shareTactic
Vivien DUFOUR 1 year ago
parent 41d431c1cb
commit fa81bd0702

@ -74,14 +74,15 @@ function SideMenu({
teams: Team[] teams: Team[]
}) { }) {
return ( return (
<div <div id="sideMenu" style={{
id="side-menu" width : width + "%",
style={{
width: width + "%",
}}> }}>
<div id="side-menu-content"> <div id="sideMenuContent">
<Team teams={teams} /> <Team teams={teams}/>
<Tactic lastTactics={lastTactics} /> <Tactic lastTactics={lastTactics}/>
<div onClick={() => {location.pathname="/shareTactic"}}>
<p>Partager une tactique</p>
</div>
</div> </div>
</div> </div>
) )

@ -12,6 +12,7 @@ use IQBall\App\Controller\EditorController;
use IQBall\App\Controller\TeamController; use IQBall\App\Controller\TeamController;
use IQBall\App\Controller\UserController; use IQBall\App\Controller\UserController;
use IQBall\App\Controller\VisualizerController; use IQBall\App\Controller\VisualizerController;
use IQBall\App\Controller\TacticController;
use IQBall\App\Session\MutableSessionHandle; use IQBall\App\Session\MutableSessionHandle;
use IQBall\App\Session\PhpSessionHandle; use IQBall\App\Session\PhpSessionHandle;
use IQBall\App\Session\SessionHandle; 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))); 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 { function getAuthController(): AuthController {
return new AuthController(new AuthModel(new AccountGateway(getConnection()))); 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", "/settings", Action::auth(fn(SessionHandle $s) => getUserController()->settings($s)));
$ar->map("GET", "/disconnect", Action::auth(fn(MutableSessionHandle $s) => getUserController()->disconnect($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 //tactic-related
$ar->map("GET", "/tactic/[i:id]/view", Action::auth(fn(int $id, SessionHandle $s) => getVisualizerController()->openVisualizer($id, $s))); $ar->map("GET", "/tactic/[i:id]/view", Action::auth(fn(int $id, SessionHandle $s) => getVisualizerController()->openVisualizer($id, $s)));

@ -50,3 +50,19 @@ CREATE TABLE Member
FOREIGN KEY (id_team) REFERENCES Team (id), FOREIGN KEY (id_team) REFERENCES Team (id),
FOREIGN KEY (id_user) REFERENCES Account (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)
);

@ -0,0 +1,44 @@
<?php
namespace IQBall\App\Controller;
use IQBall\App\Session\SessionHandle;
use IQBall\App\ViewHttpResponse;
use IQBall\Core\Model\TacticModel;
use IQBall\Core\Model\TeamModel;
class TacticController
{
private TacticModel $tactics;
private ?TeamModel $teams;
public function __construct(TacticModel $tactics, ?TeamModel $teams = NULL) {
$this->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("/");
}
}

@ -243,4 +243,10 @@ class TeamController {
$this->model->editTeam($idTeam, $request['name'], $request['picture'], $request['main_color'], $request['second_color']); $this->model->editTeam($idTeam, $request['name'], $request['picture'], $request['main_color'], $request['second_color']);
return HttpResponse::redirect('/team/' . $idTeam); 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);
}
} }

@ -0,0 +1,31 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Confirmation</title>
</head>
<body>
<div class="container">
<h2>Etes-vous sûr de vouloir partager la tactique ?</h2>
<form action="{{ path("/shareTactic/#{tactic}/team/#{team}") }}" method="POST">
<div>
<input type="radio" id="yes" name="confirmation" value="yes" />
<label for="yes">Oui</label>
</div>
<div>
<input type="radio" id="no" name="confirmation" value="no" />
<label for="no">Non</label>
</div>
<div class="form-group">
<input type="submit" value="Confirmer">
</div>
</form>
</div>
</body>
</html>

@ -0,0 +1,19 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Tactiques partageables</title>
</head>
<body>
<header>
<h1><a href="{{ path('/') }}">IQBall</a></h1>
</header>
{% for t in tactics %}
<div onclick="window.location.href = '{{ path("/shareTactic/#{t.id}") }}'">
<p> {{ t.name }} </p>
</div>
{% endfor %}
</body>
</html>

@ -0,0 +1,21 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Twig view</title>
</head>
<body>
{% if teams is empty %}
<p>Vous n'êtes dans aucune équipe</p>
{% else %}
{% for team in teams %}
<div class="team" onclick="window.location.href = '{{ path("/shareTactic/#{tactic}/team/#{team.id}") }}'">
<p>Nom de l'équipe : {{ team.name }}</p>
<img src="{{ team.picture }}" alt="logo de l'équipe">
</div>
{% endfor %}
{% endif %}
</body>
</html>

@ -83,6 +83,34 @@ class TacticInfoGateway {
return $res; 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 string $name
* @param int $owner * @param int $owner

@ -33,6 +33,18 @@ class TeamGateway {
return intval($this->con->lastInsertId()); 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 string $name
* @param int $id * @param int $id

@ -79,6 +79,19 @@ class TacticModel {
public function getAll(int $ownerId): ?array { public function getAll(int $ownerId): ?array {
return $this->tactics->getAll($ownerId); 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 * Update the name of a tactic
* @param int $id the tactic identifier * @param int $id the tactic identifier

@ -78,6 +78,13 @@ class TeamModel {
return new Team($teamInfo, $members); 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 * delete a member from given team identifier
* @param int $idMember * @param int $idMember

Loading…
Cancel
Save