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 |
|||
| <?php | |
| namespace BodyRep\Controller; | |
| use BodyRep\Form\Profile; | |
| use Symfony\Component\HttpFoundation\Response; | |
| use Symfony\Bundle\FrameworkBundle\Controller\Controller; | |
| use Symfony\Component\Security\Core\SecurityContext; | |
| # Annotations & templates | |
| use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | |
| use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template; | |
| use JMS\SecurityExtraBundle\Annotation\Secure; | |
| use Symfony\Component\DependencyInjection\ContainerAwareInterface; | |
| use Symfony\Component\DependencyInjection\ContainerInterface; | |
| class MemberController extends Controller | |
| { | |
| private $member; | |
| public function setContainer(ContainerInterface $container = null) | |
| { | |
| parent::setContainer($container); | |
| $db = $this->getDoctrine()->getManager(); | |
| $user = $this->getUser(); | |
| if (method_exists($user, 'getUsername')) | |
| { | |
| $username = $this->getUser()->getUsername(); | |
| $query = $db->createQuery(' | |
| SELECT m | |
| FROM BodyRep:Member m | |
| WHERE m.username = :username') | |
| ->setParameter('username', $username) | |
| ->setMaxResults(1); | |
| if (sizeof($query->getResult()) != 1) | |
| throw $this->createNotFoundException("User '".$username."' not found"); | |
| $this->member = $query->getSingleResult(); | |
| } | |
| } | |
| /** | |
| * @Route("/login", name="_login") | |
| * @Template() | |
| */ | |
| public function loginAction() | |
| { | |
| if ($this->get('request')->attributes->has(SecurityContext::AUTHENTICATION_ERROR)) { | |
| $error = $this->get('request')->attributes->get(SecurityContext::AUTHENTICATION_ERROR); | |
| } else { | |
| $error = $this->get('request')->getSession()->get(SecurityContext::AUTHENTICATION_ERROR); | |
| } | |
| return array( | |
| 'last_username' => $this->get('request')->getSession()->get(SecurityContext::LAST_USERNAME), | |
| 'error' => $error, | |
| ); | |
| } | |
| private function getMember() | |
| { | |
| return $this->member; | |
| } | |
| /** | |
| * @Route("/login_check", name="_security_check") | |
| */ | |
| public function securityCheckAction() | |
| { | |
| // The security layer will intercept this request | |
| } | |
| /** | |
| * @Route("/logout", name="_logout") | |
| */ | |
| public function logoutAction() | |
| { | |
| // The security layer will intercept this request | |
| } | |
| public function navbarAction() | |
| { | |
| // The security layer will intercept this request | |
| } | |
| /** | |
| * @Route("/", name="_member") | |
| * @Template() | |
| */ | |
| public function indexAction() | |
| { | |
| $username = $this->getUser()->getUsername(); | |
| return array('name' => $this->getMember()->getFullName()); | |
| } | |
| /** | |
| * @Route("/profile/", name="_member_profile") | |
| * @Template() | |
| */ | |
| public function profileAction() | |
| { | |
| $username = $this->getUser()->getUsername(); | |
| $db = $this->getDoctrine()->getManager(); | |
| $query = $db->createQuery(' | |
| SELECT p | |
| FROM BodyRep:Profile p | |
| WHERE p.username = :username') | |
| ->setParameter('username', $username) | |
| ->setMaxResults(1); | |
| if (sizeof($query->getResult()) != 1) | |
| throw $this->createNotFoundException("User '".$username."' not found"); | |
| $profile = $query->getSingleResult(); | |
| return (array('sFullName' => $profile->getFullName(), 'name' => $this->getMember()->getFullName())); | |
| } | |
| /** | |
| * @Route("/profile/edit", name="_member_profile_edit") | |
| * @Template() | |
| */ | |
| public function editProfileAction() | |
| { | |
| $username = $this->getUser()->getUsername(); | |
| $form = $this->get('form.factory')->create(new Profile(), array('fullname' => $this->getMember()->getFullName())); | |
| $error = ''; | |
| return array('form' => $form->createView(), 'error' => ''); | |
| } | |
| /** | |
| * @Route("/profile/save", name="_member_profile_save") | |
| */ | |
| public function saveAction() | |
| { | |
| $username = $this->getUser()->getUsername(); | |
| $json = array('result' => 0); | |
| $form = $this->get('form.factory')->create(new Profile()); | |
| $request = $this->get('request'); | |
| $form->bind($request); | |
| if ($form->isValid()) | |
| { | |
| $json['result'] = 1; | |
| $d = $form->getClientData(); | |
| $this->getMember()->setFullName($d['fullname']); | |
| // $this->container->get('bodyrep.sub_mailer')->notifySubscribers($post, $comment); | |
| // send message | |
| if ($recipients = $swift->send($message, $failures)) | |
| { | |
| // This will let us know how many users received this message | |
| echo 'Message sent out to '.$recipients.' users';exit; | |
| } | |
| $db->persist($this->getMember()); | |
| $db->flush(); | |
| } | |
| $resp = new Response (json_encode($json)); | |
| $resp->headers->set('Content-Type', 'text/plain'); | |
| return $resp; | |
| } | |
| /** | |
| * @Route("/search/{param}", name="_member_search", defaults={"param" = 0}) | |
| * @Template() | |
| */ | |
| public function searchAction($param='') | |
| { | |
| /* | |
| * Integrated suggester response | |
| * | |
| */ | |
| $em = $this->getDoctrine()->getManager(); | |
| $query = $em->createQuery("SELECT m FROM BodyRep:Member m WHERE m.fullname ILIKE '%$param%'"); | |
| $res = $query->getResult(); | |
| $resc = sizeof($res); | |
| $sugg = array(); | |
| /*if ($res > 0) | |
| { | |
| foreach ($res as $member) | |
| { | |
| $text = preg_replace('/<br[^\>]*>/i', "\n", $member->getFullname()); | |
| $item['text'] = strip_tags($text); | |
| $item['html'] = $text; | |
| $item['data'] = array('username' => htmlspecialchars($member->getUsername())); | |
| $sugg[] = $item; | |
| } | |
| } | |
| if (!empty($param)) | |
| { | |
| $json = array('result' => 1, 'suggestions' => $sugg); | |
| $resp = new Response (json_encode($json)); | |
| $resp->headers->set('Content-Type', 'text/plain'); | |
| return $resp; | |
| } | |
| else*/ | |
| return array('search' => $res); | |
| } | |
| } |