/
v.bolshakov
/
AIEcosystem-Testing
Обзор
Документация
Войти
/
v.bolshakov
/
AIEcosystem-Testing
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
dev
backend/forms/data/task_default/DefaultTaskModelTrait.php
79 строк
2 KB
Developer
Initial commit
03 авг 2026, 17:43
03 авг 2026, 17:43
7433917
Код
Авторство
О чём код?
<?php namespace backend\forms\data\task_default; use common\models\Task; use common\models\TaskDefault; use common\models\UserTask; use Yii; /** * Форма редактирования сервиса * * @author Dmitry E. Semenov <sde.tomsk@gmail.com> * @copyright Self (c) 2024 */ trait DefaultTaskModelTrait { /** * @inheritdoc */ public function beforeValidate() { $result = parent::beforeValidate(); // TODO: Change the autogenerated stub $a = Task::getAlias(); $not_unique = Task::find() ->prepareDefault() ->andWhere([ 'title' => $this->title ]) ->andFilterWhere([ '<>', $a . '.id', $this->oid ]) ->published() ->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) { if (!$this->oid) { $td = TaskDefault::findOrNew([ 'task_id' => $this->model->id ]); $td->setAttributes([ 'is_research' => $this->is_research ]); if (!$td->save()) { $this->addErrors($td->errors); return false; } } } return $result; } }