static function fixDateValues($relative, &$from, &$to) { if ($relative) { list($from, $to) = CRM_Utils_Date::getFromTo($relative, $from, $to); } }
/** * Convert submitted values for relative custom date fields to query object format. * * The query will support the sqlOperator format so convert to that format. * * @param array $formValues * Submitted values. * @param array $params * Converted parameters for the query object. * @param string $values * Submitted value. * @param string $fieldName * Submitted field name. (Matches form field not DB field.) */ protected static function convertCustomDateRelativeFields(&$formValues, &$params, $values, $fieldName) { if (empty($values)) { // e.g we might have relative set & from & to empty. The form flow is a bit funky & // this function gets called again after they fields have been converted which can get ugly. return; } $customFieldName = self::getCustomFieldName($fieldName); if (substr($fieldName, -9, 9) == '_relative') { list($from, $to) = CRM_Utils_Date::getFromTo($values, NULL, NULL); } else { if ($fieldName == $customFieldName . '_to' && CRM_Utils_Array::value($customFieldName . '_from', $formValues)) { // Both to & from are set. We only need to acton one, choosing from. return; } list($from, $to) = CRM_Utils_Date::getFromTo(NULL, empty($formValues[$customFieldName . '_from']) ? NULL : $formValues[$customFieldName . '_from'], CRM_Utils_Array::value($customFieldName . '_to', $formValues)); } if ($from) { if ($to) { $relativeFunction = array('BETWEEN' => array($from, $to)); } else { $relativeFunction = array('>=' => $from); } } else { $relativeFunction = array('<=' => $to); } $params[] = array($customFieldName, '=', $relativeFunction, 0, 0); }