Skip to content

Commit

Permalink
NEUSPRT-234: Format activity date using format from settings
Browse files Browse the repository at this point in the history
  • Loading branch information
olayiwola-compucorp committed May 10, 2024
1 parent 39efa58 commit d51d035
Show file tree
Hide file tree
Showing 8 changed files with 64 additions and 4 deletions.
48 changes: 48 additions & 0 deletions CRM/Civicase/Hook/BuildForm/FormatCaseActivityDateFormat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

use CRM_Civicase_ExtensionUtil as E;

/**
* FormatCaseActivityDateFormat BuildForm Hook Class.
*/
class CRM_Civicase_Hook_BuildForm_FormatCaseActivityDateFormat {

/**
* Adds Activity DateFormat To Date Settings Form.
*
* @param CRM_Core_Form $form
* Form Class object.
* @param string $formName
* Form Name.
*/
public function run(CRM_Core_Form &$form, $formName) {
if (!$this->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;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
</civicase-tooltip>
</div>
<!-- End - top section -->
<span class="civicase__activity-date" ng-class="{'civicase__overdue-activity-icon': activity.is_overdue}"><i class="material-icons">event</i>{{formatDate(activity.activity_date_time, 'DD MMM YYYY') }}</span>
<span class="civicase__activity-date" ng-class="{'civicase__overdue-activity-icon': activity.is_overdue}"><i class="material-icons">event</i>{{activity.formatted_activity_date_time}}</span>
<!-- Subject -->
<div class="civicase__activity-subject">{{ activity.subject }}</div>
<!-- End - Subject -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
class="civicase__activity-date"
ng-class="{'civicase__overdue-activity-icon': activity.is_overdue}">
<span class="civicase__activity-date__with-year">
{{formatDate(activity.activity_date_time, 'DD MMM YYYY')}}
{{activity.formatted_activity_date_time}}
</span>
<span
class="civicase__activity-date__without-year"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<span ng-if="activity.icon || activity.category.indexOf('milestone') > -1" activity-icon="activity"></span>

<!-- Activity Date -->
<span class="civicase__activity-date" ng-class="{'civicase__overdue-activity-icon': activity.is_overdue}">{{ formatDate(activity.activity_date_time, 'DD MMM YYYY') }}</span>
<span class="civicase__activity-date" ng-class="{'civicase__overdue-activity-icon': activity.is_overdue}">{{activity.formatted_activity_date_time}}</span>
<!-- End - Activity Date -->

<span class="civicase__activity__right-container">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ <h3 class="panel-subtitle clearfix">
<span
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}}
</span>
<!-- End - Activity Date -->

Expand Down
4 changes: 4 additions & 0 deletions api/v3/Activity/Getall.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions civicase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
7 changes: 7 additions & 0 deletions js/modify-activity-date.js
Original file line number Diff line number Diff line change
@@ -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);
})();
});

0 comments on commit d51d035

Please sign in to comment.