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 |
* Serve endorsement JSON for assertion.
|
|
|
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 |
define('AJAX_SCRIPT', true);
|
|
|
26 |
define('NO_MOODLE_COOKIES', true); // No need for a session here.
|
|
|
27 |
require_once(__DIR__ . '/../config.php');
|
|
|
28 |
require_once($CFG->libdir . '/badgeslib.php');
|
|
|
29 |
|
|
|
30 |
if (empty($CFG->enablebadges)) {
|
|
|
31 |
throw new \moodle_exception('badgesdisabled', 'badges');
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
global $DB;
|
|
|
35 |
$id = required_param('id', PARAM_INT);
|
|
|
36 |
$action = optional_param('action', null, PARAM_BOOL); // Generates endorsement issuer class if true.
|
|
|
37 |
$badge = new badge($id);
|
|
|
38 |
|
|
|
39 |
$json = array();
|
|
|
40 |
$endorsement = $badge->get_endorsement();
|
|
|
41 |
$endorsementurl = new moodle_url('/badges/endorsement_json.php', array('id' => $id));
|
|
|
42 |
|
|
|
43 |
if ($endorsement) {
|
|
|
44 |
$issuer = array();
|
|
|
45 |
$issuerurl = new moodle_url('/badges/endorsement_json.php', array('id' => $id, 'action' => 1));
|
|
|
46 |
$issuer['id'] = $issuerurl->out(false);
|
|
|
47 |
$issuer['name'] = $endorsement->issuername;
|
|
|
48 |
$issuer['email'] = $endorsement->issueremail;
|
|
|
49 |
$issuer['url'] = $endorsement->issuerurl;
|
|
|
50 |
if ($action) {
|
|
|
51 |
$json = $issuer;
|
|
|
52 |
} else {
|
|
|
53 |
$json['@context'] = OPEN_BADGES_V2_CONTEXT;
|
|
|
54 |
$json['type'] = OPEN_BADGES_V2_TYPE_ENDORSEMENT;
|
|
|
55 |
$json['id'] = $endorsementurl->out(false);
|
|
|
56 |
$json['issuer'] = $issuer;
|
|
|
57 |
if (!empty($endorsement->claimcomment)) {
|
|
|
58 |
$json['claim']['id'] = $endorsement->claimid;
|
|
|
59 |
$json['claim']['endorsementComment'] = $endorsement->claimcomment;
|
|
|
60 |
} else {
|
|
|
61 |
$json['claim'] = $endorsement->claimid;
|
|
|
62 |
}
|
|
|
63 |
$json['issuedOn'] = date('c', $endorsement->dateissued);
|
|
|
64 |
$json['verification'] = array('type' => 'hosted');
|
|
|
65 |
}
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
echo $OUTPUT->header();
|
|
|
69 |
echo json_encode($json);
|