You are here

function wf_crm_format_event in Webform CiviCRM Integration 7.4

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

Parameters

array|object $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. FIXME use the api for this.
wf_crm_webform_postprocess::validateParticipants in includes/wf_crm_webform_postprocess.inc
Validate event participants and add line items

File

includes/utils.inc, line 229
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) {
      $config = CRM_Core_Config::singleton();
      $date_format = $config->{$value};
    }
  }
  $event = (object) $event;
  $title = array();
  if (in_array('title', $format)) {
    $title[] = $event->title;
  }
  if (in_array('type', $format)) {
    $types = wf_crm_apivalues('event', 'getoptions', array(
      'field' => 'event_type_id',
      'context' => 'get',
    ));
    $title[] = $types[$event->event_type_id];
  }
  if (in_array('start', $format) && $event->start_date) {
    $title[] = CRM_Utils_Date::customFormat($event->start_date, $date_format);
  }
  if (in_array('end', $format) && $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 ? $config->dateformatTime : $date_format;
      $title[] = CRM_Utils_Date::customFormat($event->end_date, $end_format);
    }
  }
  return implode(' - ', $title);
}