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'");
172 $groupmode = groups_get_activity_groupmode($coursemod);
173 switch ($groupmode) {
174 case SEPARATEGROUPS
:
176 if ($mygroups = groups_get_all_groups($course->id
, $USER->id
, $coursemod->groupingid
)) {
177 if (array_key_exists($selectedgroup, $mygroups)) {
178 $groupid = $selectedgroup;
183 case VISIBLEGROUPS
: $groupid = $selectedgroup; break;
185 default : $groupid = 0;
188 $libfile = "$CFG->dirroot/mod/$coursemod->name/lib.php";
190 if (file_exists($libfile)) {
191 require_once($libfile);
192 $get_recent_mod_activity = $coursemod->name
."_get_recent_mod_activity";
194 if (function_exists($get_recent_mod_activity)) {
195 $activity = new Object;
196 $activity->type
= "activity";
197 $activity->name
= $instance->name
;
198 $activity->visible
= $coursemod->visible
;
199 $activity->content
->modfullname
= $mod->modfullname
;
200 $activity->content
->modname
= $mod->modname
;
201 $activity->content
->modid
=$mod->id
;
202 $activities[$index] = $activity;
204 $get_recent_mod_activity($activities, $index, $date, $course->id
, $sectionmod, $user, $groupid);
214 case "datedesc" : usort($activities, "compare_activities_by_time_desc"); break;
215 case "dateasc" : usort($activities, "compare_activities_by_time_asc"); break;
217 default : $detail = false; $sortby = "default";
221 if (!empty($activities)) {
231 if (has_capability('moodle/course:viewhiddensections', get_context_instance(CONTEXT_COURSE
, $course->id
))) {
236 $activity_count = count($activities);
238 foreach ($activities as $key => $activity) {
240 // peak at next activity. If it's another section, don't print this one!
241 // this means there are no activities in the current section
242 if (($activity->type
== "section") &&
243 (($activity_count == ($key +
1)) ||
244 ($activities[$key+
1]->type
== "section"))) {
250 if (($activity->type
== "section") && ($sortby == "default")) {
252 print_simple_box_end();
255 print_simple_box_start("center", "90%");
256 echo "<h2>$activity->name</h2>";
259 } else if ($activity->type
== "activity") {
261 if ($sortby == "default") {
262 if ($teacher && $activity->visible
== 0) {
263 $linkformat = 'class="dimmed"';
267 $image = "<img src=\"$CFG->modpixpath/" . $activity->content
->modname
. "/icon.gif\"" .
268 " class=\"icon\" alt=\"" . $activity->content
->modfullname
. "\" />";
269 echo "<ul><h4>$image " . $activity->content
->modfullname
.
270 " <a href=\"$CFG->wwwroot/mod/" . $activity->content
->modname
. "/view.php?" .
271 "id=" . $activity->content
->modid
. "\" $linkformat>" .
272 format_string($activity->name
,true) . "</a></h4></ul>";
278 print_simple_box_start("center", "90%");
282 $print_recent_mod_activity = $activity->type
."_print_recent_mod_activity";
284 if (function_exists($print_recent_mod_activity)) {
286 $print_recent_mod_activity($activity, $course->id
, $detail);
293 print_simple_box_end();
299 echo "<h4><center>" . get_string("norecentactivity") . "</center></h2>";
302 // fix modid for selection form
305 print_footer($course);
307 function compare_activities_by_time_desc($a, $b) {
308 // make sure the activities actually have a timestamp property
309 if ((!object_property_exists($a,'timestamp')) or (!object_property_exists($b,'timestamp'))) {
312 if ($a->timestamp
== $b->timestamp
)
314 return ($a->timestamp
> $b->timestamp
) ?
-1 : 1;
317 function compare_activities_by_time_asc($a, $b) {
318 // make sure the activities actually have a timestamp property
319 if ((!object_property_exists($a,'timestamp')) or (!object_property_exists($b,'timestamp'))) {
322 if ($a->timestamp
== $b->timestamp
)
324 return ($a->timestamp
< $b->timestamp
) ?
-1 : 1;