-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #39 from CPNV-ES/release/1.0.0
Release/1.0.0
- Loading branch information
Showing
31 changed files
with
723 additions
and
230 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
FROM php:8.3.11-fpm | ||
RUN apt-get update && apt-get install -y libpq-dev && docker-php-ext-install pdo pdo_pgsql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,26 @@ | ||
<?php | ||
|
||
function lost() | ||
function lost($return_code = 404, $error_message = 'Page not found') | ||
{ | ||
include VIEW_DIR . '/errors/lost.php'; | ||
include VIEW_DIR . '/errors/error.php'; | ||
} | ||
|
||
function badRequest() | ||
function error($return_code, $error_message) | ||
{ | ||
include VIEW_DIR . '/errors/bad_request.php'; | ||
include VIEW_DIR . '/errors/error.php'; | ||
} | ||
|
||
function serverError(string $console_log = '') | ||
function badRequest($return_code = 400, $error_message = 'Bad Request') | ||
{ | ||
include VIEW_DIR . '/errors/server_error.php'; | ||
include VIEW_DIR . '/errors/error.php'; | ||
} | ||
|
||
function unauthorized($return_code = 401, $error_message = 'Unauthorized') | ||
{ | ||
include VIEW_DIR . '/errors/error.php'; | ||
} | ||
|
||
function serverError($return_code = 500, $error_message = 'Server Error') | ||
{ | ||
include VIEW_DIR . '/errors/error.php'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
<?php | ||
|
||
include_once MODEL_DIR . '/exercise.php'; | ||
|
||
class FulfillmentController | ||
{ | ||
public function createFulfillment(int $exercise_id) | ||
{ | ||
if (!isset($_POST['fulfillment']['answers_attributes'])) { | ||
badRequest(); | ||
return; | ||
} | ||
|
||
$exercise = new Exercise($exercise_id); | ||
|
||
$fields = $exercise->getFields(); | ||
|
||
foreach ($_POST['fulfillment']['answers_attributes'] as $answers_attribute) { | ||
if (!isset($answers_attribute['field_id'], $answers_attribute['value'])) { | ||
badRequest(); | ||
return; | ||
} | ||
if (!$exercise->isFieldInExercise(new Field($answers_attribute['field_id']))) { | ||
badRequest(); | ||
return; | ||
} | ||
} | ||
$fulfillment = $exercise->createFulfillment(); | ||
|
||
foreach ($fields as $field) { | ||
$fulfillment->createFields($field, $_POST['fulfillment']['answers_attributes'][$field->getId()]['value']); | ||
} | ||
|
||
header('Location: /exercises/' . $exercise->getId() . '/fulfillments/' . $fulfillment->getId() . '/edit'); | ||
} | ||
|
||
public function editFulfillment(int $exercise_id, int $fulfillment_id) | ||
{ | ||
if (!isset($_POST['fulfillment']['answers_attributes'])) { | ||
badRequest(); | ||
return; | ||
} | ||
|
||
$exercise = new Exercise($exercise_id); | ||
|
||
$fulfillment = new Fulfillment($fulfillment_id); | ||
|
||
foreach ($_POST['fulfillment']['answers_attributes'] as $answers_attribute) { | ||
if (!isset($answers_attribute['field_id'], $answers_attribute['value'])) { | ||
badRequest(); | ||
return; | ||
} | ||
|
||
$fulfillment_data = new FulfillmentField($answers_attribute['field_id'], $fulfillment_id); | ||
|
||
$fulfillment_data->setBody($answers_attribute['value']); | ||
} | ||
|
||
header('Location: /exercises/' . $exercise->getId() . '/fulfillments/' . $fulfillment->getId() . '/edit'); | ||
} | ||
} |
Oops, something went wrong.