$newEmployer = !empty($params['employer_id']) ? $params['employer_id'] : $params['current_employer'] ?? NULL;
$newContact = empty($params['contact_id']);
- if ($newEmployer) {
+ if (!CRM_Utils_System::isNull($newEmployer)) {
CRM_Contact_BAO_Contact_Utils::createCurrentEmployerRelationship($contact->id, $newEmployer, $employerId, $newContact);
}
elseif ($employerId) {
+--------------------------------------------------------------------+
*/
+use Civi\Api4\Contact;
+
/**
*
* @package CRM
* Contact id of the individual.
* @param $organization
* (id or name).
- * @param int $previousEmployerID
+ * @param null $previousEmployerID
* @param bool $newContact
*
+ * @throws \API_Exception
* @throws \CRM_Core_Exception
* @throws \CiviCRM_API3_Exception
*/
}
if (!is_numeric($organization)) {
$dupeIDs = CRM_Contact_BAO_Contact::getDuplicateContacts(['organization_name' => $organization], 'Organization', 'Unsupervised', [], FALSE);
-
- if (is_array($dupeIDs) && !empty($dupeIDs)) {
- // we should create relationship only w/ first org CRM-4193
- foreach ($dupeIDs as $orgId) {
- $organization = $orgId;
- break;
- }
- }
- else {
- //create new organization
- $newOrg = [
+ $organization = reset($dupeIDs) ?: Contact::create(FALSE)
+ ->setValues([
'contact_type' => 'Organization',
'organization_name' => $organization,
- ];
- $org = CRM_Contact_BAO_Contact::create($newOrg);
- $organization = $org->id;
- }
+ ])->execute()->first()['id'];
}
if (is_numeric($organization)) {