namespace app\controllers;
+use yii\data\ActiveDataProvider;
use yii\web\Controller;
+use yii_app\records\CityStore;
class StoreController extends Controller
{
public function actionStats() { return $this->render('stats'); }
+
+ public function actionIndex()
+ {
+ // Создаем DataProvider, чтобы получить магазины, у которых visible = 1
+ $dataProvider = new ActiveDataProvider([
+ 'query' => CityStore::find()
+ ->where(['visible' => 1])
+ ->with(['city', 'cluster', 'administrator']), // Загружаем связанные данные
+ 'pagination' => [
+ 'pageSize' => 20,
+ ],
+ ]);
+
+ return $this->render('index', [
+ 'dataProvider' => $dataProvider,
+ ]);
+ }
public function actionItemmatrix() { return $this->render('itemmatrix'); }
}
\ No newline at end of file
--- /dev/null
+<?php
+
+use yii\helpers\Html;
+use yii\grid\GridView;
+
+/** @var yii\web\View $this */
+/** @var yii\data\ActiveDataProvider $dataProvider */
+
+$this->title = 'Список магазинов';
+$this->params['breadcrumbs'][] = $this->title;
+?>
+<div class="store-index p-4">
+
+ <h1><?= Html::encode($this->title) ?></h1>
+
+ <p>
+ <?= Html::a('Создать магазин', ['/city-store/create'], ['class' => 'btn btn-success']) ?>
+ </p>
+
+ <?= GridView::widget([
+ 'dataProvider' => $dataProvider,
+ 'columns' => [
+ ['class' => 'yii\grid\SerialColumn'],
+
+ [
+ 'attribute' => 'name',
+ 'label' => 'Наименование магазина',
+ ],
+ [
+ 'attribute' => 'city.city_name_ru',
+ 'label' => 'Город',
+ 'value' => function ($model) {
+ return $model->city ? $model->city->city_name_ru : '(Не указан)';
+ },
+ ],
+ [
+ 'attribute' => 'cluster.name',
+ 'label' => 'Куст',
+ 'value' => function ($model) {
+ return $model->cluster ? $model->cluster->name : '(Не указан)';
+ },
+ ],
+ [
+ 'attribute' => 'administrator.name',
+ 'label' => 'Администратор',
+ 'value' => function ($model) {
+ return $model->administrator ? $model->administrator->name : '(Не указан)';
+ },
+ ],
+
+ [
+ 'class' => 'yii\grid\ActionColumn',
+ 'template' => '{view} {update}', // Убираем действие удаления
+ 'buttons' => [
+ 'view' => function ($url, $model, $key) {
+
+ return Html::a(Html::img('@web/images/icon-view.svg', ['alt' => 'View Icon', 'style' => 'width: 1em; height: 1em; display: inline-block; vertical-align: -0.125em;']), [
+ '/city-store/view',
+ 'id' => $model->id,
+
+ ], [
+ 'class' => 'btn btn-primary btn-sm',
+ 'title' => 'Просмотр',
+ 'data-bs-toggle' => 'tooltip', // Подсказка на иконке
+ 'data-bs-placement' => 'top',
+ ]);
+
+
+ },
+ 'update' => function ($url, $model, $key) {
+
+ return Html::a(Html::img('@web/images/icon-edit.svg', ['alt' => 'Edit Icon', 'style' => 'width: 1em; height: 1em; display: inline-block; vertical-align: -0.125em;']), [
+ '/city-store/update',
+ 'id' => $model->id,
+
+ ], [
+ 'class' => 'btn btn-success btn-sm',
+ 'title' => 'Редактировать',
+ 'data-bs-toggle' => 'tooltip',
+ 'data-bs-placement' => 'top',
+ ]);
+
+ },
+
+ ],
+ ],
+
+ ],
+ ]); ?>
+</div>