-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlocallib.php
76 lines (68 loc) · 2.57 KB
/
locallib.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* Internal library of functions for the townsquaresupport plugin
*
* @package local_townsquaresupport
* @copyright 2024 Tamaro Walter
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
namespace local_townsquaresupport;
/**
* Helper function for townsquaresupport_get_subplugin_events, that checks if an amount
* of events have all the required attributes from the townsquaresupport interface.
*
* @param array $subevents
* @return bool
*/
function townsquaresupport_check_subplugin_events($subevents): bool {
if (!gettype($subevents == 'array')) {
return false;
}
if ($subevents == []) {
// If no events are available, then everything is okay.
return true;
} else {
// Check every event.
foreach ($subevents as $event) {
if (gettype($event) != 'object') {
return false;
}
// Check if all variables are set.
$issetcheck = townsquaresupport_check_isset($event, 'courseid') &&
townsquaresupport_check_isset($event, 'modulename') &&
townsquaresupport_check_isset($event, 'instancename') &&
townsquaresupport_check_isset($event, 'content') &&
townsquaresupport_check_isset($event, 'timestart') &&
townsquaresupport_check_isset($event, 'coursemoduleid') &&
townsquaresupport_check_isset($event, 'eventtype');
if (!$issetcheck) {
return false;
}
}
}
return true;
}
/**
* Helper function for check_subplugin_events function that proves if a variable is set in an array.
*
* @param array $event Event that is checked.
* @param string $variablename Name of the variable
* @return bool
*/
function townsquaresupport_check_isset($event, $variablename): bool {
return isset($event->$variablename);
}