/
v.bolshakov
/
AIEcosystem-Testing
Обзор
Документация
Войти
/
v.bolshakov
/
AIEcosystem-Testing
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
dev
backend/controllers/data/user/TmController.php
156 строк
4 KB
Developer
Initial commit
03 авг 2026, 17:43
03 авг 2026, 17:43
7433917
Код
Авторство
О чём код?
<?php namespace backend\controllers\data\user; use backend\assets\TmAsset; use common\controllers\base\ParentCrudController; use common\helpers\LanguageHelper; use common\helpers\NumHelper; use common\helpers\TmHelper; use common\kdf\KSystem; use common\models\tm\Tm; use Yii; use yii\web\NotFoundHttpException; /** * Контроллер для работы с TM пользователя * * @author Dmitry E. Semenov <sde.tomsk@gmail.com> * @copyright Self (c) 2026 */ class TmController extends ParentCrudController { /** * @inheritdoc */ protected $modelClassPath = 'backend\components\crud\user\tm'; /** * @inheritdoc */ protected $classPrefix = 'Tm'; /** * @inheritdoc */ protected $parentModelName = 'common\models\User'; /** * @inheritdoc */ protected $relationKey = ['user_id' => 'id']; /** * Получить TM в виде JSONL * @param $id * @return \yii\web\Response * @throws \yii\base\InvalidConfigException */ public function actionJsonl($id) { Yii::$app->request->validateSig(); /** @var Tm $tm */ $tm = Tm::find() ->andWhere([ 'id' => $id ]) ->one(); if (!$tm) { throw new NotFoundHttpException(Yii::t('app', 'TM not found')); } $attachmentName = Yii::t('app', '{0} ({1} - {2}).jsonl', [ $tm->name, LanguageHelper::getLanguageCode($tm->source_language_id, KSystem::Code3), LanguageHelper::getLanguageCode($tm->target_language_id, KSystem::Code3) ]); return $this->response->sendContentAsFile($tm->toJsonl(), $attachmentName); } /** * Проверка текста и глоссария * * @param $id * @return string * @throws NotFoundHttpException * @throws \yii\base\InvalidConfigException */ public function actionAnalysis($id) { Yii::$app->request->validateSig(); /** @var Tm $tm */ $tm = Tm::find() ->andWhere([ 'id' => $id ]) ->one(); if (!$tm) { throw new NotFoundHttpException(Yii::t('app', 'TM not found')); } $view = Yii::$app->view; $view->title = Yii::t('app', 'Analysis TM'); $breadcrumbs[] = [ 'label' => $view->title, ]; $view->params['breadcrumbs'] = $breadcrumbs; TmAsset::register($view); return $this->render('@backend/views/data/user/check_tm.twig', [ 'tm' => $tm ]); } /** * Проверка текста и глоссария * * @return \yii\web\Response * @throws NotFoundHttpException * @throws \yii\base\InvalidConfigException */ public function actionDoAnalysis($id) { $text = Yii::$app->request->post('request_text'); /** @var Tm $tm */ $tm = Tm::find() ->andWhere([ 'id' => $id ]) ->one(); if (!$tm) { throw new NotFoundHttpException(Yii::t('app', 'TM not found')); } $data = TmHelper::doAnalysis($text, $tm); $is_ok = $data['is_ok']; $table = []; if ($is_ok) { $index = 1; foreach ($data['raw'] as $row) { $table[] = [ $index, $row['segment'], $row['source'], NumHelper::toString($row['score'], 2), ]; $index++; } } return $this->asJson([ 'is_ok' => $is_ok, 'message' => $data['message'], 'table' => array_values($table) ]); } }