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 |
namespace core_calendar\external;
|
|
|
18 |
|
|
|
19 |
use core\external\exporter;
|
|
|
20 |
use renderer_base;
|
|
|
21 |
use stdClass;
|
|
|
22 |
use moodle_url;
|
|
|
23 |
|
|
|
24 |
/**
|
|
|
25 |
* Class for exporting calendar footer view options data.
|
|
|
26 |
*
|
|
|
27 |
* @package core_calendar
|
|
|
28 |
* @copyright 2017 Simey Lameze
|
|
|
29 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
30 |
*/
|
|
|
31 |
class footer_options_exporter extends exporter {
|
|
|
32 |
|
|
|
33 |
/**
|
|
|
34 |
* @var \calendar_information $calendar The calendar to be rendered.
|
|
|
35 |
*/
|
|
|
36 |
protected $calendar;
|
|
|
37 |
|
|
|
38 |
/**
|
|
|
39 |
* @var int $userid The user id.
|
|
|
40 |
*/
|
|
|
41 |
protected $userid;
|
|
|
42 |
|
|
|
43 |
/**
|
|
|
44 |
* @var string $token The user sha1 token.
|
|
|
45 |
*/
|
|
|
46 |
protected $token;
|
|
|
47 |
|
|
|
48 |
/**
|
|
|
49 |
* @var bool $showfullcalendarlink Whether the full calendar link should be displayed or not.
|
|
|
50 |
*/
|
|
|
51 |
protected $showfullcalendarlink;
|
|
|
52 |
|
|
|
53 |
/**
|
|
|
54 |
* Constructor for month_exporter.
|
|
|
55 |
*
|
|
|
56 |
* @param \calendar_information $calendar The calendar being represented
|
|
|
57 |
* @param int $userid The user id
|
|
|
58 |
* @param string $token The user sha1 token.
|
|
|
59 |
* @param array $options Display options for the footer. If an option is not set, a default value will be provided.
|
|
|
60 |
* It consists of:
|
|
|
61 |
* - showfullcalendarlink - bool - Whether to show the full calendar link or not. Defaults to false.
|
|
|
62 |
*/
|
|
|
63 |
public function __construct(\calendar_information $calendar, $userid, $token, array $options = []) {
|
|
|
64 |
$this->calendar = $calendar;
|
|
|
65 |
$this->userid = $userid;
|
|
|
66 |
$this->token = $token;
|
|
|
67 |
$this->showfullcalendarlink = $options['showfullcalendarlink'] ?? false;
|
|
|
68 |
}
|
|
|
69 |
|
|
|
70 |
/**
|
|
|
71 |
* Get manage subscription link.
|
|
|
72 |
*
|
|
|
73 |
* @return string|null The manage subscription hyperlink.
|
|
|
74 |
*/
|
|
|
75 |
protected function get_manage_subscriptions_link(): ?string {
|
|
|
76 |
if (calendar_user_can_add_event($this->calendar->course)) {
|
|
|
77 |
$managesubscriptionurl = new moodle_url('/calendar/managesubscriptions.php');
|
|
|
78 |
return $managesubscriptionurl->out(true);
|
|
|
79 |
}
|
|
|
80 |
return null;
|
|
|
81 |
}
|
|
|
82 |
|
|
|
83 |
/**
|
|
|
84 |
* Get the additional values to inject while exporting.
|
|
|
85 |
*
|
|
|
86 |
* @param renderer_base $output The renderer.
|
|
|
87 |
* @return array Keys are the property names, values are their values.
|
|
|
88 |
*/
|
|
|
89 |
protected function get_other_values(renderer_base $output) {
|
|
|
90 |
global $CFG;
|
|
|
91 |
|
|
|
92 |
$values = new stdClass();
|
|
|
93 |
$values->footerlinks = [];
|
|
|
94 |
|
|
|
95 |
if ($this->showfullcalendarlink) {
|
|
|
96 |
if ($this->calendar->courseid !== SITEID) {
|
|
|
97 |
$linkname = get_string('coursecalendarlink', 'calendar');
|
|
|
98 |
} else {
|
|
|
99 |
$linkname = get_string('fullcalendar', 'calendar');
|
|
|
100 |
}
|
|
|
101 |
$values->footerlinks[] = (object)[
|
|
|
102 |
'url' => $this->get_calendar_url(),
|
|
|
103 |
'linkname' => $linkname,
|
|
|
104 |
];
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
if (!empty($CFG->enablecalendarexport) && $managesubscriptionlink = $this->get_manage_subscriptions_link()) {
|
|
|
108 |
$values->footerlinks[] = (object)[
|
|
|
109 |
'url' => $managesubscriptionlink,
|
|
|
110 |
'linkname' => get_string('managesubscriptions', 'calendar'),
|
|
|
111 |
];
|
|
|
112 |
}
|
|
|
113 |
|
|
|
114 |
return (array) $values;
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
/**
|
|
|
118 |
* Return the list of additional properties.
|
|
|
119 |
*
|
|
|
120 |
* @return array
|
|
|
121 |
*/
|
|
|
122 |
public static function define_other_properties() {
|
|
|
123 |
return [
|
|
|
124 |
'footerlinks' => [
|
|
|
125 |
'type' => [
|
|
|
126 |
'url' => [
|
|
|
127 |
'type' => PARAM_URL,
|
|
|
128 |
],
|
|
|
129 |
'linkname' => [
|
|
|
130 |
'type' => PARAM_TEXT,
|
|
|
131 |
],
|
|
|
132 |
],
|
|
|
133 |
'multiple' => true,
|
|
|
134 |
'optional' => true,
|
|
|
135 |
],
|
|
|
136 |
];
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
/**
|
|
|
140 |
* Build the calendar URL.
|
|
|
141 |
*
|
|
|
142 |
* @return string The calendar URL.
|
|
|
143 |
*/
|
|
|
144 |
public function get_calendar_url() {
|
|
|
145 |
$url = new moodle_url('/calendar/view.php', [
|
|
|
146 |
'view' => 'month',
|
|
|
147 |
'time' => $this->calendar->time,
|
|
|
148 |
'course' => $this->calendar->courseid,
|
|
|
149 |
]);
|
|
|
150 |
|
|
|
151 |
return $url->out(false);
|
|
|
152 |
}
|
|
|
153 |
}
|