Summary Files Commits Branches @commit @diff @stats
path: root / src / controllers
diff options
context:
space:
mode:
Commitf8c1df9a9a24be0ff3811dc33e00f92bf51465ab (patch)
Author
 Kamen Mladenov <kamen.d.mladenov@protonmail.com>
2021-04-03 11:54:52 +0300
Committer
 GitHub <noreply@github.com>
2021-04-03 11:54:52 +0300
Files56dfbe9d57e3150b480928da543b3dba30e11692 /src/controllers
devrix-job-board-f8c1df9a9a24be0ff3811dc33e00f92bf51465ab.tar
devrix-job-board-f8c1df9a9a24be0ff3811dc33e00f92bf51465ab.tar.gz
devrix-job-board-f8c1df9a9a24be0ff3811dc33e00f92bf51465ab.zip
Parentaa2e361c3114b53ac7858e118454b9dfaf51ebe4 (diff)
Parentfff8c08ad7f3845eb32671292392cbf08bb738c9 (diff)
Merge pull request #1 from Syndamia/dev v0.1
Implemented main functionality
diff --git a/src/controllers/BaseController.php b/src/controllers/BaseController.php
new file mode 100644
index 0000000..2c2a647
--- /dev/null
+++ b/src/controllers/BaseController.php
@@ -0,0 +1,36 @@
+<?php
+class BaseController {
+ public static function invoke() {
+ switch ($_SERVER["REQUEST_METHOD"]) {
+ case "POST":
+ static::post();
+ break;
+ case "PUT":
+ static::put();
+ break;
+ case "DELETE":
+ static::delete();
+ break;
+ default:
+ static::get();
+ break;
+ }
+ }
+
+ protected static function get() {
+ echo "GET method not implemented!";
+ }
+
+ protected static function post() {
+
+ echo "POST method not implemented!";
+ }
+
+ protected static function put() {
+ echo "PUT method not implemented!";
+ }
+
+ protected static function delete() {
+ echo "DELETE method not implemented!";
+ }
+}
diff --git a/src/controllers/CreateOfferController.php b/src/controllers/CreateOfferController.php
new file mode 100644
index 0000000..a223463
--- /dev/null
+++ b/src/controllers/CreateOfferController.php
@@ -0,0 +1,21 @@
+<?php
+include_once('controllers/BaseController.php');
+include_once('models/Company.php');
+
+class CreateOfferController extends BaseController {
+ private static $companies;
+
+ public static function get() {
+ self::$companies = Company::getAllFromDB();
+ include 'views/create-offer.php';
+ }
+
+ public static function post() {
+ $newJobOffer = new JobOffer($_POST['title'], $_POST['description'], $_POST['company'], $_POST['salary']);
+ JobOffer::insertIntoDB($newJobOffer);
+
+ // Redirect to landing page
+ header("Location: /", TRUE, 301);
+ exit();
+ }
+}
diff --git a/src/controllers/DashboardController.php b/src/controllers/DashboardController.php
new file mode 100644
index 0000000..548f60b
--- /dev/null
+++ b/src/controllers/DashboardController.php
@@ -0,0 +1,31 @@
+<?php
+include_once('controllers/BaseController.php');
+include_once('models/JobOffer.php');
+include_once('models/Company.php');
+include_once('controllers/EditOfferController.php');
+
+class DashboardController extends BaseController {
+ public static $companies = array();
+
+ public static function get() {
+ $jobs = JobOffer::getAllFromDB();
+ foreach(Company::getAllFromDB() as $company) {
+ self::$companies[$company->id] = $company->name;
+ }
+ include "views/dashboard.php";
+ }
+
+ public static function post() {
+ switch($_POST['_method']) {
+ case "get":
+ EditOfferController::get();
+ break;
+ case "put":
+ EditOfferController::put();
+ break;
+ case "delete":
+ EditOfferController::delete();
+ break;
+ }
+ }
+}
diff --git a/src/controllers/DashboardLoginController.php b/src/controllers/DashboardLoginController.php
new file mode 100644
index 0000000..fe2009b
--- /dev/null
+++ b/src/controllers/DashboardLoginController.php
@@ -0,0 +1,25 @@
+<?php
+include_once('controllers/BaseController.php');
+include_once('controllers/DashboardController.php');
+
+class DashboardLoginController extends BaseController {
+ private static $message;
+
+ public static function get() {
+ include "views/dashboard-login.php";
+ }
+
+ public static function post() {
+ if (isset($_POST['_method'])) {
+ DashboardController::invoke();
+ }
+ else if ($_POST['username'] == "admin" && $_POST['password'] == "admin") {
+ // Load normal dashboard
+ DashboardController::get();
+ }
+ else {
+ self::$message = "Bad credentials!";
+ include "views/dashboard-login.php";
+ }
+ }
+}
diff --git a/src/controllers/EditOfferController.php b/src/controllers/EditOfferController.php
new file mode 100644
index 0000000..ae49c5b
--- /dev/null
+++ b/src/controllers/EditOfferController.php
@@ -0,0 +1,30 @@
+<?php
+include_once('controllers/BaseController.php');
+include_once('models/JobOffer.php');
+include_once('models/Company.php');
+include_once('controllers/DashboardController.php');
+
+class EditOfferController extends BaseController {
+ private static $job;
+ private static $companies;
+
+ public static function get() {
+ self::$job = JobOffer::getFromDBById($_POST['jobId']);
+ self::$companies = Company::getAllFromDB();
+ include "views/edit-offer.php";
+ }
+
+ public static function put() {
+ $newJobOffer = new JobOffer($_POST['title'], $_POST['description'], $_POST['company'], $_POST['salary']);
+ $newJobOffer->id = $_POST['id'];
+ JobOffer::updateFromDB($newJobOffer);
+
+ DashboardController::get();
+ }
+
+ public static function delete() {
+ JobOffer::deleteFromDB($_POST['jobId']);
+
+ DashboardController::get();
+ }
+}
diff --git a/src/controllers/LandingController.php b/src/controllers/LandingController.php
new file mode 100644
index 0000000..ffa8644
--- /dev/null
+++ b/src/controllers/LandingController.php
@@ -0,0 +1,16 @@
+<?php
+include_once("models/JobOffer.php");
+include_once('models/Company.php');
+include_once("controllers/BaseController.php");
+
+class LandingController extends BaseController {
+ private static $companies = array();
+
+ public static function get() {
+ $jobs = JobOffer::getAllFromDB();
+ foreach(Company::getAllFromDB() as $company) {
+ self::$companies[$company->id] = $company->name;
+ }
+ include "views/landing.php";
+ }
+}