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
 * 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
$deactivate = optional_param('lock', 0, PARAM_INT);
36
$confirm    = optional_param('confirm', false, PARAM_BOOL);
37
$delete     = optional_param('delete', 0, PARAM_INT);
38
$archive    = optional_param('archive', 0, PARAM_INT);
39
$msg        = optional_param('msg', '', PARAM_TEXT);
40
 
41
require_login();
42
 
43
if (empty($CFG->enablebadges)) {
44
    throw new \moodle_exception('badgesdisabled', 'badges');
45
}
46
 
47
if (empty($CFG->badges_allowcoursebadges) && ($type == BADGE_TYPE_COURSE)) {
48
    throw new \moodle_exception('coursebadgesdisabled', 'badges');
49
}
50
 
51
$urlparams = ['type' => $type];
52
 
53
if ($course = $DB->get_record('course', ['id' => $courseid])) {
54
    $urlparams['id'] = $course->id;
55
}
56
 
57
$hdr = get_string('managebadges', 'badges');
58
$returnurl = new moodle_url('/badges/index.php', $urlparams);
59
$PAGE->set_url($returnurl);
60
$PAGE->add_body_class('limitedwidth');
61
 
62
if ($type == BADGE_TYPE_SITE) {
63
    $title = get_string('sitebadges', 'badges');
64
    $PAGE->set_context(context_system::instance());
65
    $PAGE->set_pagelayout('admin');
66
    $PAGE->set_heading(get_string('administrationsite'));
67
    navigation_node::override_active_url(new moodle_url('/badges/index.php', array('type' => BADGE_TYPE_SITE)), true);
68
} else {
69
    require_login($course);
70
    $coursecontext = context_course::instance($course->id);
71
    $title = get_string('coursebadges', 'badges');
72
    $PAGE->set_context($coursecontext);
73
    $PAGE->set_pagelayout('incourse');
74
    $PAGE->set_heading(format_string($course->fullname, true, array('context' => $coursecontext)));
75
    navigation_node::override_active_url(
76
        new moodle_url('/badges/index.php', array('type' => BADGE_TYPE_COURSE, 'id' => $course->id))
77
    );
78
}
79
 
80
if (!has_any_capability(array(
81
        'moodle/badges:viewawarded',
82
        'moodle/badges:createbadge',
83
        'moodle/badges:awardbadge',
84
        'moodle/badges:configurecriteria',
85
        'moodle/badges:configuremessages',
86
        'moodle/badges:configuredetails',
87
        'moodle/badges:deletebadge'), $PAGE->context)) {
88
    redirect($CFG->wwwroot);
89
}
90
 
91
$PAGE->set_title($hdr);
92
$output = $PAGE->get_renderer('core', 'badges');
93
 
11 efrain 94
if ($delete || $archive) {
1 efrain 95
    $badgeid = ($archive != 0) ? $archive : $delete;
96
    $badge = new badge($badgeid);
11 efrain 97
    require_capability('moodle/badges:deletebadge', $badge->get_context());
1 efrain 98
    if (!$confirm) {
99
        echo $output->header();
100
        // Archive this badge?
101
        echo $output->heading(get_string('archivebadge', 'badges', $badge->name));
102
        $archivebutton = $output->single_button(
103
                            new moodle_url($PAGE->url, array('archive' => $badge->id, 'confirm' => 1)),
104
                            get_string('archiveconfirm', 'badges'));
105
        echo $output->box(get_string('archivehelp', 'badges') . $archivebutton, 'generalbox');
106
 
107
        // Delete this badge?
108
        echo $output->heading(get_string('delbadge', 'badges', $badge->name));
109
        $deletebutton = $output->single_button(
110
                            new moodle_url($PAGE->url, array('delete' => $badge->id, 'confirm' => 1)),
111
                            get_string('delconfirm', 'badges'));
112
        echo $output->box(get_string('deletehelp', 'badges') . $deletebutton, 'generalbox');
113
 
114
        // Go back.
115
        echo $output->action_link($returnurl, get_string('cancel'));
116
 
117
        echo $output->footer();
118
        die();
119
    } else {
120
        require_sesskey();
121
        $archiveonly = ($archive != 0) ? true : false;
122
        $badge->delete($archiveonly);
123
        redirect($returnurl);
124
    }
125
}
126
 
127
if ($deactivate && has_capability('moodle/badges:configuredetails', $PAGE->context)) {
128
    require_sesskey();
129
    $badge = new badge($deactivate);
130
    if ($badge->is_locked()) {
131
        $badge->set_status(BADGE_STATUS_INACTIVE_LOCKED);
132
    } else {
133
        $badge->set_status(BADGE_STATUS_INACTIVE);
134
    }
135
    $msg = 'deactivatesuccess';
136
    $returnurl->param('msg', $msg);
137
    redirect($returnurl);
138
}
139
 
140
echo $OUTPUT->header();
141
$backurl = $type == BADGE_TYPE_SITE ? null : new moodle_url('/badges/view.php', ['type' => $type, 'id' => $courseid]);
142
$actionbar = new \core_badges\output\standard_action_bar($PAGE, $type, false, true, $backurl);
143
echo $output->render_tertiary_navigation($actionbar);
144
 
145
if ($type == BADGE_TYPE_SITE) {
146
    echo $OUTPUT->heading_with_help($hdr, 'sitebadges', 'badges');
147
} else {
148
    echo $OUTPUT->heading($hdr);
149
}
150
 
151
echo $OUTPUT->box('', 'notifyproblem hide', 'check_connection');
152
 
153
if ($course && $course->startdate > time()) {
154
    echo $OUTPUT->box(get_string('error:notifycoursedate', 'badges'), 'generalbox notifyproblem');
155
}
156
 
157
if ($msg !== '') {
158
    echo $OUTPUT->notification(get_string($msg, 'badges'), 'notifysuccess');
159
}
160
 
161
$report = system_report_factory::create(badges::class, $PAGE->context);
162
$report->set_default_no_results_notice(new lang_string('nobadges', 'badges'));
163
 
164
echo $report->output();
165
 
166
echo $OUTPUT->footer();