}
-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;
}
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;
}
/// 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;
}
"$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");
}
}
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";
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
"", "", 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;
}
// 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;
}
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;
}
$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 .= "
- <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'
}
}
-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;
-}
-
?>
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");
}
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;
}