Add function setTarget(), implement recursion in getSource() for folders

This commit is contained in:
Michael Gapczynski 2011-06-25 22:00:52 -04:00
parent 78293ea244
commit 12c168b6dd
1 changed files with 21 additions and 10 deletions

View File

@ -78,25 +78,36 @@ class OC_SHARE {
/**
* Get the source location of the target item
* @param $target
* @return source path
*/
public static function getSource($target) {
// Break up the $target to get only the first part in case it is inside a folder
$parts = explode("/", $target);
$query = OC_DB::prepare("SELECT source FROM *PREFIX*sharing WHERE target = ? AND uid_shared_with = ?");
$result = $query->execute(array($parts[0], $_SESSION['user_id']))->fetchAll();
$result = $query->execute(array($target, $_SESSION['user_id']))->fetchAll();
if (count($result) > 0) {
$source = $result[0]['source'];
// Add the $parts back in
foreach (array_slice($parts, 1) as $part) {
$source .= $part;
}
return $source;
return $result[0]['source'];
} else {
return false;
// Check if the directory above this target is shared
$parentDir = substr($target, 0, strrpos($target, "/"));
if ($parentDir) {
$result = OC_SHARE::getSource($parentDir);
return $result.substr($target, strrpos($target, "/"));
} else {
return false;
}
}
}
/**
* Set the target location to a new value
* @param $oldTarget The current target location
* @param $newTarget The new target location
*/
public static function setTarget($oldTarget, $newTarget) {
$query = OC_DB::prepare("UPDATE *PREFIX*sharing SET target = ? WHERE target = ? AND uid_shared_with = ?");
$query->execute(array($newTarget, $oldTarget, $_SESSION['user_id']));
}
/**
* Get all items the user is sharing
* @return array