/**
* 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,
];
}
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:
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.
Here is my attempt from last night (draft):