Skip to content

Commit

Permalink
NEUSPRT-234: Add a new date format type to the date formats screen ca…
Browse files Browse the repository at this point in the history
…lled “Date Format: Activity Feed”
  • Loading branch information
olayiwola-compucorp committed May 10, 2024
1 parent 84daf75 commit 39efa58
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

/**
* Add ActivityDateFormat To DateSettings BuildForm Hook Class.
*/
class CRM_Civicase_Hook_BuildForm_AddCaseActivityDateFormatToDateSettings {

/**
* 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($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",
]);
}

}
50 changes: 50 additions & 0 deletions CRM/Civicase/Hook/PostProcess/SaveCaseActivityDateFormat.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/**
* Save Activity DateFormat.
*/
class CRM_Civicase_Hook_PostProcess_SaveCaseActivityDateFormat {

/**
* Saves The Activity DateFormat field.
*
* @param string $formName
* Form Name.
* @param CRM_Core_Form $form
* Form Class object.
*/
public function run($formName, CRM_Core_Form $form) {
if (!$this->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']);
}
}

}
2 changes: 2 additions & 0 deletions civicase.php
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ function civicase_civicrm_buildForm($formName, &$form) {
new CRM_Civicase_Hook_BuildForm_AddEntityReferenceToCustomField(),
new CRM_Civicase_Hook_BuildForm_AttachQuotationToInvoiceMail(),
new CRM_Civicase_Hook_BuildForm_RefreshInvoiceListOnUpdate(),
new CRM_Civicase_Hook_BuildForm_AddCaseActivityDateFormatToDateSettings(),
];

foreach ($hooks as $hook) {
Expand Down Expand Up @@ -304,6 +305,7 @@ function civicase_civicrm_postProcess($formName, &$form) {
new CRM_Civicase_Hook_PostProcess_SaveCaseCategoryCustomFields(),
new CRM_Civicase_Hook_PostProcess_SaveCaseCategoryFeature(),
new CRM_Civicase_Hook_PostProcess_SaveQuotationsNotesSettings(),
new CRM_Civicase_Hook_PostProcess_SaveCaseActivityDateFormat(),
];

foreach ($hooks as $hook) {
Expand Down
12 changes: 12 additions & 0 deletions templates/CRM/Civicase/Form/CaseActivityDateFormat.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<table class="form-layout-compressed">
<tr class="crm-date-form-block-_qf_civiCaseActivityDateformat">
<td class="label">{$form._qf_civiCaseActivityDateformat.label}</td>
<td>{$form._qf_civiCaseActivityDateformat.html}</td>
</tr>
</table>

{literal}
<script>
CRM.$('.crm-date-form-block-dateformatTime').last().after(CRM.$('.crm-date-form-block-_qf_civiCaseActivityDateformat'))
</script>
{/literal}

0 comments on commit 39efa58

Please sign in to comment.