1<?php 2/* 3 +-----------------------------------------------------------------------------+ 4 | ILIAS open source | 5 +-----------------------------------------------------------------------------+ 6 | Copyright (c) 1998-2006 ILIAS open source, University of Cologne | 7 | | 8 | This program is free software; you can redistribute it and/or | 9 | modify it under the terms of the GNU General Public License | 10 | as published by the Free Software Foundation; either version 2 | 11 | of the License, or (at your option) any later version. | 12 | | 13 | This program is distributed in the hope that it will be useful, | 14 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 15 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 16 | GNU General Public License for more details. | 17 | | 18 | You should have received a copy of the GNU General Public License | 19 | along with this program; if not, write to the Free Software | 20 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | 21 +-----------------------------------------------------------------------------+ 22*/ 23 24include_once('./Services/Table/classes/class.ilTable2GUI.php'); 25include_once './Modules/Course/classes/class.ilCourseObjective.php'; 26include_once('./Modules/Course/classes/class.ilCourseObjectiveMaterials.php'); 27include_once('./Modules/Course/classes/class.ilCourseObjectiveQuestion.php'); 28include_once './Modules/Course/classes/Objectives/class.ilLOUtils.php'; 29 30// begin-patch lok 31include_once './Modules/Course/classes/Objectives/class.ilLOSettings.php'; 32// end-patch lok 33 34/** 35* 36* @author Stefan Meyer <smeyer.ilias@gmx.de> 37* @version $Id$ 38* 39* @ingroup ModulesCourse 40*/ 41class ilCourseObjectivesTableGUI extends ilTable2GUI 42{ 43 protected $course_obj = null; 44 45 // begin-patch lok 46 protected $settings = null; 47 // end-patch lok 48 49 /** 50 * Constructor 51 * 52 * @access public 53 * @param object parent gui object 54 * @return 55 */ 56 public function __construct($a_parent_obj, $a_course_obj) 57 { 58 global $DIC; 59 60 $lng = $DIC['lng']; 61 $ilCtrl = $DIC['ilCtrl']; 62 63 $this->course_obj = $a_course_obj; 64 65 // begin-patch lok 66 $this->settings = ilLOSettings::getInstanceByObjId($this->course_obj->getId()); 67 // end-patch lok 68 69 $this->lng = $lng; 70 $this->lng->loadLanguageModule('crs'); 71 $this->ctrl = $ilCtrl; 72 73 parent::__construct($a_parent_obj, 'listObjectives'); 74 $this->setFormName('objectives'); 75 $this->addColumn('', 'f', "1px"); 76 $this->addColumn($this->lng->txt('position'), 'position', '10em'); 77 $this->addColumn($this->lng->txt('title'), 'title', '20%'); 78 $this->addColumn($this->lng->txt('crs_objective_assigned_materials'), 'materials'); 79 // begin-patch lok 80 if ($this->getSettings()->worksWithInitialTest()) { 81 $this->addColumn($this->lng->txt('crs_objective_self_assessment'), 'self'); 82 } 83 // end-patch lok 84 if ($this->getSettings()->getQualifyingTestType() == ilLOSettings::TYPE_QUALIFYING_SELECTED) { 85 $this->addColumn($this->lng->txt('crs_objective_tbl_col_final_tsts'), 'final'); 86 } else { 87 $this->addColumn($this->lng->txt('crs_objective_final_test'), 'final'); 88 } 89 $this->addColumn($this->lng->txt('actions'), '5em'); 90 91 $this->setFormAction($this->ctrl->getFormAction($a_parent_obj)); 92 $this->setRowTemplate("tpl.crs_objectives_table_row.html", "Modules/Course"); 93 $this->disable('sort'); 94 $this->enable('header'); 95 $this->disable('numinfo'); 96 $this->enable('select_all'); 97 // begin-patch lok 98 $this->setSelectAllCheckbox('objective'); 99 // end-patch lok 100 $this->setLimit(200); 101 102 // begin-patch lo 103 $this->addMultiCommand('activateObjectives', $this->lng->txt('set_online')); 104 $this->addMultiCommand('deactivateObjectives', $this->lng->txt('set_offline')); 105 $this->addMultiCommand('askDeleteObjectives', $this->lng->txt('delete')); 106 // end-patch lok 107 $this->addCommandButton('saveSorting', $this->lng->txt('sorting_save')); 108 // $this->addCommandButton('create',$this->lng->txt('crs_add_objective')); 109 } 110 111 // begin-patch lok 112 /** 113 * Get settings 114 * @return ilLOSettings 115 */ 116 public function getSettings() 117 { 118 return $this->settings; 119 } 120 // end-patch lok 121 122 123 /** 124 * fill row 125 * 126 * @access protected 127 * @param array row data 128 * @return 129 */ 130 protected function fillRow($a_set) 131 { 132 $this->tpl->setVariable('VAL_ID', $a_set['id']); 133 $this->tpl->setVariable('VAL_POSITION', $a_set['position']); 134 135 // begin-patch lok 136 if ($a_set['online']) { 137 $this->tpl->setVariable('VAL_ONOFFLINE', $this->lng->txt('online')); 138 $this->tpl->setVariable('ONOFFLINE_CLASS', 'smallgreen'); 139 } else { 140 $this->tpl->setVariable('VAL_ONOFFLINE', $this->lng->txt('offline')); 141 $this->tpl->setVariable('ONOFFLINE_CLASS', 'smallred'); 142 } 143 144 if ($a_set['passes']) { 145 $this->tpl->setVariable('PASSES_TXT', $this->lng->txt('crs_loc_passes_info')); 146 $this->tpl->setVariable('PASSES_VAL', $a_set['passes']); 147 } 148 149 150 // begin-patch lok 151 $this->ctrl->setParameterByClass('ilcourseobjectivesgui', 'objective_id', $a_set['id']); 152 $this->tpl->setVariable('VAL_TITLE_LINKED', $this->ctrl->getLinkTargetByClass('ilcourseobjectivesgui', 'edit')); 153 // end-patch lok 154 155 $this->tpl->setVariable('VAL_TITLE', $a_set['title']); 156 if (strlen($a_set['description'])) { 157 $this->tpl->setVariable('VAL_DESC', $a_set['description']); 158 } 159 160 // materials 161 foreach ($a_set['materials'] as $ref_id => $data) { 162 if ($data['items']) { 163 $this->tpl->touchBlock('ul_begin'); 164 foreach ($data['items'] as $pg_st) { 165 $this->tpl->setCurrentBlock('st_pg'); 166 $this->tpl->setVariable('MAT_IMG', ilObject::_getIcon($pg_st['obj_id'], "tiny", $pg_st['type'])); 167 $this->tpl->setVariable('MAT_ALT', $this->lng->txt('obj_' . $pg_st['type'])); 168 include_once('Modules/LearningModule/classes/class.ilLMObject.php'); 169 $title = ilLMObject::_lookupTitle($pg_st['obj_id']); 170 $this->tpl->setVariable('MAT_TITLE', $title); 171 $this->tpl->parseCurrentBlock(); 172 } 173 $this->tpl->touchBlock('ul_end'); 174 } else { 175 $this->tpl->touchBlock('new_line'); 176 } 177 $this->tpl->setCurrentBlock('mat_row'); 178 $this->tpl->setVariable('LM_IMG', ilObject::_getIcon($data['obj_id'], "tiny", $data['type'])); 179 $this->tpl->setVariable('LM_ALT', $this->lng->txt('obj_' . $data['type'])); 180 181 if ($data['type'] == 'catr' or $data['type'] == 'crsr' or $data['type'] == 'grpr') { 182 include_once './Services/ContainerReference/classes/class.ilContainerReference.php'; 183 $this->tpl->setVariable( 184 'LM_TITLE', 185 ilContainerReference::_lookupTargetTitle($data['obj_id']) 186 ); 187 } else { 188 $this->tpl->setVariable('LM_TITLE', ilObject::_lookupTitle($data['obj_id'])); 189 } 190 $this->tpl->parseCurrentBlock(); 191 } 192 193 // self assessment 194 // begin-patch lok 195 if ($this->getSettings()->worksWithInitialTest()) { 196 if ($this->getSettings()->hasSeparateInitialTests()) { 197 if ($a_set['initial']) { 198 include_once './Services/Link/classes/class.ilLink.php'; 199 $obj_id = ilObject::_lookupObjId($a_set['initial']); 200 $this->tpl->setCurrentBlock('initial_test_per_objective'); 201 $this->tpl->setVariable('IT_IMG', ilObject::_getIcon($obj_id, 'tiny')); 202 $this->tpl->setVariable('IT_ALT', $this->lng->txt('obj_tst')); 203 $this->tpl->setVariable('IT_TITLE', ilObject::_lookupTitle($obj_id)); 204 $this->tpl->setVariable('IT_TITLE_LINK', ilLink::_getLink($a_set['initial'])); 205 206 include_once './Services/Link/classes/class.ilLink.php'; 207 $this->ctrl->setParameterByClass('ilobjtestgui', 'ref_id', $a_set['initial']); 208 $this->ctrl->setParameterByClass('ilobjtestgui', 'cmd', 'questionsTabGateway'); 209 $this->tpl->setVariable( 210 'IT_TITLE_LINK', 211 $this->ctrl->getLinkTargetByClass('ilobjtestgui') 212 ); 213 214 $this->tpl->parseCurrentBlock(); 215 } else { 216 $this->tpl->touchBlock('initial_test_per_objective'); 217 } 218 } else { 219 foreach ($a_set['self'] as $test) { 220 // begin-patch lok 221 foreach ((array) $test['questions'] as $question) { 222 $this->tpl->setCurrentBlock('self_qst_row'); 223 $this->tpl->setVariable('SELF_QST_TITLE', $question['title']); 224 $this->tpl->parseCurrentBlock(); 225 } 226 // end-patch lok 227 } 228 // begin-patch lok 229 if (!count($a_set['self'])) { 230 $this->tpl->touchBlock('self_qst_row'); 231 } 232 } 233 234 // end-patch lok 235 } 236 // end-patch lok 237 238 // final test questions 239 if ($this->getSettings()->getQualifyingTestType() == ilLOSettings::TYPE_QUALIFYING_SELECTED) { 240 if ($a_set['final']) { 241 $obj_id = ilObject::_lookupObjId($a_set['final']); 242 $this->tpl->setCurrentBlock('final_test_per_objective'); 243 $this->tpl->setVariable('FT_IMG', ilObject::_getIcon($obj_id, 'tiny')); 244 $this->tpl->setVariable('FT_ALT', $this->lng->txt('obj_tst')); 245 $this->tpl->setVariable('FT_TITLE', ilObject::_lookupTitle($obj_id)); 246 247 include_once './Services/Link/classes/class.ilLink.php'; 248 $this->ctrl->setParameterByClass('ilobjtestgui', 'ref_id', $a_set['final']); 249 $this->ctrl->setParameterByClass('ilobjtestgui', 'cmd', 'questionsTabGateway'); 250 $this->tpl->setVariable( 251 'FT_TITLE_LINK', 252 $this->ctrl->getLinkTargetByClass('ilobjtestgui') 253 ); 254 255 256 $this->tpl->parseCurrentBlock(); 257 } else { 258 $this->tpl->touchBlock('final_test_per_objective'); 259 } 260 } else { 261 foreach ((array) $a_set['final'] as $test) { 262 foreach ((array) $test['questions'] as $question) { 263 $this->tpl->setCurrentBlock('final_qst_row'); 264 $this->tpl->setVariable('FINAL_QST_TITLE', $question['title']); 265 $this->tpl->parseCurrentBlock(); 266 } 267 // begin-patch lok 268 #$this->tpl->setCurrentBlock('final_test_row'); 269 #$this->tpl->setVariable('FINAL_TST_IMG',ilUtil::getImagePath('icon_tst_s.png')); 270 #$this->tpl->setVariable('FINAL_TST_ALT',$this->lng->txt('obj_tst')); 271 #$this->tpl->setVariable('FINAL_TST_TITLE',ilObject::_lookupTitle($test['obj_id'])); 272 #$this->tpl->parseCurrentBlock(); 273 // end-patch lok 274 } 275 } 276 277 // begin-patch lok 278 // Edit Link 279 #$this->ctrl->setParameterByClass(get_class($this->getParentObject()),'objective_id',$a_set['id']); 280 $this->ctrl->setParameterByClass('ilcourseobjectivesgui', 'objective_id', $a_set['id']); 281 #$this->tpl->setVariable('EDIT_LINK',$this->ctrl->getLinkTargetByClass(get_class($this->getParentObject()),'edit')); 282 $this->tpl->setVariable('EDIT_LINK', $this->ctrl->getLinkTargetByClass('ilcourseobjectivesgui', 'edit')); 283 // end-patch lok 284 $this->tpl->setVariable('TXT_EDIT', $this->lng->txt('edit')); 285 286 include_once("./Services/UIComponent/AdvancedSelectionList/classes/class.ilAdvancedSelectionListGUI.php"); 287 $alist = new ilAdvancedSelectionListGUI(); 288 $alist->setId($a_set['id']); 289 //$alist->setListTitle($this->lng->txt("actions")); 290 291 $alist->addItem( 292 $this->lng->txt('edit'), 293 '', 294 $this->ctrl->getLinkTargetByClass('ilcourseobjectivesgui', 'edit') 295 ); 296 // materials 297 $alist->addItem( 298 $this->lng->txt('crs_objective_action_materials'), 299 '', 300 $this->ctrl->getLinkTargetByClass('ilcourseobjectivesgui', 'materialAssignment') 301 ); 302 // itest 303 if ($this->getSettings()->worksWithInitialTest() && !$this->getSettings()->hasSeparateInitialTests()) { 304 $alist->addItem( 305 $this->lng->txt('crs_objective_action_itest'), 306 '', 307 $this->ctrl->getLinkTargetByClass('ilcourseobjectivesgui', 'selfAssessmentAssignment') 308 ); 309 } 310 // qtest 311 if ($this->getSettings()->hasSeparateQualifiedTests()) { 312 #$alist->addItem( 313 # $this->lng->txt('crs_objective_action_qtest_sep'), 314 # '', 315 # $this->ctrl->getLinkTargetByClass('ilcourseobjectivesgui', 'finalSeparatedTestAssignment') 316 #); 317 } else { 318 $alist->addItem( 319 $this->lng->txt('crs_objective_action_qtest'), 320 '', 321 $this->ctrl->getLinkTargetByClass('ilcourseobjectivesgui', 'finalTestAssignment') 322 ); 323 } 324 325 $this->ctrl->setParameterByClass('illopagegui', 'objective_id', $a_set['id']); 326 $alist->addItem( 327 $this->lng->txt('crs_edit_lo_introduction'), 328 '', 329 $this->ctrl->getLinkTargetByClass('illopagegui', 'edit') 330 ); 331 332 333 $this->tpl->setVariable('VAL_ACTIONS', $alist->getHTML()); 334 335 // end-patch lok 336 } 337 338 339 /** 340 * parse 341 * 342 * @access public 343 * @param array array of objective id's 344 */ 345 public function parse($a_objective_ids) 346 { 347 $position = 1; 348 foreach ($a_objective_ids as $objective_id) { 349 $objective = new ilCourseObjective($this->course_obj, $objective_id); 350 351 $objective_data = []; 352 $objective_data['id'] = $objective_id; 353 $objective_data['position'] = sprintf("%.1f", $position++) * 10; 354 $objective_data['title'] = $objective->getTitle(); 355 $objective_data['description'] = $objective->getDescription(); 356 357 // begin-patch lok 358 $objective_data['online'] = $objective->isActive(); 359 $objective_data['passes'] = $objective->getPasses(); 360 // end-patch lok 361 362 // assigned materials 363 $materials = array(); 364 $ass_materials = new ilCourseObjectiveMaterials($objective_id); 365 foreach ($ass_materials->getMaterials() as $material) { 366 $materials[$material['ref_id']]['obj_id'] = $obj_id = ilObject::_lookupObjId($material['ref_id']); 367 $materials[$material['ref_id']]['type'] = ilObject::_lookupType($obj_id); 368 369 switch ($material['type']) { 370 case 'pg': 371 case 'st': 372 $materials[$material['ref_id']]['items'][] = $material; 373 break; 374 default: 375 376 } 377 } 378 $objective_data['materials'] = $materials; 379 $question_obj = new ilCourseObjectiveQuestion($objective_id); 380 381 // self assessment questions 382 // begin-patch lok 383 if ($this->getSettings()->worksWithInitialTest()) { 384 if ($this->getSettings()->hasSeparateInitialTests()) { 385 include_once './Modules/Course/classes/Objectives/class.ilLOTestAssignments.php'; 386 $assignments = ilLOTestAssignments::getInstance($this->course_obj->getId()); 387 $assignment = $assignments->getAssignmentByObjective($objective_id, ilLOSettings::TYPE_TEST_INITIAL); 388 389 $objective_data['initial'] = 0; 390 if ($assignment instanceof ilLOTestAssignment) { 391 $test_id = $assignment->getTestRefId(); 392 393 include_once './Services/Object/classes/class.ilObjectFactory.php'; 394 $factory = new ilObjectFactory(); 395 $test_candidate = $factory->getInstanceByRefId($test_id, false); 396 if ($test_candidate instanceof ilObjTest) { 397 $objective_data['initial'] = $test_id; 398 } 399 } 400 } elseif (ilLOUtils::lookupRandomTest(ilObject::_lookupObjId($this->getSettings()->getInitialTest()))) { 401 $test = array(); 402 $objective_data['self'] = []; 403 foreach (ilLORandomTestQuestionPools::lookupSequencesByType( 404 $this->course_obj->getId(), 405 $objective_id, 406 ilObject::_lookupObjId($this->getSettings()->getInitialTest()), 407 ilLOSettings::TYPE_TEST_INITIAL 408 ) as $sequence_id 409 ) { 410 $test['obj_id'] = ilObject::_lookupObjId($this->getSettings()->getInitialTest()); 411 $qst = ilLOUtils::lookupQplBySequence($this->getSettings()->getInitialTest(), $sequence_id); 412 if ($qst) { 413 $test['questions'][] = array('title' => $qst); 414 } 415 $objective_data['self'] = array($test); 416 } 417 } else { 418 $tests = array(); 419 foreach ($question_obj->getSelfAssessmentTests() as $test) { 420 $questions = array(); 421 foreach ($question_obj->getQuestionsOfTest($test['obj_id']) as $qst) { 422 $questions[] = $qst; 423 } 424 $tmp_test = $test; 425 $tmp_test['questions'] = $questions; 426 427 $tests[] = $tmp_test; 428 } 429 $objective_data['self'] = $tests; 430 } 431 } 432 // end-patch lok 433 434 // final test questions 435 // begin-patch lok 436 // single test assignments 437 if ($this->getSettings()->getQualifyingTestType() == ilLOSettings::TYPE_QUALIFYING_SELECTED) { 438 include_once './Modules/Course/classes/Objectives/class.ilLOTestAssignments.php'; 439 $assignments = ilLOTestAssignments::getInstance($this->course_obj->getId()); 440 $assignment = $assignments->getAssignmentByObjective($objective_id, ilLOSettings::TYPE_TEST_QUALIFIED); 441 442 $objective_data['final'] = 0; 443 if ($assignment instanceof ilLOTestAssignment) { 444 $test_id = $assignment->getTestRefId(); 445 446 include_once './Services/Object/classes/class.ilObjectFactory.php'; 447 $factory = new ilObjectFactory(); 448 $test_candidate = $factory->getInstanceByRefId($test_id, false); 449 if ($test_candidate instanceof ilObjTest) { 450 $objective_data['final'] = $test_id; 451 } 452 } 453 } elseif ($this->getSettings()->getQualifiedTest()) { 454 if (ilLOUtils::lookupRandomTest(ilObject::_lookupObjId($this->getSettings()->getQualifiedTest()))) { 455 $test = array(); 456 foreach (ilLORandomTestQuestionPools::lookupSequencesByType( 457 $this->course_obj->getId(), 458 $objective_id, 459 ilObject::_lookupObjId($this->getSettings()->getQualifiedTest()), 460 ilLOSettings::TYPE_TEST_QUALIFIED 461 ) as $sequence_id 462 ) { 463 $test['obj_id'] = ilObject::_lookupObjId($this->getSettings()->getQualifiedTest()); 464 $qst = ilLOUtils::lookupQplBySequence($this->getSettings()->getQualifiedTest(), $sequence_id); 465 if ($qst) { 466 $test['questions'][] = array('title' => $qst); 467 } 468 $objective_data['final'] = array($test); 469 } 470 } else { 471 $tests = array(); 472 foreach ($question_obj->getFinalTests() as $test) { 473 $questions = array(); 474 foreach ($question_obj->getQuestionsOfTest($test['obj_id']) as $qst) { 475 $questions[] = $qst; 476 } 477 $tmp_test = $test; 478 $tmp_test['questions'] = $questions; 479 480 $tests[] = $tmp_test; 481 } 482 $objective_data['final'] = $tests; 483 } 484 } 485 // end-patch lok 486 $objectives[] = (array) $objective_data; 487 } 488 $this->setData($objectives ? $objectives : array()); 489 } 490} 491