FlagsReviewComposer.php
2.03 KB
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<?php
namespace FootyRoom\Http\ViewComposers;
use FootyRoom\User\User;
use FootyRoom\Queries\Comment\FlagsReportQuery;
use FootyRoom\Support\Pagination\Paginator;
use Illuminate\Contracts\View\View;
class FlagsReviewComposer
{
/**
* @var int
*/
const ITEMS_PER_PAGE = 1;
/**
* @var \FootyRoom\Queries\Comment\FlagsReportQuery
*/
protected $flagsReportsQuery;
/**
* Constructor.
*
* @param \FootyRoom\Queries\Comment\FlagsReportQuery $flagsReportsQuery
*/
public function __construct(FlagsReportQuery $flagsReportsQuery)
{
$this->flagsReportsQuery = $flagsReportsQuery;
}
/**
* Compose the view.
*
* @param \Illuminate\Contracts\View\View $view
* @param \FootyRoom\User\User $user
* @param int $page
*
* @return \Illuminate\Contracts\View\View
*/
public function compose(View $view, User $user, $page = 1)
{
$this->loadFlagsReports($view, $user, $page);
$reportsCount = $this->getPostsCount($this->getPostsCount());
if (!count($view->flagsReports) && $page > 1) {
$this->loadFlagsReports($view, $user, $page = 1);
}
$view->pagination = (new Paginator(
$reportsCount,
self::ITEMS_PER_PAGE,
$page
))
->setPath(route('flagsReview'));
return $view;
}
/**
* Returns flags reports count.
*
* @return int
*/
protected function getPostsCount()
{
return $this->flagsReportsQuery->count();
}
/**
* Loads flags reports.
*
* @param \Illuminate\Contracts\View\View $view
* @param \FootyRoom\User\User $user The user
* @param int $page
*/
protected function loadFlagsReports(View $view, User $user, $page)
{
$flagsReports = $this->flagsReportsQuery->find(
$user->getRole(),
self::ITEMS_PER_PAGE,
self::ITEMS_PER_PAGE * ($page - 1)
);
$view->with('flagsReports', $flagsReports);
}
}