diff --git a/Config/Autoload.php b/Config/Autoload.php index 6f2118a8..4f0d043b 100644 --- a/Config/Autoload.php +++ b/Config/Autoload.php @@ -4,6 +4,9 @@ class Autoload { private static $_instance = null; + /** + * If the class is not already loaded, then load it. + */ public static function charger() { if(null !== self::$_instance) { @@ -18,6 +21,9 @@ class Autoload } } + /** + * If the instance is not null, unregister the autoload function and set the instance to null. + */ public static function shutDown() { if(null !== self::$_instance) { @@ -30,6 +36,11 @@ class Autoload } } + /** + * If the file exists, include it + * + * @param class The name of the class to load. + */ private static function _autoload($class) { global $rep; diff --git a/Config/Connection.php b/Config/Connection.php index a8561e0b..6b1e9241 100644 --- a/Config/Connection.php +++ b/Config/Connection.php @@ -3,12 +3,29 @@ class Connection extends SQLite3 { private $stmt; private $result; + + /** + * The function __construct() is a constructor function that takes a parameter and calls the + * open() function with the parameter + * + * @param dsn The Data Source Name, or DSN, contains the information required to connect to the + * database. + */ function __construct($dsn) { $this->open($dsn); $this->enableExceptions(true); } + /** + * It takes a query and an array of parameters, binds the parameters to the query, and executes the + * query + * + * @param string query The query to execute. + * @param array parameters + * + * @return bool The result of the query. + */ public function executeQuery(string $query, array $parameters = []): bool { $this->stmt = parent::prepare($query); @@ -25,6 +42,12 @@ class Connection extends SQLite3 } } + + /** + * It takes the result of a query and returns an array of arrays + * + * @return array An array of arrays. + */ public function getResults(): array { $resultArray = $this->result->fetchArray(SQLITE3_ASSOC); diff --git a/Config/Nettoyage.php b/Config/Nettoyage.php index 8f85c7fb..3778a674 100644 --- a/Config/Nettoyage.php +++ b/Config/Nettoyage.php @@ -1,19 +1,28 @@ clean($input); $output = filter_var($output, FILTER_SANITIZE_EMAIL); return $output; diff --git a/Config/Validation.php b/Config/Validation.php index d5896884..45edef55 100644 --- a/Config/Validation.php +++ b/Config/Validation.php @@ -2,6 +2,11 @@ class Validation { + /** + * If the variable is set, return true, otherwise return false. + * + * @param var The variable you want to check if it's set. + */ public function ValidateSet($var) :bool{ if (isset($var)) { return true; @@ -9,6 +14,11 @@ class Validation return false; } + /** + * If the variable is empty, return false. Otherwise, return true. + * + * @param var The variable to be validated. + */ public function ValidateNotEmpty($var) :bool{ if (empty($var)) { return false; @@ -16,6 +26,13 @@ class Validation return true; } + /** + * If the URL is not a valid URL, return false. Otherwise, return true. + * + * @param string url The URL to be validated. + * + * @return bool A boolean value. + */ public function ValidateURL(string $url) :bool{ if (!preg_match("/\b(?:(?:https?|ftp):\/\/|www\.)[-a-z0-9+&@#\/%?=~_|!:,.;]*[-a-z0-9+&@#\/%=~_|]/i",$url)) { return false; @@ -23,12 +40,27 @@ class Validation return true; } + /** + * It checks if the email is valid. + * + * @param string email The email address to validate. + * + * @return bool A boolean value. + */ public function ValidateEmail(string $email) :bool{ if (!filter_var($email, FILTER_VALIDATE_EMAIL)) { return false; } return true; } + + /** + * It returns true if the username is valid, and false if it isn't. + * + * @param string username The username to validate. + * + * @return bool A boolean value. + */ public function ValidateUsername(string $username) : bool{ // if(!filter_var($username,FILTER_VALIDATE_REGEXP,array("options" => array( "regexp" => "^[^&=_'\-+;<>.]{1,18}$" )))) @@ -37,6 +69,14 @@ class Validation // } return true; } + + /** + * If the password is longer than 100 characters, return false. Otherwise, return true. + * + * @param string password The password to validate. + * + * @return bool A boolean value. + */ public function ValidatePassword(string $password) : bool{ if(strlen($password)>100) { @@ -44,6 +84,23 @@ class Validation } return true; } + + /** + * It checks if the length of the strings are less than 250 characters and if the resolution time + * and points are positive + * + * @param string name The name of the enigma + * @param string statement The statement of the enigma + * @param string help Help text for the enigma + * @param string reminder a reminder of the enigma + * @param string example + * @param string solution The solution to the enigma + * @param string test the test to be run on the solution + * @param string resolutionTime the time it takes to solve the enigma + * @param int points + * + * @return bool a boolean value. + */ public function ValidateEnigme(string $name,string $statement,string $help,string $reminder,string $example,string $solution,string $test, string $resolutionTime, int $points) : bool{ if(strlen($name)>50 || strlen($statement) > 250 || strlen($help) > 250 || strlen($reminder) > 250 || strlen($example) > 250 || strlen($solution) > 250 || strlen($test) > 250 || $resolutionTime < 0 || $points < 0) return false; diff --git a/Controller/AdminController.php b/Controller/AdminController.php index 4c6c6328..ab37dc1b 100644 --- a/Controller/AdminController.php +++ b/Controller/AdminController.php @@ -145,6 +145,10 @@ class AdminController extends UserController } } + /** + * It gets the enigme from the database and displays it + * in the enigme page. + */ public function goToEnigme() { try { @@ -162,6 +166,11 @@ class AdminController extends UserController } } + /** + * It gets the enigmas from the database and sorts them by their order + * and displays them in the admin page. + * + */ public function goToAdmin() { try { @@ -178,6 +187,7 @@ class AdminController extends UserController require($rep . $vues['erreur']); } } + public function goToAddEnigmeSolo() { try { @@ -188,6 +198,7 @@ class AdminController extends UserController require($rep . $vues['erreur']); } } + public function goToAddEnigmeMulti(){ try { global $rep, $vues; @@ -291,6 +302,10 @@ class AdminController extends UserController require($rep . $vues['erreur']); } } + /** + * When the user clicks on the button, the function enigmeEnded() is called, which will display the + * next enigma. + */ public function enigmeEnded(){ try{ global $rep, $vues; @@ -303,6 +318,7 @@ class AdminController extends UserController require($rep . $vues['erreur']); } } + public function editEnigme() { try{ @@ -336,6 +352,7 @@ class AdminController extends UserController require($rep . $vues['erreur']); } } + public function deleteEnigme(){ try{ global $rep, $vues; @@ -437,6 +454,7 @@ class AdminController extends UserController require($rep . $vues['erreur']); } } + public function report(){ try{ global $rep, $vues; diff --git a/Controller/EnigmeGateway.php b/Controller/EnigmeGateway.php index d071859f..a6ae2da7 100644 --- a/Controller/EnigmeGateway.php +++ b/Controller/EnigmeGateway.php @@ -107,7 +107,8 @@ class EnigmeGateway * * @return array of objects. */ - public function findSoloEnigma(){ + public function findSoloEnigma() : array + { $query = "SELECT * FROM Enigme WHERE points IS NULL OR points = 0"; $this->con->executeQuery($query); @@ -115,7 +116,7 @@ class EnigmeGateway return $tabEnigme; } - public function findEnigmaFromPartie(string $idPartie){ + public function findEnigmaFromPartie(string $idPartie) : array{ $query = "SELECT * FROM Enigme e, Contenir c WHERE c.partie=:idPartie"; $this->con->executeQuery($query, array( diff --git a/Controller/PartieGateway.php b/Controller/PartieGateway.php index 44dbb40a..c1c803a7 100644 --- a/Controller/PartieGateway.php +++ b/Controller/PartieGateway.php @@ -47,7 +47,7 @@ class PartieGateway return $partie; } - public function findPartieInQueue() + public function findPartieInQueue() : int { $query = "SELECT partie FROM Participer @@ -61,7 +61,7 @@ class PartieGateway return $results[0]['partie']; } - public function creerPartieSolo(Utilisateur $utilisateur) + public function creerPartieSolo(Utilisateur $utilisateur) { $query = "SELECT * FROM Enigme WHERE points IS NULL OR points = 0"; @@ -269,7 +269,7 @@ class PartieGateway $row = $results[0]; return $row['count(*)']; } - public function getEtat($idPartie){ + public function getEtat($idPartie) : int{ $query = "SELECT etat FROM Participer WHERE partie = :idPartie"; $this->con->executeQuery($query, array( "idPartie" => array($idPartie, SQLITE3_INTEGER) @@ -287,7 +287,7 @@ class PartieGateway return 0; } - public function getLesMailJoueurs($idPartie){ + public function getLesMailJoueurs($idPartie) : array{ $query = "SELECT utilisateur FROM Participer WHERE partie = :idPartie"; $this->con->executeQuery($query, array( "idPartie" => array($idPartie, SQLITE3_INTEGER) @@ -300,7 +300,7 @@ class PartieGateway } return $lesJoueurs; } - public function getLesIdEnigmes($idPartie){ + public function getLesIdEnigmes($idPartie) : array{ $query = "SELECT enigme FROM Contenir WHERE partie = :idPartie"; $this->con->executeQuery($query, array( "idPartie" => array($idPartie, SQLITE3_INTEGER) @@ -349,6 +349,11 @@ class PartieGateway $date = new DateTime ($results[0]['dateDebut']); return $date; } + /** + * It updates the state of a game to 2 (ended) in the database + * + * @param int idPartie the id of the game + */ public function endGame(int $idPartie){ $query = "UPDATE Participer SET etat = 2 WHERE partie = :idPartie"; $this->con->executeQuery($query, array( @@ -356,6 +361,11 @@ class PartieGateway ) ); } + /** + * It updates the state of a game from 0 to 1. + * + * @param int idPartie the id of the game + */ public function launchGame(int $idPartie){ $query = "UPDATE Participer SET etat=1 WHERE etat=0 AND partie=:partie"; $this->con->executeQuery($query,array( @@ -373,6 +383,11 @@ class PartieGateway } return true; } + /** + * It updates the dateDebut column of the Partie table with the current date and time. + * + * @param int idPartie + */ public function majDateDebut(int $idPartie){ $query = "UPDATE Partie SET dateDebut = :dateDebut WHERE id = :idPartie"; $this->con->executeQuery($query, array( @@ -381,6 +396,7 @@ class PartieGateway ) ); } + public function quitQueue(string $mailUtilisateur,int $idPartie){ $query = "DELETE FROM Participer WHERE utilisateur = :mailUtilisateur diff --git a/Controller/ResoudreGateway.php b/Controller/ResoudreGateway.php index e5c1b502..a4a58de9 100644 --- a/Controller/ResoudreGateway.php +++ b/Controller/ResoudreGateway.php @@ -127,7 +127,7 @@ class ResoudreGateway "ended" => array($ended, SQLITE3_INTEGER))); } } - public function checkEnigmeIsEnded(string $mailUtilisateur, int $enigmeId){ + public function checkEnigmeIsEnded(string $mailUtilisateur, int $enigmeId) : bool{ $query="SELECT * FROM Resoudre WHERE utilisateur=:utilisateur AND enigme=:enigme"; @@ -144,7 +144,7 @@ class ResoudreGateway return $results[0]['ended']; } } - public function checkEnigmeIsEndedInPartie(string $mailUtilisateur, int $enigmeId, int $idPartie){ + public function checkEnigmeIsEndedInPartie(string $mailUtilisateur, int $enigmeId, int $idPartie) : bool{ $query="SELECT * FROM Resoudre WHERE utilisateur=:utilisateur AND enigme=:enigme diff --git a/Controller/UserController.php b/Controller/UserController.php index ecf0c7a1..f86fa7bc 100644 --- a/Controller/UserController.php +++ b/Controller/UserController.php @@ -384,8 +384,7 @@ class UserController require($rep . $vues['erreur']); } } - - // A appeler après avoir vérifié que la partie est finie + public function endGame(){ try { global $rep, $vues, $error; diff --git a/Controller/UtilisateurGateway.php b/Controller/UtilisateurGateway.php index 6647a576..9ab95fc9 100644 --- a/Controller/UtilisateurGateway.php +++ b/Controller/UtilisateurGateway.php @@ -139,7 +139,7 @@ class UtilisateurGateway return true; } - public function queueFilled(){ + public function queueFilled() : bool{ $query = "SELECT count(*) FROM Participer WHERE etat=0"; $this->con->executeQuery($query); if ($this->con->getResults()[0]['count(*)'] >= 2) diff --git a/Factory/EnigmeFactory.php b/Factory/EnigmeFactory.php index cb0d3b2e..73e36b93 100644 --- a/Factory/EnigmeFactory.php +++ b/Factory/EnigmeFactory.php @@ -1,6 +1,6 @@ \ No newline at end of file