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