コード例 #1
0
 public static function create(array $attributes)
 {
     if (!array_get($attributes, 'module')) {
         throw new Exception("Module name should be passed!");
     }
     if (!array_get($attributes, 'parent_id')) {
         throw new Exception("parent_id should be passed!");
     }
     $langs = ci()->translate->languages_admin();
     $count = 0;
     $count_success = 0;
     foreach ($langs as $lang_slug => $lang) {
         $keys = filter_by_key_suffix($attributes, '_' . $lang_slug, true);
         foreach ($keys as $key => $val) {
             ++$count;
             $input = array('key' => $key, 'val' => $val, 'lang' => $lang_slug);
             $input['uid'] = (int) array_get($attributes, 'uid');
             $input['module'] = $attributes['module'];
             $input['parent_id'] = $attributes['parent_id'];
             if ($obj = parent::create($input)) {
                 ++$count_success;
             }
         }
     }
     return $count === $count_success;
 }
コード例 #2
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $input = \Input::all();
     $validation = \Validator::make($input, $this->getRules());
     if ($validation->passes()) {
         $record = $this->Model->create($input);
         return \Redirect::route($this->routeName . 'show', $record->getKey());
     }
     return \Redirect::route($this->routeName . 'create')->withInput()->withErrors($validation);
 }
コード例 #3
0
ファイル: Post.php プロジェクト: doptor/doptor
 /**
  * When creating a post, run the attributes through a validator first.
  * @param array $attributes
  * @return void
  */
 public static function create(array $attributes = array())
 {
     App::make('Components\\Posts\\Validation\\PostValidator')->validateForCreation($attributes);
     $extras = array();
     $extras['contact_page'] = isset($attributes['contact']);
     $extras['contact_coords'] = isset($attributes['contact_coords']) ? $attributes['contact_coords'] : '';
     $attributes['extras'] = json_encode($extras);
     $attributes['featured'] = isset($attributes['featured']) ? true : false;
     $attributes['created_by'] = current_user()->id;
     return parent::create($attributes);
 }
コード例 #4
0
 public static function create(array $attributes)
 {
     if (static::$updateByDefault) {
         $model = new static($attributes);
         $existing = $model->findUnique();
         if ($existing) {
             $existing->fill($attributes);
             $existing->save();
             return $existing;
         }
     }
     return parent::create($attributes);
 }
コード例 #5
0
 public static function create(array $attributes)
 {
     $success = false;
     if ($results = parent::create($attributes)) {
         $parent_id = $results->getAttribute('id');
         $uid = (int) $results->getAttribute('uid');
         $translated = filter_by_key_prefix($attributes, 'translated_', true);
         $translated['uid'] = $uid;
         $translated['module'] = strtolower(get_called_class());
         $translated['parent_id'] = $parent_id;
         // we create child translated
         $success = EloquentTranslatedModel::create($translated);
     }
     return $success ? $results : false;
 }
コード例 #6
0
ファイル: FormEntry.php プロジェクト: jrafaelca/Doptor
 public static function create(array $attributes = array())
 {
     // dd($attributes);
     static::isValid($attributes);
     if (isset($attributes['captcha'])) {
         // Do not save the value of captcha to database
         unset($attributes['captcha']);
     }
     unset($attributes['_token']);
     $entry['form_id'] = $attributes['form_id'];
     unset($attributes['form_id']);
     $form = BuiltForm::findOrFail($entry['form_id']);
     $module_builder = new Services\ModuleBuilder();
     $form_fields = $module_builder->getFormFields($form->data);
     $fields = array_combine($form_fields['fields'], $form_fields['field_names']);
     $entry['data'] = json_encode($attributes);
     $entry['fields'] = json_encode($fields);
     // dd($entry);
     return parent::create($entry);
 }
コード例 #7
0
ファイル: Category.php プロジェクト: doptor/doptor
 /**
  * When creating a post, run the attributes through a validator first.
  * @param array $attributes
  * @return void
  */
 public static function create(array $attributes = array())
 {
     App::make('Components\\Posts\\Validation\\CategoryValidator')->validateForCreation($attributes);
     $attributes['created_by'] = current_user()->id;
     return parent::create($attributes);
 }
コード例 #8
0
ファイル: ThemeSetting.php プロジェクト: doptor/doptor
 /**
  * When creating a theme, run the attributes through a validator first.
  * @param array $attributes
  * @return void
  */
 public static function create(array $attributes = array())
 {
     $attributes['created_by'] = current_user()->id;
     return parent::create($attributes);
 }
コード例 #9
0
ファイル: BaseModel.php プロジェクト: gtcrais/gtcms
 public static function create(array $data = [])
 {
     $fullEntity = get_called_class();
     $reflection = new \ReflectionClass($fullEntity);
     $entity = $reflection->getShortName();
     $modelConfig = AdminHelper::modelExists($entity);
     if (!$modelConfig) {
         throw new \Exception("Model config for entity " . $entity . " doesn't exist.");
     }
     if ($modelConfig->index == 'tree') {
         $depth = 0;
         $parentData = (new static())->getParentData();
         if ($parentData['parentObject']) {
             $depth = $parentData['parentObject']->depth + 1;
         }
         $maxPos = static::getMaxPos('position', $parentData);
         $data['depth'] = $depth;
         $data['position'] = $maxPos + 1;
         if ($parentData['parentIdProperty'] && $parentData['parentId']) {
             $data[$parentData['parentIdProperty']] = $parentData['parentId'];
         } else {
             if ($depth > 0) {
                 throw new \Exception('Tree structure view: $parentData["parentIdProperty"] OR $parentData["parentId"] is false!');
             }
         }
     } else {
         if ($modelConfig->position) {
             $maxPos = static::getMaxPos('position', false);
             $data['position'] = $maxPos + 1;
         }
     }
     return parent::create($data);
 }
コード例 #10
0
 /**
  * Create a new item
  * @return Model
  */
 public function create()
 {
     $model = $this->model->create($this->getInput());
     return $model;
 }