/
v.bolshakov
/
AIEcosystem-Testing
Обзор
Документация
Войти
/
v.bolshakov
/
AIEcosystem-Testing
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
dev
common/widgets/model/Grid.php
128 строк
4 KB
Developer
Initial commit
03 авг 2026, 17:43
03 авг 2026, 17:43
7433917
Код
Авторство
О чём код?
<?php namespace common\widgets\model; use common\components\crud\FormCrud; use common\grid\ActionColumn; use common\grid\GridPanelView; use common\helpers\ArrayHelper; use common\helpers\TextHelper; use common\models\base\BaseModel; use Yii; use yii\base\Model; use yii\helpers\Url; /** * Отображение данных в табличной форме * * @author Dmitry E. Semenov <sde.tomsk@gmail.com> * @copyright Self (c) 2020 */ class Grid extends BaseWidget { /** * Crud форма для создания новой записи * @var FormCrud */ public $form = null; /** * Родительский элемент текущего объекта * @var BaseModel */ public $parent = null; /** * Отображение данных * * @return string * @throws \Exception */ public function run() { $columns = $this->crud->columns(); $indexed_columns = []; $the_index = 0; foreach ($columns as $column) { $index = ArrayHelper::getValue($column, 'options.index', $the_index); $indexed_columns[$index] = $column; $the_index += 10; } ArrayHelper::ksortRecursive($indexed_columns); foreach ($indexed_columns as $i => $column) { if (ActionColumn::className() == ArrayHelper::getValue($column, 'class')) { $indexed_columns[$i]['parent'] = $this->parent; } } $button = null; $header = $this->crud->headingElements(); if ($this->form) { $title = $this->form->getTitle(); if ($this->form->render == 'default') { $button = [ 'icon' => 'file-plus', 'label' => Yii::t('app', $title), 'url' => ['create', 'parent_id' => $this->parent ? $this->parent->id : null], 'options' => [ 'class' => 'btn btn-success', ] ]; } else { $button = [ 'icon' => 'file-plus', 'label' => Yii::t('app', $title), 'options' => [ 'class' => 'ajax-modal btn btn-success', 'data' => [ 'source' => Url::to([ '/modal/source', 'class' => $this->form->classNameUrl(), 'parent_id' => $this->parent ? $this->parent->id : null, 'reload' => 1, ]), 'action' => Url::to([ '/modal/update', 'class' => $this->form->classNameUrl(), 'reload' => 1, 'parent_id' => $this->parent ? $this->parent->id : null, ]), ] ] ]; } $header[] = $button; } return GridPanelView::widget([ 'dataProvider' => $this->dataProvider, 'names' => $this->model->modelName, 'columns' => $indexed_columns, 'buttons' => $header, 'tableSise' => $this->crud->gridSise, 'filterSelector' => '#per_page', 'rowOptions' => function ($model, $index, $widget, $grid) { if (is_array($model)) { if ($color = ArrayHelper::getValue($model, 'color')) { if ($class = TextHelper::toColor($color)) { return ['class' => $class]; } } } elseif (method_exists($model, 'isPublished') and !$model->isPublished()) { return ['class' => 'danger']; } elseif (method_exists($model, 'getClassStatus') or ($model instanceof Model and $model->getBehavior('ConfirmBehavior'))) { return ['class' => $model->getClassStatus()]; } return []; }, ]); } }