mirror of
https://github.com/nerzhul/ocsms.git
synced 2025-06-07 16:06:15 +00:00
pushPhoneNumberToCache. This permit to fix problems with phone numbers with dashes and parenthesis
This commit is contained in:
parent
cc8d5ac50a
commit
66859a4940
@ -134,19 +134,73 @@ class OcSmsApp extends App {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private function pushPhoneNumberToCache($rawPhone, $contactName) {
|
private function pushPhoneNumberToCache($rawPhone, $contactName) {
|
||||||
|
// We try to add many combinaisons
|
||||||
$phoneNb = preg_replace("#[ ]#", "/", $rawPhone);
|
$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[$phoneNb] = $contactName;
|
||||||
self::$contacts[$phoneNbNoSpaces] = $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])) {
|
if (!isset(self::$contactsInverted[$contactName])) {
|
||||||
self::$contactsInverted[$contactName] = array();
|
self::$contactsInverted[$contactName] = array();
|
||||||
}
|
}
|
||||||
|
|
||||||
array_push(self::$contactsInverted[$contactName], $phoneNb);
|
array_push(self::$contactsInverted[$contactName], $phoneNb);
|
||||||
|
|
||||||
if ($phoneNb != $phoneNbNoSpaces) {
|
if (!in_array($phoneNbNoSpaces, self::$contactsInverted[$contactName])) {
|
||||||
array_push(self::$contactsInverted[$contactName], $phoneNbNoSpaces);
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,7 +127,7 @@ class SmsController extends Controller {
|
|||||||
$msgCount = 0;
|
$msgCount = 0;
|
||||||
|
|
||||||
// This table will be used to avoid duplicates
|
// This table will be used to avoid duplicates
|
||||||
$noSpacesPhones = array();
|
$cleanedPhones = array();
|
||||||
|
|
||||||
// Contact resolved
|
// Contact resolved
|
||||||
if ($contactName != "" && isset($iContacts[$contactName])) {
|
if ($contactName != "" && isset($iContacts[$contactName])) {
|
||||||
@ -143,10 +143,10 @@ class SmsController extends Controller {
|
|||||||
|
|
||||||
$msgCount += $this->smsMapper->countMessagesForPhoneNumber($this->userId, $fmtPN);
|
$msgCount += $this->smsMapper->countMessagesForPhoneNumber($this->userId, $fmtPN);
|
||||||
|
|
||||||
$fmtPNNoSpaces = preg_replace("#[ ]#","", $fmtPN);
|
$fmtPNCleaned = preg_replace("#[ ]|-|\(|\)]#","", $fmtPN);
|
||||||
if (!in_array($fmtPNNoSpaces, $noSpacesPhones)) {
|
if (!in_array($fmtPNCleaned, $cleanedPhones)) {
|
||||||
$phoneNumbers[] = $fmtPN;
|
$phoneNumbers[] = $fmtPN;
|
||||||
$noSpacesPhones[] = $fmtPNNoSpaces;
|
$cleanedPhones[] = $fmtPNCleaned;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -157,10 +157,10 @@ class SmsController extends Controller {
|
|||||||
$messages = $this->smsMapper->getAllMessagesForPhoneNumber($this->userId, $fmtPN, $lastDate);
|
$messages = $this->smsMapper->getAllMessagesForPhoneNumber($this->userId, $fmtPN, $lastDate);
|
||||||
$msgCount = $this->smsMapper->countMessagesForPhoneNumber($this->userId, $fmtPN);
|
$msgCount = $this->smsMapper->countMessagesForPhoneNumber($this->userId, $fmtPN);
|
||||||
|
|
||||||
$fmtPNNoSpaces = preg_replace("#[ ]#","", $fmtPN);
|
$fmtPNCleaned = preg_replace("#[ ]|-|\(|\)]#","", $fmtPN);
|
||||||
if (!in_array($fmtPNNoSpaces, $noSpacesPhones)) {
|
if (!in_array($fmtPNCleaned, $cleanedPhones)) {
|
||||||
$phoneNumbers[] = $fmtPN;
|
$phoneNumbers[] = $fmtPN;
|
||||||
$noSpacesPhones[] = $fmtPNNoSpaces;
|
$cleanedPhones[] = $fmtPNCleaned;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user