CSY2028-assignment-2/jobs/Routes.php

33 lines
1.0 KiB
PHP
Raw Normal View History

2023-01-21 23:12:42 +00:00
<?php
namespace jobs;
class Routes implements \CSY2028\Routes {
public function getController($name) {
$catsTable = new \CSY2028\DatabaseTable('category', 'id', '\jobs\Entity\Category');
2023-01-23 16:08:51 +00:00
$jobsTable = new \CSY2028\DatabaseTable('job', 'id', '\jobs\Entity\Job', [$catsTable]);
$appsTable = new \CSY2028\DatabaseTable('applicants', 'id', '\jobs\Entity\Applicant', [$jobsTable]);
2023-01-21 23:12:42 +00:00
$controllers = [];
//TODO: Add Controllers
2023-01-23 16:08:51 +00:00
$controllers['jobs'] = new \jobs\controllers\Jobs($jobsTable, $catsTable);
2023-01-21 23:12:42 +00:00
return $controllers[$name];
}
public function getDefaultRoute() {
return 'jobs/home';
2023-01-21 23:12:42 +00:00
}
public function checkLogin($route) {
\session_start();
$loginRoutes = [];
//TODO: Add login routes
//$loginRoutes['job/edit'] = true;
$requiresLogin = $loginRoutes[$route] ?? false;
if ($requiresLogin && !\isset($_SESSION['loggedin'])) {
\header('location: /user/login');
exit();
}
}
}