Skip to content

Commit

Permalink
[jcalendar] remove jcalendar usage from participant_register_date on …
Browse files Browse the repository at this point in the history
…event search

This removes one more place where legacy jcalendar is used. There is actually still one left on the form (event date)
which I left out for now as it involves thinking about the fact event is a different entity & might warrant different
representation in the arrays
  • Loading branch information
eileenmcnaughton committed May 28, 2019
1 parent 61b4d09 commit 8a6fde2
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 28 deletions.
25 changes: 12 additions & 13 deletions CRM/Contact/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -1553,23 +1553,21 @@ public static function convertFormValues(&$formValues, $wildcard = 0, $useEquals
}

self::filterCountryFromValuesIfStateExists($formValues);

// We shouldn't have to whitelist fields to not hack but here we are, for now.
$nonLegacyDateFields = ['participant_register_date_relative'];
// Handle relative dates first
foreach (array_keys($formValues) as $id) {
if (preg_match('/_date_relative$/', $id) ||
if (
!in_array($id, $nonLegacyDateFields) && (
preg_match('/_date_relative$/', $id) ||
$id == 'event_relative' ||
$id == 'case_from_relative' ||
$id == 'case_to_relative' ||
$id == 'participant_relative'
$id == 'case_to_relative')
) {
if ($id == 'event_relative') {
$fromRange = 'event_start_date_low';
$toRange = 'event_end_date_high';
}
elseif ($id == 'participant_relative') {
$fromRange = 'participant_register_date_low';
$toRange = 'participant_register_date_high';
}
elseif ($id == 'case_from_relative') {
$fromRange = 'case_from_start_date_low';
$toRange = 'case_from_start_date_high';
Expand Down Expand Up @@ -1647,11 +1645,12 @@ public static function convertFormValues(&$formValues, $wildcard = 0, $useEquals
) {
self::convertCustomRelativeFields($formValues, $params, $values, $id);
}
elseif (preg_match('/_date_relative$/', $id) ||
$id == 'event_relative' ||
$id == 'case_from_relative' ||
$id == 'case_to_relative' ||
$id == 'participant_relative'
elseif (
!in_array($id, $nonLegacyDateFields) && (
preg_match('/_date_relative$/', $id) ||
$id == 'event_relative' ||
$id == 'case_from_relative' ||
$id == 'case_to_relative')
) {
// Already handled in previous loop
continue;
Expand Down
2 changes: 0 additions & 2 deletions CRM/Contact/BAO/SavedSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ public static function getFormValues($id) {
$specialDateFields = [
'event_start_date_low' => 'event_date_low',
'event_end_date_high' => 'event_date_high',
'participant_register_date_low' => 'participant_date_low',
'participant_register_date_high' => 'participant_date_high',
'case_from_start_date_low' => 'case_from_date_low',
'case_from_start_date_high' => 'case_from_date_high',
'case_to_end_date_low' => 'case_to_date_low',
Expand Down
2 changes: 1 addition & 1 deletion CRM/Core/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ public static function formRule($fields, $files, $form) {
foreach ($form->getSearchFieldMetadata() as $entity => $spec) {
foreach ($spec as $fieldName => $fieldSpec) {
if ($fieldSpec['type'] === CRM_Utils_Type::T_DATE || $fieldSpec['type'] === (CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME)) {
if (isset($fields[$fieldName . '_high']) && isset($fields[$fieldName . '_low']) && empty($fields[$fieldName . '_relative'])) {
if (!empty($fields[$fieldName . '_high']) && !empty($fields[$fieldName . '_low']) && empty($fields[$fieldName . '_relative'])) {
if (strtotime($fields[$fieldName . '_low']) > strtotime($fields[$fieldName . '_high'])) {
$errors[$fieldName . '_low'] = ts('%1: Please check that your date range is in correct chronological order.', [1 => $fieldSpec['title']]);
}
Expand Down
12 changes: 2 additions & 10 deletions CRM/Event/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ public static function defaultReturnProperties(
public static function getSearchFieldMetadata() {
$fields = [
'participant_status_id',
'participant_register_date',
];
$metadata = civicrm_api3('Participant', 'getfields', [])['values'];
return array_intersect_key($metadata, array_flip($fields));
Expand Down Expand Up @@ -628,10 +629,7 @@ public static function buildSearchForm(&$form) {

CRM_Core_Form_Date::buildDateRange($form, 'event', 1, '_start_date_low', '_end_date_high', ts('From'), FALSE);

CRM_Core_Form_Date::buildDateRange($form, 'participant', 1, '_register_date_low', '_register_date_high', ts('From'), FALSE);

$form->addElement('hidden', 'event_date_range_error');
$form->addElement('hidden', 'participant_date_range_error');
$form->addFormRule(['CRM_Event_BAO_Query', 'formRule'], $form);

$form->addElement('checkbox', "event_include_repeating_events", NULL, ts('Include participants from all events in the %1 series', [1 => '<em>%1</em>']));
Expand Down Expand Up @@ -686,7 +684,7 @@ public static function tableNames(&$tables) {
public static function formRule($fields, $files, $form) {
$errors = [];

if ((empty($fields['event_start_date_low']) || empty($fields['event_end_date_high'])) && (empty($fields['participant_register_date_low']) || empty($fields['participant_register_date_high']))) {
if ((empty($fields['event_start_date_low']) || empty($fields['event_end_date_high']))) {
return TRUE;
}
$lowDate = strtotime($fields['event_start_date_low']);
Expand All @@ -696,12 +694,6 @@ public static function formRule($fields, $files, $form) {
$errors['event_date_range_error'] = ts('Please check that your Event Date Range is in correct chronological order.');
}

$lowDate1 = strtotime($fields['participant_register_date_low']);
$highDate1 = strtotime($fields['participant_register_date_high']);

if ($lowDate1 > $highDate1) {
$errors['participant_date_range_error'] = ts('Please check that your Registration Date Range is in correct chronological order.');
}
return empty($errors) ? TRUE : $errors;
}

Expand Down
3 changes: 2 additions & 1 deletion CRM/Event/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,9 @@ class CRM_Event_Form_Search extends CRM_Core_Form_Search {
*/
protected $searchFieldMetadata = [];


/**
* Get the default entity for the form.
*
* @return string
*/
public function getDefaultEntity() {
Expand Down
5 changes: 5 additions & 0 deletions CRM/Upgrade/Incremental/php/FiveFifteen.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,11 @@ public function upgrade_5_15_alpha1($rev) {
$this->addTask(ts('Upgrade DB to %1: SQL', [1 => $rev]), 'runSql', $rev);
$this->addTask('Fix errant deferred revenue settings', 'updateContributeSettings');
$this->addTask('Fix cache key column name in prev next cache', 'fixCacheKeyColumnNamePrevNext');
$this->addTask('Update smart groups where jcalendar fields have been converted to datepicker', 'updateSmartGroups', [
'datepickerConversion' => [
'participant_register_date',
],
]);
}

public static function fixCacheKeyColumnNamePrevNext() {
Expand Down
2 changes: 1 addition & 1 deletion templates/CRM/Event/Form/Search/Common.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
{include file="CRM/Core/DateRange.tpl" fieldName="event" from='_start_date_low' to='_end_date_high' label="<label>Event Dates</label>"}
</tr>
<tr>
{include file="CRM/Core/DateRange.tpl" fieldName="participant" from='_register_date_low' to='_register_date_high' label="<label>Registration Date</label>"}
{include file="CRM/Core/DatePickerRangeWrapper.tpl" fieldName="participant_register_date" colspan="2"}
</tr>
<tr>
<td class="crm-event-form-block-participant_status"><label>{$form.participant_status_id.label}</label>
Expand Down

0 comments on commit 8a6fde2

Please sign in to comment.