Skip to content

Output in vCard (RFC6350) matching form #38

@blacksenator

Description

@blacksenator

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:

  1. 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.
  2. If the name string is obviously not a company name, then try to splitt it into its components
  3. 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,
        ];
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions