[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

/report/stats/ -> user.php (source)

   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
  21   * @subpackage stats
  22   * @copyright  1999 onwards Martin Dougiamas  http://dougiamas.com
  23   * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
  24   */
  25  
  26  require('../../config.php');
  27  require_once($CFG->dirroot.'/report/stats/locallib.php');
  28  
  29  $userid   = required_param('id', PARAM_INT);
  30  $courseid = required_param('course', PARAM_INT);
  31  
  32  $user = $DB->get_record('user', array('id'=>$userid, 'deleted'=>0), '*', MUST_EXIST);
  33  $course = $DB->get_record('course', array('id'=>$courseid), '*', MUST_EXIST);
  34  
  35  $coursecontext   = context_course::instance($course->id);
  36  $personalcontext = context_user::instance($user->id);
  37  
  38  if ($USER->id != $user->id and has_capability('moodle/user:viewuseractivitiesreport', $personalcontext)
  39          and !is_enrolled($coursecontext, $USER) and is_enrolled($coursecontext, $user)) {
  40      //TODO: do not require parents to be enrolled in courses - this is a hack!
  41      require_login();
  42      $PAGE->set_course($course);
  43  } else {
  44      require_login($course);
  45  }
  46  
  47  if (!report_stats_can_access_user_report($user, $course, true)) {
  48      // this should never happen
  49      error('Can not access user statistics report');
  50  }
  51  
  52  $stractivityreport = get_string('activityreport');
  53  
  54  $PAGE->set_pagelayout('report');
  55  $PAGE->set_url('/report/stats/user.php', array('id'=>$user->id, 'course'=>$course->id));
  56  $PAGE->navigation->extend_for_user($user);
  57  $PAGE->navigation->set_userid_for_parent_checks($user->id); // see MDL-25805 for reasons and for full commit reference for reversal when fixed.
  58  $PAGE->set_title("$course->shortname: $stractivityreport");
  59  $PAGE->set_heading($course->fullname);
  60  echo $OUTPUT->header();
  61  
  62  // Trigger a user report viewed event.
  63  $event = \report_stats\event\user_report_viewed::create(array('context' => $coursecontext, 'relateduserid' => $user->id));
  64  $event->trigger();
  65  
  66  if (empty($CFG->enablestats)) {
  67      print_error('statsdisable', 'error');
  68  }
  69  
  70  $statsstatus = stats_check_uptodate($course->id);
  71  if ($statsstatus !== NULL) {
  72      echo $OUTPUT->notification($statsstatus);
  73  }
  74  
  75  $earliestday   = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_user_daily}');
  76  $earliestweek  = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_user_weekly}');
  77  $earliestmonth = $DB->get_field_sql('SELECT MIN(timeend) FROM {stats_user_monthly}');
  78  
  79  if (empty($earliestday)) {
  80      $earliestday = time();
  81  }
  82  if (empty($earliestweek)) {
  83      $earliestweek = time();
  84  }
  85  if (empty($earliestmonth)) {
  86      $earliestmonth = time();
  87  }
  88  
  89  $now = stats_get_base_daily();
  90  $lastweekend = stats_get_base_weekly();
  91  $lastmonthend = stats_get_base_monthly();
  92  
  93  $timeoptions = stats_get_time_options($now,$lastweekend,$lastmonthend,$earliestday,$earliestweek,$earliestmonth);
  94  
  95  if (empty($timeoptions)) {
  96      print_error('nostatstodisplay', '', $CFG->wwwroot.'/course/user.php?id='.$course->id.'&user='.$user->id.'&mode=outline');
  97  }
  98  
  99  // use the earliest.
 100  $timekeys = array_keys($timeoptions);
 101  $time = array_pop($timekeys);
 102  
 103  $param = stats_get_parameters($time,STATS_REPORT_USER_VIEW,$course->id,STATS_MODE_DETAILED);
 104  $params = $param->params;
 105  
 106  $param->table = 'user_'.$param->table;
 107  
 108  $sql = 'SELECT timeend,'.$param->fields.' FROM {stats_'.$param->table.'} WHERE '
 109  .(($course->id == SITEID) ? '' : ' courseid = '.$course->id.' AND ')
 110      .' userid = '.$user->id.' AND timeend >= '.$param->timeafter .$param->extras
 111      .' ORDER BY timeend DESC';
 112  $stats = $DB->get_records_sql($sql, $params); //TODO: improve these params!!
 113  
 114  if (empty($stats)) {
 115      print_error('nostatstodisplay', '', $CFG->wwwroot.'/course/user.php?id='.$course->id.'&user='.$user->id.'&mode=outline');
 116  }
 117  
 118  echo '<center><img src="'.$CFG->wwwroot.'/report/stats/graph.php?mode='.STATS_MODE_DETAILED.'&course='.$course->id.'&time='.$time.'&report='.STATS_REPORT_USER_VIEW.'&userid='.$user->id.'" alt="'.get_string('statisticsgraph').'" /></center>';
 119  
 120  // What the heck is this about?   -- MD
 121  $stats = stats_fix_zeros($stats,$param->timeafter,$param->table,(!empty($param->line2)),(!empty($param->line3)));
 122  
 123  $table = new html_table();
 124  $table->align = array('left','center','center','center');
 125  $param->table = str_replace('user_','',$param->table);
 126  switch ($param->table) {
 127      case 'daily'  : $period = get_string('day'); break;
 128      case 'weekly' : $period = get_string('week'); break;
 129      case 'monthly': $period = get_string('month', 'form'); break;
 130      default : $period = '';
 131  }
 132  $table->head = array(get_string('periodending','moodle',$period),$param->line1,$param->line2,$param->line3);
 133  foreach ($stats as $stat) {
 134      if (!empty($stat->zerofixed)) {  // Don't know why this is necessary, see stats_fix_zeros above - MD
 135          continue;
 136      }
 137      $a = array(userdate($stat->timeend,get_string('strftimedate'),$CFG->timezone),$stat->line1);
 138      $a[] = $stat->line2;
 139      $a[] = $stat->line3;
 140      $table->data[] = $a;
 141  }
 142  echo html_writer::table($table);
 143  
 144  
 145  echo $OUTPUT->footer();


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1