$capacity ) { CatalogValidator::invalid( 'participant_count', __( 'The number of participants exceeds the resource capacity.', 'abece-booking' ) ); } $booker = CatalogValidator::boolean( $input['booker_participates'] ?? true, 'booker_participates' ); $ids = $input['member_ids'] ?? []; if ( ! is_array( $ids ) || ! array_is_list( $ids ) || count( $ids ) > 100 ) { CatalogValidator::invalid( 'member_ids', __( 'Provide a list of at most 100 identified members.', 'abece-booking' ) ); } $type = BookingCustomerService::type( $customer ); if ( 'member' !== $type && $ids ) { CatalogValidator::invalid( 'member_ids', __( 'Only member bookings may include identified club members.', 'abece-booking' ) ); } if ( 'member' === $type && $booker && !in_array($customer['customer_member_id'],array_map('intval',$ids),true) ) { array_unshift( $ids, $customer['customer_member_id'] ); } $eligible=$this->membership->getActiveMembershipsForMembers($ids,$this->customers->day($date)); $names=$this->members->names($ids);$seen = []; $rows = []; foreach ( $ids as $id ) { $id = CatalogValidator::integer( $id, 'member_ids', 1, PHP_INT_MAX ); if ( in_array( $id, $seen, true ) || ( ! in_array( $id, $retained_ids, true ) && ! isset($eligible[$id]) ) ) { CatalogValidator::invalid( 'member_ids', __( 'Select each member only once and ensure eligibility on the booking date.', 'abece-booking' ) ); } $seen[] = $id; $m = $names[$id]??null;if(!$m)CatalogValidator::invalid('member_ids',__('The selected member does not exist.','abece-booking')); $rows[] = [ 'member_id' => $id, 'participant_type' => 'member', 'name' => MembershipValidator::text( trim( $m['first_name'] . ' ' . $m['last_name'] ), 'member_ids', 200 ), 'price_adjustment' => 0 ]; } if ( count( $rows ) > $count ) { CatalogValidator::invalid( 'participant_count', __( 'Identified members cannot exceed the total number of players.', 'abece-booking' ) ); } return [ 'participant_count' => $count, 'participants' => $rows ]; } public function input( array $booking, array $participants ): array { $type = BookingCustomerService::type( $booking ); $count = 0; if ( 'member' === $type ) { $day = $this->customers->day( Time::timestamp( Time::fromSql( $booking['starts_at'] ) )->format( 'Y-m-d' ) ); $eligible=$this->membership->getActiveMembershipsForMembers(array_column($participants,'member_id'),$day);foreach ( $participants as $p ) { if ( 'member' === $p['participant_type'] && $p['member_id'] && isset($eligible[$p['member_id']]) ) { ++$count; } } } return [ 'customer_type' => $type, 'participant_count' => $booking['participant_count'], 'eligible_member_count' => $count, 'non_member_count' => max( 0, $booking['participant_count'] - $count ), 'full_public_price' => 'member' !== $type ]; } }