extend API to get the shares from all files in a given folder

This commit is contained in:
Bjoern Schiessle 2013-09-19 16:41:29 +02:00
parent 8cf8c0b161
commit c9f1538c1f
1 changed files with 32 additions and 0 deletions

View File

@ -35,6 +35,11 @@ class Api {
// if a file is specified, get the share for this file
if (isset($_GET['file'])) {
$params['itemSource'] = self::getFileId($_GET['file']);
$params['path'] = $_GET['file'];
if (isset($_GET['subfiles']) && $_GET['subfiles'] === 'yes') {
error_log("get shares from folder");
return self::getSharesFromFolder($params);
}
return self::getShare($params);
}
@ -88,6 +93,33 @@ class Api {
}
}
/**
* @brief get share from all files in a given folder (non-recursive)
* @param array $params contains 'path' to the folder
* @return \OC_OCS_Result
*/
private static function getSharesFromFolder($params) {
$path = $params['path'];
$view = new \OC\Files\View('/'.\OCP\User::getUser().'/files');
if(!$view->is_dir($path)) {
return new \OC_OCS_Result(null, 404, "not a directory");
}
$content = $view->getDirectoryContent($path);
$result = array();
foreach ($content as $file) {
$share = \OCP\Share::getItemShared('file', $file['fileid']);
if ($share) {
$share['filename'] = $file['name'];
$result[] = $share;
}
}
return new \OC_OCS_Result($result);
}
/**
* @breif create a new share
* @param array $params