3 // Display all recent activity in a flexible way
5 require_once("../config.php");
6 require_once("lib.php");
8 $id = required_param('id', PARAM_INT
);
9 $user = optional_param('user', '0', PARAM_INT
);
10 $sortby = optional_param('sortby', 'default', PARAM_ALPHA
);
11 $selectedgroup = optional_param('selectedgroup', 0, PARAM_INT
);
12 $date = optional_param('date', '', PARAM_INT
);
13 $advancedfilter = optional_param('advancedfilter', 0, PARAM_INT
);
14 $modname = optional_param('modname', '', PARAM_ALPHA
); // not used??
15 $modid = optional_param('modid', 'activity/All', PARAM_FILE
); // not a file, but looks like it anyway
16 $modaction = optional_param('modaction', '', PARAM_ALPHA
); // not used??
17 $chooserecent = optional_param('chooserecent', 0, PARAM_INT
);
19 if (! $course = get_record("course", "id", $id) ) {
20 error("That's an invalid course id");
23 require_login($course->id
);
25 add_to_log($course->id
, "course", "recent", "recent.php?id=$course->id", "$course->id");
27 $strrecentactivity = get_string("recentactivity");
28 $meta = '<meta name="robots" content="none" />'; // prevent duplicate content in search engines MDL-7299
30 $loggedinas = user_login_string($course, $USER);
33 if (!empty($chooserecent)) {
34 $userinfo = get_string("allparticipants");
35 $dateinfo = get_string("alldays");
38 if (!$u = get_record("user", "id", $user) ) {
39 error("That's an invalid user!");
41 $userinfo = fullname($u);
44 $dateinfo = userdate($date, get_string("strftimedaydate"));
46 $navlinks[] = array('name' => $strrecentactivity, 'link' => "recent.php?id=$course->id", 'type' => 'misc');
47 $navlinks[] = array('name' => "$userinfo, $dateinfo", 'link' => null, 'type' => 'misc');
48 $navigation = build_navigation($navlinks);
49 print_header("$course->shortname: $strrecentactivity", $course->fullname
, $navigation, "", $meta);
51 print_heading(format_string($course->fullname
) . ": $userinfo, $dateinfo (".usertimezone().")", '', 3);
53 print_recent_selector_form($course, $advancedfilter, $user, $date, $modname, $modid, $modaction, $selectedgroup, $sortby);
57 if (empty($date)) { // no date picked, default to last login time
58 $date = time() - COURSE_MAX_RECENT_PERIOD
;
60 if (!empty($USER->lastcourseaccess
[$course->id
])) {
61 if ($USER->lastcourseaccess
[$course->id
] > $date) {
62 $date = $USER->lastcourseaccess
[$course->id
];
66 $navlinks[] = array('name' => $strrecentactivity, 'link' => null, 'type' => 'misc');
67 $navigation = build_navigation($navlinks);
68 print_header("$course->shortname: $strrecentactivity", $course->fullname
, $navigation, "", $meta);
70 print_heading(get_string("activitysince", "", userdate($date)));
72 print_recent_selector_form($course, $advancedfilter);
79 case "activity/Assignments" : $filter = "assignment"; break;
80 case "activity/Chats" : $filter = "chat"; break;
81 case "activity/Forums" : $filter = "forum"; break;
82 case "activity/Quizzes" : $filter = "quiz"; break;
83 case "activity/Workshops" : $filter = "workshop"; break;
84 default : $filter = "";
87 $activities = array();
90 switch ($course->format
) {
91 case "weeks": $sectiontitle = get_string("week"); break;
92 case "topics": $sectiontitle = get_string("topic"); break;
93 default: $sectiontitle = get_string("section"); break;
98 if (is_numeric($modid)) { // you chose a single activity
100 $sections[0]->sequence
= "$modid";
102 } else { // you chose a group of activities
104 if (has_capability('moodle/course:viewhiddensections', get_context_instance(CONTEXT_COURSE
, $course->id
))) {
107 $hiddenfilter = " AND cs.visible = '1' ";
110 $sections = get_records_sql("SELECT cs.id, cs.section, cs.sequence, cs.summary, cs.visible
111 FROM {$CFG->prefix}course_sections cs
112 WHERE course = '$course->id' $hiddenfilter
116 get_all_mods($course->id
, $mods, $modnames, $modnamesplural, $modnamesused);
118 if (!empty($sections)) {
123 if (!empty($filter)) {
124 $activityfilter = "AND m.name = '$filter'";
126 $activityfilter = "";
129 if (has_capability('moodle/course:viewhiddensections', get_context_instance(CONTEXT_COURSE
, $course->id
))) {
132 $hiddenfilter = " AND cm.visible = '1' ";
135 foreach ($sections as $section) {
137 if ($i <= $course->numsections
) {
138 $activity = new Object;
139 $activity->type
= "section";
141 $activity->name
= $sectiontitle . " $i";
143 $activity->name
= '';
145 $activity->visible
= $section->visible
;
146 $activities[$index] = $activity;
151 $sectionmods = explode(",", $section->sequence
);
153 foreach ($sectionmods as $sectionmod) {
155 if (empty($mods[$sectionmod])) {
158 $mod = $mods[$sectionmod];
159 $instance = get_record("$mod->modname", "id", "$mod->instance");
161 $coursemod = get_record_sql("SELECT m.id, m.name, cm.groupmode, cm.visible, cm.course, cm.groupingid
162 FROM {$CFG->prefix}course_modules cm,
163 {$CFG->prefix}modules m
164 WHERE course = '$course->id' $hiddenfilter
165 AND m.id = cm.module $activityfilter
166 AND cm.id = '$sectionmod'");
167 $groupmode = groups_get_activity_groupmode($coursemod);
168 switch ($groupmode) {
169 case SEPARATEGROUPS
:
171 if ($mygroups = groups_get_all_groups($course->id
, $USER->id
, $coursemode->groupingid
)) {
172 if (array_key_exists($selectedgroup, $mygroups)) {
173 $groupid = $selectedgroup;
178 case VISIBLEGROUPS
: $groupid = $selectedgroup; break;
180 default : $groupid = 0;
183 $libfile = "$CFG->dirroot/mod/$coursemod->name/lib.php";
185 if (file_exists($libfile)) {
186 require_once($libfile);
187 $get_recent_mod_activity = $coursemod->name
."_get_recent_mod_activity";
189 if (function_exists($get_recent_mod_activity)) {
190 $activity = new Object;
191 $activity->type
= "activity";
192 $activity->name
= $instance->name
;
193 $activity->visible
= $coursemod->visible
;
194 $activity->content
->modfullname
= $mod->modfullname
;
195 $activity->content
->modname
= $mod->modname
;
196 $activity->content
->modid
=$mod->id
;
197 $activities[$index] = $activity;
199 $get_recent_mod_activity($activities, $index, $date, $course->id
, $sectionmod, $user, $groupid);
209 case "datedesc" : usort($activities, "compare_activities_by_time_desc"); break;
210 case "dateasc" : usort($activities, "compare_activities_by_time_asc"); break;
212 default : $detail = false; $sortby = "default";
216 if (!empty($activities)) {
226 if (has_capability('moodle/course:viewhiddensections', get_context_instance(CONTEXT_COURSE
, $course->id
))) {
231 $activity_count = count($activities);
233 foreach ($activities as $key => $activity) {
235 // peak at next activity. If it's another section, don't print this one!
236 // this means there are no activities in the current section
237 if (($activity->type
== "section") &&
238 (($activity_count == ($key +
1)) ||
239 ($activities[$key+
1]->type
== "section"))) {
245 if (($activity->type
== "section") && ($sortby == "default")) {
247 print_simple_box_end();
250 print_simple_box_start("center", "90%");
251 echo "<h2>$activity->name</h2>";
254 } else if ($activity->type
== "activity") {
256 if ($sortby == "default") {
257 if ($teacher && $activity->visible
== 0) {
258 $linkformat = 'class="dimmed"';
262 $image = "<img src=\"$CFG->modpixpath/" . $activity->content
->modname
. "/icon.gif\"" .
263 " class=\"icon\" alt=\"" . $activity->content
->modfullname
. "\" />";
264 echo "<ul><h4>$image " . $activity->content
->modfullname
.
265 " <a href=\"$CFG->wwwroot/mod/" . $activity->content
->modname
. "/view.php?" .
266 "id=" . $activity->content
->modid
. "\" $linkformat>" .
267 format_string($activity->name
,true) . "</a></h4></ul>";
273 print_simple_box_start("center", "90%");
277 $print_recent_mod_activity = $activity->type
."_print_recent_mod_activity";
279 if (function_exists($print_recent_mod_activity)) {
281 $print_recent_mod_activity($activity, $course->id
, $detail);
288 print_simple_box_end();
294 echo "<h4><center>" . get_string("norecentactivity") . "</center></h2>";
297 // fix modid for selection form
300 print_footer($course);
302 function compare_activities_by_time_desc($a, $b) {
303 // make sure the activities actually have a timestamp property
304 if ((!object_property_exists($a,'timestamp')) or (!object_property_exists($b,'timestamp'))) {
307 if ($a->timestamp
== $b->timestamp
)
309 return ($a->timestamp
> $b->timestamp
) ?
-1 : 1;
312 function compare_activities_by_time_asc($a, $b) {
313 // make sure the activities actually have a timestamp property
314 if ((!object_property_exists($a,'timestamp')) or (!object_property_exists($b,'timestamp'))) {
317 if ($a->timestamp
== $b->timestamp
)
319 return ($a->timestamp
< $b->timestamp
) ?
-1 : 1;