Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[code-quality] [jcalendar] remove jcalendar usage from participant_register_date on event search #14330

Merged
merged 2 commits into from
Jun 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 2 additions & 2 deletions CRM/Core/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public function addSearchFieldMetadata($searchFieldMetadata) {
/**
* Common buildForm tasks required by all searches.
*/
public function buildQuickform() {
public function buildQuickForm() {
CRM_Core_Resources::singleton()
->addScriptFile('civicrm', 'js/crm.searchForm.js', 1, 'html-header')
->addStyleFile('civicrm', 'css/searchForm.css', 1, 'html-header');
Expand Down 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
44 changes: 23 additions & 21 deletions CRM/Event/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -575,9 +575,30 @@ public static function defaultReturnProperties(
}

/**
* @param CRM_Core_Form $form
* Get the metadata for fields to be included on the grant search form.
*
* @throws \CiviCRM_API3_Exception
*/
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));
}

/**
* Build the event search form.
*
* @param \CRM_Event_Form_Search $form
*
* @throws \CiviCRM_API3_Exception
* @throws \CRM_Core_Exception
*/
public static function buildSearchForm(&$form) {
$form->addSearchFieldMetadata(['Participant' => self::getSearchFieldMetadata()]);
$form->addFormFieldsFromMetadata();
$dataURLEventFee = CRM_Utils_System::url('civicrm/ajax/eventFee',
"reset=1",
FALSE, NULL, FALSE
Expand Down Expand Up @@ -608,24 +629,11 @@ 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>']));

$form->addSelect('participant_status_id',
[
'entity' => 'participant',
'label' => ts('Participant Status'),
'multiple' => 'multiple',
'option_url' => NULL,
'placeholder' => ts('- any -'),
]
);

$form->addSelect('participant_role_id',
[
'entity' => 'participant',
Expand Down Expand Up @@ -676,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 @@ -686,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
23 changes: 18 additions & 5 deletions CRM/Event/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,6 @@
* @copyright CiviCRM LLC (c) 2004-2019
*/

/**
* Files required
*/

/**
* This file is for civievent search
*/
Expand Down Expand Up @@ -74,6 +70,22 @@ class CRM_Event_Form_Search extends CRM_Core_Form_Search {
*/
protected $_ssID;

/**
* Metadata of all fields to include on the form.
*
* @var array
*/
protected $searchFieldMetadata = [];

/**
* Get the default entity for the form.
*
* @return string
*/
public function getDefaultEntity() {
return 'Participant';
}

/**
* Processing needed for buildForm and later.
*
Expand Down Expand Up @@ -138,8 +150,9 @@ public function preProcess() {
/**
* Build the form object.
*
*
* @return void
*
* @throws \CRM_Core_Exception
*/
public function buildQuickForm() {
parent::buildQuickForm();
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