Exemplo n.º 1
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getUser()
 {
     return $this->hasOne(User::className(), ['id' => 'user_id']);
 }
Exemplo n.º 2
0
 /**
  * @throws InvalidConfigException
  */
 public function initDefaultTypeList()
 {
     if ($this->typeList instanceof Closure) {
         $this->typeList = call_user_func($this->typeList, $this);
     }
     if (!is_array($this->typeList)) {
         throw new InvalidConfigException('The "typeList" property must be array.');
     }
     if (!isset($this->typeList['users'])) {
         $this->typeList['users'] = ['query' => function () {
             return \pavlinter\adm\models\User::find();
         }, 'label' => Yii::t('adm-mailing', 'Users', ['dot' => false])];
     } else {
         if ($this->typeList['users'] === false) {
             unset($this->typeList['users']);
         }
     }
     foreach ($this->typeList as $key => $value) {
         if ($value instanceof Closure) {
             $options = ['query' => $value, 'label' => $key];
         } else {
             if (is_array($value)) {
                 $options = $value;
             } else {
                 throw new InvalidConfigException('The "typeList" property must be correct structure.');
             }
         }
         if (!isset($options['class'])) {
             $options['class'] = $this->typeClass;
         }
         $this->typeList[$key] = Yii::createObject($options);
     }
 }