Proyectos de Subversion Moodle

Rev

| 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/>.
16
 
17
/**
18
 * Contains class for displaying a issuer.
19
 *
20
 * @package   core_badges
21
 * @copyright 2019 Damyon Wiese
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
namespace core_badges\external;
26
 
27
defined('MOODLE_INTERNAL') || die();
28
 
29
use core\external\exporter;
30
 
31
/**
32
 * Class for displaying a badge competency.
33
 *
34
 * @package   core_badges
35
 * @copyright 2019 Damyon Wiese
36
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
37
 */
38
class issuer_exporter extends exporter {
39
 
40
    /**
41
     * Either map version 1 data to version 2 or return it untouched.
42
     *
43
     * @param stdClass $data The remote data.
44
     * @param string $apiversion The backpack version used to communicate remotely.
45
     * @return stdClass
46
     */
47
    public static function map_external_data($data, $apiversion) {
48
        if ($apiversion == OPEN_BADGES_V1) {
49
            $result = new \stdClass();
50
            return $result;
51
        }
52
        $mapped = new \stdClass();
53
        if (isset($data->entityType)) {
54
            $mapped->type = $data->entityType;
55
        } else {
56
            $mapped->type = $data->type;
57
        }
58
        if (isset($data->entityId)) {
59
            $mapped->id = $data->entityId;
60
        } else {
61
            $mapped->id = $data->id;
62
        }
63
        $mapped->name = $data->name;
64
        $mapped->email = $data->email;
65
        $mapped->url = $data->url;
66
        return $mapped;
67
    }
68
 
69
    /**
70
     * Return the list of properties.
71
     *
72
     * @return array
73
     */
74
    protected static function define_properties() {
75
        return [
76
            'type' => [
77
                'type' => PARAM_ALPHA,
78
                'description' => 'Issuer',
79
            ],
80
            'id' => [
81
                'type' => PARAM_RAW,
82
                'description' => 'Unique identifier for this issuer',
83
            ],
84
            'name' => [
85
                'type' => PARAM_TEXT,
86
                'description' => 'Name of the issuer',
87
            ],
88
            'email' => [
89
                'type' => PARAM_EMAIL,
90
                'description' => 'Email of the issuer',
91
            ],
92
            'url' => [
93
                'type' => PARAM_URL,
94
                'description' => 'URL for this issuer',
95
            ],
96
        ];
97
    }
98
 
99
    /**
100
     * Returns a list of objects that are related.
101
     *
102
     * @return array
103
     */
104
    protected static function define_related() {
105
        return array(
106
            'context' => 'context',
107
        );
108
    }
109
}