@@ -459,7 +459,7 @@ discard block |
||
459 | 459 | * there's a single shared message template group among all the events. Otherwise it returns null. |
460 | 460 | * |
461 | 461 | * @param array $event_ids |
462 | - * @return EE_Message_Template_Group|null |
|
462 | + * @return null|EE_Base_Class |
|
463 | 463 | * @throws EE_Error |
464 | 464 | * @throws InvalidArgumentException |
465 | 465 | * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
@@ -495,7 +495,7 @@ discard block |
||
495 | 495 | /** |
496 | 496 | * Retrieves the global message template group for the current messenger and message type. |
497 | 497 | * |
498 | - * @return EE_Message_Template_Group|null |
|
498 | + * @return null|EE_Base_Class |
|
499 | 499 | * @throws EE_Error |
500 | 500 | * @throws InvalidArgumentException |
501 | 501 | * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
@@ -641,7 +641,7 @@ discard block |
||
641 | 641 | * @param EE_Messages_Addressee $recipient |
642 | 642 | * @param array $templates formatted array of templates used for parsing data. |
643 | 643 | * @param EE_Message_Template_Group $message_template_group |
644 | - * @return bool|EE_Message |
|
644 | + * @return EE_Message |
|
645 | 645 | * @throws EE_Error |
646 | 646 | */ |
647 | 647 | protected function _setup_message_object( |
@@ -12,973 +12,973 @@ |
||
12 | 12 | { |
13 | 13 | |
14 | 14 | |
15 | - /** |
|
16 | - * @type EE_Messages_Data_Handler_Collection |
|
17 | - */ |
|
18 | - protected $_data_handler_collection; |
|
19 | - |
|
20 | - /** |
|
21 | - * @type EE_Message_Template_Group_Collection |
|
22 | - */ |
|
23 | - protected $_template_collection; |
|
24 | - |
|
25 | - /** |
|
26 | - * This will hold the data handler for the current EE_Message being generated. |
|
27 | - * |
|
28 | - * @type EE_Messages_incoming_data |
|
29 | - */ |
|
30 | - protected $_current_data_handler; |
|
31 | - |
|
32 | - /** |
|
33 | - * This holds the EE_Messages_Queue that contains the messages to generate. |
|
34 | - * |
|
35 | - * @type EE_Messages_Queue |
|
36 | - */ |
|
37 | - protected $_generation_queue; |
|
38 | - |
|
39 | - /** |
|
40 | - * This holds the EE_Messages_Queue that will store the generated EE_Message objects. |
|
41 | - * |
|
42 | - * @type EE_Messages_Queue |
|
43 | - */ |
|
44 | - protected $_ready_queue; |
|
45 | - |
|
46 | - /** |
|
47 | - * This is a container for any error messages that get created through the generation |
|
48 | - * process. |
|
49 | - * |
|
50 | - * @type array |
|
51 | - */ |
|
52 | - protected $_error_msg = array(); |
|
53 | - |
|
54 | - /** |
|
55 | - * Flag used to set when the current EE_Message in the generation queue has been verified. |
|
56 | - * |
|
57 | - * @type bool |
|
58 | - */ |
|
59 | - protected $_verified = false; |
|
60 | - |
|
61 | - /** |
|
62 | - * This will hold the current messenger object corresponding with the current EE_Message in the generation queue. |
|
63 | - * |
|
64 | - * @type EE_messenger |
|
65 | - */ |
|
66 | - protected $_current_messenger; |
|
67 | - |
|
68 | - /** |
|
69 | - * This will hold the current message type object corresponding with the current EE_Message in the generation queue. |
|
70 | - * |
|
71 | - * @type EE_message_type |
|
72 | - */ |
|
73 | - protected $_current_message_type; |
|
74 | - |
|
75 | - /** |
|
76 | - * @type EEH_Parse_Shortcodes |
|
77 | - */ |
|
78 | - protected $_shortcode_parser; |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * @param EE_Messages_Queue $generation_queue |
|
83 | - * @param \EE_Messages_Queue $ready_queue |
|
84 | - * @param \EE_Messages_Data_Handler_Collection $data_handler_collection |
|
85 | - * @param \EE_Message_Template_Group_Collection $template_collection |
|
86 | - * @param \EEH_Parse_Shortcodes $shortcode_parser |
|
87 | - */ |
|
88 | - public function __construct( |
|
89 | - EE_Messages_Queue $generation_queue, |
|
90 | - EE_Messages_Queue $ready_queue, |
|
91 | - EE_Messages_Data_Handler_Collection $data_handler_collection, |
|
92 | - EE_Message_Template_Group_Collection $template_collection, |
|
93 | - EEH_Parse_Shortcodes $shortcode_parser |
|
94 | - ) { |
|
95 | - $this->_generation_queue = $generation_queue; |
|
96 | - $this->_ready_queue = $ready_queue; |
|
97 | - $this->_data_handler_collection = $data_handler_collection; |
|
98 | - $this->_template_collection = $template_collection; |
|
99 | - $this->_shortcode_parser = $shortcode_parser; |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * @return EE_Messages_Queue |
|
105 | - */ |
|
106 | - public function generation_queue() |
|
107 | - { |
|
108 | - return $this->_generation_queue; |
|
109 | - } |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * This iterates through the provided queue and generates the EE_Message objects. |
|
114 | - * When iterating through the queue, the queued item that served as the base for generating other EE_Message |
|
115 | - * objects gets removed and the new EE_Message objects get added to a NEW queue. The NEW queue is then returned |
|
116 | - * for the caller to decide what to do with it. |
|
117 | - * |
|
118 | - * @param bool $save Whether to save the EE_Message objects in the new queue or just return. |
|
119 | - * @return EE_Messages_Queue The new queue for holding generated EE_Message objects. |
|
120 | - * @throws EE_Error |
|
121 | - * @throws ReflectionException |
|
122 | - */ |
|
123 | - public function generate($save = true) |
|
124 | - { |
|
125 | - // iterate through the messages in the queue, generate, and add to new queue. |
|
126 | - $this->_generation_queue->get_message_repository()->rewind(); |
|
127 | - while ($this->_generation_queue->get_message_repository()->valid()) { |
|
128 | - // reset "current" properties |
|
129 | - $this->_reset_current_properties(); |
|
130 | - |
|
131 | - /** @type EE_Message $msg */ |
|
132 | - $msg = $this->_generation_queue->get_message_repository()->current(); |
|
133 | - |
|
134 | - /** |
|
135 | - * need to get the next object and capture it for setting manually after deletes. The reason is that when |
|
136 | - * an object is removed from the repo then valid for the next object will fail. |
|
137 | - */ |
|
138 | - $this->_generation_queue->get_message_repository()->next(); |
|
139 | - $next_msg = $this->_generation_queue->get_message_repository()->current(); |
|
140 | - // restore pointer to current item |
|
141 | - $this->_generation_queue->get_message_repository()->set_current($msg); |
|
142 | - |
|
143 | - // skip and delete if the current $msg is NOT incomplete (queued for generation) |
|
144 | - if ($msg->STS_ID() !== EEM_Message::status_incomplete) { |
|
145 | - // we keep this item in the db just remove from the repo. |
|
146 | - $this->_generation_queue->get_message_repository()->remove($msg); |
|
147 | - // next item |
|
148 | - $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
149 | - continue; |
|
150 | - } |
|
151 | - |
|
152 | - if ($this->_verify()) { |
|
153 | - // let's get generating! |
|
154 | - $this->_generate(); |
|
155 | - } |
|
156 | - |
|
157 | - // don't persist debug_only messages if the messages system is not in debug mode. |
|
158 | - if ($msg->STS_ID() === EEM_Message::status_debug_only |
|
159 | - && ! EEM_Message::debug() |
|
160 | - ) { |
|
161 | - do_action( |
|
162 | - 'AHEE__EE_Messages_Generator__generate__before_debug_delete', |
|
163 | - $msg, |
|
164 | - $this->_error_msg, |
|
165 | - $this->_current_messenger, |
|
166 | - $this->_current_message_type, |
|
167 | - $this->_current_data_handler |
|
168 | - ); |
|
169 | - $this->_generation_queue->get_message_repository()->delete(); |
|
170 | - $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
171 | - continue; |
|
172 | - } |
|
173 | - |
|
174 | - // if there are error messages then let's set the status and the error message. |
|
175 | - if ($this->_error_msg) { |
|
176 | - // if the status is already debug only, then let's leave it at that. |
|
177 | - if ($msg->STS_ID() !== EEM_Message::status_debug_only) { |
|
178 | - $msg->set_STS_ID(EEM_Message::status_failed); |
|
179 | - } |
|
180 | - do_action( |
|
181 | - 'AHEE__EE_Messages_Generator__generate__processing_failed_message', |
|
182 | - $msg, |
|
183 | - $this->_error_msg, |
|
184 | - $this->_current_messenger, |
|
185 | - $this->_current_message_type, |
|
186 | - $this->_current_data_handler |
|
187 | - ); |
|
188 | - $msg->set_error_message( |
|
189 | - esc_html__('Message failed to generate for the following reasons: ', 'event_espresso') |
|
190 | - . "\n" |
|
191 | - . implode("\n", $this->_error_msg) |
|
192 | - ); |
|
193 | - $msg->set_modified(time()); |
|
194 | - } else { |
|
195 | - do_action( |
|
196 | - 'AHEE__EE_Messages_Generator__generate__before_successful_generated_message_delete', |
|
197 | - $msg, |
|
198 | - $this->_error_msg, |
|
199 | - $this->_current_messenger, |
|
200 | - $this->_current_message_type, |
|
201 | - $this->_current_data_handler |
|
202 | - ); |
|
203 | - // remove from db |
|
204 | - $this->_generation_queue->get_message_repository()->delete(); |
|
205 | - } |
|
206 | - // next item |
|
207 | - $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
208 | - } |
|
209 | - |
|
210 | - // generation queue is ALWAYS saved to record any errors in the generation process. |
|
211 | - $this->_generation_queue->save(); |
|
212 | - |
|
213 | - /** |
|
214 | - * save _ready_queue if flag set. |
|
215 | - * Note: The EE_Message objects have values set via the EE_Base_Class::set_field_or_extra_meta() method. This |
|
216 | - * means if a field was added that is not a valid database column. The EE_Message was already saved to the db |
|
217 | - * so a EE_Extra_Meta entry could be created and attached to the EE_Message. In those cases the save flag is |
|
218 | - * irrelevant. |
|
219 | - */ |
|
220 | - if ($save) { |
|
221 | - $this->_ready_queue->save(); |
|
222 | - } |
|
223 | - |
|
224 | - // final reset of properties |
|
225 | - $this->_reset_current_properties(); |
|
226 | - |
|
227 | - return $this->_ready_queue; |
|
228 | - } |
|
229 | - |
|
230 | - |
|
231 | - /** |
|
232 | - * This resets all the properties used for holding "current" values corresponding to the current EE_Message object |
|
233 | - * in the generation queue. |
|
234 | - */ |
|
235 | - protected function _reset_current_properties() |
|
236 | - { |
|
237 | - $this->_verified = false; |
|
238 | - // make sure any _data value in the current message type is reset |
|
239 | - if ($this->_current_message_type instanceof EE_message_type) { |
|
240 | - $this->_current_message_type->reset_data(); |
|
241 | - } |
|
242 | - $this->_current_messenger = $this->_current_message_type = $this->_current_data_handler = null; |
|
243 | - } |
|
244 | - |
|
245 | - |
|
246 | - /** |
|
247 | - * This proceeds with the actual generation of a message. By the time this is called, there should already be a |
|
248 | - * $_current_data_handler set and all incoming information should be validated for the current EE_Message in the |
|
249 | - * _generating_queue. |
|
250 | - * |
|
251 | - * @return bool Whether the message was successfully generated or not. |
|
252 | - * @throws EE_Error |
|
253 | - * @throws InvalidArgumentException |
|
254 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
255 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
256 | - */ |
|
257 | - protected function _generate() |
|
258 | - { |
|
259 | - // double check verification has run and that everything is ready to work with (saves us having to validate |
|
260 | - // everything again). |
|
261 | - if (! $this->_verified) { |
|
262 | - return false; // get out because we don't have a valid setup to work with. |
|
263 | - } |
|
264 | - |
|
265 | - |
|
266 | - try { |
|
267 | - $addressees = $this->_current_message_type->get_addressees( |
|
268 | - $this->_current_data_handler, |
|
269 | - $this->_generation_queue->get_message_repository()->current()->context() |
|
270 | - ); |
|
271 | - } catch (EE_Error $e) { |
|
272 | - $this->_error_msg[] = $e->getMessage(); |
|
273 | - return false; |
|
274 | - } |
|
275 | - |
|
276 | - |
|
277 | - // if no addressees then get out because there is nothing to generation (possible bad data). |
|
278 | - if (! $this->_valid_addressees($addressees)) { |
|
279 | - do_action( |
|
280 | - 'AHEE__EE_Messages_Generator___generate__invalid_addressees', |
|
281 | - $this->_generation_queue->get_message_repository()->current(), |
|
282 | - $addressees, |
|
283 | - $this->_current_messenger, |
|
284 | - $this->_current_message_type, |
|
285 | - $this->_current_data_handler |
|
286 | - ); |
|
287 | - $this->_generation_queue->get_message_repository()->current()->set_STS_ID( |
|
288 | - EEM_Message::status_debug_only |
|
289 | - ); |
|
290 | - $this->_error_msg[] = esc_html__( |
|
291 | - 'This is not a critical error but an informational notice. Unable to generate messages EE_Messages_Addressee objects. There were no attendees prepared by the data handler. Sometimes this is because messages only get generated for certain registration statuses. For example, the ticket notice message type only goes to approved registrations.', |
|
292 | - 'event_espresso' |
|
293 | - ); |
|
294 | - return false; |
|
295 | - } |
|
296 | - |
|
297 | - $message_template_group = $this->_get_message_template_group(); |
|
298 | - |
|
299 | - // in the unlikely event there is no EE_Message_Template_Group available, get out! |
|
300 | - if (! $message_template_group instanceof EE_Message_Template_Group) { |
|
301 | - $this->_error_msg[] = esc_html__( |
|
302 | - 'Unable to get the Message Templates for the Message being generated. No message template group accessible.', |
|
303 | - 'event_espresso' |
|
304 | - ); |
|
305 | - return false; |
|
306 | - } |
|
307 | - |
|
308 | - // get formatted templates for using to parse and setup EE_Message objects. |
|
309 | - $templates = $this->_get_templates($message_template_group); |
|
310 | - |
|
311 | - |
|
312 | - // setup new EE_Message objects (and add to _ready_queue) |
|
313 | - return $this->_assemble_messages($addressees, $templates, $message_template_group); |
|
314 | - } |
|
315 | - |
|
316 | - |
|
317 | - /** |
|
318 | - * Retrieves the message template group being used for generating messages. |
|
319 | - * Note: this also utilizes the EE_Message_Template_Group_Collection to avoid having to hit the db multiple times. |
|
320 | - * |
|
321 | - * @return EE_Message_Template_Group|null |
|
322 | - * @throws EE_Error |
|
323 | - * @throws InvalidArgumentException |
|
324 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
325 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
326 | - */ |
|
327 | - protected function _get_message_template_group() |
|
328 | - { |
|
329 | - // first see if there is a specific message template group requested (current message in the queue has a specific |
|
330 | - // GRP_ID |
|
331 | - $message_template_group = $this->_specific_message_template_group_from_queue(); |
|
332 | - if ($message_template_group instanceof EE_Message_Template_Group) { |
|
333 | - return $message_template_group; |
|
334 | - } |
|
335 | - |
|
336 | - // get event_ids from the datahandler so we can check to see if there's already a message template group for them |
|
337 | - // in the collection. |
|
338 | - $event_ids = $this->_get_event_ids_from_current_data_handler(); |
|
339 | - $message_template_group = $this->_template_collection->get_by_key( |
|
340 | - $this->_template_collection->getKey( |
|
341 | - $this->_current_messenger->name, |
|
342 | - $this->_current_message_type->name, |
|
343 | - $event_ids |
|
344 | - ) |
|
345 | - ); |
|
346 | - |
|
347 | - // if we have a message template group then no need to hit the database, just return it. |
|
348 | - if ($message_template_group instanceof EE_Message_Template_Group) { |
|
349 | - return $message_template_group; |
|
350 | - } |
|
351 | - |
|
352 | - // okay made it here, so let's get the global group first for this messenger and message type to ensure |
|
353 | - // there is no override set. |
|
354 | - $global_message_template_group = |
|
355 | - $this->_get_global_message_template_group_for_current_messenger_and_message_type(); |
|
356 | - |
|
357 | - if ($global_message_template_group instanceof EE_Message_Template_Group |
|
358 | - && $global_message_template_group->get('MTP_is_override') |
|
359 | - ) { |
|
360 | - return $global_message_template_group; |
|
361 | - } |
|
362 | - |
|
363 | - // if we're still here, that means there was no message template group for the events in the collection and |
|
364 | - // the global message template group for the messenger and message type is not set for override. So next step is |
|
365 | - // to see if there is a common shared custom message template group for this set of events. |
|
366 | - $message_template_group = $this->_get_shared_message_template_for_events($event_ids); |
|
367 | - if ($message_template_group instanceof EE_Message_Template_Group) { |
|
368 | - return $message_template_group; |
|
369 | - } |
|
370 | - |
|
371 | - // STILL here? Okay that means the fallback is to just use the global message template group for this event set. |
|
372 | - // So we'll cache the global group for this event set (so this logic doesn't have to be repeated in this request) |
|
373 | - // and return it. |
|
374 | - if ($global_message_template_group instanceof EE_Message_Template_Group) { |
|
375 | - $this->_template_collection->add( |
|
376 | - $global_message_template_group, |
|
377 | - $event_ids |
|
378 | - ); |
|
379 | - return $global_message_template_group; |
|
380 | - } |
|
381 | - |
|
382 | - // if we land here that means there's NO active message template group for this set. |
|
383 | - // TODO this will be a good target for some optimization down the road. Whenever there is no active message |
|
384 | - // template group for a given event set then cache that result so we don't repeat the logic. However, for now, |
|
385 | - // this should likely bit hit rarely enough that it's not a significant issue. |
|
386 | - return null; |
|
387 | - } |
|
388 | - |
|
389 | - |
|
390 | - /** |
|
391 | - * This checks the current message in the queue and determines if there is a specific Message Template Group |
|
392 | - * requested for that message. |
|
393 | - * |
|
394 | - * @return EE_Message_Template_Group|null |
|
395 | - * @throws EE_Error |
|
396 | - * @throws InvalidArgumentException |
|
397 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
398 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
399 | - */ |
|
400 | - protected function _specific_message_template_group_from_queue() |
|
401 | - { |
|
402 | - // is there a GRP_ID already on the EE_Message object? If there is, then a specific template has been requested |
|
403 | - // so let's use that. |
|
404 | - $GRP_ID = $this->_generation_queue->get_message_repository()->current()->GRP_ID(); |
|
405 | - |
|
406 | - if ($GRP_ID) { |
|
407 | - // attempt to retrieve from repo first |
|
408 | - $message_template_group = $this->_template_collection->get_by_ID($GRP_ID); |
|
409 | - if ($message_template_group instanceof EE_Message_Template_Group) { |
|
410 | - return $message_template_group; // got it! |
|
411 | - } |
|
412 | - |
|
413 | - // nope don't have it yet. Get from DB then add to repo if its not here, then that means the current GRP_ID |
|
414 | - // is not valid, so we'll continue on in the code assuming there's NO GRP_ID. |
|
415 | - $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
416 | - if ($message_template_group instanceof EE_Message_Template_Group) { |
|
417 | - $this->_template_collection->add($message_template_group); |
|
418 | - return $message_template_group; |
|
419 | - } |
|
420 | - } |
|
421 | - return null; |
|
422 | - } |
|
423 | - |
|
424 | - |
|
425 | - /** |
|
426 | - * Returns whether the event ids passed in all share the same message template group for the current message type |
|
427 | - * and messenger. |
|
428 | - * |
|
429 | - * @param array $event_ids |
|
430 | - * @return bool true means they DO share the same message template group, false means they don't. |
|
431 | - * @throws EE_Error |
|
432 | - * @throws InvalidArgumentException |
|
433 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
434 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
435 | - */ |
|
436 | - protected function _queue_shares_same_message_template_group_for_events(array $event_ids) |
|
437 | - { |
|
438 | - foreach ($this->_current_data_handler->events as $event) { |
|
439 | - $event_ids[ $event['ID'] ] = $event['ID']; |
|
440 | - } |
|
441 | - $count_of_message_template_groups = EEM_Message_Template_Group::instance()->count( |
|
442 | - array( |
|
443 | - array( |
|
444 | - 'Event.EVT_ID' => array('IN', $event_ids), |
|
445 | - 'MTP_messenger' => $this->_current_messenger->name, |
|
446 | - 'MTP_message_type' => $this->_current_message_type->name, |
|
447 | - ), |
|
448 | - ), |
|
449 | - 'GRP_ID', |
|
450 | - true |
|
451 | - ); |
|
452 | - return $count_of_message_template_groups === 1; |
|
453 | - } |
|
454 | - |
|
455 | - |
|
456 | - /** |
|
457 | - * This will get the shared message template group for events that are in the current data handler but ONLY if |
|
458 | - * there's a single shared message template group among all the events. Otherwise it returns null. |
|
459 | - * |
|
460 | - * @param array $event_ids |
|
461 | - * @return EE_Message_Template_Group|null |
|
462 | - * @throws EE_Error |
|
463 | - * @throws InvalidArgumentException |
|
464 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
465 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
466 | - */ |
|
467 | - protected function _get_shared_message_template_for_events(array $event_ids) |
|
468 | - { |
|
469 | - $message_template_group = null; |
|
470 | - if ($this->_queue_shares_same_message_template_group_for_events($event_ids)) { |
|
471 | - $message_template_group = EEM_Message_Template_Group::instance()->get_one( |
|
472 | - array( |
|
473 | - array( |
|
474 | - 'Event.EVT_ID' => array('IN', $event_ids), |
|
475 | - 'MTP_messenger' => $this->_current_messenger->name, |
|
476 | - 'MTP_message_type' => $this->_current_message_type->name, |
|
477 | - 'MTP_is_active' => true, |
|
478 | - ), |
|
479 | - 'group_by' => 'GRP_ID', |
|
480 | - ) |
|
481 | - ); |
|
482 | - // store this in the collection if its valid |
|
483 | - if ($message_template_group instanceof EE_Message_Template_Group) { |
|
484 | - $this->_template_collection->add( |
|
485 | - $message_template_group, |
|
486 | - $event_ids |
|
487 | - ); |
|
488 | - } |
|
489 | - } |
|
490 | - return $message_template_group; |
|
491 | - } |
|
492 | - |
|
493 | - |
|
494 | - /** |
|
495 | - * Retrieves the global message template group for the current messenger and message type. |
|
496 | - * |
|
497 | - * @return EE_Message_Template_Group|null |
|
498 | - * @throws EE_Error |
|
499 | - * @throws InvalidArgumentException |
|
500 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
501 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
502 | - */ |
|
503 | - protected function _get_global_message_template_group_for_current_messenger_and_message_type() |
|
504 | - { |
|
505 | - // first check the collection (we use an array with 0 in it to represent global groups). |
|
506 | - $global_message_template_group = $this->_template_collection->get_by_key( |
|
507 | - $this->_template_collection->getKey( |
|
508 | - $this->_current_messenger->name, |
|
509 | - $this->_current_message_type->name, |
|
510 | - array(0) |
|
511 | - ) |
|
512 | - ); |
|
513 | - |
|
514 | - // if we don't have a group lets hit the db. |
|
515 | - if (! $global_message_template_group instanceof EE_Message_Template_Group) { |
|
516 | - $global_message_template_group = EEM_Message_Template_Group::instance()->get_one( |
|
517 | - array( |
|
518 | - array( |
|
519 | - 'MTP_messenger' => $this->_current_messenger->name, |
|
520 | - 'MTP_message_type' => $this->_current_message_type->name, |
|
521 | - 'MTP_is_active' => true, |
|
522 | - 'MTP_is_global' => true, |
|
523 | - ), |
|
524 | - ) |
|
525 | - ); |
|
526 | - // if we have a group, add it to the collection. |
|
527 | - if ($global_message_template_group instanceof EE_Message_Template_Group) { |
|
528 | - $this->_template_collection->add( |
|
529 | - $global_message_template_group, |
|
530 | - array(0) |
|
531 | - ); |
|
532 | - } |
|
533 | - } |
|
534 | - return $global_message_template_group; |
|
535 | - } |
|
536 | - |
|
537 | - |
|
538 | - /** |
|
539 | - * Returns an array of event ids for all the events within the current data handler. |
|
540 | - * |
|
541 | - * @return array |
|
542 | - */ |
|
543 | - protected function _get_event_ids_from_current_data_handler() |
|
544 | - { |
|
545 | - $event_ids = array(); |
|
546 | - foreach ($this->_current_data_handler->events as $event) { |
|
547 | - $event_ids[ $event['ID'] ] = $event['ID']; |
|
548 | - } |
|
549 | - return $event_ids; |
|
550 | - } |
|
551 | - |
|
552 | - |
|
553 | - /** |
|
554 | - * Retrieves formatted array of template information for each context specific to the given |
|
555 | - * EE_Message_Template_Group |
|
556 | - * |
|
557 | - * @param EE_Message_Template_Group $message_template_group |
|
558 | - * @return array The returned array is in this structure: |
|
559 | - * array( |
|
560 | - * 'field_name' => array( |
|
561 | - * 'context' => 'content' |
|
562 | - * ) |
|
563 | - * ) |
|
564 | - * @throws EE_Error |
|
565 | - */ |
|
566 | - protected function _get_templates(EE_Message_Template_Group $message_template_group) |
|
567 | - { |
|
568 | - $templates = array(); |
|
569 | - $context_templates = $message_template_group->context_templates(); |
|
570 | - foreach ($context_templates as $context => $template_fields) { |
|
571 | - foreach ($template_fields as $template_field => $template_obj) { |
|
572 | - if (! $template_obj instanceof EE_Message_Template) { |
|
573 | - continue; |
|
574 | - } |
|
575 | - $templates[ $template_field ][ $context ] = $template_obj->get('MTP_content'); |
|
576 | - } |
|
577 | - } |
|
578 | - return $templates; |
|
579 | - } |
|
580 | - |
|
581 | - |
|
582 | - /** |
|
583 | - * Assembles new fully generated EE_Message objects and adds to _ready_queue |
|
584 | - * |
|
585 | - * @param array $addressees Array of EE_Messages_Addressee objects indexed by message type |
|
586 | - * context. |
|
587 | - * @param array $templates formatted array of templates used for parsing data. |
|
588 | - * @param EE_Message_Template_Group $message_template_group |
|
589 | - * @return bool true if message generation went a-ok. false if some sort of exception occurred. Note: The |
|
590 | - * method will attempt to generate ALL EE_Message objects and add to |
|
591 | - * the _ready_queue. Successfully generated messages get added to the |
|
592 | - * queue with EEM_Message::status_idle, unsuccessfully generated |
|
593 | - * messages will get added to the queue as EEM_Message::status_failed. |
|
594 | - * Very rarely should "false" be returned from this method. |
|
595 | - * @throws EE_Error |
|
596 | - */ |
|
597 | - protected function _assemble_messages($addressees, $templates, EE_Message_Template_Group $message_template_group) |
|
598 | - { |
|
599 | - |
|
600 | - // if templates are empty then get out because we can't generate anything. |
|
601 | - if (! $templates) { |
|
602 | - $this->_error_msg[] = esc_html__( |
|
603 | - 'Unable to assemble messages because there are no templates retrieved for generating the messages with', |
|
604 | - 'event_espresso' |
|
605 | - ); |
|
606 | - return false; |
|
607 | - } |
|
608 | - |
|
609 | - // We use this as the counter for generated messages because don't forget we may be executing this inside of a |
|
610 | - // generation_queue. So _ready_queue may have generated EE_Message objects already. |
|
611 | - $generated_count = 0; |
|
612 | - foreach ($addressees as $context => $recipients) { |
|
613 | - foreach ($recipients as $recipient) { |
|
614 | - $message = $this->_setup_message_object($context, $recipient, $templates, $message_template_group); |
|
615 | - if ($message instanceof EE_Message) { |
|
616 | - $this->_ready_queue->add( |
|
617 | - $message, |
|
618 | - array(), |
|
619 | - $this->_generation_queue->get_message_repository()->is_preview(), |
|
620 | - $this->_generation_queue->get_message_repository()->is_test_send() |
|
621 | - ); |
|
622 | - $generated_count++; |
|
623 | - } |
|
624 | - |
|
625 | - // if the current MSG being generated is for a test send then we'll only use ONE message in the |
|
626 | - // generation. |
|
627 | - if ($this->_generation_queue->get_message_repository()->is_test_send()) { |
|
628 | - break 2; |
|
629 | - } |
|
630 | - } |
|
631 | - } |
|
632 | - |
|
633 | - // if there are no generated messages then something else fatal went wrong. |
|
634 | - return $generated_count > 0; |
|
635 | - } |
|
636 | - |
|
637 | - |
|
638 | - /** |
|
639 | - * @param string $context The context for the generated message. |
|
640 | - * @param EE_Messages_Addressee $recipient |
|
641 | - * @param array $templates formatted array of templates used for parsing data. |
|
642 | - * @param EE_Message_Template_Group $message_template_group |
|
643 | - * @return bool|EE_Message |
|
644 | - * @throws EE_Error |
|
645 | - */ |
|
646 | - protected function _setup_message_object( |
|
647 | - $context, |
|
648 | - EE_Messages_Addressee $recipient, |
|
649 | - $templates, |
|
650 | - EE_Message_Template_Group $message_template_group |
|
651 | - ) { |
|
652 | - // stuff we already know |
|
653 | - $transaction_id = $recipient->txn instanceof EE_Transaction ? $recipient->txn->ID() : 0; |
|
654 | - $transaction_id = empty($transaction_id) && $this->_current_data_handler->txn instanceof EE_Transaction |
|
655 | - ? $this->_current_data_handler->txn->ID() |
|
656 | - : $transaction_id; |
|
657 | - $message_fields = array( |
|
658 | - 'GRP_ID' => $message_template_group->ID(), |
|
659 | - 'TXN_ID' => $transaction_id, |
|
660 | - 'MSG_messenger' => $this->_current_messenger->name, |
|
661 | - 'MSG_message_type' => $this->_current_message_type->name, |
|
662 | - 'MSG_context' => $context, |
|
663 | - ); |
|
664 | - |
|
665 | - // recipient id and type should be on the EE_Messages_Addressee object but if this is empty, let's try to grab |
|
666 | - // the info from the att_obj found in the EE_Messages_Addressee object. |
|
667 | - if (empty($recipient->recipient_id) || empty($recipient->recipient_type)) { |
|
668 | - $message_fields['MSG_recipient_ID'] = $recipient->att_obj instanceof EE_Attendee |
|
669 | - ? $recipient->att_obj->ID() |
|
670 | - : 0; |
|
671 | - $message_fields['MSG_recipient_type'] = 'Attendee'; |
|
672 | - } else { |
|
673 | - $message_fields['MSG_recipient_ID'] = $recipient->recipient_id; |
|
674 | - $message_fields['MSG_recipient_type'] = $recipient->recipient_type; |
|
675 | - } |
|
676 | - $message = EE_Message_Factory::create($message_fields); |
|
677 | - |
|
678 | - // grab valid shortcodes for shortcode parser |
|
679 | - $mt_shortcodes = $this->_current_message_type->get_valid_shortcodes(); |
|
680 | - $m_shortcodes = $this->_current_messenger->get_valid_shortcodes(); |
|
681 | - |
|
682 | - // if the 'to' field is empty or the context is inactive we skip EXCEPT if we're previewing |
|
683 | - if (( |
|
684 | - ( |
|
685 | - empty($templates['to'][ $context ]) |
|
686 | - && ! $this->_current_messenger->allow_empty_to_field() |
|
687 | - ) |
|
688 | - || ! $message_template_group->is_context_active($context) |
|
689 | - ) |
|
690 | - && ! $this->_generation_queue->get_message_repository()->is_preview() |
|
691 | - ) { |
|
692 | - // we silently exit here and do NOT record a fail because the message is "turned off" by having no "to" |
|
693 | - // field. |
|
694 | - return false; |
|
695 | - } |
|
696 | - $error_msg = array(); |
|
697 | - foreach ($templates as $field => $field_context) { |
|
698 | - $error_msg = array(); |
|
699 | - // let's setup the valid shortcodes for the incoming context. |
|
700 | - $valid_shortcodes = $mt_shortcodes[ $context ]; |
|
701 | - // merge in valid shortcodes for the field. |
|
702 | - $shortcodes = isset($m_shortcodes[ $field ]) ? $m_shortcodes[ $field ] : $valid_shortcodes; |
|
703 | - if (isset($templates[ $field ][ $context ])) { |
|
704 | - // prefix field. |
|
705 | - $column_name = 'MSG_' . $field; |
|
706 | - try { |
|
707 | - $content = $this->_shortcode_parser->parse_message_template( |
|
708 | - $templates[ $field ][ $context ], |
|
709 | - $recipient, |
|
710 | - $shortcodes, |
|
711 | - $this->_current_message_type, |
|
712 | - $this->_current_messenger, |
|
713 | - $message |
|
714 | - ); |
|
715 | - // the model field removes slashes when setting (usually necessary when the input is from the |
|
716 | - // request) but this value is from another model and has no slashes. So add them so it matchces |
|
717 | - // what the field expected (otherwise slashes will have been stripped from this an extra time) |
|
718 | - $message->set_field_or_extra_meta($column_name, addslashes($content)); |
|
719 | - } catch (EE_Error $e) { |
|
720 | - $error_msg[] = sprintf( |
|
721 | - esc_html__( |
|
722 | - 'There was a problem generating the content for the field %s: %s', |
|
723 | - 'event_espresso' |
|
724 | - ), |
|
725 | - $field, |
|
726 | - $e->getMessage() |
|
727 | - ); |
|
728 | - $message->set_STS_ID(EEM_Message::status_failed); |
|
729 | - } |
|
730 | - } |
|
731 | - } |
|
732 | - |
|
733 | - if ($message->STS_ID() === EEM_Message::status_failed) { |
|
734 | - $error_msg = esc_html__('There were problems generating this message:', 'event_espresso') |
|
735 | - . "\n" |
|
736 | - . implode("\n", $error_msg); |
|
737 | - $message->set_error_message($error_msg); |
|
738 | - } else { |
|
739 | - $message->set_STS_ID(EEM_Message::status_idle); |
|
740 | - } |
|
741 | - return $message; |
|
742 | - } |
|
743 | - |
|
744 | - |
|
745 | - /** |
|
746 | - * This verifies that the incoming array has a EE_messenger object and a EE_message_type object and sets appropriate |
|
747 | - * error message if either is missing. |
|
748 | - * |
|
749 | - * @return bool true means there were no errors, false means there were errors. |
|
750 | - * @throws EE_Error |
|
751 | - * @throws ReflectionException |
|
752 | - */ |
|
753 | - protected function _verify() |
|
754 | - { |
|
755 | - // reset error message to an empty array. |
|
756 | - $this->_error_msg = array(); |
|
757 | - $valid = true; |
|
758 | - $valid = $valid ? $this->_validate_messenger_and_message_type() : $valid; |
|
759 | - $valid = $valid ? $this->_validate_and_setup_data() : $valid; |
|
760 | - |
|
761 | - // set the verified flag so we know everything has been validated. |
|
762 | - $this->_verified = $valid; |
|
763 | - |
|
764 | - return $valid; |
|
765 | - } |
|
766 | - |
|
767 | - |
|
768 | - /** |
|
769 | - * This accepts an array and validates that it is an array indexed by context with each value being an array of |
|
770 | - * EE_Messages_Addressee objects. |
|
771 | - * |
|
772 | - * @param array $addressees Keys correspond to contexts for the message type and values are EE_Messages_Addressee[] |
|
773 | - * @return bool |
|
774 | - */ |
|
775 | - protected function _valid_addressees($addressees) |
|
776 | - { |
|
777 | - if (! $addressees || ! is_array($addressees)) { |
|
778 | - return false; |
|
779 | - } |
|
780 | - |
|
781 | - foreach ($addressees as $addressee_array) { |
|
782 | - foreach ($addressee_array as $addressee) { |
|
783 | - if (! $addressee instanceof EE_Messages_Addressee) { |
|
784 | - return false; |
|
785 | - } |
|
786 | - } |
|
787 | - } |
|
788 | - return true; |
|
789 | - } |
|
790 | - |
|
791 | - |
|
792 | - /** |
|
793 | - * This validates the messenger, message type, and presences of generation data for the current EE_Message in the |
|
794 | - * queue. This process sets error messages if something is wrong. |
|
795 | - * |
|
796 | - * @return bool true is if there are no errors. false is if there is. |
|
797 | - */ |
|
798 | - protected function _validate_messenger_and_message_type() |
|
799 | - { |
|
800 | - |
|
801 | - // first are there any existing error messages? If so then return. |
|
802 | - if ($this->_error_msg) { |
|
803 | - return false; |
|
804 | - } |
|
805 | - /** @type EE_Message $message */ |
|
806 | - $message = $this->_generation_queue->get_message_repository()->current(); |
|
807 | - try { |
|
808 | - $this->_current_messenger = $message->valid_messenger(true) |
|
809 | - ? $message->messenger_object() |
|
810 | - : null; |
|
811 | - } catch (Exception $e) { |
|
812 | - $this->_error_msg[] = $e->getMessage(); |
|
813 | - } |
|
814 | - try { |
|
815 | - $this->_current_message_type = $message->valid_message_type(true) |
|
816 | - ? $message->message_type_object() |
|
817 | - : null; |
|
818 | - } catch (Exception $e) { |
|
819 | - $this->_error_msg[] = $e->getMessage(); |
|
820 | - } |
|
821 | - |
|
822 | - /** |
|
823 | - * Check if there is any generation data, but only if this is not for a preview. |
|
824 | - */ |
|
825 | - if (! $this->_generation_queue->get_message_repository()->get_generation_data() |
|
826 | - && ( |
|
827 | - ! $this->_generation_queue->get_message_repository()->is_preview() |
|
828 | - && $this->_generation_queue->get_message_repository()->get_data_handler() |
|
829 | - !== 'EE_Messages_Preview_incoming_data' |
|
830 | - ) |
|
831 | - ) { |
|
832 | - $this->_error_msg[] = esc_html__( |
|
833 | - 'There is no generation data for this message. Unable to generate.', |
|
834 | - 'event_espresso' |
|
835 | - ); |
|
836 | - } |
|
837 | - |
|
838 | - return empty($this->_error_msg); |
|
839 | - } |
|
840 | - |
|
841 | - |
|
842 | - /** |
|
843 | - * This method retrieves the expected data handler for the message type and validates the generation data for that |
|
844 | - * data handler. |
|
845 | - * |
|
846 | - * @return bool true means there are no errors. false means there were errors (and handler did not get setup). |
|
847 | - * @throws EE_Error |
|
848 | - * @throws ReflectionException |
|
849 | - */ |
|
850 | - protected function _validate_and_setup_data() |
|
851 | - { |
|
852 | - |
|
853 | - // First, are there any existing error messages? If so, return because if there were errors elsewhere this can't |
|
854 | - // be used anyways. |
|
855 | - if ($this->_error_msg) { |
|
856 | - return false; |
|
857 | - } |
|
858 | - |
|
859 | - $generation_data = $this->_generation_queue->get_message_repository()->get_generation_data(); |
|
860 | - |
|
861 | - /** @type EE_Messages_incoming_data $data_handler_class_name - well not really... just the class name actually*/ |
|
862 | - $data_handler_class_name = $this->_generation_queue->get_message_repository()->get_data_handler() |
|
863 | - ? $this->_generation_queue->get_message_repository()->get_data_handler() |
|
864 | - : 'EE_Messages_' . $this->_current_message_type->get_data_handler($generation_data) . '_incoming_data'; |
|
865 | - |
|
866 | - // If this EE_Message is for a preview, then let's switch out to the preview data handler. |
|
867 | - if ($this->_generation_queue->get_message_repository()->is_preview()) { |
|
868 | - $data_handler_class_name = 'EE_Messages_Preview_incoming_data'; |
|
869 | - } |
|
870 | - |
|
871 | - // First get the class name for the data handler (and also verifies it exists. |
|
872 | - if (! class_exists($data_handler_class_name)) { |
|
873 | - $this->_error_msg[] = sprintf( |
|
874 | - esc_html__( |
|
875 | - 'The included data handler class name does not match any valid, accessible, "%1$s" classes. Looking for %2$s.', |
|
876 | - 'event_espresso' |
|
877 | - ), |
|
878 | - 'EE_Messages_incoming_data', |
|
879 | - $data_handler_class_name |
|
880 | - ); |
|
881 | - return false; |
|
882 | - } |
|
883 | - |
|
884 | - // convert generation_data for data_handler_instantiation. |
|
885 | - $generation_data = $data_handler_class_name::convert_data_from_persistent_storage($generation_data); |
|
886 | - |
|
887 | - // note, this may set error messages as well. |
|
888 | - $this->_set_data_handler($generation_data, $data_handler_class_name); |
|
889 | - |
|
890 | - return empty($this->_error_msg); |
|
891 | - } |
|
892 | - |
|
893 | - |
|
894 | - /** |
|
895 | - * Sets the $_current_data_handler property that is used for generating the current EE_Message in the queue, and |
|
896 | - * adds it to the _data repository. |
|
897 | - * |
|
898 | - * @param mixed $generating_data This is data expected by the instantiated data handler. |
|
899 | - * @param string $data_handler_class_name This is the reference string indicating what data handler is being |
|
900 | - * instantiated. |
|
901 | - * @return void . |
|
902 | - * @throws EE_Error |
|
903 | - * @throws ReflectionException |
|
904 | - */ |
|
905 | - protected function _set_data_handler($generating_data, $data_handler_class_name) |
|
906 | - { |
|
907 | - // valid classname for the data handler. Now let's setup the key for the data handler repository to see if there |
|
908 | - // is already a ready data handler in the repository. |
|
909 | - $this->_current_data_handler = $this->_data_handler_collection->get_by_key( |
|
910 | - $this->_data_handler_collection->get_key( |
|
911 | - $data_handler_class_name, |
|
912 | - $generating_data |
|
913 | - ) |
|
914 | - ); |
|
915 | - if (! $this->_current_data_handler instanceof EE_Messages_incoming_data) { |
|
916 | - // no saved data_handler in the repo so let's set one up and add it to the repo. |
|
917 | - try { |
|
918 | - $this->_current_data_handler = new $data_handler_class_name($generating_data); |
|
919 | - $this->_data_handler_collection->add($this->_current_data_handler, $generating_data); |
|
920 | - } catch (EE_Error $e) { |
|
921 | - $this->_error_msg[] = $e->get_error(); |
|
922 | - } |
|
923 | - } |
|
924 | - } |
|
925 | - |
|
926 | - |
|
927 | - /** |
|
928 | - * The queued EE_Message for generation does not save the data used for generation as objects |
|
929 | - * because serialization of those objects could be problematic if the data is saved to the db. |
|
930 | - * So this method calls the static method on the associated data_handler for the given message_type |
|
931 | - * and that preps the data for later instantiation when generating. |
|
932 | - * |
|
933 | - * @param EE_Message_To_Generate $message_to_generate |
|
934 | - * @param bool $preview Indicate whether this is being used for a preview or not. |
|
935 | - * @return mixed Prepped data for persisting to the queue. false is returned if unable to prep data. |
|
936 | - */ |
|
937 | - protected function _prepare_data_for_queue(EE_Message_To_Generate $message_to_generate, $preview) |
|
938 | - { |
|
939 | - /** @type EE_Messages_incoming_data $data_handler - well not really... just the class name actually */ |
|
940 | - $data_handler = $message_to_generate->get_data_handler_class_name($preview); |
|
941 | - if (! $message_to_generate->valid()) { |
|
942 | - return false; // unable to get the data because the info in the EE_Message_To_Generate class is invalid. |
|
943 | - } |
|
944 | - return $data_handler::convert_data_for_persistent_storage($message_to_generate->data()); |
|
945 | - } |
|
946 | - |
|
947 | - |
|
948 | - /** |
|
949 | - * This sets up a EEM_Message::status_incomplete EE_Message object and adds it to the generation queue. |
|
950 | - * |
|
951 | - * @param EE_Message_To_Generate $message_to_generate |
|
952 | - * @param bool $test_send Whether this is just a test send or not. Typically used for previews. |
|
953 | - * @throws InvalidArgumentException |
|
954 | - * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
955 | - * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
956 | - */ |
|
957 | - public function create_and_add_message_to_queue(EE_Message_To_Generate $message_to_generate, $test_send = false) |
|
958 | - { |
|
959 | - // prep data |
|
960 | - $data = $this->_prepare_data_for_queue($message_to_generate, $message_to_generate->preview()); |
|
961 | - |
|
962 | - $message = $message_to_generate->get_EE_Message(); |
|
963 | - |
|
964 | - // is there a GRP_ID in the request? |
|
965 | - if ($GRP_ID = EE_Registry::instance()->REQ->get('GRP_ID')) { |
|
966 | - $message->set_GRP_ID($GRP_ID); |
|
967 | - } |
|
968 | - |
|
969 | - if ($data === false) { |
|
970 | - $message->set_STS_ID(EEM_Message::status_failed); |
|
971 | - $message->set_error_message( |
|
972 | - esc_html__( |
|
973 | - 'Unable to prepare data for persistence to the database.', |
|
974 | - 'event_espresso' |
|
975 | - ) |
|
976 | - ); |
|
977 | - } else { |
|
978 | - // make sure that the data handler is cached on the message as well |
|
979 | - $data['data_handler_class_name'] = $message_to_generate->get_data_handler_class_name(); |
|
980 | - } |
|
981 | - |
|
982 | - $this->_generation_queue->add($message, $data, $message_to_generate->preview(), $test_send); |
|
983 | - } |
|
15 | + /** |
|
16 | + * @type EE_Messages_Data_Handler_Collection |
|
17 | + */ |
|
18 | + protected $_data_handler_collection; |
|
19 | + |
|
20 | + /** |
|
21 | + * @type EE_Message_Template_Group_Collection |
|
22 | + */ |
|
23 | + protected $_template_collection; |
|
24 | + |
|
25 | + /** |
|
26 | + * This will hold the data handler for the current EE_Message being generated. |
|
27 | + * |
|
28 | + * @type EE_Messages_incoming_data |
|
29 | + */ |
|
30 | + protected $_current_data_handler; |
|
31 | + |
|
32 | + /** |
|
33 | + * This holds the EE_Messages_Queue that contains the messages to generate. |
|
34 | + * |
|
35 | + * @type EE_Messages_Queue |
|
36 | + */ |
|
37 | + protected $_generation_queue; |
|
38 | + |
|
39 | + /** |
|
40 | + * This holds the EE_Messages_Queue that will store the generated EE_Message objects. |
|
41 | + * |
|
42 | + * @type EE_Messages_Queue |
|
43 | + */ |
|
44 | + protected $_ready_queue; |
|
45 | + |
|
46 | + /** |
|
47 | + * This is a container for any error messages that get created through the generation |
|
48 | + * process. |
|
49 | + * |
|
50 | + * @type array |
|
51 | + */ |
|
52 | + protected $_error_msg = array(); |
|
53 | + |
|
54 | + /** |
|
55 | + * Flag used to set when the current EE_Message in the generation queue has been verified. |
|
56 | + * |
|
57 | + * @type bool |
|
58 | + */ |
|
59 | + protected $_verified = false; |
|
60 | + |
|
61 | + /** |
|
62 | + * This will hold the current messenger object corresponding with the current EE_Message in the generation queue. |
|
63 | + * |
|
64 | + * @type EE_messenger |
|
65 | + */ |
|
66 | + protected $_current_messenger; |
|
67 | + |
|
68 | + /** |
|
69 | + * This will hold the current message type object corresponding with the current EE_Message in the generation queue. |
|
70 | + * |
|
71 | + * @type EE_message_type |
|
72 | + */ |
|
73 | + protected $_current_message_type; |
|
74 | + |
|
75 | + /** |
|
76 | + * @type EEH_Parse_Shortcodes |
|
77 | + */ |
|
78 | + protected $_shortcode_parser; |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * @param EE_Messages_Queue $generation_queue |
|
83 | + * @param \EE_Messages_Queue $ready_queue |
|
84 | + * @param \EE_Messages_Data_Handler_Collection $data_handler_collection |
|
85 | + * @param \EE_Message_Template_Group_Collection $template_collection |
|
86 | + * @param \EEH_Parse_Shortcodes $shortcode_parser |
|
87 | + */ |
|
88 | + public function __construct( |
|
89 | + EE_Messages_Queue $generation_queue, |
|
90 | + EE_Messages_Queue $ready_queue, |
|
91 | + EE_Messages_Data_Handler_Collection $data_handler_collection, |
|
92 | + EE_Message_Template_Group_Collection $template_collection, |
|
93 | + EEH_Parse_Shortcodes $shortcode_parser |
|
94 | + ) { |
|
95 | + $this->_generation_queue = $generation_queue; |
|
96 | + $this->_ready_queue = $ready_queue; |
|
97 | + $this->_data_handler_collection = $data_handler_collection; |
|
98 | + $this->_template_collection = $template_collection; |
|
99 | + $this->_shortcode_parser = $shortcode_parser; |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * @return EE_Messages_Queue |
|
105 | + */ |
|
106 | + public function generation_queue() |
|
107 | + { |
|
108 | + return $this->_generation_queue; |
|
109 | + } |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * This iterates through the provided queue and generates the EE_Message objects. |
|
114 | + * When iterating through the queue, the queued item that served as the base for generating other EE_Message |
|
115 | + * objects gets removed and the new EE_Message objects get added to a NEW queue. The NEW queue is then returned |
|
116 | + * for the caller to decide what to do with it. |
|
117 | + * |
|
118 | + * @param bool $save Whether to save the EE_Message objects in the new queue or just return. |
|
119 | + * @return EE_Messages_Queue The new queue for holding generated EE_Message objects. |
|
120 | + * @throws EE_Error |
|
121 | + * @throws ReflectionException |
|
122 | + */ |
|
123 | + public function generate($save = true) |
|
124 | + { |
|
125 | + // iterate through the messages in the queue, generate, and add to new queue. |
|
126 | + $this->_generation_queue->get_message_repository()->rewind(); |
|
127 | + while ($this->_generation_queue->get_message_repository()->valid()) { |
|
128 | + // reset "current" properties |
|
129 | + $this->_reset_current_properties(); |
|
130 | + |
|
131 | + /** @type EE_Message $msg */ |
|
132 | + $msg = $this->_generation_queue->get_message_repository()->current(); |
|
133 | + |
|
134 | + /** |
|
135 | + * need to get the next object and capture it for setting manually after deletes. The reason is that when |
|
136 | + * an object is removed from the repo then valid for the next object will fail. |
|
137 | + */ |
|
138 | + $this->_generation_queue->get_message_repository()->next(); |
|
139 | + $next_msg = $this->_generation_queue->get_message_repository()->current(); |
|
140 | + // restore pointer to current item |
|
141 | + $this->_generation_queue->get_message_repository()->set_current($msg); |
|
142 | + |
|
143 | + // skip and delete if the current $msg is NOT incomplete (queued for generation) |
|
144 | + if ($msg->STS_ID() !== EEM_Message::status_incomplete) { |
|
145 | + // we keep this item in the db just remove from the repo. |
|
146 | + $this->_generation_queue->get_message_repository()->remove($msg); |
|
147 | + // next item |
|
148 | + $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
149 | + continue; |
|
150 | + } |
|
151 | + |
|
152 | + if ($this->_verify()) { |
|
153 | + // let's get generating! |
|
154 | + $this->_generate(); |
|
155 | + } |
|
156 | + |
|
157 | + // don't persist debug_only messages if the messages system is not in debug mode. |
|
158 | + if ($msg->STS_ID() === EEM_Message::status_debug_only |
|
159 | + && ! EEM_Message::debug() |
|
160 | + ) { |
|
161 | + do_action( |
|
162 | + 'AHEE__EE_Messages_Generator__generate__before_debug_delete', |
|
163 | + $msg, |
|
164 | + $this->_error_msg, |
|
165 | + $this->_current_messenger, |
|
166 | + $this->_current_message_type, |
|
167 | + $this->_current_data_handler |
|
168 | + ); |
|
169 | + $this->_generation_queue->get_message_repository()->delete(); |
|
170 | + $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
171 | + continue; |
|
172 | + } |
|
173 | + |
|
174 | + // if there are error messages then let's set the status and the error message. |
|
175 | + if ($this->_error_msg) { |
|
176 | + // if the status is already debug only, then let's leave it at that. |
|
177 | + if ($msg->STS_ID() !== EEM_Message::status_debug_only) { |
|
178 | + $msg->set_STS_ID(EEM_Message::status_failed); |
|
179 | + } |
|
180 | + do_action( |
|
181 | + 'AHEE__EE_Messages_Generator__generate__processing_failed_message', |
|
182 | + $msg, |
|
183 | + $this->_error_msg, |
|
184 | + $this->_current_messenger, |
|
185 | + $this->_current_message_type, |
|
186 | + $this->_current_data_handler |
|
187 | + ); |
|
188 | + $msg->set_error_message( |
|
189 | + esc_html__('Message failed to generate for the following reasons: ', 'event_espresso') |
|
190 | + . "\n" |
|
191 | + . implode("\n", $this->_error_msg) |
|
192 | + ); |
|
193 | + $msg->set_modified(time()); |
|
194 | + } else { |
|
195 | + do_action( |
|
196 | + 'AHEE__EE_Messages_Generator__generate__before_successful_generated_message_delete', |
|
197 | + $msg, |
|
198 | + $this->_error_msg, |
|
199 | + $this->_current_messenger, |
|
200 | + $this->_current_message_type, |
|
201 | + $this->_current_data_handler |
|
202 | + ); |
|
203 | + // remove from db |
|
204 | + $this->_generation_queue->get_message_repository()->delete(); |
|
205 | + } |
|
206 | + // next item |
|
207 | + $this->_generation_queue->get_message_repository()->set_current($next_msg); |
|
208 | + } |
|
209 | + |
|
210 | + // generation queue is ALWAYS saved to record any errors in the generation process. |
|
211 | + $this->_generation_queue->save(); |
|
212 | + |
|
213 | + /** |
|
214 | + * save _ready_queue if flag set. |
|
215 | + * Note: The EE_Message objects have values set via the EE_Base_Class::set_field_or_extra_meta() method. This |
|
216 | + * means if a field was added that is not a valid database column. The EE_Message was already saved to the db |
|
217 | + * so a EE_Extra_Meta entry could be created and attached to the EE_Message. In those cases the save flag is |
|
218 | + * irrelevant. |
|
219 | + */ |
|
220 | + if ($save) { |
|
221 | + $this->_ready_queue->save(); |
|
222 | + } |
|
223 | + |
|
224 | + // final reset of properties |
|
225 | + $this->_reset_current_properties(); |
|
226 | + |
|
227 | + return $this->_ready_queue; |
|
228 | + } |
|
229 | + |
|
230 | + |
|
231 | + /** |
|
232 | + * This resets all the properties used for holding "current" values corresponding to the current EE_Message object |
|
233 | + * in the generation queue. |
|
234 | + */ |
|
235 | + protected function _reset_current_properties() |
|
236 | + { |
|
237 | + $this->_verified = false; |
|
238 | + // make sure any _data value in the current message type is reset |
|
239 | + if ($this->_current_message_type instanceof EE_message_type) { |
|
240 | + $this->_current_message_type->reset_data(); |
|
241 | + } |
|
242 | + $this->_current_messenger = $this->_current_message_type = $this->_current_data_handler = null; |
|
243 | + } |
|
244 | + |
|
245 | + |
|
246 | + /** |
|
247 | + * This proceeds with the actual generation of a message. By the time this is called, there should already be a |
|
248 | + * $_current_data_handler set and all incoming information should be validated for the current EE_Message in the |
|
249 | + * _generating_queue. |
|
250 | + * |
|
251 | + * @return bool Whether the message was successfully generated or not. |
|
252 | + * @throws EE_Error |
|
253 | + * @throws InvalidArgumentException |
|
254 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
255 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
256 | + */ |
|
257 | + protected function _generate() |
|
258 | + { |
|
259 | + // double check verification has run and that everything is ready to work with (saves us having to validate |
|
260 | + // everything again). |
|
261 | + if (! $this->_verified) { |
|
262 | + return false; // get out because we don't have a valid setup to work with. |
|
263 | + } |
|
264 | + |
|
265 | + |
|
266 | + try { |
|
267 | + $addressees = $this->_current_message_type->get_addressees( |
|
268 | + $this->_current_data_handler, |
|
269 | + $this->_generation_queue->get_message_repository()->current()->context() |
|
270 | + ); |
|
271 | + } catch (EE_Error $e) { |
|
272 | + $this->_error_msg[] = $e->getMessage(); |
|
273 | + return false; |
|
274 | + } |
|
275 | + |
|
276 | + |
|
277 | + // if no addressees then get out because there is nothing to generation (possible bad data). |
|
278 | + if (! $this->_valid_addressees($addressees)) { |
|
279 | + do_action( |
|
280 | + 'AHEE__EE_Messages_Generator___generate__invalid_addressees', |
|
281 | + $this->_generation_queue->get_message_repository()->current(), |
|
282 | + $addressees, |
|
283 | + $this->_current_messenger, |
|
284 | + $this->_current_message_type, |
|
285 | + $this->_current_data_handler |
|
286 | + ); |
|
287 | + $this->_generation_queue->get_message_repository()->current()->set_STS_ID( |
|
288 | + EEM_Message::status_debug_only |
|
289 | + ); |
|
290 | + $this->_error_msg[] = esc_html__( |
|
291 | + 'This is not a critical error but an informational notice. Unable to generate messages EE_Messages_Addressee objects. There were no attendees prepared by the data handler. Sometimes this is because messages only get generated for certain registration statuses. For example, the ticket notice message type only goes to approved registrations.', |
|
292 | + 'event_espresso' |
|
293 | + ); |
|
294 | + return false; |
|
295 | + } |
|
296 | + |
|
297 | + $message_template_group = $this->_get_message_template_group(); |
|
298 | + |
|
299 | + // in the unlikely event there is no EE_Message_Template_Group available, get out! |
|
300 | + if (! $message_template_group instanceof EE_Message_Template_Group) { |
|
301 | + $this->_error_msg[] = esc_html__( |
|
302 | + 'Unable to get the Message Templates for the Message being generated. No message template group accessible.', |
|
303 | + 'event_espresso' |
|
304 | + ); |
|
305 | + return false; |
|
306 | + } |
|
307 | + |
|
308 | + // get formatted templates for using to parse and setup EE_Message objects. |
|
309 | + $templates = $this->_get_templates($message_template_group); |
|
310 | + |
|
311 | + |
|
312 | + // setup new EE_Message objects (and add to _ready_queue) |
|
313 | + return $this->_assemble_messages($addressees, $templates, $message_template_group); |
|
314 | + } |
|
315 | + |
|
316 | + |
|
317 | + /** |
|
318 | + * Retrieves the message template group being used for generating messages. |
|
319 | + * Note: this also utilizes the EE_Message_Template_Group_Collection to avoid having to hit the db multiple times. |
|
320 | + * |
|
321 | + * @return EE_Message_Template_Group|null |
|
322 | + * @throws EE_Error |
|
323 | + * @throws InvalidArgumentException |
|
324 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
325 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
326 | + */ |
|
327 | + protected function _get_message_template_group() |
|
328 | + { |
|
329 | + // first see if there is a specific message template group requested (current message in the queue has a specific |
|
330 | + // GRP_ID |
|
331 | + $message_template_group = $this->_specific_message_template_group_from_queue(); |
|
332 | + if ($message_template_group instanceof EE_Message_Template_Group) { |
|
333 | + return $message_template_group; |
|
334 | + } |
|
335 | + |
|
336 | + // get event_ids from the datahandler so we can check to see if there's already a message template group for them |
|
337 | + // in the collection. |
|
338 | + $event_ids = $this->_get_event_ids_from_current_data_handler(); |
|
339 | + $message_template_group = $this->_template_collection->get_by_key( |
|
340 | + $this->_template_collection->getKey( |
|
341 | + $this->_current_messenger->name, |
|
342 | + $this->_current_message_type->name, |
|
343 | + $event_ids |
|
344 | + ) |
|
345 | + ); |
|
346 | + |
|
347 | + // if we have a message template group then no need to hit the database, just return it. |
|
348 | + if ($message_template_group instanceof EE_Message_Template_Group) { |
|
349 | + return $message_template_group; |
|
350 | + } |
|
351 | + |
|
352 | + // okay made it here, so let's get the global group first for this messenger and message type to ensure |
|
353 | + // there is no override set. |
|
354 | + $global_message_template_group = |
|
355 | + $this->_get_global_message_template_group_for_current_messenger_and_message_type(); |
|
356 | + |
|
357 | + if ($global_message_template_group instanceof EE_Message_Template_Group |
|
358 | + && $global_message_template_group->get('MTP_is_override') |
|
359 | + ) { |
|
360 | + return $global_message_template_group; |
|
361 | + } |
|
362 | + |
|
363 | + // if we're still here, that means there was no message template group for the events in the collection and |
|
364 | + // the global message template group for the messenger and message type is not set for override. So next step is |
|
365 | + // to see if there is a common shared custom message template group for this set of events. |
|
366 | + $message_template_group = $this->_get_shared_message_template_for_events($event_ids); |
|
367 | + if ($message_template_group instanceof EE_Message_Template_Group) { |
|
368 | + return $message_template_group; |
|
369 | + } |
|
370 | + |
|
371 | + // STILL here? Okay that means the fallback is to just use the global message template group for this event set. |
|
372 | + // So we'll cache the global group for this event set (so this logic doesn't have to be repeated in this request) |
|
373 | + // and return it. |
|
374 | + if ($global_message_template_group instanceof EE_Message_Template_Group) { |
|
375 | + $this->_template_collection->add( |
|
376 | + $global_message_template_group, |
|
377 | + $event_ids |
|
378 | + ); |
|
379 | + return $global_message_template_group; |
|
380 | + } |
|
381 | + |
|
382 | + // if we land here that means there's NO active message template group for this set. |
|
383 | + // TODO this will be a good target for some optimization down the road. Whenever there is no active message |
|
384 | + // template group for a given event set then cache that result so we don't repeat the logic. However, for now, |
|
385 | + // this should likely bit hit rarely enough that it's not a significant issue. |
|
386 | + return null; |
|
387 | + } |
|
388 | + |
|
389 | + |
|
390 | + /** |
|
391 | + * This checks the current message in the queue and determines if there is a specific Message Template Group |
|
392 | + * requested for that message. |
|
393 | + * |
|
394 | + * @return EE_Message_Template_Group|null |
|
395 | + * @throws EE_Error |
|
396 | + * @throws InvalidArgumentException |
|
397 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
398 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
399 | + */ |
|
400 | + protected function _specific_message_template_group_from_queue() |
|
401 | + { |
|
402 | + // is there a GRP_ID already on the EE_Message object? If there is, then a specific template has been requested |
|
403 | + // so let's use that. |
|
404 | + $GRP_ID = $this->_generation_queue->get_message_repository()->current()->GRP_ID(); |
|
405 | + |
|
406 | + if ($GRP_ID) { |
|
407 | + // attempt to retrieve from repo first |
|
408 | + $message_template_group = $this->_template_collection->get_by_ID($GRP_ID); |
|
409 | + if ($message_template_group instanceof EE_Message_Template_Group) { |
|
410 | + return $message_template_group; // got it! |
|
411 | + } |
|
412 | + |
|
413 | + // nope don't have it yet. Get from DB then add to repo if its not here, then that means the current GRP_ID |
|
414 | + // is not valid, so we'll continue on in the code assuming there's NO GRP_ID. |
|
415 | + $message_template_group = EEM_Message_Template_Group::instance()->get_one_by_ID($GRP_ID); |
|
416 | + if ($message_template_group instanceof EE_Message_Template_Group) { |
|
417 | + $this->_template_collection->add($message_template_group); |
|
418 | + return $message_template_group; |
|
419 | + } |
|
420 | + } |
|
421 | + return null; |
|
422 | + } |
|
423 | + |
|
424 | + |
|
425 | + /** |
|
426 | + * Returns whether the event ids passed in all share the same message template group for the current message type |
|
427 | + * and messenger. |
|
428 | + * |
|
429 | + * @param array $event_ids |
|
430 | + * @return bool true means they DO share the same message template group, false means they don't. |
|
431 | + * @throws EE_Error |
|
432 | + * @throws InvalidArgumentException |
|
433 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
434 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
435 | + */ |
|
436 | + protected function _queue_shares_same_message_template_group_for_events(array $event_ids) |
|
437 | + { |
|
438 | + foreach ($this->_current_data_handler->events as $event) { |
|
439 | + $event_ids[ $event['ID'] ] = $event['ID']; |
|
440 | + } |
|
441 | + $count_of_message_template_groups = EEM_Message_Template_Group::instance()->count( |
|
442 | + array( |
|
443 | + array( |
|
444 | + 'Event.EVT_ID' => array('IN', $event_ids), |
|
445 | + 'MTP_messenger' => $this->_current_messenger->name, |
|
446 | + 'MTP_message_type' => $this->_current_message_type->name, |
|
447 | + ), |
|
448 | + ), |
|
449 | + 'GRP_ID', |
|
450 | + true |
|
451 | + ); |
|
452 | + return $count_of_message_template_groups === 1; |
|
453 | + } |
|
454 | + |
|
455 | + |
|
456 | + /** |
|
457 | + * This will get the shared message template group for events that are in the current data handler but ONLY if |
|
458 | + * there's a single shared message template group among all the events. Otherwise it returns null. |
|
459 | + * |
|
460 | + * @param array $event_ids |
|
461 | + * @return EE_Message_Template_Group|null |
|
462 | + * @throws EE_Error |
|
463 | + * @throws InvalidArgumentException |
|
464 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
465 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
466 | + */ |
|
467 | + protected function _get_shared_message_template_for_events(array $event_ids) |
|
468 | + { |
|
469 | + $message_template_group = null; |
|
470 | + if ($this->_queue_shares_same_message_template_group_for_events($event_ids)) { |
|
471 | + $message_template_group = EEM_Message_Template_Group::instance()->get_one( |
|
472 | + array( |
|
473 | + array( |
|
474 | + 'Event.EVT_ID' => array('IN', $event_ids), |
|
475 | + 'MTP_messenger' => $this->_current_messenger->name, |
|
476 | + 'MTP_message_type' => $this->_current_message_type->name, |
|
477 | + 'MTP_is_active' => true, |
|
478 | + ), |
|
479 | + 'group_by' => 'GRP_ID', |
|
480 | + ) |
|
481 | + ); |
|
482 | + // store this in the collection if its valid |
|
483 | + if ($message_template_group instanceof EE_Message_Template_Group) { |
|
484 | + $this->_template_collection->add( |
|
485 | + $message_template_group, |
|
486 | + $event_ids |
|
487 | + ); |
|
488 | + } |
|
489 | + } |
|
490 | + return $message_template_group; |
|
491 | + } |
|
492 | + |
|
493 | + |
|
494 | + /** |
|
495 | + * Retrieves the global message template group for the current messenger and message type. |
|
496 | + * |
|
497 | + * @return EE_Message_Template_Group|null |
|
498 | + * @throws EE_Error |
|
499 | + * @throws InvalidArgumentException |
|
500 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
501 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
502 | + */ |
|
503 | + protected function _get_global_message_template_group_for_current_messenger_and_message_type() |
|
504 | + { |
|
505 | + // first check the collection (we use an array with 0 in it to represent global groups). |
|
506 | + $global_message_template_group = $this->_template_collection->get_by_key( |
|
507 | + $this->_template_collection->getKey( |
|
508 | + $this->_current_messenger->name, |
|
509 | + $this->_current_message_type->name, |
|
510 | + array(0) |
|
511 | + ) |
|
512 | + ); |
|
513 | + |
|
514 | + // if we don't have a group lets hit the db. |
|
515 | + if (! $global_message_template_group instanceof EE_Message_Template_Group) { |
|
516 | + $global_message_template_group = EEM_Message_Template_Group::instance()->get_one( |
|
517 | + array( |
|
518 | + array( |
|
519 | + 'MTP_messenger' => $this->_current_messenger->name, |
|
520 | + 'MTP_message_type' => $this->_current_message_type->name, |
|
521 | + 'MTP_is_active' => true, |
|
522 | + 'MTP_is_global' => true, |
|
523 | + ), |
|
524 | + ) |
|
525 | + ); |
|
526 | + // if we have a group, add it to the collection. |
|
527 | + if ($global_message_template_group instanceof EE_Message_Template_Group) { |
|
528 | + $this->_template_collection->add( |
|
529 | + $global_message_template_group, |
|
530 | + array(0) |
|
531 | + ); |
|
532 | + } |
|
533 | + } |
|
534 | + return $global_message_template_group; |
|
535 | + } |
|
536 | + |
|
537 | + |
|
538 | + /** |
|
539 | + * Returns an array of event ids for all the events within the current data handler. |
|
540 | + * |
|
541 | + * @return array |
|
542 | + */ |
|
543 | + protected function _get_event_ids_from_current_data_handler() |
|
544 | + { |
|
545 | + $event_ids = array(); |
|
546 | + foreach ($this->_current_data_handler->events as $event) { |
|
547 | + $event_ids[ $event['ID'] ] = $event['ID']; |
|
548 | + } |
|
549 | + return $event_ids; |
|
550 | + } |
|
551 | + |
|
552 | + |
|
553 | + /** |
|
554 | + * Retrieves formatted array of template information for each context specific to the given |
|
555 | + * EE_Message_Template_Group |
|
556 | + * |
|
557 | + * @param EE_Message_Template_Group $message_template_group |
|
558 | + * @return array The returned array is in this structure: |
|
559 | + * array( |
|
560 | + * 'field_name' => array( |
|
561 | + * 'context' => 'content' |
|
562 | + * ) |
|
563 | + * ) |
|
564 | + * @throws EE_Error |
|
565 | + */ |
|
566 | + protected function _get_templates(EE_Message_Template_Group $message_template_group) |
|
567 | + { |
|
568 | + $templates = array(); |
|
569 | + $context_templates = $message_template_group->context_templates(); |
|
570 | + foreach ($context_templates as $context => $template_fields) { |
|
571 | + foreach ($template_fields as $template_field => $template_obj) { |
|
572 | + if (! $template_obj instanceof EE_Message_Template) { |
|
573 | + continue; |
|
574 | + } |
|
575 | + $templates[ $template_field ][ $context ] = $template_obj->get('MTP_content'); |
|
576 | + } |
|
577 | + } |
|
578 | + return $templates; |
|
579 | + } |
|
580 | + |
|
581 | + |
|
582 | + /** |
|
583 | + * Assembles new fully generated EE_Message objects and adds to _ready_queue |
|
584 | + * |
|
585 | + * @param array $addressees Array of EE_Messages_Addressee objects indexed by message type |
|
586 | + * context. |
|
587 | + * @param array $templates formatted array of templates used for parsing data. |
|
588 | + * @param EE_Message_Template_Group $message_template_group |
|
589 | + * @return bool true if message generation went a-ok. false if some sort of exception occurred. Note: The |
|
590 | + * method will attempt to generate ALL EE_Message objects and add to |
|
591 | + * the _ready_queue. Successfully generated messages get added to the |
|
592 | + * queue with EEM_Message::status_idle, unsuccessfully generated |
|
593 | + * messages will get added to the queue as EEM_Message::status_failed. |
|
594 | + * Very rarely should "false" be returned from this method. |
|
595 | + * @throws EE_Error |
|
596 | + */ |
|
597 | + protected function _assemble_messages($addressees, $templates, EE_Message_Template_Group $message_template_group) |
|
598 | + { |
|
599 | + |
|
600 | + // if templates are empty then get out because we can't generate anything. |
|
601 | + if (! $templates) { |
|
602 | + $this->_error_msg[] = esc_html__( |
|
603 | + 'Unable to assemble messages because there are no templates retrieved for generating the messages with', |
|
604 | + 'event_espresso' |
|
605 | + ); |
|
606 | + return false; |
|
607 | + } |
|
608 | + |
|
609 | + // We use this as the counter for generated messages because don't forget we may be executing this inside of a |
|
610 | + // generation_queue. So _ready_queue may have generated EE_Message objects already. |
|
611 | + $generated_count = 0; |
|
612 | + foreach ($addressees as $context => $recipients) { |
|
613 | + foreach ($recipients as $recipient) { |
|
614 | + $message = $this->_setup_message_object($context, $recipient, $templates, $message_template_group); |
|
615 | + if ($message instanceof EE_Message) { |
|
616 | + $this->_ready_queue->add( |
|
617 | + $message, |
|
618 | + array(), |
|
619 | + $this->_generation_queue->get_message_repository()->is_preview(), |
|
620 | + $this->_generation_queue->get_message_repository()->is_test_send() |
|
621 | + ); |
|
622 | + $generated_count++; |
|
623 | + } |
|
624 | + |
|
625 | + // if the current MSG being generated is for a test send then we'll only use ONE message in the |
|
626 | + // generation. |
|
627 | + if ($this->_generation_queue->get_message_repository()->is_test_send()) { |
|
628 | + break 2; |
|
629 | + } |
|
630 | + } |
|
631 | + } |
|
632 | + |
|
633 | + // if there are no generated messages then something else fatal went wrong. |
|
634 | + return $generated_count > 0; |
|
635 | + } |
|
636 | + |
|
637 | + |
|
638 | + /** |
|
639 | + * @param string $context The context for the generated message. |
|
640 | + * @param EE_Messages_Addressee $recipient |
|
641 | + * @param array $templates formatted array of templates used for parsing data. |
|
642 | + * @param EE_Message_Template_Group $message_template_group |
|
643 | + * @return bool|EE_Message |
|
644 | + * @throws EE_Error |
|
645 | + */ |
|
646 | + protected function _setup_message_object( |
|
647 | + $context, |
|
648 | + EE_Messages_Addressee $recipient, |
|
649 | + $templates, |
|
650 | + EE_Message_Template_Group $message_template_group |
|
651 | + ) { |
|
652 | + // stuff we already know |
|
653 | + $transaction_id = $recipient->txn instanceof EE_Transaction ? $recipient->txn->ID() : 0; |
|
654 | + $transaction_id = empty($transaction_id) && $this->_current_data_handler->txn instanceof EE_Transaction |
|
655 | + ? $this->_current_data_handler->txn->ID() |
|
656 | + : $transaction_id; |
|
657 | + $message_fields = array( |
|
658 | + 'GRP_ID' => $message_template_group->ID(), |
|
659 | + 'TXN_ID' => $transaction_id, |
|
660 | + 'MSG_messenger' => $this->_current_messenger->name, |
|
661 | + 'MSG_message_type' => $this->_current_message_type->name, |
|
662 | + 'MSG_context' => $context, |
|
663 | + ); |
|
664 | + |
|
665 | + // recipient id and type should be on the EE_Messages_Addressee object but if this is empty, let's try to grab |
|
666 | + // the info from the att_obj found in the EE_Messages_Addressee object. |
|
667 | + if (empty($recipient->recipient_id) || empty($recipient->recipient_type)) { |
|
668 | + $message_fields['MSG_recipient_ID'] = $recipient->att_obj instanceof EE_Attendee |
|
669 | + ? $recipient->att_obj->ID() |
|
670 | + : 0; |
|
671 | + $message_fields['MSG_recipient_type'] = 'Attendee'; |
|
672 | + } else { |
|
673 | + $message_fields['MSG_recipient_ID'] = $recipient->recipient_id; |
|
674 | + $message_fields['MSG_recipient_type'] = $recipient->recipient_type; |
|
675 | + } |
|
676 | + $message = EE_Message_Factory::create($message_fields); |
|
677 | + |
|
678 | + // grab valid shortcodes for shortcode parser |
|
679 | + $mt_shortcodes = $this->_current_message_type->get_valid_shortcodes(); |
|
680 | + $m_shortcodes = $this->_current_messenger->get_valid_shortcodes(); |
|
681 | + |
|
682 | + // if the 'to' field is empty or the context is inactive we skip EXCEPT if we're previewing |
|
683 | + if (( |
|
684 | + ( |
|
685 | + empty($templates['to'][ $context ]) |
|
686 | + && ! $this->_current_messenger->allow_empty_to_field() |
|
687 | + ) |
|
688 | + || ! $message_template_group->is_context_active($context) |
|
689 | + ) |
|
690 | + && ! $this->_generation_queue->get_message_repository()->is_preview() |
|
691 | + ) { |
|
692 | + // we silently exit here and do NOT record a fail because the message is "turned off" by having no "to" |
|
693 | + // field. |
|
694 | + return false; |
|
695 | + } |
|
696 | + $error_msg = array(); |
|
697 | + foreach ($templates as $field => $field_context) { |
|
698 | + $error_msg = array(); |
|
699 | + // let's setup the valid shortcodes for the incoming context. |
|
700 | + $valid_shortcodes = $mt_shortcodes[ $context ]; |
|
701 | + // merge in valid shortcodes for the field. |
|
702 | + $shortcodes = isset($m_shortcodes[ $field ]) ? $m_shortcodes[ $field ] : $valid_shortcodes; |
|
703 | + if (isset($templates[ $field ][ $context ])) { |
|
704 | + // prefix field. |
|
705 | + $column_name = 'MSG_' . $field; |
|
706 | + try { |
|
707 | + $content = $this->_shortcode_parser->parse_message_template( |
|
708 | + $templates[ $field ][ $context ], |
|
709 | + $recipient, |
|
710 | + $shortcodes, |
|
711 | + $this->_current_message_type, |
|
712 | + $this->_current_messenger, |
|
713 | + $message |
|
714 | + ); |
|
715 | + // the model field removes slashes when setting (usually necessary when the input is from the |
|
716 | + // request) but this value is from another model and has no slashes. So add them so it matchces |
|
717 | + // what the field expected (otherwise slashes will have been stripped from this an extra time) |
|
718 | + $message->set_field_or_extra_meta($column_name, addslashes($content)); |
|
719 | + } catch (EE_Error $e) { |
|
720 | + $error_msg[] = sprintf( |
|
721 | + esc_html__( |
|
722 | + 'There was a problem generating the content for the field %s: %s', |
|
723 | + 'event_espresso' |
|
724 | + ), |
|
725 | + $field, |
|
726 | + $e->getMessage() |
|
727 | + ); |
|
728 | + $message->set_STS_ID(EEM_Message::status_failed); |
|
729 | + } |
|
730 | + } |
|
731 | + } |
|
732 | + |
|
733 | + if ($message->STS_ID() === EEM_Message::status_failed) { |
|
734 | + $error_msg = esc_html__('There were problems generating this message:', 'event_espresso') |
|
735 | + . "\n" |
|
736 | + . implode("\n", $error_msg); |
|
737 | + $message->set_error_message($error_msg); |
|
738 | + } else { |
|
739 | + $message->set_STS_ID(EEM_Message::status_idle); |
|
740 | + } |
|
741 | + return $message; |
|
742 | + } |
|
743 | + |
|
744 | + |
|
745 | + /** |
|
746 | + * This verifies that the incoming array has a EE_messenger object and a EE_message_type object and sets appropriate |
|
747 | + * error message if either is missing. |
|
748 | + * |
|
749 | + * @return bool true means there were no errors, false means there were errors. |
|
750 | + * @throws EE_Error |
|
751 | + * @throws ReflectionException |
|
752 | + */ |
|
753 | + protected function _verify() |
|
754 | + { |
|
755 | + // reset error message to an empty array. |
|
756 | + $this->_error_msg = array(); |
|
757 | + $valid = true; |
|
758 | + $valid = $valid ? $this->_validate_messenger_and_message_type() : $valid; |
|
759 | + $valid = $valid ? $this->_validate_and_setup_data() : $valid; |
|
760 | + |
|
761 | + // set the verified flag so we know everything has been validated. |
|
762 | + $this->_verified = $valid; |
|
763 | + |
|
764 | + return $valid; |
|
765 | + } |
|
766 | + |
|
767 | + |
|
768 | + /** |
|
769 | + * This accepts an array and validates that it is an array indexed by context with each value being an array of |
|
770 | + * EE_Messages_Addressee objects. |
|
771 | + * |
|
772 | + * @param array $addressees Keys correspond to contexts for the message type and values are EE_Messages_Addressee[] |
|
773 | + * @return bool |
|
774 | + */ |
|
775 | + protected function _valid_addressees($addressees) |
|
776 | + { |
|
777 | + if (! $addressees || ! is_array($addressees)) { |
|
778 | + return false; |
|
779 | + } |
|
780 | + |
|
781 | + foreach ($addressees as $addressee_array) { |
|
782 | + foreach ($addressee_array as $addressee) { |
|
783 | + if (! $addressee instanceof EE_Messages_Addressee) { |
|
784 | + return false; |
|
785 | + } |
|
786 | + } |
|
787 | + } |
|
788 | + return true; |
|
789 | + } |
|
790 | + |
|
791 | + |
|
792 | + /** |
|
793 | + * This validates the messenger, message type, and presences of generation data for the current EE_Message in the |
|
794 | + * queue. This process sets error messages if something is wrong. |
|
795 | + * |
|
796 | + * @return bool true is if there are no errors. false is if there is. |
|
797 | + */ |
|
798 | + protected function _validate_messenger_and_message_type() |
|
799 | + { |
|
800 | + |
|
801 | + // first are there any existing error messages? If so then return. |
|
802 | + if ($this->_error_msg) { |
|
803 | + return false; |
|
804 | + } |
|
805 | + /** @type EE_Message $message */ |
|
806 | + $message = $this->_generation_queue->get_message_repository()->current(); |
|
807 | + try { |
|
808 | + $this->_current_messenger = $message->valid_messenger(true) |
|
809 | + ? $message->messenger_object() |
|
810 | + : null; |
|
811 | + } catch (Exception $e) { |
|
812 | + $this->_error_msg[] = $e->getMessage(); |
|
813 | + } |
|
814 | + try { |
|
815 | + $this->_current_message_type = $message->valid_message_type(true) |
|
816 | + ? $message->message_type_object() |
|
817 | + : null; |
|
818 | + } catch (Exception $e) { |
|
819 | + $this->_error_msg[] = $e->getMessage(); |
|
820 | + } |
|
821 | + |
|
822 | + /** |
|
823 | + * Check if there is any generation data, but only if this is not for a preview. |
|
824 | + */ |
|
825 | + if (! $this->_generation_queue->get_message_repository()->get_generation_data() |
|
826 | + && ( |
|
827 | + ! $this->_generation_queue->get_message_repository()->is_preview() |
|
828 | + && $this->_generation_queue->get_message_repository()->get_data_handler() |
|
829 | + !== 'EE_Messages_Preview_incoming_data' |
|
830 | + ) |
|
831 | + ) { |
|
832 | + $this->_error_msg[] = esc_html__( |
|
833 | + 'There is no generation data for this message. Unable to generate.', |
|
834 | + 'event_espresso' |
|
835 | + ); |
|
836 | + } |
|
837 | + |
|
838 | + return empty($this->_error_msg); |
|
839 | + } |
|
840 | + |
|
841 | + |
|
842 | + /** |
|
843 | + * This method retrieves the expected data handler for the message type and validates the generation data for that |
|
844 | + * data handler. |
|
845 | + * |
|
846 | + * @return bool true means there are no errors. false means there were errors (and handler did not get setup). |
|
847 | + * @throws EE_Error |
|
848 | + * @throws ReflectionException |
|
849 | + */ |
|
850 | + protected function _validate_and_setup_data() |
|
851 | + { |
|
852 | + |
|
853 | + // First, are there any existing error messages? If so, return because if there were errors elsewhere this can't |
|
854 | + // be used anyways. |
|
855 | + if ($this->_error_msg) { |
|
856 | + return false; |
|
857 | + } |
|
858 | + |
|
859 | + $generation_data = $this->_generation_queue->get_message_repository()->get_generation_data(); |
|
860 | + |
|
861 | + /** @type EE_Messages_incoming_data $data_handler_class_name - well not really... just the class name actually*/ |
|
862 | + $data_handler_class_name = $this->_generation_queue->get_message_repository()->get_data_handler() |
|
863 | + ? $this->_generation_queue->get_message_repository()->get_data_handler() |
|
864 | + : 'EE_Messages_' . $this->_current_message_type->get_data_handler($generation_data) . '_incoming_data'; |
|
865 | + |
|
866 | + // If this EE_Message is for a preview, then let's switch out to the preview data handler. |
|
867 | + if ($this->_generation_queue->get_message_repository()->is_preview()) { |
|
868 | + $data_handler_class_name = 'EE_Messages_Preview_incoming_data'; |
|
869 | + } |
|
870 | + |
|
871 | + // First get the class name for the data handler (and also verifies it exists. |
|
872 | + if (! class_exists($data_handler_class_name)) { |
|
873 | + $this->_error_msg[] = sprintf( |
|
874 | + esc_html__( |
|
875 | + 'The included data handler class name does not match any valid, accessible, "%1$s" classes. Looking for %2$s.', |
|
876 | + 'event_espresso' |
|
877 | + ), |
|
878 | + 'EE_Messages_incoming_data', |
|
879 | + $data_handler_class_name |
|
880 | + ); |
|
881 | + return false; |
|
882 | + } |
|
883 | + |
|
884 | + // convert generation_data for data_handler_instantiation. |
|
885 | + $generation_data = $data_handler_class_name::convert_data_from_persistent_storage($generation_data); |
|
886 | + |
|
887 | + // note, this may set error messages as well. |
|
888 | + $this->_set_data_handler($generation_data, $data_handler_class_name); |
|
889 | + |
|
890 | + return empty($this->_error_msg); |
|
891 | + } |
|
892 | + |
|
893 | + |
|
894 | + /** |
|
895 | + * Sets the $_current_data_handler property that is used for generating the current EE_Message in the queue, and |
|
896 | + * adds it to the _data repository. |
|
897 | + * |
|
898 | + * @param mixed $generating_data This is data expected by the instantiated data handler. |
|
899 | + * @param string $data_handler_class_name This is the reference string indicating what data handler is being |
|
900 | + * instantiated. |
|
901 | + * @return void . |
|
902 | + * @throws EE_Error |
|
903 | + * @throws ReflectionException |
|
904 | + */ |
|
905 | + protected function _set_data_handler($generating_data, $data_handler_class_name) |
|
906 | + { |
|
907 | + // valid classname for the data handler. Now let's setup the key for the data handler repository to see if there |
|
908 | + // is already a ready data handler in the repository. |
|
909 | + $this->_current_data_handler = $this->_data_handler_collection->get_by_key( |
|
910 | + $this->_data_handler_collection->get_key( |
|
911 | + $data_handler_class_name, |
|
912 | + $generating_data |
|
913 | + ) |
|
914 | + ); |
|
915 | + if (! $this->_current_data_handler instanceof EE_Messages_incoming_data) { |
|
916 | + // no saved data_handler in the repo so let's set one up and add it to the repo. |
|
917 | + try { |
|
918 | + $this->_current_data_handler = new $data_handler_class_name($generating_data); |
|
919 | + $this->_data_handler_collection->add($this->_current_data_handler, $generating_data); |
|
920 | + } catch (EE_Error $e) { |
|
921 | + $this->_error_msg[] = $e->get_error(); |
|
922 | + } |
|
923 | + } |
|
924 | + } |
|
925 | + |
|
926 | + |
|
927 | + /** |
|
928 | + * The queued EE_Message for generation does not save the data used for generation as objects |
|
929 | + * because serialization of those objects could be problematic if the data is saved to the db. |
|
930 | + * So this method calls the static method on the associated data_handler for the given message_type |
|
931 | + * and that preps the data for later instantiation when generating. |
|
932 | + * |
|
933 | + * @param EE_Message_To_Generate $message_to_generate |
|
934 | + * @param bool $preview Indicate whether this is being used for a preview or not. |
|
935 | + * @return mixed Prepped data for persisting to the queue. false is returned if unable to prep data. |
|
936 | + */ |
|
937 | + protected function _prepare_data_for_queue(EE_Message_To_Generate $message_to_generate, $preview) |
|
938 | + { |
|
939 | + /** @type EE_Messages_incoming_data $data_handler - well not really... just the class name actually */ |
|
940 | + $data_handler = $message_to_generate->get_data_handler_class_name($preview); |
|
941 | + if (! $message_to_generate->valid()) { |
|
942 | + return false; // unable to get the data because the info in the EE_Message_To_Generate class is invalid. |
|
943 | + } |
|
944 | + return $data_handler::convert_data_for_persistent_storage($message_to_generate->data()); |
|
945 | + } |
|
946 | + |
|
947 | + |
|
948 | + /** |
|
949 | + * This sets up a EEM_Message::status_incomplete EE_Message object and adds it to the generation queue. |
|
950 | + * |
|
951 | + * @param EE_Message_To_Generate $message_to_generate |
|
952 | + * @param bool $test_send Whether this is just a test send or not. Typically used for previews. |
|
953 | + * @throws InvalidArgumentException |
|
954 | + * @throws \EventEspresso\core\exceptions\InvalidDataTypeException |
|
955 | + * @throws \EventEspresso\core\exceptions\InvalidInterfaceException |
|
956 | + */ |
|
957 | + public function create_and_add_message_to_queue(EE_Message_To_Generate $message_to_generate, $test_send = false) |
|
958 | + { |
|
959 | + // prep data |
|
960 | + $data = $this->_prepare_data_for_queue($message_to_generate, $message_to_generate->preview()); |
|
961 | + |
|
962 | + $message = $message_to_generate->get_EE_Message(); |
|
963 | + |
|
964 | + // is there a GRP_ID in the request? |
|
965 | + if ($GRP_ID = EE_Registry::instance()->REQ->get('GRP_ID')) { |
|
966 | + $message->set_GRP_ID($GRP_ID); |
|
967 | + } |
|
968 | + |
|
969 | + if ($data === false) { |
|
970 | + $message->set_STS_ID(EEM_Message::status_failed); |
|
971 | + $message->set_error_message( |
|
972 | + esc_html__( |
|
973 | + 'Unable to prepare data for persistence to the database.', |
|
974 | + 'event_espresso' |
|
975 | + ) |
|
976 | + ); |
|
977 | + } else { |
|
978 | + // make sure that the data handler is cached on the message as well |
|
979 | + $data['data_handler_class_name'] = $message_to_generate->get_data_handler_class_name(); |
|
980 | + } |
|
981 | + |
|
982 | + $this->_generation_queue->add($message, $data, $message_to_generate->preview(), $test_send); |
|
983 | + } |
|
984 | 984 | } |
@@ -258,7 +258,7 @@ discard block |
||
258 | 258 | { |
259 | 259 | // double check verification has run and that everything is ready to work with (saves us having to validate |
260 | 260 | // everything again). |
261 | - if (! $this->_verified) { |
|
261 | + if ( ! $this->_verified) { |
|
262 | 262 | return false; // get out because we don't have a valid setup to work with. |
263 | 263 | } |
264 | 264 | |
@@ -275,7 +275,7 @@ discard block |
||
275 | 275 | |
276 | 276 | |
277 | 277 | // if no addressees then get out because there is nothing to generation (possible bad data). |
278 | - if (! $this->_valid_addressees($addressees)) { |
|
278 | + if ( ! $this->_valid_addressees($addressees)) { |
|
279 | 279 | do_action( |
280 | 280 | 'AHEE__EE_Messages_Generator___generate__invalid_addressees', |
281 | 281 | $this->_generation_queue->get_message_repository()->current(), |
@@ -297,7 +297,7 @@ discard block |
||
297 | 297 | $message_template_group = $this->_get_message_template_group(); |
298 | 298 | |
299 | 299 | // in the unlikely event there is no EE_Message_Template_Group available, get out! |
300 | - if (! $message_template_group instanceof EE_Message_Template_Group) { |
|
300 | + if ( ! $message_template_group instanceof EE_Message_Template_Group) { |
|
301 | 301 | $this->_error_msg[] = esc_html__( |
302 | 302 | 'Unable to get the Message Templates for the Message being generated. No message template group accessible.', |
303 | 303 | 'event_espresso' |
@@ -407,7 +407,7 @@ discard block |
||
407 | 407 | // attempt to retrieve from repo first |
408 | 408 | $message_template_group = $this->_template_collection->get_by_ID($GRP_ID); |
409 | 409 | if ($message_template_group instanceof EE_Message_Template_Group) { |
410 | - return $message_template_group; // got it! |
|
410 | + return $message_template_group; // got it! |
|
411 | 411 | } |
412 | 412 | |
413 | 413 | // nope don't have it yet. Get from DB then add to repo if its not here, then that means the current GRP_ID |
@@ -436,7 +436,7 @@ discard block |
||
436 | 436 | protected function _queue_shares_same_message_template_group_for_events(array $event_ids) |
437 | 437 | { |
438 | 438 | foreach ($this->_current_data_handler->events as $event) { |
439 | - $event_ids[ $event['ID'] ] = $event['ID']; |
|
439 | + $event_ids[$event['ID']] = $event['ID']; |
|
440 | 440 | } |
441 | 441 | $count_of_message_template_groups = EEM_Message_Template_Group::instance()->count( |
442 | 442 | array( |
@@ -512,7 +512,7 @@ discard block |
||
512 | 512 | ); |
513 | 513 | |
514 | 514 | // if we don't have a group lets hit the db. |
515 | - if (! $global_message_template_group instanceof EE_Message_Template_Group) { |
|
515 | + if ( ! $global_message_template_group instanceof EE_Message_Template_Group) { |
|
516 | 516 | $global_message_template_group = EEM_Message_Template_Group::instance()->get_one( |
517 | 517 | array( |
518 | 518 | array( |
@@ -544,7 +544,7 @@ discard block |
||
544 | 544 | { |
545 | 545 | $event_ids = array(); |
546 | 546 | foreach ($this->_current_data_handler->events as $event) { |
547 | - $event_ids[ $event['ID'] ] = $event['ID']; |
|
547 | + $event_ids[$event['ID']] = $event['ID']; |
|
548 | 548 | } |
549 | 549 | return $event_ids; |
550 | 550 | } |
@@ -569,10 +569,10 @@ discard block |
||
569 | 569 | $context_templates = $message_template_group->context_templates(); |
570 | 570 | foreach ($context_templates as $context => $template_fields) { |
571 | 571 | foreach ($template_fields as $template_field => $template_obj) { |
572 | - if (! $template_obj instanceof EE_Message_Template) { |
|
572 | + if ( ! $template_obj instanceof EE_Message_Template) { |
|
573 | 573 | continue; |
574 | 574 | } |
575 | - $templates[ $template_field ][ $context ] = $template_obj->get('MTP_content'); |
|
575 | + $templates[$template_field][$context] = $template_obj->get('MTP_content'); |
|
576 | 576 | } |
577 | 577 | } |
578 | 578 | return $templates; |
@@ -598,7 +598,7 @@ discard block |
||
598 | 598 | { |
599 | 599 | |
600 | 600 | // if templates are empty then get out because we can't generate anything. |
601 | - if (! $templates) { |
|
601 | + if ( ! $templates) { |
|
602 | 602 | $this->_error_msg[] = esc_html__( |
603 | 603 | 'Unable to assemble messages because there are no templates retrieved for generating the messages with', |
604 | 604 | 'event_espresso' |
@@ -682,7 +682,7 @@ discard block |
||
682 | 682 | // if the 'to' field is empty or the context is inactive we skip EXCEPT if we're previewing |
683 | 683 | if (( |
684 | 684 | ( |
685 | - empty($templates['to'][ $context ]) |
|
685 | + empty($templates['to'][$context]) |
|
686 | 686 | && ! $this->_current_messenger->allow_empty_to_field() |
687 | 687 | ) |
688 | 688 | || ! $message_template_group->is_context_active($context) |
@@ -697,15 +697,15 @@ discard block |
||
697 | 697 | foreach ($templates as $field => $field_context) { |
698 | 698 | $error_msg = array(); |
699 | 699 | // let's setup the valid shortcodes for the incoming context. |
700 | - $valid_shortcodes = $mt_shortcodes[ $context ]; |
|
700 | + $valid_shortcodes = $mt_shortcodes[$context]; |
|
701 | 701 | // merge in valid shortcodes for the field. |
702 | - $shortcodes = isset($m_shortcodes[ $field ]) ? $m_shortcodes[ $field ] : $valid_shortcodes; |
|
703 | - if (isset($templates[ $field ][ $context ])) { |
|
702 | + $shortcodes = isset($m_shortcodes[$field]) ? $m_shortcodes[$field] : $valid_shortcodes; |
|
703 | + if (isset($templates[$field][$context])) { |
|
704 | 704 | // prefix field. |
705 | - $column_name = 'MSG_' . $field; |
|
705 | + $column_name = 'MSG_'.$field; |
|
706 | 706 | try { |
707 | 707 | $content = $this->_shortcode_parser->parse_message_template( |
708 | - $templates[ $field ][ $context ], |
|
708 | + $templates[$field][$context], |
|
709 | 709 | $recipient, |
710 | 710 | $shortcodes, |
711 | 711 | $this->_current_message_type, |
@@ -774,13 +774,13 @@ discard block |
||
774 | 774 | */ |
775 | 775 | protected function _valid_addressees($addressees) |
776 | 776 | { |
777 | - if (! $addressees || ! is_array($addressees)) { |
|
777 | + if ( ! $addressees || ! is_array($addressees)) { |
|
778 | 778 | return false; |
779 | 779 | } |
780 | 780 | |
781 | 781 | foreach ($addressees as $addressee_array) { |
782 | 782 | foreach ($addressee_array as $addressee) { |
783 | - if (! $addressee instanceof EE_Messages_Addressee) { |
|
783 | + if ( ! $addressee instanceof EE_Messages_Addressee) { |
|
784 | 784 | return false; |
785 | 785 | } |
786 | 786 | } |
@@ -822,7 +822,7 @@ discard block |
||
822 | 822 | /** |
823 | 823 | * Check if there is any generation data, but only if this is not for a preview. |
824 | 824 | */ |
825 | - if (! $this->_generation_queue->get_message_repository()->get_generation_data() |
|
825 | + if ( ! $this->_generation_queue->get_message_repository()->get_generation_data() |
|
826 | 826 | && ( |
827 | 827 | ! $this->_generation_queue->get_message_repository()->is_preview() |
828 | 828 | && $this->_generation_queue->get_message_repository()->get_data_handler() |
@@ -861,7 +861,7 @@ discard block |
||
861 | 861 | /** @type EE_Messages_incoming_data $data_handler_class_name - well not really... just the class name actually*/ |
862 | 862 | $data_handler_class_name = $this->_generation_queue->get_message_repository()->get_data_handler() |
863 | 863 | ? $this->_generation_queue->get_message_repository()->get_data_handler() |
864 | - : 'EE_Messages_' . $this->_current_message_type->get_data_handler($generation_data) . '_incoming_data'; |
|
864 | + : 'EE_Messages_'.$this->_current_message_type->get_data_handler($generation_data).'_incoming_data'; |
|
865 | 865 | |
866 | 866 | // If this EE_Message is for a preview, then let's switch out to the preview data handler. |
867 | 867 | if ($this->_generation_queue->get_message_repository()->is_preview()) { |
@@ -869,7 +869,7 @@ discard block |
||
869 | 869 | } |
870 | 870 | |
871 | 871 | // First get the class name for the data handler (and also verifies it exists. |
872 | - if (! class_exists($data_handler_class_name)) { |
|
872 | + if ( ! class_exists($data_handler_class_name)) { |
|
873 | 873 | $this->_error_msg[] = sprintf( |
874 | 874 | esc_html__( |
875 | 875 | 'The included data handler class name does not match any valid, accessible, "%1$s" classes. Looking for %2$s.', |
@@ -912,7 +912,7 @@ discard block |
||
912 | 912 | $generating_data |
913 | 913 | ) |
914 | 914 | ); |
915 | - if (! $this->_current_data_handler instanceof EE_Messages_incoming_data) { |
|
915 | + if ( ! $this->_current_data_handler instanceof EE_Messages_incoming_data) { |
|
916 | 916 | // no saved data_handler in the repo so let's set one up and add it to the repo. |
917 | 917 | try { |
918 | 918 | $this->_current_data_handler = new $data_handler_class_name($generating_data); |
@@ -938,7 +938,7 @@ discard block |
||
938 | 938 | { |
939 | 939 | /** @type EE_Messages_incoming_data $data_handler - well not really... just the class name actually */ |
940 | 940 | $data_handler = $message_to_generate->get_data_handler_class_name($preview); |
941 | - if (! $message_to_generate->valid()) { |
|
941 | + if ( ! $message_to_generate->valid()) { |
|
942 | 942 | return false; // unable to get the data because the info in the EE_Message_To_Generate class is invalid. |
943 | 943 | } |
944 | 944 | return $data_handler::convert_data_for_persistent_storage($message_to_generate->data()); |
@@ -10,22 +10,22 @@ discard block |
||
10 | 10 | * @var int $message_template_group_id The ID for the message template group this context belongs to. |
11 | 11 | */ |
12 | 12 | $active_message = sprintf( |
13 | - esc_html__( |
|
14 | - 'The template for %1$s is currently %2$sactive%3$s.', |
|
15 | - 'event_espresso' |
|
16 | - ), |
|
17 | - $context_label, |
|
18 | - '<strong>', |
|
19 | - '</strong>' |
|
13 | + esc_html__( |
|
14 | + 'The template for %1$s is currently %2$sactive%3$s.', |
|
15 | + 'event_espresso' |
|
16 | + ), |
|
17 | + $context_label, |
|
18 | + '<strong>', |
|
19 | + '</strong>' |
|
20 | 20 | ); |
21 | 21 | $inactive_message = sprintf( |
22 | - esc_html__( |
|
23 | - 'The template for %1$s is currently %2$sinactive%3$s.', |
|
24 | - 'event_espresso' |
|
25 | - ), |
|
26 | - $context_label, |
|
27 | - '<strong>', |
|
28 | - '</strong>' |
|
22 | + esc_html__( |
|
23 | + 'The template for %1$s is currently %2$sinactive%3$s.', |
|
24 | + 'event_espresso' |
|
25 | + ), |
|
26 | + $context_label, |
|
27 | + '<strong>', |
|
28 | + '</strong>' |
|
29 | 29 | ); |
30 | 30 | ?> |
31 | 31 | <div class="context-active-control-container"> |
@@ -34,8 +34,8 @@ discard block |
||
34 | 34 | <span id="on-off-nonce-<?php echo $context; ?>" class="hidden"><?php echo $nonce; ?></span> |
35 | 35 | <span class="ee-on-off-toggle-label"> |
36 | 36 | <?php |
37 | - echo $is_active ? $active_message : $inactive_message; |
|
38 | - ?> |
|
37 | + echo $is_active ? $active_message : $inactive_message; |
|
38 | + ?> |
|
39 | 39 | </span> |
40 | 40 | <div class="hidden js-data"> |
41 | 41 | <span class="ee-active-message"><?php echo $active_message; ?></span> |
@@ -43,8 +43,8 @@ discard block |
||
43 | 43 | </div> |
44 | 44 | <div class="switch"> |
45 | 45 | <?php |
46 | - $checked = $is_active ? ' checked="checked"' : ''; |
|
47 | - ?> |
|
46 | + $checked = $is_active ? ' checked="checked"' : ''; |
|
47 | + ?> |
|
48 | 48 | <input data-grpid="<?php echo $message_template_group_id; ?>" id="ee-on-off-toggle-<?php echo $context; ?>" type="checkbox" class="ee-on-off-toggle ee-toggle-round-flat"<?php echo $checked; ?> value="<?php echo $on_off_action; ?>"> |
49 | 49 | <label for="ee-on-off-toggle-<?php echo $context; ?>"></label> |
50 | 50 | </div> |
@@ -8,8 +8,8 @@ discard block |
||
8 | 8 | $event_label = 'Testing Context Deactivation'; |
9 | 9 | |
10 | 10 | $I->wantTo( |
11 | - 'Test that the context activation toggle for turning on or off specific contexts for message sending works as' |
|
12 | - . ' expected' |
|
11 | + 'Test that the context activation toggle for turning on or off specific contexts for message sending works as' |
|
12 | + . ' expected' |
|
13 | 13 | ); |
14 | 14 | |
15 | 15 | $I->loginAsAdmin(); |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | $I->see('The template for Primary Registrant Recipient is currently inactive.'); |
35 | 35 | |
36 | 36 | $I->amGoingTo( |
37 | - 'Trigger Registration Approved Messages and verify primary registrant context is excluded from sent messages.' |
|
37 | + 'Trigger Registration Approved Messages and verify primary registrant context is excluded from sent messages.' |
|
38 | 38 | ); |
39 | 39 | $I->amOnDefaultEventsListTablePage(); |
40 | 40 | $I->click(EventsAdmin::ADD_NEW_EVENT_BUTTON_SELECTOR); |
@@ -44,9 +44,9 @@ discard block |
||
44 | 44 | $event_link = $I->observeLinkUrlAt(EventsAdmin::EVENT_EDITOR_VIEW_LINK_AFTER_PUBLISH_SELECTOR); |
45 | 45 | $event_id = $I->observeValueFromInputAt(EventsAdmin::EVENT_EDITOR_EVT_ID_SELECTOR); |
46 | 46 | $test_registration_details = array( |
47 | - 'fname' => 'ContextTestGuy', |
|
48 | - 'lname' => 'ContextTestDude', |
|
49 | - 'email' => '[email protected]', |
|
47 | + 'fname' => 'ContextTestGuy', |
|
48 | + 'lname' => 'ContextTestDude', |
|
49 | + 'email' => '[email protected]', |
|
50 | 50 | ); |
51 | 51 | $I->logOut(); |
52 | 52 | $I->amOnUrl($event_link); |
@@ -63,48 +63,48 @@ discard block |
||
63 | 63 | $I->amOnMessagesActivityListTablePage(); |
64 | 64 | //verify registrant context |
65 | 65 | $I->see( |
66 | - $test_registration_details['email'], |
|
67 | - MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
68 | - 'to', |
|
69 | - 'Registration Approved', |
|
70 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
71 | - '', |
|
72 | - 'Registrant' |
|
73 | - ) |
|
66 | + $test_registration_details['email'], |
|
67 | + MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
68 | + 'to', |
|
69 | + 'Registration Approved', |
|
70 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
71 | + '', |
|
72 | + 'Registrant' |
|
73 | + ) |
|
74 | 74 | ); |
75 | 75 | $I->deleteMessageInMessagesListTableFor( |
76 | - 'Registration Approved', |
|
77 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
78 | - 'Email', |
|
79 | - 'Registrant' |
|
76 | + 'Registration Approved', |
|
77 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
78 | + 'Email', |
|
79 | + 'Registrant' |
|
80 | 80 | ); |
81 | 81 | //verify admin context |
82 | 82 | $I->see( |
83 | - '[email protected]', |
|
84 | - MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
85 | - 'to', |
|
86 | - 'Registration Approved', |
|
87 | - MessagesAdmin::MESSAGE_STATUS_SENT |
|
88 | - ) |
|
83 | + '[email protected]', |
|
84 | + MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
85 | + 'to', |
|
86 | + 'Registration Approved', |
|
87 | + MessagesAdmin::MESSAGE_STATUS_SENT |
|
88 | + ) |
|
89 | 89 | ); |
90 | 90 | $I->deleteMessageInMessagesListTableFor( |
91 | - 'Registration Approved' |
|
91 | + 'Registration Approved' |
|
92 | 92 | ); |
93 | 93 | //verify primary registrant context is NOT present. |
94 | 94 | $I->dontSee( |
95 | - $test_registration_details['email'], |
|
96 | - MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
97 | - 'to', |
|
98 | - 'Registration Approved', |
|
99 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
100 | - '', |
|
101 | - 'Primary Registrant' |
|
102 | - ) |
|
95 | + $test_registration_details['email'], |
|
96 | + MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
97 | + 'to', |
|
98 | + 'Registration Approved', |
|
99 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
100 | + '', |
|
101 | + 'Primary Registrant' |
|
102 | + ) |
|
103 | 103 | ); |
104 | 104 | |
105 | 105 | $I->amGoingTo( |
106 | - 'Deactivate primary registrant context for Registration Approved Message Templates and restore the "To"' |
|
107 | - . ' field to an empty string to verify the message does not send for that context.' |
|
106 | + 'Deactivate primary registrant context for Registration Approved Message Templates and restore the "To"' |
|
107 | + . ' field to an empty string to verify the message does not send for that context.' |
|
108 | 108 | ); |
109 | 109 | $I->amOnDefaultMessageTemplateListTablePage(); |
110 | 110 | $I->clickToEditMessageTemplateByMessageType('registration', 'primary_attendee'); |
@@ -128,41 +128,41 @@ discard block |
||
128 | 128 | $I->amOnMessagesActivityListTablePage(); |
129 | 129 | //verify registrant context |
130 | 130 | $I->see( |
131 | - $test_registration_details['email'], |
|
132 | - MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
133 | - 'to', |
|
134 | - 'Registration Approved', |
|
135 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
136 | - '', |
|
137 | - 'Registrant' |
|
138 | - ) |
|
131 | + $test_registration_details['email'], |
|
132 | + MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
133 | + 'to', |
|
134 | + 'Registration Approved', |
|
135 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
136 | + '', |
|
137 | + 'Registrant' |
|
138 | + ) |
|
139 | 139 | ); |
140 | 140 | $I->deleteMessageInMessagesListTableFor( |
141 | - 'Registration Approved', |
|
142 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
143 | - 'Email', |
|
144 | - 'Registrant' |
|
141 | + 'Registration Approved', |
|
142 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
143 | + 'Email', |
|
144 | + 'Registrant' |
|
145 | 145 | ); |
146 | 146 | //verify admin context |
147 | 147 | $I->see( |
148 | - '[email protected]', |
|
149 | - MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
150 | - 'to', |
|
151 | - 'Registration Approved', |
|
152 | - MessagesAdmin::MESSAGE_STATUS_SENT |
|
153 | - ) |
|
148 | + '[email protected]', |
|
149 | + MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
150 | + 'to', |
|
151 | + 'Registration Approved', |
|
152 | + MessagesAdmin::MESSAGE_STATUS_SENT |
|
153 | + ) |
|
154 | 154 | ); |
155 | 155 | $I->deleteMessageInMessagesListTableFor( |
156 | - 'Registration Approved' |
|
156 | + 'Registration Approved' |
|
157 | 157 | ); |
158 | 158 | //verify primary registrant context is NOT present. |
159 | 159 | $I->dontSee( |
160 | - $test_registration_details['email'], |
|
161 | - MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
162 | - 'to', |
|
163 | - 'Registration Approved', |
|
164 | - MessagesAdmin::MESSAGE_STATUS_SENT, |
|
165 | - '', |
|
166 | - 'Primary Registrant' |
|
167 | - ) |
|
160 | + $test_registration_details['email'], |
|
161 | + MessagesAdmin::messagesActivityListTableCellSelectorFor( |
|
162 | + 'to', |
|
163 | + 'Registration Approved', |
|
164 | + MessagesAdmin::MESSAGE_STATUS_SENT, |
|
165 | + '', |
|
166 | + 'Primary Registrant' |
|
167 | + ) |
|
168 | 168 | ); |
169 | 169 | \ No newline at end of file |
@@ -9,9 +9,9 @@ discard block |
||
9 | 9 | * @ link http://www.eventespresso.com |
10 | 10 | * @ version 4+ |
11 | 11 | */ |
12 | -define( 'EE_THEME_FUNCTIONS_LOADED', TRUE ); |
|
12 | +define('EE_THEME_FUNCTIONS_LOADED', TRUE); |
|
13 | 13 | |
14 | -if ( ! function_exists( 'espresso_pagination' ) ) { |
|
14 | +if ( ! function_exists('espresso_pagination')) { |
|
15 | 15 | /** |
16 | 16 | * espresso_pagination |
17 | 17 | * |
@@ -23,21 +23,21 @@ discard block |
||
23 | 23 | $big = 999999999; // need an unlikely integer |
24 | 24 | $pagination = paginate_links( |
25 | 25 | array( |
26 | - 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
26 | + 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), |
|
27 | 27 | 'format' => '?paged=%#%', |
28 | - 'current' => max( 1, get_query_var( 'paged' ) ), |
|
28 | + 'current' => max(1, get_query_var('paged')), |
|
29 | 29 | 'total' => $wp_query->max_num_pages, |
30 | 30 | 'show_all' => true, |
31 | 31 | 'end_size' => 10, |
32 | 32 | 'mid_size' => 6, |
33 | 33 | 'prev_next' => true, |
34 | - 'prev_text' => __( '‹ PREV', 'event_espresso' ), |
|
35 | - 'next_text' => __( 'NEXT ›', 'event_espresso' ), |
|
34 | + 'prev_text' => __('‹ PREV', 'event_espresso'), |
|
35 | + 'next_text' => __('NEXT ›', 'event_espresso'), |
|
36 | 36 | 'type' => 'plain', |
37 | 37 | 'add_args' => false, |
38 | 38 | 'add_fragment' => '' |
39 | 39 | ) |
40 | 40 | ); |
41 | - echo ! empty( $pagination ) ? '<div class="ee-pagination-dv ee-clear-float">' . $pagination . '</div>' : ''; |
|
41 | + echo ! empty($pagination) ? '<div class="ee-pagination-dv ee-clear-float">'.$pagination.'</div>' : ''; |
|
42 | 42 | } |
43 | 43 | } |
44 | 44 | \ No newline at end of file |
@@ -3,79 +3,79 @@ |
||
3 | 3 | </p> |
4 | 4 | <p> |
5 | 5 | <?php esc_html_e( |
6 | - 'You can select Messengers via the tabs across the top of the settings page. The available messengers you see depends on what version of Event Espresso you have and what addons are installed. Every install include an "Email" messenger tab. When you click one of those tabs it will display that messenger.', |
|
7 | - 'event_espresso' |
|
8 | - ); ?> |
|
6 | + 'You can select Messengers via the tabs across the top of the settings page. The available messengers you see depends on what version of Event Espresso you have and what addons are installed. Every install include an "Email" messenger tab. When you click one of those tabs it will display that messenger.', |
|
7 | + 'event_espresso' |
|
8 | + ); ?> |
|
9 | 9 | </p> |
10 | 10 | <p> |
11 | 11 | <?php esc_html_e( |
12 | - 'There are two ways to determine whether a messenger is active or not. The first way is via the messenger tab itself.', |
|
13 | - 'event_espresso' |
|
14 | - ); ?> |
|
12 | + 'There are two ways to determine whether a messenger is active or not. The first way is via the messenger tab itself.', |
|
13 | + 'event_espresso' |
|
14 | + ); ?> |
|
15 | 15 | </p> |
16 | 16 | <p> |
17 | 17 | <?php printf( |
18 | - esc_html__( |
|
19 | - 'The green colored gear %s indicates that this messenger is currently active.', |
|
20 | - 'event_espresso' |
|
21 | - ), |
|
22 | - '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '"' |
|
23 | - . ' alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />' |
|
24 | - ); |
|
25 | - printf( |
|
26 | - esc_html__( |
|
27 | - ' The white colored gear %s indicates the messenger is inactive. This is very helpful for seeing at a glance all the messengers that are active when you first view the page.', |
|
28 | - 'event_espresso' |
|
29 | - ), |
|
30 | - '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' |
|
31 | - . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />' |
|
32 | - ); ?> |
|
18 | + esc_html__( |
|
19 | + 'The green colored gear %s indicates that this messenger is currently active.', |
|
20 | + 'event_espresso' |
|
21 | + ), |
|
22 | + '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '"' |
|
23 | + . ' alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />' |
|
24 | + ); |
|
25 | + printf( |
|
26 | + esc_html__( |
|
27 | + ' The white colored gear %s indicates the messenger is inactive. This is very helpful for seeing at a glance all the messengers that are active when you first view the page.', |
|
28 | + 'event_espresso' |
|
29 | + ), |
|
30 | + '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' |
|
31 | + . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />' |
|
32 | + ); ?> |
|
33 | 33 | </p> |
34 | 34 | <p> |
35 | 35 | <?php esc_html_e( |
36 | - 'The second way to determine whether a messenger is active or not is via the "on/off" button in the top right corner of the active messenger displayed content:', |
|
37 | - 'event_espresso' |
|
38 | - ); ?> |
|
36 | + 'The second way to determine whether a messenger is active or not is via the "on/off" button in the top right corner of the active messenger displayed content:', |
|
37 | + 'event_espresso' |
|
38 | + ); ?> |
|
39 | 39 | </p> |
40 | 40 | <p> |
41 | 41 | <?php printf( |
42 | - esc_html__( |
|
43 | - '%1$s means of course that the messenger is active and %2$s means the messenger is inactive.', |
|
44 | - 'event_espresso' |
|
45 | - ), |
|
46 | - '<div class="switch">' |
|
47 | - . '<input class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked="checked" disabled>' |
|
48 | - . '<label for="ee-on-off-toggle-on"></label>' |
|
49 | - . '</div>', |
|
50 | - '<div class="switch">' |
|
51 | - . '<input class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" disabled>' |
|
52 | - . '<label for="ee-on-off-toggle-on"></label>' |
|
53 | - . '</div>' |
|
54 | - ); ?> |
|
42 | + esc_html__( |
|
43 | + '%1$s means of course that the messenger is active and %2$s means the messenger is inactive.', |
|
44 | + 'event_espresso' |
|
45 | + ), |
|
46 | + '<div class="switch">' |
|
47 | + . '<input class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" checked="checked" disabled>' |
|
48 | + . '<label for="ee-on-off-toggle-on"></label>' |
|
49 | + . '</div>', |
|
50 | + '<div class="switch">' |
|
51 | + . '<input class="ee-on-off-toggle ee-toggle-round-flat" type="checkbox" disabled>' |
|
52 | + . '<label for="ee-on-off-toggle-on"></label>' |
|
53 | + . '</div>' |
|
54 | + ); ?> |
|
55 | 55 | </p> |
56 | 56 | <p> |
57 | 57 | <?php |
58 | - esc_html_e( |
|
59 | - 'The on/off toggle is also what you use to activate or deactivate a messenger.', |
|
60 | - 'event_espresso' |
|
61 | - ); ?> |
|
58 | + esc_html_e( |
|
59 | + 'The on/off toggle is also what you use to activate or deactivate a messenger.', |
|
60 | + 'event_espresso' |
|
61 | + ); ?> |
|
62 | 62 | </p> |
63 | 63 | <p> |
64 | 64 | <?php esc_html_e( |
65 | - 'What happens when you click the toggle to activate is the messenger is activated and the system determines what default message types are activated with the messenger. Then, if there are any default settings for either the messenger or message types those settings are saved. Next, the system will generate any default templates (if none have been generated before, if there are previously generated templates then they are reactivated). Finally, you will see the display change to reflect that the messenger is active. If the messenger has settings you can modify them then. Any message types that have settings will also automatically expand so you can see the default settings and make any changes as necessary to fit your needs. Usually the defaults are sufficient however.', |
|
66 | - 'event_espresso' |
|
67 | - ); ?> |
|
65 | + 'What happens when you click the toggle to activate is the messenger is activated and the system determines what default message types are activated with the messenger. Then, if there are any default settings for either the messenger or message types those settings are saved. Next, the system will generate any default templates (if none have been generated before, if there are previously generated templates then they are reactivated). Finally, you will see the display change to reflect that the messenger is active. If the messenger has settings you can modify them then. Any message types that have settings will also automatically expand so you can see the default settings and make any changes as necessary to fit your needs. Usually the defaults are sufficient however.', |
|
66 | + 'event_espresso' |
|
67 | + ); ?> |
|
68 | 68 | </p> |
69 | 69 | <p> |
70 | 70 | <?php esc_html_e( |
71 | - 'When you deactivate a messenger, the system will first check if there are any custom event templates for that messenger. If there are you will be unable to deactivate the messenger. This is a fail safe to make sure you know that no messages will go out for those specific events so you don\'t accidentally deactivate. If this check passes, then the system will deactivate any global templates for that messenger (note the templates are not erased, they just become inactive, so if you decide to reactivate the messenger later all your customizations are preserved). Then the display will change to reflect the deactivation.', |
|
72 | - 'event_espresso' |
|
73 | - ); ?> |
|
71 | + 'When you deactivate a messenger, the system will first check if there are any custom event templates for that messenger. If there are you will be unable to deactivate the messenger. This is a fail safe to make sure you know that no messages will go out for those specific events so you don\'t accidentally deactivate. If this check passes, then the system will deactivate any global templates for that messenger (note the templates are not erased, they just become inactive, so if you decide to reactivate the messenger later all your customizations are preserved). Then the display will change to reflect the deactivation.', |
|
72 | + 'event_espresso' |
|
73 | + ); ?> |
|
74 | 74 | </p> |
75 | 75 | <p> |
76 | 76 | <strong><?php esc_html_e('Important', 'event_espresso'); ?></strong><br/> |
77 | 77 | <?php esc_html_e( |
78 | - 'Although customizations made to global templates are preserved when a messenger is deactivated, any settings for that messenger (or the message types that were attached to it) are lost on deactivation. Also, once you deactivate a messenger, no more messages will be delivered using that messenger for any of your events.', |
|
79 | - 'event_espresso' |
|
80 | - ); ?> |
|
78 | + 'Although customizations made to global templates are preserved when a messenger is deactivated, any settings for that messenger (or the message types that were attached to it) are lost on deactivation. Also, once you deactivate a messenger, no more messages will be delivered using that messenger for any of your events.', |
|
79 | + 'event_espresso' |
|
80 | + ); ?> |
|
81 | 81 | </p> |
@@ -19,16 +19,16 @@ |
||
19 | 19 | 'The green colored gear %s indicates that this messenger is currently active.', |
20 | 20 | 'event_espresso' |
21 | 21 | ), |
22 | - '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-active.png' . '"' |
|
23 | - . ' alt="' . esc_attr__('Active Email Tab', 'event_espresso') . '" />' |
|
22 | + '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-active.png'.'"' |
|
23 | + . ' alt="'.esc_attr__('Active Email Tab', 'event_espresso').'" />' |
|
24 | 24 | ); |
25 | 25 | printf( |
26 | 26 | esc_html__( |
27 | 27 | ' The white colored gear %s indicates the messenger is inactive. This is very helpful for seeing at a glance all the messengers that are active when you first view the page.', |
28 | 28 | 'event_espresso' |
29 | 29 | ), |
30 | - '<img class="inline-text" src="' . EE_MSG_ASSETS_URL . 'images/email-tab-inactive.png' |
|
31 | - . '" alt="' . esc_attr__('Inactive Email Tab', 'event_espresso') . '" />' |
|
30 | + '<img class="inline-text" src="'.EE_MSG_ASSETS_URL.'images/email-tab-inactive.png' |
|
31 | + . '" alt="'.esc_attr__('Inactive Email Tab', 'event_espresso').'" />' |
|
32 | 32 | ); ?> |
33 | 33 | </p> |
34 | 34 | <p> |
@@ -176,7 +176,7 @@ |
||
176 | 176 | /** |
177 | 177 | * This retrieves the EE_Venue from the available data object. |
178 | 178 | * |
179 | - * @return EE_Venue|null |
|
179 | + * @return EE_Base_Class|null |
|
180 | 180 | * @throws EE_Error |
181 | 181 | * @throws EntityNotFoundException |
182 | 182 | */ |
@@ -17,315 +17,315 @@ |
||
17 | 17 | { |
18 | 18 | |
19 | 19 | |
20 | - /** |
|
21 | - * Will hold the EE_Event if available |
|
22 | - * |
|
23 | - * @var EE_Event |
|
24 | - */ |
|
25 | - protected $_event; |
|
26 | - |
|
27 | - /** |
|
28 | - * Will hold the EE_Venue if available |
|
29 | - * |
|
30 | - * @var EE_Venue |
|
31 | - */ |
|
32 | - protected $_venue; |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * Initialize properties |
|
37 | - */ |
|
38 | - protected function _init_props() |
|
39 | - { |
|
40 | - $this->label = esc_html__('Venue Shortcodes', 'event_espresso'); |
|
41 | - $this->description = esc_html__('All shortcodes specific to venue related data', 'event_espresso'); |
|
42 | - $this->_shortcodes = array( |
|
43 | - '[VENUE_TITLE]' => esc_html__('The title for the event venue', 'event_espresso'), |
|
44 | - '[VENUE_DESCRIPTION]' => esc_html__('The description for the event venue', 'event_espresso'), |
|
45 | - '[VENUE_URL]' => esc_html__('A url to a webpage for the venue', 'event_espresso'), |
|
46 | - '[VENUE_DETAILS_URL]' => sprintf( |
|
47 | - esc_html__( |
|
48 | - 'This shortcode outputs the url or website address to the venue details page on this website. This differs from %s which outputs what is entered in the "url" field in the venue details page.', |
|
49 | - 'event_espresso' |
|
50 | - ), |
|
51 | - '[VENUE_URL]' |
|
52 | - ), |
|
53 | - '[VENUE_IMAGE]' => esc_html__('An image representing the event venue', 'event_espresso'), |
|
54 | - '[VENUE_PHONE]' => esc_html__('The phone number for the venue', 'event_espresso'), |
|
55 | - '[VENUE_ADDRESS]' => esc_html__('The address for the venue', 'event_espresso'), |
|
56 | - '[VENUE_ADDRESS2]' => esc_html__('Address 2 for the venue', 'event_espresso'), |
|
57 | - '[VENUE_CITY]' => esc_html__('The city the venue is in', 'event_espresso'), |
|
58 | - '[VENUE_STATE]' => esc_html__('The state the venue is located in', 'event_espresso'), |
|
59 | - '[VENUE_COUNTRY]' => esc_html__('The country the venue is located in', 'event_espresso'), |
|
60 | - '[VENUE_FORMATTED_ADDRESS]' => esc_html__( |
|
61 | - 'This just outputs the venue address in a semantic address format.', |
|
62 | - 'event_espresso' |
|
63 | - ), |
|
64 | - '[VENUE_ZIP]' => esc_html__('The zip code for the venue address', 'event_espresso'), |
|
65 | - '[VENUE_META_*]' => esc_html__( |
|
66 | - 'This is a special dynamic shortcode. After the "*", add the exact name for your custom field, if there is a value set for that custom field within the venue then it will be output in place of this shortcode.', |
|
67 | - 'event_espresso' |
|
68 | - ), |
|
69 | - '[GOOGLE_MAP_URL]' => esc_html__( |
|
70 | - 'URL for the google map associated with the venue.', |
|
71 | - 'event_espresso' |
|
72 | - ), |
|
73 | - '[GOOGLE_MAP_LINK]' => esc_html__('Link to a google map for the venue', 'event_espresso'), |
|
74 | - '[GOOGLE_MAP_IMAGE]' => esc_html__('Google map for venue wrapped in image tags', 'event_espresso'), |
|
75 | - ); |
|
76 | - } |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * Parse incoming shortcode |
|
81 | - * |
|
82 | - * @param string $shortcode |
|
83 | - * @return string |
|
84 | - * @throws EE_Error |
|
85 | - * @throws EntityNotFoundException |
|
86 | - */ |
|
87 | - protected function _parser($shortcode) |
|
88 | - { |
|
89 | - $this->_venue = $this->_get_venue(); |
|
90 | - // If there is no venue object by now then get out. |
|
91 | - if (! $this->_venue instanceof EE_Venue) { |
|
92 | - return ''; |
|
93 | - } |
|
94 | - |
|
95 | - switch ($shortcode) { |
|
96 | - case '[VENUE_TITLE]': |
|
97 | - return $this->_venue('title'); |
|
98 | - break; |
|
99 | - |
|
100 | - case '[VENUE_DESCRIPTION]': |
|
101 | - return $this->_venue('description'); |
|
102 | - break; |
|
103 | - |
|
104 | - case '[VENUE_URL]': |
|
105 | - return $this->_venue('url'); |
|
106 | - break; |
|
107 | - |
|
108 | - case '[VENUE_IMAGE]': |
|
109 | - return $this->_venue('image'); |
|
110 | - break; |
|
111 | - |
|
112 | - case '[VENUE_PHONE]': |
|
113 | - return $this->_venue('phone'); |
|
114 | - break; |
|
115 | - |
|
116 | - case '[VENUE_ADDRESS]': |
|
117 | - return $this->_venue('address'); |
|
118 | - break; |
|
119 | - |
|
120 | - case '[VENUE_ADDRESS2]': |
|
121 | - return $this->_venue('address2'); |
|
122 | - break; |
|
123 | - |
|
124 | - case '[VENUE_CITY]': |
|
125 | - return $this->_venue('city'); |
|
126 | - break; |
|
127 | - |
|
128 | - case '[VENUE_COUNTRY]': |
|
129 | - return $this->_venue('country'); |
|
130 | - break; |
|
131 | - |
|
132 | - case '[VENUE_STATE]': |
|
133 | - return $this->_venue('state'); |
|
134 | - break; |
|
135 | - |
|
136 | - case '[VENUE_ZIP]': |
|
137 | - return $this->_venue('zip'); |
|
138 | - break; |
|
139 | - |
|
140 | - case '[VENUE_FORMATTED_ADDRESS]': |
|
141 | - return $this->_venue('formatted_address'); |
|
142 | - break; |
|
143 | - |
|
144 | - case '[GOOGLE_MAP_URL]': |
|
145 | - return $this->_venue('gmap_url'); |
|
146 | - break; |
|
147 | - |
|
148 | - case '[GOOGLE_MAP_LINK]': |
|
149 | - return $this->_venue('gmap_link'); |
|
150 | - break; |
|
151 | - |
|
152 | - case '[GOOGLE_MAP_IMAGE]': |
|
153 | - return $this->_venue('gmap_link_img'); |
|
154 | - break; |
|
155 | - |
|
156 | - case '[VENUE_DETAILS_URL]': |
|
157 | - return $this->_venue('permalink'); |
|
158 | - break; |
|
159 | - } |
|
160 | - |
|
161 | - if (strpos($shortcode, '[VENUE_META_*') !== false) { |
|
162 | - $shortcode = str_replace('[VENUE_META_*', '', $shortcode); |
|
163 | - $shortcode = trim(str_replace(']', '', $shortcode)); |
|
164 | - |
|
165 | - // pull the meta value from the venue post |
|
166 | - $venue_meta = $this->_venue->get_post_meta($shortcode, true); |
|
167 | - |
|
168 | - return ! empty($venue_meta) ? $venue_meta : ''; |
|
169 | - } |
|
170 | - } |
|
171 | - |
|
172 | - /** |
|
173 | - * This retrieves the EE_Venue from the available data object. |
|
174 | - * |
|
175 | - * @return EE_Venue|null |
|
176 | - * @throws EE_Error |
|
177 | - * @throws EntityNotFoundException |
|
178 | - */ |
|
179 | - private function _get_venue() |
|
180 | - { |
|
181 | - |
|
182 | - // we need the EE_Event object to get the venue. |
|
183 | - $this->_event = $this->_data instanceof EE_Event ? $this->_data : null; |
|
184 | - |
|
185 | - // if no event, then let's see if there is a reg_obj. If there IS, then we'll try and grab the event from the |
|
186 | - // reg_obj instead. |
|
187 | - if (! $this->_event instanceof EE_Event) { |
|
188 | - $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
189 | - $aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee; |
|
190 | - |
|
191 | - $this->_event = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration |
|
192 | - ? $aee->reg_obj->event() |
|
193 | - : null; |
|
194 | - |
|
195 | - // if still empty do we have a ticket data item? |
|
196 | - $this->_event = ! $this->_event instanceof EE_Event |
|
197 | - && $this->_data instanceof EE_Ticket |
|
198 | - && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
199 | - ? $this->_extra_data['data']->tickets[ $this->_data->ID() ]['EE_Event'] |
|
200 | - : $this->_event; |
|
201 | - |
|
202 | - // if STILL empty event, let's try to get the first event in the list of events via EE_Messages_Addressee |
|
203 | - // and use that. |
|
204 | - $this->_event = ! $this->_event instanceof EE_Event && $aee instanceof EE_Messages_Addressee |
|
205 | - ? reset($aee->events) |
|
206 | - : $this->_event; |
|
207 | - } |
|
208 | - |
|
209 | - // If we have an event object use it to pull the venue. |
|
210 | - if ($this->_event instanceof EE_Event) { |
|
211 | - return $this->_event->get_first_related('Venue'); |
|
212 | - } |
|
213 | - |
|
214 | - return null; |
|
215 | - } |
|
216 | - |
|
217 | - /** |
|
218 | - * This retrieves the specified venue information |
|
219 | - * |
|
220 | - * @param string $field What Venue field to retrieve |
|
221 | - * @return string What was retrieved! |
|
222 | - * @throws EE_Error |
|
223 | - * @throws EntityNotFoundException |
|
224 | - */ |
|
225 | - private function _venue($field) |
|
226 | - { |
|
227 | - |
|
228 | - if (! $this->_venue instanceof EE_Venue) { |
|
229 | - return ''; |
|
230 | - } //no venue so get out. |
|
231 | - |
|
232 | - switch ($field) { |
|
233 | - case 'title': |
|
234 | - return $this->_venue->get('VNU_name'); |
|
235 | - break; |
|
236 | - |
|
237 | - case 'description': |
|
238 | - return $this->_venue->get('VNU_desc'); |
|
239 | - break; |
|
240 | - |
|
241 | - case 'url': |
|
242 | - $url = $this->_venue->get('VNU_url'); |
|
243 | - return empty($url) ? $this->_venue->get_permalink() : $url; |
|
244 | - break; |
|
245 | - |
|
246 | - case 'permalink': |
|
247 | - return $this->_venue->get_permalink(); |
|
248 | - break; |
|
249 | - |
|
250 | - case 'image': |
|
251 | - return '<img src="' . $this->_venue->feature_image_url(array(200, 200,)) |
|
252 | - . '" alt="' . sprintf( |
|
253 | - esc_attr__('%s Feature Image', 'event_espresso'), |
|
254 | - $this->_venue->get('VNU_name') |
|
255 | - ) . '" />'; |
|
256 | - break; |
|
257 | - |
|
258 | - case 'phone': |
|
259 | - return $this->_venue->get('VNU_phone'); |
|
260 | - break; |
|
261 | - |
|
262 | - case 'address': |
|
263 | - return $this->_venue->get('VNU_address'); |
|
264 | - break; |
|
265 | - |
|
266 | - case 'address2': |
|
267 | - return $this->_venue->get('VNU_address2'); |
|
268 | - break; |
|
269 | - |
|
270 | - case 'city': |
|
271 | - return $this->_venue->get('VNU_city'); |
|
272 | - break; |
|
273 | - |
|
274 | - case 'state': |
|
275 | - $state = $this->_venue->state_obj(); |
|
276 | - return is_object($state) ? $state->get('STA_name') : ''; |
|
277 | - break; |
|
278 | - |
|
279 | - case 'country': |
|
280 | - $country = $this->_venue->country_obj(); |
|
281 | - return is_object($country) ? $country->get('CNT_name') : ''; |
|
282 | - break; |
|
283 | - |
|
284 | - case 'zip': |
|
285 | - return $this->_venue->get('VNU_zip'); |
|
286 | - break; |
|
287 | - |
|
288 | - case 'formatted_address': |
|
289 | - return EEH_Address::format($this->_venue); |
|
290 | - break; |
|
291 | - |
|
292 | - case 'gmap_link': |
|
293 | - case 'gmap_url': |
|
294 | - case 'gmap_link_img': |
|
295 | - $atts = $this->get_map_attributes($this->_venue, $field); |
|
296 | - return EEH_Maps::google_map_link($atts); |
|
297 | - break; |
|
298 | - } |
|
299 | - return ''; |
|
300 | - } |
|
301 | - |
|
302 | - |
|
303 | - /** |
|
304 | - * Generates the attributes for retrieving a google_map artifact. |
|
305 | - * |
|
306 | - * @param EE_Venue $venue |
|
307 | - * @param string $field |
|
308 | - * @return array |
|
309 | - * @throws EE_Error |
|
310 | - */ |
|
311 | - protected function get_map_attributes(EE_Venue $venue, $field = 'gmap_link') |
|
312 | - { |
|
313 | - $state = $venue->state_obj(); |
|
314 | - $country = $venue->country_obj(); |
|
315 | - $atts = array( |
|
316 | - 'id' => $venue->ID(), |
|
317 | - 'address' => $venue->get('VNU_address'), |
|
318 | - 'city' => $venue->get('VNU_city'), |
|
319 | - 'state' => is_object($state) ? $state->get('STA_name') : '', |
|
320 | - 'zip' => $venue->get('VNU_zip'), |
|
321 | - 'country' => is_object($country) ? $country->get('CNT_name') : '', |
|
322 | - 'type' => $field === 'gmap_link' ? 'url' : 'map', |
|
323 | - 'map_w' => 200, |
|
324 | - 'map_h' => 200, |
|
325 | - ); |
|
326 | - if ($field === 'gmap_url') { |
|
327 | - $atts['type'] = 'url_only'; |
|
328 | - } |
|
329 | - return $atts; |
|
330 | - } |
|
20 | + /** |
|
21 | + * Will hold the EE_Event if available |
|
22 | + * |
|
23 | + * @var EE_Event |
|
24 | + */ |
|
25 | + protected $_event; |
|
26 | + |
|
27 | + /** |
|
28 | + * Will hold the EE_Venue if available |
|
29 | + * |
|
30 | + * @var EE_Venue |
|
31 | + */ |
|
32 | + protected $_venue; |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * Initialize properties |
|
37 | + */ |
|
38 | + protected function _init_props() |
|
39 | + { |
|
40 | + $this->label = esc_html__('Venue Shortcodes', 'event_espresso'); |
|
41 | + $this->description = esc_html__('All shortcodes specific to venue related data', 'event_espresso'); |
|
42 | + $this->_shortcodes = array( |
|
43 | + '[VENUE_TITLE]' => esc_html__('The title for the event venue', 'event_espresso'), |
|
44 | + '[VENUE_DESCRIPTION]' => esc_html__('The description for the event venue', 'event_espresso'), |
|
45 | + '[VENUE_URL]' => esc_html__('A url to a webpage for the venue', 'event_espresso'), |
|
46 | + '[VENUE_DETAILS_URL]' => sprintf( |
|
47 | + esc_html__( |
|
48 | + 'This shortcode outputs the url or website address to the venue details page on this website. This differs from %s which outputs what is entered in the "url" field in the venue details page.', |
|
49 | + 'event_espresso' |
|
50 | + ), |
|
51 | + '[VENUE_URL]' |
|
52 | + ), |
|
53 | + '[VENUE_IMAGE]' => esc_html__('An image representing the event venue', 'event_espresso'), |
|
54 | + '[VENUE_PHONE]' => esc_html__('The phone number for the venue', 'event_espresso'), |
|
55 | + '[VENUE_ADDRESS]' => esc_html__('The address for the venue', 'event_espresso'), |
|
56 | + '[VENUE_ADDRESS2]' => esc_html__('Address 2 for the venue', 'event_espresso'), |
|
57 | + '[VENUE_CITY]' => esc_html__('The city the venue is in', 'event_espresso'), |
|
58 | + '[VENUE_STATE]' => esc_html__('The state the venue is located in', 'event_espresso'), |
|
59 | + '[VENUE_COUNTRY]' => esc_html__('The country the venue is located in', 'event_espresso'), |
|
60 | + '[VENUE_FORMATTED_ADDRESS]' => esc_html__( |
|
61 | + 'This just outputs the venue address in a semantic address format.', |
|
62 | + 'event_espresso' |
|
63 | + ), |
|
64 | + '[VENUE_ZIP]' => esc_html__('The zip code for the venue address', 'event_espresso'), |
|
65 | + '[VENUE_META_*]' => esc_html__( |
|
66 | + 'This is a special dynamic shortcode. After the "*", add the exact name for your custom field, if there is a value set for that custom field within the venue then it will be output in place of this shortcode.', |
|
67 | + 'event_espresso' |
|
68 | + ), |
|
69 | + '[GOOGLE_MAP_URL]' => esc_html__( |
|
70 | + 'URL for the google map associated with the venue.', |
|
71 | + 'event_espresso' |
|
72 | + ), |
|
73 | + '[GOOGLE_MAP_LINK]' => esc_html__('Link to a google map for the venue', 'event_espresso'), |
|
74 | + '[GOOGLE_MAP_IMAGE]' => esc_html__('Google map for venue wrapped in image tags', 'event_espresso'), |
|
75 | + ); |
|
76 | + } |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * Parse incoming shortcode |
|
81 | + * |
|
82 | + * @param string $shortcode |
|
83 | + * @return string |
|
84 | + * @throws EE_Error |
|
85 | + * @throws EntityNotFoundException |
|
86 | + */ |
|
87 | + protected function _parser($shortcode) |
|
88 | + { |
|
89 | + $this->_venue = $this->_get_venue(); |
|
90 | + // If there is no venue object by now then get out. |
|
91 | + if (! $this->_venue instanceof EE_Venue) { |
|
92 | + return ''; |
|
93 | + } |
|
94 | + |
|
95 | + switch ($shortcode) { |
|
96 | + case '[VENUE_TITLE]': |
|
97 | + return $this->_venue('title'); |
|
98 | + break; |
|
99 | + |
|
100 | + case '[VENUE_DESCRIPTION]': |
|
101 | + return $this->_venue('description'); |
|
102 | + break; |
|
103 | + |
|
104 | + case '[VENUE_URL]': |
|
105 | + return $this->_venue('url'); |
|
106 | + break; |
|
107 | + |
|
108 | + case '[VENUE_IMAGE]': |
|
109 | + return $this->_venue('image'); |
|
110 | + break; |
|
111 | + |
|
112 | + case '[VENUE_PHONE]': |
|
113 | + return $this->_venue('phone'); |
|
114 | + break; |
|
115 | + |
|
116 | + case '[VENUE_ADDRESS]': |
|
117 | + return $this->_venue('address'); |
|
118 | + break; |
|
119 | + |
|
120 | + case '[VENUE_ADDRESS2]': |
|
121 | + return $this->_venue('address2'); |
|
122 | + break; |
|
123 | + |
|
124 | + case '[VENUE_CITY]': |
|
125 | + return $this->_venue('city'); |
|
126 | + break; |
|
127 | + |
|
128 | + case '[VENUE_COUNTRY]': |
|
129 | + return $this->_venue('country'); |
|
130 | + break; |
|
131 | + |
|
132 | + case '[VENUE_STATE]': |
|
133 | + return $this->_venue('state'); |
|
134 | + break; |
|
135 | + |
|
136 | + case '[VENUE_ZIP]': |
|
137 | + return $this->_venue('zip'); |
|
138 | + break; |
|
139 | + |
|
140 | + case '[VENUE_FORMATTED_ADDRESS]': |
|
141 | + return $this->_venue('formatted_address'); |
|
142 | + break; |
|
143 | + |
|
144 | + case '[GOOGLE_MAP_URL]': |
|
145 | + return $this->_venue('gmap_url'); |
|
146 | + break; |
|
147 | + |
|
148 | + case '[GOOGLE_MAP_LINK]': |
|
149 | + return $this->_venue('gmap_link'); |
|
150 | + break; |
|
151 | + |
|
152 | + case '[GOOGLE_MAP_IMAGE]': |
|
153 | + return $this->_venue('gmap_link_img'); |
|
154 | + break; |
|
155 | + |
|
156 | + case '[VENUE_DETAILS_URL]': |
|
157 | + return $this->_venue('permalink'); |
|
158 | + break; |
|
159 | + } |
|
160 | + |
|
161 | + if (strpos($shortcode, '[VENUE_META_*') !== false) { |
|
162 | + $shortcode = str_replace('[VENUE_META_*', '', $shortcode); |
|
163 | + $shortcode = trim(str_replace(']', '', $shortcode)); |
|
164 | + |
|
165 | + // pull the meta value from the venue post |
|
166 | + $venue_meta = $this->_venue->get_post_meta($shortcode, true); |
|
167 | + |
|
168 | + return ! empty($venue_meta) ? $venue_meta : ''; |
|
169 | + } |
|
170 | + } |
|
171 | + |
|
172 | + /** |
|
173 | + * This retrieves the EE_Venue from the available data object. |
|
174 | + * |
|
175 | + * @return EE_Venue|null |
|
176 | + * @throws EE_Error |
|
177 | + * @throws EntityNotFoundException |
|
178 | + */ |
|
179 | + private function _get_venue() |
|
180 | + { |
|
181 | + |
|
182 | + // we need the EE_Event object to get the venue. |
|
183 | + $this->_event = $this->_data instanceof EE_Event ? $this->_data : null; |
|
184 | + |
|
185 | + // if no event, then let's see if there is a reg_obj. If there IS, then we'll try and grab the event from the |
|
186 | + // reg_obj instead. |
|
187 | + if (! $this->_event instanceof EE_Event) { |
|
188 | + $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
|
189 | + $aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee; |
|
190 | + |
|
191 | + $this->_event = $aee instanceof EE_Messages_Addressee && $aee->reg_obj instanceof EE_Registration |
|
192 | + ? $aee->reg_obj->event() |
|
193 | + : null; |
|
194 | + |
|
195 | + // if still empty do we have a ticket data item? |
|
196 | + $this->_event = ! $this->_event instanceof EE_Event |
|
197 | + && $this->_data instanceof EE_Ticket |
|
198 | + && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
|
199 | + ? $this->_extra_data['data']->tickets[ $this->_data->ID() ]['EE_Event'] |
|
200 | + : $this->_event; |
|
201 | + |
|
202 | + // if STILL empty event, let's try to get the first event in the list of events via EE_Messages_Addressee |
|
203 | + // and use that. |
|
204 | + $this->_event = ! $this->_event instanceof EE_Event && $aee instanceof EE_Messages_Addressee |
|
205 | + ? reset($aee->events) |
|
206 | + : $this->_event; |
|
207 | + } |
|
208 | + |
|
209 | + // If we have an event object use it to pull the venue. |
|
210 | + if ($this->_event instanceof EE_Event) { |
|
211 | + return $this->_event->get_first_related('Venue'); |
|
212 | + } |
|
213 | + |
|
214 | + return null; |
|
215 | + } |
|
216 | + |
|
217 | + /** |
|
218 | + * This retrieves the specified venue information |
|
219 | + * |
|
220 | + * @param string $field What Venue field to retrieve |
|
221 | + * @return string What was retrieved! |
|
222 | + * @throws EE_Error |
|
223 | + * @throws EntityNotFoundException |
|
224 | + */ |
|
225 | + private function _venue($field) |
|
226 | + { |
|
227 | + |
|
228 | + if (! $this->_venue instanceof EE_Venue) { |
|
229 | + return ''; |
|
230 | + } //no venue so get out. |
|
231 | + |
|
232 | + switch ($field) { |
|
233 | + case 'title': |
|
234 | + return $this->_venue->get('VNU_name'); |
|
235 | + break; |
|
236 | + |
|
237 | + case 'description': |
|
238 | + return $this->_venue->get('VNU_desc'); |
|
239 | + break; |
|
240 | + |
|
241 | + case 'url': |
|
242 | + $url = $this->_venue->get('VNU_url'); |
|
243 | + return empty($url) ? $this->_venue->get_permalink() : $url; |
|
244 | + break; |
|
245 | + |
|
246 | + case 'permalink': |
|
247 | + return $this->_venue->get_permalink(); |
|
248 | + break; |
|
249 | + |
|
250 | + case 'image': |
|
251 | + return '<img src="' . $this->_venue->feature_image_url(array(200, 200,)) |
|
252 | + . '" alt="' . sprintf( |
|
253 | + esc_attr__('%s Feature Image', 'event_espresso'), |
|
254 | + $this->_venue->get('VNU_name') |
|
255 | + ) . '" />'; |
|
256 | + break; |
|
257 | + |
|
258 | + case 'phone': |
|
259 | + return $this->_venue->get('VNU_phone'); |
|
260 | + break; |
|
261 | + |
|
262 | + case 'address': |
|
263 | + return $this->_venue->get('VNU_address'); |
|
264 | + break; |
|
265 | + |
|
266 | + case 'address2': |
|
267 | + return $this->_venue->get('VNU_address2'); |
|
268 | + break; |
|
269 | + |
|
270 | + case 'city': |
|
271 | + return $this->_venue->get('VNU_city'); |
|
272 | + break; |
|
273 | + |
|
274 | + case 'state': |
|
275 | + $state = $this->_venue->state_obj(); |
|
276 | + return is_object($state) ? $state->get('STA_name') : ''; |
|
277 | + break; |
|
278 | + |
|
279 | + case 'country': |
|
280 | + $country = $this->_venue->country_obj(); |
|
281 | + return is_object($country) ? $country->get('CNT_name') : ''; |
|
282 | + break; |
|
283 | + |
|
284 | + case 'zip': |
|
285 | + return $this->_venue->get('VNU_zip'); |
|
286 | + break; |
|
287 | + |
|
288 | + case 'formatted_address': |
|
289 | + return EEH_Address::format($this->_venue); |
|
290 | + break; |
|
291 | + |
|
292 | + case 'gmap_link': |
|
293 | + case 'gmap_url': |
|
294 | + case 'gmap_link_img': |
|
295 | + $atts = $this->get_map_attributes($this->_venue, $field); |
|
296 | + return EEH_Maps::google_map_link($atts); |
|
297 | + break; |
|
298 | + } |
|
299 | + return ''; |
|
300 | + } |
|
301 | + |
|
302 | + |
|
303 | + /** |
|
304 | + * Generates the attributes for retrieving a google_map artifact. |
|
305 | + * |
|
306 | + * @param EE_Venue $venue |
|
307 | + * @param string $field |
|
308 | + * @return array |
|
309 | + * @throws EE_Error |
|
310 | + */ |
|
311 | + protected function get_map_attributes(EE_Venue $venue, $field = 'gmap_link') |
|
312 | + { |
|
313 | + $state = $venue->state_obj(); |
|
314 | + $country = $venue->country_obj(); |
|
315 | + $atts = array( |
|
316 | + 'id' => $venue->ID(), |
|
317 | + 'address' => $venue->get('VNU_address'), |
|
318 | + 'city' => $venue->get('VNU_city'), |
|
319 | + 'state' => is_object($state) ? $state->get('STA_name') : '', |
|
320 | + 'zip' => $venue->get('VNU_zip'), |
|
321 | + 'country' => is_object($country) ? $country->get('CNT_name') : '', |
|
322 | + 'type' => $field === 'gmap_link' ? 'url' : 'map', |
|
323 | + 'map_w' => 200, |
|
324 | + 'map_h' => 200, |
|
325 | + ); |
|
326 | + if ($field === 'gmap_url') { |
|
327 | + $atts['type'] = 'url_only'; |
|
328 | + } |
|
329 | + return $atts; |
|
330 | + } |
|
331 | 331 | } |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | { |
89 | 89 | $this->_venue = $this->_get_venue(); |
90 | 90 | // If there is no venue object by now then get out. |
91 | - if (! $this->_venue instanceof EE_Venue) { |
|
91 | + if ( ! $this->_venue instanceof EE_Venue) { |
|
92 | 92 | return ''; |
93 | 93 | } |
94 | 94 | |
@@ -184,7 +184,7 @@ discard block |
||
184 | 184 | |
185 | 185 | // if no event, then let's see if there is a reg_obj. If there IS, then we'll try and grab the event from the |
186 | 186 | // reg_obj instead. |
187 | - if (! $this->_event instanceof EE_Event) { |
|
187 | + if ( ! $this->_event instanceof EE_Event) { |
|
188 | 188 | $aee = $this->_data instanceof EE_Messages_Addressee ? $this->_data : null; |
189 | 189 | $aee = $this->_extra_data instanceof EE_Messages_Addressee ? $this->_extra_data : $aee; |
190 | 190 | |
@@ -196,7 +196,7 @@ discard block |
||
196 | 196 | $this->_event = ! $this->_event instanceof EE_Event |
197 | 197 | && $this->_data instanceof EE_Ticket |
198 | 198 | && $this->_extra_data['data'] instanceof EE_Messages_Addressee |
199 | - ? $this->_extra_data['data']->tickets[ $this->_data->ID() ]['EE_Event'] |
|
199 | + ? $this->_extra_data['data']->tickets[$this->_data->ID()]['EE_Event'] |
|
200 | 200 | : $this->_event; |
201 | 201 | |
202 | 202 | // if STILL empty event, let's try to get the first event in the list of events via EE_Messages_Addressee |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | private function _venue($field) |
226 | 226 | { |
227 | 227 | |
228 | - if (! $this->_venue instanceof EE_Venue) { |
|
228 | + if ( ! $this->_venue instanceof EE_Venue) { |
|
229 | 229 | return ''; |
230 | 230 | } //no venue so get out. |
231 | 231 | |
@@ -248,11 +248,11 @@ discard block |
||
248 | 248 | break; |
249 | 249 | |
250 | 250 | case 'image': |
251 | - return '<img src="' . $this->_venue->feature_image_url(array(200, 200,)) |
|
252 | - . '" alt="' . sprintf( |
|
251 | + return '<img src="'.$this->_venue->feature_image_url(array(200, 200,)) |
|
252 | + . '" alt="'.sprintf( |
|
253 | 253 | esc_attr__('%s Feature Image', 'event_espresso'), |
254 | 254 | $this->_venue->get('VNU_name') |
255 | - ) . '" />'; |
|
255 | + ).'" />'; |
|
256 | 256 | break; |
257 | 257 | |
258 | 258 | case 'phone': |
@@ -15,22 +15,22 @@ |
||
15 | 15 | class EE_Radio_Button_Input extends EE_Form_Input_With_Options_Base |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @param array $answer_options |
|
20 | - * @param array $input_settings |
|
21 | - */ |
|
22 | - public function __construct($answer_options, $input_settings = array()) |
|
23 | - { |
|
24 | - $this->_set_display_strategy(new EE_Radio_Button_Display_Strategy()); |
|
25 | - $this->_add_validation_strategy( |
|
26 | - new EE_Enum_Validation_Strategy( |
|
27 | - isset($input_settings['validation_error_message']) |
|
28 | - ? $input_settings['validation_error_message'] |
|
29 | - : null |
|
30 | - ) |
|
31 | - ); |
|
32 | - $this->_multiple_selections = false; |
|
33 | - parent::__construct($answer_options, $input_settings); |
|
34 | - } |
|
18 | + /** |
|
19 | + * @param array $answer_options |
|
20 | + * @param array $input_settings |
|
21 | + */ |
|
22 | + public function __construct($answer_options, $input_settings = array()) |
|
23 | + { |
|
24 | + $this->_set_display_strategy(new EE_Radio_Button_Display_Strategy()); |
|
25 | + $this->_add_validation_strategy( |
|
26 | + new EE_Enum_Validation_Strategy( |
|
27 | + isset($input_settings['validation_error_message']) |
|
28 | + ? $input_settings['validation_error_message'] |
|
29 | + : null |
|
30 | + ) |
|
31 | + ); |
|
32 | + $this->_multiple_selections = false; |
|
33 | + parent::__construct($answer_options, $input_settings); |
|
34 | + } |
|
35 | 35 | |
36 | 36 | } |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | ) |
30 | 30 | ); |
31 | 31 | parent::__construct($input_settings); |
32 | - $this->set_html_class($this->html_class() . ' datepicker'); |
|
32 | + $this->set_html_class($this->html_class().' datepicker'); |
|
33 | 33 | // add some style and make it dance |
34 | 34 | add_action('wp_enqueue_scripts', array('EE_Datepicker_Input', 'enqueue_styles_and_scripts')); |
35 | 35 | add_action('admin_enqueue_scripts', array('EE_Datepicker_Input', 'enqueue_styles_and_scripts')); |
@@ -48,7 +48,7 @@ discard block |
||
48 | 48 | // load css |
49 | 49 | wp_register_style( |
50 | 50 | 'espresso-ui-theme', |
51 | - EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
51 | + EE_GLOBAL_ASSETS_URL.'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
52 | 52 | array(), |
53 | 53 | EVENT_ESPRESSO_VERSION |
54 | 54 | ); |
@@ -10,45 +10,45 @@ |
||
10 | 10 | class EE_Datepicker_Input extends EE_Form_Input_Base |
11 | 11 | { |
12 | 12 | |
13 | - /** |
|
14 | - * @param array $input_settings |
|
15 | - */ |
|
16 | - public function __construct($input_settings = array()) |
|
17 | - { |
|
18 | - $this->_set_display_strategy(new EE_Text_Input_Display_Strategy('datepicker')); |
|
19 | - $this->_set_normalization_strategy(new EE_Text_Normalization()); |
|
20 | - // we could do better for validation, but at least verify its plaintext |
|
21 | - $this->_add_validation_strategy( |
|
22 | - new EE_Plaintext_Validation_Strategy( |
|
23 | - isset($input_settings['validation_error_message']) |
|
24 | - ? $input_settings['validation_error_message'] |
|
25 | - : null |
|
26 | - ) |
|
27 | - ); |
|
28 | - parent::__construct($input_settings); |
|
29 | - $this->set_html_class($this->html_class() . ' datepicker'); |
|
30 | - // add some style and make it dance |
|
31 | - add_action('wp_enqueue_scripts', array('EE_Datepicker_Input', 'enqueue_styles_and_scripts')); |
|
32 | - add_action('admin_enqueue_scripts', array('EE_Datepicker_Input', 'enqueue_styles_and_scripts')); |
|
33 | - } |
|
13 | + /** |
|
14 | + * @param array $input_settings |
|
15 | + */ |
|
16 | + public function __construct($input_settings = array()) |
|
17 | + { |
|
18 | + $this->_set_display_strategy(new EE_Text_Input_Display_Strategy('datepicker')); |
|
19 | + $this->_set_normalization_strategy(new EE_Text_Normalization()); |
|
20 | + // we could do better for validation, but at least verify its plaintext |
|
21 | + $this->_add_validation_strategy( |
|
22 | + new EE_Plaintext_Validation_Strategy( |
|
23 | + isset($input_settings['validation_error_message']) |
|
24 | + ? $input_settings['validation_error_message'] |
|
25 | + : null |
|
26 | + ) |
|
27 | + ); |
|
28 | + parent::__construct($input_settings); |
|
29 | + $this->set_html_class($this->html_class() . ' datepicker'); |
|
30 | + // add some style and make it dance |
|
31 | + add_action('wp_enqueue_scripts', array('EE_Datepicker_Input', 'enqueue_styles_and_scripts')); |
|
32 | + add_action('admin_enqueue_scripts', array('EE_Datepicker_Input', 'enqueue_styles_and_scripts')); |
|
33 | + } |
|
34 | 34 | |
35 | 35 | |
36 | 36 | |
37 | - /** |
|
38 | - * enqueue_styles_and_scripts |
|
39 | - * |
|
40 | - * @access public |
|
41 | - * @return void |
|
42 | - */ |
|
43 | - public static function enqueue_styles_and_scripts() |
|
44 | - { |
|
45 | - // load css |
|
46 | - wp_register_style( |
|
47 | - 'espresso-ui-theme', |
|
48 | - EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
49 | - array(), |
|
50 | - EVENT_ESPRESSO_VERSION |
|
51 | - ); |
|
52 | - wp_enqueue_style('espresso-ui-theme'); |
|
53 | - } |
|
37 | + /** |
|
38 | + * enqueue_styles_and_scripts |
|
39 | + * |
|
40 | + * @access public |
|
41 | + * @return void |
|
42 | + */ |
|
43 | + public static function enqueue_styles_and_scripts() |
|
44 | + { |
|
45 | + // load css |
|
46 | + wp_register_style( |
|
47 | + 'espresso-ui-theme', |
|
48 | + EE_GLOBAL_ASSETS_URL . 'css/espresso-ui-theme/jquery-ui-1.10.3.custom.min.css', |
|
49 | + array(), |
|
50 | + EVENT_ESPRESSO_VERSION |
|
51 | + ); |
|
52 | + wp_enqueue_style('espresso-ui-theme'); |
|
53 | + } |
|
54 | 54 | } |
@@ -22,15 +22,15 @@ discard block |
||
22 | 22 | |
23 | 23 | <div class="event-attendees"> |
24 | 24 | <?php do_action_ref_array( |
25 | - 'AHEE__loop-espresso_event_attendees__before', |
|
26 | - array( |
|
27 | - $contacts, |
|
28 | - $event, |
|
29 | - $datetime, |
|
30 | - $ticket, |
|
31 | - $show_gravatar, |
|
32 | - ) |
|
33 | - ); ?> |
|
25 | + 'AHEE__loop-espresso_event_attendees__before', |
|
26 | + array( |
|
27 | + $contacts, |
|
28 | + $event, |
|
29 | + $datetime, |
|
30 | + $ticket, |
|
31 | + $show_gravatar, |
|
32 | + ) |
|
33 | + ); ?> |
|
34 | 34 | <?php if ( $contacts ) : ?> |
35 | 35 | <ul class="event-attendees-list"> |
36 | 36 | <?php foreach( $contacts as $contact ) : |
@@ -47,13 +47,13 @@ discard block |
||
47 | 47 | <p><?php echo $no_attendees_message; ?></p> |
48 | 48 | <?php endif; ?> |
49 | 49 | <?php do_action_ref_array( |
50 | - 'AHEE__loop-espresso_event_attendees__after', |
|
51 | - array( |
|
52 | - $contacts, |
|
53 | - $event, |
|
54 | - $datetime, |
|
55 | - $ticket, |
|
56 | - $show_gravatar, |
|
57 | - ) |
|
58 | - ); ?> |
|
50 | + 'AHEE__loop-espresso_event_attendees__after', |
|
51 | + array( |
|
52 | + $contacts, |
|
53 | + $event, |
|
54 | + $datetime, |
|
55 | + $ticket, |
|
56 | + $show_gravatar, |
|
57 | + ) |
|
58 | + ); ?> |
|
59 | 59 | </div> |
60 | 60 | \ No newline at end of file |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | * @type bool $show_gravatar whether to show gravatar or not. |
16 | 16 | */ |
17 | 17 | |
18 | -$no_attendees_message = apply_filters( 'FHEE__loop-espresso_attendees-shortcode__template__no_attendees_message', __('No Attendees Yet', 'event_espresso' ) ); |
|
18 | +$no_attendees_message = apply_filters('FHEE__loop-espresso_attendees-shortcode__template__no_attendees_message', __('No Attendees Yet', 'event_espresso')); |
|
19 | 19 | |
20 | 20 | |
21 | 21 | ?> |
@@ -31,16 +31,16 @@ discard block |
||
31 | 31 | $show_gravatar, |
32 | 32 | ) |
33 | 33 | ); ?> |
34 | - <?php if ( $contacts ) : ?> |
|
34 | + <?php if ($contacts) : ?> |
|
35 | 35 | <ul class="event-attendees-list"> |
36 | - <?php foreach( $contacts as $contact ) : |
|
37 | - EEH_Template::get_template_part( 'content', 'espresso_event_attendees', array( |
|
36 | + <?php foreach ($contacts as $contact) : |
|
37 | + EEH_Template::get_template_part('content', 'espresso_event_attendees', array( |
|
38 | 38 | 'contact' => $contact, |
39 | 39 | 'event' => $event, |
40 | 40 | 'datetime' => $datetime, |
41 | 41 | 'ticket' => $ticket, |
42 | 42 | 'show_gravatar' => $show_gravatar |
43 | - ) ); |
|
43 | + )); |
|
44 | 44 | endforeach; ?> |
45 | 45 | </ul> |
46 | 46 | <?php else : ?> |
@@ -43,8 +43,11 @@ |
||
43 | 43 | ) ); |
44 | 44 | endforeach; ?> |
45 | 45 | </ul> |
46 | - <?php else : ?> |
|
47 | - <p><?php echo $no_attendees_message; ?></p> |
|
46 | + <?php else { |
|
47 | + : ?> |
|
48 | + <p><?php echo $no_attendees_message; |
|
49 | +} |
|
50 | +?></p> |
|
48 | 51 | <?php endif; ?> |
49 | 52 | <?php do_action_ref_array( |
50 | 53 | 'AHEE__loop-espresso_event_attendees__after', |