1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
use SForce\Wsdl\SaveResult; |
4
|
|
|
|
5
|
|
|
class SalesforceContactLog extends DataObject |
6
|
|
|
{ |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* create contact log |
10
|
|
|
* @param string $type |
11
|
|
|
* @param array $fieldsSent |
12
|
|
|
* @param array $filters |
13
|
|
|
* |
14
|
|
|
* @return SalesforceContactLog |
15
|
|
|
*/ |
16
|
|
|
public static function create_contact_log($type, array $fieldsSent, array $filters) : SalesforceContactLog |
|
|
|
|
17
|
|
|
{ |
18
|
|
|
$fieldsSent = serialize($fieldsSent); |
19
|
|
|
$filters = serialize($fieldsSent); |
20
|
|
|
$obj = SalesforceContactLog::create( |
21
|
|
|
[ |
22
|
|
|
'Type' => $type, |
23
|
|
|
'FieldsSent' => $fieldsSent, |
24
|
|
|
'Filters' => $filters, |
25
|
|
|
] |
26
|
|
|
); |
27
|
|
|
$id = $obj->write(); |
28
|
|
|
|
29
|
|
|
return SalesforceContactLog::get()->byID($id); |
|
|
|
|
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* returns true if the contact update was successful |
34
|
|
|
* @param mixed $response |
35
|
|
|
* |
36
|
|
|
* @return bool |
37
|
|
|
*/ |
38
|
|
|
public function confirmContactLog($response) : bool |
39
|
|
|
{ |
40
|
|
|
$id = ''; |
41
|
|
|
$errors = ''; |
42
|
|
|
$hasError = false; |
43
|
|
|
if(is_array($response)) { |
44
|
|
|
$response = $response[0]; |
45
|
|
|
} |
46
|
|
|
if($response instanceof \SForce\Wsdl\SaveResult) { |
47
|
|
|
$id = $response->getId(); |
48
|
|
|
$errors = serialize($response->getErrors()); |
49
|
|
|
if($response->getSuccess()) { |
50
|
|
|
$hasError = false; |
51
|
|
|
} else { |
52
|
|
|
$hasError = true; |
53
|
|
|
} |
54
|
|
|
} else { |
55
|
|
|
$errors = 'Unexpected response: '.serialize($response); |
56
|
|
|
// print_r($response); |
57
|
|
|
user_error('unexptected response'); |
58
|
|
|
} |
59
|
|
|
$this->SalesforceIdentifier = $id; |
|
|
|
|
60
|
|
|
$this->Errors = $errors; |
|
|
|
|
61
|
|
|
$this->HasError = $hasError; |
|
|
|
|
62
|
|
|
$this->write(); |
63
|
|
|
|
64
|
|
|
return $this->HasError; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Singular name for CMS |
69
|
|
|
* @var string |
70
|
|
|
*/ |
71
|
|
|
private static $singular_name = 'Sales Force Contact Log'; |
|
|
|
|
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Plural name for CMS |
75
|
|
|
* @var string |
76
|
|
|
*/ |
77
|
|
|
private static $plural_name = 'Sales Force Contact Log Entries'; |
|
|
|
|
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* SS4 prep! |
81
|
|
|
* @var string |
82
|
|
|
*/ |
83
|
|
|
private static $table_name = 'SalesforceContactLog'; |
|
|
|
|
84
|
|
|
|
85
|
|
|
private static $db = [ |
|
|
|
|
86
|
|
|
'SalesforceIdentifier' => 'Varchar(40)', |
87
|
|
|
'Type' => 'Enum("Created,Updated")', |
88
|
|
|
'Executed' => 'Boolean', |
89
|
|
|
'FieldsSent' => 'Text', |
90
|
|
|
'Filters' => 'Text', |
91
|
|
|
'HasError' => 'Boolean', |
92
|
|
|
'Errors' => 'Text', |
93
|
|
|
]; |
94
|
|
|
|
95
|
|
|
|
96
|
|
|
private static $default_sort = [ |
|
|
|
|
97
|
|
|
'ID' => 'DESC' |
98
|
|
|
]; |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Defines a default list of filters for the search context |
102
|
|
|
* @var array |
103
|
|
|
*/ |
104
|
|
|
private static $searchable_fields = [ |
|
|
|
|
105
|
|
|
'Type' => 'ExactMatchFilter', |
106
|
|
|
'Executed' => 'ExactMatchFilter', |
107
|
|
|
'HasError' => 'ExactMatchFilter', |
108
|
|
|
'SalesforceIdentifier' => 'PartialMatchField', |
109
|
|
|
'FieldsSent' => 'PartialMatchField', |
110
|
|
|
'Filters' => 'PartialMatchField', |
111
|
|
|
'Errors' => 'PartialMatchField', |
112
|
|
|
]; |
113
|
|
|
|
114
|
|
|
/** |
115
|
|
|
* Defines summary fields commonly used in table columns |
116
|
|
|
* as a quick overview of the data for this dataobject |
117
|
|
|
* @var array |
118
|
|
|
*/ |
119
|
|
|
private static $summary_fields = [ |
|
|
|
|
120
|
|
|
'Created.Nice' => 'Created', |
121
|
|
|
'SalesforceIdentifier' => 'SF ID', |
122
|
|
|
'Type' => 'Type', |
123
|
|
|
'Executed.Nice' => 'Executed', |
124
|
|
|
'Type' => 'Type', |
125
|
|
|
'HasError.Nice' => 'Errors', |
126
|
|
|
'Errors' => 'Errors', |
127
|
|
|
]; |
128
|
|
|
|
129
|
|
|
private static $indexes = [ |
|
|
|
|
130
|
|
|
'SalesforceIdentifier' => true |
131
|
|
|
]; |
132
|
|
|
|
133
|
|
|
/** |
134
|
|
|
* CMS Fields |
135
|
|
|
* @return FieldList |
136
|
|
|
*/ |
137
|
|
|
public function getCMSFields() |
138
|
|
|
{ |
139
|
|
|
$fields = parent::getCMSFields(); |
140
|
|
|
$fields->removeFieldsFromTab( |
141
|
|
|
'Root.Main', |
142
|
|
|
[ |
143
|
|
|
'FieldsSent', |
144
|
|
|
'Filters', |
145
|
|
|
'HasError', |
146
|
|
|
'Executed', |
147
|
|
|
] |
148
|
|
|
); |
149
|
|
|
$fields->addFieldsToTab( |
150
|
|
|
'Root.Main', |
151
|
|
|
[ |
152
|
|
|
ReadonlyField::create( |
153
|
|
|
'Created', |
154
|
|
|
'Created', |
155
|
|
|
DBField::create_field('SS_DateTime', $this->Created)->Nice() |
156
|
|
|
), |
157
|
|
|
ReadonlyField::create( |
158
|
|
|
'SalesforceIdentifier', |
159
|
|
|
'Sales Force Identifier' |
160
|
|
|
), |
161
|
|
|
LiteralField::create( |
162
|
|
|
'FieldsSentNice', |
163
|
|
|
'<h2>Fields Sent</h2>'.$this->serializedToHTML($this->FieldsSent) |
|
|
|
|
164
|
|
|
), |
165
|
|
|
ReadonlyField::create( |
166
|
|
|
'Type', |
167
|
|
|
'Type' |
168
|
|
|
), |
169
|
|
|
LiteralField::create( |
170
|
|
|
'FiltersNice', |
171
|
|
|
'<h2>Filters</h2>'.$this->serializedToHTML($this->Filters) |
|
|
|
|
172
|
|
|
), |
173
|
|
|
ReadonlyField::create( |
174
|
|
|
'ExecutedNice', |
175
|
|
|
'Executed', |
176
|
|
|
DBField::create_field('Boolean', $this->Executed)->Nice() |
|
|
|
|
177
|
|
|
), |
178
|
|
|
ReadonlyField::create( |
179
|
|
|
'HasErrorNice', |
180
|
|
|
'HasError', |
181
|
|
|
DBField::create_field('Boolean', $this->HasError)->Nice() |
182
|
|
|
), |
183
|
|
|
ReadonlyField::create( |
184
|
|
|
'Errors', |
185
|
|
|
'Communication Errors' |
186
|
|
|
)->setRightTitle('Separated by three ||| symbols.') |
187
|
|
|
] |
188
|
|
|
); |
189
|
|
|
|
190
|
|
|
return $fields; |
191
|
|
|
} |
192
|
|
|
|
193
|
|
|
/** |
194
|
|
|
* DataObject create permissions |
195
|
|
|
* @param Member $member |
196
|
|
|
* @return bool |
197
|
|
|
*/ |
198
|
|
|
public function canCreate($member = null) |
199
|
|
|
{ |
200
|
|
|
return false; |
201
|
|
|
} |
202
|
|
|
|
203
|
|
|
/** |
204
|
|
|
* DataObject edit permissions |
205
|
|
|
* @param Member $member |
206
|
|
|
* @return bool |
207
|
|
|
*/ |
208
|
|
|
public function canEdit($member = null) |
209
|
|
|
{ |
210
|
|
|
return false; |
211
|
|
|
} |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* DataObject delete permissions |
215
|
|
|
* @param Member $member |
216
|
|
|
* @return bool |
217
|
|
|
*/ |
218
|
|
|
public function canDelete($member = null) |
219
|
|
|
{ |
220
|
|
|
return false; |
221
|
|
|
} |
222
|
|
|
|
223
|
|
|
/** |
224
|
|
|
* |
225
|
|
|
* @param string $serializedString (serialised data) |
226
|
|
|
* @return string (html) |
227
|
|
|
*/ |
228
|
|
|
protected function serializedToHTML($serializedString) |
229
|
|
|
{ |
230
|
|
|
$s = unserialize($serializedString); |
231
|
|
|
|
232
|
|
|
return '<pre>'.print_r($s, 1).'</pre>'; |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
} |
236
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.