ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
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
4require_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 foreach ($active_ids as $active_id)
278 {
279 $passes[] = $this->object->_getPass($active_id);
280 foreach ($passes as $key => $pass)
281 {
282 for ($i = 0; $i <= $pass; $i++)
283 {
284 $results[] = $question->object->getSolutionValues($active_id, $i);
285 }
286 }
287 }
288
289 $relevant_answers = array();
290 foreach ($results as $result)
291 {
292 foreach ($result as $answer)
293 {
294 if( $answer['question_fi'] == $question->object->getId() )
295 {
296 $relevant_answers[] = $answer;
297 }
298 }
299 }
300
301 $answers_view = $question->getAggregatedAnswersView($relevant_answers);
302
303 include_once 'Services/jQuery/classes/class.iljQueryUtil.php';
305 include_once 'Services/YUI/classes/class.ilYuiUtil.php';
308 $this->tpl->addJavascript('./Services/UIComponent/Overlay/js/ilOverlay.js');
309 $this->tpl->addJavaScript("./Services/JavaScript/js/Basic.js");
310
311 $container = new ilTemplate('tpl.il_as_tst_adjust_answer_aggregation_container.html', true, true, 'Modules/Test');
312 $container->setVariable('FORM_ELEMENT_NAME', 'aggr_usr_answ');
313 $container->setVariable('CLOSE_HTML', json_encode(ilGlyphGUI::get(ilGlyphGUI::CLOSE, $this->lng->txt('close'))));
314 $container->setVariable('TXT_SHOW_ANSWER_OVERVIEW', $this->lng->txt('show_answer_overview'));
315 $container->setVariable('TXT_CLOSE', $this->lng->txt('close'));
316 $container->setVariable('ANSWER_OVERVIEW', $answers_view);
317
318 $custom_input = new ilCustomInputGUI('', 'aggr_usr_answ');
319 $custom_input->setHtml($container->get());
320 $form->addItem($custom_input);
321 return $form;
322 }
323
324 protected function suppressPostParticipationFormElements(\ilPropertyFormGUI $form, $postvars_to_suppress)
325 {
326 foreach ($postvars_to_suppress as $postvar)
327 {
329 $item = $form->getItemByPostVar($postvar);
330 $item->setDisabled(true);
331 }
332 return $form;
333 }
334
335 protected function saveQuestion()
336 {
337 $question_id = $_POST['q_id'];
338 $question_pool_id = $_POST['qpl_id'];
339 $form = $this->buildAdjustQuestionForm($question_id, $question_pool_id);
340
341 $form->setValuesByPost($_POST);
342
343 if (!$form->checkInput())
344 {
345 ilUtil::sendFailure($this->lng->txt('adjust_question_form_error'));
346 $this->outputAdjustQuestionForm($form);
347 return;
348 }
349
350 require_once './Modules/TestQuestionPool/classes/class.assQuestion.php';
352 $question = assQuestion::instantiateQuestionGUI( $question_id );
353
354 if ($question instanceof ilGuiQuestionScoringAdjustable)
355 {
356 $question->writeQuestionSpecificPostData($form);
357
358 }
359
360 if ($question->object instanceof ilObjQuestionScoringAdjustable)
361 {
362 $question->object->saveAdditionalQuestionDataToDb();
363 }
364
365 if ($question instanceof ilGuiAnswerScoringAdjustable)
366 {
367 $question->writeAnswerSpecificPostData($form);
368 }
369
370 if($question->object instanceof ilObjAnswerScoringAdjustable)
371 {
372 $question->object->saveAnswerSpecificDataToDb();
373 }
374
375 $question->object->setPoints($question->object->getMaximumPoints());
376 $question->object->saveQuestionDataToDb();
377
378 require_once './Modules/Test/classes/class.ilTestScoring.php';
379 $scoring = new ilTestScoring($this->object);
380 $scoring->setPreserveManualScores($_POST['preserve_manscoring'] == 1 ? true : false);
381 $scoring->recalculateSolutions();
382
383 ilUtil::sendSuccess($this->lng->txt('saved_adjustment'));
384 $this->questionsObject();
385
386 }
387
392 protected function populateScoringAdjustments( $question, $form )
393 {
394 if ( $question instanceof ilGuiQuestionScoringAdjustable )
395 {
396 $question->populateQuestionSpecificFormPart( $form );
397 $this->suppressPostParticipationFormElements( $form,
398 $question->getAfterParticipationSuppressionQuestionPostVars()
399 );
400 }
401
402 if ( $question instanceof ilGuiAnswerScoringAdjustable )
403 {
404 $question->populateAnswerSpecificFormPart( $form );
405 $this->suppressPostParticipationFormElements( $form,
406 $question->getAfterParticipationSuppressionAnswerPostVars()
407 );
408 }
409 }
410}
$result
$_GET["client_id"]
Basic GUI class for assessment questions.
getQuestionType()
Returns the question type string.
static instantiateQuestionGUI($a_question_id)
Creates an instance of a question gui with a given question id.
This class represents a checkbox property in a property form.
This class represents a custom property in a property form.
This class represents a section header in a property form.
static get($a_glyph, $a_text="")
Get glyph html.
This class represents a hidden form property in a property form.
static getQuestionTypeByTypeId($type_id)
This class represents a property form user interface.
checkInput()
Check Post Input.
setValuesByPost()
Set form values from POST values.
getItemByPostVar($a_post_var)
Get Item by POST variable.
Class ilScoringAdjustmentGUI.
__construct(ilObjTest $a_object)
Default constructor.
populateScoringAdjustments( $question, $form)
supportsAdjustment(\assQuestionGUI $question_object)
Returns if the given question object support scoring adjustment.
allowedInAdjustment(\assQuestionGUI $question_object)
Returns if the question type is allowed for adjustments in the global test administration.
ILIAS Setting Class.
special template class to simplify handling of ITX/PEAR
Class ilTestScoring.
Service class for tests.
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
static sendFailure($a_info="", $a_keep=false)
Send Failure Message to Screen.
static sendInfo($a_info="", $a_keep=false)
Send Info Message to Screen.
static initPanel($a_resize=false)
Init yui panel.
static initOverlay()
Init YUI Overlay module.
static initjQuery($a_tpl=null)
Init jQuery.
$_POST['username']
Definition: cron.php:12
< a tabindex="-1" style="border-style: none;" href="#" title="Refresh Image" onclick="document.getElementById('siimage').src = './securimage_show.php?sid=' + Math.random(); this.blur(); return false">< img src="./images/refresh.png" alt="Reload Image" height="32" width="32" onclick="this.blur()" align="bottom" border="0"/></a >< br/>< strong > Enter Code *if($_SERVER['REQUEST_METHOD']=='POST' &&@ $_POST['do']=='contact') $_SESSION['ctform']['success']
global $ilCtrl
Definition: ilias.php:18
Interface ilGuiAnswerScoringAdjustable.
Interface ilGuiQuestionScoringAdjustable.
Interface ilObjAnswerScoringAdjustable.
Interface ilObjQuestionScoringAdjustable.
exit
Definition: login.php:54
redirection script todo: (a better solution should control the processing via a xml file)
$cmd
Definition: sahs_server.php:35
$results