@@ -3,7 +3,6 @@ |
||
| 3 | 3 | namespace EventEspresso\core\domain\services\admin\events\editor; |
| 4 | 4 | |
| 5 | 5 | use EE_Error; |
| 6 | -use EEM_Price; |
|
| 7 | 6 | use EventEspresso\core\domain\entities\admin\GraphQLData\Datetimes; |
| 8 | 7 | use EventEspresso\core\domain\entities\admin\GraphQLData\Prices; |
| 9 | 8 | use EventEspresso\core\domain\entities\admin\GraphQLData\PriceTypes; |
@@ -21,108 +21,108 @@ |
||
| 21 | 21 | class EventEditorGraphQLData |
| 22 | 22 | { |
| 23 | 23 | |
| 24 | - /** |
|
| 25 | - * @var Datetimes $datetimes |
|
| 26 | - */ |
|
| 27 | - protected $datetimes; |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * @var Prices $prices |
|
| 31 | - */ |
|
| 32 | - protected $prices; |
|
| 33 | - |
|
| 34 | - /** |
|
| 35 | - * @var PriceTypes $price_types |
|
| 36 | - */ |
|
| 37 | - protected $price_types; |
|
| 38 | - |
|
| 39 | - /** |
|
| 40 | - * @var Tickets $tickets |
|
| 41 | - */ |
|
| 42 | - protected $tickets; |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * @var EventEntityRelations $relations |
|
| 46 | - */ |
|
| 47 | - protected $relations; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * @var NewEventDefaultEntities $default_entities |
|
| 51 | - */ |
|
| 52 | - protected $default_entities; |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * EventEditorGraphQLData constructor. |
|
| 57 | - * |
|
| 58 | - * @param Datetimes $datetimes |
|
| 59 | - * @param Prices $prices |
|
| 60 | - * @param PriceTypes $price_types |
|
| 61 | - * @param Tickets $tickets |
|
| 62 | - * @param EventEntityRelations $relations |
|
| 63 | - * @param NewEventDefaultEntities $default_entities |
|
| 64 | - */ |
|
| 65 | - public function __construct( |
|
| 66 | - Datetimes $datetimes, |
|
| 67 | - Prices $prices, |
|
| 68 | - PriceTypes $price_types, |
|
| 69 | - Tickets $tickets, |
|
| 70 | - EventEntityRelations $relations, |
|
| 71 | - NewEventDefaultEntities $default_entities |
|
| 72 | - ) { |
|
| 73 | - $this->datetimes = $datetimes; |
|
| 74 | - $this->default_entities = $default_entities; |
|
| 75 | - $this->prices = $prices; |
|
| 76 | - $this->price_types = $price_types; |
|
| 77 | - $this->relations = $relations; |
|
| 78 | - $this->tickets = $tickets; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * @param int $eventId |
|
| 84 | - * @return array |
|
| 85 | - * @throws EE_Error |
|
| 86 | - * @throws ReflectionException |
|
| 87 | - * @since $VID:$ |
|
| 88 | - */ |
|
| 89 | - public function getData($eventId) |
|
| 90 | - { |
|
| 91 | - $datetimes = $this->datetimes->getData(['eventId' => $eventId]); |
|
| 92 | - |
|
| 93 | - // Avoid undefined variable warning in PHP >= 7.3 |
|
| 94 | - $tickets = null; |
|
| 95 | - $prices = null; |
|
| 96 | - |
|
| 97 | - if (empty($datetimes['nodes']) || (isset($_REQUEST['action']) && $_REQUEST['action'] === 'create_new')) { |
|
| 98 | - $this->default_entities->getData($eventId); |
|
| 99 | - $datetimes = $this->datetimes->getData(['eventId' => $eventId]); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - if (! empty($datetimes['nodes'])) { |
|
| 103 | - $datetimeIn = wp_list_pluck($datetimes['nodes'], 'id'); |
|
| 104 | - |
|
| 105 | - if (! empty($datetimeIn)) { |
|
| 106 | - $tickets = $this->tickets->getData(['datetimeIn' => $datetimeIn]); |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - if (! empty($tickets['nodes'])) { |
|
| 111 | - $ticketIn = wp_list_pluck($tickets['nodes'], 'id'); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - $pricesArgs = ['includeDefaultPrices' => true]; |
|
| 115 | - |
|
| 116 | - if (! empty($ticketIn)) { |
|
| 117 | - $pricesArgs['ticketIn'] = $ticketIn; |
|
| 118 | - } |
|
| 119 | - $prices = $this->prices->getData($pricesArgs); |
|
| 120 | - |
|
| 121 | - $priceTypes = $this->price_types->getData(); |
|
| 122 | - |
|
| 123 | - $relations = $this->relations->getData($eventId); |
|
| 124 | - |
|
| 125 | - |
|
| 126 | - return compact('datetimes', 'tickets', 'prices', 'priceTypes', 'relations'); |
|
| 127 | - } |
|
| 24 | + /** |
|
| 25 | + * @var Datetimes $datetimes |
|
| 26 | + */ |
|
| 27 | + protected $datetimes; |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * @var Prices $prices |
|
| 31 | + */ |
|
| 32 | + protected $prices; |
|
| 33 | + |
|
| 34 | + /** |
|
| 35 | + * @var PriceTypes $price_types |
|
| 36 | + */ |
|
| 37 | + protected $price_types; |
|
| 38 | + |
|
| 39 | + /** |
|
| 40 | + * @var Tickets $tickets |
|
| 41 | + */ |
|
| 42 | + protected $tickets; |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * @var EventEntityRelations $relations |
|
| 46 | + */ |
|
| 47 | + protected $relations; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * @var NewEventDefaultEntities $default_entities |
|
| 51 | + */ |
|
| 52 | + protected $default_entities; |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * EventEditorGraphQLData constructor. |
|
| 57 | + * |
|
| 58 | + * @param Datetimes $datetimes |
|
| 59 | + * @param Prices $prices |
|
| 60 | + * @param PriceTypes $price_types |
|
| 61 | + * @param Tickets $tickets |
|
| 62 | + * @param EventEntityRelations $relations |
|
| 63 | + * @param NewEventDefaultEntities $default_entities |
|
| 64 | + */ |
|
| 65 | + public function __construct( |
|
| 66 | + Datetimes $datetimes, |
|
| 67 | + Prices $prices, |
|
| 68 | + PriceTypes $price_types, |
|
| 69 | + Tickets $tickets, |
|
| 70 | + EventEntityRelations $relations, |
|
| 71 | + NewEventDefaultEntities $default_entities |
|
| 72 | + ) { |
|
| 73 | + $this->datetimes = $datetimes; |
|
| 74 | + $this->default_entities = $default_entities; |
|
| 75 | + $this->prices = $prices; |
|
| 76 | + $this->price_types = $price_types; |
|
| 77 | + $this->relations = $relations; |
|
| 78 | + $this->tickets = $tickets; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * @param int $eventId |
|
| 84 | + * @return array |
|
| 85 | + * @throws EE_Error |
|
| 86 | + * @throws ReflectionException |
|
| 87 | + * @since $VID:$ |
|
| 88 | + */ |
|
| 89 | + public function getData($eventId) |
|
| 90 | + { |
|
| 91 | + $datetimes = $this->datetimes->getData(['eventId' => $eventId]); |
|
| 92 | + |
|
| 93 | + // Avoid undefined variable warning in PHP >= 7.3 |
|
| 94 | + $tickets = null; |
|
| 95 | + $prices = null; |
|
| 96 | + |
|
| 97 | + if (empty($datetimes['nodes']) || (isset($_REQUEST['action']) && $_REQUEST['action'] === 'create_new')) { |
|
| 98 | + $this->default_entities->getData($eventId); |
|
| 99 | + $datetimes = $this->datetimes->getData(['eventId' => $eventId]); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + if (! empty($datetimes['nodes'])) { |
|
| 103 | + $datetimeIn = wp_list_pluck($datetimes['nodes'], 'id'); |
|
| 104 | + |
|
| 105 | + if (! empty($datetimeIn)) { |
|
| 106 | + $tickets = $this->tickets->getData(['datetimeIn' => $datetimeIn]); |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + if (! empty($tickets['nodes'])) { |
|
| 111 | + $ticketIn = wp_list_pluck($tickets['nodes'], 'id'); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + $pricesArgs = ['includeDefaultPrices' => true]; |
|
| 115 | + |
|
| 116 | + if (! empty($ticketIn)) { |
|
| 117 | + $pricesArgs['ticketIn'] = $ticketIn; |
|
| 118 | + } |
|
| 119 | + $prices = $this->prices->getData($pricesArgs); |
|
| 120 | + |
|
| 121 | + $priceTypes = $this->price_types->getData(); |
|
| 122 | + |
|
| 123 | + $relations = $this->relations->getData($eventId); |
|
| 124 | + |
|
| 125 | + |
|
| 126 | + return compact('datetimes', 'tickets', 'prices', 'priceTypes', 'relations'); |
|
| 127 | + } |
|
| 128 | 128 | } |
@@ -99,21 +99,21 @@ |
||
| 99 | 99 | $datetimes = $this->datetimes->getData(['eventId' => $eventId]); |
| 100 | 100 | } |
| 101 | 101 | |
| 102 | - if (! empty($datetimes['nodes'])) { |
|
| 102 | + if ( ! empty($datetimes['nodes'])) { |
|
| 103 | 103 | $datetimeIn = wp_list_pluck($datetimes['nodes'], 'id'); |
| 104 | 104 | |
| 105 | - if (! empty($datetimeIn)) { |
|
| 105 | + if ( ! empty($datetimeIn)) { |
|
| 106 | 106 | $tickets = $this->tickets->getData(['datetimeIn' => $datetimeIn]); |
| 107 | 107 | } |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | - if (! empty($tickets['nodes'])) { |
|
| 110 | + if ( ! empty($tickets['nodes'])) { |
|
| 111 | 111 | $ticketIn = wp_list_pluck($tickets['nodes'], 'id'); |
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | $pricesArgs = ['includeDefaultPrices' => true]; |
| 115 | 115 | |
| 116 | - if (! empty($ticketIn)) { |
|
| 116 | + if ( ! empty($ticketIn)) { |
|
| 117 | 117 | $pricesArgs['ticketIn'] = $ticketIn; |
| 118 | 118 | } |
| 119 | 119 | $prices = $this->prices->getData($pricesArgs); |
@@ -15,180 +15,180 @@ |
||
| 15 | 15 | */ |
| 16 | 16 | class PriceConnectionResolver extends AbstractConnectionResolver |
| 17 | 17 | { |
| 18 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 19 | - public function get_loader_name() |
|
| 20 | - { |
|
| 21 | - return 'espresso_price'; |
|
| 22 | - } |
|
| 23 | - |
|
| 24 | - /** |
|
| 25 | - * @return EEM_Price |
|
| 26 | - * @throws EE_Error |
|
| 27 | - * @throws InvalidArgumentException |
|
| 28 | - * @throws InvalidDataTypeException |
|
| 29 | - * @throws InvalidInterfaceException |
|
| 30 | - */ |
|
| 31 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 32 | - public function get_query() |
|
| 33 | - { |
|
| 34 | - return EEM_Price::instance(); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Return an array of item IDs from the query |
|
| 40 | - * |
|
| 41 | - * @return array |
|
| 42 | - */ |
|
| 43 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 44 | - public function get_ids() |
|
| 45 | - { |
|
| 46 | - $results = $this->query->get_col($this->query_args); |
|
| 47 | - |
|
| 48 | - return ! empty($results) ? $results : []; |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * Determine whether the Query should execute. If it's determined that the query should |
|
| 54 | - * not be run based on context such as, but not limited to, who the user is, where in the |
|
| 55 | - * ResolveTree the Query is, the relation to the node the Query is connected to, etc |
|
| 56 | - * Return false to prevent the query from executing. |
|
| 57 | - * |
|
| 58 | - * @return bool |
|
| 59 | - */ |
|
| 60 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 61 | - public function should_execute() |
|
| 62 | - { |
|
| 63 | - if ($this->should_execute === false) { |
|
| 64 | - return false; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - return $this->should_execute; |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - |
|
| 71 | - /** |
|
| 72 | - * Here, we map the args from the input, then we make sure that we're only querying |
|
| 73 | - * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers |
|
| 74 | - * handle batch resolution of the posts. |
|
| 75 | - * |
|
| 76 | - * @return array |
|
| 77 | - * @throws EE_Error |
|
| 78 | - * @throws InvalidArgumentException |
|
| 79 | - * @throws ReflectionException |
|
| 80 | - * @throws InvalidDataTypeException |
|
| 81 | - * @throws InvalidInterfaceException |
|
| 82 | - */ |
|
| 83 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 84 | - public function get_query_args() |
|
| 85 | - { |
|
| 86 | - $where_params = []; |
|
| 87 | - $query_args = []; |
|
| 88 | - |
|
| 89 | - $query_args['limit'] = $this->getLimit(); |
|
| 90 | - |
|
| 91 | - // Avoid multiple entries by join. |
|
| 92 | - $query_args['group_by'] = 'PRC_ID'; |
|
| 93 | - |
|
| 94 | - $query_args['default_where_conditions'] = 'minimum'; |
|
| 95 | - |
|
| 96 | - /** |
|
| 97 | - * Collect the input_fields and sanitize them to prepare them for sending to the Query |
|
| 98 | - */ |
|
| 99 | - $input_fields = []; |
|
| 100 | - if (! empty($this->args['where'])) { |
|
| 101 | - $input_fields = $this->sanitizeInputFields($this->args['where']); |
|
| 102 | - |
|
| 103 | - // Use the proper operator. |
|
| 104 | - if (! empty($input_fields['PRC_ID']) && is_array($input_fields['PRC_ID'])) { |
|
| 105 | - $input_fields['PRC_ID'] = ['in', $input_fields['PRC_ID']]; |
|
| 106 | - } |
|
| 107 | - if (! empty($input_fields['Ticket.TKT_ID']) && is_array($input_fields['Ticket.TKT_ID'])) { |
|
| 108 | - $input_fields['Ticket.TKT_ID'] = ['in', $input_fields['Ticket.TKT_ID']]; |
|
| 109 | - } |
|
| 110 | - if (! empty($input_fields['Price_Type.PBT_ID']) && is_array($input_fields['Price_Type.PBT_ID'])) { |
|
| 111 | - $input_fields['Price_Type.PBT_ID'] = ['in', $input_fields['Price_Type.PBT_ID']]; |
|
| 112 | - } |
|
| 113 | - if (! empty($input_fields['Price_Type.PRT_ID']) && is_array($input_fields['Price_Type.PRT_ID'])) { |
|
| 114 | - $input_fields['Price_Type.PRT_ID'] = ['in', $input_fields['Price_Type.PRT_ID']]; |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Determine where we're at in the Graph and adjust the query context appropriately. |
|
| 120 | - */ |
|
| 121 | - if ($this->source instanceof EE_Ticket) { |
|
| 122 | - $where_params['Ticket.TKT_ID'] = $this->source->ID(); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - /** |
|
| 126 | - * Merge the input_fields with the default query_args |
|
| 127 | - */ |
|
| 128 | - if (! empty($input_fields)) { |
|
| 129 | - $where_params = array_merge($where_params, $input_fields); |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - list($query_args, $where_params) = $this->mapOrderbyInputArgs($query_args, $where_params, 'PRC_ID'); |
|
| 133 | - |
|
| 134 | - // If default prices should be included. |
|
| 135 | - if (! empty($this->args['where']['includeDefaultPrices'])) { |
|
| 136 | - /** |
|
| 137 | - * We need to get each price that |
|
| 138 | - * - satisfies $where_params above |
|
| 139 | - * OR |
|
| 140 | - * - it's a default non trashed price |
|
| 141 | - */ |
|
| 142 | - $where_params = [ |
|
| 143 | - 'OR' => [ |
|
| 144 | - // use extra OR instead of AND to avoid it getting overridden |
|
| 145 | - 'OR' => [ |
|
| 146 | - 'AND' => [ |
|
| 147 | - 'PRC_deleted' => 0, |
|
| 148 | - 'PRC_is_default' => 1, |
|
| 149 | - ] |
|
| 150 | - ], |
|
| 151 | - 'AND' => $where_params, |
|
| 152 | - ], |
|
| 153 | - ]; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - $query_args[] = $where_params; |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * Return the $query_args |
|
| 160 | - */ |
|
| 161 | - return $query_args; |
|
| 162 | - } |
|
| 163 | - |
|
| 164 | - |
|
| 165 | - /** |
|
| 166 | - * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model |
|
| 167 | - * friendly keys. |
|
| 168 | - * |
|
| 169 | - * @param array $where_args |
|
| 170 | - * @return array |
|
| 171 | - */ |
|
| 172 | - public function sanitizeInputFields(array $where_args) |
|
| 173 | - { |
|
| 174 | - $arg_mapping = [ |
|
| 175 | - 'in' => 'PRC_ID', |
|
| 176 | - 'idIn' => 'PRC_ID', |
|
| 177 | - 'ticket' => 'Ticket.TKT_ID', |
|
| 178 | - 'ticketIn' => 'Ticket.TKT_ID', |
|
| 179 | - 'ticketIdIn' => 'Ticket.TKT_ID', |
|
| 180 | - 'ticketId' => 'Ticket.TKT_ID', // priority. |
|
| 181 | - 'priceType' => 'Price_Type.PRT_ID', |
|
| 182 | - 'priceTypeIn' => 'Price_Type.PRT_ID', |
|
| 183 | - 'priceTypeIdIn' => 'Price_Type.PRT_ID', |
|
| 184 | - 'priceTypeId' => 'Price_Type.PRT_ID', // priority. |
|
| 185 | - 'priceBaseType' => 'Price_Type.PBT_ID', |
|
| 186 | - 'priceBaseTypeIn' => 'Price_Type.PBT_ID', |
|
| 187 | - ]; |
|
| 188 | - return $this->sanitizeWhereArgsForInputFields( |
|
| 189 | - $where_args, |
|
| 190 | - $arg_mapping, |
|
| 191 | - ['in', 'ticket', 'ticketIn', 'priceType', 'priceTypeIn'] |
|
| 192 | - ); |
|
| 193 | - } |
|
| 18 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 19 | + public function get_loader_name() |
|
| 20 | + { |
|
| 21 | + return 'espresso_price'; |
|
| 22 | + } |
|
| 23 | + |
|
| 24 | + /** |
|
| 25 | + * @return EEM_Price |
|
| 26 | + * @throws EE_Error |
|
| 27 | + * @throws InvalidArgumentException |
|
| 28 | + * @throws InvalidDataTypeException |
|
| 29 | + * @throws InvalidInterfaceException |
|
| 30 | + */ |
|
| 31 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 32 | + public function get_query() |
|
| 33 | + { |
|
| 34 | + return EEM_Price::instance(); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Return an array of item IDs from the query |
|
| 40 | + * |
|
| 41 | + * @return array |
|
| 42 | + */ |
|
| 43 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 44 | + public function get_ids() |
|
| 45 | + { |
|
| 46 | + $results = $this->query->get_col($this->query_args); |
|
| 47 | + |
|
| 48 | + return ! empty($results) ? $results : []; |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * Determine whether the Query should execute. If it's determined that the query should |
|
| 54 | + * not be run based on context such as, but not limited to, who the user is, where in the |
|
| 55 | + * ResolveTree the Query is, the relation to the node the Query is connected to, etc |
|
| 56 | + * Return false to prevent the query from executing. |
|
| 57 | + * |
|
| 58 | + * @return bool |
|
| 59 | + */ |
|
| 60 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 61 | + public function should_execute() |
|
| 62 | + { |
|
| 63 | + if ($this->should_execute === false) { |
|
| 64 | + return false; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + return $this->should_execute; |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + |
|
| 71 | + /** |
|
| 72 | + * Here, we map the args from the input, then we make sure that we're only querying |
|
| 73 | + * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers |
|
| 74 | + * handle batch resolution of the posts. |
|
| 75 | + * |
|
| 76 | + * @return array |
|
| 77 | + * @throws EE_Error |
|
| 78 | + * @throws InvalidArgumentException |
|
| 79 | + * @throws ReflectionException |
|
| 80 | + * @throws InvalidDataTypeException |
|
| 81 | + * @throws InvalidInterfaceException |
|
| 82 | + */ |
|
| 83 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 84 | + public function get_query_args() |
|
| 85 | + { |
|
| 86 | + $where_params = []; |
|
| 87 | + $query_args = []; |
|
| 88 | + |
|
| 89 | + $query_args['limit'] = $this->getLimit(); |
|
| 90 | + |
|
| 91 | + // Avoid multiple entries by join. |
|
| 92 | + $query_args['group_by'] = 'PRC_ID'; |
|
| 93 | + |
|
| 94 | + $query_args['default_where_conditions'] = 'minimum'; |
|
| 95 | + |
|
| 96 | + /** |
|
| 97 | + * Collect the input_fields and sanitize them to prepare them for sending to the Query |
|
| 98 | + */ |
|
| 99 | + $input_fields = []; |
|
| 100 | + if (! empty($this->args['where'])) { |
|
| 101 | + $input_fields = $this->sanitizeInputFields($this->args['where']); |
|
| 102 | + |
|
| 103 | + // Use the proper operator. |
|
| 104 | + if (! empty($input_fields['PRC_ID']) && is_array($input_fields['PRC_ID'])) { |
|
| 105 | + $input_fields['PRC_ID'] = ['in', $input_fields['PRC_ID']]; |
|
| 106 | + } |
|
| 107 | + if (! empty($input_fields['Ticket.TKT_ID']) && is_array($input_fields['Ticket.TKT_ID'])) { |
|
| 108 | + $input_fields['Ticket.TKT_ID'] = ['in', $input_fields['Ticket.TKT_ID']]; |
|
| 109 | + } |
|
| 110 | + if (! empty($input_fields['Price_Type.PBT_ID']) && is_array($input_fields['Price_Type.PBT_ID'])) { |
|
| 111 | + $input_fields['Price_Type.PBT_ID'] = ['in', $input_fields['Price_Type.PBT_ID']]; |
|
| 112 | + } |
|
| 113 | + if (! empty($input_fields['Price_Type.PRT_ID']) && is_array($input_fields['Price_Type.PRT_ID'])) { |
|
| 114 | + $input_fields['Price_Type.PRT_ID'] = ['in', $input_fields['Price_Type.PRT_ID']]; |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Determine where we're at in the Graph and adjust the query context appropriately. |
|
| 120 | + */ |
|
| 121 | + if ($this->source instanceof EE_Ticket) { |
|
| 122 | + $where_params['Ticket.TKT_ID'] = $this->source->ID(); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + /** |
|
| 126 | + * Merge the input_fields with the default query_args |
|
| 127 | + */ |
|
| 128 | + if (! empty($input_fields)) { |
|
| 129 | + $where_params = array_merge($where_params, $input_fields); |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + list($query_args, $where_params) = $this->mapOrderbyInputArgs($query_args, $where_params, 'PRC_ID'); |
|
| 133 | + |
|
| 134 | + // If default prices should be included. |
|
| 135 | + if (! empty($this->args['where']['includeDefaultPrices'])) { |
|
| 136 | + /** |
|
| 137 | + * We need to get each price that |
|
| 138 | + * - satisfies $where_params above |
|
| 139 | + * OR |
|
| 140 | + * - it's a default non trashed price |
|
| 141 | + */ |
|
| 142 | + $where_params = [ |
|
| 143 | + 'OR' => [ |
|
| 144 | + // use extra OR instead of AND to avoid it getting overridden |
|
| 145 | + 'OR' => [ |
|
| 146 | + 'AND' => [ |
|
| 147 | + 'PRC_deleted' => 0, |
|
| 148 | + 'PRC_is_default' => 1, |
|
| 149 | + ] |
|
| 150 | + ], |
|
| 151 | + 'AND' => $where_params, |
|
| 152 | + ], |
|
| 153 | + ]; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + $query_args[] = $where_params; |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * Return the $query_args |
|
| 160 | + */ |
|
| 161 | + return $query_args; |
|
| 162 | + } |
|
| 163 | + |
|
| 164 | + |
|
| 165 | + /** |
|
| 166 | + * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model |
|
| 167 | + * friendly keys. |
|
| 168 | + * |
|
| 169 | + * @param array $where_args |
|
| 170 | + * @return array |
|
| 171 | + */ |
|
| 172 | + public function sanitizeInputFields(array $where_args) |
|
| 173 | + { |
|
| 174 | + $arg_mapping = [ |
|
| 175 | + 'in' => 'PRC_ID', |
|
| 176 | + 'idIn' => 'PRC_ID', |
|
| 177 | + 'ticket' => 'Ticket.TKT_ID', |
|
| 178 | + 'ticketIn' => 'Ticket.TKT_ID', |
|
| 179 | + 'ticketIdIn' => 'Ticket.TKT_ID', |
|
| 180 | + 'ticketId' => 'Ticket.TKT_ID', // priority. |
|
| 181 | + 'priceType' => 'Price_Type.PRT_ID', |
|
| 182 | + 'priceTypeIn' => 'Price_Type.PRT_ID', |
|
| 183 | + 'priceTypeIdIn' => 'Price_Type.PRT_ID', |
|
| 184 | + 'priceTypeId' => 'Price_Type.PRT_ID', // priority. |
|
| 185 | + 'priceBaseType' => 'Price_Type.PBT_ID', |
|
| 186 | + 'priceBaseTypeIn' => 'Price_Type.PBT_ID', |
|
| 187 | + ]; |
|
| 188 | + return $this->sanitizeWhereArgsForInputFields( |
|
| 189 | + $where_args, |
|
| 190 | + $arg_mapping, |
|
| 191 | + ['in', 'ticket', 'ticketIn', 'priceType', 'priceTypeIn'] |
|
| 192 | + ); |
|
| 193 | + } |
|
| 194 | 194 | } |
@@ -97,20 +97,20 @@ discard block |
||
| 97 | 97 | * Collect the input_fields and sanitize them to prepare them for sending to the Query |
| 98 | 98 | */ |
| 99 | 99 | $input_fields = []; |
| 100 | - if (! empty($this->args['where'])) { |
|
| 100 | + if ( ! empty($this->args['where'])) { |
|
| 101 | 101 | $input_fields = $this->sanitizeInputFields($this->args['where']); |
| 102 | 102 | |
| 103 | 103 | // Use the proper operator. |
| 104 | - if (! empty($input_fields['PRC_ID']) && is_array($input_fields['PRC_ID'])) { |
|
| 104 | + if ( ! empty($input_fields['PRC_ID']) && is_array($input_fields['PRC_ID'])) { |
|
| 105 | 105 | $input_fields['PRC_ID'] = ['in', $input_fields['PRC_ID']]; |
| 106 | 106 | } |
| 107 | - if (! empty($input_fields['Ticket.TKT_ID']) && is_array($input_fields['Ticket.TKT_ID'])) { |
|
| 107 | + if ( ! empty($input_fields['Ticket.TKT_ID']) && is_array($input_fields['Ticket.TKT_ID'])) { |
|
| 108 | 108 | $input_fields['Ticket.TKT_ID'] = ['in', $input_fields['Ticket.TKT_ID']]; |
| 109 | 109 | } |
| 110 | - if (! empty($input_fields['Price_Type.PBT_ID']) && is_array($input_fields['Price_Type.PBT_ID'])) { |
|
| 110 | + if ( ! empty($input_fields['Price_Type.PBT_ID']) && is_array($input_fields['Price_Type.PBT_ID'])) { |
|
| 111 | 111 | $input_fields['Price_Type.PBT_ID'] = ['in', $input_fields['Price_Type.PBT_ID']]; |
| 112 | 112 | } |
| 113 | - if (! empty($input_fields['Price_Type.PRT_ID']) && is_array($input_fields['Price_Type.PRT_ID'])) { |
|
| 113 | + if ( ! empty($input_fields['Price_Type.PRT_ID']) && is_array($input_fields['Price_Type.PRT_ID'])) { |
|
| 114 | 114 | $input_fields['Price_Type.PRT_ID'] = ['in', $input_fields['Price_Type.PRT_ID']]; |
| 115 | 115 | } |
| 116 | 116 | } |
@@ -125,14 +125,14 @@ discard block |
||
| 125 | 125 | /** |
| 126 | 126 | * Merge the input_fields with the default query_args |
| 127 | 127 | */ |
| 128 | - if (! empty($input_fields)) { |
|
| 128 | + if ( ! empty($input_fields)) { |
|
| 129 | 129 | $where_params = array_merge($where_params, $input_fields); |
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | list($query_args, $where_params) = $this->mapOrderbyInputArgs($query_args, $where_params, 'PRC_ID'); |
| 133 | 133 | |
| 134 | 134 | // If default prices should be included. |
| 135 | - if (! empty($this->args['where']['includeDefaultPrices'])) { |
|
| 135 | + if ( ! empty($this->args['where']['includeDefaultPrices'])) { |
|
| 136 | 136 | /** |
| 137 | 137 | * We need to get each price that |
| 138 | 138 | * - satisfies $where_params above |
@@ -17,168 +17,168 @@ |
||
| 17 | 17 | abstract class AbstractConnectionResolver extends WPGraphQLConnectionResolver |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * Set limit the highest value of first and last, with a (filterable) max of 100 |
|
| 22 | - * |
|
| 23 | - * @return array |
|
| 24 | - */ |
|
| 25 | - protected function getLimit() |
|
| 26 | - { |
|
| 27 | - $first = ! empty($this->args['first']) ? absint($this->args['first']) : null; |
|
| 28 | - $last = ! empty($this->args['last']) ? absint($this->args['last']) : null; |
|
| 29 | - |
|
| 30 | - $limit = min( |
|
| 31 | - max($first, $last, 100), |
|
| 32 | - $this->query_amount |
|
| 33 | - ); |
|
| 34 | - $limit++; |
|
| 35 | - return $limit; |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - /** |
|
| 39 | - * Get_amount_requested |
|
| 40 | - * |
|
| 41 | - * This checks the $args to determine the amount requested |
|
| 42 | - * |
|
| 43 | - * @return int|null |
|
| 44 | - * @throws \Exception |
|
| 45 | - */ |
|
| 46 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 47 | - public function get_amount_requested() |
|
| 48 | - { |
|
| 49 | - $amount_requested = parent::get_amount_requested(); |
|
| 50 | - |
|
| 51 | - /** |
|
| 52 | - * If both first & last are used in the input args, throw an exception as that won't |
|
| 53 | - * work properly |
|
| 54 | - */ |
|
| 55 | - if (empty($this->args['first']) && empty($this->args['last']) && $amount_requested === 10) { |
|
| 56 | - return 100; // default. |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - return $amount_requested; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - /** |
|
| 63 | - * Determine whether or not the the offset is valid, i.e the entity corresponding to the |
|
| 64 | - * offset exists. Offset is equivalent to entity ID. So this function is equivalent to |
|
| 65 | - * checking if the entity with the given ID exists. |
|
| 66 | - * |
|
| 67 | - * @access public |
|
| 68 | - * |
|
| 69 | - * @param int $offset The ID of the node used for the cursor offset |
|
| 70 | - * |
|
| 71 | - * @return bool |
|
| 72 | - */ |
|
| 73 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 74 | - public function is_valid_offset($offset) |
|
| 75 | - { |
|
| 76 | - $entity = $this->get_query()->get_one_by_ID($offset); |
|
| 20 | + /** |
|
| 21 | + * Set limit the highest value of first and last, with a (filterable) max of 100 |
|
| 22 | + * |
|
| 23 | + * @return array |
|
| 24 | + */ |
|
| 25 | + protected function getLimit() |
|
| 26 | + { |
|
| 27 | + $first = ! empty($this->args['first']) ? absint($this->args['first']) : null; |
|
| 28 | + $last = ! empty($this->args['last']) ? absint($this->args['last']) : null; |
|
| 29 | + |
|
| 30 | + $limit = min( |
|
| 31 | + max($first, $last, 100), |
|
| 32 | + $this->query_amount |
|
| 33 | + ); |
|
| 34 | + $limit++; |
|
| 35 | + return $limit; |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + /** |
|
| 39 | + * Get_amount_requested |
|
| 40 | + * |
|
| 41 | + * This checks the $args to determine the amount requested |
|
| 42 | + * |
|
| 43 | + * @return int|null |
|
| 44 | + * @throws \Exception |
|
| 45 | + */ |
|
| 46 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 47 | + public function get_amount_requested() |
|
| 48 | + { |
|
| 49 | + $amount_requested = parent::get_amount_requested(); |
|
| 50 | + |
|
| 51 | + /** |
|
| 52 | + * If both first & last are used in the input args, throw an exception as that won't |
|
| 53 | + * work properly |
|
| 54 | + */ |
|
| 55 | + if (empty($this->args['first']) && empty($this->args['last']) && $amount_requested === 10) { |
|
| 56 | + return 100; // default. |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + return $amount_requested; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + /** |
|
| 63 | + * Determine whether or not the the offset is valid, i.e the entity corresponding to the |
|
| 64 | + * offset exists. Offset is equivalent to entity ID. So this function is equivalent to |
|
| 65 | + * checking if the entity with the given ID exists. |
|
| 66 | + * |
|
| 67 | + * @access public |
|
| 68 | + * |
|
| 69 | + * @param int $offset The ID of the node used for the cursor offset |
|
| 70 | + * |
|
| 71 | + * @return bool |
|
| 72 | + */ |
|
| 73 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 74 | + public function is_valid_offset($offset) |
|
| 75 | + { |
|
| 76 | + $entity = $this->get_query()->get_one_by_ID($offset); |
|
| 77 | 77 | |
| 78 | - return $entity instanceof EE_Base_Class; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Validates Model. |
|
| 83 | - * |
|
| 84 | - * @param array $entity Entity node. |
|
| 85 | - * |
|
| 86 | - * @return bool |
|
| 87 | - */ |
|
| 88 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 89 | - protected function is_valid_model($entity) |
|
| 90 | - { |
|
| 91 | - return $entity instanceof EE_Base_Class; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - |
|
| 95 | - /** |
|
| 96 | - * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model |
|
| 97 | - * friendly keys. |
|
| 98 | - * |
|
| 99 | - * @param array $query_args |
|
| 100 | - * @param array $where_params |
|
| 101 | - * @param string $primary_key |
|
| 102 | - * @return array |
|
| 103 | - */ |
|
| 104 | - protected function mapOrderbyInputArgs(array $query_args, array $where_params, $primary_key) |
|
| 105 | - { |
|
| 106 | - // ID of the current offset |
|
| 107 | - $offset = $this->get_offset(); |
|
| 108 | - /** |
|
| 109 | - * Map the orderby inputArgs to the WP_Query |
|
| 110 | - */ |
|
| 111 | - if (! empty($this->args['where']['orderby']) && is_array($this->args['where']['orderby'])) { |
|
| 112 | - $query_args['order_by'] = []; |
|
| 113 | - foreach ($this->args['where']['orderby'] as $orderby_input) { |
|
| 114 | - $query_args['order_by'][ $orderby_input['field'] ] = $orderby_input['order']; |
|
| 115 | - } |
|
| 116 | - } elseif ($offset) { |
|
| 117 | - $compare = $this->args['last'] ? '<' : '>'; |
|
| 118 | - $where_params[ $primary_key ] = [ $compare, $offset ]; |
|
| 119 | - } |
|
| 120 | - return [ $query_args, $where_params ]; |
|
| 121 | - } |
|
| 122 | - |
|
| 123 | - |
|
| 124 | - /** |
|
| 125 | - * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model |
|
| 126 | - * friendly keys. |
|
| 127 | - * |
|
| 128 | - * @param array $where_args |
|
| 129 | - * @param array $arg_mapping |
|
| 130 | - * @param array $id_fields The fields to convert from global IDs to DB IDs. |
|
| 131 | - * @return array |
|
| 132 | - */ |
|
| 133 | - protected function sanitizeWhereArgsForInputFields( |
|
| 134 | - array $where_args, |
|
| 135 | - array $arg_mapping, |
|
| 136 | - array $id_fields |
|
| 137 | - ) { |
|
| 138 | - $query_args = []; |
|
| 139 | - |
|
| 140 | - foreach ($where_args as $arg => $value) { |
|
| 141 | - if (! array_key_exists($arg, $arg_mapping)) { |
|
| 142 | - continue; |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - if (is_array($value) && ! empty($value)) { |
|
| 146 | - $value = array_map( |
|
| 147 | - static function ($value) { |
|
| 148 | - if (is_string($value)) { |
|
| 149 | - $value = sanitize_text_field($value); |
|
| 150 | - } |
|
| 151 | - return $value; |
|
| 152 | - }, |
|
| 153 | - $value |
|
| 154 | - ); |
|
| 155 | - } elseif (is_string($value)) { |
|
| 156 | - $value = sanitize_text_field($value); |
|
| 157 | - } |
|
| 158 | - $query_args[ $arg_mapping[ $arg ] ] = in_array($arg, $id_fields, true) |
|
| 159 | - ? $this->convertGlobalId($value) |
|
| 160 | - : $value; |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * Return the Query Args |
|
| 165 | - */ |
|
| 166 | - return ! empty($query_args) && is_array($query_args) ? $query_args : []; |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - |
|
| 170 | - /** |
|
| 171 | - * Converts global ID to DB ID. |
|
| 172 | - * |
|
| 173 | - * @param string|string[] $ID |
|
| 174 | - * @return mixed |
|
| 175 | - */ |
|
| 176 | - protected function convertGlobalId($ID) |
|
| 177 | - { |
|
| 178 | - if (is_array($ID)) { |
|
| 179 | - return array_map([ $this, 'convertGlobalId' ], $ID); |
|
| 180 | - } |
|
| 181 | - $parts = Relay::fromGlobalId($ID); |
|
| 182 | - return ! empty($parts['id']) ? $parts['id'] : null; |
|
| 183 | - } |
|
| 78 | + return $entity instanceof EE_Base_Class; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Validates Model. |
|
| 83 | + * |
|
| 84 | + * @param array $entity Entity node. |
|
| 85 | + * |
|
| 86 | + * @return bool |
|
| 87 | + */ |
|
| 88 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 89 | + protected function is_valid_model($entity) |
|
| 90 | + { |
|
| 91 | + return $entity instanceof EE_Base_Class; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + |
|
| 95 | + /** |
|
| 96 | + * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model |
|
| 97 | + * friendly keys. |
|
| 98 | + * |
|
| 99 | + * @param array $query_args |
|
| 100 | + * @param array $where_params |
|
| 101 | + * @param string $primary_key |
|
| 102 | + * @return array |
|
| 103 | + */ |
|
| 104 | + protected function mapOrderbyInputArgs(array $query_args, array $where_params, $primary_key) |
|
| 105 | + { |
|
| 106 | + // ID of the current offset |
|
| 107 | + $offset = $this->get_offset(); |
|
| 108 | + /** |
|
| 109 | + * Map the orderby inputArgs to the WP_Query |
|
| 110 | + */ |
|
| 111 | + if (! empty($this->args['where']['orderby']) && is_array($this->args['where']['orderby'])) { |
|
| 112 | + $query_args['order_by'] = []; |
|
| 113 | + foreach ($this->args['where']['orderby'] as $orderby_input) { |
|
| 114 | + $query_args['order_by'][ $orderby_input['field'] ] = $orderby_input['order']; |
|
| 115 | + } |
|
| 116 | + } elseif ($offset) { |
|
| 117 | + $compare = $this->args['last'] ? '<' : '>'; |
|
| 118 | + $where_params[ $primary_key ] = [ $compare, $offset ]; |
|
| 119 | + } |
|
| 120 | + return [ $query_args, $where_params ]; |
|
| 121 | + } |
|
| 122 | + |
|
| 123 | + |
|
| 124 | + /** |
|
| 125 | + * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model |
|
| 126 | + * friendly keys. |
|
| 127 | + * |
|
| 128 | + * @param array $where_args |
|
| 129 | + * @param array $arg_mapping |
|
| 130 | + * @param array $id_fields The fields to convert from global IDs to DB IDs. |
|
| 131 | + * @return array |
|
| 132 | + */ |
|
| 133 | + protected function sanitizeWhereArgsForInputFields( |
|
| 134 | + array $where_args, |
|
| 135 | + array $arg_mapping, |
|
| 136 | + array $id_fields |
|
| 137 | + ) { |
|
| 138 | + $query_args = []; |
|
| 139 | + |
|
| 140 | + foreach ($where_args as $arg => $value) { |
|
| 141 | + if (! array_key_exists($arg, $arg_mapping)) { |
|
| 142 | + continue; |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + if (is_array($value) && ! empty($value)) { |
|
| 146 | + $value = array_map( |
|
| 147 | + static function ($value) { |
|
| 148 | + if (is_string($value)) { |
|
| 149 | + $value = sanitize_text_field($value); |
|
| 150 | + } |
|
| 151 | + return $value; |
|
| 152 | + }, |
|
| 153 | + $value |
|
| 154 | + ); |
|
| 155 | + } elseif (is_string($value)) { |
|
| 156 | + $value = sanitize_text_field($value); |
|
| 157 | + } |
|
| 158 | + $query_args[ $arg_mapping[ $arg ] ] = in_array($arg, $id_fields, true) |
|
| 159 | + ? $this->convertGlobalId($value) |
|
| 160 | + : $value; |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * Return the Query Args |
|
| 165 | + */ |
|
| 166 | + return ! empty($query_args) && is_array($query_args) ? $query_args : []; |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + |
|
| 170 | + /** |
|
| 171 | + * Converts global ID to DB ID. |
|
| 172 | + * |
|
| 173 | + * @param string|string[] $ID |
|
| 174 | + * @return mixed |
|
| 175 | + */ |
|
| 176 | + protected function convertGlobalId($ID) |
|
| 177 | + { |
|
| 178 | + if (is_array($ID)) { |
|
| 179 | + return array_map([ $this, 'convertGlobalId' ], $ID); |
|
| 180 | + } |
|
| 181 | + $parts = Relay::fromGlobalId($ID); |
|
| 182 | + return ! empty($parts['id']) ? $parts['id'] : null; |
|
| 183 | + } |
|
| 184 | 184 | } |
@@ -19,116 +19,116 @@ |
||
| 19 | 19 | { |
| 20 | 20 | |
| 21 | 21 | |
| 22 | - /** |
|
| 23 | - * TicketConnection constructor. |
|
| 24 | - * |
|
| 25 | - * @param EEM_Price $model |
|
| 26 | - */ |
|
| 27 | - public function __construct(EEM_Price $model) |
|
| 28 | - { |
|
| 29 | - $this->model = $model; |
|
| 30 | - } |
|
| 22 | + /** |
|
| 23 | + * TicketConnection constructor. |
|
| 24 | + * |
|
| 25 | + * @param EEM_Price $model |
|
| 26 | + */ |
|
| 27 | + public function __construct(EEM_Price $model) |
|
| 28 | + { |
|
| 29 | + $this->model = $model; |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | 32 | |
| 33 | - /** |
|
| 34 | - * @return array |
|
| 35 | - * @since $VID:$ |
|
| 36 | - */ |
|
| 37 | - public function config() |
|
| 38 | - { |
|
| 39 | - return [ |
|
| 40 | - 'fromType' => $this->namespace . 'Ticket', |
|
| 41 | - 'toType' => $this->namespace . 'Price', |
|
| 42 | - 'fromFieldName' => 'prices', |
|
| 43 | - 'connectionTypeName' => "{$this->namespace}TicketPricesConnection", |
|
| 44 | - 'connectionArgs' => TicketPricesConnection::get_connection_args(), |
|
| 45 | - 'resolve' => [$this, 'resolveConnection'], |
|
| 46 | - ]; |
|
| 47 | - } |
|
| 33 | + /** |
|
| 34 | + * @return array |
|
| 35 | + * @since $VID:$ |
|
| 36 | + */ |
|
| 37 | + public function config() |
|
| 38 | + { |
|
| 39 | + return [ |
|
| 40 | + 'fromType' => $this->namespace . 'Ticket', |
|
| 41 | + 'toType' => $this->namespace . 'Price', |
|
| 42 | + 'fromFieldName' => 'prices', |
|
| 43 | + 'connectionTypeName' => "{$this->namespace}TicketPricesConnection", |
|
| 44 | + 'connectionArgs' => TicketPricesConnection::get_connection_args(), |
|
| 45 | + 'resolve' => [$this, 'resolveConnection'], |
|
| 46 | + ]; |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | 49 | |
| 50 | - /** |
|
| 51 | - * @param $entity |
|
| 52 | - * @param $args |
|
| 53 | - * @param $context |
|
| 54 | - * @param $info |
|
| 55 | - * @return array |
|
| 56 | - * @throws Exception |
|
| 57 | - * @since $VID:$ |
|
| 58 | - */ |
|
| 59 | - public function resolveConnection($entity, $args, $context, $info) |
|
| 60 | - { |
|
| 61 | - $resolver = new PriceConnectionResolver($entity, $args, $context, $info); |
|
| 62 | - return $resolver->get_connection(); |
|
| 63 | - } |
|
| 50 | + /** |
|
| 51 | + * @param $entity |
|
| 52 | + * @param $args |
|
| 53 | + * @param $context |
|
| 54 | + * @param $info |
|
| 55 | + * @return array |
|
| 56 | + * @throws Exception |
|
| 57 | + * @since $VID:$ |
|
| 58 | + */ |
|
| 59 | + public function resolveConnection($entity, $args, $context, $info) |
|
| 60 | + { |
|
| 61 | + $resolver = new PriceConnectionResolver($entity, $args, $context, $info); |
|
| 62 | + return $resolver->get_connection(); |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * Given an optional array of args, this returns the args to be used in the connection |
|
| 67 | - * |
|
| 68 | - * @access public |
|
| 69 | - * @param array $args The args to modify the defaults |
|
| 70 | - * |
|
| 71 | - * @return array |
|
| 72 | - */ |
|
| 73 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 74 | - public static function get_connection_args($args = []) |
|
| 75 | - { |
|
| 76 | - return array_merge( |
|
| 77 | - [ |
|
| 78 | - 'in' => [ |
|
| 79 | - 'type' => ['list_of' => 'ID'], |
|
| 80 | - 'description' => esc_html__('Limit prices to the given globally unique IDs', 'event_espresso'), |
|
| 81 | - ], |
|
| 82 | - 'idIn' => [ |
|
| 83 | - 'type' => ['list_of' => 'ID'], |
|
| 84 | - 'description' => esc_html__('Limit prices to the given IDs', 'event_espresso'), |
|
| 85 | - ], |
|
| 86 | - 'includeDefaultPrices' => [ |
|
| 87 | - 'type' => 'Boolean', |
|
| 88 | - 'description' => esc_html__('Whether to add default prices to the list.', 'event_espresso'), |
|
| 89 | - ], |
|
| 90 | - 'ticket' => [ |
|
| 91 | - 'type' => 'ID', |
|
| 92 | - 'description' => esc_html__('Globally unique ticket ID to get the prices for.', 'event_espresso'), |
|
| 93 | - ], |
|
| 94 | - 'ticketIn' => [ |
|
| 95 | - 'type' => ['list_of' => 'ID'], |
|
| 96 | - 'description' => esc_html__('Globally unique ticket IDs to get the prices for.', 'event_espresso'), |
|
| 97 | - ], |
|
| 98 | - 'ticketId' => [ |
|
| 99 | - 'type' => 'Int', |
|
| 100 | - 'description' => esc_html__('Ticket ID to get the prices for.', 'event_espresso'), |
|
| 101 | - ], |
|
| 102 | - 'ticketIdIn' => [ |
|
| 103 | - 'type' => ['list_of' => 'Int'], |
|
| 104 | - 'description' => esc_html__('Ticket IDs to get the prices for.', 'event_espresso'), |
|
| 105 | - ], |
|
| 106 | - 'priceType' => [ |
|
| 107 | - 'type' => 'ID', |
|
| 108 | - 'description' => esc_html__('Globally unique price type ID to get the prices for.', 'event_espresso'), |
|
| 109 | - ], |
|
| 110 | - 'priceTypeIn' => [ |
|
| 111 | - 'type' => ['list_of' => 'ID'], |
|
| 112 | - 'description' => esc_html__('Globally unique price type IDs to get the prices for.', 'event_espresso'), |
|
| 113 | - ], |
|
| 114 | - 'priceTypeId' => [ |
|
| 115 | - 'type' => 'Int', |
|
| 116 | - 'description' => esc_html__('Price type ID to get the prices for.', 'event_espresso'), |
|
| 117 | - ], |
|
| 118 | - 'priceTypeIdIn' => [ |
|
| 119 | - 'type' => ['list_of' => 'Int'], |
|
| 120 | - 'description' => esc_html__('Price type IDs to get the prices for.', 'event_espresso'), |
|
| 121 | - ], |
|
| 122 | - 'priceBaseType' => [ |
|
| 123 | - 'type' => 'PriceBaseTypeEnum', |
|
| 124 | - 'description' => esc_html__('Price Base type.', 'event_espresso'), |
|
| 125 | - ], |
|
| 126 | - 'priceBaseTypeIn' => [ |
|
| 127 | - 'type' => ['list_of' => 'PriceBaseTypeEnum'], |
|
| 128 | - 'description' => esc_html__('Price Base types.', 'event_espresso'), |
|
| 129 | - ], |
|
| 130 | - ], |
|
| 131 | - $args |
|
| 132 | - ); |
|
| 133 | - } |
|
| 65 | + /** |
|
| 66 | + * Given an optional array of args, this returns the args to be used in the connection |
|
| 67 | + * |
|
| 68 | + * @access public |
|
| 69 | + * @param array $args The args to modify the defaults |
|
| 70 | + * |
|
| 71 | + * @return array |
|
| 72 | + */ |
|
| 73 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
| 74 | + public static function get_connection_args($args = []) |
|
| 75 | + { |
|
| 76 | + return array_merge( |
|
| 77 | + [ |
|
| 78 | + 'in' => [ |
|
| 79 | + 'type' => ['list_of' => 'ID'], |
|
| 80 | + 'description' => esc_html__('Limit prices to the given globally unique IDs', 'event_espresso'), |
|
| 81 | + ], |
|
| 82 | + 'idIn' => [ |
|
| 83 | + 'type' => ['list_of' => 'ID'], |
|
| 84 | + 'description' => esc_html__('Limit prices to the given IDs', 'event_espresso'), |
|
| 85 | + ], |
|
| 86 | + 'includeDefaultPrices' => [ |
|
| 87 | + 'type' => 'Boolean', |
|
| 88 | + 'description' => esc_html__('Whether to add default prices to the list.', 'event_espresso'), |
|
| 89 | + ], |
|
| 90 | + 'ticket' => [ |
|
| 91 | + 'type' => 'ID', |
|
| 92 | + 'description' => esc_html__('Globally unique ticket ID to get the prices for.', 'event_espresso'), |
|
| 93 | + ], |
|
| 94 | + 'ticketIn' => [ |
|
| 95 | + 'type' => ['list_of' => 'ID'], |
|
| 96 | + 'description' => esc_html__('Globally unique ticket IDs to get the prices for.', 'event_espresso'), |
|
| 97 | + ], |
|
| 98 | + 'ticketId' => [ |
|
| 99 | + 'type' => 'Int', |
|
| 100 | + 'description' => esc_html__('Ticket ID to get the prices for.', 'event_espresso'), |
|
| 101 | + ], |
|
| 102 | + 'ticketIdIn' => [ |
|
| 103 | + 'type' => ['list_of' => 'Int'], |
|
| 104 | + 'description' => esc_html__('Ticket IDs to get the prices for.', 'event_espresso'), |
|
| 105 | + ], |
|
| 106 | + 'priceType' => [ |
|
| 107 | + 'type' => 'ID', |
|
| 108 | + 'description' => esc_html__('Globally unique price type ID to get the prices for.', 'event_espresso'), |
|
| 109 | + ], |
|
| 110 | + 'priceTypeIn' => [ |
|
| 111 | + 'type' => ['list_of' => 'ID'], |
|
| 112 | + 'description' => esc_html__('Globally unique price type IDs to get the prices for.', 'event_espresso'), |
|
| 113 | + ], |
|
| 114 | + 'priceTypeId' => [ |
|
| 115 | + 'type' => 'Int', |
|
| 116 | + 'description' => esc_html__('Price type ID to get the prices for.', 'event_espresso'), |
|
| 117 | + ], |
|
| 118 | + 'priceTypeIdIn' => [ |
|
| 119 | + 'type' => ['list_of' => 'Int'], |
|
| 120 | + 'description' => esc_html__('Price type IDs to get the prices for.', 'event_espresso'), |
|
| 121 | + ], |
|
| 122 | + 'priceBaseType' => [ |
|
| 123 | + 'type' => 'PriceBaseTypeEnum', |
|
| 124 | + 'description' => esc_html__('Price Base type.', 'event_espresso'), |
|
| 125 | + ], |
|
| 126 | + 'priceBaseTypeIn' => [ |
|
| 127 | + 'type' => ['list_of' => 'PriceBaseTypeEnum'], |
|
| 128 | + 'description' => esc_html__('Price Base types.', 'event_espresso'), |
|
| 129 | + ], |
|
| 130 | + ], |
|
| 131 | + $args |
|
| 132 | + ); |
|
| 133 | + } |
|
| 134 | 134 | } |