|
- <?php
-
-
-
- use common\helpers\GlobalParam;
- use domain\PointSale\PointSale\PointSale;
- use domain\Producer\Producer\ProducerModule;
- use domain\Product\Product\ProductModule;
- use domain\Subscription\Subscription\SubscriptionModule;
- use yii\grid\GridView;
- use yii\helpers\ArrayHelper;
- use yii\helpers\Html;
-
- $producerModule = ProducerModule::getInstance();
- $productModule = ProductModule::getInstance();
- $subscriptionModule = SubscriptionModule::getInstance();
-
- $this->setTitle('Abonnements');
- $this->addButton(['label' => '<i class="bi bi-plus-lg"></i> Créer', 'url' => 'subscription/form', 'class' => 'btn btn-primary']);
-
- $columns = [
- [
- 'label' => 'Point de vente',
- 'format' => 'raw',
- 'filter' => ArrayHelper::map(PointSale::find()->where(['id_producer' => GlobalParam::getCurrentProducerId()])->asArray()->all(), 'id', 'name'),
- 'value' => function ($model) {
- $html = '';
- if ($model->pointSale) {
- $html .= Html::encode($model->pointSale->name);
- $html .= '<br /><span class="locality">'. Html::encode($model->pointSale->locality). '</span>';
- }
- return $html;
- }
- ],
- [
- 'attribute' => 'product_name',
- 'label' => 'Produits',
- 'format' => 'raw',
- 'value' => function ($subscription) use ($subscriptionModule) {
- return $subscriptionModule->getProductsListAsHtml($subscription);
- }
- ],
- [
- 'attribute' => 'day',
- 'label' => 'Jours',
- 'format' => 'raw',
- 'filter' => [
- 'monday' => 'Lundi',
- 'tuesday' => 'Mardi',
- 'wednesday' => 'Mercredi',
- 'thursday' => 'Jeudi',
- 'friday' => 'Vendredi',
- 'saterday' => 'Samedi',
- 'sunday' => 'Dimanche',
- ],
- 'contentOptions' => ['class' => 'text-small'],
- 'value' => function ($model) {
- $html = '';
- if ($model->monday) {
- $html .= 'lundi, ';
- }
- if ($model->tuesday) {
- $html .= 'mardi, ';
- }
- if ($model->wednesday) {
- $html .= 'mercredi, ';
- }
- if ($model->thursday) {
- $html .= 'jeudi, ';
- }
- if ($model->friday) {
- $html .= 'vendredi, ';
- }
- if ($model->saturday) {
- $html .= 'samedi, ';
- }
- if ($model->sunday) {
- $html .= 'dimanche, ';
- }
-
- if (strlen($html)) {
- return substr($html, 0, strlen($html) - 2);
- } else {
- return '<i class="bi bi-exclamation-triangle"></i> Aucun jour';
- }
- }
- ],
- [
- 'attribute' => 'week_frequency',
- 'filter' => [
- 1 => 'Toutes les semaines',
- 2 => 'Toutes les 2 semaines',
- 3 => 'Toutes les 3 semaines',
- 4 => 'Tous les mois'],
- 'value' => function ($model) {
- if ($model->week_frequency == 1) {
- return 'Toutes les semaines';
- } else {
- return 'Toutes les ' . $model->week_frequency . ' semaines';
- }
-
- }
- ],
- [
- 'attribute' => 'date_begin',
- 'label' => 'Date de début',
- 'format' => 'raw',
- 'value' => function ($model) {
- $html = date('d/m/Y', strtotime($model->date_begin));
- return $html;
- }
- ],
- ];
-
-
-
- $columns[] = [
- 'class' => 'yii\grid\ActionColumn',
- 'template' => '{form} {delete}',
- 'headerOptions' => ['class' => 'column-actions'],
- 'contentOptions' => ['class' => 'column-actions'],
- 'buttons' => [
- 'form' => function ($url, $model) {
- return Html::a('<i class="bi bi-pencil"></i>', $url, [
- 'title' => 'Modifier',
- 'class' => 'btn btn-secondary',
- 'data-bs-toggle' => 'tooltip',
- 'data-bs-placement' => 'top',
- 'title' => 'Modifier'
- ]);
- },
- 'delete' => function ($url, $model) {
- return Html::a('<i class="bi bi-trash"></i>', $url, [
- 'title' => 'Supprimer',
- 'class' => 'btn btn-secondary',
- 'data-bs-toggle' => 'tooltip',
- 'data-bs-placement' => 'top',
- 'title' => 'Supprimer'
- ]);
- }
- ],
- ];
-
- ?>
- <div class="subscription-index">
- <?php if ($dataProvider->getCount()): ?>
- <div class="table-responsive">
- <?= GridView::widget([
- 'dataProvider' => $dataProvider,
- 'columns' => $columns,
- 'summary' => ''
- ]); ?>
- </div>
- <?php else: ?>
- <div class="alert alert-dark">
- Vous n'avez aucun abonnement chez ce producteur.
- </div>
- <?php endif; ?>
- </div>
|