public function saveFormData(Zend_Form $form)
 {
     $item = $this->_model;
     $item->setOptions($form->getValues());
     if ($this->_request->getParam('contentMarkdown')) {
         $context_html = Michelf\MarkdownExtra::defaultTransform($this->_request->getParam('contentMarkdown'));
         $item->setContentHtml($context_html);
     }
     $fullPath = $this->_request->getParam('path');
     if ($this->_request->getParam('parentId') != 0) {
         $parentCategory = $this->_modelMapper->find($this->_request->getParam('parentId'), new Pipeline_Model_PipelineCategories());
         if ($parentCategory) {
             $fullPath = $parentCategory->getFullPath();
         }
     }
     $item->setFullPath($fullPath);
     $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 init()
 {
     $pageTitle = 'Детали трубопроводов';
     $pageMapper = new Default_Model_Mapper_Pages();
     $page = $pageMapper->findByPath('pipeline', new Default_Model_Pages());
     if ($page) {
         $pageTitle = $page->getTitle();
         $this->view->meta_title = $page->getMetaTitle();
         $this->view->meta_description = $page->getMetaDescription();
         $this->view->meta_keywords = $page->getMetaKeywords();
         $this->view->page = $page;
     }
     $this->view->title = $pageTitle;
     $categoriesMapper = new Pipeline_Model_Mapper_PipelineCategories();
     $select = $categoriesMapper->getDbTable()->select();
     $select->where('parent_id = ?', 0)->where('active != ?', 0)->where('deleted != ?', 1)->order('sorting ASC');
     $categories = $categoriesMapper->fetchAll($select);
     $this->view->categories = $categories;
     /*//Заглушка
       if(!Zend_Auth::getInstance()->hasIdentity()){
           $this->_helper->layout->setLayout('_cap');
           $this->render('cap');
       }*/
     $this->view->adminPath = 'pipeline-categories/';
 }
 public function viewAction()
 {
     $fullPath = $this->getFullPath();
     $pipelineMapper = new Pipeline_Model_Mapper_Pipeline();
     $pipeline = $pipelineMapper->findByFulPath($fullPath, new Pipeline_Model_Pipeline());
     if (is_null($pipeline)) {
         throw new Zend_Controller_Action_Exception("Страница не найдена", 404);
     }
     $this->getJson($pipeline);
     $this->setParamsDataItem($pipeline);
     $this->checkDeleted($pipeline);
     $categoriesMapper = new Pipeline_Model_Mapper_PipelineCategories();
     $category = $categoriesMapper->find($pipeline->getCategoryId(), new Pipeline_Model_PipelineCategories());
     $pipelineProperties = $pipelineMapper->fetchPropertyRel($pipeline->getId());
     if (!empty($pipelineProperties)) {
         $propertyValuesMapper = new Pipeline_Model_Mapper_PipelinePropertyValues();
         $viewProperties = array();
         foreach ($pipelineProperties as $property) {
             $propertyValues = $propertyValuesMapper->findByKey($pipeline->getId(), $property->getId(), new Pipeline_Model_PipelinePropertyValues());
             $viewProperties[$property->getName()] = $propertyValues;
         }
         $this->view->assign('properties', $viewProperties);
     }
     $this->view->assign(array('pipeline' => $pipeline, 'category' => $category, 'title' => $pipeline->getTitle(), 'adminPath' => 'pipeline/edit/' . $pipeline->getId()));
     $this->checkActive($pipeline);
 }
 /**
  * @return array
  */
 public function getCategoryArray()
 {
     $pipelineCategoryMapper = new Pipeline_Model_Mapper_PipelineCategories();
     $select = $pipelineCategoryMapper->getDbTable()->select();
     $select->where('deleted != ?', 1)->order('sorting ASC');
     $categoryArray = array();
     $categoryArray[] = 'нет';
     $pipelineCategories = $pipelineCategoryMapper->fetchAll();
     if (!empty($pipelineCategories)) {
         foreach ($pipelineCategories as $category) {
             $categoryArray[$category->getId()] = $category->getTitle();
         }
     }
     return $categoryArray;
 }
 /**
  * @return array
  */
 public function getCategories()
 {
     if (0 == count($this->_categories)) {
         $categoriesMapper = new Pipeline_Model_Mapper_PipelineCategories();
         $select = $categoriesMapper->getDbTable()->select();
         $select->where('parent_id = ?', 0)->where('active != ?', 0)->where('deleted != ?', 1)->order('sorting ASC');
         $this->_categories = $categoriesMapper->fetchAll($select);
     }
     return $this->_categories;
 }