/
v.bolshakov
/
AIEcosystem-Testing
Обзор
Документация
Войти
/
v.bolshakov
/
AIEcosystem-Testing
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
dev
api/controllers/ResponseController.php
113 строк
4 KB
Developer
Initial commit
03 авг 2026, 17:43
03 авг 2026, 17:43
7433917
Код
Авторство
О чём код?
<?php namespace api\controllers; use api\controllers\base\BaseController; use common\helpers\ArrayHelper; use common\kdf\KModelStatus; use common\models\Request; use common\models\RequestBatch; use common\models\RequestSegment; use common\models\ResponseBatch; use common\models\ResponseSegment; use common\models\TextSegment; use Yii; use yii\helpers\UnsetArrayValue; use yii\web\NotFoundHttpException; /** * Работа с ответом * * @author Dmitry E. Semenov <sde.tomsk@gmail.com> * @copyright Self (c) 2024 */ class ResponseController extends BaseController { /** * {@inheritDoc} */ public function actions() { return ArrayHelper::merge(parent::actions(), [ 'index' => new UnsetArrayValue(), ]); } /** * @SWG\Get(path="/response", * tags = {"user"}, * summary = "Get response for request", * produces = {"application/json", "application/xml"}, * @SWG\Parameter(in = "header", name = "hub-key", required = true, type = "string", description = "User Hub ID"), * @SWG\Parameter(in = "query", name = "request_id", type = "string", description = "Request ID"), * @SWG\Response(response = 200, description = "OK"), * @SWG\Response(response = 422, description = "Unprocessable entity"), * @SWG\Response(response = 500, description = "Internal Server Error") * ) */ public function actionIndex($request_id) { /** @var Request $request */ $request = Request::find() ->andWhere([ 'guid' => $request_id ]) ->currentUser() ->one(); if (!$request) { throw new NotFoundHttpException(Yii::t('app', 'Request «{0}» not found', [ $request_id ])); } $items = []; $text = ''; $time_spent = null; if ($request->rec_status == KModelStatus::PUBLISHED) { $a = RequestSegment::getAlias(); $rows = RequestSegment::find() ->select(['rsr.segment_id', 'segment_index']) ->alias($a) ->leftJoin(['rsr' => ResponseSegment::tableName()], $a . '.id = rsr.request_segment_id') ->andWhere([ 'request_id' => $request->id, ]) ->orderBy([ 'segment_index' => SORT_ASC ]) ->asArray() ->all(); foreach ($rows as $row) { $segment_id = ArrayHelper::getValue($row, 'segment_id'); $segment = TextSegment::getText($segment_id); if (!$segment) { $segment = '---------- Attention! This is a technical information: several segments above have been merged ----------'; } $items[] = $segment; $text .= '<s[' . $row['segment_index'] . ']>' . $segment; } $time_spent = ResponseBatch::find() ->innerJoin(['rb' => RequestBatch::tableName()], 'rb.id = request_batch_id') ->andWhere([ 'request_id' => $request->id ]) ->sum('time_spent'); } return [ 'id' => $request_id, 'created_at' => $request->created_at, 'status' => $request->rec_status, 'time_spent' => $time_spent, 'text' => $text, 'items' => $items, ]; } }