ILIAS  release_10 Revision v10.1-43-ga1241a92c2f
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  {
38  return $this->default_owner;
39  }
40 
41  public function canBeAccessedByCurrentUser(ResourceIdentification $identification): bool
42  {
43  global $DIC;
44 
45  $object_id = $this->resolveObjectId($identification);
46  if ($object_id === null) {
47  return true;
48  }
49 
50  $ref_ids = ilObject2::_getAllReferences($object_id);
51  foreach ($ref_ids as $ref_id) {
52  if ($DIC->access()->checkAccessOfUser($this->current_user, 'read', '', $ref_id)) {
53  return true;
54  }
55  }
56 
57  return false;
58  }
59 
60  private function resolveObjectId(ResourceIdentification $identification): ?int
61  {
62  $this->initDB();
63  $r = $this->database->queryF(
64  "SELECT file_id FROM file_data WHERE rid = %s",
65  ['text'],
66  [$identification->serialize()]
67  );
68  $d = $this->database->fetchObject($r);
69 
70  return (isset($d->file_id) ? (int) $d->file_id : null);
71  }
72 
73  public function resourceHasBeenDeleted(ResourceIdentification $identification): bool
74  {
75  $object_id = $this->resolveObjectId($identification);
76  try {
77  $this->database->manipulateF(
78  "UPDATE object_data SET offline = 1 WHERE obj_id = %s",
79  ['text'],
80  [$object_id]
81  );
82  } catch (Throwable) {
83  return false;
84  }
85  return true;
86  }
87 
88  public function getLocationURIForResourceUsage(ResourceIdentification $identification): ?string
89  {
90  $this->initDB();
91  $r = $this->database->queryF(
92  "SELECT file_id FROM file_data WHERE rid = %s",
93  ['text'],
94  [$identification->serialize()]
95  );
96  $d = $this->database->fetchObject($r);
97  if ($d !== null && property_exists($d, 'file_id') && $d->file_id !== null) {
98  $references = ilObject::_getAllReferences($d->file_id);
99  $ref_id = array_shift($references);
100 
101  return ilLink::_getLink($ref_id, 'file');
102  }
103  return null;
104  }
105 
106  private function initDB(): void
107  {
108  global $DIC;
109  $this->database = $DIC->database();
110  }
111 }
canBeAccessedByCurrentUser(ResourceIdentification $identification)
getLocationURIForResourceUsage(ResourceIdentification $identification)
Class ilObjFileStakeholder.
static _getAllReferences(int $id)
get all reference ids for object ID
resourceHasBeenDeleted(ResourceIdentification $identification)
$ref_id
Definition: ltiauth.php:66
resolveObjectId(ResourceIdentification $identification)
global $DIC
Definition: shib_login.php:25
$r