/
v.bolshakov
/
AIEcosystem-Testing
Обзор
Документация
Войти
/
v.bolshakov
/
AIEcosystem-Testing
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
dev
backend/forms/data/task/TaskVersionModelForm.php
165 строк
4 KB
Developer
Initial commit
03 авг 2026, 17:43
03 авг 2026, 17:43
7433917
Код
Авторство
О чём код?
<?php namespace backend\forms\data\task; use common\helpers\ArrayHelper; use common\helpers\NumHelper; use common\kdf\KTaskType; use common\models\link\LinkTaskGlossary; use common\models\ModelAI; use common\models\Task; use common\models\TaskModel; use common\models\TextSegment; use Yii; /** * Форма редактирования сервиса * * @author Dmitry E. Semenov <sde.tomsk@gmail.com> * @copyright Self (c) 2024 */ class TaskVersionModelForm extends TaskModelForm { /** * @var int */ public $task_id = null; /** * Модель * @var null */ public $description = null; /** * Версия * @var null */ public $version = null; /** * Текущий ? * @var null */ public $is_default = null; /** * @inheritdoc */ public function rules() { return ArrayHelper::merge([ ['title', 'default', 'value' => '-'], ['task_id', 'required'], ['task_id', 'number'], [['description'], 'required'], [['description'], 'string'], ], parent::rules()); } /** * @inheritdoc */ public function attributeLabels() { return ArrayHelper::merge(parent::attributeLabels(), [ 'description' => Yii::t('app', 'Description'), ]); } /** * @inheritdoc */ public function loadModel($condition) { parent::loadModel($condition); // TODO: Change the autogenerated stub $this->task_id = ArrayHelper::getValue($condition, 'task_id', ArrayHelper::getValue($condition, 'parent_id') ); if ($this->oid) { $tm = TaskModel::findOne($this->oid); if ($tm) { $this->initState($tm); } } } /** * @inheritdoc */ public function initState($object) { if ($object instanceof TaskModel) { $this->model_id = $object->model_id; $this->project_id = $object->project_id; $this->promt_format_id = $object->promt_format_id; $this->top_p = $object->top_p; $this->promt = $object->promt; $this->temperature = $object->temperature; $this->description = $object->description; $this->version = $object->version; $this->is_default = $object->is_default; /** @var LinkTaskGlossary $tg */ if ($tg = $object->task->taskGlossary) { $this->glossary_id = $tg->glossary_id; } } parent::initState($object); // TODO: Change the autogenerated stub } /** * @inheritdoc */ public function getPublicFields() { return ArrayHelper::merge(parent::getPublicFields(), [ 'description', ]); } /** * @inheritdoc */ protected function doSave() { $tm = TaskModel::findOrNew([ 'id' => $this->oid, ]); $segment = TextSegment::findOrNew($tm->promt_id); if (!$segment->save()) { $this->addErrors($segment->errors); return false; } $tm->setAttributes([ 'task_id' => $this->task_id, 'project_id' => $this->project_id, 'model_id' => $this->model_id, 'promt_format_id' => $this->promt_format_id, 'top_p' => NumHelper::toPoint($this->top_p), 'temperature' => NumHelper::toPoint($this->temperature), 'promt_id' => $segment->id, 'description' => $this->description ]); if (!$tm->save()) { $this->addErrors($tm->errors); return false; } Task::updateAll([ 'provider_id' => $tm->model->getProviderId() ], [ 'id' => $this->task_id ]); return true; } }