| Code Coverage
| Classes and Traits | Functions and Methods | Lines
Total |  | 0.00% | 0 / 1 |  | 0.00% | 0 / 11 | CRAP |  | 0.00% | 0 / 162
MemberController |  | 0.00% | 0 / 1 |  | 0.00% | 0 / 11 | 306 |  | 0.00% | 0 / 161
setContainer(ContainerInterface $container = null) |  | 0.00% | 0 / 1 | 12 |  | 0.00% | 0 / 19
loginAction() |  | 0.00% | 0 / 1 | 6 |  | 0.00% | 0 / 12
getMember() |  | 0.00% | 0 / 1 | 2 |  | 0.00% | 0 / 4
securityCheckAction() |  | 0.00% | 0 / 1 | 2 |  | 0.00% | 0 / 4
logoutAction() |  | 0.00% | 0 / 1 | 2 |  | 0.00% | 0 / 4
navbarAction() |  | 0.00% | 0 / 1 | 2 |  | 0.00% | 0 / 4
indexAction() |  | 0.00% | 0 / 1 | 2 |  | 0.00% | 0 / 5
profileAction() |  | 0.00% | 0 / 1 | 6 |  | 0.00% | 0 / 15
editProfileAction() |  | 0.00% | 0 / 1 | 2 |  | 0.00% | 0 / 7
saveAction() |  | 0.00% | 0 / 1 | 12 |  | 0.00% | 0 / 26
searchAction($param='') |  | 0.00% | 0 / 1 | 2 |  | 0.00% | 0 / 32

1 | <?php
2 |
3 | namespace BodyRep\Controller;
4 | use BodyRep\Form\Profile;
5 | use Symfony\Component\HttpFoundation\Response;
6 |
7 | use Symfony\Bundle\FrameworkBundle\Controller\Controller;
8 | use Symfony\Component\Security\Core\SecurityContext;
9 |
10 | # Annotations & templates
11 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
12 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
13 |
14 | use JMS\SecurityExtraBundle\Annotation\Secure;
15 | use Symfony\Component\DependencyInjection\ContainerAwareInterface;
16 | use Symfony\Component\DependencyInjection\ContainerInterface;
17 |
18 | class MemberController extends Controller
19 | {
20 | private $member;
21 | public function setContainer(ContainerInterface $container = null)
22 | {
23 | parent::setContainer($container);
24 | $db = $this->getDoctrine()->getManager();
25 | $user = $this->getUser();
26 | if (method_exists($user, 'getUsername'))
27 | {
28 | $username = $this->getUser()->getUsername();
29 |
30 | $query = $db->createQuery('
31 | SELECT m
32 | FROM BodyRep:Member m
33 | WHERE m.username = :username')
34 | ->setParameter('username', $username)
35 | ->setMaxResults(1);
36 |
37 | if (sizeof($query->getResult()) != 1)
38 | throw $this->createNotFoundException("User '".$username."' not found");
39 |
40 | $this->member = $query->getSingleResult();
41 | }
42 | }
43 |
44 | /**
45 | * @Route("/login", name="_login")
46 | * @Template()
47 | */
48 | public function loginAction()
49 | {
50 | if ($this->get('request')->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) {
51 | $error = $this->get('request')->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
52 | } else {
53 | $error = $this->get('request')->getSession()->get(SecurityContext::AUTHENTICATION_ERROR);
54 | }
55 |
56 | return array(
57 | 'last_username' => $this->get('request')->getSession()->get(SecurityContext::LAST_USERNAME),
58 | 'error' => $error,
59 | );
60 | }
61 |
62 | private function getMember()
63 | {
64 | return $this->member;
65 | }
66 |
67 | /**
68 | * @Route("/login_check", name="_security_check")
69 | */
70 | public function securityCheckAction()
71 | {
72 | // The security layer will intercept this request
73 | }
74 |
75 | /**
76 | * @Route("/logout", name="_logout")
77 | */
78 | public function logoutAction()
79 | {
80 | // The security layer will intercept this request
81 | }
82 |
83 |
84 | public function navbarAction()
85 | {
86 | // The security layer will intercept this request
87 | }
88 |
89 | /**
90 | * @Route("/", name="_member")
91 | * @Template()
92 | */
93 | public function indexAction()
94 | {
95 | $username = $this->getUser()->getUsername();
96 |
97 |
98 | return array('name' => $this->getMember()->getFullName());
99 | }
100 |
101 | /**
102 | * @Route("/profile/", name="_member_profile")
103 | * @Template()
104 | */
105 | public function profileAction()
106 | {
107 | $username = $this->getUser()->getUsername();
108 |
109 | $db = $this->getDoctrine()->getManager();
110 | $query = $db->createQuery('
111 | SELECT p
112 | FROM BodyRep:Profile p
113 | WHERE p.username = :username')
114 | ->setParameter('username', $username)
115 | ->setMaxResults(1);
116 | if (sizeof($query->getResult()) != 1)
117 | throw $this->createNotFoundException("User '".$username."' not found");
118 |
119 | $profile = $query->getSingleResult();
120 |
121 | return (array('sFullName' => $profile->getFullName(), 'name' => $this->getMember()->getFullName()));
122 | }
123 |
124 | /**
125 | * @Route("/profile/edit", name="_member_profile_edit")
126 | * @Template()
127 | */
128 | public function editProfileAction()
129 | {
130 | $username = $this->getUser()->getUsername();
131 | $form = $this->get('form.factory')->create(new Profile(), array('fullname' => $this->getMember()->getFullName()));
132 | $error = '';
133 |
134 | return array('form' => $form->createView(), 'error' => '');
135 | }
136 |
137 | /**
138 | * @Route("/profile/save", name="_member_profile_save")
139 | */
140 | public function saveAction()
141 | {
142 | $username = $this->getUser()->getUsername();
143 |
144 | $json = array('result' => 0);
145 |
146 | $form = $this->get('form.factory')->create(new Profile());
147 | $request = $this->get('request');
148 |
149 |
150 | $form->bind($request);
151 |
152 | if ($form->isValid())
153 | {
154 | $json['result'] = 1;
155 | $d = $form->getClientData();
156 | $this->getMember()->setFullName($d['fullname']);
157 | // $this->container->get('bodyrep.sub_mailer')->notifySubscribers($post, $comment);
158 |
159 | // send message
160 | if ($recipients = $swift->send($message, $failures))
161 | {
162 | // This will let us know how many users received this message
163 | echo 'Message sent out to '.$recipients.' users';exit;
164 | }
165 | $db->persist($this->getMember());
166 | $db->flush();
167 | }
168 |
169 | $resp = new Response (json_encode($json));
170 | $resp->headers->set('Content-Type', 'text/plain');
171 |
172 | return $resp;
173 | }
174 | /**
175 | * @Route("/search/{param}", name="_member_search", defaults={"param" = 0})
176 | * @Template()
177 | */
178 | public function searchAction($param='')
179 | {
180 |
181 | /*
182 | * Integrated suggester response
183 | *
184 | */
185 | $em = $this->getDoctrine()->getManager();
186 | $query = $em->createQuery("SELECT m FROM BodyRep:Member m WHERE m.fullname ILIKE '%$param%'");
187 |
188 | $res = $query->getResult();
189 | $resc = sizeof($res);
190 | $sugg = array();
191 | /*if ($res > 0)
192 | {
193 | foreach ($res as $member)
194 | {
195 | $text = preg_replace('/<br[^\>]*>/i', "\n", $member->getFullname());
196 | $item['text'] = strip_tags($text);
197 | $item['html'] = $text;
198 | $item['data'] = array('username' => htmlspecialchars($member->getUsername()));
199 | $sugg[] = $item;
200 | }
201 | }
202 | if (!empty($param))
203 | {
204 | $json = array('result' => 1, 'suggestions' => $sugg);
205 | $resp = new Response (json_encode($json));
206 | $resp->headers->set('Content-Type', 'text/plain');
207 | return $resp;
208 | }
209 | else*/
210 | return array('search' => $res);
211 |
212 |
213 | }
214 | }