/** * Returns documents * $data can be mixed * if data is an array, return all documents * if data is numeric, return all documents with parent_id equal to $data * if data is string, return all documents with parent's url key equal to $data * * @param mixed $data Data * * @return array \Gc\Document\Model */ public function __invoke($data = null) { $elements = array(); $documents = new DocumentCollection(); if (empty($data)) { $elements = $documents->load(0)->getDocuments(); } else { if (is_numeric($data)) { $elements = $documents->load($data)->getDocuments(); } elseif (is_string($data)) { $document = DocumentModel::fromUrlKey($data); $elements = $document->getChildren(); } elseif (is_array($data)) { foreach ($data as $documentId) { if (empty($documentId)) { continue; } $document = $this->getView()->document($documentId); if (!empty($document)) { $elements[] = $document; } } } } return $elements; }
/** * Initialize General sub form * * @return Config */ public function initGeneral() { //General settings $generalFieldset = new Fieldset('general'); $generalFieldset->setLabel('General'); $name = new Element\Text('site_name'); $name->setLabel('Site name')->setLabelAttributes(array('class' => 'required control-label col-lg-2'))->setAttribute('id', 'site_name')->setAttribute('class', 'form-control'); $generalFieldset->add($name); $this->getInputFilter()->add(array('name' => 'site_name', 'required' => true, 'validators' => array(array('name' => 'not_empty'))), 'site_name'); $isOffline = new Element\Checkbox('site_is_offline'); $isOffline->setLabel('Is offline')->setLabelAttributes(array('class' => 'required control-label col-lg-2'))->setAttribute('class', 'input-checkbox')->setAttribute('id', 'site-offiline')->setCheckedValue('1'); $generalFieldset->add($isOffline); $this->getInputFilter()->add(array('name' => 'site_is_offline', 'required' => false), 'site_is_offline'); $documentCollection = new Document\Collection(); $documentCollection->load(0); $offlineDocument = new Element\Select('site_offline_document'); $offlineDocument->setLabel('Offline document')->setLabelAttributes(array('class' => 'required control-label col-lg-2'))->setAttribute('class', 'form-control')->setAttribute('id', 'site_offline_document')->setValueOptions(array('Select document') + $documentCollection->getSelect()); $generalFieldset->add($offlineDocument); $this->getInputFilter()->add(array('name' => 'site_offline_document', 'required' => true), 'site_offline_document'); $layoutCollection = new Layout\Collection(); $layoutNotFound = new Element\Select('site_404_layout'); $layoutNotFound->setLabel('404 layout')->setLabelAttributes(array('class' => 'required control-label col-lg-2'))->setAttribute('class', 'form-control')->setAttribute('id', 'site_404_layout')->setValueOptions(array('Select document') + $layoutCollection->getSelect()); $generalFieldset->add($layoutNotFound); $this->getInputFilter()->add(array('name' => 'site_404_layout', 'required' => true), 'site_404_layout'); $layoutException = new Element\Select('site_exception_layout'); $layoutException->setLabel('Exception layout')->setLabelAttributes(array('class' => 'required control-label col-lg-2'))->setAttribute('class', 'form-control')->setAttribute('id', 'site_exception_layout')->setValueOptions(array('Select document') + $layoutCollection->getSelect()); $generalFieldset->add($layoutException); $this->getInputFilter()->add(array('name' => 'site_exception_layout', 'required' => true), 'site_exception_layout'); $this->add($generalFieldset); return $this; }
/** * Constructor, initialize documents * * @param integer $documentId Document id * @param boolean $activeBranch Use active branch or not */ public function __construct($documentId = 0, $activeBranch = false) { $documents = new Document\Collection(); $documents->load($documentId); $this->documents = $documents->getDocuments(); $this->requestUri = Registry::get('Application')->getRequest()->getUri()->getPath(); $this->useActiveBranch = (bool) $activeBranch; }
/** * Initialize Document Controller * * @return void */ public function init() { $documents = new DocumentCollection(); $documents->load(0); $this->layout()->setVariable('treeview', Component\TreeView::render(array($documents))); $routes = array('edit' => 'content/document/edit', 'new' => 'content/document/create', 'delete' => 'content/document/delete', 'copy' => 'content/document/copy', 'cut' => 'content/document/cut', 'paste' => 'content/document/paste', 'publish' => 'content/document/publish', 'unpublish' => 'content/document/unpublish', 'refresh' => 'content/document/refresh-treeview'); $arrayRoutes = array(); foreach ($routes as $key => $route) { $arrayRoutes[$key] = $this->url()->fromRoute($route, array('id' => 'itemId')); } $this->layout()->setVariable('routes', Json::encode($arrayRoutes)); }
/** * Test * * @return void */ public function testGetAvailableChilren() { $this->object->load(0); $this->assertInternalType('array', $this->object->getAvailableChildren()); }
/** * Test * * @return void */ public function testRender() { Registry::get('Application')->getRequest()->getUri()->setPath($this->documentChildren->getEditUrl()); $collection = new DocumentCollection(); $collection->load(0); $array = array_merge(array($collection), array('test' => 'value')); $this->assertTrue(strlen($this->object->render($array)) > 0); }
/** * Test * * @return void */ public function testRenderWithIterableInterface() { $view = ViewModel::fromArray(array('name' => 'View Name', 'identifier' => 'View identifier', 'description' => 'View Description', 'content' => 'View Content')); $view->save(); $layout = LayoutModel::fromArray(array('name' => 'Layout Name', 'identifier' => 'Layout identifier', 'description' => 'Layout Description', 'content' => 'Layout Content')); $layout->save(); $user = UserModel::fromArray(array('lastname' => 'User test', 'firstname' => 'User test', 'email' => '*****@*****.**', 'login' => 'test', 'user_acl_role_id' => 1)); $user->setPassword('test'); $user->save(); $documentType = DocumentTypeModel::fromArray(array('name' => 'Document Type Name', 'description' => 'Document Type description', 'icon_id' => 1, 'defaultview_id' => $view->getId(), 'user_id' => $user->getId())); $documentType->save(); $document = DocumentModel::fromArray(array('name' => 'Document name', 'url_key' => 'url-key', 'status' => DocumentModel::STATUS_ENABLE, 'show_in_nav' => true, 'user_id' => $user->getId(), 'document_type_id' => $documentType->getId(), 'view_id' => $view->getId(), 'layout_id' => $layout->getId(), 'parent_id' => 0)); $document->save(); $collection = new DocumentCollection(); $collection->load(0); $this->assertEquals(sprintf('<ul><li><a href="#tabs-%d">Document name</a></li></ul>', $document->getId()), $this->object->render($collection->getChildren())); $document->delete(); $documentType->delete(); $layout->delete(); $view->delete(); $user->delete(); }
/** (non-PHPdoc) * * @see include \Gc\Component\IterableInterface#getChildren() * @return array */ public function getChildren() { if ($this->getData('children') === null) { $children = new Collection(); $children->load($this->getId()); $this->setData('children', $children->getChildren()); } return $this->getData('children'); }
/** * Refresh treeview * * @return \Zend\View\Model\ViewModel */ public function refreshTreeviewAction() { $documentId = $this->getRouteMatch()->getParam('id', 0); if (empty($documentId)) { $documents = new DocumentCollection(); $documents->load($documentId); $documentsList = $documents->getChildren(); } else { $documents = DocumentModel::fromId($documentId); $documentsList = $documents->getChildren(); } return $this->returnJson(array('treeview' => Component\TreeView::render($documentsList, false))); }