private function wf_crm_webform_preprocess::populateEvents in Webform CiviCRM Integration 7.4
Same name and namespace in other branches
- 7.5 includes/wf_crm_webform_preprocess.inc \wf_crm_webform_preprocess::populateEvents()
Check if events are open to registration and take appropriate action
1 call to wf_crm_webform_preprocess::populateEvents()
- wf_crm_webform_preprocess::alterForm in includes/
wf_crm_webform_preprocess.inc - Alter front-end of webforms: Called by hook_form_alter() when rendering a civicrm-enabled webform Add custom prefix. Display messages. Block users who should not have access. Set webform default values.
File
- includes/
wf_crm_webform_preprocess.inc, line 237
Class
Code
private function populateEvents() {
$reg = wf_crm_aval($this->data, 'reg_options', array());
// Fetch events set in back-end
$this->data += array(
'participant' => array(),
);
foreach ($this->data['participant'] as $e => $par) {
if (!empty($par['participant'])) {
foreach ($par['participant'] as $n => $p) {
if (!empty($p['event_id'])) {
// Handle multi-valued event selection
foreach ((array) $p['event_id'] as $eid) {
if ($eid = (int) $eid) {
$this->events[$eid]['ended'] = TRUE;
$this->events[$eid]['title'] = t('this event');
$this->events[$eid]['count'] = wf_crm_aval($this->events, "{$eid}:count", 0) + 1;
$status_fid = "civicrm_{$e}_participant_{$n}_participant_status_id";
$this->events[$eid]['form'][] = array(
'contact' => $e,
'num' => $n,
'eid' => NULL,
'status_id' => (array) $this
->getData($status_fid, array_keys($this
->getExposedOptions($status_fid))),
);
}
}
}
}
}
}
// Add events exposed to the form
foreach ($this->enabled as $field => $fid) {
if (strpos($field, 'participant_event_id')) {
foreach ($this
->getExposedOptions($field) as $p => $label) {
list($eid) = explode('-', $p);
$this->events[$eid]['ended'] = TRUE;
$this->events[$eid]['title'] = $label;
list(, $e, , $n) = explode('_', $field);
$status_fid = "civicrm_{$e}_participant_{$n}_participant_status_id";
$this->events[$eid]['form'][] = array(
'contact' => $e,
'num' => $n,
'eid' => $p,
'status_id' => (array) $this
->getData($status_fid, array_keys($this
->getExposedOptions($status_fid))),
);
}
}
}
if ($this->events && (!empty($reg['show_remaining']) || !empty($reg['block_form']))) {
$this
->loadEvents();
foreach ($this->events as $eid => $event) {
if ($event['ended']) {
if (!empty($reg['show_remaining'])) {
$this
->setMessage(t('Sorry, %event has ended.', array(
'%event' => $event['title'],
)), 'warning');
}
}
elseif ($event['full']) {
if (!empty($reg['show_remaining'])) {
$this
->setMessage('<em>' . check_plain($event['title']) . '</em>: ' . check_plain($event['full_message']), 'warning');
}
}
else {
$reg['block_form'] = FALSE;
if ($event['max_participants'] && ($reg['show_remaining'] == 'always' || intval($reg['show_remaining']) >= $event['remaining'])) {
$this
->setMessage(format_plural($event['remaining'], '%event has 1 remaining space.', '%event has @count remaining spaces.', array(
'%event' => $event['title'],
)));
}
}
}
if ($reg['block_form']) {
$this->form['submitted']['#access'] = $this->form['actions']['#access'] = FALSE;
return;
}
}
}