Esempio n. 1
0
 public function treatAction()
 {
     $categoryMapper = new CategoryMapper();
     if ($this->getRequest()->getParam('id')) {
         $this->getLayout()->getAdminHmenu()->add($this->getTranslator()->trans('menuArticle'), array('action' => 'index'))->add($this->getTranslator()->trans('menuCats'), array('action' => 'index'))->add($this->getTranslator()->trans('edit'), array('action' => 'treat'));
         $this->getView()->set('cat', $categoryMapper->getCategoryById($this->getRequest()->getParam('id')));
     } else {
         $this->getLayout()->getAdminHmenu()->add($this->getTranslator()->trans('menuArticle'), array('action' => 'index'))->add($this->getTranslator()->trans('menuCats'), array('action' => 'index'))->add($this->getTranslator()->trans('add'), array('action' => 'treat'));
     }
     if ($this->getRequest()->isPost()) {
         $model = new CategoryModel();
         if ($this->getRequest()->getParam('id')) {
             $model->setId($this->getRequest()->getParam('id'));
         }
         $name = trim($this->getRequest()->getPost('name'));
         if (empty($name)) {
             $this->addMessage('missingName', 'danger');
         } else {
             $model->setName($name);
             $categoryMapper->save($model);
             $this->addMessage('saveSuccess');
             $this->redirect(array('action' => 'index'));
         }
     }
 }
Esempio n. 2
0
 /**
  * Gets categorys.
  *
  * @param array $where
  * @return CategoryModel[]|null
  */
 public function getCategories($where = array())
 {
     $categoryArray = $this->db()->select('*')->from('articles_cats')->where($where)->order(array('id' => 'ASC'))->execute()->fetchRows();
     if (empty($categoryArray)) {
         return null;
     }
     $categorys = array();
     foreach ($categoryArray as $categoryRow) {
         $categoryModel = new CategoryModel();
         $categoryModel->setId($categoryRow['id']);
         $categoryModel->setName($categoryRow['name']);
         $categorys[] = $categoryModel;
     }
     return $categorys;
 }