diff --git a/sql/setup-tables.sql b/sql/setup-tables.sql index 0d157d9..c827bd0 100644 --- a/sql/setup-tables.sql +++ b/sql/setup-tables.sql @@ -25,12 +25,23 @@ CREATE TABLE Tactic FOREIGN KEY (owner) REFERENCES Account ); -CREATE TABLE FormEntries +CREATE TABLE TacticFolder ( - name varchar NOT NULL, - description varchar NOT NULL + id integer PRIMARY KEY AUTOINCREMENT, + name varchar NOT NULL, + owner integer NOT NULL, + tacticFolderParent integer, + FOREIGN KEY (owner) REFERENCES Account, + FOREIGN KEY (tacticFolderParent) REFERENCES TacticFolder ); +CREATE TABLE TacticFolderLink +( + idFolder integer NOT NULL, + idTactic integer NOT NULL, + FOREIGN KEY (idFolder) REFERENCES TacticFolder, + FOREIGN KEY (idTactic) REFERENCES Tactic +); CREATE TABLE Team ( diff --git a/src/Core/Gateway/TacticInfoGateway.php b/src/Core/Gateway/TacticInfoGateway.php index 08302c9..e96d807 100644 --- a/src/Core/Gateway/TacticInfoGateway.php +++ b/src/Core/Gateway/TacticInfoGateway.php @@ -130,4 +130,29 @@ 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, TacticFolderLink tfl + WHERE t.owner = :ownerId AND t.id NOT IN (SELECT idTactic FROM TacticFolderLink)"; + $args = ["ownerId" => [$accountId, PDO::PARAM_INT]]; + + }else { + $query = "SELECT t.* + FROM Tactic t, TacticFolderLink tfl + WHERE t.owner = :ownerId AND tfl.idTactic = :folderId"; + $args = ["ownerId" => [$accountId, PDO::PARAM_INT], + "folderId" => [$folderId, PDO::PARAM_INT]]; + } + return $this->con->fetch($query,$args); + } + } diff --git a/src/Core/Model/TacticModel.php b/src/Core/Model/TacticModel.php index 4953fb2..10e41ac 100644 --- a/src/Core/Model/TacticModel.php +++ b/src/Core/Model/TacticModel.php @@ -102,4 +102,8 @@ class TacticModel { return null; } + public function getFolderTactic(int $acountId,int $folderId = 0): array{ + return $this->tactics->getFolderTactic($acountId,$folderId); + } + }