]> git.mjollnir.org Git - moodle.git/commitdiff
add get_coursemodule_from_id/instance functions for compatability with Moodles <1.7
authorgbateson <gbateson>
Thu, 14 Sep 2006 07:29:22 +0000 (07:29 +0000)
committergbateson <gbateson>
Thu, 14 Sep 2006 07:29:22 +0000 (07:29 +0000)
mod/hotpot/lib.php

index e7c0eb838ecb6effa922f72551eae62f3ecf25d2..d37d875fb44c90d7c9f7202a2736eacc692f8b28 100644 (file)
@@ -2134,7 +2134,7 @@ function hotpot_string_id($str) {
     if (isset($str) && $str<>'') {
 
         // get the id from the table if it is already there
-               $md5key = md5($str);
+        $md5key = md5($str);
         if (!$id = get_field('hotpot_strings', 'id', 'md5key', $md5key, 'string', $str)) {
 
             // create a string record
@@ -2195,6 +2195,46 @@ if (!function_exists('set_user_preference')) {
         return false;
     }
 }
+if (!function_exists('get_coursemodule_from_id')) {
+    // add this function for Moodle < 1.5.4
+    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')) {
+    // add this function for Moodle < 1.5.4
+    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