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

PCHR-3544: Hide Fields for Contact Summary #2703

Merged
Show file tree
Hide file tree
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
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing @return

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed thanks

*
* @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;
}

}