diff --git a/src/App/Controller/UserController.php b/src/App/Controller/UserController.php index bf996fb..68419cb 100644 --- a/src/App/Controller/UserController.php +++ b/src/App/Controller/UserController.php @@ -39,7 +39,7 @@ class UserController { $user = $session->getAccount()->getUser(); $lastTactics = $this->tactics->getLast($limitNbTactics, $user->getId()); - $rootTactics = $this->tactics->getFolderTactic($user->getId()); + $rootTactics = $this->tactics->getFoldefrTactic($user->getId()); $name = $user->getName(); if ($this->teams != null) { diff --git a/src/Core/Data/PersonalSpace/PersonalSpaceFolder.php b/src/Core/Data/PersonalSpace/PersonalSpaceFolder.php new file mode 100644 index 0000000..fbf8c57 --- /dev/null +++ b/src/Core/Data/PersonalSpace/PersonalSpaceFolder.php @@ -0,0 +1,34 @@ +id = $id; + $this->name = $name; + } + + /** + * @return int + */ + public function getId(): int { + return $this->id; + } + + /** + * @return string + */ + public function getName(): string { + return $this->name; + } + + + +} \ No newline at end of file diff --git a/src/Core/Data/PersonalSpace/PersonalSpaceItem.php b/src/Core/Data/PersonalSpace/PersonalSpaceItem.php new file mode 100644 index 0000000..0fea816 --- /dev/null +++ b/src/Core/Data/PersonalSpace/PersonalSpaceItem.php @@ -0,0 +1,9 @@ +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)", [ - "name" =>[$folderName,\PDO::PARAM_STR], - "owner"=>[$ownerId,\PDO::PARAM_INT], - "parent"=>[$parentId,\PDO::PARAM_INT] + "name" => [$folderName, \PDO::PARAM_STR], + "owner" => [$ownerId, \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] ] ); } diff --git a/src/Core/Gateway/TacticInfoGateway.php b/src/Core/Gateway/TacticInfoGateway.php index 06475a0..259deec 100644 --- a/src/Core/Gateway/TacticInfoGateway.php +++ b/src/Core/Gateway/TacticInfoGateway.php @@ -131,28 +131,6 @@ class TacticInfoGateway { 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); - } + } diff --git a/src/Core/Model/PersonalSpaceModel.php b/src/Core/Model/PersonalSpaceModel.php index 622a8fb..9b28457 100644 --- a/src/Core/Model/PersonalSpaceModel.php +++ b/src/Core/Model/PersonalSpaceModel.php @@ -3,19 +3,28 @@ namespace IQBall\Core\Model; use IQBall\Core\Gateway\PersonalSpaceGateway; +use IQBall\Core\Gateway\TacticInfoGateway; 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) { - $this->gateway = $gateway; + public function __construct(PersonalSpaceGateway $personalSpaces,TacticInfoGateway $tactics) { + $this->personalSpaces = $personalSpaces; + $this->tactics = $tactics; } 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); + } } \ No newline at end of file diff --git a/src/Core/Model/TacticModel.php b/src/Core/Model/TacticModel.php index 10e41ac..4953fb2 100644 --- a/src/Core/Model/TacticModel.php +++ b/src/Core/Model/TacticModel.php @@ -102,8 +102,4 @@ class TacticModel { return null; } - public function getFolderTactic(int $acountId,int $folderId = 0): array{ - return $this->tactics->getFolderTactic($acountId,$folderId); - } - }