diff --git a/blocks/timeline/amd/build/event_list.min.js b/blocks/timeline/amd/build/event_list.min.js index cd209c581a0..025c5963364 100644 --- a/blocks/timeline/amd/build/event_list.min.js +++ b/blocks/timeline/amd/build/event_list.min.js @@ -1 +1 @@ -define(["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=86400,i={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"]'},j={EVENT_LIST_CONTENT:"block_timeline/event-list-content"},k={ignoreControlWhileLoading:!0,controlPlacementBottom:!0,ariaLabels:{itemsperpagecomponents:"ariaeventlistpagelimit, block_timeline"}},l=function(a){a.find(i.EVENT_LIST_CONTENT).addClass("hidden"),a.find(i.EMPTY_MESSAGE).removeClass("hidden")},m=function(a){a.find(i.EVENT_LIST_CONTENT).removeClass("hidden"),a.find(i.EMPTY_MESSAGE).addClass("hidden")},n=function(a){a.find(i.EVENT_LIST_CONTENT).empty()},o=function(a,b){var c={},d={eventsbyday:[]};return a.forEach(function(a){var d=f.getUserMidnightForTimestamp(a.timesort,b);c[d]?c[d].push(a):c[d]=[a]}),Object.keys(c).forEach(function(a){var e=c[a];d.eventsbyday.push({past:apage->get_renderer('block_timeline'); $this->content = (object) [ diff --git a/blocks/timeline/classes/output/main.php b/blocks/timeline/classes/output/main.php index 218eb46f194..bb741b408e4 100644 --- a/blocks/timeline/classes/output/main.php +++ b/blocks/timeline/classes/output/main.php @@ -54,15 +54,22 @@ class main implements renderable, templatable { */ public $order; + /** + * @var string The current limit preference + */ + public $limit; + /** * main constructor. * * @param string $order Constant sort value from ../timeline/lib.php - * @param string $filter Constant sort value from ../timeline/lib.php + * @param string $filter Constant filter value from ../timeline/lib.php + * @param string $limit Constant limit value from ../timeline/lib.php */ - public function __construct($order, $filter) { + public function __construct($order, $filter, $limit) { $this->order = $order ? $order : BLOCK_TIMELINE_SORT_BY_DATES; $this->filter = $filter ? $filter : BLOCK_TIMELINE_FILTER_BY_7_DAYS; + $this->limit = $limit ? $limit : BLOCK_TIMELINE_LIMIT_DEFAULT; } /** @@ -165,6 +172,7 @@ class main implements renderable, templatable { 'hasdaysoffset' => true, 'hasdayslimit' => $offsets['dayslimit'] !== false , 'nodayslimit' => $offsets['dayslimit'] === false , + 'limit' => $this->limit ]; return array_merge($contextvariables, $filters, $offsets); } diff --git a/blocks/timeline/classes/privacy/provider.php b/blocks/timeline/classes/privacy/provider.php index 3be099871b1..ed1df85bd13 100644 --- a/blocks/timeline/classes/privacy/provider.php +++ b/blocks/timeline/classes/privacy/provider.php @@ -44,6 +44,7 @@ class provider implements \core_privacy\local\metadata\provider, \core_privacy\l public static function get_metadata(collection $collection) : collection { $collection->add_user_preference('block_timeline_user_sort_preference', 'privacy:metadata:timelinesortpreference'); $collection->add_user_preference('block_timeline_user_filter_preference', 'privacy:metadata:timelinefilterpreference'); + $collection->add_user_preference('block_timeline_user_limit_preference', 'privacy:metadata:timelinelimitpreference'); return $collection; } @@ -68,5 +69,13 @@ class provider implements \core_privacy\local\metadata\provider, \core_privacy\l get_string('privacy:metadata:timelinefilterpreference', 'block_timeline') ); } + + $preference = get_user_preferences('block_timeline_user_limit_preference', null, $userid); + if (isset($preference)) { + \core_privacy\local\request\writer::export_user_preference('block_timeline', 'block_timeline_user_limit_preference', + $preference, + get_string('privacy:metadata:timelinelimitpreference', 'block_timeline') + ); + } } } diff --git a/blocks/timeline/lang/en/block_timeline.php b/blocks/timeline/lang/en/block_timeline.php index 12dae0d56c9..b45d3ff1d2b 100644 --- a/blocks/timeline/lang/en/block_timeline.php +++ b/blocks/timeline/lang/en/block_timeline.php @@ -49,3 +49,4 @@ $string['timeline'] = 'Timeline'; $string['viewcourse'] = 'View course'; $string['privacy:metadata:timelinesortpreference'] = 'The user sort preference for the timeline block.'; $string['privacy:metadata:timelinefilterpreference'] = 'The user day filter preference for the timeline block.'; +$string['privacy:metadata:timelinelimitpreference'] = 'The user page limit preference for the timeline block.'; diff --git a/blocks/timeline/lib.php b/blocks/timeline/lib.php index 26e8783f02a..adf9083a73a 100644 --- a/blocks/timeline/lib.php +++ b/blocks/timeline/lib.php @@ -38,6 +38,7 @@ define('BLOCK_TIMELINE_FILTER_BY_7_DAYS', 'next7days'); define('BLOCK_TIMELINE_FILTER_BY_30_DAYS', 'next30days'); define('BLOCK_TIMELINE_FILTER_BY_3_MONTHS', 'next3months'); define('BLOCK_TIMELINE_FILTER_BY_6_MONTHS', 'next6months'); +define('BLOCK_TIMELINE_LIMIT_DEFAULT', 2); /** * Returns the name of the user preferences as well as the details this plugin uses. @@ -66,5 +67,11 @@ function block_timeline_user_preferences() { ) ); + $preferences['block_timeline_user_limit_preference'] = array( + 'null' => NULL_NOT_ALLOWED, + 'default' => BLOCK_TIMELINE_LIMIT_DEFAULT, + 'type' => PARAM_INT + ); + return $preferences; } diff --git a/blocks/timeline/templates/view.mustache b/blocks/timeline/templates/view.mustache index acb5f7815f1..ce96132255d 100644 --- a/blocks/timeline/templates/view.mustache +++ b/blocks/timeline/templates/view.mustache @@ -42,12 +42,13 @@ "next3months": false, "next6months": false, "daysoffset": -14, - "dayslimit": false + "dayslimit": false, + "limit": 0 } }}
-
+
{{> block_timeline/view-dates }}
resetAfterTest(); - $user = $this->getDataGenerator()->create_user(); - set_user_preference('block_timeline_user_sort_preference', 'sortbydates', $user); - + set_user_preference($type, $value, $user); provider::export_user_preferences($user->id); $writer = writer::with_context(\context_system::instance()); $blockpreferences = $writer->get_user_preferences('block_timeline'); - $this->assertEquals('Sort by dates', $blockpreferences->block_timeline_user_sort_preference->value); + if (!$expected) { + $expected = get_string($value, 'block_timeline'); + } + $this->assertEquals($expected, $blockpreferences->{$type}->value); } /** - * Test that the preference timeline is exported properly. + * Create an array of valid user preferences for the timeline block. + * + * @return array Array of valid user preferences. */ - public function test_export_user_preferences_course_sort_preference() { - $this->resetAfterTest(); - - $user = $this->getDataGenerator()->create_user(); - set_user_preference('block_timeline_user_sort_preference', 'sortbycourses', $user); - - provider::export_user_preferences($user->id); - $writer = writer::with_context(\context_system::instance()); - $blockpreferences = $writer->get_user_preferences('block_timeline'); - $this->assertEquals('Sort by courses', $blockpreferences->block_timeline_user_sort_preference->value); - } - - /** - * Test that the preference timeline is exported properly. - */ - public function test_export_user_preferences_7day_filter_preference() { - $this->resetAfterTest(); - - $user = $this->getDataGenerator()->create_user(); - set_user_preference('block_timeline_user_filter_preference', 'next7days', $user); - - provider::export_user_preferences($user->id); - $writer = writer::with_context(\context_system::instance()); - $blockpreferences = $writer->get_user_preferences('block_timeline'); - $this->assertEquals('Next 7 days', $blockpreferences->block_timeline_user_filter_preference->value); - } - - /** - * Test that the preference timeline is exported properly. - */ - public function test_export_user_preferences_all_filter_preference() { - $this->resetAfterTest(); - - $user = $this->getDataGenerator()->create_user(); - set_user_preference('block_timeline_user_filter_preference', 'all', $user); - - provider::export_user_preferences($user->id); - $writer = writer::with_context(\context_system::instance()); - $blockpreferences = $writer->get_user_preferences('block_timeline'); - $this->assertEquals('All', $blockpreferences->block_timeline_user_filter_preference->value); + public function user_preference_provider() { + return array( + array('block_timeline_user_sort_preference', 'sortbydates', ''), + array('block_timeline_user_sort_preference', 'sortbycourses', ''), + array('block_timeline_user_sort_preference', 'next7days', ''), + array('block_timeline_user_sort_preference', 'all', ''), + array('block_timeline_user_limit_preference', 5, 5), + ); } }