function postProcess() { $params = $this->controller->exportValues($this->_name); CRM_Contact_BAO_Query::fixDateValues($params["mailing_relative"], $params['mailing_from'], $params['mailing_to']); $parent = $this->controller->getParent(); if (!empty($params)) { $fields = array('mailing_name', 'mailing_from', 'mailing_to', 'sort_name', 'campaign_id', 'mailing_status', 'sms', 'status_unscheduled', 'is_archived', 'hidden_find_mailings'); foreach ($fields as $field) { if (isset($params[$field]) && !CRM_Utils_System::isNull($params[$field])) { if (in_array($field, array('mailing_from', 'mailing_to')) && !$params["mailing_relative"]) { $time = $field == 'mailing_to' ? '235959' : NULL; $parent->set($field, CRM_Utils_Date::processDate($params[$field], $time)); } else { $parent->set($field, $params[$field]); } } else { $parent->set($field, NULL); } } } }
static function convertFormValues(&$formValues, $wildcard = 0, $useEquals = FALSE) { $params = array(); if (empty($formValues)) { return $params; } foreach ($formValues as $id => $values) { if ($id == 'privacy') { if (is_array($formValues['privacy'])) { $op = CRM_Utils_Array::value('do_not_toggle', $formValues['privacy']) ? '=' : '!='; foreach ($formValues['privacy'] as $key => $value) { if ($value) { $params[] = array($key, $op, $value, 0, 0); } } } } elseif ($id == 'email_on_hold') { if ($formValues['email_on_hold']['on_hold']) { $params[] = array('on_hold', '=', $formValues['email_on_hold']['on_hold'], 0, 0); } } elseif (preg_match('/_date_relative$/', $id) || $id == 'event_relative') { if ($id == 'event_relative') { $fromRange = 'event_start_date_low'; $toRange = 'event_end_date_high'; } else { $dateComponent = explode('_date_relative', $id); $fromRange = "{$dateComponent[0]}_date_low"; $toRange = "{$dateComponent[0]}_date_high"; } if (array_key_exists($fromRange, $formValues) && array_key_exists($toRange, $formValues)) { CRM_Contact_BAO_Query::fixDateValues($formValues[$id], $formValues[$fromRange], $formValues[$toRange]); continue; } } else { $values = CRM_Contact_BAO_Query::fixWhereValues($id, $values, $wildcard, $useEquals); if (!$values) { continue; } $params[] = $values; } } return $params; }
/** * Convert values from form-appropriate to query-object appropriate. * * The query object is increasingly supporting the sql-filter syntax which is the most flexible syntax. * So, ideally we would convert all fields to look like * array( * 0 => $fieldName * // Set the operator for legacy reasons, but it is ignored * 1 => '=' * // array in sql filter syntax * 2 => array('BETWEEN' => array(1,60), * 3 => null * 4 => null * ); * * There are some examples of the syntax in * https://github.com/civicrm/civicrm-core/tree/master/api/v3/examples/Relationship * * More notes at CRM_Core_DAO::createSQLFilter * * and a list of supported operators in CRM_Core_DAO * * @param array $formValues * @param int $wildcard * @param bool $useEquals * * @param string $apiEntity * * @param array $entityReferenceFields * Field names of any entity reference fields (which will need reformatting to IN syntax). * * @return array */ public static function convertFormValues(&$formValues, $wildcard = 0, $useEquals = FALSE, $apiEntity = NULL, $entityReferenceFields = array()) { $params = array(); if (empty($formValues)) { return $params; } foreach ($formValues as $id => $values) { self::legacyConvertFormValues($id, $values); if (self::isAlreadyProcessedForQueryFormat($values)) { $params[] = $values; continue; } if ($id == 'privacy') { if (is_array($formValues['privacy'])) { $op = !empty($formValues['privacy']['do_not_toggle']) ? '=' : '!='; foreach ($formValues['privacy'] as $key => $value) { if ($value) { $params[] = array($key, $op, $value, 0, 0); } } } } elseif ($id == 'email_on_hold') { if ($formValues['email_on_hold']['on_hold']) { $params[] = array('on_hold', '=', $formValues['email_on_hold']['on_hold'], 0, 0); } } elseif (substr($id, 0, 7) == 'custom_' && (substr($id, -9, 9) == '_relative' || substr($id, -5, 5) == '_from' || substr($id, -3, 3) == '_to')) { self::convertCustomDateRelativeFields($formValues, $params, $values, $id); } elseif (preg_match('/_date_relative$/', $id) || $id == 'event_relative' || $id == 'case_from_relative' || $id == 'case_to_relative' || $id == 'participant_relative') { if ($id == 'event_relative') { $fromRange = 'event_start_date_low'; $toRange = 'event_end_date_high'; } elseif ($id == 'participant_relative') { $fromRange = 'participant_register_date_low'; $toRange = 'participant_register_date_high'; } elseif ($id == 'case_from_relative') { $fromRange = 'case_from_start_date_low'; $toRange = 'case_from_start_date_high'; } elseif ($id == 'case_to_relative') { $fromRange = 'case_to_end_date_low'; $toRange = 'case_to_end_date_high'; } else { $dateComponent = explode('_date_relative', $id); $fromRange = "{$dateComponent[0]}_date_low"; $toRange = "{$dateComponent[0]}_date_high"; } if (array_key_exists($fromRange, $formValues) && array_key_exists($toRange, $formValues)) { CRM_Contact_BAO_Query::fixDateValues($formValues[$id], $formValues[$fromRange], $formValues[$toRange]); continue; } } elseif (in_array($id, $entityReferenceFields) && !empty($values) && is_string($values) && strpos($values, ',') != FALSE) { $params[] = array($id, 'IN', explode(',', $values), 0, 0); } else { $values = CRM_Contact_BAO_Query::fixWhereValues($id, $values, $wildcard, $useEquals, $apiEntity); if (!$values) { continue; } $params[] = $values; } } return $params; }
/** * Convert values from form-appropriate to query-object appropriate. * * The query object is increasingly supporting the sql-filter syntax which is the most flexible syntax. * So, ideally we would convert all fields to look like * array( * 0 => $fieldName * // Set the operator for legacy reasons, but it is ignored * 1 => '=' * // array in sql filter syntax * 2 => array('BETWEEN' => array(1,60), * 3 => null * 4 => null * ); * * There are some examples of the syntax in * https://github.com/civicrm/civicrm-core/tree/master/api/v3/examples/Relationship * * More notes at CRM_Core_DAO::createSQLFilter * * and a list of supported operators in CRM_Core_DAO * * @param array $formValues * @param int $wildcard * @param bool $useEquals * * @param string $apiEntity * * @param array $entityReferenceFields * Field names of any entity reference fields (which will need reformatting to IN syntax). * * @return array */ public static function convertFormValues(&$formValues, $wildcard = 0, $useEquals = FALSE, $apiEntity = NULL, $entityReferenceFields = array()) { $params = array(); if (empty($formValues)) { return $params; } foreach ($formValues as $id => $values) { if (self::isAlreadyProcessedForQueryFormat($values)) { $params[] = $values; continue; } self::legacyConvertFormValues($id, $values); // The form uses 1 field to represent two db fields if ($id == 'contact_type' && $values && (!is_array($values) || !array_intersect(array_keys($values), CRM_Core_DAO::acceptedSQLOperators()))) { $contactType = array(); $subType = array(); foreach ((array) $values as $key => $type) { $types = explode('__', is_numeric($type) ? $key : $type); $contactType[$types[0]] = $types[0]; // Add sub-type if specified if (!empty($types[1])) { $subType[$types[1]] = $types[1]; } } $params[] = array('contact_type', 'IN', $contactType, 0, 0); if ($subType) { $params[] = array('contact_sub_type', 'IN', $subType, 0, 0); } } elseif ($id == 'privacy') { if (is_array($formValues['privacy'])) { $op = !empty($formValues['privacy']['do_not_toggle']) ? '=' : '!='; foreach ($formValues['privacy'] as $key => $value) { if ($value) { $params[] = array($key, $op, $value, 0, 0); } } } } elseif ($id == 'email_on_hold') { if ($formValues['email_on_hold']['on_hold']) { $params[] = array('on_hold', '=', $formValues['email_on_hold']['on_hold'], 0, 0); } } elseif (substr($id, 0, 7) == 'custom_' && (substr($id, -9, 9) == '_relative' || substr($id, -5, 5) == '_from' || substr($id, -3, 3) == '_to')) { self::convertCustomDateRelativeFields($formValues, $params, $values, $id); } elseif (preg_match('/_date_relative$/', $id) || $id == 'event_relative' || $id == 'case_from_relative' || $id == 'case_to_relative' || $id == 'participant_relative') { if ($id == 'event_relative') { $fromRange = 'event_start_date_low'; $toRange = 'event_end_date_high'; } elseif ($id == 'participant_relative') { $fromRange = 'participant_register_date_low'; $toRange = 'participant_register_date_high'; } elseif ($id == 'case_from_relative') { $fromRange = 'case_from_start_date_low'; $toRange = 'case_from_start_date_high'; } elseif ($id == 'case_to_relative') { $fromRange = 'case_to_end_date_low'; $toRange = 'case_to_end_date_high'; } else { $dateComponent = explode('_date_relative', $id); $fromRange = "{$dateComponent[0]}_date_low"; $toRange = "{$dateComponent[0]}_date_high"; } if (array_key_exists($fromRange, $formValues) && array_key_exists($toRange, $formValues)) { CRM_Contact_BAO_Query::fixDateValues($formValues[$id], $formValues[$fromRange], $formValues[$toRange]); continue; } } elseif (in_array($id, $entityReferenceFields) && !empty($values) && is_string($values) && strpos($values, ',') != FALSE) { $params[] = array($id, 'IN', explode(',', $values), 0, 0); } else { $values = CRM_Contact_BAO_Query::fixWhereValues($id, $values, $wildcard, $useEquals, $apiEntity); if (!$values) { continue; } $params[] = $values; } } return $params; }
public static function convertFormValues(&$formValues, $wildcard = 0, $useEquals = FALSE, $apiEntity = NULL) { $params = array(); if (empty($formValues)) { return $params; } foreach ($formValues as $id => $values) { if ($id == 'start_date_relative' || $id == 'end_date_relative') { if ($id == 'start_date_relative') { $fromRange = 'start_date_low'; $toRange = 'start_date_high'; } elseif ($id == 'end_date_relative') { $fromRange = 'end_date_low'; $toRange = 'end_date_high'; } if (array_key_exists($fromRange, $formValues) && array_key_exists($toRange, $formValues)) { CRM_Contact_BAO_Query::fixDateValues($formValues[$id], $formValues[$fromRange], $formValues[$toRange]); continue; } } else { $values = CRM_Relationship_BAO_Query::fixWhereValues($id, $values, $wildcard, $useEquals, $apiEntity); if (!$values) { continue; } $params[] = $values; } } return $params; }