1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* View districts page controller class file |
4
|
|
|
* |
5
|
|
|
* @package EBloodBank |
6
|
|
|
* @subpackage Controllers |
7
|
|
|
* @since 1.0 |
8
|
|
|
*/ |
9
|
|
|
namespace EBloodBank\Controllers; |
10
|
|
|
|
11
|
|
|
use EBloodBank as EBB; |
12
|
|
|
use EBloodBank\Options; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* View districts page controller class |
16
|
|
|
* |
17
|
|
|
* @since 1.0 |
18
|
|
|
*/ |
19
|
|
|
class ViewDistricts extends Controller |
20
|
|
|
{ |
21
|
|
|
/** |
22
|
|
|
* @return void |
23
|
|
|
* @since 1.0 |
24
|
|
|
*/ |
25
|
|
|
public function __invoke() |
26
|
|
|
{ |
27
|
|
|
$isSitePublic = ('on' === EBB\Options::getOption('site_publication')); |
28
|
|
|
if (! $isSitePublic && (! $this->hasAuthenticatedUser() || ! $this->getAcl()->isUserAllowed($this->getAuthenticatedUser(), 'District', 'read'))) { |
29
|
|
|
$this->viewFactory->displayView('error-403'); |
30
|
|
|
} else { |
31
|
|
|
$this->viewFactory->displayView('view-districts', [ |
32
|
|
|
'districts' => $this->getQueriedDistricts(), |
33
|
|
|
'pagination.total' => $this->getPagesTotal(), |
34
|
|
|
'pagination.current' => $this->getCurrentPage(), |
35
|
|
|
]); |
36
|
|
|
} |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @return int |
41
|
|
|
* @since 1.0 |
42
|
|
|
*/ |
43
|
|
|
public function getPagesTotal() |
44
|
|
|
{ |
45
|
|
|
$total = 1; |
46
|
|
|
$limit = (int) Options::getOption('entities_per_page'); |
47
|
|
|
if ($limit >= 1) { |
48
|
|
|
$total = (int) ceil($this->countAllDistricts() / $limit); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
return $total; |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @return int |
56
|
|
|
* @since 1.0 |
57
|
|
|
*/ |
58
|
|
|
public function getCurrentPage() |
59
|
|
|
{ |
60
|
|
|
return max((int) filter_input(INPUT_GET, 'page'), 1); |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
/** |
64
|
|
|
* @return \EBloodBank\Models\District[] |
65
|
|
|
* @since 1.0 |
66
|
|
|
*/ |
67
|
|
|
public function getAllDistricts() |
68
|
|
|
{ |
69
|
|
|
return $this->getDistrictRepository()->findAll([], ['created_at' => 'DESC']); |
|
|
|
|
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @return int |
74
|
|
|
* @since 1.0 |
75
|
|
|
*/ |
76
|
|
|
public function countAllDistricts() |
77
|
|
|
{ |
78
|
|
|
return $this->getDistrictRepository()->countAll(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* @return \EBloodBank\Models\District[] |
83
|
|
|
* @since 1.0 |
84
|
|
|
*/ |
85
|
|
|
public function getQueriedDistricts() |
86
|
|
|
{ |
87
|
|
|
$limit = (int) Options::getOption('entities_per_page'); |
88
|
|
|
$offset = ($this->getCurrentPage() - 1) * $limit; |
89
|
|
|
|
90
|
|
|
return $this->getDistrictRepository()->findBy([], ['created_at' => 'DESC'], $limit, $offset); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @return int |
95
|
|
|
* @since 1.0 |
96
|
|
|
*/ |
97
|
|
|
public function countQueriedDistricts() |
98
|
|
|
{ |
99
|
|
|
return count($this->getQueriedDistricts()); |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
|
This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.
If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.