1
0
mirror of https://github.com/owncloudarchive/contacts.git synced 2024-12-11 22:24:32 +01:00

return 'PHOTO' attribute on AddressbookProvider::search

This commit is contained in:
Thomas Müller 2014-07-22 12:42:59 +02:00 committed by Jan-Christoph Borchardt
parent f4e00e72e4
commit b8ad6889ed
2 changed files with 24 additions and 58 deletions

View File

@ -22,6 +22,8 @@
namespace OCA\Contacts;
use OC_L10N;
use OCA\Contacts\Backend\AbstractBackend;
use OCP\AppFramework\Http;
/**
@ -148,7 +150,7 @@ class Addressbook extends AbstractPIMCollection {
/**
* @brief Activate an address book
* @param bool active
* @param bool $active
* @return void
*/
public function setActive($active) {
@ -411,7 +413,7 @@ class Addressbook extends AbstractPIMCollection {
if (!$this->hasPermission(\OCP\PERMISSION_UPDATE)) {
throw new \Exception(
self::$l10n->t('Access denied'),
STATUS_FORBIDDEN
Http::STATUS_FORBIDDEN
);
}
@ -447,7 +449,7 @@ class Addressbook extends AbstractPIMCollection {
*/
public function delete() {
if (!$this->hasPermission(\OCP\PERMISSION_DELETE)) {
throw new Exception(
throw new \Exception(
self::$l10n->t('You don\'t have permissions to delete the address book.'),
Http::STATUS_FORBIDDEN
);

View File

@ -21,7 +21,10 @@
*/
namespace OCA\Contacts;
use OCA\Contacts\Utils\JSONSerializer;
use OCA\Contacts\Utils\Properties;
use OCA\Contacts\Utils\TemporaryPhoto;
use OCA\Contacts\VObject\VCard;
/**
* This class manages our addressbooks.
@ -79,47 +82,6 @@ class AddressbookProvider implements \OCP\IAddressBook {
return $this->addressBook->getPermissions();
}
private function getProperty(&$results, $row) {
if(!$row['name'] || !$row['value']) {
return false;
}
$value = null;
switch($row['name']) {
case 'PHOTO':
$value = 'VALUE=uri:' . \OCP\Util::linkToAbsolute('contacts', 'photo.php') . '?id=' . $row['contactid'];
break;
case 'N':
case 'ORG':
case 'ADR':
case 'GEO':
case 'CATEGORIES':
$property = \Sabre\VObject\Property::create($row['name'], $row['value']);
$value = $property->getParts();
break;
default:
$value = $value = strtr($row['value'], array('\,' => ',', '\;' => ';'));
break;
}
if(in_array($row['name'], Properties::$multiProperties)) {
if(!isset($results[$row['contactid']])) {
$results[$row['contactid']] = array('id' => $row['contactid'], $row['name'] => array($value));
} elseif(!isset($results[$row['contactid']][$row['name']])) {
$results[$row['contactid']][$row['name']] = array($value);
} else {
$results[$row['contactid']][$row['name']][] = $value;
}
} else {
if(!isset($results[$row['contactid']])) {
$results[$row['contactid']] = array('id' => $row['contactid'], $row['name'] => $value);
} elseif(!isset($results[$row['contactid']][$row['name']])) {
$results[$row['contactid']][$row['name']] = $value;
}
}
}
/**
* @param $pattern
* @param $searchProperties
@ -151,19 +113,21 @@ class AddressbookProvider implements \OCP\IAddressBook {
}
if(count($ids) > 0) {
$query = 'SELECT `' . self::CONTACT_TABLE . '`.`addressbookid`, `' . self::PROPERTY_TABLE . '`.`contactid`, `'
. self::PROPERTY_TABLE . '`.`name`, `' . self::PROPERTY_TABLE . '`.`value` FROM `'
. self::PROPERTY_TABLE . '`,`' . self::CONTACT_TABLE . '` WHERE `'
. self::CONTACT_TABLE . '`.`addressbookid` = \'' . $this->addressBook->getId() . '\' AND `'
. self::PROPERTY_TABLE . '`.`contactid` = `' . self::CONTACT_TABLE . '`.`id` AND `'
. self::PROPERTY_TABLE . '`.`contactid` IN (' . join(',', array_fill(0, count($ids), '?')) . ')';
//\OCP\Util::writeLog('contacts', __METHOD__ . 'DB query: ' . $query, \OCP\Util::DEBUG);
$stmt = \OCP\DB::prepare($query);
$result = $stmt->execute($ids);
foreach($ids as $id){
$contact = $this->addressBook->getChild($id);
$j = JSONSerializer::serializeContact($contact);
if (isset($contact->PHOTO)) {
$url =\OCP\Util::linkToRoute('contacts_contact_photo',
array(
'backend' => $contact->getBackend()->name,
'addressBookId' => $this->addressBook->getId(),
'contactId' => $contact->getId()
));
$url = \OC_Helper::makeURLAbsolute($url);
$j['data']['PHOTO'] = "VALUE=uri:$url";
}
$results[]= $j['data'];
}
while( $row = $result->fetchRow()) {
$this->getProperty($results, $row);
}
return $results;