index.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. use dektrium\user\models\Profile;
  16. use dektrium\user\models\User;
  17. /**
  18. * @var \yii\web\View $this
  19. * @var \yii\data\ActiveDataProvider $dataProvider
  20. * @var \dektrium\user\models\UserSearch $searchModel
  21. */
  22. $this->title = Yii::t('user', 'Manage users');
  23. $this->params['breadcrumbs'][] = $this->title;
  24. ?>
  25. <?= $this->render('/_alert', ['module' => Yii::$app->getModule('user')]) ?>
  26. <?= $this->render('/admin/_menu') ?>
  27. <?php Pjax::begin() ?>
  28. <?
  29. ?>
  30. <?= GridView::widget([
  31. 'dataProvider' => $dataProvider,
  32. 'filterModel' => $searchModel,
  33. 'layout' => "{items}\n{pager}",
  34. 'columns' => [
  35. [
  36. 'attribute' => 'id',
  37. 'headerOptions' => ['style' => 'width:90px;'], # 90px is sufficient for 5-digit user ids
  38. ],
  39. 'username',
  40. [
  41. 'attribute' => 'Name',
  42. 'value' => function ($model) {
  43. $s='';
  44. //Yii::$app->profile->get($model->id);
  45. $profile = Profile::findOne($model->id);
  46. return $profile->name;
  47. },
  48. 'format' => 'html',
  49. ],
  50. 'email:email',
  51. [
  52. 'attribute' => 'registration_ip',
  53. 'value' => function ($model) {
  54. return $model->registration_ip == null
  55. ? '<span class="not-set">' . Yii::t('user', '(not set)') . '</span>'
  56. : $model->registration_ip;
  57. },
  58. 'format' => 'html',
  59. ],
  60. [
  61. 'attribute' => 'Роли',
  62. 'value' => function ($model) {
  63. $s='';
  64. foreach(Yii::$app->authManager->getRolesByUser($model->id) as $role=>$set){
  65. $s .= $set->name.' ';
  66. }
  67. return $s;
  68. },
  69. 'format' => 'html',
  70. ],
  71. [
  72. 'attribute' => 'created_at',
  73. 'value' => function ($model) {
  74. if (extension_loaded('intl')) {
  75. return Yii::t('user', '{0, date, MMMM dd, YYYY HH:mm}', [$model->created_at]);
  76. } else {
  77. return date('Y-m-d G:i:s', $model->created_at);
  78. }
  79. },
  80. ],
  81. [
  82. 'attribute' => 'last_login_at',
  83. 'value' => function ($model) {
  84. if (!$model->last_login_at || $model->last_login_at == 0) {
  85. return Yii::t('user', 'Never');
  86. } else if (extension_loaded('intl')) {
  87. return Yii::t('user', '{0, date, MMMM dd, YYYY HH:mm}', [$model->last_login_at]);
  88. } else {
  89. return date('Y-m-d G:i:s', $model->last_login_at);
  90. }
  91. },
  92. ],
  93. [
  94. 'header' => Yii::t('user', 'Confirmation'),
  95. 'value' => function ($model) {
  96. if ($model->isConfirmed) {
  97. return '<div class="text-center">
  98. <span class="text-success">' . Yii::t('user', 'Confirmed') . '</span>
  99. </div>';
  100. } else {
  101. return Html::a(Yii::t('user', 'Confirm'), ['confirm', 'id' => $model->id], [
  102. 'class' => 'btn btn-xs btn-success btn-block',
  103. 'data-method' => 'post',
  104. 'data-confirm' => Yii::t('user', 'Are you sure you want to confirm this user?'),
  105. ]);
  106. }
  107. },
  108. 'format' => 'raw',
  109. 'visible' => Yii::$app->getModule('user')->enableConfirmation,
  110. ],
  111. [
  112. 'header' => Yii::t('user', 'Block status'),
  113. 'value' => function ($model) {
  114. if ($model->isBlocked) {
  115. return Html::a(Yii::t('user', 'Unblock'), ['block', 'id' => $model->id], [
  116. 'class' => 'btn btn-xs btn-success btn-block',
  117. 'data-method' => 'post',
  118. 'data-confirm' => Yii::t('user', 'Are you sure you want to unblock this user?'),
  119. ]);
  120. } else {
  121. return Html::a(Yii::t('user', 'Block'), ['block', 'id' => $model->id], [
  122. 'class' => 'btn btn-xs btn-danger btn-block',
  123. 'data-method' => 'post',
  124. 'data-confirm' => Yii::t('user', 'Are you sure you want to block this user?'),
  125. ]);
  126. }
  127. },
  128. 'format' => 'raw',
  129. ],
  130. [
  131. 'class' => 'yii\grid\ActionColumn',
  132. 'template' => '{switch} {resend_password} {update} {delete}',
  133. 'buttons' => [
  134. 'resend_password' => function ($url, $model, $key) {
  135. if (\Yii::$app->user->identity->isAdmin && !$model->isAdmin) {
  136. return '
  137. <a data-method="POST" data-confirm="' . Yii::t('user', 'Are you sure?') . '" href="' . Url::to(['resend-password', 'id' => $model->id]) . '">
  138. <span title="' . Yii::t('user', 'Generate and send new password to user') . '" class="glyphicon glyphicon-envelope">
  139. </span> </a>';
  140. }
  141. },
  142. 'switch' => function ($url, $model) {
  143. if(\Yii::$app->user->identity->isAdmin && $model->id != Yii::$app->user->id && Yii::$app->getModule('user')->enableImpersonateUser) {
  144. return Html::a('<span class="glyphicon glyphicon-user"></span>', ['/user/admin/switch', 'id' => $model->id], [
  145. 'title' => Yii::t('user', 'Become this user'),
  146. 'data-confirm' => Yii::t('user', 'Are you sure you want to switch to this user for the rest of this Session?'),
  147. 'data-method' => 'POST',
  148. ]);
  149. }
  150. }
  151. ]
  152. ],
  153. ],
  154. ]); ?>
  155. <?php Pjax::end() ?>