ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilTestInfoScreenToolbarGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
4 require_once 'Services/UIComponent/Toolbar/classes/class.ilToolbarGUI.php';
5 require_once 'Services/UIComponent/Button/classes/class.ilLinkButton.php';
6 require_once 'Services/UIComponent/Button/classes/class.ilSubmitButton.php';
7 require_once 'Services/Form/classes/class.ilFormPropertyGUI.php';
8 require_once 'Services/Form/classes/class.ilHiddenInputGUI.php';
9 
17 {
18  private static $TARGET_CLASS_PATH_BASE = array('ilRepositoryGUI', 'ilObjTestGUI');
19 
23  private $globalToolbar;
24 
28  protected $db;
29 
33  protected $access;
34 
38  protected $ctrl;
39 
43  protected $lng;
44 
48  protected $pluginAdmin;
49 
53  protected $testOBJ;
54 
59 
63  protected $testPlayerGUI;
64 
68  protected $testSession;
69 
73  protected $testSequence;
74 
79 
83  private $infoMessages = array();
84 
88  private $failureMessages = array();
89 
91  {
92  $this->db = $db;
93  $this->access = $access;
94  $this->ctrl = $ctrl;
95  $this->lng = $lng;
96  $this->pluginAdmin = $pluginAdmin;
97  }
98 
102  public function getGlobalToolbar()
103  {
104  return $this->globalToolbar;
105  }
106 
111  {
112  $this->globalToolbar = $globalToolbar;
113  }
114 
118  public function getTestOBJ()
119  {
120  return $this->testOBJ;
121  }
122 
126  public function setTestOBJ($testOBJ)
127  {
128  $this->testOBJ = $testOBJ;
129  }
130 
134  public function getTestQuestionSetConfig()
135  {
137  }
138 
143  {
144  $this->testQuestionSetConfig = $testQuestionSetConfig;
145  }
146 
150  public function getTestPlayerGUI()
151  {
152  return $this->testPlayerGUI;
153  }
154 
159  {
160  $this->testPlayerGUI = $testPlayerGUI;
161  }
162 
166  public function getTestSession()
167  {
168  return $this->testSession;
169  }
170 
174  public function setTestSession($testSession)
175  {
176  $this->testSession = $testSession;
177  }
178 
182  public function getTestSequence()
183  {
184  return $this->testSequence;
185  }
186 
191  {
192  $this->testSequence = $testSequence;
193  }
194 
198  public function getSessionLockString()
199  {
201  }
202 
207  {
208  $this->sessionLockString = $sessionLockString;
209  }
210 
214  public function getInfoMessages()
215  {
216  return $this->infoMessages;
217  }
218 
222  public function addInfoMessage($infoMessage)
223  {
224  $this->infoMessages[] = $infoMessage;
225  }
226 
230  public function getFailureMessages()
231  {
232  return $this->failureMessages;
233  }
234 
238  public function addFailureMessage($failureMessage)
239  {
240  $this->failureMessages[] = $failureMessage;
241  }
242 
243  public function setFormAction($formAction, $isMultipart = false, $target = '')
244  {
245  if($this->globalToolbar instanceof parent)
246  {
247  $this->globalToolbar->setFormAction($formAction, $isMultipart, $target);
248  }
249  else
250  {
251  parent::setFormAction($formAction, $isMultipart, $target);
252  }
253  }
254 
255  public function addButtonInstance(ilButtonBase $btnInstance)
256  {
257  if($this->globalToolbar instanceof parent)
258  {
259  $this->globalToolbar->addButtonInstance($btnInstance);
260  }
261  else
262  {
263  parent::addButtonInstance($btnInstance);
264  }
265  }
266 
267  public function setCloseFormTag($enabled)
268  {
269  if($this->globalToolbar instanceof parent)
270  {
271  $this->globalToolbar->setCloseFormTag($enabled);
272  }
273  else
274  {
275  parent::setCloseFormTag($enabled);
276  }
277  }
278 
279  public function addInputItem(ilToolbarItem $inputItem, $outputLabel = false)
280  {
281  if($this->globalToolbar instanceof parent)
282  {
283  $this->globalToolbar->addInputItem($inputItem, $outputLabel);
284  }
285  else
286  {
287  parent::addInputItem($inputItem, $outputLabel);
288  }
289  }
290 
291  public function addFormInput($formInput)
292  {
293  if($this->globalToolbar instanceof parent)
294  {
295  $this->globalToolbar->addFormInput($formInput);
296  }
297  else
298  {
299  parent::addFormInput($formInput);
300  }
301  }
302 
303  public function clearItems()
304  {
305  if($this->globalToolbar instanceof parent)
306  {
307  $this->globalToolbar->setItems(array());
308  }
309  else
310  {
311  $this->setItems(array());
312  }
313  }
314 
315  private function getClassName($target)
316  {
317  if( is_object($target) )
318  {
319  $target = get_class($target);
320  }
321 
322  return $target;
323  }
324 
325  private function getClassNameArray($target)
326  {
327  if( is_array($target) )
328  {
329  return $target;
330  }
331 
332  return array($this->getClassName($target));
333  }
334 
335  private function getClassPath($target)
336  {
337  return array_merge(self::$TARGET_CLASS_PATH_BASE, $this->getClassNameArray($target));
338  }
339 
340  private function setParameter($target, $parameter, $value)
341  {
342  $this->ctrl->setParameterByClass($this->getClassName($target), $parameter, $value);
343  }
344 
345  private function buildLinkTarget($target, $cmd = null)
346  {
347  return $this->ctrl->getLinkTargetByClass($this->getClassPath($target), $cmd);
348  }
349 
350  private function buildFormAction($target)
351  {
352  return $this->ctrl->getFormActionByClass($this->getClassPath($target));
353  }
354 
356  {
357  if( !strlen($this->getSessionLockString()) )
358  {
360  }
361  }
362 
363  private function buildSessionLockString()
364  {
365  return md5($_COOKIE['PHPSESSID'] . time());
366  }
367 
374  {
375  if( !$this->getTestSession()->getActiveId() )
376  {
377  return false;
378  }
379 
380  if( !$this->getTestOBJ()->isDynamicTest() )
381  {
382  return false;
383  }
384 
385  if( !$this->getTestOBJ()->isPassDeletionAllowed() )
386  {
387  return false;
388  }
389 
390  if( !$this->getTestSequence()->hasStarted($this->getTestSession()) )
391  {
392  return false;
393  }
394 
395  return true;
396  }
397 
403  {
404  require_once 'Modules/Test/classes/confirmations/class.ilTestPassDeletionConfirmationGUI.php';
405 
406  $this->ctrl->setParameterByClass(
407  'iltestevaluationgui', 'context', ilTestPassDeletionConfirmationGUI::CONTEXT_INFO_SCREEN
408  );
409 
410  $this->setParameter('iltestevaluationgui', 'active_id', $this->getTestSession()->getActiveId());
411  $this->setParameter('iltestevaluationgui', 'pass', $this->getTestSession()->getPass());
412 
413  $btn = ilLinkButton::getInstance();
414  $btn->setCaption('tst_delete_dyn_test_results_btn');
415  $btn->setUrl($this->buildLinkTarget('iltestevaluationgui', 'confirmDeletePass'));
416  $btn->setPrimary(false);
417 
418  $this->addButtonInstance($btn);
419  }
420 
422  {
423  if( !$this->getTestOBJ()->isSkillServiceEnabled() )
424  {
425  return false;
426  }
427 
428  if( $this->getTestOBJ()->isDynamicTest() )
429  {
430  $questionSetConfig = $this->getTestQuestionSetConfig();
431  $questionContainerId = $questionSetConfig->getSourceQuestionPoolId();
432  }
433  else
434  {
435  $questionContainerId = $this->getTestOBJ()->getId();
436  }
437 
438  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionSkillAssignmentList.php';
439  require_once 'Modules/Test/classes/class.ilTestSkillLevelThreshold.php';
440 
441  $assignmentList = new ilAssQuestionSkillAssignmentList($this->db);
442  $assignmentList->setParentObjId($questionContainerId);
443  $assignmentList->loadFromDb();
444 
445  foreach($assignmentList->getUniqueAssignedSkills() as $data)
446  {
447  foreach($data['skill']->getLevelData() as $level)
448  {
449  $treshold = new ilTestSkillLevelThreshold($this->db);
450  $treshold->setTestId($this->getTestOBJ()->getTestId());
451  $treshold->setSkillBaseId($data['skill_base_id']);
452  $treshold->setSkillTrefId($data['skill_tref_id']);
453  $treshold->setSkillLevelId($level['id']);
454 
455  if( !$treshold->dbRecordExists() )
456  {
457  return true;
458  }
459  }
460  }
461 
462  return false;
463  }
464 
466  {
467  require_once 'Modules/Test/classes/class.ilTestSkillLevelThresholdsGUI.php';
468 
469  $link = $this->buildLinkTarget(
470  array('ilTestSkillAdministrationGUI', 'ilTestSkillLevelThresholdsGUI'),
472  );
473 
474  $msg = $this->lng->txt('tst_skl_level_thresholds_missing');
475  $msg .= '<br /><a href="'.$link.'">'.$this->lng->txt('tst_skl_level_thresholds_link').'</a>';
476 
477  return $msg;
478  }
479 
481  {
482  if( !$this->testOBJ->isFixedTest() )
483  {
484  return false;
485  }
486 
487  require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionSkillAssignmentList.php';
488  $assignmentList = new ilAssQuestionSkillAssignmentList($this->db);
489  $assignmentList->setParentObjId($this->testOBJ->getId());
490  $assignmentList->loadFromDb();
491 
492  return $assignmentList->hasSkillsAssignedLowerThanBarrier();
493  }
494 
495  private function getSkillAssignBarrierInfo()
496  {
497  require_once 'Modules/Test/classes/class.ilObjAssessmentFolder.php';
498 
499  return sprintf( $this->lng->txt('tst_skill_triggerings_num_req_answers_not_reached_warn'),
501  );
502  }
503 
504  public function build()
505  {
507 
508  $this->setParameter($this->getTestPlayerGUI(), 'lock', $this->getSessionLockString());
509  $this->setParameter($this->getTestPlayerGUI(), 'sequence', $this->getTestSession()->getLastSequence());
510  $this->setParameter('ilObjTestGUI', 'ref_id', $this->getTestOBJ()->getRefId());
511 
512  $this->setFormAction($this->buildFormAction($this->testPlayerGUI));
513 
514  $online_access = false;
515  if ($this->getTestOBJ()->getFixedParticipants())
516  {
517  include_once "./Modules/Test/classes/class.ilObjTestAccess.php";
518  $online_access_result = ilObjTestAccess::_lookupOnlineTestAccess($this->getTestOBJ()->getId(), $this->getTestSession()->getUserId());
519  if ($online_access_result === true)
520  {
521  $online_access = true;
522  }
523  else
524  {
525  $this->addInfoMessage($online_access_result);
526  }
527  }
528 
529  if( $this->getTestOBJ()->isOnline() && $this->getTestOBJ()->isComplete( $this->getTestQuestionSetConfig() ) )
530  {
531  if ((!$this->getTestOBJ()->getFixedParticipants() || $online_access) && $this->access->checkAccess("read", "", $this->getTestOBJ()->getRefId()))
532  {
533  $executable = $this->getTestOBJ()->isExecutable(
534  $this->getTestSession(), $this->getTestSession()->getUserId(), $allowPassIncrease = TRUE
535  );
536 
537  if ($executable["executable"])
538  {
539  if( $this->getTestOBJ()->areObligationsEnabled() && $this->getTestOBJ()->hasObligations($this->getTestOBJ()->getTestId()) )
540  {
541  $this->addInfoMessage($this->lng->txt('tst_test_contains_obligatory_questions'));
542  }
543 
544  if ($this->getTestSession()->getActiveId() > 0)
545  {
546  // resume test
547  require_once 'Modules/Test/classes/class.ilTestPassesSelector.php';
548  $testPassesSelector = new ilTestPassesSelector($this->db, $this->getTestOBJ());
549  $testPassesSelector->setActiveId($this->getTestSession()->getActiveId());
550  $testPassesSelector->setLastFinishedPass($this->getTestSession()->getLastFinishedPass());
551 
552  $closedPasses = $testPassesSelector->getClosedPasses();
553  $existingPasses = $testPassesSelector->getExistingPasses();
554 
555  if ($existingPasses > $closedPasses)
556  {
558  $btn->setCaption('tst_resume_test');
559  $btn->setCommand('resumePlayer');
560  $btn->setPrimary(true);
561  $this->addButtonInstance($btn);
562  }
563  else
564  {
566  $btn->setCaption($this->getTestOBJ()->getStartTestLabel($this->getTestSession()->getActiveId()), false);
567  $btn->setCommand('startPlayer');
568  $btn->setPrimary(true);
569  $this->addButtonInstance($btn);
570  }
571  }
572  else
573  {
574  // start new test
576  $btn->setCaption($this->getTestOBJ()->getStartTestLabel($this->getTestSession()->getActiveId()), false);
577  $btn->setCommand('startPlayer');
578  $btn->setPrimary(true);
579  $this->addButtonInstance($btn);
580  }
581  }
582  else
583  {
584  $this->addInfoMessage($executable['errormessage']);
585  }
586  if ($this->getTestSession()->getActiveId() > 0)
587  {
588  // test results button
589 
590  require_once 'Modules/Test/classes/class.ilTestPassesSelector.php';
591  $testPassesSelector = new ilTestPassesSelector($GLOBALS['ilDB'], $this->getTestOBJ());
592  $testPassesSelector->setActiveId($this->getTestSession()->getActiveId());
593  $testPassesSelector->setLastFinishedPass($this->getTestSession()->getLastFinishedPass());
594 
595  if( $this->getTestOBJ()->canShowTestResults($this->getTestSession()) )
596  {
597  $btn = ilLinkButton::getInstance();
598  $btn->setCaption('tst_show_results');
599  $btn->setUrl($this->buildLinkTarget('ilTestEvaluationGUI', 'outUserResultsOverview'));
600  $btn->setPrimary(false);
601  $this->addButtonInstance($btn);
602 
603  if ($this->getTestOBJ()->getHighscoreEnabled())
604  {
605  // Can also compare results then
606  $btn = ilLinkButton::getInstance();
607  $btn->setCaption('tst_show_toplist');
608  $btn->setUrl($this->buildLinkTarget('ilTestToplistGUI', 'outResultsToplist'));
609  $btn->setPrimary(false);
610  $this->addButtonInstance($btn);
611  }
612 
613  if( $this->getTestOBJ()->isSkillServiceToBeConsidered() )
614  {
615  require_once 'Modules/Test/classes/class.ilTestSkillEvaluationGUI.php';
616 
617  $btn = ilLinkButton::getInstance();
618  $btn->setCaption('tst_show_comp_results');
619  $btn->setUrl($this->buildLinkTarget('ilTestSkillEvaluationGUI', ilTestSkillEvaluationGUI::CMD_SHOW));
620  $btn->setPrimary(false);
621  $this->addButtonInstance($btn);
622  }
623  }
624 
625  }
626  }
627  if ($this->getTestSession()->getActiveId() > 0)
628  {
629  if ($this->getTestOBJ()->canShowSolutionPrintview($this->getTestSession()->getUserId()))
630  {
631  $btn = ilLinkButton::getInstance();
632  $btn->setCaption('tst_list_of_answers_show');
633  $btn->setUrl($this->buildLinkTarget('ilTestEvaluationGUI', 'outUserListOfAnswerPasses'));
634  $btn->setPrimary(false);
635  $this->addButtonInstance($btn);
636  }
637  }
638 
640  {
642  }
643 
644  if($_SESSION["AccountId"] == ANONYMOUS_USER_ID)
645  {
646  if( $this->getItems() )
647  {
648  $this->addSeparator();
649  }
650 
651  require_once 'Services/Form/classes/class.ilTextInputGUI.php';
652  $anonymous_id = new ilTextInputGUI($this->lng->txt('enter_anonymous_code'), 'anonymous_id');
653  $anonymous_id->setSize(8);
654  $this->addInputItem($anonymous_id, true);
655  $this->addFormButton($this->lng->txt('submit'), 'setAnonymousId');
656  }
657  }
658  if( !$this->getTestOBJ()->isOnline() && !$this->getTestQuestionSetConfig()->areDepenciesBroken() )
659  {
660  $message = $this->lng->txt("test_is_offline");
661 
662  if($this->access->checkAccess("write", "", $this->getTestOBJ()->getRefId()))
663  {
664  $message .= "<br /><a href=\"".$this->buildLinkTarget('ilobjtestsettingsgeneralgui')."\">".
665  $this->lng->txt("test_edit_settings")."</a>";
666  }
667 
668  $this->addInfoMessage($message);
669  }
670 
671  if($this->access->checkAccess("write", "", $this->getTestOBJ()->getRefId()))
672  {
673  require_once 'Modules/TestQuestionPool/classes/questions/class.ilAssQuestionSkillAssignmentImportFails.php';
674  $qsaImportFails = new ilAssQuestionSkillAssignmentImportFails($this->testOBJ->getId());
675  require_once 'Modules/Test/classes/class.ilTestSkillLevelThresholdImportFails.php';
676  $sltImportFails = new ilTestSkillLevelThresholdImportFails($this->testOBJ->getId());
677 
678  if( $qsaImportFails->failedImportsRegistered() || $sltImportFails->failedImportsRegistered() )
679  {
680  $importFailsMsg = array();
681 
682  if( $qsaImportFails->failedImportsRegistered() )
683  {
684  $importFailsMsg[] = $qsaImportFails->getFailedImportsMessage($this->lng);
685  }
686 
687  if( $sltImportFails->failedImportsRegistered() )
688  {
689  $importFailsMsg[] = $sltImportFails->getFailedImportsMessage($this->lng);
690  }
691 
692  $button = ilLinkButton::getInstance();
693  $button->setUrl($this->ctrl->getLinkTargetByClass('ilObjTestGUI', 'removeImportFails'));
694  $button->setCaption('ass_skl_import_fails_remove_btn');
695  $importFailsMsg[] = $button->render();
696 
697  $this->addFailureMessage(implode('<br />', $importFailsMsg));
698  }
699  elseif( $this->getTestOBJ()->isSkillServiceToBeConsidered() )
700  {
701  if( $this->areSkillLevelThresholdsMissing() )
702  {
704  }
705 
707  {
708  $this->addInfoMessage($this->getSkillAssignBarrierInfo());
709  }
710  }
711 
712  if( $this->getTestQuestionSetConfig()->areDepenciesBroken() )
713  {
714  $this->addFailureMessage($this->getTestQuestionSetConfig()->getDepenciesBrokenMessage($this->lng));
715 
716  $this->clearItems();
717  }
718  elseif( $this->getTestQuestionSetConfig()->areDepenciesInVulnerableState() )
719  {
720  $this->addInfoMessage( $this->getTestQuestionSetConfig()->getDepenciesInVulnerableStateMessage($this->lng) );
721  }
722  }
723  }
724 
725  public function sendMessages()
726  {
727  ilUtil::sendInfo( array_pop($this->getInfoMessages()) );
728  ilUtil::sendFailure( array_pop($this->getFailureMessages()) );
729  }
730 }
This class provides processing control methods.
$_SESSION["AccountId"]
setParameter($target, $parameter, $value)
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
$cmd
Definition: sahs_server.php:35
Interface for property form input GUI classes that can be used in ilToolbarGUI.
Administration class for plugins.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
Interface ilDBInterface.
static _lookupOnlineTestAccess($a_test_id, $a_user_id)
Checks if a user is allowd to run an online exam.
addInputItem(ilToolbarItem $inputItem, $outputLabel=false)
addFormButton($a_txt, $a_cmd, $a_acc_key="", $a_primary=false, $a_class=false)
Add form button to toolbar.
setSize($a_size)
Set Size.
This class represents a text property in a property form.
addButtonInstance(ilButtonBase $btnInstance)
addSeparator()
Add separator.
Create styles array
The data for the language used.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
setFormAction($formAction, $isMultipart=false, $target='')
$_COOKIE['ilClientId']
Definition: BPMN2Parser.php:15
language handling
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
__construct(ilDBInterface $db, ilAccessHandler $access, ilCtrl $ctrl, ilLanguage $lng, ilPluginAdmin $pluginAdmin)
Class ilAccessHandler.