public function editAction() { if ($this->_request->getParam('dataPage')) { $dataPage = $this->_request->getParam('dataPage'); $id = $this->_request->getParam('id'); $categories = $this->_modelMapper->find($id, $this->_model); $categories->setOptions($dataPage); $this->setUploadImage($categories); $this->_modelMapper->save($categories); $this->getRedirector()->gotoUrlAndExit('/media/' . $categories->getPath()); } parent::editAction(); }
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); } $categoryId = $this->_request->getParam('category_id') ? $this->_request->getParam('category_id') : $item->getCategoryId(); $category = $this->_modelCategoriesMapper->find($categoryId, new Media_Model_MediaCategories()); $fullPath = $category ? $category->getPath() . '/' . $item->getPath() : $item->getPath(); $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 viewAction() { $request = $this->getRequest(); $mediaPathItem = $request->getParam('fullPath'); $mediaMapper = new Media_Model_Mapper_Media(); $mediaItem = $mediaMapper->findByFullPath($mediaPathItem, new Media_Model_Media()); if (is_null($mediaItem)) { throw new Zend_Controller_Action_Exception("Страница не найдена", 404); } if (!is_null($this->getRequest()->getParam('json')) && Zend_Auth::getInstance()->hasIdentity()) { $this->forward('json', 'media', 'admin', array('id' => $mediaItem->getId())); return; } if (Zend_Auth::getInstance()->hasIdentity()) { $this->_request->setParams(array('dataItem' => array('controller' => 'media', 'id' => $mediaItem->getId(), 'active' => $mediaItem->getActive(), 'deleted' => $mediaItem->getDeleted()))); } $mediaCategoryMapper = new Media_Model_Mapper_MediaCategories(); $currentCategory = $mediaCategoryMapper->find($mediaItem->getCategoryId(), new Media_Model_MediaCategories()); if ($mediaItem->getDeleted() != '0') { if (!Zend_Auth::getInstance()->hasIdentity() && $mediaItem->getDeleted() != '0') { throw new Zend_Controller_Action_Exception("Страница не найдена", 404); } $this->_redirector->gotoRouteAndExit(array('module' => 'admin', 'controller' => 'media-categories', 'action' => 'list', 'id' => $currentCategory->getId()), 'adminEdit', true); } $this->view->assign(array('currentCategory' => $currentCategory, 'adminPath' => 'media/edit/' . $mediaItem->getId())); $meta_description = $mediaItem->getMetaDescription() != '' ? $mediaItem->getMetaDescription() : $mediaItem->getName() . '. ' . $currentCategory->getName() . '. Альфа-Гидро.'; $meta_keywords = $mediaItem->getMetaKeywords() != '' ? $mediaItem->getMetaKeywords() : $mediaItem->getName() . ', ' . $currentCategory->getName() . ', пресса'; $this->view->assign(array('mediaItem' => $mediaItem, 'meta_description' => $meta_description, 'meta_keywords' => $meta_keywords)); if ($mediaItem->getActive() != '1' && !Zend_Auth::getInstance()->hasIdentity()) { $this->view->assign(array('title' => $mediaItem->getName())); throw new Zend_Controller_Action_Exception("Страница временно не доступна", 403); } }