ILIAS  Release_5_0_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
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.
 $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

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().

{
$this->setId($id);
$this->root_node = $this->createNode($root_path, $root_id, true);
$this->setCaseSensitive($service->isCaseSensitive());
}

+ Here is the call graph for this function:

Member Function Documentation

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().

{
try
{
if ($folder_name == null)
{
}
$current_node = $this->getNodeFromId($id);
$path = ilCloudUtil::joinPaths($current_node->getPath(), ilCloudUtil::normalizePath($folder_name));
if($this->getNodeFromPath($path) != null)
{
}
$current_node->setLoadingComplete(false);
$service = ilCloudConnector::getServiceClass($this->getServiceName(), $this->getId());
$service->createFolder($path, $this);
$this->addItemsFromService($current_node->getId());
$new_path = ilCloudUtil::joinPaths($current_node->getPath(), $folder_name);
$new_node = $this->getNodeFromPath($new_path);
return $new_node;
} catch (Exception $e)
{
if ($e instanceof ilCloudException)
{
throw $e;
}
throw new ilCloudException(ilCloudException::FOLDER_CREATION_FAILED, $e->getMessage());
}
}

+ Here is the call graph for this function:

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().

{
try
{
$node = $this->getNodeFromId($folder_id);
if(!$node)
{
}
$service = ilCloudConnector::getServiceClass($this->getServiceName(), $this->getId());
$service->addToFileTree($this, $node->getPath());
} catch (Exception $e)
{
if ($e instanceof ilCloudException)
{
throw $e;
}
throw new ilCloudException(ilCloudException::ADD_ITEMS_FROM_SERVICE_FAILED,$e->getMessage());
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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.

{
$node = $this->getNodeFromPath($path);
//node does not yet exist
if (!$node)
{
if ($this->getNodeFromId($id))
{
}
$path_of_parent = ilCloudUtil::normalizePath(dirname($path));
$node_parent = $this->getNodeFromPath($path_of_parent);
if(!$node_parent)
{
}
$node = $this->createNode($path, $id, $is_Dir);
$node->setParentId($node_parent->getId());
$node_parent->addChild($node->getPath());
}
$node->setSize($size);
$node->setModified($modified);
return $node;
}

+ Here is the call graph for this function:

static ilCloudFileTree::clearFileTreeSession ( )
static

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

References $_SESSION.

{
$_SESSION['ilCloudFileTree'] = null;
}
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().

{
$this->item_list[$node->getPath()] = $node;
$this->id_to_path_map[$node->getId()] = $node->getPath();
$node->setIsDir($is_dir);
return $node;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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().

{
$item_node = $this->getNodeFromId($id);
try
{
$service = ilCloudConnector::getServiceClass($this->getServiceName(), $this->getId());
$service->deleteItem($item_node->getPath(), $this);
$this->removeNode($item_node->getPath());
} catch (Exception $e)
{
if ($e instanceof ilCloudException)
{
throw $e;
}
throw new ilCloudException(ilCloudException::DELETE_FAILED, $e->getMessage());
}
}

+ Here is the call graph for this function:

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().

{
try
{
$service = ilCloudConnector::getServiceClass($this->getServiceName(), $this->getId());
$node = $this->getNodeFromId($id);
$service->getFile($node->getPath(), $this);
} catch (Exception $e)
{
if ($e instanceof ilCloudException)
{
throw $e;
}
throw new ilCloudException(ilCloudException::DOWNLOAD_FAILED, $e->getMessage());
}
}

+ Here is the call graph for this function:

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().

{
if(isset($_SESSION['ilCloudFileTree']))
{
return unserialize($_SESSION['ilCloudFileTree']);
}
else
{
return false;
}
}

+ Here is the caller graph for this function:

ilCloudFileTree::getId ( )
Returns
int

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

References $id.

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

{
return $this->id;
}

+ Here is the caller graph for this function:

ilCloudFileTree::getItemList ( )
Returns
array

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

References $item_list.

Referenced by getListForJSONEncode().

{
}

+ Here is the caller graph for this function:

ilCloudFileTree::getListForJSONEncode ( )
Returns
array

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

References $path, and getItemList().

{
$list = array();
foreach ($this->getItemList() as $path => $node)
{
$list[$node->getId()] = $node->getJSONEncode();
}
return $list;
}

+ Here is the call graph for this function:

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().

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

+ Here is the caller graph for this function:

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().

{
if (!$this->isCaseSensitive() || $this->item_list[$path])
{
return $this->item_list[$path];
}
foreach (array_keys($this->item_list) as $item)
{
if (strtolower($item) == strtolower($path))
{
return $this->item_list[$item];
}
}
return null;
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilCloudFileTree::getRootNode ( )
Returns
ilCloudFileNode|null

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

References $root_node.

{
}
ilCloudFileTree::getRootPath ( )
Returns
string

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

References $root_path.

{
}
ilCloudFileTree::getServiceName ( )
Returns
string

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

References $service_name.

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

{
}

+ Here is the caller graph for this function:

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

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

References ilCloudFileNode\getChildrenPathes().

{
$children = $node->getChildrenPathes();
usort($children, array("ilCloudFileTree", "orderListAlphabet"));
return $children;
}

+ Here is the call graph for this function:

ilCloudFileTree::isCaseSensitive ( )
Returns
boolean

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

References $case_sensitive.

Referenced by getNodeFromPath().

{
}

+ Here is the caller graph for this function:

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

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

References getNodeFromPath().

{
$node1 = $this->getNodeFromPath($path1);
$node2 = $this->getNodeFromPath($path2);
if ($node1->getIsDir() != $node2->getIsDir())
{
return $node2->getIsDir() ? +1 : -1;
}
$nameNode1 = strtolower(basename($node1->getPath()));
$nameNode2 = strtolower(basename($node2->getPath()));
return ($nameNode1 > $nameNode2) ? +1 : -1;
}

+ Here is the call graph for this function:

ilCloudFileTree::removeNode (   $path)
Parameters
$path

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

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

Referenced by deleteFromService().

{
$node = $this->getNodeFromPath($path);
$parent = $this->getNodeFromId($node->getParentId());
$parent->removeChild($path);
unset($this->item_list[$node->getPath()]);
unset($this->id_to_path_map[$node->getId()]);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

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

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

References $case_sensitive.

Referenced by __construct().

{
$this->case_sensitive = $case_sensitive;
}

+ Here is the caller graph for this function:

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

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

References $id.

Referenced by __construct().

{
$this->id = $id;
}

+ Here is the caller graph for this function:

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.

{
$node = $this->getNodeFromPath($path);
if(!$node)
{
}
$node->setLoadingComplete(true);
}

+ Here is the call graph for this function:

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

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

References $path, and ilCloudUtil\normalizePath().

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

+ Here is the call graph for this function:

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

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

References $service_name.

Referenced by __construct().

{
$this->service_name = $service_name;
}

+ Here is the caller graph for this function:

ilCloudFileTree::storeFileTreeToSession ( )

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

References $_SESSION.

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

{
$_SESSION['ilCloudFileTree'] = null;
$_SESSION['ilCloudFileTree'] = serialize($this);
}

+ Here is the caller graph for this function:

ilCloudFileTree::updateFileTree (   $current_path)
Parameters
$current_path

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

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

{
$node = $this->getNodeFromPath($current_path);
if (!$node)
{
$this->updateFileTree(dirname($current_path));
$node = $this->getNodeFromPath($current_path);
}
if (!$node->getLoadingComplete())
{
$this->addItemsFromService($node->getId());
}
}

+ Here is the call graph for this function:

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.

{
$plugin = ilCloudConnector::getPluginClass($this->getServiceName(), $this->getId());
$max_file_size = $plugin->getMaxFileSize();
if($max_file_size >= filesize($tmp_name)/(1024 * 1024))
{
$current_node = $this->getNodeFromId($current_id);
$current_node->setLoadingComplete(false);
try
{
$service = ilCloudConnector::getServiceClass($this->getServiceName(), $this->getId());
$service->putFile($tmp_name, $file_name, $current_node->getPath(), $this);
} catch (Exception $e)
{
if ($e instanceof ilCloudException)
{
throw $e;
}
throw new ilCloudException(ilCloudException::UPLOAD_FAILED, $e->getMessage());
}
}
else
{
throw new ilCloudException(ilCloudException::UPLOAD_FAILED_MAX_FILESIZE, filesize($tmp_name) / (1024 * 1024) . " MB");
}
}

+ Here is the call graph for this function:

Field Documentation

ilCloudFileTree::$case_sensitive = false
protected

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

Referenced by isCaseSensitive(), and setCaseSensitive().

ilCloudFileTree::$id = 0
protected
ilCloudFileTree::$id_to_path_map = array()
protected

Only for better performance.

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

ilCloudFileTree::$item_list = array()
protected

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

Referenced by getItemList().

ilCloudFileTree::$root_node = null
protected

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

Referenced by getRootNode().

ilCloudFileTree::$root_path = ""
protected

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

Referenced by __construct(), and getRootPath().

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: