@@ -69,7 +69,7 @@ |
||
69 | 69 | $keys_only = empty( |
70 | 70 | array_filter( |
71 | 71 | array_values($data_value), |
72 | - function ($v) { |
|
72 | + function($v) { |
|
73 | 73 | return $v !== null && (is_array($v) || trim($v) !== ''); |
74 | 74 | } |
75 | 75 | ) |
@@ -19,38 +19,38 @@ discard block |
||
19 | 19 | */ |
20 | 20 | function ee_recurse_into_array_for_display($data, $depth = 0, $td = true) |
21 | 21 | { |
22 | - if (is_object($data) || $data instanceof __PHP_Incomplete_Class) { |
|
23 | - // is_object($incomplete_class) actually returns false, hence why we check for it |
|
24 | - $data = json_decode(json_encode($data), true); |
|
25 | - } |
|
26 | - if (empty($data)) { |
|
27 | - return; |
|
28 | - } |
|
29 | - if (is_array($data)) { |
|
30 | - $depth++; |
|
31 | - ksort($data, SORT_NATURAL | SORT_FLAG_CASE); |
|
32 | - if (EEH_Array::is_associative_array($data)) { ?> |
|
22 | + if (is_object($data) || $data instanceof __PHP_Incomplete_Class) { |
|
23 | + // is_object($incomplete_class) actually returns false, hence why we check for it |
|
24 | + $data = json_decode(json_encode($data), true); |
|
25 | + } |
|
26 | + if (empty($data)) { |
|
27 | + return; |
|
28 | + } |
|
29 | + if (is_array($data)) { |
|
30 | + $depth++; |
|
31 | + ksort($data, SORT_NATURAL | SORT_FLAG_CASE); |
|
32 | + if (EEH_Array::is_associative_array($data)) { ?> |
|
33 | 33 | <table class='ee-system-stati ee-system-stati-<?php echo absint($depth); ?>'> |
34 | 34 | <tbody> |
35 | 35 | <?php foreach ($data as $data_key => $data_value) { |
36 | - // if the value is a single element array with no key, |
|
37 | - // and the value is a primitive (not an array, object, etc.) |
|
38 | - if ( |
|
39 | - is_array($data_value) |
|
40 | - && count($data_value) === 1 |
|
41 | - && empty(key($data_value)) |
|
42 | - && is_scalar(reset($data_value)) |
|
43 | - ) { |
|
44 | - ?> |
|
36 | + // if the value is a single element array with no key, |
|
37 | + // and the value is a primitive (not an array, object, etc.) |
|
38 | + if ( |
|
39 | + is_array($data_value) |
|
40 | + && count($data_value) === 1 |
|
41 | + && empty(key($data_value)) |
|
42 | + && is_scalar(reset($data_value)) |
|
43 | + ) { |
|
44 | + ?> |
|
45 | 45 | <tr> |
46 | 46 | <td class="ee-system-stati-value" colspan="2"> |
47 | 47 | <?php echo esc_html(reset($data_value)); ?> |
48 | 48 | </td> |
49 | 49 | </tr> |
50 | 50 | <?php |
51 | - continue; |
|
52 | - } |
|
53 | - ?> |
|
51 | + continue; |
|
52 | + } |
|
53 | + ?> |
|
54 | 54 | <tr> |
55 | 55 | <td class='ee-system-stati-key'> |
56 | 56 | <span class="ee-system-stati-label"> |
@@ -65,31 +65,31 @@ discard block |
||
65 | 65 | <?php if (is_scalar($data_value)) { ?> |
66 | 66 | <?php ee_recurse_into_array_for_display($data_value, $depth); ?> |
67 | 67 | <?php } else { |
68 | - if (is_array($data_value) && count($data_value) === 1) { |
|
69 | - // verify that values have been set |
|
70 | - $keys_only = empty( |
|
71 | - array_filter( |
|
72 | - array_values($data_value), |
|
73 | - function ($v) { |
|
74 | - return $v !== null && (is_array($v) || trim($v) !== ''); |
|
75 | - } |
|
76 | - ) |
|
77 | - ); |
|
78 | - // if the array only consists of keys (no values) |
|
79 | - if ($keys_only) { |
|
80 | - // then use keys for values |
|
81 | - $data_value = array_keys($data_value); |
|
82 | - // but if there is only one value now |
|
83 | - if (count($data_value) === 1) { |
|
84 | - // then pass that single value back into this function |
|
85 | - // this prevents extra empty layers of nothing being added to the output |
|
86 | - ee_recurse_into_array_for_display(reset($data_value), $depth); |
|
87 | - // need to finish the row off though |
|
88 | - echo '</tr>'; |
|
89 | - continue; |
|
90 | - } |
|
91 | - } |
|
92 | - } ?> |
|
68 | + if (is_array($data_value) && count($data_value) === 1) { |
|
69 | + // verify that values have been set |
|
70 | + $keys_only = empty( |
|
71 | + array_filter( |
|
72 | + array_values($data_value), |
|
73 | + function ($v) { |
|
74 | + return $v !== null && (is_array($v) || trim($v) !== ''); |
|
75 | + } |
|
76 | + ) |
|
77 | + ); |
|
78 | + // if the array only consists of keys (no values) |
|
79 | + if ($keys_only) { |
|
80 | + // then use keys for values |
|
81 | + $data_value = array_keys($data_value); |
|
82 | + // but if there is only one value now |
|
83 | + if (count($data_value) === 1) { |
|
84 | + // then pass that single value back into this function |
|
85 | + // this prevents extra empty layers of nothing being added to the output |
|
86 | + ee_recurse_into_array_for_display(reset($data_value), $depth); |
|
87 | + // need to finish the row off though |
|
88 | + echo '</tr>'; |
|
89 | + continue; |
|
90 | + } |
|
91 | + } |
|
92 | + } ?> |
|
93 | 93 | <td class="ee-system-stati-sub-values"> |
94 | 94 | <?php ee_recurse_into_array_for_display($data_value, $depth); ?> |
95 | 95 | </td> |
@@ -107,19 +107,19 @@ discard block |
||
107 | 107 | <?php } ?> |
108 | 108 | </ul> |
109 | 109 | <?php } else { |
110 | - // there's no key (label) and there's only one value, |
|
111 | - // so let's just pass that value back into this function, |
|
112 | - // but reset the depth back to where it was. |
|
113 | - // this prevents extra empty layers of nothing being added to the output |
|
114 | - $depth--; |
|
115 | - ee_recurse_into_array_for_display(reset($data), $depth, false); |
|
116 | - } |
|
117 | - } else { |
|
118 | - echo wp_kses($td ? '<td class="ee-system-stati-value">' : '', AllowedTags::getAllowedTags()); |
|
119 | - // simple value |
|
120 | - echo wp_kses($data, AllowedTags::getAllowedTags()); |
|
121 | - echo wp_kses($td ? '</td>' : '', AllowedTags::getAllowedTags()); |
|
122 | - } |
|
110 | + // there's no key (label) and there's only one value, |
|
111 | + // so let's just pass that value back into this function, |
|
112 | + // but reset the depth back to where it was. |
|
113 | + // this prevents extra empty layers of nothing being added to the output |
|
114 | + $depth--; |
|
115 | + ee_recurse_into_array_for_display(reset($data), $depth, false); |
|
116 | + } |
|
117 | + } else { |
|
118 | + echo wp_kses($td ? '<td class="ee-system-stati-value">' : '', AllowedTags::getAllowedTags()); |
|
119 | + // simple value |
|
120 | + echo wp_kses($data, AllowedTags::getAllowedTags()); |
|
121 | + echo wp_kses($td ? '</td>' : '', AllowedTags::getAllowedTags()); |
|
122 | + } |
|
123 | 123 | } |
124 | 124 | |
125 | 125 | ?> |
@@ -17,76 +17,76 @@ |
||
17 | 17 | |
18 | 18 | class BulkEntityDelete extends EntityMutator |
19 | 19 | { |
20 | - /** |
|
21 | - * Defines the mutation data modification closure. |
|
22 | - * |
|
23 | - * @return callable |
|
24 | - */ |
|
25 | - public static function mutateAndGetPayload() |
|
26 | - { |
|
27 | - /** |
|
28 | - * Updates an entity. |
|
29 | - * |
|
30 | - * @param array $input The input for the mutation |
|
31 | - * @param AppContext $context The AppContext passed down to all resolvers |
|
32 | - * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
33 | - * @return array |
|
34 | - * @throws UserError |
|
35 | - * @throws ReflectionException |
|
36 | - * @throws InvalidArgumentException |
|
37 | - * @throws InvalidInterfaceException |
|
38 | - * @throws InvalidDataTypeException |
|
39 | - * @throws EE_Error |
|
40 | - */ |
|
41 | - return static function (array $input, AppContext $context, ResolveInfo $info): array { |
|
42 | - /** |
|
43 | - * Stop now if a user isn't allowed to delete. |
|
44 | - */ |
|
45 | - if (! current_user_can('ee_delete_events')) { |
|
46 | - throw new UserError( |
|
47 | - esc_html__('Sorry, you do not have the required permissions to delete entities', 'event_espresso') |
|
48 | - ); |
|
49 | - } |
|
20 | + /** |
|
21 | + * Defines the mutation data modification closure. |
|
22 | + * |
|
23 | + * @return callable |
|
24 | + */ |
|
25 | + public static function mutateAndGetPayload() |
|
26 | + { |
|
27 | + /** |
|
28 | + * Updates an entity. |
|
29 | + * |
|
30 | + * @param array $input The input for the mutation |
|
31 | + * @param AppContext $context The AppContext passed down to all resolvers |
|
32 | + * @param ResolveInfo $info The ResolveInfo passed down to all resolvers |
|
33 | + * @return array |
|
34 | + * @throws UserError |
|
35 | + * @throws ReflectionException |
|
36 | + * @throws InvalidArgumentException |
|
37 | + * @throws InvalidInterfaceException |
|
38 | + * @throws InvalidDataTypeException |
|
39 | + * @throws EE_Error |
|
40 | + */ |
|
41 | + return static function (array $input, AppContext $context, ResolveInfo $info): array { |
|
42 | + /** |
|
43 | + * Stop now if a user isn't allowed to delete. |
|
44 | + */ |
|
45 | + if (! current_user_can('ee_delete_events')) { |
|
46 | + throw new UserError( |
|
47 | + esc_html__('Sorry, you do not have the required permissions to delete entities', 'event_espresso') |
|
48 | + ); |
|
49 | + } |
|
50 | 50 | |
51 | - $details = EntityReorder::prepareEntityDetailsFromInput($input); |
|
51 | + $details = EntityReorder::prepareEntityDetailsFromInput($input); |
|
52 | 52 | |
53 | - $deletePermanently = ! empty($input['deletePermanently']); |
|
53 | + $deletePermanently = ! empty($input['deletePermanently']); |
|
54 | 54 | |
55 | - $deletionMethod = __NAMESPACE__; |
|
56 | - // if it's for datetimes. |
|
57 | - if ($details['entityType'] === EEM_Datetime::instance()->item_name()) { |
|
58 | - $deletionMethod .= '\DatetimeDelete::' . ($deletePermanently ? 'deleteDatetimeAndRelations' : 'trashDatetimeAndRelations'); |
|
59 | - } elseif ($details['entityType'] === EEM_Ticket::instance()->item_name()) { |
|
60 | - $deletionMethod .= '\TicketDelete::' . ($deletePermanently ? 'deleteTicketAndRelations' : 'trashTicket'); |
|
61 | - } elseif ($details['entityType'] === EEM_Price::instance()->item_name()) { |
|
62 | - $deletionMethod .= '\PriceDelete::deletePriceAndRelations'; |
|
63 | - } else { |
|
64 | - throw new UserError( |
|
65 | - esc_html__( |
|
66 | - 'A valid data model could not be obtained. Did you supply a valid entity type?', |
|
67 | - 'event_espresso' |
|
68 | - ) |
|
69 | - ); |
|
70 | - } |
|
55 | + $deletionMethod = __NAMESPACE__; |
|
56 | + // if it's for datetimes. |
|
57 | + if ($details['entityType'] === EEM_Datetime::instance()->item_name()) { |
|
58 | + $deletionMethod .= '\DatetimeDelete::' . ($deletePermanently ? 'deleteDatetimeAndRelations' : 'trashDatetimeAndRelations'); |
|
59 | + } elseif ($details['entityType'] === EEM_Ticket::instance()->item_name()) { |
|
60 | + $deletionMethod .= '\TicketDelete::' . ($deletePermanently ? 'deleteTicketAndRelations' : 'trashTicket'); |
|
61 | + } elseif ($details['entityType'] === EEM_Price::instance()->item_name()) { |
|
62 | + $deletionMethod .= '\PriceDelete::deletePriceAndRelations'; |
|
63 | + } else { |
|
64 | + throw new UserError( |
|
65 | + esc_html__( |
|
66 | + 'A valid data model could not be obtained. Did you supply a valid entity type?', |
|
67 | + 'event_espresso' |
|
68 | + ) |
|
69 | + ); |
|
70 | + } |
|
71 | 71 | |
72 | - $deleted = []; |
|
73 | - $failed = []; |
|
72 | + $deleted = []; |
|
73 | + $failed = []; |
|
74 | 74 | |
75 | - foreach ($details['entity_db_ids'] as $key => $entityDbid) { |
|
76 | - $guid = $details['entityGuids'][ $key ]; |
|
77 | - $entity = $details['entities'][ $entityDbid ]; |
|
78 | - try { |
|
79 | - $result = $deletionMethod($entity); |
|
80 | - EntityMutator::validateResults($result); |
|
81 | - // we are here it means the deletion was successful. |
|
82 | - $deleted[] = $guid; |
|
83 | - } catch (Exception $e) { |
|
84 | - // sorry mate, couldn't help you :( |
|
85 | - $failed[] = $guid; |
|
86 | - } |
|
87 | - } |
|
75 | + foreach ($details['entity_db_ids'] as $key => $entityDbid) { |
|
76 | + $guid = $details['entityGuids'][ $key ]; |
|
77 | + $entity = $details['entities'][ $entityDbid ]; |
|
78 | + try { |
|
79 | + $result = $deletionMethod($entity); |
|
80 | + EntityMutator::validateResults($result); |
|
81 | + // we are here it means the deletion was successful. |
|
82 | + $deleted[] = $guid; |
|
83 | + } catch (Exception $e) { |
|
84 | + // sorry mate, couldn't help you :( |
|
85 | + $failed[] = $guid; |
|
86 | + } |
|
87 | + } |
|
88 | 88 | |
89 | - return compact('deleted', 'failed'); |
|
90 | - }; |
|
91 | - } |
|
89 | + return compact('deleted', 'failed'); |
|
90 | + }; |
|
91 | + } |
|
92 | 92 | } |
@@ -38,11 +38,11 @@ discard block |
||
38 | 38 | * @throws InvalidDataTypeException |
39 | 39 | * @throws EE_Error |
40 | 40 | */ |
41 | - return static function (array $input, AppContext $context, ResolveInfo $info): array { |
|
41 | + return static function(array $input, AppContext $context, ResolveInfo $info): array { |
|
42 | 42 | /** |
43 | 43 | * Stop now if a user isn't allowed to delete. |
44 | 44 | */ |
45 | - if (! current_user_can('ee_delete_events')) { |
|
45 | + if ( ! current_user_can('ee_delete_events')) { |
|
46 | 46 | throw new UserError( |
47 | 47 | esc_html__('Sorry, you do not have the required permissions to delete entities', 'event_espresso') |
48 | 48 | ); |
@@ -55,9 +55,9 @@ discard block |
||
55 | 55 | $deletionMethod = __NAMESPACE__; |
56 | 56 | // if it's for datetimes. |
57 | 57 | if ($details['entityType'] === EEM_Datetime::instance()->item_name()) { |
58 | - $deletionMethod .= '\DatetimeDelete::' . ($deletePermanently ? 'deleteDatetimeAndRelations' : 'trashDatetimeAndRelations'); |
|
58 | + $deletionMethod .= '\DatetimeDelete::'.($deletePermanently ? 'deleteDatetimeAndRelations' : 'trashDatetimeAndRelations'); |
|
59 | 59 | } elseif ($details['entityType'] === EEM_Ticket::instance()->item_name()) { |
60 | - $deletionMethod .= '\TicketDelete::' . ($deletePermanently ? 'deleteTicketAndRelations' : 'trashTicket'); |
|
60 | + $deletionMethod .= '\TicketDelete::'.($deletePermanently ? 'deleteTicketAndRelations' : 'trashTicket'); |
|
61 | 61 | } elseif ($details['entityType'] === EEM_Price::instance()->item_name()) { |
62 | 62 | $deletionMethod .= '\PriceDelete::deletePriceAndRelations'; |
63 | 63 | } else { |
@@ -73,8 +73,8 @@ discard block |
||
73 | 73 | $failed = []; |
74 | 74 | |
75 | 75 | foreach ($details['entity_db_ids'] as $key => $entityDbid) { |
76 | - $guid = $details['entityGuids'][ $key ]; |
|
77 | - $entity = $details['entities'][ $entityDbid ]; |
|
76 | + $guid = $details['entityGuids'][$key]; |
|
77 | + $entity = $details['entities'][$entityDbid]; |
|
78 | 78 | try { |
79 | 79 | $result = $deletionMethod($entity); |
80 | 80 | EntityMutator::validateResults($result); |
@@ -106,7 +106,7 @@ discard block |
||
106 | 106 | { |
107 | 107 | // $block_editor_context can be either an object or a string |
108 | 108 | // so checking it here, thus no type hinting in function params |
109 | - if (! $block_editor_context instanceof WP_Block_Editor_Context) { |
|
109 | + if ( ! $block_editor_context instanceof WP_Block_Editor_Context) { |
|
110 | 110 | return $categories; |
111 | 111 | } |
112 | 112 | return array_merge( |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | foreach ($this->blocks as $block) { |
168 | 168 | $block->initialize(); |
169 | 169 | $this->trackAssetManagersForBlocks($block); |
170 | - if (! $this->block_asset_manager_collection->has($block->assetManager())) { |
|
170 | + if ( ! $this->block_asset_manager_collection->has($block->assetManager())) { |
|
171 | 171 | $this->block_asset_manager_collection->add($block->assetManager()); |
172 | 172 | $block->assetManager()->setAssetHandles(); |
173 | 173 | } |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | $supported_routes = $block->supportedRoutes(); |
190 | 190 | foreach ($supported_routes as $supported_route) { |
191 | 191 | if ($this->route_manager->routeMatchesCurrentRequest($supported_route)) { |
192 | - $this->block_asset_managers[ $block->blockType() ] = $block->assetManager()->assetNamespace(); |
|
192 | + $this->block_asset_managers[$block->blockType()] = $block->assetManager()->assetNamespace(); |
|
193 | 193 | } |
194 | 194 | } |
195 | 195 | } |
@@ -205,10 +205,10 @@ discard block |
||
205 | 205 | */ |
206 | 206 | public function matchesRoute(BlockInterface $block) |
207 | 207 | { |
208 | - if (isset($this->block_asset_managers[ $block->blockType() ])) { |
|
208 | + if (isset($this->block_asset_managers[$block->blockType()])) { |
|
209 | 209 | return true; |
210 | 210 | } |
211 | - unset($this->block_asset_managers[ $block->blockType() ]); |
|
211 | + unset($this->block_asset_managers[$block->blockType()]); |
|
212 | 212 | return false; |
213 | 213 | } |
214 | 214 | |
@@ -224,12 +224,12 @@ discard block |
||
224 | 224 | try { |
225 | 225 | // cycle thru block loader folders |
226 | 226 | foreach ($this->blocks as $block) { |
227 | - if (! $this->matchesRoute($block)) { |
|
227 | + if ( ! $this->matchesRoute($block)) { |
|
228 | 228 | continue; |
229 | 229 | } |
230 | 230 | // perform any setup required for the block |
231 | 231 | $block_type = $block->registerBlock(); |
232 | - if (! $block_type instanceof WP_Block_Type) { |
|
232 | + if ( ! $block_type instanceof WP_Block_Type) { |
|
233 | 233 | throw new InvalidEntityException($block_type, 'WP_Block_Type'); |
234 | 234 | } |
235 | 235 | do_action( |
@@ -248,7 +248,7 @@ discard block |
||
248 | 248 | $assets = array_flip($this->block_asset_managers); |
249 | 249 | foreach ($this->block_asset_manager_collection as $asset_manager) { |
250 | 250 | // if there are no longer any blocks that require these assets, |
251 | - if (! isset($assets[ $asset_manager->assetNamespace() ])) { |
|
251 | + if ( ! isset($assets[$asset_manager->assetNamespace()])) { |
|
252 | 252 | // then unset asset enqueueing and bail |
253 | 253 | remove_action('wp_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0); |
254 | 254 | remove_action('admin_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0); |
@@ -32,228 +32,228 @@ |
||
32 | 32 | */ |
33 | 33 | class BlockRegistrationManager extends BlockManager |
34 | 34 | { |
35 | - /** |
|
36 | - * @var BlockAssetManagerCollection $block_asset_manager_collection |
|
37 | - */ |
|
38 | - protected $block_asset_manager_collection; |
|
35 | + /** |
|
36 | + * @var BlockAssetManagerCollection $block_asset_manager_collection |
|
37 | + */ |
|
38 | + protected $block_asset_manager_collection; |
|
39 | 39 | |
40 | - /** |
|
41 | - * @var RouteMatchSpecificationManager $route_manager |
|
42 | - */ |
|
43 | - protected $route_manager; |
|
40 | + /** |
|
41 | + * @var RouteMatchSpecificationManager $route_manager |
|
42 | + */ |
|
43 | + protected $route_manager; |
|
44 | 44 | |
45 | - /** |
|
46 | - * array for tracking asset managers required by blocks for the current route |
|
47 | - * |
|
48 | - * @var array $block_asset_managers |
|
49 | - */ |
|
50 | - protected $block_asset_managers = array(); |
|
45 | + /** |
|
46 | + * array for tracking asset managers required by blocks for the current route |
|
47 | + * |
|
48 | + * @var array $block_asset_managers |
|
49 | + */ |
|
50 | + protected $block_asset_managers = array(); |
|
51 | 51 | |
52 | 52 | |
53 | - /** |
|
54 | - * BlockRegistrationManager constructor. |
|
55 | - * |
|
56 | - * @param BlockAssetManagerCollection $block_asset_manager_collection |
|
57 | - * @param BlockCollection $blocks |
|
58 | - * @param RouteMatchSpecificationManager $route_manager |
|
59 | - * @param RequestInterface $request |
|
60 | - */ |
|
61 | - public function __construct( |
|
62 | - BlockAssetManagerCollection $block_asset_manager_collection, |
|
63 | - BlockCollection $blocks, |
|
64 | - RouteMatchSpecificationManager $route_manager, |
|
65 | - RequestInterface $request |
|
66 | - ) { |
|
67 | - $this->block_asset_manager_collection = $block_asset_manager_collection; |
|
68 | - $this->route_manager = $route_manager; |
|
69 | - parent::__construct($blocks, $request); |
|
70 | - } |
|
53 | + /** |
|
54 | + * BlockRegistrationManager constructor. |
|
55 | + * |
|
56 | + * @param BlockAssetManagerCollection $block_asset_manager_collection |
|
57 | + * @param BlockCollection $blocks |
|
58 | + * @param RouteMatchSpecificationManager $route_manager |
|
59 | + * @param RequestInterface $request |
|
60 | + */ |
|
61 | + public function __construct( |
|
62 | + BlockAssetManagerCollection $block_asset_manager_collection, |
|
63 | + BlockCollection $blocks, |
|
64 | + RouteMatchSpecificationManager $route_manager, |
|
65 | + RequestInterface $request |
|
66 | + ) { |
|
67 | + $this->block_asset_manager_collection = $block_asset_manager_collection; |
|
68 | + $this->route_manager = $route_manager; |
|
69 | + parent::__construct($blocks, $request); |
|
70 | + } |
|
71 | 71 | |
72 | 72 | |
73 | - /** |
|
74 | - * Returns the name of a hook point to be used to call initialize() |
|
75 | - * |
|
76 | - * @return string |
|
77 | - */ |
|
78 | - public function initHook() |
|
79 | - { |
|
80 | - return 'AHEE__EE_System__initialize'; |
|
81 | - } |
|
73 | + /** |
|
74 | + * Returns the name of a hook point to be used to call initialize() |
|
75 | + * |
|
76 | + * @return string |
|
77 | + */ |
|
78 | + public function initHook() |
|
79 | + { |
|
80 | + return 'AHEE__EE_System__initialize'; |
|
81 | + } |
|
82 | 82 | |
83 | 83 | |
84 | - /** |
|
85 | - * Perform any early setup required for block editors to functions |
|
86 | - * |
|
87 | - * @return void |
|
88 | - * @throws Exception |
|
89 | - */ |
|
90 | - public function initialize() |
|
91 | - { |
|
92 | - $this->initializeBlocks(); |
|
93 | - add_action('AHEE__EE_System__initialize_last', array($this, 'registerBlocks')); |
|
94 | - add_action('wp_loaded', array($this, 'unloadAssets')); |
|
95 | - add_filter('block_categories_all', array($this, 'addEspressoBlockCategories'), 10, 2); |
|
96 | - } |
|
84 | + /** |
|
85 | + * Perform any early setup required for block editors to functions |
|
86 | + * |
|
87 | + * @return void |
|
88 | + * @throws Exception |
|
89 | + */ |
|
90 | + public function initialize() |
|
91 | + { |
|
92 | + $this->initializeBlocks(); |
|
93 | + add_action('AHEE__EE_System__initialize_last', array($this, 'registerBlocks')); |
|
94 | + add_action('wp_loaded', array($this, 'unloadAssets')); |
|
95 | + add_filter('block_categories_all', array($this, 'addEspressoBlockCategories'), 10, 2); |
|
96 | + } |
|
97 | 97 | |
98 | 98 | |
99 | - /** |
|
100 | - * @param array $categories |
|
101 | - * @since 4.9.71.p |
|
102 | - * @return array |
|
103 | - */ |
|
104 | - public function addEspressoBlockCategories(array $categories, $block_editor_context): array |
|
105 | - { |
|
106 | - // $block_editor_context can be either an object or a string |
|
107 | - // so checking it here, thus no type hinting in function params |
|
108 | - if (! $block_editor_context instanceof WP_Block_Editor_Context) { |
|
109 | - return $categories; |
|
110 | - } |
|
111 | - return array_merge( |
|
112 | - $categories, |
|
113 | - [ |
|
114 | - [ |
|
115 | - 'slug' => 'event-espresso', |
|
116 | - 'title' => esc_html__('Event Espresso', 'event_espresso'), |
|
117 | - ] |
|
118 | - ] |
|
119 | - ); |
|
120 | - } |
|
99 | + /** |
|
100 | + * @param array $categories |
|
101 | + * @since 4.9.71.p |
|
102 | + * @return array |
|
103 | + */ |
|
104 | + public function addEspressoBlockCategories(array $categories, $block_editor_context): array |
|
105 | + { |
|
106 | + // $block_editor_context can be either an object or a string |
|
107 | + // so checking it here, thus no type hinting in function params |
|
108 | + if (! $block_editor_context instanceof WP_Block_Editor_Context) { |
|
109 | + return $categories; |
|
110 | + } |
|
111 | + return array_merge( |
|
112 | + $categories, |
|
113 | + [ |
|
114 | + [ |
|
115 | + 'slug' => 'event-espresso', |
|
116 | + 'title' => esc_html__('Event Espresso', 'event_espresso'), |
|
117 | + ] |
|
118 | + ] |
|
119 | + ); |
|
120 | + } |
|
121 | 121 | |
122 | 122 | |
123 | - /** |
|
124 | - * @return CollectionInterface|BlockInterface[] |
|
125 | - * @throws CollectionLoaderException |
|
126 | - * @throws CollectionDetailsException |
|
127 | - */ |
|
128 | - protected function populateBlockCollection() |
|
129 | - { |
|
130 | - $loader = new CollectionLoader( |
|
131 | - new CollectionDetails( |
|
132 | - // collection name |
|
133 | - 'editor_blocks', |
|
134 | - // collection interface |
|
135 | - 'EventEspresso\core\domain\entities\editor\BlockInterface', |
|
136 | - // FQCNs for classes to add (all classes within each namespace will be loaded) |
|
137 | - apply_filters( |
|
138 | - 'FHEE__EventEspresso_core_services_editor_BlockManager__populateBlockCollection__collection_FQCNs', |
|
139 | - array('EventEspresso\core\domain\entities\editor\blocks') |
|
140 | - ), |
|
141 | - // file paths to classes to add |
|
142 | - array(), |
|
143 | - // file mask to use if parsing folder for files to add |
|
144 | - '', |
|
145 | - // what to use as identifier for collection entities |
|
146 | - // using CLASS NAME prevents duplicates (works like a singleton) |
|
147 | - CollectionDetails::ID_CLASS_NAME |
|
148 | - ), |
|
149 | - $this->blocks |
|
150 | - ); |
|
151 | - return $loader->getCollection(); |
|
152 | - } |
|
123 | + /** |
|
124 | + * @return CollectionInterface|BlockInterface[] |
|
125 | + * @throws CollectionLoaderException |
|
126 | + * @throws CollectionDetailsException |
|
127 | + */ |
|
128 | + protected function populateBlockCollection() |
|
129 | + { |
|
130 | + $loader = new CollectionLoader( |
|
131 | + new CollectionDetails( |
|
132 | + // collection name |
|
133 | + 'editor_blocks', |
|
134 | + // collection interface |
|
135 | + 'EventEspresso\core\domain\entities\editor\BlockInterface', |
|
136 | + // FQCNs for classes to add (all classes within each namespace will be loaded) |
|
137 | + apply_filters( |
|
138 | + 'FHEE__EventEspresso_core_services_editor_BlockManager__populateBlockCollection__collection_FQCNs', |
|
139 | + array('EventEspresso\core\domain\entities\editor\blocks') |
|
140 | + ), |
|
141 | + // file paths to classes to add |
|
142 | + array(), |
|
143 | + // file mask to use if parsing folder for files to add |
|
144 | + '', |
|
145 | + // what to use as identifier for collection entities |
|
146 | + // using CLASS NAME prevents duplicates (works like a singleton) |
|
147 | + CollectionDetails::ID_CLASS_NAME |
|
148 | + ), |
|
149 | + $this->blocks |
|
150 | + ); |
|
151 | + return $loader->getCollection(); |
|
152 | + } |
|
153 | 153 | |
154 | 154 | |
155 | - /** |
|
156 | - * populates the BlockCollection and calls initialize() on all installed blocks |
|
157 | - * |
|
158 | - * @return void |
|
159 | - * @throws Exception |
|
160 | - */ |
|
161 | - public function initializeBlocks() |
|
162 | - { |
|
163 | - try { |
|
164 | - $this->populateBlockCollection(); |
|
165 | - // cycle thru block loaders and initialize each loader |
|
166 | - foreach ($this->blocks as $block) { |
|
167 | - $block->initialize(); |
|
168 | - $this->trackAssetManagersForBlocks($block); |
|
169 | - if (! $this->block_asset_manager_collection->has($block->assetManager())) { |
|
170 | - $this->block_asset_manager_collection->add($block->assetManager()); |
|
171 | - $block->assetManager()->setAssetHandles(); |
|
172 | - } |
|
173 | - } |
|
174 | - } catch (Exception $exception) { |
|
175 | - new ExceptionStackTraceDisplay($exception); |
|
176 | - } |
|
177 | - } |
|
155 | + /** |
|
156 | + * populates the BlockCollection and calls initialize() on all installed blocks |
|
157 | + * |
|
158 | + * @return void |
|
159 | + * @throws Exception |
|
160 | + */ |
|
161 | + public function initializeBlocks() |
|
162 | + { |
|
163 | + try { |
|
164 | + $this->populateBlockCollection(); |
|
165 | + // cycle thru block loaders and initialize each loader |
|
166 | + foreach ($this->blocks as $block) { |
|
167 | + $block->initialize(); |
|
168 | + $this->trackAssetManagersForBlocks($block); |
|
169 | + if (! $this->block_asset_manager_collection->has($block->assetManager())) { |
|
170 | + $this->block_asset_manager_collection->add($block->assetManager()); |
|
171 | + $block->assetManager()->setAssetHandles(); |
|
172 | + } |
|
173 | + } |
|
174 | + } catch (Exception $exception) { |
|
175 | + new ExceptionStackTraceDisplay($exception); |
|
176 | + } |
|
177 | + } |
|
178 | 178 | |
179 | 179 | |
180 | - /** |
|
181 | - * track blocks with routes that match the current request |
|
182 | - * |
|
183 | - * @param BlockInterface $block |
|
184 | - * @throws InvalidClassException |
|
185 | - */ |
|
186 | - private function trackAssetManagersForBlocks(BlockInterface $block) |
|
187 | - { |
|
188 | - $supported_routes = $block->supportedRoutes(); |
|
189 | - foreach ($supported_routes as $supported_route) { |
|
190 | - if ($this->route_manager->routeMatchesCurrentRequest($supported_route)) { |
|
191 | - $this->block_asset_managers[ $block->blockType() ] = $block->assetManager()->assetNamespace(); |
|
192 | - } |
|
193 | - } |
|
194 | - } |
|
180 | + /** |
|
181 | + * track blocks with routes that match the current request |
|
182 | + * |
|
183 | + * @param BlockInterface $block |
|
184 | + * @throws InvalidClassException |
|
185 | + */ |
|
186 | + private function trackAssetManagersForBlocks(BlockInterface $block) |
|
187 | + { |
|
188 | + $supported_routes = $block->supportedRoutes(); |
|
189 | + foreach ($supported_routes as $supported_route) { |
|
190 | + if ($this->route_manager->routeMatchesCurrentRequest($supported_route)) { |
|
191 | + $this->block_asset_managers[ $block->blockType() ] = $block->assetManager()->assetNamespace(); |
|
192 | + } |
|
193 | + } |
|
194 | + } |
|
195 | 195 | |
196 | 196 | |
197 | - /** |
|
198 | - * returns true if the block should be registered for the current request |
|
199 | - * else removes block from block_routes array and returns false |
|
200 | - * |
|
201 | - * @param BlockInterface $block |
|
202 | - * @return boolean |
|
203 | - * @throws InvalidClassException |
|
204 | - */ |
|
205 | - public function matchesRoute(BlockInterface $block) |
|
206 | - { |
|
207 | - if (isset($this->block_asset_managers[ $block->blockType() ])) { |
|
208 | - return true; |
|
209 | - } |
|
210 | - unset($this->block_asset_managers[ $block->blockType() ]); |
|
211 | - return false; |
|
212 | - } |
|
197 | + /** |
|
198 | + * returns true if the block should be registered for the current request |
|
199 | + * else removes block from block_routes array and returns false |
|
200 | + * |
|
201 | + * @param BlockInterface $block |
|
202 | + * @return boolean |
|
203 | + * @throws InvalidClassException |
|
204 | + */ |
|
205 | + public function matchesRoute(BlockInterface $block) |
|
206 | + { |
|
207 | + if (isset($this->block_asset_managers[ $block->blockType() ])) { |
|
208 | + return true; |
|
209 | + } |
|
210 | + unset($this->block_asset_managers[ $block->blockType() ]); |
|
211 | + return false; |
|
212 | + } |
|
213 | 213 | |
214 | 214 | |
215 | - /** |
|
216 | - * calls registerBlock() and load assets for all installed blocks |
|
217 | - * |
|
218 | - * @return void |
|
219 | - * @throws Exception |
|
220 | - */ |
|
221 | - public function registerBlocks() |
|
222 | - { |
|
223 | - try { |
|
224 | - // cycle thru block loader folders |
|
225 | - foreach ($this->blocks as $block) { |
|
226 | - if (! $this->matchesRoute($block)) { |
|
227 | - continue; |
|
228 | - } |
|
229 | - // perform any setup required for the block |
|
230 | - $block_type = $block->registerBlock(); |
|
231 | - if (! $block_type instanceof WP_Block_Type) { |
|
232 | - throw new InvalidEntityException($block_type, 'WP_Block_Type'); |
|
233 | - } |
|
234 | - do_action( |
|
235 | - 'FHEE__EventEspresso_core_services_editor_BlockManager__registerBlocks__block_type_registered', |
|
236 | - $block, |
|
237 | - $block_type |
|
238 | - ); |
|
239 | - } |
|
240 | - } catch (Exception $exception) { |
|
241 | - new ExceptionStackTraceDisplay($exception); |
|
242 | - } |
|
243 | - } |
|
215 | + /** |
|
216 | + * calls registerBlock() and load assets for all installed blocks |
|
217 | + * |
|
218 | + * @return void |
|
219 | + * @throws Exception |
|
220 | + */ |
|
221 | + public function registerBlocks() |
|
222 | + { |
|
223 | + try { |
|
224 | + // cycle thru block loader folders |
|
225 | + foreach ($this->blocks as $block) { |
|
226 | + if (! $this->matchesRoute($block)) { |
|
227 | + continue; |
|
228 | + } |
|
229 | + // perform any setup required for the block |
|
230 | + $block_type = $block->registerBlock(); |
|
231 | + if (! $block_type instanceof WP_Block_Type) { |
|
232 | + throw new InvalidEntityException($block_type, 'WP_Block_Type'); |
|
233 | + } |
|
234 | + do_action( |
|
235 | + 'FHEE__EventEspresso_core_services_editor_BlockManager__registerBlocks__block_type_registered', |
|
236 | + $block, |
|
237 | + $block_type |
|
238 | + ); |
|
239 | + } |
|
240 | + } catch (Exception $exception) { |
|
241 | + new ExceptionStackTraceDisplay($exception); |
|
242 | + } |
|
243 | + } |
|
244 | 244 | |
245 | - public function unloadAssets() |
|
246 | - { |
|
247 | - $assets = array_flip($this->block_asset_managers); |
|
248 | - foreach ($this->block_asset_manager_collection as $asset_manager) { |
|
249 | - // if there are no longer any blocks that require these assets, |
|
250 | - if (! isset($assets[ $asset_manager->assetNamespace() ])) { |
|
251 | - // then unset asset enqueueing and bail |
|
252 | - remove_action('wp_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0); |
|
253 | - remove_action('admin_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0); |
|
254 | - remove_action('wp_enqueue_scripts', array($asset_manager, 'addAssets'), 2); |
|
255 | - remove_action('admin_enqueue_scripts', array($asset_manager, 'addAssets'), 2); |
|
256 | - } |
|
257 | - } |
|
258 | - } |
|
245 | + public function unloadAssets() |
|
246 | + { |
|
247 | + $assets = array_flip($this->block_asset_managers); |
|
248 | + foreach ($this->block_asset_manager_collection as $asset_manager) { |
|
249 | + // if there are no longer any blocks that require these assets, |
|
250 | + if (! isset($assets[ $asset_manager->assetNamespace() ])) { |
|
251 | + // then unset asset enqueueing and bail |
|
252 | + remove_action('wp_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0); |
|
253 | + remove_action('admin_enqueue_scripts', array($asset_manager, 'addManifestFile'), 0); |
|
254 | + remove_action('wp_enqueue_scripts', array($asset_manager, 'addAssets'), 2); |
|
255 | + remove_action('admin_enqueue_scripts', array($asset_manager, 'addAssets'), 2); |
|
256 | + } |
|
257 | + } |
|
258 | + } |
|
259 | 259 | } |
@@ -2,12 +2,12 @@ discard block |
||
2 | 2 | <h2><?php esc_html_e('The Default Tickets Manager Has Moved', 'event_espresso'); ?></h2> |
3 | 3 | <p> |
4 | 4 | <?php printf( |
5 | - esc_html__( |
|
6 | - 'The new Advanced Event Editor introduces a better way to manage your events\' default tickets...%1$sright from within the Event Editor.', |
|
7 | - 'event_espresso' |
|
8 | - ), |
|
9 | - '<br />' |
|
10 | - ); ?> |
|
5 | + esc_html__( |
|
6 | + 'The new Advanced Event Editor introduces a better way to manage your events\' default tickets...%1$sright from within the Event Editor.', |
|
7 | + 'event_espresso' |
|
8 | + ), |
|
9 | + '<br />' |
|
10 | + ); ?> |
|
11 | 11 | </p> |
12 | 12 | <h5> |
13 | 13 | <?php esc_html_e('Follow these simple steps:', 'event_espresso'); ?> |
@@ -19,26 +19,26 @@ discard block |
||
19 | 19 | <li> |
20 | 20 | <p> |
21 | 21 | <?php esc_html_e( |
22 | - 'Edit an existing event or create a new event by clicking the "Add New Event" button.', |
|
23 | - 'event_espresso' |
|
24 | - ); ?> |
|
22 | + 'Edit an existing event or create a new event by clicking the "Add New Event" button.', |
|
23 | + 'event_espresso' |
|
24 | + ); ?> |
|
25 | 25 | </p> |
26 | 26 | </li> |
27 | 27 | <li> |
28 | 28 | <p> |
29 | 29 | <?php esc_html_e( |
30 | - 'Scroll down to the bottom of the "Available Tickets" list.', |
|
31 | - 'event_espresso' |
|
32 | - ); ?> |
|
30 | + 'Scroll down to the bottom of the "Available Tickets" list.', |
|
31 | + 'event_espresso' |
|
32 | + ); ?> |
|
33 | 33 | </p> |
34 | 34 | </li> |
35 | 35 | <li> |
36 | 36 | <div> |
37 | 37 | <p> |
38 | 38 | <?php esc_html_e( |
39 | - 'Click on the menu button to the right of the "Add New Ticket" button.', |
|
40 | - 'event_espresso' |
|
41 | - ); ?> |
|
39 | + 'Click on the menu button to the right of the "Add New Ticket" button.', |
|
40 | + 'event_espresso' |
|
41 | + ); ?> |
|
42 | 42 | </p> |
43 | 43 | <img alt='event editor tickets list menu button' |
44 | 44 | class='ee-new-edtr-notice__img' |
@@ -50,9 +50,9 @@ discard block |
||
50 | 50 | <div> |
51 | 51 | <p> |
52 | 52 | <?php esc_html_e( |
53 | - 'Click on the "Default Tickets" option to open the "Default Tickets Manager".', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
53 | + 'Click on the "Default Tickets" option to open the "Default Tickets Manager".', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | <img alt='event editor default tickets menu option' |
58 | 58 | class='ee-new-edtr-notice__img' |
@@ -64,9 +64,9 @@ discard block |
||
64 | 64 | <div> |
65 | 65 | <p> |
66 | 66 | <?php esc_html_e( |
67 | - 'Use existing tickets as templates or create new default tickets from scratch', |
|
68 | - 'event_espresso' |
|
69 | - ); ?> |
|
67 | + 'Use existing tickets as templates or create new default tickets from scratch', |
|
68 | + 'event_espresso' |
|
69 | + ); ?> |
|
70 | 70 | </p> |
71 | 71 | <img alt='the default tickets editor' |
72 | 72 | class="ee-new-edtr-notice__img ee-new-edtr-notice__img--big" |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | </p> |
43 | 43 | <img alt='event editor tickets list menu button' |
44 | 44 | class='ee-new-edtr-notice__img' |
45 | - src='<?php echo esc_url_raw(EE_IMAGES_URL . 'default-tickets-1.png'); ?>' |
|
45 | + src='<?php echo esc_url_raw(EE_IMAGES_URL.'default-tickets-1.png'); ?>' |
|
46 | 46 | /> |
47 | 47 | </div> |
48 | 48 | </li> |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | </p> |
57 | 57 | <img alt='event editor default tickets menu option' |
58 | 58 | class='ee-new-edtr-notice__img' |
59 | - src='<?php echo esc_url_raw(EE_IMAGES_URL . 'default-tickets-2.png'); ?>' |
|
59 | + src='<?php echo esc_url_raw(EE_IMAGES_URL.'default-tickets-2.png'); ?>' |
|
60 | 60 | /> |
61 | 61 | </div> |
62 | 62 | </li> |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | </p> |
71 | 71 | <img alt='the default tickets editor' |
72 | 72 | class="ee-new-edtr-notice__img ee-new-edtr-notice__img--big" |
73 | - src='<?php echo esc_url_raw(EE_IMAGES_URL . 'default-tickets-3.png'); ?>' |
|
73 | + src='<?php echo esc_url_raw(EE_IMAGES_URL.'default-tickets-3.png'); ?>' |
|
74 | 74 | /> |
75 | 75 | </div> |
76 | 76 | </li> |
@@ -63,7 +63,7 @@ |
||
63 | 63 | */ |
64 | 64 | public function allowed(string $feature): bool |
65 | 65 | { |
66 | - $flag = $this->feature_flags[ $feature ] ?? false; |
|
66 | + $flag = $this->feature_flags[$feature] ?? false; |
|
67 | 67 | try { |
68 | 68 | return $flag instanceof CapCheck |
69 | 69 | ? $this->capabilities_checker->processCapCheck($flag) |
@@ -15,80 +15,80 @@ |
||
15 | 15 | */ |
16 | 16 | class FeatureFlags |
17 | 17 | { |
18 | - /** |
|
19 | - * @var CapabilitiesChecker $capabilities_checker |
|
20 | - */ |
|
21 | - private $capabilities_checker; |
|
18 | + /** |
|
19 | + * @var CapabilitiesChecker $capabilities_checker |
|
20 | + */ |
|
21 | + private $capabilities_checker; |
|
22 | 22 | |
23 | - /** |
|
24 | - * array of key value pairs where the key is the feature flag in question |
|
25 | - * and the value is either a boolean or a CapCheck object defining the required permissions |
|
26 | - * example: |
|
27 | - * [ |
|
28 | - * 'use_bulk_edit' => true, |
|
29 | - * 'use_death_ray' => new CapCheck( 'ee-death-ray-cap', 'context-desc' ) |
|
30 | - * ] |
|
31 | - * array is filterable via FHEE__EventEspresso_core_domain_services_capabilities_FeatureFlags |
|
32 | - * |
|
33 | - * @var boolean[]|CapCheck[] |
|
34 | - */ |
|
35 | - private $feature_flags; |
|
23 | + /** |
|
24 | + * array of key value pairs where the key is the feature flag in question |
|
25 | + * and the value is either a boolean or a CapCheck object defining the required permissions |
|
26 | + * example: |
|
27 | + * [ |
|
28 | + * 'use_bulk_edit' => true, |
|
29 | + * 'use_death_ray' => new CapCheck( 'ee-death-ray-cap', 'context-desc' ) |
|
30 | + * ] |
|
31 | + * array is filterable via FHEE__EventEspresso_core_domain_services_capabilities_FeatureFlags |
|
32 | + * |
|
33 | + * @var boolean[]|CapCheck[] |
|
34 | + */ |
|
35 | + private $feature_flags; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @var Domain |
|
39 | - */ |
|
40 | - protected $domain; |
|
37 | + /** |
|
38 | + * @var Domain |
|
39 | + */ |
|
40 | + protected $domain; |
|
41 | 41 | |
42 | 42 | |
43 | - /** |
|
44 | - * FeatureFlags constructor. |
|
45 | - * |
|
46 | - * @param CapabilitiesChecker $capabilities_checker |
|
47 | - * @param Domain $domain |
|
48 | - */ |
|
49 | - public function __construct(CapabilitiesChecker $capabilities_checker, Domain $domain) |
|
50 | - { |
|
51 | - $this->capabilities_checker = $capabilities_checker; |
|
52 | - $this->domain = $domain; |
|
53 | - $this->feature_flags = apply_filters( |
|
54 | - 'FHEE__EventEspresso_core_domain_services_capabilities_FeatureFlags', |
|
55 | - [ |
|
56 | - 'ee_advanced_event_editor' => $this->domain->isCaffeinated() && ! $this->domain->isMultiSite(), |
|
57 | - 'ee_event_editor_bulk_edit' => $this->domain->isCaffeinated() && ! $this->domain->isMultiSite(), |
|
58 | - 'use_default_ticket_manager' => true, |
|
59 | - 'use_event_description_rte' => false, |
|
60 | - 'use_experimental_rte' => false, |
|
61 | - 'use_reg_form_builder' => false, |
|
62 | - 'use_reg_options_meta_box' => false, |
|
63 | - ] |
|
64 | - ); |
|
65 | - } |
|
43 | + /** |
|
44 | + * FeatureFlags constructor. |
|
45 | + * |
|
46 | + * @param CapabilitiesChecker $capabilities_checker |
|
47 | + * @param Domain $domain |
|
48 | + */ |
|
49 | + public function __construct(CapabilitiesChecker $capabilities_checker, Domain $domain) |
|
50 | + { |
|
51 | + $this->capabilities_checker = $capabilities_checker; |
|
52 | + $this->domain = $domain; |
|
53 | + $this->feature_flags = apply_filters( |
|
54 | + 'FHEE__EventEspresso_core_domain_services_capabilities_FeatureFlags', |
|
55 | + [ |
|
56 | + 'ee_advanced_event_editor' => $this->domain->isCaffeinated() && ! $this->domain->isMultiSite(), |
|
57 | + 'ee_event_editor_bulk_edit' => $this->domain->isCaffeinated() && ! $this->domain->isMultiSite(), |
|
58 | + 'use_default_ticket_manager' => true, |
|
59 | + 'use_event_description_rte' => false, |
|
60 | + 'use_experimental_rte' => false, |
|
61 | + 'use_reg_form_builder' => false, |
|
62 | + 'use_reg_options_meta_box' => false, |
|
63 | + ] |
|
64 | + ); |
|
65 | + } |
|
66 | 66 | |
67 | 67 | |
68 | - /** |
|
69 | - * @param string $feature |
|
70 | - * @return bool |
|
71 | - */ |
|
72 | - public function allowed(string $feature): bool |
|
73 | - { |
|
74 | - $flag = $this->feature_flags[ $feature ] ?? false; |
|
75 | - try { |
|
76 | - return $flag instanceof CapCheck |
|
77 | - ? $this->capabilities_checker->processCapCheck($flag) |
|
78 | - : filter_var($flag, FILTER_VALIDATE_BOOLEAN); |
|
79 | - } catch (InsufficientPermissionsException $e) { |
|
80 | - // eat the exception |
|
81 | - } |
|
82 | - return false; |
|
83 | - } |
|
68 | + /** |
|
69 | + * @param string $feature |
|
70 | + * @return bool |
|
71 | + */ |
|
72 | + public function allowed(string $feature): bool |
|
73 | + { |
|
74 | + $flag = $this->feature_flags[ $feature ] ?? false; |
|
75 | + try { |
|
76 | + return $flag instanceof CapCheck |
|
77 | + ? $this->capabilities_checker->processCapCheck($flag) |
|
78 | + : filter_var($flag, FILTER_VALIDATE_BOOLEAN); |
|
79 | + } catch (InsufficientPermissionsException $e) { |
|
80 | + // eat the exception |
|
81 | + } |
|
82 | + return false; |
|
83 | + } |
|
84 | 84 | |
85 | 85 | |
86 | - /** |
|
87 | - * @return array |
|
88 | - */ |
|
89 | - public function getAllowedFeatures(): array |
|
90 | - { |
|
91 | - $allowed = array_filter($this->feature_flags, [$this, 'allowed'], ARRAY_FILTER_USE_KEY); |
|
92 | - return array_keys($allowed); |
|
93 | - } |
|
86 | + /** |
|
87 | + * @return array |
|
88 | + */ |
|
89 | + public function getAllowedFeatures(): array |
|
90 | + { |
|
91 | + $allowed = array_filter($this->feature_flags, [$this, 'allowed'], ARRAY_FILTER_USE_KEY); |
|
92 | + return array_keys($allowed); |
|
93 | + } |
|
94 | 94 | } |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | { |
72 | 72 | $this->_validate_list_requirements(); |
73 | 73 | |
74 | - if (! $this->_data['data'] instanceof EE_Ticket) { |
|
74 | + if ( ! $this->_data['data'] instanceof EE_Ticket) { |
|
75 | 75 | return ''; |
76 | 76 | } |
77 | 77 | |
@@ -82,10 +82,10 @@ discard block |
||
82 | 82 | $addressee_obj = $this->_extra_data['data']; |
83 | 83 | |
84 | 84 | // made it here so we have an EE_Ticket, so we should have what we need. |
85 | - $ticket_line_item = isset($addressee_obj->tickets[ $ticket->ID() ]['line_item']) |
|
86 | - ? $addressee_obj->tickets[ $ticket->ID() ]['line_item'] : null; |
|
87 | - $sub_line_items = isset($addressee_obj->tickets[ $ticket->ID() ]['sub_line_items']) |
|
88 | - ? $addressee_obj->tickets[ $ticket->ID() ]['sub_line_items'] : array(); |
|
85 | + $ticket_line_item = isset($addressee_obj->tickets[$ticket->ID()]['line_item']) |
|
86 | + ? $addressee_obj->tickets[$ticket->ID()]['line_item'] : null; |
|
87 | + $sub_line_items = isset($addressee_obj->tickets[$ticket->ID()]['sub_line_items']) |
|
88 | + ? $addressee_obj->tickets[$ticket->ID()]['sub_line_items'] : array(); |
|
89 | 89 | |
90 | 90 | $template = count($sub_line_items) < 2 ? $templates['ticket_line_item_no_pms'] |
91 | 91 | : $templates['ticket_line_item_pms']; |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | } |
121 | 121 | $this->_validate_list_requirements(); |
122 | 122 | |
123 | - if (! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
123 | + if ( ! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
124 | 124 | return ''; |
125 | 125 | } |
126 | 126 | |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | |
155 | 155 | $this->_validate_list_requirements(); |
156 | 156 | |
157 | - if (! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
157 | + if ( ! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
158 | 158 | return ''; |
159 | 159 | } |
160 | 160 | |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | { |
191 | 191 | $this->_validate_list_requirements(); |
192 | 192 | |
193 | - if (! $this->_data['data'] instanceof EE_Line_Item) { |
|
193 | + if ( ! $this->_data['data'] instanceof EE_Line_Item) { |
|
194 | 194 | return ''; |
195 | 195 | } |
196 | 196 | |
@@ -203,8 +203,8 @@ discard block |
||
203 | 203 | |
204 | 204 | $main_line_item_id = $main_line_item->ID(); |
205 | 205 | |
206 | - $price_mod_line_items = ! empty($addressee_obj->line_items_with_children[ $main_line_item_id ]['children']) |
|
207 | - ? $addressee_obj->line_items_with_children[ $main_line_item_id ]['children'] : array(); |
|
206 | + $price_mod_line_items = ! empty($addressee_obj->line_items_with_children[$main_line_item_id]['children']) |
|
207 | + ? $addressee_obj->line_items_with_children[$main_line_item_id]['children'] : array(); |
|
208 | 208 | |
209 | 209 | $line_item_list = ''; |
210 | 210 |
@@ -20,201 +20,201 @@ |
||
20 | 20 | */ |
21 | 21 | class EE_Line_Item_List_Shortcodes extends EE_Shortcodes |
22 | 22 | { |
23 | - protected function _init_props() |
|
24 | - { |
|
25 | - $this->label = esc_html__('Line Item List Shortcodes', 'event_espresso'); |
|
26 | - $this->description = esc_html__('All shortcodes specific to line item lists', 'event_espresso'); |
|
27 | - $this->_shortcodes = array( |
|
28 | - '[TICKET_LINE_ITEM_LIST]' => esc_html__('Outputs a list of ticket line items.', 'event_espresso'), |
|
29 | - '[TAX_LINE_ITEM_LIST]' => esc_html__('Outputs a list of tax line items.', 'event_espresso'), |
|
30 | - '[ADDITIONAL_LINE_ITEM_LIST]' => esc_html__( |
|
31 | - 'Outputs a list of additional line items (other charges or discounts)', |
|
32 | - 'event_espresso' |
|
33 | - ), |
|
34 | - '[PRICE_MODIFIER_LINE_ITEM_LIST]' => esc_html__('Outputs a list of price modifier line items', 'event_espresso'), |
|
35 | - ); |
|
36 | - } |
|
37 | - |
|
38 | - |
|
39 | - protected function _parser($shortcode) |
|
40 | - { |
|
41 | - |
|
42 | - switch ($shortcode) { |
|
43 | - case '[TICKET_LINE_ITEM_LIST]': |
|
44 | - return $this->_get_ticket_line_item_list(); |
|
45 | - |
|
46 | - case '[TAX_LINE_ITEM_LIST]': |
|
47 | - return $this->_get_tax_line_item_list(); |
|
48 | - |
|
49 | - case '[PRICE_MODIFIER_LINE_ITEM_LIST]': |
|
50 | - return $this->_get_price_mod_line_item_list(); |
|
51 | - |
|
52 | - case '[ADDITIONAL_LINE_ITEM_LIST]': |
|
53 | - return $this->_get_additional_line_item_list(); |
|
54 | - |
|
55 | - default: |
|
56 | - return ''; |
|
57 | - } |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * verify incoming data contains what is needed for retrieving and parsing each ticket line item for an event. |
|
63 | - * |
|
64 | - * @since 4.5.0 |
|
65 | - * |
|
66 | - * @return string parsed ticket line item list. |
|
67 | - */ |
|
68 | - private function _get_ticket_line_item_list() |
|
69 | - { |
|
70 | - $this->_validate_list_requirements(); |
|
71 | - |
|
72 | - if (! $this->_data['data'] instanceof EE_Ticket) { |
|
73 | - return ''; |
|
74 | - } |
|
75 | - |
|
76 | - $valid_shortcodes = array('line_item', 'line_item_list', 'ticket'); |
|
77 | - |
|
78 | - $ticket = $this->_data['data']; |
|
79 | - $templates = $this->_extra_data['template']; |
|
80 | - $addressee_obj = $this->_extra_data['data']; |
|
81 | - |
|
82 | - // made it here so we have an EE_Ticket, so we should have what we need. |
|
83 | - $ticket_line_item = isset($addressee_obj->tickets[ $ticket->ID() ]['line_item']) |
|
84 | - ? $addressee_obj->tickets[ $ticket->ID() ]['line_item'] : null; |
|
85 | - $sub_line_items = isset($addressee_obj->tickets[ $ticket->ID() ]['sub_line_items']) |
|
86 | - ? $addressee_obj->tickets[ $ticket->ID() ]['sub_line_items'] : array(); |
|
87 | - |
|
88 | - $template = count($sub_line_items) < 2 ? $templates['ticket_line_item_no_pms'] |
|
89 | - : $templates['ticket_line_item_pms']; |
|
90 | - |
|
91 | - if (empty($ticket_line_item) || empty($sub_line_items)) { |
|
92 | - return ''; |
|
93 | - } |
|
94 | - |
|
95 | - // now we just return the appropriate template parsed for each ticket. |
|
96 | - return $this->_shortcode_helper->parse_line_item_list_template( |
|
97 | - $template, |
|
98 | - $ticket_line_item, |
|
99 | - $valid_shortcodes, |
|
100 | - $this->_extra_data |
|
101 | - ); |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * Verify incoming data contains what is needed for retrieving and parsing each tax line item for a transaction. |
|
107 | - * |
|
108 | - * @return string parsed tax line item list. |
|
109 | - * @throws EE_Error |
|
110 | - * @since 4.5.0 |
|
111 | - */ |
|
112 | - private function _get_tax_line_item_list() |
|
113 | - { |
|
114 | - /** @var EE_Admin_Config $admin_config */ |
|
115 | - $admin_config = LoaderFactory::getShared(EE_Admin_Config::class); |
|
116 | - if ($admin_config->useAdvancedEditor()) { |
|
117 | - return ''; |
|
118 | - } |
|
119 | - $this->_validate_list_requirements(); |
|
120 | - |
|
121 | - if (! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
122 | - return ''; |
|
123 | - } |
|
124 | - |
|
125 | - // made it here so we're good to go. |
|
126 | - $valid_shortcodes = array('line_item'); |
|
127 | - $templates = $this->_data['template']; |
|
128 | - |
|
129 | - $tax_line_items = $this->_data['data']->tax_line_items; |
|
130 | - $line_item_list = ''; |
|
131 | - foreach ($tax_line_items as $line_item) { |
|
132 | - $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template( |
|
133 | - $templates['tax_line_item_list'], |
|
134 | - $line_item, |
|
135 | - $valid_shortcodes, |
|
136 | - $this->_extra_data |
|
137 | - ); |
|
138 | - } |
|
139 | - |
|
140 | - return $line_item_list; |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * Verify incoming data contains what is needed for retrieving and parsing each other line item for a transaction. |
|
145 | - * |
|
146 | - * @since 4.5.0 |
|
147 | - * |
|
148 | - * @return string parsed other line item list. |
|
149 | - */ |
|
150 | - private function _get_additional_line_item_list() |
|
151 | - { |
|
152 | - |
|
153 | - $this->_validate_list_requirements(); |
|
154 | - |
|
155 | - if (! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
156 | - return ''; |
|
157 | - } |
|
158 | - |
|
159 | - // made it here so we're good to go. |
|
160 | - $valid_shortcodes = array('line_item'); |
|
161 | - $templates = $this->_data['template']; |
|
162 | - |
|
163 | - $additional_line_items = $this->_data['data']->additional_line_items; |
|
164 | - $line_item_list = ''; |
|
165 | - foreach ($additional_line_items as $line_item) { |
|
166 | - $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template( |
|
167 | - $templates['additional_line_item_list'], |
|
168 | - $line_item, |
|
169 | - $valid_shortcodes, |
|
170 | - $this->_extra_data |
|
171 | - ); |
|
172 | - } |
|
173 | - |
|
174 | - |
|
175 | - return $line_item_list; |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * Verify incoming data contains what is needed for retrieving and parsing each price modifier line item for a |
|
181 | - * parent ticket line item. |
|
182 | - * |
|
183 | - * @since 4.5.0 |
|
184 | - * |
|
185 | - * @return string parsed price modifier line item list. |
|
186 | - */ |
|
187 | - private function _get_price_mod_line_item_list() |
|
188 | - { |
|
189 | - $this->_validate_list_requirements(); |
|
190 | - |
|
191 | - if (! $this->_data['data'] instanceof EE_Line_Item) { |
|
192 | - return ''; |
|
193 | - } |
|
194 | - |
|
195 | - // made it here so we're good to go. |
|
196 | - $main_line_item = $this->_data['data']; |
|
197 | - $templates = $this->_extra_data['template']; |
|
198 | - $addressee_obj = $this->_extra_data['data']; |
|
199 | - |
|
200 | - $valid_shortcodes = array('line_item'); |
|
201 | - |
|
202 | - $main_line_item_id = $main_line_item->ID(); |
|
203 | - |
|
204 | - $price_mod_line_items = ! empty($addressee_obj->line_items_with_children[ $main_line_item_id ]['children']) |
|
205 | - ? $addressee_obj->line_items_with_children[ $main_line_item_id ]['children'] : array(); |
|
206 | - |
|
207 | - $line_item_list = ''; |
|
208 | - |
|
209 | - foreach ($price_mod_line_items as $line_item) { |
|
210 | - $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template( |
|
211 | - $templates['price_modifier_line_item_list'], |
|
212 | - $line_item, |
|
213 | - $valid_shortcodes, |
|
214 | - $this->_extra_data |
|
215 | - ); |
|
216 | - } |
|
217 | - |
|
218 | - return $line_item_list; |
|
219 | - } |
|
23 | + protected function _init_props() |
|
24 | + { |
|
25 | + $this->label = esc_html__('Line Item List Shortcodes', 'event_espresso'); |
|
26 | + $this->description = esc_html__('All shortcodes specific to line item lists', 'event_espresso'); |
|
27 | + $this->_shortcodes = array( |
|
28 | + '[TICKET_LINE_ITEM_LIST]' => esc_html__('Outputs a list of ticket line items.', 'event_espresso'), |
|
29 | + '[TAX_LINE_ITEM_LIST]' => esc_html__('Outputs a list of tax line items.', 'event_espresso'), |
|
30 | + '[ADDITIONAL_LINE_ITEM_LIST]' => esc_html__( |
|
31 | + 'Outputs a list of additional line items (other charges or discounts)', |
|
32 | + 'event_espresso' |
|
33 | + ), |
|
34 | + '[PRICE_MODIFIER_LINE_ITEM_LIST]' => esc_html__('Outputs a list of price modifier line items', 'event_espresso'), |
|
35 | + ); |
|
36 | + } |
|
37 | + |
|
38 | + |
|
39 | + protected function _parser($shortcode) |
|
40 | + { |
|
41 | + |
|
42 | + switch ($shortcode) { |
|
43 | + case '[TICKET_LINE_ITEM_LIST]': |
|
44 | + return $this->_get_ticket_line_item_list(); |
|
45 | + |
|
46 | + case '[TAX_LINE_ITEM_LIST]': |
|
47 | + return $this->_get_tax_line_item_list(); |
|
48 | + |
|
49 | + case '[PRICE_MODIFIER_LINE_ITEM_LIST]': |
|
50 | + return $this->_get_price_mod_line_item_list(); |
|
51 | + |
|
52 | + case '[ADDITIONAL_LINE_ITEM_LIST]': |
|
53 | + return $this->_get_additional_line_item_list(); |
|
54 | + |
|
55 | + default: |
|
56 | + return ''; |
|
57 | + } |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * verify incoming data contains what is needed for retrieving and parsing each ticket line item for an event. |
|
63 | + * |
|
64 | + * @since 4.5.0 |
|
65 | + * |
|
66 | + * @return string parsed ticket line item list. |
|
67 | + */ |
|
68 | + private function _get_ticket_line_item_list() |
|
69 | + { |
|
70 | + $this->_validate_list_requirements(); |
|
71 | + |
|
72 | + if (! $this->_data['data'] instanceof EE_Ticket) { |
|
73 | + return ''; |
|
74 | + } |
|
75 | + |
|
76 | + $valid_shortcodes = array('line_item', 'line_item_list', 'ticket'); |
|
77 | + |
|
78 | + $ticket = $this->_data['data']; |
|
79 | + $templates = $this->_extra_data['template']; |
|
80 | + $addressee_obj = $this->_extra_data['data']; |
|
81 | + |
|
82 | + // made it here so we have an EE_Ticket, so we should have what we need. |
|
83 | + $ticket_line_item = isset($addressee_obj->tickets[ $ticket->ID() ]['line_item']) |
|
84 | + ? $addressee_obj->tickets[ $ticket->ID() ]['line_item'] : null; |
|
85 | + $sub_line_items = isset($addressee_obj->tickets[ $ticket->ID() ]['sub_line_items']) |
|
86 | + ? $addressee_obj->tickets[ $ticket->ID() ]['sub_line_items'] : array(); |
|
87 | + |
|
88 | + $template = count($sub_line_items) < 2 ? $templates['ticket_line_item_no_pms'] |
|
89 | + : $templates['ticket_line_item_pms']; |
|
90 | + |
|
91 | + if (empty($ticket_line_item) || empty($sub_line_items)) { |
|
92 | + return ''; |
|
93 | + } |
|
94 | + |
|
95 | + // now we just return the appropriate template parsed for each ticket. |
|
96 | + return $this->_shortcode_helper->parse_line_item_list_template( |
|
97 | + $template, |
|
98 | + $ticket_line_item, |
|
99 | + $valid_shortcodes, |
|
100 | + $this->_extra_data |
|
101 | + ); |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * Verify incoming data contains what is needed for retrieving and parsing each tax line item for a transaction. |
|
107 | + * |
|
108 | + * @return string parsed tax line item list. |
|
109 | + * @throws EE_Error |
|
110 | + * @since 4.5.0 |
|
111 | + */ |
|
112 | + private function _get_tax_line_item_list() |
|
113 | + { |
|
114 | + /** @var EE_Admin_Config $admin_config */ |
|
115 | + $admin_config = LoaderFactory::getShared(EE_Admin_Config::class); |
|
116 | + if ($admin_config->useAdvancedEditor()) { |
|
117 | + return ''; |
|
118 | + } |
|
119 | + $this->_validate_list_requirements(); |
|
120 | + |
|
121 | + if (! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
122 | + return ''; |
|
123 | + } |
|
124 | + |
|
125 | + // made it here so we're good to go. |
|
126 | + $valid_shortcodes = array('line_item'); |
|
127 | + $templates = $this->_data['template']; |
|
128 | + |
|
129 | + $tax_line_items = $this->_data['data']->tax_line_items; |
|
130 | + $line_item_list = ''; |
|
131 | + foreach ($tax_line_items as $line_item) { |
|
132 | + $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template( |
|
133 | + $templates['tax_line_item_list'], |
|
134 | + $line_item, |
|
135 | + $valid_shortcodes, |
|
136 | + $this->_extra_data |
|
137 | + ); |
|
138 | + } |
|
139 | + |
|
140 | + return $line_item_list; |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * Verify incoming data contains what is needed for retrieving and parsing each other line item for a transaction. |
|
145 | + * |
|
146 | + * @since 4.5.0 |
|
147 | + * |
|
148 | + * @return string parsed other line item list. |
|
149 | + */ |
|
150 | + private function _get_additional_line_item_list() |
|
151 | + { |
|
152 | + |
|
153 | + $this->_validate_list_requirements(); |
|
154 | + |
|
155 | + if (! $this->_data['data'] instanceof EE_Messages_Addressee) { |
|
156 | + return ''; |
|
157 | + } |
|
158 | + |
|
159 | + // made it here so we're good to go. |
|
160 | + $valid_shortcodes = array('line_item'); |
|
161 | + $templates = $this->_data['template']; |
|
162 | + |
|
163 | + $additional_line_items = $this->_data['data']->additional_line_items; |
|
164 | + $line_item_list = ''; |
|
165 | + foreach ($additional_line_items as $line_item) { |
|
166 | + $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template( |
|
167 | + $templates['additional_line_item_list'], |
|
168 | + $line_item, |
|
169 | + $valid_shortcodes, |
|
170 | + $this->_extra_data |
|
171 | + ); |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + return $line_item_list; |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * Verify incoming data contains what is needed for retrieving and parsing each price modifier line item for a |
|
181 | + * parent ticket line item. |
|
182 | + * |
|
183 | + * @since 4.5.0 |
|
184 | + * |
|
185 | + * @return string parsed price modifier line item list. |
|
186 | + */ |
|
187 | + private function _get_price_mod_line_item_list() |
|
188 | + { |
|
189 | + $this->_validate_list_requirements(); |
|
190 | + |
|
191 | + if (! $this->_data['data'] instanceof EE_Line_Item) { |
|
192 | + return ''; |
|
193 | + } |
|
194 | + |
|
195 | + // made it here so we're good to go. |
|
196 | + $main_line_item = $this->_data['data']; |
|
197 | + $templates = $this->_extra_data['template']; |
|
198 | + $addressee_obj = $this->_extra_data['data']; |
|
199 | + |
|
200 | + $valid_shortcodes = array('line_item'); |
|
201 | + |
|
202 | + $main_line_item_id = $main_line_item->ID(); |
|
203 | + |
|
204 | + $price_mod_line_items = ! empty($addressee_obj->line_items_with_children[ $main_line_item_id ]['children']) |
|
205 | + ? $addressee_obj->line_items_with_children[ $main_line_item_id ]['children'] : array(); |
|
206 | + |
|
207 | + $line_item_list = ''; |
|
208 | + |
|
209 | + foreach ($price_mod_line_items as $line_item) { |
|
210 | + $line_item_list .= $this->_shortcode_helper->parse_line_item_list_template( |
|
211 | + $templates['price_modifier_line_item_list'], |
|
212 | + $line_item, |
|
213 | + $valid_shortcodes, |
|
214 | + $this->_extra_data |
|
215 | + ); |
|
216 | + } |
|
217 | + |
|
218 | + return $line_item_list; |
|
219 | + } |
|
220 | 220 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | $tax = 0; |
43 | 43 | $total_tax = 0; |
44 | 44 | // This first checks to see if the given ticket is taxable. |
45 | - if (! $ticket->taxable()) { |
|
45 | + if ( ! $ticket->taxable()) { |
|
46 | 46 | return $tax; |
47 | 47 | } |
48 | 48 | // get subtotal (notice we're only retrieving a subtotal if there isn't one given) |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | public static function get_subtotal_for_admin(EE_Ticket $ticket) |
86 | 86 | { |
87 | 87 | $TKT_ID = $ticket->ID(); |
88 | - return EE_Taxes::$_subtotal[ $TKT_ID ] ?? EE_Taxes::_get_subtotal_for_admin($ticket); |
|
88 | + return EE_Taxes::$_subtotal[$TKT_ID] ?? EE_Taxes::_get_subtotal_for_admin($ticket); |
|
89 | 89 | } |
90 | 90 | |
91 | 91 | |
@@ -133,7 +133,7 @@ discard block |
||
133 | 133 | } |
134 | 134 | } |
135 | 135 | $TKT_ID = $ticket->ID(); |
136 | - EE_Taxes::$_subtotal[ $TKT_ID ] = $subtotal; |
|
136 | + EE_Taxes::$_subtotal[$TKT_ID] = $subtotal; |
|
137 | 137 | return $subtotal; |
138 | 138 | } |
139 | 139 |
@@ -11,147 +11,147 @@ |
||
11 | 11 | */ |
12 | 12 | class EE_Taxes extends EE_Base |
13 | 13 | { |
14 | - /** |
|
15 | - * This is used for when EE_Taxes is used statically by the admin |
|
16 | - * |
|
17 | - * @var array |
|
18 | - */ |
|
19 | - private static $_subtotal = []; |
|
14 | + /** |
|
15 | + * This is used for when EE_Taxes is used statically by the admin |
|
16 | + * |
|
17 | + * @var array |
|
18 | + */ |
|
19 | + private static $_subtotal = []; |
|
20 | 20 | |
21 | - /** |
|
22 | - * This holds an array of EE_Price objects that are of PRT_ID == 4 (tax price types) |
|
23 | - * |
|
24 | - * @var EE_Price[] |
|
25 | - */ |
|
26 | - private static $_default_taxes = []; |
|
21 | + /** |
|
22 | + * This holds an array of EE_Price objects that are of PRT_ID == 4 (tax price types) |
|
23 | + * |
|
24 | + * @var EE_Price[] |
|
25 | + */ |
|
26 | + private static $_default_taxes = []; |
|
27 | 27 | |
28 | 28 | |
29 | - /** |
|
30 | - * This method simply calculates the total taxes for a given ticket (by pulling the prices attached to the ticket |
|
31 | - * and applying default taxes to it). Note: this is just an intermediary helper method added to facilitate quick |
|
32 | - * calc of taxes for tickets listed in the event editor. |
|
33 | - * |
|
34 | - * @param EE_Ticket $ticket incoming EE_Ticket |
|
35 | - * @return float total taxes to apply to ticket. |
|
36 | - * @throws EE_Error |
|
37 | - * @throws ReflectionException |
|
38 | - */ |
|
39 | - public static function get_total_taxes_for_admin(EE_Ticket $ticket) |
|
40 | - { |
|
41 | - $tax = 0; |
|
42 | - $total_tax = 0; |
|
43 | - // This first checks to see if the given ticket is taxable. |
|
44 | - if (! $ticket->taxable()) { |
|
45 | - return $tax; |
|
46 | - } |
|
47 | - // get subtotal (notice we're only retrieving a subtotal if there isn't one given) |
|
48 | - $subtotal = EE_Taxes::get_subtotal_for_admin($ticket); |
|
49 | - // get taxes |
|
50 | - $taxes = EE_Taxes::get_taxes_for_admin(); |
|
51 | - // apply taxes to subtotal |
|
52 | - foreach ($taxes as $tax) { |
|
53 | - // assuming taxes are not cumulative |
|
54 | - $total_tax += $subtotal * $tax->amount() / 100; |
|
55 | - } |
|
56 | - return $total_tax; |
|
57 | - } |
|
29 | + /** |
|
30 | + * This method simply calculates the total taxes for a given ticket (by pulling the prices attached to the ticket |
|
31 | + * and applying default taxes to it). Note: this is just an intermediary helper method added to facilitate quick |
|
32 | + * calc of taxes for tickets listed in the event editor. |
|
33 | + * |
|
34 | + * @param EE_Ticket $ticket incoming EE_Ticket |
|
35 | + * @return float total taxes to apply to ticket. |
|
36 | + * @throws EE_Error |
|
37 | + * @throws ReflectionException |
|
38 | + */ |
|
39 | + public static function get_total_taxes_for_admin(EE_Ticket $ticket) |
|
40 | + { |
|
41 | + $tax = 0; |
|
42 | + $total_tax = 0; |
|
43 | + // This first checks to see if the given ticket is taxable. |
|
44 | + if (! $ticket->taxable()) { |
|
45 | + return $tax; |
|
46 | + } |
|
47 | + // get subtotal (notice we're only retrieving a subtotal if there isn't one given) |
|
48 | + $subtotal = EE_Taxes::get_subtotal_for_admin($ticket); |
|
49 | + // get taxes |
|
50 | + $taxes = EE_Taxes::get_taxes_for_admin(); |
|
51 | + // apply taxes to subtotal |
|
52 | + foreach ($taxes as $tax) { |
|
53 | + // assuming taxes are not cumulative |
|
54 | + $total_tax += $subtotal * $tax->amount() / 100; |
|
55 | + } |
|
56 | + return $total_tax; |
|
57 | + } |
|
58 | 58 | |
59 | 59 | |
60 | - /** |
|
61 | - * Gets the total percentage of tax that should be applied to taxable line items |
|
62 | - * |
|
63 | - * @return float the percentage of tax that should be added to taxable items |
|
64 | - * @throws EE_Error |
|
65 | - * @throws ReflectionException |
|
66 | - * eg 20 for %20 tax (NOT 0.20, which |
|
67 | - */ |
|
68 | - public static function get_total_taxes_percentage() |
|
69 | - { |
|
70 | - $total_tax_percent = 0; |
|
71 | - foreach (EE_Taxes::get_taxes_for_admin() as $tax_price) { |
|
72 | - $total_tax_percent += $tax_price->get('PRC_amount'); |
|
73 | - } |
|
74 | - return $total_tax_percent; |
|
75 | - } |
|
60 | + /** |
|
61 | + * Gets the total percentage of tax that should be applied to taxable line items |
|
62 | + * |
|
63 | + * @return float the percentage of tax that should be added to taxable items |
|
64 | + * @throws EE_Error |
|
65 | + * @throws ReflectionException |
|
66 | + * eg 20 for %20 tax (NOT 0.20, which |
|
67 | + */ |
|
68 | + public static function get_total_taxes_percentage() |
|
69 | + { |
|
70 | + $total_tax_percent = 0; |
|
71 | + foreach (EE_Taxes::get_taxes_for_admin() as $tax_price) { |
|
72 | + $total_tax_percent += $tax_price->get('PRC_amount'); |
|
73 | + } |
|
74 | + return $total_tax_percent; |
|
75 | + } |
|
76 | 76 | |
77 | 77 | |
78 | - /** |
|
79 | - * @param EE_Ticket $ticket |
|
80 | - * @return float |
|
81 | - * @throws EE_Error |
|
82 | - * @throws ReflectionException |
|
83 | - */ |
|
84 | - public static function get_subtotal_for_admin(EE_Ticket $ticket) |
|
85 | - { |
|
86 | - $TKT_ID = $ticket->ID(); |
|
87 | - return EE_Taxes::$_subtotal[ $TKT_ID ] ?? EE_Taxes::_get_subtotal_for_admin($ticket); |
|
88 | - } |
|
78 | + /** |
|
79 | + * @param EE_Ticket $ticket |
|
80 | + * @return float |
|
81 | + * @throws EE_Error |
|
82 | + * @throws ReflectionException |
|
83 | + */ |
|
84 | + public static function get_subtotal_for_admin(EE_Ticket $ticket) |
|
85 | + { |
|
86 | + $TKT_ID = $ticket->ID(); |
|
87 | + return EE_Taxes::$_subtotal[ $TKT_ID ] ?? EE_Taxes::_get_subtotal_for_admin($ticket); |
|
88 | + } |
|
89 | 89 | |
90 | 90 | |
91 | - /** |
|
92 | - * simply take an incoming ticket and calculate the subtotal for the ticket |
|
93 | - * |
|
94 | - * @param EE_Ticket $ticket |
|
95 | - * @return float subtotal calculated from all EE_Price[] on Ticket. |
|
96 | - * @throws EE_Error |
|
97 | - * @throws ReflectionException |
|
98 | - */ |
|
99 | - private static function _get_subtotal_for_admin(EE_Ticket $ticket) |
|
100 | - { |
|
101 | - $subtotal = 0; |
|
102 | - // get all prices |
|
103 | - $prices = $ticket->get_many_related( |
|
104 | - 'Price', |
|
105 | - [ |
|
106 | - 0 => [ |
|
107 | - 'Price_Type.PBT_ID' => ['!=', EEM_Price_Type::base_type_tax], |
|
108 | - ], |
|
109 | - 'default_where_conditions' => 'none', |
|
110 | - 'order_by' => ['PRC_order' => 'ASC'], |
|
111 | - ] |
|
112 | - ); |
|
113 | - // let's loop through them (base price is always the first item) |
|
114 | - foreach ($prices as $price) { |
|
115 | - if ($price instanceof EE_Price) { |
|
116 | - $price_type = $price->type_obj(); |
|
117 | - if ($price_type instanceof EE_Price_Type) { |
|
118 | - switch ($price->type_obj()->base_type()) { |
|
119 | - case 1: // base price |
|
120 | - case 3: // surcharges |
|
121 | - $subtotal += $price->is_percent() |
|
122 | - ? $subtotal * $price->get('PRC_amount') / 100 |
|
123 | - : $price->get('PRC_amount'); |
|
124 | - break; |
|
125 | - case 2: // discounts |
|
126 | - $subtotal -= $price->is_percent() |
|
127 | - ? $subtotal * $price->get('PRC_amount') / 100 |
|
128 | - : $price->get('PRC_amount'); |
|
129 | - break; |
|
130 | - } |
|
131 | - } |
|
132 | - } |
|
133 | - } |
|
134 | - $TKT_ID = $ticket->ID(); |
|
135 | - EE_Taxes::$_subtotal[ $TKT_ID ] = $subtotal; |
|
136 | - return $subtotal; |
|
137 | - } |
|
91 | + /** |
|
92 | + * simply take an incoming ticket and calculate the subtotal for the ticket |
|
93 | + * |
|
94 | + * @param EE_Ticket $ticket |
|
95 | + * @return float subtotal calculated from all EE_Price[] on Ticket. |
|
96 | + * @throws EE_Error |
|
97 | + * @throws ReflectionException |
|
98 | + */ |
|
99 | + private static function _get_subtotal_for_admin(EE_Ticket $ticket) |
|
100 | + { |
|
101 | + $subtotal = 0; |
|
102 | + // get all prices |
|
103 | + $prices = $ticket->get_many_related( |
|
104 | + 'Price', |
|
105 | + [ |
|
106 | + 0 => [ |
|
107 | + 'Price_Type.PBT_ID' => ['!=', EEM_Price_Type::base_type_tax], |
|
108 | + ], |
|
109 | + 'default_where_conditions' => 'none', |
|
110 | + 'order_by' => ['PRC_order' => 'ASC'], |
|
111 | + ] |
|
112 | + ); |
|
113 | + // let's loop through them (base price is always the first item) |
|
114 | + foreach ($prices as $price) { |
|
115 | + if ($price instanceof EE_Price) { |
|
116 | + $price_type = $price->type_obj(); |
|
117 | + if ($price_type instanceof EE_Price_Type) { |
|
118 | + switch ($price->type_obj()->base_type()) { |
|
119 | + case 1: // base price |
|
120 | + case 3: // surcharges |
|
121 | + $subtotal += $price->is_percent() |
|
122 | + ? $subtotal * $price->get('PRC_amount') / 100 |
|
123 | + : $price->get('PRC_amount'); |
|
124 | + break; |
|
125 | + case 2: // discounts |
|
126 | + $subtotal -= $price->is_percent() |
|
127 | + ? $subtotal * $price->get('PRC_amount') / 100 |
|
128 | + : $price->get('PRC_amount'); |
|
129 | + break; |
|
130 | + } |
|
131 | + } |
|
132 | + } |
|
133 | + } |
|
134 | + $TKT_ID = $ticket->ID(); |
|
135 | + EE_Taxes::$_subtotal[ $TKT_ID ] = $subtotal; |
|
136 | + return $subtotal; |
|
137 | + } |
|
138 | 138 | |
139 | 139 | |
140 | - /** |
|
141 | - * get all default prices that are a Tax price type (PRT_ID = 4) and return |
|
142 | - * |
|
143 | - * @return EE_Price[] EE_Price objects that have PRT_ID == 4 |
|
144 | - * @throws EE_Error |
|
145 | - */ |
|
146 | - public static function get_taxes_for_admin(): array |
|
147 | - { |
|
148 | - if (empty(EE_Taxes::$_default_taxes)) { |
|
149 | - /** @var EEM_Price $price_model */ |
|
150 | - $price_model = LoaderFactory::getLoader()->getShared('EEM_Price'); |
|
151 | - EE_Taxes::$_default_taxes = $price_model->get_all( |
|
152 | - [['PRC_is_default' => 1, 'Price_Type.PBT_ID' => 4]] |
|
153 | - ); |
|
154 | - } |
|
155 | - return EE_Taxes::$_default_taxes; |
|
156 | - } |
|
140 | + /** |
|
141 | + * get all default prices that are a Tax price type (PRT_ID = 4) and return |
|
142 | + * |
|
143 | + * @return EE_Price[] EE_Price objects that have PRT_ID == 4 |
|
144 | + * @throws EE_Error |
|
145 | + */ |
|
146 | + public static function get_taxes_for_admin(): array |
|
147 | + { |
|
148 | + if (empty(EE_Taxes::$_default_taxes)) { |
|
149 | + /** @var EEM_Price $price_model */ |
|
150 | + $price_model = LoaderFactory::getLoader()->getShared('EEM_Price'); |
|
151 | + EE_Taxes::$_default_taxes = $price_model->get_all( |
|
152 | + [['PRC_is_default' => 1, 'Price_Type.PBT_ID' => 4]] |
|
153 | + ); |
|
154 | + } |
|
155 | + return EE_Taxes::$_default_taxes; |
|
156 | + } |
|
157 | 157 | } |
@@ -15,11 +15,11 @@ |
||
15 | 15 | */ |
16 | 16 | interface EE_Line_Item_Filter |
17 | 17 | { |
18 | - /** |
|
19 | - * process |
|
20 | - * |
|
21 | - * @param EE_Line_Item $line_item |
|
22 | - * @return EE_Line_Item |
|
23 | - */ |
|
24 | - public function process(EE_Line_Item $line_item): ?EE_Line_Item; |
|
18 | + /** |
|
19 | + * process |
|
20 | + * |
|
21 | + * @param EE_Line_Item $line_item |
|
22 | + * @return EE_Line_Item |
|
23 | + */ |
|
24 | + public function process(EE_Line_Item $line_item): ?EE_Line_Item; |
|
25 | 25 | } |
@@ -20,234 +20,234 @@ |
||
20 | 20 | */ |
21 | 21 | class TicketPriceModifiers |
22 | 22 | { |
23 | - /** |
|
24 | - * @var EE_Ticket |
|
25 | - */ |
|
26 | - private $ticket; |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * @var EE_Price[] |
|
31 | - */ |
|
32 | - private $ticket_prices; |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * @param EE_Ticket $ticket |
|
37 | - * @throws EE_Error |
|
38 | - * @throws ReflectionException |
|
39 | - */ |
|
40 | - public function __construct(EE_Ticket $ticket) |
|
41 | - { |
|
42 | - $this->ticket = $ticket; |
|
43 | - // run a query to retrieve ALL of this ticket's related prices before doing anything else |
|
44 | - $this->ticket_prices = $this->ticket->prices(); |
|
45 | - } |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * @param callable $filter |
|
50 | - * @return array |
|
51 | - * @throws EE_Error |
|
52 | - * @throws ReflectionException |
|
53 | - */ |
|
54 | - private function filterModifiersForTicket(callable $filter): array |
|
55 | - { |
|
56 | - $ticket_modifiers = $this->ticket->get_all_from_cache('Price'); |
|
57 | - if (empty($ticket_modifiers)) { |
|
58 | - $ticket_modifiers = $this->ticket_prices; |
|
59 | - } |
|
60 | - return array_filter($ticket_modifiers, $filter); |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * retrieve all price modifiers for the this ticket |
|
66 | - * |
|
67 | - * @return array |
|
68 | - * @throws EE_Error |
|
69 | - * @throws ReflectionException |
|
70 | - */ |
|
71 | - public function getAllModifiersForTicket(): array |
|
72 | - { |
|
73 | - return $this->filterModifiersForTicket([$this, 'allModifiersFilter']); |
|
74 | - } |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * pass to filterModifiersForTicket() with a ticket to retrieve all price modifiers for the this ticket |
|
79 | - * |
|
80 | - * @param EE_Price $price_modifier |
|
81 | - * @return bool |
|
82 | - * @throws EE_Error |
|
83 | - * @throws ReflectionException |
|
84 | - */ |
|
85 | - public function allModifiersFilter(EE_Price $price_modifier): bool |
|
86 | - { |
|
87 | - return ! $price_modifier->is_base_price(); |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * retrieve all discounts for the this ticket |
|
93 | - * |
|
94 | - * @return array |
|
95 | - * @throws EE_Error |
|
96 | - * @throws ReflectionException |
|
97 | - */ |
|
98 | - public function getAllDiscountModifiersForTicket(): array |
|
99 | - { |
|
100 | - return $this->filterModifiersForTicket([$this, 'discountModifierFilter']); |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * pass to filterModifiersForTicket() with a ticket to retrieve all discounts for the this ticket |
|
106 | - * |
|
107 | - * @param EE_Price $price_modifier |
|
108 | - * @return bool |
|
109 | - * @throws EE_Error |
|
110 | - * @throws ReflectionException |
|
111 | - */ |
|
112 | - public function discountModifierFilter(EE_Price $price_modifier): bool |
|
113 | - { |
|
114 | - return $price_modifier->is_discount(); |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * retrieve all surcharges for the this ticket |
|
120 | - * |
|
121 | - * @return array |
|
122 | - * @throws EE_Error |
|
123 | - * @throws ReflectionException |
|
124 | - */ |
|
125 | - public function getAllSurchargeModifiersForTicket(): array |
|
126 | - { |
|
127 | - return $this->filterModifiersForTicket([$this, 'surchargeModifierFilter']); |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * pass to filterModifiersForTicket() with a ticket to retrieve all surcharges for the this ticket |
|
133 | - * |
|
134 | - * @param EE_Price $price_modifier |
|
135 | - * @return bool |
|
136 | - * @throws EE_Error |
|
137 | - * @throws ReflectionException |
|
138 | - */ |
|
139 | - public function surchargeModifierFilter(EE_Price $price_modifier): bool |
|
140 | - { |
|
141 | - return $price_modifier->is_surcharge(); |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * retrieve all discounts AND surcharges for the this ticket |
|
147 | - * |
|
148 | - * @return array |
|
149 | - * @throws EE_Error |
|
150 | - * @throws ReflectionException |
|
151 | - */ |
|
152 | - public function getAllDiscountAndSurchargeModifiersForTicket(): array |
|
153 | - { |
|
154 | - return $this->filterModifiersForTicket([$this, 'discountAndSurchargeModifierFilter']); |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * pass to filterModifiersForTicket() with a ticket to retrieve all discounts AND surcharges for the this ticket |
|
160 | - * |
|
161 | - * @param EE_Price $price_modifier |
|
162 | - * @return bool |
|
163 | - * @throws EE_Error |
|
164 | - * @throws ReflectionException |
|
165 | - */ |
|
166 | - public function discountAndSurchargeModifierFilter(EE_Price $price_modifier): bool |
|
167 | - { |
|
168 | - return $price_modifier->is_discount() || $price_modifier->is_surcharge(); |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - /** |
|
173 | - * retrieve all taxes for the this ticket |
|
174 | - * |
|
175 | - * @return array |
|
176 | - * @throws EE_Error |
|
177 | - * @throws ReflectionException |
|
178 | - */ |
|
179 | - public function getAllTaxesForTicket(): array |
|
180 | - { |
|
181 | - return $this->filterModifiersForTicket([$this, 'taxModifierFilter']); |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * pass to filterModifiersForTicket() with a ticket to retrieve all taxes for the this ticket |
|
187 | - * |
|
188 | - * @param EE_Price $price_modifier |
|
189 | - * @return bool |
|
190 | - * @throws EE_Error |
|
191 | - * @throws ReflectionException |
|
192 | - */ |
|
193 | - public function taxModifierFilter(EE_Price $price_modifier): bool |
|
194 | - { |
|
195 | - return $price_modifier->is_tax(); |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - /** |
|
200 | - * retrieve ALL PRICES that are NOT taxes for the this ticket |
|
201 | - * |
|
202 | - * @return array |
|
203 | - * @throws EE_Error |
|
204 | - * @throws ReflectionException |
|
205 | - */ |
|
206 | - public function getAllNonTaxPricesForTicket(): array |
|
207 | - { |
|
208 | - return $this->filterModifiersForTicket([$this, 'nonTaxPriceFilter']); |
|
209 | - } |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * pass to filterModifiersForTicket() with a ticket |
|
214 | - * to retrieve ALL PRICES that are NOT taxes for the this ticket |
|
215 | - * |
|
216 | - * @param EE_Price $price_modifier |
|
217 | - * @return bool |
|
218 | - * @throws EE_Error |
|
219 | - * @throws ReflectionException |
|
220 | - */ |
|
221 | - public function nonTaxPriceFilter(EE_Price $price_modifier): bool |
|
222 | - { |
|
223 | - return ! $price_modifier->is_base_price() && ! $price_modifier->is_tax(); |
|
224 | - } |
|
225 | - |
|
226 | - |
|
227 | - /** |
|
228 | - * retrieve the base price for the this ticket |
|
229 | - * |
|
230 | - * @return array |
|
231 | - * @throws EE_Error |
|
232 | - * @throws ReflectionException |
|
233 | - */ |
|
234 | - public function getBasePrice(): array |
|
235 | - { |
|
236 | - return $this->filterModifiersForTicket([$this, 'basePriceFilter']); |
|
237 | - } |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * pass to filterModifiersForTicket() |
|
242 | - * to retrieve the base price for the this ticket |
|
243 | - * |
|
244 | - * @param EE_Price $price_modifier |
|
245 | - * @return bool |
|
246 | - * @throws EE_Error |
|
247 | - * @throws ReflectionException |
|
248 | - */ |
|
249 | - public function basePriceFilter(EE_Price $price_modifier): bool |
|
250 | - { |
|
251 | - return $price_modifier->is_base_price(); |
|
252 | - } |
|
23 | + /** |
|
24 | + * @var EE_Ticket |
|
25 | + */ |
|
26 | + private $ticket; |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * @var EE_Price[] |
|
31 | + */ |
|
32 | + private $ticket_prices; |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * @param EE_Ticket $ticket |
|
37 | + * @throws EE_Error |
|
38 | + * @throws ReflectionException |
|
39 | + */ |
|
40 | + public function __construct(EE_Ticket $ticket) |
|
41 | + { |
|
42 | + $this->ticket = $ticket; |
|
43 | + // run a query to retrieve ALL of this ticket's related prices before doing anything else |
|
44 | + $this->ticket_prices = $this->ticket->prices(); |
|
45 | + } |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * @param callable $filter |
|
50 | + * @return array |
|
51 | + * @throws EE_Error |
|
52 | + * @throws ReflectionException |
|
53 | + */ |
|
54 | + private function filterModifiersForTicket(callable $filter): array |
|
55 | + { |
|
56 | + $ticket_modifiers = $this->ticket->get_all_from_cache('Price'); |
|
57 | + if (empty($ticket_modifiers)) { |
|
58 | + $ticket_modifiers = $this->ticket_prices; |
|
59 | + } |
|
60 | + return array_filter($ticket_modifiers, $filter); |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * retrieve all price modifiers for the this ticket |
|
66 | + * |
|
67 | + * @return array |
|
68 | + * @throws EE_Error |
|
69 | + * @throws ReflectionException |
|
70 | + */ |
|
71 | + public function getAllModifiersForTicket(): array |
|
72 | + { |
|
73 | + return $this->filterModifiersForTicket([$this, 'allModifiersFilter']); |
|
74 | + } |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * pass to filterModifiersForTicket() with a ticket to retrieve all price modifiers for the this ticket |
|
79 | + * |
|
80 | + * @param EE_Price $price_modifier |
|
81 | + * @return bool |
|
82 | + * @throws EE_Error |
|
83 | + * @throws ReflectionException |
|
84 | + */ |
|
85 | + public function allModifiersFilter(EE_Price $price_modifier): bool |
|
86 | + { |
|
87 | + return ! $price_modifier->is_base_price(); |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * retrieve all discounts for the this ticket |
|
93 | + * |
|
94 | + * @return array |
|
95 | + * @throws EE_Error |
|
96 | + * @throws ReflectionException |
|
97 | + */ |
|
98 | + public function getAllDiscountModifiersForTicket(): array |
|
99 | + { |
|
100 | + return $this->filterModifiersForTicket([$this, 'discountModifierFilter']); |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * pass to filterModifiersForTicket() with a ticket to retrieve all discounts for the this ticket |
|
106 | + * |
|
107 | + * @param EE_Price $price_modifier |
|
108 | + * @return bool |
|
109 | + * @throws EE_Error |
|
110 | + * @throws ReflectionException |
|
111 | + */ |
|
112 | + public function discountModifierFilter(EE_Price $price_modifier): bool |
|
113 | + { |
|
114 | + return $price_modifier->is_discount(); |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * retrieve all surcharges for the this ticket |
|
120 | + * |
|
121 | + * @return array |
|
122 | + * @throws EE_Error |
|
123 | + * @throws ReflectionException |
|
124 | + */ |
|
125 | + public function getAllSurchargeModifiersForTicket(): array |
|
126 | + { |
|
127 | + return $this->filterModifiersForTicket([$this, 'surchargeModifierFilter']); |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * pass to filterModifiersForTicket() with a ticket to retrieve all surcharges for the this ticket |
|
133 | + * |
|
134 | + * @param EE_Price $price_modifier |
|
135 | + * @return bool |
|
136 | + * @throws EE_Error |
|
137 | + * @throws ReflectionException |
|
138 | + */ |
|
139 | + public function surchargeModifierFilter(EE_Price $price_modifier): bool |
|
140 | + { |
|
141 | + return $price_modifier->is_surcharge(); |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * retrieve all discounts AND surcharges for the this ticket |
|
147 | + * |
|
148 | + * @return array |
|
149 | + * @throws EE_Error |
|
150 | + * @throws ReflectionException |
|
151 | + */ |
|
152 | + public function getAllDiscountAndSurchargeModifiersForTicket(): array |
|
153 | + { |
|
154 | + return $this->filterModifiersForTicket([$this, 'discountAndSurchargeModifierFilter']); |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * pass to filterModifiersForTicket() with a ticket to retrieve all discounts AND surcharges for the this ticket |
|
160 | + * |
|
161 | + * @param EE_Price $price_modifier |
|
162 | + * @return bool |
|
163 | + * @throws EE_Error |
|
164 | + * @throws ReflectionException |
|
165 | + */ |
|
166 | + public function discountAndSurchargeModifierFilter(EE_Price $price_modifier): bool |
|
167 | + { |
|
168 | + return $price_modifier->is_discount() || $price_modifier->is_surcharge(); |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + /** |
|
173 | + * retrieve all taxes for the this ticket |
|
174 | + * |
|
175 | + * @return array |
|
176 | + * @throws EE_Error |
|
177 | + * @throws ReflectionException |
|
178 | + */ |
|
179 | + public function getAllTaxesForTicket(): array |
|
180 | + { |
|
181 | + return $this->filterModifiersForTicket([$this, 'taxModifierFilter']); |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * pass to filterModifiersForTicket() with a ticket to retrieve all taxes for the this ticket |
|
187 | + * |
|
188 | + * @param EE_Price $price_modifier |
|
189 | + * @return bool |
|
190 | + * @throws EE_Error |
|
191 | + * @throws ReflectionException |
|
192 | + */ |
|
193 | + public function taxModifierFilter(EE_Price $price_modifier): bool |
|
194 | + { |
|
195 | + return $price_modifier->is_tax(); |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + /** |
|
200 | + * retrieve ALL PRICES that are NOT taxes for the this ticket |
|
201 | + * |
|
202 | + * @return array |
|
203 | + * @throws EE_Error |
|
204 | + * @throws ReflectionException |
|
205 | + */ |
|
206 | + public function getAllNonTaxPricesForTicket(): array |
|
207 | + { |
|
208 | + return $this->filterModifiersForTicket([$this, 'nonTaxPriceFilter']); |
|
209 | + } |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * pass to filterModifiersForTicket() with a ticket |
|
214 | + * to retrieve ALL PRICES that are NOT taxes for the this ticket |
|
215 | + * |
|
216 | + * @param EE_Price $price_modifier |
|
217 | + * @return bool |
|
218 | + * @throws EE_Error |
|
219 | + * @throws ReflectionException |
|
220 | + */ |
|
221 | + public function nonTaxPriceFilter(EE_Price $price_modifier): bool |
|
222 | + { |
|
223 | + return ! $price_modifier->is_base_price() && ! $price_modifier->is_tax(); |
|
224 | + } |
|
225 | + |
|
226 | + |
|
227 | + /** |
|
228 | + * retrieve the base price for the this ticket |
|
229 | + * |
|
230 | + * @return array |
|
231 | + * @throws EE_Error |
|
232 | + * @throws ReflectionException |
|
233 | + */ |
|
234 | + public function getBasePrice(): array |
|
235 | + { |
|
236 | + return $this->filterModifiersForTicket([$this, 'basePriceFilter']); |
|
237 | + } |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * pass to filterModifiersForTicket() |
|
242 | + * to retrieve the base price for the this ticket |
|
243 | + * |
|
244 | + * @param EE_Price $price_modifier |
|
245 | + * @return bool |
|
246 | + * @throws EE_Error |
|
247 | + * @throws ReflectionException |
|
248 | + */ |
|
249 | + public function basePriceFilter(EE_Price $price_modifier): bool |
|
250 | + { |
|
251 | + return $price_modifier->is_base_price(); |
|
252 | + } |
|
253 | 253 | } |