Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Output in vCard (RFC6350) matching form #38

Open
blacksenator opened this issue Dec 6, 2019 · 2 comments · May be fixed by #40
Open

Output in vCard (RFC6350) matching form #38

blacksenator opened this issue Dec 6, 2019 · 2 comments · May be fixed by #40

Comments

@blacksenator
Copy link

blacksenator commented Dec 6, 2019

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,
        ];
    }
@wyrfel
Copy link
Contributor

wyrfel commented Dec 12, 2019

@blacksenator Thanks for sharing this use case. An interesting way to use the package.

Is there anything this solution doesn't cover for you?
We would like to keep the name-parser package focussed on just the core functionality as possible use cases are plentiful and the package could easily loose focus if we try to incorporate too many of them. However, if there is an aspect about this that the parser doesn't cater for, i'd be happy to look at that.

It might also be nice to permanently make these solutions and use cases available - i could add the github wiki functionality if you feel that might be a good way?

@blacksenator
Copy link
Author

blacksenator commented Dec 12, 2019

@wyrfel - Thank you Andre for your answer.
First of all, I would like to say that your program is clever, so sophisticated, that I am - with my PHP knowledge - be still lost in the code of my fork.
In my opinion, there are actually a few things missing - at least for German standards. Whether the repository loses its focus - I can not say.

But step by step:
In my view, the main thing that is missing is an examination of whether it is a person or a company.
In my opinion, the examination can be made relatively trivial:

  • if the string does not contain a comma (count ($segments) <= 1 in Parser.php line 77 et seqq.)
  • check against language-dependent character strings (e.g., "Ltd.", "Inc.")
  • if true no further mappings are necessary
  • return the whole string in the new "Company" field

Now to the German peculiarities:
When checking personal names, it would be very useful if the following two name components were identified individually:

  1. Title - this primarily means German doctoral degrees. They are not officially part of the name - although many believe it - and are therefore typically used as part of the name. These academic titles can occur several times:
    Example:
    [Salutation] [Title] [Title] [Firstname] [Prefix] [Lastname]
    [Lastname], [Title] [Title] [Firstname] [Prefix]

  2. What is not taken into account are nobility predicates. This predicates have been carried out since 1918 (abolition of the nobility) as a name extension (it´s not optional it´s part of the name!). An aristocratic predicate occurs only once in the name, and if so, then usually followed by a prefix ("baron" "of")
    Example (very simple cases):
    [Salutation] [Title] [Firstname] [Extension] [Prefix] [Lastname]
    [Lastname], [Title] [Firstname] [Extension] [Prefix]
    The good thing is that there is an official source with a list of "allowed" extensions: the German health system.

As I said, the code is programmed so abstractly that I have not yet been able to implement a proper PR. My knowledge is limited, so I just expanded the basics with the lists of parts of the name and copied classes accordingly.

If you are interesseted in this wrought material I will push an PR on your request.

blacksenator added a commit to blacksenator/name-parser that referenced this issue Dec 15, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants