private function wf_crm_webform_preprocess::loadMemberships 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::loadMemberships()
Load existing membership information and display a message to members.
id
Parameters
int $c:
1 call to wf_crm_webform_preprocess::loadMemberships()
- 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 396
Class
Code
private function loadMemberships($c, $cid) {
$today = date('Y-m-d');
foreach ($this
->findMemberships($cid) as $num => $membership) {
// Only show 1 expired membership, and only if there are no active ones
if (!$membership['is_active'] && $num) {
break;
}
$type = $membership['membership_type_id'];
$msg = t('@type membership for @contact has a status of "@status".', array(
'@type' => $this
->getMembershipTypeField($type, 'name'),
'@contact' => $this->info['contact'][$c]['contact'][1]['display_name'],
'@status' => $membership['status'],
));
if (!empty($membership['end_date'])) {
$end = array(
'@date' => CRM_Utils_Date::customFormat($membership['end_date']),
);
$msg .= ' ' . ($membership['end_date'] > $today ? t('Expires @date.', $end) : t('Expired @date.', $end));
}
$this
->setMessage($msg);
for ($n = 1; $n <= $this->data['membership'][$c]['number_of_membership']; ++$n) {
$fid = "civicrm_{$c}_membership_{$n}_membership_membership_type_id";
if (empty($info['membership'][$c]['membership'][$n]) && ($this
->getData($fid) == $type || array_key_exists($type, $this
->getExposedOptions($fid)))) {
$this->info['membership'][$c]['membership'][$n] = $membership;
break;
}
}
}
}