. /** * Internal library of functions for module sqlbox * * All the sqlbox specific functions, needed to implement the module * logic, should go here. Never include this file from your lib.php! * * @package mod * @subpackage sqlbox * @copyright 2012 Jan Klemkow, Benjamin Franzke * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ defined('MOODLE_INTERNAL') || die(); /** * Does something really useful with the passed things * * @param array $things * @return object */ //function sqlbox_do_something_useful(array $things) { // return new stdClass(); //} function db_table_from_query($db, $query) { global $PAGE; $table = new html_table; $result = @pg_query($db, $query); if (!$result) print_error('queryfailed', 'sqlbox', $PAGE->url, pg_last_error($db)); $table = new html_table; $n = pg_num_fields($result); for ($i = 0; $i < $n; $i++) $table->head[] = pg_field_name($result, $i); $table->align = $n > 0 ? array_fill(0, $n, 'left') : array(); while ($row = pg_fetch_row($result)) $table->data[] = $row; return $table; } function sqlbox_submit_response($query, $sqlbox, $correct, $userid) { global $DB, $CFG; // 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); }