};
/**
- * 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
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'
};
});
* @param {Number} courseid The course id.
* @return {promise} Resolved with the month view data.
*/
- var getCalendarMonthData = function (time, courseid) {
+ var getCalendarMonthData = function(time, courseid) {
var request = {
methodname: 'core_calendar_get_calendar_monthly_view',
args: {
time: time,
- courseid: courseid,
+ courseid: courseid
}
};
* @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'],
- function($, Templates, Notification, CalendarRepository) {
+define(['jquery', 'core/templates', 'core/notification', 'core_calendar/repository', 'core_calendar/events'],
+ function($, Templates, Notification, CalendarRepository, CalendarEvents) {
var SELECTORS = {
ROOT: "[data-region='calendar']",
});
};
-
/**
* 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) {
- // TODO Fetch the page title from somewhere..?
- window.history.pushState({}, 'Some new title', url);
+ window.history.pushState({}, '', url);
return Templates.render('core_calendar/month_detailed', context);
})
return Templates.runTemplateJS(js);
})
- .then(function() {
- // TODO Fire an event to say the month changed.
+ .done(function() {
+ $('body').trigger(CalendarEvents.monthChanged, []);
})
.fail(Notification.exception);
};
<?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 the list of additional properties.
+ *
+ * @return array
+ */
protected static function define_other_properties() {
return [
'timestamp' => [
'events' => [
'type' => event_exporter::read_properties_definition(),
'multiple' => true,
- ],
- 'viewdaylink' => [
- 'type' => PARAM_URL,
- ],
-
- //'viewdaylink' => $this->viewdaylink->out(false),
- //'createeventlink' => $this->createeventlink,
- //'viewdaylinktitle' => $this->get_title($renderer),
- //'events' => $this->get_events($renderer),
- //'hasevents' => !empty($this->events),
- //'eventtypes' => array_unique($this->eventtypes),
- //'eventcount' => count($this->events),
- //'durationevents' => array_unique($this->durationevents),
+ ]
];
}
+ /**
+ * 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) {
- //$events = new events_exporter($this->related['events'], $this->related);
$return = [
'timestamp' => $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);
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[]',
<?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;
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_name_exporter extends exporter {
/**
*/
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' => [
* 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;
*/
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]);
+ 'preset_time' => 'recentupcoming', 'userid' => $this->userid, 'authtoken' => $this->token]);
}
<?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 {
/**
parent::__construct([], $related);
}
+ /**
+ * Return the list of additional properties.
+ *
+ * @return array
+ */
protected static function define_other_properties() {
return [
'courseid' => [
];
}
+ /**
+ * 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,
/**
* Get the course filter selector.
- * TODO Convert to new exporter?
*
- * @param renderer_base $output
- * return string
+ * @param renderer_base $output
+ * @return string The html code for the course filter selector.
*/
protected function get_course_filter_selector(renderer_base $output) {
$content = '';
}
/**
- * Get the course filter selector.
- * TODO Convert to new exporter?
+ * Get the calendar navigation controls.
*
- * @param renderer_base $output
- * return string
+ * @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', [
* 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
+ * @param renderer_base $output
+ * @return array The list of weeks.
*/
protected function get_weeks(renderer_base $output) {
$weeks = [];
/**
* Get the list of days with the matching date array.
*
- * @return array
+ * @return array
*/
protected function get_days() {
$date = $this->related['type']->timestamp_to_date_array($this->calendar->time);
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[]',
];
}
+ /**
+ * 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']);
}
}
<?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;
use moodle_url;
+/**
+ * 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 {
/**
protected $days = [];
/**
- * @var int $prepadding The number of pre-padding days at the start of
- * the week.
+ * @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.
+ * @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;
parent::__construct([], $related);
}
+ /**
+ * Return the list of additional properties.
+ *
+ * @return array
+ */
protected static function define_other_properties() {
return [
'prepadding' => [
];
}
+ /**
+ * 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' => [],
// 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[]',
* @return array[array, string]
*/
function calendar_get_view(\calendar_information $calendar, $view) {
- global $PAGE, $DB, $OUTPUT;
+ global $PAGE, $CFG;
$renderer = $PAGE->get_renderer('core_calendar');
$type = \core_calendar\type_factory::get_calendar_instance();
$tend = $tstart + DAYSECS - 1;
$selectortitle = get_string('dayviewfor', 'calendar');
} else if ($view === 'upcoming') {
- $defaultlookahead = isset($CFG->calendar_lookahead) ? intval($CFG->calendar_lookahead) : CALENDAR_DEFAULT_UPCOMING_LOOKAHEAD;
+ 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 {
'cache' => new \core_calendar\external\events_related_objects_cache($events),
];
- if ($view === 'day') {
- // TODO: Export the days events in a new exporter.
- } else if ($view === 'upcoming') {
+ if ($view === 'upcoming') {
$defaultlookahead = CALENDAR_DEFAULT_UPCOMING_LOOKAHEAD;
if (isset($CFG->calendar_lookahead)) {
$defaultlookahead = intval($CFG->calendar_lookahead);
$defaultmaxevents = intval($CFG->calendar_maxevents);
}
$maxevents = get_user_preferences('calendar_maxevents', $defaultmaxevents);
- // TODO: Export the upcoming events in a new exporter.
} else {
$month = new \core_calendar\external\month_exporter($calendar, $type, $related);
$data = $month->export($renderer);
+{{!
+ 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 }}
+{{!
+ 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}}}
+{{!
+ 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}}}