Inheritance: extends Gc\Db\AbstractTable
Exemple #1
0
 /**
  * Create document
  *
  * @return \Zend\View\Model\ViewModel|array
  */
 public function createAction()
 {
     $documentForm = new Form\DocumentInformation();
     $parentId = $this->getRouteMatch()->getParam('id');
     if (!empty($parentId)) {
         $routeName = 'content/document/create-w-parent';
     } else {
         $routeName = 'content/document/create';
     }
     $documentForm->setAttribute('action', $this->url()->fromRoute($routeName, array('id' => $parentId)));
     $documentTypeCollection = new DocumentType\Collection();
     $documentTypeElement = $documentForm->get('document_type');
     if (empty($parentId)) {
         $documentTypeElement->setValueOptions(array('' => 'Select document type') + $documentTypeCollection->getSelect());
     } else {
         $documentForm->get('parent')->setValue($parentId);
         $documentTypeCollection->init(DocumentModel::fromId($parentId)->getDocumentTypeId());
         $documentTypeElement->setValueOptions(array('' => 'Select document type') + $documentTypeCollection->getSelect());
     }
     if ($this->getRequest()->isPost()) {
         $documentForm->getInputFilter()->add(array('required' => true, 'validators' => array(array('name' => 'not_empty'))), 'document_type');
         $documentForm->setData($this->getRequest()->getPost()->toArray());
         if (!$documentForm->isValid()) {
             $this->flashMessenger()->addErrorMessage('Invalid document data');
             $this->useFlashMessenger();
         } else {
             $documentName = $documentForm->getValue('document-name');
             $documentUrlKey = $documentForm->getValue('document-url_key');
             $documentTypeId = $documentForm->getValue('document_type');
             $parentId = $documentForm->getValue('parent');
             $document = new DocumentModel();
             $document->setName($documentName)->setDocumentTypeId($documentTypeId)->setParentId($parentId)->setUrlKey(!empty($documentUrlKey) ? $documentUrlKey : $this->checkUrlKey($documentName))->setUserId($this->getServiceLocator()->get('Auth')->getIdentity()->getId());
             $document->save();
             $this->flashMessenger()->addSuccessMessage('This document has been saved');
             $this->redirect()->toRoute('content/document/edit', array('id' => $document->getId()));
         }
     }
     return array('form' => $documentForm);
 }
 /**
  * List all document types
  *
  * @return \Zend\View\Model\ViewModel|array
  */
 public function indexAction()
 {
     $documents = new DocumentType\Collection();
     return array('documents' => $documents->getDocumentTypes());
 }
Exemple #3
0
 /**
  * Load Document type data
  *
  * @return string
  */
 public function createDocumentType()
 {
     $documentTypesCollection = new DocumentType\Collection();
     $array = $documentTypesCollection->getDocumentTypes();
     if (empty($array)) {
         return '';
     }
     foreach ($documentTypesCollection->getDocumentTypes() as $documentType) {
         //Preload dependencies
         $children = array();
         $dependencies = $documentType->getDependencies();
         foreach ($dependencies as $dependency) {
             $children[] = array('id' => $dependency);
         }
         $documentType->setData('dependencies', $children);
         //Preload available views
         $children = array();
         $availableViews = $documentType->getAvailableViews()->getViews();
         foreach ($availableViews as $view) {
             $children[] = array('id' => $view->getId());
         }
         $documentType->setData('available_views', $children);
         foreach ($documentType->getTabs() as $tab) {
             //Preload Tabs
             foreach ($tab->getProperties() as $property) {
                 //Preload Properties
             }
         }
     }
     return $documentTypesCollection->toXml($documentTypesCollection->getDocumentTypes(), 'document_types');
 }
Exemple #4
0
 /**
  * Test
  *
  * @return void
  */
 public function testGetSelect()
 {
     $this->object->init();
     $this->assertInternalType('array', $this->object->getSelect());
 }
Exemple #5
0
 /**
  * Initialize infos sub form
  *
  * @return \Zend\Form\FieldSet
  */
 protected function getInfos()
 {
     $fieldsets = $this->getFieldSets();
     if (!empty($fieldsets['infos'])) {
         return $fieldsets['infos'];
     }
     $fieldsets = new FieldSet('infos');
     $this->getInputFilter()->add(array('type' => 'Zend\\InputFilter\\InputFilter', 'name' => array('name' => 'name', 'required' => true, 'validators' => array(array('name' => 'not_empty'), array('name' => 'db\\no_record_exists', 'options' => array('table' => 'document_type', 'field' => 'name', 'adapter' => $this->getAdapter())))), 'description' => array('name' => 'description', 'required' => false, 'allow_empty' => true), 'icon_id' => array('name' => 'icon_id', 'required' => true, 'allow_empty' => false), 'dependency' => array('name' => 'dependency', 'required' => false, 'allow_empty' => true)), 'infos');
     $fieldsets->add(new Element\Text('name'));
     $fieldsets->add(new Element\Text('description'));
     $iconId = new Element\Select('icon_id');
     $collection = new Icon\Collection();
     $iconId->setValueOptions($collection->getIcons())->setAttribute('class', 'form-control');
     $fieldsets->add($iconId);
     $documentTypeCollection = new DocumentTypeCollection();
     $select = $documentTypeCollection->getSelect();
     if (!empty($select)) {
         $dependency = new Element\MultiCheckbox('infos[dependency]');
         $dependency->setAttribute('class', 'input-checkbox');
         $dependency->setValueOptions($documentTypeCollection->getSelect());
         $fieldsets->add($dependency);
     }
     $this->add($fieldsets);
     return $fieldsets;
 }