function wf_crm_get_events in Webform CiviCRM Integration 7.5
Same name and namespace in other branches
- 7.4 includes/utils.inc \wf_crm_get_events()
Get list of events.
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 243 - Webform CiviCRM module's common utility functions.
Code
function wf_crm_get_events($reg_options, $context) {
$ret = [];
$format = wf_crm_aval($reg_options, 'title_display', 'title');
$params = [
'is_template' => 0,
'is_active' => 1,
];
$event_types = array_filter((array) $reg_options['event_type'], "is_numeric");
if ($event_types) {
$params['event_type_id'] = [
'IN' => $event_types,
];
}
if (is_numeric(wf_crm_aval($reg_options, 'show_public_events'))) {
$params['is_public'] = $reg_options['show_public_events'];
}
$params['options'] = [
'sort' => 'start_date' . ($context == 'config_form' ? ' DESC' : ''),
];
$values = wf_crm_apivalues('Event', 'get', $params);
// '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));
foreach ($values as $key => $value) {
if (isset($value['end_date']) && $value['end_date'] <= $date_past) {
unset($values[$key]);
}
}
}
// '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));
foreach ($values as $key => $value) {
if (isset($value['end_date']) && $value['end_date'] >= $date_future) {
unset($values[$key]);
}
}
}
foreach ($values as $value) {
$ret[$value['id'] . '-' . $value['event_type_id']] = wf_crm_format_event($value, $format);
}
return $ret;
}