view.php 6.16 KB
<?php
    use artweb\artbox\ecommerce\models\Label;
    use artweb\artbox\ecommerce\models\Order;
    use kartik\grid\GridView;
    use yii\data\ActiveDataProvider;
    use yii\helpers\Html;
    use yii\helpers\StringHelper;
    use yii\web\View;
    
    /**
     * @var ActiveDataProvider $dataProvider
     * @var View               $this
     * @var Label              $label
     */
    
    $this->title = 'Статистика по метке: ' . $label->lang->title;
    
    $this->params['breadcrumbs'][] = [
      'url' => ['index'],
      'label' => 'Статистика заказов',
    ];
    $this->params['breadcrumbs'][] = $this->title;
    
    $js = <<< JS
 $('[data-toggle="popover"]').popover();
JS;
$this->registerJs($js, View::POS_READY);
  
?>

<div class="box box-default">
  <div class="box-header with-border">
    <h3 class="box-title"><?=$this->title?></h3>
  </div><!-- /.box-header -->
  <div class="box-body">
    
      <?= GridView::widget(
          [
              'dataProvider' => $dataProvider,
              'columns'      => [
                  'id',
                  [
                      'label'   => 'Дата добавления',
                      'content' => function(Order $model) {
                          return \Yii::$app->formatter->asDate(
                                  $model->created_at
                              ) . '<br>' . \Yii::$app->formatter->asTime($model->created_at);
                      },
                  ],
                  'name',
                  [
                      'label'   => 'Товары',
                      'content' => function(Order $model) {
                          if (empty($model->products)) {
                              return '';
                          } else {
                              $content = '';
                              $i = 0;
                              foreach ($model->products as $product) {
                                  if (empty($product->productVariant)) {
                                      $image = '';
                                  } else {
                                      $image = $product->productVariant->imageUrl;
                                  }
                                  $i++;
                                  $content .= Html::a(
                                      $product->sku,
                                      '#',
                                      [
                                          'onclick'        => 'event.preventDefault();',
                                          'data-toggle'    => 'popover',
                                          'data-placement' => 'right',
                                          'data-html'      => 'true',
                                          'data-content'   => Html::img(
                                                  $image,
                                                  [
                                                      'class' => 'img-rounded',
                                                  ]
                                              ) . Html::tag('p', $product->product_name),
                                      ]
                                  );
                                  if ($i != count($model->products)) {
                                      $content .= ', ';
                                  }
                                  if ($i % 2 == 0) {
                                      $content .= '<br>';
                                  }
                              }
                              return $content;
                          }
                      },
                  ],
                  'city',
                  [
                      'attribute' => 'orderLabel.label',
                      'label'     => 'Метка',
                  ],
                  'total',
                  [
                      'attribute' => 'reason',
                      'content'   => function($model) {
                          /**
                           * @var Order $model
                           */
                          if (empty($model->reason)) {
                              return '';
                          } else {
                              return Order::REASONS[ $model->reason ];
                          }
                      },
                  ],
                  [
                      'attribute' => 'manager.username',
                      'label'     => 'Менеджер',
                  ],
                  [
                      'attribute' => 'body',
                      'content'   => function($model) {
                          /**
                           * @var Order $model
                           */
                          if (empty($model->body)) {
                              return '';
                          } else {
                              return Html::a(
                                  StringHelper::truncate($model->body, 10, '...'),
                                  '#',
                                  [
                                      'data-toggle' => 'tooltip',
                                      'title'       => $model->body,
                                      'onclick'     => 'event.preventDefault();',
                                  ]
                              );
                          }
                      },
                  ],
                  [
                      'content' => function($model) {
                          /**
                           * @var Order $model
                           */
                          return Html::a(
                              Html::tag('i', '', [ 'class' => 'glyphicon glyphicon-eye-open' ]),
                              [
                                  '/ecommerce/order/view',
                                  'id' => $model->id,
                              ],
                              [
                                  'target'    => '_blank',
                                  'data-pjax' => '0',
                              ]
                          );
                      },
                  ],
              ],
          ]
      ) ?>

  </div>
</div>