ILIAS  release_7 Revision v7.30-3-g800a261c036
All Data Structures Namespaces Files Functions Variables Modules Pages
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 . More...
 
 getObject ()
 Returns ILIAS Object. More...
 

Protected Member Functions

 checkReadAndVisibleAccessForObj ($child_ref)
 

Additional Inherited Members

- Protected Attributes inherited from ilObjectDAV
 $ref_id
 
 $obj
 
 $request
 
 $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.

References ILIAS\GlobalScreen\Provider\__construct().

29  {
30  parent::__construct($a_obj, $repo_helper, $dav_helper);
31  }
__construct(Container $dic, ilPlugin $plugin)
+ Here is the call graph for this function:

Member Function Documentation

◆ checkReadAndVisibleAccessForObj()

ilObjContainerDAV::checkReadAndVisibleAccessForObj (   $child_ref)
protected

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

References getChildCollectionType().

Referenced by childExists(), getChild(), and getChildren().

260  {
261  return $this->repo_helper->checkAccess("visible", $child_ref) && $this->repo_helper->checkAccess("read", $child_ref);
262  }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ childExists()

ilObjContainerDAV::childExists (   $name)

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

Parameters
string$name
Returns
bool

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

References $name, and checkReadAndVisibleAccessForObj().

Referenced by createFile().

236  {
237  foreach ($this->repo_helper->getChildrenOfRefId($this->obj->getRefId()) as $child_ref) {
238  // Only davable object types
239  if ($this->dav_helper->isDAVableObject($child_ref, true)) {
240  // Check if names are the same
241  if ($this->repo_helper->getObjectTitleFromRefId($child_ref, true) == $name) {
242  // Check if read permission is given
243  if ($this->checkReadAndVisibleAccessForObj($child_ref)) {
244  return true;
245  } else {
246  /*
247  * This is an interesting edge case. What happens if there are 2 objects with the same name
248  * but User1 only has access to the first and user2 has only access to the second?
249  */
250  return false;
251  }
252  }
253  }
254  }
255 
256  return false;
257  }
if($format !==null) $name
Definition: metadata.php:230
checkReadAndVisibleAccessForObj($child_ref)
+ 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

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

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

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

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

References $data, $name, $size, childExists(), getChild(), and ilUtil\getUploadSizeLimitBytes().

61  {
62  if ($this->repo_helper->checkCreateAccessForType($this->obj->getRefId(), 'file')) {
63  $size = $this->request->getHeader("Content-Length")[0] ?? 0;
65  throw new Exception\Forbidden('File is too big');
66  }
67 
68  // Check if file has valid extension
69  if ($this->dav_helper->isValidFileNameWithValidFileExtension($name)) {
70  if ($this->childExists($name)) {
71  $file_dav = $this->getChild($name);
72  return $file_dav->put($data);
73  } else {
74  $file_obj = new ilObjFile();
75  $file_obj->setTitle($name);
76  $file_obj->setFileName($name);
77  $file_obj->setVersion(1);
78  $file_obj->setMaxVersion(1);
79  $file_obj->createDirectory();
80  $file_obj->create();
81 
82  $file_obj->createReference();
83  $file_obj->putInTree($this->obj->getRefId());
84  $file_obj->setPermissions($this->ref_id);
85 
86  $file_dav = new ilObjFileDAV($file_obj, $this->repo_helper, $this->dav_helper);
87  return $file_dav->handleFileUpload($data, "create");
88  }
89  } else {
90  // Throw forbidden if invalid extension or filename. As far as we know, it is sadly not
91  // possible to inform the user why his upload was "forbidden".
92  throw new Forbidden('Invalid file name or file extension');
93  }
94  } else {
95  throw new Forbidden('No write access');
96  }
97  }
$size
Definition: RandomTest.php:84
$data
Definition: storeScorm.php:23
Class ilObjFileDAV.
childExists($name)
Checks if a child-node with the specified name exists.
if($format !==null) $name
Definition: metadata.php:230
static getUploadSizeLimitBytes()
getChild($name)
Returns a specific child node, referenced by its name.
+ 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

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

References $name, checkReadAndVisibleAccessForObj(), and ilProblemInfoFileDAV\PROBLEM_INFO_FILE_NAME.

Referenced by createFile().

151  {
152  $child_node = null;
153  $child_exists = false;
154 
155  // Early exit if the problem info file is opened
157  return new ilProblemInfoFileDAV($this, $this->repo_helper, $this->dav_helper);
158  }
159 
160  // Search for the desired file
161  foreach ($this->repo_helper->getChildrenOfRefId($this->obj->getRefId()) as $child_ref) {
162  // Check if a DAV Object exists for this type
163  if ($this->dav_helper->isDAVableObject($child_ref, true)) {
164  // Check if names matches
165  if ($this->repo_helper->getObjectTitleFromRefId($child_ref, true) == $name) {
166  $child_exists = true;
167 
168  // Check if user has permission to read this object
169  if ($this->checkReadAndVisibleAccessForObj($child_ref)) {
170  $child_node = $this->dav_helper->createDAVObjectForRefId($child_ref);
171  }
172  }
173  }
174  }
175 
176  // There exists 1 or more nodes with this name. Return last found node.
177  if (!is_null($child_node)) {
178  return $child_node;
179  }
180 
181  // There is no davable object with the same name. Sorry for you...
182  throw new Sabre\DAV\Exception\NotFound("$name not found");
183  }
if($format !==null) $name
Definition: metadata.php:230
checkReadAndVisibleAccessForObj($child_ref)
+ Here is the call graph for this function:
+ 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 checkReadAndVisibleAccessForObj(), and createDirectory().

+ Here is the caller graph for this function:

◆ getChildren()

ilObjContainerDAV::getChildren ( )

Returns an array with all the child nodes.

Returns
ilObject[]

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

References checkReadAndVisibleAccessForObj().

191  {
192  $child_nodes = array();
193  $already_seen_titles = array();
194  $problem_info_file_needed = false;
195 
196  foreach ($this->repo_helper->getChildrenOfRefId($this->obj->getRefId()) as $child_ref) {
197  // Check if is davable object types
198  if ($this->dav_helper->isDAVableObject($child_ref, true)) {
199  // Check for duplicates
200  $title = $this->repo_helper->getObjectTitleFromRefId($child_ref);
201  if (in_array($title, $already_seen_titles)) {
202  $problem_info_file_needed = true;
203  continue;
204  }
205 
206  $already_seen_titles[] = $title;
207 
208  // Check if read permission is given
209  if ($this->checkReadAndVisibleAccessForObj($child_ref)) {
210  // Create DAV-object out of ILIAS-object
211  $child_nodes[$child_ref] = $this->dav_helper->createDAVObjectForRefId($child_ref);
212  }
213  }
214  // if title is not davable because of forbidden characters in title -> problem info file will be created
215  elseif (!$problem_info_file_needed
216  && $this->dav_helper->isDAVableObjType($this->repo_helper->getObjectTypeFromRefId($child_ref))
217  && $this->dav_helper->hasTitleForbiddenChars($this->repo_helper->getObjectTitleFromRefId($child_ref))) {
218  $problem_info_file_needed = true;
219  }
220  }
221 
222  if ($problem_info_file_needed) {
223  $child_nodes[] = new ilProblemInfoFileDAV($this, $this->repo_helper, $this->dav_helper);
224  }
225 
226  return $child_nodes;
227  }
checkReadAndVisibleAccessForObj($child_ref)
+ Here is the call graph for this function:

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