Ejemplo n.º 1
0
 public function followDepartementAction(Request $request, Departement $departement)
 {
     if ($request->isXmlHttpRequest()) {
         $response = new JsonResponse();
         $em = $this->getDoctrine()->getEntityManager();
         $user = $this->getUser();
         if (!is_object($user) || !$user instanceof User) {
             throw new AccessDeniedException('This user does not have access to this section.');
         }
         $followedDepartement = $user->getFolloweddepartement();
         $toArray = array();
         foreach ($followedDepartement as $r) {
             $toArray[] = $r->getId();
         }
         if (in_array($departement->getId(), $toArray)) {
             $user->removeFolloweddepartement($departement);
             $response->setData(array('username' => $departement->getNom(), 'subject' => "Vous n'êtes plus abonné à "));
         } else {
             $user->addFolloweddepartement($departement);
             $response->setData(array('username' => $departement->getNom(), 'subject' => 'Vous êtes abonné à '));
             $this->get('event_dispatcher')->dispatch(SkuagEvents::ON_FOLLOW_DEPARTEMENT, new FollowDepartementEvent($departement, $user));
         }
         $em->flush();
         return $response;
     }
     return $this->errorMethodRequest();
 }
Ejemplo n.º 2
0
 public function showByDepartementAction(Request $request, Departement $departement)
 {
     // Le manager des annonces
     $advertManager = $this->getAdvertManager();
     $choices = null;
     $user = $this->getUser();
     $userFollow = false;
     // Controle si la région demandé existe
     $page_title = $departement->getNom();
     $advertManager->checkRegionBySession($departement->getRegion()->getId());
     if ($request->isMethod('post')) {
         $choices = $advertManager->recordChoiceFilter();
     } else {
         $advertManager->removeChoiceSession();
     }
     $advertListToPaginate = $advertManager->getAdvertByDepartement($departement, $choices);
     $advertList = $this->get('knp_paginator')->paginate($advertListToPaginate, $request->query->getInt('page', 1), 10);
     $breadcrumb = array(array($departement->getRegion()->getNom(), $this->generateUrl('snoozit_platform_show_by_region', array('slug' => $departement->getRegion()->getSlug()))), array($departement->getNom(), '#', true));
     if (is_object($user) || $user instanceof User) {
         $userFollow = $this->checkIfUserFollow($departement);
     }
     $requestRubriqueId = $departement->getId();
     return $this->getGlobalAdvertTemplating($advertList, $breadcrumb, $choices, $page_title, null, $userFollow, $requestRubriqueId);
 }
Ejemplo n.º 3
0
 private function createDepartement($nom, $num, $region_id)
 {
     $departements = new Departement();
     $departements->setNom($nom);
     $departements->setNumero($num);
     $departements->setRegion($region_id);
     return $departements;
 }