1
0
mirror of https://github.com/nerzhul/ocsms.git synced 2025-06-07 07:56:23 +00:00

pushPhoneNumberToCache. This permit to fix problems with phone numbers with dashes and parenthesis

This commit is contained in:
Loic Blot 2014-11-05 11:08:59 +00:00
parent cc8d5ac50a
commit 66859a4940
2 changed files with 63 additions and 9 deletions

View File

@ -134,19 +134,73 @@ class OcSmsApp extends App {
}
private function pushPhoneNumberToCache($rawPhone, $contactName) {
// We try to add many combinaisons
$phoneNb = preg_replace("#[ ]#", "/", $rawPhone);
$phoneNbNoSpaces = preg_replace("#[ ]#", "", $rawPhone);
/*
* At this point, spaces are slashes.
*/
// Spaces removed
$phoneNbNoSpaces = preg_replace("#[/]#", "", $phoneNb);
// Parenthesis removed
$phoneNbNoParenthesis = preg_replace("#[(]|[)]#", "", $phoneNb);
// Dashes removed
$phoneNbNoDashes = preg_replace("#[-]#", "", $phoneNb);
// Spaces and parenthesis
$phoneNbNoSpacesParenthesis = preg_replace("#[/]|[(]|[)]#", "", $phoneNb);
// Spaces and dashes
$phoneNbNoSpacesDashes = preg_replace("#[/]|[-]#", "", $phoneNb);
// parenthesis and dashes
$phoneNbNoDashesParenthesis = preg_replace("#[-]|[(]|[)]#", "", $phoneNb);
// Nothing
$phoneNbNothing = preg_replace("#[/]|[(]|[)]|[-]#", "", $phoneNb);
// Contacts
self::$contacts[$phoneNb] = $contactName;
self::$contacts[$phoneNbNoSpaces] = $contactName;
self::$contacts[$phoneNbNoParenthesis] = $contactName;
self::$contacts[$phoneNbNoDashes] = $contactName;
self::$contacts[$phoneNbNoSpacesParenthesis] = $contactName;
self::$contacts[$phoneNbNoSpacesDashes] = $contactName;
self::$contacts[$phoneNbNoDashesParenthesis] = $contactName;
self::$contacts[$phoneNbNothing] = $contactName;
// Inverted contacts
if (!isset(self::$contactsInverted[$contactName])) {
self::$contactsInverted[$contactName] = array();
}
array_push(self::$contactsInverted[$contactName], $phoneNb);
if ($phoneNb != $phoneNbNoSpaces) {
if (!in_array($phoneNbNoSpaces, self::$contactsInverted[$contactName])) {
array_push(self::$contactsInverted[$contactName], $phoneNbNoSpaces);
}
if (!in_array($phoneNbNoParenthesis, self::$contactsInverted[$contactName])) {
array_push(self::$contactsInverted[$contactName], $phoneNbNoParenthesis);
}
if (!in_array($phoneNbNoDashes, self::$contactsInverted[$contactName])) {
array_push(self::$contactsInverted[$contactName], $phoneNbNoDashes);
}
if (!in_array($phoneNbNoSpacesParenthesis, self::$contactsInverted[$contactName])) {
array_push(self::$contactsInverted[$contactName], $phoneNbNoSpacesParenthesis);
}
if (!in_array($phoneNbNoSpacesDashes, self::$contactsInverted[$contactName])) {
array_push(self::$contactsInverted[$contactName], $phoneNbNoSpacesDashes);
}
if (!in_array($phoneNbNoDashesParenthesis, self::$contactsInverted[$contactName])) {
array_push(self::$contactsInverted[$contactName], $phoneNbNoDashesParenthesis);
}
if (!in_array($phoneNbNothing, self::$contactsInverted[$contactName])) {
array_push(self::$contactsInverted[$contactName], $phoneNbNothing);
}
}
}

View File

@ -127,7 +127,7 @@ class SmsController extends Controller {
$msgCount = 0;
// This table will be used to avoid duplicates
$noSpacesPhones = array();
$cleanedPhones = array();
// Contact resolved
if ($contactName != "" && isset($iContacts[$contactName])) {
@ -143,10 +143,10 @@ class SmsController extends Controller {
$msgCount += $this->smsMapper->countMessagesForPhoneNumber($this->userId, $fmtPN);
$fmtPNNoSpaces = preg_replace("#[ ]#","", $fmtPN);
if (!in_array($fmtPNNoSpaces, $noSpacesPhones)) {
$fmtPNCleaned = preg_replace("#[ ]|-|\(|\)]#","", $fmtPN);
if (!in_array($fmtPNCleaned, $cleanedPhones)) {
$phoneNumbers[] = $fmtPN;
$noSpacesPhones[] = $fmtPNNoSpaces;
$cleanedPhones[] = $fmtPNCleaned;
}
}
}
@ -157,10 +157,10 @@ class SmsController extends Controller {
$messages = $this->smsMapper->getAllMessagesForPhoneNumber($this->userId, $fmtPN, $lastDate);
$msgCount = $this->smsMapper->countMessagesForPhoneNumber($this->userId, $fmtPN);
$fmtPNNoSpaces = preg_replace("#[ ]#","", $fmtPN);
if (!in_array($fmtPNNoSpaces, $noSpacesPhones)) {
$fmtPNCleaned = preg_replace("#[ ]|-|\(|\)]#","", $fmtPN);
if (!in_array($fmtPNCleaned, $cleanedPhones)) {
$phoneNumbers[] = $fmtPN;
$noSpacesPhones[] = $fmtPNNoSpaces;
$cleanedPhones[] = $fmtPNCleaned;
}
}