MDL-63793 block_myoverview: Persist the user's paging limit preference
[moodle.git] / blocks / myoverview / classes / privacy / provider.php
CommitLineData
bcc3f1e8
ZT
1<?php
2// This file is part of Moodle - http://moodle.org/
3//
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17/**
18 * Privacy Subsystem implementation for block_myoverview.
19 *
20 * @package block_myoverview
21 * @copyright 2018 Zig Tan <zig@moodle.com>
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
25namespace block_myoverview\privacy;
26
3cfff885
BB
27use core_privacy\local\request\user_preference_provider;
28use core_privacy\local\metadata\collection;
fd955097 29use \core_privacy\local\request\writer;
3cfff885 30
bcc3f1e8
ZT
31defined('MOODLE_INTERNAL') || die();
32
33/**
5eb8ad87 34 * Privacy Subsystem for block_myoverview.
bcc3f1e8
ZT
35 *
36 * @copyright 2018 Zig Tan <zig@moodle.com>
37 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
38 */
3cfff885 39class provider implements \core_privacy\local\metadata\provider, user_preference_provider {
bcc3f1e8
ZT
40
41 /**
3cfff885 42 * Returns meta-data information about the myoverview block.
bcc3f1e8 43 *
3cfff885
BB
44 * @param \core_privacy\local\metadata\collection $collection A collection of meta-data.
45 * @return \core_privacy\local\metadata\collection Return the collection of meta-data.
bcc3f1e8 46 */
3cfff885
BB
47 public static function get_metadata(collection $collection) : collection {
48 $collection->add_user_preference('block_myoverview_user_sort_preference', 'privacy:metadata:overviewsortpreference');
49 $collection->add_user_preference('block_myoverview_user_view_preference', 'privacy:metadata:overviewviewpreference');
50 $collection->add_user_preference('block_myoverview_user_grouping_preference',
51 'privacy:metadata:overviewgroupingpreference');
11988d74
P
52 $collection->add_user_preference('block_myoverview_user_paging_preference',
53 'privacy:metadata:overviewpagingpreference');
3cfff885
BB
54 return $collection;
55 }
56 /**
57 * Export all user preferences for the myoverview block
58 *
59 * @param int $userid The userid of the user whose data is to be exported.
60 */
61 public static function export_user_preferences(int $userid) {
62 $preference = get_user_preferences('block_myoverview_user_sort_preference', null, $userid);
63 if (isset($preference)) {
fd955097 64 writer::export_user_preference('block_myoverview',
3cfff885
BB
65 'block_myoverview_user_sort_preference', get_string($preference, 'block_myoverview'),
66 get_string('privacy:metadata:overviewsortpreference', 'block_myoverview'));
67 }
68
69 $preference = get_user_preferences('block_myoverview_user_view_preference', null, $userid);
70 if (isset($preference)) {
fd955097 71 writer::export_user_preference('block_myoverview',
3cfff885
BB
72 'block_myoverview_user_view_preference',
73 get_string($preference, 'block_myoverview'),
74 get_string('privacy:metadata:overviewviewpreference', 'block_myoverview'));
75 }
76
77 $preference = get_user_preferences('block_myoverview_user_grouping_preference', null, $userid);
78 if (isset($preference)) {
fd955097 79 writer::export_user_preference('block_myoverview',
3cfff885
BB
80 'block_myoverview_user_grouping_preference',
81 get_string($preference, 'block_myoverview'),
82 get_string('privacy:metadata:overviewgroupingpreference', 'block_myoverview'));
83 }
e6f03948
P
84
85 $preferences = get_user_preferences(null, null, $userid);
86 foreach ($preferences as $name => $value) {
87 if ((substr($name, 0, 30) == 'block_myoverview_hidden_course')) {
88 writer::export_user_preference(
89 'block_myoverview',
90 $name,
91 $value,
92 get_string('privacy:request:preference:set', 'block_myoverview', (object) [
93 'name' => $name,
94 'value' => $value,
95 ])
96 );
97 }
98 }
11988d74
P
99
100 $preference = get_user_preferences('block_myoverview_user_paging_preference', null, $userid);
101 if (isset($preference)) {
102 \core_privacy\local\request\writer::export_user_preference('block_myoverview',
103 'block_myoverview_user_paging_preference',
104 $preference,
105 get_string('privacy:metadata:overviewpagingpreference', 'block_myoverview'));
106 }
bcc3f1e8 107 }
3cfff885 108}