Skip to content

Commit

Permalink
MMB-273: Add renewal or rolling start date token
Browse files Browse the repository at this point in the history
  • Loading branch information
shahrukh-moby committed Nov 7, 2023
1 parent 6620a27 commit 1c57150
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
9 changes: 9 additions & 0 deletions CRM/Certificate/Token/Certificate.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class CRM_Certificate_Token_Certificate extends CRM_Certificate_Token_AbstractCe
"end_date" => "Certificate End Date",
"valid_from" => "Certificate Valid From Date",
"valid_to" => "Certificate Valid To Date",
"rolling_start_or_renewal_date" => "Certificate Rolling Start Or Renewal Date",
];

public function __construct($tokenNames = []) {
Expand Down Expand Up @@ -101,6 +102,14 @@ private function resolveFields($certificate, array $membershipDates, &$resolvedT
$membershipEndTimestamp = !empty($membershipDates['end_date']) ? strtotime($membershipDates['end_date']) : '';
$certificateValidityStartTimestamp = !empty($certificate->min_valid_from_date) ? strtotime($certificate->min_valid_from_date) : '';
$certificateValidityEndTimestamp = !empty($certificate->max_valid_through_date) ? strtotime($certificate->max_valid_through_date) : '';
$resolvedTokens['rolling_start_or_renewal_date'] = '';

if ($membershipStartTimestamp && $membershipEndTimestamp) {
$renewalTimestamp = strtotime($membershipDates['end_date'] . " -1 year 1 day");
$resolvedTokens['rolling_start_or_renewal_date'] = $renewalTimestamp > $membershipStartTimestamp
? CRM_Utils_Date::customFormat(date('Y-m-d', $renewalTimestamp), '%e/%b/%Y')
: CRM_Utils_Date::customFormat($membershipDates['start_date'], '%e/%b/%Y');
}

$validityStartDate = empty($certificateValidityStartTimestamp) || $membershipStartTimestamp > $certificateValidityStartTimestamp ?
$membershipDates['start_date'] : (string) $certificate->min_valid_from_date;
Expand Down
1 change: 0 additions & 1 deletion tests/phpunit/CRM/Certificate/Token/CertificateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public function testCanResolveCertificateTokenFields() {
$this->assertTrue(is_array($prefetchedTokens));
array_walk($certificateFields, function ($key) use ($prefetchedTokens) {
$this->assertArrayHasKey($key, $prefetchedTokens);
$this->assertNotEmpty($prefetchedTokens[$key]);
});
}

Expand Down

0 comments on commit 1c57150

Please sign in to comment.