2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * Library functions for overview.
20 * @package block_myoverview
21 * @copyright 2018 Peter Dias
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 defined('MOODLE_INTERNAL') ||
die();
28 * Constants for the user preferences grouping options
30 define('BLOCK_MYOVERVIEW_GROUPING_ALLINCLUDINGHIDDEN', 'allincludinghidden');
31 define('BLOCK_MYOVERVIEW_GROUPING_ALL', 'all');
32 define('BLOCK_MYOVERVIEW_GROUPING_INPROGRESS', 'inprogress');
33 define('BLOCK_MYOVERVIEW_GROUPING_FUTURE', 'future');
34 define('BLOCK_MYOVERVIEW_GROUPING_PAST', 'past');
35 define('BLOCK_MYOVERVIEW_GROUPING_FAVOURITES', 'favourites');
36 define('BLOCK_MYOVERVIEW_GROUPING_HIDDEN', 'hidden');
37 define('BLOCK_MYOVERVIEW_GROUPING_CUSTOMFIELD', 'customfield');
40 * Allows selection of all courses without a value for the custom field.
42 define('BLOCK_MYOVERVIEW_CUSTOMFIELD_EMPTY', -1);
45 * Constants for the user preferences sorting options
48 define('BLOCK_MYOVERVIEW_SORTING_TITLE', 'title');
49 define('BLOCK_MYOVERVIEW_SORTING_LASTACCESSED', 'lastaccessed');
50 define('BLOCK_MYOVERVIEW_SORTING_SHORTNAME', 'shortname');
53 * Constants for the user preferences view options
55 define('BLOCK_MYOVERVIEW_VIEW_CARD', 'card');
56 define('BLOCK_MYOVERVIEW_VIEW_LIST', 'list');
57 define('BLOCK_MYOVERVIEW_VIEW_SUMMARY', 'summary');
60 * Constants for the user paging preferences
62 define('BLOCK_MYOVERVIEW_PAGING_12', 12);
63 define('BLOCK_MYOVERVIEW_PAGING_24', 24);
64 define('BLOCK_MYOVERVIEW_PAGING_48', 48);
65 define('BLOCK_MYOVERVIEW_PAGING_96', 96);
66 define('BLOCK_MYOVERVIEW_PAGING_ALL', 0);
69 * Constants for the admin category display setting
71 define('BLOCK_MYOVERVIEW_DISPLAY_CATEGORIES_ON', 'on');
72 define('BLOCK_MYOVERVIEW_DISPLAY_CATEGORIES_OFF', 'off');
75 * Get the current user preferences that are available
77 * @uses core_user::is_current_user
79 * @return array[] Array representing current options along with defaults
81 function block_myoverview_user_preferences(): array {
82 $preferences['block_myoverview_user_grouping_preference'] = array(
83 'null' => NULL_NOT_ALLOWED
,
84 'default' => BLOCK_MYOVERVIEW_GROUPING_ALL
,
85 'type' => PARAM_ALPHA
,
87 BLOCK_MYOVERVIEW_GROUPING_ALLINCLUDINGHIDDEN
,
88 BLOCK_MYOVERVIEW_GROUPING_ALL
,
89 BLOCK_MYOVERVIEW_GROUPING_INPROGRESS
,
90 BLOCK_MYOVERVIEW_GROUPING_FUTURE
,
91 BLOCK_MYOVERVIEW_GROUPING_PAST
,
92 BLOCK_MYOVERVIEW_GROUPING_FAVOURITES
,
93 BLOCK_MYOVERVIEW_GROUPING_HIDDEN
,
94 BLOCK_MYOVERVIEW_GROUPING_CUSTOMFIELD
,
96 'permissioncallback' => [core_user
::class, 'is_current_user'],
99 $preferences['block_myoverview_user_grouping_customfieldvalue_preference'] = [
100 'null' => NULL_ALLOWED
,
103 'permissioncallback' => [core_user
::class, 'is_current_user'],
106 $preferences['block_myoverview_user_sort_preference'] = array(
107 'null' => NULL_NOT_ALLOWED
,
108 'default' => BLOCK_MYOVERVIEW_SORTING_LASTACCESSED
,
109 'type' => PARAM_ALPHA
,
111 BLOCK_MYOVERVIEW_SORTING_TITLE
,
112 BLOCK_MYOVERVIEW_SORTING_LASTACCESSED
,
113 BLOCK_MYOVERVIEW_SORTING_SHORTNAME
115 'permissioncallback' => [core_user
::class, 'is_current_user'],
118 $preferences['block_myoverview_user_view_preference'] = array(
119 'null' => NULL_NOT_ALLOWED
,
120 'default' => BLOCK_MYOVERVIEW_VIEW_CARD
,
121 'type' => PARAM_ALPHA
,
123 BLOCK_MYOVERVIEW_VIEW_CARD
,
124 BLOCK_MYOVERVIEW_VIEW_LIST
,
125 BLOCK_MYOVERVIEW_VIEW_SUMMARY
127 'permissioncallback' => [core_user
::class, 'is_current_user'],
130 $preferences['/^block_myoverview_hidden_course_(\d)+$/'] = array(
132 'choices' => array(0, 1),
134 'null' => NULL_NOT_ALLOWED
,
136 'permissioncallback' => [core_user
::class, 'is_current_user'],
139 $preferences['block_myoverview_user_paging_preference'] = array(
140 'null' => NULL_NOT_ALLOWED
,
141 'default' => BLOCK_MYOVERVIEW_PAGING_12
,
144 BLOCK_MYOVERVIEW_PAGING_12
,
145 BLOCK_MYOVERVIEW_PAGING_24
,
146 BLOCK_MYOVERVIEW_PAGING_48
,
147 BLOCK_MYOVERVIEW_PAGING_96
,
148 BLOCK_MYOVERVIEW_PAGING_ALL
150 'permissioncallback' => [core_user
::class, 'is_current_user'],
157 * Pre-delete course hook to cleanup any records with references to the deleted course.
159 * @param stdClass $course The deleted course
161 function block_myoverview_pre_course_delete(\stdClass
$course) {
162 // Removing any favourited courses which have been created for users, for this course.
163 $service = \core_favourites\service_factory
::get_service_for_component('core_course');
164 $service->delete_favourites_by_type_and_item('courses', $course->id
);