1
0
mirror of https://github.com/nextcloud/ocsms.git synced 2026-08-21 21:32:59 +00:00

new file: appinfo/formatphonenumber.php

modified:   appinfo/ocsmsapp.php
	modified:   controller/smscontroller.php
	modified:   db/smsmapper.php

A lot of changes in Code dealing with phonenumbers
This commit is contained in:
stagprom
2014-11-24 15:54:10 +01:00
parent 3cd85810eb
commit 4519f0088d
4 changed files with 141 additions and 123 deletions
+8 -66
View File
@@ -9,6 +9,7 @@
* @copyright Loic Blot 2014
*/
namespace OCA\OcSms\AppInfo;
@@ -19,15 +20,16 @@ use \OCA\OcSms\Controller\SmsController;
use \OCA\OcSms\Db\Sms;
use \OCA\OcSms\Db\SmsMapper;
use \OCA\OcSms\AppInfo\FormatPhoneNumber;
class OcSmsApp extends App {
/**
* @var array used to cache the parsed contacts for every request
*/
private static $contacts;
private static $contacts; // dosn´t work
private static $contactsInverted;
private static $contactsInverted; // dosn´t work
private $c;
@@ -80,19 +82,19 @@ class OcSmsApp extends App {
public function getContacts() {
// Only load contacts if they aren't in the buffer
// dosn´t work
if(count(self::$contacts) == 0) {
$this->loadContacts();
}
return self::$contacts;
}
public function getInvertedContacts() {
// Only load contacts if they aren't in the buffer
// dosn´t work
if(count(self::$contactsInverted) == 0) {
$this->loadContacts();
}
return self::$contactsInverted;
}
@@ -134,73 +136,13 @@ class OcSmsApp extends App {
}
private function pushPhoneNumberToCache($rawPhone, $contactName) {
// We try to add many combinaisons
$phoneNb = 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
$phoneNb = FormatPhoneNumber::formatPhoneNumber($rawPhone);
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])) {
if (!isset(self::$contactsInverted[$contactName]))
self::$contactsInverted[$contactName] = array();
}
array_push(self::$contactsInverted[$contactName], $phoneNb);
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);
}
}
}