Skip to content

Commit

Permalink
Switch pledge_reminder over to use tokens
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Oct 22, 2021
1 parent 432b761 commit c8af617
Show file tree
Hide file tree
Showing 9 changed files with 3,753 additions and 3,741 deletions.
30 changes: 11 additions & 19 deletions CRM/Pledge/BAO/Pledge.php
Original file line number Diff line number Diff line change
Expand Up @@ -800,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 @@ -905,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 @@ -979,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
9 changes: 9 additions & 0 deletions CRM/Upgrade/Incremental/MessageTemplates.php
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,15 @@ protected function getTemplateUpdates() {
['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
4 changes: 4 additions & 0 deletions CRM/Utils/Token.php
Original file line number Diff line number Diff line change
Expand Up @@ -1973,6 +1973,10 @@ public static function getTokenDeprecations(): array {
'$domain' => 'no longer available / relevant',
'$contact' => 'no longer available / relevant',
],
'pledge_reminder' => [
'$domain' => 'no longer available / relevant',
'$contact' => 'no longer available / relevant',
],
],
];
}
Expand Down
7,413 changes: 3,701 additions & 3,712 deletions sql/civicrm_generated.mysql

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions tests/phpunit/CRM/Pledge/BAO/PledgeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,4 +135,21 @@ public function testGetPledgeStartDate(): void {
$this->assertEquals('06/10/2016', date('m/d/Y', strtotime($date)), 'The two dates do not match');
}

/**
* Test the job that updates pledge.
*/
public function testPledgeUpdate(): void {
$this->pledgeCreate($this->_params);
$this->addLocationBlockToDomain();
$mut = new CiviMailUtils($this);
CRM_Pledge_BAO_Pledge::updatePledgeStatus(['send_reminders' => TRUE]);
$mut->checkAllMailLog([
'Dear Anthony,',
'123',
'fixme.domainemail@example.org',
'10 Downing Street
London,',
]);
}

}
3 changes: 2 additions & 1 deletion tests/phpunit/CRM/Pledge/Form/PledgeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
use Civi\Api4\Email;

/**
* Include dataProvider for tests
* CRM_Pledge_Form_PledgeTest
*
* @group headless
*/
class CRM_Pledge_Form_PledgeTest extends CiviUnitTestCase {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{assign var="greeting" value="{contact.email_greeting_display}"}{if $greeting}<p>{$greeting},</p>{/if}
{assign var="greeting" value="{contact.email_greeting_display}"}{if $greeting}{$greeting},{/if}

{ts}Thank you for your generous pledge.{/ts}

Expand Down
8 changes: 4 additions & 4 deletions xml/templates/message_templates/pledge_reminder_html.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

<tr>
<td>
{assign var="greeting" value="{contact.email_greeting}"}{if $greeting}<p>{$greeting},</p>{/if}
{assign var="greeting" value="{contact.email_greeting_display}"}{if $greeting}<p>{$greeting},</p>{/if}
<p>{ts 1=$next_payment|truncate:10:''|crmDate}This is a reminder that the next payment on your pledge is due on %1.{/ts}</p>
</td>
</tr>
Expand All @@ -47,10 +47,10 @@
<tr>
<td>
{if $contribution_page_id}
{capture assign=contributionUrl}{crmURL p='civicrm/contribute/transact' q="reset=1&id=`$contribution_page_id`&cid=`$contact.contact_id`&pledgeId=`$pledge_id`&cs=`$checksumValue`" a=true h=0 fe=1}{/capture}
{capture assign=contributionUrl}{crmURL p='civicrm/contribute/transact' q="reset=1&id=`$contribution_page_id`&cid=`{contact.id}`&pledgeId=`$pledge_id`&cs=`$checksumValue`" a=true h=0 fe=1}{/capture}
<p><a href="{$contributionUrl}">{ts}Go to a web page where you can make your payment online{/ts}</a></p>
{else}
<p>{ts}Please mail your payment to{/ts}: {$domain.address}</p>
<p>{ts}Please mail your payment to{/ts}: {domain.address}</p>
{/if}
</td>
</tr>
Expand Down Expand Up @@ -93,7 +93,7 @@

<tr>
<td>
<p>{ts 1=$domain.phone 2=$domain.email}Please contact us at %1 or send email to %2 if you have questions
<p>{ts 1='{domain.phone}' 2='{domain.email}'}Please contact us at %1 or send email to %2 if you have questions
or need to modify your payment schedule.{/ts}</p>
<p>{ts}Thank your for your generous support.{/ts}</p>
</td>
Expand Down
8 changes: 4 additions & 4 deletions xml/templates/message_templates/pledge_reminder_text.tpl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{assign var="greeting" value="{contact.email_greeting}"}{if $greeting}{$greeting},{/if}
{assign var="greeting" value="{contact.email_greeting_display}"}{if $greeting}{$greeting},{/if}

{ts 1=$next_payment|truncate:10:''|crmDate}This is a reminder that the next payment on your pledge is due on %1.{/ts}

Expand All @@ -10,12 +10,12 @@
{ts}Due Date{/ts}: {$scheduled_payment_date|truncate:10:''|crmDate}

{if $contribution_page_id}
{capture assign=contributionUrl}{crmURL p='civicrm/contribute/transact' q="reset=1&id=`$contribution_page_id`&cid=`$contact.contact_id`&pledgeId=`$pledge_id`&cs=`$checksumValue`" a=true h=0 fe=1}{/capture}
{capture assign=contributionUrl}{crmURL p='civicrm/contribute/transact' q="reset=1&id=`$contribution_page_id`&cid=`{contact.id}`&pledgeId=`$pledge_id`&cs=`$checksumValue`" a=true h=0 fe=1}{/capture}
Click this link to go to a web page where you can make your payment online:
{$contributionUrl}
{else}
{ts}Please mail your payment to{/ts}:
{$domain.address}
{domain.address}
{/if}

===========================================================
Expand All @@ -26,7 +26,7 @@ Click this link to go to a web page where you can make your payment online:
{ts}Total Pledge Amount{/ts}: {$amount|crmMoney:$currency}
{ts}Total Paid{/ts}: {$amount_paid|crmMoney:$currency}

{ts 1=$domain.phone 2=$domain.email}Please contact us at %1 or send email to %2 if you have questions
{ts 1='{domain.phone}' 2='{domain.email}'} Please contact us at %1 or send email to %2 if you have questions
or need to modify your payment schedule.{/ts}


Expand Down

0 comments on commit c8af617

Please sign in to comment.