Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/report/outline/user.php
Go to the documentation of this file.
00001 <?php
00002 // This file is part of Moodle - http://moodle.org/
00003 //
00004 // Moodle is free software: you can redistribute it and/or modify
00005 // it under the terms of the GNU General Public License as published by
00006 // the Free Software Foundation, either version 3 of the License, or
00007 // (at your option) any later version.
00008 //
00009 // Moodle is distributed in the hope that it will be useful,
00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 // GNU General Public License for more details.
00013 //
00014 // You should have received a copy of the GNU General Public License
00015 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00016 
00026 require('../../config.php');
00027 require_once($CFG->dirroot.'/report/outline/locallib.php');
00028 
00029 $userid   = required_param('id', PARAM_INT);
00030 $courseid = required_param('course', PARAM_INT);
00031 $mode     = optional_param('mode', 'outline', PARAM_ALPHA);
00032 
00033 if ($mode !== 'complete' and $mode !== 'outline') {
00034     $mode = 'outline';
00035 }
00036 
00037 $user = $DB->get_record('user', array('id'=>$userid, 'deleted'=>0), '*', MUST_EXIST);
00038 $course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST);
00039 
00040 $coursecontext   = context_course::instance($course->id);
00041 $personalcontext = context_user::instance($user->id);
00042 
00043 if ($USER->id != $user->id and has_capability('moodle/user:viewuseractivitiesreport', $personalcontext)
00044         and !is_enrolled($coursecontext, $USER) and is_enrolled($coursecontext, $user)) {
00045     //TODO: do not require parents to be enrolled in courses - this is a hack!
00046     require_login();
00047     $PAGE->set_course($course);
00048 } else {
00049     require_login($course);
00050 }
00051 
00052 if (!report_outline_can_access_user_report($user, $course, true)) {
00053     require_capability('report/outline:view', $coursecontext);
00054 }
00055 
00056 add_to_log($course->id, 'course', 'report outline', "report/outline/user.php?id=$user->id&course=$course->id&mode=$mode", $course->id);
00057 
00058 $stractivityreport = get_string('activityreport');
00059 
00060 $PAGE->set_pagelayout('admin');
00061 $PAGE->set_url('/report/outline/user.php', array('id'=>$user->id, 'course'=>$course->id, 'mode'=>$mode));
00062 $PAGE->navigation->extend_for_user($user);
00063 $PAGE->navigation->set_userid_for_parent_checks($user->id); // see MDL-25805 for reasons and for full commit reference for reversal when fixed.
00064 $PAGE->set_title("$course->shortname: $stractivityreport");
00065 $PAGE->set_heading($course->fullname);
00066 echo $OUTPUT->header();
00067 
00068 
00069 get_all_mods($course->id, $mods, $modnames, $modnamesplural, $modnamesused);
00070 $sections = get_all_sections($course->id);
00071 $itemsprinted = false;
00072 
00073 for ($i=0; $i<=$course->numsections; $i++) {
00074 
00075     if (isset($sections[$i])) {   // should always be true
00076 
00077         $section = $sections[$i];
00078         $showsection = (has_capability('moodle/course:viewhiddensections', $coursecontext) or $section->visible or !$course->hiddensections);
00079 
00080         if ($showsection) { // prevent hidden sections in user activity. Thanks to Geoff Wilbert!
00081             // Check the section has a sequence. This is the sequence of modules/resources.
00082             // If there is no sequence there is nothing to display.
00083             if ($section->sequence) {
00084                 $itemsprinted = true;
00085                 echo '<div class="section">';
00086                 echo '<h2>';
00087                 echo get_section_name($course, $section);
00088                 echo "</h2>";
00089 
00090                 echo '<div class="content">';
00091 
00092                 if ($mode == "outline") {
00093                     echo "<table cellpadding=\"4\" cellspacing=\"0\">";
00094                 }
00095 
00096                 $sectionmods = explode(",", $section->sequence);
00097                 foreach ($sectionmods as $sectionmod) {
00098                     if (empty($mods[$sectionmod])) {
00099                         continue;
00100                     }
00101                     $mod = $mods[$sectionmod];
00102 
00103                     if (empty($mod->visible)) {
00104                         continue;
00105                     }
00106 
00107                     $instance = $DB->get_record("$mod->modname", array("id"=>$mod->instance));
00108                     $libfile = "$CFG->dirroot/mod/$mod->modname/lib.php";
00109 
00110                     if (file_exists($libfile)) {
00111                         require_once($libfile);
00112 
00113                         switch ($mode) {
00114                             case "outline":
00115                                 $user_outline = $mod->modname."_user_outline";
00116                                 if (function_exists($user_outline)) {
00117                                     $output = $user_outline($course, $user, $mod, $instance);
00118                                     report_outline_print_row($mod, $instance, $output);
00119                                 }
00120                                 break;
00121                             case "complete":
00122                                 $user_complete = $mod->modname."_user_complete";
00123                                 if (function_exists($user_complete)) {
00124                                     $image = $OUTPUT->pix_icon('icon', $mod->modfullname, 'mod_'.$mod->modname, array('class'=>'icon'));
00125                                     echo "<h4>$image $mod->modfullname: ".
00126                                          "<a href=\"$CFG->wwwroot/mod/$mod->modname/view.php?id=$mod->id\">".
00127                                          format_string($instance->name,true)."</a></h4>";
00128 
00129                                     ob_start();
00130 
00131                                     echo "<ul>";
00132                                     $user_complete($course, $user, $mod, $instance);
00133                                     echo "</ul>";
00134 
00135                                     $output = ob_get_contents();
00136                                     ob_end_clean();
00137 
00138                                     if (str_replace(' ', '', $output) != '<ul></ul>') {
00139                                         echo $output;
00140                                     }
00141                                 }
00142                                 break;
00143                             }
00144                         }
00145                     }
00146 
00147                 if ($mode == "outline") {
00148                     echo "</table>";
00149                 }
00150                 echo '</div>';  // content
00151                 echo '</div>';  // section
00152             }
00153         }
00154     }
00155 }
00156 
00157 if (!$itemsprinted) {
00158     echo $OUTPUT->notification(get_string('nothingtodisplay'));
00159 }
00160 
00161 echo $OUTPUT->footer();
 All Data Structures Namespaces Files Functions Variables Enumerations