From 1c5715071f41d3e4f2c880bf7fc5446283ddcf86 Mon Sep 17 00:00:00 2001 From: shahrukh-moby Date: Mon, 6 Nov 2023 23:32:42 +0500 Subject: [PATCH] MMB-273: Add renewal or rolling start date token --- CRM/Certificate/Token/Certificate.php | 9 +++++++++ tests/phpunit/CRM/Certificate/Token/CertificateTest.php | 1 - 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/CRM/Certificate/Token/Certificate.php b/CRM/Certificate/Token/Certificate.php index 6d736fa..ec26d4a 100644 --- a/CRM/Certificate/Token/Certificate.php +++ b/CRM/Certificate/Token/Certificate.php @@ -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 = []) { @@ -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; diff --git a/tests/phpunit/CRM/Certificate/Token/CertificateTest.php b/tests/phpunit/CRM/Certificate/Token/CertificateTest.php index 48720e1..12ec408 100644 --- a/tests/phpunit/CRM/Certificate/Token/CertificateTest.php +++ b/tests/phpunit/CRM/Certificate/Token/CertificateTest.php @@ -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]); }); }