function opigno_moxtra_opigno_moxtra_meeting_update in Opigno Moxtra 3.x
Same name and namespace in other branches
- 8 opigno_moxtra.module \opigno_moxtra_opigno_moxtra_meeting_update()
Implements hook_ENTITY_TYPE_update().
Updates meeting info in the Moxtra.
File
- ./
opigno_moxtra.module, line 604 - Contains opigno_moxtra.module.
Code
function opigno_moxtra_opigno_moxtra_meeting_update(EntityInterface $entity) {
// Set meeting reference on the related calendar event.
/** @var \Drupal\opigno_moxtra\MeetingInterface $entity */
$calendar_event = $entity
->getCalendarEvent();
if (isset($calendar_event)) {
$calendar_event
->set('field_meeting', $entity);
$calendar_event
->save();
}
$moxtra_api = _opigno_moxtra_get_moxtra_api();
$owner_id = $entity
->getOwnerId();
$session_key = $entity
->getSessionKey();
if (!empty($session_key)) {
$info = $moxtra_api
->getMeetingInfo($owner_id, $session_key);
$status = !empty($info['data']) ? $info['data']['status'] : FALSE;
if ($status !== 'SESSION_SCHEDULED') {
// Not update the meeting info in the Moxtra, if it is not scheduled.
return;
}
$title = $entity
->getTitle();
$ends_value = $entity
->getEndDate();
$starts_value = $entity
->getStartDate();
$original_title = $entity->original
->getTitle();
$original_starts = $entity->original
->getStartDate();
$original_ends = $entity->original
->getEndDate();
if ($title !== $original_title || $original_starts !== $starts_value || $ends_value !== $original_ends) {
// Get ISO-8601 date without a timezone when meeting starts.
$starts = isset($starts_value) ? DrupalDateTime::createFromFormat(DrupalDateTime::FORMAT, $starts_value)
->setTimezone(new \DateTimeZone('UTC'))
->format('Y-m-d\\TH:i:s\\Z') : NULL;
// Get ISO-8601 date without a timezone when meeting ends.
$ends = isset($ends_value) ? DrupalDateTime::createFromFormat(DrupalDateTime::FORMAT, $ends_value)
->setTimezone(new \DateTimeZone('UTC'))
->format('Y-m-d\\TH:i:s\\Z') : NULL;
$moxtra_api
->updateMeeting($owner_id, $session_key, $title, $starts, $ends);
}
}
}