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 event class for displaying a calendar event's subscription.
19
 *
20
 * @package   core_calendar
21
 * @copyright 2017 Simey Lameze <simey@moodle.com>
22
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23
 */
24
 
25
namespace core_calendar\external;
26
 
27
defined('MOODLE_INTERNAL') || die();
28
 
29
use \core\external\exporter;
30
use \core_calendar\local\event\entities\event_interface;
31
 
32
/**
33
 * Class for displaying a calendar event's subscription.
34
 *
35
 * @package   core_calendar
36
 * @copyright 2017 Simey Lameze <simey@moodle.com>
37
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38
 */
39
class event_subscription_exporter extends exporter {
40
 
41
    /**
42
     * Constructor.
43
     *
44
     * @param event_interface $event
45
     */
46
    public function __construct(event_interface $event) {
47
        global $CFG;
48
 
49
        $data = new \stdClass();
50
        $data->displayeventsource = false;
51
        if ($event->get_subscription()) {
52
            $subscription = calendar_get_subscription($event->get_subscription()->get('id'));
53
            if (!empty($subscription) && $CFG->calendar_showicalsource) {
54
                $data->displayeventsource = true;
55
                if (!empty($subscription->url)) {
56
                    $data->subscriptionurl = $subscription->url;
57
                }
58
                $data->subscriptionname = $subscription->name;
59
            }
60
        }
61
 
62
        parent::__construct($data);
63
    }
64
 
65
    /**
66
     * Return the list of properties.
67
     *
68
     * @return array
69
     */
70
    protected static function define_properties() {
71
        return [
72
            'displayeventsource' => [
73
                'type' => PARAM_BOOL
74
            ],
75
            'subscriptionname' => [
76
                'type' => PARAM_RAW,
77
                'optional' => true
78
            ],
79
            'subscriptionurl' => [
80
                'type' => PARAM_URL,
81
                'optional' => true
82
            ],
83
        ];
84
    }
85
}