ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilObjFileStakeholder.php
Go to the documentation of this file.
1<?php
2
21
27{
28 protected ?ilDBInterface $database = null;
29
30
31 public function getId(): string
32 {
33 return 'file_obj';
34 }
35
36 public function getOwnerOfNewResources(): int
37 {
39 }
40
41 #[\Override]
42 public function canBeAccessedByCurrentUser(ResourceIdentification $identification): bool
43 {
44 global $DIC;
45
46 $object_id = $this->resolveObjectId($identification);
47 if ($object_id === null) {
48 return true;
49 }
50
51 $ref_ids = ilObject2::_getAllReferences($object_id);
52 foreach ($ref_ids as $ref_id) {
53 if ($DIC->access()->checkAccessOfUser($this->current_user, 'read', '', $ref_id)) {
54 return true;
55 }
56 }
57
58 return false;
59 }
60
61 private function resolveObjectId(ResourceIdentification $identification): ?int
62 {
63 $this->initDB();
64 $r = $this->database->queryF(
65 "SELECT file_id FROM file_data WHERE rid = %s",
66 ['text'],
67 [$identification->serialize()]
68 );
69 $d = $this->database->fetchObject($r);
70
71 return (isset($d->file_id) ? (int) $d->file_id : null);
72 }
73
74 #[\Override]
75 public function resourceHasBeenDeleted(ResourceIdentification $identification): bool
76 {
77 $object_id = $this->resolveObjectId($identification);
78 try {
79 $this->database->manipulateF(
80 "UPDATE object_data SET offline = 1 WHERE obj_id = %s",
81 ['text'],
82 [$object_id]
83 );
84 } catch (Throwable) {
85 return false;
86 }
87 return true;
88 }
89
90 public function getLocationURIForResourceUsage(ResourceIdentification $identification): ?string
91 {
92 $this->initDB();
93 $r = $this->database->queryF(
94 "SELECT file_id FROM file_data WHERE rid = %s",
95 ['text'],
96 [$identification->serialize()]
97 );
98 $d = $this->database->fetchObject($r);
99 if ($d !== null && property_exists($d, 'file_id') && $d->file_id !== null) {
100 $references = ilObject::_getAllReferences($d->file_id);
101 $ref_id = array_shift($references);
102
103 return ilLink::_getLink($ref_id, 'file');
104 }
105 return null;
106 }
107
108 private function initDB(): void
109 {
110 global $DIC;
111 $this->database = $DIC->database();
112 }
113}
Class ilObjFileStakeholder.
resolveObjectId(ResourceIdentification $identification)
canBeAccessedByCurrentUser(ResourceIdentification $identification)
resourceHasBeenDeleted(ResourceIdentification $identification)
getLocationURIForResourceUsage(ResourceIdentification $identification)
static _getAllReferences(int $id)
get all reference ids for object ID
Interface ilDBInterface.
$ref_id
Definition: ltiauth.php:66
global $DIC
Definition: shib_login.php:26