07ab0c80 |
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 | * |
19 | * Hub library |
20 | * |
21 | * @package hub |
22 | * @copyright 2010 Moodle Pty Ltd (http://moodle.com) |
23 | * @author Jerome Mouneyrac |
24 | * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com} |
25 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
26 | */ |
27 | |
28 | |
29 | ///// IMAGE SIZES ///// |
30 | |
31 | /** |
32 | * SITEIMAGEHEIGHT - the maximum height size of a site logo |
33 | */ |
34 | define('SITEIMAGEHEIGHT', 150); |
35 | |
36 | /** |
37 | * SITEIMAGEWIDTH - the maximum width size of a site logo |
38 | */ |
39 | define('SITEIMAGEWIDTH', 150); |
40 | |
41 | |
42 | |
43 | ///// MOODLE.ORG URLS ////// |
44 | |
45 | /** |
46 | * Hub directory url (should be moodle.org) |
47 | */ |
48 | //define('HUBDIRECTORYURL', "http://jerome.moodle.local/Moodle_HEAD_hubdirectory/moodle"); |
49 | define('HUBDIRECTORYURL', "http://hubdirectory.moodle.org"); |
50 | |
51 | |
52 | /** |
53 | * Moodle.org url (should be moodle.org) |
54 | */ |
55 | //define('MOODLEORGHUBURL', "http://jerome.moodle.local/Moodle_HEAD_secure_hub/moodle"); |
56 | define('MOODLEORGHUBURL', "http://hub.moodle.org"); |
57 | |
58 | |
59 | |
60 | //// SITE PRIVACY ///// |
61 | |
62 | /** |
63 | * Site privacy: private |
64 | */ |
65 | define('SITENOTPUBLISHED', 'notdisplayed'); |
66 | |
67 | /** |
68 | * Site privacy: public |
69 | */ |
70 | define('SITENAMEPUBLISHED', 'named'); |
71 | |
72 | /** |
73 | * Site privacy: public and global |
74 | */ |
75 | define('SITELINKPUBLISHED', 'linked'); |
76 | |
77 | |
78 | |
79 | //// Communication ///// |
80 | |
81 | /** |
82 | * Hub server |
83 | */ |
84 | define('HUB', 'hub'); |
85 | |
86 | /** |
87 | * Registered site |
88 | */ |
89 | define('REGISTEREDSITE', 'site'); |
90 | |
91 | /** |
92 | * Public site |
93 | */ |
94 | define('PUBLICSITE', 'publicsite'); |
95 | |
96 | /** |
97 | * Hub directory |
98 | */ |
99 | define('HUBDIRECTORY', 'hubdirectory'); |
100 | |
101 | /** |
102 | * WS server |
103 | */ |
104 | define('WSSERVER', 'server'); |
105 | |
106 | /** |
107 | * WS client |
108 | */ |
109 | define('WSCLIENT', 'client'); |
110 | |
111 | |
112 | |
113 | //// AUDIENCE //// |
114 | |
115 | /** |
116 | * Audience: educators |
117 | */ |
118 | define('AUDIENCE_EDUCATORS', 'educators'); |
119 | |
120 | /** |
121 | * Audience: students |
122 | */ |
123 | define('AUDIENCE_STUDENTS', 'students'); |
124 | |
125 | /** |
126 | * Audience: admins |
127 | */ |
128 | define('AUDIENCE_ADMINS', 'admins'); |
129 | |
130 | |
131 | |
132 | ///// EDUCATIONAL LEVEL ///// |
133 | |
134 | /** |
135 | * Educational level: primary |
136 | */ |
137 | define('EDULEVEL_PRIMARY', 'primary'); |
138 | |
139 | /** |
140 | * Educational level: secondary |
141 | */ |
142 | define('EDULEVEL_SECONDARY', 'secondary'); |
143 | |
144 | /** |
145 | * Educational level: tertiary |
146 | */ |
147 | define('EDULEVEL_TERTIARY', 'tertiary'); |
148 | |
149 | /** |
150 | * Educational level: government |
151 | */ |
152 | define('EDULEVEL_GOVERNMENT', 'government'); |
153 | |
154 | /** |
155 | * Educational level: association |
156 | */ |
157 | define('EDULEVEL_ASSOCIATION', 'association'); |
158 | |
159 | /** |
160 | * Educational level: corporate |
161 | */ |
162 | define('EDULEVEL_CORPORATE', 'corporate'); |
163 | |
164 | /** |
165 | * Educational level: other |
166 | */ |
167 | define('EDULEVEL_OTHER', 'other'); |
168 | |
169 | |
170 | |
171 | ///// FILE TYPES ///// |
172 | |
173 | /** |
174 | * FILE TYPE: SCREENSHOTS |
175 | */ |
176 | define('SCREENSHOT_FILE_TYPE', 'screenshot'); |
177 | |
178 | /** |
179 | * FILE TYPE: BACKUP |
180 | */ |
181 | define('BACKUP_FILE_TYPE', 'backup'); |
182 | |
183 | |
184 | |
185 | class hub { |
186 | |
187 | /////////////////////////// |
188 | /// DB Facade functions // |
189 | /////////////////////////// |
190 | |
191 | public function add_registeredhub($hub) { |
192 | global $DB; |
193 | $id = $DB->insert_record('registration_hubs', $hub); |
194 | return $id; |
195 | } |
196 | |
197 | public function get_registeredhub($huburl = null, $token = null) { |
198 | global $DB; |
199 | |
200 | $params = array(); |
201 | if (!empty($huburl)) { |
202 | $params['huburl'] = $huburl; |
203 | } |
204 | if (!empty($token)) { |
205 | $params['token'] = $token; |
206 | } |
207 | $token = $DB->get_record('registration_hubs',$params); |
208 | return $token; |
209 | } |
210 | |
211 | public function update_registeredhub($communication) { |
212 | global $DB; |
213 | $DB->update_record('registration_hubs', $communication); |
214 | } |
215 | |
216 | |
217 | /////////////////////////// |
218 | /// Library functions /// |
219 | /////////////////////////// |
220 | |
221 | |
222 | |
223 | /** |
224 | * Return site information for a specific hub |
225 | * @param string $huburl |
226 | * @return array site info |
227 | */ |
228 | public function get_site_info($huburl) { |
229 | global $CFG, $DB; |
230 | |
231 | $siteinfo = array(); |
232 | $cleanhuburl = clean_param($huburl, PARAM_ALPHANUMEXT); |
233 | $siteinfo['name'] = get_config('hub', 'site_name_'.$cleanhuburl); |
234 | $siteinfo['description'] = get_config('hub', 'site_description_'.$cleanhuburl); |
235 | $siteinfo['contactname'] = get_config('hub', 'site_contactname_'.$cleanhuburl); |
236 | $siteinfo['contactemail'] = get_config('hub', 'site_contactemail_'.$cleanhuburl); |
237 | $siteinfo['contactphone'] = get_config('hub', 'site_contactphone_'.$cleanhuburl); |
238 | $siteinfo['imageurl'] = get_config('hub', 'site_imageurl_'.$cleanhuburl); |
239 | $siteinfo['privacy'] = get_config('hub', 'site_privacy_'.$cleanhuburl); |
240 | $siteinfo['street'] = get_config('hub', 'site_address_'.$cleanhuburl); |
241 | $siteinfo['regioncode'] = get_config('hub', 'site_region_'.$cleanhuburl); |
242 | $siteinfo['countrycode'] = get_config('hub', 'site_country_'.$cleanhuburl); |
243 | $siteinfo['geolocation'] = get_config('hub', 'site_geolocation_'.$cleanhuburl); |
244 | $siteinfo['contactable'] = get_config('hub', 'site_contactable_'.$cleanhuburl); |
245 | $siteinfo['emailalert'] = get_config('hub', 'site_emailalert_'.$cleanhuburl); |
246 | if (get_config('hub', 'site_coursesnumber_'.$cleanhuburl) == -1) { |
247 | $coursecount = -1; |
248 | } else { |
249 | $coursecount = $DB->count_records('course')-1; |
250 | } |
251 | $siteinfo['courses'] = $coursecount; |
252 | if (get_config('hub', 'site_usersnumber_'.$cleanhuburl) == -1) { |
253 | $usercount = -1; |
254 | } else { |
255 | $usercount = $DB->count_records('user', array('deleted'=>0)); |
256 | } |
257 | $siteinfo['users'] = $usercount; |
258 | |
259 | if (get_config('hub', 'site_roleassignmentsnumber_'.$cleanhuburl) == -1) { |
260 | $roleassigncount = -1; |
261 | } else { |
262 | $roleassigncount = $DB->count_records('role_assignments'); |
263 | } |
264 | $siteinfo['enrolments'] = $roleassigncount; |
265 | if (get_config('hub', 'site_postsnumber_'.$cleanhuburl) == -1) { |
266 | $postcount = -1; |
267 | } else { |
268 | $postcount = $DB->count_records('forum_posts'); |
269 | } |
270 | $siteinfo['posts'] = $postcount; |
271 | if (get_config('hub', 'site_questionsnumber_'.$cleanhuburl) == -1) { |
272 | $questioncount = -1; |
273 | } else { |
274 | $questioncount = $DB->count_records('question'); |
275 | } |
276 | $siteinfo['questions'] = $questioncount; |
277 | if (get_config('hub', 'site_resourcesnumber_'.$cleanhuburl) == -1) { |
278 | $resourcecount = -1; |
279 | } else { |
280 | $resourcecount = $DB->count_records('resource'); |
281 | } |
282 | $siteinfo['resources'] = $resourcecount; |
283 | //TODO |
284 | require_once($CFG->dirroot."/course/lib.php"); |
285 | if (get_config('hub', 'site_participantnumberaverage_'.$cleanhuburl) == -1) { |
286 | $participantnumberaverage = -1; |
287 | } else { |
288 | $participantnumberaverage = average_number_of_participants(); |
289 | } |
290 | $siteinfo['participantnumberaverage'] = $participantnumberaverage; |
291 | if (get_config('hub', 'site_modulenumberaverage_'.$cleanhuburl) == -1) { |
292 | $modulenumberaverage = -1; |
293 | } else { |
294 | $modulenumberaverage = average_number_of_courses_modules(); |
295 | } |
296 | $siteinfo['modulenumberaverage'] = $modulenumberaverage; |
297 | $siteinfo['language'] = current_language(); |
298 | $siteinfo['moodleversion'] = $CFG->version; |
299 | $siteinfo['moodlerelease'] = $CFG->release; |
300 | $siteinfo['url'] = $CFG->wwwroot; |
301 | |
302 | return $siteinfo; |
303 | } |
304 | |
305 | |
306 | /** |
307 | * Retrieve the site privacy string matching the define value |
308 | * @param string $privacy must match the define into moodlelib.php |
309 | * @return string |
310 | */ |
311 | public function get_site_privacy_string($privacy) { |
312 | switch ($privacy) { |
313 | case SITENOTPUBLISHED: |
314 | $privacystring = get_string('publicdirectory0'); |
315 | break; |
316 | case SITENAMEPUBLISHED: |
317 | $privacystring = get_string('publicdirectory1'); |
318 | break; |
319 | case SITELINKPUBLISHED: |
320 | $privacystring = get_string('publicdirectory2'); |
321 | break; |
322 | } |
323 | if (empty($privacystring)) { |
324 | throw new moodle_exception('unknownprivacy'); |
325 | } |
326 | return $privacystring; |
327 | } |
328 | |
329 | |
330 | |
331 | /** |
332 | * Return all hubs where the site is registered on |
333 | */ |
334 | public function get_registered_on_hubs() { |
335 | global $DB; |
336 | $hubs = $DB->get_records('registration_hubs', array()); |
337 | return $hubs; |
338 | } |
339 | |
340 | } |