Skip to content

Commit

Permalink
Better Contact matching + better US phone format
Browse files Browse the repository at this point in the history
  • Loading branch information
tlshaheen committed Aug 11, 2016
1 parent bc59e5d commit c31e84a
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/NationBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -428,6 +428,14 @@ public function findContact($personId, $searchParams)
return null;
}

/**
* Find contact made by author_id
* @param $searchParams
*
* @return null
* @author tlshaheen
* @date 8-10-2016
*/
public function findContactMade($searchParams)
{
$contactInfo = null;
Expand All @@ -436,14 +444,14 @@ public function findContactMade($searchParams)
while (!empty($contacts['next']) || $first == true) {
$first = false;
//Get the contacts made
$contacts = $this->client->fetchData('contacts', $searchParams);
$contacts = $this->fetchData('contacts', $searchParams, 'GET');
if (!empty($contacts['results'])) {
foreach ($contacts['results'] as $contactResult) {
//By default, this result is the match
//If we find that one of the fields is not a match, then we'll continue to the next result
$exactMatch = true;
foreach ($searchParams as $searchParamField => $searchParamValue) {
if (!isset($contactResult[$searchParamField]) || $contactResult[$searchParamField] != $searchParamValue) {
if (!array_key_exists($searchParamField, $contactResult) || $contactResult[$searchParamField] != $searchParamValue) {
//One of the search params does not match
//Continue to the next result
$exactMatch = false;
Expand All @@ -458,9 +466,6 @@ public function findContactMade($searchParams)
}
}
}
if (!empty($contacts['next'])) {
$next = $contacts['next'];
}
}
return null;
}
Expand Down Expand Up @@ -931,9 +936,14 @@ public function formatPhoneForStorage($inputphone)
*
* @author prstoddart
*/
public function formatPhoneForNationBuilder($inputphone)
public function formatPhoneForNationBuilder($phone, $us = true)
{
$phone = preg_replace("/[^0-9]/", "", $inputphone);
if ($us) {
//If phone was prefixed with +1, remove it
$phone = str_replace('+1', '', $phone);
//Remove any remaining non-numbers
$phone = preg_replace("/[^0-9]/", "", $phone);
}

return $phone;
}
Expand Down

0 comments on commit c31e84a

Please sign in to comment.