Browse Source

Fixed bug by which certificates were not always showing the right score although the students did succeed to the evaluation tests (fixes #2342)

ywarnier 14 years ago
parent
commit
de538aff42

+ 2 - 1
main/gradebook/lib/be/category.class.php

@@ -415,7 +415,8 @@ class Category implements GradebookItem
 	 */
 	public function is_certificate_available($user_id) {
 		$score = $this->calc_score($user_id);
-		if($score >= $this->certificate_min_score) {
+        $certification_score = ($score[0]/$score[1])*100; //get a percentage score to compare to minimum certificate score
+		if($certification_score >= $this->certificate_min_score) {
 			return true;
 		}
 		return false;

+ 4 - 4
main/gradebook/lib/be/exerciselink.class.php

@@ -92,8 +92,8 @@ class ExerciseLink extends AbstractLink
     public function calc_score($stud_id = null) {
     	$tbl_stats = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
     	$tbl_stats_e_attempt_recording = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);
-
-		$sql = 'SELECT * FROM '.$tbl_stats.' WHERE exe_exo_id = '.(int)$this->get_ref_id().' AND orig_lp_id = 0 AND orig_lp_item_id = 0';
+        //the following query should be similar (in conditions) to the one used in exercice/exercice.php, look for note-query-exe-results marker
+		$sql = 'SELECT * FROM '.$tbl_stats.' WHERE exe_exo_id = '.(int)$this->get_ref_id().' AND orig_lp_id = 0 AND orig_lp_item_id = 0  AND status <>\'incomplete\'';
 
 		if (isset($stud_id)){
 
@@ -102,8 +102,8 @@ class ExerciseLink extends AbstractLink
     		$course_code_exe = $this->get_course_code();
     		$sql .= ' AND exe_cours_id="'.$course_code_exe.'" AND exe_user_id = '."'".$stud_id."'";
     	}
-		$sql .= ' ORDER BY exe_id DESC';		
-		$scores = Database::query($sql);
+		$sql .= ' ORDER BY exe_id DESC';
+        $scores = Database::query($sql);
     	if (isset($stud_id)) {
     		// for 1 student
     		if ($data=Database::fetch_array($scores)) {

+ 1 - 0
main/gradebook/lib/fe/flatviewtable.class.php

@@ -160,6 +160,7 @@ class FlatViewTable extends SortableTable
 		$img_file = '';
 
 		if ($this->datagen->get_total_items_count()>0 && $total_users > 0 ) {
+            //remove lastname and firstname columns (which are meant for the table, not the graph)
 			array_shift($header_name);
 			array_shift($header_name);
 

+ 19 - 11
main/gradebook/lib/fe/gradebooktable.class.php

@@ -87,6 +87,9 @@ class GradebookTable extends SortableTable
 	 * Function used by SortableTable to generate the data to display
 	 */
 	function get_table_data($from = 1) {
+        //variables load in index.php
+        global $my_score_in_gradebook, $certificate_min_score;
+        $scoretotal = 0;
 		// determine sorting type
 		$col_adjust = (api_is_allowed_to_create_course() ? 1 : 0);
 		switch ($this->column) {
@@ -112,7 +115,7 @@ class GradebookTable extends SortableTable
 		} else {
 			$sorting |= GradebookDataGenerator :: GDG_SORT_ASC;
 		}
-		//status de user in course
+		//status of user in course
 	    $user_id=api_get_user_id();
 		$course_code=api_get_course_id();
 		$status_user=api_get_status_of_user_in_course ($user_id,$course_code);
@@ -123,10 +126,13 @@ class GradebookTable extends SortableTable
 		$weight_total_links = 0;
 
 		foreach ($data_array as $data) {
+            // list of items inside the gradebook (exercises, lps, fora, etc)
 			$row = array ();
 			$item = $data[0];
 			$id = $item->get_id();
-			if (empty($_GET['selectcat']) ) {
+            //the following condition seems strange to me - YW 20110421
+            //GET['selectcat'] is the main gradebook. When defined, it means we are looking at the whole stuff instead of one sub-element (or something like that?)
+			if (empty($_GET['selectcat']) ) { //if not particular gradebook item was selected, take the certificate score for the current item
 				$certificate_min_score = $this->build_certificate_min_score($item);
 			}
 			//if the item is invisible, wrap it in a span with class invisible
@@ -146,7 +152,7 @@ class GradebookTable extends SortableTable
 			} else {
 
 				if (empty($_GET['selectcat'])) {
-				// generating the total score for a course
+				    // generating the total score for a course
 				    $stud_id= api_get_user_id();
 					$cats_course = Category :: load ($id, null, null, null, null, null, false);
 					$alleval_course= $cats_course[0]->get_evaluations($stud_id,true);
@@ -163,16 +169,18 @@ class GradebookTable extends SortableTable
 								$item_total+=$item->get_weight();
 					}
 					$item_value = number_format($item_value, 2, '.', ' ');
-					$cattotal = Category :: load($id);
-					$scoretotal= $cattotal[0]->calc_score(api_get_user_id());
-					$scoretotal_display = (isset($scoretotal)? round($scoretotal[0],2).'/'.round($scoretotal[1],2).' ('.round(($scoretotal[0] / $scoretotal[1]) * 100,2) . ' %)': '-');
+                    $cattotal = Category :: load($id);
+                    $scoretotal= $cattotal[0]->calc_score(api_get_user_id());
+                    $scoretotal_display = (isset($scoretotal)? round($scoretotal[0],2).'/'.round($scoretotal[1],2).' ('.round(($scoretotal[0] / $scoretotal[1]) * 100,2) . ' %)': '-');
 					$row[] = $item_value;
 
 				} else {
+                    $cattotal = Category :: load($_GET['selectcat']);
+                    $scoretotal= $cattotal[0]->calc_score(api_get_user_id());
 			   		$row[] = $invisibility_span_open . $data[3] . $invisibility_span_close;
 			   	}
 			}
-				$row[] = $invisibility_span_open . str_replace(' ','&nbsp;',$data[4]) . $invisibility_span_close;
+    		$row[] = $invisibility_span_open . str_replace(' ','&nbsp;',$data[4]) . $invisibility_span_close;
 
 			//admins get an edit column
 			if (api_is_allowed_to_edit(null, true)) {
@@ -189,11 +197,10 @@ class GradebookTable extends SortableTable
 						$row[] = $value_data;
 					}
 				}
-				//variables load in index.php
-				global $my_score_in_gradebook, $certificate_min_score, $item_value, $certificate_min_score;
 
 				if (empty($_GET['selectcat'])) {
-					if (isset($certificate_min_score) && (int)$item_value >= (int)$certificate_min_score) {
+                    //$certification_score = ($scoretotal[0]/$scoretotal[1])*100;
+					if (isset($certificate_min_score) && $item_value >= $certificate_min_score) {
 						$certificates = '<a href="'.api_get_path(WEB_CODE_PATH) .'gradebook/'.$_SESSION['gradebook_dest'].'?export_certificate=yes&cat_id='.$id.'" target="_blank">
 										 <img src="'.api_get_path(WEB_CODE_PATH) . 'img/logo.gif" /></a>&nbsp;'.$scoretotal_display;
 
@@ -213,7 +220,8 @@ class GradebookTable extends SortableTable
 					}
 					$row[] = $certificates;
 				} else {
-					if (isset($certificate_min_score) && (int)$item_value >= (int)$certificate_min_score) {
+                    //$certification_score = ($scoretotal[0]/$scoretotal[1])*100;
+					if (isset($certificate_min_score) && $item_value >= $certificate_min_score) {
 						//register gradebook certificate
 						$current_user_id=api_get_user_id();
 						register_user_info_about_certificate($_GET['selectcat'],$current_user_id,$my_score_in_gradebook,api_get_utc_datetime());