analysis_course.php 5.54 KB
Newer Older
1
<?php
2
3
4
5
6
7
8
9
10
11
12
13
14
15
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16

17
/**
18
19
20
21
 * shows an analysed view of a feedback on the mainsite
 *
 * @author Andreas Grabs
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
22
 * @package mod_feedback
23
 */
24

25
26
27
28
29
30
31
32
33
34
require_once("../../config.php");
require_once("lib.php");

$current_tab = 'analysis';

$id = required_param('id', PARAM_INT);  //the POST dominated the GET
$courseitemfilter = optional_param('courseitemfilter', '0', PARAM_INT);
$courseitemfiltertyp = optional_param('courseitemfiltertyp', '0', PARAM_ALPHANUM);
$courseid = optional_param('courseid', false, PARAM_INT);

35
$url = new moodle_url('/mod/feedback/analysis_course.php', array('id'=>$id));
36
navigation_node::override_active_url($url);
37
38
39
40
41
42
43
44
45
46
47
if ($courseid !== false) {
    $url->param('courseid', $courseid);
}
if ($courseitemfilter !== '0') {
    $url->param('courseitemfilter', $courseitemfilter);
}
if ($courseitemfiltertyp !== '0') {
    $url->param('courseitemfiltertyp', $courseitemfiltertyp);
}
$PAGE->set_url($url);

48
list($course, $cm) = get_course_and_cm_from_cmid($id, 'feedback');
49
$context = context_module::instance($cm->id);
50

51
52
53
require_course_login($course, true, $cm);

$feedback = $PAGE->activityrecord;
54

55
if (!($feedback->publish_stats OR has_capability('mod/feedback:viewreports', $context))) {
56
57
58
    print_error('error');
}

59
60
$feedbackstructure = new mod_feedback_structure($feedback, $PAGE->cm, $courseid);

61
62
63
64
65
66
// Process course select form.
$courseselectform = new mod_feedback_course_select_form($url, $feedbackstructure);
if ($data = $courseselectform->get_data()) {
    redirect(new moodle_url($url, ['courseid' => $data->courseid]));
}

67
68
69
70
/// Print the page header
$strfeedbacks = get_string("modulenameplural", "feedback");
$strfeedback  = get_string("modulename", "feedback");

71
72
$PAGE->set_heading($course->fullname);
$PAGE->set_title($feedback->name);
73
echo $OUTPUT->header();
74
75
76
if (!$PAGE->has_secondary_navigation()) {
    echo $OUTPUT->heading(format_string($feedback->name));
}
77
78
79
80
81

//get the groupid
//lstgroupid is the choosen id
$mygroupid = false;

82
83
$courseselectform->display();

84
85
86
87
88
89
90
91
92
// Button "Export to excel".
if (has_capability('mod/feedback:viewreports', $context) && $feedbackstructure->get_items()) {
    echo $OUTPUT->container_start('form-buttons');
    $aurl = new moodle_url('/mod/feedback/analysis_to_excel.php',
        ['sesskey' => sesskey(), 'id' => $id, 'courseid' => (int)$courseid]);
    echo $OUTPUT->single_button($aurl, get_string('export_to_excel', 'feedback'));
    echo $OUTPUT->container_end();
}

93
94
95
// Show the summary.
$summary = new mod_feedback\output\summary($feedbackstructure);
echo $OUTPUT->render_from_template('mod_feedback/summary', $summary->export_for_template($OUTPUT));
96

97
98
// Get the items of the feedback.
$items = $feedbackstructure->get_items(true);
99
100

if ($courseitemfilter > 0) {
101
102
    $sumvalue = 'SUM(' . $DB->sql_cast_char2real('value', true) . ')';
    $sql = "SELECT fv.course_id, c.shortname, $sumvalue AS sumvalue, COUNT(value) as countvalue
103
104
105
            FROM {feedback_value} fv, {course} c, {feedback_item} fi
            WHERE fv.course_id = c.id AND fi.id = fv.item AND fi.typ = ? AND fv.item = ?
            GROUP BY course_id, shortname
106
            ORDER BY sumvalue desc";
107
108

    if ($courses = $DB->get_records_sql($sql, array($courseitemfiltertyp, $courseitemfilter))) {
109
        $item = $DB->get_record('feedback_item', array('id'=>$courseitemfilter));
110
111
112
        echo '<h4>'.$item->name.'</h4>';
        echo '<div class="clearfix">';
        echo '<table>';
113
114
115
        echo '<tr><th>Course</th><th>Average</th></tr>';

        foreach ($courses as $c) {
116
            $coursecontext = context_course::instance($c->course_id);
117
118
119
120
            $shortname = format_string($c->shortname, true, array('context' => $coursecontext));

            echo '<tr>';
            echo '<td>'.$shortname.'</td>';
121
            echo '<td align="right">';
122
            echo format_float(($c->sumvalue / $c->countvalue), 2);
123
124
            echo '</td>';
            echo '</tr>';
125
        }
126
        echo '</table>';
127
    } else {
128
        echo '<p>'.get_string('noresults').'</p>';
129
    }
130
131
132
    echo '<p><a href="analysis_course.php?id=' . $id . '">';
    echo get_string('back');
    echo '</a></p>';
133
134
} else {

135
    // Print the items in an analysed form.
136
    foreach ($items as $item) {
137
        echo '<table class="analysis">';
138
        $itemobj = feedback_get_item_class($item->typ);
139
140
        $printnr = ($feedback->autonumbering && $item->itemnr) ? ($item->itemnr . '.') : '';
        $itemobj->print_analysed($item, $printnr, $mygroupid, $feedbackstructure->get_courseid());
141
        if (preg_match('/rated$/i', $item->typ)) {
142
143
144
            $url = new moodle_url('/mod/feedback/analysis_course.php', array('id' => $id,
                'courseitemfilter' => $item->id, 'courseitemfiltertyp' => $item->typ));
            $anker = html_writer::link($url, get_string('sort_by_course', 'feedback'));
145
146

            echo '<tr><td colspan="2">'.$anker.'</td></tr>';
147
        }
148
        echo '</table>';
149
    }
150
}
151

152
echo $OUTPUT->footer();
153