@@ -244,9 +244,10 @@ public function buildLeadRecord($leadAttributes, $leadKey = null){
244244 * Format Marketo lead object into something easier to work with
245245 *
246246 * @param object $result The result of a get_lead call
247+ * @param bool $flattenAttributes (defaults to true)
247248 * @return array An array of formatted lead objects
248249 */
249- protected function formatLeads ($ result ){
250+ protected function formatLeads ($ result, $ flattenAttributes = true ){
250251
251252 $ leads = array ();
252253
@@ -260,15 +261,17 @@ protected function formatLeads($result){
260261
261262 }
262263
263- foreach ($ result ->result ->leadRecordList ->leadRecord as $ lead ){
264-
265- $ lead ->attributes = $ this ->flattenAttributes (
266- $ lead ->leadAttributeList ->attribute
267- );
268- unset($ lead ->leadAttributeList );
269-
270- array_push ($ leads , $ lead );
271-
264+ if ($ flattenAttributes ){
265+ foreach ($ result ->result ->leadRecordList ->leadRecord as $ lead ){
266+
267+ $ lead ->attributes = $ this ->flattenAttributes (
268+ $ lead ->leadAttributeList ->attribute
269+ );
270+ unset($ lead ->leadAttributeList );
271+
272+ array_push ($ leads , $ lead );
273+
274+ }
272275 }
273276
274277 return $ leads ;
@@ -303,15 +306,18 @@ protected function flattenAttributes($attributes){
303306 }
304307
305308 /**
306- * Gets an array of one or more leads from a lead cookie, lead id or lead
309+ * Gets an array of one or more leads from a lead cookie, lead id or lead
307310 * email address
308- *
311+ *
309312 * @param string $type 'COOKIE', 'IDNUM' or 'EMAIL'
310313 * @param string $value tracking cookie, email address or lead id value
314+ * @param bool $flattenAttributes (defaults to true) whether to process the
315+ * result leads through flattenAttributes
316+ * @throws Exception
317+ * @throws SoapFault
311318 * @return bool|array a Marketo lead object or false on lead not found
312- * @throws SoapFault|Exception containing an error message
313319 */
314- public function getLeadBy ($ type , $ value ){
320+ public function getLeadBy ($ type , $ value, $ flattenAttributes = true ){
315321
316322 $ params = $ this ->createMarketoGetLeadParams ($ type , $ value );
317323 $ header = $ this ->createMarketoSoapHeader ();
@@ -323,8 +329,8 @@ public function getLeadBy($type, $value){
323329 $ this ->options ,
324330 $ header
325331 );
326-
327- return $ this ->formatLeads ($ leads );
332+
333+ return $ this ->formatLeads ($ leads, $ flattenAttributes );
328334
329335 } catch (SoapFault $ ex ) {
330336 if (
@@ -338,32 +344,39 @@ public function getLeadBy($type, $value){
338344 }
339345
340346 }
341-
347+
342348 /**
343349 * Create or update lead information
344- *
350+ *
345351 * Examples
346- *
352+ *
347353 * When no $lead_key or $cookie is given a new lead will be created
348- *
354+ *
349355 * `$client->syncLead(array('Email' => 'ben@benubois.com'));`
350- *
351- * When a $leadKey or $cookie is specified, Marketo will attempt to
356+ *
357+ * When a $leadKey or $cookie is specified, Marketo will attempt to
352358 * identify the lead and update it
353- *
359+ *
354360 * `$client->syncLead(
355- * array('Unsubscribed' => false),
361+ * array('Unsubscribed' => false),
356362 * 'ben@benubois.com', $_COOKIE['_mkto_trk']
357363 * );`
358- *
364+ *
359365 * @param array $leadAttributes Associative array of lead attributes
360366 * @param null|string $leadKey Optional, The key being used to identify the
361367 * lead, this can be either an email or Marketo ID
362- * @param null|string $cookie Optional, The entire _mkto_trk cookie the
368+ * @param null|string $cookie Optional, The entire _mkto_trk cookie the
363369 * lead will be associated with
370+ * @param bool $flattenAttributes (defaults to true)
364371 * @return object An object containing the lead info
365372 */
366- public function syncLead ($ leadAttributes , $ leadKey = null , $ cookie = null ){
373+ public function syncLead (
374+ $ leadAttributes ,
375+ $ leadKey = null ,
376+ $ cookie = null ,
377+ $ flattenAttributes = true
378+ ){
379+
367380 $ params = new stdClass ;
368381 $ params ->marketoCookie = $ cookie ;
369382 $ params ->returnLead = true ;
@@ -380,12 +393,15 @@ public function syncLead($leadAttributes, $leadKey = null, $cookie = null){
380393 );
381394
382395 $ result = $ result ->result ;
383- $ result ->leadRecord ->attributes = $ this ->flattenAttributes (
384- $ result ->leadRecord ->leadAttributeList ->attribute
385- );
386- unset($ result ->leadRecord ->leadAttributeList );
396+ if ($ flattenAttributes ){
397+ $ result ->leadRecord ->attributes = $ this ->flattenAttributes (
398+ $ result ->leadRecord ->leadAttributeList ->attribute
399+ );
400+ unset($ result ->leadRecord ->leadAttributeList );
401+ }
387402
388403 return $ result ;
404+
389405 }
390406
391407 /**
0 commit comments