ILIAS  release_8 Revision v8.24
class.ilWebDAVRepositoryHelper.php
Go to the documentation of this file.
1<?php
2
3declare(strict_types=1);
4
21use Sabre\DAV\Exception\Forbidden;
22
24{
26 protected ilTree $tree;
29
31 {
32 $this->access = $access;
33 $this->tree = $tree;
34 $this->repository_util = $repository_util;
35 $this->locks_repository = $locks_repository;
36 }
37
38 public function deleteObject(int $ref_id): void
39 {
40 if (!$this->checkAccess('delete', $ref_id)) {
41 throw new Forbidden("Permission denied");
42 }
43
44 $parent = $this->tree->getParentId($ref_id);
45 $this->repository_util->deleteObjects($parent, [$ref_id]);
46 }
47
48 public function checkAccess(string $permission, int $ref_id): bool
49 {
50 return $this->access->checkAccess($permission, '', $ref_id);
51 }
52
53 public function checkCreateAccessForType(int $ref_id, string $type): bool
54 {
55 return $this->access->checkAccess('create', '', $ref_id, $type);
56 }
57
58 public function objectWithRefIdExists(int $ref_id): bool
59 {
60 return ilObject::_exists($ref_id, true);
61 }
62
63 public function getObjectIdFromRefId(int $ref_id): int
64 {
66 }
67
68 public function getObjectTitleFromObjId(int $obj_id, bool $escape_forbidden_fileextension = false): string
69 {
70 if ($escape_forbidden_fileextension && ilObject::_lookupType($obj_id) === 'file') {
71 $title = $this->getFilenameWithSanitizedFileExtension($obj_id);
72 } else {
73 $title = $this->getRawObjectTitleFromObjId($obj_id);
74 }
75
76 return $title;
77 }
78
79 public function getFilenameWithSanitizedFileExtension(int $obj_id): string
80 {
81 $unescaped_title = $this->getRawObjectTitleFromObjId($obj_id);
82
83 try {
84 $escaped_title = ilFileUtils::getValidFilename($unescaped_title);
85 } catch (ilFileUtilsException $e) {
86 $escaped_title = '';
87 }
88
89 return $escaped_title;
90 }
91
92 protected function getRawObjectTitleFromObjId(int $obj_id): string
93 {
94 return ilObject::_lookupTitle($obj_id);
95 }
96
97 public function getParentOfRefId(int $ref_id): int
98 {
99 return $this->tree->getParentId($ref_id);
100 }
101
102 public function getObjectTypeFromObjId(int $obj_id): string
103 {
104 return ilObject::_lookupType($obj_id);
105 }
106
107 public function getObjectTitleFromRefId(int $ref_id, bool $escape_forbidden_fileextension = false): string
108 {
109 $obj_id = $this->getObjectIdFromRefId($ref_id);
110
111 return $this->getObjectTitleFromObjId($obj_id, $escape_forbidden_fileextension);
112 }
113
114 public function getObjectTypeFromRefId(int $ref_id): string
115 {
116 return ilObject::_lookupType($ref_id, true);
117 }
118
123 public function getChildrenOfRefId(int $ref_id): array
124 {
125 return array_map(
126 'intval',
127 $this->tree->getChildIds($ref_id)
128 );
129 }
130
131 public function updateLocksAfterResettingObject(int $old_obj_id, int $new_obj_id): void
132 {
133 $this->locks_repository->updateLocks($old_obj_id, $new_obj_id);
134 }
135}
static getValidFilename(string $a_filename)
static _lookupObjectId(int $ref_id)
static _lookupType(int $id, bool $reference=false)
static _exists(int $id, bool $reference=false, ?string $type=null)
checks if an object exists in object_data
static _lookupTitle(int $obj_id)
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...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
updateLocksAfterResettingObject(int $old_obj_id, int $new_obj_id)
getObjectTitleFromObjId(int $obj_id, bool $escape_forbidden_fileextension=false)
getObjectTitleFromRefId(int $ref_id, bool $escape_forbidden_fileextension=false)
checkAccess(string $permission, int $ref_id)
checkCreateAccessForType(int $ref_id, string $type)
ilWebDAVLocksRepository $locks_repository
__construct(ilAccessHandler $access, ilTree $tree, ilRepUtil $repository_util, ilWebDAVLocksRepository $locks_repository)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$ref_id
Definition: ltiauth.php:67
$type