Changeset 13541 for sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events/includes/routes/user/attend-event.php
- Timestamp:
- 04/16/2024 12:41:37 PM (19 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events/includes/routes/user/attend-event.php
r13529 r13541 7 7 use Wporg\TranslationEvents\Event\Event_Repository_Interface; 8 8 use Wporg\TranslationEvents\Routes\Route; 9 use Wporg\TranslationEvents\Stats\Stats_Importer; 9 10 use Wporg\TranslationEvents\Translation_Events; 10 11 … … 13 14 * If the user is not currently marked as attending, they will be marked as attending. 14 15 * If the user is currently marked as attending, they will be marked as not attending. 16 * 17 * If the user is marked as attending, and the event is active at that moment, stats for the translations the user 18 * created since the event started are imported. 15 19 */ 16 20 class Attend_Event_Route extends Route { 17 21 private Event_Repository_Interface $event_repository; 18 22 private Attendee_Repository $attendee_repository; 23 private Stats_Importer $stats_importer; 19 24 20 25 public function __construct() { … … 22 27 $this->event_repository = Translation_Events::get_event_repository(); 23 28 $this->attendee_repository = Translation_Events::get_attendee_repository(); 29 $this->stats_importer = new Stats_Importer(); 24 30 } 25 31 … … 29 35 $this->die_with_error( esc_html__( 'Only logged-in users can attend events', 'gp-translation-events' ), 403 ); 30 36 } 37 $user_id = $user->ID; 31 38 32 39 $event = $this->event_repository->get_event( $event_id ); … … 35 42 } 36 43 37 $attendee = $this->attendee_repository->get_attendee( $event->id(), $user->ID ); 38 if ( $attendee instanceof Attendee && $attendee->is_host() && ( 1 === count( $this->attendee_repository->get_hosts( $event_id ) ) ) ) { 39 $this->die_with_error( esc_html__( 'The event needs a host. Add a new host before stopping to attend the event.', 'gp-translation-events' ), 403 ); 44 if ( $event->is_past() ) { 45 $this->die_with_error( esc_html__( 'Cannot attend or un-attend a past event', 'gp-translation-events' ), 403 ); 40 46 } 47 48 $attendee = $this->attendee_repository->get_attendee( $event->id(), $user_id ); 41 49 if ( $attendee instanceof Attendee ) { 42 $this->attendee_repository->remove_attendee( $event->id(), $user ->ID);50 $this->attendee_repository->remove_attendee( $event->id(), $user_id ); 43 51 } else { 44 $attendee = new Attendee( $event->id(), $user ->ID);52 $attendee = new Attendee( $event->id(), $user_id ); 45 53 $this->attendee_repository->insert_attendee( $attendee ); 54 55 // If the event is active right now, 56 // import stats for translations the user created since the event started. 57 if ( $event->is_active() ) { 58 $this->stats_importer->import_for_user_and_event( $user_id, $event ); 59 } 46 60 } 47 61
Note: See TracChangeset
for help on using the changeset viewer.