$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.
*
}
/**
- * @param $values
- * @param $query
+ * Get where clause for field.
+ *
+ * @todo most of this could be replaced by using metadata.
+ *
+ * @param array $values
+ * @param \CRM_Contact_BAO_Query $query
+ *
+ * @throws \CRM_Core_Exception
*/
public static function whereClauseSingle(&$values, &$query) {
+ if ($query->buildDateRangeQuery($values)) {
+ // @todo - move this to Contact_Query in or near the call to
+ // $this->buildRelativeDateQuery($values);
+ return;
+ }
list($name, $op, $value, $grouping, $wildcard) = $values;
switch ($name) {
- case 'pledge_create_date_low':
- case 'pledge_create_date_high':
- // process to / from date
- $query->dateQueryBuilder($values,
- 'civicrm_pledge', 'pledge_create_date', 'create_date', 'Pledge Made'
- );
- case 'pledge_start_date_low':
- case 'pledge_start_date_high':
- // process to / from date
- $query->dateQueryBuilder($values,
- 'civicrm_pledge', 'pledge_start_date', 'start_date', 'Pledge Start Date'
- );
- return;
-
- case 'pledge_end_date_low':
- case 'pledge_end_date_high':
- // process to / from date
- $query->dateQueryBuilder($values,
- 'civicrm_pledge', 'pledge_end_date', 'end_date', 'Pledge End Date'
- );
- return;
-
- case 'pledge_payment_date_low':
- case 'pledge_payment_date_high':
- // process to / from date
- $query->dateQueryBuilder($values,
- 'civicrm_pledge_payment', 'pledge_payment_date', 'scheduled_date', 'Payment Scheduled'
- );
- return;
-
- case 'pledge_payment_scheduled_date_low':
- case 'pledge_payment_scheduled_date_high':
- // process to / from date
- $query->dateQueryBuilder($values,
- 'civicrm_pledge_payment', 'pledge_payment_scheduled_date', 'scheduled_date', 'Payment Scheduled'
- );
- return;
-
case 'pledge_amount':
case 'pledge_amount_low':
case 'pledge_amount_high':