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()
This commit is contained in:
+26
-11
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
+1
-1
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
@@ -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";
|
||||
|
||||
+1
-1
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
+1
-1
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
+35
-70
@@ -21,76 +21,6 @@ $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;
|
||||
|
||||
if ($courseid) {
|
||||
if (! $course = get_record("course", "id", $courseid)) {
|
||||
error("Could not find the specified course");
|
||||
}
|
||||
|
||||
require_login($course->id);
|
||||
|
||||
} else {
|
||||
if (! $course = get_record("course", "category", 0)) {
|
||||
error("Could not find a top-level course!");
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
return $links;
|
||||
}
|
||||
|
||||
|
||||
function resource_user_outline($course, $user, $mod, $resource) {
|
||||
if ($logs = get_records_select("log", "userid='$user->id' AND module='resource'
|
||||
AND action='view' AND info='$resource->id'", "time ASC")) {
|
||||
|
||||
$numviews = count($logs);
|
||||
$lastlog = array_pop($logs);
|
||||
|
||||
$result->info = get_string("numviews", "", $numviews);
|
||||
$result->time = $lastlog->time;
|
||||
|
||||
return $result;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
function resource_user_complete($course, $user, $mod, $resource) {
|
||||
global $CFG, $THEME;
|
||||
|
||||
if ($logs = get_records_select("log", "userid='$user->id' AND module='resource'
|
||||
AND action='view' AND info='$resource->id'", "time ASC")) {
|
||||
$numviews = count($logs);
|
||||
$lastlog = array_pop($logs);
|
||||
|
||||
$strmostrecently = get_string("mostrecently");
|
||||
$strnumviews = get_string("numviews", "", $numviews);
|
||||
|
||||
echo "$strnumviews - $strmostrecently ".userdate($lastlog->time);
|
||||
|
||||
} else {
|
||||
print_string("neverseen", "resource");
|
||||
}
|
||||
}
|
||||
|
||||
function resource_add_instance($resource) {
|
||||
// Given an object containing all the necessary data,
|
||||
// (defined by the form in mod.html) this function
|
||||
@@ -134,4 +64,39 @@ function resource_delete_instance($id) {
|
||||
}
|
||||
|
||||
|
||||
function resource_user_outline($course, $user, $mod, $resource) {
|
||||
if ($logs = get_records_select("log", "userid='$user->id' AND module='resource'
|
||||
AND action='view' AND info='$resource->id'", "time ASC")) {
|
||||
|
||||
$numviews = count($logs);
|
||||
$lastlog = array_pop($logs);
|
||||
|
||||
$result->info = get_string("numviews", "", $numviews);
|
||||
$result->time = $lastlog->time;
|
||||
|
||||
return $result;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
function resource_user_complete($course, $user, $mod, $resource) {
|
||||
global $CFG, $THEME;
|
||||
|
||||
if ($logs = get_records_select("log", "userid='$user->id' AND module='resource'
|
||||
AND action='view' AND info='$resource->id'", "time ASC")) {
|
||||
$numviews = count($logs);
|
||||
$lastlog = array_pop($logs);
|
||||
|
||||
$strmostrecently = get_string("mostrecently");
|
||||
$strnumviews = get_string("numviews", "", $numviews);
|
||||
|
||||
echo "$strnumviews - $strmostrecently ".userdate($lastlog->time);
|
||||
|
||||
} else {
|
||||
print_string("neverseen", "resource");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
?>
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user