progressivetech / net.ourpowerbase.qrcodecheckin

QRCode Checkin allows you to send an email that contains a scanable code to the registered participants for your event.
Other
16 stars 15 forks source link

Feature: Allow for more participant roles than "attendee" #30

Closed CsarRamos closed 1 year ago

CsarRamos commented 1 year ago

Hello all,

I am opening the ticket to see if the QR code events extension can be modified so that more roles than "attendee" can be used.

If possible, I can start a new development to allow it.

Do you see it as a usable functionality? to include it in the extension?

cc: @jmcclelland

Cheers

jmcclelland commented 1 year ago

Yes - sound great. I would welcome that change.

CsarRamos commented 1 year ago

Hello, doing some tests I detected that we can now use any participant role in the event settings and it works, except that the label and the name in the civicrm_option_value table have to match.

Example works: label: Attendee, name: Attendee Example works: label: Volunteer, name Volunteer Example that does not work: label Asistente, name: Attendee

This happens when a different language is installed by default when CiviCRM is installed.

If you create a new role it works fine, because it is the same label and name, but if you have CiviCRM translated into another language than English it will fail.

It works fine if I assign a default role and then create a participant with another role, except for the language problem.

I was planning to do this functionality but it is now available. Maybe I would look at correcting that you can use the default roles that have been created in civicrm_option_value with another language.

This issue was already reported here:

https://github.com/progressivetech/net.ourpowerbase.qrcodecheckin/issues/10

jmcclelland commented 1 year ago

I think #10 is about participant status, not participant role. And, looking at the what I think is the relevant code I'm not sure why it would fail if the role was different. Is that the code causing the problem?

CsarRamos commented 1 year ago

I haven't investigated the code, I'll do some tests and report back.

Cheers

CsarRamos commented 1 year ago

Hello, this is the error in the browser when trying to update the status to attended:

error_message: "'Asistente' is not a valid option for field role_id"

The error is when the get of the participant returns the translated role of the participant with api3, this blocks the creation when passing the label in the create. A solution could be to update the participant_role with the name before the create or delete unnecessary values to update status.

A way to get the name instead of the label:

  $participantRoles = CRM_Core_OptionGroup::values('participant_role', FALSE, FALSE, FALSE, FALSE, 'name');
  $values['participant_role'] = $participantRoles[$values['participant_role_id']];

This would also work because we don't want to update the role: unset($values['participant_role'])

I think it's not necessary to pass all values, another way would be just to pass the id and status of the participant.

$values['status_id'] = 'Attended';
$values['id'] = $result['id'];

All these changes would be just before the create

jmcclelland commented 1 year ago

@CsarRamos thanks for the analysis - I think you are correct.

My suggested fix would be to simply replace it all with an APIv4 call. I don't think you need to get anything, just update the status_id.name to 'Attended'. I think that should resolve all the problems.

In other words, something like:

\Civi\Api4\Activity::update()
 ->addWhere('id', '=', $params['participant_id'])
 ->addValue('status_id:name', 'Attended')
 ->execute();
CsarRamos commented 1 year ago

Great, sounds a good approach. I'll send you a pull request with the changes.

jmcclelland commented 1 year ago

Thanks @CsarRamos for seeing this through.