Proyectos de Subversion Moodle

Rev

| 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
 * List alignments, skills, or standards are targeted by a BadgeClass.
18
 *
19
 * @package    core
20
 * @subpackage badges
21
 * @copyright  2018 Tung Thai
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 * @author     Tung Thai <Tung.ThaiDuc@nashtechglobal.com>
24
 */
25
require_once(__DIR__ . '/../config.php');
26
require_once($CFG->libdir . '/badgeslib.php');
27
require_once($CFG->dirroot . '/badges/alignment_form.php');
28
 
29
$badgeid = required_param('id', PARAM_INT);
30
$alignmentid = optional_param('alignmentid', 0, PARAM_INT);
31
$action = optional_param('action', '', PARAM_TEXT);
32
$lang = current_language();
33
 
34
require_login();
35
if (empty($CFG->enablebadges)) {
36
    throw new \moodle_exception('badgesdisabled', 'badges');
37
}
38
$badge = new badge($badgeid);
39
$context = $badge->get_context();
40
$navurl = new moodle_url('/badges/index.php', array('type' => $badge->type));
41
require_capability('moodle/badges:configuredetails', $context);
42
 
43
if ($badge->type == BADGE_TYPE_COURSE) {
44
    if (empty($CFG->badges_allowcoursebadges)) {
45
        throw new \moodle_exception('coursebadgesdisabled', 'badges');
46
    }
47
    require_login($badge->courseid);
48
    $course = get_course($badge->courseid);
49
    $heading = format_string($course->fullname, true, ['context' => $context]);
50
    $navurl = new moodle_url('/badges/index.php', array('type' => $badge->type, 'id' => $badge->courseid));
51
    $PAGE->set_pagelayout('standard');
52
    navigation_node::override_active_url($navurl);
53
} else {
54
    $PAGE->set_pagelayout('admin');
55
    $heading = get_string('administrationsite');
56
    navigation_node::override_active_url($navurl, true);
57
}
58
 
59
$currenturl = new moodle_url('/badges/alignment.php', array('id' => $badge->id));
60
$PAGE->set_context($context);
61
$PAGE->set_url($currenturl);
62
$PAGE->set_heading($heading);
63
$PAGE->set_title($badge->name);
64
$PAGE->navbar->add($badge->name);
65
 
66
$output = $PAGE->get_renderer('core', 'badges');
67
$msg = optional_param('msg', '', PARAM_TEXT);
68
$emsg = optional_param('emsg', '', PARAM_TEXT);
69
$url = new moodle_url('/badges/alignment.php', array('id' => $badge->id, 'action' => $action, 'alignmentid' => $alignmentid));
70
$mform = new alignment_form($url, array('badge' => $badge, 'action' => $action, 'alignmentid' => $alignmentid));
71
if ($mform->is_cancelled()) {
72
    redirect($currenturl);
73
} else if ($mform->is_submitted() && $mform->is_validated() && ($data = $mform->get_data())) {
74
    $alignment = new stdClass();
75
    $alignment->badgeid = $badgeid;
76
    $alignment->targetname = $data->targetname;
77
    $alignment->targeturl = $data->targeturl;
78
    $alignment->targetframework = $data->targetframework;
79
    $alignment->targetcode = $data->targetcode;
80
    $alignment->targetdescription = trim($data->targetdescription);
81
    $badge->save_alignment($alignment, $alignmentid);
82
    redirect($currenturl);
83
}
84
 
85
echo $OUTPUT->header();
86
$actionbar = new \core_badges\output\manage_badge_action_bar($badge, $PAGE);
87
echo $output->render_tertiary_navigation($actionbar);
88
echo $OUTPUT->heading(print_badge_image($badge, $context, 'small') . ' ' . $badge->name);
89
echo $output->print_badge_status_box($badge);
90
if ($emsg !== '') {
91
    echo $OUTPUT->notification($emsg);
92
} else if ($msg !== '') {
93
    echo $OUTPUT->notification(get_string($msg, 'badges'), 'notifysuccess');
94
}
95
echo $output->notification(get_string('notealignment', 'badges'), 'info');
96
 
97
if ($alignmentid || $action == 'add' || $action == 'edit') {
98
    $mform->display();
99
} else if (empty($action)) {
100
    if (!$badge->is_active() && !$badge->is_locked()) {
101
        $urlbutton = new moodle_url('/badges/alignment.php', array('id' => $badge->id, 'action' => 'add'));
102
        echo $OUTPUT->box($OUTPUT->single_button($urlbutton, get_string('addalignment', 'badges')), 'clearfix mdl-align');
103
    }
104
    $alignments = $badge->get_alignments();
105
    if (count($alignments) > 0) {
106
        $renderrelated = new \core_badges\output\badge_alignments($alignments, $badgeid);
107
        echo $output->render($renderrelated);
108
    } else {
109
        echo $output->notification(get_string('noalignment', 'badges'));
110
    }
111
}
112
 
113
echo $OUTPUT->footer();