);
}
- if ($contact->contact_type == 'Individual' &&
- (isset($params['current_employer']) ||
- isset($params['employer_id'])
- )
- ) {
+ if ($contact->contact_type == 'Individual' && (isset($params['current_employer']) || isset($params['employer_id']))) {
+ $newEmployer = !empty($params['employer_id']) ? $params['employer_id'] : CRM_Utils_Array::value('current_employer', $params);
// create current employer
- if (isset($params['employer_id'])) {
- CRM_Contact_BAO_Contact_Utils::createCurrentEmployerRelationship($contact->id,
- $params['employer_id'], $employerId
- );
- }
- 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);
}
else {
//unset if employer id exits
* @access public
* @static
*/
- static function createCurrentEmployerRelationship($contactID, $organization, $previousEmployerID = NULL) {
- $organizationId = NULL;
-
- // if organization id is passed.
- if (is_numeric($organization)) {
- $organizationId = $organization;
- }
- else {
- $orgName = explode('::', $organization);
- trim($orgName[0]);
-
- $organizationParams = array();
- $organizationParams['organization_name'] = $orgName[0];
-
- $dedupeParams = CRM_Dedupe_Finder::formatParams($organizationParams, 'Organization');
-
- $dedupeParams['check_permission'] = FALSE;
- $dupeIDs = CRM_Dedupe_Finder::dupesByParams($dedupeParams, 'Organization', 'Supervised');
-
- if (is_array($dupeIDs) && !empty($dupeIDs)) {
- // we should create relationship only w/ first org CRM-4193
- foreach ($dupeIDs as $orgId) {
- $organizationId = $orgId;
- break;
- }
- }
- else {
- //create new organization
- $newOrg = array(
- 'contact_type' => 'Organization',
- 'organization_name' => trim($orgName[0]),
- );
- $org = CRM_Contact_BAO_Contact::create($newOrg);
- $organizationId = $org->id;
- }
- }
-
- if ($organizationId) {
+ static function createCurrentEmployerRelationship($contactID, $organizationId, $previousEmployerID = NULL) {
+ if ($organizationId && is_numeric($organizationId)) {
$cid = array('contact' => $contactID);
// get the relationship type id of "Employee of"
}
}
else {
- $currentEmployer = CRM_Contact_BAO_Relationship::getCurrentEmployer(array($this->_contactId));
- $defaults['current_employer_id'] = CRM_Utils_Array::value('org_id', $currentEmployer[$this->_contactId]);
-
foreach ($defaults['email'] as $dontCare => & $val) {
if (isset($val['signature_text'])) {
$val['signature_text_hidden'] = $val['signature_text'];
$defaults['contact_sub_type'] = $this->_oldSubtypes;
}
}
- $this->assign('currentEmployer', CRM_Utils_Array::value('current_employer_id', $defaults));
-
// set defaults for blocks ( custom data, address, communication preference, notes, tags and groups )
foreach ($this->_editOptions as $name => $label) {
if (!in_array($name, array('Address', 'Notes'))) {
* @access public
*/
public function setDefaultValues() {
- $defaults = parent::setDefaultValues();
-
- if ($this->_contactType == 'Individual') {
- // set current employer details
- $currentEmployer = CRM_Contact_BAO_Relationship::getCurrentEmployer(array($this->_contactId));
- $defaults['current_employer_id'] = CRM_Utils_Array::value('org_id', $currentEmployer[$this->_contactId]);
-
- $this->assign('currentEmployer', CRM_Utils_Array::value('current_employer_id', $defaults));
- }
-
- return $defaults;
+ return parent::setDefaultValues();
}
/**