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