コード例 #1
0
ファイル: DatatypeController.php プロジェクト: gotcms/gotcms
 /**
  * Create Datatype
  *
  * @return \Zend\View\Model\ViewModel|array
  */
 public function createAction()
 {
     $datatype = new Datatype\Model();
     $datatypeForm = new DatatypeForm();
     $datatypeForm->setAttribute('action', $this->url()->fromRoute('development/datatype/create'));
     if ($this->getRequest()->isPost()) {
         $post = $this->getRequest()->getPost()->toArray();
         $datatypeForm->setData($post);
         if (!$datatypeForm->isValid()) {
             $this->flashMessenger()->addErrorMessage('Can not save datatype');
             $this->useFlashMessenger();
         } else {
             $datatype->addData($datatypeForm->getInputFilter()->getValues());
             try {
                 $id = $datatype->save();
                 $this->flashMessenger()->addSuccessMessage('This datatype has been saved');
                 return $this->redirect()->toRoute('development/datatype/edit', array('id' => $id));
             } catch (Exception $e) {
                 throw new \Gc\Exception($e->getMessage(), $e->getCode(), $e);
             }
         }
     }
     return array('form' => $datatypeForm);
 }
コード例 #2
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);
         }
     }
 }