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('./Modules/Course/classes/class.ilCourseObjectiveQuestion.php'); 25include_once('./Services/Table/classes/class.ilTable2GUI.php'); 26// begin-patch lok 27include_once './Modules/Course/classes/Objectives/class.ilLOSettings.php'; 28// end-patch lok 29 30/** 31* TableGUI for question assignments of course objectives 32* 33* @author Stefan Meyer <smeyer.ilias@gmx.de> 34* @version $Id$ 35* 36* @ingroup ModulesCourse 37*/ 38class ilCourseObjectiveQuestionAssignmentTableGUI extends ilTable2GUI 39{ 40 // begin-patch lok 41 private $settings = null; 42 // end-patch lok 43 44 private $mode = 0; 45 private $objective = null; 46 private $objective_lm = null; 47 48 private $objective_id = 0; 49 private $course_obj; 50 51 /** 52 * Constructor 53 * 54 * @access public 55 * @param 56 * @return 57 */ 58 public function __construct($a_parent_obj, $a_course_obj, $a_objective_id, $a_mode) 59 { 60 global $DIC; 61 62 $lng = $DIC['lng']; 63 $ilCtrl = $DIC['ilCtrl']; 64 65 $this->objective_id = $a_objective_id; 66 $this->course_obj = $a_course_obj; 67 68 // begin-patch lok 69 $this->settings = ilLOSettings::getInstanceByObjId($this->course_obj->getId()); 70 // end-patch lok 71 72 $this->lng = $lng; 73 $this->lng->loadLanguageModule('crs'); 74 $this->ctrl = $ilCtrl; 75 76 parent::__construct($a_parent_obj, 'materialAssignment'); 77 $this->setFormName('assignments'); 78 $this->addColumn($this->lng->txt('type'), 'type', "20px"); 79 $this->addColumn($this->lng->txt('title'), 'title', ''); 80 81 $this->setFormAction($this->ctrl->getFormAction($a_parent_obj)); 82 $this->setRowTemplate("tpl.crs_objective_list_questions_row.html", "Modules/Course"); 83 $this->disable('sort'); 84 $this->disable('header'); 85 $this->disable('numinfo'); 86 $this->disable('select_all'); 87 88 #$this->setDefaultOrderField('title'); 89 $this->setLimit(200); 90 91 $this->mode = $a_mode; 92 switch ($a_mode) { 93 case ilCourseObjectiveQuestion::TYPE_SELF_ASSESSMENT: 94 $this->addCommandButton('updateSelfAssessmentAssignment', $this->lng->txt('crs_wiz_next')); 95 $this->addCommandButton('materialAssignment', $this->lng->txt('crs_wiz_back')); 96 break; 97 98 case ilCourseObjectiveQuestion::TYPE_FINAL_TEST: 99 $this->addCommandButton('updateFinalTestAssignment', $this->lng->txt('crs_wiz_next')); 100 $this->addCommandButton('selfAssessmentAssignment', $this->lng->txt('crs_wiz_back')); 101 break; 102 } 103 104 $this->initQuestionAssignments(); 105 } 106 107 // begin-patch lok 108 /** 109 * Get settings 110 * @return ilLOSettings 111 */ 112 public function getSettings() 113 { 114 return $this->settings; 115 } 116 // end-patch lok 117 118 /** 119 * fill row 120 * 121 * @access protected 122 * @param array row data 123 * @return 124 */ 125 protected function fillRow($a_set) 126 { 127 foreach ($a_set['sub'] as $sub_data) { 128 if ($a_set['random']) { 129 break; 130 } 131 132 133 if ($sub_data['description']) { 134 $this->tpl->setVariable('QST_DESCRIPTION', $sub_data['description']); 135 } 136 if ($sub_data['qst_txt']) { 137 $txt = $sub_data['qst_txt']; 138 if ($sub_data['qst_points']) { 139 $this->lng->loadLanguageModule('assessment'); 140 $txt .= (' (' . $sub_data['qst_points'] . ' ' . $this->lng->txt('points') . ')'); 141 } 142 143 $this->tpl->setVariable('QST_DESCRIPTION', $txt); 144 } 145 $this->tpl->setCurrentBlock('qst'); 146 $this->tpl->setVariable('QST_TITLE', $sub_data['title']); 147 $this->tpl->setVariable('QST_ID', $a_set['id'] . '_' . $sub_data['id']); 148 149 switch ($this->mode) { 150 case ilCourseObjectiveQuestion::TYPE_SELF_ASSESSMENT: 151 if ($this->objective_qst_obj->isSelfAssessmentQuestion($sub_data['id'])) { 152 $this->tpl->setVariable('QST_CHECKED', 'checked="checked"'); 153 } 154 break; 155 156 case ilCourseObjectiveQuestion::TYPE_FINAL_TEST: 157 if ($this->objective_qst_obj->isFinalTestQuestion($sub_data['id'])) { 158 $this->tpl->setVariable('QST_CHECKED', 'checked="checked"'); 159 } 160 break; 161 } 162 $this->tpl->parseCurrentBlock(); 163 } 164 if (count($a_set['sub']) and !$a_set['random']) { 165 $this->tpl->setVariable('TXT_QUESTIONS', $this->lng->txt('objs_qst')); 166 } 167 if ($a_set['random']) { 168 $this->tpl->setVariable('VAL_WARN', $this->lng->txt('crs_objective_random_warn')); 169 } 170 171 $this->tpl->setVariable('VAL_ID', $a_set['id']); 172 173 $this->tpl->setVariable('ROW_TYPE_IMG', ilObject::_getIcon($a_set['obj_id'], "tiny", $a_set['type'])); 174 $this->tpl->setVariable('ROW_TYPE_ALT', $this->lng->txt('obj_' . $a_set['type'])); 175 176 $this->tpl->setVariable('VAL_TITLE', $a_set['title']); 177 if (strlen($a_set['description'])) { 178 $this->tpl->setVariable('VAL_DESC', $a_set['description']); 179 } 180 } 181 182 /** 183 * parse 184 * 185 * @access public 186 * @param array array of assignable nodes (tree node data) 187 * @return 188 */ 189 public function parse($a_assignable) 190 { 191 global $DIC; 192 193 $objDefinition = $DIC['objDefinition']; 194 195 // begin-patch lok 196 $a_assignable = $this->getTestNode(); 197 // end-patch lok 198 $tests = array(); 199 200 foreach ($a_assignable as $node) { 201 $tmp_data = array(); 202 $subobjects = array(); 203 204 if (!$tmp_tst = ilObjectFactory::getInstanceByRefId((int) $node['ref_id'], false)) { 205 continue; 206 } 207 208 include_once './Modules/Test/classes/class.ilObjTest.php'; 209 $tmp_data['random'] = ilObjTest::_lookupRandomTest($node['obj_id']); 210 $tmp_data['random'] = false; 211 212 foreach ($qst = $this->sortQuestions($tmp_tst->getAllQuestions()) as $question_data) { 213 $tmp_question = ilObjTest::_instanciateQuestion($question_data['question_id']); 214 #$sub['qst_txt'] = $tmp_question->_getQuestionText($question_data['question_id']); 215 $sub['qst_txt'] = ''; 216 $sub['qst_points'] = assQuestion::_getMaximumPoints($question_data['question_id']); 217 218 $sub['title'] = $tmp_question->getTitle(); 219 $sub['description'] = $tmp_question->getComment(); 220 $sub['id'] = $question_data['question_id']; 221 222 $subobjects[] = $sub; 223 } 224 $tmp_data['title'] = $node['title']; 225 $tmp_data['description'] = $node['description']; 226 $tmp_data['type'] = $node['type']; 227 $tmp_data['id'] = $node['child']; 228 $tmp_data['obj_id'] = $node['obj_id']; 229 $tmp_data['sub'] = $subobjects; 230 231 $tests[] = $tmp_data; 232 } 233 234 $this->setData($tests); 235 } 236 // begin-patch lok 237 protected function getTestNode() 238 { 239 if ($this->mode == ilCourseObjectiveQuestion::TYPE_SELF_ASSESSMENT) { 240 $tst_ref_id = $this->getSettings()->getInitialTest(); 241 if ($tst_ref_id) { 242 return array($GLOBALS['DIC']['tree']->getNodeData($tst_ref_id)); 243 } 244 } 245 if ($this->mode == ilCourseObjectiveQuestion::TYPE_FINAL_TEST) { 246 $tst_ref_id = $this->getSettings()->getQualifiedTest(); 247 if ($tst_ref_id) { 248 return array($GLOBALS['DIC']['tree']->getNodeData($tst_ref_id)); 249 } 250 } 251 return array(); 252 } 253 // end-patch lok 254 255 /** 256 * init objective assignments 257 * 258 * @access protected 259 * @return 260 */ 261 protected function initQuestionAssignments() 262 { 263 include_once './Modules/Course/classes/class.ilCourseObjectiveQuestion.php'; 264 $this->objective_qst_obj = new ilCourseObjectiveQuestion($this->objective_id); 265 266 return true; 267 } 268 269 /** 270 * Sort questions 271 * 272 * @access protected 273 * @param 274 * @return 275 */ 276 protected function sortQuestions($a_qst_ids) 277 { 278 return ilUtil::sortArray($a_qst_ids, 'title', 'asc'); 279 } 280} 281