1<?php 2/* Copyright (c) 1998-2013 ILIAS open source, Extended GPL, see docs/LICENSE */ 3 4require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionAbstractPageObjectCommandForwarder.php'; 5require_once 'Modules/TestQuestionPool/classes/class.ilAssQuestionHintsGUI.php'; 6 7/** 8 * class can be used as forwarder for hint page object contexts 9 * 10 * @author Björn Heyser <bheyser@databay.de> 11 * @version $Id$ 12 * 13 * @package Modules/TestQuestionPool 14 */ 15class ilAssQuestionHintPageObjectCommandForwarder extends ilAssQuestionAbstractPageObjectCommandForwarder 16{ 17 /** 18 * presentation mode for authoring 19 */ 20 const PRESENTATION_MODE_AUTHOR = 'PRESENTATION_MODE_AUTHOR'; 21 22 /** 23 * presentation mode for authoring 24 */ 25 const PRESENTATION_MODE_PREVIEW = 'PRESENTATION_MODE_PREVIEW'; 26 27 /** 28 * presentation mode for requesting 29 */ 30 const PRESENTATION_MODE_REQUEST = 'PRESENTATION_MODE_REQUEST'; 31 32 /** 33 * currently set presentation mode 34 * 35 * @var string 36 */ 37 protected $presentationMode = null; 38 39 /** 40 * object instance of question hint 41 * 42 * @access protected 43 * @var ilAssQuestionHint 44 */ 45 protected $questionHint = null; 46 47 /** 48 * Constructor 49 * 50 * @access public 51 * @param assQuestion $questionOBJ 52 * @param ilCtrl $ctrl 53 * @param ilTabsGUI $tabs 54 * @param ilLanguage $lng 55 */ 56 public function __construct(assQuestion $questionOBJ, ilCtrl $ctrl, ilTabsGUI $tabs, ilLanguage $lng) 57 { 58 parent::__construct($questionOBJ, $ctrl, $tabs, $lng); 59 60 $this->questionHint = new ilAssQuestionHint(); 61 62 if (!isset($_GET['hint_id']) || !(int) $_GET['hint_id'] || !$this->questionHint->load((int) $_GET['hint_id'])) { 63 ilUtil::sendFailure('invalid hint id given: ' . (int) $_GET['hint_id'], true); 64 $this->ctrl->redirectByClass('ilAssQuestionHintsGUI', ilAssQuestionHintsGUI::CMD_SHOW_LIST); 65 } 66 } 67 68 /** 69 * forward method 70 * 71 * @throws ilTestQuestionPoolException 72 */ 73 public function forward() 74 { 75 switch ($this->getPresentationMode()) { 76 case self::PRESENTATION_MODE_AUTHOR: 77 78 $pageObjectGUI = $this->buildAuthorPresentationPageObjectGUI(); 79 break; 80 81 case self::PRESENTATION_MODE_PREVIEW: 82 83 $pageObjectGUI = $this->buildPreviewPresentationPageObjectGUI(); 84 break; 85 86 case self::PRESENTATION_MODE_REQUEST: 87 88 $pageObjectGUI = $this->buildRequestPresentationPageObjectGUI(); 89 break; 90 } 91 92 $this->ctrl->setParameter($pageObjectGUI, 'hint_id', $this->questionHint->getId()); 93 94 $this->ctrl->forwardCommand($pageObjectGUI); 95 } 96 97 /** 98 * forwards the command to page object gui for author presentation 99 * 100 * @access private 101 * @return page object gui object 102 */ 103 private function buildPreviewPresentationPageObjectGUI() 104 { 105 $this->tabs->setBackTarget( 106 $this->lng->txt('tst_question_hints_back_to_hint_list'), 107 $this->ctrl->getLinkTargetByClass('ilAssQuestionHintsGUI', ilAssQuestionHintsGUI::CMD_SHOW_LIST) 108 ); 109 110 $pageObjectGUI = $this->getPageObjectGUI( 111 $this->questionHint->getPageObjectType(), 112 $this->questionHint->getId() 113 ); 114 115 $pageObjectGUI->setEnabledTabs(false); 116 117 $pageObjectGUI->setPresentationTitle( 118 ilAssQuestionHint::getHintIndexLabel($this->lng, $this->questionHint->getIndex()) 119 ); 120 121 return $pageObjectGUI; 122 } 123 124 /** 125 * forwards the command to page object gui for author presentation 126 * 127 * @access private 128 * @return page object gui object 129 */ 130 private function buildRequestPresentationPageObjectGUI() 131 { 132 $this->tabs->setBackTarget( 133 $this->lng->txt('tst_question_hints_back_to_hint_list'), 134 $this->ctrl->getLinkTargetByClass('ilAssQuestionHintRequestGUI', ilAssQuestionHintRequestGUI::CMD_SHOW_LIST) 135 ); 136 137 $pageObjectGUI = $this->getPageObjectGUI( 138 $this->questionHint->getPageObjectType(), 139 $this->questionHint->getId() 140 ); 141 142 $pageObjectGUI->setEnabledTabs(false); 143 144 $pageObjectGUI->setPresentationTitle( 145 ilAssQuestionHint::getHintIndexLabel($this->lng, $this->questionHint->getIndex()) 146 ); 147 148 return $pageObjectGUI; 149 } 150 151 /** 152 * forwards the command to page object gui for author presentation 153 * 154 * @access private 155 * @return page object gui object 156 */ 157 private function buildAuthorPresentationPageObjectGUI() 158 { 159 $this->tabs->setBackTarget( 160 $this->lng->txt('tst_question_hints_back_to_hint_list'), 161 $this->ctrl->getLinkTargetByClass('ilAssQuestionHintsGUI', ilAssQuestionHintsGUI::CMD_SHOW_LIST) 162 ); 163 164 $this->ensurePageObjectExists( 165 $this->questionHint->getPageObjectType(), 166 $this->questionHint->getId() 167 ); 168 169 $pageObjectGUI = $this->getPageObjectGUI( 170 $this->questionHint->getPageObjectType(), 171 $this->questionHint->getId() 172 ); 173 174 $pageObjectGUI->setEnabledTabs(true); 175 176 return $pageObjectGUI; 177 } 178 179 /** 180 * getter for presentation mode 181 * 182 * @return string 183 */ 184 public function getPresentationMode() 185 { 186 return $this->presentationMode; 187 } 188 189 /** 190 * setter for presentation mode 191 * 192 * @param string $presentationMode 193 * @throws ilTestQuestionPoolException 194 */ 195 public function setPresentationMode($presentationMode) 196 { 197 switch ($presentationMode) { 198 case self::PRESENTATION_MODE_AUTHOR: 199 case self::PRESENTATION_MODE_PREVIEW: 200 case self::PRESENTATION_MODE_REQUEST: 201 202 $this->presentationMode = $presentationMode; 203 break; 204 205 default: throw new ilTestQuestionPoolException('invalid presentation mode given: ' . $presentationMode); 206 } 207 } 208 209 /** 210 * instantiates, initialises and returns a page object gui object 211 * 212 * @access protected 213 * @return page object gui object 214 */ 215 protected function getPageObjectGUI($pageObjectType, $pageObjectId) 216 { 217 include_once("./Modules/TestQuestionPool/classes/class.ilAssHintPageGUI.php"); 218 $pageObjectGUI = new ilAssHintPageGUI($pageObjectId); 219 $pageObjectGUI->obj->addUpdateListener( 220 $this->questionOBJ, 221 'updateTimestamp' 222 ); 223 return $pageObjectGUI; 224 } 225 226 /** 227 * ensures an existing page object with giben type/id 228 * 229 * @access protected 230 */ 231 protected function ensurePageObjectExists($pageObjectType, $pageObjectId) 232 { 233 include_once("./Modules/TestQuestionPool/classes/class.ilAssHintPage.php"); 234 if (!ilAssHintPage::_exists($pageObjectType, $pageObjectId)) { 235 $pageObject = new ilAssHintPage(); 236 $pageObject->setParentId($this->questionOBJ->getId()); 237 $pageObject->setId($pageObjectId); 238 $pageObject->createFromXML(); 239 } 240 } 241} 242