function hotpot_get_chain(&$cm) {
global $DB;
// get details of course_modules in this section
- $course_module_ids = get_field('course_sections', 'sequence', 'id', $cm->section);
+ $course_module_ids = $DB->get_field('course_sections', 'sequence', array('id'=>$cm->section));
if (empty($course_module_ids)) {
$hotpot_modules = array();
} else {
- $hotpot_modules = get_records_select('course_modules', "id IN ($course_module_ids) AND module=$cm->module");
+ $hotpot_modules = $DB->get_records_select('course_modules', "id IN ($course_module_ids) AND module=?", array($cm->module));
if (empty($hotpot_modules)) {
$hotpot_modules = array();
}
return $found ? $chain : false;
}
function hotpot_is_visible(&$cm) {
- global $CFG, $COURSE;
+ global $CFG, $COURSE, $DB;
// check grouping
$modulecontext = get_context_instance(CONTEXT_MODULE, $cm->id);
}
if (!isset($cm->sectionvisible)) {
- if (! $section = get_record('course_sections', 'id', $cm->section)) {
+ if (! $section = $DB->get_record('course_sections', array('id'=>$cm->section))) {
print_error('invalidsection');
}
$cm->sectionvisible = $section->visible;
function hotpot_add_chain(&$hotpot) {
/// add a chain of hotpot actiivities
- global $CFG, $course;
+ global $CFG, $course, $DB;
$ok = true;
$hotpot->names = array();
for ($i=0; $i<$i_max; $i++) {
hotpot_set_name_summary_reference($hotpot, $i);
- $hotpot->reference = addslashes($hotpot->reference);
+ $hotpot->reference = $hotpot->reference;
- if (!$hotpot->instance = insert_record("hotpot", $hotpot)) {
+ if (!$hotpot->instance = $DB->insert_record("hotpot", $hotpot)) {
print_error('cannotaddnewinstance', '', 'view.php?id='.$hotpot->course, $hotpot->modulename);
}
print_error('cannotaddcoursemoduletosection');
}
- if (! set_field('course_modules', 'section', $sectionid, "id", $hotpot->coursemodule)) {
+ if (! $DB->set_field('course_modules', 'section', $sectionid, array("id"=>$hotpot->coursemodule))) {
print_error('cannotupdatecoursemodule');
}
// settings for final activity in chain
hotpot_set_name_summary_reference($hotpot, $i);
- $hotpot->reference = addslashes($hotpot->references[$i]);
+ $hotpot->reference = $hotpot->references[$i];
$hotpot->shownextquiz = HOTPOT_NO;
if (isset($hotpot->startofchain)) {
}
function hotpot_get_all_instances_in_course($modulename, $course) {
/// called from index.php
+ global $CFG, $DB;
- global $CFG;
$instances = array();
- if (isset($CFG->release) && substr($CFG->release, 0, 3)>=1.2) {
- $groupmode = 'cm.groupmode,';
- } else {
- $groupmode = '';
- }
-
$query = "
SELECT
cm.id AS coursemodule,
cm.instance AS instance,
-- cm.section AS section,
cm.visible AS visible,
- $groupmode
+ cm.groupmode,
-- cs.section AS sectionnumber,
cs.section AS section,
cs.sequence AS sequence,
cs.visible AS sectionvisible,
thismodule.*
FROM
- {$CFG->prefix}course_modules cm,
- {$CFG->prefix}course_sections cs,
- {$CFG->prefix}modules m,
- {$CFG->prefix}$modulename thismodule
+ {course_modules} cm,
+ {course_sections} cs,
+ {modules} m,
+ {".$modulename."} thismodule
WHERE
- m.name = '$modulename' AND
+ m.name = :modulename AND
m.id = cm.module AND
- cm.course = '$course->id' AND
+ cm.course = :courseid AND
cm.section = cs.id AND
cm.instance = thismodule.id
";
- if ($rawmods = get_records_sql($query)) {
+ $params = array('modulename'=>$modulename, 'courseid'=>$course->id);
+
+ if ($rawmods = $DB->get_records_sql($query, $params)) {
// cache $isteacher setting
function hotpot_update_chain(&$hotpot) {
/// update a chain of hotpot actiivities
+ global $DB;
$ok = true;
if ($hotpot_modules = hotpot_get_chain($hotpot)) {
}
// update $thishotpot, if required
- if ($require_update && !update_record("hotpot", $thishotpot)) {
+ if ($require_update && !$DB->update_record("hotpot", $thishotpot)) {
print_error('cannotupdatemod', '',
'view.php?id='.$hotpot->course, $hotpot->modulename);
}
return true;
}
-function hotpot_delete_and_notify($table, $select, $strtable) {
- $count = max(0, count_records_select($table, $select));
+function hotpot_delete_and_notify($table, $select, $params, $strtable) {
+ global $DB;
+
+ $count = max(0, $DB->count_records_select($table, $select, $params));
if ($count) {
- delete_records_select($table, $select);
- $count -= max(0, count_records_select($table, $select));
+ $DB->delete_records_select($table, $select, $params);
+ $count -= max(0, $DB->count_records_select($table, $select, $params));
if ($count) {
notify(get_string('deleted')." $count x $strtable");
}
/// Used for user activity reports.
/// $report->time = the time they did it
/// $report->info = a short text description
+ global $DB;
$report = NULL;
- if ($records = get_records_select("hotpot_attempts", "hotpot='$hotpot->id' AND userid='$user->id'", "timestart ASC", "*")) {
+ if ($records = $DB->get_records("hotpot_attempts", array('hotpot'=>$hotpot->id, 'userid'=>$user->id), "timestart ASC", "*")) {
$report = new stdClass();
$scores = array();
foreach ($records as $record){
/// Given a course and a time, this module should find recent activity
/// that has occurred in hotpot activities and print it out.
/// Return true if there was output, or false is there was none.
+ global $CFG, $DB;
- global $CFG;
$result = false;
- $records = get_records_sql("
+ $records = $DB->get_records_sql("
SELECT
h.id AS id,
h.name AS name,
COUNT(*) AS count_attempts
FROM
- {$CFG->prefix}hotpot h,
- {$CFG->prefix}hotpot_attempts a
+ {hotpot} h,
+ {hotpot_attempts} a
WHERE
- h.course = $course->id
+ h.course = ?
AND h.id = a.hotpot
AND a.id = a.clickreportid
- AND a.starttime > $timestart
+ AND a.starttime > ?
GROUP BY
h.id, h.name
- ");
+ ", array($course->id, $timestart));
// note that PostGreSQL requires h.name in the GROUP BY clause
if($records) {
function hotpot_get_recent_mod_activity(&$activities, &$index, $sincetime, $courseid, $cmid="", $userid="", $groupid="") {
// Returns all quizzes since a given time.
-
- global $CFG;
+ global $CFG, $DB;
// If $cmid or $userid are specified, then this restricts the results
- $cm_select = empty($cmid) ? "" : " AND cm.id = '$cmid'";
- $user_select = empty($userid) ? "" : " AND u.id = '$userid'";
+ $cm_select = empty($cmid) ? "" : " AND cm.id = :cmid";
+ $user_select = empty($userid) ? "" : " AND u.id = :userid";
+
+ $params = array('cmid'=>$cmid, 'userid'=>$userid, 'sincetime'=>$sincetime, 'courseid'=>$courseid);
- $records = get_records_sql("
+ $records = $DB->get_records_sql("
SELECT
a.*,
h.name, h.course,
cm.instance, cm.section,
u.firstname, u.lastname, u.picture
FROM
- {$CFG->prefix}hotpot_attempts a,
- {$CFG->prefix}hotpot h,
- {$CFG->prefix}course_modules cm,
- {$CFG->prefix}user u
+ {hotpot_attempts} a,
+ {hotpot} h,
+ {course_modules} cm,
+ {user} u
WHERE
- a.timefinish > '$sincetime'
+ a.timefinish > :sincetime
AND a.id = a.clickreportid
AND a.userid = u.id $user_select
AND a.hotpot = h.id $cm_select
AND cm.instance = h.id
- AND cm.course = '$courseid'
+ AND cm.course = :courseid
AND h.course = cm.course
ORDER BY
a.timefinish ASC
- ");
+ ", $params);
if (!empty($records)) {
foreach ($records as $record) {
if (empty($groupid) || groups_is_member($groupid, $record->userid)) {
- unset($activity);
+ $activity = new object();
$activity->type = "hotpot";
$activity->defaultindex = $index;
/// Function to be run periodically according to the moodle cron
/// This function searches for things that need to be done, such
/// as sending out mail, toggling flags etc ...
-
- global $CFG;
-
return true;
}
function hotpot_grades($hotpotid) {
/// Must return an array of grades for a given instance of this module,
/// indexed by user. It also returns a maximum allowed grade.
+ global $DB;
+
+ $hotpot = $DB->get_record('hotpot', array('id'=>$hotpotid));
- $hotpot = get_record('hotpot', 'id', $hotpotid);
+ $return = new object();
$return->grades = hotpot_get_grades($hotpot);
$return->maxgrade = $hotpot->grade;
break;
case HOTPOT_GRADEMETHOD_FIRST:
$grade = "ROUND(score * $weighting, $precision)";
- $grade = sql_concat('timestart', "'_'", $grade);
+ $grade = $DB->sql_concat('timestart', "'_'", $grade);
$grade = "MIN($grade) AS grade";
break;
case HOTPOT_GRADEMETHOD_LAST:
$grade = "ROUND(score * $weighting, $precision)";
- $grade = sql_concat('timestart', "'_'", $grade);
+ $grade = $DB->sql_concat('timestart', "'_'", $grade);
$grade = "MAX($grade) AS grade";
break;
}
* @param int $userid specific user only, 0 means all users
*/
function hotpot_update_grades($hotpot=null, $userid=0, $nullifnone=true) {
- global $CFG;
- if (! function_exists('grade_update')) {
- require_once($CFG->libdir.'/gradelib.php');
- }
+ global $CFG, $DB;
+ require_once($CFG->libdir.'/gradelib.php');
+
if (is_null($hotpot)) {
// update (=create) grades for all hotpots
$sql = "
SELECT h.*, cm.idnumber as cmidnumber
- FROM {$CFG->prefix}hotpot h, {$CFG->prefix}course_modules cm, {$CFG->prefix}modules m
+ FROM {hotpot} h, {course_modules} cm, {modules} m
WHERE m.name='hotpot' AND m.id=cm.module AND cm.instance=h.id"
;
- if ($rs = get_recordset_sql($sql)) {
- while ($hotpot = rs_fetch_next_record($rs)) {
+ if ($rs = $DB->get_recordset_sql($sql)) {
+ foreach ($rs as $hotpot) {
hotpot_update_grades($hotpot, 0, false);
}
- rs_close($rs);
+ $rs->close();
}
} else {
// update (=create) grade for a single hotpot
*/
function hotpot_grade_item_update($hotpot, $grades=null) {
global $CFG;
- if (! function_exists('grade_update')) {
- require_once($CFG->libdir.'/gradelib.php');
- }
+ require_once($CFG->libdir.'/gradelib.php');
+
$params = array('itemname' => $hotpot->name);
if (array_key_exists('cmidnumber', $hotpot)) {
//cmidnumber may not be always present
*/
function hotpot_grade_item_delete($hotpot) {
global $CFG;
- if (! function_exists('grade_update')) {
- require_once($CFG->libdir.'/gradelib.php');
- }
+ require_once($CFG->libdir.'/gradelib.php');
return grade_update('mod/hotpot', $hotpot->course, 'mod', 'hotpot', $hotpot->id, 0, null, array('deleted'=>1));
}
//for a given instance of hotpot. Must include every user involved
//in the instance, independient of his role (student, teacher, admin...)
//See other modules as example.
- global $CFG;
+ global $DB;
- return get_records_sql("
+ return $DB->get_records_sql("
SELECT DISTINCT
u.id, u.id
FROM
- {$CFG->prefix}user u,
- {$CFG->prefix}hotpot_attempts a
+ {user} u,
+ {hotpot_attempts} a
WHERE
u.id = a.userid
- AND a.hotpot = '$hotpotid'
- ");
+ AND a.hotpot = ?
+ ", array($hotpotid));
}
function hotpot_scale_used ($hotpotid, $scaleid) {
$report = false;
- //$rec = get_record("hotpot","id","$hotpotid","scale","-$scaleid");
+ //$rec = $DB->get_record("hotpot", array("id"=>"$hotpotid","scale"=>-$scaleid));
//
//if (!empty($rec) && !empty($scaleid)) {
// $report = true;
$time = time();
// set all previous "in progress" attempts at this quiz to "abandoned"
- if ($attempts = get_records_select('hotpot_attempts', "hotpot='$hotpotid' AND userid='$USER->id' AND status='".HOTPOT_STATUS_INPROGRESS."'")) {
+ if ($attempts = $DB->get_records('hotpot_attempts', array('hotpot'=>$hotpotid, 'userid'=>$USER->id, 'status'=>HOTPOT_STATUS_INPROGRESS))) {
foreach ($attempts as $attempt) {
if ($attempt->timefinish==0) {
$attempt->timefinish = $time;
$attempt->clickreportid = $attempt->id;
}
$attempt->status = HOTPOT_STATUS_ABANDONED;
- update_record('hotpot_attempts', $attempt);
+ $DB->update_record('hotpot_attempts', $attempt);
}
}
$attempt->attempt = hotpot_get_next_attempt($hotpotid);
$attempt->timestart = $time;
- return insert_record("hotpot_attempts", $attempt);
+ return $DB->insert_record("hotpot_attempts", $attempt);
}
function hotpot_get_next_attempt($hotpotid) {
- global $USER;
+ global $USER, $DB;
// get max attempt so far
- $i = count_records_select('hotpot_attempts', "hotpot='$hotpotid' AND userid='$USER->id'", 'MAX(attempt)');
+ $i = $DB->count_records_select('hotpot_attempts', "hotpot=? AND userid=?", array($hotpotid, $USER->id), 'MAX(attempt)');
return empty($i) ? 1 : ($i+1);
}
return $name;
}
function hotpot_strings($ids) {
+ global $DB;
// array of ids of empty strings
static $HOTPOT_EMPTYSTRINGS;
if (!isset($HOTPOT_EMPTYSTRINGS)) { // first time only
// get ids of empty strings
- $emptystrings = get_records_select('hotpot_strings', 'LENGTH(TRIM(string))=0');
+ $emptystrings = $DB->get_records_select('hotpot_strings', 'LENGTH(TRIM(string))=0');
$HOTPOT_EMPTYSTRINGS = empty($emptystrings) ? array() : array_keys($emptystrings);
}
return implode(',', $strings);
}
function hotpot_string($id) {
- return get_field('hotpot_strings', 'string', 'id', $id);
+ global $DB;
+ return $DB->get_field('hotpot_strings', 'string', array('id'=>$id));
}
//////////////////////////////////////////////////////////////////////////////////////
return preg_replace($search, $replace, $urls);
}
function hotpot_convert_navbutton_url($baseurl, $reference, $url, $course, $stripslashes=true) {
- global $CFG;
+ global $CFG, $DB;
if ($stripslashes) {
$url = hotpot_stripslashes($url);
// is this a $url for another hotpot in this course ?
if (preg_match("|^".preg_quote($baseurl)."(.*)$|", $url, $matches)) {
- if ($records = get_records_select('hotpot', "course='$course' AND reference='".$matches[1]."'")) {
+ if ($records = $DB->get_records('hotpot', array('course'=>$course, 'reference'=>$matches[1]))) {
$ids = array_keys($records);
$url = "$CFG->wwwroot/mod/hotpot/view.php?hp=".$ids[0];
}
}
$question->md5key = md5($question->name);
- if (!$question->id = get_field('hotpot_questions', 'id', 'hotpot', $attempt->hotpot, 'md5key', $question->md5key, 'name', $question->name)) {
+ if (!$question->id = $DB->get_field('hotpot_questions', 'id', array('hotpot'=>$attempt->hotpot, 'md5key'=>$question->md5key, 'name'=>$question->name))) {
// add question record
- if (!$question->id = insert_record('hotpot_questions', $question)) {
+ if (!$question->id = $DB->insert_record('hotpot_questions', $question)) {
print_error('cannotaddquestionrecord', 'hotpot', $next_url);
}
}
- if (record_exists('hotpot_responses', 'attempt', $attempt->id, 'question', $question->id)) {
+ if ($DB->record_exists('hotpot_responses', array('attempt'=>$attempt->id, 'question'=>$question->id))) {
// there is already a response to this question for this attempt
// probably because this quiz has two questions with the same text
// e.g. Which one of these answers is correct?
$response->question = $question->id;
// add response record
- if(!$response->id = insert_record('hotpot_responses', $response)) {
+ if(!$response->id = $DB->insert_record('hotpot_responses', $response)) {
print_error('cannotaddresprecord', 'hotpot', $next_url);
}
return implode(',', $ids);
}
function hotpot_string_id($str) {
+ global $DB;
+
$id = '';
if (isset($str) && $str<>'') {
// get the id from the table if it is already there
$md5key = md5($str);
- if (!$id = get_field('hotpot_strings', 'id', 'md5key', $md5key, 'string', $str)) {
+ if (!$id = $DB->get_field('hotpot_strings', 'id', array('md5key'=>$md5key, 'string'=>$str))) {
// create a string record
$record = new stdClass();
$record->md5key = $md5key;
// try and add the new string record
- if (!$id = insert_record('hotpot_strings', $record)) {
+ if (!$id = $DB->insert_record('hotpot_strings', $record)) {
global $DB;
print_error('cannotaddstrrecord', 'hotpot');
}
if (! $cm = get_coursemodule_from_id('hotpot', $id)) {
print_error('invalidcoursemodule');
}
- if (! $course = get_record("course", "id", $cm->course)) {
+ if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
print_error('coursemisconf');
}
- if (! $hotpot = get_record("hotpot", "id", $cm->instance)) {
+ if (! $hotpot = $DB->get_record("hotpot", array("id"=>$cm->instance))) {
print_error('invalidhotpotid', 'hotpot');
}
} else {
- if (! $hotpot = get_record("hotpot", "id", $hp)) {
+ if (! $hotpot = $DB->get_record("hotpot", array("id"=>$hp))) {
print_error('invalidhotpotid', 'hotpot');
}
- if (! $course = get_record("course", "id", $hotpot->course)) {
+ if (! $course = $DB->get_record("course", array("id"=>$hotpot->course))) {
print_error('coursemisconf');
}
if (! $cm = get_coursemodule_from_instance("hotpot", $hotpot->id, $course->id)) {
case 'allusers':
// anyone who has ever attempted this hotpot
- if ($records = get_records_select('hotpot_attempts', "hotpot=$hotpot->id", '', 'id,userid')) {
+ if ($records = $DB->get_records('hotpot_attempts', array('hotpot'=>$hotpot->id), '', 'id,userid')) {
foreach ($records as $record) {
$users[$record->userid] = 0; // "0" means user is NOT currently allowed to attempt this HotPot
}
}
// database table and selection conditions
- $table = "{$CFG->prefix}hotpot_attempts a";
- $select = "a.hotpot=$hotpot->id AND a.userid IN ($user_ids)";
+ $table = "{hotpot_attempts} a";
+ $select = "a.hotpot=:hotpotid AND a.userid IN ($user_ids)";
if ($mode!='overview') {
$select .= ' AND a.status<>'.HOTPOT_STATUS_INPROGRESS;
}
+ $params = array('hotpotid'=>$hotpot->id);
// confine attempts if necessary
switch ($formdata['reportattempts']) {
// do nothing (i.e. get ALL attempts)
} else {
$groupby = 'userid';
- $records = hotpot_get_records_groupby($function, $fieldnames, $table, $select, $groupby);
+ $records = hotpot_get_records_groupby($function, $fieldnames, $table, $select, $params, $groupby);
$select = '';
+ $params = array();
if ($records) {
$ids = array();
foreach ($records as $record) {
// pick out last attempt in each clickreport series
if ($select) {
- $cr_attempts = hotpot_get_records_groupby('MAX', array('timefinish', 'id'), $table, $select, 'clickreportid');
+ $cr_attempts = hotpot_get_records_groupby('MAX', array('timefinish', 'id'), $table, $select, $params, 'clickreportid');
} else {
$cr_attempts = array();
}
sort($ids);
$select = "a.id IN (".join(',', $ids).")";
}
+ $params = array();
}
$attempts = array();
if ($select) {
// add user information to SQL query
$select .= ' AND a.userid = u.id';
- $table .= ", {$CFG->prefix}user u";
+ $table .= ", {user} u";
$order = "u.lastname, a.attempt, a.timefinish";
// get the attempts (at last!)
- $attempts = get_records_sql("SELECT $fields FROM $table WHERE $select ORDER BY $order");
+ $attempts = $DB->get_records_sql("SELECT $fields FROM $table WHERE $select ORDER BY $order", $params);
}
// stop now if no attempts were found
}
// get the questions
- if (!$questions = get_records_select('hotpot_questions', "hotpot='$hotpot->id'")) {
+ if (!$questions = $DB->get_records('hotpot_questions', array('hotpot'=>$hotpot->id))) {
$questions = array();
}
// get reponses to these attempts
$attempt_ids = join(',',array_keys($attempts));
- if (!$responses = get_records_sql("SELECT * FROM {$CFG->prefix}hotpot_responses WHERE attempt IN ($attempt_ids)")) {
+ if (!$responses = $DB->get_records_sql("SELECT * FROM {hotpot_responses} WHERE attempt IN ($attempt_ids)")) {
$responses = array();
}
return get_string('grade')."$nl($grademethod)";
}
function hotpot_delete_selected_attempts(&$hotpot, $del) {
+ global $DB;
$select = '';
+ $params = array('hotpotid'=>$hotpot->id);
switch ($del) {
case 'all' :
- $select = "hotpot='$hotpot->id'";
+ $select = "hotpot=:hotpotid";
break;
case 'abandoned':
- $select = "hotpot='$hotpot->id' AND status=".HOTPOT_STATUS_ABANDONED;
+ $select = "hotpot=:hotpotid AND status=".HOTPOT_STATUS_ABANDONED;
break;
case 'selection':
$ids = (array)data_submitted();
unset($ids['del']);
unset($ids['id']);
if (!empty($ids)) {
- $select = "hotpot='$hotpot->id' AND clickreportid IN (".implode(',', $ids).")";
+ list($ids, $idparams) = $DB->get_in_or_equal($ids, SQL_PARAMS_NAMED, 'crid0');
+ $params = array_merge($params, $idparams);
+ $select = "hotpot=:hotpotid AND clickreportid $ids";
}
break;
}
if ($select) {
$table = 'hotpot_attempts';
- if ($attempts = get_records_select($table, $select)) {
+ if ($attempts = $DB->get_records_select($table, $select, $params)) {
- hotpot_delete_and_notify($table, $select, get_string('attempts', 'quiz'));
+ hotpot_delete_and_notify($table, $select, $params, get_string('attempts', 'quiz'));
$select = 'attempt IN ('.implode(',', array_keys($attempts)).')';
- hotpot_delete_and_notify('hotpot_details', $select, get_string('rawdetails', 'hotpot'));
- hotpot_delete_and_notify('hotpot_responses', $select, get_string('answer', 'quiz'));
+ $params = array();
+ hotpot_delete_and_notify('hotpot_details', $select, $params, get_string('rawdetails', 'hotpot'));
+ hotpot_delete_and_notify('hotpot_responses', $select, $params, get_string('answer', 'quiz'));
// update grades for all users for this hotpot
hotpot_update_grades($hotpot);
print_heading($hotpot->name);
}
function hotpot_print_report_selector(&$course, &$hotpot, &$formdata) {
-
- global $CFG;
+ global $CFG, $DB;
$reports = hotpot_get_report_names('overview,simplestat,fullstat');
}
// get users who have ever atetmpted this HotPot
- $users = get_records_sql("
+ $users = $DB->get_records_sql("
SELECT
u.id, u.firstname, u.lastname
FROM
- {$CFG->prefix}user u,
- {$CFG->prefix}hotpot_attempts ha
+ {user} u,
+ {hotpot_attempts} ha
WHERE
- u.id = ha.userid AND ha.hotpot=$hotpot->id
+ u.id = ha.userid AND ha.hotpot=?
ORDER BY
u.lastname
- ");
+ ", array($hotpot->id));
// get context
$cm = get_coursemodule_from_instance('hotpot', $hotpot->id);
return $reports;
}
-function hotpot_get_records_groupby($function, $fieldnames, $table, $select, $groupby) {
+function hotpot_get_records_groupby($function, $fieldnames, $table, $select, $params, $groupby) {
// $function is an SQL aggregate function (MAX or MIN)
+ global $DB;
- $fields = sql_concat_join("'_'", $fieldnames);
+ $fields = $DB->sql_concat_join("'_'", $fieldnames);
$fields = "$groupby, $function($fields) AS joinedvalues";
if ($fields) {
- $records = get_records_sql("SELECT $fields FROM $table WHERE $select GROUP BY $groupby");
+ $records = $DB->get_records_sql("SELECT $fields FROM $table WHERE $select GROUP BY $groupby", $params);
}
if (empty($fields) || empty($records)) {
if (! $cm = get_coursemodule_from_id('hotpot', $id)) {
print_error('invalidcoursemodule');
}
- if (! $course = get_record("course", "id", $cm->course)) {
+ if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
print_error('coursemisconf');
}
- if (! $hotpot = get_record("hotpot", "id", $cm->instance)) {
+ if (! $hotpot = $DB->get_record("hotpot", array("id"=>$cm->instance))) {
print_error('invalidcoursemodule');
}
} else {
- if (! $hotpot = get_record("hotpot", "id", $hp)) {
+ if (! $hotpot = $DB->get_record("hotpot", array("id"=>$hp))) {
print_error('invalidcoursemodule');
}
- if (! $course = get_record("course", "id", $hotpot->course)) {
+ if (! $course = $DB->get_record("course", array("id"=>$hotpot->course))) {
print_error('coursemisconf');
}
if (! $cm = get_coursemodule_from_instance("hotpot", $hotpot->id, $course->id)) {
print_error('invalidcoursemodule');
}
}
- if (! $attempt = get_record("hotpot_attempts", "id", $attempt)) {
+ if (! $attempt = $DB->get_record("hotpot_attempts", array("id"=>$attempt))) {
print_error('invalidattemptid', 'hotpot');
}
hotpot_print_review_buttons($course, $hotpot, $attempt, $context);
$action = has_capability('mod/hotpot:viewreport',$context) ? optional_param('action', '', PARAM_ALPHA) : '';
if ($action) {
- $xml = get_field('hotpot_details', 'details', 'attempt', $attempt->id);
+ $xml = $DB->get_field('hotpot_details', 'details', array('attempt'=>$attempt->id));
print '<hr>';
switch ($action) {
case 'showxmltree':
print_simple_box_end();
}
function hotpot_print_review_buttons(&$course, &$hotpot, &$attempt, $context) {
+ global $DB;
+
print "\n".'<table border="0" align="center" cellpadding="2" cellspacing="2" class="generaltable">';
print "\n<tr>\n".'<td align="center">';
print_single_button("report.php?hp=$hotpot->id", NULL, get_string('continue'), 'post');
- if (has_capability('mod/hotpot:viewreport',$context) && record_exists('hotpot_details', 'attempt', $attempt->id)) {
+ if (has_capability('mod/hotpot:viewreport',$context) && $DB->record_exists('hotpot_details', array('attempt'=>$attempt->id))) {
print "</td>\n".'<td align="center">';
print_single_button("review.php?hp=$hotpot->id&attempt=$attempt->id&action=showxmlsource", NULL, get_string('showxmlsource', 'hotpot'), 'post');
print "</td>\n".'<td align="center">';
print "</table>\n";
}
function hotpot_print_attempt_details(&$hotpot, &$attempt) {
+ global $DB;
+
// define fields to print
$textfields = array('correct', 'ignored', 'wrong');
$numfields = array('score', 'weighting', 'hints', 'clues', 'checks');
$f[$field] = array('count'=>0, 'name'=>$name);
}
// get questions and responses for this attempt
- $questions = get_records_select('hotpot_questions', "hotpot='$hotpot->id'", 'id');
- $responses = get_records_select('hotpot_responses', "attempt='$attempt->id'", 'id');
+ $questions = $DB->get_records('hotpot_questions', array('hotpot'=>$hotpot->id), 'id');
+ $responses = $DB->get_records('hotpot_responses', array('attempt'=>$attempt->id), 'id');
if ($questions && $responses) {
foreach ($responses as $response) {
$id = $response->question;