Commit 27cedb98 authored by eileen's avatar eileen

Convert activity_date_time field to datepicker and add support for url input

This converts the form to being a metadata defined field & a date-picker field as well
as adding standardised url support for input.

The input format is
activity_date_time_high=20100101

I stripped out the complex and probably broken based on feedback  & not used in core
existing hard-coded url support.

Note that there are some outstanding items
1) the upgrade script item needs to be added - this includes dealing with renaming of the field
since I made it more consistent
2) I stripped out the check to ensure the high date is greater than the low date
- if we still want this we should re-add as a generic thing. My guess is it's a bit optional
parent 6a9757ec
......@@ -288,8 +288,10 @@ class CRM_Activity_BAO_Query {
case 'activity_date':
case 'activity_date_low':
case 'activity_date_high':
case 'activity_date_time_low':
case 'activity_date_time_high':
$query->dateQueryBuilder($values,
'civicrm_activity', 'activity_date', 'activity_date_time', ts('Activity Date')
'civicrm_activity', str_replace(['_high', '_low'], '', $name), 'activity_date_time', ts('Activity Date')
);
break;
......@@ -440,7 +442,7 @@ class CRM_Activity_BAO_Query {
* rather than a static function.
*/
public static function getSearchFieldMetadata() {
$fields = ['activity_type_id'];
$fields = ['activity_type_id', 'activity_date_time'];
$metadata = civicrm_api3('Activity', 'getfields', [])['values'];
return array_intersect_key($metadata, array_flip($fields));
}
......@@ -454,10 +456,6 @@ class CRM_Activity_BAO_Query {
$form->addSearchFieldMetadata(['Activity' => self::getSearchFieldMetadata()]);
$form->addFormFieldsFromMetadata();
CRM_Core_Form_Date::buildDateRange($form, 'activity_date', 1, '_low', '_high', ts('From'), FALSE, FALSE);
$form->addElement('hidden', 'activity_date_range_error');
$form->addFormRule(array('CRM_Activity_BAO_Query', 'formRule'), $form);
$followUpActivity = array(
1 => ts('Yes'),
2 => ts('No'),
......@@ -631,27 +629,6 @@ class CRM_Activity_BAO_Query {
return $properties;
}
/**
* 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 = array();
if (empty($fields['activity_date_low']) || empty($fields['activity_date_high'])) {
return TRUE;
}
CRM_Utils_Rule::validDateRange($fields, 'activity_date', $errors, ts('Activity Date'));
return empty($errors) ? TRUE : $errors;
}
/**
* Where/qill clause for notes
*
......
......@@ -322,31 +322,6 @@ class CRM_Activity_Form_Search extends CRM_Core_Form_Search {
}
}
$dateLow = CRM_Utils_Request::retrieve('dateLow', 'String');
if ($dateLow) {
$dateLow = date('m/d/Y', strtotime($dateLow));
$this->_formValues['activity_date_relative'] = 0;
$this->_defaults['activity_date_relative'] = 0;
$this->_formValues['activity_date_low'] = $dateLow;
$this->_defaults['activity_date_low'] = $dateLow;
}
$dateHigh = CRM_Utils_Request::retrieve('dateHigh', 'String');
if ($dateHigh) {
// Activity date time assumes midnight at the beginning of the date
// This sets it to almost midnight at the end of the date
/* if ($dateHigh <= 99999999) {
$dateHigh = 1000000 * $dateHigh + 235959;
} */
$dateHigh = date('m/d/Y', strtotime($dateHigh));
$this->_formValues['activity_date_relative'] = 0;
$this->_defaults['activity_date_relative'] = 0;
$this->_formValues['activity_date_high'] = $dateHigh;
$this->_defaults['activity_date_high'] = $dateHigh;
}
// Enable search activity by custom value
// @todo this is not good security practice. Instead define entity fields in metadata &
// use getEntity Defaults
......
......@@ -1899,6 +1899,8 @@ class CRM_Contact_BAO_Query {
case 'activity_date':
case 'activity_date_low':
case 'activity_date_high':
case 'activity_date_time_low':
case 'activity_date_time_high':
case 'activity_role':
case 'activity_status_id':
case 'activity_status':
......
......@@ -1295,11 +1295,13 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
*
* @param string $fieldName
* @param string $label
* @param bool $isDateTime
* Is this a date-time field (not just date).
* @param bool $required
* @param string $fromLabel
* @param string $toLabel
*/
public function addDatePickerRange($fieldName, $label, $required = FALSE, $fromLabel = 'From', $toLabel = 'To') {
public function addDatePickerRange($fieldName, $label, $isDateTime = FALSE, $required = FALSE, $fromLabel = 'From', $toLabel = 'To') {
$options = array(
'' => ts('- any -'),
......@@ -1314,7 +1316,7 @@ class CRM_Core_Form extends HTML_QuickForm_Page {
NULL
);
$attributes = ['format' => 'searchDate'];
$extra = ['time' => FALSE];
$extra = ['time' => $isDateTime];
$this->add('datepicker', $fieldName . '_low', ts($fromLabel), $attributes, $required, $extra);
$this->add('datepicker', $fieldName . '_high', ts($toLabel), $attributes, $required, $extra);
}
......
......@@ -154,9 +154,8 @@ class CRM_Core_Form_Search extends CRM_Core_Form {
$this->_action = CRM_Core_Action::ADVANCED;
foreach ($this->getSearchFieldMetadata() as $entity => $fields) {
foreach ($fields as $fieldName => $fieldSpec) {
if ($fieldSpec['type'] === CRM_Utils_Type::T_DATE) {
// Assuming time is false for now as we are not checking for date-time fields as yet.
$this->addDatePickerRange($fieldName, $fieldSpec['title'], FALSE);
if ($fieldSpec['type'] === CRM_Utils_Type::T_DATE || $fieldSpec['type'] === (CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME)) {
$this->addDatePickerRange($fieldName, $fieldSpec['title'], ($fieldSpec['type'] === (CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME)));
}
else {
$this->addField($fieldName, ['entity' => $entity]);
......@@ -184,6 +183,10 @@ class CRM_Core_Form_Search extends CRM_Core_Form {
case CRM_Utils_Type::T_INT:
return 'CommaSeparatedIntegers';
case CRM_Utils_Type::T_DATE:
case CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME:
return 'Timestamp';
default:
return 'Alphanumeric';
}
......@@ -204,6 +207,15 @@ class CRM_Core_Form_Search extends CRM_Core_Form {
if ($value !== FALSE) {
$defaults[$fieldSpec['name']] = $value;
}
if ($fieldSpec['type'] === CRM_Utils_Type::T_DATE || ($fieldSpec['type'] === CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME)) {
$low = CRM_Utils_Request::retrieveValue($fieldSpec['name'] . '_low', 'Timestamp', FALSE, NULL, 'GET');
$high = CRM_Utils_Request::retrieveValue($fieldSpec['name'] . '_high', 'Timestamp', FALSE, NULL, 'GET');
if ($low !== FALSE || $high !== FALSE) {
$defaults[$fieldSpec['name'] . '_relative'] = 0;
$defaults[$fieldSpec['name'] . '_low'] = $low ? date('Y-m-d H:i:s', strtotime($low)) : NULL;
$defaults[$fieldSpec['name'] . '_high'] = $high ? date('Y-m-d H:i:s', strtotime($high)) : NULL;
}
}
}
}
return $defaults;
......
......@@ -89,10 +89,9 @@
</tr>
<tr>
<td><label>{ts}Activity Dates{/ts}</label></td>
</tr>
<tr>
{include file="CRM/Core/DateRange.tpl" fieldName="activity_date" from='_low' to='_high'}
<td>
{include file="CRM/Core/DatePickerRange.tpl" fieldName="activity_date_time" from='_low' to='_high'}
</td>
</tr>
<tr>
<td>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment