@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
3 | - exit('No direct script access allowed'); |
|
3 | + exit('No direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -16,117 +16,117 @@ discard block |
||
16 | 16 | { |
17 | 17 | |
18 | 18 | |
19 | - /** |
|
20 | - * Constructor. |
|
21 | - * |
|
22 | - * @param EE_Registration[] $data expecting an array of EE_Registration objects. |
|
23 | - * @throws EE_Error |
|
24 | - * @access protected |
|
25 | - */ |
|
26 | - public function __construct($data = array()) |
|
27 | - { |
|
28 | - |
|
29 | - //validate that the first element in the array is an EE_Registration object. |
|
30 | - if (! reset($data) instanceof EE_Registration) { |
|
31 | - throw new EE_Error(__('The EE_Message_Registrations_incoming_data class expects an array of EE_Registration objects.', |
|
32 | - 'event_espresso')); |
|
33 | - } |
|
34 | - parent::__construct($data); |
|
35 | - } |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * setup the data. |
|
40 | - * Sets up the expected data object for the messages prep using incoming registration objects. |
|
41 | - * |
|
42 | - * @return void |
|
43 | - * @access protected |
|
44 | - */ |
|
45 | - protected function _setup_data() |
|
46 | - { |
|
47 | - //we'll loop through each contact and setup the data needed. Note that many properties will just be set as empty |
|
48 | - //because this data handler is for a very specific set of data (i.e. just what's related to the registration). |
|
49 | - |
|
50 | - $this->reg_objs = $this->data(); |
|
51 | - $this->txn = $this->_maybe_get_transaction(); |
|
52 | - $this->_assemble_data(); |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * If the incoming registrations all share the same transaction then this will return the transaction object shared |
|
58 | - * among the registrations. Otherwise the transaction object is set to null because its intended to only represent |
|
59 | - * one transaction. |
|
60 | - * |
|
61 | - * @return EE_Transaction|null |
|
62 | - */ |
|
63 | - protected function _maybe_get_transaction() |
|
64 | - { |
|
65 | - $transactions = array(); |
|
66 | - foreach ($this->reg_objs as $registration) { |
|
67 | - if ($registration instanceof EE_Registration) { |
|
68 | - $transaction = $registration->transaction(); |
|
69 | - if ($transaction instanceof EE_Transaction) { |
|
70 | - $transactions[$transaction->ID()] = $transaction; |
|
71 | - } |
|
72 | - } |
|
73 | - } |
|
74 | - return count($transactions) === 1 ? reset($transactions) : null; |
|
75 | - } |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * Returns database safe representation of the data later used to when instantiating this object. |
|
80 | - * |
|
81 | - * @param array $registrations The incoming data to be prepped. |
|
82 | - * @return EE_Registration[] The data being prepared for the db |
|
83 | - */ |
|
84 | - static public function convert_data_for_persistent_storage($registrations) |
|
85 | - { |
|
86 | - if ( |
|
87 | - ! is_array($registrations) |
|
88 | - || ! reset($registrations) instanceof EE_Registration |
|
89 | - ) { |
|
90 | - return array(); |
|
91 | - } |
|
92 | - |
|
93 | - $registration_ids = array(); |
|
94 | - |
|
95 | - $registration_ids = array_filter( |
|
96 | - array_map( |
|
97 | - function ($registration) { |
|
98 | - if ($registration instanceof EE_Registration) { |
|
99 | - return $registration->ID(); |
|
100 | - } |
|
101 | - return false; |
|
102 | - }, |
|
103 | - $registrations |
|
104 | - ) |
|
105 | - ); |
|
106 | - |
|
107 | - return $registration_ids; |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * Data that has been stored in persistent storage that was prepped by _convert_data_for_persistent_storage |
|
113 | - * can be sent into this method and converted back into the format used for instantiating with this data handler. |
|
114 | - * |
|
115 | - * @param array $data |
|
116 | - * @return EE_Registration[] |
|
117 | - */ |
|
118 | - static public function convert_data_from_persistent_storage($data) |
|
119 | - { |
|
120 | - //since this was added later, we need to account of possible back compat issues where data already queued for generation |
|
121 | - //is in the old format, which is an array of EE_Registration objects. So if that's the case, then let's just return them |
|
122 | - //@see https://events.codebasehq.com/projects/event-espresso/tickets/10127 |
|
123 | - if (is_array($data) && reset($data) instanceof EE_Registration) { |
|
124 | - return $data; |
|
125 | - } |
|
126 | - |
|
127 | - $registrations = is_array($data) |
|
128 | - ? EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $data)))) |
|
129 | - : array(); |
|
130 | - return $registrations; |
|
131 | - } |
|
19 | + /** |
|
20 | + * Constructor. |
|
21 | + * |
|
22 | + * @param EE_Registration[] $data expecting an array of EE_Registration objects. |
|
23 | + * @throws EE_Error |
|
24 | + * @access protected |
|
25 | + */ |
|
26 | + public function __construct($data = array()) |
|
27 | + { |
|
28 | + |
|
29 | + //validate that the first element in the array is an EE_Registration object. |
|
30 | + if (! reset($data) instanceof EE_Registration) { |
|
31 | + throw new EE_Error(__('The EE_Message_Registrations_incoming_data class expects an array of EE_Registration objects.', |
|
32 | + 'event_espresso')); |
|
33 | + } |
|
34 | + parent::__construct($data); |
|
35 | + } |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * setup the data. |
|
40 | + * Sets up the expected data object for the messages prep using incoming registration objects. |
|
41 | + * |
|
42 | + * @return void |
|
43 | + * @access protected |
|
44 | + */ |
|
45 | + protected function _setup_data() |
|
46 | + { |
|
47 | + //we'll loop through each contact and setup the data needed. Note that many properties will just be set as empty |
|
48 | + //because this data handler is for a very specific set of data (i.e. just what's related to the registration). |
|
49 | + |
|
50 | + $this->reg_objs = $this->data(); |
|
51 | + $this->txn = $this->_maybe_get_transaction(); |
|
52 | + $this->_assemble_data(); |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * If the incoming registrations all share the same transaction then this will return the transaction object shared |
|
58 | + * among the registrations. Otherwise the transaction object is set to null because its intended to only represent |
|
59 | + * one transaction. |
|
60 | + * |
|
61 | + * @return EE_Transaction|null |
|
62 | + */ |
|
63 | + protected function _maybe_get_transaction() |
|
64 | + { |
|
65 | + $transactions = array(); |
|
66 | + foreach ($this->reg_objs as $registration) { |
|
67 | + if ($registration instanceof EE_Registration) { |
|
68 | + $transaction = $registration->transaction(); |
|
69 | + if ($transaction instanceof EE_Transaction) { |
|
70 | + $transactions[$transaction->ID()] = $transaction; |
|
71 | + } |
|
72 | + } |
|
73 | + } |
|
74 | + return count($transactions) === 1 ? reset($transactions) : null; |
|
75 | + } |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * Returns database safe representation of the data later used to when instantiating this object. |
|
80 | + * |
|
81 | + * @param array $registrations The incoming data to be prepped. |
|
82 | + * @return EE_Registration[] The data being prepared for the db |
|
83 | + */ |
|
84 | + static public function convert_data_for_persistent_storage($registrations) |
|
85 | + { |
|
86 | + if ( |
|
87 | + ! is_array($registrations) |
|
88 | + || ! reset($registrations) instanceof EE_Registration |
|
89 | + ) { |
|
90 | + return array(); |
|
91 | + } |
|
92 | + |
|
93 | + $registration_ids = array(); |
|
94 | + |
|
95 | + $registration_ids = array_filter( |
|
96 | + array_map( |
|
97 | + function ($registration) { |
|
98 | + if ($registration instanceof EE_Registration) { |
|
99 | + return $registration->ID(); |
|
100 | + } |
|
101 | + return false; |
|
102 | + }, |
|
103 | + $registrations |
|
104 | + ) |
|
105 | + ); |
|
106 | + |
|
107 | + return $registration_ids; |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * Data that has been stored in persistent storage that was prepped by _convert_data_for_persistent_storage |
|
113 | + * can be sent into this method and converted back into the format used for instantiating with this data handler. |
|
114 | + * |
|
115 | + * @param array $data |
|
116 | + * @return EE_Registration[] |
|
117 | + */ |
|
118 | + static public function convert_data_from_persistent_storage($data) |
|
119 | + { |
|
120 | + //since this was added later, we need to account of possible back compat issues where data already queued for generation |
|
121 | + //is in the old format, which is an array of EE_Registration objects. So if that's the case, then let's just return them |
|
122 | + //@see https://events.codebasehq.com/projects/event-espresso/tickets/10127 |
|
123 | + if (is_array($data) && reset($data) instanceof EE_Registration) { |
|
124 | + return $data; |
|
125 | + } |
|
126 | + |
|
127 | + $registrations = is_array($data) |
|
128 | + ? EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $data)))) |
|
129 | + : array(); |
|
130 | + return $registrations; |
|
131 | + } |
|
132 | 132 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | 3 | exit('No direct script access allowed'); |
4 | 4 | } |
5 | 5 | |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | { |
28 | 28 | |
29 | 29 | //validate that the first element in the array is an EE_Registration object. |
30 | - if (! reset($data) instanceof EE_Registration) { |
|
30 | + if ( ! reset($data) instanceof EE_Registration) { |
|
31 | 31 | throw new EE_Error(__('The EE_Message_Registrations_incoming_data class expects an array of EE_Registration objects.', |
32 | 32 | 'event_espresso')); |
33 | 33 | } |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | |
95 | 95 | $registration_ids = array_filter( |
96 | 96 | array_map( |
97 | - function ($registration) { |
|
97 | + function($registration) { |
|
98 | 98 | if ($registration instanceof EE_Registration) { |
99 | 99 | return $registration->ID(); |
100 | 100 | } |