Changeset 13529 for sites/trunk/wordpress.org/public_html/wp-content/plugins/wporg-gp-translation-events/includes/routes/user/attend-event.php
- Timestamp:
- 04/15/2024 01:37:55 PM (20 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
r13298 r13529 3 3 namespace Wporg\TranslationEvents\Routes\User; 4 4 5 use Wporg\TranslationEvents\Attendee\Attendee; 6 use Wporg\TranslationEvents\Attendee\Attendee_Repository; 7 use Wporg\TranslationEvents\Event\Event_Repository_Interface; 5 8 use Wporg\TranslationEvents\Routes\Route; 6 9 use Wporg\TranslationEvents\Translation_Events; … … 12 15 */ 13 16 class Attend_Event_Route extends Route { 17 private Event_Repository_Interface $event_repository; 18 private Attendee_Repository $attendee_repository; 19 20 public function __construct() { 21 parent::__construct(); 22 $this->event_repository = Translation_Events::get_event_repository(); 23 $this->attendee_repository = Translation_Events::get_attendee_repository(); 24 } 25 14 26 public function handle( int $event_id ): void { 15 27 $user = wp_get_current_user(); … … 18 30 } 19 31 20 $event = get_post( $event_id ); 21 32 $event = $this->event_repository->get_event( $event_id ); 22 33 if ( ! $event ) { 23 34 $this->die_with_404(); 24 35 } 25 36 26 $event_ids = get_user_meta( $user->ID, Translation_Events::USER_META_KEY_ATTENDING, true ) ?? array(); 27 if ( ! $event_ids ) { 28 $event_ids = array(); 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 ); 40 } 41 if ( $attendee instanceof Attendee ) { 42 $this->attendee_repository->remove_attendee( $event->id(), $user->ID ); 43 } else { 44 $attendee = new Attendee( $event->id(), $user->ID ); 45 $this->attendee_repository->insert_attendee( $attendee ); 29 46 } 30 47 31 if ( ! isset( $event_ids[ $event_id ] ) ) { 32 // Not yet attending, mark as attending. 33 $event_ids[ $event_id ] = true; 34 } else { 35 // Currently attending, mark as not attending. 36 unset( $event_ids[ $event_id ] ); 37 } 38 39 update_user_meta( $user->ID, Translation_Events::USER_META_KEY_ATTENDING, $event_ids ); 40 41 wp_safe_redirect( gp_url( "/events/$event->post_name" ) ); 48 wp_safe_redirect( gp_url( "/events/{$event->slug()}" ) ); 42 49 exit; 43 50 }
Note: See TracChangeset
for help on using the changeset viewer.