Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1 efrain 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
 
25
defined('MOODLE_INTERNAL') || die();
26
 
27
/**
28
 * Constants for the user preferences grouping options
29
 */
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');
38
 
39
/**
40
 * Allows selection of all courses without a value for the custom field.
41
 */
42
define('BLOCK_MYOVERVIEW_CUSTOMFIELD_EMPTY', -1);
43
 
44
/**
45
 * Constants for the user preferences sorting options
46
 * timeline
47
 */
48
define('BLOCK_MYOVERVIEW_SORTING_TITLE', 'title');
49
define('BLOCK_MYOVERVIEW_SORTING_LASTACCESSED', 'lastaccessed');
50
define('BLOCK_MYOVERVIEW_SORTING_SHORTNAME', 'shortname');
51
 
52
/**
53
 * Constants for the user preferences view options
54
 */
55
define('BLOCK_MYOVERVIEW_VIEW_CARD', 'card');
56
define('BLOCK_MYOVERVIEW_VIEW_LIST', 'list');
57
define('BLOCK_MYOVERVIEW_VIEW_SUMMARY', 'summary');
58
 
59
/**
60
 * Constants for the user paging preferences
61
 */
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);
67
 
68
/**
69
 * Constants for the admin category display setting
70
 */
71
define('BLOCK_MYOVERVIEW_DISPLAY_CATEGORIES_ON', 'on');
72
define('BLOCK_MYOVERVIEW_DISPLAY_CATEGORIES_OFF', 'off');
73
 
74
/**
75
 * Get the current user preferences that are available
76
 *
77
 * @uses core_user::is_current_user
78
 *
79
 * @return array[] Array representing current options along with defaults
80
 */
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,
95
        ),
96
        'permissioncallback' => [core_user::class, 'is_current_user'],
97
    );
98
 
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'],
104
    ];
105
 
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
114
        ),
115
        'permissioncallback' => [core_user::class, 'is_current_user'],
116
    );
117
 
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
126
        ),
127
        'permissioncallback' => [core_user::class, 'is_current_user'],
128
    );
129
 
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'],
137
    );
138
 
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
149
        ),
150
        'permissioncallback' => [core_user::class, 'is_current_user'],
151
    );
152
 
153
    return $preferences;
154
}
155
 
156
/**
157
 * Pre-delete course hook to cleanup any records with references to the deleted course.
158
 *
159
 * @param stdClass $course The deleted course
160
 */
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);
165
}