@@ -106,70 +106,70 @@ discard block |
||
106 | 106 | // we'll actually use the generated line_item identifiers for our loop |
107 | 107 | $dtts = $tkts = []; |
108 | 108 | foreach ($events as $id => $event) { |
109 | - if (! $event instanceof EE_Event) { |
|
109 | + if ( ! $event instanceof EE_Event) { |
|
110 | 110 | continue; |
111 | 111 | } |
112 | - $this->_events[ $id ]['ID'] = $id; |
|
113 | - $this->_events[ $id ]['name'] = $event->get('EVT_name'); |
|
112 | + $this->_events[$id]['ID'] = $id; |
|
113 | + $this->_events[$id]['name'] = $event->get('EVT_name'); |
|
114 | 114 | $datetime = $event->get_first_related('Datetime'); |
115 | 115 | $tickets = $datetime instanceof EE_Datetime ? $datetime->get_many_related( |
116 | 116 | 'Ticket', |
117 | 117 | ['default_where_conditions' => 'none'] |
118 | 118 | ) : []; |
119 | - $this->_events[ $id ]['event'] = $event; |
|
120 | - $this->_events[ $id ]['reg_objs'] = []; |
|
121 | - $this->_events[ $id ]['tkt_objs'] = $tickets; |
|
122 | - $this->_events[ $id ]['dtt_objs'] = []; |
|
119 | + $this->_events[$id]['event'] = $event; |
|
120 | + $this->_events[$id]['reg_objs'] = []; |
|
121 | + $this->_events[$id]['tkt_objs'] = $tickets; |
|
122 | + $this->_events[$id]['dtt_objs'] = []; |
|
123 | 123 | |
124 | - $tkts = []; |
|
124 | + $tkts = []; |
|
125 | 125 | foreach ($tickets as $ticket) { |
126 | - if (! $ticket instanceof EE_Ticket) { |
|
126 | + if ( ! $ticket instanceof EE_Ticket) { |
|
127 | 127 | continue; |
128 | 128 | } |
129 | 129 | $reldatetime = $ticket->datetimes(); |
130 | - $tkts[ $ticket->ID() ] = []; |
|
131 | - $tkts[ $ticket->ID() ]['ticket'] = $ticket; |
|
132 | - $tkts[ $ticket->ID() ]['dtt_objs'] = $reldatetime; |
|
133 | - $tkts[ $ticket->ID() ]['att_objs'] = $attendees; |
|
134 | - $tkts[ $ticket->ID() ]['count'] = count($attendees); |
|
135 | - $tkts[ $ticket->ID() ]['EE_Event'] = $event; |
|
130 | + $tkts[$ticket->ID()] = []; |
|
131 | + $tkts[$ticket->ID()]['ticket'] = $ticket; |
|
132 | + $tkts[$ticket->ID()]['dtt_objs'] = $reldatetime; |
|
133 | + $tkts[$ticket->ID()]['att_objs'] = $attendees; |
|
134 | + $tkts[$ticket->ID()]['count'] = count($attendees); |
|
135 | + $tkts[$ticket->ID()]['EE_Event'] = $event; |
|
136 | 136 | foreach ($reldatetime as $datetime) { |
137 | - if ($datetime instanceof EE_Datetime && ! isset($dtts[ $datetime->ID() ])) { |
|
138 | - $this->_events[ $id ]['dtt_objs'][ $datetime->ID() ] = $datetime; |
|
139 | - $dtts[ $datetime->ID() ]['datetime'] = $datetime; |
|
140 | - $dtts[ $datetime->ID() ]['tkt_objs'][] = $ticket; |
|
141 | - $dtts[ $datetime->ID() ]['evt_objs'][] = $event; |
|
137 | + if ($datetime instanceof EE_Datetime && ! isset($dtts[$datetime->ID()])) { |
|
138 | + $this->_events[$id]['dtt_objs'][$datetime->ID()] = $datetime; |
|
139 | + $dtts[$datetime->ID()]['datetime'] = $datetime; |
|
140 | + $dtts[$datetime->ID()]['tkt_objs'][] = $ticket; |
|
141 | + $dtts[$datetime->ID()]['evt_objs'][] = $event; |
|
142 | 142 | } |
143 | 143 | } |
144 | 144 | } |
145 | 145 | |
146 | - $this->_events[ $id ]['total_attendees'] = count($attendees); |
|
147 | - $this->_events[ $id ]['att_objs'] = $attendees; |
|
146 | + $this->_events[$id]['total_attendees'] = count($attendees); |
|
147 | + $this->_events[$id]['att_objs'] = $attendees; |
|
148 | 148 | |
149 | 149 | // let's also setup the dummy attendees property! |
150 | 150 | foreach ($attendees as $att_key => $attendee) { |
151 | - if (! $attendee instanceof EE_Attendee) { |
|
151 | + if ( ! $attendee instanceof EE_Attendee) { |
|
152 | 152 | continue; |
153 | 153 | } |
154 | - $this->_attendees[ $att_key ]['line_ref'][] = |
|
155 | - $id; // so later it can be determined what events this attendee registered for! |
|
156 | - $this->_attendees[ $att_key ]['evt_objs'][] = $event; |
|
157 | - $this->_attendees[ $att_key ]['att_obj'] = $attendee; |
|
154 | + $this->_attendees[$att_key]['line_ref'][] = |
|
155 | + $id; // so later it can be determined what events this attendee registered for! |
|
156 | + $this->_attendees[$att_key]['evt_objs'][] = $event; |
|
157 | + $this->_attendees[$att_key]['att_obj'] = $attendee; |
|
158 | 158 | // $this->_attendees[$att_key]['registration_id'] = 0; |
159 | - $this->_attendees[ $att_key ]['attendee_email'] = $attendee->email(); |
|
160 | - $this->_attendees[ $att_key ]['tkt_objs'] = $tickets; |
|
159 | + $this->_attendees[$att_key]['attendee_email'] = $attendee->email(); |
|
160 | + $this->_attendees[$att_key]['tkt_objs'] = $tickets; |
|
161 | 161 | if ($att_key == 999999991) { |
162 | - $this->_attendees[ $att_key ]['ans_objs'][999] = $answers_n_questions['answers'][999]; |
|
163 | - $this->_attendees[ $att_key ]['ans_objs'][1002] = $answers_n_questions['answers'][1002]; |
|
164 | - $this->_attendees[ $att_key ]['ans_objs'][1005] = $answers_n_questions['answers'][1005]; |
|
162 | + $this->_attendees[$att_key]['ans_objs'][999] = $answers_n_questions['answers'][999]; |
|
163 | + $this->_attendees[$att_key]['ans_objs'][1002] = $answers_n_questions['answers'][1002]; |
|
164 | + $this->_attendees[$att_key]['ans_objs'][1005] = $answers_n_questions['answers'][1005]; |
|
165 | 165 | } elseif ($att_key == 999999992) { |
166 | - $this->_attendees[ $att_key ]['ans_objs'][1000] = $answers_n_questions['answers'][1000]; |
|
167 | - $this->_attendees[ $att_key ]['ans_objs'][1003] = $answers_n_questions['answers'][1003]; |
|
168 | - $this->_attendees[ $att_key ]['ans_objs'][1006] = $answers_n_questions['answers'][1006]; |
|
166 | + $this->_attendees[$att_key]['ans_objs'][1000] = $answers_n_questions['answers'][1000]; |
|
167 | + $this->_attendees[$att_key]['ans_objs'][1003] = $answers_n_questions['answers'][1003]; |
|
168 | + $this->_attendees[$att_key]['ans_objs'][1006] = $answers_n_questions['answers'][1006]; |
|
169 | 169 | } elseif ($att_key == 999999993) { |
170 | - $this->_attendees[ $att_key ]['ans_objs'][1001] = $answers_n_questions['answers'][1001]; |
|
171 | - $this->_attendees[ $att_key ]['ans_objs'][1004] = $answers_n_questions['answers'][1004]; |
|
172 | - $this->_attendees[ $att_key ]['ans_objs'][1007] = $answers_n_questions['answers'][1007]; |
|
170 | + $this->_attendees[$att_key]['ans_objs'][1001] = $answers_n_questions['answers'][1001]; |
|
171 | + $this->_attendees[$att_key]['ans_objs'][1004] = $answers_n_questions['answers'][1004]; |
|
172 | + $this->_attendees[$att_key]['ans_objs'][1007] = $answers_n_questions['answers'][1007]; |
|
173 | 173 | } |
174 | 174 | } |
175 | 175 | } |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | /** @var $email string */ |
271 | 271 | /** @var $phone string */ |
272 | 272 | /** @var $attid string */ |
273 | - $attendees[ $attid ] = EE_Attendee::new_instance( |
|
273 | + $attendees[$attid] = EE_Attendee::new_instance( |
|
274 | 274 | [ |
275 | 275 | 'ATT_fname' => $fname, |
276 | 276 | 'ATT_lname' => $lname, |
@@ -377,7 +377,7 @@ discard block |
||
377 | 377 | // first the questions |
378 | 378 | foreach ($quests_array as $qst) { |
379 | 379 | $qstobj = array_combine($qst_columns, $qst); |
380 | - $qsts[ $qstobj['QST_ID'] ] = EE_Question::new_instance($qstobj); |
|
380 | + $qsts[$qstobj['QST_ID']] = EE_Question::new_instance($qstobj); |
|
381 | 381 | } |
382 | 382 | |
383 | 383 | // now the answers (and we'll setup our arrays) |
@@ -385,8 +385,8 @@ discard block |
||
385 | 385 | foreach ($ans_array as $ans) { |
386 | 386 | $ansobj = array_combine($ans_columns, $ans); |
387 | 387 | $ansobj = EE_Answer::new_instance($ansobj); |
388 | - $q_n_as['answers'][ $ansobj->ID() ] = $ansobj; |
|
389 | - $q_n_as['questions'][ $ansobj->ID() ] = $qsts[ $ansobj->get('QST_ID') ]; |
|
388 | + $q_n_as['answers'][$ansobj->ID()] = $ansobj; |
|
389 | + $q_n_as['questions'][$ansobj->ID()] = $qsts[$ansobj->get('QST_ID')]; |
|
390 | 390 | } |
391 | 391 | |
392 | 392 | return $q_n_as; |
@@ -471,11 +471,11 @@ discard block |
||
471 | 471 | $regtxn = $this->txn->ID(); |
472 | 472 | $regcnt = 1; |
473 | 473 | foreach ($attendee['line_ref'] as $evtid) { |
474 | - foreach ($this->_events[ $evtid ]['tkt_objs'] as $ticket) { |
|
475 | - if (! $ticket instanceof EE_Ticket) { |
|
474 | + foreach ($this->_events[$evtid]['tkt_objs'] as $ticket) { |
|
475 | + if ( ! $ticket instanceof EE_Ticket) { |
|
476 | 476 | continue; |
477 | 477 | } |
478 | - $reg_array = [ |
|
478 | + $reg_array = [ |
|
479 | 479 | 'EVT_ID' => $evtid, |
480 | 480 | 'ATT_ID' => $regatt, |
481 | 481 | 'TXN_ID' => $regtxn, |
@@ -484,18 +484,18 @@ discard block |
||
484 | 484 | 'REG_date' => time(), |
485 | 485 | 'REG_final_price' => $ticket->get('TKT_price'), |
486 | 486 | 'REG_session' => 'dummy_session_id', |
487 | - 'REG_code' => $regid . '-dummy-generated-code', |
|
488 | - 'REG_url_link' => $regcnt . '-daafpapasdlfakasdfpqasdfasdf', |
|
487 | + 'REG_code' => $regid.'-dummy-generated-code', |
|
488 | + 'REG_url_link' => $regcnt.'-daafpapasdlfakasdfpqasdfasdf', |
|
489 | 489 | 'REG_count' => $regcnt, |
490 | - 'REG_group_size' => $this->_events[ $evtid ]['total_attendees'], |
|
490 | + 'REG_group_size' => $this->_events[$evtid]['total_attendees'], |
|
491 | 491 | 'REG_att_is_going' => true, |
492 | 492 | 'REG_ID' => $regid, |
493 | 493 | ]; |
494 | 494 | $REG_OBJ = EE_Registration::new_instance($reg_array); |
495 | - $this->_attendees[ $key ]['reg_objs'][ $regid ] = $REG_OBJ; |
|
496 | - $this->_events[ $evtid ]['reg_objs'][] = $REG_OBJ; |
|
495 | + $this->_attendees[$key]['reg_objs'][$regid] = $REG_OBJ; |
|
496 | + $this->_events[$evtid]['reg_objs'][] = $REG_OBJ; |
|
497 | 497 | $this->reg_objs[] = $REG_OBJ; |
498 | - $this->tickets[ $ticket->ID() ]['reg_objs'][ $regid ] = $REG_OBJ; |
|
498 | + $this->tickets[$ticket->ID()]['reg_objs'][$regid] = $REG_OBJ; |
|
499 | 499 | |
500 | 500 | $regcnt++; |
501 | 501 | $regid++; |
@@ -541,19 +541,19 @@ discard block |
||
541 | 541 | $event_line_items = EEH_Line_Item::get_pre_tax_subtotal($line_item_total)->children(); |
542 | 542 | $line_items = []; |
543 | 543 | foreach ($event_line_items as $line_item) { |
544 | - if (! $line_item instanceof EE_Line_Item || $line_item->OBJ_type() !== 'Event') { |
|
544 | + if ( ! $line_item instanceof EE_Line_Item || $line_item->OBJ_type() !== 'Event') { |
|
545 | 545 | continue; |
546 | 546 | } |
547 | 547 | $ticket_line_items = EEH_Line_Item::get_ticket_line_items($line_item); |
548 | 548 | foreach ($ticket_line_items as $ticket_line_item) { |
549 | - if (! $ticket_line_item instanceof EE_Line_Item) { |
|
549 | + if ( ! $ticket_line_item instanceof EE_Line_Item) { |
|
550 | 550 | continue; |
551 | 551 | } |
552 | - $this->tickets[ $ticket_line_item->OBJ_ID() ]['line_item'] = $ticket_line_item; |
|
553 | - $this->tickets[ $ticket_line_item->OBJ_ID() ]['sub_line_items'] = $ticket_line_item->children(); |
|
554 | - $line_items[ $ticket_line_item->ID() ]['children'] = $ticket_line_item->children(); |
|
555 | - $line_items[ $ticket_line_item->ID() ]['EE_Ticket'] = |
|
556 | - $this->tickets[ $ticket_line_item->OBJ_ID() ]['ticket']; |
|
552 | + $this->tickets[$ticket_line_item->OBJ_ID()]['line_item'] = $ticket_line_item; |
|
553 | + $this->tickets[$ticket_line_item->OBJ_ID()]['sub_line_items'] = $ticket_line_item->children(); |
|
554 | + $line_items[$ticket_line_item->ID()]['children'] = $ticket_line_item->children(); |
|
555 | + $line_items[$ticket_line_item->ID()]['EE_Ticket'] = |
|
556 | + $this->tickets[$ticket_line_item->OBJ_ID()]['ticket']; |
|
557 | 557 | } |
558 | 558 | } |
559 | 559 | |
@@ -568,15 +568,15 @@ discard block |
||
568 | 568 | |
569 | 569 | // add additional details for each registration |
570 | 570 | foreach ($this->reg_objs as $reg) { |
571 | - if (! $reg instanceof EE_Registration) { |
|
571 | + if ( ! $reg instanceof EE_Registration) { |
|
572 | 572 | continue; |
573 | 573 | } |
574 | - $this->_registrations[ $reg->ID() ]['tkt_obj'] = $this->tickets[ $reg->get('TKT_ID') ]['ticket']; |
|
575 | - $this->_registrations[ $reg->ID() ]['evt_obj'] = $this->_events[ $reg->get('EVT_ID') ]['event']; |
|
576 | - $this->_registrations[ $reg->ID() ]['reg_obj'] = $reg; |
|
577 | - $this->_registrations[ $reg->ID() ]['ans_objs'] = $this->_attendees[ $reg->get('ATT_ID') ]['ans_objs']; |
|
578 | - $this->_registrations[ $reg->ID() ]['att_obj'] = $this->_attendees[ $reg->get('ATT_ID') ]['att_obj']; |
|
579 | - $this->_registrations[ $reg->ID() ]['dtt_objs'] = $this->tickets[ $reg->get('TKT_ID') ]['dtt_objs']; |
|
574 | + $this->_registrations[$reg->ID()]['tkt_obj'] = $this->tickets[$reg->get('TKT_ID')]['ticket']; |
|
575 | + $this->_registrations[$reg->ID()]['evt_obj'] = $this->_events[$reg->get('EVT_ID')]['event']; |
|
576 | + $this->_registrations[$reg->ID()]['reg_obj'] = $reg; |
|
577 | + $this->_registrations[$reg->ID()]['ans_objs'] = $this->_attendees[$reg->get('ATT_ID')]['ans_objs']; |
|
578 | + $this->_registrations[$reg->ID()]['att_obj'] = $this->_attendees[$reg->get('ATT_ID')]['att_obj']; |
|
579 | + $this->_registrations[$reg->ID()]['dtt_objs'] = $this->tickets[$reg->get('TKT_ID')]['dtt_objs']; |
|
580 | 580 | } |
581 | 581 | |
582 | 582 |
@@ -21,603 +21,603 @@ |
||
21 | 21 | */ |
22 | 22 | class EE_Messages_Preview_incoming_data extends EE_Messages_incoming_data |
23 | 23 | { |
24 | - // some specific properties we need for this class |
|
25 | - private $_events = []; |
|
26 | - |
|
27 | - private $_attendees = []; |
|
28 | - |
|
29 | - private $_registrations = []; |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * For the constructor of this special preview class. We're either looking for an event id or empty data. If we |
|
34 | - * have an event id (or ids) then we'll use that as the source for the "dummy" data. If the data is empty then |
|
35 | - * we'll get the first three published events from the users database and use that as a source. |
|
36 | - * |
|
37 | - * @param array $data |
|
38 | - * @throws EE_Error |
|
39 | - * @throws EE_Error |
|
40 | - * @throws ReflectionException |
|
41 | - */ |
|
42 | - public function __construct($data = []) |
|
43 | - { |
|
44 | - $this->_data = isset($data['event_ids']) ? $data['event_ids'] : []; |
|
45 | - $this->_setup_attendees_events(); |
|
46 | - parent::__construct($data); |
|
47 | - } |
|
48 | - |
|
49 | - |
|
50 | - /** |
|
51 | - * Returns database safe representation of the data later used to when instantiating this object. |
|
52 | - * |
|
53 | - * @param array $data The incoming data to be prepped. |
|
54 | - * |
|
55 | - * @return array The prepped data for db |
|
56 | - */ |
|
57 | - public static function convert_data_for_persistent_storage($data) |
|
58 | - { |
|
59 | - return $data; |
|
60 | - } |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * Data that has been stored in persistent storage that was prepped by _convert_data_for_persistent_storage |
|
65 | - * can be sent into this method and converted back into the format used for instantiating with this data handler. |
|
66 | - * |
|
67 | - * @param array $data |
|
68 | - * |
|
69 | - * @return array |
|
70 | - */ |
|
71 | - public static function convert_data_from_persistent_storage($data) |
|
72 | - { |
|
73 | - return $data; |
|
74 | - } |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * This will just setup the _events property in the expected format. |
|
79 | - * |
|
80 | - * @throws EE_Error |
|
81 | - * @throws ReflectionException |
|
82 | - */ |
|
83 | - private function _setup_attendees_events() |
|
84 | - { |
|
85 | - |
|
86 | - // setup some attendee objects |
|
87 | - $attendees = $this->_get_some_attendees(); |
|
88 | - |
|
89 | - // if empty $data we'll do a query to get some events from the server. |
|
90 | - // otherwise we'll retrieve the event data for the given ids. |
|
91 | - $events = $this->_get_some_events($this->_data); |
|
92 | - |
|
93 | - $answers_n_questions = $this->_get_some_q_and_as(); |
|
94 | - |
|
95 | - if (count($events) < 1) { |
|
96 | - throw new EE_Error( |
|
97 | - esc_html__( |
|
98 | - 'We can\'t generate a preview for you because there are no active events in your database', |
|
99 | - 'event_espresso' |
|
100 | - ) |
|
101 | - ); |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - // now let's loop and set up the _events property. At the same time we'll set up attendee properties. |
|
106 | - // we'll actually use the generated line_item identifiers for our loop |
|
107 | - $dtts = $tkts = []; |
|
108 | - foreach ($events as $id => $event) { |
|
109 | - if (! $event instanceof EE_Event) { |
|
110 | - continue; |
|
111 | - } |
|
112 | - $this->_events[ $id ]['ID'] = $id; |
|
113 | - $this->_events[ $id ]['name'] = $event->get('EVT_name'); |
|
114 | - $datetime = $event->get_first_related('Datetime'); |
|
115 | - $tickets = $datetime instanceof EE_Datetime ? $datetime->get_many_related( |
|
116 | - 'Ticket', |
|
117 | - ['default_where_conditions' => 'none'] |
|
118 | - ) : []; |
|
119 | - $this->_events[ $id ]['event'] = $event; |
|
120 | - $this->_events[ $id ]['reg_objs'] = []; |
|
121 | - $this->_events[ $id ]['tkt_objs'] = $tickets; |
|
122 | - $this->_events[ $id ]['dtt_objs'] = []; |
|
123 | - |
|
124 | - $tkts = []; |
|
125 | - foreach ($tickets as $ticket) { |
|
126 | - if (! $ticket instanceof EE_Ticket) { |
|
127 | - continue; |
|
128 | - } |
|
129 | - $reldatetime = $ticket->datetimes(); |
|
130 | - $tkts[ $ticket->ID() ] = []; |
|
131 | - $tkts[ $ticket->ID() ]['ticket'] = $ticket; |
|
132 | - $tkts[ $ticket->ID() ]['dtt_objs'] = $reldatetime; |
|
133 | - $tkts[ $ticket->ID() ]['att_objs'] = $attendees; |
|
134 | - $tkts[ $ticket->ID() ]['count'] = count($attendees); |
|
135 | - $tkts[ $ticket->ID() ]['EE_Event'] = $event; |
|
136 | - foreach ($reldatetime as $datetime) { |
|
137 | - if ($datetime instanceof EE_Datetime && ! isset($dtts[ $datetime->ID() ])) { |
|
138 | - $this->_events[ $id ]['dtt_objs'][ $datetime->ID() ] = $datetime; |
|
139 | - $dtts[ $datetime->ID() ]['datetime'] = $datetime; |
|
140 | - $dtts[ $datetime->ID() ]['tkt_objs'][] = $ticket; |
|
141 | - $dtts[ $datetime->ID() ]['evt_objs'][] = $event; |
|
142 | - } |
|
143 | - } |
|
144 | - } |
|
145 | - |
|
146 | - $this->_events[ $id ]['total_attendees'] = count($attendees); |
|
147 | - $this->_events[ $id ]['att_objs'] = $attendees; |
|
148 | - |
|
149 | - // let's also setup the dummy attendees property! |
|
150 | - foreach ($attendees as $att_key => $attendee) { |
|
151 | - if (! $attendee instanceof EE_Attendee) { |
|
152 | - continue; |
|
153 | - } |
|
154 | - $this->_attendees[ $att_key ]['line_ref'][] = |
|
155 | - $id; // so later it can be determined what events this attendee registered for! |
|
156 | - $this->_attendees[ $att_key ]['evt_objs'][] = $event; |
|
157 | - $this->_attendees[ $att_key ]['att_obj'] = $attendee; |
|
158 | - // $this->_attendees[$att_key]['registration_id'] = 0; |
|
159 | - $this->_attendees[ $att_key ]['attendee_email'] = $attendee->email(); |
|
160 | - $this->_attendees[ $att_key ]['tkt_objs'] = $tickets; |
|
161 | - if ($att_key == 999999991) { |
|
162 | - $this->_attendees[ $att_key ]['ans_objs'][999] = $answers_n_questions['answers'][999]; |
|
163 | - $this->_attendees[ $att_key ]['ans_objs'][1002] = $answers_n_questions['answers'][1002]; |
|
164 | - $this->_attendees[ $att_key ]['ans_objs'][1005] = $answers_n_questions['answers'][1005]; |
|
165 | - } elseif ($att_key == 999999992) { |
|
166 | - $this->_attendees[ $att_key ]['ans_objs'][1000] = $answers_n_questions['answers'][1000]; |
|
167 | - $this->_attendees[ $att_key ]['ans_objs'][1003] = $answers_n_questions['answers'][1003]; |
|
168 | - $this->_attendees[ $att_key ]['ans_objs'][1006] = $answers_n_questions['answers'][1006]; |
|
169 | - } elseif ($att_key == 999999993) { |
|
170 | - $this->_attendees[ $att_key ]['ans_objs'][1001] = $answers_n_questions['answers'][1001]; |
|
171 | - $this->_attendees[ $att_key ]['ans_objs'][1004] = $answers_n_questions['answers'][1004]; |
|
172 | - $this->_attendees[ $att_key ]['ans_objs'][1007] = $answers_n_questions['answers'][1007]; |
|
173 | - } |
|
174 | - } |
|
175 | - } |
|
176 | - |
|
177 | - $this->tickets = $tkts; |
|
178 | - $this->datetimes = $dtts; |
|
179 | - $this->answers = $answers_n_questions['answers']; |
|
180 | - $this->questions = $answers_n_questions['questions']; |
|
181 | - $this->total_ticket_count = count($tkts) * count($this->_attendees); |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * This just returns an array of dummy attendee objects that we'll use to attach to events for our preview data |
|
187 | - * |
|
188 | - * @access private |
|
189 | - * @return array an array of attendee objects |
|
190 | - * @throws EE_Error |
|
191 | - * @throws EE_Error |
|
192 | - */ |
|
193 | - private function _get_some_attendees() |
|
194 | - { |
|
195 | - // let's just setup a dummy array of various attendee details |
|
196 | - $dummy_attendees = [ |
|
197 | - 0 => [ |
|
198 | - 'Luke', |
|
199 | - 'Skywalker', |
|
200 | - '[email protected]', |
|
201 | - '804 Bantha Dr.', |
|
202 | - 'Complex 8', |
|
203 | - 'Mos Eisley', |
|
204 | - 32, |
|
205 | - 'US', |
|
206 | - 'f0r3e', |
|
207 | - '222-333-4763', |
|
208 | - false, |
|
209 | - '999999991', |
|
210 | - ], |
|
211 | - 1 => [ |
|
212 | - 'Princess', |
|
213 | - 'Leia', |
|
214 | - '[email protected]', |
|
215 | - '1456 Valley Way Boulevard', |
|
216 | - 'Suite 9', |
|
217 | - 'Alderaan', |
|
218 | - 15, |
|
219 | - 'US', |
|
220 | - 'c1h2c', |
|
221 | - '78-123-111-1111', |
|
222 | - false, |
|
223 | - '999999992', |
|
224 | - ], |
|
225 | - 2 => [ |
|
226 | - 'Yoda', |
|
227 | - 'I Am', |
|
228 | - '[email protected]', |
|
229 | - '4th Tree', |
|
230 | - '5th Knot', |
|
231 | - 'Marsh', |
|
232 | - 22, |
|
233 | - 'US', |
|
234 | - 'l18n', |
|
235 | - '999-999-9999', |
|
236 | - false, |
|
237 | - '999999993', |
|
238 | - ], |
|
239 | - ]; |
|
240 | - |
|
241 | - // let's generate the attendee objects |
|
242 | - $attendees = []; |
|
243 | - $var_array = [ |
|
244 | - 'fname', |
|
245 | - 'lname', |
|
246 | - 'email', |
|
247 | - 'address', |
|
248 | - 'address2', |
|
249 | - 'city', |
|
250 | - 'staid', |
|
251 | - 'cntry', |
|
252 | - 'zip', |
|
253 | - 'phone', |
|
254 | - 'deleted', |
|
255 | - 'attid', |
|
256 | - ]; |
|
257 | - |
|
258 | - // EE_Registry::instance()->load_class( 'Attendee', array(), FALSE, false, TRUE ); |
|
259 | - foreach ($dummy_attendees as $dummy) { |
|
260 | - $att = array_combine($var_array, $dummy); |
|
261 | - extract($att); |
|
262 | - /** @var $fname string */ |
|
263 | - /** @var $lname string */ |
|
264 | - /** @var $address string */ |
|
265 | - /** @var $address2 string */ |
|
266 | - /** @var $city string */ |
|
267 | - /** @var $staid string */ |
|
268 | - /** @var $cntry string */ |
|
269 | - /** @var $zip string */ |
|
270 | - /** @var $email string */ |
|
271 | - /** @var $phone string */ |
|
272 | - /** @var $attid string */ |
|
273 | - $attendees[ $attid ] = EE_Attendee::new_instance( |
|
274 | - [ |
|
275 | - 'ATT_fname' => $fname, |
|
276 | - 'ATT_lname' => $lname, |
|
277 | - 'ATT_address' => $address, |
|
278 | - 'ATT_address2' => $address2, |
|
279 | - 'ATT_city' => $city, |
|
280 | - 'STA_ID' => $staid, |
|
281 | - 'CNT_ISO' => $cntry, |
|
282 | - 'ATT_zip' => $zip, |
|
283 | - 'ATT_email' => $email, |
|
284 | - 'ATT_phone' => $phone, |
|
285 | - 'ATT_ID' => $attid, |
|
286 | - ] |
|
287 | - ); |
|
288 | - } |
|
289 | - |
|
290 | - return $attendees; |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - /** |
|
295 | - * Return an array of dummy question objects indexed by answer id and dummy answer objects indexed by answer id. |
|
296 | - * This will be used in our dummy data setup |
|
297 | - * |
|
298 | - * @return array |
|
299 | - * @throws EE_Error |
|
300 | - * @throws ReflectionException |
|
301 | - */ |
|
302 | - private function _get_some_q_and_as() |
|
303 | - { |
|
304 | - $quests_array = [ |
|
305 | - 0 => [ |
|
306 | - 555, |
|
307 | - esc_html__('What is your favorite planet?', 'event_espresso'), |
|
308 | - 0, |
|
309 | - ], |
|
310 | - 1 => [ |
|
311 | - 556, |
|
312 | - esc_html__('What is your favorite food?', 'event_espresso'), |
|
313 | - 0, |
|
314 | - ], |
|
315 | - 2 => [ |
|
316 | - 557, |
|
317 | - esc_html__('How many lightyears have you travelled', 'event_espresso'), |
|
318 | - 0, |
|
319 | - ], |
|
320 | - ]; |
|
321 | - |
|
322 | - $ans_array = [ |
|
323 | - 0 => [ |
|
324 | - 999, |
|
325 | - 555, |
|
326 | - 'Tattoine', |
|
327 | - ], |
|
328 | - 1 => [ |
|
329 | - 1000, |
|
330 | - 555, |
|
331 | - 'Alderaan', |
|
332 | - ], |
|
333 | - 2 => [ |
|
334 | - 1001, |
|
335 | - 555, |
|
336 | - 'Dantooine', |
|
337 | - ], |
|
338 | - 3 => [ |
|
339 | - 1002, |
|
340 | - 556, |
|
341 | - 'Fish Fingers', |
|
342 | - ], |
|
343 | - 4 => [ |
|
344 | - 1003, |
|
345 | - 556, |
|
346 | - 'Sushi', |
|
347 | - ], |
|
348 | - 5 => [ |
|
349 | - 1004, |
|
350 | - 556, |
|
351 | - 'Water', |
|
352 | - ], |
|
353 | - 6 => [ |
|
354 | - 1005, |
|
355 | - 557, |
|
356 | - 'A lot', |
|
357 | - ], |
|
358 | - 7 => [ |
|
359 | - 1006, |
|
360 | - 557, |
|
361 | - "That's none of your business.", |
|
362 | - ], |
|
363 | - 8 => [ |
|
364 | - 1007, |
|
365 | - 557, |
|
366 | - "People less travel me then.", |
|
367 | - ], |
|
368 | - ]; |
|
369 | - |
|
370 | - $qst_columns = ['QST_ID', 'QST_display_text', 'QST_system']; |
|
371 | - $ans_columns = ['ANS_ID', 'QST_ID', 'ANS_value']; |
|
372 | - |
|
373 | - // EE_Registry::instance()->load_class( 'Question', array(), FALSE, TRUE, TRUE ); |
|
374 | - // EE_Registry::instance()->load_class( 'Answer', array(), FALSE, TRUE, TRUE ); |
|
375 | - |
|
376 | - $qsts = []; |
|
377 | - // first the questions |
|
378 | - foreach ($quests_array as $qst) { |
|
379 | - $qstobj = array_combine($qst_columns, $qst); |
|
380 | - $qsts[ $qstobj['QST_ID'] ] = EE_Question::new_instance($qstobj); |
|
381 | - } |
|
382 | - |
|
383 | - // now the answers (and we'll setup our arrays) |
|
384 | - $q_n_as = []; |
|
385 | - foreach ($ans_array as $ans) { |
|
386 | - $ansobj = array_combine($ans_columns, $ans); |
|
387 | - $ansobj = EE_Answer::new_instance($ansobj); |
|
388 | - $q_n_as['answers'][ $ansobj->ID() ] = $ansobj; |
|
389 | - $q_n_as['questions'][ $ansobj->ID() ] = $qsts[ $ansobj->get('QST_ID') ]; |
|
390 | - } |
|
391 | - |
|
392 | - return $q_n_as; |
|
393 | - } |
|
394 | - |
|
395 | - |
|
396 | - /** |
|
397 | - * Return an array of event objects from the database |
|
398 | - * |
|
399 | - * If event ids are not included then we'll just retrieve the first published event from the database. |
|
400 | - * |
|
401 | - * @param array $event_ids if set, this will be an array of event ids to obtain events for. |
|
402 | - * |
|
403 | - * @return array An array of event objects from the db. |
|
404 | - * @throws EE_Error |
|
405 | - */ |
|
406 | - private function _get_some_events(array $event_ids = []) |
|
407 | - { |
|
408 | - /** @var RequestInterface $request */ |
|
409 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
410 | - // if we have an evt_id then we want to make sure we use that for the preview |
|
411 | - // (because a specific event template is being viewed); |
|
412 | - $event_ids = $request->getRequestParam('evt_id', $event_ids, 'int', true); |
|
413 | - // clear out any invalid IDs, like 0 |
|
414 | - $event_ids = array_filter($event_ids); |
|
415 | - $limit = ! empty($event_ids) |
|
416 | - ? null |
|
417 | - : apply_filters('FHEE__EE_Messages_Preview_incoming_data___get_some_events__limit', '0,1'); |
|
418 | - |
|
419 | - $where = ! empty($event_ids) |
|
420 | - ? [ |
|
421 | - 'EVT_ID' => ['IN', $event_ids], |
|
422 | - 'Datetime.Ticket.TKT_ID' => ['>', 1], |
|
423 | - ] |
|
424 | - : ['Datetime.Ticket.TKT_ID' => ['>', 1]]; |
|
425 | - |
|
426 | - return EEM_Event::instance()->get_all([$where, 'limit' => $limit]); |
|
427 | - } |
|
428 | - |
|
429 | - |
|
430 | - /** |
|
431 | - * @throws EE_Error |
|
432 | - * @throws ReflectionException |
|
433 | - */ |
|
434 | - protected function _setup_data() |
|
435 | - { |
|
436 | - // need to figure out the running total for test purposes so... we're going to create a temp cart and add the tickets to it! |
|
437 | - if (EE_Registry::instance()->SSN instanceof EE_Session) { |
|
438 | - EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
439 | - $session = EE_Registry::instance()->SSN; |
|
440 | - } else { |
|
441 | - $session = EE_Registry::instance()->load_core('Session'); |
|
442 | - } |
|
443 | - $cart = EE_Cart::instance(null, $session); |
|
444 | - |
|
445 | - // add tickets to cart |
|
446 | - foreach ($this->tickets as $ticket) { |
|
447 | - $cart->add_ticket_to_cart($ticket['ticket']); |
|
448 | - } |
|
449 | - |
|
450 | - // setup txn property |
|
451 | - $this->txn = EE_Transaction::new_instance( |
|
452 | - [ |
|
453 | - 'TXN_timestamp' => time(), // unix timestamp |
|
454 | - 'TXN_total' => 0, // txn_total |
|
455 | - 'TXN_paid' => 0, // txn_paid |
|
456 | - 'STS_ID' => EEM_Transaction::incomplete_status_code, // sts_id |
|
457 | - 'TXN_session_data' => null, // dump of txn session object (we're just going to leave blank here) |
|
458 | - 'TXN_hash_salt' => null, // hash salt blank as well |
|
459 | - 'TXN_ID' => 999999, |
|
460 | - ] |
|
461 | - ); |
|
462 | - |
|
463 | - |
|
464 | - // setup reg_objects |
|
465 | - // note we're setting up a reg object for each attendee in each event but ALSO adding to the reg_object array. |
|
466 | - $this->reg_objs = []; |
|
467 | - $regid = 9999990; |
|
468 | - foreach ($this->_attendees as $key => $attendee) { |
|
469 | - // note we need to setup reg_objects for each event this attendee belongs to |
|
470 | - $regatt = $attendee['att_obj'] instanceof EE_Attendee ? $attendee['att_obj']->ID() : null; |
|
471 | - $regtxn = $this->txn->ID(); |
|
472 | - $regcnt = 1; |
|
473 | - foreach ($attendee['line_ref'] as $evtid) { |
|
474 | - foreach ($this->_events[ $evtid ]['tkt_objs'] as $ticket) { |
|
475 | - if (! $ticket instanceof EE_Ticket) { |
|
476 | - continue; |
|
477 | - } |
|
478 | - $reg_array = [ |
|
479 | - 'EVT_ID' => $evtid, |
|
480 | - 'ATT_ID' => $regatt, |
|
481 | - 'TXN_ID' => $regtxn, |
|
482 | - 'TKT_ID' => $ticket->ID(), |
|
483 | - 'STS_ID' => RegStatus::PENDING_PAYMENT, |
|
484 | - 'REG_date' => time(), |
|
485 | - 'REG_final_price' => $ticket->get('TKT_price'), |
|
486 | - 'REG_session' => 'dummy_session_id', |
|
487 | - 'REG_code' => $regid . '-dummy-generated-code', |
|
488 | - 'REG_url_link' => $regcnt . '-daafpapasdlfakasdfpqasdfasdf', |
|
489 | - 'REG_count' => $regcnt, |
|
490 | - 'REG_group_size' => $this->_events[ $evtid ]['total_attendees'], |
|
491 | - 'REG_att_is_going' => true, |
|
492 | - 'REG_ID' => $regid, |
|
493 | - ]; |
|
494 | - $REG_OBJ = EE_Registration::new_instance($reg_array); |
|
495 | - $this->_attendees[ $key ]['reg_objs'][ $regid ] = $REG_OBJ; |
|
496 | - $this->_events[ $evtid ]['reg_objs'][] = $REG_OBJ; |
|
497 | - $this->reg_objs[] = $REG_OBJ; |
|
498 | - $this->tickets[ $ticket->ID() ]['reg_objs'][ $regid ] = $REG_OBJ; |
|
499 | - |
|
500 | - $regcnt++; |
|
501 | - $regid++; |
|
502 | - } |
|
503 | - } |
|
504 | - } |
|
505 | - |
|
506 | - |
|
507 | - // setup line items! |
|
508 | - $line_item_total = EEH_Line_Item::create_total_line_item($this->txn); |
|
509 | - |
|
510 | - // add tickets |
|
511 | - foreach ($this->tickets as $item) { |
|
512 | - $qty = $item['count']; |
|
513 | - $ticket = $item['ticket']; |
|
514 | - EEH_Line_Item::add_ticket_purchase($line_item_total, $ticket, $qty); |
|
515 | - } |
|
516 | - |
|
517 | - $shipping_line_item = EE_Line_Item::new_instance( |
|
518 | - [ |
|
519 | - 'LIN_name' => esc_html__( |
|
520 | - 'Shipping Surcharge', |
|
521 | - 'event_espresso' |
|
522 | - ), |
|
523 | - 'LIN_desc' => esc_html__( |
|
524 | - 'Sent via Millenium Falcon', |
|
525 | - 'event_espresso' |
|
526 | - ), |
|
527 | - 'LIN_unit_price' => 20, |
|
528 | - 'LIN_quantity' => 1, |
|
529 | - 'LIN_is_taxable' => true, |
|
530 | - 'LIN_total' => 20, |
|
531 | - 'LIN_type' => EEM_Line_Item::type_line_item, |
|
532 | - ] |
|
533 | - ); |
|
534 | - EEH_Line_Item::add_item($line_item_total, $shipping_line_item); |
|
535 | - $this->additional_line_items = [$shipping_line_item]; |
|
536 | - |
|
537 | - // now let's add taxes |
|
538 | - EEH_Line_Item::apply_taxes($line_item_total); |
|
539 | - |
|
540 | - // now we should be able to get the items we need from this object |
|
541 | - $event_line_items = EEH_Line_Item::get_pre_tax_subtotal($line_item_total)->children(); |
|
542 | - $line_items = []; |
|
543 | - foreach ($event_line_items as $line_item) { |
|
544 | - if (! $line_item instanceof EE_Line_Item || $line_item->OBJ_type() !== 'Event') { |
|
545 | - continue; |
|
546 | - } |
|
547 | - $ticket_line_items = EEH_Line_Item::get_ticket_line_items($line_item); |
|
548 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
549 | - if (! $ticket_line_item instanceof EE_Line_Item) { |
|
550 | - continue; |
|
551 | - } |
|
552 | - $this->tickets[ $ticket_line_item->OBJ_ID() ]['line_item'] = $ticket_line_item; |
|
553 | - $this->tickets[ $ticket_line_item->OBJ_ID() ]['sub_line_items'] = $ticket_line_item->children(); |
|
554 | - $line_items[ $ticket_line_item->ID() ]['children'] = $ticket_line_item->children(); |
|
555 | - $line_items[ $ticket_line_item->ID() ]['EE_Ticket'] = |
|
556 | - $this->tickets[ $ticket_line_item->OBJ_ID() ]['ticket']; |
|
557 | - } |
|
558 | - } |
|
559 | - |
|
560 | - $this->line_items_with_children = $line_items; |
|
561 | - $this->tax_line_items = $line_item_total->tax_descendants(); |
|
562 | - |
|
563 | - // add proper total to transaction object. |
|
564 | - $grand_total = $line_item_total->recalculate_total_including_taxes(); |
|
565 | - $this->grand_total_line_item = $line_item_total; |
|
566 | - $this->txn->set_total($grand_total); |
|
567 | - |
|
568 | - |
|
569 | - // add additional details for each registration |
|
570 | - foreach ($this->reg_objs as $reg) { |
|
571 | - if (! $reg instanceof EE_Registration) { |
|
572 | - continue; |
|
573 | - } |
|
574 | - $this->_registrations[ $reg->ID() ]['tkt_obj'] = $this->tickets[ $reg->get('TKT_ID') ]['ticket']; |
|
575 | - $this->_registrations[ $reg->ID() ]['evt_obj'] = $this->_events[ $reg->get('EVT_ID') ]['event']; |
|
576 | - $this->_registrations[ $reg->ID() ]['reg_obj'] = $reg; |
|
577 | - $this->_registrations[ $reg->ID() ]['ans_objs'] = $this->_attendees[ $reg->get('ATT_ID') ]['ans_objs']; |
|
578 | - $this->_registrations[ $reg->ID() ]['att_obj'] = $this->_attendees[ $reg->get('ATT_ID') ]['att_obj']; |
|
579 | - $this->_registrations[ $reg->ID() ]['dtt_objs'] = $this->tickets[ $reg->get('TKT_ID') ]['dtt_objs']; |
|
580 | - } |
|
581 | - |
|
582 | - |
|
583 | - // events and attendees |
|
584 | - $this->events = $this->_events; |
|
585 | - $this->attendees = $this->_attendees; |
|
586 | - $this->registrations = $this->_registrations; |
|
587 | - |
|
588 | - $attendees_to_shift = $this->_attendees; |
|
589 | - |
|
590 | - // setup primary attendee property |
|
591 | - $this->primary_attendee_data = [ |
|
592 | - 'fname' => $this->_attendees[999999991]['att_obj'] instanceof EE_Attendee |
|
593 | - ? $this->_attendees[999999991]['att_obj']->fname() |
|
594 | - : '', |
|
595 | - |
|
596 | - 'lname' => $this->_attendees[999999991]['att_obj'] instanceof EE_Attendee |
|
597 | - ? $this->_attendees[999999991]['att_obj']->lname() |
|
598 | - : '', |
|
599 | - |
|
600 | - 'email' => $this->_attendees[999999991]['att_obj'] instanceof EE_Attendee |
|
601 | - ? $this->_attendees[999999991]['att_obj']->email() |
|
602 | - : '', |
|
603 | - |
|
604 | - 'att_obj' => $this->_attendees[999999991]['att_obj'], |
|
605 | - |
|
606 | - 'reg_obj' => array_shift($attendees_to_shift[999999991]['reg_objs']), |
|
607 | - ]; |
|
608 | - |
|
609 | - // reg_info property |
|
610 | - // note this isn't referenced by any shortcode parsers so we'll ignore for now. |
|
611 | - $this->reg_info = []; |
|
612 | - |
|
613 | - // let's set a reg_obj for messengers expecting one. |
|
614 | - $this->reg_obj = array_shift($this->_attendees[999999991]['reg_objs']); |
|
615 | - |
|
616 | - // the below are just dummy items. |
|
617 | - $this->user_id = 1; |
|
618 | - $this->ip_address = '192.0.2.1'; |
|
619 | - $this->user_agent = ''; |
|
620 | - $this->init_access = time(); |
|
621 | - $this->last_access = time(); |
|
622 | - } |
|
24 | + // some specific properties we need for this class |
|
25 | + private $_events = []; |
|
26 | + |
|
27 | + private $_attendees = []; |
|
28 | + |
|
29 | + private $_registrations = []; |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * For the constructor of this special preview class. We're either looking for an event id or empty data. If we |
|
34 | + * have an event id (or ids) then we'll use that as the source for the "dummy" data. If the data is empty then |
|
35 | + * we'll get the first three published events from the users database and use that as a source. |
|
36 | + * |
|
37 | + * @param array $data |
|
38 | + * @throws EE_Error |
|
39 | + * @throws EE_Error |
|
40 | + * @throws ReflectionException |
|
41 | + */ |
|
42 | + public function __construct($data = []) |
|
43 | + { |
|
44 | + $this->_data = isset($data['event_ids']) ? $data['event_ids'] : []; |
|
45 | + $this->_setup_attendees_events(); |
|
46 | + parent::__construct($data); |
|
47 | + } |
|
48 | + |
|
49 | + |
|
50 | + /** |
|
51 | + * Returns database safe representation of the data later used to when instantiating this object. |
|
52 | + * |
|
53 | + * @param array $data The incoming data to be prepped. |
|
54 | + * |
|
55 | + * @return array The prepped data for db |
|
56 | + */ |
|
57 | + public static function convert_data_for_persistent_storage($data) |
|
58 | + { |
|
59 | + return $data; |
|
60 | + } |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * Data that has been stored in persistent storage that was prepped by _convert_data_for_persistent_storage |
|
65 | + * can be sent into this method and converted back into the format used for instantiating with this data handler. |
|
66 | + * |
|
67 | + * @param array $data |
|
68 | + * |
|
69 | + * @return array |
|
70 | + */ |
|
71 | + public static function convert_data_from_persistent_storage($data) |
|
72 | + { |
|
73 | + return $data; |
|
74 | + } |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * This will just setup the _events property in the expected format. |
|
79 | + * |
|
80 | + * @throws EE_Error |
|
81 | + * @throws ReflectionException |
|
82 | + */ |
|
83 | + private function _setup_attendees_events() |
|
84 | + { |
|
85 | + |
|
86 | + // setup some attendee objects |
|
87 | + $attendees = $this->_get_some_attendees(); |
|
88 | + |
|
89 | + // if empty $data we'll do a query to get some events from the server. |
|
90 | + // otherwise we'll retrieve the event data for the given ids. |
|
91 | + $events = $this->_get_some_events($this->_data); |
|
92 | + |
|
93 | + $answers_n_questions = $this->_get_some_q_and_as(); |
|
94 | + |
|
95 | + if (count($events) < 1) { |
|
96 | + throw new EE_Error( |
|
97 | + esc_html__( |
|
98 | + 'We can\'t generate a preview for you because there are no active events in your database', |
|
99 | + 'event_espresso' |
|
100 | + ) |
|
101 | + ); |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + // now let's loop and set up the _events property. At the same time we'll set up attendee properties. |
|
106 | + // we'll actually use the generated line_item identifiers for our loop |
|
107 | + $dtts = $tkts = []; |
|
108 | + foreach ($events as $id => $event) { |
|
109 | + if (! $event instanceof EE_Event) { |
|
110 | + continue; |
|
111 | + } |
|
112 | + $this->_events[ $id ]['ID'] = $id; |
|
113 | + $this->_events[ $id ]['name'] = $event->get('EVT_name'); |
|
114 | + $datetime = $event->get_first_related('Datetime'); |
|
115 | + $tickets = $datetime instanceof EE_Datetime ? $datetime->get_many_related( |
|
116 | + 'Ticket', |
|
117 | + ['default_where_conditions' => 'none'] |
|
118 | + ) : []; |
|
119 | + $this->_events[ $id ]['event'] = $event; |
|
120 | + $this->_events[ $id ]['reg_objs'] = []; |
|
121 | + $this->_events[ $id ]['tkt_objs'] = $tickets; |
|
122 | + $this->_events[ $id ]['dtt_objs'] = []; |
|
123 | + |
|
124 | + $tkts = []; |
|
125 | + foreach ($tickets as $ticket) { |
|
126 | + if (! $ticket instanceof EE_Ticket) { |
|
127 | + continue; |
|
128 | + } |
|
129 | + $reldatetime = $ticket->datetimes(); |
|
130 | + $tkts[ $ticket->ID() ] = []; |
|
131 | + $tkts[ $ticket->ID() ]['ticket'] = $ticket; |
|
132 | + $tkts[ $ticket->ID() ]['dtt_objs'] = $reldatetime; |
|
133 | + $tkts[ $ticket->ID() ]['att_objs'] = $attendees; |
|
134 | + $tkts[ $ticket->ID() ]['count'] = count($attendees); |
|
135 | + $tkts[ $ticket->ID() ]['EE_Event'] = $event; |
|
136 | + foreach ($reldatetime as $datetime) { |
|
137 | + if ($datetime instanceof EE_Datetime && ! isset($dtts[ $datetime->ID() ])) { |
|
138 | + $this->_events[ $id ]['dtt_objs'][ $datetime->ID() ] = $datetime; |
|
139 | + $dtts[ $datetime->ID() ]['datetime'] = $datetime; |
|
140 | + $dtts[ $datetime->ID() ]['tkt_objs'][] = $ticket; |
|
141 | + $dtts[ $datetime->ID() ]['evt_objs'][] = $event; |
|
142 | + } |
|
143 | + } |
|
144 | + } |
|
145 | + |
|
146 | + $this->_events[ $id ]['total_attendees'] = count($attendees); |
|
147 | + $this->_events[ $id ]['att_objs'] = $attendees; |
|
148 | + |
|
149 | + // let's also setup the dummy attendees property! |
|
150 | + foreach ($attendees as $att_key => $attendee) { |
|
151 | + if (! $attendee instanceof EE_Attendee) { |
|
152 | + continue; |
|
153 | + } |
|
154 | + $this->_attendees[ $att_key ]['line_ref'][] = |
|
155 | + $id; // so later it can be determined what events this attendee registered for! |
|
156 | + $this->_attendees[ $att_key ]['evt_objs'][] = $event; |
|
157 | + $this->_attendees[ $att_key ]['att_obj'] = $attendee; |
|
158 | + // $this->_attendees[$att_key]['registration_id'] = 0; |
|
159 | + $this->_attendees[ $att_key ]['attendee_email'] = $attendee->email(); |
|
160 | + $this->_attendees[ $att_key ]['tkt_objs'] = $tickets; |
|
161 | + if ($att_key == 999999991) { |
|
162 | + $this->_attendees[ $att_key ]['ans_objs'][999] = $answers_n_questions['answers'][999]; |
|
163 | + $this->_attendees[ $att_key ]['ans_objs'][1002] = $answers_n_questions['answers'][1002]; |
|
164 | + $this->_attendees[ $att_key ]['ans_objs'][1005] = $answers_n_questions['answers'][1005]; |
|
165 | + } elseif ($att_key == 999999992) { |
|
166 | + $this->_attendees[ $att_key ]['ans_objs'][1000] = $answers_n_questions['answers'][1000]; |
|
167 | + $this->_attendees[ $att_key ]['ans_objs'][1003] = $answers_n_questions['answers'][1003]; |
|
168 | + $this->_attendees[ $att_key ]['ans_objs'][1006] = $answers_n_questions['answers'][1006]; |
|
169 | + } elseif ($att_key == 999999993) { |
|
170 | + $this->_attendees[ $att_key ]['ans_objs'][1001] = $answers_n_questions['answers'][1001]; |
|
171 | + $this->_attendees[ $att_key ]['ans_objs'][1004] = $answers_n_questions['answers'][1004]; |
|
172 | + $this->_attendees[ $att_key ]['ans_objs'][1007] = $answers_n_questions['answers'][1007]; |
|
173 | + } |
|
174 | + } |
|
175 | + } |
|
176 | + |
|
177 | + $this->tickets = $tkts; |
|
178 | + $this->datetimes = $dtts; |
|
179 | + $this->answers = $answers_n_questions['answers']; |
|
180 | + $this->questions = $answers_n_questions['questions']; |
|
181 | + $this->total_ticket_count = count($tkts) * count($this->_attendees); |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * This just returns an array of dummy attendee objects that we'll use to attach to events for our preview data |
|
187 | + * |
|
188 | + * @access private |
|
189 | + * @return array an array of attendee objects |
|
190 | + * @throws EE_Error |
|
191 | + * @throws EE_Error |
|
192 | + */ |
|
193 | + private function _get_some_attendees() |
|
194 | + { |
|
195 | + // let's just setup a dummy array of various attendee details |
|
196 | + $dummy_attendees = [ |
|
197 | + 0 => [ |
|
198 | + 'Luke', |
|
199 | + 'Skywalker', |
|
200 | + '[email protected]', |
|
201 | + '804 Bantha Dr.', |
|
202 | + 'Complex 8', |
|
203 | + 'Mos Eisley', |
|
204 | + 32, |
|
205 | + 'US', |
|
206 | + 'f0r3e', |
|
207 | + '222-333-4763', |
|
208 | + false, |
|
209 | + '999999991', |
|
210 | + ], |
|
211 | + 1 => [ |
|
212 | + 'Princess', |
|
213 | + 'Leia', |
|
214 | + '[email protected]', |
|
215 | + '1456 Valley Way Boulevard', |
|
216 | + 'Suite 9', |
|
217 | + 'Alderaan', |
|
218 | + 15, |
|
219 | + 'US', |
|
220 | + 'c1h2c', |
|
221 | + '78-123-111-1111', |
|
222 | + false, |
|
223 | + '999999992', |
|
224 | + ], |
|
225 | + 2 => [ |
|
226 | + 'Yoda', |
|
227 | + 'I Am', |
|
228 | + '[email protected]', |
|
229 | + '4th Tree', |
|
230 | + '5th Knot', |
|
231 | + 'Marsh', |
|
232 | + 22, |
|
233 | + 'US', |
|
234 | + 'l18n', |
|
235 | + '999-999-9999', |
|
236 | + false, |
|
237 | + '999999993', |
|
238 | + ], |
|
239 | + ]; |
|
240 | + |
|
241 | + // let's generate the attendee objects |
|
242 | + $attendees = []; |
|
243 | + $var_array = [ |
|
244 | + 'fname', |
|
245 | + 'lname', |
|
246 | + 'email', |
|
247 | + 'address', |
|
248 | + 'address2', |
|
249 | + 'city', |
|
250 | + 'staid', |
|
251 | + 'cntry', |
|
252 | + 'zip', |
|
253 | + 'phone', |
|
254 | + 'deleted', |
|
255 | + 'attid', |
|
256 | + ]; |
|
257 | + |
|
258 | + // EE_Registry::instance()->load_class( 'Attendee', array(), FALSE, false, TRUE ); |
|
259 | + foreach ($dummy_attendees as $dummy) { |
|
260 | + $att = array_combine($var_array, $dummy); |
|
261 | + extract($att); |
|
262 | + /** @var $fname string */ |
|
263 | + /** @var $lname string */ |
|
264 | + /** @var $address string */ |
|
265 | + /** @var $address2 string */ |
|
266 | + /** @var $city string */ |
|
267 | + /** @var $staid string */ |
|
268 | + /** @var $cntry string */ |
|
269 | + /** @var $zip string */ |
|
270 | + /** @var $email string */ |
|
271 | + /** @var $phone string */ |
|
272 | + /** @var $attid string */ |
|
273 | + $attendees[ $attid ] = EE_Attendee::new_instance( |
|
274 | + [ |
|
275 | + 'ATT_fname' => $fname, |
|
276 | + 'ATT_lname' => $lname, |
|
277 | + 'ATT_address' => $address, |
|
278 | + 'ATT_address2' => $address2, |
|
279 | + 'ATT_city' => $city, |
|
280 | + 'STA_ID' => $staid, |
|
281 | + 'CNT_ISO' => $cntry, |
|
282 | + 'ATT_zip' => $zip, |
|
283 | + 'ATT_email' => $email, |
|
284 | + 'ATT_phone' => $phone, |
|
285 | + 'ATT_ID' => $attid, |
|
286 | + ] |
|
287 | + ); |
|
288 | + } |
|
289 | + |
|
290 | + return $attendees; |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + /** |
|
295 | + * Return an array of dummy question objects indexed by answer id and dummy answer objects indexed by answer id. |
|
296 | + * This will be used in our dummy data setup |
|
297 | + * |
|
298 | + * @return array |
|
299 | + * @throws EE_Error |
|
300 | + * @throws ReflectionException |
|
301 | + */ |
|
302 | + private function _get_some_q_and_as() |
|
303 | + { |
|
304 | + $quests_array = [ |
|
305 | + 0 => [ |
|
306 | + 555, |
|
307 | + esc_html__('What is your favorite planet?', 'event_espresso'), |
|
308 | + 0, |
|
309 | + ], |
|
310 | + 1 => [ |
|
311 | + 556, |
|
312 | + esc_html__('What is your favorite food?', 'event_espresso'), |
|
313 | + 0, |
|
314 | + ], |
|
315 | + 2 => [ |
|
316 | + 557, |
|
317 | + esc_html__('How many lightyears have you travelled', 'event_espresso'), |
|
318 | + 0, |
|
319 | + ], |
|
320 | + ]; |
|
321 | + |
|
322 | + $ans_array = [ |
|
323 | + 0 => [ |
|
324 | + 999, |
|
325 | + 555, |
|
326 | + 'Tattoine', |
|
327 | + ], |
|
328 | + 1 => [ |
|
329 | + 1000, |
|
330 | + 555, |
|
331 | + 'Alderaan', |
|
332 | + ], |
|
333 | + 2 => [ |
|
334 | + 1001, |
|
335 | + 555, |
|
336 | + 'Dantooine', |
|
337 | + ], |
|
338 | + 3 => [ |
|
339 | + 1002, |
|
340 | + 556, |
|
341 | + 'Fish Fingers', |
|
342 | + ], |
|
343 | + 4 => [ |
|
344 | + 1003, |
|
345 | + 556, |
|
346 | + 'Sushi', |
|
347 | + ], |
|
348 | + 5 => [ |
|
349 | + 1004, |
|
350 | + 556, |
|
351 | + 'Water', |
|
352 | + ], |
|
353 | + 6 => [ |
|
354 | + 1005, |
|
355 | + 557, |
|
356 | + 'A lot', |
|
357 | + ], |
|
358 | + 7 => [ |
|
359 | + 1006, |
|
360 | + 557, |
|
361 | + "That's none of your business.", |
|
362 | + ], |
|
363 | + 8 => [ |
|
364 | + 1007, |
|
365 | + 557, |
|
366 | + "People less travel me then.", |
|
367 | + ], |
|
368 | + ]; |
|
369 | + |
|
370 | + $qst_columns = ['QST_ID', 'QST_display_text', 'QST_system']; |
|
371 | + $ans_columns = ['ANS_ID', 'QST_ID', 'ANS_value']; |
|
372 | + |
|
373 | + // EE_Registry::instance()->load_class( 'Question', array(), FALSE, TRUE, TRUE ); |
|
374 | + // EE_Registry::instance()->load_class( 'Answer', array(), FALSE, TRUE, TRUE ); |
|
375 | + |
|
376 | + $qsts = []; |
|
377 | + // first the questions |
|
378 | + foreach ($quests_array as $qst) { |
|
379 | + $qstobj = array_combine($qst_columns, $qst); |
|
380 | + $qsts[ $qstobj['QST_ID'] ] = EE_Question::new_instance($qstobj); |
|
381 | + } |
|
382 | + |
|
383 | + // now the answers (and we'll setup our arrays) |
|
384 | + $q_n_as = []; |
|
385 | + foreach ($ans_array as $ans) { |
|
386 | + $ansobj = array_combine($ans_columns, $ans); |
|
387 | + $ansobj = EE_Answer::new_instance($ansobj); |
|
388 | + $q_n_as['answers'][ $ansobj->ID() ] = $ansobj; |
|
389 | + $q_n_as['questions'][ $ansobj->ID() ] = $qsts[ $ansobj->get('QST_ID') ]; |
|
390 | + } |
|
391 | + |
|
392 | + return $q_n_as; |
|
393 | + } |
|
394 | + |
|
395 | + |
|
396 | + /** |
|
397 | + * Return an array of event objects from the database |
|
398 | + * |
|
399 | + * If event ids are not included then we'll just retrieve the first published event from the database. |
|
400 | + * |
|
401 | + * @param array $event_ids if set, this will be an array of event ids to obtain events for. |
|
402 | + * |
|
403 | + * @return array An array of event objects from the db. |
|
404 | + * @throws EE_Error |
|
405 | + */ |
|
406 | + private function _get_some_events(array $event_ids = []) |
|
407 | + { |
|
408 | + /** @var RequestInterface $request */ |
|
409 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
410 | + // if we have an evt_id then we want to make sure we use that for the preview |
|
411 | + // (because a specific event template is being viewed); |
|
412 | + $event_ids = $request->getRequestParam('evt_id', $event_ids, 'int', true); |
|
413 | + // clear out any invalid IDs, like 0 |
|
414 | + $event_ids = array_filter($event_ids); |
|
415 | + $limit = ! empty($event_ids) |
|
416 | + ? null |
|
417 | + : apply_filters('FHEE__EE_Messages_Preview_incoming_data___get_some_events__limit', '0,1'); |
|
418 | + |
|
419 | + $where = ! empty($event_ids) |
|
420 | + ? [ |
|
421 | + 'EVT_ID' => ['IN', $event_ids], |
|
422 | + 'Datetime.Ticket.TKT_ID' => ['>', 1], |
|
423 | + ] |
|
424 | + : ['Datetime.Ticket.TKT_ID' => ['>', 1]]; |
|
425 | + |
|
426 | + return EEM_Event::instance()->get_all([$where, 'limit' => $limit]); |
|
427 | + } |
|
428 | + |
|
429 | + |
|
430 | + /** |
|
431 | + * @throws EE_Error |
|
432 | + * @throws ReflectionException |
|
433 | + */ |
|
434 | + protected function _setup_data() |
|
435 | + { |
|
436 | + // need to figure out the running total for test purposes so... we're going to create a temp cart and add the tickets to it! |
|
437 | + if (EE_Registry::instance()->SSN instanceof EE_Session) { |
|
438 | + EE_Registry::instance()->SSN->clear_session(__CLASS__, __FUNCTION__); |
|
439 | + $session = EE_Registry::instance()->SSN; |
|
440 | + } else { |
|
441 | + $session = EE_Registry::instance()->load_core('Session'); |
|
442 | + } |
|
443 | + $cart = EE_Cart::instance(null, $session); |
|
444 | + |
|
445 | + // add tickets to cart |
|
446 | + foreach ($this->tickets as $ticket) { |
|
447 | + $cart->add_ticket_to_cart($ticket['ticket']); |
|
448 | + } |
|
449 | + |
|
450 | + // setup txn property |
|
451 | + $this->txn = EE_Transaction::new_instance( |
|
452 | + [ |
|
453 | + 'TXN_timestamp' => time(), // unix timestamp |
|
454 | + 'TXN_total' => 0, // txn_total |
|
455 | + 'TXN_paid' => 0, // txn_paid |
|
456 | + 'STS_ID' => EEM_Transaction::incomplete_status_code, // sts_id |
|
457 | + 'TXN_session_data' => null, // dump of txn session object (we're just going to leave blank here) |
|
458 | + 'TXN_hash_salt' => null, // hash salt blank as well |
|
459 | + 'TXN_ID' => 999999, |
|
460 | + ] |
|
461 | + ); |
|
462 | + |
|
463 | + |
|
464 | + // setup reg_objects |
|
465 | + // note we're setting up a reg object for each attendee in each event but ALSO adding to the reg_object array. |
|
466 | + $this->reg_objs = []; |
|
467 | + $regid = 9999990; |
|
468 | + foreach ($this->_attendees as $key => $attendee) { |
|
469 | + // note we need to setup reg_objects for each event this attendee belongs to |
|
470 | + $regatt = $attendee['att_obj'] instanceof EE_Attendee ? $attendee['att_obj']->ID() : null; |
|
471 | + $regtxn = $this->txn->ID(); |
|
472 | + $regcnt = 1; |
|
473 | + foreach ($attendee['line_ref'] as $evtid) { |
|
474 | + foreach ($this->_events[ $evtid ]['tkt_objs'] as $ticket) { |
|
475 | + if (! $ticket instanceof EE_Ticket) { |
|
476 | + continue; |
|
477 | + } |
|
478 | + $reg_array = [ |
|
479 | + 'EVT_ID' => $evtid, |
|
480 | + 'ATT_ID' => $regatt, |
|
481 | + 'TXN_ID' => $regtxn, |
|
482 | + 'TKT_ID' => $ticket->ID(), |
|
483 | + 'STS_ID' => RegStatus::PENDING_PAYMENT, |
|
484 | + 'REG_date' => time(), |
|
485 | + 'REG_final_price' => $ticket->get('TKT_price'), |
|
486 | + 'REG_session' => 'dummy_session_id', |
|
487 | + 'REG_code' => $regid . '-dummy-generated-code', |
|
488 | + 'REG_url_link' => $regcnt . '-daafpapasdlfakasdfpqasdfasdf', |
|
489 | + 'REG_count' => $regcnt, |
|
490 | + 'REG_group_size' => $this->_events[ $evtid ]['total_attendees'], |
|
491 | + 'REG_att_is_going' => true, |
|
492 | + 'REG_ID' => $regid, |
|
493 | + ]; |
|
494 | + $REG_OBJ = EE_Registration::new_instance($reg_array); |
|
495 | + $this->_attendees[ $key ]['reg_objs'][ $regid ] = $REG_OBJ; |
|
496 | + $this->_events[ $evtid ]['reg_objs'][] = $REG_OBJ; |
|
497 | + $this->reg_objs[] = $REG_OBJ; |
|
498 | + $this->tickets[ $ticket->ID() ]['reg_objs'][ $regid ] = $REG_OBJ; |
|
499 | + |
|
500 | + $regcnt++; |
|
501 | + $regid++; |
|
502 | + } |
|
503 | + } |
|
504 | + } |
|
505 | + |
|
506 | + |
|
507 | + // setup line items! |
|
508 | + $line_item_total = EEH_Line_Item::create_total_line_item($this->txn); |
|
509 | + |
|
510 | + // add tickets |
|
511 | + foreach ($this->tickets as $item) { |
|
512 | + $qty = $item['count']; |
|
513 | + $ticket = $item['ticket']; |
|
514 | + EEH_Line_Item::add_ticket_purchase($line_item_total, $ticket, $qty); |
|
515 | + } |
|
516 | + |
|
517 | + $shipping_line_item = EE_Line_Item::new_instance( |
|
518 | + [ |
|
519 | + 'LIN_name' => esc_html__( |
|
520 | + 'Shipping Surcharge', |
|
521 | + 'event_espresso' |
|
522 | + ), |
|
523 | + 'LIN_desc' => esc_html__( |
|
524 | + 'Sent via Millenium Falcon', |
|
525 | + 'event_espresso' |
|
526 | + ), |
|
527 | + 'LIN_unit_price' => 20, |
|
528 | + 'LIN_quantity' => 1, |
|
529 | + 'LIN_is_taxable' => true, |
|
530 | + 'LIN_total' => 20, |
|
531 | + 'LIN_type' => EEM_Line_Item::type_line_item, |
|
532 | + ] |
|
533 | + ); |
|
534 | + EEH_Line_Item::add_item($line_item_total, $shipping_line_item); |
|
535 | + $this->additional_line_items = [$shipping_line_item]; |
|
536 | + |
|
537 | + // now let's add taxes |
|
538 | + EEH_Line_Item::apply_taxes($line_item_total); |
|
539 | + |
|
540 | + // now we should be able to get the items we need from this object |
|
541 | + $event_line_items = EEH_Line_Item::get_pre_tax_subtotal($line_item_total)->children(); |
|
542 | + $line_items = []; |
|
543 | + foreach ($event_line_items as $line_item) { |
|
544 | + if (! $line_item instanceof EE_Line_Item || $line_item->OBJ_type() !== 'Event') { |
|
545 | + continue; |
|
546 | + } |
|
547 | + $ticket_line_items = EEH_Line_Item::get_ticket_line_items($line_item); |
|
548 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
549 | + if (! $ticket_line_item instanceof EE_Line_Item) { |
|
550 | + continue; |
|
551 | + } |
|
552 | + $this->tickets[ $ticket_line_item->OBJ_ID() ]['line_item'] = $ticket_line_item; |
|
553 | + $this->tickets[ $ticket_line_item->OBJ_ID() ]['sub_line_items'] = $ticket_line_item->children(); |
|
554 | + $line_items[ $ticket_line_item->ID() ]['children'] = $ticket_line_item->children(); |
|
555 | + $line_items[ $ticket_line_item->ID() ]['EE_Ticket'] = |
|
556 | + $this->tickets[ $ticket_line_item->OBJ_ID() ]['ticket']; |
|
557 | + } |
|
558 | + } |
|
559 | + |
|
560 | + $this->line_items_with_children = $line_items; |
|
561 | + $this->tax_line_items = $line_item_total->tax_descendants(); |
|
562 | + |
|
563 | + // add proper total to transaction object. |
|
564 | + $grand_total = $line_item_total->recalculate_total_including_taxes(); |
|
565 | + $this->grand_total_line_item = $line_item_total; |
|
566 | + $this->txn->set_total($grand_total); |
|
567 | + |
|
568 | + |
|
569 | + // add additional details for each registration |
|
570 | + foreach ($this->reg_objs as $reg) { |
|
571 | + if (! $reg instanceof EE_Registration) { |
|
572 | + continue; |
|
573 | + } |
|
574 | + $this->_registrations[ $reg->ID() ]['tkt_obj'] = $this->tickets[ $reg->get('TKT_ID') ]['ticket']; |
|
575 | + $this->_registrations[ $reg->ID() ]['evt_obj'] = $this->_events[ $reg->get('EVT_ID') ]['event']; |
|
576 | + $this->_registrations[ $reg->ID() ]['reg_obj'] = $reg; |
|
577 | + $this->_registrations[ $reg->ID() ]['ans_objs'] = $this->_attendees[ $reg->get('ATT_ID') ]['ans_objs']; |
|
578 | + $this->_registrations[ $reg->ID() ]['att_obj'] = $this->_attendees[ $reg->get('ATT_ID') ]['att_obj']; |
|
579 | + $this->_registrations[ $reg->ID() ]['dtt_objs'] = $this->tickets[ $reg->get('TKT_ID') ]['dtt_objs']; |
|
580 | + } |
|
581 | + |
|
582 | + |
|
583 | + // events and attendees |
|
584 | + $this->events = $this->_events; |
|
585 | + $this->attendees = $this->_attendees; |
|
586 | + $this->registrations = $this->_registrations; |
|
587 | + |
|
588 | + $attendees_to_shift = $this->_attendees; |
|
589 | + |
|
590 | + // setup primary attendee property |
|
591 | + $this->primary_attendee_data = [ |
|
592 | + 'fname' => $this->_attendees[999999991]['att_obj'] instanceof EE_Attendee |
|
593 | + ? $this->_attendees[999999991]['att_obj']->fname() |
|
594 | + : '', |
|
595 | + |
|
596 | + 'lname' => $this->_attendees[999999991]['att_obj'] instanceof EE_Attendee |
|
597 | + ? $this->_attendees[999999991]['att_obj']->lname() |
|
598 | + : '', |
|
599 | + |
|
600 | + 'email' => $this->_attendees[999999991]['att_obj'] instanceof EE_Attendee |
|
601 | + ? $this->_attendees[999999991]['att_obj']->email() |
|
602 | + : '', |
|
603 | + |
|
604 | + 'att_obj' => $this->_attendees[999999991]['att_obj'], |
|
605 | + |
|
606 | + 'reg_obj' => array_shift($attendees_to_shift[999999991]['reg_objs']), |
|
607 | + ]; |
|
608 | + |
|
609 | + // reg_info property |
|
610 | + // note this isn't referenced by any shortcode parsers so we'll ignore for now. |
|
611 | + $this->reg_info = []; |
|
612 | + |
|
613 | + // let's set a reg_obj for messengers expecting one. |
|
614 | + $this->reg_obj = array_shift($this->_attendees[999999991]['reg_objs']); |
|
615 | + |
|
616 | + // the below are just dummy items. |
|
617 | + $this->user_id = 1; |
|
618 | + $this->ip_address = '192.0.2.1'; |
|
619 | + $this->user_agent = ''; |
|
620 | + $this->init_access = time(); |
|
621 | + $this->last_access = time(); |
|
622 | + } |
|
623 | 623 | } |
@@ -284,7 +284,7 @@ discard block |
||
284 | 284 | public function queue_for_generation(EE_Message_To_Generate $message_to_generate, $test_send = false) |
285 | 285 | { |
286 | 286 | if ($message_to_generate->valid()) { |
287 | - if (! $this->_generator->create_and_add_message_to_queue($message_to_generate, $test_send)) { |
|
287 | + if ( ! $this->_generator->create_and_add_message_to_queue($message_to_generate, $test_send)) { |
|
288 | 288 | throw new RuntimeException( |
289 | 289 | esc_html__('Message failed to generate', 'event_espresso') |
290 | 290 | ); |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | protected function _queue_for_generation_loop($messages_to_generate) |
331 | 331 | { |
332 | 332 | // make sure is in an array. |
333 | - if (! is_array($messages_to_generate)) { |
|
333 | + if ( ! is_array($messages_to_generate)) { |
|
334 | 334 | $messages_to_generate = [$messages_to_generate]; |
335 | 335 | } |
336 | 336 | |
@@ -370,7 +370,7 @@ discard block |
||
370 | 370 | */ |
371 | 371 | public function generate_for_preview(EE_Message_To_Generate $message_to_generate, $test_send = false) |
372 | 372 | { |
373 | - if (! $message_to_generate->valid()) { |
|
373 | + if ( ! $message_to_generate->valid()) { |
|
374 | 374 | EE_Error::add_error( |
375 | 375 | esc_html__('Unable to generate preview because of invalid data', 'event_espresso'), |
376 | 376 | __FILE__, |
@@ -407,7 +407,7 @@ discard block |
||
407 | 407 | */ |
408 | 408 | public function queue_for_sending(EE_Message_To_Generate $message_to_generate) |
409 | 409 | { |
410 | - if (! $message_to_generate->valid()) { |
|
410 | + if ( ! $message_to_generate->valid()) { |
|
411 | 411 | return false; |
412 | 412 | } |
413 | 413 | $this->_init_queue_and_generator(); |
@@ -432,7 +432,7 @@ discard block |
||
432 | 432 | */ |
433 | 433 | public function generate_and_send_now(EE_Message_To_Generate $message_to_generate) |
434 | 434 | { |
435 | - if (! $message_to_generate->valid()) { |
|
435 | + if ( ! $message_to_generate->valid()) { |
|
436 | 436 | return null; |
437 | 437 | } |
438 | 438 | // is there supposed to be a sending messenger for this message? |
@@ -579,7 +579,7 @@ discard block |
||
579 | 579 | |
580 | 580 | foreach ($regIDs as $regID) { |
581 | 581 | $reg = EEM_Registration::instance()->get_one_by_ID($regID); |
582 | - if (! $reg instanceof EE_Registration) { |
|
582 | + if ( ! $reg instanceof EE_Registration) { |
|
583 | 583 | EE_Error::add_error( |
584 | 584 | sprintf( |
585 | 585 | esc_html__( |
@@ -591,7 +591,7 @@ discard block |
||
591 | 591 | ); |
592 | 592 | return false; |
593 | 593 | } |
594 | - $regs_to_send[ $reg->transaction_ID() ][ $reg->status_ID() ][] = $reg; |
|
594 | + $regs_to_send[$reg->transaction_ID()][$reg->status_ID()][] = $reg; |
|
595 | 595 | } |
596 | 596 | |
597 | 597 | $messages_to_generate = []; |
@@ -599,7 +599,7 @@ discard block |
||
599 | 599 | foreach ($regs_to_send as $status_group) { |
600 | 600 | foreach ($status_group as $status_id => $registrations) { |
601 | 601 | $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($status_id); |
602 | - if (! $message_type) { |
|
602 | + if ( ! $message_type) { |
|
603 | 603 | continue; |
604 | 604 | } |
605 | 605 | $messages_to_generate = array_merge( |
@@ -14,602 +14,602 @@ |
||
14 | 14 | */ |
15 | 15 | class EE_Messages_Processor |
16 | 16 | { |
17 | - /** |
|
18 | - * @type EE_Message_Resource_Manager $_message_resource_manager |
|
19 | - */ |
|
20 | - protected $_message_resource_manager; |
|
21 | - |
|
22 | - /** |
|
23 | - * @type EE_Messages_Queue |
|
24 | - */ |
|
25 | - protected $_queue; |
|
26 | - |
|
27 | - /** |
|
28 | - * @type EE_Messages_Generator |
|
29 | - */ |
|
30 | - protected $_generator; |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * constructor |
|
35 | - * |
|
36 | - * @param EE_Message_Resource_Manager $message_resource_manager |
|
37 | - */ |
|
38 | - public function __construct(EE_Message_Resource_Manager $message_resource_manager) |
|
39 | - { |
|
40 | - $this->_message_resource_manager = $message_resource_manager; |
|
41 | - $this->_init_queue_and_generator(); |
|
42 | - } |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * This method sets (or resets) the various properties for use. |
|
47 | - * |
|
48 | - * - $_queue = holds the messages queue |
|
49 | - * - $_generator = holds the messages generator |
|
50 | - */ |
|
51 | - protected function _init_queue_and_generator() |
|
52 | - { |
|
53 | - $this->_generator = EE_Registry::factory('EE_Messages_Generator'); |
|
54 | - $this->_queue = $this->_generator->generation_queue(); |
|
55 | - } |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * This returns the current set queue. |
|
60 | - * |
|
61 | - * @return EE_Messages_Queue |
|
62 | - */ |
|
63 | - public function get_queue() |
|
64 | - { |
|
65 | - return $this->_queue; |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * This method can be utilized to process messages from a queue and they will be processed immediately on the same |
|
71 | - * request. Please note that this method alone does not bypass the usual "locks" for generation/sending (it assumes |
|
72 | - * client code has already filtered those if necessary). |
|
73 | - * |
|
74 | - * @param EE_Messages_Queue $queue_to_process |
|
75 | - * @return bool true for success false for error. |
|
76 | - * @throws EE_Error |
|
77 | - * @throws ReflectionException |
|
78 | - */ |
|
79 | - public function process_immediately_from_queue(EE_Messages_Queue $queue_to_process) |
|
80 | - { |
|
81 | - $success = false; |
|
82 | - $messages_to_send = []; |
|
83 | - $messages_to_generate = []; |
|
84 | - // loop through and setup the various messages from the queue so we know what is being processed |
|
85 | - $queue_to_process->get_message_repository()->rewind(); |
|
86 | - foreach ($queue_to_process->get_message_repository() as $message) { |
|
87 | - if ($message->STS_ID() === EEM_Message::status_incomplete) { |
|
88 | - $messages_to_generate[] = $message; |
|
89 | - continue; |
|
90 | - } |
|
91 | - |
|
92 | - if (in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send())) { |
|
93 | - $messages_to_send[] = $message; |
|
94 | - } |
|
95 | - } |
|
96 | - |
|
97 | - // do generation/sends |
|
98 | - if ($messages_to_generate) { |
|
99 | - $success = $this->batch_generate_from_queue($messages_to_generate, true); |
|
100 | - } |
|
101 | - |
|
102 | - if ($messages_to_send) { |
|
103 | - $sent = $this->batch_send_from_queue($messages_to_send, true); |
|
104 | - // if there was messages to generate and it failed, then we override any success value for the sending process |
|
105 | - // otherwise we just use the return from batch send. The intent is that there is a simple response for success/fail. |
|
106 | - // Either everything was successful or we consider it a fail. To be clear, this is a limitation of doing |
|
107 | - // all messages processing on the same request. |
|
108 | - $success = $messages_to_generate && ! $success ? false : $sent; |
|
109 | - } |
|
110 | - return $success; |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * Calls the EE_Messages_Queue::get_batch_to_generate() method and sends to EE_Messages_Generator. |
|
116 | - * |
|
117 | - * @param EE_Message[] $messages Array of EE_Message objects (optional) to build the queue with. |
|
118 | - * @param bool $clear_queue Whether to ensure a fresh queue or not. |
|
119 | - * |
|
120 | - * @return bool|EE_Messages_Queue return false if nothing generated. This returns a new EE_Message_Queue with |
|
121 | - * generated messages. |
|
122 | - * @throws EE_Error |
|
123 | - * @throws ReflectionException |
|
124 | - */ |
|
125 | - public function batch_generate_from_queue($messages = [], $clear_queue = false) |
|
126 | - { |
|
127 | - if ($this->_build_queue_for_generation($messages, $clear_queue)) { |
|
128 | - $new_queue = $this->_generator->generate(); |
|
129 | - if ($new_queue instanceof EE_Messages_Queue) { |
|
130 | - // unlock queue |
|
131 | - $this->_queue->unlock_queue(); |
|
132 | - $new_queue->initiate_request_by_priority('send'); |
|
133 | - return $new_queue; |
|
134 | - } |
|
135 | - } |
|
136 | - $this->_queue->unlock_queue(); |
|
137 | - return false; |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * This method preps a queue for generation. |
|
143 | - * |
|
144 | - * @param EE_Message[] $messages Array of EE_Message objects to build the queue with |
|
145 | - * |
|
146 | - * @param bool $clear_queue This indicates whether the existing queue should be dumped or not. |
|
147 | - * |
|
148 | - * @return bool true means queue prepped, false means there was a lock so no generation please. |
|
149 | - * @throws EE_Error |
|
150 | - * @throws ReflectionException |
|
151 | - * @since 4.9.0 |
|
152 | - * |
|
153 | - */ |
|
154 | - protected function _build_queue_for_generation($messages = [], $clear_queue = false) |
|
155 | - { |
|
156 | - |
|
157 | - if ($clear_queue) { |
|
158 | - $this->_init_queue_and_generator(); |
|
159 | - } |
|
160 | - |
|
161 | - if ($messages) { |
|
162 | - // if generation is locked then get out now because that means processing is already happening. |
|
163 | - if ($this->_queue->is_locked()) { |
|
164 | - return false; |
|
165 | - } |
|
166 | - |
|
167 | - $this->_queue->lock_queue(); |
|
168 | - $messages = is_array($messages) ? $messages : [$messages]; |
|
169 | - foreach ($messages as $message) { |
|
170 | - if ($message instanceof EE_Message) { |
|
171 | - $data = $message->all_extra_meta_array(); |
|
172 | - $this->_queue->add($message, $data); |
|
173 | - } |
|
174 | - } |
|
175 | - return true; |
|
176 | - } else { |
|
177 | - return $this->_queue->get_batch_to_generate(); |
|
178 | - } |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * This method preps a queue for sending. |
|
184 | - * |
|
185 | - * @param EE_Message[] $messages |
|
186 | - * @param bool $clear_queue Used to indicate whether to start with a fresh queue or not. |
|
187 | - * |
|
188 | - * @return bool true means queue prepped, false means there was a lock so no queue prepped. |
|
189 | - */ |
|
190 | - protected function _build_queue_for_sending($messages, $clear_queue = false) |
|
191 | - { |
|
192 | - // if sending is locked then get out now because that means processing is already happening. |
|
193 | - if ($this->_queue->is_locked(EE_Messages_Queue::action_sending)) { |
|
194 | - return false; |
|
195 | - } |
|
196 | - |
|
197 | - $this->_queue->lock_queue(EE_Messages_Queue::action_sending); |
|
198 | - |
|
199 | - if ($clear_queue) { |
|
200 | - $this->_init_queue_and_generator(); |
|
201 | - } |
|
202 | - |
|
203 | - $messages = is_array($messages) ? $messages : [$messages]; |
|
204 | - |
|
205 | - foreach ($messages as $message) { |
|
206 | - $this->_queue->add($message); |
|
207 | - } |
|
208 | - return true; |
|
209 | - } |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * Calls the EE_Message_Queue::get_to_send_batch_and_send() method and then immediately just calls |
|
214 | - * EE_Message_Queue::execute() to iterate and send unsent messages. |
|
215 | - * |
|
216 | - * @param EE_Message[] $messages If an array of messages is sent in then use it. |
|
217 | - * |
|
218 | - * @param bool $clear_queue Whether to initialize a new queue or keep the existing one. |
|
219 | - * |
|
220 | - * @return EE_Messages_Queue |
|
221 | - * @throws EE_Error |
|
222 | - * @throws ReflectionException |
|
223 | - */ |
|
224 | - public function batch_send_from_queue($messages = [], $clear_queue = false) |
|
225 | - { |
|
226 | - |
|
227 | - if ($messages && $this->_build_queue_for_sending($messages, $clear_queue)) { |
|
228 | - $this->_queue->execute(); |
|
229 | - $this->_queue->unlock_queue(EE_Messages_Queue::action_sending); |
|
230 | - } else { |
|
231 | - // get messages to send and execute. |
|
232 | - $this->_queue->get_to_send_batch_and_send(); |
|
233 | - } |
|
234 | - // note: callers can use the EE_Messages_Queue::count_STS_in_queue() method to find out if there were any failed |
|
235 | - // messages in the queue and decide how to handle at that point. |
|
236 | - return $this->_queue; |
|
237 | - } |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * This immediately generates messages using the given array of EE_Message_To_Generate objects and returns the |
|
242 | - * EE_Message_Queue with the generated messages for the caller to work with. Note, this does NOT save the generated |
|
243 | - * messages in the queue, leaving it up to the caller to do so. |
|
244 | - * |
|
245 | - * @param EE_Message_To_Generate[] $messages_to_generate |
|
246 | - * @return EE_Messages_Queue |
|
247 | - * @throws EE_Error |
|
248 | - * @throws ReflectionException |
|
249 | - */ |
|
250 | - public function generate_and_return($messages_to_generate) |
|
251 | - { |
|
252 | - $this->_init_queue_and_generator(); |
|
253 | - $this->_queue_for_generation_loop($messages_to_generate); |
|
254 | - return $this->_generator->generate(false); |
|
255 | - } |
|
256 | - |
|
257 | - |
|
258 | - /** |
|
259 | - * Executes the generator generate method on the current internal queue, and returns the generated queue. |
|
260 | - * |
|
261 | - * @param bool $persist Indicate whether to instruct the generator to persist the generated queue (true) or not |
|
262 | - * (false). |
|
263 | - * @return EE_Messages_Queue |
|
264 | - * @throws EE_Error |
|
265 | - * @throws ReflectionException |
|
266 | - */ |
|
267 | - public function generate_queue($persist = true) |
|
268 | - { |
|
269 | - return $this->_generator->generate($persist); |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - /** |
|
274 | - * Queue for generation. Note this does NOT persist to the db. Client code should call |
|
275 | - * get_message_repository()->save() if desire to persist. This method is provided to client code to decide what it |
|
276 | - * wants to do with queued messages for generation. |
|
277 | - * |
|
278 | - * @param EE_Message_To_Generate $message_to_generate |
|
279 | - * @param bool $test_send Whether this item is for a test send or not. |
|
280 | - * @return void |
|
281 | - */ |
|
282 | - public function queue_for_generation(EE_Message_To_Generate $message_to_generate, $test_send = false) |
|
283 | - { |
|
284 | - if ($message_to_generate->valid()) { |
|
285 | - if (! $this->_generator->create_and_add_message_to_queue($message_to_generate, $test_send)) { |
|
286 | - throw new RuntimeException( |
|
287 | - esc_html__('Message failed to generate', 'event_espresso') |
|
288 | - ); |
|
289 | - } |
|
290 | - } |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - /** |
|
295 | - * This receives an array of EE_Message_To_Generate objects, converts them to EE_Message adds them to the |
|
296 | - * generation queue and then persists to storage. |
|
297 | - * |
|
298 | - * @param EE_Message_To_Generate[] $messages_to_generate |
|
299 | - */ |
|
300 | - public function batch_queue_for_generation_and_persist($messages_to_generate) |
|
301 | - { |
|
302 | - $this->_init_queue_and_generator(); |
|
303 | - $this->_queue_for_generation_loop($messages_to_generate); |
|
304 | - $this->_queue->save(); |
|
305 | - } |
|
306 | - |
|
307 | - |
|
308 | - /** |
|
309 | - * This receives an array of EE_Message_To_Generate objects, converts them to EE_Message and adds them to the |
|
310 | - * generation queue. Does NOT persist to storage (unless there is an error. Client code can retrieve the generated |
|
311 | - * queue by calling EEM_Messages_Processor::get_queue() |
|
312 | - * |
|
313 | - * @param EE_Message_To_Generate[] $messages_to_generate |
|
314 | - */ |
|
315 | - public function batch_queue_for_generation_no_persist($messages_to_generate) |
|
316 | - { |
|
317 | - $this->_init_queue_and_generator(); |
|
318 | - $this->_queue_for_generation_loop($messages_to_generate); |
|
319 | - } |
|
320 | - |
|
321 | - |
|
322 | - /** |
|
323 | - * Simply loops through the given array of EE_Message_To_Generate objects and adds them to the _queue as EE_Message |
|
324 | - * objects. |
|
325 | - * |
|
326 | - * @param EE_Message_To_Generate[] $messages_to_generate |
|
327 | - */ |
|
328 | - protected function _queue_for_generation_loop($messages_to_generate) |
|
329 | - { |
|
330 | - // make sure is in an array. |
|
331 | - if (! is_array($messages_to_generate)) { |
|
332 | - $messages_to_generate = [$messages_to_generate]; |
|
333 | - } |
|
334 | - |
|
335 | - foreach ($messages_to_generate as $message_to_generate) { |
|
336 | - if ($message_to_generate instanceof EE_Message_To_Generate && $message_to_generate->valid()) { |
|
337 | - $this->queue_for_generation($message_to_generate); |
|
338 | - } |
|
339 | - } |
|
340 | - } |
|
341 | - |
|
342 | - |
|
343 | - /** |
|
344 | - * Receives an array of EE_Message_To_Generate objects and generates the EE_Message objects, then persists (so its |
|
345 | - * queued for sending). |
|
346 | - * |
|
347 | - * @param EE_Message_To_Generate[] |
|
348 | - * @return EE_Messages_Queue |
|
349 | - * @throws EE_Error |
|
350 | - * @throws ReflectionException |
|
351 | - */ |
|
352 | - public function generate_and_queue_for_sending($messages_to_generate) |
|
353 | - { |
|
354 | - $this->_init_queue_and_generator(); |
|
355 | - $this->_queue_for_generation_loop($messages_to_generate); |
|
356 | - return $this->_generator->generate(); |
|
357 | - } |
|
358 | - |
|
359 | - |
|
360 | - /** |
|
361 | - * Generate for preview and execute right away. |
|
362 | - * |
|
363 | - * @param EE_Message_To_Generate $message_to_generate |
|
364 | - * @param bool $test_send Whether this is a test send or not. |
|
365 | - * @return EE_Messages_Queue | bool false if unable to generate otherwise the generated queue. |
|
366 | - * @throws EE_Error |
|
367 | - * @throws ReflectionException |
|
368 | - */ |
|
369 | - public function generate_for_preview(EE_Message_To_Generate $message_to_generate, $test_send = false) |
|
370 | - { |
|
371 | - if (! $message_to_generate->valid()) { |
|
372 | - EE_Error::add_error( |
|
373 | - esc_html__('Unable to generate preview because of invalid data', 'event_espresso'), |
|
374 | - __FILE__, |
|
375 | - __FUNCTION__, |
|
376 | - __LINE__ |
|
377 | - ); |
|
378 | - return false; |
|
379 | - } |
|
380 | - // just make sure preview is set on the $message_to_generate (in case client forgot) |
|
381 | - $message_to_generate->set_preview(true); |
|
382 | - $this->_init_queue_and_generator(); |
|
383 | - $this->queue_for_generation($message_to_generate, $test_send); |
|
384 | - $generated_queue = $this->_generator->generate(false); |
|
385 | - if ($generated_queue->execute(false)) { |
|
386 | - // the first queue item should be the preview |
|
387 | - $generated_queue->get_message_repository()->rewind(); |
|
388 | - if ($generated_queue->get_message_repository()->valid()) { |
|
389 | - return $generated_queue; |
|
390 | - } |
|
391 | - } |
|
392 | - return false; |
|
393 | - } |
|
394 | - |
|
395 | - |
|
396 | - /** |
|
397 | - * This queues for sending. |
|
398 | - * The messenger send now method is also verified to see if sending immediately is requested. |
|
399 | - * otherwise its just saved to the queue. |
|
400 | - * |
|
401 | - * @param EE_Message_To_Generate $message_to_generate |
|
402 | - * @return bool true or false for success. |
|
403 | - * @throws EE_Error |
|
404 | - * @throws ReflectionException |
|
405 | - */ |
|
406 | - public function queue_for_sending(EE_Message_To_Generate $message_to_generate) |
|
407 | - { |
|
408 | - if (! $message_to_generate->valid()) { |
|
409 | - return false; |
|
410 | - } |
|
411 | - $this->_init_queue_and_generator(); |
|
412 | - $message = $message_to_generate->get_EE_Message(); |
|
413 | - $this->_queue->add($message); |
|
414 | - if ($message->send_now()) { |
|
415 | - $this->_queue->execute(false); |
|
416 | - } else { |
|
417 | - $this->_queue->save(); |
|
418 | - } |
|
419 | - return true; |
|
420 | - } |
|
421 | - |
|
422 | - |
|
423 | - /** |
|
424 | - * This generates and sends from the given EE_Message_To_Generate class immediately. |
|
425 | - * |
|
426 | - * @param EE_Message_To_Generate $message_to_generate |
|
427 | - * @return EE_Messages_Queue | null |
|
428 | - * @throws EE_Error |
|
429 | - * @throws ReflectionException |
|
430 | - */ |
|
431 | - public function generate_and_send_now(EE_Message_To_Generate $message_to_generate) |
|
432 | - { |
|
433 | - if (! $message_to_generate->valid()) { |
|
434 | - return null; |
|
435 | - } |
|
436 | - // is there supposed to be a sending messenger for this message? |
|
437 | - if ($message_to_generate instanceof EEI_Has_Sending_Messenger) { |
|
438 | - // make sure it's valid, but if it's not, |
|
439 | - // then set the value of $sending_messenger to an EE_Error object |
|
440 | - // so that downstream code can easily see that things went wrong. |
|
441 | - $sending_messenger = $message_to_generate->sending_messenger() instanceof EE_messenger |
|
442 | - ? $message_to_generate->sending_messenger() |
|
443 | - : new EE_Error( |
|
444 | - esc_html__( |
|
445 | - 'There was a specific sending messenger requested for the send action, but it was either invalid or not active at time of sending.', |
|
446 | - 'event_espresso' |
|
447 | - ) |
|
448 | - ); |
|
449 | - } else { |
|
450 | - $sending_messenger = null; |
|
451 | - } |
|
452 | - |
|
453 | - if ($message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_idle) { |
|
454 | - $this->_init_queue_and_generator(); |
|
455 | - $this->_queue->add($message_to_generate->get_EE_Message()); |
|
456 | - $this->_queue->execute(false, $sending_messenger); |
|
457 | - return $this->_queue; |
|
458 | - } elseif ($message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_incomplete) { |
|
459 | - $generated_queue = $this->generate_and_return([$message_to_generate]); |
|
460 | - $generated_queue->execute(false, $sending_messenger); |
|
461 | - return $generated_queue; |
|
462 | - } |
|
463 | - return null; |
|
464 | - } |
|
465 | - |
|
466 | - |
|
467 | - /** |
|
468 | - * Creates mtg objects for all active messengers and queues for generation. |
|
469 | - * This method also calls the execute by priority method on the queue which will optionally kick off a new |
|
470 | - * non-blocking request to complete the action if the priority for the message requires immediate action. |
|
471 | - * |
|
472 | - * @param string $message_type |
|
473 | - * @param mixed $data The data being used for generation. |
|
474 | - * @param bool $persist Whether to persist the queued messages to the db or not. |
|
475 | - * @throws EE_Error |
|
476 | - * @throws ReflectionException |
|
477 | - */ |
|
478 | - public function generate_for_all_active_messengers($message_type, $data, $persist = true) |
|
479 | - { |
|
480 | - $messages_to_generate = $this->setup_mtgs_for_all_active_messengers($message_type, $data); |
|
481 | - if ($persist) { |
|
482 | - $this->batch_queue_for_generation_and_persist($messages_to_generate); |
|
483 | - $this->_queue->initiate_request_by_priority(); |
|
484 | - } else { |
|
485 | - $this->batch_queue_for_generation_no_persist($messages_to_generate); |
|
486 | - } |
|
487 | - } |
|
488 | - |
|
489 | - |
|
490 | - /** |
|
491 | - * This simply loops through all active messengers and takes care of setting up the |
|
492 | - * EE_Message_To_Generate objects. |
|
493 | - * |
|
494 | - * @param $message_type |
|
495 | - * @param $data |
|
496 | - * |
|
497 | - * @return EE_Message_To_Generate[] |
|
498 | - */ |
|
499 | - public function setup_mtgs_for_all_active_messengers($message_type, $data) |
|
500 | - { |
|
501 | - $messages_to_generate = []; |
|
502 | - foreach ($this->_message_resource_manager->active_messengers() as $messenger_slug => $messenger_object) { |
|
503 | - $message_to_generate = new EE_Message_To_Generate($messenger_slug, $message_type, $data); |
|
504 | - if ($message_to_generate->valid()) { |
|
505 | - $messages_to_generate[] = $message_to_generate; |
|
506 | - } |
|
507 | - } |
|
508 | - return $messages_to_generate; |
|
509 | - } |
|
510 | - |
|
511 | - |
|
512 | - /** |
|
513 | - * This accepts an array of EE_Message::MSG_ID values |
|
514 | - * and will use that to retrieve the objects from the database and send. |
|
515 | - * |
|
516 | - * @param array $message_ids |
|
517 | - * @throws EE_Error |
|
518 | - * @throws ReflectionException |
|
519 | - */ |
|
520 | - public function setup_messages_from_ids_and_send($message_ids) |
|
521 | - { |
|
522 | - $this->_init_queue_and_generator(); |
|
523 | - $messages = EEM_Message::instance()->get_all( |
|
524 | - [ |
|
525 | - [ |
|
526 | - 'MSG_ID' => ['IN', $message_ids], |
|
527 | - 'STS_ID' => [ |
|
528 | - 'IN', |
|
529 | - array_merge( |
|
530 | - EEM_Message::instance()->stati_indicating_sent(), |
|
531 | - [EEM_Message::status_retry] |
|
532 | - ), |
|
533 | - ], |
|
534 | - ], |
|
535 | - ] |
|
536 | - ); |
|
537 | - // set the Messages to resend. |
|
538 | - foreach ($messages as $message) { |
|
539 | - if ($message instanceof EE_Message) { |
|
540 | - $message->set_STS_ID(EEM_Message::status_resend); |
|
541 | - $this->_queue->add($message); |
|
542 | - } |
|
543 | - } |
|
544 | - |
|
545 | - $this->_queue->initiate_request_by_priority('send'); |
|
546 | - } |
|
547 | - |
|
548 | - |
|
549 | - /** |
|
550 | - * This method checks for registration IDs in the request via the given key and creates the messages to generate |
|
551 | - * objects from them, then returns the array of messages to generate objects. |
|
552 | - * Note, this sets up registrations for the registration family of message types. |
|
553 | - * |
|
554 | - * @param string $registration_ids_key This is used to indicate what represents the registration ids in the request. |
|
555 | - * |
|
556 | - * @return EE_Message_To_Generate[]|bool |
|
557 | - * @throws EE_Error |
|
558 | - */ |
|
559 | - public function setup_messages_to_generate_from_registration_ids_in_request($registration_ids_key = '_REG_ID') |
|
560 | - { |
|
561 | - /** @var RequestInterface $request */ |
|
562 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
563 | - $regs_to_send = []; |
|
564 | - $regIDs = $request->getRequestParam($registration_ids_key, [], 'int', true); |
|
565 | - if (empty($regIDs)) { |
|
566 | - EE_Error::add_error( |
|
567 | - esc_html__('Something went wrong because we\'re missing the registration ID', 'event_espresso'), |
|
568 | - __FILE__, |
|
569 | - __FUNCTION__, |
|
570 | - __LINE__ |
|
571 | - ); |
|
572 | - return false; |
|
573 | - } |
|
574 | - |
|
575 | - // make sure is an array |
|
576 | - $regIDs = is_array($regIDs) ? $regIDs : [$regIDs]; |
|
577 | - |
|
578 | - foreach ($regIDs as $regID) { |
|
579 | - $reg = EEM_Registration::instance()->get_one_by_ID($regID); |
|
580 | - if (! $reg instanceof EE_Registration) { |
|
581 | - EE_Error::add_error( |
|
582 | - sprintf( |
|
583 | - esc_html__( |
|
584 | - 'Unable to retrieve a registration object for the given reg id (%s)', |
|
585 | - 'event_espresso' |
|
586 | - ), |
|
587 | - $regID |
|
588 | - ) |
|
589 | - ); |
|
590 | - return false; |
|
591 | - } |
|
592 | - $regs_to_send[ $reg->transaction_ID() ][ $reg->status_ID() ][] = $reg; |
|
593 | - } |
|
594 | - |
|
595 | - $messages_to_generate = []; |
|
596 | - |
|
597 | - foreach ($regs_to_send as $status_group) { |
|
598 | - foreach ($status_group as $status_id => $registrations) { |
|
599 | - $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($status_id); |
|
600 | - if (! $message_type) { |
|
601 | - continue; |
|
602 | - } |
|
603 | - $messages_to_generate = array_merge( |
|
604 | - $messages_to_generate, |
|
605 | - $this->setup_mtgs_for_all_active_messengers( |
|
606 | - $message_type, |
|
607 | - [$registrations, $status_id] |
|
608 | - ) |
|
609 | - ); |
|
610 | - } |
|
611 | - } |
|
612 | - |
|
613 | - return $messages_to_generate; |
|
614 | - } |
|
17 | + /** |
|
18 | + * @type EE_Message_Resource_Manager $_message_resource_manager |
|
19 | + */ |
|
20 | + protected $_message_resource_manager; |
|
21 | + |
|
22 | + /** |
|
23 | + * @type EE_Messages_Queue |
|
24 | + */ |
|
25 | + protected $_queue; |
|
26 | + |
|
27 | + /** |
|
28 | + * @type EE_Messages_Generator |
|
29 | + */ |
|
30 | + protected $_generator; |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * constructor |
|
35 | + * |
|
36 | + * @param EE_Message_Resource_Manager $message_resource_manager |
|
37 | + */ |
|
38 | + public function __construct(EE_Message_Resource_Manager $message_resource_manager) |
|
39 | + { |
|
40 | + $this->_message_resource_manager = $message_resource_manager; |
|
41 | + $this->_init_queue_and_generator(); |
|
42 | + } |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * This method sets (or resets) the various properties for use. |
|
47 | + * |
|
48 | + * - $_queue = holds the messages queue |
|
49 | + * - $_generator = holds the messages generator |
|
50 | + */ |
|
51 | + protected function _init_queue_and_generator() |
|
52 | + { |
|
53 | + $this->_generator = EE_Registry::factory('EE_Messages_Generator'); |
|
54 | + $this->_queue = $this->_generator->generation_queue(); |
|
55 | + } |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * This returns the current set queue. |
|
60 | + * |
|
61 | + * @return EE_Messages_Queue |
|
62 | + */ |
|
63 | + public function get_queue() |
|
64 | + { |
|
65 | + return $this->_queue; |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * This method can be utilized to process messages from a queue and they will be processed immediately on the same |
|
71 | + * request. Please note that this method alone does not bypass the usual "locks" for generation/sending (it assumes |
|
72 | + * client code has already filtered those if necessary). |
|
73 | + * |
|
74 | + * @param EE_Messages_Queue $queue_to_process |
|
75 | + * @return bool true for success false for error. |
|
76 | + * @throws EE_Error |
|
77 | + * @throws ReflectionException |
|
78 | + */ |
|
79 | + public function process_immediately_from_queue(EE_Messages_Queue $queue_to_process) |
|
80 | + { |
|
81 | + $success = false; |
|
82 | + $messages_to_send = []; |
|
83 | + $messages_to_generate = []; |
|
84 | + // loop through and setup the various messages from the queue so we know what is being processed |
|
85 | + $queue_to_process->get_message_repository()->rewind(); |
|
86 | + foreach ($queue_to_process->get_message_repository() as $message) { |
|
87 | + if ($message->STS_ID() === EEM_Message::status_incomplete) { |
|
88 | + $messages_to_generate[] = $message; |
|
89 | + continue; |
|
90 | + } |
|
91 | + |
|
92 | + if (in_array($message->STS_ID(), EEM_Message::instance()->stati_indicating_to_send())) { |
|
93 | + $messages_to_send[] = $message; |
|
94 | + } |
|
95 | + } |
|
96 | + |
|
97 | + // do generation/sends |
|
98 | + if ($messages_to_generate) { |
|
99 | + $success = $this->batch_generate_from_queue($messages_to_generate, true); |
|
100 | + } |
|
101 | + |
|
102 | + if ($messages_to_send) { |
|
103 | + $sent = $this->batch_send_from_queue($messages_to_send, true); |
|
104 | + // if there was messages to generate and it failed, then we override any success value for the sending process |
|
105 | + // otherwise we just use the return from batch send. The intent is that there is a simple response for success/fail. |
|
106 | + // Either everything was successful or we consider it a fail. To be clear, this is a limitation of doing |
|
107 | + // all messages processing on the same request. |
|
108 | + $success = $messages_to_generate && ! $success ? false : $sent; |
|
109 | + } |
|
110 | + return $success; |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * Calls the EE_Messages_Queue::get_batch_to_generate() method and sends to EE_Messages_Generator. |
|
116 | + * |
|
117 | + * @param EE_Message[] $messages Array of EE_Message objects (optional) to build the queue with. |
|
118 | + * @param bool $clear_queue Whether to ensure a fresh queue or not. |
|
119 | + * |
|
120 | + * @return bool|EE_Messages_Queue return false if nothing generated. This returns a new EE_Message_Queue with |
|
121 | + * generated messages. |
|
122 | + * @throws EE_Error |
|
123 | + * @throws ReflectionException |
|
124 | + */ |
|
125 | + public function batch_generate_from_queue($messages = [], $clear_queue = false) |
|
126 | + { |
|
127 | + if ($this->_build_queue_for_generation($messages, $clear_queue)) { |
|
128 | + $new_queue = $this->_generator->generate(); |
|
129 | + if ($new_queue instanceof EE_Messages_Queue) { |
|
130 | + // unlock queue |
|
131 | + $this->_queue->unlock_queue(); |
|
132 | + $new_queue->initiate_request_by_priority('send'); |
|
133 | + return $new_queue; |
|
134 | + } |
|
135 | + } |
|
136 | + $this->_queue->unlock_queue(); |
|
137 | + return false; |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * This method preps a queue for generation. |
|
143 | + * |
|
144 | + * @param EE_Message[] $messages Array of EE_Message objects to build the queue with |
|
145 | + * |
|
146 | + * @param bool $clear_queue This indicates whether the existing queue should be dumped or not. |
|
147 | + * |
|
148 | + * @return bool true means queue prepped, false means there was a lock so no generation please. |
|
149 | + * @throws EE_Error |
|
150 | + * @throws ReflectionException |
|
151 | + * @since 4.9.0 |
|
152 | + * |
|
153 | + */ |
|
154 | + protected function _build_queue_for_generation($messages = [], $clear_queue = false) |
|
155 | + { |
|
156 | + |
|
157 | + if ($clear_queue) { |
|
158 | + $this->_init_queue_and_generator(); |
|
159 | + } |
|
160 | + |
|
161 | + if ($messages) { |
|
162 | + // if generation is locked then get out now because that means processing is already happening. |
|
163 | + if ($this->_queue->is_locked()) { |
|
164 | + return false; |
|
165 | + } |
|
166 | + |
|
167 | + $this->_queue->lock_queue(); |
|
168 | + $messages = is_array($messages) ? $messages : [$messages]; |
|
169 | + foreach ($messages as $message) { |
|
170 | + if ($message instanceof EE_Message) { |
|
171 | + $data = $message->all_extra_meta_array(); |
|
172 | + $this->_queue->add($message, $data); |
|
173 | + } |
|
174 | + } |
|
175 | + return true; |
|
176 | + } else { |
|
177 | + return $this->_queue->get_batch_to_generate(); |
|
178 | + } |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * This method preps a queue for sending. |
|
184 | + * |
|
185 | + * @param EE_Message[] $messages |
|
186 | + * @param bool $clear_queue Used to indicate whether to start with a fresh queue or not. |
|
187 | + * |
|
188 | + * @return bool true means queue prepped, false means there was a lock so no queue prepped. |
|
189 | + */ |
|
190 | + protected function _build_queue_for_sending($messages, $clear_queue = false) |
|
191 | + { |
|
192 | + // if sending is locked then get out now because that means processing is already happening. |
|
193 | + if ($this->_queue->is_locked(EE_Messages_Queue::action_sending)) { |
|
194 | + return false; |
|
195 | + } |
|
196 | + |
|
197 | + $this->_queue->lock_queue(EE_Messages_Queue::action_sending); |
|
198 | + |
|
199 | + if ($clear_queue) { |
|
200 | + $this->_init_queue_and_generator(); |
|
201 | + } |
|
202 | + |
|
203 | + $messages = is_array($messages) ? $messages : [$messages]; |
|
204 | + |
|
205 | + foreach ($messages as $message) { |
|
206 | + $this->_queue->add($message); |
|
207 | + } |
|
208 | + return true; |
|
209 | + } |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * Calls the EE_Message_Queue::get_to_send_batch_and_send() method and then immediately just calls |
|
214 | + * EE_Message_Queue::execute() to iterate and send unsent messages. |
|
215 | + * |
|
216 | + * @param EE_Message[] $messages If an array of messages is sent in then use it. |
|
217 | + * |
|
218 | + * @param bool $clear_queue Whether to initialize a new queue or keep the existing one. |
|
219 | + * |
|
220 | + * @return EE_Messages_Queue |
|
221 | + * @throws EE_Error |
|
222 | + * @throws ReflectionException |
|
223 | + */ |
|
224 | + public function batch_send_from_queue($messages = [], $clear_queue = false) |
|
225 | + { |
|
226 | + |
|
227 | + if ($messages && $this->_build_queue_for_sending($messages, $clear_queue)) { |
|
228 | + $this->_queue->execute(); |
|
229 | + $this->_queue->unlock_queue(EE_Messages_Queue::action_sending); |
|
230 | + } else { |
|
231 | + // get messages to send and execute. |
|
232 | + $this->_queue->get_to_send_batch_and_send(); |
|
233 | + } |
|
234 | + // note: callers can use the EE_Messages_Queue::count_STS_in_queue() method to find out if there were any failed |
|
235 | + // messages in the queue and decide how to handle at that point. |
|
236 | + return $this->_queue; |
|
237 | + } |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * This immediately generates messages using the given array of EE_Message_To_Generate objects and returns the |
|
242 | + * EE_Message_Queue with the generated messages for the caller to work with. Note, this does NOT save the generated |
|
243 | + * messages in the queue, leaving it up to the caller to do so. |
|
244 | + * |
|
245 | + * @param EE_Message_To_Generate[] $messages_to_generate |
|
246 | + * @return EE_Messages_Queue |
|
247 | + * @throws EE_Error |
|
248 | + * @throws ReflectionException |
|
249 | + */ |
|
250 | + public function generate_and_return($messages_to_generate) |
|
251 | + { |
|
252 | + $this->_init_queue_and_generator(); |
|
253 | + $this->_queue_for_generation_loop($messages_to_generate); |
|
254 | + return $this->_generator->generate(false); |
|
255 | + } |
|
256 | + |
|
257 | + |
|
258 | + /** |
|
259 | + * Executes the generator generate method on the current internal queue, and returns the generated queue. |
|
260 | + * |
|
261 | + * @param bool $persist Indicate whether to instruct the generator to persist the generated queue (true) or not |
|
262 | + * (false). |
|
263 | + * @return EE_Messages_Queue |
|
264 | + * @throws EE_Error |
|
265 | + * @throws ReflectionException |
|
266 | + */ |
|
267 | + public function generate_queue($persist = true) |
|
268 | + { |
|
269 | + return $this->_generator->generate($persist); |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + /** |
|
274 | + * Queue for generation. Note this does NOT persist to the db. Client code should call |
|
275 | + * get_message_repository()->save() if desire to persist. This method is provided to client code to decide what it |
|
276 | + * wants to do with queued messages for generation. |
|
277 | + * |
|
278 | + * @param EE_Message_To_Generate $message_to_generate |
|
279 | + * @param bool $test_send Whether this item is for a test send or not. |
|
280 | + * @return void |
|
281 | + */ |
|
282 | + public function queue_for_generation(EE_Message_To_Generate $message_to_generate, $test_send = false) |
|
283 | + { |
|
284 | + if ($message_to_generate->valid()) { |
|
285 | + if (! $this->_generator->create_and_add_message_to_queue($message_to_generate, $test_send)) { |
|
286 | + throw new RuntimeException( |
|
287 | + esc_html__('Message failed to generate', 'event_espresso') |
|
288 | + ); |
|
289 | + } |
|
290 | + } |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + /** |
|
295 | + * This receives an array of EE_Message_To_Generate objects, converts them to EE_Message adds them to the |
|
296 | + * generation queue and then persists to storage. |
|
297 | + * |
|
298 | + * @param EE_Message_To_Generate[] $messages_to_generate |
|
299 | + */ |
|
300 | + public function batch_queue_for_generation_and_persist($messages_to_generate) |
|
301 | + { |
|
302 | + $this->_init_queue_and_generator(); |
|
303 | + $this->_queue_for_generation_loop($messages_to_generate); |
|
304 | + $this->_queue->save(); |
|
305 | + } |
|
306 | + |
|
307 | + |
|
308 | + /** |
|
309 | + * This receives an array of EE_Message_To_Generate objects, converts them to EE_Message and adds them to the |
|
310 | + * generation queue. Does NOT persist to storage (unless there is an error. Client code can retrieve the generated |
|
311 | + * queue by calling EEM_Messages_Processor::get_queue() |
|
312 | + * |
|
313 | + * @param EE_Message_To_Generate[] $messages_to_generate |
|
314 | + */ |
|
315 | + public function batch_queue_for_generation_no_persist($messages_to_generate) |
|
316 | + { |
|
317 | + $this->_init_queue_and_generator(); |
|
318 | + $this->_queue_for_generation_loop($messages_to_generate); |
|
319 | + } |
|
320 | + |
|
321 | + |
|
322 | + /** |
|
323 | + * Simply loops through the given array of EE_Message_To_Generate objects and adds them to the _queue as EE_Message |
|
324 | + * objects. |
|
325 | + * |
|
326 | + * @param EE_Message_To_Generate[] $messages_to_generate |
|
327 | + */ |
|
328 | + protected function _queue_for_generation_loop($messages_to_generate) |
|
329 | + { |
|
330 | + // make sure is in an array. |
|
331 | + if (! is_array($messages_to_generate)) { |
|
332 | + $messages_to_generate = [$messages_to_generate]; |
|
333 | + } |
|
334 | + |
|
335 | + foreach ($messages_to_generate as $message_to_generate) { |
|
336 | + if ($message_to_generate instanceof EE_Message_To_Generate && $message_to_generate->valid()) { |
|
337 | + $this->queue_for_generation($message_to_generate); |
|
338 | + } |
|
339 | + } |
|
340 | + } |
|
341 | + |
|
342 | + |
|
343 | + /** |
|
344 | + * Receives an array of EE_Message_To_Generate objects and generates the EE_Message objects, then persists (so its |
|
345 | + * queued for sending). |
|
346 | + * |
|
347 | + * @param EE_Message_To_Generate[] |
|
348 | + * @return EE_Messages_Queue |
|
349 | + * @throws EE_Error |
|
350 | + * @throws ReflectionException |
|
351 | + */ |
|
352 | + public function generate_and_queue_for_sending($messages_to_generate) |
|
353 | + { |
|
354 | + $this->_init_queue_and_generator(); |
|
355 | + $this->_queue_for_generation_loop($messages_to_generate); |
|
356 | + return $this->_generator->generate(); |
|
357 | + } |
|
358 | + |
|
359 | + |
|
360 | + /** |
|
361 | + * Generate for preview and execute right away. |
|
362 | + * |
|
363 | + * @param EE_Message_To_Generate $message_to_generate |
|
364 | + * @param bool $test_send Whether this is a test send or not. |
|
365 | + * @return EE_Messages_Queue | bool false if unable to generate otherwise the generated queue. |
|
366 | + * @throws EE_Error |
|
367 | + * @throws ReflectionException |
|
368 | + */ |
|
369 | + public function generate_for_preview(EE_Message_To_Generate $message_to_generate, $test_send = false) |
|
370 | + { |
|
371 | + if (! $message_to_generate->valid()) { |
|
372 | + EE_Error::add_error( |
|
373 | + esc_html__('Unable to generate preview because of invalid data', 'event_espresso'), |
|
374 | + __FILE__, |
|
375 | + __FUNCTION__, |
|
376 | + __LINE__ |
|
377 | + ); |
|
378 | + return false; |
|
379 | + } |
|
380 | + // just make sure preview is set on the $message_to_generate (in case client forgot) |
|
381 | + $message_to_generate->set_preview(true); |
|
382 | + $this->_init_queue_and_generator(); |
|
383 | + $this->queue_for_generation($message_to_generate, $test_send); |
|
384 | + $generated_queue = $this->_generator->generate(false); |
|
385 | + if ($generated_queue->execute(false)) { |
|
386 | + // the first queue item should be the preview |
|
387 | + $generated_queue->get_message_repository()->rewind(); |
|
388 | + if ($generated_queue->get_message_repository()->valid()) { |
|
389 | + return $generated_queue; |
|
390 | + } |
|
391 | + } |
|
392 | + return false; |
|
393 | + } |
|
394 | + |
|
395 | + |
|
396 | + /** |
|
397 | + * This queues for sending. |
|
398 | + * The messenger send now method is also verified to see if sending immediately is requested. |
|
399 | + * otherwise its just saved to the queue. |
|
400 | + * |
|
401 | + * @param EE_Message_To_Generate $message_to_generate |
|
402 | + * @return bool true or false for success. |
|
403 | + * @throws EE_Error |
|
404 | + * @throws ReflectionException |
|
405 | + */ |
|
406 | + public function queue_for_sending(EE_Message_To_Generate $message_to_generate) |
|
407 | + { |
|
408 | + if (! $message_to_generate->valid()) { |
|
409 | + return false; |
|
410 | + } |
|
411 | + $this->_init_queue_and_generator(); |
|
412 | + $message = $message_to_generate->get_EE_Message(); |
|
413 | + $this->_queue->add($message); |
|
414 | + if ($message->send_now()) { |
|
415 | + $this->_queue->execute(false); |
|
416 | + } else { |
|
417 | + $this->_queue->save(); |
|
418 | + } |
|
419 | + return true; |
|
420 | + } |
|
421 | + |
|
422 | + |
|
423 | + /** |
|
424 | + * This generates and sends from the given EE_Message_To_Generate class immediately. |
|
425 | + * |
|
426 | + * @param EE_Message_To_Generate $message_to_generate |
|
427 | + * @return EE_Messages_Queue | null |
|
428 | + * @throws EE_Error |
|
429 | + * @throws ReflectionException |
|
430 | + */ |
|
431 | + public function generate_and_send_now(EE_Message_To_Generate $message_to_generate) |
|
432 | + { |
|
433 | + if (! $message_to_generate->valid()) { |
|
434 | + return null; |
|
435 | + } |
|
436 | + // is there supposed to be a sending messenger for this message? |
|
437 | + if ($message_to_generate instanceof EEI_Has_Sending_Messenger) { |
|
438 | + // make sure it's valid, but if it's not, |
|
439 | + // then set the value of $sending_messenger to an EE_Error object |
|
440 | + // so that downstream code can easily see that things went wrong. |
|
441 | + $sending_messenger = $message_to_generate->sending_messenger() instanceof EE_messenger |
|
442 | + ? $message_to_generate->sending_messenger() |
|
443 | + : new EE_Error( |
|
444 | + esc_html__( |
|
445 | + 'There was a specific sending messenger requested for the send action, but it was either invalid or not active at time of sending.', |
|
446 | + 'event_espresso' |
|
447 | + ) |
|
448 | + ); |
|
449 | + } else { |
|
450 | + $sending_messenger = null; |
|
451 | + } |
|
452 | + |
|
453 | + if ($message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_idle) { |
|
454 | + $this->_init_queue_and_generator(); |
|
455 | + $this->_queue->add($message_to_generate->get_EE_Message()); |
|
456 | + $this->_queue->execute(false, $sending_messenger); |
|
457 | + return $this->_queue; |
|
458 | + } elseif ($message_to_generate->get_EE_Message()->STS_ID() === EEM_Message::status_incomplete) { |
|
459 | + $generated_queue = $this->generate_and_return([$message_to_generate]); |
|
460 | + $generated_queue->execute(false, $sending_messenger); |
|
461 | + return $generated_queue; |
|
462 | + } |
|
463 | + return null; |
|
464 | + } |
|
465 | + |
|
466 | + |
|
467 | + /** |
|
468 | + * Creates mtg objects for all active messengers and queues for generation. |
|
469 | + * This method also calls the execute by priority method on the queue which will optionally kick off a new |
|
470 | + * non-blocking request to complete the action if the priority for the message requires immediate action. |
|
471 | + * |
|
472 | + * @param string $message_type |
|
473 | + * @param mixed $data The data being used for generation. |
|
474 | + * @param bool $persist Whether to persist the queued messages to the db or not. |
|
475 | + * @throws EE_Error |
|
476 | + * @throws ReflectionException |
|
477 | + */ |
|
478 | + public function generate_for_all_active_messengers($message_type, $data, $persist = true) |
|
479 | + { |
|
480 | + $messages_to_generate = $this->setup_mtgs_for_all_active_messengers($message_type, $data); |
|
481 | + if ($persist) { |
|
482 | + $this->batch_queue_for_generation_and_persist($messages_to_generate); |
|
483 | + $this->_queue->initiate_request_by_priority(); |
|
484 | + } else { |
|
485 | + $this->batch_queue_for_generation_no_persist($messages_to_generate); |
|
486 | + } |
|
487 | + } |
|
488 | + |
|
489 | + |
|
490 | + /** |
|
491 | + * This simply loops through all active messengers and takes care of setting up the |
|
492 | + * EE_Message_To_Generate objects. |
|
493 | + * |
|
494 | + * @param $message_type |
|
495 | + * @param $data |
|
496 | + * |
|
497 | + * @return EE_Message_To_Generate[] |
|
498 | + */ |
|
499 | + public function setup_mtgs_for_all_active_messengers($message_type, $data) |
|
500 | + { |
|
501 | + $messages_to_generate = []; |
|
502 | + foreach ($this->_message_resource_manager->active_messengers() as $messenger_slug => $messenger_object) { |
|
503 | + $message_to_generate = new EE_Message_To_Generate($messenger_slug, $message_type, $data); |
|
504 | + if ($message_to_generate->valid()) { |
|
505 | + $messages_to_generate[] = $message_to_generate; |
|
506 | + } |
|
507 | + } |
|
508 | + return $messages_to_generate; |
|
509 | + } |
|
510 | + |
|
511 | + |
|
512 | + /** |
|
513 | + * This accepts an array of EE_Message::MSG_ID values |
|
514 | + * and will use that to retrieve the objects from the database and send. |
|
515 | + * |
|
516 | + * @param array $message_ids |
|
517 | + * @throws EE_Error |
|
518 | + * @throws ReflectionException |
|
519 | + */ |
|
520 | + public function setup_messages_from_ids_and_send($message_ids) |
|
521 | + { |
|
522 | + $this->_init_queue_and_generator(); |
|
523 | + $messages = EEM_Message::instance()->get_all( |
|
524 | + [ |
|
525 | + [ |
|
526 | + 'MSG_ID' => ['IN', $message_ids], |
|
527 | + 'STS_ID' => [ |
|
528 | + 'IN', |
|
529 | + array_merge( |
|
530 | + EEM_Message::instance()->stati_indicating_sent(), |
|
531 | + [EEM_Message::status_retry] |
|
532 | + ), |
|
533 | + ], |
|
534 | + ], |
|
535 | + ] |
|
536 | + ); |
|
537 | + // set the Messages to resend. |
|
538 | + foreach ($messages as $message) { |
|
539 | + if ($message instanceof EE_Message) { |
|
540 | + $message->set_STS_ID(EEM_Message::status_resend); |
|
541 | + $this->_queue->add($message); |
|
542 | + } |
|
543 | + } |
|
544 | + |
|
545 | + $this->_queue->initiate_request_by_priority('send'); |
|
546 | + } |
|
547 | + |
|
548 | + |
|
549 | + /** |
|
550 | + * This method checks for registration IDs in the request via the given key and creates the messages to generate |
|
551 | + * objects from them, then returns the array of messages to generate objects. |
|
552 | + * Note, this sets up registrations for the registration family of message types. |
|
553 | + * |
|
554 | + * @param string $registration_ids_key This is used to indicate what represents the registration ids in the request. |
|
555 | + * |
|
556 | + * @return EE_Message_To_Generate[]|bool |
|
557 | + * @throws EE_Error |
|
558 | + */ |
|
559 | + public function setup_messages_to_generate_from_registration_ids_in_request($registration_ids_key = '_REG_ID') |
|
560 | + { |
|
561 | + /** @var RequestInterface $request */ |
|
562 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
563 | + $regs_to_send = []; |
|
564 | + $regIDs = $request->getRequestParam($registration_ids_key, [], 'int', true); |
|
565 | + if (empty($regIDs)) { |
|
566 | + EE_Error::add_error( |
|
567 | + esc_html__('Something went wrong because we\'re missing the registration ID', 'event_espresso'), |
|
568 | + __FILE__, |
|
569 | + __FUNCTION__, |
|
570 | + __LINE__ |
|
571 | + ); |
|
572 | + return false; |
|
573 | + } |
|
574 | + |
|
575 | + // make sure is an array |
|
576 | + $regIDs = is_array($regIDs) ? $regIDs : [$regIDs]; |
|
577 | + |
|
578 | + foreach ($regIDs as $regID) { |
|
579 | + $reg = EEM_Registration::instance()->get_one_by_ID($regID); |
|
580 | + if (! $reg instanceof EE_Registration) { |
|
581 | + EE_Error::add_error( |
|
582 | + sprintf( |
|
583 | + esc_html__( |
|
584 | + 'Unable to retrieve a registration object for the given reg id (%s)', |
|
585 | + 'event_espresso' |
|
586 | + ), |
|
587 | + $regID |
|
588 | + ) |
|
589 | + ); |
|
590 | + return false; |
|
591 | + } |
|
592 | + $regs_to_send[ $reg->transaction_ID() ][ $reg->status_ID() ][] = $reg; |
|
593 | + } |
|
594 | + |
|
595 | + $messages_to_generate = []; |
|
596 | + |
|
597 | + foreach ($regs_to_send as $status_group) { |
|
598 | + foreach ($status_group as $status_id => $registrations) { |
|
599 | + $message_type = EEH_MSG_Template::convert_reg_status_to_message_type($status_id); |
|
600 | + if (! $message_type) { |
|
601 | + continue; |
|
602 | + } |
|
603 | + $messages_to_generate = array_merge( |
|
604 | + $messages_to_generate, |
|
605 | + $this->setup_mtgs_for_all_active_messengers( |
|
606 | + $message_type, |
|
607 | + [$registrations, $status_id] |
|
608 | + ) |
|
609 | + ); |
|
610 | + } |
|
611 | + } |
|
612 | + |
|
613 | + return $messages_to_generate; |
|
614 | + } |
|
615 | 615 | } |
@@ -297,8 +297,8 @@ |
||
297 | 297 | */ |
298 | 298 | public static function verify_and_retrieve_class_name_for_data_handler_reference($data_handler_reference) |
299 | 299 | { |
300 | - $class_name = 'EE_Messages_' . $data_handler_reference . '_incoming_data'; |
|
301 | - if (! class_exists($class_name)) { |
|
300 | + $class_name = 'EE_Messages_'.$data_handler_reference.'_incoming_data'; |
|
301 | + if ( ! class_exists($class_name)) { |
|
302 | 302 | EE_Error::add_error( |
303 | 303 | sprintf( |
304 | 304 | esc_html__( |
@@ -11,308 +11,308 @@ |
||
11 | 11 | */ |
12 | 12 | class EE_Message_To_Generate |
13 | 13 | { |
14 | - /** |
|
15 | - * @var string |
|
16 | - */ |
|
17 | - protected $_messenger_name; |
|
18 | - |
|
19 | - /** |
|
20 | - * @var string |
|
21 | - */ |
|
22 | - protected $_message_type_name; |
|
23 | - |
|
24 | - /** |
|
25 | - * @var EE_messenger |
|
26 | - */ |
|
27 | - protected $_messenger; |
|
28 | - |
|
29 | - /** |
|
30 | - * @var EE_message_type |
|
31 | - */ |
|
32 | - protected $_message_type; |
|
33 | - |
|
34 | - /** |
|
35 | - * Identifier for the context the message is to be generated for. |
|
36 | - * |
|
37 | - * @var string |
|
38 | - */ |
|
39 | - protected $_context = ''; |
|
40 | - |
|
41 | - /** |
|
42 | - * Data that will be used to generate message. |
|
43 | - * |
|
44 | - * @var array |
|
45 | - */ |
|
46 | - protected $_data = []; |
|
47 | - |
|
48 | - /** |
|
49 | - * Whether this message is for a preview or not. |
|
50 | - * |
|
51 | - * @var bool |
|
52 | - */ |
|
53 | - protected $_preview = false; |
|
54 | - |
|
55 | - /** |
|
56 | - * @var EE_Message |
|
57 | - */ |
|
58 | - protected $_message; |
|
59 | - |
|
60 | - /** |
|
61 | - * This is set by the constructor to indicate whether the incoming messenger |
|
62 | - * and message type are valid. This can then be checked by callers to determine whether |
|
63 | - * to generate this message or not. |
|
64 | - * |
|
65 | - * @var bool |
|
66 | - */ |
|
67 | - protected $_valid = false; |
|
68 | - |
|
69 | - /** |
|
70 | - * If there are any errors (non exception errors) they get added to this array for callers to decide |
|
71 | - * how to handle. |
|
72 | - * |
|
73 | - * @var array |
|
74 | - */ |
|
75 | - protected $_error_msg = []; |
|
76 | - |
|
77 | - /** |
|
78 | - * Can be accessed via the send_now() method, this is set in the validation |
|
79 | - * routine via the EE_messenger::send_now() method. |
|
80 | - * |
|
81 | - * @var bool |
|
82 | - */ |
|
83 | - protected $_send_now = false; |
|
84 | - |
|
85 | - /** |
|
86 | - * Holds the classname for the data handler used by the current message type. |
|
87 | - * This is set on the first call to the public `get_data_handler_class_name()` method. |
|
88 | - * |
|
89 | - * @var string |
|
90 | - */ |
|
91 | - protected $_data_handler_class_name = ''; |
|
92 | - |
|
93 | - /** |
|
94 | - * one of the message status constants on EEM_Message |
|
95 | - * |
|
96 | - * @var string |
|
97 | - * @since 4.10.29.p |
|
98 | - */ |
|
99 | - protected $_status = ''; |
|
100 | - |
|
101 | - /** |
|
102 | - * use $_status var above |
|
103 | - * |
|
104 | - * @var string |
|
105 | - * @deprecated 4.10.29.p |
|
106 | - */ |
|
107 | - protected $_message_status = ''; |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * Constructor |
|
112 | - * |
|
113 | - * @param string $messenger_name Slug representing messenger |
|
114 | - * @param string $message_type_name Slug representing message type. |
|
115 | - * @param mixed $data Data used for generating message. |
|
116 | - * @param string $context Optional context to restrict message generated for. |
|
117 | - * @param bool $preview Whether this is being used to generate a preview or not. |
|
118 | - * @param string $status |
|
119 | - */ |
|
120 | - public function __construct( |
|
121 | - $messenger_name, |
|
122 | - $message_type_name, |
|
123 | - $data = [], |
|
124 | - $context = '', |
|
125 | - $preview = false, |
|
126 | - $status = EEM_Message::status_incomplete |
|
127 | - ) { |
|
128 | - $this->_messenger_name = $messenger_name; |
|
129 | - $this->_message_type_name = $message_type_name; |
|
130 | - $this->_data = is_array($data) ? $data : [$data]; |
|
131 | - $this->_context = $context; |
|
132 | - $this->_preview = $preview; |
|
133 | - $this->_status = $status; |
|
134 | - // attempt to generate message immediately |
|
135 | - $this->_message = $this->_generate_message(); |
|
136 | - } |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * @return string |
|
141 | - */ |
|
142 | - public function context() |
|
143 | - { |
|
144 | - return $this->_context; |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * @return array |
|
150 | - */ |
|
151 | - public function data() |
|
152 | - { |
|
153 | - return $this->_data; |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * @return EE_messenger |
|
159 | - */ |
|
160 | - public function messenger() |
|
161 | - { |
|
162 | - return $this->_messenger; |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * @return EE_message_type |
|
168 | - */ |
|
169 | - public function message_type() |
|
170 | - { |
|
171 | - return $this->_message_type; |
|
172 | - } |
|
173 | - |
|
174 | - |
|
175 | - /** |
|
176 | - * @return boolean |
|
177 | - */ |
|
178 | - public function preview() |
|
179 | - { |
|
180 | - return $this->_preview; |
|
181 | - } |
|
182 | - |
|
183 | - |
|
184 | - /** |
|
185 | - * @param boolean $preview |
|
186 | - */ |
|
187 | - public function set_preview($preview) |
|
188 | - { |
|
189 | - $this->_preview = filter_var($preview, FILTER_VALIDATE_BOOLEAN); |
|
190 | - } |
|
191 | - |
|
192 | - |
|
193 | - /** |
|
194 | - * @return bool |
|
195 | - */ |
|
196 | - public function send_now() |
|
197 | - { |
|
198 | - return $this->_send_now; |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * Simply returns the state of the $_valid property. |
|
204 | - * |
|
205 | - * @return bool |
|
206 | - */ |
|
207 | - public function valid() |
|
208 | - { |
|
209 | - return $this->_valid; |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * generates an EE_Message using the supplied arguments and some defaults |
|
215 | - * |
|
216 | - * @param array $properties |
|
217 | - * @return EE_Message |
|
218 | - */ |
|
219 | - protected function _generate_message($properties = []) |
|
220 | - { |
|
221 | - $message = EE_Message_Factory::create( |
|
222 | - array_merge( |
|
223 | - [ |
|
224 | - 'MSG_messenger' => $this->_messenger_name, |
|
225 | - 'MSG_message_type' => $this->_message_type_name, |
|
226 | - 'MSG_context' => $this->_context, |
|
227 | - 'STS_ID' => $this->_status, |
|
228 | - ], |
|
229 | - $properties |
|
230 | - ) |
|
231 | - ); |
|
232 | - // validate the message, and if it's good, set some properties |
|
233 | - try { |
|
234 | - $message->is_valid_for_sending_or_generation(true); |
|
235 | - $this->_valid = true; |
|
236 | - $this->_messenger = $message->messenger_object(); |
|
237 | - $this->_message_type = $message->message_type_object(); |
|
238 | - $this->_send_now = $message->send_now(); |
|
239 | - } catch (Exception $e) { |
|
240 | - $this->_valid = false; |
|
241 | - $this->_error_msg[] = $e->getMessage(); |
|
242 | - } |
|
243 | - return $message; |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * Returns an instantiated EE_Message object from the internal data. |
|
249 | - * |
|
250 | - * @return EE_Message |
|
251 | - */ |
|
252 | - public function get_EE_Message() |
|
253 | - { |
|
254 | - // already set ? |
|
255 | - if ($this->_message instanceof EE_Message) { |
|
256 | - return $this->_message; |
|
257 | - } |
|
258 | - // no? then let's create one |
|
259 | - $this->_message = $this->_generate_message(); |
|
260 | - return $this->_message; |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - /** |
|
265 | - * This returns the data_handler class name for the internal message type set. |
|
266 | - * Note: this also verifies that the data handler class exists. If it doesn't then $_valid is set to false |
|
267 | - * and the data_handler_class name is set to an empty string. |
|
268 | - * |
|
269 | - * @param bool $preview Used to indicate that the preview data handler is to be returned. |
|
270 | - * @return string |
|
271 | - */ |
|
272 | - public function get_data_handler_class_name($preview = false) |
|
273 | - { |
|
274 | - if ($this->_data_handler_class_name === '' && $this->valid()) { |
|
275 | - $ref = $preview ? 'Preview' : $this->_message_type->get_data_handler($this->_data); |
|
276 | - // make sure internal data is updated. |
|
277 | - $this->_data = $this->_message_type->get_data(); |
|
278 | - |
|
279 | - // verify |
|
280 | - $this->_data_handler_class_name = |
|
281 | - EE_Message_To_Generate::verify_and_retrieve_class_name_for_data_handler_reference($ref); |
|
282 | - if ($this->_data_handler_class_name === '') { |
|
283 | - $this->_valid = false; |
|
284 | - } |
|
285 | - } |
|
286 | - return $this->_data_handler_class_name; |
|
287 | - } |
|
288 | - |
|
289 | - |
|
290 | - /** |
|
291 | - * Validates the given string as a reference for an existing, accessible data handler and returns the class name |
|
292 | - * For the handler the reference matches. |
|
293 | - * |
|
294 | - * @param string $data_handler_reference |
|
295 | - * @return string |
|
296 | - */ |
|
297 | - public static function verify_and_retrieve_class_name_for_data_handler_reference($data_handler_reference) |
|
298 | - { |
|
299 | - $class_name = 'EE_Messages_' . $data_handler_reference . '_incoming_data'; |
|
300 | - if (! class_exists($class_name)) { |
|
301 | - EE_Error::add_error( |
|
302 | - sprintf( |
|
303 | - esc_html__( |
|
304 | - 'The included data handler reference (%s) does not match any valid, accessible, "EE_Messages_incoming_data" classes. Looking for %s.', |
|
305 | - 'event_espresso' |
|
306 | - ), |
|
307 | - $data_handler_reference, |
|
308 | - $class_name |
|
309 | - ), |
|
310 | - __FILE__, |
|
311 | - __FUNCTION__, |
|
312 | - __LINE__ |
|
313 | - ); |
|
314 | - $class_name = ''; // clear out class_name so caller knows this isn't valid. |
|
315 | - } |
|
316 | - return $class_name; |
|
317 | - } |
|
14 | + /** |
|
15 | + * @var string |
|
16 | + */ |
|
17 | + protected $_messenger_name; |
|
18 | + |
|
19 | + /** |
|
20 | + * @var string |
|
21 | + */ |
|
22 | + protected $_message_type_name; |
|
23 | + |
|
24 | + /** |
|
25 | + * @var EE_messenger |
|
26 | + */ |
|
27 | + protected $_messenger; |
|
28 | + |
|
29 | + /** |
|
30 | + * @var EE_message_type |
|
31 | + */ |
|
32 | + protected $_message_type; |
|
33 | + |
|
34 | + /** |
|
35 | + * Identifier for the context the message is to be generated for. |
|
36 | + * |
|
37 | + * @var string |
|
38 | + */ |
|
39 | + protected $_context = ''; |
|
40 | + |
|
41 | + /** |
|
42 | + * Data that will be used to generate message. |
|
43 | + * |
|
44 | + * @var array |
|
45 | + */ |
|
46 | + protected $_data = []; |
|
47 | + |
|
48 | + /** |
|
49 | + * Whether this message is for a preview or not. |
|
50 | + * |
|
51 | + * @var bool |
|
52 | + */ |
|
53 | + protected $_preview = false; |
|
54 | + |
|
55 | + /** |
|
56 | + * @var EE_Message |
|
57 | + */ |
|
58 | + protected $_message; |
|
59 | + |
|
60 | + /** |
|
61 | + * This is set by the constructor to indicate whether the incoming messenger |
|
62 | + * and message type are valid. This can then be checked by callers to determine whether |
|
63 | + * to generate this message or not. |
|
64 | + * |
|
65 | + * @var bool |
|
66 | + */ |
|
67 | + protected $_valid = false; |
|
68 | + |
|
69 | + /** |
|
70 | + * If there are any errors (non exception errors) they get added to this array for callers to decide |
|
71 | + * how to handle. |
|
72 | + * |
|
73 | + * @var array |
|
74 | + */ |
|
75 | + protected $_error_msg = []; |
|
76 | + |
|
77 | + /** |
|
78 | + * Can be accessed via the send_now() method, this is set in the validation |
|
79 | + * routine via the EE_messenger::send_now() method. |
|
80 | + * |
|
81 | + * @var bool |
|
82 | + */ |
|
83 | + protected $_send_now = false; |
|
84 | + |
|
85 | + /** |
|
86 | + * Holds the classname for the data handler used by the current message type. |
|
87 | + * This is set on the first call to the public `get_data_handler_class_name()` method. |
|
88 | + * |
|
89 | + * @var string |
|
90 | + */ |
|
91 | + protected $_data_handler_class_name = ''; |
|
92 | + |
|
93 | + /** |
|
94 | + * one of the message status constants on EEM_Message |
|
95 | + * |
|
96 | + * @var string |
|
97 | + * @since 4.10.29.p |
|
98 | + */ |
|
99 | + protected $_status = ''; |
|
100 | + |
|
101 | + /** |
|
102 | + * use $_status var above |
|
103 | + * |
|
104 | + * @var string |
|
105 | + * @deprecated 4.10.29.p |
|
106 | + */ |
|
107 | + protected $_message_status = ''; |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * Constructor |
|
112 | + * |
|
113 | + * @param string $messenger_name Slug representing messenger |
|
114 | + * @param string $message_type_name Slug representing message type. |
|
115 | + * @param mixed $data Data used for generating message. |
|
116 | + * @param string $context Optional context to restrict message generated for. |
|
117 | + * @param bool $preview Whether this is being used to generate a preview or not. |
|
118 | + * @param string $status |
|
119 | + */ |
|
120 | + public function __construct( |
|
121 | + $messenger_name, |
|
122 | + $message_type_name, |
|
123 | + $data = [], |
|
124 | + $context = '', |
|
125 | + $preview = false, |
|
126 | + $status = EEM_Message::status_incomplete |
|
127 | + ) { |
|
128 | + $this->_messenger_name = $messenger_name; |
|
129 | + $this->_message_type_name = $message_type_name; |
|
130 | + $this->_data = is_array($data) ? $data : [$data]; |
|
131 | + $this->_context = $context; |
|
132 | + $this->_preview = $preview; |
|
133 | + $this->_status = $status; |
|
134 | + // attempt to generate message immediately |
|
135 | + $this->_message = $this->_generate_message(); |
|
136 | + } |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * @return string |
|
141 | + */ |
|
142 | + public function context() |
|
143 | + { |
|
144 | + return $this->_context; |
|
145 | + } |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * @return array |
|
150 | + */ |
|
151 | + public function data() |
|
152 | + { |
|
153 | + return $this->_data; |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * @return EE_messenger |
|
159 | + */ |
|
160 | + public function messenger() |
|
161 | + { |
|
162 | + return $this->_messenger; |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * @return EE_message_type |
|
168 | + */ |
|
169 | + public function message_type() |
|
170 | + { |
|
171 | + return $this->_message_type; |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + /** |
|
176 | + * @return boolean |
|
177 | + */ |
|
178 | + public function preview() |
|
179 | + { |
|
180 | + return $this->_preview; |
|
181 | + } |
|
182 | + |
|
183 | + |
|
184 | + /** |
|
185 | + * @param boolean $preview |
|
186 | + */ |
|
187 | + public function set_preview($preview) |
|
188 | + { |
|
189 | + $this->_preview = filter_var($preview, FILTER_VALIDATE_BOOLEAN); |
|
190 | + } |
|
191 | + |
|
192 | + |
|
193 | + /** |
|
194 | + * @return bool |
|
195 | + */ |
|
196 | + public function send_now() |
|
197 | + { |
|
198 | + return $this->_send_now; |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * Simply returns the state of the $_valid property. |
|
204 | + * |
|
205 | + * @return bool |
|
206 | + */ |
|
207 | + public function valid() |
|
208 | + { |
|
209 | + return $this->_valid; |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * generates an EE_Message using the supplied arguments and some defaults |
|
215 | + * |
|
216 | + * @param array $properties |
|
217 | + * @return EE_Message |
|
218 | + */ |
|
219 | + protected function _generate_message($properties = []) |
|
220 | + { |
|
221 | + $message = EE_Message_Factory::create( |
|
222 | + array_merge( |
|
223 | + [ |
|
224 | + 'MSG_messenger' => $this->_messenger_name, |
|
225 | + 'MSG_message_type' => $this->_message_type_name, |
|
226 | + 'MSG_context' => $this->_context, |
|
227 | + 'STS_ID' => $this->_status, |
|
228 | + ], |
|
229 | + $properties |
|
230 | + ) |
|
231 | + ); |
|
232 | + // validate the message, and if it's good, set some properties |
|
233 | + try { |
|
234 | + $message->is_valid_for_sending_or_generation(true); |
|
235 | + $this->_valid = true; |
|
236 | + $this->_messenger = $message->messenger_object(); |
|
237 | + $this->_message_type = $message->message_type_object(); |
|
238 | + $this->_send_now = $message->send_now(); |
|
239 | + } catch (Exception $e) { |
|
240 | + $this->_valid = false; |
|
241 | + $this->_error_msg[] = $e->getMessage(); |
|
242 | + } |
|
243 | + return $message; |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * Returns an instantiated EE_Message object from the internal data. |
|
249 | + * |
|
250 | + * @return EE_Message |
|
251 | + */ |
|
252 | + public function get_EE_Message() |
|
253 | + { |
|
254 | + // already set ? |
|
255 | + if ($this->_message instanceof EE_Message) { |
|
256 | + return $this->_message; |
|
257 | + } |
|
258 | + // no? then let's create one |
|
259 | + $this->_message = $this->_generate_message(); |
|
260 | + return $this->_message; |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + /** |
|
265 | + * This returns the data_handler class name for the internal message type set. |
|
266 | + * Note: this also verifies that the data handler class exists. If it doesn't then $_valid is set to false |
|
267 | + * and the data_handler_class name is set to an empty string. |
|
268 | + * |
|
269 | + * @param bool $preview Used to indicate that the preview data handler is to be returned. |
|
270 | + * @return string |
|
271 | + */ |
|
272 | + public function get_data_handler_class_name($preview = false) |
|
273 | + { |
|
274 | + if ($this->_data_handler_class_name === '' && $this->valid()) { |
|
275 | + $ref = $preview ? 'Preview' : $this->_message_type->get_data_handler($this->_data); |
|
276 | + // make sure internal data is updated. |
|
277 | + $this->_data = $this->_message_type->get_data(); |
|
278 | + |
|
279 | + // verify |
|
280 | + $this->_data_handler_class_name = |
|
281 | + EE_Message_To_Generate::verify_and_retrieve_class_name_for_data_handler_reference($ref); |
|
282 | + if ($this->_data_handler_class_name === '') { |
|
283 | + $this->_valid = false; |
|
284 | + } |
|
285 | + } |
|
286 | + return $this->_data_handler_class_name; |
|
287 | + } |
|
288 | + |
|
289 | + |
|
290 | + /** |
|
291 | + * Validates the given string as a reference for an existing, accessible data handler and returns the class name |
|
292 | + * For the handler the reference matches. |
|
293 | + * |
|
294 | + * @param string $data_handler_reference |
|
295 | + * @return string |
|
296 | + */ |
|
297 | + public static function verify_and_retrieve_class_name_for_data_handler_reference($data_handler_reference) |
|
298 | + { |
|
299 | + $class_name = 'EE_Messages_' . $data_handler_reference . '_incoming_data'; |
|
300 | + if (! class_exists($class_name)) { |
|
301 | + EE_Error::add_error( |
|
302 | + sprintf( |
|
303 | + esc_html__( |
|
304 | + 'The included data handler reference (%s) does not match any valid, accessible, "EE_Messages_incoming_data" classes. Looking for %s.', |
|
305 | + 'event_espresso' |
|
306 | + ), |
|
307 | + $data_handler_reference, |
|
308 | + $class_name |
|
309 | + ), |
|
310 | + __FILE__, |
|
311 | + __FUNCTION__, |
|
312 | + __LINE__ |
|
313 | + ); |
|
314 | + $class_name = ''; // clear out class_name so caller knows this isn't valid. |
|
315 | + } |
|
316 | + return $class_name; |
|
317 | + } |
|
318 | 318 | } |
@@ -6,15 +6,15 @@ discard block |
||
6 | 6 | </p> |
7 | 7 | <p> |
8 | 8 | <?php |
9 | - printf( |
|
10 | - esc_html__( |
|
11 | - 'See %1$shere%2$s for list of currencies supported by Authorize.net AIM.', |
|
12 | - 'event_espresso' |
|
13 | - ), |
|
14 | - "<a href='https://support.authorize.net/s/article/Which-Currencies-Does-Authorize-Net-Support/' target='_blank' rel='noopener noreferrer'>", |
|
15 | - "</a>" |
|
16 | - ); |
|
17 | - ?> |
|
9 | + printf( |
|
10 | + esc_html__( |
|
11 | + 'See %1$shere%2$s for list of currencies supported by Authorize.net AIM.', |
|
12 | + 'event_espresso' |
|
13 | + ), |
|
14 | + "<a href='https://support.authorize.net/s/article/Which-Currencies-Does-Authorize-Net-Support/' target='_blank' rel='noopener noreferrer'>", |
|
15 | + "</a>" |
|
16 | + ); |
|
17 | + ?> |
|
18 | 18 | </p> |
19 | 19 | <p> |
20 | 20 | <strong><?php esc_html_e('Authorize.net AIM Settings', 'event_espresso'); ?></strong> |
@@ -24,70 +24,70 @@ discard block |
||
24 | 24 | <strong><?php esc_html_e('Authorize.net API Login ID', 'event_espresso'); ?></strong> |
25 | 25 | <br/> |
26 | 26 | <?php |
27 | - printf( |
|
28 | - esc_html__( |
|
29 | - 'Enter your API Login ID for Authorize.net. Learn how to find your %1$sAPI Login%2$s ID.', |
|
30 | - 'event_espresso' |
|
31 | - ), |
|
32 | - '<a href="https://support.authorize.net/authkb/index?page=content&id=A405" target="_blank" rel="noopener noreferrer">', |
|
33 | - '</a>' |
|
34 | - ); |
|
35 | - ?> |
|
27 | + printf( |
|
28 | + esc_html__( |
|
29 | + 'Enter your API Login ID for Authorize.net. Learn how to find your %1$sAPI Login%2$s ID.', |
|
30 | + 'event_espresso' |
|
31 | + ), |
|
32 | + '<a href="https://support.authorize.net/authkb/index?page=content&id=A405" target="_blank" rel="noopener noreferrer">', |
|
33 | + '</a>' |
|
34 | + ); |
|
35 | + ?> |
|
36 | 36 | </li> |
37 | 37 | <li> |
38 | 38 | <strong><?php esc_html_e('Authorize.net Transaction Key', 'event_espresso'); ?></strong> |
39 | 39 | <br/> |
40 | 40 | <?php |
41 | - printf( |
|
42 | - esc_html__( |
|
43 | - 'Enter your Transaction Key for Authorize.net. Learn how to find your %1$sTransaction Key%2$s.', |
|
44 | - 'event_espresso' |
|
45 | - ), |
|
46 | - '<a href="https://support.authorize.net/authkb/index?page=content&id=A405" target="_blank" rel="noopener noreferrer">', |
|
47 | - '</a>' |
|
48 | - ); |
|
49 | - ?> |
|
41 | + printf( |
|
42 | + esc_html__( |
|
43 | + 'Enter your Transaction Key for Authorize.net. Learn how to find your %1$sTransaction Key%2$s.', |
|
44 | + 'event_espresso' |
|
45 | + ), |
|
46 | + '<a href="https://support.authorize.net/authkb/index?page=content&id=A405" target="_blank" rel="noopener noreferrer">', |
|
47 | + '</a>' |
|
48 | + ); |
|
49 | + ?> |
|
50 | 50 | </li> |
51 | 51 | <li> |
52 | 52 | <strong> |
53 | 53 | <?php esc_html_e( |
54 | - 'Is this an account on the Authorize.net development server?', |
|
55 | - 'event_espresso' |
|
56 | - ); ?> |
|
54 | + 'Is this an account on the Authorize.net development server?', |
|
55 | + 'event_espresso' |
|
56 | + ); ?> |
|
57 | 57 | </strong> |
58 | 58 | <br/> |
59 | 59 | <?php esc_html_e( |
60 | - 'Specify whether this is a live/production account or a test account on the Authorize.net development server.', |
|
61 | - 'event_espresso' |
|
62 | - ); ?> |
|
60 | + 'Specify whether this is a live/production account or a test account on the Authorize.net development server.', |
|
61 | + 'event_espresso' |
|
62 | + ); ?> |
|
63 | 63 | </li> |
64 | 64 | <li> |
65 | 65 | <strong><?php esc_html_e('Do you want to submit a test transaction?', 'event_espresso'); ?></strong> |
66 | 66 | <br/> |
67 | 67 | <?php esc_html_e( |
68 | - 'Specify if you want to test the Authorize.net AIM payment gateway by submitting a test transaction. Be sure to turn this setting off when you are done testing.', |
|
69 | - 'event_espresso' |
|
70 | - ); ?> |
|
68 | + 'Specify if you want to test the Authorize.net AIM payment gateway by submitting a test transaction. Be sure to turn this setting off when you are done testing.', |
|
69 | + 'event_espresso' |
|
70 | + ); ?> |
|
71 | 71 | </li> |
72 | 72 | <li> |
73 | 73 | <strong><?php esc_html_e('Excluded and Required Payment Form Fields', 'event_espresso'); ?></strong> |
74 | 74 | <br/> |
75 | 75 | <?php esc_html_e( |
76 | - 'By logging into Authorize.net, you can change which payment fields are required by Authorize.net when processing payments. These settings affect both the Advanced Integration Method (AIM, this) and the Simple Integration Method (SIM, different). The payment method settings "Excluded Payment Form Fields" and "Required Payment Form Fields" allow you to change the billing form in Event Espresso to reflect your payment form settings in Authorize.net.', |
|
77 | - 'event_espresso' |
|
78 | - ); ?> |
|
76 | + 'By logging into Authorize.net, you can change which payment fields are required by Authorize.net when processing payments. These settings affect both the Advanced Integration Method (AIM, this) and the Simple Integration Method (SIM, different). The payment method settings "Excluded Payment Form Fields" and "Required Payment Form Fields" allow you to change the billing form in Event Espresso to reflect your payment form settings in Authorize.net.', |
|
77 | + 'event_espresso' |
|
78 | + ); ?> |
|
79 | 79 | <br> |
80 | 80 | <?php printf( |
81 | - esc_html__( |
|
82 | - 'To change your payment form settings in Authorize.net, %1$slog in to authorize.net%2$s, go to %3$sAccount then Payment Form%2$s, then %4$sForm Fields%2$s. It will look similar to %5$sthis%2$s. If you make a field required in Authorize.net, you should also make it required in Event Espresso. If it isn\'t required in Authorize.net, and you want to simplify the billing form in Event Espresso, you can exclude it from the Event Espresso Form too.', |
|
83 | - 'event_espresso' |
|
84 | - ), |
|
85 | - '<a href="http://authorize.net" target="_blank" rel="noopener noreferrer">', |
|
86 | - '</a>', |
|
87 | - '<a href="https://monosnap.com/file/nebVteOkEXcdDIos88SojStWOifP23" target="_blank" rel="noopener noreferrer">', |
|
88 | - '<a href="https://monosnap.com/file/WyxGJtev87TcDmdGBEZ2oi1xaBIQAm" target="_blank" rel="noopener noreferrer">', |
|
89 | - '<a href="https://monosnap.com/image/DbCJNfEesWXeSNUs1wLIpGYODFw52m" target="_blank" rel="noopener noreferrer">' |
|
90 | - ); ?> |
|
81 | + esc_html__( |
|
82 | + 'To change your payment form settings in Authorize.net, %1$slog in to authorize.net%2$s, go to %3$sAccount then Payment Form%2$s, then %4$sForm Fields%2$s. It will look similar to %5$sthis%2$s. If you make a field required in Authorize.net, you should also make it required in Event Espresso. If it isn\'t required in Authorize.net, and you want to simplify the billing form in Event Espresso, you can exclude it from the Event Espresso Form too.', |
|
83 | + 'event_espresso' |
|
84 | + ), |
|
85 | + '<a href="http://authorize.net" target="_blank" rel="noopener noreferrer">', |
|
86 | + '</a>', |
|
87 | + '<a href="https://monosnap.com/file/nebVteOkEXcdDIos88SojStWOifP23" target="_blank" rel="noopener noreferrer">', |
|
88 | + '<a href="https://monosnap.com/file/WyxGJtev87TcDmdGBEZ2oi1xaBIQAm" target="_blank" rel="noopener noreferrer">', |
|
89 | + '<a href="https://monosnap.com/image/DbCJNfEesWXeSNUs1wLIpGYODFw52m" target="_blank" rel="noopener noreferrer">' |
|
90 | + ); ?> |
|
91 | 91 | </li> |
92 | 92 | <li> |
93 | 93 | <strong><?php esc_html_e('Button Image URL', 'event_espresso'); ?></strong> |
@@ -97,8 +97,8 @@ discard block |
||
97 | 97 | <li> |
98 | 98 | <strong><?php esc_html_e('Note About Special Characters', 'event_espresso'); ?></strong> |
99 | 99 | <?php esc_html_e( |
100 | - 'If your event name, ticket name or ticket description contain special characters (eg emojis, foreign language characters, or curly quotes) they will be removed when sent to Authorize.net. This is because Authorize.net doesn\'t support them.', |
|
101 | - 'event_espresso' |
|
102 | - ); ?> |
|
100 | + 'If your event name, ticket name or ticket description contain special characters (eg emojis, foreign language characters, or curly quotes) they will be removed when sent to Authorize.net. This is because Authorize.net doesn\'t support them.', |
|
101 | + 'event_espresso' |
|
102 | + ); ?> |
|
103 | 103 | </li> |
104 | 104 | </ul> |
@@ -175,7 +175,7 @@ discard block |
||
175 | 175 | '', |
176 | 176 | 'tckt-slctr-tbl-td-qty cntr', |
177 | 177 | '', |
178 | - 'headers="quantity-' . $this->EVT_ID . '"' |
|
178 | + 'headers="quantity-'.$this->EVT_ID.'"' |
|
179 | 179 | ); |
180 | 180 | $this->setTicketStatusDisplay($remaining); |
181 | 181 | if (empty($this->ticket_status_display)) { |
@@ -242,7 +242,7 @@ discard block |
||
242 | 242 | '', |
243 | 243 | 'tckt-slctr-tbl-td-name', |
244 | 244 | '', |
245 | - 'headers="details-' . $this->EVT_ID . '"' |
|
245 | + 'headers="details-'.$this->EVT_ID.'"' |
|
246 | 246 | ); |
247 | 247 | $html .= EEH_HTML::strong($this->ticket->get_pretty('TKT_name')); |
248 | 248 | $html .= $this->ticket_details->getShowHideLinks(); |
@@ -276,7 +276,7 @@ discard block |
||
276 | 276 | '', |
277 | 277 | 'tckt-slctr-tbl-td-price jst-rght', |
278 | 278 | '', |
279 | - 'headers="price-' . $this->EVT_ID . '"' |
|
279 | + 'headers="price-'.$this->EVT_ID.'"' |
|
280 | 280 | ); |
281 | 281 | $html .= EEH_HTML::span( |
282 | 282 | EEH_Template::format_currency($this->ticket_price), |
@@ -19,390 +19,390 @@ |
||
19 | 19 | */ |
20 | 20 | class TicketSelectorRowStandard extends TicketSelectorRow |
21 | 21 | { |
22 | - /** |
|
23 | - * @var TicketDetails |
|
24 | - */ |
|
25 | - protected $ticket_details; |
|
26 | - |
|
27 | - /** |
|
28 | - * @var EE_Ticket_Selector_Config |
|
29 | - */ |
|
30 | - protected $template_settings; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var EE_Tax_Config |
|
34 | - */ |
|
35 | - protected $tax_settings; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var boolean |
|
39 | - */ |
|
40 | - protected $prices_displayed_including_taxes; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var int |
|
44 | - */ |
|
45 | - protected $row; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var int |
|
49 | - */ |
|
50 | - protected $cols; |
|
51 | - |
|
52 | - /** |
|
53 | - * @var boolean |
|
54 | - */ |
|
55 | - protected $hidden_input_qty = false; |
|
56 | - |
|
57 | - /** |
|
58 | - * @var string |
|
59 | - */ |
|
60 | - protected $ticket_datetime_classes; |
|
61 | - |
|
62 | - private bool $use_new_checkbox_selector; |
|
63 | - |
|
64 | - |
|
65 | - /** |
|
66 | - * TicketDetails constructor. |
|
67 | - * |
|
68 | - * @param TicketDetails $ticket_details |
|
69 | - * @param EE_Tax_Config $tax_settings |
|
70 | - * @param int $total_tickets |
|
71 | - * @param int $max_attendees |
|
72 | - * @param int $row |
|
73 | - * @param int $cols |
|
74 | - * @param boolean $required_ticket_sold_out |
|
75 | - * @param string $event_status |
|
76 | - * @param string $ticket_datetime_classes |
|
77 | - * @param bool $use_new_checkbox_selector |
|
78 | - * @throws EE_Error |
|
79 | - * @throws UnexpectedEntityException |
|
80 | - */ |
|
81 | - public function __construct( |
|
82 | - TicketDetails $ticket_details, |
|
83 | - EE_Tax_Config $tax_settings, |
|
84 | - $total_tickets, |
|
85 | - $max_attendees, |
|
86 | - $row, |
|
87 | - $cols, |
|
88 | - $required_ticket_sold_out, |
|
89 | - $event_status, |
|
90 | - $ticket_datetime_classes, |
|
91 | - bool $use_new_checkbox_selector = false |
|
92 | - ) { |
|
93 | - $this->ticket_details = $ticket_details; |
|
94 | - $this->template_settings = $ticket_details->getTemplateSettings(); |
|
95 | - $this->tax_settings = $tax_settings; |
|
96 | - $this->row = $row; |
|
97 | - $this->cols = $cols; |
|
98 | - $this->ticket_datetime_classes = $ticket_datetime_classes; |
|
99 | - $this->use_new_checkbox_selector = $use_new_checkbox_selector; |
|
100 | - parent::__construct( |
|
101 | - $ticket_details->getTicket(), |
|
102 | - $max_attendees, |
|
103 | - $ticket_details->getDateFormat(), |
|
104 | - $event_status, |
|
105 | - $required_ticket_sold_out, |
|
106 | - $total_tickets |
|
107 | - ); |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * other ticket rows will need to know if a required ticket is sold out, |
|
113 | - * so that they are not offered for sale |
|
114 | - * |
|
115 | - * @return boolean |
|
116 | - */ |
|
117 | - public function getRequiredTicketSoldOut() |
|
118 | - { |
|
119 | - return $this->required_ticket_sold_out; |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * @return int |
|
125 | - */ |
|
126 | - public function getCols() |
|
127 | - { |
|
128 | - return $this->cols; |
|
129 | - } |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * getHtml |
|
134 | - * |
|
135 | - * @return string |
|
136 | - * @throws EE_Error |
|
137 | - * @throws ReflectionException |
|
138 | - */ |
|
139 | - public function getHtml() |
|
140 | - { |
|
141 | - $this->min = 0; |
|
142 | - $this->max = $this->ticket->max(); |
|
143 | - $remaining = $this->ticket->remaining(); |
|
144 | - $this->setTicketMinAndMax($remaining); |
|
145 | - // set flag if ticket is required (flag is set to start date so that future tickets are not blocked) |
|
146 | - $this->required_ticket_sold_out = $this->ticket->required() && ! $remaining |
|
147 | - ? $this->ticket->start_date() |
|
148 | - : $this->required_ticket_sold_out; |
|
149 | - $this->setTicketPriceDetails(); |
|
150 | - $this->setTicketStatusClasses($remaining); |
|
151 | - $filtered_row_html = $this->getFilteredRowHtml(); |
|
152 | - if ($filtered_row_html !== false) { |
|
153 | - return $filtered_row_html; |
|
154 | - } |
|
155 | - $ticket_selector_row_html = EEH_HTML::tr( |
|
156 | - '', |
|
157 | - '', |
|
158 | - "tckt-slctr-tbl-tr {$this->status_class}{$this->ticket_datetime_classes} " |
|
159 | - . espresso_get_object_css_class($this->ticket) |
|
160 | - ); |
|
161 | - $filtered_row_content = $this->getFilteredRowContents(); |
|
162 | - if ($filtered_row_content !== false) { |
|
163 | - if ($this->max_attendees === 1) { |
|
164 | - return $ticket_selector_row_html |
|
165 | - . $filtered_row_content |
|
166 | - . $this->ticketQtyAndIdHiddenInputs() |
|
167 | - . EEH_HTML::trx(); |
|
168 | - } |
|
169 | - return $ticket_selector_row_html |
|
170 | - . $filtered_row_content |
|
171 | - . EEH_HTML::trx(); |
|
172 | - } |
|
173 | - $this->hidden_input_qty = $this->max_attendees > 1; |
|
174 | - |
|
175 | - $ticket_selector_row_html .= $this->ticketNameTableCell(); |
|
176 | - $ticket_selector_row_html .= $this->ticketPriceTableCell(); |
|
177 | - $ticket_selector_row_html .= EEH_HTML::td( |
|
178 | - '', |
|
179 | - '', |
|
180 | - 'tckt-slctr-tbl-td-qty cntr', |
|
181 | - '', |
|
182 | - 'headers="quantity-' . $this->EVT_ID . '"' |
|
183 | - ); |
|
184 | - $this->setTicketStatusDisplay($remaining); |
|
185 | - if (empty($this->ticket_status_display)) { |
|
186 | - $this->hidden_input_qty = false; |
|
187 | - // display submit button since we have tickets available |
|
188 | - add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
189 | - if ($this->max_attendees === 1) { |
|
190 | - // only ONE attendee is allowed to register at a time |
|
191 | - $ticket_selector_row_html .= $this->onlyOneAttendeeCanRegister(); |
|
192 | - } else { |
|
193 | - $ticket_selector_row_html .= $this->max === 1 && $this->use_new_checkbox_selector |
|
194 | - ? $this->ticketCheckboxSelector() |
|
195 | - : $this->ticketQuantitySelector(); |
|
196 | - } |
|
197 | - } |
|
198 | - $ticket_selector_row_html .= $this->ticket_status_display; |
|
199 | - $ticket_selector_row_html .= $this->ticketQtyAndIdHiddenInputs(); |
|
200 | - $ticket_selector_row_html .= $this->ticket_details->display( |
|
201 | - $this->ticket_price, |
|
202 | - $remaining, |
|
203 | - $this->cols |
|
204 | - ); |
|
205 | - $ticket_selector_row_html .= EEH_HTML::tdx(); |
|
206 | - $ticket_selector_row_html .= EEH_HTML::trx(); |
|
207 | - |
|
208 | - |
|
209 | - $this->row++; |
|
210 | - return $ticket_selector_row_html; |
|
211 | - } |
|
212 | - |
|
213 | - |
|
214 | - /** |
|
215 | - * getTicketPriceDetails |
|
216 | - * |
|
217 | - * @return void |
|
218 | - * @throws EE_Error |
|
219 | - * @throws ReflectionException |
|
220 | - */ |
|
221 | - protected function setTicketPriceDetails() |
|
222 | - { |
|
223 | - $this->ticket_price = $this->tax_settings->prices_displayed_including_taxes |
|
224 | - ? $this->ticket->get_ticket_total_with_taxes() |
|
225 | - : $this->ticket->get_ticket_subtotal(); |
|
226 | - $this->ticket_bundle = false; |
|
227 | - $ticket_min = $this->ticket->min(); |
|
228 | - // for ticket bundles, set min and max qty the same |
|
229 | - if ($ticket_min !== 0 && $ticket_min === $this->ticket->max()) { |
|
230 | - $this->ticket_price *= $ticket_min; |
|
231 | - $this->ticket_bundle = true; |
|
232 | - } |
|
233 | - $this->ticket_price = apply_filters( |
|
234 | - 'FHEE__ticket_selector_chart_template__ticket_price', |
|
235 | - $this->ticket_price, |
|
236 | - $this->ticket |
|
237 | - ); |
|
238 | - } |
|
239 | - |
|
240 | - |
|
241 | - /** |
|
242 | - * ticketNameTableCell |
|
243 | - * |
|
244 | - * @return string |
|
245 | - * @throws EE_Error |
|
246 | - * @throws ReflectionException |
|
247 | - */ |
|
248 | - protected function ticketNameTableCell() |
|
249 | - { |
|
250 | - $html = EEH_HTML::td( |
|
251 | - '', |
|
252 | - '', |
|
253 | - 'tckt-slctr-tbl-td-name', |
|
254 | - '', |
|
255 | - 'headers="details-' . $this->EVT_ID . '"' |
|
256 | - ); |
|
257 | - $html .= EEH_HTML::strong($this->ticket->get_pretty('TKT_name')); |
|
258 | - $html .= $this->ticket_details->getShowHideLinks(); |
|
259 | - if ($this->ticket->required()) { |
|
260 | - $html .= EEH_HTML::p( |
|
261 | - apply_filters( |
|
262 | - 'FHEE__ticket_selector_chart_template__ticket_required_message', |
|
263 | - esc_html__('This ticket is required and must be purchased.', 'event_espresso') |
|
264 | - ), |
|
265 | - '', |
|
266 | - 'ticket-required-pg' |
|
267 | - ); |
|
268 | - } |
|
269 | - $html .= EEH_HTML::tdx(); |
|
270 | - return $html; |
|
271 | - } |
|
272 | - |
|
273 | - |
|
274 | - /** |
|
275 | - * ticketPriceTableCell |
|
276 | - * |
|
277 | - * @return string |
|
278 | - * @throws EE_Error |
|
279 | - * @throws ReflectionException |
|
280 | - */ |
|
281 | - protected function ticketPriceTableCell() |
|
282 | - { |
|
283 | - $html = ''; |
|
284 | - if (apply_filters('FHEE__ticket_selector_chart_template__display_ticket_price_details', true)) { |
|
285 | - $html .= EEH_HTML::td( |
|
286 | - '', |
|
287 | - '', |
|
288 | - 'tckt-slctr-tbl-td-price jst-rght', |
|
289 | - '', |
|
290 | - 'headers="price-' . $this->EVT_ID . '"' |
|
291 | - ); |
|
292 | - $html .= EEH_HTML::span( |
|
293 | - EEH_Template::format_currency($this->ticket_price), |
|
294 | - '', |
|
295 | - 'tckt-price--nowrap' |
|
296 | - ); |
|
297 | - $html .= $this->ticket->taxable() |
|
298 | - ? EEH_HTML::span('*', '', 'taxable-tickets-asterisk grey-text') |
|
299 | - : ''; |
|
300 | - $html .= ' '; |
|
301 | - // phpcs:disable WordPress.WP.I18n.NoEmptyStrings |
|
302 | - $html .= EEH_HTML::span( |
|
303 | - $this->ticket_bundle |
|
304 | - ? apply_filters( |
|
305 | - 'FHEE__ticket_selector_chart_template__per_ticket_bundle_text', |
|
306 | - esc_html__(' / bundle', 'event_espresso') |
|
307 | - ) |
|
308 | - : apply_filters( |
|
309 | - 'FHEE__ticket_selector_chart_template__per_ticket_text', |
|
310 | - esc_html__('', 'event_espresso') |
|
311 | - ), |
|
312 | - '', |
|
313 | - 'smaller-text no-bold' |
|
314 | - ); |
|
315 | - $html .= ' '; |
|
316 | - $html .= EEH_HTML::tdx(); |
|
317 | - $this->cols++; |
|
318 | - } |
|
319 | - return $html; |
|
320 | - } |
|
321 | - |
|
322 | - |
|
323 | - /** |
|
324 | - * @return string |
|
325 | - * @throws EE_Error |
|
326 | - * @throws ReflectionException |
|
327 | - */ |
|
328 | - protected function onlyOneAttendeeCanRegister(): string |
|
329 | - { |
|
330 | - $TKT = $this->ticket->ID(); |
|
331 | - $label = esc_html__('Select this ticket', 'event_espresso'); |
|
332 | - $name = "tkt-slctr-qty-$this->EVT_ID"; |
|
333 | - $class = "ticket-selector-tbl-qty-slct"; |
|
334 | - $id = "$class-$this->EVT_ID-$this->row"; |
|
335 | - $checked = $this->total_tickets === 1 ? ' checked' : ''; |
|
336 | - |
|
337 | - return " |
|
22 | + /** |
|
23 | + * @var TicketDetails |
|
24 | + */ |
|
25 | + protected $ticket_details; |
|
26 | + |
|
27 | + /** |
|
28 | + * @var EE_Ticket_Selector_Config |
|
29 | + */ |
|
30 | + protected $template_settings; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var EE_Tax_Config |
|
34 | + */ |
|
35 | + protected $tax_settings; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var boolean |
|
39 | + */ |
|
40 | + protected $prices_displayed_including_taxes; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var int |
|
44 | + */ |
|
45 | + protected $row; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var int |
|
49 | + */ |
|
50 | + protected $cols; |
|
51 | + |
|
52 | + /** |
|
53 | + * @var boolean |
|
54 | + */ |
|
55 | + protected $hidden_input_qty = false; |
|
56 | + |
|
57 | + /** |
|
58 | + * @var string |
|
59 | + */ |
|
60 | + protected $ticket_datetime_classes; |
|
61 | + |
|
62 | + private bool $use_new_checkbox_selector; |
|
63 | + |
|
64 | + |
|
65 | + /** |
|
66 | + * TicketDetails constructor. |
|
67 | + * |
|
68 | + * @param TicketDetails $ticket_details |
|
69 | + * @param EE_Tax_Config $tax_settings |
|
70 | + * @param int $total_tickets |
|
71 | + * @param int $max_attendees |
|
72 | + * @param int $row |
|
73 | + * @param int $cols |
|
74 | + * @param boolean $required_ticket_sold_out |
|
75 | + * @param string $event_status |
|
76 | + * @param string $ticket_datetime_classes |
|
77 | + * @param bool $use_new_checkbox_selector |
|
78 | + * @throws EE_Error |
|
79 | + * @throws UnexpectedEntityException |
|
80 | + */ |
|
81 | + public function __construct( |
|
82 | + TicketDetails $ticket_details, |
|
83 | + EE_Tax_Config $tax_settings, |
|
84 | + $total_tickets, |
|
85 | + $max_attendees, |
|
86 | + $row, |
|
87 | + $cols, |
|
88 | + $required_ticket_sold_out, |
|
89 | + $event_status, |
|
90 | + $ticket_datetime_classes, |
|
91 | + bool $use_new_checkbox_selector = false |
|
92 | + ) { |
|
93 | + $this->ticket_details = $ticket_details; |
|
94 | + $this->template_settings = $ticket_details->getTemplateSettings(); |
|
95 | + $this->tax_settings = $tax_settings; |
|
96 | + $this->row = $row; |
|
97 | + $this->cols = $cols; |
|
98 | + $this->ticket_datetime_classes = $ticket_datetime_classes; |
|
99 | + $this->use_new_checkbox_selector = $use_new_checkbox_selector; |
|
100 | + parent::__construct( |
|
101 | + $ticket_details->getTicket(), |
|
102 | + $max_attendees, |
|
103 | + $ticket_details->getDateFormat(), |
|
104 | + $event_status, |
|
105 | + $required_ticket_sold_out, |
|
106 | + $total_tickets |
|
107 | + ); |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * other ticket rows will need to know if a required ticket is sold out, |
|
113 | + * so that they are not offered for sale |
|
114 | + * |
|
115 | + * @return boolean |
|
116 | + */ |
|
117 | + public function getRequiredTicketSoldOut() |
|
118 | + { |
|
119 | + return $this->required_ticket_sold_out; |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * @return int |
|
125 | + */ |
|
126 | + public function getCols() |
|
127 | + { |
|
128 | + return $this->cols; |
|
129 | + } |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * getHtml |
|
134 | + * |
|
135 | + * @return string |
|
136 | + * @throws EE_Error |
|
137 | + * @throws ReflectionException |
|
138 | + */ |
|
139 | + public function getHtml() |
|
140 | + { |
|
141 | + $this->min = 0; |
|
142 | + $this->max = $this->ticket->max(); |
|
143 | + $remaining = $this->ticket->remaining(); |
|
144 | + $this->setTicketMinAndMax($remaining); |
|
145 | + // set flag if ticket is required (flag is set to start date so that future tickets are not blocked) |
|
146 | + $this->required_ticket_sold_out = $this->ticket->required() && ! $remaining |
|
147 | + ? $this->ticket->start_date() |
|
148 | + : $this->required_ticket_sold_out; |
|
149 | + $this->setTicketPriceDetails(); |
|
150 | + $this->setTicketStatusClasses($remaining); |
|
151 | + $filtered_row_html = $this->getFilteredRowHtml(); |
|
152 | + if ($filtered_row_html !== false) { |
|
153 | + return $filtered_row_html; |
|
154 | + } |
|
155 | + $ticket_selector_row_html = EEH_HTML::tr( |
|
156 | + '', |
|
157 | + '', |
|
158 | + "tckt-slctr-tbl-tr {$this->status_class}{$this->ticket_datetime_classes} " |
|
159 | + . espresso_get_object_css_class($this->ticket) |
|
160 | + ); |
|
161 | + $filtered_row_content = $this->getFilteredRowContents(); |
|
162 | + if ($filtered_row_content !== false) { |
|
163 | + if ($this->max_attendees === 1) { |
|
164 | + return $ticket_selector_row_html |
|
165 | + . $filtered_row_content |
|
166 | + . $this->ticketQtyAndIdHiddenInputs() |
|
167 | + . EEH_HTML::trx(); |
|
168 | + } |
|
169 | + return $ticket_selector_row_html |
|
170 | + . $filtered_row_content |
|
171 | + . EEH_HTML::trx(); |
|
172 | + } |
|
173 | + $this->hidden_input_qty = $this->max_attendees > 1; |
|
174 | + |
|
175 | + $ticket_selector_row_html .= $this->ticketNameTableCell(); |
|
176 | + $ticket_selector_row_html .= $this->ticketPriceTableCell(); |
|
177 | + $ticket_selector_row_html .= EEH_HTML::td( |
|
178 | + '', |
|
179 | + '', |
|
180 | + 'tckt-slctr-tbl-td-qty cntr', |
|
181 | + '', |
|
182 | + 'headers="quantity-' . $this->EVT_ID . '"' |
|
183 | + ); |
|
184 | + $this->setTicketStatusDisplay($remaining); |
|
185 | + if (empty($this->ticket_status_display)) { |
|
186 | + $this->hidden_input_qty = false; |
|
187 | + // display submit button since we have tickets available |
|
188 | + add_filter('FHEE__EE_Ticket_Selector__display_ticket_selector_submit', '__return_true'); |
|
189 | + if ($this->max_attendees === 1) { |
|
190 | + // only ONE attendee is allowed to register at a time |
|
191 | + $ticket_selector_row_html .= $this->onlyOneAttendeeCanRegister(); |
|
192 | + } else { |
|
193 | + $ticket_selector_row_html .= $this->max === 1 && $this->use_new_checkbox_selector |
|
194 | + ? $this->ticketCheckboxSelector() |
|
195 | + : $this->ticketQuantitySelector(); |
|
196 | + } |
|
197 | + } |
|
198 | + $ticket_selector_row_html .= $this->ticket_status_display; |
|
199 | + $ticket_selector_row_html .= $this->ticketQtyAndIdHiddenInputs(); |
|
200 | + $ticket_selector_row_html .= $this->ticket_details->display( |
|
201 | + $this->ticket_price, |
|
202 | + $remaining, |
|
203 | + $this->cols |
|
204 | + ); |
|
205 | + $ticket_selector_row_html .= EEH_HTML::tdx(); |
|
206 | + $ticket_selector_row_html .= EEH_HTML::trx(); |
|
207 | + |
|
208 | + |
|
209 | + $this->row++; |
|
210 | + return $ticket_selector_row_html; |
|
211 | + } |
|
212 | + |
|
213 | + |
|
214 | + /** |
|
215 | + * getTicketPriceDetails |
|
216 | + * |
|
217 | + * @return void |
|
218 | + * @throws EE_Error |
|
219 | + * @throws ReflectionException |
|
220 | + */ |
|
221 | + protected function setTicketPriceDetails() |
|
222 | + { |
|
223 | + $this->ticket_price = $this->tax_settings->prices_displayed_including_taxes |
|
224 | + ? $this->ticket->get_ticket_total_with_taxes() |
|
225 | + : $this->ticket->get_ticket_subtotal(); |
|
226 | + $this->ticket_bundle = false; |
|
227 | + $ticket_min = $this->ticket->min(); |
|
228 | + // for ticket bundles, set min and max qty the same |
|
229 | + if ($ticket_min !== 0 && $ticket_min === $this->ticket->max()) { |
|
230 | + $this->ticket_price *= $ticket_min; |
|
231 | + $this->ticket_bundle = true; |
|
232 | + } |
|
233 | + $this->ticket_price = apply_filters( |
|
234 | + 'FHEE__ticket_selector_chart_template__ticket_price', |
|
235 | + $this->ticket_price, |
|
236 | + $this->ticket |
|
237 | + ); |
|
238 | + } |
|
239 | + |
|
240 | + |
|
241 | + /** |
|
242 | + * ticketNameTableCell |
|
243 | + * |
|
244 | + * @return string |
|
245 | + * @throws EE_Error |
|
246 | + * @throws ReflectionException |
|
247 | + */ |
|
248 | + protected function ticketNameTableCell() |
|
249 | + { |
|
250 | + $html = EEH_HTML::td( |
|
251 | + '', |
|
252 | + '', |
|
253 | + 'tckt-slctr-tbl-td-name', |
|
254 | + '', |
|
255 | + 'headers="details-' . $this->EVT_ID . '"' |
|
256 | + ); |
|
257 | + $html .= EEH_HTML::strong($this->ticket->get_pretty('TKT_name')); |
|
258 | + $html .= $this->ticket_details->getShowHideLinks(); |
|
259 | + if ($this->ticket->required()) { |
|
260 | + $html .= EEH_HTML::p( |
|
261 | + apply_filters( |
|
262 | + 'FHEE__ticket_selector_chart_template__ticket_required_message', |
|
263 | + esc_html__('This ticket is required and must be purchased.', 'event_espresso') |
|
264 | + ), |
|
265 | + '', |
|
266 | + 'ticket-required-pg' |
|
267 | + ); |
|
268 | + } |
|
269 | + $html .= EEH_HTML::tdx(); |
|
270 | + return $html; |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + /** |
|
275 | + * ticketPriceTableCell |
|
276 | + * |
|
277 | + * @return string |
|
278 | + * @throws EE_Error |
|
279 | + * @throws ReflectionException |
|
280 | + */ |
|
281 | + protected function ticketPriceTableCell() |
|
282 | + { |
|
283 | + $html = ''; |
|
284 | + if (apply_filters('FHEE__ticket_selector_chart_template__display_ticket_price_details', true)) { |
|
285 | + $html .= EEH_HTML::td( |
|
286 | + '', |
|
287 | + '', |
|
288 | + 'tckt-slctr-tbl-td-price jst-rght', |
|
289 | + '', |
|
290 | + 'headers="price-' . $this->EVT_ID . '"' |
|
291 | + ); |
|
292 | + $html .= EEH_HTML::span( |
|
293 | + EEH_Template::format_currency($this->ticket_price), |
|
294 | + '', |
|
295 | + 'tckt-price--nowrap' |
|
296 | + ); |
|
297 | + $html .= $this->ticket->taxable() |
|
298 | + ? EEH_HTML::span('*', '', 'taxable-tickets-asterisk grey-text') |
|
299 | + : ''; |
|
300 | + $html .= ' '; |
|
301 | + // phpcs:disable WordPress.WP.I18n.NoEmptyStrings |
|
302 | + $html .= EEH_HTML::span( |
|
303 | + $this->ticket_bundle |
|
304 | + ? apply_filters( |
|
305 | + 'FHEE__ticket_selector_chart_template__per_ticket_bundle_text', |
|
306 | + esc_html__(' / bundle', 'event_espresso') |
|
307 | + ) |
|
308 | + : apply_filters( |
|
309 | + 'FHEE__ticket_selector_chart_template__per_ticket_text', |
|
310 | + esc_html__('', 'event_espresso') |
|
311 | + ), |
|
312 | + '', |
|
313 | + 'smaller-text no-bold' |
|
314 | + ); |
|
315 | + $html .= ' '; |
|
316 | + $html .= EEH_HTML::tdx(); |
|
317 | + $this->cols++; |
|
318 | + } |
|
319 | + return $html; |
|
320 | + } |
|
321 | + |
|
322 | + |
|
323 | + /** |
|
324 | + * @return string |
|
325 | + * @throws EE_Error |
|
326 | + * @throws ReflectionException |
|
327 | + */ |
|
328 | + protected function onlyOneAttendeeCanRegister(): string |
|
329 | + { |
|
330 | + $TKT = $this->ticket->ID(); |
|
331 | + $label = esc_html__('Select this ticket', 'event_espresso'); |
|
332 | + $name = "tkt-slctr-qty-$this->EVT_ID"; |
|
333 | + $class = "ticket-selector-tbl-qty-slct"; |
|
334 | + $id = "$class-$this->EVT_ID-$this->row"; |
|
335 | + $checked = $this->total_tickets === 1 ? ' checked' : ''; |
|
336 | + |
|
337 | + return " |
|
338 | 338 | <label class='ee-a11y-screen-reader-text' for='$id' >$label</label> |
339 | 339 | <input type='radio'$checked name='$name' id='$id' class='$class' value='$TKT-1' />"; |
340 | - } |
|
341 | - |
|
342 | - |
|
343 | - /** |
|
344 | - * @return string |
|
345 | - * @throws EE_Error |
|
346 | - * @throws ReflectionException |
|
347 | - */ |
|
348 | - protected function ticketCheckboxSelector(): string |
|
349 | - { |
|
350 | - $TKT = $this->ticket->ID(); |
|
351 | - $label = esc_html__('Select this ticket', 'event_espresso'); |
|
352 | - $name = "tkt-slctr-qty-$this->EVT_ID[$TKT]"; |
|
353 | - $class = 'ticket-selector-tbl-qty-slct'; |
|
354 | - $id = "$class-$this->EVT_ID-$this->row"; |
|
355 | - $title = esc_html__('only one of this ticket can be purchased at a time', 'event_espresso'); |
|
356 | - |
|
357 | - return " |
|
340 | + } |
|
341 | + |
|
342 | + |
|
343 | + /** |
|
344 | + * @return string |
|
345 | + * @throws EE_Error |
|
346 | + * @throws ReflectionException |
|
347 | + */ |
|
348 | + protected function ticketCheckboxSelector(): string |
|
349 | + { |
|
350 | + $TKT = $this->ticket->ID(); |
|
351 | + $label = esc_html__('Select this ticket', 'event_espresso'); |
|
352 | + $name = "tkt-slctr-qty-$this->EVT_ID[$TKT]"; |
|
353 | + $class = 'ticket-selector-tbl-qty-slct'; |
|
354 | + $id = "$class-$this->EVT_ID-$this->row"; |
|
355 | + $title = esc_html__('only one of this ticket can be purchased at a time', 'event_espresso'); |
|
356 | + |
|
357 | + return " |
|
358 | 358 | <label class='ee-a11y-screen-reader-text' for='$id' >$label</label> |
359 | 359 | <input type='checkbox' name='$name' id='$id' class='$class' value='1' title='$title'/>"; |
360 | - } |
|
361 | - |
|
362 | - |
|
363 | - /** |
|
364 | - * @return string |
|
365 | - * @throws EE_Error |
|
366 | - * @throws ReflectionException |
|
367 | - */ |
|
368 | - protected function ticketQuantitySelector(): string |
|
369 | - { |
|
370 | - $TKT = $this->ticket->ID(); |
|
371 | - $label = esc_html__('Quantity', 'event_espresso'); |
|
372 | - $name = "tkt-slctr-qty-$this->EVT_ID[$TKT]"; |
|
373 | - $class = 'ticket-selector-tbl-qty-slct'; |
|
374 | - $id = "$class-{$this->EVT_ID}-{$this->row}"; |
|
375 | - |
|
376 | - $html = "<label class='ee-a11y-screen-reader-text' for='$id' >$label</label>"; |
|
377 | - $html .= "<select name='$name' id='$id' class='$class'>"; |
|
378 | - // this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased |
|
379 | - if ($this->min !== 0 && ! $this->ticket->required()) { |
|
380 | - $html .= "<option value='0'> 0 </option>"; |
|
381 | - } |
|
382 | - // offer ticket quantities from the min to the max |
|
383 | - for ($i = $this->min; $i <= $this->max; $i++) { |
|
384 | - $html .= "<option value='$i'> $i </option>"; |
|
385 | - } |
|
386 | - $html .= "</select>"; |
|
387 | - return $html; |
|
388 | - } |
|
389 | - |
|
390 | - |
|
391 | - /** |
|
392 | - * @return string |
|
393 | - * @throws EE_Error |
|
394 | - * @throws ReflectionException |
|
395 | - */ |
|
396 | - protected function ticketQtyAndIdHiddenInputs(): string |
|
397 | - { |
|
398 | - $html = ''; |
|
399 | - $EVT = $this->EVT_ID; |
|
400 | - $TKT = $this->ticket->ID(); |
|
401 | - // depending on group reg we need to change the format for qty |
|
402 | - if ($this->hidden_input_qty) { |
|
403 | - $html .= "<input type='hidden' name='tkt-slctr-qty-{$EVT}[]' value='0' />"; |
|
404 | - } |
|
405 | - $html .= "<input type='hidden' name='tkt-slctr-ticket-id-{$EVT}[]' value='{$TKT}' />"; |
|
406 | - return $html; |
|
407 | - } |
|
360 | + } |
|
361 | + |
|
362 | + |
|
363 | + /** |
|
364 | + * @return string |
|
365 | + * @throws EE_Error |
|
366 | + * @throws ReflectionException |
|
367 | + */ |
|
368 | + protected function ticketQuantitySelector(): string |
|
369 | + { |
|
370 | + $TKT = $this->ticket->ID(); |
|
371 | + $label = esc_html__('Quantity', 'event_espresso'); |
|
372 | + $name = "tkt-slctr-qty-$this->EVT_ID[$TKT]"; |
|
373 | + $class = 'ticket-selector-tbl-qty-slct'; |
|
374 | + $id = "$class-{$this->EVT_ID}-{$this->row}"; |
|
375 | + |
|
376 | + $html = "<label class='ee-a11y-screen-reader-text' for='$id' >$label</label>"; |
|
377 | + $html .= "<select name='$name' id='$id' class='$class'>"; |
|
378 | + // this ensures that non-required tickets with non-zero MIN QTYs don't HAVE to be purchased |
|
379 | + if ($this->min !== 0 && ! $this->ticket->required()) { |
|
380 | + $html .= "<option value='0'> 0 </option>"; |
|
381 | + } |
|
382 | + // offer ticket quantities from the min to the max |
|
383 | + for ($i = $this->min; $i <= $this->max; $i++) { |
|
384 | + $html .= "<option value='$i'> $i </option>"; |
|
385 | + } |
|
386 | + $html .= "</select>"; |
|
387 | + return $html; |
|
388 | + } |
|
389 | + |
|
390 | + |
|
391 | + /** |
|
392 | + * @return string |
|
393 | + * @throws EE_Error |
|
394 | + * @throws ReflectionException |
|
395 | + */ |
|
396 | + protected function ticketQtyAndIdHiddenInputs(): string |
|
397 | + { |
|
398 | + $html = ''; |
|
399 | + $EVT = $this->EVT_ID; |
|
400 | + $TKT = $this->ticket->ID(); |
|
401 | + // depending on group reg we need to change the format for qty |
|
402 | + if ($this->hidden_input_qty) { |
|
403 | + $html .= "<input type='hidden' name='tkt-slctr-qty-{$EVT}[]' value='0' />"; |
|
404 | + } |
|
405 | + $html .= "<input type='hidden' name='tkt-slctr-ticket-id-{$EVT}[]' value='{$TKT}' />"; |
|
406 | + return $html; |
|
407 | + } |
|
408 | 408 | } |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | |
452 | 452 | function espressoUpgradeNow() |
453 | 453 | { |
454 | - if (! defined('EE_CAF_URL')) { |
|
454 | + if ( ! defined('EE_CAF_URL')) { |
|
455 | 455 | return ' |
456 | 456 | <div class="ee-card ee-card__buy-now ee-grid-col-span-3 ee-card--blank"> |
457 | 457 | <a href="https://eventespresso.com/pricing/?utm_source=wordpress_org&utm_medium=link&utm_campaign=decaf_about_page&utm_content=reviews+tab" |
@@ -459,7 +459,7 @@ discard block |
||
459 | 459 | class="button button--primary button-hero" |
460 | 460 | > |
461 | 461 | <span class="dashicons dashicons-cart"></span> |
462 | - ' . esc_html__('Upgrade Now!', 'event_espresso') . ' |
|
462 | + ' . esc_html__('Upgrade Now!', 'event_espresso').' |
|
463 | 463 | </a> |
464 | 464 | </div>'; |
465 | 465 | } |
@@ -1,19 +1,19 @@ discard block |
||
1 | 1 | <h2 style="text-align: left;"><?php esc_html_e('Who uses Event Espresso?', 'event_espresso'); ?></h2> |
2 | 2 | <p> |
3 | 3 | <?php printf( |
4 | - esc_html__( |
|
5 | - 'Event Espresso is used by over 40,000 event organizers across the world. They host %sconferences%s, %sart classes%s, training courses, concerts, fundraisers, workshops, %sfilm festivals%s, %spaint and wine%s, and more.', |
|
6 | - 'event_espresso' |
|
7 | - ), |
|
8 | - '<a href="https://eventespresso.com/use-cases/conferences/?utm_source=wordpress_org&utm_medium=link&utm_campaign=decaf_about_page&utm_content=Decaf+vs+Regular">', |
|
9 | - '</a>', |
|
10 | - '<a href="https://eventespresso.com/use-cases/art-classes/?utm_source=wordpress_org&utm_medium=link&utm_campaign=decaf_about_page&utm_content=Decaf+vs+Regular">', |
|
11 | - '</a>', |
|
12 | - '<a href="https://eventespresso.com/use-cases/film-festival-ticketing-software/?utm_source=wordpress_org&utm_medium=link&utm_campaign=decaf_about_page&utm_content=Decaf+vs+Regular">', |
|
13 | - '</a>', |
|
14 | - '<a href="https://eventespresso.com/use-cases/paint-wine-party-ticketing-software/?utm_source=wordpress_org&utm_medium=link&utm_campaign=decaf_about_page&utm_content=Decaf+vs+Regular">', |
|
15 | - '</a>' |
|
16 | - ); ?> |
|
4 | + esc_html__( |
|
5 | + 'Event Espresso is used by over 40,000 event organizers across the world. They host %sconferences%s, %sart classes%s, training courses, concerts, fundraisers, workshops, %sfilm festivals%s, %spaint and wine%s, and more.', |
|
6 | + 'event_espresso' |
|
7 | + ), |
|
8 | + '<a href="https://eventespresso.com/use-cases/conferences/?utm_source=wordpress_org&utm_medium=link&utm_campaign=decaf_about_page&utm_content=Decaf+vs+Regular">', |
|
9 | + '</a>', |
|
10 | + '<a href="https://eventespresso.com/use-cases/art-classes/?utm_source=wordpress_org&utm_medium=link&utm_campaign=decaf_about_page&utm_content=Decaf+vs+Regular">', |
|
11 | + '</a>', |
|
12 | + '<a href="https://eventespresso.com/use-cases/film-festival-ticketing-software/?utm_source=wordpress_org&utm_medium=link&utm_campaign=decaf_about_page&utm_content=Decaf+vs+Regular">', |
|
13 | + '</a>', |
|
14 | + '<a href="https://eventespresso.com/use-cases/paint-wine-party-ticketing-software/?utm_source=wordpress_org&utm_medium=link&utm_campaign=decaf_about_page&utm_content=Decaf+vs+Regular">', |
|
15 | + '</a>' |
|
16 | + ); ?> |
|
17 | 17 | </p> |
18 | 18 | |
19 | 19 | <h2 class="about-headline-callout"> |
@@ -451,8 +451,8 @@ discard block |
||
451 | 451 | |
452 | 452 | function espressoUpgradeNow() |
453 | 453 | { |
454 | - if (! defined('EE_CAF_URL')) { |
|
455 | - return ' |
|
454 | + if (! defined('EE_CAF_URL')) { |
|
455 | + return ' |
|
456 | 456 | <div class="ee-card ee-card__buy-now ee-grid-col-span-3 ee-card--blank"> |
457 | 457 | <a href="https://eventespresso.com/pricing/?utm_source=wordpress_org&utm_medium=link&utm_campaign=decaf_about_page&utm_content=reviews+tab" |
458 | 458 | target="_blank" |
@@ -462,13 +462,13 @@ discard block |
||
462 | 462 | ' . esc_html__('Upgrade Now!', 'event_espresso') . ' |
463 | 463 | </a> |
464 | 464 | </div>'; |
465 | - } |
|
465 | + } |
|
466 | 466 | } |
467 | 467 | |
468 | 468 | |
469 | 469 | function espressoFiveStars() |
470 | 470 | { |
471 | - return ' |
|
471 | + return ' |
|
472 | 472 | <div class="wporg-ratings" aria-label="5 out of 5 stars"> |
473 | 473 | <span class="dashicons dashicons-star-filled"></span> |
474 | 474 | <span class="dashicons dashicons-star-filled"></span> |
@@ -3,100 +3,100 @@ |
||
3 | 3 | |
4 | 4 | <h4> |
5 | 5 | <?php |
6 | - esc_html_e( |
|
7 | - 'You may be able to find an answer for your question or concern here:', |
|
8 | - 'event_espresso' |
|
9 | - ); |
|
10 | - ?> |
|
6 | + esc_html_e( |
|
7 | + 'You may be able to find an answer for your question or concern here:', |
|
8 | + 'event_espresso' |
|
9 | + ); |
|
10 | + ?> |
|
11 | 11 | </h4> |
12 | 12 | <ol> |
13 | 13 | <li> |
14 | 14 | <strong><em><?php esc_html_e('A known issue.', 'event_espresso'); ?></em></strong> |
15 | 15 | <?php |
16 | - printf( |
|
17 | - esc_html__( |
|
18 | - 'Some themes and plugins have %1$sknown conflicts%2$s with Event Espresso. (You can also browse the %3$sEvent Espresso support pages%2$s or %4$sEvent Espresso support forums%2$s to see if other members have experienced and solved the problem.)', |
|
19 | - 'event_espresso' |
|
20 | - ), |
|
21 | - '<a href="https://eventespresso.com/wiki/known-third-party-plugin-theme-conflicts/" target="_blank">', |
|
22 | - '</a>', |
|
23 | - '<a href="https://eventespresso.com/support/documentation/versioned-docs/?doc_ver=ee4" target="_blank">', |
|
24 | - '<a href="https://eventespresso.com/support/forums/" target="_blank">' |
|
25 | - ); |
|
26 | - ?> |
|
16 | + printf( |
|
17 | + esc_html__( |
|
18 | + 'Some themes and plugins have %1$sknown conflicts%2$s with Event Espresso. (You can also browse the %3$sEvent Espresso support pages%2$s or %4$sEvent Espresso support forums%2$s to see if other members have experienced and solved the problem.)', |
|
19 | + 'event_espresso' |
|
20 | + ), |
|
21 | + '<a href="https://eventespresso.com/wiki/known-third-party-plugin-theme-conflicts/" target="_blank">', |
|
22 | + '</a>', |
|
23 | + '<a href="https://eventespresso.com/support/documentation/versioned-docs/?doc_ver=ee4" target="_blank">', |
|
24 | + '<a href="https://eventespresso.com/support/forums/" target="_blank">' |
|
25 | + ); |
|
26 | + ?> |
|
27 | 27 | </li> |
28 | 28 | <li> |
29 | 29 | <strong><em><?php esc_html_e('A plugin conflict.', 'event_espresso'); ?></em></strong> |
30 | 30 | <?php esc_html_e( |
31 | - 'You can check to see if there is a plugin conflict by temporarily deactivating all plugins except for Event Espresso. If the problem goes away, then reactivate your plugins one by one until the issue returns. This will help you pinpoint the source of the conflict.', |
|
32 | - 'event_espresso' |
|
33 | - ); ?> |
|
31 | + 'You can check to see if there is a plugin conflict by temporarily deactivating all plugins except for Event Espresso. If the problem goes away, then reactivate your plugins one by one until the issue returns. This will help you pinpoint the source of the conflict.', |
|
32 | + 'event_espresso' |
|
33 | + ); ?> |
|
34 | 34 | </li> |
35 | 35 | <li> |
36 | 36 | <strong><em><?php esc_html_e('A theme conflict.', 'event_espresso'); ?></em></strong> |
37 | 37 | <?php |
38 | - $default_theme = wp_get_theme(WP_DEFAULT_THEME); |
|
38 | + $default_theme = wp_get_theme(WP_DEFAULT_THEME); |
|
39 | 39 | |
40 | - if ($default_theme->exists()) { |
|
41 | - printf( |
|
42 | - esc_html__( |
|
43 | - 'If your problem is not a known issue or caused by a plugin, then try activating %s (the default WordPress theme).', |
|
44 | - 'event_espresso' |
|
45 | - ), |
|
46 | - $default_theme->get('Name') |
|
47 | - ); |
|
48 | - } else { |
|
49 | - esc_html_e( |
|
50 | - 'If your problem is not a known issue or caused by a plugin, then try activating the default WordPress theme.', |
|
51 | - 'event_espresso' |
|
52 | - ); |
|
53 | - } |
|
54 | - ?> |
|
40 | + if ($default_theme->exists()) { |
|
41 | + printf( |
|
42 | + esc_html__( |
|
43 | + 'If your problem is not a known issue or caused by a plugin, then try activating %s (the default WordPress theme).', |
|
44 | + 'event_espresso' |
|
45 | + ), |
|
46 | + $default_theme->get('Name') |
|
47 | + ); |
|
48 | + } else { |
|
49 | + esc_html_e( |
|
50 | + 'If your problem is not a known issue or caused by a plugin, then try activating the default WordPress theme.', |
|
51 | + 'event_espresso' |
|
52 | + ); |
|
53 | + } |
|
54 | + ?> |
|
55 | 55 | <?php |
56 | - esc_html_e( |
|
57 | - 'If this solves the problem for you, then something in your theme is causing this issue. Check to see if an update is available for your WordPress theme or reach out to the theme author.', |
|
58 | - 'event_espresso' |
|
59 | - ); |
|
60 | - ?> |
|
56 | + esc_html_e( |
|
57 | + 'If this solves the problem for you, then something in your theme is causing this issue. Check to see if an update is available for your WordPress theme or reach out to the theme author.', |
|
58 | + 'event_espresso' |
|
59 | + ); |
|
60 | + ?> |
|
61 | 61 | </li> |
62 | 62 | </ol> |
63 | 63 | |
64 | 64 | <p> |
65 | 65 | <?php |
66 | - esc_html_e( |
|
67 | - 'If none of the suggestions above help you find a solution, then feel free to reach out to the support team at Event Espresso.', |
|
68 | - 'event_espresso' |
|
69 | - ); |
|
70 | - ?> |
|
66 | + esc_html_e( |
|
67 | + 'If none of the suggestions above help you find a solution, then feel free to reach out to the support team at Event Espresso.', |
|
68 | + 'event_espresso' |
|
69 | + ); |
|
70 | + ?> |
|
71 | 71 | </p> |
72 | 72 | <p> |
73 | 73 | <?php |
74 | - printf( |
|
75 | - esc_html__( |
|
76 | - 'Login to your account on EventEspresso.com and %1$screate a support post in our member support forums%2$s. Use a %3$sclear and descriptive title%4$s in your support post, %3$sdescribe the issue to the best of your knowledge%4$s, and %3$snever post any sensitive information such as login details%4$s. Be sure to also include %5$simportant information in the section below%2$s about your WordPress site.', |
|
77 | - 'event_espresso' |
|
78 | - ), |
|
79 | - '<a href="https://eventespresso.com/support/forums/" target="_blank">', |
|
80 | - '</a>', |
|
81 | - '<strong>', |
|
82 | - '</strong>', |
|
83 | - '<a href="#espresso_important_information_settings">' |
|
84 | - ); |
|
85 | - ?> |
|
74 | + printf( |
|
75 | + esc_html__( |
|
76 | + 'Login to your account on EventEspresso.com and %1$screate a support post in our member support forums%2$s. Use a %3$sclear and descriptive title%4$s in your support post, %3$sdescribe the issue to the best of your knowledge%4$s, and %3$snever post any sensitive information such as login details%4$s. Be sure to also include %5$simportant information in the section below%2$s about your WordPress site.', |
|
77 | + 'event_espresso' |
|
78 | + ), |
|
79 | + '<a href="https://eventespresso.com/support/forums/" target="_blank">', |
|
80 | + '</a>', |
|
81 | + '<strong>', |
|
82 | + '</strong>', |
|
83 | + '<a href="#espresso_important_information_settings">' |
|
84 | + ); |
|
85 | + ?> |
|
86 | 86 | </p> |
87 | 87 | |
88 | 88 | <h4><?php esc_html_e('Have an emergency?', 'event_espresso'); ?></h4> |
89 | 89 | |
90 | 90 | <p> |
91 | 91 | <?php |
92 | - printf( |
|
93 | - esc_html__( |
|
94 | - 'We offer support tokens to members that need help with a time-sensitive issue. A support token will provide you with up to 30 minutes of one-on-one time with a team member at Event Espresso. If you have an emergency and need help quickly, then please %1$spurchase a support token%2$s.', |
|
95 | - 'event_espresso' |
|
96 | - ), |
|
97 | - '<a href="https://eventespresso.com/product/premium-support-token/?utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=help_support_tab&utm_content=support_token" target="_blank">', |
|
98 | - '</a>' |
|
99 | - ); |
|
100 | - ?> |
|
92 | + printf( |
|
93 | + esc_html__( |
|
94 | + 'We offer support tokens to members that need help with a time-sensitive issue. A support token will provide you with up to 30 minutes of one-on-one time with a team member at Event Espresso. If you have an emergency and need help quickly, then please %1$spurchase a support token%2$s.', |
|
95 | + 'event_espresso' |
|
96 | + ), |
|
97 | + '<a href="https://eventespresso.com/product/premium-support-token/?utm_source=ee4_plugin_admin&utm_medium=link&utm_campaign=help_support_tab&utm_content=support_token" target="_blank">', |
|
98 | + '</a>' |
|
99 | + ); |
|
100 | + ?> |
|
101 | 101 | </p> |
102 | 102 | </div> |
@@ -1,19 +1,19 @@ discard block |
||
1 | 1 | <div class="padding"> |
2 | 2 | <p> |
3 | 3 | <?php |
4 | - esc_html_e( |
|
5 | - 'Displays a list of events based on a set of criteria on a WordPress page or post. Unless otherwise specified, events are sorted by start date.', |
|
6 | - 'event_espresso' |
|
7 | - ); |
|
8 | - printf( |
|
9 | - esc_html__( |
|
10 | - 'For a full list of available shortcodes, please view the %sshortcode documentation%s on our website.', |
|
11 | - 'event_espresso' |
|
12 | - ), |
|
13 | - '<a href="https://eventespresso.com/wiki/ee4-shortcodes-template-variables/">', |
|
14 | - '</a>' |
|
15 | - ); |
|
16 | - ?> |
|
4 | + esc_html_e( |
|
5 | + 'Displays a list of events based on a set of criteria on a WordPress page or post. Unless otherwise specified, events are sorted by start date.', |
|
6 | + 'event_espresso' |
|
7 | + ); |
|
8 | + printf( |
|
9 | + esc_html__( |
|
10 | + 'For a full list of available shortcodes, please view the %sshortcode documentation%s on our website.', |
|
11 | + 'event_espresso' |
|
12 | + ), |
|
13 | + '<a href="https://eventespresso.com/wiki/ee4-shortcodes-template-variables/">', |
|
14 | + '</a>' |
|
15 | + ); |
|
16 | + ?> |
|
17 | 17 | </p> |
18 | 18 | <ul> |
19 | 19 | <li> |
@@ -36,9 +36,9 @@ discard block |
||
36 | 36 | <li> |
37 | 37 | <strong> |
38 | 38 | <?php esc_html_e( |
39 | - 'Limit (paginate) the number of events that are shown in the event list on a page or post', |
|
40 | - 'event_espresso' |
|
41 | - ); ?> |
|
39 | + 'Limit (paginate) the number of events that are shown in the event list on a page or post', |
|
40 | + 'event_espresso' |
|
41 | + ); ?> |
|
42 | 42 | </strong> |
43 | 43 | <br /> |
44 | 44 | [ESPRESSO_EVENTS limit=5] |
@@ -81,9 +81,9 @@ discard block |
||
81 | 81 | <li> |
82 | 82 | <strong> |
83 | 83 | <?php esc_html_e( |
84 | - 'Order the event list by a specific set of parameters (refer to available options below)', |
|
85 | - 'event_espresso' |
|
86 | - ); ?> |
|
84 | + 'Order the event list by a specific set of parameters (refer to available options below)', |
|
85 | + 'event_espresso' |
|
86 | + ); ?> |
|
87 | 87 | </strong> |
88 | 88 | <br /> |
89 | 89 | [ESPRESSO_EVENTS order_by=start_date,id] |
@@ -91,14 +91,14 @@ discard block |
||
91 | 91 | </ul> |
92 | 92 | <p> |
93 | 93 | <?php |
94 | - printf( |
|
95 | - esc_html__( |
|
96 | - 'These parameters (options) are available for the %s shortcode parameter above. Multiple parameters should be separated by a comma.', |
|
97 | - 'event_espresso' |
|
98 | - ), |
|
99 | - 'order_by' |
|
100 | - ); |
|
101 | - ?> |
|
94 | + printf( |
|
95 | + esc_html__( |
|
96 | + 'These parameters (options) are available for the %s shortcode parameter above. Multiple parameters should be separated by a comma.', |
|
97 | + 'event_espresso' |
|
98 | + ), |
|
99 | + 'order_by' |
|
100 | + ); |
|
101 | + ?> |
|
102 | 102 | </p> |
103 | 103 | <p> |
104 | 104 | id<br /> |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | |
118 | 118 | protected function _installation() |
119 | 119 | { |
120 | - $template_path = EE_SUPPORT_ADMIN_TEMPLATE_PATH . 'support_admin_details_installation.template.php'; |
|
120 | + $template_path = EE_SUPPORT_ADMIN_TEMPLATE_PATH.'support_admin_details_installation.template.php'; |
|
121 | 121 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
122 | 122 | $template_path, |
123 | 123 | '', |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | $this->addMetaBox( |
139 | 139 | "espresso_{$box}_settings", |
140 | 140 | $label, |
141 | - function ($post, $metabox) { |
|
141 | + function($post, $metabox) { |
|
142 | 142 | EEH_Template::display_template( |
143 | 143 | $metabox['args']['template_path'], |
144 | 144 | $metabox['args']['template_args'] |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | $box, |
174 | 174 | $label, |
175 | 175 | array( |
176 | - 'template_path' => EE_SUPPORT_ADMIN_TEMPLATE_PATH . "support_admin_details_{$box}.template.php", |
|
176 | + 'template_path' => EE_SUPPORT_ADMIN_TEMPLATE_PATH."support_admin_details_{$box}.template.php", |
|
177 | 177 | 'template_args' => $this->_template_args, |
178 | 178 | ) |
179 | 179 | ); |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | $box, |
206 | 206 | $label, |
207 | 207 | array( |
208 | - 'template_path' => EE_SUPPORT_ADMIN_TEMPLATE_PATH . "support_admin_details_{$box}.template.php", |
|
208 | + 'template_path' => EE_SUPPORT_ADMIN_TEMPLATE_PATH."support_admin_details_{$box}.template.php", |
|
209 | 209 | 'template_args' => $this->_template_args, |
210 | 210 | ) |
211 | 211 | ); |
@@ -233,7 +233,7 @@ discard block |
||
233 | 233 | $box, |
234 | 234 | $label, |
235 | 235 | array( |
236 | - 'template_path' => EE_SUPPORT_ADMIN_TEMPLATE_PATH . "support_admin_details_{$box}.template.php", |
|
236 | + 'template_path' => EE_SUPPORT_ADMIN_TEMPLATE_PATH."support_admin_details_{$box}.template.php", |
|
237 | 237 | 'template_args' => $this->_template_args, |
238 | 238 | ) |
239 | 239 | ); |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | protected function _developers() |
245 | 245 | { |
246 | 246 | $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
247 | - EE_SUPPORT_ADMIN_TEMPLATE_PATH . 'developers_admin_details.template.php', |
|
247 | + EE_SUPPORT_ADMIN_TEMPLATE_PATH.'developers_admin_details.template.php', |
|
248 | 248 | array(), |
249 | 249 | true |
250 | 250 | ); |
@@ -11,244 +11,244 @@ |
||
11 | 11 | */ |
12 | 12 | class Support_Admin_Page extends EE_Admin_Page |
13 | 13 | { |
14 | - protected function _init_page_props() |
|
15 | - { |
|
16 | - $this->page_slug = EE_SUPPORT_PG_SLUG; |
|
17 | - $this->page_label = esc_html__('Help & Support', 'event_espresso'); |
|
18 | - $this->_admin_base_url = EE_SUPPORT_ADMIN_URL; |
|
19 | - $this->_admin_base_path = EE_SUPPORT_ADMIN; |
|
20 | - } |
|
21 | - |
|
22 | - |
|
23 | - protected function _ajax_hooks() |
|
24 | - { |
|
25 | - } |
|
26 | - |
|
27 | - |
|
28 | - protected function _define_page_props() |
|
29 | - { |
|
30 | - $this->_labels = array(); |
|
31 | - $this->_admin_page_title = $this->page_label; |
|
32 | - } |
|
33 | - |
|
34 | - |
|
35 | - protected function _set_page_routes() |
|
36 | - { |
|
37 | - $this->_page_routes = array( |
|
38 | - 'default' => array( |
|
39 | - 'func' => [$this, '_contact_support'], |
|
40 | - 'capability' => 'ee_read_ee', |
|
41 | - ), |
|
42 | - 'developers' => array( |
|
43 | - 'func' => [$this, '_developers'], |
|
44 | - 'capability' => 'ee_read_ee', |
|
45 | - ), |
|
46 | - 'shortcodes' => array( |
|
47 | - 'func' => [$this, '_shortcodes'], |
|
48 | - 'capability' => 'ee_read_ee', |
|
49 | - ), |
|
50 | - ); |
|
51 | - } |
|
52 | - |
|
53 | - |
|
54 | - protected function _set_page_config() |
|
55 | - { |
|
56 | - $this->_page_config = array( |
|
57 | - 'default' => array( |
|
58 | - 'nav' => array( |
|
59 | - 'label' => esc_html__('Support', 'event_espresso'), |
|
60 | - 'icon' => 'dashicons-sos', |
|
61 | - 'order' => 30, |
|
62 | - ), |
|
63 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_support_boxes')), |
|
64 | - 'require_nonce' => false, |
|
65 | - ), |
|
66 | - 'developers' => array( |
|
67 | - 'nav' => array( |
|
68 | - 'label' => esc_html__('Developers', 'event_espresso'), |
|
69 | - 'icon' => 'dashicons-coffee', |
|
70 | - 'order' => 50, |
|
71 | - ), |
|
72 | - 'metaboxes' => $this->_default_espresso_metaboxes, |
|
73 | - 'require_nonce' => false, |
|
74 | - ), |
|
75 | - 'shortcodes' => array( |
|
76 | - 'nav' => array( |
|
77 | - 'label' => esc_html__('Shortcodes', 'event_espresso'), |
|
78 | - 'icon' => 'dashicons-shortcode', |
|
79 | - 'order' => 60, |
|
80 | - ), |
|
81 | - 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_shortcodes_boxes')), |
|
82 | - 'require_nonce' => false, |
|
83 | - ), |
|
84 | - ); |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - // none of the below group are currently used for Support pages |
|
89 | - protected function _add_screen_options() |
|
90 | - { |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - protected function _add_feature_pointers() |
|
95 | - { |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - public function admin_init() |
|
100 | - { |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - public function admin_notices() |
|
105 | - { |
|
106 | - } |
|
107 | - |
|
108 | - |
|
109 | - public function admin_footer_scripts() |
|
110 | - { |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - public function load_scripts_styles() |
|
115 | - { |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - protected function _installation() |
|
120 | - { |
|
121 | - $template_path = EE_SUPPORT_ADMIN_TEMPLATE_PATH . 'support_admin_details_installation.template.php'; |
|
122 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
123 | - $template_path, |
|
124 | - '', |
|
125 | - true |
|
126 | - ); |
|
127 | - $this->display_admin_page_with_sidebar(); |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - protected function _resources() |
|
132 | - { |
|
133 | - $this->display_admin_page_with_sidebar(); |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - protected function _add_settings_metabox($box, $label, array $args) |
|
138 | - { |
|
139 | - $this->addMetaBox( |
|
140 | - "espresso_{$box}_settings", |
|
141 | - $label, |
|
142 | - function ($post, $metabox) { |
|
143 | - EEH_Template::display_template( |
|
144 | - $metabox['args']['template_path'], |
|
145 | - $metabox['args']['template_args'] |
|
146 | - ); |
|
147 | - }, |
|
148 | - $this->_current_screen->id, |
|
149 | - 'normal', |
|
150 | - 'high', |
|
151 | - apply_filters( |
|
152 | - "FHEE__Support_Admin_Page___add_settings_metabox__{$box}_args_array", |
|
153 | - $args |
|
154 | - ) |
|
155 | - ); |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - protected function _resources_boxes() |
|
160 | - { |
|
161 | - $boxes = apply_filters( |
|
162 | - 'FHEE__Support_Admin_Page___resources_boxes__boxes_array', |
|
163 | - array( |
|
164 | - 'favorite_theme_developers' => esc_html__('Favorite Theme Developers', 'event_espresso'), |
|
165 | - 'highly_recommended_themes' => esc_html__('Highly Recommended Themes', 'event_espresso'), |
|
166 | - 'hire_developer' => esc_html__('Hire a Developer', 'event_espresso'), |
|
167 | - 'partners' => esc_html__('Partners', 'event_espresso'), |
|
168 | - 'recommended_plugins' => esc_html__('Recommended Plugins', 'event_espresso'), |
|
169 | - 'other_resources' => esc_html__('Other Resources', 'event_espresso'), |
|
170 | - ) |
|
171 | - ); |
|
172 | - foreach ($boxes as $box => $label) { |
|
173 | - $this->_add_settings_metabox( |
|
174 | - $box, |
|
175 | - $label, |
|
176 | - array( |
|
177 | - 'template_path' => EE_SUPPORT_ADMIN_TEMPLATE_PATH . "support_admin_details_{$box}.template.php", |
|
178 | - 'template_args' => $this->_template_args, |
|
179 | - ) |
|
180 | - ); |
|
181 | - } |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - protected function _shortcodes() |
|
186 | - { |
|
187 | - $this->display_admin_page_with_sidebar(); |
|
188 | - } |
|
189 | - |
|
190 | - |
|
191 | - protected function _shortcodes_boxes() |
|
192 | - { |
|
193 | - $boxes = apply_filters( |
|
194 | - 'FHEE__Support_Admin_Page___shortcodes_boxes__boxes_array', |
|
195 | - array( |
|
196 | - 'shortcodes_event_listings' => esc_html__('Event Listings', 'event_espresso'), |
|
197 | - 'shortcodes_ticket_selector' => esc_html__('Event Ticket Selector', 'event_espresso'), |
|
198 | - 'shortcodes_category' => esc_html__('Event Categories', 'event_espresso'), |
|
199 | - 'shortcodes_attendee' => esc_html__('Event Attendees', 'event_espresso') |
|
200 | - /*'shortcodes_single_events' => esc_html__('Single Events', 'event_espresso'),*/ |
|
201 | - /*'shortcodes_attendee_listings' => esc_html__('Attendee Listings', 'event_espresso'),*/ |
|
202 | - ) |
|
203 | - ); |
|
204 | - foreach ($boxes as $box => $label) { |
|
205 | - $this->_add_settings_metabox( |
|
206 | - $box, |
|
207 | - $label, |
|
208 | - array( |
|
209 | - 'template_path' => EE_SUPPORT_ADMIN_TEMPLATE_PATH . "support_admin_details_{$box}.template.php", |
|
210 | - 'template_args' => $this->_template_args, |
|
211 | - ) |
|
212 | - ); |
|
213 | - } |
|
214 | - } |
|
215 | - |
|
216 | - |
|
217 | - protected function _contact_support() |
|
218 | - { |
|
219 | - $this->display_admin_page_with_sidebar(); |
|
220 | - } |
|
221 | - |
|
222 | - |
|
223 | - protected function _support_boxes() |
|
224 | - { |
|
225 | - $boxes = apply_filters( |
|
226 | - 'FHEE__Support_Admin_Page___support_boxes__boxes_array', |
|
227 | - array( |
|
228 | - 'contact_support' => esc_html__('Contact Support', 'event_espresso'), |
|
229 | - 'important_information' => esc_html__('Important Information', 'event_espresso'), |
|
230 | - ) |
|
231 | - ); |
|
232 | - foreach ($boxes as $box => $label) { |
|
233 | - $this->_add_settings_metabox( |
|
234 | - $box, |
|
235 | - $label, |
|
236 | - array( |
|
237 | - 'template_path' => EE_SUPPORT_ADMIN_TEMPLATE_PATH . "support_admin_details_{$box}.template.php", |
|
238 | - 'template_args' => $this->_template_args, |
|
239 | - ) |
|
240 | - ); |
|
241 | - } |
|
242 | - } |
|
243 | - |
|
244 | - |
|
245 | - protected function _developers() |
|
246 | - { |
|
247 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
248 | - EE_SUPPORT_ADMIN_TEMPLATE_PATH . 'developers_admin_details.template.php', |
|
249 | - array(), |
|
250 | - true |
|
251 | - ); |
|
252 | - $this->display_admin_page_with_sidebar(); |
|
253 | - } |
|
14 | + protected function _init_page_props() |
|
15 | + { |
|
16 | + $this->page_slug = EE_SUPPORT_PG_SLUG; |
|
17 | + $this->page_label = esc_html__('Help & Support', 'event_espresso'); |
|
18 | + $this->_admin_base_url = EE_SUPPORT_ADMIN_URL; |
|
19 | + $this->_admin_base_path = EE_SUPPORT_ADMIN; |
|
20 | + } |
|
21 | + |
|
22 | + |
|
23 | + protected function _ajax_hooks() |
|
24 | + { |
|
25 | + } |
|
26 | + |
|
27 | + |
|
28 | + protected function _define_page_props() |
|
29 | + { |
|
30 | + $this->_labels = array(); |
|
31 | + $this->_admin_page_title = $this->page_label; |
|
32 | + } |
|
33 | + |
|
34 | + |
|
35 | + protected function _set_page_routes() |
|
36 | + { |
|
37 | + $this->_page_routes = array( |
|
38 | + 'default' => array( |
|
39 | + 'func' => [$this, '_contact_support'], |
|
40 | + 'capability' => 'ee_read_ee', |
|
41 | + ), |
|
42 | + 'developers' => array( |
|
43 | + 'func' => [$this, '_developers'], |
|
44 | + 'capability' => 'ee_read_ee', |
|
45 | + ), |
|
46 | + 'shortcodes' => array( |
|
47 | + 'func' => [$this, '_shortcodes'], |
|
48 | + 'capability' => 'ee_read_ee', |
|
49 | + ), |
|
50 | + ); |
|
51 | + } |
|
52 | + |
|
53 | + |
|
54 | + protected function _set_page_config() |
|
55 | + { |
|
56 | + $this->_page_config = array( |
|
57 | + 'default' => array( |
|
58 | + 'nav' => array( |
|
59 | + 'label' => esc_html__('Support', 'event_espresso'), |
|
60 | + 'icon' => 'dashicons-sos', |
|
61 | + 'order' => 30, |
|
62 | + ), |
|
63 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_support_boxes')), |
|
64 | + 'require_nonce' => false, |
|
65 | + ), |
|
66 | + 'developers' => array( |
|
67 | + 'nav' => array( |
|
68 | + 'label' => esc_html__('Developers', 'event_espresso'), |
|
69 | + 'icon' => 'dashicons-coffee', |
|
70 | + 'order' => 50, |
|
71 | + ), |
|
72 | + 'metaboxes' => $this->_default_espresso_metaboxes, |
|
73 | + 'require_nonce' => false, |
|
74 | + ), |
|
75 | + 'shortcodes' => array( |
|
76 | + 'nav' => array( |
|
77 | + 'label' => esc_html__('Shortcodes', 'event_espresso'), |
|
78 | + 'icon' => 'dashicons-shortcode', |
|
79 | + 'order' => 60, |
|
80 | + ), |
|
81 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_shortcodes_boxes')), |
|
82 | + 'require_nonce' => false, |
|
83 | + ), |
|
84 | + ); |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + // none of the below group are currently used for Support pages |
|
89 | + protected function _add_screen_options() |
|
90 | + { |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + protected function _add_feature_pointers() |
|
95 | + { |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + public function admin_init() |
|
100 | + { |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + public function admin_notices() |
|
105 | + { |
|
106 | + } |
|
107 | + |
|
108 | + |
|
109 | + public function admin_footer_scripts() |
|
110 | + { |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + public function load_scripts_styles() |
|
115 | + { |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + protected function _installation() |
|
120 | + { |
|
121 | + $template_path = EE_SUPPORT_ADMIN_TEMPLATE_PATH . 'support_admin_details_installation.template.php'; |
|
122 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
123 | + $template_path, |
|
124 | + '', |
|
125 | + true |
|
126 | + ); |
|
127 | + $this->display_admin_page_with_sidebar(); |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + protected function _resources() |
|
132 | + { |
|
133 | + $this->display_admin_page_with_sidebar(); |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + protected function _add_settings_metabox($box, $label, array $args) |
|
138 | + { |
|
139 | + $this->addMetaBox( |
|
140 | + "espresso_{$box}_settings", |
|
141 | + $label, |
|
142 | + function ($post, $metabox) { |
|
143 | + EEH_Template::display_template( |
|
144 | + $metabox['args']['template_path'], |
|
145 | + $metabox['args']['template_args'] |
|
146 | + ); |
|
147 | + }, |
|
148 | + $this->_current_screen->id, |
|
149 | + 'normal', |
|
150 | + 'high', |
|
151 | + apply_filters( |
|
152 | + "FHEE__Support_Admin_Page___add_settings_metabox__{$box}_args_array", |
|
153 | + $args |
|
154 | + ) |
|
155 | + ); |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + protected function _resources_boxes() |
|
160 | + { |
|
161 | + $boxes = apply_filters( |
|
162 | + 'FHEE__Support_Admin_Page___resources_boxes__boxes_array', |
|
163 | + array( |
|
164 | + 'favorite_theme_developers' => esc_html__('Favorite Theme Developers', 'event_espresso'), |
|
165 | + 'highly_recommended_themes' => esc_html__('Highly Recommended Themes', 'event_espresso'), |
|
166 | + 'hire_developer' => esc_html__('Hire a Developer', 'event_espresso'), |
|
167 | + 'partners' => esc_html__('Partners', 'event_espresso'), |
|
168 | + 'recommended_plugins' => esc_html__('Recommended Plugins', 'event_espresso'), |
|
169 | + 'other_resources' => esc_html__('Other Resources', 'event_espresso'), |
|
170 | + ) |
|
171 | + ); |
|
172 | + foreach ($boxes as $box => $label) { |
|
173 | + $this->_add_settings_metabox( |
|
174 | + $box, |
|
175 | + $label, |
|
176 | + array( |
|
177 | + 'template_path' => EE_SUPPORT_ADMIN_TEMPLATE_PATH . "support_admin_details_{$box}.template.php", |
|
178 | + 'template_args' => $this->_template_args, |
|
179 | + ) |
|
180 | + ); |
|
181 | + } |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + protected function _shortcodes() |
|
186 | + { |
|
187 | + $this->display_admin_page_with_sidebar(); |
|
188 | + } |
|
189 | + |
|
190 | + |
|
191 | + protected function _shortcodes_boxes() |
|
192 | + { |
|
193 | + $boxes = apply_filters( |
|
194 | + 'FHEE__Support_Admin_Page___shortcodes_boxes__boxes_array', |
|
195 | + array( |
|
196 | + 'shortcodes_event_listings' => esc_html__('Event Listings', 'event_espresso'), |
|
197 | + 'shortcodes_ticket_selector' => esc_html__('Event Ticket Selector', 'event_espresso'), |
|
198 | + 'shortcodes_category' => esc_html__('Event Categories', 'event_espresso'), |
|
199 | + 'shortcodes_attendee' => esc_html__('Event Attendees', 'event_espresso') |
|
200 | + /*'shortcodes_single_events' => esc_html__('Single Events', 'event_espresso'),*/ |
|
201 | + /*'shortcodes_attendee_listings' => esc_html__('Attendee Listings', 'event_espresso'),*/ |
|
202 | + ) |
|
203 | + ); |
|
204 | + foreach ($boxes as $box => $label) { |
|
205 | + $this->_add_settings_metabox( |
|
206 | + $box, |
|
207 | + $label, |
|
208 | + array( |
|
209 | + 'template_path' => EE_SUPPORT_ADMIN_TEMPLATE_PATH . "support_admin_details_{$box}.template.php", |
|
210 | + 'template_args' => $this->_template_args, |
|
211 | + ) |
|
212 | + ); |
|
213 | + } |
|
214 | + } |
|
215 | + |
|
216 | + |
|
217 | + protected function _contact_support() |
|
218 | + { |
|
219 | + $this->display_admin_page_with_sidebar(); |
|
220 | + } |
|
221 | + |
|
222 | + |
|
223 | + protected function _support_boxes() |
|
224 | + { |
|
225 | + $boxes = apply_filters( |
|
226 | + 'FHEE__Support_Admin_Page___support_boxes__boxes_array', |
|
227 | + array( |
|
228 | + 'contact_support' => esc_html__('Contact Support', 'event_espresso'), |
|
229 | + 'important_information' => esc_html__('Important Information', 'event_espresso'), |
|
230 | + ) |
|
231 | + ); |
|
232 | + foreach ($boxes as $box => $label) { |
|
233 | + $this->_add_settings_metabox( |
|
234 | + $box, |
|
235 | + $label, |
|
236 | + array( |
|
237 | + 'template_path' => EE_SUPPORT_ADMIN_TEMPLATE_PATH . "support_admin_details_{$box}.template.php", |
|
238 | + 'template_args' => $this->_template_args, |
|
239 | + ) |
|
240 | + ); |
|
241 | + } |
|
242 | + } |
|
243 | + |
|
244 | + |
|
245 | + protected function _developers() |
|
246 | + { |
|
247 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template( |
|
248 | + EE_SUPPORT_ADMIN_TEMPLATE_PATH . 'developers_admin_details.template.php', |
|
249 | + array(), |
|
250 | + true |
|
251 | + ); |
|
252 | + $this->display_admin_page_with_sidebar(); |
|
253 | + } |
|
254 | 254 | } |