Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Modernised insert and update of answers (using standard functions)

  • Loading branch information...
commit 6821bec5d73568a5e5c882c6e5bb97612baf4c30 1 parent c4016bc
martin authored
Showing with 10 additions and 24 deletions.
  1. +0 −22 mod/choice/lib.php
  2. +10 −2 mod/choice/view.php
22 mod/choice/lib.php
View
@@ -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) {
12 mod/choice/view.php
View
@@ -30,13 +30,21 @@
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");
Please sign in to comment.
Something went wrong with that request. Please try again.