forked from civicrm/org.civicrm.civicase
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1015 from compucorp/NEUSPRT-324-timestamp
NEUSPRT-324: Allow user to customize activity date format
- Loading branch information
Showing
14 changed files
with
205 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
CRM/Civicase/Hook/BuildForm/AddCaseActivityDateFormatToDateSettings.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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", | ||
]); | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
CRM/Civicase/Hook/BuildForm/FormatCaseActivityDateFormat.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |
50 changes: 50 additions & 0 deletions
50
CRM/Civicase/Hook/PostProcess/SaveCaseActivityDateFormat.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
})(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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} |