/**
  * Finds the SourceMessage model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return SourceMessage the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = SourceMessage::findOne(['id' => $id])) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 public static function handleMissingTranslation(MissingTranslationEvent $event)
 {
     $allLanguage = ArrayHelper::map(Language::getAllActive(), 'varCode', 'varName');
     if ($event->category === 'admin') {
         Yii::$app->language = Setting::getValue('languageAdminPanel');
     }
     if (self::checkNeeded($event->category)) {
         $attributes = ['category' => $event->category, 'message' => $event->message];
         $query = (new Query())->select('id, category, message')->from(SourceMessage::tableName())->where('category = :category AND BINARY message = :message');
         $data = $query->createCommand()->bindValue('category', $event->category)->bindValue('message', $event->message)->queryOne();
         if (!$data) {
             $model = new SourceMessage();
             $model->attributes = $attributes;
             if ($model->save()) {
                 $attributes = ['id' => $model->id, 'language' => $event->language];
                 self::saveMessage($attributes, $event);
                 if ($event->category === 'app') {
                     foreach ($allLanguage as $language => $languageName) {
                         $attributes = ['id' => $model->id, 'language' => $language];
                         self::saveMessage($attributes, $event);
                     }
                 }
             }
         } else {
             /** @var Message $model */
             if (($model = Message::findOne(['id' => $data['id'], 'language' => $event->language])) === null) {
                 $attributes = ['id' => $data['id'], 'language' => $event->language];
                 self::saveMessage($attributes, $event);
             }
             if ($event->category === 'app') {
                 foreach ($allLanguage as $language => $languageName) {
                     $attributes = ['id' => $data['id'], 'language' => $language];
                     self::saveMessage($attributes, $event);
                 }
             }
         }
         return $event;
     }
 }
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = SourceMessage::find()->groupBy('source_message.id');
     $query->joinWith('messages');
     $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => 15]]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'category' => 'app']);
     $query->andFilterWhere(['like', 'message', $this->message]);
     $langs = Language::getAllActive();
     foreach ($langs as $lang) {
         $query->andFilterWhere(['like', 'translation', $this->translations[$lang->varCode]]);
     }
     return $dataProvider;
 }
 /**
  * Deletes an existing Message model.
  * If deletion is successful, the browser will be redirected to the 'index' page.
  * @param integer $id
  * @param string $language
  * @return mixed
  */
 public function actionDelete($id, $language)
 {
     $this->findModel($id, $language)->delete();
     SourceMessage::findOne($id)->delete();
     return $this->redirect(Url::previous());
 }
Esempio n. 5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getSourceMessage()
 {
     return $this->hasOne(SourceMessage::className(), ['id' => 'id']);
 }