Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add get_coursemodule functions for Moodle <1.5.4

  • Loading branch information...
commit ac63de90c689357bf1d20cc7245fb568c67a8e29 1 parent 5f4a37b
gbateson authored
Showing with 49 additions and 7 deletions.
  1. +49 −7 mod/hotpot/lib.php
View
56 mod/hotpot/lib.php
@@ -1889,13 +1889,13 @@ function hotpot_add_attempt_details(&$attempt) {
hotpot_add_response($attempt, $question, $response);
// initialize question object
- $question = NULL;
+ $question = new stdClass();
$question->name = '';
$question->text = '';
$question->hotpot = $attempt->hotpot;
// initialize response object
- $response = NULL;
+ $response = new stdClass();
$response->attempt = $attempt->id;
// update question number
@@ -1927,7 +1927,7 @@ function hotpot_add_attempt_details(&$attempt) {
case 'hints':
case 'clues':
case 'checks':
- $response->$name = intval($data);
+ $response->$name = round($data);
break;
}
@@ -1936,9 +1936,9 @@ function hotpot_add_attempt_details(&$attempt) {
// adjust field name and value
hotpot_adjust_response_field($quiztype, $question, $num='', $name, $data);
- // add $data to the attempt details
- if ($name=='penalties') {
- $attempt->$name = intval($data);
+ // allow only positive integers for penalties and score
+ if ($name=='penalties' || $name=='score') {
+ $attempt->$name = max(0, round($data));
}
}
}
@@ -2032,12 +2032,15 @@ function hotpot_adjust_response_field($quiztype, &$question, &$num, &$name, &$da
break;
case 'jcross':
$question->type = HOTPOT_JCROSS;
- $question->name = $num;
+ if (empty($question->name)) {
+ $question->name = $num;
+ }
switch ($name) {
case '': // HotPot v2.0.x
$name = 'correct';
break;
case 'clue':
+ case 'clue_text':
$name = 'text';
break;
}
@@ -2191,6 +2194,45 @@ function set_user_preference($name, $value, $otheruser=NULL) {
return false;
}
}
+if (!function_exists('get_coursemodule_from_id')) {
+ // add this function for Moodle < 1.6
+ function get_coursemodule_from_id($modulename, $cmid, $courseid=0) {
+ global $CFG;
+ return get_record_sql("
+ SELECT
+ cm.*, m.name, md.name as modname
+ FROM
+ {$CFG->prefix}course_modules cm,
+ {$CFG->prefix}modules md,
+ {$CFG->prefix}$modulename m
+ WHERE
+ ".($courseid ? "cm.course = '$courseid' AND " : '')."
+ cm.id = '$cmid' AND
+ cm.instance = m.id AND
+ md.name = '$modulename' AND
+ md.id = cm.module
+ ");
+ }
+}
+if (!function_exists('get_coursemodule_from_instance')) {
+ function get_coursemodule_from_instance($modulename, $instance, $courseid=0) {
+ global $CFG;
+ return get_record_sql("
+ SELECT
+ cm.*, m.name, md.name as modname
+ FROM
+ {$CFG->prefix}course_modules cm,
+ {$CFG->prefix}modules md,
+ {$CFG->prefix}$modulename m
+ WHERE
+ ".($courseid ? "cm.course = '$courseid' AND" : '')."
+ cm.instance = m.id AND
+ md.name = '$modulename' AND
+ md.id = cm.module AND
+ m.id = '$instance'
+ ");
+ }
+}
function hotpot_utf8_to_html_entity($char) {
// http://www.zend.com/codex.php?id=835&single=1
Please sign in to comment.
Something went wrong with that request. Please try again.