/
v.bolshakov
/
AIEcosystem-Testing
Обзор
Документация
Войти
/
v.bolshakov
/
AIEcosystem-Testing
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
dev
common/models/TextSegmentMongo.php
104 строки
2 KB
Developer
Initial commit
03 авг 2026, 17:43
03 авг 2026, 17:43
7433917
Код
Авторство
О чём код?
<?php namespace common\models; use Yii; use yii\helpers\ArrayHelper; use yii\helpers\VarDumper; use yii\mongodb\ActiveRecord; use yii\web\ServerErrorHttpException; /** * Таблица текстовые сегменты в базе данных MongoDB * * @property string $id * @property string $segment * * @author Dmitry E. Semenov <sde.tomsk@gmail.com> * @copyright Self (c) 2026 */ class TextSegmentMongo extends ActiveRecord { /** * @inheritdoc */ public static function tableName() { return 'text_segment'; } /** * @inheritdoc */ public function rules() { return [ [['segment'], 'trim'], [['segment'], 'required'], [['segment'], 'string'], ]; } /** * @inheritdoc */ public function attributes() { return [ '_id', 'segment', ]; } /** * @inheritdoc */ public function attributeLabels() { return ArrayHelper::merge(parent::attributeLabels(), [ 'segment' => Yii::t('app', 'Segment'), ]); } /** * Получить текст сегмента * @param $segment_id * @return false|int|string|null * @throws \yii\base\InvalidConfigException */ public static function getText($segment_id) { if ($segment_id) { return TextSegmentMongo::find() ->select(['segment']) ->andWhere(['_id' => $segment_id]) ->scalar(); } else { return ''; } } /** * Установить текст сегмента * @param $segment * @return TextSegmentMongo * @throws ServerErrorHttpException * @throws \yii\db\Exception */ public static function setText($segment) { $segment = new TextSegmentMongo([ 'segment' => $segment, ]); if (!$segment->save()) { Yii::debug(VarDumper::dumpAsString([ 'errors' => $segment->errors ])); throw new ServerErrorHttpException(Yii::t('app', 'Error save segment')); } return $segment; } }