Skip to content

Commit

Permalink
add get_coursemodule functions for Moodle <1.5.4
Browse files Browse the repository at this point in the history
  • Loading branch information
gbateson committed Sep 13, 2006
1 parent 5f4a37b commit ac63de9
Showing 1 changed file with 49 additions and 7 deletions.
56 changes: 49 additions & 7 deletions mod/hotpot/lib.php
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1889,13 +1889,13 @@ function hotpot_add_attempt_details(&$attempt) {
hotpot_add_response($attempt, $question, $response); hotpot_add_response($attempt, $question, $response);


// initialize question object // initialize question object
$question = NULL; $question = new stdClass();
$question->name = ''; $question->name = '';
$question->text = ''; $question->text = '';
$question->hotpot = $attempt->hotpot; $question->hotpot = $attempt->hotpot;


// initialize response object // initialize response object
$response = NULL; $response = new stdClass();
$response->attempt = $attempt->id; $response->attempt = $attempt->id;


// update question number // update question number
Expand Down Expand Up @@ -1927,7 +1927,7 @@ function hotpot_add_attempt_details(&$attempt) {
case 'hints': case 'hints':
case 'clues': case 'clues':
case 'checks': case 'checks':
$response->$name = intval($data); $response->$name = round($data);
break; break;
} }


Expand All @@ -1936,9 +1936,9 @@ function hotpot_add_attempt_details(&$attempt) {
// adjust field name and value // adjust field name and value
hotpot_adjust_response_field($quiztype, $question, $num='', $name, $data); hotpot_adjust_response_field($quiztype, $question, $num='', $name, $data);


// add $data to the attempt details // allow only positive integers for penalties and score
if ($name=='penalties') { if ($name=='penalties' || $name=='score') {
$attempt->$name = intval($data); $attempt->$name = max(0, round($data));
} }
} }
} }
Expand Down Expand Up @@ -2032,12 +2032,15 @@ function hotpot_adjust_response_field($quiztype, &$question, &$num, &$name, &$da
break; break;
case 'jcross': case 'jcross':
$question->type = HOTPOT_JCROSS; $question->type = HOTPOT_JCROSS;
$question->name = $num; if (empty($question->name)) {
$question->name = $num;
}
switch ($name) { switch ($name) {
case '': // HotPot v2.0.x case '': // HotPot v2.0.x
$name = 'correct'; $name = 'correct';
break; break;
case 'clue': case 'clue':
case 'clue_text':
$name = 'text'; $name = 'text';
break; break;
} }
Expand Down Expand Up @@ -2191,6 +2194,45 @@ function set_user_preference($name, $value, $otheruser=NULL) {
return false; 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) { function hotpot_utf8_to_html_entity($char) {
// http://www.zend.com/codex.php?id=835&single=1 // http://www.zend.com/codex.php?id=835&single=1


Expand Down

0 comments on commit ac63de9

Please sign in to comment.