MDL-64901 block_myoverview: admin settings to control available layouts
[moodle.git] / blocks / myoverview / lib.php
CommitLineData
3cfff885
BB
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 * 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 */
24
25defined('MOODLE_INTERNAL') || die();
26
27/**
28 * Constants for the user preferences grouping options
29 */
30define('BLOCK_MYOVERVIEW_GROUPING_ALL', 'all');
31define('BLOCK_MYOVERVIEW_GROUPING_INPROGRESS', 'inprogress');
32define('BLOCK_MYOVERVIEW_GROUPING_FUTURE', 'future');
33define('BLOCK_MYOVERVIEW_GROUPING_PAST', 'past');
34define('BLOCK_MYOVERVIEW_GROUPING_FAVOURITES', 'favourites');
e6f03948 35define('BLOCK_MYOVERVIEW_GROUPING_HIDDEN', 'hidden');
3cfff885
BB
36
37/**
38 * Constants for the user preferences sorting options
39 * timeline
40 */
41define('BLOCK_MYOVERVIEW_SORTING_TITLE', 'title');
42define('BLOCK_MYOVERVIEW_SORTING_LASTACCESSED', 'lastaccessed');
43
44/**
45 * Constants for the user preferences view options
46 */
5f59a4c0 47define('BLOCK_MYOVERVIEW_VIEW_CARD', 'card');
3cfff885
BB
48define('BLOCK_MYOVERVIEW_VIEW_LIST', 'list');
49define('BLOCK_MYOVERVIEW_VIEW_SUMMARY', 'summary');
50
11988d74
P
51/**
52 * Constants for the user paging preferences
53 */
54define('BLOCK_MYOVERVIEW_PAGING_12', 12);
55define('BLOCK_MYOVERVIEW_PAGING_24', 24);
56define('BLOCK_MYOVERVIEW_PAGING_48', 48);
57
5ae4db88
TD
58/**
59 * Constants for the admin category display setting
60 */
61define('BLOCK_MYOVERVIEW_DISPLAY_CATEGORIES_ON', 'on');
62define('BLOCK_MYOVERVIEW_DISPLAY_CATEGORIES_OFF', 'off');
63
3cfff885
BB
64/**
65 * Get the current user preferences that are available
66 *
67 * @return mixed Array representing current options along with defaults
68 */
69function 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,
e6f03948
P
79 BLOCK_MYOVERVIEW_GROUPING_FAVOURITES,
80 BLOCK_MYOVERVIEW_GROUPING_HIDDEN
3cfff885
BB
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 );
e6f03948
P
102
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 );
110
11988d74
P
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 );
121
3cfff885 122 return $preferences;
e6f03948 123}