@@ -49,9 +49,6 @@ public function run() {
49
49
$ this ->assign ('iCal ' , CRM_Event_BAO_Event::getICalLinks ($ this ->_id ));
50
50
$ this ->assign ('isShowICalIconsInline ' , TRUE );
51
51
52
- // Sometimes we want to suppress the Event Full msg
53
- $ noFullMsg = CRM_Utils_Request::retrieve ('noFullMsg ' , 'String ' , $ this , FALSE , 'false ' );
54
-
55
52
//retrieve event information
56
53
$ params = ['id ' => $ this ->_id ];
57
54
$ values = ['event ' => NULL ];
@@ -271,17 +268,25 @@ public function run() {
271
268
$ this ->assign ('registerClosed ' , !empty ($ values ['event ' ]['is_online_registration ' ]) && !$ isEventOpenForRegistration && CRM_Core_Permission::check ('register for events ' ));
272
269
$ this ->assign ('allowRegistration ' , $ allowRegistration );
273
270
274
- $ session = CRM_Core_Session::singleton ();
275
- $ params = [
276
- 'contact_id ' => $ session ->get ('userID ' ),
277
- 'event_id ' => $ values ['event ' ]['id ' ] ?? NULL ,
278
- 'role_id ' => $ values ['event ' ]['default_role_id ' ] ?? NULL ,
279
- ];
280
-
281
- if (($ this ->isEventFull () && $ noFullMsg === 'false ' ) || CRM_Event_BAO_Event::checkRegistration ($ params )) {
282
- $ statusMessage = $ this ->getEventValue ('event_full_text ' );
283
- if (CRM_Event_BAO_Event::checkRegistration ($ params )) {
284
- if ($ noFullMsg == 'false ' ) {
271
+ $ isAlreadyRegistered = $ this ->isAlreadyRegistered ();
272
+ // noFullMsg was originally passed in to suppress the message about the event being full. The intent
273
+ // was originally such that when you were sending the user back to the info page after registering
274
+ // they would not be told it was full. Along the way it got overloaded to encompass
275
+ // the scenario where the user is potentially trying to register another user & hence became very confusing.
276
+ // We could probably make this make more sense by
277
+ // 1) always passing cid in the url if the person is being redirected to register another person
278
+ // and using that rather than the logged in use to check for existing registrations
279
+ // 2) using a more positive 'you are registered' message rather than making it
280
+ // sound like a mistake.
281
+ // 3) using the normal button to pass cid=0 information rather than a link.
282
+ $ noFullMsg = CRM_Utils_Request::retrieve ('noFullMsg ' , 'String ' , $ this , FALSE , 'false ' );
283
+ $ isSuppressEventFullMessage = $ noFullMsg !== 'false ' ;
284
+ $ statusMessage = ($ this ->isEventFull () && !$ isSuppressEventFullMessage && !$ isAlreadyRegistered ) ? $ this ->getEventValue ('event_full_text ' ) : '' ;
285
+ if (($ this ->isEventFull () && $ noFullMsg === 'false ' ) || $ isAlreadyRegistered ) {
286
+ if ($ isAlreadyRegistered ) {
287
+ // @todo - this usage of `$isSuppressEventFullMessage` is where the historical mis-use makes it
288
+ // confusing - better use of cid in the url would help.
289
+ if (!$ isSuppressEventFullMessage ) {
285
290
if ($ values ['event ' ]['allow_same_participant_emails ' ]) {
286
291
$ statusMessage = ts ('It looks like you are already registered for this event. You may proceed if you want to create an additional registration. ' );
287
292
}
@@ -377,4 +382,19 @@ public function getPriceSetID(): ?int {
377
382
return NULL ;
378
383
}
379
384
385
+ /**
386
+ * @return bool
387
+ * @throws \CRM_Core_Exception
388
+ */
389
+ public function isAlreadyRegistered (): bool {
390
+ $ params = [
391
+ // @todo - instead of just checking logged in user check for cid=0 or an integer
392
+ // in the url. (For zero there should be no check).
393
+ 'contact_id ' => CRM_Core_Session::getLoggedInContactID (),
394
+ 'event_id ' => $ this ->getEventID (),
395
+ 'role_id ' => $ this ->getEventValue ('default_role_id ' ),
396
+ ];
397
+ return CRM_Event_BAO_Event::checkRegistration ($ params );
398
+ }
399
+
380
400
}
0 commit comments