@@ -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,256 +16,256 @@ discard block |
||
16 | 16 | { |
17 | 17 | |
18 | 18 | |
19 | - /** |
|
20 | - * EE_Message_Repository constructor |
|
21 | - */ |
|
22 | - public function __construct() |
|
23 | - { |
|
24 | - $this->interface = 'EE_Message'; |
|
25 | - parent::__construct(); |
|
26 | - } |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * Add the EE_Message to the repository. |
|
31 | - * This also ensures that the MSG_token is saves as a part of the info for retrieval. |
|
32 | - * |
|
33 | - * @param EE_Message $message |
|
34 | - * @param mixed $info Any included data is saved in the attached object info array indexed by 'data' |
|
35 | - * @return bool |
|
36 | - */ |
|
37 | - public function add($message, $info = null) |
|
38 | - { |
|
39 | - $attached = parent::add($message); |
|
40 | - //ensure $info is an array if not already |
|
41 | - $info = $info === null ? $info = array() : (array)$info; |
|
42 | - $data = $this->_init_data($info, $attached, $message); |
|
43 | - if ($attached) { |
|
44 | - $this->set_info($message, $data); |
|
45 | - } |
|
46 | - return $attached; |
|
47 | - } |
|
48 | - |
|
49 | - |
|
50 | - /** |
|
51 | - * Initializes the data from the incoming info. |
|
52 | - * |
|
53 | - * @param array $info incoming data. |
|
54 | - * @param bool $attached Indicates whether the object was attached successfully. |
|
55 | - * @param EE_Message $message |
|
56 | - * @return array |
|
57 | - */ |
|
58 | - protected function _init_data($info, $attached, $message) |
|
59 | - { |
|
60 | - $data = array( |
|
61 | - 'test_send' => false, |
|
62 | - 'preview' => false, |
|
63 | - 'data_handler_class_name' => '', |
|
64 | - 'data' => array( |
|
65 | - 'MSG_generation_data' => array(), |
|
66 | - ), |
|
67 | - ); |
|
68 | - if (isset($info['preview'])) { |
|
69 | - $data['preview'] = $info['preview']; |
|
70 | - unset($info['preview']); |
|
71 | - } |
|
72 | - if (isset($info['test_send'])) { |
|
73 | - $data['test_send'] = $info['test_send']; |
|
74 | - unset($info['test_send']); |
|
75 | - } |
|
76 | - if (isset($info['data_handler_class_name'])) { |
|
77 | - $data['data_handler_class_name'] = $info['data_handler_class_name']; |
|
78 | - unset($info['data_handler_class_name']); |
|
79 | - } |
|
80 | - if ($attached && $message->STS_ID() === EEM_Message::status_incomplete) { |
|
81 | - $generation_data = isset($info['MSG_generation_data']) ? $info['MSG_generation_data'] : array(); |
|
82 | - //if data isn't in $info...let's see if its available via the message object |
|
83 | - $generation_data = ! $generation_data ? $message->get_generation_data() : $generation_data; |
|
84 | - //still empty then let's just use info |
|
85 | - $generation_data = ! $generation_data ? $info : $generation_data; |
|
86 | - $data['data']['MSG_generation_data'] = $generation_data; |
|
87 | - } |
|
88 | - return $data; |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * Save all EE_Message objects to the db. |
|
94 | - * |
|
95 | - * @param bool $do_hooks_only When true, only the hooks related to saving are fired. |
|
96 | - * @return array array( |
|
97 | - * 'updated' => 0, //count of how many messages updated |
|
98 | - * 'notupdated' => 0, //count of how many messages not updated. |
|
99 | - * 'errors' => array( $token ), //array of message object tokens that had errors in saving |
|
100 | - * ) |
|
101 | - */ |
|
102 | - public function saveAll($do_hooks_only = false) |
|
103 | - { |
|
104 | - $save_tracking = array('updated' => 0, 'notupdated' => 0, 'errors' => array()); |
|
105 | - |
|
106 | - if (! $do_hooks_only) { |
|
107 | - $this->rewind(); |
|
108 | - //exit early if there is nothing to save. |
|
109 | - if ($this->count() < 1) { |
|
110 | - return $save_tracking; |
|
111 | - } |
|
112 | - |
|
113 | - while ($this->valid()) { |
|
114 | - $saved = $this->current()->save(); |
|
115 | - if ($saved === false) { |
|
116 | - $save_tracking['errors'][] = $this->current()->MSG_token(); |
|
117 | - } elseif ($saved) { |
|
118 | - $save_tracking['updated']++; |
|
119 | - } else { |
|
120 | - $save_tracking['notupdated']++; |
|
121 | - } |
|
122 | - //maybe persist generation data if this is an incomplete EE_Message. |
|
123 | - $this->_maybe_persist_attached_data(); |
|
124 | - |
|
125 | - $this->next(); |
|
126 | - } |
|
127 | - } |
|
128 | - do_action('AHEE__EE_Message_Repository__saveAll__after', $save_tracking, $this, $do_hooks_only); |
|
129 | - return $save_tracking; |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * Retrieves a EE_Message from the repository that matches the given token. |
|
135 | - * |
|
136 | - * @param string $token Token. |
|
137 | - * @return EE_Message | null |
|
138 | - */ |
|
139 | - public function getMessageByToken($token) |
|
140 | - { |
|
141 | - $this->rewind(); |
|
142 | - while ($this->valid()) { |
|
143 | - if ($this->current()->MSG_token() === $token) { |
|
144 | - $message = $this->current(); |
|
145 | - $this->rewind(); |
|
146 | - return $message; |
|
147 | - } |
|
148 | - $this->next(); |
|
149 | - } |
|
150 | - return null; |
|
151 | - } |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * This retrieves any data required for generation that may be saved with the current EE_Message in storage. |
|
156 | - * |
|
157 | - * @return array(); |
|
158 | - */ |
|
159 | - public function get_generation_data() |
|
160 | - { |
|
161 | - //first verify we're at a valid iterator point. |
|
162 | - if ( ! $this->valid()) { |
|
163 | - return array(); |
|
164 | - } |
|
165 | - $info = $this->getInfo(); |
|
166 | - return isset($info['data']) && isset($info['data']['MSG_generation_data']) ? $info['data']['MSG_generation_data'] : array(); |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * Retrieves the data_handler_class_name or reference associated with the current EE_Message object in the iterator. |
|
172 | - * |
|
173 | - * @return string |
|
174 | - */ |
|
175 | - public function get_data_handler() |
|
176 | - { |
|
177 | - if ( ! $this->valid()) { |
|
178 | - return ''; |
|
179 | - } |
|
180 | - $info = $this->getInfo(); |
|
181 | - return isset($info['data_handler_class_name']) ? $info['data_handler_class_name'] : ''; |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * Returns whether this EE_Message is for a preview or not. |
|
187 | - * |
|
188 | - * @return bool |
|
189 | - */ |
|
190 | - public function is_preview() |
|
191 | - { |
|
192 | - if ( ! $this->valid()) { |
|
193 | - return false; |
|
194 | - } |
|
195 | - $info = $this->getInfo(); |
|
196 | - return $info['preview']; |
|
197 | - } |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * Returns whether the current message pointed to is for a test send. |
|
202 | - * |
|
203 | - * @return bool |
|
204 | - */ |
|
205 | - public function is_test_send() |
|
206 | - { |
|
207 | - if ( ! $this->valid()) { |
|
208 | - return false; |
|
209 | - } |
|
210 | - $info = $this->getInfo(); |
|
211 | - return $info['test_send']; |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - /** |
|
216 | - * This checks if the current EE_Message in the iterator is incomplete. If it is, then |
|
217 | - * data is attached for later retrieval (batch generation). |
|
218 | - */ |
|
219 | - protected function _maybe_persist_attached_data() |
|
220 | - { |
|
221 | - if ( ! $this->valid()) { |
|
222 | - return; |
|
223 | - } |
|
224 | - |
|
225 | - $info = $this->getInfo(); |
|
226 | - $data_handler_class_name = isset($info['data_handler_class_name']) ? $info['data_handler_class_name'] : ''; |
|
227 | - $data = isset($info['data']) && isset($info['data']['MSG_generation_data']) ? $info['data']['MSG_generation_data'] : array(); |
|
228 | - if ($data && $this->current()->STS_ID() === EEM_Message::status_incomplete) { |
|
229 | - $this->current()->set_generation_data($data); |
|
230 | - $this->current()->set_field_or_extra_meta('data_handler_class_name', $data_handler_class_name); |
|
231 | - } |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - /** |
|
236 | - * This method returns a count of messages in the repository that have a given priority. |
|
237 | - * |
|
238 | - * @param int $priority the priority that is being filtered for the count. |
|
239 | - * @param array $status the optional status(es) that will also be filtered by when priority matches. |
|
240 | - * @return int count of messages in the queue matching the conditions. |
|
241 | - */ |
|
242 | - public function count_by_priority_and_status($priority, $status = array()) |
|
243 | - { |
|
244 | - if ( ! empty($status)) { |
|
245 | - $status = is_array($status) ? $status : array($status); |
|
246 | - } |
|
247 | - |
|
248 | - $count = 0; |
|
249 | - $this->rewind(); |
|
250 | - while ($this->valid()) { |
|
251 | - if ($this->current()->priority() === $priority && (($status && in_array($this->current()->STS_ID(), |
|
252 | - $status)) || ! $status) |
|
253 | - ) { |
|
254 | - $count++; |
|
255 | - } |
|
256 | - $this->next(); |
|
257 | - } |
|
258 | - return $count; |
|
259 | - } |
|
260 | - |
|
261 | - |
|
262 | - /** |
|
263 | - * @return EE_Message |
|
264 | - */ |
|
265 | - public function current() |
|
266 | - { |
|
267 | - return parent::current(); |
|
268 | - } |
|
19 | + /** |
|
20 | + * EE_Message_Repository constructor |
|
21 | + */ |
|
22 | + public function __construct() |
|
23 | + { |
|
24 | + $this->interface = 'EE_Message'; |
|
25 | + parent::__construct(); |
|
26 | + } |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * Add the EE_Message to the repository. |
|
31 | + * This also ensures that the MSG_token is saves as a part of the info for retrieval. |
|
32 | + * |
|
33 | + * @param EE_Message $message |
|
34 | + * @param mixed $info Any included data is saved in the attached object info array indexed by 'data' |
|
35 | + * @return bool |
|
36 | + */ |
|
37 | + public function add($message, $info = null) |
|
38 | + { |
|
39 | + $attached = parent::add($message); |
|
40 | + //ensure $info is an array if not already |
|
41 | + $info = $info === null ? $info = array() : (array)$info; |
|
42 | + $data = $this->_init_data($info, $attached, $message); |
|
43 | + if ($attached) { |
|
44 | + $this->set_info($message, $data); |
|
45 | + } |
|
46 | + return $attached; |
|
47 | + } |
|
48 | + |
|
49 | + |
|
50 | + /** |
|
51 | + * Initializes the data from the incoming info. |
|
52 | + * |
|
53 | + * @param array $info incoming data. |
|
54 | + * @param bool $attached Indicates whether the object was attached successfully. |
|
55 | + * @param EE_Message $message |
|
56 | + * @return array |
|
57 | + */ |
|
58 | + protected function _init_data($info, $attached, $message) |
|
59 | + { |
|
60 | + $data = array( |
|
61 | + 'test_send' => false, |
|
62 | + 'preview' => false, |
|
63 | + 'data_handler_class_name' => '', |
|
64 | + 'data' => array( |
|
65 | + 'MSG_generation_data' => array(), |
|
66 | + ), |
|
67 | + ); |
|
68 | + if (isset($info['preview'])) { |
|
69 | + $data['preview'] = $info['preview']; |
|
70 | + unset($info['preview']); |
|
71 | + } |
|
72 | + if (isset($info['test_send'])) { |
|
73 | + $data['test_send'] = $info['test_send']; |
|
74 | + unset($info['test_send']); |
|
75 | + } |
|
76 | + if (isset($info['data_handler_class_name'])) { |
|
77 | + $data['data_handler_class_name'] = $info['data_handler_class_name']; |
|
78 | + unset($info['data_handler_class_name']); |
|
79 | + } |
|
80 | + if ($attached && $message->STS_ID() === EEM_Message::status_incomplete) { |
|
81 | + $generation_data = isset($info['MSG_generation_data']) ? $info['MSG_generation_data'] : array(); |
|
82 | + //if data isn't in $info...let's see if its available via the message object |
|
83 | + $generation_data = ! $generation_data ? $message->get_generation_data() : $generation_data; |
|
84 | + //still empty then let's just use info |
|
85 | + $generation_data = ! $generation_data ? $info : $generation_data; |
|
86 | + $data['data']['MSG_generation_data'] = $generation_data; |
|
87 | + } |
|
88 | + return $data; |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * Save all EE_Message objects to the db. |
|
94 | + * |
|
95 | + * @param bool $do_hooks_only When true, only the hooks related to saving are fired. |
|
96 | + * @return array array( |
|
97 | + * 'updated' => 0, //count of how many messages updated |
|
98 | + * 'notupdated' => 0, //count of how many messages not updated. |
|
99 | + * 'errors' => array( $token ), //array of message object tokens that had errors in saving |
|
100 | + * ) |
|
101 | + */ |
|
102 | + public function saveAll($do_hooks_only = false) |
|
103 | + { |
|
104 | + $save_tracking = array('updated' => 0, 'notupdated' => 0, 'errors' => array()); |
|
105 | + |
|
106 | + if (! $do_hooks_only) { |
|
107 | + $this->rewind(); |
|
108 | + //exit early if there is nothing to save. |
|
109 | + if ($this->count() < 1) { |
|
110 | + return $save_tracking; |
|
111 | + } |
|
112 | + |
|
113 | + while ($this->valid()) { |
|
114 | + $saved = $this->current()->save(); |
|
115 | + if ($saved === false) { |
|
116 | + $save_tracking['errors'][] = $this->current()->MSG_token(); |
|
117 | + } elseif ($saved) { |
|
118 | + $save_tracking['updated']++; |
|
119 | + } else { |
|
120 | + $save_tracking['notupdated']++; |
|
121 | + } |
|
122 | + //maybe persist generation data if this is an incomplete EE_Message. |
|
123 | + $this->_maybe_persist_attached_data(); |
|
124 | + |
|
125 | + $this->next(); |
|
126 | + } |
|
127 | + } |
|
128 | + do_action('AHEE__EE_Message_Repository__saveAll__after', $save_tracking, $this, $do_hooks_only); |
|
129 | + return $save_tracking; |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * Retrieves a EE_Message from the repository that matches the given token. |
|
135 | + * |
|
136 | + * @param string $token Token. |
|
137 | + * @return EE_Message | null |
|
138 | + */ |
|
139 | + public function getMessageByToken($token) |
|
140 | + { |
|
141 | + $this->rewind(); |
|
142 | + while ($this->valid()) { |
|
143 | + if ($this->current()->MSG_token() === $token) { |
|
144 | + $message = $this->current(); |
|
145 | + $this->rewind(); |
|
146 | + return $message; |
|
147 | + } |
|
148 | + $this->next(); |
|
149 | + } |
|
150 | + return null; |
|
151 | + } |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * This retrieves any data required for generation that may be saved with the current EE_Message in storage. |
|
156 | + * |
|
157 | + * @return array(); |
|
158 | + */ |
|
159 | + public function get_generation_data() |
|
160 | + { |
|
161 | + //first verify we're at a valid iterator point. |
|
162 | + if ( ! $this->valid()) { |
|
163 | + return array(); |
|
164 | + } |
|
165 | + $info = $this->getInfo(); |
|
166 | + return isset($info['data']) && isset($info['data']['MSG_generation_data']) ? $info['data']['MSG_generation_data'] : array(); |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * Retrieves the data_handler_class_name or reference associated with the current EE_Message object in the iterator. |
|
172 | + * |
|
173 | + * @return string |
|
174 | + */ |
|
175 | + public function get_data_handler() |
|
176 | + { |
|
177 | + if ( ! $this->valid()) { |
|
178 | + return ''; |
|
179 | + } |
|
180 | + $info = $this->getInfo(); |
|
181 | + return isset($info['data_handler_class_name']) ? $info['data_handler_class_name'] : ''; |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * Returns whether this EE_Message is for a preview or not. |
|
187 | + * |
|
188 | + * @return bool |
|
189 | + */ |
|
190 | + public function is_preview() |
|
191 | + { |
|
192 | + if ( ! $this->valid()) { |
|
193 | + return false; |
|
194 | + } |
|
195 | + $info = $this->getInfo(); |
|
196 | + return $info['preview']; |
|
197 | + } |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * Returns whether the current message pointed to is for a test send. |
|
202 | + * |
|
203 | + * @return bool |
|
204 | + */ |
|
205 | + public function is_test_send() |
|
206 | + { |
|
207 | + if ( ! $this->valid()) { |
|
208 | + return false; |
|
209 | + } |
|
210 | + $info = $this->getInfo(); |
|
211 | + return $info['test_send']; |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + /** |
|
216 | + * This checks if the current EE_Message in the iterator is incomplete. If it is, then |
|
217 | + * data is attached for later retrieval (batch generation). |
|
218 | + */ |
|
219 | + protected function _maybe_persist_attached_data() |
|
220 | + { |
|
221 | + if ( ! $this->valid()) { |
|
222 | + return; |
|
223 | + } |
|
224 | + |
|
225 | + $info = $this->getInfo(); |
|
226 | + $data_handler_class_name = isset($info['data_handler_class_name']) ? $info['data_handler_class_name'] : ''; |
|
227 | + $data = isset($info['data']) && isset($info['data']['MSG_generation_data']) ? $info['data']['MSG_generation_data'] : array(); |
|
228 | + if ($data && $this->current()->STS_ID() === EEM_Message::status_incomplete) { |
|
229 | + $this->current()->set_generation_data($data); |
|
230 | + $this->current()->set_field_or_extra_meta('data_handler_class_name', $data_handler_class_name); |
|
231 | + } |
|
232 | + } |
|
233 | + |
|
234 | + |
|
235 | + /** |
|
236 | + * This method returns a count of messages in the repository that have a given priority. |
|
237 | + * |
|
238 | + * @param int $priority the priority that is being filtered for the count. |
|
239 | + * @param array $status the optional status(es) that will also be filtered by when priority matches. |
|
240 | + * @return int count of messages in the queue matching the conditions. |
|
241 | + */ |
|
242 | + public function count_by_priority_and_status($priority, $status = array()) |
|
243 | + { |
|
244 | + if ( ! empty($status)) { |
|
245 | + $status = is_array($status) ? $status : array($status); |
|
246 | + } |
|
247 | + |
|
248 | + $count = 0; |
|
249 | + $this->rewind(); |
|
250 | + while ($this->valid()) { |
|
251 | + if ($this->current()->priority() === $priority && (($status && in_array($this->current()->STS_ID(), |
|
252 | + $status)) || ! $status) |
|
253 | + ) { |
|
254 | + $count++; |
|
255 | + } |
|
256 | + $this->next(); |
|
257 | + } |
|
258 | + return $count; |
|
259 | + } |
|
260 | + |
|
261 | + |
|
262 | + /** |
|
263 | + * @return EE_Message |
|
264 | + */ |
|
265 | + public function current() |
|
266 | + { |
|
267 | + return parent::current(); |
|
268 | + } |
|
269 | 269 | |
270 | 270 | |
271 | 271 | } |
272 | 272 | \ No newline at end of file |
@@ -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 | |
@@ -38,7 +38,7 @@ discard block |
||
38 | 38 | { |
39 | 39 | $attached = parent::add($message); |
40 | 40 | //ensure $info is an array if not already |
41 | - $info = $info === null ? $info = array() : (array)$info; |
|
41 | + $info = $info === null ? $info = array() : (array) $info; |
|
42 | 42 | $data = $this->_init_data($info, $attached, $message); |
43 | 43 | if ($attached) { |
44 | 44 | $this->set_info($message, $data); |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | { |
104 | 104 | $save_tracking = array('updated' => 0, 'notupdated' => 0, 'errors' => array()); |
105 | 105 | |
106 | - if (! $do_hooks_only) { |
|
106 | + if ( ! $do_hooks_only) { |
|
107 | 107 | $this->rewind(); |
108 | 108 | //exit early if there is nothing to save. |
109 | 109 | if ($this->count() < 1) { |
@@ -1,7 +1,7 @@ discard block |
||
1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | 2 | exit('No direct script access allowed'); |
3 | 3 | } |
4 | -require_once(EE_MODELS . 'EEM_CPT_Base.model.php'); |
|
4 | +require_once(EE_MODELS.'EEM_CPT_Base.model.php'); |
|
5 | 5 | |
6 | 6 | |
7 | 7 | |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | public static function instance($timezone = null) |
60 | 60 | { |
61 | 61 | // check if instance of EEM_Event already exists |
62 | - if (! self::$_instance instanceof EEM_Event) { |
|
62 | + if ( ! self::$_instance instanceof EEM_Event) { |
|
63 | 63 | // instantiate Espresso_model |
64 | 64 | self::$_instance = new self($timezone); |
65 | 65 | } |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | */ |
250 | 250 | public function get_all_event_question_groups($EVT_ID = 0) |
251 | 251 | { |
252 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
252 | + if ( ! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
253 | 253 | EE_Error::add_error( |
254 | 254 | esc_html__( |
255 | 255 | 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | */ |
279 | 279 | public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true) |
280 | 280 | { |
281 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
281 | + if ( ! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
282 | 282 | EE_Error::add_error( |
283 | 283 | esc_html__( |
284 | 284 | 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
@@ -310,7 +310,7 @@ discard block |
||
310 | 310 | */ |
311 | 311 | public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration) |
312 | 312 | { |
313 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
313 | + if ( ! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
314 | 314 | EE_Error::add_error( |
315 | 315 | esc_html__( |
316 | 316 | 'An error occurred. No Question Groups could be retrieved because an Event ID was not received.', |
@@ -714,7 +714,7 @@ discard block |
||
714 | 714 | $questions = array(); |
715 | 715 | // get all question groups for event |
716 | 716 | $qgs = $this->get_question_groups_for_event($EVT_ID, $registration); |
717 | - if (! empty($qgs)) { |
|
717 | + if ( ! empty($qgs)) { |
|
718 | 718 | foreach ($qgs as $qg) { |
719 | 719 | $qsts = $qg->questions(); |
720 | 720 | $questions[$qg->ID()] = $qg->model_field_array(); |
@@ -732,7 +732,7 @@ discard block |
||
732 | 732 | $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object(); |
733 | 733 | $qst_name = $qstn_id = $qst->ID(); |
734 | 734 | $ans_id = $answer->ID(); |
735 | - $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']'; |
|
735 | + $qst_name = ! empty($ans_id) ? '['.$qst_name.']['.$ans_id.']' : '['.$qst_name.']'; |
|
736 | 736 | $input_name = ''; |
737 | 737 | $input_id = sanitize_key($qst->display_text()); |
738 | 738 | $input_class = ''; |
@@ -740,7 +740,7 @@ discard block |
||
740 | 740 | $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn' |
741 | 741 | . $input_name |
742 | 742 | . $qst_name; |
743 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id . '-' . $qstn_id; |
|
743 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id.'-'.$qstn_id; |
|
744 | 744 | $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class; |
745 | 745 | $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'] = array(); |
746 | 746 | $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj'] = $qst; |
@@ -217,7 +217,7 @@ |
||
217 | 217 | |
218 | 218 | /** |
219 | 219 | * Used to override the default for the additional limit field. |
220 | - * @param $additional_limit |
|
220 | + * @param integer $additional_limit |
|
221 | 221 | */ |
222 | 222 | public static function set_default_additional_limit($additional_limit) |
223 | 223 | { |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | require_once(EE_MODELS . 'EEM_CPT_Base.model.php'); |
5 | 5 | |
@@ -16,793 +16,793 @@ discard block |
||
16 | 16 | class EEM_Event extends EEM_CPT_Base |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the |
|
21 | - * event |
|
22 | - */ |
|
23 | - const sold_out = 'sold_out'; |
|
24 | - |
|
25 | - /** |
|
26 | - * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later |
|
27 | - * date) |
|
28 | - */ |
|
29 | - const postponed = 'postponed'; |
|
30 | - |
|
31 | - /** |
|
32 | - * constant used by status(), indicating that the event will no longer occur |
|
33 | - */ |
|
34 | - const cancelled = 'cancelled'; |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * @var string |
|
39 | - */ |
|
40 | - protected static $_default_reg_status; |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * This is the default for the additional limit field. |
|
45 | - * @var int |
|
46 | - */ |
|
47 | - protected static $_default_additional_limit = 10; |
|
48 | - |
|
49 | - |
|
50 | - /** |
|
51 | - * private instance of the Event object |
|
52 | - * |
|
53 | - * @var EEM_Event |
|
54 | - */ |
|
55 | - protected static $_instance; |
|
56 | - |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * This function is a singleton method used to instantiate the EEM_Event object |
|
61 | - * |
|
62 | - * @param string $timezone |
|
63 | - * @return EEM_Event |
|
64 | - * @throws \EE_Error |
|
65 | - */ |
|
66 | - public static function instance($timezone = null) |
|
67 | - { |
|
68 | - // check if instance of EEM_Event already exists |
|
69 | - if (! self::$_instance instanceof EEM_Event) { |
|
70 | - // instantiate Espresso_model |
|
71 | - self::$_instance = new self($timezone); |
|
72 | - } |
|
73 | - //we might have a timezone set, let set_timezone decide what to do with it |
|
74 | - self::$_instance->set_timezone($timezone); |
|
75 | - // EEM_Event object |
|
76 | - return self::$_instance; |
|
77 | - } |
|
78 | - |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * Adds a relationship to Term_Taxonomy for each CPT_Base |
|
83 | - * |
|
84 | - * @param string $timezone |
|
85 | - * @throws \EE_Error |
|
86 | - */ |
|
87 | - protected function __construct($timezone = null) |
|
88 | - { |
|
89 | - EE_Registry::instance()->load_model('Registration'); |
|
90 | - $this->singular_item = esc_html__('Event', 'event_espresso'); |
|
91 | - $this->plural_item = esc_html__('Events', 'event_espresso'); |
|
92 | - // to remove Cancelled events from the frontend, copy the following filter to your functions.php file |
|
93 | - // add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' ); |
|
94 | - // to remove Postponed events from the frontend, copy the following filter to your functions.php file |
|
95 | - // add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' ); |
|
96 | - // to remove Sold Out events from the frontend, copy the following filter to your functions.php file |
|
97 | - // add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' ); |
|
98 | - $this->_custom_stati = apply_filters( |
|
99 | - 'AFEE__EEM_Event__construct___custom_stati', |
|
100 | - array( |
|
101 | - EEM_Event::cancelled => array( |
|
102 | - 'label' => esc_html__('Cancelled', 'event_espresso'), |
|
103 | - 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true), |
|
104 | - ), |
|
105 | - EEM_Event::postponed => array( |
|
106 | - 'label' => esc_html__('Postponed', 'event_espresso'), |
|
107 | - 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true), |
|
108 | - ), |
|
109 | - EEM_Event::sold_out => array( |
|
110 | - 'label' => esc_html__('Sold Out', 'event_espresso'), |
|
111 | - 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true), |
|
112 | - ), |
|
113 | - ) |
|
114 | - ); |
|
115 | - self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment |
|
116 | - : self::$_default_reg_status; |
|
117 | - $this->_tables = array( |
|
118 | - 'Event_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
119 | - 'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'), |
|
120 | - ); |
|
121 | - $this->_fields = array( |
|
122 | - 'Event_CPT' => array( |
|
123 | - 'EVT_ID' => new EE_Primary_Key_Int_Field('ID', |
|
124 | - esc_html__('Post ID for Event', 'event_espresso')), |
|
125 | - 'EVT_name' => new EE_Plain_Text_Field('post_title', esc_html__('Event Name', 'event_espresso'), |
|
126 | - false, |
|
127 | - ''), |
|
128 | - 'EVT_desc' => new EE_Post_Content_Field('post_content', |
|
129 | - esc_html__('Event Description', 'event_espresso'), |
|
130 | - false, ''), |
|
131 | - 'EVT_slug' => new EE_Slug_Field('post_name', esc_html__('Event Slug', 'event_espresso'), false, |
|
132 | - ''), |
|
133 | - 'EVT_created' => new EE_Datetime_Field('post_date', |
|
134 | - esc_html__('Date/Time Event Created', 'event_espresso'), |
|
135 | - false, EE_Datetime_Field::now), |
|
136 | - 'EVT_short_desc' => new EE_Simple_HTML_Field('post_excerpt', |
|
137 | - esc_html__('Event Short Description', 'event_espresso'), false, ''), |
|
138 | - 'EVT_modified' => new EE_Datetime_Field('post_modified', |
|
139 | - esc_html__('Date/Time Event Modified', 'event_espresso'), false, EE_Datetime_Field::now), |
|
140 | - 'EVT_wp_user' => new EE_WP_User_Field('post_author', |
|
141 | - esc_html__('Event Creator ID', 'event_espresso'), |
|
142 | - false), |
|
143 | - 'parent' => new EE_Integer_Field('post_parent', esc_html__('Event Parent ID', 'event_espresso'), |
|
144 | - false, |
|
145 | - 0), |
|
146 | - 'EVT_order' => new EE_Integer_Field('menu_order', esc_html__('Event Menu Order', 'event_espresso'), |
|
147 | - false, |
|
148 | - 1), |
|
149 | - 'post_type' => new EE_WP_Post_Type_Field('espresso_events'), |
|
150 | - // EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ), |
|
151 | - 'status' => new EE_WP_Post_Status_Field('post_status', |
|
152 | - esc_html__('Event Status', 'event_espresso'), |
|
153 | - false, 'draft', $this->_custom_stati), |
|
154 | - ), |
|
155 | - 'Event_Meta' => array( |
|
156 | - 'EVTM_ID' => new EE_DB_Only_Float_Field('EVTM_ID', |
|
157 | - esc_html__('Event Meta Row ID', 'event_espresso'), false), |
|
158 | - 'EVT_ID_fk' => new EE_DB_Only_Int_Field('EVT_ID', |
|
159 | - esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'), false), |
|
160 | - 'EVT_display_desc' => new EE_Boolean_Field('EVT_display_desc', |
|
161 | - esc_html__('Display Description Flag', 'event_espresso'), false, 1), |
|
162 | - 'EVT_display_ticket_selector' => new EE_Boolean_Field('EVT_display_ticket_selector', |
|
163 | - esc_html__('Display Ticket Selector Flag', 'event_espresso'), false, 1), |
|
164 | - 'EVT_visible_on' => new EE_Datetime_Field('EVT_visible_on', |
|
165 | - esc_html__('Event Visible Date', 'event_espresso'), true, EE_Datetime_Field::now), |
|
166 | - 'EVT_additional_limit' => new EE_Integer_Field( |
|
167 | - 'EVT_additional_limit', |
|
168 | - esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
169 | - true, |
|
170 | - self::$_default_additional_limit |
|
171 | - ), |
|
172 | - 'EVT_default_registration_status' => new EE_Enum_Text_Field( |
|
173 | - 'EVT_default_registration_status', |
|
174 | - esc_html__('Default Registration Status on this Event', 'event_espresso'), false, |
|
175 | - EEM_Event::$_default_reg_status, EEM_Registration::reg_status_array() |
|
176 | - ), |
|
177 | - 'EVT_member_only' => new EE_Boolean_Field('EVT_member_only', |
|
178 | - esc_html__('Member-Only Event Flag', 'event_espresso'), false, false), |
|
179 | - 'EVT_phone' => new EE_Plain_Text_Field('EVT_phone', |
|
180 | - esc_html__('Event Phone Number', 'event_espresso'), false), |
|
181 | - 'EVT_allow_overflow' => new EE_Boolean_Field('EVT_allow_overflow', |
|
182 | - esc_html__('Allow Overflow on Event', 'event_espresso'), false, false), |
|
183 | - 'EVT_timezone_string' => new EE_Plain_Text_Field('EVT_timezone_string', |
|
184 | - esc_html__('Timezone (name) for Event times', 'event_espresso'), false), |
|
185 | - 'EVT_external_URL' => new EE_Plain_Text_Field('EVT_external_URL', |
|
186 | - esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'), true), |
|
187 | - 'EVT_donations' => new EE_Boolean_Field('EVT_donations', |
|
188 | - esc_html__('Accept Donations?', 'event_espresso'), false, false), |
|
189 | - ), |
|
190 | - ); |
|
191 | - $this->_model_relations = array( |
|
192 | - 'Registration' => new EE_Has_Many_Relation(), |
|
193 | - 'Datetime' => new EE_Has_Many_Relation(), |
|
194 | - 'Question_Group' => new EE_HABTM_Relation('Event_Question_Group'), |
|
195 | - 'Venue' => new EE_HABTM_Relation('Event_Venue'), |
|
196 | - 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
197 | - 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
198 | - 'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'), |
|
199 | - 'Attendee' => new EE_HABTM_Relation('Registration'), |
|
200 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
201 | - ); |
|
202 | - //this model is generally available for reading |
|
203 | - $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
204 | - parent::__construct($timezone); |
|
205 | - } |
|
206 | - |
|
207 | - |
|
208 | - |
|
209 | - /** |
|
210 | - * @param string $default_reg_status |
|
211 | - */ |
|
212 | - public static function set_default_reg_status($default_reg_status) |
|
213 | - { |
|
214 | - self::$_default_reg_status = $default_reg_status; |
|
215 | - // if EEM_Event has already been instantiated, |
|
216 | - // then we need to reset the `EVT_default_reg_status` field to use the new default. |
|
217 | - if (self::$_instance instanceof EEM_Event) { |
|
218 | - $default_reg_status = new EE_Enum_Text_Field( |
|
219 | - 'EVT_default_registration_status', |
|
220 | - esc_html__('Default Registration Status on this Event', 'event_espresso'), |
|
221 | - false, |
|
222 | - $default_reg_status, |
|
223 | - EEM_Registration::reg_status_array() |
|
224 | - ); |
|
225 | - $default_reg_status->_construct_finalize( |
|
226 | - 'Event_Meta', |
|
227 | - 'EVT_default_registration_status', |
|
228 | - 'EEM_Event' |
|
229 | - ); |
|
230 | - self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status; |
|
231 | - } |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - /** |
|
236 | - * Used to override the default for the additional limit field. |
|
237 | - * @param $additional_limit |
|
238 | - */ |
|
239 | - public static function set_default_additional_limit($additional_limit) |
|
240 | - { |
|
241 | - self::$_default_additional_limit = (int) $additional_limit; |
|
242 | - if (self::$_instance instanceof EEM_Event) { |
|
243 | - self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field( |
|
244 | - 'EVT_additional_limit', |
|
245 | - __('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
246 | - true, |
|
247 | - self::$_default_additional_limit |
|
248 | - ); |
|
249 | - self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize( |
|
250 | - 'Event_Meta', |
|
251 | - 'EVT_additional_limit', |
|
252 | - 'EEM_Event' |
|
253 | - ); |
|
254 | - } |
|
255 | - } |
|
256 | - |
|
257 | - |
|
258 | - /** |
|
259 | - * Return what is currently set as the default additional limit for the event. |
|
260 | - * @return int |
|
261 | - */ |
|
262 | - public static function get_default_additional_limit() |
|
263 | - { |
|
264 | - return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit); |
|
265 | - } |
|
266 | - |
|
267 | - |
|
268 | - /** |
|
269 | - * get_question_groups |
|
270 | - * |
|
271 | - * @return array |
|
272 | - * @throws \EE_Error |
|
273 | - */ |
|
274 | - public function get_all_question_groups() |
|
275 | - { |
|
276 | - return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
277 | - array( |
|
278 | - array('QSG_deleted' => false), |
|
279 | - 'order_by' => array('QSG_order' => 'ASC'), |
|
280 | - ) |
|
281 | - ); |
|
282 | - } |
|
283 | - |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * get_question_groups |
|
288 | - * |
|
289 | - * @param int $EVT_ID |
|
290 | - * @return array|bool |
|
291 | - * @throws \EE_Error |
|
292 | - */ |
|
293 | - public function get_all_event_question_groups($EVT_ID = 0) |
|
294 | - { |
|
295 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
296 | - EE_Error::add_error( |
|
297 | - esc_html__( |
|
298 | - 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
299 | - 'event_espresso' |
|
300 | - ), |
|
301 | - __FILE__, __FUNCTION__, __LINE__ |
|
302 | - ); |
|
303 | - return false; |
|
304 | - } |
|
305 | - return EE_Registry::instance()->load_model('Event_Question_Group')->get_all( |
|
306 | - array( |
|
307 | - array('EVT_ID' => $EVT_ID), |
|
308 | - ) |
|
309 | - ); |
|
310 | - } |
|
311 | - |
|
312 | - |
|
313 | - |
|
314 | - /** |
|
315 | - * get_question_groups |
|
316 | - * |
|
317 | - * @param int $EVT_ID |
|
318 | - * @param boolean $for_primary_attendee |
|
319 | - * @return array|bool |
|
320 | - * @throws \EE_Error |
|
321 | - */ |
|
322 | - public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true) |
|
323 | - { |
|
324 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
325 | - EE_Error::add_error( |
|
326 | - esc_html__( |
|
327 | - 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
328 | - 'event_espresso' |
|
329 | - ), |
|
330 | - __FILE__, __FUNCTION__, __LINE__ |
|
331 | - ); |
|
332 | - return false; |
|
333 | - } |
|
334 | - return EE_Registry::instance()->load_model('Event_Question_Group')->get_all( |
|
335 | - array( |
|
336 | - array( |
|
337 | - 'EVT_ID' => $EVT_ID, |
|
338 | - 'EQG_primary' => $for_primary_attendee, |
|
339 | - ), |
|
340 | - ) |
|
341 | - ); |
|
342 | - } |
|
343 | - |
|
344 | - |
|
345 | - |
|
346 | - /** |
|
347 | - * get_question_groups |
|
348 | - * |
|
349 | - * @param int $EVT_ID |
|
350 | - * @param EE_Registration $registration |
|
351 | - * @return array|bool |
|
352 | - * @throws \EE_Error |
|
353 | - */ |
|
354 | - public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration) |
|
355 | - { |
|
356 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
357 | - EE_Error::add_error( |
|
358 | - esc_html__( |
|
359 | - 'An error occurred. No Question Groups could be retrieved because an Event ID was not received.', |
|
360 | - 'event_espresso' |
|
361 | - ), |
|
362 | - __FILE__, __FUNCTION__, __LINE__ |
|
363 | - ); |
|
364 | - return false; |
|
365 | - } |
|
366 | - $where_params = array( |
|
367 | - 'Event_Question_Group.EVT_ID' => $EVT_ID, |
|
368 | - 'Event_Question_Group.EQG_primary' => $registration->count() === 1 ? true : false, |
|
369 | - 'QSG_deleted' => false, |
|
370 | - ); |
|
371 | - return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
372 | - array( |
|
373 | - $where_params, |
|
374 | - 'order_by' => array('QSG_order' => 'ASC'), |
|
375 | - ) |
|
376 | - ); |
|
377 | - } |
|
378 | - |
|
379 | - |
|
380 | - |
|
381 | - /** |
|
382 | - * get_question_target_db_column |
|
383 | - * |
|
384 | - * @param string $QSG_IDs csv list of $QSG IDs |
|
385 | - * @return array|bool |
|
386 | - * @throws \EE_Error |
|
387 | - */ |
|
388 | - public function get_questions_in_groups($QSG_IDs = '') |
|
389 | - { |
|
390 | - if (empty($QSG_IDs)) { |
|
391 | - EE_Error::add_error( |
|
392 | - esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'), |
|
393 | - __FILE__, __FUNCTION__, __LINE__ |
|
394 | - ); |
|
395 | - return false; |
|
396 | - } |
|
397 | - return EE_Registry::instance()->load_model('Question')->get_all( |
|
398 | - array( |
|
399 | - array( |
|
400 | - 'Question_Group.QSG_ID' => array('IN', $QSG_IDs), |
|
401 | - 'QST_deleted' => false, |
|
402 | - 'QST_admin_only' => is_admin(), |
|
403 | - ), |
|
404 | - 'order_by' => 'QST_order', |
|
405 | - ) |
|
406 | - ); |
|
407 | - } |
|
408 | - |
|
409 | - |
|
410 | - |
|
411 | - /** |
|
412 | - * get_options_for_question |
|
413 | - * |
|
414 | - * @param string $QST_IDs csv list of $QST IDs |
|
415 | - * @return array|bool |
|
416 | - * @throws \EE_Error |
|
417 | - */ |
|
418 | - public function get_options_for_question($QST_IDs) |
|
419 | - { |
|
420 | - if (empty($QST_IDs)) { |
|
421 | - EE_Error::add_error( |
|
422 | - esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'), |
|
423 | - __FILE__, __FUNCTION__, __LINE__ |
|
424 | - ); |
|
425 | - return false; |
|
426 | - } |
|
427 | - return EE_Registry::instance()->load_model('Question_Option')->get_all( |
|
428 | - array( |
|
429 | - array( |
|
430 | - 'Question.QST_ID' => array('IN', $QST_IDs), |
|
431 | - 'QSO_deleted' => false, |
|
432 | - ), |
|
433 | - 'order_by' => 'QSO_ID', |
|
434 | - ) |
|
435 | - ); |
|
436 | - } |
|
437 | - |
|
438 | - |
|
439 | - |
|
440 | - |
|
441 | - |
|
442 | - |
|
443 | - |
|
444 | - /** |
|
445 | - * Gets all events that are published |
|
446 | - * and have event start time earlier than now and an event end time later than now |
|
447 | - * |
|
448 | - * @param array $query_params An array of query params to further filter on |
|
449 | - * (note that status and DTT_EVT_start and DTT_EVT_end will be overridden) |
|
450 | - * @param bool $count whether to return the count or not (default FALSE) |
|
451 | - * @return EE_Event[]|int |
|
452 | - * @throws \EE_Error |
|
453 | - */ |
|
454 | - public function get_active_events($query_params, $count = false) |
|
455 | - { |
|
456 | - if (array_key_exists(0, $query_params)) { |
|
457 | - $where_params = $query_params[0]; |
|
458 | - unset($query_params[0]); |
|
459 | - } else { |
|
460 | - $where_params = array(); |
|
461 | - } |
|
462 | - // if we have count make sure we don't include group by |
|
463 | - if ($count && isset($query_params['group_by'])) { |
|
464 | - unset($query_params['group_by']); |
|
465 | - } |
|
466 | - // let's add specific query_params for active_events |
|
467 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
468 | - $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
469 | - //if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions |
|
470 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
471 | - $where_params['Datetime.DTT_EVT_start******'] = array( |
|
472 | - '<', |
|
473 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
474 | - ); |
|
475 | - } else { |
|
476 | - $where_params['Datetime.DTT_EVT_start'] = array( |
|
477 | - '<', |
|
478 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
479 | - ); |
|
480 | - } |
|
481 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
482 | - $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
483 | - '>', |
|
484 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
485 | - ); |
|
486 | - } else { |
|
487 | - $where_params['Datetime.DTT_EVT_end'] = array( |
|
488 | - '>', |
|
489 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
490 | - ); |
|
491 | - } |
|
492 | - $query_params[0] = $where_params; |
|
493 | - // don't use $query_params with count() |
|
494 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
495 | - return $count |
|
496 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
497 | - : $this->get_all($query_params); |
|
498 | - } |
|
499 | - |
|
500 | - |
|
501 | - |
|
502 | - /** |
|
503 | - * get all events that are published and have an event start time later than now |
|
504 | - * |
|
505 | - * @param array $query_params An array of query params to further filter on |
|
506 | - * (Note that status and DTT_EVT_start will be overridden) |
|
507 | - * @param bool $count whether to return the count or not (default FALSE) |
|
508 | - * @return EE_Event[]|int |
|
509 | - * @throws \EE_Error |
|
510 | - */ |
|
511 | - public function get_upcoming_events($query_params, $count = false) |
|
512 | - { |
|
513 | - if (array_key_exists(0, $query_params)) { |
|
514 | - $where_params = $query_params[0]; |
|
515 | - unset($query_params[0]); |
|
516 | - } else { |
|
517 | - $where_params = array(); |
|
518 | - } |
|
519 | - // if we have count make sure we don't include group by |
|
520 | - if ($count && isset($query_params['group_by'])) { |
|
521 | - unset($query_params['group_by']); |
|
522 | - } |
|
523 | - // let's add specific query_params for active_events |
|
524 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
525 | - $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
526 | - // if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
|
527 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
528 | - $where_params['Datetime.DTT_EVT_start*****'] = array( |
|
529 | - '>', |
|
530 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
531 | - ); |
|
532 | - } else { |
|
533 | - $where_params['Datetime.DTT_EVT_start'] = array( |
|
534 | - '>', |
|
535 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
536 | - ); |
|
537 | - } |
|
538 | - $query_params[0] = $where_params; |
|
539 | - // don't use $query_params with count() |
|
540 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
541 | - return $count |
|
542 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
543 | - : $this->get_all($query_params); |
|
544 | - } |
|
545 | - |
|
546 | - |
|
547 | - |
|
548 | - /** |
|
549 | - * Gets all events that are published |
|
550 | - * and have an event end time later than now |
|
551 | - * |
|
552 | - * @param array $query_params An array of query params to further filter on |
|
553 | - * (note that status and DTT_EVT_end will be overridden) |
|
554 | - * @param bool $count whether to return the count or not (default FALSE) |
|
555 | - * @return EE_Event[]|int |
|
556 | - * @throws \EE_Error |
|
557 | - */ |
|
558 | - public function get_active_and_upcoming_events($query_params, $count = false) |
|
559 | - { |
|
560 | - if (array_key_exists(0, $query_params)) { |
|
561 | - $where_params = $query_params[0]; |
|
562 | - unset($query_params[0]); |
|
563 | - } else { |
|
564 | - $where_params = array(); |
|
565 | - } |
|
566 | - // if we have count make sure we don't include group by |
|
567 | - if ($count && isset($query_params['group_by'])) { |
|
568 | - unset($query_params['group_by']); |
|
569 | - } |
|
570 | - // let's add specific query_params for active_events |
|
571 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
572 | - $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
573 | - // add where params for DTT_EVT_end |
|
574 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
575 | - $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
576 | - '>', |
|
577 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
578 | - ); |
|
579 | - } else { |
|
580 | - $where_params['Datetime.DTT_EVT_end'] = array( |
|
581 | - '>', |
|
582 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
583 | - ); |
|
584 | - } |
|
585 | - $query_params[0] = $where_params; |
|
586 | - // don't use $query_params with count() |
|
587 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
588 | - return $count |
|
589 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
590 | - : $this->get_all($query_params); |
|
591 | - } |
|
592 | - |
|
593 | - |
|
594 | - |
|
595 | - /** |
|
596 | - * This only returns events that are expired. |
|
597 | - * They may still be published but all their datetimes have expired. |
|
598 | - * |
|
599 | - * @param array $query_params An array of query params to further filter on |
|
600 | - * (note that status and DTT_EVT_end will be overridden) |
|
601 | - * @param bool $count whether to return the count or not (default FALSE) |
|
602 | - * @return EE_Event[]|int |
|
603 | - * @throws \EE_Error |
|
604 | - */ |
|
605 | - public function get_expired_events($query_params, $count = false) |
|
606 | - { |
|
607 | - $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
608 | - // if we have count make sure we don't include group by |
|
609 | - if ($count && isset($query_params['group_by'])) { |
|
610 | - unset($query_params['group_by']); |
|
611 | - } |
|
612 | - // let's add specific query_params for active_events |
|
613 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
614 | - if (isset($where_params['status'])) { |
|
615 | - unset($where_params['status']); |
|
616 | - } |
|
617 | - $exclude_query = $query_params; |
|
618 | - if (isset($exclude_query[0])) { |
|
619 | - unset($exclude_query[0]); |
|
620 | - } |
|
621 | - $exclude_query[0] = array( |
|
622 | - 'Datetime.DTT_EVT_end' => array( |
|
623 | - '>', |
|
624 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
625 | - ), |
|
626 | - ); |
|
627 | - // first get all events that have datetimes where its not expired. |
|
628 | - $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID'); |
|
629 | - $event_ids = array_keys($event_ids); |
|
630 | - // if we have any additional query_params, let's add them to the 'AND' condition |
|
631 | - $and_condition = array( |
|
632 | - 'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')), |
|
633 | - 'EVT_ID' => array('NOT IN', $event_ids), |
|
634 | - ); |
|
635 | - if (isset($where_params['OR'])) { |
|
636 | - $and_condition['OR'] = $where_params['OR']; |
|
637 | - unset($where_params['OR']); |
|
638 | - } |
|
639 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
640 | - $and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
641 | - unset($where_params['Datetime.DTT_EVT_end']); |
|
642 | - } |
|
643 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
644 | - $and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
645 | - unset($where_params['Datetime.DTT_EVT_start']); |
|
646 | - } |
|
647 | - // merge remaining $where params with the and conditions. |
|
648 | - $where_params['AND'] = array_merge($and_condition, $where_params); |
|
649 | - $query_params[0] = $where_params; |
|
650 | - // don't use $query_params with count() |
|
651 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
652 | - return $count |
|
653 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
654 | - : $this->get_all($query_params); |
|
655 | - } |
|
656 | - |
|
657 | - |
|
658 | - |
|
659 | - /** |
|
660 | - * This basically just returns the events that do not have the publish status. |
|
661 | - * |
|
662 | - * @param array $query_params An array of query params to further filter on |
|
663 | - * (note that status will be overwritten) |
|
664 | - * @param boolean $count whether to return the count or not (default FALSE) |
|
665 | - * @return EE_Event[]|int |
|
666 | - * @throws \EE_Error |
|
667 | - */ |
|
668 | - public function get_inactive_events($query_params, $count = false) |
|
669 | - { |
|
670 | - $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
671 | - // let's add in specific query_params for inactive events. |
|
672 | - if (isset($where_params['status'])) { |
|
673 | - unset($where_params['status']); |
|
674 | - } |
|
675 | - // if we have count make sure we don't include group by |
|
676 | - if ($count && isset($query_params['group_by'])) { |
|
677 | - unset($query_params['group_by']); |
|
678 | - } |
|
679 | - // if we have any additional query_params, let's add them to the 'AND' condition |
|
680 | - $where_params['AND']['status'] = array('!=', 'publish'); |
|
681 | - if (isset($where_params['OR'])) { |
|
682 | - $where_params['AND']['OR'] = $where_params['OR']; |
|
683 | - unset($where_params['OR']); |
|
684 | - } |
|
685 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
686 | - $where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
687 | - unset($where_params['Datetime.DTT_EVT_end']); |
|
688 | - } |
|
689 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
690 | - $where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
691 | - unset($where_params['Datetime.DTT_EVT_start']); |
|
692 | - } |
|
693 | - $query_params[0] = $where_params; |
|
694 | - // don't use $query_params with count() |
|
695 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
696 | - return $count |
|
697 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
698 | - : $this->get_all($query_params); |
|
699 | - } |
|
700 | - |
|
701 | - |
|
702 | - |
|
703 | - /** |
|
704 | - * This is just injecting into the parent add_relationship_to so we do special handling on price relationships |
|
705 | - * because we don't want to override any existing global default prices but instead insert NEW prices that get |
|
706 | - * attached to the event. See parent for param descriptions |
|
707 | - * |
|
708 | - * @param $id_or_obj |
|
709 | - * @param $other_model_id_or_obj |
|
710 | - * @param string $relationName |
|
711 | - * @param array $where_query |
|
712 | - * @return EE_Base_Class |
|
713 | - * @throws EE_Error |
|
714 | - */ |
|
715 | - public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) |
|
716 | - { |
|
717 | - if ($relationName === 'Price') { |
|
718 | - //let's get the PRC object for the given ID to make sure that we aren't dealing with a default |
|
719 | - $prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj); |
|
720 | - //if EVT_ID = 0, then this is a default |
|
721 | - if ((int) $prc_chk->get('EVT_ID') === 0) { |
|
722 | - //let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation |
|
723 | - $prc_chk->set('PRC_ID', 0); |
|
724 | - } |
|
725 | - //run parent |
|
726 | - return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query); |
|
727 | - } |
|
728 | - //otherwise carry on as normal |
|
729 | - return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query); |
|
730 | - } |
|
731 | - |
|
732 | - |
|
733 | - |
|
734 | - /******************** DEPRECATED METHODS ********************/ |
|
735 | - |
|
736 | - |
|
737 | - |
|
738 | - /** |
|
739 | - * _get_question_target_db_column |
|
740 | - * |
|
741 | - * @deprecated as of 4.8.32.rc.001. Instead consider using |
|
742 | - * EE_Registration_Custom_Questions_Form located in |
|
743 | - * admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php |
|
744 | - * @access public |
|
745 | - * @param EE_Registration $registration (so existing answers for registration are included) |
|
746 | - * @param int $EVT_ID so all question groups are included for event (not just answers from |
|
747 | - * registration). |
|
748 | - * @throws EE_Error |
|
749 | - * @return array |
|
750 | - */ |
|
751 | - public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0) |
|
752 | - { |
|
753 | - if (empty($EVT_ID)) { |
|
754 | - throw new EE_Error(__('An error occurred. No EVT_ID is included. Needed to know which question groups to retrieve.', |
|
755 | - 'event_espresso')); |
|
756 | - } |
|
757 | - $questions = array(); |
|
758 | - // get all question groups for event |
|
759 | - $qgs = $this->get_question_groups_for_event($EVT_ID, $registration); |
|
760 | - if (! empty($qgs)) { |
|
761 | - foreach ($qgs as $qg) { |
|
762 | - $qsts = $qg->questions(); |
|
763 | - $questions[$qg->ID()] = $qg->model_field_array(); |
|
764 | - $questions[$qg->ID()]['QSG_questions'] = array(); |
|
765 | - foreach ($qsts as $qst) { |
|
766 | - if ($qst->is_system_question()) { |
|
767 | - continue; |
|
768 | - } |
|
769 | - $answer = EEM_Answer::instance()->get_one(array( |
|
770 | - array( |
|
771 | - 'QST_ID' => $qst->ID(), |
|
772 | - 'REG_ID' => $registration->ID(), |
|
773 | - ), |
|
774 | - )); |
|
775 | - $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object(); |
|
776 | - $qst_name = $qstn_id = $qst->ID(); |
|
777 | - $ans_id = $answer->ID(); |
|
778 | - $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']'; |
|
779 | - $input_name = ''; |
|
780 | - $input_id = sanitize_key($qst->display_text()); |
|
781 | - $input_class = ''; |
|
782 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()] = $qst->model_field_array(); |
|
783 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn' |
|
784 | - . $input_name |
|
785 | - . $qst_name; |
|
786 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id . '-' . $qstn_id; |
|
787 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class; |
|
788 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'] = array(); |
|
789 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj'] = $qst; |
|
790 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['ans_obj'] = $answer; |
|
791 | - //leave responses as-is, don't convert stuff into html entities please! |
|
792 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['htmlentities'] = false; |
|
793 | - if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') { |
|
794 | - $QSOs = $qst->options(true, $answer->value()); |
|
795 | - if (is_array($QSOs)) { |
|
796 | - foreach ($QSOs as $QSO_ID => $QSO) { |
|
797 | - $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'][$QSO_ID] = $QSO->model_field_array(); |
|
798 | - } |
|
799 | - } |
|
800 | - } |
|
801 | - } |
|
802 | - } |
|
803 | - } |
|
804 | - return $questions; |
|
805 | - } |
|
19 | + /** |
|
20 | + * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the |
|
21 | + * event |
|
22 | + */ |
|
23 | + const sold_out = 'sold_out'; |
|
24 | + |
|
25 | + /** |
|
26 | + * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later |
|
27 | + * date) |
|
28 | + */ |
|
29 | + const postponed = 'postponed'; |
|
30 | + |
|
31 | + /** |
|
32 | + * constant used by status(), indicating that the event will no longer occur |
|
33 | + */ |
|
34 | + const cancelled = 'cancelled'; |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * @var string |
|
39 | + */ |
|
40 | + protected static $_default_reg_status; |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * This is the default for the additional limit field. |
|
45 | + * @var int |
|
46 | + */ |
|
47 | + protected static $_default_additional_limit = 10; |
|
48 | + |
|
49 | + |
|
50 | + /** |
|
51 | + * private instance of the Event object |
|
52 | + * |
|
53 | + * @var EEM_Event |
|
54 | + */ |
|
55 | + protected static $_instance; |
|
56 | + |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * This function is a singleton method used to instantiate the EEM_Event object |
|
61 | + * |
|
62 | + * @param string $timezone |
|
63 | + * @return EEM_Event |
|
64 | + * @throws \EE_Error |
|
65 | + */ |
|
66 | + public static function instance($timezone = null) |
|
67 | + { |
|
68 | + // check if instance of EEM_Event already exists |
|
69 | + if (! self::$_instance instanceof EEM_Event) { |
|
70 | + // instantiate Espresso_model |
|
71 | + self::$_instance = new self($timezone); |
|
72 | + } |
|
73 | + //we might have a timezone set, let set_timezone decide what to do with it |
|
74 | + self::$_instance->set_timezone($timezone); |
|
75 | + // EEM_Event object |
|
76 | + return self::$_instance; |
|
77 | + } |
|
78 | + |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * Adds a relationship to Term_Taxonomy for each CPT_Base |
|
83 | + * |
|
84 | + * @param string $timezone |
|
85 | + * @throws \EE_Error |
|
86 | + */ |
|
87 | + protected function __construct($timezone = null) |
|
88 | + { |
|
89 | + EE_Registry::instance()->load_model('Registration'); |
|
90 | + $this->singular_item = esc_html__('Event', 'event_espresso'); |
|
91 | + $this->plural_item = esc_html__('Events', 'event_espresso'); |
|
92 | + // to remove Cancelled events from the frontend, copy the following filter to your functions.php file |
|
93 | + // add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' ); |
|
94 | + // to remove Postponed events from the frontend, copy the following filter to your functions.php file |
|
95 | + // add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' ); |
|
96 | + // to remove Sold Out events from the frontend, copy the following filter to your functions.php file |
|
97 | + // add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' ); |
|
98 | + $this->_custom_stati = apply_filters( |
|
99 | + 'AFEE__EEM_Event__construct___custom_stati', |
|
100 | + array( |
|
101 | + EEM_Event::cancelled => array( |
|
102 | + 'label' => esc_html__('Cancelled', 'event_espresso'), |
|
103 | + 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true), |
|
104 | + ), |
|
105 | + EEM_Event::postponed => array( |
|
106 | + 'label' => esc_html__('Postponed', 'event_espresso'), |
|
107 | + 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true), |
|
108 | + ), |
|
109 | + EEM_Event::sold_out => array( |
|
110 | + 'label' => esc_html__('Sold Out', 'event_espresso'), |
|
111 | + 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true), |
|
112 | + ), |
|
113 | + ) |
|
114 | + ); |
|
115 | + self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment |
|
116 | + : self::$_default_reg_status; |
|
117 | + $this->_tables = array( |
|
118 | + 'Event_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
119 | + 'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'), |
|
120 | + ); |
|
121 | + $this->_fields = array( |
|
122 | + 'Event_CPT' => array( |
|
123 | + 'EVT_ID' => new EE_Primary_Key_Int_Field('ID', |
|
124 | + esc_html__('Post ID for Event', 'event_espresso')), |
|
125 | + 'EVT_name' => new EE_Plain_Text_Field('post_title', esc_html__('Event Name', 'event_espresso'), |
|
126 | + false, |
|
127 | + ''), |
|
128 | + 'EVT_desc' => new EE_Post_Content_Field('post_content', |
|
129 | + esc_html__('Event Description', 'event_espresso'), |
|
130 | + false, ''), |
|
131 | + 'EVT_slug' => new EE_Slug_Field('post_name', esc_html__('Event Slug', 'event_espresso'), false, |
|
132 | + ''), |
|
133 | + 'EVT_created' => new EE_Datetime_Field('post_date', |
|
134 | + esc_html__('Date/Time Event Created', 'event_espresso'), |
|
135 | + false, EE_Datetime_Field::now), |
|
136 | + 'EVT_short_desc' => new EE_Simple_HTML_Field('post_excerpt', |
|
137 | + esc_html__('Event Short Description', 'event_espresso'), false, ''), |
|
138 | + 'EVT_modified' => new EE_Datetime_Field('post_modified', |
|
139 | + esc_html__('Date/Time Event Modified', 'event_espresso'), false, EE_Datetime_Field::now), |
|
140 | + 'EVT_wp_user' => new EE_WP_User_Field('post_author', |
|
141 | + esc_html__('Event Creator ID', 'event_espresso'), |
|
142 | + false), |
|
143 | + 'parent' => new EE_Integer_Field('post_parent', esc_html__('Event Parent ID', 'event_espresso'), |
|
144 | + false, |
|
145 | + 0), |
|
146 | + 'EVT_order' => new EE_Integer_Field('menu_order', esc_html__('Event Menu Order', 'event_espresso'), |
|
147 | + false, |
|
148 | + 1), |
|
149 | + 'post_type' => new EE_WP_Post_Type_Field('espresso_events'), |
|
150 | + // EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ), |
|
151 | + 'status' => new EE_WP_Post_Status_Field('post_status', |
|
152 | + esc_html__('Event Status', 'event_espresso'), |
|
153 | + false, 'draft', $this->_custom_stati), |
|
154 | + ), |
|
155 | + 'Event_Meta' => array( |
|
156 | + 'EVTM_ID' => new EE_DB_Only_Float_Field('EVTM_ID', |
|
157 | + esc_html__('Event Meta Row ID', 'event_espresso'), false), |
|
158 | + 'EVT_ID_fk' => new EE_DB_Only_Int_Field('EVT_ID', |
|
159 | + esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'), false), |
|
160 | + 'EVT_display_desc' => new EE_Boolean_Field('EVT_display_desc', |
|
161 | + esc_html__('Display Description Flag', 'event_espresso'), false, 1), |
|
162 | + 'EVT_display_ticket_selector' => new EE_Boolean_Field('EVT_display_ticket_selector', |
|
163 | + esc_html__('Display Ticket Selector Flag', 'event_espresso'), false, 1), |
|
164 | + 'EVT_visible_on' => new EE_Datetime_Field('EVT_visible_on', |
|
165 | + esc_html__('Event Visible Date', 'event_espresso'), true, EE_Datetime_Field::now), |
|
166 | + 'EVT_additional_limit' => new EE_Integer_Field( |
|
167 | + 'EVT_additional_limit', |
|
168 | + esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
169 | + true, |
|
170 | + self::$_default_additional_limit |
|
171 | + ), |
|
172 | + 'EVT_default_registration_status' => new EE_Enum_Text_Field( |
|
173 | + 'EVT_default_registration_status', |
|
174 | + esc_html__('Default Registration Status on this Event', 'event_espresso'), false, |
|
175 | + EEM_Event::$_default_reg_status, EEM_Registration::reg_status_array() |
|
176 | + ), |
|
177 | + 'EVT_member_only' => new EE_Boolean_Field('EVT_member_only', |
|
178 | + esc_html__('Member-Only Event Flag', 'event_espresso'), false, false), |
|
179 | + 'EVT_phone' => new EE_Plain_Text_Field('EVT_phone', |
|
180 | + esc_html__('Event Phone Number', 'event_espresso'), false), |
|
181 | + 'EVT_allow_overflow' => new EE_Boolean_Field('EVT_allow_overflow', |
|
182 | + esc_html__('Allow Overflow on Event', 'event_espresso'), false, false), |
|
183 | + 'EVT_timezone_string' => new EE_Plain_Text_Field('EVT_timezone_string', |
|
184 | + esc_html__('Timezone (name) for Event times', 'event_espresso'), false), |
|
185 | + 'EVT_external_URL' => new EE_Plain_Text_Field('EVT_external_URL', |
|
186 | + esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'), true), |
|
187 | + 'EVT_donations' => new EE_Boolean_Field('EVT_donations', |
|
188 | + esc_html__('Accept Donations?', 'event_espresso'), false, false), |
|
189 | + ), |
|
190 | + ); |
|
191 | + $this->_model_relations = array( |
|
192 | + 'Registration' => new EE_Has_Many_Relation(), |
|
193 | + 'Datetime' => new EE_Has_Many_Relation(), |
|
194 | + 'Question_Group' => new EE_HABTM_Relation('Event_Question_Group'), |
|
195 | + 'Venue' => new EE_HABTM_Relation('Event_Venue'), |
|
196 | + 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
197 | + 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
198 | + 'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'), |
|
199 | + 'Attendee' => new EE_HABTM_Relation('Registration'), |
|
200 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
201 | + ); |
|
202 | + //this model is generally available for reading |
|
203 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
204 | + parent::__construct($timezone); |
|
205 | + } |
|
206 | + |
|
207 | + |
|
208 | + |
|
209 | + /** |
|
210 | + * @param string $default_reg_status |
|
211 | + */ |
|
212 | + public static function set_default_reg_status($default_reg_status) |
|
213 | + { |
|
214 | + self::$_default_reg_status = $default_reg_status; |
|
215 | + // if EEM_Event has already been instantiated, |
|
216 | + // then we need to reset the `EVT_default_reg_status` field to use the new default. |
|
217 | + if (self::$_instance instanceof EEM_Event) { |
|
218 | + $default_reg_status = new EE_Enum_Text_Field( |
|
219 | + 'EVT_default_registration_status', |
|
220 | + esc_html__('Default Registration Status on this Event', 'event_espresso'), |
|
221 | + false, |
|
222 | + $default_reg_status, |
|
223 | + EEM_Registration::reg_status_array() |
|
224 | + ); |
|
225 | + $default_reg_status->_construct_finalize( |
|
226 | + 'Event_Meta', |
|
227 | + 'EVT_default_registration_status', |
|
228 | + 'EEM_Event' |
|
229 | + ); |
|
230 | + self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status; |
|
231 | + } |
|
232 | + } |
|
233 | + |
|
234 | + |
|
235 | + /** |
|
236 | + * Used to override the default for the additional limit field. |
|
237 | + * @param $additional_limit |
|
238 | + */ |
|
239 | + public static function set_default_additional_limit($additional_limit) |
|
240 | + { |
|
241 | + self::$_default_additional_limit = (int) $additional_limit; |
|
242 | + if (self::$_instance instanceof EEM_Event) { |
|
243 | + self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field( |
|
244 | + 'EVT_additional_limit', |
|
245 | + __('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
246 | + true, |
|
247 | + self::$_default_additional_limit |
|
248 | + ); |
|
249 | + self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize( |
|
250 | + 'Event_Meta', |
|
251 | + 'EVT_additional_limit', |
|
252 | + 'EEM_Event' |
|
253 | + ); |
|
254 | + } |
|
255 | + } |
|
256 | + |
|
257 | + |
|
258 | + /** |
|
259 | + * Return what is currently set as the default additional limit for the event. |
|
260 | + * @return int |
|
261 | + */ |
|
262 | + public static function get_default_additional_limit() |
|
263 | + { |
|
264 | + return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit); |
|
265 | + } |
|
266 | + |
|
267 | + |
|
268 | + /** |
|
269 | + * get_question_groups |
|
270 | + * |
|
271 | + * @return array |
|
272 | + * @throws \EE_Error |
|
273 | + */ |
|
274 | + public function get_all_question_groups() |
|
275 | + { |
|
276 | + return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
277 | + array( |
|
278 | + array('QSG_deleted' => false), |
|
279 | + 'order_by' => array('QSG_order' => 'ASC'), |
|
280 | + ) |
|
281 | + ); |
|
282 | + } |
|
283 | + |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * get_question_groups |
|
288 | + * |
|
289 | + * @param int $EVT_ID |
|
290 | + * @return array|bool |
|
291 | + * @throws \EE_Error |
|
292 | + */ |
|
293 | + public function get_all_event_question_groups($EVT_ID = 0) |
|
294 | + { |
|
295 | + if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
296 | + EE_Error::add_error( |
|
297 | + esc_html__( |
|
298 | + 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
299 | + 'event_espresso' |
|
300 | + ), |
|
301 | + __FILE__, __FUNCTION__, __LINE__ |
|
302 | + ); |
|
303 | + return false; |
|
304 | + } |
|
305 | + return EE_Registry::instance()->load_model('Event_Question_Group')->get_all( |
|
306 | + array( |
|
307 | + array('EVT_ID' => $EVT_ID), |
|
308 | + ) |
|
309 | + ); |
|
310 | + } |
|
311 | + |
|
312 | + |
|
313 | + |
|
314 | + /** |
|
315 | + * get_question_groups |
|
316 | + * |
|
317 | + * @param int $EVT_ID |
|
318 | + * @param boolean $for_primary_attendee |
|
319 | + * @return array|bool |
|
320 | + * @throws \EE_Error |
|
321 | + */ |
|
322 | + public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true) |
|
323 | + { |
|
324 | + if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
325 | + EE_Error::add_error( |
|
326 | + esc_html__( |
|
327 | + 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
328 | + 'event_espresso' |
|
329 | + ), |
|
330 | + __FILE__, __FUNCTION__, __LINE__ |
|
331 | + ); |
|
332 | + return false; |
|
333 | + } |
|
334 | + return EE_Registry::instance()->load_model('Event_Question_Group')->get_all( |
|
335 | + array( |
|
336 | + array( |
|
337 | + 'EVT_ID' => $EVT_ID, |
|
338 | + 'EQG_primary' => $for_primary_attendee, |
|
339 | + ), |
|
340 | + ) |
|
341 | + ); |
|
342 | + } |
|
343 | + |
|
344 | + |
|
345 | + |
|
346 | + /** |
|
347 | + * get_question_groups |
|
348 | + * |
|
349 | + * @param int $EVT_ID |
|
350 | + * @param EE_Registration $registration |
|
351 | + * @return array|bool |
|
352 | + * @throws \EE_Error |
|
353 | + */ |
|
354 | + public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration) |
|
355 | + { |
|
356 | + if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
357 | + EE_Error::add_error( |
|
358 | + esc_html__( |
|
359 | + 'An error occurred. No Question Groups could be retrieved because an Event ID was not received.', |
|
360 | + 'event_espresso' |
|
361 | + ), |
|
362 | + __FILE__, __FUNCTION__, __LINE__ |
|
363 | + ); |
|
364 | + return false; |
|
365 | + } |
|
366 | + $where_params = array( |
|
367 | + 'Event_Question_Group.EVT_ID' => $EVT_ID, |
|
368 | + 'Event_Question_Group.EQG_primary' => $registration->count() === 1 ? true : false, |
|
369 | + 'QSG_deleted' => false, |
|
370 | + ); |
|
371 | + return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
372 | + array( |
|
373 | + $where_params, |
|
374 | + 'order_by' => array('QSG_order' => 'ASC'), |
|
375 | + ) |
|
376 | + ); |
|
377 | + } |
|
378 | + |
|
379 | + |
|
380 | + |
|
381 | + /** |
|
382 | + * get_question_target_db_column |
|
383 | + * |
|
384 | + * @param string $QSG_IDs csv list of $QSG IDs |
|
385 | + * @return array|bool |
|
386 | + * @throws \EE_Error |
|
387 | + */ |
|
388 | + public function get_questions_in_groups($QSG_IDs = '') |
|
389 | + { |
|
390 | + if (empty($QSG_IDs)) { |
|
391 | + EE_Error::add_error( |
|
392 | + esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'), |
|
393 | + __FILE__, __FUNCTION__, __LINE__ |
|
394 | + ); |
|
395 | + return false; |
|
396 | + } |
|
397 | + return EE_Registry::instance()->load_model('Question')->get_all( |
|
398 | + array( |
|
399 | + array( |
|
400 | + 'Question_Group.QSG_ID' => array('IN', $QSG_IDs), |
|
401 | + 'QST_deleted' => false, |
|
402 | + 'QST_admin_only' => is_admin(), |
|
403 | + ), |
|
404 | + 'order_by' => 'QST_order', |
|
405 | + ) |
|
406 | + ); |
|
407 | + } |
|
408 | + |
|
409 | + |
|
410 | + |
|
411 | + /** |
|
412 | + * get_options_for_question |
|
413 | + * |
|
414 | + * @param string $QST_IDs csv list of $QST IDs |
|
415 | + * @return array|bool |
|
416 | + * @throws \EE_Error |
|
417 | + */ |
|
418 | + public function get_options_for_question($QST_IDs) |
|
419 | + { |
|
420 | + if (empty($QST_IDs)) { |
|
421 | + EE_Error::add_error( |
|
422 | + esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'), |
|
423 | + __FILE__, __FUNCTION__, __LINE__ |
|
424 | + ); |
|
425 | + return false; |
|
426 | + } |
|
427 | + return EE_Registry::instance()->load_model('Question_Option')->get_all( |
|
428 | + array( |
|
429 | + array( |
|
430 | + 'Question.QST_ID' => array('IN', $QST_IDs), |
|
431 | + 'QSO_deleted' => false, |
|
432 | + ), |
|
433 | + 'order_by' => 'QSO_ID', |
|
434 | + ) |
|
435 | + ); |
|
436 | + } |
|
437 | + |
|
438 | + |
|
439 | + |
|
440 | + |
|
441 | + |
|
442 | + |
|
443 | + |
|
444 | + /** |
|
445 | + * Gets all events that are published |
|
446 | + * and have event start time earlier than now and an event end time later than now |
|
447 | + * |
|
448 | + * @param array $query_params An array of query params to further filter on |
|
449 | + * (note that status and DTT_EVT_start and DTT_EVT_end will be overridden) |
|
450 | + * @param bool $count whether to return the count or not (default FALSE) |
|
451 | + * @return EE_Event[]|int |
|
452 | + * @throws \EE_Error |
|
453 | + */ |
|
454 | + public function get_active_events($query_params, $count = false) |
|
455 | + { |
|
456 | + if (array_key_exists(0, $query_params)) { |
|
457 | + $where_params = $query_params[0]; |
|
458 | + unset($query_params[0]); |
|
459 | + } else { |
|
460 | + $where_params = array(); |
|
461 | + } |
|
462 | + // if we have count make sure we don't include group by |
|
463 | + if ($count && isset($query_params['group_by'])) { |
|
464 | + unset($query_params['group_by']); |
|
465 | + } |
|
466 | + // let's add specific query_params for active_events |
|
467 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
468 | + $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
469 | + //if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions |
|
470 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
471 | + $where_params['Datetime.DTT_EVT_start******'] = array( |
|
472 | + '<', |
|
473 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
474 | + ); |
|
475 | + } else { |
|
476 | + $where_params['Datetime.DTT_EVT_start'] = array( |
|
477 | + '<', |
|
478 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
479 | + ); |
|
480 | + } |
|
481 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
482 | + $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
483 | + '>', |
|
484 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
485 | + ); |
|
486 | + } else { |
|
487 | + $where_params['Datetime.DTT_EVT_end'] = array( |
|
488 | + '>', |
|
489 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
490 | + ); |
|
491 | + } |
|
492 | + $query_params[0] = $where_params; |
|
493 | + // don't use $query_params with count() |
|
494 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
495 | + return $count |
|
496 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
497 | + : $this->get_all($query_params); |
|
498 | + } |
|
499 | + |
|
500 | + |
|
501 | + |
|
502 | + /** |
|
503 | + * get all events that are published and have an event start time later than now |
|
504 | + * |
|
505 | + * @param array $query_params An array of query params to further filter on |
|
506 | + * (Note that status and DTT_EVT_start will be overridden) |
|
507 | + * @param bool $count whether to return the count or not (default FALSE) |
|
508 | + * @return EE_Event[]|int |
|
509 | + * @throws \EE_Error |
|
510 | + */ |
|
511 | + public function get_upcoming_events($query_params, $count = false) |
|
512 | + { |
|
513 | + if (array_key_exists(0, $query_params)) { |
|
514 | + $where_params = $query_params[0]; |
|
515 | + unset($query_params[0]); |
|
516 | + } else { |
|
517 | + $where_params = array(); |
|
518 | + } |
|
519 | + // if we have count make sure we don't include group by |
|
520 | + if ($count && isset($query_params['group_by'])) { |
|
521 | + unset($query_params['group_by']); |
|
522 | + } |
|
523 | + // let's add specific query_params for active_events |
|
524 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
525 | + $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
526 | + // if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
|
527 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
528 | + $where_params['Datetime.DTT_EVT_start*****'] = array( |
|
529 | + '>', |
|
530 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
531 | + ); |
|
532 | + } else { |
|
533 | + $where_params['Datetime.DTT_EVT_start'] = array( |
|
534 | + '>', |
|
535 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
536 | + ); |
|
537 | + } |
|
538 | + $query_params[0] = $where_params; |
|
539 | + // don't use $query_params with count() |
|
540 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
541 | + return $count |
|
542 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
543 | + : $this->get_all($query_params); |
|
544 | + } |
|
545 | + |
|
546 | + |
|
547 | + |
|
548 | + /** |
|
549 | + * Gets all events that are published |
|
550 | + * and have an event end time later than now |
|
551 | + * |
|
552 | + * @param array $query_params An array of query params to further filter on |
|
553 | + * (note that status and DTT_EVT_end will be overridden) |
|
554 | + * @param bool $count whether to return the count or not (default FALSE) |
|
555 | + * @return EE_Event[]|int |
|
556 | + * @throws \EE_Error |
|
557 | + */ |
|
558 | + public function get_active_and_upcoming_events($query_params, $count = false) |
|
559 | + { |
|
560 | + if (array_key_exists(0, $query_params)) { |
|
561 | + $where_params = $query_params[0]; |
|
562 | + unset($query_params[0]); |
|
563 | + } else { |
|
564 | + $where_params = array(); |
|
565 | + } |
|
566 | + // if we have count make sure we don't include group by |
|
567 | + if ($count && isset($query_params['group_by'])) { |
|
568 | + unset($query_params['group_by']); |
|
569 | + } |
|
570 | + // let's add specific query_params for active_events |
|
571 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
572 | + $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
573 | + // add where params for DTT_EVT_end |
|
574 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
575 | + $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
576 | + '>', |
|
577 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
578 | + ); |
|
579 | + } else { |
|
580 | + $where_params['Datetime.DTT_EVT_end'] = array( |
|
581 | + '>', |
|
582 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
583 | + ); |
|
584 | + } |
|
585 | + $query_params[0] = $where_params; |
|
586 | + // don't use $query_params with count() |
|
587 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
588 | + return $count |
|
589 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
590 | + : $this->get_all($query_params); |
|
591 | + } |
|
592 | + |
|
593 | + |
|
594 | + |
|
595 | + /** |
|
596 | + * This only returns events that are expired. |
|
597 | + * They may still be published but all their datetimes have expired. |
|
598 | + * |
|
599 | + * @param array $query_params An array of query params to further filter on |
|
600 | + * (note that status and DTT_EVT_end will be overridden) |
|
601 | + * @param bool $count whether to return the count or not (default FALSE) |
|
602 | + * @return EE_Event[]|int |
|
603 | + * @throws \EE_Error |
|
604 | + */ |
|
605 | + public function get_expired_events($query_params, $count = false) |
|
606 | + { |
|
607 | + $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
608 | + // if we have count make sure we don't include group by |
|
609 | + if ($count && isset($query_params['group_by'])) { |
|
610 | + unset($query_params['group_by']); |
|
611 | + } |
|
612 | + // let's add specific query_params for active_events |
|
613 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
614 | + if (isset($where_params['status'])) { |
|
615 | + unset($where_params['status']); |
|
616 | + } |
|
617 | + $exclude_query = $query_params; |
|
618 | + if (isset($exclude_query[0])) { |
|
619 | + unset($exclude_query[0]); |
|
620 | + } |
|
621 | + $exclude_query[0] = array( |
|
622 | + 'Datetime.DTT_EVT_end' => array( |
|
623 | + '>', |
|
624 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
625 | + ), |
|
626 | + ); |
|
627 | + // first get all events that have datetimes where its not expired. |
|
628 | + $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID'); |
|
629 | + $event_ids = array_keys($event_ids); |
|
630 | + // if we have any additional query_params, let's add them to the 'AND' condition |
|
631 | + $and_condition = array( |
|
632 | + 'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')), |
|
633 | + 'EVT_ID' => array('NOT IN', $event_ids), |
|
634 | + ); |
|
635 | + if (isset($where_params['OR'])) { |
|
636 | + $and_condition['OR'] = $where_params['OR']; |
|
637 | + unset($where_params['OR']); |
|
638 | + } |
|
639 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
640 | + $and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
641 | + unset($where_params['Datetime.DTT_EVT_end']); |
|
642 | + } |
|
643 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
644 | + $and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
645 | + unset($where_params['Datetime.DTT_EVT_start']); |
|
646 | + } |
|
647 | + // merge remaining $where params with the and conditions. |
|
648 | + $where_params['AND'] = array_merge($and_condition, $where_params); |
|
649 | + $query_params[0] = $where_params; |
|
650 | + // don't use $query_params with count() |
|
651 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
652 | + return $count |
|
653 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
654 | + : $this->get_all($query_params); |
|
655 | + } |
|
656 | + |
|
657 | + |
|
658 | + |
|
659 | + /** |
|
660 | + * This basically just returns the events that do not have the publish status. |
|
661 | + * |
|
662 | + * @param array $query_params An array of query params to further filter on |
|
663 | + * (note that status will be overwritten) |
|
664 | + * @param boolean $count whether to return the count or not (default FALSE) |
|
665 | + * @return EE_Event[]|int |
|
666 | + * @throws \EE_Error |
|
667 | + */ |
|
668 | + public function get_inactive_events($query_params, $count = false) |
|
669 | + { |
|
670 | + $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
671 | + // let's add in specific query_params for inactive events. |
|
672 | + if (isset($where_params['status'])) { |
|
673 | + unset($where_params['status']); |
|
674 | + } |
|
675 | + // if we have count make sure we don't include group by |
|
676 | + if ($count && isset($query_params['group_by'])) { |
|
677 | + unset($query_params['group_by']); |
|
678 | + } |
|
679 | + // if we have any additional query_params, let's add them to the 'AND' condition |
|
680 | + $where_params['AND']['status'] = array('!=', 'publish'); |
|
681 | + if (isset($where_params['OR'])) { |
|
682 | + $where_params['AND']['OR'] = $where_params['OR']; |
|
683 | + unset($where_params['OR']); |
|
684 | + } |
|
685 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
686 | + $where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
687 | + unset($where_params['Datetime.DTT_EVT_end']); |
|
688 | + } |
|
689 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
690 | + $where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
691 | + unset($where_params['Datetime.DTT_EVT_start']); |
|
692 | + } |
|
693 | + $query_params[0] = $where_params; |
|
694 | + // don't use $query_params with count() |
|
695 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
696 | + return $count |
|
697 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
698 | + : $this->get_all($query_params); |
|
699 | + } |
|
700 | + |
|
701 | + |
|
702 | + |
|
703 | + /** |
|
704 | + * This is just injecting into the parent add_relationship_to so we do special handling on price relationships |
|
705 | + * because we don't want to override any existing global default prices but instead insert NEW prices that get |
|
706 | + * attached to the event. See parent for param descriptions |
|
707 | + * |
|
708 | + * @param $id_or_obj |
|
709 | + * @param $other_model_id_or_obj |
|
710 | + * @param string $relationName |
|
711 | + * @param array $where_query |
|
712 | + * @return EE_Base_Class |
|
713 | + * @throws EE_Error |
|
714 | + */ |
|
715 | + public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) |
|
716 | + { |
|
717 | + if ($relationName === 'Price') { |
|
718 | + //let's get the PRC object for the given ID to make sure that we aren't dealing with a default |
|
719 | + $prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj); |
|
720 | + //if EVT_ID = 0, then this is a default |
|
721 | + if ((int) $prc_chk->get('EVT_ID') === 0) { |
|
722 | + //let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation |
|
723 | + $prc_chk->set('PRC_ID', 0); |
|
724 | + } |
|
725 | + //run parent |
|
726 | + return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query); |
|
727 | + } |
|
728 | + //otherwise carry on as normal |
|
729 | + return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query); |
|
730 | + } |
|
731 | + |
|
732 | + |
|
733 | + |
|
734 | + /******************** DEPRECATED METHODS ********************/ |
|
735 | + |
|
736 | + |
|
737 | + |
|
738 | + /** |
|
739 | + * _get_question_target_db_column |
|
740 | + * |
|
741 | + * @deprecated as of 4.8.32.rc.001. Instead consider using |
|
742 | + * EE_Registration_Custom_Questions_Form located in |
|
743 | + * admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php |
|
744 | + * @access public |
|
745 | + * @param EE_Registration $registration (so existing answers for registration are included) |
|
746 | + * @param int $EVT_ID so all question groups are included for event (not just answers from |
|
747 | + * registration). |
|
748 | + * @throws EE_Error |
|
749 | + * @return array |
|
750 | + */ |
|
751 | + public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0) |
|
752 | + { |
|
753 | + if (empty($EVT_ID)) { |
|
754 | + throw new EE_Error(__('An error occurred. No EVT_ID is included. Needed to know which question groups to retrieve.', |
|
755 | + 'event_espresso')); |
|
756 | + } |
|
757 | + $questions = array(); |
|
758 | + // get all question groups for event |
|
759 | + $qgs = $this->get_question_groups_for_event($EVT_ID, $registration); |
|
760 | + if (! empty($qgs)) { |
|
761 | + foreach ($qgs as $qg) { |
|
762 | + $qsts = $qg->questions(); |
|
763 | + $questions[$qg->ID()] = $qg->model_field_array(); |
|
764 | + $questions[$qg->ID()]['QSG_questions'] = array(); |
|
765 | + foreach ($qsts as $qst) { |
|
766 | + if ($qst->is_system_question()) { |
|
767 | + continue; |
|
768 | + } |
|
769 | + $answer = EEM_Answer::instance()->get_one(array( |
|
770 | + array( |
|
771 | + 'QST_ID' => $qst->ID(), |
|
772 | + 'REG_ID' => $registration->ID(), |
|
773 | + ), |
|
774 | + )); |
|
775 | + $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object(); |
|
776 | + $qst_name = $qstn_id = $qst->ID(); |
|
777 | + $ans_id = $answer->ID(); |
|
778 | + $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']'; |
|
779 | + $input_name = ''; |
|
780 | + $input_id = sanitize_key($qst->display_text()); |
|
781 | + $input_class = ''; |
|
782 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()] = $qst->model_field_array(); |
|
783 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn' |
|
784 | + . $input_name |
|
785 | + . $qst_name; |
|
786 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id . '-' . $qstn_id; |
|
787 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class; |
|
788 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'] = array(); |
|
789 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj'] = $qst; |
|
790 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['ans_obj'] = $answer; |
|
791 | + //leave responses as-is, don't convert stuff into html entities please! |
|
792 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['htmlentities'] = false; |
|
793 | + if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') { |
|
794 | + $QSOs = $qst->options(true, $answer->value()); |
|
795 | + if (is_array($QSOs)) { |
|
796 | + foreach ($QSOs as $QSO_ID => $QSO) { |
|
797 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'][$QSO_ID] = $QSO->model_field_array(); |
|
798 | + } |
|
799 | + } |
|
800 | + } |
|
801 | + } |
|
802 | + } |
|
803 | + } |
|
804 | + return $questions; |
|
805 | + } |
|
806 | 806 | |
807 | 807 | |
808 | 808 | } |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | use EventEspresso\core\exceptions\InvalidEntityException; |
3 | 3 | |
4 | 4 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
5 | - exit('No direct script access allowed'); |
|
5 | + exit('No direct script access allowed'); |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | |
@@ -17,1717 +17,1717 @@ discard block |
||
17 | 17 | class EED_Single_Page_Checkout extends EED_Module |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * $_initialized - has the SPCO controller already been initialized ? |
|
22 | - * |
|
23 | - * @access private |
|
24 | - * @var bool $_initialized |
|
25 | - */ |
|
26 | - private static $_initialized = false; |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * $_checkout_verified - is the EE_Checkout verified as correct for this request ? |
|
31 | - * |
|
32 | - * @access private |
|
33 | - * @var bool $_valid_checkout |
|
34 | - */ |
|
35 | - private static $_checkout_verified = true; |
|
36 | - |
|
37 | - /** |
|
38 | - * $_reg_steps_array - holds initial array of reg steps |
|
39 | - * |
|
40 | - * @access private |
|
41 | - * @var array $_reg_steps_array |
|
42 | - */ |
|
43 | - private static $_reg_steps_array = array(); |
|
44 | - |
|
45 | - /** |
|
46 | - * $checkout - EE_Checkout object for handling the properties of the current checkout process |
|
47 | - * |
|
48 | - * @access public |
|
49 | - * @var EE_Checkout $checkout |
|
50 | - */ |
|
51 | - public $checkout; |
|
52 | - |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * @return EED_Single_Page_Checkout |
|
57 | - */ |
|
58 | - public static function instance() |
|
59 | - { |
|
60 | - add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true'); |
|
61 | - return parent::get_instance(__CLASS__); |
|
62 | - } |
|
63 | - |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * @return EE_CART |
|
68 | - */ |
|
69 | - public function cart() |
|
70 | - { |
|
71 | - return $this->checkout->cart; |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * @return EE_Transaction |
|
78 | - */ |
|
79 | - public function transaction() |
|
80 | - { |
|
81 | - return $this->checkout->transaction; |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * set_hooks - for hooking into EE Core, other modules, etc |
|
88 | - * |
|
89 | - * @access public |
|
90 | - * @return void |
|
91 | - * @throws \EE_Error |
|
92 | - */ |
|
93 | - public static function set_hooks() |
|
94 | - { |
|
95 | - EED_Single_Page_Checkout::set_definitions(); |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
102 | - * |
|
103 | - * @access public |
|
104 | - * @return void |
|
105 | - * @throws \EE_Error |
|
106 | - */ |
|
107 | - public static function set_hooks_admin() |
|
108 | - { |
|
109 | - EED_Single_Page_Checkout::set_definitions(); |
|
110 | - if ( ! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
111 | - // hook into the top of pre_get_posts to set the reg step routing, which gives other modules or plugins a chance to modify the reg steps, but just before the routes get called |
|
112 | - add_action('pre_get_posts', array('EED_Single_Page_Checkout', 'load_reg_steps'), 1); |
|
113 | - return; |
|
114 | - } |
|
115 | - // going to start an output buffer in case anything gets accidentally output that might disrupt our JSON response |
|
116 | - ob_start(); |
|
117 | - EED_Single_Page_Checkout::load_request_handler(); |
|
118 | - EED_Single_Page_Checkout::load_reg_steps(); |
|
119 | - // set ajax hooks |
|
120 | - add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
121 | - add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
122 | - add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
123 | - add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
124 | - add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
125 | - add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
126 | - } |
|
127 | - |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * process ajax request |
|
132 | - * |
|
133 | - * @param string $ajax_action |
|
134 | - * @throws \EE_Error |
|
135 | - */ |
|
136 | - public static function process_ajax_request($ajax_action) |
|
137 | - { |
|
138 | - EE_Registry::instance()->REQ->set('action', $ajax_action); |
|
139 | - EED_Single_Page_Checkout::instance()->_initialize(); |
|
140 | - } |
|
141 | - |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * ajax display registration step |
|
146 | - * |
|
147 | - * @throws \EE_Error |
|
148 | - */ |
|
149 | - public static function display_reg_step() |
|
150 | - { |
|
151 | - EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step'); |
|
152 | - } |
|
153 | - |
|
154 | - |
|
155 | - |
|
156 | - /** |
|
157 | - * ajax process registration step |
|
158 | - * |
|
159 | - * @throws \EE_Error |
|
160 | - */ |
|
161 | - public static function process_reg_step() |
|
162 | - { |
|
163 | - EED_Single_Page_Checkout::process_ajax_request('process_reg_step'); |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - |
|
168 | - /** |
|
169 | - * ajax process registration step |
|
170 | - * |
|
171 | - * @throws \EE_Error |
|
172 | - */ |
|
173 | - public static function update_reg_step() |
|
174 | - { |
|
175 | - EED_Single_Page_Checkout::process_ajax_request('update_reg_step'); |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - |
|
180 | - /** |
|
181 | - * update_checkout |
|
182 | - * |
|
183 | - * @access public |
|
184 | - * @return void |
|
185 | - * @throws \EE_Error |
|
186 | - */ |
|
187 | - public static function update_checkout() |
|
188 | - { |
|
189 | - EED_Single_Page_Checkout::process_ajax_request('update_checkout'); |
|
190 | - } |
|
191 | - |
|
192 | - |
|
193 | - |
|
194 | - /** |
|
195 | - * load_request_handler |
|
196 | - * |
|
197 | - * @access public |
|
198 | - * @return void |
|
199 | - */ |
|
200 | - public static function load_request_handler() |
|
201 | - { |
|
202 | - // load core Request_Handler class |
|
203 | - if ( ! isset(EE_Registry::instance()->REQ)) { |
|
204 | - EE_Registry::instance()->load_core('Request_Handler'); |
|
205 | - } |
|
206 | - } |
|
207 | - |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * set_definitions |
|
212 | - * |
|
213 | - * @access public |
|
214 | - * @return void |
|
215 | - * @throws \EE_Error |
|
216 | - */ |
|
217 | - public static function set_definitions() |
|
218 | - { |
|
219 | - define('SPCO_BASE_PATH', rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS); |
|
220 | - define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS); |
|
221 | - define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS); |
|
222 | - define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS); |
|
223 | - define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS); |
|
224 | - define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS); |
|
225 | - define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS); |
|
226 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true); |
|
227 | - EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf( |
|
228 | - __('%1$sWe\'re sorry, but you\'re registration time has expired.%2$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s', |
|
229 | - 'event_espresso'), |
|
230 | - '<h4 class="important-notice">', |
|
231 | - '</h4>', |
|
232 | - '<br />', |
|
233 | - '<p>', |
|
234 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
235 | - '">', |
|
236 | - '</a>', |
|
237 | - '</p>' |
|
238 | - ); |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - |
|
243 | - /** |
|
244 | - * load_reg_steps |
|
245 | - * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array |
|
246 | - * |
|
247 | - * @access private |
|
248 | - * @throws EE_Error |
|
249 | - * @return void |
|
250 | - */ |
|
251 | - public static function load_reg_steps() |
|
252 | - { |
|
253 | - static $reg_steps_loaded = false; |
|
254 | - if ($reg_steps_loaded) { |
|
255 | - return; |
|
256 | - } |
|
257 | - // filter list of reg_steps |
|
258 | - $reg_steps_to_load = (array)apply_filters( |
|
259 | - 'AHEE__SPCO__load_reg_steps__reg_steps_to_load', |
|
260 | - EED_Single_Page_Checkout::get_reg_steps() |
|
261 | - ); |
|
262 | - // sort by key (order) |
|
263 | - ksort($reg_steps_to_load); |
|
264 | - // loop through folders |
|
265 | - foreach ($reg_steps_to_load as $order => $reg_step) { |
|
266 | - // we need a |
|
267 | - if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
268 | - // copy over to the reg_steps_array |
|
269 | - EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step; |
|
270 | - // register custom key route for each reg step |
|
271 | - // ie: step=>"slug" - this is the entire reason we load the reg steps array now |
|
272 | - EE_Config::register_route($reg_step['slug'], 'EED_Single_Page_Checkout', 'run', 'step'); |
|
273 | - // add AJAX or other hooks |
|
274 | - if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) { |
|
275 | - // setup autoloaders if necessary |
|
276 | - if ( ! class_exists($reg_step['class_name'])) { |
|
277 | - EEH_Autoloader::register_autoloaders_for_each_file_in_folder($reg_step['file_path'], true); |
|
278 | - } |
|
279 | - if (is_callable($reg_step['class_name'], 'set_hooks')) { |
|
280 | - call_user_func(array($reg_step['class_name'], 'set_hooks')); |
|
281 | - } |
|
282 | - } |
|
283 | - } |
|
284 | - } |
|
285 | - $reg_steps_loaded = true; |
|
286 | - } |
|
287 | - |
|
288 | - |
|
289 | - |
|
290 | - /** |
|
291 | - * get_reg_steps |
|
292 | - * |
|
293 | - * @access public |
|
294 | - * @return array |
|
295 | - */ |
|
296 | - public static function get_reg_steps() |
|
297 | - { |
|
298 | - $reg_steps = EE_Registry::instance()->CFG->registration->reg_steps; |
|
299 | - if (empty($reg_steps)) { |
|
300 | - $reg_steps = array( |
|
301 | - 10 => array( |
|
302 | - 'file_path' => SPCO_REG_STEPS_PATH . 'attendee_information', |
|
303 | - 'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information', |
|
304 | - 'slug' => 'attendee_information', |
|
305 | - 'has_hooks' => false, |
|
306 | - ), |
|
307 | - 20 => array( |
|
308 | - 'file_path' => SPCO_REG_STEPS_PATH . 'registration_confirmation', |
|
309 | - 'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation', |
|
310 | - 'slug' => 'registration_confirmation', |
|
311 | - 'has_hooks' => false, |
|
312 | - ), |
|
313 | - 30 => array( |
|
314 | - 'file_path' => SPCO_REG_STEPS_PATH . 'payment_options', |
|
315 | - 'class_name' => 'EE_SPCO_Reg_Step_Payment_Options', |
|
316 | - 'slug' => 'payment_options', |
|
317 | - 'has_hooks' => true, |
|
318 | - ), |
|
319 | - 999 => array( |
|
320 | - 'file_path' => SPCO_REG_STEPS_PATH . 'finalize_registration', |
|
321 | - 'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration', |
|
322 | - 'slug' => 'finalize_registration', |
|
323 | - 'has_hooks' => false, |
|
324 | - ), |
|
325 | - ); |
|
326 | - } |
|
327 | - return $reg_steps; |
|
328 | - } |
|
329 | - |
|
330 | - |
|
331 | - |
|
332 | - /** |
|
333 | - * registration_checkout_for_admin |
|
334 | - * |
|
335 | - * @access public |
|
336 | - * @return string |
|
337 | - * @throws \EE_Error |
|
338 | - */ |
|
339 | - public static function registration_checkout_for_admin() |
|
340 | - { |
|
341 | - EED_Single_Page_Checkout::load_reg_steps(); |
|
342 | - EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
343 | - EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step'); |
|
344 | - EE_Registry::instance()->REQ->set('process_form_submission', false); |
|
345 | - EED_Single_Page_Checkout::instance()->_initialize(); |
|
346 | - EED_Single_Page_Checkout::instance()->_display_spco_reg_form(); |
|
347 | - return EE_Registry::instance()->REQ->get_output(); |
|
348 | - } |
|
349 | - |
|
350 | - |
|
351 | - |
|
352 | - /** |
|
353 | - * process_registration_from_admin |
|
354 | - * |
|
355 | - * @access public |
|
356 | - * @return \EE_Transaction |
|
357 | - * @throws \EE_Error |
|
358 | - */ |
|
359 | - public static function process_registration_from_admin() |
|
360 | - { |
|
361 | - EED_Single_Page_Checkout::load_reg_steps(); |
|
362 | - EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
363 | - EE_Registry::instance()->REQ->set('action', 'process_reg_step'); |
|
364 | - EE_Registry::instance()->REQ->set('process_form_submission', true); |
|
365 | - EED_Single_Page_Checkout::instance()->_initialize(); |
|
366 | - if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) { |
|
367 | - $final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps); |
|
368 | - if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) { |
|
369 | - EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step); |
|
370 | - if ($final_reg_step->process_reg_step()) { |
|
371 | - $final_reg_step->set_completed(); |
|
372 | - EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array(); |
|
373 | - return EED_Single_Page_Checkout::instance()->checkout->transaction; |
|
374 | - } |
|
375 | - } |
|
376 | - } |
|
377 | - return null; |
|
378 | - } |
|
379 | - |
|
380 | - |
|
381 | - |
|
382 | - /** |
|
383 | - * run |
|
384 | - * |
|
385 | - * @access public |
|
386 | - * @param WP_Query $WP_Query |
|
387 | - * @return void |
|
388 | - * @throws \EE_Error |
|
389 | - */ |
|
390 | - public function run($WP_Query) |
|
391 | - { |
|
392 | - if ( |
|
393 | - $WP_Query instanceof WP_Query |
|
394 | - && $WP_Query->is_main_query() |
|
395 | - && apply_filters('FHEE__EED_Single_Page_Checkout__run', true) |
|
396 | - && $this->_is_reg_checkout() |
|
397 | - ) { |
|
398 | - $this->_initialize(); |
|
399 | - } |
|
400 | - } |
|
401 | - |
|
402 | - |
|
403 | - |
|
404 | - /** |
|
405 | - * determines whether current url matches reg page url |
|
406 | - * |
|
407 | - * @return bool |
|
408 | - */ |
|
409 | - protected function _is_reg_checkout() |
|
410 | - { |
|
411 | - // get current permalink for reg page without any extra query args |
|
412 | - $reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id); |
|
413 | - // get request URI for current request, but without the scheme or host |
|
414 | - $current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI'); |
|
415 | - $current_request_uri = html_entity_decode($current_request_uri); |
|
416 | - // get array of query args from the current request URI |
|
417 | - $query_args = \EEH_URL::get_query_string($current_request_uri); |
|
418 | - // grab page id if it is set |
|
419 | - $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0; |
|
420 | - // and remove the page id from the query args (we will re-add it later) |
|
421 | - unset($query_args['page_id']); |
|
422 | - // now strip all query args from current request URI |
|
423 | - $current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri); |
|
424 | - // and re-add the page id if it was set |
|
425 | - if ($page_id) { |
|
426 | - $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri); |
|
427 | - } |
|
428 | - // remove slashes and ? |
|
429 | - $current_request_uri = trim($current_request_uri, '?/'); |
|
430 | - // is current request URI part of the known full reg page URL ? |
|
431 | - return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false; |
|
432 | - } |
|
433 | - |
|
434 | - |
|
435 | - |
|
436 | - /** |
|
437 | - * run |
|
438 | - * |
|
439 | - * @access public |
|
440 | - * @param WP_Query $WP_Query |
|
441 | - * @return void |
|
442 | - * @throws \EE_Error |
|
443 | - */ |
|
444 | - public static function init($WP_Query) |
|
445 | - { |
|
446 | - EED_Single_Page_Checkout::instance()->run($WP_Query); |
|
447 | - } |
|
448 | - |
|
449 | - |
|
450 | - |
|
451 | - /** |
|
452 | - * _initialize - initial module setup |
|
453 | - * |
|
454 | - * @access private |
|
455 | - * @throws EE_Error |
|
456 | - * @return void |
|
457 | - */ |
|
458 | - private function _initialize() |
|
459 | - { |
|
460 | - // ensure SPCO doesn't run twice |
|
461 | - if (EED_Single_Page_Checkout::$_initialized) { |
|
462 | - return; |
|
463 | - } |
|
464 | - try { |
|
465 | - $this->_verify_session(); |
|
466 | - // setup the EE_Checkout object |
|
467 | - $this->checkout = $this->_initialize_checkout(); |
|
468 | - // filter checkout |
|
469 | - $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout); |
|
470 | - // get the $_GET |
|
471 | - $this->_get_request_vars(); |
|
472 | - if ($this->_block_bots()) { |
|
473 | - return; |
|
474 | - } |
|
475 | - // filter continue_reg |
|
476 | - $this->checkout->continue_reg = apply_filters('FHEE__EED_Single_Page_Checkout__init___continue_reg', true, $this->checkout); |
|
477 | - // load the reg steps array |
|
478 | - if ( ! $this->_load_and_instantiate_reg_steps()) { |
|
479 | - EED_Single_Page_Checkout::$_initialized = true; |
|
480 | - return; |
|
481 | - } |
|
482 | - // set the current step |
|
483 | - $this->checkout->set_current_step($this->checkout->step); |
|
484 | - // and the next step |
|
485 | - $this->checkout->set_next_step(); |
|
486 | - // verify that everything has been setup correctly |
|
487 | - if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) { |
|
488 | - EED_Single_Page_Checkout::$_initialized = true; |
|
489 | - return; |
|
490 | - } |
|
491 | - // lock the transaction |
|
492 | - $this->checkout->transaction->lock(); |
|
493 | - // make sure all of our cached objects are added to their respective model entity mappers |
|
494 | - $this->checkout->refresh_all_entities(); |
|
495 | - // set amount owing |
|
496 | - $this->checkout->amount_owing = $this->checkout->transaction->remaining(); |
|
497 | - // initialize each reg step, which gives them the chance to potentially alter the process |
|
498 | - $this->_initialize_reg_steps(); |
|
499 | - // DEBUG LOG |
|
500 | - //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
501 | - // get reg form |
|
502 | - if( ! $this->_check_form_submission()) { |
|
503 | - EED_Single_Page_Checkout::$_initialized = true; |
|
504 | - return; |
|
505 | - } |
|
506 | - // checkout the action!!! |
|
507 | - $this->_process_form_action(); |
|
508 | - // add some style and make it dance |
|
509 | - $this->add_styles_and_scripts(); |
|
510 | - // kk... SPCO has successfully run |
|
511 | - EED_Single_Page_Checkout::$_initialized = true; |
|
512 | - // set no cache headers and constants |
|
513 | - EE_System::do_not_cache(); |
|
514 | - // add anchor |
|
515 | - add_action('loop_start', array($this, 'set_checkout_anchor'), 1); |
|
516 | - // remove transaction lock |
|
517 | - add_action('shutdown', array($this, 'unlock_transaction'), 1); |
|
518 | - } catch (Exception $e) { |
|
519 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
520 | - } |
|
521 | - } |
|
522 | - |
|
523 | - |
|
524 | - |
|
525 | - /** |
|
526 | - * _verify_session |
|
527 | - * checks that the session is valid and not expired |
|
528 | - * |
|
529 | - * @access private |
|
530 | - * @throws EE_Error |
|
531 | - */ |
|
532 | - private function _verify_session() |
|
533 | - { |
|
534 | - if ( ! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
535 | - throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso')); |
|
536 | - } |
|
537 | - // is session still valid ? |
|
538 | - if (EE_Registry::instance()->SSN->expired() && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === '') { |
|
539 | - $this->checkout = new EE_Checkout(); |
|
540 | - EE_Registry::instance()->SSN->reset_cart(); |
|
541 | - EE_Registry::instance()->SSN->reset_checkout(); |
|
542 | - EE_Registry::instance()->SSN->reset_transaction(); |
|
543 | - EE_Error::add_attention(EE_Registry::$i18n_js_strings['registration_expiration_notice'], __FILE__, |
|
544 | - __FUNCTION__, __LINE__); |
|
545 | - EE_Registry::instance()->SSN->reset_expired(); |
|
546 | - } |
|
547 | - } |
|
548 | - |
|
549 | - |
|
550 | - |
|
551 | - /** |
|
552 | - * _initialize_checkout |
|
553 | - * loads and instantiates EE_Checkout |
|
554 | - * |
|
555 | - * @access private |
|
556 | - * @throws EE_Error |
|
557 | - * @return EE_Checkout |
|
558 | - */ |
|
559 | - private function _initialize_checkout() |
|
560 | - { |
|
561 | - // look in session for existing checkout |
|
562 | - /** @type EE_Checkout $checkout */ |
|
563 | - $checkout = EE_Registry::instance()->SSN->checkout(); |
|
564 | - // verify |
|
565 | - if ( ! $checkout instanceof EE_Checkout) { |
|
566 | - // instantiate EE_Checkout object for handling the properties of the current checkout process |
|
567 | - $checkout = EE_Registry::instance()->load_file(SPCO_INC_PATH, 'EE_Checkout', 'class', array(), false); |
|
568 | - } else { |
|
569 | - if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) { |
|
570 | - $this->unlock_transaction(); |
|
571 | - wp_safe_redirect($checkout->redirect_url); |
|
572 | - exit(); |
|
573 | - } |
|
574 | - } |
|
575 | - $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout); |
|
576 | - // verify again |
|
577 | - if ( ! $checkout instanceof EE_Checkout) { |
|
578 | - throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso')); |
|
579 | - } |
|
580 | - // reset anything that needs a clean slate for each request |
|
581 | - $checkout->reset_for_current_request(); |
|
582 | - return $checkout; |
|
583 | - } |
|
584 | - |
|
585 | - |
|
586 | - |
|
587 | - /** |
|
588 | - * _get_request_vars |
|
589 | - * |
|
590 | - * @access private |
|
591 | - * @return void |
|
592 | - * @throws \EE_Error |
|
593 | - */ |
|
594 | - private function _get_request_vars() |
|
595 | - { |
|
596 | - // load classes |
|
597 | - EED_Single_Page_Checkout::load_request_handler(); |
|
598 | - //make sure this request is marked as belonging to EE |
|
599 | - EE_Registry::instance()->REQ->set_espresso_page(true); |
|
600 | - // which step is being requested ? |
|
601 | - $this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step()); |
|
602 | - // which step is being edited ? |
|
603 | - $this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', ''); |
|
604 | - // and what we're doing on the current step |
|
605 | - $this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step'); |
|
606 | - // timestamp |
|
607 | - $this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0); |
|
608 | - // returning to edit ? |
|
609 | - $this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', ''); |
|
610 | - // or some other kind of revisit ? |
|
611 | - $this->checkout->revisit = filter_var( |
|
612 | - EE_Registry::instance()->REQ->get('revisit', false), |
|
613 | - FILTER_VALIDATE_BOOLEAN |
|
614 | - ); |
|
615 | - // and whether or not to generate a reg form for this request |
|
616 | - $this->checkout->generate_reg_form = filter_var( |
|
617 | - EE_Registry::instance()->REQ->get('generate_reg_form', true), |
|
618 | - FILTER_VALIDATE_BOOLEAN |
|
619 | - ); |
|
620 | - // and whether or not to process a reg form submission for this request |
|
621 | - $this->checkout->process_form_submission = filter_var( |
|
622 | - EE_Registry::instance()->REQ->get( |
|
623 | - 'process_form_submission', |
|
624 | - $this->checkout->action === 'process_reg_step' |
|
625 | - ), |
|
626 | - FILTER_VALIDATE_BOOLEAN |
|
627 | - ); |
|
628 | - $this->checkout->process_form_submission = filter_var( |
|
629 | - $this->checkout->action !== 'display_spco_reg_step' |
|
630 | - ? $this->checkout->process_form_submission |
|
631 | - : false, |
|
632 | - FILTER_VALIDATE_BOOLEAN |
|
633 | - ); |
|
634 | - // $this->_display_request_vars(); |
|
635 | - } |
|
636 | - |
|
637 | - |
|
638 | - |
|
639 | - /** |
|
640 | - * _display_request_vars |
|
641 | - * |
|
642 | - * @access protected |
|
643 | - * @return void |
|
644 | - */ |
|
645 | - protected function _display_request_vars() |
|
646 | - { |
|
647 | - if ( ! WP_DEBUG) { |
|
648 | - return; |
|
649 | - } |
|
650 | - EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__); |
|
651 | - EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__); |
|
652 | - EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__); |
|
653 | - EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__); |
|
654 | - EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__); |
|
655 | - EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__); |
|
656 | - EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__); |
|
657 | - EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__); |
|
658 | - } |
|
659 | - |
|
660 | - |
|
661 | - |
|
662 | - /** |
|
663 | - * _block_bots |
|
664 | - * checks that the incoming request has either of the following set: |
|
665 | - * a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector |
|
666 | - * a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN |
|
667 | - * so if you're not coming from the Ticket Selector nor returning for a valid IP... |
|
668 | - * then where you coming from man? |
|
669 | - * |
|
670 | - * @return boolean |
|
671 | - */ |
|
672 | - private function _block_bots() |
|
673 | - { |
|
674 | - $invalid_checkout_access = \EED_Invalid_Checkout_Access::getInvalidCheckoutAccess(); |
|
675 | - if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) { |
|
676 | - return true; |
|
677 | - } |
|
678 | - return false; |
|
679 | - } |
|
680 | - |
|
681 | - |
|
682 | - |
|
683 | - /** |
|
684 | - * _get_first_step |
|
685 | - * gets slug for first step in $_reg_steps_array |
|
686 | - * |
|
687 | - * @access private |
|
688 | - * @throws EE_Error |
|
689 | - * @return string |
|
690 | - */ |
|
691 | - private function _get_first_step() |
|
692 | - { |
|
693 | - $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array); |
|
694 | - return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information'; |
|
695 | - } |
|
696 | - |
|
697 | - |
|
698 | - |
|
699 | - /** |
|
700 | - * _load_and_instantiate_reg_steps |
|
701 | - * instantiates each reg step based on the loaded reg_steps array |
|
702 | - * |
|
703 | - * @access private |
|
704 | - * @throws EE_Error |
|
705 | - * @return bool |
|
706 | - */ |
|
707 | - private function _load_and_instantiate_reg_steps() |
|
708 | - { |
|
709 | - do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout); |
|
710 | - // have reg_steps already been instantiated ? |
|
711 | - if ( |
|
712 | - empty($this->checkout->reg_steps) |
|
713 | - || apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout) |
|
714 | - ) { |
|
715 | - // if not, then loop through raw reg steps array |
|
716 | - foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) { |
|
717 | - if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) { |
|
718 | - return false; |
|
719 | - } |
|
720 | - } |
|
721 | - EE_Registry::instance()->CFG->registration->skip_reg_confirmation = true; |
|
722 | - EE_Registry::instance()->CFG->registration->reg_confirmation_last = true; |
|
723 | - // skip the registration_confirmation page ? |
|
724 | - if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) { |
|
725 | - // just remove it from the reg steps array |
|
726 | - $this->checkout->remove_reg_step('registration_confirmation', false); |
|
727 | - } else if ( |
|
728 | - isset($this->checkout->reg_steps['registration_confirmation']) |
|
729 | - && EE_Registry::instance()->CFG->registration->reg_confirmation_last |
|
730 | - ) { |
|
731 | - // set the order to something big like 100 |
|
732 | - $this->checkout->set_reg_step_order('registration_confirmation', 100); |
|
733 | - } |
|
734 | - // filter the array for good luck |
|
735 | - $this->checkout->reg_steps = apply_filters( |
|
736 | - 'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps', |
|
737 | - $this->checkout->reg_steps |
|
738 | - ); |
|
739 | - // finally re-sort based on the reg step class order properties |
|
740 | - $this->checkout->sort_reg_steps(); |
|
741 | - } else { |
|
742 | - foreach ($this->checkout->reg_steps as $reg_step) { |
|
743 | - // set all current step stati to FALSE |
|
744 | - $reg_step->set_is_current_step(false); |
|
745 | - } |
|
746 | - } |
|
747 | - if (empty($this->checkout->reg_steps)) { |
|
748 | - EE_Error::add_error(__('No Reg Steps were loaded..', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
749 | - return false; |
|
750 | - } |
|
751 | - // make reg step details available to JS |
|
752 | - $this->checkout->set_reg_step_JSON_info(); |
|
753 | - return true; |
|
754 | - } |
|
755 | - |
|
756 | - |
|
757 | - |
|
758 | - /** |
|
759 | - * _load_and_instantiate_reg_step |
|
760 | - * |
|
761 | - * @access private |
|
762 | - * @param array $reg_step |
|
763 | - * @param int $order |
|
764 | - * @return bool |
|
765 | - */ |
|
766 | - private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0) |
|
767 | - { |
|
768 | - // we need a file_path, class_name, and slug to add a reg step |
|
769 | - if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
770 | - // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step) |
|
771 | - if ( |
|
772 | - $this->checkout->reg_url_link |
|
773 | - && $this->checkout->step !== $reg_step['slug'] |
|
774 | - && $reg_step['slug'] !== 'finalize_registration' |
|
775 | - // normally at this point we would NOT load the reg step, but this filter can change that |
|
776 | - && apply_filters( |
|
777 | - 'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step', |
|
778 | - true, |
|
779 | - $reg_step, |
|
780 | - $this->checkout |
|
781 | - ) |
|
782 | - ) { |
|
783 | - return true; |
|
784 | - } |
|
785 | - // instantiate step class using file path and class name |
|
786 | - $reg_step_obj = EE_Registry::instance()->load_file( |
|
787 | - $reg_step['file_path'], |
|
788 | - $reg_step['class_name'], |
|
789 | - 'class', |
|
790 | - $this->checkout, |
|
791 | - false |
|
792 | - ); |
|
793 | - // did we gets the goods ? |
|
794 | - if ($reg_step_obj instanceof EE_SPCO_Reg_Step) { |
|
795 | - // set reg step order based on config |
|
796 | - $reg_step_obj->set_order($order); |
|
797 | - // add instantiated reg step object to the master reg steps array |
|
798 | - $this->checkout->add_reg_step($reg_step_obj); |
|
799 | - } else { |
|
800 | - EE_Error::add_error( |
|
801 | - __('The current step could not be set.', 'event_espresso'), |
|
802 | - __FILE__, __FUNCTION__, __LINE__ |
|
803 | - ); |
|
804 | - return false; |
|
805 | - } |
|
806 | - } else { |
|
807 | - if (WP_DEBUG) { |
|
808 | - EE_Error::add_error( |
|
809 | - sprintf( |
|
810 | - __('A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s', 'event_espresso'), |
|
811 | - isset($reg_step['file_path']) ? $reg_step['file_path'] : '', |
|
812 | - isset($reg_step['class_name']) ? $reg_step['class_name'] : '', |
|
813 | - isset($reg_step['slug']) ? $reg_step['slug'] : '', |
|
814 | - '<ul>', |
|
815 | - '<li>', |
|
816 | - '</li>', |
|
817 | - '</ul>' |
|
818 | - ), |
|
819 | - __FILE__, __FUNCTION__, __LINE__ |
|
820 | - ); |
|
821 | - } |
|
822 | - return false; |
|
823 | - } |
|
824 | - return true; |
|
825 | - } |
|
826 | - |
|
827 | - |
|
828 | - |
|
829 | - /** |
|
830 | - * _verify_transaction_and_get_registrations |
|
831 | - * |
|
832 | - * @access private |
|
833 | - * @return bool |
|
834 | - */ |
|
835 | - private function _verify_transaction_and_get_registrations() |
|
836 | - { |
|
837 | - // was there already a valid transaction in the checkout from the session ? |
|
838 | - if ( ! $this->checkout->transaction instanceof EE_Transaction) { |
|
839 | - // get transaction from db or session |
|
840 | - $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin() |
|
841 | - ? $this->_get_transaction_and_cart_for_previous_visit() |
|
842 | - : $this->_get_cart_for_current_session_and_setup_new_transaction(); |
|
843 | - if ( ! $this->checkout->transaction instanceof EE_Transaction) { |
|
844 | - EE_Error::add_error( |
|
845 | - __('Your Registration and Transaction information could not be retrieved from the db.', |
|
846 | - 'event_espresso'), |
|
847 | - __FILE__, __FUNCTION__, __LINE__ |
|
848 | - ); |
|
849 | - $this->checkout->transaction = EE_Transaction::new_instance(); |
|
850 | - // add some style and make it dance |
|
851 | - $this->add_styles_and_scripts(); |
|
852 | - EED_Single_Page_Checkout::$_initialized = true; |
|
853 | - return false; |
|
854 | - } |
|
855 | - // and the registrations for the transaction |
|
856 | - $this->_get_registrations($this->checkout->transaction); |
|
857 | - } |
|
858 | - return true; |
|
859 | - } |
|
860 | - |
|
861 | - |
|
862 | - |
|
863 | - /** |
|
864 | - * _get_transaction_and_cart_for_previous_visit |
|
865 | - * |
|
866 | - * @access private |
|
867 | - * @return mixed EE_Transaction|NULL |
|
868 | - */ |
|
869 | - private function _get_transaction_and_cart_for_previous_visit() |
|
870 | - { |
|
871 | - /** @var $TXN_model EEM_Transaction */ |
|
872 | - $TXN_model = EE_Registry::instance()->load_model('Transaction'); |
|
873 | - // because the reg_url_link is present in the request, this is a return visit to SPCO, so we'll get the transaction data from the db |
|
874 | - $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link); |
|
875 | - // verify transaction |
|
876 | - if ($transaction instanceof EE_Transaction) { |
|
877 | - // and get the cart that was used for that transaction |
|
878 | - $this->checkout->cart = $this->_get_cart_for_transaction($transaction); |
|
879 | - return $transaction; |
|
880 | - } else { |
|
881 | - EE_Error::add_error(__('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
882 | - return null; |
|
883 | - } |
|
884 | - } |
|
885 | - |
|
886 | - |
|
887 | - |
|
888 | - /** |
|
889 | - * _get_cart_for_transaction |
|
890 | - * |
|
891 | - * @access private |
|
892 | - * @param EE_Transaction $transaction |
|
893 | - * @return EE_Cart |
|
894 | - */ |
|
895 | - private function _get_cart_for_transaction($transaction) |
|
896 | - { |
|
897 | - return $this->checkout->get_cart_for_transaction($transaction); |
|
898 | - } |
|
899 | - |
|
900 | - |
|
901 | - |
|
902 | - /** |
|
903 | - * get_cart_for_transaction |
|
904 | - * |
|
905 | - * @access public |
|
906 | - * @param EE_Transaction $transaction |
|
907 | - * @return EE_Cart |
|
908 | - */ |
|
909 | - public function get_cart_for_transaction(EE_Transaction $transaction) |
|
910 | - { |
|
911 | - return $this->checkout->get_cart_for_transaction($transaction); |
|
912 | - } |
|
913 | - |
|
914 | - |
|
915 | - |
|
916 | - /** |
|
917 | - * _get_transaction_and_cart_for_current_session |
|
918 | - * generates a new EE_Transaction object and adds it to the $_transaction property. |
|
919 | - * |
|
920 | - * @access private |
|
921 | - * @return EE_Transaction |
|
922 | - * @throws \EE_Error |
|
923 | - */ |
|
924 | - private function _get_cart_for_current_session_and_setup_new_transaction() |
|
925 | - { |
|
926 | - // if there's no transaction, then this is the FIRST visit to SPCO |
|
927 | - // so load up the cart ( passing nothing for the TXN because it doesn't exist yet ) |
|
928 | - $this->checkout->cart = $this->_get_cart_for_transaction(null); |
|
929 | - // and then create a new transaction |
|
930 | - $transaction = $this->_initialize_transaction(); |
|
931 | - // verify transaction |
|
932 | - if ($transaction instanceof EE_Transaction) { |
|
933 | - // save it so that we have an ID for other objects to use |
|
934 | - $transaction->save(); |
|
935 | - // and save TXN data to the cart |
|
936 | - $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID()); |
|
937 | - } else { |
|
938 | - EE_Error::add_error(__('A Valid Transaction could not be initialized.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
939 | - } |
|
940 | - return $transaction; |
|
941 | - } |
|
942 | - |
|
943 | - |
|
944 | - |
|
945 | - /** |
|
946 | - * generates a new EE_Transaction object and adds it to the $_transaction property. |
|
947 | - * |
|
948 | - * @access private |
|
949 | - * @return mixed EE_Transaction|NULL |
|
950 | - */ |
|
951 | - private function _initialize_transaction() |
|
952 | - { |
|
953 | - try { |
|
954 | - // ensure cart totals have been calculated |
|
955 | - $this->checkout->cart->get_grand_total()->recalculate_total_including_taxes(); |
|
956 | - // grab the cart grand total |
|
957 | - $cart_total = $this->checkout->cart->get_cart_grand_total(); |
|
958 | - // create new TXN |
|
959 | - $transaction = EE_Transaction::new_instance( |
|
960 | - array( |
|
961 | - 'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(), |
|
962 | - 'TXN_total' => $cart_total > 0 ? $cart_total : 0, |
|
963 | - 'TXN_paid' => 0, |
|
964 | - 'STS_ID' => EEM_Transaction::failed_status_code, |
|
965 | - ) |
|
966 | - ); |
|
967 | - // save it so that we have an ID for other objects to use |
|
968 | - $transaction->save(); |
|
969 | - // set cron job for following up on TXNs after their session has expired |
|
970 | - EE_Cron_Tasks::schedule_expired_transaction_check( |
|
971 | - EE_Registry::instance()->SSN->expiration() + 1, |
|
972 | - $transaction->ID() |
|
973 | - ); |
|
974 | - return $transaction; |
|
975 | - } catch (Exception $e) { |
|
976 | - EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
977 | - } |
|
978 | - return null; |
|
979 | - } |
|
980 | - |
|
981 | - |
|
982 | - |
|
983 | - /** |
|
984 | - * _get_registrations |
|
985 | - * |
|
986 | - * @access private |
|
987 | - * @param EE_Transaction $transaction |
|
988 | - * @return void |
|
989 | - * @throws \EventEspresso\core\exceptions\InvalidEntityException |
|
990 | - * @throws \EE_Error |
|
991 | - */ |
|
992 | - private function _get_registrations(EE_Transaction $transaction) |
|
993 | - { |
|
994 | - // first step: grab the registrants { : o |
|
995 | - $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, true); |
|
996 | - // verify registrations have been set |
|
997 | - if (empty($registrations)) { |
|
998 | - // if no cached registrations, then check the db |
|
999 | - $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false); |
|
1000 | - // still nothing ? well as long as this isn't a revisit |
|
1001 | - if (empty($registrations) && ! $this->checkout->revisit) { |
|
1002 | - // generate new registrations from scratch |
|
1003 | - $registrations = $this->_initialize_registrations($transaction); |
|
1004 | - } |
|
1005 | - } |
|
1006 | - // sort by their original registration order |
|
1007 | - usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count')); |
|
1008 | - // then loop thru the array |
|
1009 | - foreach ($registrations as $registration) { |
|
1010 | - // verify each registration |
|
1011 | - if ($registration instanceof EE_Registration) { |
|
1012 | - // we display all attendee info for the primary registrant |
|
1013 | - if ($this->checkout->reg_url_link === $registration->reg_url_link() |
|
1014 | - && $registration->is_primary_registrant() |
|
1015 | - ) { |
|
1016 | - $this->checkout->primary_revisit = true; |
|
1017 | - break; |
|
1018 | - } else if ($this->checkout->revisit |
|
1019 | - && $this->checkout->reg_url_link !== $registration->reg_url_link() |
|
1020 | - ) { |
|
1021 | - // but hide info if it doesn't belong to you |
|
1022 | - $transaction->clear_cache('Registration', $registration->ID()); |
|
1023 | - } |
|
1024 | - $this->checkout->set_reg_status_updated($registration->ID(), false); |
|
1025 | - } |
|
1026 | - } |
|
1027 | - } |
|
1028 | - |
|
1029 | - |
|
1030 | - |
|
1031 | - /** |
|
1032 | - * adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object |
|
1033 | - * |
|
1034 | - * @access private |
|
1035 | - * @param EE_Transaction $transaction |
|
1036 | - * @return array |
|
1037 | - * @throws \EventEspresso\core\exceptions\InvalidEntityException |
|
1038 | - * @throws \EE_Error |
|
1039 | - */ |
|
1040 | - private function _initialize_registrations(EE_Transaction $transaction) |
|
1041 | - { |
|
1042 | - $att_nmbr = 0; |
|
1043 | - $registrations = array(); |
|
1044 | - if ($transaction instanceof EE_Transaction) { |
|
1045 | - /** @type EE_Registration_Processor $registration_processor */ |
|
1046 | - $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
1047 | - $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count(); |
|
1048 | - // now let's add the cart items to the $transaction |
|
1049 | - foreach ($this->checkout->cart->get_tickets() as $line_item) { |
|
1050 | - //do the following for each ticket of this type they selected |
|
1051 | - for ($x = 1; $x <= $line_item->quantity(); $x++) { |
|
1052 | - $att_nmbr++; |
|
1053 | - /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */ |
|
1054 | - $CreateRegistrationCommand = EE_Registry::instance() |
|
1055 | - ->create( |
|
1056 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
1057 | - array( |
|
1058 | - $transaction, |
|
1059 | - $line_item, |
|
1060 | - $att_nmbr, |
|
1061 | - $this->checkout->total_ticket_count, |
|
1062 | - ) |
|
1063 | - ); |
|
1064 | - // override capabilities for frontend registrations |
|
1065 | - if ( ! is_admin()) { |
|
1066 | - $CreateRegistrationCommand->setCapCheck( |
|
1067 | - new PublicCapabilities('', 'create_new_registration') |
|
1068 | - ); |
|
1069 | - } |
|
1070 | - $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand); |
|
1071 | - if ( ! $registration instanceof EE_Registration) { |
|
1072 | - throw new InvalidEntityException($registration, 'EE_Registration'); |
|
1073 | - } |
|
1074 | - $registrations[ $registration->ID() ] = $registration; |
|
1075 | - } |
|
1076 | - } |
|
1077 | - $registration_processor->fix_reg_final_price_rounding_issue($transaction); |
|
1078 | - } |
|
1079 | - return $registrations; |
|
1080 | - } |
|
1081 | - |
|
1082 | - |
|
1083 | - |
|
1084 | - /** |
|
1085 | - * sorts registrations by REG_count |
|
1086 | - * |
|
1087 | - * @access public |
|
1088 | - * @param EE_Registration $reg_A |
|
1089 | - * @param EE_Registration $reg_B |
|
1090 | - * @return int |
|
1091 | - */ |
|
1092 | - public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B) |
|
1093 | - { |
|
1094 | - // this shouldn't ever happen within the same TXN, but oh well |
|
1095 | - if ($reg_A->count() === $reg_B->count()) { |
|
1096 | - return 0; |
|
1097 | - } |
|
1098 | - return ($reg_A->count() > $reg_B->count()) ? 1 : -1; |
|
1099 | - } |
|
1100 | - |
|
1101 | - |
|
1102 | - |
|
1103 | - /** |
|
1104 | - * _final_verifications |
|
1105 | - * just makes sure that everything is set up correctly before proceeding |
|
1106 | - * |
|
1107 | - * @access private |
|
1108 | - * @return bool |
|
1109 | - * @throws \EE_Error |
|
1110 | - */ |
|
1111 | - private function _final_verifications() |
|
1112 | - { |
|
1113 | - // filter checkout |
|
1114 | - $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___final_verifications__checkout', $this->checkout); |
|
1115 | - //verify that current step is still set correctly |
|
1116 | - if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) { |
|
1117 | - EE_Error::add_error( |
|
1118 | - __('We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', 'event_espresso'), |
|
1119 | - __FILE__, |
|
1120 | - __FUNCTION__, |
|
1121 | - __LINE__ |
|
1122 | - ); |
|
1123 | - return false; |
|
1124 | - } |
|
1125 | - // if returning to SPCO, then verify that primary registrant is set |
|
1126 | - if ( ! empty($this->checkout->reg_url_link)) { |
|
1127 | - $valid_registrant = $this->checkout->transaction->primary_registration(); |
|
1128 | - if ( ! $valid_registrant instanceof EE_Registration) { |
|
1129 | - EE_Error::add_error( |
|
1130 | - __('We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', 'event_espresso'), |
|
1131 | - __FILE__, |
|
1132 | - __FUNCTION__, |
|
1133 | - __LINE__ |
|
1134 | - ); |
|
1135 | - return false; |
|
1136 | - } |
|
1137 | - $valid_registrant = null; |
|
1138 | - foreach ($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration) { |
|
1139 | - if ( |
|
1140 | - $registration instanceof EE_Registration |
|
1141 | - && $registration->reg_url_link() === $this->checkout->reg_url_link |
|
1142 | - ) { |
|
1143 | - $valid_registrant = $registration; |
|
1144 | - } |
|
1145 | - } |
|
1146 | - if ( ! $valid_registrant instanceof EE_Registration) { |
|
1147 | - // hmmm... maybe we have the wrong session because the user is opening multiple tabs ? |
|
1148 | - if (EED_Single_Page_Checkout::$_checkout_verified) { |
|
1149 | - // clear the session, mark the checkout as unverified, and try again |
|
1150 | - EE_Registry::instance()->SSN->clear_session(); |
|
1151 | - EED_Single_Page_Checkout::$_initialized = false; |
|
1152 | - EED_Single_Page_Checkout::$_checkout_verified = false; |
|
1153 | - $this->_initialize(); |
|
1154 | - EE_Error::reset_notices(); |
|
1155 | - return false; |
|
1156 | - } |
|
1157 | - EE_Error::add_error( |
|
1158 | - __('We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.', 'event_espresso'), |
|
1159 | - __FILE__, |
|
1160 | - __FUNCTION__, |
|
1161 | - __LINE__ |
|
1162 | - ); |
|
1163 | - return false; |
|
1164 | - } |
|
1165 | - } |
|
1166 | - // now that things have been kinda sufficiently verified, |
|
1167 | - // let's add the checkout to the session so that's available other systems |
|
1168 | - EE_Registry::instance()->SSN->set_checkout($this->checkout); |
|
1169 | - return true; |
|
1170 | - } |
|
1171 | - |
|
1172 | - |
|
1173 | - |
|
1174 | - /** |
|
1175 | - * _initialize_reg_steps |
|
1176 | - * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required |
|
1177 | - * then loops thru all of the active reg steps and calls the initialize_reg_step() method |
|
1178 | - * |
|
1179 | - * @access private |
|
1180 | - * @param bool $reinitializing |
|
1181 | - * @throws \EE_Error |
|
1182 | - */ |
|
1183 | - private function _initialize_reg_steps($reinitializing = false) |
|
1184 | - { |
|
1185 | - $this->checkout->set_reg_step_initiated($this->checkout->current_step); |
|
1186 | - // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS |
|
1187 | - foreach ($this->checkout->reg_steps as $reg_step) { |
|
1188 | - if ( ! $reg_step->initialize_reg_step()) { |
|
1189 | - // if not initialized then maybe this step is being removed... |
|
1190 | - if ( ! $reinitializing && $reg_step->is_current_step()) { |
|
1191 | - // if it was the current step, then we need to start over here |
|
1192 | - $this->_initialize_reg_steps(true); |
|
1193 | - return; |
|
1194 | - } |
|
1195 | - continue; |
|
1196 | - } |
|
1197 | - // add css and JS for current step |
|
1198 | - $reg_step->enqueue_styles_and_scripts(); |
|
1199 | - // i18n |
|
1200 | - $reg_step->translate_js_strings(); |
|
1201 | - if ($reg_step->is_current_step()) { |
|
1202 | - // the text that appears on the reg step form submit button |
|
1203 | - $reg_step->set_submit_button_text(); |
|
1204 | - } |
|
1205 | - } |
|
1206 | - // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information |
|
1207 | - do_action("AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}", $this->checkout->current_step); |
|
1208 | - } |
|
1209 | - |
|
1210 | - |
|
1211 | - |
|
1212 | - /** |
|
1213 | - * _check_form_submission |
|
1214 | - * |
|
1215 | - * @access private |
|
1216 | - * @return boolean |
|
1217 | - */ |
|
1218 | - private function _check_form_submission() |
|
1219 | - { |
|
1220 | - //does this request require the reg form to be generated ? |
|
1221 | - if ($this->checkout->generate_reg_form) { |
|
1222 | - // ever heard that song by Blue Rodeo ? |
|
1223 | - try { |
|
1224 | - $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form(); |
|
1225 | - // if not displaying a form, then check for form submission |
|
1226 | - if ( |
|
1227 | - $this->checkout->process_form_submission |
|
1228 | - && $this->checkout->current_step->reg_form->was_submitted() |
|
1229 | - ) { |
|
1230 | - // clear out any old data in case this step is being run again |
|
1231 | - $this->checkout->current_step->set_valid_data(array()); |
|
1232 | - // capture submitted form data |
|
1233 | - $this->checkout->current_step->reg_form->receive_form_submission( |
|
1234 | - apply_filters('FHEE__Single_Page_Checkout___check_form_submission__request_params', EE_Registry::instance()->REQ->params(), $this->checkout) |
|
1235 | - ); |
|
1236 | - // validate submitted form data |
|
1237 | - if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) { |
|
1238 | - // thou shall not pass !!! |
|
1239 | - $this->checkout->continue_reg = false; |
|
1240 | - // any form validation errors? |
|
1241 | - if ($this->checkout->current_step->reg_form->submission_error_message() !== '') { |
|
1242 | - $submission_error_messages = array(); |
|
1243 | - // bad, bad, bad registrant |
|
1244 | - foreach ($this->checkout->current_step->reg_form->get_validation_errors_accumulated() as $validation_error) { |
|
1245 | - if ($validation_error instanceof EE_Validation_Error) { |
|
1246 | - $submission_error_messages[] = sprintf( |
|
1247 | - __('%s : %s', 'event_espresso'), |
|
1248 | - $validation_error->get_form_section()->html_label_text(), |
|
1249 | - $validation_error->getMessage() |
|
1250 | - ); |
|
1251 | - } |
|
1252 | - } |
|
1253 | - EE_Error::add_error(implode('<br />', $submission_error_messages), __FILE__, __FUNCTION__, __LINE__); |
|
1254 | - } |
|
1255 | - // well not really... what will happen is we'll just get redirected back to redo the current step |
|
1256 | - $this->go_to_next_step(); |
|
1257 | - return false; |
|
1258 | - } |
|
1259 | - } |
|
1260 | - } catch (EE_Error $e) { |
|
1261 | - $e->get_error(); |
|
1262 | - } |
|
1263 | - } |
|
1264 | - return true; |
|
1265 | - } |
|
1266 | - |
|
1267 | - |
|
1268 | - |
|
1269 | - /** |
|
1270 | - * _process_action |
|
1271 | - * |
|
1272 | - * @access private |
|
1273 | - * @return void |
|
1274 | - * @throws \EE_Error |
|
1275 | - */ |
|
1276 | - private function _process_form_action() |
|
1277 | - { |
|
1278 | - // what cha wanna do? |
|
1279 | - switch ($this->checkout->action) { |
|
1280 | - // AJAX next step reg form |
|
1281 | - case 'display_spco_reg_step' : |
|
1282 | - $this->checkout->redirect = false; |
|
1283 | - if (EE_Registry::instance()->REQ->ajax) { |
|
1284 | - $this->checkout->json_response->set_reg_step_html($this->checkout->current_step->display_reg_form()); |
|
1285 | - } |
|
1286 | - break; |
|
1287 | - default : |
|
1288 | - // meh... do one of those other steps first |
|
1289 | - if ( ! empty($this->checkout->action) && is_callable(array($this->checkout->current_step, $this->checkout->action))) { |
|
1290 | - // dynamically creates hook point like: AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step |
|
1291 | - do_action("AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}", $this->checkout->current_step); |
|
1292 | - // call action on current step |
|
1293 | - if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) { |
|
1294 | - // good registrant, you get to proceed |
|
1295 | - if ( |
|
1296 | - $this->checkout->current_step->success_message() !== '' |
|
1297 | - && apply_filters( |
|
1298 | - 'FHEE__Single_Page_Checkout___process_form_action__display_success', |
|
1299 | - false |
|
1300 | - ) |
|
1301 | - ) { |
|
1302 | - EE_Error::add_success( |
|
1303 | - $this->checkout->current_step->success_message() |
|
1304 | - . '<br />' . $this->checkout->next_step->_instructions() |
|
1305 | - ); |
|
1306 | - } |
|
1307 | - // pack it up, pack it in... |
|
1308 | - $this->_setup_redirect(); |
|
1309 | - } |
|
1310 | - // dynamically creates hook point like: AHEE__Single_Page_Checkout__after_payment_options__process_reg_step |
|
1311 | - do_action("AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}", $this->checkout->current_step); |
|
1312 | - } else { |
|
1313 | - EE_Error::add_error( |
|
1314 | - sprintf( |
|
1315 | - __('The requested form action "%s" does not exist for the current "%s" registration step.', 'event_espresso'), |
|
1316 | - $this->checkout->action, |
|
1317 | - $this->checkout->current_step->name() |
|
1318 | - ), |
|
1319 | - __FILE__, |
|
1320 | - __FUNCTION__, |
|
1321 | - __LINE__ |
|
1322 | - ); |
|
1323 | - } |
|
1324 | - // end default |
|
1325 | - } |
|
1326 | - // store our progress so far |
|
1327 | - $this->checkout->stash_transaction_and_checkout(); |
|
1328 | - // advance to the next step! If you pass GO, collect $200 |
|
1329 | - $this->go_to_next_step(); |
|
1330 | - } |
|
1331 | - |
|
1332 | - |
|
1333 | - |
|
1334 | - /** |
|
1335 | - * add_styles_and_scripts |
|
1336 | - * |
|
1337 | - * @access public |
|
1338 | - * @return void |
|
1339 | - */ |
|
1340 | - public function add_styles_and_scripts() |
|
1341 | - { |
|
1342 | - // i18n |
|
1343 | - $this->translate_js_strings(); |
|
1344 | - if ($this->checkout->admin_request) { |
|
1345 | - add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
1346 | - } else { |
|
1347 | - add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
1348 | - } |
|
1349 | - } |
|
1350 | - |
|
1351 | - |
|
1352 | - |
|
1353 | - /** |
|
1354 | - * translate_js_strings |
|
1355 | - * |
|
1356 | - * @access public |
|
1357 | - * @return void |
|
1358 | - */ |
|
1359 | - public function translate_js_strings() |
|
1360 | - { |
|
1361 | - EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit; |
|
1362 | - EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link; |
|
1363 | - EE_Registry::$i18n_js_strings['server_error'] = __('An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', 'event_espresso'); |
|
1364 | - EE_Registry::$i18n_js_strings['invalid_json_response'] = __('An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.', 'event_espresso'); |
|
1365 | - EE_Registry::$i18n_js_strings['validation_error'] = __('There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.', 'event_espresso'); |
|
1366 | - EE_Registry::$i18n_js_strings['invalid_payment_method'] = __('There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.', 'event_espresso'); |
|
1367 | - EE_Registry::$i18n_js_strings['reg_step_error'] = __('This registration step could not be completed. Please refresh the page and try again.', 'event_espresso'); |
|
1368 | - EE_Registry::$i18n_js_strings['invalid_coupon'] = __('We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.', 'event_espresso'); |
|
1369 | - EE_Registry::$i18n_js_strings['process_registration'] = sprintf( |
|
1370 | - __('Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.', 'event_espresso'), |
|
1371 | - '<br/>', |
|
1372 | - '<br/>' |
|
1373 | - ); |
|
1374 | - EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language'); |
|
1375 | - EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id(); |
|
1376 | - EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency; |
|
1377 | - EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20'; |
|
1378 | - EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso'); |
|
1379 | - EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso'); |
|
1380 | - EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso'); |
|
1381 | - EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso'); |
|
1382 | - EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso'); |
|
1383 | - EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso'); |
|
1384 | - EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso'); |
|
1385 | - EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso'); |
|
1386 | - EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso'); |
|
1387 | - EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso'); |
|
1388 | - EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso'); |
|
1389 | - EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso'); |
|
1390 | - EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso'); |
|
1391 | - EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso'); |
|
1392 | - EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf( |
|
1393 | - __( |
|
1394 | - '%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s', |
|
1395 | - 'event_espresso' |
|
1396 | - ), |
|
1397 | - '<h4 class="important-notice">', |
|
1398 | - '</h4>', |
|
1399 | - '<br />', |
|
1400 | - '<p>', |
|
1401 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
1402 | - '">', |
|
1403 | - '</a>', |
|
1404 | - '</p>' |
|
1405 | - ); |
|
1406 | - EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters('FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit', true); |
|
1407 | - EE_Registry::$i18n_js_strings['session_extension'] = absint( |
|
1408 | - apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS) |
|
1409 | - ); |
|
1410 | - EE_Registry::$i18n_js_strings['session_expiration'] = gmdate( |
|
1411 | - 'M d, Y H:i:s', EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
1412 | - ); |
|
1413 | - } |
|
1414 | - |
|
1415 | - |
|
1416 | - |
|
1417 | - /** |
|
1418 | - * enqueue_styles_and_scripts |
|
1419 | - * |
|
1420 | - * @access public |
|
1421 | - * @return void |
|
1422 | - * @throws \EE_Error |
|
1423 | - */ |
|
1424 | - public function enqueue_styles_and_scripts() |
|
1425 | - { |
|
1426 | - // load css |
|
1427 | - wp_register_style('single_page_checkout', SPCO_CSS_URL . 'single_page_checkout.css', array(), EVENT_ESPRESSO_VERSION); |
|
1428 | - wp_enqueue_style('single_page_checkout'); |
|
1429 | - // load JS |
|
1430 | - wp_register_script('jquery_plugin', EE_THIRD_PARTY_URL . 'jquery .plugin.min.js', array('jquery'), '1.0.1', true); |
|
1431 | - wp_register_script('jquery_countdown', EE_THIRD_PARTY_URL . 'jquery .countdown.min.js', array('jquery_plugin'), '2.0.2', true); |
|
1432 | - wp_register_script('single_page_checkout', SPCO_JS_URL . 'single_page_checkout.js', array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'), EVENT_ESPRESSO_VERSION, true); |
|
1433 | - if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) { |
|
1434 | - $this->checkout->registration_form->enqueue_js(); |
|
1435 | - } |
|
1436 | - if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) { |
|
1437 | - $this->checkout->current_step->reg_form->enqueue_js(); |
|
1438 | - } |
|
1439 | - wp_enqueue_script('single_page_checkout'); |
|
1440 | - /** |
|
1441 | - * global action hook for enqueueing styles and scripts with |
|
1442 | - * spco calls. |
|
1443 | - */ |
|
1444 | - do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this); |
|
1445 | - /** |
|
1446 | - * dynamic action hook for enqueueing styles and scripts with spco calls. |
|
1447 | - * The hook will end up being something like AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information |
|
1448 | - */ |
|
1449 | - do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(), $this); |
|
1450 | - } |
|
1451 | - |
|
1452 | - |
|
1453 | - |
|
1454 | - /** |
|
1455 | - * display the Registration Single Page Checkout Form |
|
1456 | - * |
|
1457 | - * @access private |
|
1458 | - * @return void |
|
1459 | - * @throws \EE_Error |
|
1460 | - */ |
|
1461 | - private function _display_spco_reg_form() |
|
1462 | - { |
|
1463 | - // if registering via the admin, just display the reg form for the current step |
|
1464 | - if ($this->checkout->admin_request) { |
|
1465 | - EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form()); |
|
1466 | - } else { |
|
1467 | - // add powered by EE msg |
|
1468 | - add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer')); |
|
1469 | - $empty_cart = count($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params)) < 1 |
|
1470 | - ? true |
|
1471 | - : false; |
|
1472 | - EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart; |
|
1473 | - $cookies_not_set_msg = ''; |
|
1474 | - if ($empty_cart && ! isset($_COOKIE['ee_cookie_test'])) { |
|
1475 | - $cookies_not_set_msg = apply_filters( |
|
1476 | - 'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg', |
|
1477 | - sprintf( |
|
1478 | - __( |
|
1479 | - '%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s', |
|
1480 | - 'event_espresso' |
|
1481 | - ), |
|
1482 | - '<div class="ee-attention">', |
|
1483 | - '</div>', |
|
1484 | - '<h6 class="important-notice">', |
|
1485 | - '</h6>', |
|
1486 | - '<p>', |
|
1487 | - '</p>', |
|
1488 | - '<br />', |
|
1489 | - '<a href="http://www.whatarecookies.com/enable.asp" target="_blank">', |
|
1490 | - '</a>' |
|
1491 | - ) |
|
1492 | - ); |
|
1493 | - } |
|
1494 | - $this->checkout->registration_form = new EE_Form_Section_Proper( |
|
1495 | - array( |
|
1496 | - 'name' => 'single-page-checkout', |
|
1497 | - 'html_id' => 'ee-single-page-checkout-dv', |
|
1498 | - 'layout_strategy' => |
|
1499 | - new EE_Template_Layout( |
|
1500 | - array( |
|
1501 | - 'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php', |
|
1502 | - 'template_args' => array( |
|
1503 | - 'empty_cart' => $empty_cart, |
|
1504 | - 'revisit' => $this->checkout->revisit, |
|
1505 | - 'reg_steps' => $this->checkout->reg_steps, |
|
1506 | - 'next_step' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
|
1507 | - ? $this->checkout->next_step->slug() |
|
1508 | - : '', |
|
1509 | - 'cancel_page_url' => $this->checkout->cancel_page_url, |
|
1510 | - 'empty_msg' => apply_filters( |
|
1511 | - 'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg', |
|
1512 | - sprintf( |
|
1513 | - __('You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.', |
|
1514 | - 'event_espresso'), |
|
1515 | - '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
1516 | - '">', |
|
1517 | - '</a>' |
|
1518 | - ) |
|
1519 | - ), |
|
1520 | - 'cookies_not_set_msg' => $cookies_not_set_msg, |
|
1521 | - 'registration_time_limit' => $this->checkout->get_registration_time_limit(), |
|
1522 | - 'session_expiration' => |
|
1523 | - date('M d, Y H:i:s', EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)), |
|
1524 | - ), |
|
1525 | - ) |
|
1526 | - ), |
|
1527 | - ) |
|
1528 | - ); |
|
1529 | - // load template and add to output sent that gets filtered into the_content() |
|
1530 | - EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html()); |
|
1531 | - } |
|
1532 | - } |
|
1533 | - |
|
1534 | - |
|
1535 | - |
|
1536 | - /** |
|
1537 | - * add_extra_finalize_registration_inputs |
|
1538 | - * |
|
1539 | - * @access public |
|
1540 | - * @param $next_step |
|
1541 | - * @internal param string $label |
|
1542 | - * @return void |
|
1543 | - */ |
|
1544 | - public function add_extra_finalize_registration_inputs($next_step) |
|
1545 | - { |
|
1546 | - if ($next_step === 'finalize_registration') { |
|
1547 | - echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>'; |
|
1548 | - } |
|
1549 | - } |
|
1550 | - |
|
1551 | - |
|
1552 | - |
|
1553 | - /** |
|
1554 | - * display_registration_footer |
|
1555 | - * |
|
1556 | - * @access public |
|
1557 | - * @return string |
|
1558 | - */ |
|
1559 | - public static function display_registration_footer() |
|
1560 | - { |
|
1561 | - if ( |
|
1562 | - apply_filters( |
|
1563 | - 'FHEE__EE_Front__Controller__show_reg_footer', |
|
1564 | - EE_Registry::instance()->CFG->admin->show_reg_footer |
|
1565 | - ) |
|
1566 | - ) { |
|
1567 | - add_filter( |
|
1568 | - 'FHEE__EEH_Template__powered_by_event_espresso__url', |
|
1569 | - function ($url) { |
|
1570 | - return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url); |
|
1571 | - } |
|
1572 | - ); |
|
1573 | - echo apply_filters( |
|
1574 | - 'FHEE__EE_Front_Controller__display_registration_footer', |
|
1575 | - \EEH_Template::powered_by_event_espresso( |
|
1576 | - '', |
|
1577 | - 'espresso-registration-footer-dv', |
|
1578 | - array('utm_content' => 'registration_checkout') |
|
1579 | - ) |
|
1580 | - ); |
|
1581 | - } |
|
1582 | - return ''; |
|
1583 | - } |
|
1584 | - |
|
1585 | - |
|
1586 | - |
|
1587 | - /** |
|
1588 | - * unlock_transaction |
|
1589 | - * |
|
1590 | - * @access public |
|
1591 | - * @return void |
|
1592 | - * @throws \EE_Error |
|
1593 | - */ |
|
1594 | - public function unlock_transaction() |
|
1595 | - { |
|
1596 | - if ($this->checkout->transaction instanceof EE_Transaction) { |
|
1597 | - $this->checkout->transaction->unlock(); |
|
1598 | - } |
|
1599 | - } |
|
1600 | - |
|
1601 | - |
|
1602 | - |
|
1603 | - /** |
|
1604 | - * _setup_redirect |
|
1605 | - * |
|
1606 | - * @access private |
|
1607 | - * @return void |
|
1608 | - */ |
|
1609 | - private function _setup_redirect() |
|
1610 | - { |
|
1611 | - if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
1612 | - $this->checkout->redirect = true; |
|
1613 | - if (empty($this->checkout->redirect_url)) { |
|
1614 | - $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url(); |
|
1615 | - } |
|
1616 | - $this->checkout->redirect_url = apply_filters( |
|
1617 | - 'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url', |
|
1618 | - $this->checkout->redirect_url, |
|
1619 | - $this->checkout |
|
1620 | - ); |
|
1621 | - } |
|
1622 | - } |
|
1623 | - |
|
1624 | - |
|
1625 | - |
|
1626 | - /** |
|
1627 | - * handle ajax message responses and redirects |
|
1628 | - * |
|
1629 | - * @access public |
|
1630 | - * @return void |
|
1631 | - * @throws \EE_Error |
|
1632 | - */ |
|
1633 | - public function go_to_next_step() |
|
1634 | - { |
|
1635 | - if (EE_Registry::instance()->REQ->ajax) { |
|
1636 | - // capture contents of output buffer we started earlier in the request, and insert into JSON response |
|
1637 | - $this->checkout->json_response->set_unexpected_errors(ob_get_clean()); |
|
1638 | - } |
|
1639 | - $this->unlock_transaction(); |
|
1640 | - // just return for these conditions |
|
1641 | - if ( |
|
1642 | - $this->checkout->admin_request |
|
1643 | - || $this->checkout->action === 'redirect_form' |
|
1644 | - || $this->checkout->action === 'update_checkout' |
|
1645 | - ) { |
|
1646 | - return; |
|
1647 | - } |
|
1648 | - // AJAX response |
|
1649 | - $this->_handle_json_response(); |
|
1650 | - // redirect to next step or the Thank You page |
|
1651 | - $this->_handle_html_redirects(); |
|
1652 | - // hmmm... must be something wrong, so let's just display the form again ! |
|
1653 | - $this->_display_spco_reg_form(); |
|
1654 | - } |
|
1655 | - |
|
1656 | - |
|
1657 | - |
|
1658 | - /** |
|
1659 | - * _handle_json_response |
|
1660 | - * |
|
1661 | - * @access protected |
|
1662 | - * @return void |
|
1663 | - */ |
|
1664 | - protected function _handle_json_response() |
|
1665 | - { |
|
1666 | - // if this is an ajax request |
|
1667 | - if (EE_Registry::instance()->REQ->ajax) { |
|
1668 | - // DEBUG LOG |
|
1669 | - //$this->checkout->log( |
|
1670 | - // __CLASS__, __FUNCTION__, __LINE__, |
|
1671 | - // array( |
|
1672 | - // 'json_response_redirect_url' => $this->checkout->json_response->redirect_url(), |
|
1673 | - // 'redirect' => $this->checkout->redirect, |
|
1674 | - // 'continue_reg' => $this->checkout->continue_reg, |
|
1675 | - // ) |
|
1676 | - //); |
|
1677 | - $this->checkout->json_response->set_registration_time_limit( |
|
1678 | - $this->checkout->get_registration_time_limit() |
|
1679 | - ); |
|
1680 | - $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing); |
|
1681 | - // just send the ajax ( |
|
1682 | - $json_response = apply_filters( |
|
1683 | - 'FHEE__EE_Single_Page_Checkout__JSON_response', |
|
1684 | - $this->checkout->json_response |
|
1685 | - ); |
|
1686 | - echo $json_response; |
|
1687 | - exit(); |
|
1688 | - } |
|
1689 | - } |
|
1690 | - |
|
1691 | - |
|
1692 | - |
|
1693 | - /** |
|
1694 | - * _handle_redirects |
|
1695 | - * |
|
1696 | - * @access protected |
|
1697 | - * @return void |
|
1698 | - */ |
|
1699 | - protected function _handle_html_redirects() |
|
1700 | - { |
|
1701 | - // going somewhere ? |
|
1702 | - if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) { |
|
1703 | - // store notices in a transient |
|
1704 | - EE_Error::get_notices(false, true, true); |
|
1705 | - // DEBUG LOG |
|
1706 | - //$this->checkout->log( |
|
1707 | - // __CLASS__, __FUNCTION__, __LINE__, |
|
1708 | - // array( |
|
1709 | - // 'headers_sent' => headers_sent(), |
|
1710 | - // 'redirect_url' => $this->checkout->redirect_url, |
|
1711 | - // 'headers_list' => headers_list(), |
|
1712 | - // ) |
|
1713 | - //); |
|
1714 | - wp_safe_redirect($this->checkout->redirect_url); |
|
1715 | - exit(); |
|
1716 | - } |
|
1717 | - } |
|
1718 | - |
|
1719 | - |
|
1720 | - |
|
1721 | - /** |
|
1722 | - * set_checkout_anchor |
|
1723 | - * |
|
1724 | - * @access public |
|
1725 | - * @return void |
|
1726 | - */ |
|
1727 | - public function set_checkout_anchor() |
|
1728 | - { |
|
1729 | - echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>'; |
|
1730 | - } |
|
20 | + /** |
|
21 | + * $_initialized - has the SPCO controller already been initialized ? |
|
22 | + * |
|
23 | + * @access private |
|
24 | + * @var bool $_initialized |
|
25 | + */ |
|
26 | + private static $_initialized = false; |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * $_checkout_verified - is the EE_Checkout verified as correct for this request ? |
|
31 | + * |
|
32 | + * @access private |
|
33 | + * @var bool $_valid_checkout |
|
34 | + */ |
|
35 | + private static $_checkout_verified = true; |
|
36 | + |
|
37 | + /** |
|
38 | + * $_reg_steps_array - holds initial array of reg steps |
|
39 | + * |
|
40 | + * @access private |
|
41 | + * @var array $_reg_steps_array |
|
42 | + */ |
|
43 | + private static $_reg_steps_array = array(); |
|
44 | + |
|
45 | + /** |
|
46 | + * $checkout - EE_Checkout object for handling the properties of the current checkout process |
|
47 | + * |
|
48 | + * @access public |
|
49 | + * @var EE_Checkout $checkout |
|
50 | + */ |
|
51 | + public $checkout; |
|
52 | + |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * @return EED_Single_Page_Checkout |
|
57 | + */ |
|
58 | + public static function instance() |
|
59 | + { |
|
60 | + add_filter('EED_Single_Page_Checkout__SPCO_active', '__return_true'); |
|
61 | + return parent::get_instance(__CLASS__); |
|
62 | + } |
|
63 | + |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * @return EE_CART |
|
68 | + */ |
|
69 | + public function cart() |
|
70 | + { |
|
71 | + return $this->checkout->cart; |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * @return EE_Transaction |
|
78 | + */ |
|
79 | + public function transaction() |
|
80 | + { |
|
81 | + return $this->checkout->transaction; |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * set_hooks - for hooking into EE Core, other modules, etc |
|
88 | + * |
|
89 | + * @access public |
|
90 | + * @return void |
|
91 | + * @throws \EE_Error |
|
92 | + */ |
|
93 | + public static function set_hooks() |
|
94 | + { |
|
95 | + EED_Single_Page_Checkout::set_definitions(); |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * set_hooks_admin - for hooking into EE Admin Core, other modules, etc |
|
102 | + * |
|
103 | + * @access public |
|
104 | + * @return void |
|
105 | + * @throws \EE_Error |
|
106 | + */ |
|
107 | + public static function set_hooks_admin() |
|
108 | + { |
|
109 | + EED_Single_Page_Checkout::set_definitions(); |
|
110 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX)) { |
|
111 | + // hook into the top of pre_get_posts to set the reg step routing, which gives other modules or plugins a chance to modify the reg steps, but just before the routes get called |
|
112 | + add_action('pre_get_posts', array('EED_Single_Page_Checkout', 'load_reg_steps'), 1); |
|
113 | + return; |
|
114 | + } |
|
115 | + // going to start an output buffer in case anything gets accidentally output that might disrupt our JSON response |
|
116 | + ob_start(); |
|
117 | + EED_Single_Page_Checkout::load_request_handler(); |
|
118 | + EED_Single_Page_Checkout::load_reg_steps(); |
|
119 | + // set ajax hooks |
|
120 | + add_action('wp_ajax_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
121 | + add_action('wp_ajax_nopriv_process_reg_step', array('EED_Single_Page_Checkout', 'process_reg_step')); |
|
122 | + add_action('wp_ajax_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
123 | + add_action('wp_ajax_nopriv_display_spco_reg_step', array('EED_Single_Page_Checkout', 'display_reg_step')); |
|
124 | + add_action('wp_ajax_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
125 | + add_action('wp_ajax_nopriv_update_reg_step', array('EED_Single_Page_Checkout', 'update_reg_step')); |
|
126 | + } |
|
127 | + |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * process ajax request |
|
132 | + * |
|
133 | + * @param string $ajax_action |
|
134 | + * @throws \EE_Error |
|
135 | + */ |
|
136 | + public static function process_ajax_request($ajax_action) |
|
137 | + { |
|
138 | + EE_Registry::instance()->REQ->set('action', $ajax_action); |
|
139 | + EED_Single_Page_Checkout::instance()->_initialize(); |
|
140 | + } |
|
141 | + |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * ajax display registration step |
|
146 | + * |
|
147 | + * @throws \EE_Error |
|
148 | + */ |
|
149 | + public static function display_reg_step() |
|
150 | + { |
|
151 | + EED_Single_Page_Checkout::process_ajax_request('display_spco_reg_step'); |
|
152 | + } |
|
153 | + |
|
154 | + |
|
155 | + |
|
156 | + /** |
|
157 | + * ajax process registration step |
|
158 | + * |
|
159 | + * @throws \EE_Error |
|
160 | + */ |
|
161 | + public static function process_reg_step() |
|
162 | + { |
|
163 | + EED_Single_Page_Checkout::process_ajax_request('process_reg_step'); |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + |
|
168 | + /** |
|
169 | + * ajax process registration step |
|
170 | + * |
|
171 | + * @throws \EE_Error |
|
172 | + */ |
|
173 | + public static function update_reg_step() |
|
174 | + { |
|
175 | + EED_Single_Page_Checkout::process_ajax_request('update_reg_step'); |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + |
|
180 | + /** |
|
181 | + * update_checkout |
|
182 | + * |
|
183 | + * @access public |
|
184 | + * @return void |
|
185 | + * @throws \EE_Error |
|
186 | + */ |
|
187 | + public static function update_checkout() |
|
188 | + { |
|
189 | + EED_Single_Page_Checkout::process_ajax_request('update_checkout'); |
|
190 | + } |
|
191 | + |
|
192 | + |
|
193 | + |
|
194 | + /** |
|
195 | + * load_request_handler |
|
196 | + * |
|
197 | + * @access public |
|
198 | + * @return void |
|
199 | + */ |
|
200 | + public static function load_request_handler() |
|
201 | + { |
|
202 | + // load core Request_Handler class |
|
203 | + if ( ! isset(EE_Registry::instance()->REQ)) { |
|
204 | + EE_Registry::instance()->load_core('Request_Handler'); |
|
205 | + } |
|
206 | + } |
|
207 | + |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * set_definitions |
|
212 | + * |
|
213 | + * @access public |
|
214 | + * @return void |
|
215 | + * @throws \EE_Error |
|
216 | + */ |
|
217 | + public static function set_definitions() |
|
218 | + { |
|
219 | + define('SPCO_BASE_PATH', rtrim(str_replace(array('\\', '/'), DS, plugin_dir_path(__FILE__)), DS) . DS); |
|
220 | + define('SPCO_CSS_URL', plugin_dir_url(__FILE__) . 'css' . DS); |
|
221 | + define('SPCO_IMG_URL', plugin_dir_url(__FILE__) . 'img' . DS); |
|
222 | + define('SPCO_JS_URL', plugin_dir_url(__FILE__) . 'js' . DS); |
|
223 | + define('SPCO_INC_PATH', SPCO_BASE_PATH . 'inc' . DS); |
|
224 | + define('SPCO_REG_STEPS_PATH', SPCO_BASE_PATH . 'reg_steps' . DS); |
|
225 | + define('SPCO_TEMPLATES_PATH', SPCO_BASE_PATH . 'templates' . DS); |
|
226 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder(SPCO_BASE_PATH, true); |
|
227 | + EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf( |
|
228 | + __('%1$sWe\'re sorry, but you\'re registration time has expired.%2$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s', |
|
229 | + 'event_espresso'), |
|
230 | + '<h4 class="important-notice">', |
|
231 | + '</h4>', |
|
232 | + '<br />', |
|
233 | + '<p>', |
|
234 | + '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
235 | + '">', |
|
236 | + '</a>', |
|
237 | + '</p>' |
|
238 | + ); |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + |
|
243 | + /** |
|
244 | + * load_reg_steps |
|
245 | + * loads and instantiates each reg step based on the EE_Registry::instance()->CFG->registration->reg_steps array |
|
246 | + * |
|
247 | + * @access private |
|
248 | + * @throws EE_Error |
|
249 | + * @return void |
|
250 | + */ |
|
251 | + public static function load_reg_steps() |
|
252 | + { |
|
253 | + static $reg_steps_loaded = false; |
|
254 | + if ($reg_steps_loaded) { |
|
255 | + return; |
|
256 | + } |
|
257 | + // filter list of reg_steps |
|
258 | + $reg_steps_to_load = (array)apply_filters( |
|
259 | + 'AHEE__SPCO__load_reg_steps__reg_steps_to_load', |
|
260 | + EED_Single_Page_Checkout::get_reg_steps() |
|
261 | + ); |
|
262 | + // sort by key (order) |
|
263 | + ksort($reg_steps_to_load); |
|
264 | + // loop through folders |
|
265 | + foreach ($reg_steps_to_load as $order => $reg_step) { |
|
266 | + // we need a |
|
267 | + if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
268 | + // copy over to the reg_steps_array |
|
269 | + EED_Single_Page_Checkout::$_reg_steps_array[$order] = $reg_step; |
|
270 | + // register custom key route for each reg step |
|
271 | + // ie: step=>"slug" - this is the entire reason we load the reg steps array now |
|
272 | + EE_Config::register_route($reg_step['slug'], 'EED_Single_Page_Checkout', 'run', 'step'); |
|
273 | + // add AJAX or other hooks |
|
274 | + if (isset($reg_step['has_hooks']) && $reg_step['has_hooks']) { |
|
275 | + // setup autoloaders if necessary |
|
276 | + if ( ! class_exists($reg_step['class_name'])) { |
|
277 | + EEH_Autoloader::register_autoloaders_for_each_file_in_folder($reg_step['file_path'], true); |
|
278 | + } |
|
279 | + if (is_callable($reg_step['class_name'], 'set_hooks')) { |
|
280 | + call_user_func(array($reg_step['class_name'], 'set_hooks')); |
|
281 | + } |
|
282 | + } |
|
283 | + } |
|
284 | + } |
|
285 | + $reg_steps_loaded = true; |
|
286 | + } |
|
287 | + |
|
288 | + |
|
289 | + |
|
290 | + /** |
|
291 | + * get_reg_steps |
|
292 | + * |
|
293 | + * @access public |
|
294 | + * @return array |
|
295 | + */ |
|
296 | + public static function get_reg_steps() |
|
297 | + { |
|
298 | + $reg_steps = EE_Registry::instance()->CFG->registration->reg_steps; |
|
299 | + if (empty($reg_steps)) { |
|
300 | + $reg_steps = array( |
|
301 | + 10 => array( |
|
302 | + 'file_path' => SPCO_REG_STEPS_PATH . 'attendee_information', |
|
303 | + 'class_name' => 'EE_SPCO_Reg_Step_Attendee_Information', |
|
304 | + 'slug' => 'attendee_information', |
|
305 | + 'has_hooks' => false, |
|
306 | + ), |
|
307 | + 20 => array( |
|
308 | + 'file_path' => SPCO_REG_STEPS_PATH . 'registration_confirmation', |
|
309 | + 'class_name' => 'EE_SPCO_Reg_Step_Registration_Confirmation', |
|
310 | + 'slug' => 'registration_confirmation', |
|
311 | + 'has_hooks' => false, |
|
312 | + ), |
|
313 | + 30 => array( |
|
314 | + 'file_path' => SPCO_REG_STEPS_PATH . 'payment_options', |
|
315 | + 'class_name' => 'EE_SPCO_Reg_Step_Payment_Options', |
|
316 | + 'slug' => 'payment_options', |
|
317 | + 'has_hooks' => true, |
|
318 | + ), |
|
319 | + 999 => array( |
|
320 | + 'file_path' => SPCO_REG_STEPS_PATH . 'finalize_registration', |
|
321 | + 'class_name' => 'EE_SPCO_Reg_Step_Finalize_Registration', |
|
322 | + 'slug' => 'finalize_registration', |
|
323 | + 'has_hooks' => false, |
|
324 | + ), |
|
325 | + ); |
|
326 | + } |
|
327 | + return $reg_steps; |
|
328 | + } |
|
329 | + |
|
330 | + |
|
331 | + |
|
332 | + /** |
|
333 | + * registration_checkout_for_admin |
|
334 | + * |
|
335 | + * @access public |
|
336 | + * @return string |
|
337 | + * @throws \EE_Error |
|
338 | + */ |
|
339 | + public static function registration_checkout_for_admin() |
|
340 | + { |
|
341 | + EED_Single_Page_Checkout::load_reg_steps(); |
|
342 | + EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
343 | + EE_Registry::instance()->REQ->set('action', 'display_spco_reg_step'); |
|
344 | + EE_Registry::instance()->REQ->set('process_form_submission', false); |
|
345 | + EED_Single_Page_Checkout::instance()->_initialize(); |
|
346 | + EED_Single_Page_Checkout::instance()->_display_spco_reg_form(); |
|
347 | + return EE_Registry::instance()->REQ->get_output(); |
|
348 | + } |
|
349 | + |
|
350 | + |
|
351 | + |
|
352 | + /** |
|
353 | + * process_registration_from_admin |
|
354 | + * |
|
355 | + * @access public |
|
356 | + * @return \EE_Transaction |
|
357 | + * @throws \EE_Error |
|
358 | + */ |
|
359 | + public static function process_registration_from_admin() |
|
360 | + { |
|
361 | + EED_Single_Page_Checkout::load_reg_steps(); |
|
362 | + EE_Registry::instance()->REQ->set('step', 'attendee_information'); |
|
363 | + EE_Registry::instance()->REQ->set('action', 'process_reg_step'); |
|
364 | + EE_Registry::instance()->REQ->set('process_form_submission', true); |
|
365 | + EED_Single_Page_Checkout::instance()->_initialize(); |
|
366 | + if (EED_Single_Page_Checkout::instance()->checkout->current_step->completed()) { |
|
367 | + $final_reg_step = end(EED_Single_Page_Checkout::instance()->checkout->reg_steps); |
|
368 | + if ($final_reg_step instanceof EE_SPCO_Reg_Step_Finalize_Registration) { |
|
369 | + EED_Single_Page_Checkout::instance()->checkout->set_reg_step_initiated($final_reg_step); |
|
370 | + if ($final_reg_step->process_reg_step()) { |
|
371 | + $final_reg_step->set_completed(); |
|
372 | + EED_Single_Page_Checkout::instance()->checkout->update_txn_reg_steps_array(); |
|
373 | + return EED_Single_Page_Checkout::instance()->checkout->transaction; |
|
374 | + } |
|
375 | + } |
|
376 | + } |
|
377 | + return null; |
|
378 | + } |
|
379 | + |
|
380 | + |
|
381 | + |
|
382 | + /** |
|
383 | + * run |
|
384 | + * |
|
385 | + * @access public |
|
386 | + * @param WP_Query $WP_Query |
|
387 | + * @return void |
|
388 | + * @throws \EE_Error |
|
389 | + */ |
|
390 | + public function run($WP_Query) |
|
391 | + { |
|
392 | + if ( |
|
393 | + $WP_Query instanceof WP_Query |
|
394 | + && $WP_Query->is_main_query() |
|
395 | + && apply_filters('FHEE__EED_Single_Page_Checkout__run', true) |
|
396 | + && $this->_is_reg_checkout() |
|
397 | + ) { |
|
398 | + $this->_initialize(); |
|
399 | + } |
|
400 | + } |
|
401 | + |
|
402 | + |
|
403 | + |
|
404 | + /** |
|
405 | + * determines whether current url matches reg page url |
|
406 | + * |
|
407 | + * @return bool |
|
408 | + */ |
|
409 | + protected function _is_reg_checkout() |
|
410 | + { |
|
411 | + // get current permalink for reg page without any extra query args |
|
412 | + $reg_page_url = \get_permalink(EE_Config::instance()->core->reg_page_id); |
|
413 | + // get request URI for current request, but without the scheme or host |
|
414 | + $current_request_uri = \EEH_URL::filter_input_server_url('REQUEST_URI'); |
|
415 | + $current_request_uri = html_entity_decode($current_request_uri); |
|
416 | + // get array of query args from the current request URI |
|
417 | + $query_args = \EEH_URL::get_query_string($current_request_uri); |
|
418 | + // grab page id if it is set |
|
419 | + $page_id = isset($query_args['page_id']) ? absint($query_args['page_id']) : 0; |
|
420 | + // and remove the page id from the query args (we will re-add it later) |
|
421 | + unset($query_args['page_id']); |
|
422 | + // now strip all query args from current request URI |
|
423 | + $current_request_uri = remove_query_arg(array_keys($query_args), $current_request_uri); |
|
424 | + // and re-add the page id if it was set |
|
425 | + if ($page_id) { |
|
426 | + $current_request_uri = add_query_arg('page_id', $page_id, $current_request_uri); |
|
427 | + } |
|
428 | + // remove slashes and ? |
|
429 | + $current_request_uri = trim($current_request_uri, '?/'); |
|
430 | + // is current request URI part of the known full reg page URL ? |
|
431 | + return ! empty($current_request_uri) && strpos($reg_page_url, $current_request_uri) !== false; |
|
432 | + } |
|
433 | + |
|
434 | + |
|
435 | + |
|
436 | + /** |
|
437 | + * run |
|
438 | + * |
|
439 | + * @access public |
|
440 | + * @param WP_Query $WP_Query |
|
441 | + * @return void |
|
442 | + * @throws \EE_Error |
|
443 | + */ |
|
444 | + public static function init($WP_Query) |
|
445 | + { |
|
446 | + EED_Single_Page_Checkout::instance()->run($WP_Query); |
|
447 | + } |
|
448 | + |
|
449 | + |
|
450 | + |
|
451 | + /** |
|
452 | + * _initialize - initial module setup |
|
453 | + * |
|
454 | + * @access private |
|
455 | + * @throws EE_Error |
|
456 | + * @return void |
|
457 | + */ |
|
458 | + private function _initialize() |
|
459 | + { |
|
460 | + // ensure SPCO doesn't run twice |
|
461 | + if (EED_Single_Page_Checkout::$_initialized) { |
|
462 | + return; |
|
463 | + } |
|
464 | + try { |
|
465 | + $this->_verify_session(); |
|
466 | + // setup the EE_Checkout object |
|
467 | + $this->checkout = $this->_initialize_checkout(); |
|
468 | + // filter checkout |
|
469 | + $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize__checkout', $this->checkout); |
|
470 | + // get the $_GET |
|
471 | + $this->_get_request_vars(); |
|
472 | + if ($this->_block_bots()) { |
|
473 | + return; |
|
474 | + } |
|
475 | + // filter continue_reg |
|
476 | + $this->checkout->continue_reg = apply_filters('FHEE__EED_Single_Page_Checkout__init___continue_reg', true, $this->checkout); |
|
477 | + // load the reg steps array |
|
478 | + if ( ! $this->_load_and_instantiate_reg_steps()) { |
|
479 | + EED_Single_Page_Checkout::$_initialized = true; |
|
480 | + return; |
|
481 | + } |
|
482 | + // set the current step |
|
483 | + $this->checkout->set_current_step($this->checkout->step); |
|
484 | + // and the next step |
|
485 | + $this->checkout->set_next_step(); |
|
486 | + // verify that everything has been setup correctly |
|
487 | + if ( ! ($this->_verify_transaction_and_get_registrations() && $this->_final_verifications())) { |
|
488 | + EED_Single_Page_Checkout::$_initialized = true; |
|
489 | + return; |
|
490 | + } |
|
491 | + // lock the transaction |
|
492 | + $this->checkout->transaction->lock(); |
|
493 | + // make sure all of our cached objects are added to their respective model entity mappers |
|
494 | + $this->checkout->refresh_all_entities(); |
|
495 | + // set amount owing |
|
496 | + $this->checkout->amount_owing = $this->checkout->transaction->remaining(); |
|
497 | + // initialize each reg step, which gives them the chance to potentially alter the process |
|
498 | + $this->_initialize_reg_steps(); |
|
499 | + // DEBUG LOG |
|
500 | + //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
501 | + // get reg form |
|
502 | + if( ! $this->_check_form_submission()) { |
|
503 | + EED_Single_Page_Checkout::$_initialized = true; |
|
504 | + return; |
|
505 | + } |
|
506 | + // checkout the action!!! |
|
507 | + $this->_process_form_action(); |
|
508 | + // add some style and make it dance |
|
509 | + $this->add_styles_and_scripts(); |
|
510 | + // kk... SPCO has successfully run |
|
511 | + EED_Single_Page_Checkout::$_initialized = true; |
|
512 | + // set no cache headers and constants |
|
513 | + EE_System::do_not_cache(); |
|
514 | + // add anchor |
|
515 | + add_action('loop_start', array($this, 'set_checkout_anchor'), 1); |
|
516 | + // remove transaction lock |
|
517 | + add_action('shutdown', array($this, 'unlock_transaction'), 1); |
|
518 | + } catch (Exception $e) { |
|
519 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
520 | + } |
|
521 | + } |
|
522 | + |
|
523 | + |
|
524 | + |
|
525 | + /** |
|
526 | + * _verify_session |
|
527 | + * checks that the session is valid and not expired |
|
528 | + * |
|
529 | + * @access private |
|
530 | + * @throws EE_Error |
|
531 | + */ |
|
532 | + private function _verify_session() |
|
533 | + { |
|
534 | + if ( ! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
535 | + throw new EE_Error(__('The EE_Session class could not be loaded.', 'event_espresso')); |
|
536 | + } |
|
537 | + // is session still valid ? |
|
538 | + if (EE_Registry::instance()->SSN->expired() && EE_Registry::instance()->REQ->get('e_reg_url_link', '') === '') { |
|
539 | + $this->checkout = new EE_Checkout(); |
|
540 | + EE_Registry::instance()->SSN->reset_cart(); |
|
541 | + EE_Registry::instance()->SSN->reset_checkout(); |
|
542 | + EE_Registry::instance()->SSN->reset_transaction(); |
|
543 | + EE_Error::add_attention(EE_Registry::$i18n_js_strings['registration_expiration_notice'], __FILE__, |
|
544 | + __FUNCTION__, __LINE__); |
|
545 | + EE_Registry::instance()->SSN->reset_expired(); |
|
546 | + } |
|
547 | + } |
|
548 | + |
|
549 | + |
|
550 | + |
|
551 | + /** |
|
552 | + * _initialize_checkout |
|
553 | + * loads and instantiates EE_Checkout |
|
554 | + * |
|
555 | + * @access private |
|
556 | + * @throws EE_Error |
|
557 | + * @return EE_Checkout |
|
558 | + */ |
|
559 | + private function _initialize_checkout() |
|
560 | + { |
|
561 | + // look in session for existing checkout |
|
562 | + /** @type EE_Checkout $checkout */ |
|
563 | + $checkout = EE_Registry::instance()->SSN->checkout(); |
|
564 | + // verify |
|
565 | + if ( ! $checkout instanceof EE_Checkout) { |
|
566 | + // instantiate EE_Checkout object for handling the properties of the current checkout process |
|
567 | + $checkout = EE_Registry::instance()->load_file(SPCO_INC_PATH, 'EE_Checkout', 'class', array(), false); |
|
568 | + } else { |
|
569 | + if ($checkout->current_step->is_final_step() && $checkout->exit_spco() === true) { |
|
570 | + $this->unlock_transaction(); |
|
571 | + wp_safe_redirect($checkout->redirect_url); |
|
572 | + exit(); |
|
573 | + } |
|
574 | + } |
|
575 | + $checkout = apply_filters('FHEE__EED_Single_Page_Checkout___initialize_checkout__checkout', $checkout); |
|
576 | + // verify again |
|
577 | + if ( ! $checkout instanceof EE_Checkout) { |
|
578 | + throw new EE_Error(__('The EE_Checkout class could not be loaded.', 'event_espresso')); |
|
579 | + } |
|
580 | + // reset anything that needs a clean slate for each request |
|
581 | + $checkout->reset_for_current_request(); |
|
582 | + return $checkout; |
|
583 | + } |
|
584 | + |
|
585 | + |
|
586 | + |
|
587 | + /** |
|
588 | + * _get_request_vars |
|
589 | + * |
|
590 | + * @access private |
|
591 | + * @return void |
|
592 | + * @throws \EE_Error |
|
593 | + */ |
|
594 | + private function _get_request_vars() |
|
595 | + { |
|
596 | + // load classes |
|
597 | + EED_Single_Page_Checkout::load_request_handler(); |
|
598 | + //make sure this request is marked as belonging to EE |
|
599 | + EE_Registry::instance()->REQ->set_espresso_page(true); |
|
600 | + // which step is being requested ? |
|
601 | + $this->checkout->step = EE_Registry::instance()->REQ->get('step', $this->_get_first_step()); |
|
602 | + // which step is being edited ? |
|
603 | + $this->checkout->edit_step = EE_Registry::instance()->REQ->get('edit_step', ''); |
|
604 | + // and what we're doing on the current step |
|
605 | + $this->checkout->action = EE_Registry::instance()->REQ->get('action', 'display_spco_reg_step'); |
|
606 | + // timestamp |
|
607 | + $this->checkout->uts = EE_Registry::instance()->REQ->get('uts', 0); |
|
608 | + // returning to edit ? |
|
609 | + $this->checkout->reg_url_link = EE_Registry::instance()->REQ->get('e_reg_url_link', ''); |
|
610 | + // or some other kind of revisit ? |
|
611 | + $this->checkout->revisit = filter_var( |
|
612 | + EE_Registry::instance()->REQ->get('revisit', false), |
|
613 | + FILTER_VALIDATE_BOOLEAN |
|
614 | + ); |
|
615 | + // and whether or not to generate a reg form for this request |
|
616 | + $this->checkout->generate_reg_form = filter_var( |
|
617 | + EE_Registry::instance()->REQ->get('generate_reg_form', true), |
|
618 | + FILTER_VALIDATE_BOOLEAN |
|
619 | + ); |
|
620 | + // and whether or not to process a reg form submission for this request |
|
621 | + $this->checkout->process_form_submission = filter_var( |
|
622 | + EE_Registry::instance()->REQ->get( |
|
623 | + 'process_form_submission', |
|
624 | + $this->checkout->action === 'process_reg_step' |
|
625 | + ), |
|
626 | + FILTER_VALIDATE_BOOLEAN |
|
627 | + ); |
|
628 | + $this->checkout->process_form_submission = filter_var( |
|
629 | + $this->checkout->action !== 'display_spco_reg_step' |
|
630 | + ? $this->checkout->process_form_submission |
|
631 | + : false, |
|
632 | + FILTER_VALIDATE_BOOLEAN |
|
633 | + ); |
|
634 | + // $this->_display_request_vars(); |
|
635 | + } |
|
636 | + |
|
637 | + |
|
638 | + |
|
639 | + /** |
|
640 | + * _display_request_vars |
|
641 | + * |
|
642 | + * @access protected |
|
643 | + * @return void |
|
644 | + */ |
|
645 | + protected function _display_request_vars() |
|
646 | + { |
|
647 | + if ( ! WP_DEBUG) { |
|
648 | + return; |
|
649 | + } |
|
650 | + EEH_Debug_Tools::printr($_REQUEST, '$_REQUEST', __FILE__, __LINE__); |
|
651 | + EEH_Debug_Tools::printr($this->checkout->step, '$this->checkout->step', __FILE__, __LINE__); |
|
652 | + EEH_Debug_Tools::printr($this->checkout->edit_step, '$this->checkout->edit_step', __FILE__, __LINE__); |
|
653 | + EEH_Debug_Tools::printr($this->checkout->action, '$this->checkout->action', __FILE__, __LINE__); |
|
654 | + EEH_Debug_Tools::printr($this->checkout->reg_url_link, '$this->checkout->reg_url_link', __FILE__, __LINE__); |
|
655 | + EEH_Debug_Tools::printr($this->checkout->revisit, '$this->checkout->revisit', __FILE__, __LINE__); |
|
656 | + EEH_Debug_Tools::printr($this->checkout->generate_reg_form, '$this->checkout->generate_reg_form', __FILE__, __LINE__); |
|
657 | + EEH_Debug_Tools::printr($this->checkout->process_form_submission, '$this->checkout->process_form_submission', __FILE__, __LINE__); |
|
658 | + } |
|
659 | + |
|
660 | + |
|
661 | + |
|
662 | + /** |
|
663 | + * _block_bots |
|
664 | + * checks that the incoming request has either of the following set: |
|
665 | + * a uts (unix timestamp) which indicates that the request was redirected from the Ticket Selector |
|
666 | + * a REG URL Link, which indicates that the request is a return visit to SPCO for a valid TXN |
|
667 | + * so if you're not coming from the Ticket Selector nor returning for a valid IP... |
|
668 | + * then where you coming from man? |
|
669 | + * |
|
670 | + * @return boolean |
|
671 | + */ |
|
672 | + private function _block_bots() |
|
673 | + { |
|
674 | + $invalid_checkout_access = \EED_Invalid_Checkout_Access::getInvalidCheckoutAccess(); |
|
675 | + if ($invalid_checkout_access->checkoutAccessIsInvalid($this->checkout)) { |
|
676 | + return true; |
|
677 | + } |
|
678 | + return false; |
|
679 | + } |
|
680 | + |
|
681 | + |
|
682 | + |
|
683 | + /** |
|
684 | + * _get_first_step |
|
685 | + * gets slug for first step in $_reg_steps_array |
|
686 | + * |
|
687 | + * @access private |
|
688 | + * @throws EE_Error |
|
689 | + * @return string |
|
690 | + */ |
|
691 | + private function _get_first_step() |
|
692 | + { |
|
693 | + $first_step = reset(EED_Single_Page_Checkout::$_reg_steps_array); |
|
694 | + return isset($first_step['slug']) ? $first_step['slug'] : 'attendee_information'; |
|
695 | + } |
|
696 | + |
|
697 | + |
|
698 | + |
|
699 | + /** |
|
700 | + * _load_and_instantiate_reg_steps |
|
701 | + * instantiates each reg step based on the loaded reg_steps array |
|
702 | + * |
|
703 | + * @access private |
|
704 | + * @throws EE_Error |
|
705 | + * @return bool |
|
706 | + */ |
|
707 | + private function _load_and_instantiate_reg_steps() |
|
708 | + { |
|
709 | + do_action('AHEE__Single_Page_Checkout___load_and_instantiate_reg_steps__start', $this->checkout); |
|
710 | + // have reg_steps already been instantiated ? |
|
711 | + if ( |
|
712 | + empty($this->checkout->reg_steps) |
|
713 | + || apply_filters('FHEE__Single_Page_Checkout__load_reg_steps__reload_reg_steps', false, $this->checkout) |
|
714 | + ) { |
|
715 | + // if not, then loop through raw reg steps array |
|
716 | + foreach (EED_Single_Page_Checkout::$_reg_steps_array as $order => $reg_step) { |
|
717 | + if ( ! $this->_load_and_instantiate_reg_step($reg_step, $order)) { |
|
718 | + return false; |
|
719 | + } |
|
720 | + } |
|
721 | + EE_Registry::instance()->CFG->registration->skip_reg_confirmation = true; |
|
722 | + EE_Registry::instance()->CFG->registration->reg_confirmation_last = true; |
|
723 | + // skip the registration_confirmation page ? |
|
724 | + if (EE_Registry::instance()->CFG->registration->skip_reg_confirmation) { |
|
725 | + // just remove it from the reg steps array |
|
726 | + $this->checkout->remove_reg_step('registration_confirmation', false); |
|
727 | + } else if ( |
|
728 | + isset($this->checkout->reg_steps['registration_confirmation']) |
|
729 | + && EE_Registry::instance()->CFG->registration->reg_confirmation_last |
|
730 | + ) { |
|
731 | + // set the order to something big like 100 |
|
732 | + $this->checkout->set_reg_step_order('registration_confirmation', 100); |
|
733 | + } |
|
734 | + // filter the array for good luck |
|
735 | + $this->checkout->reg_steps = apply_filters( |
|
736 | + 'FHEE__Single_Page_Checkout__load_reg_steps__reg_steps', |
|
737 | + $this->checkout->reg_steps |
|
738 | + ); |
|
739 | + // finally re-sort based on the reg step class order properties |
|
740 | + $this->checkout->sort_reg_steps(); |
|
741 | + } else { |
|
742 | + foreach ($this->checkout->reg_steps as $reg_step) { |
|
743 | + // set all current step stati to FALSE |
|
744 | + $reg_step->set_is_current_step(false); |
|
745 | + } |
|
746 | + } |
|
747 | + if (empty($this->checkout->reg_steps)) { |
|
748 | + EE_Error::add_error(__('No Reg Steps were loaded..', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
749 | + return false; |
|
750 | + } |
|
751 | + // make reg step details available to JS |
|
752 | + $this->checkout->set_reg_step_JSON_info(); |
|
753 | + return true; |
|
754 | + } |
|
755 | + |
|
756 | + |
|
757 | + |
|
758 | + /** |
|
759 | + * _load_and_instantiate_reg_step |
|
760 | + * |
|
761 | + * @access private |
|
762 | + * @param array $reg_step |
|
763 | + * @param int $order |
|
764 | + * @return bool |
|
765 | + */ |
|
766 | + private function _load_and_instantiate_reg_step($reg_step = array(), $order = 0) |
|
767 | + { |
|
768 | + // we need a file_path, class_name, and slug to add a reg step |
|
769 | + if (isset($reg_step['file_path'], $reg_step['class_name'], $reg_step['slug'])) { |
|
770 | + // if editing a specific step, but this is NOT that step... (and it's not the 'finalize_registration' step) |
|
771 | + if ( |
|
772 | + $this->checkout->reg_url_link |
|
773 | + && $this->checkout->step !== $reg_step['slug'] |
|
774 | + && $reg_step['slug'] !== 'finalize_registration' |
|
775 | + // normally at this point we would NOT load the reg step, but this filter can change that |
|
776 | + && apply_filters( |
|
777 | + 'FHEE__Single_Page_Checkout___load_and_instantiate_reg_step__bypass_reg_step', |
|
778 | + true, |
|
779 | + $reg_step, |
|
780 | + $this->checkout |
|
781 | + ) |
|
782 | + ) { |
|
783 | + return true; |
|
784 | + } |
|
785 | + // instantiate step class using file path and class name |
|
786 | + $reg_step_obj = EE_Registry::instance()->load_file( |
|
787 | + $reg_step['file_path'], |
|
788 | + $reg_step['class_name'], |
|
789 | + 'class', |
|
790 | + $this->checkout, |
|
791 | + false |
|
792 | + ); |
|
793 | + // did we gets the goods ? |
|
794 | + if ($reg_step_obj instanceof EE_SPCO_Reg_Step) { |
|
795 | + // set reg step order based on config |
|
796 | + $reg_step_obj->set_order($order); |
|
797 | + // add instantiated reg step object to the master reg steps array |
|
798 | + $this->checkout->add_reg_step($reg_step_obj); |
|
799 | + } else { |
|
800 | + EE_Error::add_error( |
|
801 | + __('The current step could not be set.', 'event_espresso'), |
|
802 | + __FILE__, __FUNCTION__, __LINE__ |
|
803 | + ); |
|
804 | + return false; |
|
805 | + } |
|
806 | + } else { |
|
807 | + if (WP_DEBUG) { |
|
808 | + EE_Error::add_error( |
|
809 | + sprintf( |
|
810 | + __('A registration step could not be loaded. One or more of the following data points is invalid:%4$s%5$sFile Path: %1$s%6$s%5$sClass Name: %2$s%6$s%5$sSlug: %3$s%6$s%7$s', 'event_espresso'), |
|
811 | + isset($reg_step['file_path']) ? $reg_step['file_path'] : '', |
|
812 | + isset($reg_step['class_name']) ? $reg_step['class_name'] : '', |
|
813 | + isset($reg_step['slug']) ? $reg_step['slug'] : '', |
|
814 | + '<ul>', |
|
815 | + '<li>', |
|
816 | + '</li>', |
|
817 | + '</ul>' |
|
818 | + ), |
|
819 | + __FILE__, __FUNCTION__, __LINE__ |
|
820 | + ); |
|
821 | + } |
|
822 | + return false; |
|
823 | + } |
|
824 | + return true; |
|
825 | + } |
|
826 | + |
|
827 | + |
|
828 | + |
|
829 | + /** |
|
830 | + * _verify_transaction_and_get_registrations |
|
831 | + * |
|
832 | + * @access private |
|
833 | + * @return bool |
|
834 | + */ |
|
835 | + private function _verify_transaction_and_get_registrations() |
|
836 | + { |
|
837 | + // was there already a valid transaction in the checkout from the session ? |
|
838 | + if ( ! $this->checkout->transaction instanceof EE_Transaction) { |
|
839 | + // get transaction from db or session |
|
840 | + $this->checkout->transaction = $this->checkout->reg_url_link && ! is_admin() |
|
841 | + ? $this->_get_transaction_and_cart_for_previous_visit() |
|
842 | + : $this->_get_cart_for_current_session_and_setup_new_transaction(); |
|
843 | + if ( ! $this->checkout->transaction instanceof EE_Transaction) { |
|
844 | + EE_Error::add_error( |
|
845 | + __('Your Registration and Transaction information could not be retrieved from the db.', |
|
846 | + 'event_espresso'), |
|
847 | + __FILE__, __FUNCTION__, __LINE__ |
|
848 | + ); |
|
849 | + $this->checkout->transaction = EE_Transaction::new_instance(); |
|
850 | + // add some style and make it dance |
|
851 | + $this->add_styles_and_scripts(); |
|
852 | + EED_Single_Page_Checkout::$_initialized = true; |
|
853 | + return false; |
|
854 | + } |
|
855 | + // and the registrations for the transaction |
|
856 | + $this->_get_registrations($this->checkout->transaction); |
|
857 | + } |
|
858 | + return true; |
|
859 | + } |
|
860 | + |
|
861 | + |
|
862 | + |
|
863 | + /** |
|
864 | + * _get_transaction_and_cart_for_previous_visit |
|
865 | + * |
|
866 | + * @access private |
|
867 | + * @return mixed EE_Transaction|NULL |
|
868 | + */ |
|
869 | + private function _get_transaction_and_cart_for_previous_visit() |
|
870 | + { |
|
871 | + /** @var $TXN_model EEM_Transaction */ |
|
872 | + $TXN_model = EE_Registry::instance()->load_model('Transaction'); |
|
873 | + // because the reg_url_link is present in the request, this is a return visit to SPCO, so we'll get the transaction data from the db |
|
874 | + $transaction = $TXN_model->get_transaction_from_reg_url_link($this->checkout->reg_url_link); |
|
875 | + // verify transaction |
|
876 | + if ($transaction instanceof EE_Transaction) { |
|
877 | + // and get the cart that was used for that transaction |
|
878 | + $this->checkout->cart = $this->_get_cart_for_transaction($transaction); |
|
879 | + return $transaction; |
|
880 | + } else { |
|
881 | + EE_Error::add_error(__('Your Registration and Transaction information could not be retrieved from the db.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
882 | + return null; |
|
883 | + } |
|
884 | + } |
|
885 | + |
|
886 | + |
|
887 | + |
|
888 | + /** |
|
889 | + * _get_cart_for_transaction |
|
890 | + * |
|
891 | + * @access private |
|
892 | + * @param EE_Transaction $transaction |
|
893 | + * @return EE_Cart |
|
894 | + */ |
|
895 | + private function _get_cart_for_transaction($transaction) |
|
896 | + { |
|
897 | + return $this->checkout->get_cart_for_transaction($transaction); |
|
898 | + } |
|
899 | + |
|
900 | + |
|
901 | + |
|
902 | + /** |
|
903 | + * get_cart_for_transaction |
|
904 | + * |
|
905 | + * @access public |
|
906 | + * @param EE_Transaction $transaction |
|
907 | + * @return EE_Cart |
|
908 | + */ |
|
909 | + public function get_cart_for_transaction(EE_Transaction $transaction) |
|
910 | + { |
|
911 | + return $this->checkout->get_cart_for_transaction($transaction); |
|
912 | + } |
|
913 | + |
|
914 | + |
|
915 | + |
|
916 | + /** |
|
917 | + * _get_transaction_and_cart_for_current_session |
|
918 | + * generates a new EE_Transaction object and adds it to the $_transaction property. |
|
919 | + * |
|
920 | + * @access private |
|
921 | + * @return EE_Transaction |
|
922 | + * @throws \EE_Error |
|
923 | + */ |
|
924 | + private function _get_cart_for_current_session_and_setup_new_transaction() |
|
925 | + { |
|
926 | + // if there's no transaction, then this is the FIRST visit to SPCO |
|
927 | + // so load up the cart ( passing nothing for the TXN because it doesn't exist yet ) |
|
928 | + $this->checkout->cart = $this->_get_cart_for_transaction(null); |
|
929 | + // and then create a new transaction |
|
930 | + $transaction = $this->_initialize_transaction(); |
|
931 | + // verify transaction |
|
932 | + if ($transaction instanceof EE_Transaction) { |
|
933 | + // save it so that we have an ID for other objects to use |
|
934 | + $transaction->save(); |
|
935 | + // and save TXN data to the cart |
|
936 | + $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn($transaction->ID()); |
|
937 | + } else { |
|
938 | + EE_Error::add_error(__('A Valid Transaction could not be initialized.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
939 | + } |
|
940 | + return $transaction; |
|
941 | + } |
|
942 | + |
|
943 | + |
|
944 | + |
|
945 | + /** |
|
946 | + * generates a new EE_Transaction object and adds it to the $_transaction property. |
|
947 | + * |
|
948 | + * @access private |
|
949 | + * @return mixed EE_Transaction|NULL |
|
950 | + */ |
|
951 | + private function _initialize_transaction() |
|
952 | + { |
|
953 | + try { |
|
954 | + // ensure cart totals have been calculated |
|
955 | + $this->checkout->cart->get_grand_total()->recalculate_total_including_taxes(); |
|
956 | + // grab the cart grand total |
|
957 | + $cart_total = $this->checkout->cart->get_cart_grand_total(); |
|
958 | + // create new TXN |
|
959 | + $transaction = EE_Transaction::new_instance( |
|
960 | + array( |
|
961 | + 'TXN_reg_steps' => $this->checkout->initialize_txn_reg_steps_array(), |
|
962 | + 'TXN_total' => $cart_total > 0 ? $cart_total : 0, |
|
963 | + 'TXN_paid' => 0, |
|
964 | + 'STS_ID' => EEM_Transaction::failed_status_code, |
|
965 | + ) |
|
966 | + ); |
|
967 | + // save it so that we have an ID for other objects to use |
|
968 | + $transaction->save(); |
|
969 | + // set cron job for following up on TXNs after their session has expired |
|
970 | + EE_Cron_Tasks::schedule_expired_transaction_check( |
|
971 | + EE_Registry::instance()->SSN->expiration() + 1, |
|
972 | + $transaction->ID() |
|
973 | + ); |
|
974 | + return $transaction; |
|
975 | + } catch (Exception $e) { |
|
976 | + EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__); |
|
977 | + } |
|
978 | + return null; |
|
979 | + } |
|
980 | + |
|
981 | + |
|
982 | + |
|
983 | + /** |
|
984 | + * _get_registrations |
|
985 | + * |
|
986 | + * @access private |
|
987 | + * @param EE_Transaction $transaction |
|
988 | + * @return void |
|
989 | + * @throws \EventEspresso\core\exceptions\InvalidEntityException |
|
990 | + * @throws \EE_Error |
|
991 | + */ |
|
992 | + private function _get_registrations(EE_Transaction $transaction) |
|
993 | + { |
|
994 | + // first step: grab the registrants { : o |
|
995 | + $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, true); |
|
996 | + // verify registrations have been set |
|
997 | + if (empty($registrations)) { |
|
998 | + // if no cached registrations, then check the db |
|
999 | + $registrations = $transaction->registrations($this->checkout->reg_cache_where_params, false); |
|
1000 | + // still nothing ? well as long as this isn't a revisit |
|
1001 | + if (empty($registrations) && ! $this->checkout->revisit) { |
|
1002 | + // generate new registrations from scratch |
|
1003 | + $registrations = $this->_initialize_registrations($transaction); |
|
1004 | + } |
|
1005 | + } |
|
1006 | + // sort by their original registration order |
|
1007 | + usort($registrations, array('EED_Single_Page_Checkout', 'sort_registrations_by_REG_count')); |
|
1008 | + // then loop thru the array |
|
1009 | + foreach ($registrations as $registration) { |
|
1010 | + // verify each registration |
|
1011 | + if ($registration instanceof EE_Registration) { |
|
1012 | + // we display all attendee info for the primary registrant |
|
1013 | + if ($this->checkout->reg_url_link === $registration->reg_url_link() |
|
1014 | + && $registration->is_primary_registrant() |
|
1015 | + ) { |
|
1016 | + $this->checkout->primary_revisit = true; |
|
1017 | + break; |
|
1018 | + } else if ($this->checkout->revisit |
|
1019 | + && $this->checkout->reg_url_link !== $registration->reg_url_link() |
|
1020 | + ) { |
|
1021 | + // but hide info if it doesn't belong to you |
|
1022 | + $transaction->clear_cache('Registration', $registration->ID()); |
|
1023 | + } |
|
1024 | + $this->checkout->set_reg_status_updated($registration->ID(), false); |
|
1025 | + } |
|
1026 | + } |
|
1027 | + } |
|
1028 | + |
|
1029 | + |
|
1030 | + |
|
1031 | + /** |
|
1032 | + * adds related EE_Registration objects for each ticket in the cart to the current EE_Transaction object |
|
1033 | + * |
|
1034 | + * @access private |
|
1035 | + * @param EE_Transaction $transaction |
|
1036 | + * @return array |
|
1037 | + * @throws \EventEspresso\core\exceptions\InvalidEntityException |
|
1038 | + * @throws \EE_Error |
|
1039 | + */ |
|
1040 | + private function _initialize_registrations(EE_Transaction $transaction) |
|
1041 | + { |
|
1042 | + $att_nmbr = 0; |
|
1043 | + $registrations = array(); |
|
1044 | + if ($transaction instanceof EE_Transaction) { |
|
1045 | + /** @type EE_Registration_Processor $registration_processor */ |
|
1046 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
1047 | + $this->checkout->total_ticket_count = $this->checkout->cart->all_ticket_quantity_count(); |
|
1048 | + // now let's add the cart items to the $transaction |
|
1049 | + foreach ($this->checkout->cart->get_tickets() as $line_item) { |
|
1050 | + //do the following for each ticket of this type they selected |
|
1051 | + for ($x = 1; $x <= $line_item->quantity(); $x++) { |
|
1052 | + $att_nmbr++; |
|
1053 | + /** @var EventEspresso\core\services\commands\registration\CreateRegistrationCommand $CreateRegistrationCommand */ |
|
1054 | + $CreateRegistrationCommand = EE_Registry::instance() |
|
1055 | + ->create( |
|
1056 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
1057 | + array( |
|
1058 | + $transaction, |
|
1059 | + $line_item, |
|
1060 | + $att_nmbr, |
|
1061 | + $this->checkout->total_ticket_count, |
|
1062 | + ) |
|
1063 | + ); |
|
1064 | + // override capabilities for frontend registrations |
|
1065 | + if ( ! is_admin()) { |
|
1066 | + $CreateRegistrationCommand->setCapCheck( |
|
1067 | + new PublicCapabilities('', 'create_new_registration') |
|
1068 | + ); |
|
1069 | + } |
|
1070 | + $registration = EE_Registry::instance()->BUS->execute($CreateRegistrationCommand); |
|
1071 | + if ( ! $registration instanceof EE_Registration) { |
|
1072 | + throw new InvalidEntityException($registration, 'EE_Registration'); |
|
1073 | + } |
|
1074 | + $registrations[ $registration->ID() ] = $registration; |
|
1075 | + } |
|
1076 | + } |
|
1077 | + $registration_processor->fix_reg_final_price_rounding_issue($transaction); |
|
1078 | + } |
|
1079 | + return $registrations; |
|
1080 | + } |
|
1081 | + |
|
1082 | + |
|
1083 | + |
|
1084 | + /** |
|
1085 | + * sorts registrations by REG_count |
|
1086 | + * |
|
1087 | + * @access public |
|
1088 | + * @param EE_Registration $reg_A |
|
1089 | + * @param EE_Registration $reg_B |
|
1090 | + * @return int |
|
1091 | + */ |
|
1092 | + public static function sort_registrations_by_REG_count(EE_Registration $reg_A, EE_Registration $reg_B) |
|
1093 | + { |
|
1094 | + // this shouldn't ever happen within the same TXN, but oh well |
|
1095 | + if ($reg_A->count() === $reg_B->count()) { |
|
1096 | + return 0; |
|
1097 | + } |
|
1098 | + return ($reg_A->count() > $reg_B->count()) ? 1 : -1; |
|
1099 | + } |
|
1100 | + |
|
1101 | + |
|
1102 | + |
|
1103 | + /** |
|
1104 | + * _final_verifications |
|
1105 | + * just makes sure that everything is set up correctly before proceeding |
|
1106 | + * |
|
1107 | + * @access private |
|
1108 | + * @return bool |
|
1109 | + * @throws \EE_Error |
|
1110 | + */ |
|
1111 | + private function _final_verifications() |
|
1112 | + { |
|
1113 | + // filter checkout |
|
1114 | + $this->checkout = apply_filters('FHEE__EED_Single_Page_Checkout___final_verifications__checkout', $this->checkout); |
|
1115 | + //verify that current step is still set correctly |
|
1116 | + if ( ! $this->checkout->current_step instanceof EE_SPCO_Reg_Step) { |
|
1117 | + EE_Error::add_error( |
|
1118 | + __('We\'re sorry but the registration process can not proceed because one or more registration steps were not setup correctly. Please refresh the page and try again or contact support.', 'event_espresso'), |
|
1119 | + __FILE__, |
|
1120 | + __FUNCTION__, |
|
1121 | + __LINE__ |
|
1122 | + ); |
|
1123 | + return false; |
|
1124 | + } |
|
1125 | + // if returning to SPCO, then verify that primary registrant is set |
|
1126 | + if ( ! empty($this->checkout->reg_url_link)) { |
|
1127 | + $valid_registrant = $this->checkout->transaction->primary_registration(); |
|
1128 | + if ( ! $valid_registrant instanceof EE_Registration) { |
|
1129 | + EE_Error::add_error( |
|
1130 | + __('We\'re sorry but there appears to be an error with the "reg_url_link" or the primary registrant for this transaction. Please refresh the page and try again or contact support.', 'event_espresso'), |
|
1131 | + __FILE__, |
|
1132 | + __FUNCTION__, |
|
1133 | + __LINE__ |
|
1134 | + ); |
|
1135 | + return false; |
|
1136 | + } |
|
1137 | + $valid_registrant = null; |
|
1138 | + foreach ($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params) as $registration) { |
|
1139 | + if ( |
|
1140 | + $registration instanceof EE_Registration |
|
1141 | + && $registration->reg_url_link() === $this->checkout->reg_url_link |
|
1142 | + ) { |
|
1143 | + $valid_registrant = $registration; |
|
1144 | + } |
|
1145 | + } |
|
1146 | + if ( ! $valid_registrant instanceof EE_Registration) { |
|
1147 | + // hmmm... maybe we have the wrong session because the user is opening multiple tabs ? |
|
1148 | + if (EED_Single_Page_Checkout::$_checkout_verified) { |
|
1149 | + // clear the session, mark the checkout as unverified, and try again |
|
1150 | + EE_Registry::instance()->SSN->clear_session(); |
|
1151 | + EED_Single_Page_Checkout::$_initialized = false; |
|
1152 | + EED_Single_Page_Checkout::$_checkout_verified = false; |
|
1153 | + $this->_initialize(); |
|
1154 | + EE_Error::reset_notices(); |
|
1155 | + return false; |
|
1156 | + } |
|
1157 | + EE_Error::add_error( |
|
1158 | + __('We\'re sorry but there appears to be an error with the "reg_url_link" or the transaction itself. Please refresh the page and try again or contact support.', 'event_espresso'), |
|
1159 | + __FILE__, |
|
1160 | + __FUNCTION__, |
|
1161 | + __LINE__ |
|
1162 | + ); |
|
1163 | + return false; |
|
1164 | + } |
|
1165 | + } |
|
1166 | + // now that things have been kinda sufficiently verified, |
|
1167 | + // let's add the checkout to the session so that's available other systems |
|
1168 | + EE_Registry::instance()->SSN->set_checkout($this->checkout); |
|
1169 | + return true; |
|
1170 | + } |
|
1171 | + |
|
1172 | + |
|
1173 | + |
|
1174 | + /** |
|
1175 | + * _initialize_reg_steps |
|
1176 | + * first makes sure that EE_Transaction_Processor::set_reg_step_initiated() is called as required |
|
1177 | + * then loops thru all of the active reg steps and calls the initialize_reg_step() method |
|
1178 | + * |
|
1179 | + * @access private |
|
1180 | + * @param bool $reinitializing |
|
1181 | + * @throws \EE_Error |
|
1182 | + */ |
|
1183 | + private function _initialize_reg_steps($reinitializing = false) |
|
1184 | + { |
|
1185 | + $this->checkout->set_reg_step_initiated($this->checkout->current_step); |
|
1186 | + // loop thru all steps to call their individual "initialize" methods and set i18n strings for JS |
|
1187 | + foreach ($this->checkout->reg_steps as $reg_step) { |
|
1188 | + if ( ! $reg_step->initialize_reg_step()) { |
|
1189 | + // if not initialized then maybe this step is being removed... |
|
1190 | + if ( ! $reinitializing && $reg_step->is_current_step()) { |
|
1191 | + // if it was the current step, then we need to start over here |
|
1192 | + $this->_initialize_reg_steps(true); |
|
1193 | + return; |
|
1194 | + } |
|
1195 | + continue; |
|
1196 | + } |
|
1197 | + // add css and JS for current step |
|
1198 | + $reg_step->enqueue_styles_and_scripts(); |
|
1199 | + // i18n |
|
1200 | + $reg_step->translate_js_strings(); |
|
1201 | + if ($reg_step->is_current_step()) { |
|
1202 | + // the text that appears on the reg step form submit button |
|
1203 | + $reg_step->set_submit_button_text(); |
|
1204 | + } |
|
1205 | + } |
|
1206 | + // dynamically creates hook point like: AHEE__Single_Page_Checkout___initialize_reg_step__attendee_information |
|
1207 | + do_action("AHEE__Single_Page_Checkout___initialize_reg_step__{$this->checkout->current_step->slug()}", $this->checkout->current_step); |
|
1208 | + } |
|
1209 | + |
|
1210 | + |
|
1211 | + |
|
1212 | + /** |
|
1213 | + * _check_form_submission |
|
1214 | + * |
|
1215 | + * @access private |
|
1216 | + * @return boolean |
|
1217 | + */ |
|
1218 | + private function _check_form_submission() |
|
1219 | + { |
|
1220 | + //does this request require the reg form to be generated ? |
|
1221 | + if ($this->checkout->generate_reg_form) { |
|
1222 | + // ever heard that song by Blue Rodeo ? |
|
1223 | + try { |
|
1224 | + $this->checkout->current_step->reg_form = $this->checkout->current_step->generate_reg_form(); |
|
1225 | + // if not displaying a form, then check for form submission |
|
1226 | + if ( |
|
1227 | + $this->checkout->process_form_submission |
|
1228 | + && $this->checkout->current_step->reg_form->was_submitted() |
|
1229 | + ) { |
|
1230 | + // clear out any old data in case this step is being run again |
|
1231 | + $this->checkout->current_step->set_valid_data(array()); |
|
1232 | + // capture submitted form data |
|
1233 | + $this->checkout->current_step->reg_form->receive_form_submission( |
|
1234 | + apply_filters('FHEE__Single_Page_Checkout___check_form_submission__request_params', EE_Registry::instance()->REQ->params(), $this->checkout) |
|
1235 | + ); |
|
1236 | + // validate submitted form data |
|
1237 | + if ( ! $this->checkout->continue_reg || ! $this->checkout->current_step->reg_form->is_valid()) { |
|
1238 | + // thou shall not pass !!! |
|
1239 | + $this->checkout->continue_reg = false; |
|
1240 | + // any form validation errors? |
|
1241 | + if ($this->checkout->current_step->reg_form->submission_error_message() !== '') { |
|
1242 | + $submission_error_messages = array(); |
|
1243 | + // bad, bad, bad registrant |
|
1244 | + foreach ($this->checkout->current_step->reg_form->get_validation_errors_accumulated() as $validation_error) { |
|
1245 | + if ($validation_error instanceof EE_Validation_Error) { |
|
1246 | + $submission_error_messages[] = sprintf( |
|
1247 | + __('%s : %s', 'event_espresso'), |
|
1248 | + $validation_error->get_form_section()->html_label_text(), |
|
1249 | + $validation_error->getMessage() |
|
1250 | + ); |
|
1251 | + } |
|
1252 | + } |
|
1253 | + EE_Error::add_error(implode('<br />', $submission_error_messages), __FILE__, __FUNCTION__, __LINE__); |
|
1254 | + } |
|
1255 | + // well not really... what will happen is we'll just get redirected back to redo the current step |
|
1256 | + $this->go_to_next_step(); |
|
1257 | + return false; |
|
1258 | + } |
|
1259 | + } |
|
1260 | + } catch (EE_Error $e) { |
|
1261 | + $e->get_error(); |
|
1262 | + } |
|
1263 | + } |
|
1264 | + return true; |
|
1265 | + } |
|
1266 | + |
|
1267 | + |
|
1268 | + |
|
1269 | + /** |
|
1270 | + * _process_action |
|
1271 | + * |
|
1272 | + * @access private |
|
1273 | + * @return void |
|
1274 | + * @throws \EE_Error |
|
1275 | + */ |
|
1276 | + private function _process_form_action() |
|
1277 | + { |
|
1278 | + // what cha wanna do? |
|
1279 | + switch ($this->checkout->action) { |
|
1280 | + // AJAX next step reg form |
|
1281 | + case 'display_spco_reg_step' : |
|
1282 | + $this->checkout->redirect = false; |
|
1283 | + if (EE_Registry::instance()->REQ->ajax) { |
|
1284 | + $this->checkout->json_response->set_reg_step_html($this->checkout->current_step->display_reg_form()); |
|
1285 | + } |
|
1286 | + break; |
|
1287 | + default : |
|
1288 | + // meh... do one of those other steps first |
|
1289 | + if ( ! empty($this->checkout->action) && is_callable(array($this->checkout->current_step, $this->checkout->action))) { |
|
1290 | + // dynamically creates hook point like: AHEE__Single_Page_Checkout__before_attendee_information__process_reg_step |
|
1291 | + do_action("AHEE__Single_Page_Checkout__before_{$this->checkout->current_step->slug()}__{$this->checkout->action}", $this->checkout->current_step); |
|
1292 | + // call action on current step |
|
1293 | + if (call_user_func(array($this->checkout->current_step, $this->checkout->action))) { |
|
1294 | + // good registrant, you get to proceed |
|
1295 | + if ( |
|
1296 | + $this->checkout->current_step->success_message() !== '' |
|
1297 | + && apply_filters( |
|
1298 | + 'FHEE__Single_Page_Checkout___process_form_action__display_success', |
|
1299 | + false |
|
1300 | + ) |
|
1301 | + ) { |
|
1302 | + EE_Error::add_success( |
|
1303 | + $this->checkout->current_step->success_message() |
|
1304 | + . '<br />' . $this->checkout->next_step->_instructions() |
|
1305 | + ); |
|
1306 | + } |
|
1307 | + // pack it up, pack it in... |
|
1308 | + $this->_setup_redirect(); |
|
1309 | + } |
|
1310 | + // dynamically creates hook point like: AHEE__Single_Page_Checkout__after_payment_options__process_reg_step |
|
1311 | + do_action("AHEE__Single_Page_Checkout__after_{$this->checkout->current_step->slug()}__{$this->checkout->action}", $this->checkout->current_step); |
|
1312 | + } else { |
|
1313 | + EE_Error::add_error( |
|
1314 | + sprintf( |
|
1315 | + __('The requested form action "%s" does not exist for the current "%s" registration step.', 'event_espresso'), |
|
1316 | + $this->checkout->action, |
|
1317 | + $this->checkout->current_step->name() |
|
1318 | + ), |
|
1319 | + __FILE__, |
|
1320 | + __FUNCTION__, |
|
1321 | + __LINE__ |
|
1322 | + ); |
|
1323 | + } |
|
1324 | + // end default |
|
1325 | + } |
|
1326 | + // store our progress so far |
|
1327 | + $this->checkout->stash_transaction_and_checkout(); |
|
1328 | + // advance to the next step! If you pass GO, collect $200 |
|
1329 | + $this->go_to_next_step(); |
|
1330 | + } |
|
1331 | + |
|
1332 | + |
|
1333 | + |
|
1334 | + /** |
|
1335 | + * add_styles_and_scripts |
|
1336 | + * |
|
1337 | + * @access public |
|
1338 | + * @return void |
|
1339 | + */ |
|
1340 | + public function add_styles_and_scripts() |
|
1341 | + { |
|
1342 | + // i18n |
|
1343 | + $this->translate_js_strings(); |
|
1344 | + if ($this->checkout->admin_request) { |
|
1345 | + add_action('admin_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
1346 | + } else { |
|
1347 | + add_action('wp_enqueue_scripts', array($this, 'enqueue_styles_and_scripts'), 10); |
|
1348 | + } |
|
1349 | + } |
|
1350 | + |
|
1351 | + |
|
1352 | + |
|
1353 | + /** |
|
1354 | + * translate_js_strings |
|
1355 | + * |
|
1356 | + * @access public |
|
1357 | + * @return void |
|
1358 | + */ |
|
1359 | + public function translate_js_strings() |
|
1360 | + { |
|
1361 | + EE_Registry::$i18n_js_strings['revisit'] = $this->checkout->revisit; |
|
1362 | + EE_Registry::$i18n_js_strings['e_reg_url_link'] = $this->checkout->reg_url_link; |
|
1363 | + EE_Registry::$i18n_js_strings['server_error'] = __('An unknown error occurred on the server while attempting to process your request. Please refresh the page and try again or contact support.', 'event_espresso'); |
|
1364 | + EE_Registry::$i18n_js_strings['invalid_json_response'] = __('An invalid response was returned from the server while attempting to process your request. Please refresh the page and try again or contact support.', 'event_espresso'); |
|
1365 | + EE_Registry::$i18n_js_strings['validation_error'] = __('There appears to be a problem with the form validation configuration! Please check the admin settings or contact support.', 'event_espresso'); |
|
1366 | + EE_Registry::$i18n_js_strings['invalid_payment_method'] = __('There appears to be a problem with the payment method configuration! Please refresh the page and try again or contact support.', 'event_espresso'); |
|
1367 | + EE_Registry::$i18n_js_strings['reg_step_error'] = __('This registration step could not be completed. Please refresh the page and try again.', 'event_espresso'); |
|
1368 | + EE_Registry::$i18n_js_strings['invalid_coupon'] = __('We\'re sorry but that coupon code does not appear to be valid. If this is incorrect, please contact the site administrator.', 'event_espresso'); |
|
1369 | + EE_Registry::$i18n_js_strings['process_registration'] = sprintf( |
|
1370 | + __('Please wait while we process your registration.%sDo not refresh the page or navigate away while this is happening.%sThank you for your patience.', 'event_espresso'), |
|
1371 | + '<br/>', |
|
1372 | + '<br/>' |
|
1373 | + ); |
|
1374 | + EE_Registry::$i18n_js_strings['language'] = get_bloginfo('language'); |
|
1375 | + EE_Registry::$i18n_js_strings['EESID'] = EE_Registry::instance()->SSN->id(); |
|
1376 | + EE_Registry::$i18n_js_strings['currency'] = EE_Registry::instance()->CFG->currency; |
|
1377 | + EE_Registry::$i18n_js_strings['datepicker_yearRange'] = '-150:+20'; |
|
1378 | + EE_Registry::$i18n_js_strings['timer_years'] = __('years', 'event_espresso'); |
|
1379 | + EE_Registry::$i18n_js_strings['timer_months'] = __('months', 'event_espresso'); |
|
1380 | + EE_Registry::$i18n_js_strings['timer_weeks'] = __('weeks', 'event_espresso'); |
|
1381 | + EE_Registry::$i18n_js_strings['timer_days'] = __('days', 'event_espresso'); |
|
1382 | + EE_Registry::$i18n_js_strings['timer_hours'] = __('hours', 'event_espresso'); |
|
1383 | + EE_Registry::$i18n_js_strings['timer_minutes'] = __('minutes', 'event_espresso'); |
|
1384 | + EE_Registry::$i18n_js_strings['timer_seconds'] = __('seconds', 'event_espresso'); |
|
1385 | + EE_Registry::$i18n_js_strings['timer_year'] = __('year', 'event_espresso'); |
|
1386 | + EE_Registry::$i18n_js_strings['timer_month'] = __('month', 'event_espresso'); |
|
1387 | + EE_Registry::$i18n_js_strings['timer_week'] = __('week', 'event_espresso'); |
|
1388 | + EE_Registry::$i18n_js_strings['timer_day'] = __('day', 'event_espresso'); |
|
1389 | + EE_Registry::$i18n_js_strings['timer_hour'] = __('hour', 'event_espresso'); |
|
1390 | + EE_Registry::$i18n_js_strings['timer_minute'] = __('minute', 'event_espresso'); |
|
1391 | + EE_Registry::$i18n_js_strings['timer_second'] = __('second', 'event_espresso'); |
|
1392 | + EE_Registry::$i18n_js_strings['registration_expiration_notice'] = sprintf( |
|
1393 | + __( |
|
1394 | + '%1$sWe\'re sorry, but your registration time has expired.%2$s%3$s%4$sIf you still wish to complete your registration, please return to the %5$sEvent List%6$sEvent List%7$s and reselect your tickets if available. Please except our apologies for any inconvenience this may have caused.%8$s', |
|
1395 | + 'event_espresso' |
|
1396 | + ), |
|
1397 | + '<h4 class="important-notice">', |
|
1398 | + '</h4>', |
|
1399 | + '<br />', |
|
1400 | + '<p>', |
|
1401 | + '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
1402 | + '">', |
|
1403 | + '</a>', |
|
1404 | + '</p>' |
|
1405 | + ); |
|
1406 | + EE_Registry::$i18n_js_strings['ajax_submit'] = apply_filters('FHEE__Single_Page_Checkout__translate_js_strings__ajax_submit', true); |
|
1407 | + EE_Registry::$i18n_js_strings['session_extension'] = absint( |
|
1408 | + apply_filters('FHEE__EE_Session__extend_expiration__seconds_added', 10 * MINUTE_IN_SECONDS) |
|
1409 | + ); |
|
1410 | + EE_Registry::$i18n_js_strings['session_expiration'] = gmdate( |
|
1411 | + 'M d, Y H:i:s', EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS) |
|
1412 | + ); |
|
1413 | + } |
|
1414 | + |
|
1415 | + |
|
1416 | + |
|
1417 | + /** |
|
1418 | + * enqueue_styles_and_scripts |
|
1419 | + * |
|
1420 | + * @access public |
|
1421 | + * @return void |
|
1422 | + * @throws \EE_Error |
|
1423 | + */ |
|
1424 | + public function enqueue_styles_and_scripts() |
|
1425 | + { |
|
1426 | + // load css |
|
1427 | + wp_register_style('single_page_checkout', SPCO_CSS_URL . 'single_page_checkout.css', array(), EVENT_ESPRESSO_VERSION); |
|
1428 | + wp_enqueue_style('single_page_checkout'); |
|
1429 | + // load JS |
|
1430 | + wp_register_script('jquery_plugin', EE_THIRD_PARTY_URL . 'jquery .plugin.min.js', array('jquery'), '1.0.1', true); |
|
1431 | + wp_register_script('jquery_countdown', EE_THIRD_PARTY_URL . 'jquery .countdown.min.js', array('jquery_plugin'), '2.0.2', true); |
|
1432 | + wp_register_script('single_page_checkout', SPCO_JS_URL . 'single_page_checkout.js', array('espresso_core', 'underscore', 'ee_form_section_validation', 'jquery_countdown'), EVENT_ESPRESSO_VERSION, true); |
|
1433 | + if ($this->checkout->registration_form instanceof EE_Form_Section_Proper) { |
|
1434 | + $this->checkout->registration_form->enqueue_js(); |
|
1435 | + } |
|
1436 | + if ($this->checkout->current_step->reg_form instanceof EE_Form_Section_Proper) { |
|
1437 | + $this->checkout->current_step->reg_form->enqueue_js(); |
|
1438 | + } |
|
1439 | + wp_enqueue_script('single_page_checkout'); |
|
1440 | + /** |
|
1441 | + * global action hook for enqueueing styles and scripts with |
|
1442 | + * spco calls. |
|
1443 | + */ |
|
1444 | + do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts', $this); |
|
1445 | + /** |
|
1446 | + * dynamic action hook for enqueueing styles and scripts with spco calls. |
|
1447 | + * The hook will end up being something like AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__attendee_information |
|
1448 | + */ |
|
1449 | + do_action('AHEE__EED_Single_Page_Checkout__enqueue_styles_and_scripts__' . $this->checkout->current_step->slug(), $this); |
|
1450 | + } |
|
1451 | + |
|
1452 | + |
|
1453 | + |
|
1454 | + /** |
|
1455 | + * display the Registration Single Page Checkout Form |
|
1456 | + * |
|
1457 | + * @access private |
|
1458 | + * @return void |
|
1459 | + * @throws \EE_Error |
|
1460 | + */ |
|
1461 | + private function _display_spco_reg_form() |
|
1462 | + { |
|
1463 | + // if registering via the admin, just display the reg form for the current step |
|
1464 | + if ($this->checkout->admin_request) { |
|
1465 | + EE_Registry::instance()->REQ->add_output($this->checkout->current_step->display_reg_form()); |
|
1466 | + } else { |
|
1467 | + // add powered by EE msg |
|
1468 | + add_action('AHEE__SPCO__reg_form_footer', array('EED_Single_Page_Checkout', 'display_registration_footer')); |
|
1469 | + $empty_cart = count($this->checkout->transaction->registrations($this->checkout->reg_cache_where_params)) < 1 |
|
1470 | + ? true |
|
1471 | + : false; |
|
1472 | + EE_Registry::$i18n_js_strings['empty_cart'] = $empty_cart; |
|
1473 | + $cookies_not_set_msg = ''; |
|
1474 | + if ($empty_cart && ! isset($_COOKIE['ee_cookie_test'])) { |
|
1475 | + $cookies_not_set_msg = apply_filters( |
|
1476 | + 'FHEE__Single_Page_Checkout__display_spco_reg_form__cookies_not_set_msg', |
|
1477 | + sprintf( |
|
1478 | + __( |
|
1479 | + '%1$s%3$sIt appears your browser is not currently set to accept Cookies%4$s%5$sIn order to register for events, you need to enable cookies.%7$sIf you require assistance, then click the following link to learn how to %8$senable cookies%9$s%6$s%2$s', |
|
1480 | + 'event_espresso' |
|
1481 | + ), |
|
1482 | + '<div class="ee-attention">', |
|
1483 | + '</div>', |
|
1484 | + '<h6 class="important-notice">', |
|
1485 | + '</h6>', |
|
1486 | + '<p>', |
|
1487 | + '</p>', |
|
1488 | + '<br />', |
|
1489 | + '<a href="http://www.whatarecookies.com/enable.asp" target="_blank">', |
|
1490 | + '</a>' |
|
1491 | + ) |
|
1492 | + ); |
|
1493 | + } |
|
1494 | + $this->checkout->registration_form = new EE_Form_Section_Proper( |
|
1495 | + array( |
|
1496 | + 'name' => 'single-page-checkout', |
|
1497 | + 'html_id' => 'ee-single-page-checkout-dv', |
|
1498 | + 'layout_strategy' => |
|
1499 | + new EE_Template_Layout( |
|
1500 | + array( |
|
1501 | + 'layout_template_file' => SPCO_TEMPLATES_PATH . 'registration_page_wrapper.template.php', |
|
1502 | + 'template_args' => array( |
|
1503 | + 'empty_cart' => $empty_cart, |
|
1504 | + 'revisit' => $this->checkout->revisit, |
|
1505 | + 'reg_steps' => $this->checkout->reg_steps, |
|
1506 | + 'next_step' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
|
1507 | + ? $this->checkout->next_step->slug() |
|
1508 | + : '', |
|
1509 | + 'cancel_page_url' => $this->checkout->cancel_page_url, |
|
1510 | + 'empty_msg' => apply_filters( |
|
1511 | + 'FHEE__Single_Page_Checkout__display_spco_reg_form__empty_msg', |
|
1512 | + sprintf( |
|
1513 | + __('You need to %1$sReturn to Events list%2$sselect at least one event%3$s before you can proceed with the registration process.', |
|
1514 | + 'event_espresso'), |
|
1515 | + '<a href="' . get_post_type_archive_link('espresso_events') . '" title="', |
|
1516 | + '">', |
|
1517 | + '</a>' |
|
1518 | + ) |
|
1519 | + ), |
|
1520 | + 'cookies_not_set_msg' => $cookies_not_set_msg, |
|
1521 | + 'registration_time_limit' => $this->checkout->get_registration_time_limit(), |
|
1522 | + 'session_expiration' => |
|
1523 | + date('M d, Y H:i:s', EE_Registry::instance()->SSN->expiration() + (get_option('gmt_offset') * HOUR_IN_SECONDS)), |
|
1524 | + ), |
|
1525 | + ) |
|
1526 | + ), |
|
1527 | + ) |
|
1528 | + ); |
|
1529 | + // load template and add to output sent that gets filtered into the_content() |
|
1530 | + EE_Registry::instance()->REQ->add_output($this->checkout->registration_form->get_html()); |
|
1531 | + } |
|
1532 | + } |
|
1533 | + |
|
1534 | + |
|
1535 | + |
|
1536 | + /** |
|
1537 | + * add_extra_finalize_registration_inputs |
|
1538 | + * |
|
1539 | + * @access public |
|
1540 | + * @param $next_step |
|
1541 | + * @internal param string $label |
|
1542 | + * @return void |
|
1543 | + */ |
|
1544 | + public function add_extra_finalize_registration_inputs($next_step) |
|
1545 | + { |
|
1546 | + if ($next_step === 'finalize_registration') { |
|
1547 | + echo '<div id="spco-extra-finalize_registration-inputs-dv"></div>'; |
|
1548 | + } |
|
1549 | + } |
|
1550 | + |
|
1551 | + |
|
1552 | + |
|
1553 | + /** |
|
1554 | + * display_registration_footer |
|
1555 | + * |
|
1556 | + * @access public |
|
1557 | + * @return string |
|
1558 | + */ |
|
1559 | + public static function display_registration_footer() |
|
1560 | + { |
|
1561 | + if ( |
|
1562 | + apply_filters( |
|
1563 | + 'FHEE__EE_Front__Controller__show_reg_footer', |
|
1564 | + EE_Registry::instance()->CFG->admin->show_reg_footer |
|
1565 | + ) |
|
1566 | + ) { |
|
1567 | + add_filter( |
|
1568 | + 'FHEE__EEH_Template__powered_by_event_espresso__url', |
|
1569 | + function ($url) { |
|
1570 | + return apply_filters('FHEE__EE_Front_Controller__registration_footer__url', $url); |
|
1571 | + } |
|
1572 | + ); |
|
1573 | + echo apply_filters( |
|
1574 | + 'FHEE__EE_Front_Controller__display_registration_footer', |
|
1575 | + \EEH_Template::powered_by_event_espresso( |
|
1576 | + '', |
|
1577 | + 'espresso-registration-footer-dv', |
|
1578 | + array('utm_content' => 'registration_checkout') |
|
1579 | + ) |
|
1580 | + ); |
|
1581 | + } |
|
1582 | + return ''; |
|
1583 | + } |
|
1584 | + |
|
1585 | + |
|
1586 | + |
|
1587 | + /** |
|
1588 | + * unlock_transaction |
|
1589 | + * |
|
1590 | + * @access public |
|
1591 | + * @return void |
|
1592 | + * @throws \EE_Error |
|
1593 | + */ |
|
1594 | + public function unlock_transaction() |
|
1595 | + { |
|
1596 | + if ($this->checkout->transaction instanceof EE_Transaction) { |
|
1597 | + $this->checkout->transaction->unlock(); |
|
1598 | + } |
|
1599 | + } |
|
1600 | + |
|
1601 | + |
|
1602 | + |
|
1603 | + /** |
|
1604 | + * _setup_redirect |
|
1605 | + * |
|
1606 | + * @access private |
|
1607 | + * @return void |
|
1608 | + */ |
|
1609 | + private function _setup_redirect() |
|
1610 | + { |
|
1611 | + if ($this->checkout->continue_reg && $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
1612 | + $this->checkout->redirect = true; |
|
1613 | + if (empty($this->checkout->redirect_url)) { |
|
1614 | + $this->checkout->redirect_url = $this->checkout->next_step->reg_step_url(); |
|
1615 | + } |
|
1616 | + $this->checkout->redirect_url = apply_filters( |
|
1617 | + 'FHEE__EED_Single_Page_Checkout___setup_redirect__checkout_redirect_url', |
|
1618 | + $this->checkout->redirect_url, |
|
1619 | + $this->checkout |
|
1620 | + ); |
|
1621 | + } |
|
1622 | + } |
|
1623 | + |
|
1624 | + |
|
1625 | + |
|
1626 | + /** |
|
1627 | + * handle ajax message responses and redirects |
|
1628 | + * |
|
1629 | + * @access public |
|
1630 | + * @return void |
|
1631 | + * @throws \EE_Error |
|
1632 | + */ |
|
1633 | + public function go_to_next_step() |
|
1634 | + { |
|
1635 | + if (EE_Registry::instance()->REQ->ajax) { |
|
1636 | + // capture contents of output buffer we started earlier in the request, and insert into JSON response |
|
1637 | + $this->checkout->json_response->set_unexpected_errors(ob_get_clean()); |
|
1638 | + } |
|
1639 | + $this->unlock_transaction(); |
|
1640 | + // just return for these conditions |
|
1641 | + if ( |
|
1642 | + $this->checkout->admin_request |
|
1643 | + || $this->checkout->action === 'redirect_form' |
|
1644 | + || $this->checkout->action === 'update_checkout' |
|
1645 | + ) { |
|
1646 | + return; |
|
1647 | + } |
|
1648 | + // AJAX response |
|
1649 | + $this->_handle_json_response(); |
|
1650 | + // redirect to next step or the Thank You page |
|
1651 | + $this->_handle_html_redirects(); |
|
1652 | + // hmmm... must be something wrong, so let's just display the form again ! |
|
1653 | + $this->_display_spco_reg_form(); |
|
1654 | + } |
|
1655 | + |
|
1656 | + |
|
1657 | + |
|
1658 | + /** |
|
1659 | + * _handle_json_response |
|
1660 | + * |
|
1661 | + * @access protected |
|
1662 | + * @return void |
|
1663 | + */ |
|
1664 | + protected function _handle_json_response() |
|
1665 | + { |
|
1666 | + // if this is an ajax request |
|
1667 | + if (EE_Registry::instance()->REQ->ajax) { |
|
1668 | + // DEBUG LOG |
|
1669 | + //$this->checkout->log( |
|
1670 | + // __CLASS__, __FUNCTION__, __LINE__, |
|
1671 | + // array( |
|
1672 | + // 'json_response_redirect_url' => $this->checkout->json_response->redirect_url(), |
|
1673 | + // 'redirect' => $this->checkout->redirect, |
|
1674 | + // 'continue_reg' => $this->checkout->continue_reg, |
|
1675 | + // ) |
|
1676 | + //); |
|
1677 | + $this->checkout->json_response->set_registration_time_limit( |
|
1678 | + $this->checkout->get_registration_time_limit() |
|
1679 | + ); |
|
1680 | + $this->checkout->json_response->set_payment_amount($this->checkout->amount_owing); |
|
1681 | + // just send the ajax ( |
|
1682 | + $json_response = apply_filters( |
|
1683 | + 'FHEE__EE_Single_Page_Checkout__JSON_response', |
|
1684 | + $this->checkout->json_response |
|
1685 | + ); |
|
1686 | + echo $json_response; |
|
1687 | + exit(); |
|
1688 | + } |
|
1689 | + } |
|
1690 | + |
|
1691 | + |
|
1692 | + |
|
1693 | + /** |
|
1694 | + * _handle_redirects |
|
1695 | + * |
|
1696 | + * @access protected |
|
1697 | + * @return void |
|
1698 | + */ |
|
1699 | + protected function _handle_html_redirects() |
|
1700 | + { |
|
1701 | + // going somewhere ? |
|
1702 | + if ($this->checkout->redirect && ! empty($this->checkout->redirect_url)) { |
|
1703 | + // store notices in a transient |
|
1704 | + EE_Error::get_notices(false, true, true); |
|
1705 | + // DEBUG LOG |
|
1706 | + //$this->checkout->log( |
|
1707 | + // __CLASS__, __FUNCTION__, __LINE__, |
|
1708 | + // array( |
|
1709 | + // 'headers_sent' => headers_sent(), |
|
1710 | + // 'redirect_url' => $this->checkout->redirect_url, |
|
1711 | + // 'headers_list' => headers_list(), |
|
1712 | + // ) |
|
1713 | + //); |
|
1714 | + wp_safe_redirect($this->checkout->redirect_url); |
|
1715 | + exit(); |
|
1716 | + } |
|
1717 | + } |
|
1718 | + |
|
1719 | + |
|
1720 | + |
|
1721 | + /** |
|
1722 | + * set_checkout_anchor |
|
1723 | + * |
|
1724 | + * @access public |
|
1725 | + * @return void |
|
1726 | + */ |
|
1727 | + public function set_checkout_anchor() |
|
1728 | + { |
|
1729 | + echo '<a id="checkout" style="float: left; margin-left: -999em;"></a>'; |
|
1730 | + } |
|
1731 | 1731 | |
1732 | 1732 | |
1733 | 1733 |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | |
@@ -16,659 +16,659 @@ discard block |
||
16 | 16 | abstract class EE_SPCO_Reg_Step |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * $_completed - TRUE if this step has fully completed it's duties |
|
21 | - * |
|
22 | - * @access protected |
|
23 | - * @type bool $_completed |
|
24 | - */ |
|
25 | - protected $_completed = false; |
|
26 | - |
|
27 | - /** |
|
28 | - * $_is_current_step - TRUE if this is the current step |
|
29 | - * |
|
30 | - * @access protected |
|
31 | - * @type bool $_is_current_step |
|
32 | - */ |
|
33 | - protected $_is_current_step = false; |
|
34 | - |
|
35 | - /** |
|
36 | - * $_order - when the reg step should be run relative to other steps |
|
37 | - * |
|
38 | - * @access protected |
|
39 | - * @type int $_template |
|
40 | - */ |
|
41 | - protected $_order = 0; |
|
42 | - |
|
43 | - /** |
|
44 | - * $_slug - URL param for this step |
|
45 | - * |
|
46 | - * @access protected |
|
47 | - * @type string $_slug |
|
48 | - */ |
|
49 | - protected $_slug; |
|
50 | - |
|
51 | - /** |
|
52 | - * $_name - Step Name - translatable string |
|
53 | - * |
|
54 | - * @access protected |
|
55 | - * @type string $_slug |
|
56 | - */ |
|
57 | - protected $_name; |
|
58 | - |
|
59 | - /** |
|
60 | - * $_submit_button_text - translatable string that appears on this step's submit button |
|
61 | - * |
|
62 | - * @access protected |
|
63 | - * @type string $_slug |
|
64 | - */ |
|
65 | - protected $_submit_button_text; |
|
66 | - |
|
67 | - /** |
|
68 | - * $_template - template name |
|
69 | - * |
|
70 | - * @access protected |
|
71 | - * @type string $_template |
|
72 | - */ |
|
73 | - protected $_template; |
|
74 | - |
|
75 | - /** |
|
76 | - * $_reg_form_name - the form input name and id attribute |
|
77 | - * |
|
78 | - * @access protected |
|
79 | - * @var string $_reg_form_name |
|
80 | - */ |
|
81 | - protected $_reg_form_name; |
|
82 | - |
|
83 | - /** |
|
84 | - * $_success_message - text to display upon successful form submission |
|
85 | - * |
|
86 | - * @access private |
|
87 | - * @var string $_success_message |
|
88 | - */ |
|
89 | - protected $_success_message; |
|
90 | - |
|
91 | - /** |
|
92 | - * $_instructions - a brief description of how to complete the reg step. Usually displayed in conjunction with |
|
93 | - * the previous step's success message. |
|
94 | - * |
|
95 | - * @access private |
|
96 | - * @var string $_instructions |
|
97 | - */ |
|
98 | - protected $_instructions; |
|
99 | - |
|
100 | - /** |
|
101 | - * $_valid_data - the normalized and validated data for this step |
|
102 | - * |
|
103 | - * @access public |
|
104 | - * @var array $_valid_data |
|
105 | - */ |
|
106 | - protected $_valid_data = array(); |
|
107 | - |
|
108 | - /** |
|
109 | - * $reg_form - the registration form for this step |
|
110 | - * |
|
111 | - * @access public |
|
112 | - * @var EE_Form_Section_Proper $reg_form |
|
113 | - */ |
|
114 | - public $reg_form; |
|
115 | - |
|
116 | - /** |
|
117 | - * $checkout - EE_Checkout object for handling the properties of the current checkout process |
|
118 | - * |
|
119 | - * @access public |
|
120 | - * @var EE_Checkout $checkout |
|
121 | - */ |
|
122 | - public $checkout; |
|
123 | - |
|
124 | - |
|
125 | - |
|
126 | - /** |
|
127 | - * @return void |
|
128 | - */ |
|
129 | - abstract public function translate_js_strings(); |
|
130 | - |
|
131 | - |
|
19 | + /** |
|
20 | + * $_completed - TRUE if this step has fully completed it's duties |
|
21 | + * |
|
22 | + * @access protected |
|
23 | + * @type bool $_completed |
|
24 | + */ |
|
25 | + protected $_completed = false; |
|
26 | + |
|
27 | + /** |
|
28 | + * $_is_current_step - TRUE if this is the current step |
|
29 | + * |
|
30 | + * @access protected |
|
31 | + * @type bool $_is_current_step |
|
32 | + */ |
|
33 | + protected $_is_current_step = false; |
|
34 | + |
|
35 | + /** |
|
36 | + * $_order - when the reg step should be run relative to other steps |
|
37 | + * |
|
38 | + * @access protected |
|
39 | + * @type int $_template |
|
40 | + */ |
|
41 | + protected $_order = 0; |
|
42 | + |
|
43 | + /** |
|
44 | + * $_slug - URL param for this step |
|
45 | + * |
|
46 | + * @access protected |
|
47 | + * @type string $_slug |
|
48 | + */ |
|
49 | + protected $_slug; |
|
50 | + |
|
51 | + /** |
|
52 | + * $_name - Step Name - translatable string |
|
53 | + * |
|
54 | + * @access protected |
|
55 | + * @type string $_slug |
|
56 | + */ |
|
57 | + protected $_name; |
|
58 | + |
|
59 | + /** |
|
60 | + * $_submit_button_text - translatable string that appears on this step's submit button |
|
61 | + * |
|
62 | + * @access protected |
|
63 | + * @type string $_slug |
|
64 | + */ |
|
65 | + protected $_submit_button_text; |
|
66 | + |
|
67 | + /** |
|
68 | + * $_template - template name |
|
69 | + * |
|
70 | + * @access protected |
|
71 | + * @type string $_template |
|
72 | + */ |
|
73 | + protected $_template; |
|
74 | + |
|
75 | + /** |
|
76 | + * $_reg_form_name - the form input name and id attribute |
|
77 | + * |
|
78 | + * @access protected |
|
79 | + * @var string $_reg_form_name |
|
80 | + */ |
|
81 | + protected $_reg_form_name; |
|
82 | + |
|
83 | + /** |
|
84 | + * $_success_message - text to display upon successful form submission |
|
85 | + * |
|
86 | + * @access private |
|
87 | + * @var string $_success_message |
|
88 | + */ |
|
89 | + protected $_success_message; |
|
90 | + |
|
91 | + /** |
|
92 | + * $_instructions - a brief description of how to complete the reg step. Usually displayed in conjunction with |
|
93 | + * the previous step's success message. |
|
94 | + * |
|
95 | + * @access private |
|
96 | + * @var string $_instructions |
|
97 | + */ |
|
98 | + protected $_instructions; |
|
99 | + |
|
100 | + /** |
|
101 | + * $_valid_data - the normalized and validated data for this step |
|
102 | + * |
|
103 | + * @access public |
|
104 | + * @var array $_valid_data |
|
105 | + */ |
|
106 | + protected $_valid_data = array(); |
|
107 | + |
|
108 | + /** |
|
109 | + * $reg_form - the registration form for this step |
|
110 | + * |
|
111 | + * @access public |
|
112 | + * @var EE_Form_Section_Proper $reg_form |
|
113 | + */ |
|
114 | + public $reg_form; |
|
115 | + |
|
116 | + /** |
|
117 | + * $checkout - EE_Checkout object for handling the properties of the current checkout process |
|
118 | + * |
|
119 | + * @access public |
|
120 | + * @var EE_Checkout $checkout |
|
121 | + */ |
|
122 | + public $checkout; |
|
123 | + |
|
124 | + |
|
125 | + |
|
126 | + /** |
|
127 | + * @return void |
|
128 | + */ |
|
129 | + abstract public function translate_js_strings(); |
|
130 | + |
|
131 | + |
|
132 | 132 | |
133 | - /** |
|
134 | - * @return void |
|
135 | - */ |
|
136 | - abstract public function enqueue_styles_and_scripts(); |
|
137 | - |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * @return boolean |
|
142 | - */ |
|
143 | - abstract public function initialize_reg_step(); |
|
144 | - |
|
145 | - |
|
146 | - |
|
147 | - /** |
|
148 | - * @return string |
|
149 | - */ |
|
150 | - abstract public function generate_reg_form(); |
|
151 | - |
|
152 | - |
|
153 | - |
|
154 | - /** |
|
155 | - * @return boolean |
|
156 | - */ |
|
157 | - abstract public function process_reg_step(); |
|
158 | - |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * @return boolean |
|
163 | - */ |
|
164 | - abstract public function update_reg_step(); |
|
165 | - |
|
166 | - |
|
167 | - |
|
168 | - /** |
|
169 | - * @return boolean |
|
170 | - */ |
|
171 | - public function completed() |
|
172 | - { |
|
173 | - return $this->_completed; |
|
174 | - } |
|
133 | + /** |
|
134 | + * @return void |
|
135 | + */ |
|
136 | + abstract public function enqueue_styles_and_scripts(); |
|
137 | + |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * @return boolean |
|
142 | + */ |
|
143 | + abstract public function initialize_reg_step(); |
|
144 | + |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * @return string |
|
149 | + */ |
|
150 | + abstract public function generate_reg_form(); |
|
151 | + |
|
152 | + |
|
153 | + |
|
154 | + /** |
|
155 | + * @return boolean |
|
156 | + */ |
|
157 | + abstract public function process_reg_step(); |
|
158 | + |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * @return boolean |
|
163 | + */ |
|
164 | + abstract public function update_reg_step(); |
|
165 | + |
|
166 | + |
|
167 | + |
|
168 | + /** |
|
169 | + * @return boolean |
|
170 | + */ |
|
171 | + public function completed() |
|
172 | + { |
|
173 | + return $this->_completed; |
|
174 | + } |
|
175 | 175 | |
176 | 176 | |
177 | 177 | |
178 | - /** |
|
179 | - * set_completed - toggles $_completed to TRUE |
|
180 | - */ |
|
181 | - public function set_completed() |
|
182 | - { |
|
183 | - // DEBUG LOG |
|
184 | - //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
185 | - $this->_completed = apply_filters('FHEE__EE_SPCO_Reg_Step__set_completed___completed', true, $this); |
|
186 | - } |
|
178 | + /** |
|
179 | + * set_completed - toggles $_completed to TRUE |
|
180 | + */ |
|
181 | + public function set_completed() |
|
182 | + { |
|
183 | + // DEBUG LOG |
|
184 | + //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
|
185 | + $this->_completed = apply_filters('FHEE__EE_SPCO_Reg_Step__set_completed___completed', true, $this); |
|
186 | + } |
|
187 | 187 | |
188 | 188 | |
189 | 189 | |
190 | - /** |
|
191 | - * set_completed - toggles $_completed to FALSE |
|
192 | - */ |
|
193 | - public function set_not_completed() |
|
194 | - { |
|
195 | - $this->_completed = false; |
|
196 | - } |
|
190 | + /** |
|
191 | + * set_completed - toggles $_completed to FALSE |
|
192 | + */ |
|
193 | + public function set_not_completed() |
|
194 | + { |
|
195 | + $this->_completed = false; |
|
196 | + } |
|
197 | 197 | |
198 | 198 | |
199 | 199 | |
200 | - /** |
|
201 | - * @return string |
|
202 | - */ |
|
203 | - public function name() |
|
204 | - { |
|
205 | - return $this->_name; |
|
206 | - } |
|
200 | + /** |
|
201 | + * @return string |
|
202 | + */ |
|
203 | + public function name() |
|
204 | + { |
|
205 | + return $this->_name; |
|
206 | + } |
|
207 | 207 | |
208 | 208 | |
209 | 209 | |
210 | - /** |
|
211 | - * @return string |
|
212 | - */ |
|
213 | - public function slug() |
|
214 | - { |
|
215 | - return $this->_slug; |
|
216 | - } |
|
210 | + /** |
|
211 | + * @return string |
|
212 | + */ |
|
213 | + public function slug() |
|
214 | + { |
|
215 | + return $this->_slug; |
|
216 | + } |
|
217 | 217 | |
218 | 218 | |
219 | 219 | |
220 | - /** |
|
221 | - * submit_button_text |
|
222 | - * the text that appears on the reg step form submit button |
|
223 | - * |
|
224 | - * @return string |
|
225 | - */ |
|
226 | - public function submit_button_text() |
|
227 | - { |
|
228 | - return $this->_submit_button_text; |
|
229 | - } |
|
220 | + /** |
|
221 | + * submit_button_text |
|
222 | + * the text that appears on the reg step form submit button |
|
223 | + * |
|
224 | + * @return string |
|
225 | + */ |
|
226 | + public function submit_button_text() |
|
227 | + { |
|
228 | + return $this->_submit_button_text; |
|
229 | + } |
|
230 | 230 | |
231 | 231 | |
232 | 232 | |
233 | - /** |
|
234 | - * set_submit_button_text |
|
235 | - * sets the text that appears on the reg step form submit button |
|
236 | - * |
|
237 | - * @param string $submit_button_text |
|
238 | - */ |
|
239 | - public function set_submit_button_text($submit_button_text = '') |
|
240 | - { |
|
241 | - if (! empty($submit_button_text)) { |
|
242 | - $this->_submit_button_text = $submit_button_text; |
|
243 | - } else if ($this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
244 | - if ($this->checkout->revisit) { |
|
245 | - $this->_submit_button_text = sprintf(__('Update %s', 'event_espresso'), |
|
246 | - $this->checkout->current_step->name()); |
|
247 | - } else { |
|
248 | - $this->_submit_button_text = sprintf(__('Proceed to %s', 'event_espresso'), |
|
249 | - $this->checkout->next_step->name()); |
|
250 | - } |
|
251 | - } |
|
252 | - // filters the submit button text |
|
253 | - $this->_submit_button_text = apply_filters( |
|
254 | - 'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', |
|
255 | - $this->_submit_button_text, |
|
256 | - $this->checkout |
|
257 | - ); |
|
258 | - } |
|
233 | + /** |
|
234 | + * set_submit_button_text |
|
235 | + * sets the text that appears on the reg step form submit button |
|
236 | + * |
|
237 | + * @param string $submit_button_text |
|
238 | + */ |
|
239 | + public function set_submit_button_text($submit_button_text = '') |
|
240 | + { |
|
241 | + if (! empty($submit_button_text)) { |
|
242 | + $this->_submit_button_text = $submit_button_text; |
|
243 | + } else if ($this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
244 | + if ($this->checkout->revisit) { |
|
245 | + $this->_submit_button_text = sprintf(__('Update %s', 'event_espresso'), |
|
246 | + $this->checkout->current_step->name()); |
|
247 | + } else { |
|
248 | + $this->_submit_button_text = sprintf(__('Proceed to %s', 'event_espresso'), |
|
249 | + $this->checkout->next_step->name()); |
|
250 | + } |
|
251 | + } |
|
252 | + // filters the submit button text |
|
253 | + $this->_submit_button_text = apply_filters( |
|
254 | + 'FHEE__EE_SPCO_Reg_Step__set_submit_button_text___submit_button_text', |
|
255 | + $this->_submit_button_text, |
|
256 | + $this->checkout |
|
257 | + ); |
|
258 | + } |
|
259 | 259 | |
260 | 260 | |
261 | 261 | |
262 | - /** |
|
263 | - * @param boolean $is_current_step |
|
264 | - */ |
|
265 | - public function set_is_current_step($is_current_step) |
|
266 | - { |
|
267 | - $this->_is_current_step = $is_current_step; |
|
268 | - } |
|
262 | + /** |
|
263 | + * @param boolean $is_current_step |
|
264 | + */ |
|
265 | + public function set_is_current_step($is_current_step) |
|
266 | + { |
|
267 | + $this->_is_current_step = $is_current_step; |
|
268 | + } |
|
269 | 269 | |
270 | 270 | |
271 | 271 | |
272 | - /** |
|
273 | - * @return boolean |
|
274 | - */ |
|
275 | - public function is_current_step() |
|
276 | - { |
|
277 | - return $this->_is_current_step; |
|
278 | - } |
|
272 | + /** |
|
273 | + * @return boolean |
|
274 | + */ |
|
275 | + public function is_current_step() |
|
276 | + { |
|
277 | + return $this->_is_current_step; |
|
278 | + } |
|
279 | 279 | |
280 | 280 | |
281 | 281 | |
282 | - /** |
|
283 | - * @return boolean |
|
284 | - */ |
|
285 | - public function is_final_step() |
|
286 | - { |
|
287 | - return $this instanceof EE_SPCO_Reg_Step_Finalize_Registration ? true : false; |
|
288 | - } |
|
282 | + /** |
|
283 | + * @return boolean |
|
284 | + */ |
|
285 | + public function is_final_step() |
|
286 | + { |
|
287 | + return $this instanceof EE_SPCO_Reg_Step_Finalize_Registration ? true : false; |
|
288 | + } |
|
289 | 289 | |
290 | 290 | |
291 | 291 | |
292 | - /** |
|
293 | - * @param int $order |
|
294 | - */ |
|
295 | - public function set_order($order) |
|
296 | - { |
|
297 | - $this->_order = $order; |
|
298 | - } |
|
299 | - |
|
300 | - |
|
292 | + /** |
|
293 | + * @param int $order |
|
294 | + */ |
|
295 | + public function set_order($order) |
|
296 | + { |
|
297 | + $this->_order = $order; |
|
298 | + } |
|
299 | + |
|
300 | + |
|
301 | 301 | |
302 | - /** |
|
303 | - * @return int |
|
304 | - */ |
|
305 | - public function order() |
|
306 | - { |
|
307 | - return $this->_order; |
|
308 | - } |
|
309 | - |
|
310 | - |
|
311 | - |
|
312 | - /** |
|
313 | - * @return string |
|
314 | - */ |
|
315 | - public function template() |
|
316 | - { |
|
317 | - return $this->_template; |
|
318 | - } |
|
319 | - |
|
320 | - |
|
321 | - |
|
322 | - /** |
|
323 | - * @return string |
|
324 | - */ |
|
325 | - public function success_message() |
|
326 | - { |
|
327 | - return $this->_success_message; |
|
328 | - } |
|
302 | + /** |
|
303 | + * @return int |
|
304 | + */ |
|
305 | + public function order() |
|
306 | + { |
|
307 | + return $this->_order; |
|
308 | + } |
|
309 | + |
|
310 | + |
|
311 | + |
|
312 | + /** |
|
313 | + * @return string |
|
314 | + */ |
|
315 | + public function template() |
|
316 | + { |
|
317 | + return $this->_template; |
|
318 | + } |
|
319 | + |
|
320 | + |
|
321 | + |
|
322 | + /** |
|
323 | + * @return string |
|
324 | + */ |
|
325 | + public function success_message() |
|
326 | + { |
|
327 | + return $this->_success_message; |
|
328 | + } |
|
329 | 329 | |
330 | 330 | |
331 | 331 | |
332 | - /** |
|
333 | - * _set_success_message |
|
334 | - * |
|
335 | - * @param string $success_message |
|
336 | - */ |
|
337 | - protected function _set_success_message($success_message) |
|
338 | - { |
|
339 | - $this->_success_message = $success_message; |
|
340 | - } |
|
341 | - |
|
342 | - |
|
343 | - |
|
344 | - /** |
|
345 | - * _reset_success_message |
|
346 | - * |
|
347 | - * @return void |
|
348 | - */ |
|
349 | - protected function _reset_success_message() |
|
350 | - { |
|
351 | - $this->_success_message = ''; |
|
352 | - } |
|
332 | + /** |
|
333 | + * _set_success_message |
|
334 | + * |
|
335 | + * @param string $success_message |
|
336 | + */ |
|
337 | + protected function _set_success_message($success_message) |
|
338 | + { |
|
339 | + $this->_success_message = $success_message; |
|
340 | + } |
|
341 | + |
|
342 | + |
|
343 | + |
|
344 | + /** |
|
345 | + * _reset_success_message |
|
346 | + * |
|
347 | + * @return void |
|
348 | + */ |
|
349 | + protected function _reset_success_message() |
|
350 | + { |
|
351 | + $this->_success_message = ''; |
|
352 | + } |
|
353 | 353 | |
354 | 354 | |
355 | 355 | |
356 | - /** |
|
357 | - * @return string |
|
358 | - */ |
|
359 | - public function _instructions() |
|
360 | - { |
|
361 | - return $this->_instructions; |
|
362 | - } |
|
363 | - |
|
364 | - |
|
365 | - |
|
366 | - /** |
|
367 | - * @param string $instructions |
|
368 | - */ |
|
369 | - public function set_instructions($instructions) |
|
370 | - { |
|
371 | - $this->_instructions = apply_filters( |
|
372 | - 'FHEE__EE_SPCO_Reg_Step__set_instructions__instructions', |
|
373 | - $instructions, |
|
374 | - $this |
|
375 | - ); |
|
376 | - } |
|
377 | - |
|
378 | - |
|
379 | - |
|
380 | - /** |
|
381 | - * @param array $valid_data |
|
382 | - */ |
|
383 | - public function set_valid_data($valid_data) |
|
384 | - { |
|
385 | - $this->_valid_data = $valid_data; |
|
386 | - } |
|
387 | - |
|
388 | - |
|
389 | - |
|
390 | - /** |
|
391 | - * @return array |
|
392 | - */ |
|
393 | - public function valid_data() |
|
394 | - { |
|
395 | - if (empty($this->_valid_data)) { |
|
396 | - $this->_valid_data = $this->reg_form->valid_data(); |
|
397 | - } |
|
398 | - return $this->_valid_data; |
|
399 | - } |
|
400 | - |
|
401 | - |
|
402 | - |
|
403 | - /** |
|
404 | - * @return string |
|
405 | - */ |
|
406 | - public function reg_form_name() |
|
407 | - { |
|
408 | - if (empty($this->_reg_form_name)) { |
|
409 | - $this->set_reg_form_name('ee-spco-' . $this->slug() . '-reg-step-form'); |
|
410 | - } |
|
411 | - return $this->_reg_form_name; |
|
412 | - } |
|
413 | - |
|
414 | - |
|
415 | - |
|
416 | - /** |
|
417 | - * @param string $reg_form_name |
|
418 | - */ |
|
419 | - protected function set_reg_form_name($reg_form_name) |
|
420 | - { |
|
421 | - $this->_reg_form_name = $reg_form_name; |
|
422 | - } |
|
423 | - |
|
424 | - |
|
425 | - |
|
426 | - /** |
|
427 | - * reg_step_url |
|
428 | - * |
|
429 | - * @param string $action |
|
430 | - * @return string |
|
431 | - */ |
|
432 | - public function reg_step_url($action = '') |
|
433 | - { |
|
434 | - $query_args = array('step' => $this->slug()); |
|
435 | - if (! empty($action)) { |
|
436 | - $query_args['action'] = $action; |
|
437 | - } |
|
438 | - // final step has no display |
|
439 | - if ($this instanceof EE_SPCO_Reg_Step_Finalize_Registration && $action === 'display_spco_reg_step') { |
|
440 | - $query_args['action'] = 'process_reg_step'; |
|
441 | - } |
|
442 | - if ($this->checkout->revisit) { |
|
443 | - $query_args['revisit'] = true; |
|
444 | - } |
|
445 | - if ($this->checkout->reg_url_link) { |
|
446 | - $query_args['e_reg_url_link'] = $this->checkout->reg_url_link; |
|
447 | - } |
|
448 | - return add_query_arg($query_args, $this->checkout->reg_page_base_url); |
|
449 | - } |
|
450 | - |
|
451 | - |
|
452 | - |
|
453 | - /** |
|
454 | - * creates the default hidden inputs section |
|
455 | - * |
|
456 | - * @return EE_Form_Section_Proper |
|
457 | - * @throws \EE_Error |
|
458 | - */ |
|
459 | - public function reg_step_hidden_inputs() |
|
460 | - { |
|
461 | - // hidden inputs for admin registrations |
|
462 | - if ($this->checkout->admin_request) { |
|
463 | - return new EE_Form_Section_Proper( |
|
464 | - array( |
|
465 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
466 | - 'html_id' => 'ee-' . $this->slug() . '-hidden-inputs', |
|
467 | - 'subsections' => array( |
|
468 | - 'next_step' => new EE_Fixed_Hidden_Input( |
|
469 | - array( |
|
470 | - 'html_name' => 'next_step', |
|
471 | - 'html_id' => 'spco-' . $this->slug() . '-next-step', |
|
472 | - 'default' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
|
473 | - ? $this->checkout->next_step->slug() : '', |
|
474 | - ) |
|
475 | - ), |
|
476 | - ), |
|
477 | - ) |
|
478 | - ); |
|
479 | - } else { |
|
480 | - $default_form_action = apply_filters( |
|
481 | - 'FHEE__EE_SPCO_Reg_Step__reg_step_hidden_inputs__default_form_action', |
|
482 | - empty($this->checkout->reg_url_link) |
|
483 | - ? 'process_reg_step' |
|
484 | - : 'update_reg_step', |
|
485 | - $this |
|
486 | - ); |
|
487 | - // hidden inputs for frontend registrations |
|
488 | - return new EE_Form_Section_Proper( |
|
489 | - array( |
|
490 | - 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
491 | - 'html_id' => 'ee-' . $this->slug() . '-hidden-inputs', |
|
492 | - 'subsections' => array( |
|
493 | - 'action' => new EE_Fixed_Hidden_Input( |
|
494 | - array( |
|
495 | - 'html_name' => 'action', |
|
496 | - 'html_id' => 'spco-' . $this->slug() . '-action', |
|
497 | - 'default' => $default_form_action, |
|
498 | - ) |
|
499 | - ), |
|
500 | - 'next_step' => new EE_Fixed_Hidden_Input( |
|
501 | - array( |
|
502 | - 'html_name' => 'next_step', |
|
503 | - 'html_id' => 'spco-' . $this->slug() . '-next-step', |
|
504 | - 'default' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
|
505 | - ? $this->checkout->next_step->slug() : '', |
|
506 | - ) |
|
507 | - ), |
|
508 | - 'e_reg_url_link' => new EE_Fixed_Hidden_Input( |
|
509 | - array( |
|
510 | - 'html_name' => 'e_reg_url_link', |
|
511 | - 'html_id' => 'spco-reg_url_link', |
|
512 | - 'default' => $this->checkout->reg_url_link, |
|
513 | - ) |
|
514 | - ), |
|
515 | - 'revisit' => new EE_Fixed_Hidden_Input( |
|
516 | - array( |
|
517 | - 'html_name' => 'revisit', |
|
518 | - 'html_id' => 'spco-revisit', |
|
519 | - 'default' => $this->checkout->revisit, |
|
520 | - ) |
|
521 | - ), |
|
522 | - ), |
|
523 | - ) |
|
524 | - ); |
|
525 | - } |
|
526 | - } |
|
527 | - |
|
528 | - |
|
529 | - |
|
530 | - /** |
|
531 | - * generate_reg_form_for_actions |
|
532 | - * |
|
533 | - * @param array $actions |
|
534 | - * @return void |
|
535 | - */ |
|
536 | - public function generate_reg_form_for_actions($actions = array()) |
|
537 | - { |
|
538 | - $actions = array_merge( |
|
539 | - array( |
|
540 | - 'generate_reg_form', |
|
541 | - 'display_spco_reg_step', |
|
542 | - 'process_reg_step', |
|
543 | - 'update_reg_step', |
|
544 | - ), $actions |
|
545 | - ); |
|
546 | - $this->checkout->generate_reg_form = in_array($this->checkout->action, $actions, true) ? true : false; |
|
547 | - } |
|
548 | - |
|
549 | - |
|
550 | - |
|
551 | - /** |
|
552 | - * @return string |
|
553 | - * @throws \EE_Error |
|
554 | - */ |
|
555 | - public function display_reg_form() |
|
556 | - { |
|
557 | - $html = ''; |
|
558 | - if ($this->reg_form instanceof EE_Form_Section_Proper) { |
|
559 | - $html .= ! $this->checkout->admin_request ? $this->reg_form->form_open($this->reg_step_url()) : ''; |
|
560 | - if (EE_Registry::instance()->REQ->ajax) { |
|
561 | - $this->reg_form->localize_validation_rules(); |
|
562 | - $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization()); |
|
563 | - } |
|
564 | - $html .= $this->reg_form->get_html(); |
|
565 | - $html .= ! $this->checkout->admin_request ? $this->reg_step_submit_button() : ''; |
|
566 | - $html .= ! $this->checkout->admin_request ? $this->reg_form->form_close() : ''; |
|
567 | - } |
|
568 | - return $html; |
|
569 | - } |
|
570 | - |
|
571 | - |
|
572 | - |
|
573 | - /** |
|
574 | - * div_class - returns nothing for current step, but a css class of "hidden" for others |
|
575 | - * |
|
576 | - * @return string |
|
577 | - * @throws \EE_Error |
|
578 | - */ |
|
579 | - public function reg_step_submit_button() |
|
580 | - { |
|
581 | - if (! $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
582 | - return ''; |
|
583 | - } |
|
584 | - ob_start(); |
|
585 | - do_action('AHEE__before_spco_whats_next_buttons', $this->slug(), $this->checkout->next_step->slug(), |
|
586 | - $this->checkout); |
|
587 | - $html = ob_get_clean(); |
|
588 | - // generate submit button |
|
589 | - $sbmt_btn = new EE_Submit_Input(array( |
|
590 | - 'html_name' => 'spco-go-to-step-' . $this->checkout->next_step->slug(), |
|
591 | - 'html_id' => 'spco-go-to-step-' . $this->checkout->next_step->slug(), |
|
592 | - 'html_class' => 'spco-next-step-btn', |
|
593 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
594 | - 'default' => $this->submit_button_text(), |
|
595 | - )); |
|
596 | - $sbmt_btn->set_button_css_attributes(true, 'large'); |
|
597 | - $sbmt_btn_html = $sbmt_btn->get_html_for_input(); |
|
598 | - $html .= EEH_HTML::div( |
|
599 | - apply_filters('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', $sbmt_btn_html, $this), |
|
600 | - 'spco-' . $this->slug() . '-whats-next-buttons-dv', |
|
601 | - 'spco-whats-next-buttons' |
|
602 | - ); |
|
603 | - return $html; |
|
604 | - } |
|
605 | - |
|
606 | - |
|
607 | - |
|
608 | - /** |
|
609 | - * div_class - returns nothing for current step, but a css class of "hidden" for others |
|
610 | - * |
|
611 | - * @return string |
|
612 | - */ |
|
613 | - public function div_class() |
|
614 | - { |
|
615 | - return $this->is_current_step() ? '' : ' hidden'; |
|
616 | - } |
|
617 | - |
|
618 | - |
|
619 | - |
|
620 | - /** |
|
621 | - * div_class - returns a css class of "hidden" for current step, but nothing for others |
|
622 | - * |
|
623 | - * @return string |
|
624 | - */ |
|
625 | - public function edit_lnk_url() |
|
626 | - { |
|
627 | - return add_query_arg(array('step' => $this->slug()), $this->checkout->reg_page_base_url); |
|
628 | - } |
|
629 | - |
|
630 | - |
|
631 | - |
|
632 | - /** |
|
633 | - * div_class - returns a css class of "hidden" for current step, but nothing for others |
|
634 | - * |
|
635 | - * @return string |
|
636 | - */ |
|
637 | - public function edit_link_class() |
|
638 | - { |
|
639 | - return $this->is_current_step() ? ' hidden' : ''; |
|
640 | - } |
|
641 | - |
|
642 | - |
|
643 | - |
|
644 | - /** |
|
645 | - * update_checkout with changes that have been made to the cart |
|
646 | - * |
|
647 | - * @return void |
|
648 | - * @throws \EE_Error |
|
649 | - */ |
|
650 | - public function update_checkout() |
|
651 | - { |
|
652 | - // grab the cart grand total and reset TXN total |
|
653 | - $this->checkout->transaction->set_total($this->checkout->cart->get_cart_grand_total()); |
|
654 | - $this->checkout->stash_transaction_and_checkout(); |
|
655 | - } |
|
656 | - |
|
657 | - |
|
658 | - |
|
659 | - /** |
|
660 | - * __sleep |
|
661 | - * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon |
|
662 | - * serialization EE_Checkout will handle the reimplementation of itself upon waking, but we won't bother with the |
|
663 | - * reg form, because if needed, it will be regenerated anyways |
|
664 | - * |
|
665 | - * @return array |
|
666 | - */ |
|
667 | - public function __sleep() |
|
668 | - { |
|
669 | - // remove the reg form and the checkout |
|
670 | - return array_diff(array_keys(get_object_vars($this)), array('reg_form', 'checkout')); |
|
671 | - } |
|
356 | + /** |
|
357 | + * @return string |
|
358 | + */ |
|
359 | + public function _instructions() |
|
360 | + { |
|
361 | + return $this->_instructions; |
|
362 | + } |
|
363 | + |
|
364 | + |
|
365 | + |
|
366 | + /** |
|
367 | + * @param string $instructions |
|
368 | + */ |
|
369 | + public function set_instructions($instructions) |
|
370 | + { |
|
371 | + $this->_instructions = apply_filters( |
|
372 | + 'FHEE__EE_SPCO_Reg_Step__set_instructions__instructions', |
|
373 | + $instructions, |
|
374 | + $this |
|
375 | + ); |
|
376 | + } |
|
377 | + |
|
378 | + |
|
379 | + |
|
380 | + /** |
|
381 | + * @param array $valid_data |
|
382 | + */ |
|
383 | + public function set_valid_data($valid_data) |
|
384 | + { |
|
385 | + $this->_valid_data = $valid_data; |
|
386 | + } |
|
387 | + |
|
388 | + |
|
389 | + |
|
390 | + /** |
|
391 | + * @return array |
|
392 | + */ |
|
393 | + public function valid_data() |
|
394 | + { |
|
395 | + if (empty($this->_valid_data)) { |
|
396 | + $this->_valid_data = $this->reg_form->valid_data(); |
|
397 | + } |
|
398 | + return $this->_valid_data; |
|
399 | + } |
|
400 | + |
|
401 | + |
|
402 | + |
|
403 | + /** |
|
404 | + * @return string |
|
405 | + */ |
|
406 | + public function reg_form_name() |
|
407 | + { |
|
408 | + if (empty($this->_reg_form_name)) { |
|
409 | + $this->set_reg_form_name('ee-spco-' . $this->slug() . '-reg-step-form'); |
|
410 | + } |
|
411 | + return $this->_reg_form_name; |
|
412 | + } |
|
413 | + |
|
414 | + |
|
415 | + |
|
416 | + /** |
|
417 | + * @param string $reg_form_name |
|
418 | + */ |
|
419 | + protected function set_reg_form_name($reg_form_name) |
|
420 | + { |
|
421 | + $this->_reg_form_name = $reg_form_name; |
|
422 | + } |
|
423 | + |
|
424 | + |
|
425 | + |
|
426 | + /** |
|
427 | + * reg_step_url |
|
428 | + * |
|
429 | + * @param string $action |
|
430 | + * @return string |
|
431 | + */ |
|
432 | + public function reg_step_url($action = '') |
|
433 | + { |
|
434 | + $query_args = array('step' => $this->slug()); |
|
435 | + if (! empty($action)) { |
|
436 | + $query_args['action'] = $action; |
|
437 | + } |
|
438 | + // final step has no display |
|
439 | + if ($this instanceof EE_SPCO_Reg_Step_Finalize_Registration && $action === 'display_spco_reg_step') { |
|
440 | + $query_args['action'] = 'process_reg_step'; |
|
441 | + } |
|
442 | + if ($this->checkout->revisit) { |
|
443 | + $query_args['revisit'] = true; |
|
444 | + } |
|
445 | + if ($this->checkout->reg_url_link) { |
|
446 | + $query_args['e_reg_url_link'] = $this->checkout->reg_url_link; |
|
447 | + } |
|
448 | + return add_query_arg($query_args, $this->checkout->reg_page_base_url); |
|
449 | + } |
|
450 | + |
|
451 | + |
|
452 | + |
|
453 | + /** |
|
454 | + * creates the default hidden inputs section |
|
455 | + * |
|
456 | + * @return EE_Form_Section_Proper |
|
457 | + * @throws \EE_Error |
|
458 | + */ |
|
459 | + public function reg_step_hidden_inputs() |
|
460 | + { |
|
461 | + // hidden inputs for admin registrations |
|
462 | + if ($this->checkout->admin_request) { |
|
463 | + return new EE_Form_Section_Proper( |
|
464 | + array( |
|
465 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
466 | + 'html_id' => 'ee-' . $this->slug() . '-hidden-inputs', |
|
467 | + 'subsections' => array( |
|
468 | + 'next_step' => new EE_Fixed_Hidden_Input( |
|
469 | + array( |
|
470 | + 'html_name' => 'next_step', |
|
471 | + 'html_id' => 'spco-' . $this->slug() . '-next-step', |
|
472 | + 'default' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
|
473 | + ? $this->checkout->next_step->slug() : '', |
|
474 | + ) |
|
475 | + ), |
|
476 | + ), |
|
477 | + ) |
|
478 | + ); |
|
479 | + } else { |
|
480 | + $default_form_action = apply_filters( |
|
481 | + 'FHEE__EE_SPCO_Reg_Step__reg_step_hidden_inputs__default_form_action', |
|
482 | + empty($this->checkout->reg_url_link) |
|
483 | + ? 'process_reg_step' |
|
484 | + : 'update_reg_step', |
|
485 | + $this |
|
486 | + ); |
|
487 | + // hidden inputs for frontend registrations |
|
488 | + return new EE_Form_Section_Proper( |
|
489 | + array( |
|
490 | + 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
|
491 | + 'html_id' => 'ee-' . $this->slug() . '-hidden-inputs', |
|
492 | + 'subsections' => array( |
|
493 | + 'action' => new EE_Fixed_Hidden_Input( |
|
494 | + array( |
|
495 | + 'html_name' => 'action', |
|
496 | + 'html_id' => 'spco-' . $this->slug() . '-action', |
|
497 | + 'default' => $default_form_action, |
|
498 | + ) |
|
499 | + ), |
|
500 | + 'next_step' => new EE_Fixed_Hidden_Input( |
|
501 | + array( |
|
502 | + 'html_name' => 'next_step', |
|
503 | + 'html_id' => 'spco-' . $this->slug() . '-next-step', |
|
504 | + 'default' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
|
505 | + ? $this->checkout->next_step->slug() : '', |
|
506 | + ) |
|
507 | + ), |
|
508 | + 'e_reg_url_link' => new EE_Fixed_Hidden_Input( |
|
509 | + array( |
|
510 | + 'html_name' => 'e_reg_url_link', |
|
511 | + 'html_id' => 'spco-reg_url_link', |
|
512 | + 'default' => $this->checkout->reg_url_link, |
|
513 | + ) |
|
514 | + ), |
|
515 | + 'revisit' => new EE_Fixed_Hidden_Input( |
|
516 | + array( |
|
517 | + 'html_name' => 'revisit', |
|
518 | + 'html_id' => 'spco-revisit', |
|
519 | + 'default' => $this->checkout->revisit, |
|
520 | + ) |
|
521 | + ), |
|
522 | + ), |
|
523 | + ) |
|
524 | + ); |
|
525 | + } |
|
526 | + } |
|
527 | + |
|
528 | + |
|
529 | + |
|
530 | + /** |
|
531 | + * generate_reg_form_for_actions |
|
532 | + * |
|
533 | + * @param array $actions |
|
534 | + * @return void |
|
535 | + */ |
|
536 | + public function generate_reg_form_for_actions($actions = array()) |
|
537 | + { |
|
538 | + $actions = array_merge( |
|
539 | + array( |
|
540 | + 'generate_reg_form', |
|
541 | + 'display_spco_reg_step', |
|
542 | + 'process_reg_step', |
|
543 | + 'update_reg_step', |
|
544 | + ), $actions |
|
545 | + ); |
|
546 | + $this->checkout->generate_reg_form = in_array($this->checkout->action, $actions, true) ? true : false; |
|
547 | + } |
|
548 | + |
|
549 | + |
|
550 | + |
|
551 | + /** |
|
552 | + * @return string |
|
553 | + * @throws \EE_Error |
|
554 | + */ |
|
555 | + public function display_reg_form() |
|
556 | + { |
|
557 | + $html = ''; |
|
558 | + if ($this->reg_form instanceof EE_Form_Section_Proper) { |
|
559 | + $html .= ! $this->checkout->admin_request ? $this->reg_form->form_open($this->reg_step_url()) : ''; |
|
560 | + if (EE_Registry::instance()->REQ->ajax) { |
|
561 | + $this->reg_form->localize_validation_rules(); |
|
562 | + $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization()); |
|
563 | + } |
|
564 | + $html .= $this->reg_form->get_html(); |
|
565 | + $html .= ! $this->checkout->admin_request ? $this->reg_step_submit_button() : ''; |
|
566 | + $html .= ! $this->checkout->admin_request ? $this->reg_form->form_close() : ''; |
|
567 | + } |
|
568 | + return $html; |
|
569 | + } |
|
570 | + |
|
571 | + |
|
572 | + |
|
573 | + /** |
|
574 | + * div_class - returns nothing for current step, but a css class of "hidden" for others |
|
575 | + * |
|
576 | + * @return string |
|
577 | + * @throws \EE_Error |
|
578 | + */ |
|
579 | + public function reg_step_submit_button() |
|
580 | + { |
|
581 | + if (! $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
582 | + return ''; |
|
583 | + } |
|
584 | + ob_start(); |
|
585 | + do_action('AHEE__before_spco_whats_next_buttons', $this->slug(), $this->checkout->next_step->slug(), |
|
586 | + $this->checkout); |
|
587 | + $html = ob_get_clean(); |
|
588 | + // generate submit button |
|
589 | + $sbmt_btn = new EE_Submit_Input(array( |
|
590 | + 'html_name' => 'spco-go-to-step-' . $this->checkout->next_step->slug(), |
|
591 | + 'html_id' => 'spco-go-to-step-' . $this->checkout->next_step->slug(), |
|
592 | + 'html_class' => 'spco-next-step-btn', |
|
593 | + 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
594 | + 'default' => $this->submit_button_text(), |
|
595 | + )); |
|
596 | + $sbmt_btn->set_button_css_attributes(true, 'large'); |
|
597 | + $sbmt_btn_html = $sbmt_btn->get_html_for_input(); |
|
598 | + $html .= EEH_HTML::div( |
|
599 | + apply_filters('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', $sbmt_btn_html, $this), |
|
600 | + 'spco-' . $this->slug() . '-whats-next-buttons-dv', |
|
601 | + 'spco-whats-next-buttons' |
|
602 | + ); |
|
603 | + return $html; |
|
604 | + } |
|
605 | + |
|
606 | + |
|
607 | + |
|
608 | + /** |
|
609 | + * div_class - returns nothing for current step, but a css class of "hidden" for others |
|
610 | + * |
|
611 | + * @return string |
|
612 | + */ |
|
613 | + public function div_class() |
|
614 | + { |
|
615 | + return $this->is_current_step() ? '' : ' hidden'; |
|
616 | + } |
|
617 | + |
|
618 | + |
|
619 | + |
|
620 | + /** |
|
621 | + * div_class - returns a css class of "hidden" for current step, but nothing for others |
|
622 | + * |
|
623 | + * @return string |
|
624 | + */ |
|
625 | + public function edit_lnk_url() |
|
626 | + { |
|
627 | + return add_query_arg(array('step' => $this->slug()), $this->checkout->reg_page_base_url); |
|
628 | + } |
|
629 | + |
|
630 | + |
|
631 | + |
|
632 | + /** |
|
633 | + * div_class - returns a css class of "hidden" for current step, but nothing for others |
|
634 | + * |
|
635 | + * @return string |
|
636 | + */ |
|
637 | + public function edit_link_class() |
|
638 | + { |
|
639 | + return $this->is_current_step() ? ' hidden' : ''; |
|
640 | + } |
|
641 | + |
|
642 | + |
|
643 | + |
|
644 | + /** |
|
645 | + * update_checkout with changes that have been made to the cart |
|
646 | + * |
|
647 | + * @return void |
|
648 | + * @throws \EE_Error |
|
649 | + */ |
|
650 | + public function update_checkout() |
|
651 | + { |
|
652 | + // grab the cart grand total and reset TXN total |
|
653 | + $this->checkout->transaction->set_total($this->checkout->cart->get_cart_grand_total()); |
|
654 | + $this->checkout->stash_transaction_and_checkout(); |
|
655 | + } |
|
656 | + |
|
657 | + |
|
658 | + |
|
659 | + /** |
|
660 | + * __sleep |
|
661 | + * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon |
|
662 | + * serialization EE_Checkout will handle the reimplementation of itself upon waking, but we won't bother with the |
|
663 | + * reg form, because if needed, it will be regenerated anyways |
|
664 | + * |
|
665 | + * @return array |
|
666 | + */ |
|
667 | + public function __sleep() |
|
668 | + { |
|
669 | + // remove the reg form and the checkout |
|
670 | + return array_diff(array_keys(get_object_vars($this)), array('reg_form', 'checkout')); |
|
671 | + } |
|
672 | 672 | |
673 | 673 | |
674 | 674 |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | 2 | exit('No direct script access allowed'); |
3 | 3 | } |
4 | 4 | |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | */ |
239 | 239 | public function set_submit_button_text($submit_button_text = '') |
240 | 240 | { |
241 | - if (! empty($submit_button_text)) { |
|
241 | + if ( ! empty($submit_button_text)) { |
|
242 | 242 | $this->_submit_button_text = $submit_button_text; |
243 | 243 | } else if ($this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
244 | 244 | if ($this->checkout->revisit) { |
@@ -406,7 +406,7 @@ discard block |
||
406 | 406 | public function reg_form_name() |
407 | 407 | { |
408 | 408 | if (empty($this->_reg_form_name)) { |
409 | - $this->set_reg_form_name('ee-spco-' . $this->slug() . '-reg-step-form'); |
|
409 | + $this->set_reg_form_name('ee-spco-'.$this->slug().'-reg-step-form'); |
|
410 | 410 | } |
411 | 411 | return $this->_reg_form_name; |
412 | 412 | } |
@@ -432,7 +432,7 @@ discard block |
||
432 | 432 | public function reg_step_url($action = '') |
433 | 433 | { |
434 | 434 | $query_args = array('step' => $this->slug()); |
435 | - if (! empty($action)) { |
|
435 | + if ( ! empty($action)) { |
|
436 | 436 | $query_args['action'] = $action; |
437 | 437 | } |
438 | 438 | // final step has no display |
@@ -463,12 +463,12 @@ discard block |
||
463 | 463 | return new EE_Form_Section_Proper( |
464 | 464 | array( |
465 | 465 | 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
466 | - 'html_id' => 'ee-' . $this->slug() . '-hidden-inputs', |
|
466 | + 'html_id' => 'ee-'.$this->slug().'-hidden-inputs', |
|
467 | 467 | 'subsections' => array( |
468 | 468 | 'next_step' => new EE_Fixed_Hidden_Input( |
469 | 469 | array( |
470 | 470 | 'html_name' => 'next_step', |
471 | - 'html_id' => 'spco-' . $this->slug() . '-next-step', |
|
471 | + 'html_id' => 'spco-'.$this->slug().'-next-step', |
|
472 | 472 | 'default' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
473 | 473 | ? $this->checkout->next_step->slug() : '', |
474 | 474 | ) |
@@ -488,19 +488,19 @@ discard block |
||
488 | 488 | return new EE_Form_Section_Proper( |
489 | 489 | array( |
490 | 490 | 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
491 | - 'html_id' => 'ee-' . $this->slug() . '-hidden-inputs', |
|
491 | + 'html_id' => 'ee-'.$this->slug().'-hidden-inputs', |
|
492 | 492 | 'subsections' => array( |
493 | 493 | 'action' => new EE_Fixed_Hidden_Input( |
494 | 494 | array( |
495 | 495 | 'html_name' => 'action', |
496 | - 'html_id' => 'spco-' . $this->slug() . '-action', |
|
496 | + 'html_id' => 'spco-'.$this->slug().'-action', |
|
497 | 497 | 'default' => $default_form_action, |
498 | 498 | ) |
499 | 499 | ), |
500 | 500 | 'next_step' => new EE_Fixed_Hidden_Input( |
501 | 501 | array( |
502 | 502 | 'html_name' => 'next_step', |
503 | - 'html_id' => 'spco-' . $this->slug() . '-next-step', |
|
503 | + 'html_id' => 'spco-'.$this->slug().'-next-step', |
|
504 | 504 | 'default' => $this->checkout->next_step instanceof EE_SPCO_Reg_Step |
505 | 505 | ? $this->checkout->next_step->slug() : '', |
506 | 506 | ) |
@@ -578,7 +578,7 @@ discard block |
||
578 | 578 | */ |
579 | 579 | public function reg_step_submit_button() |
580 | 580 | { |
581 | - if (! $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
581 | + if ( ! $this->checkout->next_step instanceof EE_SPCO_Reg_Step) { |
|
582 | 582 | return ''; |
583 | 583 | } |
584 | 584 | ob_start(); |
@@ -587,17 +587,17 @@ discard block |
||
587 | 587 | $html = ob_get_clean(); |
588 | 588 | // generate submit button |
589 | 589 | $sbmt_btn = new EE_Submit_Input(array( |
590 | - 'html_name' => 'spco-go-to-step-' . $this->checkout->next_step->slug(), |
|
591 | - 'html_id' => 'spco-go-to-step-' . $this->checkout->next_step->slug(), |
|
590 | + 'html_name' => 'spco-go-to-step-'.$this->checkout->next_step->slug(), |
|
591 | + 'html_id' => 'spco-go-to-step-'.$this->checkout->next_step->slug(), |
|
592 | 592 | 'html_class' => 'spco-next-step-btn', |
593 | - 'other_html_attributes' => ' rel="' . $this->slug() . '"', |
|
593 | + 'other_html_attributes' => ' rel="'.$this->slug().'"', |
|
594 | 594 | 'default' => $this->submit_button_text(), |
595 | 595 | )); |
596 | 596 | $sbmt_btn->set_button_css_attributes(true, 'large'); |
597 | 597 | $sbmt_btn_html = $sbmt_btn->get_html_for_input(); |
598 | 598 | $html .= EEH_HTML::div( |
599 | 599 | apply_filters('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', $sbmt_btn_html, $this), |
600 | - 'spco-' . $this->slug() . '-whats-next-buttons-dv', |
|
600 | + 'spco-'.$this->slug().'-whats-next-buttons-dv', |
|
601 | 601 | 'spco-whats-next-buttons' |
602 | 602 | ); |
603 | 603 | return $html; |
@@ -286,41 +286,41 @@ discard block |
||
286 | 286 | $this->checkout->revisit |
287 | 287 | ); |
288 | 288 | foreach ( $registrations as $REG_ID => $registration ) { |
289 | - /** @var $registration EE_Registration */ |
|
290 | - // has this registration lost it's space ? |
|
289 | + /** @var $registration EE_Registration */ |
|
290 | + // has this registration lost it's space ? |
|
291 | 291 | if ( isset( $ejected_registrations[ $REG_ID ] ) ) { |
292 | 292 | $insufficient_spaces_available[ $registration->event()->ID() ] = $registration->event(); |
293 | 293 | continue; |
294 | 294 | } |
295 | - // event requires admin approval |
|
296 | - if ($registration->status_ID() === EEM_Registration::status_id_not_approved) { |
|
297 | - // add event to list of events with pre-approval reg status |
|
298 | - $registrations_requiring_pre_approval[$REG_ID] = $registration; |
|
299 | - do_action( |
|
300 | - 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_pre_approval', |
|
301 | - $registration->event(), |
|
302 | - $this |
|
303 | - ); |
|
304 | - continue; |
|
305 | - } |
|
306 | - if ( |
|
295 | + // event requires admin approval |
|
296 | + if ($registration->status_ID() === EEM_Registration::status_id_not_approved) { |
|
297 | + // add event to list of events with pre-approval reg status |
|
298 | + $registrations_requiring_pre_approval[$REG_ID] = $registration; |
|
299 | + do_action( |
|
300 | + 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_pre_approval', |
|
301 | + $registration->event(), |
|
302 | + $this |
|
303 | + ); |
|
304 | + continue; |
|
305 | + } |
|
306 | + if ( |
|
307 | 307 | // returning registrant |
308 | 308 | $this->checkout->revisit |
309 | 309 | // anything other than Approved |
310 | 310 | && $registration->status_ID() !== EEM_Registration::status_id_approved |
311 | - && ( |
|
312 | - $registration->event()->is_sold_out() |
|
313 | - || $registration->event()->is_sold_out( true ) |
|
314 | - ) |
|
315 | - ) { |
|
316 | - // add event to list of events that are sold out |
|
317 | - $sold_out_events[ $registration->event()->ID() ] = $registration->event(); |
|
318 | - do_action( |
|
319 | - 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__sold_out_event', |
|
320 | - $registration->event(), |
|
321 | - $this |
|
322 | - ); |
|
323 | - continue; |
|
311 | + && ( |
|
312 | + $registration->event()->is_sold_out() |
|
313 | + || $registration->event()->is_sold_out( true ) |
|
314 | + ) |
|
315 | + ) { |
|
316 | + // add event to list of events that are sold out |
|
317 | + $sold_out_events[ $registration->event()->ID() ] = $registration->event(); |
|
318 | + do_action( |
|
319 | + 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__sold_out_event', |
|
320 | + $registration->event(), |
|
321 | + $this |
|
322 | + ); |
|
323 | + continue; |
|
324 | 324 | } |
325 | 325 | // are they allowed to pay now and is there monies owing? |
326 | 326 | if ( $registration->owes_monies_and_can_pay() ) { |
@@ -428,11 +428,11 @@ discard block |
||
428 | 428 | new EE_Billable_Line_Item_Filter( |
429 | 429 | EE_SPCO_Reg_Step_Payment_Options::remove_ejected_registrations( |
430 | 430 | EE_Registry::instance()->SSN->checkout()->transaction->registrations( |
431 | - EE_Registry::instance()->SSN->checkout()->reg_cache_where_params |
|
432 | - ) |
|
431 | + EE_Registry::instance()->SSN->checkout()->reg_cache_where_params |
|
432 | + ) |
|
433 | 433 | ) |
434 | 434 | ) |
435 | - ); |
|
435 | + ); |
|
436 | 436 | $line_item_filter_collection->add( new EE_Non_Zero_Line_Item_Filter() ); |
437 | 437 | return $line_item_filter_collection; |
438 | 438 | } |
@@ -481,46 +481,46 @@ discard block |
||
481 | 481 | * @throws \EE_Error |
482 | 482 | */ |
483 | 483 | public static function find_registrations_that_lost_their_space( array $registrations, $revisit = false ) { |
484 | - // registrations per event |
|
484 | + // registrations per event |
|
485 | 485 | $event_reg_count = array(); |
486 | 486 | // spaces left per event |
487 | 487 | $event_spaces_remaining = array(); |
488 | - // tickets left sorted by ID |
|
489 | - $tickets_remaining = array(); |
|
490 | - // registrations that have lost their space |
|
488 | + // tickets left sorted by ID |
|
489 | + $tickets_remaining = array(); |
|
490 | + // registrations that have lost their space |
|
491 | 491 | $ejected_registrations = array(); |
492 | 492 | foreach ( $registrations as $REG_ID => $registration ) { |
493 | - if ( |
|
494 | - $registration->status_ID() === EEM_Registration::status_id_approved |
|
495 | - || apply_filters( |
|
496 | - 'FHEE__EE_SPCO_Reg_Step_Payment_Options__find_registrations_that_lost_their_space__allow_reg_payment', |
|
497 | - false, |
|
498 | - $registration, |
|
499 | - $revisit |
|
500 | - ) |
|
501 | - ) { |
|
502 | - continue; |
|
493 | + if ( |
|
494 | + $registration->status_ID() === EEM_Registration::status_id_approved |
|
495 | + || apply_filters( |
|
496 | + 'FHEE__EE_SPCO_Reg_Step_Payment_Options__find_registrations_that_lost_their_space__allow_reg_payment', |
|
497 | + false, |
|
498 | + $registration, |
|
499 | + $revisit |
|
500 | + ) |
|
501 | + ) { |
|
502 | + continue; |
|
503 | 503 | } |
504 | 504 | $EVT_ID = $registration->event_ID(); |
505 | - $ticket = $registration->ticket(); |
|
506 | - if ( ! isset($tickets_remaining[$ticket->ID()])) { |
|
507 | - $tickets_remaining[$ticket->ID()] = $ticket->remaining(); |
|
508 | - } |
|
509 | - if ($tickets_remaining[$ticket->ID()] > 0) { |
|
510 | - if ( ! isset($event_reg_count[$EVT_ID])) { |
|
511 | - $event_reg_count[$EVT_ID] = 0; |
|
512 | - } |
|
513 | - $event_reg_count[$EVT_ID]++; |
|
514 | - if ( ! isset($event_spaces_remaining[$EVT_ID])) { |
|
515 | - $event_spaces_remaining[$EVT_ID] = $registration->event()->spaces_remaining_for_sale(); |
|
516 | - } |
|
517 | - } |
|
505 | + $ticket = $registration->ticket(); |
|
506 | + if ( ! isset($tickets_remaining[$ticket->ID()])) { |
|
507 | + $tickets_remaining[$ticket->ID()] = $ticket->remaining(); |
|
508 | + } |
|
509 | + if ($tickets_remaining[$ticket->ID()] > 0) { |
|
510 | + if ( ! isset($event_reg_count[$EVT_ID])) { |
|
511 | + $event_reg_count[$EVT_ID] = 0; |
|
512 | + } |
|
513 | + $event_reg_count[$EVT_ID]++; |
|
514 | + if ( ! isset($event_spaces_remaining[$EVT_ID])) { |
|
515 | + $event_spaces_remaining[$EVT_ID] = $registration->event()->spaces_remaining_for_sale(); |
|
516 | + } |
|
517 | + } |
|
518 | 518 | if ( |
519 | 519 | $revisit |
520 | 520 | && ( |
521 | - $tickets_remaining[$ticket->ID()] === 0 |
|
522 | - || $event_reg_count[ $EVT_ID ] > $event_spaces_remaining[ $EVT_ID ] |
|
523 | - ) |
|
521 | + $tickets_remaining[$ticket->ID()] === 0 |
|
522 | + || $event_reg_count[ $EVT_ID ] > $event_spaces_remaining[ $EVT_ID ] |
|
523 | + ) |
|
524 | 524 | ) { |
525 | 525 | $ejected_registrations[ $REG_ID ] = $registration->event(); |
526 | 526 | if ( $registration->status_ID() !== EEM_Registration::status_id_wait_list ) { |
@@ -589,9 +589,9 @@ discard block |
||
589 | 589 | 'layout_strategy' => new EE_Template_Layout( |
590 | 590 | array( |
591 | 591 | 'layout_template_file' => SPCO_REG_STEPS_PATH |
592 | - . $this->_slug |
|
593 | - . DS |
|
594 | - . 'sold_out_events.template.php', |
|
592 | + . $this->_slug |
|
593 | + . DS |
|
594 | + . 'sold_out_events.template.php', |
|
595 | 595 | 'template_args' => apply_filters( |
596 | 596 | 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args', |
597 | 597 | array( |
@@ -644,9 +644,9 @@ discard block |
||
644 | 644 | 'layout_strategy' => new EE_Template_Layout( |
645 | 645 | array( |
646 | 646 | 'layout_template_file' => SPCO_REG_STEPS_PATH |
647 | - . $this->_slug |
|
648 | - . DS |
|
649 | - . 'sold_out_events.template.php', |
|
647 | + . $this->_slug |
|
648 | + . DS |
|
649 | + . 'sold_out_events.template.php', |
|
650 | 650 | 'template_args' => apply_filters( |
651 | 651 | 'FHEE__EE_SPCO_Reg_Step_Payment_Options___insufficient_spaces_available__template_args', |
652 | 652 | array( |
@@ -694,9 +694,9 @@ discard block |
||
694 | 694 | 'layout_strategy' => new EE_Template_Layout( |
695 | 695 | array( |
696 | 696 | 'layout_template_file' => SPCO_REG_STEPS_PATH |
697 | - . $this->_slug |
|
698 | - . DS |
|
699 | - . 'events_requiring_pre_approval.template.php', // layout_template |
|
697 | + . $this->_slug |
|
698 | + . DS |
|
699 | + . 'events_requiring_pre_approval.template.php', // layout_template |
|
700 | 700 | 'template_args' => apply_filters( |
701 | 701 | 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args', |
702 | 702 | array( |
@@ -734,9 +734,9 @@ discard block |
||
734 | 734 | 'layout_strategy' => new EE_Template_Layout( |
735 | 735 | array( |
736 | 736 | 'layout_template_file' => SPCO_REG_STEPS_PATH |
737 | - . $this->_slug |
|
738 | - . DS |
|
739 | - . 'no_payment_required.template.php', // layout_template |
|
737 | + . $this->_slug |
|
738 | + . DS |
|
739 | + . 'no_payment_required.template.php', // layout_template |
|
740 | 740 | 'template_args' => apply_filters( |
741 | 741 | 'FHEE__EE_SPCO_Reg_Step_Payment_Options___no_payment_required__template_args', |
742 | 742 | array( |
@@ -964,7 +964,7 @@ discard block |
||
964 | 964 | $available_payment_method_options[ $payment_method->slug() ] = $payment_method_button; |
965 | 965 | } |
966 | 966 | $payment_methods_billing_info[ $payment_method->slug() |
967 | - . '-info' ] = $this->_payment_method_billing_info( |
|
967 | + . '-info' ] = $this->_payment_method_billing_info( |
|
968 | 968 | $payment_method |
969 | 969 | ); |
970 | 970 | } |
@@ -1152,7 +1152,7 @@ discard block |
||
1152 | 1152 | // fill form with attendee info if applicable |
1153 | 1153 | if ( |
1154 | 1154 | $payment_method_billing_form instanceof EE_Billing_Attendee_Info_Form |
1155 | - && $this->checkout->transaction_has_primary_registrant() |
|
1155 | + && $this->checkout->transaction_has_primary_registrant() |
|
1156 | 1156 | ) { |
1157 | 1157 | $payment_method_billing_form->populate_from_attendee( |
1158 | 1158 | $this->checkout->transaction->primary_registration()->attendee() |
@@ -1161,7 +1161,7 @@ discard block |
||
1161 | 1161 | // and debug content |
1162 | 1162 | if ( |
1163 | 1163 | $payment_method_billing_form instanceof EE_Billing_Info_Form |
1164 | - && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base |
|
1164 | + && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base |
|
1165 | 1165 | ) { |
1166 | 1166 | $payment_method_billing_form = $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings( |
1167 | 1167 | $payment_method_billing_form |
@@ -1336,7 +1336,7 @@ discard block |
||
1336 | 1336 | } |
1337 | 1337 | // and debug content |
1338 | 1338 | if ( $this->checkout->billing_form instanceof EE_Billing_Info_Form |
1339 | - && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base |
|
1339 | + && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base |
|
1340 | 1340 | ) { |
1341 | 1341 | $this->checkout->billing_form = $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings( |
1342 | 1342 | $this->checkout->billing_form |
@@ -1506,8 +1506,8 @@ discard block |
||
1506 | 1506 | } |
1507 | 1507 | // does this attendee already exist in the db ? we're searching using a combination of first name, last name, AND email address |
1508 | 1508 | if ( ! empty( $attendee_data['ATT_fname'] ) |
1509 | - && ! empty( $attendee_data['ATT_lname'] ) |
|
1510 | - && ! empty( $attendee_data['ATT_email'] ) |
|
1509 | + && ! empty( $attendee_data['ATT_lname'] ) |
|
1510 | + && ! empty( $attendee_data['ATT_email'] ) |
|
1511 | 1511 | ) { |
1512 | 1512 | $existing_attendee = EE_Registry::instance()->LIB->EEM_Attendee->find_existing_attendee( |
1513 | 1513 | array( |
@@ -1754,7 +1754,7 @@ discard block |
||
1754 | 1754 | $payment_status = $payment->status(); |
1755 | 1755 | if ( |
1756 | 1756 | $payment_status === EEM_Payment::status_id_approved |
1757 | - || $payment_status === EEM_Payment::status_id_pending |
|
1757 | + || $payment_status === EEM_Payment::status_id_pending |
|
1758 | 1758 | ) { |
1759 | 1759 | return true; |
1760 | 1760 | } else { |
@@ -1980,8 +1980,8 @@ discard block |
||
1980 | 1980 | return false; |
1981 | 1981 | } |
1982 | 1982 | if ( ! $primary_registration->_add_relation_to( $this->checkout->primary_attendee_obj, 'Attendee' ) |
1983 | - instanceof |
|
1984 | - EE_Attendee |
|
1983 | + instanceof |
|
1984 | + EE_Attendee |
|
1985 | 1985 | ) { |
1986 | 1986 | EE_Error::add_error( |
1987 | 1987 | sprintf( |
@@ -2699,19 +2699,19 @@ discard block |
||
2699 | 2699 | |
2700 | 2700 | |
2701 | 2701 | |
2702 | - /** |
|
2703 | - * __sleep |
|
2704 | - * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon serialization |
|
2705 | - * EE_Checkout will handle the reimplementation of itself upon waking, |
|
2706 | - * but we won't bother with the reg form, because if needed, it will be regenerated anyways |
|
2707 | - * |
|
2708 | - * @return array |
|
2709 | - */ |
|
2710 | - public function __sleep() |
|
2711 | - { |
|
2712 | - // remove the reg form and the checkout |
|
2713 | - return array_diff( array_keys( get_object_vars( $this ) ), array( 'reg_form', 'checkout', 'line_item_display' ) ); |
|
2714 | - } |
|
2702 | + /** |
|
2703 | + * __sleep |
|
2704 | + * to conserve db space, let's remove the reg_form and the EE_Checkout object from EE_SPCO_Reg_Step objects upon serialization |
|
2705 | + * EE_Checkout will handle the reimplementation of itself upon waking, |
|
2706 | + * but we won't bother with the reg form, because if needed, it will be regenerated anyways |
|
2707 | + * |
|
2708 | + * @return array |
|
2709 | + */ |
|
2710 | + public function __sleep() |
|
2711 | + { |
|
2712 | + // remove the reg form and the checkout |
|
2713 | + return array_diff( array_keys( get_object_vars( $this ) ), array( 'reg_form', 'checkout', 'line_item_display' ) ); |
|
2714 | + } |
|
2715 | 2715 | |
2716 | 2716 | |
2717 | 2717 |
@@ -1,5 +1,5 @@ discard block |
||
1 | -<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
2 | - exit( 'No direct script access allowed' ); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | |
@@ -38,32 +38,32 @@ discard block |
||
38 | 38 | public static function set_hooks() { |
39 | 39 | add_filter( |
40 | 40 | 'FHEE__SPCO__EE_Line_Item_Filter_Collection', |
41 | - array( 'EE_SPCO_Reg_Step_Payment_Options', 'add_spco_line_item_filters' ) |
|
41 | + array('EE_SPCO_Reg_Step_Payment_Options', 'add_spco_line_item_filters') |
|
42 | 42 | ); |
43 | 43 | add_action( |
44 | 44 | 'wp_ajax_switch_spco_billing_form', |
45 | - array( 'EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form' ) |
|
45 | + array('EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form') |
|
46 | 46 | ); |
47 | 47 | add_action( |
48 | 48 | 'wp_ajax_nopriv_switch_spco_billing_form', |
49 | - array( 'EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form' ) |
|
49 | + array('EE_SPCO_Reg_Step_Payment_Options', 'switch_spco_billing_form') |
|
50 | 50 | ); |
51 | - add_action( 'wp_ajax_save_payer_details', array( 'EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details' ) ); |
|
51 | + add_action('wp_ajax_save_payer_details', array('EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details')); |
|
52 | 52 | add_action( |
53 | 53 | 'wp_ajax_nopriv_save_payer_details', |
54 | - array( 'EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details' ) |
|
54 | + array('EE_SPCO_Reg_Step_Payment_Options', 'save_payer_details') |
|
55 | 55 | ); |
56 | 56 | add_action( |
57 | 57 | 'wp_ajax_get_transaction_details_for_gateways', |
58 | - array( 'EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details' ) |
|
58 | + array('EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details') |
|
59 | 59 | ); |
60 | 60 | add_action( |
61 | 61 | 'wp_ajax_nopriv_get_transaction_details_for_gateways', |
62 | - array( 'EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details' ) |
|
62 | + array('EE_SPCO_Reg_Step_Payment_Options', 'get_transaction_details') |
|
63 | 63 | ); |
64 | 64 | add_filter( |
65 | 65 | 'FHEE__EED_Recaptcha___bypass_recaptcha__bypass_request_params_array', |
66 | - array( 'EE_SPCO_Reg_Step_Payment_Options', 'bypass_recaptcha_for_load_payment_method' ), |
|
66 | + array('EE_SPCO_Reg_Step_Payment_Options', 'bypass_recaptcha_for_load_payment_method'), |
|
67 | 67 | 10, |
68 | 68 | 1 |
69 | 69 | ); |
@@ -77,7 +77,7 @@ discard block |
||
77 | 77 | * @throws \EE_Error |
78 | 78 | */ |
79 | 79 | public static function switch_spco_billing_form() { |
80 | - EED_Single_Page_Checkout::process_ajax_request( 'switch_payment_method' ); |
|
80 | + EED_Single_Page_Checkout::process_ajax_request('switch_payment_method'); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | * @throws \EE_Error |
89 | 89 | */ |
90 | 90 | public static function save_payer_details() { |
91 | - EED_Single_Page_Checkout::process_ajax_request( 'save_payer_details_via_ajax' ); |
|
91 | + EED_Single_Page_Checkout::process_ajax_request('save_payer_details_via_ajax'); |
|
92 | 92 | } |
93 | 93 | |
94 | 94 | |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | * @throws \EE_Error |
100 | 100 | */ |
101 | 101 | public static function get_transaction_details() { |
102 | - EED_Single_Page_Checkout::process_ajax_request( 'get_transaction_details_for_gateways' ); |
|
102 | + EED_Single_Page_Checkout::process_ajax_request('get_transaction_details_for_gateways'); |
|
103 | 103 | } |
104 | 104 | |
105 | 105 | |
@@ -126,10 +126,10 @@ discard block |
||
126 | 126 | * @access public |
127 | 127 | * @param EE_Checkout $checkout |
128 | 128 | */ |
129 | - public function __construct( EE_Checkout $checkout ) { |
|
129 | + public function __construct(EE_Checkout $checkout) { |
|
130 | 130 | $this->_slug = 'payment_options'; |
131 | - $this->_name = __( 'Payment Options', 'event_espresso' ); |
|
132 | - $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . DS . 'payment_options_main.template.php'; |
|
131 | + $this->_name = __('Payment Options', 'event_espresso'); |
|
132 | + $this->_template = SPCO_REG_STEPS_PATH.$this->_slug.DS.'payment_options_main.template.php'; |
|
133 | 133 | $this->checkout = $checkout; |
134 | 134 | $this->_reset_success_message(); |
135 | 135 | $this->set_instructions( |
@@ -154,7 +154,7 @@ discard block |
||
154 | 154 | /** |
155 | 155 | * @param null $line_item_display |
156 | 156 | */ |
157 | - public function set_line_item_display( $line_item_display ) { |
|
157 | + public function set_line_item_display($line_item_display) { |
|
158 | 158 | $this->line_item_display = $line_item_display; |
159 | 159 | } |
160 | 160 | |
@@ -172,8 +172,8 @@ discard block |
||
172 | 172 | /** |
173 | 173 | * @param boolean $handle_IPN_in_this_request |
174 | 174 | */ |
175 | - public function set_handle_IPN_in_this_request( $handle_IPN_in_this_request ) { |
|
176 | - $this->handle_IPN_in_this_request = filter_var( $handle_IPN_in_this_request, FILTER_VALIDATE_BOOLEAN ); |
|
175 | + public function set_handle_IPN_in_this_request($handle_IPN_in_this_request) { |
|
176 | + $this->handle_IPN_in_this_request = filter_var($handle_IPN_in_this_request, FILTER_VALIDATE_BOOLEAN); |
|
177 | 177 | } |
178 | 178 | |
179 | 179 | |
@@ -208,14 +208,14 @@ discard block |
||
208 | 208 | public function enqueue_styles_and_scripts() { |
209 | 209 | $transaction = $this->checkout->transaction; |
210 | 210 | //if the transaction isn't set or nothing is owed on it, don't enqueue any JS |
211 | - if( ! $transaction instanceof EE_Transaction || EEH_Money::compare_floats( $transaction->remaining(), 0 ) ) { |
|
211 | + if ( ! $transaction instanceof EE_Transaction || EEH_Money::compare_floats($transaction->remaining(), 0)) { |
|
212 | 212 | return; |
213 | 213 | } |
214 | - foreach( EEM_Payment_Method::instance()->get_all_for_transaction( $transaction, EEM_Payment_Method::scope_cart ) as $payment_method ) { |
|
214 | + foreach (EEM_Payment_Method::instance()->get_all_for_transaction($transaction, EEM_Payment_Method::scope_cart) as $payment_method) { |
|
215 | 215 | $type_obj = $payment_method->type_obj(); |
216 | - if( $type_obj instanceof EE_PMT_Base ) { |
|
217 | - $billing_form = $type_obj->generate_new_billing_form( $transaction ); |
|
218 | - if( $billing_form instanceof EE_Form_Section_Proper ) { |
|
216 | + if ($type_obj instanceof EE_PMT_Base) { |
|
217 | + $billing_form = $type_obj->generate_new_billing_form($transaction); |
|
218 | + if ($billing_form instanceof EE_Form_Section_Proper) { |
|
219 | 219 | $billing_form->enqueue_js(); |
220 | 220 | } |
221 | 221 | } |
@@ -240,20 +240,20 @@ discard block |
||
240 | 240 | // $ 0.00 transactions (no payment required) |
241 | 241 | ! $this->checkout->payment_required() |
242 | 242 | // but do NOT remove if current action being called belongs to this reg step |
243 | - && ! is_callable( array( $this, $this->checkout->action ) ) |
|
243 | + && ! is_callable(array($this, $this->checkout->action)) |
|
244 | 244 | && ! $this->completed() |
245 | 245 | ) { |
246 | 246 | // and if so, then we no longer need the Payment Options step |
247 | - if ( $this->is_current_step() ) { |
|
247 | + if ($this->is_current_step()) { |
|
248 | 248 | $this->checkout->generate_reg_form = false; |
249 | 249 | } |
250 | - $this->checkout->remove_reg_step( $this->_slug ); |
|
250 | + $this->checkout->remove_reg_step($this->_slug); |
|
251 | 251 | // DEBUG LOG |
252 | 252 | //$this->checkout->log( __CLASS__, __FUNCTION__, __LINE__ ); |
253 | 253 | return false; |
254 | 254 | } |
255 | 255 | // load EEM_Payment_Method |
256 | - EE_Registry::instance()->load_model( 'Payment_Method' ); |
|
256 | + EE_Registry::instance()->load_model('Payment_Method'); |
|
257 | 257 | // get all active payment methods |
258 | 258 | $this->checkout->available_payment_methods = EEM_Payment_Method::instance()->get_all_for_transaction( |
259 | 259 | $this->checkout->transaction, |
@@ -280,16 +280,16 @@ discard block |
||
280 | 280 | $insufficient_spaces_available = array(); |
281 | 281 | $no_payment_required = true; |
282 | 282 | // loop thru registrations to gather info |
283 | - $registrations = $this->checkout->transaction->registrations( $this->checkout->reg_cache_where_params ); |
|
283 | + $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
284 | 284 | $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
285 | 285 | $registrations, |
286 | 286 | $this->checkout->revisit |
287 | 287 | ); |
288 | - foreach ( $registrations as $REG_ID => $registration ) { |
|
288 | + foreach ($registrations as $REG_ID => $registration) { |
|
289 | 289 | /** @var $registration EE_Registration */ |
290 | 290 | // has this registration lost it's space ? |
291 | - if ( isset( $ejected_registrations[ $REG_ID ] ) ) { |
|
292 | - $insufficient_spaces_available[ $registration->event()->ID() ] = $registration->event(); |
|
291 | + if (isset($ejected_registrations[$REG_ID])) { |
|
292 | + $insufficient_spaces_available[$registration->event()->ID()] = $registration->event(); |
|
293 | 293 | continue; |
294 | 294 | } |
295 | 295 | // event requires admin approval |
@@ -310,11 +310,11 @@ discard block |
||
310 | 310 | && $registration->status_ID() !== EEM_Registration::status_id_approved |
311 | 311 | && ( |
312 | 312 | $registration->event()->is_sold_out() |
313 | - || $registration->event()->is_sold_out( true ) |
|
313 | + || $registration->event()->is_sold_out(true) |
|
314 | 314 | ) |
315 | 315 | ) { |
316 | 316 | // add event to list of events that are sold out |
317 | - $sold_out_events[ $registration->event()->ID() ] = $registration->event(); |
|
317 | + $sold_out_events[$registration->event()->ID()] = $registration->event(); |
|
318 | 318 | do_action( |
319 | 319 | 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__sold_out_event', |
320 | 320 | $registration->event(), |
@@ -323,8 +323,8 @@ discard block |
||
323 | 323 | continue; |
324 | 324 | } |
325 | 325 | // are they allowed to pay now and is there monies owing? |
326 | - if ( $registration->owes_monies_and_can_pay() ) { |
|
327 | - $registrations_requiring_payment[ $REG_ID ] = $registration; |
|
326 | + if ($registration->owes_monies_and_can_pay()) { |
|
327 | + $registrations_requiring_payment[$REG_ID] = $registration; |
|
328 | 328 | do_action( |
329 | 329 | 'AHEE__EE_SPCO_Reg_Step_Payment_Options__generate_reg_form__event_requires_payment', |
330 | 330 | $registration->event(), |
@@ -335,29 +335,29 @@ discard block |
||
335 | 335 | && $registration->status_ID() !== EEM_Registration::status_id_not_approved |
336 | 336 | && $registration->ticket()->is_free() |
337 | 337 | ) { |
338 | - $registrations_for_free_events[ $registration->event()->ID() ] = $registration; |
|
338 | + $registrations_for_free_events[$registration->event()->ID()] = $registration; |
|
339 | 339 | } |
340 | 340 | } |
341 | 341 | $subsections = array(); |
342 | 342 | // now decide which template to load |
343 | - if ( ! empty( $sold_out_events ) ) { |
|
344 | - $subsections['sold_out_events'] = $this->_sold_out_events( $sold_out_events ); |
|
343 | + if ( ! empty($sold_out_events)) { |
|
344 | + $subsections['sold_out_events'] = $this->_sold_out_events($sold_out_events); |
|
345 | 345 | } |
346 | - if ( ! empty( $insufficient_spaces_available ) ) { |
|
346 | + if ( ! empty($insufficient_spaces_available)) { |
|
347 | 347 | $subsections['insufficient_space'] = $this->_insufficient_spaces_available( |
348 | 348 | $insufficient_spaces_available |
349 | 349 | ); |
350 | 350 | } |
351 | - if ( ! empty( $registrations_requiring_pre_approval ) ) { |
|
351 | + if ( ! empty($registrations_requiring_pre_approval)) { |
|
352 | 352 | $subsections['registrations_requiring_pre_approval'] = $this->_registrations_requiring_pre_approval( |
353 | 353 | $registrations_requiring_pre_approval |
354 | 354 | ); |
355 | 355 | } |
356 | - if ( ! empty( $registrations_for_free_events ) ) { |
|
357 | - $subsections['no_payment_required'] = $this->_no_payment_required( $registrations_for_free_events ); |
|
356 | + if ( ! empty($registrations_for_free_events)) { |
|
357 | + $subsections['no_payment_required'] = $this->_no_payment_required($registrations_for_free_events); |
|
358 | 358 | } |
359 | - if ( ! empty( $registrations_requiring_payment ) ) { |
|
360 | - if ( $this->checkout->amount_owing > 0 ) { |
|
359 | + if ( ! empty($registrations_requiring_payment)) { |
|
360 | + if ($this->checkout->amount_owing > 0) { |
|
361 | 361 | // autoload Line_Item_Display classes |
362 | 362 | EEH_Autoloader::register_line_item_filter_autoloaders(); |
363 | 363 | $line_item_filter_processor = new EE_Line_Item_Filter_Processor( |
@@ -370,15 +370,15 @@ discard block |
||
370 | 370 | /** @var EE_Line_Item $filtered_line_item_tree */ |
371 | 371 | $filtered_line_item_tree = $line_item_filter_processor->process(); |
372 | 372 | EEH_Autoloader::register_line_item_display_autoloaders(); |
373 | - $this->set_line_item_display( new EE_Line_Item_Display( 'spco' ) ); |
|
373 | + $this->set_line_item_display(new EE_Line_Item_Display('spco')); |
|
374 | 374 | $subsections['payment_options'] = $this->_display_payment_options( |
375 | 375 | $this->line_item_display->display_line_item( |
376 | 376 | $filtered_line_item_tree, |
377 | - array( 'registrations' => $registrations ) |
|
377 | + array('registrations' => $registrations) |
|
378 | 378 | ) |
379 | 379 | ); |
380 | 380 | $this->checkout->amount_owing = $filtered_line_item_tree->total(); |
381 | - $this->_apply_registration_payments_to_amount_owing( $registrations ); |
|
381 | + $this->_apply_registration_payments_to_amount_owing($registrations); |
|
382 | 382 | } |
383 | 383 | $no_payment_required = false; |
384 | 384 | } else { |
@@ -387,7 +387,7 @@ discard block |
||
387 | 387 | $this->_save_selected_method_of_payment(); |
388 | 388 | |
389 | 389 | $subsections['default_hidden_inputs'] = $this->reg_step_hidden_inputs(); |
390 | - $subsections['extra_hidden_inputs' ] = $this->_extra_hidden_inputs( $no_payment_required ); |
|
390 | + $subsections['extra_hidden_inputs'] = $this->_extra_hidden_inputs($no_payment_required); |
|
391 | 391 | |
392 | 392 | return new EE_Form_Section_Proper( |
393 | 393 | array( |
@@ -414,14 +414,14 @@ discard block |
||
414 | 414 | * @return \EE_Line_Item_Filter_Collection |
415 | 415 | * @throws \EE_Error |
416 | 416 | */ |
417 | - public static function add_spco_line_item_filters( EE_Line_Item_Filter_Collection $line_item_filter_collection ) { |
|
418 | - if ( ! EE_Registry::instance()->SSN instanceof EE_Session ) { |
|
417 | + public static function add_spco_line_item_filters(EE_Line_Item_Filter_Collection $line_item_filter_collection) { |
|
418 | + if ( ! EE_Registry::instance()->SSN instanceof EE_Session) { |
|
419 | 419 | return $line_item_filter_collection; |
420 | 420 | } |
421 | - if ( ! EE_Registry::instance()->SSN->checkout() instanceof EE_Checkout ) { |
|
421 | + if ( ! EE_Registry::instance()->SSN->checkout() instanceof EE_Checkout) { |
|
422 | 422 | return $line_item_filter_collection; |
423 | 423 | } |
424 | - if ( ! EE_Registry::instance()->SSN->checkout()->transaction instanceof EE_Transaction ) { |
|
424 | + if ( ! EE_Registry::instance()->SSN->checkout()->transaction instanceof EE_Transaction) { |
|
425 | 425 | return $line_item_filter_collection; |
426 | 426 | } |
427 | 427 | $line_item_filter_collection->add( |
@@ -433,7 +433,7 @@ discard block |
||
433 | 433 | ) |
434 | 434 | ) |
435 | 435 | ); |
436 | - $line_item_filter_collection->add( new EE_Non_Zero_Line_Item_Filter() ); |
|
436 | + $line_item_filter_collection->add(new EE_Non_Zero_Line_Item_Filter()); |
|
437 | 437 | return $line_item_filter_collection; |
438 | 438 | } |
439 | 439 | |
@@ -449,15 +449,15 @@ discard block |
||
449 | 449 | * @return \EE_Registration[] |
450 | 450 | * @throws \EE_Error |
451 | 451 | */ |
452 | - public static function remove_ejected_registrations( array $registrations ) { |
|
452 | + public static function remove_ejected_registrations(array $registrations) { |
|
453 | 453 | $ejected_registrations = EE_SPCO_Reg_Step_Payment_Options::find_registrations_that_lost_their_space( |
454 | 454 | $registrations, |
455 | 455 | EE_Registry::instance()->SSN->checkout()->revisit |
456 | 456 | ); |
457 | - foreach ( $registrations as $REG_ID => $registration ) { |
|
457 | + foreach ($registrations as $REG_ID => $registration) { |
|
458 | 458 | // has this registration lost it's space ? |
459 | - if ( isset( $ejected_registrations[ $REG_ID ] ) ) { |
|
460 | - unset( $registrations[ $REG_ID ] ); |
|
459 | + if (isset($ejected_registrations[$REG_ID])) { |
|
460 | + unset($registrations[$REG_ID]); |
|
461 | 461 | continue; |
462 | 462 | } |
463 | 463 | } |
@@ -480,7 +480,7 @@ discard block |
||
480 | 480 | * @return array |
481 | 481 | * @throws \EE_Error |
482 | 482 | */ |
483 | - public static function find_registrations_that_lost_their_space( array $registrations, $revisit = false ) { |
|
483 | + public static function find_registrations_that_lost_their_space(array $registrations, $revisit = false) { |
|
484 | 484 | // registrations per event |
485 | 485 | $event_reg_count = array(); |
486 | 486 | // spaces left per event |
@@ -489,7 +489,7 @@ discard block |
||
489 | 489 | $tickets_remaining = array(); |
490 | 490 | // registrations that have lost their space |
491 | 491 | $ejected_registrations = array(); |
492 | - foreach ( $registrations as $REG_ID => $registration ) { |
|
492 | + foreach ($registrations as $REG_ID => $registration) { |
|
493 | 493 | if ( |
494 | 494 | $registration->status_ID() === EEM_Registration::status_id_approved |
495 | 495 | || apply_filters( |
@@ -519,13 +519,13 @@ discard block |
||
519 | 519 | $revisit |
520 | 520 | && ( |
521 | 521 | $tickets_remaining[$ticket->ID()] === 0 |
522 | - || $event_reg_count[ $EVT_ID ] > $event_spaces_remaining[ $EVT_ID ] |
|
522 | + || $event_reg_count[$EVT_ID] > $event_spaces_remaining[$EVT_ID] |
|
523 | 523 | ) |
524 | 524 | ) { |
525 | - $ejected_registrations[ $REG_ID ] = $registration->event(); |
|
526 | - if ( $registration->status_ID() !== EEM_Registration::status_id_wait_list ) { |
|
525 | + $ejected_registrations[$REG_ID] = $registration->event(); |
|
526 | + if ($registration->status_ID() !== EEM_Registration::status_id_wait_list) { |
|
527 | 527 | /** @type EE_Registration_Processor $registration_processor */ |
528 | - $registration_processor = EE_Registry::instance()->load_class( 'Registration_Processor' ); |
|
528 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
529 | 529 | // at this point, we should have enough details about the registrant to consider the registration NOT incomplete |
530 | 530 | $registration_processor->manually_update_registration_status( |
531 | 531 | $registration, |
@@ -560,8 +560,8 @@ discard block |
||
560 | 560 | * @return void |
561 | 561 | */ |
562 | 562 | protected function _hide_reg_step_submit_button_if_revisit() { |
563 | - if ( $this->checkout->revisit ) { |
|
564 | - add_filter( 'FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', '__return_empty_string' ); |
|
563 | + if ($this->checkout->revisit) { |
|
564 | + add_filter('FHEE__EE_SPCO_Reg_Step__reg_step_submit_button__sbmt_btn_html', '__return_empty_string'); |
|
565 | 565 | } |
566 | 566 | } |
567 | 567 | |
@@ -575,13 +575,13 @@ discard block |
||
575 | 575 | * @return \EE_Form_Section_Proper |
576 | 576 | * @throws \EE_Error |
577 | 577 | */ |
578 | - private function _sold_out_events( $sold_out_events_array = array() ) { |
|
578 | + private function _sold_out_events($sold_out_events_array = array()) { |
|
579 | 579 | // set some defaults |
580 | 580 | $this->checkout->selected_method_of_payment = 'events_sold_out'; |
581 | 581 | $sold_out_events = ''; |
582 | - foreach ( $sold_out_events_array as $sold_out_event ) { |
|
582 | + foreach ($sold_out_events_array as $sold_out_event) { |
|
583 | 583 | $sold_out_events .= EEH_HTML::li( |
584 | - EEH_HTML::span( ' ' .$sold_out_event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text' ) |
|
584 | + EEH_HTML::span(' '.$sold_out_event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text') |
|
585 | 585 | ); |
586 | 586 | } |
587 | 587 | return new EE_Form_Section_Proper( |
@@ -599,7 +599,7 @@ discard block |
||
599 | 599 | 'sold_out_events_msg' => apply_filters( |
600 | 600 | 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__sold_out_events_msg', |
601 | 601 | sprintf( |
602 | - __( 'It appears that the event you were about to make a payment for has sold out since you first registered. If you have already made a partial payment towards this event, please contact the event administrator for a refund.%3$s%3$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%2$s', 'event_espresso' ), |
|
602 | + __('It appears that the event you were about to make a payment for has sold out since you first registered. If you have already made a partial payment towards this event, please contact the event administrator for a refund.%3$s%3$s%1$sPlease note that availability can change at any time due to cancellations, so please check back again later if registration for this event(s) is important to you.%2$s', 'event_espresso'), |
|
603 | 603 | '<strong>', |
604 | 604 | '</strong>', |
605 | 605 | '<br />' |
@@ -624,14 +624,14 @@ discard block |
||
624 | 624 | * @return \EE_Form_Section_Proper |
625 | 625 | * @throws \EE_Error |
626 | 626 | */ |
627 | - private function _insufficient_spaces_available( $insufficient_spaces_events_array = array() ) { |
|
627 | + private function _insufficient_spaces_available($insufficient_spaces_events_array = array()) { |
|
628 | 628 | // set some defaults |
629 | 629 | $this->checkout->selected_method_of_payment = 'invoice'; |
630 | 630 | $insufficient_space_events = ''; |
631 | - foreach ( $insufficient_spaces_events_array as $event ) { |
|
632 | - if ( $event instanceof EE_Event ) { |
|
631 | + foreach ($insufficient_spaces_events_array as $event) { |
|
632 | + if ($event instanceof EE_Event) { |
|
633 | 633 | $insufficient_space_events .= EEH_HTML::li( |
634 | - EEH_HTML::span( ' ' . $event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text' ) |
|
634 | + EEH_HTML::span(' '.$event->name(), '', 'dashicons dashicons-marker ee-icon-size-16 pink-text') |
|
635 | 635 | ); |
636 | 636 | } |
637 | 637 | } |
@@ -675,17 +675,17 @@ discard block |
||
675 | 675 | * @return \EE_Form_Section_Proper |
676 | 676 | * @throws \EE_Error |
677 | 677 | */ |
678 | - private function _registrations_requiring_pre_approval( $registrations_requiring_pre_approval = array() ) { |
|
678 | + private function _registrations_requiring_pre_approval($registrations_requiring_pre_approval = array()) { |
|
679 | 679 | $events_requiring_pre_approval = ''; |
680 | - foreach ( $registrations_requiring_pre_approval as $registration ) { |
|
681 | - if ( $registration instanceof EE_Registration && $registration->event() instanceof EE_Event ) { |
|
682 | - $events_requiring_pre_approval[ $registration->event()->ID() ] = EEH_HTML::li( |
|
680 | + foreach ($registrations_requiring_pre_approval as $registration) { |
|
681 | + if ($registration instanceof EE_Registration && $registration->event() instanceof EE_Event) { |
|
682 | + $events_requiring_pre_approval[$registration->event()->ID()] = EEH_HTML::li( |
|
683 | 683 | EEH_HTML::span( |
684 | 684 | '', |
685 | 685 | '', |
686 | 686 | 'dashicons dashicons-marker ee-icon-size-16 orange-text' |
687 | 687 | ) |
688 | - . EEH_HTML::span( $registration->event()->name(), '', 'orange-text' ) |
|
688 | + . EEH_HTML::span($registration->event()->name(), '', 'orange-text') |
|
689 | 689 | ); |
690 | 690 | } |
691 | 691 | } |
@@ -700,7 +700,7 @@ discard block |
||
700 | 700 | 'template_args' => apply_filters( |
701 | 701 | 'FHEE__EE_SPCO_Reg_Step_Payment_Options___sold_out_events__template_args', |
702 | 702 | array( |
703 | - 'events_requiring_pre_approval' => implode( '', $events_requiring_pre_approval ), |
|
703 | + 'events_requiring_pre_approval' => implode('', $events_requiring_pre_approval), |
|
704 | 704 | 'events_requiring_pre_approval_msg' => apply_filters( |
705 | 705 | 'FHEE__EE_SPCO_Reg_Step_Payment_Options___events_requiring_pre_approval__events_requiring_pre_approval_msg', |
706 | 706 | __( |
@@ -725,7 +725,7 @@ discard block |
||
725 | 725 | * @return \EE_Form_Section_Proper |
726 | 726 | * @throws \EE_Error |
727 | 727 | */ |
728 | - private function _no_payment_required( $registrations_for_free_events = array() ) { |
|
728 | + private function _no_payment_required($registrations_for_free_events = array()) { |
|
729 | 729 | // set some defaults |
730 | 730 | $this->checkout->selected_method_of_payment = 'no_payment_required'; |
731 | 731 | // generate no_payment_required form |
@@ -745,7 +745,7 @@ discard block |
||
745 | 745 | 'ticket_count' => array(), |
746 | 746 | 'registrations_for_free_events' => $registrations_for_free_events, |
747 | 747 | 'no_payment_required_msg' => EEH_HTML::p( |
748 | - __( 'This is a free event, so no billing will occur.', 'event_espresso' ) |
|
748 | + __('This is a free event, so no billing will occur.', 'event_espresso') |
|
749 | 749 | ) |
750 | 750 | ) |
751 | 751 | ), |
@@ -764,7 +764,7 @@ discard block |
||
764 | 764 | * @return \EE_Form_Section_Proper |
765 | 765 | * @throws \EE_Error |
766 | 766 | */ |
767 | - private function _display_payment_options( $transaction_details = '' ) { |
|
767 | + private function _display_payment_options($transaction_details = '') { |
|
768 | 768 | // has method_of_payment been set by no-js user? |
769 | 769 | $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(); |
770 | 770 | // build payment options form |
@@ -776,14 +776,14 @@ discard block |
||
776 | 776 | 'before_payment_options' => apply_filters( |
777 | 777 | 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__before_payment_options', |
778 | 778 | new EE_Form_Section_Proper( |
779 | - array( 'layout_strategy' => new EE_Div_Per_Section_Layout() ) |
|
779 | + array('layout_strategy' => new EE_Div_Per_Section_Layout()) |
|
780 | 780 | ) |
781 | 781 | ), |
782 | 782 | 'payment_options' => $this->_setup_payment_options(), |
783 | 783 | 'after_payment_options' => apply_filters( |
784 | 784 | 'FHEE__EE_SPCO_Reg_Step_Payment_Options___display_payment_options__after_payment_options', |
785 | 785 | new EE_Form_Section_Proper( |
786 | - array( 'layout_strategy' => new EE_Div_Per_Section_Layout() ) |
|
786 | + array('layout_strategy' => new EE_Div_Per_Section_Layout()) |
|
787 | 787 | ) |
788 | 788 | ), |
789 | 789 | ), |
@@ -814,10 +814,10 @@ discard block |
||
814 | 814 | * @return \EE_Form_Section_Proper |
815 | 815 | * @throws \EE_Error |
816 | 816 | */ |
817 | - private function _extra_hidden_inputs( $no_payment_required = true ) { |
|
817 | + private function _extra_hidden_inputs($no_payment_required = true) { |
|
818 | 818 | return new EE_Form_Section_Proper( |
819 | 819 | array( |
820 | - 'html_id' => 'ee-' . $this->slug() . '-extra-hidden-inputs', |
|
820 | + 'html_id' => 'ee-'.$this->slug().'-extra-hidden-inputs', |
|
821 | 821 | 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
822 | 822 | 'subsections' => array( |
823 | 823 | 'spco_no_payment_required' => new EE_Hidden_Input( |
@@ -849,16 +849,16 @@ discard block |
||
849 | 849 | * @access protected |
850 | 850 | * @param array $registrations |
851 | 851 | */ |
852 | - protected function _apply_registration_payments_to_amount_owing( array $registrations ) { |
|
852 | + protected function _apply_registration_payments_to_amount_owing(array $registrations) { |
|
853 | 853 | $payments = array(); |
854 | - foreach ( $registrations as $registration ) { |
|
855 | - if ( $registration instanceof EE_Registration && $registration->owes_monies_and_can_pay() ) { |
|
854 | + foreach ($registrations as $registration) { |
|
855 | + if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) { |
|
856 | 856 | $payments += $registration->registration_payments(); |
857 | 857 | } |
858 | 858 | } |
859 | - if ( ! empty( $payments ) ) { |
|
860 | - foreach ( $payments as $payment ) { |
|
861 | - if ( $payment instanceof EE_Registration_Payment ) { |
|
859 | + if ( ! empty($payments)) { |
|
860 | + foreach ($payments as $payment) { |
|
861 | + if ($payment instanceof EE_Registration_Payment) { |
|
862 | 862 | $this->checkout->amount_owing -= $payment->amount(); |
863 | 863 | } |
864 | 864 | } |
@@ -874,11 +874,11 @@ discard block |
||
874 | 874 | * @param bool $force_reset |
875 | 875 | * @return void |
876 | 876 | */ |
877 | - private function _reset_selected_method_of_payment( $force_reset = false ) { |
|
877 | + private function _reset_selected_method_of_payment($force_reset = false) { |
|
878 | 878 | $reset_payment_method = $force_reset |
879 | 879 | ? true |
880 | - : sanitize_text_field( EE_Registry::instance()->REQ->get( 'reset_payment_method', false ) ); |
|
881 | - if ( $reset_payment_method ) { |
|
880 | + : sanitize_text_field(EE_Registry::instance()->REQ->get('reset_payment_method', false)); |
|
881 | + if ($reset_payment_method) { |
|
882 | 882 | $this->checkout->selected_method_of_payment = null; |
883 | 883 | $this->checkout->payment_method = null; |
884 | 884 | $this->checkout->billing_form = null; |
@@ -897,12 +897,12 @@ discard block |
||
897 | 897 | * @param string $selected_method_of_payment |
898 | 898 | * @return void |
899 | 899 | */ |
900 | - private function _save_selected_method_of_payment( $selected_method_of_payment = '' ) { |
|
901 | - $selected_method_of_payment = ! empty( $selected_method_of_payment ) |
|
900 | + private function _save_selected_method_of_payment($selected_method_of_payment = '') { |
|
901 | + $selected_method_of_payment = ! empty($selected_method_of_payment) |
|
902 | 902 | ? $selected_method_of_payment |
903 | 903 | : $this->checkout->selected_method_of_payment; |
904 | 904 | EE_Registry::instance()->SSN->set_session_data( |
905 | - array( 'selected_method_of_payment' => $selected_method_of_payment ) |
|
905 | + array('selected_method_of_payment' => $selected_method_of_payment) |
|
906 | 906 | ); |
907 | 907 | } |
908 | 908 | |
@@ -918,19 +918,19 @@ discard block |
||
918 | 918 | // load payment method classes |
919 | 919 | $this->checkout->available_payment_methods = $this->_get_available_payment_methods(); |
920 | 920 | // switch up header depending on number of available payment methods |
921 | - $payment_method_header = count( $this->checkout->available_payment_methods ) > 1 |
|
921 | + $payment_method_header = count($this->checkout->available_payment_methods) > 1 |
|
922 | 922 | ? apply_filters( |
923 | 923 | 'FHEE__registration_page_payment_options__method_of_payment_hdr', |
924 | - __( 'Please Select Your Method of Payment', 'event_espresso' ) |
|
924 | + __('Please Select Your Method of Payment', 'event_espresso') |
|
925 | 925 | ) |
926 | 926 | : apply_filters( |
927 | 927 | 'FHEE__registration_page_payment_options__method_of_payment_hdr', |
928 | - __( 'Method of Payment', 'event_espresso' ) |
|
928 | + __('Method of Payment', 'event_espresso') |
|
929 | 929 | ); |
930 | 930 | $available_payment_methods = array( |
931 | 931 | // display the "Payment Method" header |
932 | 932 | 'payment_method_header' => new EE_Form_Section_HTML( |
933 | - EEH_HTML::h4( $payment_method_header, 'method-of-payment-hdr' ) |
|
933 | + EEH_HTML::h4($payment_method_header, 'method-of-payment-hdr') |
|
934 | 934 | ) |
935 | 935 | ); |
936 | 936 | // the list of actual payment methods ( invoice, paypal, etc ) in a ( slug => HTML ) format |
@@ -939,32 +939,32 @@ discard block |
||
939 | 939 | // additional instructions to be displayed and hidden below payment methods (adding a clearing div to start) |
940 | 940 | $payment_methods_billing_info = array( |
941 | 941 | new EE_Form_Section_HTML( |
942 | - EEH_HTML::div( '<br />', '', '', 'clear:both;' ) |
|
942 | + EEH_HTML::div('<br />', '', '', 'clear:both;') |
|
943 | 943 | ) |
944 | 944 | ); |
945 | 945 | // loop through payment methods |
946 | - foreach ( $this->checkout->available_payment_methods as $payment_method ) { |
|
947 | - if ( $payment_method instanceof EE_Payment_Method ) { |
|
946 | + foreach ($this->checkout->available_payment_methods as $payment_method) { |
|
947 | + if ($payment_method instanceof EE_Payment_Method) { |
|
948 | 948 | $payment_method_button = EEH_HTML::img( |
949 | 949 | $payment_method->button_url(), |
950 | 950 | $payment_method->name(), |
951 | - 'spco-payment-method-' . $payment_method->slug() . '-btn-img', |
|
951 | + 'spco-payment-method-'.$payment_method->slug().'-btn-img', |
|
952 | 952 | 'spco-payment-method-btn-img' |
953 | 953 | ); |
954 | 954 | // check if any payment methods are set as default |
955 | 955 | // if payment method is already selected OR nothing is selected and this payment method should be open_by_default |
956 | 956 | if ( |
957 | - ( $this->checkout->selected_method_of_payment === $payment_method->slug() ) |
|
958 | - || ( ! $this->checkout->selected_method_of_payment && $payment_method->open_by_default() ) |
|
957 | + ($this->checkout->selected_method_of_payment === $payment_method->slug()) |
|
958 | + || ( ! $this->checkout->selected_method_of_payment && $payment_method->open_by_default()) |
|
959 | 959 | ) { |
960 | 960 | $this->checkout->selected_method_of_payment = $payment_method->slug(); |
961 | 961 | $this->_save_selected_method_of_payment(); |
962 | - $default_payment_method_option[ $payment_method->slug() ] = $payment_method_button; |
|
962 | + $default_payment_method_option[$payment_method->slug()] = $payment_method_button; |
|
963 | 963 | } else { |
964 | - $available_payment_method_options[ $payment_method->slug() ] = $payment_method_button; |
|
964 | + $available_payment_method_options[$payment_method->slug()] = $payment_method_button; |
|
965 | 965 | } |
966 | - $payment_methods_billing_info[ $payment_method->slug() |
|
967 | - . '-info' ] = $this->_payment_method_billing_info( |
|
966 | + $payment_methods_billing_info[$payment_method->slug() |
|
967 | + . '-info'] = $this->_payment_method_billing_info( |
|
968 | 968 | $payment_method |
969 | 969 | ); |
970 | 970 | } |
@@ -994,12 +994,12 @@ discard block |
||
994 | 994 | * @return EE_Payment_Method[] |
995 | 995 | */ |
996 | 996 | protected function _get_available_payment_methods() { |
997 | - if ( ! empty( $this->checkout->available_payment_methods ) ) { |
|
997 | + if ( ! empty($this->checkout->available_payment_methods)) { |
|
998 | 998 | return $this->checkout->available_payment_methods; |
999 | 999 | } |
1000 | 1000 | $available_payment_methods = array(); |
1001 | 1001 | // load EEM_Payment_Method |
1002 | - EE_Registry::instance()->load_model( 'Payment_Method' ); |
|
1002 | + EE_Registry::instance()->load_model('Payment_Method'); |
|
1003 | 1003 | /** @type EEM_Payment_Method $EEM_Payment_Method */ |
1004 | 1004 | $EEM_Payment_Method = EE_Registry::instance()->LIB->EEM_Payment_Method; |
1005 | 1005 | // get all active payment methods |
@@ -1007,9 +1007,9 @@ discard block |
||
1007 | 1007 | $this->checkout->transaction, |
1008 | 1008 | EEM_Payment_Method::scope_cart |
1009 | 1009 | ); |
1010 | - foreach ( $payment_methods as $payment_method ) { |
|
1011 | - if ( $payment_method instanceof EE_Payment_Method ) { |
|
1012 | - $available_payment_methods[ $payment_method->slug() ] = $payment_method; |
|
1010 | + foreach ($payment_methods as $payment_method) { |
|
1011 | + if ($payment_method instanceof EE_Payment_Method) { |
|
1012 | + $available_payment_methods[$payment_method->slug()] = $payment_method; |
|
1013 | 1013 | } |
1014 | 1014 | } |
1015 | 1015 | return $available_payment_methods; |
@@ -1024,14 +1024,14 @@ discard block |
||
1024 | 1024 | * @param array $available_payment_method_options |
1025 | 1025 | * @return \EE_Form_Section_Proper |
1026 | 1026 | */ |
1027 | - private function _available_payment_method_inputs( $available_payment_method_options = array() ) { |
|
1027 | + private function _available_payment_method_inputs($available_payment_method_options = array()) { |
|
1028 | 1028 | // generate inputs |
1029 | 1029 | return new EE_Form_Section_Proper( |
1030 | 1030 | array( |
1031 | 1031 | 'html_id' => 'ee-available-payment-method-inputs', |
1032 | 1032 | 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
1033 | 1033 | 'subsections' => array( |
1034 | - '' => new EE_Radio_Button_Input ( |
|
1034 | + '' => new EE_Radio_Button_Input( |
|
1035 | 1035 | $available_payment_method_options, |
1036 | 1036 | array( |
1037 | 1037 | 'html_name' => 'selected_method_of_payment', |
@@ -1056,28 +1056,28 @@ discard block |
||
1056 | 1056 | * @return \EE_Form_Section_Proper |
1057 | 1057 | * @throws \EE_Error |
1058 | 1058 | */ |
1059 | - private function _payment_method_billing_info( EE_Payment_Method $payment_method ) { |
|
1059 | + private function _payment_method_billing_info(EE_Payment_Method $payment_method) { |
|
1060 | 1060 | $currently_selected = $this->checkout->selected_method_of_payment === $payment_method->slug() |
1061 | 1061 | ? true |
1062 | 1062 | : false; |
1063 | 1063 | // generate the billing form for payment method |
1064 | 1064 | $billing_form = $currently_selected |
1065 | - ? $this->_get_billing_form_for_payment_method( $payment_method ) |
|
1065 | + ? $this->_get_billing_form_for_payment_method($payment_method) |
|
1066 | 1066 | : new EE_Form_Section_HTML(); |
1067 | 1067 | $this->checkout->billing_form = $currently_selected |
1068 | 1068 | ? $billing_form |
1069 | 1069 | : $this->checkout->billing_form; |
1070 | 1070 | // it's all in the details |
1071 | 1071 | $info_html = EEH_HTML::h3( |
1072 | - __( 'Important information regarding your payment', 'event_espresso' ), |
|
1072 | + __('Important information regarding your payment', 'event_espresso'), |
|
1073 | 1073 | '', |
1074 | 1074 | 'spco-payment-method-hdr' |
1075 | 1075 | ); |
1076 | 1076 | // add some info regarding the step, either from what's saved in the admin, |
1077 | 1077 | // or a default string depending on whether the PM has a billing form or not |
1078 | - if ( $payment_method->description() ) { |
|
1078 | + if ($payment_method->description()) { |
|
1079 | 1079 | $payment_method_info = $payment_method->description(); |
1080 | - } elseif ( $billing_form instanceof EE_Billing_Info_Form ) { |
|
1080 | + } elseif ($billing_form instanceof EE_Billing_Info_Form) { |
|
1081 | 1081 | $payment_method_info = sprintf( |
1082 | 1082 | __( |
1083 | 1083 | 'Please provide the following billing information, then click the "%1$s" button below in order to proceed.', |
@@ -1087,7 +1087,7 @@ discard block |
||
1087 | 1087 | ); |
1088 | 1088 | } else { |
1089 | 1089 | $payment_method_info = sprintf( |
1090 | - __( 'Please click the "%1$s" button below in order to proceed.', 'event_espresso' ), |
|
1090 | + __('Please click the "%1$s" button below in order to proceed.', 'event_espresso'), |
|
1091 | 1091 | $this->submit_button_text() |
1092 | 1092 | ); |
1093 | 1093 | } |
@@ -1101,13 +1101,13 @@ discard block |
||
1101 | 1101 | ); |
1102 | 1102 | return new EE_Form_Section_Proper( |
1103 | 1103 | array( |
1104 | - 'html_id' => 'spco-payment-method-info-' . $payment_method->slug(), |
|
1104 | + 'html_id' => 'spco-payment-method-info-'.$payment_method->slug(), |
|
1105 | 1105 | 'html_class' => 'spco-payment-method-info-dv', |
1106 | 1106 | // only display the selected or default PM |
1107 | 1107 | 'html_style' => $currently_selected ? '' : 'display:none;', |
1108 | 1108 | 'layout_strategy' => new EE_Div_Per_Section_Layout(), |
1109 | 1109 | 'subsections' => array( |
1110 | - 'info' => new EE_Form_Section_HTML( $info_html ), |
|
1110 | + 'info' => new EE_Form_Section_HTML($info_html), |
|
1111 | 1111 | 'billing_form' => $currently_selected ? $billing_form : new EE_Form_Section_HTML() |
1112 | 1112 | ) |
1113 | 1113 | ) |
@@ -1125,15 +1125,15 @@ discard block |
||
1125 | 1125 | */ |
1126 | 1126 | public function get_billing_form_html_for_payment_method() { |
1127 | 1127 | // how have they chosen to pay? |
1128 | - $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment( true ); |
|
1128 | + $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
1129 | 1129 | $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment(); |
1130 | - if ( ! $this->checkout->payment_method instanceof EE_Payment_Method ) { |
|
1130 | + if ( ! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
1131 | 1131 | return false; |
1132 | 1132 | } |
1133 | - if ( apply_filters( |
|
1133 | + if (apply_filters( |
|
1134 | 1134 | 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
1135 | 1135 | false |
1136 | - ) ) { |
|
1136 | + )) { |
|
1137 | 1137 | EE_Error::add_success( |
1138 | 1138 | apply_filters( |
1139 | 1139 | 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
@@ -1148,7 +1148,7 @@ discard block |
||
1148 | 1148 | ); |
1149 | 1149 | } |
1150 | 1150 | // now generate billing form for selected method of payment |
1151 | - $payment_method_billing_form = $this->_get_billing_form_for_payment_method( $this->checkout->payment_method ); |
|
1151 | + $payment_method_billing_form = $this->_get_billing_form_for_payment_method($this->checkout->payment_method); |
|
1152 | 1152 | // fill form with attendee info if applicable |
1153 | 1153 | if ( |
1154 | 1154 | $payment_method_billing_form instanceof EE_Billing_Attendee_Info_Form |
@@ -1170,10 +1170,10 @@ discard block |
||
1170 | 1170 | $billing_info = $payment_method_billing_form instanceof EE_Form_Section_Proper |
1171 | 1171 | ? $payment_method_billing_form->get_html() |
1172 | 1172 | : ''; |
1173 | - $this->checkout->json_response->set_return_data( array( 'payment_method_info' => $billing_info ) ); |
|
1173 | + $this->checkout->json_response->set_return_data(array('payment_method_info' => $billing_info)); |
|
1174 | 1174 | // localize validation rules for main form |
1175 | 1175 | $this->checkout->current_step->reg_form->localize_validation_rules(); |
1176 | - $this->checkout->json_response->add_validation_rules( EE_Form_Section_Proper::js_localization() ); |
|
1176 | + $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization()); |
|
1177 | 1177 | return true; |
1178 | 1178 | } |
1179 | 1179 | |
@@ -1187,18 +1187,18 @@ discard block |
||
1187 | 1187 | * @return \EE_Billing_Info_Form|\EE_Form_Section_HTML |
1188 | 1188 | * @throws \EE_Error |
1189 | 1189 | */ |
1190 | - private function _get_billing_form_for_payment_method( EE_Payment_Method $payment_method ) { |
|
1190 | + private function _get_billing_form_for_payment_method(EE_Payment_Method $payment_method) { |
|
1191 | 1191 | $billing_form = $payment_method->type_obj()->billing_form( |
1192 | 1192 | $this->checkout->transaction, |
1193 | - array( 'amount_owing' => $this->checkout->amount_owing ) |
|
1193 | + array('amount_owing' => $this->checkout->amount_owing) |
|
1194 | 1194 | ); |
1195 | - if ( $billing_form instanceof EE_Billing_Info_Form ) { |
|
1195 | + if ($billing_form instanceof EE_Billing_Info_Form) { |
|
1196 | 1196 | if ( |
1197 | 1197 | apply_filters( |
1198 | 1198 | 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
1199 | 1199 | false |
1200 | 1200 | ) |
1201 | - && EE_Registry::instance()->REQ->is_set( 'payment_method' ) |
|
1201 | + && EE_Registry::instance()->REQ->is_set('payment_method') |
|
1202 | 1202 | ) { |
1203 | 1203 | EE_Error::add_success( |
1204 | 1204 | apply_filters( |
@@ -1240,15 +1240,15 @@ discard block |
||
1240 | 1240 | $request_param = 'selected_method_of_payment' |
1241 | 1241 | ) { |
1242 | 1242 | // is selected_method_of_payment set in the request ? |
1243 | - $selected_method_of_payment = EE_Registry::instance()->REQ->get( $request_param, false ); |
|
1244 | - if ( $selected_method_of_payment ) { |
|
1243 | + $selected_method_of_payment = EE_Registry::instance()->REQ->get($request_param, false); |
|
1244 | + if ($selected_method_of_payment) { |
|
1245 | 1245 | // sanitize it |
1246 | - $selected_method_of_payment = is_array( $selected_method_of_payment ) |
|
1247 | - ? array_shift( $selected_method_of_payment ) |
|
1246 | + $selected_method_of_payment = is_array($selected_method_of_payment) |
|
1247 | + ? array_shift($selected_method_of_payment) |
|
1248 | 1248 | : $selected_method_of_payment; |
1249 | - $selected_method_of_payment = sanitize_text_field( $selected_method_of_payment ); |
|
1249 | + $selected_method_of_payment = sanitize_text_field($selected_method_of_payment); |
|
1250 | 1250 | // store it in the session so that it's available for all subsequent requests including AJAX |
1251 | - $this->_save_selected_method_of_payment( $selected_method_of_payment ); |
|
1251 | + $this->_save_selected_method_of_payment($selected_method_of_payment); |
|
1252 | 1252 | } else { |
1253 | 1253 | // or is is set in the session ? |
1254 | 1254 | $selected_method_of_payment = EE_Registry::instance()->SSN->get_session_data( |
@@ -1256,7 +1256,7 @@ discard block |
||
1256 | 1256 | ); |
1257 | 1257 | } |
1258 | 1258 | // do ya really really gotta have it? |
1259 | - if ( empty( $selected_method_of_payment ) && $required ) { |
|
1259 | + if (empty($selected_method_of_payment) && $required) { |
|
1260 | 1260 | EE_Error::add_error( |
1261 | 1261 | sprintf( |
1262 | 1262 | __( |
@@ -1265,7 +1265,7 @@ discard block |
||
1265 | 1265 | ), |
1266 | 1266 | '<br/>', |
1267 | 1267 | '<br/>', |
1268 | - EE_Registry::instance()->CFG->organization->get_pretty( 'email' ) |
|
1268 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
1269 | 1269 | ), |
1270 | 1270 | __FILE__, |
1271 | 1271 | __FUNCTION__, |
@@ -1292,13 +1292,13 @@ discard block |
||
1292 | 1292 | * @throws \EE_Error |
1293 | 1293 | */ |
1294 | 1294 | public function switch_payment_method() { |
1295 | - if ( ! $this->_verify_payment_method_is_set() ) { |
|
1295 | + if ( ! $this->_verify_payment_method_is_set()) { |
|
1296 | 1296 | return false; |
1297 | 1297 | } |
1298 | - if ( apply_filters( |
|
1298 | + if (apply_filters( |
|
1299 | 1299 | 'FHEE__EE_SPCO_Reg_Step_Payment_Options__registration_checkout__selected_payment_method__display_success', |
1300 | 1300 | false |
1301 | - ) ) { |
|
1301 | + )) { |
|
1302 | 1302 | EE_Error::add_success( |
1303 | 1303 | apply_filters( |
1304 | 1304 | 'FHEE__Single_Page_Checkout__registration_checkout__selected_payment_method', |
@@ -1313,7 +1313,7 @@ discard block |
||
1313 | 1313 | ); |
1314 | 1314 | } |
1315 | 1315 | // generate billing form for selected method of payment if it hasn't been done already |
1316 | - if ( $this->checkout->payment_method->type_obj()->has_billing_form() ) { |
|
1316 | + if ($this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
1317 | 1317 | $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
1318 | 1318 | $this->checkout->payment_method |
1319 | 1319 | ); |
@@ -1335,7 +1335,7 @@ discard block |
||
1335 | 1335 | ); |
1336 | 1336 | } |
1337 | 1337 | // and debug content |
1338 | - if ( $this->checkout->billing_form instanceof EE_Billing_Info_Form |
|
1338 | + if ($this->checkout->billing_form instanceof EE_Billing_Info_Form |
|
1339 | 1339 | && $this->checkout->payment_method->type_obj() instanceof EE_PMT_Base |
1340 | 1340 | ) { |
1341 | 1341 | $this->checkout->billing_form = $this->checkout->payment_method->type_obj()->apply_billing_form_debug_settings( |
@@ -1343,15 +1343,15 @@ discard block |
||
1343 | 1343 | ); |
1344 | 1344 | } |
1345 | 1345 | // get html and validation rules for form |
1346 | - if ( $this->checkout->billing_form instanceof EE_Form_Section_Proper ) { |
|
1346 | + if ($this->checkout->billing_form instanceof EE_Form_Section_Proper) { |
|
1347 | 1347 | $this->checkout->json_response->set_return_data( |
1348 | - array( 'payment_method_info' => $this->checkout->billing_form->get_html() ) |
|
1348 | + array('payment_method_info' => $this->checkout->billing_form->get_html()) |
|
1349 | 1349 | ); |
1350 | 1350 | // localize validation rules for main form |
1351 | - $this->checkout->billing_form->localize_validation_rules( true ); |
|
1352 | - $this->checkout->json_response->add_validation_rules( EE_Form_Section_Proper::js_localization() ); |
|
1351 | + $this->checkout->billing_form->localize_validation_rules(true); |
|
1352 | + $this->checkout->json_response->add_validation_rules(EE_Form_Section_Proper::js_localization()); |
|
1353 | 1353 | } else { |
1354 | - $this->checkout->json_response->set_return_data( array( 'payment_method_info' => '' ) ); |
|
1354 | + $this->checkout->json_response->set_return_data(array('payment_method_info' => '')); |
|
1355 | 1355 | } |
1356 | 1356 | //prevents advancement to next step |
1357 | 1357 | $this->checkout->continue_reg = false; |
@@ -1368,18 +1368,18 @@ discard block |
||
1368 | 1368 | */ |
1369 | 1369 | protected function _verify_payment_method_is_set() { |
1370 | 1370 | // generate billing form for selected method of payment if it hasn't been done already |
1371 | - if ( empty( $this->checkout->selected_method_of_payment ) ) { |
|
1371 | + if (empty($this->checkout->selected_method_of_payment)) { |
|
1372 | 1372 | // how have they chosen to pay? |
1373 | - $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment( true ); |
|
1373 | + $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
1374 | 1374 | } else { |
1375 | 1375 | // choose your own adventure based on method_of_payment |
1376 | - switch ( $this->checkout->selected_method_of_payment ) { |
|
1376 | + switch ($this->checkout->selected_method_of_payment) { |
|
1377 | 1377 | case 'events_sold_out' : |
1378 | 1378 | EE_Error::add_attention( |
1379 | 1379 | apply_filters( |
1380 | 1380 | 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__sold_out_events_msg', |
1381 | - __( 'It appears that the event you were about to make a payment for has sold out since this form first loaded. Please contact the event administrator if you believe this is an error.', |
|
1382 | - 'event_espresso' ) |
|
1381 | + __('It appears that the event you were about to make a payment for has sold out since this form first loaded. Please contact the event administrator if you believe this is an error.', |
|
1382 | + 'event_espresso') |
|
1383 | 1383 | ), |
1384 | 1384 | __FILE__, __FUNCTION__, __LINE__ |
1385 | 1385 | ); |
@@ -1389,7 +1389,7 @@ discard block |
||
1389 | 1389 | EE_Error::add_attention( |
1390 | 1390 | apply_filters( |
1391 | 1391 | 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__payments_closed_msg', |
1392 | - __( 'It appears that the event you were about to make a payment for is not accepting payments at this time. Please contact the event administrator if you believe this is an error.', 'event_espresso' ) |
|
1392 | + __('It appears that the event you were about to make a payment for is not accepting payments at this time. Please contact the event administrator if you believe this is an error.', 'event_espresso') |
|
1393 | 1393 | ), |
1394 | 1394 | __FILE__, __FUNCTION__, __LINE__ |
1395 | 1395 | ); |
@@ -1399,7 +1399,7 @@ discard block |
||
1399 | 1399 | EE_Error::add_attention( |
1400 | 1400 | apply_filters( |
1401 | 1401 | 'FHEE__EE_SPCO_Reg_Step_Payment_Options___verify_payment_method_is_set__no_payment_required_msg', |
1402 | - __( 'It appears that the event you were about to make a payment for does not require payment. Please contact the event administrator if you believe this is an error.', 'event_espresso' ) |
|
1402 | + __('It appears that the event you were about to make a payment for does not require payment. Please contact the event administrator if you believe this is an error.', 'event_espresso') |
|
1403 | 1403 | ), |
1404 | 1404 | __FILE__, __FUNCTION__, __LINE__ |
1405 | 1405 | ); |
@@ -1409,7 +1409,7 @@ discard block |
||
1409 | 1409 | } |
1410 | 1410 | } |
1411 | 1411 | // verify payment method |
1412 | - if ( ! $this->checkout->payment_method instanceof EE_Payment_Method ) { |
|
1412 | + if ( ! $this->checkout->payment_method instanceof EE_Payment_Method) { |
|
1413 | 1413 | // get payment method for selected method of payment |
1414 | 1414 | $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment(); |
1415 | 1415 | } |
@@ -1428,25 +1428,25 @@ discard block |
||
1428 | 1428 | * @throws \EE_Error |
1429 | 1429 | */ |
1430 | 1430 | public function save_payer_details_via_ajax() { |
1431 | - if ( ! $this->_verify_payment_method_is_set() ) { |
|
1431 | + if ( ! $this->_verify_payment_method_is_set()) { |
|
1432 | 1432 | return; |
1433 | 1433 | } |
1434 | 1434 | // generate billing form for selected method of payment if it hasn't been done already |
1435 | - if ( $this->checkout->payment_method->type_obj()->has_billing_form() ) { |
|
1435 | + if ($this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
1436 | 1436 | $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
1437 | 1437 | $this->checkout->payment_method |
1438 | 1438 | ); |
1439 | 1439 | } |
1440 | 1440 | // generate primary attendee from payer info if applicable |
1441 | - if ( ! $this->checkout->transaction_has_primary_registrant() ) { |
|
1441 | + if ( ! $this->checkout->transaction_has_primary_registrant()) { |
|
1442 | 1442 | $attendee = $this->_create_attendee_from_request_data(); |
1443 | - if ( $attendee instanceof EE_Attendee ) { |
|
1444 | - foreach ( $this->checkout->transaction->registrations() as $registration ) { |
|
1445 | - if ( $registration->is_primary_registrant() ) { |
|
1443 | + if ($attendee instanceof EE_Attendee) { |
|
1444 | + foreach ($this->checkout->transaction->registrations() as $registration) { |
|
1445 | + if ($registration->is_primary_registrant()) { |
|
1446 | 1446 | $this->checkout->primary_attendee_obj = $attendee; |
1447 | - $registration->_add_relation_to( $attendee, 'Attendee' ); |
|
1448 | - $registration->set_attendee_id( $attendee->ID() ); |
|
1449 | - $registration->update_cache_after_object_save( 'Attendee', $attendee ); |
|
1447 | + $registration->_add_relation_to($attendee, 'Attendee'); |
|
1448 | + $registration->set_attendee_id($attendee->ID()); |
|
1449 | + $registration->update_cache_after_object_save('Attendee', $attendee); |
|
1450 | 1450 | } |
1451 | 1451 | } |
1452 | 1452 | } |
@@ -1464,50 +1464,50 @@ discard block |
||
1464 | 1464 | */ |
1465 | 1465 | protected function _create_attendee_from_request_data() { |
1466 | 1466 | // get State ID |
1467 | - $STA_ID = ! empty( $_REQUEST['state'] ) ? sanitize_text_field( $_REQUEST['state'] ) : ''; |
|
1468 | - if ( ! empty( $STA_ID ) ) { |
|
1467 | + $STA_ID = ! empty($_REQUEST['state']) ? sanitize_text_field($_REQUEST['state']) : ''; |
|
1468 | + if ( ! empty($STA_ID)) { |
|
1469 | 1469 | // can we get state object from name ? |
1470 | - EE_Registry::instance()->load_model( 'State' ); |
|
1471 | - $state = EEM_State::instance()->get_col( array( array( 'STA_name' => $STA_ID ), 'limit' => 1 ), 'STA_ID' ); |
|
1472 | - $STA_ID = is_array( $state ) && ! empty( $state ) ? reset( $state ) : $STA_ID; |
|
1470 | + EE_Registry::instance()->load_model('State'); |
|
1471 | + $state = EEM_State::instance()->get_col(array(array('STA_name' => $STA_ID), 'limit' => 1), 'STA_ID'); |
|
1472 | + $STA_ID = is_array($state) && ! empty($state) ? reset($state) : $STA_ID; |
|
1473 | 1473 | } |
1474 | 1474 | // get Country ISO |
1475 | - $CNT_ISO = ! empty( $_REQUEST['country'] ) ? sanitize_text_field( $_REQUEST['country'] ) : ''; |
|
1476 | - if ( ! empty( $CNT_ISO ) ) { |
|
1475 | + $CNT_ISO = ! empty($_REQUEST['country']) ? sanitize_text_field($_REQUEST['country']) : ''; |
|
1476 | + if ( ! empty($CNT_ISO)) { |
|
1477 | 1477 | // can we get country object from name ? |
1478 | - EE_Registry::instance()->load_model( 'Country' ); |
|
1478 | + EE_Registry::instance()->load_model('Country'); |
|
1479 | 1479 | $country = EEM_Country::instance()->get_col( |
1480 | - array( array( 'CNT_name' => $CNT_ISO ), 'limit' => 1 ), |
|
1480 | + array(array('CNT_name' => $CNT_ISO), 'limit' => 1), |
|
1481 | 1481 | 'CNT_ISO' |
1482 | 1482 | ); |
1483 | - $CNT_ISO = is_array( $country ) && ! empty( $country ) ? reset( $country ) : $CNT_ISO; |
|
1483 | + $CNT_ISO = is_array($country) && ! empty($country) ? reset($country) : $CNT_ISO; |
|
1484 | 1484 | } |
1485 | 1485 | // grab attendee data |
1486 | 1486 | $attendee_data = array( |
1487 | - 'ATT_fname' => ! empty( $_REQUEST['first_name'] ) ? sanitize_text_field( $_REQUEST['first_name'] ) : '', |
|
1488 | - 'ATT_lname' => ! empty( $_REQUEST['last_name'] ) ? sanitize_text_field( $_REQUEST['last_name'] ) : '', |
|
1489 | - 'ATT_email' => ! empty( $_REQUEST['email'] ) ? sanitize_email( $_REQUEST['email'] ) : '', |
|
1490 | - 'ATT_address' => ! empty( $_REQUEST['address'] ) ? sanitize_text_field( $_REQUEST['address'] ) : '', |
|
1491 | - 'ATT_address2' => ! empty( $_REQUEST['address2'] ) ? sanitize_text_field( $_REQUEST['address2'] ) : '', |
|
1492 | - 'ATT_city' => ! empty( $_REQUEST['city'] ) ? sanitize_text_field( $_REQUEST['city'] ) : '', |
|
1487 | + 'ATT_fname' => ! empty($_REQUEST['first_name']) ? sanitize_text_field($_REQUEST['first_name']) : '', |
|
1488 | + 'ATT_lname' => ! empty($_REQUEST['last_name']) ? sanitize_text_field($_REQUEST['last_name']) : '', |
|
1489 | + 'ATT_email' => ! empty($_REQUEST['email']) ? sanitize_email($_REQUEST['email']) : '', |
|
1490 | + 'ATT_address' => ! empty($_REQUEST['address']) ? sanitize_text_field($_REQUEST['address']) : '', |
|
1491 | + 'ATT_address2' => ! empty($_REQUEST['address2']) ? sanitize_text_field($_REQUEST['address2']) : '', |
|
1492 | + 'ATT_city' => ! empty($_REQUEST['city']) ? sanitize_text_field($_REQUEST['city']) : '', |
|
1493 | 1493 | 'STA_ID' => $STA_ID, |
1494 | 1494 | 'CNT_ISO' => $CNT_ISO, |
1495 | - 'ATT_zip' => ! empty( $_REQUEST['zip'] ) ? sanitize_text_field( $_REQUEST['zip'] ) : '', |
|
1496 | - 'ATT_phone' => ! empty( $_REQUEST['phone'] ) ? sanitize_text_field( $_REQUEST['phone'] ) : '', |
|
1495 | + 'ATT_zip' => ! empty($_REQUEST['zip']) ? sanitize_text_field($_REQUEST['zip']) : '', |
|
1496 | + 'ATT_phone' => ! empty($_REQUEST['phone']) ? sanitize_text_field($_REQUEST['phone']) : '', |
|
1497 | 1497 | ); |
1498 | 1498 | // validate the email address since it is the most important piece of info |
1499 | - if ( empty( $attendee_data['ATT_email'] ) || $attendee_data['ATT_email'] !== $_REQUEST['email'] ) { |
|
1499 | + if (empty($attendee_data['ATT_email']) || $attendee_data['ATT_email'] !== $_REQUEST['email']) { |
|
1500 | 1500 | EE_Error::add_error( |
1501 | - __( 'An invalid email address was submitted.', 'event_espresso' ), |
|
1501 | + __('An invalid email address was submitted.', 'event_espresso'), |
|
1502 | 1502 | __FILE__, |
1503 | 1503 | __FUNCTION__, |
1504 | 1504 | __LINE__ |
1505 | 1505 | ); |
1506 | 1506 | } |
1507 | 1507 | // does this attendee already exist in the db ? we're searching using a combination of first name, last name, AND email address |
1508 | - if ( ! empty( $attendee_data['ATT_fname'] ) |
|
1509 | - && ! empty( $attendee_data['ATT_lname'] ) |
|
1510 | - && ! empty( $attendee_data['ATT_email'] ) |
|
1508 | + if ( ! empty($attendee_data['ATT_fname']) |
|
1509 | + && ! empty($attendee_data['ATT_lname']) |
|
1510 | + && ! empty($attendee_data['ATT_email']) |
|
1511 | 1511 | ) { |
1512 | 1512 | $existing_attendee = EE_Registry::instance()->LIB->EEM_Attendee->find_existing_attendee( |
1513 | 1513 | array( |
@@ -1516,19 +1516,19 @@ discard block |
||
1516 | 1516 | 'ATT_email' => $attendee_data['ATT_email'] |
1517 | 1517 | ) |
1518 | 1518 | ); |
1519 | - if ( $existing_attendee instanceof EE_Attendee ) { |
|
1519 | + if ($existing_attendee instanceof EE_Attendee) { |
|
1520 | 1520 | return $existing_attendee; |
1521 | 1521 | } |
1522 | 1522 | } |
1523 | 1523 | // no existing attendee? kk let's create a new one |
1524 | 1524 | // kinda lame, but we need a first and last name to create an attendee, so use the email address if those don't exist |
1525 | - $attendee_data['ATT_fname'] = ! empty( $attendee_data['ATT_fname'] ) |
|
1525 | + $attendee_data['ATT_fname'] = ! empty($attendee_data['ATT_fname']) |
|
1526 | 1526 | ? $attendee_data['ATT_fname'] |
1527 | 1527 | : $attendee_data['ATT_email']; |
1528 | - $attendee_data['ATT_lname'] = ! empty( $attendee_data['ATT_lname'] ) |
|
1528 | + $attendee_data['ATT_lname'] = ! empty($attendee_data['ATT_lname']) |
|
1529 | 1529 | ? $attendee_data['ATT_lname'] |
1530 | 1530 | : $attendee_data['ATT_email']; |
1531 | - return EE_Attendee::new_instance( $attendee_data ); |
|
1531 | + return EE_Attendee::new_instance($attendee_data); |
|
1532 | 1532 | } |
1533 | 1533 | |
1534 | 1534 | |
@@ -1546,26 +1546,26 @@ discard block |
||
1546 | 1546 | // how have they chosen to pay? |
1547 | 1547 | $this->checkout->selected_method_of_payment = $this->checkout->transaction->is_free() |
1548 | 1548 | ? 'no_payment_required' |
1549 | - : $this->_get_selected_method_of_payment( true ); |
|
1549 | + : $this->_get_selected_method_of_payment(true); |
|
1550 | 1550 | // choose your own adventure based on method_of_payment |
1551 | - switch ( $this->checkout->selected_method_of_payment ) { |
|
1551 | + switch ($this->checkout->selected_method_of_payment) { |
|
1552 | 1552 | |
1553 | 1553 | case 'events_sold_out' : |
1554 | 1554 | $this->checkout->redirect = true; |
1555 | 1555 | $this->checkout->redirect_url = $this->checkout->cancel_page_url; |
1556 | - $this->checkout->json_response->set_redirect_url( $this->checkout->redirect_url ); |
|
1556 | + $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
1557 | 1557 | // mark this reg step as completed |
1558 | 1558 | $this->set_completed(); |
1559 | 1559 | return false; |
1560 | 1560 | break; |
1561 | 1561 | |
1562 | 1562 | case 'payments_closed' : |
1563 | - if ( apply_filters( |
|
1563 | + if (apply_filters( |
|
1564 | 1564 | 'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__payments_closed__display_success', |
1565 | 1565 | false |
1566 | - ) ) { |
|
1566 | + )) { |
|
1567 | 1567 | EE_Error::add_success( |
1568 | - __( 'no payment required at this time.', 'event_espresso' ), |
|
1568 | + __('no payment required at this time.', 'event_espresso'), |
|
1569 | 1569 | __FILE__, |
1570 | 1570 | __FUNCTION__, |
1571 | 1571 | __LINE__ |
@@ -1577,12 +1577,12 @@ discard block |
||
1577 | 1577 | break; |
1578 | 1578 | |
1579 | 1579 | case 'no_payment_required' : |
1580 | - if ( apply_filters( |
|
1580 | + if (apply_filters( |
|
1581 | 1581 | 'FHEE__EE_SPCO_Reg_Step_Payment_Options__process_reg_step__no_payment_required__display_success', |
1582 | 1582 | false |
1583 | - ) ) { |
|
1583 | + )) { |
|
1584 | 1584 | EE_Error::add_success( |
1585 | - __( 'no payment required.', 'event_espresso' ), |
|
1585 | + __('no payment required.', 'event_espresso'), |
|
1586 | 1586 | __FILE__, |
1587 | 1587 | __FUNCTION__, |
1588 | 1588 | __LINE__ |
@@ -1602,15 +1602,15 @@ discard block |
||
1602 | 1602 | EE_Registry::instance()->SSN->checkout()->revisit |
1603 | 1603 | ); |
1604 | 1604 | // calculate difference between the two arrays |
1605 | - $registrations = array_diff( $registrations, $ejected_registrations ); |
|
1606 | - if ( empty( $registrations ) ) { |
|
1605 | + $registrations = array_diff($registrations, $ejected_registrations); |
|
1606 | + if (empty($registrations)) { |
|
1607 | 1607 | $this->_redirect_because_event_sold_out(); |
1608 | 1608 | return false; |
1609 | 1609 | } |
1610 | 1610 | $payment_successful = $this->_process_payment(); |
1611 | - if ( $payment_successful ) { |
|
1611 | + if ($payment_successful) { |
|
1612 | 1612 | $this->checkout->continue_reg = true; |
1613 | - $this->_maybe_set_completed( $this->checkout->payment_method ); |
|
1613 | + $this->_maybe_set_completed($this->checkout->payment_method); |
|
1614 | 1614 | } else { |
1615 | 1615 | $this->checkout->continue_reg = false; |
1616 | 1616 | } |
@@ -1631,10 +1631,10 @@ discard block |
||
1631 | 1631 | $this->checkout->continue_reg = false; |
1632 | 1632 | // set redirect URL |
1633 | 1633 | $this->checkout->redirect_url = add_query_arg( |
1634 | - array( 'e_reg_url_link' => $this->checkout->reg_url_link ), |
|
1634 | + array('e_reg_url_link' => $this->checkout->reg_url_link), |
|
1635 | 1635 | $this->checkout->current_step->reg_step_url() |
1636 | 1636 | ); |
1637 | - $this->checkout->json_response->set_redirect_url( $this->checkout->redirect_url ); |
|
1637 | + $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
1638 | 1638 | } |
1639 | 1639 | |
1640 | 1640 | |
@@ -1647,8 +1647,8 @@ discard block |
||
1647 | 1647 | * @return void |
1648 | 1648 | * @throws \EE_Error |
1649 | 1649 | */ |
1650 | - protected function _maybe_set_completed( EE_Payment_Method $payment_method ) { |
|
1651 | - switch ( $payment_method->type_obj()->payment_occurs() ) { |
|
1650 | + protected function _maybe_set_completed(EE_Payment_Method $payment_method) { |
|
1651 | + switch ($payment_method->type_obj()->payment_occurs()) { |
|
1652 | 1652 | case EE_PMT_Base::offsite : |
1653 | 1653 | break; |
1654 | 1654 | case EE_PMT_Base::onsite : |
@@ -1671,7 +1671,7 @@ discard block |
||
1671 | 1671 | public function update_reg_step() { |
1672 | 1672 | $success = true; |
1673 | 1673 | // if payment required |
1674 | - if ( $this->checkout->transaction->total() > 0 ) { |
|
1674 | + if ($this->checkout->transaction->total() > 0) { |
|
1675 | 1675 | do_action( |
1676 | 1676 | 'AHEE__EE_Single_Page_Checkout__process_finalize_registration__before_gateway', |
1677 | 1677 | $this->checkout->transaction |
@@ -1679,13 +1679,13 @@ discard block |
||
1679 | 1679 | // attempt payment via payment method |
1680 | 1680 | $success = $this->process_reg_step(); |
1681 | 1681 | } |
1682 | - if ( $success && ! $this->checkout->redirect ) { |
|
1682 | + if ($success && ! $this->checkout->redirect) { |
|
1683 | 1683 | $this->checkout->cart->get_grand_total()->save_this_and_descendants_to_txn( |
1684 | 1684 | $this->checkout->transaction->ID() |
1685 | 1685 | ); |
1686 | 1686 | // set return URL |
1687 | 1687 | $this->checkout->redirect_url = add_query_arg( |
1688 | - array( 'e_reg_url_link' => $this->checkout->reg_url_link ), |
|
1688 | + array('e_reg_url_link' => $this->checkout->reg_url_link), |
|
1689 | 1689 | $this->checkout->thank_you_page_url |
1690 | 1690 | ); |
1691 | 1691 | } |
@@ -1703,36 +1703,36 @@ discard block |
||
1703 | 1703 | */ |
1704 | 1704 | private function _process_payment() { |
1705 | 1705 | // basically confirm that the event hasn't sold out since they hit the page |
1706 | - if ( ! $this->_last_second_ticket_verifications() ) { |
|
1706 | + if ( ! $this->_last_second_ticket_verifications()) { |
|
1707 | 1707 | return false; |
1708 | 1708 | } |
1709 | 1709 | // ya gotta make a choice man |
1710 | - if ( empty( $this->checkout->selected_method_of_payment ) ) { |
|
1710 | + if (empty($this->checkout->selected_method_of_payment)) { |
|
1711 | 1711 | $this->checkout->json_response->set_plz_select_method_of_payment( |
1712 | - __( 'Please select a method of payment before proceeding.', 'event_espresso' ) |
|
1712 | + __('Please select a method of payment before proceeding.', 'event_espresso') |
|
1713 | 1713 | ); |
1714 | 1714 | return false; |
1715 | 1715 | } |
1716 | 1716 | // get EE_Payment_Method object |
1717 | - if ( ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment() ) { |
|
1717 | + if ( ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
1718 | 1718 | return false; |
1719 | 1719 | } |
1720 | 1720 | // setup billing form |
1721 | - if ( $this->checkout->payment_method->is_on_site() ) { |
|
1721 | + if ($this->checkout->payment_method->is_on_site()) { |
|
1722 | 1722 | $this->checkout->billing_form = $this->_get_billing_form_for_payment_method( |
1723 | 1723 | $this->checkout->payment_method |
1724 | 1724 | ); |
1725 | 1725 | // bad billing form ? |
1726 | - if ( ! $this->_billing_form_is_valid() ) { |
|
1726 | + if ( ! $this->_billing_form_is_valid()) { |
|
1727 | 1727 | return false; |
1728 | 1728 | } |
1729 | 1729 | } |
1730 | 1730 | // ensure primary registrant has been fully processed |
1731 | - if ( ! $this->_setup_primary_registrant_prior_to_payment() ) { |
|
1731 | + if ( ! $this->_setup_primary_registrant_prior_to_payment()) { |
|
1732 | 1732 | return false; |
1733 | 1733 | } |
1734 | 1734 | // if session is close to expiring (under 10 minutes by default) |
1735 | - if ( ( time() - EE_Registry::instance()->SSN->expiration() ) < EE_Registry::instance()->SSN->extension() ) { |
|
1735 | + if ((time() - EE_Registry::instance()->SSN->expiration()) < EE_Registry::instance()->SSN->extension()) { |
|
1736 | 1736 | // add some time to session expiration so that payment can be completed |
1737 | 1737 | EE_Registry::instance()->SSN->extend_expiration(); |
1738 | 1738 | } |
@@ -1741,12 +1741,12 @@ discard block |
||
1741 | 1741 | // in case a registrant leaves to an Off-Site Gateway and never returns, we want to approve any registrations for events with a default reg status of Approved |
1742 | 1742 | //$transaction_processor->toggle_registration_statuses_for_default_approved_events( $this->checkout->transaction, $this->checkout->reg_cache_where_params ); |
1743 | 1743 | // attempt payment |
1744 | - $payment = $this->_attempt_payment( $this->checkout->payment_method ); |
|
1744 | + $payment = $this->_attempt_payment($this->checkout->payment_method); |
|
1745 | 1745 | // process results |
1746 | - $payment = $this->_validate_payment( $payment ); |
|
1747 | - $payment = $this->_post_payment_processing( $payment ); |
|
1746 | + $payment = $this->_validate_payment($payment); |
|
1747 | + $payment = $this->_post_payment_processing($payment); |
|
1748 | 1748 | // verify payment |
1749 | - if ( $payment instanceof EE_Payment ) { |
|
1749 | + if ($payment instanceof EE_Payment) { |
|
1750 | 1750 | // store that for later |
1751 | 1751 | $this->checkout->payment = $payment; |
1752 | 1752 | // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to abandoned |
@@ -1760,7 +1760,7 @@ discard block |
||
1760 | 1760 | } else { |
1761 | 1761 | return false; |
1762 | 1762 | } |
1763 | - } else if ( $payment === true ) { |
|
1763 | + } else if ($payment === true) { |
|
1764 | 1764 | // please note that offline payment methods will NOT make a payment, |
1765 | 1765 | // but instead just mark themselves as the PMD_ID on the transaction, and return true |
1766 | 1766 | $this->checkout->payment = $payment; |
@@ -1780,22 +1780,22 @@ discard block |
||
1780 | 1780 | */ |
1781 | 1781 | protected function _last_second_ticket_verifications() { |
1782 | 1782 | // don't bother re-validating if not a return visit |
1783 | - if ( ! $this->checkout->revisit ) { |
|
1783 | + if ( ! $this->checkout->revisit) { |
|
1784 | 1784 | return true; |
1785 | 1785 | } |
1786 | 1786 | $registrations = $this->checkout->transaction->registrations(); |
1787 | - if ( empty( $registrations ) ) { |
|
1787 | + if (empty($registrations)) { |
|
1788 | 1788 | return false; |
1789 | 1789 | } |
1790 | - foreach ( $registrations as $registration ) { |
|
1791 | - if ( $registration instanceof EE_Registration ) { |
|
1790 | + foreach ($registrations as $registration) { |
|
1791 | + if ($registration instanceof EE_Registration) { |
|
1792 | 1792 | $event = $registration->event_obj(); |
1793 | - if ( $event instanceof EE_Event && $event->is_sold_out( true ) ) { |
|
1793 | + if ($event instanceof EE_Event && $event->is_sold_out(true)) { |
|
1794 | 1794 | EE_Error::add_error( |
1795 | 1795 | apply_filters( |
1796 | 1796 | 'FHEE__EE_SPCO_Reg_Step_Payment_Options___last_second_ticket_verifications__sold_out_events_msg', |
1797 | 1797 | sprintf( |
1798 | - __( 'It appears that the %1$s event that you were about to make a payment for has sold out since you first registered and/or arrived at this page. Please refresh the page and try again. If you have already made a partial payment towards this event, please contact the event administrator for a refund.', 'event_espresso' ), |
|
1798 | + __('It appears that the %1$s event that you were about to make a payment for has sold out since you first registered and/or arrived at this page. Please refresh the page and try again. If you have already made a partial payment towards this event, please contact the event administrator for a refund.', 'event_espresso'), |
|
1799 | 1799 | $event->name() |
1800 | 1800 | ) |
1801 | 1801 | ), |
@@ -1825,7 +1825,7 @@ discard block |
||
1825 | 1825 | ); |
1826 | 1826 | $html = $payment_method_billing_info->get_html(); |
1827 | 1827 | $html .= $this->checkout->redirect_form; |
1828 | - EE_Registry::instance()->REQ->add_output( $html ); |
|
1828 | + EE_Registry::instance()->REQ->add_output($html); |
|
1829 | 1829 | return true; |
1830 | 1830 | } |
1831 | 1831 | |
@@ -1839,28 +1839,28 @@ discard block |
||
1839 | 1839 | * @throws \EE_Error |
1840 | 1840 | */ |
1841 | 1841 | private function _billing_form_is_valid() { |
1842 | - if ( ! $this->checkout->payment_method->type_obj()->has_billing_form() ) { |
|
1842 | + if ( ! $this->checkout->payment_method->type_obj()->has_billing_form()) { |
|
1843 | 1843 | return true; |
1844 | 1844 | } |
1845 | - if ( $this->checkout->billing_form instanceof EE_Billing_Info_Form ) { |
|
1846 | - if ( $this->checkout->billing_form->was_submitted() ) { |
|
1845 | + if ($this->checkout->billing_form instanceof EE_Billing_Info_Form) { |
|
1846 | + if ($this->checkout->billing_form->was_submitted()) { |
|
1847 | 1847 | $this->checkout->billing_form->receive_form_submission(); |
1848 | - if ( $this->checkout->billing_form->is_valid() ) { |
|
1848 | + if ($this->checkout->billing_form->is_valid()) { |
|
1849 | 1849 | return true; |
1850 | 1850 | } |
1851 | 1851 | $validation_errors = $this->checkout->billing_form->get_validation_errors_accumulated(); |
1852 | 1852 | $error_strings = array(); |
1853 | - foreach ( $validation_errors as $validation_error ) { |
|
1854 | - if ( $validation_error instanceof EE_Validation_Error ) { |
|
1853 | + foreach ($validation_errors as $validation_error) { |
|
1854 | + if ($validation_error instanceof EE_Validation_Error) { |
|
1855 | 1855 | $form_section = $validation_error->get_form_section(); |
1856 | - if ( $form_section instanceof EE_Form_Input_Base ) { |
|
1856 | + if ($form_section instanceof EE_Form_Input_Base) { |
|
1857 | 1857 | $label = $form_section->html_label_text(); |
1858 | - } elseif ( $form_section instanceof EE_Form_Section_Base ) { |
|
1858 | + } elseif ($form_section instanceof EE_Form_Section_Base) { |
|
1859 | 1859 | $label = $form_section->name(); |
1860 | 1860 | } else { |
1861 | - $label = __( 'Validation Error', 'event_espresso' ); |
|
1861 | + $label = __('Validation Error', 'event_espresso'); |
|
1862 | 1862 | } |
1863 | - $error_strings[] = sprintf( '%1$s: %2$s', $label, $validation_error->getMessage() ); |
|
1863 | + $error_strings[] = sprintf('%1$s: %2$s', $label, $validation_error->getMessage()); |
|
1864 | 1864 | } |
1865 | 1865 | } |
1866 | 1866 | EE_Error::add_error( |
@@ -1870,7 +1870,7 @@ discard block |
||
1870 | 1870 | 'event_espresso' |
1871 | 1871 | ), |
1872 | 1872 | '<br/>', |
1873 | - implode( '<br/>', $error_strings ) |
|
1873 | + implode('<br/>', $error_strings) |
|
1874 | 1874 | ), |
1875 | 1875 | __FILE__, |
1876 | 1876 | __FUNCTION__, |
@@ -1889,7 +1889,7 @@ discard block |
||
1889 | 1889 | } |
1890 | 1890 | } else { |
1891 | 1891 | EE_Error::add_error( |
1892 | - __( 'The submitted billing form is invalid possibly due to a technical reason.', 'event_espresso' ), |
|
1892 | + __('The submitted billing form is invalid possibly due to a technical reason.', 'event_espresso'), |
|
1893 | 1893 | __FILE__, |
1894 | 1894 | __FUNCTION__, |
1895 | 1895 | __LINE__ |
@@ -1928,7 +1928,7 @@ discard block |
||
1928 | 1928 | // save the TXN ( which clears cached copy of primary_registration) |
1929 | 1929 | $this->checkout->transaction->save(); |
1930 | 1930 | // grab TXN ID and save it to the primary_registration |
1931 | - $primary_registration->set_transaction_id( $this->checkout->transaction->ID() ); |
|
1931 | + $primary_registration->set_transaction_id($this->checkout->transaction->ID()); |
|
1932 | 1932 | // save what we have so far |
1933 | 1933 | $primary_registration->save(); |
1934 | 1934 | return true; |
@@ -1946,7 +1946,7 @@ discard block |
||
1946 | 1946 | private function _capture_primary_registration_data_from_billing_form() { |
1947 | 1947 | // convert billing form data into an attendee |
1948 | 1948 | $this->checkout->primary_attendee_obj = $this->checkout->billing_form->create_attendee_from_billing_form_data(); |
1949 | - if ( ! $this->checkout->primary_attendee_obj instanceof EE_Attendee ) { |
|
1949 | + if ( ! $this->checkout->primary_attendee_obj instanceof EE_Attendee) { |
|
1950 | 1950 | EE_Error::add_error( |
1951 | 1951 | sprintf( |
1952 | 1952 | __( |
@@ -1954,7 +1954,7 @@ discard block |
||
1954 | 1954 | 'event_espresso' |
1955 | 1955 | ), |
1956 | 1956 | '<br/>', |
1957 | - EE_Registry::instance()->CFG->organization->get_pretty( 'email' ) |
|
1957 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
1958 | 1958 | ), |
1959 | 1959 | __FILE__, |
1960 | 1960 | __FUNCTION__, |
@@ -1963,7 +1963,7 @@ discard block |
||
1963 | 1963 | return false; |
1964 | 1964 | } |
1965 | 1965 | $primary_registration = $this->checkout->transaction->primary_registration(); |
1966 | - if ( ! $primary_registration instanceof EE_Registration ) { |
|
1966 | + if ( ! $primary_registration instanceof EE_Registration) { |
|
1967 | 1967 | EE_Error::add_error( |
1968 | 1968 | sprintf( |
1969 | 1969 | __( |
@@ -1971,7 +1971,7 @@ discard block |
||
1971 | 1971 | 'event_espresso' |
1972 | 1972 | ), |
1973 | 1973 | '<br/>', |
1974 | - EE_Registry::instance()->CFG->organization->get_pretty( 'email' ) |
|
1974 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
1975 | 1975 | ), |
1976 | 1976 | __FILE__, |
1977 | 1977 | __FUNCTION__, |
@@ -1979,7 +1979,7 @@ discard block |
||
1979 | 1979 | ); |
1980 | 1980 | return false; |
1981 | 1981 | } |
1982 | - if ( ! $primary_registration->_add_relation_to( $this->checkout->primary_attendee_obj, 'Attendee' ) |
|
1982 | + if ( ! $primary_registration->_add_relation_to($this->checkout->primary_attendee_obj, 'Attendee') |
|
1983 | 1983 | instanceof |
1984 | 1984 | EE_Attendee |
1985 | 1985 | ) { |
@@ -1990,7 +1990,7 @@ discard block |
||
1990 | 1990 | 'event_espresso' |
1991 | 1991 | ), |
1992 | 1992 | '<br/>', |
1993 | - EE_Registry::instance()->CFG->organization->get_pretty( 'email' ) |
|
1993 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
1994 | 1994 | ), |
1995 | 1995 | __FILE__, |
1996 | 1996 | __FUNCTION__, |
@@ -1999,9 +1999,9 @@ discard block |
||
1999 | 1999 | return false; |
2000 | 2000 | } |
2001 | 2001 | /** @type EE_Registration_Processor $registration_processor */ |
2002 | - $registration_processor = EE_Registry::instance()->load_class( 'Registration_Processor' ); |
|
2002 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
2003 | 2003 | // at this point, we should have enough details about the registrant to consider the registration NOT incomplete |
2004 | - $registration_processor->toggle_incomplete_registration_status_to_default( $primary_registration ); |
|
2004 | + $registration_processor->toggle_incomplete_registration_status_to_default($primary_registration); |
|
2005 | 2005 | return true; |
2006 | 2006 | } |
2007 | 2007 | |
@@ -2016,22 +2016,22 @@ discard block |
||
2016 | 2016 | * @throws \EE_Error |
2017 | 2017 | */ |
2018 | 2018 | private function _get_payment_method_for_selected_method_of_payment() { |
2019 | - if ( $this->checkout->selected_method_of_payment === 'events_sold_out' ) { |
|
2019 | + if ($this->checkout->selected_method_of_payment === 'events_sold_out') { |
|
2020 | 2020 | $this->_redirect_because_event_sold_out(); |
2021 | 2021 | return null; |
2022 | 2022 | } |
2023 | 2023 | // get EE_Payment_Method object |
2024 | - if ( isset( $this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ] ) ) { |
|
2025 | - $payment_method = $this->checkout->available_payment_methods[ $this->checkout->selected_method_of_payment ]; |
|
2024 | + if (isset($this->checkout->available_payment_methods[$this->checkout->selected_method_of_payment])) { |
|
2025 | + $payment_method = $this->checkout->available_payment_methods[$this->checkout->selected_method_of_payment]; |
|
2026 | 2026 | } else { |
2027 | 2027 | // load EEM_Payment_Method |
2028 | - EE_Registry::instance()->load_model( 'Payment_Method' ); |
|
2028 | + EE_Registry::instance()->load_model('Payment_Method'); |
|
2029 | 2029 | /** @type EEM_Payment_Method $EEM_Payment_Method */ |
2030 | 2030 | $EEM_Payment_Method = EE_Registry::instance()->LIB->EEM_Payment_Method; |
2031 | - $payment_method = $EEM_Payment_Method->get_one_by_slug( $this->checkout->selected_method_of_payment ); |
|
2031 | + $payment_method = $EEM_Payment_Method->get_one_by_slug($this->checkout->selected_method_of_payment); |
|
2032 | 2032 | } |
2033 | 2033 | // verify $payment_method |
2034 | - if ( ! $payment_method instanceof EE_Payment_Method ) { |
|
2034 | + if ( ! $payment_method instanceof EE_Payment_Method) { |
|
2035 | 2035 | // not a payment |
2036 | 2036 | EE_Error::add_error( |
2037 | 2037 | sprintf( |
@@ -2040,7 +2040,7 @@ discard block |
||
2040 | 2040 | 'event_espresso' |
2041 | 2041 | ), |
2042 | 2042 | '<br/>', |
2043 | - EE_Registry::instance()->CFG->organization->get_pretty( 'email' ) |
|
2043 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2044 | 2044 | ), |
2045 | 2045 | __FILE__, |
2046 | 2046 | __FUNCTION__, |
@@ -2049,7 +2049,7 @@ discard block |
||
2049 | 2049 | return null; |
2050 | 2050 | } |
2051 | 2051 | // and verify it has a valid Payment_Method Type object |
2052 | - if ( ! $payment_method->type_obj() instanceof EE_PMT_Base ) { |
|
2052 | + if ( ! $payment_method->type_obj() instanceof EE_PMT_Base) { |
|
2053 | 2053 | // not a payment |
2054 | 2054 | EE_Error::add_error( |
2055 | 2055 | sprintf( |
@@ -2058,7 +2058,7 @@ discard block |
||
2058 | 2058 | 'event_espresso' |
2059 | 2059 | ), |
2060 | 2060 | '<br/>', |
2061 | - EE_Registry::instance()->CFG->organization->get_pretty( 'email' ) |
|
2061 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2062 | 2062 | ), |
2063 | 2063 | __FILE__, |
2064 | 2064 | __FUNCTION__, |
@@ -2079,29 +2079,29 @@ discard block |
||
2079 | 2079 | * @return mixed EE_Payment | boolean |
2080 | 2080 | * @throws \EE_Error |
2081 | 2081 | */ |
2082 | - private function _attempt_payment( EE_Payment_Method $payment_method ) { |
|
2082 | + private function _attempt_payment(EE_Payment_Method $payment_method) { |
|
2083 | 2083 | $payment = null; |
2084 | 2084 | $this->checkout->transaction->save(); |
2085 | - $payment_processor = EE_Registry::instance()->load_core( 'Payment_Processor' ); |
|
2086 | - if ( ! $payment_processor instanceof EE_Payment_Processor ) { |
|
2085 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
2086 | + if ( ! $payment_processor instanceof EE_Payment_Processor) { |
|
2087 | 2087 | return false; |
2088 | 2088 | } |
2089 | 2089 | try { |
2090 | - $payment_processor->set_revisit( $this->checkout->revisit ); |
|
2090 | + $payment_processor->set_revisit($this->checkout->revisit); |
|
2091 | 2091 | // generate payment object |
2092 | 2092 | $payment = $payment_processor->process_payment( |
2093 | 2093 | $payment_method, |
2094 | 2094 | $this->checkout->transaction, |
2095 | 2095 | $this->checkout->amount_owing, |
2096 | 2096 | $this->checkout->billing_form, |
2097 | - $this->_get_return_url( $payment_method ), |
|
2097 | + $this->_get_return_url($payment_method), |
|
2098 | 2098 | 'CART', |
2099 | 2099 | $this->checkout->admin_request, |
2100 | 2100 | true, |
2101 | 2101 | $this->reg_step_url() |
2102 | 2102 | ); |
2103 | - } catch ( Exception $e ) { |
|
2104 | - $this->_handle_payment_processor_exception( $e ); |
|
2103 | + } catch (Exception $e) { |
|
2104 | + $this->_handle_payment_processor_exception($e); |
|
2105 | 2105 | } |
2106 | 2106 | return $payment; |
2107 | 2107 | } |
@@ -2116,7 +2116,7 @@ discard block |
||
2116 | 2116 | * @return void |
2117 | 2117 | * @throws \EE_Error |
2118 | 2118 | */ |
2119 | - protected function _handle_payment_processor_exception( Exception $e ) { |
|
2119 | + protected function _handle_payment_processor_exception(Exception $e) { |
|
2120 | 2120 | EE_Error::add_error( |
2121 | 2121 | sprintf( |
2122 | 2122 | __( |
@@ -2124,7 +2124,7 @@ discard block |
||
2124 | 2124 | 'event_espresso' |
2125 | 2125 | ), |
2126 | 2126 | '<br/>', |
2127 | - EE_Registry::instance()->CFG->organization->get_pretty( 'email' ), |
|
2127 | + EE_Registry::instance()->CFG->organization->get_pretty('email'), |
|
2128 | 2128 | $e->getMessage(), |
2129 | 2129 | $e->getFile(), |
2130 | 2130 | $e->getLine() |
@@ -2145,9 +2145,9 @@ discard block |
||
2145 | 2145 | * @return string |
2146 | 2146 | * @throws \EE_Error |
2147 | 2147 | */ |
2148 | - protected function _get_return_url( EE_Payment_Method $payment_method ) { |
|
2148 | + protected function _get_return_url(EE_Payment_Method $payment_method) { |
|
2149 | 2149 | $return_url = ''; |
2150 | - switch ( $payment_method->type_obj()->payment_occurs() ) { |
|
2150 | + switch ($payment_method->type_obj()->payment_occurs()) { |
|
2151 | 2151 | case EE_PMT_Base::offsite : |
2152 | 2152 | $return_url = add_query_arg( |
2153 | 2153 | array( |
@@ -2176,12 +2176,12 @@ discard block |
||
2176 | 2176 | * @return EE_Payment | FALSE |
2177 | 2177 | * @throws \EE_Error |
2178 | 2178 | */ |
2179 | - private function _validate_payment( $payment = null ) { |
|
2180 | - if ( $this->checkout->payment_method->is_off_line() ) { |
|
2179 | + private function _validate_payment($payment = null) { |
|
2180 | + if ($this->checkout->payment_method->is_off_line()) { |
|
2181 | 2181 | return true; |
2182 | 2182 | } |
2183 | 2183 | // verify payment object |
2184 | - if ( ! $payment instanceof EE_Payment ) { |
|
2184 | + if ( ! $payment instanceof EE_Payment) { |
|
2185 | 2185 | // not a payment |
2186 | 2186 | EE_Error::add_error( |
2187 | 2187 | sprintf( |
@@ -2190,7 +2190,7 @@ discard block |
||
2190 | 2190 | 'event_espresso' |
2191 | 2191 | ), |
2192 | 2192 | '<br/>', |
2193 | - EE_Registry::instance()->CFG->organization->get_pretty( 'email' ) |
|
2193 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2194 | 2194 | ), |
2195 | 2195 | __FILE__, |
2196 | 2196 | __FUNCTION__, |
@@ -2211,27 +2211,27 @@ discard block |
||
2211 | 2211 | * @return bool |
2212 | 2212 | * @throws \EE_Error |
2213 | 2213 | */ |
2214 | - private function _post_payment_processing( $payment = null ) { |
|
2214 | + private function _post_payment_processing($payment = null) { |
|
2215 | 2215 | // Off-Line payment? |
2216 | - if ( $payment === true ) { |
|
2216 | + if ($payment === true) { |
|
2217 | 2217 | //$this->_setup_redirect_for_next_step(); |
2218 | 2218 | return true; |
2219 | 2219 | // On-Site payment? |
2220 | - } else if ( $this->checkout->payment_method->is_on_site() ) { |
|
2221 | - if ( ! $this->_process_payment_status( $payment, EE_PMT_Base::onsite ) ) { |
|
2220 | + } else if ($this->checkout->payment_method->is_on_site()) { |
|
2221 | + if ( ! $this->_process_payment_status($payment, EE_PMT_Base::onsite)) { |
|
2222 | 2222 | //$this->_setup_redirect_for_next_step(); |
2223 | 2223 | $this->checkout->continue_reg = false; |
2224 | 2224 | } |
2225 | 2225 | // Off-Site payment? |
2226 | - } else if ( $this->checkout->payment_method->is_off_site() ) { |
|
2226 | + } else if ($this->checkout->payment_method->is_off_site()) { |
|
2227 | 2227 | // if a payment object was made and it specifies a redirect url, then we'll setup that redirect info |
2228 | - if ( $payment instanceof EE_Payment && $payment->redirect_url() ) { |
|
2229 | - do_action( 'AHEE_log', __CLASS__, __FUNCTION__, $payment->redirect_url(), '$payment->redirect_url()' ); |
|
2228 | + if ($payment instanceof EE_Payment && $payment->redirect_url()) { |
|
2229 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->redirect_url(), '$payment->redirect_url()'); |
|
2230 | 2230 | $this->checkout->redirect = true; |
2231 | 2231 | $this->checkout->redirect_form = $payment->redirect_form(); |
2232 | - $this->checkout->redirect_url = $this->reg_step_url( 'redirect_form' ); |
|
2232 | + $this->checkout->redirect_url = $this->reg_step_url('redirect_form'); |
|
2233 | 2233 | // set JSON response |
2234 | - $this->checkout->json_response->set_redirect_form( $this->checkout->redirect_form ); |
|
2234 | + $this->checkout->json_response->set_redirect_form($this->checkout->redirect_form); |
|
2235 | 2235 | // set cron job for finalizing the TXN |
2236 | 2236 | // in case the user does not return from the off-site gateway |
2237 | 2237 | EE_Cron_Tasks::schedule_finalize_abandoned_transactions_check( |
@@ -2239,7 +2239,7 @@ discard block |
||
2239 | 2239 | $this->checkout->transaction->ID() |
2240 | 2240 | ); |
2241 | 2241 | // and lastly, let's bump the payment status to pending |
2242 | - $payment->set_status( EEM_Payment::status_id_pending ); |
|
2242 | + $payment->set_status(EEM_Payment::status_id_pending); |
|
2243 | 2243 | $payment->save(); |
2244 | 2244 | } else { |
2245 | 2245 | // not a payment |
@@ -2251,7 +2251,7 @@ discard block |
||
2251 | 2251 | 'event_espresso' |
2252 | 2252 | ), |
2253 | 2253 | '<br/>', |
2254 | - EE_Registry::instance()->CFG->organization->get_pretty( 'email' ) |
|
2254 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2255 | 2255 | ), |
2256 | 2256 | __FILE__, |
2257 | 2257 | __FUNCTION__, |
@@ -2289,21 +2289,21 @@ discard block |
||
2289 | 2289 | * @return bool |
2290 | 2290 | * @throws \EE_Error |
2291 | 2291 | */ |
2292 | - private function _process_payment_status( $payment, $payment_occurs = EE_PMT_Base::offline ) { |
|
2292 | + private function _process_payment_status($payment, $payment_occurs = EE_PMT_Base::offline) { |
|
2293 | 2293 | // off-line payment? carry on |
2294 | - if ( $payment_occurs === EE_PMT_Base::offline ) { |
|
2294 | + if ($payment_occurs === EE_PMT_Base::offline) { |
|
2295 | 2295 | return true; |
2296 | 2296 | } |
2297 | 2297 | // verify payment validity |
2298 | - if ( $payment instanceof EE_Payment ) { |
|
2299 | - do_action( 'AHEE_log', __CLASS__, __FUNCTION__, $payment->status(), '$payment->status()' ); |
|
2298 | + if ($payment instanceof EE_Payment) { |
|
2299 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $payment->status(), '$payment->status()'); |
|
2300 | 2300 | $msg = $payment->gateway_response(); |
2301 | 2301 | // check results |
2302 | - switch ( $payment->status() ) { |
|
2302 | + switch ($payment->status()) { |
|
2303 | 2303 | // good payment |
2304 | 2304 | case EEM_Payment::status_id_approved : |
2305 | 2305 | EE_Error::add_success( |
2306 | - __( 'Your payment was processed successfully.', 'event_espresso' ), |
|
2306 | + __('Your payment was processed successfully.', 'event_espresso'), |
|
2307 | 2307 | __FILE__, |
2308 | 2308 | __FUNCTION__, |
2309 | 2309 | __LINE__ |
@@ -2312,45 +2312,45 @@ discard block |
||
2312 | 2312 | break; |
2313 | 2313 | // slow payment |
2314 | 2314 | case EEM_Payment::status_id_pending : |
2315 | - if ( empty( $msg ) ) { |
|
2315 | + if (empty($msg)) { |
|
2316 | 2316 | $msg = __( |
2317 | 2317 | 'Your payment appears to have been processed successfully, but the Instant Payment Notification has not yet been received. It should arrive shortly.', |
2318 | 2318 | 'event_espresso' |
2319 | 2319 | ); |
2320 | 2320 | } |
2321 | - EE_Error::add_success( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
2321 | + EE_Error::add_success($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2322 | 2322 | return true; |
2323 | 2323 | break; |
2324 | 2324 | // don't wanna payment |
2325 | 2325 | case EEM_Payment::status_id_cancelled : |
2326 | - if ( empty( $msg ) ) { |
|
2326 | + if (empty($msg)) { |
|
2327 | 2327 | $msg = _n( |
2328 | 2328 | 'Payment cancelled. Please try again.', |
2329 | 2329 | 'Payment cancelled. Please try again or select another method of payment.', |
2330 | - count( $this->checkout->available_payment_methods ), |
|
2330 | + count($this->checkout->available_payment_methods), |
|
2331 | 2331 | 'event_espresso' |
2332 | 2332 | ); |
2333 | 2333 | } |
2334 | - EE_Error::add_attention( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
2334 | + EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2335 | 2335 | return false; |
2336 | 2336 | break; |
2337 | 2337 | // not enough payment |
2338 | 2338 | case EEM_Payment::status_id_declined : |
2339 | - if ( empty( $msg ) ) { |
|
2339 | + if (empty($msg)) { |
|
2340 | 2340 | $msg = _n( |
2341 | 2341 | 'We\'re sorry but your payment was declined. Please try again.', |
2342 | 2342 | 'We\'re sorry but your payment was declined. Please try again or select another method of payment.', |
2343 | - count( $this->checkout->available_payment_methods ), |
|
2343 | + count($this->checkout->available_payment_methods), |
|
2344 | 2344 | 'event_espresso' |
2345 | 2345 | ); |
2346 | 2346 | } |
2347 | - EE_Error::add_attention( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
2347 | + EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2348 | 2348 | return false; |
2349 | 2349 | break; |
2350 | 2350 | // bad payment |
2351 | 2351 | case EEM_Payment::status_id_failed : |
2352 | - if ( ! empty( $msg ) ) { |
|
2353 | - EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
2352 | + if ( ! empty($msg)) { |
|
2353 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2354 | 2354 | return false; |
2355 | 2355 | } |
2356 | 2356 | // default to error below |
@@ -2359,7 +2359,7 @@ discard block |
||
2359 | 2359 | } |
2360 | 2360 | // off-site payment gateway responses are too unreliable, so let's just assume that |
2361 | 2361 | // the payment processing is just running slower than the registrant's request |
2362 | - if ( $payment_occurs === EE_PMT_Base::offsite ) { |
|
2362 | + if ($payment_occurs === EE_PMT_Base::offsite) { |
|
2363 | 2363 | return true; |
2364 | 2364 | } |
2365 | 2365 | EE_Error::add_error( |
@@ -2369,7 +2369,7 @@ discard block |
||
2369 | 2369 | 'event_espresso' |
2370 | 2370 | ), |
2371 | 2371 | '<br/>', |
2372 | - EE_Registry::instance()->CFG->organization->get_pretty( 'email' ) |
|
2372 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2373 | 2373 | ), |
2374 | 2374 | __FILE__, |
2375 | 2375 | __FUNCTION__, |
@@ -2402,13 +2402,13 @@ discard block |
||
2402 | 2402 | public function process_gateway_response() { |
2403 | 2403 | $payment = null; |
2404 | 2404 | // how have they chosen to pay? |
2405 | - $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment( true ); |
|
2405 | + $this->checkout->selected_method_of_payment = $this->_get_selected_method_of_payment(true); |
|
2406 | 2406 | // get EE_Payment_Method object |
2407 | - if ( ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment() ) { |
|
2407 | + if ( ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment()) { |
|
2408 | 2408 | $this->checkout->continue_reg = false; |
2409 | 2409 | return false; |
2410 | 2410 | } |
2411 | - if ( ! $this->checkout->payment_method->is_off_site() ) { |
|
2411 | + if ( ! $this->checkout->payment_method->is_off_site()) { |
|
2412 | 2412 | return false; |
2413 | 2413 | } |
2414 | 2414 | $this->_validate_offsite_return(); |
@@ -2422,23 +2422,23 @@ discard block |
||
2422 | 2422 | // true |
2423 | 2423 | //); |
2424 | 2424 | // verify TXN |
2425 | - if ( $this->checkout->transaction instanceof EE_Transaction ) { |
|
2425 | + if ($this->checkout->transaction instanceof EE_Transaction) { |
|
2426 | 2426 | $gateway = $this->checkout->payment_method->type_obj()->get_gateway(); |
2427 | - if ( ! $gateway instanceof EE_Offsite_Gateway ) { |
|
2427 | + if ( ! $gateway instanceof EE_Offsite_Gateway) { |
|
2428 | 2428 | $this->checkout->continue_reg = false; |
2429 | 2429 | return false; |
2430 | 2430 | } |
2431 | - $payment = $this->_process_off_site_payment( $gateway ); |
|
2432 | - $payment = $this->_process_cancelled_payments( $payment ); |
|
2433 | - $payment = $this->_validate_payment( $payment ); |
|
2431 | + $payment = $this->_process_off_site_payment($gateway); |
|
2432 | + $payment = $this->_process_cancelled_payments($payment); |
|
2433 | + $payment = $this->_validate_payment($payment); |
|
2434 | 2434 | // if payment was not declined by the payment gateway or cancelled by the registrant |
2435 | - if ( $this->_process_payment_status( $payment, EE_PMT_Base::offsite ) ) { |
|
2435 | + if ($this->_process_payment_status($payment, EE_PMT_Base::offsite)) { |
|
2436 | 2436 | //$this->_setup_redirect_for_next_step(); |
2437 | 2437 | // store that for later |
2438 | 2438 | $this->checkout->payment = $payment; |
2439 | 2439 | // mark this reg step as completed, as long as gateway doesn't use a separate IPN request, |
2440 | 2440 | // because we will complete this step during the IPN processing then |
2441 | - if ( $gateway instanceof EE_Offsite_Gateway && ! $this->handle_IPN_in_this_request() ) { |
|
2441 | + if ($gateway instanceof EE_Offsite_Gateway && ! $this->handle_IPN_in_this_request()) { |
|
2442 | 2442 | $this->set_completed(); |
2443 | 2443 | } |
2444 | 2444 | return true; |
@@ -2462,21 +2462,21 @@ discard block |
||
2462 | 2462 | * @throws \EE_Error |
2463 | 2463 | */ |
2464 | 2464 | private function _validate_offsite_return() { |
2465 | - $TXN_ID = (int)EE_Registry::instance()->REQ->get( 'spco_txn', 0 ); |
|
2466 | - if ( $TXN_ID !== $this->checkout->transaction->ID() ) { |
|
2465 | + $TXN_ID = (int) EE_Registry::instance()->REQ->get('spco_txn', 0); |
|
2466 | + if ($TXN_ID !== $this->checkout->transaction->ID()) { |
|
2467 | 2467 | // Houston... we might have a problem |
2468 | 2468 | $invalid_TXN = false; |
2469 | 2469 | // first gather some info |
2470 | - $valid_TXN = EEM_Transaction::instance()->get_one_by_ID( $TXN_ID ); |
|
2470 | + $valid_TXN = EEM_Transaction::instance()->get_one_by_ID($TXN_ID); |
|
2471 | 2471 | $primary_registrant = $valid_TXN instanceof EE_Transaction |
2472 | 2472 | ? $valid_TXN->primary_registration() |
2473 | 2473 | : null; |
2474 | 2474 | // let's start by retrieving the cart for this TXN |
2475 | - $cart = $this->checkout->get_cart_for_transaction( $this->checkout->transaction ); |
|
2476 | - if ( $cart instanceof EE_Cart ) { |
|
2475 | + $cart = $this->checkout->get_cart_for_transaction($this->checkout->transaction); |
|
2476 | + if ($cart instanceof EE_Cart) { |
|
2477 | 2477 | // verify that the current cart has tickets |
2478 | 2478 | $tickets = $cart->get_tickets(); |
2479 | - if ( empty( $tickets ) ) { |
|
2479 | + if (empty($tickets)) { |
|
2480 | 2480 | $invalid_TXN = true; |
2481 | 2481 | } |
2482 | 2482 | } else { |
@@ -2486,35 +2486,35 @@ discard block |
||
2486 | 2486 | ? $primary_registrant->session_ID() |
2487 | 2487 | : null; |
2488 | 2488 | // validate current Session ID and compare against valid TXN session ID |
2489 | - if ( EE_Session::instance()->id() === null ) { |
|
2489 | + if (EE_Session::instance()->id() === null) { |
|
2490 | 2490 | $invalid_TXN = true; |
2491 | - } else if ( EE_Session::instance()->id() === $valid_TXN_SID ) { |
|
2491 | + } else if (EE_Session::instance()->id() === $valid_TXN_SID) { |
|
2492 | 2492 | // WARNING !!! |
2493 | 2493 | // this could be PayPal sending back duplicate requests (ya they do that) |
2494 | 2494 | // or it **could** mean someone is simply registering AGAIN after having just done so |
2495 | 2495 | // so now we need to determine if this current TXN looks valid or not |
2496 | 2496 | // has this step even been started ? |
2497 | - if ( $this->checkout->transaction->reg_step_completed( $this->slug() === false ) |
|
2497 | + if ($this->checkout->transaction->reg_step_completed($this->slug() === false) |
|
2498 | 2498 | ) { |
2499 | 2499 | // really? you're half way through this reg step, but you never started it ? |
2500 | 2500 | $invalid_TXN = true; |
2501 | 2501 | } |
2502 | 2502 | } |
2503 | - if ( $invalid_TXN ) { |
|
2503 | + if ($invalid_TXN) { |
|
2504 | 2504 | // is the valid TXN completed ? |
2505 | - if ( $valid_TXN instanceof EE_Transaction ) { |
|
2505 | + if ($valid_TXN instanceof EE_Transaction) { |
|
2506 | 2506 | // has this step even been started ? |
2507 | - $reg_step_completed = $valid_TXN->reg_step_completed( $this->slug() ); |
|
2508 | - if ( $reg_step_completed !== false && $reg_step_completed !== true ) { |
|
2507 | + $reg_step_completed = $valid_TXN->reg_step_completed($this->slug()); |
|
2508 | + if ($reg_step_completed !== false && $reg_step_completed !== true) { |
|
2509 | 2509 | // so it **looks** like this is a double request from PayPal |
2510 | 2510 | // so let's try to pick up where we left off |
2511 | 2511 | $this->checkout->transaction = $valid_TXN; |
2512 | - $this->checkout->refresh_all_entities( true ); |
|
2512 | + $this->checkout->refresh_all_entities(true); |
|
2513 | 2513 | return; |
2514 | 2514 | } |
2515 | 2515 | } |
2516 | 2516 | // you appear to be lost? |
2517 | - $this->_redirect_wayward_request( $primary_registrant ); |
|
2517 | + $this->_redirect_wayward_request($primary_registrant); |
|
2518 | 2518 | } |
2519 | 2519 | } |
2520 | 2520 | } |
@@ -2529,14 +2529,14 @@ discard block |
||
2529 | 2529 | * @return bool |
2530 | 2530 | * @throws \EE_Error |
2531 | 2531 | */ |
2532 | - private function _redirect_wayward_request( EE_Registration $primary_registrant ) { |
|
2533 | - if ( ! $primary_registrant instanceof EE_Registration ) { |
|
2532 | + private function _redirect_wayward_request(EE_Registration $primary_registrant) { |
|
2533 | + if ( ! $primary_registrant instanceof EE_Registration) { |
|
2534 | 2534 | // try redirecting based on the current TXN |
2535 | 2535 | $primary_registrant = $this->checkout->transaction instanceof EE_Transaction |
2536 | 2536 | ? $this->checkout->transaction->primary_registration() |
2537 | 2537 | : null; |
2538 | 2538 | } |
2539 | - if ( ! $primary_registrant instanceof EE_Registration ) { |
|
2539 | + if ( ! $primary_registrant instanceof EE_Registration) { |
|
2540 | 2540 | EE_Error::add_error( |
2541 | 2541 | sprintf( |
2542 | 2542 | __( |
@@ -2544,7 +2544,7 @@ discard block |
||
2544 | 2544 | 'event_espresso' |
2545 | 2545 | ), |
2546 | 2546 | '<br/>', |
2547 | - EE_Registry::instance()->CFG->organization->get_pretty( 'email' ) |
|
2547 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
2548 | 2548 | ), |
2549 | 2549 | __FILE__, |
2550 | 2550 | __FUNCTION__, |
@@ -2575,17 +2575,17 @@ discard block |
||
2575 | 2575 | * @return \EE_Payment |
2576 | 2576 | * @throws \EE_Error |
2577 | 2577 | */ |
2578 | - private function _process_off_site_payment( EE_Offsite_Gateway $gateway ) { |
|
2578 | + private function _process_off_site_payment(EE_Offsite_Gateway $gateway) { |
|
2579 | 2579 | try { |
2580 | 2580 | $request_data = \EE_Registry::instance()->REQ->params(); |
2581 | 2581 | // if gateway uses_separate_IPN_request, then we don't have to process the IPN manually |
2582 | 2582 | $this->set_handle_IPN_in_this_request( |
2583 | - $gateway->handle_IPN_in_this_request( $request_data, false ) |
|
2583 | + $gateway->handle_IPN_in_this_request($request_data, false) |
|
2584 | 2584 | ); |
2585 | - if ( $this->handle_IPN_in_this_request() ) { |
|
2585 | + if ($this->handle_IPN_in_this_request()) { |
|
2586 | 2586 | // get payment details and process results |
2587 | 2587 | /** @type EE_Payment_Processor $payment_processor */ |
2588 | - $payment_processor = EE_Registry::instance()->load_core( 'Payment_Processor' ); |
|
2588 | + $payment_processor = EE_Registry::instance()->load_core('Payment_Processor'); |
|
2589 | 2589 | $payment = $payment_processor->process_ipn( |
2590 | 2590 | $request_data, |
2591 | 2591 | $this->checkout->transaction, |
@@ -2598,14 +2598,14 @@ discard block |
||
2598 | 2598 | $payment = $this->checkout->transaction->last_payment(); |
2599 | 2599 | //$payment_source = 'last_payment'; |
2600 | 2600 | } |
2601 | - } catch ( Exception $e ) { |
|
2601 | + } catch (Exception $e) { |
|
2602 | 2602 | // let's just eat the exception and try to move on using any previously set payment info |
2603 | 2603 | $payment = $this->checkout->transaction->last_payment(); |
2604 | 2604 | //$payment_source = 'last_payment after Exception'; |
2605 | 2605 | // but if we STILL don't have a payment object |
2606 | - if ( ! $payment instanceof EE_Payment ) { |
|
2606 | + if ( ! $payment instanceof EE_Payment) { |
|
2607 | 2607 | // then we'll object ! ( not object like a thing... but object like what a lawyer says ! ) |
2608 | - $this->_handle_payment_processor_exception( $e ); |
|
2608 | + $this->_handle_payment_processor_exception($e); |
|
2609 | 2609 | } |
2610 | 2610 | } |
2611 | 2611 | // DEBUG LOG |
@@ -2630,13 +2630,13 @@ discard block |
||
2630 | 2630 | * @return EE_Payment | FALSE |
2631 | 2631 | * @throws \EE_Error |
2632 | 2632 | */ |
2633 | - private function _process_cancelled_payments( $payment = null ) { |
|
2633 | + private function _process_cancelled_payments($payment = null) { |
|
2634 | 2634 | if ( |
2635 | 2635 | $payment instanceof EE_Payment |
2636 | - && isset( $_REQUEST['ee_cancel_payment'] ) |
|
2636 | + && isset($_REQUEST['ee_cancel_payment']) |
|
2637 | 2637 | && $payment->status() === EEM_Payment::status_id_failed |
2638 | 2638 | ) { |
2639 | - $payment->set_status( EEM_Payment::status_id_cancelled ); |
|
2639 | + $payment->set_status(EEM_Payment::status_id_cancelled); |
|
2640 | 2640 | } |
2641 | 2641 | return $payment; |
2642 | 2642 | } |
@@ -2653,14 +2653,14 @@ discard block |
||
2653 | 2653 | public function get_transaction_details_for_gateways() { |
2654 | 2654 | $txn_details = array(); |
2655 | 2655 | // ya gotta make a choice man |
2656 | - if ( empty( $this->checkout->selected_method_of_payment ) ) { |
|
2656 | + if (empty($this->checkout->selected_method_of_payment)) { |
|
2657 | 2657 | $txn_details = array( |
2658 | - 'error' => __( 'Please select a method of payment before proceeding.', 'event_espresso' ) |
|
2658 | + 'error' => __('Please select a method of payment before proceeding.', 'event_espresso') |
|
2659 | 2659 | ); |
2660 | 2660 | } |
2661 | 2661 | // get EE_Payment_Method object |
2662 | 2662 | if ( |
2663 | - empty( $txn_details ) |
|
2663 | + empty($txn_details) |
|
2664 | 2664 | && |
2665 | 2665 | ! $this->checkout->payment_method = $this->_get_payment_method_for_selected_method_of_payment() |
2666 | 2666 | ) { |
@@ -2672,8 +2672,8 @@ discard block |
||
2672 | 2672 | ) |
2673 | 2673 | ); |
2674 | 2674 | } |
2675 | - if ( empty( $txn_details ) && $this->checkout->transaction instanceof EE_Transaction ) { |
|
2676 | - $return_url = $this->_get_return_url( $this->checkout->payment_method ); |
|
2675 | + if (empty($txn_details) && $this->checkout->transaction instanceof EE_Transaction) { |
|
2676 | + $return_url = $this->_get_return_url($this->checkout->payment_method); |
|
2677 | 2677 | $txn_details = array( |
2678 | 2678 | 'TXN_ID' => $this->checkout->transaction->ID(), |
2679 | 2679 | 'TXN_timestamp' => $this->checkout->transaction->datetime(), |
@@ -2684,7 +2684,7 @@ discard block |
||
2684 | 2684 | 'PMD_ID' => $this->checkout->transaction->payment_method_ID(), |
2685 | 2685 | 'payment_amount' => $this->checkout->amount_owing, |
2686 | 2686 | 'return_url' => $return_url, |
2687 | - 'cancel_url' => add_query_arg( array( 'ee_cancel_payment' => true ), $return_url ), |
|
2687 | + 'cancel_url' => add_query_arg(array('ee_cancel_payment' => true), $return_url), |
|
2688 | 2688 | 'notify_url' => EE_Config::instance()->core->txn_page_url( |
2689 | 2689 | array( |
2690 | 2690 | 'e_reg_url_link' => $this->checkout->transaction->primary_registration()->reg_url_link(), |
@@ -2693,7 +2693,7 @@ discard block |
||
2693 | 2693 | ) |
2694 | 2694 | ); |
2695 | 2695 | } |
2696 | - echo wp_json_encode( $txn_details ); |
|
2696 | + echo wp_json_encode($txn_details); |
|
2697 | 2697 | exit(); |
2698 | 2698 | } |
2699 | 2699 | |
@@ -2710,7 +2710,7 @@ discard block |
||
2710 | 2710 | public function __sleep() |
2711 | 2711 | { |
2712 | 2712 | // remove the reg form and the checkout |
2713 | - return array_diff( array_keys( get_object_vars( $this ) ), array( 'reg_form', 'checkout', 'line_item_display' ) ); |
|
2713 | + return array_diff(array_keys(get_object_vars($this)), array('reg_form', 'checkout', 'line_item_display')); |
|
2714 | 2714 | } |
2715 | 2715 | |
2716 | 2716 |
@@ -32,7 +32,6 @@ |
||
32 | 32 | * Removes the checkin and checkout endpoints from the index for requests |
33 | 33 | * to api versions lowers than 4.8.33 |
34 | 34 | * |
35 | - * @param array $routes_on_this_version |
|
36 | 35 | * @param EventEspresso\core\libraries\rest_api\controllers\Base $controller |
37 | 36 | * @return array like $routes_on_this_version |
38 | 37 | */ |
@@ -12,39 +12,39 @@ |
||
12 | 12 | class Changes_In_4_8_34 extends Changes_In_Base |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * Adds hooks so requests to 4.8.29 don't have the checkin endpoints |
|
17 | - */ |
|
18 | - public function set_hooks() |
|
19 | - { |
|
20 | - //set a hook to remove the checkout/checkout endpoints if the request |
|
21 | - //is for lower than 4.8.33 |
|
22 | - add_filter( |
|
23 | - 'FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_response_headers', |
|
24 | - array($this, 'remove_response_headers'), |
|
25 | - 10, |
|
26 | - 3 |
|
27 | - ); |
|
28 | - } |
|
29 | - |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * Removes the checkin and checkout endpoints from the index for requests |
|
34 | - * to api versions lowers than 4.8.33 |
|
35 | - * |
|
36 | - * @param array $routes_on_this_version |
|
37 | - * @param EventEspresso\core\libraries\rest_api\controllers\Base $controller |
|
38 | - * @return array like $routes_on_this_version |
|
39 | - */ |
|
40 | - public function remove_response_headers($response_headers, $controller, $requested_version) |
|
41 | - { |
|
42 | - if ($controller instanceof Base |
|
43 | - && $this->applies_to_version($requested_version) |
|
44 | - ) { |
|
45 | - return array(); |
|
46 | - } |
|
47 | - return $response_headers; |
|
48 | - } |
|
15 | + /** |
|
16 | + * Adds hooks so requests to 4.8.29 don't have the checkin endpoints |
|
17 | + */ |
|
18 | + public function set_hooks() |
|
19 | + { |
|
20 | + //set a hook to remove the checkout/checkout endpoints if the request |
|
21 | + //is for lower than 4.8.33 |
|
22 | + add_filter( |
|
23 | + 'FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_response_headers', |
|
24 | + array($this, 'remove_response_headers'), |
|
25 | + 10, |
|
26 | + 3 |
|
27 | + ); |
|
28 | + } |
|
29 | + |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * Removes the checkin and checkout endpoints from the index for requests |
|
34 | + * to api versions lowers than 4.8.33 |
|
35 | + * |
|
36 | + * @param array $routes_on_this_version |
|
37 | + * @param EventEspresso\core\libraries\rest_api\controllers\Base $controller |
|
38 | + * @return array like $routes_on_this_version |
|
39 | + */ |
|
40 | + public function remove_response_headers($response_headers, $controller, $requested_version) |
|
41 | + { |
|
42 | + if ($controller instanceof Base |
|
43 | + && $this->applies_to_version($requested_version) |
|
44 | + ) { |
|
45 | + return array(); |
|
46 | + } |
|
47 | + return $response_headers; |
|
48 | + } |
|
49 | 49 | } |
50 | 50 |
@@ -314,7 +314,7 @@ |
||
314 | 314 | * |
315 | 315 | * @param string $route |
316 | 316 | * @param string $regex |
317 | - * @param array $match_keys EXCLUDING matching the entire regex |
|
317 | + * @param string[] $match_keys EXCLUDING matching the entire regex |
|
318 | 318 | * @return array where $match_keys are the keys (the first value of $match_keys |
319 | 319 | * becomes the first key of the return value, etc. Eg passing in $match_keys of |
320 | 320 | * array( 'model', 'id' ), will, if the regex is successful, will return |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | use EventEspresso\core\libraries\rest_api\Rest_Exception; |
5 | 5 | |
6 | 6 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
7 | - exit('No direct script access allowed'); |
|
7 | + exit('No direct script access allowed'); |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | |
@@ -20,309 +20,309 @@ discard block |
||
20 | 20 | class Base |
21 | 21 | { |
22 | 22 | |
23 | - const header_prefix_for_ee = 'X-EE-'; |
|
24 | - |
|
25 | - const header_prefix_for_wp = 'X-WP-'; |
|
26 | - |
|
27 | - /** |
|
28 | - * Contains debug info we'll send back in the response headers |
|
29 | - * |
|
30 | - * @var array |
|
31 | - */ |
|
32 | - protected $_debug_info = array(); |
|
33 | - |
|
34 | - /** |
|
35 | - * Indicates whether or not the API is in debug mode |
|
36 | - * |
|
37 | - * @var boolean |
|
38 | - */ |
|
39 | - protected $_debug_mode = false; |
|
40 | - |
|
41 | - /** |
|
42 | - * Indicates the version that was requested |
|
43 | - * |
|
44 | - * @var string |
|
45 | - */ |
|
46 | - protected $_requested_version; |
|
47 | - |
|
48 | - /** |
|
49 | - * flat array of headers to send in the response |
|
50 | - * |
|
51 | - * @var array |
|
52 | - */ |
|
53 | - protected $_response_headers = array(); |
|
54 | - |
|
55 | - |
|
56 | - |
|
57 | - public function __construct() |
|
58 | - { |
|
59 | - $this->_debug_mode = defined('EE_REST_API_DEBUG_MODE') ? EE_REST_API_DEBUG_MODE : false; |
|
60 | - } |
|
61 | - |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * Sets the version the user requested |
|
66 | - * |
|
67 | - * @param string $version eg '4.8' |
|
68 | - */ |
|
69 | - public function set_requested_version($version) |
|
70 | - { |
|
71 | - $this->_requested_version = $version; |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * Sets some debug info that we'll send back in headers |
|
78 | - * |
|
79 | - * @param string $key |
|
80 | - * @param string|array $info |
|
81 | - */ |
|
82 | - protected function _set_debug_info($key, $info) |
|
83 | - { |
|
84 | - $this->_debug_info[$key] = $info; |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * Sets headers for the response |
|
91 | - * |
|
92 | - * @param string $header_key , excluding the "X-EE-" part |
|
93 | - * @param array|string $value if an array, multiple headers will be added, one |
|
94 | - * for each key in the array |
|
95 | - * @param boolean $use_ee_prefix whether to use the EE prefix on the header, or fallback to |
|
96 | - * the standard WP one |
|
97 | - */ |
|
98 | - protected function _set_response_header($header_key, $value, $use_ee_prefix = true) |
|
99 | - { |
|
100 | - if (is_array($value)) { |
|
101 | - foreach ($value as $value_key => $value_value) { |
|
102 | - $this->_set_response_header($header_key . '[' . $value_key . ']', $value_value); |
|
103 | - } |
|
104 | - } else { |
|
105 | - $prefix = $use_ee_prefix ? Base::header_prefix_for_ee : Base::header_prefix_for_wp; |
|
106 | - $this->_response_headers[$prefix . $header_key] = $value; |
|
107 | - } |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * Returns a flat array of headers to be added to the response |
|
114 | - * |
|
115 | - * @return array |
|
116 | - */ |
|
117 | - protected function _get_response_headers() |
|
118 | - { |
|
119 | - return apply_filters('FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_response_headers', |
|
120 | - $this->_response_headers, |
|
121 | - $this, |
|
122 | - $this->_requested_version |
|
123 | - ); |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - |
|
128 | - /** |
|
129 | - * Adds error notices from EE_Error onto the provided \WP_Error |
|
130 | - * |
|
131 | - * @param \WP_Error $wp_error_response |
|
132 | - * @return \WP_Error |
|
133 | - */ |
|
134 | - protected function _add_ee_errors_to_response(\WP_Error $wp_error_response) |
|
135 | - { |
|
136 | - $notices_during_checkin = \EE_Error::get_raw_notices(); |
|
137 | - if (! empty($notices_during_checkin['errors'])) { |
|
138 | - foreach ($notices_during_checkin['errors'] as $error_code => $error_message) { |
|
139 | - $wp_error_response->add( |
|
140 | - sanitize_key($error_code), |
|
141 | - strip_tags($error_message)); |
|
142 | - } |
|
143 | - } |
|
144 | - return $wp_error_response; |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - |
|
149 | - /** |
|
150 | - * Sends a response, but also makes sure to attach headers that |
|
151 | - * are handy for debugging. |
|
152 | - * Specifically, we assume folks will want to know what exactly was the DB query that got run, |
|
153 | - * what exactly was the Models query that got run, what capabilities came into play, what fields were omitted from |
|
154 | - * the response, others? |
|
155 | - * |
|
156 | - * @param array|\WP_Error|\Exception $response |
|
157 | - * @return \WP_REST_Response |
|
158 | - */ |
|
159 | - public function send_response($response) |
|
160 | - { |
|
161 | - if ($response instanceof Rest_Exception) { |
|
162 | - $response = new \WP_Error($response->get_string_code(), $response->getMessage(), $response->get_data()); |
|
163 | - } |
|
164 | - if ($response instanceof \Exception) { |
|
165 | - $code = $response->getCode() ? $response->getCode() : 'error_occurred'; |
|
166 | - $response = new \WP_Error($code, $response->getMessage()); |
|
167 | - } |
|
168 | - if ($response instanceof \WP_Error) { |
|
169 | - $response = $this->_add_ee_errors_to_response($response); |
|
170 | - $rest_response = $this->_create_rest_response_from_wp_error($response); |
|
171 | - } else { |
|
172 | - $rest_response = new \WP_REST_Response($response, 200); |
|
173 | - } |
|
174 | - $headers = array(); |
|
175 | - if ($this->_debug_mode && is_array($this->_debug_info)) { |
|
176 | - foreach ($this->_debug_info as $debug_key => $debug_info) { |
|
177 | - if (is_array($debug_info)) { |
|
178 | - $debug_info = wp_json_encode($debug_info); |
|
179 | - } |
|
180 | - $headers['X-EE4-Debug-' . ucwords($debug_key)] = $debug_info; |
|
181 | - } |
|
182 | - } |
|
183 | - $headers = array_merge( |
|
184 | - $headers, |
|
185 | - $this->_get_response_headers(), |
|
186 | - $this->_get_headers_from_ee_notices() |
|
187 | - ); |
|
188 | - $rest_response->set_headers($headers); |
|
189 | - return $rest_response; |
|
190 | - } |
|
191 | - |
|
192 | - |
|
193 | - |
|
194 | - /** |
|
195 | - * Converts the \WP_Error into `WP_REST_Response. |
|
196 | - * Mostly this is just a copy-and-paste from \WP_REST_Server::error_to_response |
|
197 | - * (which is protected) |
|
198 | - * |
|
199 | - * @param \WP_Error $wp_error |
|
200 | - * @return \WP_REST_Response |
|
201 | - */ |
|
202 | - protected function _create_rest_response_from_wp_error(\WP_Error $wp_error) |
|
203 | - { |
|
204 | - $error_data = $wp_error->get_error_data(); |
|
205 | - if (is_array($error_data) && isset($error_data['status'])) { |
|
206 | - $status = $error_data['status']; |
|
207 | - } else { |
|
208 | - $status = 500; |
|
209 | - } |
|
210 | - $errors = array(); |
|
211 | - foreach ((array)$wp_error->errors as $code => $messages) { |
|
212 | - foreach ((array)$messages as $message) { |
|
213 | - $errors[] = array( |
|
214 | - 'code' => $code, |
|
215 | - 'message' => $message, |
|
216 | - 'data' => $wp_error->get_error_data($code), |
|
217 | - ); |
|
218 | - } |
|
219 | - } |
|
220 | - $data = isset($errors[0]) ? $errors[0] : array(); |
|
221 | - if (count($errors) > 1) { |
|
222 | - // Remove the primary error. |
|
223 | - array_shift($errors); |
|
224 | - $data['additional_errors'] = $errors; |
|
225 | - } |
|
226 | - return new \WP_REST_Response($data, $status); |
|
227 | - } |
|
228 | - |
|
229 | - |
|
230 | - |
|
231 | - /** |
|
232 | - * Array of headers derived from EE success, attention, and error messages |
|
233 | - * |
|
234 | - * @return array |
|
235 | - */ |
|
236 | - protected function _get_headers_from_ee_notices() |
|
237 | - { |
|
238 | - $headers = array(); |
|
239 | - $notices = \EE_Error::get_raw_notices(); |
|
240 | - foreach ($notices as $notice_type => $sub_notices) { |
|
241 | - if (! is_array($sub_notices)) { |
|
242 | - continue; |
|
243 | - } |
|
244 | - foreach ($sub_notices as $notice_code => $sub_notice) { |
|
245 | - $headers['X-EE4-Notices-' |
|
246 | - . \EEH_Inflector::humanize($notice_type) |
|
247 | - . '[' |
|
248 | - . $notice_code |
|
249 | - . ']'] = strip_tags($sub_notice); |
|
250 | - } |
|
251 | - } |
|
252 | - return apply_filters( |
|
253 | - 'FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_headers_from_ee_notices__return', |
|
254 | - $headers, |
|
255 | - $this->_requested_version, |
|
256 | - $notices |
|
257 | - ); |
|
258 | - } |
|
259 | - |
|
260 | - |
|
261 | - |
|
262 | - /** |
|
263 | - * Finds which version of the API was requested given the route, and returns it. |
|
264 | - * eg in a request to "mysite.com/wp-json/ee/v4.8.29/events/123" this would return |
|
265 | - * "4.8.29" |
|
266 | - * |
|
267 | - * @param string $route |
|
268 | - * @return string |
|
269 | - */ |
|
270 | - public function get_requested_version($route = null) |
|
271 | - { |
|
272 | - $matches = $this->parse_route( |
|
273 | - $route, |
|
274 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '~', |
|
275 | - array('version') |
|
276 | - ); |
|
277 | - if (isset($matches['version'])) { |
|
278 | - return $matches['version']; |
|
279 | - } else { |
|
280 | - return \EED_Core_Rest_Api::latest_rest_api_version(); |
|
281 | - } |
|
282 | - } |
|
283 | - |
|
284 | - |
|
285 | - |
|
286 | - /** |
|
287 | - * Applies the regex to the route, then creates an array using the values of |
|
288 | - * $match_keys as keys (but ignores the full pattern match). Returns the array of matches. |
|
289 | - * For example, if you call |
|
290 | - * parse_route( '/ee/v4.8/events', '~\/ee\/v([^/]*)\/(.*)~', array( 'version', 'model' ) ) |
|
291 | - * it will return array( 'version' => '4.8', 'model' => 'events' ) |
|
292 | - * |
|
293 | - * @param string $route |
|
294 | - * @param string $regex |
|
295 | - * @param array $match_keys EXCLUDING matching the entire regex |
|
296 | - * @return array where $match_keys are the keys (the first value of $match_keys |
|
297 | - * becomes the first key of the return value, etc. Eg passing in $match_keys of |
|
298 | - * array( 'model', 'id' ), will, if the regex is successful, will return |
|
299 | - * array( 'model' => 'foo', 'id' => 'bar' ) |
|
300 | - * @throws \EE_Error if it couldn't be parsed |
|
301 | - */ |
|
302 | - public function parse_route($route, $regex, $match_keys) |
|
303 | - { |
|
304 | - $indexed_matches = array(); |
|
305 | - $success = preg_match($regex, $route, $matches); |
|
306 | - if ( |
|
307 | - is_array($matches) |
|
308 | - ) { |
|
309 | - //skip the overall regex match. Who cares |
|
310 | - for ($i = 1; $i <= count($match_keys); $i++) { |
|
311 | - if (! isset($matches[$i])) { |
|
312 | - $success = false; |
|
313 | - } else { |
|
314 | - $indexed_matches[$match_keys[$i - 1]] = $matches[$i]; |
|
315 | - } |
|
316 | - } |
|
317 | - } |
|
318 | - if (! $success) { |
|
319 | - throw new \EE_Error( |
|
320 | - __('We could not parse the URL. Please contact Event Espresso Support', 'event_espresso'), |
|
321 | - 'endpoint_parsing_error' |
|
322 | - ); |
|
323 | - } |
|
324 | - return $indexed_matches; |
|
325 | - } |
|
23 | + const header_prefix_for_ee = 'X-EE-'; |
|
24 | + |
|
25 | + const header_prefix_for_wp = 'X-WP-'; |
|
26 | + |
|
27 | + /** |
|
28 | + * Contains debug info we'll send back in the response headers |
|
29 | + * |
|
30 | + * @var array |
|
31 | + */ |
|
32 | + protected $_debug_info = array(); |
|
33 | + |
|
34 | + /** |
|
35 | + * Indicates whether or not the API is in debug mode |
|
36 | + * |
|
37 | + * @var boolean |
|
38 | + */ |
|
39 | + protected $_debug_mode = false; |
|
40 | + |
|
41 | + /** |
|
42 | + * Indicates the version that was requested |
|
43 | + * |
|
44 | + * @var string |
|
45 | + */ |
|
46 | + protected $_requested_version; |
|
47 | + |
|
48 | + /** |
|
49 | + * flat array of headers to send in the response |
|
50 | + * |
|
51 | + * @var array |
|
52 | + */ |
|
53 | + protected $_response_headers = array(); |
|
54 | + |
|
55 | + |
|
56 | + |
|
57 | + public function __construct() |
|
58 | + { |
|
59 | + $this->_debug_mode = defined('EE_REST_API_DEBUG_MODE') ? EE_REST_API_DEBUG_MODE : false; |
|
60 | + } |
|
61 | + |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * Sets the version the user requested |
|
66 | + * |
|
67 | + * @param string $version eg '4.8' |
|
68 | + */ |
|
69 | + public function set_requested_version($version) |
|
70 | + { |
|
71 | + $this->_requested_version = $version; |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * Sets some debug info that we'll send back in headers |
|
78 | + * |
|
79 | + * @param string $key |
|
80 | + * @param string|array $info |
|
81 | + */ |
|
82 | + protected function _set_debug_info($key, $info) |
|
83 | + { |
|
84 | + $this->_debug_info[$key] = $info; |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * Sets headers for the response |
|
91 | + * |
|
92 | + * @param string $header_key , excluding the "X-EE-" part |
|
93 | + * @param array|string $value if an array, multiple headers will be added, one |
|
94 | + * for each key in the array |
|
95 | + * @param boolean $use_ee_prefix whether to use the EE prefix on the header, or fallback to |
|
96 | + * the standard WP one |
|
97 | + */ |
|
98 | + protected function _set_response_header($header_key, $value, $use_ee_prefix = true) |
|
99 | + { |
|
100 | + if (is_array($value)) { |
|
101 | + foreach ($value as $value_key => $value_value) { |
|
102 | + $this->_set_response_header($header_key . '[' . $value_key . ']', $value_value); |
|
103 | + } |
|
104 | + } else { |
|
105 | + $prefix = $use_ee_prefix ? Base::header_prefix_for_ee : Base::header_prefix_for_wp; |
|
106 | + $this->_response_headers[$prefix . $header_key] = $value; |
|
107 | + } |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * Returns a flat array of headers to be added to the response |
|
114 | + * |
|
115 | + * @return array |
|
116 | + */ |
|
117 | + protected function _get_response_headers() |
|
118 | + { |
|
119 | + return apply_filters('FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_response_headers', |
|
120 | + $this->_response_headers, |
|
121 | + $this, |
|
122 | + $this->_requested_version |
|
123 | + ); |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + |
|
128 | + /** |
|
129 | + * Adds error notices from EE_Error onto the provided \WP_Error |
|
130 | + * |
|
131 | + * @param \WP_Error $wp_error_response |
|
132 | + * @return \WP_Error |
|
133 | + */ |
|
134 | + protected function _add_ee_errors_to_response(\WP_Error $wp_error_response) |
|
135 | + { |
|
136 | + $notices_during_checkin = \EE_Error::get_raw_notices(); |
|
137 | + if (! empty($notices_during_checkin['errors'])) { |
|
138 | + foreach ($notices_during_checkin['errors'] as $error_code => $error_message) { |
|
139 | + $wp_error_response->add( |
|
140 | + sanitize_key($error_code), |
|
141 | + strip_tags($error_message)); |
|
142 | + } |
|
143 | + } |
|
144 | + return $wp_error_response; |
|
145 | + } |
|
146 | + |
|
147 | + |
|
148 | + |
|
149 | + /** |
|
150 | + * Sends a response, but also makes sure to attach headers that |
|
151 | + * are handy for debugging. |
|
152 | + * Specifically, we assume folks will want to know what exactly was the DB query that got run, |
|
153 | + * what exactly was the Models query that got run, what capabilities came into play, what fields were omitted from |
|
154 | + * the response, others? |
|
155 | + * |
|
156 | + * @param array|\WP_Error|\Exception $response |
|
157 | + * @return \WP_REST_Response |
|
158 | + */ |
|
159 | + public function send_response($response) |
|
160 | + { |
|
161 | + if ($response instanceof Rest_Exception) { |
|
162 | + $response = new \WP_Error($response->get_string_code(), $response->getMessage(), $response->get_data()); |
|
163 | + } |
|
164 | + if ($response instanceof \Exception) { |
|
165 | + $code = $response->getCode() ? $response->getCode() : 'error_occurred'; |
|
166 | + $response = new \WP_Error($code, $response->getMessage()); |
|
167 | + } |
|
168 | + if ($response instanceof \WP_Error) { |
|
169 | + $response = $this->_add_ee_errors_to_response($response); |
|
170 | + $rest_response = $this->_create_rest_response_from_wp_error($response); |
|
171 | + } else { |
|
172 | + $rest_response = new \WP_REST_Response($response, 200); |
|
173 | + } |
|
174 | + $headers = array(); |
|
175 | + if ($this->_debug_mode && is_array($this->_debug_info)) { |
|
176 | + foreach ($this->_debug_info as $debug_key => $debug_info) { |
|
177 | + if (is_array($debug_info)) { |
|
178 | + $debug_info = wp_json_encode($debug_info); |
|
179 | + } |
|
180 | + $headers['X-EE4-Debug-' . ucwords($debug_key)] = $debug_info; |
|
181 | + } |
|
182 | + } |
|
183 | + $headers = array_merge( |
|
184 | + $headers, |
|
185 | + $this->_get_response_headers(), |
|
186 | + $this->_get_headers_from_ee_notices() |
|
187 | + ); |
|
188 | + $rest_response->set_headers($headers); |
|
189 | + return $rest_response; |
|
190 | + } |
|
191 | + |
|
192 | + |
|
193 | + |
|
194 | + /** |
|
195 | + * Converts the \WP_Error into `WP_REST_Response. |
|
196 | + * Mostly this is just a copy-and-paste from \WP_REST_Server::error_to_response |
|
197 | + * (which is protected) |
|
198 | + * |
|
199 | + * @param \WP_Error $wp_error |
|
200 | + * @return \WP_REST_Response |
|
201 | + */ |
|
202 | + protected function _create_rest_response_from_wp_error(\WP_Error $wp_error) |
|
203 | + { |
|
204 | + $error_data = $wp_error->get_error_data(); |
|
205 | + if (is_array($error_data) && isset($error_data['status'])) { |
|
206 | + $status = $error_data['status']; |
|
207 | + } else { |
|
208 | + $status = 500; |
|
209 | + } |
|
210 | + $errors = array(); |
|
211 | + foreach ((array)$wp_error->errors as $code => $messages) { |
|
212 | + foreach ((array)$messages as $message) { |
|
213 | + $errors[] = array( |
|
214 | + 'code' => $code, |
|
215 | + 'message' => $message, |
|
216 | + 'data' => $wp_error->get_error_data($code), |
|
217 | + ); |
|
218 | + } |
|
219 | + } |
|
220 | + $data = isset($errors[0]) ? $errors[0] : array(); |
|
221 | + if (count($errors) > 1) { |
|
222 | + // Remove the primary error. |
|
223 | + array_shift($errors); |
|
224 | + $data['additional_errors'] = $errors; |
|
225 | + } |
|
226 | + return new \WP_REST_Response($data, $status); |
|
227 | + } |
|
228 | + |
|
229 | + |
|
230 | + |
|
231 | + /** |
|
232 | + * Array of headers derived from EE success, attention, and error messages |
|
233 | + * |
|
234 | + * @return array |
|
235 | + */ |
|
236 | + protected function _get_headers_from_ee_notices() |
|
237 | + { |
|
238 | + $headers = array(); |
|
239 | + $notices = \EE_Error::get_raw_notices(); |
|
240 | + foreach ($notices as $notice_type => $sub_notices) { |
|
241 | + if (! is_array($sub_notices)) { |
|
242 | + continue; |
|
243 | + } |
|
244 | + foreach ($sub_notices as $notice_code => $sub_notice) { |
|
245 | + $headers['X-EE4-Notices-' |
|
246 | + . \EEH_Inflector::humanize($notice_type) |
|
247 | + . '[' |
|
248 | + . $notice_code |
|
249 | + . ']'] = strip_tags($sub_notice); |
|
250 | + } |
|
251 | + } |
|
252 | + return apply_filters( |
|
253 | + 'FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_headers_from_ee_notices__return', |
|
254 | + $headers, |
|
255 | + $this->_requested_version, |
|
256 | + $notices |
|
257 | + ); |
|
258 | + } |
|
259 | + |
|
260 | + |
|
261 | + |
|
262 | + /** |
|
263 | + * Finds which version of the API was requested given the route, and returns it. |
|
264 | + * eg in a request to "mysite.com/wp-json/ee/v4.8.29/events/123" this would return |
|
265 | + * "4.8.29" |
|
266 | + * |
|
267 | + * @param string $route |
|
268 | + * @return string |
|
269 | + */ |
|
270 | + public function get_requested_version($route = null) |
|
271 | + { |
|
272 | + $matches = $this->parse_route( |
|
273 | + $route, |
|
274 | + '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '~', |
|
275 | + array('version') |
|
276 | + ); |
|
277 | + if (isset($matches['version'])) { |
|
278 | + return $matches['version']; |
|
279 | + } else { |
|
280 | + return \EED_Core_Rest_Api::latest_rest_api_version(); |
|
281 | + } |
|
282 | + } |
|
283 | + |
|
284 | + |
|
285 | + |
|
286 | + /** |
|
287 | + * Applies the regex to the route, then creates an array using the values of |
|
288 | + * $match_keys as keys (but ignores the full pattern match). Returns the array of matches. |
|
289 | + * For example, if you call |
|
290 | + * parse_route( '/ee/v4.8/events', '~\/ee\/v([^/]*)\/(.*)~', array( 'version', 'model' ) ) |
|
291 | + * it will return array( 'version' => '4.8', 'model' => 'events' ) |
|
292 | + * |
|
293 | + * @param string $route |
|
294 | + * @param string $regex |
|
295 | + * @param array $match_keys EXCLUDING matching the entire regex |
|
296 | + * @return array where $match_keys are the keys (the first value of $match_keys |
|
297 | + * becomes the first key of the return value, etc. Eg passing in $match_keys of |
|
298 | + * array( 'model', 'id' ), will, if the regex is successful, will return |
|
299 | + * array( 'model' => 'foo', 'id' => 'bar' ) |
|
300 | + * @throws \EE_Error if it couldn't be parsed |
|
301 | + */ |
|
302 | + public function parse_route($route, $regex, $match_keys) |
|
303 | + { |
|
304 | + $indexed_matches = array(); |
|
305 | + $success = preg_match($regex, $route, $matches); |
|
306 | + if ( |
|
307 | + is_array($matches) |
|
308 | + ) { |
|
309 | + //skip the overall regex match. Who cares |
|
310 | + for ($i = 1; $i <= count($match_keys); $i++) { |
|
311 | + if (! isset($matches[$i])) { |
|
312 | + $success = false; |
|
313 | + } else { |
|
314 | + $indexed_matches[$match_keys[$i - 1]] = $matches[$i]; |
|
315 | + } |
|
316 | + } |
|
317 | + } |
|
318 | + if (! $success) { |
|
319 | + throw new \EE_Error( |
|
320 | + __('We could not parse the URL. Please contact Event Espresso Support', 'event_espresso'), |
|
321 | + 'endpoint_parsing_error' |
|
322 | + ); |
|
323 | + } |
|
324 | + return $indexed_matches; |
|
325 | + } |
|
326 | 326 | } |
327 | 327 | |
328 | 328 | // End of file Base.php |
329 | 329 | \ No newline at end of file |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | |
4 | 4 | use EventEspresso\core\libraries\rest_api\Rest_Exception; |
5 | 5 | |
6 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
6 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
7 | 7 | exit('No direct script access allowed'); |
8 | 8 | } |
9 | 9 | |
@@ -99,11 +99,11 @@ discard block |
||
99 | 99 | { |
100 | 100 | if (is_array($value)) { |
101 | 101 | foreach ($value as $value_key => $value_value) { |
102 | - $this->_set_response_header($header_key . '[' . $value_key . ']', $value_value); |
|
102 | + $this->_set_response_header($header_key.'['.$value_key.']', $value_value); |
|
103 | 103 | } |
104 | 104 | } else { |
105 | 105 | $prefix = $use_ee_prefix ? Base::header_prefix_for_ee : Base::header_prefix_for_wp; |
106 | - $this->_response_headers[$prefix . $header_key] = $value; |
|
106 | + $this->_response_headers[$prefix.$header_key] = $value; |
|
107 | 107 | } |
108 | 108 | } |
109 | 109 | |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | protected function _add_ee_errors_to_response(\WP_Error $wp_error_response) |
135 | 135 | { |
136 | 136 | $notices_during_checkin = \EE_Error::get_raw_notices(); |
137 | - if (! empty($notices_during_checkin['errors'])) { |
|
137 | + if ( ! empty($notices_during_checkin['errors'])) { |
|
138 | 138 | foreach ($notices_during_checkin['errors'] as $error_code => $error_message) { |
139 | 139 | $wp_error_response->add( |
140 | 140 | sanitize_key($error_code), |
@@ -177,7 +177,7 @@ discard block |
||
177 | 177 | if (is_array($debug_info)) { |
178 | 178 | $debug_info = wp_json_encode($debug_info); |
179 | 179 | } |
180 | - $headers['X-EE4-Debug-' . ucwords($debug_key)] = $debug_info; |
|
180 | + $headers['X-EE4-Debug-'.ucwords($debug_key)] = $debug_info; |
|
181 | 181 | } |
182 | 182 | } |
183 | 183 | $headers = array_merge( |
@@ -208,8 +208,8 @@ discard block |
||
208 | 208 | $status = 500; |
209 | 209 | } |
210 | 210 | $errors = array(); |
211 | - foreach ((array)$wp_error->errors as $code => $messages) { |
|
212 | - foreach ((array)$messages as $message) { |
|
211 | + foreach ((array) $wp_error->errors as $code => $messages) { |
|
212 | + foreach ((array) $messages as $message) { |
|
213 | 213 | $errors[] = array( |
214 | 214 | 'code' => $code, |
215 | 215 | 'message' => $message, |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | $headers = array(); |
239 | 239 | $notices = \EE_Error::get_raw_notices(); |
240 | 240 | foreach ($notices as $notice_type => $sub_notices) { |
241 | - if (! is_array($sub_notices)) { |
|
241 | + if ( ! is_array($sub_notices)) { |
|
242 | 242 | continue; |
243 | 243 | } |
244 | 244 | foreach ($sub_notices as $notice_code => $sub_notice) { |
@@ -271,7 +271,7 @@ discard block |
||
271 | 271 | { |
272 | 272 | $matches = $this->parse_route( |
273 | 273 | $route, |
274 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '~', |
|
274 | + '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'~', |
|
275 | 275 | array('version') |
276 | 276 | ); |
277 | 277 | if (isset($matches['version'])) { |
@@ -308,14 +308,14 @@ discard block |
||
308 | 308 | ) { |
309 | 309 | //skip the overall regex match. Who cares |
310 | 310 | for ($i = 1; $i <= count($match_keys); $i++) { |
311 | - if (! isset($matches[$i])) { |
|
311 | + if ( ! isset($matches[$i])) { |
|
312 | 312 | $success = false; |
313 | 313 | } else { |
314 | 314 | $indexed_matches[$match_keys[$i - 1]] = $matches[$i]; |
315 | 315 | } |
316 | 316 | } |
317 | 317 | } |
318 | - if (! $success) { |
|
318 | + if ( ! $success) { |
|
319 | 319 | throw new \EE_Error( |
320 | 320 | __('We could not parse the URL. Please contact Event Espresso Support', 'event_espresso'), |
321 | 321 | 'endpoint_parsing_error' |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | namespace EventEspresso\core\libraries\rest_api; |
3 | 3 | |
4 | 4 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
5 | - exit('No direct script access allowed'); |
|
5 | + exit('No direct script access allowed'); |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | |
@@ -24,462 +24,462 @@ discard block |
||
24 | 24 | class Model_Version_Info |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * Constant used in the $_model_changes array to indicate that a model |
|
29 | - * was completely new in this version |
|
30 | - */ |
|
31 | - const model_added = 'model_added_in_this_version'; |
|
32 | - |
|
33 | - /** |
|
34 | - * Top-level keys are versions (major and minor version numbers, eg "4.6") |
|
35 | - * next-level keys are model names (eg "Event") that underwent some change in that version |
|
36 | - * and the value is either Model_Version_Info::model_added (indicating the model is completely NEW in this version), |
|
37 | - * or it's an array where the values are model field names, |
|
38 | - * or API resource properties (ie, non-model fields that appear in REST API results) |
|
39 | - * If a version is missing then we don't know anything about what changes it introduced from the previous version |
|
40 | - * |
|
41 | - * @var array |
|
42 | - */ |
|
43 | - protected $_model_changes = array(); |
|
44 | - |
|
45 | - /** |
|
46 | - * top-level keys are version numbers, |
|
47 | - * next-level keys are model CLASSNAMES (even parent classnames), |
|
48 | - * and next-level keys are extra resource properties to attach to those models' resources, |
|
49 | - * and next-level key-value pairs, where the keys are: |
|
50 | - * 'raw', 'type', 'nullable', 'table_alias', 'table_column', 'always_available' |
|
51 | - * |
|
52 | - * @var array |
|
53 | - */ |
|
54 | - protected $_resource_changes = array(); |
|
55 | - |
|
56 | - /** |
|
57 | - * @var string indicating what version of the API was requested |
|
58 | - * (eg although core might be at version 4.8.11, they may have sent a request |
|
59 | - * for 4.6) |
|
60 | - */ |
|
61 | - protected $_requested_version = null; |
|
62 | - |
|
63 | - /** |
|
64 | - * Keys are model names, values are their classnames. |
|
65 | - * We cache this so we only need to calculate this once per request |
|
66 | - * |
|
67 | - * @var array |
|
68 | - */ |
|
69 | - protected $_cached_models_for_requested_version = null; |
|
70 | - |
|
71 | - /** |
|
72 | - * @var array |
|
73 | - */ |
|
74 | - protected $_cached_model_changes_between_requested_version_and_current = null; |
|
75 | - |
|
76 | - /** |
|
77 | - * @var array |
|
78 | - */ |
|
79 | - protected $_cached_resource_changes_between_requested_version_and_current = null; |
|
80 | - |
|
81 | - /** |
|
82 | - * 2d array where top-level keys are model names, 2nd-level keys are field names |
|
83 | - * and values are the actual field objects |
|
84 | - * |
|
85 | - * @var array |
|
86 | - */ |
|
87 | - protected $_cached_fields_on_models = array(); |
|
88 | - |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * Model_Version_Info constructor. |
|
93 | - * |
|
94 | - * @param string $requested_version |
|
95 | - */ |
|
96 | - public function __construct($requested_version) |
|
97 | - { |
|
98 | - $this->_requested_version = $requested_version; |
|
99 | - $this->_model_changes = array( |
|
100 | - '4.8.29' => array( |
|
101 | - //first version where the REST API is in EE core, so no need |
|
102 | - //to specify how its different from the previous |
|
103 | - ), |
|
104 | - ); |
|
105 | - //setup data for "extra" fields added onto resources which don't actually exist on models |
|
106 | - $this->_resource_changes = apply_filters( |
|
107 | - 'FHEE__Model_Version_Info___construct__extra_resource_properties_for_models', |
|
108 | - array() |
|
109 | - ); |
|
110 | - $defaults = array( |
|
111 | - 'raw' => false, |
|
112 | - 'type' => 'N/A', |
|
113 | - 'nullable' => true, |
|
114 | - 'table_alias' => 'N/A', |
|
115 | - 'table_column' => 'N/A', |
|
116 | - 'always_available' => true, |
|
117 | - ); |
|
118 | - foreach ($this->_resource_changes as $version => $model_classnames) { |
|
119 | - foreach ($model_classnames as $model_classname => $extra_fields) { |
|
120 | - foreach ($extra_fields as $fieldname => $field_data) { |
|
121 | - $this->_resource_changes[$model_classname][$fieldname]['name'] = $fieldname; |
|
122 | - foreach ($defaults as $attribute => $default_value) { |
|
123 | - if (! isset($this->_resource_changes[$model_classname][$fieldname][$attribute])) { |
|
124 | - $this->_resource_changes[$model_classname][$fieldname][$attribute] = $default_value; |
|
125 | - } |
|
126 | - } |
|
127 | - } |
|
128 | - } |
|
129 | - } |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * Returns a slice of Model_Version_Info::model_changes()'s array |
|
136 | - * indicating exactly what changes happened between the current core version, |
|
137 | - * and the version requested |
|
138 | - * |
|
139 | - * @return array |
|
140 | - */ |
|
141 | - public function model_changes_between_requested_version_and_current() |
|
142 | - { |
|
143 | - if ($this->_cached_model_changes_between_requested_version_and_current === null) { |
|
144 | - $model_changes = array(); |
|
145 | - foreach ($this->model_changes() as $version => $models_changed_in_version) { |
|
146 | - if ($version <= \EED_Core_Rest_Api::core_version() && $version > $this->requested_version()) { |
|
147 | - $model_changes[$version] = $models_changed_in_version; |
|
148 | - } |
|
149 | - } |
|
150 | - $this->_cached_model_changes_between_requested_version_and_current = $model_changes; |
|
151 | - } |
|
152 | - return $this->_cached_model_changes_between_requested_version_and_current; |
|
153 | - } |
|
154 | - |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * Returns a slice of Model_Version_Info::model_changes()'s array |
|
159 | - * indicating exactly what changes happened between the current core version, |
|
160 | - * and the version requested |
|
161 | - * |
|
162 | - * @return array |
|
163 | - */ |
|
164 | - public function resource_changes_between_requested_version_and_current() |
|
165 | - { |
|
166 | - if ($this->_cached_resource_changes_between_requested_version_and_current === null) { |
|
167 | - $resource_changes = array(); |
|
168 | - foreach ($this->resource_changes() as $version => $model_classnames) { |
|
169 | - if ($version <= \EED_Core_Rest_Api::core_version() && $version > $this->requested_version()) { |
|
170 | - $resource_changes[$version] = $model_classnames; |
|
171 | - } |
|
172 | - } |
|
173 | - $this->_cached_resource_changes_between_requested_version_and_current = $resource_changes; |
|
174 | - } |
|
175 | - return $this->_cached_resource_changes_between_requested_version_and_current; |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - |
|
180 | - /** |
|
181 | - * If a request was sent to 'wp-json/ee/v4.7/events' this would be '4.7' |
|
182 | - * |
|
183 | - * @return string like '4.6' |
|
184 | - */ |
|
185 | - public function requested_version() |
|
186 | - { |
|
187 | - return $this->_requested_version; |
|
188 | - } |
|
189 | - |
|
190 | - |
|
191 | - |
|
192 | - /** |
|
193 | - * Returns an array describing how the models have changed in each version of core |
|
194 | - * that supports the API (starting at 4.6) |
|
195 | - * Top-level keys are versions (major and minor version numbers, eg "4.6") |
|
196 | - * next-level keys are model names (eg "Event") that underwent some change in that version |
|
197 | - * and the value is either NULL (indicating the model is completely NEW in this version), |
|
198 | - * or it's an array where fields are value names. |
|
199 | - * If a version is missing then we don't know anything about what changes it introduced from the previous version |
|
200 | - * |
|
201 | - * @return array |
|
202 | - */ |
|
203 | - public function model_changes() |
|
204 | - { |
|
205 | - return $this->_model_changes; |
|
206 | - } |
|
207 | - |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * Takes into account the requested version, and the current version, and |
|
212 | - * what changed between the two, and tries to return. |
|
213 | - * Analogous to EE_Registry::instance()->non_abstract_db_models |
|
214 | - * |
|
215 | - * @return array keys are model names, values are their classname |
|
216 | - */ |
|
217 | - public function models_for_requested_version() |
|
218 | - { |
|
219 | - if ($this->_cached_models_for_requested_version === null) { |
|
220 | - $all_models_in_current_version = \EE_Registry::instance()->non_abstract_db_models; |
|
221 | - foreach ($this->model_changes_between_requested_version_and_current() as $version => $models_changed) { |
|
222 | - foreach ($models_changed as $model_name => $new_indicator_or_fields_added) { |
|
223 | - if ($new_indicator_or_fields_added === Model_Version_Info::model_added) { |
|
224 | - unset($all_models_in_current_version[$model_name]); |
|
225 | - } |
|
226 | - } |
|
227 | - } |
|
228 | - $this->_cached_models_for_requested_version = apply_filters( |
|
229 | - 'FHEE__EventEspresso_core_libraries_rest_api__models_for_requested_version', |
|
230 | - $all_models_in_current_version, |
|
231 | - $this |
|
232 | - ); |
|
233 | - } |
|
234 | - return $this->_cached_models_for_requested_version; |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - |
|
239 | - /** |
|
240 | - * Determines if this is a valid model name in the requested version. |
|
241 | - * Similar to EE_Registry::instance()->is_model_name(), but takes the requested |
|
242 | - * version's models into account |
|
243 | - * |
|
244 | - * @param string $model_name eg 'Event' |
|
245 | - * @return boolean |
|
246 | - */ |
|
247 | - public function is_model_name_in_this_version($model_name) |
|
248 | - { |
|
249 | - $model_names = $this->models_for_requested_version(); |
|
250 | - if (isset($model_names[$model_name])) { |
|
251 | - return true; |
|
252 | - } else { |
|
253 | - return false; |
|
254 | - } |
|
255 | - } |
|
256 | - |
|
257 | - |
|
258 | - |
|
259 | - /** |
|
260 | - * Wrapper for EE_Registry::instance()->load_model(), but takes the requested |
|
261 | - * version's models into account |
|
262 | - * |
|
263 | - * @param string $model_name |
|
264 | - * @return \EEM_Base |
|
265 | - * @throws \EE_Error |
|
266 | - */ |
|
267 | - public function load_model($model_name) |
|
268 | - { |
|
269 | - if ($this->is_model_name_in_this_version($model_name)) { |
|
270 | - return \EE_Registry::instance()->load_model($model_name); |
|
271 | - } else { |
|
272 | - throw new \EE_Error( |
|
273 | - sprintf( |
|
274 | - __( |
|
275 | - 'Cannot load model "%1$s" because it does not exist in version %2$s of Event Espresso', |
|
276 | - 'event_espresso' |
|
277 | - ), |
|
278 | - $model_name, |
|
279 | - $this->requested_version() |
|
280 | - ) |
|
281 | - ); |
|
282 | - } |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - |
|
287 | - /** |
|
288 | - * Gets all the fields that should exist on this model right now |
|
289 | - * |
|
290 | - * @param \EEM_Base $model |
|
291 | - * @return array|\EE_Model_Field_Base[] |
|
292 | - */ |
|
293 | - public function fields_on_model_in_this_version($model) |
|
294 | - { |
|
295 | - if (! isset($this->_cached_fields_on_models[$model->get_this_model_name()])) { |
|
296 | - //get all model changes between the requested version and current core version |
|
297 | - $changes = $this->model_changes_between_requested_version_and_current(); |
|
298 | - //fetch all fields currently on this model |
|
299 | - $current_fields = $model->field_settings(); |
|
300 | - //remove all fields that have been added since |
|
301 | - foreach ($changes as $version => $changes_in_version) { |
|
302 | - if ( |
|
303 | - isset($changes_in_version[$model->get_this_model_name()]) |
|
304 | - && $changes_in_version[$model->get_this_model_name()] !== Model_Version_Info::model_added |
|
305 | - ) { |
|
306 | - $current_fields = array_diff_key( |
|
307 | - $current_fields, |
|
308 | - array_flip($changes_in_version[$model->get_this_model_name()]) |
|
309 | - ); |
|
310 | - } |
|
311 | - } |
|
312 | - $this->_cached_fields_on_models = $current_fields; |
|
313 | - } |
|
314 | - return $this->_cached_fields_on_models; |
|
315 | - } |
|
316 | - |
|
317 | - |
|
318 | - |
|
319 | - /** |
|
320 | - * Determines if $object is of one of the classes of $classes. Similar to |
|
321 | - * in_array(), except this checks if $object is a subclass of the classnames provided |
|
322 | - * in $classnames |
|
323 | - * |
|
324 | - * @param object $object |
|
325 | - * @param array $classnames |
|
326 | - * @return boolean |
|
327 | - */ |
|
328 | - public function is_subclass_of_one($object, $classnames) |
|
329 | - { |
|
330 | - foreach ($classnames as $classname) { |
|
331 | - if (is_a($object, $classname)) { |
|
332 | - return true; |
|
333 | - } |
|
334 | - } |
|
335 | - return false; |
|
336 | - } |
|
337 | - |
|
338 | - |
|
339 | - |
|
340 | - /** |
|
341 | - * Returns the list of model field classes that that the API basically ignores |
|
342 | - * |
|
343 | - * @return array |
|
344 | - */ |
|
345 | - public function fields_ignored() |
|
346 | - { |
|
347 | - return apply_filters( |
|
348 | - 'FHEE__Controller_Model_Read_fields_ignored', |
|
349 | - array('EE_Foreign_Key_Field_Base', 'EE_Any_Foreign_Model_Name_Field') |
|
350 | - ); |
|
351 | - } |
|
352 | - |
|
353 | - |
|
354 | - |
|
355 | - /** |
|
356 | - * If this field one that should be ignored by the API? |
|
357 | - * |
|
358 | - * @param EE_Model_Field_Base |
|
359 | - * @return boolean |
|
360 | - */ |
|
361 | - public function field_is_ignored($field_obj) |
|
362 | - { |
|
363 | - return $this->is_subclass_of_one($field_obj, $this->fields_ignored()); |
|
364 | - } |
|
365 | - |
|
366 | - |
|
367 | - |
|
368 | - /** |
|
369 | - * Returns the list of model field classes that have a "raw" and non-raw formats. |
|
370 | - * Normally the "raw" versions are only accessible to those who can edit them. |
|
371 | - * |
|
372 | - * @return array an array of EE_Model_Field_Base child classnames |
|
373 | - */ |
|
374 | - public function fields_that_have_rendered_format() |
|
375 | - { |
|
376 | - return apply_filters( |
|
377 | - 'FHEE__Controller_Model_Read__fields_raw', |
|
378 | - array('EE_Post_Content_Field', 'EE_Full_HTML_Field') |
|
379 | - ); |
|
380 | - } |
|
381 | - |
|
382 | - |
|
383 | - |
|
384 | - /** |
|
385 | - * If this field one that has a raw format |
|
386 | - * |
|
387 | - * @param EE_Model_Field_Base |
|
388 | - * @return boolean |
|
389 | - */ |
|
390 | - public function field_has_rendered_format($field_obj) |
|
391 | - { |
|
392 | - return $this->is_subclass_of_one($field_obj, $this->fields_that_have_rendered_format()); |
|
393 | - } |
|
394 | - |
|
395 | - |
|
396 | - |
|
397 | - /** |
|
398 | - * Returns the list of model field classes that have a "_pretty" and non-pretty versions. |
|
399 | - * The pretty version of the field is NOT queryable or editable, but requires no extra permissions |
|
400 | - * to view |
|
401 | - * |
|
402 | - * @return array an array of EE_Model_Field_Base child classnames |
|
403 | - */ |
|
404 | - public function fields_that_have_pretty_format() |
|
405 | - { |
|
406 | - return apply_filters( |
|
407 | - 'FHEE__Controller_Model_Read__fields_pretty', |
|
408 | - array('EE_Enum_Integer_Field', 'EE_Enum_Text_Field', 'EE_Money_Field') |
|
409 | - ); |
|
410 | - } |
|
411 | - |
|
412 | - |
|
413 | - |
|
414 | - /** |
|
415 | - * If this field one that has a pretty equivalent |
|
416 | - * |
|
417 | - * @param EE_Model_Field_Base |
|
418 | - * @return boolean |
|
419 | - */ |
|
420 | - public function field_has_pretty_format($field_obj) |
|
421 | - { |
|
422 | - return $this->is_subclass_of_one($field_obj, $this->fields_that_have_pretty_format()); |
|
423 | - } |
|
424 | - |
|
425 | - |
|
426 | - |
|
427 | - /** |
|
428 | - * Returns an array describing what extra API resource properties have been added through the versions |
|
429 | - * |
|
430 | - * @return array @see $this->_extra_resource_properties_for_models |
|
431 | - */ |
|
432 | - public function resource_changes() |
|
433 | - { |
|
434 | - return $this->_resource_changes; |
|
435 | - } |
|
436 | - |
|
437 | - |
|
438 | - |
|
439 | - /** |
|
440 | - * Returns an array where keys are extra resource properties in this version of the API, |
|
441 | - * and values are key-value pairs describing the new properties. @see Model_Version::_resource_changes |
|
442 | - * |
|
443 | - * @param \EEM_Base $model |
|
444 | - * @return array |
|
445 | - */ |
|
446 | - public function extra_resource_properties_for_model($model) |
|
447 | - { |
|
448 | - $extra_properties = array(); |
|
449 | - foreach ($this->resource_changes_between_requested_version_and_current() as $version => $model_classnames) { |
|
450 | - foreach ($model_classnames as $model_classname => $properties_added_in_this_version) { |
|
451 | - if (is_subclass_of($model, $model_classname)) { |
|
452 | - $extra_properties = array_merge($extra_properties, $properties_added_in_this_version); |
|
453 | - } |
|
454 | - } |
|
455 | - } |
|
456 | - return $extra_properties; |
|
457 | - } |
|
458 | - |
|
459 | - |
|
460 | - |
|
461 | - /** |
|
462 | - * Gets all the related models for the specified model. It's good to use this |
|
463 | - * in case this model didn't exist for this version or something |
|
464 | - * |
|
465 | - * @param \EEM_Base $model |
|
466 | - * @return \EE_Model_Relation_Base[] |
|
467 | - */ |
|
468 | - public function relation_settings(\EEM_Base $model) |
|
469 | - { |
|
470 | - $relations = array(); |
|
471 | - foreach ($model->relation_settings() as $relation_name => $relation_obj) { |
|
472 | - if ($this->is_model_name_in_this_version($relation_name)) { |
|
473 | - $relations[$relation_name] = $relation_obj; |
|
474 | - } |
|
475 | - } |
|
476 | - //filter the results, but use the old filter name |
|
477 | - return apply_filters( |
|
478 | - 'FHEE__Read__create_entity_from_wpdb_result__related_models_to_include', |
|
479 | - $relations, |
|
480 | - $model |
|
481 | - ); |
|
482 | - } |
|
27 | + /** |
|
28 | + * Constant used in the $_model_changes array to indicate that a model |
|
29 | + * was completely new in this version |
|
30 | + */ |
|
31 | + const model_added = 'model_added_in_this_version'; |
|
32 | + |
|
33 | + /** |
|
34 | + * Top-level keys are versions (major and minor version numbers, eg "4.6") |
|
35 | + * next-level keys are model names (eg "Event") that underwent some change in that version |
|
36 | + * and the value is either Model_Version_Info::model_added (indicating the model is completely NEW in this version), |
|
37 | + * or it's an array where the values are model field names, |
|
38 | + * or API resource properties (ie, non-model fields that appear in REST API results) |
|
39 | + * If a version is missing then we don't know anything about what changes it introduced from the previous version |
|
40 | + * |
|
41 | + * @var array |
|
42 | + */ |
|
43 | + protected $_model_changes = array(); |
|
44 | + |
|
45 | + /** |
|
46 | + * top-level keys are version numbers, |
|
47 | + * next-level keys are model CLASSNAMES (even parent classnames), |
|
48 | + * and next-level keys are extra resource properties to attach to those models' resources, |
|
49 | + * and next-level key-value pairs, where the keys are: |
|
50 | + * 'raw', 'type', 'nullable', 'table_alias', 'table_column', 'always_available' |
|
51 | + * |
|
52 | + * @var array |
|
53 | + */ |
|
54 | + protected $_resource_changes = array(); |
|
55 | + |
|
56 | + /** |
|
57 | + * @var string indicating what version of the API was requested |
|
58 | + * (eg although core might be at version 4.8.11, they may have sent a request |
|
59 | + * for 4.6) |
|
60 | + */ |
|
61 | + protected $_requested_version = null; |
|
62 | + |
|
63 | + /** |
|
64 | + * Keys are model names, values are their classnames. |
|
65 | + * We cache this so we only need to calculate this once per request |
|
66 | + * |
|
67 | + * @var array |
|
68 | + */ |
|
69 | + protected $_cached_models_for_requested_version = null; |
|
70 | + |
|
71 | + /** |
|
72 | + * @var array |
|
73 | + */ |
|
74 | + protected $_cached_model_changes_between_requested_version_and_current = null; |
|
75 | + |
|
76 | + /** |
|
77 | + * @var array |
|
78 | + */ |
|
79 | + protected $_cached_resource_changes_between_requested_version_and_current = null; |
|
80 | + |
|
81 | + /** |
|
82 | + * 2d array where top-level keys are model names, 2nd-level keys are field names |
|
83 | + * and values are the actual field objects |
|
84 | + * |
|
85 | + * @var array |
|
86 | + */ |
|
87 | + protected $_cached_fields_on_models = array(); |
|
88 | + |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * Model_Version_Info constructor. |
|
93 | + * |
|
94 | + * @param string $requested_version |
|
95 | + */ |
|
96 | + public function __construct($requested_version) |
|
97 | + { |
|
98 | + $this->_requested_version = $requested_version; |
|
99 | + $this->_model_changes = array( |
|
100 | + '4.8.29' => array( |
|
101 | + //first version where the REST API is in EE core, so no need |
|
102 | + //to specify how its different from the previous |
|
103 | + ), |
|
104 | + ); |
|
105 | + //setup data for "extra" fields added onto resources which don't actually exist on models |
|
106 | + $this->_resource_changes = apply_filters( |
|
107 | + 'FHEE__Model_Version_Info___construct__extra_resource_properties_for_models', |
|
108 | + array() |
|
109 | + ); |
|
110 | + $defaults = array( |
|
111 | + 'raw' => false, |
|
112 | + 'type' => 'N/A', |
|
113 | + 'nullable' => true, |
|
114 | + 'table_alias' => 'N/A', |
|
115 | + 'table_column' => 'N/A', |
|
116 | + 'always_available' => true, |
|
117 | + ); |
|
118 | + foreach ($this->_resource_changes as $version => $model_classnames) { |
|
119 | + foreach ($model_classnames as $model_classname => $extra_fields) { |
|
120 | + foreach ($extra_fields as $fieldname => $field_data) { |
|
121 | + $this->_resource_changes[$model_classname][$fieldname]['name'] = $fieldname; |
|
122 | + foreach ($defaults as $attribute => $default_value) { |
|
123 | + if (! isset($this->_resource_changes[$model_classname][$fieldname][$attribute])) { |
|
124 | + $this->_resource_changes[$model_classname][$fieldname][$attribute] = $default_value; |
|
125 | + } |
|
126 | + } |
|
127 | + } |
|
128 | + } |
|
129 | + } |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * Returns a slice of Model_Version_Info::model_changes()'s array |
|
136 | + * indicating exactly what changes happened between the current core version, |
|
137 | + * and the version requested |
|
138 | + * |
|
139 | + * @return array |
|
140 | + */ |
|
141 | + public function model_changes_between_requested_version_and_current() |
|
142 | + { |
|
143 | + if ($this->_cached_model_changes_between_requested_version_and_current === null) { |
|
144 | + $model_changes = array(); |
|
145 | + foreach ($this->model_changes() as $version => $models_changed_in_version) { |
|
146 | + if ($version <= \EED_Core_Rest_Api::core_version() && $version > $this->requested_version()) { |
|
147 | + $model_changes[$version] = $models_changed_in_version; |
|
148 | + } |
|
149 | + } |
|
150 | + $this->_cached_model_changes_between_requested_version_and_current = $model_changes; |
|
151 | + } |
|
152 | + return $this->_cached_model_changes_between_requested_version_and_current; |
|
153 | + } |
|
154 | + |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * Returns a slice of Model_Version_Info::model_changes()'s array |
|
159 | + * indicating exactly what changes happened between the current core version, |
|
160 | + * and the version requested |
|
161 | + * |
|
162 | + * @return array |
|
163 | + */ |
|
164 | + public function resource_changes_between_requested_version_and_current() |
|
165 | + { |
|
166 | + if ($this->_cached_resource_changes_between_requested_version_and_current === null) { |
|
167 | + $resource_changes = array(); |
|
168 | + foreach ($this->resource_changes() as $version => $model_classnames) { |
|
169 | + if ($version <= \EED_Core_Rest_Api::core_version() && $version > $this->requested_version()) { |
|
170 | + $resource_changes[$version] = $model_classnames; |
|
171 | + } |
|
172 | + } |
|
173 | + $this->_cached_resource_changes_between_requested_version_and_current = $resource_changes; |
|
174 | + } |
|
175 | + return $this->_cached_resource_changes_between_requested_version_and_current; |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + |
|
180 | + /** |
|
181 | + * If a request was sent to 'wp-json/ee/v4.7/events' this would be '4.7' |
|
182 | + * |
|
183 | + * @return string like '4.6' |
|
184 | + */ |
|
185 | + public function requested_version() |
|
186 | + { |
|
187 | + return $this->_requested_version; |
|
188 | + } |
|
189 | + |
|
190 | + |
|
191 | + |
|
192 | + /** |
|
193 | + * Returns an array describing how the models have changed in each version of core |
|
194 | + * that supports the API (starting at 4.6) |
|
195 | + * Top-level keys are versions (major and minor version numbers, eg "4.6") |
|
196 | + * next-level keys are model names (eg "Event") that underwent some change in that version |
|
197 | + * and the value is either NULL (indicating the model is completely NEW in this version), |
|
198 | + * or it's an array where fields are value names. |
|
199 | + * If a version is missing then we don't know anything about what changes it introduced from the previous version |
|
200 | + * |
|
201 | + * @return array |
|
202 | + */ |
|
203 | + public function model_changes() |
|
204 | + { |
|
205 | + return $this->_model_changes; |
|
206 | + } |
|
207 | + |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * Takes into account the requested version, and the current version, and |
|
212 | + * what changed between the two, and tries to return. |
|
213 | + * Analogous to EE_Registry::instance()->non_abstract_db_models |
|
214 | + * |
|
215 | + * @return array keys are model names, values are their classname |
|
216 | + */ |
|
217 | + public function models_for_requested_version() |
|
218 | + { |
|
219 | + if ($this->_cached_models_for_requested_version === null) { |
|
220 | + $all_models_in_current_version = \EE_Registry::instance()->non_abstract_db_models; |
|
221 | + foreach ($this->model_changes_between_requested_version_and_current() as $version => $models_changed) { |
|
222 | + foreach ($models_changed as $model_name => $new_indicator_or_fields_added) { |
|
223 | + if ($new_indicator_or_fields_added === Model_Version_Info::model_added) { |
|
224 | + unset($all_models_in_current_version[$model_name]); |
|
225 | + } |
|
226 | + } |
|
227 | + } |
|
228 | + $this->_cached_models_for_requested_version = apply_filters( |
|
229 | + 'FHEE__EventEspresso_core_libraries_rest_api__models_for_requested_version', |
|
230 | + $all_models_in_current_version, |
|
231 | + $this |
|
232 | + ); |
|
233 | + } |
|
234 | + return $this->_cached_models_for_requested_version; |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + |
|
239 | + /** |
|
240 | + * Determines if this is a valid model name in the requested version. |
|
241 | + * Similar to EE_Registry::instance()->is_model_name(), but takes the requested |
|
242 | + * version's models into account |
|
243 | + * |
|
244 | + * @param string $model_name eg 'Event' |
|
245 | + * @return boolean |
|
246 | + */ |
|
247 | + public function is_model_name_in_this_version($model_name) |
|
248 | + { |
|
249 | + $model_names = $this->models_for_requested_version(); |
|
250 | + if (isset($model_names[$model_name])) { |
|
251 | + return true; |
|
252 | + } else { |
|
253 | + return false; |
|
254 | + } |
|
255 | + } |
|
256 | + |
|
257 | + |
|
258 | + |
|
259 | + /** |
|
260 | + * Wrapper for EE_Registry::instance()->load_model(), but takes the requested |
|
261 | + * version's models into account |
|
262 | + * |
|
263 | + * @param string $model_name |
|
264 | + * @return \EEM_Base |
|
265 | + * @throws \EE_Error |
|
266 | + */ |
|
267 | + public function load_model($model_name) |
|
268 | + { |
|
269 | + if ($this->is_model_name_in_this_version($model_name)) { |
|
270 | + return \EE_Registry::instance()->load_model($model_name); |
|
271 | + } else { |
|
272 | + throw new \EE_Error( |
|
273 | + sprintf( |
|
274 | + __( |
|
275 | + 'Cannot load model "%1$s" because it does not exist in version %2$s of Event Espresso', |
|
276 | + 'event_espresso' |
|
277 | + ), |
|
278 | + $model_name, |
|
279 | + $this->requested_version() |
|
280 | + ) |
|
281 | + ); |
|
282 | + } |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + |
|
287 | + /** |
|
288 | + * Gets all the fields that should exist on this model right now |
|
289 | + * |
|
290 | + * @param \EEM_Base $model |
|
291 | + * @return array|\EE_Model_Field_Base[] |
|
292 | + */ |
|
293 | + public function fields_on_model_in_this_version($model) |
|
294 | + { |
|
295 | + if (! isset($this->_cached_fields_on_models[$model->get_this_model_name()])) { |
|
296 | + //get all model changes between the requested version and current core version |
|
297 | + $changes = $this->model_changes_between_requested_version_and_current(); |
|
298 | + //fetch all fields currently on this model |
|
299 | + $current_fields = $model->field_settings(); |
|
300 | + //remove all fields that have been added since |
|
301 | + foreach ($changes as $version => $changes_in_version) { |
|
302 | + if ( |
|
303 | + isset($changes_in_version[$model->get_this_model_name()]) |
|
304 | + && $changes_in_version[$model->get_this_model_name()] !== Model_Version_Info::model_added |
|
305 | + ) { |
|
306 | + $current_fields = array_diff_key( |
|
307 | + $current_fields, |
|
308 | + array_flip($changes_in_version[$model->get_this_model_name()]) |
|
309 | + ); |
|
310 | + } |
|
311 | + } |
|
312 | + $this->_cached_fields_on_models = $current_fields; |
|
313 | + } |
|
314 | + return $this->_cached_fields_on_models; |
|
315 | + } |
|
316 | + |
|
317 | + |
|
318 | + |
|
319 | + /** |
|
320 | + * Determines if $object is of one of the classes of $classes. Similar to |
|
321 | + * in_array(), except this checks if $object is a subclass of the classnames provided |
|
322 | + * in $classnames |
|
323 | + * |
|
324 | + * @param object $object |
|
325 | + * @param array $classnames |
|
326 | + * @return boolean |
|
327 | + */ |
|
328 | + public function is_subclass_of_one($object, $classnames) |
|
329 | + { |
|
330 | + foreach ($classnames as $classname) { |
|
331 | + if (is_a($object, $classname)) { |
|
332 | + return true; |
|
333 | + } |
|
334 | + } |
|
335 | + return false; |
|
336 | + } |
|
337 | + |
|
338 | + |
|
339 | + |
|
340 | + /** |
|
341 | + * Returns the list of model field classes that that the API basically ignores |
|
342 | + * |
|
343 | + * @return array |
|
344 | + */ |
|
345 | + public function fields_ignored() |
|
346 | + { |
|
347 | + return apply_filters( |
|
348 | + 'FHEE__Controller_Model_Read_fields_ignored', |
|
349 | + array('EE_Foreign_Key_Field_Base', 'EE_Any_Foreign_Model_Name_Field') |
|
350 | + ); |
|
351 | + } |
|
352 | + |
|
353 | + |
|
354 | + |
|
355 | + /** |
|
356 | + * If this field one that should be ignored by the API? |
|
357 | + * |
|
358 | + * @param EE_Model_Field_Base |
|
359 | + * @return boolean |
|
360 | + */ |
|
361 | + public function field_is_ignored($field_obj) |
|
362 | + { |
|
363 | + return $this->is_subclass_of_one($field_obj, $this->fields_ignored()); |
|
364 | + } |
|
365 | + |
|
366 | + |
|
367 | + |
|
368 | + /** |
|
369 | + * Returns the list of model field classes that have a "raw" and non-raw formats. |
|
370 | + * Normally the "raw" versions are only accessible to those who can edit them. |
|
371 | + * |
|
372 | + * @return array an array of EE_Model_Field_Base child classnames |
|
373 | + */ |
|
374 | + public function fields_that_have_rendered_format() |
|
375 | + { |
|
376 | + return apply_filters( |
|
377 | + 'FHEE__Controller_Model_Read__fields_raw', |
|
378 | + array('EE_Post_Content_Field', 'EE_Full_HTML_Field') |
|
379 | + ); |
|
380 | + } |
|
381 | + |
|
382 | + |
|
383 | + |
|
384 | + /** |
|
385 | + * If this field one that has a raw format |
|
386 | + * |
|
387 | + * @param EE_Model_Field_Base |
|
388 | + * @return boolean |
|
389 | + */ |
|
390 | + public function field_has_rendered_format($field_obj) |
|
391 | + { |
|
392 | + return $this->is_subclass_of_one($field_obj, $this->fields_that_have_rendered_format()); |
|
393 | + } |
|
394 | + |
|
395 | + |
|
396 | + |
|
397 | + /** |
|
398 | + * Returns the list of model field classes that have a "_pretty" and non-pretty versions. |
|
399 | + * The pretty version of the field is NOT queryable or editable, but requires no extra permissions |
|
400 | + * to view |
|
401 | + * |
|
402 | + * @return array an array of EE_Model_Field_Base child classnames |
|
403 | + */ |
|
404 | + public function fields_that_have_pretty_format() |
|
405 | + { |
|
406 | + return apply_filters( |
|
407 | + 'FHEE__Controller_Model_Read__fields_pretty', |
|
408 | + array('EE_Enum_Integer_Field', 'EE_Enum_Text_Field', 'EE_Money_Field') |
|
409 | + ); |
|
410 | + } |
|
411 | + |
|
412 | + |
|
413 | + |
|
414 | + /** |
|
415 | + * If this field one that has a pretty equivalent |
|
416 | + * |
|
417 | + * @param EE_Model_Field_Base |
|
418 | + * @return boolean |
|
419 | + */ |
|
420 | + public function field_has_pretty_format($field_obj) |
|
421 | + { |
|
422 | + return $this->is_subclass_of_one($field_obj, $this->fields_that_have_pretty_format()); |
|
423 | + } |
|
424 | + |
|
425 | + |
|
426 | + |
|
427 | + /** |
|
428 | + * Returns an array describing what extra API resource properties have been added through the versions |
|
429 | + * |
|
430 | + * @return array @see $this->_extra_resource_properties_for_models |
|
431 | + */ |
|
432 | + public function resource_changes() |
|
433 | + { |
|
434 | + return $this->_resource_changes; |
|
435 | + } |
|
436 | + |
|
437 | + |
|
438 | + |
|
439 | + /** |
|
440 | + * Returns an array where keys are extra resource properties in this version of the API, |
|
441 | + * and values are key-value pairs describing the new properties. @see Model_Version::_resource_changes |
|
442 | + * |
|
443 | + * @param \EEM_Base $model |
|
444 | + * @return array |
|
445 | + */ |
|
446 | + public function extra_resource_properties_for_model($model) |
|
447 | + { |
|
448 | + $extra_properties = array(); |
|
449 | + foreach ($this->resource_changes_between_requested_version_and_current() as $version => $model_classnames) { |
|
450 | + foreach ($model_classnames as $model_classname => $properties_added_in_this_version) { |
|
451 | + if (is_subclass_of($model, $model_classname)) { |
|
452 | + $extra_properties = array_merge($extra_properties, $properties_added_in_this_version); |
|
453 | + } |
|
454 | + } |
|
455 | + } |
|
456 | + return $extra_properties; |
|
457 | + } |
|
458 | + |
|
459 | + |
|
460 | + |
|
461 | + /** |
|
462 | + * Gets all the related models for the specified model. It's good to use this |
|
463 | + * in case this model didn't exist for this version or something |
|
464 | + * |
|
465 | + * @param \EEM_Base $model |
|
466 | + * @return \EE_Model_Relation_Base[] |
|
467 | + */ |
|
468 | + public function relation_settings(\EEM_Base $model) |
|
469 | + { |
|
470 | + $relations = array(); |
|
471 | + foreach ($model->relation_settings() as $relation_name => $relation_obj) { |
|
472 | + if ($this->is_model_name_in_this_version($relation_name)) { |
|
473 | + $relations[$relation_name] = $relation_obj; |
|
474 | + } |
|
475 | + } |
|
476 | + //filter the results, but use the old filter name |
|
477 | + return apply_filters( |
|
478 | + 'FHEE__Read__create_entity_from_wpdb_result__related_models_to_include', |
|
479 | + $relations, |
|
480 | + $model |
|
481 | + ); |
|
482 | + } |
|
483 | 483 | |
484 | 484 | } |
485 | 485 |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | namespace EventEspresso\core\libraries\rest_api; |
3 | 3 | |
4 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
4 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
5 | 5 | exit('No direct script access allowed'); |
6 | 6 | } |
7 | 7 | |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | foreach ($extra_fields as $fieldname => $field_data) { |
121 | 121 | $this->_resource_changes[$model_classname][$fieldname]['name'] = $fieldname; |
122 | 122 | foreach ($defaults as $attribute => $default_value) { |
123 | - if (! isset($this->_resource_changes[$model_classname][$fieldname][$attribute])) { |
|
123 | + if ( ! isset($this->_resource_changes[$model_classname][$fieldname][$attribute])) { |
|
124 | 124 | $this->_resource_changes[$model_classname][$fieldname][$attribute] = $default_value; |
125 | 125 | } |
126 | 126 | } |
@@ -292,7 +292,7 @@ discard block |
||
292 | 292 | */ |
293 | 293 | public function fields_on_model_in_this_version($model) |
294 | 294 | { |
295 | - if (! isset($this->_cached_fields_on_models[$model->get_this_model_name()])) { |
|
295 | + if ( ! isset($this->_cached_fields_on_models[$model->get_this_model_name()])) { |
|
296 | 296 | //get all model changes between the requested version and current core version |
297 | 297 | $changes = $this->model_changes_between_requested_version_and_current(); |
298 | 298 | //fetch all fields currently on this model |
@@ -2,7 +2,7 @@ discard block |
||
2 | 2 | namespace EventEspresso\core\libraries\rest_api; |
3 | 3 | |
4 | 4 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
5 | - exit('No direct script access allowed'); |
|
5 | + exit('No direct script access allowed'); |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | |
@@ -27,485 +27,485 @@ discard block |
||
27 | 27 | class Model_Data_Translator |
28 | 28 | { |
29 | 29 | |
30 | - /** |
|
31 | - * We used to use -1 for infinity in the rest api, but that's ambiguous for |
|
32 | - * fields that COULD contain -1; so we use null |
|
33 | - */ |
|
34 | - const ee_inf_in_rest = null; |
|
35 | - |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * Prepares a possible array of input values from JSON for use by the models |
|
40 | - * |
|
41 | - * @param \EE_Model_Field_Base $field_obj |
|
42 | - * @param mixed $original_value_maybe_array |
|
43 | - * @param string $requested_version |
|
44 | - * @param string $timezone_string treat values as being in this timezone |
|
45 | - * @return mixed |
|
46 | - * @throws \DomainException |
|
47 | - */ |
|
48 | - public static function prepare_field_values_from_json( |
|
49 | - $field_obj, |
|
50 | - $original_value_maybe_array, |
|
51 | - $requested_version, |
|
52 | - $timezone_string = 'UTC' |
|
53 | - ) { |
|
54 | - if (is_array($original_value_maybe_array)) { |
|
55 | - $new_value_maybe_array = array(); |
|
56 | - foreach ($original_value_maybe_array as $array_key => $array_item) { |
|
57 | - $new_value_maybe_array[$array_key] = Model_Data_Translator::prepare_field_value_from_json( |
|
58 | - $field_obj, |
|
59 | - $array_item, |
|
60 | - $requested_version, |
|
61 | - $timezone_string |
|
62 | - ); |
|
63 | - } |
|
64 | - } else { |
|
65 | - $new_value_maybe_array = Model_Data_Translator::prepare_field_value_from_json( |
|
66 | - $field_obj, |
|
67 | - $original_value_maybe_array, |
|
68 | - $requested_version, |
|
69 | - $timezone_string |
|
70 | - ); |
|
71 | - } |
|
72 | - return $new_value_maybe_array; |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * Prepares an array of field values FOR use in JSON/REST API |
|
79 | - * |
|
80 | - * @param \EE_Model_Field_Base $field_obj |
|
81 | - * @param mixed $original_value_maybe_array |
|
82 | - * @param string $request_version (eg 4.8.36) |
|
83 | - * @return array |
|
84 | - */ |
|
85 | - public static function prepare_field_values_for_json($field_obj, $original_value_maybe_array, $request_version) |
|
86 | - { |
|
87 | - if (is_array($original_value_maybe_array)) { |
|
88 | - $new_value_maybe_array = array(); |
|
89 | - foreach ($original_value_maybe_array as $array_key => $array_item) { |
|
90 | - $new_value_maybe_array[$array_key] = Model_Data_Translator::prepare_field_value_for_json( |
|
91 | - $field_obj, |
|
92 | - $array_item, |
|
93 | - $request_version |
|
94 | - ); |
|
95 | - } |
|
96 | - } else { |
|
97 | - $new_value_maybe_array = Model_Data_Translator::prepare_field_value_for_json( |
|
98 | - $field_obj, |
|
99 | - $original_value_maybe_array, |
|
100 | - $request_version |
|
101 | - ); |
|
102 | - } |
|
103 | - return $new_value_maybe_array; |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * Prepares incoming data from the json or $_REQUEST parameters for the models' |
|
110 | - * "$query_params". |
|
111 | - * |
|
112 | - * @param \EE_Model_Field_Base $field_obj |
|
113 | - * @param mixed $original_value |
|
114 | - * @param string $requested_version |
|
115 | - * @param string $timezone_string treat values as being in this timezone |
|
116 | - * @return mixed |
|
117 | - * @throws \DomainException |
|
118 | - */ |
|
119 | - public static function prepare_field_value_from_json( |
|
120 | - $field_obj, |
|
121 | - $original_value, |
|
122 | - $requested_version, |
|
123 | - $timezone_string = 'UTC' // UTC |
|
124 | - ) |
|
125 | - { |
|
126 | - $timezone_string = $timezone_string !== '' ? $timezone_string : get_option('timezone_string', ''); |
|
127 | - $new_value = null; |
|
128 | - if ($field_obj instanceof \EE_Infinite_Integer_Field |
|
129 | - && in_array($original_value, array(null, ''), true) |
|
130 | - ) { |
|
131 | - $new_value = EE_INF; |
|
132 | - } elseif ($field_obj instanceof \EE_Datetime_Field) { |
|
133 | - list($offset_sign, $offset_secs) = Model_Data_Translator::parse_timezone_offset( |
|
134 | - $field_obj->get_timezone_offset( |
|
135 | - new \DateTimeZone($timezone_string) |
|
136 | - ) |
|
137 | - ); |
|
138 | - $offset_string = |
|
139 | - str_pad( |
|
140 | - floor($offset_secs / HOUR_IN_SECONDS), |
|
141 | - 2, |
|
142 | - '0', |
|
143 | - STR_PAD_LEFT |
|
144 | - ) |
|
145 | - . ':' |
|
146 | - . str_pad( |
|
147 | - ($offset_secs % HOUR_IN_SECONDS) / MINUTE_IN_SECONDS, |
|
148 | - 2, |
|
149 | - '0', |
|
150 | - STR_PAD_LEFT |
|
151 | - ); |
|
152 | - $new_value = rest_parse_date($original_value . $offset_sign . $offset_string); |
|
153 | - } else { |
|
154 | - $new_value = $original_value; |
|
155 | - } |
|
156 | - return $new_value; |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * determines what's going on with them timezone strings |
|
163 | - * |
|
164 | - * @param int $timezone_offset |
|
165 | - * @return array |
|
166 | - */ |
|
167 | - private static function parse_timezone_offset($timezone_offset) |
|
168 | - { |
|
169 | - $first_char = substr((string)$timezone_offset, 0, 1); |
|
170 | - if ($first_char === '+' || $first_char === '-') { |
|
171 | - $offset_sign = $first_char; |
|
172 | - $offset_secs = substr((string)$timezone_offset, 1); |
|
173 | - } else { |
|
174 | - $offset_sign = '+'; |
|
175 | - $offset_secs = $timezone_offset; |
|
176 | - } |
|
177 | - return array($offset_sign, $offset_secs); |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * Prepares a field's value for display in the API |
|
184 | - * |
|
185 | - * @param \EE_Model_Field_Base $field_obj |
|
186 | - * @param mixed $original_value |
|
187 | - * @param string $requested_version |
|
188 | - * @return mixed |
|
189 | - */ |
|
190 | - public static function prepare_field_value_for_json($field_obj, $original_value, $requested_version) |
|
191 | - { |
|
192 | - if ($original_value === EE_INF) { |
|
193 | - $new_value = Model_Data_Translator::ee_inf_in_rest; |
|
194 | - } elseif ($field_obj instanceof \EE_Datetime_Field) { |
|
195 | - if ($original_value instanceof \DateTime) { |
|
196 | - $new_value = $original_value->format('Y-m-d H:i:s'); |
|
197 | - } elseif (is_int($original_value)) { |
|
198 | - $new_value = date('Y-m-d H:i:s', $original_value); |
|
199 | - } else { |
|
200 | - $new_value = $original_value; |
|
201 | - } |
|
202 | - $new_value = mysql_to_rfc3339($new_value); |
|
203 | - } else { |
|
204 | - $new_value = $original_value; |
|
205 | - } |
|
206 | - return apply_filters('FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_field_for_rest_api', |
|
207 | - $new_value, |
|
208 | - $field_obj, |
|
209 | - $original_value, |
|
210 | - $requested_version |
|
211 | - ); |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - |
|
216 | - /** |
|
217 | - * Prepares condition-query-parameters (like what's in where and having) from |
|
218 | - * the format expected in the API to use in the models |
|
219 | - * |
|
220 | - * @param array $inputted_query_params_of_this_type |
|
221 | - * @param \EEM_Base $model |
|
222 | - * @param string $requested_version |
|
223 | - * @return array |
|
224 | - * @throws \DomainException |
|
225 | - * @throws \EE_Error |
|
226 | - */ |
|
227 | - public static function prepare_conditions_query_params_for_models( |
|
228 | - $inputted_query_params_of_this_type, |
|
229 | - \EEM_Base $model, |
|
230 | - $requested_version |
|
231 | - ) { |
|
232 | - $query_param_for_models = array(); |
|
233 | - foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) { |
|
234 | - $query_param_sans_stars = Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($query_param_key); |
|
235 | - $field = Model_Data_Translator::deduce_field_from_query_param( |
|
236 | - $query_param_sans_stars, |
|
237 | - $model |
|
238 | - ); |
|
239 | - //double-check is it a *_gmt field? |
|
240 | - if (! $field instanceof \EE_Model_Field_Base |
|
241 | - && Model_Data_Translator::is_gmt_date_field_name($query_param_sans_stars) |
|
242 | - ) { |
|
243 | - //yep, take off '_gmt', and find the field |
|
244 | - $query_param_key = Model_Data_Translator::remove_gmt_from_field_name($query_param_sans_stars); |
|
245 | - $field = Model_Data_Translator::deduce_field_from_query_param( |
|
246 | - $query_param_key, |
|
247 | - $model |
|
248 | - ); |
|
249 | - $timezone = 'UTC'; |
|
250 | - } else { |
|
251 | - //so it's not a GMT field. Set the timezone on the model to the default |
|
252 | - $timezone = \EEH_DTT_Helper::get_valid_timezone_string(); |
|
253 | - } |
|
254 | - if ($field instanceof \EE_Model_Field_Base) { |
|
255 | - //did they specify an operator? |
|
256 | - if (is_array($query_param_value)) { |
|
257 | - $op = $query_param_value[0]; |
|
258 | - $translated_value = array($op); |
|
259 | - if (isset($query_param_value[1])) { |
|
260 | - $value = $query_param_value[1]; |
|
261 | - $translated_value[1] = Model_Data_Translator::prepare_field_values_from_json($field, $value, |
|
262 | - $requested_version, $timezone); |
|
263 | - } |
|
264 | - } else { |
|
265 | - $translated_value = Model_Data_Translator::prepare_field_value_from_json($field, $query_param_value, |
|
266 | - $requested_version, $timezone); |
|
267 | - } |
|
268 | - $query_param_for_models[$query_param_key] = $translated_value; |
|
269 | - } else { |
|
270 | - //so it's not for a field, assume it's a logic query param key |
|
271 | - $query_param_for_models[$query_param_key] = Model_Data_Translator::prepare_conditions_query_params_for_models($query_param_value, |
|
272 | - $model, $requested_version); |
|
273 | - } |
|
274 | - } |
|
275 | - return $query_param_for_models; |
|
276 | - } |
|
277 | - |
|
278 | - |
|
279 | - |
|
280 | - /** |
|
281 | - * Mostly checks if the last 4 characters are "_gmt", indicating its a |
|
282 | - * gmt date field name |
|
283 | - * |
|
284 | - * @param string $field_name |
|
285 | - * @return boolean |
|
286 | - */ |
|
287 | - public static function is_gmt_date_field_name($field_name) |
|
288 | - { |
|
289 | - return substr( |
|
290 | - Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($field_name), |
|
291 | - -4, |
|
292 | - 4 |
|
293 | - ) === '_gmt'; |
|
294 | - } |
|
295 | - |
|
296 | - |
|
297 | - |
|
298 | - /** |
|
299 | - * Removes the last "_gmt" part of a field name (and if there is no "_gmt" at the end, leave it alone) |
|
300 | - * |
|
301 | - * @param string $field_name |
|
302 | - * @return string |
|
303 | - */ |
|
304 | - public static function remove_gmt_from_field_name($field_name) |
|
305 | - { |
|
306 | - if (! Model_Data_Translator::is_gmt_date_field_name($field_name)) { |
|
307 | - return $field_name; |
|
308 | - } |
|
309 | - $query_param_sans_stars = Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($field_name); |
|
310 | - $query_param_sans_gmt_and_sans_stars = substr( |
|
311 | - $query_param_sans_stars, |
|
312 | - 0, |
|
313 | - strrpos( |
|
314 | - $field_name, |
|
315 | - '_gmt' |
|
316 | - ) |
|
317 | - ); |
|
318 | - return str_replace($query_param_sans_stars, $query_param_sans_gmt_and_sans_stars, $field_name); |
|
319 | - } |
|
320 | - |
|
321 | - |
|
322 | - |
|
323 | - /** |
|
324 | - * Takes a field name from the REST API and prepares it for the model querying |
|
325 | - * |
|
326 | - * @param string $field_name |
|
327 | - * @return string |
|
328 | - */ |
|
329 | - public static function prepare_field_name_from_json($field_name) |
|
330 | - { |
|
331 | - if (Model_Data_Translator::is_gmt_date_field_name($field_name)) { |
|
332 | - return Model_Data_Translator::remove_gmt_from_field_name($field_name); |
|
333 | - } |
|
334 | - return $field_name; |
|
335 | - } |
|
336 | - |
|
337 | - |
|
338 | - |
|
339 | - /** |
|
340 | - * Takes array of field names from REST API and prepares for models |
|
341 | - * |
|
342 | - * @param array $field_names |
|
343 | - * @return array of field names (possibly include model prefixes) |
|
344 | - */ |
|
345 | - public static function prepare_field_names_from_json(array $field_names) |
|
346 | - { |
|
347 | - $new_array = array(); |
|
348 | - foreach ($field_names as $key => $field_name) { |
|
349 | - $new_array[$key] = Model_Data_Translator::prepare_field_name_from_json($field_name); |
|
350 | - } |
|
351 | - return $new_array; |
|
352 | - } |
|
353 | - |
|
354 | - |
|
355 | - |
|
356 | - /** |
|
357 | - * Takes array where array keys are field names (possibly with model path prefixes) |
|
358 | - * from the REST API and prepares them for model querying |
|
359 | - * |
|
360 | - * @param array $field_names_as_keys |
|
361 | - * @return array |
|
362 | - */ |
|
363 | - public static function prepare_field_names_in_array_keys_from_json(array $field_names_as_keys) |
|
364 | - { |
|
365 | - $new_array = array(); |
|
366 | - foreach ($field_names_as_keys as $field_name => $value) { |
|
367 | - $new_array[Model_Data_Translator::prepare_field_name_from_json($field_name)] = $value; |
|
368 | - } |
|
369 | - return $new_array; |
|
370 | - } |
|
371 | - |
|
372 | - |
|
373 | - |
|
374 | - /** |
|
375 | - * Prepares an array of model query params for use in the REST API |
|
376 | - * |
|
377 | - * @param array $model_query_params |
|
378 | - * @param \EEM_Base $model |
|
379 | - * @param string $requested_version eg "4.8.36". If null is provided, defaults to the latest release of the EE4 |
|
380 | - * REST API |
|
381 | - * @return array which can be passed into the EE4 REST API when querying a model resource |
|
382 | - * @throws \EE_Error |
|
383 | - */ |
|
384 | - public static function prepare_query_params_for_rest_api( |
|
385 | - array $model_query_params, |
|
386 | - \EEM_Base $model, |
|
387 | - $requested_version = null |
|
388 | - ) { |
|
389 | - if ($requested_version === null) { |
|
390 | - $requested_version = \EED_Core_Rest_Api::latest_rest_api_version(); |
|
391 | - } |
|
392 | - $rest_query_params = $model_query_params; |
|
393 | - if (isset($model_query_params[0])) { |
|
394 | - $rest_query_params['where'] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api( |
|
395 | - $model_query_params[0], |
|
396 | - $model, |
|
397 | - $requested_version |
|
398 | - ); |
|
399 | - unset($rest_query_params[0]); |
|
400 | - } |
|
401 | - if (isset($model_query_params['having'])) { |
|
402 | - $rest_query_params['having'] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api( |
|
403 | - $model_query_params['having'], |
|
404 | - $model, |
|
405 | - $requested_version |
|
406 | - ); |
|
407 | - } |
|
408 | - return apply_filters('FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_query_params_for_rest_api', |
|
409 | - $rest_query_params, $model_query_params, $model, $requested_version); |
|
410 | - } |
|
411 | - |
|
412 | - |
|
413 | - |
|
414 | - /** |
|
415 | - * Prepares all the sub-conditions query parameters (eg having or where conditions) for use in the rest api |
|
416 | - * |
|
417 | - * @param array $inputted_query_params_of_this_type eg like the "where" or "having" conditions query params |
|
418 | - * passed into EEM_Base::get_all() |
|
419 | - * @param \EEM_Base $model |
|
420 | - * @param string $requested_version eg "4.8.36" |
|
421 | - * @return array ready for use in the rest api query params |
|
422 | - * @throws \EE_Error |
|
423 | - */ |
|
424 | - public static function prepare_conditions_query_params_for_rest_api( |
|
425 | - $inputted_query_params_of_this_type, |
|
426 | - \EEM_Base $model, |
|
427 | - $requested_version |
|
428 | - ) { |
|
429 | - $query_param_for_models = array(); |
|
430 | - foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) { |
|
431 | - $field = Model_Data_Translator::deduce_field_from_query_param( |
|
432 | - Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($query_param_key), |
|
433 | - $model |
|
434 | - ); |
|
435 | - if ($field instanceof \EE_Model_Field_Base) { |
|
436 | - //did they specify an operator? |
|
437 | - if (is_array($query_param_value)) { |
|
438 | - $op = $query_param_value[0]; |
|
439 | - $translated_value = array($op); |
|
440 | - if (isset($query_param_value[1])) { |
|
441 | - $value = $query_param_value[1]; |
|
442 | - $translated_value[1] = Model_Data_Translator::prepare_field_values_for_json($field, $value, |
|
443 | - $requested_version); |
|
444 | - } |
|
445 | - } else { |
|
446 | - $translated_value = Model_Data_Translator::prepare_field_value_for_json($field, $query_param_value, |
|
447 | - $requested_version); |
|
448 | - } |
|
449 | - $query_param_for_models[$query_param_key] = $translated_value; |
|
450 | - } else { |
|
451 | - //so it's not for a field, assume it's a logic query param key |
|
452 | - $query_param_for_models[$query_param_key] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api($query_param_value, |
|
453 | - $model, $requested_version); |
|
454 | - } |
|
455 | - } |
|
456 | - return $query_param_for_models; |
|
457 | - } |
|
458 | - |
|
459 | - |
|
460 | - |
|
461 | - /** |
|
462 | - * @param $condition_query_param_key |
|
463 | - * @return string |
|
464 | - */ |
|
465 | - public static function remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key) |
|
466 | - { |
|
467 | - $pos_of_star = strpos($condition_query_param_key, '*'); |
|
468 | - if ($pos_of_star === false) { |
|
469 | - return $condition_query_param_key; |
|
470 | - } else { |
|
471 | - $condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star); |
|
472 | - return $condition_query_param_sans_star; |
|
473 | - } |
|
474 | - } |
|
475 | - |
|
476 | - |
|
477 | - |
|
478 | - /** |
|
479 | - * Takes the input parameter and finds the model field that it indicates. |
|
480 | - * |
|
481 | - * @param string $query_param_name like Registration.Transaction.TXN_ID, Event.Datetime.start_time, or REG_ID |
|
482 | - * @param \EEM_Base $model |
|
483 | - * @return \EE_Model_Field_Base |
|
484 | - * @throws \EE_Error |
|
485 | - */ |
|
486 | - public static function deduce_field_from_query_param($query_param_name, \EEM_Base $model) |
|
487 | - { |
|
488 | - //ok, now proceed with deducing which part is the model's name, and which is the field's name |
|
489 | - //which will help us find the database table and column |
|
490 | - $query_param_parts = explode('.', $query_param_name); |
|
491 | - if (empty($query_param_parts)) { |
|
492 | - throw new \EE_Error(sprintf(__('_extract_column_name is empty when trying to extract column and table name from %s', |
|
493 | - 'event_espresso'), $query_param_name)); |
|
494 | - } |
|
495 | - $number_of_parts = count($query_param_parts); |
|
496 | - $last_query_param_part = $query_param_parts[count($query_param_parts) - 1]; |
|
497 | - if ($number_of_parts === 1) { |
|
498 | - $field_name = $last_query_param_part; |
|
499 | - } else {// $number_of_parts >= 2 |
|
500 | - //the last part is the column name, and there are only 2parts. therefore... |
|
501 | - $field_name = $last_query_param_part; |
|
502 | - $model = \EE_Registry::instance()->load_model($query_param_parts[$number_of_parts - 2]); |
|
503 | - } |
|
504 | - try { |
|
505 | - return $model->field_settings_for($field_name); |
|
506 | - } catch (\EE_Error $e) { |
|
507 | - return null; |
|
508 | - } |
|
509 | - } |
|
30 | + /** |
|
31 | + * We used to use -1 for infinity in the rest api, but that's ambiguous for |
|
32 | + * fields that COULD contain -1; so we use null |
|
33 | + */ |
|
34 | + const ee_inf_in_rest = null; |
|
35 | + |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * Prepares a possible array of input values from JSON for use by the models |
|
40 | + * |
|
41 | + * @param \EE_Model_Field_Base $field_obj |
|
42 | + * @param mixed $original_value_maybe_array |
|
43 | + * @param string $requested_version |
|
44 | + * @param string $timezone_string treat values as being in this timezone |
|
45 | + * @return mixed |
|
46 | + * @throws \DomainException |
|
47 | + */ |
|
48 | + public static function prepare_field_values_from_json( |
|
49 | + $field_obj, |
|
50 | + $original_value_maybe_array, |
|
51 | + $requested_version, |
|
52 | + $timezone_string = 'UTC' |
|
53 | + ) { |
|
54 | + if (is_array($original_value_maybe_array)) { |
|
55 | + $new_value_maybe_array = array(); |
|
56 | + foreach ($original_value_maybe_array as $array_key => $array_item) { |
|
57 | + $new_value_maybe_array[$array_key] = Model_Data_Translator::prepare_field_value_from_json( |
|
58 | + $field_obj, |
|
59 | + $array_item, |
|
60 | + $requested_version, |
|
61 | + $timezone_string |
|
62 | + ); |
|
63 | + } |
|
64 | + } else { |
|
65 | + $new_value_maybe_array = Model_Data_Translator::prepare_field_value_from_json( |
|
66 | + $field_obj, |
|
67 | + $original_value_maybe_array, |
|
68 | + $requested_version, |
|
69 | + $timezone_string |
|
70 | + ); |
|
71 | + } |
|
72 | + return $new_value_maybe_array; |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * Prepares an array of field values FOR use in JSON/REST API |
|
79 | + * |
|
80 | + * @param \EE_Model_Field_Base $field_obj |
|
81 | + * @param mixed $original_value_maybe_array |
|
82 | + * @param string $request_version (eg 4.8.36) |
|
83 | + * @return array |
|
84 | + */ |
|
85 | + public static function prepare_field_values_for_json($field_obj, $original_value_maybe_array, $request_version) |
|
86 | + { |
|
87 | + if (is_array($original_value_maybe_array)) { |
|
88 | + $new_value_maybe_array = array(); |
|
89 | + foreach ($original_value_maybe_array as $array_key => $array_item) { |
|
90 | + $new_value_maybe_array[$array_key] = Model_Data_Translator::prepare_field_value_for_json( |
|
91 | + $field_obj, |
|
92 | + $array_item, |
|
93 | + $request_version |
|
94 | + ); |
|
95 | + } |
|
96 | + } else { |
|
97 | + $new_value_maybe_array = Model_Data_Translator::prepare_field_value_for_json( |
|
98 | + $field_obj, |
|
99 | + $original_value_maybe_array, |
|
100 | + $request_version |
|
101 | + ); |
|
102 | + } |
|
103 | + return $new_value_maybe_array; |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * Prepares incoming data from the json or $_REQUEST parameters for the models' |
|
110 | + * "$query_params". |
|
111 | + * |
|
112 | + * @param \EE_Model_Field_Base $field_obj |
|
113 | + * @param mixed $original_value |
|
114 | + * @param string $requested_version |
|
115 | + * @param string $timezone_string treat values as being in this timezone |
|
116 | + * @return mixed |
|
117 | + * @throws \DomainException |
|
118 | + */ |
|
119 | + public static function prepare_field_value_from_json( |
|
120 | + $field_obj, |
|
121 | + $original_value, |
|
122 | + $requested_version, |
|
123 | + $timezone_string = 'UTC' // UTC |
|
124 | + ) |
|
125 | + { |
|
126 | + $timezone_string = $timezone_string !== '' ? $timezone_string : get_option('timezone_string', ''); |
|
127 | + $new_value = null; |
|
128 | + if ($field_obj instanceof \EE_Infinite_Integer_Field |
|
129 | + && in_array($original_value, array(null, ''), true) |
|
130 | + ) { |
|
131 | + $new_value = EE_INF; |
|
132 | + } elseif ($field_obj instanceof \EE_Datetime_Field) { |
|
133 | + list($offset_sign, $offset_secs) = Model_Data_Translator::parse_timezone_offset( |
|
134 | + $field_obj->get_timezone_offset( |
|
135 | + new \DateTimeZone($timezone_string) |
|
136 | + ) |
|
137 | + ); |
|
138 | + $offset_string = |
|
139 | + str_pad( |
|
140 | + floor($offset_secs / HOUR_IN_SECONDS), |
|
141 | + 2, |
|
142 | + '0', |
|
143 | + STR_PAD_LEFT |
|
144 | + ) |
|
145 | + . ':' |
|
146 | + . str_pad( |
|
147 | + ($offset_secs % HOUR_IN_SECONDS) / MINUTE_IN_SECONDS, |
|
148 | + 2, |
|
149 | + '0', |
|
150 | + STR_PAD_LEFT |
|
151 | + ); |
|
152 | + $new_value = rest_parse_date($original_value . $offset_sign . $offset_string); |
|
153 | + } else { |
|
154 | + $new_value = $original_value; |
|
155 | + } |
|
156 | + return $new_value; |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * determines what's going on with them timezone strings |
|
163 | + * |
|
164 | + * @param int $timezone_offset |
|
165 | + * @return array |
|
166 | + */ |
|
167 | + private static function parse_timezone_offset($timezone_offset) |
|
168 | + { |
|
169 | + $first_char = substr((string)$timezone_offset, 0, 1); |
|
170 | + if ($first_char === '+' || $first_char === '-') { |
|
171 | + $offset_sign = $first_char; |
|
172 | + $offset_secs = substr((string)$timezone_offset, 1); |
|
173 | + } else { |
|
174 | + $offset_sign = '+'; |
|
175 | + $offset_secs = $timezone_offset; |
|
176 | + } |
|
177 | + return array($offset_sign, $offset_secs); |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * Prepares a field's value for display in the API |
|
184 | + * |
|
185 | + * @param \EE_Model_Field_Base $field_obj |
|
186 | + * @param mixed $original_value |
|
187 | + * @param string $requested_version |
|
188 | + * @return mixed |
|
189 | + */ |
|
190 | + public static function prepare_field_value_for_json($field_obj, $original_value, $requested_version) |
|
191 | + { |
|
192 | + if ($original_value === EE_INF) { |
|
193 | + $new_value = Model_Data_Translator::ee_inf_in_rest; |
|
194 | + } elseif ($field_obj instanceof \EE_Datetime_Field) { |
|
195 | + if ($original_value instanceof \DateTime) { |
|
196 | + $new_value = $original_value->format('Y-m-d H:i:s'); |
|
197 | + } elseif (is_int($original_value)) { |
|
198 | + $new_value = date('Y-m-d H:i:s', $original_value); |
|
199 | + } else { |
|
200 | + $new_value = $original_value; |
|
201 | + } |
|
202 | + $new_value = mysql_to_rfc3339($new_value); |
|
203 | + } else { |
|
204 | + $new_value = $original_value; |
|
205 | + } |
|
206 | + return apply_filters('FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_field_for_rest_api', |
|
207 | + $new_value, |
|
208 | + $field_obj, |
|
209 | + $original_value, |
|
210 | + $requested_version |
|
211 | + ); |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + |
|
216 | + /** |
|
217 | + * Prepares condition-query-parameters (like what's in where and having) from |
|
218 | + * the format expected in the API to use in the models |
|
219 | + * |
|
220 | + * @param array $inputted_query_params_of_this_type |
|
221 | + * @param \EEM_Base $model |
|
222 | + * @param string $requested_version |
|
223 | + * @return array |
|
224 | + * @throws \DomainException |
|
225 | + * @throws \EE_Error |
|
226 | + */ |
|
227 | + public static function prepare_conditions_query_params_for_models( |
|
228 | + $inputted_query_params_of_this_type, |
|
229 | + \EEM_Base $model, |
|
230 | + $requested_version |
|
231 | + ) { |
|
232 | + $query_param_for_models = array(); |
|
233 | + foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) { |
|
234 | + $query_param_sans_stars = Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($query_param_key); |
|
235 | + $field = Model_Data_Translator::deduce_field_from_query_param( |
|
236 | + $query_param_sans_stars, |
|
237 | + $model |
|
238 | + ); |
|
239 | + //double-check is it a *_gmt field? |
|
240 | + if (! $field instanceof \EE_Model_Field_Base |
|
241 | + && Model_Data_Translator::is_gmt_date_field_name($query_param_sans_stars) |
|
242 | + ) { |
|
243 | + //yep, take off '_gmt', and find the field |
|
244 | + $query_param_key = Model_Data_Translator::remove_gmt_from_field_name($query_param_sans_stars); |
|
245 | + $field = Model_Data_Translator::deduce_field_from_query_param( |
|
246 | + $query_param_key, |
|
247 | + $model |
|
248 | + ); |
|
249 | + $timezone = 'UTC'; |
|
250 | + } else { |
|
251 | + //so it's not a GMT field. Set the timezone on the model to the default |
|
252 | + $timezone = \EEH_DTT_Helper::get_valid_timezone_string(); |
|
253 | + } |
|
254 | + if ($field instanceof \EE_Model_Field_Base) { |
|
255 | + //did they specify an operator? |
|
256 | + if (is_array($query_param_value)) { |
|
257 | + $op = $query_param_value[0]; |
|
258 | + $translated_value = array($op); |
|
259 | + if (isset($query_param_value[1])) { |
|
260 | + $value = $query_param_value[1]; |
|
261 | + $translated_value[1] = Model_Data_Translator::prepare_field_values_from_json($field, $value, |
|
262 | + $requested_version, $timezone); |
|
263 | + } |
|
264 | + } else { |
|
265 | + $translated_value = Model_Data_Translator::prepare_field_value_from_json($field, $query_param_value, |
|
266 | + $requested_version, $timezone); |
|
267 | + } |
|
268 | + $query_param_for_models[$query_param_key] = $translated_value; |
|
269 | + } else { |
|
270 | + //so it's not for a field, assume it's a logic query param key |
|
271 | + $query_param_for_models[$query_param_key] = Model_Data_Translator::prepare_conditions_query_params_for_models($query_param_value, |
|
272 | + $model, $requested_version); |
|
273 | + } |
|
274 | + } |
|
275 | + return $query_param_for_models; |
|
276 | + } |
|
277 | + |
|
278 | + |
|
279 | + |
|
280 | + /** |
|
281 | + * Mostly checks if the last 4 characters are "_gmt", indicating its a |
|
282 | + * gmt date field name |
|
283 | + * |
|
284 | + * @param string $field_name |
|
285 | + * @return boolean |
|
286 | + */ |
|
287 | + public static function is_gmt_date_field_name($field_name) |
|
288 | + { |
|
289 | + return substr( |
|
290 | + Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($field_name), |
|
291 | + -4, |
|
292 | + 4 |
|
293 | + ) === '_gmt'; |
|
294 | + } |
|
295 | + |
|
296 | + |
|
297 | + |
|
298 | + /** |
|
299 | + * Removes the last "_gmt" part of a field name (and if there is no "_gmt" at the end, leave it alone) |
|
300 | + * |
|
301 | + * @param string $field_name |
|
302 | + * @return string |
|
303 | + */ |
|
304 | + public static function remove_gmt_from_field_name($field_name) |
|
305 | + { |
|
306 | + if (! Model_Data_Translator::is_gmt_date_field_name($field_name)) { |
|
307 | + return $field_name; |
|
308 | + } |
|
309 | + $query_param_sans_stars = Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($field_name); |
|
310 | + $query_param_sans_gmt_and_sans_stars = substr( |
|
311 | + $query_param_sans_stars, |
|
312 | + 0, |
|
313 | + strrpos( |
|
314 | + $field_name, |
|
315 | + '_gmt' |
|
316 | + ) |
|
317 | + ); |
|
318 | + return str_replace($query_param_sans_stars, $query_param_sans_gmt_and_sans_stars, $field_name); |
|
319 | + } |
|
320 | + |
|
321 | + |
|
322 | + |
|
323 | + /** |
|
324 | + * Takes a field name from the REST API and prepares it for the model querying |
|
325 | + * |
|
326 | + * @param string $field_name |
|
327 | + * @return string |
|
328 | + */ |
|
329 | + public static function prepare_field_name_from_json($field_name) |
|
330 | + { |
|
331 | + if (Model_Data_Translator::is_gmt_date_field_name($field_name)) { |
|
332 | + return Model_Data_Translator::remove_gmt_from_field_name($field_name); |
|
333 | + } |
|
334 | + return $field_name; |
|
335 | + } |
|
336 | + |
|
337 | + |
|
338 | + |
|
339 | + /** |
|
340 | + * Takes array of field names from REST API and prepares for models |
|
341 | + * |
|
342 | + * @param array $field_names |
|
343 | + * @return array of field names (possibly include model prefixes) |
|
344 | + */ |
|
345 | + public static function prepare_field_names_from_json(array $field_names) |
|
346 | + { |
|
347 | + $new_array = array(); |
|
348 | + foreach ($field_names as $key => $field_name) { |
|
349 | + $new_array[$key] = Model_Data_Translator::prepare_field_name_from_json($field_name); |
|
350 | + } |
|
351 | + return $new_array; |
|
352 | + } |
|
353 | + |
|
354 | + |
|
355 | + |
|
356 | + /** |
|
357 | + * Takes array where array keys are field names (possibly with model path prefixes) |
|
358 | + * from the REST API and prepares them for model querying |
|
359 | + * |
|
360 | + * @param array $field_names_as_keys |
|
361 | + * @return array |
|
362 | + */ |
|
363 | + public static function prepare_field_names_in_array_keys_from_json(array $field_names_as_keys) |
|
364 | + { |
|
365 | + $new_array = array(); |
|
366 | + foreach ($field_names_as_keys as $field_name => $value) { |
|
367 | + $new_array[Model_Data_Translator::prepare_field_name_from_json($field_name)] = $value; |
|
368 | + } |
|
369 | + return $new_array; |
|
370 | + } |
|
371 | + |
|
372 | + |
|
373 | + |
|
374 | + /** |
|
375 | + * Prepares an array of model query params for use in the REST API |
|
376 | + * |
|
377 | + * @param array $model_query_params |
|
378 | + * @param \EEM_Base $model |
|
379 | + * @param string $requested_version eg "4.8.36". If null is provided, defaults to the latest release of the EE4 |
|
380 | + * REST API |
|
381 | + * @return array which can be passed into the EE4 REST API when querying a model resource |
|
382 | + * @throws \EE_Error |
|
383 | + */ |
|
384 | + public static function prepare_query_params_for_rest_api( |
|
385 | + array $model_query_params, |
|
386 | + \EEM_Base $model, |
|
387 | + $requested_version = null |
|
388 | + ) { |
|
389 | + if ($requested_version === null) { |
|
390 | + $requested_version = \EED_Core_Rest_Api::latest_rest_api_version(); |
|
391 | + } |
|
392 | + $rest_query_params = $model_query_params; |
|
393 | + if (isset($model_query_params[0])) { |
|
394 | + $rest_query_params['where'] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api( |
|
395 | + $model_query_params[0], |
|
396 | + $model, |
|
397 | + $requested_version |
|
398 | + ); |
|
399 | + unset($rest_query_params[0]); |
|
400 | + } |
|
401 | + if (isset($model_query_params['having'])) { |
|
402 | + $rest_query_params['having'] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api( |
|
403 | + $model_query_params['having'], |
|
404 | + $model, |
|
405 | + $requested_version |
|
406 | + ); |
|
407 | + } |
|
408 | + return apply_filters('FHEE__EventEspresso\core\libraries\rest_api\Model_Data_Translator__prepare_query_params_for_rest_api', |
|
409 | + $rest_query_params, $model_query_params, $model, $requested_version); |
|
410 | + } |
|
411 | + |
|
412 | + |
|
413 | + |
|
414 | + /** |
|
415 | + * Prepares all the sub-conditions query parameters (eg having or where conditions) for use in the rest api |
|
416 | + * |
|
417 | + * @param array $inputted_query_params_of_this_type eg like the "where" or "having" conditions query params |
|
418 | + * passed into EEM_Base::get_all() |
|
419 | + * @param \EEM_Base $model |
|
420 | + * @param string $requested_version eg "4.8.36" |
|
421 | + * @return array ready for use in the rest api query params |
|
422 | + * @throws \EE_Error |
|
423 | + */ |
|
424 | + public static function prepare_conditions_query_params_for_rest_api( |
|
425 | + $inputted_query_params_of_this_type, |
|
426 | + \EEM_Base $model, |
|
427 | + $requested_version |
|
428 | + ) { |
|
429 | + $query_param_for_models = array(); |
|
430 | + foreach ($inputted_query_params_of_this_type as $query_param_key => $query_param_value) { |
|
431 | + $field = Model_Data_Translator::deduce_field_from_query_param( |
|
432 | + Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($query_param_key), |
|
433 | + $model |
|
434 | + ); |
|
435 | + if ($field instanceof \EE_Model_Field_Base) { |
|
436 | + //did they specify an operator? |
|
437 | + if (is_array($query_param_value)) { |
|
438 | + $op = $query_param_value[0]; |
|
439 | + $translated_value = array($op); |
|
440 | + if (isset($query_param_value[1])) { |
|
441 | + $value = $query_param_value[1]; |
|
442 | + $translated_value[1] = Model_Data_Translator::prepare_field_values_for_json($field, $value, |
|
443 | + $requested_version); |
|
444 | + } |
|
445 | + } else { |
|
446 | + $translated_value = Model_Data_Translator::prepare_field_value_for_json($field, $query_param_value, |
|
447 | + $requested_version); |
|
448 | + } |
|
449 | + $query_param_for_models[$query_param_key] = $translated_value; |
|
450 | + } else { |
|
451 | + //so it's not for a field, assume it's a logic query param key |
|
452 | + $query_param_for_models[$query_param_key] = Model_Data_Translator::prepare_conditions_query_params_for_rest_api($query_param_value, |
|
453 | + $model, $requested_version); |
|
454 | + } |
|
455 | + } |
|
456 | + return $query_param_for_models; |
|
457 | + } |
|
458 | + |
|
459 | + |
|
460 | + |
|
461 | + /** |
|
462 | + * @param $condition_query_param_key |
|
463 | + * @return string |
|
464 | + */ |
|
465 | + public static function remove_stars_and_anything_after_from_condition_query_param_key($condition_query_param_key) |
|
466 | + { |
|
467 | + $pos_of_star = strpos($condition_query_param_key, '*'); |
|
468 | + if ($pos_of_star === false) { |
|
469 | + return $condition_query_param_key; |
|
470 | + } else { |
|
471 | + $condition_query_param_sans_star = substr($condition_query_param_key, 0, $pos_of_star); |
|
472 | + return $condition_query_param_sans_star; |
|
473 | + } |
|
474 | + } |
|
475 | + |
|
476 | + |
|
477 | + |
|
478 | + /** |
|
479 | + * Takes the input parameter and finds the model field that it indicates. |
|
480 | + * |
|
481 | + * @param string $query_param_name like Registration.Transaction.TXN_ID, Event.Datetime.start_time, or REG_ID |
|
482 | + * @param \EEM_Base $model |
|
483 | + * @return \EE_Model_Field_Base |
|
484 | + * @throws \EE_Error |
|
485 | + */ |
|
486 | + public static function deduce_field_from_query_param($query_param_name, \EEM_Base $model) |
|
487 | + { |
|
488 | + //ok, now proceed with deducing which part is the model's name, and which is the field's name |
|
489 | + //which will help us find the database table and column |
|
490 | + $query_param_parts = explode('.', $query_param_name); |
|
491 | + if (empty($query_param_parts)) { |
|
492 | + throw new \EE_Error(sprintf(__('_extract_column_name is empty when trying to extract column and table name from %s', |
|
493 | + 'event_espresso'), $query_param_name)); |
|
494 | + } |
|
495 | + $number_of_parts = count($query_param_parts); |
|
496 | + $last_query_param_part = $query_param_parts[count($query_param_parts) - 1]; |
|
497 | + if ($number_of_parts === 1) { |
|
498 | + $field_name = $last_query_param_part; |
|
499 | + } else {// $number_of_parts >= 2 |
|
500 | + //the last part is the column name, and there are only 2parts. therefore... |
|
501 | + $field_name = $last_query_param_part; |
|
502 | + $model = \EE_Registry::instance()->load_model($query_param_parts[$number_of_parts - 2]); |
|
503 | + } |
|
504 | + try { |
|
505 | + return $model->field_settings_for($field_name); |
|
506 | + } catch (\EE_Error $e) { |
|
507 | + return null; |
|
508 | + } |
|
509 | + } |
|
510 | 510 | |
511 | 511 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | namespace EventEspresso\core\libraries\rest_api; |
3 | 3 | |
4 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
4 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
5 | 5 | exit('No direct script access allowed'); |
6 | 6 | } |
7 | 7 | |
@@ -149,7 +149,7 @@ discard block |
||
149 | 149 | '0', |
150 | 150 | STR_PAD_LEFT |
151 | 151 | ); |
152 | - $new_value = rest_parse_date($original_value . $offset_sign . $offset_string); |
|
152 | + $new_value = rest_parse_date($original_value.$offset_sign.$offset_string); |
|
153 | 153 | } else { |
154 | 154 | $new_value = $original_value; |
155 | 155 | } |
@@ -166,10 +166,10 @@ discard block |
||
166 | 166 | */ |
167 | 167 | private static function parse_timezone_offset($timezone_offset) |
168 | 168 | { |
169 | - $first_char = substr((string)$timezone_offset, 0, 1); |
|
169 | + $first_char = substr((string) $timezone_offset, 0, 1); |
|
170 | 170 | if ($first_char === '+' || $first_char === '-') { |
171 | 171 | $offset_sign = $first_char; |
172 | - $offset_secs = substr((string)$timezone_offset, 1); |
|
172 | + $offset_secs = substr((string) $timezone_offset, 1); |
|
173 | 173 | } else { |
174 | 174 | $offset_sign = '+'; |
175 | 175 | $offset_secs = $timezone_offset; |
@@ -237,7 +237,7 @@ discard block |
||
237 | 237 | $model |
238 | 238 | ); |
239 | 239 | //double-check is it a *_gmt field? |
240 | - if (! $field instanceof \EE_Model_Field_Base |
|
240 | + if ( ! $field instanceof \EE_Model_Field_Base |
|
241 | 241 | && Model_Data_Translator::is_gmt_date_field_name($query_param_sans_stars) |
242 | 242 | ) { |
243 | 243 | //yep, take off '_gmt', and find the field |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | */ |
304 | 304 | public static function remove_gmt_from_field_name($field_name) |
305 | 305 | { |
306 | - if (! Model_Data_Translator::is_gmt_date_field_name($field_name)) { |
|
306 | + if ( ! Model_Data_Translator::is_gmt_date_field_name($field_name)) { |
|
307 | 307 | return $field_name; |
308 | 308 | } |
309 | 309 | $query_param_sans_stars = Model_Data_Translator::remove_stars_and_anything_after_from_condition_query_param_key($field_name); |