ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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)
 
 addIdBasedNode ($path, $id, $parent_id, $is_Dir, $modified=null, $size=0)
 Add node that relies on id's. More...
 
 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.

67 {
68 $this->setId($id);
69 $this->root_node = $this->createNode($root_path, $root_id, true);
72 $this->setCaseSensitive($service->isCaseSensitive());
73 }
static getServiceClass($service_name, $obj_id, $connect=true)
setCaseSensitive($case_sensitive)
createNode($path="/", $id, $is_dir=false)
setServiceName($service_name)
$service
Definition: login.php:15

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

+ Here is the call graph for this function:

Member Function Documentation

◆ addFolderToService()

ilCloudFileTree::addFolderToService (   $id,
  $folder_name 
)
Parameters
$id
$folder_name
Returns
bool|ilCloudFileNode|null
Exceptions
ilCloudException

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

351 {
352 try {
353 if ($folder_name == null) {
354 throw new ilCloudException(ilCloudException::INVALID_INPUT, $folder_name);
355 }
356 $current_node = $this->getNodeFromId($id);
357 $path = ilCloudUtil::joinPaths($current_node->getPath(), ilCloudUtil::normalizePath($folder_name));
358
359 if ($this->getNodeFromPath($path) != null) {
361 }
362
363
364 $current_node->setLoadingComplete(false);
365 $this->storeFileTreeToSession();
366
368
369 $new_folder_id = $service->createFolderById($id, $folder_name);
370 $new_node = null;
371
372 if (is_null($new_folder_id) || !$new_folder_id) {
373 // Use path
374 $service->createFolder($path, $this);
375 $this->addItemsFromService($current_node->getId());
376 $new_path = ilCloudUtil::joinPaths($current_node->getPath(), $folder_name);
377 $new_node = $this->getNodeFromPath($new_path);
378 } else {
379 // Use id
380 $this->addItemsFromService($current_node->getId());
381 $new_node = $this->getNodeFromId($new_folder_id);
382 }
383
384 return $new_node;
385 } catch (Exception $e) {
386 if ($e instanceof ilCloudException) {
387 throw $e;
388 }
390 }
391 }
Class ilCloudException.
addItemsFromService($folder_id)
static normalizePath($path)
static joinPaths($path1, $path2)

References $id, $path, $service, 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().

+ Here is the call graph for this function:

◆ addIdBasedNode()

ilCloudFileTree::addIdBasedNode (   $path,
  $id,
  $parent_id,
  $is_Dir,
  $modified = null,
  $size = 0 
)

Add node that relies on id's.

Parameters
$path
$id
$parent_id
$is_Dir
null$modified
int$size
Returns
ilCloudFileNode
Exceptions
ilCloudException

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

210 {
212 $node = $this->getNodeFromPath($path);
213
214 //node does not yet exist
215 if (!$node) {
216 $nodeFromId = $this->getNodeFromId($id);
217 // If path isn't found but id is there -> Path got changed
218 if ($nodeFromId) {
219 // Adjust path
220 $nodeFromId->setPath($path);
221 }
222
223 $node_parent = $this->getNodeFromId($parent_id);
224 if (!$node_parent) {
226 }
227 $node = $this->createNode($path, $id, $is_Dir);
228 $node->setParentId($node_parent->getId());
229 $node_parent->addChild($node->getPath());
230 }
231
232 $node->setSize($size);
233 $node->setModified($modified);
234
235 return $node;
236 }
$size
Definition: RandomTest.php:84
const PATH_DOES_NOT_EXIST_IN_FILE_TREE_IN_SESSION

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

+ Here is the call graph for this function:

◆ addItemsFromService()

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

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

324 {
325 try {
326 $node = $this->getNodeFromId($folder_id);
327 if (!$node) {
329 }
331 if (!$service->addToFileTreeWithId($this, $node->getId())) {
332 $service->addToFileTree($this, $node->getPath());
333 }
334 } catch (Exception $e) {
335 if ($e instanceof ilCloudException) {
336 throw $e;
337 }
339 }
340 }
const ID_DOES_NOT_EXIST_IN_FILE_TREE_IN_SESSION

References $service, 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().

+ 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.

170 {
172 $node = $this->getNodeFromPath($path);
173
174 //node does not yet exist
175 if (!$node) {
176 if ($this->getNodeFromId($id)) {
178 }
179 $path_of_parent = ilCloudUtil::normalizePath(dirname($path));
180 $node_parent = $this->getNodeFromPath($path_of_parent);
181 if (!$node_parent) {
183 }
184 $node = $this->createNode($path, $id, $is_Dir);
185 $node->setParentId($node_parent->getId());
186 $node_parent->addChild($node->getPath());
187 }
188
189 $node->setSize($size);
190 $node->setModified($modified);
191
192 return $node;
193 }
const ID_ALREADY_EXISTS_IN_FILE_TREE_IN_SESSION

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.

+ Here is the call graph for this function:

◆ clearFileTreeSession()

static ilCloudFileTree::clearFileTreeSession ( )
static

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

494 {
495 $_SESSION['ilCloudFileTree'] = null;
496 }
$_SESSION["AccountId"]

References $_SESSION.

◆ 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.

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 }
ilCloudFileTree class

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

Referenced by __construct(), addIdBasedNode(), and addNode().

+ 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 432 of file class.ilCloudFileTree.php.

433 {
434 $item_node = $this->getNodeFromId($id);
435
436 try {
438
439 if (!$service->deleteItemById($item_node->getId())) {
440 $service->deleteItem($item_node->getPath(), $this);
441 }
442
443 $this->removeNode($item_node->getPath());
444 $this->storeFileTreeToSession();
445 } catch (Exception $e) {
446 if ($e instanceof ilCloudException) {
447 throw $e;
448 }
449 throw new ilCloudException(ilCloudException::DELETE_FAILED, $e->getMessage());
450 }
451 }

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

+ Here is the call graph for this function:

◆ downloadFromService()

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

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

458 {
459 try {
461 $node = $this->getNodeFromId($id);
462
463 if (!$service->getFileById($node->getId())) {
464 $service->getFile($node->getPath(), $this);
465 }
466 } catch (Exception $e) {
467 if ($e instanceof ilCloudException) {
468 throw $e;
469 }
470 throw new ilCloudException(ilCloudException::DOWNLOAD_FAILED, $e->getMessage());
471 }
472 }

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

+ Here is the call graph for this function:

◆ getFileTreeFromSession()

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

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

484 {
485 if (isset($_SESSION['ilCloudFileTree'])) {
486 return unserialize($_SESSION['ilCloudFileTree']);
487 } else {
488 return false;
489 }
490 }

References $_SESSION.

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

+ Here is the caller graph for this function:

◆ getId()

ilCloudFileTree::getId ( )
Returns
int

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

87 {
88 return $this->id;
89 }

References $id.

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

+ Here is the caller graph for this function:

◆ getItemList()

ilCloudFileTree::getItemList ( )
Returns
array

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

255 {
256 return $this->item_list;
257 }

References $item_list.

Referenced by getListForJSONEncode().

+ Here is the caller graph for this function:

◆ getListForJSONEncode()

ilCloudFileTree::getListForJSONEncode ( )
Returns
array

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

530 {
531 $list = array();
532 foreach ($this->getItemList() as $path => $node) {
533 $list[$node->getId()] = $node->getJSONEncode();
534 }
535 return $list;
536 }
if(isset($_REQUEST['delete'])) $list
Definition: registry.php:41

References $list, $path, and getItemList().

+ Here is the call graph for this function:

◆ getNodeFromId()

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

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

283 {
284 return $this->item_list[$this->id_to_path_map[$id]];
285 }

References $id.

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

+ Here is the caller graph for this function:

◆ getNodeFromPath()

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

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

264 {
265 if (!$this->isCaseSensitive() || $this->item_list[$path]) {
266 return $this->item_list[$path];
267 }
268
269 foreach (array_keys($this->item_list) as $item) {
270 if (strtolower($item) == strtolower($path)) {
271 return $this->item_list[$item];
272 }
273 }
274
275 return null;
276 }

References $path, and isCaseSensitive().

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

+ 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.

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

References $root_node.

◆ getRootPath()

ilCloudFileTree::getRootPath ( )
Returns
string

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

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

References $root_path.

◆ getServiceName()

ilCloudFileTree::getServiceName ( )
Returns
string

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

120 {
121 return $this->service_name;
122 }

References $service_name.

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

+ Here is the caller graph for this function:

◆ getSortedListOfChildren()

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

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

520 {
521 $children = $node->getChildrenPathes();
522 usort($children, array("ilCloudFileTree", "orderListAlphabet"));
523 return $children;
524 }

References ilCloudFileNode\getChildrenPathes().

+ Here is the call graph for this function:

◆ isCaseSensitive()

ilCloudFileTree::isCaseSensitive ( )
Returns
boolean

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

128 {
130 }

References $case_sensitive.

Referenced by getNodeFromPath().

+ Here is the caller graph for this function:

◆ orderListAlphabet()

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

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

504 {
505 $node1 = $this->getNodeFromPath($path1);
506 $node2 = $this->getNodeFromPath($path2);
507 if ($node1->getIsDir() != $node2->getIsDir()) {
508 return $node2->getIsDir() ? +1 : -1;
509 }
510 $nameNode1 = strtolower(basename($node1->getPath()));
511 $nameNode2 = strtolower(basename($node2->getPath()));
512 return ($nameNode1 > $nameNode2) ? +1 : -1;
513 }

References getNodeFromPath().

+ Here is the call graph for this function:

◆ removeNode()

ilCloudFileTree::removeNode (   $path)
Parameters
$path

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

243 {
244 $node = $this->getNodeFromPath($path);
245 $parent = $this->getNodeFromId($node->getParentId());
246 $parent->removeChild($path);
247 unset($this->item_list[$node->getPath()]);
248 unset($this->id_to_path_map[$node->getId()]);
249 }

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

Referenced by deleteFromService().

+ 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.

136 {
137 $this->case_sensitive = $case_sensitive;
138 }

References $case_sensitive.

Referenced by __construct().

+ 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.

79 {
80 $this->id = $id;
81 }

References $id.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ setLoadingOfFolderComplete()

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

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

292 {
293 $node = $this->getNodeFromPath($path);
294 if (!$node) {
296 }
297 $node->setLoadingComplete(true);
298 }

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

+ 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.

96 {
97 $this->root_path = ilCloudUtil::normalizePath($path);
98 }

References $path, and ilCloudUtil\normalizePath().

+ 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.

112 {
113 $this->service_name = $service_name;
114 }

References $service_name.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ storeFileTreeToSession()

ilCloudFileTree::storeFileTreeToSession ( )

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

475 {
476 $_SESSION['ilCloudFileTree'] = null;
477 $_SESSION['ilCloudFileTree'] = serialize($this);
478 }

References $_SESSION.

Referenced by addFolderToService(), deleteFromService(), updateFileTree(), and uploadFileToService().

+ Here is the caller graph for this function:

◆ updateFileTree()

ilCloudFileTree::updateFileTree (   $current_path)
Parameters
$current_path

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

304 {
305 $node = $this->getNodeFromPath($current_path);
306
307 if (!$node) {
308 $this->updateFileTree(dirname($current_path));
309 $node = $this->getNodeFromPath($current_path);
310 }
311 if (!$node->getLoadingComplete()) {
312 $this->addItemsFromService($node->getId());
313 }
314 $this->storeFileTreeToSession();
315 }
updateFileTree($current_path)

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

Referenced by updateFileTree().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ uploadFileToService()

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

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

402 {
403 $plugin = ilCloudConnector::getPluginClass($this->getServiceName(), $this->getId());
404 $max_file_size = $plugin->getMaxFileSize();
405
406 if ($max_file_size >= filesize($tmp_name)/(1024 * 1024)) {
407 $current_node = $this->getNodeFromId($current_id);
408
409 $current_node->setLoadingComplete(false);
410 $this->storeFileTreeToSession();
411
412 try {
414 if (!$service->putFileById($tmp_name, $file_name, $current_node->getId(), $this)) {
415 $service->putFile($tmp_name, $file_name, $current_node->getPath(), $this);
416 }
417 } catch (Exception $e) {
418 if ($e instanceof ilCloudException) {
419 throw $e;
420 }
421 throw new ilCloudException(ilCloudException::UPLOAD_FAILED, $e->getMessage());
422 }
423 } else {
424 throw new ilCloudException(ilCloudException::UPLOAD_FAILED_MAX_FILESIZE, filesize($tmp_name) / (1024 * 1024) . " MB");
425 }
426 }
static getPluginClass($service_name, $obj_id)

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

+ 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

◆ $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: