implement folder modify and delete api calls

This commit is contained in:
Gregor Tätzner 2013-03-07 18:25:31 +01:00
Родитель 3c87c2be39
Коммит 25a766a009
4 изменённых файлов: 98 добавлений и 37 удалений

Просмотреть файл

@ -247,7 +247,6 @@ $this->create('news_ajax_importOPML', '/import')->action(
},
'news', \OC_API::USER_AUTH
);
\OCP\API::register(
'post', '/news/folders/create',
function($urlParams) {
@ -256,3 +255,19 @@ $this->create('news_ajax_importOPML', '/import')->action(
},
'news', \OC_API::USER_AUTH
);
\OCP\API::register(
'get', '/news/folders/{folderid}/delete',
function($urlParams) {
$container = createDIContainer();
return $container['FolderApi']->delete($urlParams);
},
'news', \OC_API::USER_AUTH
);
\OCP\API::register(
'post', '/news/folders/{folderid}/modify',
function($urlParams) {
$container = createDIContainer();
return $container['FolderApi']->modify($urlParams);
},
'news', \OC_API::USER_AUTH
);

Просмотреть файл

@ -111,6 +111,9 @@ class FolderMapper {
$result = $stmt->execute(array($this->userid, $id));
$row = $result->fetchRow();
if(!$row)
return null;
$folder = new Folder($row['name'], $row['id']);
$folder->setOpened($row['opened']);

Просмотреть файл

@ -22,7 +22,6 @@ class FolderApi {
}
public function create() {
$name = $_POST['name'];
$parentId = $_POST['parentid'];
@ -30,5 +29,31 @@ class FolderApi {
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');
}
}

Просмотреть файл

@ -17,4 +17,22 @@ class FolderBl {
$folder = new Folder($name, null, null);
return $this->folderMapper->save($folder);
}
public function delete($folderid) {
return $this->folderMapper->deleteById($folderid);
}
public function modify($folderid, $name = null, $parent = null, $opened = null) {
$folder = $this->folderMapper->find($folderid);
if(!$folder)
return false;
if($name)
$folder->setName($name);
if($parent)
$folder->setParentId($parent);
if($opened)
$folder->setOpened($opened);
return $this->folderMapper->update($folder);
}
}