Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

149 Zeilen
6.4KB

  1. <?php
  2. use yii\helpers\Html;
  3. use yii\grid\GridView;
  4. use common\models\User ;
  5. use common\models\Commande ;
  6. /* @var $this yii\web\View */
  7. /* @var $dataProvider yii\data\ActiveDataProvider */
  8. $this->title = 'Utilisateurs';
  9. $this->params['breadcrumbs'][] = $this->title;
  10. ?>
  11. <div class="user-index">
  12. <h1>
  13. <?= Html::encode($this->title) ?>
  14. <?= Html::a('Ajouter', ['create'], ['class' => 'btn btn-primary']) ?>
  15. <?= Html::a('<span class="glyphicon glyphicon-envelope"></span> Liste des emails', ['mail'], ['class' => 'btn btn-default']) ?>
  16. </h1>
  17. <?= GridView::widget([
  18. 'dataProvider' => $dataProvider,
  19. 'filterModel' => true,
  20. 'columns' => [
  21. [
  22. 'attribute' => 'nom',
  23. 'filter' => Html::input(
  24. 'string',
  25. 'nom',
  26. isset(Yii::$app->request->queryParams['nom']) ? Html::encode(Yii::$app->request->queryParams['nom']) : '',
  27. [ 'class' => 'form-control']
  28. )
  29. ],
  30. [
  31. 'attribute' => 'prenom',
  32. 'filter' => Html::input(
  33. 'string',
  34. 'prenom',
  35. isset(Yii::$app->request->queryParams['prenom']) ? Html::encode(Yii::$app->request->queryParams['prenom']) : '',
  36. ['class' => 'form-control']
  37. )
  38. ],
  39. [
  40. 'attribute' => 'telephone',
  41. 'filter' => Html::input(
  42. 'string',
  43. 'telephone',
  44. isset(Yii::$app->request->queryParams['telephone']) ? Html::encode(Yii::$app->request->queryParams['telephone']) : '',
  45. ['class' => 'form-control']
  46. )
  47. ],
  48. [
  49. 'attribute' => 'email',
  50. 'filter' => Html::input(
  51. 'string',
  52. 'email',
  53. isset(Yii::$app->request->queryParams['email']) ? Html::encode(Yii::$app->request->queryParams['email']) : '',
  54. ['class' => 'form-control']
  55. )
  56. ],
  57. [
  58. 'attribute' => 'created_at',
  59. 'label' => 'Date d\'inscription',
  60. 'value' => function($model) {
  61. if(isset($model['created_at']))
  62. return date('m/d/Y à H:i', $model['created_at']);
  63. }
  64. ],
  65. [
  66. 'attribute' => 'date_derniere_connexion',
  67. 'label' => 'Dernière connexion',
  68. 'value' => function($model) {
  69. if(isset($model['date_derniere_connexion']))
  70. return date('m/d/Y à H:i', strtotime($model['date_derniere_connexion']));
  71. else
  72. return '' ;
  73. }
  74. ],
  75. [
  76. 'class' => 'yii\grid\ActionColumn',
  77. 'template' => '{commandes}',
  78. 'headerOptions' => ['class' => 'actions'],
  79. 'buttons' => [
  80. 'commandes' => function ($url, $model) {
  81. $url = Yii::$app->urlManager->createUrl(['user/commandes','id' => $model['id']]) ;
  82. $count_commandes = Commande::find()->joinWith('production')->where(['id_user' => $model['id'], 'production.id_etablissement' => Yii::$app->user->identity->id_etablissement])->count() ;
  83. $html = '' ;
  84. if($count_commandes)
  85. {
  86. $s = '' ;
  87. if($count_commandes > 1) $s = 's' ;
  88. $html .= Html::a('<span class="glyphicon glyphicon-eye-open"></span> '.$count_commandes.' commande'.$s, $url, [
  89. 'title' => Yii::t('app', 'Commandes'), 'class' => 'btn btn-default '
  90. ]); ;
  91. }
  92. else {
  93. $html .= 'Aucune commande' ;
  94. }
  95. return $html ;
  96. },
  97. ],
  98. ],
  99. [
  100. 'attribute' => 'credit',
  101. 'format' => 'raw',
  102. 'value' => function($model) use($etablissement) {
  103. $html = '<div class="input-group">
  104. <input type="text" class="form-control input-credit" readonly="readonly" value="'.number_format($model['credit'],2).' €" placeholder="">
  105. <span class="input-group-btn">
  106. '.Html::a(
  107. '<span class="glyphicon glyphicon-euro"></span> Crédit',
  108. Yii::$app->urlManager->createUrl(['user/credit','id' => $model['id']]),
  109. [
  110. 'title' => 'Crédit',
  111. 'class' => 'btn btn-default'
  112. ]
  113. ).'
  114. </span>
  115. </div>' ;
  116. return $html ;
  117. }
  118. ],
  119. [
  120. 'class' => 'yii\grid\ActionColumn',
  121. 'template' => '{update}',
  122. 'headerOptions' => ['class' => 'actions'],
  123. 'buttons' => [
  124. 'update' => function ($url, $model) {
  125. $url = Yii::$app->urlManager->createUrl(['user/update','id' => $model['id']]) ;
  126. $user = User::find()->with('userEtablissement')->where(['id' => $model['id']])->one() ;
  127. if(count($user->userEtablissement) <= 1)
  128. {
  129. return Html::a('<span class="glyphicon glyphicon-pencil"></span> Modifier', $url, [
  130. 'title' => Yii::t('app', 'Modifier'), 'class' => 'btn btn-default'
  131. ]);
  132. }
  133. else {
  134. return '<span data-toggle="tooltip" data-placement="top" title="Vous ne pouvez pas modifier les utilisateurs qui appartiennent à plusieurs boulangeries."><span class="glyphicon glyphicon-remove-sign"></span> Non modifiable</span>' ;
  135. }
  136. },
  137. ],
  138. ],
  139. ],
  140. ]); ?>
  141. </div>