[ Index ] |
|
Code source de Claroline 188 |
1 <?php // $Id: user_exercise_details.php,v 1.29.2.1 2007/03/05 10:09:16 seb Exp $ 2 /** 3 * CLAROLINE 4 * 5 * This page display global information about 6 * 7 * @version 1.8 $Revision: 1.29.2.1 $ 8 * 9 * @copyright 2001-2007 Universite catholique de Louvain (UCL) 10 * @license http://www.gnu.org/copyleft/gpl.html (GPL) GENERAL PUBLIC LICENSE 11 * @author claro team <info@claroline.net> 12 * 13 */ 14 require '../inc/claro_init_global.inc.php'; 15 16 include_once get_path('incRepositorySys') . '/lib/statsUtils.lib.inc.php'; 17 include_once get_path('incRepositorySys') . '/lib/htmlxtra.lib.php'; 18 19 $path = dirname(__FILE__); 20 include_once get_module_path('CLQWZ') . '/lib/exercise.class.php'; 21 include_once get_module_path('CLQWZ') . '/lib/question.class.php'; 22 include_once get_module_path('CLQWZ') . '/lib/answer_multiplechoice.class.php'; 23 include_once get_module_path('CLQWZ') . '/lib/answer_truefalse.class.php'; 24 include_once get_module_path('CLQWZ') . '/lib/answer_fib.class.php'; 25 include_once get_module_path('CLQWZ') . '/lib/answer_matching.class.php'; 26 27 /** 28 * extend Question class to add extract from tracking method to each answer type 29 */ 30 class TrackQuestion extends Question 31 { 32 /** 33 * Include the correct answer class and create answer 34 */ 35 function setAnswer() 36 { 37 switch($this->type) 38 { 39 case 'MCUA' : 40 $this->answer = new TrackAnswerMultipleChoice($this->id, false); 41 break; 42 case 'MCMA' : 43 $this->answer = new TrackAnswerMultipleChoice($this->id, true); 44 break; 45 case 'TF' : 46 $this->answer = new TrackAnswerTrueFalse($this->id); 47 break; 48 case 'FIB' : 49 $this->answer = new TrackAnswerFillInBlanks($this->id); 50 break; 51 case 'MATCHING' : 52 $this->answer = new TrackAnswerMatching($this->id); 53 break; 54 default : 55 $this->answer = null; 56 break; 57 } 58 59 return true; 60 } 61 } 62 63 class TrackAnswerMultipleChoice extends answerMultipleChoice 64 { 65 function extractResponseFromTracking( $attemptDetailsId ) 66 { 67 $tbl_cdb_names = claro_sql_get_course_tbl(); 68 $tblTrackAnswers = $tbl_cdb_names['track_e_exe_answers']; 69 70 // get the answers the user has gaven for this question 71 $sql = "SELECT `answer` 72 FROM `" . $tblTrackAnswers . "` 73 WHERE `details_id` = " . (int) $attemptDetailsId; 74 75 $trackedAnswers = claro_sql_query_fetch_all($sql); 76 77 $this->response = array(); 78 79 foreach( $trackedAnswers as $trackedAnswer ) 80 { 81 foreach( $this->answerList as $answer ) 82 { 83 if( $answer['answer'] == $trackedAnswer['answer'] ) 84 { 85 $this->response[$answer['id']] = true; 86 } 87 } 88 } 89 90 return true; 91 } 92 } 93 94 class TrackAnswerTrueFalse extends answerTrueFalse 95 { 96 function extractResponseFromTracking( $attemptDetailsId ) 97 { 98 $tbl_cdb_names = claro_sql_get_course_tbl(); 99 $tblTrackAnswers = $tbl_cdb_names['track_e_exe_answers']; 100 101 // get the answers the user has gaven for this question 102 $sql = "SELECT `answer` 103 FROM `" . $tblTrackAnswers . "` 104 WHERE `details_id` = " . (int) $attemptDetailsId; 105 106 $this->response = claro_sql_query_get_single_value($sql); 107 108 return true; 109 } 110 } 111 112 class TrackAnswerFillInBlanks extends answerFillInBlanks 113 { 114 function extractResponseFromTracking( $attemptDetailsId ) 115 { 116 $tbl_cdb_names = claro_sql_get_course_tbl(); 117 $tblTrackAnswers = $tbl_cdb_names['track_e_exe_answers']; 118 119 // get the answers the user has gaven for this question 120 $sql = "SELECT `answer` 121 FROM `" . $tblTrackAnswers . "` 122 WHERE `details_id` = " . (int) $attemptDetailsId; 123 124 $answers = claro_sql_query_fetch_all($sql); 125 126 foreach( $answers as $answer ) 127 { 128 $this->response[] = $answer['answer']; 129 } 130 131 return true; 132 } 133 } 134 135 class TrackAnswerMatching extends answerMatching 136 { 137 function extractResponseFromTracking( $attemptDetailsId ) 138 { 139 $tbl_cdb_names = claro_sql_get_course_tbl(); 140 $tblTrackAnswers = $tbl_cdb_names['track_e_exe_answers']; 141 142 // get the answers the user has gaven for this question 143 $sql = "SELECT `answer` 144 FROM `" . $tblTrackAnswers . "` 145 WHERE `details_id` = " . (int) $attemptDetailsId; 146 147 $trackedAnswers = claro_sql_query_fetch_all($sql); 148 149 $answerCount = count($this->leftList); 150 151 foreach( $trackedAnswers as $trackedAnswer ) 152 { 153 list($leftProposal, $rightProposal) = explode(' -> ',$trackedAnswer['answer']); 154 155 // find corresponding right code if exists 156 $rightCode = ''; 157 if( isset($rightProposal) ) 158 { 159 foreach( $this->rightList as $rightElt ) 160 { 161 if( $rightElt['answer'] == $rightProposal ) 162 { 163 $rightCode = $rightElt['code']; 164 break; 165 } 166 } 167 } 168 169 for( $i = 0; $i < $answerCount ; $i++ ) 170 { 171 if( $this->leftList[$i]['answer'] == $leftProposal ) 172 { 173 $this->leftList[$i]['response'] = $rightCode; 174 break; 175 } 176 } 177 } 178 return true; 179 } 180 } 181 182 /** 183 * DB tables definition 184 */ 185 $tbl_mdb_names = claro_sql_get_main_tbl(); 186 $tbl_rel_course_user = $tbl_mdb_names['rel_course_user' ]; 187 $tbl_user = $tbl_mdb_names['user' ]; 188 189 $tbl_cdb_names = claro_sql_get_course_tbl(); 190 $tbl_qwz_exercise = $tbl_cdb_names['qwz_exercise']; 191 192 $tbl_track_e_exercices = $tbl_cdb_names['track_e_exercices']; 193 $tbl_track_e_exe_details = $tbl_cdb_names['track_e_exe_details']; 194 $tbl_track_e_exe_answers = $tbl_cdb_names['track_e_exe_answers']; 195 196 197 198 // all I need from REQUEST is the track_id and it is required 199 if( isset($_REQUEST['trackedExId']) && is_numeric($_REQUEST['trackedExId']) ) 200 { 201 $trackedExId = (int) $_REQUEST['trackedExId']; 202 } 203 else 204 { 205 claro_redirect("../exercise/exercise.php"); 206 exit(); 207 } 208 209 210 //-- get infos 211 // get infos about the exercise 212 // get infos about the user 213 // get infos about the exercise attempt 214 $sql = "SELECT `E`.`id`, `E`.`title`, `E`.`showAnswers`, `E`.`attempts`, 215 `U`.`user_id`, `U`.`nom` as `lastname`, `U`.`prenom` as `firstname`, 216 `TE`.`exe_exo_id`, `TE`.`exe_result`, `TE`.`exe_time`, `TE`.`exe_weighting`, 217 UNIX_TIMESTAMP(`TE`.`exe_date`) AS `unix_exe_date` 218 FROM `".$tbl_qwz_exercise."` as `E`, `".$tbl_track_e_exercices."` as `TE`, `".$tbl_user."` as `U` 219 WHERE `E`.`id` = `TE`.`exe_exo_id` 220 AND `TE`.`exe_user_id` = `U`.`user_id` 221 AND `TE`.`exe_id` = ". $trackedExId; 222 223 if( ! $thisAttemptDetails = claro_sql_query_get_single_row($sql) ) 224 { 225 // sql error, let's get out of here ! 226 claro_redirect("../exercise/exercise.php"); 227 exit(); 228 } 229 230 //-- permissions 231 // if a user want to see its own results the teacher must have allowed the students 232 // to see the answers at the end of the exercise 233 $is_allowedToTrack = false; 234 235 if( claro_is_user_authenticated() ) 236 { 237 if( claro_is_course_manager() ) 238 { 239 $is_allowedToTrack = true; 240 } 241 elseif( claro_get_current_user_id() == $thisAttemptDetails['user_id'] ) 242 { 243 if( $thisAttemptDetails['showAnswers'] == 'ALWAYS' ) 244 { 245 $is_allowedToTrack = true; 246 } 247 elseif( $thisAttemptDetails['showAnswers'] == 'LASTTRY' ) 248 { 249 // we must check that user has at least "max_attempt" results 250 $sql = "SELECT COUNT(`exe_id`) 251 FROM `".$tbl_track_e_exercices."` 252 WHERE `exe_user_id` = " . (int) claro_get_current_user_id() . " 253 AND `exe_exo_id` = ".$thisAttemptDetails['exe_exo_id']; 254 $userAttempts = claro_sql_query_get_single_value($sql); 255 256 if( $userAttempts >= $thisAttemptDetails['attempts'] ) 257 { 258 $is_allowedToTrack = true; 259 } 260 else 261 { 262 $dialogBox = get_lang('You must reach the maximum number of allowed attempts to view these statistics.'); 263 } 264 265 } 266 else 267 { 268 // user cannot see its full results if show_answer == 'NEVER' 269 $dialogBox = get_lang('Display of detailled answers is not authorized.'); 270 } 271 } 272 } 273 274 275 $interbredcrump[]= array ('url'=>'../exercise/exercise.php', 'name'=> get_lang('Exercises')); 276 277 $backLink = '<p><small><a href="userLog.php?uInfo='.$thisAttemptDetails['user_id'].'&view=0100000&exoDet='.$thisAttemptDetails['id'].'"><< ' . get_lang('Back') . '</a></small></p>' . "\n\n"; 278 279 $nameTools = get_lang('Statistics of exercise attempt'); 280 281 include get_path('incRepositorySys') . '/claro_init_header.inc.php'; 282 // display title 283 $titleTab['mainTitle'] = $nameTools; 284 285 echo claro_html_tool_title($titleTab); 286 287 echo $backLink; 288 289 if( $is_allowedToTrack && get_conf('is_trackingEnabled') ) 290 { 291 // get all question that user get for this attempt 292 $sql = "SELECT TD.`id` as `trackId`, TD.`question_id`, TD.`result` 293 FROM `".$tbl_track_e_exe_details."` as TD 294 WHERE `exercise_track_id` = ". $trackedExId; 295 296 $trackedQuestionList = claro_sql_query_fetch_all($sql); 297 298 $i = 0; 299 $totalResult = 0; 300 $totalGrade = 0; 301 $questionList = array(); 302 303 // for each question the user get 304 foreach( $trackedQuestionList as $trackedQuestion ) 305 { 306 $question = new TrackQuestion(); 307 308 if( $question->load($trackedQuestion['question_id']) ) 309 { 310 // required by getGrade and getQuestionFeedbackHtml 311 $question->answer->extractResponseFromTracking($trackedQuestion['trackId']); 312 313 $questionResult[$i] = $question->answer->gradeResponse(); 314 $questionGrade[$i] = $question->getGrade(); 315 316 // sum of score 317 $totalResult += $questionResult[$i]; 318 $totalGrade += $questionGrade[$i]; 319 320 // save question object in a list to reuse it later 321 $questionList[$i] = $question; 322 323 $i++; 324 } 325 // else skip question 326 } 327 328 // display 329 330 // display infos about the details ... 331 echo '<ul>' . "\n" 332 . '<li>' . get_lang('Last name') . ' : '.$thisAttemptDetails['lastname'] . '</li>' . "\n" 333 . '<li>' . get_lang('First name') . ' : '.$thisAttemptDetails['firstname'] . '</li>' . "\n" 334 . '<li>' . get_lang('Date') . ' : ' . claro_html_localised_date(get_locale('dateTimeFormatLong'),$thisAttemptDetails['unix_exe_date']) . '</li>' . "\n" 335 . '<li>' . get_lang('Score') . ' : ' . $thisAttemptDetails['exe_result'] . '/' . $thisAttemptDetails['exe_weighting'] . '</li>' . "\n" 336 . '<li>' . get_lang('Time') . ' : ' . claro_html_duration($thisAttemptDetails['exe_time']) . '</li>' . "\n" 337 . '</ul>' . "\n\n" 338 ; 339 340 echo "\n" . '<table width="100%" border="0" cellpadding="1" cellspacing="0" class="claroTable">' . "\n\n"; 341 342 if( !empty($questionList) ) 343 { 344 // foreach question 345 $questionIterator = 1; 346 $i = 0; 347 348 foreach( $questionList as $question ) 349 { 350 echo '<tr class="headerX">' . "\n" 351 . '<th>' 352 . get_lang('Question') . ' ' . $questionIterator 353 . '</th>' . "\n" 354 . '</tr>' . "\n\n"; 355 356 echo '<tr>' 357 . '<td>' . "\n"; 358 359 echo $question->getQuestionFeedbackHtml(); 360 361 echo '</td>' . "\n" 362 . '</tr>' . "\n\n" 363 364 . '<tr>' 365 . '<td align="right">' . "\n" 366 . '<strong>'.get_lang('Score').' : '.$questionResult[$i].'/'.$questionGrade[$i].'</strong>' 367 . '</td>' . "\n" 368 . '</tr>' . "\n\n"; 369 370 $questionIterator++; 371 $i++; 372 } 373 } 374 375 echo '</table>' . "\n\n"; 376 377 } 378 // not allowed 379 else 380 { 381 if(!get_conf('is_trackingEnabled')) 382 { 383 $dialogBox = get_lang('Tracking has been disabled by system administrator.'); 384 } 385 echo claro_html_message_box($dialogBox); 386 } 387 388 include get_path('incRepositorySys') . '/claro_init_footer.inc.php'; 389 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Thu Nov 29 14:38:42 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |