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/>.
1441 ariadna 16
 
1 efrain 17
/**
18
 * Endorsement 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
 */
1441 ariadna 26
 
27
use core_badges\form\endorsement;
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
 
34
require_login();
35
 
36
if (empty($CFG->enablebadges)) {
37
    throw new \moodle_exception('badgesdisabled', 'badges');
38
}
39
 
40
$badge = new badge($badgeid);
41
$context = $badge->get_context();
1441 ariadna 42
$title = [get_string('bendorsement', 'badges'), $badge->name];
43
$navurl = new moodle_url('/badges/index.php', ['type' => $badge->type]);
1 efrain 44
require_capability('moodle/badges:configuredetails', $context);
45
 
46
if ($badge->type == BADGE_TYPE_COURSE) {
47
    if (empty($CFG->badges_allowcoursebadges)) {
48
        throw new \moodle_exception('coursebadgesdisabled', 'badges');
49
    }
50
    require_login($badge->courseid);
51
    $course = get_course($badge->courseid);
52
    $heading = format_string($course->fullname, true, ['context' => $context]);
1441 ariadna 53
    $title[] = $heading;
54
    $navurl = new moodle_url('/badges/index.php', ['type' => $badge->type, 'id' => $badge->courseid]);
1 efrain 55
    $PAGE->set_pagelayout('standard');
56
    navigation_node::override_active_url($navurl);
57
} else {
58
    $PAGE->set_pagelayout('admin');
59
    $heading = get_string('administrationsite');
60
    navigation_node::override_active_url($navurl, true);
61
}
62
 
1441 ariadna 63
$currenturl = new moodle_url('/badges/endorsement.php', ['id' => $badgeid]);
1 efrain 64
$PAGE->set_context($context);
65
$PAGE->set_url($currenturl);
66
$PAGE->set_heading($heading);
1441 ariadna 67
$PAGE->set_title(implode(\moodle_page::TITLE_SEPARATOR, $title));
1 efrain 68
$PAGE->navbar->add($badge->name);
69
 
70
$output = $PAGE->get_renderer('core', 'badges');
71
$msg = optional_param('msg', '', PARAM_TEXT);
72
$emsg = optional_param('emsg', '', PARAM_TEXT);
73
 
74
if ($msg !== '') {
75
    $msg = get_string($msg, 'badges');
76
}
77
 
78
echo $OUTPUT->header();
79
 
80
$actionbar = new \core_badges\output\manage_badge_action_bar($badge, $PAGE);
81
echo $output->render_tertiary_navigation($actionbar);
82
 
83
echo $OUTPUT->heading(print_badge_image($badge, $context, 'small') . ' ' . $badge->name);
84
echo $output->print_badge_status_box($badge);
85
 
1441 ariadna 86
$form = new endorsement($currenturl, ['badge' => $badge]);
1 efrain 87
if ($form->is_cancelled()) {
1441 ariadna 88
    redirect(new moodle_url('/badges/overview.php', ['id' => $badgeid]));
1 efrain 89
} else if ($form->is_submitted() && $form->is_validated() && ($data = $form->get_data())) {
90
    $endorsement = new stdClass();
91
    $endorsement->badgeid = $badgeid;
92
    $endorsement->issuername = $data->issuername;
93
    $endorsement->issueremail = $data->issueremail;
94
    $endorsement->issuerurl = $data->issuerurl;
95
    $endorsement->claimid = $data->claimid;
96
    $endorsement->claimcomment = strip_tags($data->claimcomment);
97
    $endorsement->dateissued = $data->dateissued;
98
 
99
    if ($badge->save_endorsement($endorsement)) {
100
        $msg = get_string('changessaved');
101
    } else {
102
        $emsg = get_string('error:save', 'badges');
103
    }
104
}
105
 
106
if ($emsg !== '') {
107
    echo $OUTPUT->notification($emsg);
108
 
109
} else if ($msg !== '') {
110
    echo $OUTPUT->notification($msg, 'notifysuccess');
111
}
112
echo $output->notification(get_string('noteendorsement', 'badges'), 'info');
113
$form->display();
114
echo $OUTPUT->footer();