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