/**
  * @inheritdoc
  */
 public function init()
 {
     if (!$this->modelClass) {
         throw new InvalidArgumentException('Param "modelClass" must be non-empty');
     }
     if (!is_subclass_of($this->modelClass, 'voskobovich\\base\\interfaces\\ModelInterface')) {
         throw new InvalidArgumentException('Param "modelClass" must be extend "voskobovich\\base\\interfaces\\ModelInterface"');
     }
     $this->_model = Yii::createObject($this->modelClass);
     $this->_model->setAttributes($this->initAttributes);
     parent::init();
 }
Beispiel #2
0
 /**
  * rewrite set attributes, set relation data to relations, auto save at after save
  * @inheritdoc
  */
 public function setAttributes($values, $safeOnly = true)
 {
     if (is_array($values)) {
         foreach ($values as $name => $value) {
             $this->tryToSetRelation($name, $value);
         }
     }
     parent::setAttributes($values, $safeOnly);
 }
Beispiel #3
0
 public function setAttributes($values, $safeOnly = true)
 {
     if (is_array($values)) {
         foreach ($values as $key => $value) {
             if (is_array($value)) {
                 unset($values[$key]);
             }
         }
     }
     parent::setAttributes($values, $safeOnly);
 }
Beispiel #4
0
 /**
  * Extends setAttributes to handle active date fields
  *
  * @param $values array
  * @param $safeOnly boolean
  */
 public function setAttributes($values, $safeOnly = true)
 {
     foreach ($this->widgetAttributes() as $fieldName => $className) {
         $className = '\\marsoltys\\yii2user\\components\\' . $className;
         if (isset($values[$fieldName]) && class_exists($className)) {
             $class = new $className();
             $arr = $this->widgetParams($fieldName);
             if ($arr) {
                 $newParams = $class->params;
                 $arr = (array) Json::decode($arr);
                 foreach ($arr as $p => $v) {
                     if (isset($newParams[$p])) {
                         $newParams[$p] = $v;
                     }
                 }
                 $class->params = $newParams;
             }
             if (method_exists($class, 'setAttributes')) {
                 $values[$fieldName] = $class->setAttributes($values[$fieldName], $this, $fieldName);
             }
         }
     }
     parent::setAttributes($values, $safeOnly);
 }
Beispiel #5
0
 public function setAttributes($attributes)
 {
     $model = $this->getModel();
     foreach ($attributes as $attribute => $value) {
         if (in_array($attribute, $this->pageAttributes)) {
             $model->title = $value;
             unset($attributes[$attribute]);
             continue;
         }
     }
     $model->save();
     $attributes['pageId'] = $model->id;
     parent::setAttributes($attributes);
 }
 /**
  * Check if some attributes uploaded via fileInput field
  * and assign them with UploadedFile
  *
  * @inheritdoc
  */
 public function setAttributes($values, $safeOnly = true)
 {
     parent::setAttributes($values, $safeOnly);
     // Looking only for file attributes (and fix null error on fly)
     if (is_array($values)) {
         $attributes = array_flip($safeOnly ? $this->safeAttributes() : $this->attributes());
         $class = StringHelper::basename(get_called_class());
         foreach ($values as $name => $value) {
             if (isset($attributes[$name])) {
                 if (isset($_FILES[$class]['name'][$name])) {
                     $uploadedFile = UploadedFile::getInstance($this, $name);
                     if ($uploadedFile) {
                         $this->{$name} = $uploadedFile;
                     } elseif (!$this->isNewRecord) {
                         $this->{$name} = $this->oldAttributes[$name];
                     }
                 }
             }
         }
     }
 }
Beispiel #7
0
 /**
  * @inheritDoc
  */
 protected function _setValue(ActiveRecord $model, $value)
 {
     /** @var ActiveRecord $model */
     $model->setAttributes([$this->attributeName => $value]);
     return true;
 }
Beispiel #8
0
 /**
  * (non-PHPdoc)
  * @see \yii\base\Model::setAttributes()
  * @throws Exception if the current record is read only
  */
 public function setAttributes($values, $safeOnly = true)
 {
     if ($this->getReadOnly()) {
         throw new Exception('Attempting to set attributes on a read only ' . Tools::getClassName($this) . ' model');
     }
     parent::setAttributes($values, $safeOnly);
 }