mirror of
https://github.com/owncloudarchive/contacts.git
synced 2024-12-04 15:24:35 +01:00
return 'PHOTO' attribute on AddressbookProvider::search
This commit is contained in:
parent
f4e00e72e4
commit
b8ad6889ed
@ -22,6 +22,8 @@
|
|||||||
|
|
||||||
namespace OCA\Contacts;
|
namespace OCA\Contacts;
|
||||||
|
|
||||||
|
use OC_L10N;
|
||||||
|
use OCA\Contacts\Backend\AbstractBackend;
|
||||||
use OCP\AppFramework\Http;
|
use OCP\AppFramework\Http;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -148,7 +150,7 @@ class Addressbook extends AbstractPIMCollection {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Activate an address book
|
* @brief Activate an address book
|
||||||
* @param bool active
|
* @param bool $active
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setActive($active) {
|
public function setActive($active) {
|
||||||
@ -411,7 +413,7 @@ class Addressbook extends AbstractPIMCollection {
|
|||||||
if (!$this->hasPermission(\OCP\PERMISSION_UPDATE)) {
|
if (!$this->hasPermission(\OCP\PERMISSION_UPDATE)) {
|
||||||
throw new \Exception(
|
throw new \Exception(
|
||||||
self::$l10n->t('Access denied'),
|
self::$l10n->t('Access denied'),
|
||||||
STATUS_FORBIDDEN
|
Http::STATUS_FORBIDDEN
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -447,7 +449,7 @@ class Addressbook extends AbstractPIMCollection {
|
|||||||
*/
|
*/
|
||||||
public function delete() {
|
public function delete() {
|
||||||
if (!$this->hasPermission(\OCP\PERMISSION_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.'),
|
self::$l10n->t('You don\'t have permissions to delete the address book.'),
|
||||||
Http::STATUS_FORBIDDEN
|
Http::STATUS_FORBIDDEN
|
||||||
);
|
);
|
||||||
|
@ -21,7 +21,10 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
namespace OCA\Contacts;
|
namespace OCA\Contacts;
|
||||||
|
use OCA\Contacts\Utils\JSONSerializer;
|
||||||
use OCA\Contacts\Utils\Properties;
|
use OCA\Contacts\Utils\Properties;
|
||||||
|
use OCA\Contacts\Utils\TemporaryPhoto;
|
||||||
|
use OCA\Contacts\VObject\VCard;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class manages our addressbooks.
|
* This class manages our addressbooks.
|
||||||
@ -79,47 +82,6 @@ class AddressbookProvider implements \OCP\IAddressBook {
|
|||||||
return $this->addressBook->getPermissions();
|
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 $pattern
|
||||||
* @param $searchProperties
|
* @param $searchProperties
|
||||||
@ -151,19 +113,21 @@ class AddressbookProvider implements \OCP\IAddressBook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(count($ids) > 0) {
|
if(count($ids) > 0) {
|
||||||
$query = 'SELECT `' . self::CONTACT_TABLE . '`.`addressbookid`, `' . self::PROPERTY_TABLE . '`.`contactid`, `'
|
foreach($ids as $id){
|
||||||
. self::PROPERTY_TABLE . '`.`name`, `' . self::PROPERTY_TABLE . '`.`value` FROM `'
|
$contact = $this->addressBook->getChild($id);
|
||||||
. self::PROPERTY_TABLE . '`,`' . self::CONTACT_TABLE . '` WHERE `'
|
$j = JSONSerializer::serializeContact($contact);
|
||||||
. self::CONTACT_TABLE . '`.`addressbookid` = \'' . $this->addressBook->getId() . '\' AND `'
|
if (isset($contact->PHOTO)) {
|
||||||
. self::PROPERTY_TABLE . '`.`contactid` = `' . self::CONTACT_TABLE . '`.`id` AND `'
|
$url =\OCP\Util::linkToRoute('contacts_contact_photo',
|
||||||
. self::PROPERTY_TABLE . '`.`contactid` IN (' . join(',', array_fill(0, count($ids), '?')) . ')';
|
array(
|
||||||
|
'backend' => $contact->getBackend()->name,
|
||||||
//\OCP\Util::writeLog('contacts', __METHOD__ . 'DB query: ' . $query, \OCP\Util::DEBUG);
|
'addressBookId' => $this->addressBook->getId(),
|
||||||
$stmt = \OCP\DB::prepare($query);
|
'contactId' => $contact->getId()
|
||||||
$result = $stmt->execute($ids);
|
));
|
||||||
}
|
$url = \OC_Helper::makeURLAbsolute($url);
|
||||||
while( $row = $result->fetchRow()) {
|
$j['data']['PHOTO'] = "VALUE=uri:$url";
|
||||||
$this->getProperty($results, $row);
|
}
|
||||||
|
$results[]= $j['data'];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $results;
|
return $results;
|
||||||
|
Loading…
Reference in New Issue
Block a user