From 4581271ad10480202183cc5e53e47f08e344258c Mon Sep 17 00:00:00 2001 From: selliott Date: Sun, 15 Feb 2004 06:11:15 +0000 Subject: [PATCH] Changed selector form in course/lib.php for course/recent.php Rewrote course/recent.php to allow sorting of data before it is output --- course/lib.php | 94 ++++++++++++++++++----- course/recent.php | 188 +++++++++++++++++++++++++++++++++++----------- 2 files changed, 217 insertions(+), 65 deletions(-) diff --git a/course/lib.php b/course/lib.php index 8db9a94439..0868eedd81 100644 --- a/course/lib.php +++ b/course/lib.php @@ -20,31 +20,30 @@ define("FRONTPAGENEWS", 0); define("FRONTPAGECOURSELIST", 1); define("FRONTPAGECATEGORYNAMES", 2); -function print_recent_selector_form($course, $selecteduser=0, $selecteddate="today", - $mod="", $modid=0, $modaction="") { +function print_recent_selector_form($course, $selecteduser=0, $selecteddate="lastlogin", + $mod="", $modid="activity/All", $modaction="", $selectedgroup="", $selectedsort="default") { global $USER, $CFG; - $isteacher = isteacher($course->id); // Get all the possible users $users = array(); - + if ($course->category) { $courseusers = get_course_users($course->id); } else { $courseusers = get_site_users("u.lastaccess DESC", "u.id, u.firstname, u.lastname"); - } - + } + if ($courseusers) { foreach ($courseusers as $courseuser) { $users[$courseuser->id] = fullname($courseuser, $isteacher); } - } + } if ($guest = get_guest()) { $users[$guest->id] = fullname($guest); } - + if (isadmin()) { if ($ccc = get_records("course", "", "", "fullname")) { foreach ($ccc as $cc) { @@ -52,26 +51,37 @@ function print_recent_selector_form($course, $selecteduser=0, $selecteddate="tod $courses["$cc->id"] = "$cc->fullname"; } else { $courses["$cc->id"] = " $cc->fullname (Site)"; - } + } } - } + } asort($courses); } $activities = array(); - $selectedactivity = ""; + + $selectedactivity = $modid; if ($modinfo = unserialize($course->modinfo)) { $section = 0; - if ($course->format == 'weeks') { // Bodgy + if ($course->format == 'weeks') { // Body $strsection = get_string("week"); } else { $strsection = get_string("topic"); } + + $activities["activity/All"] = "All activities"; + $activities["activity/Assignments"] = "All assignments"; + $activities["activity/Chats"] = "All chats"; + $activities["activity/Forums"] = "All forums"; + $activities["activity/Quizzes"] = "All quizzes"; + $activities["activity/Workshops"] = "All workshops"; + + $activities["section/individual"] = "------------- Individual Activities --------------"; + foreach ($modinfo as $mod) { if ($mod->mod == "label") { continue; - } + } if ($mod->section > 0 and $section <> $mod->section) { $activities["section/$mod->section"] = "-------------- $strsection $mod->section --------------"; } @@ -105,8 +115,9 @@ function print_recent_selector_form($course, $selecteduser=0, $selecteddate="tod // What day is it now for the user, and when is midnight that day (in GMT). $timemidnight = $today = usergetmidnight($timenow); - // Put today up the top of the list - $dates = array("$timemidnight" => get_string("today").", ".userdate($timenow, $strftimedate) ); + $dates = array(); + $dates["$USER->lastlogin"] = get_string("lastlogin").", ".userdate($USER->lastlogin, $strftimedate); + $dates["$timemidnight"] = get_string("today").", ".userdate($timenow, $strftimedate); if (!$course->startdate or ($course->startdate > $timenow)) { $course->startdate = $course->timecreated; @@ -120,24 +131,67 @@ function print_recent_selector_form($course, $selecteduser=0, $selecteddate="tod $numdates++; } - if ($selecteddate == "today") { - $selecteddate = $today; + if ($selecteddate == "lastlogin") { + $selecteddate = $USER->lastlogin; } - echo '
'; echo '
'; echo ''; + echo "
"; + echo ""; + if (isadmin()) { + echo ""; } else { echo "id\">"; } + + $sortfields = array("default" => "By course order","dateasc" => "Date - Most recent last", "datedesc" => "Date - Most recent first"); + + echo ""; + + echo ""; + + echo ""; + + echo ""; + + echo ''; + + $groupmode = groupmode($course); + + if ($groupmode == VISIBLEGROUPS or ($groupmode and isteacheredit($course->id))) { + if ($groups = get_records_menu("groups", "courseid", $course->id, "name ASC", "id,name")) { + echo ''; + } + } + + + echo ""; + + echo "
" . get_string("courses") . ""; choose_from_menu ($courses, "id", $course->id, ""); + echo "
" . get_string("participants") . ""; choose_from_menu ($users, "user", $selecteduser, get_string("allparticipants") ); + echo "" . get_string("since") . ""; choose_from_menu ($dates, "date", $selecteddate, get_string("alldays")); - choose_from_menu ($activities, "modid", $selectedactivity, get_string("allactivities"), "", ""); + echo "
" . get_string("activities") . ""; + choose_from_menu ($activities, "modid", $selectedactivity, ""); + echo "" . get_string("sortby") . ""; + choose_from_menu ($sortfields, "sortby", $selectedsort, ""); + echo "
'; + if ($groupmode == VISIBLEGROUPS) { + print_string('groupsvisible'); + } else { + print_string('groupsseparate'); + } + echo ':'; + choose_from_menu($groups, "selectedgroup", $selectedgroup, get_string("allgroups"), "", ""); + echo '"; echo ""; - echo ""; + echo "
"; echo "
"; + echo ""; } function print_log_selector_form($course, $selecteduser=0, $selecteddate="today", diff --git a/course/recent.php b/course/recent.php index cfaa154544..8fa4ae167b 100644 --- a/course/recent.php +++ b/course/recent.php @@ -46,7 +46,7 @@ } print_heading("$course->fullname: $userinfo, $dateinfo (".usertimezone().")"); - print_recent_selector_form($course, $user, $date, $modname, $modid, $modaction); + print_recent_selector_form($course, $user, $date, $modname, $modid, $modaction, $selectedgroup, $sortby); } else { @@ -68,65 +68,163 @@ } - get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused); + $tmpmodid = $modid; - $sections = get_all_sections($course->id); + switch ($tmpmodid) { + case "activity/Assignments" : $filter = "assignment"; break; + case "activity/Chats" : $filter = "chat"; break; + case "activity/Forums" : $filter = "forum"; break; + case "activity/Quizzes" : $filter = "quiz"; break; + case "activity/Workshops" : $filter = "workshop"; break; + default : $filter = ""; + } - for ($i=0; $i<=$course->numsections; $i++) { + if (!empty($filter)) { + $activityfilter = "AND m.name = '$filter'"; + } else { + $activityfilter = ""; + } - if (isset($sections[$i]) && $sections[$i]->visible) { + $activities = array(); + $sections = array(); - $section = $sections[$i]; - - if ($section->sequence) { - echo "
"; - echo "

"; - switch ($course->format) { - case "weeks": print_string("week"); break; - case "topics": print_string("topic"); break; - default: print_string("section"); break; - } - echo " $i

"; + $index = 0; - echo "
    "; + if (is_numeric($modid)) { // you chose a single activity - $sectionmods = explode(",", $section->sequence); + $sections[0]->sequence = "$modid"; - foreach ($sectionmods as $sectionmod) { - if (empty($mods[$sectionmod])) { - continue; - } - $mod = $mods[$sectionmod]; - - $instance = get_record("$mod->modname", "id", "$mod->instance"); - $libfile = "$CFG->dirroot/mod/$mod->modname/lib.php"; - - if (file_exists($libfile)) { - require_once($libfile); - $print_recent_instance_activity = $mod->modname."_print_recent_instance_activity"; - - // fix modid if a section (or week) is selected, may want to enhance to get all mods from section (or week) - if (!is_numeric($modid)) - $modid = ""; - - if (function_exists($print_recent_instance_activity) && (($mod->id == $modid) || (empty($modid)))) { - $image = "modpixpath/$mod->modname/icon.gif\" ". - "height=16 width=16 alt=\"$mod->modfullname\">"; - echo "

    $image $mod->modfullname: ". - "wwwroot/mod/$mod->modname/view.php?id=$mod->id\">". - "$instance->name

    "; - echo "
      "; - $print_recent_instance_activity($instance, $date, $user); - echo "
    "; - } + } else { // you chose a group of activities + + $sections = get_records_sql("SELECT cs.id, cs.section, cs.sequence + FROM {$CFG->prefix}course_sections cs + WHERE course = '$course->id' + AND cs.visible = '1' + AND sequence != '' + ORDER by section"); + } + + if (!empty($sections)) { + + echo "
    "; + + foreach ($sections as $section) { + $sectionmods = explode(",", $section->sequence); + + foreach ($sectionmods as $sectionmod) { + $coursemod = get_record_sql("SELECT m.id, m.name, cm.groupmode + FROM {$CFG->prefix}course_modules cm, + {$CFG->prefix}modules m + WHERE course = '$course->id' + AND m.id = cm.module $activityfilter + AND cm.id = '$sectionmod'"); + + $groupmode = groupmode($course, $coursemod); + switch ($groupmode) { + case SEPARATEGROUPS : $groupid = mygroupid($course->id); break; + case VISIBLEGROUPS : + if ($selectedgroup == "allgroups") { + $groupid == ""; + } else { + $groupid = $selectedgroup; + } + break; + case NOGROUPS : + default : $groupid = ""; + } + + $libfile = "$CFG->dirroot/mod/$coursemod->name/lib.php"; + + if (file_exists($libfile)) { + require_once($libfile); + $get_recent_mod_activity = $coursemod->name."_get_recent_mod_activity"; + + if (function_exists($get_recent_mod_activity)) { + $get_recent_mod_activity($activities, $index, $date, $course->id, $sectionmod, $user, $groupid); } } + } + } + } + + $detail = true; + + switch ($sortby) { + case "datedesc" : usort($activities, "compare_activities_by_time_desc"); break; + case "dateasc" : usort($activities, "compare_activities_by_time_asc"); break; + case "default" : + default : $detail = false; $sortby = "default"; + + } + + if (!empty($activities)) { + + echo "
      "; + $newsection = true; + $lastsection = ""; + $newinstance = true; + $lastinstance = ""; + + switch ($course->format) { + case "weeks": $sectiontitle = get_string("week"); break; + case "topics": $sectiontitle = get_string("topic"); break; + default: $sectiontitle = get_string("section"); break; + } + + echo "
      "; + foreach ($activities as $activity) { + + if ($sortby == "default") { + if ($lastsection != $activity->section) { + $lastsection = $activity->section; + $newsection = true; + } + if ($newsection) { +// echo "

      $sectiontitle: $activity->section

      "; + $newsection = false; + } + if ($lastinstance != $activity->instance) { + $lastinstance = $activity->instance; + $newinstance = true; + } + if ($newinstance) { + $image = "modpixpath/$activity->type/icon.gif\" ". + "height=16 width=16 alt=\"$activity->type\">"; + echo "

      $image " . $activity->name . "

      "; + + $newinstance = false; + } + + } + + $print_recent_mod_activity = $activity->type."_print_recent_mod_activity"; + + if (function_exists($print_recent_mod_activity)) { + echo "
        "; + $print_recent_mod_activity($activity, $course->id, $detail); echo "
      "; } } + echo "
    "; + } else { + echo "

    " . get_string("norecentactivity") . "

    "; } +// fix modid for selection form + $modid =$tmpmodid; + print_footer($course); +function compare_activities_by_time_desc($a, $b) { + if ($a->timestamp == $b->timestamp) + return 0; + return ($a->timestamp > $b->timestamp) ? -1 : 1; +} + +function compare_activities_by_time_asc($a, $b) { + if ($a->timestamp == $b->timestamp) + return 0; + return ($a->timestamp < $b->timestamp) ? -1 : 1; +} ?> -- 2.39.5