ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5
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  $form->setTitle( $question->object->getTitle() . '<br /><small>(' . $question->outQuestionType() . ')</small>' );
251 
252  $hidden_question_id = new ilHiddenInputGUI('q_id');
253  $hidden_question_id->setValue( $question_id );
254  $form->addItem( $hidden_question_id );
255 
256  $hidden_qpl_id = new ilHiddenInputGUI('qpl_id');
257  $hidden_qpl_id->setValue( $question_pool_id );
258  $form->addItem( $hidden_qpl_id );
259 
260  $this->populateScoringAdjustments( $question, $form );
261 
262  $manscoring_section = new ilFormSectionHeaderGUI();
263  $manscoring_section->setTitle($this->lng->txt('manscoring'));
264  $form->addItem($manscoring_section);
265 
266  $manscoring_preservation = new ilCheckboxInputGUI($this->lng->txt('preserve_manscoring'), 'preserve_manscoring');
267  $manscoring_preservation->setChecked(true);
268  $manscoring_preservation->setInfo($this->lng->txt('preserve_manscoring_info'));
269  $form->addItem($manscoring_preservation);
270 
271  $form->addCommandButton("savescoringfortest", $this->lng->txt("save"));
272 
273  $participants = $this->object->getParticipants();
274  $active_ids = array_keys($participants);
275  $results = array();
276 
277  require_once 'Modules/Test/classes/class.ilTestPassesSelector.php';
278  $db = isset($GLOBALS['DIC']) ? $GLOBALS['DIC']['ilDB'] : $GLOBALS['ilDB'];
279  foreach( $active_ids as $active_id )
280  {
281  $passesSelector = new ilTestPassesSelector($db, $this->object);
282  $passesSelector->setActiveId($active_id);
283  $passesSelector->loadLastFinishedPass();
284 
285  foreach( $passesSelector->getClosedPasses() as $pass )
286  {
287  $results[] = $question->object->getSolutionValues($active_id, $pass);
288  }
289  }
290 
291  $relevant_answers = array();
292  foreach ($results as $result)
293  {
294  foreach ($result as $answer)
295  {
296  if( $answer['question_fi'] == $question->object->getId() )
297  {
298  $relevant_answers[] = $answer;
299  }
300  }
301  }
302 
303  $this->tpl->addCss('Modules/Test/templates/default/ta.css');
304  $answers_view = $question->getAggregatedAnswersView($relevant_answers);
305 
306  include_once 'Services/jQuery/classes/class.iljQueryUtil.php';
308  include_once 'Services/YUI/classes/class.ilYuiUtil.php';
311  $this->tpl->addJavascript('./Services/UIComponent/Overlay/js/ilOverlay.js');
312  $this->tpl->addJavaScript("./Services/JavaScript/js/Basic.js");
313 
314  $container = new ilTemplate('tpl.il_as_tst_adjust_answer_aggregation_container.html', true, true, 'Modules/Test');
315  $container->setVariable('FORM_ELEMENT_NAME', 'aggr_usr_answ');
316  $container->setVariable('CLOSE_HTML', json_encode(ilGlyphGUI::get(ilGlyphGUI::CLOSE, $this->lng->txt('close'))));
317  $container->setVariable('TXT_SHOW_ANSWER_OVERVIEW', $this->lng->txt('show_answer_overview'));
318  $container->setVariable('TXT_CLOSE', $this->lng->txt('close'));
319  $container->setVariable('ANSWER_OVERVIEW', $answers_view);
320 
321  $custom_input = new ilCustomInputGUI('', 'aggr_usr_answ');
322  $custom_input->setHtml($container->get());
323  $form->addItem($custom_input);
324  return $form;
325  }
326 
327  protected function suppressPostParticipationFormElements(\ilPropertyFormGUI $form, $postvars_to_suppress)
328  {
329  foreach ($postvars_to_suppress as $postvar)
330  {
332  $item = $form->getItemByPostVar($postvar);
333  $item->setDisabled(true);
334  }
335  return $form;
336  }
337 
338  protected function saveQuestion()
339  {
340  $question_id = $_POST['q_id'];
341  $question_pool_id = $_POST['qpl_id'];
342  $form = $this->buildAdjustQuestionForm($question_id, $question_pool_id);
343 
344  $form->setValuesByPost($_POST);
345 
346  if (!$form->checkInput())
347  {
348  ilUtil::sendFailure($this->lng->txt('adjust_question_form_error'));
349  $this->outputAdjustQuestionForm($form);
350  return;
351  }
352 
353  require_once './Modules/TestQuestionPool/classes/class.assQuestion.php';
355  $question = assQuestion::instantiateQuestionGUI( $question_id );
356 
357  if ($question instanceof ilGuiQuestionScoringAdjustable)
358  {
359  $question->writeQuestionSpecificPostData($form);
360 
361  }
362 
363  if ($question->object instanceof ilObjQuestionScoringAdjustable)
364  {
365  $question->object->saveAdditionalQuestionDataToDb();
366  }
367 
368  if ($question instanceof ilGuiAnswerScoringAdjustable)
369  {
370  $question->writeAnswerSpecificPostData($form);
371  }
372 
373  if($question->object instanceof ilObjAnswerScoringAdjustable)
374  {
375  $question->object->saveAnswerSpecificDataToDb();
376  }
377 
378  $question->object->setPoints($question->object->getMaximumPoints());
379  $question->object->saveQuestionDataToDb();
380 
381  require_once './Modules/Test/classes/class.ilTestScoring.php';
382  $scoring = new ilTestScoring($this->object);
383  $scoring->setPreserveManualScores($_POST['preserve_manscoring'] == 1 ? true : false);
384  $scoring->recalculateSolutions();
385 
386  ilUtil::sendSuccess($this->lng->txt('saved_adjustment'));
387  $this->questionsObject();
388 
389  }
390 
395  protected function populateScoringAdjustments( $question, $form )
396  {
397  if ( $question instanceof ilGuiQuestionScoringAdjustable )
398  {
399  $question->populateQuestionSpecificFormPart( $form );
400  $this->suppressPostParticipationFormElements( $form,
401  $question->getAfterParticipationSuppressionQuestionPostVars()
402  );
403  }
404 
405  if ( $question instanceof ilGuiAnswerScoringAdjustable )
406  {
407  $question->populateAnswerSpecificFormPart( $form );
408  $this->suppressPostParticipationFormElements( $form,
409  $question->getAfterParticipationSuppressionAnswerPostVars()
410  );
411  }
412  }
413 }
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
ILIAS Setting Class.
exit
Definition: login.php:54
$_POST['username']
Definition: cron.php:12
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)
$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)
$data
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.
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.
Interface ilObjQuestionScoringAdjustable.
static initOverlay()
Init YUI Overlay module.
static initjQuery($a_tpl=null)
Init jQuery.
Interface ilGuiAnswerScoringAdjustable.
__construct(ilObjTest $a_object)
Default constructor.
$GLOBALS['PHPCAS_CLIENT']
This global variable is used by the interface class phpCAS.
Definition: CAS.php:276
Class ilScoringAdjustmentGUI.
Interface ilGuiQuestionScoringAdjustable.
static instantiateQuestionGUI($a_question_id)
Creates an instance of a question gui with a given question id.