[ Index ] |
PHP Cross Reference of Unnamed Project |
[Summary view] [Print] [Text view]
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 outline 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/outline/locallib.php'); 28 29 $id = required_param('id',PARAM_INT); // course id 30 31 $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST); 32 33 $PAGE->set_url('/report/outline/index.php', array('id'=>$id)); 34 $PAGE->set_pagelayout('report'); 35 36 require_login($course); 37 $context = context_course::instance($course->id); 38 require_capability('report/outline:view', $context); 39 40 // Trigger an activity report viewed event. 41 $event = \report_outline\event\activity_report_viewed::create(array('context' => $context)); 42 $event->trigger(); 43 44 $showlastaccess = true; 45 $hiddenfields = explode(',', $CFG->hiddenuserfields); 46 47 if (array_search('lastaccess', $hiddenfields) !== false and !has_capability('moodle/user:viewhiddendetails', $context)) { 48 $showlastaccess = false; 49 } 50 51 $stractivityreport = get_string('pluginname', 'report_outline'); 52 $stractivity = get_string('activity'); 53 $strlast = get_string('lastaccess'); 54 $strreports = get_string('reports'); 55 $strviews = get_string('views'); 56 $strrelatedblogentries = get_string('relatedblogentries', 'blog'); 57 58 $PAGE->set_title($course->shortname .': '. $stractivityreport); 59 $PAGE->set_heading($course->fullname); 60 echo $OUTPUT->header(); 61 echo $OUTPUT->heading(format_string($course->fullname)); 62 63 list($uselegacyreader, $useinternalreader, $minloginternalreader, $logtable) = report_outline_get_common_log_variables(); 64 65 // If no legacy and no internal log then don't proceed. 66 if (!$uselegacyreader && !$useinternalreader) { 67 echo $OUTPUT->box_start('generalbox', 'notice'); 68 echo $OUTPUT->notification(get_string('nologreaderenabled', 'report_outline')); 69 echo $OUTPUT->box_end(); 70 echo $OUTPUT->footer(); 71 die(); 72 } 73 74 // We want to display the time we are beginning to get logs from in the heading. 75 // If we are using the legacy reader check the minimum time in that log table. 76 if ($uselegacyreader) { 77 $minlog = $DB->get_field_sql('SELECT min(time) FROM {log}'); 78 } 79 80 // If we are using the internal reader check the minimum time in that table. 81 if ($useinternalreader) { 82 // If new log table has older data then don't use the minimum time obtained from the legacy table. 83 if (empty($minlog) || ($minloginternalreader <= $minlog)) { 84 $minlog = $minloginternalreader; 85 } 86 } 87 88 echo $OUTPUT->container(get_string('computedfromlogs', 'admin', userdate($minlog)), 'loginfo'); 89 90 $outlinetable = new html_table(); 91 $outlinetable->attributes['class'] = 'generaltable boxaligncenter'; 92 $outlinetable->cellpadding = 5; 93 $outlinetable->id = 'outlinetable'; 94 $outlinetable->head = array($stractivity, $strviews); 95 96 if (!empty($CFG->enableblogs) && $CFG->useblogassociations) { 97 $outlinetable->head[] = $strrelatedblogentries; 98 } 99 100 if ($showlastaccess) { 101 $outlinetable->head[] = $strlast; 102 } 103 104 $modinfo = get_fast_modinfo($course); 105 106 // If using legacy log then get users from old table. 107 if ($uselegacyreader) { 108 // If we are going to use the internal (not legacy) log table, we should only get records 109 // from the legacy table that exist before we started adding logs to the new table. 110 $limittime = ''; 111 if (!empty($minloginternalreader)) { 112 $limittime = ' AND time < :timeto '; 113 } 114 // Check if we need to show the last access. 115 $sqllasttime = ''; 116 if ($showlastaccess) { 117 $sqllasttime = ", MAX(time) AS lasttime"; 118 } 119 $logactionlike = $DB->sql_like('l.action', ':action'); 120 $sql = "SELECT cm.id, COUNT('x') AS numviews, COUNT(DISTINCT userid) AS distinctusers $sqllasttime 121 FROM {course_modules} cm 122 JOIN {modules} m 123 ON m.id = cm.module 124 JOIN {log} l 125 ON l.cmid = cm.id 126 WHERE cm.course = :courseid 127 AND $logactionlike 128 AND m.visible = :visible $limittime 129 GROUP BY cm.id"; 130 $params = array('courseid' => $course->id, 'action' => 'view%', 'visible' => 1); 131 if (!empty($minloginternalreader)) { 132 $params['timeto'] = $minloginternalreader; 133 } 134 $views = $DB->get_records_sql($sql, $params); 135 } 136 137 // Get record from sql_internal_table_reader and merge with records obtained from legacy log (if needed). 138 if ($useinternalreader) { 139 // Check if we need to show the last access. 140 $sqllasttime = ''; 141 if ($showlastaccess) { 142 $sqllasttime = ", MAX(timecreated) AS lasttime"; 143 } 144 $sql = "SELECT contextinstanceid as cmid, COUNT('x') AS numviews, COUNT(DISTINCT userid) AS distinctusers $sqllasttime 145 FROM {" . $logtable . "} l 146 WHERE courseid = :courseid 147 AND anonymous = 0 148 AND crud = 'r' 149 AND contextlevel = :contextmodule 150 GROUP BY contextinstanceid"; 151 $params = array('courseid' => $course->id, 'contextmodule' => CONTEXT_MODULE); 152 $v = $DB->get_records_sql($sql, $params); 153 154 if (empty($views)) { 155 $views = $v; 156 } else { 157 // Merge two view arrays. 158 foreach ($v as $key => $value) { 159 if (isset($views[$key]) && !empty($views[$key]->numviews)) { 160 $views[$key]->numviews += $value->numviews; 161 if ($value->lasttime > $views[$key]->lasttime) { 162 $views[$key]->lasttime = $value->lasttime; 163 } 164 } else { 165 $views[$key] = $value; 166 } 167 } 168 } 169 } 170 171 $prevsecctionnum = 0; 172 foreach ($modinfo->sections as $sectionnum=>$section) { 173 foreach ($section as $cmid) { 174 $cm = $modinfo->cms[$cmid]; 175 if (!$cm->has_view()) { 176 continue; 177 } 178 if (!$cm->uservisible) { 179 continue; 180 } 181 if ($prevsecctionnum != $sectionnum) { 182 $sectionrow = new html_table_row(); 183 $sectionrow->attributes['class'] = 'section'; 184 $sectioncell = new html_table_cell(); 185 $sectioncell->colspan = count($outlinetable->head); 186 187 $sectiontitle = get_section_name($course, $sectionnum); 188 189 $sectioncell->text = $OUTPUT->heading($sectiontitle, 3); 190 $sectionrow->cells[] = $sectioncell; 191 $outlinetable->data[] = $sectionrow; 192 193 $prevsecctionnum = $sectionnum; 194 } 195 196 $dimmed = $cm->visible ? '' : 'class="dimmed"'; 197 $modulename = get_string('modulename', $cm->modname); 198 199 $reportrow = new html_table_row(); 200 $activitycell = new html_table_cell(); 201 $activitycell->attributes['class'] = 'activity'; 202 203 $activityicon = $OUTPUT->pix_icon('icon', $modulename, $cm->modname, array('class'=>'icon')); 204 205 $attributes = array(); 206 if (!$cm->visible) { 207 $attributes['class'] = 'dimmed'; 208 } 209 210 $activitycell->text = $activityicon . html_writer::link("$CFG->wwwroot/mod/$cm->modname/view.php?id=$cm->id", format_string($cm->name), $attributes); 211 212 $reportrow->cells[] = $activitycell; 213 214 $numviewscell = new html_table_cell(); 215 $numviewscell->attributes['class'] = 'numviews'; 216 217 if (!empty($views[$cm->id]->numviews)) { 218 $numviewscell->text = get_string('numviews', 'report_outline', $views[$cm->id]); 219 } else { 220 $numviewscell->text = '-'; 221 } 222 223 $reportrow->cells[] = $numviewscell; 224 225 if (!empty($CFG->enableblogs) && $CFG->useblogassociations) { 226 require_once($CFG->dirroot.'/blog/lib.php'); 227 $blogcell = new html_table_cell(); 228 $blogcell->attributes['class'] = 'blog'; 229 if ($blogcount = blog_get_associated_count($course->id, $cm->id)) { 230 $blogurl = new moodle_url('/blog/index.php', array('modid' => $cm->id)); 231 $blogcell->text = html_writer::link($blogurl, $blogcount); 232 } else { 233 $blogcell->text = '-'; 234 } 235 $reportrow->cells[] = $blogcell; 236 } 237 238 if ($showlastaccess) { 239 $lastaccesscell = new html_table_cell(); 240 $lastaccesscell->attributes['class'] = 'lastaccess'; 241 242 if (isset($views[$cm->id]->lasttime)) { 243 $timeago = format_time(time() - $views[$cm->id]->lasttime); 244 $lastaccesscell->text = userdate($views[$cm->id]->lasttime)." ($timeago)"; 245 } 246 $reportrow->cells[] = $lastaccesscell; 247 } 248 $outlinetable->data[] = $reportrow; 249 } 250 } 251 echo html_writer::table($outlinetable); 252 253 echo $OUTPUT->footer(); 254 255 256
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Thu Aug 11 10:00:09 2016 | Cross-referenced by PHPXref 0.7.1 |