$attemptid = required_param('attemptid', PARAM_INT);
// get attempt, hotpot, course and course_module records
- if (! $attempt = get_record("hotpot_attempts", "id", $attemptid)) {
+ if (! $attempt = $DB->get_record("hotpot_attempts", array("id"=>$attemptid))) {
print_error('invalidattemptid', 'hotpot');
}
if ($attempt->userid != $USER->id) {
print_error("invaliduserid");
}
- if (! $hotpot = get_record("hotpot", "id", $attempt->hotpot)) {
+ if (! $hotpot = $DB->get_record("hotpot", array("id"=>$attempt->hotpot))) {
print_error('invalidhotpotid', 'hotpot');
}
- if (! $course = get_record("course", "id", $hotpot->course)) {
+ if (! $course = $DB->get_record("course", array("id"=>$hotpot->course))) {
print_error('invalidcourseid');
}
if (! $cm = get_coursemodule_from_instance("hotpot", $hotpot->id, $course->id)) {
}
// check if this is the second (or subsequent) click
- if (get_field("hotpot_attempts", "timefinish", "id", $attempt->id)) {
+ if ($DB->get_field("hotpot_attempts", "timefinish", array("id"=>$attempt->id))) {
if ($hotpot->clickreporting==HOTPOT_YES) {
// add attempt record for each form submission
// records are linked via the "clickreportid" field
// update status in previous records in this group
- set_field("hotpot_attempts", "status", $attempt->status, "clickreportid", $attempt->clickreportid);
+ $DB->set_field("hotpot_attempts", "status", $attempt->status, array("clickreportid"=>$attempt->clickreportid));
// add new attempt record
unset ($attempt->id);
- $attempt->id = insert_record("hotpot_attempts", $attempt);
+ $attempt->id = $DB->insert_record("hotpot_attempts", $attempt);
if (empty($attempt->id)) {
print_error('cannotinsertattempt', 'hotpot', $next_url, $DB->get_last_error());
// add attempt details record, if necessary
if (!empty($attempt->details)) {
- unset($details);
+ $details = new object();
$details->attempt = $attempt->id;
$details->details = $attempt->details;
- if (! insert_record("hotpot_details", $details, false)) {
+ if (! $DB->insert_record("hotpot_details", $details, false)) {
print_error('cannotinsertattempt', 'hotpot', $next_url, $DB->get_last_error());
}
}
} else {
// remove previous responses for this attempt, if required
// (N.B. this does NOT remove the attempt record, just the responses)
- delete_records("hotpot_responses", "attempt", $attempt->id);
+ $DB->delete_records("hotpot_responses", array("attempt"=>$attempt->id));
}
}
hotpot_add_attempt_details($attempt);
// add slashes again, so the details can be added to the database
- $attempt->details = addslashes($attempt->details);
+ $attempt->details = $attempt->details;
// update the attempt record
- if (! update_record("hotpot_attempts", $attempt)) {
+ if (! $DB->update_record("hotpot_attempts", $attempt)) {
print_error('cannotupdateattempt', 'hotpot', $next_url, $DB->get_last_error());
}
hotpot_update_grades($hotpot, $attempt->userid);
// get previous attempt details record, if any
- $details_exist = record_exists("hotpot_details", "attempt", $attempt->id);
+ $details_exist = $DB->record_exists("hotpot_details", array("attempt"=>$attempt->id));
// delete/update/add the attempt details record
if (empty($attempt->details)) {
if ($details_exist) {
- delete_records("hotpot_details", "attempt", $attempt->id);
+ $DB->delete_records("hotpot_details", array("attempt"=>$attempt->id));
}
} else {
if ($details_exist) {
- set_field("hotpot_details", "details", $attempt->details, "attempt", $attempt->id);
+ $DB->set_field("hotpot_details", "details", $attempt->details, array("attempt"=>$attempt->id));
} else {
- unset($details);
+ $details = new object();
$details->attempt = $attempt->id;
$details->details = $attempt->details;
- if (! insert_record("hotpot_details", $details)) {
+ if (! $DB->insert_record("hotpot_details", $details)) {
print_error('cannotinsertattempt', 'hotpot', $next_url, $DB->get_last_error());
}
}
function hotpot_get_next_cm(&$cm) {
// gets the next module in this section of the course
// that is the same type of module as the current module
+ global $DB;
$next_mod = false;
// get a list of $ids of modules in this section
- if ($ids = get_field('course_sections', 'sequence', 'id', $cm->section)) {
+ if ($ids = $DB->get_field('course_sections', 'sequence', array('id'=>$cm->section))) {
$found = false;
$ids = explode(',', $ids);
foreach ($ids as $id) {
- if ($found && ($cm->module==get_field('course_modules', 'module', 'id', $id))) {
+ if ($found && ($cm->module==$DB->get_field('course_modules', 'module', array('id'=>$id)))) {
$next_mod = $id;
break;
} else if ($cm->id==$id) {
return $next_mod;
}
function hotpot_set_attempt_details(&$attempt) {
- global $CFG, $HOTPOT_QUIZTYPE;
+ global $CFG, $HOTPOT_QUIZTYPE, $DB;
// optional_param('showallquestions', 0, PARAM_INT);
}
// get previous responses to this question (if any)
- $records = get_records_sql("
+ $records = $DB->get_records_sql("
SELECT
r.*
FROM
- {$CFG->prefix}hotpot_attempts a,
- {$CFG->prefix}hotpot_questions q,
- {$CFG->prefix}hotpot_responses r
+ {hotpot_attempts} a,
+ {hotpot_questions} q,
+ {hotpot_responses} r
WHERE
- a.clickreportid = $attempt->clickreportid AND
+ a.clickreportid = ? AND
a.id = r.attempt AND
r.question = q.id AND
- q.name = '$questionname' AND
- q.hotpot = $attempt->hotpot
+ q.name = ? AND
+ q.hotpot = ?
ORDER BY
a.timefinish
- ");
+ ", array($attempt->clickreportid, $questionname, $attempt->hotpot));
if ($records) {
foreach ($records as $record) {
//
//-----------------------------------------------------------
function hotpot_backup_mods($bf, $preferences) {
- global $CFG;
+ global $DB;
$status = true;
//Iterate over hotpot table
- $hotpots = get_records ("hotpot","course",$preferences->backup_course,"id");
+ $hotpots = $DB->get_records ("hotpot", array("course"=>$preferences->backup_course), "id");
if ($hotpots) {
foreach ($hotpots as $hotpot) {
if (function_exists('backup_mod_selected')) {
$level = 3;
$status = true;
$table = 'hotpot';
- $select = "course=$preferences->backup_course AND id='$instance'";
+ $select = "course=? AND id=?";
+ $params = array($preferences->backup_course, $instance);
$records_tag = '';
$records_tags = array();
$record_tag = 'MOD';
}
return hotpot_backup_records(
$bf, $status, $level,
- $table, $select,
+ $table, $select, $params,
$records_tag, $records_tags,
$record_tag, $record_tags,
$excluded_tags, $more_backup
function hotpot_backup_attempts($bf, &$parent, $level, $status) {
// $parent is a reference to a hotpot record
$table = 'hotpot_attempts';
- $select = "hotpot=$parent->id";
+ $select = "hotpot=?";
+ $params = array($parent->id);
$records_tag = 'ATTEMPT_DATA';
$records_tags = array();
$record_tag = 'ATTEMPT';
$excluded_tags = array('hotpot');
return hotpot_backup_records(
$bf, $status, $level,
- $table, $select,
+ $table, $select, $params,
$records_tag, $records_tags,
$record_tag, $record_tags,
$excluded_tags, $more_backup
function hotpot_backup_details($bf, &$parent, $level, $status) {
// $parent is a reference to an attempt record
$table = 'hotpot_details';
- $select = "attempt=$parent->id";
+ $select = "attempt=?";
+ $params = array($parent->id);
$records_tag = '';
$records_tags = array();
$record_tag = '';
$excluded_tags = array('id','attempt');
return hotpot_backup_records(
$bf, $status, $level,
- $table, $select,
+ $table, $select, $params,
$records_tag, $records_tags,
$record_tag, $record_tags,
$excluded_tags, $more_backup
function hotpot_backup_responses($bf, &$parent, $level, $status) {
// $parent is a reference to an attempt record
$table = 'hotpot_responses';
- $select = "attempt=$parent->id";
+ $select = "attempt=?";
+ $params = array($parent->id);
$records_tag = 'RESPONSE_DATA';
$records_tags = array();
$record_tag = 'RESPONSE';
$excluded_tags = array('id','attempt');
return hotpot_backup_records(
$bf, $status, $level,
- $table, $select,
+ $table, $select, $params,
$records_tag, $records_tags,
$record_tag, $record_tags,
$excluded_tags, $more_backup
function hotpot_backup_questions($bf, &$parent, $level, $status) {
// $parent is a reference to an hotpot record
$table = 'hotpot_questions';
- $select = "hotpot=$parent->id";
+ $select = "hotpot=?";
+ $params = array($parent->id);
$records_tag = 'QUESTION_DATA';
$records_tags = array();
$record_tag = 'QUESTION';
$ids = implode(',', $ids);
$table = 'hotpot_strings';
$select = "id IN ($ids)";
+ $params = array();
$records_tag = 'STRING_DATA';
$records_tags = array();
$record_tag = 'STRING';
$excluded_tags = array('');
$status = hotpot_backup_records(
$bf, $status, $level,
- $table, $select,
+ $table, $select, $params,
$records_tag, $records_tags,
$record_tag, $record_tags,
$excluded_tags, $more_backup
}
return $status;
}
- function hotpot_backup_records(&$bf, $status, $level, $table, $select, $records_tag, $records_tags, $record_tag, $record_tags, $excluded_tags, $more_backup) {
+ function hotpot_backup_records(&$bf, $status, $level, $table, $select, $params, $records_tag, $records_tags, $record_tag, $record_tags, $excluded_tags, $more_backup) {
// general purpose backup function
// $bf : resource id of backup file
// $status : current status of backup (true or false)
// no further "fwrite"s will be attempted
// and the function returns "false".
// Otherwise, the function returns "true".
- if ($status && ($records = get_records_select($table, $select, 'id'))) {
+ global $DB;
+
+ if ($status && ($records = $DB->get_records_select($table, $select, $params, 'id'))) {
// start a group of records
if ($records_tag) {
$status = $status && fwrite($bf, start_tag($records_tag, $level, true));
}
////Return an array of info (name, value)
function hotpot_check_backup_mods($course, $user_data=false, $backup_unique_code, $instances=null) {
- global $CFG;
+ global $CFG, $DB;
$info = array();
if (isset($instances) && is_array($instances) && count($instances)) {
foreach ($instances as $id => $instance) {
} else {
// the course data
$info[0][0] = get_string('modulenameplural','hotpot');
- $info[0][1] = count_records('hotpot', 'course', $course);
+ $info[0][1] = $DB->count_records('hotpot', array('course'=>$course));
// the user_data, if requested
if ($user_data) {
- $table = "{$CFG->prefix}hotpot h, {$CFG->prefix}hotpot_attempts a";
- $select = "h.course = $course AND h.id = a.hotpot";
+ $table = "{hotpot} h, {hotpot_attempts} a";
+ $select = "h.course = ? AND h.id = a.hotpot";
+ $params = array($course);
$info[1][0] = get_string('attempts', 'quiz');
- $info[1][1] = count_records_sql("SELECT COUNT(*) FROM $table WHERE $select");
+ $info[1][1] = $DB->count_records_sql("SELECT COUNT(*) FROM $table WHERE $select", $params);
}
}
return $info;
////Return an array of info (name, value)
function hotpot_check_backup_mods_instances($instance,$backup_unique_code) {
- global $CFG;
+ global $CFG, $DB;
$info = array();
// the course data
// the user_data, if requested
if (!empty($instance->userdata)) {
- $table = "{$CFG->prefix}hotpot_attempts a";
- $select = "a.hotpot = $instance->id";
+ $table = "{hotpot_attempts} a";
+ $select = "a.hotpot = ?";
+ $params = array($instance->id);
$info[$instance->id.'1'][0] = get_string('attempts', 'quiz');
- $info[$instance->id.'1'][1] = count_records_sql("SELECT COUNT(*) FROM $table WHERE $select");
+ $info[$instance->id.'1'][1] = $DB->count_records_sql("SELECT COUNT(*) FROM $table WHERE $select", $params);
}
return $info;
}
<?php // $Id$
if (empty($CFG->hotpot_initialdisable)) {
- if (!count_records('hotpot')) {
- set_field('modules', 'visible', 0, 'name', 'hotpot'); // Disable it by default
+ if (!$DB->count_records('hotpot')) {
+ $DB->set_field('modules', 'visible', 0, array('name'=>'hotpot')); // Disable it by default
set_config('hotpot_initialdisable', 1);
}
}
print_error('invalidcoursemodule');
}
- if (! $hotpot = get_record("hotpot", "id", $cm->instance)) {
+ if (! $hotpot = $DB->get_record("hotpot", array("id"=>$cm->instance))) {
print_error('invalidhotpotid', 'hotpot');
}
- if (! $course = get_record("course", "id", $hotpot->course)) {
+ if (! $course = $DB->get_record("course", array("id"=>$hotpot->course))) {
print_error("invalidcourse");
}
notify("<b>$hotpot->name</b>");
// delete questions and responses for this hotpot
- if ($records = get_records_select('hotpot_questions', "hotpot=$hotpot->id", '', 'id,hotpot')) {
+ if ($records = $DB->get_records('hotpot_questions', array('hotpot'=>$hotpot->id), '', 'id,hotpot')) {
$questionids = implode(',', array_keys($records));
hotpot_delete_and_notify('hotpot_questions', "id IN ($questionids)", get_string('question', 'quiz'));
hotpot_delete_and_notify('hotpot_responses', "question IN ($questionids)", get_string('answer', 'quiz'));
$attemptcount = 0;
// regrade attempts, if any, for this hotpot
- if ($attempts = get_records_select('hotpot_attempts', "hotpot=$hotpot->id")) {
+ if ($attempts = $DB->get_records('hotpot_attempts', array('hotpot'=>$hotpot->id))) {
foreach ($attempts as $attempt) {
- $attempt->details = get_field('hotpot_details', 'details', 'attempt', $attempt->id);
+ $attempt->details = $DB->get_field('hotpot_details', 'details', array('attempt'=>$attempt->id));
if ($attempt->details) {
hotpot_add_attempt_details($attempt);
- if (! update_record('hotpot_attempts', $attempt)) {
+ if (! $DB->update_record('hotpot_attempts', $attempt)) {
print_error('cannotupdateattempt', 'hotpot', $next_url, $DB->get_last_error());
}
}
$regrade_hotpots = array();
$concat_field = sql_concat('hotpot', "'_'", 'name');
if ($concat_field) {
- $records = get_records_sql("
+ $records = $DB->get_records_sql("
SELECT $concat_field, COUNT(*), hotpot, name
- FROM {$CFG->prefix}hotpot_questions
+ FROM {hotpot_questions}
WHERE hotpot IN ($hotpotids)
GROUP BY hotpot, name
HAVING COUNT(*) >1
$start = microtime();
// get total number of attempts, users and details for these hotpots
- $tables = "{$CFG->prefix}hotpot_attempts a";
+ $params = array();
+ $tables = "{hotpot_attempts} a";
$fields = "
a.hotpot AS hotpot,
COUNT(DISTINCT a.clickreportid) AS attemptcount,
// do nothing (=get all users)
} else {
// restrict results to this user only
- $select .= " AND a.userid='$USER->id'";
+ $select .= " AND a.userid=:userid";
+ $params['userid'] = $USER->id;
}
$usejoin = 0;
if (has_capability('mod/hotpot:grade', get_context_instance(CONTEXT_SYSTEM)) && $usejoin) {
// join attempts table and details table
- $tables .= ",{$CFG->prefix}hotpot_details d";
+ $tables .= ",{hotpot_details} d";
$fields .= ',COUNT(DISTINCT d.id) AS detailcount';
$select .= " AND a.id=d.attempt";
// this may take about twice as long as getting the gradecounts separately :-(
// so this operation could be done after getting the $totals from the attempts table
}
- $totals = get_records_sql("SELECT $fields FROM $tables WHERE $select GROUP BY a.hotpot");
+ $totals = $DB->get_records_sql("SELECT $fields FROM $tables WHERE $select GROUP BY a.hotpot", $params);
if (has_capability('mod/hotpot:grade', get_context_instance(CONTEXT_SYSTEM)) && empty($usejoin)) {
foreach ($hotpots as $hotpot) {
$totals[$hotpot->id]->detailcount = 0;
- if ($ids = get_records('hotpot_attempts', 'hotpot', $hotpot->id)) {
+ if ($ids = $DB->get_records('hotpot_attempts', array('hotpot'=>$hotpot->id))) {
$ids = join(',', array_keys($ids));
- $totals[$hotpot->id]->detailcount = count_records_select('hotpot_details', "attempt IN ($ids)");
+ $totals[$hotpot->id]->detailcount = $DB->count_records_select('hotpot_details', "attempt IN ($ids)");
}
}
}
}
}
function set_data_exercise(&$cm, &$course, &$hotpot, &$questions, &$questionids, &$questioncount, &$blank) {
+ global $DB;
+
// get exercise details (course name, section number, activity number, quiztype and question count)
- $record = get_record("course_sections", "id", $cm->section);
+ $record = $DB->get_record("course_sections", array("id"=>$cm->section));
$this->data['exercise'] = array(
'course' => $course->shortname,
'section' => empty($record) ? $blank : $record->section+1,