/** * Send a file to the browser * * @return \Zend\Stdlib\ResponseInterface */ public function downloadAction() { $viewId = $this->getRouteMatch()->getParam('id', null); if (!empty($viewId)) { $view = View\Model::fromId($viewId); if (empty($view)) { $this->flashMessenger()->addErrorMessage('This view can not be download'); return $this->redirect()->toRoute('development/view/edit', array('id' => $viewId)); } $content = $view->getContent(); $filename = $view->getIdentifier() . '.phtml'; } else { $views = new View\Collection(); $children = $views->getViews(); $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 = 'views.zip'; unlink($tmpFilename); } } if (empty($content) or empty($filename)) { $this->flashMessenger()->addErrorMessage('Can not save views'); return $this->redirect()->toRoute('development/view'); } $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; }
/** * Load document form from DocumentModel * * @param DocumentModel $document Document model * @param array $config Configuration * * @return void */ public function load(DocumentModel $document, array $config) { $this->get('document-name')->setValue($document->getName()); $this->get('document-url_key')->setValue($document->getUrlKey()); $status = new Element\Checkbox('document-status'); $status->setLabel('Publish')->setValue($document->isPublished())->setAttribute('id', 'status')->setAttribute('class', 'input-checkbox')->setCheckedValue((string) DocumentModel::STATUS_ENABLE); $this->add($status); $showInNav = new Element\Checkbox('document-show_in_nav'); $showInNav->setLabel('Show in nav')->setValue($document->showInNav())->setAttribute('id', 'show_in_nav')->setAttribute('class', 'input-checkbox')->setCheckedValue((string) DocumentModel::STATUS_ENABLE); $this->add($showInNav); $canBeCached = new Element\Checkbox('document-can_be_cached'); $canBeCached->setLabel('Can be cached')->setValue($document->canBeCached())->setAttribute('id', 'can_be_cached')->setAttribute('class', 'input-checkbox')->setCheckedValue((string) DocumentModel::STATUS_ENABLE); $this->add($canBeCached); array_unshift($config['locales'], '-- Use parent configuration'); $locale = new Element\Select('document-locale'); $locale->setLabel('Locale')->setValueOptions($config['locales'])->setValue($document->getLocale())->setAttribute('id', 'locale')->setAttribute('class', 'form-control'); $this->add($locale); $documentType = $document->getDocumentType(); $viewsCollection = $documentType->getAvailableViews(); $select = $viewsCollection->getSelect(); $viewSelected = $document->getViewId(); $viewModel = View\Model::fromId($document->getDocumentType()->getDefaultViewId()); if (!empty($viewModel)) { $select = $select + array($viewModel->getId() => $viewModel->getName()); if (empty($viewSelected)) { $viewSelected = $viewModel->getId(); } } $view = new Element\Select('document-view'); $view->setValueOptions($select)->setValue((string) $viewSelected)->setAttribute('id', 'view')->setAttribute('class', 'form-control')->setLabel('View'); $inputFilterFactory = $this->getInputFilter(); $inputFilterFactory->add(array('name' => 'document-view', 'required' => true, 'validators' => array(array('name' => 'not_empty'))), 'document-view'); $this->add($view); $layoutsCollection = new Layout\Collection(); $layout = new Element\Select('document-layout'); $layout->setValueOptions($layoutsCollection->getSelect())->setValue((string) $document->getLayoutId())->setAttribute('id', 'layout')->setAttribute('class', 'form-control')->setLabel('Layout'); $inputFilterFactory->add(array('name' => 'document-layout', 'required' => true, 'validators' => array(array('name' => 'not_empty'))), 'document-layout'); $this->add($layout); $this->remove('document_type'); $this->remove('parent'); $moreInformation = new Element\Hidden('more_information'); $moreInformation->setAttribute('content', ''); $this->add($moreInformation); $this->parentId = $document->getParentId(); $this->documentId = $document->getId(); $this->loadValues($document); }
/** * get View Model * * @return \Gc\View\Model */ public function getView() { if ($this->getData('view') == null) { $view = View\Model::fromId($this->getViewId()); if ($view !== null) { $this->setData('view', $view); } } return $this->getData('view'); }
/** * Test * * @return void */ public function testFromFakeId() { $model = $this->object->fromId(10000); $this->assertFalse($model); }