Plugin: Zoom: Refactor + Show type in details form - refs BT#19479

pull/4160/head
Angel Fernando Quiroz Campos 4 years ago
parent 7390cf2b26
commit dfd8decfe9
  1. 3
      plugin/zoom/Entity/Meeting.php
  2. 3
      plugin/zoom/Entity/Webinar.php
  3. 9
      plugin/zoom/lib/API/BaseMeetingTrait.php
  4. 2
      plugin/zoom/lib/API/MeetingInfoGet.php
  5. 10
      plugin/zoom/lib/API/WebinarSchema.php
  6. 116
      plugin/zoom/lib/ZoomPlugin.php
  7. 4
      plugin/zoom/meeting.php

@ -9,6 +9,7 @@ use Chamilo\CoreBundle\Entity\CourseRelUser;
use Chamilo\CoreBundle\Entity\Session; use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CoreBundle\Entity\SessionRelCourseRelUser; use Chamilo\CoreBundle\Entity\SessionRelCourseRelUser;
use Chamilo\CourseBundle\Entity\CGroupInfo; use Chamilo\CourseBundle\Entity\CGroupInfo;
use Chamilo\PluginBundle\Zoom\API\BaseMeetingTrait;
use Chamilo\PluginBundle\Zoom\API\MeetingInfoGet; use Chamilo\PluginBundle\Zoom\API\MeetingInfoGet;
use Chamilo\PluginBundle\Zoom\API\MeetingListItem; use Chamilo\PluginBundle\Zoom\API\MeetingListItem;
use Chamilo\PluginBundle\Zoom\API\MeetingSettings; use Chamilo\PluginBundle\Zoom\API\MeetingSettings;
@ -402,7 +403,7 @@ class Meeting
} }
/** /**
* @param MeetingInfoGet $meetingInfoGet * @param MeetingInfoGet|BaseMeetingTrait $meetingInfoGet
* *
* @throws Exception * @throws Exception
* *

@ -4,6 +4,7 @@
namespace Chamilo\PluginBundle\Zoom; namespace Chamilo\PluginBundle\Zoom;
use Chamilo\PluginBundle\Zoom\API\BaseMeetingTrait;
use Chamilo\PluginBundle\Zoom\API\WebinarSchema; use Chamilo\PluginBundle\Zoom\API\WebinarSchema;
use Chamilo\PluginBundle\Zoom\API\WebinarSettings; use Chamilo\PluginBundle\Zoom\API\WebinarSettings;
use DateInterval; use DateInterval;
@ -47,6 +48,8 @@ class Webinar extends Meeting
} }
/** /**
* @param WebinarSchema|BaseMeetingTrait $webinarSchema
*
* @throws Exception * @throws Exception
*/ */
public function setWebinarSchema(WebinarSchema $webinarSchema): Webinar public function setWebinarSchema(WebinarSchema $webinarSchema): Webinar

@ -4,6 +4,8 @@
namespace Chamilo\PluginBundle\Zoom\API; namespace Chamilo\PluginBundle\Zoom\API;
use Exception;
/** /**
* Trait BaseMeetingTrait. * Trait BaseMeetingTrait.
* Common meeting properties definitions. * Common meeting properties definitions.
@ -29,4 +31,11 @@ trait BaseMeetingTrait
public $agenda; public $agenda;
/** @var string description */ /** @var string description */
public $host_email; public $host_email;
/**
* @throws Exception
*/
public function update(): void
{
}
} }

@ -49,7 +49,7 @@ class MeetingInfoGet extends MeetingInfo
* *
* @throws Exception * @throws Exception
*/ */
public function update() public function update(): void
{ {
Client::getInstance()->send('PATCH', 'meetings/'.$this->id, [], $this); Client::getInstance()->send('PATCH', 'meetings/'.$this->id, [], $this);
} }

@ -9,6 +9,7 @@ use stdClass;
class WebinarSchema class WebinarSchema
{ {
use BaseMeetingTrait;
use JsonDeserializableTrait; use JsonDeserializableTrait;
const TYPE_WEBINAR = 5; const TYPE_WEBINAR = 5;
@ -18,13 +19,6 @@ class WebinarSchema
public $uuid; public $uuid;
public $id; public $id;
public $host_id; public $host_id;
public $host_email;
public $topic;
public $type;
public $start_time;
public $duration;
public $timezone;
public $agenda;
public $created_at; public $created_at;
public $start_url; public $start_url;
public $join_url; public $join_url;
@ -92,7 +86,7 @@ class WebinarSchema
/** /**
* @throws Exception * @throws Exception
*/ */
public function update() public function update(): void
{ {
Client::getInstance()->send('PATCH', 'webinars/'.$this->id, [], $this); Client::getInstance()->send('PATCH', 'webinars/'.$this->id, [], $this);
} }

@ -5,6 +5,7 @@
use Chamilo\CoreBundle\Entity\Course; use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\Session; use Chamilo\CoreBundle\Entity\Session;
use Chamilo\CourseBundle\Entity\CGroupInfo; use Chamilo\CourseBundle\Entity\CGroupInfo;
use Chamilo\PluginBundle\Zoom\API\BaseMeetingTrait;
use Chamilo\PluginBundle\Zoom\API\JWTClient; use Chamilo\PluginBundle\Zoom\API\JWTClient;
use Chamilo\PluginBundle\Zoom\API\MeetingInfoGet; use Chamilo\PluginBundle\Zoom\API\MeetingInfoGet;
use Chamilo\PluginBundle\Zoom\API\MeetingRegistrant; use Chamilo\PluginBundle\Zoom\API\MeetingRegistrant;
@ -325,87 +326,21 @@ class ZoomPlugin extends Plugin
} }
/** /**
* Generates a meeting edit form and updates the meeting on validation.
*
* @param Meeting $meeting the meeting
*
* @throws Exception * @throws Exception
*
* @return FormValidator
*/ */
public function getEditMeetingForm($meeting) public function getEditConferenceForm(Meeting $conference): FormValidator
{ {
$meetingInfoGet = $meeting->getMeetingInfoGet(); $isWebinar = $conference instanceof Webinar;
$form = new FormValidator('edit', 'post', $_SERVER['REQUEST_URI']); $requiresDateAndDuration = $conference->requiresDateAndDuration();
$form->addHeader($this->get_lang('UpdateMeeting'));
$form->addText('topic', $this->get_lang('Topic'));
if ($meeting->requiresDateAndDuration()) {
$startTimeDatePicker = $form->addDateTimePicker('startTime', get_lang('StartTime'));
$form->setRequired($startTimeDatePicker);
$durationNumeric = $form->addNumeric('duration', $this->get_lang('DurationInMinutes'));
$form->setRequired($durationNumeric);
}
$form->addTextarea('agenda', get_lang('Agenda'), ['maxlength' => 2000]);
//$form->addLabel(get_lang('Password'), $meeting->getMeetingInfoGet()->password);
// $form->addText('password', get_lang('Password'), false, ['maxlength' => '10']);
$form->addCheckBox('sign_attendance', $this->get_lang('SignAttendance'), get_lang('Yes'));
$form->addTextarea('reason_to_sign', $this->get_lang('ReasonToSign'), ['rows' => 5]);
$form->addButtonUpdate(get_lang('Update'));
if ($form->validate()) {
$values = $form->exportValues();
if ($meeting->requiresDateAndDuration()) { /** @var BaseMeetingTrait $schema */
$meetingInfoGet->start_time = (new DateTime($values['startTime']))->format( $schema = $isWebinar ? $conference->getWebinarSchema() : $conference->getMeetingInfoGet();
DATE_ATOM
);
$meetingInfoGet->timezone = date_default_timezone_get();
$meetingInfoGet->duration = (int) $values['duration'];
}
$meetingInfoGet->topic = $values['topic'];
$meetingInfoGet->agenda = $values['agenda'];
$meeting
->setSignAttendance(isset($values['sign_attendance']))
->setReasonToSignAttendance($values['reason_to_sign']);
try {
$meetingInfoGet->update();
$meeting->setMeetingInfoGet($meetingInfoGet);
Database::getManager()->persist($meeting);
Database::getManager()->flush();
Display::addFlash(
Display::return_message($this->get_lang('MeetingUpdated'), 'confirm')
);
} catch (Exception $exception) {
Display::addFlash(
Display::return_message($exception->getMessage(), 'error')
);
}
}
$defaults = [
'topic' => $meetingInfoGet->topic,
'agenda' => $meetingInfoGet->agenda,
];
if ($meeting->requiresDateAndDuration()) {
$defaults['startTime'] = $meeting->startDateTime->format('Y-m-d H:i');
$defaults['duration'] = $meetingInfoGet->duration;
}
$defaults['sign_attendance'] = $meeting->isSignAttendance();
$defaults['reason_to_sign'] = $meeting->getReasonToSignAttendance();
$form->setDefaults($defaults);
return $form;
}
/**
* @throws Exception
*/
public function getEditWebinarForm(Webinar $webinar): FormValidator
{
$schema = $webinar->getWebinarSchema();
$requiresDateAndDuration = $webinar->requiresDateAndDuration();
$form = new FormValidator('edit', 'post', $_SERVER['REQUEST_URI']); $form = new FormValidator('edit', 'post', $_SERVER['REQUEST_URI']);
$form->addHeader($this->get_lang('UpdateWebinar')); $form->addHeader(
$isWebinar ? $this->get_lang('UpdateWebinar') : $this->get_lang('UpdateMeeting')
);
$form->addLabel(get_lang('Type'), $conference->typeName);
$form->addText('topic', $this->get_lang('Topic')); $form->addText('topic', $this->get_lang('Topic'));
if ($requiresDateAndDuration) { if ($requiresDateAndDuration) {
@ -417,14 +352,17 @@ class ZoomPlugin extends Plugin
} }
$form->addTextarea('agenda', get_lang('Agenda'), ['maxlength' => 2000]); $form->addTextarea('agenda', get_lang('Agenda'), ['maxlength' => 2000]);
$form->addCheckBox('sign_attendance', $this->get_lang('SignAttendance'), get_lang('Yes'));
$form->addTextarea('reason_to_sign', $this->get_lang('ReasonToSign'), ['rows' => 5]);
$form->addButtonUpdate(get_lang('Update')); $form->addButtonUpdate(get_lang('Update'));
if ($form->validate()) { if ($form->validate()) {
$formValues = $form->exportValues(); $formValues = $form->exportValues();
$em = Database::getManager();
if ($requiresDateAndDuration) { if ($requiresDateAndDuration) {
$schema->start_time = (new DateTime($formValues['startTime'])) $schema->start_time = (new DateTime($formValues['startTime']))->format(DATE_ATOM);
->format(DATE_ATOM);
$schema->timezone = date_default_timezone_get(); $schema->timezone = date_default_timezone_get();
$schema->duration = (int) $formValues['duration']; $schema->duration = (int) $formValues['duration'];
} }
@ -432,16 +370,27 @@ class ZoomPlugin extends Plugin
$schema->topic = $formValues['topic']; $schema->topic = $formValues['topic'];
$schema->agenda = $formValues['agenda']; $schema->agenda = $formValues['agenda'];
$conference
->setSignAttendance(isset($formValues['sign_attendance']))
->setReasonToSignAttendance($formValues['reason_to_sign']);
try { try {
$schema->update(); $schema->update();
$webinar->setWebinarSchema($schema);
$em = Database::getManager(); if ($isWebinar) {
$em->persist($webinar); $conference->setWebinarSchema($schema);
} else {
$conference->setMeetingInfoGet($schema);
}
$em->persist($conference);
$em->flush(); $em->flush();
Display::addFlash( Display::addFlash(
Display::return_message($this->get_lang('WebinarUpdated'), 'success') Display::return_message(
$isWebinar ? $this->get_lang('WebinarUpdated') : $this->get_lang('MeetingUpdated'),
'confirm'
)
); );
} catch (Exception $exception) { } catch (Exception $exception) {
Display::addFlash( Display::addFlash(
@ -456,10 +405,13 @@ class ZoomPlugin extends Plugin
]; ];
if ($requiresDateAndDuration) { if ($requiresDateAndDuration) {
$defaults['startTime'] = $webinar->startDateTime->format('Y-m-d H:i'); $defaults['startTime'] = $conference->startDateTime->format('Y-m-d H:i');
$defaults['duration'] = $schema->duration; $defaults['duration'] = $schema->duration;
} }
$defaults['sign_attendance'] = $conference->isSignAttendance();
$defaults['reason_to_sign'] = $conference->getReasonToSignAttendance();
$form->setDefaults($defaults); $form->setDefaults($defaults);
return $form; return $form;

@ -57,11 +57,11 @@ if ($plugin->userIsConferenceManager($meeting)) {
// user can edit, start and delete meeting // user can edit, start and delete meeting
$tpl->assign('isConferenceManager', true); $tpl->assign('isConferenceManager', true);
$tpl->assign('editMeetingForm', $plugin->getEditConferenceForm($meeting)->returnForm());
if ($meeting instanceof Webinar) { if ($meeting instanceof Webinar) {
$tpl->assign('editMeetingForm', $plugin->getEditWebinarForm($meeting)->returnForm());
$tpl->assign('deleteMeetingForm', $plugin->getDeleteWebinarForm($meeting, $returnURL)->returnForm()); $tpl->assign('deleteMeetingForm', $plugin->getDeleteWebinarForm($meeting, $returnURL)->returnForm());
} elseif ($meeting instanceof Meeting) { } elseif ($meeting instanceof Meeting) {
$tpl->assign('editMeetingForm', $plugin->getEditMeetingForm($meeting)->returnForm());
$tpl->assign('deleteMeetingForm', $plugin->getDeleteMeetingForm($meeting, $returnURL)->returnForm()); $tpl->assign('deleteMeetingForm', $plugin->getDeleteMeetingForm($meeting, $returnURL)->returnForm());
} }

Loading…
Cancel
Save