diff --git a/CSY2028/DatabaseTable.php b/CSY2028/DatabaseTable.php index 8377290..56c2997 100644 --- a/CSY2028/DatabaseTable.php +++ b/CSY2028/DatabaseTable.php @@ -36,12 +36,12 @@ class DatabaseTable { $this->pdo->prepare('UPDATE '. $this->table .' SET '. \implode(', ', $params) .' WHERE '. $this->pk .' = :primaryKey')->execute($record); } - public function find($column, $value, $column2 = "", $value2 = "", $comparator = "=", $order = "ASC") { - if ($column2 == "" && $value2 == "") { + public function find($column, $value, $column2 = "", $value2 = "", $comparator = "=", $comparator2 = "=", $order = "ASC", $orderColumn = "id") { + if ($column2 == "" || $value2 == "") { $values = [ 'value' => $value ]; - $stmt = $this->pdo->prepare('SELECT * FROM '. $this->table . ' WHERE '. $column . ' '. $comparator .' :value ORDER BY '. $column ." ". $order); + $stmt = $this->pdo->prepare('SELECT * FROM '.$this->table.' WHERE '.$column.' '.$comparator.' :value ORDER BY '.$orderColumn." ".$order); $stmt->setFetchMode(\PDO::FETCH_CLASS, $this->entityClass, $this->entityConstructor); $stmt->execute($values); return $stmt->fetchAll(); @@ -51,7 +51,7 @@ class DatabaseTable { 'value' => $value, 'value2' => $value2 ]; - $stmt = $this->pdo->prepare('SELECT * FROM '. $this->table . ' WHERE '. $column . ' '. $comparator .' :value AND '. $column2 .' = :value2'); + $stmt = $this->pdo->prepare('SELECT * FROM '.$this->table.' WHERE '.$column.' '.$comparator.' :value AND '.$column2.' '.$comparator2.' :value2 ORDER BY '.$orderColumn." ".$order); $stmt->setFetchMode(\PDO::FETCH_CLASS, $this->entityClass, $this->entityConstructor); $stmt->execute($values); return $stmt->fetchAll(); diff --git a/jobs/controllers/Jobs.php b/jobs/controllers/Jobs.php index 1fa5221..e16fb00 100644 --- a/jobs/controllers/Jobs.php +++ b/jobs/controllers/Jobs.php @@ -14,7 +14,7 @@ class Jobs { } public function home() { - $this->vars['jobs'] = $this->jobsTable->find("closingDate", date("y-m-d"), "", "", ">", "DESC"); + $this->vars['jobs'] = $this->jobsTable->find("closingDate", date("y-m-d"), "", "", ">", "", "DESC", "closingDate"); return ['template' => 'home.html.php', 'title' => 'Jo\'s Jobs- Home', 'vars' => $this->vars @@ -31,7 +31,7 @@ class Jobs { $this->vars['jobs'] = $this->jobsTable->find('categoryId', $cat[0]->id, "location", $_GET['filter']); } else { - $this->vars['jobs'] = $this->jobsTable->find('categoryId', $cat[0]->id); + $this->vars['jobs'] = $this->jobsTable->find('categoryId', $cat[0]->id, "closingDate", date("y-m-d"), "=", ">"); } $this->vars['heading'] = $cat[0]->name;