ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilExcTutorFeedbackZipStakeholder.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_zip';
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  if ($object_id === null) {
58  return true;
59  }
60 
61  $ref_ids = ilObject2::_getAllReferences($object_id);
62  foreach ($ref_ids as $ref_id) {
63  // one must have read permissions on the exercise to see the instruction files
64  if ($DIC->access()->checkAccessOfUser($this->current_user, 'write', '', $ref_id)) {
65  return true;
66  }
67  }
68 
69  return false;
70  }
71 
72  public function resourceHasBeenDeleted(ResourceIdentification $identification): bool
73  {
74  // at this place we could handle de deletion of a resource. not needed for instruction files IMO.
75 
76  return true;
77  }
78 
79  public function getLocationURIForResourceUsage(ResourceIdentification $identification): ?string
80  {
81  $this->initDB();
82  $object_id = $this->resolveObjectId($identification);
83  if ($object_id !== null) {
84  $references = ilObject::_getAllReferences($object_id);
85  $ref_id = array_shift($references);
86 
87  // 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.
88  return ilLink::_getLink($ref_id, 'exc');
89  }
90  return null;
91  }
92 
93  private function resolveObjectId(ResourceIdentification $identification): ?int
94  {
95  $this->initDB();
96  $r = $this->database->queryF(
97  "SELECT exc_id FROM exc_assignment ass, exc_multi_feedback mf ON (ass.id = mf.ass_id) WHERE mf.zip_rid = %s;",
98  ['text'],
99  [$identification->serialize()]
100  );
101  $d = $this->database->fetchObject($r);
102 
103  return (isset($d->exc_id) ? (int) $d->exc_id : null);
104  }
105 
106  private function initDB(): void
107  {
108  global $DIC;
109  if ($this->database === null) {
110  $this->database = $DIC->database();
111  }
112  }
113 }
const ANONYMOUS_USER_ID
Definition: constants.php:27
canBeAccessedByCurrentUser(ResourceIdentification $identification)
static _getAllReferences(int $id)
get all reference ids for object ID
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
global $DIC
Definition: feed.php:28
$ref_id
Definition: ltiauth.php:67
getLocationURIForResourceUsage(ResourceIdentification $identification)
resourceHasBeenDeleted(ResourceIdentification $identification)
resolveObjectId(ResourceIdentification $identification)
$r