/
v.bolshakov
/
AIEcosystem-Testing
Обзор
Документация
Войти
/
v.bolshakov
/
AIEcosystem-Testing
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
dev
backend/forms/data/tm/TmTermForm.php
152 строки
3 KB
Developer
Initial commit
03 авг 2026, 17:43
03 авг 2026, 17:43
7433917
Код
Авторство
О чём код?
<?php namespace backend\forms\data\tm; use common\forms\base\ObjectIdForm; use common\helpers\TextHelper; use common\models\tm\Tm; use common\models\tm\TmTermMongo; use Yii; use yii\helpers\ArrayHelper; /** * Форма TM * * @author Dmitry E. Semenov <sde.tomsk@gmail.com> * @copyright Self (c) 2026 */ class TmTermForm extends ObjectIdForm { /** * title * @var null */ public $source = null; /** * title * @var null */ public $target = null; protected $tm_id = null; /** * @inheritdoc */ public function attributeLabels() { return ArrayHelper::merge(parent::attributeLabels(), [ 'source' => Yii::t('app', 'Source'), 'target' => Yii::t('app', 'Target'), ]); } /** * @inheritdoc */ public function rules() { return ArrayHelper::merge(parent::rules(), [ [['source', 'target'], 'required'], [['source', 'target'], 'string'], [ 'target', 'filter', 'filter' => function ($value) { return TextHelper::normalizeWhitespace($value); } ] ]); } /** * @inheritdoc */ public function loadModel($condition) { parent::loadModel($condition); $obj = TmTermMongo::find() ->andWhere([ '_id' => $this->oid, ]) ->one(); $this->tm_id = ArrayHelper::getValue($condition, 'parent_id'); if ($obj) { $this->source = $obj->source; $this->target = $obj->target; $this->initState($obj); } } /** * @inheritdoc */ public function getPublicFields() { return ArrayHelper::merge(parent::getPublicFields(), [ 'source', 'target' ]); } /** * @inheritdoc */ protected function doSave() { $term = TmTermMongo::find() ->andWhere([ '_id' => $this->oid, ]) ->one(); if (!$term) { $term = new TmTermMongo(); } $term->setAttributes([ 'source' => $this->source, 'target' => $this->target, ]); if ($this->tm_id) { $term->setAttributes([ 'tm_id' => (int)$this->tm_id ]); } if (!$term->save()) { $this->addErrors($term->errors); return false; } $this->model = $term; if ($this->tm_id) { $count = TmTermMongo::find() ->andWhere([ 'tm_id' => (int)$this->tm_id ]) ->count(); Tm::updateAll(['term_count' => $count], ['id' => $this->tm_id]); } return true; } /** * @inheritdoc */ protected function doDelete() { $this->model->delete(); return true; } }