From f9d29e15f536a378f1608db729c98cafdc620ba8 Mon Sep 17 00:00:00 2001 From: b1ek Date: Tue, 20 Aug 2024 14:55:10 +1000 Subject: [PATCH] feat: display images in list --- models/ParameterSearch.php | 2 +- views/list/index.php | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) diff --git a/models/ParameterSearch.php b/models/ParameterSearch.php index 788bb56..901da23 100644 --- a/models/ParameterSearch.php +++ b/models/ParameterSearch.php @@ -24,7 +24,7 @@ class ParameterSearch extends Parameter public function search($params): ActiveDataProvider { - $query = Parameter::find(); + $query = Parameter::find()->with(['icon', 'iconGray']); $dataProvider = new ActiveDataProvider([ 'query' => $query, diff --git a/views/list/index.php b/views/list/index.php index cd034dd..bd246e1 100644 --- a/views/list/index.php +++ b/views/list/index.php @@ -1,4 +1,5 @@ title = 'params list'; + ?>

Parameters

@@ -23,4 +25,34 @@ $this->title = 'params list'; $provider, 'filterModel' => $searchModel, + 'columns' => [ + 'id', 'title', 'type', + [ + 'label' => 'Icon', + 'value' => function (Parameter $model) { + if ($model->icon) { + $url = '/api/image?sha256=' . $model->getRelatedRecords()['icon']->sha256; + return Html::a(Html::img($url, [ 'width' => 150, 'height' => 150 ]), $url, [ 'alt' => 'icon', 'target' => '_blank' ]); + } + }, + 'format' => 'raw', + ], + [ + 'label' => 'Gray Icon', + 'value' => function (Parameter $model) { + if ($model->iconGray) { + $url = '/api/image?sha256=' . $model->getRelatedRecords()['iconGray']->sha256; + return Html::a(Html::img($url, [ 'width' => 150, 'height' => 150 ]), $url, [ 'alt' => 'grayscale icon', 'target' => '_blank' ]); + } + }, + 'format' => 'raw', + ], + [ + 'label' => 'Edit', + 'value' => function (Parameter $model) { + return Html::a('Edit', '/list/edit?id=' . $model->id); + }, + 'format' => 'raw', + ], + ] ]); ?>