示例#1
0
 public function treatCatAction()
 {
     $this->getLayout()->getAdminHmenu()->add($this->getTranslator()->trans('menuLinks'), array('action' => 'index'))->add($this->getTranslator()->trans('menuActionNewCategory'), array('action' => 'treat'));
     $categorykMapper = new CategoryMapper();
     if ($this->getRequest()->getParam('id')) {
         $this->getView()->set('category', $categorykMapper->getCategoryById($this->getRequest()->getParam('id')));
     }
     if ($this->getRequest()->isPost()) {
         $model = new CategoryModel();
         if ($this->getRequest()->getParam('id')) {
             $model->setId($this->getRequest()->getParam('id'));
         }
         $name = $this->getRequest()->getPost('name');
         if (empty($name)) {
             $this->addMessage('missingName', 'danger');
         } else {
             $model->setName($this->getRequest()->getPost('name'));
             $model->setDesc($this->getRequest()->getPost('desc'));
             $model->setParentID($this->getRequest()->getParam('parentId'));
             $categorykMapper->save($model);
             $this->addMessage('saveSuccess');
             if ($this->getRequest()->getParam('parentId')) {
                 $this->redirect(array('action' => 'index', 'cat_id' => $this->getRequest()->getParam('parentId')));
             } else {
                 $this->redirect(array('action' => 'index'));
             }
         }
     }
 }
示例#2
0
 /**
  * Inserts or updates category model.
  *
  * @param CategoryModel $category
  */
 public function save(CategoryModel $category)
 {
     $fields = array('name' => $category->getName(), 'desc' => $category->getDesc(), 'parent_id' => $category->getParentId());
     if ($category->getId()) {
         $this->db()->update('link_cats')->values($fields)->where(array('id' => $category->getId()))->execute();
     } else {
         $this->db()->insert('link_cats')->values($fields)->execute();
     }
 }