MDL-69773 block_section_links: Add an option to display section name
[moodle.git] / badges / alignment.php
CommitLineData
d363a5c2
TT
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/**
e8bfd9b4 17 * List alignments, skills, or standards are targeted by a BadgeClass.
d363a5c2
TT
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 */
25require_once(__DIR__ . '/../config.php');
26require_once($CFG->libdir . '/badgeslib.php');
e8bfd9b4 27require_once($CFG->dirroot . '/badges/alignment_form.php');
d363a5c2
TT
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
34require_login();
35if (empty($CFG->enablebadges)) {
36 print_error('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));
41require_capability('moodle/badges:configuredetails', $context);
42
43if ($badge->type == BADGE_TYPE_COURSE) {
44 if (empty($CFG->badges_allowcoursebadges)) {
45 print_error('coursebadgesdisabled', 'badges');
46 }
47 require_login($badge->courseid);
48 $navurl = new moodle_url('/badges/index.php', array('type' => $badge->type, 'id' => $badge->courseid));
49 $PAGE->set_pagelayout('standard');
50 navigation_node::override_active_url($navurl);
51} else {
52 $PAGE->set_pagelayout('admin');
53 navigation_node::override_active_url($navurl, true);
54}
55
e8bfd9b4 56$currenturl = new moodle_url('/badges/alignment.php', array('id' => $badge->id));
d363a5c2
TT
57$PAGE->set_context($context);
58$PAGE->set_url($currenturl);
59$PAGE->set_heading($badge->name);
60$PAGE->set_title($badge->name);
61$PAGE->navbar->add($badge->name);
62
63$output = $PAGE->get_renderer('core', 'badges');
64$msg = optional_param('msg', '', PARAM_TEXT);
65$emsg = optional_param('emsg', '', PARAM_TEXT);
e8bfd9b4
DW
66$url = new moodle_url('/badges/alignment.php', array('id' => $badge->id, 'action' => $action, 'alignmentid' => $alignmentid));
67$mform = new alignment_form($url, array('badge' => $badge, 'action' => $action, 'alignmentid' => $alignmentid));
d363a5c2
TT
68if ($mform->is_cancelled()) {
69 redirect($currenturl);
70} else if ($mform->is_submitted() && $mform->is_validated() && ($data = $mform->get_data())) {
71 $alignment = new stdClass();
72 $alignment->badgeid = $badgeid;
73 $alignment->targetname = $data->targetname;
74 $alignment->targeturl = $data->targeturl;
75 $alignment->targetframework = $data->targetframework;
76 $alignment->targetcode = $data->targetcode;
77 $alignment->targetdescription = trim($data->targetdescription);
78 $badge->save_alignment($alignment, $alignmentid);
79 redirect($currenturl);
80}
81
82echo $OUTPUT->header();
83echo $OUTPUT->heading(print_badge_image($badge, $context, 'small') . ' ' . $badge->name);
84echo $output->print_badge_status_box($badge);
85$output->print_badge_tabs($badgeid, $context, 'alignment');
86if ($emsg !== '') {
87 echo $OUTPUT->notification($emsg);
88} else if ($msg !== '') {
89 echo $OUTPUT->notification(get_string($msg, 'badges'), 'notifysuccess');
90}
91echo $output->notification(get_string('notealignment', 'badges'), 'info');
92
93if ($alignmentid || $action == 'add' || $action == 'edit') {
94 $mform->display();
95} else if (empty($action)) {
96 if (!$badge->is_active() && !$badge->is_locked()) {
e8bfd9b4 97 $urlbutton = new moodle_url('/badges/alignment.php', array('id' => $badge->id, 'action' => 'add'));
d363a5c2
TT
98 echo $OUTPUT->box($OUTPUT->single_button($urlbutton, get_string('addalignment', 'badges')), 'clearfix mdl-align');
99 }
e8bfd9b4
DW
100 $alignments = $badge->get_alignments();
101 if (count($alignments) > 0) {
aae219ac 102 $renderrelated = new \core_badges\output\badge_alignments($alignments, $badgeid);
d363a5c2
TT
103 echo $output->render($renderrelated);
104 } else {
105 echo $output->notification(get_string('noalignment', 'badges'));
106 }
107}
108
109echo $OUTPUT->footer();