diff --git a/config.ini b/config.ini index efbb6baf..1c5ba094 100644 --- a/config.ini +++ b/config.ini @@ -10,6 +10,7 @@ mediaPath=./public_html/media/ title=szurubooru [browsing] +usersPerPage=8 postsPerPage=20 thumbWidth=140 thumbHeight=140 diff --git a/lib/chibi-core b/lib/chibi-core index 89897319..5a936768 160000 --- a/lib/chibi-core +++ b/lib/chibi-core @@ -1 +1 @@ -Subproject commit 898973195c1c6db2905cf2a52c80b0a8ba142058 +Subproject commit 5a936768ee7baeff89c192b7d35f6e8c692ee08f diff --git a/public_html/media/css/user-list.css b/public_html/media/css/user-list.css new file mode 100644 index 00000000..832587aa --- /dev/null +++ b/public_html/media/css/user-list.css @@ -0,0 +1,31 @@ +img { + float: left; + margin-right: 0.5em; +} +h1 { + margin-top: 0; + margin-bottom: 0.25em; +} + +.user { + line-height: 1.5em; + margin-bottom: 1em; + width: 25em; + display: inline-block; +} + +nav.sort-styles ul { + list-style-type: none; + margin: 0 0 1em 0; + text-align: center; + padding: 0; +} +nav.sort-styles li { + display: inline-block; + font-size: 105%; + margin: 0 1em; + padding-bottom: 0.2em; +} +nav.sort-styles li.active { + border-bottom: 3px solid firebrick; +} diff --git a/src/Controllers/PostController.php b/src/Controllers/PostController.php index 6791f0c8..c98ceb67 100644 --- a/src/Controllers/PostController.php +++ b/src/Controllers/PostController.php @@ -143,9 +143,11 @@ class PostController $searchDbQuery->offset('?')->put(($page - 1) * $postsPerPage); $posts = $searchDbQuery->get(); - $this->context->transport->page = $page; - $this->context->transport->postCount = $postCount; - $this->context->transport->pageCount = $pageCount; + $this->context->transport->paginator = new StdClass; + $this->context->transport->paginator->page = $page; + $this->context->transport->paginator->pageCount = $pageCount; + $this->context->transport->paginator->entityCount = $postCount; + $this->context->transport->paginator->entities = $posts; $this->context->transport->posts = $posts; } diff --git a/src/Controllers/UserController.php b/src/Controllers/UserController.php index f5986666..09972eb4 100644 --- a/src/Controllers/UserController.php +++ b/src/Controllers/UserController.php @@ -13,11 +13,78 @@ class UserController /** * @route /users + * @route /users/{page} + * @route /users/{sortStyle} + * @route /users/{sortStyle}/{page} + * @validate sortStyle alpha|alpha,asc|alpha,desc|date,asc|date,desc|pending + * @validate page [0-9]+ */ - public function listAction() + public function listAction($sortStyle, $page) { - $this->context->subTitle = 'users'; - throw new SimpleException('Not implemented'); + $this->context->stylesheets []= 'user-list.css'; + $this->context->stylesheets []= 'paginator.css'; + if ($this->config->browsing->endlessScrolling) + $this->context->scripts []= 'paginator-endless.js'; + + $page = intval($page); + $usersPerPage = intval($this->config->browsing->usersPerPage); + $this->context->subTitle = 'browsing users'; + PrivilegesHelper::confirmWithException($this->context->user, Privilege::ListUsers); + + if ($sortStyle == '' or $sortStyle == 'alpha') + $sortStyle = 'alpha,asc'; + if ($sortStyle == 'date') + $sortStyle = 'date,asc'; + + $buildDbQuery = function($dbQuery, $sortStyle) + { + $dbQuery->from('user'); + + switch ($sortStyle) + { + case 'alpha,asc': + $dbQuery->orderBy('name')->asc(); + break; + case 'alpha,desc': + $dbQuery->orderBy('name')->desc(); + break; + case 'date,asc': + $dbQuery->orderBy('join_date')->asc(); + break; + case 'date,desc': + $dbQuery->orderBy('join_date')->desc(); + break; + case 'pending': + $dbQuery->whereNot('staff_confirmed')->and($this->config->registration->staffActivation); + break; + default: + throw new SimpleException('Unknown sort style'); + } + }; + + $countDbQuery = R::$f->begin(); + $countDbQuery->select('COUNT(1)')->as('count'); + $buildDbQuery($countDbQuery, $sortStyle); + $userCount = intval($countDbQuery->get('row')['count']); + $pageCount = ceil($userCount / $usersPerPage); + $page = max(1, min($pageCount, $page)); + + $searchDbQuery = R::$f->begin(); + $searchDbQuery->select('user.*'); + $buildDbQuery($searchDbQuery, $sortStyle); + $searchDbQuery->limit('?')->put($usersPerPage); + $searchDbQuery->offset('?')->put(($page - 1) * $usersPerPage); + + $users = $searchDbQuery->get(); + $users = R::convertToBeans('user', $users); + $this->context->sortStyle = $sortStyle; + $this->context->transport->paginator = new StdClass; + $this->context->transport->paginator->page = $page; + $this->context->transport->paginator->pageCount = $pageCount; + $this->context->transport->paginator->entityCount = $userCount; + $this->context->transport->paginator->entities = $users; + $this->context->transport->paginator->params = func_get_args(); + $this->context->transport->users = $users; } @@ -275,9 +342,11 @@ class UserController $posts = $searchDbQuery->get(); $this->context->transport->user = $user; $this->context->transport->tab = $tab; - $this->context->transport->page = $page; - $this->context->transport->postCount = $postCount; - $this->context->transport->pageCount = $pageCount; + $this->context->transport->paginator = new StdClass; + $this->context->transport->paginator->page = $page; + $this->context->transport->paginator->pageCount = $pageCount; + $this->context->transport->paginator->entityCount = $postCount; + $this->context->transport->paginator->entities = $posts; $this->context->transport->posts = $posts; } diff --git a/src/Views/paginator.phtml b/src/Views/paginator.phtml new file mode 100644 index 00000000..ad35bae3 --- /dev/null +++ b/src/Views/paginator.phtml @@ -0,0 +1,63 @@ +context->transport->paginator->pageCount; + $delta = 3; + $pagesVisible = array_merge($pagesVisible, range($this->context->transport->paginator->page - $delta, $this->context->transport->paginator->page + $delta)); + $pagesVisible = array_filter($pagesVisible, function($x) { return $x >= 1 and $x <= $this->context->transport->paginator->pageCount; }); + $pagesVisible = array_unique($pagesVisible); + sort($pagesVisible, SORT_NUMERIC); + + if (!function_exists('pageUrl')) + { + function pageUrl($page) + { + $context = \Chibi\Registry::getContext(); + $controller = $context->route->simpleControllerName; + $action = $context->route->simpleActionName; + $page = max(1, $page); + $page = min($context->transport->paginator->pageCount, $page); + $params = $context->route->arguments; + $params['page'] = $page; + return \Chibi\UrlHelper::route($controller, $action, $params); + } + } +?> + + + + diff --git a/src/Views/post-list.phtml b/src/Views/post-list.phtml index 8f5a1fa2..279d4eff 100644 --- a/src/Views/post-list.phtml +++ b/src/Views/post-list.phtml @@ -8,74 +8,8 @@ - - -route->simpleControllerName; - $action = $context->route->simpleActionName; - $page = max(1, $page); - $page = min($context->transport->pageCount, $page); - $params = []; - $params['page'] = $page; - if ($context->transport->searchQuery != '') - { - $params['query'] = $context->transport->searchQuery; - } - return \Chibi\UrlHelper::route($controller, $action, $params); - } -} -?> - -context->transport->pageCount; - $delta = 3; - $pagesVisible = array_merge($pagesVisible, range($this->context->transport->page - $delta, $this->context->transport->page + $delta)); - $pagesVisible = array_filter($pagesVisible, function($x) { return $x >= 1 and $x <= $this->context->transport->pageCount; }); - $pagesVisible = array_unique($pagesVisible); - sort($pagesVisible, SORT_NUMERIC); -?> - - - + + renderFile('paginator'); + ?> diff --git a/src/Views/user-list.phtml b/src/Views/user-list.phtml new file mode 100644 index 00000000..8a5d7603 --- /dev/null +++ b/src/Views/user-list.phtml @@ -0,0 +1,53 @@ + + +context->transport->users)): ?> +

No users to show.

+ +
+ context->transport->users as $user): ?> +
+ + <?php echo $user->name ?> + +
+

+ + name ?> + +

+ +
Date registered: join_date) ?>
+
Favorite count: countOwn('favoritee') ?>
+
Post count: alias('uploader')->countOwn('post') ?>
+
+
+ +
+ + renderFile('paginator') ?> + diff --git a/src/Views/user-view.phtml b/src/Views/user-view.phtml index 1b76320c..045cd30c 100644 --- a/src/Views/user-view.phtml +++ b/src/Views/user-view.phtml @@ -142,23 +142,7 @@ context->transport->posts)): ?> - route->simpleControllerName; - $action = $context->route->simpleActionName; - $page = max(1, $page); - $page = min($context->transport->pageCount, $page); - $params = []; - $params['page'] = $page; - $params['tab'] = $context->transport->tab; - $params['name'] = $context->transport->user->name; - return \Chibi\UrlHelper::route($controller, $action, $params); - } - $this->renderFile('post-list') - ?> + renderFile('post-list') ?> context->transport->tab == 'edit'): ?>