You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

131 lines
5.7KB

  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. 'class' => 'yii\grid\ActionColumn',
  59. 'template' => '{commandes}',
  60. 'headerOptions' => ['class' => 'actions'],
  61. 'buttons' => [
  62. 'commandes' => function ($url, $model) {
  63. $url = Yii::$app->urlManager->createUrl(['user/commandes','id' => $model['id']]) ;
  64. $count_commandes = Commande::find()->joinWith('production')->where(['id_user' => $model['id'], 'production.id_etablissement' => Yii::$app->user->identity->id_etablissement])->count() ;
  65. $html = '' ;
  66. if($count_commandes)
  67. {
  68. $s = '' ;
  69. if($count_commandes > 1) $s = 's' ;
  70. $html .= Html::a('<span class="glyphicon glyphicon-eye-open"></span> '.$count_commandes.' commande'.$s, $url, [
  71. 'title' => Yii::t('app', 'Commandes'), 'class' => 'btn btn-default '
  72. ]); ;
  73. }
  74. else {
  75. $html .= 'Aucune commande' ;
  76. }
  77. return $html ;
  78. },
  79. ],
  80. ],
  81. [
  82. 'attribute' => 'credit',
  83. 'format' => 'raw',
  84. 'value' => function($model) use($etablissement) {
  85. $html = '<div class="input-group">
  86. <input type="text" class="form-control input-credit" readonly="readonly" value="'.number_format($model['credit'],2).' €" placeholder="">
  87. <span class="input-group-btn">
  88. '.Html::a(
  89. '<span class="glyphicon glyphicon-euro"></span> Crédit',
  90. Yii::$app->urlManager->createUrl(['user/credit','id' => $model['id']]),
  91. [
  92. 'title' => 'Crédit',
  93. 'class' => 'btn btn-default'
  94. ]
  95. ).'
  96. </span>
  97. </div>' ;
  98. return $html ;
  99. }
  100. ],
  101. [
  102. 'class' => 'yii\grid\ActionColumn',
  103. 'template' => '{update}',
  104. 'headerOptions' => ['class' => 'actions'],
  105. 'buttons' => [
  106. 'update' => function ($url, $model) {
  107. $url = Yii::$app->urlManager->createUrl(['user/update','id' => $model['id']]) ;
  108. $user = User::find()->with('userEtablissement')->where(['id' => $model['id']])->one() ;
  109. if(count($user->userEtablissement) <= 1)
  110. {
  111. return Html::a('<span class="glyphicon glyphicon-pencil"></span> Modifier', $url, [
  112. 'title' => Yii::t('app', 'Modifier'), 'class' => 'btn btn-default'
  113. ]);
  114. }
  115. else {
  116. 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>' ;
  117. }
  118. },
  119. ],
  120. ],
  121. ],
  122. ]); ?>
  123. </div>