index.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. <?php
  2. /*
  3. * This file is part of the Dektrium project.
  4. *
  5. * (c) Dektrium project <http://github.com/dektrium>
  6. *
  7. * For the full copyright and license information, please view the LICENSE.md
  8. * file that was distributed with this source code.
  9. */
  10. use yii\grid\GridView;
  11. use yii\helpers\Html;
  12. use yii\helpers\Url;
  13. use yii\web\View;
  14. use yii\widgets\Pjax;
  15. /**
  16. * @var \yii\web\View $this
  17. * @var \yii\data\ActiveDataProvider $dataProvider
  18. * @var \dektrium\user\models\UserSearch $searchModel
  19. */
  20. $this->title = Yii::t('user', 'Manage users');
  21. $this->params['breadcrumbs'][] = $this->title;
  22. ?>
  23. <?= $this->render('/_alert', ['module' => Yii::$app->getModule('user')]) ?>
  24. <?= $this->render('/admin/_menu') ?>
  25. <?php Pjax::begin() ?>
  26. <?= GridView::widget([
  27. 'dataProvider' => $dataProvider,
  28. 'filterModel' => $searchModel,
  29. 'layout' => "{items}\n{pager}",
  30. 'columns' => [
  31. [
  32. 'attribute' => 'id',
  33. 'headerOptions' => ['style' => 'width:90px;'], # 90px is sufficient for 5-digit user ids
  34. ],
  35. 'username',
  36. 'email:email',
  37. [
  38. 'attribute' => 'registration_ip',
  39. 'value' => function ($model) {
  40. return $model->registration_ip == null
  41. ? '<span class="not-set">' . Yii::t('user', '(not set)') . '</span>'
  42. : $model->registration_ip;
  43. },
  44. 'format' => 'html',
  45. ],
  46. [
  47. 'attribute' => 'created_at',
  48. 'value' => function ($model) {
  49. if (extension_loaded('intl')) {
  50. return Yii::t('user', '{0, date, MMMM dd, YYYY HH:mm}', [$model->created_at]);
  51. } else {
  52. return date('Y-m-d G:i:s', $model->created_at);
  53. }
  54. },
  55. ],
  56. [
  57. 'attribute' => 'last_login_at',
  58. 'value' => function ($model) {
  59. if (!$model->last_login_at || $model->last_login_at == 0) {
  60. return Yii::t('user', 'Never');
  61. } else if (extension_loaded('intl')) {
  62. return Yii::t('user', '{0, date, MMMM dd, YYYY HH:mm}', [$model->last_login_at]);
  63. } else {
  64. return date('Y-m-d G:i:s', $model->last_login_at);
  65. }
  66. },
  67. ],
  68. [
  69. 'header' => Yii::t('user', 'Confirmation'),
  70. 'value' => function ($model) {
  71. if ($model->isConfirmed) {
  72. return '<div class="text-center">
  73. <span class="text-success">' . Yii::t('user', 'Confirmed') . '</span>
  74. </div>';
  75. } else {
  76. return Html::a(Yii::t('user', 'Confirm'), ['confirm', 'id' => $model->id], [
  77. 'class' => 'btn btn-xs btn-success btn-block',
  78. 'data-method' => 'post',
  79. 'data-confirm' => Yii::t('user', 'Are you sure you want to confirm this user?'),
  80. ]);
  81. }
  82. },
  83. 'format' => 'raw',
  84. 'visible' => Yii::$app->getModule('user')->enableConfirmation,
  85. ],
  86. [
  87. 'header' => Yii::t('user', 'Block status'),
  88. 'value' => function ($model) {
  89. if ($model->isBlocked) {
  90. return Html::a(Yii::t('user', 'Unblock'), ['block', 'id' => $model->id], [
  91. 'class' => 'btn btn-xs btn-success btn-block',
  92. 'data-method' => 'post',
  93. 'data-confirm' => Yii::t('user', 'Are you sure you want to unblock this user?'),
  94. ]);
  95. } else {
  96. return Html::a(Yii::t('user', 'Block'), ['block', 'id' => $model->id], [
  97. 'class' => 'btn btn-xs btn-danger btn-block',
  98. 'data-method' => 'post',
  99. 'data-confirm' => Yii::t('user', 'Are you sure you want to block this user?'),
  100. ]);
  101. }
  102. },
  103. 'format' => 'raw',
  104. ],
  105. [
  106. 'class' => 'yii\grid\ActionColumn',
  107. 'contentOptions' => ['style'=>'white-space:nowrap;'],
  108. 'template' => '{switch} {resend_password} {update} {delete}',
  109. 'buttons' => [
  110. 'resend_password' => function ($url, $model, $key) {
  111. if (\Yii::$app->user->identity->isAdmin && !$model->isAdmin) {
  112. return '
  113. <a data-method="POST" data-confirm="' . Yii::t('user', 'Are you sure?') . '" href="' . Url::to(['resend-password', 'id' => $model->id]) . '">
  114. <span title="' . Yii::t('user', 'Generate and send new password to user') . '" class="glyphicon glyphicon-envelope">
  115. </span> </a>';
  116. }
  117. },
  118. 'switch' => function ($url, $model) {
  119. if(\Yii::$app->user->identity->isAdmin && $model->id != Yii::$app->user->id && Yii::$app->getModule('user')->enableImpersonateUser) {
  120. return Html::a('<span class="glyphicon glyphicon-user"></span>', ['/user/admin/switch', 'id' => $model->id], [
  121. 'title' => Yii::t('user', 'Become this user'),
  122. 'data-confirm' => Yii::t('user', 'Are you sure you want to switch to this user for the rest of this Session?'),
  123. 'data-method' => 'POST',
  124. ]);
  125. }
  126. }
  127. ]
  128. ],
  129. ],
  130. ]); ?>
  131. <?php Pjax::end() ?>