ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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  {
72  $this->ctrl->redirectByClass('ilObjTestGUI');
73  }
74 
75  $cmd = $this->ctrl->getCmd();
76  $next_class = $this->ctrl->getNextClass($this);
77 
78  switch($next_class)
79  {
80  default:
81  return $this->dispatchCommand($cmd);
82  }
83  }
84 
85  protected function dispatchCommand($cmd)
86  {
87  switch (strtolower($cmd))
88  {
89  case 'savescoringfortest':
90  $this->saveQuestion();
91  break;
92 
93  case 'adjustscoringfortest':
94  $this->editQuestion();
95  break;
96 
97  case 'showquestionlist':
98  default:
99  $this->questionsObject();
100  }
101  }
102 
103  protected function questionsObject()
104  {
106  global $ilAccess;
107 
108  if (!$ilAccess->checkAccess("write", "", $this->ref_id))
109  {
110  // allow only write access
111  ilUtil::sendInfo($this->lng->txt("cannot_edit_test"), true);
112  $this->ctrl->redirect($this, "infoScreen");
113  }
114 
115  if ($_GET['browse'])
116  {
117  exit('Browse??');
118  return $this->object->questionbrowser();
119  }
120 
121  if ($_GET["eqid"] && $_GET["eqpl"])
122  {
123  $this->ctrl->setParameter($this, 'q_id', $_GET["eqid"]);
124  $this->ctrl->setParameter($this, 'qpl_id', $_GET["eqpl"]);
125  $this->ctrl->redirect($this, 'adjustscoringfortest');
126  }
127 
128 
129  $this->tpl->addBlockFile("ADM_CONTENT", "adm_content", "tpl.il_as_tst_questions.html", "Modules/Test");
130 
131  $this->tpl->setCurrentBlock("adm_content");
132 
133  include_once "./Modules/Test/classes/tables/class.ilTestQuestionsTableGUI.php";
134  $checked_move = is_array($_SESSION['tst_qst_move_' . $this->object->getTestId()])
135  && (count($_SESSION['tst_qst_move_' . $this->object->getTestId()]));
136 
137  $table_gui = new ilTestQuestionsTableGUI(
138  $this,
139  'showquestionlist',
140  (($ilAccess->checkAccess("write", "", $this->ref_id) ? true : false)),
141  $checked_move, 0);
142 
143  $data = $this->object->getTestQuestions();
144  // @TODO Ask object for random test.
145  if (!$data)
146  {
147  $this->object->getPotentialRandomTestQuestions();
148  }
149 
150  $filtered_data = array();
151  foreach($data as $question)
152  {
153  $question_object = assQuestion::instantiateQuestionGUI($question['question_id']);
154 
155  if ( $this->supportsAdjustment( $question_object ) && $this->allowedInAdjustment( $question_object ) )
156  {
157  $filtered_data[] = $question;
158  }
159  }
160  $table_gui->setData($filtered_data);
161 
162  $table_gui->clearActionButtons();
163  $table_gui->clearCommandButtons();
164  $table_gui->multi = array();
165  $table_gui->setRowTemplate('tpl.il_as_tst_adjust_questions_row.html', 'Modules/Test');
166  $table_gui->header_commands = array();
167  $table_gui->setSelectAllCheckbox(null);
168 
169  $this->tpl->setVariable('QUESTIONBROWSER', $table_gui->getHTML());
170  $this->tpl->setVariable("ACTION_QUESTION_FORM", $this->ctrl->getFormAction($this, 'showquestionlist'));
171  $this->tpl->parseCurrentBlock();
172  }
173 
181  protected function supportsAdjustment(\assQuestionGUI $question_object)
182  {
183  return ($question_object instanceof ilGuiQuestionScoringAdjustable
184  || $question_object instanceof ilGuiAnswerScoringAdjustable)
185  && ($question_object->object instanceof ilObjQuestionScoringAdjustable
186  || $question_object->object instanceof ilObjAnswerScoringAdjustable);
187  }
188 
195  protected function allowedInAdjustment(\assQuestionGUI $question_object)
196  {
197  $setting = new ilSetting('assessment');
198  $types = explode(',',$setting->get('assessment_scoring_adjustment'));
199  require_once './Modules/TestQuestionPool/classes/class.ilObjQuestionPool.php';
200  $type_def = array();
201  foreach ($types as $type)
202  {
203  $type_def[$type] = ilObjQuestionPool::getQuestionTypeByTypeId($type);
204  }
205 
206  $type = $question_object->getQuestionType();
207  if (in_array($type,$type_def))
208  {
209  return true;
210  }
211  return false;
212  }
213 
214  protected function editQuestion()
215  {
216  $form = $this->buildAdjustQuestionForm( (int)$_GET['q_id'], (int)$_GET['qpl_id'] );
217  $this->outputAdjustQuestionForm( $form );
218  }
219 
223  protected function outputAdjustQuestionForm($form)
224  {
225  $this->tpl->addBlockFile( "ADM_CONTENT", "adm_content", "tpl.il_as_tst_questions.html", "Modules/Test" );
226  $this->tpl->setCurrentBlock( "adm_content" );
227  $this->tpl->setVariable( 'QUESTIONBROWSER', $form->getHTML() );
228  $this->tpl->parseCurrentBlock();
229  }
230 
237  protected function buildAdjustQuestionForm($question_id, $question_pool_id)
238  {
239  require_once './Services/Form/classes/class.ilPropertyFormGUI.php';
240  require_once './Modules/TestQuestionPool/classes/class.assQuestion.php';
241 
242  $form = new ilPropertyFormGUI();
243  $form->setFormAction( $this->ctrl->getFormAction( $this ) );
244  $form->setMultipart( FALSE );
245  $form->setTableWidth( "100%" );
246  $form->setId( "adjustment" );
247 
249  $question = assQuestion::instantiateQuestionGUI( $question_id );
250  $question->setEditContext(assQuestionGUI::EDIT_CONTEXT_ADJUSTMENT);
251  $form->setTitle( $question->object->getTitle() . '<br /><small>(' . $question->outQuestionType() . ')</small>' );
252 
253  $hidden_question_id = new ilHiddenInputGUI('q_id');
254  $hidden_question_id->setValue( $question_id );
255  $form->addItem( $hidden_question_id );
256 
257  $hidden_qpl_id = new ilHiddenInputGUI('qpl_id');
258  $hidden_qpl_id->setValue( $question_pool_id );
259  $form->addItem( $hidden_qpl_id );
260 
261  $this->populateScoringAdjustments( $question, $form );
262 
263  $manscoring_section = new ilFormSectionHeaderGUI();
264  $manscoring_section->setTitle($this->lng->txt('manscoring'));
265  $form->addItem($manscoring_section);
266 
267  $manscoring_preservation = new ilCheckboxInputGUI($this->lng->txt('preserve_manscoring'), 'preserve_manscoring');
268  $manscoring_preservation->setChecked(true);
269  $manscoring_preservation->setInfo($this->lng->txt('preserve_manscoring_info'));
270  $form->addItem($manscoring_preservation);
271 
272  $form->addCommandButton("savescoringfortest", $this->lng->txt("save"));
273 
274  $participants = $this->object->getParticipants();
275  $active_ids = array_keys($participants);
276  $results = array();
277 
278  require_once 'Modules/Test/classes/class.ilTestPassesSelector.php';
279  $db = isset($GLOBALS['DIC']) ? $GLOBALS['DIC']['ilDB'] : $GLOBALS['ilDB'];
280  foreach( $active_ids as $active_id )
281  {
282  $passesSelector = new ilTestPassesSelector($db, $this->object);
283  $passesSelector->setActiveId($active_id);
284  $passesSelector->loadLastFinishedPass();
285 
286  foreach( $passesSelector->getClosedPasses() as $pass )
287  {
288  $results[] = $question->object->getSolutionValues($active_id, $pass);
289  }
290  }
291 
292  $relevant_answers = array();
293  foreach ($results as $result)
294  {
295  foreach ($result as $answer)
296  {
297  if( $answer['question_fi'] == $question->object->getId() )
298  {
299  $relevant_answers[] = $answer;
300  }
301  }
302  }
303 
304  $this->tpl->addCss('Modules/Test/templates/default/ta.css');
305  $answers_view = $question->getAggregatedAnswersView($relevant_answers);
306 
307  include_once 'Services/jQuery/classes/class.iljQueryUtil.php';
309  include_once 'Services/YUI/classes/class.ilYuiUtil.php';
312  $this->tpl->addJavascript('./Services/UIComponent/Overlay/js/ilOverlay.js');
313  $this->tpl->addJavaScript("./Services/JavaScript/js/Basic.js");
314 
315  $container = new ilTemplate('tpl.il_as_tst_adjust_answer_aggregation_container.html', true, true, 'Modules/Test');
316  $container->setVariable('FORM_ELEMENT_NAME', 'aggr_usr_answ');
317  $container->setVariable('CLOSE_HTML', json_encode(ilGlyphGUI::get(ilGlyphGUI::CLOSE, $this->lng->txt('close'))));
318  $container->setVariable('TXT_SHOW_ANSWER_OVERVIEW', $this->lng->txt('show_answer_overview'));
319  $container->setVariable('TXT_CLOSE', $this->lng->txt('close'));
320  $container->setVariable('ANSWER_OVERVIEW', $answers_view);
321 
322  $custom_input = new ilCustomInputGUI('', 'aggr_usr_answ');
323  $custom_input->setHtml($container->get());
324  $form->addItem($custom_input);
325  return $form;
326  }
327 
328  protected function suppressPostParticipationFormElements(\ilPropertyFormGUI $form, $postvars_to_suppress)
329  {
330  foreach ($postvars_to_suppress as $postvar)
331  {
333  $item = $form->getItemByPostVar($postvar);
334  $item->setDisabled(true);
335  }
336  return $form;
337  }
338 
339  protected function saveQuestion()
340  {
341  $question_id = $_POST['q_id'];
342  $question_pool_id = $_POST['qpl_id'];
343  $form = $this->buildAdjustQuestionForm($question_id, $question_pool_id);
344 
345  $form->setValuesByPost($_POST);
346 
347  if (!$form->checkInput())
348  {
349  ilUtil::sendFailure($this->lng->txt('adjust_question_form_error'));
350  $this->outputAdjustQuestionForm($form);
351  return;
352  }
353 
354  require_once './Modules/TestQuestionPool/classes/class.assQuestion.php';
356  $question = assQuestion::instantiateQuestionGUI( $question_id );
357  $question->setEditContext(assQuestionGUI::EDIT_CONTEXT_ADJUSTMENT);
358 
359  if ($question instanceof ilGuiQuestionScoringAdjustable)
360  {
361  $question->writeQuestionSpecificPostData($form);
362 
363  }
364 
365  if ($question->object instanceof ilObjQuestionScoringAdjustable)
366  {
367  $question->object->saveAdditionalQuestionDataToDb();
368  }
369 
370  if ($question instanceof ilGuiAnswerScoringAdjustable)
371  {
372  $question->writeAnswerSpecificPostData($form);
373  }
374 
375  if($question->object instanceof ilObjAnswerScoringAdjustable)
376  {
377  $question->object->saveAnswerSpecificDataToDb();
378  }
379 
380  $question->object->setPoints($question->object->getMaximumPoints());
381  $question->object->saveQuestionDataToDb();
382 
383  require_once './Modules/Test/classes/class.ilTestScoring.php';
384  $scoring = new ilTestScoring($this->object);
385  $scoring->setPreserveManualScores($_POST['preserve_manscoring'] == 1 ? true : false);
386  $scoring->recalculateSolutions();
387 
388  ilUtil::sendSuccess($this->lng->txt('saved_adjustment'));
389  $this->questionsObject();
390 
391  }
392 
397  protected function populateScoringAdjustments( $question, $form )
398  {
399  $question->setAdjustmentEditContext();
400 
401  if ( $question instanceof ilGuiQuestionScoringAdjustable )
402  {
403  $question->populateQuestionSpecificFormPart($form);
404 
405  $this->suppressPostParticipationFormElements(
406  $form, $question->getAfterParticipationSuppressionQuestionPostVars()
407  );
408  }
409 
410  if ( $question instanceof ilGuiAnswerScoringAdjustable )
411  {
412  $question->populateAnswerSpecificFormPart($form);
413 
414  $this->suppressPostParticipationFormElements(
415  $form, $question->getAfterParticipationSuppressionAnswerPostVars()
416  );
417  }
418  }
419 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
ILIAS Setting Class.
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.
$_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.
$cmd
Definition: sahs_server.php:35
static get($a_glyph, $a_text="")
Get glyph html.
This class represents a checkbox property in a property form.
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.
supportsAdjustment(\assQuestionGUI $question_object)
Returns if the given question object support scoring adjustment.
populateScoringAdjustments( $question, $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) ...
$results
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.
static initPanel($a_resize=false)
Init yui panel.
Service class for tests.
This class represents a custom property in a property form.
Create new PHPExcel object
obj_idprivate
Interface ilObjQuestionScoringAdjustable.
static initOverlay()
Init YUI Overlay module.
static initjQuery($a_tpl=null)
Init jQuery.
Interface ilGuiAnswerScoringAdjustable.
__construct(ilObjTest $a_object)
Default constructor.
Class ilScoringAdjustmentGUI.
Interface ilGuiQuestionScoringAdjustable.
$_POST["username"]
static instantiateQuestionGUI($a_question_id)
Creates an instance of a question gui with a given question id.