Summary Files Commits Branches @commit @diff @stats
path: root / src / models
diff options
context:
space:
mode:
2 files changed, 16 insertions, 2 deletions
-rw-r--r--src/models/DB.php7
-rw-r--r--src/models/JobOffer.php11
diff --git a/src/models/DB.php b/src/models/DB.php
index 299b05a..b973e4b 100644
--- a/src/models/DB.php
+++ b/src/models/DB.php
@@ -37,6 +37,13 @@ class DB {
$this->connection->exec($query);
}
+ function getById(string $tableName, int $id) {
+ $sth = $this->connection->prepare("SELECT * FROM `{$tableName}` WHERE id = {$id}");
+ $sth->execute();
+
+ return $sth->fetch(PDO::FETCH_OBJ);
+ }
+
function getAllValues(string $tableName) {
$sth = $this->connection->prepare("SELECT * FROM `{$tableName}`");
$sth->execute();
diff --git a/src/models/JobOffer.php b/src/models/JobOffer.php
index 7603211..3bb1791 100644
--- a/src/models/JobOffer.php
+++ b/src/models/JobOffer.php
@@ -20,13 +20,20 @@ class JobOffer extends DBModel {
}
/**
+ * @return JobOffer
+ */
+ static function getFromDBById(int $id) {
+ return self::$DB->getById(self::TABLE_NAME, $id);
+ }
+
+ /**
* @return JobOffer[]
*/
- static function getAll() {
+ static function getAllFromDB() {
return self::$DB->getAllValues(self::TABLE_NAME);
}
- static function insertInDB(JobOffer $jb) {
+ static function insertIntoDB(JobOffer $jb) {
self::$DB->insertValue(self::TABLE_NAME, $jb->title, $jb->description, $jb->company, $jb->salary);
}
}