4 * The Card object represents a single Card from an addressbook
8 * @copyright Copyright (C) 2007-2012 Rooftop Solutions. All rights reserved.
9 * @author Evert Pot (http://www.rooftopsolutions.nl/)
10 * @license http://code.google.com/p/sabredav/wiki/License Modified BSD License
12 class Sabre_CardDAV_Card extends Sabre_DAV_File implements Sabre_CardDAV_ICard, Sabre_DAVACL_IACL {
17 * @var Sabre_CardDAV_Backend_Abstract
19 private $carddavBackend;
22 * Array with information about this Card
29 * Array with information about the containing addressbook
33 private $addressBookInfo;
38 * @param Sabre_CardDAV_Backend_Abstract $carddavBackend
39 * @param array $addressBookInfo
40 * @param array $cardData
42 public function __construct(Sabre_CardDAV_Backend_Abstract $carddavBackend,array $addressBookInfo,array $cardData) {
44 $this->carddavBackend = $carddavBackend;
45 $this->addressBookInfo = $addressBookInfo;
46 $this->cardData = $cardData;
51 * Returns the uri for this object
55 public function getName() {
57 return $this->cardData['uri'];
62 * Returns the VCard-formatted object
66 public function get() {
68 // Pre-populating 'carddata' is optional. If we don't yet have it
69 // already, we fetch it from the backend.
70 if (!isset($this->cardData['carddata'])) {
71 $this->cardData = $this->carddavBackend->getCard($this->addressBookInfo['id'], $this->cardData['uri']);
73 return $this->cardData['carddata'];
78 * Updates the VCard-formatted object
80 * @param string $cardData
83 public function put($cardData) {
85 if (is_resource($cardData))
86 $cardData = stream_get_contents($cardData);
88 // Converting to UTF-8, if needed
89 $cardData = Sabre_DAV_StringUtil::ensureUTF8($cardData);
91 $etag = $this->carddavBackend->updateCard($this->addressBookInfo['id'],$this->cardData['uri'],$cardData);
92 $this->cardData['carddata'] = $cardData;
93 $this->cardData['etag'] = $etag;
104 public function delete() {
106 $this->carddavBackend->deleteCard($this->addressBookInfo['id'],$this->cardData['uri']);
111 * Returns the mime content-type
115 public function getContentType() {
117 return 'text/x-vcard; charset=utf-8';
122 * Returns an ETag for this object
126 public function getETag() {
128 if (isset($this->cardData['etag'])) {
129 return $this->cardData['etag'];
131 return '"' . md5($this->get()) . '"';
137 * Returns the last modification date as a unix timestamp
141 public function getLastModified() {
143 return isset($this->cardData['lastmodified'])?$this->cardData['lastmodified']:null;
148 * Returns the size of this object in bytes
152 public function getSize() {
154 if (array_key_exists('size', $this->cardData)) {
155 return $this->cardData['size'];
157 return strlen($this->get());
163 * Returns the owner principal
165 * This must be a url to a principal, or null if there's no owner
167 * @return string|null
169 public function getOwner() {
171 return $this->addressBookInfo['principaluri'];
176 * Returns a group principal
178 * This must be a url to a principal, or null if there's no owner
180 * @return string|null
182 public function getGroup() {
189 * Returns a list of ACE's for this node.
191 * Each ACE has the following properties:
192 * * 'privilege', a string such as {DAV:}read or {DAV:}write. These are
193 * currently the only supported privileges
194 * * 'principal', a url to the principal who owns the node
195 * * 'protected' (optional), indicating that this ACE is not allowed to
200 public function getACL() {
204 'privilege' => '{DAV:}read',
205 'principal' => $this->addressBookInfo['principaluri'],
209 'privilege' => '{DAV:}write',
210 'principal' => $this->addressBookInfo['principaluri'],
220 * This method will receive a list of new ACE's.
225 public function setACL(array $acl) {
227 throw new Sabre_DAV_Exception_MethodNotAllowed('Changing ACL is not yet supported');
232 * Returns the list of supported privileges for this node.
234 * The returned data structure is a list of nested privileges.
235 * See Sabre_DAVACL_Plugin::getDefaultSupportedPrivilegeSet for a simple
236 * standard structure.
238 * If null is returned from this method, the default privilege set is used,
239 * which is fine for most common usecases.
243 public function getSupportedPrivilegeSet() {