ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilExcInstructionFilesStakeholder.php
Go to the documentation of this file.
1 <?php
2 
20 use ILIAS\Exercise;
24 
29 {
30  protected int $owner = 6;
31  private int $current_user;
32  protected ?ilDBInterface $database = null;
33 
37  public function __construct(int $owner = 6)
38  {
39  global $DIC;
40  $this->current_user = (int) ($DIC->isDependencyAvailable('user')
41  ? $DIC->user()->getId()
42  : (defined('ANONYMOUS_USER_ID') ? ANONYMOUS_USER_ID : 6));
43  $this->owner = $owner;
44  }
45 
46  public function getId(): string
47  {
48  return 'exc_instruction_files';
49  }
50 
51  public function getOwnerOfNewResources(): int
52  {
53  return $this->owner;
54  }
55 
56  public function canBeAccessedByCurrentUser(ResourceIdentification $identification): bool
57  {
58  global $DIC;
59 
60  $object_id = $this->resolveObjectId($identification);
61  if ($object_id === null) {
62  return true;
63  }
64 
65  $ref_ids = ilObject2::_getAllReferences($object_id);
66  foreach ($ref_ids as $ref_id) {
67  // one must have read permissions on the exercise to see the instruction files
68  if ($DIC->access()->checkAccessOfUser($this->current_user, 'read', '', $ref_id)) {
69  return true;
70  }
71  }
72 
73  return false;
74  }
75 
76  public function resourceHasBeenDeleted(ResourceIdentification $identification): bool
77  {
78  // at this place we could handle de deletion of a resource. not needed for instruction files IMO.
79 
80  return true;
81  }
82 
83  public function getLocationURIForResourceUsage(ResourceIdentification $identification): ?string
84  {
85  $this->initDB();
86  $object_id = $this->resolveObjectId($identification);
87  if ($object_id !== null) {
88  $references = ilObject::_getAllReferences($object_id);
89  $ref_id = array_shift($references);
90 
91  // 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.
92  return ilLink::_getLink($ref_id, 'exc');
93  }
94  return null;
95  }
96 
97  private function resolveObjectId(ResourceIdentification $identification): ?int
98  {
99  $this->initDB();
100  $r = $this->database->queryF(
101  "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;",
102  ['text'],
103  [$identification->serialize()]
104  );
105  $d = $this->database->fetchObject($r);
106 
107  return (isset($d->exc_id) ? (int) $d->exc_id : null);
108  }
109 
110  private function initDB(): void
111  {
112  global $DIC;
113  if ($this->database === null) {
114  $this->database = $DIC->database();
115  }
116  }
117 }
const ANONYMOUS_USER_ID
Definition: constants.php:27
resourceHasBeenDeleted(ResourceIdentification $identification)
static _getAllReferences(int $id)
get all reference ids for object ID
getLocationURIForResourceUsage(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
$ref_id
Definition: ltiauth.php:67
__construct(int $owner=6)
ilObjFileStakeholder constructor.
resolveObjectId(ResourceIdentification $identification)
canBeAccessedByCurrentUser(ResourceIdentification $identification)
$r