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

41 lines
1.2 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-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-21 23:12:42 +00:00
}
public function home() {
return ['template' => 'home.html.php',
'title' => 'Jo\'s Jobs- Home',
2023-01-23 16:08:51 +00:00
'vars' => ['cats' => $this->catsTable->findAll()]
];
}
public function category() {
$cat = $this->catsTable->find('name', $_GET['page']);
if ($cat == null) {
return $this->notFound();
}
else {
return ['template' => 'category.html.php',
'title' => 'Jo\'s Jobs- '. $_GET['page'],
'vars' => ['jobs' => $this->jobsTable->find('categoryId', $cat[0]->id),
'cats' => $this->catsTable->findAll(),
'heading' => $cat[0]->name]
];
}
}
public function notFound() {
return ['template' => 'notFound.html.php',
'title' => 'Jo\'s Jobs- 404 Not Found',
2023-01-21 23:12:42 +00:00
'vars' => []
];
}
}
?>