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
 * Statement object (activity, user or group) for xAPI structure checking and usage.
19
 *
20
 * @package    core_xapi
21
 * @copyright  2020 Ferran Recio
22
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
namespace core_xapi\local\statement;
26
 
27
use core_xapi\xapi_exception;
28
use core_xapi\iri;
29
use stdClass;
30
 
31
defined('MOODLE_INTERNAL') || die();
32
 
33
/**
34
 * Abstract object item used in xAPI statements.
35
 *
36
 * Object represents the object in which a xAPI verb is applied. There
37
 * are 3 types of objects supported: agent (user), group (of users) and
38
 * activity (defined by every plugin).
39
 *
40
 * @copyright  2020 Ferran Recio
41
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
42
 */
43
abstract class item_object extends item {
44
 
45
    /**
46
     * Create a xAPI object compatible from data (Agent, Group or Activity).
47
     *
48
     * @param stdClass $data data structure from statement object
49
     * @return item item_group|item_agent|item_activity resulting object
50
     */
51
    public static function create_from_data(stdClass $data): item {
52
        if (!isset($data->objectType)) {
53
            $data->objectType = 'Activity';
54
        }
55
        switch ($data->objectType) {
56
            case 'Agent':
57
                return item_agent::create_from_data($data);
58
                break;
59
            case 'Group':
60
                return item_group::create_from_data($data);
61
                break;
62
            case 'Activity':
63
                return item_activity::create_from_data($data);
64
                break;
65
            default:
66
                throw new xapi_exception("Unknown Object type '{$data->objectType}'");
67
        }
68
    }
69
}