merged issue/27
This commit is contained in:
commit
acedf890f5
6 changed files with 98 additions and 30 deletions
|
@ -357,12 +357,26 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
|
|||
$this->add(
|
||||
'select', // field type
|
||||
'campaign', // field name
|
||||
E::ts('Campaign (e.g. for donation)'), // field label
|
||||
E::ts('Default Campaign'), // field label
|
||||
array('' => E::ts('- none -')) + static::getCampaigns(), // list of options
|
||||
FALSE, // is not required
|
||||
array('class' => 'crm-select2 huge')
|
||||
);
|
||||
|
||||
$this->add(
|
||||
'select',
|
||||
'campaign_targets',
|
||||
E::ts('Set Campaign for'),
|
||||
[
|
||||
'contribution' => E::ts("Contribution"),
|
||||
'recurring' => E::ts("Recurring Contribution"),
|
||||
'membership' => E::ts("Membership"),
|
||||
'mandate' => E::ts("SEPA Mandate"),
|
||||
],
|
||||
FALSE, // is not required
|
||||
['class' => 'crm-select2 huge', 'multiple' => 'multiple']
|
||||
);
|
||||
|
||||
$this->add(
|
||||
'select', // field type
|
||||
'membership_type_id', // field name
|
||||
|
@ -511,9 +525,14 @@ class CRM_Twingle_Form_Profile extends CRM_Core_Form {
|
|||
$defaults = parent::setDefaultValues();
|
||||
if (in_array($this->_op, array('create', 'edit'))) {
|
||||
$defaults['name'] = $this->profile->getName();
|
||||
foreach ($this->profile->getData() as $element_name => $value) {
|
||||
$profile_data = $this->profile->getData();
|
||||
foreach ($profile_data as $element_name => $value) {
|
||||
$defaults[$element_name] = $value;
|
||||
}
|
||||
// backwards compatibility, see issue #27
|
||||
if (!isset($profile_data['campaign_targets'])) {
|
||||
$defaults['campaign_targets'] = ['contribution', 'contact'];
|
||||
}
|
||||
}
|
||||
return $defaults;
|
||||
}
|
||||
|
|
|
@ -215,6 +215,7 @@ class CRM_Twingle_Profile {
|
|||
'postinfo_groups',
|
||||
'donation_receipt_groups',
|
||||
'campaign',
|
||||
'campaign_targets',
|
||||
'contribution_source',
|
||||
'custom_field_mapping',
|
||||
'membership_type_id',
|
||||
|
@ -287,6 +288,7 @@ class CRM_Twingle_Profile {
|
|||
'postinfo_groups' => NULL,
|
||||
'donation_receipt_groups' => NULL,
|
||||
'campaign' => NULL,
|
||||
'campaign_targets' => ['contribution', 'contact'],
|
||||
'contribution_source' => NULL,
|
||||
'custom_field_mapping' => NULL,
|
||||
'membership_type_id' => NULL,
|
||||
|
|
|
@ -129,6 +129,8 @@ class CRM_Twingle_Submission {
|
|||
* Data to use for contact lookup/to create a contact with.
|
||||
* @param CRM_Twingle_Profile $profile
|
||||
* Profile used for this process
|
||||
* @param array $submission
|
||||
* Submission data
|
||||
*
|
||||
* @return int | NULL
|
||||
* The ID of the matching/created contact, or NULL if no matching contact
|
||||
|
@ -136,7 +138,7 @@ class CRM_Twingle_Submission {
|
|||
* @throws \CiviCRM_API3_Exception
|
||||
* When invalid data was given.
|
||||
*/
|
||||
public static function getContact($contact_type, $contact_data, $profile) {
|
||||
public static function getContact($contact_type, $contact_data, $profile, $submission = []) {
|
||||
// If no parameters are given, do nothing.
|
||||
if (empty($contact_data)) {
|
||||
return NULL;
|
||||
|
@ -148,11 +150,8 @@ class CRM_Twingle_Submission {
|
|||
$contact_data['xcm_profile'] = $xcm_profile;
|
||||
}
|
||||
|
||||
// add campaign
|
||||
$campaign_id = (int) $profile->getAttribute('campaign');
|
||||
if ($campaign_id) {
|
||||
$contact_data['campaign_id'] = $campaign_id;
|
||||
}
|
||||
// add campaign, see issue #17
|
||||
CRM_Twingle_Submission::setCampaign($contact_data, 'contact', $submission, $profile);
|
||||
|
||||
// Prepare values: country.
|
||||
if (!empty($contact_data['country'])) {
|
||||
|
@ -354,4 +353,37 @@ class CRM_Twingle_Submission {
|
|||
return date('j', $earliest_cycle_day);
|
||||
}
|
||||
|
||||
/**
|
||||
* Will set the campaign_id to the entity_data set, if the
|
||||
* profile is configured to do so. In that case the campaign is taken
|
||||
* from the submission data. Should that be empty, the profile's default
|
||||
* campaign is used.
|
||||
*
|
||||
* @param array $entity_data
|
||||
* the data set where the campaign_id should be set
|
||||
* @param string $context
|
||||
* defines the type of the entity_data: one of 'contribution', 'membership','mandate', 'recurring', 'contact'
|
||||
* @param array $submission
|
||||
* the submitted data
|
||||
* @param CRM_Twingle_Profile $profile
|
||||
* the twingle profile used
|
||||
*/
|
||||
public static function setCampaign(&$entity_data, $context, $submission, $profile) {
|
||||
$enabled_contexts = $profile->getAttribute('campaign_targets');
|
||||
if ($enabled_contexts === null || !is_array($enabled_contexts)) {
|
||||
// backward compatibility:
|
||||
$enabled_contexts = ['contribution', 'contact'];
|
||||
}
|
||||
|
||||
// check if campaign should be set it this context
|
||||
if (in_array($context, $enabled_contexts)) {
|
||||
// use the submitted campaign if set
|
||||
if (!empty($submission['campaign_id'])) {
|
||||
$entity_data['campaign_id'] = $submission['campaign_id'];
|
||||
} // otherwise use the profile's
|
||||
elseif (!empty($campaign = $profile->getAttribute('campaign'))) {
|
||||
$entity_data['campaign_id'] = $campaign;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -137,12 +137,12 @@ class CRM_Twingle_Tools {
|
|||
'source_contact_id' => CRM_Core_Session::getLoggedInContactID(),
|
||||
]);
|
||||
} catch (Exception $ex) {
|
||||
Civi::log()->debug("TwingleAPI: Couldn't create recurring protection activity: " . $ex->getMessage());
|
||||
Civi::log()->warning("TwingleAPI: Couldn't create recurring protection activity: " . $ex->getMessage());
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
Civi::log()->debug("TwingleAPI: Unknown recurring contribution protection mode: '{$protection_mode}'");
|
||||
Civi::log()->warning("TwingleAPI: Unknown recurring contribution protection mode: '{$protection_mode}'");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -203,7 +203,7 @@ class CRM_Twingle_Tools {
|
|||
return reset($ooff_mandate['values']);
|
||||
}
|
||||
} catch (Exception $ex) {
|
||||
Civi::log()->debug("CRM_Twingle_Tools::getMandate failed for [{$contribution_id}]: " . $ex->getMessage());
|
||||
Civi::log()->warning("CRM_Twingle_Tools::getMandate failed for [{$contribution_id}]: " . $ex->getMessage());
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue