Пример #1
0
 /**
  * Updates texts for file in given language
  * @param $id integer id of file
  * @return string|Response
  */
 public function actionUpdateTexts($id)
 {
     /** @var FileRecord $file */
     $file = FileRecord::findOne($id);
     if ($file) {
         $session = Yii::$app->session;
         if (!$session['language_id']) {
             $session['language_id'] = LanguageRecord::getMainLanguageId();
         }
         $model = FileTextRecord::find()->where(['file_id' => $id, 'language_id' => $session['language_id']])->one();
         if (!$model) {
             $model = new FileTextRecord();
             $model->title = $file->title;
             $model->file_id = $id;
             $model->language_id = $session['language_id'];
         }
         if ($model->load(Yii::$app->request->post()) && $model->save()) {
             if ($model->file->type == FileRecord::TYPE_IMAGE) {
                 return $this->redirect(['images']);
             } else {
                 return $this->redirect(['files']);
             }
         } elseif (Yii::$app->request->isAjax) {
             return $this->renderAjax('_textsForm', compact('model'));
         }
         return $this->render('_textsForm', compact('model'));
     } else {
         throw new InvalidValueException(Yii::t('back', 'No file record found of this ID') . ': ' . $id);
     }
 }
Пример #2
0
 /**
  * Gets description of file in given language
  * @param $languageId
  * @return string
  */
 public function getFileDescription($languageId)
 {
     $description = FileTextRecord::find()->select('description')->where(['file_id' => $this->id, 'language_id' => $languageId])->scalar();
     return $description;
 }