public function followRegionAction(Request $request, Region $region) { 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.'); } $followedRegion = $user->getFollowedregion(); $toArray = array(); foreach ($followedRegion as $r) { $toArray[] = $r->getId(); } if (in_array($region->getId(), $toArray)) { $user->removeFollowedregion($region); $response->setData(array('username' => $region->getNom(), 'subject' => "Vous n'êtes plus abonné à ")); } else { $user->addFollowedregion($region); $response->setData(array('username' => $region->getNom(), 'subject' => 'Vous êtes abonné à ')); $this->get('event_dispatcher')->dispatch(SkuagEvents::ON_FOLLOW_REGION, new FollowRegionEvent($region, $user)); } $em->flush(); return $response; } return $this->errorMethodRequest(); }
public function showByRegionAction(Request $request, Region $region) { // Le manager des annonces $advertManager = $this->getAdvertManager(); $choices = null; $page_title = $region->getNom(); $advertManager->checkRegionBySession($region->getId()); if ($request->isMethod('post')) { $choices = $advertManager->recordChoiceFilter(); } else { $advertManager->removeChoiceSession(); } $advertListToPaginate = $advertManager->getAdvertByRegion($region, $choices); $advertList = $this->get('knp_paginator')->paginate($advertListToPaginate, $request->query->getInt('page', 1), 10); $usersFound = $this->getDoctrine()->getRepository('SnoozitUserBundle:User')->getTimelineUsersFound($this->get('sz_search_engine_manager')->getPageTitle()); $breadcrumb = array(array($region->getNom(), $this->generateUrl('snoozit_platform_show_by_region', array('slug' => $region->getSlug())), true)); $user = $this->getUser(); $userFollow = false; if (is_object($user) || $user instanceof User) { $userFollow = $this->checkIfUserFollow($region); } $requestRubriqueId = $region->getId(); return $this->getGlobalAdvertTemplating($advertList, $breadcrumb, $choices, $page_title, null, $userFollow, $requestRubriqueId, $usersFound); }
private function createRegion($nom) { $region = new Region(); $region->setNom($nom); return $region; }