51 $allUserFolders = null;
53 $folderDao = $this->restHelper->getFolderDao();
54 if (isset($args[
'id'])) {
55 $id = intval($args[
'id']);
57 if (! $folderDao->isFolderAccessible($id)) {
58 $returnVal =
new Info(403,
"Folder id $id is not accessible",
61 if ($folderDao->getFolder($id) === null) {
62 $returnVal =
new Info(404,
"Folder id $id does not exists",
65 if ($returnVal !== null) {
66 return $response->withJson($returnVal->getArray(), $returnVal->getCode());
72 $rootFolder = $folderDao->getRootFolder($this->restHelper->getUserId())->getId();
73 $allUserFolders = array();
75 $allUserFolders = array_keys($allUserFolders);
77 $foldersList = array();
78 foreach ($allUserFolders as $folderId) {
79 $folder = $folderDao->getFolder($folderId);
80 $parentId = $folderDao->getFolderParentId($folderId);
81 $folderModel =
new Folder($folder->getId(), $folder->getName(),
82 $folder->getDescription(), $parentId);
83 $foldersList[] = $folderModel->
getArray();
86 $foldersList = $foldersList[0];
88 return $response->withJson($foldersList, 200);
102 $parentFolder = $request->getHeaderLine(
'parentFolder');
103 $folderName =
trim($request->getHeaderLine(
'folderName'));
104 $folderDescription =
trim($request->getHeaderLine(
'folderDescription'));
106 if (! is_numeric($parentFolder) || $parentFolder < 0) {
107 $info =
new Info(400,
"Parent folder id must be a positive integer!",
110 if (empty($folderName)) {
111 $info =
new Info(400,
"Folder name can not be empty!", InfoType::ERROR);
113 if (! $this->restHelper->getFolderDao()->isFolderAccessible($parentFolder,
114 $this->restHelper->getUserId())) {
115 $info =
new Info(403,
"Parent folder can not be accessed!", InfoType::ERROR);
117 if ($info !== null) {
118 return $response->withJson($info->getArray(), $info->getCode());
120 $folderCreate = $this->restHelper->getPlugin(
'folder_create');
121 $rc = $folderCreate->create($parentFolder, $folderName, $folderDescription);
123 $info =
new Info(200,
"Folder $folderName already exists!", InfoType::INFO);
124 } elseif ($rc == 0) {
125 $info =
new Info(404,
"Parent folder not found!", InfoType::ERROR);
127 $folderId = $this->restHelper->getFolderDao()->getFolderId($folderName, $parentFolder);
128 $info =
new Info(201, intval($folderId), InfoType::INFO);
130 return $response->withJson($info->getArray(), $info->getCode());
144 $folderDao = $this->restHelper->getFolderDao();
145 $folderId = $args[
'id'];
147 if (! is_numeric($folderId) || $folderId < 0) {
148 $info =
new Info(400,
"Folder id must be a positive integer!",
150 } elseif ($folderDao->getFolder($folderId) === null) {
151 $info =
new Info(404,
"Folder id not found!", InfoType::ERROR);
153 $folderDelete = $this->restHelper->getPlugin(
'admin_folder_delete');
156 $folderParent = intval($folderArray[count($folderArray) - 2][
'folder_pk']);
157 $folderId =
"$folderParent $folderId";
160 if ($rc ==
"No access to delete this folder") {
161 $info =
new Info(403, $rc, InfoType::ERROR);
162 } elseif ($rc !== null) {
163 $info =
new Info(500, $rc, InfoType::ERROR);
165 $info =
new Info(202,
"Folder, \"$folderName\" deleted.", InfoType::INFO);
168 return $response->withJson($info->getArray(), $info->getCode());
182 $folderDao = $this->restHelper->getFolderDao();
183 $folderId = $args[
'id'];
184 $newName = $request->getHeaderLine(
'name');
185 $newDesc = $request->getHeaderLine(
'description');
187 if ($folderDao->getFolder($folderId) === null) {
188 $info =
new Info(404,
"Folder id not found!", InfoType::ERROR);
189 } elseif (! $folderDao->isFolderAccessible($folderId, $this->restHelper->getUserId())) {
190 $info =
new Info(403,
"Folder is not accessible!", InfoType::ERROR);
192 $folderEdit = $this->restHelper->getPlugin(
'folder_properties');
194 $folderEdit->Edit($folderId, $newName, $newDesc);
195 $info =
new Info(200,
"Folder \"$folderName\" updated.", InfoType::INFO);
197 return $response->withJson($info->getArray(), $info->getCode());
211 $folderDao = $this->restHelper->getFolderDao();
212 $folderId = $args[
'id'];
213 $newParent = $request->getHeaderLine(
'parent');
214 $action = strtolower($request->getHeaderLine(
'action'));
216 if (! is_numeric($newParent) || $newParent < 0) {
217 $info =
new Info(400,
"Parent id must be a positive integer!",
219 } elseif ($folderDao->getFolder($folderId) === null) {
220 $info =
new Info(404,
"Folder id not found!", InfoType::ERROR);
221 } elseif ($folderDao->getFolder($newParent) === null) {
222 $info =
new Info(404,
"Parent folder not found!", InfoType::ERROR);
223 } elseif (! $folderDao->isFolderAccessible($folderId,
224 $this->restHelper->getUserId())) {
225 $info =
new Info(403,
"Folder is not accessible!", InfoType::ERROR);
226 } elseif (! $folderDao->isFolderAccessible($newParent,
227 $this->restHelper->getUserId())) {
228 $info =
new Info(403,
"Parent folder is not accessible!", InfoType::ERROR);
229 } elseif (strcmp($action,
"copy") != 0 && strcmp($action,
"move") != 0) {
230 $info =
new Info(400,
"Action can be one of [copy,move]!", InfoType::ERROR);
232 $folderMove = $this->restHelper->getPlugin(
'content_move');
235 $isCopy = (strcmp($action,
"copy") == 0);
236 $message = $folderMove->copyContent(
238 $folderDao->getFolderContentsId($folderId)
239 ], $newParent, $isCopy);
240 if (empty($message)) {
241 $info =
new Info(202,
242 "Folder \"$folderName\" $action(ed) under \"$parentFolderName\".",
245 $info =
new Info(500, $message, InfoType::ERROR);
248 return $response->withJson($info->getArray(), $info->getCode());
static getUserId()
Get the current user's id.
Base controller for REST calls.
Controller for Folder model.
editFolder($request, $response, $args)
FolderGetName($FolderPk, $Top=-1)
Given a folder_pk, return the full path to this folder.
copyFolder($request, $response, $args)
GetFolderArray($RootFolder, &$FolderArray)
Get an array of all the folders from a $RootFolder on down.
Folder2Path($folder_pk)
Return an array of folder_pk, folder_name from the users.root_folder_fk to $folder_pk.
getFolders($request, $response, $args)
Info model to contain general error and return values.
createFolder($request, $response, $args)
deleteFolder($request, $response, $args)
char * trim(char *ptext)
Trimming whitespace.