/** * Create relationship type. * * @param array $params * Array per getfields metadata. * * @return array */ function civicrm_api3_relationship_type_create($params) { if (!isset($params['label_a_b'])) { $params['label_a_b'] = $params['name_a_b']; } if (!isset($params['label_b_a'])) { $params['label_b_a'] = $params['name_b_a']; } $ids = array(); if (isset($params['id']) && !CRM_Utils_Rule::integer($params['id'])) { return civicrm_api3_create_error('Invalid value for relationship type ID'); } else { $ids['relationshipType'] = CRM_Utils_Array::value('id', $params); } $relationType = CRM_Contact_BAO_RelationshipType::add($params, $ids); $relType = array(); _civicrm_api3_object_to_array($relationType, $relType[$relationType->id]); return civicrm_api3_create_success($relType, $params, 'RelationshipType', 'create', $relationType); }
/** * Function to create relationship type * * @param array $params Associative array of property name/value pairs to insert in new relationship type. * * @return Newly created Relationship_type object * * @access public * */ function crm_create_relationship_type($params) { if (!isset($params['name_a_b']) and !isset($params['name_b_a']) and !isset($params['contact_type_a']) and !isset($params['contact_type_b'])) { return _crm_error('Return array is not properly set'); } require_once 'CRM/Contact/BAO/RelationshipType.php'; $relationType = CRM_Contact_BAO_RelationshipType::add($params, $ids); return $relationType; }
/** * Function to process the form * * @access public * @return None */ public function postProcess() { if ($this->_action & CRM_Core_Action::DELETE) { CRM_Contact_BAO_RelationshipType::del($this->_id); CRM_Core_Session::setStatus(ts('Selected Relationship type has been deleted.')); } else { $params = array(); $ids = array(); // store the submitted values in an array $params = $this->exportValues(); $params['is_active'] = CRM_Utils_Array::value('is_active', $params, false); if ($this->_action & CRM_Core_Action::UPDATE) { $ids['relationshipType'] = $this->_id; } $cTypeA = CRM_Utils_System::explode(CRM_Core_DAO::VALUE_SEPARATOR, $params['contact_types_a'], 2); $cTypeB = CRM_Utils_System::explode(CRM_Core_DAO::VALUE_SEPARATOR, $params['contact_types_b'], 2); $params['contact_type_a'] = $cTypeA[0]; $params['contact_type_b'] = $cTypeB[0]; $params['contact_sub_type_a'] = $cTypeA[1] ? $cTypeA[1] : 'NULL'; $params['contact_sub_type_b'] = $cTypeB[1] ? $cTypeB[1] : 'NULL'; CRM_Contact_BAO_RelationshipType::add($params, $ids); CRM_Core_Session::setStatus(ts('The Relationship Type has been saved.')); } }
/** * Function to create relationship type * * @param array $params Associative array of property name/value pairs to insert in new relationship type. * * @return Newly created Relationship_type object * * @access public * */ function civicrm_relationship_type_add($params) { if (empty($params)) { return civicrm_create_error(ts('No input parameters present')); } if (!is_array($params)) { return civicrm_create_error(ts('Parameter is not an array')); } if (!isset($params['contact_types_a']) && !isset($params['contact_types_b']) && !isset($params['name_a_b']) && !isset($params['name_b_a'])) { return civicrm_create_error(ts('Missing some required parameters (contact_types_a contact_types_b name_a_b name b_a)')); } if (!isset($params['label_a_b'])) { $params['label_a_b'] = $params['name_a_b']; } if (!isset($params['label_b_a'])) { $params['label_b_a'] = $params['name_b_a']; } require_once 'CRM/Utils/Rule.php'; $ids = array(); if (isset($params['id']) && !CRM_Utils_Rule::integer($params['id'])) { return civicrm_create_error('Invalid value for relationship type ID'); } else { $ids['relationshipType'] = CRM_Utils_Array::value('id', $params); } require_once 'CRM/Contact/BAO/RelationshipType.php'; $relationType = CRM_Contact_BAO_RelationshipType::add($params, $ids); $relType = array(); _civicrm_object_to_array($relationType, $relType); return $relType; }
public function testRelCreateWithinDiffTypeStudentSponsor() { //check for Student to Sponcer $relTypeParams = array('name_a_b' => 'StudentToSponsor', 'name_b_a' => 'SponsorToStudent', 'contact_type_a' => 'Individual', 'contact_sub_type_a' => $this->student, 'contact_type_b' => 'Organization', 'contact_sub_type_b' => $this->sponsor); $relTypeIds = array(); $relType = CRM_Contact_BAO_RelationshipType::add($relTypeParams, $relTypeIds); $params = array('relationship_type_id' => $relType->id . '_a_b', 'is_active' => 1, 'contact_check' => array($this->organization_sponsor => 1)); $ids = array('contact' => $this->indivi_student); list($valid, $invalid, $duplicate, $saved, $relationshipIds) = CRM_Contact_BAO_Relationship::legacyCreateMultiple($params, $ids); $this->assertEquals($valid, 1); $this->assertEquals(empty($relationshipIds), FALSE); $this->relationshipTypeDelete($relType->id); }
/** * Function to process the form * * @access public * @return None */ function postProcess() { if ($this->_action & CRM_CORE_ACTION_DELETE) { CRM_Contact_BAO_RelationshipType::del($this->_id); CRM_Core_Session::setStatus(ts('Selected Relationship type has been deleted.')); } else { $params = array(); $ids = array(); // store the submitted values in an array $params = $this->exportValues(); $params['is_active'] = CRM_Utils_Array::value('is_active', $params, false); if ($this->_action & CRM_CORE_ACTION_UPDATE) { $ids['relationshipType'] = $this->_id; } CRM_Contact_BAO_RelationshipType::add($params, $ids); CRM_Core_Session::setStatus(ts('The Relationship Type has been saved.')); } }