ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilTestParticipantsGUI.php
Go to the documentation of this file.
1<?php
2
3/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
4
18{
23 const CMD_SHOW = 'show';
24 const CMD_SET_FILTER = 'setFilter';
25 const CMD_RESET_FILTER = 'resetFilter';
26 const CMD_SAVE_CLIENT_IP = 'saveClientIp';
27
28 const CALLBACK_ADD_PARTICIPANT = 'addParticipants';
29
33 protected $testObj;
34
39
44
48 protected $testAccess;
49
55 {
56 $this->testObj = $testObj;
57 $this->questionSetConfig = $questionSetConfig;
58 }
59
63 public function getTestObj()
64 {
65 return $this->testObj;
66 }
67
71 public function setTestObj($testObj)
72 {
73 $this->testObj = $testObj;
74 }
75
79 public function getQuestionSetConfig()
80 {
82 }
83
88 {
89 $this->questionSetConfig = $questionSetConfig;
90 }
91
96 {
98 }
99
104 {
105 $this->objectiveParent = $objectiveParent;
106 }
107
111 public function getTestAccess() : ilTestAccess
112 {
113 return $this->testAccess;
114 }
115
120 {
121 $this->testAccess = $testAccess;
122 }
123
127 public function executeCommand()
128 {
129 global $DIC; /* @var ILIAS\DI\Container $DIC */
130
131
132 switch ($DIC->ctrl()->getNextClass($this)) {
133 case 'ilrepositorysearchgui':
134
135 require_once 'Modules/Test/classes/class.ilTestParticipantAccessFilter.php';
136 require_once 'Services/Search/classes/class.ilRepositorySearchGUI.php';
137
138 $gui = new ilRepositorySearchGUI();
139 $gui->setCallback($this, self::CALLBACK_ADD_PARTICIPANT, array());
140
142 $this->getTestObj()->getRefId()
143 ));
144
145
146 $DIC->ctrl()->setReturn($this, self::CMD_SHOW);
147 $DIC->ctrl()->forwardCommand($gui);
148
149 break;
150
151 case "iltestevaluationgui":
152
153 require_once 'Modules/Test/classes/class.ilTestEvaluationGUI.php';
154
155 $gui = new ilTestEvaluationGUI($this->getTestObj());
156 $gui->setObjectiveOrientedContainer($this->getObjectiveParent());
157 $gui->setTestAccess($this->getTestAccess());
158 $DIC->tabs()->clearTargets();
159 $DIC->tabs()->clearSubTabs();
160
161 $DIC->ctrl()->forwardCommand($gui);
162
163 break;
164
165 default:
166
167 $command = $DIC->ctrl()->getCmd(self::CMD_SHOW) . 'Cmd';
168 $this->{$command}();
169 }
170 }
171
176 public function addParticipants($a_user_ids = array())
177 {
178 global $DIC; /* @var ILIAS\DI\Container $DIC */
179
180 require_once 'Modules/Test/classes/class.ilTestParticipantAccessFilter.php';
182 $a_user_ids = call_user_func_array($filterCallback, [$a_user_ids]);
183
184 $countusers = 0;
185 // add users
186 if (is_array($a_user_ids)) {
187 $i = 0;
188 foreach ($a_user_ids as $user_id) {
189 $client_ip = $_POST["client_ip"][$i];
190 $this->getTestObj()->inviteUser($user_id, $client_ip);
191 $countusers++;
192 $i++;
193 }
194 }
195 $message = "";
196 if ($countusers) {
197 $message = $DIC->language()->txt("tst_invited_selected_users");
198 }
199 if (strlen($message)) {
201 } else {
202 ilUtil::sendInfo($DIC->language()->txt("tst_invited_nobody"), true);
203 return false;
204 }
205
206 $DIC->ctrl()->redirect($this, self::CMD_SHOW);
207 }
208
212 protected function buildTableGUI()
213 {
214 global $DIC; /* @var ILIAS\DI\Container $DIC */
215
216 require_once 'Modules/Test/classes/tables/class.ilTestParticipantsTableGUI.php';
217 $tableGUI = new ilTestParticipantsTableGUI($this, self::CMD_SHOW);
218
219 $tableGUI->setParticipantHasSolutionsFilterEnabled(
220 $this->getTestObj()->getFixedParticipants()
221 );
222
223 if ($this->getTestObj()->getFixedParticipants()) {
224 $tableGUI->setTitle($DIC->language()->txt('tst_tbl_invited_users'));
225 } else {
226 $tableGUI->setTitle($DIC->language()->txt('tst_tbl_participants'));
227 }
228
229 return $tableGUI;
230 }
231
235 protected function setFilterCmd()
236 {
237 $tableGUI = $this->buildTableGUI();
238 $tableGUI->initFilter($this->getTestObj()->getFixedParticipants());
239 $tableGUI->writeFilterToSession();
240 $tableGUI->resetOffset();
241 $this->showCmd();
242 }
243
247 protected function resetFilterCmd()
248 {
249 $tableGUI = $this->buildTableGUI();
250 $tableGUI->resetFilter();
251 $tableGUI->resetOffset();
252 $this->showCmd();
253 }
254
258 public function showCmd()
259 {
260 global $DIC; /* @var ILIAS\DI\Container $DIC */
261
262 $tableGUI = $this->buildTableGUI();
263
264 if (!$this->getQuestionSetConfig()->areDepenciesBroken()) {
265 if ($this->getTestObj()->getFixedParticipants()) {
266 $participantList = $this->getTestObj()->getInvitedParticipantList()->getAccessFilteredList(
268 );
269
270 $tableGUI->setData($this->applyFilterCriteria($participantList->getParticipantsTableRows()));
271 $tableGUI->setRowKeyDataField('usr_id');
272 $tableGUI->setManageInviteesCommandsEnabled(true);
273 $tableGUI->setDescription($DIC->language()->txt("fixed_participants_hint"));
274 } else {
275 $participantList = $this->getTestObj()->getActiveParticipantList()->getAccessFilteredList(
277 );
278
279 $tableGUI->setData($participantList->getParticipantsTableRows());
280 $tableGUI->setRowKeyDataField('active_id');
281 }
282
283 $tableGUI->setManageResultsCommandsEnabled(true);
284
285 $this->initToolbarControls($participantList);
286 }
287
288 $tableGUI->setAnonymity($this->getTestObj()->getAnonymity());
289
290 $tableGUI->initColumns();
291 $tableGUI->initCommands();
292
293 $tableGUI->initFilter();
294 $tableGUI->setFilterCommand(self::CMD_SET_FILTER);
295 $tableGUI->setResetCommand(self::CMD_RESET_FILTER);
296
297 $DIC->ui()->mainTemplate()->setContent($DIC->ctrl()->getHTML($tableGUI));
298 }
299
304 protected function applyFilterCriteria($in_rows)
305 {
306 global $DIC; /* @var ILIAS\DI\Container $DIC */
307
308 $sess_filter = $_SESSION['form_tst_participants_' . $this->getTestObj()->getRefId()]['selection'];
309 $sess_filter = str_replace('"', '', $sess_filter);
310 $sess_filter = explode(':', $sess_filter);
311 $filter = substr($sess_filter[2], 0, strlen($sess_filter[2]) - 1);
312
313 if ($filter == 'all' || $filter == false) {
314 return $in_rows; #unchanged - no filter.
315 }
316
317 $with_result = array();
318 $without_result = array();
319 foreach ($in_rows as $row) {
320 $result = $DIC->database()->query(
321 'SELECT count(solution_id) count
322 FROM tst_solutions
323 WHERE active_fi = ' . $DIC->database()->quote($row['active_id'])
324 );
325 $count = $DIC->database()->fetchAssoc($result);
326 $count = $count['count'];
327
328 if ($count == 0) {
329 $without_result[] = $row;
330 } else {
331 $with_result[] = $row;
332 }
333 }
334
335 if ($filter == 'withSolutions') {
336 return $with_result;
337 }
338 return $without_result;
339 }
340
341 protected function initToolbarControls(ilTestParticipantList $participantList)
342 {
343 global $DIC; /* @var ILIAS\DI\Container $DIC */
344
345 if ($this->getTestObj()->getFixedParticipants()) {
346 $this->addUserSearchControls($DIC->toolbar());
347 }
348
349 if ($this->getTestObj()->getFixedParticipants() && $participantList->hasUnfinishedPasses()) {
350 $DIC->toolbar()->addSeparator();
351 }
352
353 if ($participantList->hasUnfinishedPasses()) {
354 $this->addFinishAllPassesButton($DIC->toolbar());
355 }
356 }
357
362 protected function addUserSearchControls(ilToolbarGUI $toolbar)
363 {
364 global $DIC; /* @var ILIAS\DI\Container $DIC */
365
366 // search button
367 include_once './Services/Search/classes/class.ilRepositorySearchGUI.php';
369 $this,
370 $toolbar,
371 array(
372 'auto_complete_name' => $DIC->language()->txt('user'),
373 'submit_name' => $DIC->language()->txt('add')
374 )
375 );
376
377 require_once 'Services/UIComponent/Button/classes/class.ilLinkButton.php';
378 $search_btn = ilLinkButton::getInstance();
379 $search_btn->setCaption('tst_search_users');
380 $search_btn->setUrl($DIC->ctrl()->getLinkTargetByClass('ilRepositorySearchGUI', 'start'));
381
382 $toolbar->addSeparator();
383 $toolbar->addButtonInstance($search_btn);
384 }
385
389 protected function addFinishAllPassesButton(ilToolbarGUI $toolbar)
390 {
391 global $DIC; /* @var ILIAS\DI\Container $DIC */
392
393 $finish_all_user_passes_btn = ilLinkButton::getInstance();
394 $finish_all_user_passes_btn->setCaption('finish_all_user_passes');
395 $finish_all_user_passes_btn->setUrl($DIC->ctrl()->getLinkTargetByClass('iltestevaluationgui', 'finishAllUserPasses'));
396 $toolbar->addButtonInstance($finish_all_user_passes_btn);
397 }
398
402 protected function saveClientIpCmd()
403 {
404 global $DIC; /* @var ILIAS\DI\Container $DIC */
405
406 require_once 'Modules/Test/classes/class.ilTestParticipantAccessFilter.php';
408 $a_user_ids = call_user_func_array($filterCallback, [(array) $_POST["chbUser"]]);
409
410 if (is_array($a_user_ids)) {
411 foreach ($a_user_ids as $user_id) {
412 $this->getTestObj()->setClientIP($user_id, $_POST["clientip_" . $user_id]);
413 }
414 } else {
415 ilUtil::sendInfo($DIC->language()->txt("select_one_user"), true);
416 }
417 $DIC->ctrl()->redirect($this, self::CMD_SHOW);
418 }
419
423 protected function removeParticipantsCmd()
424 {
425 global $DIC; /* @var ILIAS\DI\Container $DIC */
426
427 require_once 'Modules/Test/classes/class.ilTestParticipantAccessFilter.php';
429 $a_user_ids = call_user_func_array($filterCallback, [(array) $_POST["chbUser"]]);
430
431 if (is_array($a_user_ids)) {
432 foreach ($a_user_ids as $user_id) {
433 $this->getTestObj()->disinviteUser($user_id);
434 }
435 } else {
436 ilUtil::sendInfo($DIC->language()->txt("select_one_user"), true);
437 }
438
439 $DIC->ctrl()->redirect($this, self::CMD_SHOW);
440 }
441}
$result
$_POST["username"]
$_SESSION["AccountId"]
An exception for terminatinating execution or to throw for unit testing.
static getInstance()
Factory.
static fillAutoCompleteToolbar($parent_object, ilToolbarGUI $toolbar=null, $a_options=array(), $a_sticky=false)
fill toolbar with
Output class for assessment test evaluation.
addUserSearchControls(ilToolbarGUI $toolbar)
setFilterCmd()
set table filter command
addParticipants($a_user_ids=array())
__construct(ilObjTest $testObj, ilTestQuestionSetConfig $questionSetConfig)
ilTestParticipantsGUI constructor.
initToolbarControls(ilTestParticipantList $participantList)
setQuestionSetConfig($questionSetConfig)
setTestAccess(ilTestAccess $testAccess)
setObjectiveParent(ilTestObjectiveOrientedContainer $objectiveParent)
removeParticipantsCmd()
remove participants command
saveClientIpCmd()
save client ip command
const CMD_SHOW
Command/Callback Constants.
resetFilterCmd()
reset table filter command
addFinishAllPassesButton(ilToolbarGUI $toolbar)
addButtonInstance(ilButtonBase $a_button)
Add button instance.
addSeparator()
Add separator.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
filter()
Definition: filter.php:2
global $DIC
Definition: goto.php:24
$i
Definition: metadata.php:24
$message
Definition: xapiexit.php:14