Merge branch 'master-MDL-66716' of https://github.com/golenkovm/moodle into master

This commit is contained in:
Eloy Lafuente (stronk7) 2020-08-12 20:09:40 +02:00
commit a470c9064a
15 changed files with 56 additions and 16 deletions

View File

@ -1,2 +1,2 @@
define ("block_timeline/event_list",["jquery","core/notification","core/templates","core/paged_content_factory","core/str","core/user_date","block_timeline/calendar_events_repository"],function(a,b,c,d,e,f,g){var h={EMPTY_MESSAGE:"[data-region=\"empty-message\"]",ROOT:"[data-region=\"event-list-container\"]",EVENT_LIST_CONTENT:"[data-region=\"event-list-content\"]",EVENT_LIST_LOADING_PLACEHOLDER:"[data-region=\"event-list-loading-placeholder\"]"},i={EVENT_LIST_CONTENT:"block_timeline/event-list-content"},j={ignoreControlWhileLoading:!0,controlPlacementBottom:!0,ariaLabels:{itemsperpagecomponents:"ariaeventlistpagelimit, block_timeline"}},k=function(a){a.find(h.EVENT_LIST_CONTENT).addClass("hidden");a.find(h.EMPTY_MESSAGE).removeClass("hidden")},l=function(a){a.find(h.EVENT_LIST_CONTENT).removeClass("hidden");a.find(h.EMPTY_MESSAGE).addClass("hidden")},m=function(a){a.find(h.EVENT_LIST_CONTENT).empty()},n=function(a,b){var c={},d={eventsbyday:[]};a.forEach(function(a){var d=f.getUserMidnightForTimestamp(a.timesort,b);if(c[d]){c[d].push(a)}else{c[d]=[a]}});Object.keys(c).forEach(function(a){var e=c[a];d.eventsbyday.push({past:a<b,dayTimestamp:a,events:e})});return d},o=function(a,b){var d=n(a,b),e=i.EVENT_LIST_CONTENT;return c.render(e,d)},p=function(a,b,c,d,e,f){var h=d!=void 0?a+d*86400:!1,i={starttime:a+c*86400,limit:b};if(e){i.aftereventid=e}if(h){i.endtime=h}if(f){i.courseid=f;return g.queryByCourse(i)}else{return g.queryByTime(i)}},q=function(a,b,c,d,e,g,h,i){var j=a.pageNumber,k=a.limit,l=j;while(!d.hasOwnProperty(l)){l--}var m=d[l],n=null;if(e&&e.hasOwnProperty(j)){n=e[j]}else{n=p(c,k+1,h,i,m,g)}return n.then(function(a){if(!a.events.length){b.allItemsLoaded(j);return[]}var d=a.events.filter(function(a){if("open"==a.eventtype||"opensubmission"==a.eventtype){var b=f.getUserMidnightForTimestamp(a.timesort,c);return b>c}return!0}),e=d.length<=k;if(e){b.allItemsLoaded(j)}else{d.pop()}return d})},r=function(c,f,g,h,i,k,l,m,n){var p={1:0},r=!1,s=a.extend({},j,n);return e.get_string("ariaeventlistpagelimit","block_timeline",a.isArray(c)?c[0].value:c).then(function(a){s.ariaLabels.itemsperpage=a;s.ariaLabels.paginationnav=m;return a}).then(function(){return d.createWithLimit(c,function(c,d){var e=[];c.forEach(function(a){var c=a.pageNumber,h=q(a,d,g,p,f,i,k,l).then(function(a){if(a.length){r=!0;var b=a[a.length-1].id;p[c+1]=b;return o(a,g)}else{return a}}).catch(b.exception);e.push(h)});a.when.apply(a,e).then(function(){h.resolve(r)}).catch(function(){h.resolve(r)});return e},s)})};return{init:function init(d,e,f,g,i){d=a(d);var j=a.Deferred(),n=d.find(h.EVENT_LIST_CONTENT),o=d.find(h.EVENT_LIST_LOADING_PLACEHOLDER),p=d.attr("data-course-id"),q=parseInt(d.attr("data-days-offset"),10),s=d.attr("data-days-limit"),t=parseInt(d.attr("data-midnight"),10);m(d);l(d);o.removeClass("hidden");if(s!=void 0){s=parseInt(s,10)}return r(e,f,t,j,p,q,s,g,i).then(function(b,e){b=a(b);b.addClass("hidden");c.replaceNodeContents(n,b,e);j.then(function(a){b.removeClass("hidden");o.addClass("hidden");if(!a){k(d)}return a}).catch(function(){return!1});return b}).catch(b.exception)},rootSelector:h.ROOT}});
define ("block_timeline/event_list",["jquery","core/notification","core/templates","core/paged_content_factory","core/str","core/user_date","block_timeline/calendar_events_repository"],function(a,b,c,d,e,f,g){var h={EMPTY_MESSAGE:"[data-region=\"empty-message\"]",ROOT:"[data-region=\"event-list-container\"]",EVENT_LIST_CONTENT:"[data-region=\"event-list-content\"]",EVENT_LIST_LOADING_PLACEHOLDER:"[data-region=\"event-list-loading-placeholder\"]"},i={EVENT_LIST_CONTENT:"block_timeline/event-list-content"},j={ignoreControlWhileLoading:!0,controlPlacementBottom:!0,ariaLabels:{itemsperpagecomponents:"ariaeventlistpagelimit, block_timeline"}},k=function(a){a.find(h.EVENT_LIST_CONTENT).addClass("hidden");a.find(h.EMPTY_MESSAGE).removeClass("hidden")},l=function(a){a.find(h.EVENT_LIST_CONTENT).removeClass("hidden");a.find(h.EMPTY_MESSAGE).addClass("hidden")},m=function(a){a.find(h.EVENT_LIST_CONTENT).empty()},n=function(a,b){var c={},d={eventsbyday:[]};a.forEach(function(a){var b=a.timeusermidnight;if(c[b]){c[b].push(a)}else{c[b]=[a]}});Object.keys(c).forEach(function(a){var e=c[a];d.eventsbyday.push({past:a<b,dayTimestamp:a,events:e})});return d},o=function(a,b){var d=n(a,b),e=i.EVENT_LIST_CONTENT;return c.render(e,d)},p=function(a,b,c,d,e,f){var h=d!=void 0?a+d*86400:!1,i={starttime:a+c*86400,limit:b};if(e){i.aftereventid=e}if(h){i.endtime=h}if(f){i.courseid=f;return g.queryByCourse(i)}else{return g.queryByTime(i)}},q=function(a,b,c,d,e,g,h,i){var j=a.pageNumber,k=a.limit,l=j;while(!d.hasOwnProperty(l)){l--}var m=d[l],n=null;if(e&&e.hasOwnProperty(j)){n=e[j]}else{n=p(c,k+1,h,i,m,g)}return n.then(function(a){if(!a.events.length){b.allItemsLoaded(j);return[]}var d=a.events.filter(function(a){if("open"==a.eventtype||"opensubmission"==a.eventtype){var b=f.getUserMidnightForTimestamp(a.timesort,c);return b>c}return!0}),e=d.length<=k;if(e){b.allItemsLoaded(j)}else{d.pop()}return d})},r=function(c,f,g,h,i,k,l,m,n){var p={1:0},r=!1,s=a.extend({},j,n);return e.get_string("ariaeventlistpagelimit","block_timeline",a.isArray(c)?c[0].value:c).then(function(a){s.ariaLabels.itemsperpage=a;s.ariaLabels.paginationnav=m;return a}).then(function(){return d.createWithLimit(c,function(c,d){var e=[];c.forEach(function(a){var c=a.pageNumber,h=q(a,d,g,p,f,i,k,l).then(function(a){if(a.length){r=!0;var b=a[a.length-1].id;p[c+1]=b;return o(a,g)}else{return a}}).catch(b.exception);e.push(h)});a.when.apply(a,e).then(function(){h.resolve(r)}).catch(function(){h.resolve(r)});return e},s)})};return{init:function init(d,e,f,g,i){d=a(d);var j=a.Deferred(),n=d.find(h.EVENT_LIST_CONTENT),o=d.find(h.EVENT_LIST_LOADING_PLACEHOLDER),p=d.attr("data-course-id"),q=parseInt(d.attr("data-days-offset"),10),s=d.attr("data-days-limit"),t=parseInt(d.attr("data-midnight"),10);m(d);l(d);o.removeClass("hidden");if(s!=void 0){s=parseInt(s,10)}return r(e,f,t,j,p,q,s,g,i).then(function(b,e){b=a(b);b.addClass("hidden");c.replaceNodeContents(n,b,e);j.then(function(a){b.removeClass("hidden");o.addClass("hidden");if(!a){k(d)}return a}).catch(function(){return!1});return b}).catch(b.exception)},rootSelector:h.ROOT}});
//# sourceMappingURL=event_list.min.js.map

File diff suppressed because one or more lines are too long

View File

@ -132,7 +132,7 @@ function(
};
calendarEvents.forEach(function(calendarEvent) {
var dayTimestamp = UserDate.getUserMidnightForTimestamp(calendarEvent.timesort, midnight);
var dayTimestamp = calendarEvent.timeusermidnight;
if (eventsByDay[dayTimestamp]) {
eventsByDay[dayTimestamp].push(calendarEvent);
} else {

View File

@ -87,6 +87,7 @@ class event_exporter_base extends exporter {
$data->timestart = $starttimestamp;
$data->timeduration = $endtimestamp - $starttimestamp;
$data->timesort = $event->get_times()->get_sort_time()->getTimestamp();
$data->timeusermidnight = $event->get_times()->get_usermidnight_time()->getTimestamp();
$data->visible = $event->is_visible() ? 1 : 0;
$data->timemodified = $event->get_times()->get_modified_time()->getTimestamp();
$data->component = $event->get_component();
@ -183,6 +184,7 @@ class event_exporter_base extends exporter {
'timestart' => ['type' => PARAM_INT],
'timeduration' => ['type' => PARAM_INT],
'timesort' => ['type' => PARAM_INT],
'timeusermidnight' => ['type' => PARAM_INT],
'visible' => ['type' => PARAM_INT],
'timemodified' => ['type' => PARAM_INT],
];

View File

@ -191,7 +191,8 @@ abstract class event_abstract_factory implements event_factory_interface {
(new \DateTimeImmutable())->setTimestamp($dbrow->timestart),
(new \DateTimeImmutable())->setTimestamp($dbrow->timestart + $dbrow->timeduration),
(new \DateTimeImmutable())->setTimestamp($dbrow->timesort ? $dbrow->timesort : $dbrow->timestart),
(new \DateTimeImmutable())->setTimestamp($dbrow->timemodified)
(new \DateTimeImmutable())->setTimestamp($dbrow->timemodified),
(new \DateTimeImmutable())->setTimestamp(usergetmidnight($dbrow->timesort))
),
!empty($dbrow->visible),
$subscription,

View File

@ -136,6 +136,7 @@ class event_mapper implements event_mapper_interface {
'timestart' => $event->get_times()->get_start_time()->getTimestamp(),
'timeduration' => $timeduration,
'timesort' => $event->get_times()->get_sort_time()->getTimestamp(),
'timeusermidnight' => $event->get_times()->get_usermidnight_time()->getTimestamp(),
'visible' => $event->is_visible() ? 1 : 0,
'timemodified' => $event->get_times()->get_modified_time()->getTimestamp(),
'subscriptionid' => $event->get_subscription() ? $event->get_subscription()->get('id') : null,

View File

@ -53,24 +53,32 @@ class event_times implements times_interface {
*/
protected $modified;
/**
* @var \DateTimeImmutable $usermidnight User midnight for the event.
*/
protected $usermidnight;
/**
* Constructor.
*
* @param \DateTimeImmutable $start Event start time.
* @param \DateTimeImmutable $end Event end time.
* @param \DateTimeImmutable $sort Date used to sort events.
* @param \DateTimeImmutable $modified Time event was last updated.
* @param \DateTimeImmutable $start Event start time.
* @param \DateTimeImmutable $end Event end time.
* @param \DateTimeImmutable $sort Date used to sort events.
* @param \DateTimeImmutable $modified Time event was last updated.
* @param \DateTimeImmutable $usermidnight User midnight for the event.
*/
public function __construct(
\DateTimeImmutable $start,
\DateTimeImmutable $end,
\DateTimeImmutable $sort,
\DateTimeImmutable $modified
\DateTimeImmutable $modified,
\DateTimeImmutable $usermidnight
) {
$this->start = $start;
$this->end = $end;
$this->sort = $sort;
$this->modified = $modified;
$this->usermidnight = $usermidnight;
}
public function get_start_time() {
@ -92,4 +100,13 @@ class event_times implements times_interface {
public function get_sort_time() {
return $this->sort;
}
/**
* Getter for usermidnight.
*
* @return \DateTimeImmutable
*/
public function get_usermidnight_time() {
return $this->usermidnight;
}
}

View File

@ -67,4 +67,11 @@ interface times_interface {
* @return \DateTimeImmutable
*/
public function get_modified_time();
/**
* Get the user midnight time.
*
* @return \DateTimeImmutable
*/
public function get_usermidnight_time();
}

View File

@ -178,6 +178,7 @@ define('CALENDAR_EVENT_TYPE_ACTION', 1);
* @property string $eventtype The event type
* @property int $timestart The start time as a timestamp
* @property int $timeduration The duration of the event in seconds
* @property int $timeusermidnight User midnight for the event
* @property int $visible 1 if the event is visible
* @property int $uuid ?
* @property int $sequence ?

View File

@ -367,7 +367,8 @@ class event_mapper_test_event implements event_interface {
(new \DateTimeImmutable())->setTimestamp(-386380800),
(new \DateTimeImmutable())->setTimestamp(115776000),
(new \DateTimeImmutable())->setTimestamp(115776000),
(new \DateTimeImmutable())->setTimestamp(time())
(new \DateTimeImmutable())->setTimestamp(time()),
(new \DateTimeImmutable())->setTimestamp(115776000)
);
}

View File

@ -98,7 +98,8 @@ class core_calendar_event_testcase extends advanced_testcase {
(new \DateTimeImmutable())->setTimestamp(-386380800),
(new \DateTimeImmutable())->setTimestamp(115776000),
(new \DateTimeImmutable())->setTimestamp(115776000),
(new \DateTimeImmutable())->setTimestamp(time())
(new \DateTimeImmutable())->setTimestamp(time()),
(new \DateTimeImmutable())->setTimestamp(115776000)
),
'visible' => true,
'subscription' => new std_proxy(1, $lamecallable),

View File

@ -44,7 +44,8 @@ class core_calendar_event_times_testcase extends advanced_testcase {
$constructorparams['start_time'],
$constructorparams['end_time'],
$constructorparams['sort_time'],
$constructorparams['modified_time']
$constructorparams['modified_time'],
$constructorparams['usermidnight_time']
);
foreach ($constructorparams as $name => $value) {
@ -64,7 +65,8 @@ class core_calendar_event_times_testcase extends advanced_testcase {
'start_time' => (new \DateTimeImmutable())->setTimestamp(-386380800),
'end_time' => (new \DateTimeImmutable())->setTimestamp(115776000),
'sort_time' => (new \DateTimeImmutable())->setTimestamp(115776000),
'modified_time' => (new \DateTimeImmutable())->setTimestamp(time())
'modified_time' => (new \DateTimeImmutable())->setTimestamp(time()),
'usermidnight_time' => (new \DateTimeImmutable())->setTimestamp(115776000),
]
],
'Dataset 2' => [
@ -72,7 +74,8 @@ class core_calendar_event_times_testcase extends advanced_testcase {
'start_time' => (new \DateTimeImmutable())->setTimestamp(123456),
'end_time' => (new \DateTimeImmutable())->setTimestamp(12345678),
'sort_time' => (new \DateTimeImmutable())->setTimestamp(1111),
'modified_time' => (new \DateTimeImmutable())->setTimestamp(time())
'modified_time' => (new \DateTimeImmutable())->setTimestamp(time()),
'usermidnight_time' => (new \DateTimeImmutable())->setTimestamp(1111),
]
]
];

View File

@ -133,7 +133,8 @@ class action_event_test_factory implements event_factory_interface {
(new \DateTimeImmutable())->setTimestamp($record->timestart),
(new \DateTimeImmutable())->setTimestamp($record->timestart + $record->timeduration),
(new \DateTimeImmutable())->setTimestamp($record->timesort ? $record->timesort : $record->timestart),
(new \DateTimeImmutable())->setTimestamp($record->timemodified)
(new \DateTimeImmutable())->setTimestamp($record->timemodified),
(new \DateTimeImmutable())->setTimestamp(usergetmidnight($record->timesort))
),
!empty($record->visible),
$subscription,

View File

@ -201,7 +201,8 @@ class core_calendar_repeat_event_collection_event_test_factory implements event_
(new \DateTimeImmutable())->setTimestamp($dbrow->timestart),
(new \DateTimeImmutable())->setTimestamp($dbrow->timestart + $dbrow->timeduration),
(new \DateTimeImmutable())->setTimestamp($dbrow->timesort ? $dbrow->timesort : $dbrow->timestart),
(new \DateTimeImmutable())->setTimestamp($dbrow->timemodified)
(new \DateTimeImmutable())->setTimestamp($dbrow->timemodified),
(new \DateTimeImmutable())->setTimestamp(usergetmidnight($dbrow->timesort))
),
!empty($dbrow->visible),
new std_proxy($dbrow->subscriptionid, $identity),

View File

@ -1,6 +1,10 @@
This files describes API changes in /calendar/* ,
information provided here is intended especially for developers.
=== 4.0 ===
* The core_calendar\local\event\value_objects\times_interface class now has new method get_usermidnight_time() which
returns the user midnight time for a given event.
=== 3.9 ===
* Plugins can now create their own calendar events, both standard and action ones. To do it they need to specify
$event->component when creating an event. Component events can not be edited or deleted manually.