index.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  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. 'username',
  32. 'email:email',
  33. [
  34. 'attribute' => 'registration_ip',
  35. 'value' => function ($model) {
  36. return $model->registration_ip == null
  37. ? '<span class="not-set">' . Yii::t('user', '(not set)') . '</span>'
  38. : $model->registration_ip;
  39. },
  40. 'format' => 'html',
  41. ],
  42. [
  43. 'attribute' => 'created_at',
  44. 'value' => function ($model) {
  45. if (extension_loaded('intl')) {
  46. return Yii::t('user', '{0, date, MMMM dd, YYYY HH:mm}', [$model->created_at]);
  47. } else {
  48. return date('Y-m-d G:i:s', $model->created_at);
  49. }
  50. },
  51. ],
  52. [
  53. 'attribute' => 'last_login_at',
  54. 'value' => function ($model) {
  55. if (!$model->last_login_at || $model->last_login_at == 0) {
  56. return Yii::t('user', 'Never');
  57. } else if (extension_loaded('intl')) {
  58. return Yii::t('user', '{0, date, MMMM dd, YYYY HH:mm}', [$model->last_login_at]);
  59. } else {
  60. return date('Y-m-d G:i:s', $model->last_login_at);
  61. }
  62. },
  63. ],
  64. [
  65. 'header' => Yii::t('user', 'Confirmation'),
  66. 'value' => function ($model) {
  67. if ($model->isConfirmed) {
  68. return '<div class="text-center">
  69. <span class="text-success">' . Yii::t('user', 'Confirmed') . '</span>
  70. </div>';
  71. } else {
  72. return Html::a(Yii::t('user', 'Confirm'), ['confirm', 'id' => $model->id], [
  73. 'class' => 'btn btn-xs btn-success btn-block',
  74. 'data-method' => 'post',
  75. 'data-confirm' => Yii::t('user', 'Are you sure you want to confirm this user?'),
  76. ]);
  77. }
  78. },
  79. 'format' => 'raw',
  80. 'visible' => Yii::$app->getModule('user')->enableConfirmation,
  81. ],
  82. [
  83. 'header' => Yii::t('user', 'Block status'),
  84. 'value' => function ($model) {
  85. if ($model->isBlocked) {
  86. return Html::a(Yii::t('user', 'Unblock'), ['block', 'id' => $model->id], [
  87. 'class' => 'btn btn-xs btn-success btn-block',
  88. 'data-method' => 'post',
  89. 'data-confirm' => Yii::t('user', 'Are you sure you want to unblock this user?'),
  90. ]);
  91. } else {
  92. return Html::a(Yii::t('user', 'Block'), ['block', 'id' => $model->id], [
  93. 'class' => 'btn btn-xs btn-danger btn-block',
  94. 'data-method' => 'post',
  95. 'data-confirm' => Yii::t('user', 'Are you sure you want to block this user?'),
  96. ]);
  97. }
  98. },
  99. 'format' => 'raw',
  100. ],
  101. [
  102. 'class' => 'yii\grid\ActionColumn',
  103. 'template' => '{switch} {resend_password} {update} {delete}',
  104. 'buttons' => [
  105. 'resend_password' => function ($url, $model, $key) {
  106. if (!$model->isAdmin) {
  107. return '
  108. <a data-method="POST" data-confirm="' . Yii::t('user', 'Are you sure?') . '" href="' . Url::to(['resend-password', 'id' => $model->id]) . '">
  109. <span title="' . Yii::t('user', 'Generate and send new password to user') . '" class="glyphicon glyphicon-envelope">
  110. </span> </a>';
  111. }
  112. },
  113. 'switch' => function ($url, $model) {
  114. if($model->id != Yii::$app->user->id && Yii::$app->getModule('user')->enableImpersonateUser) {
  115. return Html::a('<span class="glyphicon glyphicon-user"></span>', ['/user/admin/switch', 'id' => $model->id], [
  116. 'title' => Yii::t('user', 'Become this user'),
  117. 'data-confirm' => Yii::t('user', 'Are you sure you want to switch to this user for the rest of this Session?'),
  118. 'data-method' => 'POST',
  119. ]);
  120. }
  121. }
  122. ]
  123. ],
  124. ],
  125. ]); ?>
  126. <?php Pjax::end() ?>