public function saveFormData(Zend_Form $form)
 {
     $item = $this->getModel();
     $item->setOptions($form->getValues());
     if ($this->_request->getParam('contentMarkdown')) {
         $context_html = Michelf\MarkdownExtra::defaultTransform($this->_request->getParam('contentMarkdown'));
         $item->setContentHtml($context_html);
     }
     $item->setFullPath($this->_request->getParam('path'));
     if ($this->_request->getParam('parentId') !== 0) {
         $parentCategory = $this->_modelMapper->find($this->_request->getParam('parentId'), new Oil_Model_OilCategories());
         if (!is_null($parentCategory)) {
             $item->setFullPath($parentCategory->getFullPath() . '/' . $this->_request->getParam('path'));
         }
     }
     $this->setMetaData($item);
     $this->getModelMapper()->save($item);
     if ($item->getId() && $item->getId() != '') {
         $id = $item->getId();
     } else {
         $id = $this->getModelMapper()->getDbTable()->getAdapter()->lastInsertId();
     }
     $item = $this->getModelMapper()->find($id, $this->getModel());
     foreach ($form->getElements() as $key => $element) {
         if ($element instanceof Zend_Form_Element_File && $element->isUploaded()) {
             $item = $this->saveUploadFile($element, $item);
         }
     }
     return $item;
 }
 public function setCategories()
 {
     $select = $this->_categoriesMapper->getDbTable()->select();
     $select->where('deleted != ?', 1)->where('active != ?', 0)->order('sorting ASC');
     $oilCategories = $this->_categoriesMapper->fetchAll($select);
     $this->view->categories = $oilCategories;
     return $this;
 }
 public function viewAction()
 {
     $pageItem = $this->_itemMapper->findByFullPath($this->_request->getParam('fullPath'), new Oil_Model_Oil());
     if (is_null($pageItem)) {
         throw new Zend_Controller_Action_Exception("Страница не найдена", 404);
     }
     $this->getJson($pageItem);
     $this->setParamsDataItem($pageItem);
     $this->checkDeleted($pageItem);
     $category = $this->_categoriesMapper->find($pageItem->getCategoryId(), new Oil_Model_OilCategories());
     $this->setMetaHead($pageItem);
     $this->view->assign(array('category' => $category, 'title' => $pageItem->getTitle(), 'pageItem' => $pageItem));
     $this->checkActive($pageItem);
 }
 /**
  * @return array
  */
 public function getCategoryArray()
 {
     $categoryMapper = new Oil_Model_Mapper_OilCategories();
     $select = $categoryMapper->getDbTable()->select();
     $select->where('deleted != ?', 1)->order('sorting ASC');
     $categoryArray = array();
     $categoryArray[0] = 'нет';
     $pipelineCategories = $categoryMapper->fetchAll();
     if (!empty($pipelineCategories)) {
         /** @var Oil_Model_OilCategories $category */
         foreach ($pipelineCategories as $category) {
             $categoryArray[$category->getId()] = $category->getTitle();
         }
     }
     return $categoryArray;
 }
 public function indexAction()
 {
     $fullPath = $this->getFullPath();
     if (is_null($fullPath)) {
         $this->_redirector->gotoSimpleAndExit('index', 'index');
     }
     $category = $this->_categoryMapper->findByFulPath($fullPath, new Oil_Model_OilCategories());
     if (is_null($category)) {
         //throw new Zend_Controller_Action_Exception("Страница не найдена", 404);
         //перенаправляем в товар, может быть это товар
         $this->forward('view', 'oil');
         return;
     }
     if (!is_null($this->getRequest()->getParam('json')) && Zend_Auth::getInstance()->hasIdentity()) {
         $this->forward('json', 'oil-categories', 'admin', array('id' => $category->getId()));
         return;
     }
     if (Zend_Auth::getInstance()->hasIdentity()) {
         $this->_request->setParams(array('dataItem' => array('controller' => 'oil-categories', 'id' => $category->getId(), 'active' => $category->getActive(), 'deleted' => $category->getDeleted())));
     }
     if ($category->getDeleted() != '0') {
         if (!Zend_Auth::getInstance()->hasIdentity()) {
             throw new Zend_Controller_Action_Exception("Страница не найдена", 404);
         }
         $this->_redirector->gotoRouteAndExit(array('module' => 'admin', 'controller' => 'oil-categories', 'action' => 'index'), 'adminEdit', true);
     }
     $this->view->assign(array('category' => $category, 'title' => $category->getTitle(), 'adminPath' => 'oil-categories/list/' . $category->getId()));
     if ($category->getActive() != '1' && !Zend_Auth::getInstance()->hasIdentity()) {
         throw new Zend_Controller_Action_Exception("Раздел временно не доступен", 500);
     }
     if ($category->getId() != 0) {
         $select = $this->_categoryMapper->getDbTable()->select();
         $select->where('parent_id = ?', $category->getId())->where('deleted != ?', 1)->order('sorting ASC');
         $categories = $this->_categoryMapper->fetchAll($select);
         if (empty($categories)) {
             $this->forward('index', 'oil', 'oil', array('category' => $category));
             return;
         }
         $this->view->categories = $categories;
     } else {
         $this->_redirector->gotoUrlAndExit('/oil/', array('code' => 301));
     }
 }