Search moodle.org's
Developer Documentation


   1  <?php
   2  // This file is part of Moodle - http://moodle.org/
   3  //
   4  // Moodle is free software: you can redistribute it and/or modify
   5  // it under the terms of the GNU General Public License as published by
   6  // the Free Software Foundation, either version 3 of the License, or
   7  // (at your option) any later version.
   8  //
   9  // Moodle is distributed in the hope that it will be useful,
  10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12  // GNU General Public License for more details.
  13  //
  14  // You should have received a copy of the GNU General Public License
  15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
  16  
  17  /**
  18   * Display user activity reports for a course (totals)
  19   *
  20   * @package    report_log
  21   * @copyright  1999 onwards Martin Dougiamas  http://dougiamas.com
  22   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  23   */
  24  
  25  require('../../config.php');
  26  require_once($CFG->dirroot.'/report/log/locallib.php');
  27  require_once($CFG->dirroot.'/lib/tablelib.php');
  28  
  29  $userid   = required_param('id', PARAM_INT);
  30  $courseid = required_param('course', PARAM_INT);
  31  $mode     = optional_param('mode', 'today', PARAM_ALPHA);
  32  $page     = optional_param('page', 0, PARAM_INT);
  33  $perpage  = optional_param('perpage', 100, PARAM_INT);
  34  $logreader   = optional_param('logreader', '', PARAM_COMPONENT); // Log reader which will be used for displaying logs.
  35  
  36  if ($mode !== 'today' and $mode !== 'all') {
  37      $mode = 'today';
  38  }
  39  
  40  $user = $DB->get_record('user', array('id' => $userid, 'deleted' => 0), '*', MUST_EXIST);
  41  $course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
  42  
  43  $coursecontext   = context_course::instance($course->id);
  44  $personalcontext = context_user::instance($user->id);
  45  
  46  if ($USER->id != $user->id and has_capability('moodle/user:viewuseractivitiesreport', $personalcontext)
  47          and !is_enrolled($coursecontext, $USER) and is_enrolled($coursecontext, $user)) {
  48      //TODO: do not require parents to be enrolled in courses - this is a hack!
  49      require_login();
  50      $PAGE->set_course($course);
  51  } else {
  52      require_login($course);
  53  }
  54  
  55  list($all, $today) = report_log_can_access_user_report($user, $course);
  56  
  57  if ($mode === 'today') {
  58      if (!$today) {
  59          require_capability('report/log:viewtoday', $coursecontext);
  60      }
  61  } else {
  62      if (!$all) {
  63          require_capability('report/log:view', $coursecontext);
  64      }
  65  }
  66  
  67  $stractivityreport = get_string('activityreport');
  68  
  69  $PAGE->set_pagelayout('report');
  70  $PAGE->set_url('/report/log/user.php', array('id' => $user->id, 'course' => $course->id, 'mode' => $mode));
  71  $PAGE->navigation->extend_for_user($user);
  72  $PAGE->navigation->set_userid_for_parent_checks($user->id); // see MDL-25805 for reasons and for full commit reference for reversal when fixed.
  73  $PAGE->set_title("$course->shortname: $stractivityreport");
  74  $PAGE->set_heading($course->fullname);
  75  
  76  // Trigger a user logs viewed event.
  77  $event = \report_log\event\user_report_viewed::create(array('context' => $coursecontext, 'relateduserid' => $userid,
  78          'other' => array('mode' => $mode)));
  79  $event->trigger();
  80  
  81  echo $OUTPUT->header();
  82  
  83  // Time to filter records from.
  84  if ($mode === 'today') {
  85      $timefrom = usergetmidnight(time());
  86  } else {
  87      $timefrom = 0;
  88  }
  89  
  90  $output = $PAGE->get_renderer('report_log');
  91  $reportlog = new report_log_renderable($logreader, $course, $user->id, 0, '', -1, -1, false, false, true, false, $PAGE->url,
  92          $timefrom, '', $page, $perpage, 'timecreated DESC');
  93  
  94  // Setup table if log reader is enabled.
  95  if (!empty($reportlog->selectedlogreader)) {
  96      $reportlog->setup_table();
  97      $reportlog->tablelog->is_downloadable(false);
  98  }
  99  
 100  echo $output->reader_selector($reportlog);
 101  
 102  if ($mode === 'today') {
 103      echo '<div class="graph">';
 104      report_log_print_graph($course, $user->id, "userday.png", 0, $logreader);
 105      echo '</div>';
 106      echo $output->render($reportlog);
 107  } else {
 108      echo '<div class="graph">';
 109      report_log_print_graph($course, $user->id, "usercourse.png", 0, $logreader);
 110      echo '</div>';
 111      $reportlog->selecteddate = 0;
 112      echo $output->render($reportlog);
 113  }
 114  
 115  echo $OUTPUT->footer();

Search This Site: