From ed422be734c10f2fad1b44ee41d0b4d8722366e2 Mon Sep 17 00:00:00 2001 From: nupplaPhil Date: Tue, 25 Feb 2020 23:22:47 +0100 Subject: [PATCH] Improve start/count parameter --- src/Console/User.php | 19 ++++++++----------- src/Model/User.php | 23 ++++++++++++++++++++--- src/Module/Admin/Users.php | 2 +- 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/src/Console/User.php b/src/Console/User.php index 5c75353a6..ab6b9623c 100644 --- a/src/Console/User.php +++ b/src/Console/User.php @@ -64,9 +64,10 @@ Usage bin/console user deny [] [-h|--help|-?] [-v] bin/console user block [] [-h|--help|-?] [-v] bin/console user unblock [] [-h|--help|-?] [-v] - bin/console user list pending [start=0 [count=50]] [-h|--help|-?] [-v] - bin/console user list removed [start=0 [count=50]] [-h|--help|-?] [-v] - bin/console user list all [start=0 [count=50]] [-h|--help|-?] [-v] + bin/console user list pending [-s|--start=0] [-c|--count=50] [-h|--help|-?] [-v] + bin/console user list removed [-s|--start=0] [-c|--count=50] [-h|--help|-?] [-v] + bin/console user list active [-s|--start=0] [-c|--count=50] [-h|--help|-?] [-v] + bin/console user list all [-s|--start=0] [-c|--count=50] [-h|--help|-?] [-v] bin/console user search id [-h|--help|-?] [-v] bin/console user search nick [-h|--help|-?] [-v] bin/console user search mail [-h|--help|-?] [-v] @@ -326,8 +327,8 @@ HELP; private function listUser() { $subCmd = $this->getArgument(1); - $start = $this->getArgument(2, 0); - $count = $this->getArgument(3, Pager::ITEMS_PER_PAGE); + $start = $this->getOption(['s', 'start'], 0); + $count = $this->getOption(['c', 'count'], Pager::ITEMS_PER_PAGE); $table = new Console_Table(); @@ -348,15 +349,11 @@ HELP; $this->out($table->getTable()); return true; case 'all': + case 'active': case 'removed': $table->setHeaders(['Nick', 'Name', 'URL', 'E-Mail', 'Register', 'Login', 'Last Item']); - $contacts = UserModel::getUsers($start, $count); + $contacts = UserModel::getUsers($start, $count, $subCmd); foreach ($contacts as $contact) { - if (($subCmd != 'removed') && !empty($contact['account_removed']) || - ($subCmd == 'removed') && empty($contact['account_removed'])) { - continue; - } - $table->addRow([ $contact['nick'], $contact['name'], diff --git a/src/Model/User.php b/src/Model/User.php index b0db51a11..c0b9f71c0 100644 --- a/src/Model/User.php +++ b/src/Model/User.php @@ -1323,21 +1323,38 @@ class User * * @param int $start Start count (Default is 0) * @param int $count Count of the items per page (Default is @see Pager::ITEMS_PER_PAGE) + * @param string $type The type of users, which should get (all, bocked, removed) * @param string $order Order of the user list (Default is 'contact.name') * @param string $order_direction Order direction (Default is ASC) * * @return array The list of the users * @throws Exception */ - public static function getUsers($start = 0, $count = Pager::ITEMS_PER_PAGE, $order = 'contact.name', $order_direction = '+') + public static function getUsers($start = 0, $count = Pager::ITEMS_PER_PAGE, $type = 'all', $order = 'contact.name', $order_direction = '+') { - $sql_order = '`' . str_replace('.', '`.`', $order) . '`'; + $sql_order = '`' . str_replace('.', '`.`', $order) . '`'; $sql_order_direction = ($order_direction === '+') ? 'ASC' : 'DESC'; + switch ($type) { + case 'active': + $sql_extra = 'AND `user`.`blocked` = 0'; + break; + case 'blocked': + $sql_extra = 'AND `user`.`blocked` = 1'; + break; + case 'removed': + $sql_extra = 'AND `user`.`account_removed` = 1'; + break; + case 'all': + default: + $sql_extra = ''; + break; + } + $usersStmt = DBA::p("SELECT `user`.*, `contact`.`name`, `contact`.`url`, `contact`.`micro`, `user`.`account_expired`, `contact`.`last-item` AS `lastitem_date`, `contact`.`nick`, `contact`.`created` FROM `user` INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self` - WHERE `user`.`verified` + WHERE `user`.`verified` $sql_extra ORDER BY $sql_order $sql_order_direction LIMIT ?, ?", $start, $count ); diff --git a/src/Module/Admin/Users.php b/src/Module/Admin/Users.php index 66f70a90c..6064892f5 100644 --- a/src/Module/Admin/Users.php +++ b/src/Module/Admin/Users.php @@ -179,7 +179,7 @@ class Users extends BaseAdmin } } - $users = User::getUsers($pager->getStart(), $pager->getItemsPerPage(), $order, $order_direction); + $users = User::getUsers($pager->getStart(), $pager->getItemsPerPage(), 'all', $order, $order_direction); $adminlist = explode(',', str_replace(' ', '', DI::config()->get('config', 'admin_email'))); $_setup_users = function ($e) use ($adminlist) {