ILIAS  trunk Revision v11.0_alpha-3011-gc6b235a2e85
class.ilExcInstructionFilesStakeholder.php
Go to the documentation of this file.
1<?php
2
21
26{
27 protected ?ilDBInterface $database = null;
28
29
30 public function getId(): string
31 {
32 return 'exc_instruction_files';
33 }
34
35 public function getOwnerOfNewResources(): int
36 {
38 }
39
40 public function canBeAccessedByCurrentUser(ResourceIdentification $identification): bool
41 {
42 global $DIC;
43
44 $object_id = $this->resolveObjectId($identification);
45 if ($object_id === null) {
46 return true;
47 }
48
49 $ref_ids = ilObject2::_getAllReferences($object_id);
50 foreach ($ref_ids as $ref_id) {
51 // one must have read permissions on the exercise to see the instruction files
52 if ($DIC->access()->checkAccessOfUser($this->current_user, 'read', '', $ref_id)) {
53 return true;
54 }
55 }
56
57 return false;
58 }
59
60 public function resourceHasBeenDeleted(ResourceIdentification $identification): bool
61 {
62 // at this place we could handle de deletion of a resource. not needed for instruction files IMO.
63
64 return true;
65 }
66
67 public function getLocationURIForResourceUsage(ResourceIdentification $identification): ?string
68 {
69 $this->initDB();
70 $object_id = $this->resolveObjectId($identification);
71 if ($object_id !== null) {
72 $references = ilObject::_getAllReferences($object_id);
73 $ref_id = array_shift($references);
74
75 // we currently deliver the goto-url of the exercise in which the resource is used. if possible, you could deliver a more speficic url wo the assignment as well.
76 return ilLink::_getLink($ref_id, 'exc');
77 }
78 return null;
79 }
80
81 private function resolveObjectId(ResourceIdentification $identification): ?int
82 {
83 $this->initDB();
84 $r = $this->database->queryF(
85 "SELECT exc_id, rcid FROM il_resource_rca JOIN exc_assignment ON exc_assignment.if_rcid = il_resource_rca.rcid WHERE il_resource_rca.rid = %s;",
86 ['text'],
87 [$identification->serialize()]
88 );
89 $d = $this->database->fetchObject($r);
90
91 return (isset($d->exc_id) ? (int) $d->exc_id : null);
92 }
93
94 private function initDB(): void
95 {
96 global $DIC;
97 if ($this->database === null) {
98 $this->database = $DIC->database();
99 }
100 }
101}
resourceHasBeenDeleted(ResourceIdentification $identification)
resolveObjectId(ResourceIdentification $identification)
canBeAccessedByCurrentUser(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