fromId() публичный статический Метод

Initialize from id
public static fromId ( integer $tabId ) : Model
$tabId integer Tab id
Результат Model
Пример #1
0
 /**
  * Add tab in session
  *
  * @return \Zend\View\Model\JsonModel
  */
 public function importTabAction()
 {
     if (!$this->getRequest()->isPost()) {
         return $this->returnJson(array('success' => false, 'message' => 'Error'));
     }
     $tabId = $this->getRequest()->getPost()->get('tab_id');
     $tabModel = Tab\Model::fromId($tabId);
     $propertiesList = $tabModel->getProperties();
     $properties = array();
     foreach ($propertiesList as $property) {
         $properties[] = array('name' => $property->getName(), 'identifier' => $property->getIdentifier(), 'description' => $property->getDescription(), 'datatype' => $property->getDatatypeId(), 'isRequired' => $property->isRequired());
     }
     $tab = array('name' => $tabModel->getName(), 'description' => $tabModel->getDescription(), 'properties' => $properties);
     return $this->returnJson(array('success' => true, 'tab' => $tab));
 }
Пример #2
0
 /**
  * Test
  *
  * @return void
  */
 public function testFromIdWithWrongValues()
 {
     $this->assertFalse(Model::fromId('undefined'));
 }
Пример #3
0
 /**
  * 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;
 }