Skip to content

Commit

Permalink
Merge pull request #46 from CPNV-ES/develop
Browse files Browse the repository at this point in the history
Release 1.0.1
  • Loading branch information
EthannSchneider authored Dec 18, 2024
2 parents 0d00572 + 9b2ce11 commit 537c24d
Show file tree
Hide file tree
Showing 34 changed files with 940 additions and 18 deletions.
31 changes: 31 additions & 0 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the
// README at: https://github.com/devcontainers/templates/tree/main/src/php
{
"name": "PHP",
// Or use a Dockerfile or Docker Compose file. More info: https://containers.dev/guide/dockerfile
"image": "mcr.microsoft.com/devcontainers/php:1-8.2-bullseye",

// Features to add to the dev container. More info: https://containers.dev/features.
// "features": {},

// Configure tool-specific properties.
// "customizations": {},

// Use 'forwardPorts' to make a list of ports inside the container available locally.
"forwardPorts": [
8080
],
"customizations": {
"vscode": {
"extensions": [
"rexshi.phpdoc-comment-vscode-plugin"
]
}
}

// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "sudo chmod a+x \"$(pwd)\" && sudo rm -rf /var/www/html && sudo ln -s \"$(pwd)\" /var/www/html"

// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
// "remoteUser": "root"
}
12 changes: 12 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# To get started with Dependabot version updates, you'll need to specify which
# package ecosystems to update and where the package manifests are located.
# Please see the documentation for more information:
# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates
# https://containers.dev/guide/dependabot

version: 2
updates:
- package-ecosystem: "devcontainers"
directory: "/"
schedule:
interval: weekly
File renamed without changes
Binary file added docs/looper_mcd.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/looper_mld.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions public/index.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<?php

/**
* @author Ethann Schneider, Guillaume Aubert, Jomana Kaempf
* @version 29.11.2024
* @description entry point of the application
*/

session_start();

define('BASE_DIR', dirname(__FILE__) . '/..');
Expand Down
27 changes: 16 additions & 11 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,20 @@ This is a project for the MAW11 course. We're supposed to rewrite [this website]
* Composer 2.7.8

### Configuration

Make `.env` file
and put the
```env
POSTGRES_USER=admin
POSTGRES_PASSWORD=mysecretpassword
[email protected]
PGADMIN_DEFAULT_PASSWORD=admin
```
or copy `.env.example`
Before starting the docker environment, you need to follow the following steps:
You need to setup the `.env` file.
Copy the `.env.example` file and change the environment variables content.

## Deployment

You need to install composer requirements :
`composer install`

Now you can start the docker stack.

If you want xdebug and phpmyadmin, use the dev environment. If you dont need them, use the production environment.


### On dev environment
#### Docker

Expand All @@ -39,12 +41,15 @@ docker-compose up
php -S localhost:8000 -t public
```

### On integration environment
### On prod environment

```bash
docker-compose -f docker-compose-prod.yml up
```

The application will be available at [127.0.0.1:8080](http://127.0.0.1:8080)


## Directory structure

```shell
Expand Down
41 changes: 41 additions & 0 deletions src/controllers/error.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,66 @@
<?php

/**
* @author Ethann Schneider, Guillaume Aubert, Jomana Kaempf
* @version 29.11.2024
* @description This file contains functions to handle various error responses such as 404 Not Found
*/

/**
* Send a 404 Not Found error page.
*
* @param int $return_code The HTTP response code to send. Default is 404.
* @param string $error_message The error message to display. Default is 'Page not found'.
* @return void
*/
function lost($return_code = 404, $error_message = 'Page not found')
{
include VIEW_DIR . '/errors/error.php';
}

/**
* Send a generic error with a specified return code and message.
*
* @param int $return_code The HTTP response code to send.
* @param string $error_message The error message to display.
* @return void
*/
function error($return_code, $error_message)
{
include VIEW_DIR . '/errors/error.php';
}

/**
* Send a 400 Bad Request error page.
*
* @param int $return_code The HTTP response code to send. Default is 400.
* @param string $error_message The error message to display. Default is 'Bad Request'.
* @return void
*/
function badRequest($return_code = 400, $error_message = 'Bad Request')
{
include VIEW_DIR . '/errors/error.php';
}

/**
* Send a 401 Unauthorized error page.
*
* @param int $return_code The HTTP response code to send. Default is 401.
* @param string $error_message The error message to display. Default is 'Unauthorized'.
* @return void
*/
function unauthorized($return_code = 401, $error_message = 'Unauthorized')
{
include VIEW_DIR . '/errors/error.php';
}

/**
* Send a 500 Internal Server Error page.
*
* @param int $return_code The HTTP response code to send. Default is 500.
* @param string $error_message The error message to display. Default is 'Server Error'.
* @return void
*/
function serverError($return_code = 500, $error_message = 'Server Error')
{
include VIEW_DIR . '/errors/error.php';
Expand Down
29 changes: 29 additions & 0 deletions src/controllers/exercise_controller.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
<?php

/**
* @author Ethann Schneider, Guillaume Aubert, Jomana Kaempf
* @version 29.11.2024
* @description This file is for the excercise controller without the view
*/

include_once MODEL_DIR . '/exercise.php';

/**
* Class ExerciseController
*
* Manages the backend operations for exercises, including creation, deletion, and state transitions.
*/
class ExerciseController
{
/**
* This method creates a new exercise based on the title provided by the user via `$_POST['exercise_title']`.
*
* @return void
*/
public function createExercise()
{
if (!isset($_POST['exercise_title'])) {
Expand All @@ -15,6 +31,13 @@ public function createExercise()
header('Location: /exercises/' . $exercise->getId() . '/fields');
}

/**
* This method deletes an exercise identified by `$id`. It only allows deletion if the exercise
* is in the `Building` or `Closed` state.
*
* @param int $id The ID of the exercise to be deleted.
* @return void
*/
public function deleteExercise(int $id)
{
$exercise = new Exercise($id);
Expand All @@ -25,6 +48,12 @@ public function deleteExercise(int $id)
header('Location: /exercises');
}

/**
* This method changes the state of an exercise identified by `$id`.
*
* @param int $id The ID of the exercise whose state is to be changed.
* @return void
*/
public function changeStateOfExercise(int $id)
{
if (!isset($_GET['exercise']['status'])) {
Expand Down
40 changes: 40 additions & 0 deletions src/controllers/field_controller.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,27 @@
<?php

/**
* @author Ethann Schneider, Guillaume Aubert, Jomana Kaempf
* @version 29.11.2024
* @description This file is for the field controller without the View
*/

require_once MODEL_DIR . '/exercise.php';

/**
* FieldController
*
* Handles backend logic for managing fields in exercises.
*/
class FieldController
{
/**
* This method creates a new field within an existing exercise, using the label and value kind
* provided by the user in `$_POST['field']`.
*
* @param int $exercise_id The ID of the exercise for which the field is being created.
* @return void
*/
public function createField(int $exercise_id)
{
if (!isset($_POST['field']['label'], $_POST['field']['value_kind'])) {
Expand All @@ -22,6 +40,13 @@ public function createField(int $exercise_id)
header('Location: /exercises/' . $exercise_id . '/fields');
}

/**
* This method deletes a field identified by `$field_id` from an exercise identified by `$exercise_id`.
*
* @param int $exercise_id The ID of the exercise from which the field is to be deleted.
* @param int $field_id The ID of the field that is to be deleted.
* @return void
*/
public function deleteField(int $exercise_id, int $field_id)
{
$exercise = null;
Expand All @@ -36,6 +61,13 @@ public function deleteField(int $exercise_id, int $field_id)
header('Location: /exercises/' . $exercise_id . '/fields');
}

/**
* This method allows the editing of an existing field for a given exercise.
*
* @param int $exercise_id The ID of the exercise containing the field.
* @param int $field_id The ID of the field to be edited.
* @return void
*/
public function editField(int $exercise_id, int $field_id)
{
$exercise = new Exercise($exercise_id);
Expand All @@ -57,6 +89,14 @@ public function editField(int $exercise_id, int $field_id)
header('Location: /exercises/' . $exercise_id . '/fields/' . $field_id . '/edit');
}

/**
* This method converts a string representation of a field kind to the corresponding enumeration value.
* It handles different kinds, such as `single_line_list`, `multi_line`, and `single_line`, and returns
* the appropriate enumeration.
*
* @param string $kind The kind of the field as a string.
* @return Kind The corresponding `Kind` enumeration value.
*/
private function kindStringToKindEnum(string $kind)
{
switch ($kind) {
Expand Down
25 changes: 25 additions & 0 deletions src/controllers/fulfillment_controller.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,25 @@
<?php

/**
* @author Ethann Schneider, Guillaume Aubert, Jomana Kaempf
* @version 29.11.2024
* @description This file contains the fulfillment controller, which handles fulfillment actions.
*/

include_once MODEL_DIR . '/exercise.php';

/**
* FulfillmentController
* This controller class handles actions related to the creation and editing of fulfillments.
*/
class FulfillmentController
{
/**
* Create a fulfillment
* This method handles the creation of a fulfillment for a specific exercise, identified by `$exercise_id`.
* @param int $exercise_id The ID of the exercise for which a new fulfillment is being created.
* @return void This function performs creation and redirects, but does not return a value.
*/
public function createFulfillment(int $exercise_id)
{
if (!isset($_POST['fulfillment']['answers_attributes'])) {
Expand Down Expand Up @@ -34,6 +50,15 @@ public function createFulfillment(int $exercise_id)
header('Location: /exercises/' . $exercise->getId() . '/fulfillments/' . $fulfillment->getId() . '/edit');
}

/**
* Edit a fulfillment
* This method handles the editing of an existing fulfillment, identified by `$fulfillment_id`,
* for a specific exercise, identified by `$exercise_id`.
*
* @param int $exercise_id The ID of the exercise associated with the fulfillment.
* @param int $fulfillment_id The ID of the fulfillment that is being edited.
* @return void This function updates the fulfillment and redirects, without returning a value.
*/
public function editFulfillment(int $exercise_id, int $fulfillment_id)
{
if (!isset($_POST['fulfillment']['answers_attributes'])) {
Expand Down
Loading

0 comments on commit 537c24d

Please sign in to comment.