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 * @return mixed Array representing current options along with defaults
79 function block_myoverview_user_preferences() {
80 $preferences['block_myoverview_user_grouping_preference'] = array(
81 'null' => NULL_NOT_ALLOWED
,
82 'default' => BLOCK_MYOVERVIEW_GROUPING_ALL
,
83 'type' => PARAM_ALPHA
,
85 BLOCK_MYOVERVIEW_GROUPING_ALLINCLUDINGHIDDEN
,
86 BLOCK_MYOVERVIEW_GROUPING_ALL
,
87 BLOCK_MYOVERVIEW_GROUPING_INPROGRESS
,
88 BLOCK_MYOVERVIEW_GROUPING_FUTURE
,
89 BLOCK_MYOVERVIEW_GROUPING_PAST
,
90 BLOCK_MYOVERVIEW_GROUPING_FAVOURITES
,
91 BLOCK_MYOVERVIEW_GROUPING_HIDDEN
,
92 BLOCK_MYOVERVIEW_GROUPING_CUSTOMFIELD
,
96 $preferences['block_myoverview_user_grouping_customfieldvalue_preference'] = [
97 'null' => NULL_ALLOWED
,
102 $preferences['block_myoverview_user_sort_preference'] = array(
103 'null' => NULL_NOT_ALLOWED
,
104 'default' => BLOCK_MYOVERVIEW_SORTING_LASTACCESSED
,
105 'type' => PARAM_ALPHA
,
107 BLOCK_MYOVERVIEW_SORTING_TITLE
,
108 BLOCK_MYOVERVIEW_SORTING_LASTACCESSED
,
109 BLOCK_MYOVERVIEW_SORTING_SHORTNAME
112 $preferences['block_myoverview_user_view_preference'] = array(
113 'null' => NULL_NOT_ALLOWED
,
114 'default' => BLOCK_MYOVERVIEW_VIEW_CARD
,
115 'type' => PARAM_ALPHA
,
117 BLOCK_MYOVERVIEW_VIEW_CARD
,
118 BLOCK_MYOVERVIEW_VIEW_LIST
,
119 BLOCK_MYOVERVIEW_VIEW_SUMMARY
123 $preferences['/^block_myoverview_hidden_course_(\d)+$/'] = array(
125 'choices' => array(0, 1),
127 'null' => NULL_NOT_ALLOWED
,
131 $preferences['block_myoverview_user_paging_preference'] = array(
132 'null' => NULL_NOT_ALLOWED
,
133 'default' => BLOCK_MYOVERVIEW_PAGING_12
,
136 BLOCK_MYOVERVIEW_PAGING_12
,
137 BLOCK_MYOVERVIEW_PAGING_24
,
138 BLOCK_MYOVERVIEW_PAGING_48
,
139 BLOCK_MYOVERVIEW_PAGING_96
,
140 BLOCK_MYOVERVIEW_PAGING_ALL
148 * Pre-delete course hook to cleanup any records with references to the deleted course.
150 * @param stdClass $course The deleted course
152 function block_myoverview_pre_course_delete(\stdClass
$course) {
153 // Removing any favourited courses which have been created for users, for this course.
154 $service = \core_favourites\service_factory
::get_service_for_component('core_course');
155 $service->delete_favourites_by_type_and_item('courses', $course->id
);