/** * @inheritdoc */ public function search($params) { $query = Message::find()->joinWith(['sourceMessage' => function ($query) { $query->from(['sourceMessage' => SourceMessage::tableName()]); }]); $dataProvider = new ActiveDataProvider(['query' => $query]); if ($this->language) { $query->filterWhere(['language' => $this->language]); } if ($this->prefix) { $query->andFilterWhere(['or', ['like', 'sourceMessage.category', $this->prefix . '.'], ['like', 'sourceMessage.category', $this->prefix . '/']]); } if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['like', 'translation', $this->translation])->andFilterWhere(['like', 'sourceMessage.message', $this->source]); if ($this->category) { if ($this->prefix) { $query->andFilterWhere(['or', ['like', 'sourceMessage.category', $this->prefix . '.' . $this->category], ['like', 'sourceMessage.category', $this->prefix . '/' . $this->category]]); } else { $query->andFilterWhere(['like', 'sourceMessage.category', $this->category]); } } if ($this->translationStatus === static::MESSAGE_TRANSLATED_YES) { $query->andWhere('translation IS NOT NULL AND translation <> ""'); } elseif ($this->translationStatus === static::MESSAGE_TRANSLATED_NO) { $query->andWhere('translation IS NULL OR translation = ""'); } return $dataProvider; }
/** * @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')); } }
/** * @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; }
public function getSourceMessage() { return $this->hasOne(SourceMessage::className(), ['id' => 'id']); }
/** * @return array|SourceMessage[] */ public static function getCategories() { return SourceMessage::find()->select('category')->distinct('category')->asArray()->all(); }
/** * @param MissingTranslationEvent $event */ public static function missingTranslation(MissingTranslationEvent $event) { $sourceMessage = SourceMessage::find()->where('category = :category and message = binary :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(); $messages = $sourceMessage->saveMessages(); // $missingTranslations = Yii::$app->cache->get(self::MISSING_TRANSLATIONS_KEY); // $missingTranslations[] = [ // 'category' => $event->category, // 'message' => $event->message, // 'messages' => $messages, // ]; // Yii::$app->cache->set(self::MISSING_TRANSLATIONS_KEY, $missingTranslations); }
public function actionFlush() { $tableNames = [Message::tableName(), SourceMessage::tableName()]; $db = Yii::$app->getDb(); foreach ($tableNames as $tableName) { $db->createCommand()->delete($tableName)->execute(); } echo PHP_EOL . 'Done.' . PHP_EOL; }