ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
class.ilAssQuestionHintsGUI.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 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintAbstractGUI.php';
5require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintGUI.php';
6require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintsOrderingClipboard.php';
7
23{
27 const CMD_SHOW_LIST = 'showList';
28 const CMD_SHOW_HINT = 'showHint';
29 const CMD_CONFIRM_DELETE = 'confirmDelete';
30 const CMD_PERFORM_DELETE = 'performDelete';
31 const CMD_SAVE_LIST_ORDER = 'saveListOrder';
32 const CMD_CUT_TO_ORDERING_CLIPBOARD = 'cutToOrderingClipboard';
33 const CMD_PASTE_FROM_ORDERING_CLIPBOARD_BEFORE = 'pasteFromOrderingClipboardBefore';
34 const CMD_PASTE_FROM_ORDERING_CLIPBOARD_AFTER = 'pasteFromOrderingClipboardAfter';
35 const CMD_RESET_ORDERING_CLIPBOARD = 'resetOrderingClipboard';
36 const CMD_CONFIRM_SYNC = 'confirmSync';
37
44 private $hintOrderingClipboard = null;
45
49 protected $editingEnabled = false;
50
58 {
59 parent::__construct($questionGUI);
60
61 $this->hintOrderingClipboard = new ilAssQuestionHintsOrderingClipboard($questionGUI->object);
62 }
63
67 public function isEditingEnabled()
68 {
70 }
71
75 public function setEditingEnabled(bool $editingEnabled)
76 {
77 $this->editingEnabled = $editingEnabled;
78 }
79
87 public function executeCommand()
88 {
89 global $ilCtrl, $ilTabs, $lng, $tpl;
90 global $DIC; /* @var \ILIAS\DI\Container $DIC */
91 $ilHelp = $DIC['ilHelp']; /* @var ilHelpGUI $ilHelp */
92 $ilHelp->setScreenIdComponent('qpl');
93
94 require_once "./Services/Style/Content/classes/class.ilObjStyleSheet.php";
95 $tpl->setCurrentBlock("ContentStyle");
96 $tpl->setVariable("LOCATION_CONTENT_STYLESHEET", ilObjStyleSheet::getContentStylePath(0));
97 $tpl->parseCurrentBlock();
98
99 $cmd = $ilCtrl->getCmd(self::CMD_SHOW_LIST);
100 $nextClass = $ilCtrl->getNextClass($this);
101
102 switch($nextClass)
103 {
104 case 'ilassquestionhintgui':
105
106 if( !$this->isEditingEnabled() )
107 {
108 return;
109 }
110
111 require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintGUI.php';
112 $gui = new ilAssQuestionHintGUI($this->questionGUI);
113 $ilCtrl->forwardCommand($gui);
114 break;
115
116 case 'ilasshintpagegui':
117
118 if( $this->isEditingEnabled() )
119 {
121 }
122 else
123 {
125 }
126
127 require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintPageObjectCommandForwarder.php';
128 $forwarder = new ilAssQuestionHintPageObjectCommandForwarder($this->questionOBJ, $ilCtrl, $ilTabs, $lng);
129 $forwarder->setPresentationMode($presentationMode);
130 $forwarder->forward();
131 break;
132
133 default:
134
135 $cmd .= 'Cmd';
136 $this->$cmd();
137 break;
138 }
139 }
140
147 private function showListCmd()
148 {
149 global $ilCtrl, $tpl, $lng;
150
152
153 require_once 'Services/UIComponent/Toolbar/classes/class.ilToolbarGUI.php';
154 require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintsTableGUI.php';
155
156 $toolbar = new ilToolbarGUI();
157
158 $questionHintList = ilAssQuestionHintList::getListByQuestionId( $this->questionOBJ->getId() );
159
160 if( $this->isEditingEnabled() )
161 {
162 if( $this->hintOrderingClipboard->hasStored() )
163 {
164 $questionHintList = $this->getQuestionHintListWithoutHintStoredInOrderingClipboard($questionHintList);
165
166 $toolbar->addButton(
167 $lng->txt('tst_questions_hints_toolbar_cmd_reset_ordering_clipboard'),
168 $ilCtrl->getLinkTarget($this, self::CMD_RESET_ORDERING_CLIPBOARD)
169 );
170 }
171 else
172 {
173 $toolbar->addButton(
174 $lng->txt('tst_questions_hints_toolbar_cmd_add_hint'),
175 $ilCtrl->getLinkTargetByClass('ilAssQuestionHintGUI', ilAssQuestionHintGUI::CMD_SHOW_FORM)
176 );
177 }
178
180 }
181 else
182 {
184 }
185
186 $table = new ilAssQuestionHintsTableGUI(
187 $this->questionOBJ, $questionHintList, $this, self::CMD_SHOW_LIST,
188 $tableMode, $this->hintOrderingClipboard
189 );
190
191 $tpl->setContent( $ilCtrl->getHtml($toolbar) . $ilCtrl->getHtml($table) );
192 }
193
202 private function confirmDeleteCmd()
203 {
204 global $ilCtrl, $tpl, $lng;
205
206 $hintIds = self::fetchHintIdsParameter();
207
208 if( !count($hintIds) )
209 {
210 ilUtil::sendFailure($lng->txt('tst_question_hints_delete_hints_missing_selection_msg'), true);
211 $ilCtrl->redirect($this);
212 }
213
214 require_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
215 $confirmation = new ilConfirmationGUI();
216
217 $confirmation->setHeaderText($lng->txt('tst_question_hints_delete_hints_confirm_header'));
218 $confirmation->setFormAction($ilCtrl->getFormAction($this));
219 $confirmation->setConfirm($lng->txt('tst_question_hints_delete_hints_confirm_cmd'), self::CMD_PERFORM_DELETE);
220 $confirmation->setCancel($lng->txt('cancel'), self::CMD_SHOW_LIST);
221
222 $questionHintList = ilAssQuestionHintList::getListByQuestionId($this->questionOBJ->getId());
223
224 foreach($questionHintList as $questionHint)
225 {
226 /* @var $questionHint ilAssQuestionHint */
227
228 if( in_array($questionHint->getId(), $hintIds) )
229 {
230 $confirmation->addItem('hint_ids[]', $questionHint->getId(), sprintf(
231 $lng->txt('tst_question_hints_delete_hints_confirm_item'), $questionHint->getIndex(), $questionHint->getText()
232 ));
233 }
234 }
235
236 $tpl->setContent( $ilCtrl->getHtml($confirmation) );
237 }
238
246 private function performDeleteCmd()
247 {
248 if( !$this->isEditingEnabled() )
249 {
250 return;
251 }
252
253 global $ilCtrl, $tpl, $lng;
254
255 $hintIds = self::fetchHintIdsParameter();
256
257 if( !count($hintIds) )
258 {
259 ilUtil::sendFailure($lng->txt('tst_question_hints_delete_hints_missing_selection_msg'), true);
260 $ilCtrl->redirect($this);
261 }
262
263 $questionCompleteHintList = ilAssQuestionHintList::getListByQuestionId($this->questionOBJ->getId());
264
265 $questionRemainingHintList = new ilAssQuestionHintList();
266
267 foreach($questionCompleteHintList as $listKey => $questionHint)
268 {
269 /* @var $questionHint ilAssQuestionHint */
270
271 if( in_array($questionHint->getId(), $hintIds) )
272 {
273 $questionHint->delete();
274 }
275 else
276 {
277 $questionRemainingHintList->addHint($questionHint);
278 }
279 }
280
281 $questionRemainingHintList->reIndex();
282
283 ilUtil::sendSuccess($lng->txt('tst_question_hints_delete_success_msg'), true);
284
285 $originalexists = $this->questionOBJ->_questionExistsInPool($this->questionOBJ->original_id);
286 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
287 global $ilUser;
288 if ($_GET["calling_test"] && $originalexists && assQuestion::_isWriteable($this->questionOBJ->original_id, $ilUser->getId()))
289 {
290 $ilCtrl->redirectByClass('ilAssQuestionHintsGUI', ilAssQuestionHintsGUI::CMD_CONFIRM_SYNC);
291 }
292
293 $ilCtrl->redirect($this);
294 }
295
304 private function saveListOrderCmd()
305 {
306 if( !$this->isEditingEnabled() )
307 {
308 return;
309 }
310
311 global $ilCtrl, $lng;
312
313 $hintIndexes = self::orderHintIndexes(
314 self::fetchHintIndexesParameter()
315 );
316
317 if( !count($hintIndexes) )
318 {
319 ilUtil::sendFailure($lng->txt('tst_question_hints_save_order_unkown_failure_msg'), true);
320 $ilCtrl->redirect($this);
321 }
322
323 $curQuestionHintList = ilAssQuestionHintList::getListByQuestionId( $this->questionOBJ->getId() );
324
325 $newQuestionHintList = new ilAssQuestionHintList();
326
327 foreach($hintIndexes as $hintId => $hintIndex)
328 {
329 if( !$curQuestionHintList->hintExists($hintId) )
330 {
331 ilUtil::sendFailure($lng->txt('tst_question_hints_save_order_unkown_failure_msg'), true);
332 $ilCtrl->redirect($this);
333 }
334
335 $questionHint = $curQuestionHintList->getHint($hintId);
336
337 $newQuestionHintList->addHint($questionHint);
338 }
339
340 $newQuestionHintList->reIndex();
341
342 ilUtil::sendSuccess($lng->txt('tst_question_hints_save_order_success_msg'), true);
343
344 $originalexists = $this->questionOBJ->_questionExistsInPool($this->questionOBJ->original_id);
345 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
346 global $ilUser;
347 if ($_GET["calling_test"] && $originalexists && assQuestion::_isWriteable($this->questionOBJ->original_id, $ilUser->getId()))
348 {
349 $ilCtrl->redirectByClass('ilAssQuestionHintsGUI', ilAssQuestionHintsGUI::CMD_CONFIRM_SYNC);
350 }
351
352 $ilCtrl->redirect($this);
353 }
354
361 private function cutToOrderingClipboardCmd()
362 {
363 if( !$this->isEditingEnabled() )
364 {
365 return;
366 }
367
368 global $ilCtrl;
369
370 $moveHintIds = self::fetchHintIdsParameter();
371 $this->checkForSingleHintIdAndRedirectOnFailure($moveHintIds);
372
373 $moveHintId = current($moveHintIds);
374
376
377 $this->hintOrderingClipboard->setStored($moveHintId);
378
379 $ilCtrl->redirect($this, self::CMD_SHOW_LIST);
380 }
381
390 {
391 if( !$this->isEditingEnabled() )
392 {
393 return;
394 }
395
396 global $ilCtrl, $lng;
397
398 $targetHintIds = self::fetchHintIdsParameter();
399 $this->checkForSingleHintIdAndRedirectOnFailure($targetHintIds);
400
401 $targetHintId = current($targetHintIds);
402
404
405 $curQuestionHintList = ilAssQuestionHintList::getListByQuestionId( $this->questionOBJ->getId() );
406 $newQuestionHintList = new ilAssQuestionHintList( $this->questionOBJ->getId() );
407
408 foreach($curQuestionHintList as $questionHint)
409 {
410 /* @var $questionHint ilAssQuestionHint */
411
412 if( $questionHint->getId() == $this->hintOrderingClipboard->getStored() )
413 {
414 continue;
415 }
416
417 if( $questionHint->getId() == $targetHintId )
418 {
419 $targetQuestionHint = $questionHint;
420
421 $pasteQuestionHint = ilAssQuestionHint::getInstanceById( $this->hintOrderingClipboard->getStored() );
422
423 $newQuestionHintList->addHint($pasteQuestionHint);
424 }
425
426 $newQuestionHintList->addHint($questionHint);
427 }
428
429 $successMsg = sprintf(
430 $lng->txt('tst_question_hints_paste_before_success_msg'),
431 $pasteQuestionHint->getIndex(), $targetQuestionHint->getIndex()
432 );
433
434 $newQuestionHintList->reIndex();
435
436 $this->hintOrderingClipboard->resetStored();
437
438 ilUtil::sendSuccess($successMsg, true);
439
440 $ilCtrl->redirect($this, self::CMD_SHOW_LIST);
441 }
442
451 {
452 if( !$this->isEditingEnabled() )
453 {
454 return;
455 }
456
457 global $ilCtrl, $lng;
458
459 $targetHintIds = self::fetchHintIdsParameter();
460 $this->checkForSingleHintIdAndRedirectOnFailure($targetHintIds);
461
462 $targetHintId = current($targetHintIds);
463
465
466 $curQuestionHintList = ilAssQuestionHintList::getListByQuestionId( $this->questionOBJ->getId() );
467 $newQuestionHintList = new ilAssQuestionHintList( $this->questionOBJ->getId() );
468
469 foreach($curQuestionHintList as $questionHint)
470 {
471 /* @var $questionHint ilAssQuestionHint */
472
473 if( $questionHint->getId() == $this->hintOrderingClipboard->getStored() )
474 {
475 continue;
476 }
477
478 $newQuestionHintList->addHint($questionHint);
479
480 if( $questionHint->getId() == $targetHintId )
481 {
482 $targetQuestionHint = $questionHint;
483
484 $pasteQuestionHint = ilAssQuestionHint::getInstanceById( $this->hintOrderingClipboard->getStored() );
485
486 $newQuestionHintList->addHint($pasteQuestionHint);
487 }
488 }
489
490 $successMsg = sprintf(
491 $lng->txt('tst_question_hints_paste_after_success_msg'),
492 $pasteQuestionHint->getIndex(), $targetQuestionHint->getIndex()
493 );
494
495 $newQuestionHintList->reIndex();
496
497 $this->hintOrderingClipboard->resetStored();
498
499 ilUtil::sendSuccess($successMsg, true);
500
501 $ilCtrl->redirect($this, self::CMD_SHOW_LIST);
502 }
503
511 private function resetOrderingClipboardCmd()
512 {
513 global $ilCtrl, $lng;
514
515 $this->hintOrderingClipboard->resetStored();
516
517 ilUtil::sendInfo($lng->txt('tst_question_hints_ordering_clipboard_resetted'), true);
518 $ilCtrl->redirect($this, self::CMD_SHOW_LIST);
519 }
520
529 {
530 global $lng;
531
532 if( !$this->hintOrderingClipboard->hasStored() )
533 {
534 return;
535 }
536
537 $questionHint = ilAssQuestionHint::getInstanceById( $this->hintOrderingClipboard->getStored() );
538
540 $lng->txt('tst_question_hints_item_stored_in_ordering_clipboard'), $questionHint->getIndex()
541 ));
542 }
543
552 {
553 $questionHintList = ilAssQuestionHintList::getListByQuestionId( $this->questionOBJ->getId() );
554
555 if( !$questionHintList->hintExists($hintId) )
556 {
557 ilUtil::sendFailure($lng->txt('tst_question_hints_invalid_hint_id'), true);
558 $ilCtrl->redirect($this, self::CMD_SHOW_LIST);
559 }
560 }
561
571 {
572 $filteredQuestionHintList = new ilAssQuestionHintList();
573
574 foreach($questionHintList as $questionHint)
575 {
576 /* @var $questionHint ilAssQuestionHint */
577
578 if( $questionHint->getId() != $this->hintOrderingClipboard->getStored() )
579 {
580 $filteredQuestionHintList->addHint($questionHint);
581 }
582 }
583
584 return $filteredQuestionHintList;
585 }
586
597 {
598 global $ilCtrl, $lng;
599
600 if( !count($hintIds) )
601 {
602 ilUtil::sendFailure($lng->txt('tst_question_hints_cut_hints_missing_selection_msg'), true);
603 $ilCtrl->redirect($this, self::CMD_SHOW_LIST);
604 }
605 elseif( count($hintIds) > 1 )
606 {
607 ilUtil::sendFailure($lng->txt('tst_question_hints_cut_hints_single_selection_msg'), true);
608 $ilCtrl->redirect($this, self::CMD_SHOW_LIST);
609 }
610 }
611
620 private static function fetchHintIdsParameter()
621 {
622 $hintIds = array();
623
624 if( isset($_POST['hint_ids']) && is_array($_POST['hint_ids']) )
625 {
626 foreach($_POST['hint_ids'] as $hintId)
627 {
628 if( (int)$hintId ) $hintIds[] = (int)$hintId;
629 }
630 }
631 elseif( isset($_GET['hint_id']) && (int)$_GET['hint_id'] )
632 {
633 $hintIds[] = (int)$_GET['hint_id'];
634 }
635
636 return $hintIds;
637 }
638
646 private static function fetchHintIndexesParameter()
647 {
648 $hintIndexes = array();
649
650 if( isset($_POST['hint_indexes']) && is_array($_POST['hint_indexes']) )
651 {
652 foreach($_POST['hint_indexes'] as $hintId => $hintIndex)
653 {
654 if( (int)$hintId ) $hintIndexes[(int)$hintId] = $hintIndex;
655 }
656 }
657
658 return $hintIndexes;
659 }
660
669 private static function orderHintIndexes($hintIndexes)
670 {
671 asort($hintIndexes);
672
673 return $hintIndexes;
674 }
675
676 public function confirmSyncCmd()
677 {
678 $this->questionGUI->originalSyncForm('showHints');
679 }
680
688 public function getHintPresentationLinkTarget($hintId, $xmlStyle = true)
689 {
690 global $DIC;
691 $ilCtrl = $DIC['ilCtrl'];
692
693 if( $this->questionOBJ->isAdditionalContentEditingModePageObject() )
694 {
695 $ilCtrl->setParameterByClass('ilasshintpagegui', 'hint_id', $hintId);
696 $linkTarget = $ilCtrl->getLinkTargetByClass('ilAssHintPageGUI', '', '', false, $xmlStyle);
697 }
698 else
699 {
700 $ilCtrl->setParameter($this, 'hintId', $hintId);
701 $linkTarget = $ilCtrl->getLinkTarget($this, self::CMD_SHOW_HINT, '', false, $xmlStyle);
702 }
703
704 return $linkTarget;
705 }
706
715 private function showHintCmd()
716 {
717 global $DIC;
718 $ilCtrl = $DIC['ilCtrl'];
719 $tpl = $DIC['tpl'];
720 $lng = $DIC['lng'];
721
722 if( !isset($_GET['hintId']) || !(int)$_GET['hintId'] )
723 {
724 throw new ilTestException('no hint id given');
725 }
726
727 $DIC->tabs()->clearTargets();
728 $DIC->tabs()->clearSubTabs();
729
730 $DIC->tabs()->setBackTarget(
731 $DIC->language()->txt('tst_question_hints_back_to_hint_list'), $DIC->ctrl()->getLinkTarget($this, self::CMD_SHOW_LIST)
732 );
733
734 $questionHint = ilAssQuestionHint::getInstanceById((int)$_GET['hintId']);
735
736 // build form
737
738 $form = new ilPropertyFormGUI();
739
740 $form->setFormAction($ilCtrl->getFormAction($this));
741
742 $form->setTableWidth('100%');
743
744 $form->setTitle(sprintf(
745 $lng->txt('tst_question_hints_form_header_edit'),
746 $questionHint->getIndex(),
747 $this->questionOBJ->getTitle()
748 ));
749
750 // form input: hint text
751
752 $nonEditableHintText = new ilNonEditableValueGUI($lng->txt('tst_question_hints_form_label_hint_text'), 'hint_text', true);
753 $nonEditableHintText->setValue( ilUtil::prepareTextareaOutput($questionHint->getText(), true) );
754 $form->addItem($nonEditableHintText);
755
756 // form input: hint points
757
758 $nonEditableHintPoints = new ilNonEditableValueGUI($lng->txt('tst_question_hints_form_label_hint_points'), 'hint_points');
759 $nonEditableHintPoints->setValue($questionHint->getPoints());
760 $form->addItem($nonEditableHintPoints);
761
762 $tpl->setContent( $form->getHTML() );
763 }
764}
sprintf('%.4f', $callTime)
global $tpl
Definition: ilias.php:8
$_GET["client_id"]
$_POST["username"]
An exception for terminatinating execution or to throw for unit testing.
Basic GUI class for assessment questions.
static _isWriteable($question_id, $user_id)
Returns true if the question is writeable by a certain user.
const CMD_SHOW_FORM
command constants
static getListByQuestionId($questionId)
instantiates a question hint list for the passed question id
static getInstanceById($hintId)
creates a hint object instance, loads the persisted hint dataset identified by passed hint id from da...
pasteFromOrderingClipboardAfterCmd()
pastes a hint from ordering clipboard after the selected one
resetOrderingClipboardCmd()
resets the ordering clipboard
getQuestionHintListWithoutHintStoredInOrderingClipboard(ilAssQuestionHintList $questionHintList)
returns a new quastion hint list that contains all question hints from the passed list except for the...
__construct(assQuestionGUI $questionGUI)
Constructor.
initHintOrderingClipboardNotification()
inits the notification telling the user, that a hint is stored to hint ordering clipboard
pasteFromOrderingClipboardBeforeCmd()
pastes a hint from ordering clipboard before the selected one
setEditingEnabled(bool $editingEnabled)
static fetchHintIdsParameter()
fetches either an array of hint ids from POST or a single hint id from GET and returns an array of (a...
cutToOrderingClipboardCmd()
cuts a hint from question hint list and stores it to ordering clipboard
static fetchHintIndexesParameter()
fetches an array of hint index values from POST
performDeleteCmd()
performs confirmed deletion for selected hints
saveListOrderCmd()
saves the order based on index values passed from table's form (the table must not be paginated,...
checkForExistingHintRelatingToCurrentQuestionAndRedirectOnFailure($hintId)
checks for an existing hint relating to current question and redirects with corresponding failure mes...
getHintPresentationLinkTarget($hintId, $xmlStyle=true)
returns the link target for hint request presentation
showHintCmd()
shows an allready requested hint
checkForSingleHintIdAndRedirectOnFailure($hintIds)
checks for a hint id in the passed array and redirects with corresponding failure message if not exac...
showListCmd()
shows a table with existing hints
static orderHintIndexes($hintIndexes)
sorts the array of indexes by index value so keys (hint ids) get into new order submitted by user
confirmDeleteCmd()
shows a confirmation screen with selected hints for deletion
const CMD_SHOW_LIST
command constants
const TBL_MODE_TESTOUTPUT
the available table modes controlling the tables behaviour
Confirmation screen class.
This class represents a non editable value in a property form.
static getContentStylePath($a_style_id)
get content style path
This class represents a property form user interface.
Base Exception for all Exceptions relating to Modules/Test.
static prepareTextareaOutput($txt_output, $prepare_for_latex_output=FALSE, $omitNl2BrWhenTextArea=false)
Prepares a string for a text area output where latex code may be in it If the text is HTML-free,...
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.
global $ilCtrl
Definition: ilias.php:18
global $lng
Definition: privfeed.php:17
$cmd
Definition: sahs_server.php:35
global $DIC
$ilUser
Definition: imgupload.php:18