$newEmployer = !empty($params['employer_id']) ? $params['employer_id'] : CRM_Utils_Array::value('current_employer', $params);
// create current employer
if ($newEmployer) {
- CRM_Contact_BAO_Contact_Utils::createCurrentEmployerRelationship($contact->id, $newEmployer, $employerId);
+ $newContact = FALSE;
+ if (empty($params['contact_id'])) {
+ $newContact = TRUE;
+ }
+ CRM_Contact_BAO_Contact_Utils::createCurrentEmployerRelationship($contact->id, $newEmployer, $employerId, $newContact);
}
else {
//unset if employer id exits
* @access public
* @static
*/
- static function createCurrentEmployerRelationship($contactID, $organizationId, $previousEmployerID = NULL) {
+ static function createCurrentEmployerRelationship($contactID, $organizationId, $previousEmployerID = NULL, $newContact = FALSE) {
if ($organizationId && is_numeric($organizationId)) {
$cid = array('contact' => $contactID);
) = 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 &&