Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add event connections to attendees types. #29

Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
433fd8d
Add event connection to attendees.
justlevine Dec 31, 2020
b112d53
Manually remove failed platform_check.php
justlevine Dec 31, 2020
e1f9daa
Update ql-events.php
zbtirrell Jan 22, 2021
980c7f6
Update README.md
zbtirrell Jan 22, 2021
fec4827
Removes extraneous comma to prevent a silent PHP error.
geoffgraham Feb 3, 2021
65e10ca
Merge pull request #31 from the-events-calendar/spotfix-comma
bordoni Apr 8, 2021
03c3136
Add event connection to attendees.
justlevine Dec 31, 2020
2047d2c
Manually remove failed platform_check.php
justlevine Dec 31, 2020
cfd99a7
Merge branch 'feature/attendee-event-connection' of https://github.co…
justlevine Apr 9, 2021
f993045
Update includes/class-core-schema-filters.php
justlevine Apr 10, 2021
10f9ac4
Update includes/data/connection/class-wooattendee-connection-resolver…
justlevine Apr 10, 2021
d516818
Update includes/data/connection/class-wooattendee-connection-resolver…
justlevine Apr 10, 2021
48073a2
Update includes/data/connection/class-wooattendee-connection-resolver…
justlevine Apr 10, 2021
de1db9f
Update includes/data/connection/class-rsvpattendee-connection-resolve…
justlevine Apr 10, 2021
079245d
Update includes/connection/class-wooattendees.php
justlevine Apr 10, 2021
9b94536
Update includes/connection/class-wooattendees.php
justlevine Apr 10, 2021
0ff3dfd
Update includes/data/connection/class-paypalattendee-connection-resol…
justlevine Apr 10, 2021
7af9ad2
Update includes/connection/class-rsvpattendees.php
justlevine Apr 10, 2021
be6fa02
Update includes/data/connection/class-paypalattendee-connection-resol…
justlevine Apr 10, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
87 changes: 87 additions & 0 deletions includes/class-core-schema-filters.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,33 @@ public static function add_filters() {
10,
5
);

add_filter(
'graphql_post_object_connection_query_args',
array(
'\WPGraphQL\QL_Events\Data\Connection\RSVPAttendee_Connection_Resolver',
'get_query_args',
),
Comment on lines +81 to +84
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
array(
'\WPGraphQL\QL_Events\Data\Connection\RSVPAttendee_Connection_Resolver',
'get_query_args',
),
[
'\WPGraphQL\QL_Events\Data\Connection\RSVPAttendee_Connection_Resolver',
'get_query_args',
],

10,
5
);

add_filter(
'graphql_post_object_connection_query_args',
array(
'\WPGraphQL\QL_Events\Data\Connection\PayPalAttendee_Connection_Resolver',
'get_query_args',
),
Comment on lines +91 to +94
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
array(
'\WPGraphQL\QL_Events\Data\Connection\PayPalAttendee_Connection_Resolver',
'get_query_args',
),
[
'\WPGraphQL\QL_Events\Data\Connection\PayPalAttendee_Connection_Resolver',
'get_query_args',
],

10,
5
);

add_filter(
'graphql_input_fields',
array( __CLASS__, 'attendees_where_args' ),
10,
2
);
Comment on lines +99 to +104
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
add_filter(
'graphql_input_fields',
array( __CLASS__, 'attendees_where_args' ),
10,
2
);
add_filter( 'graphql_input_fields', [ __CLASS__, 'attendees_where_args' ], 10, 2 );

}

if ( \QL_Events::is_ticket_events_plus_loaded() ) {
Expand All @@ -97,6 +124,23 @@ public static function add_filters() {
10,
6
);

add_filter(
'graphql_post_object_connection_query_args',
array(
'\WPGraphQL\QL_Events\Data\Connection\WooAttendee_Connection_Resolver',
'get_query_args',
),
Comment on lines +130 to +133
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
array(
'\WPGraphQL\QL_Events\Data\Connection\WooAttendee_Connection_Resolver',
'get_query_args',
),
[
'\WPGraphQL\QL_Events\Data\Connection\WooAttendee_Connection_Resolver',
'get_query_args',
],

10,
5
);

add_filter(
'graphql_input_fields',
array( __CLASS__, 'ticket_plus_attendees_where_args' ),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
array( __CLASS__, 'ticket_plus_attendees_where_args' ),
[ __CLASS__, 'ticket_plus_attendees_where_args' ],

10,
2
);
}
}

Expand Down Expand Up @@ -201,4 +245,47 @@ public static function events_where_args( $fields = array(), $type_name ) {
}
return $fields;
}

/**
* Adds "where" arguments to Attendees connections
*
* @param array $fields Attendees where args.
* @param string $type_name Connection "where" input type name.
*
* @return array
*/
public static function attendees_where_args( $fields = array(), $type_name ) {
if ( self::ends_with( $type_name, 'RSVPAttendeeConnectionWhereArgs' ) ) {
$fields = array_merge(
$fields,
\WPGraphQL\QL_Events\Connection\RSVPAttendees::where_args()
);
}

if ( self::ends_with( $type_name, 'PayPalAttendeeConnectionWhereArgs' ) ) {
justlevine marked this conversation as resolved.
Show resolved Hide resolved
$fields = array_merge(
$fields,
\WPGraphQL\QL_Events\Connection\PayPalAttendees::where_args()
);
}
return $fields;
}

/**
* Adds "where" arguments to WooAttendee connections
*
* @param array $fields WooAttendee where args.
* @param string $type_name Connection "where" input type name.
*
* @return array
*/
public static function ticket_plus_attendees_where_args( $fields = array(), $type_name ) {
if ( self::ends_with( $type_name, 'WooAttendeeConnectionWhereArgs' ) ) {
$fields = array_merge(
$fields,
\WPGraphQL\QL_Events\Connection\WooAttendees::where_args()
);
}
return $fields;
}
}
4 changes: 4 additions & 0 deletions includes/class-type-registry.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ public function init( \WPGraphQL\Registry\TypeRegistry $type_registry ) {

// Event Tickets Connections.
\WPGraphQL\QL_Events\Connection\Tickets::register_connections();
\WPGraphQL\QL_Events\Connection\RSVPAttendees::register_connections();
\WPGraphQL\QL_Events\Connection\PayPalAttendees::register_connections();
}

if ( \QL_Events::is_ticket_events_plus_loaded() ) {
Expand All @@ -47,6 +49,8 @@ public function init( \WPGraphQL\Registry\TypeRegistry $type_registry ) {

// Event Tickets Plus Connections.
\WPGraphQL\QL_Events\Connection\Tickets_Plus::register_connections();
\WPGraphQL\QL_Events\Connection\WooAttendees::register_connections();

}
}
}
45 changes: 45 additions & 0 deletions includes/connection/class-paypalattendees.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* Connection - PayPalAttendees
*
* Registers connections to PayPalAttendee
*
* @package WPGraphQL\QL_Events\Connection
* @since 0.0.1
*/

namespace WPGraphQL\QL_Events\Connection;

use Tribe__Tickets__Commerce__PayPal__Main as PAYPAL;
use WPGraphQL\Connection\PostObjects;

/**
* Class - Attendees
*/
class PayPalAttendees extends PostObjects {
/**
* Registers the various connections from other Types to Attendees
*/
public static function register_connections() {
// From Event to Attendees.
register_graphql_connection(
self::get_connection_config(
get_post_type_object( PAYPAL::ATTENDEE_OBJECT ),
array(
'fromType' => 'Event',
'toType' => 'PayPalAttendee',
'fromFieldName' => 'payPalAttendees',
)
Comment on lines +28 to +32
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
array(
'fromType' => 'Event',
'toType' => 'PayPalAttendee',
'fromFieldName' => 'payPalAttendees',
)
[
'fromType' => 'Event',
'toType' => 'PayPalAttendee',
'fromFieldName' => 'payPalAttendees',
]

)
);
}

public static function where_args() {
return array(
'eventsIn' => array(
'type' => array( 'list_of' => 'ID'),
'description' => __( 'Filter the connection based on event Id'),
)
);
Comment on lines +38 to +43
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return array(
'eventsIn' => array(
'type' => array( 'list_of' => 'ID'),
'description' => __( 'Filter the connection based on event Id'),
)
);
return [
'eventsIn' => [
'type' => [ 'list_of' => 'ID' ],
'description' => __( 'Filter the connection based on event Id', 'ql-events' ),
]
];

}
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<?php
/**
* Connection - Attendees
* Connection - RSVPAttendees
*
* Registers connections to Attendee
* Registers connections to RSVPAttendee
*
* @package WPGraphQL\QL_Events\Connection
* @since 0.0.1
Expand All @@ -14,9 +14,9 @@
use WPGraphQL\Connection\PostObjects;

/**
* Class - Attendees
* Class - RSVPAttendees
*/
class Attendees extends PostObjects {
class RSVPAttendees extends PostObjects {
/**
* Registers the various connections from other Types to Attendees
*/
Expand All @@ -27,10 +27,19 @@ public static function register_connections() {
get_post_type_object( RSVP::ATTENDEE_OBJECT ),
array(
'fromType' => 'Event',
'toType' => 'Attendee',
'fromFieldName' => 'attendees',
'toType' => 'RSVPAttendee',
'fromFieldName' => 'rSVPAttendees',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this r lower case intentional?

)
)
);
}

public static function where_args() {
return array(
'eventsIn' => array(
'type' => array( 'list_of' => 'ID'),
'description' => __( 'Filter the connection based on event Id'),
)
);
justlevine marked this conversation as resolved.
Show resolved Hide resolved
}
}
45 changes: 45 additions & 0 deletions includes/connection/class-wooattendees.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php
/**
* Connection - WooAttendees
*
* Registers connections to WooAttendee
*
* @package WPGraphQL\QL_Events\Connection
* @since 0.0.1
*/

namespace WPGraphQL\QL_Events\Connection;

use Tribe__Tickets_Plus__Commerce__WooCommerce__Main as WOO;
use WPGraphQL\Connection\PostObjects;

/**
* Class - WooAttendees
*/
class WooAttendees extends PostObjects {
/**
* Registers the various connections from other Types to Attendees
*/
public static function register_connections() {
// From Event to Attendees.
register_graphql_connection(
self::get_connection_config(
get_post_type_object( WOO::ATTENDEE_OBJECT ),
array(
'fromType' => 'Event',
'toType' => 'WooAttendee',
'fromFieldName' => 'wooAttendees',
)
justlevine marked this conversation as resolved.
Show resolved Hide resolved
)
);
}

public static function where_args() {
return array(
'eventsIn' => array(
'type' => array( 'list_of' => 'ID'),
'description' => __( 'Filter the connection based on event Id'),
)
);
justlevine marked this conversation as resolved.
Show resolved Hide resolved
}
}
112 changes: 112 additions & 0 deletions includes/data/connection/class-paypalattendee-connection-resolver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php
/**
* Connection resolver - PayPalAttendee
*
* Filters connections to Attendee type
*
* @package WPGraphQL\QL_Events\Data\Connection
* @since 0.0.1
*/

namespace WPGraphQL\QL_Events\Data\Connection;

use GraphQL\Type\Definition\ResolveInfo;
use Tribe__Events__Main as Main;
use Tribe__Tickets__Commerce__PayPal__Main as PAYPAL;
use WPGraphQL\AppContext;
use WPGraphQL\Model\Post;

/**
* Class PayPalAttendee_Connection_Resolver
*/
class PayPalAttendee_Connection_Resolver {
/**
* This prepares the $query_args for use in the connection query. This is where default $args are set, where dynamic
* $args from the $this->source get set, and where mapping the input $args to the actual $query_args occurs.
*
* @param array $query_args - WP_Query args.
* @param mixed $source - Connection parent resolver.
* @param array $args - Connection arguments.
* @param AppContext $context - AppContext object.
* @param ResolveInfo $info - ResolveInfo object.
*
* @return mixed
*/
public static function get_query_args( $query_args, $source, $args, $context, $info ) {

/**
* Collect the input_fields and sanitize them to prepare them for sending to the WP_Query
*/
$input_fields = array();
if ( ! empty( $args['where'] ) ) {
$input_fields = self::sanitize_input_fields( $args['where'] );
}

if ( ! empty( $input_fields ) ) {
$query_args = array_merge( $query_args, $input_fields );
}

// Determine where we're at in the Graph and adjust the query context appropriately.
// @Todo: this was left over from class-attendee-connection-resolver.php which wasnt loaded. May not be necessary.
if ( true === is_object( $source ) ) {

switch ( $source->post_type ) {
case Main::POSTTYPE:
// @codingStandardsIgnoreLine
if ( 'payPalAttendees' === $info->fieldName ) {
if ( ! isset( $query_args['meta_query'] ) ) {
$query_args['meta_query'] = array(); // WPCS: slow query ok.
justlevine marked this conversation as resolved.
Show resolved Hide resolved
}
$query_args['meta_query'][] = array(
'key' => PAYPAL::ATTENDEE_EVENT_KEY,
'value' => $source->ID,
'compare' => '=',
);
justlevine marked this conversation as resolved.
Show resolved Hide resolved
}
break;
}
// @codingStandardsIgnoreLine

}

$query_args = apply_filters(
'graphql_paypal_attendee_connection_query_args',
$query_args,
$source,
$args,
$context,
$info
);

return $query_args;
}

/**
* This sets up the "allowed" args, and translates the GraphQL-friendly keys to WP_Query
* friendly keys. There's probably a cleaner/more dynamic way to approach this, but
* this was quick. I'd be down to explore more dynamic ways to map this, but for
* now this gets the job done.
*
* @since 0.0.5
* @access private
*
* @param array $args Where argument input.
*
* @return array
*/

private static function sanitize_input_fields( $args ){
$query_args = array();

if ( !empty( $args['eventsIn'])){
$query_args['meta_query'] = array(); // WPCS: slow query ok.
$query_args['meta_query'][] = array(
'key' => PAYPAL::ATTENDEE_EVENT_KEY,
'value' => $args['eventsIn'],
'compare' => 'IN',
);
}
Comment on lines +101 to +108
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if ( !empty( $args['eventsIn'])){
$query_args['meta_query'] = array(); // WPCS: slow query ok.
$query_args['meta_query'][] = array(
'key' => PAYPAL::ATTENDEE_EVENT_KEY,
'value' => $args['eventsIn'],
'compare' => 'IN',
);
}
if ( ! empty( $args['eventsIn'] ) ) {
$query_args['meta_query'] = []; // WPCS: slow query ok.
$query_args['meta_query'][] = [
'key' => PAYPAL::ATTENDEE_EVENT_KEY,
'value' => $args['eventsIn'],
'compare' => 'IN',
];
}


return $query_args;
}
}
Loading