diff --git a/.github/workflows/unit-test.yml b/.github/workflows/unit-test.yml index 98ba66b06..b989b4fea 100644 --- a/.github/workflows/unit-test.yml +++ b/.github/workflows/unit-test.yml @@ -5,7 +5,7 @@ on: pull_request jobs: run-unit-tests: - runs-on: ubuntu-latest + runs-on: ubuntu-20.04 container: compucorp/civicrm-buildkit:1.3.1-php8.0-chrome env: diff --git a/CRM/Civicase/Hook/BuildForm/AddCaseActivityDateFormatToDateSettings.php b/CRM/Civicase/Hook/BuildForm/AddCaseActivityDateFormatToDateSettings.php new file mode 100644 index 000000000..624525ef6 --- /dev/null +++ b/CRM/Civicase/Hook/BuildForm/AddCaseActivityDateFormatToDateSettings.php @@ -0,0 +1,63 @@ +shouldRun($formName)) { + return; + } + + $this->addActivityDateFormatField($form); + } + + /** + * Checks if this shook should run. + * + * @param string $formName + * Form Name. + * + * @return bool + * True if the hook should run. + */ + public function shouldRun($formName) { + return $formName == CRM_Admin_Form_Setting_Date::class; + } + + /** + * Add activity date format field. + * + * @param CRM_Core_Form $form + * Form Class object. + */ + private function addActivityDateFormatField($form) { + $name = 'civiCaseActivityDateformat'; + $fieldName = '_qf_' . $name; + $field = [ + $fieldName => [ + 'html_type' => 'text', + 'title' => ts('Date Format: Activity Feed'), + 'weight' => 5, + ], + ]; + + $form->add('text', $fieldName, $field[$fieldName]['title'], $field[$fieldName]['attributes']); + $value = Civi::settings()->get($name) ?? '%d %b %Y'; + $form->setDefaults(array_merge($form->_defaultValues, [$fieldName => $value])); + + CRM_Core_Region::instance('form-body')->add([ + 'template' => "CRM/Civicase/Form/CaseActivityDateFormat.tpl", + ]); + } + +} 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/CRM/Civicase/Hook/PostProcess/SaveCaseActivityDateFormat.php b/CRM/Civicase/Hook/PostProcess/SaveCaseActivityDateFormat.php new file mode 100644 index 000000000..0886112f6 --- /dev/null +++ b/CRM/Civicase/Hook/PostProcess/SaveCaseActivityDateFormat.php @@ -0,0 +1,50 @@ +shouldRun($formName)) { + return; + } + + $this->saveCaseActivityDateFormatField($form); + } + + /** + * Checks if this shook should run. + * + * @param string $formName + * Form Name. + * + * @return bool + * True if the hook should run. + */ + public function shouldRun($formName) { + return $formName == CRM_Admin_Form_Setting_Date::class; + } + + /** + * Saves The Activity DateFormat field. + * + * @param CRM_Core_Form $form + * Form Class object. + */ + public function saveCaseActivityDateFormatField(CRM_Core_Form &$form) { + $values = $form->getVar('_submitValues'); + if (!empty($values['_qf_civiCaseActivityDateformat'])) { + Civi::settings()->set('civiCaseActivityDateformat', $values['_qf_civiCaseActivityDateformat']); + } + } + +} 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}}
{$form._qf_civiCaseActivityDateformat.label} | +{$form._qf_civiCaseActivityDateformat.html} | +