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
 * The gradebook outcomes report
19
 *
20
 * @package   gradereport_outcomes
21
 * @copyright 2007 Nicolas Connault
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
include_once('../../../config.php');
26
require_once($CFG->libdir . '/gradelib.php');
27
require_once $CFG->dirroot.'/grade/lib.php';
28
 
29
$courseid = required_param('id', PARAM_INT);                   // course id
30
 
31
$PAGE->set_url('/grade/report/outcomes/index.php', array('id'=>$courseid));
32
 
33
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
34
    throw new \moodle_exception('invalidcourseid');
35
}
36
 
37
require_login($course);
38
$context = context_course::instance($course->id);
39
 
40
require_capability('gradereport/outcomes:view', $context);
41
 
42
if (empty($CFG->enableoutcomes)) {
43
    redirect(course_get_url($course), get_string('outcomesdisabled', 'core_grades'));
44
}
45
 
46
// First make sure we have proper final grades.
1441 ariadna 47
$regradetask = \core_course\task\regrade_final_grades::create($courseid);
48
$indicatormessage = get_string('recalculatinggradesadhoc', 'grades');
49
$indicatorheading = get_string('recalculatinggrades', 'grades');
50
$taskindicator = new \core\output\task_indicator($regradetask, $indicatorheading, $indicatormessage, $PAGE->url);
51
if (!$taskindicator->has_task_record()) {
52
    grade_regrade_final_grades_if_required($course);
53
}
1 efrain 54
 
55
// Grab all outcomes used in course.
56
$report_info = array();
57
$outcomes = grade_outcome::fetch_all_available($courseid);
58
 
59
// Will exclude grades of suspended users if required.
60
$defaultgradeshowactiveenrol = !empty($CFG->grade_report_showonlyactiveenrol);
61
$showonlyactiveenrol = get_user_preferences('grade_report_showonlyactiveenrol', $defaultgradeshowactiveenrol);
62
$showonlyactiveenrol = $showonlyactiveenrol || !has_capability('moodle/course:viewsuspendedusers', $context);
63
if ($showonlyactiveenrol) {
64
    $suspendedusers = get_suspended_userids($context);
65
}
66
 
67
// Get grade_items that use each outcome.
68
foreach ($outcomes as $outcomeid => $outcome) {
69
    $report_info[$outcomeid]['items'] = $DB->get_records_select('grade_items', "outcomeid = ? AND courseid = ?", array($outcomeid, $courseid));
70
    $report_info[$outcomeid]['outcome'] = $outcome;
71
 
72
    // Get average grades for each item.
73
    if (is_array($report_info[$outcomeid]['items'])) {
74
        foreach ($report_info[$outcomeid]['items'] as $itemid => $item) {
75
            $params = array();
76
            $hidesuspendedsql = '';
77
            if ($showonlyactiveenrol && !empty($suspendedusers)) {
78
                list($notinusers, $params) = $DB->get_in_or_equal($suspendedusers, SQL_PARAMS_QM, null, false);
79
                $hidesuspendedsql = ' AND userid ' . $notinusers;
80
            }
81
            $params = array_merge(array($itemid), $params);
82
 
83
            $sql = "SELECT itemid, AVG(finalgrade) AS avg, COUNT(finalgrade) AS count
84
                      FROM {grade_grades}
85
                     WHERE itemid = ?".
86
                     $hidesuspendedsql.
87
                  " GROUP BY itemid";
88
            $info = $DB->get_records_sql($sql, $params);
89
 
90
            if (!$info) {
91
                unset($report_info[$outcomeid]['items'][$itemid]);
92
                continue;
93
            } else {
94
                $info = reset($info);
95
                $avg = round($info->avg, 2);
96
                $count = $info->count;
97
            }
98
 
99
            $report_info[$outcomeid]['items'][$itemid]->avg = $avg;
100
            $report_info[$outcomeid]['items'][$itemid]->count = $count;
101
        }
102
    }
103
}
104
 
1441 ariadna 105
print_grade_page_head($courseid, 'report', 'outcomes');
106
 
107
if ($taskindicator->has_task_record()) {
108
    echo $OUTPUT->render($taskindicator);
109
    echo $OUTPUT->footer();
110
    exit;
111
}
112
 
1 efrain 113
$html = '<table class="generaltable boxaligncenter" width="90%" cellspacing="1" cellpadding="5" summary="Outcomes Report">' . "\n";
114
$html .= '<tr><th class="header c0" scope="col">' . get_string('outcomeshortname', 'grades') . '</th>';
115
$html .= '<th class="header c1" scope="col">' . get_string('courseavg', 'grades') . '</th>';
116
$html .= '<th class="header c2" scope="col">' . get_string('sitewide', 'grades') . '</th>';
117
$html .= '<th class="header c3" scope="col">' . get_string('activities', 'grades') . '</th>';
118
$html .= '<th class="header c4" scope="col">' . get_string('average', 'grades') . '</th>';
119
$html .= '<th class="header c5" scope="col">' . get_string('numberofgrades', 'grades') . '</th></tr>' . "\n";
120
 
121
$row = 0;
122
foreach ($report_info as $outcomeid => $outcomedata) {
123
    $rowspan = count($outcomedata['items']);
124
    // If there are no items for this outcome, rowspan will equal 0, which is not good.
125
    if ($rowspan == 0) {
126
        $rowspan = 1;
127
    }
128
 
129
    $shortname_html = '<tr class="r' . $row . '"><td class="cell c0" rowspan="' . $rowspan . '">' . $outcomedata['outcome']->shortname . "</td>\n";
130
 
131
    $sitewide = get_string('no');
132
    if (empty($outcomedata['outcome']->courseid)) {
133
        $sitewide = get_string('yes');
134
    }
135
 
136
    $sitewide_html = '<td class="cell c2" rowspan="' . $rowspan . '">' . $sitewide . "</td>\n";
137
 
138
    $outcomedata['outcome']->sum = 0;
139
    $scale = new grade_scale(array('id' => $outcomedata['outcome']->scaleid), false);
140
 
141
    $print_tr = false;
142
    $items_html = '';
143
 
144
    if (!empty($outcomedata['items'])) {
145
        foreach ($outcomedata['items'] as $itemid => $item) {
146
            if ($print_tr) {
147
                $row++;
148
                $items_html .= "<tr class=\"r$row\">\n";
149
            }
150
 
151
            $grade_item = new grade_item($item, false);
152
 
153
            if ($item->itemtype == 'mod') {
154
                $cm = get_coursemodule_from_instance($item->itemmodule, $item->iteminstance, $item->courseid);
155
                $itemname = '<a href="'.$CFG->wwwroot.'/mod/'.$item->itemmodule.'/view.php?id='.$cm->id.'">'.format_string($cm->name, true, $cm->course).'</a>';
156
            } else {
157
                $itemname = $grade_item->get_name();
158
            }
159
 
160
            $outcomedata['outcome']->sum += $item->avg;
161
            $gradehtml = $scale->get_nearest_item($item->avg);
162
 
163
            $items_html .= "<td class=\"cell c3\">$itemname</td>"
164
                         . "<td class=\"cell c4\">$gradehtml ($item->avg)</td>"
165
                         . "<td class=\"cell c5\">$item->count</td></tr>\n";
166
            $print_tr = true;
167
        }
168
    } else {
169
        $items_html .= "<td class=\"cell c3\"> - </td><td class=\"cell c4\"> - </td><td class=\"cell c5\"> 0 </td></tr>\n";
170
    }
171
 
172
    // Calculate outcome average.
173
    if (is_array($outcomedata['items'])) {
174
        $count = count($outcomedata['items']);
175
        if ($count > 0) {
176
            $avg = $outcomedata['outcome']->sum / $count;
177
        } else {
178
            $avg = $outcomedata['outcome']->sum;
179
        }
180
        $avg_html = $scale->get_nearest_item($avg) . " (" . round($avg, 2) . ")\n";
181
    } else {
182
        $avg_html = ' - ';
183
    }
184
 
185
    $outcomeavg_html = '<td class="cell c1" rowspan="' . $rowspan . '">' . $avg_html . "</td>\n";
186
 
187
    $html .= $shortname_html . $outcomeavg_html . $sitewide_html . $items_html;
188
    $row++;
189
}
190
 
191
$html .= '</table>';
192
 
193
echo $html;
194
 
195
$event = \gradereport_outcomes\event\grade_report_viewed::create(
196
    array(
197
        'context' => $context,
198
        'courseid' => $courseid,
199
    )
200
);
201
$event->trigger();
202
 
203
echo $OUTPUT->footer();