index.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  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. [
  40. 'attribute' => 'Фото',
  41. 'value' => function ($model) {
  42. if( file_exists(Yii::getAlias('@webroot').'/images/users/'.$model->id.'_sm.jpg') ){
  43. $s = Html::img('/images/users/'.$model->id.'_sm.jpg',['class' => "direct-chat-img"]);
  44. }else{
  45. $s = '';
  46. }
  47. return $s;
  48. },
  49. 'format' => 'html',
  50. ],
  51. 'username',
  52. [
  53. 'attribute' => 'Name',
  54. 'value' => function ($model) {
  55. $s='';
  56. //Yii::$app->profile->get($model->id);
  57. $profile = Profile::findOne($model->id);
  58. return $profile->name;
  59. },
  60. 'format' => 'html',
  61. ],
  62. 'email:email',
  63. [
  64. 'attribute' => 'registration_ip',
  65. 'value' => function ($model) {
  66. return $model->registration_ip == null
  67. ? '<span class="not-set">' . Yii::t('user', '(not set)') . '</span>'
  68. : $model->registration_ip;
  69. },
  70. 'format' => 'html',
  71. ],
  72. [
  73. 'attribute' => 'Роли',
  74. 'value' => function ($model) {
  75. $s='';
  76. foreach(Yii::$app->authManager->getRolesByUser($model->id) as $role=>$set){
  77. $s .= $set->name.' ';
  78. }
  79. return $s;
  80. },
  81. 'format' => 'html',
  82. ],
  83. [
  84. 'attribute' => 'created_at',
  85. 'value' => function ($model) {
  86. if (extension_loaded('intl')) {
  87. return Yii::t('user', '{0, date, MMMM dd, YYYY HH:mm}', [$model->created_at]);
  88. } else {
  89. return date('Y-m-d G:i:s', $model->created_at);
  90. }
  91. },
  92. ],
  93. [
  94. 'attribute' => 'last_login_at',
  95. 'value' => function ($model) {
  96. if (!$model->last_login_at || $model->last_login_at == 0) {
  97. return Yii::t('user', 'Never');
  98. } else if (extension_loaded('intl')) {
  99. return Yii::t('user', '{0, date, MMMM dd, YYYY HH:mm}', [$model->last_login_at]);
  100. } else {
  101. return date('Y-m-d G:i:s', $model->last_login_at);
  102. }
  103. },
  104. ],
  105. [
  106. 'header' => Yii::t('user', 'Confirmation'),
  107. 'value' => function ($model) {
  108. if ($model->isConfirmed) {
  109. return '<div class="text-center">
  110. <span class="text-success">' . Yii::t('user', 'Confirmed') . '</span>
  111. </div>';
  112. } else {
  113. return Html::a(Yii::t('user', 'Confirm'), ['confirm', 'id' => $model->id], [
  114. 'class' => 'btn btn-xs btn-success btn-block',
  115. 'data-method' => 'post',
  116. 'data-confirm' => Yii::t('user', 'Are you sure you want to confirm this user?'),
  117. ]);
  118. }
  119. },
  120. 'format' => 'raw',
  121. 'visible' => Yii::$app->getModule('user')->enableConfirmation,
  122. ],
  123. [
  124. 'header' => Yii::t('user', 'Block status'),
  125. 'value' => function ($model) {
  126. if ($model->isBlocked) {
  127. return Html::a(Yii::t('user', 'Unblock'), ['block', 'id' => $model->id], [
  128. 'class' => 'btn btn-xs btn-success btn-block',
  129. 'data-method' => 'post',
  130. 'data-confirm' => Yii::t('user', 'Are you sure you want to unblock this user?'),
  131. ]);
  132. } else {
  133. return Html::a(Yii::t('user', 'Block'), ['block', 'id' => $model->id], [
  134. 'class' => 'btn btn-xs btn-danger btn-block',
  135. 'data-method' => 'post',
  136. 'data-confirm' => Yii::t('user', 'Are you sure you want to block this user?'),
  137. ]);
  138. }
  139. },
  140. 'format' => 'raw',
  141. ],
  142. [
  143. 'class' => 'yii\grid\ActionColumn',
  144. 'template' => '{switch} {resend_password} {update} {avatar} {delete}',
  145. 'buttons' => [
  146. 'resend_password' => function ($url, $model, $key) {
  147. if (\Yii::$app->user->identity->isAdmin && !$model->isAdmin) {
  148. return '
  149. <a data-method="POST" data-confirm="' . Yii::t('user', 'Are you sure?') . '" href="' . Url::to(['resend-password', 'id' => $model->id]) . '">
  150. <span title="' . Yii::t('user', 'Generate and send new password to user') . '" class="glyphicon glyphicon-envelope">
  151. </span> </a>';
  152. }
  153. },
  154. 'switch' => function ($url, $model) {
  155. if(\Yii::$app->user->identity->isAdmin && $model->id != Yii::$app->user->id && Yii::$app->getModule('user')->enableImpersonateUser) {
  156. return Html::a('<span class="glyphicon glyphicon-user"></span>', ['/user/admin/switch', 'id' => $model->id], [
  157. 'title' => Yii::t('user', 'Become this user'),
  158. 'data-confirm' => Yii::t('user', 'Are you sure you want to switch to this user for the rest of this Session?'),
  159. 'data-method' => 'POST',
  160. ]);
  161. }
  162. },
  163. 'avatar' => function ($url, $model) {
  164. if(\Yii::$app->user->identity->isAdmin && Yii::$app->getModule('user')->enableImpersonateUser) {
  165. return Html::a('<span class="glyphicon glyphicon-picture"></span>', ['/manager/userex', 'id' => $model->id], [
  166. 'title' => Yii::t('user', 'Avatar this user')
  167. ]);
  168. }
  169. }
  170. ]
  171. ],
  172. ],
  173. ]); ?>
  174. <?php Pjax::end() ?>