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

REF Extract getDefaultRoleID for add participant #14499

Merged
merged 1 commit into from
Jun 25, 2019

Conversation

mattwire
Copy link
Contributor

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

@civibot
Copy link

civibot bot commented Jun 12, 2019

(Standard links)

@civibot civibot bot added the master label Jun 12, 2019
'role_id' => CRM_Utils_Array::value('participant_role_id',
$params, $roleID
),
'role_id' => self::getDefaultRoleID($params),
Copy link
Contributor

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) {

Copy link
Member

@monishdeb monishdeb Jun 13, 2019

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],
     ])
  ),
...

:)

Copy link
Contributor

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

Copy link
Contributor

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();

$roleID = CRM_Utils_Array::value('participant_role_id', $params);
if (!$roleID) {
$roleID = civicrm_api3('OptionValue', 'getvalue', [
'return' => "value",
Copy link
Contributor

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?

@mattwire mattwire force-pushed the extract_getdefaultroleid branch from 3e6dc41 to 151fd2f Compare June 13, 2019 22:28
@mattwire
Copy link
Contributor Author

@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...

@mattwire mattwire force-pushed the extract_getdefaultroleid branch from 151fd2f to 413859f Compare June 13, 2019 22:30
@mattwire mattwire added the merge ready PR will be merged after a few days if there are no objections label Jun 16, 2019
@seamuslee001
Copy link
Contributor

Seems like this has general agreement and has passed unit tests merging

@seamuslee001 seamuslee001 merged commit 458a3ae into civicrm:master Jun 25, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
master merge ready PR will be merged after a few days if there are no objections
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants