2013-04-02 13:57:39 +13:00
|
|
|
<?php
|
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Page for badges management
|
|
|
|
*
|
|
|
|
* @package core
|
|
|
|
* @subpackage badges
|
|
|
|
* @copyright 2012 onwards Totara Learning Solutions Ltd {@link http://www.totaralms.com/}
|
|
|
|
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
|
* @author Yuliya Bozhko <yuliya.bozhko@totaralms.com>
|
|
|
|
*/
|
|
|
|
|
2023-02-12 17:20:33 +01:00
|
|
|
use core_badges\reportbuilder\local\systemreports\badges;
|
|
|
|
use core_reportbuilder\system_report_factory;
|
|
|
|
|
2016-02-26 17:47:58 +11:00
|
|
|
require_once(__DIR__ . '/../config.php');
|
2013-04-02 13:57:39 +13:00
|
|
|
require_once($CFG->libdir . '/badgeslib.php');
|
|
|
|
|
|
|
|
$type = required_param('type', PARAM_INT);
|
|
|
|
$courseid = optional_param('id', 0, PARAM_INT);
|
|
|
|
$deactivate = optional_param('lock', 0, PARAM_INT);
|
|
|
|
$confirm = optional_param('confirm', false, PARAM_BOOL);
|
|
|
|
$delete = optional_param('delete', 0, PARAM_INT);
|
2013-12-09 15:50:10 +13:00
|
|
|
$archive = optional_param('archive', 0, PARAM_INT);
|
2013-04-02 13:57:39 +13:00
|
|
|
$msg = optional_param('msg', '', PARAM_TEXT);
|
|
|
|
|
|
|
|
require_login();
|
|
|
|
|
|
|
|
if (empty($CFG->enablebadges)) {
|
2022-04-12 09:38:41 +05:30
|
|
|
throw new \moodle_exception('badgesdisabled', 'badges');
|
2013-04-02 13:57:39 +13:00
|
|
|
}
|
|
|
|
|
2013-04-29 14:36:14 +12:00
|
|
|
if (empty($CFG->badges_allowcoursebadges) && ($type == BADGE_TYPE_COURSE)) {
|
2022-04-12 09:38:41 +05:30
|
|
|
throw new \moodle_exception('coursebadgesdisabled', 'badges');
|
2013-04-29 14:36:14 +12:00
|
|
|
}
|
|
|
|
|
2024-08-13 17:16:48 +02:00
|
|
|
if ($type == BADGE_TYPE_COURSE && !$courseid) {
|
|
|
|
throw new \moodle_exception('courseidnotfound');
|
|
|
|
}
|
|
|
|
|
2023-02-12 17:20:33 +01:00
|
|
|
$urlparams = ['type' => $type];
|
2013-04-02 13:57:39 +13:00
|
|
|
|
2023-02-12 17:20:33 +01:00
|
|
|
if ($course = $DB->get_record('course', ['id' => $courseid])) {
|
2013-04-02 13:57:39 +13:00
|
|
|
$urlparams['id'] = $course->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
$returnurl = new moodle_url('/badges/index.php', $urlparams);
|
|
|
|
$PAGE->set_url($returnurl);
|
2022-01-11 11:36:45 +01:00
|
|
|
$PAGE->add_body_class('limitedwidth');
|
2013-04-02 13:57:39 +13:00
|
|
|
|
|
|
|
if ($type == BADGE_TYPE_SITE) {
|
|
|
|
$title = get_string('sitebadges', 'badges');
|
|
|
|
$PAGE->set_context(context_system::instance());
|
|
|
|
$PAGE->set_pagelayout('admin');
|
2021-11-22 15:22:35 +08:00
|
|
|
$PAGE->set_heading(get_string('administrationsite'));
|
2024-08-13 17:16:48 +02:00
|
|
|
navigation_node::override_active_url(new moodle_url('/badges/index.php', ['type' => BADGE_TYPE_SITE]), true);
|
|
|
|
$eventotherparams = ['badgetype' => BADGE_TYPE_SITE];
|
2013-04-02 13:57:39 +13:00
|
|
|
} else {
|
|
|
|
require_login($course);
|
2013-09-20 14:33:16 +12:00
|
|
|
$coursecontext = context_course::instance($course->id);
|
2013-04-02 13:57:39 +13:00
|
|
|
$title = get_string('coursebadges', 'badges');
|
2013-09-20 14:33:16 +12:00
|
|
|
$PAGE->set_context($coursecontext);
|
2014-09-02 14:44:24 +12:00
|
|
|
$PAGE->set_pagelayout('incourse');
|
2024-08-13 17:16:48 +02:00
|
|
|
$PAGE->set_heading(format_string($course->fullname, true, ['context' => $coursecontext]));
|
2013-04-02 13:57:39 +13:00
|
|
|
navigation_node::override_active_url(
|
2024-08-13 17:16:48 +02:00
|
|
|
new moodle_url('/badges/index.php', ['type' => BADGE_TYPE_COURSE, 'id' => $course->id])
|
2013-04-02 13:57:39 +13:00
|
|
|
);
|
2024-08-13 17:16:48 +02:00
|
|
|
$eventotherparams = ['badgetype' => BADGE_TYPE_COURSE, 'courseid' => $course->id];
|
2013-04-02 13:57:39 +13:00
|
|
|
}
|
|
|
|
|
2024-08-13 17:16:48 +02:00
|
|
|
if (!has_any_capability([
|
|
|
|
'moodle/badges:viewbadges',
|
2013-04-16 10:47:40 +12:00
|
|
|
'moodle/badges:viewawarded',
|
|
|
|
'moodle/badges:createbadge',
|
|
|
|
'moodle/badges:awardbadge',
|
2019-02-28 13:46:03 +01:00
|
|
|
'moodle/badges:configurecriteria',
|
2013-04-16 10:47:40 +12:00
|
|
|
'moodle/badges:configuremessages',
|
|
|
|
'moodle/badges:configuredetails',
|
2024-08-13 17:16:48 +02:00
|
|
|
'moodle/badges:deletebadge'], $PAGE->context)) {
|
2013-04-02 13:57:39 +13:00
|
|
|
redirect($CFG->wwwroot);
|
|
|
|
}
|
|
|
|
|
2024-08-13 17:16:48 +02:00
|
|
|
$PAGE->set_title($title);
|
2024-08-28 11:35:54 +01:00
|
|
|
|
|
|
|
/** @var core_badges_renderer $output */
|
2013-04-02 13:57:39 +13:00
|
|
|
$output = $PAGE->get_renderer('core', 'badges');
|
|
|
|
|
2024-07-04 19:22:02 +01:00
|
|
|
if ($delete || $archive) {
|
2013-12-09 15:50:10 +13:00
|
|
|
$badgeid = ($archive != 0) ? $archive : $delete;
|
|
|
|
$badge = new badge($badgeid);
|
2024-07-04 19:22:02 +01:00
|
|
|
require_capability('moodle/badges:deletebadge', $badge->get_context());
|
2013-04-02 13:57:39 +13:00
|
|
|
if (!$confirm) {
|
|
|
|
echo $output->header();
|
2013-12-09 15:50:10 +13:00
|
|
|
// Archive this badge?
|
|
|
|
echo $output->heading(get_string('archivebadge', 'badges', $badge->name));
|
|
|
|
$archivebutton = $output->single_button(
|
2024-08-13 17:16:48 +02:00
|
|
|
new moodle_url($PAGE->url, ['archive' => $badge->id, 'confirm' => 1]),
|
2013-12-09 15:50:10 +13:00
|
|
|
get_string('archiveconfirm', 'badges'));
|
|
|
|
echo $output->box(get_string('archivehelp', 'badges') . $archivebutton, 'generalbox');
|
|
|
|
|
|
|
|
// Delete this badge?
|
|
|
|
echo $output->heading(get_string('delbadge', 'badges', $badge->name));
|
|
|
|
$deletebutton = $output->single_button(
|
2024-08-13 17:16:48 +02:00
|
|
|
new moodle_url($PAGE->url, ['delete' => $badge->id, 'confirm' => 1]),
|
2013-12-09 15:50:10 +13:00
|
|
|
get_string('delconfirm', 'badges'));
|
|
|
|
echo $output->box(get_string('deletehelp', 'badges') . $deletebutton, 'generalbox');
|
|
|
|
|
|
|
|
// Go back.
|
|
|
|
echo $output->action_link($returnurl, get_string('cancel'));
|
|
|
|
|
2013-04-02 13:57:39 +13:00
|
|
|
echo $output->footer();
|
|
|
|
die();
|
|
|
|
} else {
|
|
|
|
require_sesskey();
|
2013-12-09 15:50:10 +13:00
|
|
|
$archiveonly = ($archive != 0) ? true : false;
|
|
|
|
$badge->delete($archiveonly);
|
2013-04-02 13:57:39 +13:00
|
|
|
redirect($returnurl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-06 15:32:59 +12:00
|
|
|
if ($deactivate && has_capability('moodle/badges:configuredetails', $PAGE->context)) {
|
|
|
|
require_sesskey();
|
2013-04-02 13:57:39 +13:00
|
|
|
$badge = new badge($deactivate);
|
|
|
|
if ($badge->is_locked()) {
|
|
|
|
$badge->set_status(BADGE_STATUS_INACTIVE_LOCKED);
|
|
|
|
} else {
|
|
|
|
$badge->set_status(BADGE_STATUS_INACTIVE);
|
|
|
|
}
|
2013-09-06 15:32:59 +12:00
|
|
|
$msg = 'deactivatesuccess';
|
2013-04-02 13:57:39 +13:00
|
|
|
$returnurl->param('msg', $msg);
|
|
|
|
redirect($returnurl);
|
|
|
|
}
|
|
|
|
|
|
|
|
echo $OUTPUT->header();
|
2021-11-22 15:22:35 +08:00
|
|
|
|
2024-08-13 17:16:48 +02:00
|
|
|
echo $OUTPUT->container_start('badges-heading');
|
2013-04-02 13:57:39 +13:00
|
|
|
if ($type == BADGE_TYPE_SITE) {
|
2024-08-13 17:16:48 +02:00
|
|
|
echo $OUTPUT->heading_with_help($title, 'sitebadges', 'badges');
|
2013-04-02 13:57:39 +13:00
|
|
|
} else {
|
2024-08-13 17:16:48 +02:00
|
|
|
echo $OUTPUT->heading($title);
|
2013-04-02 13:57:39 +13:00
|
|
|
}
|
2024-08-13 17:16:48 +02:00
|
|
|
$actionbar = new \core_badges\output\standard_action_bar(
|
|
|
|
page: $PAGE,
|
|
|
|
type: $type,
|
|
|
|
showaddbadge: true,
|
|
|
|
);
|
|
|
|
echo $output->render_tertiary_navigation($actionbar);
|
|
|
|
echo $OUTPUT->container_end();
|
2021-11-22 15:22:35 +08:00
|
|
|
|
2013-04-02 13:57:39 +13:00
|
|
|
echo $OUTPUT->box('', 'notifyproblem hide', 'check_connection');
|
|
|
|
|
2023-09-12 14:55:04 +01:00
|
|
|
if ($course && $course->startdate > time()) {
|
2024-08-13 17:16:48 +02:00
|
|
|
echo $OUTPUT->notification(
|
|
|
|
get_string('error:notifycoursedate', 'badges', userdate($course->startdate)),
|
|
|
|
'warning'
|
|
|
|
);
|
2023-09-12 14:55:04 +01:00
|
|
|
}
|
2013-04-02 13:57:39 +13:00
|
|
|
|
2023-09-12 14:55:04 +01:00
|
|
|
if ($msg !== '') {
|
|
|
|
echo $OUTPUT->notification(get_string($msg, 'badges'), 'notifysuccess');
|
|
|
|
}
|
2013-04-02 13:57:39 +13:00
|
|
|
|
2023-09-12 14:55:04 +01:00
|
|
|
$report = system_report_factory::create(badges::class, $PAGE->context);
|
2024-08-28 11:35:54 +01:00
|
|
|
|
2024-08-13 17:16:48 +02:00
|
|
|
echo $report->output();
|
2024-06-18 16:52:15 +02:00
|
|
|
$PAGE->requires->js_call_amd('core_badges/actions', 'init');
|
2013-04-02 13:57:39 +13:00
|
|
|
|
2024-08-13 17:16:48 +02:00
|
|
|
// Trigger event, badge listing viewed.
|
|
|
|
$eventparams = ['context' => $PAGE->context, 'other' => $eventotherparams];
|
|
|
|
$event = \core\event\badge_listing_viewed::create($eventparams);
|
|
|
|
$event->trigger();
|
|
|
|
|
2013-04-02 13:57:39 +13:00
|
|
|
echo $OUTPUT->footer();
|