ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilWebDAVObjFactory.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use Sabre\DAV\Exception\NotFound;
23use Sabre\DAV\INode;
24use Sabre\DAV\Exception\Forbidden;
25use Psr\Http\Message\RequestInterface;
26
31{
32 use ilWebDAVCheckValidTitleTrait;
33
37 private array $davable_object_types = [
38 'cat',
39 'crs',
40 'fold',
41 'file',
42 'grp'
43 ];
44
45 protected array $_cache = [];
46
47 public function __construct(
48 protected ilWebDAVRepositoryHelper $repository_helper,
49 protected ilObjUser $current_user,
50 protected Services $resource_storage,
51 protected RequestInterface $request,
52 protected ilLanguage $language,
53 protected string $client_id,
54 protected bool $versioning_enabled
55 ) {
56 }
57
59 {
60 if (!$this->checkReadAndVisibleAccessForObj($ref_id)) {
61 throw new Forbidden("No read permission for object with reference ID $ref_id");
62 }
63
64 if (isset($this->_cache[$ref_id])) {
65 return $this->_cache[$ref_id];
66 }
67
69
70 if ($ilias_object === null) {
71 throw new NotFound();
72 }
73
74 $ilias_object_type = $ilias_object->getType();
75
76 if (!in_array($ilias_object_type, $this->davable_object_types)) {
78 }
79
80 if ($this->isHiddenFile($ilias_object->getTitle())) {
82 }
83
84 if ($this->hasTitleForbiddenChars($ilias_object->getTitle())) {
86 }
87
88 if ($ilias_object_type === 'file') {
89 return $this->_cache[$ref_id] = new ilDAVFile(
90 $ilias_object,
91 $this->repository_helper,
92 $this->resource_storage,
93 $this->request,
94 $this,
95 $this->versioning_enabled
96 );
97 }
98
99 return $this->_cache[$ref_id] = new ilDAVContainer(
100 $ilias_object,
101 $this->current_user,
102 $this->request,
103 $this,
104 $this->repository_helper
105 );
106 }
107
108 public function createDAVObject(ilObject $ilias_object, int $parent_ref_id): INode
109 {
110 if (!$this->isDAVableObjTitle($ilias_object->getTitle())) {
112 }
113
114 if ($ilias_object->getType() === 'file' &&
115 !$this->hasValidFileExtension($ilias_object->getTitle())) {
117 }
118
119 if ($ilias_object->getRefId() === 0) {
120 $ilias_object->create();
121 $ilias_object->createReference();
122 $ilias_object->putInTree($parent_ref_id);
123 $ilias_object->setPermissions($parent_ref_id);
124 }
125
126 $ref_id = $ilias_object->getRefId();
127
128 if ($ilias_object->getType() === 'file') {
129 return $this->_cache[$ref_id] = new ilDAVFile(
130 $ilias_object,
131 $this->repository_helper,
132 $this->resource_storage,
133 $this->request,
134 $this,
135 $this->versioning_enabled
136 );
137 }
138
139 return $this->_cache[$ref_id] = new ilDAVContainer(
140 $ilias_object,
141 $this->current_user,
142 $this->request,
143 $this,
144 $this->repository_helper
145 );
146 }
147
148 public function getProblemInfoFile(int $container_ref_id): ilDAVProblemInfoFile
149 {
150 return new ilDAVProblemInfoFile($container_ref_id, $this->repository_helper, $this, $this->language);
151 }
152
154 {
155 return new ilDAVMountPoint($this->client_id, $this, $this->repository_helper, $this->current_user);
156 }
157
158 public function getClientNode(string $name): ilDAVClientNode
159 {
160 if ($name !== $this->client_id) {
161 throw new NotFound();
162 }
163
164 return new ilDAVClientNode($this->client_id, $this, $this->repository_helper);
165 }
166
167 protected function checkReadAndVisibleAccessForObj(int $child_ref): bool
168 {
169 return $this->repository_helper->checkAccess("visible", $child_ref) && $this->repository_helper->checkAccess(
170 "read",
171 $child_ref
172 );
173 }
174}
This class represents the absolut Root-Node on a WebDAV request.
language handling
User class.
static getInstanceByRefId(int $ref_id, bool $stop_on_error=true)
get an instance of an Ilias object by reference id
Class ilObject Basic functions for all objects.
setPermissions(int $parent_ref_id)
createReference()
creates reference for object
putInTree(int $parent_ref_id)
maybe this method should be in tree object!?
create()
note: title, description and type should be set when this function is called
getProblemInfoFile(int $container_ref_id)
__construct(protected ilWebDAVRepositoryHelper $repository_helper, protected ilObjUser $current_user, protected Services $resource_storage, protected RequestInterface $request, protected ilLanguage $language, protected string $client_id, protected bool $versioning_enabled)
createDAVObject(ilObject $ilias_object, int $parent_ref_id)
checkReadAndVisibleAccessForObj(int $child_ref)
$client_id
Definition: ltiauth.php:67
$ref_id
Definition: ltiauth.php:66