/
v.bolshakov
/
AIEcosystem-Testing
Обзор
Документация
Войти
/
v.bolshakov
/
AIEcosystem-Testing
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
dev
backend/forms/data/task_user/UserTaskModelTrait.php
117 строк
3 KB
Developer
Initial commit
03 авг 2026, 17:43
03 авг 2026, 17:43
7433917
Код
Авторство
О чём код?
<?php namespace backend\forms\data\task_user; use common\models\link\LinkTaskGlossary; use common\models\Task; use common\models\tm\LinkTaskTm; use common\models\UserTask; use Yii; /** * Форма редактирования сервиса * * @author Dmitry E. Semenov <sde.tomsk@gmail.com> * @copyright Self (c) 2024 */ trait UserTaskModelTrait { /** * @inheritdoc */ public function beforeValidate() { $result = parent::beforeValidate(); // TODO: Change the autogenerated stub $a = Task::getAlias(); $not_unique = Task::find() ->currentUser($this->user_id) ->andWhere([ 'title' => $this->title ]) ->andFilterWhere([ '<>', $a . '.id', $this->oid ]) ->exists(); if ($not_unique) { $this->addError('title', Yii::t('yii', '{attribute} "{value}" has already been taken.', [ 'attribute' => $this->getAttributeLabel('title'), 'value' => $this->title ])); return false; } return $result; } /** * @inheritdoc */ protected function doSave() { $result = parent::doSave(); if ($result) { $ta = UserTask::findOrNew([ 'task_id' => $this->model->id ]); $ta->setAttributes([ 'user_id' => $this->user_id ]); if (!$ta->save()) { $this->addErrors($ta->errors); return false; } if ($this->glossary_id) { $link = LinkTaskGlossary::findOrNew([ 'task_id' => $this->model->id ]); $link->setAttributes([ 'glossary_id' => $this->glossary_id, 'passing_score' => $this->passing_score ]); if (!$link->save()) { $this->addErrors($link->errors); return false; } } else { LinkTaskGlossary::deleteAll([ 'task_id' => $this->model->id ]); } if ($this->tm_id) { $link = LinkTaskTm::findOrNew([ 'task_id' => $this->model->id ]); $link->setAttributes([ 'tm_id' => $this->tm_id, 'passing_score' => $this->passing_score_tm ]); if (!$link->save()) { $this->addErrors($link->errors); return false; } } else { LinkTaskTm::deleteAll([ 'task_id' => $this->model->id ]); } } return $result; } }