/
v.bolshakov
/
AIEcosystem-Testing
Обзор
Документация
Войти
/
v.bolshakov
/
AIEcosystem-Testing
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
dev
common/widgets/model/Info.php
94 строки
3 KB
Developer
Initial commit
03 авг 2026, 17:43
03 авг 2026, 17:43
7433917
Код
Авторство
О чём код?
<?php namespace common\widgets\model; use common\components\crud\ViewCrud; use common\models\User; use common\widgets\DetailView; use Yii; /** * Отображение специфичных данных о модели * * @author Dmitry E. Semenov <sde.tomsk@gmail.com> * @copyright Self (c) 2020 */ class Info extends BaseWidget { /** * Показывать системыне поля * @var bool */ public $use_system = true; /** * ширина колонки с названием поля * @var bool */ public $col_md = 2; /** * Выполнение виджета * * @return string */ public function run() { $fields = $this->crud->fields(); $model = $this->model; if ($this->crud instanceof ViewCrud) { $this->use_system = $this->crud->use_system; } // показывать или нет системные поля if ($this->use_system) { // Кто добавил запись if ($model->hasAttribute($model->created_attribute['user'])) { $fields['created'] = [ 'value' => $model->created, 'label' => Yii::t('app', 'Date of creation'), ]; /** @var User $user */ $user = $model->createdBy; $fields[] = [ 'value' => function () use ($user) { return $user ? $user->username : null; }, 'label' => Yii::t('app', 'Author'), ]; } // Когда изменилась запись if ($model->hasAttribute($model->updated_attribute['date'])) { $fields['updated'] = [ 'value' => $model->updated, 'label' => Yii::t('app', 'Last change date'), ]; } // Кто обновил запись if ($model->hasAttribute($model->updated_attribute['user'])) { /** @var User $user */ $user = $model->updatedBy; $fields[] = [ 'value' => function () use ($user) { return $user ? $user->username : null; }, 'label' => Yii::t('app', 'Change author'), ]; } } echo DetailView::widget([ 'model' => $this->model, 'attributes' => $fields, 'template' => '<tr><th class="col-md-' . $this->col_md . ' text-bold text-right" {captionOptions}>{label}</th><td{contentOptions}>{value}</td></tr>' ]); } }