fromId() 공개 정적인 메소드

Get model from id
public static fromId ( integer $datatypeId ) : AbstractTable
$datatypeId integer Datatype id
리턴 Gc\Db\AbstractTable
예제 #1
0
파일: Model.php 프로젝트: gotcms/gotcms
 /**
  * Load Datatype
  *
  * @param ServiceManager $serviceManager Service manager
  * @param integer        $datatypeId     Datatype id
  * @param integer        $documentId     Optional document id
  *
  * @return mixed
  */
 public static function loadDatatype(ServiceManager $serviceManager, $datatypeId, $documentId = null)
 {
     $datatype = Model::fromId($datatypeId);
     $class = 'Datatypes\\' . $datatype->getModel() . '\\Datatype';
     $object = new $class();
     $object->setRequest($serviceManager->get('Request'))->setRouter($serviceManager->get('Router'))->setHelperManager($serviceManager->get('viewhelpermanager'))->setDatatypesList($serviceManager->get('DatatypesList'))->load($datatype, $documentId);
     return $object;
 }
예제 #2
0
 /**
  * Delete datatype
  *
  * @return \Zend\View\Model\JsonModel
  */
 public function deleteAction()
 {
     $datatype = Datatype\Model::fromId($this->getRouteMatch()->getParam('id', null));
     if (!empty($datatype) and $datatype->delete()) {
         return $this->returnJson(array('success' => true, 'message' => 'This datatype has been deleted'));
     }
     return $this->returnJson(array('success' => false, 'message' => 'Datatype does not exists'));
 }
예제 #3
0
파일: Content.php 프로젝트: gotcms/gotcms
 /**
  * Import Datatypes
  *
  * @param array &$ids     Ids
  * @param array &$errors  Errors
  * @param array $children Children list
  *
  * @return void
  */
 protected function importDatatypes(&$ids, &$errors, $children)
 {
     foreach ($children['children'] as $child) {
         $attributes = $child->attributes();
         $id = (int) $attributes['id'];
         $model = Datatype\Model::fromId($id);
         if ($model === false) {
             $model = new Datatype\Model();
         }
         $name = (string) $child->name;
         $datatypeModel = (string) $child->model;
         $model->addData(array('name' => empty($name) ? $model->getName() : $name, 'model' => empty($datatypeModel) ? $model->getModel() : $datatypeModel));
         $model->setPrevalueValue((string) $child->prevalue_value);
         try {
             if (!empty($model)) {
                 $model->save();
                 $ids['datatypes'][$id] = $model->getId();
             }
         } catch (Exception $e) {
             $errors[] = sprintf($this->serviceLocator->get('MvcTranslator')->translate('Cannot save datatype with id (%d)'), $id);
         }
     }
 }
예제 #4
0
파일: ModelTest.php 프로젝트: gotcms/gotcms
 /**
  * Test
  *
  * @return void
  */
 public function testFromId()
 {
     $this->assertInstanceOf('Gc\\Datatype\\Model', Model::fromId($this->object->getId()));
     $this->assertFalse(Model::fromId('undefined id'));
 }