From fa81bd070295f38313495704be6afeebb1ea6191 Mon Sep 17 00:00:00 2001 From: "vivien.dufour" Date: Tue, 9 Jan 2024 10:21:44 +0100 Subject: [PATCH] conflicts --- front/views/Home.tsx | 17 +++---- public/index.php | 11 +++++ sql/setup-tables.sql | 16 +++++++ src/App/Controller/TacticController.php | 44 +++++++++++++++++++ src/App/Controller/TeamController.php | 6 +++ .../display_share_confirmation.html.twig | 31 +++++++++++++ src/App/Views/display_tactic.html.twig | 19 ++++++++ src/App/Views/display_user_teams.html.twig | 21 +++++++++ src/Core/Gateway/TacticInfoGateway.php | 28 ++++++++++++ src/Core/Gateway/TeamGateway.php | 12 +++++ src/Core/Model/TacticModel.php | 13 ++++++ src/Core/Model/TeamModel.php | 7 +++ 12 files changed, 217 insertions(+), 8 deletions(-) create mode 100644 src/App/Controller/TacticController.php create mode 100644 src/App/Views/display_share_confirmation.html.twig create mode 100644 src/App/Views/display_tactic.html.twig create mode 100644 src/App/Views/display_user_teams.html.twig diff --git a/front/views/Home.tsx b/front/views/Home.tsx index a9a4b0a..132457c 100644 --- a/front/views/Home.tsx +++ b/front/views/Home.tsx @@ -74,14 +74,15 @@ function SideMenu({ teams: Team[] }) { return ( -
-
- - +
+
+ + +
{location.pathname="/shareTactic"}}> +

Partager une tactique

+
) diff --git a/public/index.php b/public/index.php index 82dd37f..3e1a9d3 100644 --- a/public/index.php +++ b/public/index.php @@ -12,6 +12,7 @@ use IQBall\App\Controller\EditorController; use IQBall\App\Controller\TeamController; use IQBall\App\Controller\UserController; use IQBall\App\Controller\VisualizerController; +use IQBall\App\Controller\TacticController; use IQBall\App\Session\MutableSessionHandle; use IQBall\App\Session\PhpSessionHandle; use IQBall\App\Session\SessionHandle; @@ -54,6 +55,11 @@ function getTeamController(): TeamController { return new TeamController(new TeamModel(new TeamGateway($con), new MemberGateway($con), new AccountGateway($con))); } +function getTacticController(): TacticController { + return new TacticController(new TacticModel(new TacticInfoGateway(getConnection())), new TeamModel( new TeamGateway(getConnection()), new MemberGateway(getConnection()), new AccountGateway(getConnection()))); +} + + function getAuthController(): AuthController { return new AuthController(new AuthModel(new AccountGateway(getConnection()))); } @@ -86,6 +92,11 @@ function getRoutes(): AltoRouter { $ar->map("GET", "/settings", Action::auth(fn(SessionHandle $s) => getUserController()->settings($s))); $ar->map("GET", "/disconnect", Action::auth(fn(MutableSessionHandle $s) => getUserController()->disconnect($s))); + $ar->map("GET", "/shareTactic", Action::auth(fn(SessionHandle $s) => getTacticController()->displayTactic($s))); + $ar->map("GET", "/shareTactic/[i:id]", Action::auth(fn(int $id, SessionHandle $s) => getTacticController()->displayTeam($id, $s))); + $ar->map("GET", "/shareTactic/[i:id]/team/[i:idTeam]", Action::auth(fn(int $tacticId, int $teamId, SessionHandle $s) => getTacticController()->displayShareConfirmation($tacticId, $teamId, $s))); + $ar->map("POST", "/shareTactic/[i:id]/team/[i:idTeam]", Action::auth(fn(int $tacticId, int $teamId, SessionHandle $s) => getTacticController()->shareTacticToTeam($_POST, $tacticId, $teamId, $s))); + //tactic-related $ar->map("GET", "/tactic/[i:id]/view", Action::auth(fn(int $id, SessionHandle $s) => getVisualizerController()->openVisualizer($id, $s))); diff --git a/sql/setup-tables.sql b/sql/setup-tables.sql index 0d157d9..7013600 100644 --- a/sql/setup-tables.sql +++ b/sql/setup-tables.sql @@ -50,3 +50,19 @@ CREATE TABLE Member FOREIGN KEY (id_team) REFERENCES Team (id), FOREIGN KEY (id_user) REFERENCES Account (id) ); + +CREATE TABLE TacticSharedTeam +( + id_team integer NOT NULL, + id_tactic integer NOT NULL, + FOREIGN KEY (id_team) REFERENCES Team (id), + FOREIGN KEY (id_tactic) REFERENCES Tactic (id) +); + +CREATE TABLE TacticSharedAccount +( + id_account integer NOT NULL, + id_tactic integer NOT NULL, + FOREIGN KEY (id_account) REFERENCES Account (id), + FOREIGN KEY (id_tactic) REFERENCES Tactic (id) +); \ No newline at end of file diff --git a/src/App/Controller/TacticController.php b/src/App/Controller/TacticController.php new file mode 100644 index 0000000..f154ed5 --- /dev/null +++ b/src/App/Controller/TacticController.php @@ -0,0 +1,44 @@ +tactics = $tactics; + $this->teams = $teams; + } + + public function displayTactic(SessionHandle $session): ViewHttpResponse { + $results = $this->tactics->getAll($session->getAccount()->getId()); + return ViewHttpResponse::twig("display_tactic.html.twig", ['tactics' => $results]); + } + + public function displayTeam(int $tacticId, SessionHandle $session): ViewHttpResponse { + $results = $this->teams->getAll($session->getAccount()->getId()); + return ViewHttpResponse::twig("display_user_teams.html.twig", ['teams' => $results, 'tactic' => $tacticId]); + } + + public function displayShareConfirmation(int $tacticId, int $teamId, SessionHandle $session) : ViewHttpResponse { + $team = $this->teams->getTeam($teamId); + $tactic = $this->tactics->get($tacticId); + return ViewHttpResponse::twig("display_share_confirmation.html.twig", ['team' => $teamId, 'tactic' => $tacticId]); + } + + public function shareTacticToTeam(array $confirmation, int $tacticId, int $teamId, SessionHandle $session) : \IQBall\Core\Http\HttpResponse + { + if($confirmation['confirmation'] == "no") { + return ViewHttpResponse::redirect("/"); + } + $this->teams->shareTacticToTeam($teamId, $tacticId); + return ViewHttpResponse::redirect("/"); + } +} diff --git a/src/App/Controller/TeamController.php b/src/App/Controller/TeamController.php index 4ab3fd7..174c971 100644 --- a/src/App/Controller/TeamController.php +++ b/src/App/Controller/TeamController.php @@ -243,4 +243,10 @@ class TeamController { $this->model->editTeam($idTeam, $request['name'], $request['picture'], $request['main_color'], $request['second_color']); return HttpResponse::redirect('/team/' . $idTeam); } + + + public function shareTactic(int $teamId, int $tacticId, SessionHandle $session): ViewHttpResponse { + $result = $this->model->shareTacticToTeam($teamId, $tacticId); + return $this->displayTeam($teamId, $session); + } } diff --git a/src/App/Views/display_share_confirmation.html.twig b/src/App/Views/display_share_confirmation.html.twig new file mode 100644 index 0000000..a2bfbf9 --- /dev/null +++ b/src/App/Views/display_share_confirmation.html.twig @@ -0,0 +1,31 @@ + + + + + Confirmation + + + + +
+ +

Etes-vous sûr de vouloir partager la tactique ?

+ +
+
+ + +
+
+ + +
+
+ +
+ +
+
+ + + \ No newline at end of file diff --git a/src/App/Views/display_tactic.html.twig b/src/App/Views/display_tactic.html.twig new file mode 100644 index 0000000..0877bd5 --- /dev/null +++ b/src/App/Views/display_tactic.html.twig @@ -0,0 +1,19 @@ + + + + + Tactiques partageables + + +
+

IQBall

+
+ + {% for t in tactics %} +
+

{{ t.name }}

+
+ {% endfor %} + + + \ No newline at end of file diff --git a/src/App/Views/display_user_teams.html.twig b/src/App/Views/display_user_teams.html.twig new file mode 100644 index 0000000..e801af5 --- /dev/null +++ b/src/App/Views/display_user_teams.html.twig @@ -0,0 +1,21 @@ + + + + + Twig view + + + +{% if teams is empty %} +

Vous n'êtes dans aucune équipe

+{% else %} + {% for team in teams %} +
+

Nom de l'équipe : {{ team.name }}

+ logo de l'équipe +
+ {% endfor %} +{% endif %} + + + \ No newline at end of file diff --git a/src/Core/Gateway/TacticInfoGateway.php b/src/Core/Gateway/TacticInfoGateway.php index 08302c9..271d4af 100644 --- a/src/Core/Gateway/TacticInfoGateway.php +++ b/src/Core/Gateway/TacticInfoGateway.php @@ -83,6 +83,34 @@ class TacticInfoGateway { return $res; } + public function getAllTacticSharedTeam(int $ownerId): ?array { + $res = $this->con->fetch( + "SELECT * FROM TacticSharedTeam + WHERE id_team = :ownerId", + [ + ":ownerId" => [$ownerId, PDO::PARAM_INT] + ] + ); + if (count($res) == 0) { + return []; + } + return $res; + } + + public function getAllTacticSharedAccount(int $ownerId): ?array { + $res = $this->con->fetch( + "SELECT * FROM TacticSharedTeam + WHERE id_account = :ownerId", + [ + ":ownerId" => [$ownerId, PDO::PARAM_INT] + ] + ); + if (count($res) == 0) { + return []; + } + return $res; + } + /** * @param string $name * @param int $owner diff --git a/src/Core/Gateway/TeamGateway.php b/src/Core/Gateway/TeamGateway.php index a817687..7d376e5 100644 --- a/src/Core/Gateway/TeamGateway.php +++ b/src/Core/Gateway/TeamGateway.php @@ -33,6 +33,18 @@ class TeamGateway { return intval($this->con->lastInsertId()); } + public function shareTacticToTeam(int $teamId, int $tacticId): int { + $this->con->exec( + "INSERT INTO TacticSharedTeam(id_team, id_tactic) VALUES(:teamId, :tacticId)", + [ + ":id_team" => [$teamId, PDO::PARAM_INT], + ":id_tactic" => [$tacticId, PDO::PARAM_INT], + ] + ); + return intval($this->con->lastInsertId()); + } + + /** * @param string $name * @param int $id diff --git a/src/Core/Model/TacticModel.php b/src/Core/Model/TacticModel.php index 7057e7f..7c801fc 100644 --- a/src/Core/Model/TacticModel.php +++ b/src/Core/Model/TacticModel.php @@ -79,6 +79,19 @@ class TacticModel { public function getAll(int $ownerId): ?array { return $this->tactics->getAll($ownerId); } + + public function getAllTacticSharedTeam(int $ownerId) : ?array { + return $this->tactics->getAllTacticSharedTeam($ownerId); + } + + public function getAllTacticSharedAccount(int $ownerId) : ?array { + return $this->tactics->getAllTacticSharedAccount($ownerId); + } + + public function shareTacticToAccount(int $accountId, int $tacticId) { + return $this->tactics->shareTacticToAccount($accountId, $tacticId); + } + /** * Update the name of a tactic * @param int $id the tactic identifier diff --git a/src/Core/Model/TeamModel.php b/src/Core/Model/TeamModel.php index 2bfe36e..fd8bea4 100644 --- a/src/Core/Model/TeamModel.php +++ b/src/Core/Model/TeamModel.php @@ -78,6 +78,13 @@ class TeamModel { return new Team($teamInfo, $members); } + + public function shareTacticToTeam(int $teamId, int $tacticId): int + { + return $this->teams->shareTacticToTeam($teamId, $tacticId); + } + + /** * delete a member from given team identifier * @param int $idMember