From d51d03528f7470e8dea836e33c44057e64887303 Mon Sep 17 00:00:00 2001 From: olayiwola-compucorp Date: Fri, 10 May 2024 10:11:47 +0100 Subject: [PATCH] NEUSPRT-234: Format activity date using format from settings --- .../FormatCaseActivityDateFormat.php | 48 +++++++++++++++++++ .../activity-card-big.directive.html | 2 +- .../activity-card-long.directive.html | 2 +- .../activity-card-short.directive.html | 2 +- .../directives/activity-panel.directive.html | 2 +- api/v3/Activity/Getall.php | 4 ++ civicase.php | 1 + js/modify-activity-date.js | 7 +++ 8 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 CRM/Civicase/Hook/BuildForm/FormatCaseActivityDateFormat.php create mode 100644 js/modify-activity-date.js diff --git a/CRM/Civicase/Hook/BuildForm/FormatCaseActivityDateFormat.php b/CRM/Civicase/Hook/BuildForm/FormatCaseActivityDateFormat.php new file mode 100644 index 000000000..67d34750d --- /dev/null +++ b/CRM/Civicase/Hook/BuildForm/FormatCaseActivityDateFormat.php @@ -0,0 +1,48 @@ +shouldRun($form, $formName)) { + return; + } + + $format = Civi::settings()->get('civiCaseActivityDateformat') ?? '%d %b %Y'; + $dateValue = CRM_Utils_Date::customFormat($form->_defaultValues['activity_date_time'], $format); + + \Civi::resources()->addVars('civicase', ['formatted_date' => $dateValue]); + \Civi::resources()->add([ + 'scriptFile' => [E::LONG_NAME, 'js/modify-activity-date.js'], + 'region' => 'form-body', + ]); + } + + /** + * Checks if this shook should run. + * + * @param CRM_Core_Form $form + * Form Class object. + * @param string $formName + * Form Name. + * + * @return bool + * True if the hook should run. + */ + public function shouldRun($form, $formName) { + return $formName == CRM_Activity_Form_Activity::class && $form->getAction() & CRM_Core_Action::VIEW; + } + +} diff --git a/ang/civicase/activity/card/directives/activity-card-big.directive.html b/ang/civicase/activity/card/directives/activity-card-big.directive.html index 8225ce65d..2e948e309 100644 --- a/ang/civicase/activity/card/directives/activity-card-big.directive.html +++ b/ang/civicase/activity/card/directives/activity-card-big.directive.html @@ -74,7 +74,7 @@ - event{{formatDate(activity.activity_date_time, 'DD MMM YYYY') }} + event{{activity.formatted_activity_date_time}}
{{ activity.subject }}
diff --git a/ang/civicase/activity/card/directives/activity-card-long.directive.html b/ang/civicase/activity/card/directives/activity-card-long.directive.html index 0675d5ca0..a4490d4cc 100644 --- a/ang/civicase/activity/card/directives/activity-card-long.directive.html +++ b/ang/civicase/activity/card/directives/activity-card-long.directive.html @@ -84,7 +84,7 @@ class="civicase__activity-date" ng-class="{'civicase__overdue-activity-icon': activity.is_overdue}"> - {{formatDate(activity.activity_date_time, 'DD MMM YYYY')}} + {{activity.formatted_activity_date_time}} - {{ formatDate(activity.activity_date_time, 'DD MMM YYYY') }} + {{activity.formatted_activity_date_time}} diff --git a/ang/civicase/activity/panel/directives/activity-panel.directive.html b/ang/civicase/activity/panel/directives/activity-panel.directive.html index 107af169f..147c4d335 100644 --- a/ang/civicase/activity/panel/directives/activity-panel.directive.html +++ b/ang/civicase/activity/panel/directives/activity-panel.directive.html @@ -96,7 +96,7 @@

- {{formatDate(activity.activity_date_time, 'DD MMM YYYY')}} + {{activity.formatted_activity_date_time}} diff --git a/api/v3/Activity/Getall.php b/api/v3/Activity/Getall.php index 4caf5594a..25c5c347f 100644 --- a/api/v3/Activity/Getall.php +++ b/api/v3/Activity/Getall.php @@ -80,6 +80,10 @@ function civicrm_api3_activity_getall(array $params) { if (!empty($activityIdsToFetchContactsFor[$row['id']])) { $row = array_merge($activityIdsToFetchContactsFor[$row['id']], $row); } + + if (!empty($row['activity_date_time'])) { + $row['formatted_activity_date_time'] = CRM_Utils_Date::customFormat($row['activity_date_time'], Civi::settings()->get('civiCaseActivityDateformat') ?? '%d %b %Y'); + } } return $result; diff --git a/civicase.php b/civicase.php index 1fee4cc27..0a6784f89 100644 --- a/civicase.php +++ b/civicase.php @@ -156,6 +156,7 @@ function civicase_civicrm_buildForm($formName, &$form) { new CRM_Civicase_Hook_BuildForm_AttachQuotationToInvoiceMail(), new CRM_Civicase_Hook_BuildForm_RefreshInvoiceListOnUpdate(), new CRM_Civicase_Hook_BuildForm_AddCaseActivityDateFormatToDateSettings(), + new CRM_Civicase_Hook_BuildForm_FormatCaseActivityDateFormat(), ]; foreach ($hooks as $hook) { diff --git a/js/modify-activity-date.js b/js/modify-activity-date.js new file mode 100644 index 000000000..86f5cd8fb --- /dev/null +++ b/js/modify-activity-date.js @@ -0,0 +1,7 @@ +CRM.$(function ($) { + (function () { + const date = CRM.vars.civicase.formatted_date; + + CRM.$('.crm-activity-form-block-activity_date_time > td.view-value').text(date); + })(); +});