You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
2.7 KiB
84 lines
2.7 KiB
<?php
|
|
|
|
namespace IQBall\Core\Gateway;
|
|
|
|
use IQBall\Core\Connection;
|
|
|
|
class PersonalSpaceGateway {
|
|
private Connection $con;
|
|
|
|
public function __construct(Connection $con) {
|
|
$this->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]
|
|
]
|
|
);
|
|
}
|
|
} |