ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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 $ilCtrl, $lng, $tpl, $ilToolbar;
48 
49  $this->ctrl = $ilCtrl;
50  $this->lng = $lng;
51  $this->tpl = $tpl;
52  $this->toolbar = $ilToolbar;
53 
54  $this->object = $object;
55  }
56 
60  public function executeCommand()
61  {
62  $cmd = $this->ctrl->getCmd('showMarkSchema');
63  $this->$cmd();
64  }
65 
69  protected function ensureMarkSchemaCanBeEdited()
70  {
71  if(!$this->object->canEditMarks())
72  {
73  ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
74  $this->ctrl->redirect($this, 'showMarkSchema');
75  }
76  }
77 
81  protected function ensureEctsGradesCanBeEdited()
82  {
83  if(!$this->object->canEditEctsGrades())
84  {
85  ilUtil::sendFailure($this->lng->txt('permission_denied'), true);
86  $this->ctrl->redirect($this, 'showMarkSchema');
87  }
88  }
89 
93  protected function addMarkStep()
94  {
96 
97  $this->saveMarkSchemaFormData();
98  $this->object->getMarkSchema()->addMarkStep();
99  $this->showMarkSchema();
100  }
101 
105  protected function saveMarkSchemaFormData()
106  {
107  $this->object->getMarkSchema()->flush();
108  foreach($_POST as $key => $value)
109  {
110  if(preg_match('/mark_short_(\d+)/', $key, $matches))
111  {
112  $this->object->getMarkSchema()->addMarkStep(
113  ilUtil::stripSlashes($_POST["mark_short_$matches[1]"]),
114  ilUtil::stripSlashes($_POST["mark_official_$matches[1]"]),
115  ilUtil::stripSlashes($_POST["mark_percentage_$matches[1]"]),
116  ilUtil::stripSlashes($_POST["passed_$matches[1]"])
117  );
118  }
119  }
120  }
121 
125  protected function addSimpleMarkSchema()
126  {
128 
129  $this->object->getMarkSchema()->createSimpleSchema(
130  $this->lng->txt('failed_short'), $this->lng->txt('failed_official'),
131  0, 0,
132  $this->lng->txt('passed_short'), $this->lng->txt('passed_official'),
133  50, 1
134  );
135  $this->showMarkSchema();
136  }
137 
141  protected function deleteMarkSteps()
142  {
144 
145  if(!isset($_POST['marks']) || !is_array($_POST['marks']))
146  {
147  $this->showMarkSchema();
148  return;
149  }
150 
151  $this->saveMarkSchemaFormData();
152  $delete_mark_steps = array();
153  foreach($_POST['marks'] as $mark_step_id)
154  {
155  $delete_mark_steps[] = $mark_step_id;
156  }
157 
158  if(count($delete_mark_steps))
159  {
160  $this->object->getMarkSchema()->deleteMarkSteps($delete_mark_steps);
161  }
162  else
163  {
164  ilUtil::sendInfo($this->lng->txt('tst_delete_missing_mark'));
165  }
166 
167  $this->showMarkSchema();
168  }
169 
173  protected function saveMarks()
174  {
176 
177  try
178  {
179  $this->saveMarkSchemaFormData();
180  $result = $this->object->checkMarks();
181  }
182  catch(Exception $e)
183  {
184  $result = $this->lng->txt('mark_schema_invalid');
185  }
186 
187  if(is_string($result))
188  {
189  ilUtil::sendFailure($this->lng->txt($result), true);
190  }
191  else
192  {
193  $this->object->getMarkSchema()->saveToDb($this->object->getMarkSchemaForeignId());
194  $this->object->onMarkSchemaSaved();
195  ilUtil::sendSuccess($this->lng->txt('saved_successfully'), true);
196  }
197 
198  $this->ctrl->redirect($this);
199  }
200 
204  private function objectSupportsEctsGrades()
205  {
206  require_once 'Modules/Test/interfaces/interface.ilEctsGradesEnabled.php';
207  return $this->object instanceof ilEctsGradesEnabled;
208  }
209 
214  protected function showMarkSchema(ilPropertyFormGUI $ects_form = null)
215  {
216  if(!$this->object->canEditMarks())
217  {
218  ilUtil::sendInfo($this->lng->txt('cannot_edit_marks'));
219  }
220 
221  $this->toolbar->setFormAction($this->ctrl->getFormAction($this, 'showMarkSchema'));
222 
223  require_once 'Modules/Test/classes/tables/class.ilMarkSchemaTableGUI.php';
224  $mark_schema_table = new ilMarkSchemaTableGUI($this, 'showMarkSchema', '', $this->object);
225 
226  if($this->object->canEditMarks())
227  {
228  require_once 'Services/UIComponent/Button/classes/class.ilSubmitButton.php';
229  $create_simple_mark_schema_button = ilSubmitButton::getInstance();
230  $create_simple_mark_schema_button->setCaption($this->lng->txt('tst_mark_create_simple_mark_schema'), false);
231  $create_simple_mark_schema_button->setCommand('addSimpleMarkSchema');
232  $this->toolbar->addButtonInstance($create_simple_mark_schema_button);
233 
234  require_once 'Services/UIComponent/Button/classes/class.ilButton.php';
235  $create_new_mark_step_button = ilButton::getInstance();
236  $create_new_mark_step_button->setCaption($this->lng->txt('tst_mark_create_new_mark_step'), false);
237  $create_new_mark_step_button->setButtonType(ilButton::BUTTON_TYPE_SUBMIT);
238  $create_new_mark_step_button->setForm('form_' . $mark_schema_table->getId());
239  $create_new_mark_step_button->setName('addMarkStep');
240  $this->toolbar->addButtonInstance($create_new_mark_step_button);
241  }
242 
243 
244  $content_parts = array($mark_schema_table->getHTML());
245 
246  if($this->objectSupportsEctsGrades() && $this->object->canShowEctsGrades())
247  {
248  if(!($ects_form instanceof ilPropertyFormGUI))
249  {
250  $ects_form = $this->getEctsForm();
251  $this->populateEctsForm($ects_form);
252  }
253  $content_parts[] = $ects_form->getHTML();
254  }
255 
256  $this->tpl->setContent(implode('<br />', $content_parts));
257  }
258 
262  protected function populateEctsForm(ilPropertyFormGUI $form)
263  {
264  $data = array();
265 
266  $data['ectcs_status'] = $this->object->getECTSOutput();
267  $data['use_ects_fx'] = preg_match('/\d+/', $this->object->getECTSFX());
268  $data['ects_fx_threshold'] = $this->object->getECTSFX();
269 
270  $ects_grades = $this->object->getECTSGrades();
271  for($i = ord('a'); $i <= ord('e'); $i++)
272  {
273  $mark = chr($i);
274  $data['ects_grade_' . $mark] = $ects_grades[chr($i - 32)];
275  }
276 
277  $form->setValuesByArray($data);
278  }
279 
283  protected function getEctsForm()
284  {
285  require_once 'Services/Form/classes/class.ilPropertyFormGUI.php';
286 
287  $disabled = !$this->object->canEditEctsGrades();
288 
289  $form = new ilPropertyFormGUI();
290  $form->setFormAction($this->ctrl->getFormAction($this, 'saveEctsForm'));
291  $form->setTitle($this->lng->txt('ects_output_of_ects_grades'));
292 
293  $allow_ects_marks = new ilCheckboxInputGUI($this->lng->txt('ects_allow_ects_grades'), 'ectcs_status');
294  $allow_ects_marks->setDisabled($disabled);
295  for($i = ord('a'); $i <= ord('e'); $i++)
296  {
297  $mark = chr($i);
298 
299  $mark_step = new ilNumberInputGUI(chr($i - 32), 'ects_grade_' . $mark);
300  $mark_step->setInfo(
301  $this->lng->txt('ects_grade_desc_prefix') . ' ' . $this->lng->txt('ects_grade_' . $mark . '_desc')
302  );
303  $mark_step->setSize(5);
304  $mark_step->allowDecimals(true);
305  $mark_step->setMinValue(0, true);
306  $mark_step->setMaxValue(100, true);
307  $mark_step->setSuffix($this->lng->txt('percentile'));
308  $mark_step->setRequired(true);
309  $mark_step->setDisabled($disabled);
310  $allow_ects_marks->addSubItem($mark_step);
311  }
312 
313  $mark_step = new ilNonEditableValueGUI('F', 'ects_grade_f');
314  $mark_step->setInfo(
315  $this->lng->txt('ects_grade_desc_prefix') . ' ' . $this->lng->txt('ects_grade_f_desc')
316  );
317  $allow_ects_marks->addSubItem($mark_step);
318 
319  $use_ects_fx = new ilCheckboxInputGUI($this->lng->txt('use_ects_fx'), 'use_ects_fx');
320  $use_ects_fx->setDisabled($disabled);
321  $allow_ects_marks->addSubItem($use_ects_fx);
322 
323  $mark_step = new ilNonEditableValueGUI('FX', 'ects_grade_fx');
324  $mark_step->setInfo(
325  $this->lng->txt('ects_grade_desc_prefix') . ' ' . $this->lng->txt('ects_grade_fx_desc')
326  );
327  $use_ects_fx->addSubItem($mark_step);
328 
329  $threshold = new ilNumberInputGUI($this->lng->txt('ects_fx_threshold'), 'ects_fx_threshold');
330  $threshold->setInfo($this->lng->txt('ects_fx_threshold_info'));
331  $threshold->setSuffix($this->lng->txt('percentile'));
332  $threshold->allowDecimals(true);
333  $threshold->setSize(5);
334  $threshold->setRequired(true);
335  $threshold->setDisabled($disabled);
336  $use_ects_fx->addSubItem($threshold);
337 
338 
339  $form->addItem($allow_ects_marks);
340 
341  if(!$disabled)
342  {
343  $form->addCommandButton('saveEctsForm', $this->lng->txt('save'));
344  }
345 
346  return $form;
347  }
348 
352  protected function saveEctsForm()
353  {
355 
356  $ects_form = $this->getEctsForm();
357  if(!$ects_form->checkInput())
358  {
359  $ects_form->setValuesByPost();
360  $this->showMarkSchema($ects_form);
361  return;
362  }
363 
364  $grades = array();
365  for($i = ord('a'); $i <= ord('e'); $i++)
366  {
367  $mark = chr($i);
368  $grades[chr($i - 32)] = $ects_form->getInput('ects_grade_' . $mark);
369  }
370 
371  $this->object->setECTSGrades($grades);
372  $this->object->setECTSOutput((int)$ects_form->getInput('ectcs_status'));
373  $this->object->setECTSFX(
374  $ects_form->getInput('use_ects_fx') && preg_match('/\d+/', $ects_form->getInput('ects_fx_threshold')) ?
375  $ects_form->getInput('ects_fx_threshold'):
376  NULL
377  );
378 
379  $this->object->saveECTSStatus();
380 
381  ilUtil::sendSuccess($this->lng->txt('saved_successfully'));
382  $ects_form->setValuesByPost();
383  $this->showMarkSchema($ects_form);
384  }
385 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
$result
executeCommand()
Controller method.
This class represents a property form user interface.
deleteMarkSteps()
Delete selected mark steps.
static getInstance()
$cmd
Definition: sahs_server.php:35
saveMarkSchemaFormData()
Save the mark schema POST data when the form was submitted.
This class represents a checkbox property in a property form.
addMarkStep()
Add a new mark step to the tests marks.
global $ilCtrl
Definition: ilias.php:18
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.
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.
Create styles array
The data for the language used.
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.
Create new PHPExcel object
obj_idprivate
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.