public function updatePost(Post $post) { if (!$post->getSlug()) { $post->setSlug(str_replace(' ', '-', strtolower($post->getName()))); } $this->em->flush($post); $this->cacheService->generateCache($this); }
/** * listin of all the posts * @return array */ public function listAction() { $request = $this->getRequest(); $pageParam = $this->params('page'); $pageSession = new Container('pagePost'); $tabFiltreSession = new Container('tabFiltrePostSession'); $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default'); // initialisation du tableau de filtre $tabFiltre['title'] = null; $tabFiltre['category'] = null; $tabFiltre['deleted'] = 0; $reset = $this->params('reset'); // on réinitialise toute la session if (!empty($reset)) { $tabFiltreSession->filtre = $tabFiltre; $pageSession->page = 1; } // le numéro de page on récupère celui reçut en param si y'en a un sinon celui en session $numPage = $pageParam ? $pageParam : $pageSession->page; // créer le form de filtre $formManager = $this->serviceLocator->get('FormElementManager'); $form = $formManager->get('Admin\\Form\\Form\\FilterPostForm'); $post = new Post(); if ($tabFiltreSession->filtre != null) { $post->setTitle($tabFiltreSession->filtre['title']); $post->setCategory($tabFiltreSession->filtre['category']); $post->setDeleted($tabFiltreSession->filtre['deleted']); } $form->bind($post); if ($request->isPost() == false) { if (empty($tabFiltreSession->filtre)) { $posts = $em->getRepository('Blog\\Entity\\Post')->getList($numPage, 10, $tabFiltre); } else { // on filtre avec la session $posts = $em->getRepository('Blog\\Entity\\Post')->getList($numPage, 10, $tabFiltreSession->filtre); } } else { $form->setData($request->getPost()); if ($form->isValid()) { $data = $form->getData(); $tabFiltre = array(); $tabFiltre['title'] = $data->getTitle(); $tabFiltre['category'] = $data->getCategory(); $tabFiltre['deleted'] = $data->getDeleted(); $posts = $em->getRepository('Blog\\Entity\\Post')->getList($numPage, 10, $tabFiltre); $tabFiltreSession->filtre = $tabFiltre; } } // On écrase la variable de session if ($numPage) { $pageSession->page = $numPage; } return new ViewModel(array("posts" => $posts, "form" => $form)); }
/** * {@inheritDoc} */ public function __toString() { $this->__initializer__ && $this->__initializer__->__invoke($this, '__toString', array()); return parent::__toString(); }