Browse Source

[svn r16969] minor - changes in logic - allows correct view view flat(forum,exercises,works)

Isaac Flores 16 years ago
parent
commit
515f2018f4

+ 42 - 29
main/gradebook/lib/be/exerciselink.class.php

@@ -113,35 +113,50 @@ class ExerciseLink extends AbstractLink
 	 */
     public function calc_score($stud_id = null) {
     	$tbl_stats = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
-    	$sql = 'SELECT * FROM '.$tbl_stats
-    			." WHERE exe_cours_id = '".$this->get_course_code()."'"
-    			.' AND exe_exo_id = '.$this->get_ref_id();
-    	
-    	if (isset($stud_id)) {
-     	$sql .= ' AND exe_user_id = '.$stud_id;  		
-    	}
-    	// order by id, that way the student's first attempt is accessed first
-		$sql .= ' ORDER BY exe_id';
-
-    	$scores = api_sql_query($sql, __FILE__, __LINE__);
-
+    	$tbl_stats_e_attempt_recording = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);  
 		// for 1 student
-    	if (isset($stud_id)) {
-    		if ($data=Database::fetch_array($scores)) {
-    			return array ($data['exe_result'], $data['exe_weighting']);    			
-    		} else {
-     			return null;   			
-    		}
-
-    	} else {// all students -> get average
+    	if (isset($stud_id))
+    	{    			
+    		$sql = "SELECT DISTINCT  e.exe_id, exe_result, exe_weighting, exe_user_id
+					FROM $tbl_stats  as e INNER JOIN 
+					$tbl_stats_e_attempt_recording as r
+					ON (e.exe_id =r.exe_id)
+					WHERE e.exe_cours_id = '".$this->get_course_code()."'AND					
+					e.exe_id = '".$this->get_ref_id()."'  AND author != ''  AND exe_user_id = '$stud_id' ORDER BY  e.exe_id DESC ";
+			$scores = api_sql_query($sql, __FILE__, __LINE__);
+    		
+    		if ($data=mysql_fetch_array($scores))
+    		{	
+    			return array ($data['exe_result'], $data['exe_weighting']);
+       		}
+    		else
+    			return null;
+    	}    	
+    	// all students -> get average
+    	else
+    	{
+    		// normal way of getting the info
+		
+			$sql = "SELECT DISTINCT  e.exe_id, exe_result, exe_weighting, exe_user_id
+				FROM $tbl_stats  as e INNER JOIN 
+				$tbl_stats_e_attempt_recording as r
+				ON (e.exe_id =r.exe_id)
+				WHERE e.exe_cours_id = '".$this->get_course_code()."'AND					
+				e.exe_exo_id = '".$this->get_ref_id()."'  AND author != ''  ORDER BY  e.exe_id DESC ";
+				    						
+	    	$scores = api_sql_query($sql, __FILE__, __LINE__);
+
     		$students=array();  // user list, needed to make sure we only
     							// take first attempts into account
 			$rescount = 0;
 			$sum = 0;
 
-			while ($data=Database::fetch_array($scores)) {
-				if (!(array_key_exists($data['exe_user_id'],$students))) {
-					if ($data['exe_weighting'] != 0) {
+			while ($data=mysql_fetch_array($scores))
+			{
+				if (!(array_key_exists($data['exe_user_id'],$students)))
+				{
+					if ($data['exe_weighting'] != 0)
+					{
 						$students[$data['exe_user_id']] = $data['exe_result'];
 						$rescount++;
 						$sum += ($data['exe_result'] / $data['exe_weighting']);
@@ -149,12 +164,10 @@ class ExerciseLink extends AbstractLink
 				}
 			}
 
-			if ($rescount == 0) {
-				return null;				
-			} else {
-				return array ($sum , $rescount);				
-			}
-
+			if ($rescount == 0)
+				return null;
+			else
+				return array ($sum , $rescount);
     	}
     }
     

+ 3 - 3
main/gradebook/lib/be/studentpublicationlink.class.php

@@ -24,7 +24,7 @@
 */
 /**
  * Gradebook link to student publication item
- * @author Bert Steppé
+ * @author Bert Stepp�
  * @package dokeos.gradebook
  */
 class StudentPublicationLink extends AbstractLink
@@ -154,7 +154,7 @@ class StudentPublicationLink extends AbstractLink
 		$query = api_sql_query($sql,__FILE__,__LINE__);
 		$assignment = Database::fetch_array($query);
 
-    	if(Database::num_rows($assignment)==0) {
+    	if(count($assignment)==0) {
     		 $v_assigment_id ='0';
     	} else { 
     		 $v_assigment_id = $assignment['id'];
@@ -175,7 +175,7 @@ class StudentPublicationLink extends AbstractLink
     		if ($data=Database::fetch_array($scores)) {
      			return array ($data['qualification'], $assignment['qualification']);   			
     		} else {
-     			return null;   			
+     			return '';   			
     		}
     	} else {
     		$students=array();  // user list, needed to make sure we only