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 * Related badges information 19 * 20 * @package core 21 * @subpackage badges 22 * @copyright 2018 Tung Thai 23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later 24 * @author Tung Thai <Tung.ThaiDuc@nashtechglobal.com> 25 */ 26 27require_once(__DIR__ . '/../config.php'); 28require_once($CFG->libdir . '/badgeslib.php'); 29require_once($CFG->dirroot . '/badges/related_form.php'); 30 31$badgeid = required_param('id', PARAM_INT); 32$action = optional_param('action', null, PARAM_TEXT); 33$lang = current_language(); 34 35require_login(); 36 37if (empty($CFG->enablebadges)) { 38 print_error('badgesdisabled', 'badges'); 39} 40 41$badge = new badge($badgeid); 42$context = $badge->get_context(); 43$navurl = new moodle_url('/badges/index.php', array('type' => $badge->type)); 44require_capability('moodle/badges:configuredetails', $context); 45 46if ($badge->type == BADGE_TYPE_COURSE) { 47 if (empty($CFG->badges_allowcoursebadges)) { 48 print_error('coursebadgesdisabled', 'badges'); 49 } 50 require_login($badge->courseid); 51 $navurl = new moodle_url('/badges/index.php', array('type' => $badge->type, 'id' => $badge->courseid)); 52 $PAGE->set_pagelayout('standard'); 53 navigation_node::override_active_url($navurl); 54} else { 55 $PAGE->set_pagelayout('admin'); 56 navigation_node::override_active_url($navurl, true); 57} 58 59$currenturl = new moodle_url('/badges/related.php', array('id' => $badge->id)); 60$PAGE->set_context($context); 61$PAGE->set_url($currenturl); 62$PAGE->set_heading($badge->name); 63$PAGE->set_title($badge->name); 64$PAGE->navbar->add($badge->name); 65$output = $PAGE->get_renderer('core', 'badges'); 66$msg = optional_param('msg', '', PARAM_TEXT); 67$emsg = optional_param('emsg', '', PARAM_TEXT); 68$url = new moodle_url('/badges/related.php', array('id' => $badge->id, 'action' => 'add')); 69 70$mform = new edit_relatedbadge_form($url, array('badge' => $badge)); 71if ($mform->is_cancelled()) { 72 redirect($currenturl); 73} else if ($mform->is_submitted() && $mform->is_validated() && ($data = $mform->get_data())) { 74 75 if (isset($data->relatedbadgeids)) { 76 $badge->add_related_badges($data->relatedbadgeids); 77 } 78 redirect($currenturl); 79} 80echo $OUTPUT->header(); 81echo $OUTPUT->heading(print_badge_image($badge, $context, 'small') . ' ' . $badge->name); 82echo $output->print_badge_status_box($badge); 83 84$output->print_badge_tabs($badgeid, $context, 'brelated'); 85if ($emsg !== '') { 86 echo $OUTPUT->notification($emsg); 87} else if ($msg !== '') { 88 echo $OUTPUT->notification(get_string($msg, 'badges'), 'notifysuccess'); 89} 90 91echo $output->notification(get_string('noterelated', 'badges'), 'info'); 92if (is_null($action)) { 93 if (!$badge->is_active() && !$badge->is_locked()) { 94 echo $OUTPUT->box($OUTPUT->single_button($url, get_string('addrelated', 'badges')), 'clearfix mdl-align'); 95 } 96 if ($badge->has_related()) { 97 $badgerelated = $badge->get_related_badges(); 98 $renderrelated = new \core_badges\output\badge_related($badgerelated, $badgeid); 99 echo $output->render($renderrelated); 100 } else { 101 echo $output->notification(get_string('norelated', 'badges')); 102 } 103} else if ($action == 'add') { 104 $mform->display(); 105} 106echo $OUTPUT->footer(); 107