fromId() public static method

Get model from id
public static fromId ( integer $documentTypeId ) : Model
$documentTypeId integer Document type id
return Model
示例#1
0
 /**
  * Load tabs from document type
  *
  * @param integer $documentTypeId Document type id
  *
  * @return array
  */
 public function loadTabs($documentTypeId)
 {
     if (empty($this->tabs[$documentTypeId])) {
         $documentType = DocumentType\Model::fromId($documentTypeId);
         $tabs = $documentType->getTabs();
         $this->tabs[$documentTypeId] = $tabs;
     }
     return $this->tabs[$documentTypeId];
 }
示例#2
0
 /**
  * Test
  *
  * @return void
  */
 public function testFromFakeId()
 {
     $model = Model::fromId(1000);
     $this->assertFalse($model);
 }
示例#3
0
 /**
  * Delete Document type
  *
  * @return \Zend\View\Model\JsonModel
  */
 public function deleteAction()
 {
     $documentType = DocumentType\Model::fromId($this->getRouteMatch()->getParam('id', null));
     if (!empty($documentType) and $documentType->delete()) {
         return $this->returnJson(array('success' => true, 'message' => 'This document type has been deleted'));
     }
     return $this->returnJson(array('success' => false, 'message' => 'Document type does not exists'));
 }
示例#4
0
文件: Model.php 项目: gotcms/gotcms
 /**
  * Get Document type
  *
  * @return \Gc\DocumentType\Model
  */
 public function getDocumentType()
 {
     if ($this->getData('document_type') === null) {
         $this->setData('document_type', \Gc\DocumentType\Model::fromId($this->getDocumentTypeId()));
     }
     return $this->getData('document_type');
 }
示例#5
0
文件: Content.php 项目: gotcms/gotcms
 /**
  * Import Document types
  *
  * @param array &$ids     Ids
  * @param array &$errors  Errors
  * @param array $children Children list
  *
  * @return void
  */
 protected function importDocumentTypes(&$ids, &$errors, $children)
 {
     $documentTypes = array();
     foreach ($children['children'] as $child) {
         $attributes = $child->attributes();
         $id = (int) $attributes['id'];
         $model = DocumentType\Model::fromId($id);
         if (empty($model)) {
             $model = new DocumentType\Model();
         }
         $viewid = isset($ids['views'][(int) $child->default_view_id]) ? $ids['views'][(int) $child->default_view_id] : (int) $child->default_view_id;
         $name = (string) $child->name;
         $model->addData(array('name' => empty($name) ? $model->getName() : $name, 'description' => (string) $child->description, 'icon_id' => (int) $child->icon_id, 'default_view_id' => $viewid));
         if ($model->getUserId() === null) {
             $model->setUserId($this->serviceLocator->get('Auth')->getIdentity()->getId());
         }
         try {
             if (!empty($model)) {
                 $model->save();
                 $tabs = (array) $child->tabs;
                 if (isset($tabs['tab']) and is_array($tabs['tab'])) {
                     $tabs = $tabs['tab'];
                 }
                 foreach ($tabs as $tab) {
                     $tabAttributes = $tab->attributes();
                     $tabId = (int) $tabAttributes['id'];
                     $tabModel = Tab\Model::fromId($tabId);
                     if (empty($tabModel)) {
                         $tabModel = new Tab\Model();
                     }
                     $tabModel->addData(array('name' => (string) $tab->name, 'description' => (string) $tab->description, 'sort_order' => (int) $tab->sort_order, 'document_type_id' => $model->getId()));
                     $tabModel->save();
                     $properties = (array) $tab->properties;
                     if (isset($properties['property']) and is_array($properties['property'])) {
                         $properties = $properties['property'];
                     }
                     foreach ($properties as $property) {
                         $propAttributes = $property->attributes();
                         $propertyId = (int) $propAttributes['id'];
                         $propertyModel = Property\Model::fromId($propertyId);
                         if (empty($propertyModel)) {
                             $propertyModel = new Property\Model();
                         }
                         $datatypeId = isset($ids['datatypes'][(int) $property->datatype_id]) ? $ids['datatypes'][(int) $property->datatype_id] : (string) $property->datatype_id;
                         $propertyModel->addData(array('name' => (string) $property->name, 'description' => (string) $property->description, 'identifier' => (string) $property->identifier, 'sort_order' => (int) $property->sort_order, 'tab_id' => $tabModel->getId(), 'datatype_id' => $datatypeId));
                         $propertyModel->save();
                         $ids['properties'][$propertyId] = $propertyModel->getId();
                     }
                 }
                 $ids['document_types'][$id] = $model->getId();
                 $documentTypes[] = array('model' => $model, 'dependencies' => (array) $child->dependencies, 'views' => (array) $child->available_views);
             }
         } catch (Exception $e) {
             $errors[] = sprintf($this->serviceLocator->get('MvcTranslator')->translate('Cannot save document type with id (%d)'), $id);
         }
     }
     return $documentTypes;
 }