namespace Friendica\Console;
+use Console_Table;
use Friendica\App;
+use Friendica\Content\Pager;
use Friendica\Core\L10n;
use Friendica\Database\Database;
use Friendica\Model\Register;
use Seld\CliPrompt\CliPrompt;
/**
- * tool to set a new password for a user
- *
- * With this tool, you can set a new password for a user
+ * tool to manage users of the current node
*/
class User extends \Asika\SimpleConsole\Console
{
bin/console user deny [<nickname>] [-h|--help|-?] [-v]
bin/console user block [<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 all [start=0 [count=50]] [-h|--help|-?] [-v]
Description
Modify user settings per console commands.
return $this->blockUser(false);
case 'delete':
return $this->deleteUser();
+ case 'list':
+ return $this->listUser();
default:
throw new \Asika\SimpleConsole\CommandArgsException('Wrong command.');
}
return UserModel::remove($user['uid'] ?? -1);
}
+
+ /**
+ * List user of the current node
+ *
+ * @return bool True, if the command was successful
+ */
+ private function listUser()
+ {
+ $subCmd = $this->getArgument(1);
+ $start = $this->getArgument(2, 0);
+ $count = $this->getArgument(3, Pager::ITEMS_PER_PAGE);
+
+ $table = new Console_Table();
+
+ switch ($subCmd) {
+ case 'pending':
+ $table->setHeaders(['Nick', 'Name', 'URL', 'E-Mail', 'Register Date', 'Comment']);
+ $pending = Register::getPending($start, $count);
+ foreach ($pending as $contact) {
+ $table->addRow([
+ $contact['nick'],
+ $contact['name'],
+ $contact['url'],
+ $contact['email'],
+ $contact['created'],
+ $contact['note'],
+ ]);
+ }
+ $this->out($table->getTable());
+ return true;
+ case 'all':
+ default:
+ $table->setHeaders(['Nick', 'Name', 'URL', 'E-Mail', 'Register Date', 'Comment']);
+ $contacts = UserModel::getUsers($start, $count);
+ foreach ($contacts as $contact) {
+ $table->addRow([
+ $contact['nick'],
+ $contact['name'],
+ $contact['url'],
+ $contact['email'],
+ $contact['created'],
+ $contact['note'],
+ ]);
+ }
+ $this->out($table->getTable());
+ return true;
+ }
+ }
}
*/
class Pager
{
+ /** @var int Default count of items per page */
+ const ITEMS_PER_PAGE = 50;
+
/** @var integer */
private $page = 1;
/** @var integer */
- protected $itemsPerPage = 50;
+ protected $itemsPerPage = self::ITEMS_PER_PAGE;
/** @var string */
protected $baseQueryString = '';
namespace Friendica\Model;
+use Friendica\Content\Pager;
use Friendica\Database\DBA;
use Friendica\Util\DateTimeFormat;
use Friendica\Util\Strings;
/**
* Return the list of pending registrations
*
+ * @param int $start Start count (Default is 0)
+ * @param int $count Count of the items per page (Default is @see Pager::ITEMS_PER_PAGE)
+ *
* @return array
* @throws \Exception
*/
- public static function getPending()
+ public static function getPending($start = 0, $count = Pager::ITEMS_PER_PAGE)
{
$stmt = DBA::p(
- "SELECT `register`.*, `contact`.`name`, `contact`.`url`, `contact`.`micro`, `user`.`email`
+ "SELECT `register`.*, `contact`.`name`, `contact`.`url`, `contact`.`micro`, `user`.`email`, `contact`.`nick`
FROM `register`
INNER JOIN `contact` ON `register`.`uid` = `contact`.`uid`
- INNER JOIN `user` ON `register`.`uid` = `user`.`uid`"
+ INNER JOIN `user` ON `register`.`uid` = `user`.`uid`
+ LIMIT ?, ?", $start, $count
);
return DBA::toArray($stmt);
use DivineOmega\PasswordExposed;
use Exception;
+use Friendica\Content\Pager;
use Friendica\Core\Hook;
use Friendica\Core\L10n;
use Friendica\Core\Logger;
return $statistics;
}
+
+ /**
+ * Get all users of the current node
+ *
+ * @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 $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 = '+')
+ {
+ $sql_order = '`' . str_replace('.', '`.`', $order) . '`';
+ $sql_order_direction = ($order_direction === '+') ? 'ASC' : 'DESC';
+
+ $usersStmt = DBA::p("SELECT `user`.*, `contact`.`name`, `contact`.`url`, `contact`.`micro`, `user`.`account_expired`, `contact`.`last-item` AS `lastitem_date`, `contact`.`nick`
+ FROM `user`
+ INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`
+ WHERE `user`.`verified`
+ ORDER BY $sql_order $sql_order_direction LIMIT ?, ?", $start, $count
+ );
+
+ return DBA::toArray($usersStmt);
+ }
}
$pager = new Pager(DI::l10n(), DI::args()->getQueryString(), 100);
- // @TODO Move below block to Model\User::getUsers($start, $count, $order = 'contact.name', $order_direction = '+')
$valid_orders = [
'contact.name',
'user.email',
$order = $new_order;
}
}
- $sql_order = '`' . str_replace('.', '`.`', $order) . '`';
- $sql_order_direction = ($order_direction === '+') ? 'ASC' : 'DESC';
-
- $usersStmt = DBA::p("SELECT `user`.*, `contact`.`name`, `contact`.`url`, `contact`.`micro`, `user`.`account_expired`, `contact`.`last-item` AS `lastitem_date`
- FROM `user`
- INNER JOIN `contact` ON `contact`.`uid` = `user`.`uid` AND `contact`.`self`
- WHERE `user`.`verified`
- ORDER BY $sql_order $sql_order_direction LIMIT ?, ?", $pager->getStart(), $pager->getItemsPerPage()
- );
- $users = DBA::toArray($usersStmt);
+
+ $users = User::getUsers($pager->getStart(), $pager->getItemsPerPage(), $order, $order_direction);
$adminlist = explode(',', str_replace(' ', '', DI::config()->get('config', 'admin_email')));
$_setup_users = function ($e) use ($adminlist) {