summaryrefslogtreecommitdiffstats
path: root/external/folder.php
blob: 68c8ff5232d30cc9148acee59d3a4afbb05b0630 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
<?php

namespace OCA\News;

use \OCA\News\Controller\FolderController;

class FolderApi {

	public function __construct($bl){
		$this->bl = $bl;
	}

	public function getAll() {
		$folders = $this->bl->getAll();
		$serializedFolders = array();

		//TODO: check the behaviour for nested folders
		foreach ($folders as $folder) {
			$serializedFolders[] = $folder->jsonSerialize();
		}
		return new \OC_OCS_Result($serializedFolders);
	}

	public function create() {
		$name = $_POST['name'];
		$parentId = $_POST['parentid'];

		$this->bl->create($name, $parentId);

		return new \OC_OCS_Result();
	}

	public function delete($params) {
		$id = $params['folderid'];
		if(!is_numeric($id))
			return new \OC_OCS_Result(null,999,'Invalid input! folderid must be an integer');

		if($this->bl->delete($id))
			return new \OC_OCS_Result();
		else
			return new \OC_OCS_Result(null,999,'Could not delete folder');
	}

	public function modify($params) {
		$id = $params['folderid'];
		if(!is_numeric($id))
			return new \OC_OCS_Result(null,999,'Invalid input! folderid must be an integer'.$id);

		$name = $_POST['name'];
		$parentId = $_POST['parentid'];
		$opened = $_POST['opened'];

		if($this->bl->modify($id, $name, $parentid, $opened))
			return new \OC_OCS_Result();
		else
			return new \OC_OCS_Result(null,999,'Could not modify folder');
	}
}