Skip to content

Commit

Permalink
Plugin: Zoom: Allow webinars - refs BT#19479
Browse files Browse the repository at this point in the history
  • Loading branch information
AngelFQC committed Apr 20, 2022
1 parent 2a65680 commit caef076
Show file tree
Hide file tree
Showing 30 changed files with 1,815 additions and 270 deletions.
33 changes: 8 additions & 25 deletions main/calendar/agenda_js.php
Expand Up @@ -92,16 +92,11 @@
if (api_is_anonymous()) {
api_not_allowed(true);
}
$extra_field_data = UserManager::get_extra_user_data_by_field(
api_get_user_id(),
'google_calendar_url'
);
if (!empty($extra_field_data) &&
isset($extra_field_data['google_calendar_url']) &&
!empty($extra_field_data['google_calendar_url'])
) {
$googleCalendarUrl = Agenda::returnGoogleCalendarUrl(api_get_user_id());

if (!empty($googleCalendarUrl)) {
$tpl->assign('use_google_calendar', 1);
$tpl->assign('google_calendar_url', $extra_field_data['google_calendar_url']);
$tpl->assign('google_calendar_url', $googleCalendarUrl);
}
$this_section = SECTION_MYAGENDA;
if (!api_is_anonymous()) {
Expand Down Expand Up @@ -312,23 +307,11 @@
$tpl->assign('form_add', $form->returnForm());
$tpl->assign('legend_list', api_get_configuration_value('agenda_legend'));

$onHoverInfo = api_get_configuration_value('agenda_on_hover_info');
if (!empty($onHoverInfo)) {
$options = $onHoverInfo['options'];
} else {
$options = [
'comment' => true,
'description' => true,
];
}
$tpl->assign('on_hover_info', $options);
$onHoverInfo = Agenda::returnOnHoverInfo();
$tpl->assign('on_hover_info', $onHoverInfo);

$extraSettings = Agenda::returnFullCalendarExtraSettings();

$settings = api_get_configuration_value('fullcalendar_settings');
$extraSettings = '';
if (!empty($settings) && isset($settings['settings']) && !empty($settings['settings'])) {
$encoded = json_encode($settings['settings']);
$extraSettings = substr($encoded, 1, -1).',';
}
$tpl->assign('fullcalendar_settings', $extraSettings);

$templateName = $tpl->get_template('agenda/month.tpl');
Expand Down
38 changes: 38 additions & 0 deletions main/inc/lib/agenda.lib.php
Expand Up @@ -4591,6 +4591,44 @@ public static function getJsForReminders(string $cssSelectorBtnAdd): string
});';
}

public static function returnGoogleCalendarUrl(int $userId): ?string
{
$extraFieldInfo = UserManager::get_extra_user_data_by_field($userId, 'google_calendar_url');

if (empty($extraFieldInfo) || empty($extraFieldInfo['google_calendar_url'])) {
return null;
}

return $extraFieldInfo['google_calendar_url'];
}

public static function returnFullCalendarExtraSettings(): ?string
{
$settings = api_get_configuration_value('fullcalendar_settings');

if (empty($settings) || empty($settings['settings'])) {
return null;
}

$encoded = json_encode($settings['settings']);

return substr($encoded, 1, -1).',';
}

public static function returnOnHoverInfo()
{
$onHoverInfo = api_get_configuration_value('agenda_on_hover_info');

if (!empty($onHoverInfo)) {
return $onHoverInfo['options'];
}

return [
'comment' => true,
'description' => true,
];
}

private function editReminders(int $eventId, array $reminderList = [])
{
if (false === api_get_configuration_value('agenda_reminders')) {
Expand Down
64 changes: 40 additions & 24 deletions plugin/zoom/Entity/Meeting.php
Expand Up @@ -35,6 +35,9 @@
* }
* )
* @ORM\HasLifecycleCallbacks
* @ORM\InheritanceType("SINGLE_TABLE")
* @ORM\DiscriminatorColumn(name="type", type="string")
* @ORM\DiscriminatorMap({"meeting" = "Chamilo\PluginBundle\Zoom\Meeting", "webinar" = "Chamilo\PluginBundle\Zoom\Webinar"})
*/
class Meeting
{
Expand Down Expand Up @@ -151,6 +154,13 @@ class Meeting
*/
protected $recordings;

/**
* @var string|null
*
* @ORM\Column(type="string", name="account_email", nullable=true)
*/
protected $accountEmail;

public function __construct()
{
$this->registrants = new ArrayCollection();
Expand Down Expand Up @@ -498,12 +508,9 @@ public function requiresDateAndDuration()
|| MeetingInfoGet::TYPE_RECURRING_WITH_FIXED_TIME === $this->meetingInfoGet->type;
}

/**
* @return bool
*/
public function requiresRegistration()
public function requiresRegistration(): bool
{
return MeetingSettings::APPROVAL_TYPE_AUTOMATICALLY_APPROVE === $this->meetingInfoGet->settings->approval_type;
return true; //MeetingSettings::APPROVAL_TYPE_AUTOMATICALLY_APPROVE === $this->meetingInfoGet->settings->approval_type;
/*return
MeetingSettings::APPROVAL_TYPE_NO_REGISTRATION_REQUIRED != $this->meetingInfoGet->settings->approval_type;*/
}
Expand All @@ -516,21 +523,7 @@ public function hasCloudAutoRecordingEnabled()
return \ZoomPlugin::RECORDING_TYPE_NONE !== $this->meetingInfoGet->settings->auto_recording;
}

/**
* @param User $user
*
* @return bool
*/
public function hasRegisteredUser($user)
{
return $this->getRegistrants()->exists(
function (int $key, Registrant $registrantEntity) use (&$user) {
return $registrantEntity->getUser() === $user;
}
);
}

public function getRegistrant(User $user): ?Registrant
public function getRegistrantByUser(User $user): ?Registrant
{
$criteria = Criteria::create()
->where(
Expand All @@ -549,7 +542,7 @@ public function getRegistrant(User $user): ?Registrant
*/
public function getIntroduction()
{
$introduction = sprintf('<h1>%s</h1>', $this->meetingInfoGet->topic).PHP_EOL;
$introduction = sprintf('<h1>%s</h1>', $this->getTopic()).PHP_EOL;
if (!$this->isGlobalMeeting()) {
if (!empty($this->formattedStartTime)) {
$introduction .= $this->formattedStartTime;
Expand All @@ -568,8 +561,9 @@ public function getIntroduction()
$introduction .= sprintf('<p class="main">%s (%s)</p>', $this->course, $this->session).PHP_EOL;
}
}
if (!empty($this->meetingInfoGet->agenda)) {
$introduction .= sprintf('<p>%s</p>', $this->meetingInfoGet->agenda).PHP_EOL;

if (!empty($this->getAgenda())) {
$introduction .= sprintf('<p>%s</p>', $this->getAgenda()).PHP_EOL;
}

return $introduction;
Expand All @@ -587,6 +581,18 @@ public function setSignAttendance(bool $signAttendance): Meeting
return $this;
}

public function getAccountEmail(): ?string
{
return $this->accountEmail;
}

public function setAccountEmail(?string $accountEmail): self
{
$this->accountEmail = $accountEmail;

return $this;
}

public function getReasonToSignAttendance(): ?string
{
return $this->reasonToSignAttendance;
Expand All @@ -599,10 +605,20 @@ public function setReasonToSignAttendance(string $reasonToSignAttendance): Meeti
return $this;
}

public function getTopic(): string
{
return $this->meetingInfoGet->topic;
}

public function getAgenda(): ?string
{
return $this->meetingInfoGet->agenda;
}

/**
* @throws Exception on unexpected start_time or duration
*/
private function initializeDisplayableProperties()
protected function initializeDisplayableProperties()
{
$zoomPlugin = new \ZoomPlugin();

Expand Down
6 changes: 1 addition & 5 deletions plugin/zoom/Entity/Registrant.php
Expand Up @@ -219,13 +219,9 @@ public function getMeetingRegistrant()
}

/**
* @param MeetingRegistrant $meetingRegistrant
*
* @throws Exception
*
* @return $this
*/
public function setMeetingRegistrant($meetingRegistrant)
public function setMeetingRegistrant(API\RegistrantSchema $meetingRegistrant): Registrant
{
$this->meetingRegistrant = $meetingRegistrant;
$this->computeFullName();
Expand Down
135 changes: 135 additions & 0 deletions plugin/zoom/Entity/Webinar.php
@@ -0,0 +1,135 @@
<?php

/* For licensing terms, see /license.txt */

namespace Chamilo\PluginBundle\Zoom;

use Chamilo\PluginBundle\Zoom\API\WebinarSchema;
use Chamilo\PluginBundle\Zoom\API\WebinarSettings;
use DateInterval;
use DateTime;
use Doctrine\ORM\Mapping as ORM;
use Exception;
use ZoomPlugin;

/**
* @ORM\Entity()
* @ORM\HasLifecycleCallbacks
*/
class Webinar extends Meeting
{
/**
* @var string
*
* @ORM\Column(name="webinar_schema_json", type="text", nullable=true)
*/
protected $webinarSchemaJson;

/**
* @var WebinarSchema
*/
protected $webinarSchema;

public function preFlush()
{
if (null !== $this->webinarSchema) {
$this->webinarSchemaJson = json_encode($this->webinarSchema);
}
}

public function postLoad()
{
if (null !== $this->webinarSchemaJson) {
$this->webinarSchema = WebinarSchema::fromJson($this->webinarSchemaJson);
}

$this->initializeDisplayableProperties();
}

/**
* @throws Exception
*/
public function setWebinarSchema(WebinarSchema $webinarSchema): Webinar
{
if (null === $this->meetingId) {
$this->meetingId = $webinarSchema->id;
} elseif ($this->meetingId != $webinarSchema->id) {
throw new Exception('the Meeting identifier differs from the MeetingInfoGet identifier');
}

$this->webinarSchema = $webinarSchema;

$this->initializeDisplayableProperties();

return $this;
}

public function getWebinarSchema(): WebinarSchema
{
return $this->webinarSchema;
}

public function hasCloudAutoRecordingEnabled(): bool
{
return $this->webinarSchema->settings->auto_recording !== ZoomPlugin::RECORDING_TYPE_NONE;
}

public function requiresDateAndDuration(): bool
{
return WebinarSchema::TYPE_WEBINAR == $this->webinarSchema->type;
}

public function requiresRegistration(): bool
{
return in_array(
$this->webinarSchema->settings->approval_type,
[
WebinarSettings::APPROVAL_TYPE_AUTOMATICALLY_APPROVE,
WebinarSettings::APPROVAL_TYPE_MANUALLY_APPROVE,
]
);
}

public function getTopic(): string
{
return $this->webinarSchema->topic;
}

public function getAgenda(): ?string
{
return $this->webinarSchema->agenda;
}

protected function initializeDisplayableProperties()
{
$zoomPlugin = ZoomPlugin::create();

$namedTypes = [
WebinarSchema::TYPE_WEBINAR => $zoomPlugin->get_lang('Webinar'),
WebinarSchema::TYPE_RECURRING_NO_FIXED_TIME => $zoomPlugin->get_lang('RecurringWithNoFixedTime'),
WebinarSchema::TYPE_RECURRING_FIXED_TIME => $zoomPlugin->get_lang('RecurringWithFixedTime'),
];

$this->typeName = $namedTypes[$this->webinarSchema->type];

if ($this->webinarSchema->start_time) {
$this->startDateTime = new DateTime(
$this->webinarSchema->start_time,
new \DateTimeZone(api_get_timezone())
);
$this->formattedStartTime = $this->startDateTime->format('Y-m-d H:i');
}

if ($this->webinarSchema->duration) {
$now = new DateTime();
$later = new DateTime();
$later->add(
new DateInterval('PT'.$this->webinarSchema->duration.'M')
);
$this->durationInterval = $now->diff($later);
$this->formattedDuration = $this->durationInterval->format(
$zoomPlugin->get_lang('DurationFormat')
);
}
}
}

0 comments on commit caef076

Please sign in to comment.