diff options
Implemented get, put and delete requests for edit offer controller; Implemented edit-offer view
3 files changed, 50 insertions, 2 deletions
| -rw-r--r-- | src/controllers/EditOfferController.php | 25 | ||||
| -rw-r--r-- | src/views/dashboard.php | 2 | ||||
| -rw-r--r-- | src/views/edit-offer.php | 25 |
diff --git a/src/controllers/EditOfferController.php b/src/controllers/EditOfferController.php index 950b6dc..ae49c5b 100644 --- a/src/controllers/EditOfferController.php +++ b/src/controllers/EditOfferController.php @@ -1,5 +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/views/dashboard.php b/src/views/dashboard.php index b1b648c..2312419 100644 --- a/src/views/dashboard.php +++ b/src/views/dashboard.php @@ -2,7 +2,7 @@ foreach($jobs as $job) { echo "{$job->id} {$job->title} <form method=\"post\"> - <input type=\"hidden\" name=\"_method\" value=\"put\"> + <input type=\"hidden\" name=\"_method\" value=\"get\"> <input type=\"hidden\" name=\"jobId\" value=\"{$job->id}\"> <input type=\"submit\" value=\"Edit\"> </form> diff --git a/src/views/edit-offer.php b/src/views/edit-offer.php index 957fc3d..b9fb464 100644 --- a/src/views/edit-offer.php +++ b/src/views/edit-offer.php @@ -1 +1,24 @@ -<p>Works!</p> +<form method="post"> + <input type="hidden" name="id" value="<?php echo self::$job->id?>"> + <label for="title">Job Title: </label> + <input type="text" name="title" value="<?php echo self::$job->title ?>"> + <br> + <label for="description">Job Description: </label> + <textarea type="text" name="description"><?php echo self::$job->description ?></textarea> + <br> + <label for="company">Company: </label> + <select name="company" selected="<?php echo self::$job->companyId ?>"> + <?php + foreach(self::$companies as $company) { + echo "<option value=\"{$company->id}\""; + echo (self::$job->companyId == $company->id ? "selected" : "") . ">{$company->name}</option>"; + } + ?> + </select> + <br> + <label for="salary">Salary: </label> + <input type="number" name="salary" min="1" placeholder="1" value="<?php echo self::$job->salary ?>"> + <br> + <input type="hidden" name="_method" value="put"> + <input type="submit" value="Update"> +</form> |
