3244e4cbe7003f02321a0c59daf15270f769d4de
[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', 'cards');
48 define('BLOCK_MYOVERVIEW_VIEW_LIST', 'list');
49 define('BLOCK_MYOVERVIEW_VIEW_SUMMARY', 'summary');
51 /**
52  * Get the current user preferences that are available
53  *
54  * @return mixed Array representing current options along with defaults
55  */
56 function block_myoverview_user_preferences() {
57     $preferences['block_myoverview_user_grouping_preference'] = array(
58         'null' => NULL_NOT_ALLOWED,
59         'default' => BLOCK_MYOVERVIEW_GROUPING_ALL,
60         'type' => PARAM_ALPHA,
61         'choices' => array(
62             BLOCK_MYOVERVIEW_GROUPING_ALL,
63             BLOCK_MYOVERVIEW_GROUPING_INPROGRESS,
64             BLOCK_MYOVERVIEW_GROUPING_FUTURE,
65             BLOCK_MYOVERVIEW_GROUPING_PAST,
66             BLOCK_MYOVERVIEW_GROUPING_FAVOURITES,
67             BLOCK_MYOVERVIEW_GROUPING_HIDDEN
68         )
69     );
70     $preferences['block_myoverview_user_sort_preference'] = array(
71         'null' => NULL_NOT_ALLOWED,
72         'default' => BLOCK_MYOVERVIEW_SORTING_TITLE,
73         'type' => PARAM_ALPHA,
74         'choices' => array(
75             BLOCK_MYOVERVIEW_SORTING_TITLE,
76             BLOCK_MYOVERVIEW_SORTING_LASTACCESSED
77         )
78     );
79     $preferences['block_myoverview_user_view_preference'] = array(
80         'null' => NULL_NOT_ALLOWED,
81         'default' => BLOCK_MYOVERVIEW_VIEW_CARD,
82         'type' => PARAM_ALPHA,
83         'choices' => array(
84             BLOCK_MYOVERVIEW_VIEW_CARD,
85             BLOCK_MYOVERVIEW_VIEW_LIST,
86             BLOCK_MYOVERVIEW_VIEW_SUMMARY
87         )
88     );
90     $preferences['/^block_myoverview_hidden_course_(\d)+$/'] = array(
91         'isregex' => true,
92         'choices' => array(0, 1),
93         'type' => PARAM_INT,
94         'null' => NULL_NOT_ALLOWED,
95         'default' => 'none'
96     );
98     return $preferences;
99 }