ILIAS  release_9 Revision v9.13-25-g2c18ec4c24f
class.ilTestAccess.php
Go to the documentation of this file.
1 <?php
2 
19 declare(strict_types=1);
20 
30 {
32  protected ilDBInterface $db;
33  protected ilLanguage $lng;
34 
36 
37  public function __construct(
38  protected int $ref_id,
39  protected int $test_id
40  ) {
42  global $DIC;
43  $this->db = $DIC['ilDB'];
44  $this->lng = $DIC['lng'];
45  $this->participant_access_filter = new ilTestParticipantAccessFilterFactory($DIC['ilAccess']);
46  $this->setAccess($DIC->access());
47 
48  $this->setRefId($ref_id);
49  $this->setTestId($test_id);
50  }
51 
52  public function getAccess(): ilAccessHandler
53  {
54  return $this->access;
55  }
56 
57  public function setAccess(ilAccessHandler $access)
58  {
59  $this->access = $access;
60  }
61 
62  public function getRefId(): int
63  {
64  return $this->ref_id;
65  }
66 
67  public function setRefId(int $ref_id)
68  {
69  $this->ref_id = $ref_id;
70  }
71 
72  public function getTestId(): int
73  {
74  return $this->test_id;
75  }
76 
77  public function setTestId(int $test_id)
78  {
79  $this->test_id = $test_id;
80  }
81 
85  public function checkCorrectionsAccess(): bool
86  {
87  return $this->getAccess()->checkAccess('write', '', $this->getRefId());
88  }
89 
93  public function checkScoreParticipantsAccess(): bool
94  {
95  if ($this->getAccess()->checkAccess('write', '', $this->getRefId())) {
96  return true;
97  }
98 
99  if ($this->getAccess()->checkPositionAccess(ilOrgUnitOperation::OP_SCORE_PARTICIPANTS, $this->getRefId())) {
100  return true;
101  }
102 
103  return false;
104  }
105 
109  public function checkManageParticipantsAccess(): bool
110  {
111  if ($this->getAccess()->checkAccess('write', '', $this->getRefId())) {
112  return true;
113  }
114 
115  if ($this->getAccess()->checkPositionAccess(ilOrgUnitOperation::OP_MANAGE_PARTICIPANTS, $this->getRefId())) {
116  return true;
117  }
118 
119  return false;
120  }
121 
125  public function checkParticipantsResultsAccess(): bool
126  {
127  if ($this->getAccess()->checkAccess('write', '', $this->getRefId())) {
128  return true;
129  }
130 
131  if ($this->getAccess()->checkAccess('tst_results', '', $this->getRefId())) {
132  return true;
133  }
134 
135  if ($this->getAccess()->checkPositionAccess(ilOrgUnitOperation::OP_MANAGE_PARTICIPANTS, $this->getRefId())) {
136  return true;
137  }
138 
139  if ($this->getAccess()->checkPositionAccess(ilOrgUnitOperation::OP_ACCESS_RESULTS, $this->getRefId())) {
140  return true;
141  }
142 
143  return false;
144  }
145 
149  public function checkStatisticsAccess(): bool
150  {
151  if ($this->getAccess()->checkAccess('tst_statistics', '', $this->getRefId())) {
152  return true;
153  }
154 
155  if ($this->getAccess()->checkPositionAccess(ilOrgUnitOperation::OP_ACCESS_RESULTS, $this->getRefId())) {
156  return true;
157  }
158 
159  return false;
160  }
161 
162  protected function checkAccessForActiveId(Closure $access_filter, int $active_id): bool
163  {
164  $participantData = new ilTestParticipantData($this->db, $this->lng);
165  $participantData->setActiveIdsFilter(array($active_id));
166  $participantData->setParticipantAccessFilter($access_filter);
167  $participantData->load($this->getTestId());
168 
169  return in_array($active_id, $participantData->getActiveIds());
170  }
171 
172  public function checkResultsAccessForActiveId(int $active_id): bool
173  {
174  $access_filter = $this->participant_access_filter->getAccessResultsUserFilter($this->getRefId());
175  return $this->checkAccessForActiveId($access_filter, $active_id);
176  }
177 
178  public function checkScoreParticipantsAccessForActiveId(int $active_id): bool
179  {
180  $access_filter = $this->participant_access_filter->getScoreParticipantsUserFilter($this->getRefId());
181  return $this->checkAccessForActiveId($access_filter, $active_id);
182  }
183 
184  public function checkStatisticsAccessForActiveId(int $active_id): bool
185  {
186  $access_filter = $this->participant_access_filter->getAccessStatisticsUserFilter($this->getRefId());
187  return $this->checkAccessForActiveId($access_filter, $active_id);
188  }
189 }
checkAccessForActiveId(Closure $access_filter, int $active_id)
ilAccessHandler $access
checkResultsAccessForActiveId(int $active_id)
setAccess(ilAccessHandler $access)
checkScoreParticipantsAccessForActiveId(int $active_id)
global $DIC
Definition: feed.php:28
setTestId(int $test_id)
$ref_id
Definition: ltiauth.php:67
__construct(VocabulariesInterface $vocabularies)
checkStatisticsAccessForActiveId(int $active_id)
ilDBInterface $db
setRefId(int $ref_id)
ilTestParticipantAccessFilterFactory $participant_access_filter