Merge branch 'MDL-75910-39' of https://github.com/andrewnicols/moodle into MOODLE_39_...
[moodle.git] / badges / alignment.php
blobcf5b4336582bba718527ab8646ed46f0d925ed7e
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.
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.
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>
25 require_once(__DIR__ . '/../config.php');
26 require_once($CFG->libdir . '/badgeslib.php');
27 require_once($CFG->dirroot . '/badges/alignment_form.php');
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();
34 require_login();
35 if (empty($CFG->enablebadges)) {
36 print_error('badgesdisabled', 'badges');
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);
43 if ($badge->type == BADGE_TYPE_COURSE) {
44 if (empty($CFG->badges_allowcoursebadges)) {
45 print_error('coursebadgesdisabled', 'badges');
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);
56 $currenturl = new moodle_url('/badges/alignment.php', array('id' => $badge->id));
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);
63 $output = $PAGE->get_renderer('core', 'badges');
64 $msg = optional_param('msg', '', PARAM_TEXT);
65 $emsg = optional_param('emsg', '', PARAM_TEXT);
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));
68 if ($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);
82 echo $OUTPUT->header();
83 echo $OUTPUT->heading(print_badge_image($badge, $context, 'small') . ' ' . $badge->name);
84 echo $output->print_badge_status_box($badge);
85 $output->print_badge_tabs($badgeid, $context, 'alignment');
86 if ($emsg !== '') {
87 echo $OUTPUT->notification($emsg);
88 } else if ($msg !== '') {
89 echo $OUTPUT->notification(get_string($msg, 'badges'), 'notifysuccess');
91 echo $output->notification(get_string('notealignment', 'badges'), 'info');
93 if ($alignmentid || $action == 'add' || $action == 'edit') {
94 $mform->display();
95 } else if (empty($action)) {
96 if (!$badge->is_active() && !$badge->is_locked()) {
97 $urlbutton = new moodle_url('/badges/alignment.php', array('id' => $badge->id, 'action' => 'add'));
98 echo $OUTPUT->box($OUTPUT->single_button($urlbutton, get_string('addalignment', 'badges')), 'clearfix mdl-align');
100 $alignments = $badge->get_alignments();
101 if (count($alignments) > 0) {
102 $renderrelated = new \core_badges\output\badge_alignments($alignments, $badgeid);
103 echo $output->render($renderrelated);
104 } else {
105 echo $output->notification(get_string('noalignment', 'badges'));
109 echo $OUTPUT->footer();