Skip to content

Commit

Permalink
Merge pull request #2703 from compucorp/PCHR-3544-hide-fields-for-con…
Browse files Browse the repository at this point in the history
…tact-summary

PCHR-3544: Hide Fields for Contact Summary
  • Loading branch information
ajesamson authored Jun 21, 2018
2 parents 91e450a + f3b4a6f commit ebede58
Show file tree
Hide file tree
Showing 2 changed files with 83 additions and 0 deletions.
1 change: 1 addition & 0 deletions uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class CRM_HRCore_Upgrader extends CRM_HRCore_Upgrader_Base {
use CRM_HRCore_Upgrader_Steps_1018;
use CRM_HRCore_Upgrader_Steps_1020;
use CRM_HRCore_Upgrader_Steps_1021;
use CRM_HRCore_Upgrader_Steps_1022;

/**
* @var array
Expand Down
82 changes: 82 additions & 0 deletions uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1022.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
<?php

trait CRM_HRCore_Upgrader_Steps_1022 {

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

$activeOptionValues = array_diff($activeOptionValues, $valuesToRemove);
civicrm_api3('Setting', 'create', [
'contact_edit_options' => $activeOptionValues,
]);

return TRUE;
}

/**
* Retrieves active contact edit option setting value
*
* @return array
*/
private function up1022_getActiveContactEditOptionValues() {
$result = civicrm_api3('Setting', 'get', [
'return' => ['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_getContactEditOptionValuesToRemove() {
$values = [];
$names = $this->up1022_getUnusedContactEditOptionNames();

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

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

return $values;
}

/**
* Get names of contact edit options not in use
*
* @return array
*/
private function up1022_getUnusedContactEditOptionNames() {
$names = [];

foreach (['Contact', 'IM', 'Website'] as $name) {
$params = ['return' => ['id']];
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);
}
}

return $names;
}

}

0 comments on commit ebede58

Please sign in to comment.