/** * get View Model * * @return \Gc\View\Model */ public function getLayout() { if ($this->getData('layout') == null) { $view = Layout\Model::fromId($this->getLayoutId()); if ($view !== null) { $this->setData('layout', $view); } } return $this->getData('layout'); }
/** * Initialize Render error event * * @param Event $event Event * * @return void */ public function prepare($event) { if ($event->getApplication()->getMvcEvent()->getRouteMatch()->getMatchedRouteName() === 'cms') { $coreConfig = $event->getApplication()->getServiceManager()->get('CoreConfig'); $layout = Layout\Model::fromId($coreConfig->getValue('site_exception_layout')); if (!empty($layout)) { $templatePathStack = $event->getApplication()->getServiceManager()->get('Zend\\View\\Resolver\\TemplatePathStack'); $event->getViewModel()->setTemplate('layout/' . $layout->getIdentifier()); } } }
/** * Generate frontend from url key * * @return ViewModel */ public function indexAction() { $coreConfig = $this->getServiceLocator()->get('CoreConfig'); $viewModel = new ViewModel(); $this->events()->trigger('Front', 'preDispatch', $this, array('viewModel' => $viewModel)); if ($coreConfig->getValue('site_is_offline') == 1) { $isAdmin = $this->getServiceLocator()->get('Auth')->hasIdentity(); if (!$isAdmin) { $document = Document\Model::fromId($coreConfig->getValue('site_offline_document')); if (empty($document)) { $viewModel->setTemplate('gc-frontend/site-is-offline'); $viewModel->setTerminal(true); return $viewModel; } } } try { $document = $this->getServiceLocator()->get('CurrentDocument'); } catch (Exception $e) { //Don't care, page is just not found } $variables = array(); if (empty($document)) { // 404 $this->getResponse()->setStatusCode(404); $layout = Layout\Model::fromId($coreConfig->getValue('site_404_layout')); if (empty($layout)) { $viewModel->setTerminal(true); } } else { //Load properties from document id $properties = new Property\Collection(); $properties->load(null, null, $document->getId()); foreach ($properties->getProperties() as $property) { $value = $property->getValue(); if ($this->isSerialized($value)) { $value = unserialize($value); } $viewModel->setVariable($property->getIdentifier(), $value); $this->layout()->setVariable($property->getIdentifier(), $value); $variables[$property->getIdentifier()] = $value; } //Set view from database $view = $document->getView(); $layout = $document->getLayout(); } if (!empty($layout)) { $this->layout()->setTemplate('layout/' . $layout->getIdentifier()); } if (!empty($view)) { $viewModel->setTemplate('view/' . $view->getIdentifier()); } if ($this->getRequest()->isXmlHttpRequest()) { if ($this->params()->fromQuery('terminate_layout') or $this->params()->fromPost('terminate_layout')) { $viewModel->setTerminal(true); } } $this->events()->trigger('Front', 'postDispatch', $this, array('viewModel' => $viewModel)); return $viewModel; }
/** * Send a file to the browser * * @return \Zend\Stdlib\ResponseInterface */ public function downloadAction() { $layoutId = $this->getRouteMatch()->getParam('id', null); if (!empty($layoutId)) { $layout = Layout\Model::fromId($layoutId); if (empty($layout)) { $this->flashMessenger()->addErrorMessage('This layout can not be download'); return $this->redirect()->toRoute('development/layout/edit', array('id' => $layoutId)); } $content = $layout->getContent(); $filename = $layout->getIdentifier() . '.phtml'; } else { $layouts = new Layout\Collection(); $children = $layouts->getLayouts(); $zip = new ZipArchive(); $tmpFilename = tempnam(sys_get_temp_dir(), 'zip'); $res = $zip->open($tmpFilename, ZipArchive::CREATE); if ($res === true) { foreach ($children as $child) { $zip->addFromString($child->getIdentifier() . '.phtml', $child->getContent()); } $zip->close(); $content = file_get_contents($tmpFilename); $filename = 'layout.zip'; unlink($tmpFilename); } } if (empty($content) or empty($filename)) { $this->flashMessenger()->addErrorMessage('Can not save layouts'); return $this->redirect()->toRoute('development/layout'); } $headers = new Headers(); $headers->addHeaderLine('Pragma', 'public')->addHeaderLine('Cache-control', 'must-revalidate, post-check=0, pre-check=0')->addHeaderLine('Cache-control', 'private')->addHeaderLine('Expires', -1)->addHeaderLine('Content-Type', 'application/octet-stream')->addHeaderLine('Content-Transfer-Encoding', 'binary')->addHeaderLine('Content-Length', strlen($content))->addHeaderLine('Content-Disposition', 'attachment; filename=' . $filename); $response = $this->getResponse(); $response->setHeaders($headers); $response->setContent($content); return $response; }
/** * Test * * @return void */ public function testFromFakeId() { $model = $this->object->fromId(10000); $this->assertFalse($model); }