ILIAS  release_7 Revision v7.30-3-g800a261c036
class.ilMarkSchemaGUI.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (c) 1998-2014 ILIAS open source, Extended GPL, see docs/LICENSE */
3 
10 {
14  protected $object;
15 
19  protected $lng;
20 
24  protected $ctrl;
25 
29  protected $tpl;
30 
34  protected $toolbar;
35 
39  public function __construct(ilMarkSchemaAware $object)
40  {
47  global $DIC;
48  $ilCtrl = $DIC['ilCtrl'];
49  $lng = $DIC['lng'];
50  $tpl = $DIC['tpl'];
51  $ilToolbar = $DIC['ilToolbar'];
52 
53  $this->ctrl = $ilCtrl;
54  $this->lng = $lng;
55  $this->tpl = $tpl;
56  $this->toolbar = $ilToolbar;
57 
58  $this->object = $object;
59  }
60 
64  public function executeCommand()
65  {
66  global $DIC; /* @var ILIAS\DI\Container $DIC */
67 
68  $DIC->tabs()->activateTab(ilTestTabsManager::TAB_ID_SETTINGS);
69 
70  $cmd = $this->ctrl->getCmd('showMarkSchema');
71  $this->$cmd();
72  }
73 
77  protected function ensureMarkSchemaCanBeEdited()
78  {
79  if (!$this->object->canEditMarks()) {
80  ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
81  $this->ctrl->redirect($this, 'showMarkSchema');
82  }
83  }
84 
88  protected function ensureEctsGradesCanBeEdited()
89  {
90  if (!$this->object->canEditEctsGrades()) {
91  ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
92  $this->ctrl->redirect($this, 'showMarkSchema');
93  }
94  }
95 
99  protected function addMarkStep()
100  {
102 
103  if ($this->saveMarkSchemaFormData()) {
104  $this->object->getMarkSchema()->addMarkStep();
105  } else {
106  $this->tpl->setOnScreenMessage('failure', $this->lng->txt('mark_schema_invalid'), true);
107  }
108  $this->showMarkSchema();
109  }
110 
111  protected function saveMarkSchemaFormData()
112  {
113  $no_save_error = true;
114  $this->object->getMarkSchema()->flush();
115  $postdata = $_POST;
116  foreach ($postdata as $key => $value) {
117  if (preg_match('/mark_short_(\d+)/', $key, $matches)) {
118  $passed = "0";
119  if (isset($postdata["passed_$matches[1]"])) {
120  $passed = "1";
121  }
122 
123  $percentage = str_replace(',', '.', ilUtil::stripSlashes($postdata["mark_percentage_$matches[1]"]));
124  if (!is_numeric($percentage)
125  || (float) $percentage < 0.0
126  || (float) $percentage > 100.0) {
127  $percentage = 0;
128  $no_save_error = false;
129  }
130 
131  $this->object->getMarkSchema()->addMarkStep(
132  ilUtil::stripSlashes($postdata["mark_short_$matches[1]"]),
133  ilUtil::stripSlashes($postdata["mark_official_$matches[1]"]),
134  (float) $percentage,
135  (int) ilUtil::stripSlashes($passed)
136  );
137  }
138  }
139 
140  return $no_save_error;
141  }
142 
146  protected function addSimpleMarkSchema()
147  {
149 
150  $this->object->getMarkSchema()->createSimpleSchema(
151  $this->lng->txt('failed_short'),
152  $this->lng->txt('failed_official'),
153  0,
154  0,
155  $this->lng->txt('passed_short'),
156  $this->lng->txt('passed_official'),
157  50,
158  1
159  );
160  $this->showMarkSchema();
161  }
162 
166  protected function deleteMarkSteps() : void
167  {
168  $delete_mark_steps = $_POST['marks'];
170  if (!isset($delete_mark_steps) || !is_array($delete_mark_steps)) {
171  $this->showMarkSchema();
172  return;
173  }
174 
175  // test delete
176  $schema = clone $this->object->getMarkSchema();
177  $schema->deleteMarkSteps($delete_mark_steps);
178  $check_result = $schema->checkMarks();
179  if (is_string($check_result)) {
180  ilUtil::sendFailure($this->lng->txt($check_result), true);
181  $this->showMarkSchema();
182  return;
183  }
184 
185  // actual delete
186  if (!empty($delete_mark_steps)) {
187  $this->object->getMarkSchema()->deleteMarkSteps($delete_mark_steps);
188  } else {
189  $this->tpl->setOnScreenMessage('info', $this->lng->txt('tst_delete_missing_mark'));
190  }
191  $this->object->getMarkSchema()->saveToDb($this->object->getTestId());
192 
193  $this->showMarkSchema();
194  }
195 
199  protected function saveMarks()
200  {
202 
203  if ($this->saveMarkSchemaFormData()) {
204  $result = $this->object->checkMarks();
205  } else {
206  $result = 'mark_schema_invalid';
207  }
208 
209  if (is_string($result)) {
210  ilUtil::sendFailure($this->lng->txt($result), true);
211  } else {
212  $this->object->getMarkSchema()->saveToDb($this->object->getMarkSchemaForeignId());
213  $this->object->onMarkSchemaSaved();
214  $this->tpl->setOnScreenMessage('success', $this->lng->txt('saved_successfully'), true);
215  $this->object->getMarkSchema()->flush();
216  $this->object->getMarkSchema()->loadFromDb($this->object->getTestId());
217  }
218 
219  $this->showMarkSchema();
220  }
221 
225  private function objectSupportsEctsGrades()
226  {
227  require_once 'Modules/Test/interfaces/interface.ilEctsGradesEnabled.php';
228  return $this->object instanceof ilEctsGradesEnabled;
229  }
230 
235  protected function showMarkSchema(ilPropertyFormGUI $ects_form = null)
236  {
237  if (!$this->object->canEditMarks()) {
238  ilUtil::sendInfo($this->lng->txt('cannot_edit_marks'));
239  }
240 
241  $this->toolbar->setFormAction($this->ctrl->getFormAction($this, 'showMarkSchema'));
242 
243  require_once 'Modules/Test/classes/tables/class.ilMarkSchemaTableGUI.php';
244  $mark_schema_table = new ilMarkSchemaTableGUI($this, 'showMarkSchema', '', $this->object);
245 
246  if ($this->object->canEditMarks()) {
247  require_once 'Services/UIComponent/Button/classes/class.ilSubmitButton.php';
248  $create_simple_mark_schema_button = ilSubmitButton::getInstance();
249  $create_simple_mark_schema_button->setCaption($this->lng->txt('tst_mark_create_simple_mark_schema'), false);
250  $create_simple_mark_schema_button->setCommand('addSimpleMarkSchema');
251  $this->toolbar->addButtonInstance($create_simple_mark_schema_button);
252 
253  require_once 'Services/UIComponent/Button/classes/class.ilButton.php';
254  $create_new_mark_step_button = ilButton::getInstance();
255  $create_new_mark_step_button->setCaption($this->lng->txt('tst_mark_create_new_mark_step'), false);
256  $create_new_mark_step_button->setButtonType(ilButton::BUTTON_TYPE_SUBMIT);
257  $create_new_mark_step_button->setForm('form_' . $mark_schema_table->getId());
258  $create_new_mark_step_button->setName('addMarkStep');
259  $this->toolbar->addButtonInstance($create_new_mark_step_button);
260  }
261 
262 
263  $content_parts = array($mark_schema_table->getHTML());
264 
265  if ($this->objectSupportsEctsGrades() && $this->object->canShowEctsGrades()) {
266  if (!($ects_form instanceof ilPropertyFormGUI)) {
267  $ects_form = $this->getEctsForm();
268  $this->populateEctsForm($ects_form);
269  }
270  $content_parts[] = $ects_form->getHTML();
271  }
272 
273  $this->tpl->setContent(implode('<br />', $content_parts));
274  }
275 
279  protected function populateEctsForm(ilPropertyFormGUI $form)
280  {
281  $data = array();
282 
283  $data['ectcs_status'] = $this->object->getECTSOutput();
284  $data['use_ects_fx'] = preg_match('/\d+/', $this->object->getECTSFX());
285  $data['ects_fx_threshold'] = $this->object->getECTSFX();
286 
287  $ects_grades = $this->object->getECTSGrades();
288  for ($i = ord('a'); $i <= ord('e'); $i++) {
289  $mark = chr($i);
290  $data['ects_grade_' . $mark] = $ects_grades[chr($i - 32)];
291  }
292 
293  $form->setValuesByArray($data);
294  }
295 
299  protected function getEctsForm()
300  {
301  require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
302 
303  $disabled = !$this->object->canEditEctsGrades();
304 
305  $form = new ilPropertyFormGUI();
306  $form->setFormAction($this->ctrl->getFormAction($this, 'saveEctsForm'));
307  $form->setTitle($this->lng->txt('ects_output_of_ects_grades'));
308 
309  $allow_ects_marks = new ilCheckboxInputGUI($this->lng->txt('ects_allow_ects_grades'), 'ectcs_status');
310  $allow_ects_marks->setDisabled($disabled);
311  for ($i = ord('a'); $i <= ord('e'); $i++) {
312  $mark = chr($i);
313 
314  $mark_step = new ilNumberInputGUI(chr($i - 32), 'ects_grade_' . $mark);
315  $mark_step->setInfo(
316  $this->lng->txt('ects_grade_desc_prefix') . ' ' . $this->lng->txt('ects_grade_' . $mark . '_desc')
317  );
318  $mark_step->setSize(5);
319  $mark_step->allowDecimals(true);
320  $mark_step->setMinValue(0, true);
321  $mark_step->setMaxValue(100, true);
322  $mark_step->setSuffix($this->lng->txt('percentile'));
323  $mark_step->setRequired(true);
324  $mark_step->setDisabled($disabled);
325  $allow_ects_marks->addSubItem($mark_step);
326  }
327 
328  $mark_step = new ilNonEditableValueGUI('F', 'ects_grade_f');
329  $mark_step->setInfo(
330  $this->lng->txt('ects_grade_desc_prefix') . ' ' . $this->lng->txt('ects_grade_f_desc')
331  );
332  $allow_ects_marks->addSubItem($mark_step);
333 
334  $use_ects_fx = new ilCheckboxInputGUI($this->lng->txt('use_ects_fx'), 'use_ects_fx');
335  $use_ects_fx->setDisabled($disabled);
336  $allow_ects_marks->addSubItem($use_ects_fx);
337 
338  $mark_step = new ilNonEditableValueGUI('FX', 'ects_grade_fx');
339  $mark_step->setInfo(
340  $this->lng->txt('ects_grade_desc_prefix') . ' ' . $this->lng->txt('ects_grade_fx_desc')
341  );
342  $use_ects_fx->addSubItem($mark_step);
343 
344  $threshold = new ilNumberInputGUI($this->lng->txt('ects_fx_threshold'), 'ects_fx_threshold');
345  $threshold->setInfo($this->lng->txt('ects_fx_threshold_info'));
346  $threshold->setSuffix($this->lng->txt('percentile'));
347  $threshold->allowDecimals(true);
348  $threshold->setSize(5);
349  $threshold->setRequired(true);
350  $threshold->setDisabled($disabled);
351  $use_ects_fx->addSubItem($threshold);
352 
353 
354  $form->addItem($allow_ects_marks);
355 
356  if (!$disabled) {
357  $form->addCommandButton('saveEctsForm', $this->lng->txt('save'));
358  }
359 
360  return $form;
361  }
362 
366  protected function saveEctsForm()
367  {
369 
370  $ects_form = $this->getEctsForm();
371  if (!$ects_form->checkInput()) {
372  $ects_form->setValuesByPost();
373  $this->showMarkSchema($ects_form);
374  return;
375  }
376 
377  $grades = array();
378  for ($i = ord('a'); $i <= ord('e'); $i++) {
379  $mark = chr($i);
380  $grades[chr($i - 32)] = $ects_form->getInput('ects_grade_' . $mark);
381  }
382 
383  $this->object->setECTSGrades($grades);
384  $this->object->setECTSOutput((int) $ects_form->getInput('ectcs_status'));
385  $this->object->setECTSFX(
386  $ects_form->getInput('use_ects_fx') && preg_match('/\d+/', $ects_form->getInput('ects_fx_threshold')) ?
387  $ects_form->getInput('ects_fx_threshold'):
388  null
389  );
390 
391  $this->object->saveECTSStatus();
392 
393  ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
394  $ects_form->setValuesByPost();
395  $this->showMarkSchema($ects_form);
396  }
397 }
$data
Definition: storeScorm.php:23
$result
executeCommand()
Controller method.
This class represents a property form user interface.
deleteMarkSteps()
Delete selected mark steps.
static getInstance()
This class represents a checkbox property in a property form.
addMarkStep()
Add a new mark step to the tests marks.
setInfo($a_info)
Set Information Text.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
showMarkSchema(ilPropertyFormGUI $ects_form=null)
Display mark schema.
This class represents a number property in a property form.
global $DIC
Definition: goto.php:24
addSimpleMarkSchema()
Add a simple mark schema to the tests marks.
static stripSlashes($a_str, $a_strip_html=true, $a_allow="")
strip slashes if magic qoutes is enabled
saveMarks()
Save the mark schema.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
populateEctsForm(ilPropertyFormGUI $form)
This class represents a non editable value in a property form.
__construct(Container $dic, ilPlugin $plugin)
const BUTTON_TYPE_SUBMIT
setDisabled($a_disabled)
Set Disabled.
$_POST["username"]
setValuesByArray($a_values, $a_restrict_to_value_keys=false)
Set form values from an array.
$i
Definition: metadata.php:24