course/report/outline $CFG typo
[moodle.git] / course / report / outline / index.php
CommitLineData
7f093351 1<?php
cc652b4d 2
3// Display user activity reports for a course (totals)
4
ad4e76e7 5 require_once('../../../config.php');
6 require_once($CFG->dirroot.'/course/lib.php');
cc652b4d 7
ad4e76e7 8 $id = required_param('id',PARAM_INT); // course id
cc652b4d 9
29f83769 10 if (!$course = $DB->get_record('course', array('id'=>$id))) {
1343697c 11 print_error('invalidcourseid');
cc652b4d 12 }
13
42581c2b 14 $PAGE->set_url(new moodle_url($CFG->wwwroot.'/course/report/outline/index.php', array('id'=>$id)));
dfab77a2 15
ad4e76e7 16 require_login($course);
7dfd669a 17 $context = get_context_instance(CONTEXT_COURSE, $course->id);
18 require_capability('coursereport/outline:view', $context);
cc652b4d 19
ad4e76e7 20 add_to_log($course->id, 'course', 'report outline', "report/outline/index.php?id=$course->id", $course->id);
cc652b4d 21
7dfd669a 22 $showlastaccess = true;
23 $hiddenfields = explode(',', $CFG->hiddenuserfields);
24
25 if (array_search('lastaccess', $hiddenfields) and !has_capability('moodle/user:viewhiddendetails', $coursecontext)) {
26 $showlastaccess = false;
27 }
28
ad4e76e7 29 $stractivityreport = get_string('activityreport');
30 $stractivity = get_string('activity');
31 $strlast = get_string('lastaccess');
32 $strreports = get_string('reports');
33 $strviews = get_string('views');
5a5cd650 34 $strrelatedblogentries = get_string('relatedblogentries', 'blog');
cc652b4d 35
0a122046 36 $PAGE->set_title($course->shortname .': '. $stractivityreport);
37 $PAGE->set_heading($course->fullname);
91152a35 38 $PAGE->navbar->add($strreports, new moodle_url($CFG->wwwroot.'/course/report.php', array('id'=>$course->id)));
0a122046 39 $PAGE->navbar->add($stractivityreport);
40 echo $OUTPUT->header();
7c5286cd 41 echo $OUTPUT->heading(format_string($course->fullname));
cc652b4d 42
a5d424df 43 if (!$logstart = $DB->get_field_sql("SELECT MIN(time) FROM {log}")) {
1343697c 44 print_error('logfilenotavailable');
ad4e76e7 45 }
cc652b4d 46
5a5cd650
NC
47 echo $OUTPUT->container(get_string('computedfromlogs', 'admin', userdate($logstart)), 'loginfo');
48
49 $outlinetable = new html_table();
50 $outlinetable->add_class('generaltable boxaligncenter');
51 $outlinetable->cellpadding = 5;
52 $outlinetable->id = 'outlinetable';
53 $outlinetable->head = array($stractivity, $strviews);
54
55 if ($CFG->useblogassociations) {
56 $outlinetable->head[] = $strrelatedblogentries;
57 }
ad4e76e7 58
7dfd669a 59 if ($showlastaccess) {
5a5cd650 60 $outlinetable->head[] = $strlast;
7dfd669a 61 }
ad4e76e7 62
63 $modinfo = get_fast_modinfo($course);
64
65 $sql = "SELECT cm.id, COUNT('x') AS numviews, MAX(time) AS lasttime
29f83769 66 FROM {course_modules} cm
67 JOIN {modules} m ON m.id = cm.module
68 JOIN {log} l ON l.cmid = cm.id
69 WHERE cm.course = ? AND l.action LIKE 'view%' AND m.visible = 1
ad4e76e7 70 GROUP BY cm.id";
29f83769 71 $views = $DB->get_records_sql($sql, array($course->id));
ad4e76e7 72
ad4e76e7 73 $prevsecctionnum = 0;
74 foreach ($modinfo->sections as $sectionnum=>$section) {
75 foreach ($section as $cmid) {
76 $cm = $modinfo->cms[$cmid];
77 if ($cm->modname == 'label') {
78 continue;
79 }
80 if (!$cm->uservisible) {
81 continue;
82 }
83 if ($prevsecctionnum != $sectionnum) {
5a5cd650
NC
84 $sectionrow = new html_table_row();
85 $sectionrow->add_class('section');
86 $sectioncell = new html_table_cell();
87 $sectioncell->colspan = count($outlinetable->head);
88
89 $sectiontitle = '';
cc652b4d 90 switch ($course->format) {
5a5cd650
NC
91 case 'weeks': $sectiontitle = get_string('week'); break;
92 case 'topics': $sectiontitle = get_string('topic'); break;
93 default: $sectiontitle = get_string('section'); break;
cc652b4d 94 }
5a5cd650
NC
95
96 $sectioncell->text = $OUTPUT->heading($sectiontitle . ' ' . $sectionnum, 3);
97 $sectionrow->cells[] = $sectioncell;
98 $outlinetable->data[] = $sectionrow;
ad4e76e7 99
100 $prevsecctionnum = $sectionnum;
101 }
cc652b4d 102
ad4e76e7 103 $dimmed = $cm->visible ? '' : 'class="dimmed"';
104 $modulename = get_string('modulename', $cm->modname);
5a5cd650
NC
105
106 $reportrow = new html_table_row();
107 $activitycell = new html_table_cell();
108 $activitycell->add_class('activity');
109
110 $activityicon = html_image::make($OUTPUT->mod_icon_url('icon', $cm->modname));
111 $activityicon->add_class('icon');
112 $activityicon->alt = $modulename;
113
114 $activitylink = html_link::make("$CFG->wwwroot/mod/$cm->modname/view.php?id=$cm->id", format_string($cm->name));
115 if (!$cm->visible) {
116 $activitylink->add_class('dimmed');
117 }
118
119 $activitycell->text = $OUTPUT->image($activityicon) . $OUTPUT->link($activitylink);
120
121 $reportrow->cells[] = $activitycell;
122
123 $numviewscell = new html_table_cell();
124 $numviewscell->add_class('numviews');
125
ad4e76e7 126 if (!empty($views[$cm->id]->numviews)) {
5a5cd650 127 $numviewscell->text = $views[$cm->id]->numviews;
ad4e76e7 128 } else {
5a5cd650 129 $numviewscell->text = '-';
cc652b4d 130 }
5a5cd650
NC
131
132 $reportrow->cells[] = $numviewscell;
133
134 if ($CFG->useblogassociations) {
135 $blogcell = new html_table_cell();
136 $blogcell->add_class('blog');
137 if ($blogcount = blog_get_associated_count($course->id, $cm->id)) {
138 $blogcell->text = $OUTPUT->link(html_link::make('/blog/index.php?modid='.$cm->id, $blogcount));
139 } else {
140 $blogcell->text = '-';
141 }
142 $reportrow->cells[] = $blogcell;
143 }
144
7dfd669a 145 if ($showlastaccess) {
5a5cd650
NC
146 $lastaccesscell = new html_table_cell();
147 $lastaccesscell->add_class('lastaccess');
148
7dfd669a 149 if (isset($views[$cm->id]->lasttime)) {
150 $timeago = format_time(time() - $views[$cm->id]->lasttime);
5a5cd650 151 $lastaccesscell->text = userdate($views[$cm->id]->lasttime)." ($timeago)";
7dfd669a 152 }
5a5cd650 153 $reportrow->cells[] = $lastaccesscell;
ad4e76e7 154 }
5a5cd650 155 $outlinetable->data[] = $reportrow;
cc652b4d 156 }
157 }
5a5cd650 158 echo $OUTPUT->table($outlinetable);
cc652b4d 159
d60c1124 160 echo $OUTPUT->footer();
cc652b4d 161
162
aa6c1ced 163