-
Notifications
You must be signed in to change notification settings - Fork 3
/
xlib.php
206 lines (163 loc) · 5.49 KB
/
xlib.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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
<?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/>.
/**
* xlib.php is a cross-components library for functions that are required
* from elsewhere in Moodle and not part of the standard Core API
*
* @package mod_customlabel
* @category mod
* @author Valery Fremaux <valery.fremaux@gmail.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL
* @copyright (C) 1999 onwards Martin Dougiamas http://dougiamas.com
*/
defined('MOODLE_INTERNAL') || die();
require_once($CFG->dirroot.'/mod/customlabel/locallib.php');
/**
* this function for use in theme_xxx_process_css() function in coordination with a
* [[customlabel|overrides]] tag placed into any stylesheet of the theme.
*/
function theme_set_customlabelcss($css) {
$tag = '[[customlabel:overrides]]';
$config = get_config('mod_customlabel');
$replacement = @$config->cssoverrides;
$css = str_replace($tag, $replacement, $css);
return $css;
}
function customlabel_get_authors($courseid) {
global $DB;
$params = ['course' => $courseid, 'labelclass' => 'authordata'];
$potcls = $DB->get_records('customlabel', $params, 'id');
if (!$potcls) {
return;
}
// At the moment take the first that comes.
$cl = array_shift($potcls);
$instance = customlabel_load_class($cl);
return $instance;
}
function customlabel_get_courseheading($courseid) {
global $DB;
$params = ['course' => $courseid, 'labelclass' => 'courseheading'];
$potcls = $DB->get_records('customlabel', $params, 'id');
if (!$potcls) {
return;
}
// At the moment take the first that comes.
$cl = array_shift($potcls);
$instance = customlabel_load_class($cl);
return $instance;
}
function customlabel_get_all_classifiers($courseid) {
global $DB;
$params = ['course' => $courseid, 'labelclass' => 'courseclassifier'];
$potcls = $DB->get_records('customlabel', $params, 'id');
return $potcls;
}
function customlabel_get_classifiers($courseid) {
global $DB;
$params = ['course' => $courseid, 'labelclass' => 'courseclassifier'];
$potcls = $DB->get_records('customlabel', $params, 'id');
if (!$potcls) {
return;
}
// At the moment take the first that comes.
$cl = array_shift($potcls);
$instance = customlabel_load_class($cl);
return $instance;
}
function customlabel_get_coursedata($courseid) {
global $DB;
$params = ['course' => $courseid, 'labelclass' => 'coursedata'];
$potcls = $DB->get_records('customlabel', $params, 'id');
if (!$potcls) {
return;
}
// At the moment take the first that comes.
$cl = array_shift($potcls);
$instance = customlabel_load_class($cl);
return $instance;
}
function customlabel_get_requestcontact($courseid) {
global $DB;
$params = ['course' => $courseid, 'labelclass' => 'requestcontact'];
$potrq = $DB->get_records('customlabel', $params, 'id');
if (!$potrq) {
return;
}
// At the moment take the first that comes.
$cl = array_shift($potrq);
$instance = customlabel_load_class($cl);
return $instance;
}
/**
* Finds a customlabel, or all customlabels of some type in a course.
* Special behaviour : in page format, needs to be published
*/
function customlabel_get_customlabel_in_course($course, $type, $wantfirst = false, $onlyvisible = true, $onlypublished = true) {
global $DB;
if ($course->format != 'page') {
$params = ['course' => $course->id, 'customlabeltype' => $type];
$instances = $DB->get_records('customlabel', $params);
} else {
$visibleclause = '';
if (!empty($onlyvisible)) {
$visibleclause = " AND
fpi.visible = 1
";
}
$select = "
SELECT
c.*
FROM
{customlabel} c,
{course_module} cm,
{module} m,
{format_page} fp,
{format_page_items} fpi
WHERE
c.id = cm.instance AND
cm.moduleid = m.id AND
m.name = 'customlabel' AND
fpi.cmid = cm.id AND
fpi.pageid = fp.id AND
fp.courseid = c.id
{$visibleclause}
";
$instances = $DB->get_records_sql($sql);
}
if (!empty($instances) && $wantfirst) {
return array_pop($instances);
}
return $instances;
}
/**
*
*/
function customlabel_get_customlabel_field($courseid) {
global $DB;
$params = ['course' => $courseid, 'labelclass' => 'requestcontact'];
$potrq = $DB->get_records('customlabel', $params, 'id');
if (!$potrq) {
return;
}
// At the moment take the first that comes.
$cl = array_shift($potrq);
$instance = customlabel_load_class($cl);
return $instance;
}
function customlabel_search_courses($searchcriteria) {
return [];
}