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

Added experimental merging for contacts with multiple numbers

This commit is contained in:
Loic Blot
2014-10-09 18:27:13 +02:00
parent 667118310d
commit 1138512dc8
4 changed files with 80 additions and 25 deletions
+48 -22
View File
@@ -27,6 +27,8 @@ class OcSmsApp extends App {
*/
private static $contacts;
private static $contactsInverted;
private $c;
public function __construct (array $urlParams=array()) {
@@ -75,33 +77,57 @@ class OcSmsApp extends App {
});
}
/**
* Partially importe this function from owncloud Chat app
* https://github.com/owncloud/chat/blob/master/app/chat.php
*/
public function getContacts() {
// Only load contacts if they aren't in the buffer
if(count(self::$contacts) == 0) {
self::$contacts = array();
$cm = $this->c['ContactsManager'];
$result = $cm->search('',array('FN'));
foreach ($result as $r) {
if (isset ($r["TEL"])) {
$phoneIds = $r["TEL"];
if (is_array($phoneIds)) {
$countPhone = count($phoneIds);
for ($i=0; $i<$countPhone; $i++) {
$phoneNb = preg_replace("#[ ]#", "", $phoneIds[$i]);
self::$contacts[$phoneNb] = $r["FN"];
}
}
else {
self::$contacts[$phoneIds] = $r["FN"];
}
}
}
$this->loadContacts();
}
return self::$contacts;
}
public function getInvertedContacts() {
// Only load contacts if they aren't in the buffer
if(count(self::$contactsInverted) == 0) {
$this->loadContacts();
}
return self::$contactsInverted;
}
/**
* Partially importe this function from owncloud Chat app
* https://github.com/owncloud/chat/blob/master/app/chat.php
*/
private function loadContacts() {
self::$contacts = array();
self::$contactsInverted = array();
$cm = $this->c['ContactsManager'];
$result = $cm->search('',array('FN'));
foreach ($result as $r) {
if (isset ($r["TEL"])) {
$phoneIds = $r["TEL"];
if (is_array($phoneIds)) {
$countPhone = count($phoneIds);
for ($i=0; $i < $countPhone; $i++) {
$phoneNb = preg_replace("#[ ]#", "", $phoneIds[$i]);
self::$contacts[$phoneNb] = $r["FN"];
if (!isset(self::$contactsInverted[$r["FN"]])) {
self::$contactsInverted[$r["FN"]] = array();
}
array_push(self::$contactsInverted[$r["FN"]], $phoneNb);
}
}
else {
self::$contacts[$phoneIds] = $r["FN"];
if (!isset(self::$contactsInverted[$r["FN"]])) {
self::$contactsInverted[$r["FN"]] = array();
}
array_push(self::$contactsInverted[$r["FN"]], $phoneIds);
}
}
}
}
}