| [ Index ] |
PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008] |
[Summary view] [Print] [Text view]
1 <?php // $Id: recent.php,v 1.34.2.3 2008/07/05 20:57:09 skodak Exp $ 2 3 // Display all recent activity in a flexible way 4 5 require_once ('../config.php'); 6 require_once ('lib.php'); 7 require_once ('recent_form.php'); 8 9 $id = required_param('id', PARAM_INT); 10 11 if (!$course = get_record('course', 'id', $id) ) { 12 error("That's an invalid course id"); 13 } 14 15 require_login($course); 16 17 add_to_log($course->id, "course", "recent", "recent.php?id=$course->id", $course->id); 18 19 $context = get_context_instance(CONTEXT_COURSE, $course->id); 20 21 $meta = '<meta name="robots" content="none" />'; // prevent duplicate content in search engines MDL-7299 22 23 $lastlogin = time() - COURSE_MAX_RECENT_PERIOD; 24 if (!isguestuser() and !empty($USER->lastcourseaccess[$COURSE->id])) { 25 if ($USER->lastcourseaccess[$COURSE->id] > $lastlogin) { 26 $lastlogin = $USER->lastcourseaccess[$COURSE->id]; 27 } 28 } 29 30 $param = new object(); 31 $param->user = 0; 32 $param->modid = 'all'; 33 $param->group = 0; 34 $param->sortby = 'default'; 35 $param->date = $lastlogin; 36 $param->id = $COURSE->id; 37 38 $mform = new recent_form(); 39 $mform->set_data($param); 40 if ($formdata = $mform->get_data(false)) { 41 $param = $formdata; 42 } 43 44 $userinfo = get_string('allparticipants'); 45 $dateinfo = get_string('alldays'); 46 47 if (!empty($param->user)) { 48 if (!$u = get_record('user', 'id', $param->user) ) { 49 error("That's an invalid user!"); 50 } 51 $userinfo = fullname($u); 52 } 53 54 $strrecentactivity = get_string('recentactivity'); 55 $navlinks = array(); 56 $navlinks[] = array('name' => $strrecentactivity, 'link' => "recent.php?id=$course->id", 'type' => 'misc'); 57 $navlinks[] = array('name' => $userinfo, 'link' => null, 'type' => 'misc'); 58 $navigation = build_navigation($navlinks); 59 print_header("$course->shortname: $strrecentactivity", $course->fullname, $navigation, '', $meta); 60 print_heading(format_string($course->fullname) . ": $userinfo", '', 3); 61 62 $mform->display(); 63 64 $modinfo =& get_fast_modinfo($course); 65 get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused); 66 67 if (has_capability('moodle/course:viewhiddensections', $context)) { 68 $hiddenfilter = ""; 69 } else { 70 $hiddenfilter = "AND cs.visible = 1"; 71 } 72 $sections = array(); 73 if ($ss = get_records_sql("SELECT cs.id, cs.section, cs.sequence, cs.summary, cs.visible 74 FROM {$CFG->prefix}course_sections cs 75 WHERE cs.course = $course->id AND cs.section <= $course->numsections 76 $hiddenfilter 77 ORDER BY section")) { 78 foreach ($ss as $section) { 79 $sections[$section->section] = $section; 80 } 81 } 82 83 if ($param->modid === 'all') { 84 // ok 85 86 } else if (strpos($param->modid, 'mod/') === 0) { 87 $modname = substr($param->modid, strlen('mod/')); 88 if (array_key_exists($modname, $modnames) and file_exists("$CFG->dirroot/mod/$modname/lib.php")) { 89 $filter = $modname; 90 } 91 92 } else if (strpos($param->modid, 'section/') === 0) { 93 $sectionid = substr($param->modid, strlen('section/')); 94 if (isset($sections[$sectionid])) { 95 $sections = array($sectionid=>$sections[$sectionid]); 96 } 97 98 } else if (is_numeric($param->modid)) { 99 $section = $sections[$modinfo->cms[$param->modid]->sectionnum]; 100 $section->sequence = $param->modid; 101 $sections = array($section->sequence=>$section); 102 } 103 104 switch ($course->format) { 105 case 'weeks': $sectiontitle = get_string('week'); break; 106 case 'topics': $sectiontitle = get_string('topic'); break; 107 default: $sectiontitle = get_string('section'); break; 108 } 109 110 if (is_null($modinfo->groups)) { 111 $modinfo->groups = groups_get_user_groups($course->id); // load all my groups and cache it in modinfo 112 } 113 114 $activities = array(); 115 $index = 0; 116 117 foreach ($sections as $section) { 118 119 $activity = new object(); 120 $activity->type = 'section'; 121 if ($section->section > 0) { 122 $activity->name = $sectiontitle.' '.$section->section; 123 } else { 124 $activity->name = ''; 125 } 126 127 $activity->visible = $section->visible; 128 $activities[$index++] = $activity; 129 130 if (empty($section->sequence)) { 131 continue; 132 } 133 134 $sectionmods = explode(",", $section->sequence); 135 136 foreach ($sectionmods as $cmid) { 137 if (!isset($mods[$cmid]) or !isset($modinfo->cms[$cmid])) { 138 continue; 139 } 140 141 $cm = $modinfo->cms[$cmid]; 142 143 if (!$cm->uservisible) { 144 continue; 145 } 146 147 if (!empty($filter) and $cm->modname != $filter) { 148 continue; 149 } 150 151 $libfile = "$CFG->dirroot/mod/$cm->modname/lib.php"; 152 153 if (file_exists($libfile)) { 154 require_once($libfile); 155 $get_recent_mod_activity = $cm->modname."_get_recent_mod_activity"; 156 157 if (function_exists($get_recent_mod_activity)) { 158 $activity = new object(); 159 $activity->type = 'activity'; 160 $activity->cmid = $cmid; 161 $activities[$index++] = $activity; 162 $get_recent_mod_activity($activities, $index, $param->date, $course->id, $cmid, $param->user, $param->group); 163 } 164 } 165 } 166 } 167 168 $detail = true; 169 170 switch ($param->sortby) { 171 case 'datedesc' : usort($activities, 'compare_activities_by_time_desc'); break; 172 case 'dateasc' : usort($activities, 'compare_activities_by_time_asc'); break; 173 case 'default' : 174 default : $detail = false; $param->sortby = 'default'; 175 176 } 177 178 if (!empty($activities)) { 179 180 $newsection = true; 181 $lastsection = ''; 182 $newinstance = true; 183 $lastinstance = ''; 184 $inbox = false; 185 186 $section = 0; 187 188 $activity_count = count($activities); 189 $viewfullnames = array(); 190 191 foreach ($activities as $key => $activity) { 192 193 if ($activity->type == 'section') { 194 if ($param->sortby != 'default') { 195 continue; // no section if ordering by date 196 } 197 if ($activity_count == ($key + 1) or $activities[$key+1]->type == 'section') { 198 // peak at next activity. If it's another section, don't print this one! 199 // this means there are no activities in the current section 200 continue; 201 } 202 } 203 204 if (($activity->type == 'section') && ($param->sortby == 'default')) { 205 if ($inbox) { 206 print_simple_box_end(); 207 print_spacer(30); 208 } 209 print_simple_box_start('center', '90%'); 210 echo "<h2>$activity->name</h2>"; 211 $inbox = true; 212 213 } else if ($activity->type == 'activity') { 214 215 if ($param->sortby == 'default') { 216 $cm = $modinfo->cms[$activity->cmid]; 217 218 if ($cm->visible) { 219 $linkformat = ''; 220 } else { 221 $linkformat = 'class="dimmed"'; 222 } 223 $name = format_string($cm->name); 224 $modfullname = $modnames[$cm->modname]; 225 226 $image = "<img src=\"$CFG->modpixpath/$cm->modname/icon.gif\" class=\"icon\" alt=\"$modfullname\" />"; 227 echo "<h4>$image $modfullname". 228 " <a href=\"$CFG->wwwroot/mod/$cm->modname/view.php?id=$cm->id\" $linkformat>$name</a></h4>"; 229 } 230 231 } else { 232 233 if (!isset($viewfullnames[$activity->cmid])) { 234 $cm_context = get_context_instance(CONTEXT_MODULE, $activity->cmid); 235 $viewfullnames[$activity->cmid] = has_capability('moodle/site:viewfullnames', $cm_context); 236 } 237 238 if (!$inbox) { 239 print_simple_box_start('center', '90%'); 240 $inbox = true; 241 } 242 243 $print_recent_mod_activity = $activity->type.'_print_recent_mod_activity'; 244 245 if (function_exists($print_recent_mod_activity)) { 246 $print_recent_mod_activity($activity, $course->id, $detail, $modnames, $viewfullnames[$activity->cmid]); 247 } 248 } 249 } 250 251 if ($inbox) { 252 print_simple_box_end(); 253 } 254 255 256 } else { 257 258 echo '<h4><center>' . get_string('norecentactivity') . '</center></h2>'; 259 260 } 261 262 print_footer($course); 263 264 function compare_activities_by_time_desc($a, $b) { 265 // make sure the activities actually have a timestamp property 266 if ((!array_key_exists('timestamp', $a)) or (!array_key_exists('timestamp', $b))) { 267 return 0; 268 } 269 if ($a->timestamp == $b->timestamp) 270 return 0; 271 return ($a->timestamp > $b->timestamp) ? -1 : 1; 272 } 273 274 function compare_activities_by_time_asc($a, $b) { 275 // make sure the activities actually have a timestamp property 276 if ((!array_key_exists('timestamp', $a)) or (!array_key_exists('timestamp', $b))) { 277 return 0; 278 } 279 if ($a->timestamp == $b->timestamp) 280 return 0; 281 return ($a->timestamp < $b->timestamp) ? -1 : 1; 282 } 283 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Wed Jan 14 11:33:29 2009 | Cross-referenced by PHPXref 0.7 |