-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathBaseController.php
More file actions
103 lines (91 loc) · 2.69 KB
/
BaseController.php
File metadata and controls
103 lines (91 loc) · 2.69 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<?php
abstract class BaseController{
protected $action;
protected $urlData;
function __construct($action, $urlData){
$this->action = $action;
$this->urlData = $urlData;
}
/**
* Execute the given action
*/
public function executeAction(){
return $this->{$this->action}();
}
protected function getView($data){
$viewloc = 'application/views/' . get_class($this) . '/' . $this->action . '.php';
ob_start();
require("application/views/_template/header.php");
require($viewloc);
$paginationView = $this->getPaginationView();
require("application/views/_template/footer.php");
$view = ob_get_contents();
ob_end_clean();
return $view;
}
protected function getPage(){
$pageNo = 1;
if(isset($this->urlData['pageNo']) && $this->urlData['pageNo'] > 0){
$pageNo = $this->urlData['pageNo'];
}
return $pageNo;
}
protected function getErrorPage($errorDetails){
ob_start();
require("application/views/_template/header.php");
require('application/views/_template/errorPage.php');
require("application/views/_template/footer.php");
$view = ob_get_contents();
ob_end_clean();
return $view;
}
protected function getSortingColumn(){
$sortingColumn = null;
if(!empty($this->urlData['sortBy'])){
$sortingColumn = $this->urlData['sortBy'];
}
return $sortingColumn;
}
protected function generatePaginationView($currentPage, $totalPages){
$display = "<center><ul class='pagination'>";
if($currentPage == 1){
$display .= "<li class='active'><a href='#' onClick='choosePage(1)'>1</a></li>";
}
else{
$display .= "<li><a href='#' onClick='choosePage(1)'>1</a></li>";
if($currentPage == 2){
$display .= "<li class='active'><a href='#' onClick='choosePage(2)'>2</a></li>";
}else{
$display .= "<li><a href='#' onClick='openPageSelector()'>...</a></li>";
$display .= "<li class='active'><a href='#' onClick='choosePage($currentPage)'>$currentPage</a></li>";
}
}
if($currentPage + 1 < $totalPages){
$display .= "<li><a href='#' onClick='openPageSelector()'>...</a></li>";
}
if($currentPage != $totalPages){
$display .= "<li><a href='#' onClick='choosePage($totalPages)'>$totalPages</a></li>";
}
$display .= "</ul></center>";
return $display;
}
/**
* Should be override if there is a pagination system
*/
public function getPaginationView(){
return null;
}
protected function isAdmin(){
return isset($_SESSION['username']);
}
protected function isSU(){
return $this->isAdmin() && $_SESSION['status'] == "superuser";
}
protected function getUsername(){
return ($this->isAdmin()) ? $_SESSION['username'] : "non-auth-user";
}
/**
* Display index page of the Controller
*/
protected abstract function index();
}