diff options
Updated all double quotes to single quotes where possible
12 files changed, 68 insertions, 69 deletions
| -rw-r--r-- | src/controllers/BaseController.php | 17 | ||||
| -rw-r--r-- | src/controllers/CreateOfferController.php | 4 | ||||
| -rw-r--r-- | src/controllers/DashboardController.php | 8 | ||||
| -rw-r--r-- | src/controllers/DashboardLoginController.php | 8 | ||||
| -rw-r--r-- | src/controllers/EditOfferController.php | 2 | ||||
| -rw-r--r-- | src/controllers/LandingController.php | 6 | ||||
| -rw-r--r-- | src/index.php | 18 | ||||
| -rw-r--r-- | src/models/Company.php | 6 | ||||
| -rw-r--r-- | src/models/DB.php | 46 | ||||
| -rw-r--r-- | src/models/DBModel.php | 2 | ||||
| -rw-r--r-- | src/models/JobOffer.php | 18 | ||||
| -rw-r--r-- | src/views/edit-offer.php | 2 |
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 @@ <?php class BaseController { public static function invoke() { - switch ($_SERVER["REQUEST_METHOD"]) { - case "POST": + switch ($_SERVER['REQUEST_METHOD']) { + case 'POST': static::post(); break; - case "PUT": + case 'PUT': static::put(); break; - case "DELETE": + case 'DELETE': static::delete(); break; default: @@ -18,19 +18,18 @@ class BaseController { } protected static function get() { - echo "GET method not implemented!"; + echo 'GET method not implemented!'; } protected static function post() { - - echo "POST method not implemented!"; + echo 'POST method not implemented!'; } protected static function put() { - echo "PUT method not implemented!"; + echo 'PUT method not implemented!'; } protected static function delete() { - echo "DELETE method not implemented!"; + echo 'DELETE method not implemented!'; } } diff --git a/src/controllers/CreateOfferController.php b/src/controllers/CreateOfferController.php index a223463..bb6015b 100644 --- a/src/controllers/CreateOfferController.php +++ b/src/controllers/CreateOfferController.php @@ -7,7 +7,7 @@ class CreateOfferController extends BaseController { public static function get() { self::$companies = Company::getAllFromDB(); - include 'views/create-offer.php'; + include('views/create-offer.php'); } public static function post() { @@ -15,7 +15,7 @@ class CreateOfferController extends BaseController { JobOffer::insertIntoDB($newJobOffer); // Redirect to landing page - header("Location: /", TRUE, 301); + header('Location: /', TRUE, 301); exit(); } } diff --git a/src/controllers/DashboardController.php b/src/controllers/DashboardController.php index 548f60b..80717ca 100644 --- a/src/controllers/DashboardController.php +++ b/src/controllers/DashboardController.php @@ -12,18 +12,18 @@ class DashboardController extends BaseController { foreach(Company::getAllFromDB() as $company) { self::$companies[$company->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 @@ <?php -include_once("models/JobOffer.php"); +include_once('models/JobOffer.php'); include_once('models/Company.php'); -include_once("controllers/BaseController.php"); +include_once('controllers/BaseController.php'); class LandingController extends BaseController { private static $companies = array(); @@ -11,6 +11,6 @@ class LandingController extends BaseController { foreach(Company::getAllFromDB() as $company) { self::$companies[$company->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 @@ </nav> <?php - include_once("controllers/LandingController.php"); - include_once("controllers/CreateOfferController.php"); - include_once("controllers/DashboardLoginController.php"); + include_once('controllers/LandingController.php'); + include_once('controllers/CreateOfferController.php'); + include_once('controllers/DashboardLoginController.php'); /* The landing page practically acts as our page router. * All request get redirected to here (look at the devrix-job-board.conf) @@ -42,16 +42,16 @@ $request = $_SERVER['REQUEST_URI']; switch ($request) { - case "": - case "/": + case '': + case '/': LandingController::invoke(); break; - case "/CreateOffer": - case "/CreateOffer/": + case '/CreateOffer': + case '/CreateOffer/': CreateOfferController::invoke(); break; - case "/Dashboard": - case "/Dashboard/": + case '/Dashboard': + case '/Dashboard/': DashboardLoginController::invoke(); break; default: diff --git a/src/models/Company.php b/src/models/Company.php index 1dfb05e..965531e 100644 --- a/src/models/Company.php +++ b/src/models/Company.php @@ -1,5 +1,5 @@ <?php -include_once("models/DBModel.php"); +include_once('models/DBModel.php'); class Company extends DBModel { public string $name; @@ -12,11 +12,11 @@ class Company extends DBModel { * Everything from here is static functionality */ - public const TABLE_NAME = "companies"; + public const TABLE_NAME = 'companies'; static function __constructStatic() { $columns = array( - "name " . DB::STRING_TYPE, + 'name ' . DB::STRING_TYPE, ); self::$DB->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 @@ <?php -include_once("DB.php"); +include_once('DB.php'); /** * A class, mainly for holding the static DB class intance. You can also get your model id from here. diff --git a/src/models/JobOffer.php b/src/models/JobOffer.php index b86ff86..4fd7acc 100644 --- a/src/models/JobOffer.php +++ b/src/models/JobOffer.php @@ -1,6 +1,6 @@ <?php -include_once("models/DBModel.php"); -include_once("models/Company.php"); +include_once('models/DBModel.php'); +include_once('models/Company.php'); /** * Model that contains the required JobOffer properties. It also contains the request methods to the job_offers table. @@ -22,17 +22,17 @@ class JobOffer extends DBModel { * Everything from here is static functionality */ - public const TABLE_NAME = "job_offers"; + public const TABLE_NAME = 'job_offers'; 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, + '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") + DB::genFK('companyId', Company::TABLE_NAME, 'id') ); self::$DB->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 @@ <?php foreach(self::$companies as $company) { echo "<option value=\"{$company->id}\""; - echo (self::$job->companyId == $company->id ? "selected" : "") . ">{$company->name}</option>"; + echo (self::$job->companyId == $company->id ? 'selected' : '') . '>{$company->name}</option>'; } ?> </select> |
