MDL-64901 block_myoverview: admin settings to control available layouts
[moodle.git] / blocks / myoverview / lib.php
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/>.
17 /**
18  * Library functions for overview.
19  *
20  * @package   block_myoverview
21  * @copyright 2018 Peter Dias
22  * @license   http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23  */
25 defined('MOODLE_INTERNAL') || die();
27 /**
28  * Constants for the user preferences grouping options
29  */
30 define('BLOCK_MYOVERVIEW_GROUPING_ALL', 'all');
31 define('BLOCK_MYOVERVIEW_GROUPING_INPROGRESS', 'inprogress');
32 define('BLOCK_MYOVERVIEW_GROUPING_FUTURE', 'future');
33 define('BLOCK_MYOVERVIEW_GROUPING_PAST', 'past');
34 define('BLOCK_MYOVERVIEW_GROUPING_FAVOURITES', 'favourites');
35 define('BLOCK_MYOVERVIEW_GROUPING_HIDDEN', 'hidden');
37 /**
38  * Constants for the user preferences sorting options
39  * timeline
40  */
41 define('BLOCK_MYOVERVIEW_SORTING_TITLE', 'title');
42 define('BLOCK_MYOVERVIEW_SORTING_LASTACCESSED', 'lastaccessed');
44 /**
45  * Constants for the user preferences view options
46  */
47 define('BLOCK_MYOVERVIEW_VIEW_CARD', 'card');
48 define('BLOCK_MYOVERVIEW_VIEW_LIST', 'list');
49 define('BLOCK_MYOVERVIEW_VIEW_SUMMARY', 'summary');
51 /**
52  * Constants for the user paging preferences
53  */
54 define('BLOCK_MYOVERVIEW_PAGING_12', 12);
55 define('BLOCK_MYOVERVIEW_PAGING_24', 24);
56 define('BLOCK_MYOVERVIEW_PAGING_48', 48);
58 /**
59  * Constants for the admin category display setting
60  */
61 define('BLOCK_MYOVERVIEW_DISPLAY_CATEGORIES_ON', 'on');
62 define('BLOCK_MYOVERVIEW_DISPLAY_CATEGORIES_OFF', 'off');
64 /**
65  * Get the current user preferences that are available
66  *
67  * @return mixed Array representing current options along with defaults
68  */
69 function block_myoverview_user_preferences() {
70     $preferences['block_myoverview_user_grouping_preference'] = array(
71         'null' => NULL_NOT_ALLOWED,
72         'default' => BLOCK_MYOVERVIEW_GROUPING_ALL,
73         'type' => PARAM_ALPHA,
74         'choices' => array(
75             BLOCK_MYOVERVIEW_GROUPING_ALL,
76             BLOCK_MYOVERVIEW_GROUPING_INPROGRESS,
77             BLOCK_MYOVERVIEW_GROUPING_FUTURE,
78             BLOCK_MYOVERVIEW_GROUPING_PAST,
79             BLOCK_MYOVERVIEW_GROUPING_FAVOURITES,
80             BLOCK_MYOVERVIEW_GROUPING_HIDDEN
81         )
82     );
83     $preferences['block_myoverview_user_sort_preference'] = array(
84         'null' => NULL_NOT_ALLOWED,
85         'default' => BLOCK_MYOVERVIEW_SORTING_TITLE,
86         'type' => PARAM_ALPHA,
87         'choices' => array(
88             BLOCK_MYOVERVIEW_SORTING_TITLE,
89             BLOCK_MYOVERVIEW_SORTING_LASTACCESSED
90         )
91     );
92     $preferences['block_myoverview_user_view_preference'] = array(
93         'null' => NULL_NOT_ALLOWED,
94         'default' => BLOCK_MYOVERVIEW_VIEW_CARD,
95         'type' => PARAM_ALPHA,
96         'choices' => array(
97             BLOCK_MYOVERVIEW_VIEW_CARD,
98             BLOCK_MYOVERVIEW_VIEW_LIST,
99             BLOCK_MYOVERVIEW_VIEW_SUMMARY
100         )
101     );
103     $preferences['/^block_myoverview_hidden_course_(\d)+$/'] = array(
104         'isregex' => true,
105         'choices' => array(0, 1),
106         'type' => PARAM_INT,
107         'null' => NULL_NOT_ALLOWED,
108         'default' => 'none'
109     );
111     $preferences['block_myoverview_user_paging_preference'] = array(
112         'null' => NULL_NOT_ALLOWED,
113         'default' => BLOCK_MYOVERVIEW_PAGING_12,
114         'type' => PARAM_INT,
115         'choices' => array(
116             BLOCK_MYOVERVIEW_PAGING_12,
117             BLOCK_MYOVERVIEW_PAGING_24,
118             BLOCK_MYOVERVIEW_PAGING_48
119         )
120     );
122     return $preferences;