ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 case 'ilassquestionhintgui':
104
105 if (!$this->isEditingEnabled()) {
106 return;
107 }
108
109 require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintGUI.php';
110 $gui = new ilAssQuestionHintGUI($this->questionGUI);
111 $ilCtrl->forwardCommand($gui);
112 break;
113
114 case 'ilasshintpagegui':
115
116 if ($this->isEditingEnabled()) {
118 } else {
120 }
121
122 require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintPageObjectCommandForwarder.php';
123 $forwarder = new ilAssQuestionHintPageObjectCommandForwarder($this->questionOBJ, $ilCtrl, $ilTabs, $lng);
124 $forwarder->setPresentationMode($presentationMode);
125 $forwarder->forward();
126 break;
127
128 default:
129
130 $cmd .= 'Cmd';
131 $this->$cmd();
132 break;
133 }
134 }
135
142 private function showListCmd()
143 {
144 global $ilCtrl, $tpl, $lng;
145
147
148 require_once 'Services/UIComponent/Toolbar/classes/class.ilToolbarGUI.php';
149 require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintsTableGUI.php';
150
151 $toolbar = new ilToolbarGUI();
152
153 $questionHintList = ilAssQuestionHintList::getListByQuestionId($this->questionOBJ->getId());
154
155 if ($this->isEditingEnabled()) {
156 if ($this->hintOrderingClipboard->hasStored()) {
157 $questionHintList = $this->getQuestionHintListWithoutHintStoredInOrderingClipboard($questionHintList);
158
159 $toolbar->addButton(
160 $lng->txt('tst_questions_hints_toolbar_cmd_reset_ordering_clipboard'),
161 $ilCtrl->getLinkTarget($this, self::CMD_RESET_ORDERING_CLIPBOARD)
162 );
163 } else {
164 $toolbar->addButton(
165 $lng->txt('tst_questions_hints_toolbar_cmd_add_hint'),
166 $ilCtrl->getLinkTargetByClass('ilAssQuestionHintGUI', ilAssQuestionHintGUI::CMD_SHOW_FORM)
167 );
168 }
169
171 } else {
173 }
174
176 $this->questionOBJ,
177 $questionHintList,
178 $this,
179 self::CMD_SHOW_LIST,
180 $tableMode,
181 $this->hintOrderingClipboard
182 );
183
184 $tpl->setContent($ilCtrl->getHtml($toolbar) . $ilCtrl->getHtml($table));
185 }
186
195 private function confirmDeleteCmd()
196 {
197 global $ilCtrl, $tpl, $lng;
198
199 $hintIds = self::fetchHintIdsParameter();
200
201 if (!count($hintIds)) {
202 ilUtil::sendFailure($lng->txt('tst_question_hints_delete_hints_missing_selection_msg'), true);
203 $ilCtrl->redirect($this);
204 }
205
206 require_once 'Services/Utilities/classes/class.ilConfirmationGUI.php';
207 $confirmation = new ilConfirmationGUI();
208
209 $confirmation->setHeaderText($lng->txt('tst_question_hints_delete_hints_confirm_header'));
210 $confirmation->setFormAction($ilCtrl->getFormAction($this));
211 $confirmation->setConfirm($lng->txt('tst_question_hints_delete_hints_confirm_cmd'), self::CMD_PERFORM_DELETE);
212 $confirmation->setCancel($lng->txt('cancel'), self::CMD_SHOW_LIST);
213
214 $questionHintList = ilAssQuestionHintList::getListByQuestionId($this->questionOBJ->getId());
215
216 foreach ($questionHintList as $questionHint) {
217 /* @var $questionHint ilAssQuestionHint */
218
219 if (in_array($questionHint->getId(), $hintIds)) {
220 $confirmation->addItem('hint_ids[]', $questionHint->getId(), sprintf(
221 $lng->txt('tst_question_hints_delete_hints_confirm_item'),
222 $questionHint->getIndex(),
223 $questionHint->getText()
224 ));
225 }
226 }
227
228 $tpl->setContent($ilCtrl->getHtml($confirmation));
229 }
230
238 private function performDeleteCmd()
239 {
240 if (!$this->isEditingEnabled()) {
241 return;
242 }
243
244 global $ilCtrl, $tpl, $lng;
245
246 $hintIds = self::fetchHintIdsParameter();
247
248 if (!count($hintIds)) {
249 ilUtil::sendFailure($lng->txt('tst_question_hints_delete_hints_missing_selection_msg'), true);
250 $ilCtrl->redirect($this);
251 }
252
253 $questionCompleteHintList = ilAssQuestionHintList::getListByQuestionId($this->questionOBJ->getId());
254
255 $questionRemainingHintList = new ilAssQuestionHintList();
256
257 foreach ($questionCompleteHintList as $listKey => $questionHint) {
258 /* @var $questionHint ilAssQuestionHint */
259
260 if (in_array($questionHint->getId(), $hintIds)) {
261 $questionHint->delete();
262 } else {
263 $questionRemainingHintList->addHint($questionHint);
264 }
265 }
266
267 $questionRemainingHintList->reIndex();
268
269 ilUtil::sendSuccess($lng->txt('tst_question_hints_delete_success_msg'), true);
270
271 $originalexists = $this->questionOBJ->_questionExistsInPool($this->questionOBJ->original_id);
272 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
273 global $ilUser;
274 if ($_GET["calling_test"] && $originalexists && assQuestion::_isWriteable($this->questionOBJ->original_id, $ilUser->getId())) {
275 $ilCtrl->redirectByClass('ilAssQuestionHintsGUI', ilAssQuestionHintsGUI::CMD_CONFIRM_SYNC);
276 }
277
278 $ilCtrl->redirect($this);
279 }
280
289 private function saveListOrderCmd()
290 {
291 if (!$this->isEditingEnabled()) {
292 return;
293 }
294
295 global $ilCtrl, $lng;
296
297 $hintIndexes = self::orderHintIndexes(
298 self::fetchHintIndexesParameter()
299 );
300
301 if (!count($hintIndexes)) {
302 ilUtil::sendFailure($lng->txt('tst_question_hints_save_order_unkown_failure_msg'), true);
303 $ilCtrl->redirect($this);
304 }
305
306 $curQuestionHintList = ilAssQuestionHintList::getListByQuestionId($this->questionOBJ->getId());
307
308 $newQuestionHintList = new ilAssQuestionHintList();
309
310 foreach ($hintIndexes as $hintId => $hintIndex) {
311 if (!$curQuestionHintList->hintExists($hintId)) {
312 ilUtil::sendFailure($lng->txt('tst_question_hints_save_order_unkown_failure_msg'), true);
313 $ilCtrl->redirect($this);
314 }
315
316 $questionHint = $curQuestionHintList->getHint($hintId);
317
318 $newQuestionHintList->addHint($questionHint);
319 }
320
321 $newQuestionHintList->reIndex();
322
323 ilUtil::sendSuccess($lng->txt('tst_question_hints_save_order_success_msg'), true);
324
325 $originalexists = $this->questionOBJ->_questionExistsInPool($this->questionOBJ->original_id);
326 include_once "./Modules/TestQuestionPool/classes/class.assQuestion.php";
327 global $ilUser;
328 if ($_GET["calling_test"] && $originalexists && assQuestion::_isWriteable($this->questionOBJ->original_id, $ilUser->getId())) {
329 $ilCtrl->redirectByClass('ilAssQuestionHintsGUI', ilAssQuestionHintsGUI::CMD_CONFIRM_SYNC);
330 }
331
332 $ilCtrl->redirect($this);
333 }
334
341 private function cutToOrderingClipboardCmd()
342 {
343 if (!$this->isEditingEnabled()) {
344 return;
345 }
346
347 global $ilCtrl;
348
349 $moveHintIds = self::fetchHintIdsParameter();
350 $this->checkForSingleHintIdAndRedirectOnFailure($moveHintIds);
351
352 $moveHintId = current($moveHintIds);
353
355
356 $this->hintOrderingClipboard->setStored($moveHintId);
357
358 $ilCtrl->redirect($this, self::CMD_SHOW_LIST);
359 }
360
369 {
370 if (!$this->isEditingEnabled()) {
371 return;
372 }
373
374 global $ilCtrl, $lng;
375
376 $targetHintIds = self::fetchHintIdsParameter();
377 $this->checkForSingleHintIdAndRedirectOnFailure($targetHintIds);
378
379 $targetHintId = current($targetHintIds);
380
382
383 $curQuestionHintList = ilAssQuestionHintList::getListByQuestionId($this->questionOBJ->getId());
384 $newQuestionHintList = new ilAssQuestionHintList($this->questionOBJ->getId());
385
386 foreach ($curQuestionHintList as $questionHint) {
387 /* @var $questionHint ilAssQuestionHint */
388
389 if ($questionHint->getId() == $this->hintOrderingClipboard->getStored()) {
390 continue;
391 }
392
393 if ($questionHint->getId() == $targetHintId) {
394 $targetQuestionHint = $questionHint;
395
396 $pasteQuestionHint = ilAssQuestionHint::getInstanceById($this->hintOrderingClipboard->getStored());
397
398 $newQuestionHintList->addHint($pasteQuestionHint);
399 }
400
401 $newQuestionHintList->addHint($questionHint);
402 }
403
404 $successMsg = sprintf(
405 $lng->txt('tst_question_hints_paste_before_success_msg'),
406 $pasteQuestionHint->getIndex(),
407 $targetQuestionHint->getIndex()
408 );
409
410 $newQuestionHintList->reIndex();
411
412 $this->hintOrderingClipboard->resetStored();
413
414 ilUtil::sendSuccess($successMsg, true);
415
416 $ilCtrl->redirect($this, self::CMD_SHOW_LIST);
417 }
418
427 {
428 if (!$this->isEditingEnabled()) {
429 return;
430 }
431
432 global $ilCtrl, $lng;
433
434 $targetHintIds = self::fetchHintIdsParameter();
435 $this->checkForSingleHintIdAndRedirectOnFailure($targetHintIds);
436
437 $targetHintId = current($targetHintIds);
438
440
441 $curQuestionHintList = ilAssQuestionHintList::getListByQuestionId($this->questionOBJ->getId());
442 $newQuestionHintList = new ilAssQuestionHintList($this->questionOBJ->getId());
443
444 foreach ($curQuestionHintList as $questionHint) {
445 /* @var $questionHint ilAssQuestionHint */
446
447 if ($questionHint->getId() == $this->hintOrderingClipboard->getStored()) {
448 continue;
449 }
450
451 $newQuestionHintList->addHint($questionHint);
452
453 if ($questionHint->getId() == $targetHintId) {
454 $targetQuestionHint = $questionHint;
455
456 $pasteQuestionHint = ilAssQuestionHint::getInstanceById($this->hintOrderingClipboard->getStored());
457
458 $newQuestionHintList->addHint($pasteQuestionHint);
459 }
460 }
461
462 $successMsg = sprintf(
463 $lng->txt('tst_question_hints_paste_after_success_msg'),
464 $pasteQuestionHint->getIndex(),
465 $targetQuestionHint->getIndex()
466 );
467
468 $newQuestionHintList->reIndex();
469
470 $this->hintOrderingClipboard->resetStored();
471
472 ilUtil::sendSuccess($successMsg, true);
473
474 $ilCtrl->redirect($this, self::CMD_SHOW_LIST);
475 }
476
484 private function resetOrderingClipboardCmd()
485 {
486 global $ilCtrl, $lng;
487
488 $this->hintOrderingClipboard->resetStored();
489
490 ilUtil::sendInfo($lng->txt('tst_question_hints_ordering_clipboard_resetted'), true);
491 $ilCtrl->redirect($this, self::CMD_SHOW_LIST);
492 }
493
502 {
503 global $lng;
504
505 if (!$this->hintOrderingClipboard->hasStored()) {
506 return;
507 }
508
509 $questionHint = ilAssQuestionHint::getInstanceById($this->hintOrderingClipboard->getStored());
510
512 $lng->txt('tst_question_hints_item_stored_in_ordering_clipboard'),
513 $questionHint->getIndex()
514 ));
515 }
516
525 {
526 $questionHintList = ilAssQuestionHintList::getListByQuestionId($this->questionOBJ->getId());
527
528 if (!$questionHintList->hintExists($hintId)) {
529 ilUtil::sendFailure($lng->txt('tst_question_hints_invalid_hint_id'), true);
530 $ilCtrl->redirect($this, self::CMD_SHOW_LIST);
531 }
532 }
533
543 {
544 $filteredQuestionHintList = new ilAssQuestionHintList();
545
546 foreach ($questionHintList as $questionHint) {
547 /* @var $questionHint ilAssQuestionHint */
548
549 if ($questionHint->getId() != $this->hintOrderingClipboard->getStored()) {
550 $filteredQuestionHintList->addHint($questionHint);
551 }
552 }
553
554 return $filteredQuestionHintList;
555 }
556
567 {
568 global $ilCtrl, $lng;
569
570 if (!count($hintIds)) {
571 ilUtil::sendFailure($lng->txt('tst_question_hints_cut_hints_missing_selection_msg'), true);
572 $ilCtrl->redirect($this, self::CMD_SHOW_LIST);
573 } elseif (count($hintIds) > 1) {
574 ilUtil::sendFailure($lng->txt('tst_question_hints_cut_hints_single_selection_msg'), true);
575 $ilCtrl->redirect($this, self::CMD_SHOW_LIST);
576 }
577 }
578
587 private static function fetchHintIdsParameter()
588 {
589 $hintIds = array();
590
591 if (isset($_POST['hint_ids']) && is_array($_POST['hint_ids'])) {
592 foreach ($_POST['hint_ids'] as $hintId) {
593 if ((int) $hintId) {
594 $hintIds[] = (int) $hintId;
595 }
596 }
597 } elseif (isset($_GET['hint_id']) && (int) $_GET['hint_id']) {
598 $hintIds[] = (int) $_GET['hint_id'];
599 }
600
601 return $hintIds;
602 }
603
611 private static function fetchHintIndexesParameter()
612 {
613 $hintIndexes = array();
614
615 if (isset($_POST['hint_indexes']) && is_array($_POST['hint_indexes'])) {
616 foreach ($_POST['hint_indexes'] as $hintId => $hintIndex) {
617 if ((int) $hintId) {
618 $hintIndexes[(int) $hintId] = $hintIndex;
619 }
620 }
621 }
622
623 return $hintIndexes;
624 }
625
634 private static function orderHintIndexes($hintIndexes)
635 {
636 asort($hintIndexes);
637
638 return $hintIndexes;
639 }
640
641 public function confirmSyncCmd()
642 {
643 $this->questionGUI->originalSyncForm('showHints');
644 }
645
653 public function getHintPresentationLinkTarget($hintId, $xmlStyle = true)
654 {
655 global $DIC;
656 $ilCtrl = $DIC['ilCtrl'];
657
658 if ($this->questionOBJ->isAdditionalContentEditingModePageObject()) {
659 $ilCtrl->setParameterByClass('ilasshintpagegui', 'hint_id', $hintId);
660 $linkTarget = $ilCtrl->getLinkTargetByClass('ilAssHintPageGUI', '', '', false, $xmlStyle);
661 } else {
662 $ilCtrl->setParameter($this, 'hintId', $hintId);
663 $linkTarget = $ilCtrl->getLinkTarget($this, self::CMD_SHOW_HINT, '', false, $xmlStyle);
664 }
665
666 return $linkTarget;
667 }
668
677 private function showHintCmd()
678 {
679 global $DIC;
680 $ilCtrl = $DIC['ilCtrl'];
681 $tpl = $DIC['tpl'];
682 $lng = $DIC['lng'];
683
684 if (!isset($_GET['hintId']) || !(int) $_GET['hintId']) {
685 throw new ilTestException('no hint id given');
686 }
687
688 $DIC->tabs()->clearTargets();
689 $DIC->tabs()->clearSubTabs();
690
691 $DIC->tabs()->setBackTarget(
692 $DIC->language()->txt('tst_question_hints_back_to_hint_list'),
693 $DIC->ctrl()->getLinkTarget($this, self::CMD_SHOW_LIST)
694 );
695
696 $questionHint = ilAssQuestionHint::getInstanceById((int) $_GET['hintId']);
697
698 // build form
699
700 $form = new ilPropertyFormGUI();
701
702 $form->setFormAction($ilCtrl->getFormAction($this));
703
704 $form->setTableWidth('100%');
705
706 $form->setTitle(sprintf(
707 $lng->txt('tst_question_hints_form_header_edit'),
708 $questionHint->getIndex(),
709 $this->questionOBJ->getTitle()
710 ));
711
712 // form input: hint text
713
714 $nonEditableHintText = new ilNonEditableValueGUI($lng->txt('tst_question_hints_form_label_hint_text'), 'hint_text', true);
715 $nonEditableHintText->setValue(ilUtil::prepareTextareaOutput($questionHint->getText(), true));
716 $form->addItem($nonEditableHintText);
717
718 // form input: hint points
719
720 $nonEditableHintPoints = new ilNonEditableValueGUI($lng->txt('tst_question_hints_form_label_hint_points'), 'hint_points');
721 $nonEditableHintPoints->setValue($questionHint->getPoints());
722 $form->addItem($nonEditableHintPoints);
723
724 $tpl->setContent($form->getHTML());
725 }
726}
sprintf('%.4f', $callTime)
$tpl
Definition: ilias.php:10
$_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, $add_random=true)
get content style path
This class represents a property form user interface.
Base Exception for all Exceptions relating to Modules/Test.
static sendSuccess($a_info="", $a_keep=false)
Send Success Message to Screen.
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 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
if(empty($password)) $table
Definition: pwgen.php:24
if(isset($_POST['submit'])) $form
global $DIC
Definition: saml.php:7
$ilUser
Definition: imgupload.php:18