From 1787135de8e42d1319f72f4f4b2798aaf8b34c10 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 1 Apr 2021 12:23:17 +0300 Subject: Added a Company model --- src/models/Company.php | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 src/models/Company.php (limited to 'src/models/Company.php') diff --git a/src/models/Company.php b/src/models/Company.php new file mode 100644 index 0000000..02d073c --- /dev/null +++ b/src/models/Company.php @@ -0,0 +1,43 @@ +name = $name; + } + + static function __constructStatic() { + self::$DB->createTable(self::TABLE_NAME, self::TABLE_COLUMNS); + } + + /* Create */ + + /** + * Inserts the giveb JobOffer into the databse. The id is automatically generated in the database. + * + * @param Company $com + */ + static function insertIntoDB($com) { + self::$DB->insertValue(self::TABLE_NAME, $com->name); + } + + /* Read */ + + /** + * Returns all Companies from the database. + * + * @return Company[] + */ + static function getAllFromDB() { + return self::$DB->getAllValues(self::TABLE_NAME); + } +} + +Company::__constructStatic(); -- cgit v1.3.1-26-gb76a 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/Company.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-26-gb76a 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/Company.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-26-gb76a 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/Company.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 @@