public function getCategoriesForParentRec($models, $id) { $categoryRow = $this->db()->select('*')->from('link_cats')->where(array('id' => $id))->execute()->fetchAssoc(); if (empty($categoryRow)) { return null; } if (!empty($categoryRow['parent_id'])) { $models = $this->getCategoriesForParentRec($models, $categoryRow['parent_id']); } $categoryModel = new CategoryModel(); $categoryModel->setId($categoryRow['id']); $categoryModel->setParentId($categoryRow['parent_id']); $categoryModel->setName($categoryRow['name']); $categoryModel->setDesc($categoryRow['desc']); $models[] = $categoryModel; return $models; }
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')); } } } }