[ 'robots' ], self::SCENARIO_CODES => [ 'ga_code', 'ya_code', 'tag_manager', ], ] ); } public function behaviors() { return [ 'translations' => [ 'class' => VariationBehavior::className(), 'variationsRelation' => 'languages', 'defaultVariationRelation' => 'language', 'variationOptionReferenceAttribute' => 'language_id', 'optionModelClass' => Language::className(), 'defaultVariationOptionReference' => function () { return Language::getCurrent()->id; }, 'optionQueryFilter' => function (ActiveQuery $query) { $query->where( [ 'status' => true, ] ); }, ], ]; } /** * @inheritdoc */ public function rules() { return [ [ [ 'phone', 'phone2', 'skype', 'email', 'address', 'facebook', 'google', 'twitter', 'name', 'analytics_key', 'about', 'logo' ], 'string', ], [ [ 'lat', 'lon', ], 'double', ], [ [ 'email', ], 'email', ], [ [ 'logo', ], 'filter', 'filter' => function ($value) { if (empty( $value )) { return null; } else { return $value; } }, ], ]; } /** * @inheritdoc */ public static function fileName() { return 'settings'; } /** * @inheritdoc */ public function attributeLabels() { return [ 'analytics_key' => Yii::t('core', 'Google Analytics Key'), 'robots' => Yii::t('core', 'Robots'), 'ga_code' => Yii::t('core', 'Google analytics code'), 'ya_code' => Yii::t('core', 'Yandex metrics code'), 'tag_manager' => Yii::t('core', 'Tag Manager code'), 'phone' => Yii::t('core', 'Phone'), 'phone2' => Yii::t('core', 'Additional phone'), 'skype' => Yii::t('core', 'Skype'), 'name' => Yii::t('core', 'Company name'), 'email' => Yii::t('core', 'Email'), 'address' => Yii::t('core', 'Address'), 'lat' => Yii::t('core', 'Latitude'), 'lon' => Yii::t('core', 'Longitude'), 'facebook' => Yii::t('core', 'Facebook'), 'google' => Yii::t('core', 'Google'), 'twitter' => Yii::t('core', 'Twitter'), 'logo' => Yii::t('core', 'Company logo'), 'about' => Yii::t('core', 'About us'), ]; } public function afterFind() { if ($this->logo === '') { $this->logo = null; } parent::afterFind(); } /** * Get Settings model instance * * @return Settings */ public static function getInstance() { if (empty( self::$instance )) { self::$instance = self::find()->with('languages')->where([ 'id' => 1 ])->one(); return self::$instance; } return self::$instance; } public function getLanguages() { return $this->hasMany(SettingsLang::className(), [ 'settings_id' => 'id' ]); } /** * @return \yii\db\ActiveQuery */ // public function getLanguage() // { // return $this->hasOne(SettingsLang::className(), [ 'settings_id' => 'id' ]); // } }