1
0
mirror of https://github.com/owncloudarchive/contacts.git synced 2025-01-18 07:52:21 +01:00

Add search() function

This commit is contained in:
LEDfan 2014-04-03 18:36:11 +02:00
parent 4cf45fa91f
commit e70814997f
3 changed files with 93 additions and 1 deletions

View File

@ -68,3 +68,4 @@ if (\OCP\User::isLoggedIn()) {
}
}
}

View File

@ -26,7 +26,8 @@ use OCA\Contacts\Contact,
OCA\Contacts\VObject\VCard,
OCA\Contacts\Utils\Properties,
Sabre\VObject\Reader,
OCA\Contacts\Addressbook;
OCA\Contacts\Addressbook,
OCA\Contacts\LocalUsersAddressbookProvider;
/**
* Contact backend for storing all the ownCloud users in this installation.
@ -297,4 +298,8 @@ class LocalUsers extends AbstractBackend {
return false;
}
}
public function getSearchProvider(){
return new LocalUsersAddressbookProvider();
}
}

View File

@ -0,0 +1,86 @@
<?php
namespace OCA\Contacts;
class LocalUsersAddressbookProvider implements \OCP\IAddressBook {
public function __construct(){
}
/**
* @param $pattern
* @param $searchProperties
* @param $options
* @return array|false
*/
public function search($pattern, $searchProperties, $options) {
if(in_array("FN", $searchProperties) && in_array("id", $searchProperties)){
echo "beide";
$query = 'SELECT DISTINCT * FROM `*PREFIX*contacts_ocu_cards` WHERE addressbookid = ? AND (`id` LIKE ? OR `fullname` LIKE ?) ';
$stmt = \OCP\DB::prepare($query);
$result = $stmt->execute(array(\OCP\User::getUser(), '%' . $pattern . "%", '%' . $pattern . "%"));
} elseif(in_array("FN", $searchProperties)){
echo "fn";
$query = 'SELECT * FROM `*PREFIX*contacts_ocu_cards` WHERE addressbookid = ? AND `fullname` LIKE ? ';
$stmt = \OCP\DB::prepare($query);
$result = $stmt->execute(array(\OCP\User::getUser(), '%' . $pattern . "%"));
} elseif(in_array("id", $searchProperties)){
echo "id";
$query = 'SELECT * FROM `*PREFIX*contacts_ocu_cards` WHERE addressbookid = ? AND `id` LIKE ? ';
$stmt = \OCP\DB::prepare($query);
$result = $stmt->execute(array(\OCP\User::getUser(), '%' . $pattern . "%"));
} else {
echo "else";
$query = 'SELECT * FROM `*PREFIX*contacts_ocu_cards` WHERE addressbookid = ?';
$stmt = \OCP\DB::prepare($query);
$result = $stmt->execute(array(\OCP\User::getUser()));
}
if (\OCP\DB::isError($result)) {
\OCP\Util::writeLog('contacts', __METHOD__ . 'DB error: ' . \OC_DB::getErrorMessage($result),
\OCP\Util::ERROR);
return false;
}
$contacts = array();
while( $row = $result->fetchRow()) {
$contacts[] = $row['id'];
}
return $contacts;
}
public function getKey(){
}
/**
* In comparison to getKey() this function returns a human readable (maybe translated) name
* @return mixed
*/
public function getDisplayName(){
}
public function createOrUpdate($properties){
}
/**
* @return mixed
*/
public function getPermissions(){
}
/**
* @param object $id the unique identifier to a contact
* @return bool successful or not
*/
public function delete($id){
}
}