CSY2028-assignment-2/jobs/controllers/Jobs.php

50 lines
1.4 KiB
PHP
Raw Normal View History

2023-01-21 23:12:42 +00:00
<?php
namespace jobs\controllers;
2023-01-23 14:38:15 +00:00
class Jobs {
2023-01-23 16:08:51 +00:00
private $jobsTable;
private $catsTable;
2023-01-23 16:44:56 +00:00
private $vars = [];
2023-01-21 23:12:42 +00:00
2023-01-23 16:08:51 +00:00
public function __construct(\CSY2028\DatabaseTable $jobsTable, \CSY2028\DatabaseTable $catsTable) {
$this->jobsTable = $jobsTable;
$this->catsTable = $catsTable;
2023-01-23 16:44:56 +00:00
$this->vars['cats'] = $this->catsTable->findAll();
2023-01-21 23:12:42 +00:00
}
public function home() {
return ['template' => 'home.html.php',
'title' => 'Jo\'s Jobs- Home',
2023-01-23 16:44:56 +00:00
'vars' => $this->vars
2023-01-23 16:08:51 +00:00
];
}
public function category() {
$cat = $this->catsTable->find('name', $_GET['page']);
if ($cat == null) {
return $this->notFound();
}
else {
2023-01-23 16:44:56 +00:00
$this->vars['jobs'] = $this->jobsTable->find('categoryId', $cat[0]->id);
$this->vars['heading'] = $cat[0]->name;
2023-01-23 16:08:51 +00:00
return ['template' => 'category.html.php',
'title' => 'Jo\'s Jobs- '. $_GET['page'],
2023-01-23 16:44:56 +00:00
'vars' => $this->vars
];
2023-01-23 16:08:51 +00:00
}
}
2023-01-23 16:44:56 +00:00
public function about() {
return ['template' => 'about.html.php',
'title' => 'Jo\'s Jobs- About us',
'vars' => $this->vars
];
}
2023-01-23 16:08:51 +00:00
public function notFound() {
return ['template' => 'notFound.html.php',
'title' => 'Jo\'s Jobs- 404 Not Found',
2023-01-23 16:44:56 +00:00
'vars' => $this->vars
];
2023-01-21 23:12:42 +00:00
}
}
?>