@@ -12,146 +12,146 @@ |
||
12 | 12 | class EE_Taxes extends EE_Base |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * This is used for when EE_Taxes is used statically by the admin |
|
17 | - * |
|
18 | - * @var array |
|
19 | - */ |
|
20 | - private static $_subtotal = []; |
|
15 | + /** |
|
16 | + * This is used for when EE_Taxes is used statically by the admin |
|
17 | + * |
|
18 | + * @var array |
|
19 | + */ |
|
20 | + private static $_subtotal = []; |
|
21 | 21 | |
22 | - /** |
|
23 | - * This holds an array of EE_Price objects that are of PRT_ID == 4 (tax price types) |
|
24 | - * |
|
25 | - * @var EE_Price[] |
|
26 | - */ |
|
27 | - private static $_default_taxes = []; |
|
22 | + /** |
|
23 | + * This holds an array of EE_Price objects that are of PRT_ID == 4 (tax price types) |
|
24 | + * |
|
25 | + * @var EE_Price[] |
|
26 | + */ |
|
27 | + private static $_default_taxes = []; |
|
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * This method simply calculates the total taxes for a given ticket (by pulling the prices attached to the ticket |
|
32 | - * and applying default taxes to it). Note: this is just an intermediary helper method added to facilitate quick |
|
33 | - * calc of taxes for tickets listed in the event editor. |
|
34 | - * |
|
35 | - * @param EE_Ticket $ticket incoming EE_Ticket |
|
36 | - * @return float total taxes to apply to ticket. |
|
37 | - * @throws EE_Error |
|
38 | - * @throws ReflectionException |
|
39 | - */ |
|
40 | - public static function get_total_taxes_for_admin(EE_Ticket $ticket) |
|
41 | - { |
|
42 | - $tax = 0; |
|
43 | - $total_tax = 0; |
|
44 | - // This first checks to see if the given ticket is taxable. |
|
45 | - if (! $ticket->taxable()) { |
|
46 | - return $tax; |
|
47 | - } |
|
48 | - // get subtotal (notice we're only retrieving a subtotal if there isn't one given) |
|
49 | - $subtotal = EE_Taxes::get_subtotal_for_admin($ticket); |
|
50 | - // get taxes |
|
51 | - $taxes = EE_Taxes::get_taxes_for_admin(); |
|
52 | - // apply taxes to subtotal |
|
53 | - foreach ($taxes as $tax) { |
|
54 | - // assuming taxes are not cumulative |
|
55 | - $total_tax += $subtotal * $tax->amount() / 100; |
|
56 | - } |
|
57 | - return $total_tax; |
|
58 | - } |
|
30 | + /** |
|
31 | + * This method simply calculates the total taxes for a given ticket (by pulling the prices attached to the ticket |
|
32 | + * and applying default taxes to it). Note: this is just an intermediary helper method added to facilitate quick |
|
33 | + * calc of taxes for tickets listed in the event editor. |
|
34 | + * |
|
35 | + * @param EE_Ticket $ticket incoming EE_Ticket |
|
36 | + * @return float total taxes to apply to ticket. |
|
37 | + * @throws EE_Error |
|
38 | + * @throws ReflectionException |
|
39 | + */ |
|
40 | + public static function get_total_taxes_for_admin(EE_Ticket $ticket) |
|
41 | + { |
|
42 | + $tax = 0; |
|
43 | + $total_tax = 0; |
|
44 | + // This first checks to see if the given ticket is taxable. |
|
45 | + if (! $ticket->taxable()) { |
|
46 | + return $tax; |
|
47 | + } |
|
48 | + // get subtotal (notice we're only retrieving a subtotal if there isn't one given) |
|
49 | + $subtotal = EE_Taxes::get_subtotal_for_admin($ticket); |
|
50 | + // get taxes |
|
51 | + $taxes = EE_Taxes::get_taxes_for_admin(); |
|
52 | + // apply taxes to subtotal |
|
53 | + foreach ($taxes as $tax) { |
|
54 | + // assuming taxes are not cumulative |
|
55 | + $total_tax += $subtotal * $tax->amount() / 100; |
|
56 | + } |
|
57 | + return $total_tax; |
|
58 | + } |
|
59 | 59 | |
60 | 60 | |
61 | - /** |
|
62 | - * Gets the total percentage of tax that should be applied to taxable line items |
|
63 | - * |
|
64 | - * @return float the percentage of tax that should be added to taxable items |
|
65 | - * @throws EE_Error |
|
66 | - * @throws ReflectionException |
|
67 | - * eg 20 for %20 tax (NOT 0.20, which |
|
68 | - */ |
|
69 | - public static function get_total_taxes_percentage() |
|
70 | - { |
|
71 | - $total_tax_percent = 0; |
|
72 | - foreach (EE_Taxes::get_taxes_for_admin() as $tax_price) { |
|
73 | - $total_tax_percent += $tax_price->get('PRC_amount'); |
|
74 | - } |
|
75 | - return $total_tax_percent; |
|
76 | - } |
|
61 | + /** |
|
62 | + * Gets the total percentage of tax that should be applied to taxable line items |
|
63 | + * |
|
64 | + * @return float the percentage of tax that should be added to taxable items |
|
65 | + * @throws EE_Error |
|
66 | + * @throws ReflectionException |
|
67 | + * eg 20 for %20 tax (NOT 0.20, which |
|
68 | + */ |
|
69 | + public static function get_total_taxes_percentage() |
|
70 | + { |
|
71 | + $total_tax_percent = 0; |
|
72 | + foreach (EE_Taxes::get_taxes_for_admin() as $tax_price) { |
|
73 | + $total_tax_percent += $tax_price->get('PRC_amount'); |
|
74 | + } |
|
75 | + return $total_tax_percent; |
|
76 | + } |
|
77 | 77 | |
78 | 78 | |
79 | - /** |
|
80 | - * @param EE_Ticket $ticket |
|
81 | - * @return float |
|
82 | - * @throws EE_Error |
|
83 | - * @throws ReflectionException |
|
84 | - */ |
|
85 | - public static function get_subtotal_for_admin(EE_Ticket $ticket) |
|
86 | - { |
|
87 | - $TKT_ID = $ticket->ID(); |
|
88 | - return isset(EE_Taxes::$_subtotal[ $TKT_ID ]) |
|
89 | - ? EE_Taxes::$_subtotal[ $TKT_ID ] |
|
90 | - : EE_Taxes::_get_subtotal_for_admin($ticket); |
|
91 | - } |
|
79 | + /** |
|
80 | + * @param EE_Ticket $ticket |
|
81 | + * @return float |
|
82 | + * @throws EE_Error |
|
83 | + * @throws ReflectionException |
|
84 | + */ |
|
85 | + public static function get_subtotal_for_admin(EE_Ticket $ticket) |
|
86 | + { |
|
87 | + $TKT_ID = $ticket->ID(); |
|
88 | + return isset(EE_Taxes::$_subtotal[ $TKT_ID ]) |
|
89 | + ? EE_Taxes::$_subtotal[ $TKT_ID ] |
|
90 | + : EE_Taxes::_get_subtotal_for_admin($ticket); |
|
91 | + } |
|
92 | 92 | |
93 | 93 | |
94 | - /** |
|
95 | - * simply take an incoming ticket and calculate the subtotal for the ticket |
|
96 | - * |
|
97 | - * @param EE_Ticket $ticket |
|
98 | - * @return float subtotal calculated from all EE_Price[] on Ticket. |
|
99 | - * @throws EE_Error |
|
100 | - * @throws ReflectionException |
|
101 | - */ |
|
102 | - private static function _get_subtotal_for_admin(EE_Ticket $ticket) |
|
103 | - { |
|
104 | - $subtotal = 0; |
|
105 | - // get all prices |
|
106 | - $prices = $ticket->get_many_related( |
|
107 | - 'Price', |
|
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 | - } |
|
94 | + /** |
|
95 | + * simply take an incoming ticket and calculate the subtotal for the ticket |
|
96 | + * |
|
97 | + * @param EE_Ticket $ticket |
|
98 | + * @return float subtotal calculated from all EE_Price[] on Ticket. |
|
99 | + * @throws EE_Error |
|
100 | + * @throws ReflectionException |
|
101 | + */ |
|
102 | + private static function _get_subtotal_for_admin(EE_Ticket $ticket) |
|
103 | + { |
|
104 | + $subtotal = 0; |
|
105 | + // get all prices |
|
106 | + $prices = $ticket->get_many_related( |
|
107 | + 'Price', |
|
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() |
|
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 | - [['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() |
|
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 | + [['Price_Type.PBT_ID' => 4]] |
|
153 | + ); |
|
154 | + } |
|
155 | + return EE_Taxes::$_default_taxes; |
|
156 | + } |
|
157 | 157 | } |
@@ -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,8 +85,8 @@ discard block |
||
85 | 85 | public static function get_subtotal_for_admin(EE_Ticket $ticket) |
86 | 86 | { |
87 | 87 | $TKT_ID = $ticket->ID(); |
88 | - return isset(EE_Taxes::$_subtotal[ $TKT_ID ]) |
|
89 | - ? EE_Taxes::$_subtotal[ $TKT_ID ] |
|
88 | + return isset(EE_Taxes::$_subtotal[$TKT_ID]) |
|
89 | + ? EE_Taxes::$_subtotal[$TKT_ID] |
|
90 | 90 | : EE_Taxes::_get_subtotal_for_admin($ticket); |
91 | 91 | } |
92 | 92 | |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | } |
133 | 133 | } |
134 | 134 | $TKT_ID = $ticket->ID(); |
135 | - EE_Taxes::$_subtotal[ $TKT_ID ] = $subtotal; |
|
135 | + EE_Taxes::$_subtotal[$TKT_ID] = $subtotal; |
|
136 | 136 | return $subtotal; |
137 | 137 | } |
138 | 138 |
@@ -22,322 +22,322 @@ |
||
22 | 22 | class RouteHandler |
23 | 23 | { |
24 | 24 | |
25 | - /** |
|
26 | - * @var LoaderInterface |
|
27 | - */ |
|
28 | - private $loader; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var EE_Maintenance_Mode $maintenance_mode |
|
32 | - */ |
|
33 | - private $maintenance_mode; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var RequestInterface $request |
|
37 | - */ |
|
38 | - private $request; |
|
39 | - |
|
40 | - /** |
|
41 | - * @var RouteMatchSpecificationManager $route_manager |
|
42 | - */ |
|
43 | - private $route_manager; |
|
44 | - |
|
45 | - /** |
|
46 | - * AdminRouter constructor. |
|
47 | - * |
|
48 | - * @param LoaderInterface $loader |
|
49 | - * @param EE_Maintenance_Mode $maintenance_mode |
|
50 | - * @param RequestInterface $request |
|
51 | - * @param RouteMatchSpecificationManager $route_manager |
|
52 | - */ |
|
53 | - public function __construct( |
|
54 | - LoaderInterface $loader, |
|
55 | - EE_Maintenance_Mode $maintenance_mode, |
|
56 | - RequestInterface $request, |
|
57 | - RouteMatchSpecificationManager $route_manager |
|
58 | - ) { |
|
59 | - $this->loader = $loader; |
|
60 | - $this->maintenance_mode = $maintenance_mode; |
|
61 | - $this->request = $request; |
|
62 | - $this->route_manager = $route_manager; |
|
63 | - } |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * @throws Exception |
|
68 | - * @since $VID:$ |
|
69 | - */ |
|
70 | - public function handleAssetManagerRequest() |
|
71 | - { |
|
72 | - try { |
|
73 | - if (! $this->request->isAdmin() |
|
74 | - && ! $this->request->isFrontend() |
|
75 | - && ! $this->request->isIframe() |
|
76 | - && ! $this->request->isWordPressApi() |
|
77 | - ) { |
|
78 | - return; |
|
79 | - } |
|
80 | - $this->loader->getShared('EventEspresso\core\services\assets\Registry'); |
|
81 | - $this->loader->getShared('EventEspresso\core\domain\services\assets\CoreAssetManager'); |
|
82 | - if ($this->canLoadBlocks()) { |
|
83 | - $this->loader->getShared( |
|
84 | - 'EventEspresso\core\services\editor\BlockRegistrationManager' |
|
85 | - ); |
|
86 | - } |
|
87 | - } catch (Exception $exception) { |
|
88 | - new ExceptionStackTraceDisplay($exception); |
|
89 | - } |
|
90 | - } |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * Return whether blocks can be registered/loaded or not. |
|
95 | - * |
|
96 | - * @return bool |
|
97 | - * @since $VID:$ |
|
98 | - */ |
|
99 | - private function canLoadBlocks() |
|
100 | - { |
|
101 | - return apply_filters('FHEE__EE_System__canLoadBlocks', true) |
|
102 | - && function_exists('register_block_type') |
|
103 | - // don't load blocks if in the Divi page builder editor context |
|
104 | - // @see https://github.com/eventespresso/event-espresso-core/issues/814 |
|
105 | - && ! $this->request->getRequestParam('et_fb', false); |
|
106 | - } |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * @throws Exception |
|
111 | - * @since $VID:$ |
|
112 | - */ |
|
113 | - public function handleControllerRequest() |
|
114 | - { |
|
115 | - try { |
|
116 | - $this->handleAdminRequest(); |
|
117 | - $this->handleFrontendRequest(); |
|
118 | - $this->handleWordPressHeartbeatRequest(); |
|
119 | - $this->handleWordPressPluginsPage(); |
|
120 | - } catch (Exception $exception) { |
|
121 | - new ExceptionStackTraceDisplay($exception); |
|
122 | - } |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * @throws Exception |
|
128 | - * @since $VID:$ |
|
129 | - */ |
|
130 | - private function handleAdminRequest() |
|
131 | - { |
|
132 | - try { |
|
133 | - if (! $this->request->isAdmin() || $this->request->isAdminAjax()) { |
|
134 | - return; |
|
135 | - } |
|
136 | - do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
137 | - $this->loader->getShared('EE_Admin'); |
|
138 | - |
|
139 | - EE_Dependency_Map::register_dependencies( |
|
140 | - 'EventEspresso\core\domain\services\assets\EspressoAdminAssetManager', |
|
141 | - [ |
|
142 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
143 | - 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
144 | - 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
145 | - ] |
|
146 | - ); |
|
147 | - $this->loader->getShared('EventEspresso\core\domain\services\assets\EspressoAdminAssetManager'); |
|
148 | - } catch (Exception $exception) { |
|
149 | - new ExceptionStackTraceDisplay($exception); |
|
150 | - } |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * @throws Exception |
|
156 | - * @since $VID:$ |
|
157 | - */ |
|
158 | - private function handleFrontendRequest() |
|
159 | - { |
|
160 | - try { |
|
161 | - // don't load frontend if M-Mode is active or request is not browser HTTP |
|
162 | - if ($this->maintenance_mode->level() || ! $this->request->isFrontend() || ! $this->request->isFrontAjax()) { |
|
163 | - return; |
|
164 | - } |
|
165 | - do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
166 | - $this->loader->getShared('EE_Front_Controller'); |
|
167 | - } catch (Exception $exception) { |
|
168 | - new ExceptionStackTraceDisplay($exception); |
|
169 | - } |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - /** |
|
174 | - * @return bool |
|
175 | - * @since $VID:$ |
|
176 | - */ |
|
177 | - private function isGQLRequest() |
|
178 | - { |
|
179 | - return PHP_VERSION_ID > 70000 |
|
180 | - && ( |
|
181 | - $this->request->isGQL() |
|
182 | - || $this->request->isUnitTesting() |
|
183 | - || $this->route_manager->routeMatchesCurrentRequest( |
|
184 | - 'EventEspresso\core\domain\entities\route_match\specifications\admin\EspressoEventEditor' |
|
185 | - ) |
|
186 | - ); |
|
187 | - } |
|
188 | - |
|
189 | - |
|
190 | - /** |
|
191 | - * @throws Exception |
|
192 | - * @since $VID:$ |
|
193 | - */ |
|
194 | - public function handleGQLRequest() |
|
195 | - { |
|
196 | - try { |
|
197 | - if (! $this->isGQLRequest()) { |
|
198 | - return; |
|
199 | - } |
|
200 | - if (! class_exists('WPGraphQL')) { |
|
201 | - require_once EE_THIRD_PARTY . 'wp-graphql/wp-graphql.php'; |
|
202 | - } |
|
203 | - // load handler for EE GraphQL requests |
|
204 | - $graphQL_manager = $this->loader->getShared( |
|
205 | - 'EventEspresso\core\services\graphql\GraphQLManager' |
|
206 | - ); |
|
207 | - $graphQL_manager->init(); |
|
208 | - } catch (Exception $exception) { |
|
209 | - new ExceptionStackTraceDisplay($exception); |
|
210 | - } |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - /** |
|
215 | - * @throws Exception |
|
216 | - * @since $VID:$ |
|
217 | - */ |
|
218 | - public function handlePersonalDataRequest() |
|
219 | - { |
|
220 | - try { |
|
221 | - // don't load frontend if M-Mode is active or request is not browser HTTP |
|
222 | - if (! $this->request->isAdmin() |
|
223 | - || ! $this->request->isAjax() |
|
224 | - || ! $this->maintenance_mode->models_can_query() |
|
225 | - ) { |
|
226 | - return; |
|
227 | - } |
|
228 | - $this->loader->getShared('EventEspresso\core\services\privacy\erasure\PersonalDataEraserManager'); |
|
229 | - $this->loader->getShared('EventEspresso\core\services\privacy\export\PersonalDataExporterManager'); |
|
230 | - } catch (Exception $exception) { |
|
231 | - new ExceptionStackTraceDisplay($exception); |
|
232 | - } |
|
233 | - } |
|
234 | - |
|
235 | - |
|
236 | - /** |
|
237 | - * @throws Exception |
|
238 | - * @since $VID:$ |
|
239 | - */ |
|
240 | - public function handlePueRequest() |
|
241 | - { |
|
242 | - try { |
|
243 | - if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) { |
|
244 | - // pew pew pew |
|
245 | - $this->loader->getShared('EventEspresso\core\services\licensing\LicenseService'); |
|
246 | - do_action('AHEE__EE_System__brew_espresso__after_pue_init'); |
|
247 | - } |
|
248 | - } catch (Exception $exception) { |
|
249 | - new ExceptionStackTraceDisplay($exception); |
|
250 | - } |
|
251 | - } |
|
252 | - |
|
253 | - |
|
254 | - /** |
|
255 | - * @throws Exception |
|
256 | - * @since $VID:$ |
|
257 | - */ |
|
258 | - public function handleSessionRequest() |
|
259 | - { |
|
260 | - try { |
|
261 | - if (! $this->request->isAdmin() && ! $this->request->isEeAjax() && ! $this->request->isFrontend()) { |
|
262 | - return; |
|
263 | - } |
|
264 | - $this->loader->getShared('EE_Session'); |
|
265 | - } catch (Exception $exception) { |
|
266 | - new ExceptionStackTraceDisplay($exception); |
|
267 | - } |
|
268 | - } |
|
269 | - |
|
270 | - |
|
271 | - /** |
|
272 | - * @throws Exception |
|
273 | - * @since $VID:$ |
|
274 | - */ |
|
275 | - public function handleShortcodesRequest() |
|
276 | - { |
|
277 | - try { |
|
278 | - if (! $this->request->isFrontend() && ! $this->request->isIframe() && ! $this->request->isAjax()) { |
|
279 | - return; |
|
280 | - } |
|
281 | - // load, register, and add shortcodes the new way |
|
282 | - $this->loader->getShared( |
|
283 | - 'EventEspresso\core\services\shortcodes\ShortcodesManager', |
|
284 | - [ |
|
285 | - // and the old way, but we'll put it under control of the new system |
|
286 | - EE_Config::getLegacyShortcodesManager(), |
|
287 | - ] |
|
288 | - ); |
|
289 | - } catch (Exception $exception) { |
|
290 | - new ExceptionStackTraceDisplay($exception); |
|
291 | - } |
|
292 | - } |
|
293 | - |
|
294 | - |
|
295 | - /** |
|
296 | - * @throws Exception |
|
297 | - * @since $VID:$ |
|
298 | - */ |
|
299 | - public function handleWordPressHeartbeatRequest() |
|
300 | - { |
|
301 | - try { |
|
302 | - if (! $this->request->isWordPressHeartbeat()) { |
|
303 | - return; |
|
304 | - } |
|
305 | - $this->loader->getShared('EventEspresso\core\domain\services\admin\ajax\WordpressHeartbeat'); |
|
306 | - } catch (Exception $exception) { |
|
307 | - new ExceptionStackTraceDisplay($exception); |
|
308 | - } |
|
309 | - } |
|
310 | - |
|
311 | - |
|
312 | - /** |
|
313 | - * @throws Exception |
|
314 | - * @since $VID:$ |
|
315 | - */ |
|
316 | - public function handleWordPressPluginsPage() |
|
317 | - { |
|
318 | - try { |
|
319 | - if (! $this->request->isAdmin() |
|
320 | - || ! $this->route_manager->routeMatchesCurrentRequest( |
|
321 | - 'EventEspresso\core\domain\entities\route_match\specifications\admin\WordPressPluginsPage' |
|
322 | - ) |
|
323 | - ) { |
|
324 | - return; |
|
325 | - } |
|
326 | - EE_Dependency_Map::register_dependencies( |
|
327 | - 'EventEspresso\core\domain\services\assets\WordpressPluginsPageAssetManager', |
|
328 | - [ |
|
329 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
330 | - 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
331 | - 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
332 | - 'EventEspresso\core\domain\services\admin\ExitModal' => EE_Dependency_Map::load_from_cache, |
|
333 | - ] |
|
334 | - ); |
|
335 | - $this->loader->getShared('EventEspresso\core\domain\services\assets\WordpressPluginsPageAssetManager'); |
|
336 | - /** @var PluginUpsells $plugin_upsells */ |
|
337 | - $plugin_upsells = $this->loader->getShared('EventEspresso\core\domain\services\admin\PluginUpsells'); |
|
338 | - $plugin_upsells->decafUpsells(); |
|
339 | - } catch (Exception $exception) { |
|
340 | - new ExceptionStackTraceDisplay($exception); |
|
341 | - } |
|
342 | - } |
|
25 | + /** |
|
26 | + * @var LoaderInterface |
|
27 | + */ |
|
28 | + private $loader; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var EE_Maintenance_Mode $maintenance_mode |
|
32 | + */ |
|
33 | + private $maintenance_mode; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var RequestInterface $request |
|
37 | + */ |
|
38 | + private $request; |
|
39 | + |
|
40 | + /** |
|
41 | + * @var RouteMatchSpecificationManager $route_manager |
|
42 | + */ |
|
43 | + private $route_manager; |
|
44 | + |
|
45 | + /** |
|
46 | + * AdminRouter constructor. |
|
47 | + * |
|
48 | + * @param LoaderInterface $loader |
|
49 | + * @param EE_Maintenance_Mode $maintenance_mode |
|
50 | + * @param RequestInterface $request |
|
51 | + * @param RouteMatchSpecificationManager $route_manager |
|
52 | + */ |
|
53 | + public function __construct( |
|
54 | + LoaderInterface $loader, |
|
55 | + EE_Maintenance_Mode $maintenance_mode, |
|
56 | + RequestInterface $request, |
|
57 | + RouteMatchSpecificationManager $route_manager |
|
58 | + ) { |
|
59 | + $this->loader = $loader; |
|
60 | + $this->maintenance_mode = $maintenance_mode; |
|
61 | + $this->request = $request; |
|
62 | + $this->route_manager = $route_manager; |
|
63 | + } |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * @throws Exception |
|
68 | + * @since $VID:$ |
|
69 | + */ |
|
70 | + public function handleAssetManagerRequest() |
|
71 | + { |
|
72 | + try { |
|
73 | + if (! $this->request->isAdmin() |
|
74 | + && ! $this->request->isFrontend() |
|
75 | + && ! $this->request->isIframe() |
|
76 | + && ! $this->request->isWordPressApi() |
|
77 | + ) { |
|
78 | + return; |
|
79 | + } |
|
80 | + $this->loader->getShared('EventEspresso\core\services\assets\Registry'); |
|
81 | + $this->loader->getShared('EventEspresso\core\domain\services\assets\CoreAssetManager'); |
|
82 | + if ($this->canLoadBlocks()) { |
|
83 | + $this->loader->getShared( |
|
84 | + 'EventEspresso\core\services\editor\BlockRegistrationManager' |
|
85 | + ); |
|
86 | + } |
|
87 | + } catch (Exception $exception) { |
|
88 | + new ExceptionStackTraceDisplay($exception); |
|
89 | + } |
|
90 | + } |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * Return whether blocks can be registered/loaded or not. |
|
95 | + * |
|
96 | + * @return bool |
|
97 | + * @since $VID:$ |
|
98 | + */ |
|
99 | + private function canLoadBlocks() |
|
100 | + { |
|
101 | + return apply_filters('FHEE__EE_System__canLoadBlocks', true) |
|
102 | + && function_exists('register_block_type') |
|
103 | + // don't load blocks if in the Divi page builder editor context |
|
104 | + // @see https://github.com/eventespresso/event-espresso-core/issues/814 |
|
105 | + && ! $this->request->getRequestParam('et_fb', false); |
|
106 | + } |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * @throws Exception |
|
111 | + * @since $VID:$ |
|
112 | + */ |
|
113 | + public function handleControllerRequest() |
|
114 | + { |
|
115 | + try { |
|
116 | + $this->handleAdminRequest(); |
|
117 | + $this->handleFrontendRequest(); |
|
118 | + $this->handleWordPressHeartbeatRequest(); |
|
119 | + $this->handleWordPressPluginsPage(); |
|
120 | + } catch (Exception $exception) { |
|
121 | + new ExceptionStackTraceDisplay($exception); |
|
122 | + } |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * @throws Exception |
|
128 | + * @since $VID:$ |
|
129 | + */ |
|
130 | + private function handleAdminRequest() |
|
131 | + { |
|
132 | + try { |
|
133 | + if (! $this->request->isAdmin() || $this->request->isAdminAjax()) { |
|
134 | + return; |
|
135 | + } |
|
136 | + do_action('AHEE__EE_System__load_controllers__load_admin_controllers'); |
|
137 | + $this->loader->getShared('EE_Admin'); |
|
138 | + |
|
139 | + EE_Dependency_Map::register_dependencies( |
|
140 | + 'EventEspresso\core\domain\services\assets\EspressoAdminAssetManager', |
|
141 | + [ |
|
142 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
143 | + 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
144 | + 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
145 | + ] |
|
146 | + ); |
|
147 | + $this->loader->getShared('EventEspresso\core\domain\services\assets\EspressoAdminAssetManager'); |
|
148 | + } catch (Exception $exception) { |
|
149 | + new ExceptionStackTraceDisplay($exception); |
|
150 | + } |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * @throws Exception |
|
156 | + * @since $VID:$ |
|
157 | + */ |
|
158 | + private function handleFrontendRequest() |
|
159 | + { |
|
160 | + try { |
|
161 | + // don't load frontend if M-Mode is active or request is not browser HTTP |
|
162 | + if ($this->maintenance_mode->level() || ! $this->request->isFrontend() || ! $this->request->isFrontAjax()) { |
|
163 | + return; |
|
164 | + } |
|
165 | + do_action('AHEE__EE_System__load_controllers__load_front_controllers'); |
|
166 | + $this->loader->getShared('EE_Front_Controller'); |
|
167 | + } catch (Exception $exception) { |
|
168 | + new ExceptionStackTraceDisplay($exception); |
|
169 | + } |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + /** |
|
174 | + * @return bool |
|
175 | + * @since $VID:$ |
|
176 | + */ |
|
177 | + private function isGQLRequest() |
|
178 | + { |
|
179 | + return PHP_VERSION_ID > 70000 |
|
180 | + && ( |
|
181 | + $this->request->isGQL() |
|
182 | + || $this->request->isUnitTesting() |
|
183 | + || $this->route_manager->routeMatchesCurrentRequest( |
|
184 | + 'EventEspresso\core\domain\entities\route_match\specifications\admin\EspressoEventEditor' |
|
185 | + ) |
|
186 | + ); |
|
187 | + } |
|
188 | + |
|
189 | + |
|
190 | + /** |
|
191 | + * @throws Exception |
|
192 | + * @since $VID:$ |
|
193 | + */ |
|
194 | + public function handleGQLRequest() |
|
195 | + { |
|
196 | + try { |
|
197 | + if (! $this->isGQLRequest()) { |
|
198 | + return; |
|
199 | + } |
|
200 | + if (! class_exists('WPGraphQL')) { |
|
201 | + require_once EE_THIRD_PARTY . 'wp-graphql/wp-graphql.php'; |
|
202 | + } |
|
203 | + // load handler for EE GraphQL requests |
|
204 | + $graphQL_manager = $this->loader->getShared( |
|
205 | + 'EventEspresso\core\services\graphql\GraphQLManager' |
|
206 | + ); |
|
207 | + $graphQL_manager->init(); |
|
208 | + } catch (Exception $exception) { |
|
209 | + new ExceptionStackTraceDisplay($exception); |
|
210 | + } |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + /** |
|
215 | + * @throws Exception |
|
216 | + * @since $VID:$ |
|
217 | + */ |
|
218 | + public function handlePersonalDataRequest() |
|
219 | + { |
|
220 | + try { |
|
221 | + // don't load frontend if M-Mode is active or request is not browser HTTP |
|
222 | + if (! $this->request->isAdmin() |
|
223 | + || ! $this->request->isAjax() |
|
224 | + || ! $this->maintenance_mode->models_can_query() |
|
225 | + ) { |
|
226 | + return; |
|
227 | + } |
|
228 | + $this->loader->getShared('EventEspresso\core\services\privacy\erasure\PersonalDataEraserManager'); |
|
229 | + $this->loader->getShared('EventEspresso\core\services\privacy\export\PersonalDataExporterManager'); |
|
230 | + } catch (Exception $exception) { |
|
231 | + new ExceptionStackTraceDisplay($exception); |
|
232 | + } |
|
233 | + } |
|
234 | + |
|
235 | + |
|
236 | + /** |
|
237 | + * @throws Exception |
|
238 | + * @since $VID:$ |
|
239 | + */ |
|
240 | + public function handlePueRequest() |
|
241 | + { |
|
242 | + try { |
|
243 | + if (is_admin() && apply_filters('FHEE__EE_System__brew_espresso__load_pue', true)) { |
|
244 | + // pew pew pew |
|
245 | + $this->loader->getShared('EventEspresso\core\services\licensing\LicenseService'); |
|
246 | + do_action('AHEE__EE_System__brew_espresso__after_pue_init'); |
|
247 | + } |
|
248 | + } catch (Exception $exception) { |
|
249 | + new ExceptionStackTraceDisplay($exception); |
|
250 | + } |
|
251 | + } |
|
252 | + |
|
253 | + |
|
254 | + /** |
|
255 | + * @throws Exception |
|
256 | + * @since $VID:$ |
|
257 | + */ |
|
258 | + public function handleSessionRequest() |
|
259 | + { |
|
260 | + try { |
|
261 | + if (! $this->request->isAdmin() && ! $this->request->isEeAjax() && ! $this->request->isFrontend()) { |
|
262 | + return; |
|
263 | + } |
|
264 | + $this->loader->getShared('EE_Session'); |
|
265 | + } catch (Exception $exception) { |
|
266 | + new ExceptionStackTraceDisplay($exception); |
|
267 | + } |
|
268 | + } |
|
269 | + |
|
270 | + |
|
271 | + /** |
|
272 | + * @throws Exception |
|
273 | + * @since $VID:$ |
|
274 | + */ |
|
275 | + public function handleShortcodesRequest() |
|
276 | + { |
|
277 | + try { |
|
278 | + if (! $this->request->isFrontend() && ! $this->request->isIframe() && ! $this->request->isAjax()) { |
|
279 | + return; |
|
280 | + } |
|
281 | + // load, register, and add shortcodes the new way |
|
282 | + $this->loader->getShared( |
|
283 | + 'EventEspresso\core\services\shortcodes\ShortcodesManager', |
|
284 | + [ |
|
285 | + // and the old way, but we'll put it under control of the new system |
|
286 | + EE_Config::getLegacyShortcodesManager(), |
|
287 | + ] |
|
288 | + ); |
|
289 | + } catch (Exception $exception) { |
|
290 | + new ExceptionStackTraceDisplay($exception); |
|
291 | + } |
|
292 | + } |
|
293 | + |
|
294 | + |
|
295 | + /** |
|
296 | + * @throws Exception |
|
297 | + * @since $VID:$ |
|
298 | + */ |
|
299 | + public function handleWordPressHeartbeatRequest() |
|
300 | + { |
|
301 | + try { |
|
302 | + if (! $this->request->isWordPressHeartbeat()) { |
|
303 | + return; |
|
304 | + } |
|
305 | + $this->loader->getShared('EventEspresso\core\domain\services\admin\ajax\WordpressHeartbeat'); |
|
306 | + } catch (Exception $exception) { |
|
307 | + new ExceptionStackTraceDisplay($exception); |
|
308 | + } |
|
309 | + } |
|
310 | + |
|
311 | + |
|
312 | + /** |
|
313 | + * @throws Exception |
|
314 | + * @since $VID:$ |
|
315 | + */ |
|
316 | + public function handleWordPressPluginsPage() |
|
317 | + { |
|
318 | + try { |
|
319 | + if (! $this->request->isAdmin() |
|
320 | + || ! $this->route_manager->routeMatchesCurrentRequest( |
|
321 | + 'EventEspresso\core\domain\entities\route_match\specifications\admin\WordPressPluginsPage' |
|
322 | + ) |
|
323 | + ) { |
|
324 | + return; |
|
325 | + } |
|
326 | + EE_Dependency_Map::register_dependencies( |
|
327 | + 'EventEspresso\core\domain\services\assets\WordpressPluginsPageAssetManager', |
|
328 | + [ |
|
329 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
330 | + 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
331 | + 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
332 | + 'EventEspresso\core\domain\services\admin\ExitModal' => EE_Dependency_Map::load_from_cache, |
|
333 | + ] |
|
334 | + ); |
|
335 | + $this->loader->getShared('EventEspresso\core\domain\services\assets\WordpressPluginsPageAssetManager'); |
|
336 | + /** @var PluginUpsells $plugin_upsells */ |
|
337 | + $plugin_upsells = $this->loader->getShared('EventEspresso\core\domain\services\admin\PluginUpsells'); |
|
338 | + $plugin_upsells->decafUpsells(); |
|
339 | + } catch (Exception $exception) { |
|
340 | + new ExceptionStackTraceDisplay($exception); |
|
341 | + } |
|
342 | + } |
|
343 | 343 | } |
@@ -25,105 +25,105 @@ |
||
25 | 25 | class DefaultPrices implements DefaultEntityGeneratorInterface |
26 | 26 | { |
27 | 27 | |
28 | - /** |
|
29 | - * @var EEM_Price $price_model |
|
30 | - */ |
|
31 | - protected $price_model; |
|
28 | + /** |
|
29 | + * @var EEM_Price $price_model |
|
30 | + */ |
|
31 | + protected $price_model; |
|
32 | 32 | |
33 | - /** |
|
34 | - * @var EEM_Price_Type $price_type_model |
|
35 | - */ |
|
36 | - protected $price_type_model; |
|
33 | + /** |
|
34 | + * @var EEM_Price_Type $price_type_model |
|
35 | + */ |
|
36 | + protected $price_type_model; |
|
37 | 37 | |
38 | 38 | |
39 | - /** |
|
40 | - * @param EEM_Price $price_model |
|
41 | - * @param EEM_Price_Type $price_type_model |
|
42 | - */ |
|
43 | - public function __construct(EEM_Price $price_model, EEM_Price_Type $price_type_model) |
|
44 | - { |
|
45 | - $this->price_model = $price_model; |
|
46 | - $this->price_type_model = $price_type_model; |
|
47 | - } |
|
39 | + /** |
|
40 | + * @param EEM_Price $price_model |
|
41 | + * @param EEM_Price_Type $price_type_model |
|
42 | + */ |
|
43 | + public function __construct(EEM_Price $price_model, EEM_Price_Type $price_type_model) |
|
44 | + { |
|
45 | + $this->price_model = $price_model; |
|
46 | + $this->price_type_model = $price_type_model; |
|
47 | + } |
|
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * @param EE_Ticket|EE_Base_Class $entity |
|
52 | - * @return EE_Price[] |
|
53 | - * @throws EE_Error |
|
54 | - * @throws InvalidInterfaceException |
|
55 | - * @throws ReflectionException |
|
56 | - * @since $VID:$ |
|
57 | - */ |
|
58 | - public function create(EE_Base_Class $entity) |
|
59 | - { |
|
60 | - if (! $entity instanceof EE_Ticket) { |
|
61 | - throw new InvalidEntityException($entity, 'EE_Ticket'); |
|
62 | - } |
|
63 | - $new_prices = []; |
|
64 | - $has_base_price = false; |
|
65 | - $default_prices = $this->price_model->get_all_default_prices(false, true); |
|
66 | - if (is_array($default_prices)) { |
|
67 | - foreach ($default_prices as $default_price) { |
|
68 | - if (! $default_price instanceof EE_Price) { |
|
69 | - throw new InvalidEntityException($default_price, 'EE_Price'); |
|
70 | - } |
|
71 | - // assign taxes but don't duplicate them because they operate globally |
|
72 | - if ($default_price->is_tax()) { |
|
73 | - $entity->set_taxable(true); |
|
74 | - $default_price->_add_relation_to($entity, 'Ticket'); |
|
75 | - continue; |
|
76 | - } |
|
77 | - $default_price_clone = clone $default_price; |
|
78 | - $default_price_clone->set('PRC_ID', null); |
|
79 | - $default_price_clone->set('PRC_is_default', false); |
|
80 | - $default_price_clone->save(); |
|
81 | - $default_price_clone->_add_relation_to($entity, 'Ticket'); |
|
82 | - // verify that a base price has been set |
|
83 | - $has_base_price = $default_price_clone->is_base_price() ? true : $has_base_price; |
|
84 | - $new_prices[ $default_price_clone->ID() ] = $default_price_clone; |
|
85 | - } |
|
86 | - } |
|
87 | - if (! $has_base_price) { |
|
88 | - $new_base_price = $this->createNewBasePrice($entity); |
|
89 | - $new_prices[ $new_base_price->ID() ] = $new_base_price; |
|
90 | - } |
|
91 | - $ticket_total = $entity->get_ticket_total_with_taxes(true); |
|
92 | - if ($ticket_total !== $entity->ticket_price()) { |
|
93 | - $entity->set_price($ticket_total); |
|
94 | - $entity->save(); |
|
95 | - } |
|
96 | - return $new_prices; |
|
97 | - } |
|
50 | + /** |
|
51 | + * @param EE_Ticket|EE_Base_Class $entity |
|
52 | + * @return EE_Price[] |
|
53 | + * @throws EE_Error |
|
54 | + * @throws InvalidInterfaceException |
|
55 | + * @throws ReflectionException |
|
56 | + * @since $VID:$ |
|
57 | + */ |
|
58 | + public function create(EE_Base_Class $entity) |
|
59 | + { |
|
60 | + if (! $entity instanceof EE_Ticket) { |
|
61 | + throw new InvalidEntityException($entity, 'EE_Ticket'); |
|
62 | + } |
|
63 | + $new_prices = []; |
|
64 | + $has_base_price = false; |
|
65 | + $default_prices = $this->price_model->get_all_default_prices(false, true); |
|
66 | + if (is_array($default_prices)) { |
|
67 | + foreach ($default_prices as $default_price) { |
|
68 | + if (! $default_price instanceof EE_Price) { |
|
69 | + throw new InvalidEntityException($default_price, 'EE_Price'); |
|
70 | + } |
|
71 | + // assign taxes but don't duplicate them because they operate globally |
|
72 | + if ($default_price->is_tax()) { |
|
73 | + $entity->set_taxable(true); |
|
74 | + $default_price->_add_relation_to($entity, 'Ticket'); |
|
75 | + continue; |
|
76 | + } |
|
77 | + $default_price_clone = clone $default_price; |
|
78 | + $default_price_clone->set('PRC_ID', null); |
|
79 | + $default_price_clone->set('PRC_is_default', false); |
|
80 | + $default_price_clone->save(); |
|
81 | + $default_price_clone->_add_relation_to($entity, 'Ticket'); |
|
82 | + // verify that a base price has been set |
|
83 | + $has_base_price = $default_price_clone->is_base_price() ? true : $has_base_price; |
|
84 | + $new_prices[ $default_price_clone->ID() ] = $default_price_clone; |
|
85 | + } |
|
86 | + } |
|
87 | + if (! $has_base_price) { |
|
88 | + $new_base_price = $this->createNewBasePrice($entity); |
|
89 | + $new_prices[ $new_base_price->ID() ] = $new_base_price; |
|
90 | + } |
|
91 | + $ticket_total = $entity->get_ticket_total_with_taxes(true); |
|
92 | + if ($ticket_total !== $entity->ticket_price()) { |
|
93 | + $entity->set_price($ticket_total); |
|
94 | + $entity->save(); |
|
95 | + } |
|
96 | + return $new_prices; |
|
97 | + } |
|
98 | 98 | |
99 | 99 | |
100 | - /** |
|
101 | - * @param EE_Ticket $ticket |
|
102 | - * @return EE_Price |
|
103 | - * @throws EE_Error |
|
104 | - * @throws ReflectionException |
|
105 | - * @since $VID:$ |
|
106 | - */ |
|
107 | - protected function createNewBasePrice(EE_Ticket $ticket) |
|
108 | - { |
|
109 | - $new_base_price = $this->price_model->get_new_price(); |
|
110 | - $base_price_type = $this->price_type_model->get_one([ |
|
111 | - [ |
|
112 | - 'PBT_ID' => EEM_Price_Type::base_type_base_price |
|
113 | - ] |
|
114 | - ]); |
|
115 | - if (! $base_price_type instanceof EE_Price_Type) { |
|
116 | - throw new RuntimeException( |
|
117 | - esc_html__( |
|
118 | - 'A valid base price type could not be retrieved from the database.', |
|
119 | - 'event_espresso' |
|
120 | - ) |
|
121 | - ); |
|
122 | - } |
|
123 | - $new_base_price->set('PRT_ID', $base_price_type->ID()); |
|
124 | - $new_base_price->set('PRC_is_default', false); |
|
125 | - $new_base_price->save(); |
|
126 | - $new_base_price->_add_relation_to($ticket, 'Ticket'); |
|
127 | - return $new_base_price; |
|
128 | - } |
|
100 | + /** |
|
101 | + * @param EE_Ticket $ticket |
|
102 | + * @return EE_Price |
|
103 | + * @throws EE_Error |
|
104 | + * @throws ReflectionException |
|
105 | + * @since $VID:$ |
|
106 | + */ |
|
107 | + protected function createNewBasePrice(EE_Ticket $ticket) |
|
108 | + { |
|
109 | + $new_base_price = $this->price_model->get_new_price(); |
|
110 | + $base_price_type = $this->price_type_model->get_one([ |
|
111 | + [ |
|
112 | + 'PBT_ID' => EEM_Price_Type::base_type_base_price |
|
113 | + ] |
|
114 | + ]); |
|
115 | + if (! $base_price_type instanceof EE_Price_Type) { |
|
116 | + throw new RuntimeException( |
|
117 | + esc_html__( |
|
118 | + 'A valid base price type could not be retrieved from the database.', |
|
119 | + 'event_espresso' |
|
120 | + ) |
|
121 | + ); |
|
122 | + } |
|
123 | + $new_base_price->set('PRT_ID', $base_price_type->ID()); |
|
124 | + $new_base_price->set('PRC_is_default', false); |
|
125 | + $new_base_price->save(); |
|
126 | + $new_base_price->_add_relation_to($ticket, 'Ticket'); |
|
127 | + return $new_base_price; |
|
128 | + } |
|
129 | 129 | } |
@@ -57,7 +57,7 @@ discard block |
||
57 | 57 | */ |
58 | 58 | public function create(EE_Base_Class $entity) |
59 | 59 | { |
60 | - if (! $entity instanceof EE_Ticket) { |
|
60 | + if ( ! $entity instanceof EE_Ticket) { |
|
61 | 61 | throw new InvalidEntityException($entity, 'EE_Ticket'); |
62 | 62 | } |
63 | 63 | $new_prices = []; |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | $default_prices = $this->price_model->get_all_default_prices(false, true); |
66 | 66 | if (is_array($default_prices)) { |
67 | 67 | foreach ($default_prices as $default_price) { |
68 | - if (! $default_price instanceof EE_Price) { |
|
68 | + if ( ! $default_price instanceof EE_Price) { |
|
69 | 69 | throw new InvalidEntityException($default_price, 'EE_Price'); |
70 | 70 | } |
71 | 71 | // assign taxes but don't duplicate them because they operate globally |
@@ -81,12 +81,12 @@ discard block |
||
81 | 81 | $default_price_clone->_add_relation_to($entity, 'Ticket'); |
82 | 82 | // verify that a base price has been set |
83 | 83 | $has_base_price = $default_price_clone->is_base_price() ? true : $has_base_price; |
84 | - $new_prices[ $default_price_clone->ID() ] = $default_price_clone; |
|
84 | + $new_prices[$default_price_clone->ID()] = $default_price_clone; |
|
85 | 85 | } |
86 | 86 | } |
87 | - if (! $has_base_price) { |
|
87 | + if ( ! $has_base_price) { |
|
88 | 88 | $new_base_price = $this->createNewBasePrice($entity); |
89 | - $new_prices[ $new_base_price->ID() ] = $new_base_price; |
|
89 | + $new_prices[$new_base_price->ID()] = $new_base_price; |
|
90 | 90 | } |
91 | 91 | $ticket_total = $entity->get_ticket_total_with_taxes(true); |
92 | 92 | if ($ticket_total !== $entity->ticket_price()) { |
@@ -112,7 +112,7 @@ discard block |
||
112 | 112 | 'PBT_ID' => EEM_Price_Type::base_type_base_price |
113 | 113 | ] |
114 | 114 | ]); |
115 | - if (! $base_price_type instanceof EE_Price_Type) { |
|
115 | + if ( ! $base_price_type instanceof EE_Price_Type) { |
|
116 | 116 | throw new RuntimeException( |
117 | 117 | esc_html__( |
118 | 118 | 'A valid base price type could not be retrieved from the database.', |
@@ -17,70 +17,70 @@ |
||
17 | 17 | class PluginUpsells |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var DomainInterface |
|
22 | - */ |
|
23 | - private $domain; |
|
20 | + /** |
|
21 | + * @var DomainInterface |
|
22 | + */ |
|
23 | + private $domain; |
|
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * PluginUpsells constructor. |
|
28 | - * |
|
29 | - * @param DomainInterface $domain |
|
30 | - */ |
|
31 | - public function __construct(DomainInterface $domain) |
|
32 | - { |
|
33 | - $this->domain = $domain; |
|
34 | - } |
|
26 | + /** |
|
27 | + * PluginUpsells constructor. |
|
28 | + * |
|
29 | + * @param DomainInterface $domain |
|
30 | + */ |
|
31 | + public function __construct(DomainInterface $domain) |
|
32 | + { |
|
33 | + $this->domain = $domain; |
|
34 | + } |
|
35 | 35 | |
36 | 36 | |
37 | - /** |
|
38 | - * Hook in various upsells for the decaf version of EE. |
|
39 | - */ |
|
40 | - public function decafUpsells() |
|
41 | - { |
|
42 | - if ($this->domain instanceof CaffeinatedInterface && ! $this->domain->isCaffeinated()) { |
|
43 | - add_action('after_plugin_row', array($this, 'doPremiumUpsell'), 10); |
|
44 | - } |
|
45 | - } |
|
37 | + /** |
|
38 | + * Hook in various upsells for the decaf version of EE. |
|
39 | + */ |
|
40 | + public function decafUpsells() |
|
41 | + { |
|
42 | + if ($this->domain instanceof CaffeinatedInterface && ! $this->domain->isCaffeinated()) { |
|
43 | + add_action('after_plugin_row', array($this, 'doPremiumUpsell'), 10); |
|
44 | + } |
|
45 | + } |
|
46 | 46 | |
47 | 47 | |
48 | - /** |
|
49 | - * Callback for `after_plugin_row` to add upsell info |
|
50 | - * |
|
51 | - * @param string $plugin_file |
|
52 | - * @throws DomainException |
|
53 | - */ |
|
54 | - public function doPremiumUpsell($plugin_file) |
|
55 | - { |
|
56 | - if ($plugin_file === $this->domain->pluginBasename()) { |
|
57 | - echo ' |
|
48 | + /** |
|
49 | + * Callback for `after_plugin_row` to add upsell info |
|
50 | + * |
|
51 | + * @param string $plugin_file |
|
52 | + * @throws DomainException |
|
53 | + */ |
|
54 | + public function doPremiumUpsell($plugin_file) |
|
55 | + { |
|
56 | + if ($plugin_file === $this->domain->pluginBasename()) { |
|
57 | + echo ' |
|
58 | 58 | <tr class="ee-upsell-plugin-list-table active"> |
59 | 59 | <th scope="row" class="check-column"></th> |
60 | 60 | <td class="column-primary"> |
61 | 61 | <div class="ee-upsell-col" style="padding:10px 0;"> |
62 | 62 | <a href="https://eventespresso.com/purchase/?slug=ee4-license-personal&utm_source=wp_admin_plugins_screen&utm_medium=link&utm_campaign=plugins_screen_upgrade_link""> |
63 | 63 | <button class="button button-secondary" style="background:#008dcb; border:1px solid #008dcb; color:#fff; ">' |
64 | - . esc_html__('Upgrade for Support', 'event_espresso') |
|
65 | - . '</button> |
|
64 | + . esc_html__('Upgrade for Support', 'event_espresso') |
|
65 | + . '</button> |
|
66 | 66 | </a> |
67 | 67 | </div> |
68 | 68 | </td> |
69 | 69 | <td class="column-description"> |
70 | 70 | <div class="ee-upsell-col plugin-description" style="font-size: .85rem; line-height: 1.2rem; padding:5px 0;">' |
71 | - . sprintf( |
|
72 | - esc_html__( |
|
73 | - 'You\'re missing out on %1$sexpert support%2$s and %1$sone-click updates%2$s!%3$sDon\'t have an Event Espresso support license key? Support the project and buy one today!', |
|
74 | - 'event_espresso' |
|
75 | - ), |
|
76 | - '<strong>', |
|
77 | - '</strong>', |
|
78 | - '<br />' |
|
79 | - ) . |
|
80 | - '</div> |
|
71 | + . sprintf( |
|
72 | + esc_html__( |
|
73 | + 'You\'re missing out on %1$sexpert support%2$s and %1$sone-click updates%2$s!%3$sDon\'t have an Event Espresso support license key? Support the project and buy one today!', |
|
74 | + 'event_espresso' |
|
75 | + ), |
|
76 | + '<strong>', |
|
77 | + '</strong>', |
|
78 | + '<br />' |
|
79 | + ) . |
|
80 | + '</div> |
|
81 | 81 | </td> |
82 | 82 | </tr> |
83 | 83 | '; |
84 | - } |
|
85 | - } |
|
84 | + } |
|
85 | + } |
|
86 | 86 | } |
@@ -76,7 +76,7 @@ |
||
76 | 76 | '<strong>', |
77 | 77 | '</strong>', |
78 | 78 | '<br />' |
79 | - ) . |
|
79 | + ). |
|
80 | 80 | '</div> |
81 | 81 | </td> |
82 | 82 | </tr> |
@@ -13,336 +13,336 @@ |
||
13 | 13 | class EEM_Price extends EEM_Soft_Delete_Base |
14 | 14 | { |
15 | 15 | |
16 | - // private instance of the EEM_Price object |
|
17 | - protected static $_instance; |
|
16 | + // private instance of the EEM_Price object |
|
17 | + protected static $_instance; |
|
18 | 18 | |
19 | 19 | |
20 | - /** |
|
21 | - * private constructor to prevent direct creation |
|
22 | - * |
|
23 | - * @Constructor |
|
24 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings |
|
25 | - * (and any incoming timezone data that gets saved). |
|
26 | - * Note this just sends the timezone info to the date time model field objects. |
|
27 | - * Default is NULL |
|
28 | - * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
29 | - */ |
|
30 | - protected function __construct($timezone) |
|
31 | - { |
|
32 | - require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
33 | - $this->singular_item = __('Price', 'event_espresso'); |
|
34 | - $this->plural_item = __('Prices', 'event_espresso'); |
|
20 | + /** |
|
21 | + * private constructor to prevent direct creation |
|
22 | + * |
|
23 | + * @Constructor |
|
24 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings |
|
25 | + * (and any incoming timezone data that gets saved). |
|
26 | + * Note this just sends the timezone info to the date time model field objects. |
|
27 | + * Default is NULL |
|
28 | + * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
29 | + */ |
|
30 | + protected function __construct($timezone) |
|
31 | + { |
|
32 | + require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
33 | + $this->singular_item = __('Price', 'event_espresso'); |
|
34 | + $this->plural_item = __('Prices', 'event_espresso'); |
|
35 | 35 | |
36 | - $this->_tables = array( |
|
37 | - 'Price' => new EE_Primary_Table('esp_price', 'PRC_ID'), |
|
38 | - ); |
|
39 | - $this->_fields = array( |
|
40 | - 'Price' => array( |
|
41 | - 'PRC_ID' => new EE_Primary_Key_Int_Field( |
|
42 | - 'PRC_ID', |
|
43 | - 'Price ID' |
|
44 | - ), |
|
45 | - 'PRT_ID' => new EE_Foreign_Key_Int_Field( |
|
46 | - 'PRT_ID', |
|
47 | - esc_html__('Price type Id', 'event_espresso'), |
|
48 | - false, |
|
49 | - null, |
|
50 | - 'Price_Type' |
|
51 | - ), |
|
52 | - 'PRC_amount' => new EE_Money_Field( |
|
53 | - 'PRC_amount', |
|
54 | - esc_html__('Price Amount', 'event_espresso'), |
|
55 | - false, |
|
56 | - 0 |
|
57 | - ), |
|
58 | - 'PRC_name' => new EE_Plain_Text_Field( |
|
59 | - 'PRC_name', |
|
60 | - esc_html__('Name of Price', 'event_espresso'), |
|
61 | - false, |
|
62 | - '' |
|
63 | - ), |
|
64 | - 'PRC_desc' => new EE_Post_Content_Field( |
|
65 | - 'PRC_desc', |
|
66 | - esc_html__('Price Description', 'event_espresso'), |
|
67 | - false, |
|
68 | - '' |
|
69 | - ), |
|
70 | - 'PRC_is_default' => new EE_Boolean_Field( |
|
71 | - 'PRC_is_default', |
|
72 | - esc_html__('Flag indicating whether price is a default price', 'event_espresso'), |
|
73 | - false, |
|
74 | - false |
|
75 | - ), |
|
76 | - 'PRC_overrides' => new EE_Integer_Field( |
|
77 | - 'PRC_overrides', |
|
78 | - esc_html__( |
|
79 | - 'Price ID for a global Price that will be overridden by this Price ( for replacing default prices )', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - true, |
|
83 | - 0 |
|
84 | - ), |
|
85 | - 'PRC_order' => new EE_Integer_Field( |
|
86 | - 'PRC_order', |
|
87 | - esc_html__( |
|
88 | - 'Order of Application of Price (lower numbers apply first?)', |
|
89 | - 'event_espresso' |
|
90 | - ), |
|
91 | - false, |
|
92 | - 1 |
|
93 | - ), |
|
94 | - 'PRC_deleted' => new EE_Trashed_Flag_Field( |
|
95 | - 'PRC_deleted', |
|
96 | - esc_html__('Flag Indicating if this has been deleted or not', 'event_espresso'), |
|
97 | - false, |
|
98 | - false |
|
99 | - ), |
|
100 | - 'PRC_parent' => new EE_Integer_Field( |
|
101 | - 'PRC_parent', |
|
102 | - esc_html__('Indicates what PRC_ID is the parent of this PRC_ID', 'event_espresso'), |
|
103 | - true, |
|
104 | - 0 |
|
105 | - ), |
|
106 | - 'PRC_wp_user' => new EE_WP_User_Field( |
|
107 | - 'PRC_wp_user', |
|
108 | - esc_html__('Price Creator ID', 'event_espresso'), |
|
109 | - false |
|
110 | - ), |
|
111 | - ), |
|
112 | - ); |
|
113 | - $this->_model_relations = array( |
|
114 | - 'Ticket' => new EE_HABTM_Relation('Ticket_Price'), |
|
115 | - 'Price_Type' => new EE_Belongs_To_Relation(), |
|
116 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
117 | - ); |
|
118 | - // this model is generally available for reading |
|
119 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = |
|
120 | - new EE_Restriction_Generator_Default_Public( |
|
121 | - 'PRC_is_default', |
|
122 | - 'Ticket.Datetime.Event' |
|
123 | - ); |
|
124 | - // account for default tickets in the caps |
|
125 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
126 | - new EE_Restriction_Generator_Default_Protected( |
|
127 | - 'PRC_is_default', |
|
128 | - 'Ticket.Datetime.Event' |
|
129 | - ); |
|
130 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = |
|
131 | - new EE_Restriction_Generator_Default_Protected( |
|
132 | - 'PRC_is_default', |
|
133 | - 'Ticket.Datetime.Event' |
|
134 | - ); |
|
135 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
136 | - new EE_Restriction_Generator_Default_Protected( |
|
137 | - 'PRC_is_default', |
|
138 | - 'Ticket.Datetime.Event' |
|
139 | - ); |
|
140 | - parent::__construct($timezone); |
|
141 | - } |
|
36 | + $this->_tables = array( |
|
37 | + 'Price' => new EE_Primary_Table('esp_price', 'PRC_ID'), |
|
38 | + ); |
|
39 | + $this->_fields = array( |
|
40 | + 'Price' => array( |
|
41 | + 'PRC_ID' => new EE_Primary_Key_Int_Field( |
|
42 | + 'PRC_ID', |
|
43 | + 'Price ID' |
|
44 | + ), |
|
45 | + 'PRT_ID' => new EE_Foreign_Key_Int_Field( |
|
46 | + 'PRT_ID', |
|
47 | + esc_html__('Price type Id', 'event_espresso'), |
|
48 | + false, |
|
49 | + null, |
|
50 | + 'Price_Type' |
|
51 | + ), |
|
52 | + 'PRC_amount' => new EE_Money_Field( |
|
53 | + 'PRC_amount', |
|
54 | + esc_html__('Price Amount', 'event_espresso'), |
|
55 | + false, |
|
56 | + 0 |
|
57 | + ), |
|
58 | + 'PRC_name' => new EE_Plain_Text_Field( |
|
59 | + 'PRC_name', |
|
60 | + esc_html__('Name of Price', 'event_espresso'), |
|
61 | + false, |
|
62 | + '' |
|
63 | + ), |
|
64 | + 'PRC_desc' => new EE_Post_Content_Field( |
|
65 | + 'PRC_desc', |
|
66 | + esc_html__('Price Description', 'event_espresso'), |
|
67 | + false, |
|
68 | + '' |
|
69 | + ), |
|
70 | + 'PRC_is_default' => new EE_Boolean_Field( |
|
71 | + 'PRC_is_default', |
|
72 | + esc_html__('Flag indicating whether price is a default price', 'event_espresso'), |
|
73 | + false, |
|
74 | + false |
|
75 | + ), |
|
76 | + 'PRC_overrides' => new EE_Integer_Field( |
|
77 | + 'PRC_overrides', |
|
78 | + esc_html__( |
|
79 | + 'Price ID for a global Price that will be overridden by this Price ( for replacing default prices )', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + true, |
|
83 | + 0 |
|
84 | + ), |
|
85 | + 'PRC_order' => new EE_Integer_Field( |
|
86 | + 'PRC_order', |
|
87 | + esc_html__( |
|
88 | + 'Order of Application of Price (lower numbers apply first?)', |
|
89 | + 'event_espresso' |
|
90 | + ), |
|
91 | + false, |
|
92 | + 1 |
|
93 | + ), |
|
94 | + 'PRC_deleted' => new EE_Trashed_Flag_Field( |
|
95 | + 'PRC_deleted', |
|
96 | + esc_html__('Flag Indicating if this has been deleted or not', 'event_espresso'), |
|
97 | + false, |
|
98 | + false |
|
99 | + ), |
|
100 | + 'PRC_parent' => new EE_Integer_Field( |
|
101 | + 'PRC_parent', |
|
102 | + esc_html__('Indicates what PRC_ID is the parent of this PRC_ID', 'event_espresso'), |
|
103 | + true, |
|
104 | + 0 |
|
105 | + ), |
|
106 | + 'PRC_wp_user' => new EE_WP_User_Field( |
|
107 | + 'PRC_wp_user', |
|
108 | + esc_html__('Price Creator ID', 'event_espresso'), |
|
109 | + false |
|
110 | + ), |
|
111 | + ), |
|
112 | + ); |
|
113 | + $this->_model_relations = array( |
|
114 | + 'Ticket' => new EE_HABTM_Relation('Ticket_Price'), |
|
115 | + 'Price_Type' => new EE_Belongs_To_Relation(), |
|
116 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
117 | + ); |
|
118 | + // this model is generally available for reading |
|
119 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = |
|
120 | + new EE_Restriction_Generator_Default_Public( |
|
121 | + 'PRC_is_default', |
|
122 | + 'Ticket.Datetime.Event' |
|
123 | + ); |
|
124 | + // account for default tickets in the caps |
|
125 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
126 | + new EE_Restriction_Generator_Default_Protected( |
|
127 | + 'PRC_is_default', |
|
128 | + 'Ticket.Datetime.Event' |
|
129 | + ); |
|
130 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = |
|
131 | + new EE_Restriction_Generator_Default_Protected( |
|
132 | + 'PRC_is_default', |
|
133 | + 'Ticket.Datetime.Event' |
|
134 | + ); |
|
135 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
136 | + new EE_Restriction_Generator_Default_Protected( |
|
137 | + 'PRC_is_default', |
|
138 | + 'Ticket.Datetime.Event' |
|
139 | + ); |
|
140 | + parent::__construct($timezone); |
|
141 | + } |
|
142 | 142 | |
143 | 143 | |
144 | - /** |
|
145 | - * instantiate a new price object with blank/empty properties |
|
146 | - * |
|
147 | - * @return mixed array on success, FALSE on fail |
|
148 | - */ |
|
149 | - public function get_new_price() |
|
150 | - { |
|
151 | - return $this->create_default_object(); |
|
152 | - } |
|
144 | + /** |
|
145 | + * instantiate a new price object with blank/empty properties |
|
146 | + * |
|
147 | + * @return mixed array on success, FALSE on fail |
|
148 | + */ |
|
149 | + public function get_new_price() |
|
150 | + { |
|
151 | + return $this->create_default_object(); |
|
152 | + } |
|
153 | 153 | |
154 | 154 | |
155 | - /** |
|
156 | - * retrieve ALL prices from db |
|
157 | - * |
|
158 | - * @return EE_Base_Class[]|EE_PRice[] |
|
159 | - * @throws EE_Error |
|
160 | - */ |
|
161 | - public function get_all_prices() |
|
162 | - { |
|
163 | - // retrieve all prices |
|
164 | - return $this->get_all(array('order_by' => array('PRC_amount' => 'ASC'))); |
|
165 | - } |
|
155 | + /** |
|
156 | + * retrieve ALL prices from db |
|
157 | + * |
|
158 | + * @return EE_Base_Class[]|EE_PRice[] |
|
159 | + * @throws EE_Error |
|
160 | + */ |
|
161 | + public function get_all_prices() |
|
162 | + { |
|
163 | + // retrieve all prices |
|
164 | + return $this->get_all(array('order_by' => array('PRC_amount' => 'ASC'))); |
|
165 | + } |
|
166 | 166 | |
167 | 167 | |
168 | - /** |
|
169 | - * retrieve all active prices for a particular event |
|
170 | - * |
|
171 | - * @param int $EVT_ID |
|
172 | - * @return array on success |
|
173 | - * @throws EE_Error |
|
174 | - */ |
|
175 | - public function get_all_event_prices($EVT_ID = 0) |
|
176 | - { |
|
177 | - return $this->get_all(array( |
|
178 | - array( |
|
179 | - 'EVT_ID' => $EVT_ID, |
|
180 | - 'Price_Type.PBT_ID' => array('!=', EEM_Price_Type::base_type_tax), |
|
181 | - ), |
|
182 | - 'order_by' => $this->_order_by_array_for_get_all_method(), |
|
183 | - )); |
|
184 | - } |
|
168 | + /** |
|
169 | + * retrieve all active prices for a particular event |
|
170 | + * |
|
171 | + * @param int $EVT_ID |
|
172 | + * @return array on success |
|
173 | + * @throws EE_Error |
|
174 | + */ |
|
175 | + public function get_all_event_prices($EVT_ID = 0) |
|
176 | + { |
|
177 | + return $this->get_all(array( |
|
178 | + array( |
|
179 | + 'EVT_ID' => $EVT_ID, |
|
180 | + 'Price_Type.PBT_ID' => array('!=', EEM_Price_Type::base_type_tax), |
|
181 | + ), |
|
182 | + 'order_by' => $this->_order_by_array_for_get_all_method(), |
|
183 | + )); |
|
184 | + } |
|
185 | 185 | |
186 | 186 | |
187 | - /** |
|
188 | - * retrieve all active global prices (that are not taxes (PBT_ID=4)) for a particular event |
|
189 | - * |
|
190 | - * @param boolean $count return count |
|
191 | - * @param bool $include_taxes |
|
192 | - * @return bool|EE_Base_Class[]|EE_PRice[] |
|
193 | - * @throws EE_Error |
|
194 | - */ |
|
195 | - public function get_all_default_prices($count = false, $include_taxes = false) |
|
196 | - { |
|
197 | - $_where = array( |
|
198 | - 'PRC_deleted' => 0, |
|
199 | - 'PRC_is_default' => 1, |
|
200 | - ); |
|
201 | - if (!$include_taxes) { |
|
202 | - $_where['Price_Type.PBT_ID'] = ['!=', 4]; |
|
203 | - } |
|
204 | - $_query_params = array( |
|
205 | - $_where, |
|
206 | - 'order_by' => $this->_order_by_array_for_get_all_method(), |
|
207 | - ); |
|
208 | - return $count ? $this->count(array($_where)) : $this->get_all($_query_params); |
|
209 | - } |
|
187 | + /** |
|
188 | + * retrieve all active global prices (that are not taxes (PBT_ID=4)) for a particular event |
|
189 | + * |
|
190 | + * @param boolean $count return count |
|
191 | + * @param bool $include_taxes |
|
192 | + * @return bool|EE_Base_Class[]|EE_PRice[] |
|
193 | + * @throws EE_Error |
|
194 | + */ |
|
195 | + public function get_all_default_prices($count = false, $include_taxes = false) |
|
196 | + { |
|
197 | + $_where = array( |
|
198 | + 'PRC_deleted' => 0, |
|
199 | + 'PRC_is_default' => 1, |
|
200 | + ); |
|
201 | + if (!$include_taxes) { |
|
202 | + $_where['Price_Type.PBT_ID'] = ['!=', 4]; |
|
203 | + } |
|
204 | + $_query_params = array( |
|
205 | + $_where, |
|
206 | + 'order_by' => $this->_order_by_array_for_get_all_method(), |
|
207 | + ); |
|
208 | + return $count ? $this->count(array($_where)) : $this->get_all($_query_params); |
|
209 | + } |
|
210 | 210 | |
211 | 211 | |
212 | - /** |
|
213 | - * retrieve all prices that are taxes |
|
214 | - * |
|
215 | - * @return EE_Base_Class[]|EE_PRice[] |
|
216 | - * @throws EE_Error |
|
217 | - * @throws InvalidArgumentException |
|
218 | - * @throws ReflectionException |
|
219 | - * @throws InvalidDataTypeException |
|
220 | - * @throws InvalidInterfaceException |
|
221 | - */ |
|
222 | - public function get_all_prices_that_are_taxes() |
|
223 | - { |
|
224 | - $taxes = array(); |
|
225 | - $all_taxes = $this->get_all(array( |
|
226 | - array('Price_Type.PBT_ID' => EEM_Price_Type::base_type_tax), |
|
227 | - 'order_by' => array('Price_Type.PRT_order' => 'ASC', 'PRC_order' => 'ASC'), |
|
228 | - )); |
|
229 | - foreach ($all_taxes as $tax) { |
|
230 | - if ($tax instanceof EE_Price) { |
|
231 | - $taxes[ $tax->order() ][ $tax->ID() ] = $tax; |
|
232 | - } |
|
233 | - } |
|
234 | - return $taxes; |
|
235 | - } |
|
212 | + /** |
|
213 | + * retrieve all prices that are taxes |
|
214 | + * |
|
215 | + * @return EE_Base_Class[]|EE_PRice[] |
|
216 | + * @throws EE_Error |
|
217 | + * @throws InvalidArgumentException |
|
218 | + * @throws ReflectionException |
|
219 | + * @throws InvalidDataTypeException |
|
220 | + * @throws InvalidInterfaceException |
|
221 | + */ |
|
222 | + public function get_all_prices_that_are_taxes() |
|
223 | + { |
|
224 | + $taxes = array(); |
|
225 | + $all_taxes = $this->get_all(array( |
|
226 | + array('Price_Type.PBT_ID' => EEM_Price_Type::base_type_tax), |
|
227 | + 'order_by' => array('Price_Type.PRT_order' => 'ASC', 'PRC_order' => 'ASC'), |
|
228 | + )); |
|
229 | + foreach ($all_taxes as $tax) { |
|
230 | + if ($tax instanceof EE_Price) { |
|
231 | + $taxes[ $tax->order() ][ $tax->ID() ] = $tax; |
|
232 | + } |
|
233 | + } |
|
234 | + return $taxes; |
|
235 | + } |
|
236 | 236 | |
237 | 237 | |
238 | - /** |
|
239 | - * retrieve all prices for an ticket plus default global prices, but not taxes |
|
240 | - * |
|
241 | - * @param int $TKT_ID the id of the event. If not included then we assume that this is a new ticket. |
|
242 | - * @return EE_Base_Class[]|EE_PRice[]|boolean |
|
243 | - * @throws EE_Error |
|
244 | - */ |
|
245 | - public function get_all_ticket_prices_for_admin($TKT_ID = 0) |
|
246 | - { |
|
247 | - $array_of_price_objects = array(); |
|
248 | - if (empty($TKT_ID)) { |
|
249 | - // if there is no tkt, get prices with no tkt ID, are global, are not a tax, and are active |
|
250 | - // return that list |
|
251 | - $default_prices = $this->get_all_default_prices(); |
|
238 | + /** |
|
239 | + * retrieve all prices for an ticket plus default global prices, but not taxes |
|
240 | + * |
|
241 | + * @param int $TKT_ID the id of the event. If not included then we assume that this is a new ticket. |
|
242 | + * @return EE_Base_Class[]|EE_PRice[]|boolean |
|
243 | + * @throws EE_Error |
|
244 | + */ |
|
245 | + public function get_all_ticket_prices_for_admin($TKT_ID = 0) |
|
246 | + { |
|
247 | + $array_of_price_objects = array(); |
|
248 | + if (empty($TKT_ID)) { |
|
249 | + // if there is no tkt, get prices with no tkt ID, are global, are not a tax, and are active |
|
250 | + // return that list |
|
251 | + $default_prices = $this->get_all_default_prices(); |
|
252 | 252 | |
253 | - if ($default_prices) { |
|
254 | - foreach ($default_prices as $price) { |
|
255 | - if ($price instanceof EE_Price) { |
|
256 | - $array_of_price_objects[ $price->type() ][] = $price; |
|
257 | - } |
|
258 | - } |
|
259 | - return $array_of_price_objects; |
|
260 | - } |
|
261 | - return array(); |
|
262 | - } |
|
263 | - $ticket_prices = $this->get_all(array( |
|
264 | - array( |
|
265 | - 'TKT_ID' => $TKT_ID, |
|
266 | - 'PRC_deleted' => 0, |
|
267 | - ), |
|
268 | - 'order_by' => array('PRC_order' => 'ASC'), |
|
269 | - )); |
|
253 | + if ($default_prices) { |
|
254 | + foreach ($default_prices as $price) { |
|
255 | + if ($price instanceof EE_Price) { |
|
256 | + $array_of_price_objects[ $price->type() ][] = $price; |
|
257 | + } |
|
258 | + } |
|
259 | + return $array_of_price_objects; |
|
260 | + } |
|
261 | + return array(); |
|
262 | + } |
|
263 | + $ticket_prices = $this->get_all(array( |
|
264 | + array( |
|
265 | + 'TKT_ID' => $TKT_ID, |
|
266 | + 'PRC_deleted' => 0, |
|
267 | + ), |
|
268 | + 'order_by' => array('PRC_order' => 'ASC'), |
|
269 | + )); |
|
270 | 270 | |
271 | - if (! empty($ticket_prices)) { |
|
272 | - foreach ($ticket_prices as $price) { |
|
273 | - if ($price instanceof EE_Price) { |
|
274 | - $array_of_price_objects[ $price->type() ][] = $price; |
|
275 | - } |
|
276 | - } |
|
277 | - return $array_of_price_objects; |
|
278 | - } |
|
279 | - return false; |
|
280 | - } |
|
271 | + if (! empty($ticket_prices)) { |
|
272 | + foreach ($ticket_prices as $price) { |
|
273 | + if ($price instanceof EE_Price) { |
|
274 | + $array_of_price_objects[ $price->type() ][] = $price; |
|
275 | + } |
|
276 | + } |
|
277 | + return $array_of_price_objects; |
|
278 | + } |
|
279 | + return false; |
|
280 | + } |
|
281 | 281 | |
282 | 282 | |
283 | - /** |
|
284 | - * _sort_event_prices_by_type |
|
285 | - * |
|
286 | - * @param EE_Price $price_a |
|
287 | - * @param EE_Price $price_b |
|
288 | - * @return bool false on fail |
|
289 | - */ |
|
290 | - public function _sort_event_prices_by_type(EE_Price $price_a, EE_Price $price_b) |
|
291 | - { |
|
292 | - if ($price_a->type_obj()->order() === $price_b->type_obj()->order()) { |
|
293 | - return $this->_sort_event_prices_by_order($price_a, $price_b); |
|
294 | - } |
|
295 | - return $price_a->type_obj()->order() < $price_b->type_obj()->order() ? -1 : 1; |
|
296 | - } |
|
283 | + /** |
|
284 | + * _sort_event_prices_by_type |
|
285 | + * |
|
286 | + * @param EE_Price $price_a |
|
287 | + * @param EE_Price $price_b |
|
288 | + * @return bool false on fail |
|
289 | + */ |
|
290 | + public function _sort_event_prices_by_type(EE_Price $price_a, EE_Price $price_b) |
|
291 | + { |
|
292 | + if ($price_a->type_obj()->order() === $price_b->type_obj()->order()) { |
|
293 | + return $this->_sort_event_prices_by_order($price_a, $price_b); |
|
294 | + } |
|
295 | + return $price_a->type_obj()->order() < $price_b->type_obj()->order() ? -1 : 1; |
|
296 | + } |
|
297 | 297 | |
298 | 298 | |
299 | - /** |
|
300 | - * _sort_event_prices_by_order |
|
301 | - * |
|
302 | - * @param EE_Price $price_a |
|
303 | - * @param EE_Price $price_b |
|
304 | - * @return bool false on fail |
|
305 | - */ |
|
306 | - public function _sort_event_prices_by_order(EE_Price $price_a, EE_Price $price_b) |
|
307 | - { |
|
308 | - if ($price_a->order() === $price_b->order()) { |
|
309 | - return 0; |
|
310 | - } |
|
311 | - return $price_a->order() < $price_b->order() ? -1 : 1; |
|
312 | - } |
|
299 | + /** |
|
300 | + * _sort_event_prices_by_order |
|
301 | + * |
|
302 | + * @param EE_Price $price_a |
|
303 | + * @param EE_Price $price_b |
|
304 | + * @return bool false on fail |
|
305 | + */ |
|
306 | + public function _sort_event_prices_by_order(EE_Price $price_a, EE_Price $price_b) |
|
307 | + { |
|
308 | + if ($price_a->order() === $price_b->order()) { |
|
309 | + return 0; |
|
310 | + } |
|
311 | + return $price_a->order() < $price_b->order() ? -1 : 1; |
|
312 | + } |
|
313 | 313 | |
314 | 314 | |
315 | - /** |
|
316 | - * get all prices of a specific type |
|
317 | - * |
|
318 | - * @param int $type - PRT_ID |
|
319 | - * @return EE_Base_Class[]|EE_PRice[] |
|
320 | - * @throws EE_Error |
|
321 | - */ |
|
322 | - public function get_all_prices_that_are_type($type = 0) |
|
323 | - { |
|
324 | - return $this->get_all(array( |
|
325 | - array( |
|
326 | - 'PRT_ID' => $type, |
|
327 | - ), |
|
328 | - 'order_by' => $this->_order_by_array_for_get_all_method(), |
|
329 | - )); |
|
330 | - } |
|
315 | + /** |
|
316 | + * get all prices of a specific type |
|
317 | + * |
|
318 | + * @param int $type - PRT_ID |
|
319 | + * @return EE_Base_Class[]|EE_PRice[] |
|
320 | + * @throws EE_Error |
|
321 | + */ |
|
322 | + public function get_all_prices_that_are_type($type = 0) |
|
323 | + { |
|
324 | + return $this->get_all(array( |
|
325 | + array( |
|
326 | + 'PRT_ID' => $type, |
|
327 | + ), |
|
328 | + 'order_by' => $this->_order_by_array_for_get_all_method(), |
|
329 | + )); |
|
330 | + } |
|
331 | 331 | |
332 | 332 | |
333 | - /** |
|
334 | - * Returns an array of the normal 'order_by' query parameter provided to the get_all query. |
|
335 | - * Of course you don't have to use it, but this is the order we usually want to sort prices by |
|
336 | - * |
|
337 | - * @return array which can be used like so: $this->get_all(array(array(...where |
|
338 | - * stuff...),'order_by'=>$this->_order_by_array_for_get_all_method())); |
|
339 | - */ |
|
340 | - public function _order_by_array_for_get_all_method() |
|
341 | - { |
|
342 | - return array( |
|
343 | - 'PRC_order' => 'ASC', |
|
344 | - 'Price_Type.PRT_order' => 'ASC', |
|
345 | - 'PRC_ID' => 'ASC', |
|
346 | - ); |
|
347 | - } |
|
333 | + /** |
|
334 | + * Returns an array of the normal 'order_by' query parameter provided to the get_all query. |
|
335 | + * Of course you don't have to use it, but this is the order we usually want to sort prices by |
|
336 | + * |
|
337 | + * @return array which can be used like so: $this->get_all(array(array(...where |
|
338 | + * stuff...),'order_by'=>$this->_order_by_array_for_get_all_method())); |
|
339 | + */ |
|
340 | + public function _order_by_array_for_get_all_method() |
|
341 | + { |
|
342 | + return array( |
|
343 | + 'PRC_order' => 'ASC', |
|
344 | + 'Price_Type.PRT_order' => 'ASC', |
|
345 | + 'PRC_ID' => 'ASC', |
|
346 | + ); |
|
347 | + } |
|
348 | 348 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | */ |
30 | 30 | protected function __construct($timezone) |
31 | 31 | { |
32 | - require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
32 | + require_once(EE_MODELS.'EEM_Price_Type.model.php'); |
|
33 | 33 | $this->singular_item = __('Price', 'event_espresso'); |
34 | 34 | $this->plural_item = __('Prices', 'event_espresso'); |
35 | 35 | |
@@ -116,23 +116,23 @@ discard block |
||
116 | 116 | 'WP_User' => new EE_Belongs_To_Relation(), |
117 | 117 | ); |
118 | 118 | // this model is generally available for reading |
119 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = |
|
119 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = |
|
120 | 120 | new EE_Restriction_Generator_Default_Public( |
121 | 121 | 'PRC_is_default', |
122 | 122 | 'Ticket.Datetime.Event' |
123 | 123 | ); |
124 | 124 | // account for default tickets in the caps |
125 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
125 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = |
|
126 | 126 | new EE_Restriction_Generator_Default_Protected( |
127 | 127 | 'PRC_is_default', |
128 | 128 | 'Ticket.Datetime.Event' |
129 | 129 | ); |
130 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = |
|
130 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = |
|
131 | 131 | new EE_Restriction_Generator_Default_Protected( |
132 | 132 | 'PRC_is_default', |
133 | 133 | 'Ticket.Datetime.Event' |
134 | 134 | ); |
135 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
135 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = |
|
136 | 136 | new EE_Restriction_Generator_Default_Protected( |
137 | 137 | 'PRC_is_default', |
138 | 138 | 'Ticket.Datetime.Event' |
@@ -198,8 +198,8 @@ discard block |
||
198 | 198 | 'PRC_deleted' => 0, |
199 | 199 | 'PRC_is_default' => 1, |
200 | 200 | ); |
201 | - if (!$include_taxes) { |
|
202 | - $_where['Price_Type.PBT_ID'] = ['!=', 4]; |
|
201 | + if ( ! $include_taxes) { |
|
202 | + $_where['Price_Type.PBT_ID'] = ['!=', 4]; |
|
203 | 203 | } |
204 | 204 | $_query_params = array( |
205 | 205 | $_where, |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | )); |
229 | 229 | foreach ($all_taxes as $tax) { |
230 | 230 | if ($tax instanceof EE_Price) { |
231 | - $taxes[ $tax->order() ][ $tax->ID() ] = $tax; |
|
231 | + $taxes[$tax->order()][$tax->ID()] = $tax; |
|
232 | 232 | } |
233 | 233 | } |
234 | 234 | return $taxes; |
@@ -253,7 +253,7 @@ discard block |
||
253 | 253 | if ($default_prices) { |
254 | 254 | foreach ($default_prices as $price) { |
255 | 255 | if ($price instanceof EE_Price) { |
256 | - $array_of_price_objects[ $price->type() ][] = $price; |
|
256 | + $array_of_price_objects[$price->type()][] = $price; |
|
257 | 257 | } |
258 | 258 | } |
259 | 259 | return $array_of_price_objects; |
@@ -268,10 +268,10 @@ discard block |
||
268 | 268 | 'order_by' => array('PRC_order' => 'ASC'), |
269 | 269 | )); |
270 | 270 | |
271 | - if (! empty($ticket_prices)) { |
|
271 | + if ( ! empty($ticket_prices)) { |
|
272 | 272 | foreach ($ticket_prices as $price) { |
273 | 273 | if ($price instanceof EE_Price) { |
274 | - $array_of_price_objects[ $price->type() ][] = $price; |
|
274 | + $array_of_price_objects[$price->type()][] = $price; |
|
275 | 275 | } |
276 | 276 | } |
277 | 277 | return $array_of_price_objects; |