diff --git a/plugin/zoom/Entity/Meeting.php b/plugin/zoom/Entity/Meeting.php index eb7fd745d0..ba28f4de1b 100644 --- a/plugin/zoom/Entity/Meeting.php +++ b/plugin/zoom/Entity/Meeting.php @@ -9,6 +9,7 @@ use Chamilo\CoreBundle\Entity\CourseRelUser; use Chamilo\CoreBundle\Entity\Session; use Chamilo\CoreBundle\Entity\SessionRelCourseRelUser; use Chamilo\CourseBundle\Entity\CGroupInfo; +use Chamilo\PluginBundle\Zoom\API\BaseMeetingTrait; use Chamilo\PluginBundle\Zoom\API\MeetingInfoGet; use Chamilo\PluginBundle\Zoom\API\MeetingListItem; use Chamilo\PluginBundle\Zoom\API\MeetingSettings; @@ -402,7 +403,7 @@ class Meeting } /** - * @param MeetingInfoGet $meetingInfoGet + * @param MeetingInfoGet|BaseMeetingTrait $meetingInfoGet * * @throws Exception * diff --git a/plugin/zoom/Entity/Webinar.php b/plugin/zoom/Entity/Webinar.php index 355f5354a9..24f29c06f4 100644 --- a/plugin/zoom/Entity/Webinar.php +++ b/plugin/zoom/Entity/Webinar.php @@ -4,6 +4,7 @@ namespace Chamilo\PluginBundle\Zoom; +use Chamilo\PluginBundle\Zoom\API\BaseMeetingTrait; use Chamilo\PluginBundle\Zoom\API\WebinarSchema; use Chamilo\PluginBundle\Zoom\API\WebinarSettings; use DateInterval; @@ -47,6 +48,8 @@ class Webinar extends Meeting } /** + * @param WebinarSchema|BaseMeetingTrait $webinarSchema + * * @throws Exception */ public function setWebinarSchema(WebinarSchema $webinarSchema): Webinar diff --git a/plugin/zoom/lib/API/BaseMeetingTrait.php b/plugin/zoom/lib/API/BaseMeetingTrait.php index 0d3037731d..fe9fe56606 100644 --- a/plugin/zoom/lib/API/BaseMeetingTrait.php +++ b/plugin/zoom/lib/API/BaseMeetingTrait.php @@ -4,6 +4,8 @@ namespace Chamilo\PluginBundle\Zoom\API; +use Exception; + /** * Trait BaseMeetingTrait. * Common meeting properties definitions. @@ -29,4 +31,11 @@ trait BaseMeetingTrait public $agenda; /** @var string description */ public $host_email; + + /** + * @throws Exception + */ + public function update(): void + { + } } diff --git a/plugin/zoom/lib/API/MeetingInfoGet.php b/plugin/zoom/lib/API/MeetingInfoGet.php index 58dceac618..45c3fbd480 100644 --- a/plugin/zoom/lib/API/MeetingInfoGet.php +++ b/plugin/zoom/lib/API/MeetingInfoGet.php @@ -49,7 +49,7 @@ class MeetingInfoGet extends MeetingInfo * * @throws Exception */ - public function update() + public function update(): void { Client::getInstance()->send('PATCH', 'meetings/'.$this->id, [], $this); } diff --git a/plugin/zoom/lib/API/WebinarSchema.php b/plugin/zoom/lib/API/WebinarSchema.php index 57774fb30f..bf0f6365ee 100644 --- a/plugin/zoom/lib/API/WebinarSchema.php +++ b/plugin/zoom/lib/API/WebinarSchema.php @@ -9,6 +9,7 @@ use stdClass; class WebinarSchema { + use BaseMeetingTrait; use JsonDeserializableTrait; const TYPE_WEBINAR = 5; @@ -18,13 +19,6 @@ class WebinarSchema public $uuid; public $id; public $host_id; - public $host_email; - public $topic; - public $type; - public $start_time; - public $duration; - public $timezone; - public $agenda; public $created_at; public $start_url; public $join_url; @@ -92,7 +86,7 @@ class WebinarSchema /** * @throws Exception */ - public function update() + public function update(): void { Client::getInstance()->send('PATCH', 'webinars/'.$this->id, [], $this); } diff --git a/plugin/zoom/lib/ZoomPlugin.php b/plugin/zoom/lib/ZoomPlugin.php index aa139b90f1..1b92ce9906 100644 --- a/plugin/zoom/lib/ZoomPlugin.php +++ b/plugin/zoom/lib/ZoomPlugin.php @@ -5,6 +5,7 @@ use Chamilo\CoreBundle\Entity\Course; use Chamilo\CoreBundle\Entity\Session; use Chamilo\CourseBundle\Entity\CGroupInfo; +use Chamilo\PluginBundle\Zoom\API\BaseMeetingTrait; use Chamilo\PluginBundle\Zoom\API\JWTClient; use Chamilo\PluginBundle\Zoom\API\MeetingInfoGet; 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 - * - * @return FormValidator */ - public function getEditMeetingForm($meeting) + public function getEditConferenceForm(Meeting $conference): FormValidator { - $meetingInfoGet = $meeting->getMeetingInfoGet(); - $form = new FormValidator('edit', 'post', $_SERVER['REQUEST_URI']); - $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(); + $isWebinar = $conference instanceof Webinar; + $requiresDateAndDuration = $conference->requiresDateAndDuration(); - if ($meeting->requiresDateAndDuration()) { - $meetingInfoGet->start_time = (new DateTime($values['startTime']))->format( - 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(); + /** @var BaseMeetingTrait $schema */ + $schema = $isWebinar ? $conference->getWebinarSchema() : $conference->getMeetingInfoGet(); $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')); if ($requiresDateAndDuration) { @@ -417,14 +352,17 @@ class ZoomPlugin extends Plugin } $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')); if ($form->validate()) { $formValues = $form->exportValues(); + $em = Database::getManager(); + if ($requiresDateAndDuration) { - $schema->start_time = (new DateTime($formValues['startTime'])) - ->format(DATE_ATOM); + $schema->start_time = (new DateTime($formValues['startTime']))->format(DATE_ATOM); $schema->timezone = date_default_timezone_get(); $schema->duration = (int) $formValues['duration']; } @@ -432,16 +370,27 @@ class ZoomPlugin extends Plugin $schema->topic = $formValues['topic']; $schema->agenda = $formValues['agenda']; + $conference + ->setSignAttendance(isset($formValues['sign_attendance'])) + ->setReasonToSignAttendance($formValues['reason_to_sign']); + try { $schema->update(); - $webinar->setWebinarSchema($schema); - $em = Database::getManager(); - $em->persist($webinar); + if ($isWebinar) { + $conference->setWebinarSchema($schema); + } else { + $conference->setMeetingInfoGet($schema); + } + + $em->persist($conference); $em->flush(); 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) { Display::addFlash( @@ -456,10 +405,13 @@ class ZoomPlugin extends Plugin ]; 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['sign_attendance'] = $conference->isSignAttendance(); + $defaults['reason_to_sign'] = $conference->getReasonToSignAttendance(); + $form->setDefaults($defaults); return $form; diff --git a/plugin/zoom/meeting.php b/plugin/zoom/meeting.php index d924bc5b20..3d61dd0db3 100755 --- a/plugin/zoom/meeting.php +++ b/plugin/zoom/meeting.php @@ -57,11 +57,11 @@ if ($plugin->userIsConferenceManager($meeting)) { // user can edit, start and delete meeting $tpl->assign('isConferenceManager', true); + $tpl->assign('editMeetingForm', $plugin->getEditConferenceForm($meeting)->returnForm()); + if ($meeting instanceof Webinar) { - $tpl->assign('editMeetingForm', $plugin->getEditWebinarForm($meeting)->returnForm()); $tpl->assign('deleteMeetingForm', $plugin->getDeleteWebinarForm($meeting, $returnURL)->returnForm()); } elseif ($meeting instanceof Meeting) { - $tpl->assign('editMeetingForm', $plugin->getEditMeetingForm($meeting)->returnForm()); $tpl->assign('deleteMeetingForm', $plugin->getDeleteMeetingForm($meeting, $returnURL)->returnForm()); }