コード例 #1
0
ファイル: Tour.php プロジェクト: vfrbgt/test-task-yii2
 public function load($data)
 {
     if (isset($data[self::getAdditionForm()])) {
         $this->additionFieldsForm = $data[self::getAdditionForm()];
     }
     return parent::load($data);
 }
コード例 #2
0
ファイル: Model.php プロジェクト: NullRefExcep/yii2-core
 /**
  * @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;
 }
コード例 #3
0
ファイル: ActiveRecord.php プロジェクト: yinheark/yincart2
 public function load($data, $formName = null)
 {
     foreach ($data as $name => $value) {
         $this->tryToSetRelation($name, $value);
     }
     return parent::load($data, $formName);
 }
コード例 #4
0
ファイル: GxActiveRecord.php プロジェクト: dlds/yii2-giixer
 /**
  * @inheritdoc
  */
 public function load($data, $formName = null)
 {
     $data = GxModelHelper::adaptToMassiveAssignment($data, static::className());
     if (false === $formName) {
         $formName = '';
     }
     return parent::load($data, $formName);
 }
コード例 #5
0
ファイル: Widgets.php プロジェクト: worstinme/yii2-widgets
 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);
     }
 }
コード例 #6
0
ファイル: File.php プロジェクト: omnilight/yii2-models
 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;
     }
 }
コード例 #7
0
ファイル: AirQuality.php プロジェクト: Olwn/pm25
 /**
  * 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' => '']);
     }
 }
コード例 #8
0
 /**
  * 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;
 }
コード例 #9
0
ファイル: Transaction.php プロジェクト: alexshadie/wallet
 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;
 }
コード例 #10
0
 /**
  * @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;
 }
コード例 #11
0
 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;
     }
 }
コード例 #12
0
ファイル: Items.php プロジェクト: exelents/test-fornekki
 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]);
         }
     }
 }
コード例 #13
0
ファイル: Controller.php プロジェクト: kalibao/magesko
 /**
  * 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;
 }
コード例 #14
0
 public function load($data, $formName = null)
 {
     if ($res = parent::load($data, $formName)) {
         $this->htmlAttributes = $data['htmlAttributes'];
     }
 }
コード例 #15
0
ファイル: Facet.php プロジェクト: xyxdasnjss/imshop
 /**
  * @inheritdoc
  */
 public function load($data, $formName = null)
 {
     return parent::load($data, $formName) && $this->loadValues($data);
 }
コード例 #16
0
ファイル: BaseNews.php プロジェクト: ChristopheBrun/hLib
 /**
  * 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);
 }
コード例 #17
0
ファイル: Product.php プロジェクト: xyxdasnjss/imshop
 /**
  * @inheritdoc
  */
 public function load($data, $formName = null)
 {
     return parent::load($data, $formName) && $this->loadBehaviors($data) && $this->loadEAttributes($data);
 }
コード例 #18
0
 public function load($data, $formName = null)
 {
     return parent::load($data, '');
 }
コード例 #19
0
ファイル: Tag.php プロジェクト: alexshadie/wallet
 public function create($data, $user)
 {
     $this->user_id = $user;
     return parent::load($data);
 }
コード例 #20
0
ファイル: Answer.php プロジェクト: igribov/question-list
 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;
 }
コード例 #21
0
ファイル: MAdminController.php プロジェクト: e96/yii2-madmin
 /**
  * @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)]);
     }
 }
コード例 #22
0
ファイル: ActiveRecord.php プロジェクト: netis-pl/yii2-crud
 /**
  * @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;
 }
コード例 #23
0
 /**
  * @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;
 }
コード例 #24
0
ファイル: BackendController.php プロジェクト: tolik505/bl
 /**
  * @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;
 }
コード例 #25
0
ファイル: Meta.php プロジェクト: manyoubaby123/imshop
 /**
  * @inheritdoc
  */
 public function load($data, $formName = null)
 {
     return parent::load($data, $formName) && $this->loadSocialMeta($data);
 }
コード例 #26
0
ファイル: User.php プロジェクト: ChristopheBrun/hLib
 /**
  * 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);
 }
コード例 #27
0
 /**
  * (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);
 }