Merge branch 'MDL-59388-master' of git://github.com/lameze/moodle

This commit is contained in:
Jun Pataleta 2017-08-16 10:12:51 +08:00
commit a88a63e694
36 changed files with 1869 additions and 470 deletions

View File

@ -1 +1 @@
define(["jquery","core/ajax","core/str","core/templates","core/notification","core/custom_interaction_events","core/modal_events","core/modal_factory","core_calendar/modal_event_form","core_calendar/summary_modal","core_calendar/repository","core_calendar/events"],function(a,b,c,d,e,f,g,h,i,j,k,l){var m={ROOT:"[data-region='calendar']",EVENT_LINK:"[data-action='view-event']",NEW_EVENT_BUTTON:"[data-action='new-event-button']"},n=function(a){var b="type"+a;return c.get_string(b,"core_calendar").then(function(a){return a})},o=function(a){return c.get_string("subsource","core_calendar",a).then(function(b){return a.url?'<a href="'+a.url+'">'+b+"</a>":b})},p=function(b){k.getEventById(b).then(function(c){if(!c.event)throw new Error("Error encountered while trying to fetch calendar event with ID: "+b);var d=c.event,e=n(d.eventtype);if(d.displayeventsource){d.subscription=JSON.parse(d.subscription);var f={url:d.subscription.url,name:d.subscription.name},g=o(f);return a.when(e,g).then(function(a,b){return d.eventtype=a,d.source=b,d})}return e.then(function(a){return d.eventtype=a,d})}).then(function(a){var b={title:a.name,type:j.TYPE,body:d.render("core_calendar/event_summary_body",a),templateContext:{canedit:a.canedit,candelete:a.candelete}};return h.create(b)}).done(function(a){a.getRoot().on(g.hidden,function(){a.destroy()}),a.show()}).fail(e.exception)},q=function(a){var b=a.find(m.NEW_EVENT_BUTTON),c=b.attr("data-context-id");return h.create({type:i.TYPE,large:!0,templateContext:{contextid:c}},b)},r=function(b,c){var d=a("body");d.on(l.created,function(){window.location.reload()}),d.on(l.deleted,function(){window.location.reload()}),d.on(l.updated,function(){window.location.reload()}),d.on(l.editActionEvent,function(a,b){window.location.assign(b)}),c.then(function(a){d.on(l.editEvent,function(b,c){a.setEventId(c),a.show()})})},s=function(){var b=a(m.ROOT);a(m.EVENT_LINK).click(function(b){b.preventDefault();var c=a(this).attr("data-event-id");p(c)});var c=q(b);r(b,c)};return{init:function(){s()}}});
define(["jquery","core/ajax","core/str","core/templates","core/notification","core/custom_interaction_events","core/modal_events","core/modal_factory","core_calendar/modal_event_form","core_calendar/summary_modal","core_calendar/repository","core_calendar/events","core_calendar/view_manager"],function(a,b,c,d,e,f,g,h,i,j,k,l,m){var n={ROOT:"[data-region='calendar']",EVENT_LINK:"[data-action='view-event']",NEW_EVENT_BUTTON:"[data-action='new-event-button']"},o=function(a){var b="type"+a;return c.get_string(b,"core_calendar").then(function(a){return a})},p=function(a){return c.get_string("subsource","core_calendar",a).then(function(b){return a.url?'<a href="'+a.url+'">'+b+"</a>":b})},q=function(b){k.getEventById(b).then(function(c){if(!c.event)throw new Error("Error encountered while trying to fetch calendar event with ID: "+b);var d=c.event,e=o(d.eventtype);if(d.displayeventsource){d.subscription=JSON.parse(d.subscription);var f={url:d.subscription.url,name:d.subscription.name},g=p(f);return a.when(e,g).then(function(a,b){return d.eventtype=a,d.source=b,d})}return e.then(function(a){return d.eventtype=a,d})}).then(function(a){var b={title:a.name,type:j.TYPE,body:d.render("core_calendar/event_summary_body",a),templateContext:{canedit:a.canedit,candelete:a.candelete}};return h.create(b)}).done(function(a){a.getRoot().on(g.hidden,function(){a.destroy()}),a.show()}).fail(e.exception)},r=function(a){var b=a.find(n.NEW_EVENT_BUTTON),c=b.attr("data-context-id");return h.create({type:i.TYPE,large:!0,templateContext:{contextid:c}},[a,n.NEW_EVENT_BUTTON])},s=function(b,c){var d=a("body");d.on(l.created,function(){window.location.reload()}),d.on(l.deleted,function(){window.location.reload()}),d.on(l.updated,function(){window.location.reload()}),d.on(l.editActionEvent,function(a,b){window.location.assign(b)}),c.then(function(a){d.on(l.editEvent,function(b,c){a.setEventId(c),a.show()})})},t=function(){var b=a(n.ROOT);b.on("click",n.EVENT_LINK,function(b){b.preventDefault();var c=a(this).attr("data-event-id");q(c)});var c=r(b);s(b,c)};return{init:function(){m.init(),t()}}});

View File

@ -1 +1 @@
define([],function(){return{created:"calendar-events:created",deleted:"calendar-events:deleted",updated:"calendar-events:updated",editEvent:"calendar-events:edit_event",editActionEvent:"calendar-events:edit_action_event"}});
define([],function(){return{created:"calendar-events:created",deleted:"calendar-events:deleted",updated:"calendar-events:updated",editEvent:"calendar-events:edit_event",editActionEvent:"calendar-events:edit_action_event",monthChanged:"calendar-events:month_changed"}});

View File

@ -1 +1 @@
define(["jquery","core/ajax"],function(a,b){var c=function(a){var c={methodname:"core_calendar_delete_calendar_events",args:{events:[{eventid:a,repeat:1}]}};return b.call([c])[0]},d=function(a){var c={methodname:"core_calendar_get_calendar_event_by_id",args:{eventid:a}};return b.call([c])[0]},e=function(a){var c={methodname:"core_calendar_submit_create_update_form",args:{formdata:a}};return b.call([c])[0]};return{getEventById:d,deleteEvent:c,submitCreateUpdateForm:e}});
define(["jquery","core/ajax"],function(a,b){var c=function(a){var c={methodname:"core_calendar_delete_calendar_events",args:{events:[{eventid:a,repeat:1}]}};return b.call([c])[0]},d=function(a){var c={methodname:"core_calendar_get_calendar_event_by_id",args:{eventid:a}};return b.call([c])[0]},e=function(a){var c={methodname:"core_calendar_submit_create_update_form",args:{formdata:a}};return b.call([c])[0]},f=function(a,c){var d={methodname:"core_calendar_get_calendar_monthly_view",args:{time:a,courseid:c}};return b.call([d])[0]};return{getEventById:d,deleteEvent:c,submitCreateUpdateForm:e,getCalendarMonthData:f}});

View File

@ -0,0 +1 @@
define(["jquery","core/templates","core/notification","core_calendar/repository","core_calendar/events"],function(a,b,c,d,e){var f={ROOT:"[data-region='calendar']",CALENDAR_NAV_LINK:"span.calendarwrapper .arrow_link",CALENDAR_MONTH_WRAPPER:".calendarwrapper"},g=function(b){b=a(b),b.on("click",f.CALENDAR_NAV_LINK,function(c){var d=a(b).find(f.CALENDAR_MONTH_WRAPPER).data("courseid"),e=a(c.currentTarget);h(e.attr("href"),e.data("time"),d),c.preventDefault()})},h=function(g,h,i){d.getCalendarMonthData(h,i).then(function(a){return window.history.pushState({},"",g),b.render("core_calendar/month_detailed",a)}).then(function(a,c){return b.replaceNodeContents(f.CALENDAR_MONTH_WRAPPER,a,c)}).done(function(){a("body").trigger(e.monthChanged,[h,i])}).fail(c.exception)};return{init:function(){g(f.ROOT)}}});

View File

@ -37,7 +37,8 @@ define([
'core_calendar/modal_event_form',
'core_calendar/summary_modal',
'core_calendar/repository',
'core_calendar/events'
'core_calendar/events',
'core_calendar/view_manager'
],
function(
$,
@ -51,7 +52,8 @@ define([
ModalEventForm,
SummaryModal,
CalendarRepository,
CalendarEvents
CalendarEvents,
CalendarViewManager
) {
var SELECTORS = {
@ -173,7 +175,7 @@ define([
contextid: contextId
}
},
newEventButton
[root, SELECTORS.NEW_EVENT_BUTTON]
);
};
@ -222,7 +224,7 @@ define([
var root = $(SELECTORS.ROOT);
// Bind click events to event links.
$(SELECTORS.EVENT_LINK).click(function(e) {
root.on('click', SELECTORS.EVENT_LINK, function(e) {
e.preventDefault();
var eventId = $(this).attr('data-event-id');
renderEventSummaryModal(eventId);
@ -234,6 +236,7 @@ define([
return {
init: function() {
CalendarViewManager.init();
registerEventListeners();
}
};

View File

@ -249,7 +249,7 @@ define(['jquery', 'core/templates'], function($, Templates) {
};
/**
* Initialise all of the form enhancementds.
* Initialise all of the form enhancements.
*
* @method init
* @param {string} formId The value of the form's id attribute

View File

@ -28,6 +28,7 @@ define([], function() {
deleted: 'calendar-events:deleted',
updated: 'calendar-events:updated',
editEvent: 'calendar-events:edit_event',
editActionEvent: 'calendar-events:edit_action_event'
editActionEvent: 'calendar-events:edit_action_event',
monthChanged: 'calendar-events:month_changed'
};
});

View File

@ -83,9 +83,30 @@ define(['jquery', 'core/ajax'], function($, Ajax) {
return Ajax.call([request])[0];
};
/**
* Get calendar data for the month view.
*
* @method getCalendarMonthData
* @param {Number} time Timestamp.
* @param {Number} courseid The course id.
* @return {promise} Resolved with the month view data.
*/
var getCalendarMonthData = function(time, courseid) {
var request = {
methodname: 'core_calendar_get_calendar_monthly_view',
args: {
time: time,
courseid: courseid
}
};
return Ajax.call([request])[0];
};
return {
getEventById: getEventById,
deleteEvent: deleteEvent,
submitCreateUpdateForm: submitCreateUpdateForm
submitCreateUpdateForm: submitCreateUpdateForm,
getCalendarMonthData: getCalendarMonthData
};
});

View File

@ -0,0 +1,77 @@
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* A javascript module to handler calendar view changes.
*
* @module core_calendar/view_manager
* @package core_calendar
* @copyright 2017 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
define(['jquery', 'core/templates', 'core/notification', 'core_calendar/repository', 'core_calendar/events'],
function($, Templates, Notification, CalendarRepository, CalendarEvents) {
var SELECTORS = {
ROOT: "[data-region='calendar']",
CALENDAR_NAV_LINK: "span.calendarwrapper .arrow_link",
CALENDAR_MONTH_WRAPPER: ".calendarwrapper",
};
/**
* Register event listeners for the module.
*
* @param {object} root The root element.
*/
var registerEventListeners = function(root) {
root = $(root);
root.on('click', SELECTORS.CALENDAR_NAV_LINK, function(e) {
var courseId = $(root).find(SELECTORS.CALENDAR_MONTH_WRAPPER).data('courseid');
var link = $(e.currentTarget);
changeMonth(link.attr('href'), link.data('time'), courseId);
e.preventDefault();
});
};
/**
* Handle changes to the current calendar view.
*
* @param {String} url The calendar url to be shown
* @param {Number} time The calendar time to be shown
* @param {Number} courseid The id of the course whose events are shown
*/
var changeMonth = function(url, time, courseid) {
CalendarRepository.getCalendarMonthData(time, courseid)
.then(function(context) {
window.history.pushState({}, '', url);
return Templates.render('core_calendar/month_detailed', context);
})
.then(function(html, js) {
return Templates.replaceNodeContents(SELECTORS.CALENDAR_MONTH_WRAPPER, html, js);
})
.done(function() {
$('body').trigger(CalendarEvents.monthChanged, [time, courseid]);
})
.fail(Notification.exception);
};
return {
init: function() {
registerEventListeners(SELECTORS.ROOT);
}
};
});

View File

@ -0,0 +1,87 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Contains event class for displaying a calendar event.
*
* @package core_calendar
* @copyright 2017 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_calendar\external;
defined('MOODLE_INTERNAL') || die();
use \core_course\external\course_summary_exporter;
use \renderer_base;
/**
* Class for displaying a calendar event.
*
* @package core_calendar
* @copyright 2017 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class calendar_event_exporter extends event_exporter_base {
/**
* Return the list of additional properties.
*
* @return array
*/
protected static function define_other_properties() {
return [
'url' => ['type' => PARAM_URL],
'icon' => [
'type' => event_icon_exporter::read_properties_definition(),
],
'course' => [
'type' => course_summary_exporter::read_properties_definition(),
'optional' => true,
]
];
}
/**
* Get the additional values to inject while exporting.
*
* @param renderer_base $output The renderer.
* @return array Keys are the property names, values are their values.
*/
protected function get_other_values(renderer_base $output) {
$values = parent::get_other_values($output);
$eventid = $this->event->get_id();
$url = new \moodle_url($this->related['daylink'], [], "event_{$eventid}");
$values['url'] = $url->out(false);
return $values;
}
/**
* Returns a list of objects that are related.
*
* @return array
*/
protected static function define_related() {
$related = parent::define_related();
$related['daylink'] = \moodle_url::class;
return $related;
}
}

View File

@ -0,0 +1,149 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Contains event class for displaying the day view.
*
* @package core_calendar
* @copyright 2017 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_calendar\external;
defined('MOODLE_INTERNAL') || die();
use core\external\exporter;
use renderer_base;
use moodle_url;
/**
* Class for displaying the day view.
*
* @package core_calendar
* @copyright 2017 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class day_exporter extends exporter {
/**
* Return the list of properties.
*
* @return array
*/
protected static function define_properties() {
// These are the default properties as returned by getuserdate()
// but without the formatted month and week names.
return [
'seconds' => [
'type' => PARAM_INT,
],
'minutes' => [
'type' => PARAM_INT,
],
'hours' => [
'type' => PARAM_INT,
],
'mday' => [
'type' => PARAM_INT,
],
'wday' => [
'type' => PARAM_INT,
],
'year' => [
'type' => PARAM_INT,
],
'yday' => [
'type' => PARAM_INT,
],
];
}
/**
* Return the list of additional properties.
*
* @return array
*/
protected static function define_other_properties() {
return [
'timestamp' => [
'type' => PARAM_INT,
],
'istoday' => [
'type' => PARAM_BOOL,
'default' => false,
],
'isweekend' => [
'type' => PARAM_BOOL,
'default' => false,
],
'viewdaylink' => [
'type' => PARAM_URL,
'optional' => true,
],
'events' => [
'type' => calendar_event_exporter::read_properties_definition(),
'multiple' => true,
]
];
}
/**
* Get the additional values to inject while exporting.
*
* @param renderer_base $output The renderer.
* @return array Keys are the property names, values are their values.
*/
protected function get_other_values(renderer_base $output) {
$return = [
'timestamp' => $this->data[0],
];
$url = new moodle_url('/calendar/view.php', [
'view' => 'day',
'time' => $this->data[0],
]);
$return['viewdaylink'] = $url->out(false);
$cache = $this->related['cache'];
$return['events'] = array_map(function($event) use ($cache, $output, $url) {
$context = $cache->get_context($event);
$course = $cache->get_course($event);
$exporter = new calendar_event_exporter($event, [
'context' => $context,
'course' => $course,
'daylink' => $url,
]);
return $exporter->export($output);
}, $this->related['events']);
return $return;
}
/**
* Returns a list of objects that are related.
*
* @return array
*/
protected static function define_related() {
return [
'events' => '\core_calendar\local\event\entities\event_interface[]',
'cache' => '\core_calendar\external\events_related_objects_cache',
'type' => '\core_calendar\type_base',
];
}
}

View File

@ -0,0 +1,87 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Contains event class for displaying the day name.
*
* @package core_calendar
* @copyright 2017 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_calendar\external;
defined('MOODLE_INTERNAL') || die();
use core\external\exporter;
/**
* Class for displaying the day view.
*
* @package core_calendar
* @copyright 2017 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class day_name_exporter extends exporter {
/**
* @var int $dayno The day number.
*/
protected $dayno;
/**
* @var string $shortname The formatted short name of the day.
*/
protected $shortname;
/**
* @var string $fullname The formatted full name of the day.
*/
protected $fullname;
/**
* Constructor.
*
* @param int $dayno The day number.
* @param array $names The list of names.
*/
public function __construct($dayno, $names) {
$data = $names + ['dayno' => $dayno];
parent::__construct($data, []);
}
/**
* Return the list of properties.
*
* @return array
*/
protected static function define_properties() {
return [
'dayno' => [
'type' => PARAM_INT,
],
'shortname' => [
// Note: The calendar type class has already formatted the names.
'type' => PARAM_RAW,
],
'fullname' => [
// Note: The calendar type class has already formatted the names.
'type' => PARAM_RAW,
],
];
}
}

View File

@ -28,8 +28,6 @@ defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot . "/calendar/lib.php");
use \core\external\exporter;
use \core_calendar\local\event\entities\event_interface;
use \core_calendar\local\event\entities\action_event_interface;
use \core_calendar\local\event\container;
use \core_course\external\course_summary_exporter;
@ -42,112 +40,7 @@ use \renderer_base;
* @copyright 2017 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class event_exporter extends exporter {
/**
* @var event_interface $event
*/
protected $event;
/**
* Constructor.
*
* @param event_interface $event
* @param array $related The related data.
*/
public function __construct(event_interface $event, $related = []) {
$this->event = $event;
$starttimestamp = $event->get_times()->get_start_time()->getTimestamp();
$endtimestamp = $event->get_times()->get_end_time()->getTimestamp();
$groupid = $event->get_group() ? $event->get_group()->get('id') : null;
$userid = $event->get_user() ? $event->get_user()->get('id') : null;
$data = new \stdClass();
$data->id = $event->get_id();
$data->name = $event->get_name();
$data->description = $event->get_description()->get_value();
$data->descriptionformat = $event->get_description()->get_format();
$data->groupid = $groupid;
$data->userid = $userid;
$data->eventtype = $event->get_type();
$data->timestart = $starttimestamp;
$data->timeduration = $endtimestamp - $starttimestamp;
$data->timesort = $event->get_times()->get_sort_time()->getTimestamp();
$data->visible = $event->is_visible() ? 1 : 0;
$data->timemodified = $event->get_times()->get_modified_time()->getTimestamp();
if ($repeats = $event->get_repeats()) {
$data->repeatid = $repeats->get_id();
}
if ($cm = $event->get_course_module()) {
$data->modulename = $cm->get('modname');
$data->instance = $cm->get('id');
}
parent::__construct($data, $related);
}
/**
* Return the list of properties.
*
* @return array
*/
protected static function define_properties() {
return [
'id' => ['type' => PARAM_INT],
'name' => ['type' => PARAM_TEXT],
'description' => [
'type' => PARAM_RAW,
'optional' => true,
'default' => null,
'null' => NULL_ALLOWED
],
'descriptionformat' => [
'type' => PARAM_INT,
'optional' => true,
'default' => null,
'null' => NULL_ALLOWED
],
'groupid' => [
'type' => PARAM_INT,
'optional' => true,
'default' => null,
'null' => NULL_ALLOWED
],
'userid' => [
'type' => PARAM_INT,
'optional' => true,
'default' => null,
'null' => NULL_ALLOWED
],
'repeatid' => [
'type' => PARAM_INT,
'optional' => true,
'default' => null,
'null' => NULL_ALLOWED
],
'modulename' => [
'type' => PARAM_TEXT,
'optional' => true,
'default' => null,
'null' => NULL_ALLOWED
],
'instance' => [
'type' => PARAM_INT,
'optional' => true,
'default' => null,
'null' => NULL_ALLOWED
],
'eventtype' => ['type' => PARAM_TEXT],
'timestart' => ['type' => PARAM_INT],
'timeduration' => ['type' => PARAM_INT],
'timesort' => ['type' => PARAM_INT],
'visible' => ['type' => PARAM_INT],
'timemodified' => ['type' => PARAM_INT],
];
}
class event_exporter extends event_exporter_base {
/**
* Return the list of additional properties.
@ -155,34 +48,26 @@ class event_exporter extends exporter {
* @return array
*/
protected static function define_other_properties() {
return [
'url' => ['type' => PARAM_URL],
'editurl' => [
'type' => PARAM_URL,
'optional' => true
],
'icon' => [
'type' => event_icon_exporter::read_properties_definition(),
],
'action' => [
'type' => event_action_exporter::read_properties_definition(),
'optional' => true,
],
'course' => [
'type' => course_summary_exporter::read_properties_definition(),
'optional' => true,
],
'canedit' => ['type' => PARAM_BOOL],
'displayeventsource' => ['type' => PARAM_BOOL],
'subscription' => [
'type' => PARAM_RAW,
'optional' => true,
'default' => null,
'null' => NULL_ALLOWED
],
'isactionevent' => ['type' => PARAM_BOOL],
'candelete' => ['type' => PARAM_BOOL]
$values = parent::define_other_properties();
$values['canedit'] = ['type' => PARAM_BOOL];
$values['displayeventsource'] = ['type' => PARAM_BOOL];
$values['subscription'] = [
'type' => PARAM_RAW,
'optional' => true,
'default' => null,
'null' => NULL_ALLOWED
];
$values['isactionevent'] = ['type' => PARAM_BOOL];
$values['candelete'] = ['type' => PARAM_BOOL];
$values['url'] = ['type' => PARAM_URL];
$values['action'] = [
'type' => event_action_exporter::read_properties_definition(),
'optional' => true,
];
return $values;
}
/**
@ -192,12 +77,14 @@ class event_exporter extends exporter {
* @return array Keys are the property names, values are their values.
*/
protected function get_other_values(renderer_base $output) {
$values = [];
$values = parent::get_other_values($output);
$event = $this->event;
$legacyevent = container::get_event_mapper()->from_event_to_legacy_event($event);
$context = $this->related['context'];
$values['isactionevent'] = false;
if ($moduleproxy = $event->get_course_module()) {
$modulename = $moduleproxy->get('modname');
$moduleid = $moduleproxy->get('id');
@ -215,11 +102,8 @@ class event_exporter extends exporter {
require_once($CFG->dirroot.'/course/lib.php');
$url = \course_get_url($this->related['course'] ?: SITEID);
}
$timesort = $event->get_times()->get_sort_time()->getTimestamp();
$iconexporter = new event_icon_exporter($event, ['context' => $context]);
$values['url'] = $url->out(false);
$values['icon'] = $iconexporter->export($output);
if ($event instanceof action_event_interface) {
$actionrelated = [
@ -253,18 +137,7 @@ class event_exporter extends exporter {
$values['subscription'] = json_encode($subscriptiondata);
}
}
return $values;
}
/**
* Returns a list of objects that are related.
*
* @return array
*/
protected static function define_related() {
return [
'context' => 'context',
'course' => 'stdClass?',
];
}
}

View File

@ -0,0 +1,225 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Contains event class for displaying a calendar event.
*
* @package core_calendar
* @copyright 2017 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_calendar\external;
defined('MOODLE_INTERNAL') || die();
use \core\external\exporter;
use \core_calendar\local\event\entities\event_interface;
use \core_calendar\local\event\entities\action_event_interface;
use \core_course\external\course_summary_exporter;
use \renderer_base;
/**
* Class for displaying a calendar event.
*
* @package core_calendar
* @copyright 2017 Ryan Wyllie <ryan@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class event_exporter_base extends exporter {
/**
* @var event_interface $event
*/
protected $event;
/**
* Constructor.
*
* @param event_interface $event
* @param array $related The related data.
*/
public function __construct(event_interface $event, $related = []) {
$this->event = $event;
$starttimestamp = $event->get_times()->get_start_time()->getTimestamp();
$endtimestamp = $event->get_times()->get_end_time()->getTimestamp();
$groupid = $event->get_group() ? $event->get_group()->get('id') : null;
$userid = $event->get_user() ? $event->get_user()->get('id') : null;
$data = new \stdClass();
$data->id = $event->get_id();
$data->name = $event->get_name();
$data->description = $event->get_description()->get_value();
$data->descriptionformat = $event->get_description()->get_format();
$data->groupid = $groupid;
$data->userid = $userid;
$data->eventtype = $event->get_type();
$data->timestart = $starttimestamp;
$data->timeduration = $endtimestamp - $starttimestamp;
$data->timesort = $event->get_times()->get_sort_time()->getTimestamp();
$data->visible = $event->is_visible() ? 1 : 0;
$data->timemodified = $event->get_times()->get_modified_time()->getTimestamp();
if ($repeats = $event->get_repeats()) {
$data->repeatid = $repeats->get_id();
}
if ($cm = $event->get_course_module()) {
$data->modulename = $cm->get('modname');
$data->instance = $cm->get('id');
}
parent::__construct($data, $related);
}
/**
* Return the list of properties.
*
* @return array
*/
protected static function define_properties() {
return [
'id' => ['type' => PARAM_INT],
'name' => ['type' => PARAM_TEXT],
'description' => [
'type' => PARAM_RAW,
'optional' => true,
'default' => null,
'null' => NULL_ALLOWED
],
'descriptionformat' => [
'type' => PARAM_INT,
'optional' => true,
'default' => null,
'null' => NULL_ALLOWED
],
'groupid' => [
'type' => PARAM_INT,
'optional' => true,
'default' => null,
'null' => NULL_ALLOWED
],
'userid' => [
'type' => PARAM_INT,
'optional' => true,
'default' => null,
'null' => NULL_ALLOWED
],
'repeatid' => [
'type' => PARAM_INT,
'optional' => true,
'default' => null,
'null' => NULL_ALLOWED
],
'modulename' => [
'type' => PARAM_TEXT,
'optional' => true,
'default' => null,
'null' => NULL_ALLOWED
],
'instance' => [
'type' => PARAM_INT,
'optional' => true,
'default' => null,
'null' => NULL_ALLOWED
],
'eventtype' => ['type' => PARAM_TEXT],
'timestart' => ['type' => PARAM_INT],
'timeduration' => ['type' => PARAM_INT],
'timesort' => ['type' => PARAM_INT],
'visible' => ['type' => PARAM_INT],
'timemodified' => ['type' => PARAM_INT],
];
}
/**
* Return the list of additional properties.
*
* @return array
*/
protected static function define_other_properties() {
return [
'url' => ['type' => PARAM_URL],
'icon' => [
'type' => event_icon_exporter::read_properties_definition(),
],
'action' => [
'type' => event_action_exporter::read_properties_definition(),
'optional' => true,
],
'course' => [
'type' => course_summary_exporter::read_properties_definition(),
'optional' => true,
]
];
}
/**
* Get the additional values to inject while exporting.
*
* @param renderer_base $output The renderer.
* @return array Keys are the property names, values are their values.
*/
protected function get_other_values(renderer_base $output) {
$values = [];
$event = $this->event;
$context = $this->related['context'];
if ($moduleproxy = $event->get_course_module()) {
$modulename = $moduleproxy->get('modname');
$moduleid = $moduleproxy->get('id');
$url = new \moodle_url(sprintf('/mod/%s/view.php', $modulename), ['id' => $moduleid]);
} else {
// TODO MDL-58866 We do not have any way to find urls for events outside of course modules.
global $CFG;
require_once($CFG->dirroot.'/course/lib.php');
$url = \course_get_url($this->related['course'] ?: SITEID);
}
$timesort = $event->get_times()->get_sort_time()->getTimestamp();
$iconexporter = new event_icon_exporter($event, ['context' => $context]);
$values['url'] = $url->out(false);
$values['icon'] = $iconexporter->export($output);
if ($event instanceof action_event_interface) {
$actionrelated = [
'context' => $context,
'event' => $event
];
$actionexporter = new event_action_exporter($event->get_action(), $actionrelated);
$values['action'] = $actionexporter->export($output);
}
if ($course = $this->related['course']) {
$coursesummaryexporter = new course_summary_exporter($course, ['context' => $context]);
$values['course'] = $coursesummaryexporter->export($output);
}
return $values;
}
/**
* Returns a list of objects that are related.
*
* @return array
*/
protected static function define_related() {
return [
'context' => 'context',
'course' => 'stdClass?',
];
}
}

View File

@ -0,0 +1,144 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Class for exporting calendar footer view options data.
*
* @package core_calendar
* @copyright 2017 Simey Lameze <simey@moodle.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_calendar\external;
defined('MOODLE_INTERNAL') || die();
use core\external\exporter;
use renderer_base;
use stdClass;
use moodle_url;
/**
* Class for exporting calendar footer view options data.
*
* @copyright 2017 Simey Lameze
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class footer_options_exporter extends exporter {
/**
* @var \calendar_information $calendar The calendar to be rendered.
*/
protected $calendar;
/**
* @var int $userid The user id.
*/
protected $userid;
/**
* @var string $token The user sha1 token.
*/
protected $token;
/**
* Constructor for month_exporter.
*
* @param \calendar_information $calendar The calendar being represented
* @param int $userid The user id
* @param string $token The user sha1 token.
*/
public function __construct(\calendar_information $calendar, $userid, $token) {
$this->calendar = $calendar;
$this->userid = $userid;
$this->token = $token;
}
/**
* Get the export calendar button.
*
* @return \single_button The export calendar button html.
*/
protected function get_export_calendar_button() {
$exportcalendarurl = new moodle_url('/calendar/export.php', ['course' => $this->calendar->course->id]);
return new \single_button($exportcalendarurl, get_string('exportcalendar', 'calendar'));
}
/**
* Get the iCal url.
*
* @return string The iCal url.
*/
protected function get_ical_url() {
return new moodle_url('/calendar/export_execute.php', ['preset_what' => 'all',
'preset_time' => 'recentupcoming', 'userid' => $this->userid, 'authtoken' => $this->token]);
}
/**
* Get manage subscription button.
*
* @return string The manage subscription button html.
*/
protected function get_manage_subscriptions_button() {
if (calendar_user_can_add_event($this->calendar->course)) {
$managesubscriptionurl = new moodle_url('/calendar/managesubscriptions.php',
['course' => $this->calendar->course->id]);
return new \single_button($managesubscriptionurl,
get_string('managesubscriptions', 'calendar'));
}
}
/**
* Get the additional values to inject while exporting.
*
* @param renderer_base $output The renderer.
* @return array Keys are the property names, values are their values.
*/
protected function get_other_values(renderer_base $output) {
global $CFG;
$values = new stdClass();
if (!empty($CFG->enablecalendarexport)) {
$exportbutton = $this->get_export_calendar_button();
$managesubscriptionbutton = $this->get_manage_subscriptions_button();
$values->exportcalendarbutton = $exportbutton->export_for_template($output);
$values->managesubscriptionbutton = $managesubscriptionbutton->export_for_template($output);
$values->icalurl = $this->get_ical_url()->out(false);
}
return (array) $values;
}
/**
* Return the list of additional properties.
*
* @return array
*/
public static function define_other_properties() {
return array(
'exportcalendarbutton' => [
'type' => PARAM_RAW,
],
'managesubscriptionbutton' => [
'type' => PARAM_RAW,
],
'icalurl' => [
'type' => PARAM_URL,
],
);
}
}

View File

@ -0,0 +1,283 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Contains event class for displaying the month view.
*
* @package core_calendar
* @copyright 2017 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_calendar\external;
defined('MOODLE_INTERNAL') || die();
use core\external\exporter;
use renderer_base;
use moodle_url;
/**
* Class for displaying the month view.
*
* @package core_calendar
* @copyright 2017 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class month_exporter extends exporter {
/**
* @var \calendar_information $calendar The calendar to be rendered.
*/
protected $calendar;
/**
* @var int $firstdayofweek The first day of the week.
*/
protected $firstdayofweek;
/**
* @var moodle_url $url The URL for the events page.
*/
protected $url;
/**
* Constructor for month_exporter.
*
* @param \calendar_information $calendar The calendar being represented
* @param \core_calendar\type_base $type The calendar type (e.g. Gregorian)
* @param array $related The related information
*/
public function __construct(\calendar_information $calendar, \core_calendar\type_base $type, $related) {
$this->calendar = $calendar;
$this->firstdayofweek = $type->get_starting_weekday();
$this->url = new moodle_url('/calendar/view.php', [
'view' => 'month',
'time' => $calendar->time,
]);
if ($this->calendar->courseid) {
$this->url->param('course', $this->calendar->courseid);
}
$related['type'] = $type;
parent::__construct([], $related);
}
/**
* Return the list of additional properties.
*
* @return array
*/
protected static function define_other_properties() {
return [
'courseid' => [
'type' => PARAM_INT,
],
'filter_selector' => [
'type' => PARAM_RAW,
],
'navigation' => [
'type' => PARAM_RAW,
],
'weeks' => [
'type' => week_exporter::read_properties_definition(),
'multiple' => true,
],
'daynames' => [
'type' => day_name_exporter::read_properties_definition(),
'multiple' => true,
],
'view' => [
'type' => PARAM_ALPHA,
],
'previousperiod' => [
'type' => PARAM_INT,
],
'nextperiod' => [
'type' => PARAM_INT,
],
];
}
/**
* Get the additional values to inject while exporting.
*
* @param renderer_base $output The renderer.
* @return array Keys are the property names, values are their values.
*/
protected function get_other_values(renderer_base $output) {
return [
'courseid' => $this->calendar->courseid,
'view' => 'month',
'previousperiod' => $this->get_previous_month_timestamp(),
'nextperiod' => $this->get_next_month_timestamp(),
'filter_selector' => $this->get_course_filter_selector($output),
'navigation' => $this->get_navigation($output),
'weeks' => $this->get_weeks($output),
'daynames' => $this->get_day_names($output),
];
}
/**
* Get the course filter selector.
*
* @param renderer_base $output
* @return string The html code for the course filter selector.
*/
protected function get_course_filter_selector(renderer_base $output) {
$content = '';
$content .= $output->course_filter_selector($this->url, get_string('detailedmonthviewfor', 'calendar'));
if (calendar_user_can_add_event($this->calendar->course)) {
$content .= $output->add_event_button($this->calendar->courseid, 0, 0, 0, $this->calendar->time);
}
return $content;
}
/**
* Get the calendar navigation controls.
*
* @param renderer_base $output
* @return string The html code to the calendar top navigation.
*/
protected function get_navigation(renderer_base $output) {
return calendar_top_controls('month', [
'id' => $this->calendar->courseid,
'time' => $this->calendar->time,
]);
}
/**
* Get the list of day names for display, re-ordered from the first day
* of the week.
*
* @param renderer_base $output
* @return day_name_exporter[]
*/
protected function get_day_names(renderer_base $output) {
$weekdays = $this->related['type']->get_weekdays();
$daysinweek = count($weekdays);
$daynames = [];
for ($i = 0; $i < $daysinweek; $i++) {
// Bump the currentdayno and ensure it loops.
$dayno = ($i + $this->firstdayofweek + $daysinweek) % $daysinweek;
$dayname = new day_name_exporter($dayno, $weekdays[$dayno]);
$daynames[] = $dayname->export($output);
}
return $daynames;
}
/**
* Get the list of week days, ordered into weeks and padded according
* to the value of the first day of the week.
*
* @param renderer_base $output
* @return array The list of weeks.
*/
protected function get_weeks(renderer_base $output) {
$weeks = [];
$alldays = $this->get_days();
$daysinweek = count($this->related['type']->get_weekdays());
// Calculate which day number is the first, and last day of the week.
$firstdayofweek = $this->firstdayofweek;
$lastdayofweek = ($firstdayofweek + $daysinweek - 1) % $daysinweek;
// The first week is special as it may have padding at the beginning.
$day = reset($alldays);
$firstdayno = $day['wday'];
$prepadding = ($firstdayno + $daysinweek - 1) % $daysinweek;
$daysinfirstweek = $daysinweek - $prepadding;
$days = array_slice($alldays, 0, $daysinfirstweek);
$week = new week_exporter($days, $prepadding, ($daysinweek - count($days) - $prepadding), $this->related);
$weeks[] = $week->export($output);
// Now chunk up the remaining day. and turn them into weeks.
$daychunks = array_chunk(array_slice($alldays, $daysinfirstweek), $daysinweek);
foreach ($daychunks as $days) {
$week = new week_exporter($days, 0, ($daysinweek - count($days)), $this->related);
$weeks[] = $week->export($output);
}
return $weeks;
}
/**
* Get the list of days with the matching date array.
*
* @return array
*/
protected function get_days() {
$date = $this->related['type']->timestamp_to_date_array($this->calendar->time);
$monthdays = $this->related['type']->get_num_days_in_month($date['year'], $date['mon']);
$days = [];
for ($dayno = 1; $dayno <= $monthdays; $dayno++) {
// Get the gregorian representation of the day.
$timestamp = $this->related['type']->convert_to_timestamp($date['year'], $date['mon'], $dayno);
$days[] = $this->related['type']->timestamp_to_date_array($timestamp);
}
return $days;
}
/**
* Returns a list of objects that are related.
*
* @return array
*/
protected static function define_related() {
return [
'events' => '\core_calendar\local\event\entities\event_interface[]',
'cache' => '\core_calendar\external\events_related_objects_cache',
'type' => '\core_calendar\type_base',
];
}
/**
* Get the previous month timestamp.
*
* @return int The previous month timestamp.
*/
protected function get_previous_month_timestamp() {
$date = $this->related['type']->timestamp_to_date_array($this->calendar->time);
$month = calendar_sub_month($date['mon'], $date['year']);
$monthtime = $this->related['type']->convert_to_gregorian($month[1], $month[0], 1);
return make_timestamp($monthtime['year'], $monthtime['month'], $monthtime['day'], $monthtime['hour'], $monthtime['minute']);
}
/**
* Get the next month timestamp.
*
* @return int The next month timestamp.
*/
protected function get_next_month_timestamp() {
$date = $this->related['type']->timestamp_to_date_array($this->calendar->time);
$month = calendar_sub_month($date['mon'], $date['year']);
$monthtime = $this->related['type']->convert_to_gregorian($month[1], $month[0], 1);
return make_timestamp($monthtime['year'], $monthtime['month'], $monthtime['day'], $monthtime['hour'], $monthtime['minute']);
}
}

View File

@ -0,0 +1,159 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Contains event class for displaying the week view.
*
* @package core_calendar
* @copyright 2017 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace core_calendar\external;
defined('MOODLE_INTERNAL') || die();
use core\external\exporter;
use renderer_base;
/**
* Class for displaying the week view.
*
* @package core_calendar
* @copyright 2017 Andrew Nicols <andrew@nicols.co.uk>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class week_exporter extends exporter {
/**
* @var array $days An array of day_exporter objects.
*/
protected $days = [];
/**
* @var int $prepadding The number of pre-padding days at the start of the week.
*/
protected $prepadding = 0;
/**
* @var int $postpadding The number of post-padding days at the start of the week.
*/
protected $postpadding = 0;
/**
* Constructor.
*
* @param mixed $days An array of day_exporter objects.
* @param int $prepadding The number of pre-padding days at the start of the week.
* @param int $postpadding The number of post-padding days at the start of the week.
* @param array $related Related objects.
*/
public function __construct($days, $prepadding, $postpadding, $related) {
$this->days = $days;
$this->prepadding = $prepadding;
$this->postpadding = $postpadding;
parent::__construct([], $related);
}
/**
* Return the list of additional properties.
*
* @return array
*/
protected static function define_other_properties() {
return [
'prepadding' => [
'type' => PARAM_INT,
'multiple' => true,
],
'postpadding' => [
'type' => PARAM_INT,
'multiple' => true,
],
'days' => [
'type' => day_exporter::read_properties_definition(),
'multiple' => true,
],
];
}
/**
* Get the additional values to inject while exporting.
*
* @param renderer_base $output The renderer.
* @return array Keys are the property names, values are their values.
*/
protected function get_other_values(renderer_base $output) {
$return = [
'prepadding' => [],
'postpadding' => [],
'days' => [],
];
for ($i = 0; $i < $this->prepadding; $i++) {
$return['prepadding'][] = $i;
}
for ($i = 0; $i < $this->postpadding; $i++) {
$return['postpadding'][] = $i;
}
$return['days'] = [];
foreach ($this->days as $daydata) {
$events = [];
foreach ($this->related['events'] as $event) {
$times = $event->get_times();
$starttime = $times->get_start_time()->getTimestamp();
$startdate = $this->related['type']->timestamp_to_date_array($starttime);
$endtime = $times->get_end_time()->getTimestamp();
$enddate = $this->related['type']->timestamp_to_date_array($endtime);
if ((($startdate['year'] * 366) + $startdate['yday']) > ($daydata['year'] * 366) + $daydata['yday']) {
// Starts after today.
continue;
}
if ((($enddate['year'] * 366) + $enddate['yday']) < ($daydata['year'] * 366) + $daydata['yday']) {
// Ends before today.
continue;
}
$events[] = $event;
}
$day = new day_exporter($daydata, [
'events' => $events,
'cache' => $this->related['cache'],
'type' => $this->related['type'],
]);
$return['days'][] = $day->export($output);
}
return $return;
}
/**
* Returns a list of objects that are related.
*
* @return array
*/
protected static function define_related() {
return [
'events' => '\core_calendar\local\event\entities\event_interface[]',
'cache' => '\core_calendar\external\events_related_objects_cache',
'type' => '\core_calendar\type_base',
];
}
}

View File

@ -70,7 +70,8 @@ class api {
array $groupsfilter = null,
array $coursesfilter = null,
$withduration = true,
$ignorehidden = true
$ignorehidden = true,
callable $filter = null
) {
global $USER;
@ -100,7 +101,8 @@ class api {
$groupsfilter,
$coursesfilter,
$withduration,
$ignorehidden
$ignorehidden,
$filter
);
}

View File

@ -217,4 +217,26 @@ abstract class type_base {
* @return string locale
*/
public abstract function locale_win_charset();
/**
* Provided with a day, month, year, hour and minute in the specific
* calendar type convert it into the equivalent Unix Time Stamp.
*
* @param int $year
* @param int $month
* @param int $day
* @param int $hour
* @param int $minute
* @return int timestamp
*/
public function convert_to_timestamp($year, $month, $day, $hour = 0, $minute = 0) {
$gregorianinfo = $this->convert_to_gregorian($year, $month, $day, $hour, $minute);
return make_timestamp(
$gregorianinfo['year'],
$gregorianinfo['month'],
$gregorianinfo['day'],
$gregorianinfo['hour'],
$gregorianinfo['minute'],
0);
}
}

View File

@ -705,6 +705,7 @@ class core_calendar_external extends external_api {
)
);
}
/**
* Get calendar event by id.
*
@ -745,7 +746,7 @@ class core_calendar_external extends external_api {
*
* @return external_description
*/
public static function get_calendar_event_by_id_returns() {
public static function get_calendar_event_by_id_returns() {
$eventstructure = event_exporter::get_read_structure();
return new external_single_structure(array(
@ -844,4 +845,65 @@ class core_calendar_external extends external_api {
)
);
}
/**
* Get data for the monthly calendar view.
*
* @param int $time The time to be shown
* @param int $courseid The course to be included
* @return array
*/
public static function get_calendar_monthly_view($time, $courseid) {
global $CFG, $DB, $USER, $PAGE;
require_once($CFG->dirroot."/calendar/lib.php");
// Parameter validation.
$params = self::validate_parameters(self::get_calendar_monthly_view_parameters(), [
'time' => $time,
'courseid' => $courseid,
]);
if ($courseid != SITEID && !empty($courseid)) {
// Course ID must be valid and existing.
$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
$courses = [$course->id => $course];
} else {
$course = get_site();
$courses = calendar_get_default_courses();
}
// TODO: Copy what we do in calendar/view.php.
$context = \context_user::instance($USER->id);
self::validate_context($context);
$calendar = new calendar_information(0, 0, 0, $time);
$calendar->prepare_for_view($course, $courses);
list($data, $template) = calendar_get_view($calendar, 'month');
return $data;
}
/**
* Returns description of method parameters.
*
* @return external_function_parameters
*/
public static function get_calendar_monthly_view_parameters() {
return new external_function_parameters(
[
'time' => new external_value(PARAM_INT, 'Time to be viewed', VALUE_REQUIRED, '', NULL_NOT_ALLOWED),
'courseid' => new external_value(PARAM_INT, 'Course being viewed', VALUE_DEFAULT, SITEID, NULL_ALLOWED),
]
);
}
/**
* Returns description of method result value.
*
* @return external_description
*/
public static function get_calendar_monthly_view_returns() {
return \core_calendar\external\month_exporter::get_read_structure();
}
}

View File

@ -2148,20 +2148,7 @@ function calendar_get_link_href($linkbase, $d, $m, $y, $time = 0) {
$linkbase = new \moodle_url($linkbase);
}
// If a day, month and year were passed then convert it to a timestamp. If these were passed
// then we can assume the day, month and year are passed as Gregorian, as no where in core
// should we be passing these values rather than the time.
if (!empty($d) && !empty($m) && !empty($y)) {
if (checkdate($m, $d, $y)) {
$time = make_timestamp($y, $m, $d);
} else {
$time = time();
}
} else if (empty($time)) {
$time = time();
}
$linkbase->param('time', $time);
$linkbase->param('time', calendar_get_timestamp($d, $m, $y, $time));
return $linkbase;
}
@ -2186,7 +2173,11 @@ function calendar_get_link_previous($text, $linkbase, $d, $m, $y, $accesshide =
return $text;
}
return link_arrow_left($text, (string)$href, $accesshide, 'previous');
$attrs = [
'data-time' => calendar_get_timestamp($d, $m, $y, $time),
];
return link_arrow_left($text, $href->out(false), $accesshide, 'previous', $attrs);
}
/**
@ -2209,7 +2200,11 @@ function calendar_get_link_next($text, $linkbase, $d, $m, $y, $accesshide = fals
return $text;
}
return link_arrow_right($text, (string)$href, $accesshide, 'next');
$attrs = [
'data-time' => calendar_get_timestamp($d, $m, $y, $time),
];
return link_arrow_right($text, $href->out(false), $accesshide, 'next', $attrs);
}
/**
@ -3427,6 +3422,98 @@ function calendar_get_legacy_events($tstart, $tend, $users, $groups, $courses, $
}, []);
}
/**
* Get the calendar view output.
*
* @param \calendar_information $calendar The calendar being represented
* @param string $view The type of calendar to have displayed
* @return array[array, string]
*/
function calendar_get_view(\calendar_information $calendar, $view) {
global $PAGE, $CFG;
$renderer = $PAGE->get_renderer('core_calendar');
$type = \core_calendar\type_factory::get_calendar_instance();
// Calculate the bounds of the month.
$date = $type->timestamp_to_date_array($calendar->time);
$tstart = $type->convert_to_timestamp($date['year'], $date['mon'], 1);
if ($view === 'day') {
$tend = $tstart + DAYSECS - 1;
$selectortitle = get_string('dayviewfor', 'calendar');
} else if ($view === 'upcoming') {
if (isset($CFG->calendar_lookahead)) {
$defaultlookahead = intval($CFG->calendar_lookahead);
} else {
$defaultlookahead = CALENDAR_DEFAULT_UPCOMING_LOOKAHEAD;
}
$tend = $tstart + get_user_preferences('calendar_lookahead', $defaultlookahead);
$selectortitle = get_string('upcomingeventsfor', 'calendar');
} else {
$monthdays = $type->get_num_days_in_month($date['year'], $date['mon']);
$tend = $tstart + ($monthdays * DAYSECS) - 1;
$selectortitle = get_string('detailedmonthviewfor', 'calendar');
}
list($userparam, $groupparam, $courseparam) = array_map(function($param) {
// If parameter is true, return null.
if ($param === true) {
return null;
}
// If parameter is false, return an empty array.
if ($param === false) {
return [];
}
// If the parameter is a scalar value, enclose it in an array.
if (!is_array($param)) {
return [$param];
}
// No normalisation required.
return $param;
}, [$calendar->users, $calendar->groups, $calendar->courses]);
$events = \core_calendar\local\api::get_events(
$tstart,
$tend,
null,
null,
null,
null,
40,
null,
$userparam,
$groupparam,
$courseparam,
true,
true,
function ($event) {
if ($proxy = $event->get_course_module()) {
$cminfo = $proxy->get_proxied_instance();
return $cminfo->uservisible;
}
return true;
}
);
$related = [
'events' => $events,
'cache' => new \core_calendar\external\events_related_objects_cache($events),
];
$month = new \core_calendar\external\month_exporter($calendar, $type, $related);
$data = $month->export($renderer);
$template = 'core_calendar/month_detailed';
return [$data, $template];
}
/**
* Request and render event form fragment.
*
@ -3499,3 +3586,50 @@ function calendar_output_fragment_event_form($args) {
$html .= $mform->render();
return $html;
}
/**
* Calculate the timestamp from the supplied Gregorian Year, Month, and Day.
*
* @param int $d The day
* @param int $m The month
* @param int $y The year
* @param int $time The timestamp to use instead of a separate y/m/d.
* @return int The timestamp
*/
function calendar_get_timestamp($d, $m, $y, $time = 0) {
// If a day, month and year were passed then convert it to a timestamp. If these were passed
// then we can assume the day, month and year are passed as Gregorian, as no where in core
// should we be passing these values rather than the time.
if (!empty($d) && !empty($m) && !empty($y)) {
if (checkdate($m, $d, $y)) {
$time = make_timestamp($y, $m, $d);
} else {
$time = time();
}
} else if (empty($time)) {
$time = time();
}
return $time;
}
/**
* Get the calendar footer options.
*
* @param calendar_information $calendar The calendar information object.
* @return array The data for template and template name.
*/
function calendar_get_footer_options($calendar) {
global $CFG, $USER, $DB, $PAGE;
// Generate hash for iCal link.
$rawhash = $USER->id . $DB->get_field('user', 'password', ['id' => $USER->id]) . $CFG->calendar_exportsalt;
$authtoken = sha1($rawhash);
$renderer = $PAGE->get_renderer('core_calendar');
$footer = new \core_calendar\external\footer_options_exporter($calendar, $USER->id, $authtoken);
$data = $footer->export($renderer);
$template = 'core_calendar/footer_options';
return [$data, $template];
}

View File

@ -128,7 +128,7 @@ class core_calendar_renderer extends plugin_renderer_base {
* $month and $year are kept for backwards compatibility.
* @return string
*/
protected function add_event_button($courseid, $day = null, $month = null, $year = null, $time = null) {
public function add_event_button($courseid, $day = null, $month = null, $year = null, $time = null) {
// If a day, month and year were passed then convert it to a timestamp. If these were passed
// then we can assume the day, month and year are passed as Gregorian, as no where in core
// should we be passing these values rather than the time. This is done for BC.
@ -312,234 +312,6 @@ class core_calendar_renderer extends plugin_renderer_base {
return html_writer::tag('div', $eventhtml, array('class' => 'event', 'id' => 'event_' . $event->id));
}
/**
* Displays a month in detail
*
* @param calendar_information $calendar
* @param moodle_url $returnurl the url to return to
* @return string
*/
public function show_month_detailed(calendar_information $calendar, moodle_url $returnurl = null) {
global $CFG;
if (empty($returnurl)) {
$returnurl = $this->page->url;
}
// Get the calendar type we are using.
$calendartype = \core_calendar\type_factory::get_calendar_instance();
// Store the display settings.
$display = new stdClass;
$display->thismonth = false;
// Get the specified date in the calendar type being used.
$date = $calendartype->timestamp_to_date_array($calendar->time);
$thisdate = $calendartype->timestamp_to_date_array(time());
if ($date['mon'] == $thisdate['mon'] && $date['year'] == $thisdate['year']) {
$display->thismonth = true;
$date = $thisdate;
$calendar->time = time();
}
// Get Gregorian date for the start of the month.
$gregoriandate = $calendartype->convert_to_gregorian($date['year'], $date['mon'], 1);
// Store the gregorian date values to be used later.
list($gy, $gm, $gd, $gh, $gmin) = array($gregoriandate['year'], $gregoriandate['month'], $gregoriandate['day'],
$gregoriandate['hour'], $gregoriandate['minute']);
// Get the starting week day for this month.
$startwday = dayofweek(1, $date['mon'], $date['year']);
// Get the days in a week.
$daynames = calendar_get_days();
// Store the number of days in a week.
$numberofdaysinweek = $calendartype->get_num_weekdays();
$display->minwday = calendar_get_starting_weekday();
$display->maxwday = $display->minwday + ($numberofdaysinweek - 1);
$display->maxdays = calendar_days_in_month($date['mon'], $date['year']);
// These are used for DB queries, so we want unixtime, so we need to use Gregorian dates.
$display->tstart = make_timestamp($gy, $gm, $gd, $gh, $gmin, 0);
$display->tend = $display->tstart + ($display->maxdays * DAYSECS) - 1;
// Align the starting weekday to fall in our display range
// This is simple, not foolproof.
if ($startwday < $display->minwday) {
$startwday += $numberofdaysinweek;
}
// Get events from database
$events = calendar_get_legacy_events($display->tstart, $display->tend, $calendar->users, $calendar->groups,
$calendar->courses);
if (!empty($events)) {
foreach($events as $eventid => $event) {
$event = new calendar_event($event);
if (!empty($event->modulename)) {
$instances = get_fast_modinfo($event->courseid)->get_instances_of($event->modulename);
if (empty($instances[$event->instance]->uservisible)) {
unset($events[$eventid]);
}
}
}
}
// Extract information: events vs. time
calendar_events_by_day($events, $date['mon'], $date['year'], $eventsbyday, $durationbyday,
$typesbyday, $calendar->courses);
$output = html_writer::start_tag('div', array('class'=>'header'));
$output .= $this->course_filter_selector($returnurl, get_string('detailedmonthviewfor', 'calendar'));
if (calendar_user_can_add_event($calendar->course)) {
$output .= $this->add_event_button($calendar->course->id, 0, 0, 0, $calendar->time);
}
$output .= html_writer::end_tag('div', array('class'=>'header'));
// Controls
$output .= html_writer::tag('div', calendar_top_controls('month', array('id' => $calendar->courseid,
'time' => $calendar->time)), array('class' => 'controls'));
$table = new html_table();
$table->attributes = array('class'=>'calendarmonth calendartable');
$table->summary = get_string('calendarheading', 'calendar', userdate($calendar->time, get_string('strftimemonthyear')));
$table->data = array();
// Get the day names as the header.
$header = array();
for($i = $display->minwday; $i <= $display->maxwday; ++$i) {
$header[] = $daynames[$i % $numberofdaysinweek]['shortname'];
}
$table->head = $header;
// For the table display. $week is the row; $dayweek is the column.
$week = 1;
$dayweek = $startwday;
$row = new html_table_row(array());
// Paddding (the first week may have blank days in the beginning)
for($i = $display->minwday; $i < $startwday; ++$i) {
$cell = new html_table_cell('&nbsp;');
$cell->attributes = array('class'=>'nottoday dayblank');
$row->cells[] = $cell;
}
// Now display all the calendar
$weekend = CALENDAR_DEFAULT_WEEKEND;
if (isset($CFG->calendar_weekend)) {
$weekend = intval($CFG->calendar_weekend);
}
$daytime = strtotime('-1 day', $display->tstart);
for ($day = 1; $day <= $display->maxdays; ++$day, ++$dayweek) {
$daytime = strtotime('+1 day', $daytime);
if($dayweek > $display->maxwday) {
// We need to change week (table row)
$table->data[] = $row;
$row = new html_table_row(array());
$dayweek = $display->minwday;
++$week;
}
// Reset vars
$cell = new html_table_cell();
$dayhref = calendar_get_link_href(new moodle_url(CALENDAR_URL . 'view.php',
array('view' => 'day', 'course' => $calendar->courseid)), 0, 0, 0, $daytime);
$cellclasses = array();
if ($weekend & (1 << ($dayweek % $numberofdaysinweek))) {
// Weekend. This is true no matter what the exact range is.
$cellclasses[] = 'weekend';
}
// Special visual fx if an event is defined
if (isset($eventsbyday[$day])) {
if(count($eventsbyday[$day]) == 1) {
$title = get_string('oneevent', 'calendar');
} else {
$title = get_string('manyevents', 'calendar', count($eventsbyday[$day]));
}
$cell->text = html_writer::tag('div', html_writer::link($dayhref, $day, array('title'=>$title)), array('class'=>'day'));
} else {
$cell->text = html_writer::tag('div', $day, array('class'=>'day'));
}
// Special visual fx if an event spans many days
$durationclass = false;
if (isset($typesbyday[$day]['durationglobal'])) {
$durationclass = 'duration_global';
} else if (isset($typesbyday[$day]['durationcourse'])) {
$durationclass = 'duration_course';
} else if (isset($typesbyday[$day]['durationgroup'])) {
$durationclass = 'duration_group';
} else if (isset($typesbyday[$day]['durationuser'])) {
$durationclass = 'duration_user';
}
if ($durationclass) {
$cellclasses[] = 'duration';
$cellclasses[] = $durationclass;
}
// Special visual fx for today
if ($display->thismonth && $day == $date['mday']) {
$cellclasses[] = 'day today';
} else {
$cellclasses[] = 'day nottoday';
}
$cell->attributes = array('class'=>join(' ',$cellclasses));
if (isset($eventsbyday[$day])) {
$cell->text .= html_writer::start_tag('ul', array('class'=>'events-new'));
foreach($eventsbyday[$day] as $eventindex) {
// If event has a class set then add it to the event <li> tag
$attributes = array();
if (!empty($events[$eventindex]->class)) {
$attributes['class'] = $events[$eventindex]->class;
}
$dayhref->set_anchor('event_'.$events[$eventindex]->id);
$eventcontext = $events[$eventindex]->context;
$eventformatopts = array('context' => $eventcontext);
// Get event name.
$eventname = format_string($events[$eventindex]->name, true, $eventformatopts);
// Include course's shortname into the event name, if applicable.
$courseid = $events[$eventindex]->courseid;
if (!empty($courseid) && $courseid !== SITEID) {
$course = get_course($courseid);
$eventnameparams = (object)[
'name' => $eventname,
'course' => format_string($course->shortname, true, $eventformatopts)
];
$eventname = get_string('eventnameandcourse', 'calendar', $eventnameparams);
}
$link = html_writer::link($dayhref, $eventname, ['data-action' => 'view-event',
'data-event-id' => $events[$eventindex]->id]);
$cell->text .= html_writer::tag('li', $link, $attributes);
}
$cell->text .= html_writer::end_tag('ul');
}
if (isset($durationbyday[$day])) {
$cell->text .= html_writer::start_tag('ul', array('class'=>'events-underway'));
foreach($durationbyday[$day] as $eventindex) {
$cell->text .= html_writer::tag('li', '['.format_string($events[$eventindex]->name,true).']', array('class'=>'events-underway'));
}
$cell->text .= html_writer::end_tag('ul');
}
$row->cells[] = $cell;
}
// Paddding (the last week may have blank days at the end)
for($i = $dayweek; $i <= $display->maxwday; ++$i) {
$cell = new html_table_cell('&nbsp;');
$cell->attributes = array('class'=>'nottoday dayblank');
$row->cells[] = $cell;
}
$table->data[] = $row;
$output .= html_writer::table($table);
return $output;
}
/**
* Displays upcoming events
*
@ -587,7 +359,7 @@ class core_calendar_renderer extends plugin_renderer_base {
* @param string $label The label to use for the course select.
* @return string
*/
protected function course_filter_selector(moodle_url $returnurl, $label=null) {
public function course_filter_selector(moodle_url $returnurl, $label=null) {
global $USER, $SESSION, $CFG;
if (!isloggedin() or isguestuser()) {

View File

@ -0,0 +1,37 @@
{{!
This file is part of Moodle - http://moodle.org/
Moodle is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Moodle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
@template core_calendar/footer_options
Displays export options on the calendar footer.
Example context (json):
{
"exportcalendarbutton": "<button class='btn btn-secondary'>Export calendar</button>",
"managesubscriptionbutton": "<button class='btn btn-secondary'>Manage subscriptions</button>",
"icalurl": "http://example.com/"
}
}}
<div class="bottom">
{{#exportcalendarbutton}}
{{> core/single_button }}
{{/exportcalendarbutton}}
{{#managesubscriptionbutton}}
{{> core/single_button }}
{{/managesubscriptionbutton}}
<a href="{{icalurl}}" title="{{#str}} quickdownloadcalendar, calendar {{/str}}" class="ical-link m-l-1">iCal</a>
</div>

View File

@ -0,0 +1,99 @@
{{!
This file is part of Moodle - http://moodle.org/
Moodle is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Moodle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
@template calendar/month_detailed
Calendar month view.
The purpose of this template is to render the month view.
Classes required for JS:
* none
Data attributes required for JS:
* none
Example context (json):
{
}
}}
<span class="calendarwrapper" data-courseid="{{courseid}}">
{{> core_calendar/month_header }}
{{> core_calendar/month_navigation }}
<table class="calendarmonth calendartable card-deck m-b-0">
<thead>
<tr>
{{# daynames }}
<th class="header text-xs-center">
{{shortname}}
</th>
{{/ daynames }}
</tr>
</thead>
<tbody>
{{#weeks}}
<tr>
{{#prepadding}}
<td class="dayblank">&nbsp;</td>
{{/prepadding}}
{{#days}}
<td class="day text-sm-center text-md-left{{!
}}{{#istoday}} today{{/istoday}}{{!
}}{{#isweekend}} weekend{{/isweekend}}{{!
}}{{#durationevents.0}} duration{{/durationevents.0}}{{!
}}{{#durationevents}} duration_{{.}}{{/durationevents}}{{!
}}">
<div class="hidden-sm-down text-xs-center">
{{#events.0}}
<a href="{{viewdaylink}}" class="day" title="{{viewdaylinktitle}}">{{mday}}</a>
{{/events.0}}
{{^events.0}}
{{mday}}
{{/events.0}}
{{#events.0}}
<ul>
{{#events}}
{{#underway}}
<li class="events-underway">[{{name}}]</li>
{{/underway}}
{{^underway}}
<li class="calendar_event_{{eventtype}}">
<a data-action="view-event" data-event-id="{{id}}" href="{{url}}">{{name}}</a>
</li>
{{/underway}}
{{/events}}
</ul>
{{/events.0}}
</div>
<div class="hidden-md-up hidden-desktop">
{{#events.0}}
<a href="{{viewdaylink}}" class="day" title="{{viewdaylinktitle}}">{{mday}}</a>
{{/events.0}}
{{^events.0}}
{{mday}}
{{/events.0}}
</div>
</td>
{{/days}}
{{#postpadding}}
<td class="dayblank">&nbsp;</td>
{{/postpadding}}
</tr>
{{/weeks}}
</tbody>
</table>
</span>

View File

@ -0,0 +1,38 @@
{{!
This file is part of Moodle - http://moodle.org/
Moodle is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Moodle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
@template calendar/month_header
Calendar month header.
The purpose of this template is to render the month header.
Classes required for JS:
* none
Data attributes required for JS:
* none
Example context (json):
{
}
}}
{{#filter_selector}}
<div class="header">
{{{filter_selector}}}
</div>
{{/filter_selector}}

View File

@ -0,0 +1,38 @@
{{!
This file is part of Moodle - http://moodle.org/
Moodle is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Moodle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
@template calendar/month_navigation
Calendar month navigation.
The purpose of this template is to render the navigation to switch to previous and next months.
Classes required for JS:
* none
Data attributes required for JS:
* none
Example context (json):
{
}
}}
{{#navigation}}
<div class="controls" data-view="{{view}}">
{{{navigation}}}
</div>
{{/navigation}}

View File

@ -132,49 +132,34 @@ echo $renderer->start_layout();
echo html_writer::start_tag('div', array('class'=>'heightcontainer'));
echo $OUTPUT->heading(get_string('calendar', 'calendar'));
switch($view) {
case 'day':
echo $renderer->show_day($calendar);
break;
case 'month':
echo $renderer->show_month_detailed($calendar, $url);
break;
case 'upcoming':
$defaultlookahead = CALENDAR_DEFAULT_UPCOMING_LOOKAHEAD;
if (isset($CFG->calendar_lookahead)) {
$defaultlookahead = intval($CFG->calendar_lookahead);
}
$lookahead = get_user_preferences('calendar_lookahead', $defaultlookahead);
if ($view == 'day' || $view == 'upcoming') {
switch($view) {
case 'day':
echo $renderer->show_day($calendar);
break;
case 'upcoming':
$defaultlookahead = CALENDAR_DEFAULT_UPCOMING_LOOKAHEAD;
if (isset($CFG->calendar_lookahead)) {
$defaultlookahead = intval($CFG->calendar_lookahead);
}
$lookahead = get_user_preferences('calendar_lookahead', $defaultlookahead);
$defaultmaxevents = CALENDAR_DEFAULT_UPCOMING_MAXEVENTS;
if (isset($CFG->calendar_maxevents)) {
$defaultmaxevents = intval($CFG->calendar_maxevents);
}
$maxevents = get_user_preferences('calendar_maxevents', $defaultmaxevents);
echo $renderer->show_upcoming_events($calendar, $lookahead, $maxevents);
break;
}
//Link to calendar export page.
echo $OUTPUT->container_start('bottom');
if (!empty($CFG->enablecalendarexport)) {
echo $OUTPUT->single_button(new moodle_url('export.php', array('course'=>$courseid)), get_string('exportcalendar', 'calendar'));
if (calendar_user_can_add_event($course)) {
echo $OUTPUT->single_button(new moodle_url('/calendar/managesubscriptions.php', array('course'=>$courseid)), get_string('managesubscriptions', 'calendar'));
}
if (isloggedin()) {
$authtoken = sha1($USER->id . $DB->get_field('user', 'password', array('id' => $USER->id)) . $CFG->calendar_exportsalt);
$link = new moodle_url(
'/calendar/export_execute.php',
array('preset_what'=>'all', 'preset_time' => 'recentupcoming', 'userid' => $USER->id, 'authtoken'=>$authtoken)
);
echo html_writer::tag('a', 'iCal',
array('href' => $link, 'title' => get_string('quickdownloadcalendar', 'calendar'), 'class' => 'ical-link m-l-1'));
$defaultmaxevents = CALENDAR_DEFAULT_UPCOMING_MAXEVENTS;
if (isset($CFG->calendar_maxevents)) {
$defaultmaxevents = intval($CFG->calendar_maxevents);
}
$maxevents = get_user_preferences('calendar_maxevents', $defaultmaxevents);
echo $renderer->show_upcoming_events($calendar, $lookahead, $maxevents);
break;
}
} else if ($view == 'month') {
list($data, $template) = calendar_get_view($calendar, $view);
echo $renderer->render_from_template($template, $data);
}
echo $OUTPUT->container_end();
echo html_writer::end_tag('div');
echo $renderer->complete_layout();
list($data, $template) = calendar_get_footer_options($calendar);
echo $renderer->render_from_template($template, $data);
$PAGE->requires->js_call_amd('core_calendar/calendar', 'init');
echo $OUTPUT->footer();

View File

@ -1 +1 @@
define(["jquery","core/modal_events","core/modal_registry","core/modal","core/modal_save_cancel","core/modal_confirm","core/modal_cancel","core/templates","core/notification","core/custom_interaction_events"],function(a,b,c,d,e,f,g,h,i,j){var k={DEFAULT:"core/modal",SAVE_CANCEL:"core/modal_save_cancel",CONFIRM:"core/modal_confirm",CANCEL:"core/modal_cancel"},l={DEFAULT:"DEFAULT",SAVE_CANCEL:"SAVE_CANCEL",CONFIRM:"CONFIRM",CANCEL:"CANCEL"};c.register(l.DEFAULT,d,k.DEFAULT),c.register(l.SAVE_CANCEL,e,k.SAVE_CANCEL),c.register(l.CONFIRM,f,k.CONFIRM),c.register(l.CANCEL,g,k.CANCEL);var m=function(a,c){"undefined"!=typeof c&&(j.define(c,[j.events.activate]),c.on(j.events.activate,function(b,c){a.show(),c.originalEvent.preventDefault()}),a.getRoot().on(b.hidden,function(){c.focus()}))},n=function(b,c,d){c=a(c);var e=b.module,f=new e(c);return m(f,d),f},o=function(b,c,d){var e=b.template;return h.render(e,c).then(function(c){var e=a(c);return n(b,e,d)}).fail(i.exception)},p=function(a,b){var d=a.type||l.DEFAULT,e=!!a.large,f=null,g={};return f=c.get(d),f||i.exception({message:"Unable to find modal of type: "+d}),"undefined"!=typeof a.templateContext&&(g=a.templateContext),o(f,g,b).then(function(b){return"undefined"!=typeof a.title&&b.setTitle(a.title),"undefined"!=typeof a.body&&b.setBody(a.body),"undefined"!=typeof a.footer&&b.setFooter(a.footer),e&&b.setLarge(),b})};return{create:p,types:l}});
define(["jquery","core/modal_events","core/modal_registry","core/modal","core/modal_save_cancel","core/modal_confirm","core/modal_cancel","core/templates","core/notification","core/custom_interaction_events"],function(a,b,c,d,e,f,g,h,i,j){var k={DEFAULT:"core/modal",SAVE_CANCEL:"core/modal_save_cancel",CONFIRM:"core/modal_confirm",CANCEL:"core/modal_cancel"},l={DEFAULT:"DEFAULT",SAVE_CANCEL:"SAVE_CANCEL",CONFIRM:"CONFIRM",CANCEL:"CANCEL"};c.register(l.DEFAULT,d,k.DEFAULT),c.register(l.SAVE_CANCEL,e,k.SAVE_CANCEL),c.register(l.CONFIRM,f,k.CONFIRM),c.register(l.CANCEL,g,k.CANCEL);var m=function(a,c){if("undefined"!=typeof c){if(Array.isArray(c)){var d=c[1];c=c[0],j.define(c,[j.events.activate]),c.on(j.events.activate,d,function(b,c){a.show(),c.originalEvent.preventDefault()})}else j.define(c,[j.events.activate]),c.on(j.events.activate,function(b,c){a.show(),c.originalEvent.preventDefault()});a.getRoot().on(b.hidden,function(){c.focus()})}},n=function(b,c,d){c=a(c);var e=b.module,f=new e(c);return m(f,d),f},o=function(b,c,d){var e=b.template;return h.render(e,c).then(function(c){var e=a(c);return n(b,e,d)}).fail(i.exception)},p=function(a,b){var d=a.type||l.DEFAULT,e=!!a.large,f=null,g={};return f=c.get(d),f||i.exception({message:"Unable to find modal of type: "+d}),"undefined"!=typeof a.templateContext&&(g=a.templateContext),o(f,g,b).then(function(b){return"undefined"!=typeof a.title&&b.setTitle(a.title),"undefined"!=typeof a.body&&b.setBody(a.body),"undefined"!=typeof a.footer&&b.setFooter(a.footer),e&&b.setLarge(),b})};return{create:p,types:l}});

View File

@ -60,11 +60,22 @@ define(['jquery', 'core/modal_events', 'core/modal_registry', 'core/modal',
*/
var setUpTrigger = function(modal, triggerElement) {
if (typeof triggerElement != 'undefined') {
CustomEvents.define(triggerElement, [CustomEvents.events.activate]);
triggerElement.on(CustomEvents.events.activate, function(e, data) {
modal.show();
data.originalEvent.preventDefault();
});
if (Array.isArray(triggerElement)) {
var selector = triggerElement[1];
triggerElement = triggerElement[0];
CustomEvents.define(triggerElement, [CustomEvents.events.activate]);
triggerElement.on(CustomEvents.events.activate, selector, function(e, data) {
modal.show();
data.originalEvent.preventDefault();
});
} else {
CustomEvents.define(triggerElement, [CustomEvents.events.activate]);
triggerElement.on(CustomEvents.events.activate, function(e, data) {
modal.show();
data.originalEvent.preventDefault();
});
}
modal.getRoot().on(ModalEvents.hidden, function() {
triggerElement.focus();

View File

@ -58,6 +58,16 @@ $functions = array(
'capabilities' => 'moodle/badges:viewotherbadges',
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE),
),
'core_calendar_get_calendar_monthly_view' => array(
'classname' => 'core_calendar_external',
'methodname' => 'get_calendar_monthly_view',
'description' => 'Fetch the monthly view data for a calendar',
'classpath' => 'calendar/externallib.php',
'type' => 'read',
'capabilities' => '',
'ajax' => true,
'services' => array(MOODLE_OFFICIAL_MOBILE_SERVICE),
),
'core_calendar_create_calendar_events' => array(
'classname' => 'core_calendar_external',
'methodname' => 'create_calendar_events',

View File

@ -0,0 +1,61 @@
{{!
This file is part of Moodle - http://moodle.org/
Moodle is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Moodle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
@template core/single_button
Moodle template for a single button submit form.
Classes required for JS:
* none
Data attributes required for JS:
* none
Context variables required for this template:
* classes - a list of classes to wrap the form.
* method - get or post
* url - the action url to submit to
* formid - optional id value for the form
* params - array of params with name and value attributes
* primary - true if this is a primary action button
* id - id for the element
* tooltip - tooltip text for the button
* disabled - true if this element is disabled
* label - text to show on the button
Example context (json):
{ "method" : "get",
"url" : "#",
"primary" : true,
"tooltip" : "This is a tooltip",
"label" : "This is a the button text"
}
}}
<div class="{{classes}}">
<form method="{{method}}" action="{{url}}" {{#formid}}id="{{formid}}"{{/formid}}>
{{#params}}
<input type="hidden" name="{{name}}" value="{{value}}">
{{/params}}
<button type="submit" class="btn {{#primary}}btn-primary{{/primary}}{{^primary}}btn-default{{/primary}}"
id="{{id}}"
title={{#quote}}{{tooltip}}{{/quote}}
{{#disabled}}disabled{{/disabled}}>{{label}}</button>
</form>
</div>
{{#hasactions}}
{{> core/actions }}
{{/hasactions}}

View File

@ -2215,7 +2215,7 @@ function send_headers($contenttype, $cacheable = true) {
* @param string $addclass Additional class names for the link, or the arrow character.
* @return string HTML string.
*/
function link_arrow_right($text, $url='', $accesshide=false, $addclass='') {
function link_arrow_right($text, $url='', $accesshide=false, $addclass='', $addparams = []) {
global $OUTPUT; // TODO: move to output renderer.
$arrowclass = 'arrow ';
if (!$url) {
@ -2234,7 +2234,16 @@ function link_arrow_right($text, $url='', $accesshide=false, $addclass='') {
if ($addclass) {
$class .= ' '.$addclass;
}
return '<a class="'.$class.'" href="'.$url.'" title="'.preg_replace('/<.*?>/', '', $text).'">'.$htmltext.$arrow.'</a>';
$linkparams = [
'class' => $class,
'href' => $url,
'title' => preg_replace('/<.*?>/', '', $text),
];
$linkparams += $addparams;
return html_writer::link($url, $htmltext . $arrow, $linkparams);
}
return $htmltext.$arrow;
}
@ -2248,7 +2257,7 @@ function link_arrow_right($text, $url='', $accesshide=false, $addclass='') {
* @param string $addclass Additional class names for the link, or the arrow character.
* @return string HTML string.
*/
function link_arrow_left($text, $url='', $accesshide=false, $addclass='') {
function link_arrow_left($text, $url='', $accesshide=false, $addclass='', $addparams = []) {
global $OUTPUT; // TODO: move to utput renderer.
$arrowclass = 'arrow ';
if (! $url) {
@ -2267,7 +2276,16 @@ function link_arrow_left($text, $url='', $accesshide=false, $addclass='') {
if ($addclass) {
$class .= ' '.$addclass;
}
return '<a class="'.$class.'" href="'.$url.'" title="'.preg_replace('/<.*?>/', '', $text).'">'.$arrow.$htmltext.'</a>';
$linkparams = [
'class' => $class,
'href' => $url,
'title' => preg_replace('/<.*?>/', '', $text),
];
$linkparams += $addparams;
return html_writer::link($url, $arrow . $htmltext, $linkparams);
}
return $arrow.$htmltext;
}

View File

@ -11,7 +11,7 @@ $calendarEventUserColor: #dce7ec !default; // Pale blue.
background-color: $calendarEventCourseColor;
}
.calendar_event_global {
.calendar_event_site {
background-color: $calendarEventGlobalColor;
}
@ -119,7 +119,7 @@ $calendarEventUserColor: #dce7ec !default; // Pale blue.
}
.calendar_event_course,
.calendar_event_global,
.calendar_event_site,
.calendar_event_group,
.calendar_event_user {
border-width: 1px 1px 1px 12px;
@ -130,7 +130,7 @@ $calendarEventUserColor: #dce7ec !default; // Pale blue.
border-color: $calendarEventCourseColor;
}
.calendar_event_global {
.calendar_event_site {
border-color: $calendarEventGlobalColor;
}

View File

@ -10,7 +10,7 @@
.calendar_event_course {
background-color: @calendarEventCourseColor;
}
.calendar_event_global {
.calendar_event_site {
background-color: @calendarEventGlobalColor;
}
.calendar_event_group {
@ -109,7 +109,7 @@
margin: 10px auto;
}
.calendar_event_course,
.calendar_event_global,
.calendar_event_site,
.calendar_event_group,
.calendar_event_user {
border-width: 1px 1px 1px 12px;
@ -118,7 +118,7 @@
.calendar_event_course {
border-color: @calendarEventCourseColor;
}
.calendar_event_global {
.calendar_event_site {
border-color: @calendarEventGlobalColor;
}
.calendar_event_group {

View File

@ -5542,7 +5542,7 @@ img.iconsmall {
.calendar_event_course {
background-color: #ffd3bd;
}
.calendar_event_global {
.calendar_event_site {
background-color: #d6f8cd;
}
.calendar_event_group {
@ -5630,7 +5630,7 @@ img.iconsmall {
margin: 10px auto;
}
.path-calendar .maincalendar .calendar_event_course,
.path-calendar .maincalendar .calendar_event_global,
.path-calendar .maincalendar .calendar_event_site,
.path-calendar .maincalendar .calendar_event_group,
.path-calendar .maincalendar .calendar_event_user {
border-width: 1px 1px 1px 12px;
@ -5639,7 +5639,7 @@ img.iconsmall {
.path-calendar .maincalendar .calendar_event_course {
border-color: #ffd3bd;
}
.path-calendar .maincalendar .calendar_event_global {
.path-calendar .maincalendar .calendar_event_site {
border-color: #d6f8cd;
}
.path-calendar .maincalendar .calendar_event_group {

View File

@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2017081000.00; // YYYYMMDD = weekly release date of this DEV branch.
$version = 2017081000.01; // YYYYMMDD = weekly release date of this DEV branch.
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.