ILIAS  release_8 Revision v8.19
All Data Structures Namespaces Files Functions Variables Modules Pages
class.ilTestParticipantsTimeExtensionGUI.php
Go to the documentation of this file.
1 <?php
2 
30 {
34  public const CMD_SHOW_LIST = 'showList';
35  public const CMD_SHOW_FORM = 'showForm';
36  public const CMD_SET_TIMING = 'setTiming';
37 
38  protected ilObjTest $testObj;
39  protected ilCtrl $ctrl;
40  protected illanguage $lng;
41  private \ilGlobalTemplateInterface $main_tpl;
42 
43  public function __construct(ilObjTest $testObj)
44  {
45  global $DIC;
46  $this->ctrl = $DIC['ilCtrl'];
47  $this->lng = $DIC['lng'];
48  $this->main_tpl = $DIC->ui()->mainTemplate();
49  $this->testObj = $testObj;
50  }
51 
52  public function getTestObj(): ilObjTest
53  {
54  return $this->testObj;
55  }
56 
57  public function setTestObj(ilObjTest $testObj)
58  {
59  $this->testObj = $testObj;
60  }
61 
62  protected function isExtraTimeFeatureAvailable(): bool
63  {
64  return (
65  $this->getTestObj()->getProcessingTimeInSeconds() > 0
66  && $this->getTestObj()->getNrOfTries() == 1
67  );
68  }
69 
70  public function executeCommand()
71  {
72  if (!$this->isExtraTimeFeatureAvailable()) {
74  }
75 
76  switch ($this->ctrl->getNextClass($this)) {
77  default:
78 
79  $command = $this->ctrl->getCmd(self::CMD_SHOW_LIST) . 'Cmd';
80 
81  $this->{$command}();
82  }
83  }
84 
85  public function showListCmd()
86  {
87  $tableGUI = new ilTimingOverviewTableGUI($this, self::CMD_SHOW_LIST);
88  $tableGUI->addCommandButton(self::CMD_SHOW_FORM, $this->lng->txt('timing'));
89 
90  $participantList = new ilTestParticipantList($this->getTestObj());
91  $participantList->initializeFromDbRows($this->getTestObj()->getTestParticipants());
92 
93  $participantList = $participantList->getAccessFilteredList(
95  );
96 
97  $addons = $this->getTestObj()->getTimeExtensionsOfParticipants();
98 
99  $tableData = array();
100  foreach ($participantList as $participant) {
101  $tblRow = [
102  'started' => '',
103  'extratime' => 0,
104  'login' => $participant->getLogin(),
105  'name' => $this->lng->txt("anonymous")
106  ];
107 
108  $time = $this->getTestObj()->getStartingTimeOfUser($participant->getActiveId());
109  if ($time) {
110  $started = $this->lng->txt('tst_started') . ': ' . ilDatePresentation::formatDate(
111  new ilDateTime($time, IL_CAL_UNIX)
112  );
113 
114  $tblRow['started'] = $started;
115  }
116 
117  $participant_id = $participant->getActiveId();
118  if (array_key_exists($participant_id, $addons) && $addons[$participant_id] > 0) {
119  $tblRow['extratime'] = $addons[$participant_id];
120  }
121 
122  if (! $this->getTestObj()->getAnonymity()) {
123  $tblRow['name'] = $participant->getLastname() . ', ' . $participant->getFirstname();
124  }
125 
126  $tableData[] = $tblRow;
127  }
128 
129  $tableGUI->setData($tableData);
130 
131  $this->main_tpl->setContent($this->ctrl->getHTML($tableGUI));
132  }
133 
134  protected function showFormCmd()
135  {
136  $this->main_tpl->setContent($this->buildTimingForm()->getHTML());
137  }
138 
139 
140  protected function buildTimingForm(): ilPropertyFormGUI
141  {
142  $form = new ilPropertyFormGUI();
143  $form->setFormAction($this->ctrl->getFormAction($this));
144  $form->setTableWidth("100%");
145  $form->setId("tst_change_workingtime");
146  $form->setTitle($this->lng->txt("tst_change_workingtime"));
147 
148  // test users
149  require_once 'Modules/Test/classes/class.ilTestParticipantList.php';
150  $participantList = new ilTestParticipantList($this->getTestObj());
151  $participantList->initializeFromDbRows($this->getTestObj()->getTestParticipants());
152 
153  $participantList = $participantList->getAccessFilteredList(
155  );
156 
157  $addons = $this->getTestObj()->getTimeExtensionsOfParticipants();
158 
159  $participantslist = new ilSelectInputGUI($this->lng->txt('participants'), "participant");
160 
161  $options = array(
162  '' => $this->lng->txt('please_select'),
163  '0' => $this->lng->txt('all_participants')
164  );
165 
166  foreach ($participantList as $participant) {
167  $started = "";
168 
169  if ($this->getTestObj()->getAnonymity()) {
170  $name = $this->lng->txt("anonymous");
171  } else {
172  $name = $participant->getLastname() . ', ' . $participant->getFirstname();
173  }
174 
175  $time = $this->getTestObj()->getStartingTimeOfUser($participant->getActiveId());
176  if ($time) {
177  $started = ", " . $this->lng->txt('tst_started') . ': ' . ilDatePresentation::formatDate(new ilDateTime($time, IL_CAL_UNIX));
178  }
179 
180  $participant_id = $participant->getActiveId();
181  if (array_key_exists($participant_id, $addons) && $addons[$participant_id] > 0) {
182  $started .= ", " . $this->lng->txt('extratime') . ': ' . $addons[$participant_id] . ' ' . $this->lng->txt('minutes');
183  }
184 
185  $options[$participant->getActiveId()] = $participant->getLogin() . ' (' . $name . ')' . $started;
186  }
187 
188  $participantslist->setRequired(true);
189  $participantslist->setOptions($options);
190  $form->addItem($participantslist);
191 
192  // extra time
193  $extratime = new ilNumberInputGUI($this->lng->txt("extratime"), "extratime");
194  $extratime->setInfo($this->lng->txt('tst_extratime_info'));
195  $extratime->setRequired(true);
196  $extratime->setMinValue(0);
197  $extratime->setMinvalueShouldBeGreater(false);
198  $extratime->setSuffix($this->lng->txt('minutes'));
199  $extratime->setSize(5);
200  $form->addItem($extratime);
201 
202  if (is_array($_POST) && isset($_POST['cmd']['timing']) && $_POST['cmd']['timing'] != '') {
203  $form->setValuesByArray($_POST);
204  }
205 
206  $form->addCommandButton(self::CMD_SET_TIMING, $this->lng->txt("save"));
207  $form->addCommandButton(self::CMD_SHOW_LIST, $this->lng->txt("cancel"));
208 
209  return $form;
210  }
211 
212  protected function setTimingCmd()
213  {
214  $form = $this->buildTimingForm();
215 
216  if ($form->checkInput()) {
217  $this->getTestObj()->addExtraTime(
218  $form->getInput('participant'),
219  $form->getInput('extratime')
220  );
221 
222  $this->main_tpl->setOnScreenMessage('success', sprintf($this->lng->txt('tst_extratime_added'), $form->getInput('extratime')), true);
223  $this->ctrl->redirect($this, self::CMD_SHOW_LIST);
224  }
225 
226  $this->main_tpl->setVariable("ADM_CONTENT", $form->getHTML());
227  }
228 }
static formatDate(ilDateTime $date, bool $a_skip_day=false, bool $a_include_wd=false, bool $include_seconds=false)
const IL_CAL_UNIX
static accessViolationRedirect()
global $DIC
Definition: feed.php:28
if($format !==null) $name
Definition: metadata.php:247
This class represents a number property in a property form.
This file is part of ILIAS, a powerful learning management system published by ILIAS open source e-Le...