/** * 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; }
/** * Parses a vcard from the output of getCardBpdy (or from an iteration * over getCardBodies) and returns the resulting VCard instance. * This method is exposed primarily for diagnostic and testing purpose to * help identify problems in failed vcards. *Do not depend on its API.* * Use importCards() and importFromFile() instead. * @param type $components * @return \EVought\vCardTools\VCard * @throws Exceptions\UndefinedPropertyException * @see importCards() * @see importFromFile() */ public function parseCardBody($components) { $vcard = new VCard(); if ('2.1' === $components['version']) { $unfoldedData = self::unfold21($components['body']); } else { $unfoldedData = self::unfold4($components['body']); } $lines = \explode("\n", $unfoldedData); foreach ($lines as $line) { // FIXME: Make sure that TYPE, ENCODING, CHARSET are dealt // with by PropertyBuilder $vcardLine = VCardLine::fromLineText($line, $components['version']); if (null === $vcardLine) { continue; } $specification = VCard::getSpecification($vcardLine->getName(), false); if ($specification->allowsCommaProperties()) { // Deal with the possibility of multiple values $origValue = $vcardLine->getValue(); $values = \str_getcsv($origValue); foreach ($values as $value) { $vcardLine->setValue($value); $specification->getBuilder()->setFromVCardLine($vcardLine)->pushTo($vcard); } } else { $specification->getBuilder()->setFromVCardLine($vcardLine)->pushTo($vcard); } } $vcard->checkSetUID(); return $vcard; }