Cover the case where an event creator passes only one name part

This commit is contained in:
Marc Michalsky 2024-07-18 15:37:30 +02:00
parent 91c70c645a
commit 7415fac88d
Signed by untrusted user who does not match committer: marc.koch
GPG key ID: 12406554CFB028B9
2 changed files with 6 additions and 4 deletions

View file

@ -219,13 +219,15 @@ class CRM_TwingleCampaign_BAO_TwingleEvent extends Campaign {
private private
static function matchContact(string $names, string $email): ?int { static function matchContact(string $names, string $email): ?int {
$names = StringOps::split_names($names); // Hopefully just a temporary solution $names = StringOps::split_names($names); // Hopefully just a temporary solution
$firstnames = $names['firstnames']; $firstnames = $names['firstnames'] ?? NULL;
$lastname = $names['lastname']; $lastname = $names['lastname'] ?? NULL;
$display_name = $names['display_name'] ?? NULL;
try { try {
$contact = civicrm_api3('Contact', 'getorcreate', [ $contact = civicrm_api3('Contact', 'getorcreate', [
'xcm_profile' => Civi::settings()->get('twinglecampaign_xcm_profile'), 'xcm_profile' => Civi::settings()->get('twinglecampaign_xcm_profile'),
'first_name' => $firstnames, 'first_name' => $firstnames,
'last_name' => $lastname, 'last_name' => $lastname,
'display_name' => $display_name,
'email' => $email, 'email' => $email,
]); ]);
return (int) $contact['id']; return (int) $contact['id'];

View file

@ -49,7 +49,7 @@ class CRM_TwingleCampaign_Utils_StringOperations {
$firstnames = implode(" ", $names); $firstnames = implode(" ", $names);
return ['firstnames' => $firstnames, 'lastname' => $lastname]; return ['firstnames' => $firstnames, 'lastname' => $lastname];
} }
return $string; return ['display_name' => $string];
} }
/** /**
@ -71,4 +71,4 @@ class CRM_TwingleCampaign_Utils_StringOperations {
public static function startsWith($haystack, $needle): bool { public static function startsWith($haystack, $needle): bool {
return substr_compare($haystack, $needle, 0, strlen($needle)) === 0; return substr_compare($haystack, $needle, 0, strlen($needle)) === 0;
} }
} }