From 42a0e2f72fed0a947242b004a0fc6eb4a664174b Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 3 Apr 2021 16:04:28 +0300 Subject: Updated all double quotes to single quotes where possible --- src/controllers/BaseController.php | 17 +++++----- src/controllers/CreateOfferController.php | 4 +-- src/controllers/DashboardController.php | 8 ++--- src/controllers/DashboardLoginController.php | 8 ++--- src/controllers/EditOfferController.php | 2 +- src/controllers/LandingController.php | 6 ++-- src/index.php | 18 +++++------ src/models/Company.php | 6 ++-- src/models/DB.php | 46 ++++++++++++++-------------- src/models/DBModel.php | 2 +- src/models/JobOffer.php | 18 +++++------ src/views/edit-offer.php | 2 +- 12 files changed, 68 insertions(+), 69 deletions(-) (limited to 'src') diff --git a/src/controllers/BaseController.php b/src/controllers/BaseController.php index 2c2a647..f766398 100644 --- a/src/controllers/BaseController.php +++ b/src/controllers/BaseController.php @@ -1,14 +1,14 @@ id] = $company->name; } - include "views/dashboard.php"; + include('views/dashboard.php'); } public static function post() { switch($_POST['_method']) { - case "get": + case 'get': EditOfferController::get(); break; - case "put": + case 'put': EditOfferController::put(); break; - case "delete": + case 'delete': EditOfferController::delete(); break; } diff --git a/src/controllers/DashboardLoginController.php b/src/controllers/DashboardLoginController.php index fe2009b..af1113e 100644 --- a/src/controllers/DashboardLoginController.php +++ b/src/controllers/DashboardLoginController.php @@ -6,20 +6,20 @@ class DashboardLoginController extends BaseController { private static $message; public static function get() { - include "views/dashboard-login.php"; + include('views/dashboard-login.php'); } public static function post() { if (isset($_POST['_method'])) { DashboardController::invoke(); } - else if ($_POST['username'] == "admin" && $_POST['password'] == "admin") { + else if ($_POST['username'] == 'admin' && $_POST['password'] == 'admin') { // Load normal dashboard DashboardController::get(); } else { - self::$message = "Bad credentials!"; - include "views/dashboard-login.php"; + self::$message = 'Bad credentials!'; + include('views/dashboard-login.php'); } } } diff --git a/src/controllers/EditOfferController.php b/src/controllers/EditOfferController.php index ae49c5b..dc9a753 100644 --- a/src/controllers/EditOfferController.php +++ b/src/controllers/EditOfferController.php @@ -11,7 +11,7 @@ class EditOfferController extends BaseController { public static function get() { self::$job = JobOffer::getFromDBById($_POST['jobId']); self::$companies = Company::getAllFromDB(); - include "views/edit-offer.php"; + include('views/edit-offer.php'); } public static function put() { diff --git a/src/controllers/LandingController.php b/src/controllers/LandingController.php index ffa8644..9e81751 100644 --- a/src/controllers/LandingController.php +++ b/src/controllers/LandingController.php @@ -1,7 +1,7 @@ id] = $company->name; } - include "views/landing.php"; + include('views/landing.php'); } } diff --git a/src/index.php b/src/index.php index 8b45dea..be262cd 100644 --- a/src/index.php +++ b/src/index.php @@ -30,9 +30,9 @@ createTable(self::TABLE_NAME, $columns); } diff --git a/src/models/DB.php b/src/models/DB.php index 8174831..0f06573 100644 --- a/src/models/DB.php +++ b/src/models/DB.php @@ -3,34 +3,34 @@ * The model that has the database functionality. DO NOT instantiate this class! If you need an instance, extend the DBModel class! */ class DB { - private static $servername = "localhost"; - private static $username = "root"; - private static $password = "password"; - private static $dbname = "devrix_job_board"; + private static $servername = 'localhost'; + private static $username = 'root'; + private static $password = 'password'; + private static $dbname = 'devrix_job_board'; - public const STRING_TYPE = "VARCHAR(100)"; - public const FLOAT_TYPE = "DOUBLE(16,4)"; - public const INTEGER_TYPE = "INT"; + public const STRING_TYPE = 'VARCHAR(100)'; + public const FLOAT_TYPE = 'DOUBLE(16,4)'; + public const INTEGER_TYPE = 'INT'; private PDO $connection; function __construct() { // Try to connect try { - $this->connection = new PDO("mysql:host=" . self::$servername, self::$username, self::$password); + $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(); + echo '[DB Exception]: ' . $e->getMessage(); } // Make sure the actual db exists - $createDBQuery = "CREATE DATABASE IF NOT EXISTS " . self::$dbname . ";"; + $createDBQuery = 'CREATE DATABASE IF NOT EXISTS ' . self::$dbname . ';'; $this->connection->exec($createDBQuery); // Connect to the actual database - $this->connection->exec("USE " . self::$dbname); + $this->connection->exec('USE ' . self::$dbname); } /** @@ -63,20 +63,20 @@ class DB { $query .= "{$column}, "; } - $query .= "PRIMARY KEY (id), "; + $query .= 'PRIMARY KEY (id), '; foreach ($foreignKeys as $fk) { $query .= "{$fk}, "; } - $query = rtrim($query, ", "); - $query .= ");"; + $query = rtrim($query, ', '); + $query .= ');'; try { $this->connection->exec($query); } catch (PDOException $e) { - echo "[DB Exception]: " . $e->getMessage(); + echo '[DB Exception]: ' . $e->getMessage(); } } @@ -92,22 +92,22 @@ class DB { $query = "INSERT INTO {$tableName} VALUES(NULL, "; foreach($values as $value) { - if (gettype($value) == "string") { + if (gettype($value) == 'string') { $query .= "'{$value}', "; } else { $query .= "{$value}, "; } } - $query = rtrim($query, ", "); + $query = rtrim($query, ', '); - $query .= ");"; + $query .= ');'; try { $this->connection->exec($query); } catch (PDOException $e) { - echo "[DB Exception]: " . $e->getMessage(); + echo '[DB Exception]: ' . $e->getMessage(); } } @@ -146,9 +146,9 @@ class DB { $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 .= "{$values[$i]} = " . (gettype($values[$i+1]) == 'string' ? "'{$values[$i+1]}'" : $values[$i+1]) . ', '; } - $query = rtrim($query, ", "); + $query = rtrim($query, ', '); $query .= " WHERE id = {$id};"; @@ -156,7 +156,7 @@ class DB { $this->connection->exec($query); } catch (PDOException $e) { - echo "[DB Exception]: " . $e->getMessage(); + echo '[DB Exception]: ' . $e->getMessage(); } } @@ -170,7 +170,7 @@ class DB { $this->connection->exec("DELETE FROM {$tableName} WHERE id = {$id}"); } catch (PDOException $e) { - echo "[DB Exception]: " . $e->getMessage(); + echo '[DB Exception]: ' . $e->getMessage(); } } } diff --git a/src/models/DBModel.php b/src/models/DBModel.php index 4e10c18..a9f931c 100644 --- a/src/models/DBModel.php +++ b/src/models/DBModel.php @@ -1,5 +1,5 @@ createTable(self::TABLE_NAME, $columns, $foreignKeys); } @@ -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, "companyId", $jb->companyId, "salary", $jb->salary); + self::$DB->updateById(self::TABLE_NAME, $jb->id, 'title', $jb->title, 'description', $jb->description, 'companyId', $jb->companyId, 'salary', $jb->salary); } /* Delete */ diff --git a/src/views/edit-offer.php b/src/views/edit-offer.php index 992b08e..2643fce 100644 --- a/src/views/edit-offer.php +++ b/src/views/edit-offer.php @@ -13,7 +13,7 @@ id}\""; - echo (self::$job->companyId == $company->id ? "selected" : "") . ">{$company->name}"; + echo (self::$job->companyId == $company->id ? 'selected' : '') . '>{$company->name}'; } ?> -- cgit v1.3.1-23-gd82d From 9b086f2c849aa765c3e5a72a7063343e7237f030 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 3 Apr 2021 16:06:33 +0300 Subject: Removed backticks from DB model --- src/models/DB.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/models/DB.php b/src/models/DB.php index 0f06573..db93d32 100644 --- a/src/models/DB.php +++ b/src/models/DB.php @@ -117,7 +117,7 @@ class DB { * 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 = $this->connection->prepare("SELECT * FROM {$tableName} WHERE id = {$id}"); $sth->execute(); return $sth->fetch(PDO::FETCH_OBJ); @@ -127,7 +127,7 @@ class DB { * Returns all values inside a table. */ function getAllValues(string $tableName) { - $sth = $this->connection->prepare("SELECT * FROM `{$tableName}`"); + $sth = $this->connection->prepare("SELECT * FROM {$tableName}"); $sth->execute(); return $sth->fetchAll(PDO::FETCH_OBJ); -- cgit v1.3.1-23-gd82d From 7ef2ae186ec847d0e8ae82cbfd5117a94687aa70 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 3 Apr 2021 16:09:59 +0300 Subject: Updated formatting of if-else statements in DB model --- src/models/DB.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'src') diff --git a/src/models/DB.php b/src/models/DB.php index db93d32..c14b9d3 100644 --- a/src/models/DB.php +++ b/src/models/DB.php @@ -92,12 +92,10 @@ class DB { $query = "INSERT INTO {$tableName} VALUES(NULL, "; foreach($values as $value) { - if (gettype($value) == 'string') { + if (gettype($value) == 'string') $query .= "'{$value}', "; - } - else { + else $query .= "{$value}, "; - } } $query = rtrim($query, ', '); @@ -146,7 +144,14 @@ class DB { $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 .= "{$values[$i]} = "; + + if (gettype($values[$i+1]) == 'string') + $query .= "'{$values[$i+1]}'"; + else + $query .= $values[$i+1]; + + $query .= ', '; } $query = rtrim($query, ', '); -- cgit v1.3.1-23-gd82d From 6d9f958082d7c1ebee30b0477bf6446fb3d09abb Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 3 Apr 2021 16:15:30 +0300 Subject: Updated comments and documentation in DB model --- src/models/DB.php | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'src') diff --git a/src/models/DB.php b/src/models/DB.php index c14b9d3..f424334 100644 --- a/src/models/DB.php +++ b/src/models/DB.php @@ -34,6 +34,8 @@ class DB { } /** + * Generates a foreign key string from the given parameters. + * * @return string */ static function genFK(string $currentColumn, string $foreignTable, string $foreignColumn) { @@ -59,10 +61,12 @@ class DB { $query = "CREATE TABLE IF NOT EXISTS {$tableName}( id INT NOT NULL AUTO_INCREMENT, "; + // Create column parts of query string foreach ($columns as $column) { $query .= "{$column}, "; } + // Create key(s) parts of query string $query .= 'PRIMARY KEY (id), '; foreach ($foreignKeys as $fk) { @@ -91,7 +95,9 @@ class DB { function insertValue(string $tableName, ...$values) { $query = "INSERT INTO {$tableName} VALUES(NULL, "; + // Create the values part of the query string foreach($values as $value) { + // In queries, strings must be surrounded in single quotes if (gettype($value) == 'string') $query .= "'{$value}', "; else @@ -143,9 +149,11 @@ class DB { function updateById(string $tableName, int $id, ...$values) { $query = "UPDATE {$tableName} SET "; + // Create the name = value part of query string for ($i = 0; $i < sizeof($values); $i += 2) { $query .= "{$values[$i]} = "; + // In queries, strings must be surrounded in single quotes if (gettype($values[$i+1]) == 'string') $query .= "'{$values[$i+1]}'"; else -- cgit v1.3.1-23-gd82d From 976b399f90fc5c0152f87e474e61e6065c0e7a5f Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 3 Apr 2021 16:25:24 +0300 Subject: Updated the comments and documentation in some controllers --- src/controllers/BaseController.php | 4 ++++ src/controllers/DashboardController.php | 3 +++ src/controllers/DashboardLoginController.php | 3 +++ 3 files changed, 10 insertions(+) (limited to 'src') diff --git a/src/controllers/BaseController.php b/src/controllers/BaseController.php index f766398..412cf25 100644 --- a/src/controllers/BaseController.php +++ b/src/controllers/BaseController.php @@ -1,5 +1,9 @@ Date: Sat, 3 Apr 2021 16:27:19 +0300 Subject: Fixed single quotes that needed to be double quotes in edit offer view --- src/views/edit-offer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src') diff --git a/src/views/edit-offer.php b/src/views/edit-offer.php index 2643fce..b1961d6 100644 --- a/src/views/edit-offer.php +++ b/src/views/edit-offer.php @@ -13,7 +13,7 @@ id}\""; - echo (self::$job->companyId == $company->id ? 'selected' : '') . '>{$company->name}'; + echo (self::$job->companyId == $company->id ? 'selected' : '') . ">{$company->name}"; } ?> -- cgit v1.3.1-23-gd82d From cc35f9a9e7f57e2afc48767a7f392529d448a072 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 3 Apr 2021 17:56:31 +0300 Subject: By default the company table will now come with three company names --- src/models/Company.php | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'src') diff --git a/src/models/Company.php b/src/models/Company.php index 965531e..58b1734 100644 --- a/src/models/Company.php +++ b/src/models/Company.php @@ -19,6 +19,13 @@ class Company extends DBModel { 'name ' . DB::STRING_TYPE, ); self::$DB->createTable(self::TABLE_NAME, $columns); + + // Since there is no real way to add companies, this serves as the only official way. + if (sizeof(self::getAllFromDB()) == 0) { + self::insertIntoDB(new Company("MegaCorp")); + self::insertIntoDB(new Company("Cool INC.")); + self::insertIntoDB(new Company("Company Awesome Ltd.")); + } } /* Create */ -- cgit v1.3.1-23-gd82d From 7828d17000f2af72e2602c0813844499cba4612f Mon Sep 17 00:00:00 2001 From: Syndamia Date: Sat, 3 Apr 2021 18:13:31 +0300 Subject: Removed static company image from landing page job offers --- README.md | 2 -- screenshots/landing-page.png | Bin 29352 -> 24583 bytes src/views/landing.php | 5 ----- 3 files changed, 7 deletions(-) (limited to 'src') diff --git a/README.md b/README.md index b464099..6dfef59 100644 --- a/README.md +++ b/README.md @@ -64,8 +64,6 @@ There are also a few custom stylings I had to make, all located in [`prog.css`]( - form and input styling - pages that have only a form inside them (for example, the [`create offer`](https://github.com/Syndamia/devrix-job-board/blob/main/src/views/create-offer.php) page) -**Note**: on the landing page, job offers have a picture to the right side of them. This is by design, since the template originally had them and without them, the job offers look weird/bad. There is no functinality behind them, they're static and purely aesthetical. - ## Tools This repo contains some tools that could be useful during setup and development of the app. They're all located in the `tools` folder. diff --git a/screenshots/landing-page.png b/screenshots/landing-page.png index d42302f..0a76312 100644 Binary files a/screenshots/landing-page.png and b/screenshots/landing-page.png differ diff --git a/src/views/landing.php b/src/views/landing.php index 514e5a7..97b53f7 100644 --- a/src/views/landing.php +++ b/src/views/landing.php @@ -12,11 +12,6 @@ '. $job->description . ' - '; } ?> -- cgit v1.3.1-23-gd82d