/
v.bolshakov
/
AIEcosystem-Testing
Обзор
Документация
Войти
/
v.bolshakov
/
AIEcosystem-Testing
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
dev
common/kdf/base/BaseKdf.php
93 строки
2 KB
Developer
Initial commit
03 авг 2026, 17:43
03 авг 2026, 17:43
7433917
Код
Авторство
О чём код?
<?php namespace common\kdf\base; use common\interfaces\TitleInterface; use common\models\base\BaseModel; use common\traits\TitleRecordTrait; use Yii; use yii\helpers\ArrayHelper; use yii\helpers\Html; /** * Базоый класс для работы со справочниками * * @author Dmitry E. Semenov <sde.tomsk@gmail.com> * @copyright Self (c) 2019-2020 */ abstract class BaseKdf extends BaseModel implements TitleInterface { use TitleRecordTrait; /** * Имя базового ActiveQuery класса * @var string */ protected static $queryClass = 'common\kdf\base\BaseKdfQuery'; /** * Присваиваем названия атрибутам * * @return array */ public function attributeLabels() { return ArrayHelper::merge(parent::attributeLabels(), [ 'title' => Yii::t('app', 'Название'), ]); } /** * @inheritdoc */ public function rules() { return ArrayHelper::merge(parent::rules(), [ [['title'], 'string', 'max' => 255], ]); } /** * @inheritdoc */ public static function primaryKey() { return ['id']; } /** * Получить строку отображения * * @return mixed|string */ public function getTitle() { foreach ((array)$this->getTitleFields() as $field) { if (!in_array($field, ['icon'])) { $path[] = $this->{$field}; } }; $title = implode(' ', array_diff($path, array('-', null, false))); if ($icon = $this->getIcon()) { return $icon . ' ' . $title; } else { return $title; } } /** * Получить иконку * * @return null|string */ public function getIcon() { if ($this->hasAttribute('icon') and $this->icon) { return Html::tag('i', '', ['class' => $this->icon]); } return null; } }