Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[REF] BAO_Contact - Remove CRM_Utils_Array::value and other unnecessary code #16874

Merged
merged 1 commit into from
Mar 24, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 14 additions & 22 deletions CRM/Contact/BAO/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public static function add(&$params) {
unset($params['preferred_communication_method']);
}

$defaults = ['source' => CRM_Utils_Array::value('contact_source', $params)];
$defaults = ['source' => $params['contact_source'] ?? NULL];
if ($params['contact_type'] === 'Organization' && isset($params['organization_name'])) {
$defaults['display_name'] = $params['organization_name'];
$defaults['sort_name'] = $params['organization_name'];
Expand Down Expand Up @@ -165,13 +165,10 @@ public static function add(&$params) {
}

$privacy = $params['privacy'] ?? NULL;
if ($privacy &&
is_array($privacy) &&
!empty($privacy)
) {
if ($privacy && is_array($privacy)) {
$allNull = FALSE;
foreach (self::$_commPrefs as $name) {
$contact->$name = CRM_Utils_Array::value($name, $privacy, FALSE);
$contact->$name = $privacy[$name] ?? FALSE;
}
}

Expand Down Expand Up @@ -199,19 +196,14 @@ public static function add(&$params) {

if ($contact->contact_type === 'Individual' && (isset($params['current_employer']) || isset($params['employer_id']))) {
// Create current employer.
$newEmployer = !empty($params['employer_id']) ? $params['employer_id'] : CRM_Utils_Array::value('current_employer', $params);
$newEmployer = !empty($params['employer_id']) ? $params['employer_id'] : $params['current_employer'] ?? NULL;

$newContact = FALSE;
if (empty($params['contact_id'])) {
$newContact = TRUE;
}
$newContact = empty($params['contact_id']);
if ($newEmployer) {
CRM_Contact_BAO_Contact_Utils::createCurrentEmployerRelationship($contact->id, $newEmployer, $employerId, $newContact);
}
else {
if ($employerId) {
CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($contact->id, $employerId);
}
elseif ($employerId) {
CRM_Contact_BAO_Contact_Utils::clearCurrentEmployer($contact->id, $employerId);
}
}

Expand Down Expand Up @@ -444,7 +436,7 @@ public static function unsetProtectedFields(&$contacts) {
$currentUser = CRM_Core_Session::getLoggedInContactID();
$editOwn = $currentUser && CRM_Core_Permission::check('edit own api keys');
foreach ($contacts as &$contact) {
$cid = is_object($contact) ? $contact->id : CRM_Utils_Array::value('id', $contact);
$cid = is_object($contact) ? $contact->id : $contact['id'] ?? NULL;
if (!($editOwn && $cid == $currentUser)) {
if (is_object($contact)) {
unset($contact->api_key);
Expand Down Expand Up @@ -827,7 +819,7 @@ public static function resolveDefaults(&$defaults, $reverse = FALSE) {
$reverse
);
}
$stateProvinceID = self::resolveStateProvinceID($values, CRM_Utils_Array::value('country_id', $values));
$stateProvinceID = self::resolveStateProvinceID($values, $values['country_id'] ?? NULL);
if ($stateProvinceID) {
$values['state_province_id'] = $stateProvinceID;
}
Expand Down Expand Up @@ -1371,7 +1363,7 @@ public static function importableFields(
$cacheKeyString .= $checkPermission ? '_1' : '_0';
$cacheKeyString .= '_' . CRM_Core_Config::domainID() . '_';

$fields = CRM_Utils_Array::value($cacheKeyString, self::$_importableFields) ?: Civi::cache('fields')->get($cacheKeyString);
$fields = self::$_importableFields[$cacheKeyString] ?? Civi::cache('fields')->get($cacheKeyString);

if (!$fields) {
$fields = CRM_Contact_DAO_Contact::import();
Expand Down Expand Up @@ -1524,7 +1516,7 @@ public static function &exportableFields($contactType = 'Individual', $status =
//as an interim fix we will cache the fields by contact
$cacheKeyString .= '_' . CRM_Core_Session::getLoggedInContactID();

if (!self::$_exportableFields || !CRM_Utils_Array::value($cacheKeyString, self::$_exportableFields)) {
if (!self::$_exportableFields || empty(self::$_exportableFields[$cacheKeyString])) {
if (!self::$_exportableFields) {
self::$_exportableFields = [];
}
Expand Down Expand Up @@ -2002,8 +1994,8 @@ public static function createProfileContact(

// manage is_opt_out
if (array_key_exists('is_opt_out', $fields) && array_key_exists('is_opt_out', $params)) {
$wasOptOut = CRM_Utils_Array::value('is_opt_out', $contactDetails, FALSE);
$isOptOut = CRM_Utils_Array::value('is_opt_out', $params, FALSE);
$wasOptOut = $contactDetails['is_opt_out'] ?? FALSE;
$isOptOut = $params['is_opt_out'];
$data['is_opt_out'] = $isOptOut;
// on change, create new civicrm_subscription_history entry
if (($wasOptOut != $isOptOut) && !empty($contactDetails['contact_id'])) {
Expand Down Expand Up @@ -3701,7 +3693,7 @@ public static function getEntityRefCreateLinks($appendProfiles = []) {
'url' => CRM_Utils_System::url('civicrm/profile/create', "reset=1&context=dialog&gid=$id",
NULL, NULL, FALSE, FALSE, TRUE),
'type' => ucfirst(str_replace('new_', '', $profile['name'])),
'icon' => CRM_Utils_Array::value(str_replace('new_', '', $profile['name']), $icons),
'icon' => $icons[str_replace('new_', '', $profile['name'])] ?? NULL,
];
}
else {
Expand Down