Tribe__Tickets__REST__V1__Post_Repository::get_ticket_data( $ticket_id,  $context = 'default' )

{@inheritdoc}


Source

File: src/Tribe/REST/V1/Post_Repository.php

	public function get_ticket_data( $ticket_id, $context = 'default' ) {
		if ( is_array( $ticket_id ) && ! empty( $ticket_id['id'] ) ) {
			// ticket data in array format
			$ticket_id = $ticket_id['id'];
		}

		$ticket = $ticket_id instanceof Tribe__Tickets__Ticket_Object
			? $ticket_id
			: $this->get_ticket_object( $ticket_id );

		if ( $ticket instanceof WP_Error ) {
			return $ticket;
		}

		// make sure the data is a nested array
		$data = json_decode( json_encode( $ticket ), true );

		$data['post_id']  = $ticket->get_event_id();
		$data['provider'] = $this->get_provider_slug( $ticket->provider_class );
		$data['id'] = (int) $data['ID'];

		try {
			$this->add_ticket_global_id_data( $data );
			$this->add_ticket_post_data( $data );
			$this->add_ticket_meta_data( $data );
			$this->add_ticket_attendees_data( $data );
			$this->add_ticket_rest_data( $data );
			$this->clean_ticket_data( $data );
		} catch ( Exception $e ) {
			if ( $e instanceof Tribe__REST__Exceptions__Exception ) {
				return new WP_Error( $e->getCode(), $e->getMessage() );
			}

			/** @var Tribe__REST__Exceptions__Exception $e */
			return new WP_Error(
				'error',
				__( 'An error happened while building the response: ', 'event-tickets' ) . $e->getMessage(),
				array( 'status' => $e->getMessage() )
			);
		}

		/**
		 * Filters the data that will be returned for a ticket.
		 *
		 * @since 4.8
		 *
		 * @param array  $data The ticket data.
		 * @param int    $ticket_id The ticket post ID.
		 * @param string $context The context in which the data will show; this is about format,
		 *                        not permissions.
		 */
		$data = apply_filters( 'tribe_tickets_rest_api_ticket_data', $data, $ticket_id, $context );

		return $data;
	}