|
- <?php
-
-
-
- use common\components\PageSizer;
- use common\logic\Producer\Producer\Wrapper\ProducerManager;
- use yii\helpers\Html;
- use yii\grid\GridView;
- use common\logic\User\User\Wrapper\UserManager;
- use common\logic\Order\Order\Model\Order;
- use common\logic\User\UserProducer\Model\UserProducer;
- use common\logic\User\User\Model\User;
-
- $producerManager = ProducerManager::getInstance();
-
- $this->setTitle('Utilisateurs');
- $this->addBreadcrumb($this->getTitle());
- $this->addButton(['label' => 'Nouvel utilisateur <span class="glyphicon glyphicon-plus"></span>', 'url' => 'user/create', 'class' => 'btn btn-primary']);
-
- ?>
-
- <?=
-
- $this->render('_menu', [
- 'idPointSaleActive' => $idPointSaleActive,
- 'sectionInactiveUsers' => $sectionInactiveUsers,
- 'sectionSubscribers' => $sectionSubscribers,
- 'pointsSaleArray' => $pointsSaleArray,
- 'section' => 'index'
- ]);
-
- ?>
-
- <?= GridView::widget([
- 'dataProvider' => $dataProvider,
- 'filterModel' => $searchModel,
- 'summary' => $this->getProducerContainer()->getProducerPageSizer()
- ->getPageSizeSummary($producer, 'user', 'Utilisateurs'),
- 'columns' => [
- [
- 'attribute' => 'username',
- 'label' => 'Nom',
- 'value' => function ($model) {
- $userManager = UserManager::getInstance();
- return $userManager->getUsername($model);
- }
- ],
- [
- 'attribute' => 'type',
- 'label' => 'Type',
- 'headerOptions' => ['class' => 'column-hide-on-mobile'],
- 'filterOptions' => ['class' => 'column-hide-on-mobile'],
- 'contentOptions' => ['class' => 'column-hide-on-mobile'],
- 'value' => function ($model) {
- $userManager = UserManager::getInstance();
- $typeArray = $userManager->getTypeChoicesArray();
- if(isset($typeArray[$model['type']])) {
- return $typeArray[$model['type']];
- }
- return '';
- }
- ],
- [
- 'attribute' => 'contacts',
- 'header' => 'Contacts',
- 'format' => 'raw',
- 'headerOptions' => ['class' => 'column-hide-on-mobile'],
- 'filterOptions' => ['class' => 'column-hide-on-mobile'],
- 'contentOptions' => ['class' => 'column-hide-on-mobile'],
- 'value' => function ($model) {
- $html = '';
- if (strlen($model['phone'])) {
- $html .= $model['phone'];
- }
- if (strlen($model['phone']) && strlen($model['email'])) {
- $html .= '<br />';
- }
- if (strlen($model['email'])) {
- $html .= $model['email'];
- }
- return $html;
- }
- ],
- [
- 'attribute' => 'newsletter',
- 'header' => "Inscrit au bulletin<br/>d'information",
- 'format' => 'raw',
- 'headerOptions' => ['class' => 'column-hide-on-mobile'],
- 'filterOptions' => ['class' => 'column-hide-on-mobile'],
- 'contentOptions' => ['class' => 'column-hide-on-mobile'],
- 'value' => function ($model) {
- $userManager = UserManager::getInstance();
- if($userManager->isUserSubscribedNewsletter($model)) {
- return '<span class="label label-success">Oui</span>';
- }
-
- return '<span class="label label-danger">Non</span>';
- }
- ],
- [
- 'class' => 'yii\grid\ActionColumn',
- 'header' => 'Commandes',
- 'template' => '{orders}',
- 'headerOptions' => ['class' => 'actions column-hide-on-mobile'],
- 'filterOptions' => ['class' => 'column-hide-on-mobile'],
- 'contentOptions' => ['class' => 'column-hide-on-mobile'],
- 'buttons' => [
- 'orders' => function ($url, $model) {
- $url = Yii::$app->urlManager->createUrl(['user/orders', 'id' => $model['id']]);
- $countOrders = Order::searchCount([
- 'id_user' => $model['id'],
- ], ['conditions' => 'date_delete IS NULL']);
-
- $html = '';
- if ($countOrders) {
- $html .= Html::a('<span class="glyphicon glyphicon-eye-open"></span> ' . $countOrders, $url, [
- 'title' => 'Commandes', 'class' => 'btn btn-default '
- ]);;
- } else {
- $html .= 'Aucune commande';
- }
-
- return $html;
- },
- ],
- ],
- [
- 'attribute' => 'credit',
- 'format' => 'raw',
- 'value' => function ($model) use ($producer) {
- $userProducer = UserProducer::searchOne([
- 'id_user' => $model->id
- ]);
- $credit = $userProducer ? $userProducer->credit : 0;
- $classBtnCredit = $userProducer->credit_active ? 'btn-success' : 'btn-default';
-
- $html = '<div class="input-group">
- <input type="text" class="form-control input-credit" readonly="readonly" value="' . number_format($credit, 2) . ' €" placeholder="">
- <span class="input-group-btn">
- ' . Html::a(
- '<span class="glyphicon glyphicon-euro"></span>',
- Yii::$app->urlManager->createUrl(['user/credit', 'id' => $model->id]),
- [
- 'title' => 'Crédit',
- 'class' => 'btn ' . $classBtnCredit
- ]
- ) . '
- </span>
- </div>';
-
- return $html;
- }
- ],
- [
- 'class' => 'yii\grid\ActionColumn',
- 'template' => '{update} {delete} {switch}',
- 'headerOptions' => ['class' => 'column-actions'],
- 'contentOptions' => ['class' => 'column-actions'],
- 'buttons' => [
- 'update' => function ($url, $model) {
- $url = Yii::$app->urlManager->createUrl(['user/update', 'id' => $model->id]);
- $user = User::find()->with('userProducer')->where(['id' => $model->id])->one();
- return Html::a('<span class="glyphicon glyphicon-pencil"></span>', $url, [
- 'title' => 'Modifier', 'class' => 'btn btn-default'
- ]);
- },
- 'delete' => function ($url, $model) {
- return Html::a('<span class="glyphicon glyphicon-trash"></span>', Yii::$app->urlManager->createUrl(array_merge(['user/delete', 'id' => $model->id], Yii::$app->getRequest()->getQueryParams())), [
- 'title' => 'Supprimer', 'class' => 'btn btn-default btn-confirm-delete'
- ]);
- },
- 'switch' => function($url, $model) {
- $userManager = UserManager::getInstance();
- if($userManager->isCurrentAdmin()) {
- return Html::a('<span class="glyphicon glyphicon-user"></span>', Yii::$app->urlManager->createUrl(['user/switch-identity', 'id' => $model->id]), [
- 'title' => 'Prendre la main', 'class' => 'btn btn-default'
- ]);
- }
- }
- ],
- ],
- ],
- ]); ?>
|