forked from ahmadi-akbar/moodle-mod_adobeconnect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lib.php
597 lines (480 loc) · 20.2 KB
/
lib.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
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
<?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/>.
/**
* @package mod_adobeconnect
* @author Akinsaya Delamarre (adelamarre@remote-learner.net)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
* @copyright (C) 2015 Remote Learner.net Inc http://www.remote-learner.net
*/
require_once('locallib.php');
/**
* Library of functions and constants for module adobeconnect
* This file should have two well differenced parts:
* - All the core Moodle functions, neeeded to allow
* the module to work integrated in Moodle.
* - All the adobeconnect specific functions, needed
* to implement all the module logic. Please, note
* that, if the module become complex and this lib
* grows a lot, it's HIGHLY recommended to move all
* these module specific functions to a new php file,
* called "locallib.php" (see forum, quiz...). This will
* help to save some memory when Moodle is performing
* actions across all modules.
*/
$adobeconnect_EXAMPLE_CONSTANT = 42;
/** Include accesslib.php */
require_once($CFG->libdir.'/accesslib.php');
/** Include calendar/lib.php */
require_once($CFG->dirroot.'/calendar/lib.php');
/**
* @uses FEATURE_GROUPS
* @uses FEATURE_GROUPINGS
* @uses FEATURE_GROUPMEMBERSONLY
* @uses FEATURE_MOD_INTRO
* @uses FEATURE_COMPLETION_TRACKS_VIEWS
* @uses FEATURE_GRADE_HAS_GRADE
* @uses FEATURE_GRADE_OUTCOMES
* @param string $feature FEATURE_xx constant for requested feature
* @return mixed True if module supports feature, false if not, null if doesn't know
*/
function adobeconnect_supports($feature) {
switch($feature) {
case FEATURE_GROUPS: return true;
case FEATURE_GROUPINGS: return true;
case FEATURE_GROUPMEMBERSONLY: return true;
case FEATURE_MOD_INTRO: return true;
case FEATURE_COMPLETION_TRACKS_VIEWS: return false;
case FEATURE_GRADE_HAS_GRADE: return false;
case FEATURE_GRADE_OUTCOMES: return false;
case FEATURE_BACKUP_MOODLE2: return true;
default: return null;
}
}
/**
* Given an object containing all the necessary data,
* (defined by the form in mod_form.php) this function
* will create a new instance and return the id number
* of the new instance.
*
* @param object $adobeconnect An object from the form in mod_form.php
* @return int The id of the newly inserted adobeconnect record
*/
function adobeconnect_add_instance($adobeconnect) {
global $COURSE, $USER, $DB;
$adobeconnect->timecreated = time();
$adobeconnect->meeturl = adobeconnect_clean_meet_url($adobeconnect->meeturl);
$adobeconnect->userid = $USER->id;
$return = false;
$meeting = new stdClass();
$username = set_username($USER->username, $USER->email);
$meetfldscoid = '';
// Assign the current user with the Adobe Presenter role
$context = context_course::instance($adobeconnect->course);
if (!has_capability('mod/adobeconnect:meetinghost', $context, $USER->id, false)) {
$param = array('shortname' => 'adobeconnecthost');
$roleid = $DB->get_field('role', 'id', $param);
if (role_assign($roleid, $USER->id, $context->id, 'mod_adobeconnect')) {
//DEBUG
} else {
debugging('role assignment failed', DEBUG_DEVELOPER);
return false;
}
}
$recid = $DB->insert_record('adobeconnect', $adobeconnect);
if (empty($recid)) {
debugging('creating adobeconnect module instance failed', DEBUG_DEVELOPER);
return false;
}
$aconnect = aconnect_login();
// Get the user's meeting folder location, if non exists then get the shared
// meeting folder location
$meetfldscoid = aconnect_get_user_folder_sco_id($aconnect, $username);
if (empty($meetfldscoid)) {
$meetfldscoid = aconnect_get_folder($aconnect, 'meetings');
}
$meeting = clone $adobeconnect;
if (0 != $adobeconnect->groupmode) { // Allow for multiple groups
// get all groups for the course
$crsgroups = groups_get_all_groups($COURSE->id);
if (empty($crsgroups)) {
return 0;
}
require_once(dirname(dirname(dirname(__FILE__))).'/group/lib.php');
// Create the meeting for each group
foreach($crsgroups as $crsgroup) {
// The teacher role if they don't already have one and
// Assign them to each group
if (!groups_is_member($crsgroup->id, $USER->id)) {
groups_add_member($crsgroup->id, $USER->id);
}
$meeting->name = $adobeconnect->name . '_' . $crsgroup->name;
if (!empty($adobeconnect->meeturl)) {
$meeting->meeturl = adobeconnect_clean_meet_url($adobeconnect->meeturl . '_' . $crsgroup->name);
}
// If creating the meeting failed, then return false and revert the group role assignments
if (!$meetingscoid = aconnect_create_meeting($aconnect, $meeting, $meetfldscoid)) {
groups_remove_member($crsgroup->id, $USER->id);
debugging('error creating meeting', DEBUG_DEVELOPER);
return false;
}
// Update permissions for meeting
if (empty($adobeconnect->meetingpublic)) {
aconnect_update_meeting_perm($aconnect, $meetingscoid, ADOBE_MEETPERM_PRIVATE);
} else {
aconnect_update_meeting_perm($aconnect, $meetingscoid, ADOBE_MEETPERM_PUBLIC);
}
// Insert record to activity instance in meeting_groups table
$record = new stdClass;
$record->instanceid = $recid;
$record->meetingscoid = $meetingscoid;
$record->groupid = $crsgroup->id;
$record->id = $DB->insert_record('adobeconnect_meeting_groups', $record);
// Add event to calendar
$event = new stdClass();
$event->name = $meeting->name;
$event->description = format_module_intro('adobeconnect', $adobeconnect, $adobeconnect->coursemodule);
$event->courseid = $adobeconnect->course;
$event->groupid = $crsgroup->id;
$event->userid = 0;
$event->instance = $recid;
$event->eventtype = 'group';
$event->timestart = $adobeconnect->starttime;
$event->timeduration = $adobeconnect->endtime - $adobeconnect->starttime;
$event->visible = 1;
$event->modulename = 'adobeconnect';
calendar_event::create($event);
}
} else { // no groups support
$meetingscoid = aconnect_create_meeting($aconnect, $meeting, $meetfldscoid);
// If creating the meeting failed, then return false and revert the group role assignments
if (!$meetingscoid) {
debugging('error creating meeting', DEBUG_DEVELOPER);
return false;
}
// Update permissions for meeting
if (empty($adobeconnect->meetingpublic)) {
aconnect_update_meeting_perm($aconnect, $meetingscoid, ADOBE_MEETPERM_PRIVATE);
} else {
aconnect_update_meeting_perm($aconnect, $meetingscoid, ADOBE_MEETPERM_PUBLIC);
}
// Insert record to activity instance in meeting_groups table
$record = new stdClass;
$record->instanceid = $recid;
$record->meetingscoid = $meetingscoid;
$record->groupid = 0;
$record->id = $DB->insert_record('adobeconnect_meeting_groups', $record);
// Add event to calendar
$event = new stdClass();
$event->name = $meeting->name;
$event->description = format_module_intro('adobeconnect', $adobeconnect, $adobeconnect->coursemodule);
$event->courseid = $adobeconnect->course;
$event->groupid = 0;
$event->userid = 0;
$event->instance = $recid;
$event->eventtype = 'course';
$event->timestart = $adobeconnect->starttime;
$event->timeduration = $adobeconnect->endtime - $adobeconnect->starttime;
$event->visible = 1;
$event->modulename = 'adobeconnect';
calendar_event::create($event);
}
// If no meeting URL was submitted,
// update meeting URL for activity with server assigned URL
if (empty($adobeconnect->meeturl) and (0 == $adobeconnect->groupmode)) {
$filter = array('filter-sco-id' => $meetingscoid);
$meeting = aconnect_meeting_exists($aconnect, $meetfldscoid, $filter);
if (!empty($meeting)) {
$meeting = current($meeting);
$record = new stdClass();
$record->id = $recid;
$record->meeturl = trim($meeting->url, '/');
$DB->update_record('adobeconnect', $record);
}
}
aconnect_logout($aconnect);
return $recid;
}
/**
* Given an object containing all the necessary data,
* (defined by the form in mod_form.php) this function
* will update an existing instance with new data.
*
* @param object $adobeconnect An object from the form in mod_form.php
* @return boolean Success/Fail
*/
function adobeconnect_update_instance($adobeconnect) {
global $DB, $USER;
$adobeconnect->timemodified = time();
$adobeconnect->id = $adobeconnect->instance;
$meetfldscoid = '';
$aconnect = aconnect_login();
$meetfldscoid = aconnect_get_folder($aconnect, 'meetings');
// Look for meetings whose names are similar
$filter = array('filter-like-name' => $adobeconnect->name);
$namematches = aconnect_meeting_exists($aconnect, $meetfldscoid, $filter);
if (empty($namematches)) {
$namematches = array();
}
// Find meeting URLs that are similar
$url = $adobeconnect->meeturl;
$filter = array('filter-like-url-path' => $url);
$urlmatches = aconnect_meeting_exists($aconnect, $meetfldscoid, $filter);
if (empty($urlmatches)) {
$urlmatches = array();
} else {
// format url for comparison
if ((false === strpos($url, '/')) or (0 != strpos($url, '/'))) {
$url = '/' . $url;
}
}
$url = adobeconnect_clean_meet_url($url);
// Get all instances of the activity meetings
$param = array('instanceid' => $adobeconnect->instance);
$grpmeetings = $DB->get_records('adobeconnect_meeting_groups', $param);
if (empty($grpmeetings)) {
$grpmeetings = array();
}
// If no errors then check to see if the updated name and URL are actually different
// If true, then update the meeting names and URLs now.
$namechange = true;
$urlchange = true;
$timechange = true;
// Look for meeting name change
foreach($namematches as $matchkey => $match) {
if (array_key_exists($match->scoid, $grpmeetings)) {
if (0 == substr_compare($match->name, $adobeconnect->name . '_', 0, strlen($adobeconnect->name . '_'), false)) {
// Break out of loop and change all referenced meetings
$namechange = false;
break;
} elseif (date('c', $adobeconnect->starttime) == $match->starttime) {
$timechange = false;
break;
} elseif (date('c', $adobeconnect->endtime) == $match->endtime) {
$timechange = false;
break;
}
}
}
// Look for URL change
foreach($urlmatches as $matchkey => $match) {
if (array_key_exists($match->scoid, $grpmeetings)) {
if (0 == substr_compare($match->url, $url . '_', 0, strlen($url . '_'), false)) {
// Break out of loop and change all referenced meetings
$urlchange = false;
break;
} elseif (date('c', $adobeconnect->starttime) == $match->starttime) {
$timechange = false;
break;
} elseif (date('c', $adobeconnect->endtime) == $match->endtime) {
$timechange = false;
break;
}
}
}
if ($timechange or $urlchange or $namechange) {
$group = '';
$meetingobj = new stdClass;
foreach ($grpmeetings as $scoid => $grpmeeting) {
if ($adobeconnect->groupmode) {
$group = groups_get_group($grpmeeting->groupid);
$group = '_' . $group->name;
} else {
$group = '';
}
$meetingobj->scoid = $grpmeeting->meetingscoid;
$meetingobj->name = $adobeconnect->name . $group;
// updating meeting URL using the API corrupts the meeting for some reason
// $meetingobj->meeturl = $data['meeturl'] . '_' . $group->name;
$meetingobj->starttime = date('c', $adobeconnect->starttime);
$meetingobj->endtime = date('c', $adobeconnect->endtime);
/* if the userid is not empty then set the meeting folder sco id to
the user's connect folder. If this line of code is not executed
then user's meetings that were previously in the user's connect folder
would be moved into the shared folder */
if (!empty($adobeconnect->userid)) {
$username = get_connect_username($adobeconnect->userid);
$user_folder = aconnect_get_user_folder_sco_id($aconnect, $username);
if (!empty($user_folder)) {
$meetfldscoid = $user_folder;
}
}
// Update each meeting instance
if (!aconnect_update_meeting($aconnect, $meetingobj, $meetfldscoid)) {
debugging('error updating meeting', DEBUG_DEVELOPER);
}
if (empty($adobeconnect->meetingpublic)) {
aconnect_update_meeting_perm($aconnect, $grpmeeting->meetingscoid, ADOBE_MEETPERM_PRIVATE);
} else {
aconnect_update_meeting_perm($aconnect, $grpmeeting->meetingscoid, ADOBE_MEETPERM_PUBLIC);
}
// Update calendar event
$param = array('courseid' => $adobeconnect->course, 'instance' =>
$adobeconnect->id, 'groupid' => $grpmeeting->groupid,
'modulename' => 'adobeconnect');
$eventid = $DB->get_field('event', 'id', $param);
if (!empty($eventid)) {
$event = new stdClass();
$event->id = $eventid;
$event->name = $meetingobj->name;
$event->description = format_module_intro('adobeconnect', $adobeconnect, $adobeconnect->coursemodule);
$event->courseid = $adobeconnect->course;
$event->groupid = $grpmeeting->groupid;
$event->userid = 0;
$event->instance = $adobeconnect->id;
$event->eventtype = 0 == $grpmeeting->groupid ? 'course' : 'group';
$event->timestart = $adobeconnect->starttime;
$event->timeduration = $adobeconnect->endtime - $adobeconnect->starttime;
$event->visible = 1;
$event->modulename = 'adobeconnect';
$calendarevent = calendar_event::load($eventid);
$calendarevent->update($event);
}
}
}
aconnect_logout($aconnect);
return $DB->update_record('adobeconnect', $adobeconnect);
}
/**
* Given an ID of an instance of this module,
* this function will permanently delete the instance
* and any data that depends on it.
*
* @param int $id Id of the module instance
* @return boolean Success/Failure
*/
function adobeconnect_delete_instance($id) {
global $DB;
$param = array('id' => $id);
if (! $adobeconnect = $DB->get_record('adobeconnect', $param)) {
return false;
}
$result = true;
// Remove meeting from Adobe connect server
$param = array('instanceid' => $adobeconnect->id);
$adbmeetings = $DB->get_records('adobeconnect_meeting_groups', $param);
if (!empty($adbmeetings)) {
$aconnect = aconnect_login();
foreach ($adbmeetings as $meeting) {
// Update calendar event
$param = array('courseid' => $adobeconnect->course, 'instance' => $adobeconnect->id,
'groupid' => $meeting->groupid, 'modulename' => 'adobeconnect');
$eventid = $DB->get_field('event', 'id', $param);
if (!empty($eventid)) {
$event = calendar_event::load($eventid);
$event->delete();
}
aconnect_remove_meeting($aconnect, $meeting->meetingscoid);
}
aconnect_logout($aconnect);
}
$param = array('id' => $adobeconnect->id);
$result &= $DB->delete_records('adobeconnect', $param);
$param = array('instanceid' => $adobeconnect->id);
$result &= $DB->delete_records('adobeconnect_meeting_groups', $param);
return $result;
}
/**
* Return a small object with summary information about what a
* user has done with a given particular instance of this module
* Used for user activity reports.
* $return->time = the time they did it
* $return->info = a short text description
*
* @return null
* @todo Finish documenting this function
*/
function adobeconnect_user_outline($course, $user, $mod, $adobeconnect) {
return null;
}
/**
* Print a detailed representation of what a user has done with
* a given particular instance of this module, for user activity reports.
*
* @return boolean
* @todo Finish documenting this function
*/
function adobeconnect_user_complete($course, $user, $mod, $adobeconnect) {
return true;
}
/**
* Given a course and a time, this module should find recent activity
* that has occurred in adobeconnect activities and print it out.
* Return true if there was output, or false is there was none.
*
* @return boolean
* @todo Finish documenting this function
*/
function adobeconnect_print_recent_activity($course, $isteacher, $timestart) {
return false; // True if anything was printed, otherwise false
}
/**
* Function to be run periodically according to the moodle cron
* This function searches for things that need to be done, such
* as sending out mail, toggling flags etc ...
*
* @return boolean
* @todo Finish documenting this function
**/
function adobeconnect_cron () {
return true;
}
/**
* Must return an array of user records (all data) who are participants
* for a given instance of adobeconnect. Must include every user involved
* in the instance, independient of his role (student, teacher, admin...)
* See other modules as example.
*
* @param int $adobeconnectid ID of an instance of this module
* @return mixed boolean/array of students
*/
function adobeconnect_get_participants($adobeconnectid) {
return false;
}
/**
* This function returns if a scale is being used by one adobeconnect
* if it has support for grading and scales. Commented code should be
* modified if necessary. See forum, glossary or journal modules
* as reference.
*
* @param int $adobeconnectid ID of an instance of this module
* @return mixed
* @todo Finish documenting this function
*/
function adobeconnect_scale_used($adobeconnectid, $scaleid) {
return false;
}
/**
* Checks if scale is being used by any instance of adobeconnect.
* This function was added in 1.9
*
* This is used to find out if scale used anywhere
* @param $scaleid int
* @return boolean True if the scale is used by any adobeconnect
*/
function adobeconnect_scale_used_anywhere($scaleid) {
return false;
}
/**
* Meeting URLs need to start with an alpha then be alphanumeric
* or hyphen('-')
*
* @param string $meeturl Incoming URL
* @return string cleaned URL
*/
function adobeconnect_clean_meet_url($meeturl) {
$meeturl = preg_replace ('/[^a-z0-9]/i', '-', $meeturl);
return $meeturl;
}