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