From eee825eb3ed35268c647a0e50904197eb2e953c5 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Wed, 31 Mar 2021 21:40:34 +0300 Subject: Added JobOffer model and implemented a basic system for creating tables --- src/models/JobOffer.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 src/models/JobOffer.php (limited to 'src/models/JobOffer.php') diff --git a/src/models/JobOffer.php b/src/models/JobOffer.php new file mode 100644 index 0000000..1fb3d28 --- /dev/null +++ b/src/models/JobOffer.php @@ -0,0 +1,18 @@ +db = $db; + } +} -- cgit v1.3.1-23-gd82d From 3298938d8f3bc7d6dafd8e67311e4ff0afc8d288 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Wed, 31 Mar 2021 22:01:00 +0300 Subject: Implemented DBModel for storing an instance of DB --- src/index.php | 4 ++-- src/models/DBModel.php | 12 ++++++++++++ src/models/JobOffer.php | 13 +++++++------ 3 files changed, 21 insertions(+), 8 deletions(-) create mode 100644 src/models/DBModel.php (limited to 'src/models/JobOffer.php') diff --git a/src/index.php b/src/index.php index 86562ab..285f6e7 100644 --- a/src/index.php +++ b/src/index.php @@ -1,6 +1,6 @@

Hello World!

diff --git a/src/models/DBModel.php b/src/models/DBModel.php new file mode 100644 index 0000000..65bb725 --- /dev/null +++ b/src/models/DBModel.php @@ -0,0 +1,12 @@ +db = $db; + function __construct(string $title, string $description, string $company, float $salary) { + $this->title = $title; + $this->description = $description; + $this->company = $company; + $this->salary = $salary; } } -- cgit v1.3.1-23-gd82d From 9f23c3963285960ec4d30fe7b25730da1125b4a4 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 1 Apr 2021 09:13:53 +0300 Subject: Updated JobOffer to initialise it's own db table --- src/models/DBModel.php | 2 +- src/models/JobOffer.php | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'src/models/JobOffer.php') diff --git a/src/models/DBModel.php b/src/models/DBModel.php index 65bb725..6980446 100644 --- a/src/models/DBModel.php +++ b/src/models/DBModel.php @@ -2,7 +2,7 @@ include_once("DB.php"); abstract class DBModel { - protected static $DB; + protected static DB $DB; public static function __constructStatic() { self::$DB = new DB(); diff --git a/src/models/JobOffer.php b/src/models/JobOffer.php index d4268db..5cd6de4 100644 --- a/src/models/JobOffer.php +++ b/src/models/JobOffer.php @@ -15,5 +15,7 @@ class JobOffer extends DBModel { $this->description = $description; $this->company = $company; $this->salary = $salary; + + self::$DB->createTable(self::TABLE_NAME, self::TABLE_COLUMNS); } } -- cgit v1.3.1-23-gd82d From 588c444417c1aa68eccfe9cb96b6d10ebd4a0a84 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 1 Apr 2021 09:15:17 +0300 Subject: Implemented a getall values from db method in JobOffer and show results in index --- src/index.php | 3 +++ src/models/JobOffer.php | 7 +++++++ 2 files changed, 10 insertions(+) (limited to 'src/models/JobOffer.php') diff --git a/src/index.php b/src/index.php index 285f6e7..6f290d6 100644 --- a/src/index.php +++ b/src/index.php @@ -3,4 +3,7 @@ include_once("models/JobOffer.php"); $jb = new JobOffer("a", "", "", 0); + foreach(JobOffer::getAll() as $key => $obj) { + echo $obj->salary . "
"; + } ?> diff --git a/src/models/JobOffer.php b/src/models/JobOffer.php index 5cd6de4..736d644 100644 --- a/src/models/JobOffer.php +++ b/src/models/JobOffer.php @@ -18,4 +18,11 @@ class JobOffer extends DBModel { self::$DB->createTable(self::TABLE_NAME, self::TABLE_COLUMNS); } + + /** + * @return JobOffer[] + */ + static function getAll() { + return self::$DB->getAllValues(self::TABLE_NAME); + } } -- cgit v1.3.1-23-gd82d From e9ba7fbcff47f0e4a03d74b857e9864d67a8b163 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 1 Apr 2021 09:37:42 +0300 Subject: Implemented value insertion into DB --- src/index.php | 5 +++-- src/models/DB.php | 18 ++++++++++++++++++ src/models/JobOffer.php | 4 ++++ 3 files changed, 25 insertions(+), 2 deletions(-) (limited to 'src/models/JobOffer.php') diff --git a/src/index.php b/src/index.php index 5fefff4..ecebcd9 100644 --- a/src/index.php +++ b/src/index.php @@ -2,8 +2,9 @@ $obj) { - echo $obj->id . "
"; + echo "{$obj->id} {$obj->title}
"; } ?> diff --git a/src/models/DB.php b/src/models/DB.php index 77e08a5..299b05a 100644 --- a/src/models/DB.php +++ b/src/models/DB.php @@ -43,4 +43,22 @@ class DB { return $sth->fetchAll(PDO::FETCH_OBJ); } + + function insertValue(string $tableName, ...$values) { + $query = "INSERT INTO {$tableName} VALUES(NULL, "; + + foreach($values as $value) { + if (gettype($value) == "string") { + $query .= "'{$value}', "; + } + else { + $query .= "{$value}, "; + } + } + $query = rtrim($query, ", "); + + $query .= ");"; + + $this->connection->exec($query); + } } diff --git a/src/models/JobOffer.php b/src/models/JobOffer.php index 736d644..7603211 100644 --- a/src/models/JobOffer.php +++ b/src/models/JobOffer.php @@ -25,4 +25,8 @@ class JobOffer extends DBModel { static function getAll() { return self::$DB->getAllValues(self::TABLE_NAME); } + + static function insertInDB(JobOffer $jb) { + self::$DB->insertValue(self::TABLE_NAME, $jb->title, $jb->description, $jb->company, $jb->salary); + } } -- cgit v1.3.1-23-gd82d From f9e2090a1028712ecc6e1b0c71390c821689b414 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 1 Apr 2021 09:43:48 +0300 Subject: Implemented getById from DB and changed some method names --- src/index.php | 8 ++++++-- src/models/DB.php | 7 +++++++ src/models/JobOffer.php | 11 +++++++++-- 3 files changed, 22 insertions(+), 4 deletions(-) (limited to 'src/models/JobOffer.php') diff --git a/src/index.php b/src/index.php index ecebcd9..55bba39 100644 --- a/src/index.php +++ b/src/index.php @@ -3,8 +3,12 @@ include_once("models/JobOffer.php"); $jb = new JobOffer("Test", "A test", "TheTest", 11); - JobOffer::insertInDB($jb); - foreach(JobOffer::getAll() as $key => $obj) { + // JobOffer::insertInDB($jb); + foreach(JobOffer::getAllFromDB() as $key => $obj) { echo "{$obj->id} {$obj->title}
"; } + echo "
"; + + $gottenjb = JobOffer::getFromDBById(1); + echo $gottenjb->title; ?> 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 @@ -19,14 +19,21 @@ class JobOffer extends DBModel { self::$DB->createTable(self::TABLE_NAME, self::TABLE_COLUMNS); } + /** + * @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); } } -- cgit v1.3.1-23-gd82d From 30ee8530a646d3dcf32d563bbf42475035449bb5 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 1 Apr 2021 10:13:17 +0300 Subject: Implemented update from DB and updated some comments and phpdocumentator tags --- src/index.php | 6 ++++++ src/models/DB.php | 40 ++++++++++++++++++++++++++++++---------- src/models/JobOffer.php | 21 +++++++++++++++++++-- 3 files changed, 55 insertions(+), 12 deletions(-) (limited to 'src/models/JobOffer.php') diff --git a/src/index.php b/src/index.php index 55bba39..6478815 100644 --- a/src/index.php +++ b/src/index.php @@ -11,4 +11,10 @@ $gottenjb = JobOffer::getFromDBById(1); echo $gottenjb->title; + + $gottenjb->title = "Something even newer"; + echo $gottenjb->title; + JobOffer::updateFromDB($gottenjb); + $secgot = JobOffer::getFromDBById(1); + echo $secgot->title; ?> diff --git a/src/models/DB.php b/src/models/DB.php index b973e4b..4c75d17 100644 --- a/src/models/DB.php +++ b/src/models/DB.php @@ -24,6 +24,8 @@ class DB { $this->connection->exec("USE " . self::$dbname); } + /* Create */ + function createTable(string $tableName, array $columns) { $query = "CREATE TABLE IF NOT EXISTS {$tableName}( id INT NOT NULL AUTO_INCREMENT,"; @@ -37,6 +39,26 @@ class DB { $this->connection->exec($query); } + function insertValue(string $tableName, ...$values) { + $query = "INSERT INTO {$tableName} VALUES(NULL, "; + + foreach($values as $value) { + if (gettype($value) == "string") { + $query .= "'{$value}', "; + } + else { + $query .= "{$value}, "; + } + } + $query = rtrim($query, ", "); + + $query .= ");"; + + $this->connection->exec($query); + } + + /* Read */ + function getById(string $tableName, int $id) { $sth = $this->connection->prepare("SELECT * FROM `{$tableName}` WHERE id = {$id}"); $sth->execute(); @@ -51,20 +73,18 @@ class DB { return $sth->fetchAll(PDO::FETCH_OBJ); } - function insertValue(string $tableName, ...$values) { - $query = "INSERT INTO {$tableName} VALUES(NULL, "; + /* Update */ - foreach($values as $value) { - if (gettype($value) == "string") { - $query .= "'{$value}', "; - } - else { - $query .= "{$value}, "; - } + function updateById(string $tableName, int $id, ...$values) { + $query = "UPDATE {$tableName} SET "; + + for ($i = 0; $i < sizeof($values); $i += 2) { + $query .= "{$values[$i]} = " . (gettype($values[$i+1]) == "string" ? "'{$values[$i+1]}'" : $values[$i+1]) . ", "; } $query = rtrim($query, ", "); - $query .= ");"; + $query .= " WHERE id = {$id};"; + echo $query; $this->connection->exec($query); } diff --git a/src/models/JobOffer.php b/src/models/JobOffer.php index 3bb1791..2627207 100644 --- a/src/models/JobOffer.php +++ b/src/models/JobOffer.php @@ -19,6 +19,17 @@ class JobOffer extends DBModel { self::$DB->createTable(self::TABLE_NAME, self::TABLE_COLUMNS); } + /* Create */ + + /** + * @param JobOffer $jb + */ + static function insertIntoDB($jb) { + self::$DB->insertValue(self::TABLE_NAME, $jb->title, $jb->description, $jb->company, $jb->salary); + } + + /* Read */ + /** * @return JobOffer */ @@ -33,7 +44,13 @@ class JobOffer extends DBModel { return self::$DB->getAllValues(self::TABLE_NAME); } - static function insertIntoDB(JobOffer $jb) { - self::$DB->insertValue(self::TABLE_NAME, $jb->title, $jb->description, $jb->company, $jb->salary); + /* Update */ + + /** + * @param JobOffer $jb + */ + static function updateFromDB($jb) { + echo "here"; + self::$DB->updateById(self::TABLE_NAME, $jb->id, "title", $jb->title, "description", $jb->description, "company", $jb->company, "salary", $jb->salary); } } -- cgit v1.3.1-23-gd82d From 852e91a3da52a478c942bf7a664df8d8798b0641 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 1 Apr 2021 10:26:26 +0300 Subject: Implemented delete from DB and added error handling to queries --- src/index.php | 2 ++ src/models/DB.php | 42 ++++++++++++++++++++++++++++++++++++------ src/models/JobOffer.php | 7 ++++++- 3 files changed, 44 insertions(+), 7 deletions(-) (limited to 'src/models/JobOffer.php') diff --git a/src/index.php b/src/index.php index 6478815..7120cd3 100644 --- a/src/index.php +++ b/src/index.php @@ -17,4 +17,6 @@ JobOffer::updateFromDB($gottenjb); $secgot = JobOffer::getFromDBById(1); echo $secgot->title; + + JobOffer::deleteFromDB(3); ?> diff --git a/src/models/DB.php b/src/models/DB.php index 4c75d17..b287273 100644 --- a/src/models/DB.php +++ b/src/models/DB.php @@ -12,8 +12,13 @@ class DB { private PDO $connection; function __construct() { - $this->connection = new PDO("mysql:host=" . self::$servername, self::$username, self::$password); - $this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + try { + $this->connection = new PDO("mysql:host=" . self::$servername, self::$username, self::$password); + $this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); + } + catch (PDOException $e) { + echo "[DB Exception]: " . $e->getMessage(); + } // Make sure the actual db exists $createDBQuery = "CREATE DATABASE IF NOT EXISTS " . self::$dbname . ";"; @@ -36,7 +41,12 @@ class DB { $query .= "PRIMARY KEY (id));"; - $this->connection->exec($query); + try { + $this->connection->exec($query); + } + catch (PDOException $e) { + echo "[DB Exception]: " . $e->getMessage(); + } } function insertValue(string $tableName, ...$values) { @@ -54,7 +64,12 @@ class DB { $query .= ");"; - $this->connection->exec($query); + try { + $this->connection->exec($query); + } + catch (PDOException $e) { + echo "[DB Exception]: " . $e->getMessage(); + } } /* Read */ @@ -84,8 +99,23 @@ class DB { $query = rtrim($query, ", "); $query .= " WHERE id = {$id};"; - echo $query; - $this->connection->exec($query); + try { + $this->connection->exec($query); + } + catch (PDOException $e) { + echo "[DB Exception]: " . $e->getMessage(); + } + } + + /* Delete */ + + function deleteById(string $tableName, int $id) { + try { + $this->connection->exec("DELETE FROM {$tableName} WHERE id = {$id}"); + } + catch (PDOException $e) { + echo "[DB Exception]: " . $e->getMessage(); + } } } diff --git a/src/models/JobOffer.php b/src/models/JobOffer.php index 2627207..5d89048 100644 --- a/src/models/JobOffer.php +++ b/src/models/JobOffer.php @@ -50,7 +50,12 @@ class JobOffer extends DBModel { * @param JobOffer $jb */ static function updateFromDB($jb) { - echo "here"; self::$DB->updateById(self::TABLE_NAME, $jb->id, "title", $jb->title, "description", $jb->description, "company", $jb->company, "salary", $jb->salary); } + + /* Delete */ + + static function deleteFromDB(int $id) { + self::$DB->deleteById(self::TABLE_NAME, $id); + } } -- cgit v1.3.1-23-gd82d From 83bb68e766bf12c5c48350bd6d9f8237e301882c Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 1 Apr 2021 11:22:04 +0300 Subject: Added and improved existing phpdocumentator documentation --- src/index.php | 11 ----------- src/models/DB.php | 39 ++++++++++++++++++++++++++++++++++++++- src/models/DBModel.php | 5 ++++- src/models/JobOffer.php | 15 +++++++++++++++ 4 files changed, 57 insertions(+), 13 deletions(-) (limited to 'src/models/JobOffer.php') diff --git a/src/index.php b/src/index.php index 7120cd3..fb5e85e 100644 --- a/src/index.php +++ b/src/index.php @@ -8,15 +8,4 @@ echo "{$obj->id} {$obj->title}
"; } echo "
"; - - $gottenjb = JobOffer::getFromDBById(1); - echo $gottenjb->title; - - $gottenjb->title = "Something even newer"; - echo $gottenjb->title; - JobOffer::updateFromDB($gottenjb); - $secgot = JobOffer::getFromDBById(1); - echo $secgot->title; - - JobOffer::deleteFromDB(3); ?> diff --git a/src/models/DB.php b/src/models/DB.php index b287273..dc69cfe 100644 --- a/src/models/DB.php +++ b/src/models/DB.php @@ -1,4 +1,7 @@ connection = new PDO("mysql:host=" . self::$servername, self::$username, self::$password); $this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); @@ -25,12 +29,21 @@ class DB { $this->connection->exec($createDBQuery); - // Make the actual connection to the database + // Connect to the actual database $this->connection->exec("USE " . self::$dbname); } /* Create */ + /** + * Creates a table, with the given name and given column information. + * **WARNING**: The method also creates an auto-incremented int id column, **DO NOT** specify it! + * + * @param string[] $columns + * Represents the column information. Each value must be like: "column_name data_type", where the data_type should be taken + * from the constant values of DB class. + * Example value: array("first_name " . DB::STRING_TYPE, "age " . DB::INTEGER_TYPE, "income " . DB::FLOAT_TYPE) + */ function createTable(string $tableName, array $columns) { $query = "CREATE TABLE IF NOT EXISTS {$tableName}( id INT NOT NULL AUTO_INCREMENT,"; @@ -49,6 +62,14 @@ class DB { } } + /** + * Inserts a value in a given table. + * + * @param string[] $values + * Represents the data that should be inserted. The values should be ordered the same way the table columns are ordered. + * Example: "John", 20, 2000.3 + * **WARNING**: DO NOT insert the id value + */ function insertValue(string $tableName, ...$values) { $query = "INSERT INTO {$tableName} VALUES(NULL, "; @@ -74,6 +95,9 @@ class DB { /* Read */ + /** + * Returns the next value that has the given id. + */ function getById(string $tableName, int $id) { $sth = $this->connection->prepare("SELECT * FROM `{$tableName}` WHERE id = {$id}"); $sth->execute(); @@ -81,6 +105,9 @@ class DB { return $sth->fetch(PDO::FETCH_OBJ); } + /** + * Returns all values inside a table. + */ function getAllValues(string $tableName) { $sth = $this->connection->prepare("SELECT * FROM `{$tableName}`"); $sth->execute(); @@ -90,6 +117,13 @@ class DB { /* Update */ + /** + * Updates the value with the given id inside the specified table. + * + * @param string[] $values + * Represents the data that should be updated. There should always be an even amount of data, where you alternate the column name and column value. + * Example: "first_name", "John", "age", 20, "income", 2000.3 + */ function updateById(string $tableName, int $id, ...$values) { $query = "UPDATE {$tableName} SET "; @@ -110,6 +144,9 @@ class DB { /* Delete */ + /** + * Deletes the value with the given id inside the given table. + */ function deleteById(string $tableName, int $id) { try { $this->connection->exec("DELETE FROM {$tableName} WHERE id = {$id}"); diff --git a/src/models/DBModel.php b/src/models/DBModel.php index 859ea97..4e10c18 100644 --- a/src/models/DBModel.php +++ b/src/models/DBModel.php @@ -1,9 +1,12 @@ deleteById(self::TABLE_NAME, $id); } -- cgit v1.3.1-23-gd82d From da1cf823d75923594b926d0c46956f385b4ed987 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 1 Apr 2021 12:23:30 +0300 Subject: Job offers company is now a foreign key to the company model --- src/models/JobOffer.php | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) (limited to 'src/models/JobOffer.php') diff --git a/src/models/JobOffer.php b/src/models/JobOffer.php index 4a53b8d..555e7f4 100644 --- a/src/models/JobOffer.php +++ b/src/models/JobOffer.php @@ -1,25 +1,36 @@ title = $title; $this->description = $description; - $this->company = $company; + $this->companyId = $companyId; $this->salary = $salary; + } - self::$DB->createTable(self::TABLE_NAME, self::TABLE_COLUMNS); + static function __constructStatic() { + $foreignKeys = array( + DB::genFK("companyId", Company::TABLE_NAME, "id") + ); + self::$DB->createTable(self::TABLE_NAME, self::TABLE_COLUMNS, $foreignKeys); } /* Create */ @@ -74,3 +85,5 @@ class JobOffer extends DBModel { self::$DB->deleteById(self::TABLE_NAME, $id); } } + +JobOffer::__constructStatic(); -- cgit v1.3.1-23-gd82d From 1bc4dc0f2aab43cc527fe449b2e2701abab35d1b Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 1 Apr 2021 12:26:22 +0300 Subject: Moved static functionality of Company and JobOffer below the dynamic one --- src/models/Company.php | 14 +++++++++----- src/models/JobOffer.php | 20 ++++++++++++-------- 2 files changed, 21 insertions(+), 13 deletions(-) (limited to 'src/models/JobOffer.php') diff --git a/src/models/Company.php b/src/models/Company.php index 02d073c..0fa72d8 100644 --- a/src/models/Company.php +++ b/src/models/Company.php @@ -2,17 +2,21 @@ include_once("DBModel.php"); class Company extends DBModel { - public const TABLE_NAME = "companies"; - public const TABLE_COLUMNS = array( - "name " . DB::STRING_TYPE, - ); - public string $name; function __construct(string $name) { $this->name = $name; } + /* + * Everything from here is static functionality + */ + + public const TABLE_NAME = "companies"; + public const TABLE_COLUMNS = array( + "name " . DB::STRING_TYPE, + ); + static function __constructStatic() { self::$DB->createTable(self::TABLE_NAME, self::TABLE_COLUMNS); } diff --git a/src/models/JobOffer.php b/src/models/JobOffer.php index 555e7f4..3ec4b77 100644 --- a/src/models/JobOffer.php +++ b/src/models/JobOffer.php @@ -6,14 +6,6 @@ include_once("Company.php"); * Model that contains the required JobOffer properties. It also contains the request methods to the job_offers table. */ class JobOffer extends DBModel { - public const TABLE_NAME = "job_offers"; - public const TABLE_COLUMNS = array( - "title " . DB::STRING_TYPE, - "description " . DB::STRING_TYPE, - "companyId " . DB::INTEGER_TYPE, // Requires a foreign key - "salary " . DB::FLOAT_TYPE, - ); - public string $title; public string $description; public int $companyId; @@ -26,6 +18,18 @@ class JobOffer extends DBModel { $this->salary = $salary; } + /* + * Everything from here is static functionality + */ + + public const TABLE_NAME = "job_offers"; + public const TABLE_COLUMNS = array( + "title " . DB::STRING_TYPE, + "description " . DB::STRING_TYPE, + "companyId " . DB::INTEGER_TYPE, // Requires a foreign key + "salary " . DB::FLOAT_TYPE, + ); + static function __constructStatic() { $foreignKeys = array( DB::genFK("companyId", Company::TABLE_NAME, "id") -- cgit v1.3.1-23-gd82d From 8075dde0bc9951b32845e1d02551c335ecab868d Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 1 Apr 2021 12:31:14 +0300 Subject: Made columns in JobOffer and Company models variables inside the static constructor --- src/models/Company.php | 8 ++++---- src/models/JobOffer.php | 14 +++++++------- 2 files changed, 11 insertions(+), 11 deletions(-) (limited to 'src/models/JobOffer.php') diff --git a/src/models/Company.php b/src/models/Company.php index 0fa72d8..0df31ee 100644 --- a/src/models/Company.php +++ b/src/models/Company.php @@ -13,12 +13,12 @@ class Company extends DBModel { */ public const TABLE_NAME = "companies"; - public const TABLE_COLUMNS = array( - "name " . DB::STRING_TYPE, - ); static function __constructStatic() { - self::$DB->createTable(self::TABLE_NAME, self::TABLE_COLUMNS); + $columns = array( + "name " . DB::STRING_TYPE, + ); + self::$DB->createTable(self::TABLE_NAME, $columns); } /* Create */ diff --git a/src/models/JobOffer.php b/src/models/JobOffer.php index 3ec4b77..7913edd 100644 --- a/src/models/JobOffer.php +++ b/src/models/JobOffer.php @@ -23,18 +23,18 @@ class JobOffer extends DBModel { */ public const TABLE_NAME = "job_offers"; - public const TABLE_COLUMNS = array( - "title " . DB::STRING_TYPE, - "description " . DB::STRING_TYPE, - "companyId " . DB::INTEGER_TYPE, // Requires a foreign key - "salary " . DB::FLOAT_TYPE, - ); static function __constructStatic() { + $columns = array( + "title " . DB::STRING_TYPE, + "description " . DB::STRING_TYPE, + "companyId " . DB::INTEGER_TYPE, // Requires a foreign key + "salary " . DB::FLOAT_TYPE, + ); $foreignKeys = array( DB::genFK("companyId", Company::TABLE_NAME, "id") ); - self::$DB->createTable(self::TABLE_NAME, self::TABLE_COLUMNS, $foreignKeys); + self::$DB->createTable(self::TABLE_NAME, $columns, $foreignKeys); } /* Create */ -- cgit v1.3.1-23-gd82d From ff5e34d0a5e07ff2f2181f362044cb77f262c147 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 1 Apr 2021 13:26:48 +0300 Subject: Made every request get redirected to index.php --- devrix-job-board.conf | 9 +++++++++ src/models/Company.php | 2 +- src/models/JobOffer.php | 4 ++-- 3 files changed, 12 insertions(+), 3 deletions(-) (limited to 'src/models/JobOffer.php') diff --git a/devrix-job-board.conf b/devrix-job-board.conf index 12bee1c..49356f2 100644 --- a/devrix-job-board.conf +++ b/devrix-job-board.conf @@ -3,4 +3,13 @@ DocumentRoot /var/www/devrix-job-board ServerName djb.local ServerAlias djb.local + + + RewriteEngine On + RewriteBase / + RewriteCond %{REQUEST_FILENAME} !-d + RewriteCond %{REQUEST_FILENAME} !-f + RewriteRule ^(.+)$ index.php [QSA,L] + + diff --git a/src/models/Company.php b/src/models/Company.php index 0df31ee..1dfb05e 100644 --- a/src/models/Company.php +++ b/src/models/Company.php @@ -1,5 +1,5 @@ Date: Sat, 3 Apr 2021 09:31:25 +0300 Subject: Implemented job offer form creating a new job offer in the database; Fixed insertIntoDB method of JobOffer; Added a link to JobOffer page in landing page --- src/controllers/CreateOfferController.php | 15 ++++++++++----- src/models/JobOffer.php | 2 +- src/views/create-offer.php | 6 +++++- src/views/landing.php | 2 ++ 4 files changed, 18 insertions(+), 7 deletions(-) (limited to 'src/models/JobOffer.php') diff --git a/src/controllers/CreateOfferController.php b/src/controllers/CreateOfferController.php index d510978..a223463 100644 --- a/src/controllers/CreateOfferController.php +++ b/src/controllers/CreateOfferController.php @@ -1,16 +1,21 @@ insertValue(self::TABLE_NAME, $jb->title, $jb->description, $jb->company, $jb->salary); + self::$DB->insertValue(self::TABLE_NAME, $jb->title, $jb->description, $jb->companyId, $jb->salary); } /* Read */ diff --git a/src/views/create-offer.php b/src/views/create-offer.php index 2bdeeaf..9162c90 100644 --- a/src/views/create-offer.php +++ b/src/views/create-offer.php @@ -9,7 +9,11 @@

diff --git a/src/views/landing.php b/src/views/landing.php index 06e32a5..e6477ee 100644 --- a/src/views/landing.php +++ b/src/views/landing.php @@ -5,3 +5,5 @@ echo "{$job->id} {$job->title}
"; } ?> + +Create a new Job Offer -- cgit v1.3.1-23-gd82d From 1ceaf277b8d6ae6fe39f7ac8aca57f864f8813e7 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 3 Apr 2021 11:03:07 +0300 Subject: Fixed job offer update from db logic --- src/models/JobOffer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/models/JobOffer.php') diff --git a/src/models/JobOffer.php b/src/models/JobOffer.php index 101bc03..b86ff86 100644 --- a/src/models/JobOffer.php +++ b/src/models/JobOffer.php @@ -77,7 +77,7 @@ class JobOffer extends DBModel { * @param JobOffer $jb */ static function updateFromDB($jb) { - self::$DB->updateById(self::TABLE_NAME, $jb->id, "title", $jb->title, "description", $jb->description, "company", $jb->company, "salary", $jb->salary); + self::$DB->updateById(self::TABLE_NAME, $jb->id, "title", $jb->title, "description", $jb->description, "companyId", $jb->companyId, "salary", $jb->salary); } /* Delete */ -- cgit v1.3.1-23-gd82d