ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilDAVProblemInfoFile.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use Sabre\DAV\IFile;
22use Sabre\DAV\Exception\Forbidden;
23use Sabre\DAV\Exception\NotFound;
24
25class ilDAVProblemInfoFile implements IFile
26{
27 public const PROBLEM_INFO_FILE_NAME = '#!_WEBDAV_INFORMATION.txt';
28
29 public const PROBLEM_DUPLICATE_OBJECTNAME = 'duplicate';
30 public const PROBLEM_FORBIDDEN_CHARACTERS = 'forbidden_characters';
31 public const PROBLEM_INFO_NAME_DUPLICATE = 'info_name_duplicate';
32
33 public function __construct(
34 protected int $container_ref_id,
35 protected ilWebDAVRepositoryHelper $repo_helper,
36 protected ilWebDAVObjFactory $dav_object_factory,
37 protected ilLanguage $language
38 ) {
39 }
40
41 public function put($data)
42 {
43 throw new Forbidden("The error info file is virtual and can therefore not be overwritten");
44 }
45
46 public function get()
47 {
48 $problem_infos = $this->analyseObjectsOfDAVContainer();
49 return $this->createMessageStringFromProblemInfoArray($problem_infos);
50 }
51
52 public function getName()
53 {
55 }
56
57 public function getContentType()
58 {
59 return 'text/plain';
60 }
61
62 public function getETag()
63 {
64 return null;
65 }
66
67 public function getSize(): int
68 {
69 return 0;
70 }
71
72 public function setName($a_name): void
73 {
74 throw new Forbidden("The error info file cannot be renamed");
75 }
76
80 protected function analyseObjectsOfDAVContainer(): array
81 {
82 $already_seen_titles = [];
83
84 $problem_infos = [
85 self::PROBLEM_DUPLICATE_OBJECTNAME => [],
86 self::PROBLEM_FORBIDDEN_CHARACTERS => [],
87 self::PROBLEM_INFO_NAME_DUPLICATE => false
88 ];
89
90 foreach ($this->repo_helper->getChildrenOfRefId($this->container_ref_id) as $ref_id) {
91 try {
92 $dav_object = $this->dav_object_factory->retrieveDAVObjectByRefID($ref_id);
93
94 $title = $dav_object->getName();
95
96 if ($title === self::PROBLEM_INFO_FILE_NAME) {
97 $problem_infos[self::PROBLEM_INFO_NAME_DUPLICATE] = true;
98 } elseif (in_array($title, $already_seen_titles)) {
99 $problem_infos[self::PROBLEM_DUPLICATE_OBJECTNAME][] = $title;
100 } else {
101 $already_seen_titles[] = $title;
102 }
105 $title = $this->repo_helper->getObjectTitleFromRefId($ref_id);
106 $problem_infos[self::PROBLEM_FORBIDDEN_CHARACTERS][] = $title;
107 }
108 } catch (Forbidden|NotFound|RuntimeException) {
109 }
110 }
111
112 return $problem_infos;
113 }
114
118 protected function createMessageStringFromProblemInfoArray(array $problem_infos): string
119 {
120 $message_string = "";
121
122 if ($problem_infos[self::PROBLEM_INFO_NAME_DUPLICATE]) {
123 $message_string .= "# " . $this->language->txt('webdav_problem_info_duplicate') . "\n\n";
124 }
125
126 $duplicates_list = $problem_infos[self::PROBLEM_DUPLICATE_OBJECTNAME];
127 if (count($duplicates_list) > 0) {
128 $message_string .= "# " . $this->language->txt('webdav_duplicate_detected_title') . "\n";
129 foreach ($duplicates_list as $duplicate_title) {
130 $message_string .= $duplicate_title . "\n";
131 }
132 $message_string .= "\n";
133 }
134
135 $forbidden_character_titles_list = $problem_infos[self::PROBLEM_FORBIDDEN_CHARACTERS];
136 if (count($forbidden_character_titles_list) > 0) {
137 $message_string .= "# " . $this->language->txt('webdav_forbidden_chars_title') . "\n";
138 foreach ($forbidden_character_titles_list as $forbidden_character_title) {
139 $message_string .= $forbidden_character_title . "\n";
140 }
141 $message_string .= "\n";
142 }
143
144 if ($message_string === '') {
145 return $this->language->txt('webdav_problem_free_container');
146 }
147
148 return $message_string;
149 }
150
151 public function delete(): void
152 {
153 throw new Forbidden("It is not possible to delete this file since it is just virtual.");
154 }
155
156 public function getLastModified()
157 {
158 return time();
159 }
160}
createMessageStringFromProblemInfoArray(array $problem_infos)
__construct(protected int $container_ref_id, protected ilWebDAVRepositoryHelper $repo_helper, protected ilWebDAVObjFactory $dav_object_factory, protected ilLanguage $language)
language handling
$ref_id
Definition: ltiauth.php:66