Browse Source

[svn r11921] update scores in lp management

Eric Marguin 18 years ago
parent
commit
838f48b61b
3 changed files with 48 additions and 34 deletions
  1. 7 4
      main/exercice/exercise_result.php
  2. 22 30
      main/mySpace/myStudents.php
  3. 19 0
      main/newscorm/learnpath.class.php

+ 7 - 4
main/exercice/exercise_result.php

@@ -27,7 +27,7 @@
 *	@package dokeos.exercise
 *	@author Olivier Brouckaert, main author
 *	@author Roan Embrechts, some refactoring
-* 	@version $Id: exercise_result.php 11595 2007-03-15 13:07:10Z elixir_julian $
+* 	@version $Id: exercise_result.php 11921 2007-04-06 15:08:29Z elixir_inter $
 *
 *	@todo	split more code up in functions, move functions to library?
 */
@@ -41,6 +41,11 @@
 include('exercise.class.php');
 include('question.class.php');
 include('answer.class.php');
+if($_GET['origin']=='learnpath')
+{
+	require_once ('../newscorm/learnpath.class.php');
+	require_once ('../newscorm/learnpathItem.class.php');
+}
 
 // answer types
 define('UNIQUE_ANSWER',	1);
@@ -814,13 +819,11 @@ if ($origin != 'learnpath')
 				$user_id = (!empty($_SESSION['_user']['id'])?$_SESSION['_user']['id']:0);
                 $lp_item = Database::get_course_table('lp_item');
                 $lp_item_view = Database::get_course_table('lp_item_view');
-                $sql2 = "UPDATE $lp_item SET max_score = '$totalWeighting'
-                        WHERE id = '$learnpath_item_id'";
-                api_sql_query($sql2,__FILE__,__LINE__);
                 $sql2 = "UPDATE $lp_item_view SET score = '$totalScore'
                         WHERE lp_item_id = '$learnpath_item_id'
                         AND lp_view_id = '".$_SESSION['scorm_view_id']."'";
                 api_sql_query($sql2,__FILE__,__LINE__);
+                $_SESSION['oLP']->save_last();
 
 }
 $csspath = "http://portal.dokeos.com/demo/main/css/default.css";

+ 22 - 30
main/mySpace/myStudents.php

@@ -460,7 +460,7 @@ if(!empty($_GET['student']))
 								INNER JOIN '.$a_infosCours['db_name'].'.'.$tbl_course_lp_view.' AS view
 									ON item_view.lp_view_id = view.id
 									AND view.lp_id = '.$a_learnpath['id'].'
-									AND view.user_id = '.$_GET['student'];
+									AND view.user_id = '.intval($_GET['student']);
 					$rs = api_sql_query($sql, __FILE__, __LINE__);
 					$total_time = mysql_result($rs, 0, 0);
 					
@@ -470,40 +470,32 @@ if(!empty($_GET['student']))
 								INNER JOIN '.$a_infosCours['db_name'].'.'.$tbl_course_lp_view.' AS view
 									ON item_view.lp_view_id = view.id
 									AND view.lp_id = '.$a_learnpath['id'].'
-									AND view.user_id = '.$_GET['student'];
+									AND view.user_id = '.intval($_GET['student']);
 					$rs = api_sql_query($sql, __FILE__, __LINE__);
 					$start_time = mysql_result($rs, 0, 0);
 					
 					
-					// get the average score in this lp (if there are exercices)
-					$score = 0;
-					$sql = 'SELECT DISTINCT path 
-							FROM '.$a_infosCours['db_name'].'.'.$tbl_course_lp_item.'
-							WHERE item_type = "quiz"
-							AND lp_id='.$a_learnpath['id'];
-					$rs = api_sql_query($sql, __FILE__,__LINE__);
-					$nb_quiz = mysql_num_rows($rs);
-					while ($quiz = Database :: fetch_array($rs))
-					{
-						$sqlScore = "SELECT  exe_result,
-									 exe_weighting
-					 				 FROM ".Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES)."
-									 WHERE exe_user_id = ".$student_id."
-					 				 AND exe_cours_id = '".Database::escape_string($_GET['course'])."'
-									 AND exe_exo_id = ".$quiz['path']."
-									 ORDER BY exe_id DESC LIMIT 0,1";
-						$rs_score = api_sql_query($sqlScore, __FILE__, __LINE__);
-						$score += mysql_result($rs_score, 0, 0) / mysql_result($rs_score, 0, 1) * 100; 
-					}
-					if($nb_quiz == 0)
-					{
-						$score = '-';
-					}
-					else
+					
+					$sql = 'SELECT id as item_id, max_score 
+							FROM '.$a_infosCours['db_name'].'.'.$tbl_course_lp_item.' AS lp_item
+							WHERE lp_id='.$a_learnpath['id'].'
+							AND item_type="quiz"';
+					$rsItems = api_sql_query($sql, __FILE__, __LINE__);
+					$total_score = $total_weighting = 0;
+					while($item = Database :: fetch_array($rsItems, 'ASSOC'))
 					{
-						$score = round($score / $nb_quiz,2).' %';
+						$sql = 'SELECT score as student_score 
+								FROM '.$a_infosCours['db_name'].'.'.$tbl_course_lp_view.' as lp_view
+								LEFT JOIN '.$a_infosCours['db_name'].'.'.$tbl_course_lp_view_item.' as lp_view_item
+									ON lp_view.id = lp_view_item.lp_view_id
+									AND lp_view_item.lp_item_id = '.$item['item_id'].'
+								WHERE lp_view.user_id = '.intval($_GET['student']).'
+								AND '.$a_learnpath['id'];
+						$rsScores = api_sql_query($sql, __FILE__, __LINE__);
+						$total_score += mysql_result($rsScores, 0, 0);
+						$total_weighting += $item['max_score'];
 					}
-					
+					$score = round($total_score / $total_weighting * 100,2);
 					
 					if($i%2==0){
 						$s_css_class="row_odd";
@@ -535,7 +527,7 @@ if(!empty($_GET['student']))
 						</td>
 						<td align="center">
 							<?php
-							if($progress > 0)
+							if($progress > 0 || $score > 0)
 							{
 							?>
 							<a href="lp_tracking.php?course=<?php echo $_GET['course'] ?>&origin=<?php echo $_GET['origin'] ?>&lp_id=<?php echo $a_learnpath['id']?>&student_id=<?php echo $a_infosUser['user_id'] ?>">

+ 19 - 0
main/newscorm/learnpath.class.php

@@ -414,6 +414,21 @@ class learnpath {
     	
     	$new_item_id = -1;
     	$id = $this->escape_string($id);
+    	
+    	if($type == 'quiz')
+    	{
+    		$sql = 'SELECT SUM(ponderation)
+					FROM '.Database :: get_course_table(TABLE_QUIZ_QUESTION).' as quiz_question
+					INNER JOIN  '.Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION).' as quiz_rel_question
+						ON quiz_question.id = quiz_rel_question.question_id
+						AND quiz_rel_question.exercice_id = '.$id;
+			$rsQuiz = api_sql_query($sql, __FILE__, __LINE__);
+			$max_score = mysql_result($rsQuiz, 0, 0);
+    	}
+    	else
+    	{
+    		$max_score = 100;
+    	}
 		
 		if($prerequisites!=0){
 			$sql_ins = "
@@ -424,6 +439,7 @@ class learnpath {
 	    			title,
 	    			description,
 	    			path,
+					max_score,
 	    			parent_item_id,
 	    			previous_item_id,
 	    			next_item_id,
@@ -436,6 +452,7 @@ class learnpath {
 	    			'" . $title . "',
 	    			'" . $description . "',
 	    			'" . $id . "',
+					'" . $max_score. "',
 	    			" . $parent . ",
 	    			" . $previous . ",
 	    			" . $next . ",
@@ -454,6 +471,7 @@ class learnpath {
 	    			title,
 	    			description,
 	    			path,
+					max_score,
 	    			parent_item_id,
 	    			previous_item_id,
 	    			next_item_id,
@@ -465,6 +483,7 @@ class learnpath {
 	    			'" . $title . "',
 	    			'" . $description . "',
 	    			'" . $id . "',
+					'" . $max_score. "',
 	    			" . $parent . ",
 	    			" . $previous . ",
 	    			" . $next . ",