Skip to content

Commit

Permalink
Merge pull request #21847 from eileenmcnaughton/pledge2
Browse files Browse the repository at this point in the history
Standardise our 2 pledge templates to use tokens, add tests
  • Loading branch information
demeritcowboy authored Oct 23, 2021
2 parents 2b4f6f2 + 2158534 commit 09c3603
Show file tree
Hide file tree
Showing 15 changed files with 4,211 additions and 4,104 deletions.
61 changes: 12 additions & 49 deletions CRM/Pledge/BAO/Pledge.php
Original file line number Diff line number Diff line change
Expand Up @@ -569,34 +569,6 @@ public static function sendAcknowledgment(&$form, $params) {
$form->assign('payments', $payments);
}

// handle domain token values
$domain = CRM_Core_BAO_Domain::getDomain();
$tokens = [
'domain' => ['name', 'phone', 'address', 'email'],
'contact' => CRM_Core_SelectValues::contactTokens(),
];
$domainValues = [];
foreach ($tokens['domain'] as $token) {
$domainValues[$token] = CRM_Utils_Token::getDomainTokenReplacement($token, $domain);
}
$form->assign('domain', $domainValues);

// handle contact token values.
$ids = [$params['contact_id']];
$fields = array_merge(array_keys(CRM_Contact_BAO_Contact::importableFields()),
['display_name', 'checksum', 'contact_id']
);
foreach ($fields as $key => $val) {
$returnProperties[$val] = TRUE;
}
[$details] = CRM_Utils_Token::getTokenDetails($ids,
$returnProperties,
TRUE, TRUE, NULL,
$tokens,
get_class($form)
);
$form->assign('contact', $details[$params['contact_id']]);

// handle custom data.
if (!empty($params['hidden_custom'])) {
$groupTree = CRM_Core_BAO_CustomGroup::getTree('Pledge', NULL, $params['id']);
Expand Down Expand Up @@ -641,8 +613,7 @@ public static function sendAcknowledgment(&$form, $params) {
}
else {
// set the domain values.
$userName = $domainValues['name'] ?? NULL;
$userEmail = $domainValues['email'] ?? NULL;
[$userName, $userEmail] = CRM_Core_BAO_Domain::getNameAndEmail();
}

if (!isset($receiptFrom)) {
Expand Down Expand Up @@ -829,8 +800,11 @@ public static function getContactPledgeCount($contactID) {
* @param array $params
*
* @return array
* @throws \API_Exception
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
public static function updatePledgeStatus($params) {
public static function updatePledgeStatus($params): array {

$returnMessages = [];

Expand Down Expand Up @@ -934,36 +908,26 @@ public static function updatePledgeStatus($params) {

if ($sendReminders) {
// retrieve domain tokens
$domain = CRM_Core_BAO_Domain::getDomain();
$tokens = [
'domain' => ['name', 'phone', 'address', 'email'],
'contact' => CRM_Core_SelectValues::contactTokens(),
];

$domainValues = [];
foreach ($tokens['domain'] as $token) {
$domainValues[$token] = CRM_Utils_Token::getDomainTokenReplacement($token, $domain);
}

// get the domain email address, since we don't carry w/ object.
$domainValue = CRM_Core_BAO_Domain::getNameAndEmail();
$domainValues['email'] = $domainValue[1];

// retrieve contact tokens

// this function does NOT return Deceased contacts since we don't want to send them email
[$contactDetails] = CRM_Utils_Token::getTokenDetails($contactIds,
NULL,
FALSE, FALSE, NULL,
$tokens, 'CRM_UpdatePledgeRecord'
);
$contactDetails = civicrm_api3('Contact', 'get', [
'is_deceased' => 0,
'id' => ['IN' => $contactIds],
'return' => ['id', 'display_name', 'email', 'do_not_email', 'email', 'on_hold'],
])['values'];

// assign domain values to template
$template = CRM_Core_Smarty::singleton();
$template->assign('domain', $domainValues);

// set receipt from
$receiptFrom = '"' . $domainValues['name'] . '" <' . $domainValues['email'] . '>';
$receiptFrom = CRM_Core_BAO_Domain::getNameAndEmail(FALSE, TRUE);
$receiptFrom = reset($receiptFrom);

foreach ($pledgeDetails as $paymentId => $details) {
if (array_key_exists($details['contact_id'], $contactDetails)) {
Expand Down Expand Up @@ -1008,7 +972,6 @@ public static function updatePledgeStatus($params) {
if ($toEmail && !($doNotEmail || $onHold)) {
// assign value to template
$template->assign('amount_paid', $details['amount_paid'] ? $details['amount_paid'] : 0);
$template->assign('contact', $contactDetails[$contactId]);
$template->assign('next_payment', $details['scheduled_date']);
$template->assign('amount_due', $details['amount_due']);
$template->assign('checksumValue', $details['checksumValue']);
Expand Down
24 changes: 24 additions & 0 deletions CRM/Pledge/WorkflowMessage/PledgeAcknowledge.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

use Civi\WorkflowMessage\GenericWorkflowMessage;

/**
* Acknowledge a new pledge being set up
*
* @support template-only
* @see CRM_Pledge_BAO_Pledge::sendAcknowledgment
*/
class CRM_Pledge_WorkflowMessage_PledgeAcknowledge extends GenericWorkflowMessage {

public const WORKFLOW = 'pledge_acknowledge';

}
24 changes: 24 additions & 0 deletions CRM/Pledge/WorkflowMessage/PledgeReminder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/

use Civi\WorkflowMessage\GenericWorkflowMessage;

/**
* Reminder pledger that a payment is due.
*
* @support template-only
* @see CRM_Pledge_BAO_Pledge::updatePledgeStatus
*/
class CRM_Pledge_WorkflowMessage_PledgeReminder extends GenericWorkflowMessage {

public const WORKFLOW = 'pledge_reminder';

}
18 changes: 18 additions & 0 deletions CRM/Upgrade/Incremental/MessageTemplates.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,24 @@ protected function getTemplateUpdates() {
['name' => 'case_activity', 'type' => 'subject'],
],
],
[
'version' => '5.44.alpha1',
'upgrade_descriptor' => ts('Use domain tokens instead of smarty values'),
'label' => ts('Pledge acknowledgement'),
'templates' => [
['name' => 'pledge_acknowledge', 'type' => 'text'],
['name' => 'pledge_acknowledge', 'type' => 'html'],
],
],
[
'version' => '5.44.alpha1',
'upgrade_descriptor' => ts('Use domain and contact tokens instead of smarty values'),
'label' => ts('Pledge reminder'),
'templates' => [
['name' => 'pledge_reminder', 'type' => 'text'],
['name' => 'pledge_reminder', 'type' => 'html'],
],
],
];
}

Expand Down
8 changes: 8 additions & 0 deletions CRM/Utils/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -1969,6 +1969,14 @@ public static function getTokenDeprecations(): array {
'$last_name' => 'contact.last_name',
'$displayName' => 'contact.display_name',
],
'pledge_acknowledgement' => [
'$domain' => 'no longer available / relevant',
'$contact' => 'no longer available / relevant',
],
'pledge_reminder' => [
'$domain' => 'no longer available / relevant',
'$contact' => 'no longer available / relevant',
],
],
];
}
Expand Down
Loading

0 comments on commit 09c3603

Please sign in to comment.