From f98d20f25c168fe3773321275c2efafd7251d2f1 Mon Sep 17 00:00:00 2001 From: Jordan Hall Date: Fri, 18 Nov 2016 10:14:04 +0000 Subject: [PATCH] Change getBySelfURL to use same node interpretation logic as getAll --- factories/ContactFactory.php | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/factories/ContactFactory.php b/factories/ContactFactory.php index 343dc26..b7e75e5 100644 --- a/factories/ContactFactory.php +++ b/factories/ContactFactory.php @@ -105,14 +105,28 @@ public static function getBySelfURL($selfURL) } $contactGDNodes = $xmlContactsEntry->children('http://schemas.google.com/g/2005'); - foreach ($contactGDNodes as $key => $value) { - $attributes = $value->attributes(); - - if ($key == 'email') { - $contactDetails[$key] = (string) $attributes['address']; - } else { - $contactDetails[$key] = (string) $value; + switch ($key) { + case 'organization': + $contactDetails[$key]['orgName'] = (string) $value->orgName; + $contactDetails[$key]['orgTitle'] = (string) $value->orgTitle; + break; + case 'email': + $attributes = $value->attributes(); + $emailadress = (string) $attributes['address']; + $emailtype = substr(strstr($attributes['rel'], '#'), 1); + $contactDetails[$key][] = ['type' => $emailtype, 'email' => $emailadress]; + break; + case 'phoneNumber': + $attributes = $value->attributes(); + $uri = (string) $attributes['uri']; + $type = substr(strstr($attributes['rel'], '#'), 1); + $e164 = substr(strstr($uri, ':'), 1); + $contactDetails[$key][] = ['type' => $type, 'number' => $e164]; + break; + default: + $contactDetails[$key] = (string) $value; + break; } }