Can now share, unshare and open shared tactic
continuous-integration/drone/push Build is failing Details

shareTactic
Vivien DUFOUR 1 year ago
parent 86a25d18b2
commit 588f580bf9

@ -83,6 +83,9 @@ function SideMenu({
<div onClick={() => {location.pathname="/shareTactic"}}>
<p>Partager une tactique</p>
</div>
<div onClick={() => {location.pathname="/unshareTactic"}}>
<p>Retirer le partage d'une tactique</p>
</div>
</div>
</div>
)

@ -18,7 +18,7 @@ use IQBall\Core\Model\AuthModel;
use IQBall\Core\Model\TacticModel;
function getTacticController(): APITacticController {
return new APITacticController(new TacticModel(new TacticInfoGateway(new Connection(get_database()))));
return new APITacticController(new TacticModel(new TacticInfoGateway(new Connection(get_database())), new AccountGateway(new Connection(get_database()))));
}
function getAuthController(): APIAuthController {

@ -76,7 +76,15 @@ class EditorController {
public function openEditor(int $id, SessionHandle $session): ViewHttpResponse {
$tactic = $this->model->get($id);
$failure = TacticValidator::validateAccess($id, $tactic, $session->getAccount()->getUser()->getId());
$ownerId = $session->getAccount()->getUser()->getId();
$ids = $this->model->getOwnerIdTacticShared($id, $session->getAccount()->getUser()->getId());
if(isset($ids)) {
$ownerId = $ids['owner'];
}
$failure = TacticValidator::validateAccess($id, $tactic, $ownerId);
if ($failure != null) {
return ViewHttpResponse::twig('error.html.twig', ['failures' => [$failure]], HttpCodes::NOT_FOUND);

@ -15,5 +15,4 @@ class TacticValidator {
}
return null;
}
}

@ -150,6 +150,35 @@ class TacticInfoGateway {
return array_map(fn(array $row) => $this->rowToTacticInfo($row), $res);
}
public function getOwnerIdTacticSharedTeam(int $tacticId, int $accountId) : ?array {
return $this->con->fetch(
"SELECT t.owner
FROM Account a
JOIN Member m on a.id = m.id_user
JOIN TacticSharedTeam tt ON m.id_team = tt.id_team
JOIN Tactic t ON tt.id_tactic = t.id
WHERE tt.id_tactic = :tacticId AND m.id_user = :accountId",
[
":tacticId" => [$tacticId, PDO::PARAM_INT],
":accountId" => [$accountId, PDO::PARAM_INT]
]
);
}
public function getOwnerIdTacticSharedAccount(int $tacticId, int $accountId) : ?array {
return $this->con->fetch(
"SELECT t.owner FROM Account a
JOIN TacticSharedAccount ta ON a.id = ta.id_account
JOIN Tactic t ON ta.id_tactic = t.id
WHERE ta.id_tactic = :tacticId AND ta.id_account = :accountId",
[
":tacticId" => [$tacticId, PDO::PARAM_INT],
":accountId" => [$accountId, PDO::PARAM_INT]
]
);
}
/**
* @param string $name
* @param int $owner

@ -135,6 +135,61 @@ class TacticModel {
return $allTactics;
}
public function shareTacticToAccount(int $accountId, int $tacticId): int
{
return $this->users->shareTacticToAccount($accountId, $tacticId);
}
public function shareTacticToAccountMail(string $email, int $tacticId): ?int
{
$account = $this->users->getAccountFromMail($email);
var_dump($account);
$accountId = $account->getUser()->getId();
var_dump($accountId);
if(isset($accountId)) {
return $this->shareTacticToAccount($accountId, $tacticId);
}
return null;
}
public function unshareTactic(int $tacticId): int
{
return $this->users->unshareTactic($tacticId);
}
public function unshareTacticToAccount(int $tacticId, int $accountId): int
{
return $this->users->unshareTacticToAccount($tacticId, $accountId);
}
public function getOwnerIdTacticShared(int $tactidId, int $accountId) : ?array {
$ids = [];
$idT = $this->tactics->getOwnerIdTacticSharedTeam($tactidId, $accountId);
if(isset($idT)) {
foreach ($idT as $id) {
if(!in_array($id, $ids)) {
array_push($ids, $id);
}
}
}
$idA = $this->tactics->getOwnerIdTacticSharedAccount($tactidId, $accountId);
if(isset($idA)) {
foreach ($idA as $id) {
if(!in_array($id, $ids)) {
array_push($ids, $id);
}
}
}
if($ids != null) {
return $ids[0];
}
return null;
}
/**
* Update the name of a tactic
* @param int $id the tactic identifier
@ -165,32 +220,4 @@ class TacticModel {
}
return null;
}
public function shareTacticToAccount(int $accountId, int $tacticId): int
{
return $this->users->shareTacticToAccount($accountId, $tacticId);
}
public function shareTacticToAccountMail(string $email, int $tacticId): ?int
{
$account = $this->users->getAccountFromMail($email);
var_dump($account);
$accountId = $account->getUser()->getId();
var_dump($accountId);
if(isset($accountId)) {
return $this->shareTacticToAccount($accountId, $tacticId);
}
return null;
}
public function unshareTactic(int $tacticId): int
{
return $this->users->unshareTactic($tacticId);
}
public function unshareTacticToAccount(int $tacticId, int $accountId): int
{
return $this->users->unshareTacticToAccount($tacticId, $accountId);
}
}

Loading…
Cancel
Save