diff options
Merge pull request #1 from Syndamia/dev v0.1
Implemented main functionality
6 files changed, 159 insertions, 0 deletions
| -rw-r--r-- | src/controllers/BaseController.php | 36 | ||||
| -rw-r--r-- | src/controllers/CreateOfferController.php | 21 | ||||
| -rw-r--r-- | src/controllers/DashboardController.php | 31 | ||||
| -rw-r--r-- | src/controllers/DashboardLoginController.php | 25 | ||||
| -rw-r--r-- | src/controllers/EditOfferController.php | 30 | ||||
| -rw-r--r-- | src/controllers/LandingController.php | 16 |
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"; + } +} |
