Exemplo n.º 1
0
 /**
  * Given an id, extract the formValues of the saved search.
  *
  * @param int $id
  *   The id of the saved search.
  *
  * @return array
  *   the values of the posted saved search used as default values in various Search Form
  */
 public static function &getFormValues($id)
 {
     $fv = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $id, 'form_values');
     $result = NULL;
     if ($fv) {
         // make sure u unserialize - since it's stored in serialized form
         $result = unserialize($fv);
     }
     $specialFields = array('contact_type', 'group', 'contact_tags', 'member_membership_type_id', 'member_status_id');
     foreach ($result as $element => $value) {
         if (CRM_Contact_BAO_Query::isAlreadyProcessedForQueryFormat($value)) {
             $id = CRM_Utils_Array::value(0, $value);
             $value = CRM_Utils_Array::value(2, $value);
             if (is_array($value) && in_array(key($value), CRM_Core_DAO::acceptedSQLOperators(), TRUE)) {
                 $value = CRM_Utils_Array::value(key($value), $value);
             }
             $result[$id] = $value;
             unset($result[$element]);
             continue;
         }
         if (!empty($value) && is_array($value)) {
             if (in_array($element, $specialFields)) {
                 $element = str_replace('member_membership_type_id', 'membership_type_id', $element);
                 $element = str_replace('member_status_id', 'membership_status_id', $element);
                 CRM_Contact_BAO_Query::legacyConvertFormValues($element, $value);
                 $result[$element] = $value;
             } elseif (in_array(key($value), CRM_Core_DAO::acceptedSQLOperators(), TRUE)) {
                 $result[$element] = CRM_Utils_Array::value(key($value), $value);
                 if (is_string($result[$element])) {
                     $result[$element] = str_replace("%", '', $result[$element]);
                 }
             }
         }
         if (substr($element, 0, 7) == 'custom_' && (substr($element, -5, 5) == '_from' || substr($element, -3, 3) == '_to')) {
             // Ensure the _relative field is set if from or to are set to ensure custom date
             // fields with 'from' or 'to' values are displayed when the are set in the smart group
             // being loaded. (CRM-17116)
             if (!isset($result[CRM_Contact_BAO_Query::getCustomFieldName($element) . '_relative'])) {
                 $result[CRM_Contact_BAO_Query::getCustomFieldName($element) . '_relative'] = 0;
             }
         }
         // check to see if we need to convert the old privacy array
         // CRM-9180
         if (!empty($result['privacy'])) {
             if (is_array($result['privacy'])) {
                 $result['privacy_operator'] = 'AND';
                 $result['privacy_toggle'] = 1;
                 if (isset($result['privacy']['do_not_toggle'])) {
                     if ($result['privacy']['do_not_toggle']) {
                         $result['privacy_toggle'] = 2;
                     }
                     unset($result['privacy']['do_not_toggle']);
                 }
                 $result['privacy_options'] = array();
                 foreach ($result['privacy'] as $name => $val) {
                     if ($val) {
                         $result['privacy_options'][] = $name;
                     }
                 }
             }
             unset($result['privacy']);
         }
     }
     return $result;
 }
Exemplo n.º 2
0
 /**
  * Given an id, extract the formValues of the saved search.
  *
  * @param int $id
  *   The id of the saved search.
  *
  * @return array
  *   the values of the posted saved search used as default values in various Search Form
  */
 public static function getFormValues($id)
 {
     $fv = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_SavedSearch', $id, 'form_values');
     $result = NULL;
     if ($fv) {
         // make sure u unserialize - since it's stored in serialized form
         $result = unserialize($fv);
     }
     //CRM-19250: fetch the default date format to format mysql value as per CRM_Core_Error::addDate()
     $dateFormat = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_PreferencesDate', 'searchDate', 'date_format', 'name');
     $dateFormat = empty($dateFormat) ? CRM_Core_Config::singleton()->dateInputFormat : $dateFormat;
     $dateFormat = CRM_Utils_Array::value($dateFormat, CRM_Core_SelectValues::datePluginToPHPFormats());
     $specialFields = array('contact_type', 'group', 'contact_tags', 'member_membership_type_id', 'member_status_id');
     foreach ($result as $element => $value) {
         if (CRM_Contact_BAO_Query::isAlreadyProcessedForQueryFormat($value)) {
             $id = CRM_Utils_Array::value(0, $value);
             $value = CRM_Utils_Array::value(2, $value);
             if (is_array($value) && in_array(key($value), CRM_Core_DAO::acceptedSQLOperators(), TRUE)) {
                 $value = CRM_Utils_Array::value(key($value), $value);
             }
             if (strpos($id, '_date_low') !== FALSE || strpos($id, '_date_high') !== FALSE) {
                 $result[$id] = date($dateFormat, strtotime($value));
                 $entityName = strstr($id, '_date', TRUE);
                 $result["{$entityName}_date_relative"] = 0;
             } else {
                 $result[$id] = $value;
             }
             unset($result[$element]);
             continue;
         }
         if (!empty($value) && is_array($value)) {
             if (in_array($element, $specialFields)) {
                 // Remove the element to minimise support for legacy formats. It is stored in $value
                 // so will be re-set with the right name.
                 unset($result[$element]);
                 $element = str_replace('member_membership_type_id', 'membership_type_id', $element);
                 $element = str_replace('member_status_id', 'membership_status_id', $element);
                 CRM_Contact_BAO_Query::legacyConvertFormValues($element, $value);
                 $result[$element] = $value;
             } elseif (in_array(key($value), CRM_Core_DAO::acceptedSQLOperators(), TRUE)) {
                 $result[$element] = CRM_Utils_Array::value(key($value), $value);
                 if (is_string($result[$element])) {
                     $result[$element] = str_replace("%", '', $result[$element]);
                 }
             }
         }
         if (substr($element, 0, 7) == 'custom_' && (substr($element, -5, 5) == '_from' || substr($element, -3, 3) == '_to')) {
             // Ensure the _relative field is set if from or to are set to ensure custom date
             // fields with 'from' or 'to' values are displayed when the are set in the smart group
             // being loaded. (CRM-17116)
             if (!isset($result[CRM_Contact_BAO_Query::getCustomFieldName($element) . '_relative'])) {
                 $result[CRM_Contact_BAO_Query::getCustomFieldName($element) . '_relative'] = 0;
             }
         }
         // check to see if we need to convert the old privacy array
         // CRM-9180
         if (!empty($result['privacy'])) {
             if (is_array($result['privacy'])) {
                 $result['privacy_operator'] = 'AND';
                 $result['privacy_toggle'] = 1;
                 if (isset($result['privacy']['do_not_toggle'])) {
                     if ($result['privacy']['do_not_toggle']) {
                         $result['privacy_toggle'] = 2;
                     }
                     unset($result['privacy']['do_not_toggle']);
                 }
                 $result['privacy_options'] = array();
                 foreach ($result['privacy'] as $name => $val) {
                     if ($val) {
                         $result['privacy_options'][] = $name;
                     }
                 }
             }
             unset($result['privacy']);
         }
     }
     return $result;
 }