Browse Source

Minor - format code.

Julio Montoya 11 years ago
parent
commit
01cce0e372

+ 15 - 4
main/exercice/exercise.class.php

@@ -2574,9 +2574,14 @@ class Exercise {
                     if ($from_database) {
                         if ($show_result) {
                             $TBL_TRACK_HOTSPOT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTSPOT);
-                            $query = "SELECT hotspot_correct FROM ".$TBL_TRACK_HOTSPOT." WHERE hotspot_exe_id = '".$exeId."' and hotspot_question_id= '".$questionId."' AND hotspot_answer_id='".Database::escape_string($answerId)."'";
-                            $resq = Database::query($query);
-                            $studentChoice = Database::result($resq,0,"hotspot_correct");
+                            $sql = "SELECT hotspot_correct
+                                    FROM $TBL_TRACK_HOTSPOT
+                                    WHERE
+                                        hotspot_exe_id = '".$exeId."' AND
+                                        hotspot_question_id= '".$questionId."' AND
+                                        hotspot_answer_id = '".Database::escape_string($answerId)."'";
+                            $result = Database::query($sql);
+                            $studentChoice = Database::result($result, 0, "hotspot_correct");
 
                             if ($studentChoice) {
                                 $questionScore  += $answerWeighting;
@@ -2608,7 +2613,13 @@ class Exercise {
                     if ($from_database) {
                         // getting the user answer
                         $TBL_TRACK_HOTSPOT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTSPOT);
-                        $query   = "SELECT hotspot_correct, hotspot_coordinate from ".$TBL_TRACK_HOTSPOT." where hotspot_exe_id = '".$exeId."' and hotspot_question_id= '".$questionId."' AND hotspot_answer_id='1'"; //by default we take 1 because it's a delineation
+                        $query   = "SELECT hotspot_correct, hotspot_coordinate
+                                    FROM $TBL_TRACK_HOTSPOT
+                                    WHERE
+                                        hotspot_exe_id = '".$exeId."' AND
+                                        hotspot_question_id= '".$questionId."' AND
+                                        hotspot_answer_id='1'";
+                        //by default we take 1 because it's a delineation
                         $resq    = Database::query($query);
                         $row     = Database::fetch_array($resq,'ASSOC');
 

+ 12 - 14
main/exercice/exercise.lib.php

@@ -45,6 +45,7 @@ function showQuestion($questionId, $only_questions = false, $origin = false, $cu
 
     $answerType    = $objQuestionTmp->selectType();
     $pictureName   = $objQuestionTmp->selectPicture();
+    $s = '';
 
     if ($answerType != HOT_SPOT && $answerType != HOT_SPOT_DELINEATION) {
     	// Question is not a hotspot
@@ -65,9 +66,6 @@ function showQuestion($questionId, $only_questions = false, $origin = false, $cu
         }
 
         echo '<div class="question_options">';
-
-    	$s = '';
-
     	// construction of the Answer object (also gets all answers details)
     	$objAnswerTmp = new Answer($questionId);
 
@@ -195,7 +193,7 @@ function showQuestion($questionId, $only_questions = false, $origin = false, $cu
                     $header .= Display::tag('th', get_lang('Feedback'));
                 }
                 $s .= '<table class="data_table">';
-                $s.= Display::tag('tr',$header, array('style'=>'text-align:left;'));
+                $s .= Display::tag('tr',$header, array('style'=>'text-align:left;'));
             }
         }
 
@@ -353,16 +351,16 @@ function showQuestion($questionId, $only_questions = false, $origin = false, $cu
                 $answer_input .= '</label>';
 
                 if ($show_comment) {
-                    $s.= '<tr>';
+                    $s .= '<tr>';
                     $s .= '<td>';
-                    $s.= $answer_input;
+                    $s .= $answer_input;
                     $s .= '</td>';
                     $s .= '<td>';
                     $s .= $comment;
                     $s .= '</td>';
-                    $s.= '</tr>';
+                    $s .= '</tr>';
                 } else {
-                    $s.= $answer_input;
+                    $s .= $answer_input;
                 }
 
             } elseif ($answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE) {
@@ -400,7 +398,7 @@ function showQuestion($questionId, $only_questions = false, $origin = false, $cu
                     $s .= $comment;
                     $s .= '</td>';
                 }
-            	$s.='</tr>';
+            	$s .='</tr>';
 
     		} elseif ($answerType == FILL_IN_BLANKS) {
                 /*
@@ -529,7 +527,7 @@ function showQuestion($questionId, $only_questions = false, $origin = false, $cu
     				}  // end foreach()
 
     				$s .= '</select></td>';
-    				$s.='<td width="45%" valign="top" >';
+    				$s .='<td width="45%" valign="top" >';
     				if (isset($select_items[$lines_count])) {
     					$s.='<span style="float:left; width:5%;"><b>'.$select_items[$lines_count]['letter'].'.</b></span>'.
     						 '<span style="float:left; width:95%;">'.$select_items[$lines_count]['answer'].'</span>';
@@ -547,8 +545,8 @@ function showQuestion($questionId, $only_questions = false, $origin = false, $cu
     						$s .= '<tr>
     							  <td colspan="2"></td>
     							  <td valign="top">';
-    						$s.='<b>'.$select_items[$lines_count]['letter'].'.</b> '.$select_items[$lines_count]['answer'];
-    						$s.="</td>
+    						$s .='<b>'.$select_items[$lines_count]['letter'].'.</b> '.$select_items[$lines_count]['answer'];
+    						$s .="</td>
     						</tr>";
     						$lines_count++;
     					}	// end while()
@@ -567,8 +565,6 @@ function showQuestion($questionId, $only_questions = false, $origin = false, $cu
             }
         }
 
-
-
     	$s .= '</div>';
 
     	// destruction of the Answer object
@@ -648,6 +644,7 @@ function showQuestion($questionId, $only_questions = false, $origin = false, $cu
     		echo $questionDescription;
     		echo '</td></tr>';
     	}
+
     	$canClick = isset($_GET['editQuestion']) ? '0' : (isset($_GET['modifyAnswers']) ? '0' : '1');
 
     	$s .= '<script type="text/javascript" src="../plugin/hotspot/JavaScriptFlashGateway.js"></script>
@@ -788,6 +785,7 @@ function showQuestion($questionId, $only_questions = false, $origin = false, $cu
     	echo $s;
         echo '</table>';
     }
+
     return $nbrAnswers;
 }
 

+ 1 - 1
main/exercice/overview.php

@@ -98,7 +98,7 @@ if (isset($exercise_stat_info['exe_id'])) {
 }
 
 //1. Check if this is a new attempt or a previous
-$countNotFinished = $exercise_stat_info['num_exe'];
+$countNotFinished = isset($exercise_stat_info['num_exe']) ? $exercise_stat_info['num_exe'] : null;
 $label = get_lang('StartTest');
 if ($time_control && !empty($clock_expired_time) || !empty($attempt_list)) {
 	$label = get_lang('ContinueTest');

+ 82 - 27
main/inc/ajax/exercise.ajax.php

@@ -77,29 +77,41 @@ switch ($action) {
             $start = 0;
         }
 
-        $sql = "SELECT  exe_id,
-                        exe_user_id,
-                        firstname,
-                        lastname,
-                        aa.status,
-                        start_date,
-                        exe_result,
-                        exe_weighting,
-                        exe_result/exe_weighting as score,
-                        exe_duration,
-                        questions_to_check,
-                        orig_lp_id
+        $sql = "SELECT
+                    exe_id,
+                    exe_user_id,
+                    firstname,
+                    lastname,
+                    aa.status,
+                    start_date,
+                    exe_result,
+                    exe_weighting,
+                    exe_result/exe_weighting as score,
+                    exe_duration,
+                    questions_to_check,
+                    orig_lp_id
                 FROM $user_table u
                 INNER JOIN (
-                    SELECT  t.exe_id, t.exe_user_id, status,
-                    start_date, exe_result, exe_weighting, exe_result/exe_weighting as score, exe_duration, questions_to_check, orig_lp_id
-                    FROM  $track_exercise  t LEFT JOIN $track_attempt a ON (a.exe_id = t.exe_id AND  t.exe_user_id = a.user_id )
-                    WHERE t.status = 'incomplete' AND
-                          $where_condition
+                    SELECT
+                    t.exe_id,
+                    t.exe_user_id,
+                    status,
+                    start_date,
+                    exe_result,
+                    exe_weighting,
+                    exe_result/exe_weighting as score,
+                    exe_duration,
+                    questions_to_check,
+                    orig_lp_id
+                    FROM  $track_exercise  t
+                    LEFT JOIN $track_attempt a
+                    ON (a.exe_id = t.exe_id AND t.exe_user_id = a.user_id )
+                    WHERE t.status = 'incomplete' AND $where_condition
                     GROUP BY exe_user_id
                 ) as aa
                 ON aa.exe_user_id = user_id
-                ORDER BY $sidx $sord LIMIT $start, $limit";
+                ORDER BY $sidx $sord
+                LIMIT $start, $limit";
 
         $result = Database::query($sql);
         $results = array();
@@ -118,9 +130,13 @@ switch ($action) {
 
         if (!empty($results)) {
             foreach ($results as $row) {
-                $sql = "SELECT SUM(count_question_id) as count_question_id FROM (
-                            SELECT 1 as count_question_id FROM  $track_attempt a
-                            WHERE user_id = {$row['exe_user_id']} and exe_id = {$row['exe_id']}
+                $sql = "SELECT SUM(count_question_id) as count_question_id
+                        FROM (
+                            SELECT 1 as count_question_id
+                            FROM $track_attempt a
+                            WHERE
+                              user_id = {$row['exe_user_id']} AND
+                              exe_id = {$row['exe_id']}
                             GROUP by question_id
                         ) as count_table";
                 $result_count = Database::query($sql);
@@ -156,7 +172,15 @@ switch ($action) {
             Database::query("DELETE FROM $table WHERE session_id = $session_id AND c_id = $course_id");
             //Insert all
             foreach ($new_list as $new_order_id) {
-                Database::insert($table, array('exercise_order' => $counter, 'session_id' => $session_id, 'exercise_id' => intval($new_order_id), 'c_id' => $course_id));
+                Database::insert(
+                    $table,
+                    array(
+                        'exercise_order' => $counter,
+                        'session_id' => $session_id,
+                        'exercise_id' => intval($new_order_id),
+                        'c_id' => $course_id
+                    )
+                );
                 $counter++;
             }
             Display::display_confirmation_message(get_lang('Saved'));
@@ -165,7 +189,6 @@ switch ($action) {
     case 'update_question_order':
         $course_info = api_get_course_info($course_code);
         $course_id = $course_info['real_id'];
-
         $exercise_id = isset($_REQUEST['exercise_id']) ? $_REQUEST['exercise_id'] : null;
 
         if (empty($exercise_id)) {
@@ -176,19 +199,28 @@ switch ($action) {
             $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
             $counter = 1;
             foreach ($new_question_list as $new_order_id) {
-                Database::update($TBL_QUESTIONS, array('question_order' => $counter), array('question_id = ? AND c_id = ? AND exercice_id = ? '=>array(intval($new_order_id), $course_id, $exercise_id)));
+                Database::update(
+                    $TBL_QUESTIONS,
+                    array('question_order' => $counter),
+                    array('question_id = ? AND c_id = ? AND exercice_id = ? ' => array(intval($new_order_id), $course_id, $exercise_id)))
+                ;
                 $counter++;
             }
             Display::display_confirmation_message(get_lang('Saved'));
         }
         break;
     case 'add_question_to_reminder':
+        /** @var Exercise $objExercise */
         $objExercise  = $_SESSION['objExercise'];
         if (empty($objExercise)) {
             echo 0;
             exit;
         } else {
-            $objExercise->edit_question_to_remind($_REQUEST['exe_id'], $_REQUEST['question_id'], $_REQUEST['action']);
+            $objExercise->edit_question_to_remind(
+                $_REQUEST['exe_id'],
+                $_REQUEST['question_id'],
+                $_REQUEST['action']
+            );
         }
         break;
     case 'save_exercise_by_now':
@@ -226,6 +258,7 @@ switch ($action) {
             }
 
             // Exercise information.
+            /** @var Exercise $objExercise */
             $objExercise = isset($_SESSION['objExercise']) ? $_SESSION['objExercise'] : null;
 
             // Question info.
@@ -346,7 +379,17 @@ switch ($action) {
 
                 if ($type == 'simple') {
                     // Getting old attempt in order to decrees the total score.
-                    $old_result = $objExercise->manage_answer($exe_id, $my_question_id, null, 'exercise_show', array(), false, true, false, $objExercise->selectPropagateNeg());
+                    $old_result = $objExercise->manage_answer(
+                        $exe_id,
+                        $my_question_id,
+                        null,
+                        'exercise_show',
+                        array(),
+                        false,
+                        true,
+                        false,
+                        $objExercise->selectPropagateNeg()
+                    );
 
                     // Removing old score.
                     $total_score = $total_score - $old_result['score'];
@@ -368,7 +411,19 @@ switch ($action) {
                 }
 
                 // We're inside *one* question. Go through each possible answer for this question
-                $result = $objExercise->manage_answer($exe_id, $my_question_id, $my_choice, 'exercise_result', $hot_spot_coordinates, true, false, false, $objExercise->selectPropagateNeg(), $hotspot_delineation_result, true);
+                $result = $objExercise->manage_answer(
+                    $exe_id,
+                    $my_question_id,
+                    $my_choice,
+                    'exercise_result',
+                    $hot_spot_coordinates,
+                    true,
+                    false,
+                    false,
+                    $objExercise->selectPropagateNeg(),
+                    $hotspot_delineation_result,
+                    true
+                );
 
                 //  Adding the new score.
                 $total_score += $result['score'];

+ 2 - 2
main/inc/ajax/model.ajax.php

@@ -603,7 +603,7 @@ switch ($action) {
                 'firstname', 'lastname', 'username', 'group_name', 'exe_duration', 'start_date', 'exe_date', 'score', 'status', 'lp', 'actions'
             );
         }
-        $result = get_exam_results_data($start, $limit, $sidx, $sord, $exercise_id, $where_condition);
+        $result = get_exam_results_data($start, $limit, $sidx, $sord, $exercise_id, $whereCondition);
         break;
     case 'get_hotpotatoes_exercise_results':
         $course = api_get_course_info();
@@ -613,7 +613,7 @@ switch ($action) {
         } else {
             $columns = array('exe_date',  'score', 'actions');
         }
-        $result = get_exam_results_hotpotatoes_data($start, $limit, $sidx, $sord, $hotpot_path, $where_condition); //get_exam_results_data($start, $limit, $sidx, $sord, $exercise_id, $where_condition);
+        $result = get_exam_results_hotpotatoes_data($start, $limit, $sidx, $sord, $hotpot_path, $whereCondition); //get_exam_results_data($start, $limit, $sidx, $sord, $exercise_id, $where_condition);
         break;
     case 'get_work_student_list_overview':
         if (!api_is_allowed_to_edit()) {