Browse Source

[svn r17489] dokeos: don't update exercise table everytime a position reenter is needed

separate a memeber function that do that(reentering positions), and call it from question create flow instead of calling Exercise::save() and update
Marco Villegas 16 years ago
parent
commit
ec603c5fb0
2 changed files with 18 additions and 12 deletions
  1. 15 9
      main/exercice/exercise.class.php
  2. 3 3
      main/exercice/question.class.php

+ 15 - 9
main/exercice/exercise.class.php

@@ -25,7 +25,7 @@
 *	Exercise class: This class allows to instantiate an object of type Exercise
 *	@package dokeos.exercise
 * 	@author Olivier Brouckaert
-* 	@version $Id: exercise.class.php 17311 2008-12-16 00:53:24Z cfasanando $
+* 	@version $Id: exercise.class.php 17489 2008-12-31 15:47:30Z marvil07 $
 */
 
 
@@ -513,16 +513,22 @@ class Exercise
 		}
 
 		// updates the question position
-		foreach($this->questionList as $position=>$questionId)
-		{ 
-			//$sql="UPDATE $TBL_QUESTIONS SET position='".Database::escape_string($position)."' WHERE id='".Database::escape_string($questionId)."'";
-			$sql="UPDATE $TBL_QUIZ_QUESTION SET question_order='".Database::escape_string($position)."' " .
-				 "WHERE question_id='".Database::escape_string($questionId)."' and exercice_id='".Database::escape_string($id)."'";
-			api_sql_query($sql,__FILE__,__LINE__);
-		
-		}
+        $this->update_question_positions();
 	}
 
+    function update_question_positions() {
+    	// updates the question position
+        $TBL_QUIZ_QUESTION= Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
+        foreach($this->questionList as $position=>$questionId)
+        {
+            //$sql="UPDATE $TBL_QUESTIONS SET position='".Database::escape_string($position)."' WHERE id='".Database::escape_string($questionId)."'";
+            $sql="UPDATE $TBL_QUIZ_QUESTION SET question_order='".Database::escape_string($position)."' " .
+                 "WHERE question_id='".Database::escape_string($questionId)."' and exercice_id=".Database::escape_string($this->id)."";
+            api_sql_query($sql,__FILE__,__LINE__);
+
+        }
+    }
+
 	/**
 	 * moves a question up in the list
 	 *

+ 3 - 3
main/exercice/question.class.php

@@ -1,4 +1,4 @@
-<?php // $Id: question.class.php 16879 2008-11-23 05:14:43Z yannoo $
+<?php // $Id: question.class.php 17489 2008-12-31 15:47:30Z marvil07 $
  
 /*
 ==============================================================================
@@ -28,7 +28,7 @@
 *	File containing the Question class.
 *	@package dokeos.exercise
 * 	@author Olivier Brouckaert
-* 	@version $Id: question.class.php 16879 2008-11-23 05:14:43Z yannoo $
+* 	@version $Id: question.class.php 17489 2008-12-31 15:47:30Z marvil07 $
 */
 
 
@@ -858,7 +858,7 @@ abstract class Question
 
 	    // modify the exercise
 	    $objExercise->addToList($this -> id);
-	    $objExercise->save();
+        $objExercise->update_question_positions();
 
 	}