Makes code more flexible/forgiving if new contact types are added in the future,
or if existing contact types are disabled.
$this->_contactType = CRM_Utils_Request::retrieve('ct', 'String',
$this, TRUE, NULL, 'REQUEST'
);
- if (!in_array($this->_contactType,
- ['Individual', 'Household', 'Organization']
- )
+ if (!in_array($this->_contactType, CRM_Contact_BAO_ContactType::basicTypes(TRUE), TRUE)
) {
CRM_Core_Error::statusBounce(ts('Could not get a contact id and/or contact type'));
}
if ($this->_onDuplicate != CRM_Import_Parser::DUPLICATE_NOCHECK) {
//Mark Dedupe Rule Fields as required, since it's used in matching contact
- foreach (['Individual', 'Household', 'Organization'] as $cType) {
+ foreach (CRM_Contact_BAO_ContactType::basicTypes() as $cType) {
$ruleParams = [
'contact_type' => $cType,
'used' => 'Unsupervised',
}
// get array of subtypes - CRM-18708
- if (in_array($csType, ['Individual', 'Organization', 'Household'])) {
+ if (in_array($csType, CRM_Contact_BAO_ContactType::basicTypes(TRUE), TRUE)) {
$csType = self::getSubtypes($params['contact_type']);
}
$requiredCheck = FALSE;
}
if ($requiredCheck) {
- if (isset($params['id'])) {
- $required = ['Individual', 'Household', 'Organization'];
- }
$required = [
'Individual' => [
['first_name', 'last_name'],
$value = NULL;
foreach ($customDataType as $dataType) {
if (array_key_exists($dataType, CRM_Core_SelectValues::customGroupExtends())) {
- if (in_array($dataType, ['Individual', 'Household', 'Organization'])) {
+ if (in_array($dataType, CRM_Contact_BAO_ContactType::basicTypes(TRUE), TRUE)) {
$val = "'" . CRM_Utils_Type::escape($dataType, 'String') . "', 'Contact' ";
}
else {
*/
public function getEntity() {
$entity = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomGroup', $this->custom_group_id, 'extends');
- return in_array($entity, ['Individual', 'Household', 'Organization']) ? 'Contact' : $entity;
+ return in_array($entity, CRM_Contact_BAO_ContactType::basicTypes(TRUE), TRUE) ? 'Contact' : $entity;
}
/**
return $fields;
}
- $types = ['Individual', 'Organization', 'Household'];
+ $types = CRM_Contact_BAO_ContactType::basicTypes(TRUE);
foreach ($params['mapper'] as $key => $value) {
$contactType = NULL;
foreach ($value as $k => $v) {
- if (in_array($v[0], $types)) {
+ if (in_array($v[0], $types, TRUE)) {
if ($contactType && $contactType != $v[0]) {
throw new CRM_Core_Exception(ts("Cannot have two clauses with different types: %1, %2",
[1 => $contactType, 2 => $v[0]]
}
}
- $contactTypes = ['Individual', 'Household', 'Organization'];
+ $contactTypes = CRM_Contact_BAO_ContactType::basicTypes(TRUE);
$subTypes = CRM_Contact_BAO_ContactType::subTypes();
$profileTypeComponent = array_intersect($components, $profileTypes);
public static function checkForMixProfiles($profileIds) {
$mixProfile = FALSE;
- $contactTypes = ['Individual', 'Household', 'Organization'];
- $subTypes = CRM_Contact_BAO_ContactType::subTypes();
+ $contactTypes = CRM_Contact_BAO_ContactType::basicTypes(TRUE);
$components = ['Contribution', 'Participant', 'Membership', 'Activity'];
if ($profileType == 'Contact') {
continue;
}
- if (in_array($profileType, $contactTypes)) {
+ if (in_array($profileType, $contactTypes, TRUE)) {
if (!isset($typeCount['ctype'][$profileType])) {
$typeCount['ctype'][$profileType] = 1;
}
break;
}
}
- elseif (in_array($profileType, $components)) {
+ elseif (in_array($profileType, $components, TRUE)) {
$mixProfile = TRUE;
break;
}
if (!$entity) {
// This means we have stored a custom field rather than an entity name in rule_table, figure out the entity.
$entity = civicrm_api3('CustomGroup', 'getvalue', ['table_name' => $this->rule_table, 'return' => 'extends']);
- if (in_array($entity, ['Individual', 'Household', 'Organization'])) {
+ if (in_array($entity, CRM_Contact_BAO_ContactType::basicTypes(TRUE), TRUE)) {
$entity = 'Contact';
}
$fieldName = 'custom_' . civicrm_api3('CustomField', 'getvalue', ['column_name' => $fieldName, 'return' => 'id']);
'civicrm_website',
];
- foreach (['Individual', 'Organization', 'Household'] as $ctype) {
+ foreach (CRM_Contact_BAO_ContactType::basicTypes() as $ctype) {
// take the table.field pairs and their titles from importableFields() if the table is supported
foreach (CRM_Contact_BAO_Contact::importableFields($ctype) as $iField) {
if (isset($iField['where'])) {
*/
protected function getContactColumns($options = []) {
$defaultOptions = [
- 'custom_fields' => ['Individual', 'Contact', 'Organization'],
+ 'custom_fields' => CRM_Contact_BAO_ContactType::basicTypes(),
'fields_defaults' => ['display_name', 'id'],
'order_bys_defaults' => ['sort_name ASC'],
'contact_type' => NULL,
}
elseif (
CRM_Utils_Array::value(1, $fields['field_name']) == 'contact_sub_type' &&
- !in_array($profileType, ['Individual', 'Household', 'Organization']) &&
- !in_array($profileType, CRM_Contact_BAO_ContactType::subTypes())
+ !in_array($profileType, CRM_Contact_BAO_ContactType::basicTypes(TRUE), TRUE) &&
+ !in_array($profileType, CRM_Contact_BAO_ContactType::subTypes(), TRUE)
) {
$errors['field_name'] = ts('Cannot add or update profile field Contact Subtype as profile type is not one of Individual, Household or Organization.');
}
}
// Adding the oddball "formatting" field here because there's no other place to put it
- foreach (['Individual', 'Organization', 'Household'] as $type) {
+ foreach (CRM_Contact_BAO_ContactType::basicTypes() as $type) {
if (isset($civiSchema[$type . 'Model'])) {
$civiSchema[$type . 'Model']['schema'] += [
'formatting' => [
}
$types = explode(CRM_Core_DAO::VALUE_SEPARATOR, substr($object->$name, 1, -1));
$values = [];
- if (in_array($object->extends, ['Individual', 'Organization', 'Household'])) {
+ if (in_array($object->extends, CRM_Contact_BAO_ContactType::basicTypes(TRUE), TRUE)) {
$key = 'contact_type';
$values = $types;
}
$valueIDs[] = $relTypeId;
}
}
- elseif (in_array($customGroup->extends, ['Individual', 'Organization', 'Household'])) {
+ elseif (in_array($customGroup->extends, CRM_Contact_BAO_ContactType::basicTypes(TRUE), TRUE)) {
$valueIDs = $optionValues;
}
elseif (in_array($customGroup->extends, ['Contribution', 'ContributionRecur'])) {
$values['custom'] = [];
$checkCheckBoxField = FALSE;
$entity = $extends;
- if (in_array($extends, ['Household', 'Individual', 'Organization'])) {
+ if (in_array($extends, CRM_Contact_BAO_ContactType::basicTypes(TRUE), TRUE)) {
$entity = 'Contact';
}
'select' => ['name', 'label', 'input_type', 'input_attrs', 'required', 'options', 'help_pre', 'help_post', 'serialize', 'data_type', 'fk_entity', 'readonly'],
'where' => [['input_type', 'IS NOT NULL']],
];
- if (in_array($entityName, ['Individual', 'Household', 'Organization'])) {
+ if (in_array($entityName, \CRM_Contact_BAO_ContactType::basicTypes(TRUE), TRUE)) {
$params['values']['contact_type'] = $entityName;
$entityName = 'Contact';
}
$scanBlocks($info['definition']['layout']);
}
- if (array_intersect($entities, ['Individual', 'Household', 'Organization'])) {
+ if (array_intersect($entities, \CRM_Contact_BAO_ContactType::basicTypes(TRUE))) {
$entities[] = 'Contact';
}
// Optimization - since contact fields are a combination of these three,
// we'll combine them client-side rather than sending them via ajax.
- elseif (array_intersect($entities, ['Individual', 'Household', 'Organization'])) {
+ elseif (array_intersect($entities, \CRM_Contact_BAO_ContactType::basicTypes(TRUE))) {
$entities = array_diff($entities, ['Contact']);
}