| 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/>.
 | 
        
           | 1441 | ariadna | 16 |   | 
        
           | 1 | efrain | 17 | /**
 | 
        
           |  |  | 18 |  * List alignments, skills, or standards are targeted by a BadgeClass.
 | 
        
           |  |  | 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 |  */
 | 
        
           | 1441 | ariadna | 26 |   | 
        
           |  |  | 27 | use core_badges\form\alignment;
 | 
        
           |  |  | 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 | $alignmentid = optional_param('alignmentid', 0, PARAM_INT);
 | 
        
           |  |  | 34 | $action = optional_param('action', '', PARAM_TEXT);
 | 
        
           |  |  | 35 | $lang = current_language();
 | 
        
           |  |  | 36 |   | 
        
           |  |  | 37 | require_login();
 | 
        
           |  |  | 38 | if (empty($CFG->enablebadges)) {
 | 
        
           |  |  | 39 |     throw new \moodle_exception('badgesdisabled', 'badges');
 | 
        
           |  |  | 40 | }
 | 
        
           |  |  | 41 | $badge = new badge($badgeid);
 | 
        
           |  |  | 42 | $context = $badge->get_context();
 | 
        
           | 1441 | ariadna | 43 | $title = [get_string('alignment', 'badges'), $badge->name];
 | 
        
           |  |  | 44 | $navurl = new moodle_url('/badges/index.php', ['type' => $badge->type]);
 | 
        
           | 1 | efrain | 45 | require_capability('moodle/badges:configuredetails', $context);
 | 
        
           |  |  | 46 |   | 
        
           |  |  | 47 | if ($badge->type == BADGE_TYPE_COURSE) {
 | 
        
           |  |  | 48 |     if (empty($CFG->badges_allowcoursebadges)) {
 | 
        
           |  |  | 49 |         throw new \moodle_exception('coursebadgesdisabled', 'badges');
 | 
        
           |  |  | 50 |     }
 | 
        
           |  |  | 51 |     require_login($badge->courseid);
 | 
        
           |  |  | 52 |     $course = get_course($badge->courseid);
 | 
        
           |  |  | 53 |     $heading = format_string($course->fullname, true, ['context' => $context]);
 | 
        
           | 1441 | ariadna | 54 |     $title[] = $heading;
 | 
        
           |  |  | 55 |     $navurl = new moodle_url('/badges/index.php', ['type' => $badge->type, 'id' => $badge->courseid]);
 | 
        
           | 1 | efrain | 56 |     $PAGE->set_pagelayout('standard');
 | 
        
           |  |  | 57 |     navigation_node::override_active_url($navurl);
 | 
        
           |  |  | 58 | } else {
 | 
        
           |  |  | 59 |     $PAGE->set_pagelayout('admin');
 | 
        
           |  |  | 60 |     $heading = get_string('administrationsite');
 | 
        
           |  |  | 61 |     navigation_node::override_active_url($navurl, true);
 | 
        
           |  |  | 62 | }
 | 
        
           |  |  | 63 |   | 
        
           | 1441 | ariadna | 64 | $currenturl = new moodle_url('/badges/alignment.php', ['id' => $badge->id]);
 | 
        
           | 1 | efrain | 65 | $PAGE->set_context($context);
 | 
        
           |  |  | 66 | $PAGE->set_url($currenturl);
 | 
        
           |  |  | 67 | $PAGE->set_heading($heading);
 | 
        
           | 1441 | ariadna | 68 | $PAGE->set_title(implode(\moodle_page::TITLE_SEPARATOR, $title));
 | 
        
           | 1 | efrain | 69 | $PAGE->navbar->add($badge->name);
 | 
        
           |  |  | 70 |   | 
        
           |  |  | 71 | $output = $PAGE->get_renderer('core', 'badges');
 | 
        
           |  |  | 72 | $msg = optional_param('msg', '', PARAM_TEXT);
 | 
        
           |  |  | 73 | $emsg = optional_param('emsg', '', PARAM_TEXT);
 | 
        
           | 1441 | ariadna | 74 | $url = new moodle_url('/badges/alignment.php', ['id' => $badge->id, 'action' => $action, 'alignmentid' => $alignmentid]);
 | 
        
           |  |  | 75 | $mform = new alignment($url, ['badge' => $badge, 'action' => $action, 'alignmentid' => $alignmentid]);
 | 
        
           | 1 | efrain | 76 | if ($mform->is_cancelled()) {
 | 
        
           |  |  | 77 |     redirect($currenturl);
 | 
        
           |  |  | 78 | } else if ($mform->is_submitted() && $mform->is_validated() && ($data = $mform->get_data())) {
 | 
        
           |  |  | 79 |     $alignment = new stdClass();
 | 
        
           |  |  | 80 |     $alignment->badgeid = $badgeid;
 | 
        
           |  |  | 81 |     $alignment->targetname = $data->targetname;
 | 
        
           |  |  | 82 |     $alignment->targeturl = $data->targeturl;
 | 
        
           |  |  | 83 |     $alignment->targetframework = $data->targetframework;
 | 
        
           |  |  | 84 |     $alignment->targetcode = $data->targetcode;
 | 
        
           |  |  | 85 |     $alignment->targetdescription = trim($data->targetdescription);
 | 
        
           |  |  | 86 |     $badge->save_alignment($alignment, $alignmentid);
 | 
        
           |  |  | 87 |     redirect($currenturl);
 | 
        
           |  |  | 88 | }
 | 
        
           |  |  | 89 |   | 
        
           |  |  | 90 | echo $OUTPUT->header();
 | 
        
           |  |  | 91 | $actionbar = new \core_badges\output\manage_badge_action_bar($badge, $PAGE);
 | 
        
           |  |  | 92 | echo $output->render_tertiary_navigation($actionbar);
 | 
        
           |  |  | 93 | echo $OUTPUT->heading(print_badge_image($badge, $context, 'small') . ' ' . $badge->name);
 | 
        
           |  |  | 94 | echo $output->print_badge_status_box($badge);
 | 
        
           |  |  | 95 | if ($emsg !== '') {
 | 
        
           |  |  | 96 |     echo $OUTPUT->notification($emsg);
 | 
        
           |  |  | 97 | } else if ($msg !== '') {
 | 
        
           |  |  | 98 |     echo $OUTPUT->notification(get_string($msg, 'badges'), 'notifysuccess');
 | 
        
           |  |  | 99 | }
 | 
        
           |  |  | 100 | echo $output->notification(get_string('notealignment', 'badges'), 'info');
 | 
        
           |  |  | 101 |   | 
        
           |  |  | 102 | if ($alignmentid || $action == 'add' || $action == 'edit') {
 | 
        
           |  |  | 103 |     $mform->display();
 | 
        
           |  |  | 104 | } else if (empty($action)) {
 | 
        
           |  |  | 105 |     if (!$badge->is_active() && !$badge->is_locked()) {
 | 
        
           | 1441 | ariadna | 106 |         $urlbutton = new moodle_url('/badges/alignment.php', ['id' => $badge->id, 'action' => 'add']);
 | 
        
           | 1 | efrain | 107 |         echo $OUTPUT->box($OUTPUT->single_button($urlbutton, get_string('addalignment', 'badges')), 'clearfix mdl-align');
 | 
        
           |  |  | 108 |     }
 | 
        
           |  |  | 109 |     $alignments = $badge->get_alignments();
 | 
        
           |  |  | 110 |     if (count($alignments) > 0) {
 | 
        
           |  |  | 111 |         $renderrelated = new \core_badges\output\badge_alignments($alignments, $badgeid);
 | 
        
           |  |  | 112 |         echo $output->render($renderrelated);
 | 
        
           |  |  | 113 |     } else {
 | 
        
           |  |  | 114 |         echo $output->notification(get_string('noalignment', 'badges'));
 | 
        
           |  |  | 115 |     }
 | 
        
           |  |  | 116 | }
 | 
        
           |  |  | 117 |   | 
        
           |  |  | 118 | echo $OUTPUT->footer();
 |