ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
class.ilScoringAdjustmentGUI.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/Glyph/classes/class.ilGlyphGUI.php';
5 
18 {
20  protected $lng;
21 
23  protected $tpl;
24 
26  protected $ctrl;
27 
29  protected $ilias;
30 
32  public $object; // Public due to law of demeter violation in ilTestQuestionsTableGUI.
33 
35  protected $tree;
36 
38  protected $ref_id;
39 
41  protected $service;
42 
48  public function __construct(ilObjTest $a_object)
49  {
50  global $lng, $tpl, $ilCtrl, $ilias, $tree;
51 
52  $this->lng = $lng;
53  $this->tpl = $tpl;
54  $this->ctrl = $ilCtrl;
55  $this->ilias = $ilias;
56  $this->object = $a_object;
57  $this->tree = $tree;
58  $this->ref_id = $a_object->ref_id;
59 
60  require_once './Modules/Test/classes/class.ilTestService.php';
61  $this->service = new ilTestService($a_object);
62  }
63 
67  public function executeCommand()
68  {
69  $setting = new ilSetting('assessment');
70  if (!(bool) $setting->get('assessment_adjustments_enabled', false)) {
71  $this->ctrl->redirectByClass('ilObjTestGUI');
72  }
73 
74  $cmd = $this->ctrl->getCmd();
75  $next_class = $this->ctrl->getNextClass($this);
76 
77  switch ($next_class) {
78  default:
79  return $this->dispatchCommand($cmd);
80  }
81  }
82 
83  protected function dispatchCommand($cmd)
84  {
85  switch (strtolower($cmd)) {
86  case 'savescoringfortest':
87  $this->saveQuestion();
88  break;
89 
90  case 'adjustscoringfortest':
91  $this->editQuestion();
92  break;
93 
94  case 'showquestionlist':
95  default:
96  $this->questionsObject();
97  }
98  }
99 
100  protected function questionsObject()
101  {
103  global $ilAccess;
104 
105  if (!$ilAccess->checkAccess("write", "", $this->ref_id)) {
106  // allow only write access
107  ilUtil::sendInfo($this->lng->txt("cannot_edit_test"), true);
108  $this->ctrl->redirect($this, "infoScreen");
109  }
110 
111  if ($_GET['browse']) {
112  exit('Browse??');
113  return $this->object->questionbrowser();
114  }
115 
116  if ($_GET["eqid"] && $_GET["eqpl"]) {
117  $this->ctrl->setParameter($this, 'q_id', $_GET["eqid"]);
118  $this->ctrl->setParameter($this, 'qpl_id', $_GET["eqpl"]);
119  $this->ctrl->redirect($this, 'adjustscoringfortest');
120  }
121 
122 
123  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_tst_questions.html", "Modules/Test");
124 
125  $this->tpl->setCurrentBlock("adm_content");
126 
127  include_once "./Modules/Test/classes/tables/class.ilTestQuestionsTableGUI.php";
128  $checked_move = is_array($_SESSION['tst_qst_move_' . $this->object->getTestId()])
129  && (count($_SESSION['tst_qst_move_' . $this->object->getTestId()]));
130 
131  $table_gui = new ilTestQuestionsTableGUI(
132  $this,
133  'showquestionlist',
134  (($ilAccess->checkAccess("write", "", $this->ref_id) ? true : false)),
135  $checked_move,
136  0
137  );
138 
139  $data = $this->object->getTestQuestions();
140  // @TODO Ask object for random test.
141  if (!$data) {
142  $this->object->getPotentialRandomTestQuestions();
143  }
144 
145  $filtered_data = array();
146  foreach ($data as $question) {
147  $question_object = assQuestion::instantiateQuestionGUI($question['question_id']);
148 
149  if ($this->supportsAdjustment($question_object) && $this->allowedInAdjustment($question_object)) {
150  $filtered_data[] = $question;
151  }
152  }
153  $table_gui->setData($filtered_data);
154 
155  $table_gui->clearActionButtons();
156  $table_gui->clearCommandButtons();
157  $table_gui->multi = array();
158  $table_gui->setRowTemplate('tpl.il_as_tst_adjust_questions_row.html', 'Modules/Test');
159  $table_gui->header_commands = array();
160  $table_gui->setSelectAllCheckbox(null);
161 
162  $this->tpl->setVariable('QUESTIONBROWSER', $table_gui->getHTML());
163  $this->tpl->setVariable("ACTION_QUESTION_FORM", $this->ctrl->getFormAction($this, 'showquestionlist'));
164  $this->tpl->parseCurrentBlock();
165  }
166 
174  protected function supportsAdjustment(\assQuestionGUI $question_object)
175  {
176  return ($question_object instanceof ilGuiQuestionScoringAdjustable
177  || $question_object instanceof ilGuiAnswerScoringAdjustable)
178  && ($question_object->object instanceof ilObjQuestionScoringAdjustable
179  || $question_object->object instanceof ilObjAnswerScoringAdjustable);
180  }
181 
188  protected function allowedInAdjustment(\assQuestionGUI $question_object)
189  {
190  $setting = new ilSetting('assessment');
191  $types = explode(',', $setting->get('assessment_scoring_adjustment'));
192  require_once './Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php';
193  $type_def = array();
194  foreach ($types as $type) {
196  }
197 
198  $type = $question_object->getQuestionType();
199  if (in_array($type, $type_def)) {
200  return true;
201  }
202  return false;
203  }
204 
205  protected function editQuestion()
206  {
207  $form = $this->buildAdjustQuestionForm((int) $_GET['q_id'], (int) $_GET['qpl_id']);
209  }
210 
214  protected function outputAdjustQuestionForm($form)
215  {
216  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_tst_questions.html", "Modules/Test");
217  $this->tpl->setCurrentBlock("adm_content");
218  $this->tpl->setVariable('QUESTIONBROWSER', $form->getHTML());
219  $this->tpl->parseCurrentBlock();
220  }
221 
228  protected function buildAdjustQuestionForm($question_id, $question_pool_id)
229  {
230  require_once './Services/Form/classes/class.ilPropertyFormGUI.php';
231  require_once './Modules/TestQuestionPool/classes/class.assQuestion.php';
232 
233  $form = new ilPropertyFormGUI();
234  $form->setFormAction($this->ctrl->getFormAction($this));
235  $form->setMultipart(false);
236  $form->setTableWidth("100%");
237  $form->setId("adjustment");
238 
240  $question = assQuestion::instantiateQuestionGUI($question_id);
241  $question->setEditContext(assQuestionGUI::EDIT_CONTEXT_ADJUSTMENT);
242  $form->setTitle($question->object->getTitle() . '<br /><small>(' . $question->outQuestionType() . ')</small>');
243 
244  $hidden_question_id = new ilHiddenInputGUI('q_id');
245  $hidden_question_id->setValue($question_id);
246  $form->addItem($hidden_question_id);
247 
248  $hidden_qpl_id = new ilHiddenInputGUI('qpl_id');
249  $hidden_qpl_id->setValue($question_pool_id);
250  $form->addItem($hidden_qpl_id);
251 
252  $this->populateScoringAdjustments($question, $form);
253 
254  $manscoring_section = new ilFormSectionHeaderGUI();
255  $manscoring_section->setTitle($this->lng->txt('manscoring'));
256  $form->addItem($manscoring_section);
257 
258  $manscoring_preservation = new ilCheckboxInputGUI($this->lng->txt('preserve_manscoring'), 'preserve_manscoring');
259  $manscoring_preservation->setChecked(true);
260  $manscoring_preservation->setInfo($this->lng->txt('preserve_manscoring_info'));
261  $form->addItem($manscoring_preservation);
262 
263  $form->addCommandButton("savescoringfortest", $this->lng->txt("save"));
264 
265  $participants = $this->object->getParticipants();
266  $active_ids = array_keys($participants);
267  $results = array();
268 
269  require_once 'Modules/Test/classes/class.ilTestPassesSelector.php';
270  $db = isset($GLOBALS['DIC']) ? $GLOBALS['DIC']['ilDB'] : $GLOBALS['ilDB'];
271  foreach ($active_ids as $active_id) {
272  $passesSelector = new ilTestPassesSelector($db, $this->object);
273  $passesSelector->setActiveId($active_id);
274  $passesSelector->loadLastFinishedPass();
275 
276  foreach ($passesSelector->getClosedPasses() as $pass) {
277  $results[] = $question->object->getSolutionValues($active_id, $pass);
278  }
279  }
280 
281  $relevant_answers = array();
282  foreach ($results as $result) {
283  foreach ($result as $answer) {
284  if ($answer['question_fi'] == $question->object->getId()) {
285  $relevant_answers[] = $answer;
286  }
287  }
288  }
289 
290  $this->tpl->addCss('Modules/Test/templates/default/ta.css');
291  $answers_view = $question->getAggregatedAnswersView($relevant_answers);
292 
293  include_once 'Services/jQuery/classes/class.iljQueryUtil.php';
295  include_once 'Services/YUI/classes/class.ilYuiUtil.php';
298  $this->tpl->addJavascript('./Services/UIComponent/Overlay/js/ilOverlay.js');
299  $this->tpl->addJavaScript("./Services/JavaScript/js/Basic.js");
300 
301  $container = new ilTemplate('tpl.il_as_tst_adjust_answer_aggregation_container.html', true, true, 'Modules/Test');
302  $container->setVariable('FORM_ELEMENT_NAME', 'aggr_usr_answ');
303  $container->setVariable('CLOSE_HTML', json_encode(ilGlyphGUI::get(ilGlyphGUI::CLOSE, $this->lng->txt('close'))));
304  $container->setVariable('TXT_SHOW_ANSWER_OVERVIEW', $this->lng->txt('show_answer_overview'));
305  $container->setVariable('TXT_CLOSE', $this->lng->txt('close'));
306  $container->setVariable('ANSWER_OVERVIEW', $answers_view);
307 
308  $custom_input = new ilCustomInputGUI('', 'aggr_usr_answ');
309  $custom_input->setHtml($container->get());
310  $form->addItem($custom_input);
311  return $form;
312  }
313 
314  protected function suppressPostParticipationFormElements(\ilPropertyFormGUI $form, $postvars_to_suppress)
315  {
316  foreach ($postvars_to_suppress as $postvar) {
318  $item = $form->getItemByPostVar($postvar);
319  $item->setDisabled(true);
320  }
321  return $form;
322  }
323 
324  protected function saveQuestion()
325  {
326  $question_id = $_POST['q_id'];
327  $question_pool_id = $_POST['qpl_id'];
328  $form = $this->buildAdjustQuestionForm($question_id, $question_pool_id);
329 
330  $form->setValuesByPost($_POST);
331 
332  if (!$form->checkInput()) {
333  ilUtil::sendFailure($this->lng->txt('adjust_question_form_error'));
334  $this->outputAdjustQuestionForm($form);
335  return;
336  }
337 
338  require_once './Modules/TestQuestionPool/classes/class.assQuestion.php';
340  $question = assQuestion::instantiateQuestionGUI($question_id);
341  $question->setEditContext(assQuestionGUI::EDIT_CONTEXT_ADJUSTMENT);
342 
343  if ($question instanceof ilGuiQuestionScoringAdjustable) {
344  $question->writeQuestionSpecificPostData($form);
345  }
346 
347  if ($question->object instanceof ilObjQuestionScoringAdjustable) {
348  $question->object->saveAdditionalQuestionDataToDb();
349  }
350 
351  if ($question instanceof ilGuiAnswerScoringAdjustable) {
352  $question->writeAnswerSpecificPostData($form);
353  }
354 
355  if ($question->object instanceof ilObjAnswerScoringAdjustable) {
356  $question->object->saveAnswerSpecificDataToDb();
357  }
358 
359  $question->object->setPoints($question->object->getMaximumPoints());
360  $question->object->saveQuestionDataToDb();
361 
362  require_once './Modules/Test/classes/class.ilTestScoring.php';
363  $scoring = new ilTestScoring($this->object);
364  $scoring->setPreserveManualScores($_POST['preserve_manscoring'] == 1 ? true : false);
365  $scoring->recalculateSolutions();
366 
367  ilUtil::sendSuccess($this->lng->txt('saved_adjustment'));
368  $this->questionsObject();
369  }
370 
375  protected function populateScoringAdjustments($question, $form)
376  {
377  $question->setAdjustmentEditContext();
378 
379  if ($question instanceof ilGuiQuestionScoringAdjustable) {
380  $question->populateQuestionSpecificFormPart($form);
381 
382  $this->suppressPostParticipationFormElements(
383  $form,
384  $question->getAfterParticipationSuppressionQuestionPostVars()
385  );
386  }
387 
388  if ($question instanceof ilGuiAnswerScoringAdjustable) {
389  $question->populateAnswerSpecificFormPart($form);
390 
391  $this->suppressPostParticipationFormElements(
392  $form,
393  $question->getAfterParticipationSuppressionAnswerPostVars()
394  );
395  }
396  }
397 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
allowedInAdjustment(\assQuestionGUI $question_object)
Returns if the question type is allowed for adjustments in the global test administration.
getItemByPostVar($a_post_var)
Get Item by POST variable.
$_SESSION["AccountId"]
$result
This class represents a property form user interface.
$type
$_GET["client_id"]
This class represents a section header in a property form.
static getQuestionTypeByTypeId($type_id)
$GLOBALS['loaded']
Global hash that tracks already loaded includes.
static get($a_glyph, $a_text="")
Get glyph html.
This class represents a checkbox property in a property form.
$container
Definition: wac.php:13
global $ilCtrl
Definition: ilias.php:18
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
setChecked($a_checked)
Set Checked.
This class represents a hidden form property in a property form.
static initOverlay(ilTemplate $a_main_tpl=null)
Init YUI Overlay module.
supportsAdjustment(\assQuestionGUI $question_object)
Returns if the given question object support scoring adjustment.
if(isset($_POST['submit'])) $form
special template class to simplify handling of ITX/PEAR
Interface ilObjAnswerScoringAdjustable.
checkInput()
Check Post Input.
redirection script todo: (a better solution should control the processing via a xml file) ...
getQuestionType()
Returns the question type string.
Basic GUI class for assessment questions.
Class ilTestScoring.
Create styles array
The data for the language used.
setValuesByPost()
Set form values from POST values.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
Service class for tests.
This class represents a custom property in a property form.
Create new PHPExcel object
obj_idprivate
Interface ilObjQuestionScoringAdjustable.
$results
Definition: svg-scanner.php:47
static initjQuery($a_tpl=null)
inits and adds the jQuery JS-File to the global or a passed template
Interface ilGuiAnswerScoringAdjustable.
__construct(ilObjTest $a_object)
Default constructor.
Class ilScoringAdjustmentGUI.
Interface ilGuiQuestionScoringAdjustable.
static initPanel($a_resize=false, ilTemplate $a_main_tpl=null)
Init yui panel.
$_POST["username"]
static instantiateQuestionGUI($a_question_id)
Creates an instance of a question gui with a given question id.