ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilTestParticipantData.php
Go to the documentation of this file.
1 <?php
2 
26 {
30  protected $db;
31 
35  protected $lng;
36 
37  private array $activeIdsFilter;
38 
39  private array $userIdsFilter;
40 
41  private array $anonymousIdsFilter;
42 
43  private array $byActiveId;
44 
45  private array $byUserId;
46 
47  private array $byAnonymousId;
48 
53 
55 
57  {
58  $this->db = $db;
59  $this->lng = $lng;
60 
61  $this->activeIdsFilter = array();
62  $this->userIdsFilter = array();
63  $this->anonymousIdsFilter = array();
64 
65  $this->byActiveId = array();
66  $this->byUserId = array();
67  $this->byAnonymousId = array();
68 
69  $this->scoredParticipantsFilterEnabled = false;
70  }
71 
75  public function getParticipantAccessFilter(): ?callable
76  {
78  }
79 
84  {
85  $this->participantAccessFilter = $participantAccessFilter;
86  }
87 
91  public function isScoredParticipantsFilterEnabled(): bool
92  {
94  }
95 
99  public function setScoredParticipantsFilterEnabled($scoredParticipantsFilterEnabled): void
100  {
101  $this->scoredParticipantsFilterEnabled = $scoredParticipantsFilterEnabled;
102  }
103 
104  public function load($testId): void
105  {
106  $this->byActiveId = array();
107  $this->byUserId = array();
108 
109  $query = "
110  SELECT ta.active_id,
111  ta.user_fi user_id,
112  ta.anonymous_id,
113  ud.firstname,
114  ud.lastname,
115  ud.login,
116  ud.matriculation
117  FROM tst_active ta
118  LEFT JOIN usr_data ud
119  ON ud.usr_id = ta.user_fi
120  WHERE test_fi = %s
121  AND {$this->getConditionalExpression()}
122  AND {$this->getScoredParticipantsFilterExpression()}
123  ";
124 
125  $res = $this->db->queryF($query, array('integer'), array($testId));
126 
127  $rows = array();
128  $accessFilteredUsrIds = array();
129 
130  while ($row = $this->db->fetchAssoc($res)) {
131  $accessFilteredUsrIds[] = $row['user_id'];
132  $rows[] = $row;
133  }
134 
135  if (is_callable($this->getParticipantAccessFilter(), true)) {
136  $accessFilteredUsrIds = call_user_func_array($this->getParticipantAccessFilter(), [$accessFilteredUsrIds]);
137  }
138 
139  foreach ($rows as $row) {
140  if (!in_array($row['user_id'], $accessFilteredUsrIds)) {
141  continue;
142  }
143 
144  $this->byActiveId[ $row['active_id'] ] = $row;
145 
146  if ($row['user_id'] == ANONYMOUS_USER_ID) {
147  $this->byAnonymousId[ $row['anonymous_id'] ] = $row;
148  } else {
149  $this->byUserId[ $row['user_id'] ] = $row;
150  }
151  }
152  }
153 
154  public function getScoredParticipantsFilterExpression(): string
155  {
156  if ($this->isScoredParticipantsFilterEnabled()) {
157  return "ta.last_finished_pass = ta.last_started_pass";
158  }
159 
160  return '1 = 1';
161  }
162 
163  public function getConditionalExpression(): string
164  {
165  $conditions = array();
166 
167  if (count($this->getActiveIdsFilter())) {
168  $conditions[] = $this->db->in('active_id', $this->getActiveIdsFilter(), false, 'integer');
169  }
170 
171  if (count($this->getUserIdsFilter())) {
172  $conditions[] = $this->db->in('user_fi', $this->getUserIdsFilter(), false, 'integer');
173  }
174 
175  if (count($this->getAnonymousIdsFilter())) {
176  $conditions[] = $this->db->in('anonymous_id', $this->getAnonymousIdsFilter(), false, 'integer');
177  }
178 
179  if (count($conditions)) {
180  return '(' . implode(' OR ', $conditions) . ')';
181  }
182 
183  return '1 = 1';
184  }
185 
186  public function setActiveIdsFilter($activeIdsFilter): void
187  {
188  $this->activeIdsFilter = $activeIdsFilter;
189  }
190 
191  public function getActiveIdsFilter(): array
192  {
193  return $this->activeIdsFilter;
194  }
195 
196  public function setUserIdsFilter($userIdsFilter): void
197  {
198  $this->userIdsFilter = $userIdsFilter;
199  }
200 
201  public function getUserIdsFilter(): array
202  {
203  return $this->userIdsFilter;
204  }
205 
206  public function setAnonymousIdsFilter($anonymousIdsFilter): void
207  {
208  $this->anonymousIdsFilter = $anonymousIdsFilter;
209  }
210 
211  public function getAnonymousIdsFilter(): array
212  {
214  }
215 
216  public function getActiveIds(): array
217  {
218  return array_keys($this->byActiveId);
219  }
220 
221  public function getUserIds(): array
222  {
223  return array_keys($this->byUserId);
224  }
225 
226  public function getAnonymousIds(): array
227  {
228  return array_keys($this->byAnonymousId);
229  }
230 
231  public function getUserIdByActiveId($activeId)
232  {
233  return $this->byActiveId[$activeId]['user_id'];
234  }
235 
236  public function getActiveIdByUserId($userId)
237  {
238  return $this->byUserId[$userId]['active_id'] ?? null;
239  }
240 
241  public function getConcatedFullnameByActiveId($activeId): string
242  {
243  return "{$this->byActiveId[$activeId]['firstname']} {$this->byActiveId[$activeId]['lastname']}";
244  }
245 
246  public function getFormatedFullnameByActiveId($activeId): string
247  {
248  return ilObjTestAccess::_getParticipantData($activeId);
249  }
250 
251  public function getFileSystemCompliantFullnameByActiveId($activeId): string
252  {
253  $fullname = str_replace(' ', '', $this->byActiveId[$activeId]['lastname']);
254  $fullname .= '_' . str_replace(' ', '', $this->byActiveId[$activeId]['firstname']);
255  $fullname .= '_' . $this->byActiveId[$activeId]['login'];
256 
257  return ilFileUtils::getASCIIFilename($fullname);
258  }
259 
260  public function getOptionArray(): array
261  {
262  $options = array();
263 
264  foreach ($this->byActiveId as $activeId => $usrData) {
265  $options[$activeId] = ilObjTestAccess::_getParticipantData($activeId);
266  }
267 
268  asort($options);
269 
270  return $options;
271  }
272 
273  public function getAnonymousActiveIds(): array
274  {
275  $anonymousActiveIds = array();
276 
277  foreach ($this->byActiveId as $activeId => $active) {
278  if ($active['user_id'] == ANONYMOUS_USER_ID) {
279  $anonymousActiveIds[] = $activeId;
280  }
281  }
282 
283  return $anonymousActiveIds;
284  }
285 
286  public function getUserDataByActiveId($activeId)
287  {
288  if (isset($this->byActiveId[$activeId])) {
289  return $this->byActiveId[$activeId];
290  }
291 
292  return null;
293  }
294 }
$res
Definition: ltiservices.php:69
__construct(ilDBInterface $db, ilLanguage $lng)
setAnonymousIdsFilter($anonymousIdsFilter)
static _getParticipantData($active_id)
Retrieves a participant name from active id.
const ANONYMOUS_USER_ID
Definition: constants.php:27
setParticipantAccessFilter($participantAccessFilter)
static getASCIIFilename(string $a_filename)
$query
setScoredParticipantsFilterEnabled($scoredParticipantsFilterEnabled)
$rows
Definition: xhr_table.php:10