You are here

function wf_crm_get_events in Webform CiviCRM Integration 7.4

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

Get list of events. FIXME use the api for this.

Parameters

array $reg_options:

string $context:

Return value

array

1 call to wf_crm_get_events()
wf_crm_field_options in includes/utils.inc
Get options for a specific field

File

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

Code

function wf_crm_get_events($reg_options, $context) {
  $ret = array();
  $format = wf_crm_aval($reg_options, 'title_display', 'title');
  $sql = "SELECT id, title, start_date, end_date, event_type_id FROM civicrm_event WHERE is_template = 0 AND is_active = 1";

  // 'now' means only current events, 1 means show all past events, other values are relative date strings
  $date_past = wf_crm_aval($reg_options, 'show_past_events', 'now');
  if ($date_past != '1') {
    $date_past = date('Y-m-d H:i:s', strtotime($date_past));
    $sql .= " AND (end_date >= '{$date_past}' OR end_date IS NULL)";
  }

  // 'now' means only past events, 1 means show all future events, other values are relative date strings
  $date_future = wf_crm_aval($reg_options, 'show_future_events', '1');
  if ($date_future != '1') {
    $date_future = date('Y-m-d H:i:s', strtotime($date_future));
    $sql .= " AND (end_date <= '{$date_future}' OR end_date IS NULL)";
  }
  $event_types = array_filter((array) $reg_options['event_type'], "is_numeric");
  if ($event_types) {
    $sql .= ' AND event_type_id IN ( ' . implode(", ", $event_types) . ' ) ';
  }
  if (is_numeric(wf_crm_aval($reg_options, 'show_public_events'))) {
    $sql .= ' AND is_public = ' . $reg_options['show_public_events'];
  }
  $sql .= ' ORDER BY start_date ' . ($context == 'config_form' ? 'DESC' : '');
  $dao = CRM_Core_DAO::executeQuery($sql);
  while ($dao
    ->fetch()) {
    $ret[$dao->id . '-' . $dao->event_type_id] = wf_crm_format_event($dao, $format);
  }
  return $ret;
}