Skip to content

Commit

Permalink
Merge pull request #1683 from voltan/develop
Browse files Browse the repository at this point in the history
Add search on username
  • Loading branch information
voltan authored Jan 27, 2021
2 parents c644d55 + b8a1def commit 097f069
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 52 deletions.
10 changes: 6 additions & 4 deletions usr/module/user/asset/ng-template/admin/index-activated.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@
</div>
&nbsp;
<div class="form-group">
<input type="text" placeholder="{{'DISPLAYNAME' | translate}}" class="form-control"
data-ng-model="filter.name">
<input type="text" placeholder="{{'DISPLAYNAME' | translate}}" class="form-control" data-ng-model="filter.name">
</div>

<div class="form-group">
<input type="text" placeholder="{{'USERNAME' | translate}}" class="form-control" data-ng-model="filter.identity">
</div>
&nbsp;
<div class="form-group">
<input type="text" placeholder="{{'EMAIL' | translate}}" class="form-control"
data-ng-model="filter.email">
<input type="text" placeholder="{{'EMAIL' | translate}}" class="form-control" data-ng-model="filter.email">
</div>
&nbsp;
<button class="btn btn-info" data-ng-click="filterAction()" style="padding: 4px 20px;">
Expand Down
10 changes: 6 additions & 4 deletions usr/module/user/asset/ng-template/admin/index-all.html
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,15 @@
</div>
&nbsp;
<div class="form-group">
<input type="text" placeholder="{{'DISPLAYNAME' | translate}}" class="form-control"
data-ng-model="filter.name">
<input type="text" placeholder="{{'DISPLAYNAME' | translate}}" class="form-control" data-ng-model="filter.name">
</div>

<div class="form-group">
<input type="text" placeholder="{{'USERNAME' | translate}}" class="form-control" data-ng-model="filter.identity">
</div>
&nbsp;
<div class="form-group">
<input type="text" placeholder="{{'EMAIL' | translate}}" class="form-control"
data-ng-model="filter.email">
<input type="text" placeholder="{{'EMAIL' | translate}}" class="form-control" data-ng-model="filter.email">
</div>
&nbsp;
<button class="btn btn-info" data-ng-click="filterAction()" style="padding: 4px 20px;">
Expand Down
10 changes: 6 additions & 4 deletions usr/module/user/asset/ng-template/admin/index-pending.html
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,15 @@
</div>
&nbsp;
<div class="form-group">
<input type="text" placeholder="{{'DISPLAYNAME' | translate}}" class="form-control"
data-ng-model="filter.name">
<input type="text" placeholder="{{'DISPLAYNAME' | translate}}" class="form-control" data-ng-model="filter.name">
</div>

<div class="form-group">
<input type="text" placeholder="{{'USERNAME' | translate}}" class="form-control" data-ng-model="filter.identity">
</div>
&nbsp;
<div class="form-group">
<input type="text" placeholder="{{'EMAIL' | translate}}" class="form-control"
data-ng-model="filter.email">
<input type="text" placeholder="{{'EMAIL' | translate}}" class="form-control" data-ng-model="filter.email">
</div>
&nbsp;
<button class="btn btn-info" data-ng-click="filterAction()" style="padding: 4px 20px;">
Expand Down
111 changes: 71 additions & 40 deletions usr/module/user/src/Controller/Admin/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,17 @@ class IndexController extends ActionController
{
/**
* Default action
*
* @return array|void
*/
public function indexAction()
{
$this->view()->setTemplate('user');
$this->view()->assign([
'roles' => $this->getRoles(),
]);
$this->view()->assign(
[
'roles' => $this->getRoles(),
]
);
}

/**
Expand All @@ -43,6 +46,7 @@ public function allAction()
$limit = Pi::config('list_limit', 'user');
$offset = (int)($page - 1) * $limit;

$condition = [];
$condition['activated'] = _get('activated') ?: '';
$condition['active'] = _get('active') ?: '';
$condition['enable'] = _get('enable') ?: '';
Expand All @@ -51,8 +55,9 @@ public function allAction()
$condition['register_date'] = _get('register_date') ?: '';
$condition['name'] = _get('name') ?: '';
$condition['email'] = _get('email') ?: '';
$condition['identity'] = _get('identity') ?: '';

list($users, $count) = $this->getUsers($condition, $limit, $offset);
[$users, $count] = $this->getUsers($condition, $limit, $offset);

// Set paginator
$paginator = [
Expand All @@ -79,6 +84,7 @@ public function activatedAction()
$limit = Pi::config('list_limit', 'user');
$offset = (int)($page - 1) * $limit;

$condition = [];
$condition['activated'] = 'activated';
$condition['active'] = _get('active') ?: '';
$condition['enable'] = _get('enable') ?: '';
Expand All @@ -88,8 +94,9 @@ public function activatedAction()
$condition['search'] = _get('search') ?: '';
$condition['name'] = _get('name') ?: '';
$condition['email'] = _get('email') ?: '';
$condition['identity'] = _get('identity') ?: '';

list($users, $count) = $this->getUsers($condition, $limit, $offset);
[$users, $count] = $this->getUsers($condition, $limit, $offset);

// Set paginator
$paginator = [
Expand All @@ -116,6 +123,7 @@ public function pendingAction()
$limit = Pi::config('list_limit', 'user');
$offset = (int)($page - 1) * $limit;

$condition = [];
$condition['activated'] = 'pending';
$condition['enable'] = _get('enable') ?: '';
$condition['front_role'] = _get('front_role') ?: '';
Expand All @@ -124,8 +132,9 @@ public function pendingAction()
$condition['search'] = _get('search') ?: '';
$condition['name'] = _get('name') ?: '';
$condition['email'] = _get('email') ?: '';
$condition['identity'] = _get('identity') ?: '';

list($users, $count) = $this->getUsers($condition, $limit, $offset);
[$users, $count] = $this->getUsers($condition, $limit, $offset);

// Set paginator
$paginator = [
Expand Down Expand Up @@ -287,7 +296,7 @@ public function searchAction()
$limit = Pi::config('list_limit', 'user');
$offset = (int)($page - 1) * $limit;

list($users, $count) = $this->getUsers($condition, $limit, $offset);
[$users, $count] = $this->getUsers($condition, $limit, $offset);

// Set paginator
$paginator = [
Expand Down Expand Up @@ -408,7 +417,7 @@ public function deleteUserAction()
foreach ($uids as $uid) {
$status = Pi::api('user', 'user')->deleteUser($uid);
if (Pi::service('module')->isActive('subscription')) {
Pi::api('people', 'subscription')->update(array('status' => 0), $uid);
Pi::api('people', 'subscription')->update(['status' => 0], $uid);
}
if (!is_array($status) && $status !== false) {
$count++;
Expand Down Expand Up @@ -547,9 +556,11 @@ public function assignRoleAction()
}

$users = [];
array_walk($uids, function ($uid) use (&$users) {
array_walk(
$uids, function ($uid) use (&$users) {
$users[$uid] = ['id' => $uid];
});
}
);
$data = $this->renderRole($users);
$result['data'] = $data;
$result['status'] = 1;
Expand All @@ -561,7 +572,7 @@ public function assignRoleAction()
/**
* Get users and count according to conditions
*
* @param $condition
* @param $condition
* @param int $limit
* @param int $offset
*
Expand Down Expand Up @@ -630,10 +641,12 @@ protected function getUsers($condition, $limit = 0, $offset = 0)
$i = 1;
foreach ($condition['front_role'] as $role) {
$prefix = $i;
$whereRoleFront = Pi::db()->where()->create([
'front' . $prefix . '.role' => $role,
'front' . $prefix . '.section' => 'front',
]);
$whereRoleFront = Pi::db()->where()->create(
[
'front' . $prefix . '.role' => $role,
'front' . $prefix . '.section' => 'front',
]
);
$where->add($whereRoleFront);
$select->join(
['front' . $prefix => $modelRole->getTable()],
Expand All @@ -643,10 +656,12 @@ protected function getUsers($condition, $limit = 0, $offset = 0)
$i++;
}
} else {
$whereRoleFront = Pi::db()->where()->create([
'front.role' => $condition['front_role'],
'front.section' => 'front',
]);
$whereRoleFront = Pi::db()->where()->create(
[
'front.role' => $condition['front_role'],
'front.section' => 'front',
]
);
$where->add($whereRoleFront);
$select->join(
['front' => $modelRole->getTable()],
Expand All @@ -661,10 +676,12 @@ protected function getUsers($condition, $limit = 0, $offset = 0)
$i = 1;
foreach ($condition['admin_role'] as $role) {
$prefix = $i;
$whereRoleFront = Pi::db()->where()->create([
'admin' . $prefix . '.role' => $role,
'admin' . $prefix . '.section' => 'admin',
]);
$whereRoleFront = Pi::db()->where()->create(
[
'admin' . $prefix . '.role' => $role,
'admin' . $prefix . '.section' => 'admin',
]
);
$where->add($whereRoleFront);
$select->join(
['admin' . $prefix => $modelRole->getTable()],
Expand All @@ -674,10 +691,12 @@ protected function getUsers($condition, $limit = 0, $offset = 0)
$i++;
}
} else {
$whereRoleFront = Pi::db()->where()->create([
'admin.role' => $condition['admin_role'],
'admin.section' => 'admin',
]);
$whereRoleFront = Pi::db()->where()->create(
[
'admin.role' => $condition['admin_role'],
'admin.section' => 'admin',
]
);
$where->add($whereRoleFront);
$select->join(
['admin' => $modelRole->getTable()],
Expand All @@ -689,9 +708,11 @@ protected function getUsers($condition, $limit = 0, $offset = 0)

if (!empty($condition['ip_register'])) {
$profileModel = $this->getModel('profile');
$whereProfile = Pi::db()->where()->create([
'profile.ip_register like ?' => '%' . $condition['ip_register'] . '%',
]);
$whereProfile = Pi::db()->where()->create(
[
'profile.ip_register like ?' => '%' . $condition['ip_register'] . '%',
]
);
$where->add($whereProfile);
$select->join(
['profile' => $profileModel->getTable()],
Expand Down Expand Up @@ -746,18 +767,22 @@ protected function getUsers($condition, $limit = 0, $offset = 0)
'register_source',
];
$users = Pi::api('user', 'user')->get($uids, $columns);
array_walk($users, function (&$user, $uid) {
$user['link'] = Pi::service('user')->getUrl('profile', [
array_walk(
$users, function (&$user, $uid) {
$user['link'] = Pi::service('user')->getUrl(
'profile', [
'id' => $uid,
]);
]
);
$user['active'] = (bool)$user['active'];
$user['time_disabled'] = $user['time_disabled']
? _date($user['time_disabled']) : 0;
$user['time_activated'] = $user['time_activated']
? _date($user['time_activated']) : 0;
$user['time_created'] = $user['time_created']
? _date($user['time_created']) : 0;
});
}
);
$users = $this->renderRole($users);
}
}
Expand Down Expand Up @@ -876,14 +901,16 @@ protected function renderRole(array $users)
$roleKey = $section . '_roles';
$roleList[$uid][$roleKey][] = $roles[$row['role']]['title'];
}
array_walk($users, function (&$user, $uid) use ($roleList) {
array_walk(
$users, function (&$user, $uid) use ($roleList) {
if (isset($roleList[$uid]['front_roles'])) {
$user['front_roles'] = $roleList[$uid]['front_roles'];
}
if (isset($roleList[$uid]['admin_roles'])) {
$user['admin_roles'] = $roleList[$uid]['admin_roles'];
}
});
}
);

return $users;
}
Expand All @@ -892,6 +919,7 @@ protected function renderRole(array $users)
* Get users status: active, activated, disable
*
* @param int[] $uids
*
* @return array
*/
protected function getUserStatus($uids)
Expand Down Expand Up @@ -919,9 +947,10 @@ protected function getUserStatus($uids)
/**
* Delete user field
*
* @param $uid
* @param $field
* @param $uid
* @param $field
* @param string $type core or user
*
* @return int
*/
protected function deleteUser($uid, $field, $type = '')
Expand Down Expand Up @@ -963,10 +992,12 @@ protected function sendNotification($uid)
$failedUsers = [];
foreach ($users as $id => $data) {
$redirect = Pi::user()->data()->get($id, 'register_redirect') ?: '';
$url = Pi::api('user', 'user')->getUrl('login', [
$url = Pi::api('user', 'user')->getUrl(
'login', [
'redirect' => $redirect,
'section' => 'front',
]);
]
);
$url = Pi::url($url, true);
$params = [
'username' => $data['identity'],
Expand Down

0 comments on commit 097f069

Please sign in to comment.