/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $translation = Translation::findOrFail($id); if ($translation->delete()) { return response()->json(['response' => 'Success', 'msg' => 'The Translation removed!']); } else { return response()->json(['response' => 'Error', 'msg' => 'Something gone wrong']); } }
public static function translateQuestion(&$question, $lang) { if (isset($question['fr_id'])) { $translation = Translation::findOne(['t_l_id' => $lang, 't_fr_id' => $question['fr_id']]); if ($translation) { $question['frage'] = $translation->frage; $question['antworten'] = $translation->antworten; } } }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Translation::find(); $pageSize = Yii::$app->session->get('pageSize', Yii::$app->params['defaultPageSize']); $dataProvider = new ActiveDataProvider(['query' => $query, 'pagination' => ['pageSize' => $pageSize]]); $dataProvider->setSort(['attributes' => ['tr_id', 't_l_id', 't_fr_id', 'questionOriginal' => ['asc' => ['{{%frage}}.frage' => SORT_ASC], 'desc' => ['{{%frage}}.frage' => SORT_DESC], 'label' => 'Frage Original'], 'frage']]); if (!($this->load($params) && $this->validate())) { $query->joinWith(['question']); return $dataProvider; } $query->andFilterWhere(['tr_id' => $this->tr_id, 't_fr_id' => $this->t_fr_id, 't_l_id' => $this->t_l_id]); $query->andFilterWhere(['like', '{{%translations}}.frage', $this->frage])->andFilterWhere(['like', 'antworten', $this->antworten]); $query->joinWith(['question' => function ($q) { $q->where('{{%frage}}.frage LIKE "%' . $this->questionOriginal . '%"'); }]); return $dataProvider; }
public function actionImport() { $imported = 0; $dropped = 0; $postData = Yii::$app->request->post(); $file = UploadedFile::getInstanceByName('filename'); if ($file) { $lang = $postData['lang']; if ($lang == '') { return $this->render('import', ['error' => "Language is not specified", 'imported' => 0, 'dropped' => 0]); } $content = file($file->tempName); $lines = 0; try { foreach ($content as $line) { $lines++; $transl = explode('@', $line); $oTranslation = Translation::findOne(['t_l_id' => $lang, 't_fr_id' => $transl[0]]); if ($oTranslation) { $oTranslation->t_l_id = $lang; $oTranslation->antworten = $transl[2]; $oTranslation->frage = $transl[1]; } else { $oTranslation = new Translation(); $oTranslation->t_fr_id = $transl[0]; $oTranslation->t_l_id = $lang; $oTranslation->antworten = $transl[2]; $oTranslation->frage = $transl[1]; } if ($oTranslation->save()) { $imported++; } else { $dropped++; } } } catch (ErrorException $e) { return $this->render('import', ['warning' => "Invalid character was found at line " . $lines . ". Imported questions - " . $imported, 'imported' => $imported, 'dropped' => $dropped]); } } elseif (!empty($postData)) { return $this->render('import', ['error' => "No file was selected to import", 'imported' => $imported, 'dropped' => $dropped]); } return $this->render('import', ['imported' => $imported, 'dropped' => $dropped]); }
public function actionImport() { $imported = 0; $dropped = 0; $file = UploadedFile::getInstanceByName('filename'); if ($file) { $lang = Yii::$app->request->post('lang'); $content = file($file->tempName); foreach ($content as $line) { $transl = explode('@', $line); $oTranslation = Translation::findOne(['t_l_id' => $lang, 't_fr_id' => $transl[0]]); if ($oTranslation) { $oTranslation->antworten = $transl[2]; $oTranslation->frage = $transl[1]; } else { $oTranslation = new Translation(); $oTranslation->t_fr_id = $transl[0]; $oTranslation->t_l_id = $lang; $oTranslation->antworten = $transl[2]; $oTranslation->frage = $transl[1]; } $oTranslation->save(); $imported++; } } return $this->render('import', ['imported' => $imported, 'dropped' => $dropped]); }
/** * Finds the Translation model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Translation the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Translation::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }