@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
4 | 4 | use EventEspresso\core\services\loaders\LoaderInterface; |
5 | 5 | |
6 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
6 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
7 | 7 | exit('No direct script access allowed'); |
8 | 8 | } |
9 | 9 | |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | public static function instance(EE_Request $request = null, EE_Response $response = null) |
117 | 117 | { |
118 | 118 | // check if class object is instantiated, and instantiated properly |
119 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
119 | + if ( ! self::$_instance instanceof EE_Dependency_Map) { |
|
120 | 120 | self::$_instance = new EE_Dependency_Map($request, $response); |
121 | 121 | } |
122 | 122 | return self::$_instance; |
@@ -141,15 +141,15 @@ discard block |
||
141 | 141 | */ |
142 | 142 | public static function register_dependencies($class, $dependencies) |
143 | 143 | { |
144 | - if (! isset(self::$_instance->_dependency_map[$class])) { |
|
144 | + if ( ! isset(self::$_instance->_dependency_map[$class])) { |
|
145 | 145 | // we need to make sure that any aliases used when registering a dependency |
146 | 146 | // get resolved to the correct class name |
147 | - foreach ((array)$dependencies as $dependency => $load_source) { |
|
147 | + foreach ((array) $dependencies as $dependency => $load_source) { |
|
148 | 148 | $alias = self::$_instance->get_alias($dependency); |
149 | 149 | unset($dependencies[$dependency]); |
150 | 150 | $dependencies[$alias] = $load_source; |
151 | 151 | } |
152 | - self::$_instance->_dependency_map[$class] = (array)$dependencies; |
|
152 | + self::$_instance->_dependency_map[$class] = (array) $dependencies; |
|
153 | 153 | return true; |
154 | 154 | } |
155 | 155 | return false; |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | ); |
182 | 182 | } |
183 | 183 | $class_name = self::$_instance->get_alias($class_name); |
184 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
184 | + if ( ! isset(self::$_instance->_class_loaders[$class_name])) { |
|
185 | 185 | self::$_instance->_class_loaders[$class_name] = $loader; |
186 | 186 | return true; |
187 | 187 | } |
@@ -279,7 +279,7 @@ discard block |
||
279 | 279 | public function add_alias($class_name, $alias, $for_class = '') |
280 | 280 | { |
281 | 281 | if ($for_class !== '') { |
282 | - if (! isset($this->_aliases[$for_class])) { |
|
282 | + if ( ! isset($this->_aliases[$for_class])) { |
|
283 | 283 | $this->_aliases[$for_class] = array(); |
284 | 284 | } |
285 | 285 | $this->_aliases[$for_class][$class_name] = $alias; |
@@ -324,7 +324,7 @@ discard block |
||
324 | 324 | */ |
325 | 325 | public function get_alias($class_name = '', $for_class = '') |
326 | 326 | { |
327 | - if (! $this->has_alias($class_name, $for_class)) { |
|
327 | + if ( ! $this->has_alias($class_name, $for_class)) { |
|
328 | 328 | return $class_name; |
329 | 329 | } |
330 | 330 | if ($for_class !== '') { |
@@ -526,10 +526,10 @@ discard block |
||
526 | 526 | 'EE_Front_Controller' => 'load_core', |
527 | 527 | 'EE_Module_Request_Router' => 'load_core', |
528 | 528 | 'EE_Registry' => 'load_core', |
529 | - 'EE_Request' => function () use (&$request) { |
|
529 | + 'EE_Request' => function() use (&$request) { |
|
530 | 530 | return $request; |
531 | 531 | }, |
532 | - 'EE_Response' => function () use (&$response) { |
|
532 | + 'EE_Response' => function() use (&$response) { |
|
533 | 533 | return $response; |
534 | 534 | }, |
535 | 535 | 'EE_Request_Handler' => 'load_core', |
@@ -546,10 +546,10 @@ discard block |
||
546 | 546 | 'EE_Messages_Queue' => 'load_lib', |
547 | 547 | 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
548 | 548 | 'EE_Message_Template_Group_Collection' => 'load_lib', |
549 | - 'EE_Messages_Generator' => function () { |
|
549 | + 'EE_Messages_Generator' => function() { |
|
550 | 550 | return EE_Registry::instance()->load_lib('Messages_Generator', array(), false, false); |
551 | 551 | }, |
552 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
552 | + 'EE_Messages_Template_Defaults' => function($arguments = array()) { |
|
553 | 553 | return EE_Registry::instance()->load_lib('Messages_Template_Defaults', $arguments, false, false); |
554 | 554 | }, |
555 | 555 | //load_model |
@@ -557,13 +557,13 @@ discard block |
||
557 | 557 | 'EEM_Message_Template_Group' => 'load_model', |
558 | 558 | 'EEM_Message_Template' => 'load_model', |
559 | 559 | //load_helper |
560 | - 'EEH_Parse_Shortcodes' => function () { |
|
560 | + 'EEH_Parse_Shortcodes' => function() { |
|
561 | 561 | if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
562 | 562 | return new EEH_Parse_Shortcodes(); |
563 | 563 | } |
564 | 564 | return null; |
565 | 565 | }, |
566 | - 'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) { |
|
566 | + 'EventEspresso\core\services\loaders\Loader' => function() use (&$loader) { |
|
567 | 567 | return $loader; |
568 | 568 | }, |
569 | 569 | ); |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | use EventEspresso\core\services\loaders\LoaderInterface; |
5 | 5 | |
6 | 6 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
7 | - exit('No direct script access allowed'); |
|
7 | + exit('No direct script access allowed'); |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | |
@@ -22,597 +22,597 @@ discard block |
||
22 | 22 | { |
23 | 23 | |
24 | 24 | |
25 | - /** |
|
26 | - * This means that the requested class dependency is not present in the dependency map |
|
27 | - */ |
|
28 | - const not_registered = 0; |
|
29 | - |
|
30 | - |
|
31 | - /** |
|
32 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
33 | - */ |
|
34 | - const load_new_object = 1; |
|
35 | - |
|
36 | - /** |
|
37 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
38 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
39 | - */ |
|
40 | - const load_from_cache = 2; |
|
41 | - |
|
42 | - /** |
|
43 | - * @type EE_Dependency_Map $_instance |
|
44 | - */ |
|
45 | - protected static $_instance; |
|
46 | - |
|
47 | - /** |
|
48 | - * @type EE_Request $request |
|
49 | - */ |
|
50 | - protected $_request; |
|
51 | - |
|
52 | - /** |
|
53 | - * @type EE_Response $response |
|
54 | - */ |
|
55 | - protected $_response; |
|
56 | - |
|
57 | - /** |
|
58 | - * @type LoaderInterface $loader |
|
59 | - */ |
|
60 | - protected $loader; |
|
61 | - |
|
62 | - /** |
|
63 | - * @type array $_dependency_map |
|
64 | - */ |
|
65 | - protected $_dependency_map = array(); |
|
66 | - |
|
67 | - /** |
|
68 | - * @type array $_class_loaders |
|
69 | - */ |
|
70 | - protected $_class_loaders = array(); |
|
71 | - |
|
72 | - /** |
|
73 | - * @type array $_aliases |
|
74 | - */ |
|
75 | - protected $_aliases = array(); |
|
76 | - |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * EE_Dependency_Map constructor. |
|
81 | - * |
|
82 | - * @param EE_Request $request |
|
83 | - * @param EE_Response $response |
|
84 | - */ |
|
85 | - protected function __construct(EE_Request $request, EE_Response $response) |
|
86 | - { |
|
87 | - $this->_request = $request; |
|
88 | - $this->_response = $response; |
|
89 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
90 | - do_action('EE_Dependency_Map____construct'); |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * @throws InvalidDataTypeException |
|
97 | - * @throws InvalidInterfaceException |
|
98 | - * @throws InvalidArgumentException |
|
99 | - */ |
|
100 | - public function initialize() |
|
101 | - { |
|
102 | - $this->_register_core_dependencies(); |
|
103 | - $this->_register_core_class_loaders(); |
|
104 | - $this->_register_core_aliases(); |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - |
|
109 | - /** |
|
110 | - * @singleton method used to instantiate class object |
|
111 | - * @access public |
|
112 | - * @param EE_Request $request |
|
113 | - * @param EE_Response $response |
|
114 | - * @return EE_Dependency_Map |
|
115 | - */ |
|
116 | - public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
117 | - { |
|
118 | - // check if class object is instantiated, and instantiated properly |
|
119 | - if (! self::$_instance instanceof EE_Dependency_Map) { |
|
120 | - self::$_instance = new EE_Dependency_Map($request, $response); |
|
121 | - } |
|
122 | - return self::$_instance; |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * @param LoaderInterface $loader |
|
129 | - */ |
|
130 | - public function setLoader(LoaderInterface $loader) |
|
131 | - { |
|
132 | - $this->loader = $loader; |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - |
|
137 | - /** |
|
138 | - * @param string $class |
|
139 | - * @param array $dependencies |
|
140 | - * @return boolean |
|
141 | - */ |
|
142 | - public static function register_dependencies($class, $dependencies) |
|
143 | - { |
|
144 | - if (! isset(self::$_instance->_dependency_map[$class])) { |
|
145 | - // we need to make sure that any aliases used when registering a dependency |
|
146 | - // get resolved to the correct class name |
|
147 | - foreach ((array)$dependencies as $dependency => $load_source) { |
|
148 | - $alias = self::$_instance->get_alias($dependency); |
|
149 | - unset($dependencies[$dependency]); |
|
150 | - $dependencies[$alias] = $load_source; |
|
151 | - } |
|
152 | - self::$_instance->_dependency_map[$class] = (array)$dependencies; |
|
153 | - return true; |
|
154 | - } |
|
155 | - return false; |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - |
|
160 | - /** |
|
161 | - * @param string $class_name |
|
162 | - * @param string $loader |
|
163 | - * @return bool |
|
164 | - * @throws EE_Error |
|
165 | - */ |
|
166 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
167 | - { |
|
168 | - // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
169 | - if ( |
|
170 | - ! is_callable($loader) |
|
171 | - && ( |
|
172 | - strpos($loader, 'load_') !== 0 |
|
173 | - || ! method_exists('EE_Registry', $loader) |
|
174 | - ) |
|
175 | - ) { |
|
176 | - throw new EE_Error( |
|
177 | - sprintf( |
|
178 | - esc_html__('"%1$s" is not a valid loader method on EE_Registry.', 'event_espresso'), |
|
179 | - $loader |
|
180 | - ) |
|
181 | - ); |
|
182 | - } |
|
183 | - $class_name = self::$_instance->get_alias($class_name); |
|
184 | - if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
185 | - self::$_instance->_class_loaders[$class_name] = $loader; |
|
186 | - return true; |
|
187 | - } |
|
188 | - return false; |
|
189 | - } |
|
190 | - |
|
191 | - |
|
192 | - |
|
193 | - /** |
|
194 | - * @return array |
|
195 | - */ |
|
196 | - public function dependency_map() |
|
197 | - { |
|
198 | - return $this->_dependency_map; |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
205 | - * |
|
206 | - * @param string $class_name |
|
207 | - * @return boolean |
|
208 | - */ |
|
209 | - public function has($class_name = '') |
|
210 | - { |
|
211 | - return isset($this->_dependency_map[$class_name]) ? true : false; |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - |
|
216 | - /** |
|
217 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
218 | - * |
|
219 | - * @param string $class_name |
|
220 | - * @param string $dependency |
|
221 | - * @return bool |
|
222 | - */ |
|
223 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
224 | - { |
|
225 | - $dependency = $this->get_alias($dependency); |
|
226 | - return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
227 | - ? true |
|
228 | - : false; |
|
229 | - } |
|
230 | - |
|
231 | - |
|
232 | - |
|
233 | - /** |
|
234 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
235 | - * |
|
236 | - * @param string $class_name |
|
237 | - * @param string $dependency |
|
238 | - * @return int |
|
239 | - */ |
|
240 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
241 | - { |
|
242 | - $dependency = $this->get_alias($dependency); |
|
243 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
244 | - ? $this->_dependency_map[$class_name][$dependency] |
|
245 | - : EE_Dependency_Map::not_registered; |
|
246 | - } |
|
247 | - |
|
248 | - |
|
249 | - |
|
250 | - /** |
|
251 | - * @param string $class_name |
|
252 | - * @return string | Closure |
|
253 | - */ |
|
254 | - public function class_loader($class_name) |
|
255 | - { |
|
256 | - $class_name = $this->get_alias($class_name); |
|
257 | - return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
258 | - } |
|
259 | - |
|
260 | - |
|
261 | - |
|
262 | - /** |
|
263 | - * @return array |
|
264 | - */ |
|
265 | - public function class_loaders() |
|
266 | - { |
|
267 | - return $this->_class_loaders; |
|
268 | - } |
|
269 | - |
|
270 | - |
|
271 | - |
|
272 | - /** |
|
273 | - * adds an alias for a classname |
|
274 | - * |
|
275 | - * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
276 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
277 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
278 | - */ |
|
279 | - public function add_alias($class_name, $alias, $for_class = '') |
|
280 | - { |
|
281 | - if ($for_class !== '') { |
|
282 | - if (! isset($this->_aliases[$for_class])) { |
|
283 | - $this->_aliases[$for_class] = array(); |
|
284 | - } |
|
285 | - $this->_aliases[$for_class][$class_name] = $alias; |
|
286 | - } |
|
287 | - $this->_aliases[$class_name] = $alias; |
|
288 | - } |
|
289 | - |
|
290 | - |
|
291 | - |
|
292 | - /** |
|
293 | - * returns TRUE if the provided class name has an alias |
|
294 | - * |
|
295 | - * @param string $class_name |
|
296 | - * @param string $for_class |
|
297 | - * @return bool |
|
298 | - */ |
|
299 | - public function has_alias($class_name = '', $for_class = '') |
|
300 | - { |
|
301 | - return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name]) |
|
302 | - || ( |
|
303 | - isset($this->_aliases[$class_name]) |
|
304 | - && ! is_array($this->_aliases[$class_name]) |
|
305 | - ); |
|
306 | - } |
|
307 | - |
|
308 | - |
|
309 | - |
|
310 | - /** |
|
311 | - * returns alias for class name if one exists, otherwise returns the original classname |
|
312 | - * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
313 | - * for example: |
|
314 | - * if the following two entries were added to the _aliases array: |
|
315 | - * array( |
|
316 | - * 'interface_alias' => 'some\namespace\interface' |
|
317 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
318 | - * ) |
|
319 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
320 | - * to load an instance of 'some\namespace\classname' |
|
321 | - * |
|
322 | - * @param string $class_name |
|
323 | - * @param string $for_class |
|
324 | - * @return string |
|
325 | - */ |
|
326 | - public function get_alias($class_name = '', $for_class = '') |
|
327 | - { |
|
328 | - if (! $this->has_alias($class_name, $for_class)) { |
|
329 | - return $class_name; |
|
330 | - } |
|
331 | - if ($for_class !== '') { |
|
332 | - return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
333 | - } |
|
334 | - return $this->get_alias($this->_aliases[$class_name]); |
|
335 | - } |
|
336 | - |
|
337 | - |
|
338 | - |
|
339 | - /** |
|
340 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
341 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
342 | - * This is done by using the following class constants: |
|
343 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
344 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
345 | - */ |
|
346 | - protected function _register_core_dependencies() |
|
347 | - { |
|
348 | - $this->_dependency_map = array( |
|
349 | - 'EE_Request_Handler' => array( |
|
350 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
351 | - ), |
|
352 | - 'EE_System' => array( |
|
353 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
354 | - ), |
|
355 | - 'EE_Session' => array( |
|
356 | - 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
357 | - ), |
|
358 | - 'EE_Cart' => array( |
|
359 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
360 | - ), |
|
361 | - 'EE_Front_Controller' => array( |
|
362 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
363 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
364 | - 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
365 | - ), |
|
366 | - 'EE_Messenger_Collection_Loader' => array( |
|
367 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
368 | - ), |
|
369 | - 'EE_Message_Type_Collection_Loader' => array( |
|
370 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
371 | - ), |
|
372 | - 'EE_Message_Resource_Manager' => array( |
|
373 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
374 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
375 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
376 | - ), |
|
377 | - 'EE_Message_Factory' => array( |
|
378 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
379 | - ), |
|
380 | - 'EE_messages' => array( |
|
381 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
382 | - ), |
|
383 | - 'EE_Messages_Generator' => array( |
|
384 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
385 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
386 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
387 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
388 | - ), |
|
389 | - 'EE_Messages_Processor' => array( |
|
390 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
391 | - ), |
|
392 | - 'EE_Messages_Queue' => array( |
|
393 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
394 | - ), |
|
395 | - 'EE_Messages_Template_Defaults' => array( |
|
396 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
397 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
398 | - ), |
|
399 | - 'EE_Message_To_Generate_From_Request' => array( |
|
400 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
401 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
402 | - ), |
|
403 | - 'EventEspresso\core\services\commands\CommandBus' => array( |
|
404 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
405 | - ), |
|
406 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
407 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
408 | - ), |
|
409 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
410 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
411 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
412 | - ), |
|
413 | - 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
414 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
415 | - ), |
|
416 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
417 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
418 | - ), |
|
419 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
420 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
421 | - ), |
|
422 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
423 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
424 | - ), |
|
425 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
426 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
427 | - ), |
|
428 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
429 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
430 | - ), |
|
431 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
432 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
433 | - ), |
|
434 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
435 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
436 | - ), |
|
437 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
438 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
439 | - ), |
|
440 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
441 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
442 | - ), |
|
443 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
444 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
445 | - ), |
|
446 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
447 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
448 | - ), |
|
449 | - 'EventEspresso\core\services\database\TableManager' => array( |
|
450 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
451 | - ), |
|
452 | - 'EE_Data_Migration_Class_Base' => array( |
|
453 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
454 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
455 | - ), |
|
456 | - 'EE_DMS_Core_4_1_0' => array( |
|
457 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
458 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
459 | - ), |
|
460 | - 'EE_DMS_Core_4_2_0' => array( |
|
461 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
462 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
463 | - ), |
|
464 | - 'EE_DMS_Core_4_3_0' => array( |
|
465 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
466 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
467 | - ), |
|
468 | - 'EE_DMS_Core_4_4_0' => array( |
|
469 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
470 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
471 | - ), |
|
472 | - 'EE_DMS_Core_4_5_0' => array( |
|
473 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
474 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
475 | - ), |
|
476 | - 'EE_DMS_Core_4_6_0' => array( |
|
477 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
478 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
479 | - ), |
|
480 | - 'EE_DMS_Core_4_7_0' => array( |
|
481 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
482 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
483 | - ), |
|
484 | - 'EE_DMS_Core_4_8_0' => array( |
|
485 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
486 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
487 | - ), |
|
488 | - 'EE_DMS_Core_4_9_0' => array( |
|
489 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
490 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
491 | - ), |
|
492 | - ); |
|
493 | - } |
|
494 | - |
|
495 | - |
|
496 | - |
|
497 | - /** |
|
498 | - * Registers how core classes are loaded. |
|
499 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
500 | - * 'EE_Request_Handler' => 'load_core' |
|
501 | - * 'EE_Messages_Queue' => 'load_lib' |
|
502 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
503 | - * or, if greater control is required, by providing a custom closure. For example: |
|
504 | - * 'Some_Class' => function () { |
|
505 | - * return new Some_Class(); |
|
506 | - * }, |
|
507 | - * This is required for instantiating dependencies |
|
508 | - * where an interface has been type hinted in a class constructor. For example: |
|
509 | - * 'Required_Interface' => function () { |
|
510 | - * return new A_Class_That_Implements_Required_Interface(); |
|
511 | - * }, |
|
512 | - */ |
|
513 | - protected function _register_core_class_loaders() |
|
514 | - { |
|
515 | - //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
516 | - //be used in a closure. |
|
517 | - $request = &$this->_request; |
|
518 | - $response = &$this->_response; |
|
519 | - $loader = &$this->loader; |
|
520 | - $this->_class_loaders = array( |
|
521 | - //load_core |
|
522 | - 'EE_Capabilities' => 'load_core', |
|
523 | - 'EE_Encryption' => 'load_core', |
|
524 | - 'EE_Front_Controller' => 'load_core', |
|
525 | - 'EE_Module_Request_Router' => 'load_core', |
|
526 | - 'EE_Registry' => 'load_core', |
|
527 | - 'EE_Request' => function () use (&$request) { |
|
528 | - return $request; |
|
529 | - }, |
|
530 | - 'EE_Response' => function () use (&$response) { |
|
531 | - return $response; |
|
532 | - }, |
|
533 | - 'EE_Request_Handler' => 'load_core', |
|
534 | - 'EE_Session' => 'load_core', |
|
535 | - 'EE_System' => 'load_core', |
|
536 | - //load_lib |
|
537 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
538 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
539 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
540 | - 'EE_Messenger_Collection' => 'load_lib', |
|
541 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
542 | - 'EE_Messages_Processor' => 'load_lib', |
|
543 | - 'EE_Message_Repository' => 'load_lib', |
|
544 | - 'EE_Messages_Queue' => 'load_lib', |
|
545 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
546 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
547 | - 'EE_Messages_Generator' => function () { |
|
548 | - return EE_Registry::instance()->load_lib('Messages_Generator', array(), false, false); |
|
549 | - }, |
|
550 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
551 | - return EE_Registry::instance()->load_lib('Messages_Template_Defaults', $arguments, false, false); |
|
552 | - }, |
|
553 | - //load_model |
|
554 | - 'EEM_Message_Template_Group' => 'load_model', |
|
555 | - 'EEM_Message_Template' => 'load_model', |
|
556 | - //load_helper |
|
557 | - 'EEH_Parse_Shortcodes' => function () { |
|
558 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
559 | - return new EEH_Parse_Shortcodes(); |
|
560 | - } |
|
561 | - return null; |
|
562 | - }, |
|
563 | - 'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) { |
|
564 | - return $loader; |
|
565 | - }, |
|
566 | - ); |
|
567 | - } |
|
568 | - |
|
569 | - |
|
570 | - |
|
571 | - /** |
|
572 | - * can be used for supplying alternate names for classes, |
|
573 | - * or for connecting interface names to instantiable classes |
|
574 | - */ |
|
575 | - protected function _register_core_aliases() |
|
576 | - { |
|
577 | - $this->_aliases = array( |
|
578 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
579 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
580 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
581 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
582 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
583 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
584 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
585 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
586 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
587 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
588 | - 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
589 | - 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
590 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
591 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
592 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
593 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
594 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
595 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
596 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
597 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
598 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
599 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
600 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
601 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
602 | - ); |
|
603 | - } |
|
604 | - |
|
605 | - |
|
606 | - |
|
607 | - /** |
|
608 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
609 | - * request Primarily used by unit tests. |
|
610 | - */ |
|
611 | - public function reset() |
|
612 | - { |
|
613 | - $this->_register_core_class_loaders(); |
|
614 | - $this->_register_core_dependencies(); |
|
615 | - } |
|
25 | + /** |
|
26 | + * This means that the requested class dependency is not present in the dependency map |
|
27 | + */ |
|
28 | + const not_registered = 0; |
|
29 | + |
|
30 | + |
|
31 | + /** |
|
32 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
33 | + */ |
|
34 | + const load_new_object = 1; |
|
35 | + |
|
36 | + /** |
|
37 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
38 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
39 | + */ |
|
40 | + const load_from_cache = 2; |
|
41 | + |
|
42 | + /** |
|
43 | + * @type EE_Dependency_Map $_instance |
|
44 | + */ |
|
45 | + protected static $_instance; |
|
46 | + |
|
47 | + /** |
|
48 | + * @type EE_Request $request |
|
49 | + */ |
|
50 | + protected $_request; |
|
51 | + |
|
52 | + /** |
|
53 | + * @type EE_Response $response |
|
54 | + */ |
|
55 | + protected $_response; |
|
56 | + |
|
57 | + /** |
|
58 | + * @type LoaderInterface $loader |
|
59 | + */ |
|
60 | + protected $loader; |
|
61 | + |
|
62 | + /** |
|
63 | + * @type array $_dependency_map |
|
64 | + */ |
|
65 | + protected $_dependency_map = array(); |
|
66 | + |
|
67 | + /** |
|
68 | + * @type array $_class_loaders |
|
69 | + */ |
|
70 | + protected $_class_loaders = array(); |
|
71 | + |
|
72 | + /** |
|
73 | + * @type array $_aliases |
|
74 | + */ |
|
75 | + protected $_aliases = array(); |
|
76 | + |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * EE_Dependency_Map constructor. |
|
81 | + * |
|
82 | + * @param EE_Request $request |
|
83 | + * @param EE_Response $response |
|
84 | + */ |
|
85 | + protected function __construct(EE_Request $request, EE_Response $response) |
|
86 | + { |
|
87 | + $this->_request = $request; |
|
88 | + $this->_response = $response; |
|
89 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
90 | + do_action('EE_Dependency_Map____construct'); |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * @throws InvalidDataTypeException |
|
97 | + * @throws InvalidInterfaceException |
|
98 | + * @throws InvalidArgumentException |
|
99 | + */ |
|
100 | + public function initialize() |
|
101 | + { |
|
102 | + $this->_register_core_dependencies(); |
|
103 | + $this->_register_core_class_loaders(); |
|
104 | + $this->_register_core_aliases(); |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + |
|
109 | + /** |
|
110 | + * @singleton method used to instantiate class object |
|
111 | + * @access public |
|
112 | + * @param EE_Request $request |
|
113 | + * @param EE_Response $response |
|
114 | + * @return EE_Dependency_Map |
|
115 | + */ |
|
116 | + public static function instance(EE_Request $request = null, EE_Response $response = null) |
|
117 | + { |
|
118 | + // check if class object is instantiated, and instantiated properly |
|
119 | + if (! self::$_instance instanceof EE_Dependency_Map) { |
|
120 | + self::$_instance = new EE_Dependency_Map($request, $response); |
|
121 | + } |
|
122 | + return self::$_instance; |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * @param LoaderInterface $loader |
|
129 | + */ |
|
130 | + public function setLoader(LoaderInterface $loader) |
|
131 | + { |
|
132 | + $this->loader = $loader; |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + |
|
137 | + /** |
|
138 | + * @param string $class |
|
139 | + * @param array $dependencies |
|
140 | + * @return boolean |
|
141 | + */ |
|
142 | + public static function register_dependencies($class, $dependencies) |
|
143 | + { |
|
144 | + if (! isset(self::$_instance->_dependency_map[$class])) { |
|
145 | + // we need to make sure that any aliases used when registering a dependency |
|
146 | + // get resolved to the correct class name |
|
147 | + foreach ((array)$dependencies as $dependency => $load_source) { |
|
148 | + $alias = self::$_instance->get_alias($dependency); |
|
149 | + unset($dependencies[$dependency]); |
|
150 | + $dependencies[$alias] = $load_source; |
|
151 | + } |
|
152 | + self::$_instance->_dependency_map[$class] = (array)$dependencies; |
|
153 | + return true; |
|
154 | + } |
|
155 | + return false; |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + |
|
160 | + /** |
|
161 | + * @param string $class_name |
|
162 | + * @param string $loader |
|
163 | + * @return bool |
|
164 | + * @throws EE_Error |
|
165 | + */ |
|
166 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
167 | + { |
|
168 | + // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
169 | + if ( |
|
170 | + ! is_callable($loader) |
|
171 | + && ( |
|
172 | + strpos($loader, 'load_') !== 0 |
|
173 | + || ! method_exists('EE_Registry', $loader) |
|
174 | + ) |
|
175 | + ) { |
|
176 | + throw new EE_Error( |
|
177 | + sprintf( |
|
178 | + esc_html__('"%1$s" is not a valid loader method on EE_Registry.', 'event_espresso'), |
|
179 | + $loader |
|
180 | + ) |
|
181 | + ); |
|
182 | + } |
|
183 | + $class_name = self::$_instance->get_alias($class_name); |
|
184 | + if (! isset(self::$_instance->_class_loaders[$class_name])) { |
|
185 | + self::$_instance->_class_loaders[$class_name] = $loader; |
|
186 | + return true; |
|
187 | + } |
|
188 | + return false; |
|
189 | + } |
|
190 | + |
|
191 | + |
|
192 | + |
|
193 | + /** |
|
194 | + * @return array |
|
195 | + */ |
|
196 | + public function dependency_map() |
|
197 | + { |
|
198 | + return $this->_dependency_map; |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
205 | + * |
|
206 | + * @param string $class_name |
|
207 | + * @return boolean |
|
208 | + */ |
|
209 | + public function has($class_name = '') |
|
210 | + { |
|
211 | + return isset($this->_dependency_map[$class_name]) ? true : false; |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + |
|
216 | + /** |
|
217 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
218 | + * |
|
219 | + * @param string $class_name |
|
220 | + * @param string $dependency |
|
221 | + * @return bool |
|
222 | + */ |
|
223 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
224 | + { |
|
225 | + $dependency = $this->get_alias($dependency); |
|
226 | + return isset($this->_dependency_map[$class_name], $this->_dependency_map[$class_name][$dependency]) |
|
227 | + ? true |
|
228 | + : false; |
|
229 | + } |
|
230 | + |
|
231 | + |
|
232 | + |
|
233 | + /** |
|
234 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
235 | + * |
|
236 | + * @param string $class_name |
|
237 | + * @param string $dependency |
|
238 | + * @return int |
|
239 | + */ |
|
240 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
241 | + { |
|
242 | + $dependency = $this->get_alias($dependency); |
|
243 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
244 | + ? $this->_dependency_map[$class_name][$dependency] |
|
245 | + : EE_Dependency_Map::not_registered; |
|
246 | + } |
|
247 | + |
|
248 | + |
|
249 | + |
|
250 | + /** |
|
251 | + * @param string $class_name |
|
252 | + * @return string | Closure |
|
253 | + */ |
|
254 | + public function class_loader($class_name) |
|
255 | + { |
|
256 | + $class_name = $this->get_alias($class_name); |
|
257 | + return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
258 | + } |
|
259 | + |
|
260 | + |
|
261 | + |
|
262 | + /** |
|
263 | + * @return array |
|
264 | + */ |
|
265 | + public function class_loaders() |
|
266 | + { |
|
267 | + return $this->_class_loaders; |
|
268 | + } |
|
269 | + |
|
270 | + |
|
271 | + |
|
272 | + /** |
|
273 | + * adds an alias for a classname |
|
274 | + * |
|
275 | + * @param string $class_name the class name that should be used (concrete class to replace interface) |
|
276 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
277 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
278 | + */ |
|
279 | + public function add_alias($class_name, $alias, $for_class = '') |
|
280 | + { |
|
281 | + if ($for_class !== '') { |
|
282 | + if (! isset($this->_aliases[$for_class])) { |
|
283 | + $this->_aliases[$for_class] = array(); |
|
284 | + } |
|
285 | + $this->_aliases[$for_class][$class_name] = $alias; |
|
286 | + } |
|
287 | + $this->_aliases[$class_name] = $alias; |
|
288 | + } |
|
289 | + |
|
290 | + |
|
291 | + |
|
292 | + /** |
|
293 | + * returns TRUE if the provided class name has an alias |
|
294 | + * |
|
295 | + * @param string $class_name |
|
296 | + * @param string $for_class |
|
297 | + * @return bool |
|
298 | + */ |
|
299 | + public function has_alias($class_name = '', $for_class = '') |
|
300 | + { |
|
301 | + return isset($this->_aliases[$for_class], $this->_aliases[$for_class][$class_name]) |
|
302 | + || ( |
|
303 | + isset($this->_aliases[$class_name]) |
|
304 | + && ! is_array($this->_aliases[$class_name]) |
|
305 | + ); |
|
306 | + } |
|
307 | + |
|
308 | + |
|
309 | + |
|
310 | + /** |
|
311 | + * returns alias for class name if one exists, otherwise returns the original classname |
|
312 | + * functions recursively, so that multiple aliases can be used to drill down to a classname |
|
313 | + * for example: |
|
314 | + * if the following two entries were added to the _aliases array: |
|
315 | + * array( |
|
316 | + * 'interface_alias' => 'some\namespace\interface' |
|
317 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
318 | + * ) |
|
319 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
320 | + * to load an instance of 'some\namespace\classname' |
|
321 | + * |
|
322 | + * @param string $class_name |
|
323 | + * @param string $for_class |
|
324 | + * @return string |
|
325 | + */ |
|
326 | + public function get_alias($class_name = '', $for_class = '') |
|
327 | + { |
|
328 | + if (! $this->has_alias($class_name, $for_class)) { |
|
329 | + return $class_name; |
|
330 | + } |
|
331 | + if ($for_class !== '') { |
|
332 | + return $this->get_alias($this->_aliases[$for_class][$class_name], $for_class); |
|
333 | + } |
|
334 | + return $this->get_alias($this->_aliases[$class_name]); |
|
335 | + } |
|
336 | + |
|
337 | + |
|
338 | + |
|
339 | + /** |
|
340 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
341 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
342 | + * This is done by using the following class constants: |
|
343 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
344 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
345 | + */ |
|
346 | + protected function _register_core_dependencies() |
|
347 | + { |
|
348 | + $this->_dependency_map = array( |
|
349 | + 'EE_Request_Handler' => array( |
|
350 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
351 | + ), |
|
352 | + 'EE_System' => array( |
|
353 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
354 | + ), |
|
355 | + 'EE_Session' => array( |
|
356 | + 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
357 | + ), |
|
358 | + 'EE_Cart' => array( |
|
359 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
360 | + ), |
|
361 | + 'EE_Front_Controller' => array( |
|
362 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
363 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
364 | + 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
365 | + ), |
|
366 | + 'EE_Messenger_Collection_Loader' => array( |
|
367 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
368 | + ), |
|
369 | + 'EE_Message_Type_Collection_Loader' => array( |
|
370 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
371 | + ), |
|
372 | + 'EE_Message_Resource_Manager' => array( |
|
373 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
374 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
375 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
376 | + ), |
|
377 | + 'EE_Message_Factory' => array( |
|
378 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
379 | + ), |
|
380 | + 'EE_messages' => array( |
|
381 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
382 | + ), |
|
383 | + 'EE_Messages_Generator' => array( |
|
384 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
385 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
386 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
387 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
388 | + ), |
|
389 | + 'EE_Messages_Processor' => array( |
|
390 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
391 | + ), |
|
392 | + 'EE_Messages_Queue' => array( |
|
393 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
394 | + ), |
|
395 | + 'EE_Messages_Template_Defaults' => array( |
|
396 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
397 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
398 | + ), |
|
399 | + 'EE_Message_To_Generate_From_Request' => array( |
|
400 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
401 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
402 | + ), |
|
403 | + 'EventEspresso\core\services\commands\CommandBus' => array( |
|
404 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
405 | + ), |
|
406 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
407 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
408 | + ), |
|
409 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
410 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
411 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
412 | + ), |
|
413 | + 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
414 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
415 | + ), |
|
416 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
417 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
418 | + ), |
|
419 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
420 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
421 | + ), |
|
422 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
423 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
424 | + ), |
|
425 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
426 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
427 | + ), |
|
428 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
429 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
430 | + ), |
|
431 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
432 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
433 | + ), |
|
434 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
435 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
436 | + ), |
|
437 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
438 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
439 | + ), |
|
440 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
441 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
442 | + ), |
|
443 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
444 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
445 | + ), |
|
446 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
447 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
448 | + ), |
|
449 | + 'EventEspresso\core\services\database\TableManager' => array( |
|
450 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
451 | + ), |
|
452 | + 'EE_Data_Migration_Class_Base' => array( |
|
453 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
454 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
455 | + ), |
|
456 | + 'EE_DMS_Core_4_1_0' => array( |
|
457 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
458 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
459 | + ), |
|
460 | + 'EE_DMS_Core_4_2_0' => array( |
|
461 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
462 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
463 | + ), |
|
464 | + 'EE_DMS_Core_4_3_0' => array( |
|
465 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
466 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
467 | + ), |
|
468 | + 'EE_DMS_Core_4_4_0' => array( |
|
469 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
470 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
471 | + ), |
|
472 | + 'EE_DMS_Core_4_5_0' => array( |
|
473 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
474 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
475 | + ), |
|
476 | + 'EE_DMS_Core_4_6_0' => array( |
|
477 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
478 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
479 | + ), |
|
480 | + 'EE_DMS_Core_4_7_0' => array( |
|
481 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
482 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
483 | + ), |
|
484 | + 'EE_DMS_Core_4_8_0' => array( |
|
485 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
486 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
487 | + ), |
|
488 | + 'EE_DMS_Core_4_9_0' => array( |
|
489 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
490 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
491 | + ), |
|
492 | + ); |
|
493 | + } |
|
494 | + |
|
495 | + |
|
496 | + |
|
497 | + /** |
|
498 | + * Registers how core classes are loaded. |
|
499 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
500 | + * 'EE_Request_Handler' => 'load_core' |
|
501 | + * 'EE_Messages_Queue' => 'load_lib' |
|
502 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
503 | + * or, if greater control is required, by providing a custom closure. For example: |
|
504 | + * 'Some_Class' => function () { |
|
505 | + * return new Some_Class(); |
|
506 | + * }, |
|
507 | + * This is required for instantiating dependencies |
|
508 | + * where an interface has been type hinted in a class constructor. For example: |
|
509 | + * 'Required_Interface' => function () { |
|
510 | + * return new A_Class_That_Implements_Required_Interface(); |
|
511 | + * }, |
|
512 | + */ |
|
513 | + protected function _register_core_class_loaders() |
|
514 | + { |
|
515 | + //for PHP5.3 compat, we need to register any properties called here in a variable because `$this` cannot |
|
516 | + //be used in a closure. |
|
517 | + $request = &$this->_request; |
|
518 | + $response = &$this->_response; |
|
519 | + $loader = &$this->loader; |
|
520 | + $this->_class_loaders = array( |
|
521 | + //load_core |
|
522 | + 'EE_Capabilities' => 'load_core', |
|
523 | + 'EE_Encryption' => 'load_core', |
|
524 | + 'EE_Front_Controller' => 'load_core', |
|
525 | + 'EE_Module_Request_Router' => 'load_core', |
|
526 | + 'EE_Registry' => 'load_core', |
|
527 | + 'EE_Request' => function () use (&$request) { |
|
528 | + return $request; |
|
529 | + }, |
|
530 | + 'EE_Response' => function () use (&$response) { |
|
531 | + return $response; |
|
532 | + }, |
|
533 | + 'EE_Request_Handler' => 'load_core', |
|
534 | + 'EE_Session' => 'load_core', |
|
535 | + 'EE_System' => 'load_core', |
|
536 | + //load_lib |
|
537 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
538 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
539 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
540 | + 'EE_Messenger_Collection' => 'load_lib', |
|
541 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
542 | + 'EE_Messages_Processor' => 'load_lib', |
|
543 | + 'EE_Message_Repository' => 'load_lib', |
|
544 | + 'EE_Messages_Queue' => 'load_lib', |
|
545 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
546 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
547 | + 'EE_Messages_Generator' => function () { |
|
548 | + return EE_Registry::instance()->load_lib('Messages_Generator', array(), false, false); |
|
549 | + }, |
|
550 | + 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
551 | + return EE_Registry::instance()->load_lib('Messages_Template_Defaults', $arguments, false, false); |
|
552 | + }, |
|
553 | + //load_model |
|
554 | + 'EEM_Message_Template_Group' => 'load_model', |
|
555 | + 'EEM_Message_Template' => 'load_model', |
|
556 | + //load_helper |
|
557 | + 'EEH_Parse_Shortcodes' => function () { |
|
558 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
559 | + return new EEH_Parse_Shortcodes(); |
|
560 | + } |
|
561 | + return null; |
|
562 | + }, |
|
563 | + 'EventEspresso\core\services\loaders\Loader' => function () use (&$loader) { |
|
564 | + return $loader; |
|
565 | + }, |
|
566 | + ); |
|
567 | + } |
|
568 | + |
|
569 | + |
|
570 | + |
|
571 | + /** |
|
572 | + * can be used for supplying alternate names for classes, |
|
573 | + * or for connecting interface names to instantiable classes |
|
574 | + */ |
|
575 | + protected function _register_core_aliases() |
|
576 | + { |
|
577 | + $this->_aliases = array( |
|
578 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
579 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
580 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
581 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
582 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
583 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
584 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
585 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
586 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
587 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
588 | + 'CreateRegCodeCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegCodeCommand', |
|
589 | + 'CreateRegUrlLinkCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegUrlLinkCommand', |
|
590 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
591 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
592 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
593 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
594 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
595 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
596 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
597 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
598 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
599 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
600 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
601 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
602 | + ); |
|
603 | + } |
|
604 | + |
|
605 | + |
|
606 | + |
|
607 | + /** |
|
608 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
609 | + * request Primarily used by unit tests. |
|
610 | + */ |
|
611 | + public function reset() |
|
612 | + { |
|
613 | + $this->_register_core_class_loaders(); |
|
614 | + $this->_register_core_dependencies(); |
|
615 | + } |
|
616 | 616 | |
617 | 617 | |
618 | 618 | } |
@@ -15,2112 +15,2112 @@ |
||
15 | 15 | class espresso_events_Pricing_Hooks extends EE_Admin_Hooks |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * This property is just used to hold the status of whether an event is currently being |
|
20 | - * created (true) or edited (false) |
|
21 | - * |
|
22 | - * @access protected |
|
23 | - * @var bool |
|
24 | - */ |
|
25 | - protected $_is_creating_event; |
|
26 | - |
|
27 | - |
|
28 | - /** |
|
29 | - * Used to contain the format strings for date and time that will be used for php date and |
|
30 | - * time. |
|
31 | - * Is set in the _set_hooks_properties() method. |
|
32 | - * |
|
33 | - * @var array |
|
34 | - */ |
|
35 | - protected $_date_format_strings; |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * @var string $_date_time_format |
|
40 | - */ |
|
41 | - protected $_date_time_format; |
|
42 | - |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * |
|
47 | - */ |
|
48 | - protected function _set_hooks_properties() |
|
49 | - { |
|
50 | - $this->_name = 'pricing'; |
|
51 | - //capability check |
|
52 | - if ( |
|
53 | - ! EE_Registry::instance()->CAP->current_user_can( |
|
54 | - 'ee_read_default_prices', |
|
55 | - 'advanced_ticket_datetime_metabox' |
|
56 | - ) |
|
57 | - ) { |
|
58 | - return; |
|
59 | - } |
|
60 | - $this->_setup_metaboxes(); |
|
61 | - $this->_set_date_time_formats(); |
|
62 | - $this->_validate_format_strings(); |
|
63 | - $this->_set_scripts_styles(); |
|
64 | - // commented out temporarily until logic is implemented in callback |
|
65 | - // add_action( |
|
66 | - // 'AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page', |
|
67 | - // array($this, 'autosave_handling') |
|
68 | - // ); |
|
69 | - add_filter( |
|
70 | - 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
71 | - array($this, 'caf_updates') |
|
72 | - ); |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * @return void |
|
79 | - */ |
|
80 | - protected function _setup_metaboxes() |
|
81 | - { |
|
82 | - //if we were going to add our own metaboxes we'd use the below. |
|
83 | - $this->_metaboxes = array( |
|
84 | - 0 => array( |
|
85 | - 'page_route' => array('edit', 'create_new'), |
|
86 | - 'func' => 'pricing_metabox', |
|
87 | - 'label' => esc_html__('Event Tickets & Datetimes', 'event_espresso'), |
|
88 | - 'priority' => 'high', |
|
89 | - 'context' => 'normal', |
|
90 | - ), |
|
91 | - ); |
|
92 | - $this->_remove_metaboxes = array( |
|
93 | - 0 => array( |
|
94 | - 'page_route' => array('edit', 'create_new'), |
|
95 | - 'id' => 'espresso_event_editor_tickets', |
|
96 | - 'context' => 'normal', |
|
97 | - ), |
|
98 | - ); |
|
99 | - } |
|
100 | - |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * @return void |
|
105 | - */ |
|
106 | - protected function _set_date_time_formats() |
|
107 | - { |
|
108 | - /** |
|
109 | - * Format strings for date and time. Defaults are existing behaviour from 4.1. |
|
110 | - * Note, that if you return null as the value for 'date', and 'time' in the array, then |
|
111 | - * EE will automatically use the set wp_options, 'date_format', and 'time_format'. |
|
112 | - * |
|
113 | - * @since 4.6.7 |
|
114 | - * @var array Expected an array returned with 'date' and 'time' keys. |
|
115 | - */ |
|
116 | - $this->_date_format_strings = apply_filters( |
|
117 | - 'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings', |
|
118 | - array( |
|
119 | - 'date' => 'Y-m-d', |
|
120 | - 'time' => 'h:i a', |
|
121 | - ) |
|
122 | - ); |
|
123 | - //validate |
|
124 | - $this->_date_format_strings['date'] = isset($this->_date_format_strings['date']) |
|
125 | - ? $this->_date_format_strings['date'] |
|
126 | - : null; |
|
127 | - $this->_date_format_strings['time'] = isset($this->_date_format_strings['time']) |
|
128 | - ? $this->_date_format_strings['time'] |
|
129 | - : null; |
|
130 | - $this->_date_time_format = $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']; |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * @return void |
|
137 | - */ |
|
138 | - protected function _validate_format_strings() |
|
139 | - { |
|
140 | - //validate format strings |
|
141 | - $format_validation = EEH_DTT_Helper::validate_format_string( |
|
142 | - $this->_date_time_format |
|
143 | - ); |
|
144 | - if (is_array($format_validation)) { |
|
145 | - $msg = '<p>'; |
|
146 | - $msg .= sprintf( |
|
147 | - __( |
|
148 | - 'The format "%s" was likely added via a filter and is invalid for the following reasons:', |
|
149 | - 'event_espresso' |
|
150 | - ), |
|
151 | - $this->_date_time_format |
|
152 | - ); |
|
153 | - $msg .= '</p><ul>'; |
|
154 | - foreach ($format_validation as $error) { |
|
155 | - $msg .= '<li>' . $error . '</li>'; |
|
156 | - } |
|
157 | - $msg .= '</ul><p>'; |
|
158 | - $msg .= sprintf( |
|
159 | - __( |
|
160 | - '%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s', |
|
161 | - 'event_espresso' |
|
162 | - ), |
|
163 | - '<span style="color:#D54E21;">', |
|
164 | - '</span>' |
|
165 | - ); |
|
166 | - $msg .= '</p>'; |
|
167 | - EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
168 | - $this->_date_format_strings = array( |
|
169 | - 'date' => 'Y-m-d', |
|
170 | - 'time' => 'h:i a', |
|
171 | - ); |
|
172 | - } |
|
173 | - } |
|
174 | - |
|
175 | - |
|
176 | - |
|
177 | - /** |
|
178 | - * @return void |
|
179 | - */ |
|
180 | - protected function _set_scripts_styles() |
|
181 | - { |
|
182 | - $this->_scripts_styles = array( |
|
183 | - 'registers' => array( |
|
184 | - 'ee-tickets-datetimes-css' => array( |
|
185 | - 'url' => PRICING_ASSETS_URL . 'event-tickets-datetimes.css', |
|
186 | - 'type' => 'css', |
|
187 | - ), |
|
188 | - 'ee-dtt-ticket-metabox' => array( |
|
189 | - 'url' => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js', |
|
190 | - 'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'), |
|
191 | - ), |
|
192 | - ), |
|
193 | - 'deregisters' => array( |
|
194 | - 'event-editor-css' => array('type' => 'css'), |
|
195 | - 'event-datetime-metabox' => array('type' => 'js'), |
|
196 | - ), |
|
197 | - 'enqueues' => array( |
|
198 | - 'ee-tickets-datetimes-css' => array('edit', 'create_new'), |
|
199 | - 'ee-dtt-ticket-metabox' => array('edit', 'create_new'), |
|
200 | - ), |
|
201 | - 'localize' => array( |
|
202 | - 'ee-dtt-ticket-metabox' => array( |
|
203 | - 'DTT_TRASH_BLOCK' => array( |
|
204 | - 'main_warning' => esc_html__( |
|
205 | - 'The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):', |
|
206 | - 'event_espresso' |
|
207 | - ), |
|
208 | - 'after_warning' => esc_html__( |
|
209 | - 'In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.', |
|
210 | - 'event_espresso' |
|
211 | - ), |
|
212 | - 'cancel_button' => '<button class="button-secondary ee-modal-cancel">' |
|
213 | - . esc_html__('Cancel', 'event_espresso') . '</button>', |
|
214 | - 'close_button' => '<button class="button-secondary ee-modal-cancel">' |
|
215 | - . esc_html__('Close', 'event_espresso') . '</button>', |
|
216 | - 'single_warning_from_tkt' => esc_html__( |
|
217 | - 'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.', |
|
218 | - 'event_espresso' |
|
219 | - ), |
|
220 | - 'single_warning_from_dtt' => esc_html__( |
|
221 | - 'The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket. Tickets must always have at least one datetime assigned to them.', |
|
222 | - 'event_espresso' |
|
223 | - ), |
|
224 | - 'dismiss_button' => '<button class="button-secondary ee-modal-cancel">' |
|
225 | - . esc_html__('Dismiss', 'event_espresso') . '</button>', |
|
226 | - ), |
|
227 | - 'DTT_ERROR_MSG' => array( |
|
228 | - 'no_ticket_name' => esc_html__('General Admission', 'event_espresso'), |
|
229 | - 'dismiss_button' => '<div class="save-cancel-button-container"><button class="button-secondary ee-modal-cancel">' |
|
230 | - . esc_html__('Dismiss', 'event_espresso') . '</button></div>', |
|
231 | - ), |
|
232 | - 'DTT_OVERSELL_WARNING' => array( |
|
233 | - 'datetime_ticket' => esc_html__( |
|
234 | - 'You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.', |
|
235 | - 'event_espresso' |
|
236 | - ), |
|
237 | - 'ticket_datetime' => esc_html__( |
|
238 | - 'You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.', |
|
239 | - 'event_espresso' |
|
240 | - ), |
|
241 | - ), |
|
242 | - 'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats( |
|
243 | - $this->_date_format_strings['date'], |
|
244 | - $this->_date_format_strings['time'] |
|
245 | - ), |
|
246 | - 'DTT_START_OF_WEEK' => array('dayValue' => (int)get_option('start_of_week')), |
|
247 | - ), |
|
248 | - ), |
|
249 | - ); |
|
250 | - } |
|
251 | - |
|
252 | - |
|
253 | - |
|
254 | - /** |
|
255 | - * @param array $update_callbacks |
|
256 | - * @return array |
|
257 | - */ |
|
258 | - public function caf_updates(array $update_callbacks) |
|
259 | - { |
|
260 | - foreach ($update_callbacks as $key => $callback) { |
|
261 | - if ($callback[1] === '_default_tickets_update') { |
|
262 | - unset($update_callbacks[$key]); |
|
263 | - } |
|
264 | - } |
|
265 | - $update_callbacks[] = array($this, 'datetime_and_tickets_caf_update'); |
|
266 | - return $update_callbacks; |
|
267 | - } |
|
268 | - |
|
269 | - |
|
270 | - |
|
271 | - /** |
|
272 | - * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
273 | - * |
|
274 | - * @param EE_Event $event The Event object we're attaching data to |
|
275 | - * @param array $data The request data from the form |
|
276 | - * @throws EE_Error |
|
277 | - */ |
|
278 | - public function datetime_and_tickets_caf_update($event, $data) |
|
279 | - { |
|
280 | - //first we need to start with datetimes cause they are the "root" items attached to events. |
|
281 | - $saved_datetimes = $this->_update_datetimes($event, $data); |
|
282 | - //next tackle the tickets (and prices?) |
|
283 | - $this->_update_tickets($event, $saved_datetimes, $data); |
|
284 | - } |
|
285 | - |
|
286 | - |
|
287 | - |
|
288 | - /** |
|
289 | - * update event_datetimes |
|
290 | - * |
|
291 | - * @param EE_Event $event Event being updated |
|
292 | - * @param array $data the request data from the form |
|
293 | - * @return EE_Datetime[] |
|
294 | - * @throws EE_Error |
|
295 | - */ |
|
296 | - protected function _update_datetimes($event, $data) |
|
297 | - { |
|
298 | - $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
299 | - $saved_dtt_ids = array(); |
|
300 | - $saved_dtt_objs = array(); |
|
301 | - foreach ($data['edit_event_datetimes'] as $row => $datetime_data) { |
|
302 | - //trim all values to ensure any excess whitespace is removed. |
|
303 | - $datetime_data = array_map( |
|
304 | - function ($datetime_data) { |
|
305 | - return is_array($datetime_data) ? $datetime_data : trim($datetime_data); |
|
306 | - }, |
|
307 | - $datetime_data |
|
308 | - ); |
|
309 | - $datetime_data['DTT_EVT_end'] = isset($datetime_data['DTT_EVT_end']) |
|
310 | - && ! empty($datetime_data['DTT_EVT_end']) |
|
311 | - ? $datetime_data['DTT_EVT_end'] |
|
312 | - : $datetime_data['DTT_EVT_start']; |
|
313 | - $datetime_values = array( |
|
314 | - 'DTT_ID' => ! empty($datetime_data['DTT_ID']) |
|
315 | - ? $datetime_data['DTT_ID'] |
|
316 | - : null, |
|
317 | - 'DTT_name' => ! empty($datetime_data['DTT_name']) |
|
318 | - ? $datetime_data['DTT_name'] |
|
319 | - : '', |
|
320 | - 'DTT_description' => ! empty($datetime_data['DTT_description']) |
|
321 | - ? $datetime_data['DTT_description'] |
|
322 | - : '', |
|
323 | - 'DTT_EVT_start' => $datetime_data['DTT_EVT_start'], |
|
324 | - 'DTT_EVT_end' => $datetime_data['DTT_EVT_end'], |
|
325 | - 'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) |
|
326 | - ? EE_INF |
|
327 | - : $datetime_data['DTT_reg_limit'], |
|
328 | - 'DTT_order' => ! isset($datetime_data['DTT_order']) |
|
329 | - ? $row |
|
330 | - : $datetime_data['DTT_order'], |
|
331 | - ); |
|
332 | - // if we have an id then let's get existing object first and then set the new values. |
|
333 | - // Otherwise we instantiate a new object for save. |
|
334 | - if (! empty($datetime_data['DTT_ID'])) { |
|
335 | - $datetime = EE_Registry::instance() |
|
336 | - ->load_model('Datetime', array($timezone)) |
|
337 | - ->get_one_by_ID($datetime_data['DTT_ID']); |
|
338 | - //set date and time format according to what is set in this class. |
|
339 | - $datetime->set_date_format($this->_date_format_strings['date']); |
|
340 | - $datetime->set_time_format($this->_date_format_strings['time']); |
|
341 | - foreach ($datetime_values as $field => $value) { |
|
342 | - $datetime->set($field, $value); |
|
343 | - } |
|
344 | - // make sure the $dtt_id here is saved just in case |
|
345 | - // after the add_relation_to() the autosave replaces it. |
|
346 | - // We need to do this so we dont' TRASH the parent DTT. |
|
347 | - // (save the ID for both key and value to avoid duplications) |
|
348 | - $saved_dtt_ids[$datetime->ID()] = $datetime->ID(); |
|
349 | - } else { |
|
350 | - $datetime = EE_Registry::instance()->load_class( |
|
351 | - 'Datetime', |
|
352 | - array( |
|
353 | - $datetime_values, |
|
354 | - $timezone, |
|
355 | - array($this->_date_format_strings['date'], $this->_date_format_strings['time']), |
|
356 | - ), |
|
357 | - false, |
|
358 | - false |
|
359 | - ); |
|
360 | - foreach ($datetime_values as $field => $value) { |
|
361 | - $datetime->set($field, $value); |
|
362 | - } |
|
363 | - } |
|
364 | - $datetime->save(); |
|
365 | - $datetime = $event->_add_relation_to($datetime, 'Datetime'); |
|
366 | - // before going any further make sure our dates are setup correctly |
|
367 | - // so that the end date is always equal or greater than the start date. |
|
368 | - if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) { |
|
369 | - $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start')); |
|
370 | - $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days'); |
|
371 | - $datetime->save(); |
|
372 | - } |
|
373 | - // now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array |
|
374 | - // because it is possible there was a new one created for the autosave. |
|
375 | - // (save the ID for both key and value to avoid duplications) |
|
376 | - $DTT_ID = $datetime->ID(); |
|
377 | - $saved_dtt_ids[$DTT_ID] = $DTT_ID; |
|
378 | - $saved_dtt_objs[$row] = $datetime; |
|
379 | - //todo if ANY of these updates fail then we want the appropriate global error message. |
|
380 | - } |
|
381 | - $event->save(); |
|
382 | - // now we need to REMOVE any datetimes that got deleted. |
|
383 | - // Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them. |
|
384 | - // So its safe to permanently delete at this point. |
|
385 | - $old_datetimes = explode(',', $data['datetime_IDs']); |
|
386 | - $old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes; |
|
387 | - if (is_array($old_datetimes)) { |
|
388 | - $datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids); |
|
389 | - foreach ($datetimes_to_delete as $id) { |
|
390 | - $id = absint($id); |
|
391 | - if (empty($id)) { |
|
392 | - continue; |
|
393 | - } |
|
394 | - $dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id); |
|
395 | - //remove tkt relationships. |
|
396 | - $related_tickets = $dtt_to_remove->get_many_related('Ticket'); |
|
397 | - foreach ($related_tickets as $tkt) { |
|
398 | - $dtt_to_remove->_remove_relation_to($tkt, 'Ticket'); |
|
399 | - } |
|
400 | - $event->_remove_relation_to($id, 'Datetime'); |
|
401 | - $dtt_to_remove->refresh_cache_of_related_objects(); |
|
402 | - } |
|
403 | - } |
|
404 | - return $saved_dtt_objs; |
|
405 | - } |
|
406 | - |
|
407 | - |
|
408 | - |
|
409 | - /** |
|
410 | - * update tickets |
|
411 | - * |
|
412 | - * @param EE_Event $event Event object being updated |
|
413 | - * @param EE_Datetime[] $saved_datetimes an array of datetime ids being updated |
|
414 | - * @param array $data incoming request data |
|
415 | - * @return EE_Ticket[] |
|
416 | - * @throws EE_Error |
|
417 | - */ |
|
418 | - protected function _update_tickets($event, $saved_datetimes, $data) |
|
419 | - { |
|
420 | - $new_tkt = null; |
|
421 | - $new_default = null; |
|
422 | - //stripslashes because WP filtered the $_POST ($data) array to add slashes |
|
423 | - $data = stripslashes_deep($data); |
|
424 | - $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
425 | - $saved_tickets = $datetimes_on_existing = array(); |
|
426 | - $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
427 | - //load money helper |
|
428 | - foreach ($data['edit_tickets'] as $row => $tkt) { |
|
429 | - $update_prices = $create_new_TKT = false; |
|
430 | - // figure out what datetimes were added to the ticket |
|
431 | - // and what datetimes were removed from the ticket in the session. |
|
432 | - $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][$row]); |
|
433 | - $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][$row]); |
|
434 | - $datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows); |
|
435 | - $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows); |
|
436 | - // trim inputs to ensure any excess whitespace is removed. |
|
437 | - $tkt = array_map( |
|
438 | - function ($ticket_data) { |
|
439 | - return is_array($ticket_data) ? $ticket_data : trim($ticket_data); |
|
440 | - }, |
|
441 | - $tkt |
|
442 | - ); |
|
443 | - // note we are doing conversions to floats here instead of allowing EE_Money_Field to handle |
|
444 | - // because we're doing calculations prior to using the models. |
|
445 | - // note incoming ['TKT_price'] value is already in standard notation (via js). |
|
446 | - $ticket_price = isset($tkt['TKT_price']) |
|
447 | - ? round((float)$tkt['TKT_price'], 3) |
|
448 | - : 0; |
|
449 | - //note incoming base price needs converted from localized value. |
|
450 | - $base_price = isset($tkt['TKT_base_price']) |
|
451 | - ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price']) |
|
452 | - : 0; |
|
453 | - //if ticket price == 0 and $base_price != 0 then ticket price == base_price |
|
454 | - $ticket_price = $ticket_price === 0 && $base_price !== 0 |
|
455 | - ? $base_price |
|
456 | - : $ticket_price; |
|
457 | - $base_price_id = isset($tkt['TKT_base_price_ID']) |
|
458 | - ? $tkt['TKT_base_price_ID'] |
|
459 | - : 0; |
|
460 | - $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][$row]) |
|
461 | - ? $data['edit_prices'][$row] |
|
462 | - : array(); |
|
463 | - $now = null; |
|
464 | - if (empty($tkt['TKT_start_date'])) { |
|
465 | - //lets' use now in the set timezone. |
|
466 | - $now = new DateTime('now', new DateTimeZone($event->get_timezone())); |
|
467 | - $tkt['TKT_start_date'] = $now->format($this->_date_time_format); |
|
468 | - } |
|
469 | - if (empty($tkt['TKT_end_date'])) { |
|
470 | - /** |
|
471 | - * set the TKT_end_date to the first datetime attached to the ticket. |
|
472 | - */ |
|
473 | - $first_dtt = $saved_datetimes[reset($tkt_dtt_rows)]; |
|
474 | - $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format); |
|
475 | - } |
|
476 | - $TKT_values = array( |
|
477 | - 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
478 | - 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
479 | - 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
480 | - 'TKT_description' => ! empty($tkt['TKT_description']) |
|
481 | - && $tkt['TKT_description'] !== esc_html__( |
|
482 | - 'You can modify this description', |
|
483 | - 'event_espresso' |
|
484 | - ) |
|
485 | - ? $tkt['TKT_description'] |
|
486 | - : '', |
|
487 | - 'TKT_start_date' => $tkt['TKT_start_date'], |
|
488 | - 'TKT_end_date' => $tkt['TKT_end_date'], |
|
489 | - 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' |
|
490 | - ? EE_INF |
|
491 | - : $tkt['TKT_qty'], |
|
492 | - 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' |
|
493 | - ? EE_INF |
|
494 | - : $tkt['TKT_uses'], |
|
495 | - 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
496 | - 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
497 | - 'TKT_row' => $row, |
|
498 | - 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0, |
|
499 | - 'TKT_taxable' => ! empty($tkt['TKT_taxable']) ? 1 : 0, |
|
500 | - 'TKT_required' => ! empty($tkt['TKT_required']) ? 1 : 0, |
|
501 | - 'TKT_price' => $ticket_price, |
|
502 | - ); |
|
503 | - // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, |
|
504 | - // which means in turn that the prices will become new prices as well. |
|
505 | - if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
506 | - $TKT_values['TKT_ID'] = 0; |
|
507 | - $TKT_values['TKT_is_default'] = 0; |
|
508 | - $update_prices = true; |
|
509 | - } |
|
510 | - // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
511 | - // we actually do our saves ahead of doing any add_relations to |
|
512 | - // because its entirely possible that this ticket wasn't removed or added to any datetime in the session |
|
513 | - // but DID have it's items modified. |
|
514 | - // keep in mind that if the TKT has been sold (and we have changed pricing information), |
|
515 | - // then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
516 | - if (absint($TKT_values['TKT_ID'])) { |
|
517 | - $ticket = EE_Registry::instance() |
|
518 | - ->load_model('Ticket', array($timezone)) |
|
519 | - ->get_one_by_ID($tkt['TKT_ID']); |
|
520 | - if ($ticket instanceof EE_Ticket) { |
|
521 | - $ticket = $this->_update_ticket_datetimes( |
|
522 | - $ticket, |
|
523 | - $saved_datetimes, |
|
524 | - $datetimes_added, |
|
525 | - $datetimes_removed |
|
526 | - ); |
|
527 | - // are there any registrations using this ticket ? |
|
528 | - $tickets_sold = $ticket->count_related( |
|
529 | - 'Registration', |
|
530 | - array( |
|
531 | - array( |
|
532 | - 'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)), |
|
533 | - ), |
|
534 | - ) |
|
535 | - ); |
|
536 | - //set ticket formats |
|
537 | - $ticket->set_date_format($this->_date_format_strings['date']); |
|
538 | - $ticket->set_time_format($this->_date_format_strings['time']); |
|
539 | - // let's just check the total price for the existing ticket |
|
540 | - // and determine if it matches the new total price. |
|
541 | - // if they are different then we create a new ticket (if tkts sold) |
|
542 | - // if they aren't different then we go ahead and modify existing ticket. |
|
543 | - $create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted() |
|
544 | - ? true : false; |
|
545 | - //set new values |
|
546 | - foreach ($TKT_values as $field => $value) { |
|
547 | - if ($field === 'TKT_qty') { |
|
548 | - $ticket->set_qty($value); |
|
549 | - } else { |
|
550 | - $ticket->set($field, $value); |
|
551 | - } |
|
552 | - } |
|
553 | - // if $create_new_TKT is false then we can safely update the existing ticket. |
|
554 | - // Otherwise we have to create a new ticket. |
|
555 | - if ($create_new_TKT) { |
|
556 | - $new_tkt = $this->_duplicate_ticket($ticket, $price_rows, $ticket_price, $base_price, |
|
557 | - $base_price_id); |
|
558 | - } |
|
559 | - } |
|
560 | - } else { |
|
561 | - // no TKT_id so a new TKT |
|
562 | - $ticket = EE_Ticket::new_instance( |
|
563 | - $TKT_values, |
|
564 | - $timezone, |
|
565 | - array($this->_date_format_strings['date'], $this->_date_format_strings['time']) |
|
566 | - ); |
|
567 | - if ($ticket instanceof EE_Ticket) { |
|
568 | - // make sure ticket has an ID of setting relations won't work |
|
569 | - $ticket->save(); |
|
570 | - $ticket = $this->_update_ticket_datetimes( |
|
571 | - $ticket, |
|
572 | - $saved_datetimes, |
|
573 | - $datetimes_added, |
|
574 | - $datetimes_removed |
|
575 | - ); |
|
576 | - $update_prices = true; |
|
577 | - } |
|
578 | - } |
|
579 | - //make sure any current values have been saved. |
|
580 | - //$ticket->save(); |
|
581 | - // before going any further make sure our dates are setup correctly |
|
582 | - // so that the end date is always equal or greater than the start date. |
|
583 | - if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) { |
|
584 | - $ticket->set('TKT_end_date', $ticket->get('TKT_start_date')); |
|
585 | - $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days'); |
|
586 | - } |
|
587 | - //let's make sure the base price is handled |
|
588 | - $ticket = ! $create_new_TKT ? $this->_add_prices_to_ticket(array(), $ticket, $update_prices, $base_price, |
|
589 | - $base_price_id) : $ticket; |
|
590 | - //add/update price_modifiers |
|
591 | - $ticket = ! $create_new_TKT ? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices) : $ticket; |
|
592 | - //need to make sue that the TKT_price is accurate after saving the prices. |
|
593 | - $ticket->ensure_TKT_Price_correct(); |
|
594 | - //handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave. |
|
595 | - if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) { |
|
596 | - $update_prices = true; |
|
597 | - $new_default = clone $ticket; |
|
598 | - $new_default->set('TKT_ID', 0); |
|
599 | - $new_default->set('TKT_is_default', 1); |
|
600 | - $new_default->set('TKT_row', 1); |
|
601 | - $new_default->set('TKT_price', $ticket_price); |
|
602 | - // remove any dtt relations cause we DON'T want dtt relations attached |
|
603 | - // (note this is just removing the cached relations in the object) |
|
604 | - $new_default->_remove_relations('Datetime'); |
|
605 | - //todo we need to add the current attached prices as new prices to the new default ticket. |
|
606 | - $new_default = $this->_add_prices_to_ticket($price_rows, $new_default, $update_prices); |
|
607 | - //don't forget the base price! |
|
608 | - $new_default = $this->_add_prices_to_ticket( |
|
609 | - array(), |
|
610 | - $new_default, |
|
611 | - $update_prices, |
|
612 | - $base_price, |
|
613 | - $base_price_id |
|
614 | - ); |
|
615 | - $new_default->save(); |
|
616 | - do_action( |
|
617 | - 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket', |
|
618 | - $new_default, |
|
619 | - $row, |
|
620 | - $ticket, |
|
621 | - $data |
|
622 | - ); |
|
623 | - } |
|
624 | - // DO ALL dtt relationships for both current tickets and any archived tickets |
|
625 | - // for the given dtt that are related to the current ticket. |
|
626 | - // TODO... not sure exactly how we're going to do this considering we don't know |
|
627 | - // what current ticket the archived tickets are related to |
|
628 | - // (and TKT_parent is used for autosaves so that's not a field we can reliably use). |
|
629 | - //let's assign any tickets that have been setup to the saved_tickets tracker |
|
630 | - //save existing TKT |
|
631 | - $ticket->save(); |
|
632 | - if ($create_new_TKT && $new_tkt instanceof EE_Ticket) { |
|
633 | - //save new TKT |
|
634 | - $new_tkt->save(); |
|
635 | - //add new ticket to array |
|
636 | - $saved_tickets[$new_tkt->ID()] = $new_tkt; |
|
637 | - do_action( |
|
638 | - 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket', |
|
639 | - $new_tkt, |
|
640 | - $row, |
|
641 | - $tkt, |
|
642 | - $data |
|
643 | - ); |
|
644 | - } else { |
|
645 | - //add tkt to saved tkts |
|
646 | - $saved_tickets[$ticket->ID()] = $ticket; |
|
647 | - do_action( |
|
648 | - 'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket', |
|
649 | - $ticket, |
|
650 | - $row, |
|
651 | - $tkt, |
|
652 | - $data |
|
653 | - ); |
|
654 | - } |
|
655 | - } |
|
656 | - // now we need to handle tickets actually "deleted permanently". |
|
657 | - // There are cases where we'd want this to happen |
|
658 | - // (i.e. autosaves are happening and then in between autosaves the user trashes a ticket). |
|
659 | - // Or a draft event was saved and in the process of editing a ticket is trashed. |
|
660 | - // No sense in keeping all the related data in the db! |
|
661 | - $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets; |
|
662 | - $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
663 | - foreach ($tickets_removed as $id) { |
|
664 | - $id = absint($id); |
|
665 | - //get the ticket for this id |
|
666 | - $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
667 | - //if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime |
|
668 | - if ($tkt_to_remove->get('TKT_is_default')) { |
|
669 | - continue; |
|
670 | - } |
|
671 | - // if this tkt has any registrations attached so then we just ARCHIVE |
|
672 | - // because we don't actually permanently delete these tickets. |
|
673 | - if ($tkt_to_remove->count_related('Registration') > 0) { |
|
674 | - $tkt_to_remove->delete(); |
|
675 | - continue; |
|
676 | - } |
|
677 | - // need to get all the related datetimes on this ticket and remove from every single one of them |
|
678 | - // (remember this process can ONLY kick off if there are NO tkts_sold) |
|
679 | - $datetimes = $tkt_to_remove->get_many_related('Datetime'); |
|
680 | - foreach ($datetimes as $datetime) { |
|
681 | - $tkt_to_remove->_remove_relation_to($datetime, 'Datetime'); |
|
682 | - } |
|
683 | - // need to do the same for prices (except these prices can also be deleted because again, |
|
684 | - // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
685 | - $tkt_to_remove->delete_related_permanently('Price'); |
|
686 | - do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove); |
|
687 | - // finally let's delete this ticket |
|
688 | - // (which should not be blocked at this point b/c we've removed all our relationships) |
|
689 | - $tkt_to_remove->delete_permanently(); |
|
690 | - } |
|
691 | - return $saved_tickets; |
|
692 | - } |
|
693 | - |
|
694 | - |
|
695 | - |
|
696 | - /** |
|
697 | - * @access protected |
|
698 | - * @param \EE_Ticket $ticket |
|
699 | - * @param \EE_Datetime[] $saved_datetimes |
|
700 | - * @param \EE_Datetime[] $added_datetimes |
|
701 | - * @param \EE_Datetime[] $removed_datetimes |
|
702 | - * @return \EE_Ticket |
|
703 | - * @throws \EE_Error |
|
704 | - */ |
|
705 | - protected function _update_ticket_datetimes( |
|
706 | - EE_Ticket $ticket, |
|
707 | - $saved_datetimes = array(), |
|
708 | - $added_datetimes = array(), |
|
709 | - $removed_datetimes = array() |
|
710 | - ) { |
|
711 | - // to start we have to add the ticket to all the datetimes its supposed to be with, |
|
712 | - // and removing the ticket from datetimes it got removed from. |
|
713 | - // first let's add datetimes |
|
714 | - if (! empty($added_datetimes) && is_array($added_datetimes)) { |
|
715 | - foreach ($added_datetimes as $row_id) { |
|
716 | - $row_id = (int)$row_id; |
|
717 | - if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
|
718 | - $ticket->_add_relation_to($saved_datetimes[$row_id], 'Datetime'); |
|
719 | - // Is this an existing ticket (has an ID) and does it have any sold? |
|
720 | - // If so, then we need to add that to the DTT sold because this DTT is getting added. |
|
721 | - if ($ticket->ID() && $ticket->sold() > 0) { |
|
722 | - $saved_datetimes[$row_id]->increase_sold($ticket->sold()); |
|
723 | - $saved_datetimes[$row_id]->save(); |
|
724 | - } |
|
725 | - } |
|
726 | - } |
|
727 | - } |
|
728 | - // then remove datetimes |
|
729 | - if (! empty($removed_datetimes) && is_array($removed_datetimes)) { |
|
730 | - foreach ($removed_datetimes as $row_id) { |
|
731 | - $row_id = (int)$row_id; |
|
732 | - // its entirely possible that a datetime got deleted (instead of just removed from relationship. |
|
733 | - // So make sure we skip over this if the dtt isn't in the $saved_datetimes array) |
|
734 | - if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
|
735 | - $ticket->_remove_relation_to($saved_datetimes[$row_id], 'Datetime'); |
|
736 | - // Is this an existing ticket (has an ID) and does it have any sold? |
|
737 | - // If so, then we need to remove it's sold from the DTT_sold. |
|
738 | - if ($ticket->ID() && $ticket->sold() > 0) { |
|
739 | - $saved_datetimes[$row_id]->decrease_sold($ticket->sold()); |
|
740 | - $saved_datetimes[$row_id]->save(); |
|
741 | - } |
|
742 | - } |
|
743 | - } |
|
744 | - } |
|
745 | - // cap ticket qty by datetime reg limits |
|
746 | - $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit'))); |
|
747 | - return $ticket; |
|
748 | - } |
|
749 | - |
|
750 | - |
|
751 | - |
|
752 | - /** |
|
753 | - * @access protected |
|
754 | - * @param \EE_Ticket $ticket |
|
755 | - * @param array $price_rows |
|
756 | - * @param int $ticket_price |
|
757 | - * @param int $base_price |
|
758 | - * @param int $base_price_id |
|
759 | - * @return \EE_Ticket |
|
760 | - * @throws \EE_Error |
|
761 | - */ |
|
762 | - protected function _duplicate_ticket( |
|
763 | - EE_Ticket $ticket, |
|
764 | - $price_rows = array(), |
|
765 | - $ticket_price = 0, |
|
766 | - $base_price = 0, |
|
767 | - $base_price_id = 0 |
|
768 | - ) { |
|
769 | - // create new ticket that's a copy of the existing |
|
770 | - // except a new id of course (and not archived) |
|
771 | - // AND has the new TKT_price associated with it. |
|
772 | - $new_ticket = clone $ticket; |
|
773 | - $new_ticket->set('TKT_ID', 0); |
|
774 | - $new_ticket->set('TKT_deleted', 0); |
|
775 | - $new_ticket->set('TKT_price', $ticket_price); |
|
776 | - $new_ticket->set('TKT_sold', 0); |
|
777 | - // let's get a new ID for this ticket |
|
778 | - $new_ticket->save(); |
|
779 | - // we also need to make sure this new ticket gets the same datetime attachments as the archived ticket |
|
780 | - $datetimes_on_existing = $ticket->get_many_related('Datetime'); |
|
781 | - $new_ticket = $this->_update_ticket_datetimes( |
|
782 | - $new_ticket, |
|
783 | - $datetimes_on_existing, |
|
784 | - array_keys($datetimes_on_existing) |
|
785 | - ); |
|
786 | - // $ticket will get archived later b/c we are NOT adding it to the saved_tickets array. |
|
787 | - // if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining |
|
788 | - // available. |
|
789 | - if ($ticket->sold() > 0) { |
|
790 | - $new_qty = $ticket->qty() - $ticket->sold(); |
|
791 | - $new_ticket->set_qty($new_qty); |
|
792 | - } |
|
793 | - //now we update the prices just for this ticket |
|
794 | - $new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true); |
|
795 | - //and we update the base price |
|
796 | - $new_ticket = $this->_add_prices_to_ticket(array(), $new_ticket, true, $base_price, $base_price_id); |
|
797 | - return $new_ticket; |
|
798 | - } |
|
799 | - |
|
800 | - |
|
801 | - |
|
802 | - /** |
|
803 | - * This attaches a list of given prices to a ticket. |
|
804 | - * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
805 | - * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
806 | - * price info and prices are automatically "archived" via the ticket. |
|
807 | - * |
|
808 | - * @access private |
|
809 | - * @param array $prices Array of prices from the form. |
|
810 | - * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
811 | - * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
812 | - * @param int|bool $base_price if FALSE then NOT doing a base price add. |
|
813 | - * @param int|bool $base_price_id if present then this is the base_price_id being updated. |
|
814 | - * @return EE_Ticket |
|
815 | - * @throws EE_Error |
|
816 | - */ |
|
817 | - protected function _add_prices_to_ticket( |
|
818 | - $prices = array(), |
|
819 | - EE_Ticket $ticket, |
|
820 | - $new_prices = false, |
|
821 | - $base_price = false, |
|
822 | - $base_price_id = false |
|
823 | - ) { |
|
824 | - // let's just get any current prices that may exist on the given ticket |
|
825 | - // so we can remove any prices that got trashed in this session. |
|
826 | - $current_prices_on_ticket = $base_price !== false |
|
827 | - ? $ticket->base_price(true) |
|
828 | - : $ticket->price_modifiers(); |
|
829 | - $updated_prices = array(); |
|
830 | - // if $base_price ! FALSE then updating a base price. |
|
831 | - if ($base_price !== false) { |
|
832 | - $prices[1] = array( |
|
833 | - 'PRC_ID' => $new_prices || $base_price_id === 1 ? null : $base_price_id, |
|
834 | - 'PRT_ID' => 1, |
|
835 | - 'PRC_amount' => $base_price, |
|
836 | - 'PRC_name' => $ticket->get('TKT_name'), |
|
837 | - 'PRC_desc' => $ticket->get('TKT_description'), |
|
838 | - ); |
|
839 | - } |
|
840 | - //possibly need to save tkt |
|
841 | - if (! $ticket->ID()) { |
|
842 | - $ticket->save(); |
|
843 | - } |
|
844 | - foreach ($prices as $row => $prc) { |
|
845 | - $prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null; |
|
846 | - if (empty($prt_id)) { |
|
847 | - continue; |
|
848 | - } //prices MUST have a price type id. |
|
849 | - $PRC_values = array( |
|
850 | - 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
851 | - 'PRT_ID' => $prt_id, |
|
852 | - 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
853 | - 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
854 | - 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
855 | - 'PRC_is_default' => false, |
|
856 | - //make sure we set PRC_is_default to false for all ticket saves from event_editor |
|
857 | - 'PRC_order' => $row, |
|
858 | - ); |
|
859 | - if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
860 | - $PRC_values['PRC_ID'] = 0; |
|
861 | - $price = EE_Registry::instance()->load_class( |
|
862 | - 'Price', |
|
863 | - array($PRC_values), |
|
864 | - false, |
|
865 | - false |
|
866 | - ); |
|
867 | - } else { |
|
868 | - $price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
869 | - //update this price with new values |
|
870 | - foreach ($PRC_values as $field => $value) { |
|
871 | - $price->set($field, $value); |
|
872 | - } |
|
873 | - } |
|
874 | - $price->save(); |
|
875 | - $updated_prices[$price->ID()] = $price; |
|
876 | - $ticket->_add_relation_to($price, 'Price'); |
|
877 | - } |
|
878 | - //now let's remove any prices that got removed from the ticket |
|
879 | - if (! empty ($current_prices_on_ticket)) { |
|
880 | - $current = array_keys($current_prices_on_ticket); |
|
881 | - $updated = array_keys($updated_prices); |
|
882 | - $prices_to_remove = array_diff($current, $updated); |
|
883 | - if (! empty($prices_to_remove)) { |
|
884 | - foreach ($prices_to_remove as $prc_id) { |
|
885 | - $p = $current_prices_on_ticket[$prc_id]; |
|
886 | - $ticket->_remove_relation_to($p, 'Price'); |
|
887 | - //delete permanently the price |
|
888 | - $p->delete_permanently(); |
|
889 | - } |
|
890 | - } |
|
891 | - } |
|
892 | - return $ticket; |
|
893 | - } |
|
894 | - |
|
895 | - |
|
896 | - |
|
897 | - /** |
|
898 | - * @param Events_Admin_Page $event_admin_obj |
|
899 | - * @return Events_Admin_Page |
|
900 | - */ |
|
901 | - public function autosave_handling( Events_Admin_Page $event_admin_obj) |
|
902 | - { |
|
903 | - return $event_admin_obj; |
|
904 | - //doing nothing for the moment. |
|
905 | - // todo when I get to this remember that I need to set the template args on the $event_admin_obj |
|
906 | - // (use the set_template_args() method) |
|
907 | - /** |
|
908 | - * need to remember to handle TICKET DEFAULT saves correctly: I've got two input fields in the dom: |
|
909 | - * 1. TKT_is_default_selector (visible) |
|
910 | - * 2. TKT_is_default (hidden) |
|
911 | - * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket |
|
912 | - * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want |
|
913 | - * this ticket to be saved as a default. |
|
914 | - * The tricky part is, on an initial display on create or edit (or after manually updating), |
|
915 | - * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true |
|
916 | - * if this is a create. However, after an autosave, users will want some sort of indicator that |
|
917 | - * the TKT HAS been saved as a default.. |
|
918 | - * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking. |
|
919 | - * On Autosave: |
|
920 | - * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements, |
|
921 | - * then set the TKT_is_default to false. |
|
922 | - * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well). |
|
923 | - * We do NOT create a new default ticket. The checkbox stays selected after autosave. |
|
924 | - * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket. |
|
925 | - */ |
|
926 | - } |
|
927 | - |
|
928 | - |
|
929 | - |
|
930 | - /** |
|
931 | - * @throws DomainException |
|
932 | - * @throws EE_Error |
|
933 | - */ |
|
934 | - public function pricing_metabox() |
|
935 | - { |
|
936 | - $existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array(); |
|
937 | - $event = $this->_adminpage_obj->get_cpt_model_obj(); |
|
938 | - //set is_creating_event property. |
|
939 | - $EVT_ID = $event->ID(); |
|
940 | - $this->_is_creating_event = absint($EVT_ID) !== 0 ? false : true; |
|
941 | - //default main template args |
|
942 | - $main_template_args = array( |
|
943 | - 'event_datetime_help_link' => EEH_Template::get_help_tab_link( |
|
944 | - 'event_editor_event_datetimes_help_tab', |
|
945 | - $this->_adminpage_obj->page_slug, |
|
946 | - $this->_adminpage_obj->get_req_action(), |
|
947 | - false, |
|
948 | - false |
|
949 | - ), |
|
950 | - // todo need to add a filter to the template for the help text |
|
951 | - // in the Events_Admin_Page core file so we can add further help |
|
952 | - 'existing_datetime_ids' => '', |
|
953 | - 'total_dtt_rows' => 1, |
|
954 | - 'add_new_dtt_help_link' => EEH_Template::get_help_tab_link( |
|
955 | - 'add_new_dtt_info', |
|
956 | - $this->_adminpage_obj->page_slug, |
|
957 | - $this->_adminpage_obj->get_req_action(), |
|
958 | - false, |
|
959 | - false |
|
960 | - ), |
|
961 | - //todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
962 | - 'datetime_rows' => '', |
|
963 | - 'show_tickets_container' => '', |
|
964 | - //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '', |
|
965 | - 'ticket_rows' => '', |
|
966 | - 'existing_ticket_ids' => '', |
|
967 | - 'total_ticket_rows' => 1, |
|
968 | - 'ticket_js_structure' => '', |
|
969 | - 'ee_collapsible_status' => ' ee-collapsible-open' |
|
970 | - //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open' |
|
971 | - ); |
|
972 | - $timezone = $event instanceof EE_Event ? $event->timezone_string() : null; |
|
973 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
974 | - /** |
|
975 | - * 1. Start with retrieving Datetimes |
|
976 | - * 2. For each datetime get related tickets |
|
977 | - * 3. For each ticket get related prices |
|
978 | - */ |
|
979 | - /** @var EEM_Datetime $datetime_model */ |
|
980 | - $datetime_model = EE_Registry::instance()->load_model('Datetime', array($timezone)); |
|
981 | - $datetimes = $datetime_model->get_all_event_dates($EVT_ID); |
|
982 | - $main_template_args['total_dtt_rows'] = count($datetimes); |
|
983 | - /** |
|
984 | - * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486 |
|
985 | - * for why we are counting $datetime_row and then setting that on the Datetime object |
|
986 | - */ |
|
987 | - $datetime_row = 1; |
|
988 | - foreach ($datetimes as $datetime) { |
|
989 | - $DTT_ID = $datetime->get('DTT_ID'); |
|
990 | - $datetime->set('DTT_order', $datetime_row); |
|
991 | - $existing_datetime_ids[] = $DTT_ID; |
|
992 | - //tickets attached |
|
993 | - $related_tickets = $datetime->ID() > 0 |
|
994 | - ? $datetime->get_many_related( |
|
995 | - 'Ticket', |
|
996 | - array( |
|
997 | - array( |
|
998 | - 'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0), |
|
999 | - ), |
|
1000 | - 'default_where_conditions' => 'none', |
|
1001 | - 'order_by' => array('TKT_order' => 'ASC'), |
|
1002 | - ) |
|
1003 | - ) |
|
1004 | - : array(); |
|
1005 | - //if there are no related tickets this is likely a new event OR autodraft |
|
1006 | - // event so we need to generate the default tickets because datetimes |
|
1007 | - // ALWAYS have at least one related ticket!!. EXCEPT, we dont' do this if there is already more than one |
|
1008 | - // datetime on the event. |
|
1009 | - if (empty ($related_tickets) && count($datetimes) < 2) { |
|
1010 | - /** @var EEM_Ticket $ticket_model */ |
|
1011 | - $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
1012 | - $related_tickets = $ticket_model->get_all_default_tickets(); |
|
1013 | - // this should be ordered by TKT_ID, so let's grab the first default ticket |
|
1014 | - // (which will be the main default) and ensure it has any default prices added to it (but do NOT save). |
|
1015 | - $default_prices = EEM_Price::instance()->get_all_default_prices(); |
|
1016 | - $main_default_ticket = reset($related_tickets); |
|
1017 | - if ($main_default_ticket instanceof EE_Ticket) { |
|
1018 | - foreach ($default_prices as $default_price) { |
|
1019 | - if ($default_price instanceof EE_Price && $default_price->is_base_price()) { |
|
1020 | - continue; |
|
1021 | - } |
|
1022 | - $main_default_ticket->cache('Price', $default_price); |
|
1023 | - } |
|
1024 | - } |
|
1025 | - } |
|
1026 | - // we can't actually setup rows in this loop yet cause we don't know all |
|
1027 | - // the unique tickets for this event yet (tickets are linked through all datetimes). |
|
1028 | - // So we're going to temporarily cache some of that information. |
|
1029 | - //loop through and setup the ticket rows and make sure the order is set. |
|
1030 | - foreach ($related_tickets as $ticket) { |
|
1031 | - $TKT_ID = $ticket->get('TKT_ID'); |
|
1032 | - $ticket_row = $ticket->get('TKT_row'); |
|
1033 | - //we only want unique tickets in our final display!! |
|
1034 | - if (! in_array($TKT_ID, $existing_ticket_ids, true)) { |
|
1035 | - $existing_ticket_ids[] = $TKT_ID; |
|
1036 | - $all_tickets[] = $ticket; |
|
1037 | - } |
|
1038 | - //temporary cache of this ticket info for this datetime for later processing of datetime rows. |
|
1039 | - $datetime_tickets[$DTT_ID][] = $ticket_row; |
|
1040 | - //temporary cache of this datetime info for this ticket for later processing of ticket rows. |
|
1041 | - if ( |
|
1042 | - ! isset($ticket_datetimes[$TKT_ID]) |
|
1043 | - || ! in_array($datetime_row, $ticket_datetimes[$TKT_ID], true) |
|
1044 | - ) { |
|
1045 | - $ticket_datetimes[$TKT_ID][] = $datetime_row; |
|
1046 | - } |
|
1047 | - } |
|
1048 | - $datetime_row++; |
|
1049 | - } |
|
1050 | - $main_template_args['total_ticket_rows'] = count($existing_ticket_ids); |
|
1051 | - $main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
1052 | - $main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
1053 | - //sort $all_tickets by order |
|
1054 | - usort( |
|
1055 | - $all_tickets, |
|
1056 | - function (EE_Ticket $a, EE_Ticket $b) { |
|
1057 | - $a_order = (int)$a->get('TKT_order'); |
|
1058 | - $b_order = (int)$b->get('TKT_order'); |
|
1059 | - if ($a_order === $b_order) { |
|
1060 | - return 0; |
|
1061 | - } |
|
1062 | - return ($a_order < $b_order) ? -1 : 1; |
|
1063 | - } |
|
1064 | - ); |
|
1065 | - // k NOW we have all the data we need for setting up the dtt rows |
|
1066 | - // and ticket rows so we start our dtt loop again. |
|
1067 | - $datetime_row = 1; |
|
1068 | - foreach ($datetimes as $datetime) { |
|
1069 | - $main_template_args['datetime_rows'] .= $this->_get_datetime_row( |
|
1070 | - $datetime_row, |
|
1071 | - $datetime, |
|
1072 | - $datetime_tickets, |
|
1073 | - $all_tickets, |
|
1074 | - false, |
|
1075 | - $datetimes |
|
1076 | - ); |
|
1077 | - $datetime_row++; |
|
1078 | - } |
|
1079 | - //then loop through all tickets for the ticket rows. |
|
1080 | - $ticket_row = 1; |
|
1081 | - foreach ($all_tickets as $ticket) { |
|
1082 | - $main_template_args['ticket_rows'] .= $this->_get_ticket_row( |
|
1083 | - $ticket_row, |
|
1084 | - $ticket, |
|
1085 | - $ticket_datetimes, |
|
1086 | - $datetimes, |
|
1087 | - false, |
|
1088 | - $all_tickets |
|
1089 | - ); |
|
1090 | - $ticket_row++; |
|
1091 | - } |
|
1092 | - $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets); |
|
1093 | - EEH_Template::display_template( |
|
1094 | - PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php', |
|
1095 | - $main_template_args |
|
1096 | - ); |
|
1097 | - } |
|
1098 | - |
|
1099 | - |
|
1100 | - |
|
1101 | - /** |
|
1102 | - * @param int $datetime_row |
|
1103 | - * @param EE_Datetime $datetime |
|
1104 | - * @param array $datetime_tickets |
|
1105 | - * @param array $all_tickets |
|
1106 | - * @param bool $default |
|
1107 | - * @param array $all_datetimes |
|
1108 | - * @return mixed |
|
1109 | - * @throws DomainException |
|
1110 | - * @throws EE_Error |
|
1111 | - */ |
|
1112 | - protected function _get_datetime_row( |
|
1113 | - $datetime_row, |
|
1114 | - EE_Datetime $datetime, |
|
1115 | - $datetime_tickets = array(), |
|
1116 | - $all_tickets = array(), |
|
1117 | - $default = false, |
|
1118 | - $all_datetimes = array() |
|
1119 | - ) { |
|
1120 | - $dtt_display_template_args = array( |
|
1121 | - 'dtt_edit_row' => $this->_get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes), |
|
1122 | - 'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row( |
|
1123 | - $datetime_row, |
|
1124 | - $datetime, |
|
1125 | - $datetime_tickets, |
|
1126 | - $all_tickets, |
|
1127 | - $default |
|
1128 | - ), |
|
1129 | - 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
1130 | - ); |
|
1131 | - return EEH_Template::display_template( |
|
1132 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php', |
|
1133 | - $dtt_display_template_args, |
|
1134 | - true |
|
1135 | - ); |
|
1136 | - } |
|
1137 | - |
|
1138 | - |
|
1139 | - |
|
1140 | - /** |
|
1141 | - * This method is used to generate a dtt fields edit row. |
|
1142 | - * The same row is used to generate a row with valid DTT objects |
|
1143 | - * and the default row that is used as the skeleton by the js. |
|
1144 | - * |
|
1145 | - * @param int $datetime_row The row number for the row being generated. |
|
1146 | - * @param EE_Datetime $datetime |
|
1147 | - * @param bool $default Whether a default row is being generated or not. |
|
1148 | - * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor. |
|
1149 | - * @return string |
|
1150 | - * @throws DomainException |
|
1151 | - * @throws EE_Error |
|
1152 | - */ |
|
1153 | - protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes) |
|
1154 | - { |
|
1155 | - // if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true. |
|
1156 | - $default = ! $datetime instanceof EE_Datetime ? true : $default; |
|
1157 | - $template_args = array( |
|
1158 | - 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
1159 | - 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
1160 | - 'edit_dtt_expanded' => '', |
|
1161 | - 'DTT_ID' => $default ? '' : $datetime->ID(), |
|
1162 | - 'DTT_name' => $default ? '' : $datetime->name(), |
|
1163 | - 'DTT_description' => $default ? '' : $datetime->description(), |
|
1164 | - 'DTT_EVT_start' => $default ? '' : $datetime->start_date($this->_date_time_format), |
|
1165 | - 'DTT_EVT_end' => $default ? '' : $datetime->end_date($this->_date_time_format), |
|
1166 | - 'DTT_reg_limit' => $default |
|
1167 | - ? '' |
|
1168 | - : $datetime->get_pretty( |
|
1169 | - 'DTT_reg_limit', |
|
1170 | - 'input' |
|
1171 | - ), |
|
1172 | - 'DTT_order' => $default ? 'DTTNUM' : $datetime_row, |
|
1173 | - 'dtt_sold' => $default ? '0' : $datetime->get('DTT_sold'), |
|
1174 | - 'dtt_reserved' => $default ? '0' : $datetime->reserved(), |
|
1175 | - 'clone_icon' => ! empty($datetime) && $datetime->get('DTT_sold') > 0 |
|
1176 | - ? '' |
|
1177 | - : 'clone-icon ee-icon ee-icon-clone clickable', |
|
1178 | - 'trash_icon' => ! empty($datetime) && $datetime->get('DTT_sold') > 0 |
|
1179 | - ? 'ee-lock-icon' |
|
1180 | - : 'trash-icon dashicons dashicons-post-trash clickable', |
|
1181 | - 'reg_list_url' => $default || ! $datetime->event() instanceof \EE_Event |
|
1182 | - ? '' |
|
1183 | - : EE_Admin_Page::add_query_args_and_nonce( |
|
1184 | - array('event_id' => $datetime->event()->ID(), 'datetime_id' => $datetime->ID()), |
|
1185 | - REG_ADMIN_URL |
|
1186 | - ), |
|
1187 | - ); |
|
1188 | - $template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' |
|
1189 | - ? ' style="display:none"' |
|
1190 | - : ''; |
|
1191 | - //allow filtering of template args at this point. |
|
1192 | - $template_args = apply_filters( |
|
1193 | - 'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args', |
|
1194 | - $template_args, |
|
1195 | - $datetime_row, |
|
1196 | - $datetime, |
|
1197 | - $default, |
|
1198 | - $all_datetimes, |
|
1199 | - $this->_is_creating_event |
|
1200 | - ); |
|
1201 | - return EEH_Template::display_template( |
|
1202 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php', |
|
1203 | - $template_args, |
|
1204 | - true |
|
1205 | - ); |
|
1206 | - } |
|
1207 | - |
|
1208 | - |
|
1209 | - |
|
1210 | - /** |
|
1211 | - * @param int $datetime_row |
|
1212 | - * @param EE_Datetime $datetime |
|
1213 | - * @param array $datetime_tickets |
|
1214 | - * @param array $all_tickets |
|
1215 | - * @param bool $default |
|
1216 | - * @return mixed |
|
1217 | - * @throws DomainException |
|
1218 | - * @throws EE_Error |
|
1219 | - */ |
|
1220 | - protected function _get_dtt_attached_tickets_row( |
|
1221 | - $datetime_row, |
|
1222 | - $datetime, |
|
1223 | - $datetime_tickets = array(), |
|
1224 | - $all_tickets = array(), |
|
1225 | - $default |
|
1226 | - ) { |
|
1227 | - $template_args = array( |
|
1228 | - 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
1229 | - 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
1230 | - 'DTT_description' => $default ? '' : $datetime->description(), |
|
1231 | - 'datetime_tickets_list' => $default ? '<li class="hidden"></li>' : '', |
|
1232 | - 'show_tickets_row' => ' style="display:none;"', |
|
1233 | - 'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link( |
|
1234 | - 'add_new_ticket_via_datetime', |
|
1235 | - $this->_adminpage_obj->page_slug, |
|
1236 | - $this->_adminpage_obj->get_req_action(), |
|
1237 | - false, |
|
1238 | - false |
|
1239 | - ), |
|
1240 | - //todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
1241 | - 'DTT_ID' => $default ? '' : $datetime->ID(), |
|
1242 | - ); |
|
1243 | - //need to setup the list items (but only if this isn't a default skeleton setup) |
|
1244 | - if (! $default) { |
|
1245 | - $ticket_row = 1; |
|
1246 | - foreach ($all_tickets as $ticket) { |
|
1247 | - $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
|
1248 | - $datetime_row, |
|
1249 | - $ticket_row, |
|
1250 | - $datetime, |
|
1251 | - $ticket, |
|
1252 | - $datetime_tickets, |
|
1253 | - $default |
|
1254 | - ); |
|
1255 | - $ticket_row++; |
|
1256 | - } |
|
1257 | - } |
|
1258 | - //filter template args at this point |
|
1259 | - $template_args = apply_filters( |
|
1260 | - 'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args', |
|
1261 | - $template_args, |
|
1262 | - $datetime_row, |
|
1263 | - $datetime, |
|
1264 | - $datetime_tickets, |
|
1265 | - $all_tickets, |
|
1266 | - $default, |
|
1267 | - $this->_is_creating_event |
|
1268 | - ); |
|
1269 | - return EEH_Template::display_template( |
|
1270 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php', |
|
1271 | - $template_args, |
|
1272 | - true |
|
1273 | - ); |
|
1274 | - } |
|
1275 | - |
|
1276 | - |
|
1277 | - |
|
1278 | - /** |
|
1279 | - * @param int $datetime_row |
|
1280 | - * @param int $ticket_row |
|
1281 | - * @param EE_Datetime $datetime |
|
1282 | - * @param EE_Ticket $ticket |
|
1283 | - * @param array $datetime_tickets |
|
1284 | - * @param bool $default |
|
1285 | - * @return mixed |
|
1286 | - * @throws DomainException |
|
1287 | - * @throws EE_Error |
|
1288 | - */ |
|
1289 | - protected function _get_datetime_tickets_list_item( |
|
1290 | - $datetime_row, |
|
1291 | - $ticket_row, |
|
1292 | - $datetime, |
|
1293 | - $ticket, |
|
1294 | - $datetime_tickets = array(), |
|
1295 | - $default |
|
1296 | - ) { |
|
1297 | - $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[$datetime->ID()]) |
|
1298 | - ? $datetime_tickets[$datetime->ID()] |
|
1299 | - : array(); |
|
1300 | - $display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0; |
|
1301 | - $no_ticket = $default && empty($ticket); |
|
1302 | - $template_args = array( |
|
1303 | - 'dtt_row' => $default |
|
1304 | - ? 'DTTNUM' |
|
1305 | - : $datetime_row, |
|
1306 | - 'tkt_row' => $no_ticket |
|
1307 | - ? 'TICKETNUM' |
|
1308 | - : $ticket_row, |
|
1309 | - 'datetime_ticket_checked' => in_array($display_row, $dtt_tkts, true) |
|
1310 | - ? ' checked="checked"' |
|
1311 | - : '', |
|
1312 | - 'ticket_selected' => in_array($display_row, $dtt_tkts, true) |
|
1313 | - ? ' ticket-selected' |
|
1314 | - : '', |
|
1315 | - 'TKT_name' => $no_ticket |
|
1316 | - ? 'TKTNAME' |
|
1317 | - : $ticket->get('TKT_name'), |
|
1318 | - 'tkt_status_class' => $no_ticket || $this->_is_creating_event |
|
1319 | - ? ' tkt-status-' . EE_Ticket::onsale |
|
1320 | - : ' tkt-status-' . $ticket->ticket_status(), |
|
1321 | - ); |
|
1322 | - //filter template args |
|
1323 | - $template_args = apply_filters( |
|
1324 | - 'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args', |
|
1325 | - $template_args, |
|
1326 | - $datetime_row, |
|
1327 | - $ticket_row, |
|
1328 | - $datetime, |
|
1329 | - $ticket, |
|
1330 | - $datetime_tickets, |
|
1331 | - $default, |
|
1332 | - $this->_is_creating_event |
|
1333 | - ); |
|
1334 | - return EEH_Template::display_template( |
|
1335 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php', |
|
1336 | - $template_args, |
|
1337 | - true |
|
1338 | - ); |
|
1339 | - } |
|
1340 | - |
|
1341 | - |
|
1342 | - |
|
1343 | - /** |
|
1344 | - * This generates the ticket row for tickets. |
|
1345 | - * This same method is used to generate both the actual rows and the js skeleton row |
|
1346 | - * (when default === true) |
|
1347 | - * |
|
1348 | - * @param int $ticket_row Represents the row number being generated. |
|
1349 | - * @param $ticket |
|
1350 | - * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket |
|
1351 | - * or empty for default |
|
1352 | - * @param EE_Datetime[] $all_datetimes All Datetimes on the event or empty for default. |
|
1353 | - * @param bool $default Whether default row being generated or not. |
|
1354 | - * @param EE_Ticket[] $all_tickets This is an array of all tickets attached to the event |
|
1355 | - * (or empty in the case of defaults) |
|
1356 | - * @return mixed |
|
1357 | - * @throws DomainException |
|
1358 | - * @throws EE_Error |
|
1359 | - */ |
|
1360 | - protected function _get_ticket_row( |
|
1361 | - $ticket_row, |
|
1362 | - $ticket, |
|
1363 | - $ticket_datetimes, |
|
1364 | - $all_datetimes, |
|
1365 | - $default = false, |
|
1366 | - $all_tickets = array() |
|
1367 | - ) { |
|
1368 | - // if $ticket is not an instance of EE_Ticket then force default to true. |
|
1369 | - $default = ! $ticket instanceof EE_Ticket ? true : $default; |
|
1370 | - $prices = ! empty($ticket) && ! $default ? $ticket->get_many_related('Price', |
|
1371 | - array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC'))) : array(); |
|
1372 | - // if there is only one price (which would be the base price) |
|
1373 | - // or NO prices and this ticket is a default ticket, |
|
1374 | - // let's just make sure there are no cached default prices on the object. |
|
1375 | - // This is done by not including any query_params. |
|
1376 | - if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) { |
|
1377 | - $prices = $ticket->get_many_related('Price'); |
|
1378 | - } |
|
1379 | - // check if we're dealing with a default ticket in which case |
|
1380 | - // we don't want any starting_ticket_datetime_row values set |
|
1381 | - // (otherwise there won't be any new relationships created for tickets based off of the default ticket). |
|
1382 | - // This will future proof in case there is ever any behaviour change between what the primary_key defaults to. |
|
1383 | - $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->get('TKT_is_default')); |
|
1384 | - $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) |
|
1385 | - ? $ticket_datetimes[$ticket->ID()] |
|
1386 | - : array(); |
|
1387 | - $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal(); |
|
1388 | - $base_price = $default ? null : $ticket->base_price(); |
|
1389 | - $count_price_mods = EEM_Price::instance()->get_all_default_prices(true); |
|
1390 | - //breaking out complicated condition for ticket_status |
|
1391 | - if ($default) { |
|
1392 | - $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale; |
|
1393 | - } else { |
|
1394 | - $ticket_status_class = $ticket->is_default() |
|
1395 | - ? ' tkt-status-' . EE_Ticket::onsale |
|
1396 | - : ' tkt-status-' . $ticket->ticket_status(); |
|
1397 | - } |
|
1398 | - //breaking out complicated condition for TKT_taxable |
|
1399 | - if ($default) { |
|
1400 | - $TKT_taxable = ''; |
|
1401 | - } else { |
|
1402 | - $TKT_taxable = $ticket->get('TKT_taxable') |
|
1403 | - ? ' checked="checked"' |
|
1404 | - : ''; |
|
1405 | - } |
|
1406 | - if ($default) { |
|
1407 | - $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence'); |
|
1408 | - } else if ($ticket->is_default()) { |
|
1409 | - $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence'); |
|
1410 | - } else { |
|
1411 | - $TKT_status = $ticket->ticket_status(true); |
|
1412 | - } |
|
1413 | - if ($default) { |
|
1414 | - $TKT_min = ''; |
|
1415 | - } else { |
|
1416 | - $TKT_min = $ticket->get('TKT_min'); |
|
1417 | - if ($TKT_min === -1 || $TKT_min === 0) { |
|
1418 | - $TKT_min = ''; |
|
1419 | - } |
|
1420 | - } |
|
1421 | - $template_args = array( |
|
1422 | - 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
1423 | - 'TKT_order' => $default ? 'TICKETNUM' : $ticket_row, |
|
1424 | - //on initial page load this will always be the correct order. |
|
1425 | - 'tkt_status_class' => $ticket_status_class, |
|
1426 | - 'display_edit_tkt_row' => ' style="display:none;"', |
|
1427 | - 'edit_tkt_expanded' => '', |
|
1428 | - 'edit_tickets_name' => $default ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
1429 | - 'TKT_name' => $default ? '' : $ticket->get('TKT_name'), |
|
1430 | - 'TKT_start_date' => $default |
|
1431 | - ? '' |
|
1432 | - : $ticket->get_date('TKT_start_date', |
|
1433 | - $this->_date_time_format), |
|
1434 | - 'TKT_end_date' => $default |
|
1435 | - ? '' |
|
1436 | - : $ticket->get_date('TKT_end_date', |
|
1437 | - $this->_date_time_format), |
|
1438 | - 'TKT_status' => $TKT_status, |
|
1439 | - 'TKT_price' => $default |
|
1440 | - ? '' |
|
1441 | - : EEH_Template::format_currency( |
|
1442 | - $ticket->get_ticket_total_with_taxes(), |
|
1443 | - false, |
|
1444 | - false |
|
1445 | - ), |
|
1446 | - 'TKT_price_code' => EE_Registry::instance()->CFG->currency->code, |
|
1447 | - 'TKT_price_amount' => $default ? 0 : $ticket_subtotal, |
|
1448 | - 'TKT_qty' => $default |
|
1449 | - ? '' |
|
1450 | - : $ticket->get_pretty('TKT_qty', 'symbol'), |
|
1451 | - 'TKT_qty_for_input' => $default |
|
1452 | - ? '' |
|
1453 | - : $ticket->get_pretty('TKT_qty', 'input'), |
|
1454 | - 'TKT_uses' => $default |
|
1455 | - ? '' |
|
1456 | - : $ticket->get_pretty('TKT_uses', 'input'), |
|
1457 | - 'TKT_min' => $TKT_min, |
|
1458 | - 'TKT_max' => $default |
|
1459 | - ? '' |
|
1460 | - : $ticket->get_pretty('TKT_max', 'input'), |
|
1461 | - 'TKT_sold' => $default ? 0 : $ticket->tickets_sold('ticket'), |
|
1462 | - 'TKT_reserved' => $default ? 0 : $ticket->reserved(), |
|
1463 | - 'TKT_registrations' => $default |
|
1464 | - ? 0 |
|
1465 | - : $ticket->count_registrations( |
|
1466 | - array( |
|
1467 | - array( |
|
1468 | - 'STS_ID' => array( |
|
1469 | - '!=', |
|
1470 | - EEM_Registration::status_id_incomplete, |
|
1471 | - ), |
|
1472 | - ), |
|
1473 | - ) |
|
1474 | - ), |
|
1475 | - 'TKT_ID' => $default ? 0 : $ticket->get('TKT_ID'), |
|
1476 | - 'TKT_description' => $default ? '' : $ticket->get('TKT_description'), |
|
1477 | - 'TKT_is_default' => $default ? 0 : $ticket->get('TKT_is_default'), |
|
1478 | - 'TKT_required' => $default ? 0 : $ticket->required(), |
|
1479 | - 'TKT_is_default_selector' => '', |
|
1480 | - 'ticket_price_rows' => '', |
|
1481 | - 'TKT_base_price' => $default || ! $base_price instanceof EE_Price |
|
1482 | - ? '' |
|
1483 | - : $base_price->get_pretty('PRC_amount', 'localized_float'), |
|
1484 | - 'TKT_base_price_ID' => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(), |
|
1485 | - 'show_price_modifier' => count($prices) > 1 || ($default && $count_price_mods > 0) |
|
1486 | - ? '' |
|
1487 | - : ' style="display:none;"', |
|
1488 | - 'show_price_mod_button' => count($prices) > 1 |
|
1489 | - || ($default && $count_price_mods > 0) |
|
1490 | - || (! $default && $ticket->get('TKT_deleted')) |
|
1491 | - ? ' style="display:none;"' |
|
1492 | - : '', |
|
1493 | - 'total_price_rows' => count($prices) > 1 ? count($prices) : 1, |
|
1494 | - 'ticket_datetimes_list' => $default ? '<li class="hidden"></li>' : '', |
|
1495 | - 'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_datetimes), |
|
1496 | - 'ticket_datetime_rows' => $default ? '' : implode(',', $tkt_datetimes), |
|
1497 | - 'existing_ticket_price_ids' => $default ? '' : implode(',', array_keys($prices)), |
|
1498 | - 'ticket_template_id' => $default ? 0 : $ticket->get('TTM_ID'), |
|
1499 | - 'TKT_taxable' => $TKT_taxable, |
|
1500 | - 'display_subtotal' => $ticket instanceof EE_Ticket && $ticket->get('TKT_taxable') |
|
1501 | - ? '' |
|
1502 | - : ' style="display:none"', |
|
1503 | - 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
1504 | - 'TKT_subtotal_amount_display' => EEH_Template::format_currency( |
|
1505 | - $ticket_subtotal, |
|
1506 | - false, |
|
1507 | - false |
|
1508 | - ), |
|
1509 | - 'TKT_subtotal_amount' => $ticket_subtotal, |
|
1510 | - 'tax_rows' => $this->_get_tax_rows($ticket_row, $ticket), |
|
1511 | - 'disabled' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') |
|
1512 | - ? true |
|
1513 | - : false, |
|
1514 | - 'ticket_archive_class' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') |
|
1515 | - ? ' ticket-archived' |
|
1516 | - : '', |
|
1517 | - 'trash_icon' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') |
|
1518 | - ? 'ee-lock-icon ' |
|
1519 | - : 'trash-icon dashicons dashicons-post-trash clickable', |
|
1520 | - 'clone_icon' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') |
|
1521 | - ? '' |
|
1522 | - : 'clone-icon ee-icon ee-icon-clone clickable', |
|
1523 | - ); |
|
1524 | - $template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' |
|
1525 | - ? ' style="display:none"' |
|
1526 | - : ''; |
|
1527 | - //handle rows that should NOT be empty |
|
1528 | - if (empty($template_args['TKT_start_date'])) { |
|
1529 | - //if empty then the start date will be now. |
|
1530 | - $template_args['TKT_start_date'] = date($this->_date_time_format, |
|
1531 | - current_time('timestamp')); |
|
1532 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
1533 | - } |
|
1534 | - if (empty($template_args['TKT_end_date'])) { |
|
1535 | - //get the earliest datetime (if present); |
|
1536 | - $earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 |
|
1537 | - ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related( |
|
1538 | - 'Datetime', |
|
1539 | - array('order_by' => array('DTT_EVT_start' => 'ASC')) |
|
1540 | - ) |
|
1541 | - : null; |
|
1542 | - if (! empty($earliest_dtt)) { |
|
1543 | - $template_args['TKT_end_date'] = $earliest_dtt->get_datetime( |
|
1544 | - 'DTT_EVT_start', |
|
1545 | - $this->_date_time_format |
|
1546 | - ); |
|
1547 | - } else { |
|
1548 | - //default so let's just use what's been set for the default date-time which is 30 days from now. |
|
1549 | - $template_args['TKT_end_date'] = date( |
|
1550 | - $this->_date_time_format, |
|
1551 | - mktime(24, 0, 0, date('m'), date('d') + 29, date('Y') |
|
1552 | - ) |
|
1553 | - ); |
|
1554 | - } |
|
1555 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
1556 | - } |
|
1557 | - //generate ticket_datetime items |
|
1558 | - if (! $default) { |
|
1559 | - $datetime_row = 1; |
|
1560 | - foreach ($all_datetimes as $datetime) { |
|
1561 | - $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
|
1562 | - $datetime_row, |
|
1563 | - $ticket_row, |
|
1564 | - $datetime, |
|
1565 | - $ticket, |
|
1566 | - $ticket_datetimes, |
|
1567 | - $default |
|
1568 | - ); |
|
1569 | - $datetime_row++; |
|
1570 | - } |
|
1571 | - } |
|
1572 | - $price_row = 1; |
|
1573 | - foreach ($prices as $price) { |
|
1574 | - if ($price->is_base_price()) { |
|
1575 | - $price_row++; |
|
1576 | - continue; |
|
1577 | - } |
|
1578 | - $show_trash = (count($prices) > 1 && $price_row === 1) || count($prices) === 1 ? false : true; |
|
1579 | - $show_create = count($prices) > 1 && count($prices) !== $price_row ? false : true; |
|
1580 | - $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row( |
|
1581 | - $ticket_row, |
|
1582 | - $price_row, |
|
1583 | - $price, |
|
1584 | - $default, |
|
1585 | - $ticket, |
|
1586 | - $show_trash, |
|
1587 | - $show_create |
|
1588 | - ); |
|
1589 | - $price_row++; |
|
1590 | - } |
|
1591 | - //filter $template_args |
|
1592 | - $template_args = apply_filters( |
|
1593 | - 'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args', |
|
1594 | - $template_args, |
|
1595 | - $ticket_row, |
|
1596 | - $ticket, |
|
1597 | - $ticket_datetimes, |
|
1598 | - $all_datetimes, |
|
1599 | - $default, |
|
1600 | - $all_tickets, |
|
1601 | - $this->_is_creating_event |
|
1602 | - ); |
|
1603 | - return EEH_Template::display_template( |
|
1604 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php', |
|
1605 | - $template_args, |
|
1606 | - true |
|
1607 | - ); |
|
1608 | - } |
|
1609 | - |
|
1610 | - |
|
1611 | - |
|
1612 | - /** |
|
1613 | - * @param int $ticket_row |
|
1614 | - * @param EE_Ticket|null $ticket |
|
1615 | - * @return string |
|
1616 | - * @throws DomainException |
|
1617 | - * @throws EE_Error |
|
1618 | - */ |
|
1619 | - protected function _get_tax_rows($ticket_row, $ticket) |
|
1620 | - { |
|
1621 | - $tax_rows = ''; |
|
1622 | - $taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin(); |
|
1623 | - foreach ($taxes as $tax) { |
|
1624 | - $tax_added = $this->_get_tax_added($tax, $ticket); |
|
1625 | - $template_args = array( |
|
1626 | - 'display_tax' => ! empty($ticket) && $ticket->get('TKT_taxable') |
|
1627 | - ? '' |
|
1628 | - : ' style="display:none;"', |
|
1629 | - 'tax_id' => $tax->ID(), |
|
1630 | - 'tkt_row' => $ticket_row, |
|
1631 | - 'tax_label' => $tax->get('PRC_name'), |
|
1632 | - 'tax_added' => $tax_added, |
|
1633 | - 'tax_added_display' => EEH_Template::format_currency($tax_added, false, false), |
|
1634 | - 'tax_amount' => $tax->get('PRC_amount'), |
|
1635 | - ); |
|
1636 | - $template_args = apply_filters( |
|
1637 | - 'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args', |
|
1638 | - $template_args, |
|
1639 | - $ticket_row, |
|
1640 | - $ticket, |
|
1641 | - $this->_is_creating_event |
|
1642 | - ); |
|
1643 | - $tax_rows .= EEH_Template::display_template( |
|
1644 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php', |
|
1645 | - $template_args, |
|
1646 | - true |
|
1647 | - ); |
|
1648 | - } |
|
1649 | - return $tax_rows; |
|
1650 | - } |
|
1651 | - |
|
1652 | - |
|
1653 | - |
|
1654 | - /** |
|
1655 | - * @param EE_Price $tax |
|
1656 | - * @param EE_Ticket|null $ticket |
|
1657 | - * @return float|int |
|
1658 | - * @throws EE_Error |
|
1659 | - */ |
|
1660 | - protected function _get_tax_added(EE_Price $tax, $ticket) |
|
1661 | - { |
|
1662 | - $subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal(); |
|
1663 | - return $subtotal * $tax->get('PRC_amount') / 100; |
|
1664 | - } |
|
1665 | - |
|
1666 | - |
|
1667 | - |
|
1668 | - /** |
|
1669 | - * @param int $ticket_row |
|
1670 | - * @param int $price_row |
|
1671 | - * @param EE_Price|null $price |
|
1672 | - * @param bool $default |
|
1673 | - * @param EE_Ticket|null $ticket |
|
1674 | - * @param bool $show_trash |
|
1675 | - * @param bool $show_create |
|
1676 | - * @return mixed |
|
1677 | - * @throws DomainException |
|
1678 | - * @throws EE_Error |
|
1679 | - */ |
|
1680 | - protected function _get_ticket_price_row( |
|
1681 | - $ticket_row, |
|
1682 | - $price_row, |
|
1683 | - $price, |
|
1684 | - $default, |
|
1685 | - $ticket, |
|
1686 | - $show_trash = true, |
|
1687 | - $show_create = true |
|
1688 | - ) { |
|
1689 | - $send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted') ? true : false; |
|
1690 | - $template_args = array( |
|
1691 | - 'tkt_row' => $default && empty($ticket) |
|
1692 | - ? 'TICKETNUM' |
|
1693 | - : $ticket_row, |
|
1694 | - 'PRC_order' => $default && empty($price) |
|
1695 | - ? 'PRICENUM' |
|
1696 | - : $price_row, |
|
1697 | - 'edit_prices_name' => $default && empty($price) |
|
1698 | - ? 'PRICENAMEATTR' |
|
1699 | - : 'edit_prices', |
|
1700 | - 'price_type_selector' => $default && empty($price) |
|
1701 | - ? $this->_get_base_price_template($ticket_row, $price_row, $price, $default) |
|
1702 | - : $this->_get_price_type_selector($ticket_row, $price_row, $price, $default, $send_disabled), |
|
1703 | - 'PRC_ID' => $default && empty($price) |
|
1704 | - ? 0 |
|
1705 | - : $price->ID(), |
|
1706 | - 'PRC_is_default' => $default && empty($price) |
|
1707 | - ? 0 |
|
1708 | - : $price->get('PRC_is_default'), |
|
1709 | - 'PRC_name' => $default && empty($price) |
|
1710 | - ? '' |
|
1711 | - : $price->get('PRC_name'), |
|
1712 | - 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
1713 | - 'show_plus_or_minus' => $default && empty($price) |
|
1714 | - ? '' |
|
1715 | - : ' style="display:none;"', |
|
1716 | - 'show_plus' => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price()) |
|
1717 | - ? ' style="display:none;"' |
|
1718 | - : '', |
|
1719 | - 'show_minus' => ($default && empty($price)) || ! $price->is_discount() |
|
1720 | - ? ' style="display:none;"' |
|
1721 | - : '', |
|
1722 | - 'show_currency_symbol' => ($default && empty($price)) || $price->is_percent() |
|
1723 | - ? ' style="display:none"' |
|
1724 | - : '', |
|
1725 | - 'PRC_amount' => $default && empty($price) |
|
1726 | - ? 0 |
|
1727 | - : $price->get_pretty('PRC_amount', |
|
1728 | - 'localized_float'), |
|
1729 | - 'show_percentage' => ($default && empty($price)) || ! $price->is_percent() |
|
1730 | - ? ' style="display:none;"' |
|
1731 | - : '', |
|
1732 | - 'show_trash_icon' => $show_trash |
|
1733 | - ? '' |
|
1734 | - : ' style="display:none;"', |
|
1735 | - 'show_create_button' => $show_create |
|
1736 | - ? '' |
|
1737 | - : ' style="display:none;"', |
|
1738 | - 'PRC_desc' => $default && empty($price) |
|
1739 | - ? '' |
|
1740 | - : $price->get('PRC_desc'), |
|
1741 | - 'disabled' => ! empty($ticket) && $ticket->get('TKT_deleted') |
|
1742 | - ? true |
|
1743 | - : false, |
|
1744 | - ); |
|
1745 | - $template_args = apply_filters( |
|
1746 | - 'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args', |
|
1747 | - $template_args, |
|
1748 | - $ticket_row, |
|
1749 | - $price_row, |
|
1750 | - $price, |
|
1751 | - $default, |
|
1752 | - $ticket, |
|
1753 | - $show_trash, |
|
1754 | - $show_create, |
|
1755 | - $this->_is_creating_event |
|
1756 | - ); |
|
1757 | - return EEH_Template::display_template( |
|
1758 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php', |
|
1759 | - $template_args, |
|
1760 | - true |
|
1761 | - ); |
|
1762 | - } |
|
1763 | - |
|
1764 | - |
|
1765 | - |
|
1766 | - /** |
|
1767 | - * @param int $ticket_row |
|
1768 | - * @param int $price_row |
|
1769 | - * @param EE_Price $price |
|
1770 | - * @param bool $default |
|
1771 | - * @param bool $disabled |
|
1772 | - * @return mixed |
|
1773 | - * @throws DomainException |
|
1774 | - * @throws EE_Error |
|
1775 | - */ |
|
1776 | - protected function _get_price_type_selector($ticket_row, $price_row, $price, $default, $disabled = false) |
|
1777 | - { |
|
1778 | - if ($price->is_base_price()) { |
|
1779 | - return $this->_get_base_price_template($ticket_row, $price_row, $price, $default); |
|
1780 | - } |
|
1781 | - return $this->_get_price_modifier_template($ticket_row, $price_row, $price, $default, $disabled); |
|
1782 | - } |
|
1783 | - |
|
1784 | - |
|
1785 | - |
|
1786 | - /** |
|
1787 | - * @param int $ticket_row |
|
1788 | - * @param int $price_row |
|
1789 | - * @param EE_Price $price |
|
1790 | - * @param bool $default |
|
1791 | - * @return mixed |
|
1792 | - * @throws DomainException |
|
1793 | - * @throws EE_Error |
|
1794 | - */ |
|
1795 | - protected function _get_base_price_template($ticket_row, $price_row, $price, $default) |
|
1796 | - { |
|
1797 | - $template_args = array( |
|
1798 | - 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
1799 | - 'PRC_order' => $default && empty($price) ? 'PRICENUM' : $price_row, |
|
1800 | - 'PRT_ID' => $default && empty($price) ? 1 : $price->get('PRT_ID'), |
|
1801 | - 'PRT_name' => esc_html__('Price', 'event_espresso'), |
|
1802 | - 'price_selected_operator' => '+', |
|
1803 | - 'price_selected_is_percent' => 0, |
|
1804 | - ); |
|
1805 | - $template_args = apply_filters( |
|
1806 | - 'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args', |
|
1807 | - $template_args, |
|
1808 | - $ticket_row, |
|
1809 | - $price_row, |
|
1810 | - $price, |
|
1811 | - $default, |
|
1812 | - $this->_is_creating_event |
|
1813 | - ); |
|
1814 | - return EEH_Template::display_template( |
|
1815 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php', |
|
1816 | - $template_args, |
|
1817 | - true |
|
1818 | - ); |
|
1819 | - } |
|
1820 | - |
|
1821 | - |
|
1822 | - |
|
1823 | - /** |
|
1824 | - * @param int $ticket_row |
|
1825 | - * @param int $price_row |
|
1826 | - * @param EE_Price $price |
|
1827 | - * @param bool $default |
|
1828 | - * @param bool $disabled |
|
1829 | - * @return mixed |
|
1830 | - * @throws DomainException |
|
1831 | - * @throws EE_Error |
|
1832 | - */ |
|
1833 | - protected function _get_price_modifier_template( |
|
1834 | - $ticket_row, |
|
1835 | - $price_row, |
|
1836 | - $price, |
|
1837 | - $default, |
|
1838 | - $disabled = false |
|
1839 | - ) { |
|
1840 | - $select_name = $default && ! $price instanceof EE_Price |
|
1841 | - ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]' |
|
1842 | - : 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]'; |
|
1843 | - /** @var EEM_Price_Type $price_type_model */ |
|
1844 | - $price_type_model = EE_Registry::instance()->load_model('Price_Type'); |
|
1845 | - $price_types = $price_type_model->get_all(array( |
|
1846 | - array( |
|
1847 | - 'OR' => array( |
|
1848 | - 'PBT_ID' => '2', |
|
1849 | - 'PBT_ID*' => '3', |
|
1850 | - ), |
|
1851 | - ), |
|
1852 | - )); |
|
1853 | - $all_price_types = $default && ! $price instanceof EE_Price ? array( |
|
1854 | - array( |
|
1855 | - 'id' => 0, |
|
1856 | - 'text' => esc_html__('Select Modifier', 'event_espresso'), |
|
1857 | - ), |
|
1858 | - ) : array(); |
|
1859 | - $selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type(); |
|
1860 | - $price_option_spans = ''; |
|
1861 | - //setup price types for selector |
|
1862 | - foreach ($price_types as $price_type) { |
|
1863 | - if (! $price_type instanceof EE_Price_Type) { |
|
1864 | - continue; |
|
1865 | - } |
|
1866 | - $all_price_types[] = array( |
|
1867 | - 'id' => $price_type->ID(), |
|
1868 | - 'text' => $price_type->get('PRT_name'), |
|
1869 | - ); |
|
1870 | - //while we're in the loop let's setup the option spans used by js |
|
1871 | - $span_args = array( |
|
1872 | - 'PRT_ID' => $price_type->ID(), |
|
1873 | - 'PRT_operator' => $price_type->is_discount() ? '-' : '+', |
|
1874 | - 'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0, |
|
1875 | - ); |
|
1876 | - $price_option_spans .= EEH_Template::display_template( |
|
1877 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php', |
|
1878 | - $span_args, |
|
1879 | - true |
|
1880 | - ); |
|
1881 | - } |
|
1882 | - $select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]' : $select_name; |
|
1883 | - $select_input = new EE_Select_Input( |
|
1884 | - $all_price_types, |
|
1885 | - array( |
|
1886 | - 'default' => $selected_price_type_id, |
|
1887 | - 'html_name' => $select_name, |
|
1888 | - 'html_class' => 'edit-price-PRT_ID', |
|
1889 | - 'html_other_attributes' => $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"', |
|
1890 | - ) |
|
1891 | - ); |
|
1892 | - $price_selected_operator = $price instanceof EE_Price && $price->is_discount() ? '-' : '+'; |
|
1893 | - $price_selected_operator = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator; |
|
1894 | - $price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0; |
|
1895 | - $price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent; |
|
1896 | - $template_args = array( |
|
1897 | - 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
1898 | - 'PRC_order' => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row, |
|
1899 | - 'price_modifier_selector' => $select_input->get_html_for_input(), |
|
1900 | - 'main_name' => $select_name, |
|
1901 | - 'selected_price_type_id' => $selected_price_type_id, |
|
1902 | - 'price_option_spans' => $price_option_spans, |
|
1903 | - 'price_selected_operator' => $price_selected_operator, |
|
1904 | - 'price_selected_is_percent' => $price_selected_is_percent, |
|
1905 | - 'disabled' => $disabled, |
|
1906 | - ); |
|
1907 | - $template_args = apply_filters( |
|
1908 | - 'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args', |
|
1909 | - $template_args, |
|
1910 | - $ticket_row, |
|
1911 | - $price_row, |
|
1912 | - $price, |
|
1913 | - $default, |
|
1914 | - $disabled, |
|
1915 | - $this->_is_creating_event |
|
1916 | - ); |
|
1917 | - return EEH_Template::display_template( |
|
1918 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php', |
|
1919 | - $template_args, |
|
1920 | - true |
|
1921 | - ); |
|
1922 | - } |
|
1923 | - |
|
1924 | - |
|
1925 | - |
|
1926 | - /** |
|
1927 | - * @param int $datetime_row |
|
1928 | - * @param int $ticket_row |
|
1929 | - * @param EE_Datetime|null $datetime |
|
1930 | - * @param EE_Ticket|null $ticket |
|
1931 | - * @param array $ticket_datetimes |
|
1932 | - * @param bool $default |
|
1933 | - * @return mixed |
|
1934 | - * @throws DomainException |
|
1935 | - * @throws EE_Error |
|
1936 | - */ |
|
1937 | - protected function _get_ticket_datetime_list_item( |
|
1938 | - $datetime_row, |
|
1939 | - $ticket_row, |
|
1940 | - $datetime, |
|
1941 | - $ticket, |
|
1942 | - $ticket_datetimes = array(), |
|
1943 | - $default |
|
1944 | - ) { |
|
1945 | - $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) |
|
1946 | - ? $ticket_datetimes[$ticket->ID()] |
|
1947 | - : array(); |
|
1948 | - $template_args = array( |
|
1949 | - 'dtt_row' => $default && ! $datetime instanceof EE_Datetime |
|
1950 | - ? 'DTTNUM' |
|
1951 | - : $datetime_row, |
|
1952 | - 'tkt_row' => $default |
|
1953 | - ? 'TICKETNUM' |
|
1954 | - : $ticket_row, |
|
1955 | - 'ticket_datetime_selected' => in_array($datetime_row, $tkt_datetimes, true) |
|
1956 | - ? ' ticket-selected' |
|
1957 | - : '', |
|
1958 | - 'ticket_datetime_checked' => in_array($datetime_row, $tkt_datetimes, true) |
|
1959 | - ? ' checked="checked"' |
|
1960 | - : '', |
|
1961 | - 'DTT_name' => $default && empty($datetime) |
|
1962 | - ? 'DTTNAME' |
|
1963 | - : $datetime->get_dtt_display_name(true), |
|
1964 | - 'tkt_status_class' => '', |
|
1965 | - ); |
|
1966 | - $template_args = apply_filters( |
|
1967 | - 'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args', |
|
1968 | - $template_args, |
|
1969 | - $datetime_row, |
|
1970 | - $ticket_row, |
|
1971 | - $datetime, |
|
1972 | - $ticket, |
|
1973 | - $ticket_datetimes, |
|
1974 | - $default, |
|
1975 | - $this->_is_creating_event |
|
1976 | - ); |
|
1977 | - return EEH_Template::display_template( |
|
1978 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php', |
|
1979 | - $template_args, |
|
1980 | - true |
|
1981 | - ); |
|
1982 | - } |
|
1983 | - |
|
1984 | - |
|
1985 | - |
|
1986 | - /** |
|
1987 | - * @param array $all_datetimes |
|
1988 | - * @param array $all_tickets |
|
1989 | - * @return mixed |
|
1990 | - * @throws DomainException |
|
1991 | - * @throws EE_Error |
|
1992 | - */ |
|
1993 | - protected function _get_ticket_js_structure($all_datetimes = array(), $all_tickets = array()) |
|
1994 | - { |
|
1995 | - $template_args = array( |
|
1996 | - 'default_datetime_edit_row' => $this->_get_dtt_edit_row( |
|
1997 | - 'DTTNUM', |
|
1998 | - null, |
|
1999 | - true, |
|
2000 | - $all_datetimes |
|
2001 | - ), |
|
2002 | - 'default_ticket_row' => $this->_get_ticket_row( |
|
2003 | - 'TICKETNUM', |
|
2004 | - null, |
|
2005 | - array(), |
|
2006 | - array(), |
|
2007 | - true |
|
2008 | - ), |
|
2009 | - 'default_price_row' => $this->_get_ticket_price_row( |
|
2010 | - 'TICKETNUM', |
|
2011 | - 'PRICENUM', |
|
2012 | - null, |
|
2013 | - true, |
|
2014 | - null |
|
2015 | - ), |
|
2016 | - 'default_price_rows' => '', |
|
2017 | - 'default_base_price_amount' => 0, |
|
2018 | - 'default_base_price_name' => '', |
|
2019 | - 'default_base_price_description' => '', |
|
2020 | - 'default_price_modifier_selector_row' => $this->_get_price_modifier_template( |
|
2021 | - 'TICKETNUM', |
|
2022 | - 'PRICENUM', |
|
2023 | - null, |
|
2024 | - true |
|
2025 | - ), |
|
2026 | - 'default_available_tickets_for_datetime' => $this->_get_dtt_attached_tickets_row( |
|
2027 | - 'DTTNUM', |
|
2028 | - null, |
|
2029 | - array(), |
|
2030 | - array(), |
|
2031 | - true |
|
2032 | - ), |
|
2033 | - 'existing_available_datetime_tickets_list' => '', |
|
2034 | - 'existing_available_ticket_datetimes_list' => '', |
|
2035 | - 'new_available_datetime_ticket_list_item' => $this->_get_datetime_tickets_list_item( |
|
2036 | - 'DTTNUM', |
|
2037 | - 'TICKETNUM', |
|
2038 | - null, |
|
2039 | - null, |
|
2040 | - array(), |
|
2041 | - true |
|
2042 | - ), |
|
2043 | - 'new_available_ticket_datetime_list_item' => $this->_get_ticket_datetime_list_item( |
|
2044 | - 'DTTNUM', |
|
2045 | - 'TICKETNUM', |
|
2046 | - null, |
|
2047 | - null, |
|
2048 | - array(), |
|
2049 | - true |
|
2050 | - ), |
|
2051 | - ); |
|
2052 | - $ticket_row = 1; |
|
2053 | - foreach ($all_tickets as $ticket) { |
|
2054 | - $template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
|
2055 | - 'DTTNUM', |
|
2056 | - $ticket_row, |
|
2057 | - null, |
|
2058 | - $ticket, |
|
2059 | - array(), |
|
2060 | - true |
|
2061 | - ); |
|
2062 | - $ticket_row++; |
|
2063 | - } |
|
2064 | - $datetime_row = 1; |
|
2065 | - foreach ($all_datetimes as $datetime) { |
|
2066 | - $template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
|
2067 | - $datetime_row, |
|
2068 | - 'TICKETNUM', |
|
2069 | - $datetime, |
|
2070 | - null, |
|
2071 | - array(), |
|
2072 | - true |
|
2073 | - ); |
|
2074 | - $datetime_row++; |
|
2075 | - } |
|
2076 | - /** @var EEM_Price $price_model */ |
|
2077 | - $price_model = EE_Registry::instance()->load_model('Price'); |
|
2078 | - $default_prices = $price_model->get_all_default_prices(); |
|
2079 | - $price_row = 1; |
|
2080 | - foreach ($default_prices as $price) { |
|
2081 | - if (! $price instanceof EE_Price) { |
|
2082 | - continue; |
|
2083 | - } |
|
2084 | - if ($price->is_base_price()) { |
|
2085 | - $template_args['default_base_price_amount'] = $price->get_pretty( |
|
2086 | - 'PRC_amount', |
|
2087 | - 'localized_float' |
|
2088 | - ); |
|
2089 | - $template_args['default_base_price_name'] = $price->get('PRC_name'); |
|
2090 | - $template_args['default_base_price_description'] = $price->get('PRC_desc'); |
|
2091 | - $price_row++; |
|
2092 | - continue; |
|
2093 | - } |
|
2094 | - $show_trash = (count($default_prices) > 1 && $price_row === 1) || count($default_prices) === 1 |
|
2095 | - ? false |
|
2096 | - : true; |
|
2097 | - $show_create = count($default_prices) > 1 && count($default_prices) !== $price_row |
|
2098 | - ? false |
|
2099 | - : true; |
|
2100 | - $template_args['default_price_rows'] .= $this->_get_ticket_price_row( |
|
2101 | - 'TICKETNUM', |
|
2102 | - $price_row, |
|
2103 | - $price, |
|
2104 | - true, |
|
2105 | - null, |
|
2106 | - $show_trash, |
|
2107 | - $show_create |
|
2108 | - ); |
|
2109 | - $price_row++; |
|
2110 | - } |
|
2111 | - $template_args = apply_filters( |
|
2112 | - 'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args', |
|
2113 | - $template_args, |
|
2114 | - $all_datetimes, |
|
2115 | - $all_tickets, |
|
2116 | - $this->_is_creating_event |
|
2117 | - ); |
|
2118 | - return EEH_Template::display_template( |
|
2119 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php', |
|
2120 | - $template_args, |
|
2121 | - true |
|
2122 | - ); |
|
2123 | - } |
|
18 | + /** |
|
19 | + * This property is just used to hold the status of whether an event is currently being |
|
20 | + * created (true) or edited (false) |
|
21 | + * |
|
22 | + * @access protected |
|
23 | + * @var bool |
|
24 | + */ |
|
25 | + protected $_is_creating_event; |
|
26 | + |
|
27 | + |
|
28 | + /** |
|
29 | + * Used to contain the format strings for date and time that will be used for php date and |
|
30 | + * time. |
|
31 | + * Is set in the _set_hooks_properties() method. |
|
32 | + * |
|
33 | + * @var array |
|
34 | + */ |
|
35 | + protected $_date_format_strings; |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * @var string $_date_time_format |
|
40 | + */ |
|
41 | + protected $_date_time_format; |
|
42 | + |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * |
|
47 | + */ |
|
48 | + protected function _set_hooks_properties() |
|
49 | + { |
|
50 | + $this->_name = 'pricing'; |
|
51 | + //capability check |
|
52 | + if ( |
|
53 | + ! EE_Registry::instance()->CAP->current_user_can( |
|
54 | + 'ee_read_default_prices', |
|
55 | + 'advanced_ticket_datetime_metabox' |
|
56 | + ) |
|
57 | + ) { |
|
58 | + return; |
|
59 | + } |
|
60 | + $this->_setup_metaboxes(); |
|
61 | + $this->_set_date_time_formats(); |
|
62 | + $this->_validate_format_strings(); |
|
63 | + $this->_set_scripts_styles(); |
|
64 | + // commented out temporarily until logic is implemented in callback |
|
65 | + // add_action( |
|
66 | + // 'AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page', |
|
67 | + // array($this, 'autosave_handling') |
|
68 | + // ); |
|
69 | + add_filter( |
|
70 | + 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
71 | + array($this, 'caf_updates') |
|
72 | + ); |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * @return void |
|
79 | + */ |
|
80 | + protected function _setup_metaboxes() |
|
81 | + { |
|
82 | + //if we were going to add our own metaboxes we'd use the below. |
|
83 | + $this->_metaboxes = array( |
|
84 | + 0 => array( |
|
85 | + 'page_route' => array('edit', 'create_new'), |
|
86 | + 'func' => 'pricing_metabox', |
|
87 | + 'label' => esc_html__('Event Tickets & Datetimes', 'event_espresso'), |
|
88 | + 'priority' => 'high', |
|
89 | + 'context' => 'normal', |
|
90 | + ), |
|
91 | + ); |
|
92 | + $this->_remove_metaboxes = array( |
|
93 | + 0 => array( |
|
94 | + 'page_route' => array('edit', 'create_new'), |
|
95 | + 'id' => 'espresso_event_editor_tickets', |
|
96 | + 'context' => 'normal', |
|
97 | + ), |
|
98 | + ); |
|
99 | + } |
|
100 | + |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * @return void |
|
105 | + */ |
|
106 | + protected function _set_date_time_formats() |
|
107 | + { |
|
108 | + /** |
|
109 | + * Format strings for date and time. Defaults are existing behaviour from 4.1. |
|
110 | + * Note, that if you return null as the value for 'date', and 'time' in the array, then |
|
111 | + * EE will automatically use the set wp_options, 'date_format', and 'time_format'. |
|
112 | + * |
|
113 | + * @since 4.6.7 |
|
114 | + * @var array Expected an array returned with 'date' and 'time' keys. |
|
115 | + */ |
|
116 | + $this->_date_format_strings = apply_filters( |
|
117 | + 'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings', |
|
118 | + array( |
|
119 | + 'date' => 'Y-m-d', |
|
120 | + 'time' => 'h:i a', |
|
121 | + ) |
|
122 | + ); |
|
123 | + //validate |
|
124 | + $this->_date_format_strings['date'] = isset($this->_date_format_strings['date']) |
|
125 | + ? $this->_date_format_strings['date'] |
|
126 | + : null; |
|
127 | + $this->_date_format_strings['time'] = isset($this->_date_format_strings['time']) |
|
128 | + ? $this->_date_format_strings['time'] |
|
129 | + : null; |
|
130 | + $this->_date_time_format = $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']; |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * @return void |
|
137 | + */ |
|
138 | + protected function _validate_format_strings() |
|
139 | + { |
|
140 | + //validate format strings |
|
141 | + $format_validation = EEH_DTT_Helper::validate_format_string( |
|
142 | + $this->_date_time_format |
|
143 | + ); |
|
144 | + if (is_array($format_validation)) { |
|
145 | + $msg = '<p>'; |
|
146 | + $msg .= sprintf( |
|
147 | + __( |
|
148 | + 'The format "%s" was likely added via a filter and is invalid for the following reasons:', |
|
149 | + 'event_espresso' |
|
150 | + ), |
|
151 | + $this->_date_time_format |
|
152 | + ); |
|
153 | + $msg .= '</p><ul>'; |
|
154 | + foreach ($format_validation as $error) { |
|
155 | + $msg .= '<li>' . $error . '</li>'; |
|
156 | + } |
|
157 | + $msg .= '</ul><p>'; |
|
158 | + $msg .= sprintf( |
|
159 | + __( |
|
160 | + '%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s', |
|
161 | + 'event_espresso' |
|
162 | + ), |
|
163 | + '<span style="color:#D54E21;">', |
|
164 | + '</span>' |
|
165 | + ); |
|
166 | + $msg .= '</p>'; |
|
167 | + EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
168 | + $this->_date_format_strings = array( |
|
169 | + 'date' => 'Y-m-d', |
|
170 | + 'time' => 'h:i a', |
|
171 | + ); |
|
172 | + } |
|
173 | + } |
|
174 | + |
|
175 | + |
|
176 | + |
|
177 | + /** |
|
178 | + * @return void |
|
179 | + */ |
|
180 | + protected function _set_scripts_styles() |
|
181 | + { |
|
182 | + $this->_scripts_styles = array( |
|
183 | + 'registers' => array( |
|
184 | + 'ee-tickets-datetimes-css' => array( |
|
185 | + 'url' => PRICING_ASSETS_URL . 'event-tickets-datetimes.css', |
|
186 | + 'type' => 'css', |
|
187 | + ), |
|
188 | + 'ee-dtt-ticket-metabox' => array( |
|
189 | + 'url' => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js', |
|
190 | + 'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'), |
|
191 | + ), |
|
192 | + ), |
|
193 | + 'deregisters' => array( |
|
194 | + 'event-editor-css' => array('type' => 'css'), |
|
195 | + 'event-datetime-metabox' => array('type' => 'js'), |
|
196 | + ), |
|
197 | + 'enqueues' => array( |
|
198 | + 'ee-tickets-datetimes-css' => array('edit', 'create_new'), |
|
199 | + 'ee-dtt-ticket-metabox' => array('edit', 'create_new'), |
|
200 | + ), |
|
201 | + 'localize' => array( |
|
202 | + 'ee-dtt-ticket-metabox' => array( |
|
203 | + 'DTT_TRASH_BLOCK' => array( |
|
204 | + 'main_warning' => esc_html__( |
|
205 | + 'The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):', |
|
206 | + 'event_espresso' |
|
207 | + ), |
|
208 | + 'after_warning' => esc_html__( |
|
209 | + 'In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.', |
|
210 | + 'event_espresso' |
|
211 | + ), |
|
212 | + 'cancel_button' => '<button class="button-secondary ee-modal-cancel">' |
|
213 | + . esc_html__('Cancel', 'event_espresso') . '</button>', |
|
214 | + 'close_button' => '<button class="button-secondary ee-modal-cancel">' |
|
215 | + . esc_html__('Close', 'event_espresso') . '</button>', |
|
216 | + 'single_warning_from_tkt' => esc_html__( |
|
217 | + 'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.', |
|
218 | + 'event_espresso' |
|
219 | + ), |
|
220 | + 'single_warning_from_dtt' => esc_html__( |
|
221 | + 'The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket. Tickets must always have at least one datetime assigned to them.', |
|
222 | + 'event_espresso' |
|
223 | + ), |
|
224 | + 'dismiss_button' => '<button class="button-secondary ee-modal-cancel">' |
|
225 | + . esc_html__('Dismiss', 'event_espresso') . '</button>', |
|
226 | + ), |
|
227 | + 'DTT_ERROR_MSG' => array( |
|
228 | + 'no_ticket_name' => esc_html__('General Admission', 'event_espresso'), |
|
229 | + 'dismiss_button' => '<div class="save-cancel-button-container"><button class="button-secondary ee-modal-cancel">' |
|
230 | + . esc_html__('Dismiss', 'event_espresso') . '</button></div>', |
|
231 | + ), |
|
232 | + 'DTT_OVERSELL_WARNING' => array( |
|
233 | + 'datetime_ticket' => esc_html__( |
|
234 | + 'You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.', |
|
235 | + 'event_espresso' |
|
236 | + ), |
|
237 | + 'ticket_datetime' => esc_html__( |
|
238 | + 'You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.', |
|
239 | + 'event_espresso' |
|
240 | + ), |
|
241 | + ), |
|
242 | + 'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats( |
|
243 | + $this->_date_format_strings['date'], |
|
244 | + $this->_date_format_strings['time'] |
|
245 | + ), |
|
246 | + 'DTT_START_OF_WEEK' => array('dayValue' => (int)get_option('start_of_week')), |
|
247 | + ), |
|
248 | + ), |
|
249 | + ); |
|
250 | + } |
|
251 | + |
|
252 | + |
|
253 | + |
|
254 | + /** |
|
255 | + * @param array $update_callbacks |
|
256 | + * @return array |
|
257 | + */ |
|
258 | + public function caf_updates(array $update_callbacks) |
|
259 | + { |
|
260 | + foreach ($update_callbacks as $key => $callback) { |
|
261 | + if ($callback[1] === '_default_tickets_update') { |
|
262 | + unset($update_callbacks[$key]); |
|
263 | + } |
|
264 | + } |
|
265 | + $update_callbacks[] = array($this, 'datetime_and_tickets_caf_update'); |
|
266 | + return $update_callbacks; |
|
267 | + } |
|
268 | + |
|
269 | + |
|
270 | + |
|
271 | + /** |
|
272 | + * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
273 | + * |
|
274 | + * @param EE_Event $event The Event object we're attaching data to |
|
275 | + * @param array $data The request data from the form |
|
276 | + * @throws EE_Error |
|
277 | + */ |
|
278 | + public function datetime_and_tickets_caf_update($event, $data) |
|
279 | + { |
|
280 | + //first we need to start with datetimes cause they are the "root" items attached to events. |
|
281 | + $saved_datetimes = $this->_update_datetimes($event, $data); |
|
282 | + //next tackle the tickets (and prices?) |
|
283 | + $this->_update_tickets($event, $saved_datetimes, $data); |
|
284 | + } |
|
285 | + |
|
286 | + |
|
287 | + |
|
288 | + /** |
|
289 | + * update event_datetimes |
|
290 | + * |
|
291 | + * @param EE_Event $event Event being updated |
|
292 | + * @param array $data the request data from the form |
|
293 | + * @return EE_Datetime[] |
|
294 | + * @throws EE_Error |
|
295 | + */ |
|
296 | + protected function _update_datetimes($event, $data) |
|
297 | + { |
|
298 | + $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
299 | + $saved_dtt_ids = array(); |
|
300 | + $saved_dtt_objs = array(); |
|
301 | + foreach ($data['edit_event_datetimes'] as $row => $datetime_data) { |
|
302 | + //trim all values to ensure any excess whitespace is removed. |
|
303 | + $datetime_data = array_map( |
|
304 | + function ($datetime_data) { |
|
305 | + return is_array($datetime_data) ? $datetime_data : trim($datetime_data); |
|
306 | + }, |
|
307 | + $datetime_data |
|
308 | + ); |
|
309 | + $datetime_data['DTT_EVT_end'] = isset($datetime_data['DTT_EVT_end']) |
|
310 | + && ! empty($datetime_data['DTT_EVT_end']) |
|
311 | + ? $datetime_data['DTT_EVT_end'] |
|
312 | + : $datetime_data['DTT_EVT_start']; |
|
313 | + $datetime_values = array( |
|
314 | + 'DTT_ID' => ! empty($datetime_data['DTT_ID']) |
|
315 | + ? $datetime_data['DTT_ID'] |
|
316 | + : null, |
|
317 | + 'DTT_name' => ! empty($datetime_data['DTT_name']) |
|
318 | + ? $datetime_data['DTT_name'] |
|
319 | + : '', |
|
320 | + 'DTT_description' => ! empty($datetime_data['DTT_description']) |
|
321 | + ? $datetime_data['DTT_description'] |
|
322 | + : '', |
|
323 | + 'DTT_EVT_start' => $datetime_data['DTT_EVT_start'], |
|
324 | + 'DTT_EVT_end' => $datetime_data['DTT_EVT_end'], |
|
325 | + 'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) |
|
326 | + ? EE_INF |
|
327 | + : $datetime_data['DTT_reg_limit'], |
|
328 | + 'DTT_order' => ! isset($datetime_data['DTT_order']) |
|
329 | + ? $row |
|
330 | + : $datetime_data['DTT_order'], |
|
331 | + ); |
|
332 | + // if we have an id then let's get existing object first and then set the new values. |
|
333 | + // Otherwise we instantiate a new object for save. |
|
334 | + if (! empty($datetime_data['DTT_ID'])) { |
|
335 | + $datetime = EE_Registry::instance() |
|
336 | + ->load_model('Datetime', array($timezone)) |
|
337 | + ->get_one_by_ID($datetime_data['DTT_ID']); |
|
338 | + //set date and time format according to what is set in this class. |
|
339 | + $datetime->set_date_format($this->_date_format_strings['date']); |
|
340 | + $datetime->set_time_format($this->_date_format_strings['time']); |
|
341 | + foreach ($datetime_values as $field => $value) { |
|
342 | + $datetime->set($field, $value); |
|
343 | + } |
|
344 | + // make sure the $dtt_id here is saved just in case |
|
345 | + // after the add_relation_to() the autosave replaces it. |
|
346 | + // We need to do this so we dont' TRASH the parent DTT. |
|
347 | + // (save the ID for both key and value to avoid duplications) |
|
348 | + $saved_dtt_ids[$datetime->ID()] = $datetime->ID(); |
|
349 | + } else { |
|
350 | + $datetime = EE_Registry::instance()->load_class( |
|
351 | + 'Datetime', |
|
352 | + array( |
|
353 | + $datetime_values, |
|
354 | + $timezone, |
|
355 | + array($this->_date_format_strings['date'], $this->_date_format_strings['time']), |
|
356 | + ), |
|
357 | + false, |
|
358 | + false |
|
359 | + ); |
|
360 | + foreach ($datetime_values as $field => $value) { |
|
361 | + $datetime->set($field, $value); |
|
362 | + } |
|
363 | + } |
|
364 | + $datetime->save(); |
|
365 | + $datetime = $event->_add_relation_to($datetime, 'Datetime'); |
|
366 | + // before going any further make sure our dates are setup correctly |
|
367 | + // so that the end date is always equal or greater than the start date. |
|
368 | + if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) { |
|
369 | + $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start')); |
|
370 | + $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days'); |
|
371 | + $datetime->save(); |
|
372 | + } |
|
373 | + // now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array |
|
374 | + // because it is possible there was a new one created for the autosave. |
|
375 | + // (save the ID for both key and value to avoid duplications) |
|
376 | + $DTT_ID = $datetime->ID(); |
|
377 | + $saved_dtt_ids[$DTT_ID] = $DTT_ID; |
|
378 | + $saved_dtt_objs[$row] = $datetime; |
|
379 | + //todo if ANY of these updates fail then we want the appropriate global error message. |
|
380 | + } |
|
381 | + $event->save(); |
|
382 | + // now we need to REMOVE any datetimes that got deleted. |
|
383 | + // Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them. |
|
384 | + // So its safe to permanently delete at this point. |
|
385 | + $old_datetimes = explode(',', $data['datetime_IDs']); |
|
386 | + $old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes; |
|
387 | + if (is_array($old_datetimes)) { |
|
388 | + $datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids); |
|
389 | + foreach ($datetimes_to_delete as $id) { |
|
390 | + $id = absint($id); |
|
391 | + if (empty($id)) { |
|
392 | + continue; |
|
393 | + } |
|
394 | + $dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id); |
|
395 | + //remove tkt relationships. |
|
396 | + $related_tickets = $dtt_to_remove->get_many_related('Ticket'); |
|
397 | + foreach ($related_tickets as $tkt) { |
|
398 | + $dtt_to_remove->_remove_relation_to($tkt, 'Ticket'); |
|
399 | + } |
|
400 | + $event->_remove_relation_to($id, 'Datetime'); |
|
401 | + $dtt_to_remove->refresh_cache_of_related_objects(); |
|
402 | + } |
|
403 | + } |
|
404 | + return $saved_dtt_objs; |
|
405 | + } |
|
406 | + |
|
407 | + |
|
408 | + |
|
409 | + /** |
|
410 | + * update tickets |
|
411 | + * |
|
412 | + * @param EE_Event $event Event object being updated |
|
413 | + * @param EE_Datetime[] $saved_datetimes an array of datetime ids being updated |
|
414 | + * @param array $data incoming request data |
|
415 | + * @return EE_Ticket[] |
|
416 | + * @throws EE_Error |
|
417 | + */ |
|
418 | + protected function _update_tickets($event, $saved_datetimes, $data) |
|
419 | + { |
|
420 | + $new_tkt = null; |
|
421 | + $new_default = null; |
|
422 | + //stripslashes because WP filtered the $_POST ($data) array to add slashes |
|
423 | + $data = stripslashes_deep($data); |
|
424 | + $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
425 | + $saved_tickets = $datetimes_on_existing = array(); |
|
426 | + $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
427 | + //load money helper |
|
428 | + foreach ($data['edit_tickets'] as $row => $tkt) { |
|
429 | + $update_prices = $create_new_TKT = false; |
|
430 | + // figure out what datetimes were added to the ticket |
|
431 | + // and what datetimes were removed from the ticket in the session. |
|
432 | + $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][$row]); |
|
433 | + $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][$row]); |
|
434 | + $datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows); |
|
435 | + $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows); |
|
436 | + // trim inputs to ensure any excess whitespace is removed. |
|
437 | + $tkt = array_map( |
|
438 | + function ($ticket_data) { |
|
439 | + return is_array($ticket_data) ? $ticket_data : trim($ticket_data); |
|
440 | + }, |
|
441 | + $tkt |
|
442 | + ); |
|
443 | + // note we are doing conversions to floats here instead of allowing EE_Money_Field to handle |
|
444 | + // because we're doing calculations prior to using the models. |
|
445 | + // note incoming ['TKT_price'] value is already in standard notation (via js). |
|
446 | + $ticket_price = isset($tkt['TKT_price']) |
|
447 | + ? round((float)$tkt['TKT_price'], 3) |
|
448 | + : 0; |
|
449 | + //note incoming base price needs converted from localized value. |
|
450 | + $base_price = isset($tkt['TKT_base_price']) |
|
451 | + ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price']) |
|
452 | + : 0; |
|
453 | + //if ticket price == 0 and $base_price != 0 then ticket price == base_price |
|
454 | + $ticket_price = $ticket_price === 0 && $base_price !== 0 |
|
455 | + ? $base_price |
|
456 | + : $ticket_price; |
|
457 | + $base_price_id = isset($tkt['TKT_base_price_ID']) |
|
458 | + ? $tkt['TKT_base_price_ID'] |
|
459 | + : 0; |
|
460 | + $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][$row]) |
|
461 | + ? $data['edit_prices'][$row] |
|
462 | + : array(); |
|
463 | + $now = null; |
|
464 | + if (empty($tkt['TKT_start_date'])) { |
|
465 | + //lets' use now in the set timezone. |
|
466 | + $now = new DateTime('now', new DateTimeZone($event->get_timezone())); |
|
467 | + $tkt['TKT_start_date'] = $now->format($this->_date_time_format); |
|
468 | + } |
|
469 | + if (empty($tkt['TKT_end_date'])) { |
|
470 | + /** |
|
471 | + * set the TKT_end_date to the first datetime attached to the ticket. |
|
472 | + */ |
|
473 | + $first_dtt = $saved_datetimes[reset($tkt_dtt_rows)]; |
|
474 | + $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format); |
|
475 | + } |
|
476 | + $TKT_values = array( |
|
477 | + 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
478 | + 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
479 | + 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
480 | + 'TKT_description' => ! empty($tkt['TKT_description']) |
|
481 | + && $tkt['TKT_description'] !== esc_html__( |
|
482 | + 'You can modify this description', |
|
483 | + 'event_espresso' |
|
484 | + ) |
|
485 | + ? $tkt['TKT_description'] |
|
486 | + : '', |
|
487 | + 'TKT_start_date' => $tkt['TKT_start_date'], |
|
488 | + 'TKT_end_date' => $tkt['TKT_end_date'], |
|
489 | + 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' |
|
490 | + ? EE_INF |
|
491 | + : $tkt['TKT_qty'], |
|
492 | + 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' |
|
493 | + ? EE_INF |
|
494 | + : $tkt['TKT_uses'], |
|
495 | + 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
496 | + 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
497 | + 'TKT_row' => $row, |
|
498 | + 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0, |
|
499 | + 'TKT_taxable' => ! empty($tkt['TKT_taxable']) ? 1 : 0, |
|
500 | + 'TKT_required' => ! empty($tkt['TKT_required']) ? 1 : 0, |
|
501 | + 'TKT_price' => $ticket_price, |
|
502 | + ); |
|
503 | + // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, |
|
504 | + // which means in turn that the prices will become new prices as well. |
|
505 | + if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
506 | + $TKT_values['TKT_ID'] = 0; |
|
507 | + $TKT_values['TKT_is_default'] = 0; |
|
508 | + $update_prices = true; |
|
509 | + } |
|
510 | + // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
511 | + // we actually do our saves ahead of doing any add_relations to |
|
512 | + // because its entirely possible that this ticket wasn't removed or added to any datetime in the session |
|
513 | + // but DID have it's items modified. |
|
514 | + // keep in mind that if the TKT has been sold (and we have changed pricing information), |
|
515 | + // then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
516 | + if (absint($TKT_values['TKT_ID'])) { |
|
517 | + $ticket = EE_Registry::instance() |
|
518 | + ->load_model('Ticket', array($timezone)) |
|
519 | + ->get_one_by_ID($tkt['TKT_ID']); |
|
520 | + if ($ticket instanceof EE_Ticket) { |
|
521 | + $ticket = $this->_update_ticket_datetimes( |
|
522 | + $ticket, |
|
523 | + $saved_datetimes, |
|
524 | + $datetimes_added, |
|
525 | + $datetimes_removed |
|
526 | + ); |
|
527 | + // are there any registrations using this ticket ? |
|
528 | + $tickets_sold = $ticket->count_related( |
|
529 | + 'Registration', |
|
530 | + array( |
|
531 | + array( |
|
532 | + 'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)), |
|
533 | + ), |
|
534 | + ) |
|
535 | + ); |
|
536 | + //set ticket formats |
|
537 | + $ticket->set_date_format($this->_date_format_strings['date']); |
|
538 | + $ticket->set_time_format($this->_date_format_strings['time']); |
|
539 | + // let's just check the total price for the existing ticket |
|
540 | + // and determine if it matches the new total price. |
|
541 | + // if they are different then we create a new ticket (if tkts sold) |
|
542 | + // if they aren't different then we go ahead and modify existing ticket. |
|
543 | + $create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted() |
|
544 | + ? true : false; |
|
545 | + //set new values |
|
546 | + foreach ($TKT_values as $field => $value) { |
|
547 | + if ($field === 'TKT_qty') { |
|
548 | + $ticket->set_qty($value); |
|
549 | + } else { |
|
550 | + $ticket->set($field, $value); |
|
551 | + } |
|
552 | + } |
|
553 | + // if $create_new_TKT is false then we can safely update the existing ticket. |
|
554 | + // Otherwise we have to create a new ticket. |
|
555 | + if ($create_new_TKT) { |
|
556 | + $new_tkt = $this->_duplicate_ticket($ticket, $price_rows, $ticket_price, $base_price, |
|
557 | + $base_price_id); |
|
558 | + } |
|
559 | + } |
|
560 | + } else { |
|
561 | + // no TKT_id so a new TKT |
|
562 | + $ticket = EE_Ticket::new_instance( |
|
563 | + $TKT_values, |
|
564 | + $timezone, |
|
565 | + array($this->_date_format_strings['date'], $this->_date_format_strings['time']) |
|
566 | + ); |
|
567 | + if ($ticket instanceof EE_Ticket) { |
|
568 | + // make sure ticket has an ID of setting relations won't work |
|
569 | + $ticket->save(); |
|
570 | + $ticket = $this->_update_ticket_datetimes( |
|
571 | + $ticket, |
|
572 | + $saved_datetimes, |
|
573 | + $datetimes_added, |
|
574 | + $datetimes_removed |
|
575 | + ); |
|
576 | + $update_prices = true; |
|
577 | + } |
|
578 | + } |
|
579 | + //make sure any current values have been saved. |
|
580 | + //$ticket->save(); |
|
581 | + // before going any further make sure our dates are setup correctly |
|
582 | + // so that the end date is always equal or greater than the start date. |
|
583 | + if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) { |
|
584 | + $ticket->set('TKT_end_date', $ticket->get('TKT_start_date')); |
|
585 | + $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days'); |
|
586 | + } |
|
587 | + //let's make sure the base price is handled |
|
588 | + $ticket = ! $create_new_TKT ? $this->_add_prices_to_ticket(array(), $ticket, $update_prices, $base_price, |
|
589 | + $base_price_id) : $ticket; |
|
590 | + //add/update price_modifiers |
|
591 | + $ticket = ! $create_new_TKT ? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices) : $ticket; |
|
592 | + //need to make sue that the TKT_price is accurate after saving the prices. |
|
593 | + $ticket->ensure_TKT_Price_correct(); |
|
594 | + //handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave. |
|
595 | + if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) { |
|
596 | + $update_prices = true; |
|
597 | + $new_default = clone $ticket; |
|
598 | + $new_default->set('TKT_ID', 0); |
|
599 | + $new_default->set('TKT_is_default', 1); |
|
600 | + $new_default->set('TKT_row', 1); |
|
601 | + $new_default->set('TKT_price', $ticket_price); |
|
602 | + // remove any dtt relations cause we DON'T want dtt relations attached |
|
603 | + // (note this is just removing the cached relations in the object) |
|
604 | + $new_default->_remove_relations('Datetime'); |
|
605 | + //todo we need to add the current attached prices as new prices to the new default ticket. |
|
606 | + $new_default = $this->_add_prices_to_ticket($price_rows, $new_default, $update_prices); |
|
607 | + //don't forget the base price! |
|
608 | + $new_default = $this->_add_prices_to_ticket( |
|
609 | + array(), |
|
610 | + $new_default, |
|
611 | + $update_prices, |
|
612 | + $base_price, |
|
613 | + $base_price_id |
|
614 | + ); |
|
615 | + $new_default->save(); |
|
616 | + do_action( |
|
617 | + 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket', |
|
618 | + $new_default, |
|
619 | + $row, |
|
620 | + $ticket, |
|
621 | + $data |
|
622 | + ); |
|
623 | + } |
|
624 | + // DO ALL dtt relationships for both current tickets and any archived tickets |
|
625 | + // for the given dtt that are related to the current ticket. |
|
626 | + // TODO... not sure exactly how we're going to do this considering we don't know |
|
627 | + // what current ticket the archived tickets are related to |
|
628 | + // (and TKT_parent is used for autosaves so that's not a field we can reliably use). |
|
629 | + //let's assign any tickets that have been setup to the saved_tickets tracker |
|
630 | + //save existing TKT |
|
631 | + $ticket->save(); |
|
632 | + if ($create_new_TKT && $new_tkt instanceof EE_Ticket) { |
|
633 | + //save new TKT |
|
634 | + $new_tkt->save(); |
|
635 | + //add new ticket to array |
|
636 | + $saved_tickets[$new_tkt->ID()] = $new_tkt; |
|
637 | + do_action( |
|
638 | + 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket', |
|
639 | + $new_tkt, |
|
640 | + $row, |
|
641 | + $tkt, |
|
642 | + $data |
|
643 | + ); |
|
644 | + } else { |
|
645 | + //add tkt to saved tkts |
|
646 | + $saved_tickets[$ticket->ID()] = $ticket; |
|
647 | + do_action( |
|
648 | + 'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket', |
|
649 | + $ticket, |
|
650 | + $row, |
|
651 | + $tkt, |
|
652 | + $data |
|
653 | + ); |
|
654 | + } |
|
655 | + } |
|
656 | + // now we need to handle tickets actually "deleted permanently". |
|
657 | + // There are cases where we'd want this to happen |
|
658 | + // (i.e. autosaves are happening and then in between autosaves the user trashes a ticket). |
|
659 | + // Or a draft event was saved and in the process of editing a ticket is trashed. |
|
660 | + // No sense in keeping all the related data in the db! |
|
661 | + $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets; |
|
662 | + $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
663 | + foreach ($tickets_removed as $id) { |
|
664 | + $id = absint($id); |
|
665 | + //get the ticket for this id |
|
666 | + $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
667 | + //if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime |
|
668 | + if ($tkt_to_remove->get('TKT_is_default')) { |
|
669 | + continue; |
|
670 | + } |
|
671 | + // if this tkt has any registrations attached so then we just ARCHIVE |
|
672 | + // because we don't actually permanently delete these tickets. |
|
673 | + if ($tkt_to_remove->count_related('Registration') > 0) { |
|
674 | + $tkt_to_remove->delete(); |
|
675 | + continue; |
|
676 | + } |
|
677 | + // need to get all the related datetimes on this ticket and remove from every single one of them |
|
678 | + // (remember this process can ONLY kick off if there are NO tkts_sold) |
|
679 | + $datetimes = $tkt_to_remove->get_many_related('Datetime'); |
|
680 | + foreach ($datetimes as $datetime) { |
|
681 | + $tkt_to_remove->_remove_relation_to($datetime, 'Datetime'); |
|
682 | + } |
|
683 | + // need to do the same for prices (except these prices can also be deleted because again, |
|
684 | + // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
685 | + $tkt_to_remove->delete_related_permanently('Price'); |
|
686 | + do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove); |
|
687 | + // finally let's delete this ticket |
|
688 | + // (which should not be blocked at this point b/c we've removed all our relationships) |
|
689 | + $tkt_to_remove->delete_permanently(); |
|
690 | + } |
|
691 | + return $saved_tickets; |
|
692 | + } |
|
693 | + |
|
694 | + |
|
695 | + |
|
696 | + /** |
|
697 | + * @access protected |
|
698 | + * @param \EE_Ticket $ticket |
|
699 | + * @param \EE_Datetime[] $saved_datetimes |
|
700 | + * @param \EE_Datetime[] $added_datetimes |
|
701 | + * @param \EE_Datetime[] $removed_datetimes |
|
702 | + * @return \EE_Ticket |
|
703 | + * @throws \EE_Error |
|
704 | + */ |
|
705 | + protected function _update_ticket_datetimes( |
|
706 | + EE_Ticket $ticket, |
|
707 | + $saved_datetimes = array(), |
|
708 | + $added_datetimes = array(), |
|
709 | + $removed_datetimes = array() |
|
710 | + ) { |
|
711 | + // to start we have to add the ticket to all the datetimes its supposed to be with, |
|
712 | + // and removing the ticket from datetimes it got removed from. |
|
713 | + // first let's add datetimes |
|
714 | + if (! empty($added_datetimes) && is_array($added_datetimes)) { |
|
715 | + foreach ($added_datetimes as $row_id) { |
|
716 | + $row_id = (int)$row_id; |
|
717 | + if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
|
718 | + $ticket->_add_relation_to($saved_datetimes[$row_id], 'Datetime'); |
|
719 | + // Is this an existing ticket (has an ID) and does it have any sold? |
|
720 | + // If so, then we need to add that to the DTT sold because this DTT is getting added. |
|
721 | + if ($ticket->ID() && $ticket->sold() > 0) { |
|
722 | + $saved_datetimes[$row_id]->increase_sold($ticket->sold()); |
|
723 | + $saved_datetimes[$row_id]->save(); |
|
724 | + } |
|
725 | + } |
|
726 | + } |
|
727 | + } |
|
728 | + // then remove datetimes |
|
729 | + if (! empty($removed_datetimes) && is_array($removed_datetimes)) { |
|
730 | + foreach ($removed_datetimes as $row_id) { |
|
731 | + $row_id = (int)$row_id; |
|
732 | + // its entirely possible that a datetime got deleted (instead of just removed from relationship. |
|
733 | + // So make sure we skip over this if the dtt isn't in the $saved_datetimes array) |
|
734 | + if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
|
735 | + $ticket->_remove_relation_to($saved_datetimes[$row_id], 'Datetime'); |
|
736 | + // Is this an existing ticket (has an ID) and does it have any sold? |
|
737 | + // If so, then we need to remove it's sold from the DTT_sold. |
|
738 | + if ($ticket->ID() && $ticket->sold() > 0) { |
|
739 | + $saved_datetimes[$row_id]->decrease_sold($ticket->sold()); |
|
740 | + $saved_datetimes[$row_id]->save(); |
|
741 | + } |
|
742 | + } |
|
743 | + } |
|
744 | + } |
|
745 | + // cap ticket qty by datetime reg limits |
|
746 | + $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit'))); |
|
747 | + return $ticket; |
|
748 | + } |
|
749 | + |
|
750 | + |
|
751 | + |
|
752 | + /** |
|
753 | + * @access protected |
|
754 | + * @param \EE_Ticket $ticket |
|
755 | + * @param array $price_rows |
|
756 | + * @param int $ticket_price |
|
757 | + * @param int $base_price |
|
758 | + * @param int $base_price_id |
|
759 | + * @return \EE_Ticket |
|
760 | + * @throws \EE_Error |
|
761 | + */ |
|
762 | + protected function _duplicate_ticket( |
|
763 | + EE_Ticket $ticket, |
|
764 | + $price_rows = array(), |
|
765 | + $ticket_price = 0, |
|
766 | + $base_price = 0, |
|
767 | + $base_price_id = 0 |
|
768 | + ) { |
|
769 | + // create new ticket that's a copy of the existing |
|
770 | + // except a new id of course (and not archived) |
|
771 | + // AND has the new TKT_price associated with it. |
|
772 | + $new_ticket = clone $ticket; |
|
773 | + $new_ticket->set('TKT_ID', 0); |
|
774 | + $new_ticket->set('TKT_deleted', 0); |
|
775 | + $new_ticket->set('TKT_price', $ticket_price); |
|
776 | + $new_ticket->set('TKT_sold', 0); |
|
777 | + // let's get a new ID for this ticket |
|
778 | + $new_ticket->save(); |
|
779 | + // we also need to make sure this new ticket gets the same datetime attachments as the archived ticket |
|
780 | + $datetimes_on_existing = $ticket->get_many_related('Datetime'); |
|
781 | + $new_ticket = $this->_update_ticket_datetimes( |
|
782 | + $new_ticket, |
|
783 | + $datetimes_on_existing, |
|
784 | + array_keys($datetimes_on_existing) |
|
785 | + ); |
|
786 | + // $ticket will get archived later b/c we are NOT adding it to the saved_tickets array. |
|
787 | + // if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining |
|
788 | + // available. |
|
789 | + if ($ticket->sold() > 0) { |
|
790 | + $new_qty = $ticket->qty() - $ticket->sold(); |
|
791 | + $new_ticket->set_qty($new_qty); |
|
792 | + } |
|
793 | + //now we update the prices just for this ticket |
|
794 | + $new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true); |
|
795 | + //and we update the base price |
|
796 | + $new_ticket = $this->_add_prices_to_ticket(array(), $new_ticket, true, $base_price, $base_price_id); |
|
797 | + return $new_ticket; |
|
798 | + } |
|
799 | + |
|
800 | + |
|
801 | + |
|
802 | + /** |
|
803 | + * This attaches a list of given prices to a ticket. |
|
804 | + * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
805 | + * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
806 | + * price info and prices are automatically "archived" via the ticket. |
|
807 | + * |
|
808 | + * @access private |
|
809 | + * @param array $prices Array of prices from the form. |
|
810 | + * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
811 | + * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
812 | + * @param int|bool $base_price if FALSE then NOT doing a base price add. |
|
813 | + * @param int|bool $base_price_id if present then this is the base_price_id being updated. |
|
814 | + * @return EE_Ticket |
|
815 | + * @throws EE_Error |
|
816 | + */ |
|
817 | + protected function _add_prices_to_ticket( |
|
818 | + $prices = array(), |
|
819 | + EE_Ticket $ticket, |
|
820 | + $new_prices = false, |
|
821 | + $base_price = false, |
|
822 | + $base_price_id = false |
|
823 | + ) { |
|
824 | + // let's just get any current prices that may exist on the given ticket |
|
825 | + // so we can remove any prices that got trashed in this session. |
|
826 | + $current_prices_on_ticket = $base_price !== false |
|
827 | + ? $ticket->base_price(true) |
|
828 | + : $ticket->price_modifiers(); |
|
829 | + $updated_prices = array(); |
|
830 | + // if $base_price ! FALSE then updating a base price. |
|
831 | + if ($base_price !== false) { |
|
832 | + $prices[1] = array( |
|
833 | + 'PRC_ID' => $new_prices || $base_price_id === 1 ? null : $base_price_id, |
|
834 | + 'PRT_ID' => 1, |
|
835 | + 'PRC_amount' => $base_price, |
|
836 | + 'PRC_name' => $ticket->get('TKT_name'), |
|
837 | + 'PRC_desc' => $ticket->get('TKT_description'), |
|
838 | + ); |
|
839 | + } |
|
840 | + //possibly need to save tkt |
|
841 | + if (! $ticket->ID()) { |
|
842 | + $ticket->save(); |
|
843 | + } |
|
844 | + foreach ($prices as $row => $prc) { |
|
845 | + $prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null; |
|
846 | + if (empty($prt_id)) { |
|
847 | + continue; |
|
848 | + } //prices MUST have a price type id. |
|
849 | + $PRC_values = array( |
|
850 | + 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
851 | + 'PRT_ID' => $prt_id, |
|
852 | + 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
853 | + 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
854 | + 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
855 | + 'PRC_is_default' => false, |
|
856 | + //make sure we set PRC_is_default to false for all ticket saves from event_editor |
|
857 | + 'PRC_order' => $row, |
|
858 | + ); |
|
859 | + if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
860 | + $PRC_values['PRC_ID'] = 0; |
|
861 | + $price = EE_Registry::instance()->load_class( |
|
862 | + 'Price', |
|
863 | + array($PRC_values), |
|
864 | + false, |
|
865 | + false |
|
866 | + ); |
|
867 | + } else { |
|
868 | + $price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
869 | + //update this price with new values |
|
870 | + foreach ($PRC_values as $field => $value) { |
|
871 | + $price->set($field, $value); |
|
872 | + } |
|
873 | + } |
|
874 | + $price->save(); |
|
875 | + $updated_prices[$price->ID()] = $price; |
|
876 | + $ticket->_add_relation_to($price, 'Price'); |
|
877 | + } |
|
878 | + //now let's remove any prices that got removed from the ticket |
|
879 | + if (! empty ($current_prices_on_ticket)) { |
|
880 | + $current = array_keys($current_prices_on_ticket); |
|
881 | + $updated = array_keys($updated_prices); |
|
882 | + $prices_to_remove = array_diff($current, $updated); |
|
883 | + if (! empty($prices_to_remove)) { |
|
884 | + foreach ($prices_to_remove as $prc_id) { |
|
885 | + $p = $current_prices_on_ticket[$prc_id]; |
|
886 | + $ticket->_remove_relation_to($p, 'Price'); |
|
887 | + //delete permanently the price |
|
888 | + $p->delete_permanently(); |
|
889 | + } |
|
890 | + } |
|
891 | + } |
|
892 | + return $ticket; |
|
893 | + } |
|
894 | + |
|
895 | + |
|
896 | + |
|
897 | + /** |
|
898 | + * @param Events_Admin_Page $event_admin_obj |
|
899 | + * @return Events_Admin_Page |
|
900 | + */ |
|
901 | + public function autosave_handling( Events_Admin_Page $event_admin_obj) |
|
902 | + { |
|
903 | + return $event_admin_obj; |
|
904 | + //doing nothing for the moment. |
|
905 | + // todo when I get to this remember that I need to set the template args on the $event_admin_obj |
|
906 | + // (use the set_template_args() method) |
|
907 | + /** |
|
908 | + * need to remember to handle TICKET DEFAULT saves correctly: I've got two input fields in the dom: |
|
909 | + * 1. TKT_is_default_selector (visible) |
|
910 | + * 2. TKT_is_default (hidden) |
|
911 | + * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket |
|
912 | + * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want |
|
913 | + * this ticket to be saved as a default. |
|
914 | + * The tricky part is, on an initial display on create or edit (or after manually updating), |
|
915 | + * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true |
|
916 | + * if this is a create. However, after an autosave, users will want some sort of indicator that |
|
917 | + * the TKT HAS been saved as a default.. |
|
918 | + * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking. |
|
919 | + * On Autosave: |
|
920 | + * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements, |
|
921 | + * then set the TKT_is_default to false. |
|
922 | + * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well). |
|
923 | + * We do NOT create a new default ticket. The checkbox stays selected after autosave. |
|
924 | + * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket. |
|
925 | + */ |
|
926 | + } |
|
927 | + |
|
928 | + |
|
929 | + |
|
930 | + /** |
|
931 | + * @throws DomainException |
|
932 | + * @throws EE_Error |
|
933 | + */ |
|
934 | + public function pricing_metabox() |
|
935 | + { |
|
936 | + $existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array(); |
|
937 | + $event = $this->_adminpage_obj->get_cpt_model_obj(); |
|
938 | + //set is_creating_event property. |
|
939 | + $EVT_ID = $event->ID(); |
|
940 | + $this->_is_creating_event = absint($EVT_ID) !== 0 ? false : true; |
|
941 | + //default main template args |
|
942 | + $main_template_args = array( |
|
943 | + 'event_datetime_help_link' => EEH_Template::get_help_tab_link( |
|
944 | + 'event_editor_event_datetimes_help_tab', |
|
945 | + $this->_adminpage_obj->page_slug, |
|
946 | + $this->_adminpage_obj->get_req_action(), |
|
947 | + false, |
|
948 | + false |
|
949 | + ), |
|
950 | + // todo need to add a filter to the template for the help text |
|
951 | + // in the Events_Admin_Page core file so we can add further help |
|
952 | + 'existing_datetime_ids' => '', |
|
953 | + 'total_dtt_rows' => 1, |
|
954 | + 'add_new_dtt_help_link' => EEH_Template::get_help_tab_link( |
|
955 | + 'add_new_dtt_info', |
|
956 | + $this->_adminpage_obj->page_slug, |
|
957 | + $this->_adminpage_obj->get_req_action(), |
|
958 | + false, |
|
959 | + false |
|
960 | + ), |
|
961 | + //todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
962 | + 'datetime_rows' => '', |
|
963 | + 'show_tickets_container' => '', |
|
964 | + //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '', |
|
965 | + 'ticket_rows' => '', |
|
966 | + 'existing_ticket_ids' => '', |
|
967 | + 'total_ticket_rows' => 1, |
|
968 | + 'ticket_js_structure' => '', |
|
969 | + 'ee_collapsible_status' => ' ee-collapsible-open' |
|
970 | + //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open' |
|
971 | + ); |
|
972 | + $timezone = $event instanceof EE_Event ? $event->timezone_string() : null; |
|
973 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
974 | + /** |
|
975 | + * 1. Start with retrieving Datetimes |
|
976 | + * 2. For each datetime get related tickets |
|
977 | + * 3. For each ticket get related prices |
|
978 | + */ |
|
979 | + /** @var EEM_Datetime $datetime_model */ |
|
980 | + $datetime_model = EE_Registry::instance()->load_model('Datetime', array($timezone)); |
|
981 | + $datetimes = $datetime_model->get_all_event_dates($EVT_ID); |
|
982 | + $main_template_args['total_dtt_rows'] = count($datetimes); |
|
983 | + /** |
|
984 | + * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486 |
|
985 | + * for why we are counting $datetime_row and then setting that on the Datetime object |
|
986 | + */ |
|
987 | + $datetime_row = 1; |
|
988 | + foreach ($datetimes as $datetime) { |
|
989 | + $DTT_ID = $datetime->get('DTT_ID'); |
|
990 | + $datetime->set('DTT_order', $datetime_row); |
|
991 | + $existing_datetime_ids[] = $DTT_ID; |
|
992 | + //tickets attached |
|
993 | + $related_tickets = $datetime->ID() > 0 |
|
994 | + ? $datetime->get_many_related( |
|
995 | + 'Ticket', |
|
996 | + array( |
|
997 | + array( |
|
998 | + 'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0), |
|
999 | + ), |
|
1000 | + 'default_where_conditions' => 'none', |
|
1001 | + 'order_by' => array('TKT_order' => 'ASC'), |
|
1002 | + ) |
|
1003 | + ) |
|
1004 | + : array(); |
|
1005 | + //if there are no related tickets this is likely a new event OR autodraft |
|
1006 | + // event so we need to generate the default tickets because datetimes |
|
1007 | + // ALWAYS have at least one related ticket!!. EXCEPT, we dont' do this if there is already more than one |
|
1008 | + // datetime on the event. |
|
1009 | + if (empty ($related_tickets) && count($datetimes) < 2) { |
|
1010 | + /** @var EEM_Ticket $ticket_model */ |
|
1011 | + $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
1012 | + $related_tickets = $ticket_model->get_all_default_tickets(); |
|
1013 | + // this should be ordered by TKT_ID, so let's grab the first default ticket |
|
1014 | + // (which will be the main default) and ensure it has any default prices added to it (but do NOT save). |
|
1015 | + $default_prices = EEM_Price::instance()->get_all_default_prices(); |
|
1016 | + $main_default_ticket = reset($related_tickets); |
|
1017 | + if ($main_default_ticket instanceof EE_Ticket) { |
|
1018 | + foreach ($default_prices as $default_price) { |
|
1019 | + if ($default_price instanceof EE_Price && $default_price->is_base_price()) { |
|
1020 | + continue; |
|
1021 | + } |
|
1022 | + $main_default_ticket->cache('Price', $default_price); |
|
1023 | + } |
|
1024 | + } |
|
1025 | + } |
|
1026 | + // we can't actually setup rows in this loop yet cause we don't know all |
|
1027 | + // the unique tickets for this event yet (tickets are linked through all datetimes). |
|
1028 | + // So we're going to temporarily cache some of that information. |
|
1029 | + //loop through and setup the ticket rows and make sure the order is set. |
|
1030 | + foreach ($related_tickets as $ticket) { |
|
1031 | + $TKT_ID = $ticket->get('TKT_ID'); |
|
1032 | + $ticket_row = $ticket->get('TKT_row'); |
|
1033 | + //we only want unique tickets in our final display!! |
|
1034 | + if (! in_array($TKT_ID, $existing_ticket_ids, true)) { |
|
1035 | + $existing_ticket_ids[] = $TKT_ID; |
|
1036 | + $all_tickets[] = $ticket; |
|
1037 | + } |
|
1038 | + //temporary cache of this ticket info for this datetime for later processing of datetime rows. |
|
1039 | + $datetime_tickets[$DTT_ID][] = $ticket_row; |
|
1040 | + //temporary cache of this datetime info for this ticket for later processing of ticket rows. |
|
1041 | + if ( |
|
1042 | + ! isset($ticket_datetimes[$TKT_ID]) |
|
1043 | + || ! in_array($datetime_row, $ticket_datetimes[$TKT_ID], true) |
|
1044 | + ) { |
|
1045 | + $ticket_datetimes[$TKT_ID][] = $datetime_row; |
|
1046 | + } |
|
1047 | + } |
|
1048 | + $datetime_row++; |
|
1049 | + } |
|
1050 | + $main_template_args['total_ticket_rows'] = count($existing_ticket_ids); |
|
1051 | + $main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
1052 | + $main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
1053 | + //sort $all_tickets by order |
|
1054 | + usort( |
|
1055 | + $all_tickets, |
|
1056 | + function (EE_Ticket $a, EE_Ticket $b) { |
|
1057 | + $a_order = (int)$a->get('TKT_order'); |
|
1058 | + $b_order = (int)$b->get('TKT_order'); |
|
1059 | + if ($a_order === $b_order) { |
|
1060 | + return 0; |
|
1061 | + } |
|
1062 | + return ($a_order < $b_order) ? -1 : 1; |
|
1063 | + } |
|
1064 | + ); |
|
1065 | + // k NOW we have all the data we need for setting up the dtt rows |
|
1066 | + // and ticket rows so we start our dtt loop again. |
|
1067 | + $datetime_row = 1; |
|
1068 | + foreach ($datetimes as $datetime) { |
|
1069 | + $main_template_args['datetime_rows'] .= $this->_get_datetime_row( |
|
1070 | + $datetime_row, |
|
1071 | + $datetime, |
|
1072 | + $datetime_tickets, |
|
1073 | + $all_tickets, |
|
1074 | + false, |
|
1075 | + $datetimes |
|
1076 | + ); |
|
1077 | + $datetime_row++; |
|
1078 | + } |
|
1079 | + //then loop through all tickets for the ticket rows. |
|
1080 | + $ticket_row = 1; |
|
1081 | + foreach ($all_tickets as $ticket) { |
|
1082 | + $main_template_args['ticket_rows'] .= $this->_get_ticket_row( |
|
1083 | + $ticket_row, |
|
1084 | + $ticket, |
|
1085 | + $ticket_datetimes, |
|
1086 | + $datetimes, |
|
1087 | + false, |
|
1088 | + $all_tickets |
|
1089 | + ); |
|
1090 | + $ticket_row++; |
|
1091 | + } |
|
1092 | + $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets); |
|
1093 | + EEH_Template::display_template( |
|
1094 | + PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php', |
|
1095 | + $main_template_args |
|
1096 | + ); |
|
1097 | + } |
|
1098 | + |
|
1099 | + |
|
1100 | + |
|
1101 | + /** |
|
1102 | + * @param int $datetime_row |
|
1103 | + * @param EE_Datetime $datetime |
|
1104 | + * @param array $datetime_tickets |
|
1105 | + * @param array $all_tickets |
|
1106 | + * @param bool $default |
|
1107 | + * @param array $all_datetimes |
|
1108 | + * @return mixed |
|
1109 | + * @throws DomainException |
|
1110 | + * @throws EE_Error |
|
1111 | + */ |
|
1112 | + protected function _get_datetime_row( |
|
1113 | + $datetime_row, |
|
1114 | + EE_Datetime $datetime, |
|
1115 | + $datetime_tickets = array(), |
|
1116 | + $all_tickets = array(), |
|
1117 | + $default = false, |
|
1118 | + $all_datetimes = array() |
|
1119 | + ) { |
|
1120 | + $dtt_display_template_args = array( |
|
1121 | + 'dtt_edit_row' => $this->_get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes), |
|
1122 | + 'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row( |
|
1123 | + $datetime_row, |
|
1124 | + $datetime, |
|
1125 | + $datetime_tickets, |
|
1126 | + $all_tickets, |
|
1127 | + $default |
|
1128 | + ), |
|
1129 | + 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
1130 | + ); |
|
1131 | + return EEH_Template::display_template( |
|
1132 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php', |
|
1133 | + $dtt_display_template_args, |
|
1134 | + true |
|
1135 | + ); |
|
1136 | + } |
|
1137 | + |
|
1138 | + |
|
1139 | + |
|
1140 | + /** |
|
1141 | + * This method is used to generate a dtt fields edit row. |
|
1142 | + * The same row is used to generate a row with valid DTT objects |
|
1143 | + * and the default row that is used as the skeleton by the js. |
|
1144 | + * |
|
1145 | + * @param int $datetime_row The row number for the row being generated. |
|
1146 | + * @param EE_Datetime $datetime |
|
1147 | + * @param bool $default Whether a default row is being generated or not. |
|
1148 | + * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor. |
|
1149 | + * @return string |
|
1150 | + * @throws DomainException |
|
1151 | + * @throws EE_Error |
|
1152 | + */ |
|
1153 | + protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes) |
|
1154 | + { |
|
1155 | + // if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true. |
|
1156 | + $default = ! $datetime instanceof EE_Datetime ? true : $default; |
|
1157 | + $template_args = array( |
|
1158 | + 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
1159 | + 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
1160 | + 'edit_dtt_expanded' => '', |
|
1161 | + 'DTT_ID' => $default ? '' : $datetime->ID(), |
|
1162 | + 'DTT_name' => $default ? '' : $datetime->name(), |
|
1163 | + 'DTT_description' => $default ? '' : $datetime->description(), |
|
1164 | + 'DTT_EVT_start' => $default ? '' : $datetime->start_date($this->_date_time_format), |
|
1165 | + 'DTT_EVT_end' => $default ? '' : $datetime->end_date($this->_date_time_format), |
|
1166 | + 'DTT_reg_limit' => $default |
|
1167 | + ? '' |
|
1168 | + : $datetime->get_pretty( |
|
1169 | + 'DTT_reg_limit', |
|
1170 | + 'input' |
|
1171 | + ), |
|
1172 | + 'DTT_order' => $default ? 'DTTNUM' : $datetime_row, |
|
1173 | + 'dtt_sold' => $default ? '0' : $datetime->get('DTT_sold'), |
|
1174 | + 'dtt_reserved' => $default ? '0' : $datetime->reserved(), |
|
1175 | + 'clone_icon' => ! empty($datetime) && $datetime->get('DTT_sold') > 0 |
|
1176 | + ? '' |
|
1177 | + : 'clone-icon ee-icon ee-icon-clone clickable', |
|
1178 | + 'trash_icon' => ! empty($datetime) && $datetime->get('DTT_sold') > 0 |
|
1179 | + ? 'ee-lock-icon' |
|
1180 | + : 'trash-icon dashicons dashicons-post-trash clickable', |
|
1181 | + 'reg_list_url' => $default || ! $datetime->event() instanceof \EE_Event |
|
1182 | + ? '' |
|
1183 | + : EE_Admin_Page::add_query_args_and_nonce( |
|
1184 | + array('event_id' => $datetime->event()->ID(), 'datetime_id' => $datetime->ID()), |
|
1185 | + REG_ADMIN_URL |
|
1186 | + ), |
|
1187 | + ); |
|
1188 | + $template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' |
|
1189 | + ? ' style="display:none"' |
|
1190 | + : ''; |
|
1191 | + //allow filtering of template args at this point. |
|
1192 | + $template_args = apply_filters( |
|
1193 | + 'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args', |
|
1194 | + $template_args, |
|
1195 | + $datetime_row, |
|
1196 | + $datetime, |
|
1197 | + $default, |
|
1198 | + $all_datetimes, |
|
1199 | + $this->_is_creating_event |
|
1200 | + ); |
|
1201 | + return EEH_Template::display_template( |
|
1202 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php', |
|
1203 | + $template_args, |
|
1204 | + true |
|
1205 | + ); |
|
1206 | + } |
|
1207 | + |
|
1208 | + |
|
1209 | + |
|
1210 | + /** |
|
1211 | + * @param int $datetime_row |
|
1212 | + * @param EE_Datetime $datetime |
|
1213 | + * @param array $datetime_tickets |
|
1214 | + * @param array $all_tickets |
|
1215 | + * @param bool $default |
|
1216 | + * @return mixed |
|
1217 | + * @throws DomainException |
|
1218 | + * @throws EE_Error |
|
1219 | + */ |
|
1220 | + protected function _get_dtt_attached_tickets_row( |
|
1221 | + $datetime_row, |
|
1222 | + $datetime, |
|
1223 | + $datetime_tickets = array(), |
|
1224 | + $all_tickets = array(), |
|
1225 | + $default |
|
1226 | + ) { |
|
1227 | + $template_args = array( |
|
1228 | + 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
1229 | + 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
1230 | + 'DTT_description' => $default ? '' : $datetime->description(), |
|
1231 | + 'datetime_tickets_list' => $default ? '<li class="hidden"></li>' : '', |
|
1232 | + 'show_tickets_row' => ' style="display:none;"', |
|
1233 | + 'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link( |
|
1234 | + 'add_new_ticket_via_datetime', |
|
1235 | + $this->_adminpage_obj->page_slug, |
|
1236 | + $this->_adminpage_obj->get_req_action(), |
|
1237 | + false, |
|
1238 | + false |
|
1239 | + ), |
|
1240 | + //todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
1241 | + 'DTT_ID' => $default ? '' : $datetime->ID(), |
|
1242 | + ); |
|
1243 | + //need to setup the list items (but only if this isn't a default skeleton setup) |
|
1244 | + if (! $default) { |
|
1245 | + $ticket_row = 1; |
|
1246 | + foreach ($all_tickets as $ticket) { |
|
1247 | + $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
|
1248 | + $datetime_row, |
|
1249 | + $ticket_row, |
|
1250 | + $datetime, |
|
1251 | + $ticket, |
|
1252 | + $datetime_tickets, |
|
1253 | + $default |
|
1254 | + ); |
|
1255 | + $ticket_row++; |
|
1256 | + } |
|
1257 | + } |
|
1258 | + //filter template args at this point |
|
1259 | + $template_args = apply_filters( |
|
1260 | + 'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args', |
|
1261 | + $template_args, |
|
1262 | + $datetime_row, |
|
1263 | + $datetime, |
|
1264 | + $datetime_tickets, |
|
1265 | + $all_tickets, |
|
1266 | + $default, |
|
1267 | + $this->_is_creating_event |
|
1268 | + ); |
|
1269 | + return EEH_Template::display_template( |
|
1270 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php', |
|
1271 | + $template_args, |
|
1272 | + true |
|
1273 | + ); |
|
1274 | + } |
|
1275 | + |
|
1276 | + |
|
1277 | + |
|
1278 | + /** |
|
1279 | + * @param int $datetime_row |
|
1280 | + * @param int $ticket_row |
|
1281 | + * @param EE_Datetime $datetime |
|
1282 | + * @param EE_Ticket $ticket |
|
1283 | + * @param array $datetime_tickets |
|
1284 | + * @param bool $default |
|
1285 | + * @return mixed |
|
1286 | + * @throws DomainException |
|
1287 | + * @throws EE_Error |
|
1288 | + */ |
|
1289 | + protected function _get_datetime_tickets_list_item( |
|
1290 | + $datetime_row, |
|
1291 | + $ticket_row, |
|
1292 | + $datetime, |
|
1293 | + $ticket, |
|
1294 | + $datetime_tickets = array(), |
|
1295 | + $default |
|
1296 | + ) { |
|
1297 | + $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[$datetime->ID()]) |
|
1298 | + ? $datetime_tickets[$datetime->ID()] |
|
1299 | + : array(); |
|
1300 | + $display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0; |
|
1301 | + $no_ticket = $default && empty($ticket); |
|
1302 | + $template_args = array( |
|
1303 | + 'dtt_row' => $default |
|
1304 | + ? 'DTTNUM' |
|
1305 | + : $datetime_row, |
|
1306 | + 'tkt_row' => $no_ticket |
|
1307 | + ? 'TICKETNUM' |
|
1308 | + : $ticket_row, |
|
1309 | + 'datetime_ticket_checked' => in_array($display_row, $dtt_tkts, true) |
|
1310 | + ? ' checked="checked"' |
|
1311 | + : '', |
|
1312 | + 'ticket_selected' => in_array($display_row, $dtt_tkts, true) |
|
1313 | + ? ' ticket-selected' |
|
1314 | + : '', |
|
1315 | + 'TKT_name' => $no_ticket |
|
1316 | + ? 'TKTNAME' |
|
1317 | + : $ticket->get('TKT_name'), |
|
1318 | + 'tkt_status_class' => $no_ticket || $this->_is_creating_event |
|
1319 | + ? ' tkt-status-' . EE_Ticket::onsale |
|
1320 | + : ' tkt-status-' . $ticket->ticket_status(), |
|
1321 | + ); |
|
1322 | + //filter template args |
|
1323 | + $template_args = apply_filters( |
|
1324 | + 'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args', |
|
1325 | + $template_args, |
|
1326 | + $datetime_row, |
|
1327 | + $ticket_row, |
|
1328 | + $datetime, |
|
1329 | + $ticket, |
|
1330 | + $datetime_tickets, |
|
1331 | + $default, |
|
1332 | + $this->_is_creating_event |
|
1333 | + ); |
|
1334 | + return EEH_Template::display_template( |
|
1335 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php', |
|
1336 | + $template_args, |
|
1337 | + true |
|
1338 | + ); |
|
1339 | + } |
|
1340 | + |
|
1341 | + |
|
1342 | + |
|
1343 | + /** |
|
1344 | + * This generates the ticket row for tickets. |
|
1345 | + * This same method is used to generate both the actual rows and the js skeleton row |
|
1346 | + * (when default === true) |
|
1347 | + * |
|
1348 | + * @param int $ticket_row Represents the row number being generated. |
|
1349 | + * @param $ticket |
|
1350 | + * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket |
|
1351 | + * or empty for default |
|
1352 | + * @param EE_Datetime[] $all_datetimes All Datetimes on the event or empty for default. |
|
1353 | + * @param bool $default Whether default row being generated or not. |
|
1354 | + * @param EE_Ticket[] $all_tickets This is an array of all tickets attached to the event |
|
1355 | + * (or empty in the case of defaults) |
|
1356 | + * @return mixed |
|
1357 | + * @throws DomainException |
|
1358 | + * @throws EE_Error |
|
1359 | + */ |
|
1360 | + protected function _get_ticket_row( |
|
1361 | + $ticket_row, |
|
1362 | + $ticket, |
|
1363 | + $ticket_datetimes, |
|
1364 | + $all_datetimes, |
|
1365 | + $default = false, |
|
1366 | + $all_tickets = array() |
|
1367 | + ) { |
|
1368 | + // if $ticket is not an instance of EE_Ticket then force default to true. |
|
1369 | + $default = ! $ticket instanceof EE_Ticket ? true : $default; |
|
1370 | + $prices = ! empty($ticket) && ! $default ? $ticket->get_many_related('Price', |
|
1371 | + array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC'))) : array(); |
|
1372 | + // if there is only one price (which would be the base price) |
|
1373 | + // or NO prices and this ticket is a default ticket, |
|
1374 | + // let's just make sure there are no cached default prices on the object. |
|
1375 | + // This is done by not including any query_params. |
|
1376 | + if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) { |
|
1377 | + $prices = $ticket->get_many_related('Price'); |
|
1378 | + } |
|
1379 | + // check if we're dealing with a default ticket in which case |
|
1380 | + // we don't want any starting_ticket_datetime_row values set |
|
1381 | + // (otherwise there won't be any new relationships created for tickets based off of the default ticket). |
|
1382 | + // This will future proof in case there is ever any behaviour change between what the primary_key defaults to. |
|
1383 | + $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->get('TKT_is_default')); |
|
1384 | + $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) |
|
1385 | + ? $ticket_datetimes[$ticket->ID()] |
|
1386 | + : array(); |
|
1387 | + $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal(); |
|
1388 | + $base_price = $default ? null : $ticket->base_price(); |
|
1389 | + $count_price_mods = EEM_Price::instance()->get_all_default_prices(true); |
|
1390 | + //breaking out complicated condition for ticket_status |
|
1391 | + if ($default) { |
|
1392 | + $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale; |
|
1393 | + } else { |
|
1394 | + $ticket_status_class = $ticket->is_default() |
|
1395 | + ? ' tkt-status-' . EE_Ticket::onsale |
|
1396 | + : ' tkt-status-' . $ticket->ticket_status(); |
|
1397 | + } |
|
1398 | + //breaking out complicated condition for TKT_taxable |
|
1399 | + if ($default) { |
|
1400 | + $TKT_taxable = ''; |
|
1401 | + } else { |
|
1402 | + $TKT_taxable = $ticket->get('TKT_taxable') |
|
1403 | + ? ' checked="checked"' |
|
1404 | + : ''; |
|
1405 | + } |
|
1406 | + if ($default) { |
|
1407 | + $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence'); |
|
1408 | + } else if ($ticket->is_default()) { |
|
1409 | + $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence'); |
|
1410 | + } else { |
|
1411 | + $TKT_status = $ticket->ticket_status(true); |
|
1412 | + } |
|
1413 | + if ($default) { |
|
1414 | + $TKT_min = ''; |
|
1415 | + } else { |
|
1416 | + $TKT_min = $ticket->get('TKT_min'); |
|
1417 | + if ($TKT_min === -1 || $TKT_min === 0) { |
|
1418 | + $TKT_min = ''; |
|
1419 | + } |
|
1420 | + } |
|
1421 | + $template_args = array( |
|
1422 | + 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
1423 | + 'TKT_order' => $default ? 'TICKETNUM' : $ticket_row, |
|
1424 | + //on initial page load this will always be the correct order. |
|
1425 | + 'tkt_status_class' => $ticket_status_class, |
|
1426 | + 'display_edit_tkt_row' => ' style="display:none;"', |
|
1427 | + 'edit_tkt_expanded' => '', |
|
1428 | + 'edit_tickets_name' => $default ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
1429 | + 'TKT_name' => $default ? '' : $ticket->get('TKT_name'), |
|
1430 | + 'TKT_start_date' => $default |
|
1431 | + ? '' |
|
1432 | + : $ticket->get_date('TKT_start_date', |
|
1433 | + $this->_date_time_format), |
|
1434 | + 'TKT_end_date' => $default |
|
1435 | + ? '' |
|
1436 | + : $ticket->get_date('TKT_end_date', |
|
1437 | + $this->_date_time_format), |
|
1438 | + 'TKT_status' => $TKT_status, |
|
1439 | + 'TKT_price' => $default |
|
1440 | + ? '' |
|
1441 | + : EEH_Template::format_currency( |
|
1442 | + $ticket->get_ticket_total_with_taxes(), |
|
1443 | + false, |
|
1444 | + false |
|
1445 | + ), |
|
1446 | + 'TKT_price_code' => EE_Registry::instance()->CFG->currency->code, |
|
1447 | + 'TKT_price_amount' => $default ? 0 : $ticket_subtotal, |
|
1448 | + 'TKT_qty' => $default |
|
1449 | + ? '' |
|
1450 | + : $ticket->get_pretty('TKT_qty', 'symbol'), |
|
1451 | + 'TKT_qty_for_input' => $default |
|
1452 | + ? '' |
|
1453 | + : $ticket->get_pretty('TKT_qty', 'input'), |
|
1454 | + 'TKT_uses' => $default |
|
1455 | + ? '' |
|
1456 | + : $ticket->get_pretty('TKT_uses', 'input'), |
|
1457 | + 'TKT_min' => $TKT_min, |
|
1458 | + 'TKT_max' => $default |
|
1459 | + ? '' |
|
1460 | + : $ticket->get_pretty('TKT_max', 'input'), |
|
1461 | + 'TKT_sold' => $default ? 0 : $ticket->tickets_sold('ticket'), |
|
1462 | + 'TKT_reserved' => $default ? 0 : $ticket->reserved(), |
|
1463 | + 'TKT_registrations' => $default |
|
1464 | + ? 0 |
|
1465 | + : $ticket->count_registrations( |
|
1466 | + array( |
|
1467 | + array( |
|
1468 | + 'STS_ID' => array( |
|
1469 | + '!=', |
|
1470 | + EEM_Registration::status_id_incomplete, |
|
1471 | + ), |
|
1472 | + ), |
|
1473 | + ) |
|
1474 | + ), |
|
1475 | + 'TKT_ID' => $default ? 0 : $ticket->get('TKT_ID'), |
|
1476 | + 'TKT_description' => $default ? '' : $ticket->get('TKT_description'), |
|
1477 | + 'TKT_is_default' => $default ? 0 : $ticket->get('TKT_is_default'), |
|
1478 | + 'TKT_required' => $default ? 0 : $ticket->required(), |
|
1479 | + 'TKT_is_default_selector' => '', |
|
1480 | + 'ticket_price_rows' => '', |
|
1481 | + 'TKT_base_price' => $default || ! $base_price instanceof EE_Price |
|
1482 | + ? '' |
|
1483 | + : $base_price->get_pretty('PRC_amount', 'localized_float'), |
|
1484 | + 'TKT_base_price_ID' => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(), |
|
1485 | + 'show_price_modifier' => count($prices) > 1 || ($default && $count_price_mods > 0) |
|
1486 | + ? '' |
|
1487 | + : ' style="display:none;"', |
|
1488 | + 'show_price_mod_button' => count($prices) > 1 |
|
1489 | + || ($default && $count_price_mods > 0) |
|
1490 | + || (! $default && $ticket->get('TKT_deleted')) |
|
1491 | + ? ' style="display:none;"' |
|
1492 | + : '', |
|
1493 | + 'total_price_rows' => count($prices) > 1 ? count($prices) : 1, |
|
1494 | + 'ticket_datetimes_list' => $default ? '<li class="hidden"></li>' : '', |
|
1495 | + 'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_datetimes), |
|
1496 | + 'ticket_datetime_rows' => $default ? '' : implode(',', $tkt_datetimes), |
|
1497 | + 'existing_ticket_price_ids' => $default ? '' : implode(',', array_keys($prices)), |
|
1498 | + 'ticket_template_id' => $default ? 0 : $ticket->get('TTM_ID'), |
|
1499 | + 'TKT_taxable' => $TKT_taxable, |
|
1500 | + 'display_subtotal' => $ticket instanceof EE_Ticket && $ticket->get('TKT_taxable') |
|
1501 | + ? '' |
|
1502 | + : ' style="display:none"', |
|
1503 | + 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
1504 | + 'TKT_subtotal_amount_display' => EEH_Template::format_currency( |
|
1505 | + $ticket_subtotal, |
|
1506 | + false, |
|
1507 | + false |
|
1508 | + ), |
|
1509 | + 'TKT_subtotal_amount' => $ticket_subtotal, |
|
1510 | + 'tax_rows' => $this->_get_tax_rows($ticket_row, $ticket), |
|
1511 | + 'disabled' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') |
|
1512 | + ? true |
|
1513 | + : false, |
|
1514 | + 'ticket_archive_class' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') |
|
1515 | + ? ' ticket-archived' |
|
1516 | + : '', |
|
1517 | + 'trash_icon' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') |
|
1518 | + ? 'ee-lock-icon ' |
|
1519 | + : 'trash-icon dashicons dashicons-post-trash clickable', |
|
1520 | + 'clone_icon' => $ticket instanceof EE_Ticket && $ticket->get('TKT_deleted') |
|
1521 | + ? '' |
|
1522 | + : 'clone-icon ee-icon ee-icon-clone clickable', |
|
1523 | + ); |
|
1524 | + $template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' |
|
1525 | + ? ' style="display:none"' |
|
1526 | + : ''; |
|
1527 | + //handle rows that should NOT be empty |
|
1528 | + if (empty($template_args['TKT_start_date'])) { |
|
1529 | + //if empty then the start date will be now. |
|
1530 | + $template_args['TKT_start_date'] = date($this->_date_time_format, |
|
1531 | + current_time('timestamp')); |
|
1532 | + $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
1533 | + } |
|
1534 | + if (empty($template_args['TKT_end_date'])) { |
|
1535 | + //get the earliest datetime (if present); |
|
1536 | + $earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 |
|
1537 | + ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related( |
|
1538 | + 'Datetime', |
|
1539 | + array('order_by' => array('DTT_EVT_start' => 'ASC')) |
|
1540 | + ) |
|
1541 | + : null; |
|
1542 | + if (! empty($earliest_dtt)) { |
|
1543 | + $template_args['TKT_end_date'] = $earliest_dtt->get_datetime( |
|
1544 | + 'DTT_EVT_start', |
|
1545 | + $this->_date_time_format |
|
1546 | + ); |
|
1547 | + } else { |
|
1548 | + //default so let's just use what's been set for the default date-time which is 30 days from now. |
|
1549 | + $template_args['TKT_end_date'] = date( |
|
1550 | + $this->_date_time_format, |
|
1551 | + mktime(24, 0, 0, date('m'), date('d') + 29, date('Y') |
|
1552 | + ) |
|
1553 | + ); |
|
1554 | + } |
|
1555 | + $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
1556 | + } |
|
1557 | + //generate ticket_datetime items |
|
1558 | + if (! $default) { |
|
1559 | + $datetime_row = 1; |
|
1560 | + foreach ($all_datetimes as $datetime) { |
|
1561 | + $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
|
1562 | + $datetime_row, |
|
1563 | + $ticket_row, |
|
1564 | + $datetime, |
|
1565 | + $ticket, |
|
1566 | + $ticket_datetimes, |
|
1567 | + $default |
|
1568 | + ); |
|
1569 | + $datetime_row++; |
|
1570 | + } |
|
1571 | + } |
|
1572 | + $price_row = 1; |
|
1573 | + foreach ($prices as $price) { |
|
1574 | + if ($price->is_base_price()) { |
|
1575 | + $price_row++; |
|
1576 | + continue; |
|
1577 | + } |
|
1578 | + $show_trash = (count($prices) > 1 && $price_row === 1) || count($prices) === 1 ? false : true; |
|
1579 | + $show_create = count($prices) > 1 && count($prices) !== $price_row ? false : true; |
|
1580 | + $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row( |
|
1581 | + $ticket_row, |
|
1582 | + $price_row, |
|
1583 | + $price, |
|
1584 | + $default, |
|
1585 | + $ticket, |
|
1586 | + $show_trash, |
|
1587 | + $show_create |
|
1588 | + ); |
|
1589 | + $price_row++; |
|
1590 | + } |
|
1591 | + //filter $template_args |
|
1592 | + $template_args = apply_filters( |
|
1593 | + 'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args', |
|
1594 | + $template_args, |
|
1595 | + $ticket_row, |
|
1596 | + $ticket, |
|
1597 | + $ticket_datetimes, |
|
1598 | + $all_datetimes, |
|
1599 | + $default, |
|
1600 | + $all_tickets, |
|
1601 | + $this->_is_creating_event |
|
1602 | + ); |
|
1603 | + return EEH_Template::display_template( |
|
1604 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php', |
|
1605 | + $template_args, |
|
1606 | + true |
|
1607 | + ); |
|
1608 | + } |
|
1609 | + |
|
1610 | + |
|
1611 | + |
|
1612 | + /** |
|
1613 | + * @param int $ticket_row |
|
1614 | + * @param EE_Ticket|null $ticket |
|
1615 | + * @return string |
|
1616 | + * @throws DomainException |
|
1617 | + * @throws EE_Error |
|
1618 | + */ |
|
1619 | + protected function _get_tax_rows($ticket_row, $ticket) |
|
1620 | + { |
|
1621 | + $tax_rows = ''; |
|
1622 | + $taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin(); |
|
1623 | + foreach ($taxes as $tax) { |
|
1624 | + $tax_added = $this->_get_tax_added($tax, $ticket); |
|
1625 | + $template_args = array( |
|
1626 | + 'display_tax' => ! empty($ticket) && $ticket->get('TKT_taxable') |
|
1627 | + ? '' |
|
1628 | + : ' style="display:none;"', |
|
1629 | + 'tax_id' => $tax->ID(), |
|
1630 | + 'tkt_row' => $ticket_row, |
|
1631 | + 'tax_label' => $tax->get('PRC_name'), |
|
1632 | + 'tax_added' => $tax_added, |
|
1633 | + 'tax_added_display' => EEH_Template::format_currency($tax_added, false, false), |
|
1634 | + 'tax_amount' => $tax->get('PRC_amount'), |
|
1635 | + ); |
|
1636 | + $template_args = apply_filters( |
|
1637 | + 'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args', |
|
1638 | + $template_args, |
|
1639 | + $ticket_row, |
|
1640 | + $ticket, |
|
1641 | + $this->_is_creating_event |
|
1642 | + ); |
|
1643 | + $tax_rows .= EEH_Template::display_template( |
|
1644 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php', |
|
1645 | + $template_args, |
|
1646 | + true |
|
1647 | + ); |
|
1648 | + } |
|
1649 | + return $tax_rows; |
|
1650 | + } |
|
1651 | + |
|
1652 | + |
|
1653 | + |
|
1654 | + /** |
|
1655 | + * @param EE_Price $tax |
|
1656 | + * @param EE_Ticket|null $ticket |
|
1657 | + * @return float|int |
|
1658 | + * @throws EE_Error |
|
1659 | + */ |
|
1660 | + protected function _get_tax_added(EE_Price $tax, $ticket) |
|
1661 | + { |
|
1662 | + $subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal(); |
|
1663 | + return $subtotal * $tax->get('PRC_amount') / 100; |
|
1664 | + } |
|
1665 | + |
|
1666 | + |
|
1667 | + |
|
1668 | + /** |
|
1669 | + * @param int $ticket_row |
|
1670 | + * @param int $price_row |
|
1671 | + * @param EE_Price|null $price |
|
1672 | + * @param bool $default |
|
1673 | + * @param EE_Ticket|null $ticket |
|
1674 | + * @param bool $show_trash |
|
1675 | + * @param bool $show_create |
|
1676 | + * @return mixed |
|
1677 | + * @throws DomainException |
|
1678 | + * @throws EE_Error |
|
1679 | + */ |
|
1680 | + protected function _get_ticket_price_row( |
|
1681 | + $ticket_row, |
|
1682 | + $price_row, |
|
1683 | + $price, |
|
1684 | + $default, |
|
1685 | + $ticket, |
|
1686 | + $show_trash = true, |
|
1687 | + $show_create = true |
|
1688 | + ) { |
|
1689 | + $send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted') ? true : false; |
|
1690 | + $template_args = array( |
|
1691 | + 'tkt_row' => $default && empty($ticket) |
|
1692 | + ? 'TICKETNUM' |
|
1693 | + : $ticket_row, |
|
1694 | + 'PRC_order' => $default && empty($price) |
|
1695 | + ? 'PRICENUM' |
|
1696 | + : $price_row, |
|
1697 | + 'edit_prices_name' => $default && empty($price) |
|
1698 | + ? 'PRICENAMEATTR' |
|
1699 | + : 'edit_prices', |
|
1700 | + 'price_type_selector' => $default && empty($price) |
|
1701 | + ? $this->_get_base_price_template($ticket_row, $price_row, $price, $default) |
|
1702 | + : $this->_get_price_type_selector($ticket_row, $price_row, $price, $default, $send_disabled), |
|
1703 | + 'PRC_ID' => $default && empty($price) |
|
1704 | + ? 0 |
|
1705 | + : $price->ID(), |
|
1706 | + 'PRC_is_default' => $default && empty($price) |
|
1707 | + ? 0 |
|
1708 | + : $price->get('PRC_is_default'), |
|
1709 | + 'PRC_name' => $default && empty($price) |
|
1710 | + ? '' |
|
1711 | + : $price->get('PRC_name'), |
|
1712 | + 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
1713 | + 'show_plus_or_minus' => $default && empty($price) |
|
1714 | + ? '' |
|
1715 | + : ' style="display:none;"', |
|
1716 | + 'show_plus' => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price()) |
|
1717 | + ? ' style="display:none;"' |
|
1718 | + : '', |
|
1719 | + 'show_minus' => ($default && empty($price)) || ! $price->is_discount() |
|
1720 | + ? ' style="display:none;"' |
|
1721 | + : '', |
|
1722 | + 'show_currency_symbol' => ($default && empty($price)) || $price->is_percent() |
|
1723 | + ? ' style="display:none"' |
|
1724 | + : '', |
|
1725 | + 'PRC_amount' => $default && empty($price) |
|
1726 | + ? 0 |
|
1727 | + : $price->get_pretty('PRC_amount', |
|
1728 | + 'localized_float'), |
|
1729 | + 'show_percentage' => ($default && empty($price)) || ! $price->is_percent() |
|
1730 | + ? ' style="display:none;"' |
|
1731 | + : '', |
|
1732 | + 'show_trash_icon' => $show_trash |
|
1733 | + ? '' |
|
1734 | + : ' style="display:none;"', |
|
1735 | + 'show_create_button' => $show_create |
|
1736 | + ? '' |
|
1737 | + : ' style="display:none;"', |
|
1738 | + 'PRC_desc' => $default && empty($price) |
|
1739 | + ? '' |
|
1740 | + : $price->get('PRC_desc'), |
|
1741 | + 'disabled' => ! empty($ticket) && $ticket->get('TKT_deleted') |
|
1742 | + ? true |
|
1743 | + : false, |
|
1744 | + ); |
|
1745 | + $template_args = apply_filters( |
|
1746 | + 'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args', |
|
1747 | + $template_args, |
|
1748 | + $ticket_row, |
|
1749 | + $price_row, |
|
1750 | + $price, |
|
1751 | + $default, |
|
1752 | + $ticket, |
|
1753 | + $show_trash, |
|
1754 | + $show_create, |
|
1755 | + $this->_is_creating_event |
|
1756 | + ); |
|
1757 | + return EEH_Template::display_template( |
|
1758 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php', |
|
1759 | + $template_args, |
|
1760 | + true |
|
1761 | + ); |
|
1762 | + } |
|
1763 | + |
|
1764 | + |
|
1765 | + |
|
1766 | + /** |
|
1767 | + * @param int $ticket_row |
|
1768 | + * @param int $price_row |
|
1769 | + * @param EE_Price $price |
|
1770 | + * @param bool $default |
|
1771 | + * @param bool $disabled |
|
1772 | + * @return mixed |
|
1773 | + * @throws DomainException |
|
1774 | + * @throws EE_Error |
|
1775 | + */ |
|
1776 | + protected function _get_price_type_selector($ticket_row, $price_row, $price, $default, $disabled = false) |
|
1777 | + { |
|
1778 | + if ($price->is_base_price()) { |
|
1779 | + return $this->_get_base_price_template($ticket_row, $price_row, $price, $default); |
|
1780 | + } |
|
1781 | + return $this->_get_price_modifier_template($ticket_row, $price_row, $price, $default, $disabled); |
|
1782 | + } |
|
1783 | + |
|
1784 | + |
|
1785 | + |
|
1786 | + /** |
|
1787 | + * @param int $ticket_row |
|
1788 | + * @param int $price_row |
|
1789 | + * @param EE_Price $price |
|
1790 | + * @param bool $default |
|
1791 | + * @return mixed |
|
1792 | + * @throws DomainException |
|
1793 | + * @throws EE_Error |
|
1794 | + */ |
|
1795 | + protected function _get_base_price_template($ticket_row, $price_row, $price, $default) |
|
1796 | + { |
|
1797 | + $template_args = array( |
|
1798 | + 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
1799 | + 'PRC_order' => $default && empty($price) ? 'PRICENUM' : $price_row, |
|
1800 | + 'PRT_ID' => $default && empty($price) ? 1 : $price->get('PRT_ID'), |
|
1801 | + 'PRT_name' => esc_html__('Price', 'event_espresso'), |
|
1802 | + 'price_selected_operator' => '+', |
|
1803 | + 'price_selected_is_percent' => 0, |
|
1804 | + ); |
|
1805 | + $template_args = apply_filters( |
|
1806 | + 'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args', |
|
1807 | + $template_args, |
|
1808 | + $ticket_row, |
|
1809 | + $price_row, |
|
1810 | + $price, |
|
1811 | + $default, |
|
1812 | + $this->_is_creating_event |
|
1813 | + ); |
|
1814 | + return EEH_Template::display_template( |
|
1815 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php', |
|
1816 | + $template_args, |
|
1817 | + true |
|
1818 | + ); |
|
1819 | + } |
|
1820 | + |
|
1821 | + |
|
1822 | + |
|
1823 | + /** |
|
1824 | + * @param int $ticket_row |
|
1825 | + * @param int $price_row |
|
1826 | + * @param EE_Price $price |
|
1827 | + * @param bool $default |
|
1828 | + * @param bool $disabled |
|
1829 | + * @return mixed |
|
1830 | + * @throws DomainException |
|
1831 | + * @throws EE_Error |
|
1832 | + */ |
|
1833 | + protected function _get_price_modifier_template( |
|
1834 | + $ticket_row, |
|
1835 | + $price_row, |
|
1836 | + $price, |
|
1837 | + $default, |
|
1838 | + $disabled = false |
|
1839 | + ) { |
|
1840 | + $select_name = $default && ! $price instanceof EE_Price |
|
1841 | + ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]' |
|
1842 | + : 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]'; |
|
1843 | + /** @var EEM_Price_Type $price_type_model */ |
|
1844 | + $price_type_model = EE_Registry::instance()->load_model('Price_Type'); |
|
1845 | + $price_types = $price_type_model->get_all(array( |
|
1846 | + array( |
|
1847 | + 'OR' => array( |
|
1848 | + 'PBT_ID' => '2', |
|
1849 | + 'PBT_ID*' => '3', |
|
1850 | + ), |
|
1851 | + ), |
|
1852 | + )); |
|
1853 | + $all_price_types = $default && ! $price instanceof EE_Price ? array( |
|
1854 | + array( |
|
1855 | + 'id' => 0, |
|
1856 | + 'text' => esc_html__('Select Modifier', 'event_espresso'), |
|
1857 | + ), |
|
1858 | + ) : array(); |
|
1859 | + $selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type(); |
|
1860 | + $price_option_spans = ''; |
|
1861 | + //setup price types for selector |
|
1862 | + foreach ($price_types as $price_type) { |
|
1863 | + if (! $price_type instanceof EE_Price_Type) { |
|
1864 | + continue; |
|
1865 | + } |
|
1866 | + $all_price_types[] = array( |
|
1867 | + 'id' => $price_type->ID(), |
|
1868 | + 'text' => $price_type->get('PRT_name'), |
|
1869 | + ); |
|
1870 | + //while we're in the loop let's setup the option spans used by js |
|
1871 | + $span_args = array( |
|
1872 | + 'PRT_ID' => $price_type->ID(), |
|
1873 | + 'PRT_operator' => $price_type->is_discount() ? '-' : '+', |
|
1874 | + 'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0, |
|
1875 | + ); |
|
1876 | + $price_option_spans .= EEH_Template::display_template( |
|
1877 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php', |
|
1878 | + $span_args, |
|
1879 | + true |
|
1880 | + ); |
|
1881 | + } |
|
1882 | + $select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]' : $select_name; |
|
1883 | + $select_input = new EE_Select_Input( |
|
1884 | + $all_price_types, |
|
1885 | + array( |
|
1886 | + 'default' => $selected_price_type_id, |
|
1887 | + 'html_name' => $select_name, |
|
1888 | + 'html_class' => 'edit-price-PRT_ID', |
|
1889 | + 'html_other_attributes' => $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"', |
|
1890 | + ) |
|
1891 | + ); |
|
1892 | + $price_selected_operator = $price instanceof EE_Price && $price->is_discount() ? '-' : '+'; |
|
1893 | + $price_selected_operator = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator; |
|
1894 | + $price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0; |
|
1895 | + $price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent; |
|
1896 | + $template_args = array( |
|
1897 | + 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
1898 | + 'PRC_order' => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row, |
|
1899 | + 'price_modifier_selector' => $select_input->get_html_for_input(), |
|
1900 | + 'main_name' => $select_name, |
|
1901 | + 'selected_price_type_id' => $selected_price_type_id, |
|
1902 | + 'price_option_spans' => $price_option_spans, |
|
1903 | + 'price_selected_operator' => $price_selected_operator, |
|
1904 | + 'price_selected_is_percent' => $price_selected_is_percent, |
|
1905 | + 'disabled' => $disabled, |
|
1906 | + ); |
|
1907 | + $template_args = apply_filters( |
|
1908 | + 'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args', |
|
1909 | + $template_args, |
|
1910 | + $ticket_row, |
|
1911 | + $price_row, |
|
1912 | + $price, |
|
1913 | + $default, |
|
1914 | + $disabled, |
|
1915 | + $this->_is_creating_event |
|
1916 | + ); |
|
1917 | + return EEH_Template::display_template( |
|
1918 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php', |
|
1919 | + $template_args, |
|
1920 | + true |
|
1921 | + ); |
|
1922 | + } |
|
1923 | + |
|
1924 | + |
|
1925 | + |
|
1926 | + /** |
|
1927 | + * @param int $datetime_row |
|
1928 | + * @param int $ticket_row |
|
1929 | + * @param EE_Datetime|null $datetime |
|
1930 | + * @param EE_Ticket|null $ticket |
|
1931 | + * @param array $ticket_datetimes |
|
1932 | + * @param bool $default |
|
1933 | + * @return mixed |
|
1934 | + * @throws DomainException |
|
1935 | + * @throws EE_Error |
|
1936 | + */ |
|
1937 | + protected function _get_ticket_datetime_list_item( |
|
1938 | + $datetime_row, |
|
1939 | + $ticket_row, |
|
1940 | + $datetime, |
|
1941 | + $ticket, |
|
1942 | + $ticket_datetimes = array(), |
|
1943 | + $default |
|
1944 | + ) { |
|
1945 | + $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) |
|
1946 | + ? $ticket_datetimes[$ticket->ID()] |
|
1947 | + : array(); |
|
1948 | + $template_args = array( |
|
1949 | + 'dtt_row' => $default && ! $datetime instanceof EE_Datetime |
|
1950 | + ? 'DTTNUM' |
|
1951 | + : $datetime_row, |
|
1952 | + 'tkt_row' => $default |
|
1953 | + ? 'TICKETNUM' |
|
1954 | + : $ticket_row, |
|
1955 | + 'ticket_datetime_selected' => in_array($datetime_row, $tkt_datetimes, true) |
|
1956 | + ? ' ticket-selected' |
|
1957 | + : '', |
|
1958 | + 'ticket_datetime_checked' => in_array($datetime_row, $tkt_datetimes, true) |
|
1959 | + ? ' checked="checked"' |
|
1960 | + : '', |
|
1961 | + 'DTT_name' => $default && empty($datetime) |
|
1962 | + ? 'DTTNAME' |
|
1963 | + : $datetime->get_dtt_display_name(true), |
|
1964 | + 'tkt_status_class' => '', |
|
1965 | + ); |
|
1966 | + $template_args = apply_filters( |
|
1967 | + 'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args', |
|
1968 | + $template_args, |
|
1969 | + $datetime_row, |
|
1970 | + $ticket_row, |
|
1971 | + $datetime, |
|
1972 | + $ticket, |
|
1973 | + $ticket_datetimes, |
|
1974 | + $default, |
|
1975 | + $this->_is_creating_event |
|
1976 | + ); |
|
1977 | + return EEH_Template::display_template( |
|
1978 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php', |
|
1979 | + $template_args, |
|
1980 | + true |
|
1981 | + ); |
|
1982 | + } |
|
1983 | + |
|
1984 | + |
|
1985 | + |
|
1986 | + /** |
|
1987 | + * @param array $all_datetimes |
|
1988 | + * @param array $all_tickets |
|
1989 | + * @return mixed |
|
1990 | + * @throws DomainException |
|
1991 | + * @throws EE_Error |
|
1992 | + */ |
|
1993 | + protected function _get_ticket_js_structure($all_datetimes = array(), $all_tickets = array()) |
|
1994 | + { |
|
1995 | + $template_args = array( |
|
1996 | + 'default_datetime_edit_row' => $this->_get_dtt_edit_row( |
|
1997 | + 'DTTNUM', |
|
1998 | + null, |
|
1999 | + true, |
|
2000 | + $all_datetimes |
|
2001 | + ), |
|
2002 | + 'default_ticket_row' => $this->_get_ticket_row( |
|
2003 | + 'TICKETNUM', |
|
2004 | + null, |
|
2005 | + array(), |
|
2006 | + array(), |
|
2007 | + true |
|
2008 | + ), |
|
2009 | + 'default_price_row' => $this->_get_ticket_price_row( |
|
2010 | + 'TICKETNUM', |
|
2011 | + 'PRICENUM', |
|
2012 | + null, |
|
2013 | + true, |
|
2014 | + null |
|
2015 | + ), |
|
2016 | + 'default_price_rows' => '', |
|
2017 | + 'default_base_price_amount' => 0, |
|
2018 | + 'default_base_price_name' => '', |
|
2019 | + 'default_base_price_description' => '', |
|
2020 | + 'default_price_modifier_selector_row' => $this->_get_price_modifier_template( |
|
2021 | + 'TICKETNUM', |
|
2022 | + 'PRICENUM', |
|
2023 | + null, |
|
2024 | + true |
|
2025 | + ), |
|
2026 | + 'default_available_tickets_for_datetime' => $this->_get_dtt_attached_tickets_row( |
|
2027 | + 'DTTNUM', |
|
2028 | + null, |
|
2029 | + array(), |
|
2030 | + array(), |
|
2031 | + true |
|
2032 | + ), |
|
2033 | + 'existing_available_datetime_tickets_list' => '', |
|
2034 | + 'existing_available_ticket_datetimes_list' => '', |
|
2035 | + 'new_available_datetime_ticket_list_item' => $this->_get_datetime_tickets_list_item( |
|
2036 | + 'DTTNUM', |
|
2037 | + 'TICKETNUM', |
|
2038 | + null, |
|
2039 | + null, |
|
2040 | + array(), |
|
2041 | + true |
|
2042 | + ), |
|
2043 | + 'new_available_ticket_datetime_list_item' => $this->_get_ticket_datetime_list_item( |
|
2044 | + 'DTTNUM', |
|
2045 | + 'TICKETNUM', |
|
2046 | + null, |
|
2047 | + null, |
|
2048 | + array(), |
|
2049 | + true |
|
2050 | + ), |
|
2051 | + ); |
|
2052 | + $ticket_row = 1; |
|
2053 | + foreach ($all_tickets as $ticket) { |
|
2054 | + $template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
|
2055 | + 'DTTNUM', |
|
2056 | + $ticket_row, |
|
2057 | + null, |
|
2058 | + $ticket, |
|
2059 | + array(), |
|
2060 | + true |
|
2061 | + ); |
|
2062 | + $ticket_row++; |
|
2063 | + } |
|
2064 | + $datetime_row = 1; |
|
2065 | + foreach ($all_datetimes as $datetime) { |
|
2066 | + $template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
|
2067 | + $datetime_row, |
|
2068 | + 'TICKETNUM', |
|
2069 | + $datetime, |
|
2070 | + null, |
|
2071 | + array(), |
|
2072 | + true |
|
2073 | + ); |
|
2074 | + $datetime_row++; |
|
2075 | + } |
|
2076 | + /** @var EEM_Price $price_model */ |
|
2077 | + $price_model = EE_Registry::instance()->load_model('Price'); |
|
2078 | + $default_prices = $price_model->get_all_default_prices(); |
|
2079 | + $price_row = 1; |
|
2080 | + foreach ($default_prices as $price) { |
|
2081 | + if (! $price instanceof EE_Price) { |
|
2082 | + continue; |
|
2083 | + } |
|
2084 | + if ($price->is_base_price()) { |
|
2085 | + $template_args['default_base_price_amount'] = $price->get_pretty( |
|
2086 | + 'PRC_amount', |
|
2087 | + 'localized_float' |
|
2088 | + ); |
|
2089 | + $template_args['default_base_price_name'] = $price->get('PRC_name'); |
|
2090 | + $template_args['default_base_price_description'] = $price->get('PRC_desc'); |
|
2091 | + $price_row++; |
|
2092 | + continue; |
|
2093 | + } |
|
2094 | + $show_trash = (count($default_prices) > 1 && $price_row === 1) || count($default_prices) === 1 |
|
2095 | + ? false |
|
2096 | + : true; |
|
2097 | + $show_create = count($default_prices) > 1 && count($default_prices) !== $price_row |
|
2098 | + ? false |
|
2099 | + : true; |
|
2100 | + $template_args['default_price_rows'] .= $this->_get_ticket_price_row( |
|
2101 | + 'TICKETNUM', |
|
2102 | + $price_row, |
|
2103 | + $price, |
|
2104 | + true, |
|
2105 | + null, |
|
2106 | + $show_trash, |
|
2107 | + $show_create |
|
2108 | + ); |
|
2109 | + $price_row++; |
|
2110 | + } |
|
2111 | + $template_args = apply_filters( |
|
2112 | + 'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args', |
|
2113 | + $template_args, |
|
2114 | + $all_datetimes, |
|
2115 | + $all_tickets, |
|
2116 | + $this->_is_creating_event |
|
2117 | + ); |
|
2118 | + return EEH_Template::display_template( |
|
2119 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php', |
|
2120 | + $template_args, |
|
2121 | + true |
|
2122 | + ); |
|
2123 | + } |
|
2124 | 2124 | |
2125 | 2125 | |
2126 | 2126 | } //end class espresso_events_Pricing_Hooks |
@@ -127,7 +127,7 @@ discard block |
||
127 | 127 | $this->_date_format_strings['time'] = isset($this->_date_format_strings['time']) |
128 | 128 | ? $this->_date_format_strings['time'] |
129 | 129 | : null; |
130 | - $this->_date_time_format = $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']; |
|
130 | + $this->_date_time_format = $this->_date_format_strings['date'].' '.$this->_date_format_strings['time']; |
|
131 | 131 | } |
132 | 132 | |
133 | 133 | |
@@ -152,7 +152,7 @@ discard block |
||
152 | 152 | ); |
153 | 153 | $msg .= '</p><ul>'; |
154 | 154 | foreach ($format_validation as $error) { |
155 | - $msg .= '<li>' . $error . '</li>'; |
|
155 | + $msg .= '<li>'.$error.'</li>'; |
|
156 | 156 | } |
157 | 157 | $msg .= '</ul><p>'; |
158 | 158 | $msg .= sprintf( |
@@ -182,11 +182,11 @@ discard block |
||
182 | 182 | $this->_scripts_styles = array( |
183 | 183 | 'registers' => array( |
184 | 184 | 'ee-tickets-datetimes-css' => array( |
185 | - 'url' => PRICING_ASSETS_URL . 'event-tickets-datetimes.css', |
|
185 | + 'url' => PRICING_ASSETS_URL.'event-tickets-datetimes.css', |
|
186 | 186 | 'type' => 'css', |
187 | 187 | ), |
188 | 188 | 'ee-dtt-ticket-metabox' => array( |
189 | - 'url' => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js', |
|
189 | + 'url' => PRICING_ASSETS_URL.'ee-datetime-ticket-metabox.js', |
|
190 | 190 | 'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'), |
191 | 191 | ), |
192 | 192 | ), |
@@ -210,9 +210,9 @@ discard block |
||
210 | 210 | 'event_espresso' |
211 | 211 | ), |
212 | 212 | 'cancel_button' => '<button class="button-secondary ee-modal-cancel">' |
213 | - . esc_html__('Cancel', 'event_espresso') . '</button>', |
|
213 | + . esc_html__('Cancel', 'event_espresso').'</button>', |
|
214 | 214 | 'close_button' => '<button class="button-secondary ee-modal-cancel">' |
215 | - . esc_html__('Close', 'event_espresso') . '</button>', |
|
215 | + . esc_html__('Close', 'event_espresso').'</button>', |
|
216 | 216 | 'single_warning_from_tkt' => esc_html__( |
217 | 217 | 'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.', |
218 | 218 | 'event_espresso' |
@@ -222,12 +222,12 @@ discard block |
||
222 | 222 | 'event_espresso' |
223 | 223 | ), |
224 | 224 | 'dismiss_button' => '<button class="button-secondary ee-modal-cancel">' |
225 | - . esc_html__('Dismiss', 'event_espresso') . '</button>', |
|
225 | + . esc_html__('Dismiss', 'event_espresso').'</button>', |
|
226 | 226 | ), |
227 | 227 | 'DTT_ERROR_MSG' => array( |
228 | 228 | 'no_ticket_name' => esc_html__('General Admission', 'event_espresso'), |
229 | 229 | 'dismiss_button' => '<div class="save-cancel-button-container"><button class="button-secondary ee-modal-cancel">' |
230 | - . esc_html__('Dismiss', 'event_espresso') . '</button></div>', |
|
230 | + . esc_html__('Dismiss', 'event_espresso').'</button></div>', |
|
231 | 231 | ), |
232 | 232 | 'DTT_OVERSELL_WARNING' => array( |
233 | 233 | 'datetime_ticket' => esc_html__( |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | $this->_date_format_strings['date'], |
244 | 244 | $this->_date_format_strings['time'] |
245 | 245 | ), |
246 | - 'DTT_START_OF_WEEK' => array('dayValue' => (int)get_option('start_of_week')), |
|
246 | + 'DTT_START_OF_WEEK' => array('dayValue' => (int) get_option('start_of_week')), |
|
247 | 247 | ), |
248 | 248 | ), |
249 | 249 | ); |
@@ -301,7 +301,7 @@ discard block |
||
301 | 301 | foreach ($data['edit_event_datetimes'] as $row => $datetime_data) { |
302 | 302 | //trim all values to ensure any excess whitespace is removed. |
303 | 303 | $datetime_data = array_map( |
304 | - function ($datetime_data) { |
|
304 | + function($datetime_data) { |
|
305 | 305 | return is_array($datetime_data) ? $datetime_data : trim($datetime_data); |
306 | 306 | }, |
307 | 307 | $datetime_data |
@@ -331,7 +331,7 @@ discard block |
||
331 | 331 | ); |
332 | 332 | // if we have an id then let's get existing object first and then set the new values. |
333 | 333 | // Otherwise we instantiate a new object for save. |
334 | - if (! empty($datetime_data['DTT_ID'])) { |
|
334 | + if ( ! empty($datetime_data['DTT_ID'])) { |
|
335 | 335 | $datetime = EE_Registry::instance() |
336 | 336 | ->load_model('Datetime', array($timezone)) |
337 | 337 | ->get_one_by_ID($datetime_data['DTT_ID']); |
@@ -435,7 +435,7 @@ discard block |
||
435 | 435 | $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows); |
436 | 436 | // trim inputs to ensure any excess whitespace is removed. |
437 | 437 | $tkt = array_map( |
438 | - function ($ticket_data) { |
|
438 | + function($ticket_data) { |
|
439 | 439 | return is_array($ticket_data) ? $ticket_data : trim($ticket_data); |
440 | 440 | }, |
441 | 441 | $tkt |
@@ -444,7 +444,7 @@ discard block |
||
444 | 444 | // because we're doing calculations prior to using the models. |
445 | 445 | // note incoming ['TKT_price'] value is already in standard notation (via js). |
446 | 446 | $ticket_price = isset($tkt['TKT_price']) |
447 | - ? round((float)$tkt['TKT_price'], 3) |
|
447 | + ? round((float) $tkt['TKT_price'], 3) |
|
448 | 448 | : 0; |
449 | 449 | //note incoming base price needs converted from localized value. |
450 | 450 | $base_price = isset($tkt['TKT_base_price']) |
@@ -592,7 +592,7 @@ discard block |
||
592 | 592 | //need to make sue that the TKT_price is accurate after saving the prices. |
593 | 593 | $ticket->ensure_TKT_Price_correct(); |
594 | 594 | //handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave. |
595 | - if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) { |
|
595 | + if ( ! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) { |
|
596 | 596 | $update_prices = true; |
597 | 597 | $new_default = clone $ticket; |
598 | 598 | $new_default->set('TKT_ID', 0); |
@@ -711,9 +711,9 @@ discard block |
||
711 | 711 | // to start we have to add the ticket to all the datetimes its supposed to be with, |
712 | 712 | // and removing the ticket from datetimes it got removed from. |
713 | 713 | // first let's add datetimes |
714 | - if (! empty($added_datetimes) && is_array($added_datetimes)) { |
|
714 | + if ( ! empty($added_datetimes) && is_array($added_datetimes)) { |
|
715 | 715 | foreach ($added_datetimes as $row_id) { |
716 | - $row_id = (int)$row_id; |
|
716 | + $row_id = (int) $row_id; |
|
717 | 717 | if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
718 | 718 | $ticket->_add_relation_to($saved_datetimes[$row_id], 'Datetime'); |
719 | 719 | // Is this an existing ticket (has an ID) and does it have any sold? |
@@ -726,9 +726,9 @@ discard block |
||
726 | 726 | } |
727 | 727 | } |
728 | 728 | // then remove datetimes |
729 | - if (! empty($removed_datetimes) && is_array($removed_datetimes)) { |
|
729 | + if ( ! empty($removed_datetimes) && is_array($removed_datetimes)) { |
|
730 | 730 | foreach ($removed_datetimes as $row_id) { |
731 | - $row_id = (int)$row_id; |
|
731 | + $row_id = (int) $row_id; |
|
732 | 732 | // its entirely possible that a datetime got deleted (instead of just removed from relationship. |
733 | 733 | // So make sure we skip over this if the dtt isn't in the $saved_datetimes array) |
734 | 734 | if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
@@ -838,7 +838,7 @@ discard block |
||
838 | 838 | ); |
839 | 839 | } |
840 | 840 | //possibly need to save tkt |
841 | - if (! $ticket->ID()) { |
|
841 | + if ( ! $ticket->ID()) { |
|
842 | 842 | $ticket->save(); |
843 | 843 | } |
844 | 844 | foreach ($prices as $row => $prc) { |
@@ -876,11 +876,11 @@ discard block |
||
876 | 876 | $ticket->_add_relation_to($price, 'Price'); |
877 | 877 | } |
878 | 878 | //now let's remove any prices that got removed from the ticket |
879 | - if (! empty ($current_prices_on_ticket)) { |
|
879 | + if ( ! empty ($current_prices_on_ticket)) { |
|
880 | 880 | $current = array_keys($current_prices_on_ticket); |
881 | 881 | $updated = array_keys($updated_prices); |
882 | 882 | $prices_to_remove = array_diff($current, $updated); |
883 | - if (! empty($prices_to_remove)) { |
|
883 | + if ( ! empty($prices_to_remove)) { |
|
884 | 884 | foreach ($prices_to_remove as $prc_id) { |
885 | 885 | $p = $current_prices_on_ticket[$prc_id]; |
886 | 886 | $ticket->_remove_relation_to($p, 'Price'); |
@@ -898,7 +898,7 @@ discard block |
||
898 | 898 | * @param Events_Admin_Page $event_admin_obj |
899 | 899 | * @return Events_Admin_Page |
900 | 900 | */ |
901 | - public function autosave_handling( Events_Admin_Page $event_admin_obj) |
|
901 | + public function autosave_handling(Events_Admin_Page $event_admin_obj) |
|
902 | 902 | { |
903 | 903 | return $event_admin_obj; |
904 | 904 | //doing nothing for the moment. |
@@ -1031,7 +1031,7 @@ discard block |
||
1031 | 1031 | $TKT_ID = $ticket->get('TKT_ID'); |
1032 | 1032 | $ticket_row = $ticket->get('TKT_row'); |
1033 | 1033 | //we only want unique tickets in our final display!! |
1034 | - if (! in_array($TKT_ID, $existing_ticket_ids, true)) { |
|
1034 | + if ( ! in_array($TKT_ID, $existing_ticket_ids, true)) { |
|
1035 | 1035 | $existing_ticket_ids[] = $TKT_ID; |
1036 | 1036 | $all_tickets[] = $ticket; |
1037 | 1037 | } |
@@ -1053,9 +1053,9 @@ discard block |
||
1053 | 1053 | //sort $all_tickets by order |
1054 | 1054 | usort( |
1055 | 1055 | $all_tickets, |
1056 | - function (EE_Ticket $a, EE_Ticket $b) { |
|
1057 | - $a_order = (int)$a->get('TKT_order'); |
|
1058 | - $b_order = (int)$b->get('TKT_order'); |
|
1056 | + function(EE_Ticket $a, EE_Ticket $b) { |
|
1057 | + $a_order = (int) $a->get('TKT_order'); |
|
1058 | + $b_order = (int) $b->get('TKT_order'); |
|
1059 | 1059 | if ($a_order === $b_order) { |
1060 | 1060 | return 0; |
1061 | 1061 | } |
@@ -1091,7 +1091,7 @@ discard block |
||
1091 | 1091 | } |
1092 | 1092 | $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets); |
1093 | 1093 | EEH_Template::display_template( |
1094 | - PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php', |
|
1094 | + PRICING_TEMPLATE_PATH.'event_tickets_metabox_main.template.php', |
|
1095 | 1095 | $main_template_args |
1096 | 1096 | ); |
1097 | 1097 | } |
@@ -1129,7 +1129,7 @@ discard block |
||
1129 | 1129 | 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
1130 | 1130 | ); |
1131 | 1131 | return EEH_Template::display_template( |
1132 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php', |
|
1132 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_row_wrapper.template.php', |
|
1133 | 1133 | $dtt_display_template_args, |
1134 | 1134 | true |
1135 | 1135 | ); |
@@ -1199,7 +1199,7 @@ discard block |
||
1199 | 1199 | $this->_is_creating_event |
1200 | 1200 | ); |
1201 | 1201 | return EEH_Template::display_template( |
1202 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php', |
|
1202 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_edit_row.template.php', |
|
1203 | 1203 | $template_args, |
1204 | 1204 | true |
1205 | 1205 | ); |
@@ -1241,7 +1241,7 @@ discard block |
||
1241 | 1241 | 'DTT_ID' => $default ? '' : $datetime->ID(), |
1242 | 1242 | ); |
1243 | 1243 | //need to setup the list items (but only if this isn't a default skeleton setup) |
1244 | - if (! $default) { |
|
1244 | + if ( ! $default) { |
|
1245 | 1245 | $ticket_row = 1; |
1246 | 1246 | foreach ($all_tickets as $ticket) { |
1247 | 1247 | $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
@@ -1267,7 +1267,7 @@ discard block |
||
1267 | 1267 | $this->_is_creating_event |
1268 | 1268 | ); |
1269 | 1269 | return EEH_Template::display_template( |
1270 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php', |
|
1270 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_attached_tickets_row.template.php', |
|
1271 | 1271 | $template_args, |
1272 | 1272 | true |
1273 | 1273 | ); |
@@ -1316,8 +1316,8 @@ discard block |
||
1316 | 1316 | ? 'TKTNAME' |
1317 | 1317 | : $ticket->get('TKT_name'), |
1318 | 1318 | 'tkt_status_class' => $no_ticket || $this->_is_creating_event |
1319 | - ? ' tkt-status-' . EE_Ticket::onsale |
|
1320 | - : ' tkt-status-' . $ticket->ticket_status(), |
|
1319 | + ? ' tkt-status-'.EE_Ticket::onsale |
|
1320 | + : ' tkt-status-'.$ticket->ticket_status(), |
|
1321 | 1321 | ); |
1322 | 1322 | //filter template args |
1323 | 1323 | $template_args = apply_filters( |
@@ -1332,7 +1332,7 @@ discard block |
||
1332 | 1332 | $this->_is_creating_event |
1333 | 1333 | ); |
1334 | 1334 | return EEH_Template::display_template( |
1335 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php', |
|
1335 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_dtt_tickets_list.template.php', |
|
1336 | 1336 | $template_args, |
1337 | 1337 | true |
1338 | 1338 | ); |
@@ -1389,11 +1389,11 @@ discard block |
||
1389 | 1389 | $count_price_mods = EEM_Price::instance()->get_all_default_prices(true); |
1390 | 1390 | //breaking out complicated condition for ticket_status |
1391 | 1391 | if ($default) { |
1392 | - $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale; |
|
1392 | + $ticket_status_class = ' tkt-status-'.EE_Ticket::onsale; |
|
1393 | 1393 | } else { |
1394 | 1394 | $ticket_status_class = $ticket->is_default() |
1395 | - ? ' tkt-status-' . EE_Ticket::onsale |
|
1396 | - : ' tkt-status-' . $ticket->ticket_status(); |
|
1395 | + ? ' tkt-status-'.EE_Ticket::onsale |
|
1396 | + : ' tkt-status-'.$ticket->ticket_status(); |
|
1397 | 1397 | } |
1398 | 1398 | //breaking out complicated condition for TKT_taxable |
1399 | 1399 | if ($default) { |
@@ -1487,7 +1487,7 @@ discard block |
||
1487 | 1487 | : ' style="display:none;"', |
1488 | 1488 | 'show_price_mod_button' => count($prices) > 1 |
1489 | 1489 | || ($default && $count_price_mods > 0) |
1490 | - || (! $default && $ticket->get('TKT_deleted')) |
|
1490 | + || ( ! $default && $ticket->get('TKT_deleted')) |
|
1491 | 1491 | ? ' style="display:none;"' |
1492 | 1492 | : '', |
1493 | 1493 | 'total_price_rows' => count($prices) > 1 ? count($prices) : 1, |
@@ -1529,7 +1529,7 @@ discard block |
||
1529 | 1529 | //if empty then the start date will be now. |
1530 | 1530 | $template_args['TKT_start_date'] = date($this->_date_time_format, |
1531 | 1531 | current_time('timestamp')); |
1532 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
1532 | + $template_args['tkt_status_class'] = ' tkt-status-'.EE_Ticket::onsale; |
|
1533 | 1533 | } |
1534 | 1534 | if (empty($template_args['TKT_end_date'])) { |
1535 | 1535 | //get the earliest datetime (if present); |
@@ -1539,7 +1539,7 @@ discard block |
||
1539 | 1539 | array('order_by' => array('DTT_EVT_start' => 'ASC')) |
1540 | 1540 | ) |
1541 | 1541 | : null; |
1542 | - if (! empty($earliest_dtt)) { |
|
1542 | + if ( ! empty($earliest_dtt)) { |
|
1543 | 1543 | $template_args['TKT_end_date'] = $earliest_dtt->get_datetime( |
1544 | 1544 | 'DTT_EVT_start', |
1545 | 1545 | $this->_date_time_format |
@@ -1552,10 +1552,10 @@ discard block |
||
1552 | 1552 | ) |
1553 | 1553 | ); |
1554 | 1554 | } |
1555 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
1555 | + $template_args['tkt_status_class'] = ' tkt-status-'.EE_Ticket::onsale; |
|
1556 | 1556 | } |
1557 | 1557 | //generate ticket_datetime items |
1558 | - if (! $default) { |
|
1558 | + if ( ! $default) { |
|
1559 | 1559 | $datetime_row = 1; |
1560 | 1560 | foreach ($all_datetimes as $datetime) { |
1561 | 1561 | $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
@@ -1601,7 +1601,7 @@ discard block |
||
1601 | 1601 | $this->_is_creating_event |
1602 | 1602 | ); |
1603 | 1603 | return EEH_Template::display_template( |
1604 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php', |
|
1604 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_row.template.php', |
|
1605 | 1605 | $template_args, |
1606 | 1606 | true |
1607 | 1607 | ); |
@@ -1641,7 +1641,7 @@ discard block |
||
1641 | 1641 | $this->_is_creating_event |
1642 | 1642 | ); |
1643 | 1643 | $tax_rows .= EEH_Template::display_template( |
1644 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php', |
|
1644 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_tax_row.template.php', |
|
1645 | 1645 | $template_args, |
1646 | 1646 | true |
1647 | 1647 | ); |
@@ -1755,7 +1755,7 @@ discard block |
||
1755 | 1755 | $this->_is_creating_event |
1756 | 1756 | ); |
1757 | 1757 | return EEH_Template::display_template( |
1758 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php', |
|
1758 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_price_row.template.php', |
|
1759 | 1759 | $template_args, |
1760 | 1760 | true |
1761 | 1761 | ); |
@@ -1812,7 +1812,7 @@ discard block |
||
1812 | 1812 | $this->_is_creating_event |
1813 | 1813 | ); |
1814 | 1814 | return EEH_Template::display_template( |
1815 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php', |
|
1815 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_type_base.template.php', |
|
1816 | 1816 | $template_args, |
1817 | 1817 | true |
1818 | 1818 | ); |
@@ -1839,7 +1839,7 @@ discard block |
||
1839 | 1839 | ) { |
1840 | 1840 | $select_name = $default && ! $price instanceof EE_Price |
1841 | 1841 | ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]' |
1842 | - : 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]'; |
|
1842 | + : 'edit_prices['.$ticket_row.']['.$price_row.'][PRT_ID]'; |
|
1843 | 1843 | /** @var EEM_Price_Type $price_type_model */ |
1844 | 1844 | $price_type_model = EE_Registry::instance()->load_model('Price_Type'); |
1845 | 1845 | $price_types = $price_type_model->get_all(array( |
@@ -1860,7 +1860,7 @@ discard block |
||
1860 | 1860 | $price_option_spans = ''; |
1861 | 1861 | //setup price types for selector |
1862 | 1862 | foreach ($price_types as $price_type) { |
1863 | - if (! $price_type instanceof EE_Price_Type) { |
|
1863 | + if ( ! $price_type instanceof EE_Price_Type) { |
|
1864 | 1864 | continue; |
1865 | 1865 | } |
1866 | 1866 | $all_price_types[] = array( |
@@ -1874,12 +1874,12 @@ discard block |
||
1874 | 1874 | 'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0, |
1875 | 1875 | ); |
1876 | 1876 | $price_option_spans .= EEH_Template::display_template( |
1877 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php', |
|
1877 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_option_span.template.php', |
|
1878 | 1878 | $span_args, |
1879 | 1879 | true |
1880 | 1880 | ); |
1881 | 1881 | } |
1882 | - $select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]' : $select_name; |
|
1882 | + $select_name = $disabled ? 'archive_price['.$ticket_row.']['.$price_row.'][PRT_ID]' : $select_name; |
|
1883 | 1883 | $select_input = new EE_Select_Input( |
1884 | 1884 | $all_price_types, |
1885 | 1885 | array( |
@@ -1915,7 +1915,7 @@ discard block |
||
1915 | 1915 | $this->_is_creating_event |
1916 | 1916 | ); |
1917 | 1917 | return EEH_Template::display_template( |
1918 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php', |
|
1918 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_modifier_selector.template.php', |
|
1919 | 1919 | $template_args, |
1920 | 1920 | true |
1921 | 1921 | ); |
@@ -1975,7 +1975,7 @@ discard block |
||
1975 | 1975 | $this->_is_creating_event |
1976 | 1976 | ); |
1977 | 1977 | return EEH_Template::display_template( |
1978 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php', |
|
1978 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_datetimes_list_item.template.php', |
|
1979 | 1979 | $template_args, |
1980 | 1980 | true |
1981 | 1981 | ); |
@@ -2078,7 +2078,7 @@ discard block |
||
2078 | 2078 | $default_prices = $price_model->get_all_default_prices(); |
2079 | 2079 | $price_row = 1; |
2080 | 2080 | foreach ($default_prices as $price) { |
2081 | - if (! $price instanceof EE_Price) { |
|
2081 | + if ( ! $price instanceof EE_Price) { |
|
2082 | 2082 | continue; |
2083 | 2083 | } |
2084 | 2084 | if ($price->is_base_price()) { |
@@ -2116,7 +2116,7 @@ discard block |
||
2116 | 2116 | $this->_is_creating_event |
2117 | 2117 | ); |
2118 | 2118 | return EEH_Template::display_template( |
2119 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php', |
|
2119 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_js_structure.template.php', |
|
2120 | 2120 | $template_args, |
2121 | 2121 | true |
2122 | 2122 | ); |
@@ -12,328 +12,328 @@ |
||
12 | 12 | class EEM_Ticket extends EEM_Soft_Delete_Base |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * private instance of the EEM_Ticket object |
|
17 | - * |
|
18 | - * @var EEM_Ticket $_instance |
|
19 | - */ |
|
20 | - protected static $_instance; |
|
15 | + /** |
|
16 | + * private instance of the EEM_Ticket object |
|
17 | + * |
|
18 | + * @var EEM_Ticket $_instance |
|
19 | + */ |
|
20 | + protected static $_instance; |
|
21 | 21 | |
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * private constructor to prevent direct creation |
|
26 | - * |
|
27 | - * @Constructor |
|
28 | - * @access private |
|
29 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings |
|
30 | - * (and any incoming timezone data that gets saved). |
|
31 | - * Note this just sends the timezone info to the date time model field objects. |
|
32 | - * Default is NULL |
|
33 | - * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
34 | - * @throws EE_Error |
|
35 | - */ |
|
36 | - protected function __construct($timezone) |
|
37 | - { |
|
38 | - $this->singular_item = esc_html__('Ticket', 'event_espresso'); |
|
39 | - $this->plural_item = esc_html__('Tickets', 'event_espresso'); |
|
40 | - $this->_tables = array( |
|
41 | - 'Ticket' => new EE_Primary_Table('esp_ticket', 'TKT_ID'), |
|
42 | - ); |
|
43 | - $this->_fields = array( |
|
44 | - 'Ticket' => array( |
|
45 | - 'TKT_ID' => new EE_Primary_Key_Int_Field( |
|
46 | - 'TKT_ID', |
|
47 | - esc_html__('Ticket ID', 'event_espresso') |
|
48 | - ), |
|
49 | - 'TTM_ID' => new EE_Foreign_Key_Int_Field( |
|
50 | - 'TTM_ID', |
|
51 | - esc_html__('Ticket Template ID', 'event_espresso'), |
|
52 | - false, |
|
53 | - 0, |
|
54 | - 'Ticket_Template' |
|
55 | - ), |
|
56 | - 'TKT_name' => new EE_Plain_Text_Field( |
|
57 | - 'TKT_name', |
|
58 | - esc_html__('Ticket Name', 'event_espresso'), |
|
59 | - false, |
|
60 | - '' |
|
61 | - ), |
|
62 | - 'TKT_description' => new EE_Post_Content_Field( |
|
63 | - 'TKT_description', |
|
64 | - esc_html__('Description of Ticket', 'event_espresso'), |
|
65 | - false, |
|
66 | - '' |
|
67 | - ), |
|
68 | - 'TKT_start_date' => new EE_Datetime_Field( |
|
69 | - 'TKT_start_date', |
|
70 | - esc_html__('Start time/date of Ticket', 'event_espresso'), |
|
71 | - false, |
|
72 | - EE_Datetime_Field::now, |
|
73 | - $timezone |
|
74 | - ), |
|
75 | - 'TKT_end_date' => new EE_Datetime_Field( |
|
76 | - 'TKT_end_date', |
|
77 | - esc_html__('End time/date of Ticket', 'event_espresso'), |
|
78 | - false, |
|
79 | - EE_Datetime_Field::now, |
|
80 | - $timezone |
|
81 | - ), |
|
82 | - 'TKT_min' => new EE_Integer_Field( |
|
83 | - 'TKT_min', |
|
84 | - esc_html__('Minimum quantity of this ticket that must be purchased', 'event_espresso'), |
|
85 | - false, |
|
86 | - 0 |
|
87 | - ), |
|
88 | - 'TKT_max' => new EE_Infinite_Integer_Field( |
|
89 | - 'TKT_max', |
|
90 | - esc_html__( |
|
91 | - 'Maximum quantity of this ticket that can be purchased in one transaction', |
|
92 | - 'event_espresso' |
|
93 | - ), |
|
94 | - false, |
|
95 | - EE_INF |
|
96 | - ), |
|
97 | - 'TKT_price' => new EE_Money_Field( |
|
98 | - 'TKT_price', |
|
99 | - esc_html__('Final calculated price for ticket', 'event_espresso'), |
|
100 | - false, |
|
101 | - 0 |
|
102 | - ), |
|
103 | - 'TKT_sold' => new EE_Integer_Field( |
|
104 | - 'TKT_sold', |
|
105 | - esc_html__('Number of this ticket sold', 'event_espresso'), |
|
106 | - false, |
|
107 | - 0 |
|
108 | - ), |
|
109 | - 'TKT_qty' => new EE_Infinite_Integer_Field( |
|
110 | - 'TKT_qty', |
|
111 | - esc_html__('Quantity of this ticket that is available', 'event_espresso'), |
|
112 | - false, |
|
113 | - EE_INF |
|
114 | - ), |
|
115 | - 'TKT_reserved' => new EE_Integer_Field( |
|
116 | - 'TKT_reserved', |
|
117 | - esc_html__( |
|
118 | - 'Quantity of this ticket that is reserved, but not yet fully purchased', |
|
119 | - 'event_espresso' |
|
120 | - ), |
|
121 | - false, |
|
122 | - 0 |
|
123 | - ), |
|
124 | - 'TKT_uses' => new EE_Infinite_Integer_Field( |
|
125 | - 'TKT_uses', |
|
126 | - esc_html__('Number of datetimes this ticket can be used at', 'event_espresso'), |
|
127 | - false, |
|
128 | - EE_INF |
|
129 | - ), |
|
130 | - 'TKT_required' => new EE_Boolean_Field( |
|
131 | - 'TKT_required', |
|
132 | - esc_html__( |
|
133 | - 'Flag indicating whether this ticket must be purchased with a transaction', |
|
134 | - 'event_espresso' |
|
135 | - ), |
|
136 | - false, |
|
137 | - false |
|
138 | - ), |
|
139 | - 'TKT_taxable' => new EE_Boolean_Field( |
|
140 | - 'TKT_taxable', |
|
141 | - esc_html__( |
|
142 | - 'Flag indicating whether there is tax applied on this ticket', |
|
143 | - 'event_espresso' |
|
144 | - ), |
|
145 | - false, |
|
146 | - false |
|
147 | - ), |
|
148 | - 'TKT_is_default' => new EE_Boolean_Field( |
|
149 | - 'TKT_is_default', |
|
150 | - esc_html__('Flag indicating that this ticket is a default ticket', 'event_espresso'), |
|
151 | - false, |
|
152 | - false |
|
153 | - ), |
|
154 | - 'TKT_order' => new EE_Integer_Field( |
|
155 | - 'TKT_order', |
|
156 | - esc_html__( |
|
157 | - 'The order in which the Ticket is displayed in the editor (used for autosaves when the form doesn\'t have the ticket ID yet)', |
|
158 | - 'event_espresso' |
|
159 | - ), |
|
160 | - false, |
|
161 | - 0 |
|
162 | - ), |
|
163 | - 'TKT_row' => new EE_Integer_Field( |
|
164 | - 'TKT_row', |
|
165 | - esc_html__('How tickets are displayed in the ui', 'event_espresso'), |
|
166 | - false, |
|
167 | - 0 |
|
168 | - ), |
|
169 | - 'TKT_deleted' => new EE_Trashed_Flag_Field( |
|
170 | - 'TKT_deleted', |
|
171 | - esc_html__('Flag indicating if this has been archived or not', 'event_espresso'), |
|
172 | - false, |
|
173 | - false |
|
174 | - ), |
|
175 | - 'TKT_wp_user' => new EE_WP_User_Field( |
|
176 | - 'TKT_wp_user', |
|
177 | - esc_html__('Ticket Creator ID', 'event_espresso'), |
|
178 | - false |
|
179 | - ), |
|
180 | - 'TKT_parent' => new EE_Integer_Field( |
|
181 | - 'TKT_parent', |
|
182 | - esc_html__( |
|
183 | - 'Indicates what TKT_ID is the parent of this TKT_ID (used in autosaves/revisions)', |
|
184 | - 'event_espresso' |
|
185 | - ), |
|
186 | - true, |
|
187 | - 0 |
|
188 | - ), |
|
189 | - ), |
|
190 | - ); |
|
191 | - $this->_model_relations = array( |
|
192 | - 'Datetime' => new EE_HABTM_Relation('Datetime_Ticket'), |
|
193 | - 'Datetime_Ticket' => new EE_Has_Many_Relation(), |
|
194 | - 'Price' => new EE_HABTM_Relation('Ticket_Price'), |
|
195 | - 'Ticket_Template' => new EE_Belongs_To_Relation(), |
|
196 | - 'Registration' => new EE_Has_Many_Relation(), |
|
197 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
198 | - ); |
|
199 | - //this model is generally available for reading |
|
200 | - $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Default_Public( |
|
201 | - 'TKT_is_default', |
|
202 | - 'Datetime.Event' |
|
203 | - ); |
|
204 | - //account for default tickets in the caps |
|
205 | - $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Default_Protected( |
|
206 | - 'TKT_is_default', |
|
207 | - 'Datetime.Event' |
|
208 | - ); |
|
209 | - $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Default_Protected( |
|
210 | - 'TKT_is_default', |
|
211 | - 'Datetime.Event' |
|
212 | - ); |
|
213 | - $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Default_Protected( |
|
214 | - 'TKT_is_default', |
|
215 | - 'Datetime.Event' |
|
216 | - ); |
|
217 | - parent::__construct($timezone); |
|
218 | - } |
|
24 | + /** |
|
25 | + * private constructor to prevent direct creation |
|
26 | + * |
|
27 | + * @Constructor |
|
28 | + * @access private |
|
29 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings |
|
30 | + * (and any incoming timezone data that gets saved). |
|
31 | + * Note this just sends the timezone info to the date time model field objects. |
|
32 | + * Default is NULL |
|
33 | + * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
34 | + * @throws EE_Error |
|
35 | + */ |
|
36 | + protected function __construct($timezone) |
|
37 | + { |
|
38 | + $this->singular_item = esc_html__('Ticket', 'event_espresso'); |
|
39 | + $this->plural_item = esc_html__('Tickets', 'event_espresso'); |
|
40 | + $this->_tables = array( |
|
41 | + 'Ticket' => new EE_Primary_Table('esp_ticket', 'TKT_ID'), |
|
42 | + ); |
|
43 | + $this->_fields = array( |
|
44 | + 'Ticket' => array( |
|
45 | + 'TKT_ID' => new EE_Primary_Key_Int_Field( |
|
46 | + 'TKT_ID', |
|
47 | + esc_html__('Ticket ID', 'event_espresso') |
|
48 | + ), |
|
49 | + 'TTM_ID' => new EE_Foreign_Key_Int_Field( |
|
50 | + 'TTM_ID', |
|
51 | + esc_html__('Ticket Template ID', 'event_espresso'), |
|
52 | + false, |
|
53 | + 0, |
|
54 | + 'Ticket_Template' |
|
55 | + ), |
|
56 | + 'TKT_name' => new EE_Plain_Text_Field( |
|
57 | + 'TKT_name', |
|
58 | + esc_html__('Ticket Name', 'event_espresso'), |
|
59 | + false, |
|
60 | + '' |
|
61 | + ), |
|
62 | + 'TKT_description' => new EE_Post_Content_Field( |
|
63 | + 'TKT_description', |
|
64 | + esc_html__('Description of Ticket', 'event_espresso'), |
|
65 | + false, |
|
66 | + '' |
|
67 | + ), |
|
68 | + 'TKT_start_date' => new EE_Datetime_Field( |
|
69 | + 'TKT_start_date', |
|
70 | + esc_html__('Start time/date of Ticket', 'event_espresso'), |
|
71 | + false, |
|
72 | + EE_Datetime_Field::now, |
|
73 | + $timezone |
|
74 | + ), |
|
75 | + 'TKT_end_date' => new EE_Datetime_Field( |
|
76 | + 'TKT_end_date', |
|
77 | + esc_html__('End time/date of Ticket', 'event_espresso'), |
|
78 | + false, |
|
79 | + EE_Datetime_Field::now, |
|
80 | + $timezone |
|
81 | + ), |
|
82 | + 'TKT_min' => new EE_Integer_Field( |
|
83 | + 'TKT_min', |
|
84 | + esc_html__('Minimum quantity of this ticket that must be purchased', 'event_espresso'), |
|
85 | + false, |
|
86 | + 0 |
|
87 | + ), |
|
88 | + 'TKT_max' => new EE_Infinite_Integer_Field( |
|
89 | + 'TKT_max', |
|
90 | + esc_html__( |
|
91 | + 'Maximum quantity of this ticket that can be purchased in one transaction', |
|
92 | + 'event_espresso' |
|
93 | + ), |
|
94 | + false, |
|
95 | + EE_INF |
|
96 | + ), |
|
97 | + 'TKT_price' => new EE_Money_Field( |
|
98 | + 'TKT_price', |
|
99 | + esc_html__('Final calculated price for ticket', 'event_espresso'), |
|
100 | + false, |
|
101 | + 0 |
|
102 | + ), |
|
103 | + 'TKT_sold' => new EE_Integer_Field( |
|
104 | + 'TKT_sold', |
|
105 | + esc_html__('Number of this ticket sold', 'event_espresso'), |
|
106 | + false, |
|
107 | + 0 |
|
108 | + ), |
|
109 | + 'TKT_qty' => new EE_Infinite_Integer_Field( |
|
110 | + 'TKT_qty', |
|
111 | + esc_html__('Quantity of this ticket that is available', 'event_espresso'), |
|
112 | + false, |
|
113 | + EE_INF |
|
114 | + ), |
|
115 | + 'TKT_reserved' => new EE_Integer_Field( |
|
116 | + 'TKT_reserved', |
|
117 | + esc_html__( |
|
118 | + 'Quantity of this ticket that is reserved, but not yet fully purchased', |
|
119 | + 'event_espresso' |
|
120 | + ), |
|
121 | + false, |
|
122 | + 0 |
|
123 | + ), |
|
124 | + 'TKT_uses' => new EE_Infinite_Integer_Field( |
|
125 | + 'TKT_uses', |
|
126 | + esc_html__('Number of datetimes this ticket can be used at', 'event_espresso'), |
|
127 | + false, |
|
128 | + EE_INF |
|
129 | + ), |
|
130 | + 'TKT_required' => new EE_Boolean_Field( |
|
131 | + 'TKT_required', |
|
132 | + esc_html__( |
|
133 | + 'Flag indicating whether this ticket must be purchased with a transaction', |
|
134 | + 'event_espresso' |
|
135 | + ), |
|
136 | + false, |
|
137 | + false |
|
138 | + ), |
|
139 | + 'TKT_taxable' => new EE_Boolean_Field( |
|
140 | + 'TKT_taxable', |
|
141 | + esc_html__( |
|
142 | + 'Flag indicating whether there is tax applied on this ticket', |
|
143 | + 'event_espresso' |
|
144 | + ), |
|
145 | + false, |
|
146 | + false |
|
147 | + ), |
|
148 | + 'TKT_is_default' => new EE_Boolean_Field( |
|
149 | + 'TKT_is_default', |
|
150 | + esc_html__('Flag indicating that this ticket is a default ticket', 'event_espresso'), |
|
151 | + false, |
|
152 | + false |
|
153 | + ), |
|
154 | + 'TKT_order' => new EE_Integer_Field( |
|
155 | + 'TKT_order', |
|
156 | + esc_html__( |
|
157 | + 'The order in which the Ticket is displayed in the editor (used for autosaves when the form doesn\'t have the ticket ID yet)', |
|
158 | + 'event_espresso' |
|
159 | + ), |
|
160 | + false, |
|
161 | + 0 |
|
162 | + ), |
|
163 | + 'TKT_row' => new EE_Integer_Field( |
|
164 | + 'TKT_row', |
|
165 | + esc_html__('How tickets are displayed in the ui', 'event_espresso'), |
|
166 | + false, |
|
167 | + 0 |
|
168 | + ), |
|
169 | + 'TKT_deleted' => new EE_Trashed_Flag_Field( |
|
170 | + 'TKT_deleted', |
|
171 | + esc_html__('Flag indicating if this has been archived or not', 'event_espresso'), |
|
172 | + false, |
|
173 | + false |
|
174 | + ), |
|
175 | + 'TKT_wp_user' => new EE_WP_User_Field( |
|
176 | + 'TKT_wp_user', |
|
177 | + esc_html__('Ticket Creator ID', 'event_espresso'), |
|
178 | + false |
|
179 | + ), |
|
180 | + 'TKT_parent' => new EE_Integer_Field( |
|
181 | + 'TKT_parent', |
|
182 | + esc_html__( |
|
183 | + 'Indicates what TKT_ID is the parent of this TKT_ID (used in autosaves/revisions)', |
|
184 | + 'event_espresso' |
|
185 | + ), |
|
186 | + true, |
|
187 | + 0 |
|
188 | + ), |
|
189 | + ), |
|
190 | + ); |
|
191 | + $this->_model_relations = array( |
|
192 | + 'Datetime' => new EE_HABTM_Relation('Datetime_Ticket'), |
|
193 | + 'Datetime_Ticket' => new EE_Has_Many_Relation(), |
|
194 | + 'Price' => new EE_HABTM_Relation('Ticket_Price'), |
|
195 | + 'Ticket_Template' => new EE_Belongs_To_Relation(), |
|
196 | + 'Registration' => new EE_Has_Many_Relation(), |
|
197 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
198 | + ); |
|
199 | + //this model is generally available for reading |
|
200 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Default_Public( |
|
201 | + 'TKT_is_default', |
|
202 | + 'Datetime.Event' |
|
203 | + ); |
|
204 | + //account for default tickets in the caps |
|
205 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Default_Protected( |
|
206 | + 'TKT_is_default', |
|
207 | + 'Datetime.Event' |
|
208 | + ); |
|
209 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Default_Protected( |
|
210 | + 'TKT_is_default', |
|
211 | + 'Datetime.Event' |
|
212 | + ); |
|
213 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Default_Protected( |
|
214 | + 'TKT_is_default', |
|
215 | + 'Datetime.Event' |
|
216 | + ); |
|
217 | + parent::__construct($timezone); |
|
218 | + } |
|
219 | 219 | |
220 | 220 | |
221 | 221 | |
222 | - /** |
|
223 | - * This returns all tickets that are defaults from the db |
|
224 | - * |
|
225 | - * @return EE_Ticket[] |
|
226 | - * @throws EE_Error |
|
227 | - */ |
|
228 | - public function get_all_default_tickets() |
|
229 | - { |
|
230 | - /** @type EE_Ticket[] $tickets */ |
|
231 | - $tickets = $this->get_all(array(array('TKT_is_default' => 1), 'order_by' => array('TKT_ID' => 'ASC'))); |
|
232 | - //we need to set the start date and end date to today's date and the start of the default dtt |
|
233 | - return $this->_set_default_dates($tickets); |
|
234 | - } |
|
222 | + /** |
|
223 | + * This returns all tickets that are defaults from the db |
|
224 | + * |
|
225 | + * @return EE_Ticket[] |
|
226 | + * @throws EE_Error |
|
227 | + */ |
|
228 | + public function get_all_default_tickets() |
|
229 | + { |
|
230 | + /** @type EE_Ticket[] $tickets */ |
|
231 | + $tickets = $this->get_all(array(array('TKT_is_default' => 1), 'order_by' => array('TKT_ID' => 'ASC'))); |
|
232 | + //we need to set the start date and end date to today's date and the start of the default dtt |
|
233 | + return $this->_set_default_dates($tickets); |
|
234 | + } |
|
235 | 235 | |
236 | 236 | |
237 | 237 | |
238 | - /** |
|
239 | - * sets up relevant start and end date for EE_Ticket (s) |
|
240 | - * |
|
241 | - * @param EE_Ticket[] $tickets |
|
242 | - * @return EE_Ticket[] |
|
243 | - * @throws EE_Error |
|
244 | - */ |
|
245 | - private function _set_default_dates($tickets) |
|
246 | - { |
|
247 | - foreach ($tickets as $ticket) { |
|
248 | - $ticket->set( |
|
249 | - 'TKT_start_date', |
|
250 | - (int)$this->current_time_for_query('TKT_start_date', true) |
|
251 | - ); |
|
252 | - $ticket->set( |
|
253 | - 'TKT_end_date', |
|
254 | - (int)$this->current_time_for_query('TKT_end_date', true) + MONTH_IN_SECONDS |
|
255 | - ); |
|
256 | - $ticket->set_end_time( |
|
257 | - $this->convert_datetime_for_query( |
|
258 | - 'TKT_end_date', |
|
259 | - '11:59 pm', |
|
260 | - 'g:i a', $this->_timezone |
|
261 | - ) |
|
262 | - ); |
|
263 | - } |
|
264 | - return $tickets; |
|
265 | - } |
|
238 | + /** |
|
239 | + * sets up relevant start and end date for EE_Ticket (s) |
|
240 | + * |
|
241 | + * @param EE_Ticket[] $tickets |
|
242 | + * @return EE_Ticket[] |
|
243 | + * @throws EE_Error |
|
244 | + */ |
|
245 | + private function _set_default_dates($tickets) |
|
246 | + { |
|
247 | + foreach ($tickets as $ticket) { |
|
248 | + $ticket->set( |
|
249 | + 'TKT_start_date', |
|
250 | + (int)$this->current_time_for_query('TKT_start_date', true) |
|
251 | + ); |
|
252 | + $ticket->set( |
|
253 | + 'TKT_end_date', |
|
254 | + (int)$this->current_time_for_query('TKT_end_date', true) + MONTH_IN_SECONDS |
|
255 | + ); |
|
256 | + $ticket->set_end_time( |
|
257 | + $this->convert_datetime_for_query( |
|
258 | + 'TKT_end_date', |
|
259 | + '11:59 pm', |
|
260 | + 'g:i a', $this->_timezone |
|
261 | + ) |
|
262 | + ); |
|
263 | + } |
|
264 | + return $tickets; |
|
265 | + } |
|
266 | 266 | |
267 | 267 | |
268 | 268 | |
269 | - /** |
|
270 | - * Gets the total number of tickets available at a particular datetime (does |
|
271 | - * NOT take int account the datetime's spaces available) |
|
272 | - * |
|
273 | - * @param int $DTT_ID |
|
274 | - * @param array $query_params |
|
275 | - * @return int |
|
276 | - */ |
|
277 | - public function sum_tickets_currently_available_at_datetime($DTT_ID, $query_params = array()) |
|
278 | - { |
|
279 | - return EEM_Datetime::instance()->sum_tickets_currently_available_at_datetime($DTT_ID, $query_params); |
|
280 | - } |
|
269 | + /** |
|
270 | + * Gets the total number of tickets available at a particular datetime (does |
|
271 | + * NOT take int account the datetime's spaces available) |
|
272 | + * |
|
273 | + * @param int $DTT_ID |
|
274 | + * @param array $query_params |
|
275 | + * @return int |
|
276 | + */ |
|
277 | + public function sum_tickets_currently_available_at_datetime($DTT_ID, $query_params = array()) |
|
278 | + { |
|
279 | + return EEM_Datetime::instance()->sum_tickets_currently_available_at_datetime($DTT_ID, $query_params); |
|
280 | + } |
|
281 | 281 | |
282 | 282 | |
283 | 283 | |
284 | - /** |
|
285 | - * Updates the TKT_sold quantity on all the tickets matching $query_params |
|
286 | - * |
|
287 | - * @param EE_Ticket[] $tickets |
|
288 | - * @return void |
|
289 | - * @throws EE_Error |
|
290 | - */ |
|
291 | - public function update_tickets_sold($tickets) |
|
292 | - { |
|
293 | - foreach ($tickets as $ticket) { |
|
294 | - /* @var $ticket EE_Ticket */ |
|
295 | - $ticket->update_tickets_sold(); |
|
296 | - } |
|
297 | - } |
|
284 | + /** |
|
285 | + * Updates the TKT_sold quantity on all the tickets matching $query_params |
|
286 | + * |
|
287 | + * @param EE_Ticket[] $tickets |
|
288 | + * @return void |
|
289 | + * @throws EE_Error |
|
290 | + */ |
|
291 | + public function update_tickets_sold($tickets) |
|
292 | + { |
|
293 | + foreach ($tickets as $ticket) { |
|
294 | + /* @var $ticket EE_Ticket */ |
|
295 | + $ticket->update_tickets_sold(); |
|
296 | + } |
|
297 | + } |
|
298 | 298 | |
299 | 299 | |
300 | 300 | |
301 | - /** |
|
302 | - * returns an array of EE_Ticket objects with a non-zero value for TKT_reserved |
|
303 | - * |
|
304 | - * @return EE_Base_Class[]|EE_Ticket[] |
|
305 | - * @throws EE_Error |
|
306 | - */ |
|
307 | - public function get_tickets_with_reservations() |
|
308 | - { |
|
309 | - return $this->get_all( |
|
310 | - array( |
|
311 | - array( |
|
312 | - 'TKT_reserved' => array('>', 0), |
|
313 | - ), |
|
314 | - ) |
|
315 | - ); |
|
316 | - } |
|
301 | + /** |
|
302 | + * returns an array of EE_Ticket objects with a non-zero value for TKT_reserved |
|
303 | + * |
|
304 | + * @return EE_Base_Class[]|EE_Ticket[] |
|
305 | + * @throws EE_Error |
|
306 | + */ |
|
307 | + public function get_tickets_with_reservations() |
|
308 | + { |
|
309 | + return $this->get_all( |
|
310 | + array( |
|
311 | + array( |
|
312 | + 'TKT_reserved' => array('>', 0), |
|
313 | + ), |
|
314 | + ) |
|
315 | + ); |
|
316 | + } |
|
317 | 317 | |
318 | 318 | |
319 | 319 | |
320 | - /** |
|
321 | - * returns an array of EE_Ticket objects matching the supplied list of IDs |
|
322 | - * |
|
323 | - * @param array $ticket_IDs |
|
324 | - * @return EE_Base_Class[]|EE_Ticket[] |
|
325 | - * @throws EE_Error |
|
326 | - */ |
|
327 | - public function get_tickets_with_IDs(array $ticket_IDs) |
|
328 | - { |
|
329 | - return $this->get_all( |
|
330 | - array( |
|
331 | - array( |
|
332 | - 'TKT_ID' => array('IN', $ticket_IDs) |
|
333 | - ) |
|
334 | - ) |
|
335 | - ); |
|
336 | - } |
|
320 | + /** |
|
321 | + * returns an array of EE_Ticket objects matching the supplied list of IDs |
|
322 | + * |
|
323 | + * @param array $ticket_IDs |
|
324 | + * @return EE_Base_Class[]|EE_Ticket[] |
|
325 | + * @throws EE_Error |
|
326 | + */ |
|
327 | + public function get_tickets_with_IDs(array $ticket_IDs) |
|
328 | + { |
|
329 | + return $this->get_all( |
|
330 | + array( |
|
331 | + array( |
|
332 | + 'TKT_ID' => array('IN', $ticket_IDs) |
|
333 | + ) |
|
334 | + ) |
|
335 | + ); |
|
336 | + } |
|
337 | 337 | |
338 | 338 | |
339 | 339 |
@@ -247,11 +247,11 @@ |
||
247 | 247 | foreach ($tickets as $ticket) { |
248 | 248 | $ticket->set( |
249 | 249 | 'TKT_start_date', |
250 | - (int)$this->current_time_for_query('TKT_start_date', true) |
|
250 | + (int) $this->current_time_for_query('TKT_start_date', true) |
|
251 | 251 | ); |
252 | 252 | $ticket->set( |
253 | 253 | 'TKT_end_date', |
254 | - (int)$this->current_time_for_query('TKT_end_date', true) + MONTH_IN_SECONDS |
|
254 | + (int) $this->current_time_for_query('TKT_end_date', true) + MONTH_IN_SECONDS |
|
255 | 255 | ); |
256 | 256 | $ticket->set_end_time( |
257 | 257 | $this->convert_datetime_for_query( |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('ABSPATH')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /* |
5 | 5 | Plugin Name: Event Espresso |
@@ -40,243 +40,243 @@ discard block |
||
40 | 40 | * @since 4.0 |
41 | 41 | */ |
42 | 42 | if (function_exists('espresso_version')) { |
43 | - /** |
|
44 | - * espresso_duplicate_plugin_error |
|
45 | - * displays if more than one version of EE is activated at the same time |
|
46 | - */ |
|
47 | - function espresso_duplicate_plugin_error() |
|
48 | - { |
|
49 | - ?> |
|
43 | + /** |
|
44 | + * espresso_duplicate_plugin_error |
|
45 | + * displays if more than one version of EE is activated at the same time |
|
46 | + */ |
|
47 | + function espresso_duplicate_plugin_error() |
|
48 | + { |
|
49 | + ?> |
|
50 | 50 | <div class="error"> |
51 | 51 | <p> |
52 | 52 | <?php echo esc_html__( |
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | 61 | |
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
65 | - if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
65 | + if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - /** |
|
97 | - * espresso_version |
|
98 | - * Returns the plugin version |
|
99 | - * |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - function espresso_version() |
|
103 | - { |
|
104 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.39.rc.012'); |
|
105 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + /** |
|
97 | + * espresso_version |
|
98 | + * Returns the plugin version |
|
99 | + * |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + function espresso_version() |
|
103 | + { |
|
104 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.39.rc.012'); |
|
105 | + } |
|
106 | 106 | |
107 | - // define versions |
|
108 | - define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | - define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | - define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | - define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | - //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | - if ( ! defined('DS')) { |
|
115 | - define('DS', '/'); |
|
116 | - } |
|
117 | - if ( ! defined('PS')) { |
|
118 | - define('PS', PATH_SEPARATOR); |
|
119 | - } |
|
120 | - if ( ! defined('SP')) { |
|
121 | - define('SP', ' '); |
|
122 | - } |
|
123 | - if ( ! defined('EENL')) { |
|
124 | - define('EENL', "\n"); |
|
125 | - } |
|
126 | - define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | - // define the plugin directory and URL |
|
128 | - define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | - define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | - define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | - // main root folder paths |
|
132 | - define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | - define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | - define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | - define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | - define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | - define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | - define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | - define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | - // core system paths |
|
141 | - define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | - define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | - define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | - define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | - define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | - define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | - define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | - define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | - define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | - define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | - define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | - define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | - // gateways |
|
154 | - define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | - define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | - // asset URL paths |
|
157 | - define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | - define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | - define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | - define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | - define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | - define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | - // define upload paths |
|
164 | - $uploads = wp_upload_dir(); |
|
165 | - // define the uploads directory and URL |
|
166 | - define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | - define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | - // define the templates directory and URL |
|
169 | - define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | - define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | - // define the gateway directory and URL |
|
172 | - define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | - define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | - // languages folder/path |
|
175 | - define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | - define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | - //check for dompdf fonts in uploads |
|
178 | - if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | - } |
|
181 | - //ajax constants |
|
182 | - define( |
|
183 | - 'EE_FRONT_AJAX', |
|
184 | - isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | - ); |
|
186 | - define( |
|
187 | - 'EE_ADMIN_AJAX', |
|
188 | - isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | - ); |
|
190 | - //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | - //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | - //want to change its default value! or find when -1 means infinity |
|
193 | - define('EE_INF_IN_DB', -1); |
|
194 | - define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | - define('EE_DEBUG', false); |
|
196 | - // for older WP versions |
|
197 | - if ( ! defined('MONTH_IN_SECONDS')) { |
|
198 | - define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
199 | - } |
|
200 | - /** |
|
201 | - * espresso_plugin_activation |
|
202 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
203 | - */ |
|
204 | - function espresso_plugin_activation() |
|
205 | - { |
|
206 | - update_option('ee_espresso_activation', true); |
|
207 | - } |
|
107 | + // define versions |
|
108 | + define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | + define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | + define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | + define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | + //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | + if ( ! defined('DS')) { |
|
115 | + define('DS', '/'); |
|
116 | + } |
|
117 | + if ( ! defined('PS')) { |
|
118 | + define('PS', PATH_SEPARATOR); |
|
119 | + } |
|
120 | + if ( ! defined('SP')) { |
|
121 | + define('SP', ' '); |
|
122 | + } |
|
123 | + if ( ! defined('EENL')) { |
|
124 | + define('EENL', "\n"); |
|
125 | + } |
|
126 | + define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | + // define the plugin directory and URL |
|
128 | + define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | + define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | + define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | + // main root folder paths |
|
132 | + define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | + define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | + define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | + define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | + define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | + define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | + define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | + define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | + // core system paths |
|
141 | + define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | + define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | + define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | + define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | + define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | + define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | + define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | + define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | + define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | + define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | + define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | + define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | + // gateways |
|
154 | + define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | + define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | + // asset URL paths |
|
157 | + define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | + define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | + define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | + define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | + define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | + define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | + // define upload paths |
|
164 | + $uploads = wp_upload_dir(); |
|
165 | + // define the uploads directory and URL |
|
166 | + define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | + define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | + // define the templates directory and URL |
|
169 | + define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | + define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | + // define the gateway directory and URL |
|
172 | + define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | + define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | + // languages folder/path |
|
175 | + define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | + define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | + //check for dompdf fonts in uploads |
|
178 | + if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | + } |
|
181 | + //ajax constants |
|
182 | + define( |
|
183 | + 'EE_FRONT_AJAX', |
|
184 | + isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | + ); |
|
186 | + define( |
|
187 | + 'EE_ADMIN_AJAX', |
|
188 | + isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | + ); |
|
190 | + //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | + //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | + //want to change its default value! or find when -1 means infinity |
|
193 | + define('EE_INF_IN_DB', -1); |
|
194 | + define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | + define('EE_DEBUG', false); |
|
196 | + // for older WP versions |
|
197 | + if ( ! defined('MONTH_IN_SECONDS')) { |
|
198 | + define('MONTH_IN_SECONDS', DAY_IN_SECONDS * 30); |
|
199 | + } |
|
200 | + /** |
|
201 | + * espresso_plugin_activation |
|
202 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
203 | + */ |
|
204 | + function espresso_plugin_activation() |
|
205 | + { |
|
206 | + update_option('ee_espresso_activation', true); |
|
207 | + } |
|
208 | 208 | |
209 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
210 | - /** |
|
211 | - * espresso_load_error_handling |
|
212 | - * this function loads EE's class for handling exceptions and errors |
|
213 | - */ |
|
214 | - function espresso_load_error_handling() |
|
215 | - { |
|
216 | - // load debugging tools |
|
217 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
218 | - require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
219 | - EEH_Debug_Tools::instance(); |
|
220 | - } |
|
221 | - // load error handling |
|
222 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
223 | - require_once(EE_CORE . 'EE_Error.core.php'); |
|
224 | - } else { |
|
225 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
226 | - } |
|
227 | - } |
|
209 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
210 | + /** |
|
211 | + * espresso_load_error_handling |
|
212 | + * this function loads EE's class for handling exceptions and errors |
|
213 | + */ |
|
214 | + function espresso_load_error_handling() |
|
215 | + { |
|
216 | + // load debugging tools |
|
217 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
218 | + require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
219 | + EEH_Debug_Tools::instance(); |
|
220 | + } |
|
221 | + // load error handling |
|
222 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
223 | + require_once(EE_CORE . 'EE_Error.core.php'); |
|
224 | + } else { |
|
225 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
226 | + } |
|
227 | + } |
|
228 | 228 | |
229 | - /** |
|
230 | - * espresso_load_required |
|
231 | - * given a class name and path, this function will load that file or throw an exception |
|
232 | - * |
|
233 | - * @param string $classname |
|
234 | - * @param string $full_path_to_file |
|
235 | - * @throws EE_Error |
|
236 | - */ |
|
237 | - function espresso_load_required($classname, $full_path_to_file) |
|
238 | - { |
|
239 | - static $error_handling_loaded = false; |
|
240 | - if ( ! $error_handling_loaded) { |
|
241 | - espresso_load_error_handling(); |
|
242 | - $error_handling_loaded = true; |
|
243 | - } |
|
244 | - if (is_readable($full_path_to_file)) { |
|
245 | - require_once($full_path_to_file); |
|
246 | - } else { |
|
247 | - throw new EE_Error ( |
|
248 | - sprintf( |
|
249 | - esc_html__( |
|
250 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
251 | - 'event_espresso' |
|
252 | - ), |
|
253 | - $classname |
|
254 | - ) |
|
255 | - ); |
|
256 | - } |
|
257 | - } |
|
229 | + /** |
|
230 | + * espresso_load_required |
|
231 | + * given a class name and path, this function will load that file or throw an exception |
|
232 | + * |
|
233 | + * @param string $classname |
|
234 | + * @param string $full_path_to_file |
|
235 | + * @throws EE_Error |
|
236 | + */ |
|
237 | + function espresso_load_required($classname, $full_path_to_file) |
|
238 | + { |
|
239 | + static $error_handling_loaded = false; |
|
240 | + if ( ! $error_handling_loaded) { |
|
241 | + espresso_load_error_handling(); |
|
242 | + $error_handling_loaded = true; |
|
243 | + } |
|
244 | + if (is_readable($full_path_to_file)) { |
|
245 | + require_once($full_path_to_file); |
|
246 | + } else { |
|
247 | + throw new EE_Error ( |
|
248 | + sprintf( |
|
249 | + esc_html__( |
|
250 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
251 | + 'event_espresso' |
|
252 | + ), |
|
253 | + $classname |
|
254 | + ) |
|
255 | + ); |
|
256 | + } |
|
257 | + } |
|
258 | 258 | |
259 | - espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
260 | - espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
261 | - espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
262 | - new EE_Bootstrap(); |
|
263 | - } |
|
259 | + espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
260 | + espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
261 | + espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
262 | + new EE_Bootstrap(); |
|
263 | + } |
|
264 | 264 | } |
265 | 265 | if ( ! function_exists('espresso_deactivate_plugin')) { |
266 | - /** |
|
267 | - * deactivate_plugin |
|
268 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
269 | - * |
|
270 | - * @access public |
|
271 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
272 | - * @return void |
|
273 | - */ |
|
274 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
275 | - { |
|
276 | - if ( ! function_exists('deactivate_plugins')) { |
|
277 | - require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
278 | - } |
|
279 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
280 | - deactivate_plugins($plugin_basename); |
|
281 | - } |
|
266 | + /** |
|
267 | + * deactivate_plugin |
|
268 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
269 | + * |
|
270 | + * @access public |
|
271 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
272 | + * @return void |
|
273 | + */ |
|
274 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
275 | + { |
|
276 | + if ( ! function_exists('deactivate_plugins')) { |
|
277 | + require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
278 | + } |
|
279 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
280 | + deactivate_plugins($plugin_basename); |
|
281 | + } |
|
282 | 282 | } |
283 | 283 | \ No newline at end of file |