|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* returns a bunch of form fields that inform the user about the configuration |
|
4
|
|
|
* of the connection and communication with Salesforce. |
|
5
|
|
|
*/ |
|
6
|
|
|
class MySalesforceContactConfigApiFormFields extends Object |
|
7
|
|
|
{ |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* [all_fields description] |
|
11
|
|
|
* @param DataObject $dataObject |
|
12
|
|
|
* @param string $createFields |
|
13
|
|
|
* @param string $updateFields |
|
14
|
|
|
* @param string $filterFields |
|
15
|
|
|
* @return array |
|
16
|
|
|
*/ |
|
17
|
|
|
public static function all_fields($dataObject, $createFields, $updateFields, $filterFields) |
|
18
|
|
|
{ |
|
19
|
|
|
return [ |
|
20
|
|
|
self::fields_to_send_field( |
|
21
|
|
|
'create', |
|
22
|
|
|
$this->$createFields() |
|
|
|
|
|
|
23
|
|
|
), |
|
24
|
|
|
|
|
25
|
|
|
self::select_default_contact_fields_field( |
|
26
|
|
|
$createFields, |
|
27
|
|
|
'Select ...' |
|
28
|
|
|
), |
|
29
|
|
|
|
|
30
|
|
|
self::fields_to_send_field( |
|
31
|
|
|
'update', |
|
32
|
|
|
$this->$updateFields() |
|
33
|
|
|
), |
|
34
|
|
|
|
|
35
|
|
|
self::select_default_contact_fields_field( |
|
36
|
|
|
$updateFields, |
|
37
|
|
|
'Select ...' |
|
38
|
|
|
), |
|
39
|
|
|
|
|
40
|
|
|
self::fields_to_send_field( |
|
41
|
|
|
'filter', |
|
42
|
|
|
$this->$filterFields() |
|
43
|
|
|
), |
|
44
|
|
|
|
|
45
|
|
|
self::select_default_contact_fields_field( |
|
46
|
|
|
$filterFields, |
|
47
|
|
|
'Select ...' |
|
48
|
|
|
), |
|
49
|
|
|
|
|
50
|
|
|
self::list_of_contact_record_types_field(), |
|
51
|
|
|
|
|
52
|
|
|
self::login_details_field(), |
|
53
|
|
|
]; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public static function login_details_field( |
|
57
|
|
|
$title = 'Account Used', |
|
58
|
|
|
$fieldName = 'SalesforceLoginDetailsField' |
|
59
|
|
|
) |
|
60
|
|
|
{ |
|
61
|
|
|
$userName = Config::inst()->get('MySalesforcePartnerApiConnectionOnly', 'username'); |
|
62
|
|
|
$password = Config::inst()->get('MySalesforcePartnerApiConnectionOnly', 'password'); |
|
63
|
|
|
$security_token = Config::inst()->get('MySalesforcePartnerApiConnectionOnly', 'security_token'); |
|
64
|
|
|
$wsdl_location = Config::inst()->get('MySalesforcePartnerApiConnectionOnly', 'wsdl_location'); |
|
65
|
|
|
$array = [ |
|
66
|
|
|
'UserName' => $userName, |
|
67
|
|
|
'Password' => substr($password, 0, 2) . '...'.substr($password, -2), |
|
68
|
|
|
'Token' => substr($security_token, 0, 2) . '...'.substr($security_token, -2), |
|
69
|
|
|
'WSDLLocation' => $wsdl_location, |
|
70
|
|
|
]; |
|
71
|
|
|
return LiteralField::create( |
|
72
|
|
|
$fieldName, |
|
73
|
|
|
'<h2>'.$title.'</h2>'. |
|
74
|
|
|
self::array_to_html($array) |
|
75
|
|
|
); |
|
76
|
|
|
} |
|
77
|
|
|
/** |
|
78
|
|
|
* Field with list of contact record types shown |
|
79
|
|
|
* @param string $fieldName |
|
80
|
|
|
* @param string $title |
|
81
|
|
|
* |
|
82
|
|
|
* @return LiteralField |
|
83
|
|
|
*/ |
|
84
|
|
|
public static function list_of_contact_record_types_field( |
|
85
|
|
|
$fieldName = 'ListOfContactRecordTypes', |
|
86
|
|
|
$title = 'Contact Record Types Available' |
|
87
|
|
|
) |
|
88
|
|
|
{ |
|
89
|
|
|
$data = MySalesforceContactApi::retrieve_contact_record_types(); |
|
90
|
|
|
|
|
91
|
|
|
return LiteralField::create( |
|
92
|
|
|
$fieldName, |
|
93
|
|
|
'<h2>'.$title.'</h2>'. |
|
94
|
|
|
'<pre>'.print_r($data, 1).'</pre>' |
|
95
|
|
|
); |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Needs to link to a many-many relationship (SalesforceDefaultContactFields) |
|
100
|
|
|
* @param array $array fields to send |
|
101
|
|
|
* |
|
102
|
|
|
* @return FormField |
|
103
|
|
|
*/ |
|
104
|
|
|
public static function select_default_contact_fields_field($fieldName, $title, $desc = '') |
|
105
|
|
|
{ |
|
106
|
|
|
$count = SalesforceDefaultContactField::get()->count(); |
|
107
|
|
|
if($count === 0) { |
|
108
|
|
|
return HiddenField::create( |
|
109
|
|
|
$fieldName, |
|
110
|
|
|
$title |
|
111
|
|
|
); |
|
112
|
|
|
} |
|
113
|
|
|
return CheckboxSetField::create( |
|
114
|
|
|
$fieldName, |
|
115
|
|
|
$title, |
|
116
|
|
|
SalesforceDefaultContactField::get()->map()->toArray() |
|
117
|
|
|
) |
|
118
|
|
|
->setDescription(' |
|
119
|
|
|
'.$desc.' |
|
120
|
|
|
<br /> |
|
121
|
|
|
You can |
|
122
|
|
|
<a href="/admin/salesforceadmin/'.SalesforceDefaultContactField::class.'/">Add or Edit the options</a> |
|
123
|
|
|
as required. Please change with care. |
|
124
|
|
|
'); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* |
|
129
|
|
|
* @param array|DataList|null $array fields to send |
|
130
|
|
|
* @param string $fieldName fields to send |
|
131
|
|
|
* @param string $title fields to send |
|
132
|
|
|
* |
|
133
|
|
|
* @return LiteralField |
|
134
|
|
|
*/ |
|
135
|
|
|
public static function fields_to_send_field( |
|
136
|
|
|
$type, |
|
137
|
|
|
$mixed = null, |
|
138
|
|
|
$fieldName = 'FieldsToSendToSalesforce', |
|
139
|
|
|
$title = 'Default Fields for' |
|
140
|
|
|
) |
|
141
|
|
|
{ |
|
142
|
|
|
$fieldName .= ucfirst($type); |
|
143
|
|
|
$title .= ' '.ucfirst($type); |
|
144
|
|
|
|
|
145
|
|
|
$array = []; |
|
146
|
|
|
switch( $type ) { |
|
147
|
|
|
case 'create': |
|
148
|
|
|
$array = MySalesforceContactConfigApi::get_fields_to_send_on_creation($mixed); |
|
149
|
|
|
break; |
|
150
|
|
|
case 'update': |
|
151
|
|
|
$array = MySalesforceContactConfigApi::get_fields_to_send_on_update($mixed); |
|
152
|
|
|
break; |
|
153
|
|
|
case 'filter': |
|
154
|
|
|
$array = MySalesforceContactConfigApi::get_fields_for_filter($mixed); |
|
155
|
|
|
break; |
|
156
|
|
|
default: |
|
157
|
|
|
user_error('type needs to be create, update or filter - currently set to: '.$type); |
|
158
|
|
|
break; |
|
159
|
|
|
} |
|
160
|
|
|
return LiteralField::create( |
|
161
|
|
|
$fieldName, |
|
162
|
|
|
'<h2>'.$title.'</h2>'. |
|
163
|
|
|
self::array_to_html($array) |
|
164
|
|
|
); |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* |
|
169
|
|
|
* @param array $array |
|
170
|
|
|
* @return string |
|
171
|
|
|
*/ |
|
172
|
|
|
protected static function array_to_html($array) |
|
173
|
|
|
{ |
|
174
|
|
|
$htmlArray = []; |
|
175
|
|
|
foreach($array as $field => $value) { |
|
176
|
|
|
$htmlArray[] = $field.' = '.$value; |
|
177
|
|
|
} |
|
178
|
|
|
if(count($htmlArray) == 0) { |
|
179
|
|
|
$htmlArray[] = 'none'; |
|
180
|
|
|
} |
|
181
|
|
|
|
|
182
|
|
|
return '<p>- '.implode('</p><p> - ', $htmlArray).'</p>'; |
|
183
|
|
|
} |
|
184
|
|
|
} |
|
185
|
|
|
|