ILIAS  release_8 Revision v8.24
class.ilDAVContainer.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
21use Sabre\DAV\Exception\Forbidden;
22use Sabre\DAV\INode;
23use Sabre\DAV\ICollection;
24use Psr\Http\Message\RequestInterface;
25
29class ilDAVContainer implements ICollection
30{
31 use ilWebDAVCheckValidTitleTrait;
32 use ilWebDAVAccessChildrenFunctionsTrait;
33 use ilWebDAVCommonINodeFunctionsTrait;
34
36 protected ilObject $obj;
37 protected RequestInterface $request;
40
41 public function __construct(
44 RequestInterface $request,
47 ) {
48 $this->obj = $obj;
49 $this->current_user = $current_user;
50 $this->request = $request;
51 $this->dav_factory = $dav_factory;
52 $this->repository_helper = $repository_helper;
53 }
54
55 public function getName(): string
56 {
57 return $this->obj->getTitle();
58 }
59
64 public function getChild($name): INode
65 {
66 return $this->getChildByParentRefId(
67 $this->repository_helper,
68 $this->dav_factory,
69 $this->obj->getRefId(),
70 $name
71 );
72 }
73
77 public function getChildren(): array
78 {
79 return $this->getChildrenByParentRefId(
80 $this->repository_helper,
81 $this->dav_factory,
82 $this->obj->getRefId()
83 );
84 }
85
90 public function childExists($name): bool
91 {
92 return $this->checkIfChildExistsByParentRefId(
93 $this->repository_helper,
94 $this->dav_factory,
95 $this->obj->getRefId(),
96 $name
97 );
98 }
99
104 public function setName($name): void
105 {
106 if (!$this->repository_helper->checkAccess("write", $this->obj->getRefId())) {
107 throw new Forbidden('Permission denied');
108 }
109
110 if ($this->isDAVableObjTitle($name)) {
111 $this->obj->setTitle($name);
112 $this->obj->update();
113 } else {
114 throw new Forbidden('Forbidden characters in title');
115 }
116 }
117
122 public function createFile($name, $data = null): ?string
123 {
124 if (!$this->repository_helper->checkCreateAccessForType($this->obj->getRefId(), 'file')) {
125 throw new Forbidden('Permission denied');
126 }
127
128 $size = $this->request->getHeader("Content-Length")[0] ?? 0;
129 if ($size === 0 && $this->request->hasHeader('X-Expected-Entity-Length')) {
130 $size = $this->request->getHeader('X-Expected-Entity-Length')[0];
131 }
132
134 throw new Forbidden('File is too big');
135 }
136
137 if ($this->childExists($name)) {
138 $file_dav = $this->getChild($name);
139 } else {
140 try {
141 $file_obj = new ilObjFile();
142 $file_obj->setTitle($name);
143 $file_obj->setFileName($name);
144
145 $file_dav = $this->dav_factory->createDAVObject($file_obj, $this->obj->getRefId());
147 throw new Forbidden('Forbidden characters in title');
148 }
149 }
150
151 return $file_dav->put($data);
152 }
153
158 public function createDirectory($name): void
159 {
160 $new_obj = $this->getChildCollection();
161
162 if (!$this->repository_helper->checkCreateAccessForType($this->obj->getRefId(), $new_obj->getType())) {
163 throw new Forbidden('Permission denied');
164 }
165
166 try {
167 $new_obj->setOwner($this->current_user->getId());
168 $new_obj->setTitle($name);
169 $this->dav_factory->createDAVObject($new_obj, $this->obj->getRefId());
171 throw new Forbidden('Forbidden characters in title');
172 }
173 }
174
175 public function delete(): void
176 {
177 $this->repository_helper->deleteObject($this->obj->getRefId());
178 }
179
180 public function getLastModified(): ?int
181 {
182 return $this->retrieveLastModifiedAsIntFromObjectLastUpdateString($this->obj->getLastUpdateDate());
183 }
184
185 protected function getChildCollection(): ilContainer
186 {
187 if (get_class($this->obj) === 'ilObjCategory') {
188 return new ilObjCategory();
189 }
190
191 return new ilObjFolder();
192 }
193}
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
ilWebDAVObjFactory $dav_factory
createFile($name, $data=null)
__construct(ilContainer $obj, ilObjUser $current_user, RequestInterface $request, ilWebDAVObjFactory $dav_factory, ilWebDAVRepositoryHelper $repository_helper)
RequestInterface $request
ilWebDAVRepositoryHelper $repository_helper
static getUploadSizeLimitBytes()
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Class ilObjFile.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
User class.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
if($format !==null) $name
Definition: metadata.php:247
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
Definition: AsyncNode.php:21