示例#1
0
 /**
  * @brief Data structure of vCard
  * @param VObject\VCard $contact
  * @return associative array|null
  */
 public static function serializeContact(Contact $contact)
 {
     if (!$contact->retrieve()) {
         \OCP\Util::writeLog('contacts', __METHOD__ . ' error reading: ' . print_r($contact, true), \OCP\Util::DEBUG);
         return null;
     }
     $details = array();
     if (isset($contact->PHOTO) || isset($contact->LOGO)) {
         $details['photo'] = true;
         $details['thumbnail'] = Properties::cacheThumbnail($contact->getBackend()->name, $contact->getParent()->getId(), $contact->getId(), null, $contact);
     }
     foreach ($contact->children as $property) {
         $pname = $property->name;
         $temp = self::serializeProperty($property);
         if (!is_null($temp)) {
             // Get Apple X-ABLabels
             if (isset($contact->{$property->group . '.X-ABLABEL'})) {
                 $temp['label'] = $contact->{$property->group . '.X-ABLABEL'}->value;
                 if ($temp['label'] == '_$!<Other>!$_') {
                     $temp['label'] = Properties::$l10n->t('Other');
                 }
                 if ($temp['label'] == '_$!<HomePage>!$_') {
                     $temp['label'] = Properties::$l10n->t('HomePage');
                 }
             }
             if (array_key_exists($pname, $details)) {
                 $details[$pname][] = $temp;
             } else {
                 $details[$pname] = array($temp);
             }
         }
     }
     return array('data' => $details, 'metadata' => $contact->getMetaData());
 }
示例#2
0
 public function testSetByName()
 {
     $this->assertTrue(!isset($this->contact->NICKNAME));
     $this->assertTrue($this->contact->setPropertyByName('NICKNAME', 'Maxie'));
     $this->assertTrue(isset($this->contact->NICKNAME));
     $this->assertEquals((string) $this->contact->NICKNAME, 'Maxie');
 }
 /**
  * Add a contact to the address book
  * This takes an array or a VCard|Contact and return
  * the ID or false.
  *
  * @param array|VObject\VCard $data
  * @return int|bool
  * @throws \Exception on missing permissions
  */
 public function addChild($data = null)
 {
     if (!$this->hasPermission(\OCP\PERMISSION_CREATE)) {
         throw new \Exception(self::$l10n->t('You do not have permissions add contacts to the address book'), Http::STATUS_FORBIDDEN);
     }
     if (!$this->getBackend()->hasContactMethodFor(\OCP\PERMISSION_CREATE)) {
         throw new \Exception(self::$l10n->t('The backend for this address book does not support adding contacts'), Http::STATUS_NOT_IMPLEMENTED);
     }
     $contact = new Contact($this, $this->backend, $data);
     if (is_null($data)) {
         // A new Contact, don't try to load from backend
         $contact->setRetrieved(true);
     }
     if ($contact->save() === false) {
         return false;
     }
     $id = $contact->getId();
     // If this method is called directly the index isn't set.
     if (!isset($this->objects[$id])) {
         $this->objects[$id] = $contact;
     }
     /* If count() hasn't been called yet don't _count hasn't been initialized
      * so incrementing it would give a misleading value.
      */
     if (isset($this->_count)) {
         $this->_count += 1;
     }
     //\OCP\Util::writeLog('contacts', __METHOD__.' id: ' . $id, \OCP\Util::DEBUG);
     return $id;
 }
示例#4
0
 /**
  * Do what's needed to get the image from storage
  * depending on the type.
  */
 protected function processImage()
 {
     $this->image = $this->contact->getPhoto();
 }