@@ -23,1703 +23,1703 @@ |
||
23 | 23 | class EE_Registry implements ResettableInterface |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * @var EE_Registry $_instance |
|
28 | - */ |
|
29 | - private static $_instance; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var EE_Dependency_Map $_dependency_map |
|
33 | - */ |
|
34 | - protected $_dependency_map; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var Mirror |
|
38 | - */ |
|
39 | - private $mirror; |
|
40 | - |
|
41 | - /** |
|
42 | - * @var ClassInterfaceCache $class_cache |
|
43 | - */ |
|
44 | - private $class_cache; |
|
45 | - |
|
46 | - /** |
|
47 | - * @var array $_class_abbreviations |
|
48 | - */ |
|
49 | - protected $_class_abbreviations = array(); |
|
50 | - |
|
51 | - /** |
|
52 | - * @var CommandBusInterface $BUS |
|
53 | - */ |
|
54 | - public $BUS; |
|
55 | - |
|
56 | - /** |
|
57 | - * @var EE_Cart $CART |
|
58 | - */ |
|
59 | - public $CART; |
|
60 | - |
|
61 | - /** |
|
62 | - * @var EE_Config $CFG |
|
63 | - */ |
|
64 | - public $CFG; |
|
65 | - |
|
66 | - /** |
|
67 | - * @var EE_Network_Config $NET_CFG |
|
68 | - */ |
|
69 | - public $NET_CFG; |
|
70 | - |
|
71 | - /** |
|
72 | - * RegistryContainer for storing library classes in |
|
73 | - * |
|
74 | - * @var RegistryContainer $LIB |
|
75 | - */ |
|
76 | - public $LIB; |
|
77 | - |
|
78 | - /** |
|
79 | - * @var EE_Request_Handler $REQ |
|
80 | - * @deprecated 4.10.14.p |
|
81 | - */ |
|
82 | - public $REQ; |
|
83 | - |
|
84 | - /** |
|
85 | - * @var EE_Session $SSN |
|
86 | - */ |
|
87 | - public $SSN; |
|
88 | - |
|
89 | - /** |
|
90 | - * @since 4.5.0 |
|
91 | - * @var EE_Capabilities $CAP |
|
92 | - */ |
|
93 | - public $CAP; |
|
94 | - |
|
95 | - /** |
|
96 | - * @since 4.9.0 |
|
97 | - * @var EE_Message_Resource_Manager $MRM |
|
98 | - */ |
|
99 | - public $MRM; |
|
100 | - |
|
101 | - /** |
|
102 | - * @var Registry $AssetsRegistry |
|
103 | - */ |
|
104 | - public $AssetsRegistry; |
|
105 | - |
|
106 | - /** |
|
107 | - * RegistryContainer for holding addons which have registered themselves to work with EE core |
|
108 | - * |
|
109 | - * @var EE_Addon[] $addons |
|
110 | - */ |
|
111 | - public $addons; |
|
112 | - |
|
113 | - /** |
|
114 | - * keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
|
115 | - * |
|
116 | - * @var EEM_Base[] $models |
|
117 | - */ |
|
118 | - public $models = array(); |
|
119 | - |
|
120 | - /** |
|
121 | - * @var EED_Module[] $modules |
|
122 | - */ |
|
123 | - public $modules; |
|
124 | - |
|
125 | - /** |
|
126 | - * @var EES_Shortcode[] $shortcodes |
|
127 | - */ |
|
128 | - public $shortcodes; |
|
129 | - |
|
130 | - /** |
|
131 | - * @var WP_Widget[] $widgets |
|
132 | - */ |
|
133 | - public $widgets; |
|
134 | - |
|
135 | - /** |
|
136 | - * this is an array of all implemented model names (i.e. not the parent abstract models, or models |
|
137 | - * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
|
138 | - * Keys are model "short names" (eg "Event") as used in model relations, and values are |
|
139 | - * classnames (eg "EEM_Event") |
|
140 | - * |
|
141 | - * @var array $non_abstract_db_models |
|
142 | - */ |
|
143 | - public $non_abstract_db_models = array(); |
|
144 | - |
|
145 | - /** |
|
146 | - * internationalization for JS strings |
|
147 | - * usage: EE_Registry::i18n_js_strings['string_key'] = esc_html__( 'string to translate.', 'event_espresso' ); |
|
148 | - * in js file: var translatedString = eei18n.string_key; |
|
149 | - * |
|
150 | - * @var array $i18n_js_strings |
|
151 | - */ |
|
152 | - public static $i18n_js_strings = array(); |
|
153 | - |
|
154 | - /** |
|
155 | - * $main_file - path to espresso.php |
|
156 | - * |
|
157 | - * @var array $main_file |
|
158 | - */ |
|
159 | - public $main_file; |
|
160 | - |
|
161 | - /** |
|
162 | - * array of ReflectionClass objects where the key is the class name |
|
163 | - * |
|
164 | - * @deprecated 4.9.62.p |
|
165 | - * @var ReflectionClass[] $_reflectors |
|
166 | - */ |
|
167 | - public $_reflectors; |
|
168 | - |
|
169 | - /** |
|
170 | - * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
|
171 | - * |
|
172 | - * @var boolean $_cache_on |
|
173 | - */ |
|
174 | - protected $_cache_on = true; |
|
175 | - |
|
176 | - /** |
|
177 | - * @var ObjectIdentifier |
|
178 | - */ |
|
179 | - private $object_identifier; |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * @singleton method used to instantiate class object |
|
184 | - * @param EE_Dependency_Map|null $dependency_map |
|
185 | - * @param Mirror|null $mirror |
|
186 | - * @param ClassInterfaceCache|null $class_cache |
|
187 | - * @param ObjectIdentifier|null $object_identifier |
|
188 | - * @return EE_Registry instance |
|
189 | - */ |
|
190 | - public static function instance( |
|
191 | - EE_Dependency_Map $dependency_map = null, |
|
192 | - Mirror $mirror = null, |
|
193 | - ClassInterfaceCache $class_cache = null, |
|
194 | - ObjectIdentifier $object_identifier = null |
|
195 | - ) { |
|
196 | - // check if class object is instantiated |
|
197 | - if ( |
|
198 | - ! self::$_instance instanceof EE_Registry |
|
199 | - && $dependency_map instanceof EE_Dependency_Map |
|
200 | - && $mirror instanceof Mirror |
|
201 | - && $class_cache instanceof ClassInterfaceCache |
|
202 | - && $object_identifier instanceof ObjectIdentifier |
|
203 | - ) { |
|
204 | - self::$_instance = new self( |
|
205 | - $dependency_map, |
|
206 | - $mirror, |
|
207 | - $class_cache, |
|
208 | - $object_identifier |
|
209 | - ); |
|
210 | - } |
|
211 | - return self::$_instance; |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - /** |
|
216 | - * protected constructor to prevent direct creation |
|
217 | - * |
|
218 | - * @Constructor |
|
219 | - * @param EE_Dependency_Map $dependency_map |
|
220 | - * @param Mirror $mirror |
|
221 | - * @param ClassInterfaceCache $class_cache |
|
222 | - * @param ObjectIdentifier $object_identifier |
|
223 | - */ |
|
224 | - protected function __construct( |
|
225 | - EE_Dependency_Map $dependency_map, |
|
226 | - Mirror $mirror, |
|
227 | - ClassInterfaceCache $class_cache, |
|
228 | - ObjectIdentifier $object_identifier |
|
229 | - ) { |
|
230 | - $this->_dependency_map = $dependency_map; |
|
231 | - $this->mirror = $mirror; |
|
232 | - $this->class_cache = $class_cache; |
|
233 | - $this->object_identifier = $object_identifier; |
|
234 | - // $registry_container = new RegistryContainer(); |
|
235 | - $this->LIB = new RegistryContainer(); |
|
236 | - $this->addons = new RegistryContainer(); |
|
237 | - $this->modules = new RegistryContainer(); |
|
238 | - $this->shortcodes = new RegistryContainer(); |
|
239 | - $this->widgets = new RegistryContainer(); |
|
240 | - add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
241 | - } |
|
242 | - |
|
243 | - |
|
244 | - /** |
|
245 | - * initialize |
|
246 | - * |
|
247 | - * @throws OutOfBoundsException |
|
248 | - * @throws InvalidArgumentException |
|
249 | - * @throws InvalidInterfaceException |
|
250 | - * @throws InvalidDataTypeException |
|
251 | - * @throws EE_Error |
|
252 | - * @throws ReflectionException |
|
253 | - */ |
|
254 | - public function initialize() |
|
255 | - { |
|
256 | - $this->_class_abbreviations = apply_filters( |
|
257 | - 'FHEE__EE_Registry____construct___class_abbreviations', |
|
258 | - array( |
|
259 | - 'EE_Config' => 'CFG', |
|
260 | - 'EE_Session' => 'SSN', |
|
261 | - 'EE_Capabilities' => 'CAP', |
|
262 | - 'EE_Cart' => 'CART', |
|
263 | - 'EE_Network_Config' => 'NET_CFG', |
|
264 | - 'EE_Request_Handler' => 'REQ', |
|
265 | - 'EE_Message_Resource_Manager' => 'MRM', |
|
266 | - 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
|
267 | - 'EventEspresso\core\services\assets\Registry' => 'AssetsRegistry', |
|
268 | - ) |
|
269 | - ); |
|
270 | - $this->load_core('Base', array(), true); |
|
271 | - // add our request and response objects to the cache |
|
272 | - $request_loader = $this->_dependency_map->class_loader( |
|
273 | - 'EventEspresso\core\services\request\Request' |
|
274 | - ); |
|
275 | - $this->_set_cached_class( |
|
276 | - $request_loader(), |
|
277 | - 'EventEspresso\core\services\request\Request' |
|
278 | - ); |
|
279 | - $response_loader = $this->_dependency_map->class_loader( |
|
280 | - 'EventEspresso\core\services\request\Response' |
|
281 | - ); |
|
282 | - $this->_set_cached_class( |
|
283 | - $response_loader(), |
|
284 | - 'EventEspresso\core\services\request\Response' |
|
285 | - ); |
|
286 | - add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
|
287 | - } |
|
288 | - |
|
289 | - |
|
290 | - /** |
|
291 | - * @return void |
|
292 | - */ |
|
293 | - public function init() |
|
294 | - { |
|
295 | - // Get current page protocol |
|
296 | - $protocol = is_ssl() ? 'https://' : 'http://'; |
|
297 | - // Output admin-ajax.php URL with same protocol as current page |
|
298 | - self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
|
299 | - self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') && WP_DEBUG; |
|
300 | - } |
|
301 | - |
|
302 | - |
|
303 | - /** |
|
304 | - * @return array |
|
305 | - */ |
|
306 | - public static function sanitize_i18n_js_strings() |
|
307 | - { |
|
308 | - $i18n_js_strings = (array) self::$i18n_js_strings; |
|
309 | - foreach ($i18n_js_strings as $key => $value) { |
|
310 | - if (is_scalar($value)) { |
|
311 | - $decoded_value = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8'); |
|
312 | - $i18n_js_strings[ $key ] = wp_strip_all_tags($decoded_value); |
|
313 | - } |
|
314 | - } |
|
315 | - return $i18n_js_strings; |
|
316 | - } |
|
317 | - |
|
318 | - |
|
319 | - /** |
|
320 | - * localize_i18n_js_strings |
|
321 | - * |
|
322 | - * @return string |
|
323 | - */ |
|
324 | - public static function localize_i18n_js_strings() |
|
325 | - { |
|
326 | - $i18n_js_strings = EE_Registry::sanitize_i18n_js_strings(); |
|
327 | - return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
328 | - } |
|
329 | - |
|
330 | - |
|
331 | - /** |
|
332 | - * @param mixed string | EED_Module $module |
|
333 | - * @throws OutOfBoundsException |
|
334 | - * @throws InvalidArgumentException |
|
335 | - * @throws InvalidInterfaceException |
|
336 | - * @throws InvalidDataTypeException |
|
337 | - * @throws EE_Error |
|
338 | - * @throws ReflectionException |
|
339 | - */ |
|
340 | - public function add_module($module) |
|
341 | - { |
|
342 | - if ($module instanceof EED_Module) { |
|
343 | - $module_class = get_class($module); |
|
344 | - $this->modules->add($module_class, $module); |
|
345 | - } else { |
|
346 | - if (! class_exists('EE_Module_Request_Router', false)) { |
|
347 | - $this->load_core('Module_Request_Router'); |
|
348 | - } |
|
349 | - EE_Module_Request_Router::module_factory($module); |
|
350 | - } |
|
351 | - } |
|
352 | - |
|
353 | - |
|
354 | - /** |
|
355 | - * @param string $module_name |
|
356 | - * @return mixed EED_Module | NULL |
|
357 | - */ |
|
358 | - public function get_module($module_name = '') |
|
359 | - { |
|
360 | - return $this->modules->get($module_name); |
|
361 | - } |
|
362 | - |
|
363 | - |
|
364 | - /** |
|
365 | - * loads core classes - must be singletons |
|
366 | - * |
|
367 | - * @param string $class_name - simple class name ie: session |
|
368 | - * @param mixed $arguments |
|
369 | - * @param bool $load_only |
|
370 | - * @return mixed |
|
371 | - * @throws InvalidInterfaceException |
|
372 | - * @throws InvalidDataTypeException |
|
373 | - * @throws EE_Error |
|
374 | - * @throws ReflectionException |
|
375 | - * @throws InvalidArgumentException |
|
376 | - */ |
|
377 | - public function load_core($class_name, $arguments = array(), $load_only = false) |
|
378 | - { |
|
379 | - $core_paths = apply_filters( |
|
380 | - 'FHEE__EE_Registry__load_core__core_paths', |
|
381 | - array( |
|
382 | - EE_CORE, |
|
383 | - EE_ADMIN, |
|
384 | - EE_CPTS, |
|
385 | - EE_CORE . 'CPTs/', |
|
386 | - EE_CORE . 'data_migration_scripts/', |
|
387 | - EE_CORE . 'request_stack/', |
|
388 | - EE_CORE . 'middleware/', |
|
389 | - ) |
|
390 | - ); |
|
391 | - // retrieve instantiated class |
|
392 | - return $this->_load( |
|
393 | - $core_paths, |
|
394 | - 'EE_', |
|
395 | - $class_name, |
|
396 | - 'core', |
|
397 | - $arguments, |
|
398 | - false, |
|
399 | - true, |
|
400 | - $load_only |
|
401 | - ); |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - /** |
|
406 | - * loads service classes |
|
407 | - * |
|
408 | - * @param string $class_name - simple class name ie: session |
|
409 | - * @param mixed $arguments |
|
410 | - * @param bool $load_only |
|
411 | - * @return mixed |
|
412 | - * @throws InvalidInterfaceException |
|
413 | - * @throws InvalidDataTypeException |
|
414 | - * @throws EE_Error |
|
415 | - * @throws ReflectionException |
|
416 | - * @throws InvalidArgumentException |
|
417 | - */ |
|
418 | - public function load_service($class_name, $arguments = array(), $load_only = false) |
|
419 | - { |
|
420 | - $service_paths = apply_filters( |
|
421 | - 'FHEE__EE_Registry__load_service__service_paths', |
|
422 | - array( |
|
423 | - EE_CORE . 'services/', |
|
424 | - ) |
|
425 | - ); |
|
426 | - // retrieve instantiated class |
|
427 | - return $this->_load( |
|
428 | - $service_paths, |
|
429 | - 'EE_', |
|
430 | - $class_name, |
|
431 | - 'class', |
|
432 | - $arguments, |
|
433 | - false, |
|
434 | - true, |
|
435 | - $load_only |
|
436 | - ); |
|
437 | - } |
|
438 | - |
|
439 | - |
|
440 | - /** |
|
441 | - * loads data_migration_scripts |
|
442 | - * |
|
443 | - * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
|
444 | - * @param mixed $arguments |
|
445 | - * @return EE_Data_Migration_Script_Base|mixed |
|
446 | - * @throws InvalidInterfaceException |
|
447 | - * @throws InvalidDataTypeException |
|
448 | - * @throws EE_Error |
|
449 | - * @throws ReflectionException |
|
450 | - * @throws InvalidArgumentException |
|
451 | - */ |
|
452 | - public function load_dms($class_name, $arguments = array()) |
|
453 | - { |
|
454 | - // retrieve instantiated class |
|
455 | - return $this->_load( |
|
456 | - EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), |
|
457 | - 'EE_DMS_', |
|
458 | - $class_name, |
|
459 | - 'dms', |
|
460 | - $arguments, |
|
461 | - false, |
|
462 | - false |
|
463 | - ); |
|
464 | - } |
|
465 | - |
|
466 | - |
|
467 | - /** |
|
468 | - * loads object creating classes - must be singletons |
|
469 | - * |
|
470 | - * @param string $class_name - simple class name ie: attendee |
|
471 | - * @param mixed $arguments - an array of arguments to pass to the class |
|
472 | - * @param bool $from_db - some classes are instantiated from the db and thus call a different method to |
|
473 | - * instantiate |
|
474 | - * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then |
|
475 | - * set this to FALSE (ie. when instantiating model objects from client in a loop) |
|
476 | - * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate |
|
477 | - * (default) |
|
478 | - * @return EE_Base_Class | bool |
|
479 | - * @throws InvalidInterfaceException |
|
480 | - * @throws InvalidDataTypeException |
|
481 | - * @throws EE_Error |
|
482 | - * @throws ReflectionException |
|
483 | - * @throws InvalidArgumentException |
|
484 | - */ |
|
485 | - public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
|
486 | - { |
|
487 | - $paths = apply_filters( |
|
488 | - 'FHEE__EE_Registry__load_class__paths', |
|
489 | - array( |
|
490 | - EE_CORE, |
|
491 | - EE_CLASSES, |
|
492 | - EE_BUSINESS, |
|
493 | - ) |
|
494 | - ); |
|
495 | - // retrieve instantiated class |
|
496 | - return $this->_load( |
|
497 | - $paths, |
|
498 | - 'EE_', |
|
499 | - $class_name, |
|
500 | - 'class', |
|
501 | - $arguments, |
|
502 | - $from_db, |
|
503 | - $cache, |
|
504 | - $load_only |
|
505 | - ); |
|
506 | - } |
|
507 | - |
|
508 | - |
|
509 | - /** |
|
510 | - * loads helper classes - must be singletons |
|
511 | - * |
|
512 | - * @param string $class_name - simple class name ie: price |
|
513 | - * @param mixed $arguments |
|
514 | - * @param bool $load_only |
|
515 | - * @return EEH_Base | bool |
|
516 | - * @throws InvalidInterfaceException |
|
517 | - * @throws InvalidDataTypeException |
|
518 | - * @throws EE_Error |
|
519 | - * @throws ReflectionException |
|
520 | - * @throws InvalidArgumentException |
|
521 | - */ |
|
522 | - public function load_helper($class_name, $arguments = array(), $load_only = true) |
|
523 | - { |
|
524 | - // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed |
|
525 | - $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); |
|
526 | - // retrieve instantiated class |
|
527 | - return $this->_load( |
|
528 | - $helper_paths, |
|
529 | - 'EEH_', |
|
530 | - $class_name, |
|
531 | - 'helper', |
|
532 | - $arguments, |
|
533 | - false, |
|
534 | - true, |
|
535 | - $load_only |
|
536 | - ); |
|
537 | - } |
|
538 | - |
|
539 | - |
|
540 | - /** |
|
541 | - * loads core classes - must be singletons |
|
542 | - * |
|
543 | - * @param string $class_name - simple class name ie: session |
|
544 | - * @param mixed $arguments |
|
545 | - * @param bool $load_only |
|
546 | - * @param bool $cache whether to cache the object or not. |
|
547 | - * @return mixed |
|
548 | - * @throws InvalidInterfaceException |
|
549 | - * @throws InvalidDataTypeException |
|
550 | - * @throws EE_Error |
|
551 | - * @throws ReflectionException |
|
552 | - * @throws InvalidArgumentException |
|
553 | - */ |
|
554 | - public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
|
555 | - { |
|
556 | - $paths = array( |
|
557 | - EE_LIBRARIES, |
|
558 | - EE_LIBRARIES . 'messages/', |
|
559 | - EE_LIBRARIES . 'shortcodes/', |
|
560 | - EE_LIBRARIES . 'qtips/', |
|
561 | - EE_LIBRARIES . 'payment_methods/', |
|
562 | - ); |
|
563 | - // retrieve instantiated class |
|
564 | - return $this->_load( |
|
565 | - $paths, |
|
566 | - 'EE_', |
|
567 | - $class_name, |
|
568 | - 'lib', |
|
569 | - $arguments, |
|
570 | - false, |
|
571 | - $cache, |
|
572 | - $load_only |
|
573 | - ); |
|
574 | - } |
|
575 | - |
|
576 | - |
|
577 | - /** |
|
578 | - * loads model classes - must be singletons |
|
579 | - * |
|
580 | - * @param string $class_name - simple class name ie: price |
|
581 | - * @param mixed $arguments |
|
582 | - * @param bool $load_only |
|
583 | - * @return mixed |
|
584 | - * @throws InvalidInterfaceException |
|
585 | - * @throws InvalidDataTypeException |
|
586 | - * @throws EE_Error |
|
587 | - * @throws ReflectionException |
|
588 | - * @throws InvalidArgumentException |
|
589 | - */ |
|
590 | - public function load_model($class_name, $arguments = array(), $load_only = false) |
|
591 | - { |
|
592 | - $paths = apply_filters( |
|
593 | - 'FHEE__EE_Registry__load_model__paths', |
|
594 | - array( |
|
595 | - EE_MODELS, |
|
596 | - EE_CORE, |
|
597 | - ) |
|
598 | - ); |
|
599 | - // retrieve instantiated class |
|
600 | - return $this->_load( |
|
601 | - $paths, |
|
602 | - 'EEM_', |
|
603 | - $class_name, |
|
604 | - 'model', |
|
605 | - $arguments, |
|
606 | - false, |
|
607 | - true, |
|
608 | - $load_only |
|
609 | - ); |
|
610 | - } |
|
611 | - |
|
612 | - |
|
613 | - /** |
|
614 | - * loads model classes - must be singletons |
|
615 | - * |
|
616 | - * @param string $class_name - simple class name ie: price |
|
617 | - * @param mixed $arguments |
|
618 | - * @param bool $load_only |
|
619 | - * @return mixed | bool |
|
620 | - * @throws InvalidInterfaceException |
|
621 | - * @throws InvalidDataTypeException |
|
622 | - * @throws EE_Error |
|
623 | - * @throws ReflectionException |
|
624 | - * @throws InvalidArgumentException |
|
625 | - */ |
|
626 | - public function load_model_class($class_name, $arguments = array(), $load_only = true) |
|
627 | - { |
|
628 | - $paths = array( |
|
629 | - EE_MODELS . 'fields/', |
|
630 | - EE_MODELS . 'helpers/', |
|
631 | - EE_MODELS . 'relations/', |
|
632 | - EE_MODELS . 'strategies/', |
|
633 | - ); |
|
634 | - // retrieve instantiated class |
|
635 | - return $this->_load( |
|
636 | - $paths, |
|
637 | - 'EE_', |
|
638 | - $class_name, |
|
639 | - '', |
|
640 | - $arguments, |
|
641 | - false, |
|
642 | - true, |
|
643 | - $load_only |
|
644 | - ); |
|
645 | - } |
|
646 | - |
|
647 | - |
|
648 | - /** |
|
649 | - * Determines if $model_name is the name of an actual EE model. |
|
650 | - * |
|
651 | - * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
|
652 | - * @return boolean |
|
653 | - */ |
|
654 | - public function is_model_name($model_name) |
|
655 | - { |
|
656 | - return isset($this->models[ $model_name ]); |
|
657 | - } |
|
658 | - |
|
659 | - |
|
660 | - /** |
|
661 | - * generic class loader |
|
662 | - * |
|
663 | - * @param string $path_to_file - directory path to file location, not including filename |
|
664 | - * @param string $file_name - file name ie: my_file.php, including extension |
|
665 | - * @param string $type - file type - core? class? helper? model? |
|
666 | - * @param mixed $arguments |
|
667 | - * @param bool $load_only |
|
668 | - * @return mixed |
|
669 | - * @throws InvalidInterfaceException |
|
670 | - * @throws InvalidDataTypeException |
|
671 | - * @throws EE_Error |
|
672 | - * @throws ReflectionException |
|
673 | - * @throws InvalidArgumentException |
|
674 | - */ |
|
675 | - public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
|
676 | - { |
|
677 | - // retrieve instantiated class |
|
678 | - return $this->_load( |
|
679 | - $path_to_file, |
|
680 | - '', |
|
681 | - $file_name, |
|
682 | - $type, |
|
683 | - $arguments, |
|
684 | - false, |
|
685 | - true, |
|
686 | - $load_only |
|
687 | - ); |
|
688 | - } |
|
689 | - |
|
690 | - |
|
691 | - /** |
|
692 | - * @param string $path_to_file - directory path to file location, not including filename |
|
693 | - * @param string $class_name - full class name ie: My_Class |
|
694 | - * @param string $type - file type - core? class? helper? model? |
|
695 | - * @param mixed $arguments |
|
696 | - * @param bool $load_only |
|
697 | - * @return bool|EE_Addon|object |
|
698 | - * @throws InvalidInterfaceException |
|
699 | - * @throws InvalidDataTypeException |
|
700 | - * @throws EE_Error |
|
701 | - * @throws ReflectionException |
|
702 | - * @throws InvalidArgumentException |
|
703 | - */ |
|
704 | - public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
|
705 | - { |
|
706 | - // retrieve instantiated class |
|
707 | - return $this->_load( |
|
708 | - $path_to_file, |
|
709 | - 'addon', |
|
710 | - $class_name, |
|
711 | - $type, |
|
712 | - $arguments, |
|
713 | - false, |
|
714 | - true, |
|
715 | - $load_only |
|
716 | - ); |
|
717 | - } |
|
718 | - |
|
719 | - |
|
720 | - /** |
|
721 | - * instantiates, caches, and automatically resolves dependencies |
|
722 | - * for classes that use a Fully Qualified Class Name. |
|
723 | - * if the class is not capable of being loaded using PSR-4 autoloading, |
|
724 | - * then you need to use one of the existing load_*() methods |
|
725 | - * which can resolve the classname and filepath from the passed arguments |
|
726 | - * |
|
727 | - * @param bool|string $class_name Fully Qualified Class Name |
|
728 | - * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
|
729 | - * @param bool $cache whether to cache the instantiated object for reuse |
|
730 | - * @param bool $from_db some classes are instantiated from the db |
|
731 | - * and thus call a different method to instantiate |
|
732 | - * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
733 | - * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
|
734 | - * @return bool|null|mixed null = failure to load or instantiate class object. |
|
735 | - * object = class loaded and instantiated successfully. |
|
736 | - * bool = fail or success when $load_only is true |
|
737 | - * @throws InvalidInterfaceException |
|
738 | - * @throws InvalidDataTypeException |
|
739 | - * @throws EE_Error |
|
740 | - * @throws ReflectionException |
|
741 | - * @throws InvalidArgumentException |
|
742 | - */ |
|
743 | - public function create( |
|
744 | - $class_name = false, |
|
745 | - $arguments = array(), |
|
746 | - $cache = false, |
|
747 | - $from_db = false, |
|
748 | - $load_only = false, |
|
749 | - $addon = false |
|
750 | - ) { |
|
751 | - $class_name = ltrim($class_name, '\\'); |
|
752 | - $class_name = $this->class_cache->getFqnForAlias($class_name); |
|
753 | - $class_exists = $this->loadOrVerifyClassExists($class_name, $arguments); |
|
754 | - // if a non-FQCN was passed, then |
|
755 | - // verifyClassExists() might return an object |
|
756 | - // or it could return null if the class just could not be found anywhere |
|
757 | - if ($class_exists instanceof $class_name || $class_exists === null) { |
|
758 | - // either way, return the results |
|
759 | - return $class_exists; |
|
760 | - } |
|
761 | - $class_name = $class_exists; |
|
762 | - // if we're only loading the class and it already exists, then let's just return true immediately |
|
763 | - if ($load_only) { |
|
764 | - return true; |
|
765 | - } |
|
766 | - $addon = $addon ? 'addon' : ''; |
|
767 | - // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
768 | - // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
769 | - // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
770 | - if ($this->_cache_on && $cache && ! $load_only) { |
|
771 | - // return object if it's already cached |
|
772 | - $cached_class = $this->_get_cached_class($class_name, $addon, $arguments); |
|
773 | - if ($cached_class !== null) { |
|
774 | - return $cached_class; |
|
775 | - } |
|
776 | - }// obtain the loader method from the dependency map |
|
777 | - $loader = $this->_dependency_map->class_loader($class_name);// instantiate the requested object |
|
778 | - if ($loader instanceof Closure) { |
|
779 | - $class_obj = $loader($arguments); |
|
780 | - } else { |
|
781 | - if ($loader && method_exists($this, $loader)) { |
|
782 | - $class_obj = $this->{$loader}($class_name, $arguments); |
|
783 | - } else { |
|
784 | - $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
|
785 | - } |
|
786 | - } |
|
787 | - if (($this->_cache_on && $cache) || $this->get_class_abbreviation($class_name, '')) { |
|
788 | - // save it for later... kinda like gum { : $ |
|
789 | - $this->_set_cached_class( |
|
790 | - $class_obj, |
|
791 | - $class_name, |
|
792 | - $addon, |
|
793 | - $from_db, |
|
794 | - $arguments |
|
795 | - ); |
|
796 | - } |
|
797 | - $this->_cache_on = true; |
|
798 | - return $class_obj; |
|
799 | - } |
|
800 | - |
|
801 | - |
|
802 | - /** |
|
803 | - * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs |
|
804 | - * |
|
805 | - * @param string|object $class_name |
|
806 | - * @param array $arguments |
|
807 | - * @param int $attempt |
|
808 | - * @return mixed |
|
809 | - */ |
|
810 | - private function loadOrVerifyClassExists($class_name, array $arguments, $attempt = 1) |
|
811 | - { |
|
812 | - if (is_object($class_name) || class_exists($class_name)) { |
|
813 | - return $class_name; |
|
814 | - } |
|
815 | - switch ($attempt) { |
|
816 | - case 1: |
|
817 | - // if it's a FQCN then maybe the class is registered with a preceding \ |
|
818 | - $class_name = strpos($class_name, '\\') !== false |
|
819 | - ? '\\' . ltrim($class_name, '\\') |
|
820 | - : $class_name; |
|
821 | - break; |
|
822 | - case 2: |
|
823 | - // |
|
824 | - $loader = $this->_dependency_map->class_loader($class_name); |
|
825 | - if ($loader && method_exists($this, $loader)) { |
|
826 | - return $this->{$loader}($class_name, $arguments); |
|
827 | - } |
|
828 | - break; |
|
829 | - case 3: |
|
830 | - default: |
|
831 | - return null; |
|
832 | - } |
|
833 | - $attempt++; |
|
834 | - return $this->loadOrVerifyClassExists($class_name, $arguments, $attempt); |
|
835 | - } |
|
836 | - |
|
837 | - |
|
838 | - /** |
|
839 | - * instantiates, caches, and injects dependencies for classes |
|
840 | - * |
|
841 | - * @param array $file_paths an array of paths to folders to look in |
|
842 | - * @param string $class_prefix EE or EEM or... ??? |
|
843 | - * @param bool|string $class_name $class name |
|
844 | - * @param string $type file type - core? class? helper? model? |
|
845 | - * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
|
846 | - * @param bool $from_db some classes are instantiated from the db |
|
847 | - * and thus call a different method to instantiate |
|
848 | - * @param bool $cache whether to cache the instantiated object for reuse |
|
849 | - * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
850 | - * @return bool|null|object null = failure to load or instantiate class object. |
|
851 | - * object = class loaded and instantiated successfully. |
|
852 | - * bool = fail or success when $load_only is true |
|
853 | - * @throws EE_Error |
|
854 | - * @throws ReflectionException |
|
855 | - * @throws InvalidInterfaceException |
|
856 | - * @throws InvalidDataTypeException |
|
857 | - * @throws InvalidArgumentException |
|
858 | - */ |
|
859 | - protected function _load( |
|
860 | - $file_paths = array(), |
|
861 | - $class_prefix = 'EE_', |
|
862 | - $class_name = false, |
|
863 | - $type = 'class', |
|
864 | - $arguments = array(), |
|
865 | - $from_db = false, |
|
866 | - $cache = true, |
|
867 | - $load_only = false |
|
868 | - ) { |
|
869 | - $class_name = ltrim($class_name, '\\'); |
|
870 | - // strip php file extension |
|
871 | - $class_name = str_replace('.php', '', trim($class_name)); |
|
872 | - // does the class have a prefix ? |
|
873 | - if (! empty($class_prefix) && $class_prefix !== 'addon') { |
|
874 | - // make sure $class_prefix is uppercase |
|
875 | - $class_prefix = strtoupper(trim($class_prefix)); |
|
876 | - // add class prefix ONCE!!! |
|
877 | - $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
878 | - } |
|
879 | - $class_name = $this->class_cache->getFqnForAlias($class_name); |
|
880 | - $class_exists = class_exists($class_name, false); |
|
881 | - // if we're only loading the class and it already exists, then let's just return true immediately |
|
882 | - if ($load_only && $class_exists) { |
|
883 | - return true; |
|
884 | - } |
|
885 | - $arguments = is_array($arguments) ? $arguments : array($arguments); |
|
886 | - // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
887 | - // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
888 | - // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
889 | - if ($this->_cache_on && $cache && ! $load_only) { |
|
890 | - // return object if it's already cached |
|
891 | - $cached_class = $this->_get_cached_class($class_name, $class_prefix, $arguments); |
|
892 | - if ($cached_class !== null) { |
|
893 | - return $cached_class; |
|
894 | - } |
|
895 | - } |
|
896 | - // if the class doesn't already exist.. then we need to try and find the file and load it |
|
897 | - if (! $class_exists) { |
|
898 | - // get full path to file |
|
899 | - $path = $this->_resolve_path($class_name, $type, $file_paths); |
|
900 | - // load the file |
|
901 | - $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
|
902 | - // if we are only loading a file but NOT instantiating an object |
|
903 | - // then return boolean for whether class was loaded or not |
|
904 | - if ($load_only) { |
|
905 | - return $loaded; |
|
906 | - } |
|
907 | - // if an object was expected but loading failed, then return nothing |
|
908 | - if (! $loaded) { |
|
909 | - return null; |
|
910 | - } |
|
911 | - } |
|
912 | - // instantiate the requested object |
|
913 | - $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); |
|
914 | - if ($this->_cache_on && $cache) { |
|
915 | - // save it for later... kinda like gum { : $ |
|
916 | - $this->_set_cached_class( |
|
917 | - $class_obj, |
|
918 | - $class_name, |
|
919 | - $class_prefix, |
|
920 | - $from_db, |
|
921 | - $arguments |
|
922 | - ); |
|
923 | - } |
|
924 | - $this->_cache_on = true; |
|
925 | - return $class_obj; |
|
926 | - } |
|
927 | - |
|
928 | - |
|
929 | - /** |
|
930 | - * @param string $class_name |
|
931 | - * @param string $default have to specify something, but not anything that will conflict |
|
932 | - * @return mixed|string |
|
933 | - */ |
|
934 | - protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS') |
|
935 | - { |
|
936 | - return isset($this->_class_abbreviations[ $class_name ]) |
|
937 | - ? $this->_class_abbreviations[ $class_name ] |
|
938 | - : $default; |
|
939 | - } |
|
940 | - |
|
941 | - |
|
942 | - /** |
|
943 | - * attempts to find a cached version of the requested class |
|
944 | - * by looking in the following places: |
|
945 | - * $this->{$class_abbreviation} ie: $this->CART |
|
946 | - * $this->{$class_name} ie: $this->Some_Class |
|
947 | - * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
948 | - * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
|
949 | - * |
|
950 | - * @param string $class_name |
|
951 | - * @param string $class_prefix |
|
952 | - * @param array $arguments |
|
953 | - * @return mixed |
|
954 | - */ |
|
955 | - protected function _get_cached_class( |
|
956 | - $class_name, |
|
957 | - $class_prefix = '', |
|
958 | - $arguments = array() |
|
959 | - ) { |
|
960 | - if ($class_name === 'EE_Registry') { |
|
961 | - return $this; |
|
962 | - } |
|
963 | - $class_abbreviation = $this->get_class_abbreviation($class_name); |
|
964 | - // check if class has already been loaded, and return it if it has been |
|
965 | - if (isset($this->{$class_abbreviation})) { |
|
966 | - return $this->{$class_abbreviation}; |
|
967 | - } |
|
968 | - $class_name = str_replace('\\', '_', $class_name); |
|
969 | - if (isset($this->{$class_name})) { |
|
970 | - return $this->{$class_name}; |
|
971 | - } |
|
972 | - if ($class_prefix === 'addon' && $this->addons->has($class_name)) { |
|
973 | - return $this->addons->get($class_name); |
|
974 | - } |
|
975 | - $object_identifier = $this->object_identifier->getIdentifier($class_name, $arguments); |
|
976 | - if ($this->LIB->has($object_identifier)) { |
|
977 | - return $this->LIB->get($object_identifier); |
|
978 | - } |
|
979 | - foreach ($this->LIB as $key => $object) { |
|
980 | - if ( |
|
26 | + /** |
|
27 | + * @var EE_Registry $_instance |
|
28 | + */ |
|
29 | + private static $_instance; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var EE_Dependency_Map $_dependency_map |
|
33 | + */ |
|
34 | + protected $_dependency_map; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var Mirror |
|
38 | + */ |
|
39 | + private $mirror; |
|
40 | + |
|
41 | + /** |
|
42 | + * @var ClassInterfaceCache $class_cache |
|
43 | + */ |
|
44 | + private $class_cache; |
|
45 | + |
|
46 | + /** |
|
47 | + * @var array $_class_abbreviations |
|
48 | + */ |
|
49 | + protected $_class_abbreviations = array(); |
|
50 | + |
|
51 | + /** |
|
52 | + * @var CommandBusInterface $BUS |
|
53 | + */ |
|
54 | + public $BUS; |
|
55 | + |
|
56 | + /** |
|
57 | + * @var EE_Cart $CART |
|
58 | + */ |
|
59 | + public $CART; |
|
60 | + |
|
61 | + /** |
|
62 | + * @var EE_Config $CFG |
|
63 | + */ |
|
64 | + public $CFG; |
|
65 | + |
|
66 | + /** |
|
67 | + * @var EE_Network_Config $NET_CFG |
|
68 | + */ |
|
69 | + public $NET_CFG; |
|
70 | + |
|
71 | + /** |
|
72 | + * RegistryContainer for storing library classes in |
|
73 | + * |
|
74 | + * @var RegistryContainer $LIB |
|
75 | + */ |
|
76 | + public $LIB; |
|
77 | + |
|
78 | + /** |
|
79 | + * @var EE_Request_Handler $REQ |
|
80 | + * @deprecated 4.10.14.p |
|
81 | + */ |
|
82 | + public $REQ; |
|
83 | + |
|
84 | + /** |
|
85 | + * @var EE_Session $SSN |
|
86 | + */ |
|
87 | + public $SSN; |
|
88 | + |
|
89 | + /** |
|
90 | + * @since 4.5.0 |
|
91 | + * @var EE_Capabilities $CAP |
|
92 | + */ |
|
93 | + public $CAP; |
|
94 | + |
|
95 | + /** |
|
96 | + * @since 4.9.0 |
|
97 | + * @var EE_Message_Resource_Manager $MRM |
|
98 | + */ |
|
99 | + public $MRM; |
|
100 | + |
|
101 | + /** |
|
102 | + * @var Registry $AssetsRegistry |
|
103 | + */ |
|
104 | + public $AssetsRegistry; |
|
105 | + |
|
106 | + /** |
|
107 | + * RegistryContainer for holding addons which have registered themselves to work with EE core |
|
108 | + * |
|
109 | + * @var EE_Addon[] $addons |
|
110 | + */ |
|
111 | + public $addons; |
|
112 | + |
|
113 | + /** |
|
114 | + * keys are 'short names' (eg Event), values are class names (eg 'EEM_Event') |
|
115 | + * |
|
116 | + * @var EEM_Base[] $models |
|
117 | + */ |
|
118 | + public $models = array(); |
|
119 | + |
|
120 | + /** |
|
121 | + * @var EED_Module[] $modules |
|
122 | + */ |
|
123 | + public $modules; |
|
124 | + |
|
125 | + /** |
|
126 | + * @var EES_Shortcode[] $shortcodes |
|
127 | + */ |
|
128 | + public $shortcodes; |
|
129 | + |
|
130 | + /** |
|
131 | + * @var WP_Widget[] $widgets |
|
132 | + */ |
|
133 | + public $widgets; |
|
134 | + |
|
135 | + /** |
|
136 | + * this is an array of all implemented model names (i.e. not the parent abstract models, or models |
|
137 | + * which don't actually fetch items from the DB in the normal way (ie, are not children of EEM_Base)). |
|
138 | + * Keys are model "short names" (eg "Event") as used in model relations, and values are |
|
139 | + * classnames (eg "EEM_Event") |
|
140 | + * |
|
141 | + * @var array $non_abstract_db_models |
|
142 | + */ |
|
143 | + public $non_abstract_db_models = array(); |
|
144 | + |
|
145 | + /** |
|
146 | + * internationalization for JS strings |
|
147 | + * usage: EE_Registry::i18n_js_strings['string_key'] = esc_html__( 'string to translate.', 'event_espresso' ); |
|
148 | + * in js file: var translatedString = eei18n.string_key; |
|
149 | + * |
|
150 | + * @var array $i18n_js_strings |
|
151 | + */ |
|
152 | + public static $i18n_js_strings = array(); |
|
153 | + |
|
154 | + /** |
|
155 | + * $main_file - path to espresso.php |
|
156 | + * |
|
157 | + * @var array $main_file |
|
158 | + */ |
|
159 | + public $main_file; |
|
160 | + |
|
161 | + /** |
|
162 | + * array of ReflectionClass objects where the key is the class name |
|
163 | + * |
|
164 | + * @deprecated 4.9.62.p |
|
165 | + * @var ReflectionClass[] $_reflectors |
|
166 | + */ |
|
167 | + public $_reflectors; |
|
168 | + |
|
169 | + /** |
|
170 | + * boolean flag to indicate whether or not to load/save dependencies from/to the cache |
|
171 | + * |
|
172 | + * @var boolean $_cache_on |
|
173 | + */ |
|
174 | + protected $_cache_on = true; |
|
175 | + |
|
176 | + /** |
|
177 | + * @var ObjectIdentifier |
|
178 | + */ |
|
179 | + private $object_identifier; |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * @singleton method used to instantiate class object |
|
184 | + * @param EE_Dependency_Map|null $dependency_map |
|
185 | + * @param Mirror|null $mirror |
|
186 | + * @param ClassInterfaceCache|null $class_cache |
|
187 | + * @param ObjectIdentifier|null $object_identifier |
|
188 | + * @return EE_Registry instance |
|
189 | + */ |
|
190 | + public static function instance( |
|
191 | + EE_Dependency_Map $dependency_map = null, |
|
192 | + Mirror $mirror = null, |
|
193 | + ClassInterfaceCache $class_cache = null, |
|
194 | + ObjectIdentifier $object_identifier = null |
|
195 | + ) { |
|
196 | + // check if class object is instantiated |
|
197 | + if ( |
|
198 | + ! self::$_instance instanceof EE_Registry |
|
199 | + && $dependency_map instanceof EE_Dependency_Map |
|
200 | + && $mirror instanceof Mirror |
|
201 | + && $class_cache instanceof ClassInterfaceCache |
|
202 | + && $object_identifier instanceof ObjectIdentifier |
|
203 | + ) { |
|
204 | + self::$_instance = new self( |
|
205 | + $dependency_map, |
|
206 | + $mirror, |
|
207 | + $class_cache, |
|
208 | + $object_identifier |
|
209 | + ); |
|
210 | + } |
|
211 | + return self::$_instance; |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + /** |
|
216 | + * protected constructor to prevent direct creation |
|
217 | + * |
|
218 | + * @Constructor |
|
219 | + * @param EE_Dependency_Map $dependency_map |
|
220 | + * @param Mirror $mirror |
|
221 | + * @param ClassInterfaceCache $class_cache |
|
222 | + * @param ObjectIdentifier $object_identifier |
|
223 | + */ |
|
224 | + protected function __construct( |
|
225 | + EE_Dependency_Map $dependency_map, |
|
226 | + Mirror $mirror, |
|
227 | + ClassInterfaceCache $class_cache, |
|
228 | + ObjectIdentifier $object_identifier |
|
229 | + ) { |
|
230 | + $this->_dependency_map = $dependency_map; |
|
231 | + $this->mirror = $mirror; |
|
232 | + $this->class_cache = $class_cache; |
|
233 | + $this->object_identifier = $object_identifier; |
|
234 | + // $registry_container = new RegistryContainer(); |
|
235 | + $this->LIB = new RegistryContainer(); |
|
236 | + $this->addons = new RegistryContainer(); |
|
237 | + $this->modules = new RegistryContainer(); |
|
238 | + $this->shortcodes = new RegistryContainer(); |
|
239 | + $this->widgets = new RegistryContainer(); |
|
240 | + add_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading', array($this, 'initialize')); |
|
241 | + } |
|
242 | + |
|
243 | + |
|
244 | + /** |
|
245 | + * initialize |
|
246 | + * |
|
247 | + * @throws OutOfBoundsException |
|
248 | + * @throws InvalidArgumentException |
|
249 | + * @throws InvalidInterfaceException |
|
250 | + * @throws InvalidDataTypeException |
|
251 | + * @throws EE_Error |
|
252 | + * @throws ReflectionException |
|
253 | + */ |
|
254 | + public function initialize() |
|
255 | + { |
|
256 | + $this->_class_abbreviations = apply_filters( |
|
257 | + 'FHEE__EE_Registry____construct___class_abbreviations', |
|
258 | + array( |
|
259 | + 'EE_Config' => 'CFG', |
|
260 | + 'EE_Session' => 'SSN', |
|
261 | + 'EE_Capabilities' => 'CAP', |
|
262 | + 'EE_Cart' => 'CART', |
|
263 | + 'EE_Network_Config' => 'NET_CFG', |
|
264 | + 'EE_Request_Handler' => 'REQ', |
|
265 | + 'EE_Message_Resource_Manager' => 'MRM', |
|
266 | + 'EventEspresso\core\services\commands\CommandBus' => 'BUS', |
|
267 | + 'EventEspresso\core\services\assets\Registry' => 'AssetsRegistry', |
|
268 | + ) |
|
269 | + ); |
|
270 | + $this->load_core('Base', array(), true); |
|
271 | + // add our request and response objects to the cache |
|
272 | + $request_loader = $this->_dependency_map->class_loader( |
|
273 | + 'EventEspresso\core\services\request\Request' |
|
274 | + ); |
|
275 | + $this->_set_cached_class( |
|
276 | + $request_loader(), |
|
277 | + 'EventEspresso\core\services\request\Request' |
|
278 | + ); |
|
279 | + $response_loader = $this->_dependency_map->class_loader( |
|
280 | + 'EventEspresso\core\services\request\Response' |
|
281 | + ); |
|
282 | + $this->_set_cached_class( |
|
283 | + $response_loader(), |
|
284 | + 'EventEspresso\core\services\request\Response' |
|
285 | + ); |
|
286 | + add_action('AHEE__EE_System__set_hooks_for_core', array($this, 'init')); |
|
287 | + } |
|
288 | + |
|
289 | + |
|
290 | + /** |
|
291 | + * @return void |
|
292 | + */ |
|
293 | + public function init() |
|
294 | + { |
|
295 | + // Get current page protocol |
|
296 | + $protocol = is_ssl() ? 'https://' : 'http://'; |
|
297 | + // Output admin-ajax.php URL with same protocol as current page |
|
298 | + self::$i18n_js_strings['ajax_url'] = admin_url('admin-ajax.php', $protocol); |
|
299 | + self::$i18n_js_strings['wp_debug'] = defined('WP_DEBUG') && WP_DEBUG; |
|
300 | + } |
|
301 | + |
|
302 | + |
|
303 | + /** |
|
304 | + * @return array |
|
305 | + */ |
|
306 | + public static function sanitize_i18n_js_strings() |
|
307 | + { |
|
308 | + $i18n_js_strings = (array) self::$i18n_js_strings; |
|
309 | + foreach ($i18n_js_strings as $key => $value) { |
|
310 | + if (is_scalar($value)) { |
|
311 | + $decoded_value = html_entity_decode((string) $value, ENT_QUOTES, 'UTF-8'); |
|
312 | + $i18n_js_strings[ $key ] = wp_strip_all_tags($decoded_value); |
|
313 | + } |
|
314 | + } |
|
315 | + return $i18n_js_strings; |
|
316 | + } |
|
317 | + |
|
318 | + |
|
319 | + /** |
|
320 | + * localize_i18n_js_strings |
|
321 | + * |
|
322 | + * @return string |
|
323 | + */ |
|
324 | + public static function localize_i18n_js_strings() |
|
325 | + { |
|
326 | + $i18n_js_strings = EE_Registry::sanitize_i18n_js_strings(); |
|
327 | + return '/* <![CDATA[ */ var eei18n = ' . wp_json_encode($i18n_js_strings) . '; /* ]]> */'; |
|
328 | + } |
|
329 | + |
|
330 | + |
|
331 | + /** |
|
332 | + * @param mixed string | EED_Module $module |
|
333 | + * @throws OutOfBoundsException |
|
334 | + * @throws InvalidArgumentException |
|
335 | + * @throws InvalidInterfaceException |
|
336 | + * @throws InvalidDataTypeException |
|
337 | + * @throws EE_Error |
|
338 | + * @throws ReflectionException |
|
339 | + */ |
|
340 | + public function add_module($module) |
|
341 | + { |
|
342 | + if ($module instanceof EED_Module) { |
|
343 | + $module_class = get_class($module); |
|
344 | + $this->modules->add($module_class, $module); |
|
345 | + } else { |
|
346 | + if (! class_exists('EE_Module_Request_Router', false)) { |
|
347 | + $this->load_core('Module_Request_Router'); |
|
348 | + } |
|
349 | + EE_Module_Request_Router::module_factory($module); |
|
350 | + } |
|
351 | + } |
|
352 | + |
|
353 | + |
|
354 | + /** |
|
355 | + * @param string $module_name |
|
356 | + * @return mixed EED_Module | NULL |
|
357 | + */ |
|
358 | + public function get_module($module_name = '') |
|
359 | + { |
|
360 | + return $this->modules->get($module_name); |
|
361 | + } |
|
362 | + |
|
363 | + |
|
364 | + /** |
|
365 | + * loads core classes - must be singletons |
|
366 | + * |
|
367 | + * @param string $class_name - simple class name ie: session |
|
368 | + * @param mixed $arguments |
|
369 | + * @param bool $load_only |
|
370 | + * @return mixed |
|
371 | + * @throws InvalidInterfaceException |
|
372 | + * @throws InvalidDataTypeException |
|
373 | + * @throws EE_Error |
|
374 | + * @throws ReflectionException |
|
375 | + * @throws InvalidArgumentException |
|
376 | + */ |
|
377 | + public function load_core($class_name, $arguments = array(), $load_only = false) |
|
378 | + { |
|
379 | + $core_paths = apply_filters( |
|
380 | + 'FHEE__EE_Registry__load_core__core_paths', |
|
381 | + array( |
|
382 | + EE_CORE, |
|
383 | + EE_ADMIN, |
|
384 | + EE_CPTS, |
|
385 | + EE_CORE . 'CPTs/', |
|
386 | + EE_CORE . 'data_migration_scripts/', |
|
387 | + EE_CORE . 'request_stack/', |
|
388 | + EE_CORE . 'middleware/', |
|
389 | + ) |
|
390 | + ); |
|
391 | + // retrieve instantiated class |
|
392 | + return $this->_load( |
|
393 | + $core_paths, |
|
394 | + 'EE_', |
|
395 | + $class_name, |
|
396 | + 'core', |
|
397 | + $arguments, |
|
398 | + false, |
|
399 | + true, |
|
400 | + $load_only |
|
401 | + ); |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + /** |
|
406 | + * loads service classes |
|
407 | + * |
|
408 | + * @param string $class_name - simple class name ie: session |
|
409 | + * @param mixed $arguments |
|
410 | + * @param bool $load_only |
|
411 | + * @return mixed |
|
412 | + * @throws InvalidInterfaceException |
|
413 | + * @throws InvalidDataTypeException |
|
414 | + * @throws EE_Error |
|
415 | + * @throws ReflectionException |
|
416 | + * @throws InvalidArgumentException |
|
417 | + */ |
|
418 | + public function load_service($class_name, $arguments = array(), $load_only = false) |
|
419 | + { |
|
420 | + $service_paths = apply_filters( |
|
421 | + 'FHEE__EE_Registry__load_service__service_paths', |
|
422 | + array( |
|
423 | + EE_CORE . 'services/', |
|
424 | + ) |
|
425 | + ); |
|
426 | + // retrieve instantiated class |
|
427 | + return $this->_load( |
|
428 | + $service_paths, |
|
429 | + 'EE_', |
|
430 | + $class_name, |
|
431 | + 'class', |
|
432 | + $arguments, |
|
433 | + false, |
|
434 | + true, |
|
435 | + $load_only |
|
436 | + ); |
|
437 | + } |
|
438 | + |
|
439 | + |
|
440 | + /** |
|
441 | + * loads data_migration_scripts |
|
442 | + * |
|
443 | + * @param string $class_name - class name for the DMS ie: EE_DMS_Core_4_2_0 |
|
444 | + * @param mixed $arguments |
|
445 | + * @return EE_Data_Migration_Script_Base|mixed |
|
446 | + * @throws InvalidInterfaceException |
|
447 | + * @throws InvalidDataTypeException |
|
448 | + * @throws EE_Error |
|
449 | + * @throws ReflectionException |
|
450 | + * @throws InvalidArgumentException |
|
451 | + */ |
|
452 | + public function load_dms($class_name, $arguments = array()) |
|
453 | + { |
|
454 | + // retrieve instantiated class |
|
455 | + return $this->_load( |
|
456 | + EE_Data_Migration_Manager::instance()->get_data_migration_script_folders(), |
|
457 | + 'EE_DMS_', |
|
458 | + $class_name, |
|
459 | + 'dms', |
|
460 | + $arguments, |
|
461 | + false, |
|
462 | + false |
|
463 | + ); |
|
464 | + } |
|
465 | + |
|
466 | + |
|
467 | + /** |
|
468 | + * loads object creating classes - must be singletons |
|
469 | + * |
|
470 | + * @param string $class_name - simple class name ie: attendee |
|
471 | + * @param mixed $arguments - an array of arguments to pass to the class |
|
472 | + * @param bool $from_db - some classes are instantiated from the db and thus call a different method to |
|
473 | + * instantiate |
|
474 | + * @param bool $cache if you don't want the class to be stored in the internal cache (non-persistent) then |
|
475 | + * set this to FALSE (ie. when instantiating model objects from client in a loop) |
|
476 | + * @param bool $load_only whether or not to just load the file and NOT instantiate, or load AND instantiate |
|
477 | + * (default) |
|
478 | + * @return EE_Base_Class | bool |
|
479 | + * @throws InvalidInterfaceException |
|
480 | + * @throws InvalidDataTypeException |
|
481 | + * @throws EE_Error |
|
482 | + * @throws ReflectionException |
|
483 | + * @throws InvalidArgumentException |
|
484 | + */ |
|
485 | + public function load_class($class_name, $arguments = array(), $from_db = false, $cache = true, $load_only = false) |
|
486 | + { |
|
487 | + $paths = apply_filters( |
|
488 | + 'FHEE__EE_Registry__load_class__paths', |
|
489 | + array( |
|
490 | + EE_CORE, |
|
491 | + EE_CLASSES, |
|
492 | + EE_BUSINESS, |
|
493 | + ) |
|
494 | + ); |
|
495 | + // retrieve instantiated class |
|
496 | + return $this->_load( |
|
497 | + $paths, |
|
498 | + 'EE_', |
|
499 | + $class_name, |
|
500 | + 'class', |
|
501 | + $arguments, |
|
502 | + $from_db, |
|
503 | + $cache, |
|
504 | + $load_only |
|
505 | + ); |
|
506 | + } |
|
507 | + |
|
508 | + |
|
509 | + /** |
|
510 | + * loads helper classes - must be singletons |
|
511 | + * |
|
512 | + * @param string $class_name - simple class name ie: price |
|
513 | + * @param mixed $arguments |
|
514 | + * @param bool $load_only |
|
515 | + * @return EEH_Base | bool |
|
516 | + * @throws InvalidInterfaceException |
|
517 | + * @throws InvalidDataTypeException |
|
518 | + * @throws EE_Error |
|
519 | + * @throws ReflectionException |
|
520 | + * @throws InvalidArgumentException |
|
521 | + */ |
|
522 | + public function load_helper($class_name, $arguments = array(), $load_only = true) |
|
523 | + { |
|
524 | + // todo: add doing_it_wrong() in a few versions after all addons have had calls to this method removed |
|
525 | + $helper_paths = apply_filters('FHEE__EE_Registry__load_helper__helper_paths', array(EE_HELPERS)); |
|
526 | + // retrieve instantiated class |
|
527 | + return $this->_load( |
|
528 | + $helper_paths, |
|
529 | + 'EEH_', |
|
530 | + $class_name, |
|
531 | + 'helper', |
|
532 | + $arguments, |
|
533 | + false, |
|
534 | + true, |
|
535 | + $load_only |
|
536 | + ); |
|
537 | + } |
|
538 | + |
|
539 | + |
|
540 | + /** |
|
541 | + * loads core classes - must be singletons |
|
542 | + * |
|
543 | + * @param string $class_name - simple class name ie: session |
|
544 | + * @param mixed $arguments |
|
545 | + * @param bool $load_only |
|
546 | + * @param bool $cache whether to cache the object or not. |
|
547 | + * @return mixed |
|
548 | + * @throws InvalidInterfaceException |
|
549 | + * @throws InvalidDataTypeException |
|
550 | + * @throws EE_Error |
|
551 | + * @throws ReflectionException |
|
552 | + * @throws InvalidArgumentException |
|
553 | + */ |
|
554 | + public function load_lib($class_name, $arguments = array(), $load_only = false, $cache = true) |
|
555 | + { |
|
556 | + $paths = array( |
|
557 | + EE_LIBRARIES, |
|
558 | + EE_LIBRARIES . 'messages/', |
|
559 | + EE_LIBRARIES . 'shortcodes/', |
|
560 | + EE_LIBRARIES . 'qtips/', |
|
561 | + EE_LIBRARIES . 'payment_methods/', |
|
562 | + ); |
|
563 | + // retrieve instantiated class |
|
564 | + return $this->_load( |
|
565 | + $paths, |
|
566 | + 'EE_', |
|
567 | + $class_name, |
|
568 | + 'lib', |
|
569 | + $arguments, |
|
570 | + false, |
|
571 | + $cache, |
|
572 | + $load_only |
|
573 | + ); |
|
574 | + } |
|
575 | + |
|
576 | + |
|
577 | + /** |
|
578 | + * loads model classes - must be singletons |
|
579 | + * |
|
580 | + * @param string $class_name - simple class name ie: price |
|
581 | + * @param mixed $arguments |
|
582 | + * @param bool $load_only |
|
583 | + * @return mixed |
|
584 | + * @throws InvalidInterfaceException |
|
585 | + * @throws InvalidDataTypeException |
|
586 | + * @throws EE_Error |
|
587 | + * @throws ReflectionException |
|
588 | + * @throws InvalidArgumentException |
|
589 | + */ |
|
590 | + public function load_model($class_name, $arguments = array(), $load_only = false) |
|
591 | + { |
|
592 | + $paths = apply_filters( |
|
593 | + 'FHEE__EE_Registry__load_model__paths', |
|
594 | + array( |
|
595 | + EE_MODELS, |
|
596 | + EE_CORE, |
|
597 | + ) |
|
598 | + ); |
|
599 | + // retrieve instantiated class |
|
600 | + return $this->_load( |
|
601 | + $paths, |
|
602 | + 'EEM_', |
|
603 | + $class_name, |
|
604 | + 'model', |
|
605 | + $arguments, |
|
606 | + false, |
|
607 | + true, |
|
608 | + $load_only |
|
609 | + ); |
|
610 | + } |
|
611 | + |
|
612 | + |
|
613 | + /** |
|
614 | + * loads model classes - must be singletons |
|
615 | + * |
|
616 | + * @param string $class_name - simple class name ie: price |
|
617 | + * @param mixed $arguments |
|
618 | + * @param bool $load_only |
|
619 | + * @return mixed | bool |
|
620 | + * @throws InvalidInterfaceException |
|
621 | + * @throws InvalidDataTypeException |
|
622 | + * @throws EE_Error |
|
623 | + * @throws ReflectionException |
|
624 | + * @throws InvalidArgumentException |
|
625 | + */ |
|
626 | + public function load_model_class($class_name, $arguments = array(), $load_only = true) |
|
627 | + { |
|
628 | + $paths = array( |
|
629 | + EE_MODELS . 'fields/', |
|
630 | + EE_MODELS . 'helpers/', |
|
631 | + EE_MODELS . 'relations/', |
|
632 | + EE_MODELS . 'strategies/', |
|
633 | + ); |
|
634 | + // retrieve instantiated class |
|
635 | + return $this->_load( |
|
636 | + $paths, |
|
637 | + 'EE_', |
|
638 | + $class_name, |
|
639 | + '', |
|
640 | + $arguments, |
|
641 | + false, |
|
642 | + true, |
|
643 | + $load_only |
|
644 | + ); |
|
645 | + } |
|
646 | + |
|
647 | + |
|
648 | + /** |
|
649 | + * Determines if $model_name is the name of an actual EE model. |
|
650 | + * |
|
651 | + * @param string $model_name like Event, Attendee, Question_Group_Question, etc. |
|
652 | + * @return boolean |
|
653 | + */ |
|
654 | + public function is_model_name($model_name) |
|
655 | + { |
|
656 | + return isset($this->models[ $model_name ]); |
|
657 | + } |
|
658 | + |
|
659 | + |
|
660 | + /** |
|
661 | + * generic class loader |
|
662 | + * |
|
663 | + * @param string $path_to_file - directory path to file location, not including filename |
|
664 | + * @param string $file_name - file name ie: my_file.php, including extension |
|
665 | + * @param string $type - file type - core? class? helper? model? |
|
666 | + * @param mixed $arguments |
|
667 | + * @param bool $load_only |
|
668 | + * @return mixed |
|
669 | + * @throws InvalidInterfaceException |
|
670 | + * @throws InvalidDataTypeException |
|
671 | + * @throws EE_Error |
|
672 | + * @throws ReflectionException |
|
673 | + * @throws InvalidArgumentException |
|
674 | + */ |
|
675 | + public function load_file($path_to_file, $file_name, $type = '', $arguments = array(), $load_only = true) |
|
676 | + { |
|
677 | + // retrieve instantiated class |
|
678 | + return $this->_load( |
|
679 | + $path_to_file, |
|
680 | + '', |
|
681 | + $file_name, |
|
682 | + $type, |
|
683 | + $arguments, |
|
684 | + false, |
|
685 | + true, |
|
686 | + $load_only |
|
687 | + ); |
|
688 | + } |
|
689 | + |
|
690 | + |
|
691 | + /** |
|
692 | + * @param string $path_to_file - directory path to file location, not including filename |
|
693 | + * @param string $class_name - full class name ie: My_Class |
|
694 | + * @param string $type - file type - core? class? helper? model? |
|
695 | + * @param mixed $arguments |
|
696 | + * @param bool $load_only |
|
697 | + * @return bool|EE_Addon|object |
|
698 | + * @throws InvalidInterfaceException |
|
699 | + * @throws InvalidDataTypeException |
|
700 | + * @throws EE_Error |
|
701 | + * @throws ReflectionException |
|
702 | + * @throws InvalidArgumentException |
|
703 | + */ |
|
704 | + public function load_addon($path_to_file, $class_name, $type = 'class', $arguments = array(), $load_only = false) |
|
705 | + { |
|
706 | + // retrieve instantiated class |
|
707 | + return $this->_load( |
|
708 | + $path_to_file, |
|
709 | + 'addon', |
|
710 | + $class_name, |
|
711 | + $type, |
|
712 | + $arguments, |
|
713 | + false, |
|
714 | + true, |
|
715 | + $load_only |
|
716 | + ); |
|
717 | + } |
|
718 | + |
|
719 | + |
|
720 | + /** |
|
721 | + * instantiates, caches, and automatically resolves dependencies |
|
722 | + * for classes that use a Fully Qualified Class Name. |
|
723 | + * if the class is not capable of being loaded using PSR-4 autoloading, |
|
724 | + * then you need to use one of the existing load_*() methods |
|
725 | + * which can resolve the classname and filepath from the passed arguments |
|
726 | + * |
|
727 | + * @param bool|string $class_name Fully Qualified Class Name |
|
728 | + * @param array $arguments an argument, or array of arguments to pass to the class upon instantiation |
|
729 | + * @param bool $cache whether to cache the instantiated object for reuse |
|
730 | + * @param bool $from_db some classes are instantiated from the db |
|
731 | + * and thus call a different method to instantiate |
|
732 | + * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
733 | + * @param bool|string $addon if true, will cache the object in the EE_Registry->$addons array |
|
734 | + * @return bool|null|mixed null = failure to load or instantiate class object. |
|
735 | + * object = class loaded and instantiated successfully. |
|
736 | + * bool = fail or success when $load_only is true |
|
737 | + * @throws InvalidInterfaceException |
|
738 | + * @throws InvalidDataTypeException |
|
739 | + * @throws EE_Error |
|
740 | + * @throws ReflectionException |
|
741 | + * @throws InvalidArgumentException |
|
742 | + */ |
|
743 | + public function create( |
|
744 | + $class_name = false, |
|
745 | + $arguments = array(), |
|
746 | + $cache = false, |
|
747 | + $from_db = false, |
|
748 | + $load_only = false, |
|
749 | + $addon = false |
|
750 | + ) { |
|
751 | + $class_name = ltrim($class_name, '\\'); |
|
752 | + $class_name = $this->class_cache->getFqnForAlias($class_name); |
|
753 | + $class_exists = $this->loadOrVerifyClassExists($class_name, $arguments); |
|
754 | + // if a non-FQCN was passed, then |
|
755 | + // verifyClassExists() might return an object |
|
756 | + // or it could return null if the class just could not be found anywhere |
|
757 | + if ($class_exists instanceof $class_name || $class_exists === null) { |
|
758 | + // either way, return the results |
|
759 | + return $class_exists; |
|
760 | + } |
|
761 | + $class_name = $class_exists; |
|
762 | + // if we're only loading the class and it already exists, then let's just return true immediately |
|
763 | + if ($load_only) { |
|
764 | + return true; |
|
765 | + } |
|
766 | + $addon = $addon ? 'addon' : ''; |
|
767 | + // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
768 | + // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
769 | + // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
770 | + if ($this->_cache_on && $cache && ! $load_only) { |
|
771 | + // return object if it's already cached |
|
772 | + $cached_class = $this->_get_cached_class($class_name, $addon, $arguments); |
|
773 | + if ($cached_class !== null) { |
|
774 | + return $cached_class; |
|
775 | + } |
|
776 | + }// obtain the loader method from the dependency map |
|
777 | + $loader = $this->_dependency_map->class_loader($class_name);// instantiate the requested object |
|
778 | + if ($loader instanceof Closure) { |
|
779 | + $class_obj = $loader($arguments); |
|
780 | + } else { |
|
781 | + if ($loader && method_exists($this, $loader)) { |
|
782 | + $class_obj = $this->{$loader}($class_name, $arguments); |
|
783 | + } else { |
|
784 | + $class_obj = $this->_create_object($class_name, $arguments, $addon, $from_db); |
|
785 | + } |
|
786 | + } |
|
787 | + if (($this->_cache_on && $cache) || $this->get_class_abbreviation($class_name, '')) { |
|
788 | + // save it for later... kinda like gum { : $ |
|
789 | + $this->_set_cached_class( |
|
790 | + $class_obj, |
|
791 | + $class_name, |
|
792 | + $addon, |
|
793 | + $from_db, |
|
794 | + $arguments |
|
795 | + ); |
|
796 | + } |
|
797 | + $this->_cache_on = true; |
|
798 | + return $class_obj; |
|
799 | + } |
|
800 | + |
|
801 | + |
|
802 | + /** |
|
803 | + * Recursively checks that a class exists and potentially attempts to load classes with non-FQCNs |
|
804 | + * |
|
805 | + * @param string|object $class_name |
|
806 | + * @param array $arguments |
|
807 | + * @param int $attempt |
|
808 | + * @return mixed |
|
809 | + */ |
|
810 | + private function loadOrVerifyClassExists($class_name, array $arguments, $attempt = 1) |
|
811 | + { |
|
812 | + if (is_object($class_name) || class_exists($class_name)) { |
|
813 | + return $class_name; |
|
814 | + } |
|
815 | + switch ($attempt) { |
|
816 | + case 1: |
|
817 | + // if it's a FQCN then maybe the class is registered with a preceding \ |
|
818 | + $class_name = strpos($class_name, '\\') !== false |
|
819 | + ? '\\' . ltrim($class_name, '\\') |
|
820 | + : $class_name; |
|
821 | + break; |
|
822 | + case 2: |
|
823 | + // |
|
824 | + $loader = $this->_dependency_map->class_loader($class_name); |
|
825 | + if ($loader && method_exists($this, $loader)) { |
|
826 | + return $this->{$loader}($class_name, $arguments); |
|
827 | + } |
|
828 | + break; |
|
829 | + case 3: |
|
830 | + default: |
|
831 | + return null; |
|
832 | + } |
|
833 | + $attempt++; |
|
834 | + return $this->loadOrVerifyClassExists($class_name, $arguments, $attempt); |
|
835 | + } |
|
836 | + |
|
837 | + |
|
838 | + /** |
|
839 | + * instantiates, caches, and injects dependencies for classes |
|
840 | + * |
|
841 | + * @param array $file_paths an array of paths to folders to look in |
|
842 | + * @param string $class_prefix EE or EEM or... ??? |
|
843 | + * @param bool|string $class_name $class name |
|
844 | + * @param string $type file type - core? class? helper? model? |
|
845 | + * @param mixed $arguments an argument or array of arguments to pass to the class upon instantiation |
|
846 | + * @param bool $from_db some classes are instantiated from the db |
|
847 | + * and thus call a different method to instantiate |
|
848 | + * @param bool $cache whether to cache the instantiated object for reuse |
|
849 | + * @param bool $load_only if true, will only load the file, but will NOT instantiate an object |
|
850 | + * @return bool|null|object null = failure to load or instantiate class object. |
|
851 | + * object = class loaded and instantiated successfully. |
|
852 | + * bool = fail or success when $load_only is true |
|
853 | + * @throws EE_Error |
|
854 | + * @throws ReflectionException |
|
855 | + * @throws InvalidInterfaceException |
|
856 | + * @throws InvalidDataTypeException |
|
857 | + * @throws InvalidArgumentException |
|
858 | + */ |
|
859 | + protected function _load( |
|
860 | + $file_paths = array(), |
|
861 | + $class_prefix = 'EE_', |
|
862 | + $class_name = false, |
|
863 | + $type = 'class', |
|
864 | + $arguments = array(), |
|
865 | + $from_db = false, |
|
866 | + $cache = true, |
|
867 | + $load_only = false |
|
868 | + ) { |
|
869 | + $class_name = ltrim($class_name, '\\'); |
|
870 | + // strip php file extension |
|
871 | + $class_name = str_replace('.php', '', trim($class_name)); |
|
872 | + // does the class have a prefix ? |
|
873 | + if (! empty($class_prefix) && $class_prefix !== 'addon') { |
|
874 | + // make sure $class_prefix is uppercase |
|
875 | + $class_prefix = strtoupper(trim($class_prefix)); |
|
876 | + // add class prefix ONCE!!! |
|
877 | + $class_name = $class_prefix . str_replace($class_prefix, '', $class_name); |
|
878 | + } |
|
879 | + $class_name = $this->class_cache->getFqnForAlias($class_name); |
|
880 | + $class_exists = class_exists($class_name, false); |
|
881 | + // if we're only loading the class and it already exists, then let's just return true immediately |
|
882 | + if ($load_only && $class_exists) { |
|
883 | + return true; |
|
884 | + } |
|
885 | + $arguments = is_array($arguments) ? $arguments : array($arguments); |
|
886 | + // $this->_cache_on is toggled during the recursive loading that can occur with dependency injection |
|
887 | + // $cache is controlled by individual calls to separate Registry loader methods like load_class() |
|
888 | + // $load_only is also controlled by individual calls to separate Registry loader methods like load_file() |
|
889 | + if ($this->_cache_on && $cache && ! $load_only) { |
|
890 | + // return object if it's already cached |
|
891 | + $cached_class = $this->_get_cached_class($class_name, $class_prefix, $arguments); |
|
892 | + if ($cached_class !== null) { |
|
893 | + return $cached_class; |
|
894 | + } |
|
895 | + } |
|
896 | + // if the class doesn't already exist.. then we need to try and find the file and load it |
|
897 | + if (! $class_exists) { |
|
898 | + // get full path to file |
|
899 | + $path = $this->_resolve_path($class_name, $type, $file_paths); |
|
900 | + // load the file |
|
901 | + $loaded = $this->_require_file($path, $class_name, $type, $file_paths); |
|
902 | + // if we are only loading a file but NOT instantiating an object |
|
903 | + // then return boolean for whether class was loaded or not |
|
904 | + if ($load_only) { |
|
905 | + return $loaded; |
|
906 | + } |
|
907 | + // if an object was expected but loading failed, then return nothing |
|
908 | + if (! $loaded) { |
|
909 | + return null; |
|
910 | + } |
|
911 | + } |
|
912 | + // instantiate the requested object |
|
913 | + $class_obj = $this->_create_object($class_name, $arguments, $type, $from_db); |
|
914 | + if ($this->_cache_on && $cache) { |
|
915 | + // save it for later... kinda like gum { : $ |
|
916 | + $this->_set_cached_class( |
|
917 | + $class_obj, |
|
918 | + $class_name, |
|
919 | + $class_prefix, |
|
920 | + $from_db, |
|
921 | + $arguments |
|
922 | + ); |
|
923 | + } |
|
924 | + $this->_cache_on = true; |
|
925 | + return $class_obj; |
|
926 | + } |
|
927 | + |
|
928 | + |
|
929 | + /** |
|
930 | + * @param string $class_name |
|
931 | + * @param string $default have to specify something, but not anything that will conflict |
|
932 | + * @return mixed|string |
|
933 | + */ |
|
934 | + protected function get_class_abbreviation($class_name, $default = 'FANCY_BATMAN_PANTS') |
|
935 | + { |
|
936 | + return isset($this->_class_abbreviations[ $class_name ]) |
|
937 | + ? $this->_class_abbreviations[ $class_name ] |
|
938 | + : $default; |
|
939 | + } |
|
940 | + |
|
941 | + |
|
942 | + /** |
|
943 | + * attempts to find a cached version of the requested class |
|
944 | + * by looking in the following places: |
|
945 | + * $this->{$class_abbreviation} ie: $this->CART |
|
946 | + * $this->{$class_name} ie: $this->Some_Class |
|
947 | + * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
948 | + * $this->addon->{$class_name} ie: $this->addon->Some_Addon_Class |
|
949 | + * |
|
950 | + * @param string $class_name |
|
951 | + * @param string $class_prefix |
|
952 | + * @param array $arguments |
|
953 | + * @return mixed |
|
954 | + */ |
|
955 | + protected function _get_cached_class( |
|
956 | + $class_name, |
|
957 | + $class_prefix = '', |
|
958 | + $arguments = array() |
|
959 | + ) { |
|
960 | + if ($class_name === 'EE_Registry') { |
|
961 | + return $this; |
|
962 | + } |
|
963 | + $class_abbreviation = $this->get_class_abbreviation($class_name); |
|
964 | + // check if class has already been loaded, and return it if it has been |
|
965 | + if (isset($this->{$class_abbreviation})) { |
|
966 | + return $this->{$class_abbreviation}; |
|
967 | + } |
|
968 | + $class_name = str_replace('\\', '_', $class_name); |
|
969 | + if (isset($this->{$class_name})) { |
|
970 | + return $this->{$class_name}; |
|
971 | + } |
|
972 | + if ($class_prefix === 'addon' && $this->addons->has($class_name)) { |
|
973 | + return $this->addons->get($class_name); |
|
974 | + } |
|
975 | + $object_identifier = $this->object_identifier->getIdentifier($class_name, $arguments); |
|
976 | + if ($this->LIB->has($object_identifier)) { |
|
977 | + return $this->LIB->get($object_identifier); |
|
978 | + } |
|
979 | + foreach ($this->LIB as $key => $object) { |
|
980 | + if ( |
|
981 | 981 | // request does not contain new arguments and therefore no args identifier |
982 | - ! $this->object_identifier->hasArguments($object_identifier) |
|
983 | - // but previously cached class with args was found |
|
984 | - && $this->object_identifier->fqcnMatchesObjectIdentifier($class_name, $key) |
|
985 | - ) { |
|
986 | - return $object; |
|
987 | - } |
|
988 | - } |
|
989 | - return null; |
|
990 | - } |
|
991 | - |
|
992 | - |
|
993 | - /** |
|
994 | - * removes a cached version of the requested class |
|
995 | - * |
|
996 | - * @param string $class_name |
|
997 | - * @param boolean $addon |
|
998 | - * @param array $arguments |
|
999 | - * @return boolean |
|
1000 | - */ |
|
1001 | - public function clear_cached_class( |
|
1002 | - $class_name, |
|
1003 | - $addon = false, |
|
1004 | - $arguments = array() |
|
1005 | - ) { |
|
1006 | - $class_abbreviation = $this->get_class_abbreviation($class_name); |
|
1007 | - // check if class has already been loaded, and return it if it has been |
|
1008 | - if (isset($this->{$class_abbreviation})) { |
|
1009 | - $this->{$class_abbreviation} = null; |
|
1010 | - return true; |
|
1011 | - } |
|
1012 | - $class_name = str_replace('\\', '_', $class_name); |
|
1013 | - if (isset($this->{$class_name})) { |
|
1014 | - $this->{$class_name} = null; |
|
1015 | - return true; |
|
1016 | - } |
|
1017 | - if ($addon && $this->addons->has($class_name)) { |
|
1018 | - $this->addons->remove($class_name); |
|
1019 | - return true; |
|
1020 | - } |
|
1021 | - $class_name = $this->object_identifier->getIdentifier($class_name, $arguments); |
|
1022 | - if ($this->LIB->has($class_name)) { |
|
1023 | - $this->LIB->remove($class_name); |
|
1024 | - return true; |
|
1025 | - } |
|
1026 | - return false; |
|
1027 | - } |
|
1028 | - |
|
1029 | - |
|
1030 | - /** |
|
1031 | - * _set_cached_class |
|
1032 | - * attempts to cache the instantiated class locally |
|
1033 | - * in one of the following places, in the following order: |
|
1034 | - * $this->{class_abbreviation} ie: $this->CART |
|
1035 | - * $this->{$class_name} ie: $this->Some_Class |
|
1036 | - * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
|
1037 | - * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
1038 | - * |
|
1039 | - * @param object $class_obj |
|
1040 | - * @param string $class_name |
|
1041 | - * @param string $class_prefix |
|
1042 | - * @param bool $from_db |
|
1043 | - * @param array $arguments |
|
1044 | - * @return void |
|
1045 | - */ |
|
1046 | - protected function _set_cached_class( |
|
1047 | - $class_obj, |
|
1048 | - $class_name, |
|
1049 | - $class_prefix = '', |
|
1050 | - $from_db = false, |
|
1051 | - $arguments = array() |
|
1052 | - ) { |
|
1053 | - if ($class_name === 'EE_Registry' || empty($class_obj)) { |
|
1054 | - return; |
|
1055 | - } |
|
1056 | - // return newly instantiated class |
|
1057 | - $class_abbreviation = $this->get_class_abbreviation($class_name, ''); |
|
1058 | - if ($class_abbreviation) { |
|
1059 | - $this->{$class_abbreviation} = $class_obj; |
|
1060 | - return; |
|
1061 | - } |
|
1062 | - $class_name = str_replace('\\', '_', $class_name); |
|
1063 | - if (property_exists($this, $class_name)) { |
|
1064 | - $this->{$class_name} = $class_obj; |
|
1065 | - return; |
|
1066 | - } |
|
1067 | - if ($class_prefix === 'addon') { |
|
1068 | - $this->addons->add($class_name, $class_obj); |
|
1069 | - return; |
|
1070 | - } |
|
1071 | - if (! $from_db) { |
|
1072 | - $class_name = $this->object_identifier->getIdentifier($class_name, $arguments); |
|
1073 | - $this->LIB->add($class_name, $class_obj); |
|
1074 | - } |
|
1075 | - } |
|
1076 | - |
|
1077 | - |
|
1078 | - /** |
|
1079 | - * attempts to find a full valid filepath for the requested class. |
|
1080 | - * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
|
1081 | - * then returns that path if the target file has been found and is readable |
|
1082 | - * |
|
1083 | - * @param string $class_name |
|
1084 | - * @param string $type |
|
1085 | - * @param array $file_paths |
|
1086 | - * @return string | bool |
|
1087 | - */ |
|
1088 | - protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
|
1089 | - { |
|
1090 | - // make sure $file_paths is an array |
|
1091 | - $file_paths = is_array($file_paths) |
|
1092 | - ? $file_paths |
|
1093 | - : array($file_paths); |
|
1094 | - // cycle thru paths |
|
1095 | - foreach ($file_paths as $key => $file_path) { |
|
1096 | - // convert all separators to proper /, if no filepath, then use EE_CLASSES |
|
1097 | - $file_path = $file_path |
|
1098 | - ? str_replace(array('/', '\\'), '/', $file_path) |
|
1099 | - : EE_CLASSES; |
|
1100 | - // prep file type |
|
1101 | - $type = ! empty($type) |
|
1102 | - ? trim($type, '.') . '.' |
|
1103 | - : ''; |
|
1104 | - // build full file path |
|
1105 | - $file_paths[ $key ] = rtrim($file_path, '/') . '/' . $class_name . '.' . $type . 'php'; |
|
1106 | - // does the file exist and can be read ? |
|
1107 | - if (is_readable($file_paths[ $key ])) { |
|
1108 | - return $file_paths[ $key ]; |
|
1109 | - } |
|
1110 | - } |
|
1111 | - return false; |
|
1112 | - } |
|
1113 | - |
|
1114 | - |
|
1115 | - /** |
|
1116 | - * basically just performs a require_once() |
|
1117 | - * but with some error handling |
|
1118 | - * |
|
1119 | - * @param string $path |
|
1120 | - * @param string $class_name |
|
1121 | - * @param string $type |
|
1122 | - * @param array $file_paths |
|
1123 | - * @return bool |
|
1124 | - * @throws EE_Error |
|
1125 | - * @throws ReflectionException |
|
1126 | - */ |
|
1127 | - protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
|
1128 | - { |
|
1129 | - $this->resolve_legacy_class_parent($class_name); |
|
1130 | - // don't give up! you gotta... |
|
1131 | - try { |
|
1132 | - // does the file exist and can it be read ? |
|
1133 | - if (! $path) { |
|
1134 | - // just in case the file has already been autoloaded, |
|
1135 | - // but discrepancies in the naming schema are preventing it from |
|
1136 | - // being loaded via one of the EE_Registry::load_*() methods, |
|
1137 | - // then let's try one last hail mary before throwing an exception |
|
1138 | - // and call class_exists() again, but with autoloading turned ON |
|
1139 | - if (class_exists($class_name)) { |
|
1140 | - return true; |
|
1141 | - } |
|
1142 | - // so sorry, can't find the file |
|
1143 | - throw new EE_Error( |
|
1144 | - sprintf( |
|
1145 | - esc_html__( |
|
1146 | - 'The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', |
|
1147 | - 'event_espresso' |
|
1148 | - ), |
|
1149 | - trim($type, '.'), |
|
1150 | - $class_name, |
|
1151 | - '<br />' . implode(',<br />', $file_paths) |
|
1152 | - ) |
|
1153 | - ); |
|
1154 | - } |
|
1155 | - // get the file |
|
1156 | - require_once($path); |
|
1157 | - // if the class isn't already declared somewhere |
|
1158 | - if (class_exists($class_name, false) === false) { |
|
1159 | - // so sorry, not a class |
|
1160 | - throw new EE_Error( |
|
1161 | - sprintf( |
|
1162 | - esc_html__( |
|
1163 | - 'The %s file %s does not appear to contain the %s Class.', |
|
1164 | - 'event_espresso' |
|
1165 | - ), |
|
1166 | - $type, |
|
1167 | - $path, |
|
1168 | - $class_name |
|
1169 | - ) |
|
1170 | - ); |
|
1171 | - } |
|
1172 | - } catch (EE_Error $e) { |
|
1173 | - $e->get_error(); |
|
1174 | - return false; |
|
1175 | - } |
|
1176 | - return true; |
|
1177 | - } |
|
1178 | - |
|
1179 | - |
|
1180 | - /** |
|
1181 | - * Some of our legacy classes that extended a parent class would simply use a require() statement |
|
1182 | - * before their class declaration in order to ensure that the parent class was loaded. |
|
1183 | - * This is not ideal, but it's nearly impossible to determine the parent class of a non-namespaced class, |
|
1184 | - * without triggering a fatal error because the parent class has yet to be loaded and therefore doesn't exist. |
|
1185 | - * |
|
1186 | - * @param string $class_name |
|
1187 | - */ |
|
1188 | - protected function resolve_legacy_class_parent($class_name = '') |
|
1189 | - { |
|
1190 | - try { |
|
1191 | - $legacy_parent_class_map = array( |
|
1192 | - 'EE_Payment_Processor' => 'core/business/EE_Processor_Base.class.php', |
|
1193 | - ); |
|
1194 | - if (isset($legacy_parent_class_map[ $class_name ])) { |
|
1195 | - require_once EE_PLUGIN_DIR_PATH . $legacy_parent_class_map[ $class_name ]; |
|
1196 | - } |
|
1197 | - } catch (Exception $exception) { |
|
1198 | - } |
|
1199 | - } |
|
1200 | - |
|
1201 | - |
|
1202 | - /** |
|
1203 | - * _create_object |
|
1204 | - * Attempts to instantiate the requested class via any of the |
|
1205 | - * commonly used instantiation methods employed throughout EE. |
|
1206 | - * The priority for instantiation is as follows: |
|
1207 | - * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
|
1208 | - * - model objects via their 'new_instance_from_db' method |
|
1209 | - * - model objects via their 'new_instance' method |
|
1210 | - * - "singleton" classes" via their 'instance' method |
|
1211 | - * - standard instantiable classes via their __constructor |
|
1212 | - * Prior to instantiation, if the classname exists in the dependency_map, |
|
1213 | - * then the constructor for the requested class will be examined to determine |
|
1214 | - * if any dependencies exist, and if they can be injected. |
|
1215 | - * If so, then those classes will be added to the array of arguments passed to the constructor |
|
1216 | - * |
|
1217 | - * @param string $class_name |
|
1218 | - * @param array $arguments |
|
1219 | - * @param string $type |
|
1220 | - * @param bool $from_db |
|
1221 | - * @return null|object|bool |
|
1222 | - * @throws InvalidArgumentException |
|
1223 | - * @throws InvalidInterfaceException |
|
1224 | - * @throws EE_Error |
|
1225 | - * @throws ReflectionException |
|
1226 | - * @throws InvalidDataTypeException |
|
1227 | - */ |
|
1228 | - protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
|
1229 | - { |
|
1230 | - // create reflection |
|
1231 | - $reflector = $this->mirror->getReflectionClass($class_name); |
|
1232 | - // make sure arguments are an array |
|
1233 | - $arguments = is_array($arguments) |
|
1234 | - ? $arguments |
|
1235 | - : array($arguments); |
|
1236 | - // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
|
1237 | - // else wrap it in an additional array so that it doesn't get split into multiple parameters |
|
1238 | - $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) |
|
1239 | - ? $arguments |
|
1240 | - : array($arguments); |
|
1241 | - // attempt to inject dependencies ? |
|
1242 | - if ($this->_dependency_map->has($class_name)) { |
|
1243 | - $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); |
|
1244 | - } |
|
1245 | - // instantiate the class if possible |
|
1246 | - if ($reflector->isAbstract()) { |
|
1247 | - // nothing to instantiate, loading file was enough |
|
1248 | - // does not throw an exception so $instantiation_mode is unused |
|
1249 | - // $instantiation_mode = "1) no constructor abstract class"; |
|
1250 | - return true; |
|
1251 | - } |
|
1252 | - if ( |
|
1253 | - empty($arguments) |
|
1254 | - && $this->mirror->getConstructorFromReflection($reflector) === null |
|
1255 | - && $reflector->isInstantiable() |
|
1256 | - ) { |
|
1257 | - // no constructor = static methods only... nothing to instantiate, loading file was enough |
|
1258 | - // $instantiation_mode = "2) no constructor but instantiable"; |
|
1259 | - return $reflector->newInstance(); |
|
1260 | - } |
|
1261 | - if ($from_db && method_exists($class_name, 'new_instance_from_db')) { |
|
1262 | - // $instantiation_mode = "3) new_instance_from_db()"; |
|
1263 | - return call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); |
|
1264 | - } |
|
1265 | - if (method_exists($class_name, 'new_instance')) { |
|
1266 | - // $instantiation_mode = "4) new_instance()"; |
|
1267 | - return call_user_func_array(array($class_name, 'new_instance'), $arguments); |
|
1268 | - } |
|
1269 | - if (method_exists($class_name, 'instance')) { |
|
1270 | - // $instantiation_mode = "5) instance()"; |
|
1271 | - return call_user_func_array(array($class_name, 'instance'), $arguments); |
|
1272 | - } |
|
1273 | - if ($reflector->isInstantiable()) { |
|
1274 | - // $instantiation_mode = "6) constructor"; |
|
1275 | - return $reflector->newInstanceArgs($arguments); |
|
1276 | - } |
|
1277 | - // heh ? something's not right ! |
|
1278 | - throw new EE_Error( |
|
1279 | - sprintf( |
|
1280 | - esc_html__('The %s file %s could not be instantiated.', 'event_espresso'), |
|
1281 | - $type, |
|
1282 | - $class_name |
|
1283 | - ) |
|
1284 | - ); |
|
1285 | - } |
|
1286 | - |
|
1287 | - |
|
1288 | - /** |
|
1289 | - * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
1290 | - * @param array $array |
|
1291 | - * @return bool |
|
1292 | - */ |
|
1293 | - protected function _array_is_numerically_and_sequentially_indexed(array $array) |
|
1294 | - { |
|
1295 | - return ! empty($array) |
|
1296 | - ? array_keys($array) === range(0, count($array) - 1) |
|
1297 | - : true; |
|
1298 | - } |
|
1299 | - |
|
1300 | - |
|
1301 | - /** |
|
1302 | - * _resolve_dependencies |
|
1303 | - * examines the constructor for the requested class to determine |
|
1304 | - * if any dependencies exist, and if they can be injected. |
|
1305 | - * If so, then those classes will be added to the array of arguments passed to the constructor |
|
1306 | - * PLZ NOTE: this is achieved by type hinting the constructor params |
|
1307 | - * For example: |
|
1308 | - * if attempting to load a class "Foo" with the following constructor: |
|
1309 | - * __construct( Bar $bar_class, Fighter $grohl_class ) |
|
1310 | - * then $bar_class and $grohl_class will be added to the $arguments array, |
|
1311 | - * but only IF they are NOT already present in the incoming arguments array, |
|
1312 | - * and the correct classes can be loaded |
|
1313 | - * |
|
1314 | - * @param ReflectionClass $reflector |
|
1315 | - * @param string $class_name |
|
1316 | - * @param array $arguments |
|
1317 | - * @return array |
|
1318 | - * @throws InvalidArgumentException |
|
1319 | - * @throws InvalidDataTypeException |
|
1320 | - * @throws InvalidInterfaceException |
|
1321 | - * @throws ReflectionException |
|
1322 | - */ |
|
1323 | - protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, array $arguments = array()) |
|
1324 | - { |
|
1325 | - // let's examine the constructor |
|
1326 | - $constructor = $this->mirror->getConstructorFromReflection($reflector); |
|
1327 | - // whu? huh? nothing? |
|
1328 | - if (! $constructor) { |
|
1329 | - return $arguments; |
|
1330 | - } |
|
1331 | - // get constructor parameters |
|
1332 | - $params = $this->mirror->getParametersFromReflection($reflector); |
|
1333 | - // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
|
1334 | - $argument_keys = array_keys($arguments); |
|
1335 | - // now loop thru all of the constructors expected parameters |
|
1336 | - foreach ($params as $index => $param) { |
|
1337 | - try { |
|
1338 | - // is this a dependency for a specific class ? |
|
1339 | - $param_class = $this->mirror->getParameterClassName($param, $class_name, $index); |
|
1340 | - } catch (ReflectionException $exception) { |
|
1341 | - // uh-oh... most likely a legacy class that has not been autoloaded |
|
1342 | - // let's try to derive the classname from what we have now |
|
1343 | - // and hope that the property var name is close to the class name |
|
1344 | - $param_class = $param->getName(); |
|
1345 | - $param_class = str_replace('_', ' ', $param_class); |
|
1346 | - $param_class = ucwords($param_class); |
|
1347 | - $param_class = str_replace(' ', '_', $param_class); |
|
1348 | - } |
|
1349 | - // BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime) |
|
1350 | - $param_class = $this->class_cache->isAlias($param_class, $class_name) |
|
1351 | - ? $this->class_cache->getFqnForAlias($param_class, $class_name) |
|
1352 | - : $param_class; |
|
1353 | - if ( |
|
1354 | - // param is not even a class |
|
1355 | - $param_class === null |
|
1356 | - // and something already exists in the incoming arguments for this param |
|
1357 | - && array_key_exists($index, $argument_keys) |
|
1358 | - && array_key_exists($argument_keys[ $index ], $arguments) |
|
1359 | - ) { |
|
1360 | - // so let's skip this argument and move on to the next |
|
1361 | - continue; |
|
1362 | - } |
|
1363 | - if ( |
|
1364 | - // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
|
1365 | - $param_class !== null |
|
1366 | - && isset($argument_keys[ $index ], $arguments[ $argument_keys[ $index ] ]) |
|
1367 | - && $arguments[ $argument_keys[ $index ] ] instanceof $param_class |
|
1368 | - ) { |
|
1369 | - // skip this argument and move on to the next |
|
1370 | - continue; |
|
1371 | - } |
|
1372 | - if ( |
|
1373 | - // parameter is type hinted as a class, and should be injected |
|
1374 | - $param_class !== null |
|
1375 | - && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) |
|
1376 | - ) { |
|
1377 | - $arguments = $this->_resolve_dependency( |
|
1378 | - $class_name, |
|
1379 | - $param_class, |
|
1380 | - $arguments, |
|
1381 | - $index |
|
1382 | - ); |
|
1383 | - } |
|
1384 | - if (empty($arguments[ $index ])) { |
|
1385 | - $default_value = $this->mirror->getParameterDefaultValue( |
|
1386 | - $param, |
|
1387 | - $class_name, |
|
1388 | - $index |
|
1389 | - ); |
|
1390 | - // if there's no default value, and the incoming argument is an array (albeit empty), then use that |
|
1391 | - $arguments[ $index ] = $default_value === null |
|
1392 | - && isset($arguments[ $index ]) |
|
1393 | - && is_array($arguments[ $index ]) |
|
1394 | - ? $arguments[ $index ] |
|
1395 | - : $default_value; |
|
1396 | - } |
|
1397 | - } |
|
1398 | - return $arguments; |
|
1399 | - } |
|
1400 | - |
|
1401 | - |
|
1402 | - /** |
|
1403 | - * @param string $class_name |
|
1404 | - * @param string $param_class |
|
1405 | - * @param array $arguments |
|
1406 | - * @param mixed $index |
|
1407 | - * @return array |
|
1408 | - * @throws InvalidArgumentException |
|
1409 | - * @throws InvalidInterfaceException |
|
1410 | - * @throws InvalidDataTypeException |
|
1411 | - */ |
|
1412 | - protected function _resolve_dependency($class_name, $param_class, $arguments, $index) |
|
1413 | - { |
|
1414 | - $dependency = null; |
|
1415 | - // should dependency be loaded from cache ? |
|
1416 | - $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency( |
|
1417 | - $class_name, |
|
1418 | - $param_class |
|
1419 | - ); |
|
1420 | - $cache_on = $cache_on !== EE_Dependency_Map::load_new_object; |
|
1421 | - // we might have a dependency... |
|
1422 | - // let's MAYBE try and find it in our cache if that's what's been requested |
|
1423 | - $cached_class = $cache_on |
|
1424 | - ? $this->_get_cached_class($param_class) |
|
1425 | - : null; |
|
1426 | - // and grab it if it exists |
|
1427 | - if ($cached_class instanceof $param_class) { |
|
1428 | - $dependency = $cached_class; |
|
1429 | - } elseif ($param_class !== $class_name) { |
|
1430 | - // obtain the loader method from the dependency map |
|
1431 | - $loader = $this->_dependency_map->class_loader($param_class); |
|
1432 | - // is loader a custom closure ? |
|
1433 | - if ($loader instanceof Closure) { |
|
1434 | - $dependency = $loader($arguments); |
|
1435 | - } else { |
|
1436 | - // set the cache on property for the recursive loading call |
|
1437 | - $this->_cache_on = $cache_on; |
|
1438 | - // if not, then let's try and load it via the registry |
|
1439 | - if ($loader && method_exists($this, $loader)) { |
|
1440 | - $dependency = $this->{$loader}($param_class); |
|
1441 | - } else { |
|
1442 | - $dependency = LoaderFactory::getLoader()->load( |
|
1443 | - $param_class, |
|
1444 | - array(), |
|
1445 | - $cache_on |
|
1446 | - ); |
|
1447 | - } |
|
1448 | - } |
|
1449 | - } |
|
1450 | - // did we successfully find the correct dependency ? |
|
1451 | - if ($dependency instanceof $param_class) { |
|
1452 | - // then let's inject it into the incoming array of arguments at the correct location |
|
1453 | - $arguments[ $index ] = $dependency; |
|
1454 | - } |
|
1455 | - return $arguments; |
|
1456 | - } |
|
1457 | - |
|
1458 | - |
|
1459 | - /** |
|
1460 | - * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
|
1461 | - * |
|
1462 | - * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
|
1463 | - * in the EE_Dependency_Map::$_class_loaders array, |
|
1464 | - * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
|
1465 | - * @param array $arguments |
|
1466 | - * @return object |
|
1467 | - */ |
|
1468 | - public static function factory($classname, $arguments = array()) |
|
1469 | - { |
|
1470 | - $loader = self::instance()->_dependency_map->class_loader($classname); |
|
1471 | - if ($loader instanceof Closure) { |
|
1472 | - return $loader($arguments); |
|
1473 | - } |
|
1474 | - if (method_exists(self::instance(), $loader)) { |
|
1475 | - return self::instance()->{$loader}($classname, $arguments); |
|
1476 | - } |
|
1477 | - return null; |
|
1478 | - } |
|
1479 | - |
|
1480 | - |
|
1481 | - /** |
|
1482 | - * Gets the addon by its class name |
|
1483 | - * |
|
1484 | - * @param string $class_name |
|
1485 | - * @return EE_Addon |
|
1486 | - */ |
|
1487 | - public function getAddon($class_name) |
|
1488 | - { |
|
1489 | - $class_name = str_replace('\\', '_', $class_name); |
|
1490 | - if (isset($this->addons->{$class_name})) { |
|
1491 | - return $this->addons->{$class_name}; |
|
1492 | - } else { |
|
1493 | - return null; |
|
1494 | - } |
|
1495 | - } |
|
1496 | - |
|
1497 | - |
|
1498 | - /** |
|
1499 | - * removes the addon from the internal cache |
|
1500 | - * |
|
1501 | - * @param string $class_name |
|
1502 | - * @return void |
|
1503 | - */ |
|
1504 | - public function removeAddon($class_name) |
|
1505 | - { |
|
1506 | - $class_name = str_replace('\\', '_', $class_name); |
|
1507 | - $this->addons->remove($class_name); |
|
1508 | - } |
|
1509 | - |
|
1510 | - |
|
1511 | - /** |
|
1512 | - * Gets the addon by its name/slug (not classname. For that, just |
|
1513 | - * use the get_addon() method above |
|
1514 | - * |
|
1515 | - * @param string $name |
|
1516 | - * @return EE_Addon |
|
1517 | - */ |
|
1518 | - public function get_addon_by_name($name) |
|
1519 | - { |
|
1520 | - foreach ($this->addons as $addon) { |
|
1521 | - if ($addon->name() === $name) { |
|
1522 | - return $addon; |
|
1523 | - } |
|
1524 | - } |
|
1525 | - return null; |
|
1526 | - } |
|
1527 | - |
|
1528 | - |
|
1529 | - /** |
|
1530 | - * Gets an array of all the registered addons, where the keys are their names. |
|
1531 | - * (ie, what each returns for their name() function) |
|
1532 | - * They're already available on EE_Registry::instance()->addons as properties, |
|
1533 | - * where each property's name is the addon's classname, |
|
1534 | - * So if you just want to get the addon by classname, |
|
1535 | - * OR use the get_addon() method above. |
|
1536 | - * PLEASE NOTE: |
|
1537 | - * addons with Fully Qualified Class Names |
|
1538 | - * have had the namespace separators converted to underscores, |
|
1539 | - * so a classname like Fully\Qualified\ClassName |
|
1540 | - * would have been converted to Fully_Qualified_ClassName |
|
1541 | - * |
|
1542 | - * @return EE_Addon[] where the KEYS are the addon's name() |
|
1543 | - */ |
|
1544 | - public function get_addons_by_name() |
|
1545 | - { |
|
1546 | - $addons = array(); |
|
1547 | - foreach ($this->addons as $addon) { |
|
1548 | - $addons[ $addon->name() ] = $addon; |
|
1549 | - } |
|
1550 | - return $addons; |
|
1551 | - } |
|
1552 | - |
|
1553 | - |
|
1554 | - /** |
|
1555 | - * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
|
1556 | - * a stale copy of it around |
|
1557 | - * |
|
1558 | - * @param string $model_name |
|
1559 | - * @return \EEM_Base |
|
1560 | - * @throws \EE_Error |
|
1561 | - */ |
|
1562 | - public function reset_model($model_name) |
|
1563 | - { |
|
1564 | - $model_class_name = strpos($model_name, 'EEM_') !== 0 |
|
1565 | - ? "EEM_{$model_name}" |
|
1566 | - : $model_name; |
|
1567 | - if (! $this->LIB->has($model_class_name)) { |
|
1568 | - return null; |
|
1569 | - } |
|
1570 | - $model = $this->LIB->get($model_class_name); |
|
1571 | - if (! $model instanceof EEM_Base) { |
|
1572 | - return null; |
|
1573 | - } |
|
1574 | - // get that model reset it and make sure we nuke the old reference to it |
|
1575 | - if ($model instanceof $model_class_name && is_callable([$model_class_name, 'reset'])) { |
|
1576 | - $this->LIB->remove($model_class_name); |
|
1577 | - $this->LIB->add($model_class_name, $model->reset()); |
|
1578 | - } else { |
|
1579 | - throw new EE_Error( |
|
1580 | - sprintf( |
|
1581 | - esc_html__('Model %s does not have a method "reset"', 'event_espresso'), |
|
1582 | - $model_name |
|
1583 | - ) |
|
1584 | - ); |
|
1585 | - } |
|
1586 | - return $model; |
|
1587 | - } |
|
1588 | - |
|
1589 | - |
|
1590 | - /** |
|
1591 | - * Resets the registry. |
|
1592 | - * The criteria for what gets reset is based on what can be shared between sites on the same request when |
|
1593 | - * switch_to_blog is used in a multisite install. Here is a list of things that are NOT reset. |
|
1594 | - * - $_dependency_map |
|
1595 | - * - $_class_abbreviations |
|
1596 | - * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
|
1597 | - * - $REQ: Still on the same request so no need to change. |
|
1598 | - * - $CAP: There is no site specific state in the EE_Capability class. |
|
1599 | - * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only |
|
1600 | - * one Session can be active in a single request. Resetting could resolve in "headers already sent" errors. |
|
1601 | - * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
|
1602 | - * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
|
1603 | - * switch or on the restore. |
|
1604 | - * - $modules |
|
1605 | - * - $shortcodes |
|
1606 | - * - $widgets |
|
1607 | - * |
|
1608 | - * @param boolean $hard [deprecated] |
|
1609 | - * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
|
1610 | - * or just reset without re-instantiating (handy to set to FALSE if you're not |
|
1611 | - * sure if you CAN currently reinstantiate the singletons at the moment) |
|
1612 | - * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so |
|
1613 | - * client |
|
1614 | - * code instead can just change the model context to a different blog id if |
|
1615 | - * necessary |
|
1616 | - * @return EE_Registry |
|
1617 | - * @throws InvalidInterfaceException |
|
1618 | - * @throws InvalidDataTypeException |
|
1619 | - * @throws EE_Error |
|
1620 | - * @throws ReflectionException |
|
1621 | - * @throws InvalidArgumentException |
|
1622 | - */ |
|
1623 | - public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
|
1624 | - { |
|
1625 | - $instance = self::instance(); |
|
1626 | - $instance->_cache_on = true; |
|
1627 | - // reset some "special" classes |
|
1628 | - EEH_Activation::reset(); |
|
1629 | - $hard = apply_filters('FHEE__EE_Registry__reset__hard', $hard); |
|
1630 | - $instance->CFG = EE_Config::reset($hard, $reinstantiate); |
|
1631 | - $instance->CART = null; |
|
1632 | - $instance->MRM = null; |
|
1633 | - $instance->AssetsRegistry = LoaderFactory::getLoader()->getShared( |
|
1634 | - 'EventEspresso\core\services\assets\Registry' |
|
1635 | - ); |
|
1636 | - // messages reset |
|
1637 | - EED_Messages::reset(); |
|
1638 | - // handle of objects cached on LIB |
|
1639 | - foreach (array('LIB', 'modules') as $cache) { |
|
1640 | - foreach ($instance->{$cache} as $class_name => $class) { |
|
1641 | - if (self::_reset_and_unset_object($class, $reset_models)) { |
|
1642 | - unset($instance->{$cache}->{$class_name}); |
|
1643 | - } |
|
1644 | - } |
|
1645 | - } |
|
1646 | - return $instance; |
|
1647 | - } |
|
1648 | - |
|
1649 | - |
|
1650 | - /** |
|
1651 | - * if passed object implements ResettableInterface, then call it's reset() method |
|
1652 | - * if passed object implements InterminableInterface, then return false, |
|
1653 | - * to indicate that it should NOT be cleared from the Registry cache |
|
1654 | - * |
|
1655 | - * @param $object |
|
1656 | - * @param bool $reset_models |
|
1657 | - * @return bool returns true if cached object should be unset |
|
1658 | - */ |
|
1659 | - private static function _reset_and_unset_object($object, $reset_models) |
|
1660 | - { |
|
1661 | - if (! is_object($object)) { |
|
1662 | - // don't unset anything that's not an object |
|
1663 | - return false; |
|
1664 | - } |
|
1665 | - if ($object instanceof EED_Module) { |
|
1666 | - $object::reset(); |
|
1667 | - // don't unset modules |
|
1668 | - return false; |
|
1669 | - } |
|
1670 | - if ($object instanceof ResettableInterface) { |
|
1671 | - if ($object instanceof EEM_Base) { |
|
1672 | - if ($reset_models) { |
|
1673 | - $object->reset(); |
|
1674 | - return true; |
|
1675 | - } |
|
1676 | - return false; |
|
1677 | - } |
|
1678 | - $object->reset(); |
|
1679 | - return true; |
|
1680 | - } |
|
1681 | - if (! $object instanceof InterminableInterface) { |
|
1682 | - return true; |
|
1683 | - } |
|
1684 | - return false; |
|
1685 | - } |
|
1686 | - |
|
1687 | - |
|
1688 | - /** |
|
1689 | - * Gets all the custom post type models defined |
|
1690 | - * |
|
1691 | - * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
|
1692 | - */ |
|
1693 | - public function cpt_models() |
|
1694 | - { |
|
1695 | - $cpt_models = array(); |
|
1696 | - foreach ($this->non_abstract_db_models as $short_name => $classname) { |
|
1697 | - if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
|
1698 | - $cpt_models[ $short_name ] = $classname; |
|
1699 | - } |
|
1700 | - } |
|
1701 | - return $cpt_models; |
|
1702 | - } |
|
1703 | - |
|
1704 | - |
|
1705 | - /** |
|
1706 | - * @return \EE_Config |
|
1707 | - */ |
|
1708 | - public static function CFG() |
|
1709 | - { |
|
1710 | - return self::instance()->CFG; |
|
1711 | - } |
|
1712 | - |
|
1713 | - |
|
1714 | - /** |
|
1715 | - * @deprecated 4.9.62.p |
|
1716 | - * @param string $class_name |
|
1717 | - * @return ReflectionClass |
|
1718 | - * @throws ReflectionException |
|
1719 | - * @throws InvalidDataTypeException |
|
1720 | - */ |
|
1721 | - public function get_ReflectionClass($class_name) |
|
1722 | - { |
|
1723 | - return $this->mirror->getReflectionClass($class_name); |
|
1724 | - } |
|
982 | + ! $this->object_identifier->hasArguments($object_identifier) |
|
983 | + // but previously cached class with args was found |
|
984 | + && $this->object_identifier->fqcnMatchesObjectIdentifier($class_name, $key) |
|
985 | + ) { |
|
986 | + return $object; |
|
987 | + } |
|
988 | + } |
|
989 | + return null; |
|
990 | + } |
|
991 | + |
|
992 | + |
|
993 | + /** |
|
994 | + * removes a cached version of the requested class |
|
995 | + * |
|
996 | + * @param string $class_name |
|
997 | + * @param boolean $addon |
|
998 | + * @param array $arguments |
|
999 | + * @return boolean |
|
1000 | + */ |
|
1001 | + public function clear_cached_class( |
|
1002 | + $class_name, |
|
1003 | + $addon = false, |
|
1004 | + $arguments = array() |
|
1005 | + ) { |
|
1006 | + $class_abbreviation = $this->get_class_abbreviation($class_name); |
|
1007 | + // check if class has already been loaded, and return it if it has been |
|
1008 | + if (isset($this->{$class_abbreviation})) { |
|
1009 | + $this->{$class_abbreviation} = null; |
|
1010 | + return true; |
|
1011 | + } |
|
1012 | + $class_name = str_replace('\\', '_', $class_name); |
|
1013 | + if (isset($this->{$class_name})) { |
|
1014 | + $this->{$class_name} = null; |
|
1015 | + return true; |
|
1016 | + } |
|
1017 | + if ($addon && $this->addons->has($class_name)) { |
|
1018 | + $this->addons->remove($class_name); |
|
1019 | + return true; |
|
1020 | + } |
|
1021 | + $class_name = $this->object_identifier->getIdentifier($class_name, $arguments); |
|
1022 | + if ($this->LIB->has($class_name)) { |
|
1023 | + $this->LIB->remove($class_name); |
|
1024 | + return true; |
|
1025 | + } |
|
1026 | + return false; |
|
1027 | + } |
|
1028 | + |
|
1029 | + |
|
1030 | + /** |
|
1031 | + * _set_cached_class |
|
1032 | + * attempts to cache the instantiated class locally |
|
1033 | + * in one of the following places, in the following order: |
|
1034 | + * $this->{class_abbreviation} ie: $this->CART |
|
1035 | + * $this->{$class_name} ie: $this->Some_Class |
|
1036 | + * $this->addon->{$$class_name} ie: $this->addon->Some_Addon_Class |
|
1037 | + * $this->LIB->{$class_name} ie: $this->LIB->Some_Class |
|
1038 | + * |
|
1039 | + * @param object $class_obj |
|
1040 | + * @param string $class_name |
|
1041 | + * @param string $class_prefix |
|
1042 | + * @param bool $from_db |
|
1043 | + * @param array $arguments |
|
1044 | + * @return void |
|
1045 | + */ |
|
1046 | + protected function _set_cached_class( |
|
1047 | + $class_obj, |
|
1048 | + $class_name, |
|
1049 | + $class_prefix = '', |
|
1050 | + $from_db = false, |
|
1051 | + $arguments = array() |
|
1052 | + ) { |
|
1053 | + if ($class_name === 'EE_Registry' || empty($class_obj)) { |
|
1054 | + return; |
|
1055 | + } |
|
1056 | + // return newly instantiated class |
|
1057 | + $class_abbreviation = $this->get_class_abbreviation($class_name, ''); |
|
1058 | + if ($class_abbreviation) { |
|
1059 | + $this->{$class_abbreviation} = $class_obj; |
|
1060 | + return; |
|
1061 | + } |
|
1062 | + $class_name = str_replace('\\', '_', $class_name); |
|
1063 | + if (property_exists($this, $class_name)) { |
|
1064 | + $this->{$class_name} = $class_obj; |
|
1065 | + return; |
|
1066 | + } |
|
1067 | + if ($class_prefix === 'addon') { |
|
1068 | + $this->addons->add($class_name, $class_obj); |
|
1069 | + return; |
|
1070 | + } |
|
1071 | + if (! $from_db) { |
|
1072 | + $class_name = $this->object_identifier->getIdentifier($class_name, $arguments); |
|
1073 | + $this->LIB->add($class_name, $class_obj); |
|
1074 | + } |
|
1075 | + } |
|
1076 | + |
|
1077 | + |
|
1078 | + /** |
|
1079 | + * attempts to find a full valid filepath for the requested class. |
|
1080 | + * loops thru each of the base paths in the $file_paths array and appends : "{classname} . {file type} . php" |
|
1081 | + * then returns that path if the target file has been found and is readable |
|
1082 | + * |
|
1083 | + * @param string $class_name |
|
1084 | + * @param string $type |
|
1085 | + * @param array $file_paths |
|
1086 | + * @return string | bool |
|
1087 | + */ |
|
1088 | + protected function _resolve_path($class_name, $type = '', $file_paths = array()) |
|
1089 | + { |
|
1090 | + // make sure $file_paths is an array |
|
1091 | + $file_paths = is_array($file_paths) |
|
1092 | + ? $file_paths |
|
1093 | + : array($file_paths); |
|
1094 | + // cycle thru paths |
|
1095 | + foreach ($file_paths as $key => $file_path) { |
|
1096 | + // convert all separators to proper /, if no filepath, then use EE_CLASSES |
|
1097 | + $file_path = $file_path |
|
1098 | + ? str_replace(array('/', '\\'), '/', $file_path) |
|
1099 | + : EE_CLASSES; |
|
1100 | + // prep file type |
|
1101 | + $type = ! empty($type) |
|
1102 | + ? trim($type, '.') . '.' |
|
1103 | + : ''; |
|
1104 | + // build full file path |
|
1105 | + $file_paths[ $key ] = rtrim($file_path, '/') . '/' . $class_name . '.' . $type . 'php'; |
|
1106 | + // does the file exist and can be read ? |
|
1107 | + if (is_readable($file_paths[ $key ])) { |
|
1108 | + return $file_paths[ $key ]; |
|
1109 | + } |
|
1110 | + } |
|
1111 | + return false; |
|
1112 | + } |
|
1113 | + |
|
1114 | + |
|
1115 | + /** |
|
1116 | + * basically just performs a require_once() |
|
1117 | + * but with some error handling |
|
1118 | + * |
|
1119 | + * @param string $path |
|
1120 | + * @param string $class_name |
|
1121 | + * @param string $type |
|
1122 | + * @param array $file_paths |
|
1123 | + * @return bool |
|
1124 | + * @throws EE_Error |
|
1125 | + * @throws ReflectionException |
|
1126 | + */ |
|
1127 | + protected function _require_file($path, $class_name, $type = '', $file_paths = array()) |
|
1128 | + { |
|
1129 | + $this->resolve_legacy_class_parent($class_name); |
|
1130 | + // don't give up! you gotta... |
|
1131 | + try { |
|
1132 | + // does the file exist and can it be read ? |
|
1133 | + if (! $path) { |
|
1134 | + // just in case the file has already been autoloaded, |
|
1135 | + // but discrepancies in the naming schema are preventing it from |
|
1136 | + // being loaded via one of the EE_Registry::load_*() methods, |
|
1137 | + // then let's try one last hail mary before throwing an exception |
|
1138 | + // and call class_exists() again, but with autoloading turned ON |
|
1139 | + if (class_exists($class_name)) { |
|
1140 | + return true; |
|
1141 | + } |
|
1142 | + // so sorry, can't find the file |
|
1143 | + throw new EE_Error( |
|
1144 | + sprintf( |
|
1145 | + esc_html__( |
|
1146 | + 'The %1$s file %2$s could not be located or is not readable due to file permissions. Please ensure that the following filepath(s) are correct: %3$s', |
|
1147 | + 'event_espresso' |
|
1148 | + ), |
|
1149 | + trim($type, '.'), |
|
1150 | + $class_name, |
|
1151 | + '<br />' . implode(',<br />', $file_paths) |
|
1152 | + ) |
|
1153 | + ); |
|
1154 | + } |
|
1155 | + // get the file |
|
1156 | + require_once($path); |
|
1157 | + // if the class isn't already declared somewhere |
|
1158 | + if (class_exists($class_name, false) === false) { |
|
1159 | + // so sorry, not a class |
|
1160 | + throw new EE_Error( |
|
1161 | + sprintf( |
|
1162 | + esc_html__( |
|
1163 | + 'The %s file %s does not appear to contain the %s Class.', |
|
1164 | + 'event_espresso' |
|
1165 | + ), |
|
1166 | + $type, |
|
1167 | + $path, |
|
1168 | + $class_name |
|
1169 | + ) |
|
1170 | + ); |
|
1171 | + } |
|
1172 | + } catch (EE_Error $e) { |
|
1173 | + $e->get_error(); |
|
1174 | + return false; |
|
1175 | + } |
|
1176 | + return true; |
|
1177 | + } |
|
1178 | + |
|
1179 | + |
|
1180 | + /** |
|
1181 | + * Some of our legacy classes that extended a parent class would simply use a require() statement |
|
1182 | + * before their class declaration in order to ensure that the parent class was loaded. |
|
1183 | + * This is not ideal, but it's nearly impossible to determine the parent class of a non-namespaced class, |
|
1184 | + * without triggering a fatal error because the parent class has yet to be loaded and therefore doesn't exist. |
|
1185 | + * |
|
1186 | + * @param string $class_name |
|
1187 | + */ |
|
1188 | + protected function resolve_legacy_class_parent($class_name = '') |
|
1189 | + { |
|
1190 | + try { |
|
1191 | + $legacy_parent_class_map = array( |
|
1192 | + 'EE_Payment_Processor' => 'core/business/EE_Processor_Base.class.php', |
|
1193 | + ); |
|
1194 | + if (isset($legacy_parent_class_map[ $class_name ])) { |
|
1195 | + require_once EE_PLUGIN_DIR_PATH . $legacy_parent_class_map[ $class_name ]; |
|
1196 | + } |
|
1197 | + } catch (Exception $exception) { |
|
1198 | + } |
|
1199 | + } |
|
1200 | + |
|
1201 | + |
|
1202 | + /** |
|
1203 | + * _create_object |
|
1204 | + * Attempts to instantiate the requested class via any of the |
|
1205 | + * commonly used instantiation methods employed throughout EE. |
|
1206 | + * The priority for instantiation is as follows: |
|
1207 | + * - abstract classes or any class flagged as "load only" (no instantiation occurs) |
|
1208 | + * - model objects via their 'new_instance_from_db' method |
|
1209 | + * - model objects via their 'new_instance' method |
|
1210 | + * - "singleton" classes" via their 'instance' method |
|
1211 | + * - standard instantiable classes via their __constructor |
|
1212 | + * Prior to instantiation, if the classname exists in the dependency_map, |
|
1213 | + * then the constructor for the requested class will be examined to determine |
|
1214 | + * if any dependencies exist, and if they can be injected. |
|
1215 | + * If so, then those classes will be added to the array of arguments passed to the constructor |
|
1216 | + * |
|
1217 | + * @param string $class_name |
|
1218 | + * @param array $arguments |
|
1219 | + * @param string $type |
|
1220 | + * @param bool $from_db |
|
1221 | + * @return null|object|bool |
|
1222 | + * @throws InvalidArgumentException |
|
1223 | + * @throws InvalidInterfaceException |
|
1224 | + * @throws EE_Error |
|
1225 | + * @throws ReflectionException |
|
1226 | + * @throws InvalidDataTypeException |
|
1227 | + */ |
|
1228 | + protected function _create_object($class_name, $arguments = array(), $type = '', $from_db = false) |
|
1229 | + { |
|
1230 | + // create reflection |
|
1231 | + $reflector = $this->mirror->getReflectionClass($class_name); |
|
1232 | + // make sure arguments are an array |
|
1233 | + $arguments = is_array($arguments) |
|
1234 | + ? $arguments |
|
1235 | + : array($arguments); |
|
1236 | + // and if arguments array is numerically and sequentially indexed, then we want it to remain as is, |
|
1237 | + // else wrap it in an additional array so that it doesn't get split into multiple parameters |
|
1238 | + $arguments = $this->_array_is_numerically_and_sequentially_indexed($arguments) |
|
1239 | + ? $arguments |
|
1240 | + : array($arguments); |
|
1241 | + // attempt to inject dependencies ? |
|
1242 | + if ($this->_dependency_map->has($class_name)) { |
|
1243 | + $arguments = $this->_resolve_dependencies($reflector, $class_name, $arguments); |
|
1244 | + } |
|
1245 | + // instantiate the class if possible |
|
1246 | + if ($reflector->isAbstract()) { |
|
1247 | + // nothing to instantiate, loading file was enough |
|
1248 | + // does not throw an exception so $instantiation_mode is unused |
|
1249 | + // $instantiation_mode = "1) no constructor abstract class"; |
|
1250 | + return true; |
|
1251 | + } |
|
1252 | + if ( |
|
1253 | + empty($arguments) |
|
1254 | + && $this->mirror->getConstructorFromReflection($reflector) === null |
|
1255 | + && $reflector->isInstantiable() |
|
1256 | + ) { |
|
1257 | + // no constructor = static methods only... nothing to instantiate, loading file was enough |
|
1258 | + // $instantiation_mode = "2) no constructor but instantiable"; |
|
1259 | + return $reflector->newInstance(); |
|
1260 | + } |
|
1261 | + if ($from_db && method_exists($class_name, 'new_instance_from_db')) { |
|
1262 | + // $instantiation_mode = "3) new_instance_from_db()"; |
|
1263 | + return call_user_func_array(array($class_name, 'new_instance_from_db'), $arguments); |
|
1264 | + } |
|
1265 | + if (method_exists($class_name, 'new_instance')) { |
|
1266 | + // $instantiation_mode = "4) new_instance()"; |
|
1267 | + return call_user_func_array(array($class_name, 'new_instance'), $arguments); |
|
1268 | + } |
|
1269 | + if (method_exists($class_name, 'instance')) { |
|
1270 | + // $instantiation_mode = "5) instance()"; |
|
1271 | + return call_user_func_array(array($class_name, 'instance'), $arguments); |
|
1272 | + } |
|
1273 | + if ($reflector->isInstantiable()) { |
|
1274 | + // $instantiation_mode = "6) constructor"; |
|
1275 | + return $reflector->newInstanceArgs($arguments); |
|
1276 | + } |
|
1277 | + // heh ? something's not right ! |
|
1278 | + throw new EE_Error( |
|
1279 | + sprintf( |
|
1280 | + esc_html__('The %s file %s could not be instantiated.', 'event_espresso'), |
|
1281 | + $type, |
|
1282 | + $class_name |
|
1283 | + ) |
|
1284 | + ); |
|
1285 | + } |
|
1286 | + |
|
1287 | + |
|
1288 | + /** |
|
1289 | + * @see http://stackoverflow.com/questions/173400/how-to-check-if-php-array-is-associative-or-sequential |
|
1290 | + * @param array $array |
|
1291 | + * @return bool |
|
1292 | + */ |
|
1293 | + protected function _array_is_numerically_and_sequentially_indexed(array $array) |
|
1294 | + { |
|
1295 | + return ! empty($array) |
|
1296 | + ? array_keys($array) === range(0, count($array) - 1) |
|
1297 | + : true; |
|
1298 | + } |
|
1299 | + |
|
1300 | + |
|
1301 | + /** |
|
1302 | + * _resolve_dependencies |
|
1303 | + * examines the constructor for the requested class to determine |
|
1304 | + * if any dependencies exist, and if they can be injected. |
|
1305 | + * If so, then those classes will be added to the array of arguments passed to the constructor |
|
1306 | + * PLZ NOTE: this is achieved by type hinting the constructor params |
|
1307 | + * For example: |
|
1308 | + * if attempting to load a class "Foo" with the following constructor: |
|
1309 | + * __construct( Bar $bar_class, Fighter $grohl_class ) |
|
1310 | + * then $bar_class and $grohl_class will be added to the $arguments array, |
|
1311 | + * but only IF they are NOT already present in the incoming arguments array, |
|
1312 | + * and the correct classes can be loaded |
|
1313 | + * |
|
1314 | + * @param ReflectionClass $reflector |
|
1315 | + * @param string $class_name |
|
1316 | + * @param array $arguments |
|
1317 | + * @return array |
|
1318 | + * @throws InvalidArgumentException |
|
1319 | + * @throws InvalidDataTypeException |
|
1320 | + * @throws InvalidInterfaceException |
|
1321 | + * @throws ReflectionException |
|
1322 | + */ |
|
1323 | + protected function _resolve_dependencies(ReflectionClass $reflector, $class_name, array $arguments = array()) |
|
1324 | + { |
|
1325 | + // let's examine the constructor |
|
1326 | + $constructor = $this->mirror->getConstructorFromReflection($reflector); |
|
1327 | + // whu? huh? nothing? |
|
1328 | + if (! $constructor) { |
|
1329 | + return $arguments; |
|
1330 | + } |
|
1331 | + // get constructor parameters |
|
1332 | + $params = $this->mirror->getParametersFromReflection($reflector); |
|
1333 | + // and the keys for the incoming arguments array so that we can compare existing arguments with what is expected |
|
1334 | + $argument_keys = array_keys($arguments); |
|
1335 | + // now loop thru all of the constructors expected parameters |
|
1336 | + foreach ($params as $index => $param) { |
|
1337 | + try { |
|
1338 | + // is this a dependency for a specific class ? |
|
1339 | + $param_class = $this->mirror->getParameterClassName($param, $class_name, $index); |
|
1340 | + } catch (ReflectionException $exception) { |
|
1341 | + // uh-oh... most likely a legacy class that has not been autoloaded |
|
1342 | + // let's try to derive the classname from what we have now |
|
1343 | + // and hope that the property var name is close to the class name |
|
1344 | + $param_class = $param->getName(); |
|
1345 | + $param_class = str_replace('_', ' ', $param_class); |
|
1346 | + $param_class = ucwords($param_class); |
|
1347 | + $param_class = str_replace(' ', '_', $param_class); |
|
1348 | + } |
|
1349 | + // BUT WAIT !!! This class may be an alias for something else (or getting replaced at runtime) |
|
1350 | + $param_class = $this->class_cache->isAlias($param_class, $class_name) |
|
1351 | + ? $this->class_cache->getFqnForAlias($param_class, $class_name) |
|
1352 | + : $param_class; |
|
1353 | + if ( |
|
1354 | + // param is not even a class |
|
1355 | + $param_class === null |
|
1356 | + // and something already exists in the incoming arguments for this param |
|
1357 | + && array_key_exists($index, $argument_keys) |
|
1358 | + && array_key_exists($argument_keys[ $index ], $arguments) |
|
1359 | + ) { |
|
1360 | + // so let's skip this argument and move on to the next |
|
1361 | + continue; |
|
1362 | + } |
|
1363 | + if ( |
|
1364 | + // parameter is type hinted as a class, exists as an incoming argument, AND it's the correct class |
|
1365 | + $param_class !== null |
|
1366 | + && isset($argument_keys[ $index ], $arguments[ $argument_keys[ $index ] ]) |
|
1367 | + && $arguments[ $argument_keys[ $index ] ] instanceof $param_class |
|
1368 | + ) { |
|
1369 | + // skip this argument and move on to the next |
|
1370 | + continue; |
|
1371 | + } |
|
1372 | + if ( |
|
1373 | + // parameter is type hinted as a class, and should be injected |
|
1374 | + $param_class !== null |
|
1375 | + && $this->_dependency_map->has_dependency_for_class($class_name, $param_class) |
|
1376 | + ) { |
|
1377 | + $arguments = $this->_resolve_dependency( |
|
1378 | + $class_name, |
|
1379 | + $param_class, |
|
1380 | + $arguments, |
|
1381 | + $index |
|
1382 | + ); |
|
1383 | + } |
|
1384 | + if (empty($arguments[ $index ])) { |
|
1385 | + $default_value = $this->mirror->getParameterDefaultValue( |
|
1386 | + $param, |
|
1387 | + $class_name, |
|
1388 | + $index |
|
1389 | + ); |
|
1390 | + // if there's no default value, and the incoming argument is an array (albeit empty), then use that |
|
1391 | + $arguments[ $index ] = $default_value === null |
|
1392 | + && isset($arguments[ $index ]) |
|
1393 | + && is_array($arguments[ $index ]) |
|
1394 | + ? $arguments[ $index ] |
|
1395 | + : $default_value; |
|
1396 | + } |
|
1397 | + } |
|
1398 | + return $arguments; |
|
1399 | + } |
|
1400 | + |
|
1401 | + |
|
1402 | + /** |
|
1403 | + * @param string $class_name |
|
1404 | + * @param string $param_class |
|
1405 | + * @param array $arguments |
|
1406 | + * @param mixed $index |
|
1407 | + * @return array |
|
1408 | + * @throws InvalidArgumentException |
|
1409 | + * @throws InvalidInterfaceException |
|
1410 | + * @throws InvalidDataTypeException |
|
1411 | + */ |
|
1412 | + protected function _resolve_dependency($class_name, $param_class, $arguments, $index) |
|
1413 | + { |
|
1414 | + $dependency = null; |
|
1415 | + // should dependency be loaded from cache ? |
|
1416 | + $cache_on = $this->_dependency_map->loading_strategy_for_class_dependency( |
|
1417 | + $class_name, |
|
1418 | + $param_class |
|
1419 | + ); |
|
1420 | + $cache_on = $cache_on !== EE_Dependency_Map::load_new_object; |
|
1421 | + // we might have a dependency... |
|
1422 | + // let's MAYBE try and find it in our cache if that's what's been requested |
|
1423 | + $cached_class = $cache_on |
|
1424 | + ? $this->_get_cached_class($param_class) |
|
1425 | + : null; |
|
1426 | + // and grab it if it exists |
|
1427 | + if ($cached_class instanceof $param_class) { |
|
1428 | + $dependency = $cached_class; |
|
1429 | + } elseif ($param_class !== $class_name) { |
|
1430 | + // obtain the loader method from the dependency map |
|
1431 | + $loader = $this->_dependency_map->class_loader($param_class); |
|
1432 | + // is loader a custom closure ? |
|
1433 | + if ($loader instanceof Closure) { |
|
1434 | + $dependency = $loader($arguments); |
|
1435 | + } else { |
|
1436 | + // set the cache on property for the recursive loading call |
|
1437 | + $this->_cache_on = $cache_on; |
|
1438 | + // if not, then let's try and load it via the registry |
|
1439 | + if ($loader && method_exists($this, $loader)) { |
|
1440 | + $dependency = $this->{$loader}($param_class); |
|
1441 | + } else { |
|
1442 | + $dependency = LoaderFactory::getLoader()->load( |
|
1443 | + $param_class, |
|
1444 | + array(), |
|
1445 | + $cache_on |
|
1446 | + ); |
|
1447 | + } |
|
1448 | + } |
|
1449 | + } |
|
1450 | + // did we successfully find the correct dependency ? |
|
1451 | + if ($dependency instanceof $param_class) { |
|
1452 | + // then let's inject it into the incoming array of arguments at the correct location |
|
1453 | + $arguments[ $index ] = $dependency; |
|
1454 | + } |
|
1455 | + return $arguments; |
|
1456 | + } |
|
1457 | + |
|
1458 | + |
|
1459 | + /** |
|
1460 | + * call any loader that's been registered in the EE_Dependency_Map::$_class_loaders array |
|
1461 | + * |
|
1462 | + * @param string $classname PLEASE NOTE: the class name needs to match what's registered |
|
1463 | + * in the EE_Dependency_Map::$_class_loaders array, |
|
1464 | + * including the class prefix, ie: "EE_", "EEM_", "EEH_", etc |
|
1465 | + * @param array $arguments |
|
1466 | + * @return object |
|
1467 | + */ |
|
1468 | + public static function factory($classname, $arguments = array()) |
|
1469 | + { |
|
1470 | + $loader = self::instance()->_dependency_map->class_loader($classname); |
|
1471 | + if ($loader instanceof Closure) { |
|
1472 | + return $loader($arguments); |
|
1473 | + } |
|
1474 | + if (method_exists(self::instance(), $loader)) { |
|
1475 | + return self::instance()->{$loader}($classname, $arguments); |
|
1476 | + } |
|
1477 | + return null; |
|
1478 | + } |
|
1479 | + |
|
1480 | + |
|
1481 | + /** |
|
1482 | + * Gets the addon by its class name |
|
1483 | + * |
|
1484 | + * @param string $class_name |
|
1485 | + * @return EE_Addon |
|
1486 | + */ |
|
1487 | + public function getAddon($class_name) |
|
1488 | + { |
|
1489 | + $class_name = str_replace('\\', '_', $class_name); |
|
1490 | + if (isset($this->addons->{$class_name})) { |
|
1491 | + return $this->addons->{$class_name}; |
|
1492 | + } else { |
|
1493 | + return null; |
|
1494 | + } |
|
1495 | + } |
|
1496 | + |
|
1497 | + |
|
1498 | + /** |
|
1499 | + * removes the addon from the internal cache |
|
1500 | + * |
|
1501 | + * @param string $class_name |
|
1502 | + * @return void |
|
1503 | + */ |
|
1504 | + public function removeAddon($class_name) |
|
1505 | + { |
|
1506 | + $class_name = str_replace('\\', '_', $class_name); |
|
1507 | + $this->addons->remove($class_name); |
|
1508 | + } |
|
1509 | + |
|
1510 | + |
|
1511 | + /** |
|
1512 | + * Gets the addon by its name/slug (not classname. For that, just |
|
1513 | + * use the get_addon() method above |
|
1514 | + * |
|
1515 | + * @param string $name |
|
1516 | + * @return EE_Addon |
|
1517 | + */ |
|
1518 | + public function get_addon_by_name($name) |
|
1519 | + { |
|
1520 | + foreach ($this->addons as $addon) { |
|
1521 | + if ($addon->name() === $name) { |
|
1522 | + return $addon; |
|
1523 | + } |
|
1524 | + } |
|
1525 | + return null; |
|
1526 | + } |
|
1527 | + |
|
1528 | + |
|
1529 | + /** |
|
1530 | + * Gets an array of all the registered addons, where the keys are their names. |
|
1531 | + * (ie, what each returns for their name() function) |
|
1532 | + * They're already available on EE_Registry::instance()->addons as properties, |
|
1533 | + * where each property's name is the addon's classname, |
|
1534 | + * So if you just want to get the addon by classname, |
|
1535 | + * OR use the get_addon() method above. |
|
1536 | + * PLEASE NOTE: |
|
1537 | + * addons with Fully Qualified Class Names |
|
1538 | + * have had the namespace separators converted to underscores, |
|
1539 | + * so a classname like Fully\Qualified\ClassName |
|
1540 | + * would have been converted to Fully_Qualified_ClassName |
|
1541 | + * |
|
1542 | + * @return EE_Addon[] where the KEYS are the addon's name() |
|
1543 | + */ |
|
1544 | + public function get_addons_by_name() |
|
1545 | + { |
|
1546 | + $addons = array(); |
|
1547 | + foreach ($this->addons as $addon) { |
|
1548 | + $addons[ $addon->name() ] = $addon; |
|
1549 | + } |
|
1550 | + return $addons; |
|
1551 | + } |
|
1552 | + |
|
1553 | + |
|
1554 | + /** |
|
1555 | + * Resets the specified model's instance AND makes sure EE_Registry doesn't keep |
|
1556 | + * a stale copy of it around |
|
1557 | + * |
|
1558 | + * @param string $model_name |
|
1559 | + * @return \EEM_Base |
|
1560 | + * @throws \EE_Error |
|
1561 | + */ |
|
1562 | + public function reset_model($model_name) |
|
1563 | + { |
|
1564 | + $model_class_name = strpos($model_name, 'EEM_') !== 0 |
|
1565 | + ? "EEM_{$model_name}" |
|
1566 | + : $model_name; |
|
1567 | + if (! $this->LIB->has($model_class_name)) { |
|
1568 | + return null; |
|
1569 | + } |
|
1570 | + $model = $this->LIB->get($model_class_name); |
|
1571 | + if (! $model instanceof EEM_Base) { |
|
1572 | + return null; |
|
1573 | + } |
|
1574 | + // get that model reset it and make sure we nuke the old reference to it |
|
1575 | + if ($model instanceof $model_class_name && is_callable([$model_class_name, 'reset'])) { |
|
1576 | + $this->LIB->remove($model_class_name); |
|
1577 | + $this->LIB->add($model_class_name, $model->reset()); |
|
1578 | + } else { |
|
1579 | + throw new EE_Error( |
|
1580 | + sprintf( |
|
1581 | + esc_html__('Model %s does not have a method "reset"', 'event_espresso'), |
|
1582 | + $model_name |
|
1583 | + ) |
|
1584 | + ); |
|
1585 | + } |
|
1586 | + return $model; |
|
1587 | + } |
|
1588 | + |
|
1589 | + |
|
1590 | + /** |
|
1591 | + * Resets the registry. |
|
1592 | + * The criteria for what gets reset is based on what can be shared between sites on the same request when |
|
1593 | + * switch_to_blog is used in a multisite install. Here is a list of things that are NOT reset. |
|
1594 | + * - $_dependency_map |
|
1595 | + * - $_class_abbreviations |
|
1596 | + * - $NET_CFG (EE_Network_Config): The config is shared network wide so no need to reset. |
|
1597 | + * - $REQ: Still on the same request so no need to change. |
|
1598 | + * - $CAP: There is no site specific state in the EE_Capability class. |
|
1599 | + * - $SSN: Although ideally, the session should not be shared between site switches, we can't reset it because only |
|
1600 | + * one Session can be active in a single request. Resetting could resolve in "headers already sent" errors. |
|
1601 | + * - $addons: In multisite, the state of the addons is something controlled via hooks etc in a normal request. So |
|
1602 | + * for now, we won't reset the addons because it could break calls to an add-ons class/methods in the |
|
1603 | + * switch or on the restore. |
|
1604 | + * - $modules |
|
1605 | + * - $shortcodes |
|
1606 | + * - $widgets |
|
1607 | + * |
|
1608 | + * @param boolean $hard [deprecated] |
|
1609 | + * @param boolean $reinstantiate whether to create new instances of EE_Registry's singletons too, |
|
1610 | + * or just reset without re-instantiating (handy to set to FALSE if you're not |
|
1611 | + * sure if you CAN currently reinstantiate the singletons at the moment) |
|
1612 | + * @param bool $reset_models Defaults to true. When false, then the models are not reset. This is so |
|
1613 | + * client |
|
1614 | + * code instead can just change the model context to a different blog id if |
|
1615 | + * necessary |
|
1616 | + * @return EE_Registry |
|
1617 | + * @throws InvalidInterfaceException |
|
1618 | + * @throws InvalidDataTypeException |
|
1619 | + * @throws EE_Error |
|
1620 | + * @throws ReflectionException |
|
1621 | + * @throws InvalidArgumentException |
|
1622 | + */ |
|
1623 | + public static function reset($hard = false, $reinstantiate = true, $reset_models = true) |
|
1624 | + { |
|
1625 | + $instance = self::instance(); |
|
1626 | + $instance->_cache_on = true; |
|
1627 | + // reset some "special" classes |
|
1628 | + EEH_Activation::reset(); |
|
1629 | + $hard = apply_filters('FHEE__EE_Registry__reset__hard', $hard); |
|
1630 | + $instance->CFG = EE_Config::reset($hard, $reinstantiate); |
|
1631 | + $instance->CART = null; |
|
1632 | + $instance->MRM = null; |
|
1633 | + $instance->AssetsRegistry = LoaderFactory::getLoader()->getShared( |
|
1634 | + 'EventEspresso\core\services\assets\Registry' |
|
1635 | + ); |
|
1636 | + // messages reset |
|
1637 | + EED_Messages::reset(); |
|
1638 | + // handle of objects cached on LIB |
|
1639 | + foreach (array('LIB', 'modules') as $cache) { |
|
1640 | + foreach ($instance->{$cache} as $class_name => $class) { |
|
1641 | + if (self::_reset_and_unset_object($class, $reset_models)) { |
|
1642 | + unset($instance->{$cache}->{$class_name}); |
|
1643 | + } |
|
1644 | + } |
|
1645 | + } |
|
1646 | + return $instance; |
|
1647 | + } |
|
1648 | + |
|
1649 | + |
|
1650 | + /** |
|
1651 | + * if passed object implements ResettableInterface, then call it's reset() method |
|
1652 | + * if passed object implements InterminableInterface, then return false, |
|
1653 | + * to indicate that it should NOT be cleared from the Registry cache |
|
1654 | + * |
|
1655 | + * @param $object |
|
1656 | + * @param bool $reset_models |
|
1657 | + * @return bool returns true if cached object should be unset |
|
1658 | + */ |
|
1659 | + private static function _reset_and_unset_object($object, $reset_models) |
|
1660 | + { |
|
1661 | + if (! is_object($object)) { |
|
1662 | + // don't unset anything that's not an object |
|
1663 | + return false; |
|
1664 | + } |
|
1665 | + if ($object instanceof EED_Module) { |
|
1666 | + $object::reset(); |
|
1667 | + // don't unset modules |
|
1668 | + return false; |
|
1669 | + } |
|
1670 | + if ($object instanceof ResettableInterface) { |
|
1671 | + if ($object instanceof EEM_Base) { |
|
1672 | + if ($reset_models) { |
|
1673 | + $object->reset(); |
|
1674 | + return true; |
|
1675 | + } |
|
1676 | + return false; |
|
1677 | + } |
|
1678 | + $object->reset(); |
|
1679 | + return true; |
|
1680 | + } |
|
1681 | + if (! $object instanceof InterminableInterface) { |
|
1682 | + return true; |
|
1683 | + } |
|
1684 | + return false; |
|
1685 | + } |
|
1686 | + |
|
1687 | + |
|
1688 | + /** |
|
1689 | + * Gets all the custom post type models defined |
|
1690 | + * |
|
1691 | + * @return array keys are model "short names" (Eg "Event") and keys are classnames (eg "EEM_Event") |
|
1692 | + */ |
|
1693 | + public function cpt_models() |
|
1694 | + { |
|
1695 | + $cpt_models = array(); |
|
1696 | + foreach ($this->non_abstract_db_models as $short_name => $classname) { |
|
1697 | + if (is_subclass_of($classname, 'EEM_CPT_Base')) { |
|
1698 | + $cpt_models[ $short_name ] = $classname; |
|
1699 | + } |
|
1700 | + } |
|
1701 | + return $cpt_models; |
|
1702 | + } |
|
1703 | + |
|
1704 | + |
|
1705 | + /** |
|
1706 | + * @return \EE_Config |
|
1707 | + */ |
|
1708 | + public static function CFG() |
|
1709 | + { |
|
1710 | + return self::instance()->CFG; |
|
1711 | + } |
|
1712 | + |
|
1713 | + |
|
1714 | + /** |
|
1715 | + * @deprecated 4.9.62.p |
|
1716 | + * @param string $class_name |
|
1717 | + * @return ReflectionClass |
|
1718 | + * @throws ReflectionException |
|
1719 | + * @throws InvalidDataTypeException |
|
1720 | + */ |
|
1721 | + public function get_ReflectionClass($class_name) |
|
1722 | + { |
|
1723 | + return $this->mirror->getReflectionClass($class_name); |
|
1724 | + } |
|
1725 | 1725 | } |
@@ -18,76 +18,76 @@ |
||
18 | 18 | class Answers |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - private $reg_row; |
|
21 | + /** |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + private $reg_row; |
|
25 | 25 | |
26 | 26 | |
27 | - /** |
|
28 | - * Answers constructor. |
|
29 | - * |
|
30 | - * @param array $reg_row |
|
31 | - */ |
|
32 | - public function __construct(array $reg_row) |
|
33 | - { |
|
34 | - $this->reg_row = $reg_row; |
|
35 | - } |
|
27 | + /** |
|
28 | + * Answers constructor. |
|
29 | + * |
|
30 | + * @param array $reg_row |
|
31 | + */ |
|
32 | + public function __construct(array $reg_row) |
|
33 | + { |
|
34 | + $this->reg_row = $reg_row; |
|
35 | + } |
|
36 | 36 | |
37 | - /** |
|
38 | - * Add question / answer columns to the CSV row |
|
39 | - * |
|
40 | - * @param array $data |
|
41 | - * @param array $question_labels |
|
42 | - * @return mixed |
|
43 | - * @throws EE_Error |
|
44 | - */ |
|
45 | - public function addAnswerColumns($data, $question_labels) |
|
46 | - { |
|
47 | - // make sure each registration has the same questions in the same order |
|
48 | - foreach ($question_labels as $question_label) { |
|
49 | - if (! isset($data[ $question_label ])) { |
|
50 | - $data[ $question_label ] = null; |
|
51 | - } |
|
52 | - } |
|
53 | - $answers = EEM_Answer::instance()->get_all_wpdb_results([ |
|
54 | - ['REG_ID' => $this->reg_row['Registration.REG_ID']], |
|
55 | - 'force_join' => ['Question'], |
|
56 | - ]); |
|
57 | - // now fill out the questions THEY answered |
|
58 | - foreach ($answers as $answer_row) { |
|
59 | - if ($answer_row['Question.QST_system']) { |
|
60 | - // it's an answer to a system question. That was already displayed as part of the attendee |
|
61 | - // fields, so don't write it out again thanks. |
|
62 | - continue; |
|
63 | - } |
|
64 | - if ($answer_row['Question.QST_ID']) { |
|
65 | - $question_label = EEH_Export::prepare_value_from_db_for_display( |
|
66 | - EEM_Question::instance(), |
|
67 | - 'QST_admin_label', |
|
68 | - $answer_row['Question.QST_admin_label'] |
|
69 | - ); |
|
70 | - } else { |
|
71 | - $question_label = sprintf(esc_html__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']); |
|
72 | - } |
|
73 | - if ( |
|
74 | - isset($answer_row['Question.QST_type']) |
|
75 | - && $answer_row['Question.QST_type'] == EEM_Question::QST_type_state |
|
76 | - ) { |
|
77 | - $data[ $question_label ] = EEM_State::instance()->get_state_name_by_ID( |
|
78 | - $answer_row['Answer.ANS_value'] |
|
79 | - ); |
|
80 | - } else { |
|
81 | - // this isn't for html, so don't show html entities |
|
82 | - $data[ $question_label ] = html_entity_decode( |
|
83 | - EEH_Export::prepare_value_from_db_for_display( |
|
84 | - EEM_Answer::instance(), |
|
85 | - 'ANS_value', |
|
86 | - $answer_row['Answer.ANS_value'] |
|
87 | - ) |
|
88 | - ); |
|
89 | - } |
|
90 | - } |
|
91 | - return $data; |
|
92 | - } |
|
37 | + /** |
|
38 | + * Add question / answer columns to the CSV row |
|
39 | + * |
|
40 | + * @param array $data |
|
41 | + * @param array $question_labels |
|
42 | + * @return mixed |
|
43 | + * @throws EE_Error |
|
44 | + */ |
|
45 | + public function addAnswerColumns($data, $question_labels) |
|
46 | + { |
|
47 | + // make sure each registration has the same questions in the same order |
|
48 | + foreach ($question_labels as $question_label) { |
|
49 | + if (! isset($data[ $question_label ])) { |
|
50 | + $data[ $question_label ] = null; |
|
51 | + } |
|
52 | + } |
|
53 | + $answers = EEM_Answer::instance()->get_all_wpdb_results([ |
|
54 | + ['REG_ID' => $this->reg_row['Registration.REG_ID']], |
|
55 | + 'force_join' => ['Question'], |
|
56 | + ]); |
|
57 | + // now fill out the questions THEY answered |
|
58 | + foreach ($answers as $answer_row) { |
|
59 | + if ($answer_row['Question.QST_system']) { |
|
60 | + // it's an answer to a system question. That was already displayed as part of the attendee |
|
61 | + // fields, so don't write it out again thanks. |
|
62 | + continue; |
|
63 | + } |
|
64 | + if ($answer_row['Question.QST_ID']) { |
|
65 | + $question_label = EEH_Export::prepare_value_from_db_for_display( |
|
66 | + EEM_Question::instance(), |
|
67 | + 'QST_admin_label', |
|
68 | + $answer_row['Question.QST_admin_label'] |
|
69 | + ); |
|
70 | + } else { |
|
71 | + $question_label = sprintf(esc_html__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']); |
|
72 | + } |
|
73 | + if ( |
|
74 | + isset($answer_row['Question.QST_type']) |
|
75 | + && $answer_row['Question.QST_type'] == EEM_Question::QST_type_state |
|
76 | + ) { |
|
77 | + $data[ $question_label ] = EEM_State::instance()->get_state_name_by_ID( |
|
78 | + $answer_row['Answer.ANS_value'] |
|
79 | + ); |
|
80 | + } else { |
|
81 | + // this isn't for html, so don't show html entities |
|
82 | + $data[ $question_label ] = html_entity_decode( |
|
83 | + EEH_Export::prepare_value_from_db_for_display( |
|
84 | + EEM_Answer::instance(), |
|
85 | + 'ANS_value', |
|
86 | + $answer_row['Answer.ANS_value'] |
|
87 | + ) |
|
88 | + ); |
|
89 | + } |
|
90 | + } |
|
91 | + return $data; |
|
92 | + } |
|
93 | 93 | } |
@@ -46,8 +46,8 @@ discard block |
||
46 | 46 | { |
47 | 47 | // make sure each registration has the same questions in the same order |
48 | 48 | foreach ($question_labels as $question_label) { |
49 | - if (! isset($data[ $question_label ])) { |
|
50 | - $data[ $question_label ] = null; |
|
49 | + if ( ! isset($data[$question_label])) { |
|
50 | + $data[$question_label] = null; |
|
51 | 51 | } |
52 | 52 | } |
53 | 53 | $answers = EEM_Answer::instance()->get_all_wpdb_results([ |
@@ -74,12 +74,12 @@ discard block |
||
74 | 74 | isset($answer_row['Question.QST_type']) |
75 | 75 | && $answer_row['Question.QST_type'] == EEM_Question::QST_type_state |
76 | 76 | ) { |
77 | - $data[ $question_label ] = EEM_State::instance()->get_state_name_by_ID( |
|
77 | + $data[$question_label] = EEM_State::instance()->get_state_name_by_ID( |
|
78 | 78 | $answer_row['Answer.ANS_value'] |
79 | 79 | ); |
80 | 80 | } else { |
81 | 81 | // this isn't for html, so don't show html entities |
82 | - $data[ $question_label ] = html_entity_decode( |
|
82 | + $data[$question_label] = html_entity_decode( |
|
83 | 83 | EEH_Export::prepare_value_from_db_for_display( |
84 | 84 | EEM_Answer::instance(), |
85 | 85 | 'ANS_value', |
@@ -18,69 +18,69 @@ |
||
18 | 18 | class Attendee |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @var array |
|
23 | - */ |
|
24 | - private $fields; |
|
21 | + /** |
|
22 | + * @var array |
|
23 | + */ |
|
24 | + private $fields; |
|
25 | 25 | |
26 | 26 | |
27 | - /** |
|
28 | - * @var array |
|
29 | - */ |
|
30 | - private $reg_row; |
|
27 | + /** |
|
28 | + * @var array |
|
29 | + */ |
|
30 | + private $reg_row; |
|
31 | 31 | |
32 | 32 | |
33 | - /** |
|
34 | - * Attendee constructor. |
|
35 | - * |
|
36 | - * @param array $fields |
|
37 | - * @param array $reg_row |
|
38 | - */ |
|
39 | - public function __construct(array $fields, array $reg_row) |
|
40 | - { |
|
41 | - $this->fields = $fields; |
|
42 | - $this->reg_row = $reg_row; |
|
43 | - } |
|
33 | + /** |
|
34 | + * Attendee constructor. |
|
35 | + * |
|
36 | + * @param array $fields |
|
37 | + * @param array $reg_row |
|
38 | + */ |
|
39 | + public function __construct(array $fields, array $reg_row) |
|
40 | + { |
|
41 | + $this->fields = $fields; |
|
42 | + $this->reg_row = $reg_row; |
|
43 | + } |
|
44 | 44 | |
45 | 45 | |
46 | - /** |
|
47 | - * Adds attendee columns to the CSV row |
|
48 | - * |
|
49 | - * @param array $data |
|
50 | - * @return array |
|
51 | - * @throws EE_Error |
|
52 | - */ |
|
53 | - public function addAttendeeColumns(array $data) |
|
54 | - { |
|
55 | - foreach ($this->fields as $field_name) { |
|
56 | - $field_obj = EEM_Attendee::instance()->field_settings_for($field_name); |
|
57 | - if ($this->reg_row['Attendee_CPT.ID']) { |
|
58 | - if ($field_name == 'STA_ID') { |
|
59 | - $value = EEM_State::instance()->get_var( |
|
60 | - [ |
|
61 | - ['STA_ID' => $this->reg_row['Attendee_Meta.STA_ID']] |
|
62 | - ], |
|
63 | - 'STA_name' |
|
64 | - ); |
|
65 | - } elseif ($field_name == 'CNT_ISO') { |
|
66 | - $value = EEM_Country::instance()->get_var( |
|
67 | - [ |
|
68 | - ['CNT_ISO' => $this->reg_row['Attendee_Meta.CNT_ISO']] |
|
69 | - ], |
|
70 | - 'CNT_name' |
|
71 | - ); |
|
72 | - } else { |
|
73 | - $value = EEH_Export::prepare_value_from_db_for_display( |
|
74 | - EEM_Attendee::instance(), |
|
75 | - $field_name, |
|
76 | - $this->reg_row[ $field_obj->get_qualified_column() ] |
|
77 | - ); |
|
78 | - } |
|
79 | - } else { |
|
80 | - $value = ''; |
|
81 | - } |
|
82 | - $data[ EEH_Export::get_column_name_for_field($field_obj) ] = $value; |
|
83 | - } |
|
84 | - return $data; |
|
85 | - } |
|
46 | + /** |
|
47 | + * Adds attendee columns to the CSV row |
|
48 | + * |
|
49 | + * @param array $data |
|
50 | + * @return array |
|
51 | + * @throws EE_Error |
|
52 | + */ |
|
53 | + public function addAttendeeColumns(array $data) |
|
54 | + { |
|
55 | + foreach ($this->fields as $field_name) { |
|
56 | + $field_obj = EEM_Attendee::instance()->field_settings_for($field_name); |
|
57 | + if ($this->reg_row['Attendee_CPT.ID']) { |
|
58 | + if ($field_name == 'STA_ID') { |
|
59 | + $value = EEM_State::instance()->get_var( |
|
60 | + [ |
|
61 | + ['STA_ID' => $this->reg_row['Attendee_Meta.STA_ID']] |
|
62 | + ], |
|
63 | + 'STA_name' |
|
64 | + ); |
|
65 | + } elseif ($field_name == 'CNT_ISO') { |
|
66 | + $value = EEM_Country::instance()->get_var( |
|
67 | + [ |
|
68 | + ['CNT_ISO' => $this->reg_row['Attendee_Meta.CNT_ISO']] |
|
69 | + ], |
|
70 | + 'CNT_name' |
|
71 | + ); |
|
72 | + } else { |
|
73 | + $value = EEH_Export::prepare_value_from_db_for_display( |
|
74 | + EEM_Attendee::instance(), |
|
75 | + $field_name, |
|
76 | + $this->reg_row[ $field_obj->get_qualified_column() ] |
|
77 | + ); |
|
78 | + } |
|
79 | + } else { |
|
80 | + $value = ''; |
|
81 | + } |
|
82 | + $data[ EEH_Export::get_column_name_for_field($field_obj) ] = $value; |
|
83 | + } |
|
84 | + return $data; |
|
85 | + } |
|
86 | 86 | } |
@@ -73,13 +73,13 @@ |
||
73 | 73 | $value = EEH_Export::prepare_value_from_db_for_display( |
74 | 74 | EEM_Attendee::instance(), |
75 | 75 | $field_name, |
76 | - $this->reg_row[ $field_obj->get_qualified_column() ] |
|
76 | + $this->reg_row[$field_obj->get_qualified_column()] |
|
77 | 77 | ); |
78 | 78 | } |
79 | 79 | } else { |
80 | 80 | $value = ''; |
81 | 81 | } |
82 | - $data[ EEH_Export::get_column_name_for_field($field_obj) ] = $value; |
|
82 | + $data[EEH_Export::get_column_name_for_field($field_obj)] = $value; |
|
83 | 83 | } |
84 | 84 | return $data; |
85 | 85 | } |
@@ -12,25 +12,25 @@ |
||
12 | 12 | class PaymentsInfo |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * Extracts payment information using the payment records |
|
17 | - * |
|
18 | - * @param array $payments_info |
|
19 | - * @return array |
|
20 | - */ |
|
21 | - public static function extractPaymentInfo(array $payments_info) |
|
22 | - { |
|
23 | - $payment_methods = []; |
|
24 | - $gateway_txn_ids_etc = []; |
|
25 | - $payment_times = []; |
|
26 | - foreach ($payments_info as $payment_method_and_gateway_txn_id) { |
|
27 | - $payment_methods[] = isset($payment_method_and_gateway_txn_id['name']) |
|
28 | - ? $payment_method_and_gateway_txn_id['name'] : esc_html__('Unknown', 'event_espresso'); |
|
29 | - $gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id']) |
|
30 | - ? $payment_method_and_gateway_txn_id['gateway_txn_id'] : ''; |
|
31 | - $payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time']) |
|
32 | - ? $payment_method_and_gateway_txn_id['payment_time'] : ''; |
|
33 | - } |
|
34 | - return [$payment_methods, $gateway_txn_ids_etc, $payment_times]; |
|
35 | - } |
|
15 | + /** |
|
16 | + * Extracts payment information using the payment records |
|
17 | + * |
|
18 | + * @param array $payments_info |
|
19 | + * @return array |
|
20 | + */ |
|
21 | + public static function extractPaymentInfo(array $payments_info) |
|
22 | + { |
|
23 | + $payment_methods = []; |
|
24 | + $gateway_txn_ids_etc = []; |
|
25 | + $payment_times = []; |
|
26 | + foreach ($payments_info as $payment_method_and_gateway_txn_id) { |
|
27 | + $payment_methods[] = isset($payment_method_and_gateway_txn_id['name']) |
|
28 | + ? $payment_method_and_gateway_txn_id['name'] : esc_html__('Unknown', 'event_espresso'); |
|
29 | + $gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id']) |
|
30 | + ? $payment_method_and_gateway_txn_id['gateway_txn_id'] : ''; |
|
31 | + $payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time']) |
|
32 | + ? $payment_method_and_gateway_txn_id['payment_time'] : ''; |
|
33 | + } |
|
34 | + return [$payment_methods, $gateway_txn_ids_etc, $payment_times]; |
|
35 | + } |
|
36 | 36 | } |
@@ -19,93 +19,93 @@ |
||
19 | 19 | class Registration |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * @var array |
|
24 | - */ |
|
25 | - private $fields; |
|
22 | + /** |
|
23 | + * @var array |
|
24 | + */ |
|
25 | + private $fields; |
|
26 | 26 | |
27 | 27 | |
28 | - /** |
|
29 | - * @var array |
|
30 | - */ |
|
31 | - private $reg_row; |
|
28 | + /** |
|
29 | + * @var array |
|
30 | + */ |
|
31 | + private $reg_row; |
|
32 | 32 | |
33 | 33 | |
34 | - /** |
|
35 | - * @var EEM_Registration |
|
36 | - */ |
|
37 | - private $reg_model; |
|
34 | + /** |
|
35 | + * @var EEM_Registration |
|
36 | + */ |
|
37 | + private $reg_model; |
|
38 | 38 | |
39 | 39 | |
40 | - /** |
|
41 | - * Registration constructor. |
|
42 | - * |
|
43 | - * @param array $fields |
|
44 | - * @param array $reg_row |
|
45 | - * @throws EE_Error |
|
46 | - * @throws ReflectionException |
|
47 | - */ |
|
48 | - public function __construct(array $fields, array $reg_row) |
|
49 | - { |
|
50 | - $this->fields = $fields; |
|
51 | - $this->reg_row = $reg_row; |
|
52 | - $this->reg_model = EE_Registry::instance()->load_model('Registration'); |
|
53 | - } |
|
40 | + /** |
|
41 | + * Registration constructor. |
|
42 | + * |
|
43 | + * @param array $fields |
|
44 | + * @param array $reg_row |
|
45 | + * @throws EE_Error |
|
46 | + * @throws ReflectionException |
|
47 | + */ |
|
48 | + public function __construct(array $fields, array $reg_row) |
|
49 | + { |
|
50 | + $this->fields = $fields; |
|
51 | + $this->reg_row = $reg_row; |
|
52 | + $this->reg_model = EE_Registry::instance()->load_model('Registration'); |
|
53 | + } |
|
54 | 54 | |
55 | 55 | |
56 | - /** |
|
57 | - * Adds registration columns to the CSV row |
|
58 | - * |
|
59 | - * @param array $data |
|
60 | - * @return mixed |
|
61 | - * @throws EE_Error |
|
62 | - */ |
|
63 | - public function addRegistrationColumns(array $data) |
|
64 | - { |
|
65 | - foreach ($this->fields as $field_name) { |
|
66 | - $field = $this->reg_model->field_settings_for($field_name); |
|
67 | - if ($field_name == 'REG_final_price') { |
|
68 | - $value = EEH_Export::prepare_value_from_db_for_display( |
|
69 | - $this->reg_model, |
|
70 | - $field_name, |
|
71 | - $this->reg_row['Registration.REG_final_price'], |
|
72 | - 'localized_float' |
|
73 | - ); |
|
74 | - } elseif ($field_name == 'REG_count') { |
|
75 | - $value = sprintf( |
|
76 | - /* translators: 1: number of registration in group (REG_count), 2: registration group size (REG_group_size) */ |
|
77 | - esc_html__('%1$s of %2$s', 'event_espresso'), |
|
78 | - EEH_Export::prepare_value_from_db_for_display( |
|
79 | - $this->reg_model, |
|
80 | - 'REG_count', |
|
81 | - $this->reg_row['Registration.REG_count'] |
|
82 | - ), |
|
83 | - EEH_Export::prepare_value_from_db_for_display( |
|
84 | - $this->reg_model, |
|
85 | - 'REG_group_size', |
|
86 | - $this->reg_row['Registration.REG_group_size'] |
|
87 | - ) |
|
88 | - ); |
|
89 | - } elseif ($field_name == 'REG_date') { |
|
90 | - $value = EEH_Export::prepare_value_from_db_for_display( |
|
91 | - $this->reg_model, |
|
92 | - $field_name, |
|
93 | - $this->reg_row['Registration.REG_date'], |
|
94 | - 'no_html' |
|
95 | - ); |
|
96 | - } else { |
|
97 | - $value = EEH_Export::prepare_value_from_db_for_display( |
|
98 | - $this->reg_model, |
|
99 | - $field_name, |
|
100 | - $this->reg_row[ $field->get_qualified_column() ] |
|
101 | - ); |
|
102 | - } |
|
103 | - $data[ EEH_Export::get_column_name_for_field($field) ] = $value; |
|
104 | - if ($field_name == 'REG_final_price') { |
|
105 | - // add a column named Currency after the final price |
|
106 | - $data[ (string) esc_html__("Currency", "event_espresso") ] = EE_Config::instance()->currency->code; |
|
107 | - } |
|
108 | - } |
|
109 | - return $data; |
|
110 | - } |
|
56 | + /** |
|
57 | + * Adds registration columns to the CSV row |
|
58 | + * |
|
59 | + * @param array $data |
|
60 | + * @return mixed |
|
61 | + * @throws EE_Error |
|
62 | + */ |
|
63 | + public function addRegistrationColumns(array $data) |
|
64 | + { |
|
65 | + foreach ($this->fields as $field_name) { |
|
66 | + $field = $this->reg_model->field_settings_for($field_name); |
|
67 | + if ($field_name == 'REG_final_price') { |
|
68 | + $value = EEH_Export::prepare_value_from_db_for_display( |
|
69 | + $this->reg_model, |
|
70 | + $field_name, |
|
71 | + $this->reg_row['Registration.REG_final_price'], |
|
72 | + 'localized_float' |
|
73 | + ); |
|
74 | + } elseif ($field_name == 'REG_count') { |
|
75 | + $value = sprintf( |
|
76 | + /* translators: 1: number of registration in group (REG_count), 2: registration group size (REG_group_size) */ |
|
77 | + esc_html__('%1$s of %2$s', 'event_espresso'), |
|
78 | + EEH_Export::prepare_value_from_db_for_display( |
|
79 | + $this->reg_model, |
|
80 | + 'REG_count', |
|
81 | + $this->reg_row['Registration.REG_count'] |
|
82 | + ), |
|
83 | + EEH_Export::prepare_value_from_db_for_display( |
|
84 | + $this->reg_model, |
|
85 | + 'REG_group_size', |
|
86 | + $this->reg_row['Registration.REG_group_size'] |
|
87 | + ) |
|
88 | + ); |
|
89 | + } elseif ($field_name == 'REG_date') { |
|
90 | + $value = EEH_Export::prepare_value_from_db_for_display( |
|
91 | + $this->reg_model, |
|
92 | + $field_name, |
|
93 | + $this->reg_row['Registration.REG_date'], |
|
94 | + 'no_html' |
|
95 | + ); |
|
96 | + } else { |
|
97 | + $value = EEH_Export::prepare_value_from_db_for_display( |
|
98 | + $this->reg_model, |
|
99 | + $field_name, |
|
100 | + $this->reg_row[ $field->get_qualified_column() ] |
|
101 | + ); |
|
102 | + } |
|
103 | + $data[ EEH_Export::get_column_name_for_field($field) ] = $value; |
|
104 | + if ($field_name == 'REG_final_price') { |
|
105 | + // add a column named Currency after the final price |
|
106 | + $data[ (string) esc_html__("Currency", "event_espresso") ] = EE_Config::instance()->currency->code; |
|
107 | + } |
|
108 | + } |
|
109 | + return $data; |
|
110 | + } |
|
111 | 111 | } |
@@ -97,13 +97,13 @@ |
||
97 | 97 | $value = EEH_Export::prepare_value_from_db_for_display( |
98 | 98 | $this->reg_model, |
99 | 99 | $field_name, |
100 | - $this->reg_row[ $field->get_qualified_column() ] |
|
100 | + $this->reg_row[$field->get_qualified_column()] |
|
101 | 101 | ); |
102 | 102 | } |
103 | - $data[ EEH_Export::get_column_name_for_field($field) ] = $value; |
|
103 | + $data[EEH_Export::get_column_name_for_field($field)] = $value; |
|
104 | 104 | if ($field_name == 'REG_final_price') { |
105 | 105 | // add a column named Currency after the final price |
106 | - $data[ (string) esc_html__("Currency", "event_espresso") ] = EE_Config::instance()->currency->code; |
|
106 | + $data[(string) esc_html__("Currency", "event_espresso")] = EE_Config::instance()->currency->code; |
|
107 | 107 | } |
108 | 108 | } |
109 | 109 | return $data; |
@@ -17,60 +17,60 @@ |
||
17 | 17 | class Checkins |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * Returns datetime label |
|
22 | - * |
|
23 | - * @param EE_Datetime $datetime |
|
24 | - * @return string |
|
25 | - * @throws EE_Error |
|
26 | - * @throws ReflectionException |
|
27 | - */ |
|
28 | - public static function getDatetineLabel(EE_Datetime $datetime) |
|
29 | - { |
|
30 | - if (trim($datetime->get('DTT_name'))) { |
|
31 | - /* translators: 1: datetime name, 2: datetime ID */ |
|
32 | - $name = sprintf( |
|
33 | - esc_html__('Check-ins for %1$s - ID: %2$s', 'event_espresso'), |
|
34 | - esc_html($datetime->get('DTT_name')), |
|
35 | - esc_html($datetime->get('DTT_ID')) |
|
36 | - ); |
|
37 | - } else { |
|
38 | - /* translators: %s: datetime ID */ |
|
39 | - $name = sprintf( |
|
40 | - esc_html__('ID: %1$s', 'event_espresso'), |
|
41 | - esc_html($datetime->get('DTT_ID')) |
|
42 | - ); |
|
43 | - } |
|
20 | + /** |
|
21 | + * Returns datetime label |
|
22 | + * |
|
23 | + * @param EE_Datetime $datetime |
|
24 | + * @return string |
|
25 | + * @throws EE_Error |
|
26 | + * @throws ReflectionException |
|
27 | + */ |
|
28 | + public static function getDatetineLabel(EE_Datetime $datetime) |
|
29 | + { |
|
30 | + if (trim($datetime->get('DTT_name'))) { |
|
31 | + /* translators: 1: datetime name, 2: datetime ID */ |
|
32 | + $name = sprintf( |
|
33 | + esc_html__('Check-ins for %1$s - ID: %2$s', 'event_espresso'), |
|
34 | + esc_html($datetime->get('DTT_name')), |
|
35 | + esc_html($datetime->get('DTT_ID')) |
|
36 | + ); |
|
37 | + } else { |
|
38 | + /* translators: %s: datetime ID */ |
|
39 | + $name = sprintf( |
|
40 | + esc_html__('ID: %1$s', 'event_espresso'), |
|
41 | + esc_html($datetime->get('DTT_ID')) |
|
42 | + ); |
|
43 | + } |
|
44 | 44 | |
45 | - return $name; |
|
46 | - } |
|
45 | + return $name; |
|
46 | + } |
|
47 | 47 | |
48 | 48 | |
49 | - /** |
|
50 | - * Returns checkin value using checkin status and datetime |
|
51 | - * |
|
52 | - * @param EE_Checkin $checkin |
|
53 | - * @return string|null |
|
54 | - * @throws EE_Error |
|
55 | - * @throws ReflectionException |
|
56 | - */ |
|
57 | - public static function getCheckinValue(?EE_Checkin $checkin) |
|
58 | - { |
|
59 | - $value = null; |
|
60 | - if ($checkin instanceof EE_Checkin && $checkin->get('CHK_in') === true) { |
|
61 | - /* translators: 1: check-in timestamp */ |
|
62 | - $value = sprintf( |
|
63 | - esc_html__('IN: %1$s', 'event_espresso'), |
|
64 | - $checkin->get_datetime('CHK_timestamp', 'Y-m-d', 'g:i a') |
|
65 | - ); |
|
66 | - } elseif ($checkin instanceof EE_Checkin && $checkin->get('CHK_in') === false) { |
|
67 | - /* translators: 1: check-in timestamp */ |
|
68 | - $value = sprintf( |
|
69 | - esc_html__('OUT: %1$s', 'event_espresso'), |
|
70 | - $checkin->get_datetime('CHK_timestamp', 'Y-m-d', 'g:i a') |
|
71 | - ); |
|
72 | - } |
|
49 | + /** |
|
50 | + * Returns checkin value using checkin status and datetime |
|
51 | + * |
|
52 | + * @param EE_Checkin $checkin |
|
53 | + * @return string|null |
|
54 | + * @throws EE_Error |
|
55 | + * @throws ReflectionException |
|
56 | + */ |
|
57 | + public static function getCheckinValue(?EE_Checkin $checkin) |
|
58 | + { |
|
59 | + $value = null; |
|
60 | + if ($checkin instanceof EE_Checkin && $checkin->get('CHK_in') === true) { |
|
61 | + /* translators: 1: check-in timestamp */ |
|
62 | + $value = sprintf( |
|
63 | + esc_html__('IN: %1$s', 'event_espresso'), |
|
64 | + $checkin->get_datetime('CHK_timestamp', 'Y-m-d', 'g:i a') |
|
65 | + ); |
|
66 | + } elseif ($checkin instanceof EE_Checkin && $checkin->get('CHK_in') === false) { |
|
67 | + /* translators: 1: check-in timestamp */ |
|
68 | + $value = sprintf( |
|
69 | + esc_html__('OUT: %1$s', 'event_espresso'), |
|
70 | + $checkin->get_datetime('CHK_timestamp', 'Y-m-d', 'g:i a') |
|
71 | + ); |
|
72 | + } |
|
73 | 73 | |
74 | - return $value; |
|
75 | - } |
|
74 | + return $value; |
|
75 | + } |
|
76 | 76 | } |
@@ -41,489 +41,489 @@ |
||
41 | 41 | */ |
42 | 42 | class RegistrationsReport extends JobHandlerFile |
43 | 43 | { |
44 | - // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
45 | - // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
|
46 | - /** |
|
47 | - * Performs any necessary setup for starting the job. This is also a good |
|
48 | - * place to setup the $job_arguments which will be used for subsequent HTTP requests |
|
49 | - * when continue_job will be called |
|
50 | - * |
|
51 | - * @param JobParameters $job_parameters |
|
52 | - * @return JobStepResponse |
|
53 | - * @throws BatchRequestException |
|
54 | - * @throws EE_Error |
|
55 | - * @throws ReflectionException |
|
56 | - */ |
|
57 | - public function create_job(JobParameters $job_parameters) |
|
58 | - { |
|
59 | - $event_id = (int) $job_parameters->request_datum('EVT_ID', '0'); |
|
60 | - $DTT_ID = (int) $job_parameters->request_datum('DTT_ID', '0'); |
|
61 | - if (! EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) { |
|
62 | - throw new BatchRequestException(esc_html__('You do not have permission to view registrations', 'event_espresso')); |
|
63 | - } |
|
64 | - $filepath = $this->create_file_from_job_with_name( |
|
65 | - $job_parameters->job_id(), |
|
66 | - $this->get_filename() |
|
67 | - ); |
|
68 | - $job_parameters->add_extra_data('filepath', $filepath); |
|
69 | - $query_params = apply_filters('FHEE__EE_Export__report_registration_for_event', array( |
|
70 | - array( |
|
71 | - 'OR' => array( |
|
72 | - // don't include registrations from failed or abandoned transactions... |
|
73 | - 'Transaction.STS_ID' => array( |
|
74 | - 'NOT IN', |
|
75 | - array( |
|
76 | - EEM_Transaction::failed_status_code, |
|
77 | - EEM_Transaction::abandoned_status_code, |
|
78 | - ), |
|
79 | - ), |
|
80 | - // unless the registration is approved, in which case include it regardless of transaction status |
|
81 | - 'STS_ID' => EEM_Registration::status_id_approved, |
|
82 | - ), |
|
83 | - 'Ticket.TKT_deleted' => array('IN', array(true, false)), |
|
84 | - ), |
|
85 | - 'order_by' => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'), |
|
86 | - 'force_join' => array('Transaction', 'Ticket', 'Attendee'), |
|
87 | - 'caps' => EEM_Base::caps_read_admin, |
|
88 | - ), $event_id); |
|
89 | - if ($event_id) { |
|
90 | - $query_params[0]['EVT_ID'] = $event_id; |
|
91 | - } else { |
|
92 | - $query_params['force_join'][] = 'Event'; |
|
93 | - } |
|
94 | - if (! isset($query_params['force_join'])) { |
|
95 | - $query_params['force_join'] = array('Event', 'Transaction', 'Ticket', 'Attendee'); |
|
96 | - } |
|
97 | - $job_parameters->add_extra_data('query_params', $query_params); |
|
98 | - $question_labels = $this->_get_question_labels($query_params); |
|
99 | - $job_parameters->add_extra_data('question_labels', $question_labels); |
|
100 | - $job_parameters->set_job_size($this->count_units_to_process($query_params)); |
|
101 | - // we should also set the header columns |
|
102 | - $csv_data_for_row = $this->get_csv_data_for( |
|
103 | - $event_id, |
|
104 | - 0, |
|
105 | - 1, |
|
106 | - $job_parameters->extra_datum('question_labels'), |
|
107 | - $job_parameters->extra_datum('query_params'), |
|
108 | - $DTT_ID |
|
109 | - ); |
|
110 | - EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true); |
|
111 | - // if we actually processed a row there, record it |
|
112 | - if ($job_parameters->job_size()) { |
|
113 | - $job_parameters->mark_processed(1); |
|
114 | - } |
|
115 | - return new JobStepResponse( |
|
116 | - $job_parameters, |
|
117 | - esc_html__('Registrations report started successfully...', 'event_espresso') |
|
118 | - ); |
|
119 | - } |
|
44 | + // phpcs:disable PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
45 | + // phpcs:disable PSR2.Methods.MethodDeclaration.Underscore |
|
46 | + /** |
|
47 | + * Performs any necessary setup for starting the job. This is also a good |
|
48 | + * place to setup the $job_arguments which will be used for subsequent HTTP requests |
|
49 | + * when continue_job will be called |
|
50 | + * |
|
51 | + * @param JobParameters $job_parameters |
|
52 | + * @return JobStepResponse |
|
53 | + * @throws BatchRequestException |
|
54 | + * @throws EE_Error |
|
55 | + * @throws ReflectionException |
|
56 | + */ |
|
57 | + public function create_job(JobParameters $job_parameters) |
|
58 | + { |
|
59 | + $event_id = (int) $job_parameters->request_datum('EVT_ID', '0'); |
|
60 | + $DTT_ID = (int) $job_parameters->request_datum('DTT_ID', '0'); |
|
61 | + if (! EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) { |
|
62 | + throw new BatchRequestException(esc_html__('You do not have permission to view registrations', 'event_espresso')); |
|
63 | + } |
|
64 | + $filepath = $this->create_file_from_job_with_name( |
|
65 | + $job_parameters->job_id(), |
|
66 | + $this->get_filename() |
|
67 | + ); |
|
68 | + $job_parameters->add_extra_data('filepath', $filepath); |
|
69 | + $query_params = apply_filters('FHEE__EE_Export__report_registration_for_event', array( |
|
70 | + array( |
|
71 | + 'OR' => array( |
|
72 | + // don't include registrations from failed or abandoned transactions... |
|
73 | + 'Transaction.STS_ID' => array( |
|
74 | + 'NOT IN', |
|
75 | + array( |
|
76 | + EEM_Transaction::failed_status_code, |
|
77 | + EEM_Transaction::abandoned_status_code, |
|
78 | + ), |
|
79 | + ), |
|
80 | + // unless the registration is approved, in which case include it regardless of transaction status |
|
81 | + 'STS_ID' => EEM_Registration::status_id_approved, |
|
82 | + ), |
|
83 | + 'Ticket.TKT_deleted' => array('IN', array(true, false)), |
|
84 | + ), |
|
85 | + 'order_by' => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'), |
|
86 | + 'force_join' => array('Transaction', 'Ticket', 'Attendee'), |
|
87 | + 'caps' => EEM_Base::caps_read_admin, |
|
88 | + ), $event_id); |
|
89 | + if ($event_id) { |
|
90 | + $query_params[0]['EVT_ID'] = $event_id; |
|
91 | + } else { |
|
92 | + $query_params['force_join'][] = 'Event'; |
|
93 | + } |
|
94 | + if (! isset($query_params['force_join'])) { |
|
95 | + $query_params['force_join'] = array('Event', 'Transaction', 'Ticket', 'Attendee'); |
|
96 | + } |
|
97 | + $job_parameters->add_extra_data('query_params', $query_params); |
|
98 | + $question_labels = $this->_get_question_labels($query_params); |
|
99 | + $job_parameters->add_extra_data('question_labels', $question_labels); |
|
100 | + $job_parameters->set_job_size($this->count_units_to_process($query_params)); |
|
101 | + // we should also set the header columns |
|
102 | + $csv_data_for_row = $this->get_csv_data_for( |
|
103 | + $event_id, |
|
104 | + 0, |
|
105 | + 1, |
|
106 | + $job_parameters->extra_datum('question_labels'), |
|
107 | + $job_parameters->extra_datum('query_params'), |
|
108 | + $DTT_ID |
|
109 | + ); |
|
110 | + EEH_Export::write_data_array_to_csv($filepath, $csv_data_for_row, true); |
|
111 | + // if we actually processed a row there, record it |
|
112 | + if ($job_parameters->job_size()) { |
|
113 | + $job_parameters->mark_processed(1); |
|
114 | + } |
|
115 | + return new JobStepResponse( |
|
116 | + $job_parameters, |
|
117 | + esc_html__('Registrations report started successfully...', 'event_espresso') |
|
118 | + ); |
|
119 | + } |
|
120 | 120 | |
121 | 121 | |
122 | - /** |
|
123 | - * Gets the filename |
|
124 | - * |
|
125 | - * @return string |
|
126 | - */ |
|
127 | - protected function get_filename() |
|
128 | - { |
|
129 | - return apply_filters( |
|
130 | - 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__get_filename', |
|
131 | - sprintf( |
|
132 | - "event-espresso-registrations-%s.csv", |
|
133 | - str_replace(array(':', ' '), '-', current_time('mysql')) |
|
134 | - ) |
|
135 | - ); |
|
136 | - } |
|
122 | + /** |
|
123 | + * Gets the filename |
|
124 | + * |
|
125 | + * @return string |
|
126 | + */ |
|
127 | + protected function get_filename() |
|
128 | + { |
|
129 | + return apply_filters( |
|
130 | + 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__get_filename', |
|
131 | + sprintf( |
|
132 | + "event-espresso-registrations-%s.csv", |
|
133 | + str_replace(array(':', ' '), '-', current_time('mysql')) |
|
134 | + ) |
|
135 | + ); |
|
136 | + } |
|
137 | 137 | |
138 | 138 | |
139 | - /** |
|
140 | - * Gets the questions which are to be used for this report, so they |
|
141 | - * can be remembered for later |
|
142 | - * |
|
143 | - * @param array $registration_query_params |
|
144 | - * @return array question admin labels to be used for this report |
|
145 | - * @throws EE_Error |
|
146 | - */ |
|
147 | - protected function _get_question_labels($registration_query_params) |
|
148 | - { |
|
149 | - $where = isset($registration_query_params[0]) ? $registration_query_params[0] : null; |
|
150 | - $question_query_params = array(); |
|
151 | - if ($where !== null) { |
|
152 | - $question_query_params = array( |
|
153 | - $this->_change_registration_where_params_to_question_where_params($registration_query_params[0]), |
|
154 | - ); |
|
155 | - } |
|
156 | - // Make sure it's not a system question |
|
157 | - $question_query_params[0]['OR*not-system-questions'] = [ |
|
158 | - 'QST_system' => '', |
|
159 | - 'QST_system*null' => ['IS_NULL'] |
|
160 | - ]; |
|
161 | - if ( |
|
162 | - apply_filters( |
|
163 | - 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions', |
|
164 | - false, |
|
165 | - $registration_query_params |
|
166 | - ) |
|
167 | - ) { |
|
168 | - $question_query_params[0]['Answer.ANS_ID'] = array('IS_NOT_NULL'); |
|
169 | - } |
|
170 | - $question_query_params['group_by'] = array('QST_ID'); |
|
171 | - return array_unique(EEM_Question::instance()->get_col($question_query_params, 'QST_admin_label')); |
|
172 | - } |
|
139 | + /** |
|
140 | + * Gets the questions which are to be used for this report, so they |
|
141 | + * can be remembered for later |
|
142 | + * |
|
143 | + * @param array $registration_query_params |
|
144 | + * @return array question admin labels to be used for this report |
|
145 | + * @throws EE_Error |
|
146 | + */ |
|
147 | + protected function _get_question_labels($registration_query_params) |
|
148 | + { |
|
149 | + $where = isset($registration_query_params[0]) ? $registration_query_params[0] : null; |
|
150 | + $question_query_params = array(); |
|
151 | + if ($where !== null) { |
|
152 | + $question_query_params = array( |
|
153 | + $this->_change_registration_where_params_to_question_where_params($registration_query_params[0]), |
|
154 | + ); |
|
155 | + } |
|
156 | + // Make sure it's not a system question |
|
157 | + $question_query_params[0]['OR*not-system-questions'] = [ |
|
158 | + 'QST_system' => '', |
|
159 | + 'QST_system*null' => ['IS_NULL'] |
|
160 | + ]; |
|
161 | + if ( |
|
162 | + apply_filters( |
|
163 | + 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport___get_question_labels__only_include_answered_questions', |
|
164 | + false, |
|
165 | + $registration_query_params |
|
166 | + ) |
|
167 | + ) { |
|
168 | + $question_query_params[0]['Answer.ANS_ID'] = array('IS_NOT_NULL'); |
|
169 | + } |
|
170 | + $question_query_params['group_by'] = array('QST_ID'); |
|
171 | + return array_unique(EEM_Question::instance()->get_col($question_query_params, 'QST_admin_label')); |
|
172 | + } |
|
173 | 173 | |
174 | 174 | |
175 | - /** |
|
176 | - * Takes where params meant for registrations and changes them to work for questions |
|
177 | - * |
|
178 | - * @param array $reg_where_params |
|
179 | - * @return array |
|
180 | - * @throws EE_Error |
|
181 | - */ |
|
182 | - protected function _change_registration_where_params_to_question_where_params($reg_where_params) |
|
183 | - { |
|
184 | - $question_where_params = array(); |
|
185 | - foreach ($reg_where_params as $key => $val) { |
|
186 | - if (EEM_Registration::instance()->is_logic_query_param_key($key)) { |
|
187 | - $question_where_params[ $key ] = $this->_change_registration_where_params_to_question_where_params($val); |
|
188 | - } else { |
|
189 | - // it's a normal where condition |
|
190 | - $question_where_params[ 'Question_Group.Event.Registration.' . $key ] = $val; |
|
191 | - } |
|
192 | - } |
|
193 | - return $question_where_params; |
|
194 | - } |
|
175 | + /** |
|
176 | + * Takes where params meant for registrations and changes them to work for questions |
|
177 | + * |
|
178 | + * @param array $reg_where_params |
|
179 | + * @return array |
|
180 | + * @throws EE_Error |
|
181 | + */ |
|
182 | + protected function _change_registration_where_params_to_question_where_params($reg_where_params) |
|
183 | + { |
|
184 | + $question_where_params = array(); |
|
185 | + foreach ($reg_where_params as $key => $val) { |
|
186 | + if (EEM_Registration::instance()->is_logic_query_param_key($key)) { |
|
187 | + $question_where_params[ $key ] = $this->_change_registration_where_params_to_question_where_params($val); |
|
188 | + } else { |
|
189 | + // it's a normal where condition |
|
190 | + $question_where_params[ 'Question_Group.Event.Registration.' . $key ] = $val; |
|
191 | + } |
|
192 | + } |
|
193 | + return $question_where_params; |
|
194 | + } |
|
195 | 195 | |
196 | 196 | |
197 | - /** |
|
198 | - * Performs another step of the job |
|
199 | - * |
|
200 | - * @param JobParameters $job_parameters |
|
201 | - * @param int $batch_size |
|
202 | - * @return JobStepResponse |
|
203 | - * @throws EE_Error |
|
204 | - * @throws ReflectionException |
|
205 | - */ |
|
206 | - public function continue_job(JobParameters $job_parameters, $batch_size = 50) |
|
207 | - { |
|
208 | - if ($job_parameters->units_processed() < $job_parameters->job_size()) { |
|
209 | - $csv_data = $this->get_csv_data_for( |
|
210 | - (int) $job_parameters->request_datum('EVT_ID', '0'), |
|
211 | - $job_parameters->units_processed(), |
|
212 | - $batch_size, |
|
213 | - $job_parameters->extra_datum('question_labels'), |
|
214 | - $job_parameters->extra_datum('query_params'), |
|
215 | - (int) $job_parameters->request_datum('DTT_ID', '0') |
|
216 | - ); |
|
217 | - EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false); |
|
218 | - $units_processed = count($csv_data); |
|
219 | - } else { |
|
220 | - $csv_data = array(); |
|
221 | - $units_processed = 0; |
|
222 | - } |
|
223 | - $job_parameters->mark_processed($units_processed); |
|
224 | - $extra_response_data = array( |
|
225 | - 'file_url' => '', |
|
226 | - ); |
|
227 | - if ($units_processed < $batch_size) { |
|
228 | - $job_parameters->set_status(JobParameters::status_complete); |
|
229 | - $extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath')); |
|
230 | - } |
|
197 | + /** |
|
198 | + * Performs another step of the job |
|
199 | + * |
|
200 | + * @param JobParameters $job_parameters |
|
201 | + * @param int $batch_size |
|
202 | + * @return JobStepResponse |
|
203 | + * @throws EE_Error |
|
204 | + * @throws ReflectionException |
|
205 | + */ |
|
206 | + public function continue_job(JobParameters $job_parameters, $batch_size = 50) |
|
207 | + { |
|
208 | + if ($job_parameters->units_processed() < $job_parameters->job_size()) { |
|
209 | + $csv_data = $this->get_csv_data_for( |
|
210 | + (int) $job_parameters->request_datum('EVT_ID', '0'), |
|
211 | + $job_parameters->units_processed(), |
|
212 | + $batch_size, |
|
213 | + $job_parameters->extra_datum('question_labels'), |
|
214 | + $job_parameters->extra_datum('query_params'), |
|
215 | + (int) $job_parameters->request_datum('DTT_ID', '0') |
|
216 | + ); |
|
217 | + EEH_Export::write_data_array_to_csv($job_parameters->extra_datum('filepath'), $csv_data, false); |
|
218 | + $units_processed = count($csv_data); |
|
219 | + } else { |
|
220 | + $csv_data = array(); |
|
221 | + $units_processed = 0; |
|
222 | + } |
|
223 | + $job_parameters->mark_processed($units_processed); |
|
224 | + $extra_response_data = array( |
|
225 | + 'file_url' => '', |
|
226 | + ); |
|
227 | + if ($units_processed < $batch_size) { |
|
228 | + $job_parameters->set_status(JobParameters::status_complete); |
|
229 | + $extra_response_data['file_url'] = $this->get_url_to_file($job_parameters->extra_datum('filepath')); |
|
230 | + } |
|
231 | 231 | |
232 | - return new JobStepResponse( |
|
233 | - $job_parameters, |
|
234 | - sprintf(esc_html__('Wrote %1$s rows to report CSV file...', 'event_espresso'), count((array) $csv_data)), |
|
235 | - $extra_response_data |
|
236 | - ); |
|
237 | - } |
|
232 | + return new JobStepResponse( |
|
233 | + $job_parameters, |
|
234 | + sprintf(esc_html__('Wrote %1$s rows to report CSV file...', 'event_espresso'), count((array) $csv_data)), |
|
235 | + $extra_response_data |
|
236 | + ); |
|
237 | + } |
|
238 | 238 | |
239 | 239 | |
240 | - /** |
|
241 | - * Gets the csv data for a batch of registrations |
|
242 | - * |
|
243 | - * @param int|null $event_id |
|
244 | - * @param int $offset |
|
245 | - * @param int $limit |
|
246 | - * @param array $question_labels the IDs for all the questions which were answered by someone in this selection |
|
247 | - * @param array $query_params for using where querying the model |
|
248 | - * @param int $DTT_ID |
|
249 | - * @return array top-level keys are numeric, next-level keys are column headers |
|
250 | - * @throws EE_Error |
|
251 | - * @throws ReflectionException |
|
252 | - */ |
|
253 | - public function get_csv_data_for($event_id, $offset, $limit, $question_labels, $query_params, $DTT_ID = 0) |
|
254 | - { |
|
255 | - $reg_fields_to_include = [ |
|
256 | - 'TXN_ID', |
|
257 | - 'ATT_ID', |
|
258 | - 'REG_date', |
|
259 | - 'REG_code', |
|
260 | - 'REG_count', |
|
261 | - 'REG_final_price', |
|
262 | - ]; |
|
263 | - $att_fields_to_include = [ |
|
264 | - 'ATT_fname', |
|
265 | - 'ATT_lname', |
|
266 | - 'ATT_email', |
|
267 | - 'ATT_address', |
|
268 | - 'ATT_address2', |
|
269 | - 'ATT_city', |
|
270 | - 'STA_ID', |
|
271 | - 'CNT_ISO', |
|
272 | - 'ATT_zip', |
|
273 | - 'ATT_phone', |
|
274 | - ]; |
|
275 | - $registrations_csv_ready_array = []; |
|
276 | - $reg_model = EE_Registry::instance()->load_model('Registration'); |
|
277 | - $query_params['limit'] = [$offset, $limit]; |
|
278 | - $registration_rows = $reg_model->get_all_wpdb_results($query_params); |
|
279 | - foreach ($registration_rows as $reg_row) { |
|
280 | - if (!is_array($reg_row)) { |
|
281 | - continue; |
|
282 | - } |
|
283 | - $reg_csv_array = []; |
|
284 | - // registration Id |
|
285 | - $reg_id_field = $reg_model->field_settings_for('REG_ID'); |
|
286 | - $reg_csv_array[ EEH_Export::get_column_name_for_field($reg_id_field) ] = EEH_Export::prepare_value_from_db_for_display( |
|
287 | - $reg_model, |
|
288 | - 'REG_ID', |
|
289 | - $reg_row[ $reg_id_field->get_qualified_column() ] |
|
290 | - ); |
|
291 | - if (! $event_id) { |
|
292 | - // get the event's name and Id |
|
293 | - $reg_csv_array[ (string) esc_html__('Event', 'event_espresso') ] = sprintf( |
|
294 | - /* translators: 1: event name, 2: event ID */ |
|
295 | - esc_html__('%1$s (%2$s)', 'event_espresso'), |
|
296 | - EEH_Export::prepare_value_from_db_for_display( |
|
297 | - EEM_Event::instance(), |
|
298 | - 'EVT_name', |
|
299 | - $reg_row['Event_CPT.post_title'] |
|
300 | - ), |
|
301 | - $reg_row['Event_CPT.ID'] |
|
302 | - ); |
|
303 | - } |
|
304 | - // add attendee columns |
|
305 | - $reg_csv_array = (new Attendee($att_fields_to_include, $reg_row)) |
|
306 | - ->addAttendeeColumns($reg_csv_array); |
|
307 | - // add registration columns |
|
308 | - $reg_csv_array = (new Registration($reg_fields_to_include, $reg_row)) |
|
309 | - ->addRegistrationColumns($reg_csv_array); |
|
310 | - // get pretty status |
|
311 | - $stati = EEM_Status::instance()->localized_status( |
|
312 | - [ |
|
313 | - $reg_row['Registration.STS_ID'] => esc_html__('unknown', 'event_espresso'), |
|
314 | - $reg_row['TransactionTable.STS_ID'] => esc_html__('unknown', 'event_espresso'), |
|
315 | - ], |
|
316 | - false, |
|
317 | - 'sentence' |
|
318 | - ); |
|
319 | - $is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false; |
|
320 | - $reg_csv_array[ (string) esc_html__("Registration Status", 'event_espresso') ] = $stati[ $reg_row['Registration.STS_ID'] ]; |
|
321 | - // get pretty transaction status |
|
322 | - $reg_csv_array[ (string) esc_html__("Transaction Status", 'event_espresso') ] = $stati[ $reg_row['TransactionTable.STS_ID'] ]; |
|
323 | - $reg_csv_array[ (string) esc_html__('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg |
|
324 | - ? EEH_Export::prepare_value_from_db_for_display( |
|
325 | - EEM_Transaction::instance(), |
|
326 | - 'TXN_total', |
|
327 | - $reg_row['TransactionTable.TXN_total'], |
|
328 | - 'localized_float' |
|
329 | - ) : '0.00'; |
|
330 | - $reg_csv_array[ (string) esc_html__('Amount Paid', 'event_espresso') ] = $is_primary_reg |
|
331 | - ? EEH_Export::prepare_value_from_db_for_display( |
|
332 | - EEM_Transaction::instance(), |
|
333 | - 'TXN_paid', |
|
334 | - $reg_row['TransactionTable.TXN_paid'], |
|
335 | - 'localized_float' |
|
336 | - ) : '0.00'; |
|
337 | - $payment_methods = []; |
|
338 | - $gateway_txn_ids_etc = []; |
|
339 | - $payment_times = []; |
|
340 | - if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) { |
|
341 | - $payments_info = EEM_Payment::instance()->get_all_wpdb_results( |
|
342 | - [ |
|
343 | - [ |
|
344 | - 'TXN_ID' => $reg_row['TransactionTable.TXN_ID'], |
|
345 | - 'STS_ID' => EEM_Payment::status_id_approved, |
|
346 | - ], |
|
347 | - 'force_join' => ['Payment_Method'], |
|
348 | - ], |
|
349 | - ARRAY_A, |
|
350 | - 'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time' |
|
351 | - ); |
|
352 | - list($payment_methods, $gateway_txn_ids_etc, $payment_times) = PaymentsInfo::extractPaymentInfo($payments_info); |
|
353 | - } |
|
354 | - $reg_csv_array[ (string) esc_html__('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times); |
|
355 | - $reg_csv_array[ (string) esc_html__('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods); |
|
356 | - $reg_csv_array[ (string) esc_html__('Gateway Transaction ID(s)', 'event_espresso') ] = implode( |
|
357 | - ',', |
|
358 | - $gateway_txn_ids_etc |
|
359 | - ); |
|
360 | - // get ticket of registration and its price |
|
361 | - $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
362 | - if ($reg_row['Ticket.TKT_ID']) { |
|
363 | - $ticket_name = EEH_Export::prepare_value_from_db_for_display( |
|
364 | - $ticket_model, |
|
365 | - 'TKT_name', |
|
366 | - $reg_row['Ticket.TKT_name'] |
|
367 | - ); |
|
368 | - $datetimes_strings = []; |
|
369 | - foreach ( |
|
370 | - EEM_Datetime::instance()->get_all_wpdb_results( |
|
371 | - [ |
|
372 | - ['Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']], |
|
373 | - 'order_by' => ['DTT_EVT_start' => 'ASC'], |
|
374 | - 'default_where_conditions' => 'none', |
|
375 | - ] |
|
376 | - ) as $datetime |
|
377 | - ) { |
|
378 | - $datetimes_strings[] = EEH_Export::prepare_value_from_db_for_display( |
|
379 | - EEM_Datetime::instance(), |
|
380 | - 'DTT_EVT_start', |
|
381 | - $datetime['Datetime.DTT_EVT_start'] |
|
382 | - ); |
|
383 | - } |
|
384 | - } else { |
|
385 | - $ticket_name = esc_html__('Unknown', 'event_espresso'); |
|
386 | - $datetimes_strings = [esc_html__('Unknown', 'event_espresso')]; |
|
387 | - } |
|
388 | - $reg_csv_array[ (string) $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name; |
|
389 | - $reg_csv_array[ (string) esc_html__("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings); |
|
390 | - // add answer columns |
|
391 | - $reg_csv_array = (new Answers($reg_row)) |
|
392 | - ->addAnswerColumns($reg_csv_array, $question_labels); |
|
393 | - // Include check-in data |
|
394 | - if ($event_id && $DTT_ID) { |
|
395 | - // get whether or not the user has checked in |
|
396 | - $reg_csv_array[ (string) esc_html__('Datetime Check-ins #', 'event_espresso') ] = $reg_model->count_related( |
|
397 | - $reg_row['Registration.REG_ID'], |
|
398 | - 'Checkin', |
|
399 | - [ |
|
400 | - [ |
|
401 | - 'DTT_ID' => $DTT_ID |
|
402 | - ] |
|
403 | - ] |
|
404 | - ); |
|
405 | - /** @var EE_Datetime $datetime */ |
|
406 | - $datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID); |
|
407 | - $checkin_rows = EEM_Checkin::instance()->get_all( |
|
408 | - [ |
|
409 | - [ |
|
410 | - 'REG_ID' => $reg_row['Registration.REG_ID'], |
|
411 | - 'DTT_ID' => $datetime->get('DTT_ID'), |
|
412 | - ], |
|
413 | - ] |
|
414 | - ); |
|
415 | - $checkins = []; |
|
416 | - foreach ($checkin_rows as $checkin_row) { |
|
417 | - /** @var EE_Checkin $checkin_row */ |
|
418 | - $checkin_value = Checkins::getCheckinValue($checkin_row); |
|
419 | - if ($checkin_value) { |
|
420 | - $checkins[] = $checkin_value; |
|
421 | - } |
|
422 | - } |
|
423 | - $datetime_name = Checkins::getDatetineLabel($datetime); |
|
424 | - $reg_csv_array[ (string) $datetime_name ] = implode(' --- ', $checkins); |
|
425 | - } elseif ($event_id) { |
|
426 | - // get whether or not the user has checked in |
|
427 | - $reg_csv_array[ (string) esc_html__('Event Check-ins #', 'event_espresso') ] = $reg_model->count_related( |
|
428 | - $reg_row['Registration.REG_ID'], |
|
429 | - 'Checkin' |
|
430 | - ); |
|
431 | - $datetimes = EEM_Datetime::instance()->get_all( |
|
432 | - [ |
|
433 | - [ |
|
434 | - 'Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID'], |
|
435 | - ], |
|
436 | - 'order_by' => ['DTT_EVT_start' => 'ASC'], |
|
437 | - 'default_where_conditions' => 'none', |
|
438 | - ] |
|
439 | - ); |
|
440 | - foreach ($datetimes as $datetime) { |
|
441 | - /** @var EE_Checkin $checkin_row */ |
|
442 | - $checkin_row = EEM_Checkin::instance()->get_one( |
|
443 | - [ |
|
444 | - [ |
|
445 | - 'REG_ID' => $reg_row['Registration.REG_ID'], |
|
446 | - 'DTT_ID' => $datetime->get('DTT_ID'), |
|
447 | - ], |
|
448 | - 'limit' => 1, |
|
449 | - 'order_by' => [ |
|
450 | - 'CHK_ID' => 'DESC' |
|
451 | - ] |
|
452 | - ] |
|
453 | - ); |
|
454 | - $checkin_value = Checkins::getCheckinValue($checkin_row); |
|
455 | - $datetime_name = Checkins::getDatetineLabel($datetime); |
|
456 | - $reg_csv_array[ (string) $datetime_name ] = $checkin_value; |
|
457 | - } |
|
458 | - } |
|
459 | - /** |
|
460 | - * Filter to change the contents of each row of the registrations report CSV file. |
|
461 | - * This can be used to add or remote columns from the CSV file, or change their values. |
|
462 | - * Note when using: all rows in the CSV should have the same columns. |
|
463 | - * @param array $reg_csv_array keys are the column names, values are their cell values |
|
464 | - * @param array $reg_row one entry from EEM_Registration::get_all_wpdb_results() |
|
465 | - */ |
|
466 | - $registrations_csv_ready_array[] = apply_filters( |
|
467 | - 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array', |
|
468 | - $reg_csv_array, |
|
469 | - $reg_row |
|
470 | - ); |
|
471 | - } |
|
472 | - // if we couldn't export anything, we want to at least show the column headers |
|
473 | - if (empty($registrations_csv_ready_array)) { |
|
474 | - $reg_csv_array = []; |
|
475 | - $model_and_fields_to_include = [ |
|
476 | - 'Registration' => $reg_fields_to_include, |
|
477 | - 'Attendee' => $att_fields_to_include, |
|
478 | - ]; |
|
479 | - foreach ($model_and_fields_to_include as $model_name => $field_list) { |
|
480 | - $model = EE_Registry::instance()->load_model($model_name); |
|
481 | - foreach ($field_list as $field_name) { |
|
482 | - $field = $model->field_settings_for($field_name); |
|
483 | - $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = null; |
|
484 | - } |
|
485 | - } |
|
486 | - $registrations_csv_ready_array[] = $reg_csv_array; |
|
487 | - } |
|
488 | - return $registrations_csv_ready_array; |
|
489 | - } |
|
240 | + /** |
|
241 | + * Gets the csv data for a batch of registrations |
|
242 | + * |
|
243 | + * @param int|null $event_id |
|
244 | + * @param int $offset |
|
245 | + * @param int $limit |
|
246 | + * @param array $question_labels the IDs for all the questions which were answered by someone in this selection |
|
247 | + * @param array $query_params for using where querying the model |
|
248 | + * @param int $DTT_ID |
|
249 | + * @return array top-level keys are numeric, next-level keys are column headers |
|
250 | + * @throws EE_Error |
|
251 | + * @throws ReflectionException |
|
252 | + */ |
|
253 | + public function get_csv_data_for($event_id, $offset, $limit, $question_labels, $query_params, $DTT_ID = 0) |
|
254 | + { |
|
255 | + $reg_fields_to_include = [ |
|
256 | + 'TXN_ID', |
|
257 | + 'ATT_ID', |
|
258 | + 'REG_date', |
|
259 | + 'REG_code', |
|
260 | + 'REG_count', |
|
261 | + 'REG_final_price', |
|
262 | + ]; |
|
263 | + $att_fields_to_include = [ |
|
264 | + 'ATT_fname', |
|
265 | + 'ATT_lname', |
|
266 | + 'ATT_email', |
|
267 | + 'ATT_address', |
|
268 | + 'ATT_address2', |
|
269 | + 'ATT_city', |
|
270 | + 'STA_ID', |
|
271 | + 'CNT_ISO', |
|
272 | + 'ATT_zip', |
|
273 | + 'ATT_phone', |
|
274 | + ]; |
|
275 | + $registrations_csv_ready_array = []; |
|
276 | + $reg_model = EE_Registry::instance()->load_model('Registration'); |
|
277 | + $query_params['limit'] = [$offset, $limit]; |
|
278 | + $registration_rows = $reg_model->get_all_wpdb_results($query_params); |
|
279 | + foreach ($registration_rows as $reg_row) { |
|
280 | + if (!is_array($reg_row)) { |
|
281 | + continue; |
|
282 | + } |
|
283 | + $reg_csv_array = []; |
|
284 | + // registration Id |
|
285 | + $reg_id_field = $reg_model->field_settings_for('REG_ID'); |
|
286 | + $reg_csv_array[ EEH_Export::get_column_name_for_field($reg_id_field) ] = EEH_Export::prepare_value_from_db_for_display( |
|
287 | + $reg_model, |
|
288 | + 'REG_ID', |
|
289 | + $reg_row[ $reg_id_field->get_qualified_column() ] |
|
290 | + ); |
|
291 | + if (! $event_id) { |
|
292 | + // get the event's name and Id |
|
293 | + $reg_csv_array[ (string) esc_html__('Event', 'event_espresso') ] = sprintf( |
|
294 | + /* translators: 1: event name, 2: event ID */ |
|
295 | + esc_html__('%1$s (%2$s)', 'event_espresso'), |
|
296 | + EEH_Export::prepare_value_from_db_for_display( |
|
297 | + EEM_Event::instance(), |
|
298 | + 'EVT_name', |
|
299 | + $reg_row['Event_CPT.post_title'] |
|
300 | + ), |
|
301 | + $reg_row['Event_CPT.ID'] |
|
302 | + ); |
|
303 | + } |
|
304 | + // add attendee columns |
|
305 | + $reg_csv_array = (new Attendee($att_fields_to_include, $reg_row)) |
|
306 | + ->addAttendeeColumns($reg_csv_array); |
|
307 | + // add registration columns |
|
308 | + $reg_csv_array = (new Registration($reg_fields_to_include, $reg_row)) |
|
309 | + ->addRegistrationColumns($reg_csv_array); |
|
310 | + // get pretty status |
|
311 | + $stati = EEM_Status::instance()->localized_status( |
|
312 | + [ |
|
313 | + $reg_row['Registration.STS_ID'] => esc_html__('unknown', 'event_espresso'), |
|
314 | + $reg_row['TransactionTable.STS_ID'] => esc_html__('unknown', 'event_espresso'), |
|
315 | + ], |
|
316 | + false, |
|
317 | + 'sentence' |
|
318 | + ); |
|
319 | + $is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false; |
|
320 | + $reg_csv_array[ (string) esc_html__("Registration Status", 'event_espresso') ] = $stati[ $reg_row['Registration.STS_ID'] ]; |
|
321 | + // get pretty transaction status |
|
322 | + $reg_csv_array[ (string) esc_html__("Transaction Status", 'event_espresso') ] = $stati[ $reg_row['TransactionTable.STS_ID'] ]; |
|
323 | + $reg_csv_array[ (string) esc_html__('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg |
|
324 | + ? EEH_Export::prepare_value_from_db_for_display( |
|
325 | + EEM_Transaction::instance(), |
|
326 | + 'TXN_total', |
|
327 | + $reg_row['TransactionTable.TXN_total'], |
|
328 | + 'localized_float' |
|
329 | + ) : '0.00'; |
|
330 | + $reg_csv_array[ (string) esc_html__('Amount Paid', 'event_espresso') ] = $is_primary_reg |
|
331 | + ? EEH_Export::prepare_value_from_db_for_display( |
|
332 | + EEM_Transaction::instance(), |
|
333 | + 'TXN_paid', |
|
334 | + $reg_row['TransactionTable.TXN_paid'], |
|
335 | + 'localized_float' |
|
336 | + ) : '0.00'; |
|
337 | + $payment_methods = []; |
|
338 | + $gateway_txn_ids_etc = []; |
|
339 | + $payment_times = []; |
|
340 | + if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) { |
|
341 | + $payments_info = EEM_Payment::instance()->get_all_wpdb_results( |
|
342 | + [ |
|
343 | + [ |
|
344 | + 'TXN_ID' => $reg_row['TransactionTable.TXN_ID'], |
|
345 | + 'STS_ID' => EEM_Payment::status_id_approved, |
|
346 | + ], |
|
347 | + 'force_join' => ['Payment_Method'], |
|
348 | + ], |
|
349 | + ARRAY_A, |
|
350 | + 'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time' |
|
351 | + ); |
|
352 | + list($payment_methods, $gateway_txn_ids_etc, $payment_times) = PaymentsInfo::extractPaymentInfo($payments_info); |
|
353 | + } |
|
354 | + $reg_csv_array[ (string) esc_html__('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times); |
|
355 | + $reg_csv_array[ (string) esc_html__('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods); |
|
356 | + $reg_csv_array[ (string) esc_html__('Gateway Transaction ID(s)', 'event_espresso') ] = implode( |
|
357 | + ',', |
|
358 | + $gateway_txn_ids_etc |
|
359 | + ); |
|
360 | + // get ticket of registration and its price |
|
361 | + $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
362 | + if ($reg_row['Ticket.TKT_ID']) { |
|
363 | + $ticket_name = EEH_Export::prepare_value_from_db_for_display( |
|
364 | + $ticket_model, |
|
365 | + 'TKT_name', |
|
366 | + $reg_row['Ticket.TKT_name'] |
|
367 | + ); |
|
368 | + $datetimes_strings = []; |
|
369 | + foreach ( |
|
370 | + EEM_Datetime::instance()->get_all_wpdb_results( |
|
371 | + [ |
|
372 | + ['Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']], |
|
373 | + 'order_by' => ['DTT_EVT_start' => 'ASC'], |
|
374 | + 'default_where_conditions' => 'none', |
|
375 | + ] |
|
376 | + ) as $datetime |
|
377 | + ) { |
|
378 | + $datetimes_strings[] = EEH_Export::prepare_value_from_db_for_display( |
|
379 | + EEM_Datetime::instance(), |
|
380 | + 'DTT_EVT_start', |
|
381 | + $datetime['Datetime.DTT_EVT_start'] |
|
382 | + ); |
|
383 | + } |
|
384 | + } else { |
|
385 | + $ticket_name = esc_html__('Unknown', 'event_espresso'); |
|
386 | + $datetimes_strings = [esc_html__('Unknown', 'event_espresso')]; |
|
387 | + } |
|
388 | + $reg_csv_array[ (string) $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name; |
|
389 | + $reg_csv_array[ (string) esc_html__("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings); |
|
390 | + // add answer columns |
|
391 | + $reg_csv_array = (new Answers($reg_row)) |
|
392 | + ->addAnswerColumns($reg_csv_array, $question_labels); |
|
393 | + // Include check-in data |
|
394 | + if ($event_id && $DTT_ID) { |
|
395 | + // get whether or not the user has checked in |
|
396 | + $reg_csv_array[ (string) esc_html__('Datetime Check-ins #', 'event_espresso') ] = $reg_model->count_related( |
|
397 | + $reg_row['Registration.REG_ID'], |
|
398 | + 'Checkin', |
|
399 | + [ |
|
400 | + [ |
|
401 | + 'DTT_ID' => $DTT_ID |
|
402 | + ] |
|
403 | + ] |
|
404 | + ); |
|
405 | + /** @var EE_Datetime $datetime */ |
|
406 | + $datetime = EEM_Datetime::instance()->get_one_by_ID($DTT_ID); |
|
407 | + $checkin_rows = EEM_Checkin::instance()->get_all( |
|
408 | + [ |
|
409 | + [ |
|
410 | + 'REG_ID' => $reg_row['Registration.REG_ID'], |
|
411 | + 'DTT_ID' => $datetime->get('DTT_ID'), |
|
412 | + ], |
|
413 | + ] |
|
414 | + ); |
|
415 | + $checkins = []; |
|
416 | + foreach ($checkin_rows as $checkin_row) { |
|
417 | + /** @var EE_Checkin $checkin_row */ |
|
418 | + $checkin_value = Checkins::getCheckinValue($checkin_row); |
|
419 | + if ($checkin_value) { |
|
420 | + $checkins[] = $checkin_value; |
|
421 | + } |
|
422 | + } |
|
423 | + $datetime_name = Checkins::getDatetineLabel($datetime); |
|
424 | + $reg_csv_array[ (string) $datetime_name ] = implode(' --- ', $checkins); |
|
425 | + } elseif ($event_id) { |
|
426 | + // get whether or not the user has checked in |
|
427 | + $reg_csv_array[ (string) esc_html__('Event Check-ins #', 'event_espresso') ] = $reg_model->count_related( |
|
428 | + $reg_row['Registration.REG_ID'], |
|
429 | + 'Checkin' |
|
430 | + ); |
|
431 | + $datetimes = EEM_Datetime::instance()->get_all( |
|
432 | + [ |
|
433 | + [ |
|
434 | + 'Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID'], |
|
435 | + ], |
|
436 | + 'order_by' => ['DTT_EVT_start' => 'ASC'], |
|
437 | + 'default_where_conditions' => 'none', |
|
438 | + ] |
|
439 | + ); |
|
440 | + foreach ($datetimes as $datetime) { |
|
441 | + /** @var EE_Checkin $checkin_row */ |
|
442 | + $checkin_row = EEM_Checkin::instance()->get_one( |
|
443 | + [ |
|
444 | + [ |
|
445 | + 'REG_ID' => $reg_row['Registration.REG_ID'], |
|
446 | + 'DTT_ID' => $datetime->get('DTT_ID'), |
|
447 | + ], |
|
448 | + 'limit' => 1, |
|
449 | + 'order_by' => [ |
|
450 | + 'CHK_ID' => 'DESC' |
|
451 | + ] |
|
452 | + ] |
|
453 | + ); |
|
454 | + $checkin_value = Checkins::getCheckinValue($checkin_row); |
|
455 | + $datetime_name = Checkins::getDatetineLabel($datetime); |
|
456 | + $reg_csv_array[ (string) $datetime_name ] = $checkin_value; |
|
457 | + } |
|
458 | + } |
|
459 | + /** |
|
460 | + * Filter to change the contents of each row of the registrations report CSV file. |
|
461 | + * This can be used to add or remote columns from the CSV file, or change their values. |
|
462 | + * Note when using: all rows in the CSV should have the same columns. |
|
463 | + * @param array $reg_csv_array keys are the column names, values are their cell values |
|
464 | + * @param array $reg_row one entry from EEM_Registration::get_all_wpdb_results() |
|
465 | + */ |
|
466 | + $registrations_csv_ready_array[] = apply_filters( |
|
467 | + 'FHEE__EventEspressoBatchRequest__JobHandlers__RegistrationsReport__reg_csv_array', |
|
468 | + $reg_csv_array, |
|
469 | + $reg_row |
|
470 | + ); |
|
471 | + } |
|
472 | + // if we couldn't export anything, we want to at least show the column headers |
|
473 | + if (empty($registrations_csv_ready_array)) { |
|
474 | + $reg_csv_array = []; |
|
475 | + $model_and_fields_to_include = [ |
|
476 | + 'Registration' => $reg_fields_to_include, |
|
477 | + 'Attendee' => $att_fields_to_include, |
|
478 | + ]; |
|
479 | + foreach ($model_and_fields_to_include as $model_name => $field_list) { |
|
480 | + $model = EE_Registry::instance()->load_model($model_name); |
|
481 | + foreach ($field_list as $field_name) { |
|
482 | + $field = $model->field_settings_for($field_name); |
|
483 | + $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = null; |
|
484 | + } |
|
485 | + } |
|
486 | + $registrations_csv_ready_array[] = $reg_csv_array; |
|
487 | + } |
|
488 | + return $registrations_csv_ready_array; |
|
489 | + } |
|
490 | 490 | |
491 | 491 | |
492 | - /** |
|
493 | - * Counts total unit to process |
|
494 | - * |
|
495 | - * @param array $query_params |
|
496 | - * @return int |
|
497 | - * @throws EE_Error |
|
498 | - */ |
|
499 | - public function count_units_to_process($query_params) |
|
500 | - { |
|
501 | - return EEM_Registration::instance()->count( |
|
502 | - array_diff_key( |
|
503 | - $query_params, |
|
504 | - array_flip( |
|
505 | - ['limit'] |
|
506 | - ) |
|
507 | - ) |
|
508 | - ); |
|
509 | - } |
|
492 | + /** |
|
493 | + * Counts total unit to process |
|
494 | + * |
|
495 | + * @param array $query_params |
|
496 | + * @return int |
|
497 | + * @throws EE_Error |
|
498 | + */ |
|
499 | + public function count_units_to_process($query_params) |
|
500 | + { |
|
501 | + return EEM_Registration::instance()->count( |
|
502 | + array_diff_key( |
|
503 | + $query_params, |
|
504 | + array_flip( |
|
505 | + ['limit'] |
|
506 | + ) |
|
507 | + ) |
|
508 | + ); |
|
509 | + } |
|
510 | 510 | |
511 | 511 | |
512 | - /** |
|
513 | - * Performs any clean-up logic when we know the job is completed. |
|
514 | - * In this case, we delete the temporary file |
|
515 | - * |
|
516 | - * @param JobParameters $job_parameters |
|
517 | - * @return JobStepResponse |
|
518 | - * @throws EE_Error |
|
519 | - */ |
|
520 | - public function cleanup_job(JobParameters $job_parameters) |
|
521 | - { |
|
522 | - $this->_file_helper->delete( |
|
523 | - EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')), |
|
524 | - true, |
|
525 | - 'd' |
|
526 | - ); |
|
527 | - return new JobStepResponse($job_parameters, esc_html__('Cleaned up temporary file', 'event_espresso')); |
|
528 | - } |
|
512 | + /** |
|
513 | + * Performs any clean-up logic when we know the job is completed. |
|
514 | + * In this case, we delete the temporary file |
|
515 | + * |
|
516 | + * @param JobParameters $job_parameters |
|
517 | + * @return JobStepResponse |
|
518 | + * @throws EE_Error |
|
519 | + */ |
|
520 | + public function cleanup_job(JobParameters $job_parameters) |
|
521 | + { |
|
522 | + $this->_file_helper->delete( |
|
523 | + EEH_File::remove_filename_from_filepath($job_parameters->extra_datum('filepath')), |
|
524 | + true, |
|
525 | + 'd' |
|
526 | + ); |
|
527 | + return new JobStepResponse($job_parameters, esc_html__('Cleaned up temporary file', 'event_espresso')); |
|
528 | + } |
|
529 | 529 | } |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | { |
59 | 59 | $event_id = (int) $job_parameters->request_datum('EVT_ID', '0'); |
60 | 60 | $DTT_ID = (int) $job_parameters->request_datum('DTT_ID', '0'); |
61 | - if (! EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) { |
|
61 | + if ( ! EE_Capabilities::instance()->current_user_can('ee_read_registrations', 'generating_report')) { |
|
62 | 62 | throw new BatchRequestException(esc_html__('You do not have permission to view registrations', 'event_espresso')); |
63 | 63 | } |
64 | 64 | $filepath = $this->create_file_from_job_with_name( |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | } else { |
92 | 92 | $query_params['force_join'][] = 'Event'; |
93 | 93 | } |
94 | - if (! isset($query_params['force_join'])) { |
|
94 | + if ( ! isset($query_params['force_join'])) { |
|
95 | 95 | $query_params['force_join'] = array('Event', 'Transaction', 'Ticket', 'Attendee'); |
96 | 96 | } |
97 | 97 | $job_parameters->add_extra_data('query_params', $query_params); |
@@ -184,10 +184,10 @@ discard block |
||
184 | 184 | $question_where_params = array(); |
185 | 185 | foreach ($reg_where_params as $key => $val) { |
186 | 186 | if (EEM_Registration::instance()->is_logic_query_param_key($key)) { |
187 | - $question_where_params[ $key ] = $this->_change_registration_where_params_to_question_where_params($val); |
|
187 | + $question_where_params[$key] = $this->_change_registration_where_params_to_question_where_params($val); |
|
188 | 188 | } else { |
189 | 189 | // it's a normal where condition |
190 | - $question_where_params[ 'Question_Group.Event.Registration.' . $key ] = $val; |
|
190 | + $question_where_params['Question_Group.Event.Registration.'.$key] = $val; |
|
191 | 191 | } |
192 | 192 | } |
193 | 193 | return $question_where_params; |
@@ -277,20 +277,20 @@ discard block |
||
277 | 277 | $query_params['limit'] = [$offset, $limit]; |
278 | 278 | $registration_rows = $reg_model->get_all_wpdb_results($query_params); |
279 | 279 | foreach ($registration_rows as $reg_row) { |
280 | - if (!is_array($reg_row)) { |
|
280 | + if ( ! is_array($reg_row)) { |
|
281 | 281 | continue; |
282 | 282 | } |
283 | 283 | $reg_csv_array = []; |
284 | 284 | // registration Id |
285 | 285 | $reg_id_field = $reg_model->field_settings_for('REG_ID'); |
286 | - $reg_csv_array[ EEH_Export::get_column_name_for_field($reg_id_field) ] = EEH_Export::prepare_value_from_db_for_display( |
|
286 | + $reg_csv_array[EEH_Export::get_column_name_for_field($reg_id_field)] = EEH_Export::prepare_value_from_db_for_display( |
|
287 | 287 | $reg_model, |
288 | 288 | 'REG_ID', |
289 | - $reg_row[ $reg_id_field->get_qualified_column() ] |
|
289 | + $reg_row[$reg_id_field->get_qualified_column()] |
|
290 | 290 | ); |
291 | - if (! $event_id) { |
|
291 | + if ( ! $event_id) { |
|
292 | 292 | // get the event's name and Id |
293 | - $reg_csv_array[ (string) esc_html__('Event', 'event_espresso') ] = sprintf( |
|
293 | + $reg_csv_array[(string) esc_html__('Event', 'event_espresso')] = sprintf( |
|
294 | 294 | /* translators: 1: event name, 2: event ID */ |
295 | 295 | esc_html__('%1$s (%2$s)', 'event_espresso'), |
296 | 296 | EEH_Export::prepare_value_from_db_for_display( |
@@ -317,17 +317,17 @@ discard block |
||
317 | 317 | 'sentence' |
318 | 318 | ); |
319 | 319 | $is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false; |
320 | - $reg_csv_array[ (string) esc_html__("Registration Status", 'event_espresso') ] = $stati[ $reg_row['Registration.STS_ID'] ]; |
|
320 | + $reg_csv_array[(string) esc_html__("Registration Status", 'event_espresso')] = $stati[$reg_row['Registration.STS_ID']]; |
|
321 | 321 | // get pretty transaction status |
322 | - $reg_csv_array[ (string) esc_html__("Transaction Status", 'event_espresso') ] = $stati[ $reg_row['TransactionTable.STS_ID'] ]; |
|
323 | - $reg_csv_array[ (string) esc_html__('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg |
|
322 | + $reg_csv_array[(string) esc_html__("Transaction Status", 'event_espresso')] = $stati[$reg_row['TransactionTable.STS_ID']]; |
|
323 | + $reg_csv_array[(string) esc_html__('Transaction Amount Due', 'event_espresso')] = $is_primary_reg |
|
324 | 324 | ? EEH_Export::prepare_value_from_db_for_display( |
325 | 325 | EEM_Transaction::instance(), |
326 | 326 | 'TXN_total', |
327 | 327 | $reg_row['TransactionTable.TXN_total'], |
328 | 328 | 'localized_float' |
329 | 329 | ) : '0.00'; |
330 | - $reg_csv_array[ (string) esc_html__('Amount Paid', 'event_espresso') ] = $is_primary_reg |
|
330 | + $reg_csv_array[(string) esc_html__('Amount Paid', 'event_espresso')] = $is_primary_reg |
|
331 | 331 | ? EEH_Export::prepare_value_from_db_for_display( |
332 | 332 | EEM_Transaction::instance(), |
333 | 333 | 'TXN_paid', |
@@ -351,9 +351,9 @@ discard block |
||
351 | 351 | ); |
352 | 352 | list($payment_methods, $gateway_txn_ids_etc, $payment_times) = PaymentsInfo::extractPaymentInfo($payments_info); |
353 | 353 | } |
354 | - $reg_csv_array[ (string) esc_html__('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times); |
|
355 | - $reg_csv_array[ (string) esc_html__('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods); |
|
356 | - $reg_csv_array[ (string) esc_html__('Gateway Transaction ID(s)', 'event_espresso') ] = implode( |
|
354 | + $reg_csv_array[(string) esc_html__('Payment Date(s)', 'event_espresso')] = implode(',', $payment_times); |
|
355 | + $reg_csv_array[(string) esc_html__('Payment Method(s)', 'event_espresso')] = implode(",", $payment_methods); |
|
356 | + $reg_csv_array[(string) esc_html__('Gateway Transaction ID(s)', 'event_espresso')] = implode( |
|
357 | 357 | ',', |
358 | 358 | $gateway_txn_ids_etc |
359 | 359 | ); |
@@ -385,15 +385,15 @@ discard block |
||
385 | 385 | $ticket_name = esc_html__('Unknown', 'event_espresso'); |
386 | 386 | $datetimes_strings = [esc_html__('Unknown', 'event_espresso')]; |
387 | 387 | } |
388 | - $reg_csv_array[ (string) $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name; |
|
389 | - $reg_csv_array[ (string) esc_html__("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings); |
|
388 | + $reg_csv_array[(string) $ticket_model->field_settings_for('TKT_name')->get_nicename()] = $ticket_name; |
|
389 | + $reg_csv_array[(string) esc_html__("Datetimes of Ticket", "event_espresso")] = implode(", ", $datetimes_strings); |
|
390 | 390 | // add answer columns |
391 | 391 | $reg_csv_array = (new Answers($reg_row)) |
392 | 392 | ->addAnswerColumns($reg_csv_array, $question_labels); |
393 | 393 | // Include check-in data |
394 | 394 | if ($event_id && $DTT_ID) { |
395 | 395 | // get whether or not the user has checked in |
396 | - $reg_csv_array[ (string) esc_html__('Datetime Check-ins #', 'event_espresso') ] = $reg_model->count_related( |
|
396 | + $reg_csv_array[(string) esc_html__('Datetime Check-ins #', 'event_espresso')] = $reg_model->count_related( |
|
397 | 397 | $reg_row['Registration.REG_ID'], |
398 | 398 | 'Checkin', |
399 | 399 | [ |
@@ -421,10 +421,10 @@ discard block |
||
421 | 421 | } |
422 | 422 | } |
423 | 423 | $datetime_name = Checkins::getDatetineLabel($datetime); |
424 | - $reg_csv_array[ (string) $datetime_name ] = implode(' --- ', $checkins); |
|
424 | + $reg_csv_array[(string) $datetime_name] = implode(' --- ', $checkins); |
|
425 | 425 | } elseif ($event_id) { |
426 | 426 | // get whether or not the user has checked in |
427 | - $reg_csv_array[ (string) esc_html__('Event Check-ins #', 'event_espresso') ] = $reg_model->count_related( |
|
427 | + $reg_csv_array[(string) esc_html__('Event Check-ins #', 'event_espresso')] = $reg_model->count_related( |
|
428 | 428 | $reg_row['Registration.REG_ID'], |
429 | 429 | 'Checkin' |
430 | 430 | ); |
@@ -453,7 +453,7 @@ discard block |
||
453 | 453 | ); |
454 | 454 | $checkin_value = Checkins::getCheckinValue($checkin_row); |
455 | 455 | $datetime_name = Checkins::getDatetineLabel($datetime); |
456 | - $reg_csv_array[ (string) $datetime_name ] = $checkin_value; |
|
456 | + $reg_csv_array[(string) $datetime_name] = $checkin_value; |
|
457 | 457 | } |
458 | 458 | } |
459 | 459 | /** |
@@ -480,7 +480,7 @@ discard block |
||
480 | 480 | $model = EE_Registry::instance()->load_model($model_name); |
481 | 481 | foreach ($field_list as $field_name) { |
482 | 482 | $field = $model->field_settings_for($field_name); |
483 | - $reg_csv_array[ EEH_Export::get_column_name_for_field($field) ] = null; |
|
483 | + $reg_csv_array[EEH_Export::get_column_name_for_field($field)] = null; |
|
484 | 484 | } |
485 | 485 | } |
486 | 486 | $registrations_csv_ready_array[] = $reg_csv_array; |
@@ -18,784 +18,784 @@ |
||
18 | 18 | class EE_Export |
19 | 19 | { |
20 | 20 | |
21 | - const option_prefix = 'ee_report_job_'; |
|
22 | - |
|
23 | - |
|
24 | - // instance of the EE_Export object |
|
25 | - private static $_instance = null; |
|
26 | - |
|
27 | - // instance of the EE_CSV object |
|
28 | - /** |
|
29 | - * |
|
30 | - * @var EE_CSV |
|
31 | - */ |
|
32 | - public $EE_CSV = null; |
|
33 | - |
|
34 | - |
|
35 | - private $_req_data = array(); |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * private constructor to prevent direct creation |
|
40 | - * |
|
41 | - * @Constructor |
|
42 | - * @access private |
|
43 | - * @param array $request_data |
|
44 | - */ |
|
45 | - private function __construct($request_data = array()) |
|
46 | - { |
|
47 | - $this->_req_data = $request_data; |
|
48 | - $this->today = date("Y-m-d", time()); |
|
49 | - require_once(EE_CLASSES . 'EE_CSV.class.php'); |
|
50 | - $this->EE_CSV = EE_CSV::instance(); |
|
51 | - } |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * @ singleton method used to instantiate class object |
|
56 | - * @ access public |
|
57 | - * |
|
58 | - * @param array $request_data |
|
59 | - * @return \EE_Export |
|
60 | - */ |
|
61 | - public static function instance($request_data = array()) |
|
62 | - { |
|
63 | - // check if class object is instantiated |
|
64 | - if (self::$_instance === null or ! is_object(self::$_instance) or ! (self::$_instance instanceof EE_Export)) { |
|
65 | - self::$_instance = new self($request_data); |
|
66 | - } |
|
67 | - return self::$_instance; |
|
68 | - } |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * @Export Event Espresso data - routes export requests |
|
73 | - * @access public |
|
74 | - * @return void | bool |
|
75 | - */ |
|
76 | - public function export() |
|
77 | - { |
|
78 | - // in case of bulk exports, the "actual" action will be in action2, but first check regular action for "export" keyword |
|
79 | - if (isset($this->_req_data['action']) && strpos($this->_req_data['action'], 'export') === false) { |
|
80 | - // check if action2 has export action |
|
81 | - if (isset($this->_req_data['action2']) && strpos($this->_req_data['action2'], 'export') !== false) { |
|
82 | - // whoop! there it is! |
|
83 | - $this->_req_data['action'] = $this->_req_data['action2']; |
|
84 | - } |
|
85 | - } |
|
86 | - |
|
87 | - $this->_req_data['export'] = isset($this->_req_data['export']) ? $this->_req_data['export'] : ''; |
|
88 | - |
|
89 | - switch ($this->_req_data['export']) { |
|
90 | - case 'report': |
|
91 | - switch ($this->_req_data['action']) { |
|
92 | - case "event": |
|
93 | - case "export_events": |
|
94 | - case 'all_event_data': |
|
95 | - $this->export_all_event_data(); |
|
96 | - break; |
|
97 | - |
|
98 | - case 'registrations_report_for_event': |
|
99 | - $this->report_registrations_for_event($this->_req_data['EVT_ID']); |
|
100 | - break; |
|
101 | - |
|
102 | - case 'attendees': |
|
103 | - $this->export_attendees(); |
|
104 | - break; |
|
105 | - |
|
106 | - case 'categories': |
|
107 | - $this->export_categories(); |
|
108 | - break; |
|
109 | - |
|
110 | - default: |
|
111 | - EE_Error::add_error( |
|
112 | - esc_html__('An error occurred! The requested export report could not be found.', 'event_espresso'), |
|
113 | - __FILE__, |
|
114 | - __FUNCTION__, |
|
115 | - __LINE__ |
|
116 | - ); |
|
117 | - return false; |
|
118 | - break; |
|
119 | - } |
|
120 | - break; // end of switch export : report |
|
121 | - default: |
|
122 | - break; |
|
123 | - } // end of switch export |
|
124 | - |
|
125 | - exit; |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * Downloads a CSV file with all the columns, but no data. This should be used for importing |
|
130 | - * |
|
131 | - * @return void kills execution |
|
132 | - * @throws EE_Error |
|
133 | - * @throws ReflectionException |
|
134 | - */ |
|
135 | - public function export_sample() |
|
136 | - { |
|
137 | - $event = EEM_Event::instance()->get_one(); |
|
138 | - $this->_req_data['EVT_ID'] = $event->ID(); |
|
139 | - $this->export_all_event_data(); |
|
140 | - } |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * @Export data for ALL events |
|
145 | - * @access public |
|
146 | - * @return void |
|
147 | - * @throws EE_Error |
|
148 | - * @throws ReflectionException |
|
149 | - */ |
|
150 | - public function export_all_event_data() |
|
151 | - { |
|
152 | - // are any Event IDs set? |
|
153 | - $event_query_params = array(); |
|
154 | - $related_models_query_params = array(); |
|
155 | - $related_through_reg_query_params = array(); |
|
156 | - $datetime_ticket_query_params = array(); |
|
157 | - $price_query_params = array(); |
|
158 | - $price_type_query_params = array(); |
|
159 | - $term_query_params = array(); |
|
160 | - $state_country_query_params = array(); |
|
161 | - $question_group_query_params = array(); |
|
162 | - $question_query_params = array(); |
|
163 | - if (isset($this->_req_data['EVT_ID'])) { |
|
164 | - // do we have an array of IDs ? |
|
165 | - |
|
166 | - if (is_array($this->_req_data['EVT_ID'])) { |
|
167 | - $EVT_IDs = array_map('sanitize_text_field', $this->_req_data['EVT_ID']); |
|
168 | - $value_to_equal = array('IN', $EVT_IDs); |
|
169 | - $filename = 'events'; |
|
170 | - } else { |
|
171 | - // generate regular where = clause |
|
172 | - $EVT_ID = absint($this->_req_data['EVT_ID']); |
|
173 | - $value_to_equal = $EVT_ID; |
|
174 | - $event = EE_Registry::instance()->load_model('Event')->get_one_by_ID($EVT_ID); |
|
175 | - |
|
176 | - $filename = 'event-' . ($event instanceof EE_Event ? $event->slug() : esc_html__('unknown', 'event_espresso')); |
|
177 | - } |
|
178 | - $event_query_params[0]['EVT_ID'] = $value_to_equal; |
|
179 | - $related_models_query_params[0]['Event.EVT_ID'] = $value_to_equal; |
|
180 | - $related_through_reg_query_params[0]['Registration.EVT_ID'] = $value_to_equal; |
|
181 | - $datetime_ticket_query_params[0]['Datetime.EVT_ID'] = $value_to_equal; |
|
182 | - $price_query_params[0]['Ticket.Datetime.EVT_ID'] = $value_to_equal; |
|
183 | - $price_type_query_params[0]['Price.Ticket.Datetime.EVT_ID'] = $value_to_equal; |
|
184 | - $term_query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $value_to_equal; |
|
185 | - $state_country_query_params[0]['Venue.Event.EVT_ID'] = $value_to_equal; |
|
186 | - $question_group_query_params[0]['Event.EVT_ID'] = $value_to_equal; |
|
187 | - $question_query_params[0]['Question_Group.Event.EVT_ID'] = $value_to_equal; |
|
188 | - } else { |
|
189 | - $filename = 'all-events'; |
|
190 | - } |
|
191 | - |
|
192 | - |
|
193 | - // array in the format: table name => query where clause |
|
194 | - $models_to_export = array( |
|
195 | - 'Event' => $event_query_params, |
|
196 | - 'Datetime' => $related_models_query_params, |
|
197 | - 'Ticket_Template' => $price_query_params, |
|
198 | - 'Ticket' => $datetime_ticket_query_params, |
|
199 | - 'Datetime_Ticket' => $datetime_ticket_query_params, |
|
200 | - 'Price_Type' => $price_type_query_params, |
|
201 | - 'Price' => $price_query_params, |
|
202 | - 'Ticket_Price' => $price_query_params, |
|
203 | - 'Term' => $term_query_params, |
|
204 | - 'Term_Taxonomy' => $related_models_query_params, |
|
205 | - 'Term_Relationship' => $related_models_query_params, // model has NO primary key... |
|
206 | - 'Country' => $state_country_query_params, |
|
207 | - 'State' => $state_country_query_params, |
|
208 | - 'Venue' => $related_models_query_params, |
|
209 | - 'Event_Venue' => $related_models_query_params, |
|
210 | - 'Question_Group' => $question_group_query_params, |
|
211 | - 'Event_Question_Group' => $question_group_query_params, |
|
212 | - 'Question' => $question_query_params, |
|
213 | - 'Question_Group_Question' => $question_query_params, |
|
214 | - // 'Transaction'=>$related_through_reg_query_params, |
|
215 | - // 'Registration'=>$related_models_query_params, |
|
216 | - // 'Attendee'=>$related_through_reg_query_params, |
|
217 | - // 'Line_Item'=> |
|
218 | - |
|
219 | - ); |
|
220 | - |
|
221 | - $model_data = $this->_get_export_data_for_models($models_to_export); |
|
222 | - |
|
223 | - $filename = $this->generate_filename($filename); |
|
224 | - |
|
225 | - if (! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $model_data)) { |
|
226 | - EE_Error::add_error( |
|
227 | - esc_html__( |
|
228 | - "'An error occurred and the Event details could not be exported from the database.'", |
|
229 | - "event_espresso" |
|
230 | - ), |
|
231 | - __FILE__, |
|
232 | - __FUNCTION__, |
|
233 | - __LINE__ |
|
234 | - ); |
|
235 | - } |
|
236 | - } |
|
237 | - |
|
238 | - public function report_attendees() |
|
239 | - { |
|
240 | - $attendee_rows = EEM_Attendee::instance()->get_all_wpdb_results( |
|
241 | - array( |
|
242 | - 'force_join' => array('State', 'Country'), |
|
243 | - 'caps' => EEM_Base::caps_read_admin, |
|
244 | - ) |
|
245 | - ); |
|
246 | - $csv_data = array(); |
|
247 | - foreach ($attendee_rows as $attendee_row) { |
|
248 | - $csv_row = array(); |
|
249 | - foreach (EEM_Attendee::instance()->field_settings() as $field_name => $field_obj) { |
|
250 | - if ($field_name == 'STA_ID') { |
|
251 | - $state_name_field = EEM_State::instance()->field_settings_for('STA_name'); |
|
252 | - $csv_row[ esc_html__('State', 'event_espresso') ] = $attendee_row[ $state_name_field->get_qualified_column( |
|
253 | - ) ]; |
|
254 | - } elseif ($field_name == 'CNT_ISO') { |
|
255 | - $country_name_field = EEM_Country::instance()->field_settings_for('CNT_name'); |
|
256 | - $csv_row[ esc_html__( |
|
257 | - 'Country', |
|
258 | - 'event_espresso' |
|
259 | - ) ] = $attendee_row[ $country_name_field->get_qualified_column() ]; |
|
260 | - } else { |
|
261 | - $csv_row[ $field_obj->get_nicename() ] = $attendee_row[ $field_obj->get_qualified_column() ]; |
|
262 | - } |
|
263 | - } |
|
264 | - $csv_data[] = $csv_row; |
|
265 | - } |
|
266 | - |
|
267 | - $filename = $this->generate_filename('contact-list-report'); |
|
268 | - |
|
269 | - $handle = $this->EE_CSV->begin_sending_csv($filename); |
|
270 | - $this->EE_CSV->write_data_array_to_csv($handle, $csv_data); |
|
271 | - $this->EE_CSV->end_sending_csv($handle); |
|
272 | - } |
|
273 | - |
|
274 | - |
|
275 | - /** |
|
276 | - * @Export data for ALL attendees |
|
277 | - * @access public |
|
278 | - * @return void |
|
279 | - * @throws EE_Error |
|
280 | - */ |
|
281 | - public function export_attendees() |
|
282 | - { |
|
283 | - |
|
284 | - $states_that_have_an_attendee = EEM_State::instance()->get_all( |
|
285 | - array(0 => array('Attendee.ATT_ID' => array('IS NOT NULL'))) |
|
286 | - ); |
|
287 | - $countries_that_have_an_attendee = EEM_Country::instance()->get_all( |
|
288 | - array(0 => array('Attendee.ATT_ID' => array('IS NOT NULL'))) |
|
289 | - ); |
|
290 | - // $states_to_export_query_params |
|
291 | - $models_to_export = array( |
|
292 | - 'Country' => array(array('CNT_ISO' => array('IN', array_keys($countries_that_have_an_attendee)))), |
|
293 | - 'State' => array(array('STA_ID' => array('IN', array_keys($states_that_have_an_attendee)))), |
|
294 | - 'Attendee' => array(), |
|
295 | - ); |
|
296 | - |
|
297 | - |
|
298 | - $model_data = $this->_get_export_data_for_models($models_to_export); |
|
299 | - $filename = $this->generate_filename('all-attendees'); |
|
300 | - |
|
301 | - if (! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $model_data)) { |
|
302 | - EE_Error::add_error( |
|
303 | - esc_html__( |
|
304 | - 'An error occurred and the Attendee data could not be exported from the database.', |
|
305 | - 'event_espresso' |
|
306 | - ), |
|
307 | - __FILE__, |
|
308 | - __FUNCTION__, |
|
309 | - __LINE__ |
|
310 | - ); |
|
311 | - } |
|
312 | - } |
|
313 | - |
|
314 | - /** |
|
315 | - * Shortcut for preparing a database result for display |
|
316 | - * |
|
317 | - * @param EEM_Base $model |
|
318 | - * @param string $field_name |
|
319 | - * @param string $raw_db_value |
|
320 | - * @param bool|string $pretty_schema true to display pretty, a string to use a specific "Schema", or false to |
|
321 | - * NOT display pretty |
|
322 | - * @return string |
|
323 | - * @throws EE_Error |
|
324 | - */ |
|
325 | - protected function _prepare_value_from_db_for_display($model, $field_name, $raw_db_value, $pretty_schema = true) |
|
326 | - { |
|
327 | - $field_obj = $model->field_settings_for($field_name); |
|
328 | - $value_on_model_obj = $field_obj->prepare_for_set_from_db($raw_db_value); |
|
329 | - if ($field_obj instanceof EE_Datetime_Field) { |
|
330 | - $field_obj->set_date_format( |
|
331 | - EE_CSV::instance()->get_date_format_for_csv($field_obj->get_date_format($pretty_schema)), |
|
332 | - $pretty_schema |
|
333 | - ); |
|
334 | - $field_obj->set_time_format( |
|
335 | - EE_CSV::instance()->get_time_format_for_csv($field_obj->get_time_format($pretty_schema)), |
|
336 | - $pretty_schema |
|
337 | - ); |
|
338 | - } |
|
339 | - if ($pretty_schema === true) { |
|
340 | - return $field_obj->prepare_for_pretty_echoing($value_on_model_obj); |
|
341 | - } elseif (is_string($pretty_schema)) { |
|
342 | - return $field_obj->prepare_for_pretty_echoing($value_on_model_obj, $pretty_schema); |
|
343 | - } else { |
|
344 | - return $field_obj->prepare_for_get($value_on_model_obj); |
|
345 | - } |
|
346 | - } |
|
347 | - |
|
348 | - /** |
|
349 | - * Export a custom CSV of registration info including: A bunch of the reg fields, the time of the event, the price |
|
350 | - * name, and the questions associated with the registrations |
|
351 | - * |
|
352 | - * @param int $event_id |
|
353 | - * @throws EE_Error |
|
354 | - * @throws ReflectionException |
|
355 | - */ |
|
356 | - public function report_registrations_for_event($event_id = null) |
|
357 | - { |
|
358 | - $reg_fields_to_include = array( |
|
359 | - 'TXN_ID', |
|
360 | - 'ATT_ID', |
|
361 | - 'REG_ID', |
|
362 | - 'REG_date', |
|
363 | - 'REG_code', |
|
364 | - 'REG_count', |
|
365 | - 'REG_final_price', |
|
366 | - |
|
367 | - ); |
|
368 | - $att_fields_to_include = array( |
|
369 | - 'ATT_fname', |
|
370 | - 'ATT_lname', |
|
371 | - 'ATT_email', |
|
372 | - 'ATT_address', |
|
373 | - 'ATT_address2', |
|
374 | - 'ATT_city', |
|
375 | - 'STA_ID', |
|
376 | - 'CNT_ISO', |
|
377 | - 'ATT_zip', |
|
378 | - 'ATT_phone', |
|
379 | - ); |
|
380 | - |
|
381 | - $registrations_csv_ready_array = array(); |
|
382 | - $reg_model = EE_Registry::instance()->load_model('Registration'); |
|
383 | - $query_params = apply_filters( |
|
384 | - 'FHEE__EE_Export__report_registration_for_event', |
|
385 | - array( |
|
386 | - array( |
|
387 | - 'OR' => array( |
|
388 | - // don't include registrations from failed or abandoned transactions... |
|
389 | - 'Transaction.STS_ID' => array( |
|
390 | - 'NOT IN', |
|
391 | - array(EEM_Transaction::failed_status_code, EEM_Transaction::abandoned_status_code), |
|
392 | - ), |
|
393 | - // unless the registration is approved, in which case include it regardless of transaction status |
|
394 | - 'STS_ID' => EEM_Registration::status_id_approved, |
|
395 | - ), |
|
396 | - 'Ticket.TKT_deleted' => array('IN', array(true, false)), |
|
397 | - ), |
|
398 | - 'order_by' => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'), |
|
399 | - 'force_join' => array('Transaction', 'Ticket', 'Attendee'), |
|
400 | - 'caps' => EEM_Base::caps_read_admin, |
|
401 | - ), |
|
402 | - $event_id |
|
403 | - ); |
|
404 | - if ($event_id) { |
|
405 | - $query_params[0]['EVT_ID'] = $event_id; |
|
406 | - } else { |
|
407 | - $query_params['force_join'][] = 'Event'; |
|
408 | - } |
|
409 | - $registration_rows = $reg_model->get_all_wpdb_results($query_params); |
|
410 | - // get all questions which relate to someone in this group |
|
411 | - $registration_ids = array(); |
|
412 | - foreach ($registration_rows as $reg_row) { |
|
413 | - $registration_ids[] = intval($reg_row['Registration.REG_ID']); |
|
414 | - } |
|
415 | - // EEM_Question::instance()->show_next_x_db_queries(); |
|
416 | - $questions_for_these_regs_rows = EEM_Question::instance()->get_all_wpdb_results( |
|
417 | - array(array('Answer.REG_ID' => array('IN', $registration_ids))) |
|
418 | - ); |
|
419 | - foreach ($registration_rows as $reg_row) { |
|
420 | - if (is_array($reg_row)) { |
|
421 | - $reg_csv_array = array(); |
|
422 | - if (! $event_id) { |
|
423 | - // get the event's name and Id |
|
424 | - $reg_csv_array[ esc_html__('Event', 'event_espresso') ] = sprintf( |
|
425 | - esc_html__('%1$s (%2$s)', 'event_espresso'), |
|
426 | - $this->_prepare_value_from_db_for_display( |
|
427 | - EEM_Event::instance(), |
|
428 | - 'EVT_name', |
|
429 | - $reg_row['Event_CPT.post_title'] |
|
430 | - ), |
|
431 | - $reg_row['Event_CPT.ID'] |
|
432 | - ); |
|
433 | - } |
|
434 | - $is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false; |
|
435 | - /*@var $reg_row EE_Registration */ |
|
436 | - foreach ($reg_fields_to_include as $field_name) { |
|
437 | - $field = $reg_model->field_settings_for($field_name); |
|
438 | - if ($field_name == 'REG_final_price') { |
|
439 | - $value = $this->_prepare_value_from_db_for_display( |
|
440 | - $reg_model, |
|
441 | - $field_name, |
|
442 | - $reg_row['Registration.REG_final_price'], |
|
443 | - 'localized_float' |
|
444 | - ); |
|
445 | - } elseif ($field_name == 'REG_count') { |
|
446 | - $value = sprintf( |
|
447 | - esc_html__('%s of %s', 'event_espresso'), |
|
448 | - $this->_prepare_value_from_db_for_display( |
|
449 | - $reg_model, |
|
450 | - 'REG_count', |
|
451 | - $reg_row['Registration.REG_count'] |
|
452 | - ), |
|
453 | - $this->_prepare_value_from_db_for_display( |
|
454 | - $reg_model, |
|
455 | - 'REG_group_size', |
|
456 | - $reg_row['Registration.REG_group_size'] |
|
457 | - ) |
|
458 | - ); |
|
459 | - } elseif ($field_name == 'REG_date') { |
|
460 | - $value = $this->_prepare_value_from_db_for_display( |
|
461 | - $reg_model, |
|
462 | - $field_name, |
|
463 | - $reg_row['Registration.REG_date'], |
|
464 | - 'no_html' |
|
465 | - ); |
|
466 | - } else { |
|
467 | - $value = $this->_prepare_value_from_db_for_display( |
|
468 | - $reg_model, |
|
469 | - $field_name, |
|
470 | - $reg_row[ $field->get_qualified_column() ] |
|
471 | - ); |
|
472 | - } |
|
473 | - $reg_csv_array[ $this->_get_column_name_for_field($field) ] = $value; |
|
474 | - if ($field_name == 'REG_final_price') { |
|
475 | - // add a column named Currency after the final price |
|
476 | - $reg_csv_array[ esc_html__("Currency", "event_espresso") ] = EE_Config::instance()->currency->code; |
|
477 | - } |
|
478 | - } |
|
479 | - // get pretty status |
|
480 | - $stati = EEM_Status::instance()->localized_status( |
|
481 | - array( |
|
482 | - $reg_row['Registration.STS_ID'] => esc_html__('unknown', 'event_espresso'), |
|
483 | - $reg_row['TransactionTable.STS_ID'] => esc_html__('unknown', 'event_espresso'), |
|
484 | - ), |
|
485 | - false, |
|
486 | - 'sentence' |
|
487 | - ); |
|
488 | - $reg_csv_array[ esc_html__( |
|
489 | - "Registration Status", |
|
490 | - 'event_espresso' |
|
491 | - ) ] = $stati[ $reg_row['Registration.STS_ID'] ]; |
|
492 | - // get pretty trnasaction status |
|
493 | - $reg_csv_array[ esc_html__( |
|
494 | - "Transaction Status", |
|
495 | - 'event_espresso' |
|
496 | - ) ] = $stati[ $reg_row['TransactionTable.STS_ID'] ]; |
|
497 | - $reg_csv_array[ esc_html__('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg |
|
498 | - ? $this->_prepare_value_from_db_for_display( |
|
499 | - EEM_Transaction::instance(), |
|
500 | - 'TXN_total', |
|
501 | - $reg_row['TransactionTable.TXN_total'], |
|
502 | - 'localized_float' |
|
503 | - ) : '0.00'; |
|
504 | - $reg_csv_array[ esc_html__('Amount Paid', 'event_espresso') ] = $is_primary_reg |
|
505 | - ? $this->_prepare_value_from_db_for_display( |
|
506 | - EEM_Transaction::instance(), |
|
507 | - 'TXN_paid', |
|
508 | - $reg_row['TransactionTable.TXN_paid'], |
|
509 | - 'localized_float' |
|
510 | - ) : '0.00'; |
|
511 | - $payment_methods = array(); |
|
512 | - $gateway_txn_ids_etc = array(); |
|
513 | - $payment_times = array(); |
|
514 | - if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) { |
|
515 | - $payments_info = EEM_Payment::instance()->get_all_wpdb_results( |
|
516 | - array( |
|
517 | - array( |
|
518 | - 'TXN_ID' => $reg_row['TransactionTable.TXN_ID'], |
|
519 | - 'STS_ID' => EEM_Payment::status_id_approved, |
|
520 | - ), |
|
521 | - 'force_join' => array('Payment_Method'), |
|
522 | - ), |
|
523 | - ARRAY_A, |
|
524 | - 'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time' |
|
525 | - ); |
|
526 | - list($payment_methods, $gateway_txn_ids_etc, $payment_times) = PaymentsInfo::extractPaymentInfo($payments_info); |
|
527 | - } |
|
528 | - $reg_csv_array[ esc_html__('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times); |
|
529 | - $reg_csv_array[ esc_html__('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods); |
|
530 | - $reg_csv_array[ esc_html__('Gateway Transaction ID(s)', 'event_espresso') ] = implode( |
|
531 | - ',', |
|
532 | - $gateway_txn_ids_etc |
|
533 | - ); |
|
534 | - |
|
535 | - // get whether or not the user has checked in |
|
536 | - $reg_csv_array[ esc_html__("Check-Ins", "event_espresso") ] = $reg_model->count_related( |
|
537 | - $reg_row['Registration.REG_ID'], |
|
538 | - 'Checkin' |
|
539 | - ); |
|
540 | - // get ticket of registration and its price |
|
541 | - $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
542 | - if ($reg_row['Ticket.TKT_ID']) { |
|
543 | - $ticket_name = $this->_prepare_value_from_db_for_display( |
|
544 | - $ticket_model, |
|
545 | - 'TKT_name', |
|
546 | - $reg_row['Ticket.TKT_name'] |
|
547 | - ); |
|
548 | - $datetimes_strings = array(); |
|
549 | - foreach ( |
|
550 | - EEM_Datetime::instance()->get_all_wpdb_results( |
|
551 | - array( |
|
552 | - array('Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']), |
|
553 | - 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
554 | - 'default_where_conditions' => 'none', |
|
555 | - ) |
|
556 | - ) as $datetime |
|
557 | - ) { |
|
558 | - $datetimes_strings[] = $this->_prepare_value_from_db_for_display( |
|
559 | - EEM_Datetime::instance(), |
|
560 | - 'DTT_EVT_start', |
|
561 | - $datetime['Datetime.DTT_EVT_start'] |
|
562 | - ); |
|
563 | - } |
|
564 | - } else { |
|
565 | - $ticket_name = esc_html__('Unknown', 'event_espresso'); |
|
566 | - $datetimes_strings = array(esc_html__('Unknown', 'event_espresso')); |
|
567 | - } |
|
568 | - $reg_csv_array[ $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name; |
|
569 | - $reg_csv_array[ esc_html__("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings); |
|
570 | - // get datetime(s) of registration |
|
571 | - |
|
572 | - // add attendee columns |
|
573 | - foreach ($att_fields_to_include as $att_field_name) { |
|
574 | - $field_obj = EEM_Attendee::instance()->field_settings_for($att_field_name); |
|
575 | - if ($reg_row['Attendee_CPT.ID']) { |
|
576 | - if ($att_field_name == 'STA_ID') { |
|
577 | - $value = EEM_State::instance()->get_var( |
|
578 | - array(array('STA_ID' => $reg_row['Attendee_Meta.STA_ID'])), |
|
579 | - 'STA_name' |
|
580 | - ); |
|
581 | - } elseif ($att_field_name == 'CNT_ISO') { |
|
582 | - $value = EEM_Country::instance()->get_var( |
|
583 | - array(array('CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO'])), |
|
584 | - 'CNT_name' |
|
585 | - ); |
|
586 | - } else { |
|
587 | - $value = $this->_prepare_value_from_db_for_display( |
|
588 | - EEM_Attendee::instance(), |
|
589 | - $att_field_name, |
|
590 | - $reg_row[ $field_obj->get_qualified_column() ] |
|
591 | - ); |
|
592 | - } |
|
593 | - } else { |
|
594 | - $value = ''; |
|
595 | - } |
|
596 | - |
|
597 | - $reg_csv_array[ $this->_get_column_name_for_field($field_obj) ] = $value; |
|
598 | - } |
|
599 | - |
|
600 | - // make sure each registration has the same questions in the same order |
|
601 | - foreach ($questions_for_these_regs_rows as $question_row) { |
|
602 | - if (! isset($reg_csv_array[ $question_row['Question.QST_admin_label'] ])) { |
|
603 | - $reg_csv_array[ $question_row['Question.QST_admin_label'] ] = null; |
|
604 | - } |
|
605 | - } |
|
606 | - // now fill out the questions THEY answered |
|
607 | - foreach ( |
|
608 | - EEM_Answer::instance()->get_all_wpdb_results( |
|
609 | - array(array('REG_ID' => $reg_row['Registration.REG_ID']), 'force_join' => array('Question')) |
|
610 | - ) as $answer_row |
|
611 | - ) { |
|
612 | - /* @var $answer EE_Answer */ |
|
613 | - if ($answer_row['Question.QST_ID']) { |
|
614 | - $question_label = $this->_prepare_value_from_db_for_display( |
|
615 | - EEM_Question::instance(), |
|
616 | - 'QST_admin_label', |
|
617 | - $answer_row['Question.QST_admin_label'] |
|
618 | - ); |
|
619 | - } else { |
|
620 | - $question_label = sprintf(esc_html__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']); |
|
621 | - } |
|
622 | - if (isset($answer_row['Question.QST_type']) && $answer_row['Question.QST_type'] == EEM_Question::QST_type_state) { |
|
623 | - $reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID( |
|
624 | - $answer_row['Answer.ANS_value'] |
|
625 | - ); |
|
626 | - } else { |
|
627 | - $reg_csv_array[ $question_label ] = $this->_prepare_value_from_db_for_display( |
|
628 | - EEM_Answer::instance(), |
|
629 | - 'ANS_value', |
|
630 | - $answer_row['Answer.ANS_value'] |
|
631 | - ); |
|
632 | - } |
|
633 | - } |
|
634 | - $registrations_csv_ready_array[] = apply_filters( |
|
635 | - 'FHEE__EE_Export__report_registrations__reg_csv_array', |
|
636 | - $reg_csv_array, |
|
637 | - $reg_row |
|
638 | - ); |
|
639 | - } |
|
640 | - } |
|
641 | - |
|
642 | - // if we couldn't export anything, we want to at least show the column headers |
|
643 | - if (empty($registrations_csv_ready_array)) { |
|
644 | - $reg_csv_array = array(); |
|
645 | - $model_and_fields_to_include = array( |
|
646 | - 'Registration' => $reg_fields_to_include, |
|
647 | - 'Attendee' => $att_fields_to_include, |
|
648 | - ); |
|
649 | - foreach ($model_and_fields_to_include as $model_name => $field_list) { |
|
650 | - $model = EE_Registry::instance()->load_model($model_name); |
|
651 | - foreach ($field_list as $field_name) { |
|
652 | - $field = $model->field_settings_for($field_name); |
|
653 | - $reg_csv_array[ $this->_get_column_name_for_field( |
|
654 | - $field |
|
655 | - ) ] = null;// $registration->get($field->get_name()); |
|
656 | - } |
|
657 | - } |
|
658 | - $registrations_csv_ready_array [] = $reg_csv_array; |
|
659 | - } |
|
660 | - if ($event_id) { |
|
661 | - $event_slug = EEM_Event::instance()->get_var(array(array('EVT_ID' => $event_id)), 'EVT_slug'); |
|
662 | - if (! $event_slug) { |
|
663 | - $event_slug = esc_html__('unknown', 'event_espresso'); |
|
664 | - } |
|
665 | - } else { |
|
666 | - $event_slug = esc_html__('all', 'event_espresso'); |
|
667 | - } |
|
668 | - $filename = sprintf("registrations-for-%s", $event_slug); |
|
669 | - |
|
670 | - $handle = $this->EE_CSV->begin_sending_csv($filename); |
|
671 | - $this->EE_CSV->write_data_array_to_csv($handle, $registrations_csv_ready_array); |
|
672 | - $this->EE_CSV->end_sending_csv($handle); |
|
673 | - } |
|
674 | - |
|
675 | - /** |
|
676 | - * Gets the 'normal' column named for fields |
|
677 | - * |
|
678 | - * @param EE_Model_Field_Base $field |
|
679 | - * @return string |
|
680 | - * @throws EE_Error |
|
681 | - */ |
|
682 | - protected function _get_column_name_for_field(EE_Model_Field_Base $field) |
|
683 | - { |
|
684 | - return $field->get_nicename() . "[" . $field->get_name() . "]"; |
|
685 | - } |
|
686 | - |
|
687 | - |
|
688 | - /** |
|
689 | - * @Export data for ALL events |
|
690 | - * @access public |
|
691 | - * @return void |
|
692 | - */ |
|
693 | - public function export_categories() |
|
694 | - { |
|
695 | - // are any Event IDs set? |
|
696 | - $query_params = array(); |
|
697 | - if (isset($this->_req_data['EVT_CAT_ID'])) { |
|
698 | - // do we have an array of IDs ? |
|
699 | - if (is_array($this->_req_data['EVT_CAT_ID'])) { |
|
700 | - // generate an "IN (CSV)" where clause |
|
701 | - $EVT_CAT_IDs = array_map('sanitize_text_field', $this->_req_data['EVT_CAT_ID']); |
|
702 | - $filename = 'event-categories'; |
|
703 | - $query_params[0]['term_taxonomy_id'] = array('IN', $EVT_CAT_IDs); |
|
704 | - } else { |
|
705 | - // generate regular where = clause |
|
706 | - $EVT_CAT_ID = absint($this->_req_data['EVT_CAT_ID']); |
|
707 | - $filename = 'event-category#' . $EVT_CAT_ID; |
|
708 | - $query_params[0]['term_taxonomy_id'] = $EVT_CAT_ID; |
|
709 | - } |
|
710 | - } else { |
|
711 | - // no IDs means we will d/l the entire table |
|
712 | - $filename = 'all-categories'; |
|
713 | - } |
|
714 | - |
|
715 | - $tables_to_export = array( |
|
716 | - 'Term_Taxonomy' => $query_params, |
|
717 | - ); |
|
718 | - |
|
719 | - $table_data = $this->_get_export_data_for_models($tables_to_export); |
|
720 | - $filename = $this->generate_filename($filename); |
|
721 | - |
|
722 | - if (! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $table_data)) { |
|
723 | - EE_Error::add_error( |
|
724 | - esc_html__( |
|
725 | - 'An error occurred and the Category details could not be exported from the database.', |
|
726 | - 'event_espresso' |
|
727 | - ), |
|
728 | - __FILE__, |
|
729 | - __FUNCTION__, |
|
730 | - __LINE__ |
|
731 | - ); |
|
732 | - } |
|
733 | - } |
|
734 | - |
|
735 | - |
|
736 | - /** |
|
737 | - * @process export name to create a suitable filename |
|
738 | - * @access private |
|
739 | - * @param string - export_name |
|
740 | - * @return string on success, FALSE on fail |
|
741 | - */ |
|
742 | - private function generate_filename($export_name = '') |
|
743 | - { |
|
744 | - if ($export_name != '') { |
|
745 | - $filename = get_bloginfo('name') . '-' . $export_name; |
|
746 | - $filename = sanitize_key($filename) . '-' . $this->today; |
|
747 | - return $filename; |
|
748 | - } else { |
|
749 | - EE_Error::add_error(esc_html__("No filename was provided", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
|
750 | - } |
|
751 | - return false; |
|
752 | - } |
|
753 | - |
|
754 | - |
|
755 | - /** |
|
756 | - * @recursive function for exporting table data and merging the results with the next results |
|
757 | - * @access private |
|
758 | - * @param array $models_to_export keys are model names (eg 'Event', 'Attendee', etc.) and values are arrays of |
|
759 | - * query params @return bool on success, FALSE on fail |
|
760 | - * @throws EE_Error |
|
761 | - * @throws ReflectionException |
|
762 | - * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
763 | - */ |
|
764 | - private function _get_export_data_for_models($models_to_export = array()) |
|
765 | - { |
|
766 | - $table_data = false; |
|
767 | - if (is_array($models_to_export)) { |
|
768 | - foreach ($models_to_export as $model_name => $query_params) { |
|
769 | - // check for a numerically-indexed array. in that case, $model_name is the value!! |
|
770 | - if (is_int($model_name)) { |
|
771 | - $model_name = $query_params; |
|
772 | - $query_params = array(); |
|
773 | - } |
|
774 | - $model = EE_Registry::instance()->load_model($model_name); |
|
775 | - $model_objects = $model->get_all($query_params); |
|
776 | - |
|
777 | - $table_data[ $model_name ] = array(); |
|
778 | - foreach ($model_objects as $model_object) { |
|
779 | - $model_data_array = array(); |
|
780 | - $fields = $model->field_settings(); |
|
781 | - foreach ($fields as $field) { |
|
782 | - $column_name = $field->get_nicename() . "[" . $field->get_name() . "]"; |
|
783 | - if ($field instanceof EE_Datetime_Field) { |
|
784 | - // $field->set_date_format('Y-m-d'); |
|
785 | - // $field->set_time_format('H:i:s'); |
|
786 | - $model_data_array[ $column_name ] = $model_object->get_datetime( |
|
787 | - $field->get_name(), |
|
788 | - 'Y-m-d', |
|
789 | - 'H:i:s' |
|
790 | - ); |
|
791 | - } else { |
|
792 | - $model_data_array[ $column_name ] = $model_object->get($field->get_name()); |
|
793 | - } |
|
794 | - } |
|
795 | - $table_data[ $model_name ][] = $model_data_array; |
|
796 | - } |
|
797 | - } |
|
798 | - } |
|
799 | - return $table_data; |
|
800 | - } |
|
21 | + const option_prefix = 'ee_report_job_'; |
|
22 | + |
|
23 | + |
|
24 | + // instance of the EE_Export object |
|
25 | + private static $_instance = null; |
|
26 | + |
|
27 | + // instance of the EE_CSV object |
|
28 | + /** |
|
29 | + * |
|
30 | + * @var EE_CSV |
|
31 | + */ |
|
32 | + public $EE_CSV = null; |
|
33 | + |
|
34 | + |
|
35 | + private $_req_data = array(); |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * private constructor to prevent direct creation |
|
40 | + * |
|
41 | + * @Constructor |
|
42 | + * @access private |
|
43 | + * @param array $request_data |
|
44 | + */ |
|
45 | + private function __construct($request_data = array()) |
|
46 | + { |
|
47 | + $this->_req_data = $request_data; |
|
48 | + $this->today = date("Y-m-d", time()); |
|
49 | + require_once(EE_CLASSES . 'EE_CSV.class.php'); |
|
50 | + $this->EE_CSV = EE_CSV::instance(); |
|
51 | + } |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * @ singleton method used to instantiate class object |
|
56 | + * @ access public |
|
57 | + * |
|
58 | + * @param array $request_data |
|
59 | + * @return \EE_Export |
|
60 | + */ |
|
61 | + public static function instance($request_data = array()) |
|
62 | + { |
|
63 | + // check if class object is instantiated |
|
64 | + if (self::$_instance === null or ! is_object(self::$_instance) or ! (self::$_instance instanceof EE_Export)) { |
|
65 | + self::$_instance = new self($request_data); |
|
66 | + } |
|
67 | + return self::$_instance; |
|
68 | + } |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * @Export Event Espresso data - routes export requests |
|
73 | + * @access public |
|
74 | + * @return void | bool |
|
75 | + */ |
|
76 | + public function export() |
|
77 | + { |
|
78 | + // in case of bulk exports, the "actual" action will be in action2, but first check regular action for "export" keyword |
|
79 | + if (isset($this->_req_data['action']) && strpos($this->_req_data['action'], 'export') === false) { |
|
80 | + // check if action2 has export action |
|
81 | + if (isset($this->_req_data['action2']) && strpos($this->_req_data['action2'], 'export') !== false) { |
|
82 | + // whoop! there it is! |
|
83 | + $this->_req_data['action'] = $this->_req_data['action2']; |
|
84 | + } |
|
85 | + } |
|
86 | + |
|
87 | + $this->_req_data['export'] = isset($this->_req_data['export']) ? $this->_req_data['export'] : ''; |
|
88 | + |
|
89 | + switch ($this->_req_data['export']) { |
|
90 | + case 'report': |
|
91 | + switch ($this->_req_data['action']) { |
|
92 | + case "event": |
|
93 | + case "export_events": |
|
94 | + case 'all_event_data': |
|
95 | + $this->export_all_event_data(); |
|
96 | + break; |
|
97 | + |
|
98 | + case 'registrations_report_for_event': |
|
99 | + $this->report_registrations_for_event($this->_req_data['EVT_ID']); |
|
100 | + break; |
|
101 | + |
|
102 | + case 'attendees': |
|
103 | + $this->export_attendees(); |
|
104 | + break; |
|
105 | + |
|
106 | + case 'categories': |
|
107 | + $this->export_categories(); |
|
108 | + break; |
|
109 | + |
|
110 | + default: |
|
111 | + EE_Error::add_error( |
|
112 | + esc_html__('An error occurred! The requested export report could not be found.', 'event_espresso'), |
|
113 | + __FILE__, |
|
114 | + __FUNCTION__, |
|
115 | + __LINE__ |
|
116 | + ); |
|
117 | + return false; |
|
118 | + break; |
|
119 | + } |
|
120 | + break; // end of switch export : report |
|
121 | + default: |
|
122 | + break; |
|
123 | + } // end of switch export |
|
124 | + |
|
125 | + exit; |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * Downloads a CSV file with all the columns, but no data. This should be used for importing |
|
130 | + * |
|
131 | + * @return void kills execution |
|
132 | + * @throws EE_Error |
|
133 | + * @throws ReflectionException |
|
134 | + */ |
|
135 | + public function export_sample() |
|
136 | + { |
|
137 | + $event = EEM_Event::instance()->get_one(); |
|
138 | + $this->_req_data['EVT_ID'] = $event->ID(); |
|
139 | + $this->export_all_event_data(); |
|
140 | + } |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * @Export data for ALL events |
|
145 | + * @access public |
|
146 | + * @return void |
|
147 | + * @throws EE_Error |
|
148 | + * @throws ReflectionException |
|
149 | + */ |
|
150 | + public function export_all_event_data() |
|
151 | + { |
|
152 | + // are any Event IDs set? |
|
153 | + $event_query_params = array(); |
|
154 | + $related_models_query_params = array(); |
|
155 | + $related_through_reg_query_params = array(); |
|
156 | + $datetime_ticket_query_params = array(); |
|
157 | + $price_query_params = array(); |
|
158 | + $price_type_query_params = array(); |
|
159 | + $term_query_params = array(); |
|
160 | + $state_country_query_params = array(); |
|
161 | + $question_group_query_params = array(); |
|
162 | + $question_query_params = array(); |
|
163 | + if (isset($this->_req_data['EVT_ID'])) { |
|
164 | + // do we have an array of IDs ? |
|
165 | + |
|
166 | + if (is_array($this->_req_data['EVT_ID'])) { |
|
167 | + $EVT_IDs = array_map('sanitize_text_field', $this->_req_data['EVT_ID']); |
|
168 | + $value_to_equal = array('IN', $EVT_IDs); |
|
169 | + $filename = 'events'; |
|
170 | + } else { |
|
171 | + // generate regular where = clause |
|
172 | + $EVT_ID = absint($this->_req_data['EVT_ID']); |
|
173 | + $value_to_equal = $EVT_ID; |
|
174 | + $event = EE_Registry::instance()->load_model('Event')->get_one_by_ID($EVT_ID); |
|
175 | + |
|
176 | + $filename = 'event-' . ($event instanceof EE_Event ? $event->slug() : esc_html__('unknown', 'event_espresso')); |
|
177 | + } |
|
178 | + $event_query_params[0]['EVT_ID'] = $value_to_equal; |
|
179 | + $related_models_query_params[0]['Event.EVT_ID'] = $value_to_equal; |
|
180 | + $related_through_reg_query_params[0]['Registration.EVT_ID'] = $value_to_equal; |
|
181 | + $datetime_ticket_query_params[0]['Datetime.EVT_ID'] = $value_to_equal; |
|
182 | + $price_query_params[0]['Ticket.Datetime.EVT_ID'] = $value_to_equal; |
|
183 | + $price_type_query_params[0]['Price.Ticket.Datetime.EVT_ID'] = $value_to_equal; |
|
184 | + $term_query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $value_to_equal; |
|
185 | + $state_country_query_params[0]['Venue.Event.EVT_ID'] = $value_to_equal; |
|
186 | + $question_group_query_params[0]['Event.EVT_ID'] = $value_to_equal; |
|
187 | + $question_query_params[0]['Question_Group.Event.EVT_ID'] = $value_to_equal; |
|
188 | + } else { |
|
189 | + $filename = 'all-events'; |
|
190 | + } |
|
191 | + |
|
192 | + |
|
193 | + // array in the format: table name => query where clause |
|
194 | + $models_to_export = array( |
|
195 | + 'Event' => $event_query_params, |
|
196 | + 'Datetime' => $related_models_query_params, |
|
197 | + 'Ticket_Template' => $price_query_params, |
|
198 | + 'Ticket' => $datetime_ticket_query_params, |
|
199 | + 'Datetime_Ticket' => $datetime_ticket_query_params, |
|
200 | + 'Price_Type' => $price_type_query_params, |
|
201 | + 'Price' => $price_query_params, |
|
202 | + 'Ticket_Price' => $price_query_params, |
|
203 | + 'Term' => $term_query_params, |
|
204 | + 'Term_Taxonomy' => $related_models_query_params, |
|
205 | + 'Term_Relationship' => $related_models_query_params, // model has NO primary key... |
|
206 | + 'Country' => $state_country_query_params, |
|
207 | + 'State' => $state_country_query_params, |
|
208 | + 'Venue' => $related_models_query_params, |
|
209 | + 'Event_Venue' => $related_models_query_params, |
|
210 | + 'Question_Group' => $question_group_query_params, |
|
211 | + 'Event_Question_Group' => $question_group_query_params, |
|
212 | + 'Question' => $question_query_params, |
|
213 | + 'Question_Group_Question' => $question_query_params, |
|
214 | + // 'Transaction'=>$related_through_reg_query_params, |
|
215 | + // 'Registration'=>$related_models_query_params, |
|
216 | + // 'Attendee'=>$related_through_reg_query_params, |
|
217 | + // 'Line_Item'=> |
|
218 | + |
|
219 | + ); |
|
220 | + |
|
221 | + $model_data = $this->_get_export_data_for_models($models_to_export); |
|
222 | + |
|
223 | + $filename = $this->generate_filename($filename); |
|
224 | + |
|
225 | + if (! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $model_data)) { |
|
226 | + EE_Error::add_error( |
|
227 | + esc_html__( |
|
228 | + "'An error occurred and the Event details could not be exported from the database.'", |
|
229 | + "event_espresso" |
|
230 | + ), |
|
231 | + __FILE__, |
|
232 | + __FUNCTION__, |
|
233 | + __LINE__ |
|
234 | + ); |
|
235 | + } |
|
236 | + } |
|
237 | + |
|
238 | + public function report_attendees() |
|
239 | + { |
|
240 | + $attendee_rows = EEM_Attendee::instance()->get_all_wpdb_results( |
|
241 | + array( |
|
242 | + 'force_join' => array('State', 'Country'), |
|
243 | + 'caps' => EEM_Base::caps_read_admin, |
|
244 | + ) |
|
245 | + ); |
|
246 | + $csv_data = array(); |
|
247 | + foreach ($attendee_rows as $attendee_row) { |
|
248 | + $csv_row = array(); |
|
249 | + foreach (EEM_Attendee::instance()->field_settings() as $field_name => $field_obj) { |
|
250 | + if ($field_name == 'STA_ID') { |
|
251 | + $state_name_field = EEM_State::instance()->field_settings_for('STA_name'); |
|
252 | + $csv_row[ esc_html__('State', 'event_espresso') ] = $attendee_row[ $state_name_field->get_qualified_column( |
|
253 | + ) ]; |
|
254 | + } elseif ($field_name == 'CNT_ISO') { |
|
255 | + $country_name_field = EEM_Country::instance()->field_settings_for('CNT_name'); |
|
256 | + $csv_row[ esc_html__( |
|
257 | + 'Country', |
|
258 | + 'event_espresso' |
|
259 | + ) ] = $attendee_row[ $country_name_field->get_qualified_column() ]; |
|
260 | + } else { |
|
261 | + $csv_row[ $field_obj->get_nicename() ] = $attendee_row[ $field_obj->get_qualified_column() ]; |
|
262 | + } |
|
263 | + } |
|
264 | + $csv_data[] = $csv_row; |
|
265 | + } |
|
266 | + |
|
267 | + $filename = $this->generate_filename('contact-list-report'); |
|
268 | + |
|
269 | + $handle = $this->EE_CSV->begin_sending_csv($filename); |
|
270 | + $this->EE_CSV->write_data_array_to_csv($handle, $csv_data); |
|
271 | + $this->EE_CSV->end_sending_csv($handle); |
|
272 | + } |
|
273 | + |
|
274 | + |
|
275 | + /** |
|
276 | + * @Export data for ALL attendees |
|
277 | + * @access public |
|
278 | + * @return void |
|
279 | + * @throws EE_Error |
|
280 | + */ |
|
281 | + public function export_attendees() |
|
282 | + { |
|
283 | + |
|
284 | + $states_that_have_an_attendee = EEM_State::instance()->get_all( |
|
285 | + array(0 => array('Attendee.ATT_ID' => array('IS NOT NULL'))) |
|
286 | + ); |
|
287 | + $countries_that_have_an_attendee = EEM_Country::instance()->get_all( |
|
288 | + array(0 => array('Attendee.ATT_ID' => array('IS NOT NULL'))) |
|
289 | + ); |
|
290 | + // $states_to_export_query_params |
|
291 | + $models_to_export = array( |
|
292 | + 'Country' => array(array('CNT_ISO' => array('IN', array_keys($countries_that_have_an_attendee)))), |
|
293 | + 'State' => array(array('STA_ID' => array('IN', array_keys($states_that_have_an_attendee)))), |
|
294 | + 'Attendee' => array(), |
|
295 | + ); |
|
296 | + |
|
297 | + |
|
298 | + $model_data = $this->_get_export_data_for_models($models_to_export); |
|
299 | + $filename = $this->generate_filename('all-attendees'); |
|
300 | + |
|
301 | + if (! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $model_data)) { |
|
302 | + EE_Error::add_error( |
|
303 | + esc_html__( |
|
304 | + 'An error occurred and the Attendee data could not be exported from the database.', |
|
305 | + 'event_espresso' |
|
306 | + ), |
|
307 | + __FILE__, |
|
308 | + __FUNCTION__, |
|
309 | + __LINE__ |
|
310 | + ); |
|
311 | + } |
|
312 | + } |
|
313 | + |
|
314 | + /** |
|
315 | + * Shortcut for preparing a database result for display |
|
316 | + * |
|
317 | + * @param EEM_Base $model |
|
318 | + * @param string $field_name |
|
319 | + * @param string $raw_db_value |
|
320 | + * @param bool|string $pretty_schema true to display pretty, a string to use a specific "Schema", or false to |
|
321 | + * NOT display pretty |
|
322 | + * @return string |
|
323 | + * @throws EE_Error |
|
324 | + */ |
|
325 | + protected function _prepare_value_from_db_for_display($model, $field_name, $raw_db_value, $pretty_schema = true) |
|
326 | + { |
|
327 | + $field_obj = $model->field_settings_for($field_name); |
|
328 | + $value_on_model_obj = $field_obj->prepare_for_set_from_db($raw_db_value); |
|
329 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
330 | + $field_obj->set_date_format( |
|
331 | + EE_CSV::instance()->get_date_format_for_csv($field_obj->get_date_format($pretty_schema)), |
|
332 | + $pretty_schema |
|
333 | + ); |
|
334 | + $field_obj->set_time_format( |
|
335 | + EE_CSV::instance()->get_time_format_for_csv($field_obj->get_time_format($pretty_schema)), |
|
336 | + $pretty_schema |
|
337 | + ); |
|
338 | + } |
|
339 | + if ($pretty_schema === true) { |
|
340 | + return $field_obj->prepare_for_pretty_echoing($value_on_model_obj); |
|
341 | + } elseif (is_string($pretty_schema)) { |
|
342 | + return $field_obj->prepare_for_pretty_echoing($value_on_model_obj, $pretty_schema); |
|
343 | + } else { |
|
344 | + return $field_obj->prepare_for_get($value_on_model_obj); |
|
345 | + } |
|
346 | + } |
|
347 | + |
|
348 | + /** |
|
349 | + * Export a custom CSV of registration info including: A bunch of the reg fields, the time of the event, the price |
|
350 | + * name, and the questions associated with the registrations |
|
351 | + * |
|
352 | + * @param int $event_id |
|
353 | + * @throws EE_Error |
|
354 | + * @throws ReflectionException |
|
355 | + */ |
|
356 | + public function report_registrations_for_event($event_id = null) |
|
357 | + { |
|
358 | + $reg_fields_to_include = array( |
|
359 | + 'TXN_ID', |
|
360 | + 'ATT_ID', |
|
361 | + 'REG_ID', |
|
362 | + 'REG_date', |
|
363 | + 'REG_code', |
|
364 | + 'REG_count', |
|
365 | + 'REG_final_price', |
|
366 | + |
|
367 | + ); |
|
368 | + $att_fields_to_include = array( |
|
369 | + 'ATT_fname', |
|
370 | + 'ATT_lname', |
|
371 | + 'ATT_email', |
|
372 | + 'ATT_address', |
|
373 | + 'ATT_address2', |
|
374 | + 'ATT_city', |
|
375 | + 'STA_ID', |
|
376 | + 'CNT_ISO', |
|
377 | + 'ATT_zip', |
|
378 | + 'ATT_phone', |
|
379 | + ); |
|
380 | + |
|
381 | + $registrations_csv_ready_array = array(); |
|
382 | + $reg_model = EE_Registry::instance()->load_model('Registration'); |
|
383 | + $query_params = apply_filters( |
|
384 | + 'FHEE__EE_Export__report_registration_for_event', |
|
385 | + array( |
|
386 | + array( |
|
387 | + 'OR' => array( |
|
388 | + // don't include registrations from failed or abandoned transactions... |
|
389 | + 'Transaction.STS_ID' => array( |
|
390 | + 'NOT IN', |
|
391 | + array(EEM_Transaction::failed_status_code, EEM_Transaction::abandoned_status_code), |
|
392 | + ), |
|
393 | + // unless the registration is approved, in which case include it regardless of transaction status |
|
394 | + 'STS_ID' => EEM_Registration::status_id_approved, |
|
395 | + ), |
|
396 | + 'Ticket.TKT_deleted' => array('IN', array(true, false)), |
|
397 | + ), |
|
398 | + 'order_by' => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'), |
|
399 | + 'force_join' => array('Transaction', 'Ticket', 'Attendee'), |
|
400 | + 'caps' => EEM_Base::caps_read_admin, |
|
401 | + ), |
|
402 | + $event_id |
|
403 | + ); |
|
404 | + if ($event_id) { |
|
405 | + $query_params[0]['EVT_ID'] = $event_id; |
|
406 | + } else { |
|
407 | + $query_params['force_join'][] = 'Event'; |
|
408 | + } |
|
409 | + $registration_rows = $reg_model->get_all_wpdb_results($query_params); |
|
410 | + // get all questions which relate to someone in this group |
|
411 | + $registration_ids = array(); |
|
412 | + foreach ($registration_rows as $reg_row) { |
|
413 | + $registration_ids[] = intval($reg_row['Registration.REG_ID']); |
|
414 | + } |
|
415 | + // EEM_Question::instance()->show_next_x_db_queries(); |
|
416 | + $questions_for_these_regs_rows = EEM_Question::instance()->get_all_wpdb_results( |
|
417 | + array(array('Answer.REG_ID' => array('IN', $registration_ids))) |
|
418 | + ); |
|
419 | + foreach ($registration_rows as $reg_row) { |
|
420 | + if (is_array($reg_row)) { |
|
421 | + $reg_csv_array = array(); |
|
422 | + if (! $event_id) { |
|
423 | + // get the event's name and Id |
|
424 | + $reg_csv_array[ esc_html__('Event', 'event_espresso') ] = sprintf( |
|
425 | + esc_html__('%1$s (%2$s)', 'event_espresso'), |
|
426 | + $this->_prepare_value_from_db_for_display( |
|
427 | + EEM_Event::instance(), |
|
428 | + 'EVT_name', |
|
429 | + $reg_row['Event_CPT.post_title'] |
|
430 | + ), |
|
431 | + $reg_row['Event_CPT.ID'] |
|
432 | + ); |
|
433 | + } |
|
434 | + $is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false; |
|
435 | + /*@var $reg_row EE_Registration */ |
|
436 | + foreach ($reg_fields_to_include as $field_name) { |
|
437 | + $field = $reg_model->field_settings_for($field_name); |
|
438 | + if ($field_name == 'REG_final_price') { |
|
439 | + $value = $this->_prepare_value_from_db_for_display( |
|
440 | + $reg_model, |
|
441 | + $field_name, |
|
442 | + $reg_row['Registration.REG_final_price'], |
|
443 | + 'localized_float' |
|
444 | + ); |
|
445 | + } elseif ($field_name == 'REG_count') { |
|
446 | + $value = sprintf( |
|
447 | + esc_html__('%s of %s', 'event_espresso'), |
|
448 | + $this->_prepare_value_from_db_for_display( |
|
449 | + $reg_model, |
|
450 | + 'REG_count', |
|
451 | + $reg_row['Registration.REG_count'] |
|
452 | + ), |
|
453 | + $this->_prepare_value_from_db_for_display( |
|
454 | + $reg_model, |
|
455 | + 'REG_group_size', |
|
456 | + $reg_row['Registration.REG_group_size'] |
|
457 | + ) |
|
458 | + ); |
|
459 | + } elseif ($field_name == 'REG_date') { |
|
460 | + $value = $this->_prepare_value_from_db_for_display( |
|
461 | + $reg_model, |
|
462 | + $field_name, |
|
463 | + $reg_row['Registration.REG_date'], |
|
464 | + 'no_html' |
|
465 | + ); |
|
466 | + } else { |
|
467 | + $value = $this->_prepare_value_from_db_for_display( |
|
468 | + $reg_model, |
|
469 | + $field_name, |
|
470 | + $reg_row[ $field->get_qualified_column() ] |
|
471 | + ); |
|
472 | + } |
|
473 | + $reg_csv_array[ $this->_get_column_name_for_field($field) ] = $value; |
|
474 | + if ($field_name == 'REG_final_price') { |
|
475 | + // add a column named Currency after the final price |
|
476 | + $reg_csv_array[ esc_html__("Currency", "event_espresso") ] = EE_Config::instance()->currency->code; |
|
477 | + } |
|
478 | + } |
|
479 | + // get pretty status |
|
480 | + $stati = EEM_Status::instance()->localized_status( |
|
481 | + array( |
|
482 | + $reg_row['Registration.STS_ID'] => esc_html__('unknown', 'event_espresso'), |
|
483 | + $reg_row['TransactionTable.STS_ID'] => esc_html__('unknown', 'event_espresso'), |
|
484 | + ), |
|
485 | + false, |
|
486 | + 'sentence' |
|
487 | + ); |
|
488 | + $reg_csv_array[ esc_html__( |
|
489 | + "Registration Status", |
|
490 | + 'event_espresso' |
|
491 | + ) ] = $stati[ $reg_row['Registration.STS_ID'] ]; |
|
492 | + // get pretty trnasaction status |
|
493 | + $reg_csv_array[ esc_html__( |
|
494 | + "Transaction Status", |
|
495 | + 'event_espresso' |
|
496 | + ) ] = $stati[ $reg_row['TransactionTable.STS_ID'] ]; |
|
497 | + $reg_csv_array[ esc_html__('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg |
|
498 | + ? $this->_prepare_value_from_db_for_display( |
|
499 | + EEM_Transaction::instance(), |
|
500 | + 'TXN_total', |
|
501 | + $reg_row['TransactionTable.TXN_total'], |
|
502 | + 'localized_float' |
|
503 | + ) : '0.00'; |
|
504 | + $reg_csv_array[ esc_html__('Amount Paid', 'event_espresso') ] = $is_primary_reg |
|
505 | + ? $this->_prepare_value_from_db_for_display( |
|
506 | + EEM_Transaction::instance(), |
|
507 | + 'TXN_paid', |
|
508 | + $reg_row['TransactionTable.TXN_paid'], |
|
509 | + 'localized_float' |
|
510 | + ) : '0.00'; |
|
511 | + $payment_methods = array(); |
|
512 | + $gateway_txn_ids_etc = array(); |
|
513 | + $payment_times = array(); |
|
514 | + if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) { |
|
515 | + $payments_info = EEM_Payment::instance()->get_all_wpdb_results( |
|
516 | + array( |
|
517 | + array( |
|
518 | + 'TXN_ID' => $reg_row['TransactionTable.TXN_ID'], |
|
519 | + 'STS_ID' => EEM_Payment::status_id_approved, |
|
520 | + ), |
|
521 | + 'force_join' => array('Payment_Method'), |
|
522 | + ), |
|
523 | + ARRAY_A, |
|
524 | + 'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time' |
|
525 | + ); |
|
526 | + list($payment_methods, $gateway_txn_ids_etc, $payment_times) = PaymentsInfo::extractPaymentInfo($payments_info); |
|
527 | + } |
|
528 | + $reg_csv_array[ esc_html__('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times); |
|
529 | + $reg_csv_array[ esc_html__('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods); |
|
530 | + $reg_csv_array[ esc_html__('Gateway Transaction ID(s)', 'event_espresso') ] = implode( |
|
531 | + ',', |
|
532 | + $gateway_txn_ids_etc |
|
533 | + ); |
|
534 | + |
|
535 | + // get whether or not the user has checked in |
|
536 | + $reg_csv_array[ esc_html__("Check-Ins", "event_espresso") ] = $reg_model->count_related( |
|
537 | + $reg_row['Registration.REG_ID'], |
|
538 | + 'Checkin' |
|
539 | + ); |
|
540 | + // get ticket of registration and its price |
|
541 | + $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
542 | + if ($reg_row['Ticket.TKT_ID']) { |
|
543 | + $ticket_name = $this->_prepare_value_from_db_for_display( |
|
544 | + $ticket_model, |
|
545 | + 'TKT_name', |
|
546 | + $reg_row['Ticket.TKT_name'] |
|
547 | + ); |
|
548 | + $datetimes_strings = array(); |
|
549 | + foreach ( |
|
550 | + EEM_Datetime::instance()->get_all_wpdb_results( |
|
551 | + array( |
|
552 | + array('Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']), |
|
553 | + 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
554 | + 'default_where_conditions' => 'none', |
|
555 | + ) |
|
556 | + ) as $datetime |
|
557 | + ) { |
|
558 | + $datetimes_strings[] = $this->_prepare_value_from_db_for_display( |
|
559 | + EEM_Datetime::instance(), |
|
560 | + 'DTT_EVT_start', |
|
561 | + $datetime['Datetime.DTT_EVT_start'] |
|
562 | + ); |
|
563 | + } |
|
564 | + } else { |
|
565 | + $ticket_name = esc_html__('Unknown', 'event_espresso'); |
|
566 | + $datetimes_strings = array(esc_html__('Unknown', 'event_espresso')); |
|
567 | + } |
|
568 | + $reg_csv_array[ $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name; |
|
569 | + $reg_csv_array[ esc_html__("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings); |
|
570 | + // get datetime(s) of registration |
|
571 | + |
|
572 | + // add attendee columns |
|
573 | + foreach ($att_fields_to_include as $att_field_name) { |
|
574 | + $field_obj = EEM_Attendee::instance()->field_settings_for($att_field_name); |
|
575 | + if ($reg_row['Attendee_CPT.ID']) { |
|
576 | + if ($att_field_name == 'STA_ID') { |
|
577 | + $value = EEM_State::instance()->get_var( |
|
578 | + array(array('STA_ID' => $reg_row['Attendee_Meta.STA_ID'])), |
|
579 | + 'STA_name' |
|
580 | + ); |
|
581 | + } elseif ($att_field_name == 'CNT_ISO') { |
|
582 | + $value = EEM_Country::instance()->get_var( |
|
583 | + array(array('CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO'])), |
|
584 | + 'CNT_name' |
|
585 | + ); |
|
586 | + } else { |
|
587 | + $value = $this->_prepare_value_from_db_for_display( |
|
588 | + EEM_Attendee::instance(), |
|
589 | + $att_field_name, |
|
590 | + $reg_row[ $field_obj->get_qualified_column() ] |
|
591 | + ); |
|
592 | + } |
|
593 | + } else { |
|
594 | + $value = ''; |
|
595 | + } |
|
596 | + |
|
597 | + $reg_csv_array[ $this->_get_column_name_for_field($field_obj) ] = $value; |
|
598 | + } |
|
599 | + |
|
600 | + // make sure each registration has the same questions in the same order |
|
601 | + foreach ($questions_for_these_regs_rows as $question_row) { |
|
602 | + if (! isset($reg_csv_array[ $question_row['Question.QST_admin_label'] ])) { |
|
603 | + $reg_csv_array[ $question_row['Question.QST_admin_label'] ] = null; |
|
604 | + } |
|
605 | + } |
|
606 | + // now fill out the questions THEY answered |
|
607 | + foreach ( |
|
608 | + EEM_Answer::instance()->get_all_wpdb_results( |
|
609 | + array(array('REG_ID' => $reg_row['Registration.REG_ID']), 'force_join' => array('Question')) |
|
610 | + ) as $answer_row |
|
611 | + ) { |
|
612 | + /* @var $answer EE_Answer */ |
|
613 | + if ($answer_row['Question.QST_ID']) { |
|
614 | + $question_label = $this->_prepare_value_from_db_for_display( |
|
615 | + EEM_Question::instance(), |
|
616 | + 'QST_admin_label', |
|
617 | + $answer_row['Question.QST_admin_label'] |
|
618 | + ); |
|
619 | + } else { |
|
620 | + $question_label = sprintf(esc_html__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']); |
|
621 | + } |
|
622 | + if (isset($answer_row['Question.QST_type']) && $answer_row['Question.QST_type'] == EEM_Question::QST_type_state) { |
|
623 | + $reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID( |
|
624 | + $answer_row['Answer.ANS_value'] |
|
625 | + ); |
|
626 | + } else { |
|
627 | + $reg_csv_array[ $question_label ] = $this->_prepare_value_from_db_for_display( |
|
628 | + EEM_Answer::instance(), |
|
629 | + 'ANS_value', |
|
630 | + $answer_row['Answer.ANS_value'] |
|
631 | + ); |
|
632 | + } |
|
633 | + } |
|
634 | + $registrations_csv_ready_array[] = apply_filters( |
|
635 | + 'FHEE__EE_Export__report_registrations__reg_csv_array', |
|
636 | + $reg_csv_array, |
|
637 | + $reg_row |
|
638 | + ); |
|
639 | + } |
|
640 | + } |
|
641 | + |
|
642 | + // if we couldn't export anything, we want to at least show the column headers |
|
643 | + if (empty($registrations_csv_ready_array)) { |
|
644 | + $reg_csv_array = array(); |
|
645 | + $model_and_fields_to_include = array( |
|
646 | + 'Registration' => $reg_fields_to_include, |
|
647 | + 'Attendee' => $att_fields_to_include, |
|
648 | + ); |
|
649 | + foreach ($model_and_fields_to_include as $model_name => $field_list) { |
|
650 | + $model = EE_Registry::instance()->load_model($model_name); |
|
651 | + foreach ($field_list as $field_name) { |
|
652 | + $field = $model->field_settings_for($field_name); |
|
653 | + $reg_csv_array[ $this->_get_column_name_for_field( |
|
654 | + $field |
|
655 | + ) ] = null;// $registration->get($field->get_name()); |
|
656 | + } |
|
657 | + } |
|
658 | + $registrations_csv_ready_array [] = $reg_csv_array; |
|
659 | + } |
|
660 | + if ($event_id) { |
|
661 | + $event_slug = EEM_Event::instance()->get_var(array(array('EVT_ID' => $event_id)), 'EVT_slug'); |
|
662 | + if (! $event_slug) { |
|
663 | + $event_slug = esc_html__('unknown', 'event_espresso'); |
|
664 | + } |
|
665 | + } else { |
|
666 | + $event_slug = esc_html__('all', 'event_espresso'); |
|
667 | + } |
|
668 | + $filename = sprintf("registrations-for-%s", $event_slug); |
|
669 | + |
|
670 | + $handle = $this->EE_CSV->begin_sending_csv($filename); |
|
671 | + $this->EE_CSV->write_data_array_to_csv($handle, $registrations_csv_ready_array); |
|
672 | + $this->EE_CSV->end_sending_csv($handle); |
|
673 | + } |
|
674 | + |
|
675 | + /** |
|
676 | + * Gets the 'normal' column named for fields |
|
677 | + * |
|
678 | + * @param EE_Model_Field_Base $field |
|
679 | + * @return string |
|
680 | + * @throws EE_Error |
|
681 | + */ |
|
682 | + protected function _get_column_name_for_field(EE_Model_Field_Base $field) |
|
683 | + { |
|
684 | + return $field->get_nicename() . "[" . $field->get_name() . "]"; |
|
685 | + } |
|
686 | + |
|
687 | + |
|
688 | + /** |
|
689 | + * @Export data for ALL events |
|
690 | + * @access public |
|
691 | + * @return void |
|
692 | + */ |
|
693 | + public function export_categories() |
|
694 | + { |
|
695 | + // are any Event IDs set? |
|
696 | + $query_params = array(); |
|
697 | + if (isset($this->_req_data['EVT_CAT_ID'])) { |
|
698 | + // do we have an array of IDs ? |
|
699 | + if (is_array($this->_req_data['EVT_CAT_ID'])) { |
|
700 | + // generate an "IN (CSV)" where clause |
|
701 | + $EVT_CAT_IDs = array_map('sanitize_text_field', $this->_req_data['EVT_CAT_ID']); |
|
702 | + $filename = 'event-categories'; |
|
703 | + $query_params[0]['term_taxonomy_id'] = array('IN', $EVT_CAT_IDs); |
|
704 | + } else { |
|
705 | + // generate regular where = clause |
|
706 | + $EVT_CAT_ID = absint($this->_req_data['EVT_CAT_ID']); |
|
707 | + $filename = 'event-category#' . $EVT_CAT_ID; |
|
708 | + $query_params[0]['term_taxonomy_id'] = $EVT_CAT_ID; |
|
709 | + } |
|
710 | + } else { |
|
711 | + // no IDs means we will d/l the entire table |
|
712 | + $filename = 'all-categories'; |
|
713 | + } |
|
714 | + |
|
715 | + $tables_to_export = array( |
|
716 | + 'Term_Taxonomy' => $query_params, |
|
717 | + ); |
|
718 | + |
|
719 | + $table_data = $this->_get_export_data_for_models($tables_to_export); |
|
720 | + $filename = $this->generate_filename($filename); |
|
721 | + |
|
722 | + if (! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $table_data)) { |
|
723 | + EE_Error::add_error( |
|
724 | + esc_html__( |
|
725 | + 'An error occurred and the Category details could not be exported from the database.', |
|
726 | + 'event_espresso' |
|
727 | + ), |
|
728 | + __FILE__, |
|
729 | + __FUNCTION__, |
|
730 | + __LINE__ |
|
731 | + ); |
|
732 | + } |
|
733 | + } |
|
734 | + |
|
735 | + |
|
736 | + /** |
|
737 | + * @process export name to create a suitable filename |
|
738 | + * @access private |
|
739 | + * @param string - export_name |
|
740 | + * @return string on success, FALSE on fail |
|
741 | + */ |
|
742 | + private function generate_filename($export_name = '') |
|
743 | + { |
|
744 | + if ($export_name != '') { |
|
745 | + $filename = get_bloginfo('name') . '-' . $export_name; |
|
746 | + $filename = sanitize_key($filename) . '-' . $this->today; |
|
747 | + return $filename; |
|
748 | + } else { |
|
749 | + EE_Error::add_error(esc_html__("No filename was provided", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
|
750 | + } |
|
751 | + return false; |
|
752 | + } |
|
753 | + |
|
754 | + |
|
755 | + /** |
|
756 | + * @recursive function for exporting table data and merging the results with the next results |
|
757 | + * @access private |
|
758 | + * @param array $models_to_export keys are model names (eg 'Event', 'Attendee', etc.) and values are arrays of |
|
759 | + * query params @return bool on success, FALSE on fail |
|
760 | + * @throws EE_Error |
|
761 | + * @throws ReflectionException |
|
762 | + * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
763 | + */ |
|
764 | + private function _get_export_data_for_models($models_to_export = array()) |
|
765 | + { |
|
766 | + $table_data = false; |
|
767 | + if (is_array($models_to_export)) { |
|
768 | + foreach ($models_to_export as $model_name => $query_params) { |
|
769 | + // check for a numerically-indexed array. in that case, $model_name is the value!! |
|
770 | + if (is_int($model_name)) { |
|
771 | + $model_name = $query_params; |
|
772 | + $query_params = array(); |
|
773 | + } |
|
774 | + $model = EE_Registry::instance()->load_model($model_name); |
|
775 | + $model_objects = $model->get_all($query_params); |
|
776 | + |
|
777 | + $table_data[ $model_name ] = array(); |
|
778 | + foreach ($model_objects as $model_object) { |
|
779 | + $model_data_array = array(); |
|
780 | + $fields = $model->field_settings(); |
|
781 | + foreach ($fields as $field) { |
|
782 | + $column_name = $field->get_nicename() . "[" . $field->get_name() . "]"; |
|
783 | + if ($field instanceof EE_Datetime_Field) { |
|
784 | + // $field->set_date_format('Y-m-d'); |
|
785 | + // $field->set_time_format('H:i:s'); |
|
786 | + $model_data_array[ $column_name ] = $model_object->get_datetime( |
|
787 | + $field->get_name(), |
|
788 | + 'Y-m-d', |
|
789 | + 'H:i:s' |
|
790 | + ); |
|
791 | + } else { |
|
792 | + $model_data_array[ $column_name ] = $model_object->get($field->get_name()); |
|
793 | + } |
|
794 | + } |
|
795 | + $table_data[ $model_name ][] = $model_data_array; |
|
796 | + } |
|
797 | + } |
|
798 | + } |
|
799 | + return $table_data; |
|
800 | + } |
|
801 | 801 | } |
@@ -46,7 +46,7 @@ discard block |
||
46 | 46 | { |
47 | 47 | $this->_req_data = $request_data; |
48 | 48 | $this->today = date("Y-m-d", time()); |
49 | - require_once(EE_CLASSES . 'EE_CSV.class.php'); |
|
49 | + require_once(EE_CLASSES.'EE_CSV.class.php'); |
|
50 | 50 | $this->EE_CSV = EE_CSV::instance(); |
51 | 51 | } |
52 | 52 | |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | $value_to_equal = $EVT_ID; |
174 | 174 | $event = EE_Registry::instance()->load_model('Event')->get_one_by_ID($EVT_ID); |
175 | 175 | |
176 | - $filename = 'event-' . ($event instanceof EE_Event ? $event->slug() : esc_html__('unknown', 'event_espresso')); |
|
176 | + $filename = 'event-'.($event instanceof EE_Event ? $event->slug() : esc_html__('unknown', 'event_espresso')); |
|
177 | 177 | } |
178 | 178 | $event_query_params[0]['EVT_ID'] = $value_to_equal; |
179 | 179 | $related_models_query_params[0]['Event.EVT_ID'] = $value_to_equal; |
@@ -222,7 +222,7 @@ discard block |
||
222 | 222 | |
223 | 223 | $filename = $this->generate_filename($filename); |
224 | 224 | |
225 | - if (! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $model_data)) { |
|
225 | + if ( ! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $model_data)) { |
|
226 | 226 | EE_Error::add_error( |
227 | 227 | esc_html__( |
228 | 228 | "'An error occurred and the Event details could not be exported from the database.'", |
@@ -249,16 +249,16 @@ discard block |
||
249 | 249 | foreach (EEM_Attendee::instance()->field_settings() as $field_name => $field_obj) { |
250 | 250 | if ($field_name == 'STA_ID') { |
251 | 251 | $state_name_field = EEM_State::instance()->field_settings_for('STA_name'); |
252 | - $csv_row[ esc_html__('State', 'event_espresso') ] = $attendee_row[ $state_name_field->get_qualified_column( |
|
253 | - ) ]; |
|
252 | + $csv_row[esc_html__('State', 'event_espresso')] = $attendee_row[$state_name_field->get_qualified_column( |
|
253 | + )]; |
|
254 | 254 | } elseif ($field_name == 'CNT_ISO') { |
255 | 255 | $country_name_field = EEM_Country::instance()->field_settings_for('CNT_name'); |
256 | - $csv_row[ esc_html__( |
|
256 | + $csv_row[esc_html__( |
|
257 | 257 | 'Country', |
258 | 258 | 'event_espresso' |
259 | - ) ] = $attendee_row[ $country_name_field->get_qualified_column() ]; |
|
259 | + )] = $attendee_row[$country_name_field->get_qualified_column()]; |
|
260 | 260 | } else { |
261 | - $csv_row[ $field_obj->get_nicename() ] = $attendee_row[ $field_obj->get_qualified_column() ]; |
|
261 | + $csv_row[$field_obj->get_nicename()] = $attendee_row[$field_obj->get_qualified_column()]; |
|
262 | 262 | } |
263 | 263 | } |
264 | 264 | $csv_data[] = $csv_row; |
@@ -298,7 +298,7 @@ discard block |
||
298 | 298 | $model_data = $this->_get_export_data_for_models($models_to_export); |
299 | 299 | $filename = $this->generate_filename('all-attendees'); |
300 | 300 | |
301 | - if (! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $model_data)) { |
|
301 | + if ( ! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $model_data)) { |
|
302 | 302 | EE_Error::add_error( |
303 | 303 | esc_html__( |
304 | 304 | 'An error occurred and the Attendee data could not be exported from the database.', |
@@ -419,9 +419,9 @@ discard block |
||
419 | 419 | foreach ($registration_rows as $reg_row) { |
420 | 420 | if (is_array($reg_row)) { |
421 | 421 | $reg_csv_array = array(); |
422 | - if (! $event_id) { |
|
422 | + if ( ! $event_id) { |
|
423 | 423 | // get the event's name and Id |
424 | - $reg_csv_array[ esc_html__('Event', 'event_espresso') ] = sprintf( |
|
424 | + $reg_csv_array[esc_html__('Event', 'event_espresso')] = sprintf( |
|
425 | 425 | esc_html__('%1$s (%2$s)', 'event_espresso'), |
426 | 426 | $this->_prepare_value_from_db_for_display( |
427 | 427 | EEM_Event::instance(), |
@@ -467,13 +467,13 @@ discard block |
||
467 | 467 | $value = $this->_prepare_value_from_db_for_display( |
468 | 468 | $reg_model, |
469 | 469 | $field_name, |
470 | - $reg_row[ $field->get_qualified_column() ] |
|
470 | + $reg_row[$field->get_qualified_column()] |
|
471 | 471 | ); |
472 | 472 | } |
473 | - $reg_csv_array[ $this->_get_column_name_for_field($field) ] = $value; |
|
473 | + $reg_csv_array[$this->_get_column_name_for_field($field)] = $value; |
|
474 | 474 | if ($field_name == 'REG_final_price') { |
475 | 475 | // add a column named Currency after the final price |
476 | - $reg_csv_array[ esc_html__("Currency", "event_espresso") ] = EE_Config::instance()->currency->code; |
|
476 | + $reg_csv_array[esc_html__("Currency", "event_espresso")] = EE_Config::instance()->currency->code; |
|
477 | 477 | } |
478 | 478 | } |
479 | 479 | // get pretty status |
@@ -485,23 +485,23 @@ discard block |
||
485 | 485 | false, |
486 | 486 | 'sentence' |
487 | 487 | ); |
488 | - $reg_csv_array[ esc_html__( |
|
488 | + $reg_csv_array[esc_html__( |
|
489 | 489 | "Registration Status", |
490 | 490 | 'event_espresso' |
491 | - ) ] = $stati[ $reg_row['Registration.STS_ID'] ]; |
|
491 | + )] = $stati[$reg_row['Registration.STS_ID']]; |
|
492 | 492 | // get pretty trnasaction status |
493 | - $reg_csv_array[ esc_html__( |
|
493 | + $reg_csv_array[esc_html__( |
|
494 | 494 | "Transaction Status", |
495 | 495 | 'event_espresso' |
496 | - ) ] = $stati[ $reg_row['TransactionTable.STS_ID'] ]; |
|
497 | - $reg_csv_array[ esc_html__('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg |
|
496 | + )] = $stati[$reg_row['TransactionTable.STS_ID']]; |
|
497 | + $reg_csv_array[esc_html__('Transaction Amount Due', 'event_espresso')] = $is_primary_reg |
|
498 | 498 | ? $this->_prepare_value_from_db_for_display( |
499 | 499 | EEM_Transaction::instance(), |
500 | 500 | 'TXN_total', |
501 | 501 | $reg_row['TransactionTable.TXN_total'], |
502 | 502 | 'localized_float' |
503 | 503 | ) : '0.00'; |
504 | - $reg_csv_array[ esc_html__('Amount Paid', 'event_espresso') ] = $is_primary_reg |
|
504 | + $reg_csv_array[esc_html__('Amount Paid', 'event_espresso')] = $is_primary_reg |
|
505 | 505 | ? $this->_prepare_value_from_db_for_display( |
506 | 506 | EEM_Transaction::instance(), |
507 | 507 | 'TXN_paid', |
@@ -525,15 +525,15 @@ discard block |
||
525 | 525 | ); |
526 | 526 | list($payment_methods, $gateway_txn_ids_etc, $payment_times) = PaymentsInfo::extractPaymentInfo($payments_info); |
527 | 527 | } |
528 | - $reg_csv_array[ esc_html__('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times); |
|
529 | - $reg_csv_array[ esc_html__('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods); |
|
530 | - $reg_csv_array[ esc_html__('Gateway Transaction ID(s)', 'event_espresso') ] = implode( |
|
528 | + $reg_csv_array[esc_html__('Payment Date(s)', 'event_espresso')] = implode(',', $payment_times); |
|
529 | + $reg_csv_array[esc_html__('Payment Method(s)', 'event_espresso')] = implode(",", $payment_methods); |
|
530 | + $reg_csv_array[esc_html__('Gateway Transaction ID(s)', 'event_espresso')] = implode( |
|
531 | 531 | ',', |
532 | 532 | $gateway_txn_ids_etc |
533 | 533 | ); |
534 | 534 | |
535 | 535 | // get whether or not the user has checked in |
536 | - $reg_csv_array[ esc_html__("Check-Ins", "event_espresso") ] = $reg_model->count_related( |
|
536 | + $reg_csv_array[esc_html__("Check-Ins", "event_espresso")] = $reg_model->count_related( |
|
537 | 537 | $reg_row['Registration.REG_ID'], |
538 | 538 | 'Checkin' |
539 | 539 | ); |
@@ -565,8 +565,8 @@ discard block |
||
565 | 565 | $ticket_name = esc_html__('Unknown', 'event_espresso'); |
566 | 566 | $datetimes_strings = array(esc_html__('Unknown', 'event_espresso')); |
567 | 567 | } |
568 | - $reg_csv_array[ $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name; |
|
569 | - $reg_csv_array[ esc_html__("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings); |
|
568 | + $reg_csv_array[$ticket_model->field_settings_for('TKT_name')->get_nicename()] = $ticket_name; |
|
569 | + $reg_csv_array[esc_html__("Datetimes of Ticket", "event_espresso")] = implode(", ", $datetimes_strings); |
|
570 | 570 | // get datetime(s) of registration |
571 | 571 | |
572 | 572 | // add attendee columns |
@@ -587,20 +587,20 @@ discard block |
||
587 | 587 | $value = $this->_prepare_value_from_db_for_display( |
588 | 588 | EEM_Attendee::instance(), |
589 | 589 | $att_field_name, |
590 | - $reg_row[ $field_obj->get_qualified_column() ] |
|
590 | + $reg_row[$field_obj->get_qualified_column()] |
|
591 | 591 | ); |
592 | 592 | } |
593 | 593 | } else { |
594 | 594 | $value = ''; |
595 | 595 | } |
596 | 596 | |
597 | - $reg_csv_array[ $this->_get_column_name_for_field($field_obj) ] = $value; |
|
597 | + $reg_csv_array[$this->_get_column_name_for_field($field_obj)] = $value; |
|
598 | 598 | } |
599 | 599 | |
600 | 600 | // make sure each registration has the same questions in the same order |
601 | 601 | foreach ($questions_for_these_regs_rows as $question_row) { |
602 | - if (! isset($reg_csv_array[ $question_row['Question.QST_admin_label'] ])) { |
|
603 | - $reg_csv_array[ $question_row['Question.QST_admin_label'] ] = null; |
|
602 | + if ( ! isset($reg_csv_array[$question_row['Question.QST_admin_label']])) { |
|
603 | + $reg_csv_array[$question_row['Question.QST_admin_label']] = null; |
|
604 | 604 | } |
605 | 605 | } |
606 | 606 | // now fill out the questions THEY answered |
@@ -620,11 +620,11 @@ discard block |
||
620 | 620 | $question_label = sprintf(esc_html__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']); |
621 | 621 | } |
622 | 622 | if (isset($answer_row['Question.QST_type']) && $answer_row['Question.QST_type'] == EEM_Question::QST_type_state) { |
623 | - $reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID( |
|
623 | + $reg_csv_array[$question_label] = EEM_State::instance()->get_state_name_by_ID( |
|
624 | 624 | $answer_row['Answer.ANS_value'] |
625 | 625 | ); |
626 | 626 | } else { |
627 | - $reg_csv_array[ $question_label ] = $this->_prepare_value_from_db_for_display( |
|
627 | + $reg_csv_array[$question_label] = $this->_prepare_value_from_db_for_display( |
|
628 | 628 | EEM_Answer::instance(), |
629 | 629 | 'ANS_value', |
630 | 630 | $answer_row['Answer.ANS_value'] |
@@ -650,16 +650,16 @@ discard block |
||
650 | 650 | $model = EE_Registry::instance()->load_model($model_name); |
651 | 651 | foreach ($field_list as $field_name) { |
652 | 652 | $field = $model->field_settings_for($field_name); |
653 | - $reg_csv_array[ $this->_get_column_name_for_field( |
|
653 | + $reg_csv_array[$this->_get_column_name_for_field( |
|
654 | 654 | $field |
655 | - ) ] = null;// $registration->get($field->get_name()); |
|
655 | + )] = null; // $registration->get($field->get_name()); |
|
656 | 656 | } |
657 | 657 | } |
658 | 658 | $registrations_csv_ready_array [] = $reg_csv_array; |
659 | 659 | } |
660 | 660 | if ($event_id) { |
661 | 661 | $event_slug = EEM_Event::instance()->get_var(array(array('EVT_ID' => $event_id)), 'EVT_slug'); |
662 | - if (! $event_slug) { |
|
662 | + if ( ! $event_slug) { |
|
663 | 663 | $event_slug = esc_html__('unknown', 'event_espresso'); |
664 | 664 | } |
665 | 665 | } else { |
@@ -681,7 +681,7 @@ discard block |
||
681 | 681 | */ |
682 | 682 | protected function _get_column_name_for_field(EE_Model_Field_Base $field) |
683 | 683 | { |
684 | - return $field->get_nicename() . "[" . $field->get_name() . "]"; |
|
684 | + return $field->get_nicename()."[".$field->get_name()."]"; |
|
685 | 685 | } |
686 | 686 | |
687 | 687 | |
@@ -704,7 +704,7 @@ discard block |
||
704 | 704 | } else { |
705 | 705 | // generate regular where = clause |
706 | 706 | $EVT_CAT_ID = absint($this->_req_data['EVT_CAT_ID']); |
707 | - $filename = 'event-category#' . $EVT_CAT_ID; |
|
707 | + $filename = 'event-category#'.$EVT_CAT_ID; |
|
708 | 708 | $query_params[0]['term_taxonomy_id'] = $EVT_CAT_ID; |
709 | 709 | } |
710 | 710 | } else { |
@@ -719,7 +719,7 @@ discard block |
||
719 | 719 | $table_data = $this->_get_export_data_for_models($tables_to_export); |
720 | 720 | $filename = $this->generate_filename($filename); |
721 | 721 | |
722 | - if (! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $table_data)) { |
|
722 | + if ( ! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $table_data)) { |
|
723 | 723 | EE_Error::add_error( |
724 | 724 | esc_html__( |
725 | 725 | 'An error occurred and the Category details could not be exported from the database.', |
@@ -742,8 +742,8 @@ discard block |
||
742 | 742 | private function generate_filename($export_name = '') |
743 | 743 | { |
744 | 744 | if ($export_name != '') { |
745 | - $filename = get_bloginfo('name') . '-' . $export_name; |
|
746 | - $filename = sanitize_key($filename) . '-' . $this->today; |
|
745 | + $filename = get_bloginfo('name').'-'.$export_name; |
|
746 | + $filename = sanitize_key($filename).'-'.$this->today; |
|
747 | 747 | return $filename; |
748 | 748 | } else { |
749 | 749 | EE_Error::add_error(esc_html__("No filename was provided", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
@@ -774,25 +774,25 @@ discard block |
||
774 | 774 | $model = EE_Registry::instance()->load_model($model_name); |
775 | 775 | $model_objects = $model->get_all($query_params); |
776 | 776 | |
777 | - $table_data[ $model_name ] = array(); |
|
777 | + $table_data[$model_name] = array(); |
|
778 | 778 | foreach ($model_objects as $model_object) { |
779 | 779 | $model_data_array = array(); |
780 | 780 | $fields = $model->field_settings(); |
781 | 781 | foreach ($fields as $field) { |
782 | - $column_name = $field->get_nicename() . "[" . $field->get_name() . "]"; |
|
782 | + $column_name = $field->get_nicename()."[".$field->get_name()."]"; |
|
783 | 783 | if ($field instanceof EE_Datetime_Field) { |
784 | 784 | // $field->set_date_format('Y-m-d'); |
785 | 785 | // $field->set_time_format('H:i:s'); |
786 | - $model_data_array[ $column_name ] = $model_object->get_datetime( |
|
786 | + $model_data_array[$column_name] = $model_object->get_datetime( |
|
787 | 787 | $field->get_name(), |
788 | 788 | 'Y-m-d', |
789 | 789 | 'H:i:s' |
790 | 790 | ); |
791 | 791 | } else { |
792 | - $model_data_array[ $column_name ] = $model_object->get($field->get_name()); |
|
792 | + $model_data_array[$column_name] = $model_object->get($field->get_name()); |
|
793 | 793 | } |
794 | 794 | } |
795 | - $table_data[ $model_name ][] = $model_data_array; |
|
795 | + $table_data[$model_name][] = $model_data_array; |
|
796 | 796 | } |
797 | 797 | } |
798 | 798 | } |