Browse Source

[svn r11058] Remove all results in stats tables when deleting an exercice

Julian Prud'homme 18 years ago
parent
commit
0f0246fa10
3 changed files with 45 additions and 8 deletions
  1. 2 2
      main/exercice/exercice.php
  2. 42 6
      main/exercice/exercise.class.php
  3. 1 0
      main/inc/lib/database.lib.php

+ 2 - 2
main/exercice/exercice.php

@@ -24,7 +24,7 @@
 *	@author Olivier Brouckaert, original author
 *	@author Denes Nagy, HotPotatoes integration
 *	@author Wolfgang Schneider, code/html cleanup
-* 	@version $Id: exercice.php 11057 2007-02-05 08:56:17Z elixir_julian $
+* 	@version $Id: exercice.php 11058 2007-02-05 13:25:41Z elixir_julian $
 */
 
 
@@ -447,7 +447,7 @@ if($show == 'test'){
  $rowi = mysql_result($sqlresult,0);
  echo $rowi.' Questions'; ?> </td>
        <td width="12%" align="center"><a href="admin.php?exerciseId=<?php echo $row[id]; ?>"><img src="../img/wizard_small.gif" border="0" title="<?php echo htmlentities(get_lang('Build')); ?>" alt="<?php echo htmlentities(get_lang('Build')); ?>" /></a>
-    <a href="exercice.php?choice=delete&exerciseId=<?php echo $row[id]; ?>" onclick="javascript:if(!confirm('<?php echo addslashes(htmlentities(get_lang('areYouSure'))); echo $row['title']; echo "?"; ?>')) return false;"> <img src="../img/delete.gif" border="0" alt="<?php echo htmlentities(get_lang('Delete')); ?>" /></a>
+    <a href="exercice.php?choice=delete&exerciseId=<?php echo $row[id]; ?>" onclick="javascript:if(!confirm('<?php echo addslashes(htmlentities(get_lang('AreYouSureToDelete'))); echo " ".$row['title']; echo "?"; ?>')) return false;"> <img src="../img/delete.gif" border="0" alt="<?php echo htmlentities(get_lang('Delete')); ?>" /></a>
     <?php
 				// if active
 				if($row['active'])

+ 42 - 6
main/exercice/exercise.class.php

@@ -22,7 +22,7 @@
 *	Exercise class: This class allows to instantiate an object of type Exercise
 *	@package dokeos.exercise
 * 	@author Olivier Brouckaert
-* 	@version $Id: exercise.class.php 10989 2007-01-30 08:21:34Z elixir_julian $
+* 	@version $Id: exercise.class.php 11058 2007-02-05 13:25:41Z elixir_julian $
 */
 
 
@@ -587,16 +587,52 @@ class Exercise
 	 */
 	function delete()
 	{
-		$TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
+		global $_user;
+		global $_course;
+		
+		$TBL_EXERCICE_TEST_QUESTIONS = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
+		$TBL_EXERCICE_ANSWERS = Database::get_course_table(TABLE_QUIZ_ANSWER);
+		$TBL_EXERCICE_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
 		$TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
+		
+		$TBL_EXERCICES_RESULTS = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
+		$TBL_EXERCICES_ATTEMPTS = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
 
 		$id=$this->id;
-
-		$sql="DELETE FROM $TBL_EXERCICE_QUESTION WHERE exercice_id='$id'";
-		api_sql_query($sql,__FILE__,__LINE__);
-
+		
+		//COURSE TABLES
 		$sql="DELETE FROM $TBL_EXERCICES WHERE id='$id'";
 		api_sql_query($sql,__FILE__,__LINE__);
+		
+		$sql="SELECT question_id FROM $TBL_EXERCICE_TEST_QUESTIONS WHERE exercice_id='$id'";
+		$result=api_sql_query($sql,__FILE__,__LINE__);
+		
+		while($a_test_questions=mysql_fetch_array($result)){
+			$question_id=$a_test_questions["question_id"];
+			
+			$sql="DELETE FROM $TBL_EXERCICE_QUESTIONS WHERE id='$question_id'";
+			api_sql_query($sql,__FILE__,__LINE__);
+			
+			$sql="DELETE FROM $TBL_EXERCICE_ANSWERS WHERE question_id='$question_id'";
+			api_sql_query($sql,__FILE__,__LINE__);
+			
+		}
+		
+		$sql="DELETE FROM $TBL_EXERCICE_TEST_QUESTIONS WHERE exercice_id='$id'";
+		api_sql_query($sql,__FILE__,__LINE__);
+		
+		//STATS TABLE
+		
+		$sql="SELECT exe_id FROM $TBL_EXERCICES_RESULTS WHERE exe_exo_id='$id' and exe_cours_id='".$_course["official_code"]."'";
+		$result=api_sql_query($sql,__FILE__,__LINE__);
+		$exercice_id=mysql_result($result,0,'exe_id');
+		
+		$sql="DELETE FROM $TBL_EXERCICES_ATTEMPTS WHERE exe_id='$exercice_id' AND question_id='$question_id'";
+		api_sql_query($sql,__FILE__,__LINE__);
+		
+		$sql="DELETE FROM $TBL_EXERCICES_RESULTS WHERE exe_exo_id='$id' AND exe_cours_id='".$_course["official_code"]."'";
+		api_sql_query($sql,__FILE__,__LINE__);
+		
 	}
 
 	/**

+ 1 - 0
main/inc/lib/database.lib.php

@@ -71,6 +71,7 @@ define('TABLE_STATISTIC_TRACK_E_ONLINE', 'track_e_online');
 define('TABLE_STATISTIC_TRACK_E_HOTPOTATOES', 'track_e_hotpotatoes');
 define('TABLE_STATISTIC_TRACK_E_COURSE_ACCESS', 'track_e_course_access');
 define('TABLE_STATISTIC_TRACK_E_EXERCICES', 'track_e_exercices');
+define('TABLE_STATISTIC_TRACK_E_ATTEMPT', 'track_e_attempt');
 
 //scorm database tables
 define('TABLE_SCORM_MAIN', 'scorm_main');