Plugin: zoom refactor, use doctrine ids, format code BT#17288

pull/3425/head
Julio Montoya 5 years ago
parent 371b4c2e94
commit d55312762e
  1. 78
      plugin/zoom/Entity/MeetingEntity.php
  2. 15
      plugin/zoom/Entity/RecordingEntity.php
  3. 3
      plugin/zoom/Entity/RegistrantEntity.php
  4. 14
      plugin/zoom/endpoint.php
  5. 2
      plugin/zoom/global.php
  6. 61
      plugin/zoom/join_meeting.php
  7. 5
      plugin/zoom/lib/API/MeetingInfoGet.php
  8. 21
      plugin/zoom/lib/ZoomPlugin.php
  9. 3
      plugin/zoom/meeting.php
  10. 3
      plugin/zoom/view/admin.tpl
  11. 4
      plugin/zoom/view/meeting.tpl
  12. 4
      plugin/zoom/view/start.tpl

@ -53,12 +53,20 @@ class MeetingEntity
/** @var string */
public $statusName;
/**
* @var int the remote zoom meeting identifier
* @ORM\Column(type="bigint")
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue()
*/
protected $id;
/**
* @var int the remote zoom meeting identifier
* @ORM\Column(type="string")
*/
private $id;
protected $meetingId;
/**
* @var User
@ -67,7 +75,7 @@ class MeetingEntity
* )
* @ORM\JoinColumn(name="user_id", nullable=true)
*/
private $user;
protected $user;
/**
* @var Course
@ -76,7 +84,7 @@ class MeetingEntity
* )
* @ORM\JoinColumn(name="course_id", nullable=true)
*/
private $course;
protected $course;
/**
* @var Session
@ -85,25 +93,25 @@ class MeetingEntity
* )
* @ORM\JoinColumn(name="session_id", nullable=true)
*/
private $session;
protected $session;
/**
* @var string
* @ORM\Column(type="text", name="meeting_list_item_json", nullable=true)
*/
private $meetingListItemJson;
protected $meetingListItemJson;
/**
* @var string
* @ORM\Column(type="text", name="meeting_info_get_json", nullable=true)
*/
private $meetingInfoGetJson;
protected $meetingInfoGetJson;
/** @var MeetingListItem */
private $meetingListItem;
protected $meetingListItem;
/** @var MeetingInfoGet */
private $meetingInfoGet;
protected $meetingInfoGet;
/**
* @var RegistrantEntity[]|ArrayCollection
@ -114,7 +122,7 @@ class MeetingEntity
* cascade={"persist", "remove"}
* )
*/
private $registrants;
protected $registrants;
/**
* @var RecordingEntity[]|ArrayCollection
@ -123,7 +131,7 @@ class MeetingEntity
* mappedBy="meeting",
* )
*/
private $recordings;
protected $recordings;
public function __construct()
{
@ -147,6 +155,26 @@ class MeetingEntity
return $this->id;
}
/**
* @return int
*/
public function getMeetingId()
{
return $this->meetingId;
}
/**
* @param int $meetingId
*
* @return MeetingEntity
*/
public function setMeetingId($meetingId)
{
$this->meetingId = $meetingId;
return $this;
}
/**
* @return User
*/
@ -287,9 +315,9 @@ class MeetingEntity
*/
public function setMeetingListItem($meetingListItem)
{
if (is_null($this->id)) {
$this->id = $meetingListItem->id;
} elseif ($this->id != $meetingListItem->id) {
if (null === $this->meetingId) {
$this->meetingId = $meetingListItem->id;
} elseif ($this->meetingId != $meetingListItem->id) {
throw new Exception('the MeetingEntity identifier differs from the MeetingListItem identifier');
}
$this->meetingListItem = $meetingListItem;
@ -306,9 +334,9 @@ class MeetingEntity
*/
public function setMeetingInfoGet($meetingInfoGet)
{
if (null === $this->id) {
$this->id = $meetingInfoGet->id;
} elseif ($this->id != $meetingInfoGet->id) {
if (null === $this->meetingId) {
$this->meetingId = $meetingInfoGet->id;
} elseif ($this->meetingId != $meetingInfoGet->id) {
throw new Exception('the MeetingEntity identifier differs from the MeetingInfoGet identifier');
}
$this->meetingInfoGet = $meetingInfoGet;
@ -322,7 +350,7 @@ class MeetingEntity
*/
public function isCourseMeeting()
{
return !is_null($this->course);
return null !== $this->course;
}
/**
@ -330,7 +358,7 @@ class MeetingEntity
*/
public function isUserMeeting()
{
return !is_null($this->user) && is_null($this->course);
return null !== $this->user && null === $this->course;
}
/**
@ -338,7 +366,7 @@ class MeetingEntity
*/
public function isGlobalMeeting()
{
return is_null($this->user) && is_null($this->course);
return null === $this->user && null === $this->course;
}
public function setStatus($status)
@ -354,20 +382,19 @@ class MeetingEntity
*/
public function getRegistrableUsers()
{
/** @var User[] $users */
$users = [];
if (!$this->isCourseMeeting()) {
$criteria = ['active' => true];
$users = Database::getManager()->getRepository('ChamiloUserBundle:User')->findBy($criteria);
} elseif (is_null($this->session)) {
if (!is_null($this->course)) {
} elseif (null === $this->session) {
if (null !== $this->course) {
/** @var CourseRelUser $courseRelUser */
foreach ($this->course->getUsers() as $courseRelUser) {
$users[] = $courseRelUser->getUser();
}
}
} else {
if (!is_null($this->course)) {
if (null !== $this->course) {
$subscriptions = $this->session->getUserCourseSubscriptionsByStatus($this->course, Session::STUDENT);
if ($subscriptions) {
/** @var SessionRelCourseRelUser $sessionCourseUser */
@ -377,6 +404,7 @@ class MeetingEntity
}
}
}
$activeUsersWithEmail = [];
foreach ($users as $user) {
if ($user->isActive() && !empty($user->getEmail())) {
@ -460,7 +488,7 @@ class MeetingEntity
if ($this->user) {
$introduction .= sprintf('<p>%s</p>', $this->user->getFullname());
} elseif ($this->isCourseMeeting()) {
if (is_null($this->session)) {
if (null === $this->session) {
$introduction .= sprintf('<p class="main">%s</p>', $this->course);
} else {
$introduction .= sprintf('<p class="main">%s (%s)</p>', $this->course, $this->session);

@ -40,8 +40,15 @@ class RecordingEntity
/**
* @var string
* @ORM\Column(type="string")
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue()
*/
private $id;
/**
* @var string
* @ORM\Column(type="string")
*/
private $uuid;
@ -128,14 +135,14 @@ class RecordingEntity
*/
public function setRecordingMeeting($recordingMeeting)
{
if (is_null($this->uuid)) {
if (null === $this->uuid) {
$this->uuid = $recordingMeeting->uuid;
} elseif ($this->uuid !== $recordingMeeting->uuid) {
throw new Exception('the RecordingEntity identifier differs from the RecordingMeeting identifier');
}
if (is_null($this->meeting)) {
if (null === $this->meeting) {
$this->meeting = Database::getManager()->getRepository(MeetingEntity::class)->find($recordingMeeting->id);
// $this->meeting remains null when the remote RecordingMeeting refers to a deleted meeting
// $this->meeting remains null when the remote RecordingMeeting refers to a deleted meeting
} elseif ($this->meeting->getId() != $recordingMeeting->id) {
throw new Exception('The RecordingEntity meeting id differs from the RecordingMeeting meeting id');
}

@ -28,9 +28,10 @@ class RegistrantEntity
{
/** @var string */
public $fullName;
/**
* @var string
* @ORM\Column(type="bigint")
* @ORM\Column(type="integer")
* @ORM\Id
* @ORM\GeneratedValue(strategy="AUTO")
*/

@ -14,7 +14,7 @@ if ('POST' !== $_SERVER['REQUEST_METHOD']) {
exit;
}
// TODO handle non-apache installations
// @todo handle non-apache installations
$authorizationHeaderValue = apache_request_headers()['Authorization'];
require __DIR__.'/config.php';
@ -31,6 +31,7 @@ if (is_null($decoded) || !is_object($decoded) || !isset($decoded->event) || !iss
http_response_code(Response::HTTP_UNPROCESSABLE_ENTITY);
exit;
}
$object = $decoded->payload->object;
list($objectType, $action) = explode('.', $decoded->event);
@ -43,17 +44,22 @@ switch ($objectType) {
$meetingEntity = null;
if ($object->id) {
$meetingEntity = $meetingRepository->find($object->id);
/** @var MeetingEntity $meetingEntity */
$meetingEntity = $meetingRepository->findBy(['meetingId' => $object->id]);
}
error_log("Meeting: $action");
switch ($action) {
case 'deleted':
if (null !== $meetingEntity) {
error_log('Meeting deleted '.$meetingEntity->getId());
$em->remove($meetingEntity);
}
break;
case 'ended':
case 'started':
error_log("Meeting $action #".$meetingEntity->getId());
$em->persist(
(
$meetingEntity->setStatus($action)
@ -64,6 +70,7 @@ switch ($objectType) {
break;
case 'participant_joined':
case 'participant_left':
// @todo check find
$registrant = $registrantRepository->find($object->participant->id);
if (null === $registrant) {
exit;
@ -81,9 +88,10 @@ switch ($objectType) {
$recordingEntity = null;
if ($object->uuid) {
$recordingEntity = $recordingRepository->find($object->uuid);
$recordingEntity = $recordingRepository->findBy(['uuid' => $object->uuid]);
}
error_log("Recording: $action");
switch ($action) {
case 'completed':
$em->persist(

@ -10,4 +10,4 @@ if (!ZoomPlugin::currentUserCanJoinGlobalMeeting()) {
api_not_allowed(true);
}
api_location('join_meeting.php?meetingId='.ZoomPlugin::create()->getGlobalMeeting()->getId());
api_location('join_meeting.php?meetingId='.ZoomPlugin::create()->getGlobalMeeting()->getMeetingId());

@ -1,49 +1,52 @@
<?php
/* For license terms, see /license.txt */
use Chamilo\PluginBundle\Zoom\MeetingEntity;
require_once __DIR__.'/config.php';
api_block_anonymous_users();
$course_plugin = 'zoom'; // needed in order to load the plugin lang variables
require_once __DIR__.'/config.php';
if (!api_user_is_login()) {
$meetingId = isset($_REQUEST['meetingId']) ? (int) $_REQUEST['meetingId'] : 0;
if (empty($meetingId)) {
api_not_allowed(true);
exit(); // just in case
}
$plugin = ZoomPlugin::create();
Display::display_header($plugin->get_title());
echo $plugin->getToolbar();
if (array_key_exists('meetingId', $_REQUEST)) {
/** @var MeetingEntity $meeting */
$meeting = $plugin->getMeetingRepository()->find($_REQUEST['meetingId']);
try {
if (is_null($meeting)) {
throw new Exception($plugin->get_lang('Meeting not found'));
}
$startJoinURL = $plugin->getStartOrJoinMeetingURL($meeting);
echo $meeting->getIntroduction();
if (!empty($startJoinURL)) {
echo Display::url($plugin->get_lang('EnterMeeting'), $startJoinURL, ['class' => 'btn btn-primary']);
} else {
echo Display::return_message($plugin->get_lang('ConferenceNotStarted'), 'warning');
}
if ($plugin->userIsConferenceManager($meeting)) {
echo '&nbsp;'.Display::url(
get_lang('Details'),
api_get_path(WEB_PLUGIN_PATH).'zoom/meeting_from_admin.php?meetingId='.$meeting->getId(),
['class' => 'btn btn-default']
);
}
} catch (Exception $exception) {
Display::addFlash(
Display::return_message($exception->getMessage(), 'error')
/** @var MeetingEntity $meeting */
$meeting = $plugin->getMeetingRepository()->findOneBy(['meetingId' => $_REQUEST['meetingId']]);
try {
if (null === $meeting) {
throw new Exception($plugin->get_lang('Meeting not found'));
}
$startJoinURL = $plugin->getStartOrJoinMeetingURL($meeting);
echo $meeting->getIntroduction();
if (!empty($startJoinURL)) {
echo Display::url($plugin->get_lang('EnterMeeting'), $startJoinURL, ['class' => 'btn btn-primary']);
} else {
echo Display::return_message($plugin->get_lang('ConferenceNotStarted'), 'warning');
}
if ($plugin->userIsConferenceManager($meeting)) {
echo '&nbsp;'.Display::url(
get_lang('Details'),
api_get_path(WEB_PLUGIN_PATH).'zoom/meeting_from_admin.php?meetingId='.$meeting->getMeetingId(),
['class' => 'btn btn-default']
);
}
} catch (Exception $exception) {
Display::addFlash(
Display::return_message($exception->getMessage(), 'error')
);
}
Display::display_footer();

@ -1,4 +1,5 @@
<?php
/* For licensing terms, see /license.txt */
namespace Chamilo\PluginBundle\Zoom\API;
@ -7,9 +8,7 @@ use Exception;
/**
* Class MeetingInfoGet
* Full Meeting as returned by the server, with unique identifiers and current status.
*
* @package Chamilo\PluginBundle\Zoom\API
* Full Meeting as returned by the server, with unique identifiers and current status. *
*/
class MeetingInfoGet extends MeetingInfo
{

@ -674,9 +674,9 @@ class ZoomPlugin extends Plugin
Display::return_message($this->get_lang('GroupUsersWereRegistered'))
);
}
api_location('meeting_from_start.php?meetingId='.$newMeeting->getId());
} elseif (!is_null($user)) {
api_location('meeting_from_user.php?meetingId='.$newMeeting->getId());
api_location('meeting_from_start.php?meetingId='.$newMeeting->getMeetingId());
} elseif (null !== $user) {
api_location('meeting_from_user.php?meetingId='.$newMeeting->getMeetingId());
}
} catch (Exception $exception) {
Display::addFlash(
@ -851,6 +851,7 @@ class ZoomPlugin extends Plugin
public function getStartOrJoinMeetingURL($meeting)
{
$status = $meeting->getMeetingInfoGet()->status;
$currentUser = api_get_user_entity(api_get_user_id());
switch ($status) {
case 'waiting':
@ -860,23 +861,24 @@ class ZoomPlugin extends Plugin
// 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())) {
if (
($meeting->isGlobalMeeting() && $this->get('enableGlobalConference')) ||
$currentUser === $meeting->getUser()
) {
return $meeting->getMeetingInfoGet()->start_url;
}
break;
case 'started':
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 (null != $registrant) {
$registrant = $meeting->getRegistrant($currentUser);
if (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;
return $this->registerUser($meeting, $currentUser)->getCreatedRegistration()->join_url;
}
}
break;
@ -1095,6 +1097,7 @@ class ZoomPlugin extends Plugin
if (empty($user->getEmail())) {
throw new Exception($this->get_lang('CannotRegisterWithoutEmailAddress'));
}
$meetingRegistrant = MeetingRegistrant::fromEmailAndFirstName(
$user->getEmail(),
$user->getFirstname(),

@ -27,7 +27,8 @@ if (!array_key_exists('meetingId', $_REQUEST)) {
}
/** @var MeetingEntity $meeting */
$meeting = $plugin->getMeetingRepository()->find($_REQUEST['meetingId']);
$meeting = $plugin->getMeetingRepository()->findOneBy(['meetingId' => $_REQUEST['meetingId']]);
if (null === $meeting) {
throw new Exception($plugin->get_lang('MeetingNotFound'));
}

@ -26,6 +26,7 @@
<td>{{ meeting.user ? meeting.user : '-' }}</td>
<td>{{ meeting.course ? meeting.course : '-' }}</td>
<td>{{ meeting.session ? meeting.session : '-' }}</td>
{% if recordings %}
<td>
{% for recording in recordings %}
@ -51,7 +52,7 @@
</td>
{% endif %}
<td>
<a class="btn btn-primary" href="meeting_from_admin.php?meetingId={{ meeting.id }}">
<a class="btn btn-primary" href="meeting_from_admin.php?meetingId={{ meeting.meetingId }}">
{{ 'Details'|get_lang }}
</a>
</td>

@ -1,10 +1,10 @@
<h4>
{{ meeting.typeName }} {{ meeting.id }} ({{ meeting.meetingInfoGet.status }})
{{ meeting.typeName }} {{ meeting.meetingId }} ({{ meeting.meetingInfoGet.status }})
</h4>
{% if meeting.meetingInfoGet.status != 'finished' %}
<p>
<a class="btn btn-primary" href="join_meeting.php?meetingId={{ meeting.id }}">
<a class="btn btn-primary" href="join_meeting.php?meetingId={{ meeting.meetingId }}">
{{ 'ViewMeeting'|get_plugin_lang('ZoomPlugin') }}
</a>
</p>

@ -29,12 +29,12 @@
{{ 'Join'|get_plugin_lang('ZoomPlugin') }}
</a>
<a class="btn btn-default" href="meeting_from_start.php?meetingId={{ meeting.id }}">
<a class="btn btn-default" href="meeting_from_start.php?meetingId={{ meeting.meetingId }}">
{{ 'Edit'|get_lang }}
</a>
<a class="btn btn-danger"
href="start.php?action=delete&meetingId={{ meeting.id }}"
href="start.php?action=delete&meetingId={{ meeting.meetingId }}"
onclick="javascript:if(!confirm('{{ 'AreYouSureToDelete' | get_lang }}')) return false;"
>
{{ 'Delete'|get_lang }}

Loading…
Cancel
Save