ILIAS  release_5-4 Revision v5.4.26-12-gabc799a52e6
ilObjContainerDAV Class Reference

Class ilObjContainerDAV. More...

+ Inheritance diagram for ilObjContainerDAV:
+ Collaboration diagram for ilObjContainerDAV:

Public Member Functions

 __construct (ilContainer $a_obj, ilWebDAVRepositoryHelper $repo_helper, ilWebDAVObjDAVHelper $dav_helper)
 Check if given object has valid type and calls parent constructor. More...
 
 createFile ($name, $data=null)
 Creates a new file in the directory. More...
 
 createDirectory ($name)
 Creates a new subdirectory. More...
 
 getChild ($name)
 Returns a specific child node, referenced by its name. More...
 
 getChildren ()
 Returns an array with all the child nodes. More...
 
 childExists ($name)
 Checks if a child-node with the specified name exists. More...
 
 getChildCollectionType ()
 Return the type for child collections of this collection For courses, groups and folders the type is 'fold' For categories the type is 'cat'. More...
 
- Public Member Functions inherited from ilObjectDAV
 __construct (ilObject $a_obj, ilWebDAVRepositoryHelper $repo_helper, ilWebDAVObjDAVHelper $dav_helper)
 Constructor for DAV Object. More...
 
 getRefId ()
 Returns the ref id of this object. More...
 
 getObjectId ()
 Returns the object id of this object. More...
 
 getLastModified ()
 Returns the last modification time as a unix timestamp. More...
 
 delete ()
 Deletes the current node. More...
 
 setName ($a_name)
 Renames the node. More...
 
 getName ()
 SabreDAV interface function Returns the name of the node.This is used to generate the url.
Returns
string
. More...
 
 getObject ()
 Returns ILIAS Object. More...
 
- Public Member Functions inherited from Sabre\DAV\Node
 getLastModified ()
 Returns the last modification time as a unix timestamp. More...
 
 delete ()
 Deletes the current node. More...
 
 setName ($name)
 Renames the node. More...
 

Additional Inherited Members

- Protected Attributes inherited from ilObjectDAV
 $ref_id
 
 $obj
 
 $repo_helper
 
 $dav_helper
 

Detailed Description

Class ilObjContainerDAV.

Base implementation for container objects to be represented as WebDAV collection.

Author
Raphael Heer rapha.nosp@m.el.h.nosp@m.eer@h.nosp@m.slu..nosp@m.ch $Id$

Definition at line 21 of file class.ilObjContainerDAV.php.

Constructor & Destructor Documentation

◆ __construct()

ilObjContainerDAV::__construct ( ilContainer  $a_obj,
ilWebDAVRepositoryHelper  $repo_helper,
ilWebDAVObjDAVHelper  $dav_helper 
)

Check if given object has valid type and calls parent constructor.

Parameters
ilContainer$a_obj

Definition at line 28 of file class.ilObjContainerDAV.php.

29  {
30  parent::__construct($a_obj, $repo_helper, $dav_helper);
31  }

Member Function Documentation

◆ childExists()

ilObjContainerDAV::childExists (   $name)

Checks if a child-node with the specified name exists.

Parameters
string$name
Returns
bool

Implements Sabre\DAV\ICollection.

Definition at line 204 of file class.ilObjContainerDAV.php.

References $name, and getChildCollectionType().

Referenced by createFile().

205  {
206  foreach ($this->repo_helper->getChildrenOfRefId($this->obj->getRefId()) as $child_ref) {
207  // Only davable object types
208  if ($this->dav_helper->isDAVableObject($child_ref, true)) {
209  // Check if names are the same
210  if ($this->repo_helper->getObjectTitleFromRefId($child_ref, true) == $name) {
211  // Check if read permission is given
212  if ($this->repo_helper->checkAccess("read", $child_ref)) {
213  return true;
214  } else {
215  /*
216  * This is an interesting edge case. What happens if there are 2 objects with the same name
217  * but User1 only has access to the first and user2 has only access to the second?
218  */
219  return false;
220  }
221  }
222  }
223  }
224 
225  return false;
226  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createDirectory()

ilObjContainerDAV::createDirectory (   $name)

Creates a new subdirectory.

Parameters
string$name
Returns
void
Exceptions
NotImplemented

Implements Sabre\DAV\ICollection.

Definition at line 105 of file class.ilObjContainerDAV.php.

References $DIC, $name, $type, getChildCollectionType(), and ilLoggerFactory\getLogger().

106  {
107  global $DIC;
108 
109  $type = $this->getChildCollectionType();
110  if ($this->repo_helper->checkCreateAccessForType($this->getRefId(), $type) && $this->dav_helper->isDAVableObjTitle($name)) {
111  switch ($type) {
112  case 'cat':
113  $new_obj = new ilObjCategory();
114  break;
115 
116  case 'fold':
117  $new_obj = new ilObjFolder();
118  break;
119 
120  default:
121  ilLoggerFactory::getLogger('WebDAV')->info(get_class($this) . ' ' . $this->obj->getTitle() . " -> $type is not supported as webdav directory");
122  throw new NotImplemented("Create type '$type' as collection is not implemented yet");
123  }
124 
125  $new_obj->setType($type);
126  $new_obj->setOwner($DIC->user()->getId());
127  $new_obj->setTitle($name);
128  $new_obj->create();
129 
130  $new_obj->createReference();
131  $new_obj->putInTree($this->obj->getRefId());
132  $new_obj->setPermissions($this->obj->getRefId());
133  $new_obj->update();
134  } else {
135  throw new Forbidden();
136  }
137  }
Class ilObjFolder.
getChildCollectionType()
Return the type for child collections of this collection For courses, groups and folders the type is ...
$type
global $DIC
Definition: saml.php:7
Class ilObjCategory.
static getLogger($a_component_id)
Get component logger.
+ Here is the call graph for this function:

◆ createFile()

ilObjContainerDAV::createFile (   $name,
  $data = null 
)

Creates a new file in the directory.

Data will either be supplied as a stream resource, or in certain cases as a string. Keep in mind that you may have to support either.

After successful creation of the file, you may choose to return the ETag of the new file here.

The returned ETag must be surrounded by double-quotes (The quotes should be part of the actual string).

If you cannot accurately determine the ETag, you should not return it. If you don't store the file exactly as-is (you're transforming it somehow) you should also not return an ETag.

This means that if a subsequent GET to this new file does not exactly return the same contents of what was submitted here, you are strongly recommended to omit the ETag.

Parameters
string$nameName of the file
resource | string$dataInitial payload
Returns
null|string
Exceptions
Exception

Implements Sabre\DAV\ICollection.

Definition at line 61 of file class.ilObjContainerDAV.php.

References $data, $name, childExists(), and getChild().

62  {
63  if ($this->repo_helper->checkCreateAccessForType($this->obj->getRefId(), 'file')) {
64  // Check if file has valid extension
65  if ($this->dav_helper->isValidFileNameWithValidFileExtension($name)) {
66  if ($this->childExists($name)) {
67  $file_dav = $this->getChild($name);
68  $file_dav->handleFileUpload($data);
69  } else {
70  $file_obj = new ilObjFile();
71  $file_obj->setTitle($name);
72  $file_obj->setFileName($name);
73  $file_obj->setVersion(1);
74  $file_obj->setMaxVersion(1);
75  $file_obj->createDirectory();
76  $file_obj->create();
77 
78  $file_obj->createReference();
79  $file_obj->putInTree($this->obj->getRefId());
80  $file_obj->setPermissions($this->ref_id);
81  $file_obj->update();
82 
83  $file_dav = new ilObjFileDAV($file_obj, $this->repo_helper, $this->dav_helper);
84  $file_dav->handleFileUpload($data);
85  }
86  } else {
87  // Throw forbidden if invalid extension or filename. As far as we know, it is sadly not
88  // possible to inform the user why his upload was "forbidden".
89  throw new Forbidden('Invalid file name or file extension');
90  }
91  } else {
92  throw new Forbidden('No write access');
93  }
94 
95  return $file_dav->getETag();
96  }
Class ilObjFileDAV.
childExists($name)
Checks if a child-node with the specified name exists.
getChild($name)
Returns a specific child node, referenced by its name.
$data
Definition: bench.php:6
+ Here is the call graph for this function:

◆ getChild()

ilObjContainerDAV::getChild (   $name)

Returns a specific child node, referenced by its name.

This method must throw Sabre if the node does not exist.

Exceptions
Exception

Implements Sabre\DAV\ICollection.

Definition at line 149 of file class.ilObjContainerDAV.php.

References $name.

Referenced by createFile().

150  {
151  $child_node = null;
152  $child_exists = false;
153  foreach ($this->repo_helper->getChildrenOfRefId($this->obj->getRefId()) as $child_ref) {
154  // Check if a DAV Object exists for this type
155  if ($this->dav_helper->isDAVableObject($child_ref, true)) {
156  // Check if names matches
157  if ($this->repo_helper->getObjectTitleFromRefId($child_ref, true) == $name) {
158  $child_exists = true;
159 
160  // Check if user has permission to read this object
161  if ($this->repo_helper->checkAccess("read", $child_ref)) {
162  $child_node = $this->dav_helper->createDAVObjectForRefId($child_ref);
163  }
164  }
165  }
166  }
167 
168  // There exists 1 or more nodes with this name. Return last found node.
169  if (!is_null($child_node)) {
170  return $child_node;
171  }
172 
173  // There is no davable object with the same name. Sorry for you...
174  throw new Sabre\DAV\Exception\NotFound("$name not found");
175  }
+ Here is the caller graph for this function:

◆ getChildCollectionType()

ilObjContainerDAV::getChildCollectionType ( )
abstract

Return the type for child collections of this collection For courses, groups and folders the type is 'fold' For categories the type is 'cat'.

Returns
string $type

Referenced by childExists(), and createDirectory().

+ Here is the caller graph for this function:

◆ getChildren()

ilObjContainerDAV::getChildren ( )

Returns an array with all the child nodes.

Returns
ilObject[]

Implements Sabre\DAV\ICollection.

Definition at line 182 of file class.ilObjContainerDAV.php.

183  {
184  $child_nodes = array();
185  foreach ($this->repo_helper->getChildrenOfRefId($this->obj->getRefId()) as $child_ref) {
186  // Check if is davable object types
187  if ($this->dav_helper->isDAVableObject($child_ref, true)) {
188  // Check if read permission is given
189  if ($this->repo_helper->checkAccess("read", $child_ref)) {
190  // Create DAV-object out of ILIAS-object
191  $child_nodes[$child_ref] = $this->dav_helper->createDAVObjectForRefId($child_ref);
192  }
193  }
194  }
195  return $child_nodes;
196  }

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