fromId() public static méthode

Initiliaze document from id
public static fromId ( integer $documentId ) : Model
$documentId integer Document id
Résultat Model
Exemple #1
0
 /**
  * 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;
 }
Exemple #2
0
 /**
  * List all comment by document id
  *
  * @return array
  */
 public function documentCommentAction()
 {
     $documentId = $this->params()->fromRoute('id');
     $document = DocumentModel::fromId($documentId);
     if (empty($document)) {
         return $this->redirect()->toRoute('module/blog');
     }
     $model = new Model\Comment();
     $commentList = $model->getList($documentId, null);
     if ($this->getRequest()->isPost()) {
         $comments = $this->getRequest()->getPost()->get('comment');
         foreach ($comments as $commentId => $data) {
             if (!empty($data['delete'])) {
                 $model->delete(array('id' => $commentId));
                 continue;
             }
             foreach ($data as $k => $v) {
                 if (!in_array($k, $this->whiteList)) {
                     unset($data[$k]);
                 }
             }
             $data['show_email'] = empty($data['show_email']) ? 0 : 1;
             $data['is_active'] = empty($data['is_active']) ? 0 : 1;
             $model->update($data, array('id' => $commentId));
         }
         return $this->redirect()->toRoute('module/blog/document-comment', array('id' => $documentId));
     }
     return array('comment_list' => $commentList, 'document' => $document);
 }
Exemple #3
0
 /**
  * Returns document from id.
  *
  * @param mixed $identifier Identifier
  *
  * @return \Gc\Document\Model
  */
 public function __invoke($identifier = '')
 {
     if (is_numeric($identifier)) {
         return DocumentModel::fromId($identifier);
     }
     return DocumentModel::fromUrlKey($identifier);
 }
Exemple #4
0
 /**
  * Return all documents with comment(s)
  *
  * @return array
  */
 public function getDocumentList()
 {
     $allComments = $this->getList(null, null);
     $documents = array();
     foreach ($allComments as $key => $comment) {
         if (empty($documents[$comment['document_id']])) {
             $document = DocumentModel::fromId($comment['document_id']);
             $documents[$document->getId()] = $document;
         }
     }
     return $documents;
 }
Exemple #5
0
 /**
  * Test
  *
  * @return void
  */
 public function testFromFakeId()
 {
     $model = Model::fromId(1000);
     $this->assertFalse($model);
 }
Exemple #6
0
 /** (non-PHPdoc)
  *
  * @see include \Gc\Component\IterableInterface#getParent()
  * @return Model
  */
 public function getParent()
 {
     $parentId = $this->getData('parent_id');
     return Model::fromId($parentId);
 }
Exemple #7
0
 /**
  * Import Documents
  *
  * @param array &$ids     Ids
  * @param array &$errors  Errors
  * @param array $children Children list
  *
  * @return void
  */
 protected function importDocuments(&$ids, &$errors, $children)
 {
     foreach ($children['children'] as $child) {
         $urlKey = (string) $child->url_key;
         $model = Document\Model::fromUrlKey($urlKey);
         $attributes = $child->attributes();
         $id = (int) $attributes['id'];
         if (empty($model)) {
             $model = Document\Model::fromId($id);
             if (empty($model)) {
                 $model = new Document\Model();
             }
         }
         $documentTypeId = isset($ids['document_types'][(int) $child->document_type_id]) ? $ids['document_types'][(int) $child->document_type_id] : $model->getDocumentTypeId();
         $viewId = isset($ids['views'][(int) $child->view_id]) ? $ids['views'][(int) $child->view_id] : $model->getViewId();
         $layoutId = isset($ids['layouts'][(int) $child->layout_id]) ? $ids['layouts'][(int) $child->layout_id] : $model->getLayoutId();
         $parentId = isset($ids['layouts'][(int) $child->parent_id]) ? $ids['layouts'][(int) $child->parent_id] : $model->getParentId();
         $name = (string) $child->name;
         $status = (string) $child->status;
         $userId = (int) $child->user_id;
         $sortOrder = (int) $child->sort_order;
         $showInNav = (int) $child->show_in_nav;
         $model->addData(array('name' => empty($name) ? $model->getName() : $name, 'url_key' => $urlKey, 'status' => empty($status) ? $model->getStatus() : $status, 'show_in_nav' => empty($showInNav) ? $model->getShowInNav() : $showInNav, 'sort_order' => empty($sortOrder) ? $model->getSortOrder() : $sortOrder, 'icon_id' => (int) $child->icon_id, 'view_id' => $viewId, 'parent_id' => $parentId, 'user_id' => $userId, 'layout_id' => $layoutId, 'document_type_id' => empty($documentTypeId) ? $model->getDocumentTypeId() : $documentTypeId));
         if ($model->getUserId() === null) {
             $model->setUserId($this->serviceLocator->get('Auth')->getIdentity()->getId());
         }
         try {
             if (!empty($model)) {
                 $model->save();
                 $ids['documents'][$id] = $model->getId();
                 $values = (array) $child->properties;
                 if (isset($values['property_value']) and is_array($values['property_value'])) {
                     $values = $values['property_value'];
                 }
                 foreach ($values as $value) {
                     $documentId = (int) $value->document_id;
                     $propertyId = (int) $value->property_id;
                     $valueModel = new Property\Value\Model();
                     $valueModel->load(null, isset($ids['documents'][$documentId]) ? $ids['documents'][$documentId] : $documentId, isset($ids['properties'][$propertyId]) ? $ids['properties'][$propertyId] : $propertyId);
                     $valueModel->setValue((string) base64_decode($value->value));
                     $valueModel->save();
                 }
             }
         } catch (Exception $e) {
             $errors[] = sprintf($this->serviceLocator->get('MvcTranslator')->translate('Cannot save document with id (%d)'), $id);
         }
     }
 }
Exemple #8
0
 /**
  * Delete file
  *
  * @return \Zend\View\Model\JsonModel
  */
 public function removeAction()
 {
     $property = Property\Model::fromId($this->getRouteMatch()->getParam('property_id'));
     $document = Document\Model::fromId($this->getRouteMatch()->getParam('document_id'));
     if ($this->getRequest()->getMethod() != 'DELETE' or empty($document) or empty($property)) {
         return $this->returnJson(array('error' => true));
     }
     $file = base64_decode($this->getRouteMatch()->getParam('file'));
     $fileClass = new File();
     $fileClass->load($property, $document);
     return $this->returnJson(array($fileClass->remove($file)));
 }
Exemple #9
0
 /**
  * Sort document action
  *
  * @return \Zend\View\Model\JsonModel
  */
 public function sortOrderAction()
 {
     $order = $this->getRequest()->getPost()->get('order');
     $list = explode(',', str_replace('document_', '', $order));
     foreach ($list as $order => $documentId) {
         $documentModel = DocumentModel::fromId($documentId);
         if (!empty($documentModel)) {
             $documentModel->setSortOrder($order);
             $documentModel->save();
         }
     }
     return $this->returnJson(array('success' => true));
 }
 /**
  * Test
  *
  * @return void
  */
 public function testUnpublishActionWithEnableDocument()
 {
     $this->dispatch('/admin/content/document/unpublish/' . $this->document->getId());
     $this->assertResponseStatusCode(200);
     $this->assertModuleName('GcContent');
     $this->assertControllerName('DocumentController');
     $this->assertControllerClass('DocumentController');
     $this->assertMatchedRouteName('content/document/unpublish');
     $document = DocumentModel::fromId($this->document->getId());
     $this->assertFalse($document->isPublished());
 }
Exemple #11
0
 /**
  * Retrieve document
  *
  * @return \Gc\Document\Model
  */
 public function getDocument()
 {
     if ($this->getData('document') === null) {
         $this->setData('document', DocumentModel::fromId($this->getDocumentId()));
     }
     return $this->getData('document');
 }