$this->buildRelativeDateQuery($values);
return;
}
+ // @todo also handle _low, _high generically here with if ($query->buildDateRangeQuery($values)) {return}
// do not process custom fields or prefixed contact ids or component params
if (CRM_Core_BAO_CustomField::getKeyID($values[0]) ||
* @param string $dateFormat
*/
public function dateQueryBuilder(
- &$values, $tableName, $fieldName,
+ $values, $tableName, $fieldName,
$dbFieldName, $fieldTitle,
$appendTimeStamp = TRUE,
$dateFormat = 'YmdHis'
return isset($this->_fields[$realField]);
}
+ /**
+ * Get the specifications for the field, if available.
+ *
+ * @param string $fieldName
+ * Fieldname as displayed on the form.
+ *
+ * @return array
+ */
+ public function getFieldSpec($fieldName) {
+ if (isset($this->_fields[$fieldName])) {
+ return $this->_fields[$fieldName];
+ }
+ $lowFieldName = str_replace('_low', '', $fieldName);
+ if (isset($this->_fields[$lowFieldName])) {
+ return array_merge($this->_fields[$lowFieldName], ['field_name' => $lowFieldName]);
+ }
+ $highFieldName = str_replace('_high', '', $fieldName);
+ if (isset($this->_fields[$highFieldName])) {
+ return array_merge($this->_fields[$highFieldName], ['field_name' => $highFieldName]);
+ }
+ return [];
+ }
+
+ public function buildWhereForDate() {
+
+ }
+
+ /**
+ * Is the field a relative date field.
+ *
+ * @param string $fieldName
+ *
+ * @return bool
+ */
+ protected function isADateRangeField($fieldName) {
+ if (substr($fieldName, -4, 4) !== '_low' && substr($fieldName, -5, 5) !== '_high') {
+ return FALSE;
+ }
+ return !empty($this->getFieldSpec($fieldName));
+ }
+
/**
* @param $values
*/
}
}
+ /**
+ * Build the query for a date field if it is a _high or _low field.
+ *
+ * @param $values
+ *
+ * @return bool
+ */
+ public function buildDateRangeQuery($values) {
+ if ($this->isADateRangeField($values[0])) {
+ $fieldSpec = $this->getFieldSpec($values[0]);
+ $title = empty($fieldSpec['unique_title']) ? $fieldSpec['title'] : $fieldSpec['unique_title'];
+ $this->dateQueryBuilder($values, $fieldSpec['table_name'], $fieldSpec['field_name'], $fieldSpec['name'], $title);
+ return TRUE;
+ }
+ return FALSE;
+ }
+
/**
* Add the address table into the query.
*