Proyectos de Subversion Moodle

Rev

Rev 1 | | Comparar con el anterior | 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.
19
 *
20
 * @package   core_calendar
21
 * @copyright 2017 Ryan Wyllie <ryan@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
require_once($CFG->dirroot . "/calendar/lib.php");
30
 
1441 ariadna 31
use core_calendar\local\event\container;
32
use core_calendar\output\humantimeperiod;
33
use renderer_base;
34
use core\url;
1 efrain 35
 
36
/**
37
 * Class for displaying a calendar event.
38
 *
39
 * @package   core_calendar
40
 * @copyright 2017 Ryan Wyllie <ryan@moodle.com>
41
 * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
42
 */
43
class event_exporter extends event_exporter_base {
44
 
45
    /**
46
     * Return the list of additional properties.
47
     *
48
     * @return array
49
     */
50
    protected static function define_other_properties() {
51
        $values = parent::define_other_properties();
52
 
53
        $values['url'] = ['type' => PARAM_URL];
54
        return $values;
55
    }
56
 
57
    /**
58
     * Get the additional values to inject while exporting.
59
     *
60
     * @param renderer_base $output The renderer.
61
     * @return array Keys are the property names, values are their values.
62
     */
63
    protected function get_other_values(renderer_base $output) {
64
        $values = parent::get_other_values($output);
65
 
66
        global $CFG;
67
        require_once($CFG->dirroot.'/course/lib.php');
68
 
69
        $event = $this->event;
70
        $context = $this->related['context'];
71
        if ($moduleproxy = $event->get_course_module()) {
72
            $modulename = $moduleproxy->get('modname');
73
            $moduleid = $moduleproxy->get('id');
1441 ariadna 74
            $url = new url(sprintf('/mod/%s/view.php', $modulename), ['id' => $moduleid]);
1 efrain 75
 
76
            // Build edit event url for action events.
77
            $params = array('update' => $moduleid, 'return' => true, 'sesskey' => sesskey());
1441 ariadna 78
            $editurl = new url('/course/mod.php', $params);
1 efrain 79
            $values['editurl'] = $editurl->out(false);
80
        } else if ($event->get_type() == 'category') {
81
            $url = $event->get_category()->get_proxied_instance()->get_view_link();
82
        } else if ($event->get_type() == 'course') {
83
            $url = \course_get_url($this->related['course'] ?: SITEID);
84
        } else {
85
            $url = \course_get_url($this->related['course'] ?: SITEID);
86
        }
87
        $values['url'] = $url->out(false);
88
 
89
        // Override default formatted time to make sure the date portion of the time is always rendered.
90
        $legacyevent = container::get_event_mapper()->from_event_to_legacy_event($event);
1441 ariadna 91
        $humanperiod = humantimeperiod::create_from_timestamp(
92
            starttimestamp: $legacyevent->timestart,
93
            endtimestamp: $legacyevent->timestart + $legacyevent->timeduration,
94
            link: new url(CALENDAR_URL . 'view.php'),
95
        );
96
        $values['formattedtime'] = $output->render($humanperiod);
1 efrain 97
 
98
        return $values;
99
    }
100
}