You are here

function wf_crm_format_event in Webform CiviCRM Integration 7.5

Same name and namespace in other branches
  1. 7.4 includes/utils.inc \wf_crm_format_event()

Parameters

array $event:

string $format:

Return value

string

2 calls to wf_crm_format_event()
wf_crm_get_events in includes/utils.inc
Get list of events.
wf_crm_webform_postprocess::validateParticipants in includes/wf_crm_webform_postprocess.inc
Validate event participants and add line items

File

includes/utils.inc, line 290
Webform CiviCRM module's common utility functions.

Code

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

  // Date format
  foreach ($format as $value) {
    if (strpos($value, 'dateformat') === 0) {
      $date_format = wf_crm_get_civi_setting($value);
    }
  }
  $title = [];
  if (in_array('title', $format)) {
    $title[] = $event['title'];
  }
  if (in_array('type', $format)) {
    $types = 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);
}