Exemplo n.º 1
0
 /**
  * @return bool
  */
 public function beforeValidate()
 {
     if (is_null(Language::getDefault()) == false) {
         $this->addError('default', '`language.default_already_exists`');
     }
     return parent::beforeValidate();
     // TODO: Change the autogenerated stub
 }
Exemplo n.º 2
0
 /**
  * @return bool
  */
 public function beforeValidate()
 {
     if ($this->fillEmptyFields) {
         $sql = "SELECT symbol FROM language";
         $langs = \Yii::$app->getDb()->createCommand($sql)->queryAll(PDO::FETCH_COLUMN);
         $defaultLang = Language::getDefault();
         unset($langs[array_search($defaultLang->symbol, $langs)]);
         // now contains langs without defaultLang
         foreach ($this->getMultiLangFields() as $field) {
             $defaultField = $this->buildMultilangFieldName($field, $defaultLang->symbol);
             foreach ($langs as $lang) {
                 $field = $this->buildMultilangFieldName($field, $lang);
                 if (!$this->{$field}) {
                     // copy value from default language to current one
                     $this->{$field} = $this->{$defaultField};
                 }
             }
         }
     }
     return parent::beforeValidate();
     // TODO: Change the autogenerated stub
 }