-
Notifications
You must be signed in to change notification settings - Fork 48
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2703 from compucorp/PCHR-3544-hide-fields-for-con…
…tact-summary PCHR-3544: Hide Fields for Contact Summary
- Loading branch information
Showing
2 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
uk.co.compucorp.civicrm.hrcore/CRM/HRCore/Upgrader/Steps/1022.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
|
||
} |