Skip to content

Commit

Permalink
dev/core#561 Convert Case date fields on search forms from jcalendar …
Browse files Browse the repository at this point in the history
…to datepicker

Swap to using buildDateRangeQuery function

Fix notice error and generically handle cases where we have specified to use the LIKE operator for strings
  • Loading branch information
seamuslee001 committed Oct 26, 2019
1 parent 1d5d009 commit 7d832c0
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 46 deletions.
33 changes: 5 additions & 28 deletions CRM/Case/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,11 @@ public static function where(&$query) {
* @param CRM_Contact_BAO_Query $query
*/
public static function whereClauseSingle(&$values, &$query) {
if ($query->buildDateRangeQuery($values)) {
// @todo - move this to Contact_Query in or near the call to
// $this->buildRelativeDateQuery($values);
return;
}
list($name, $op, $value, $grouping, $wildcard) = $values;
$val = $names = [];
switch ($name) {
Expand Down Expand Up @@ -718,12 +723,6 @@ public static function buildSearchForm(&$form) {
$form->addSearchFieldMetadata(['Case' => self::getSearchFieldMetadata()]);
$form->addFormFieldsFromMetadata();

CRM_Core_Form_Date::buildDateRange($form, 'case_from', 1, '_start_date_low', '_start_date_high', ts('From'), FALSE);
CRM_Core_Form_Date::buildDateRange($form, 'case_to', 1, '_end_date_low', '_end_date_high', ts('From'), FALSE);
$form->addElement('hidden', 'case_from_start_date_range_error');
$form->addElement('hidden', 'case_to_end_date_range_error');
$form->addFormRule(['CRM_Case_BAO_Query', 'formRule'], $form);

$form->assign('validCiviCase', TRUE);

//give options when all cases are accessible.
Expand Down Expand Up @@ -752,26 +751,4 @@ public static function buildSearchForm(&$form) {
$form->setDefaults(['case_owner' => 1]);
}

/**
* Custom form rules.
*
* @param array $fields
* @param array $files
* @param CRM_Core_Form $form
*
* @return bool|array
*/
public static function formRule($fields, $files, $form) {
$errors = [];

if ((empty($fields['case_from_start_date_low']) || empty($fields['case_from_start_date_high'])) && (empty($fields['case_to_end_date_low']) || empty($fields['case_to_end_date_high']))) {
return TRUE;
}

CRM_Utils_Rule::validDateRange($fields, 'case_from_start_date', $errors, ts('Case Start Date'));
CRM_Utils_Rule::validDateRange($fields, 'case_to_end_date', $errors, ts('Case End Date'));

return empty($errors) ? TRUE : $errors;
}

}
11 changes: 1 addition & 10 deletions CRM/Case/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,7 @@ public function preProcess() {
$this->loadFormValues();

if ($this->_force) {
$this->postProcess();
$this->set('force', 0);
$this->handleForcedSearch();
}

$sortID = NULL;
Expand Down Expand Up @@ -213,7 +212,6 @@ public function postProcess() {
$this->_done = TRUE;
$this->setFormValues();
$this->fixFormValues();

if (isset($this->_ssID) && empty($_POST)) {
// if we are editing / running a saved search and the form has not been posted
$this->_formValues = CRM_Contact_BAO_SavedSearch::getFormValues($this->_ssID);
Expand Down Expand Up @@ -385,13 +383,6 @@ public function fixFormValues() {
}
}

/**
* @return null
*/
public function getFormValues() {
return NULL;
}

/**
* Return a descriptive name for the page, used in wizard header
*
Expand Down
2 changes: 2 additions & 0 deletions CRM/Contact/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -1595,6 +1595,8 @@ public static function convertFormValues(&$formValues, $wildcard = 0, $useEquals
'membership_join_date_relative',
'membership_start_date_relative',
'membership_end_date_relative',
'case_start_date_relative',
'case_end_date_relative',
];
// Handle relative dates first
foreach (array_keys($formValues) as $id) {
Expand Down
2 changes: 2 additions & 0 deletions CRM/Upgrade/Incremental/SmartGroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ public function datePickerConversion($fields) {
'pledge_create_date' => 'pledge_create',
'pledge_end_date' => 'pledge_end',
'pledge_start_date' => 'pledge_start',
'case_start_date' => 'case_from',
'case_end_date' => 'case_to',
];

foreach ($fields as $field) {
Expand Down
16 changes: 16 additions & 0 deletions CRM/Upgrade/Incremental/php/FiveTwenty.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,22 @@ public function upgrade_5_20_alpha1($rev) {
}
$this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
$this->addTask('Add "Template" contribution status', 'templateStatus');
$this->addTask('Update smart groups to rename filters on case_from and case_to to case_start_date and case_end_date', 'updateSmartGroups', [
'renameField' => [
['old' => 'case_from_relative', 'new' => 'case_start_date_relative'],
['old' => 'case_from_start_date_high', 'new' => 'case_start_date_high'],
['old' => 'case_from_start_date_low', 'new' => 'case_start_date_low'],
['old' => 'case_to_relative', 'new' => 'case_end_date_relative'],
['old' => 'case_to_end_date_high', 'new' => 'case_end_date_high'],
['old' => 'case_to_end_date_low', 'new' => 'case_end_date_low'],
],
]);
$this->addTask('Update smart groups where jcalendar fields have been converted to datepicker', 'updateSmartGroups', [
'datepickerConversion' => [
'case_start_date',
'case_end_date',
],
]);
}

public static function templateStatus(CRM_Queue_TaskContext $ctx) {
Expand Down
10 changes: 2 additions & 8 deletions templates/CRM/Case/Form/Search/Common.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,10 @@
</tr>

<tr>
<td>
<label>{ts}Case Start Date{/ts}</label>
</td>
{include file="CRM/Core/DateRange.tpl" fieldName="case_from" from='_start_date_low' to='_start_date_high'}
{include file="CRM/Core/DatePickerRangeWrapper.tpl" fieldName="case_start_date"}
</tr>
<tr>
<td>
<label>{ts}Case End Date{/ts}</label>
</td>
{include file="CRM/Core/DateRange.tpl" fieldName="case_to" from='_end_date_low' to='_end_date_high'}
{include file="CRM/Core/DatePickerRangeWrapper.tpl" fieldName="case_end_date"}
</tr>

<tr id='case_search_form'>
Expand Down

0 comments on commit 7d832c0

Please sign in to comment.