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