/**
  * @return boolean whether the record should be deleted. Defaults to true.
  * @throws InvalidParamException
  */
 public function beforeDelete()
 {
     if (LanguageHelper::removeAllData($this)) {
         return parent::beforeDelete();
     }
     return false;
 }
 /**
  * Return all translated attributes include value
  *
  * @param ActiveRecord $model
  * @param null         $language_code
  *
  * @return array
  * @throws InvalidConfigException
  */
 public static function attributes($model, $language_code = null)
 {
     $behavior = $model->behaviors();
     if (!isset($behavior['ml'])) {
         throw new InvalidConfigException("MultiLanguage was not defined in " . get_class($model) . ".");
     }
     $response = [];
     foreach (Language::getLanguages() as $language) {
         foreach ($behavior['ml']['attributes'] as $mlAttribute) {
             $attribute = $mlAttribute . '_' . $language->code;
             if ($language_code != null) {
                 if ($language_code == $language->code) {
                     $response[$attribute] = isset($model->behaviors['ml']) ? $model->{$attribute} : '';
                 }
             } else {
                 $response[$attribute] = isset($model->behaviors['ml']) ? $model->{$attribute} : '';
             }
         }
     }
     return $response;
 }
Example #3
0
 /**
  * @return array attribute labels (name => label)
  * @see generateAttributeLabel()
  */
 public function attributeLabels()
 {
     $labels = parent::attributeLabels();
     foreach ($this->languages as $language) {
         $labels[$language->code] = $language->name;
     }
     return $labels;
 }