Proyectos de Subversion Moodle

Rev

Rev 11 | | 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
 * Page for badges management
19
 *
20
 * @package    core
21
 * @subpackage badges
22
 * @copyright  2012 onwards Totara Learning Solutions Ltd {@link http://www.totaralms.com/}
23
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
24
 * @author     Yuliya Bozhko <yuliya.bozhko@totaralms.com>
25
 */
26
 
27
use core_badges\reportbuilder\local\systemreports\badges;
28
use core_reportbuilder\system_report_factory;
29
 
30
require_once(__DIR__ . '/../config.php');
31
require_once($CFG->libdir . '/badgeslib.php');
32
 
33
$type       = required_param('type', PARAM_INT);
34
$courseid   = optional_param('id', 0, PARAM_INT);
35
$confirm    = optional_param('confirm', false, PARAM_BOOL);
36
$delete     = optional_param('delete', 0, PARAM_INT);
37
$archive    = optional_param('archive', 0, PARAM_INT);
38
$msg        = optional_param('msg', '', PARAM_TEXT);
39
 
40
require_login();
41
 
42
if (empty($CFG->enablebadges)) {
43
    throw new \moodle_exception('badgesdisabled', 'badges');
44
}
45
 
46
if (empty($CFG->badges_allowcoursebadges) && ($type == BADGE_TYPE_COURSE)) {
47
    throw new \moodle_exception('coursebadgesdisabled', 'badges');
48
}
49
 
1441 ariadna 50
if ($type == BADGE_TYPE_COURSE && !$courseid) {
51
    throw new \moodle_exception('courseidnotfound');
52
}
53
 
1 efrain 54
$urlparams = ['type' => $type];
55
 
56
if ($course = $DB->get_record('course', ['id' => $courseid])) {
57
    $urlparams['id'] = $course->id;
58
}
59
 
60
$returnurl = new moodle_url('/badges/index.php', $urlparams);
61
$PAGE->set_url($returnurl);
62
$PAGE->add_body_class('limitedwidth');
63
 
64
if ($type == BADGE_TYPE_SITE) {
65
    $title = get_string('sitebadges', 'badges');
66
    $PAGE->set_context(context_system::instance());
67
    $PAGE->set_pagelayout('admin');
68
    $PAGE->set_heading(get_string('administrationsite'));
1441 ariadna 69
    navigation_node::override_active_url(new moodle_url('/badges/index.php', ['type' => BADGE_TYPE_SITE]), true);
70
    $eventotherparams = ['badgetype' => BADGE_TYPE_SITE];
1 efrain 71
} else {
72
    require_login($course);
73
    $coursecontext = context_course::instance($course->id);
74
    $title = get_string('coursebadges', 'badges');
75
    $PAGE->set_context($coursecontext);
76
    $PAGE->set_pagelayout('incourse');
1441 ariadna 77
    $PAGE->set_heading(format_string($course->fullname, true, ['context' => $coursecontext]));
1 efrain 78
    navigation_node::override_active_url(
1441 ariadna 79
        new moodle_url('/badges/index.php', ['type' => BADGE_TYPE_COURSE, 'id' => $course->id])
1 efrain 80
    );
1441 ariadna 81
    $eventotherparams = ['badgetype' => BADGE_TYPE_COURSE, 'courseid' => $course->id];
1 efrain 82
}
83
 
1441 ariadna 84
if (!has_any_capability([
85
        'moodle/badges:viewbadges',
1 efrain 86
        'moodle/badges:viewawarded',
87
        'moodle/badges:createbadge',
88
        'moodle/badges:awardbadge',
89
        'moodle/badges:configurecriteria',
90
        'moodle/badges:configuremessages',
91
        'moodle/badges:configuredetails',
1441 ariadna 92
        'moodle/badges:deletebadge'], $PAGE->context)) {
1 efrain 93
    redirect($CFG->wwwroot);
94
}
95
 
1441 ariadna 96
$PAGE->set_title($title);
97
 
98
/** @var core_badges_renderer $output */
1 efrain 99
$output = $PAGE->get_renderer('core', 'badges');
100
 
11 efrain 101
if ($delete || $archive) {
1 efrain 102
    $badgeid = ($archive != 0) ? $archive : $delete;
103
    $badge = new badge($badgeid);
11 efrain 104
    require_capability('moodle/badges:deletebadge', $badge->get_context());
1 efrain 105
    if (!$confirm) {
106
        echo $output->header();
107
        // Archive this badge?
108
        echo $output->heading(get_string('archivebadge', 'badges', $badge->name));
109
        $archivebutton = $output->single_button(
1441 ariadna 110
                            new moodle_url($PAGE->url, ['archive' => $badge->id, 'confirm' => 1]),
1 efrain 111
                            get_string('archiveconfirm', 'badges'));
112
        echo $output->box(get_string('archivehelp', 'badges') . $archivebutton, 'generalbox');
113
 
114
        // Delete this badge?
115
        echo $output->heading(get_string('delbadge', 'badges', $badge->name));
116
        $deletebutton = $output->single_button(
1441 ariadna 117
                            new moodle_url($PAGE->url, ['delete' => $badge->id, 'confirm' => 1]),
1 efrain 118
                            get_string('delconfirm', 'badges'));
119
        echo $output->box(get_string('deletehelp', 'badges') . $deletebutton, 'generalbox');
120
 
121
        // Go back.
122
        echo $output->action_link($returnurl, get_string('cancel'));
123
 
124
        echo $output->footer();
125
        die();
126
    } else {
127
        require_sesskey();
128
        $archiveonly = ($archive != 0) ? true : false;
129
        $badge->delete($archiveonly);
130
        redirect($returnurl);
131
    }
132
}
133
 
134
echo $OUTPUT->header();
135
 
1441 ariadna 136
echo $OUTPUT->container_start('badges-heading');
1 efrain 137
if ($type == BADGE_TYPE_SITE) {
1441 ariadna 138
    echo $OUTPUT->heading_with_help($title, 'sitebadges', 'badges');
1 efrain 139
} else {
1441 ariadna 140
    echo $OUTPUT->heading($title);
1 efrain 141
}
1441 ariadna 142
$actionbar = new \core_badges\output\standard_action_bar(
143
    page: $PAGE,
144
    type: $type,
145
    showaddbadge: true,
146
);
147
echo $output->render_tertiary_navigation($actionbar);
148
echo $OUTPUT->container_end();
1 efrain 149
 
150
echo $OUTPUT->box('', 'notifyproblem hide', 'check_connection');
151
 
152
if ($course && $course->startdate > time()) {
1441 ariadna 153
    echo $OUTPUT->notification(
154
        get_string('error:notifycoursedate', 'badges', userdate($course->startdate)),
155
        'warning'
156
    );
1 efrain 157
}
158
 
159
if ($msg !== '') {
160
    echo $OUTPUT->notification(get_string($msg, 'badges'), 'notifysuccess');
161
}
162
 
163
$report = system_report_factory::create(badges::class, $PAGE->context);
164
 
165
echo $report->output();
1441 ariadna 166
$PAGE->requires->js_call_amd('core_badges/actions', 'init');
1 efrain 167
 
1441 ariadna 168
// Trigger event, badge listing viewed.
169
$eventparams = ['context' => $PAGE->context, 'other' => $eventotherparams];
170
$event = \core\event\badge_listing_viewed::create($eventparams);
171
$event->trigger();
172
 
1 efrain 173
echo $OUTPUT->footer();