예제 #1
0
 /**
  *
  * @param array|integer $id            
  * @return SourceMessage|SourceMessage[]
  * @throws NotFoundHttpException
  */
 protected function findModel($id)
 {
     $query = SourceMessage::find()->where('id = :id', [':id' => $id]);
     $models = is_array($id) ? $query->all() : $query->one();
     if (!empty($models)) {
         return $models;
     } else {
         throw new NotFoundHttpException(Module::t('The requested page does not exist'));
     }
 }
예제 #2
0
 /**
  *
  * @param MissingTranslationEvent $event            
  */
 public static function missingTranslation(MissingTranslationEvent $event)
 {
     $driver = \Yii::$app->getDb()->getDriverName();
     $caseInsensitivePrefix = $driver === 'mysql' ? 'binary' : '';
     $sourceMessage = SourceMessage::find()->where('category = :category and message = ' . $caseInsensitivePrefix . ' :message', [':category' => $event->category, ':message' => $event->message])->with('messages')->one();
     if (!$sourceMessage) {
         $sourceMessage = new SourceMessage();
         $sourceMessage->setAttributes(['category' => $event->category, 'message' => $event->message], false);
         $sourceMessage->save(false);
     }
     $sourceMessage->initMessages();
     $sourceMessage->saveMessages();
 }
 /**
  * @param array|null $params
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = SourceMessage::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     if (!($this->load($params) && $this->validate())) {
         return $dataProvider;
     }
     if ($this->status == static::STATUS_TRANSLATED) {
         $query->translated();
     }
     if ($this->status == static::STATUS_NOT_TRANSLATED) {
         $query->notTranslated();
     }
     $query->andFilterWhere(['like', 'category', $this->category])->andFilterWhere(['like', 'message', $this->message]);
     return $dataProvider;
 }
예제 #4
0
 /**
  * @return array|SourceMessage[]
  */
 public static function getCategories()
 {
     return SourceMessage::find()->select('category')->distinct('category')->asArray()->all();
 }