Skip to content

Commit

Permalink
Merge branch 'MDL-60062-master-2' of git://github.com/ryanwyllie/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewnicols committed Nov 7, 2017
2 parents b44bc9b + 6688ae2 commit 03561ea
Show file tree
Hide file tree
Showing 17 changed files with 1,360 additions and 889 deletions.
27 changes: 24 additions & 3 deletions calendar/classes/external/calendar_event_exporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,10 @@ protected static function define_other_properties() {
'type' => PARAM_TEXT,
'optional' => true
];
$values['draggable'] = [
'type' => PARAM_BOOL,
'default' => false
];

return $values;
}
Expand All @@ -90,6 +94,10 @@ protected function get_other_values(renderer_base $output) {
$values = parent::get_other_values($output);
$event = $this->event;

// By default all events that can be edited are
// draggable.
$values['draggable'] = $values['canedit'];

if ($moduleproxy = $event->get_course_module()) {
$modulename = $moduleproxy->get('modname');
$moduleid = $moduleproxy->get('id');
Expand Down Expand Up @@ -213,17 +221,30 @@ public function get_calendar_event_type() {
* @return array
*/
protected function get_module_timestamp_limits($event) {
global $DB;

$values = [];
$mapper = container::get_event_mapper();
$starttime = $event->get_times()->get_start_time();
$modname = $event->get_course_module()->get('modname');
$modid = $event->get_course_module()->get('instance');
$moduleinstance = $DB->get_record($modname, ['id' => $modid]);

list($min, $max) = component_callback(
'mod_' . $event->get_course_module()->get('modname'),
'mod_' . $modname,
'core_calendar_get_valid_event_timestart_range',
[$mapper->from_event_to_legacy_event($event)],
[null, null]
[$mapper->from_event_to_legacy_event($event), $moduleinstance],
[false, false]
);

// The callback will return false for either of the
// min or max cutoffs to indicate that there are no
// valid timestart values. In which case the event is
// not draggable.
if ($min === false || $max === false) {
return ['draggable' => false];
}

if ($min) {
$values = array_merge($values, $this->get_module_timestamp_min_limit($starttime, $min));
}
Expand Down
42 changes: 34 additions & 8 deletions calendar/classes/local/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,25 +231,51 @@ public static function update_event_start_day(
event_interface $event,
\DateTimeInterface $startdate
) {
global $DB;

$mapper = container::get_event_mapper();
$legacyevent = $mapper->from_event_to_legacy_event($event);
$hascoursemodule = !empty($event->get_course_module());
$moduleinstance = null;
$starttime = $event->get_times()->get_start_time()->setDate(
$startdate->format('Y'),
$startdate->format('n'),
$startdate->format('j')
);

if ($hascoursemodule) {
$moduleinstance = $DB->get_record(
$event->get_course_module()->get('modname'),
['id' => $event->get_course_module()->get('instance')],
'*',
MUST_EXIST
);
$legacyevent->timestart = $starttime->getTimestamp();
// If this event is from an activity then we need to call
// the activity callback to let it validate that the changes
// to the event are correct.
component_callback(

// If there is a timestart range callback implemented then we can
// use the values returned from the valid timestart range to apply
// some default validation on the event's timestart value to ensure
// that it falls within the specified range.
list($min, $max) = component_callback(
'mod_' . $event->get_course_module()->get('modname'),
'core_calendar_validate_event_timestart',
[$legacyevent]
'core_calendar_get_valid_event_timestart_range',
[$legacyevent, $moduleinstance],
[false, false]
);

// If the callback returns false for either value it means that
// there is no valid time start range.
if ($min === false || $max === false) {
throw new \moodle_exception('The start day of this event can not be modified');
}

if ($min && $legacyevent->timestart < $min[0]) {
throw new \moodle_exception($min[1]);
}

if ($max && $legacyevent->timestart > $max[0]) {
throw new \moodle_exception($max[1]);
}
}

// This function does our capability checks.
Expand All @@ -262,15 +288,15 @@ public static function update_event_start_day(
// We don't want to call the event update callback if the user isn't allowed
// to modify course modules because depending on the callback it can make
// some changes that would be considered security issues, such as updating the
// due date for and assignment.
// due date for an assignment.
if ($hascoursemodule && calendar_edit_event_allowed($legacyevent, true)) {
// If this event is from an activity then we need to call
// the activity callback to let it know that the event it
// created has been modified so it needs to update accordingly.
component_callback(
'mod_' . $event->get_course_module()->get('modname'),
'core_calendar_event_timestart_updated',
[$legacyevent]
[$legacyevent, $moduleinstance]
);
}

Expand Down
4 changes: 2 additions & 2 deletions calendar/templates/month_detailed.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
{{^underway}}
<li data-region="event-item"
data-eventtype-{{calendareventtype}}="1"
{{#canedit}}
{{#draggable}}
draggable="true"
data-drag-type="move"
{{#mindaytimestamp}}
Expand All @@ -102,7 +102,7 @@
{{#maxdayerror}}
data-max-day-error="{{.}}"
{{/maxdayerror}}
{{/canedit}}>
{{/draggable}}>

<a data-action="view-event" data-event-id="{{id}}" href="{{url}}" title="{{name}}">
<span class="badge badge-circle calendar_event_{{calendareventtype}}">
Expand Down
Loading

0 comments on commit 03561ea

Please sign in to comment.