diff --git a/main/exercice/exercise.class.php b/main/exercice/exercise.class.php index 3456c4d1e9..e42dcf19b5 100755 --- a/main/exercice/exercise.class.php +++ b/main/exercice/exercise.class.php @@ -2938,17 +2938,62 @@ class Exercise if ($debug) error_log('Showing questions $from '.$from); //display answers (if not matching type, or if the answer is correct) if ($answerType != MATCHING || $answerCorrect) { - if (in_array($answerType, array(UNIQUE_ANSWER, UNIQUE_ANSWER_IMAGE, UNIQUE_ANSWER_NO_OPTION, MULTIPLE_ANSWER, MULTIPLE_ANSWER_COMBINATION, GLOBAL_MULTIPLE_ANSWER))) { + if ( + in_array( + $answerType, + array( + UNIQUE_ANSWER, + UNIQUE_ANSWER_IMAGE, + UNIQUE_ANSWER_NO_OPTION, + MULTIPLE_ANSWER, + MULTIPLE_ANSWER_COMBINATION, + GLOBAL_MULTIPLE_ANSWER + ) + ) + ) { //if ($origin != 'learnpath') { - ExerciseShowFunctions::display_unique_or_multiple_answer($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect, 0, 0, 0, $results_disabled); + ExerciseShowFunctions::display_unique_or_multiple_answer( + $feedback_type, + $answerType, + $studentChoice, + $answer, + $answerComment, + $answerCorrect, + 0, + 0, + 0, + $results_disabled + ); //} } elseif ($answerType == MULTIPLE_ANSWER_TRUE_FALSE) { //if ($origin!='learnpath') { - ExerciseShowFunctions::display_multiple_answer_true_false($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect,0,$questionId,0, $results_disabled); + ExerciseShowFunctions::display_multiple_answer_true_false( + $feedback_type, + $answerType, + $studentChoice, + $answer, + $answerComment, + $answerCorrect, + 0, + $questionId, + 0, + $results_disabled + ); //} } elseif ($answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE ) { // if ($origin!='learnpath') { - ExerciseShowFunctions::display_multiple_answer_combination_true_false($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect,0,0,0, $results_disabled); + ExerciseShowFunctions::display_multiple_answer_combination_true_false( + $feedback_type, + $answerType, + $studentChoice, + $answer, + $answerComment, + $answerCorrect, + 0, + 0, + 0, + $results_disabled + ); //} } elseif ($answerType == FILL_IN_BLANKS) { //if ($origin!='learnpath') { @@ -2960,20 +3005,44 @@ class Exercise // } } elseif ($answerType == FREE_ANSWER) { //if($origin != 'learnpath') { - ExerciseShowFunctions::display_free_answer($feedback_type, $choice, $exeId, $questionId, $questionScore); + ExerciseShowFunctions::display_free_answer( + $feedback_type, + $choice, + $exeId, + $questionId, + $questionScore + ); //} } elseif ($answerType == ORAL_EXPRESSION) { // to store the details of open questions in an array to be used in mail //if ($origin != 'learnpath') { - ExerciseShowFunctions::display_oral_expression_answer($feedback_type, $choice, 0, 0, $nano); + ExerciseShowFunctions::display_oral_expression_answer( + $feedback_type, + $choice, + 0, + 0, + $nano); //} } elseif ($answerType == HOT_SPOT) { //if ($origin != 'learnpath') { - ExerciseShowFunctions::display_hotspot_answer($feedback_type, $answerId, $answer, $studentChoice, $answerComment, $results_disabled); + ExerciseShowFunctions::display_hotspot_answer( + $feedback_type, + $answerId, + $answer, + $studentChoice, + $answerComment, + $results_disabled + ); // } } elseif ($answerType == HOT_SPOT_ORDER) { //if ($origin != 'learnpath') { - ExerciseShowFunctions::display_hotspot_order_answer($feedback_type, $answerId, $answer, $studentChoice, $answerComment); + ExerciseShowFunctions::display_hotspot_order_answer( + $feedback_type, + $answerId, + $answer, + $studentChoice, + $answerComment + ); //} } elseif ($answerType == HOT_SPOT_DELINEATION) { $user_answer = $_SESSION['exerciseResultCoordinates'][$questionId]; @@ -2992,16 +3061,16 @@ class Exercise $user_answer = $user_array; // we compare only the delineation not the other points - $answer_question = $_SESSION['hotspot_coord'][1]; - $answerDestination = $_SESSION['hotspot_dest'][1]; + $answer_question = $_SESSION['hotspot_coord'][1]; + $answerDestination = $_SESSION['hotspot_dest'][1]; //calculating the area - $poly_user = convert_coordinates($user_answer,'/'); - $poly_answer = convert_coordinates($answer_question,'|'); - $max_coord = poly_get_max($poly_user,$poly_answer); - $poly_user_compiled = poly_compile($poly_user,$max_coord); - $poly_answer_compiled = poly_compile($poly_answer,$max_coord); - $poly_results = poly_result($poly_answer_compiled,$poly_user_compiled,$max_coord); + $poly_user = convert_coordinates($user_answer, '/'); + $poly_answer = convert_coordinates($answer_question, '|'); + $max_coord = poly_get_max($poly_user, $poly_answer); + $poly_user_compiled = poly_compile($poly_user, $max_coord); + $poly_answer_compiled = poly_compile($poly_answer, $max_coord); + $poly_results = poly_result($poly_answer_compiled, $poly_user_compiled, $max_coord); $overlap = $poly_results['both']; $poly_answer_area = $poly_results['s1']; @@ -3009,8 +3078,11 @@ class Exercise $missing = $poly_results['s1Only']; $excess = $poly_results['s2Only']; - //$overlap = round(polygons_overlap($poly_answer,$poly_user)); //this is an area in pixels - if ($debug>0) error_log(__LINE__.' - Polygons results are '.print_r($poly_results,1),0); + //$overlap = round(polygons_overlap($poly_answer,$poly_user)); + // //this is an area in pixels + if ($debug > 0) { + error_log(__LINE__ . ' - Polygons results are ' . print_r($poly_results, 1), 0); + } if ($overlap < 1) { //shortcut to avoid complicated calculations @@ -3018,18 +3090,23 @@ class Exercise $final_missing = 100; $final_excess = 100; } else { - // the final overlap is the percentage of the initial polygon that is overlapped by the user's polygon - $final_overlap = round(((float)$overlap / (float)$poly_answer_area)*100); - if ($debug>1) error_log(__LINE__.' - Final overlap is '.$final_overlap,0); - // the final missing area is the percentage of the initial polygon that is not overlapped by the user's polygon + // the final overlap is the percentage of the initial polygon + // that is overlapped by the user's polygon + $final_overlap = round(((float) $overlap / (float) $poly_answer_area) * 100); + if ($debug > 1) { + error_log(__LINE__ . ' - Final overlap is ' . $final_overlap, 0); + } + // the final missing area is the percentage of the initial polygon + // that is not overlapped by the user's polygon $final_missing = 100 - $final_overlap; - if ($debug>1) { - error_log(__LINE__.' - Final missing is '.$final_missing,0); + if ($debug > 1) { + error_log(__LINE__ . ' - Final missing is ' . $final_missing, 0); } - // the final excess area is the percentage of the initial polygon's size that is covered by the user's polygon outside of the initial polygon - $final_excess = round((((float)$poly_user_area-(float)$overlap)/(float)$poly_answer_area)*100); - if ($debug>1) { - error_log(__LINE__.' - Final excess is '.$final_excess,0); + // the final excess area is the percentage of the initial polygon's size + // that is covered by the user's polygon outside of the initial polygon + $final_excess = round((((float) $poly_user_area - (float) $overlap) / (float) $poly_answer_area) * 100); + if ($debug > 1) { + error_log(__LINE__ . ' - Final excess is ' . $final_excess, 0); } } @@ -3057,7 +3134,11 @@ class Exercise } // if pass - if ($final_overlap>=$threadhold1 && $final_missing<=$threadhold3 && $final_excess<=$threadhold2) { + if ( + $final_overlap >= $threadhold1 && + $final_missing <= $threadhold3 && + $final_excess <= $threadhold2 + ) { $next=1; //go to the oars $result_comment=get_lang('Acceptable'); $final_answer = 1; // do not update with update_exercise_attempt @@ -3123,8 +3204,10 @@ class Exercise } } elseif($answerType == MATCHING) { echo ''; - echo ''.$answerMatching[$answerId].''; - echo ''.$user_answer.' / '.$answerMatching[$answerCorrect].''; + echo '' . $answerMatching[$answerId] . ''; + echo '' . $user_answer . ' / ' + . '' . $answerMatching[$answerCorrect] . '' + . ''; echo ''; } } @@ -3138,66 +3221,175 @@ class Exercise case MULTIPLE_ANSWER : case GLOBAL_MULTIPLE_ANSWER : case MULTIPLE_ANSWER_COMBINATION : - if ($answerId==1) { - ExerciseShowFunctions::display_unique_or_multiple_answer($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$exeId,$questionId,$answerId, $results_disabled); + if ($answerId == 1) { + ExerciseShowFunctions::display_unique_or_multiple_answer( + $feedback_type, + $answerType, + $studentChoice, + $answer, + $answerComment, + $answerCorrect, + $exeId, + $questionId, + $answerId, + $results_disabled + ); } else { - ExerciseShowFunctions::display_unique_or_multiple_answer($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$exeId,$questionId,"", $results_disabled); + ExerciseShowFunctions::display_unique_or_multiple_answer( + $feedback_type, + $answerType, + $studentChoice, + $answer, + $answerComment, + $answerCorrect, + $exeId, + $questionId, + "", + $results_disabled + ); } break; case MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE: - if ($answerId==1) { - ExerciseShowFunctions::display_multiple_answer_combination_true_false($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$exeId,$questionId,$answerId, $results_disabled); + if ($answerId == 1) { + ExerciseShowFunctions::display_multiple_answer_combination_true_false( + $feedback_type, + $answerType, + $studentChoice, + $answer, + $answerComment, + $answerCorrect, + $exeId, + $questionId, + $answerId, + $results_disabled + ); } else { - ExerciseShowFunctions::display_multiple_answer_combination_true_false($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$exeId,$questionId,"", $results_disabled); + ExerciseShowFunctions::display_multiple_answer_combination_true_false( + $feedback_type, + $answerType, + $studentChoice, + $answer, + $answerComment, + $answerCorrect, + $exeId, + $questionId, + "", + $results_disabled + ); } break; case MULTIPLE_ANSWER_TRUE_FALSE : - if ($answerId==1) { - ExerciseShowFunctions::display_multiple_answer_true_false($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$exeId,$questionId,$answerId, $results_disabled); + if ($answerId == 1) { + ExerciseShowFunctions::display_multiple_answer_true_false( + $feedback_type, + $answerType, + $studentChoice, + $answer, + $answerComment, + $answerCorrect, + $exeId, + $questionId, + $answerId, + $results_disabled + ); } else { - ExerciseShowFunctions::display_multiple_answer_true_false($feedback_type, $answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$exeId,$questionId, "", $results_disabled); + ExerciseShowFunctions::display_multiple_answer_true_false( + $feedback_type, + $answerType, + $studentChoice, + $answer, + $answerComment, + $answerCorrect, + $exeId, + $questionId, + "", + $results_disabled + ); } break; case FILL_IN_BLANKS: - ExerciseShowFunctions::display_fill_in_blanks_answer($feedback_type, $answer,$exeId,$questionId); + ExerciseShowFunctions::display_fill_in_blanks_answer( + $feedback_type, + $answer, + $exeId, + $questionId + ); break; case CALCULATED_ANSWER: - ExerciseShowFunctions::display_calculated_answer($feedback_type, $answer, $exeId, $questionId); + ExerciseShowFunctions::display_calculated_answer( + $feedback_type, + $answer, + $exeId, + $questionId + ); break; case FREE_ANSWER: - echo ExerciseShowFunctions::display_free_answer($feedback_type, $choice, $exeId, $questionId, $questionScore); + echo ExerciseShowFunctions::display_free_answer( + $feedback_type, + $choice, + $exeId, + $questionId, + $questionScore + ); break; case ORAL_EXPRESSION: echo ' - '.ExerciseShowFunctions::display_oral_expression_answer($feedback_type, $choice, $exeId, $questionId, $nano).' - - '; + ' . ExerciseShowFunctions::display_oral_expression_answer( + $feedback_type, + $choice, + $exeId, + $questionId, + $nano + ) . ' + + '; break; case HOT_SPOT: - ExerciseShowFunctions::display_hotspot_answer($feedback_type, $answerId, $answer, $studentChoice, $answerComment, $results_disabled); + ExerciseShowFunctions::display_hotspot_answer( + $feedback_type, + $answerId, + $answer, + $studentChoice, + $answerComment, + $results_disabled); break; case HOT_SPOT_DELINEATION: $user_answer = $user_array; if ($next) { //$tbl_track_e_hotspot = Database::get_main_table(TABLE_STATISTIC_TRACK_E_HOTSPOT); // Save into db - /* $sql = "INSERT INTO $tbl_track_e_hotspot (hotspot_user_id, hotspot_course_code, hotspot_exe_id, hotspot_question_id, hotspot_answer_id, hotspot_correct, hotspot_coordinate ) - VALUES ('".Database::escape_string($_user['user_id'])."', '".Database::escape_string($_course['id'])."', '".Database::escape_string($exeId)."', '".Database::escape_string($questionId)."', '".Database::escape_string($answerId)."', '".Database::escape_string($studentChoice)."', '".Database::escape_string($user_array)."')"; - $result = Database::query($sql,__FILE__,__LINE__);*/ + /* $sql = "INSERT INTO $tbl_track_e_hotspot ( + * hotspot_user_id, + * hotspot_course_code, + * hotspot_exe_id, + * hotspot_question_id, + * hotspot_answer_id, + * hotspot_correct, + * hotspot_coordinate + * ) + VALUES ( + * '".Database::escape_string($_user['user_id'])."', + * '".Database::escape_string($_course['id'])."', + * '".Database::escape_string($exeId)."', '".Database::escape_string($questionId)."', + * '".Database::escape_string($answerId)."', + * '".Database::escape_string($studentChoice)."', + * '".Database::escape_string($user_array)."')"; + $result = Database::query($sql,__FILE__,__LINE__); + */ $user_answer = $user_array; // we compare only the delineation not the other points - $answer_question = $_SESSION['hotspot_coord'][1]; - $answerDestination = $_SESSION['hotspot_dest'][1]; + $answer_question = $_SESSION['hotspot_coord'][1]; + $answerDestination = $_SESSION['hotspot_dest'][1]; //calculating the area - $poly_user = convert_coordinates($user_answer,'/'); - $poly_answer = convert_coordinates($answer_question,'|'); + $poly_user = convert_coordinates($user_answer, '/'); + $poly_answer = convert_coordinates($answer_question, '|'); - $max_coord = poly_get_max($poly_user,$poly_answer); - $poly_user_compiled = poly_compile($poly_user,$max_coord); - $poly_answer_compiled = poly_compile($poly_answer,$max_coord); - $poly_results = poly_result($poly_answer_compiled,$poly_user_compiled,$max_coord); + $max_coord = poly_get_max($poly_user, $poly_answer); + $poly_user_compiled = poly_compile($poly_user, $max_coord); + $poly_answer_compiled = poly_compile($poly_answer, $max_coord); + $poly_results = poly_result($poly_answer_compiled, $poly_user_compiled, $max_coord); $overlap = $poly_results['both']; $poly_answer_area = $poly_results['s1']; @@ -3206,8 +3398,8 @@ class Exercise $excess = $poly_results['s2Only']; //$overlap = round(polygons_overlap($poly_answer,$poly_user)); //this is an area in pixels - if ($debug>0) { - error_log(__LINE__.' - Polygons results are '.print_r($poly_results,1),0); + if ($debug > 0) { + error_log(__LINE__ . ' - Polygons results are ' . print_r($poly_results, 1), 0); } if ($overlap < 1) { //shortcut to avoid complicated calculations @@ -3216,82 +3408,81 @@ class Exercise $final_excess = 100; } else { // the final overlap is the percentage of the initial polygon that is overlapped by the user's polygon - $final_overlap = round(((float)$overlap / (float)$poly_answer_area)*100); - if ($debug>1) { - error_log(__LINE__.' - Final overlap is '.$final_overlap,0); + $final_overlap = round(((float) $overlap / (float) $poly_answer_area) * 100); + if ($debug > 1) { + error_log(__LINE__ . ' - Final overlap is ' . $final_overlap, 0); } // the final missing area is the percentage of the initial polygon that is not overlapped by the user's polygon $final_missing = 100 - $final_overlap; - if ($debug>1) { - error_log(__LINE__.' - Final missing is '.$final_missing,0); + if ($debug > 1) { + error_log(__LINE__ . ' - Final missing is ' . $final_missing, 0); } // the final excess area is the percentage of the initial polygon's size that is covered by the user's polygon outside of the initial polygon - $final_excess = round((((float)$poly_user_area-(float)$overlap)/(float)$poly_answer_area)*100); - if ($debug>1) { - error_log(__LINE__.' - Final excess is '.$final_excess,0); + $final_excess = round((((float) $poly_user_area - (float) $overlap) / (float) $poly_answer_area) * 100); + if ($debug > 1) { + error_log(__LINE__ . ' - Final excess is ' . $final_excess, 0); } } //checking the destination parameters parsing the "@@" - $destination_items= explode('@@', $answerDestination); + $destination_items = explode('@@', $answerDestination); $threadhold_total = $destination_items[0]; - $threadhold_items=explode(';',$threadhold_total); + $threadhold_items = explode(';', $threadhold_total); $threadhold1 = $threadhold_items[0]; // overlap $threadhold2 = $threadhold_items[1]; // excess - $threadhold3 = $threadhold_items[2]; //missing - + $threadhold3 = $threadhold_items[2]; //missing // if is delineation - if ($answerId===1) { + if ($answerId === 1) { //setting colors - if ($final_overlap>=$threadhold1) { - $overlap_color=true; //echo 'a'; + if ($final_overlap >= $threadhold1) { + $overlap_color = true; //echo 'a'; } //echo $excess.'-'.$threadhold2; - if ($final_excess<=$threadhold2) { - $excess_color=true; //echo 'b'; + if ($final_excess <= $threadhold2) { + $excess_color = true; //echo 'b'; } //echo '--------'.$missing.'-'.$threadhold3; - if ($final_missing<=$threadhold3) { - $missing_color=true; //echo 'c'; + if ($final_missing <= $threadhold3) { + $missing_color = true; //echo 'c'; } // if pass - if ($final_overlap>=$threadhold1 && $final_missing<=$threadhold3 && $final_excess<=$threadhold2) { - $next=1; //go to the oars - $result_comment=get_lang('Acceptable'); - $final_answer = 1; // do not update with update_exercise_attempt + if ($final_overlap >= $threadhold1 && $final_missing <= $threadhold3 && $final_excess <= $threadhold2) { + $next = 1; //go to the oars + $result_comment = get_lang('Acceptable'); + $final_answer = 1; // do not update with update_exercise_attempt } else { - $next=0; - $result_comment=get_lang('Unacceptable'); - $comment=$answerDestination=$objAnswerTmp->selectComment(1); - $answerDestination=$objAnswerTmp->selectDestination(1); + $next = 0; + $result_comment = get_lang('Unacceptable'); + $comment = $answerDestination = $objAnswerTmp->selectComment(1); + $answerDestination = $objAnswerTmp->selectDestination(1); //checking the destination parameters parsing the "@@" - $destination_items= explode('@@', $answerDestination); + $destination_items = explode('@@', $answerDestination); } - } elseif($answerId>1) { + } elseif ($answerId > 1) { if ($objAnswerTmp->selectHotspotType($answerId) == 'noerror') { - if ($debug>0) { - error_log(__LINE__.' - answerId is of type noerror',0); + if ($debug > 0) { + error_log(__LINE__ . ' - answerId is of type noerror', 0); } //type no error shouldn't be treated $next = 1; continue; } - if ($debug>0) { - error_log(__LINE__.' - answerId is >1 so we\'re probably in OAR',0); + if ($debug > 0) { + error_log(__LINE__ . ' - answerId is >1 so we\'re probably in OAR', 0); } //check the intersection between the oar and the user //echo 'user'; print_r($x_user_list); print_r($y_user_list); //echo 'official';print_r($x_list);print_r($y_list); //$result = get_intersection_data($x_list,$y_list,$x_user_list,$y_user_list); - $inter= $result['success']; + $inter = $result['success']; //$delineation_cord=$objAnswerTmp->selectHotspotCoordinates($answerId); - $delineation_cord=$objAnswerTmp->selectHotspotCoordinates($answerId); + $delineation_cord = $objAnswerTmp->selectHotspotCoordinates($answerId); - $poly_answer = convert_coordinates($delineation_cord,'|'); - $max_coord = poly_get_max($poly_user,$poly_answer); - $poly_answer_compiled = poly_compile($poly_answer,$max_coord); + $poly_answer = convert_coordinates($delineation_cord, '|'); + $max_coord = poly_get_max($poly_user, $poly_answer); + $poly_answer_compiled = poly_compile($poly_answer, $max_coord); $overlap = poly_touch($poly_user_compiled, $poly_answer_compiled,$max_coord); if ($overlap == false) { @@ -3299,35 +3490,43 @@ class Exercise $next = 1; continue; } else { - if ($debug>0) { - error_log(__LINE__.' - Overlap is '.$overlap.': OAR hit',0); + if ($debug > 0) { + error_log(__LINE__ . ' - Overlap is ' . $overlap . ': OAR hit', 0); } $organs_at_risk_hit++; //show the feedback - $next=0; - $comment=$answerDestination=$objAnswerTmp->selectComment($answerId); - $answerDestination=$objAnswerTmp->selectDestination($answerId); - - $destination_items= explode('@@', $answerDestination); - $try_hotspot=$destination_items[1]; - $lp_hotspot=$destination_items[2]; - $select_question_hotspot=$destination_items[3]; + $next = 0; + $comment = $answerDestination = $objAnswerTmp->selectComment($answerId); + $answerDestination = $objAnswerTmp->selectDestination($answerId); + + $destination_items = explode('@@', $answerDestination); + $try_hotspot = $destination_items[1]; + $lp_hotspot = $destination_items[2]; + $select_question_hotspot = $destination_items[3]; $url_hotspot=$destination_items[4]; } } } else { // the first delineation feedback - if ($debug>0) { - error_log(__LINE__.' first',0); + if ($debug > 0) { + error_log(__LINE__ . ' first', 0); } } break; case HOT_SPOT_ORDER: - ExerciseShowFunctions::display_hotspot_order_answer($feedback_type, $answerId, $answer, $studentChoice, $answerComment); + ExerciseShowFunctions::display_hotspot_order_answer( + $feedback_type, + $answerId, + $answer, + $studentChoice, + $answerComment + ); break; case MATCHING: echo ''; - echo ''.$answerMatching[$answerId].''; - echo ''.$user_answer.' / '.$answerMatching[$answerCorrect].''; + echo '' . $answerMatching[$answerId] . ''; + echo '' . $user_answer . ' / ' + . '' . $answerMatching[$answerCorrect] . '' + . ''; echo ''; break; @@ -3350,9 +3549,9 @@ class Exercise if ($answerType == MULTIPLE_ANSWER_COMBINATION || $answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE ) { if ($final_answer) { //getting only the first score where we save the weight of all the question - $answerWeighting = $objAnswerTmp->selectWeighting(1); - $questionScore += $answerWeighting; - $totalScore += $answerWeighting; + $answerWeighting = $objAnswerTmp->selectWeighting(1); + $questionScore += $answerWeighting; + $totalScore += $answerWeighting; } } @@ -3366,7 +3565,8 @@ class Exercise $counter = 1; $correct_answer = true; foreach ($real_answers as $my_answer) { - if ($debug) error_log(" my_answer: $my_answer answer_correct_array[counter]: ".$answer_correct_array[$counter]); + if ($debug) + error_log(" my_answer: $my_answer answer_correct_array[counter]: ".$answer_correct_array[$counter]); if ($my_answer != $answer_correct_array[$counter]) { $correct_answer = false; break; @@ -3400,8 +3600,10 @@ class Exercise 'threadhold3'=> $threadhold3, ); if ($from == 'exercise_result') { - // if answer is hotspot. To the difference of exercise_show.php, we use the results from the session (from_db=0) - // TODO Change this, because it is wrong to show the user some results that haven't been stored in the database yet + // if answer is hotspot. To the difference of exercise_show.php, + // we use the results from the session (from_db=0) + // TODO Change this, because it is wrong to show the user + // some results that haven't been stored in the database yet if ($answerType == HOT_SPOT || $answerType == HOT_SPOT_ORDER || $answerType == HOT_SPOT_DELINEATION ) { if ($debug) error_log('$from AND this is a hotspot kind of question '); @@ -3440,65 +3642,76 @@ class Exercise } $table_resume=' - - - - - - - - - - - - - - - - - - - - -
'.get_lang('Requirements').''.get_lang('YourAnswer').'
'.get_lang('Overlap').''.get_lang('Min').' '.$threadhold1.'
'.(($final_overlap < 0)?0:intval($final_overlap)).'
'.get_lang('Excess').''.get_lang('Max').' '.$threadhold2.'
'.(($final_excess < 0)?0:intval($final_excess)).'
'.get_lang('Missing').''.get_lang('Max').' '.$threadhold3.'
'.(($final_missing < 0)?0:intval($final_missing)).'
'; - if ($next==0) { + + + ' . get_lang('Requirements') . ' + ' . get_lang('YourAnswer') . ' + + + ' . get_lang('Overlap') . ' + ' . get_lang('Min') . ' ' . $threadhold1 . ' +
' + . (($final_overlap < 0) ? 0 : intval($final_overlap)) . '
+ + + ' . get_lang('Excess') . ' + ' . get_lang('Max') . ' ' . $threadhold2 . ' +
' + . (($final_excess < 0) ? 0 : intval($final_excess)) . '
+ + + ' . get_lang('Missing') . ' + ' . get_lang('Max') . ' ' . $threadhold3 . ' +
' + . (($final_missing < 0) ? 0 : intval($final_missing)) . '
+ + '; + if ($next == 0) { $try = $try_hotspot; $lp = $lp_hotspot; - $destinationid= $select_question_hotspot; - $url=$url_hotspot; + $destinationid = $select_question_hotspot; + $url = $url_hotspot; } else { //show if no error //echo 'no error'; - $comment=$answerComment=$objAnswerTmp->selectComment($nbrAnswers); - $answerDestination=$objAnswerTmp->selectDestination($nbrAnswers); + $comment = $answerComment = $objAnswerTmp->selectComment($nbrAnswers); + $answerDestination = $objAnswerTmp->selectDestination($nbrAnswers); } - echo '

'.get_lang('Feedback').'

-

'; + echo '

' . get_lang('Feedback') . '

+

'; - $message='

'.get_lang('YourDelineation').'

'; - $message.=$table_resume; - $message.='
'.get_lang('ResultIs').' '.$result_comment.'
'; - if ($organs_at_risk_hit>0) { - $message.='

'.get_lang('OARHit').'

'; + $message = '

' . get_lang('YourDelineation') . '

'; + $message .= $table_resume; + $message .= '
' . get_lang('ResultIs') . ' ' . $result_comment . '
'; + if ($organs_at_risk_hit > 0) { + $message .= '

' . get_lang('OARHit') . '

'; } - $message.='

'.$comment.'

'; + $message .='

' . $comment . '

'; echo $message; } else { echo $hotspot_delineation_result[0]; //prints message - $from_database = 1; // the hotspot_solution.swf needs this variable + $from_database = 1; // the hotspot_solution.swf needs this variable } //save the score attempts if (1) { - $final_answer = $hotspot_delineation_result[1]; //getting the answer 1 or 0 comes from exercise_submit_modal.php + //getting the answer 1 or 0 comes from exercise_submit_modal.php + $final_answer = $hotspot_delineation_result[1]; if ($final_answer == 0) { $questionScore = 0; } - Event::saveQuestionAttempt($questionScore, 1, $quesId, $exeId, 0); // we always insert the answer_id 1 = delineation + // we always insert the answer_id 1 = delineation + Event::saveQuestionAttempt($questionScore, 1, $quesId, $exeId, 0); //in delineation mode, get the answer from $hotspot_delineation_result[1] - Event::saveExerciseAttemptHotspot($exeId,$quesId,1, $hotspot_delineation_result[1], $exerciseResultCoordinates[$quesId]); + Event::saveExerciseAttemptHotspot( + $exeId, + $quesId, + 1, + $hotspot_delineation_result[1], + $exerciseResultCoordinates[$quesId] + ); } else { if ($final_answer==0) { $questionScore = 0; @@ -3532,9 +3745,19 @@ class Exercise '; echo ''.get_lang('HotSpot').'

'; - echo ' - - '; + echo ' + + '; echo ' '; // } @@ -3561,13 +3784,22 @@ class Exercise if (empty($choice)) { $choice = 0; } - if ($answerType == MULTIPLE_ANSWER_TRUE_FALSE || $answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE ) { + if ($answerType == MULTIPLE_ANSWER_TRUE_FALSE || $answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE) { if ($choice != 0) { $reply = array_keys($choice); for ($i = 0; $i < sizeof($reply); $i++) { $ans = $reply[$i]; - Event::saveQuestionAttempt($questionScore, $ans.':'.$choice[$ans], $quesId, $exeId, $i, $this->id); - if ($debug) error_log('result =>'.$questionScore.' '.$ans.':'.$choice[$ans]); + Event::saveQuestionAttempt( + $questionScore, + $ans . ':' . $choice[$ans], + $quesId, + $exeId, + $i, + $this->id + ); + if ($debug) { + error_log('result =>' . $questionScore . ' ' . $ans . ':' . $choice[$ans]); + } } } else { Event::saveQuestionAttempt($questionScore, 0, $quesId, $exeId, 0, $this->id); @@ -3576,7 +3808,9 @@ class Exercise if ($choice != 0) { $reply = array_keys($choice); - if ($debug) error_log("reply ".print_r($reply, 1).""); + if ($debug) { + error_log("reply " . print_r($reply, 1) . ""); + } for ($i = 0; $i < sizeof($reply); $i++) { $ans = $reply[$i]; Event::saveQuestionAttempt($questionScore, $ans, $quesId, $exeId, $i, $this->id); @@ -3614,7 +3848,7 @@ class Exercise Event::saveQuestionAttempt($questionScore, $answer, $quesId, $exeId, 0, $this->id); if (isset($exerciseResultCoordinates[$questionId]) && !empty($exerciseResultCoordinates[$questionId])) { foreach ($exerciseResultCoordinates[$questionId] as $idx => $val) { - Event::saveExerciseAttemptHotspot($exeId,$quesId,$idx,$choice[$idx],$val,$this->id); + Event::saveExerciseAttemptHotspot($exeId, $quesId, $idx, $choice[$idx], $val, $this->id); } } } else { @@ -3665,7 +3899,14 @@ class Exercise return false; } - $url_email = api_get_path(WEB_CODE_PATH).'exercice/exercise_show.php?'.api_get_cidreq().'&id_session='.$sessionId.'&id='.$exe_id.'&action=qualify'; + $url_email = api_get_path(WEB_CODE_PATH) + . 'exercice/exercise_show.php?' + . api_get_cidreq() + . '&id_session=' + . $sessionId + . '&id=' + . $exe_id + . '&action=qualify'; $user_info = UserManager::get_user_info_by_id(api_get_user_id()); $msg = '

'.get_lang('ExerciseAttempted').' :

@@ -3734,7 +3975,14 @@ class Exercise $courseCode = api_get_course_id(); $course_info = api_get_course_info($courseCode); - $url_email = api_get_path(WEB_CODE_PATH).'exercice/exercise_show.php?'.api_get_cidreq().'&id_session='.api_get_session_id().'&id='.$exe_id.'&action=qualify'; + $url_email = api_get_path(WEB_CODE_PATH) + . 'exercice/exercise_show.php?' + . api_get_cidreq() + . '&id_session=' + . api_get_session_id() + . '&id=' + . $exe_id + . '&action=qualify'; $user_info = UserManager::get_user_info_by_id(api_get_user_id()); $msg = '

'.get_lang('OpenQuestionsAttempted').' :

@@ -3824,7 +4072,14 @@ class Exercise $courseCode = api_get_course_id(); $course_info = api_get_course_info($courseCode); - $url_email = api_get_path(WEB_CODE_PATH).'exercice/exercise_show.php?'.api_get_cidreq().'&id_session='.api_get_session_id().'&id='.$exe_id.'&action=qualify'; + $url_email = api_get_path(WEB_CODE_PATH) + . 'exercice/exercise_show.php?' + . api_get_cidreq() + . '&id_session=' + . api_get_session_id() + . '&id=' + . $exe_id + . '&action=qualify'; $user_info = UserManager::get_user_info_by_id(api_get_user_id()); $oral_question_list = null; @@ -3834,14 +4089,15 @@ class Exercise $answer_type = $item['answer_type']; if (!empty($question) && !empty($answer) && $answer_type == ORAL_EXPRESSION) { - $oral_question_list.='
- - - - - - -
  '.get_lang('Question').''.$question.'
  '.get_lang('Answer').''.$answer.'
'; + $oral_question_list.='
+ + + + + + + +
  '.get_lang('Question').''.$question.'
  '.get_lang('Answer').''.$answer.'
'; } } @@ -3984,8 +4240,36 @@ class Exercise $sessionId = api_get_session_id(); $course_id = api_get_course_int_id(); // Save a new quiz - $sql = "INSERT INTO $tbl_quiz (c_id, title, type, random, active, results_disabled, max_attempt, start_time,end_time,feedback_type,expired_time, session_id, propagate_neg) - VALUES('$course_id', '".$title."', $type, $random, $active, $results_disabled, $max_attempt,'','', $feedback, $expired_time, $sessionId, $propagateNegative)"; + $sql = "INSERT INTO $tbl_quiz ( + c_id, + title, + type, + random, + active, + results_disabled, + max_attempt, + start_time, + end_time, + feedback_type, + expired_time, + session_id, + propagate_neg + ) + VALUES ( + '$course_id', + '$title', + $type, + $random, + $active, + $results_disabled, + $max_attempt, + '', + '', + $feedback, + $expired_time, + $sessionId, + $propagateNegative + )"; Database::query($sql); $quiz_id = Database::insert_id(); @@ -4102,7 +4386,10 @@ class Exercise } //3. We check if the time limits are on - $limit_time_exists = ((!empty($this->start_time) && $this->start_time != '0000-00-00 00:00:00') || (!empty($this->end_time) && $this->end_time != '0000-00-00 00:00:00')) ? true : false; + $limit_time_exists = ( + (!empty($this->start_time) && $this->start_time != '0000-00-00 00:00:00') || + (!empty($this->end_time) && $this->end_time != '0000-00-00 00:00:00') + ) ? true : false; if ($limit_time_exists) { $time_now = time(); @@ -4112,18 +4399,28 @@ class Exercise } if ($is_visible == false) { - $message = sprintf(get_lang('ExerciseAvailableFromX'), api_convert_and_format_date($this->start_time)); + $message = sprintf( + get_lang('ExerciseAvailableFromX'), + api_convert_and_format_date($this->start_time) + ); } if ($is_visible == true) { if ($this->end_time != '0000-00-00 00:00:00') { $is_visible = ((api_strtotime($this->end_time, 'UTC') > $time_now) > 0) ? true : false; if ($is_visible == false) { - $message = sprintf(get_lang('ExerciseAvailableUntilX'), api_convert_and_format_date($this->end_time)); + $message = sprintf( + get_lang('ExerciseAvailableUntilX'), + api_convert_and_format_date($this->end_time) + ); } } } - if ($is_visible == false && $this->start_time != '0000-00-00 00:00:00' && $this->end_time != '0000-00-00 00:00:00') { + if ( + $is_visible == false && + $this->start_time != '0000-00-00 00:00:00' && + $this->end_time != '0000-00-00 00:00:00' + ) { $message = sprintf( get_lang('ExerciseWillBeActivatedFromXToY'), api_convert_and_format_date($this->start_time), @@ -4169,9 +4466,9 @@ class Exercise public function added_in_lp() { - $TBL_LP_ITEM = Database::get_course_table(TABLE_LP_ITEM); + $TBL_LP_ITEM = Database::get_course_table(TABLE_LP_ITEM); $sql = "SELECT max_score FROM $TBL_LP_ITEM - WHERE c_id = ".$this->course_id." AND item_type = '".TOOL_QUIZ."' AND path = '".$this->id."'"; + WHERE c_id = {$this->course_id} AND item_type = '" . TOOL_QUIZ . "' AND path = '{$this->id}'"; $result = Database::query($sql); if (Database::num_rows($result) > 0) { return true; @@ -4255,7 +4552,13 @@ class Exercise if ($this->random == -1) { $number_of_random_question = count($this->questionList); } - $questionList = array_merge($questionList, TestCategory::getNElementsFromArray($tabquestion, $number_of_random_question)); + $questionList = array_merge( + $questionList, + TestCategory::getNElementsFromArray( + $tabquestion, + $number_of_random_question + ) + ); } // shuffle the question list if test is not grouped by categories if ($isRandomByCategory == 1) { @@ -4263,7 +4566,8 @@ class Exercise } $tabres = $questionList; } else { - // Problem, random by category has been selected and we have no $this->isRandom nnumber of question selected + // Problem, random by category has been selected and + // we have no $this->isRandom number of question selected // Should not happened } } @@ -4415,11 +4719,11 @@ class Exercise $value = null; //Cleaning student answer list $value = strip_tags($teacher_item); - $value = api_substr($value,1, api_strlen($value)-2); + $value = api_substr($value, 1, api_strlen($value) - 2); $value = explode('/', $value); if (!empty($value[0])) { $value = trim($value[0]); - $value = str_replace(' ', '', $value); + $value = str_replace(' ', '', $value); $result .= $value; } } @@ -4429,7 +4733,17 @@ class Exercise function return_time_left_div() { - $html = ''; + $html = ''; $html .= '
'; return $html; } @@ -4454,7 +4768,7 @@ class Exercise $result = Database::query($sql); $list = array(); if (Database::num_rows($result)) { - while($row = Database::fetch_array($result, 'ASSOC')) { + while ($row = Database::fetch_array($result, 'ASSOC')) { $list[$row['exercise_order']] = $row['exercise_id']; } } @@ -4464,20 +4778,21 @@ class Exercise /** * Calculate the max_score of the quiz, depending of question inside, and quiz advanced option */ - public function get_max_score() { + public function get_max_score() + { $out_max_score = 0; $tab_question_list = $this->selectQuestionList(true); // list of question's id !!! the array key start at 1 !!! // test is randomQuestions - see field random of test if ($this->random > 0 && $this->randomByCat == 0) { $nb_random_questions = $this->random; $tab_questions_score = array(); - for ($i=1; $i <= count($tab_question_list); $i++) { + for ($i = 1; $i <= count($tab_question_list); $i++) { $tmpobj_question = Question::read($tab_question_list[$i]); $tab_questions_score[] = $tmpobj_question->weighting; } rsort($tab_questions_score); // add the first $nb_random_questions value of score array to get max_score - for ($i=0; $i < min($nb_random_questions, count($tab_questions_score)); $i++) { + for ($i = 0; $i < min($nb_random_questions, count($tab_questions_score)); $i++) { $out_max_score += $tab_questions_score[$i]; } } @@ -4486,7 +4801,7 @@ class Exercise else if ($this->random > 0 && $this->randomByCat > 0) { $nb_random_questions = $this->random; $tab_categories_scores = array(); - for ($i=1; $i <= count($tab_question_list); $i++) { + for ($i = 1; $i <= count($tab_question_list); $i++) { $question_category_id = TestCategory::getCategoryForQuestion($tab_question_list[$i]); if (!is_array($tab_categories_scores[$question_category_id])) { $tab_categories_scores[$question_category_id] = array(); @@ -4497,14 +4812,14 @@ class Exercise // here we've got an array with first key, the category_id, second key, score of question for this cat while (list($key, $tab_scores) = each($tab_categories_scores)) { rsort($tab_scores); - for ($i=0; $i < min($nb_random_questions, count($tab_scores)); $i++) { + for ($i = 0; $i < min($nb_random_questions, count($tab_scores)); $i++) { $out_max_score += $tab_scores[$i]; } } } // standart test, just add each question score else { - for ($i=1; $i <= count($tab_question_list); $i++) { + for ($i = 1; $i <= count($tab_question_list); $i++) { $tmpobj_question = Question::read($tab_question_list[$i]); $out_max_score += $tmpobj_question->weighting; } diff --git a/main/exercice/question.class.php b/main/exercice/question.class.php index 2c67c0a809..b21b55279c 100755 --- a/main/exercice/question.class.php +++ b/main/exercice/question.class.php @@ -32,22 +32,25 @@ abstract class Question public static $explanationLangVar = ''; public $question_table_class = 'table table-striped'; public static $questionTypes = array( - UNIQUE_ANSWER => array('unique_answer.class.php' , 'UniqueAnswer'), - MULTIPLE_ANSWER => array('multiple_answer.class.php' , 'MultipleAnswer'), - FILL_IN_BLANKS => array('fill_blanks.class.php' , 'FillBlanks'), - MATCHING => array('matching.class.php' , 'Matching'), - FREE_ANSWER => array('freeanswer.class.php' , 'FreeAnswer'), - ORAL_EXPRESSION => array('oral_expression.class.php' , 'OralExpression'), - HOT_SPOT => array('hotspot.class.php' , 'HotSpot'), - HOT_SPOT_DELINEATION => array('hotspot.class.php' , 'HotspotDelineation'), - MULTIPLE_ANSWER_COMBINATION => array('multiple_answer_combination.class.php', 'MultipleAnswerCombination'), - UNIQUE_ANSWER_NO_OPTION => array('unique_answer_no_option.class.php', 'UniqueAnswerNoOption'), - MULTIPLE_ANSWER_TRUE_FALSE => array('multiple_answer_true_false.class.php', 'MultipleAnswerTrueFalse'), - MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE => array('multiple_answer_combination_true_false.class.php', 'MultipleAnswerCombinationTrueFalse'), - GLOBAL_MULTIPLE_ANSWER => array('global_multiple_answer.class.php' , 'GlobalMultipleAnswer'), - CALCULATED_ANSWER => array('calculated_answer.class.php' , 'CalculatedAnswer'), + UNIQUE_ANSWER => array('unique_answer.class.php', 'UniqueAnswer'), + MULTIPLE_ANSWER => array('multiple_answer.class.php', 'MultipleAnswer'), + FILL_IN_BLANKS => array('fill_blanks.class.php', 'FillBlanks'), + MATCHING => array('matching.class.php', 'Matching'), + FREE_ANSWER => array('freeanswer.class.php', 'FreeAnswer'), + ORAL_EXPRESSION => array('oral_expression.class.php', 'OralExpression'), + HOT_SPOT => array('hotspot.class.php', 'HotSpot'), + HOT_SPOT_DELINEATION => array('hotspot.class.php', 'HotspotDelineation'), + MULTIPLE_ANSWER_COMBINATION => array('multiple_answer_combination.class.php', 'MultipleAnswerCombination'), + UNIQUE_ANSWER_NO_OPTION => array('unique_answer_no_option.class.php', 'UniqueAnswerNoOption'), + MULTIPLE_ANSWER_TRUE_FALSE => array('multiple_answer_true_false.class.php', 'MultipleAnswerTrueFalse'), + MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE => array( + 'multiple_answer_combination_true_false.class.php', + 'MultipleAnswerCombinationTrueFalse' + ), + GLOBAL_MULTIPLE_ANSWER => array('global_multiple_answer.class.php' , 'GlobalMultipleAnswer'), + CALCULATED_ANSWER => array('calculated_answer.class.php' , 'CalculatedAnswer'), UNIQUE_ANSWER_IMAGE => ['UniqueAnswerImage.php', 'UniqueAnswerImage'] - //MEDIA_QUESTION => array('media_question.class.php' , 'MediaQuestion') + //MEDIA_QUESTION => array('media_question.class.php' , 'MediaQuestion') ); /** @@ -115,7 +118,7 @@ abstract class Question $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION); $TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION); - $sql = "SELECT question,description,ponderation,position,type,picture,level,extra + $sql = "SELECT question, description, ponderation, position, type, picture, level, extra FROM $TBL_QUESTIONS WHERE c_id = $course_id AND id = $id "; @@ -127,17 +130,17 @@ abstract class Question $objQuestion = Question::getInstance($object->type); if (!empty($objQuestion)) { - $objQuestion->id = $id; - $objQuestion->question = $object->question; - $objQuestion->description = $object->description; - $objQuestion->weighting = $object->ponderation; - $objQuestion->position = $object->position; - $objQuestion->type = $object->type; - $objQuestion->picture = $object->picture; - $objQuestion->level = (int) $object->level; - $objQuestion->extra = $object->extra; - $objQuestion->course = $course_info; - $objQuestion->category = TestCategory::getCategoryForQuestion($id); + $objQuestion->id = $id; + $objQuestion->question = $object->question; + $objQuestion->description = $object->description; + $objQuestion->weighting = $object->ponderation; + $objQuestion->position = $object->position; + $objQuestion->type = $object->type; + $objQuestion->picture = $object->picture; + $objQuestion->level = (int) $object->level; + $objQuestion->extra = $object->extra; + $objQuestion->course = $course_info; + $objQuestion->category = TestCategory::getCategoryForQuestion($id); $sql = "SELECT exercice_id FROM $TBL_EXERCICE_QUESTION WHERE c_id = $course_id AND question_id = $id"; @@ -253,7 +256,7 @@ abstract class Question public function selectPicturePath() { if (!empty($this->picture)) { - return api_get_path(WEB_COURSE_PATH).$this->course['path'].'/document/images/'.$this->picture; + return api_get_path(WEB_COURSE_PATH) . $this->course['path'] . '/document/images/' . $this->picture; } return false; } @@ -306,7 +309,7 @@ abstract class Question */ public function updateDescription($description) { - $this->description=$description; + $this->description = $description; } /** @@ -317,7 +320,7 @@ abstract class Question */ public function updateWeighting($weighting) { - $this->weighting=$weighting; + $this->weighting = $weighting; } /** @@ -326,7 +329,7 @@ abstract class Question */ public function updateCategory($in_category) { - $this->category=$in_category; + $this->category = $in_category; } /** @@ -335,7 +338,7 @@ abstract class Question */ public function updateScoreAlwaysPositive($in_positive) { - $this->scoreAlwaysPositive=$in_positive; + $this->scoreAlwaysPositive = $in_positive; } /** @@ -344,7 +347,7 @@ abstract class Question */ public function updateUncheckedMayScore($in_positive) { - $this->uncheckedMayScore=$in_positive; + $this->uncheckedMayScore = $in_positive; } /** @@ -366,17 +369,22 @@ abstract class Question foreach ($category_list as $category_id) { $category_id = intval($category_id); $question_id = intval($this->id); - $sql = "SELECT count(*) AS nb FROM $TBL_QUESTION_REL_CATEGORY - WHERE category_id = $category_id AND question_id = $question_id AND c_id=".api_get_course_int_id(); + $sql = "SELECT count(*) AS nb + FROM $TBL_QUESTION_REL_CATEGORY + WHERE + category_id = $category_id + AND question_id = $question_id + AND c_id=".api_get_course_int_id(); $res = Database::query($sql); $row = Database::fetch_array($res); if ($row['nb'] > 0) { //DO nothing - //$sql = "UPDATE $TBL_QUESTION_REL_CATEGORY SET category_id = $category_id WHERE question_id=$question_id AND c_id=".api_get_course_int_id(); + //$sql = "UPDATE $TBL_QUESTION_REL_CATEGORY SET category_id = $category_id + //WHERE question_id=$question_id AND c_id=".api_get_course_int_id(); //$res = Database::query($sql); } else { $sql = "INSERT INTO $TBL_QUESTION_REL_CATEGORY (c_id, question_id, category_id) - VALUES (".api_get_course_int_id().", $question_id, $category_id)"; + VALUES (" . api_get_course_int_id() . ", $question_id, $category_id)"; Database::query($sql); } } @@ -400,14 +408,16 @@ abstract class Question $category_id = intval($in_category); $question_id = intval($this->id); $sql = "SELECT count(*) AS nb FROM $TBL_QUESTION_REL_CATEGORY - WHERE question_id=$question_id AND c_id=".api_get_course_int_id(); + WHERE question_id = $question_id AND c_id=" . api_get_course_int_id(); $res = Database::query($sql); $row = Database::fetch_array($res); if ($row['nb'] > 0){ - $sql = "UPDATE $TBL_QUESTION_REL_CATEGORY SET category_id=$category_id WHERE question_id=$question_id AND c_id=".api_get_course_int_id(); + $sql = "UPDATE $TBL_QUESTION_REL_CATEGORY SET category_id = $category_id + WHERE question_id = $question_id AND c_id = " . api_get_course_int_id(); Database::query($sql); } else { - $sql = "INSERT INTO $TBL_QUESTION_REL_CATEGORY VALUES (".api_get_course_int_id().", $question_id, $category_id)"; + $sql = "INSERT INTO $TBL_QUESTION_REL_CATEGORY + VALUES (" . api_get_course_int_id() . ", $question_id, $category_id)"; Database::query($sql); } } @@ -424,7 +434,7 @@ abstract class Question $TBL_QUESTION_REL_CATEGORY = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY); $question_id = intval($this->id); $sql = "DELETE FROM $TBL_QUESTION_REL_CATEGORY - WHERE question_id=$question_id AND c_id=".api_get_course_int_id(); + WHERE question_id = $question_id AND c_id = " . api_get_course_int_id(); Database::query($sql); } @@ -436,7 +446,7 @@ abstract class Question */ public function updatePosition($position) { - $this->position=$position; + $this->position = $position; } /** @@ -447,7 +457,7 @@ abstract class Question */ public function updateLevel($level) { - $this->level=$level; + $this->level = $level; } /** @@ -460,7 +470,7 @@ abstract class Question public function updateType($type) { $TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER); - $course_id = $this->course['real_id']; + $course_id = $this->course['real_id']; if (empty($course_id)) { $course_id = api_get_course_int_id(); @@ -468,10 +478,13 @@ abstract class Question // if we really change the type if ($type != $this->type) { // if we don't change from "unique answer" to "multiple answers" (or conversely) - if (!in_array($this->type, array(UNIQUE_ANSWER,MULTIPLE_ANSWER)) || !in_array($type,array(UNIQUE_ANSWER,MULTIPLE_ANSWER))) { + if ( + !in_array($this->type, array(UNIQUE_ANSWER, MULTIPLE_ANSWER)) || + !in_array($type, array(UNIQUE_ANSWER, MULTIPLE_ANSWER)) + ) { // removes old answers $sql = "DELETE FROM $TBL_REPONSES - WHERE c_id = $course_id AND question_id = ".intval($this->id).""; + WHERE c_id = $course_id AND question_id = " . intval($this->id); Database::query($sql); } @@ -497,9 +510,9 @@ abstract class Question if (mkdir($picturePath, api_get_permissions_for_new_directories())) { // document path $documentPath = api_get_path(SYS_COURSE_PATH) . $this->course['path'] . "/document"; - $path = str_replace($documentPath,'',$picturePath); + $path = str_replace($documentPath, '', $picturePath); $title_path = basename($picturePath); - $doc_id = add_document($this->course, $path, 'folder', 0,$title_path); + $doc_id = add_document($this->course, $path, 'folder', 0, $title_path); api_item_property_update($this->course, TOOL_DOCUMENT, $doc_id, 'FolderCreated', api_get_user_id()); } } @@ -507,18 +520,24 @@ abstract class Question // if the question has got an ID if ($this->id) { $extension = pathinfo($PictureName, PATHINFO_EXTENSION); - $this->picture = 'quiz-'.$this->id.'.jpg'; + $this->picture = 'quiz-' . $this->id . '.jpg'; $o_img = new Image($Picture); - $o_img->send_image($picturePath.'/'.$this->picture, -1, 'jpg'); + $o_img->send_image($picturePath . '/' . $this->picture, -1, 'jpg'); $document_id = add_document( $this->course, - '/images/' . $this->picture, 'file', + '/images/' . $this->picture, + 'file', filesize($picturePath . '/' . $this->picture), $this->picture ); if ($document_id) { - return api_item_property_update($this->course, TOOL_DOCUMENT, - $document_id, 'DocumentAdded', api_get_user_id()); + return api_item_property_update( + $this->course, + TOOL_DOCUMENT, + $document_id, + 'DocumentAdded', + api_get_user_id() + ); } } @@ -526,8 +545,8 @@ abstract class Question } /** - * Resizes a picture || Warning!: can only be called after uploadPicture, or if picture is already available in object. - * + * Resizes a picture || Warning!: can only be called after uploadPicture, + * or if picture is already available in object. * @author Toon Keppens * @param string $Dimension - Resizing happens proportional according to given dimension: height|width|any * @param integer $Max - Maximum size @@ -540,15 +559,15 @@ abstract class Question // if the question has an ID if ($this->id) { // Get dimensions from current image. - $my_image = new Image($picturePath.'/'.$this->picture); + $my_image = new Image($picturePath . '/' . $this->picture); $current_image_size = $my_image->get_image_size(); - $current_width = $current_image_size['width']; - $current_height = $current_image_size['height']; + $current_width = $current_image_size['width']; + $current_height = $current_image_size['height']; - if($current_width < $Max && $current_height <$Max) + if ($current_width < $Max && $current_height < $Max) return true; - elseif($current_height == "") + elseif ($current_height == "") return false; // Resize according to height. @@ -582,7 +601,7 @@ abstract class Question } $my_image->resize($new_width, $new_height); - $result = $my_image->send_image($picturePath.'/'.$this->picture); + $result = $my_image->send_image($picturePath . '/' . $this->picture); if ($result) { return true; @@ -603,11 +622,11 @@ abstract class Question global $picturePath; // if the question has got an ID and if the picture exists - if($this->id) { - $picture=$this->picture; - $this->picture=''; + if ($this->id) { + $picture = $this->picture; + $this->picture = ''; - return @unlink($picturePath.'/'.$picture)?true:false; + return @unlink($picturePath . '/' . $picture) ? true : false; } return false; @@ -622,26 +641,38 @@ abstract class Question */ public function exportPicture($questionId, $course_info) { - $course_id = $course_info['real_id']; - $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION); - $destination_path = api_get_path(SYS_COURSE_PATH).$course_info['path'].'/document/images'; - $source_path = api_get_path(SYS_COURSE_PATH).$this->course['path'].'/document/images'; + $course_id = $course_info['real_id']; + $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION); + $destination_path = api_get_path(SYS_COURSE_PATH) . $course_info['path'] . '/document/images'; + $source_path = api_get_path(SYS_COURSE_PATH) . $this->course['path'] . '/document/images'; // if the question has got an ID and if the picture exists if ($this->id && !empty($this->picture)) { - $picture=explode('.',$this->picture); - $extension = $picture[sizeof($picture)-1]; - $picture = 'quiz-'.$questionId.'.'.$extension; - $result = @copy($source_path.'/'.$this->picture, $destination_path.'/'.$picture) ? true : false; + $picture = explode('.', $this->picture); + $extension = $picture[sizeof($picture) - 1]; + $picture = 'quiz-' . $questionId . '.' . $extension; + $result = @copy($source_path . '/' . $this->picture, $destination_path . '/' . $picture) ? true : false; //If copy was correct then add to the database if ($result) { - $sql = "UPDATE $TBL_QUESTIONS SET picture='".Database::escape_string($picture)."' - WHERE c_id = $course_id AND id='".intval($questionId)."'"; + $sql = "UPDATE $TBL_QUESTIONS SET picture='" . Database::escape_string($picture) . "' + WHERE c_id = $course_id AND id='" . intval($questionId) . "'"; Database::query($sql); - $document_id = add_document($course_info, '/images/'.$picture, 'file', filesize($destination_path.'/'.$picture), $picture); + $document_id = add_document( + $course_info, + '/images/' . $picture, + 'file', + filesize($destination_path . '/' . $picture), + $picture + ); if ($document_id) { - return api_item_property_update($course_info, TOOL_DOCUMENT, $document_id, 'DocumentAdded', api_get_user_id()); + return api_item_property_update( + $course_info, + TOOL_DOCUMENT, + $document_id, + 'DocumentAdded', + api_get_user_id() + ); } } @@ -659,14 +690,14 @@ abstract class Question * @param string $Picture - temporary path of the picture to move * @param string $PictureName - Name of the picture */ - public function setTmpPicture($Picture,$PictureName) + public function setTmpPicture($Picture, $PictureName) { global $picturePath; - $PictureName = explode('.',$PictureName); - $Extension = $PictureName[sizeof($PictureName)-1]; + $PictureName = explode('.', $PictureName); + $Extension = $PictureName[sizeof($PictureName) - 1]; // saves the picture into a temporary file - @move_uploaded_file($Picture,$picturePath.'/tmp.'.$Extension); + @move_uploaded_file($Picture, $picturePath . '/tmp.' . $Extension); } /** @@ -698,15 +729,15 @@ abstract class Question // if the question has got an ID and if the picture exists if ($this->id) { - if (file_exists($picturePath.'/tmp.jpg')) { - $Extension='jpg'; - } elseif(file_exists($picturePath.'/tmp.gif')) { - $Extension='gif'; - } elseif(file_exists($picturePath.'/tmp.png')) { - $Extension='png'; + if (file_exists($picturePath . '/tmp.jpg')) { + $Extension = 'jpg'; + } elseif (file_exists($picturePath . '/tmp.gif')) { + $Extension = 'gif'; + } elseif (file_exists($picturePath . '/tmp.png')) { + $Extension = 'png'; } - $this->picture='quiz-'.$this->id.'.'.$Extension; - return @rename($picturePath.'/tmp.'.$Extension,$picturePath.'/'.$this->picture)?true:false; + $this->picture = 'quiz-' . $this->id . '.' . $Extension; + return @rename($picturePath . '/tmp.' . $Extension, $picturePath . '/' . $this->picture) ? true : false; } return false; } @@ -737,16 +768,17 @@ abstract class Question // question already exists if(!empty($id)) { - $sql="UPDATE $TBL_QUESTIONS SET - question ='".Database::escape_string($question)."', - description ='".Database::escape_string($description)."', - ponderation ='".Database::escape_string($weighting)."', - position ='".Database::escape_string($position)."', - type ='".Database::escape_string($type)."', - picture ='".Database::escape_string($picture)."', - extra ='".Database::escape_string($extra)."', - level ='".Database::escape_string($level)."' - WHERE c_id = $c_id AND id = ".intval($id).""; + $sql = "UPDATE $TBL_QUESTIONS + SET + question = '" . Database::escape_string($question) . "', + description = '" . Database::escape_string($description) . "', + ponderation = '" . Database::escape_string($weighting) . "', + position = '" . Database::escape_string($position) . "', + type = '" . Database::escape_string($type) . "', + picture = '" . Database::escape_string($picture) . "', + extra = '" . Database::escape_string($extra) . "', + level = '" . Database::escape_string($level) . "' + WHERE c_id = $c_id AND id = " . intval($id); Database::query($sql); $this->saveCategory($category); @@ -759,7 +791,7 @@ abstract class Question api_get_user_id() ); } - if (api_get_setting('search_enabled')=='true') { + if (api_get_setting('search_enabled') == 'true') { if ($exerciseId != 0) { $this -> search_engine_edit($exerciseId); } else { @@ -773,27 +805,30 @@ abstract class Question // creates a new question $sql = "SELECT max(position) FROM $TBL_QUESTIONS as question, - $TBL_EXERCICE_QUESTION as test_question + $TBL_EXERCICE_QUESTION as test_question WHERE question.id = test_question.question_id AND - test_question.exercice_id = ".intval($exerciseId)." AND - question.c_id = $c_id AND - test_question.c_id = $c_id "; + test_question.exercice_id = " . intval($exerciseId) . " AND + question.c_id = $c_id AND + test_question.c_id = $c_id "; $result = Database::query($sql); $current_position = Database::result($result,0,0); $this->updatePosition($current_position+1); $position = $this->position; - $sql = "INSERT INTO $TBL_QUESTIONS (c_id, question, description, ponderation, position, type, picture, extra, level) VALUES ( - $c_id, - '".Database::escape_string($question)."', - '".Database::escape_string($description)."', - '".Database::escape_string($weighting)."', - '".Database::escape_string($position)."', - '".Database::escape_string($type)."', - '".Database::escape_string($picture)."', - '".Database::escape_string($extra)."', - '".Database::escape_string($level)."' - )"; + $sql = "INSERT INTO $TBL_QUESTIONS ( + c_id, question, description, ponderation, position, type, picture, extra, level + ) + VALUES ( + $c_id, + '" . Database::escape_string($question) . "', + '" . Database::escape_string($description) . "', + '" . Database::escape_string($weighting) . "', + '" . Database::escape_string($position) . "', + '" . Database::escape_string($type) . "', + '" . Database::escape_string($picture) . "', + '" . Database::escape_string($extra) . "', + '" . Database::escape_string($level) . "' + )"; Database::query($sql); $this->id = Database::insert_id(); @@ -815,8 +850,21 @@ abstract class Question $TBL_ANSWERS = Database::get_course_table( TABLE_QUIZ_ANSWER ); - $sql = "INSERT INTO $TBL_ANSWERS (c_id, question_id , answer, correct, comment, ponderation, position, hotspot_coordinates, hotspot_type) - VALUES (".$c_id.", ".intval($this->id).", '', NULL , '', '10' , '1', '0;0|0|0', 'square')"; + $sql = "INSERT INTO $TBL_ANSWERS ( + c_id, question_id , answer, correct, comment, ponderation, position, hotspot_coordinates, + hotspot_type + ) + VALUES ( + $c_id, + " . intval($this->id) . ", + '', + NULL, + '', + '10', + '1', + '0;0|0|0', + 'square' + )"; Database::query($sql); $id = Database::insert_id(); if ($id) { @@ -829,8 +877,13 @@ abstract class Question $TBL_ANSWERS = Database::get_course_table( TABLE_QUIZ_ANSWER ); - $sql = "INSERT INTO $TBL_ANSWERS (c_id, question_id , answer , correct , comment , ponderation , position , hotspot_coordinates , hotspot_type ) - VALUES (".$c_id.", ".intval($this->id).", '', NULL , '', '10' , '1', '0;0|0|0', 'delineation')"; + $sql = "INSERT INTO $TBL_ANSWERS ( + c_id, question_id, answer, correct, comment, ponderation, position, hotspot_coordinates, + hotspot_type + ) + VALUES ( + $c_id, " . intval($this->id) . ", '', NULL , '', '10' , '1', '0;0|0|0', 'delineation' + )"; Database::query($sql); $id = Database::insert_id(); @@ -876,10 +929,13 @@ abstract class Question $tbl_se_ref = Database::get_main_table(TABLE_MAIN_SEARCH_ENGINE_REF); if ($addQs || $rmQs) { //there's only one row per question on normal db and one document per question on search engine db - $sql = 'SELECT * FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_second_level=%s LIMIT 1'; + $sql = 'SELECT * FROM % + WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_second_level=%s LIMIT 1'; $sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_QUIZ, $this->id); } else { - $sql = 'SELECT * FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=%s AND ref_id_second_level=%s LIMIT 1'; + $sql = 'SELECT * FROM %s + WHERE course_code=\'%s\' AND tool_id=\'%s\' + AND ref_id_high_level=%s AND ref_id_second_level=%s LIMIT 1'; $sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_QUIZ, $exerciseId, $this->id); } $res = Database::query($sql); @@ -890,21 +946,27 @@ abstract class Question $di = new ChamiloIndexer(); if ($addQs) { - $question_exercises = array((int)$exerciseId); + $question_exercises = array((int) $exerciseId); } else { $question_exercises = array(); } - isset($_POST['language'])? $lang=Database::escape_string($_POST['language']): $lang = 'english'; + isset($_POST['language']) ? $lang = Database::escape_string($_POST['language']) : $lang = 'english'; $di->connectDb(NULL, NULL, $lang); // retrieve others exercise ids $se_ref = Database::fetch_array($res); $se_doc = $di->get_document((int)$se_ref['search_did']); if ($se_doc !== FALSE) { - if ( ($se_doc_data=$di->get_document_data($se_doc)) !== FALSE ) { + if (($se_doc_data = $di->get_document_data($se_doc)) !== FALSE) { $se_doc_data = unserialize($se_doc_data); - if (isset($se_doc_data[SE_DATA]['type']) && $se_doc_data[SE_DATA]['type'] == SE_DOCTYPE_EXERCISE_QUESTION) { - if (isset($se_doc_data[SE_DATA]['exercise_ids']) && is_array($se_doc_data[SE_DATA]['exercise_ids'])) { + if ( + isset($se_doc_data[SE_DATA]['type']) && + $se_doc_data[SE_DATA]['type'] == SE_DOCTYPE_EXERCISE_QUESTION + ) { + if ( + isset($se_doc_data[SE_DATA]['exercise_ids']) && + is_array($se_doc_data[SE_DATA]['exercise_ids']) + ) { foreach ($se_doc_data[SE_DATA]['exercise_ids'] as $old_value) { if (!in_array($old_value, $question_exercises)) { $question_exercises[] = $old_value; @@ -915,7 +977,7 @@ abstract class Question } } if ($rmQs) { - while ( ($key=array_search($exerciseId, $question_exercises)) !== FALSE) { + while (($key = array_search($exerciseId, $question_exercises)) !== FALSE) { unset($question_exercises[$key]); } } @@ -928,7 +990,11 @@ abstract class Question $xapian_data = array( SE_COURSE_ID => $course_id, SE_TOOL_ID => TOOL_QUIZ, - SE_DATA => array('type' => SE_DOCTYPE_EXERCISE_QUESTION, 'exercise_ids' => $question_exercises, 'question_id' => (int)$this->id), + SE_DATA => array( + 'type' => SE_DOCTYPE_EXERCISE_QUESTION, + 'exercise_ids' => $question_exercises, + 'question_id' => (int)$this->id + ), SE_USER => (int)api_get_user_id(), ); $ic_slide->xapian_data = serialize($xapian_data); @@ -947,23 +1013,46 @@ abstract class Question if ($did || $rmQs) { // save it to db if ($addQs || $rmQs) { - $sql = 'DELETE FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_second_level=\'%s\''; + $sql = "DELETE FROM %s + WHERE course_code = '%s' AND tool_id = '%s' AND ref_id_second_level = '%s'"; $sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_QUIZ, $this->id); } else { - $sql = 'DELETE FROM %s WHERE course_code=\'%s\' AND tool_id=\'%s\' AND ref_id_high_level=\'%s\' AND ref_id_second_level=\'%s\''; + $sql = "DELETE FROM %S + WHERE + course_code = '%s' + AND tool_id = '%s' + AND tool_id = '%s' + AND ref_id_high_level = '%s' + AND ref_id_second_level = '%s'"; $sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_QUIZ, $exerciseId, $this->id); } Database::query($sql); if ($rmQs) { if (!empty($question_exercises)) { - $sql = 'INSERT INTO %s (id, course_code, tool_id, ref_id_high_level, ref_id_second_level, search_did) - VALUES (NULL , \'%s\', \'%s\', %s, %s, %s)'; - $sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_QUIZ, array_shift($question_exercises), $this->id, $did); + $sql = "INSERT INTO %s ( + id, course_code, tool_id, ref_id_high_level, ref_id_second_level, search_did + ) + VALUES ( + NULL, '%s', '%s', %s, %s, %s + )"; + $sql = sprintf( + $sql, + $tbl_se_ref, + $course_id, + TOOL_QUIZ, + array_shift($question_exercises), + $this->id, + $did + ); Database::query($sql); } } else { - $sql = 'INSERT INTO %s (id, course_code, tool_id, ref_id_high_level, ref_id_second_level, search_did) - VALUES (NULL , \'%s\', \'%s\', %s, %s, %s)'; + $sql = "INSERT INTO %s ( + id, course_code, tool_id, ref_id_high_level, ref_id_second_level, search_did + ) + VALUES ( + NULL , '%s', '%s', %s, %s, %s + )"; $sql = sprintf($sql, $tbl_se_ref, $course_id, TOOL_QUIZ, $exerciseId, $this->id, $did); Database::query($sql); } @@ -985,14 +1074,14 @@ abstract class Question $exerciseRelQuestionTable = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION); $id = $this->id; // checks if the exercise ID is not in the list - if (!in_array($exerciseId,$this->exerciseList)) { - $this->exerciseList[]= $exerciseId; + if (!in_array($exerciseId, $this->exerciseList)) { + $this->exerciseList[] = $exerciseId; $new_exercise = new Exercise(); $new_exercise->read($exerciseId); $count = $new_exercise->selectNbrQuestions(); $count++; - $sql="INSERT INTO $exerciseRelQuestionTable (c_id, question_id, exercice_id, question_order) VALUES - ({$this->course['real_id']}, ".intval($id).", ".intval($exerciseId).", '$count' )"; + $sql="INSERT INTO $exerciseRelQuestionTable (c_id, question_id, exercice_id, question_order) + VALUES ({$this->course['real_id']}, " . intval($id) . ", " . intval($exerciseId) . ", '$count')"; Database::query($sql); // we do not want to reindex if we had just saved adnd indexed the question @@ -1016,7 +1105,7 @@ abstract class Question $id = $this->id; // searches the position of the exercise ID in the list - $pos=array_search($exerciseId,$this->exerciseList); + $pos = array_search($exerciseId, $this->exerciseList); $course_id = api_get_course_int_id(); @@ -1027,20 +1116,31 @@ abstract class Question // deletes the position in the array containing the wanted exercise ID unset($this->exerciseList[$pos]); //update order of other elements - $sql = "SELECT question_order FROM $TBL_EXERCICE_QUESTION - WHERE c_id = $course_id AND question_id = ".intval($id)." AND exercice_id = ".intval($exerciseId).""; + $sql = "SELECT question_order + FROM $TBL_EXERCICE_QUESTION + WHERE + c_id = $course_id + AND question_id = " . intval($id) . " + AND exercice_id = " . intval($exerciseId); $res = Database::query($sql); if (Database::num_rows($res)>0) { $row = Database::fetch_array($res); if (!empty($row['question_order'])) { - $sql = "UPDATE $TBL_EXERCICE_QUESTION SET question_order = question_order-1 - WHERE c_id = $course_id AND exercice_id = ".intval($exerciseId)." AND question_order > ".$row['question_order']; + $sql = "UPDATE $TBL_EXERCICE_QUESTION + SET question_order = question_order-1 + WHERE + c_id = $course_id + AND exercice_id = " . intval($exerciseId) . " + AND question_order > " . $row['question_order']; $res = Database::query($sql); } } $sql = "DELETE FROM $TBL_EXERCICE_QUESTION - WHERE c_id = $course_id AND question_id = ".intval($id)." AND exercice_id = ".intval($exerciseId).""; + WHERE + c_id = $course_id + AND question_id = " . intval($id) . " + AND exercice_id = " . intval($exerciseId); Database::query($sql); return true; @@ -1059,9 +1159,9 @@ abstract class Question { $course_id = api_get_course_int_id(); - $TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION); - $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION); - $TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER); + $TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION); + $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION); + $TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER); $TBL_QUIZ_QUESTION_REL_CATEGORY = Database::get_course_table(TABLE_QUIZ_QUESTION_REL_CATEGORY); $id = $this->id; @@ -1078,27 +1178,30 @@ abstract class Question if (!empty($row['question_order'])) { $sql = "UPDATE $TBL_EXERCICE_QUESTION SET question_order = question_order-1 - WHERE c_id = $course_id AND exercice_id = ".intval($row['exercice_id'])." AND question_order > ".$row['question_order']; + WHERE + c_id= $course_id + AND exercice_id = " . intval($row['exercice_id']) . " + AND question_order > " . $row['question_order']; Database::query($sql); } } } - $sql = "DELETE FROM $TBL_EXERCICE_QUESTION WHERE c_id = $course_id AND question_id = ".intval($id).""; + $sql = "DELETE FROM $TBL_EXERCICE_QUESTION WHERE c_id = $course_id AND question_id = " . intval($id) . ""; Database::query($sql); - $sql = "DELETE FROM $TBL_QUESTIONS WHERE c_id = $course_id AND id = ".intval($id).""; + $sql = "DELETE FROM $TBL_QUESTIONS WHERE c_id = $course_id AND id = " . intval($id) . ""; Database::query($sql); - $sql = "DELETE FROM $TBL_REPONSES WHERE c_id = $course_id AND question_id = ".intval($id).""; + $sql = "DELETE FROM $TBL_REPONSES WHERE c_id = $course_id AND question_id = " . intval($id) . ""; Database::query($sql); // remove the category of this question in the question_rel_category table $sql = "DELETE FROM $TBL_QUIZ_QUESTION_REL_CATEGORY - WHERE c_id = $course_id AND question_id = ".intval($id)." AND c_id=".api_get_course_int_id(); + WHERE c_id = $course_id AND question_id = " . intval($id) . " AND c_id=" . api_get_course_int_id(); Database::query($sql); - api_item_property_update($this->course, TOOL_QUIZ, $id,'QuizQuestionDeleted',api_get_user_id()); + api_item_property_update($this->course, TOOL_QUIZ, $id, 'QuizQuestionDeleted', api_get_user_id()); $this->removePicture(); // resets the object @@ -1106,11 +1209,11 @@ abstract class Question } else { // just removes the exercise from the list $this->removeFromList($deleteFromEx); - if (api_get_setting('search_enabled')=='true' && extension_loaded('xapian')) { + if (api_get_setting('search_enabled') == 'true' && extension_loaded('xapian')) { // disassociate question with this exercise - $this -> search_engine_edit($deleteFromEx, FALSE, TRUE); + $this->search_engine_edit($deleteFromEx, FALSE, TRUE); } - api_item_property_update($this->course, TOOL_QUIZ, $id,'QuizQuestionDeleted',api_get_user_id()); + api_item_property_update($this->course, TOOL_QUIZ, $id, 'QuizQuestionDeleted', api_get_user_id()); } } @@ -1160,8 +1263,19 @@ abstract class Question $options = self::readQuestionOption($this->id, $this->course['real_id']); //Inserting in the new course db / or the same course db - $sql = "INSERT INTO $TBL_QUESTIONS (c_id, question, description, ponderation, position, type, level, extra ) - VALUES('$course_id', '".Database::escape_string($question)."','".Database::escape_string($description)."','".Database::escape_string($weighting)."','".Database::escape_string($position)."','".Database::escape_string($type)."' ,'".Database::escape_string($level)."' ,'".Database::escape_string($extra)."' )"; + $sql = "INSERT INTO $TBL_QUESTIONS ( + c_id, question, description, ponderation, position, type, level, extra + ) + VALUES ( + '$course_id', + '" . Database::escape_string($question) . "', + '" . Database::escape_string($description) . "', + '" . Database::escape_string($weighting) . "', + '" . Database::escape_string($position) . "', + '" . Database::escape_string($type) . "', + '" . Database::escape_string($level) . "', + '" . Database::escape_string($extra) . "' + )"; Database::query($sql); $new_question_id = Database::insert_id(); @@ -1237,7 +1351,7 @@ abstract class Question if (class_exists($class_name)) { return new $class_name(); } else { - echo 'Can\'t instanciate class '.$class_name.' of type '.$type; + echo 'Can\'t instanciate class ' . $class_name . ' of type ' . $type; } } } @@ -1253,8 +1367,8 @@ abstract class Question public function createForm(&$form) { echo ''; + .media { display:none;} + '; echo ''; + '; // question name $form->addElement('text', 'questionName', get_lang('Question'), array('class' => 'span6')); @@ -1437,17 +1550,17 @@ abstract class Question require_once $a_type[0]; // get the picture of the type and the langvar which describes it $img = $explanation = ''; - eval('$img = '.$a_type[1].'::$typePicture;'); - eval('$explanation = get_lang('.$a_type[1].'::$explanationLangVar);'); + eval('$img = ' . $a_type[1] . '::$typePicture;'); + eval('$explanation = get_lang(' . $a_type[1] . '::$explanationLangVar);'); echo '
  • '; echo '
    '; if ($objExercise->exercise_was_added_in_lp == true) { $img = pathinfo($img); - $img = $img['filename'].'_na.'.$img['extension']; + $img = $img['filename'] . '_na.' . $img['extension']; echo Display::return_icon($img, $explanation, null, ICON_SIZE_BIG); } else { - echo ''. - Display::return_icon($img, $explanation, null, ICON_SIZE_BIG).''; + echo '' . + Display::return_icon($img, $explanation, null, ICON_SIZE_BIG) . ''; } echo '
    '; echo '
  • '; @@ -1458,10 +1571,10 @@ abstract class Question if ($objExercise->exercise_was_added_in_lp == true) { echo Display::return_icon('database_na.png', get_lang('GetExistingQuestion'), null, ICON_SIZE_BIG); } else { - if ($feedback_type==1) { - echo $url = ''; + if ($feedback_type == 1) { + echo $url = ""; } else { - echo $url = ''; + echo $url = ''; } echo Display::return_icon('database.png', get_lang('GetExistingQuestion'), null, ICON_SIZE_BIG); } @@ -1485,7 +1598,7 @@ abstract class Question $params['name'] = $name; $params['position'] = $position; $params['c_id'] = $course_id; - $result = self::readQuestionOption($question_id, $course_id); + $result = self::readQuestionOption($question_id, $course_id); $last_id = Database::insert($TBL_EXERCICE_QUESTION_OPTION, $params); if ($last_id) { $sql = "UPDATE $TBL_EXERCICE_QUESTION_OPTION SET id = iid WHERE iid = $last_id"; @@ -1598,9 +1711,12 @@ abstract class Question $header .= $this->show_media_content(); } - $header .= Display::page_subheader2($counter_label.". ".$question_title); - $header .= Display::div('

    '.$score_label.'

    '.$score['result'].'

    ', array('class'=>'ribbon')); - $header .= Display::div($this->description, array('id'=>'question_description')); + $header .= Display::page_subheader2($counter_label . ". " . $question_title); + $header .= Display::div( + "

    $score_label'

    {$score['result']}

    ", + array('class' => 'ribbon') + ); + $header .= Display::div($this->description, array('id' => 'question_description')); return $header; } @@ -1640,11 +1756,21 @@ abstract class Question r.c_id = $course_id"; $rs_max = Database::query($sql); $row_max = Database::fetch_object($rs_max); - $max_position = $row_max->max_position +1; + $max_position = $row_max->max_position + 1; // Insert the new question - $sql = "INSERT INTO $tbl_quiz_question (c_id, question, description, ponderation, position, type, level) - VALUES ($course_id, '".Database::escape_string($question_name)."', '".Database::escape_string($question_description)."', '$max_score', $max_position, $type, $level)"; + $sql = "INSERT INTO $tbl_quiz_question ( + c_id, question, description, ponderation, position, type, level + ) + VALUES ( + $course_id, + '" . Database::escape_string($question_name) . "', + '" . Database::escape_string($question_description) . "', + '$max_score', + $max_position, + $type, + $level + )"; Database::query($sql); // Get the question ID @@ -1675,12 +1801,12 @@ abstract class Question */ public function get_type_icon_html() { - $type = $this->selectType(); + $type = $this->selectType(); $tabQuestionList = Question::get_question_type_list(); // [0]=file to include [1]=type name require_once $tabQuestionList[$type][0]; - eval('$img = '.$tabQuestionList[$type][1].'::$typePicture;'); - eval('$explanation = get_lang('.$tabQuestionList[$type][1].'::$explanationLangVar);'); + eval('$img = ' . $tabQuestionList[$type][1] . '::$typePicture;'); + eval('$explanation = get_lang(' . $tabQuestionList[$type][1] . '::$explanationLangVar);'); return array($img, $explanation); } @@ -1688,15 +1814,25 @@ abstract class Question * Get course medias * @param int course id */ - static function get_course_medias($course_id, $start = 0, $limit = 100, $sidx = "question", $sord = "ASC", $where_condition = array()) + static function get_course_medias( + $course_id, + $start = 0, + $limit = 100, + $sidx = "question", + $sord = "ASC", + $where_condition = array() + ) { $table_question = Database::get_course_table(TABLE_QUIZ_QUESTION); $default_where = array('c_id = ? AND parent_id = 0 AND type = ?' => array($course_id, MEDIA_QUESTION)); - $result = Database::select('*', $table_question, + $result = Database::select( + '*', + $table_question, array( 'limit' => " $start, $limit", 'where' => $default_where, - 'order' => "$sidx $sord") + 'order' => "$sidx $sord" + ) ); return $result; } @@ -1711,9 +1847,9 @@ abstract class Question { $table_question = Database::get_course_table(TABLE_QUIZ_QUESTION); $result = Database::select( - 'count(*) as count', + 'count(*) as count', $table_question, - array('where'=>array('c_id = ? AND parent_id = 0 AND type = ?' => array($course_id, MEDIA_QUESTION))), + array('where' => array('c_id = ? AND parent_id = 0 AND type = ?' => array($course_id, MEDIA_QUESTION))), 'first' ); diff --git a/main/inc/lib/exercise.lib.php b/main/inc/lib/exercise.lib.php index 05ffa23407..3c9424dc05 100644 --- a/main/inc/lib/exercise.lib.php +++ b/main/inc/lib/exercise.lib.php @@ -223,16 +223,17 @@ class ExerciseLib } if ($show_comment) { - if (in_array( - $answerType, - array( - MULTIPLE_ANSWER, - MULTIPLE_ANSWER_COMBINATION, - UNIQUE_ANSWER, - UNIQUE_ANSWER_NO_OPTION, - GLOBAL_MULTIPLE_ANSWER + if ( + in_array( + $answerType, + array( + MULTIPLE_ANSWER, + MULTIPLE_ANSWER_COMBINATION, + UNIQUE_ANSWER, + UNIQUE_ANSWER_NO_OPTION, + GLOBAL_MULTIPLE_ANSWER + ) ) - ) ) { $header = Display::tag('th', get_lang('Options')); if ($exercise_feedback == EXERCISE_FEEDBACK_TYPE_END) { @@ -329,7 +330,8 @@ class ExerciseLib $s .= $answer_input; } - } elseif ($answerType == MULTIPLE_ANSWER || + } elseif ( + $answerType == MULTIPLE_ANSWER || $answerType == MULTIPLE_ANSWER_TRUE_FALSE || $answerType == GLOBAL_MULTIPLE_ANSWER ) {