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