Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
 * shows an analysed view of a feedback on the mainsite
19
 *
20
 * @author Andreas Grabs
21
 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
22
 * @package mod_feedback
23
 */
24
 
25
require_once("../../config.php");
26
require_once("lib.php");
27
 
28
$id = required_param('id', PARAM_INT);  //the POST dominated the GET
29
$courseitemfilter = optional_param('courseitemfilter', '0', PARAM_INT);
30
$courseitemfiltertyp = optional_param('courseitemfiltertyp', '0', PARAM_ALPHANUM);
31
$courseid = optional_param('courseid', false, PARAM_INT);
32
 
33
$url = new moodle_url('/mod/feedback/analysis_course.php', array('id'=>$id));
34
navigation_node::override_active_url($url);
35
if ($courseid !== false) {
36
    $url->param('courseid', $courseid);
37
}
38
if ($courseitemfilter !== '0') {
39
    $url->param('courseitemfilter', $courseitemfilter);
40
}
41
if ($courseitemfiltertyp !== '0') {
42
    $url->param('courseitemfiltertyp', $courseitemfiltertyp);
43
}
44
$PAGE->set_url($url);
45
 
46
list($course, $cm) = get_course_and_cm_from_cmid($id, 'feedback');
47
$context = context_module::instance($cm->id);
48
 
49
require_course_login($course, true, $cm);
50
 
51
$feedback = $PAGE->activityrecord;
52
 
53
if (!($feedback->publish_stats OR has_capability('mod/feedback:viewreports', $context))) {
54
    throw new \moodle_exception('error');
55
}
56
 
57
$feedbackstructure = new mod_feedback_structure($feedback, $PAGE->cm, $courseid);
58
 
59
// Process course select form.
60
$courseselectform = new mod_feedback_course_select_form($url, $feedbackstructure);
61
if ($data = $courseselectform->get_data()) {
62
    redirect(new moodle_url($url, ['courseid' => $data->courseid]));
63
}
64
 
65
/// Print the page header
66
$strfeedbacks = get_string("modulenameplural", "feedback");
67
$strfeedback  = get_string("modulename", "feedback");
68
 
69
$PAGE->set_heading($course->fullname);
70
$PAGE->set_title($feedback->name);
71
echo $OUTPUT->header();
72
if (!$PAGE->has_secondary_navigation()) {
73
    echo $OUTPUT->heading(format_string($feedback->name));
74
}
75
 
76
//get the groupid
77
//lstgroupid is the choosen id
78
$mygroupid = false;
79
 
80
$courseselectform->display();
81
 
82
// Button "Export to excel".
83
if (has_capability('mod/feedback:viewreports', $context) && $feedbackstructure->get_items()) {
84
    echo $OUTPUT->container_start('form-buttons');
85
    $aurl = new moodle_url('/mod/feedback/analysis_to_excel.php',
86
        ['sesskey' => sesskey(), 'id' => $id, 'courseid' => (int)$courseid]);
87
    echo $OUTPUT->single_button($aurl, get_string('export_to_excel', 'feedback'));
88
    echo $OUTPUT->container_end();
89
}
90
 
91
// Show the summary.
92
$summary = new mod_feedback\output\summary($feedbackstructure);
93
echo $OUTPUT->render_from_template('mod_feedback/summary', $summary->export_for_template($OUTPUT));
94
 
95
// Get the items of the feedback.
96
$items = $feedbackstructure->get_items(true);
97
 
98
if ($courseitemfilter > 0) {
99
    $sumvalue = 'SUM(' . $DB->sql_cast_char2real('value', true) . ')';
100
    $sql = "SELECT fv.course_id, c.shortname, $sumvalue AS sumvalue, COUNT(value) as countvalue
101
            FROM {feedback_value} fv, {course} c, {feedback_item} fi
102
            WHERE fv.course_id = c.id AND fi.id = fv.item AND fi.typ = ? AND fv.item = ?
103
            GROUP BY course_id, shortname
104
            ORDER BY sumvalue desc";
105
 
106
    if ($courses = $DB->get_records_sql($sql, array($courseitemfiltertyp, $courseitemfilter))) {
107
        $item = $DB->get_record('feedback_item', array('id'=>$courseitemfilter));
108
        echo '<h4>'.$item->name.'</h4>';
109
        echo '<div class="clearfix">';
110
        echo '<table>';
111
        echo '<tr><th>Course</th><th>Average</th></tr>';
112
 
113
        foreach ($courses as $c) {
114
            $coursecontext = context_course::instance($c->course_id);
115
            $shortname = format_string($c->shortname, true, array('context' => $coursecontext));
116
 
117
            echo '<tr>';
118
            echo '<td>'.$shortname.'</td>';
1441 ariadna 119
            echo '<td class="text-end">';
1 efrain 120
            echo format_float(($c->sumvalue / $c->countvalue), 2);
121
            echo '</td>';
122
            echo '</tr>';
123
        }
124
        echo '</table>';
125
    } else {
126
        echo '<p>'.get_string('noresults').'</p>';
127
    }
128
    echo '<p><a href="analysis_course.php?id=' . $id . '">';
129
    echo get_string('back');
130
    echo '</a></p>';
131
} else {
132
 
133
    // Print the items in an analysed form.
134
    foreach ($items as $item) {
135
        echo '<table class="analysis">';
136
        $itemobj = feedback_get_item_class($item->typ);
137
        $printnr = ($feedback->autonumbering && $item->itemnr) ? ($item->itemnr . '.') : '';
138
        $itemobj->print_analysed($item, $printnr, $mygroupid, $feedbackstructure->get_courseid());
139
        if (preg_match('/rated$/i', $item->typ)) {
140
            $url = new moodle_url('/mod/feedback/analysis_course.php', array('id' => $id,
141
                'courseitemfilter' => $item->id, 'courseitemfiltertyp' => $item->typ));
142
            $anker = html_writer::link($url, get_string('sort_by_course', 'feedback'));
143
 
144
            echo '<tr><td colspan="2">'.$anker.'</td></tr>';
145
        }
146
        echo '</table>';
147
    }
148
}
149
 
150
echo $OUTPUT->footer();
151