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 overview report
19
 *
20
 * @package   gradereport_overview
21
 * @copyright 2007 Nicolas Connault
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
require_once '../../../config.php';
26
require_once $CFG->libdir.'/gradelib.php';
27
require_once $CFG->dirroot.'/grade/lib.php';
28
require_once $CFG->dirroot.'/grade/report/overview/lib.php';
29
 
30
$courseid = optional_param('id', SITEID, PARAM_INT);
31
$userid   = optional_param('userid', $USER->id, PARAM_INT);
32
 
33
$PAGE->set_url(new moodle_url('/grade/report/overview/index.php', array('id' => $courseid, 'userid' => $userid)));
34
 
35
if (!$course = $DB->get_record('course', array('id' => $courseid))) {
36
    throw new \moodle_exception('invalidcourseid');
37
}
38
require_login(null, false);
39
$PAGE->set_course($course);
40
 
41
$context = context_course::instance($course->id);
42
$systemcontext = context_system::instance();
43
$personalcontext = null;
44
 
45
// If we are accessing the page from a site context then ignore this check.
46
if ($courseid != SITEID) {
47
    require_capability('gradereport/overview:view', $context);
48
}
49
 
50
if (empty($userid)) {
51
    require_capability('moodle/grade:viewall', $context);
52
 
53
} else {
54
    if (!$DB->get_record('user', array('id'=>$userid, 'deleted'=>0)) or isguestuser($userid)) {
55
        throw new \moodle_exception('invaliduserid');
56
    }
57
    $personalcontext = context_user::instance($userid);
58
}
59
 
60
if (isset($personalcontext) && $courseid == SITEID) {
61
    $PAGE->set_context($personalcontext);
62
} else {
63
    $PAGE->set_context($context);
64
}
65
if ($userid == $USER->id) {
66
    $settings = $PAGE->settingsnav->find('mygrades', null);
67
    $settings->make_active();
68
} else if ($courseid != SITEID && $userid) {
69
    // Show some other navbar thing.
70
    $user = $DB->get_record('user', array('id' => $userid), '*', MUST_EXIST);
71
    $PAGE->navigation->extend_for_user($user);
72
}
73
 
74
$access = grade_report_overview::check_access($systemcontext, $context, $personalcontext, $course, $userid);
75
 
76
if (!$access) {
77
    // no access to grades!
78
    throw new \moodle_exception('nopermissiontoviewgrades', 'error',  $CFG->wwwroot.'/course/view.php?id='.$courseid);
79
}
80
 
81
/// return tracking object
82
$gpr = new grade_plugin_return(array('type'=>'report', 'plugin'=>'overview', 'courseid'=>$course->id, 'userid'=>$userid));
83
 
84
/// last selected report session tracking
85
if (!isset($USER->grade_last_report)) {
86
    $USER->grade_last_report = array();
87
}
88
$USER->grade_last_report[$course->id] = 'overview';
89
 
90
$actionbar = new \core_grades\output\general_action_bar($context,
91
    new moodle_url('/grade/report/overview/index.php', ['id' => $courseid]), 'report', 'overview');
92
 
1441 ariadna 93
$taskindicator = new \core\output\task_indicator(
94
    \core_course\task\regrade_final_grades::create($courseid),
95
    get_string('recalculatinggrades', 'grades'),
96
    get_string('recalculatinggradesadhoc', 'grades'),
97
    $PAGE->url,
98
);
99
 
1 efrain 100
if (has_capability('moodle/grade:viewall', $context) && $courseid != SITEID) {
101
    // Please note this would be extremely slow if we wanted to implement this properly for all teachers.
102
    $groupmode    = groups_get_course_groupmode($course);   // Groups are being used
103
    $currentgroup = $gpr->groupid;
104
 
105
    if (!$currentgroup) {      // To make some other functions work better later
106
        $currentgroup = NULL;
107
    }
108
 
109
    $isseparategroups = ($course->groupmode == SEPARATEGROUPS and !has_capability('moodle/site:accessallgroups', $context));
110
 
111
    if ($isseparategroups and (!$currentgroup)) {
112
        // no separate group access, can view only self
113
        $userid = $USER->id;
114
        $user_selector = false;
115
    } else {
116
        $user_selector = true;
117
    }
118
 
119
    if (empty($userid)) {
120
        print_grade_page_head($courseid, 'report', 'overview', false, false, false,
121
            true, null, null, null, $actionbar);
122
 
123
        groups_print_course_menu($course, $gpr->get_return_url('index.php?id='.$courseid, array('userid'=>0)));
124
 
1441 ariadna 125
        if ($taskindicator->has_task_record()) {
126
            echo $OUTPUT->render($taskindicator);
127
            echo $OUTPUT->footer();
128
            exit;
129
        }
130
 
1 efrain 131
        if ($user_selector) {
132
            $renderer = $PAGE->get_renderer('gradereport_overview');
133
            echo $renderer->graded_users_selector('overview', $course, $userid, $currentgroup, false);
134
        }
135
        // do not list all users
136
 
137
    } else { // Only show one user's report
138
        $report = new grade_report_overview($userid, $gpr, $context);
139
        // Make sure we have proper final grades - this report shows grades from other courses, not just the
140
        // selected one, so we need to check and regrade all courses the user is enrolled in.
141
        $report->regrade_all_courses_if_needed(true);
142
        print_grade_page_head($courseid, 'report', 'overview', get_string('pluginname', 'gradereport_overview') .
143
            ' - ' . fullname($report->user), false, false, true, null, null,
144
            $report->user, $actionbar);
145
        groups_print_course_menu($course, $gpr->get_return_url('index.php?id='.$courseid, array('userid'=>0)));
146
 
1441 ariadna 147
        if ($taskindicator->has_task_record()) {
148
            echo $OUTPUT->render($taskindicator);
149
            echo $OUTPUT->footer();
150
            exit;
151
        }
152
 
1 efrain 153
        if ($user_selector) {
154
            $renderer = $PAGE->get_renderer('gradereport_overview');
155
            echo $renderer->graded_users_selector('overview', $course, $userid, $currentgroup, false);
156
        }
157
 
158
        if ($currentgroup and !groups_is_member($currentgroup, $userid)) {
159
            echo $OUTPUT->notification(get_string('groupusernotmember', 'error'));
160
        } else {
161
            if ($report->fill_table()) {
162
                echo '<br />'.$report->print_table(true);
163
            }
164
        }
165
    }
166
} else { // Non-admins and users viewing from the site context can just see their own report.
167
 
168
    // Create a report instance
169
    $report = new grade_report_overview($userid, $gpr, $context);
170
 
171
    if (!empty($report->studentcourseids)) {
172
        // If the course id matches the site id then we don't have a course context to work with.
173
        // Display a standard page.
174
        if ($courseid == SITEID) {
175
            $PAGE->set_pagelayout('standard');
176
            $header = get_string('grades', 'grades') . ' - ' . fullname($report->user);
177
            $PAGE->set_title($header);
178
            $PAGE->set_heading(fullname($report->user));
179
 
180
            if ($USER->id != $report->user->id) {
181
                $PAGE->navigation->extend_for_user($report->user);
182
                if ($node = $PAGE->settingsnav->get('userviewingsettings'.$report->user->id)) {
183
                    $node->forceopen = true;
184
                }
185
            } else if ($node = $PAGE->settingsnav->get('usercurrentsettings', navigation_node::TYPE_CONTAINER)) {
186
                $node->forceopen = true;
187
            }
188
 
189
            echo $OUTPUT->header();
1441 ariadna 190
            if ($taskindicator->has_task_record()) {
191
                echo $OUTPUT->render($taskindicator);
192
                echo $OUTPUT->footer();
193
                exit;
194
            }
1 efrain 195
            if ($report->fill_table(true, true)) {
196
                echo html_writer::tag('h3', get_string('coursesiamtaking', 'grades'));
197
                echo '<br />' . $report->print_table(true);
198
            }
199
        } else { // We have a course context. We must be navigating from the gradebook.
200
            print_grade_page_head($courseid, 'report', 'overview', get_string('pluginname', 'gradereport_overview')
201
                . ' - ' . fullname($report->user), false, false, true, null, null,
202
                $report->user, $actionbar);
1441 ariadna 203
            if ($taskindicator->has_task_record()) {
204
                echo $OUTPUT->render($taskindicator);
205
                echo $OUTPUT->footer();
206
                exit;
207
            }
1 efrain 208
            if ($report->fill_table()) {
209
                echo '<br />' . $report->print_table(true);
210
            }
211
        }
212
    } else {
213
        $PAGE->set_pagelayout('standard');
214
        $header = get_string('grades', 'grades') . ' - ' . fullname($report->user);
215
        $PAGE->set_title($header);
216
        $PAGE->set_heading(fullname($report->user));
217
        echo $OUTPUT->header();
218
    }
219
 
220
    if (count($report->teachercourses)) {
1441 ariadna 221
        if ($taskindicator->has_task_record()) {
222
            echo $OUTPUT->render($taskindicator);
223
            echo $OUTPUT->footer();
224
            exit;
225
        }
1 efrain 226
        echo html_writer::tag('h3', get_string('coursesiamteaching', 'grades'));
227
        $report->print_teacher_table();
228
    }
229
 
230
    if (empty($report->studentcourseids) && empty($report->teachercourses)) {
231
        // We have no report to show the user. Let them know something.
232
        echo $OUTPUT->notification(get_string('noreports', 'grades'), 'notifymessage');
233
    }
234
}
235
 
236
grade_report_overview::viewed($context, $courseid, $userid);
237
 
238
echo $OUTPUT->footer();