index.php 5.68 KB
Newer Older
1
<?php
2
3
4

// Display user activity reports for a course (totals)

5
6
    require_once('../../../config.php');
    require_once($CFG->dirroot.'/course/lib.php');
7

8
    $id = required_param('id',PARAM_INT);       // course id
9

10
    if (!$course = $DB->get_record('course', array('id'=>$id))) {
dongsheng's avatar
dongsheng committed
11
        print_error('invalidcourseid');
12
13
    }

14
    $PAGE->set_url('/course/report/outline/index.php', array('id'=>$id));
15
    $PAGE->set_pagelayout('report');
16

17
    require_login($course);
18
19
    $context = get_context_instance(CONTEXT_COURSE, $course->id);
    require_capability('coursereport/outline:view', $context);
20

21
    add_to_log($course->id, 'course', 'report outline', "report/outline/index.php?id=$course->id", $course->id);
22

23
24
25
26
27
28
29
    $showlastaccess = true;
    $hiddenfields = explode(',', $CFG->hiddenuserfields);

    if (array_search('lastaccess', $hiddenfields) and !has_capability('moodle/user:viewhiddendetails', $coursecontext)) {
        $showlastaccess = false;
    }

30
31
32
33
34
    $stractivityreport = get_string('activityreport');
    $stractivity       = get_string('activity');
    $strlast           = get_string('lastaccess');
    $strreports        = get_string('reports');
    $strviews          = get_string('views');
35
    $strrelatedblogentries = get_string('relatedblogentries', 'blog');
36

37
38
39
    $PAGE->set_title($course->shortname .': '. $stractivityreport);
    $PAGE->set_heading($course->fullname);
    echo $OUTPUT->header();
40
    echo $OUTPUT->heading(format_string($course->fullname));
41

42
    if (!$logstart = $DB->get_field_sql("SELECT MIN(time) FROM {log}")) {
dongsheng's avatar
dongsheng committed
43
        print_error('logfilenotavailable');
44
    }
45

46
47
48
    echo $OUTPUT->container(get_string('computedfromlogs', 'admin', userdate($logstart)), 'loginfo');

    $outlinetable = new html_table();
49
    $outlinetable->attributes['class'] = 'generaltable boxaligncenter';
50
    $outlinetable->attributes['style'] = 'width:2000px;';
51
52
53
54
55
56
57
    $outlinetable->cellpadding = 5;
    $outlinetable->id = 'outlinetable';
    $outlinetable->head = array($stractivity, $strviews);

    if ($CFG->useblogassociations) {
        $outlinetable->head[] = $strrelatedblogentries;
    }
58

59
    if ($showlastaccess) {
60
        $outlinetable->head[] = $strlast;
61
    }
62
63

    $modinfo = get_fast_modinfo($course);
64
    $sections = get_all_sections($course->id);
65
66

    $sql = "SELECT cm.id, COUNT('x') AS numviews, MAX(time) AS lasttime
67
68
69
70
              FROM {course_modules} cm
                   JOIN {modules} m ON m.id = cm.module
                   JOIN {log} l     ON l.cmid = cm.id
             WHERE cm.course = ? AND l.action LIKE 'view%' AND m.visible = 1
71
          GROUP BY cm.id";
72
    $views = $DB->get_records_sql($sql, array($course->id));
73
74
75
76
77
78
79
80
81
82
83
84

    $prevsecctionnum = 0;
    foreach ($modinfo->sections as $sectionnum=>$section) {
        foreach ($section as $cmid) {
            $cm = $modinfo->cms[$cmid];
            if ($cm->modname == 'label') {
                continue;
            }
            if (!$cm->uservisible) {
                continue;
            }
            if ($prevsecctionnum != $sectionnum) {
85
                $sectionrow = new html_table_row();
86
                $sectionrow->attributes['class'] = 'section';
87
88
89
                $sectioncell = new html_table_cell();
                $sectioncell->colspan = count($outlinetable->head);

90
                $sectiontitle = get_section_name($course, $sections[$sectionnum]);
91

92
                $sectioncell->text = $OUTPUT->heading($sectiontitle, 3);
93
94
                $sectionrow->cells[] = $sectioncell;
                $outlinetable->data[] = $sectionrow;
95
96
97

                $prevsecctionnum = $sectionnum;
            }
98

99
100
            $dimmed = $cm->visible ? '' : 'class="dimmed"';
            $modulename = get_string('modulename', $cm->modname);
101
102
103

            $reportrow = new html_table_row();
            $activitycell = new html_table_cell();
104
            $activitycell->attributes['class'] = 'activity';
105

106
            $activityicon = $OUTPUT->pix_icon('icon', $modulename, $cm->modname, array('class'=>'icon'));
107

108
            $attributes = array();
109
            if (!$cm->visible) {
110
                $attributes['class'] = 'dimmed';
111
112
            }

113
            $activitycell->text = $activityicon . html_writer::link("$CFG->wwwroot/mod/$cm->modname/view.php?id=$cm->id", format_string($cm->name), $attributes);;
114
115
116
117

            $reportrow->cells[] = $activitycell;

            $numviewscell = new html_table_cell();
118
            $numviewscell->attributes['class'] = 'numviews';
119

120
            if (!empty($views[$cm->id]->numviews)) {
121
                $numviewscell->text = $views[$cm->id]->numviews;
122
            } else {
123
                $numviewscell->text = '-';
124
            }
125
126
127
128
129

            $reportrow->cells[] = $numviewscell;

            if ($CFG->useblogassociations) {
                $blogcell = new html_table_cell();
130
                $blogcell->attributes['class'] = 'blog';
131
                if ($blogcount = blog_get_associated_count($course->id, $cm->id)) {
132
                    $blogcell->text = html_writer::link('/blog/index.php?modid='.$cm->id, $blogcount);
133
134
135
136
137
138
                } else {
                    $blogcell->text = '-';
                }
                $reportrow->cells[] = $blogcell;
            }

139
            if ($showlastaccess) {
140
                $lastaccesscell = new html_table_cell();
141
                $lastaccesscell->attributes['class'] = 'lastaccess';
142

143
144
                if (isset($views[$cm->id]->lasttime)) {
                    $timeago = format_time(time() - $views[$cm->id]->lasttime);
145
                    $lastaccesscell->text = userdate($views[$cm->id]->lasttime)." ($timeago)";
146
                }
147
                $reportrow->cells[] = $lastaccesscell;
148
            }
149
            $outlinetable->data[] = $reportrow;
150
151
        }
    }
152
    echo html_writer::table($outlinetable);
153

154
    echo $OUTPUT->footer();
155
156


157