index.php 7.0 KB

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