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
 * Contains the import_strategy_link class.
18
 *
19
 * @package tool_moodlenet
20
 * @copyright 2020 Jake Dallimore <jrhdallimore@gmail.com>
21
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
22
 */
23
namespace tool_moodlenet\local;
24
 
25
/**
26
 * The import_strategy_link class.
27
 *
28
 * The import_strategy_link objects contains the setup steps needed to prepare a resource for import as a URL into Moodle.
29
 *
30
 * @copyright 2020 Jake Dallimore <jrhdallimore@gmail.com>
31
 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
32
 */
33
class import_strategy_link implements import_strategy {
34
 
35
    /**
36
     * Get an array of import_handler_info objects representing modules supporting import of the resource.
37
     *
38
     * @param array $registrydata the fully populated registry.
39
     * @param remote_resource $resource the remote resource.
40
     * @return import_handler_info[] the array of import_handler_info objects.
41
     */
42
    public function get_handlers(array $registrydata, remote_resource $resource): array {
43
        $handlers = [];
44
        foreach ($registrydata['types'] as $identifier => $items) {
45
            foreach ($items as $item) {
46
                if ($identifier === 'url') {
47
                    $handlers[] = new import_handler_info($item['module'], $item['message'], $this);
48
                }
49
            }
50
        }
51
        return $handlers;
52
    }
53
 
54
    /**
55
     * Import the remote resource according to the rules of this strategy.
56
     *
57
     * @param remote_resource $resource the resource to import.
58
     * @param \stdClass $user the user to import on behalf of.
59
     * @param \stdClass $course the course into which the remote_resource is being imported.
60
     * @param int $section the section into which the remote_resource is being imported.
61
     * @return \stdClass the module data.
62
     */
63
    public function import(remote_resource $resource, \stdClass $user, \stdClass $course, int $section): \stdClass {
64
        $data = new \stdClass();
65
        $data->type = 'url';
66
        $data->course = $course;
67
        $data->content = $resource->get_url()->get_value();
68
        $data->displayname = $resource->get_name();
69
        return $data;
70
    }
71
}