ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
ilWebDAVAccessChildrenFunctionsTrait.php
Go to the documentation of this file.
1<?php
2
19declare(strict_types=1);
20
21use Sabre\DAV\Exception\NotFound;
22use Sabre\DAV\Exception\Forbidden;
23use Sabre\DAV\INode;
24
25trait ilWebDAVAccessChildrenFunctionsTrait
26{
27 protected function getChildByParentRefId(
28 ilWebDAVRepositoryHelper $repository_helper,
29 ilWebDAVObjFactory $dav_object_factory,
30 int $parent_ref_id,
31 string $name
32 ): INode {
33 $child_node = null;
34 $has_only_files_with_missing_storage = false;
35
37 return $dav_object_factory->getProblemInfoFile($parent_ref_id);
38 }
39
40 foreach ($repository_helper->getChildrenOfRefId($parent_ref_id) as $child_ref) {
41 try {
42 $child = $dav_object_factory->retrieveDAVObjectByRefID($child_ref);
43
44 if ($child->getName() === $name) {
45 $child_node = $child;
46 }
47 } catch (RuntimeException $e) {
48 if ($e->getMessage() === 'cannot read rource from resource storage server') {
49 $has_only_files_with_missing_storage = true;
50 }
51 } catch (ilWebDAVNotDavableException|Forbidden|NotFound) {
52 }
53 }
54
55 if (!is_null($child_node)) {
56 return $child_node;
57 }
58
59 if ($has_only_files_with_missing_storage) {
61 }
62
63 throw new NotFound("$name not found");
64 }
65
69 protected function getChildrenByParentRefId(
70 ilWebDAVRepositoryHelper $repository_helper,
71 ilWebDAVObjFactory $dav_object_factory,
72 int $parent_ref_id
73 ): array {
74 $child_nodes = [];
75 $already_seen_titles = [];
76 $problem_info_file_needed = false;
77
78 foreach ($repository_helper->getChildrenOfRefId($parent_ref_id) as $child_ref) {
79 try {
80 $child = $dav_object_factory->retrieveDAVObjectByRefID($child_ref);
81 if (($key = array_search($child->getName(), $already_seen_titles)) !== false) {
82 unset($child_nodes[$key]);
83 $problem_info_file_needed = true;
84 }
85
86 $already_seen_titles[$child_ref] = $child->getName();
87
88 $child_nodes[$child_ref] = $child;
90 if (!$problem_info_file_needed &&
92 $problem_info_file_needed = true;
93 }
94 } catch (NotFound|RuntimeException|Forbidden) {
95 }
96 }
97
98 if ($problem_info_file_needed) {
99 $child_nodes[] = $dav_object_factory->getProblemInfoFile($parent_ref_id);
100 }
101
102 return $child_nodes;
103 }
104
105 protected function checkIfChildExistsByParentRefId(
106 ilWebDAVRepositoryHelper $repository_helper,
107 ilWebDAVObjFactory $dav_object_factory,
108 int $parent_ref_id,
109 string $name
110 ): bool {
111 if ($name === ilDAVProblemInfoFile::PROBLEM_INFO_FILE_NAME) {
112 return true;
113 }
114
115 foreach ($repository_helper->getChildrenOfRefId($parent_ref_id) as $child_ref) {
116 try {
117 $child = $dav_object_factory->retrieveDAVObjectByRefID($child_ref);
118
119 if ($child->getName() === $name) {
120 return true;
121 }
122 } catch (ilWebDAVNotDavableException|Forbidden|NotFound|RuntimeException) {
123 }
124 }
125
126 return false;
127 }
128}
getProblemInfoFile(int $container_ref_id)
if(!file_exists('../ilias.ini.php'))