]> git.mjollnir.org Git - moodle.git/commitdiff
When displaying index lists of a particular module's activities,
authormoodler <moodler>
Sat, 12 Jul 2003 05:19:18 +0000 (05:19 +0000)
committermoodler <moodler>
Sat, 12 Jul 2003 05:19:18 +0000 (05:19 +0000)
ensure that the order they are displayed in is always the same as the
order they have been defined in.   See bug 553.

This involved API changes to the function get_all_instances_in_course()

12 files changed:
lib/datalib.php
mod/assignment/index.php
mod/chat/index.php
mod/choice/index.php
mod/forum/discuss.php
mod/forum/index.php
mod/journal/index.php
mod/quiz/index.php
mod/resource/index.php
mod/resource/lib.php
mod/survey/index.php
mod/workshop/index.php

index 2663acf56a24beddedcad3fa65759636a7993187..cb938e0846b15356cddfe02b54f5bcdaff68e600 100644 (file)
@@ -1080,31 +1080,46 @@ function get_coursemodule_from_instance($modulename, $instance, $courseid) {
 
 }
 
-function get_all_instances_in_course($modulename, $courseid, $sort="cw.section") {
+function get_all_instances_in_course($modulename, $course) {
 /// Returns an array of all the active instances of a particular
-/// module in a given course.   Returns false on any errors.
+/// module in a given course, sorted in the order they are defined
+/// in the course.   Returns false on any errors.
+/// $course is a course object, this depends on an accurate $course->modinfo
 
     global $CFG;
 
-    // Hide non-visible instances from students
-    if (isteacher($courseid)) {
-        $showvisible = "";
-    } else {
-        $showvisible = "AND cm.visible = '1'";
+    if (!$modinfo = unserialize($course->modinfo)) {
+        return array();
     }
 
-    return get_records_sql("SELECT m.*,cw.section,cm.id as coursemodule,cm.visible as visible 
+    if (!$rawmods = get_records_sql("SELECT cm.id as coursemodule, m.*,cw.section,cm.visible as visible 
                             FROM {$CFG->prefix}course_modules cm, 
                                  {$CFG->prefix}course_sections cw, 
                                  {$CFG->prefix}modules md, 
                                  {$CFG->prefix}$modulename m 
-                            WHERE cm.course = '$courseid' AND 
+                            WHERE cm.course = '$course->id' AND 
                                   cm.instance = m.id AND 
                                   cm.deleted = '0' AND
                                   cm.section = cw.id AND 
                                   md.name = '$modulename' AND 
-                                  md.id = cm.module $showvisible
-                            ORDER BY $sort");
+                                  md.id = cm.module")) {
+        return array();
+    }
+
+    // Hide non-visible instances from students
+    if (isteacher($course->id)) {
+        $invisible = -1;
+    } else {
+        $invisible = 0;
+    }
+
+    foreach ($modinfo as $mod) {
+        if ($mod->mod == $modulename and $mod->visible > $invisible) {
+            $outputarray[] = $rawmods[$mod->cm];
+        }
+    }
+
+    return $outputarray;
 
 }
 
index d15d8dfebd840e0c0229f14f344456350d789aab..b071b423ca807066d985aff9f55e5147600b6fa5 100644 (file)
@@ -27,7 +27,7 @@
 
     print_header("$course->shortname: $strassignments", "$course->fullname", "$navigation $strassignments", "", "", true, "", navmenu($course));
 
-    if (! $assignments = get_all_instances_in_course("assignment", $course->id, "cw.section ASC")) {
+    if (! $assignments = get_all_instances_in_course("assignment", $course)) {
         notice("There are no assignments", "../../course/view.php?id=$course->id");
         die;
     }
index 2d9e0bd1687782c83e288da7f3d3fca95b48520e..f411248b967e92ddb534adb5f69b03e2f4c38507 100644 (file)
@@ -30,7 +30,7 @@
 
 /// Get all the appropriate data
 
-    if (! $chats = get_all_instances_in_course("chat", $course->id, "cw.section ASC")) {
+    if (! $chats = get_all_instances_in_course("chat", $course)) {
         notice("There are no chats", "../../course/view.php?id=$course->id");
         die;
     }
index afcff8d1c08a3ce324288c353214f4beafeaab44..a4784c24be484083d4ca23cdf56905a695c7810f 100644 (file)
@@ -26,7 +26,7 @@
                  "$navigation $strchoices", "", "", true, "", navmenu($course));
 
 
-    if (! $choices = get_all_instances_in_course("choice", $course->id, "cw.section ASC")) {
+    if (! $choices = get_all_instances_in_course("choice", $course)) {
         notice("There are no choices", "../../course/view.php?id=$course->id");
     }
 
index 88ebc0e72f37413d2024b084ff8a15b470f2d045..a5f24a3fce3913f9aa5cf8de4a9efbdb65e6e086 100644 (file)
@@ -90,7 +90,7 @@
     }
 
     if (isteacher($course->id)) {    // Popup menu to allow discussions to be moved to other forums
-        if ($forums = get_all_instances_in_course("forum", $course->id, "cw.section ASC")) {
+        if ($forums = get_all_instances_in_course("forum", $course)) {
             foreach ($forums as $courseforum) {
                 if ($courseforum->id != $forum->id) {
                     $url = "discuss.php?d=$discussion->id&move=$courseforum->id";
index 4414a6f528f8e00f84303633f86d08e31e169899..ffc6d7dea8ffce26f646f77bc8b4f68c845baa1a 100644 (file)
         array_unshift($table->head, "");
         array_unshift($table->align, "center");
     
-        if ($learningforums = get_all_instances_in_course("forum", $course->id)) {
+        if ($learningforums = get_all_instances_in_course("forum", $course)) {
             foreach ($learningforums as $key => $forum) {
                 if ($forum->type == "news" or $forum->type == "social") {
                     unset($learningforums[$key]);  // Remove these
index 9504d388795907719cba7af453fc377d7fdb5a55..838c8d63ea3adaf141ba279e7ab59e30e66c3e3a 100644 (file)
@@ -29,7 +29,7 @@
                  "", "", true, "", navmenu($course));
 
 
-    if (! $journals = get_all_instances_in_course("journal", $course->id, "cw.section ASC")) {
+    if (! $journals = get_all_instances_in_course("journal", $course)) {
         notice("There are no journals", "../../course/view.php?id=$course->id");
         die;
     }
index 20b1e46742442d6483cefd441f11aefdb51e40f0..b2153d63eaf24a5f32e84a0b6d7ebeb1e026566c 100644 (file)
@@ -30,7 +30,7 @@
 
 // Get all the appropriate data
 
-    if (! $quizzes = get_all_instances_in_course("quiz", $course->id, "cw.section ASC")) {
+    if (! $quizzes = get_all_instances_in_course("quiz", $course)) {
         notice("There are no quizzes", "../../course/view.php?id=$course->id");
         die;
     }
index f235040fd6fc61fe297c0309f62f80d250568018..e855f46536c8f34632945e5d686f38525f293547 100644 (file)
     print_header("$course->shortname: $strresources", "$course->fullname", "$navigation $strresources", 
                  "", "", true, "", navmenu($course));
 
-    if ($course->format == "weeks" or $course->format == "topics") {
-        $sortorder = "cw.section ASC";
-    } else {
-        $sortorder = "m.timemodified DESC";
-    }
-
-    if (! $resources = get_all_instances_in_course("resource", $course->id, $sortorder)) {
+    if (! $resources = get_all_instances_in_course("resource", $course)) {
         notice("There are no resources", "../../course/view.php?id=$course->id");
         exit;
     }
index 8e54de4d0afeaca29265fccf788c308769bad6ff..c72f4e49ca8150f4737747c3b3f76217d9c7010a 100644 (file)
@@ -21,41 +21,48 @@ $RESOURCE_TYPE = array (REFERENCE    => get_string("resourcetype1", "resource"),
 $RESOURCE_FRAME_SIZE = 130;
 
 
-function resource_list_all_resources($courseid=0, $sort="name ASC", $recent=0) {
-    // Returns list of all resource links in an array of strings
-    global $CFG, $USER;
+function resource_add_instance($resource) {
+// Given an object containing all the necessary data, 
+// (defined by the form in mod.html) this function 
+// will create a new instance and return the id number 
+// of the new instance.
 
-    if ($courseid) {
-        if (! $course = get_record("course", "id", $courseid)) {
-            error("Could not find the specified course");
-        }
+    $resource->timemodified = time();
 
-        require_login($course->id);
+    return insert_record("resource", $resource);
+}
 
-    } else {
-        if (! $course = get_record("course", "category", 0)) {
-            error("Could not find a top-level course!");
-        }
+
+function resource_update_instance($resource) {
+// Given an object containing all the necessary data, 
+// (defined by the form in mod.html) this function 
+// will update an existing instance with new data.
+
+    $resource->id = $resource->instance;
+    $resource->timemodified = time();
+
+    return update_record("resource", $resource);
+}
+
+
+function resource_delete_instance($id) {
+// Given an ID of an instance of this module, 
+// this function will permanently delete the instance 
+// and any data that depends on it.  
+
+    if (! $resource = get_record("resource", "id", "$id")) {
+        return false;
     }
 
-    if ($resources = get_all_instances_in_course("resource", $course->id, $sort)) {
-        foreach ($resources as $resource) {
-            $link = "<A HREF=\"$CFG->wwwroot/mod/resource/view.php?id=$resource->coursemodule\">$resource->name</A>";
-            if ($USER->editing) {
-                $link .= "&nbsp; &nbsp; 
-                    <A HREF=\"$CFG->wwwroot/course/mod.php?delete=$resource->coursemodule\"><IMG 
-                       SRC=\"$CFG->wwwroot/pix/t/delete.gif\" BORDER=0 ALT=Delete></A>
-                    <A HREF=\"$CFG->wwwroot/course/mod.php?update=$resource->coursemodule\"><IMG 
-                       SRC=\"$CFG->wwwroot/pix/t/edit.gif\" BORDER=0 ALT=Update></A>";
-            }
-            $links[] = $link;
-        }
+    $result = true;
+
+    if (! delete_records("resource", "id", "$resource->id")) {
+        $result = false;
     }
 
-    return $links;
+    return $result;
 }
+
 
 function resource_user_outline($course, $user, $mod, $resource) {
     if ($logs = get_records_select("log", "userid='$user->id' AND module='resource' 
@@ -91,47 +98,5 @@ function resource_user_complete($course, $user, $mod, $resource) {
     }
 }
 
-function resource_add_instance($resource) {
-// Given an object containing all the necessary data, 
-// (defined by the form in mod.html) this function 
-// will create a new instance and return the id number 
-// of the new instance.
-
-    $resource->timemodified = time();
-
-    return insert_record("resource", $resource);
-}
-
-
-function resource_update_instance($resource) {
-// Given an object containing all the necessary data, 
-// (defined by the form in mod.html) this function 
-// will update an existing instance with new data.
-
-    $resource->id = $resource->instance;
-    $resource->timemodified = time();
-
-    return update_record("resource", $resource);
-}
-
-
-function resource_delete_instance($id) {
-// Given an ID of an instance of this module, 
-// this function will permanently delete the instance 
-// and any data that depends on it.  
-
-    if (! $resource = get_record("resource", "id", "$id")) {
-        return false;
-    }
-
-    $result = true;
-
-    if (! delete_records("resource", "id", "$resource->id")) {
-        $result = false;
-    }
-
-    return $result;
-}
-
 
 ?>
index 237c85afdd17083f3a78d7f3825ae782b2d921ef..41249f766281dd6a6fa360e984348b985a64f23d 100644 (file)
@@ -28,7 +28,7 @@
     print_header("$course->shortname: $strsurveys", "$course->fullname", "$navigation $strsurveys", 
                  "", "", true, "", navmenu($course));
 
-    if (! $surveys = get_all_instances_in_course("survey", $course->id, "cw.section ASC")) {
+    if (! $surveys = get_all_instances_in_course("survey", $course)) {
         notice("There are no surveys.", "../../course/view.php?id=$course->id");
     }
     
index 552f0f56bb5f3f8ba60dfb9b6db75ddd7f8c3347..304e5655f9a96e7baaadbce46d7868a5aca5b95a 100644 (file)
@@ -26,7 +26,7 @@
 
        print_header("$course->shortname: $strworkshops", "$course->fullname", "$navigation $strworkshops", "", "", true, "", navmenu($course));
 
-    if (! $workshops = get_all_instances_in_course("workshop", $course->id, "cw.section ASC")) {
+    if (! $workshops = get_all_instances_in_course("workshop", $course)) {
         notice("There are no workshops", "../../course/view.php?id=$course->id");
         die;
     }