From bf9f02b4d0a296a5fa0bebe91a7699a6b9a8f12b Mon Sep 17 00:00:00 2001 From: Julio Montoya Date: Tue, 19 Aug 2008 20:29:30 +0200 Subject: [PATCH] [svn r16025] Bug when deleting attempts in track_e_attempt and track_e_exercices fixed. --- main/exercice/exercise_result.php | 25 +++++++++----- main/inc/lib/events.lib.inc.php | 57 +++++++++++++++++++------------ 2 files changed, 53 insertions(+), 29 deletions(-) diff --git a/main/exercice/exercise_result.php b/main/exercice/exercise_result.php index 0b53282f46..2034f7fd83 100644 --- a/main/exercice/exercise_result.php +++ b/main/exercice/exercise_result.php @@ -29,7 +29,7 @@ * @author Olivier Brouckaert, main author * @author Roan Embrechts, some refactoring * @author Julio Montoya Armas switchable fill in blank option added -* @version $Id: exercise_result.php 16000 2008-08-15 04:26:07Z juliomontoya $ +* @version $Id: exercise_result.php 16025 2008-08-19 18:29:30Z juliomontoya $ * * @todo split more code up in functions, move functions to library? */ @@ -427,10 +427,20 @@ $exerciseTitle=api_parse_tex($exerciseTitle); // added by Priya Saini - $sql = "select max(exe_Id) as id from ".$TBL_TRACK_EXERCICES; - $res = api_sql_query($sql, __FILE__, __LINE__); - $exeId =mysql_result($res,0,"id"); - $exeId=$exeId+1; + //$sql = "select max(exe_Id) as id from ".$TBL_TRACK_EXERCICES; + + /* + $sql = "select max(exe_Id) as id from ".$TBL_TRACK_ATTEMPT; + $res = api_sql_query($sql, __FILE__, __LINE__); + $exeId =mysql_result($res,0,"id"); + $exeId=$exeId+1; + */ + + if($_configuration['tracking_enabled']) + { + // Create an empty exercise + $exeId= create_event_exercice(); + } $counter=0; foreach($questionList as $questionId) @@ -1046,9 +1056,8 @@ $exerciseTitle=api_parse_tex($exerciseTitle); if($_configuration['tracking_enabled']) { - //include(api_get_path(LIBRARY_PATH).'events.lib.inc.php'); - event_exercice($objExercise->selectId(),$totalScore,$totalWeighting,$answer,$question_id); - + // Updates the empty exercise + update_event_exercice($exeId, $objExercise->selectId(),$totalScore,$totalWeighting,$answer,$question_id); } if($objExercise->results_disabled) diff --git a/main/inc/lib/events.lib.inc.php b/main/inc/lib/events.lib.inc.php index 121042be28..7cc97b66bf 100644 --- a/main/inc/lib/events.lib.inc.php +++ b/main/inc/lib/events.lib.inc.php @@ -1,4 +1,4 @@ - + * @author Julio Montoya * @desc Record result of user when an exercice was done */ -function event_exercice($exo_id, $score, $weighting) +function update_event_exercice($exeid,$exo_id, $score, $weighting) { - global $_configuration, $_user, $_cid; - $TABLETRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); - - // if tracking is disabled record nothing - if (!$_configuration['tracking_enabled']) + if ($exeid!='') { - return 0; + $TABLETRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); + $reallyNow = time(); + $sql = "UPDATE $TABLETRACK_EXERCICES SET + exe_exo_id = '".$exo_id."', + exe_result = '".$score."', + exe_weighting = '".$weighting."', + exe_date= FROM_UNIXTIME(".$reallyNow.") + WHERE exe_id = '".$exeid."'"; + $res = @api_sql_query($sql,__FILE__,__LINE__); + return $res; } + else + return false; +} +/** + * This function creates an empty Exercise in STATISTIC_TRACK_E_EXERCICES table. + * After that in exercise_result.php we call the update_event_exercice() to update the exercise + * @return $id the last id registered + * @author Julio Montoya + * @desc Record result of user when an exercice was done +*/ +function create_event_exercice() +{ + global $_user, $_cid; + $TABLETRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES); $reallyNow = time(); if ($_user['user_id']) { @@ -442,26 +463,20 @@ function event_exercice($exo_id, $score, $weighting) $sql = "INSERT INTO $TABLETRACK_EXERCICES ( exe_user_id, - exe_cours_id, - exe_exo_id, - exe_result, - exe_weighting, - exe_date - ) - + exe_cours_id + ) VALUES ( ".$user_id.", - '".$_cid."', - '".$exo_id."', - '".$score."', - '".$weighting."', - FROM_UNIXTIME(".$reallyNow.") + '".$_cid."' )"; $res = @api_sql_query($sql,__FILE__,__LINE__); - return $res; + $id= Database::get_last_insert_id(); + return $id; } + + /** * Record an event for this attempt at answering an exercise * @param float Score achieved