* Deletes an entire addressbook and all its contents
*
* @param int $addressBookId
* @return void
*/
functiondeleteAddressBook($addressBookId){
$stmt=$this->pdo->prepare('DELETE FROM '.$this->cardsTableName.' WHERE addressbookid = ?');
$stmt->execute([$addressBookId]);
$stmt=$this->pdo->prepare('DELETE FROM '.$this->addressBooksTableName.' WHERE id = ?');
$stmt->execute([$addressBookId]);
$stmt=$this->pdo->prepare('DELETE FROM '.$this->addressBookChangesTableName.' WHERE id = ?');
$stmt->execute([$addressBookId]);
}
/**
* Returns all cards for a specific addressbook id.
*
* This method should return the following properties for each card:
* * carddata - raw vcard data
* * uri - Some unique url
* * lastmodified - A unix timestamp
*
* It's recommended to also return the following properties:
* * etag - A unique etag. This must change every time the card changes.
* * size - The size of the card in bytes.
*
* If these last two properties are provided, less time will be spent
* calculating them. If they are specified, you can also ommit carddata.
* This may speed up certain requests, especially with large cards.
*
* @param mixed $addressbookId
* @return array
*/
functiongetCards($addressbookId){
$stmt=$this->pdo->prepare('SELECT id, uri, lastmodified, etag, size FROM '.$this->cardsTableName.' WHERE addressbookid = ?');
$stmt->execute([$addressbookId]);
$result=[];
while($row=$stmt->fetch(\PDO::FETCH_ASSOC)){
$row['etag']='"'.$row['etag'].'"';
$result[]=$row;
}
return$result;
}
/**
* Returns a specfic card.
*
* The same set of properties must be returned as with getCards. The only
* exception is that 'carddata' is absolutely required.
*
* If the card does not exist, you must return false.
*
* @param mixed $addressBookId
* @param string $cardUri
* @return array
*/
functiongetCard($addressBookId,$cardUri){
$stmt=$this->pdo->prepare('SELECT id, carddata, uri, lastmodified, etag, size FROM '.$this->cardsTableName.' WHERE addressbookid = ? AND uri = ? LIMIT 1');
$stmt->execute([$addressBookId,$cardUri]);
$result=$stmt->fetch(\PDO::FETCH_ASSOC);
if(!$result)returnfalse;
$result['etag']='"'.$result['etag'].'"';
return$result;
}
/**
* Returns a list of cards.
*
* This method should work identical to getCard, but instead return all the
* cards in the list as an array.
*
* If the backend supports this, it may allow for some speed-ups.
$stmt=$this->pdo->prepare('SELECT synctoken FROM '.$this->addressBooksTableName.' WHERE id = ?');
$stmt->execute([$addressBookId]);
$currentToken=$stmt->fetchColumn(0);
if(is_null($currentToken))returnnull;
$result=[
'syncToken'=>$currentToken,
'added'=>[],
'modified'=>[],
'deleted'=>[],
];
if($syncToken){
$query="SELECT uri, operation FROM ".$this->addressBookChangesTableName." WHERE synctoken >= ? AND synctoken < ? AND addressbookid = ? ORDER BY synctoken";
$stmt=$this->pdo->prepare('INSERT INTO '.$this->addressBookChangesTableName.' (uri, synctoken, addressbookid, operation) SELECT ?, synctoken, ?, ? FROM '.$this->addressBooksTableName.' WHERE id = ?');
$stmt->execute([
$objectUri,
$addressBookId,
$operation,
$addressBookId
]);
$stmt=$this->pdo->prepare('UPDATE '.$this->addressBooksTableName.' SET synctoken = synctoken + 1 WHERE id = ?');