ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilExcTutorFeedbackFileStakeholder.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
22 use ILIAS\Exercise;
26 
28 {
29  protected int $owner = 6;
30  private int $current_user;
31  protected ?ilDBInterface $database = null;
32 
33  public function __construct(int $owner = 6)
34  {
35  global $DIC;
36  $this->current_user = (int) ($DIC->isDependencyAvailable('user')
37  ? $DIC->user()->getId()
38  : (defined('ANONYMOUS_USER_ID') ? ANONYMOUS_USER_ID : 6));
39  $this->owner = $owner;
40  }
41 
42  public function getId(): string
43  {
44  return 'exc_tutor_feedback';
45  }
46 
47  public function getOwnerOfNewResources(): int
48  {
49  return $this->owner;
50  }
51 
52  public function canBeAccessedByCurrentUser(ResourceIdentification $identification): bool
53  {
54  global $DIC;
55 
56  $object_id = $this->resolveObjectId($identification);
57  $is_recipient = $this->isRecipient($identification);
58 
59  if ($object_id === null) {
60  return true;
61  }
62 
63  $ref_ids = ilObject2::_getAllReferences($object_id);
64  foreach ($ref_ids as $ref_id) {
65  if ($DIC->access()->checkAccessOfUser($this->current_user, 'write', '', $ref_id)) {
66  return true;
67  }
68  if ($is_recipient &&
69  $DIC->access()->checkAccessOfUser($this->current_user, 'read', '', $ref_id)) {
70  return true;
71  }
72  }
73 
74  return false;
75  }
76 
77  public function resourceHasBeenDeleted(ResourceIdentification $identification): bool
78  {
79  // at this place we could handle de deletion of a resource. not needed for instruction files IMO.
80 
81  return true;
82  }
83 
84  public function getLocationURIForResourceUsage(ResourceIdentification $identification): ?string
85  {
86  $this->initDB();
87  $object_id = $this->resolveObjectId($identification);
88  if ($object_id !== null) {
89  $references = ilObject::_getAllReferences($object_id);
90  $ref_id = array_shift($references);
91 
92  // 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.
93  return ilLink::_getLink($ref_id, 'exc');
94  }
95  return null;
96  }
97 
98  private function isRecipient(ResourceIdentification $identification): bool
99  {
100  $this->initDB();
101  $r = $this->database->queryF(
102  "SELECT exc_mem_ass_status.usr_id FROM il_resource_rca JOIN exc_mem_ass_status ON exc_mem_ass_status.feedback_rcid = il_resource_rca.rcid WHERE il_resource_rca.rid = %s;",
103  ['text'],
104  [$identification->serialize()]
105  );
106  $d = $this->database->fetchAssoc($r);
107  $user_id = (int) ($d["usr_id"] ?? 0);
108 
109  return ($user_id === $this->current_user);
110  }
111 
112  private function resolveObjectId(ResourceIdentification $identification): ?int
113  {
114  $this->initDB();
115  $r = $this->database->queryF(
116  "SELECT exc_id, rcid FROM il_resource_rca JOIN exc_mem_ass_status ON exc_mem_ass_status.feedback_rcid = il_resource_rca.rcid JOIN exc_assignment ON (exc_assignment.id = exc_mem_ass_status.ass_id) WHERE il_resource_rca.rid = %s;",
117  ['text'],
118  [$identification->serialize()]
119  );
120  $d = $this->database->fetchObject($r);
121 
122  return (isset($d->exc_id) ? (int) $d->exc_id : null);
123  }
124 
125  private function initDB(): void
126  {
127  global $DIC;
128  if ($this->database === null) {
129  $this->database = $DIC->database();
130  }
131  }
132 }
resourceHasBeenDeleted(ResourceIdentification $identification)
getLocationURIForResourceUsage(ResourceIdentification $identification)
const ANONYMOUS_USER_ID
Definition: constants.php:27
static _getAllReferences(int $id)
get all reference ids for object ID
canBeAccessedByCurrentUser(ResourceIdentification $identification)
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
isRecipient(ResourceIdentification $identification)
$ref_id
Definition: ltiauth.php:67
resolveObjectId(ResourceIdentification $identification)
$r