public function getStr() { return $this->hasOne(TransData::className(), ['id' => 'str_id']); }
/** * @param $lng * @param $id * @return null|void|static * @throws NotFoundHttpException */ public function actionTest($id) { $uid = Yii::$app->user->identity->getId(); $direction = $this->getDirections($uid); $model = $this->findTranslation($direction['dst'], $id); if ($model->load(\Yii::$app->request->post()) && $model->save()) { return $this->redirect(['update', 'id' => $model->id + 1]); } else { $model['src'] = $direction['src']; $model['dst'] = $direction['dst']; $model['source'] = $this->findTranslation($model['src'], $id)->str; if (strlen($model->str) <= 1) { $model['yandex'] = Yii::$app->translate->translate($model['src'], $model['dst'], $model['source'])['text'][0]; } $sources['src'] = new Translate(); $sources['dst'] = new Translate(); $sources['src'] = $sources['src']->findLastXtranslations($direction['src'], $id); $sources['dst'] = $sources['dst']->findLastXtranslations($direction['dst'], $id); /* $sources = (new \yii\db\Query()) ->select(['str']) ->from('trans_'.$direction['src']) ->where(['between', 'id', $id-3, $id ]) ->limit(3) ->all(); */ return $this->render('transcard', ['model' => $model, 'source' => TransData::find()->where(['id' => $id])->one(), 'sources' => $sources]); } }