/** * process the form after the input has been submitted and validated * * @access public * * @return None */ public function postProcess() { // store the submitted values in an array $params = $this->controller->exportValues($this->_name); $this->set('searchDone', 0); if (CRM_Utils_Array::value('_qf_AddToOrganization_refresh', $_POST)) { $searchParams['contact_type'] = array('Organization' => 'Organization'); $searchParams['rel_contact'] = $params['name']; CRM_Contact_Form_Task_AddToHousehold::search($this, $searchParams); $this->set('searchDone', 1); return; } $data = array(); $data['relationship_type_id'] = $params['relationship_type_id']; $data['is_active'] = 1; $invalid = 0; $valid = 0; $duplicate = 0; if (is_array($this->_contactIds)) { foreach ($this->_contactIds as $value) { $ids = array(); $ids['contact'] = $value; $errors = CRM_Contact_BAO_Relationship::checkValidRelationship($params, $ids, $params['contact_check']); if ($errors) { $invalid++; continue; } if (CRM_Contact_BAO_Relationship::checkDuplicateRelationship($params, CRM_Utils_Array::value('contact', $ids), $params['contact_check'])) { $duplicate++; continue; } CRM_Contact_BAO_Relationship::add($data, $ids, $params['contact_check']); $valid++; } $org = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $params['contact_check'], 'display_name'); list($rtype, $a_b) = explode('_', $data['relationship_type_id'], 2); $relationship = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', $rtype, "label_{$a_b}"); $status = array(ts('%count %2 %3 relationship created', array('count' => $valid, 'plural' => '%count %2 %3 relationships created', 2 => $relationship, 3 => $org))); if ($duplicate) { $status[] = ts('%count was skipped because the contact is already %2 %3', array('count' => $duplicate, 'plural' => '%count were skipped because the contacts are already %2 %3', 2 => $relationship, 3 => $org)); } if ($invalid) { $status[] = ts('%count relationship was not created because the contact is not of the right type for this relationship', array('count' => $invalid, 'plural' => '%count relationships were not created because the contact is not of the right type for this relationship')); } $status = '<ul><li>' . implode('</li><li>', $status) . '</li></ul>'; CRM_Core_Session::setStatus($status, ts('Relationship Created', array('count' => $valid, 'plural' => 'Relationships Created')), 'success', array('expires' => 0)); } }
/** * process the form after the input has been submitted and validated * * @access public * * @return None */ public function postProcess() { // store the submitted values in an array $params = $this->controller->exportValues($this->_name); $this->set('searchDone', 0); if (CRM_Utils_Array::value('_qf_AddToOrganization_refresh', $_POST)) { $searchParams['contact_type'] = array('Organization' => 'Organization'); $searchParams['rel_contact'] = $params['name']; CRM_Contact_Form_Task_AddToHousehold::search($this, $searchParams); $this->set('searchDone', 1); return; } $data = array(); //$params['relationship_type_id']='4_a_b'; $data['relationship_type_id'] = $params['relationship_type_id']; $data['is_active'] = 1; $invalid = 0; $valid = 0; $duplicate = 0; if (is_array($this->_contactIds)) { foreach ($this->_contactIds as $value) { $ids = array(); $ids['contact'] = $value; //contact b --> organization // contact a -> individual $errors = CRM_Contact_BAO_Relationship::checkValidRelationship($params, $ids, $params['contact_check']); if ($errors) { $invalid = $invalid + 1; continue; } if (CRM_Contact_BAO_Relationship::checkDuplicateRelationship($params, CRM_Utils_Array::value('contact', $ids), $params['contact_check'])) { $duplicate++; continue; } CRM_Contact_BAO_Relationship::add($data, $ids, $params['contact_check']); $valid++; } $status = array(ts('Added Contact(s) to Organization'), ts('Total Selected Contact(s): %1', array(1 => $valid + $invalid + $duplicate))); if ($valid) { $status[] = ts('New relationship record(s) created: %1.', array(1 => $valid)) . '<br/>'; } if ($invalid) { $status[] = ts('Relationship record(s) not created due to invalid target contact type: %1.', array(1 => $invalid)) . '<br/>'; } if ($duplicate) { $status[] = ts('Relationship record(s) not created - duplicate of existing relationship: %1.', array(1 => $duplicate)) . '<br/>'; } CRM_Core_Session::setStatus($status); } }