[#18] implementing xcm profiles

This commit is contained in:
B. Endres 2020-01-30 08:17:16 +01:00
parent 8ae3f658c0
commit 8642ab5cfd
6 changed files with 77 additions and 6 deletions

View file

@ -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.

View file

@ -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"

View file

@ -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) {

View file

@ -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.

View file

@ -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}

View file

@ -48,6 +48,27 @@
<td class="content">{$form.selector.html}</td>
</tr>
<tr class="crm-section">
<td class="label">{$form.xcm_profile.label}
<a
onclick='
CRM.help(
"{ts domain="de.systopia.twingle"}XCM Profile{/ts}",
{literal}{
"id": "id-xcm_profile",
"file": "CRM\/Twingle\/Form\/Profile"
}{/literal}
);
return false;
'
href="#"
title="{ts domain="de.systopia.twingle"}Help{/ts}"
class="helpicon"
></a>
</td>
<td class="content">{$form.xcm_profile.html}</td>
</tr>
<tr class="crm-section">
<td class="label">
{$form.location_type_id.label}