You are here

function opigno_ilt_ical_prepare in Opigno Instructor-led Trainings 8

Same name and namespace in other branches
  1. 3.x opigno_ilt.module \opigno_ilt_ical_prepare()

Helper function to prepare iCal file for Instructor Led Training.

2 calls to opigno_ilt_ical_prepare()
ILTForm::save in src/Form/ILTForm.php
Form submission handler for the 'save' action.
opigno_ilt_cron in ./opigno_ilt.module
Implements hook_cron().

File

./opigno_ilt.module, line 460
Contains opigno_ilt.module.

Code

function opigno_ilt_ical_prepare($ilt) {
  $startDate = new DateTime($ilt
    ->getStartDate());
  $endDate = new DateTime($ilt
    ->getEndDate());
  $iCal = \Drupal::service('opigno_calendar_event.iCal')
    ->buildICalEvent([
    'summary' => $ilt
      ->getTitle(),
    'start' => $startDate
      ->setTimezone(new DateTimeZone("UTC")),
    'end' => $endDate
      ->setTimezone(new DateTimeZone("UTC")),
    'description' => t('The Instructor-Led Training %ilt starts in less than 24 hours', [
      '%ilt' => $ilt
        ->getTitle(),
    ]),
    'url' => $ilt
      ->toUrl('canonical', [
      'absolute' => TRUE,
    ])
      ->setAbsolute()
      ->toString(),
    'org' => \Drupal::config('system.site')
      ->get('name'),
    'location' => $ilt
      ->getPlace(),
  ]);
  $attachments = [
    'filecontent' => $iCal,
    'filename' => $ilt
      ->getTitle() . '.ical',
    'filemime' => 'text/calendar',
  ];
  return $attachments;
}