Proyectos de Subversion Moodle

Rev

| 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
 * View a particular instance of the subcourse
19
 *
20
 * @package     mod_subcourse
21
 * @copyright   2008 David Mudrak <david@moodle.com>
22
 * @license     http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
require(__DIR__.'/../../config.php');
26
require_once($CFG->dirroot.'/mod/subcourse/locallib.php');
27
require_once($CFG->libdir.'/gradelib.php');
28
 
29
$id = required_param('id', PARAM_INT);
30
$fetchnow = optional_param('fetchnow', 0, PARAM_INT);
31
$isblankwindow = optional_param('isblankwindow', false, PARAM_BOOL);
32
 
33
$cm = get_coursemodule_from_id('subcourse', $id, 0, false, MUST_EXIST);
34
$course = $DB->get_record('course', ['id' => $cm->course], '*', MUST_EXIST);
35
$subcourse = $DB->get_record('subcourse', ['id' => $cm->instance], '*', MUST_EXIST);
36
 
37
$context = context_module::instance($cm->id);
38
$coursecontext = context_course::instance($course->id);
39
 
40
require_login($course, true, $cm);
41
require_capability('mod/subcourse:view', $context);
42
 
43
$PAGE->set_url(new moodle_url('/mod/subcourse/view.php', ['id' => $cm->id]));
44
$PAGE->set_title($subcourse->name);
45
$PAGE->set_heading($course->fullname);
46
 
47
if (empty($subcourse->refcourse)) {
48
    $refcourse = false;
49
 
50
} else {
51
    $refcourse = $DB->get_record('course', ['id' => $subcourse->refcourse], '*', IGNORE_MISSING);
52
}
53
 
54
if ($fetchnow && $refcourse) {
55
    require_sesskey();
56
    require_capability('mod/subcourse:fetchgrades', $context);
57
 
58
    $event = \mod_subcourse\event\subcourse_grades_fetched::create([
59
        'objectid' => $subcourse->id,
60
        'context' => $context,
61
        'other' => ['refcourse' => $refcourse->id]
62
    ]);
63
 
64
    $event->add_record_snapshot('course_modules', $cm);
65
    $event->add_record_snapshot('course', $course);
66
    $event->add_record_snapshot('subcourse', $subcourse);
67
    $event->trigger();
68
 
69
    $result = subcourse_grades_update($subcourse->course, $subcourse->id, $subcourse->refcourse,
70
        null, false, false, [], $subcourse->fetchpercentage);
71
 
72
    if ($result == GRADE_UPDATE_OK) {
73
        subcourse_update_timefetched($subcourse->id);
74
        redirect(new moodle_url('/mod/subcourse/view.php', ['id' => $cm->id]));
75
 
76
    } else {
77
        throw new moodle_exception('errfetch', 'subcourse', $CFG->wwwroot . '/mod/subcourse/view.php?id=' . $cm->id, $result);
78
    }
79
}
80
 
81
subcourse_set_module_viewed($subcourse, $context, $course, $cm);
82
 
83
if ($refcourse && !empty($subcourse->instantredirect)) {
84
    if (!has_capability('mod/subcourse:fetchgrades', $context)) {
85
        redirect(new moodle_url('/course/view.php', ['id' => $refcourse->id]));
86
    }
87
}
88
 
89
echo $OUTPUT->header();
90
 
91
if ($refcourse) {
92
    $percentage = \core_completion\progress::get_course_progress_percentage($refcourse);
93
    $strgrade = subcourse_get_current_grade($subcourse, $USER->id);
94
 
95
    echo $OUTPUT->render_from_template('mod_subcourse/subcourseinfo', [
96
        'haspercentage' => ($percentage !== null),
97
        'hasstrgrade' => ($strgrade !== null),
98
        'percentage' => floor((float)$percentage),
99
        'strgrade' => $strgrade,
100
    ]);
101
 
102
    echo html_writer::start_div('actionbuttons');
103
 
104
    if ($subcourse->blankwindow && !$isblankwindow) {
105
        $target = '_blank';
106
    } else {
107
        $target = '';
108
    }
109
 
110
    echo html_writer::link(
111
        new moodle_url('/course/view.php', ['id' => $refcourse->id]),
112
        get_string('gotorefcourse', 'subcourse', format_string($refcourse->fullname)),
113
        ['class' => 'btn btn-primary', 'target' => $target]
114
    );
115
 
116
    $refcoursecontext = context_course::instance($refcourse->id);
117
 
118
    if (has_all_capabilities(['gradereport/grader:view', 'moodle/grade:viewall'], $refcoursecontext)) {
119
        echo html_writer::link(
120
            new moodle_url('/grade/report/grader/index.php', ['id' => $refcourse->id]),
121
            get_string('gotorefcoursegrader', 'subcourse', format_string($refcourse->fullname)),
122
            ['class' => 'btn btn-secondary']
123
        );
124
    }
125
 
126
    if (has_all_capabilities(['gradereport/user:view', 'moodle/grade:view'], $refcoursecontext)
127
            && $refcourse->showgrades && ($strgrade !== null)) {
128
        echo html_writer::link(
129
            new moodle_url('/grade/report/user/index.php', ['id' => $refcourse->id]),
130
            get_string('gotorefcoursemygrades', 'subcourse', format_string($refcourse->fullname)),
131
            ['class' => 'btn btn-secondary']
132
        );
133
    }
134
 
135
    if (has_capability('mod/subcourse:fetchgrades', $context)) {
136
        echo html_writer::link(
137
            new moodle_url($PAGE->url, ['sesskey' => sesskey(), 'fetchnow' => 1]),
138
            get_string('fetchnow', 'subcourse'),
139
            ['class' => 'btn btn-link']
140
        );
141
 
142
        if (empty($subcourse->timefetched)) {
143
            $fetchinfo = get_string('lastfetchnever', 'subcourse');
144
        } else {
145
            $fetchinfo = get_string('lastfetchtime', 'subcourse', userdate($subcourse->timefetched));
146
        }
147
 
148
        echo html_writer::tag('small', $fetchinfo, ['class' => 'dimmed_text']);
149
    }
150
 
151
    // End of div.actionbuttons.
152
    echo html_writer::end_div();
153
 
154
} else {
155
    if (has_capability('mod/subcourse:fetchgrades', $context)) {
156
        echo $OUTPUT->notification(get_string('refcoursenull', 'subcourse'));
157
    }
158
}
159
 
160
echo $OUTPUT->footer();