]> git.mjollnir.org Git - moodle.git/commitdiff
Modernised insert and update of answers (using standard functions)
authormartin <martin>
Mon, 12 Aug 2002 08:56:36 +0000 (08:56 +0000)
committermartin <martin>
Mon, 12 Aug 2002 08:56:36 +0000 (08:56 +0000)
mod/choice/lib.php
mod/choice/view.php

index 25b2083c504353c9041bbf0ea7517d00c0da08d8..502187970459d30bb299fc71cff88e7d1cf3d2f6 100644 (file)
@@ -83,28 +83,6 @@ function choice_delete_instance($id) {
 }
 
 
-function choice_add_new_to_database($choice, $answer) {
-    global $db;
-    global $USER;
-
-    $timenow = time();
-
-    $rs = $db->Execute("INSERT INTO choice_answers (choice, user, answer, timemodified)
-                        VALUES ( '$choice->id', '$USER->id', '$answer', '$timenow')");
-    return $rs;
-}
-
-function choice_update_in_database($current, $answer) {
-    global $db;
-
-    $timenow = time();
-
-    $rs = $db->Execute("UPDATE choice_answers
-                        SET answer='$answer', timemodified='$timenow' 
-                        WHERE id = '$current->id'");
-    return $rs;
-}
-
 function choice_get_answer($choice, $code) {
 // Returns text string which is the answer that matches the code
     switch ($code) {
index 3161db6d22362775ff0087eb90ad0f60ec1a8086..93dba902ec9ca65dbd0cfc1b8a4524d6653cde15 100644 (file)
 
     if (match_referer() && isset($HTTP_POST_VARS)) {    // form submitted
         $form = (object)$HTTP_POST_VARS;
+        $timenow = time();
         if ($current) {
-            if (! choice_update_in_database($current, $form->answer)) {
+            $newanswer = $current;
+            $newanswer->answer = $form->answer;
+            $newanswer->timemodified = $timenow;
+            if (! update_record("choice_answers", $newanswer)) {
                 error("Could not update your choice");
             }
             add_to_log($course->id, "choice", "update", "view.php?id=$cm->id", "$choice->id");
         } else {
-            if (! choice_add_new_to_database($choice, $form->answer)) {
+            $newanswer->choice = $choice->id;
+            $newanswer->user   = $USER->id;
+            $newanswer->answer = $form->answer;
+            $newanswer->timemodified = $timenow;
+            if (! insert_record("choice_answers", $newanswer)) {
                 error("Could not save your choice");
             }
             add_to_log($course->id, "choice", "add", "view.php?id=$cm->id", "$choice->id");