Minor code style fix - refs BT#17288

pull/3274/head
Sébastien Ducoulombier 6 years ago
parent c99cac23f8
commit c763a2a618
  1. 2
      plugin/zoom/API/CreatedRegistration.php
  2. 115
      plugin/zoom/API/JWTClient.php
  3. 18
      plugin/zoom/API/Meeting.php
  4. 2
      plugin/zoom/API/MeetingInfo.php
  5. 4
      plugin/zoom/API/MeetingListItem.php
  6. 3
      plugin/zoom/API/MeetingRegistrantListItem.php
  7. 44
      plugin/zoom/API/MeetingSettings.php
  8. 8
      plugin/zoom/API/Pagination.php
  9. 8
      plugin/zoom/API/PastMeeting.php
  10. 303
      plugin/zoom/lib/zoom_plugin.class.php
  11. 4
      plugin/zoom/meeting.php
  12. 4
      plugin/zoom/start.php

@ -5,7 +5,7 @@ namespace Chamilo\PluginBundle\Zoom;
class CreatedRegistration
{
/** @var integer meeting ID */
/** @var int meeting ID */
public $id;
/** @var string Unique URL for this registrant to join the meeting.

@ -4,10 +4,10 @@
namespace Chamilo\PluginBundle\Zoom;
use Exception;
use \Firebase\JWT\JWT;
use Firebase\JWT\JWT;
/**
* Class JWTClient
* Class JWTClient.
*
* @see https://marketplace.zoom.us/docs/api-reference/zoom-api
* @package Chamilo\PluginBundle\Zoom
@ -23,9 +23,9 @@ class JWTClient
/**
* JWTClient constructor.
* Requires a JWT app credentials.
* Requires JWT app credentials.
*
* @param string $apiKey JWT API Key
* @param string $apiKey JWT API Key
* @param string $apiSecret JWT API Secret
*/
public function __construct($apiKey, $apiSecret)
@ -45,13 +45,15 @@ class JWTClient
* On success, returns the body of the response
* On error, throws an exception with an detailed error message
*
* @param string $httpMethod GET, POST, PUT, DELETE ...
* @param string $httpMethod GET, POST, PUT, DELETE ...
* @param string $relativeQueryString what to append to URL https://api.zoom.us/v2/
* @param object $requestBody json-encoded body of the request
* @return object json-decoded body of the response
* @param object $requestBody json-encoded body of the request
*
* @throws Exception describing the error (message and code)
*
* @return object json-decoded body of the response
*/
protected function send($httpMethod, $relativeQueryString, $requestBody = null)
public function send($httpMethod, $relativeQueryString, $requestBody = null)
{
$options = [
CURLOPT_URL => "https://api.zoom.us/v2/$relativeQueryString",
@ -111,36 +113,27 @@ class JWTClient
/**
* Returns the list of Zoom user permissions.
*
* @return string[] Zoom user permissions
* @throws Exception describing the error (message and code)
*
* @return string[] Zoom user permissions
*/
public function userPermissions()
{
return $this->send('GET', '/users/me/permissions')->permissions;
}
/**
* Double-encodes a string.
* Used for meeting UUIDs that are inserted into a URL.
*
* @param string $string the string to double-encode
* @return string double-encoded string
*/
private function doubleEncode($string)
{
return htmlentities($string, ENT_COMPAT, 'utf-8', true);
}
/**
* Retrieves a limited list of meetings.
*
* @param string $type MEETING_TYPE_SCHEDULED, MEETING_TYPE_LIVE or MEETING_TYPE_UPCOMING
* @param int $pageNumber number of the result page to be returned, starts at 1
* @param int $pageSize how many meetings can fit in one page
* @return MeetingList|object list of meetings
* @param string $type MEETING_TYPE_SCHEDULED, MEETING_TYPE_LIVE or MEETING_TYPE_UPCOMING
* @param int $pageNumber number of the result page to be returned, starts at 1
* @param int $pageSize how many meetings can fit in one page
*
* @throws Exception describing the error (message and code)
*
* @return MeetingList|object list of meetings
*/
protected function listMeetings($type, $pageNumber = 1, $pageSize = 30)
public function listMeetings($type, $pageNumber = 1, $pageSize = 30)
{
return $this->send('GET', "users/me/meetings?type=$type&page_size=$pageSize&page_number=$pageNumber");
}
@ -149,8 +142,10 @@ class JWTClient
* Gets a full list of meetings.
*
* @param string $type MEETING_TYPE_SCHEDULED, MEETING_TYPE_LIVE or MEETING_TYPE_UPCOMING
* @return MeetingListItem[] meetings
*
* @throws Exception describing the error (message and code)
*
* @return MeetingListItem[] meetings
*/
public function listAllMeetings($type)
{
@ -158,7 +153,7 @@ class JWTClient
$pageCount = 1;
$pageSize = 300;
$totalRecords = 0;
for ($pageNumber = 1; $pageNumber <= $pageCount; $pageNumber ++) {
for ($pageNumber = 1; $pageNumber <= $pageCount; $pageNumber++) {
$response = $this->listMeetings($type, $pageNumber, $pageSize);
if (!is_null($response)) {
$meetings = array_merge($meetings, $response->meetings);
@ -172,6 +167,7 @@ class JWTClient
if (count($meetings) !== $totalRecords) {
error_log('Zoom announced '.$totalRecords.' records but returned '.count($meetings));
}
return $meetings;
}
@ -179,8 +175,10 @@ class JWTClient
* Retrieves the list of ended meeting instances.
*
* @param int $meetingId meeting ID
* @return MeetingInstances|object list of meeting instances
*
* @throws Exception describing the error (message and code)
*
* @return MeetingInstances|object list of meeting instances
*/
public function listEndedMeetingInstances($meetingId)
{
@ -191,8 +189,10 @@ class JWTClient
* Creates a meeting and returns it.
*
* @param Meeting $meeting meeting to create with at lead $topic and $type
* @return Meeting|object meeting
*
* @throws Exception describing the error (message and code)
*
* @return Meeting|object meeting
*/
public function createMeeting($meeting)
{
@ -203,8 +203,10 @@ class JWTClient
* Retrieves a meeting.
*
* @param int $meetingId meeting identifier
* @return Meeting|object meeting
*
* @throws Exception describing the error (message and code)
*
* @return Meeting|object meeting
*/
public function getMeeting($meetingId)
{
@ -214,8 +216,9 @@ class JWTClient
/**
* Updates a meeting's attributes.
*
* @param int $meetingId meeting identifier
* @param int $meetingId meeting identifier
* @param Meeting $meeting modified meeting object (only need modified properties)
*
* @throws Exception describing the error (message and code)
*/
public function updateMeeting($meetingId, $meeting)
@ -227,6 +230,7 @@ class JWTClient
* Ends a meeting.
*
* @param int $meetingId meeting identifier
*
* @throws Exception describing the error (message and code)
*/
public function endMeeting($meetingId)
@ -238,6 +242,7 @@ class JWTClient
* Deletes a meeting.
*
* @param int $meetingId meeting identifier
*
* @throws Exception describing the error (message and code)
*/
public function deleteMeeting($meetingId)
@ -248,11 +253,13 @@ class JWTClient
/**
* Adds a meeting registrant.
*
* @param int $meetingId meeting identifier
* @param int $meetingId meeting identifier
* @param MeetingRegistrant $registrant with at least 'email' and 'first_name'
* @param string $occurrenceIds separated by comma
* @return CreatedRegistration|object with unique join_url and registrant_id properties
* @param string $occurrenceIds separated by comma
*
* @throws Exception describing the error (message and code)
*
* @return CreatedRegistration|object with unique join_url and registrant_id properties
*/
public function addMeetingRegistrant($meetingId, $registrant, $occurrenceIds = '')
{
@ -260,6 +267,7 @@ class JWTClient
if (!empty($occurrenceIds)) {
$path .= "?occurrence_ids=$occurrenceIds";
}
return $this->send('POST', $path, $registrant);
}
@ -277,8 +285,10 @@ class JWTClient
* Retrieves a past meeting's details.
*
* @param string $meetingUUID the meeting UUID
* @return PastMeeting|object meeting
*
* @throws Exception describing the error (message and code)
*
* @return PastMeeting|object meeting
*/
public function getPastMeetingDetails($meetingUUID)
{
@ -290,8 +300,10 @@ class JWTClient
* The recording files can be downloaded via the `download_url` property listed in the response.
*
* @param $meetingUUID
* @return object an object with string property 'share_url' and array property 'recording_files'
*
* @throws Exception describing the error (message and code)
*
* @return object an object with string property 'share_url' and array property 'recording_files'
*/
public function listRecordings($meetingUUID)
{
@ -302,10 +314,12 @@ class JWTClient
* Retrieves information on participants from a past meeting.
*
* @param string $meetingUUID the meeting instance UUID
* @param int $pageNumber
* @param int $pageSize
* @param int $pageNumber
* @param int $pageSize
*
* @throws Exception describing the error (message and code)
*
* @return ParticipantList|object
* @throws Exception
*/
public function getParticipants($meetingUUID, $pageNumber = 1, $pageSize = 30)
{
@ -321,8 +335,10 @@ class JWTClient
* Gets a full list of participants.
*
* @param string $meetingUUID the meeting instance UUID
* @return ParticipantListItem[] participants
*
* @throws Exception describing the error (message and code)
*
* @return ParticipantListItem[] participants
*/
public function getAllParticipants($meetingUUID)
{
@ -330,7 +346,7 @@ class JWTClient
$pageCount = 1;
$pageSize = 300;
$totalRecords = 0;
for ($pageNumber = 1; $pageNumber <= $pageCount; $pageNumber ++) {
for ($pageNumber = 1; $pageNumber <= $pageCount; $pageNumber++) {
$response = $this->getParticipants($meetingUUID, $pageNumber, $pageSize);
if (!is_null($response)) {
$participants = array_merge($participants, $response->participants);
@ -344,6 +360,21 @@ class JWTClient
if (count($participants) !== $totalRecords) {
error_log('Zoom announced '.$totalRecords.' records but returned '.count($participants));
}
return $participants;
}
/**
* Double-encodes a string.
* Used for meeting UUIDs that are inserted into a URL.
*
* @param string $string the string to double-encode
*
* @return string double-encoded string
*/
private function doubleEncode($string)
{
return htmlentities($string, ENT_COMPAT, 'utf-8', true);
}
}

@ -5,26 +5,27 @@ namespace Chamilo\PluginBundle\Zoom;
class Meeting
{
/** @var string */
public $topic;
/** @var integer */
public $type;
const TYPE_INSTANT = 1;
const TYPE_SCHEDULED = 2;
const TYPE_RECURRING_WITH_NO_FIXED_TIME = 3;
const TYPE_RECURRING_WITH_FIXED_TIME = 8;
/** @var string */
public $topic;
/** @var int */
public $type;
/** @var string "yyyy-MM-dd'T'HH:mm:ss'Z'" for GMT, same without 'Z' for local time (as set on zoom account) */
public $start_time;
/** @var integer in minutes, for scheduled meetings only */
/** @var int in minutes, for scheduled meetings only */
public $duration;
/** @var string the timezone for start_time */
public $timezone;
/** @var string password to join. [a-z A-Z 0-9 @ - _ *]. Max of 10 characters.*/
/** @var string password to join. [a-z A-Z 0-9 @ - _ *]. Max of 10 characters. */
public $password;
/** @var string description */
@ -41,8 +42,9 @@ class Meeting
/**
* Meeting constructor.
*
* @param string $topic
* @param int $type
* @param int $type
*/
public function __construct($topic, $type = self::TYPE_SCHEDULED)
{

@ -13,7 +13,7 @@ class MeetingInfo extends Meeting
public $join_url;
/** @var string H.323/SIP room system password */
public $h323_password;
/** @var integer Personal Meeting Id. Only used for scheduled meetings and recurring meetings with no fixed time */
/** @var int Personal Meeting Id. Only used for scheduled meetings and recurring meetings with no fixed time */
public $pmi;
/** @var object[] */
public $occurrences;

@ -17,13 +17,13 @@ class MeetingListItem
/** @var string */
public $topic;
/** @var integer @see Meeting */
/** @var int @see Meeting */
public $type;
/** @var string */
public $start_time;
/** @var integer in minutes */
/** @var int in minutes */
public $duration;
/** @var string */

@ -1,9 +1,8 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\PluginBundle\Zoom;
class MeetingRegistrantListItem extends MeetingRegistrant
{
/** @var string Registrant ID. */

@ -5,48 +5,50 @@ namespace Chamilo\PluginBundle\Zoom;
class MeetingSettings
{
/** @var boolean Start video when the host joins the meeting */
const APPROVAL_TYPE_AUTOMATICALLY_APPROVE = 0;
const APPROVAL_TYPE_MANUALLY_APPROVE = 1;
const APPROVAL_TYPE_NO_REGISTRATION_REQUIRED = 2;
const REGISTRATION_TYPE_REGISTER_ONCE_ATTEND_ANY = 1;
const REGISTRATION_TYPE_REGISTER_EACH = 2;
const REGISTRATION_TYPE_REGISTER_ONCE_CHOOSE = 3;
/** @var bool Start video when the host joins the meeting */
public $host_video;
/** @var boolean Start video when participants join the meeting */
/** @var bool Start video when participants join the meeting */
public $participant_video;
/** @var boolean Host meeting in China */
/** @var bool Host meeting in China */
public $cn_meeting;
/** @var boolean Host meeting in India */
/** @var bool Host meeting in India */
public $in_meeting;
/** @var boolean Allow participants to join the meeting before the host starts the meeting.
/** @var bool Allow participants to join the meeting before the host starts the meeting.
* Only used for scheduled or recurring meetings.
*/
public $join_before_host;
/** @var boolean Mute participants upon entry */
/** @var bool Mute participants upon entry */
public $mute_upon_entry;
/** @var boolean Add watermark when viewing a shared screen */
/** @var bool Add watermark when viewing a shared screen */
public $watermark;
/** @var boolean Use a personal meeting ID.
/** @var bool Use a personal meeting ID.
* Only used for scheduled meetings and recurring meetings with no fixed time.
*/
public $use_pmi;
/** @var integer Enable registration and set approval for the registration.
/** @var int Enable registration and set approval for the registration.
* Note that this feature requires the host to be of **Licensed** user type.
* **Registration cannot be enabled for a basic user.**
*/
public $approval_type;
const APPROVAL_TYPE_AUTOMATICALLY_APPROVE = 0;
const APPROVAL_TYPE_MANUALLY_APPROVE = 1;
const APPROVAL_TYPE_NO_REGISTRATION_REQUIRED = 2;
/** @var integer Used for recurring meeting with fixed time only. */
/** @var int Used for recurring meeting with fixed time only. */
public $registration_type;
const REGISTRATION_TYPE_REGISTER_ONCE_ATTEND_ANY = 1;
const REGISTRATION_TYPE_REGISTER_EACH = 2;
const REGISTRATION_TYPE_REGISTER_ONCE_CHOOSE = 3;
/** @var string either both, telephony or voip */
public $audio;
@ -57,10 +59,10 @@ class MeetingSettings
/** @var string Alternative host's emails or IDs: multiple values separated by a comma. */
public $alternative_hosts;
/** @var boolean Close registration after event date */
/** @var bool Close registration after event date */
public $close_registration;
/** @var boolean Enable waiting room */
/** @var bool Enable waiting room */
public $waiting_room;
/** @var string[] List of global dial-in countries */
@ -75,15 +77,15 @@ class MeetingSettings
/** @var string Contact email for registration */
public $contact_email;
/** @var boolean Send confirmation email to registrants upon successful registration */
/** @var bool Send confirmation email to registrants upon successful registration */
public $registrants_confirmation_email;
/** @var boolean Send email notifications to registrants about approval, cancellation, denial of the registration.
/** @var bool Send email notifications to registrants about approval, cancellation, denial of the registration.
* The value of this field must be set to true in order to use the `registrants_confirmation_email` field.
*/
public $registrants_email_notification;
/** @var boolean Only authenticated users can join meetings. */
/** @var bool Only authenticated users can join meetings. */
public $meeting_authentication;
/** @var string Meeting authentication option id. */

@ -5,12 +5,12 @@ namespace Chamilo\PluginBundle\Zoom;
class Pagination
{
/** @var integer */
/** @var int */
public $page_count;
/** @var integer counting from 1 */
/** @var int counting from 1 */
public $page_number;
/** @var integer */
/** @var int */
public $page_size;
/** @var integer */
/** @var int */
public $total_records;
}

@ -17,7 +17,7 @@ class PastMeeting extends Meeting
/** @var string */
public $topic;
/** @var integer @see Meeting */
/** @var int @see Meeting */
public $type;
/** @var string user display name */
@ -32,12 +32,12 @@ class PastMeeting extends Meeting
/** @var string "yyyy-MM-dd'T'HH:mm:ss'Z'" (GMT) */
public $end_time;
/** @var integer in minutes, for scheduled meetings only */
/** @var int in minutes, for scheduled meetings only */
public $duration;
/** @var integer sum of meeting minutes from all participants in the meeting. */
/** @var int sum of meeting minutes from all participants in the meeting. */
public $total_minutes;
/** @var integer number of meeting participants */
/** @var int number of meeting participants */
public $participants_count;
}

@ -28,20 +28,6 @@ class ZoomPlugin extends Plugin
$this->isAdminPlugin = true;
}
/**
* Caches and returns the JWT client instance, initialized with plugin settings.
*
* @return JWTClient object that provides means of communications with the Zoom servers
*/
protected function jwtClient()
{
static $jwtClient = null;
if (is_null($jwtClient)) {
$jwtClient = new JWTClient($this->get('apiKey'), $this->get('apiSecret'));
}
return $jwtClient;
}
/**
* Caches and returns an instance of this class.
*
@ -50,6 +36,7 @@ class ZoomPlugin extends Plugin
public static function create()
{
static $instance = null;
return $instance ? $instance : $instance = new self();
}
@ -70,52 +57,15 @@ class ZoomPlugin extends Plugin
}
/**
* @return string a tag to append to a meeting agenda so to link it to a (course, session) tuple
*/
private function agendaTag()
{
$courseId = api_get_course_int_id();
$sessionId = api_get_session_id();
return "\n(course $courseId, session $sessionId)";
}
private function courseIdAndSessionIdFromAgenda($agenda)
{
return preg_match('/course (?P<courseId>\d+), session (?P<sessionId>\d+)/m', $agenda, $matches)
? $matches
: [
'courseId' => 0,
'sessionId' => 0,
];
}
/**
* Retrieves all meetings of a specific type and linked to current course and session
* Retrieves information about meetings having a start_time between two dates.
*
* @param string $type MEETING_TYPE_LIVE, MEETING_TYPE_SCHEDULED or MEETING_TYPE_UPCOMING
* @return MeetingListItem[] matching meetings
* @throws Exception on API error
*/
private function getMeetings($type)
{
$matchingMeetings = [];
$tag = $this->agendaTag();
foreach ($this->jwtClient()->listAllMeetings($type) as $meeting) {
if (property_exists($meeting, 'agenda') && substr($meeting->agenda, -strlen($tag)) === $tag) {
$matchingMeetings[] = $meeting;
}
}
return $matchingMeetings;
}
/**
* @param string $type MEETING_TYPE_LIVE, MEETING_TYPE_SCHEDULED or MEETING_TYPE_UPCOMING
* @param string $type MEETING_TYPE_LIVE, MEETING_TYPE_SCHEDULED or MEETING_TYPE_UPCOMING
* @param DateTime $startDate
* @param DateTime $endDate
* @return MeetingListItem[] matching meetings
*
* @throws Exception on API error
*
* @return MeetingListItem[] matching meetings with extra_data
*/
public function getPeriodMeetings($type, $startDate, $endDate)
{
@ -132,7 +82,6 @@ class ZoomPlugin extends Plugin
return $this->computeMeetingExtraData($matchingMeetings);
}
public function userIsConferenceManager()
{
return api_is_coach()
@ -141,48 +90,13 @@ class ZoomPlugin extends Plugin
}
/**
* Computes and append extra data for each listed meeting
* Retrieves a meeting properties and extra_data.
*
* @param MeetingListItem[] $meetings list of retreived meeting objects
* @return Meeting[]|MeetingListItem[] same meetings with extra_data added
* @throws Exception on API error
*/
private function computeMeetingExtraData($meetings)
{
$completeMeetings = [];
$tag = $this->agendaTag();
$typeNames = [
Meeting::TYPE_INSTANT => get_lang('Instant'),
Meeting::TYPE_SCHEDULED => get_lang('Scheduled'),
Meeting::TYPE_RECURRING_WITH_NO_FIXED_TIME => get_lang('RecurringWithNoFixedTime'),
Meeting::TYPE_RECURRING_WITH_FIXED_TIME => get_lang('RecurringWithFixedTime'),
];
$now = new DateTime();
foreach ($meetings as $meeting) {
$completeMeeting = $meeting;
$startTime = new DateTime($meeting->start_time);
$duration = new DateInterval('PT'.$meeting->duration.'M');
$courseIdAndSessionId = $this->courseIdAndSessionIdFromAgenda($meeting->agenda);
$courseId = $courseIdAndSessionId['courseId'];
$sessionId = $courseIdAndSessionId['sessionId'];
$completeMeeting->extra_data = [
'stripped_agenda' => substr($meeting->agenda, 0, -strlen($tag)),
'type_name' => $typeNames[$meeting->type],
'formatted_start_time' => $startTime->format(get_lang('Y-m-d H:i')),
'formatted_duration' => $duration->format(get_lang('%Hh%I')),
'meeting_details_url' => 'meeting.php?meetingId='.$meeting->id,
'course' => api_get_course_info_by_id($courseId),
'session' => api_get_session_info($sessionId),
];
$completeMeetings[] = $completeMeeting;
}
return $completeMeetings;
}
/**
* @param int $meetingId
* @return Meeting
*
* @throws Exception
*
* @return Meeting
*/
public function getMeeting($meetingId)
{
@ -190,10 +104,11 @@ class ZoomPlugin extends Plugin
}
/**
* Retrieves all live meetings linked to current course and session
* Retrieves all live meetings linked to current course and session.
*
* @return Meeting[] matching meetings
* @throws Exception on API error
*
* @return Meeting[] matching meetings
*/
public function getLiveMeetings()
{
@ -201,10 +116,11 @@ class ZoomPlugin extends Plugin
}
/**
* Retrieves all scheduled meetings linked to current course and session
* Retrieves all scheduled meetings linked to current course and session.
*
* @return Meeting[] matching meetings
* @throws Exception on API error
*
* @return Meeting[] matching meetings
*/
public function getScheduledMeetings()
{
@ -212,10 +128,11 @@ class ZoomPlugin extends Plugin
}
/**
* Retrieves all upcoming meetings linked to current course and session
* Retrieves all upcoming meetings linked to current course and session.
*
* @return Meeting[] matching meetings
* @throws Exception on API error
*
* @return Meeting[] matching meetings
*/
public function getUpcomingMeetings()
{
@ -223,33 +140,11 @@ class ZoomPlugin extends Plugin
}
/**
* Creates a meeting and returns it.
* Creates an instant meeting and returns it.
*
* @param Meeting $meeting a meeting with at least a type.
* @param string $topic short title of the meeting, required
* @param string $agenda ordre du jour
* @param string $password meeting password
* @return Meeting|object meeting
* @throws Exception describing the error (message and code)
*/
private function createMeeting($meeting, $topic, $agenda, $password)
{
$meeting->topic = $topic;
$meeting->agenda = $agenda;
$meeting->password = $password;
$meeting->settings->auto_recording = 'cloud';
$meeting->agenda .= $this->agendaTag();
return $this->jwtClient()->createMeeting($meeting);
}
/**
* Creates an instant meeting and returns it.
*
* @param string $topic short title of the meeting, required
* @param string $agenda ordre du jour
* @param string $password meeting password
* @return Meeting|object meeting
* @throws Exception describing the error (message and code)
*/
public function createInstantMeeting()
{
@ -261,6 +156,7 @@ class ZoomPlugin extends Plugin
}
$courseInfo = api_get_course_info();
$topic .= $courseInfo['title'].', '.date('yy-m-d H:i');
return $this->createMeeting(new Meeting(Meeting::TYPE_INSTANT), $topic, '', '');
}
@ -268,18 +164,21 @@ class ZoomPlugin extends Plugin
* Schedules a meeting and returns it.
*
* @param DateTime $startTime meeting local start date-time (configure local timezone on your Zoom account)
* @param int $duration in minutes
* @param string $topic short title of the meeting, required
* @param string $agenda ordre du jour
* @param string $password meeting password
* @return Meeting|object meeting
* @param int $duration in minutes
* @param string $topic short title of the meeting, required
* @param string $agenda ordre du jour
* @param string $password meeting password
*
* @throws Exception describing the error (message and code)
*
* @return Meeting|object meeting
*/
public function createScheduledMeeting($startTime, $duration, $topic, $agenda = '', $password = '')
{
$meeting = new Meeting(Meeting::TYPE_SCHEDULED);
$meeting->duration = $duration;
$meeting->start_time = $startTime->format(DateTimeInterface::ISO8601);
return $this->createMeeting($meeting, $topic, $agenda, $password);
}
@ -287,7 +186,8 @@ class ZoomPlugin extends Plugin
* Updates a meeting.
*
* @param integer $meetingId
* @param Meeting $meeting with updated properties
* @param Meeting $meeting with updated properties
*
* @throws Exception on API error
*/
public function updateMeeting($meetingId, $meeting)
@ -300,6 +200,7 @@ class ZoomPlugin extends Plugin
* Ends a current meeting.
*
* @param integer $meetingId
*
* @throws Exception on API error
*/
public function endMeeting($meetingId)
@ -311,6 +212,7 @@ class ZoomPlugin extends Plugin
* Deletes a meeting.
*
* @param integer $meetingId
*
* @throws Exception on API error
*/
public function deleteMeeting($meetingId)
@ -322,8 +224,10 @@ class ZoomPlugin extends Plugin
* @see JWTClient::listRecordings()
*
* @param $meetingUUID
* @return object
*
* @throws Exception on API error
*
* @return object
*/
public function getRecordings($meetingUUID)
{
@ -334,8 +238,10 @@ class ZoomPlugin extends Plugin
* @see JWTClient::getAllParticipants()
*
* @param $meetingUUID
* @return ParticipantListItem[]
*
* @throws Exception
*
* @return ParticipantListItem[]
*/
public function getParticipants($meetingUUID)
{
@ -343,11 +249,13 @@ class ZoomPlugin extends Plugin
}
/**
* Adds a link to a meeting's recordings
* Adds a link to a meeting's recordings.
*
* @param string $meetingUUID UUID of the meeting
*
* @param string $uuid UUID of the meeting
* @return Link the newly added link
* @throws Exception on API error
*
* @return Link the newly added link
*/
public function copyRecordingToLinkTool($meetingUUID)
{
@ -359,6 +267,129 @@ class ZoomPlugin extends Plugin
'title' => $recordings->topic,
]
);
return $link;
}
/**
* Caches and returns the JWT client instance, initialized with plugin settings.
*
* @return JWTClient object that provides means of communications with the Zoom servers
*/
protected function jwtClient()
{
static $jwtClient = null;
if (is_null($jwtClient)) {
$jwtClient = new JWTClient($this->get('apiKey'), $this->get('apiSecret'));
}
return $jwtClient;
}
/**
* @return string a tag to append to a meeting agenda so to link it to a (course, session) tuple
*/
private function agendaTag()
{
$courseId = api_get_course_int_id();
$sessionId = api_get_session_id();
return "\n(course $courseId, session $sessionId)";
}
private function courseIdAndSessionIdFromAgenda($agenda)
{
return preg_match('/course (?P<courseId>\d+), session (?P<sessionId>\d+)/m', $agenda, $matches)
? $matches
: [
'courseId' => 0,
'sessionId' => 0,
];
}
/**
* Retrieves all meetings of a specific type and linked to current course and session.
*
* @param string $type MEETING_TYPE_LIVE, MEETING_TYPE_SCHEDULED or MEETING_TYPE_UPCOMING
*
* @throws Exception on API error
*
* @return MeetingListItem[] matching meetings
*/
private function getMeetings($type)
{
$matchingMeetings = [];
$tag = $this->agendaTag();
foreach ($this->jwtClient()->listAllMeetings($type) as $meeting) {
if (property_exists($meeting, 'agenda') && substr($meeting->agenda, -strlen($tag)) === $tag) {
$matchingMeetings[] = $meeting;
}
}
return $matchingMeetings;
}
/**
* Computes and append extra data for each listed meeting.
*
* @param MeetingListItem[] $meetings list of retreived meeting objects
*
* @throws Exception on API error
*
* @return Meeting[]|MeetingListItem[] same meetings with extra_data added
*/
private function computeMeetingExtraData($meetings)
{
$completeMeetings = [];
$tag = $this->agendaTag();
$typeNames = [
Meeting::TYPE_INSTANT => get_lang('Instant'),
Meeting::TYPE_SCHEDULED => get_lang('Scheduled'),
Meeting::TYPE_RECURRING_WITH_NO_FIXED_TIME => get_lang('RecurringWithNoFixedTime'),
Meeting::TYPE_RECURRING_WITH_FIXED_TIME => get_lang('RecurringWithFixedTime'),
];
foreach ($meetings as $meeting) {
$completeMeeting = $meeting;
$startTime = new DateTime($meeting->start_time);
$duration = new DateInterval('PT'.$meeting->duration.'M');
$courseIdAndSessionId = $this->courseIdAndSessionIdFromAgenda($meeting->agenda);
$courseId = $courseIdAndSessionId['courseId'];
$sessionId = $courseIdAndSessionId['sessionId'];
$completeMeeting->extra_data = [
'stripped_agenda' => substr($meeting->agenda, 0, -strlen($tag)),
'type_name' => $typeNames[$meeting->type],
'formatted_start_time' => $startTime->format(get_lang('Y-m-d H:i')),
'formatted_duration' => $duration->format(get_lang('%Hh%I')),
'meeting_details_url' => 'meeting.php?meetingId='.$meeting->id,
'course' => api_get_course_info_by_id($courseId),
'session' => api_get_session_info($sessionId),
];
$completeMeetings[] = $completeMeeting;
}
return $completeMeetings;
}
/**
* Creates a meeting and returns it.
*
* @param Meeting $meeting a meeting with at least a type.
* @param string $topic short title of the meeting, required
* @param string $agenda ordre du jour
* @param string $password meeting password
*
* @throws Exception describing the error (message and code)
*
* @return Meeting|object meeting
*/
private function createMeeting($meeting, $topic, $agenda, $password)
{
$meeting->topic = $topic;
$meeting->agenda = $agenda;
$meeting->password = $password;
$meeting->settings->auto_recording = 'cloud';
$meeting->agenda .= $this->agendaTag();
return $this->jwtClient()->createMeeting($meeting);
}
}

@ -39,8 +39,8 @@ if ($plugin->userIsConferenceManager()) {
$durationNumeric = $editMeetingForm->addNumeric('duration', get_lang('Duration'));
}
$topicText = $editMeetingForm->addText('topic', get_lang('Topic'));
$agendaTextArea = $editMeetingForm->addTextarea('agenda', get_lang('Agenda'), [ 'maxlength' => 2000 ]);
// $passwordText = $editMeetingForm->addText('password', get_lang('Password'), false, [ 'maxlength' => '10' ]);
$agendaTextArea = $editMeetingForm->addTextarea('agenda', get_lang('Agenda'), ['maxlength' => 2000]);
// $passwordText = $editMeetingForm->addText('password', get_lang('Password'), false, ['maxlength' => '10']);
$editMeetingForm->addButtonUpdate(get_lang('UpdateMeeting'));
if ($editMeetingForm->validate()) {
$meeting->start_time = $editMeetingForm->getSubmitValue('start_time');

@ -46,8 +46,8 @@ if ($plugin->userIsConferenceManager()) {
$scheduleMeetingForm->setRequired($startTimeDatePicker);
$durationNumeric = $scheduleMeetingForm->addNumeric('duration', get_lang('Duration'));
$topicText = $scheduleMeetingForm->addText('topic', get_lang('Topic'), true);
$agendaTextArea = $scheduleMeetingForm->addTextarea('agenda', get_lang('Agenda'), [ 'maxlength' => 2000 ]);
// $passwordText = $scheduleMeetingForm->addText('password', get_lang('Password'), false, [ 'maxlength' => '10' ]);
$agendaTextArea = $scheduleMeetingForm->addTextarea('agenda', get_lang('Agenda'), ['maxlength' => 2000]);
// $passwordText = $scheduleMeetingForm->addText('password', get_lang('Password'), false, ['maxlength' => '10']);
$scheduleMeetingForm->addButtonCreate(get_lang('ScheduleMeeting'));
// meeting scheduling

Loading…
Cancel
Save