1
0
mirror of https://github.com/owncloudarchive/contacts.git synced 2024-12-10 21:24:33 +01:00
OwncloudContactsOfficial/lib/localusersaddressbookprovider.php

87 lines
2.3 KiB
PHP
Raw Normal View History

2014-04-03 18:36:11 +02:00
<?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){
}
}