/
v.bolshakov
/
AIEcosystem-Testing
Обзор
Документация
Войти
/
v.bolshakov
/
AIEcosystem-Testing
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
dev
common/kdf/KLanguage.php
142 строки
3 KB
Developer
Initial commit
03 авг 2026, 17:43
03 авг 2026, 17:43
7433917
Код
Авторство
О чём код?
<?php namespace common\kdf; use common\behaviors\OldValueBehavior; use common\behaviors\TranslateRecordBehavior; use common\kdf\base\PerevodKdf; use common\validators\UidValidator; use Yii; use yii\helpers\ArrayHelper; /** * Классификатор - языки * * @property string $title Название * @property string $guid Guid * @property string $code2 Код-2 * @property string $code3 Код-3 * * @author Dmitry E. Semenov <sde.tomsk@gmail.com> * @copyright Self (c) 2019-2024 */ class KLanguage extends PerevodKdf { /** * @inheritdoc */ public $softDelete = true; const ENGLISH = 30; const RUSSIAN = 100; const GERMAN = 46; /** * @inheritdoc */ protected $modelName = 'Language'; /** * {@inheritdoc} */ public static function tableName() { return 'k_language'; } /** * {@inheritdoc} */ public function rules() { return ArrayHelper::merge(parent::rules(), [ [['title'], 'required'], [['title'], 'string', 'max' => 50], [['code2', 'code3'], 'string', 'max' => 20], [['title'], 'unique'] ]); } /** * {@inheritdoc} */ public function behaviors() { return ArrayHelper::merge(parent::behaviors(), [ 'TranslateRecordBehavior' => [ 'class' => TranslateRecordBehavior::class, 'translate_table' => 'k_language_perevod', 'translate_map' => [ 'title' => 'title', ], ], ]); } /** * {@inheritdoc} */ public function attributeLabels() { return ArrayHelper::merge(parent::attributeLabels(), [ 'title' => Yii::t('app', 'Title'), 'code2' => Yii::t('app', 'Code 2'), 'code3' => Yii::t('app', 'Code 3'), ]); } /** * {@inheritdoc} */ public function beforeSave($insert) { $parent = parent::beforeSave($insert); // TODO: Change the autogenerated stub if (in_array($this->id, [ self::RUSSIAN, self::GERMAN, self::ENGLISH ])) { $this->rec_status = 1; } return $parent; } /** * @inheritdoc * @return array|false */ public function fields() { return [ 'id' => function () { return $this->id; }, 'title', 'code2', 'code3', 'is_deleted' => function () { return $this->isPublished() ? 0 : 1; } ]; } /** * Получить название языка * * @param $lang_id * @return mixed * @throws \Exception */ public static function getNativeLang($lang_id) { $map = [ self::ENGLISH => 'English', self::RUSSIAN => 'Russian', self::GERMAN => 'German' ]; return ArrayHelper::getValue($map, $lang_id); } }