diff options
author | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2013-01-24 13:06:19 +0100 |
---|---|---|
committer | Benjamin Franzke <benjaminfranzke@googlemail.com> | 2013-01-24 14:47:06 +0100 |
commit | 588af7d081e11db69277612f196f8cb264ac1243 (patch) | |
tree | bbc8cf8078bf953c71bd1ebccccb31737bfd9d40 /sqlbox/locallib.php | |
parent | 0d94307750159d8afce745064742a97485ad9094 (diff) | |
download | sqltutor-plugin-588af7d081e11db69277612f196f8cb264ac1243.tar.gz sqltutor-plugin-588af7d081e11db69277612f196f8cb264ac1243.tar.bz2 sqltutor-plugin-588af7d081e11db69277612f196f8cb264ac1243.zip |
Store user query and if query was correct
Diffstat (limited to 'sqlbox/locallib.php')
-rw-r--r-- | sqlbox/locallib.php | 23 |
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); +} |