WIP avancing on implementing folder into personal space
continuous-integration/drone/push Build is failing Details

folder
Maël DAIM 1 year ago
parent 6875c500f2
commit c82b329652

@ -39,7 +39,7 @@ class UserController {
$user = $session->getAccount()->getUser(); $user = $session->getAccount()->getUser();
$lastTactics = $this->tactics->getLast($limitNbTactics, $user->getId()); $lastTactics = $this->tactics->getLast($limitNbTactics, $user->getId());
$rootTactics = $this->tactics->getFolderTactic($user->getId()); $rootTactics = $this->tactics->getFoldefrTactic($user->getId());
$name = $user->getName(); $name = $user->getName();
if ($this->teams != null) { if ($this->teams != null) {

@ -0,0 +1,34 @@
<?php
namespace IQBall\Core\Data;
class PersonalSpaceFolder implements PersonalSpaceItem {
private int $id;
private string $name;
/**
* @param int $id
* @param string $name
*/
public function __construct(int $id, string $name) {
$this->id = $id;
$this->name = $name;
}
/**
* @return int
*/
public function getId(): int {
return $this->id;
}
/**
* @return string
*/
public function getName(): string {
return $this->name;
}
}

@ -0,0 +1,9 @@
<?php
namespace IQBall\Core\Data;
interface PersonalSpaceItem {
public function getId();
public function getName();
}

@ -2,7 +2,7 @@
namespace IQBall\Core\Data; namespace IQBall\Core\Data;
class TacticInfo { class TacticInfo implements PersonalSpaceItem {
private int $id; private int $id;
private string $name; private string $name;
private int $creationDate; private int $creationDate;

@ -11,12 +11,73 @@ class PersonalSpaceGateway {
$this->con = $con; $this->con = $con;
} }
public function addFolder(string $folderName,int $ownerId,int $parentId): void{ public function addFolder(string $folderName, int $ownerId, int $parentId): void {
$this->con->exec("INSERT INTO TacticFolder(name,owner,tactic_folder_parent) VALUES(:name,:owner,:parent)", $this->con->exec("INSERT INTO TacticFolder(name,owner,tactic_folder_parent) VALUES(:name,:owner,:parent)",
[ [
"name" =>[$folderName,\PDO::PARAM_STR], "name" => [$folderName, \PDO::PARAM_STR],
"owner"=>[$ownerId,\PDO::PARAM_INT], "owner" => [$ownerId, \PDO::PARAM_INT],
"parent"=>[$parentId,\PDO::PARAM_INT] "parent" => [$parentId, \PDO::PARAM_INT]
]
);
}
/**
* Return all the tactic of a specific folder
* If the folder's id is 0, we return all tactics at the root
* @param int $accountId
* @param int $folderId
* @return array
*/
public function getContentFromFolder(int $accountId, int $folderId): array {
if ($folderId == 0) {
$content = $this->getTacticFromRoot($accountId);
$content = array_merge($this->getFolderFromRoot($accountId), $content);
} else {
$content = $this->getTacticFromFolder($accountId, $folderId);
$content = array_merge($this->getFolderFromFolder($accountId, $folderId), $content);
}
return $content;
}
public function getTacticFromRoot(int $accountId): array {
return $this->con->fetch(
"SELECT t.*
FROM Tactic t
WHERE t.owner = :ownerId AND t.id NOT IN (SELECT id_tactic FROM TacticFolderLink)",
["ownerId" => [$accountId, PDO::PARAM_INT]]
);
}
public function getFolderFromRoot(int $accountId): array {
return $this->con->fetch(
"SELECT *
FROM TacticFolder
WHERE owner = :owner AND tactic_folder_parent IS NULL",
["ownerId" => [$accountId, PDO::PARAM_INT]]
);
}
public function getTacticFromFolder(int $accountId, int $folderId): array {
return $this->con->fetch(
"SELECT t.*
FROM Tactic t, TacticFolderLink tfl
WHERE t.owner = :ownerId AND tfl.id_tactic = :folderId",
[
"ownerId" => [$accountId, PDO::PARAM_INT],
"folderId" => [$folderId, PDO::PARAM_INT]
]
);
}
public function getFolderFromFolder(int $accountId, int $folderId): array {
return $this->con->fetch(
"SELECT *
FROM TacticFolder
WHERE owner = :ownerId AND tactic_folder_parent = :folderId",
[
"ownerId" => [$accountId, PDO::PARAM_INT],
"folderId" => [$folderId, PDO::PARAM_INT]
] ]
); );
} }

@ -131,28 +131,6 @@ class TacticInfoGateway {
return $stmnt->rowCount() == 1; return $stmnt->rowCount() == 1;
} }
/**
* Return all the tactic of a specific folder
* If the folder's id is 0, we return all tactics at the root
* @param int $accountId
* @param int $folderId
* @return array
*/
public function getFolderTactic(int $accountId,int $folderId): array {
if($folderId == 0){
$query = "SELECT t.*
FROM Tactic t
WHERE t.owner = :ownerId AND t.id NOT IN (SELECT id_tactic FROM TacticFolderLink)";
$args = ["ownerId" => [$accountId, PDO::PARAM_INT]];
}else {
$query = "SELECT t.*
FROM Tactic t, TacticFolderLink tfl
WHERE t.owner = :ownerId AND tfl.id_tactic = :folderId";
$args = ["ownerId" => [$accountId, PDO::PARAM_INT],
"folderId" => [$folderId, PDO::PARAM_INT]];
}
return $this->con->fetch($query,$args);
}
} }

@ -3,19 +3,28 @@
namespace IQBall\Core\Model; namespace IQBall\Core\Model;
use IQBall\Core\Gateway\PersonalSpaceGateway; use IQBall\Core\Gateway\PersonalSpaceGateway;
use IQBall\Core\Gateway\TacticInfoGateway;
class PersonalSpaceModel { class PersonalSpaceModel {
private PersonalSpaceGateway $gateway; private PersonalSpaceGateway $personalSpaces;
private TacticInfoGateway $tactics;
/** /**
* @param PersonalSpaceGateway $gateway * @param PersonalSpaceGateway $personalSpaces
* @param TacticInfoGateway $tactics
*/ */
public function __construct(PersonalSpaceGateway $gateway) { public function __construct(PersonalSpaceGateway $personalSpaces,TacticInfoGateway $tactics) {
$this->gateway = $gateway; $this->personalSpaces = $personalSpaces;
$this->tactics = $tactics;
} }
public function createFolder(string $folderName,int $ownerId,int $parentFolder): void{ public function createFolder(string $folderName,int $ownerId,int $parentFolder): void{
$this->gateway->addFolder($folderName,$ownerId,$parentFolder); $this->personalSpaces->addFolder($folderName,$ownerId,$parentFolder);
}
public function getFolderContent(int $acountId,int $folderId = 0): array{
$tactics = $this->personalSpaces->getFolderTactic($acountId,$folderId);
} }
} }

@ -102,8 +102,4 @@ class TacticModel {
return null; return null;
} }
public function getFolderTactic(int $acountId,int $folderId = 0): array{
return $this->tactics->getFolderTactic($acountId,$folderId);
}
} }

Loading…
Cancel
Save