@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php namespace Davispeixoto\ForceDotComToolkitForPhp; |
2 | 2 | |
3 | - /* |
|
3 | + /* |
|
4 | 4 | * Copyright (c) 2007, salesforce.com, inc. |
5 | 5 | * All rights reserved. |
6 | 6 | * |
@@ -34,173 +34,173 @@ discard block |
||
34 | 34 | */ |
35 | 35 | class SforcePartnerClient extends SforceBaseClient |
36 | 36 | { |
37 | - const PARTNER_NAMESPACE = 'urn:partner.soap.sforce.com'; |
|
38 | - |
|
39 | - function __construct() |
|
40 | - { |
|
41 | - $this->namespace = self::PARTNER_NAMESPACE; |
|
42 | - } |
|
43 | - |
|
44 | - protected function getSoapClient($wsdl, $options) |
|
45 | - { |
|
46 | - return new SforceSoapClient($wsdl, $options); |
|
47 | - } |
|
48 | - |
|
49 | - /** |
|
50 | - * Adds one or more new individual objects to your organization's data. |
|
51 | - * @param array $sObjects Array of one or more sObjects (up to 200) to create. |
|
52 | - * @return SaveResult |
|
53 | - */ |
|
54 | - public function create($sObjects) |
|
55 | - { |
|
56 | - $arg = new stdClass; |
|
57 | - foreach ($sObjects as $sObject) { |
|
58 | - if (isset ($sObject->fields)) { |
|
59 | - $sObject->any = $this->_convertToAny($sObject->fields); |
|
60 | - } |
|
61 | - } |
|
62 | - $arg->sObjects = $sObjects; |
|
63 | - |
|
64 | - return parent::_create($arg); |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * Merge records |
|
69 | - * |
|
70 | - * @param stdclass $mergeRequest |
|
71 | - * @param String $type |
|
72 | - * @return mixed |
|
73 | - */ |
|
74 | - public function merge($mergeRequest) |
|
75 | - { |
|
76 | - if (isset($mergeRequest->masterRecord)) { |
|
77 | - if (isset($mergeRequest->masterRecord->fields)) { |
|
78 | - $mergeRequest->masterRecord->any = $this->_convertToAny($mergeRequest->masterRecord->fields); |
|
79 | - } |
|
80 | - $arg = new stdClass(); |
|
81 | - $arg->request = $mergeRequest; |
|
82 | - |
|
83 | - return $this->_merge($arg); |
|
84 | - } |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * |
|
89 | - * @param array $request |
|
90 | - */ |
|
91 | - public function sendSingleEmail($request) |
|
92 | - { |
|
93 | - if (is_array($request)) { |
|
94 | - $messages = array(); |
|
95 | - foreach ($request as $r) { |
|
96 | - $email = new \SoapVar($r, SOAP_ENC_OBJECT, 'SingleEmailMessage', $this->namespace); |
|
97 | - array_push($messages, $email); |
|
98 | - } |
|
99 | - $arg->messages = $messages; |
|
100 | - |
|
101 | - return parent::_sendEmail($arg); |
|
102 | - } else { |
|
103 | - $backtrace = debug_backtrace(); |
|
104 | - error_log('Please pass in array to this function: ' . $backtrace[0]['function']); |
|
105 | - return false; |
|
106 | - } |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * |
|
111 | - * @param array $request |
|
112 | - */ |
|
113 | - public function sendMassEmail($request) |
|
114 | - { |
|
115 | - $arg = new stdClass(); |
|
116 | - if (is_array($request)) { |
|
117 | - $messages = array(); |
|
118 | - foreach ($request as $r) { |
|
119 | - $email = new \SoapVar($r, SOAP_ENC_OBJECT, 'MassEmailMessage', $this->namespace); |
|
120 | - array_push($messages, $email); |
|
121 | - } |
|
122 | - $arg->messages = $messages; |
|
123 | - |
|
124 | - return parent::_sendEmail($arg); |
|
125 | - } else { |
|
126 | - $backtrace = debug_backtrace(); |
|
127 | - error_log('Please pass in array to this function: ' . $backtrace[0]['function']); |
|
128 | - return false; |
|
129 | - } |
|
130 | - } |
|
131 | - |
|
132 | - /** |
|
133 | - * Updates one or more new individual objects to your organization's data. |
|
134 | - * @param array sObjects Array of sObjects |
|
135 | - * @return UpdateResult |
|
136 | - */ |
|
137 | - public function update($sObjects) |
|
138 | - { |
|
139 | - $arg = new stdClass; |
|
140 | - foreach ($sObjects as $sObject) { |
|
141 | - if (isset($sObject->fields)) { |
|
142 | - $sObject->any = $this->_convertToAny($sObject->fields); |
|
143 | - } |
|
144 | - } |
|
145 | - $arg->sObjects = $sObjects; |
|
146 | - |
|
147 | - return parent::_update($arg); |
|
148 | - } |
|
149 | - |
|
150 | - /** |
|
151 | - * Creates new objects and updates existing objects; uses a custom field to |
|
152 | - * determine the presence of existing objects. In most cases, we recommend |
|
153 | - * that you use upsert instead of create because upsert is idempotent. |
|
154 | - * Available in the API version 7.0 and later. |
|
155 | - * |
|
156 | - * @param string $ext_Id External Id |
|
157 | - * @param array $sObjects Array of sObjects |
|
158 | - * @return UpsertResult |
|
159 | - */ |
|
160 | - public function upsert($ext_Id, $sObjects) |
|
161 | - { |
|
162 | - $arg = new stdClass; |
|
163 | - $arg->externalIDFieldName = new \SoapVar($ext_Id, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema'); |
|
164 | - foreach ($sObjects as $sObject) { |
|
165 | - if (isset ($sObject->fields)) { |
|
166 | - $sObject->any = $this->_convertToAny($sObject->fields); |
|
167 | - } |
|
168 | - } |
|
169 | - $arg->sObjects = $sObjects; |
|
170 | - |
|
171 | - return parent::_upsert($arg); |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * @param string $fieldList |
|
176 | - * @param string $sObjectType |
|
177 | - * @param array $ids |
|
178 | - * @return string |
|
179 | - */ |
|
180 | - public function retrieve($fieldList, $sObjectType, $ids) |
|
181 | - { |
|
182 | - return $this->_retrieveResult(parent::retrieve($fieldList, $sObjectType, $ids)); |
|
183 | - } |
|
184 | - |
|
185 | - /** |
|
186 | - * |
|
187 | - * @param mixed $response |
|
188 | - * @return array |
|
189 | - */ |
|
190 | - private function _retrieveResult($response) |
|
191 | - { |
|
192 | - $arr = array(); |
|
193 | - if (is_array($response)) { |
|
194 | - foreach ($response as $r) { |
|
195 | - $sobject = new SObject($r); |
|
196 | - array_push($arr, $sobject); |
|
197 | - } |
|
198 | - } else { |
|
199 | - $sobject = new SObject($response); |
|
200 | - array_push($arr, $sobject); |
|
201 | - } |
|
202 | - |
|
203 | - return $arr; |
|
204 | - } |
|
37 | + const PARTNER_NAMESPACE = 'urn:partner.soap.sforce.com'; |
|
38 | + |
|
39 | + function __construct() |
|
40 | + { |
|
41 | + $this->namespace = self::PARTNER_NAMESPACE; |
|
42 | + } |
|
43 | + |
|
44 | + protected function getSoapClient($wsdl, $options) |
|
45 | + { |
|
46 | + return new SforceSoapClient($wsdl, $options); |
|
47 | + } |
|
48 | + |
|
49 | + /** |
|
50 | + * Adds one or more new individual objects to your organization's data. |
|
51 | + * @param array $sObjects Array of one or more sObjects (up to 200) to create. |
|
52 | + * @return SaveResult |
|
53 | + */ |
|
54 | + public function create($sObjects) |
|
55 | + { |
|
56 | + $arg = new stdClass; |
|
57 | + foreach ($sObjects as $sObject) { |
|
58 | + if (isset ($sObject->fields)) { |
|
59 | + $sObject->any = $this->_convertToAny($sObject->fields); |
|
60 | + } |
|
61 | + } |
|
62 | + $arg->sObjects = $sObjects; |
|
63 | + |
|
64 | + return parent::_create($arg); |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * Merge records |
|
69 | + * |
|
70 | + * @param stdclass $mergeRequest |
|
71 | + * @param String $type |
|
72 | + * @return mixed |
|
73 | + */ |
|
74 | + public function merge($mergeRequest) |
|
75 | + { |
|
76 | + if (isset($mergeRequest->masterRecord)) { |
|
77 | + if (isset($mergeRequest->masterRecord->fields)) { |
|
78 | + $mergeRequest->masterRecord->any = $this->_convertToAny($mergeRequest->masterRecord->fields); |
|
79 | + } |
|
80 | + $arg = new stdClass(); |
|
81 | + $arg->request = $mergeRequest; |
|
82 | + |
|
83 | + return $this->_merge($arg); |
|
84 | + } |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * |
|
89 | + * @param array $request |
|
90 | + */ |
|
91 | + public function sendSingleEmail($request) |
|
92 | + { |
|
93 | + if (is_array($request)) { |
|
94 | + $messages = array(); |
|
95 | + foreach ($request as $r) { |
|
96 | + $email = new \SoapVar($r, SOAP_ENC_OBJECT, 'SingleEmailMessage', $this->namespace); |
|
97 | + array_push($messages, $email); |
|
98 | + } |
|
99 | + $arg->messages = $messages; |
|
100 | + |
|
101 | + return parent::_sendEmail($arg); |
|
102 | + } else { |
|
103 | + $backtrace = debug_backtrace(); |
|
104 | + error_log('Please pass in array to this function: ' . $backtrace[0]['function']); |
|
105 | + return false; |
|
106 | + } |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * |
|
111 | + * @param array $request |
|
112 | + */ |
|
113 | + public function sendMassEmail($request) |
|
114 | + { |
|
115 | + $arg = new stdClass(); |
|
116 | + if (is_array($request)) { |
|
117 | + $messages = array(); |
|
118 | + foreach ($request as $r) { |
|
119 | + $email = new \SoapVar($r, SOAP_ENC_OBJECT, 'MassEmailMessage', $this->namespace); |
|
120 | + array_push($messages, $email); |
|
121 | + } |
|
122 | + $arg->messages = $messages; |
|
123 | + |
|
124 | + return parent::_sendEmail($arg); |
|
125 | + } else { |
|
126 | + $backtrace = debug_backtrace(); |
|
127 | + error_log('Please pass in array to this function: ' . $backtrace[0]['function']); |
|
128 | + return false; |
|
129 | + } |
|
130 | + } |
|
131 | + |
|
132 | + /** |
|
133 | + * Updates one or more new individual objects to your organization's data. |
|
134 | + * @param array sObjects Array of sObjects |
|
135 | + * @return UpdateResult |
|
136 | + */ |
|
137 | + public function update($sObjects) |
|
138 | + { |
|
139 | + $arg = new stdClass; |
|
140 | + foreach ($sObjects as $sObject) { |
|
141 | + if (isset($sObject->fields)) { |
|
142 | + $sObject->any = $this->_convertToAny($sObject->fields); |
|
143 | + } |
|
144 | + } |
|
145 | + $arg->sObjects = $sObjects; |
|
146 | + |
|
147 | + return parent::_update($arg); |
|
148 | + } |
|
149 | + |
|
150 | + /** |
|
151 | + * Creates new objects and updates existing objects; uses a custom field to |
|
152 | + * determine the presence of existing objects. In most cases, we recommend |
|
153 | + * that you use upsert instead of create because upsert is idempotent. |
|
154 | + * Available in the API version 7.0 and later. |
|
155 | + * |
|
156 | + * @param string $ext_Id External Id |
|
157 | + * @param array $sObjects Array of sObjects |
|
158 | + * @return UpsertResult |
|
159 | + */ |
|
160 | + public function upsert($ext_Id, $sObjects) |
|
161 | + { |
|
162 | + $arg = new stdClass; |
|
163 | + $arg->externalIDFieldName = new \SoapVar($ext_Id, XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema'); |
|
164 | + foreach ($sObjects as $sObject) { |
|
165 | + if (isset ($sObject->fields)) { |
|
166 | + $sObject->any = $this->_convertToAny($sObject->fields); |
|
167 | + } |
|
168 | + } |
|
169 | + $arg->sObjects = $sObjects; |
|
170 | + |
|
171 | + return parent::_upsert($arg); |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * @param string $fieldList |
|
176 | + * @param string $sObjectType |
|
177 | + * @param array $ids |
|
178 | + * @return string |
|
179 | + */ |
|
180 | + public function retrieve($fieldList, $sObjectType, $ids) |
|
181 | + { |
|
182 | + return $this->_retrieveResult(parent::retrieve($fieldList, $sObjectType, $ids)); |
|
183 | + } |
|
184 | + |
|
185 | + /** |
|
186 | + * |
|
187 | + * @param mixed $response |
|
188 | + * @return array |
|
189 | + */ |
|
190 | + private function _retrieveResult($response) |
|
191 | + { |
|
192 | + $arr = array(); |
|
193 | + if (is_array($response)) { |
|
194 | + foreach ($response as $r) { |
|
195 | + $sobject = new SObject($r); |
|
196 | + array_push($arr, $sobject); |
|
197 | + } |
|
198 | + } else { |
|
199 | + $sobject = new SObject($response); |
|
200 | + array_push($arr, $sobject); |
|
201 | + } |
|
202 | + |
|
203 | + return $arr; |
|
204 | + } |
|
205 | 205 | |
206 | 206 | } |