/** * 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'); }
/** * Edit document type * * @return \Zend\View\Model\ViewModel|array */ public function editAction() { $documentTypeId = $this->getRouteMatch()->getParam('id'); $documentType = DocumentType\Model::fromId($documentTypeId); if (empty($documentType)) { return $this->redirect()->toRoute('development/document-type/create'); } $form = new DocumentTypeForm(); $form->setAttribute('action', $this->url()->fromRoute('development/document-type/edit', array('id' => $documentTypeId))); $request = $this->getRequest(); $session = $this->getSession(); if (!$request->isPost()) { $form->setValues($documentType); $this->prepareDocumentTypeSession($session, $documentType); } else { $validators = $form->getInputFilter()->get('infos')->get('name')->getValidatorChain()->getValidators(); foreach ($validators as $validator) { if ($validator['instance'] instanceof Validator\Db\NoRecordExists) { $validator['instance']->setExclude(array('field' => 'id', 'value' => $documentType->getId())); } } $postData = $this->getRequest()->getPost()->toArray(); $form->setData($postData); $form->setValues($postData); if (!$form->isValid()) { $this->flashMessenger()->addErrorMessage('Can not save document type'); $this->useFlashMessenger(); } else { $propertyCollection = new Property\Collection(); $input = $form->getInputFilter(); $infosSubform = $input->get('infos'); $viewsSubform = $input->get('views'); $documentType->addData(array('name' => $infosSubform->getValue('name'), 'icon_id' => $infosSubform->getValue('icon_id'), 'description' => $infosSubform->getValue('description'), 'default_view_id' => $viewsSubform->getValue('default_view'))); $documentType->getAdapter()->getDriver()->getConnection()->beginTransaction(); try { $availableViews = $viewsSubform->getValue('available_views'); if (empty($availableViews)) { $availableViews = array(); } $documentType->addViews($availableViews); $documentType->setDependencies($infosSubform->getValue('dependency')); $documentType->save(); $existingTabs = $this->saveTabs($input->get('tabs'), $documentType); $tabCollection = new Tab\Collection(); $tabs = $tabCollection->load($documentType->getId())->getTabs(); foreach ($tabs as $tab) { if (!in_array($tab->getId(), $existingTabs)) { $tab->delete(); } } $existingProperties = $this->saveProperties($input->get('properties'), $existingTabs); $propertyCollection = new Property\Collection(); $properties = $propertyCollection->load($documentType->getId())->getProperties(); foreach ($properties as $property) { if (!in_array($property->getId(), $existingProperties)) { $property->delete(); } } $documentType->getAdapter()->getDriver()->getConnection()->commit(); $this->flashMessenger()->addSuccessMessage('This document type has been saved'); return $this->redirect()->toRoute('development/document-type/edit', array('id' => $documentTypeId)); } catch (Exception $e) { $documentType->getAdapter()->getDriver()->getConnection()->rollBack(); throw new \Gc\Exception('Error Processing Request ' . print_r($e, true), 1); } } } return array('form' => $form); }
/** * Load Document data * * @return string */ public function createDocument() { $documents = new Document\Collection(); $rows = $documents->fetchAll($documents->select(function ($select) { $select->order('sort_order ASC'); $select->order('created_at ASC'); })); if (empty($rows)) { return ''; } $documentArray = array(); foreach ($rows as $row) { $documentArray[] = Document\Model::fromArray((array) $row); } $propertiyCollection = new Property\Collection(); foreach ($documentArray as $document) { $array = array(); $properties = $propertiyCollection->load(null, null, $document->getId())->getProperties(); foreach ($properties as $property) { $value = $property->getValueModel()->getValue(); $property->getValueModel()->setValue(base64_encode($value)); $array[] = $property->getValueModel(); } $document->setProperties($array); } return $documents->toXml($documentArray, 'documents'); }
/** * 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)); } }