ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
ilCloudFileTree Class Reference

ilCloudFileTree class More...

+ Collaboration diagram for ilCloudFileTree:

Public Member Functions

 __construct ($root_path="/", $root_id="root", $id, $service_name)
 
 getId ()
 
 getRootPath ()
 
 getServiceName ()
 
 isCaseSensitive ()
 
 setCaseSensitive ($case_sensitive)
 
 getRootNode ()
 
 addNode ($path, $id, $is_Dir, $modified=null, $size=0)
 
 removeNode ($path)
 
 getItemList ()
 
 getNodeFromPath ($path="/")
 
 getNodeFromId ($id)
 
 setLoadingOfFolderComplete ($path)
 
 updateFileTree ($current_path)
 
 addItemsFromService ($folder_id)
 
 addFolderToService ($id, $folder_name)
 
 uploadFileToService ($current_id, $tmp_name, $file_name)
 
 deleteFromService ($id)
 
 downloadFromService ($id)
 
 storeFileTreeToSession ()
 
 orderListAlphabet ($path1, $path2)
 
 getSortedListOfChildren (ilCloudFileNode $node)
 
 getListForJSONEncode ()
 

Static Public Member Functions

static getFileTreeFromSession ()
 
static clearFileTreeSession ()
 

Protected Member Functions

 setId ($id)
 
 setRootPath ($path="/")
 
 setServiceName ($service_name)
 
 createNode ($path="/", $id, $is_dir=false)
 

Protected Attributes

 $id = 0
 
 $root_node = null
 
 $root_path = ""
 
 $item_list = array()
 
 $id_to_path_map = array()
 Only for better performance. More...
 
 $service_name = ""
 
 $case_sensitive = false
 

Detailed Description

ilCloudFileTree class

Representation of the structure of all files and folders so far. Not really a tree but a list simulating a tree (for faster access on the nodes). This class also calls the functions of a service to update the tree (addToFileTree, deleteItem, etc.)

Author
Timon Amstutz timon.nosp@m..ams.nosp@m.tutz@.nosp@m.ilub.nosp@m..unib.nosp@m.e.ch
Version
$Id$

Definition at line 20 of file class.ilCloudFileTree.php.

Constructor & Destructor Documentation

◆ __construct()

ilCloudFileTree::__construct (   $root_path = "/",
  $root_id = "root",
  $id,
  $service_name 
)
Parameters
string$root_path
string$root_id
int$id
string$service_name
bool$case_sensitive

Definition at line 66 of file class.ilCloudFileTree.php.

References $id, $root_path, $service_name, createNode(), ilCloudConnector\getServiceClass(), setCaseSensitive(), setId(), and setServiceName().

67  {
68  $this->setId($id);
69  $this->root_node = $this->createNode($root_path, $root_id, true);
72  $this->setCaseSensitive($service->isCaseSensitive());
73  }
setServiceName($service_name)
createNode($path="/", $id, $is_dir=false)
static getServiceClass($service_name, $obj_id, $connect=true)
setCaseSensitive($case_sensitive)
+ Here is the call graph for this function:

Member Function Documentation

◆ addFolderToService()

ilCloudFileTree::addFolderToService (   $id,
  $folder_name 
)
Parameters
$id
$folder_name
Exceptions
ilCloudException

Definition at line 313 of file class.ilCloudFileTree.php.

References $id, $path, addItemsFromService(), ilCloudException\FOLDER_ALREADY_EXISTING_ON_SERVICE, ilCloudException\FOLDER_CREATION_FAILED, getId(), getNodeFromId(), getNodeFromPath(), ilCloudConnector\getServiceClass(), getServiceName(), ilCloudException\INVALID_INPUT, ilCloudUtil\joinPaths(), ilCloudUtil\normalizePath(), and storeFileTreeToSession().

314  {
315  try
316  {
317  if ($folder_name == null)
318  {
319  throw new ilCloudException(ilCloudException::INVALID_INPUT, $folder_name);
320  }
321  $current_node = $this->getNodeFromId($id);
322  $path = ilCloudUtil::joinPaths($current_node->getPath(), ilCloudUtil::normalizePath($folder_name));
323 
324  if($this->getNodeFromPath($path) != null)
325  {
327  }
328 
329 
330  $current_node->setLoadingComplete(false);
331  $this->storeFileTreeToSession();
332 
333  $service = ilCloudConnector::getServiceClass($this->getServiceName(), $this->getId());
334  $service->createFolder($path, $this);
335 
336  $this->addItemsFromService($current_node->getId());
337  $new_path = ilCloudUtil::joinPaths($current_node->getPath(), $folder_name);
338  $new_node = $this->getNodeFromPath($new_path);
339  return $new_node;
340 
341  } catch (Exception $e)
342  {
343  if ($e instanceof ilCloudException)
344  {
345  throw $e;
346  }
347  throw new ilCloudException(ilCloudException::FOLDER_CREATION_FAILED, $e->getMessage());
348  }
349 
350  }
$path
Definition: aliased.php:25
static joinPaths($path1, $path2)
static getServiceClass($service_name, $obj_id, $connect=true)
addItemsFromService($folder_id)
Class ilCloudException.
static normalizePath($path)
+ Here is the call graph for this function:

◆ addItemsFromService()

ilCloudFileTree::addItemsFromService (   $folder_id)
Parameters
$path
Exceptions
ilCloudException

Definition at line 287 of file class.ilCloudFileTree.php.

References ilCloudException\ADD_ITEMS_FROM_SERVICE_FAILED, getId(), getNodeFromId(), ilCloudConnector\getServiceClass(), getServiceName(), and ilCloudException\ID_DOES_NOT_EXIST_IN_FILE_TREE_IN_SESSION.

Referenced by addFolderToService(), and updateFileTree().

288  {
289  try
290  {
291  $node = $this->getNodeFromId($folder_id);
292  if(!$node)
293  {
295  }
296  $service = ilCloudConnector::getServiceClass($this->getServiceName(), $this->getId());
297  $service->addToFileTree($this, $node->getPath());
298  } catch (Exception $e)
299  {
300  if ($e instanceof ilCloudException)
301  {
302  throw $e;
303  }
304  throw new ilCloudException(ilCloudException::ADD_ITEMS_FROM_SERVICE_FAILED,$e->getMessage());
305  }
306  }
const ID_DOES_NOT_EXIST_IN_FILE_TREE_IN_SESSION
static getServiceClass($service_name, $obj_id, $connect=true)
Class ilCloudException.
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ addNode()

ilCloudFileTree::addNode (   $path,
  $id,
  $is_Dir,
  $modified = null,
  $size = 0 
)
Parameters
$path
$is_Dir
null$modified
int$size
Returns
ilCloudFileNode

Definition at line 169 of file class.ilCloudFileTree.php.

References $id, $path, $size, createNode(), getNodeFromId(), getNodeFromPath(), ilCloudException\ID_ALREADY_EXISTS_IN_FILE_TREE_IN_SESSION, ilCloudUtil\normalizePath(), and ilCloudException\PATH_DOES_NOT_EXIST_IN_FILE_TREE_IN_SESSION.

170  {
172  $node = $this->getNodeFromPath($path);
173 
174  //node does not yet exist
175  if (!$node)
176  {
177  if ($this->getNodeFromId($id))
178  {
180  }
181  $path_of_parent = ilCloudUtil::normalizePath(dirname($path));
182  $node_parent = $this->getNodeFromPath($path_of_parent);
183  if(!$node_parent)
184  {
186  }
187  $node = $this->createNode($path, $id, $is_Dir);
188  $node->setParentId($node_parent->getId());
189  $node_parent->addChild($node->getPath());
190  }
191 
192  $node->setSize($size);
193  $node->setModified($modified);
194 
195  return $node;
196 
197  }
const PATH_DOES_NOT_EXIST_IN_FILE_TREE_IN_SESSION
$path
Definition: aliased.php:25
$size
Definition: RandomTest.php:79
createNode($path="/", $id, $is_dir=false)
const ID_ALREADY_EXISTS_IN_FILE_TREE_IN_SESSION
Class ilCloudException.
static normalizePath($path)
+ Here is the call graph for this function:

◆ clearFileTreeSession()

static ilCloudFileTree::clearFileTreeSession ( )
static

Definition at line 457 of file class.ilCloudFileTree.php.

References $_SESSION.

458  {
459  $_SESSION['ilCloudFileTree'] = null;
460  }
$_SESSION["AccountId"]

◆ createNode()

ilCloudFileTree::createNode (   $path = "/",
  $id,
  $is_dir = false 
)
protected
Parameters
string$path
bool$is_dir
Returns
ilCloudFileNode

Definition at line 153 of file class.ilCloudFileTree.php.

References $id, $path, and ilCloudUtil\normalizePath().

Referenced by __construct(), and addNode().

154  {
156  $this->item_list[$node->getPath()] = $node;
157  $this->id_to_path_map[$node->getId()] = $node->getPath();
158  $node->setIsDir($is_dir);
159  return $node;
160  }
$path
Definition: aliased.php:25
static normalizePath($path)
ilCloudFileTree class
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ deleteFromService()

ilCloudFileTree::deleteFromService (   $id)
Parameters
$id
Exceptions
ilCloudException

Definition at line 394 of file class.ilCloudFileTree.php.

References $id, ilCloudException\DELETE_FAILED, getId(), getNodeFromId(), ilCloudConnector\getServiceClass(), getServiceName(), removeNode(), and storeFileTreeToSession().

395  {
396  $item_node = $this->getNodeFromId($id);
397 
398  try
399  {
400  $service = ilCloudConnector::getServiceClass($this->getServiceName(), $this->getId());
401  $service->deleteItem($item_node->getPath(), $this);
402  $this->removeNode($item_node->getPath());
403  $this->storeFileTreeToSession();
404  } catch (Exception $e)
405  {
406  if ($e instanceof ilCloudException)
407  {
408  throw $e;
409  }
410  throw new ilCloudException(ilCloudException::DELETE_FAILED, $e->getMessage());
411  }
412  }
static getServiceClass($service_name, $obj_id, $connect=true)
Class ilCloudException.
+ Here is the call graph for this function:

◆ downloadFromService()

ilCloudFileTree::downloadFromService (   $id)
Parameters
$id
Exceptions
ilCloudException

Definition at line 418 of file class.ilCloudFileTree.php.

References $id, ilCloudException\DOWNLOAD_FAILED, getId(), getNodeFromId(), ilCloudConnector\getServiceClass(), and getServiceName().

419  {
420  try
421  {
422  $service = ilCloudConnector::getServiceClass($this->getServiceName(), $this->getId());
423  $node = $this->getNodeFromId($id);
424  $service->getFile($node->getPath(), $this);
425  } catch (Exception $e)
426  {
427  if ($e instanceof ilCloudException)
428  {
429  throw $e;
430  }
431  throw new ilCloudException(ilCloudException::DOWNLOAD_FAILED, $e->getMessage());
432  }
433  }
static getServiceClass($service_name, $obj_id, $connect=true)
Class ilCloudException.
+ Here is the call graph for this function:

◆ getFileTreeFromSession()

static ilCloudFileTree::getFileTreeFromSession ( )
static
Returns
ilCloudFileTree fileTree;

Definition at line 444 of file class.ilCloudFileTree.php.

References $_SESSION.

Referenced by ilCloudPluginDeleteGUI\asyncDeleteItem(), ilObjCloudGUI\asyncGetActionListContent(), ilObjCloudGUI\asyncGetBlock(), ilCloudPluginCreateFolderGUI\createFolder(), ilCloudPluginDeleteGUI\deleteItem(), ilObjCloudGUI\executeCommand(), ilObjCloudGUI\getFile(), and ilCloudPluginUploadGUI\handleFileUpload().

445  {
446  if(isset($_SESSION['ilCloudFileTree']))
447  {
448  return unserialize($_SESSION['ilCloudFileTree']);
449  }
450  else
451  {
452  return false;
453  }
454 
455  }
$_SESSION["AccountId"]
+ Here is the caller graph for this function:

◆ getId()

ilCloudFileTree::getId ( )
Returns
int

Definition at line 86 of file class.ilCloudFileTree.php.

References $id.

Referenced by addFolderToService(), addItemsFromService(), deleteFromService(), downloadFromService(), and uploadFileToService().

87  {
88  return $this->id;
89  }
+ Here is the caller graph for this function:

◆ getItemList()

ilCloudFileTree::getItemList ( )
Returns
array

Definition at line 214 of file class.ilCloudFileTree.php.

References $item_list.

Referenced by getListForJSONEncode().

215  {
216  return $this->item_list;
217  }
+ Here is the caller graph for this function:

◆ getListForJSONEncode()

ilCloudFileTree::getListForJSONEncode ( )
Returns
array

Definition at line 494 of file class.ilCloudFileTree.php.

References $path, array, and getItemList().

495  {
496  $list = array();
497  foreach ($this->getItemList() as $path => $node)
498  {
499  $list[$node->getId()] = $node->getJSONEncode();
500  }
501  return $list;
502  }
$path
Definition: aliased.php:25
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ getNodeFromId()

ilCloudFileTree::getNodeFromId (   $id)
Parameters
$id
Returns
bool|ilCloudFileNode

Definition at line 245 of file class.ilCloudFileTree.php.

References $id.

Referenced by addFolderToService(), addItemsFromService(), addNode(), deleteFromService(), downloadFromService(), removeNode(), and uploadFileToService().

246  {
247  return $this->item_list[$this->id_to_path_map[$id]];
248  }
+ Here is the caller graph for this function:

◆ getNodeFromPath()

ilCloudFileTree::getNodeFromPath (   $path = "/")
Parameters
string$path
Returns
ilCloudFileNode node;

Definition at line 223 of file class.ilCloudFileTree.php.

References $path, and isCaseSensitive().

Referenced by addFolderToService(), addNode(), orderListAlphabet(), removeNode(), setLoadingOfFolderComplete(), and updateFileTree().

224  {
225  if (!$this->isCaseSensitive() || $this->item_list[$path])
226  {
227  return $this->item_list[$path];
228  }
229 
230  foreach (array_keys($this->item_list) as $item)
231  {
232  if (strtolower($item) == strtolower($path))
233  {
234  return $this->item_list[$item];
235  }
236  }
237 
238  return null;
239  }
$path
Definition: aliased.php:25
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getRootNode()

ilCloudFileTree::getRootNode ( )
Returns
ilCloudFileNode|null

Definition at line 143 of file class.ilCloudFileTree.php.

References $root_node.

144  {
145  return $this->root_node;
146  }

◆ getRootPath()

ilCloudFileTree::getRootPath ( )
Returns
string

Definition at line 103 of file class.ilCloudFileTree.php.

References $root_path.

104  {
105  return $this->root_path;
106  }

◆ getServiceName()

ilCloudFileTree::getServiceName ( )
Returns
string

Definition at line 119 of file class.ilCloudFileTree.php.

References $service_name.

Referenced by addFolderToService(), addItemsFromService(), deleteFromService(), downloadFromService(), and uploadFileToService().

120  {
121  return $this->service_name;
122  }
+ Here is the caller graph for this function:

◆ getSortedListOfChildren()

ilCloudFileTree::getSortedListOfChildren ( ilCloudFileNode  $node)
Parameters
ilCloudFileNode$node
Returns
array|null

Definition at line 484 of file class.ilCloudFileTree.php.

References array, and ilCloudFileNode\getChildrenPathes().

485  {
486  $children = $node->getChildrenPathes();
487  usort($children, array("ilCloudFileTree", "orderListAlphabet"));
488  return $children;
489  }
Create styles array
The data for the language used.
+ Here is the call graph for this function:

◆ isCaseSensitive()

ilCloudFileTree::isCaseSensitive ( )
Returns
boolean

Definition at line 127 of file class.ilCloudFileTree.php.

References $case_sensitive.

Referenced by getNodeFromPath().

128  {
129  return $this->case_sensitive;
130  }
+ Here is the caller graph for this function:

◆ orderListAlphabet()

ilCloudFileTree::orderListAlphabet (   $path1,
  $path2 
)
Parameters
$path1
$path2
Returns
int

Definition at line 467 of file class.ilCloudFileTree.php.

References getNodeFromPath().

468  {
469  $node1 = $this->getNodeFromPath($path1);
470  $node2 = $this->getNodeFromPath($path2);
471  if ($node1->getIsDir() != $node2->getIsDir())
472  {
473  return $node2->getIsDir() ? +1 : -1;
474  }
475  $nameNode1 = strtolower(basename($node1->getPath()));
476  $nameNode2 = strtolower(basename($node2->getPath()));
477  return ($nameNode1 > $nameNode2) ? +1 : -1;
478  }
+ Here is the call graph for this function:

◆ removeNode()

ilCloudFileTree::removeNode (   $path)
Parameters
$path

Definition at line 202 of file class.ilCloudFileTree.php.

References $path, getNodeFromId(), and getNodeFromPath().

Referenced by deleteFromService().

203  {
204  $node = $this->getNodeFromPath($path);
205  $parent = $this->getNodeFromId($node->getParentId());
206  $parent->removeChild($path);
207  unset($this->item_list[$node->getPath()]);
208  unset($this->id_to_path_map[$node->getId()]);
209  }
$path
Definition: aliased.php:25
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ setCaseSensitive()

ilCloudFileTree::setCaseSensitive (   $case_sensitive)
Parameters
boolean$case_sensitive

Definition at line 135 of file class.ilCloudFileTree.php.

References $case_sensitive.

Referenced by __construct().

136  {
137  $this->case_sensitive = $case_sensitive;
138  }
+ Here is the caller graph for this function:

◆ setId()

ilCloudFileTree::setId (   $id)
protected
Parameters
int$id

Definition at line 78 of file class.ilCloudFileTree.php.

References $id.

Referenced by __construct().

79  {
80  $this->id = $id;
81  }
+ Here is the caller graph for this function:

◆ setLoadingOfFolderComplete()

ilCloudFileTree::setLoadingOfFolderComplete (   $path)
Parameters
$path
Exceptions
ilCloudException

Definition at line 254 of file class.ilCloudFileTree.php.

References $path, getNodeFromPath(), and ilCloudException\PATH_DOES_NOT_EXIST_IN_FILE_TREE_IN_SESSION.

255  {
256  $node = $this->getNodeFromPath($path);
257  if(!$node)
258  {
260  }
261  $node->setLoadingComplete(true);
262  }
const PATH_DOES_NOT_EXIST_IN_FILE_TREE_IN_SESSION
$path
Definition: aliased.php:25
Class ilCloudException.
+ Here is the call graph for this function:

◆ setRootPath()

ilCloudFileTree::setRootPath (   $path = "/")
protected
Parameters
string$path

Definition at line 95 of file class.ilCloudFileTree.php.

References $path, and ilCloudUtil\normalizePath().

96  {
97  $this->root_path = ilCloudUtil::normalizePath($path);
98  }
$path
Definition: aliased.php:25
static normalizePath($path)
+ Here is the call graph for this function:

◆ setServiceName()

ilCloudFileTree::setServiceName (   $service_name)
protected
Parameters
string$service_name

Definition at line 111 of file class.ilCloudFileTree.php.

References $service_name.

Referenced by __construct().

112  {
113  $this->service_name = $service_name;
114  }
+ Here is the caller graph for this function:

◆ storeFileTreeToSession()

ilCloudFileTree::storeFileTreeToSession ( )

Definition at line 435 of file class.ilCloudFileTree.php.

References $_SESSION.

Referenced by addFolderToService(), deleteFromService(), ilCloudPluginInitGUI\initGUI(), updateFileTree(), and uploadFileToService().

436  {
437  $_SESSION['ilCloudFileTree'] = null;
438  $_SESSION['ilCloudFileTree'] = serialize($this);
439  }
$_SESSION["AccountId"]
+ Here is the caller graph for this function:

◆ updateFileTree()

ilCloudFileTree::updateFileTree (   $current_path)
Parameters
$current_path

Definition at line 267 of file class.ilCloudFileTree.php.

References addItemsFromService(), getNodeFromPath(), and storeFileTreeToSession().

268  {
269  $node = $this->getNodeFromPath($current_path);
270 
271  if (!$node)
272  {
273  $this->updateFileTree(dirname($current_path));
274  $node = $this->getNodeFromPath($current_path);
275  }
276  if (!$node->getLoadingComplete())
277  {
278  $this->addItemsFromService($node->getId());
279  }
280  $this->storeFileTreeToSession();
281  }
updateFileTree($current_path)
addItemsFromService($folder_id)
+ Here is the call graph for this function:

◆ uploadFileToService()

ilCloudFileTree::uploadFileToService (   $current_id,
  $tmp_name,
  $file_name 
)
Parameters
$id
$tmp_name
$file_name
Exceptions
ilCloudException

Definition at line 358 of file class.ilCloudFileTree.php.

References getId(), getNodeFromId(), ilCloudConnector\getPluginClass(), ilCloudConnector\getServiceClass(), getServiceName(), storeFileTreeToSession(), ilCloudException\UPLOAD_FAILED, and ilCloudException\UPLOAD_FAILED_MAX_FILESIZE.

359  {
360  $plugin = ilCloudConnector::getPluginClass($this->getServiceName(), $this->getId());
361  $max_file_size = $plugin->getMaxFileSize();
362 
363  if($max_file_size >= filesize($tmp_name)/(1024 * 1024))
364  {
365  $current_node = $this->getNodeFromId($current_id);
366 
367  $current_node->setLoadingComplete(false);
368  $this->storeFileTreeToSession();
369 
370  try
371  {
372  $service = ilCloudConnector::getServiceClass($this->getServiceName(), $this->getId());
373  $service->putFile($tmp_name, $file_name, $current_node->getPath(), $this);
374 
375  } catch (Exception $e)
376  {
377  if ($e instanceof ilCloudException)
378  {
379  throw $e;
380  }
381  throw new ilCloudException(ilCloudException::UPLOAD_FAILED, $e->getMessage());
382  }
383  }
384  else
385  {
386  throw new ilCloudException(ilCloudException::UPLOAD_FAILED_MAX_FILESIZE, filesize($tmp_name) / (1024 * 1024) . " MB");
387  }
388  }
static getPluginClass($service_name, $obj_id)
static getServiceClass($service_name, $obj_id, $connect=true)
Class ilCloudException.
+ Here is the call graph for this function:

Field Documentation

◆ $case_sensitive

ilCloudFileTree::$case_sensitive = false
protected

Definition at line 57 of file class.ilCloudFileTree.php.

Referenced by isCaseSensitive(), and setCaseSensitive().

◆ $id

ilCloudFileTree::$id = 0
protected

◆ $id_to_path_map

ilCloudFileTree::$id_to_path_map = array()
protected

Only for better performance.

Definition at line 47 of file class.ilCloudFileTree.php.

◆ $item_list

ilCloudFileTree::$item_list = array()
protected

Definition at line 42 of file class.ilCloudFileTree.php.

Referenced by getItemList().

◆ $root_node

ilCloudFileTree::$root_node = null
protected

Definition at line 32 of file class.ilCloudFileTree.php.

Referenced by getRootNode().

◆ $root_path

ilCloudFileTree::$root_path = ""
protected

Definition at line 38 of file class.ilCloudFileTree.php.

Referenced by __construct(), and getRootPath().

◆ $service_name

string ilCloudFileTree::$service_name = ""
protected

Definition at line 52 of file class.ilCloudFileTree.php.

Referenced by __construct(), getServiceName(), and setServiceName().


The documentation for this class was generated from the following file: