-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTopics.php
59 lines (51 loc) · 1.6 KB
/
Topics.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php
namespace App\controllers;
use Minz\Request;
use Minz\Response;
use App\models;
use App\utils;
/**
* @author Marien Fressinaud <[email protected]>
* @license http://www.gnu.org/licenses/agpl-3.0.en.html AGPL
*/
class Topics
{
/**
* Show the discovery page
*
* @request_param string id
* @request_param integer page
*
* @response 302 /topic/:id?page=:bounded_page if :page is invalid
* @response 404 if the topic is missing
* @response 200
*/
public function show(Request $request): Response
{
$id = $request->param('id', '');
$pagination_page = $request->paramInteger('page', 1);
$topic = models\Topic::find($id);
if (!$topic) {
return Response::notFound('not_found.phtml');
}
$number_collections = $topic->countPublicCollections();
$pagination = new utils\Pagination($number_collections, 30, $pagination_page);
if ($pagination_page !== $pagination->currentPage()) {
return Response::redirect('topic', [
'id' => $topic->id,
'page' => $pagination->currentPage(),
]);
}
$collections = models\Collection::listPublicByTopicIdWithNumberLinks(
$topic->id,
$pagination->currentOffset(),
$pagination->numberPerPage()
);
$collections = utils\Sorter::localeSort($collections, 'name');
return Response::ok('topics/show.phtml', [
'topic' => $topic,
'collections' => $collections,
'pagination' => $pagination,
]);
}
}