Skip to content

Commit

Permalink
PCHR-3544: PR Feedback - Code refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ajesamson committed Jun 21, 2018
1 parent 0991390 commit f3b4a6f
Showing 1 changed file with 12 additions and 12 deletions.
24 changes: 12 additions & 12 deletions uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1022.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ trait CRM_HRCore_Upgrader_Steps_1022 {

/**
* Hide Fields For Contact Summary
*
* @return bool
*/
public function upgrade_1022() {
$valuesRemoved = $this->up1022_getContactEditOptionValues();
$optionValues = $this->up1022_getActiveContactEditOptionValues();
$valuesToRemove = $this->up1022_getContactEditOptionValuesToRemove();
$activeOptionValues = $this->up1022_getActiveContactEditOptionValues();

$activeOptionValues = array_diff($optionValues, $valuesRemoved);
$activeOptionValues = array_diff($activeOptionValues, $valuesToRemove);
civicrm_api3('Setting', 'create', [
'contact_edit_options' => $activeOptionValues,
]);
Expand All @@ -24,33 +26,31 @@ public function upgrade_1022() {
*/
private function up1022_getActiveContactEditOptionValues() {
$result = civicrm_api3('Setting', 'get', [
'sequential' => 1,
'return' => ['contact_edit_options'],
]);

return $result['values'][0]['contact_edit_options'];
return $result['values'][$result['id']]['contact_edit_options'];
}

/**
* Retrieves value for contact edit options to be removed
*
* @return array
*/
private function up1022_getContactEditOptionValues() {
private function up1022_getContactEditOptionValuesToRemove() {
$values = [];
$names = $this->up1022_getUnusedContactEditOptionNames();

$params = [
'sequential' => 1,
'return' => ['value', 'name'],
'option_group_id' => 'contact_edit_options',
'is_active' => 1,
'name' => ['IN' => $names]
];

$optionValues = civicrm_api3('OptionValue', 'get', $params);
foreach ($optionValues['values'] as $optionValue) {
array_push($values, $optionValue['value']);
$results = civicrm_api3('OptionValue', 'get', $params);
foreach ($results['values'] as $result) {
array_push($values, $result['value']);
}

return $values;
Expand All @@ -66,13 +66,13 @@ private function up1022_getUnusedContactEditOptionNames() {

foreach (['Contact', 'IM', 'Website'] as $name) {
$params = ['return' => ['id']];
if ($name == 'Contact') {
if ($name === 'Contact') {
$params['suffix_id'] = ['IS NOT NULL' => 1];
}

$result = civicrm_api3($name, 'get', $params);
if ($result['count'] == 0) {
array_push($names, $name == 'Contact' ? 'Suffix' : $name);
array_push($names, $name === 'Contact' ? 'Suffix' : $name);
}
}

Expand Down

0 comments on commit f3b4a6f

Please sign in to comment.