-
Notifications
You must be signed in to change notification settings - Fork 36
Open
Description
According to this question I really would appreciate to get a feature solving my needs.
My idea is, that the return of "vCard-function" returns an array with key is vCard property name and value is name (part).
Steps:
- Try to figure out whether it´s a company or a person.
From my point of view only a language related list of key words (user extendable) can solve this.
If this matches, than return 'FN' and 'ORG' containing the name string as befor. - If the name string is obviously not a company name, then try to splitt it into its components
- Rearrange components and return them as 'FN', 'N' or maybe 'NICKNAME'.
Here is my attempt from last night (draft):
/**
* get an array of name properties with vCard property as key
*
* @param string $realname
* @return array
*/
public function getNameProperties(string $realName)
{
$nameParts = explode(',', $realName); // "lastname, firstname"
if (count($nameParts) == 2) { // it`s a person
$nameParts = $this->parser->parse($realName);
$salutation = $nameParts->getSalutation();
$firstName = $nameParts->getFirstname();
$lastName = $nameParts->getLastname();
$middleName = $nameParts->getMiddlename();
$nickName = $nameParts->getNickname();
$initials = $nameParts->getInitials();
$suffix = $nameParts->getSuffix();
if (!empty($middleName) && empty($initials)) {
$additionalName = $middleName;
} elseif (empty($middleName) && !empty($initials)) {
$additionalName = $initials;
} elseif (empty($middleName) && empty($initials)) {
$additionalName = '';
} else {
$additionalName = implode(',', [$middleName, $initials]);
}
$names = implode(';', [$lastName, $firstName, $additionalName, $salutation, $suffix]);
$fullName = implode(' ', [$salutation, $firstName, $additionalName, $lastName]);
if (!empty($suffix)) {
$fullName = $fullName .', '. $suffix;
}
$fullName = preg_replace('/\s+/', ' ', $fullName);
$company = '';
} else { // it`s a company
$names = '';
$nickName = '';
$fullName = $realName;
$company = $realName;
}
return [
'N' => $names,
'FN' => $fullName,
'NICKNAME' => $nickName,
'ORG' => $company,
];
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels