Browse Source

users list page display&search fix

Oleg K 2 years ago
parent
commit
8b97003ac6
5 changed files with 94 additions and 15 deletions
  1. 1 1
      config/web.php
  2. 3 3
      models/user/User.php
  3. 76 0
      models/user/search/Users.php
  4. 1 1
      views/profile/index.php
  5. 13 10
      views/user/admin/index.php

+ 1 - 1
config/web.php

@@ -148,7 +148,7 @@ $config = [
                 //'RecoveryForm' => 'app\models\security\RecoveryForm',
                 //'RegistrationForm' => 'app\models\security\RegistrationForm',
                 'User' => 'app\models\user\User',
-                //'UserSearch' => 'app\models\search\Users',
+                'UserSearch' => 'app\models\user\search\Users',
                 'LoginForm' => 'app\models\user\LoginForm',
                 //'Profile' => 'app\models\user\Profile',
                 //'SettingsForm' => 'app\models\user\SettingsForm',

+ 3 - 3
models/user/User.php

@@ -26,10 +26,10 @@ class User extends BaseUser
     public function attributeLabels()
     {
         return [
-            'uuid'              => \Yii::t('user', 'Nomer Dogovora'),
+            'uuid'              => \Yii::t('user', '№ договора'),
             'username'          => \Yii::t('user', 'Username'),
-            'fio'               => \Yii::t('user', 'Fio'),
-            'cname'             => \Yii::t('user', 'Company name'),
+            'fio'               => \Yii::t('user', 'ФІО'),
+            'cname'             => \Yii::t('user', 'Компанія'),
             'type'              => \Yii::t('user', 'Role'),
             'email'             => \Yii::t('user', 'Email'),
             'phone'             => \Yii::t('user', 'Phone'),

+ 76 - 0
models/user/search/Users.php

@@ -0,0 +1,76 @@
+<?php
+namespace app\models\user\search;
+
+use dektrium\user\models\UserSearch as BaseUserSearch;
+use Yii;
+use yii\data\ActiveDataProvider;
+
+class Users extends BaseUserSearch
+{
+    /** @var integer */
+    public $uuid;
+    public $fio;
+    public $cname;
+    public $phone;
+
+    public function rules()
+    {
+        return [
+            'fieldsSafe' => [['id', 'uuid', 'fio', 'cname', 'phone', 'email', 'registration_ip', 'created_at', 'last_login_at'], 'safe'],
+            'createdDefault' => ['created_at', 'default', 'value' => null],
+            'lastloginDefault' => ['last_login_at', 'default', 'value' => null],
+        ];
+    }
+
+    /** @inheritdoc */
+    public function attributeLabels()
+    {
+        return [
+            'id'              => Yii::t('user', '#'),
+            'uuid'            => Yii::t('user', 'Nomer Dogovora'),
+            'username'        => Yii::t('user', 'Username'),
+            'email'           => Yii::t('user', 'Email'),
+            'created_at'      => Yii::t('user', 'Registration time'),
+            'last_login_at'   => Yii::t('user', 'Last login'),
+            'registration_ip' => Yii::t('user', 'Registration ip'),
+        ];
+    }
+
+    /**
+     * @param $params
+     *
+     * @return ActiveDataProvider
+     */
+    public function search($params)
+    {
+        $query = $this->finder->getUserQuery();
+
+        $dataProvider = new ActiveDataProvider([
+               'query' => $query,
+               'sort' => ['defaultOrder' => ['created_at' => SORT_DESC]],
+           ]);
+
+        if (!($this->load($params) && $this->validate())) {
+            return $dataProvider;
+        }
+
+        $modelClass = $query->modelClass;
+        $table_name = $modelClass::tableName();
+
+        if ($this->created_at !== null) {
+            $date = strtotime($this->created_at);
+            $query->andFilterWhere(['between', $table_name . '.created_at', $date, $date + 3600 * 24]);
+        }
+
+        $query->andFilterWhere(['like', $table_name . '.username', $this->username])
+            ->andFilterWhere(['like', $table_name . '.phone', $this->phone])
+            ->andFilterWhere(['like', $table_name . '.email', $this->email])
+            ->andFilterWhere(['like', $table_name . '.fio', $this->fio])
+            ->andFilterWhere(['like', $table_name . '.cname', $this->cname])
+            ->andFilterWhere([$table_name . '.id' => $this->id])
+            ->andFilterWhere([$table_name . '.uuid' => $this->uuid])
+            ->andFilterWhere([$table_name . 'registration_ip' => $this->registration_ip]);
+
+        return $dataProvider;
+    }
+}

+ 1 - 1
views/profile/index.php

@@ -16,7 +16,7 @@ $this->params['breadcrumbs'][] = $this->title;
             </div>
             <div class="card-body box-profile">
                 <h3 class="profile-username text-center">
-                    <?= $profile->fio ? $profile->fio : '<small>Номер договора: </small><strong>' . $profile->uuid . '</strong>'; ?>
+                    <?= $profile->fio ? $profile->fio : '<small>Номер договору: </small><strong>' . $profile->uuid . '</strong>'; ?>
                 </h3>
 
                 <?php if ($profile->cname): ?>

+ 13 - 10
views/user/admin/index.php

@@ -37,13 +37,16 @@ $this->params['breadcrumbs'][] = $this->title;
     'filterModel'  => $searchModel,
     'layout'       => "{items}\n{pager}",
     'columns' => [
-        [
+        /*[
             'attribute' => 'id',
             'headerOptions' => ['style' => 'width:90px;'], # 90px is sufficient for 5-digit user ids
-        ],
+        ],*/
         'uuid',
+        'fio',
+        'cname',
+        'phone',
         'email:email',
-        [
+        /*[
             'attribute' => 'registration_ip',
             'value' => function ($model) {
                 return $model->registration_ip == null
@@ -51,8 +54,8 @@ $this->params['breadcrumbs'][] = $this->title;
                     : $model->registration_ip;
             },
             'format' => 'html',
-        ],
-        [
+        ],*/
+        /*[
             'attribute' => 'created_at',
             'value' => function ($model) {
                 if (extension_loaded('intl')) {
@@ -61,9 +64,9 @@ $this->params['breadcrumbs'][] = $this->title;
                     return date('Y-m-d G:i:s', $model->created_at);
                 }
             },
-        ],
+        ],*/
 
-        [
+        /*[
           'attribute' => 'last_login_at',
           'value' => function ($model) {
             if (!$model->last_login_at || $model->last_login_at == 0) {
@@ -74,8 +77,8 @@ $this->params['breadcrumbs'][] = $this->title;
                 return date('Y-m-d G:i:s', $model->last_login_at);
             }
           },
-        ],
-        [
+        ],*/
+        /*[
             'header' => Yii::t('user', 'Confirmation'),
             'value' => function ($model) {
                 if ($model->isConfirmed) {
@@ -92,7 +95,7 @@ $this->params['breadcrumbs'][] = $this->title;
             },
             'format' => 'raw',
             'visible' => Yii::$app->getModule('user')->enableConfirmation,
-        ],
+        ],*/
         [
             'header' => Yii::t('user', 'Block status'),
             'value' => function ($model) {