public function load($data) { if (isset($data[self::getAdditionForm()])) { $this->additionFieldsForm = $data[self::getAdditionForm()]; } return parent::load($data); }
/** * @param array $data * @param null $formName * @return bool */ public function load($data, $formName = null) { $this->trigger(self::EVENT_BEFORE_LOAD); $result = parent::load($data, $formName); $this->trigger(self::EVENT_AFTER_LOAD); return $result; }
public function load($data, $formName = null) { foreach ($data as $name => $value) { $this->tryToSetRelation($name, $value); } return parent::load($data, $formName); }
/** * @inheritdoc */ public function load($data, $formName = null) { $data = GxModelHelper::adaptToMassiveAssignment($data, static::className()); if (false === $formName) { $formName = ''; } return parent::load($data, $formName); }
public function load($data, $formName = null) { if ($this->widgetModel !== null) { $this->widgetModel->load($data, $formName); return parent::load($data, $formName); } else { return parent::load($data, $formName); } }
public function load($data, $formName = null) { if (parent::load($data, $formName)) { if ($this->scenario == self::SCENARIO_FILE_UPLOAD) { if (!$this->fileUpload instanceof UploadedFile) { $this->fileUpload = UploadedFile::getInstance($this, 'fileUpload'); } } return true; } else { return false; } }
/** * inherite load() function */ public function load($data, $formName = null) { parent::load($data, $formName); if ($this->attributes['time_point']) { $dateTime = \DateTime::createFromFormat("Y-m-d?H:i:s?", $this->attributes['time_point']); $this->setAttributes(['time_point' => $dateTime->format('Y-m-d H:i:s')]); } if (null == $this->attributes['primary_pollutant']) { $this->setAttributes(['primary_pollutant' => '']); } if (null == $this->attributes['quality']) { $this->setAttributes(['quality' => '']); } }
/** * Load owner model and translation models from data. * @param $data * @param null $languages array of languages for loading * @param null $formName * @param null $translationFormName * @return bool */ public function loadWithTranslations($data, $languages, $formName = null, $translationFormName = null) { if ($this->owner->load($data, $formName)) { if (!$languages) { throw new InvalidParamException('Languages must be set.'); } foreach ($languages as $language) { $modelI18n = static::getTranslation($language); $modelI18n->load($data, $translationFormName); } return true; } return false; }
public function load($data, $formName = null) { $loaded = parent::load($data, $formName); if (!$this->date) { $this->date = date('Y-m-d H:i:s'); } else { $this->date = date('Y-m-d H:i:s', strtotime($this->date)); } $scope = $formName === null ? $this->formName() : $formName; if (isset($data[$scope])) { if (isset($data[$scope]['outgoing'])) { foreach ($data[$scope]['outgoing'] as $key => $outgoing) { if (isset($this->outgoings[$key])) { $loaded &= $this->outgoings[$key]->load($outgoing, ''); } else { $out = new TransactionOutgoing(); $out->id = $key; $loaded &= $out->load($outgoing, ''); $this->outgoings[] = $out; } } } if (isset($data[$scope]['incoming'])) { foreach ($data[$scope]['incoming'] as $key => $incoming) { if (isset($this->incomings[$key])) { $loaded &= $this->incomings[$key]->load($incoming, ''); } else { $in = new TransactionIncoming(); $in->id = $key; $loaded &= $in->load($incoming, ''); $this->incomings[] = $in; } } } if (isset($data[$scope]['expense'])) { foreach ($data[$scope]['expense'] as $key => $expense) { if (isset($this->expenses[$key])) { $loaded &= $this->expenses[$key]->load($expense, ''); } else { $exp = new TransactionExpense(); $exp->id = $key; $loaded &= $exp->load($expense, ''); $this->expenses[] = $exp; } } } } return $loaded; }
/** * @param ActiveRecord $model * @param array $opts * @return ActiveQuery | array */ static function searchQuery($model, $opts = []) { $opts = ArrayHelper::merge(['data' => null, 'query' => null, 'columns' => [], 'filters' => []], $opts); $columns = $opts['columns']; $filters = $opts['filters']; $data = $opts['data']; if (null === $data) { $data = \Yii::$app->request->get(); } $query = $opts['query']; if (is_string($query)) { $query = call_user_func([$model, $opts['query']]); } elseif (null === $query) { $query = $model->find(); foreach (array_filter($model->getAttributes()) as $prop => $val) { $query->andWhere([$prop => $val]); } } if ($model->load($data) && $model->validate()) { foreach ($model->getAttributes($model->safeAttributes()) as $name => $value) { if ($model->isAttributeChanged($name)) { $attributeTypes = []; if (method_exists($model, 'attributeTypes')) { $attributeTypes = $model->attributeTypes(); } $type = null; if (isset($attributeTypes[$name])) { $type = $attributeTypes[$name]; } // Default filter function $filterFunc = isset($filters[$name]) && is_callable($filters[$name]) ? $filters[$name] : function (ActiveQuery $query, $name, $value, $type) { /** * @var string $name * @var string|array $value * @var string $type */ $query->andFilterWhere(static::searchAttribute($name, $value, $type)); }; if (isset($columns[$name])) { $name = $columns[$name]; } call_user_func($filterFunc, $query, $name, $value, $type); } } } return $query; }
public function load($data, $formName = null) { if (parent::load($data, $formName)) { $scope = $formName === null ? $this->formName() : $formName; if ($scope) { $data = $data[$scope]; } $extraFields = $this->parseExtraField(); foreach ($data as $attr => $value) { if (in_array($attr, $extraFields)) { $this->{$attr} = $value; } } return true; } else { return false; } }
public function load($data, $formName = null) { parent::load($data, $formName); if (!(Yii::$app->user->id > 0)) { $this->addError('seller_id'); return; } //print_r($this); die(); //print_r($data); die(); //$this->id = $data['id']; $this->title = $data['title']; $this->description = $data['description']; $this->img_url = $data['img_url']; $this->price = (int) $data['price']; $this->seller_id = Yii::$app->user->id; $this->trash = 0; $this->categoriesArr = explode('_', $data['selected_categories']); foreach ($this->categoriesArr as $k => $v) { if (!((int) $v > 0)) { unset($this->categoriesArr[$k]); } } }
/** * Save model of settings * @param ActiveRecord $model Model to save * @param array $requestParams Request parameters * @return bool */ protected function saveSettingsModel(ActiveRecord $model, array $requestParams) { $success = false; $transaction = $model->getDb()->beginTransaction(); try { $model->load($requestParams); if ($model->save()) { $transaction->commit(); Yii::$app->interfaceSettings->refreshUserInterfaceSettings($model->user_id, $model->interface_id); $success = true; } else { throw new Exception(); } } catch (Exception $e) { if ($transaction->isActive) { $transaction->rollBack(); } } // trigger an event $this->trigger(self::EVENT_SAVE_SETTING, new ExtraDataEvent(['extraData' => ['model' => $model, 'success' => $success]])); return $success; }
public function load($data, $formName = null) { if ($res = parent::load($data, $formName)) { $this->htmlAttributes = $data['htmlAttributes']; } }
/** * @inheritdoc */ public function load($data, $formName = null) { return parent::load($data, $formName) && $this->loadValues($data); }
/** * Assignation en masse des attributs avec prise en compte de la liste des ids des tags * todo_cbn cf. issue #20 * * @inheritdoc */ public function load($data, $formName = null) { $this->updatedBaseTagsIds = ArrayHelper::getValue($data, 'BaseNews.baseTags', []); if ($this->updatedBaseTagsIds === "") { $this->updatedBaseTagsIds = []; } return parent::load($data, $formName); }
/** * @inheritdoc */ public function load($data, $formName = null) { return parent::load($data, $formName) && $this->loadBehaviors($data) && $this->loadEAttributes($data); }
public function load($data, $formName = null) { return parent::load($data, ''); }
public function create($data, $user) { $this->user_id = $user; return parent::load($data); }
public function load($data, $formName = null) { $result = parent::load($data, $formName); $oldAttributes = $this->getOldAttributes(); $isChange = $data['answer'] != $oldAttributes['answer'] || $data['answer_comment'] != $oldAttributes['answer_comment']; if ($isChange) { $this->profile_id = Yii::$app->user->identity->username; } return $this->validate() && $result; }
/** * @param ActiveRecord $model * @return string|\yii\web\Response */ protected function editModel($model) { // validate() && save(false) because of CantSave exception if ($model->load(Yii::$app->request->post()) && $model->validate() && $model->save(false)) { return $this->redirect($this->getReturnUrl()); } else { return $this->render($this->formView, ['model' => $model, 'returnUrl' => $this->getReturnUrl(), 'modelTitleForms' => $this->modelTitleForms, 'formElements' => $this->getFormElements($model)]); } }
/** * @inheritdoc */ public function load($data, $formName = null) { if (!parent::load($data, $formName)) { return false; } $scope = $formName === null ? $this->formName() : $formName; $attributes = []; if ($scope === '' && !empty($data)) { $attributes = array_keys($data); } elseif (isset($data[$scope])) { $attributes = array_keys($data[$scope]); } //filter only those attributes that was set $this->filterAttributes($attributes); return true; }
/** * @inheritdoc */ public function load($data, $formName = null) { $load = parent::load($data, $formName); if (!empty($this->skipValidation)) { $attribute = $this->skipValidation; $this->validate([$attribute]); } $load = empty($this->skipValidation) && $load; return $load; }
/** * @param \yii\db\ActiveRecord $model * * @return bool */ public function loadModels($model) { $loaded = true; if ($model instanceof \common\components\model\Translateable) { $languages = LanguageHelper::getLanguageModels(); $models = []; foreach ($languages as $language) { if ($language->locale === LanguageHelper::getDefaultLanguage()->locale) { continue; } $models[$language->locale] = $model->getTranslation($language->locale); } if (!empty($models)) { $loaded &= Model::loadMultiple($models, Yii::$app->request->post()); } } $loaded = $model->load(Yii::$app->request->post()) && $loaded; return $loaded; }
/** * @inheritdoc */ public function load($data, $formName = null) { return parent::load($data, $formName) && $this->loadSocialMeta($data); }
/** * Assignation de masse des attributs avec prise en compte de la liste des ids des rôles * * @inheritdoc */ public function load($data, $formName = null) { $this->updatedRolesIds = hArray::getValue($data, 'User.roles'); if ($this->updatedRolesIds === "") { $this->updatedRolesIds = []; } return parent::load($data, $formName); }
/** * (non-PHPdoc) * @see \yii\base\Model::load($data, $formName) * @throws Exception if the current record is read only */ public function load($data, $formName = null) { if ($this->getReadOnly()) { throw new Exception('Attempting to load attributes on a read only ' . Tools::getClassName($this) . ' model'); } if ($this->getIsNewRecord() && $this->applyDefaults && !$this->defaultsApplied) { $this->applyDefaults(false); } return parent::load($data, $formName); }