2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * Display user activity reports for a course (totals)
22 * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 require('../../config.php');
27 require_once($CFG->dirroot
.'/report/outline/locallib.php');
29 $id = required_param('id',PARAM_INT
); // course id
31 $course = $DB->get_record('course', array('id'=>$id), '*', MUST_EXIST
);
33 $PAGE->set_url('/report/outline/index.php', array('id'=>$id));
34 $PAGE->set_pagelayout('report');
36 require_login($course);
37 $context = context_course
::instance($course->id
);
38 require_capability('report/outline:view', $context);
40 add_to_log($course->id
, 'course', 'report outline', "report/outline/index.php?id=$course->id", $course->id
);
42 $showlastaccess = true;
43 $hiddenfields = explode(',', $CFG->hiddenuserfields
);
45 if (array_search('lastaccess', $hiddenfields) !== false and !has_capability('moodle/user:viewhiddendetails', $context)) {
46 $showlastaccess = false;
49 $stractivityreport = get_string('pluginname', 'report_outline');
50 $stractivity = get_string('activity');
51 $strlast = get_string('lastaccess');
52 $strreports = get_string('reports');
53 $strviews = get_string('views');
54 $strrelatedblogentries = get_string('relatedblogentries', 'blog');
56 $PAGE->set_title($course->shortname
.': '. $stractivityreport);
57 $PAGE->set_heading($course->fullname
);
58 echo $OUTPUT->header();
59 echo $OUTPUT->heading(format_string($course->fullname
));
61 if (!$logstart = $DB->get_field_sql("SELECT MIN(time) FROM {log}")) {
62 print_error('logfilenotavailable');
65 echo $OUTPUT->container(get_string('computedfromlogs', 'admin', userdate($logstart)), 'loginfo');
67 $outlinetable = new html_table();
68 $outlinetable->attributes
['class'] = 'generaltable boxaligncenter';
69 $outlinetable->cellpadding
= 5;
70 $outlinetable->id
= 'outlinetable';
71 $outlinetable->head
= array($stractivity, $strviews);
73 if ($CFG->useblogassociations
) {
74 $outlinetable->head
[] = $strrelatedblogentries;
77 if ($showlastaccess) {
78 $outlinetable->head
[] = $strlast;
81 $modinfo = get_fast_modinfo($course);
83 $sql = "SELECT cm.id, COUNT('x') AS numviews, MAX(time) AS lasttime
84 FROM {course_modules} cm
85 JOIN {modules} m ON m.id = cm.module
86 JOIN {log} l ON l.cmid = cm.id
87 WHERE cm.course = ? AND l.action LIKE 'view%' AND m.visible = 1
89 $views = $DB->get_records_sql($sql, array($course->id
));
92 foreach ($modinfo->sections
as $sectionnum=>$section) {
93 foreach ($section as $cmid) {
94 $cm = $modinfo->cms
[$cmid];
95 if (!$cm->has_view()) {
98 if (!$cm->uservisible
) {
101 if ($prevsecctionnum != $sectionnum) {
102 $sectionrow = new html_table_row();
103 $sectionrow->attributes
['class'] = 'section';
104 $sectioncell = new html_table_cell();
105 $sectioncell->colspan
= count($outlinetable->head
);
107 $sectiontitle = get_section_name($course, $sectionnum);
109 $sectioncell->text
= $OUTPUT->heading($sectiontitle, 3);
110 $sectionrow->cells
[] = $sectioncell;
111 $outlinetable->data
[] = $sectionrow;
113 $prevsecctionnum = $sectionnum;
116 $dimmed = $cm->visible ?
'' : 'class="dimmed"';
117 $modulename = get_string('modulename', $cm->modname
);
119 $reportrow = new html_table_row();
120 $activitycell = new html_table_cell();
121 $activitycell->attributes
['class'] = 'activity';
123 $activityicon = $OUTPUT->pix_icon('icon', $modulename, $cm->modname
, array('class'=>'icon'));
125 $attributes = array();
127 $attributes['class'] = 'dimmed';
130 $activitycell->text
= $activityicon . html_writer
::link("$CFG->wwwroot/mod/$cm->modname/view.php?id=$cm->id", format_string($cm->name
), $attributes);
132 $reportrow->cells
[] = $activitycell;
134 $numviewscell = new html_table_cell();
135 $numviewscell->attributes
['class'] = 'numviews';
137 if (!empty($views[$cm->id
]->numviews
)) {
138 $numviewscell->text
= $views[$cm->id
]->numviews
;
140 $numviewscell->text
= '-';
143 $reportrow->cells
[] = $numviewscell;
145 if ($CFG->useblogassociations
) {
146 require_once($CFG->dirroot
.'/blog/lib.php');
147 $blogcell = new html_table_cell();
148 $blogcell->attributes
['class'] = 'blog';
149 if ($blogcount = blog_get_associated_count($course->id
, $cm->id
)) {
150 $blogurl = new moodle_url('/blog/index.php', array('modid' => $cm->id
));
151 $blogcell->text
= html_writer
::link($blogurl, $blogcount);
153 $blogcell->text
= '-';
155 $reportrow->cells
[] = $blogcell;
158 if ($showlastaccess) {
159 $lastaccesscell = new html_table_cell();
160 $lastaccesscell->attributes
['class'] = 'lastaccess';
162 if (isset($views[$cm->id
]->lasttime
)) {
163 $timeago = format_time(time() - $views[$cm->id
]->lasttime
);
164 $lastaccesscell->text
= userdate($views[$cm->id
]->lasttime
)." ($timeago)";
166 $reportrow->cells
[] = $lastaccesscell;
168 $outlinetable->data
[] = $reportrow;
171 echo html_writer
::table($outlinetable);
173 echo $OUTPUT->footer();