From cccb016ae4ae5522f8a9318203486fd31491dcd2 Mon Sep 17 00:00:00 2001 From: moodler Date: Sat, 12 Jul 2003 05:19:18 +0000 Subject: [PATCH] When displaying index lists of a particular module's activities, 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() --- lib/datalib.php | 37 +++++++++----- mod/assignment/index.php | 2 +- mod/chat/index.php | 2 +- mod/choice/index.php | 2 +- mod/forum/discuss.php | 2 +- mod/forum/index.php | 2 +- mod/journal/index.php | 2 +- mod/quiz/index.php | 2 +- mod/resource/index.php | 8 +-- mod/resource/lib.php | 103 +++++++++++++-------------------------- mod/survey/index.php | 2 +- mod/workshop/index.php | 2 +- 12 files changed, 70 insertions(+), 96 deletions(-) diff --git a/lib/datalib.php b/lib/datalib.php index 2663acf56a..cb938e0846 100644 --- a/lib/datalib.php +++ b/lib/datalib.php @@ -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; } diff --git a/mod/assignment/index.php b/mod/assignment/index.php index d15d8dfebd..b071b423ca 100644 --- a/mod/assignment/index.php +++ b/mod/assignment/index.php @@ -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; } diff --git a/mod/chat/index.php b/mod/chat/index.php index 2d9e0bd168..f411248b96 100644 --- a/mod/chat/index.php +++ b/mod/chat/index.php @@ -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; } diff --git a/mod/choice/index.php b/mod/choice/index.php index afcff8d1c0..a4784c24be 100644 --- a/mod/choice/index.php +++ b/mod/choice/index.php @@ -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"); } diff --git a/mod/forum/discuss.php b/mod/forum/discuss.php index 88ebc0e72f..a5f24a3fce 100644 --- a/mod/forum/discuss.php +++ b/mod/forum/discuss.php @@ -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"; diff --git a/mod/forum/index.php b/mod/forum/index.php index 4414a6f528..ffc6d7dea8 100644 --- a/mod/forum/index.php +++ b/mod/forum/index.php @@ -115,7 +115,7 @@ 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 diff --git a/mod/journal/index.php b/mod/journal/index.php index 9504d38879..838c8d63ea 100644 --- a/mod/journal/index.php +++ b/mod/journal/index.php @@ -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; } diff --git a/mod/quiz/index.php b/mod/quiz/index.php index 20b1e46742..b2153d63ea 100644 --- a/mod/quiz/index.php +++ b/mod/quiz/index.php @@ -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; } diff --git a/mod/resource/index.php b/mod/resource/index.php index f235040fd6..e855f46536 100644 --- a/mod/resource/index.php +++ b/mod/resource/index.php @@ -26,13 +26,7 @@ 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; } diff --git a/mod/resource/lib.php b/mod/resource/lib.php index 8e54de4d0a..c72f4e49ca 100644 --- a/mod/resource/lib.php +++ b/mod/resource/lib.php @@ -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 = "wwwroot/mod/resource/view.php?id=$resource->coursemodule\">$resource->name"; - if ($USER->editing) { - $link .= "    - wwwroot/course/mod.php?delete=$resource->coursemodule\">wwwroot/pix/t/delete.gif\" BORDER=0 ALT=Delete> - wwwroot/course/mod.php?update=$resource->coursemodule\">wwwroot/pix/t/edit.gif\" BORDER=0 ALT=Update>"; - } - $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; -} - ?> diff --git a/mod/survey/index.php b/mod/survey/index.php index 237c85afdd..41249f7662 100644 --- a/mod/survey/index.php +++ b/mod/survey/index.php @@ -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"); } diff --git a/mod/workshop/index.php b/mod/workshop/index.php index 552f0f56bb..304e5655f9 100644 --- a/mod/workshop/index.php +++ b/mod/workshop/index.php @@ -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; } -- 2.39.5