Improve start/count parameter

This commit is contained in:
nupplaPhil 2020-02-25 23:22:47 +01:00
parent d950a3241b
commit ed422be734
No known key found for this signature in database
GPG key ID: D8365C3D36B77D90
3 changed files with 29 additions and 15 deletions

View file

@ -64,9 +64,10 @@ Usage
bin/console user deny [<nickname>] [-h|--help|-?] [-v] bin/console user deny [<nickname>] [-h|--help|-?] [-v]
bin/console user block [<nickname>] [-h|--help|-?] [-v] bin/console user block [<nickname>] [-h|--help|-?] [-v]
bin/console user unblock [<nickname>] [-h|--help|-?] [-v] bin/console user unblock [<nickname>] [-h|--help|-?] [-v]
bin/console user list pending [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 [start=0 [count=50]] [-h|--help|-?] [-v] bin/console user list removed [-s|--start=0] [-c|--count=50] [-h|--help|-?] [-v]
bin/console user list all [start=0 [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 <UID> [-h|--help|-?] [-v] bin/console user search id <UID> [-h|--help|-?] [-v]
bin/console user search nick <nick> [-h|--help|-?] [-v] bin/console user search nick <nick> [-h|--help|-?] [-v]
bin/console user search mail <mail> [-h|--help|-?] [-v] bin/console user search mail <mail> [-h|--help|-?] [-v]
@ -326,8 +327,8 @@ HELP;
private function listUser() private function listUser()
{ {
$subCmd = $this->getArgument(1); $subCmd = $this->getArgument(1);
$start = $this->getArgument(2, 0); $start = $this->getOption(['s', 'start'], 0);
$count = $this->getArgument(3, Pager::ITEMS_PER_PAGE); $count = $this->getOption(['c', 'count'], Pager::ITEMS_PER_PAGE);
$table = new Console_Table(); $table = new Console_Table();
@ -348,15 +349,11 @@ HELP;
$this->out($table->getTable()); $this->out($table->getTable());
return true; return true;
case 'all': case 'all':
case 'active':
case 'removed': case 'removed':
$table->setHeaders(['Nick', 'Name', 'URL', 'E-Mail', 'Register', 'Login', 'Last Item']); $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) { foreach ($contacts as $contact) {
if (($subCmd != 'removed') && !empty($contact['account_removed']) ||
($subCmd == 'removed') && empty($contact['account_removed'])) {
continue;
}
$table->addRow([ $table->addRow([
$contact['nick'], $contact['nick'],
$contact['name'], $contact['name'],

View file

@ -1323,21 +1323,38 @@ class User
* *
* @param int $start Start count (Default is 0) * @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 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 Order of the user list (Default is 'contact.name')
* @param string $order_direction Order direction (Default is ASC) * @param string $order_direction Order direction (Default is ASC)
* *
* @return array The list of the users * @return array The list of the users
* @throws Exception * @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'; $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` $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` FROM `user`
INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self` 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 ORDER BY $sql_order $sql_order_direction LIMIT ?, ?", $start, $count
); );

View file

@ -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'))); $adminlist = explode(',', str_replace(' ', '', DI::config()->get('config', 'admin_email')));
$_setup_users = function ($e) use ($adminlist) { $_setup_users = function ($e) use ($adminlist) {