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

dev/core#561 Convert mailing date search field to using datepicker #15633

Merged
merged 1 commit into from
Oct 28, 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
1 change: 1 addition & 0 deletions CRM/Contact/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -1597,6 +1597,7 @@ public static function convertFormValues(&$formValues, $wildcard = 0, $useEquals
'membership_end_date_relative',
'case_start_date_relative',
'case_end_date_relative',
'mailing_job_start_date_relative',
];
// Handle relative dates first
foreach (array_keys($formValues) as $id) {
Expand Down
1 change: 0 additions & 1 deletion CRM/Contact/BAO/SavedSearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,6 @@ public static function saveRelativeDates(&$queryParams, $formValues) {
'log_date_relative',
'birth_date_relative',
'deceased_date_relative',
'mailing_date_relative',
'relation_date_relative',
'relation_start_date_relative',
'relation_end_date_relative',
Expand Down
3 changes: 3 additions & 0 deletions CRM/Contact/Form/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,9 @@ public function preProcess() {
'mailing_unsubscribe',
'mailing_date_low',
'mailing_date_high',
'mailing_job_start_date_low',
'mailing_job_start_date_high',
'mailing_job_start_date_relative',
] as $mailingFilter) {
$type = 'String';
if ($mailingFilter == 'mailing_id' &&
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 @@ -183,9 +183,9 @@ public function addFormFieldsFromMetadata() {
foreach ($this->getSearchFieldMetadata() as $entity => $fields) {
foreach ($fields as $fieldName => $fieldSpec) {
$fieldType = $fieldSpec['type'] ?? '';
if ($fieldType === CRM_Utils_Type::T_DATE || $fieldType === (CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME)) {
if ($fieldType === CRM_Utils_Type::T_DATE || $fieldType === (CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME) || $fieldType === CRM_Utils_Type::T_TIMESTAMP) {
$title = empty($fieldSpec['unique_title']) ? $fieldSpec['title'] : $fieldSpec['unique_title'];
$this->addDatePickerRange($fieldName, $title, ($fieldType === (CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME)));
$this->addDatePickerRange($fieldName, $title, ($fieldType === (CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME) || $fieldType === CRM_Utils_Type::T_TIMESTAMP));
}
else {
// Not quite sure about moving to a mix of keying by entity vs permitting entity to
Expand Down
27 changes: 1 addition & 26 deletions CRM/Mailing/BAO/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public static function select(&$query) {
* rather than a static function.
*/
public static function getSearchFieldMetadata() {
$fields = [];
$fields = ['mailing_job_start_date'];
$metadata = civicrm_api3('Mailing', 'getfields', [])['values'];
$metadata = array_merge($metadata, civicrm_api3('MailingJob', 'getfields', [])['values']);
return array_intersect_key($metadata, array_flip($fields));
Expand Down Expand Up @@ -427,10 +427,6 @@ public static function buildSearchForm(&$form) {
);
}

CRM_Core_Form_Date::buildDateRange($form, 'mailing_date', 1, '_low', '_high', ts('From'), FALSE);
$form->addElement('hidden', 'mailing_date_range_error');
$form->addFormRule(['CRM_Mailing_BAO_Query', 'formRule'], $form);

$mailingJobStatuses = [
'' => ts('- select -'),
'Complete' => 'Complete',
Expand Down Expand Up @@ -517,25 +513,4 @@ public static function mailingEventQueryBuilder(&$query, &$values, $tableName, $
$query->_tables[$tableName] = $query->_whereTables[$tableName] = 1;
}

/**
* Check if the values in the date range are in correct chronological order.
*
* @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['mailing_date_high']) || empty($fields['mailing_date_low'])) {
return TRUE;
}

CRM_Utils_Rule::validDateRange($fields, 'mailing_date', $errors, ts('Mailing Date'));

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

}
1 change: 1 addition & 0 deletions CRM/Upgrade/Incremental/SmartGroups.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ public function datePickerConversion($fields) {
'pledge_start_date' => 'pledge_start',
'case_start_date' => 'case_from',
'case_end_date' => 'case_to',
'mailing_job_start_date' => 'mailing_date',
];

foreach ($fields as $field) {
Expand Down
4 changes: 4 additions & 0 deletions CRM/Upgrade/Incremental/php/FiveTwenty.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,16 @@ public function upgrade_5_20_alpha1($rev) {
['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'],
['old' => 'mailing_date_relative', 'new' => 'mailing_job_start_date_relative'],
['old' => 'mailing_date_high', 'new' => 'mailing_job_start_date_high'],
['old' => 'mailing_date_low', 'new' => 'mailing_job_start_date_low'],
],
]);
$this->addTask('Update smart groups where jcalendar fields have been converted to datepicker', 'updateSmartGroups', [
'datepickerConversion' => [
'case_start_date',
'case_end_date',
'mailing_job_start_date',
],
]);
}
Expand Down
2 changes: 1 addition & 1 deletion templates/CRM/Mailing/Form/Search/Common.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</tr>
<tr><td><label>{ts}Mailing Date{/ts}</label></td></tr>
<tr>
{include file="CRM/Core/DateRange.tpl" fieldName="mailing_date" from='_low' to='_high'}
{include file="CRM/Core/DatePickerRangeWrapper.tpl" fieldName="mailing_job_start_date"}
</tr>
<tr>
<td>
Expand Down