|
- <?php
-
-
-
- use common\helpers\Price;
- use lo\widgets\Toggle;
- use yii\helpers\Html;
- use yii\grid\GridView;
-
- $this->setTitle('Fonctionnalités');
- $this->addBreadcrumb($this->getTitle());
-
- ?>
-
- <div class="feature-admin-index">
- <?= GridView::widget([
- 'dataProvider' => $dataProviderFeatures,
- 'columns' => [
- [
- 'attribute' => 'position',
- 'headerOptions' => ['class' => 'position'],
- 'format' => 'raw',
- 'filter' => '',
- 'value' => function ($model) {
- return '<a class="btn-position btn btn-default" href="javascript:void(0);"><span class="glyphicon glyphicon-resize-vertical"></span></a>';
- }
- ],
- 'name',
- [
- 'attribute' => 'status',
- 'headerOptions' => ['class' => 'status column-hide-on-mobile'],
- 'filterOptions' => ['class' => 'column-hide-on-mobile'],
- 'contentOptions' => ['class' => 'center column-hide-on-mobile'],
- 'format' => 'raw',
- 'filter' => [0 => 'Désactivée', 1 => 'Activée'],
- 'value' => function ($model) {
- return Toggle::widget(
- [
- 'name' => 'active',
- 'checked' => $model->status,
- 'options' => [
- 'data-id' => $model->id,
- 'data-on' => 'Activée',
- 'data-off' => 'Désactivée',
- ],
- ]
- );
- }
- ],
- [
- 'attribute' => 'producers',
- 'label' => 'Producteurs',
- 'headerOptions' => ['class' => 'column-hide-on-mobile'],
- 'filterOptions' => ['class' => 'column-hide-on-mobile'],
- 'contentOptions' => ['class' => 'column-hide-on-mobile'],
- 'format' => 'raw',
- 'value' => function ($model) {
- $html = '';
- foreach($model->featureProducers as $featureProducer) {
- if(!is_null($featureProducer->status)) {
- $html .= feature_status_producer($featureProducer->producer->name, $featureProducer->status);
- }
- }
-
- return $html;
- }
- ],
- [
- 'attribute' => 'only_for_selected_producers',
- 'label' => "Producteurs sélectionnés",
- 'headerOptions' => ['class' => 'only-for-selected-producers column-hide-on-mobile'],
- 'filterOptions' => ['class' => 'column-hide-on-mobile'],
- 'contentOptions' => ['class' => 'only-for-selected-producers column-hide-on-mobile'],
- 'format' => 'raw',
- 'value' => function ($model) {
- return '<span class="label label-'.($model->only_for_selected_producers ? 'success' : 'default').'">'
- .($model->only_for_selected_producers ? 'Oui' : 'Non') .'</span>';
- }
- ],
- [
- 'attribute' => 'is_paid_feature',
- 'headerOptions' => ['class' => 'column-hide-on-mobile'],
- 'filterOptions' => ['class' => 'column-hide-on-mobile'],
- 'contentOptions' => ['class' => 'column-hide-on-mobile'],
- 'format' => 'raw',
- 'value' => function ($model) {
- return '<span class="label label-'.($model->is_paid_feature ? 'success' : 'default').'">'
- .($model->is_paid_feature ? 'Oui' : 'Non') .'</span>';
- }
- ],
- [
- 'attribute' => 'price',
- 'headerOptions' => ['class' => 'column-hide-on-mobile'],
- 'filterOptions' => ['class' => 'column-hide-on-mobile'],
- 'contentOptions' => ['class' => 'column-hide-on-mobile'],
- 'format' => 'raw',
- 'value' => function ($model) {
- if($model->is_paid_feature && $model->price) {
- return Price::format($model->price, 0);
- }
-
- return '';
- }
- ],
- [
- 'class' => 'yii\grid\ActionColumn',
- 'template' => '{toggle_status_feature_producer} {update}',
- 'headerOptions' => ['class' => 'column-actions'],
- 'contentOptions' => ['class' => 'column-actions'],
- 'buttons' => [
- 'toggle_status_feature_producer' => function ($url, $model) use ($producerCurrent) {
- return '<div class="dropdown">
- <button class="btn btn-default dropdown-toggle" type="button" id="dropdownMenu1" data-toggle="dropdown" aria-haspopup="true" aria-expanded="true">
- '.Html::encode($producerCurrent->name).'
- <span class="caret"></span>
- </button>
- <ul class="dropdown-menu" aria-labelledby="dropdownMenu1">
- <li><a href="'.Yii::$app->urlManager->createUrl(['feature-admin/toggle-status-feature-producer', 'id' => $model->id]).'">Par défaut</a></li>
- <li><a href="'.Yii::$app->urlManager->createUrl(['feature-admin/toggle-status-feature-producer', 'id' => $model->id, 'status' => 1]).'">Activer</a></li>
- <li><a href="'.Yii::$app->urlManager->createUrl(['feature-admin/toggle-status-feature-producer', 'id' => $model->id, 'status' => 0]).'">Désactiver</a></li>
- </ul>
- </div>';
- },
- 'update' => function ($url, $model) {
- return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, [
- 'title' => 'Modifier', 'class' => 'btn btn-default'
- ]);
- },
- ],
- ],
- ]
- ]);
- ?>
- </div>
-
- <?php
-
- function feature_status_producer($producerName, $status): string {
- return '<span class="label label-'.($status ? 'success' : 'danger').'">'.Html::encode($producerName).'</span> ';
- }
-
- ?>
|