/** * Saves the vcard contact data to the database, returns the id of the * new connection record (resuses existing uid if provided). * Stores JUST the info from the CONTACT table itself, no sub-tables. * @param VCard $vcard The record to store. * @return string The new uid. */ private function storeJustContact(VCard $vcard) { assert(!empty($this->connection)); $vcard->setFNAppropriately(); $uid = $vcard->checkSetUID(); $stmt = $this->prepareCannedQuery('store', 'contact'); $stmt->bindValue(':uid', $uid); foreach (['kind', 'rev'] as $simpleProperty) { assert($vcard->getSpecification($simpleProperty)->requiresSingleProperty(), $simpleProperty . ' must be a single value element'); $stmt->bindValue(':' . $simpleProperty, empty($vcard->{$simpleProperty}) ? null : $vcard->{$simpleProperty}->getValue(), \PDO::PARAM_STR); } // HACK: #104, #105, #106 VCard and the spec think these are multiple. // Database doesn't. Arbitrarily take the first value. foreach (['fn', 'bday', 'anniversary'] as $hackMultiple) { assert(!$vcard->getSpecification($hackMultiple)->requiresSingleProperty(), $simpleProperty . ' must NOT be a single value element'); $hackMultipleValue = $vcard->{$hackMultiple}; if (empty($hackMultipleValue)) { $stmt->bindValue(':' . $hackMultiple, null, \PDO::PARAM_NULL); } else { $stmt->bindValue(':' . $hackMultiple, $hackMultipleValue[0]->getValue()); } } $stmt->execute(); return $uid; }