1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* configuration for adding / updating contact records |
4
|
|
|
*/ |
5
|
|
|
class MySalesforceContactConfigApi extends Object |
6
|
|
|
{ |
7
|
|
|
/** |
8
|
|
|
* @var array |
9
|
|
|
*/ |
10
|
|
|
private static $site_wide_fields_to_send_on_creation = []; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @var array |
14
|
|
|
*/ |
15
|
|
|
private static $site_wide_fields_to_send_on_update = []; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @var array |
19
|
|
|
*/ |
20
|
|
|
private static $site_wide_filter_values = []; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var array |
24
|
|
|
*/ |
25
|
|
|
private static $run_time_fields_to_send_on_creation = []; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var array |
29
|
|
|
*/ |
30
|
|
|
private static $run_time_fields_to_send_on_update = []; |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @var array |
34
|
|
|
*/ |
35
|
|
|
private static $run_time_fields_for_filter = []; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param array|DataList|string $mixed fields to send for creations |
39
|
|
|
*/ |
40
|
|
|
public static function add_fields_to_send_on_creation($mixed) |
41
|
|
|
{ |
42
|
|
|
$array = self::mixed_to_array($mixed); |
43
|
|
|
|
44
|
|
|
self::$run_time_fields_to_send_on_creation += $array; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @param array|DataList|string $mixed fields to send for updates |
49
|
|
|
* |
50
|
|
|
* @return array |
51
|
|
|
*/ |
52
|
|
|
public static function add_fields_to_send_on_update($mixed) |
53
|
|
|
{ |
54
|
|
|
$array = self::mixed_to_array($mixed); |
55
|
|
|
|
56
|
|
|
self::$run_time_fields_to_send_on_update += $array; |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* @param array|DataList|string $mixed fields to send as filters |
61
|
|
|
* |
62
|
|
|
* @return array |
63
|
|
|
*/ |
64
|
|
|
public static function add_fields_to_use_for_filter($mixed) |
65
|
|
|
{ |
66
|
|
|
$array = self::mixed_to_array($mixed); |
67
|
|
|
|
68
|
|
|
self::$run_time_fields_for_filter += $array; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @param array|DataList|null $mixed fields to send |
73
|
|
|
* |
74
|
|
|
* @return array |
75
|
|
|
*/ |
76
|
|
|
public static function get_fields_to_send_on_creation($mixed = null) |
77
|
|
|
{ |
78
|
|
|
$array = self::mixed_to_array($mixed); |
79
|
|
|
|
80
|
|
|
return array_merge( |
81
|
|
|
Config::inst()->get('MySalesforceContactConfigApi', 'site_wide_fields_to_send_on_creation'), |
82
|
|
|
$array, |
83
|
|
|
self::$run_time_fields_to_send_on_creation |
84
|
|
|
); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @param array|DataList|null $mixed fields to send |
89
|
|
|
* |
90
|
|
|
* @return array |
91
|
|
|
*/ |
92
|
|
|
public static function get_fields_to_send_on_update($mixed = null) |
93
|
|
|
{ |
94
|
|
|
$array = self::mixed_to_array($mixed); |
95
|
|
|
|
96
|
|
|
return array_merge( |
97
|
|
|
Config::inst()->get('MySalesforceContactConfigApi', 'site_wide_fields_to_send_on_update'), |
98
|
|
|
$array, |
99
|
|
|
self::$run_time_fields_to_send_on_update |
100
|
|
|
); |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @param array|DataList|null $mixed fields to send |
105
|
|
|
* |
106
|
|
|
* @return array|DataList|null |
107
|
|
|
*/ |
108
|
|
|
public static function get_fields_for_filter($mixed = null) |
109
|
|
|
{ |
110
|
|
|
$array = self::mixed_to_array($mixed); |
111
|
|
|
|
112
|
|
|
return array_merge( |
113
|
|
|
Config::inst()->get('MySalesforceContactConfigApi', 'site_wide_filter_values'), |
114
|
|
|
$array, |
115
|
|
|
self::$run_time_fields_for_filter |
116
|
|
|
); |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
/** |
120
|
|
|
* @param DataList|array|string|null $mixed |
121
|
|
|
* |
122
|
|
|
* @return array |
123
|
|
|
*/ |
124
|
|
|
protected static function mixed_to_array($mixed = null) |
125
|
|
|
{ |
126
|
|
|
if ($mixed === null) { |
127
|
|
|
$array = []; |
128
|
|
|
} elseif ($mixed instanceof SS_List) { |
129
|
|
|
$array = []; |
130
|
|
|
foreach ($mixed as $object) { |
131
|
|
|
$array[trim($object->Key)] = $object->BetterValue(); |
132
|
|
|
} |
133
|
|
|
} elseif (is_string($mixed)) { |
134
|
|
|
$array = [$mixed]; |
135
|
|
|
} elseif (is_array($mixed)) { |
136
|
|
|
$array = $mixed; |
137
|
|
|
} else { |
138
|
|
|
$array = []; |
139
|
|
|
user_error('Variable ' . print_r($mixed, 1) . ' should be an array. Currently, it is a ' . gettype($mixed)); |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
return $array; |
143
|
|
|
} |
144
|
|
|
} |
145
|
|
|
|