From d08defaf65a6491f751018b8debea120d0f90df1 Mon Sep 17 00:00:00 2001 From: "mael.daim" Date: Sun, 12 Nov 2023 23:50:58 +0100 Subject: [PATCH] Added a view for the creation of a team, started the list by name action --- src/Controller/TeamController.php | 18 ++++--- src/Gateway/TeamGateway.php | 7 ++- src/Model/TeamModel.php | 13 ++++- src/Views/insertTeam.html.twig | 81 +++++++++++++++++++++++++++++++ 4 files changed, 110 insertions(+), 9 deletions(-) create mode 100644 src/Views/insertTeam.html.twig diff --git a/src/Controller/TeamController.php b/src/Controller/TeamController.php index 930fe21..65e3f25 100644 --- a/src/Controller/TeamController.php +++ b/src/Controller/TeamController.php @@ -20,16 +20,22 @@ class TeamController /* verif si les camp sont assignés, sinon erreur 400*/ public function submitTeam(array $request){ $errors = []; - if(isset($request['name']) && isset($request["picture"]) && isset($request["mainColor"]) && isset($request["secondColor"])){ - $errors = $this->model->createTeam($request['name'],$request['picture'],$request['mainColor'],$request["secondColor"]); - /*todo gestion des erreurs grace au tableau*/ + $this->model->createTeam($request['name'],$request['picture'],$request['mainColor'],$request["secondColor"],$errors); + if(!empty($errors)){ + /*todo appelle vue avec param*/ + } + } + + public function listTeamByName(array $request){ + $errors = []; + $this->model->listByName($request['name'],$errors); + if(!empty($errors)){ + /*todo appelle vue avec param*/ } else{ - http_response_code(400); - /*todo rappeler vue avec parametre pour signaler les pb */ + /*todo appelle bonne vue*/ } } - } diff --git a/src/Gateway/TeamGateway.php b/src/Gateway/TeamGateway.php index 56992d8..17462ea 100644 --- a/src/Gateway/TeamGateway.php +++ b/src/Gateway/TeamGateway.php @@ -27,7 +27,12 @@ class TeamGateway /* retourne exception par rapport à la validité du paramètr } public function listByName($name): array { - /*todo*/ + return $this->con->fetch( + "SELECT name,picture,mainColor,secondColor FROM Team WHERE name LIKE '% :thing %' ", + [ + ":thing" => [$name, PDO::PARAM_STR] + ] + ); } } \ No newline at end of file diff --git a/src/Model/TeamModel.php b/src/Model/TeamModel.php index 3158423..6815ad6 100644 --- a/src/Model/TeamModel.php +++ b/src/Model/TeamModel.php @@ -16,6 +16,7 @@ class TeamModel /* throw des exceptions(ex validation des champs, filtre etc) po public const ERROR_INVALID_NAME = 1; public const ERROR_INVALID_PICTURE = 2; public const ERROR_INVALID_SEARCH = 3; + public const ERROR_NO_DATA_FOUND = 4; private TeamGateway $gateway; @@ -49,9 +50,17 @@ class TeamModel /* throw des exceptions(ex validation des champs, filtre etc) po } - public function list(string $search,array $errors):array { - if(Validation::hasHTMLInjection($search)){ + public function listByName(string $name,array $errors):?array { + if(Validation::hasHTMLInjection($name)){ $errors = self::ERROR_INVALID_SEARCH; } + $results = $this->gateway->listByName($name); + if(empty($results)){ + $errors = self::ERROR_NO_DATA_FOUND; + } + if(!empty($errors)){ + return $results; + } + return null; } } \ No newline at end of file diff --git a/src/Views/insertTeam.html.twig b/src/Views/insertTeam.html.twig new file mode 100644 index 0000000..62f6553 --- /dev/null +++ b/src/Views/insertTeam.html.twig @@ -0,0 +1,81 @@ + + + + + Insertion view + + + + + + + +
+

Créer une équipe

+
+
+ + + + + + + + +
+
+ +
+
+
+ + + \ No newline at end of file