From 24801bb6bc3f1a89a4214b6f5a1c158204485c6b Mon Sep 17 00:00:00 2001 From: "B. Endres" Date: Fri, 31 Jan 2020 13:11:32 +0100 Subject: [PATCH] [#14] implementing individual prefix mapping --- CRM/Twingle/Form/Profile.php | 59 +++++++++++++++++++++++++- CRM/Twingle/Profile.php | 3 ++ api/v3/TwingleDonation/Submit.php | 8 ++++ templates/CRM/Twingle/Form/Profile.tpl | 12 +++--- 4 files changed, 75 insertions(+), 7 deletions(-) diff --git a/CRM/Twingle/Form/Profile.php b/CRM/Twingle/Form/Profile.php index 81f6d1b..dc54b39 100644 --- a/CRM/Twingle/Form/Profile.php +++ b/CRM/Twingle/Form/Profile.php @@ -90,6 +90,14 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { */ protected static $_genderOptions = NULL; + /** + * @var array + * + * A static cache of retrieved prefixes found within + * static::getGenderOptions(). + */ + protected static $_prefixOptions = NULL; + /** * @var array * @@ -267,6 +275,28 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { TRUE ); + $this->add( + 'select', + 'prefix_male', + E::ts('Prefix option for submitted value "male"'), + static::getPrefixOptions(), + FALSE + ); + $this->add( + 'select', + 'prefix_female', + E::ts('Prefix option for submitted value "female"'), + static::getPrefixOptions(), + FALSE + ); + $this->add( + 'select', + 'prefix_other', + E::ts('Prefix option for submitted value "other"'), + static::getPrefixOptions(), + FALSE + ); + $payment_instruments = CRM_Twingle_Profile::paymentInstruments(); $this->assign('payment_instruments', $payment_instruments); foreach ($payment_instruments as $pi_name => $pi_label) { @@ -593,7 +623,7 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { } /** - * Retrieves campaigns present within the system as options for select form + * Retrieves genders present within the system as options for select form * elements. * * @return array @@ -619,6 +649,33 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { return static::$_genderOptions; } + /** + * Retrieves prefixes present within the system as options for select form + * elements. + * + * @return array + * + * @throws \CiviCRM_API3_Exception + */ + public static function getPrefixOptions() { + if (!isset(static::$_prefixOptions)) { + static::$_prefixOptions = array('' => E::ts('none')); + $query = civicrm_api3('OptionValue', 'get', array( + 'option.limit' => 0, + 'option_group_id' => 'individual_prefix', + 'is_active' => 1, + 'return' => array( + 'value', + 'label', + ), + )); + foreach ($query['values'] as $prefix) { + static::$_prefixOptions[$prefix['value']] = $prefix['label']; + } + } + return static::$_prefixOptions; + } + /** * Retrieves CiviSEPA creditors as options for select form elements. * diff --git a/CRM/Twingle/Profile.php b/CRM/Twingle/Profile.php index 6fa7020..5c98333 100644 --- a/CRM/Twingle/Profile.php +++ b/CRM/Twingle/Profile.php @@ -208,6 +208,9 @@ class CRM_Twingle_Profile { 'gender_male', 'gender_female', 'gender_other', + 'prefix_male', + 'prefix_female', + 'prefix_other', 'newsletter_groups', 'postinfo_groups', 'donation_receipt_groups', diff --git a/api/v3/TwingleDonation/Submit.php b/api/v3/TwingleDonation/Submit.php index 5a0e377..52de247 100644 --- a/api/v3/TwingleDonation/Submit.php +++ b/api/v3/TwingleDonation/Submit.php @@ -384,6 +384,14 @@ function civicrm_api3_twingle_donation_Submit($params) { } } + // Get the prefix ID defined within the profile + if (!empty($params['user_gender'])) { + $prefix_id = (int) $profile->getAttribute('prefix_' . $params['user_gender']); + if ($prefix_id) { + $contact_data['prefix_id'] = $prefix_id; + } + } + // Add custom field values. if (!empty($custom_fields['Contact'])) { $contact_data += $custom_fields['Contact']; diff --git a/templates/CRM/Twingle/Form/Profile.tpl b/templates/CRM/Twingle/Form/Profile.tpl index b285ee3..3878454 100644 --- a/templates/CRM/Twingle/Form/Profile.tpl +++ b/templates/CRM/Twingle/Form/Profile.tpl @@ -165,16 +165,16 @@ {/if} - {$form.gender_male.label} - {$form.gender_male.html} + {ts domain="de.systopia.twingle"}Gender/Prefix for value 'male'{/ts} + {$form.gender_male.html} / {$form.prefix_male.html} - {$form.gender_female.label} - {$form.gender_female.html} + {ts domain="de.systopia.twingle"}Gender/Prefix for value 'female'{/ts} + {$form.gender_female.html} / {$form.prefix_female.html} - {$form.gender_other.label} - {$form.gender_other.html} + {ts domain="de.systopia.twingle"}Gender/Prefix for value 'other'{/ts} + {$form.gender_other.html} / {$form.prefix_other.html}