public function createMessage() { if (!$this->validate()) { Alert::addError(Yii::t('messages', 'Translation has not been saved'), $this->errors); return false; } $sourceMessage = new SourceMessage(); $sourceMessage->language = $this->language; $sourceMessage->category = $this->category; $sourceMessage->message = $this->source_message; $sourceMessage->messageTranslation = $this->translation; if (!$sourceMessage->save()) { Alert::addError(Yii::t('messages', 'Translation has not been saved'), $sourceMessage->errors); } return false; }
public function loadTranslation() { if (!$this->validate()) { Alert::addError('Translation has not been loaded', $this->errors); return false; } $xlsImport = new xlsImport(Yii::$app->controller, Yii::$app->request->referrer, SourceMessage::className(), KReader::className(), $this, 'file', $this->isUpdate); $xlsImport->run(); return true; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = SourceMessage::find()->where("id not in (select id from message where language = :language)", [":language" => Yii::$app->language])->orderBy("message"); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'category', $this->category])->andFilterWhere(['like', 'message', $this->message]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getId0() { return $this->hasOne(SourceMessage::className(), ['id' => 'id']); }
/** * 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)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getSourceMessage() { return $this->hasOne(SourceMessage::className(), ['id' => 'id'])->from([SourceMessage::tableName() . ' sourceMessage']); }
public function actions() { return ['ajax-update' => ['class' => TranslationEditableAction::className(), 'modelClass' => SourceMessage::className(), 'forceCreate' => false, 'preProcess' => function ($model) { $model->language = Yii::$app->request->get('language'); }]]; }