public function setDefaults(array $data) { $layoutGateway = new Layouts_Model_LayoutGateway(); $this->getElement('layout_title_orig')->setValue($data['layout_title']); $this->getElement('layout_content')->setValue($layoutGateway->fetchLayoutContents($data['layout_id'])); return parent::setDefaults($data); }
public function indexAction() { $this->_helper->viewRenderer->setNoRender(true); $layoutGateway = new Layouts_Model_LayoutGateway(); $layout = $layoutGateway->fetchLayout($this->_getParam('id')); $layoutGateway->duplicateLayout($layout); $flashMessenger = $this->_helper->getHelper('FlashMessenger'); $flashMessenger->setNamespace('notifications')->addMessage('Layout Duplicated.'); if ($layout->layout_module == 'layouts') { $this->_redirect('/admin/layouts/'); } else { $this->_redirect('/admin/' . $layout->layout_module . '/layouts'); } }
public function processAction() { $return = array(); $layoutGateway = new Layouts_Model_LayoutGateway(); $form = $layoutGateway->getForm('ModifyLayout'); if ($form->isValid($this->_request->getPost())) { $layoutGateway->create($form->getValues())->save(); $flashMessenger = $this->_helper->getHelper('FlashMessenger'); $flashMessenger->setNamespace('notifications')->addMessage('Layout updated.'); $return['notification']['target'] = '.notifications'; $return['notification']['content'] = $this->view->displayMessages(true); } else { $return['formErrors'] = $form->getMessages(); } $this->_helper->json->sendJson($return); }
/** * Save layout * @param * @return */ public function save() { $data = $this->toArray(); $cache = Zend_Controller_Action_HelperBroker::getStaticHelper('Cache')->getManager()->getCache('database'); $cache->clean(Zend_Cache::CLEANING_MODE_MATCHING_TAG, array('layouts')); $data['layout_type'] = self::CUSTOM; // If we are updating content then we may need to update the file too if (!empty($this->layout_content)) { // Get the layout info $layoutGateway = new Layouts_Model_LayoutGateway(); $path = $layoutGateway->fetchLayoutPath($this->layout_type, $this->layout_module); $file = $path . $data['layout_filename']; // Rename the file if needed if ($data['layout_title'] != $data['layout_title_orig']) { $filename = $this->createFilename($data['layout_title_orig']); $origFile = $path . $filename; if (rename($origFile, $file) === false) { throw new Exception('There was a problem renaming the layout. Probably a permission issue.'); } } // Write the new contents $layoutFile = fopen($file, 'w+'); fwrite($layoutFile, $this->layout_content); fclose($layoutFile); } unset($data['layout_content']); unset($data['layout_title_orig']); unset($data['layout_filename']); // Save/Insert our data into the db if (!isset($data['layout_id'])) { $this->getDbTable()->insert($data); } else { $this->getDbTable()->update($data, array('layout_id = ?' => $data['layout_id'])); } }