From e099f58c4712e24d44ef1704e88ddd4ef309f7bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Ducoulombier?= Date: Sun, 19 Jul 2020 16:54:07 +0200 Subject: [PATCH] Zoom meeting introduction and universal EnterMeeting link - refs BT#17288 --- plugin/zoom/Entity/MeetingEntity.php | 28 ++++++++ plugin/zoom/global.php | 22 +------ plugin/zoom/join_meeting.php | 10 ++- plugin/zoom/lang/english.php | 2 +- plugin/zoom/lang/french.php | 2 +- plugin/zoom/lang/spanish.php | 2 +- plugin/zoom/lib/zoom_plugin.class.php | 92 ++++++++++----------------- plugin/zoom/view/meeting.tpl | 12 +++- 8 files changed, 82 insertions(+), 88 deletions(-) diff --git a/plugin/zoom/Entity/MeetingEntity.php b/plugin/zoom/Entity/MeetingEntity.php index a7467b793b..721b50a3ff 100644 --- a/plugin/zoom/Entity/MeetingEntity.php +++ b/plugin/zoom/Entity/MeetingEntity.php @@ -443,6 +443,34 @@ class MeetingEntity return null; } + /** + * Generates a short presentation of the meeting for the future participant. + * To be displayed above the "Enter meeting" link. + * + * @return string + */ + public function getIntroduction() + { + $introduction = sprintf('

%s

', $this->meetingInfoGet->topic); + if (!$this->isGlobalMeeting()) { + $introduction .= sprintf('

%s (%s)

', $this->formattedStartTime, $this->formattedDuration); + } + if ($this->user) { + $introduction .= sprintf('

%s

', $this->user->getFullname()); + } elseif ($this->isCourseMeeting()) { + if (is_null($this->session)) { + $introduction .= sprintf('

%s

', $this->course); + } else { + $introduction .= sprintf('

%s (%s)

', $this->course, $this->session); + } + } + if (!empty($this->meetingInfoGet->agenda)) { + $introduction .= sprintf('

%s

', $this->meetingInfoGet->agenda); + } + + return $introduction; + } + /** * @throws Exception on unexpected start_time or duration */ diff --git a/plugin/zoom/global.php b/plugin/zoom/global.php index 3ef67e5de5..26f076a75d 100644 --- a/plugin/zoom/global.php +++ b/plugin/zoom/global.php @@ -5,26 +5,8 @@ $course_plugin = 'zoom'; // needed in order to load the plugin lang variables require_once __DIR__.'/config.php'; -if (!api_user_is_login()) { +if (!ZoomPlugin::currentUserCanJoinGlobalMeeting()) { api_not_allowed(true); } -$plugin = ZoomPlugin::create(); - -Display::display_header($plugin->get_title()); - -try { - printf( - '
- %s -
', - $plugin->getGlobalMeetingURL(), - get_lang('JoinGlobalVideoConference') - ); -} catch (Exception $exception) { - Display::addFlash( - Display::return_message($exception->getMessage(), 'error') - ); -} - -Display::display_footer(); +location('join_meeting.php?meetingId='.ZoomPlugin::create()->getGlobalMeeting()->getId()); diff --git a/plugin/zoom/join_meeting.php b/plugin/zoom/join_meeting.php index 9cae81d6e2..8871b0ae68 100644 --- a/plugin/zoom/join_meeting.php +++ b/plugin/zoom/join_meeting.php @@ -23,13 +23,11 @@ if (array_key_exists('meetingId', $_REQUEST)) { if (is_null($meeting)) { throw new Exception('Meeting not found'); } - // TODO introduce the meeting printf( - '
- %s -
', - $plugin->getUserMeetingURL($meeting), - get_lang('JoinMeetingAsMyself') + '%s

%s

', + $meeting->getIntroduction(), + $plugin->getStartOrJoinMeetingURL($meeting), + get_lang('EnterMeeting') ); } catch (Exception $exception) { Display::addFlash( diff --git a/plugin/zoom/lang/english.php b/plugin/zoom/lang/english.php index 3b12b1dc84..25d0a1b8fe 100755 --- a/plugin/zoom/lang/english.php +++ b/plugin/zoom/lang/english.php @@ -79,6 +79,7 @@ $strings['Duration'] = "Duration"; $strings['DurationFormat'] = "%hh%I"; $strings['DurationInMinutes'] = "Duration (in minutes)"; $strings['EndDate'] = "End Date"; +$strings['EnterMeeting'] = "Enter meeting"; $strings['Files'] = "Files"; $strings['Finished'] = "finished"; $strings['FileWasCopiedToCourse'] = "The file was copied to the course"; @@ -88,7 +89,6 @@ $strings['GroupUsersWereRegistered'] = "Group members were registered"; $strings['InstantMeeting'] = "Instant meeting"; $strings['Join'] = "Join"; $strings['JoinGlobalVideoConference'] = "Join global conference"; -$strings['JoinMeetingAsMyself'] = "Join meeting as myself"; $strings['JoinURLCopied'] = "Join URL copied"; $strings['JoinURLToSendToParticipants'] = "Join URL to send to participants"; $strings['LiveMeetings'] = "Live meetings"; diff --git a/plugin/zoom/lang/french.php b/plugin/zoom/lang/french.php index 6ebb27e10c..dca8b5babe 100755 --- a/plugin/zoom/lang/french.php +++ b/plugin/zoom/lang/french.php @@ -78,6 +78,7 @@ $strings['Duration'] = "Durée"; $strings['DurationFormat'] = "%hh%I"; $strings['DurationInMinutes'] = "Durée (en minutes)"; $strings['EndDate'] = "Date de fin"; +$strings['EnterMeeting'] = "Entrer dans la conférence"; $strings['Files'] = "Fichiers"; $strings['Finished'] = "terminée"; $strings['FileWasCopiedToCourse'] = "Le fichier a été copié dans le cours"; @@ -87,7 +88,6 @@ $strings['GroupUsersWereRegistered'] = "Les membres des groupes ont été inscri $strings['InstantMeeting'] = "Conférence instantanée"; $strings['Join'] = "Rejoindre"; $strings['JoinGlobalVideoConference'] = "Rejoindre la conférence globale"; -$strings['JoinMeetingAsMyself'] = "Rejoindre la conférence en tant que moi-même"; $strings['JoinURLCopied'] = "URL pour rejoindre copiée"; $strings['JoinURLToSendToParticipants'] = "URL pour assister à la conférence (à envoyer aux participants)"; $strings['LiveMeetings'] = "Conférences en cours"; diff --git a/plugin/zoom/lang/spanish.php b/plugin/zoom/lang/spanish.php index abc86452af..d3b3a589ff 100644 --- a/plugin/zoom/lang/spanish.php +++ b/plugin/zoom/lang/spanish.php @@ -78,6 +78,7 @@ $strings['Duration'] = "Duración"; $strings['DurationFormat'] = "%hh%I"; $strings['DurationInMinutes'] = "Duración (en minutos)"; $strings['EndDate'] = "Fecha de fin"; +$strings['EnterMeeting'] = "Ingresar la conferencia"; $strings['Files'] = "Archivos"; $strings['Finished'] = "terminada"; $strings['FileWasCopiedToCourse'] = "El archivo ha sido copiado en el curso"; @@ -87,7 +88,6 @@ $strings['GroupUsersWereRegistered'] = "Miembros de los grupos han sido registra $strings['InstantMeeting'] = "Conferencia instantánea"; $strings['Join'] = "Ingresar"; $strings['JoinGlobalVideoConference'] = "Ingresar la conrencia global"; -$strings['JoinMeetingAsMyself'] = "Ingresar la conferencia como yo mismo"; $strings['JoinURLCopied'] = "URL para juntarse copiada"; $strings['JoinURLToSendToParticipants'] = "URL para asistir a la conferencia (para enviar a los participantes)"; $strings['LiveMeetings'] = "Conferencias activas"; diff --git a/plugin/zoom/lib/zoom_plugin.class.php b/plugin/zoom/lib/zoom_plugin.class.php index 9dd3a52920..6365140c7b 100755 --- a/plugin/zoom/lib/zoom_plugin.class.php +++ b/plugin/zoom/lib/zoom_plugin.class.php @@ -87,7 +87,7 @@ class ZoomPlugin extends Plugin */ public static function currentUserCanJoinGlobalMeeting() { - return 'true' === api_get_plugin_setting('zoom', 'enableGlobalConference'); + return 'true' === api_get_plugin_setting('zoom', 'enableGlobalConference') && api_user_is_login(); } /** @@ -764,87 +764,65 @@ class ZoomPlugin extends Plugin } /** - * @throws OptimisticLockException + * Return the current global meeting (create it if needed). + * * @throws Exception * * @return string */ - public function getGlobalMeetingURL() + public function getGlobalMeeting() { - if (!self::currentUserCanJoinGlobalMeeting()) { - throw new Exception('global meetings are not enabled'); - } - $url = null; foreach ($this->getMeetingRepository()->unfinishedGlobalMeetings() as $meeting) { - // Zoom does not allow for a new meeting to be started on first participant join. - // It requires the host to start the meeting first. - // Therefore we must make the global meeting creator the host, that is, redirect to start_url, not join_url - $meetingInfoGet = MeetingInfoGet::fromId($meeting->getMeetingInfoGet()->id); - if ($meeting->getMeetingInfoGet() != $meetingInfoGet) { // keep comparison operator (!=) - $meeting->setMeetingInfoGet($meetingInfoGet); - Database::getManager()->persist($meeting); - Database::getManager()->flush($meeting); - } - if ('waiting' === $meetingInfoGet->status) { - $url = $meeting->getMeetingInfoGet()->start_url; - break; - } elseif ('started' === $meetingInfoGet->status) { - if ('true' === $this->get('enableParticipantRegistration') && $meeting->requiresRegistration()) { - $user = api_get_user_entity(api_get_user_id()); - /** @var RegistrantEntity $registrant */ - $registrant = $meeting->getRegistrant($user); - if (is_null($registrant)) { // not registered yet - $registrant = $this->registerUser($meeting, $user); - } - $url = $registrant->getCreatedRegistration()->join_url; - break; - } else { // no registration possible, join anonymously - $url = $meetingInfoGet->join_url; - break; - } - } // else 'finished' - try next - } - if (is_null($url)) { - $url = $this->createGlobalMeeting()->getMeetingInfoGet()->start_url; + return $meeting; } - return $url; + return $this->createGlobalMeeting(); } /** - * Returns the URL to enter (start or join) a user meeting. + * Returns the URL to enter (start or join) a meeting or null if not possible to enter the meeting, + * The returned URL depends on the meeting current status (waiting, started or finished) and the current user. * * @param MeetingEntity $meeting - * @param bool $autoRegister * * @throws Exception * @throws OptimisticLockException * - * @return string + * @return string|null */ - public function getUserMeetingURL($meeting, $autoRegister = false) + public function getStartOrJoinMeetingURL($meeting) { - $url = null; - $host = $meeting->getUser(); - $participant = api_get_user_entity(api_get_user_id()); - if ($host === $participant) { - $url = $meeting->getMeetingInfoGet()->start_url; - } else { + if ('waiting' === $meeting->getMeetingInfoGet()->status) { + // Zoom does not allow for a new meeting to be started on first participant join. + // It requires the host to start the meeting first. + // Therefore for global meetings we must make the first participant the host + // that is use start_url rather than join_url. + // the participant will not be registered and will appear as the Zoom user account owner. + // For course and user meetings, only the host can start the meeting. + if ($meeting->isGlobalMeeting() && $this->get('enableGlobalConference') + || $meeting->getUser() === api_get_user_entity(api_get_user_id())) { + return $meeting->getMeetingInfoGet()->start_url; + } + } elseif ('started' === $meeting->getMeetingInfoGet()->status) { if ('true' === $this->get('enableParticipantRegistration') && $meeting->requiresRegistration()) { + // the participant must be registered + $participant = api_get_user_entity(api_get_user_id()); $registrant = $meeting->getRegistrant($participant); - if (is_null($registrant)) { // not registered yet - if (!$autoRegister) { - throw new Exception(get_lang('YouAreNotRegisteredToThisMeeting')); - } - $registrant = $this->registerUser($meeting, $participant); + if (!is_null($registrant)) { + // the participant is registered + return $registrant->getCreatedRegistration()->join_url; + } + // the participant is not registered, he can join only the global meeting (automatic registration) + if ($meeting->isGlobalMeeting() && $this->get('enableGlobalConference')) { + return $this->registerUser($meeting, $participant)->getCreatedRegistration()->join_url; } - $url = $registrant->getCreatedRegistration()->join_url; - } else { // no registration possible, join anonymously - $url = $meeting->getMeetingInfoGet()->join_url; + } else { + // no registration possible, join anonymously + return $meeting->getMeetingInfoGet()->join_url; } } - return $url; + return null; } /** diff --git a/plugin/zoom/view/meeting.tpl b/plugin/zoom/view/meeting.tpl index 11d3097d80..8f4266347b 100644 --- a/plugin/zoom/view/meeting.tpl +++ b/plugin/zoom/view/meeting.tpl @@ -1,4 +1,13 @@ -

{{ meeting.typeName }} {{ meeting.id }} ({{ meeting.meetingInfoGet.status }})

+

+ {{ meeting.typeName }} {{ meeting.id }} ({{ meeting.meetingInfoGet.status }}) +

+{% if meeting.meetingInfoGet.status != 'finished' %} +

+ + {{ 'EnterMeeting'|get_lang }} + +

+{% endif %} {% if isConferenceManager and meeting.status == 'waiting' %}

@@ -75,4 +84,3 @@ {% endif %} {% endif %} -