2 // This file is part of Moodle - http://moodle.org/
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.
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/>.
18 * Contains class for displaying a assertion.
20 * @package core_badges
21 * @copyright 2019 Damyon Wiese
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 namespace core_badges\external
;
27 defined('MOODLE_INTERNAL') ||
die();
29 use core\external\exporter
;
34 * Class for displaying a badge competency.
36 * @package core_badges
37 * @copyright 2019 Damyon Wiese
38 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
40 class assertion_exporter
extends exporter
{
43 * Map from a request response data to the internal structure.
45 * @param stdClass $data The remote data.
46 * @param string $apiversion The backpack version used to communicate remotely.
49 public static function map_external_data($data, $apiversion) {
50 $mapped = new \
stdClass();
51 if (isset($data->entityType
)) {
52 $mapped->type
= $data->entityType
;
54 $mapped->type
= $data->type
;
56 if (isset($data->entityId
)) {
57 $mapped->id
= $data->entityId
;
59 $mapped->id
= $data->id
;
61 if (isset($data->issuedOn
)) {
62 $mapped->issuedOn
= $data->issuedOn
;
64 if (isset($data->recipient
)) {
65 $mapped->recipient
= $data->recipient
;
67 if (isset($data->badgeclass
)) {
68 $mapped->badgeclass
= $data->badgeclass
;
70 $propname = '@context';
71 $mapped->$propname = 'https://w3id.org/openbadges/v2';
76 * Return the list of additional properties.
80 protected static function define_other_properties() {
83 'type' => badgeclass_exporter
::read_properties_definition(),
87 'type' => recipient_exporter
::read_properties_definition(),
90 'verification' => array(
91 'type' => verification_exporter
::read_properties_definition(),
98 * We map from related data passed as data to this exporter to clean exportable values.
100 * @param renderer_base $output
103 protected function get_other_values(renderer_base
$output) {
107 if (array_key_exists('related_badge', $this->data
)) {
108 $exporter = new badgeclass_exporter($this->data
['related_badge'], $this->related
);
109 $result['badge'] = $exporter->export($output);
111 if (array_key_exists('related_recipient', $this->data
)) {
112 $exporter = new recipient_exporter($this->data
['related_recipient'], $this->related
);
113 $result['recipient'] = $exporter->export($output);
115 if (array_key_exists('related_verify', $this->data
)) {
116 $exporter = new verification_exporter($this->data
['related_verify'], $this->related
);
117 $result['verification'] = $exporter->export($output);
123 * Return the list of properties.
127 protected static function define_properties() {
130 'type' => PARAM_ALPHA
,
131 'description' => 'Issuer',
135 'description' => 'Unique identifier for this assertion',
139 'description' => 'Identifier of the badge for this assertion',
144 'description' => 'Date this badge was issued',
148 'description' => 'Date this badge will expire',
153 'description' => 'Badge version',
159 * Returns a list of objects that are related.
163 protected static function define_related() {
165 'context' => 'context'