forked from elan-ev/studip-meeting
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MeetingPlugin.php
538 lines (461 loc) · 18.6 KB
/
MeetingPlugin.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
<?php
/*
* Stud.IP Video Conference Services Integration
*
* This program 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 2 of
* the License, or (at your option) any later version.
*
* @author Till Glöggler <till.gloeggler@elan-ev.de>
* @author Christian Flothmann <christian.flothmann@uos.de>
* @copyright 2011-2014 ELAN e.V. <http://www.elan-ev.de>
* @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
* @category Stud.IP
*/
require_once __DIR__.'/bootstrap.php';
use ElanEv\Model\CourseConfig;
use ElanEv\Model\MeetingCourse;
use ElanEv\Model\Meeting;
use Meetings\AppFactory;
use Meetings\RouteMap;
use Meetings\Helpers\WidgetHelper;
use Meetings\Errors\Error;
require_once 'compat/StudipVersion.php';
class MeetingPlugin extends StudIPPlugin implements PortalPlugin, StandardPlugin, SystemPlugin
{
const GETTEXT_DOMAIN = 'meetings';
const NAVIGATION_ITEM_NAME = 'video-conferences';
private $assetsUrl;
public function __construct()
{
parent::__construct();
bindtextdomain(static::GETTEXT_DOMAIN, $this->getPluginPath() . '/locale');
bind_textdomain_codeset(static::GETTEXT_DOMAIN, 'UTF-8');
$this->assetsUrl = rtrim($this->getPluginURL(), '/').'/assets';
/** @var \Seminar_Perm $perm */
$perm = $GLOBALS['perm'];
if ($perm->have_perm('root')) {
$item = new Navigation($this->_('Meetings konfigurieren'), PluginEngine::getLink($this, array(), 'admin#/admin'));
$item->setImage(self::getIcon('chat', 'white'));
if (Navigation::hasItem('/admin/config') && !Navigation::hasItem('/admin/config/meetings')) {
Navigation::addItem('/admin/config/meetings', $item);
}
}
NotificationCenter::addObserver($this, 'DeleteMeetingOnUserDelete', 'UserDidDelete');
NotificationCenter::addObserver($this, 'UpdateMeetingOnUserMigrate', 'UserDidMigrate');
// do nothing if plugin is deactivated in this seminar/institute
if (!$this->isActivated()) {
return;
}
}
/**
* Checks if the context in which the plugin is activated is of Course type.
*
* @param Range $context
* @return bool
*/
public function isActivatableForContext(Range $context)
{
return get_class($context) === \Course::class;
}
/**
* Plugin localization for a single string.
* This method supports sprintf()-like execution if you pass additional
* parameters.
*
* @param String $string String to translate
* @return translated string
*/
public function _($string)
{
$result = static::GETTEXT_DOMAIN === null
? $string
: dcgettext(static::GETTEXT_DOMAIN, $string, LC_MESSAGES);
if ($result === $string) {
$result = _($string);
}
if (func_num_args() > 1) {
$arguments = array_slice(func_get_args(), 1);
$result = vsprintf($result, $arguments);
}
return $result;
}
/**
* Plugin localization for plural strings.
* This method supports sprintf()-like execution if you pass additional
* parameters.
*
* @param String $string0 String to translate (singular)
* @param String $string1 String to translate (plural)
* @param mixed $n Quantity factor (may be an array or array-like)
* @return translated string
*/
public function _n($string0, $string1, $n)
{
if (is_array($n)) {
$n = count($n);
}
$result = static::GETTEXT_DOMAIN === null
? $string0
: dngettext(static::GETTEXT_DOMAIN, $string0, $string1, $n);
if ($result === $string0 || $result === $string1) {
$result = ngettext($string0, $string1, $n);
}
if (func_num_args() > 3) {
$arguments = array_slice(func_get_args(), 3);
$result = vsprintf($result, $arguments);
}
return $result;
}
public static function getIcon($name, $color)
{
if (StudipVersion::newerThan('3.3')) {
$type = 'info';
switch ($color) {
case 'white': $type = 'info_alt'; break;
case 'grey': $type = 'inactive'; break;
case 'blue': $type = 'clickable';break;
case 'red': $type = 'new'; break;
case 'gray': $type = 'inactive'; break;
}
return Icon::create($name, $type);
} else {
return 'icons/16/' . $color .'/' . $name;
}
}
public function getPluginName()
{
return $this->_('Meetings');
}
public function getInfoTemplate($course_id) {
return null;
}
/**
* {@inheritdoc}
*/
public function getIconNavigation($courseId, $lastVisit, $userId = null)
{
require_once __DIR__ . '/vendor/autoload.php';
/** @var Seminar_Perm $perm */
$perm = $GLOBALS['perm'];
if ($perm->have_studip_perm('tutor', $courseId)) {
$courses = MeetingCourse::findByCourseId($courseId);
} else {
$courses = MeetingCourse::findActiveByCourseId($courseId);
}
$recentMeetings = 0;
foreach ($courses as $meetingCourse) {
if ($meetingCourse->meeting->mkdate >= $lastVisit) {
$recentMeetings++;
}
}
$courseConfig = CourseConfig::findByCourseId($courseId);
$navigation = new Navigation($courseConfig->title, PluginEngine::getLink($this, array(), 'index'));
if ($recentMeetings > 0) {
$navigation->setImage(self::getIcon('chat', 'red'), array(
'title' => sprintf($this->_('%d Meeting(s), %d neue'), count($courses), $recentMeetings),
));
} else {
$navigation->setImage(self::getIcon('chat', 'gray'), array(
'title' => sprintf($this->_('%d Meeting(s)'), count($courses)),
));
}
return $navigation;
}
/* interface method */
function getNotificationObjects($course_id, $since, $user_id)
{
return array();
}
/**
* {@inheritdoc}
*/
public function getTabNavigation($courseId)
{
require_once __DIR__ . '/vendor/autoload.php';
$courseConfig = CourseConfig::findByCourseId($courseId);
$main = new Navigation($courseConfig->title);
$main->setURL(PluginEngine::getURL($this, [], 'index'));
$main->addSubNavigation('meetings', new Navigation(
$courseConfig->title,
PluginEngine::getURL($this, [], 'index')
));
if ($GLOBALS['perm']->have_studip_perm('dozent', $courseId)) {
$main->addSubNavigation('config', new Navigation(
_('Anpassen'),
PluginEngine::getLink($this, [], 'index/config')
));
}
return array(self::NAVIGATION_ITEM_NAME => $main);
}
/**
* {@inheritdoc}
*/
public function perform($unconsumed_path)
{
require_once __DIR__ . '/vendor/autoload.php';
if (substr($unconsumed_path, 0, 3) == 'api') {
$appFactory = new AppFactory();
$app = $appFactory->makeApp($this);
$app->group('/meetingplugin/api', new RouteMap($app));
$app->run();
} else {
PageLayout::addStylesheet($this->getPluginUrl() . '/static/styles.css');
$trails_root = $this->getPluginPath() . '/app';
$dispatcher = new Trails_Dispatcher($trails_root,
rtrim(PluginEngine::getURL($this, null, ''), '/'),
'index'
);
$dispatcher->current_plugin = $this;
$dispatcher->dispatch($unconsumed_path);
}
}
public function getAssetsUrl()
{
return $this->assetsUrl;
}
/**
* Checks if opencast is loaded, and if course id is passed,
* returns the series id of the course if opencast has been set for the course
*
* @param string $cid course ID with default null
* @return bool | array | string(empty - in case opencast is not activated for this course)
*/
public static function checkOpenCast($cid = null) {
$plugin_manager = \PluginManager::getInstance();
$opencast_plugin = $plugin_manager->getPluginInfo('OpenCast');
if ($opencast_plugin && $opencast_plugin['enabled']) {
if ($cid) {
if ($plugin_manager->isPluginActivated($opencast_plugin['id'], $cid)) {
try {
return self::getOpencastSeriesId($cid, $opencast_plugin);
} catch (Exception $ex) {
//Handle Error
throw new Error('Opencast-Serien-ID konnte nicht abgerufen werden.', 500);
}
} else {
return ""; //because of checkers along the flow (empty string is a sign of Opencast not activated!)
}
}
return true;
}
return false;
}
private static function getOpencastSeriesId($cid, $opencast_plugin_info) {
if (empty($cid)) {
return false;
}
// We need to provide the right files in order to use the getSeries method from OCSeminarSeries
// when the user is not authenticated, that happens mostly via QR-Code login.
if ($GLOBALS['auth']->auth['uid'] === 'nobody') {
$opencast_plugin_path = "{$GLOBALS['ABSOLUTE_PATH_STUDIP']}plugins_packages/{$opencast_plugin_info['path']}";
if (!file_exists("$opencast_plugin_path/constants.php") ||
!file_exists("$opencast_plugin_path/classes/OCRestClient/OCRestClient.php") ||
!file_exists("$opencast_plugin_path/classes/OCRestClient/SeriesClient.php")) {
throw new Error('Opencast-Serien-ID konnte nicht abgerufen werden.', 500);
}
require("$opencast_plugin_path/constants.php");
require("$opencast_plugin_path/classes/OCRestClient/OCRestClient.php");
require("$opencast_plugin_path/classes/OCRestClient/SeriesClient.php");
}
$opencastSeminarSeries = \Opencast\Models\OCSeminarSeries::getSeries($cid);
return (!empty($opencastSeminarSeries) ? $opencastSeminarSeries[0]['series_id'] : false);
}
/**
* @inherits
*
* Overwrite default metadata-function to translate the descriptions
*
* @return Array the plugins metadata as an array
*/
public function getMetadata()
{
$metadata = parent::getMetadata();
$metadata['pluginname'] = $this->_("Meetings");
$metadata['displayname'] = $this->_("Meetings");
$metadata['descriptionlong'] = $this->_("Virtueller Raum, mit dem Live-Online-Treffen, Veranstaltungen "
. "und Videokonferenzen durchgeführt werden können. Die Teilnehmenden können sich während "
. "eines Meetings gegenseitig hören und über eine angeschlossene Webcam - wenn vorhanden - "
. "sehen und miteinander arbeiten. Folien können präsentiert und Abfragen durchgeführt werden. "
. "Ein Fenster in der Benutzungsoberfläche des eigenen Rechners kann für andere sichtbar "
. "geschaltet werden, um zum Beispiel den Teilnehmenden bestimmte Webseiten oder Anwendungen "
. "zu zeigen. Außerdem kann die Veranstaltung aufgezeichnet und Interessierten zur Verfügung gestellt werden."
);
$metadata['descriptionshort'] = $this->_("Face-to-face-Kommunikation mit Adobe Connect oder BigBlueButton");
$metadata['keywords'] = $this->_("Videokonferenz- und Veranstaltungsmöglichkeit; "
. "Live im Netz präsentieren sowie gemeinsam zeichnen und arbeiten;Kommunikation über Mikrofon und Kamera; "
. "Ideal für dezentrale Lern- und Arbeitsgruppen; "
. "Verlinkung zu bereits bestehenden eigenen Räumen"
);
return $metadata;
}
/**
* getMeetingManifestInfo
*
* get the plugin manifest from PluginManager getPluginManifest method
*
* @return Array $metadata the manifest metadata of this plugin
*/
public static function getMeetingManifestInfo()
{
$plugin_manager = \PluginManager::getInstance();
$this_plugin = $plugin_manager->getPluginInfo(__CLASS__);
$plugin_path = \get_config('PLUGINS_PATH') . '/' .$this_plugin['path'];
$manifest = $plugin_manager->getPluginManifest($plugin_path);
return $manifest;
}
/**
* DeleteMeetingOnUserDelete: handler for UserDidDelete event
*
* @param object event
* @param user $user
*
*/
public function DeleteMeetingOnUserDelete($event, $user)
{
require_once __DIR__ . '/vendor/autoload.php';
if (!$user instanceof \Seminar_User) {
$seminar_user = new \Seminar_User($user);
}
$meetingCourses = MeetingCourse::findByUser($seminar_user);
if ($meetingCourses) {
foreach ($meetingCourses as $meetingCourse) {
$meetingCourse->meeting->delete();
$meetingCourse->delete();
}
}
}
/**
* UpdateMeetingOnUserMigrate: handler for UserDidMigrate event
*
* @param string $old_id old user id
* @param string $new_id new user id
*
*/
public function UpdateMeetingOnUserMigrate($event, $old_id, $new_id)
{
require_once __DIR__ . '/vendor/autoload.php';
if ($old_id && $new_id) {
$user_meetings = Meeting::findBySQL('user_id = ?', [$old_id]);
if ($user_meetings) {
foreach ($user_meetings as $meeting) {
$meeting->user_id = $new_id;
$meeting->store();
}
}
}
}
/**
* Get seminar types for the course_types (dropdown).
* The course_types dropdown applies to each server of a given server
*
* @return array with key => value pairs like: array('class_id' => array('name' => 'class_name', 'subs' => [array of sub cats]))
*/
public static function getSemClasses()
{
$sem_classes = [];
foreach ($GLOBALS['SEM_CLASS'] as $class_id => $class) {
$class_obj = [];
$class_obj['name'] = _($class['name']);
$class_obj['subs'][$class_id] = "{$class_obj['name']} (" . _('Alle') . ")";
if (!$class['studygroup_mode']) {
foreach ($class->getSemTypes() as $type_id => $type) {
$class_obj['subs']["{$class_id}_{$type_id}"] = _($type['name']);
}
}
$sem_classes[$class_id] = $class_obj;
}
ksort($sem_classes);
return $sem_classes;
}
/**
* Checks whether the server course type against the current course
*
* @param Course $course The current course which the server is going to be used
* @param String $server_course_type The server course type
* @return boolean
*/
public static function checkCourseType(Course $course, $server_course_type)
{
if ($server_course_type == '' || is_array($server_course_type)) { // When it is empty or an array, it supports all course types.
return true;
}
if (!$course) {
return false;
}
$course_class_id = $course->getSemClass()->offsetGet('id');
$course_type_id = $course->getSemType()->offsetGet('id');
$server_course_type_arr = explode("_", $server_course_type);
$server_course_class_id = '';
$server_course_type_id = '';
if (count($server_course_type_arr) == 1) {
$server_course_class_id = $server_course_type_arr[0];
if ($server_course_class_id == $course_class_id) {
return true;
} else {
return false;
}
} elseif (count($server_course_type_arr) == 2) {
$server_course_class_id = $server_course_type_arr[0];
$server_course_type_id = $server_course_type_arr[1];
if ($server_course_class_id == $course_class_id && $server_course_type_id == $course_type_id) {
return true;
} else {
return false;
}
}
return false;
}
/**
* Finds corresponding course type name
*
* @param String $server_course_type The server course type
* @return String $course_type_name The name of the semClass
*/
public static function getCourseTypeName($server_course_type)
{
if (!$server_course_type || is_array($server_course_type)) { // When it is empty or an array, it supports all course types.
return _('Alle Veranstaltungstypen');
}
$server_course_type_arr = explode("_", $server_course_type);
$server_course_class_id = '';
$server_course_type_id = '';
if (count($server_course_type_arr) == 1) {
$server_course_class_id = $server_course_type_arr[0];
return _($GLOBALS['SEM_CLASS'][$server_course_class_id]['name']);
} elseif (count($server_course_type_arr) == 2) {
$server_course_class_id = $server_course_type_arr[0];
$server_course_type_id = $server_course_type_arr[1];
return _($GLOBALS['SEM_CLASS'][$server_course_class_id]->getSemTypes()[$server_course_type_id]['name']);
}
return '';
}
/**
* Return the template for the widget.
*
* @return Flexi_PhpTemplate The template containing the widget contents
*/
public function getPortalTemplate()
{
require_once __DIR__ . '/vendor/autoload.php';
// We need to use "nobody" rights for Upload Slides,
// but in here we have to prevent that right,
// in order to not to show the template in login page and so on.
if ('nobody' === $GLOBALS['user']->id) {
return;
}
$template_factory = new Flexi_TemplateFactory(__DIR__ . "/templates");
$template = $template_factory->open("index.php");
$template->set_attribute('items', WidgetHelper::getMeetingsForWidget());
$texts = [
'empty' => $this->_('Derzeit finden keine Meetings in den gebuchten Kursen statt.'),
'current' => $this->_('Derzeitige Meetings'),
'upcoming' => $this->_('Kommende Meetings'),
'to_course' => $this->_('Zur Meeting-Liste'),
'to_meeting' => $this->_('Direkt zum Meeting')
];
$template->set_attribute('texts', $texts);
return $template;
}
}