match Contacts

This commit is contained in:
Marc Michalsky forumZFD 2020-11-02 17:49:39 +01:00
parent 937a35e1b8
commit 346091307d
Signed by untrusted user who does not match committer: marc.koch
GPG key ID: 12406554CFB028B9
2 changed files with 48 additions and 0 deletions

View file

@ -290,6 +290,51 @@ class TwingleEvent extends Campaign {
]; ];
} }
/**
* Matches a single string that should contain first and lastname to match a
* contact or create a new one if it does not exist yet.
*
* TODO: The logic of this method should instead be handled in the XCM
* extension. This ist only a temporary solution.
*
* @param string $names
* @param string $email
*
* @return int|null
* Returns a contact id
*/
private function matchContact(string $names, string $email) {
$names = explode(' ', $names);
$lastname = '';
if (is_array($names) && count($names) > 1) {
$lastname = array_pop($names);
$test = $names[count($names) - 1];
$nameSuffixes = ['de', 'da', 'von', 'van'];
if (in_array($test, $nameSuffixes)) {
array_pop($names);
$lastname = $test . ' ' . $lastname;
}
$names = implode(" ", $names);
}
try {
$contact = civicrm_api3('Contact', 'getorcreate', [
'xcm_profile' => 'default',
'first_name' => $names,
'last_name' => $lastname,
'email' => $email,
]);
return (int) $contact['id'];
} catch (CiviCRM_API3_Exception $e) {
$message = $e->getMessage();
\Civi::log()->error("TwingleCampaign extension could not match or create a contact for:
$names $lastname $email./nError Message: $message");
return NULL;
}
}
/** /**
* Return a timestamp of the last update of the Campaign * Return a timestamp of the last update of the Campaign
* *

View file

@ -21,6 +21,9 @@
<ver>5.0</ver> <ver>5.0</ver>
</compatibility> </compatibility>
<comments>This is a new, undeveloped module</comments> <comments>This is a new, undeveloped module</comments>
<requires>
<ext>de.systopia.xcm</ext>
</requires>
<classloader> <classloader>
<psr4 prefix="Civi\" path="Civi"/> <psr4 prefix="Civi\" path="Civi"/>
</classloader> </classloader>