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

100 lines
3.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-23 17:50:11 +00:00
private $appsTable;
2023-01-23 16:44:56 +00:00
private $vars = [];
2023-01-21 23:12:42 +00:00
2023-01-25 17:44:11 +00:00
public function __construct(\jobs\JobDatabaseTable $jobsTable, \jobs\JobDatabaseTable $catsTable, \jobs\JobDatabaseTable $appsTable) {
2023-01-23 16:08:51 +00:00
$this->jobsTable = $jobsTable;
$this->catsTable = $catsTable;
2023-01-23 17:50:11 +00:00
$this->appsTable = $appsTable;
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-25 16:33:08 +00:00
if (isset($_GET['filter'])) {
$this->vars['jobs'] = $this->jobsTable->find('categoryId', $cat[0]->id, "location", $_GET['filter']);
}
else {
$this->vars['jobs'] = $this->jobsTable->find('categoryId', $cat[0]->id);
}
2023-01-23 16:44:56 +00:00
$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 17:50:11 +00:00
2023-01-23 16:08:51 +00:00
public function notFound() {
2023-01-23 17:50:11 +00:00
$this->vars['response'] = 'The page you have requested has not been found';
return ['template' => 'response.html.php',
2023-01-23 16:08:51 +00:00
'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
}
2023-01-23 17:50:11 +00:00
public function apply() {
$this->vars['job'] = $this->jobsTable->find('id', $_GET['id'])[0];
return ['template' => 'apply.html.php',
'title' => 'Jo\'s Jobs- Apply',
'vars' => $this->vars];
}
public function applySubmit() {
if ($_FILES['cv']['error'] == 0) {
$parts = explode('.', $_FILES['cv']['name']);
$extension = end($parts);
$fileName = uniqid() . '.' . $extension;
move_uploaded_file($_FILES['cv']['tmp_name'], 'cvs/' . $fileName);
$record = [
'name' => $_POST['name'],
'email' => $_POST['email'],
'details' => $_POST['details'],
'jobId' => $_POST['jobId'],
'cv' => $fileName
];
$this->appsTable->save($record);
$this->vars['response'] = 'Your application is complete. We will contact you after the closing date.';
}
else {
$this->vars['response'] = 'There was an error uploading your CV';
}
return ['template' => 'response.html.php',
'title' => 'Jo\'s Jobs- Apply',
'vars' => $this->vars];
}
2023-01-23 19:07:28 +00:00
public function faq() {
return ['template' => 'construction.html.php',
'title' => 'Jo\'s Jobs- FAQ',
'vars' => $this->vars];
}
2023-01-21 23:12:42 +00:00
}
?>