Exemplo n.º 1
0
 private function createCategory($nom, $parent)
 {
     $category = new Category();
     $category->setCategory($nom);
     $category->setParentcategory($parent);
     return $category;
 }
Exemplo n.º 2
0
 public function followCategoryAction(Request $request, Category $category)
 {
     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.');
         }
         $followedCategory = $user->getFollowedcategories();
         $toArray = array();
         foreach ($followedCategory as $cat) {
             $toArray[] = $cat->getId();
         }
         if (in_array($category->getId(), $toArray)) {
             $user->removeFollowedcategory($category);
             $response->setData(array('username' => $category->getCategory(), 'subject' => "Vous n'êtes plus abonné à "));
         } else {
             $user->addFollowedcategory($category);
             $this->get('event_dispatcher')->dispatch(SkuagEvents::ON_FOLLOW_CATEGORY, new FollowCategoryEvent($category, $user));
             $response->setData(array('username' => $category->getCategory(), 'subject' => 'Vous êtes abonné à '));
         }
         $em->flush();
         return $response;
     }
     return $this->errorMethodRequest();
 }
Exemplo n.º 3
0
 public function showByCategoryAction(Request $request, Category $category)
 {
     // Le manager des annonces
     $advertManager = $this->getAdvertManager();
     $choices = null;
     $noRegionSelected = $this->get('session')->get('noRegionSelected');
     $page_title = $category->getCategory();
     if ($request->isMethod('post')) {
         $choices = $advertManager->recordChoiceFilter();
     } else {
         $advertManager->removeChoiceSession();
     }
     if ($noRegionSelected) {
         $localisation = null;
     } else {
         $localisation = $advertManager->getAdvertLocalisationSession();
     }
     $user = $this->getUser();
     $userFollow = false;
     if (is_object($user) || $user instanceof User) {
         $userFollow = $this->checkIfUserFollow($category);
     }
     $advertListToPaginate = $advertManager->getAdvertByCategory($category, $choices, $localisation);
     $advertList = $this->get('knp_paginator')->paginate($advertListToPaginate, $request->query->getInt('page', 1), 10);
     $breadcrumb = array(array($category->getCategory(), '#', true));
     $requestRubriqueId = $category->getId();
     return $this->getGlobalAdvertTemplating($advertList, $breadcrumb, $choices, $page_title, $localisation, $userFollow, $requestRubriqueId, $category->getId());
 }