ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
class.ilWebDAVTree.php
Go to the documentation of this file.
1 <?php
2 
5 
18 {
19  protected static $instance;
20 
21  public static function getInstance()
22  {
23  if (!isset(self::$instance)) {
24  self::$instance = new self();
25  }
26  return self::$instance;
27  }
28 
42  public static function getRefIdForWebDAVPath($a_uri)
43  {
44  $a_uri = strtolower(trim($a_uri, '/'));
45 
46  /* After this funciton, the array SHOULD look like this:
47  * $splitted_path[0] = '<client_name>'
48  * $splitted_path[1] = 'ref_<ref_id>' or <ilias_root_name>
49  * $splitted_path[2] = '<rest>/<of>/<the>/<path>
50  */
51  $splitted_path = explode('/', $a_uri, 3);
52 
53  // Early exit for bad request
54  if (count($splitted_path) < 2) {
55  throw new BadRequest();
56  }
57 
58  $repository_mountpoint = $splitted_path[1];
59  $path_in_mountpoint = $splitted_path[2];
60 
61  // Since we already know our client, we only have to check the requested root for our path
62  // if second string = 'ilias', the request was for the ilias root
63  if ($repository_mountpoint == 'ilias') {
64  if ($path_in_mountpoint != '') {
65  $ref_path = self::getRefIdForGivenRootAndPath(ROOT_FOLDER_ID, $path_in_mountpoint);
66  $searched_node = $ref_path[count($ref_path) - 1];
67  $ref_id = $searched_node['child'];
68  } else {
69  $ref_id = ROOT_FOLDER_ID;
70  }
71  }
72  // if the first 4 letters are 'ref_', we are searching for a ref ID in the tree
73  elseif (substr($splitted_path[1], 0, 4) == 'ref_') {
74  // Make a 'ref_1234' to a '1234'
75  // Since we already tested for 'ref_', we can be sure there is at least one '_' character
76  $start_node = (int) explode('_', $repository_mountpoint)[1];
77  if ($path_in_mountpoint != '' && $start_node > 0) {
78  $ref_id = self::getRefIdForGivenRootAndPath($start_node, $path_in_mountpoint);
79  } elseif ($path_in_mountpoint == '') {
80  $ref_id = $start_node;
81  } else {
82  throw new NotFound();
83  }
84  }
85  // if there was no 'ilias' and no 'ref_' in the second string, this was a bad request...
86  else {
87  throw new BadRequest();
88  }
89 
90  return $ref_id;
91  }
92 
98  public static function getRefIdForGivenRootAndPath(int $start_ref, string $path_from_startnode)
99  {
100  return self::iterateRecursiveThroughTree(explode('/', $path_from_startnode), 0, $start_ref);
101  }
102 
111  protected static function iterateRecursiveThroughTree($path_title_array, $searched_element_index, $parent_ref_id)
112  {
113  global $DIC;
114 
115  // Check if last element was already found
116  if ($path_title_array[$searched_element_index] == '' || count($path_title_array) == $searched_element_index) {
117  return $parent_ref_id;
118  }
119 
120  // Search if any child of the given ref has the name of the given searched element
121  foreach ($DIC->repositoryTree()->getChildIds($parent_ref_id) as $child_ref) {
122  $child_obj_id = ilObject::_lookupObjectId($child_ref);
123  $child_title = strtolower(ilObject::_lookupTitle($child_obj_id));
124  if ($path_title_array[$searched_element_index] == $child_title) {
125  if (count($path_title_array) - 1 == $searched_element_index) {
126  // Last element found. Return ref_id
127  return $child_ref;
128  } else {
129  // Search next element in path
130  return self::iterateRecursiveThroughTree($path_title_array, $searched_element_index + 1, $child_ref);
131  }
132  }
133  }
134 
135  return -1;
136  }
137 }
global $DIC
Definition: saml.php:7
static getRefIdForGivenRootAndPath(int $start_ref, string $path_from_startnode)
static _lookupTitle($a_id)
lookup object title
static _lookupObjectId($a_ref_id)
lookup object id
static getRefIdForWebDAVPath($a_uri)
Returns the ref_id of the given webdav path.
Class ilWebDAVTree.
static iterateRecursiveThroughTree($path_title_array, $searched_element_index, $parent_ref_id)
Recursive function to iterate through tree with given path.