ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilTestParticipantsGUI.php
Go to the documentation of this file.
1 <?php
2 
32 {
33  public const CMD_SHOW = 'show';
34  public const CMD_SET_FILTER = 'setFilter';
35  public const CMD_RESET_FILTER = 'resetFilter';
36  public const CMD_SAVE_CLIENT_IP = 'saveClientIp';
37 
38  public const CALLBACK_ADD_PARTICIPANT = 'addParticipants';
39 
43  protected $testObj;
44 
48  protected $questionSetConfig;
49 
53  protected $objectiveParent;
54 
58  protected $testAccess;
59  private \ilGlobalTemplateInterface $main_tpl;
60 
66  {
67  global $DIC;
68  $this->main_tpl = $DIC->ui()->mainTemplate();
69  $this->testObj = $testObj;
70  $this->questionSetConfig = $questionSetConfig;
71  }
72 
76  public function getTestObj(): ilObjTest
77  {
78  return $this->testObj;
79  }
80 
84  public function setTestObj($testObj)
85  {
86  $this->testObj = $testObj;
87  }
88 
93  {
95  }
96 
101  {
102  $this->questionSetConfig = $questionSetConfig;
103  }
104 
109  {
110  return $this->objectiveParent;
111  }
112 
117  {
118  $this->objectiveParent = $objectiveParent;
119  }
120 
124  public function getTestAccess(): ilTestAccess
125  {
126  return $this->testAccess;
127  }
128 
133  {
134  $this->testAccess = $testAccess;
135  }
136 
140  public function executeCommand()
141  {
142  global $DIC; /* @var ILIAS\DI\Container $DIC */
143 
144 
145  switch ($DIC->ctrl()->getNextClass($this)) {
146  case 'ilrepositorysearchgui':
147 
148  require_once 'Modules/Test/classes/class.ilTestParticipantAccessFilter.php';
149  require_once 'Services/Search/classes/class.ilRepositorySearchGUI.php';
150 
151  $gui = new ilRepositorySearchGUI();
152  $gui->setCallback($this, self::CALLBACK_ADD_PARTICIPANT, array());
153 
154  $gui->addUserAccessFilterCallable(ilTestParticipantAccessFilter::getManageParticipantsUserFilter(
155  $this->getTestObj()->getRefId()
156  ));
157 
158 
159  $DIC->ctrl()->setReturn($this, self::CMD_SHOW);
160  $DIC->ctrl()->forwardCommand($gui);
161 
162  break;
163 
164  case "iltestevaluationgui":
165 
166  require_once 'Modules/Test/classes/class.ilTestEvaluationGUI.php';
167 
168  $gui = new ilTestEvaluationGUI($this->getTestObj());
169  $gui->setObjectiveOrientedContainer($this->getObjectiveParent());
170  $gui->setTestAccess($this->getTestAccess());
171  $DIC->tabs()->clearTargets();
172  $DIC->tabs()->clearSubTabs();
173 
174  $DIC->ctrl()->forwardCommand($gui);
175 
176  break;
177 
178  default:
179 
180  $command = $DIC->ctrl()->getCmd(self::CMD_SHOW) . 'Cmd';
181  $this->{$command}();
182  }
183  }
184 
185  public function addParticipants($a_user_ids = array()): ?bool
186  {
187  global $DIC; /* @var ILIAS\DI\Container $DIC */
188 
189  require_once 'Modules/Test/classes/class.ilTestParticipantAccessFilter.php';
190  $filterCallback = ilTestParticipantAccessFilter::getManageParticipantsUserFilter($this->getTestObj()->getRefId());
191  $a_user_ids = call_user_func_array($filterCallback, [$a_user_ids]);
192 
193  $countusers = 0;
194  // add users
195  if (is_array($a_user_ids)) {
196  $i = 0;
197  foreach ($a_user_ids as $user_id) {
198  $client_ip = $_POST["client_ip"][$i] ?? '';
199  $this->getTestObj()->inviteUser($user_id, $client_ip);
200  $countusers++;
201  $i++;
202  }
203  }
204  $message = "";
205  if ($countusers) {
206  $message = $DIC->language()->txt("tst_invited_selected_users");
207  }
208  if (strlen($message)) {
209  $this->main_tpl->setOnScreenMessage('info', $message, true);
210  } else {
211  $this->main_tpl->setOnScreenMessage('info', $DIC->language()->txt("tst_invited_nobody"), true);
212  return false;
213  }
214 
215  $DIC->ctrl()->redirect($this, self::CMD_SHOW);
216  return null;
217  }
218 
223  {
224  global $DIC; /* @var ILIAS\DI\Container $DIC */
225 
226  require_once 'Modules/Test/classes/tables/class.ilTestParticipantsTableGUI.php';
227  $tableGUI = new ilTestParticipantsTableGUI($this, self::CMD_SHOW);
228 
229  $tableGUI->setParticipantHasSolutionsFilterEnabled(
230  (bool) $this->getTestObj()->getFixedParticipants()
231  );
232 
233  if ($this->getTestObj()->getFixedParticipants()) {
234  $tableGUI->setTitle($DIC->language()->txt('tst_tbl_invited_users'));
235  } else {
236  $tableGUI->setTitle($DIC->language()->txt('tst_tbl_participants'));
237  }
238 
239  return $tableGUI;
240  }
241 
245  protected function setFilterCmd()
246  {
247  $tableGUI = $this->buildTableGUI();
248  $tableGUI->initFilter($this->getTestObj()->getFixedParticipants());
249  $tableGUI->writeFilterToSession();
250  $tableGUI->resetOffset();
251  $this->showCmd();
252  }
253 
257  protected function resetFilterCmd()
258  {
259  $tableGUI = $this->buildTableGUI();
260  $tableGUI->resetFilter();
261  $tableGUI->resetOffset();
262  $this->showCmd();
263  }
264 
268  public function showCmd()
269  {
270  global $DIC; /* @var ILIAS\DI\Container $DIC */
271 
272  $tableGUI = $this->buildTableGUI();
273 
274  if (!$this->getQuestionSetConfig()->areDepenciesBroken()) {
275  if ($this->getTestObj()->getFixedParticipants()) {
276  $participantList = $this->getTestObj()->getInvitedParticipantList()->getAccessFilteredList(
278  );
279 
280  $tableGUI->setData($this->applyFilterCriteria($participantList->getParticipantsTableRows()));
281  $tableGUI->setRowKeyDataField('usr_id');
282  $tableGUI->setManageInviteesCommandsEnabled(true);
283  $tableGUI->setDescription($DIC->language()->txt("fixed_participants_hint"));
284  } else {
285  $participantList = $this->getTestObj()->getActiveParticipantList()->getAccessFilteredList(
287  );
288 
289  $tableGUI->setData($participantList->getParticipantsTableRows());
290  $tableGUI->setRowKeyDataField('active_id');
291  }
292 
293  $tableGUI->setManageResultsCommandsEnabled(true);
294 
295  $this->initToolbarControls($participantList);
296  }
297 
298  $tableGUI->setAnonymity($this->getTestObj()->getAnonymity());
299 
300  $tableGUI->initColumns();
301  $tableGUI->initCommands();
302 
303  $tableGUI->initFilter();
304  $tableGUI->setFilterCommand(self::CMD_SET_FILTER);
305  $tableGUI->setResetCommand(self::CMD_RESET_FILTER);
306 
307  $DIC->ui()->mainTemplate()->setContent($DIC->ctrl()->getHTML($tableGUI));
308  }
309 
314  protected function applyFilterCriteria($in_rows): array
315  {
316  global $DIC; /* @var ILIAS\DI\Container $DIC */
317 
318  $selected_pax = ilSession::get('form_tst_participants_' . $this->getTestObj()->getRefId() . '_selection');
319 
320  if (!is_string($selected_pax)) {
321  return $in_rows;
322  }
323 
324  $filter = unserialize($selected_pax, ['allowed_classes' => false]);
325 
326  if (!is_string($filter) || $filter === 'all') {
327  return $in_rows;
328  }
329 
330  $rows = [];
331 
332  foreach ($in_rows as $row) {
333  $query = $DIC->database()->query(
334  'SELECT count(solution_id) count
335  FROM tst_solutions
336  WHERE active_fi = ' . $DIC->database()->quote($row['active_id'])
337  . ' HAVING count ' . ($filter === 'withSolutions' ? '>' : '=') . ' 0'
338  );
339 
340  if (is_array($DIC->database()->fetchAssoc($query))) {
341  $rows[] = $row;
342  }
343  }
344 
345  return $rows;
346  }
347 
348  protected function initToolbarControls(ilTestParticipantList $participantList)
349  {
350  global $DIC; /* @var ILIAS\DI\Container $DIC */
351 
352  if ($this->getTestObj()->getFixedParticipants()) {
353  $this->addUserSearchControls($DIC->toolbar());
354  }
355 
356  if ($this->getTestObj()->getFixedParticipants() && $participantList->hasUnfinishedPasses()) {
357  $DIC->toolbar()->addSeparator();
358  }
359 
360  if ($participantList->hasUnfinishedPasses()) {
361  $this->addFinishAllPassesButton($DIC->toolbar());
362  }
363  }
364 
369  protected function addUserSearchControls(ilToolbarGUI $toolbar)
370  {
371  global $DIC; /* @var ILIAS\DI\Container $DIC */
372 
373  // search button
374  include_once './Services/Search/classes/class.ilRepositorySearchGUI.php';
376  $this,
377  $toolbar,
378  array(
379  'auto_complete_name' => $DIC->language()->txt('user'),
380  'submit_name' => $DIC->language()->txt('add')
381  )
382  );
383 
384  require_once 'Services/UIComponent/Button/classes/class.ilLinkButton.php';
385  $search_btn = ilLinkButton::getInstance();
386  $search_btn->setCaption('tst_search_users');
387  $search_btn->setUrl($DIC->ctrl()->getLinkTargetByClass('ilRepositorySearchGUI', 'start'));
388 
389  $toolbar->addSeparator();
390  $toolbar->addButtonInstance($search_btn);
391  }
392 
396  protected function addFinishAllPassesButton(ilToolbarGUI $toolbar)
397  {
398  global $DIC; /* @var ILIAS\DI\Container $DIC */
399 
400  $finish_all_user_passes_btn = ilLinkButton::getInstance();
401  $finish_all_user_passes_btn->setCaption('finish_all_user_passes');
402  $finish_all_user_passes_btn->setUrl($DIC->ctrl()->getLinkTargetByClass('iltestevaluationgui', 'finishAllUserPasses'));
403  $toolbar->addButtonInstance($finish_all_user_passes_btn);
404  }
405 
409  protected function saveClientIpCmd()
410  {
411  global $DIC; /* @var ILIAS\DI\Container $DIC */
412 
413  require_once 'Modules/Test/classes/class.ilTestParticipantAccessFilter.php';
414  $filterCallback = ilTestParticipantAccessFilter::getManageParticipantsUserFilter($this->getTestObj()->getRefId());
415  $a_user_ids = call_user_func_array($filterCallback, [(array) $_POST["chbUser"]]);
416 
417  if (is_array($a_user_ids)) {
418  foreach ($a_user_ids as $user_id) {
419  $this->getTestObj()->setClientIP($user_id, $_POST["clientip_" . $user_id]);
420  }
421  } else {
422  $this->main_tpl->setOnScreenMessage('info', $DIC->language()->txt("select_one_user"), true);
423  }
424  $DIC->ctrl()->redirect($this, self::CMD_SHOW);
425  }
426 
430  protected function removeParticipantsCmd()
431  {
432  global $DIC; /* @var ILIAS\DI\Container $DIC */
433 
434  require_once 'Modules/Test/classes/class.ilTestParticipantAccessFilter.php';
435  $filterCallback = ilTestParticipantAccessFilter::getManageParticipantsUserFilter($this->getTestObj()->getRefId());
436  $a_user_ids = call_user_func_array($filterCallback, [(array) $_POST["chbUser"]]);
437 
438  if (is_array($a_user_ids)) {
439  foreach ($a_user_ids as $user_id) {
440  $this->getTestObj()->disinviteUser($user_id);
441  }
442  } else {
443  $this->main_tpl->setOnScreenMessage('info', $DIC->language()->txt("select_one_user"), true);
444  }
445 
446  $DIC->ctrl()->redirect($this, self::CMD_SHOW);
447  }
448 }
static get(string $a_var)
setObjectiveParent(ilTestObjectiveOrientedContainer $objectiveParent)
addButtonInstance(ilButtonBase $a_button)
Add button instance.
removeParticipantsCmd()
remove participants command
addParticipants($a_user_ids=array())
global $DIC
Definition: feed.php:28
resetFilterCmd()
reset table filter command
setFilterCmd()
set table filter command
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
__construct(ilObjTest $testObj, ilTestQuestionSetConfig $questionSetConfig)
ilTestParticipantsGUI constructor.
static fillAutoCompleteToolbar(object $parent_object, ilToolbarGUI $toolbar=null, array $a_options=[], bool $a_sticky=false)
array( auto_complete_name = $lng->txt(&#39;user&#39;), auto_complete_size = 15, user_type = array(ilCoursePar...
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...
$query
addUserSearchControls(ilToolbarGUI $toolbar)
$rows
Definition: xhr_table.php:10
saveClientIpCmd()
save client ip command
ilGlobalTemplateInterface $main_tpl
initToolbarControls(ilTestParticipantList $participantList)
addFinishAllPassesButton(ilToolbarGUI $toolbar)
$message
Definition: xapiexit.php:32
setTestAccess(ilTestAccess $testAccess)
setQuestionSetConfig($questionSetConfig)
$i
Definition: metadata.php:41