Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/course/recent.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00026 require_once('../config.php');
00027 require_once('lib.php');
00028 require_once('recent_form.php');
00029 
00030 $id = required_param('id', PARAM_INT);
00031 
00032 $PAGE->set_url('/course/recent.php', array('id'=>$id));
00033 
00034 if (!$course = $DB->get_record('course', array('id'=>$id))) {
00035     print_error("That's an invalid course id");
00036 }
00037 
00038 require_login($course);
00039 
00040 add_to_log($course->id, "course", "recent", "recent.php?id=$course->id", $course->id);
00041 
00042 $context = get_context_instance(CONTEXT_COURSE, $course->id);
00043 
00044 $lastlogin = time() - COURSE_MAX_RECENT_PERIOD;
00045 if (!isguestuser() and !empty($USER->lastcourseaccess[$COURSE->id])) {
00046     if ($USER->lastcourseaccess[$COURSE->id] > $lastlogin) {
00047         $lastlogin = $USER->lastcourseaccess[$COURSE->id];
00048     }
00049 }
00050 
00051 $param = new stdClass();
00052 $param->user   = 0;
00053 $param->modid  = 'all';
00054 $param->group  = 0;
00055 $param->sortby = 'default';
00056 $param->date   = $lastlogin;
00057 $param->id     = $COURSE->id;
00058 
00059 $mform = new recent_form();
00060 $mform->set_data($param);
00061 if ($formdata = $mform->get_data()) {
00062     $param = $formdata;
00063 }
00064 
00065 $userinfo = get_string('allparticipants');
00066 $dateinfo = get_string('alldays');
00067 
00068 if (!empty($param->user)) {
00069     if (!$u = $DB->get_record('user', array('id'=>$param->user))) {
00070         print_error("That's an invalid user!");
00071     }
00072     $userinfo = fullname($u);
00073 }
00074 
00075 $strrecentactivity = get_string('recentactivity');
00076 $PAGE->navbar->add($strrecentactivity, new moodle_url('/course/recent.php', array('id'=>$course->id)));
00077 $PAGE->navbar->add($userinfo);
00078 $PAGE->set_title("$course->shortname: $strrecentactivity");
00079 $PAGE->set_heading($course->fullname);
00080 echo $OUTPUT->header();
00081 echo $OUTPUT->heading(format_string($course->fullname) . ": $userinfo", 3);
00082 
00083 $mform->display();
00084 
00085 $modinfo =& get_fast_modinfo($course);
00086 get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
00087 
00088 if (has_capability('moodle/course:viewhiddensections', $context)) {
00089     $hiddenfilter = "";
00090 } else {
00091     $hiddenfilter = "AND cs.visible = 1";
00092 }
00093 $sections = array();
00094 $rawsections = array_slice(get_all_sections($course->id), 0, $course->numsections+1, true);
00095 $canviewhidden = has_capability('moodle/course:viewhiddensections', $context);
00096 foreach ($rawsections as $section) {
00097     if ($canviewhidden || !empty($section->visible)) {
00098         $sections[$section->section] = $section;
00099     }
00100 }
00101 
00102 if ($param->modid === 'all') {
00103     // ok
00104 
00105 } else if (strpos($param->modid, 'mod/') === 0) {
00106     $modname = substr($param->modid, strlen('mod/'));
00107     if (array_key_exists($modname, $modnames) and file_exists("$CFG->dirroot/mod/$modname/lib.php")) {
00108         $filter = $modname;
00109     }
00110 
00111 } else if (strpos($param->modid, 'section/') === 0) {
00112     $sectionid = substr($param->modid, strlen('section/'));
00113     if (isset($sections[$sectionid])) {
00114         $sections = array($sectionid=>$sections[$sectionid]);
00115     }
00116 
00117 } else if (is_numeric($param->modid)) {
00118     $section = $sections[$modinfo->cms[$param->modid]->sectionnum];
00119     $section->sequence = $param->modid;
00120     $sections = array($section->sequence=>$section);
00121 }
00122 
00123 
00124 if (is_null($modinfo->groups)) {
00125     $modinfo->groups = groups_get_user_groups($course->id); // load all my groups and cache it in modinfo
00126 }
00127 
00128 $activities = array();
00129 $index = 0;
00130 
00131 foreach ($sections as $section) {
00132 
00133     $activity = new stdClass();
00134     $activity->type = 'section';
00135     if ($section->section > 0) {
00136         $activity->name = get_section_name($course, $section);
00137     } else {
00138         $activity->name = '';
00139     }
00140 
00141     $activity->visible = $section->visible;
00142     $activities[$index++] = $activity;
00143 
00144     if (empty($section->sequence)) {
00145         continue;
00146     }
00147 
00148     $sectionmods = explode(",", $section->sequence);
00149 
00150     foreach ($sectionmods as $cmid) {
00151         if (!isset($mods[$cmid]) or !isset($modinfo->cms[$cmid])) {
00152             continue;
00153         }
00154 
00155         $cm = $modinfo->cms[$cmid];
00156 
00157         if (!$cm->uservisible) {
00158             continue;
00159         }
00160 
00161         if (!empty($filter) and $cm->modname != $filter) {
00162             continue;
00163         }
00164 
00165         $libfile = "$CFG->dirroot/mod/$cm->modname/lib.php";
00166 
00167         if (file_exists($libfile)) {
00168             require_once($libfile);
00169             $get_recent_mod_activity = $cm->modname."_get_recent_mod_activity";
00170 
00171             if (function_exists($get_recent_mod_activity)) {
00172                 $activity = new stdClass();
00173                 $activity->type    = 'activity';
00174                 $activity->cmid    = $cmid;
00175                 $activities[$index++] = $activity;
00176                 $get_recent_mod_activity($activities, $index, $param->date, $course->id, $cmid, $param->user, $param->group);
00177             }
00178         }
00179     }
00180 }
00181 
00182 $detail = true;
00183 
00184 switch ($param->sortby) {
00185     case 'datedesc' : usort($activities, 'compare_activities_by_time_desc'); break;
00186     case 'dateasc'  : usort($activities, 'compare_activities_by_time_asc'); break;
00187     case 'default'  :
00188     default         : $detail = false; $param->sortby = 'default';
00189 
00190 }
00191 
00192 if (!empty($activities)) {
00193 
00194     $newsection   = true;
00195     $lastsection  = '';
00196     $newinstance  = true;
00197     $lastinstance = '';
00198     $inbox        = false;
00199 
00200     $section = 0;
00201 
00202     $activity_count = count($activities);
00203     $viewfullnames  = array();
00204 
00205     foreach ($activities as $key => $activity) {
00206 
00207         if ($activity->type == 'section') {
00208             if ($param->sortby != 'default') {
00209                 continue; // no section if ordering by date
00210             }
00211             if ($activity_count == ($key + 1) or $activities[$key+1]->type == 'section') {
00212             // peak at next activity.  If it's another section, don't print this one!
00213             // this means there are no activities in the current section
00214                 continue;
00215             }
00216         }
00217 
00218         if (($activity->type == 'section') && ($param->sortby == 'default')) {
00219             if ($inbox) {
00220                 echo $OUTPUT->box_end();
00221                 echo $OUTPUT->spacer(array('height'=>30, 'br'=>true)); // should be done with CSS instead
00222             }
00223             echo $OUTPUT->box_start();
00224             echo "<h2>$activity->name</h2>";
00225             $inbox = true;
00226 
00227         } else if ($activity->type == 'activity') {
00228 
00229             if ($param->sortby == 'default') {
00230                 $cm = $modinfo->cms[$activity->cmid];
00231 
00232                 if ($cm->visible) {
00233                     $linkformat = '';
00234                 } else {
00235                     $linkformat = 'class="dimmed"';
00236                 }
00237                 $name        = format_string($cm->name);
00238                 $modfullname = $modnames[$cm->modname];
00239 
00240                 $image = "<img src=\"" . $OUTPUT->pix_url('icon', $cm->modname) . "\" class=\"icon\" alt=\"$modfullname\" />";
00241                 echo "<h4>$image $modfullname".
00242                      " <a href=\"$CFG->wwwroot/mod/$cm->modname/view.php?id=$cm->id\" $linkformat>$name</a></h4>";
00243            }
00244 
00245         } else {
00246 
00247             if (!isset($viewfullnames[$activity->cmid])) {
00248                 $cm_context = get_context_instance(CONTEXT_MODULE, $activity->cmid);
00249                 $viewfullnames[$activity->cmid] = has_capability('moodle/site:viewfullnames', $cm_context);
00250             }
00251 
00252             if (!$inbox) {
00253                 echo $OUTPUT->box_start();
00254                 $inbox = true;
00255             }
00256 
00257             $print_recent_mod_activity = $activity->type.'_print_recent_mod_activity';
00258 
00259             if (function_exists($print_recent_mod_activity)) {
00260                 $print_recent_mod_activity($activity, $course->id, $detail, $modnames, $viewfullnames[$activity->cmid]);
00261             }
00262         }
00263     }
00264 
00265     if ($inbox) {
00266         echo $OUTPUT->box_end();
00267     }
00268 
00269 
00270 } else {
00271 
00272     echo '<h4><center>' . get_string('norecentactivity') . '</center></h2>';
00273 
00274 }
00275 
00276 echo $OUTPUT->footer();
00277 
00278 function compare_activities_by_time_desc($a, $b) {
00279     // make sure the activities actually have a timestamp property
00280     if ((!array_key_exists('timestamp', $a)) or (!array_key_exists('timestamp', $b))) {
00281       return 0;
00282     }
00283     if ($a->timestamp == $b->timestamp)
00284         return 0;
00285     return ($a->timestamp > $b->timestamp) ? -1 : 1;
00286 }
00287 
00288 function compare_activities_by_time_asc($a, $b) {
00289     // make sure the activities actually have a timestamp property
00290     if ((!array_key_exists('timestamp', $a)) or (!array_key_exists('timestamp', $b))) {
00291       return 0;
00292     }
00293     if ($a->timestamp == $b->timestamp)
00294         return 0;
00295     return ($a->timestamp < $b->timestamp) ? -1 : 1;
00296 }
00297 
 All Data Structures Namespaces Files Functions Variables Enumerations