From 8642ab5cfd8af4d96d6bd3965d86a8a995097127 Mon Sep 17 00:00:00 2001 From: "B. Endres" Date: Thu, 30 Jan 2020 08:17:16 +0100 Subject: [PATCH] [#18] implementing xcm profiles --- CRM/Twingle/Form/Profile.php | 36 ++++++++++++++++++++++++++ CRM/Twingle/Profile.php | 2 ++ CRM/Twingle/Submission.php | 6 +++++ api/v3/TwingleDonation/Submit.php | 13 +++++----- templates/CRM/Twingle/Form/Profile.hlp | 5 ++++ templates/CRM/Twingle/Form/Profile.tpl | 21 +++++++++++++++ 6 files changed, 77 insertions(+), 6 deletions(-) diff --git a/CRM/Twingle/Form/Profile.php b/CRM/Twingle/Form/Profile.php index eeb35fe..81f6d1b 100644 --- a/CRM/Twingle/Form/Profile.php +++ b/CRM/Twingle/Form/Profile.php @@ -98,6 +98,14 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { */ protected static $_locationTypes = NULL; + /** + * @var array + * + * A static cache of retrieved location types found within + * static::getXCMProfiles(). + */ + protected static $_xcm_profiles = NULL; + /** * @var array * @@ -198,6 +206,14 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { TRUE // is required ); + $this->add( + 'select', + 'xcm_profile', + E::ts('Contact Matcher (XCM) Profile'), + static::getXCMProfiles(), + TRUE + ); + $this->add( 'select', 'location_type_id', @@ -510,6 +526,26 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form { return static::$_locationTypes; } + /** + * Retrieves XCM profiles (if supported). 'default' profile is always available + * + * @return array + */ + public static function getXCMProfiles() { + if (!isset(static::$_xcm_profiles)) { + static::$_xcm_profiles = array( + '' => E::ts("<default profile>"), + ); + if (method_exists('CRM_Xcm_Configuration', 'getProfileList')) { + $profiles = CRM_Xcm_Configuration::getProfileList(); + foreach ($profiles as $profile_key => $profile_name) { + static::$_xcm_profiles[$profile_key] = $profile_name; + } + } + } + return static::$_xcm_profiles; + } + /** * Retrieves financial types present within the system as options for select * form elements. diff --git a/CRM/Twingle/Profile.php b/CRM/Twingle/Profile.php index 5301cd6..6fa7020 100644 --- a/CRM/Twingle/Profile.php +++ b/CRM/Twingle/Profile.php @@ -199,6 +199,7 @@ class CRM_Twingle_Profile { return array_merge( array( 'selector', + 'xcm_profile', 'location_type_id', 'location_type_id_organisation', 'financial_type_id', @@ -258,6 +259,7 @@ class CRM_Twingle_Profile { public static function createDefaultProfile($name = 'default') { return new CRM_Twingle_Profile($name, array( 'selector' => '', + 'xcm_profile' => '', 'location_type_id' => CRM_Twingle_Submission::LOCATION_TYPE_ID_WORK, 'location_type_id_organisation' => CRM_Twingle_Submission::LOCATION_TYPE_ID_WORK, 'financial_type_id' => 1, // "Donation" diff --git a/CRM/Twingle/Submission.php b/CRM/Twingle/Submission.php index f64bc69..469af34 100644 --- a/CRM/Twingle/Submission.php +++ b/CRM/Twingle/Submission.php @@ -139,6 +139,12 @@ class CRM_Twingle_Submission { return NULL; } + // add xcm profile + $xcm_profile = $profile->getAttribute('xcm_profile'); + if (!empty($xcm_profile)) { + $contact_data['xcm_profile'] = $xcm_profile; + } + // add campaign $campaign_id = (int) $profile->getAttribute('campaign'); if ($campaign_id) { diff --git a/api/v3/TwingleDonation/Submit.php b/api/v3/TwingleDonation/Submit.php index 8a8c0b4..5a0e377 100644 --- a/api/v3/TwingleDonation/Submit.php +++ b/api/v3/TwingleDonation/Submit.php @@ -450,14 +450,15 @@ function civicrm_api3_twingle_donation_Submit($params) { ) ); - // Address is not shared, use submitted address with configured location - // type. + // Address is not shared, use submitted address with + // configured location type. if (!$address_shared && !empty($submitted_address)) { - // Do not use `Address.create` API action in order for XCM to decide + // Do not use `Address.create` API action, let XCM decide // whether to create an address. - civicrm_api3('Contact', 'getorcreate', array( - 'id' => $contact_id, - ) + $submitted_address); + CRM_Twingle_Submission::getContact( + 'Individual', + array('id' => $contact_id) + $submitted_address, + $profile); } // Create employer relationship between organization and individual. diff --git a/templates/CRM/Twingle/Form/Profile.hlp b/templates/CRM/Twingle/Form/Profile.hlp index 3e82883..81045c2 100644 --- a/templates/CRM/Twingle/Form/Profile.hlp +++ b/templates/CRM/Twingle/Form/Profile.hlp @@ -21,6 +21,11 @@ {ts domain="de.systopia.twingle"}You can also provide multiple project IDs separated by a comma.{/ts} {/htxt} +{htxt id='id-xcm_profile'} + {ts domain="de.systopia.twingle"}The Contact Matcher (XCM) manages the identification or creation of the related contact.{/ts} + {ts domain="de.systopia.twingle"}We recommend creating a new XCM profile only to be used with the Twingle API.{/ts} +{/htxt} + {htxt id='id-location_type_id_organisation'} {ts domain="de.systopia.twingle"}Select which location type to use for addresses for organisations and shared organisation addresses for individual contacts.{/ts} {/htxt} diff --git a/templates/CRM/Twingle/Form/Profile.tpl b/templates/CRM/Twingle/Form/Profile.tpl index c0b444f..b285ee3 100644 --- a/templates/CRM/Twingle/Form/Profile.tpl +++ b/templates/CRM/Twingle/Form/Profile.tpl @@ -48,6 +48,27 @@ {$form.selector.html} + + {$form.xcm_profile.label} + + + {$form.xcm_profile.html} + + {$form.location_type_id.label}