diff --git a/code/Api/Contact/MySalesforceContactConfigApi.php b/code/Api/Contact/MySalesforceContactConfigApi.php new file mode 100644 index 0000000..17ae46c --- /dev/null +++ b/code/Api/Contact/MySalesforceContactConfigApi.php @@ -0,0 +1,144 @@ +get('MySalesforceContactConfigApi', 'site_wide_fields_to_send_on_creation'), + $array, + self::$run_time_fields_to_send_on_creation + ); + } + + /** + * @param array|DataList|null $mixed fields to send + * + * @return array + */ + public static function get_fields_to_send_on_update($mixed = null) + { + $array = self::mixed_to_array($mixed); + + return array_merge( + Config::inst()->get('MySalesforceContactConfigApi', 'site_wide_fields_to_send_on_update'), + $array, + self::$run_time_fields_to_send_on_update + ); + } + + /** + * @param array|DataList|null $mixed fields to send + * + * @return array|DataList|null + */ + public static function get_fields_for_filter($mixed = null) + { + $array = self::mixed_to_array($mixed); + + return array_merge( + Config::inst()->get('MySalesforceContactConfigApi', 'site_wide_filter_values'), + $array, + self::$run_time_fields_for_filter + ); + } + + /** + * @param DataList|array|string|null $mixed + * + * @return array + */ + protected static function mixed_to_array($mixed = null) + { + if ($mixed === null) { + $array = []; + } elseif ($mixed instanceof SS_List) { + $array = []; + foreach ($mixed as $object) { + $array[trim($object->Key)] = $object->BetterValue(); + } + } elseif (is_string($mixed)) { + $array = [$mixed]; + } elseif (is_array($mixed)) { + $array = $mixed; + } else { + $array = []; + user_error('Variable ' . print_r($mixed, 1) . ' should be an array. Currently, it is a ' . gettype($mixed)); + } + + return $array; + } +}