)
) {
// create current employer
- if (isset($params['employer_id'])) {
- CRM_Contact_BAO_Contact_Utils::createCurrentEmployerRelationship($contact->id,
- $params['employer_id'], $employerId
- );
+ $newEmployer = !empty($params['employer_id']) ? $params['employer_id'] : CRM_Utils_Array::value('current_employer', $params);
+
+ $newContact = FALSE;
+ if (empty($params['contact_id'])) {
+ $newContact = TRUE;
}
- elseif ($params['current_employer']) {
- CRM_Contact_BAO_Contact_Utils::createCurrentEmployerRelationship($contact->id,
- $params['current_employer']
- );
+ if ($newEmployer) {
+ CRM_Contact_BAO_Contact_Utils::createCurrentEmployerRelationship($contact->id, $newEmployer, $employerId, $newContact);
}
else {
//unset if employer id exits
* @access public
* @static
*/
- static function createCurrentEmployerRelationship($contactID, $organization, $previousEmployerID = NULL) {
+ static function createCurrentEmployerRelationship($contactID, $organization, $previousEmployerID = NULL, $newContact = FALSE) {
$organizationId = NULL;
// if organization id is passed.
) = CRM_Contact_BAO_Relationship::create($relationshipParams, $cid);
- // In case we change employer, clean prveovious employer related records.
- if (!$previousEmployerID) {
+ // In case we change employer, clean previous employer related records.
+ if (!$previousEmployerID && !$newContact) {
$previousEmployerID = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $contactID, 'employer_id');
}
if ($previousEmployerID &&
}
}
}
-