-
Notifications
You must be signed in to change notification settings - Fork 48
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-3546: Make All Currencies Available #2698
PCHR-3546: Make All Currencies Available #2698
Conversation
58f5af7
to
c46351c
Compare
c46351c
to
0272322
Compare
'option_group_id' => 'currencies_enabled', | ||
'label' => $dao->name . ' (' . $dao->symbol . ')', | ||
'value' => $dao->name, | ||
'name' => $dao->name, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Took a quick look in my local db, seems the enabled currencies have the same value for both name and label.
e.g EUR (€).
'label' => $dao->name . ' (' . $dao->symbol . ')', | ||
'value' => $dao->name, | ||
'name' => $dao->name, | ||
'is_active' => 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need to set is_active, is_reserved, is_optgroup and is_default, The values set for them are the same they have as the default database values.
while ($dao->fetch()) { | ||
$currencyExists = civicrm_api3('OptionValue', 'get', [ | ||
'value' => $dao->name, | ||
]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You need to add the option_group_id to the parameter to fetch the option value. In Civi it is possible for an option value with same names to exist and they will belong to different option groups. So for example we can have GBP
belonging as an option value to another option group.
*/ | ||
private function makeAllCurrenciesAvailable() { | ||
$dao = CRM_Core_DAO::executeQuery('SELECT * from civicrm_currency'); | ||
while ($dao->fetch()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also since the currency records might be up to 200(on my local installation), wondering if we could optimize this by using a single API call to get all enable currencies names.
$result = civicrm_api3('OptionValue', 'get', array(
'sequential' => 1,
'return' => array("name"),
'option_group_id' => "currencies_enabled",
));
Then in this loop, we can check if
if(!in_array($dao->name, $enabledCurrency){
// create the currency
}
@@ -194,20 +194,18 @@ private function createDefaultRelationshipTypes() { | |||
*/ | |||
private function makeAllCurrenciesAvailable() { | |||
$dao = CRM_Core_DAO::executeQuery('SELECT * from civicrm_currency'); | |||
$result = civicrm_api3('OptionValue', 'get', array( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use short array syntax and single quote for strings.
'return' => array("name"), | ||
'option_group_id' => "currencies_enabled", | ||
)); | ||
$enabledCurrency = array_column($result['values'],'name'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think enabledCurrencies
might be a better name since there will most likely be more than one.
* Making All Currencies Available for new installations | ||
*/ | ||
private function makeAllCurrenciesAvailable() { | ||
$dao = CRM_Core_DAO::executeQuery('SELECT * from civicrm_currency'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please move this line to just before the while loop.
You can also add a space before that so the code is not cluttered together
1c68dc6
to
772a8ea
Compare
772a8ea
to
cb193f0
Compare
0e4fc54
to
748cc72
Compare
cb193f0
to
34bd51f
Compare
748cc72
to
45176dd
Compare
34bd51f
to
0c8ded2
Compare
Overview
Made all currencies available for new installations
Before
Only few currencies was available on new installations
After
All Currencies are available on new CiviHR installations by default
Technical Details
Couldn't find any CiviCRM API to retrieve currencies, so made direct query.