con = $con; } 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] ] ); } /** * 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] ] ); } }