예제 #1
0
 public function createAction()
 {
     if ($this->request->isPost()) {
         $categoriesFactory = new CategorieFactory();
         $categorieService = $categoriesFactory->createService($this->getServiceLocator());
         $categorieName = $this->getRequest()->getPost()["categoryName"];
         if (!$categorieService->isCategoryNameUsed($categorieName)) {
             $categorieService->saveCategorie($categorieName);
         }
         $this->redirect()->toRoute('articles - create');
     } else {
         $this->redirect()->toRoute('home');
     }
 }
예제 #2
0
 public function createAction()
 {
     if ($this->zfcUserAuthentication()->getIdentity()->getRole() == 'member') {
         $this->getServiceLocator()->get('Zend\\Log')->info('Quelqu\'un de non authorizé essais d\'acceder à la page de création d\'article');
         $this->redirect()->toRoute('home');
     }
     $categorieFactory = new CategorieFactory();
     $categorieService = $categorieFactory->createService($this->getServiceLocator());
     $categories = $categorieService->getAllCategories();
     if ($this->request->isPost()) {
         $this->getServiceLocator()->get('Zend\\Log')->info('Une tentative de création d\'article a été déctecté');
         $post = $this->getRequest()->getPost();
         $categoriesFactory = new CategorieFactory();
         $categorieService = $categoriesFactory->createService($this->getServiceLocator());
         $categorie = new Categorie();
         $categorie = $categorieService->getById($post["categorie"]);
         if ($categorie == null) {
             return $this->notFoundAction();
         }
         $post["categorie"] = $categorie;
         $articlesFactory = new ArticleFactory();
         $articlesService = $articlesFactory->createService($this->getServiceLocator());
         $article = $articlesService->isValidPost($post);
         if (!$article["valide"]) {
             foreach ($article['error'] as $error) {
                 $this->getServiceLocator()->get('Zend\\Log')->info('Erreur : ' . $error);
             }
             return new ViewModel(array('errors' => $article['error'], 'categories' => $categories));
         } else {
             //Saving article
             $articlesService->saveArticle($post, $categorie, $this->zfcUserAuthentication()->getIdentity());
             $this->getServiceLocator()->get('Zend\\Log')->info('Un article a été sauvgardé');
             $this->redirect('home');
         }
     }
     return new ViewModel(array('categories' => $categories));
 }