summaryrefslogtreecommitdiff
path: root/sqlbox/locallib.php
diff options
context:
space:
mode:
Diffstat (limited to 'sqlbox/locallib.php')
-rw-r--r--sqlbox/locallib.php23
1 files changed, 23 insertions, 0 deletions
diff --git a/sqlbox/locallib.php b/sqlbox/locallib.php
index f335b9a..1646bbf 100644
--- a/sqlbox/locallib.php
+++ b/sqlbox/locallib.php
@@ -55,3 +55,26 @@ function db_table_from_query($db, $query) {
return $table;
}
+
+function sqlbox_submit_response($query, $sqlbox, $correct, $userid) {
+ global $DB, $CFG;
+ require_once($CFG->libdir.'/completionlib.php');
+
+ // TODO: Add timemodified
+ //
+ $current = $DB->get_record('sqlbox_solutions', array('sqlboxid' => $sqlbox->id, 'userid' => $userid));
+ if ($current) {
+ $newsolution = $current;
+ } else {
+ $newsolution = new stdClass();
+ $newsolution->userid = $userid;
+ $newsolution->sqlboxid = $sqlbox->id;
+ }
+ $newsolution->query = $query;
+ $newsolution->correct = $correct;
+
+ if ($current)
+ $DB->update_record("sqlbox_solutions", $newsolution);
+ else
+ $DB->insert_record("sqlbox_solutions", $newsolution);
+}