Summary Files Commits Branches @commit @diff @stats
diff options
context:
space:
mode:
Commitfb2645d444729d656a209ef586a13fb569429280 (patch)
Author
 Kamen Mladenov <kamen.d.mladenov@protonmail.com>
2021-04-03 18:27:33 +0300
Committer
 GitHub <noreply@github.com>
2021-04-03 18:27:33 +0300
Files91daafcdb8af6cd41551bbf442f4be77dee575a4
devrix-job-board-1.0.tar
devrix-job-board-1.0.tar.gz
devrix-job-board-1.0.zip
Parent67bc860ea4b3db5033a42038ab86d0df955c9295 (diff)
Parent3b0cbc90e3046a8bb979c2b9a17fae5a94bb2707 (diff)
Merge pull request #3 from Syndamia/dev v1.0
Exam version finished
diff --git a/README.md b/README.md
index 641416b..7003325 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1,87 @@
# devrix-job-board
-The repository for my solution of DevriX's exam for their internship program
+
+The repository for my solution of DevriX's exam for their internship program.
+
+It's an oversimplified job offer website, (roughly) following the MVC design pattern and using the LAMP stack (with MySQL). In `src` you can find the source code and in `db-export` you can find the export of a very small demo database.
+
+**CREDENTIALS FOR DASHBOARD**
+```
+Username: admin
+Password: admin
+```
+
+<details>
+ <summary>Screenshorts of site</summary>
+ <img src="./screenshots/landing-page.png">
+ <img src="./screenshots/create-offer.png">
+ <img src="./screenshots/dashboard-login.png">
+ <img src="./screenshots/dashboard-logged-in.png">
+ <img src="./screenshots/edit-offer.png">
+</details>
+
+## Contents
+- [Getting started](#Getting%20started)
+- [Structure](#Structure)
+ - [Back-end](#Back-end)
+ - [Front-end](#Front-end)
+- [Tools](#Tools)
+- [Issues and Future](#Issues%20and%20Future)
+
+## Getting started
+
+1. As previously mentioned, the project uses the LAMP stack. Links on setting it up: [Ubuntu 20.04](https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-ubuntu-20-04), [Debian 8](https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mysql-php-lamp-stack-on-debian-8) or [CentOS 8](https://www.digitalocean.com/community/tutorials/how-to-install-linux-apache-mariadb-php-lamp-stack-on-centos-8).
+
+2. You'll need to update the source code with your `MySQL` credentials. In the file `src/models/DB.php`, on lines 6 to 9 you'll find the connection information. You'll need to change the values of `$username` and `$password` with your own.
+ - If you're connecting to a remote database or have your database at a non-standart port, you'll also need to change `$servername`. Changing the value of `$dbname` is completely up to preference.
+ - Don't worry if the database or tables don't exist, when the app starts it automatically create them.
+
+3. Currently this repo provides an Apache configuration file (`configs/devrix-job-board.conf`) with the localhost domain `djb.local`.
+ - To use that domain, you'll also need to open your `/etc/hosts` file and add, on a new line, `127.0.0.1 djb.local`. **Beware**, it will break any other localhost domains you've setup.
+ - If you wanna use it in a server environment, update the values of `ServerName` and `ServerAlias` with your desired domain and subdomain.
+
+4. Finally, we'll need to move the source code to the `/var/www/devrix-job-board/` folder.
+ - This (and creating the folder if it doesn't exist) can be done automatically, just run with sudo the `move-to-www.sh` script:
+ ```
+ sudo ./tools/move-to-www.sh
+ ```
+
+## Structure
+
+This section serves as a mini-documentation of the overall project.
+
+### Back-end
+
+For the back-end, it uses pure PHP, without any libraries what so ever. Database access is done with automatically generated queries (see [`DB.php`](https://github.com/Syndamia/devrix-job-board/blob/main/src/models/DB.php)) and URI routing is done, using the `$_SERVER`'s request URI (see [index.php, Line 44](https://github.com/Syndamia/devrix-job-board/blob/67bc860ea4b3db5033a42038ab86d0df955c9295/src/index.php#L44)).
+
+The database has two tables: `companies` and `job_offers`. Inside `companies` is stored the different company name. `job_offers` contains the actual job offers, where the company is referenced with a foreign key to the `comapnies` table.
+
+### Front-end
+
+The front-end is a modified version of the given [template](https://github.com/xavortm/html-template-jobs). I took the CSS and the structure of the HTML files and applied it to my structure, trying to leave behind as little as possible.
+
+There are also a few custom stylings I had to make, all located in [`prog.css`](https://github.com/Syndamia/devrix-job-board/blob/main/src/css/prog.css). These are mainly:
+- a navigation bar
+- 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)
+
+## 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.
+
+1. `move-to-www.sh` - moves the source code (located in `src`) to the `/var/www/devrix-job-board/` folder
+2. `watch-move-to-www.sh` - does the same thing as `move-to-www.sh`, but does it automatically every time you update a file inside the `src` folder. Especially useful while developing the application.
+ - Dependencies: [`inotify-tools`](https://pkgs.org/download/inotify-tools)
+
+## Issues and Future
+
+The project has the following issues, that the original task description didn't explicitly require to be fixed, but might be a good idea to explore:
+- There is no "404 Not-found" page
+- There is no system for user accounts (and by extension, no system for accepting/signing up to job offers)
+- There is no job offer page (a page for viewing a job offer; currently it only makes sense for sharing, as the landing page shows all job offer information)
+- There is no way to practical way to change the Dashboard page credentials or add multiple ones (e.g. they're hard coded)
+
+These are the following things that might be a good idea to explore, post exam evaluation:
+- Actually using proper tools for the job (using an ORM for database queries, using a more fleshed out routing plugin, etc.)
+- Adding search functionalities (by words and by tags, like company, date, salary, etc.)
+- Either adding more info to job offers or updating the styling to better fit the current job offers
+- Have a proper way to add and remove companies
diff --git a/configs/devrix-job-board.conf b/configs/devrix-job-board.conf
index 49356f2..88021bc 100644
--- a/configs/devrix-job-board.conf
+++ b/configs/devrix-job-board.conf
@@ -12,4 +12,3 @@
RewriteRule ^(.+)$ index.php [QSA,L]
</Directory>
</VirtualHost>
-
diff --git a/db-export/devrix_job_board.sql b/db-export/devrix_job_board.sql
new file mode 100644
index 0000000..a65dbfd
--- /dev/null
+++ b/db-export/devrix_job_board.sql
@@ -0,0 +1,111 @@
+-- phpMyAdmin SQL Dump
+-- version 5.1.0
+-- https://www.phpmyadmin.net/
+--
+-- Host: localhost
+-- Generation Time: Apr 03, 2021 at 03:15 PM
+-- Server version: 8.0.23
+-- PHP Version: 7.4.16
+
+SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
+START TRANSACTION;
+SET time_zone = "+00:00";
+
+
+/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
+/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
+/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
+/*!40101 SET NAMES utf8mb4 */;
+
+--
+-- Database: `devrix_job_board`
+--
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `companies`
+--
+
+CREATE TABLE `companies` (
+ `id` int NOT NULL,
+ `name` varchar(100) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
+
+--
+-- Dumping data for table `companies`
+--
+
+INSERT INTO `companies` (`id`, `name`) VALUES
+(1, 'MegaCorp'),
+(2, 'Cool INC.');
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `job_offers`
+--
+
+CREATE TABLE `job_offers` (
+ `id` int NOT NULL,
+ `title` varchar(100) DEFAULT NULL,
+ `description` varchar(100) DEFAULT NULL,
+ `companyId` int DEFAULT NULL,
+ `salary` double(16,4) DEFAULT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
+
+--
+-- Dumping data for table `job_offers`
+--
+
+INSERT INTO `job_offers` (`id`, `title`, `description`, `companyId`, `salary`) VALUES
+(1, 'Programmer', 'Coding', 1, 2000.0000),
+(7, 'Test Job', 'Testing', 2, 346.0000);
+
+--
+-- Indexes for dumped tables
+--
+
+--
+-- Indexes for table `companies`
+--
+ALTER TABLE `companies`
+ ADD PRIMARY KEY (`id`);
+
+--
+-- Indexes for table `job_offers`
+--
+ALTER TABLE `job_offers`
+ ADD PRIMARY KEY (`id`),
+ ADD KEY `fk_companyId_companies` (`companyId`);
+
+--
+-- AUTO_INCREMENT for dumped tables
+--
+
+--
+-- AUTO_INCREMENT for table `companies`
+--
+ALTER TABLE `companies`
+ MODIFY `id` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;
+
+--
+-- AUTO_INCREMENT for table `job_offers`
+--
+ALTER TABLE `job_offers`
+ MODIFY `id` int NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=10;
+
+--
+-- Constraints for dumped tables
+--
+
+--
+-- Constraints for table `job_offers`
+--
+ALTER TABLE `job_offers`
+ ADD CONSTRAINT `fk_companyId_companies` FOREIGN KEY (`companyId`) REFERENCES `companies` (`id`);
+COMMIT;
+
+/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
+/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
+/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
diff --git a/db-export/devrix_job_board.xml b/db-export/devrix_job_board.xml
new file mode 100644
index 0000000..5f8488a
--- /dev/null
+++ b/db-export/devrix_job_board.xml
@@ -0,0 +1,70 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!--
+- phpMyAdmin XML Dump
+- version 5.1.0
+- https://www.phpmyadmin.net
+-
+- Host: localhost
+- Generation Time: Apr 03, 2021 at 03:15 PM
+- Server version: 8.0.23
+- PHP Version: 7.4.16
+-->
+
+<pma_xml_export version="1.0" xmlns:pma="https://www.phpmyadmin.net/some_doc_url/">
+ <!--
+ - Structure schemas
+ -->
+ <pma:structure_schemas>
+ <pma:database name="devrix_job_board" collation="utf8mb4_0900_ai_ci" charset="utf8mb4">
+ <pma:table name="companies">
+ CREATE TABLE `companies` (
+ `id` int NOT NULL AUTO_INCREMENT,
+ `name` varchar(100) DEFAULT NULL,
+ PRIMARY KEY (`id`)
+ ) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
+ </pma:table>
+ <pma:table name="job_offers">
+ CREATE TABLE `job_offers` (
+ `id` int NOT NULL AUTO_INCREMENT,
+ `title` varchar(100) DEFAULT NULL,
+ `description` varchar(100) DEFAULT NULL,
+ `companyId` int DEFAULT NULL,
+ `salary` double(16,4) DEFAULT NULL,
+ PRIMARY KEY (`id`),
+ KEY `fk_companyId_companies` (`companyId`),
+ CONSTRAINT `fk_companyId_companies` FOREIGN KEY (`companyId`) REFERENCES `companies` (`id`)
+ ) ENGINE=InnoDB AUTO_INCREMENT=10 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci;
+ </pma:table>
+ </pma:database>
+ </pma:structure_schemas>
+
+ <!--
+ - Database: 'devrix_job_board'
+ -->
+ <database name="devrix_job_board">
+ <!-- Table companies -->
+ <table name="companies">
+ <column name="id">1</column>
+ <column name="name">MegaCorp</column>
+ </table>
+ <table name="companies">
+ <column name="id">2</column>
+ <column name="name">Cool INC.</column>
+ </table>
+ <!-- Table job_offers -->
+ <table name="job_offers">
+ <column name="id">1</column>
+ <column name="title">Programmer</column>
+ <column name="description">Coding</column>
+ <column name="companyId">1</column>
+ <column name="salary">2000.0000</column>
+ </table>
+ <table name="job_offers">
+ <column name="id">7</column>
+ <column name="title">Test Job</column>
+ <column name="description">Testing</column>
+ <column name="companyId">2</column>
+ <column name="salary">346.0000</column>
+ </table>
+ </database>
+</pma_xml_export> \ No newline at end of file
diff --git a/screenshots/create-offer.png b/screenshots/create-offer.png
new file mode 100644
index 0000000..31e07a4
--- /dev/null
+++ b/screenshots/create-offer.png
Binary files differ
diff --git a/screenshots/dashboard-logged-in.png b/screenshots/dashboard-logged-in.png
new file mode 100644
index 0000000..cf56610
--- /dev/null
+++ b/screenshots/dashboard-logged-in.png
Binary files differ
diff --git a/screenshots/dashboard-login.png b/screenshots/dashboard-login.png
new file mode 100644
index 0000000..fa0b16d
--- /dev/null
+++ b/screenshots/dashboard-login.png
Binary files differ
diff --git a/screenshots/edit-offer.png b/screenshots/edit-offer.png
new file mode 100644
index 0000000..8d045c7
--- /dev/null
+++ b/screenshots/edit-offer.png
Binary files differ
diff --git a/screenshots/landing-page.png b/screenshots/landing-page.png
new file mode 100644
index 0000000..0a76312
--- /dev/null
+++ b/screenshots/landing-page.png
Binary files differ
diff --git a/src/controllers/BaseController.php b/src/controllers/BaseController.php
index 2c2a647..412cf25 100644
--- a/src/controllers/BaseController.php
+++ b/src/controllers/BaseController.php
@@ -1,14 +1,18 @@
<?php
class BaseController {
+ /**
+ * Calls the get, post, put or delete static methods, depending on the server request method ($_SERVER['REQUEST_METHOD'])
+ * **By default** all requests that are not POST, PUT or DELETE execute the GET request method
+ */
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 +22,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..59c1090 100644
--- a/src/controllers/DashboardController.php
+++ b/src/controllers/DashboardController.php
@@ -12,18 +12,21 @@ 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() {
+ // Forms can only send POST or GET requests.
+ // EditOfferController doesn't have it's own URI, so we can't send a request.
+ // We also can't just invoke it, because that means manually changing the server's request method.
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..c6ac070 100644
--- a/src/controllers/DashboardLoginController.php
+++ b/src/controllers/DashboardLoginController.php
@@ -6,20 +6,23 @@ 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() {
+ // The dashboard(controller) doesn't have it's own URI (and all requests are sent in this controller), so
+ // we can't send a request directly to dashboard.
+ // This does compromise security, but for now it will have to do.
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..58b1734 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,13 +12,20 @@ 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);
+
+ // 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 */
diff --git a/src/models/DB.php b/src/models/DB.php
index 8174831..f424334 100644
--- a/src/models/DB.php
+++ b/src/models/DB.php
@@ -3,37 +3,39 @@
* 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);
}
/**
+ * Generates a foreign key string from the given parameters.
+ *
* @return string
*/
static function genFK(string $currentColumn, string $foreignTable, string $foreignColumn) {
@@ -59,24 +61,26 @@ 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}, ";
}
- $query .= "PRIMARY KEY (id), ";
+ // Create key(s) parts of query string
+ $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();
}
}
@@ -91,23 +95,23 @@ 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) {
- if (gettype($value) == "string") {
+ // In queries, strings must be surrounded in single quotes
+ if (gettype($value) == 'string')
$query .= "'{$value}', ";
- }
- else {
+ 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();
}
}
@@ -117,7 +121,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 +131,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);
@@ -145,10 +149,19 @@ 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]} = " . (gettype($values[$i+1]) == "string" ? "'{$values[$i+1]}'" : $values[$i+1]) . ", ";
+ $query .= "{$values[$i]} = ";
+
+ // In queries, strings must be surrounded in single quotes
+ if (gettype($values[$i+1]) == 'string')
+ $query .= "'{$values[$i+1]}'";
+ else
+ $query .= $values[$i+1];
+
+ $query .= ', ';
}
- $query = rtrim($query, ", ");
+ $query = rtrim($query, ', ');
$query .= " WHERE id = {$id};";
@@ -156,7 +169,7 @@ class DB {
$this->connection->exec($query);
}
catch (PDOException $e) {
- echo "[DB Exception]: " . $e->getMessage();
+ echo '[DB Exception]: ' . $e->getMessage();
}
}
@@ -170,7 +183,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..b1961d6 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>
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 . '
</div>
</div>
- <div class="job-logo">
- <div class="job-logo-box">
- <img src="https://i.imgur.com/ZbILm3F.png" alt="">
- </div>
- </div>
</li>';
}
?>