public function addAction()
 {
     $form = new CategoryAddForm();
     $status = $message = '';
     $em = $this->getEntityManager();
     $request = $this->getRequest();
     if ($request->isPost()) {
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $category = new Category();
             $category->exchangeArray($form->getData());
             $em->persist($category);
             $em->flush();
             $status = 'success';
             $message = 'Категорія добавлена';
         } else {
             $status = 'error';
             $message = 'Помилка параметрів';
         }
     } else {
         return new ViewModel(array('form' => $form));
     }
     if ($message) {
         $this->flashMessenger()->setNamespace($status)->addMessage($message);
     }
     return $this->redirect()->toRoute('admin/category');
 }
 public function listAction()
 {
     $request = $this->getRequest();
     $pageParam = $this->params('page');
     $pageSession = new Container('pageCategory');
     $tabFiltreSession = new Container('tabFiltreCategorySession');
     $em = $this->getServiceLocator()->get('doctrine.entitymanager.orm_default');
     // initialisation du tableau de filtre
     $tabFiltre['label'] = null;
     $reset = $this->params('reset');
     if (!empty($reset)) {
         $tabFiltreSession->filtre = $tabFiltre;
         $pageSession->page = 1;
     }
     // récupération des filtres de sessions
     // 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\\FilterCategoryForm');
     $category = new Category();
     if ($tabFiltreSession->filtre != null) {
         $category->setLabel($tabFiltreSession->filtre['label']);
     }
     $form->bind($category);
     if ($request->isPost() == false) {
         if (empty($tabFiltreSession->filtre)) {
             $categorys = $em->getRepository('Blog\\Entity\\Category')->getList($numPage, 20, $tabFiltre);
         } else {
             // on filtre avec la session
             $categorys = $em->getRepository('Blog\\Entity\\Category')->getList($numPage, 20, $tabFiltreSession->filtre);
         }
     } else {
         $form->setData($request->getPost());
         if ($form->isValid()) {
             $data = $form->getData();
             $tabFiltre = array();
             $tabFiltre['label'] = $data->getLabel();
             $categorys = $em->getRepository('Blog\\Entity\\Category')->getList($numPage, 20, $tabFiltre);
             $tabFiltreSession->filtre = $tabFiltre;
         }
     }
     // On écrase la variable de session
     if ($numPage) {
         $pageSession->page = $numPage;
     }
     return new ViewModel(array("categorys" => $categorys, "form" => $form));
 }
 /**
  * {@inheritDoc}
  */
 public function __toString()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, '__toString', array());
     return parent::__toString();
 }
 /**
  * {@inheritDoc}
  */
 public function getInputFilter()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getInputFilter', array());
     return parent::getInputFilter();
 }