MDL-70829 block_myoverview: Mark up decorative image properly
[moodle.git] / blocks / myoverview / lib.php
blob4dd7a1aa446d3d482b6f73cde6704a771207b2ee
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.
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.
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();
27 /**
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');
39 /**
40 * Allows selection of all courses without a value for the custom field.
42 define('BLOCK_MYOVERVIEW_CUSTOMFIELD_EMPTY', -1);
44 /**
45 * Constants for the user preferences sorting options
46 * timeline
48 define('BLOCK_MYOVERVIEW_SORTING_TITLE', 'title');
49 define('BLOCK_MYOVERVIEW_SORTING_LASTACCESSED', 'lastaccessed');
50 define('BLOCK_MYOVERVIEW_SORTING_SHORTNAME', 'shortname');
52 /**
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');
59 /**
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);
68 /**
69 * Constants for the admin category display setting
71 define('BLOCK_MYOVERVIEW_DISPLAY_CATEGORIES_ON', 'on');
72 define('BLOCK_MYOVERVIEW_DISPLAY_CATEGORIES_OFF', 'off');
74 /**
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,
86 'choices' => array(
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,
101 'default' => null,
102 'type' => PARAM_RAW,
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,
110 'choices' => array(
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,
122 'choices' => array(
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(
131 'isregex' => true,
132 'choices' => array(0, 1),
133 'type' => PARAM_INT,
134 'null' => NULL_NOT_ALLOWED,
135 'default' => 0,
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,
142 'type' => PARAM_INT,
143 'choices' => array(
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'],
153 return $preferences;
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);