Get properties
public getProperties ( boolean $forceReload = false ) : array | ||
$forceReload | boolean | to initiliaze properties |
return | array |
/** * Test * * @return void */ public function testGetProperties() { $documentModel = DocumentModel::fromArray(array('name' => 'DocumentTest', 'url_key' => 'document-test', 'status' => DocumentModel::STATUS_ENABLE, 'sort_order' => 1, 'show_in_nav' => true, 'user_id' => $this->user->getId(), 'document_type_id' => $this->documentType->getId(), 'view_id' => $this->view->getId(), 'layout_id' => $this->layout->getId(), 'parent_id' => 0)); $documentModel->save(); $this->object->setDocumentId($documentModel->getId()); $this->object->save(); $this->object->load($this->documentType->getId(), $this->tab->getId(), 1); $this->assertInternalType('array', $this->object->getProperties(true)); $this->object->load(); $this->assertInternalType('array', $this->object->getProperties(true)); }
/** * Load properties from document type, tab and document * * @param integer $documentTypeId Document type id * @param integer $tabId Tab id * @param integer $documentId Document id * * @return array */ public function loadProperties($documentTypeId, $tabId, $documentId) { $propertyName = sprintf('%d-%d-%d', $documentTypeId, $tabId, $documentId); if (empty($this->properties[$propertyName])) { $properties = new Property\Collection(); $properties->load($documentTypeId, $tabId, $documentId); $this->properties[$propertyName] = $properties->getProperties(); } return $this->properties[$propertyName]; }
/** * 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; }
/** * Return properties * * @return array */ public function getProperties() { if ($this->getData('properties') === null) { $propertiesCollection = new Property\Collection(); $propertiesCollection->load($this->getDocumentTypeId(), $this->getId()); $this->setData('properties', $propertiesCollection->getProperties()); } return $this->getData('properties'); }
/** * Paste document * * @return \Zend\View\Model\JsonModel */ public function pasteAction() { $parentId = $this->getRouteMatch()->getParam('id', null); $session = $this->getSession(); if (!empty($parentId)) { $parentDocument = DocumentModel::fromId($parentId); if (empty($parentDocument)) { return $this->returnJson(array('success' => false)); } } if (!empty($session['document-cut'])) { $document = DocumentModel::fromId($session['document-cut']); if (empty($document)) { return $this->returnJson(array('success' => false)); } if (!empty($parentDocument)) { $availableChildren = $parentDocument->getDocumentType()->getDependencies(); if (!in_array($document->getDocumentType()->getId(), $availableChildren)) { return $this->returnJson(array('success' => false)); } } $searchDocument = DocumentModel::fromUrlKey($document->getUrlKey(), $parentId); if (!empty($searchDocument)) { return $this->returnJson(array('success' => false)); } $document->setParentId($parentId); $document->save(); unset($session['document-cut']); return $this->returnJson(array('success' => true)); } elseif (!empty($session['document-copy'])) { $urlKey = $this->getRequest()->getQuery('url_key'); $searchDocument = DocumentModel::fromUrlKey($urlKey, $parentId); if (!empty($searchDocument)) { return $this->returnJson(array('success' => false)); } $document = DocumentModel::fromId($session['document-copy']); if (empty($document)) { return $this->returnJson(array('success' => false)); } if (!empty($parentDocument)) { $availableChildren = $parentDocument->getDocumentType()->getDependencies(); if (!in_array($document->getDocumentType()->getId(), $availableChildren)) { return $this->returnJson(array('success' => false)); } } $copyDocument = new DocumentModel(); $copyDocumentProperties = new Property\Collection(); $copyDocumentProperties->load(null, null, $document->getId()); $copyDocument->addData($document->getData()); $copyDocument->setData('id', null); $copyDocument->setParentId($parentId); $copyDocument->setName($this->getRequest()->getQuery('name')); $copyDocument->setUrlKey($urlKey); $copyDocument->save(); foreach ($copyDocumentProperties->getProperties() as $property) { $value = $property->getValueModel(); if (empty($value)) { continue; } $copyProperty = new Property\Value\Model(); $copyProperty->addData($value->getData()); $copyProperty->setData('id', null); $copyProperty->setDocumentId($copyDocument->getId()); $copyProperty->save(); } return $this->returnJson(array('success' => true)); } else { return $this->returnJson(array('success' => false)); } }