ILIAS  release_6 Revision v6.24-5-g0c8bfefb3b8
class.ilObjContainerDAV.php
Go to the documentation of this file.
1<?php
2
3use Sabre\DAV;
5use Sabre\DAV\Exception;
6use Sabre\DAV\Exception\NotFound;
7use Sabre\DAV\Exception\NotImplemented;
8use Sabre\DAV\Exception\Forbidden;
9
21abstract class ilObjContainerDAV extends ilObjectDAV implements Sabre\DAV\ICollection
22{
29 {
31 }
32
33
61 public function createFile($name, $data = null)
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->put($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, "create");
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 }
97
105 public function createDirectory($name)
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 }
138
149 public function getChild($name)
150 {
151 $child_node = null;
152 $child_exists = false;
153
154 // Early exit if the problem info file is opened
156 return new ilProblemInfoFileDAV($this, $this->repo_helper, $this->dav_helper);
157 }
158
159 // Search for the desired file
160 foreach ($this->repo_helper->getChildrenOfRefId($this->obj->getRefId()) as $child_ref) {
161 // Check if a DAV Object exists for this type
162 if ($this->dav_helper->isDAVableObject($child_ref, true)) {
163 // Check if names matches
164 if ($this->repo_helper->getObjectTitleFromRefId($child_ref, true) == $name) {
165 $child_exists = true;
166
167 // Check if user has permission to read this object
168 if ($this->repo_helper->checkAccess("read", $child_ref)
169 && $this->repo_helper->checkAccess("visible", $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 }
184
190 public function getChildren()
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->repo_helper->checkAccess("read", $child_ref)
210 && $this->repo_helper->checkAccess("visible", $child_ref)) {
211 // Create DAV-object out of ILIAS-object
212 $child_nodes[$child_ref] = $this->dav_helper->createDAVObjectForRefId($child_ref);
213 }
214 }
215 // if title is not davable because of forbidden characters in title -> problem info file will be created
216 elseif (!$problem_info_file_needed
217 && $this->dav_helper->isDAVableObjType($this->repo_helper->getObjectTypeFromRefId($child_ref))
218 && $this->dav_helper->hasTitleForbiddenChars($this->repo_helper->getObjectTitleFromRefId($child_ref))) {
219 $problem_info_file_needed = true;
220 }
221 }
222
223 if ($problem_info_file_needed) {
224 $child_nodes[] = new ilProblemInfoFileDAV($this, $this->repo_helper, $this->dav_helper);
225 }
226
227 return $child_nodes;
228 }
229
236 public function childExists($name)
237 {
238 foreach ($this->repo_helper->getChildrenOfRefId($this->obj->getRefId()) as $child_ref) {
239 // Only davable object types
240 if ($this->dav_helper->isDAVableObject($child_ref, true)) {
241 // Check if names are the same
242 if ($this->repo_helper->getObjectTitleFromRefId($child_ref, true) == $name) {
243 // Check if read permission is given
244 if ($this->repo_helper->checkAccess("read", $child_ref)) {
245 return true;
246 } else {
247 /*
248 * This is an interesting edge case. What happens if there are 2 objects with the same name
249 * but User1 only has access to the first and user2 has only access to the second?
250 */
251 return false;
252 }
253 }
254 }
255 }
256
257 return false;
258 }
259
267 abstract public function getChildCollectionType();
268}
An exception for terminatinating execution or to throw for unit testing.
This exception indicates that an UI component was accepted by the JF but is not backed by a real impl...
Class ilContainer.
static getLogger($a_component_id)
Get component logger.
Class ilObjCategory.
Class ilObjContainerDAV.
getChildCollectionType()
Return the type for child collections of this collection For courses, groups and folders the type is ...
__construct(ilContainer $a_obj, ilWebDAVRepositoryHelper $repo_helper, ilWebDAVObjDAVHelper $dav_helper)
Check if given object has valid type and calls parent constructor.
getChild($name)
Returns a specific child node, referenced by its name.
createDirectory($name)
Creates a new subdirectory.
childExists($name)
Checks if a child-node with the specified name exists.
createFile($name, $data=null)
Creates a new file in the directory.
getChildren()
Returns an array with all the child nodes.
Class ilObjFileDAV.
Class ilObjFile.
Class ilObjFolder.
Class ilObjectDAV.
Class ilWebDAVObjDAVHelper.
Class ilWebDAVRepositoryHelper.
if($format !==null) $name
Definition: metadata.php:230
__construct(Container $dic, ilPlugin $plugin)
@inheritDoc
$type
$data
Definition: storeScorm.php:23
$DIC
Definition: xapitoken.php:46