fixed error with DatabaseTable
This commit is contained in:
parent
2f280f6f46
commit
e5a3069ebd
|
|
@ -25,27 +25,33 @@ class DatabaseTable {
|
||||||
$keys = \array_keys($record);
|
$keys = \array_keys($record);
|
||||||
$columns = \implode(', ', $keys);
|
$columns = \implode(', ', $keys);
|
||||||
$values = \implode(', :', $keys);
|
$values = \implode(', :', $keys);
|
||||||
startDB()->prepare('INSERT INTO '. $this->table . ' (' . $columns . ') VALUES (:' . $values . ')')->execute($record);
|
$this->startDB()->prepare('INSERT INTO '. $this->table . ' (' . $columns . ') VALUES (:' . $values . ')')->execute($record);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function update($record) {
|
private function update($record) {
|
||||||
$params = [];
|
$params = [];
|
||||||
foreach ($record as $key => $value) {
|
foreach ($record as $key => $value) {
|
||||||
$params[] = $key . ' = :' .$key;
|
$params[] = $key . ' = :' .$key;
|
||||||
}
|
}
|
||||||
$record['primaryKey'] = $record[$this->pk];
|
$record['primaryKey'] = $record[$this->pk];
|
||||||
startDB()->prepare('UPDATE '. $this->table .' SET '. \implode(', ', $params) .' WHERE '. $this->pk .' = :primaryKey')->execute($record);
|
$this->startDB()->prepare('UPDATE '. $this->table .' SET '. \implode(', ', $params) .' WHERE '. $this->pk .' = :primaryKey')->execute($record);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function find($column, $value) {
|
public function find($column, $value) {
|
||||||
$values = [
|
$values = [
|
||||||
'value' => $value
|
'value' => $value
|
||||||
];
|
];
|
||||||
return startDB()->prepare('SELECT * FROM '. $this->table . ' WHERE '. $field . ' = :value')->setFetchMode(\PDO::FETCH_CLASS, $this->entityClass, $this->entityConstructor)->execute($values)->fetchAll();
|
$stmt = $this->startDB()->prepare('SELECT * FROM '. $this->table . ' WHERE '. $column . ' = :value');
|
||||||
|
$stmt->setFetchMode(\PDO::FETCH_CLASS, $this->entityClass, $this->entityConstructor);
|
||||||
|
$stmt->execute($values);
|
||||||
|
return $stmt->fetchAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function findAll() {
|
public function findAll() {
|
||||||
return startDB()->prepare('SELECT * FROM ' . $this->table)->execute()->fetchAll();
|
$stmt = $this->startDB()->prepare('SELECT * FROM ' . $this->table);
|
||||||
|
$stmt->setFetchMode(\PDO::FETCH_CLASS, $this->entityClass, $this->entityConstructor);
|
||||||
|
$stmt->execute();
|
||||||
|
return $stmt->fetchAll();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function delete($column, $value) {
|
public function delete($column, $value) {
|
||||||
|
|
|
||||||
|
|
@ -3,12 +3,12 @@ namespace jobs;
|
||||||
class Routes implements \CSY2028\Routes {
|
class Routes implements \CSY2028\Routes {
|
||||||
public function getController($name) {
|
public function getController($name) {
|
||||||
$catsTable = new \CSY2028\DatabaseTable('category', 'id', '\jobs\Entity\Category');
|
$catsTable = new \CSY2028\DatabaseTable('category', 'id', '\jobs\Entity\Category');
|
||||||
$jobsTable = new \CSY2028\DatabaseTable('jobs', 'id', '\jobs\Entity\Job', [$catsTable]);
|
$jobsTable = new \CSY2028\DatabaseTable('job', 'id', '\jobs\Entity\Job', [$catsTable]);
|
||||||
$appsTable = new \CSY2028\DatabaseTable('applicants', 'id', '\jobs\Entity\Applicant', [$jobsTable]);
|
$appsTable = new \CSY2028\DatabaseTable('applicants', 'id', '\jobs\Entity\Applicant', [$jobsTable]);
|
||||||
|
|
||||||
$controllers = [];
|
$controllers = [];
|
||||||
//TODO: Add Controllers
|
//TODO: Add Controllers
|
||||||
$controllers['jobs'] = new \jobs\controllers\Jobs($jobsTable);
|
$controllers['jobs'] = new \jobs\controllers\Jobs($jobsTable, $catsTable);
|
||||||
|
|
||||||
return $controllers[$name];
|
return $controllers[$name];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,15 +1,39 @@
|
||||||
<?php
|
<?php
|
||||||
namespace jobs\controllers;
|
namespace jobs\controllers;
|
||||||
class Jobs {
|
class Jobs {
|
||||||
private $jobTable;
|
private $jobsTable;
|
||||||
|
private $catsTable;
|
||||||
|
|
||||||
public function __construct(\CSY2028\DatabaseTable $jobTable) {
|
public function __construct(\CSY2028\DatabaseTable $jobsTable, \CSY2028\DatabaseTable $catsTable) {
|
||||||
$this->jobTable = $jobTable;
|
$this->jobsTable = $jobsTable;
|
||||||
|
$this->catsTable = $catsTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function home() {
|
public function home() {
|
||||||
return ['template' => 'home.html.php',
|
return ['template' => 'home.html.php',
|
||||||
'title' => 'Jo\'s Jobs- Home',
|
'title' => 'Jo\'s Jobs- Home',
|
||||||
|
'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',
|
||||||
'vars' => []
|
'vars' => []
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,19 +35,7 @@
|
||||||
<img src="images/randombanner.php"/>
|
<img src="images/randombanner.php"/>
|
||||||
<main class="sidebar">
|
<main class="sidebar">
|
||||||
|
|
||||||
<section class="left">
|
|
||||||
<ul>
|
|
||||||
<li><a href="it.php">IT</a></li>
|
|
||||||
<li><a href="hr.php">Human Resources</a></li>
|
|
||||||
<li class="current"><a href="sales.php">Sales</a></li>
|
|
||||||
</ul>
|
|
||||||
</section>
|
|
||||||
|
|
||||||
<section class="right">
|
|
||||||
|
|
||||||
<h1>Sales Jobs</h1>
|
|
||||||
|
|
||||||
<ul class="listing">
|
|
||||||
|
|
||||||
|
|
||||||
<?php
|
<?php
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue