updated framework
This commit is contained in:
parent
2bbb598b5c
commit
9607c6be3c
|
|
@ -1,8 +1,53 @@
|
||||||
<?php
|
<?php
|
||||||
namespace CSY2028;
|
namespace CSY2028;
|
||||||
interface Routes {
|
class Routes {
|
||||||
public function getController($controllerName, $functionName);
|
protected $databaseTables;
|
||||||
public function getDefaultRoute();
|
protected $controllers;
|
||||||
public function checkLogin($route);
|
protected $loginControllers;
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
$this->databaseTables = [];
|
||||||
|
$this->controllers = [];
|
||||||
|
$this->loginControllers = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getController($controllerName, $functionName) {
|
||||||
|
|
||||||
|
$this->checkLogin($controllerName);
|
||||||
|
|
||||||
|
if (array_key_exists($controllerName, $this->controllers)) {
|
||||||
|
if (\method_exists($this->controllers[$controllerName], $functionName)) {
|
||||||
|
return $this->controllers[$controllerName];
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDefaultRoute() {
|
||||||
|
return 'controller/home';
|
||||||
|
}
|
||||||
|
|
||||||
|
public function checkLogin($name) {
|
||||||
|
$requiresLogin = $this->loginControllers[$name] ?? false;
|
||||||
|
|
||||||
|
if ($requiresLogin && !isset($_SESSION['loggedin'])) {
|
||||||
|
header('location: /user/login');
|
||||||
|
exit();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public function notFound() {
|
||||||
|
return ['template' => 'response.html.php',
|
||||||
|
'title' => '404 Not Found',
|
||||||
|
'vars' => ['response' => '404 Page Not Found']
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
@ -1,64 +1,29 @@
|
||||||
<?php
|
<?php
|
||||||
namespace jobs;
|
namespace jobs;
|
||||||
class Routes implements \CSY2028\Routes {
|
class Routes extends \CSY2028\Routes {
|
||||||
|
|
||||||
public function getController($controllerName, $functionName) {
|
|
||||||
$catsTable = new \jobs\JobDatabaseTable('category', 'id', '\jobs\Entity\Category');
|
|
||||||
$jobsTable = new \jobs\JobDatabaseTable('job', 'id', '\jobs\Entity\Job', [$catsTable]);
|
|
||||||
$appsTable = new \jobs\JobDatabaseTable('applicants', 'id', '\jobs\Entity\Applicant', [$jobsTable]);
|
|
||||||
$usersTable = new \jobs\JobDatabaseTable('users', 'id', '\jobs\Entity\User');
|
|
||||||
|
|
||||||
$controllers = [];
|
|
||||||
$controllers['jobs'] = new \jobs\controllers\Jobs($jobsTable, $catsTable, $appsTable);
|
|
||||||
$controllers['portal'] = new \jobs\controllers\Portal($catsTable, $jobsTable, $appsTable);
|
|
||||||
$controllers['user'] = new \jobs\controllers\User($usersTable, $catsTable);
|
|
||||||
|
|
||||||
$this->checkLogin($controllerName);
|
|
||||||
|
|
||||||
if (array_key_exists($controllerName, $controllers)) {
|
|
||||||
if (\method_exists($controllers[$controllerName], $functionName)) {
|
|
||||||
return $controllers[$controllerName];
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
setDbTables();
|
||||||
|
$this->controllers = [
|
||||||
|
"jobs" => new \jobs\controllers\Jobs($this->databaseTables["jobs"], $this->databaseTables["categories"], $this->databaseTables["applicants"]),
|
||||||
|
"portal" => new \jobs\controllers\Portal($this->databaseTables["categories"], $this->databaseTables["jobs"], $this->databaseTables["applicants"]),
|
||||||
|
"user" => new \jobs\controllers\User($this->databaseTables["users"], $this->databaseTables["categories"])
|
||||||
|
];
|
||||||
|
$this->loginControllers = [
|
||||||
|
"portal" => true
|
||||||
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getDefaultRoute() {
|
public function getDefaultRoute() {
|
||||||
return 'jobs/home';
|
return 'jobs/home';
|
||||||
}
|
}
|
||||||
|
|
||||||
public function checkLogin($name) {
|
private function setDbTables() {
|
||||||
$loginRoutes = [];
|
$this->databaseTables = [];
|
||||||
$loginRoutes['portal'] = true;
|
$this->databaseTables["categories"] = new \jobs\JobDatabaseTable('category', 'id', '\jobs\Entity\Category');
|
||||||
$requiresLogin = $loginRoutes[$name] ?? false;
|
$this->databaseTables["jobs"] = new \jobs\JobDatabaseTable('job', 'id', '\jobs\Entity\Job', [$this->databaseTables["categories"]]);
|
||||||
|
$this->databaseTables["applicants"] = new \jobs\JobDatabaseTable('applicants', 'id', '\jobs\Entity\Applicant', [$this->databaseTables["jobs"]]);
|
||||||
if ($requiresLogin && !isset($_SESSION['loggedin'])) {
|
$this->databaseTables["users"] = new \jobs\JobDatabaseTable('users', 'id', '\jobs\Entity\User');
|
||||||
header('location: /user/login');
|
|
||||||
exit();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public function notFound() {
|
|
||||||
$cats = new \jobs\JobDatabaseTable('category', 'id', '\jobs\Entity\Category');
|
|
||||||
return ['template' => 'response.html.php',
|
|
||||||
'title' => 'Jo\'s Jobs- 404 Not Found',
|
|
||||||
'vars' => ['cats' => $cats->findAll(),
|
|
||||||
'response' => '404 Page Not Found']
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
public function nav() {
|
|
||||||
$cats = new \jobs\JobDatabaseTable('category', 'id', '\jobs\Entity\Category');
|
|
||||||
return ['template' => 'nav.html.php',
|
|
||||||
'vars' => ['cats' => $cats->findAll()]
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
Loading…
Reference in New Issue