You are here

function Utils::wf_crm_format_event in Webform CiviCRM Integration 8.5

Parameters

array $event:

string $format:

Return value

string

Overrides UtilsInterface::wf_crm_format_event

1 call to Utils::wf_crm_format_event()
Utils::wf_crm_get_events in src/Utils.php
Get list of events.

File

src/Utils.php, line 201
Webform CiviCRM module's common utility functions.

Class

Utils

Namespace

Drupal\webform_civicrm

Code

function wf_crm_format_event($event, $format) {
  $format = explode(' ', $format);

  // Date format
  foreach ($format as $value) {
    if (strpos($value, 'dateformat') === 0) {
      $date_format = $this
        ->wf_crm_get_civi_setting($value);
    }
  }
  $title = [];
  if (in_array('title', $format)) {
    $title[] = $event['title'];
  }
  if (in_array('type', $format)) {
    $types = $this
      ->wf_crm_apivalues('event', 'getoptions', [
      'field' => 'event_type_id',
      'context' => 'get',
    ]);
    $title[] = $types[$event['event_type_id']];
  }
  if (in_array('start', $format) && !empty($event['start_date'])) {
    $title[] = \CRM_Utils_Date::customFormat($event['start_date'], $date_format);
  }
  if (in_array('end', $format) && isset($event['end_date'])) {

    // Avoid showing redundant end-date if it is the same as the start date
    $same_day = substr($event['start_date'], 0, 10) == substr($event['end_date'], 0, 10);
    if (!$same_day || in_array('dateformatDatetime', $format) || in_array('dateformatTime', $format)) {
      $end_format = in_array('dateformatDatetime', $format) && $same_day ? wf_crm_get_civi_setting('dateformatTime') : $date_format;
      $title[] = \CRM_Utils_Date::customFormat($event['end_date'], $end_format);
    }
  }
  return implode(' - ', $title);
}