-
-
Notifications
You must be signed in to change notification settings - Fork 825
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
REF Extract getDefaultRoleID for add participant #14499
REF Extract getDefaultRoleID for add participant #14499
Conversation
(Standard links)
|
CRM/Event/Form/Registration.php
Outdated
'role_id' => CRM_Utils_Array::value('participant_role_id', | ||
$params, $roleID | ||
), | ||
'role_id' => self::getDefaultRoleID($params), |
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.
How about
'role_id' => self::getDefaultRoleID(
CRM_Utils_Array::value('participant_role_id', $params)
),
private static function getDefaultRoleID($roleID) {
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.
or how about:
...
'role_id' => CRM_Utils_Array::value(
'participant_role_id',
$params,
civicrm_api3('OptionValue', 'getvalue', [
'return' => "value",
'option_group_id' => "participant_role",
'options' => ['limit' => 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 agree with creating a new function for getDefaultRoleID() since it can be re-used elsewhere but i think we should not pass whole params array to that function
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 agree - the only reason params is being passed is to check whether we need to look up the default role id - I think that should be done outside the function ie
$roleId = CRM_Utils_Array::value('participant_role_id', $params) ? : self::getDefaultRoleID();
CRM/Event/Form/Registration.php
Outdated
$roleID = CRM_Utils_Array::value('participant_role_id', $params); | ||
if (!$roleID) { | ||
$roleID = civicrm_api3('OptionValue', 'getvalue', [ | ||
'return' => "value", |
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.
is the is_default=1 not required? Is is_active implicit?
3e6dc41
to
151fd2f
Compare
@monishdeb @pradpnayak @eileenmcnaughton Thanks for the review. I've taken the best of each and updated the PR. I've added in is_active (that should have been there). Also I've sorted by is_default though they're all NULL on my db and it wasn't previously checking for the is_default flag but it makes sense that it does... |
151fd2f
to
413859f
Compare
Seems like this has general agreement and has passed unit tests merging |
Overview
Extract function to get default role ID if it's not defined.
Before
Custom query was being run whether or not it was required.
After
Custom query replaced by API call and only run when it's actually needed (ie. we don't already have a role ID).
Technical Details
Comments