| 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 |  * 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 |   | 
        
           |  |  | 27 | require_once(__DIR__ . '/../config.php');
 | 
        
           |  |  | 28 | require_once($CFG->libdir . '/badgeslib.php');
 | 
        
           |  |  | 29 | require_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 |   | 
        
           |  |  | 35 | require_login();
 | 
        
           |  |  | 36 |   | 
        
           |  |  | 37 | if (empty($CFG->enablebadges)) {
 | 
        
           |  |  | 38 |     throw new \moodle_exception('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));
 | 
        
           |  |  | 44 | require_capability('moodle/badges:configuredetails', $context);
 | 
        
           |  |  | 45 |   | 
        
           |  |  | 46 | if ($badge->type == BADGE_TYPE_COURSE) {
 | 
        
           |  |  | 47 |     if (empty($CFG->badges_allowcoursebadges)) {
 | 
        
           |  |  | 48 |         throw new \moodle_exception('coursebadgesdisabled', 'badges');
 | 
        
           |  |  | 49 |     }
 | 
        
           |  |  | 50 |     require_login($badge->courseid);
 | 
        
           |  |  | 51 |     $course = get_course($badge->courseid);
 | 
        
           |  |  | 52 |     $heading = format_string($course->fullname, true, ['context' => $context]);
 | 
        
           |  |  | 53 |   | 
        
           |  |  | 54 |     $navurl = new moodle_url('/badges/index.php', array('type' => $badge->type, 'id' => $badge->courseid));
 | 
        
           |  |  | 55 |     $PAGE->set_pagelayout('standard');
 | 
        
           |  |  | 56 |     navigation_node::override_active_url($navurl);
 | 
        
           |  |  | 57 | } else {
 | 
        
           |  |  | 58 |     $PAGE->set_pagelayout('admin');
 | 
        
           |  |  | 59 |     $heading = get_string('administrationsite');
 | 
        
           |  |  | 60 |     navigation_node::override_active_url($navurl, true);
 | 
        
           |  |  | 61 | }
 | 
        
           |  |  | 62 |   | 
        
           |  |  | 63 | $currenturl = new moodle_url('/badges/related.php', array('id' => $badge->id));
 | 
        
           |  |  | 64 | $PAGE->set_context($context);
 | 
        
           |  |  | 65 | $PAGE->set_url($currenturl);
 | 
        
           |  |  | 66 | $PAGE->set_heading($heading);
 | 
        
           |  |  | 67 | $PAGE->set_title($badge->name);
 | 
        
           |  |  | 68 | $PAGE->navbar->add($badge->name);
 | 
        
           |  |  | 69 | $output = $PAGE->get_renderer('core', 'badges');
 | 
        
           |  |  | 70 | $msg = optional_param('msg', '', PARAM_TEXT);
 | 
        
           |  |  | 71 | $emsg = optional_param('emsg', '', PARAM_TEXT);
 | 
        
           |  |  | 72 | $url = new moodle_url('/badges/related.php', array('id' => $badge->id, 'action' => 'add'));
 | 
        
           |  |  | 73 |   | 
        
           |  |  | 74 | $mform = new edit_relatedbadge_form($url, array('badge' => $badge));
 | 
        
           |  |  | 75 | if ($mform->is_cancelled()) {
 | 
        
           |  |  | 76 |     redirect($currenturl);
 | 
        
           |  |  | 77 | } else if ($mform->is_submitted() && $mform->is_validated() && ($data = $mform->get_data())) {
 | 
        
           |  |  | 78 |   | 
        
           |  |  | 79 |     if (isset($data->relatedbadgeids)) {
 | 
        
           |  |  | 80 |         $badge->add_related_badges($data->relatedbadgeids);
 | 
        
           |  |  | 81 |     }
 | 
        
           |  |  | 82 |     redirect($currenturl);
 | 
        
           |  |  | 83 | }
 | 
        
           |  |  | 84 | echo $OUTPUT->header();
 | 
        
           |  |  | 85 |   | 
        
           |  |  | 86 | $actionbar = new \core_badges\output\manage_badge_action_bar($badge, $PAGE);
 | 
        
           |  |  | 87 | echo $output->render_tertiary_navigation($actionbar);
 | 
        
           |  |  | 88 |   | 
        
           |  |  | 89 | echo $OUTPUT->heading(print_badge_image($badge, $context, 'small') . ' ' . $badge->name);
 | 
        
           |  |  | 90 | echo $output->print_badge_status_box($badge);
 | 
        
           |  |  | 91 |   | 
        
           |  |  | 92 | if ($emsg !== '') {
 | 
        
           |  |  | 93 |     echo $OUTPUT->notification($emsg);
 | 
        
           |  |  | 94 | } else if ($msg !== '') {
 | 
        
           |  |  | 95 |     echo $OUTPUT->notification(get_string($msg, 'badges'), 'notifysuccess');
 | 
        
           |  |  | 96 | }
 | 
        
           |  |  | 97 |   | 
        
           |  |  | 98 | echo $output->notification(get_string('noterelated', 'badges'), 'info');
 | 
        
           |  |  | 99 | if (is_null($action)) {
 | 
        
           |  |  | 100 |     if (!$badge->is_active() && !$badge->is_locked()) {
 | 
        
           |  |  | 101 |         echo $OUTPUT->box($OUTPUT->single_button($url, get_string('addrelated', 'badges')), 'clearfix mdl-align');
 | 
        
           |  |  | 102 |     }
 | 
        
           |  |  | 103 |     if ($badge->has_related()) {
 | 
        
           |  |  | 104 |         $badgerelated = $badge->get_related_badges();
 | 
        
           |  |  | 105 |         $renderrelated = new \core_badges\output\badge_related($badgerelated, $badgeid);
 | 
        
           |  |  | 106 |         echo $output->render($renderrelated);
 | 
        
           |  |  | 107 |     } else {
 | 
        
           |  |  | 108 |         echo $output->notification(get_string('norelated', 'badges'));
 | 
        
           |  |  | 109 |     }
 | 
        
           |  |  | 110 | } else if ($action == 'add') {
 | 
        
           |  |  | 111 |     $mform->display();
 | 
        
           |  |  | 112 | }
 | 
        
           |  |  | 113 | echo $OUTPUT->footer();
 |