@@ -26,149 +26,149 @@ |
||
26 | 26 | { |
27 | 27 | |
28 | 28 | |
29 | - /** |
|
30 | - * @param EE_Registration $target_registration |
|
31 | - * @param EE_Registration $registration_to_copy |
|
32 | - * @return bool |
|
33 | - * @throws UnexpectedEntityException |
|
34 | - * @throws EntityNotFoundException |
|
35 | - * @throws RuntimeException |
|
36 | - * @throws EE_Error |
|
37 | - */ |
|
38 | - public function copyRegistrationDetails( |
|
39 | - EE_Registration $target_registration, |
|
40 | - EE_Registration $registration_to_copy |
|
41 | - ) { |
|
42 | - // copy attendee |
|
43 | - $target_registration->set_attendee_id($registration_to_copy->attendee_ID()); |
|
44 | - $target_registration->updateStatusBasedOnTotalPaid(false); |
|
45 | - $target_registration->save(); |
|
46 | - // get answers to previous reg questions |
|
47 | - $answers = $this->reindexAnswersByQuestionId($registration_to_copy->answers()); |
|
48 | - // get questions to new event reg form |
|
49 | - $new_event = $target_registration->event(); |
|
50 | - $question_groups = $new_event->question_groups( |
|
51 | - array( |
|
52 | - array( |
|
53 | - 'Event.EVT_ID' => $new_event->ID(), |
|
54 | - 'Event_Question_Group.EQG_primary' => $registration_to_copy->is_primary_registrant(), |
|
55 | - ), |
|
56 | - 'order_by' => array('QSG_order' => 'ASC'), |
|
57 | - ) |
|
58 | - ); |
|
59 | - foreach ($question_groups as $question_group) { |
|
60 | - if ($question_group instanceof \EE_Question_Group) { |
|
61 | - foreach ($question_group->questions() as $question) { |
|
62 | - if ($question instanceof EE_Question) { |
|
63 | - $this->generateNewAnswer( |
|
64 | - $question, |
|
65 | - $target_registration, |
|
66 | - $answers |
|
67 | - ); |
|
68 | - } |
|
69 | - } |
|
70 | - } |
|
71 | - } |
|
72 | - return true; |
|
73 | - } |
|
29 | + /** |
|
30 | + * @param EE_Registration $target_registration |
|
31 | + * @param EE_Registration $registration_to_copy |
|
32 | + * @return bool |
|
33 | + * @throws UnexpectedEntityException |
|
34 | + * @throws EntityNotFoundException |
|
35 | + * @throws RuntimeException |
|
36 | + * @throws EE_Error |
|
37 | + */ |
|
38 | + public function copyRegistrationDetails( |
|
39 | + EE_Registration $target_registration, |
|
40 | + EE_Registration $registration_to_copy |
|
41 | + ) { |
|
42 | + // copy attendee |
|
43 | + $target_registration->set_attendee_id($registration_to_copy->attendee_ID()); |
|
44 | + $target_registration->updateStatusBasedOnTotalPaid(false); |
|
45 | + $target_registration->save(); |
|
46 | + // get answers to previous reg questions |
|
47 | + $answers = $this->reindexAnswersByQuestionId($registration_to_copy->answers()); |
|
48 | + // get questions to new event reg form |
|
49 | + $new_event = $target_registration->event(); |
|
50 | + $question_groups = $new_event->question_groups( |
|
51 | + array( |
|
52 | + array( |
|
53 | + 'Event.EVT_ID' => $new_event->ID(), |
|
54 | + 'Event_Question_Group.EQG_primary' => $registration_to_copy->is_primary_registrant(), |
|
55 | + ), |
|
56 | + 'order_by' => array('QSG_order' => 'ASC'), |
|
57 | + ) |
|
58 | + ); |
|
59 | + foreach ($question_groups as $question_group) { |
|
60 | + if ($question_group instanceof \EE_Question_Group) { |
|
61 | + foreach ($question_group->questions() as $question) { |
|
62 | + if ($question instanceof EE_Question) { |
|
63 | + $this->generateNewAnswer( |
|
64 | + $question, |
|
65 | + $target_registration, |
|
66 | + $answers |
|
67 | + ); |
|
68 | + } |
|
69 | + } |
|
70 | + } |
|
71 | + } |
|
72 | + return true; |
|
73 | + } |
|
74 | 74 | |
75 | 75 | |
76 | - /** |
|
77 | - * @param EE_Answer[] $answers |
|
78 | - * @return array |
|
79 | - * @throws EE_Error |
|
80 | - */ |
|
81 | - protected function reindexAnswersByQuestionId(array $answers) |
|
82 | - { |
|
83 | - $reindexed_answers = array(); |
|
84 | - foreach ($answers as $answer) { |
|
85 | - if ($answer instanceof EE_Answer) { |
|
86 | - $reindexed_answers[ $answer->question_ID() ] = $answer->value(); |
|
87 | - } |
|
88 | - } |
|
89 | - return $reindexed_answers; |
|
90 | - } |
|
76 | + /** |
|
77 | + * @param EE_Answer[] $answers |
|
78 | + * @return array |
|
79 | + * @throws EE_Error |
|
80 | + */ |
|
81 | + protected function reindexAnswersByQuestionId(array $answers) |
|
82 | + { |
|
83 | + $reindexed_answers = array(); |
|
84 | + foreach ($answers as $answer) { |
|
85 | + if ($answer instanceof EE_Answer) { |
|
86 | + $reindexed_answers[ $answer->question_ID() ] = $answer->value(); |
|
87 | + } |
|
88 | + } |
|
89 | + return $reindexed_answers; |
|
90 | + } |
|
91 | 91 | |
92 | 92 | |
93 | - /** |
|
94 | - * @param EE_Question $question |
|
95 | - * @param EE_Registration $registration |
|
96 | - * @param $previous_answers |
|
97 | - * @return EE_Answer |
|
98 | - * @throws UnexpectedEntityException |
|
99 | - * @throws EE_Error |
|
100 | - */ |
|
101 | - protected function generateNewAnswer( |
|
102 | - EE_Question $question, |
|
103 | - EE_Registration $registration, |
|
104 | - $previous_answers |
|
105 | - ) { |
|
106 | - $old_answer_value = isset($previous_answers[ $question->ID() ]) |
|
107 | - ? $previous_answers[ $question->ID() ] |
|
108 | - : ''; |
|
109 | - $new_answer = EE_Answer::new_instance( |
|
110 | - array( |
|
111 | - 'QST_ID' => $question->ID(), |
|
112 | - 'REG_ID' => $registration->ID(), |
|
113 | - 'ANS_value' => $old_answer_value, |
|
114 | - ) |
|
115 | - ); |
|
116 | - if (! $new_answer instanceof EE_Answer) { |
|
117 | - throw new UnexpectedEntityException($new_answer, 'EE_Answer'); |
|
118 | - } |
|
119 | - $new_answer->save(); |
|
120 | - return $new_answer; |
|
121 | - } |
|
93 | + /** |
|
94 | + * @param EE_Question $question |
|
95 | + * @param EE_Registration $registration |
|
96 | + * @param $previous_answers |
|
97 | + * @return EE_Answer |
|
98 | + * @throws UnexpectedEntityException |
|
99 | + * @throws EE_Error |
|
100 | + */ |
|
101 | + protected function generateNewAnswer( |
|
102 | + EE_Question $question, |
|
103 | + EE_Registration $registration, |
|
104 | + $previous_answers |
|
105 | + ) { |
|
106 | + $old_answer_value = isset($previous_answers[ $question->ID() ]) |
|
107 | + ? $previous_answers[ $question->ID() ] |
|
108 | + : ''; |
|
109 | + $new_answer = EE_Answer::new_instance( |
|
110 | + array( |
|
111 | + 'QST_ID' => $question->ID(), |
|
112 | + 'REG_ID' => $registration->ID(), |
|
113 | + 'ANS_value' => $old_answer_value, |
|
114 | + ) |
|
115 | + ); |
|
116 | + if (! $new_answer instanceof EE_Answer) { |
|
117 | + throw new UnexpectedEntityException($new_answer, 'EE_Answer'); |
|
118 | + } |
|
119 | + $new_answer->save(); |
|
120 | + return $new_answer; |
|
121 | + } |
|
122 | 122 | |
123 | 123 | |
124 | - /** |
|
125 | - * @param EE_Registration $target_registration |
|
126 | - * @param EE_Registration $registration_to_copy |
|
127 | - * @return bool |
|
128 | - * @throws RuntimeException |
|
129 | - * @throws UnexpectedEntityException |
|
130 | - * @throws EE_Error |
|
131 | - */ |
|
132 | - public function copyPaymentDetails( |
|
133 | - EE_Registration $target_registration, |
|
134 | - EE_Registration $registration_to_copy |
|
135 | - ) { |
|
136 | - $save = false; |
|
137 | - $previous_registration_payments = $registration_to_copy->registration_payments(); |
|
138 | - $new_registration_payment_total = 0; |
|
139 | - $registration_to_copy_total = $registration_to_copy->paid(); |
|
140 | - foreach ($previous_registration_payments as $previous_registration_payment) { |
|
141 | - if ($previous_registration_payment instanceof EE_Registration_Payment |
|
142 | - && $previous_registration_payment->payment() instanceof EE_Payment |
|
143 | - && $previous_registration_payment->payment()->is_approved() |
|
144 | - ) { |
|
145 | - $payment_amount = $previous_registration_payment->amount(); |
|
146 | - $new_registration_payment = EE_Registration_Payment::new_instance( |
|
147 | - array( |
|
148 | - 'REG_ID' => $target_registration->ID(), |
|
149 | - 'PAY_ID' => $previous_registration_payment->payment()->ID(), |
|
150 | - 'RPY_amount' => $payment_amount, |
|
151 | - ) |
|
152 | - ); |
|
153 | - if (! $new_registration_payment instanceof EE_Registration_Payment) { |
|
154 | - throw new UnexpectedEntityException($new_registration_payment, 'EE_Registration_Payment'); |
|
155 | - } |
|
156 | - $new_registration_payment->save(); |
|
157 | - // if new reg payment is good, then set old reg payment amount to zero |
|
158 | - $previous_registration_payment->set_amount(0); |
|
159 | - $previous_registration_payment->save(); |
|
160 | - // now increment/decrement payment amounts |
|
161 | - $new_registration_payment_total += $payment_amount; |
|
162 | - $registration_to_copy_total -= $payment_amount; |
|
163 | - $save = true; |
|
164 | - } |
|
165 | - } |
|
166 | - if ($save) { |
|
167 | - $target_registration->set_paid($new_registration_payment_total); |
|
168 | - $target_registration->save(); |
|
169 | - $registration_to_copy->set_paid($registration_to_copy_total); |
|
170 | - $registration_to_copy->save(); |
|
171 | - } |
|
172 | - return true; |
|
173 | - } |
|
124 | + /** |
|
125 | + * @param EE_Registration $target_registration |
|
126 | + * @param EE_Registration $registration_to_copy |
|
127 | + * @return bool |
|
128 | + * @throws RuntimeException |
|
129 | + * @throws UnexpectedEntityException |
|
130 | + * @throws EE_Error |
|
131 | + */ |
|
132 | + public function copyPaymentDetails( |
|
133 | + EE_Registration $target_registration, |
|
134 | + EE_Registration $registration_to_copy |
|
135 | + ) { |
|
136 | + $save = false; |
|
137 | + $previous_registration_payments = $registration_to_copy->registration_payments(); |
|
138 | + $new_registration_payment_total = 0; |
|
139 | + $registration_to_copy_total = $registration_to_copy->paid(); |
|
140 | + foreach ($previous_registration_payments as $previous_registration_payment) { |
|
141 | + if ($previous_registration_payment instanceof EE_Registration_Payment |
|
142 | + && $previous_registration_payment->payment() instanceof EE_Payment |
|
143 | + && $previous_registration_payment->payment()->is_approved() |
|
144 | + ) { |
|
145 | + $payment_amount = $previous_registration_payment->amount(); |
|
146 | + $new_registration_payment = EE_Registration_Payment::new_instance( |
|
147 | + array( |
|
148 | + 'REG_ID' => $target_registration->ID(), |
|
149 | + 'PAY_ID' => $previous_registration_payment->payment()->ID(), |
|
150 | + 'RPY_amount' => $payment_amount, |
|
151 | + ) |
|
152 | + ); |
|
153 | + if (! $new_registration_payment instanceof EE_Registration_Payment) { |
|
154 | + throw new UnexpectedEntityException($new_registration_payment, 'EE_Registration_Payment'); |
|
155 | + } |
|
156 | + $new_registration_payment->save(); |
|
157 | + // if new reg payment is good, then set old reg payment amount to zero |
|
158 | + $previous_registration_payment->set_amount(0); |
|
159 | + $previous_registration_payment->save(); |
|
160 | + // now increment/decrement payment amounts |
|
161 | + $new_registration_payment_total += $payment_amount; |
|
162 | + $registration_to_copy_total -= $payment_amount; |
|
163 | + $save = true; |
|
164 | + } |
|
165 | + } |
|
166 | + if ($save) { |
|
167 | + $target_registration->set_paid($new_registration_payment_total); |
|
168 | + $target_registration->save(); |
|
169 | + $registration_to_copy->set_paid($registration_to_copy_total); |
|
170 | + $registration_to_copy->save(); |
|
171 | + } |
|
172 | + return true; |
|
173 | + } |
|
174 | 174 | } |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | $reindexed_answers = array(); |
84 | 84 | foreach ($answers as $answer) { |
85 | 85 | if ($answer instanceof EE_Answer) { |
86 | - $reindexed_answers[ $answer->question_ID() ] = $answer->value(); |
|
86 | + $reindexed_answers[$answer->question_ID()] = $answer->value(); |
|
87 | 87 | } |
88 | 88 | } |
89 | 89 | return $reindexed_answers; |
@@ -103,8 +103,8 @@ discard block |
||
103 | 103 | EE_Registration $registration, |
104 | 104 | $previous_answers |
105 | 105 | ) { |
106 | - $old_answer_value = isset($previous_answers[ $question->ID() ]) |
|
107 | - ? $previous_answers[ $question->ID() ] |
|
106 | + $old_answer_value = isset($previous_answers[$question->ID()]) |
|
107 | + ? $previous_answers[$question->ID()] |
|
108 | 108 | : ''; |
109 | 109 | $new_answer = EE_Answer::new_instance( |
110 | 110 | array( |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | 'ANS_value' => $old_answer_value, |
114 | 114 | ) |
115 | 115 | ); |
116 | - if (! $new_answer instanceof EE_Answer) { |
|
116 | + if ( ! $new_answer instanceof EE_Answer) { |
|
117 | 117 | throw new UnexpectedEntityException($new_answer, 'EE_Answer'); |
118 | 118 | } |
119 | 119 | $new_answer->save(); |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | 'RPY_amount' => $payment_amount, |
151 | 151 | ) |
152 | 152 | ); |
153 | - if (! $new_registration_payment instanceof EE_Registration_Payment) { |
|
153 | + if ( ! $new_registration_payment instanceof EE_Registration_Payment) { |
|
154 | 154 | throw new UnexpectedEntityException($new_registration_payment, 'EE_Registration_Payment'); |
155 | 155 | } |
156 | 156 | $new_registration_payment->save(); |
@@ -15,293 +15,293 @@ |
||
15 | 15 | class StatsGatherer |
16 | 16 | { |
17 | 17 | |
18 | - const COUNT_ALL_EVENTS = 'event'; |
|
19 | - const COUNT_ACTIVE_EVENTS = 'active_event'; |
|
20 | - const COUNT_DATETIMES = 'datetime'; |
|
21 | - const COUNT_TICKETS = 'ticket'; |
|
22 | - const COUNT_DATETIMES_SOLD = 'datetime_sold'; |
|
23 | - const COUNT_TICKETS_FREE = 'free_ticket'; |
|
24 | - const COUNT_TICKETS_PAID = 'paid_ticket'; |
|
25 | - const COUNT_TICKETS_SOLD = 'ticket_sold'; |
|
26 | - const COUNT_REGISTRATIONS_APPROVED = 'registrations_approved'; |
|
27 | - const COUNT_REGISTRATIONS_NOT_APPROVED = 'registrations_not_approved'; |
|
28 | - const COUNT_REGISTRATIONS_PENDING = 'registrations_pending'; |
|
29 | - const COUNT_REGISTRATIONS_INCOMPLETE = 'registrations_incomplete'; |
|
30 | - const COUNT_REGISTRATIONS_ALL = 'registrations_all'; |
|
31 | - const COUNT_REGISTRATIONS_CANCELLED = 'registrations_cancelled'; |
|
32 | - const COUNT_REGISTRATIONS_DECLINED = 'registrations_declined'; |
|
33 | - const SUM_TRANSACTIONS_COMPLETE_TOTAL = 'transactions_complete_total_sum'; |
|
34 | - const SUM_TRANSACTIONS_ALL_PAID = 'transactions_all_paid'; |
|
35 | - const INFO_SITE_CURRENCY = 'site_currency'; |
|
18 | + const COUNT_ALL_EVENTS = 'event'; |
|
19 | + const COUNT_ACTIVE_EVENTS = 'active_event'; |
|
20 | + const COUNT_DATETIMES = 'datetime'; |
|
21 | + const COUNT_TICKETS = 'ticket'; |
|
22 | + const COUNT_DATETIMES_SOLD = 'datetime_sold'; |
|
23 | + const COUNT_TICKETS_FREE = 'free_ticket'; |
|
24 | + const COUNT_TICKETS_PAID = 'paid_ticket'; |
|
25 | + const COUNT_TICKETS_SOLD = 'ticket_sold'; |
|
26 | + const COUNT_REGISTRATIONS_APPROVED = 'registrations_approved'; |
|
27 | + const COUNT_REGISTRATIONS_NOT_APPROVED = 'registrations_not_approved'; |
|
28 | + const COUNT_REGISTRATIONS_PENDING = 'registrations_pending'; |
|
29 | + const COUNT_REGISTRATIONS_INCOMPLETE = 'registrations_incomplete'; |
|
30 | + const COUNT_REGISTRATIONS_ALL = 'registrations_all'; |
|
31 | + const COUNT_REGISTRATIONS_CANCELLED = 'registrations_cancelled'; |
|
32 | + const COUNT_REGISTRATIONS_DECLINED = 'registrations_declined'; |
|
33 | + const SUM_TRANSACTIONS_COMPLETE_TOTAL = 'transactions_complete_total_sum'; |
|
34 | + const SUM_TRANSACTIONS_ALL_PAID = 'transactions_all_paid'; |
|
35 | + const INFO_SITE_CURRENCY = 'site_currency'; |
|
36 | 36 | |
37 | 37 | |
38 | - /** |
|
39 | - * @var EEM_Payment_Method |
|
40 | - */ |
|
41 | - private $payment_method_model; |
|
38 | + /** |
|
39 | + * @var EEM_Payment_Method |
|
40 | + */ |
|
41 | + private $payment_method_model; |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * @var EEM_Event |
|
46 | - */ |
|
47 | - private $event_model; |
|
44 | + /** |
|
45 | + * @var EEM_Event |
|
46 | + */ |
|
47 | + private $event_model; |
|
48 | 48 | |
49 | - /** |
|
50 | - * @var EEM_Datetime |
|
51 | - */ |
|
52 | - private $datetime_model; |
|
49 | + /** |
|
50 | + * @var EEM_Datetime |
|
51 | + */ |
|
52 | + private $datetime_model; |
|
53 | 53 | |
54 | 54 | |
55 | - /** |
|
56 | - * @var EEM_Ticket |
|
57 | - */ |
|
58 | - private $ticket_model; |
|
55 | + /** |
|
56 | + * @var EEM_Ticket |
|
57 | + */ |
|
58 | + private $ticket_model; |
|
59 | 59 | |
60 | 60 | |
61 | - /** |
|
62 | - * @var EEM_Registration |
|
63 | - */ |
|
64 | - private $registration_model; |
|
61 | + /** |
|
62 | + * @var EEM_Registration |
|
63 | + */ |
|
64 | + private $registration_model; |
|
65 | 65 | |
66 | 66 | |
67 | - /** |
|
68 | - * @var EEM_Transaction |
|
69 | - */ |
|
70 | - private $transaction_model; |
|
67 | + /** |
|
68 | + * @var EEM_Transaction |
|
69 | + */ |
|
70 | + private $transaction_model; |
|
71 | 71 | |
72 | 72 | |
73 | - /** |
|
74 | - * @var EE_Config |
|
75 | - */ |
|
76 | - private $config; |
|
73 | + /** |
|
74 | + * @var EE_Config |
|
75 | + */ |
|
76 | + private $config; |
|
77 | 77 | |
78 | 78 | |
79 | - /** |
|
80 | - * StatsGatherer constructor. |
|
81 | - * |
|
82 | - * @param EEM_Payment_Method $payment_method_model |
|
83 | - * @param EEM_Event $event_model |
|
84 | - * @param EEM_Datetime $datetime_model |
|
85 | - * @param EEM_Ticket $ticket_model |
|
86 | - * @param EEM_Registration $registration_model |
|
87 | - * @param EEM_Transaction $transaction_model |
|
88 | - * @param EE_Config $config |
|
89 | - */ |
|
90 | - public function __construct( |
|
91 | - EEM_Payment_Method $payment_method_model, |
|
92 | - EEM_Event $event_model, |
|
93 | - EEM_Datetime $datetime_model, |
|
94 | - EEM_Ticket $ticket_model, |
|
95 | - EEM_Registration $registration_model, |
|
96 | - EEM_Transaction $transaction_model, |
|
97 | - EE_Config $config |
|
98 | - ) { |
|
99 | - $this->payment_method_model = $payment_method_model; |
|
100 | - $this->event_model = $event_model; |
|
101 | - $this->datetime_model = $datetime_model; |
|
102 | - $this->ticket_model = $ticket_model; |
|
103 | - $this->registration_model = $registration_model; |
|
104 | - $this->transaction_model = $transaction_model; |
|
105 | - $this->config = $config; |
|
106 | - } |
|
79 | + /** |
|
80 | + * StatsGatherer constructor. |
|
81 | + * |
|
82 | + * @param EEM_Payment_Method $payment_method_model |
|
83 | + * @param EEM_Event $event_model |
|
84 | + * @param EEM_Datetime $datetime_model |
|
85 | + * @param EEM_Ticket $ticket_model |
|
86 | + * @param EEM_Registration $registration_model |
|
87 | + * @param EEM_Transaction $transaction_model |
|
88 | + * @param EE_Config $config |
|
89 | + */ |
|
90 | + public function __construct( |
|
91 | + EEM_Payment_Method $payment_method_model, |
|
92 | + EEM_Event $event_model, |
|
93 | + EEM_Datetime $datetime_model, |
|
94 | + EEM_Ticket $ticket_model, |
|
95 | + EEM_Registration $registration_model, |
|
96 | + EEM_Transaction $transaction_model, |
|
97 | + EE_Config $config |
|
98 | + ) { |
|
99 | + $this->payment_method_model = $payment_method_model; |
|
100 | + $this->event_model = $event_model; |
|
101 | + $this->datetime_model = $datetime_model; |
|
102 | + $this->ticket_model = $ticket_model; |
|
103 | + $this->registration_model = $registration_model; |
|
104 | + $this->transaction_model = $transaction_model; |
|
105 | + $this->config = $config; |
|
106 | + } |
|
107 | 107 | |
108 | 108 | |
109 | - /** |
|
110 | - * Return the stats array for PUE UXIP stats. |
|
111 | - * |
|
112 | - * @return array |
|
113 | - */ |
|
114 | - public function stats() |
|
115 | - { |
|
116 | - $stats = $this->paymentMethodStats(); |
|
117 | - // a-ok so let's setup our stats. |
|
118 | - $stats = array_merge($stats, array( |
|
119 | - 'is_multisite' => is_multisite() && is_main_site(), |
|
120 | - 'active_theme' => $this->getActiveThemeStat(), |
|
121 | - 'ee4_all_events_count' => $this->getCountFor(self::COUNT_ALL_EVENTS), |
|
122 | - 'ee4_active_events_count' => $this->getCountFor(self::COUNT_ACTIVE_EVENTS), |
|
123 | - 'all_dtts_count' => $this->getCountFor(self::COUNT_DATETIMES), |
|
124 | - 'dtt_sold' => $this->getCountFor(self::COUNT_DATETIMES_SOLD), |
|
125 | - 'all_tkt_count' => $this->getCountFor(self::COUNT_TICKETS), |
|
126 | - 'free_tkt_count' => $this->getCountFor(self::COUNT_TICKETS_FREE), |
|
127 | - 'paid_tkt_count' => $this->getCountFor(self::COUNT_TICKETS_PAID), |
|
128 | - 'tkt_sold' => $this->getCountFor(self::COUNT_TICKETS_SOLD), |
|
129 | - 'approve_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_APPROVED), |
|
130 | - 'pending_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_PENDING), |
|
131 | - 'not_approved_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_NOT_APPROVED), |
|
132 | - 'incomplete_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_INCOMPLETE), |
|
133 | - 'cancelled_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_CANCELLED), |
|
134 | - 'declined_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_DECLINED), |
|
135 | - 'all_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_ALL), |
|
136 | - 'completed_transaction_total_sum' => $this->getCountFor(self::SUM_TRANSACTIONS_COMPLETE_TOTAL), |
|
137 | - 'all_transaction_paid_sum' => $this->getCountFor(self::SUM_TRANSACTIONS_ALL_PAID), |
|
138 | - self::INFO_SITE_CURRENCY => $this->config->currency instanceof EE_Currency_Config |
|
139 | - ? $this->config->currency->code |
|
140 | - : 'unknown', |
|
141 | - 'phpversion' => implode( |
|
142 | - '.', |
|
143 | - array(PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION) |
|
144 | - ), |
|
145 | - )); |
|
146 | - // remove any values that equal null. This ensures any stats that weren't retrieved successfully are excluded. |
|
147 | - return array_filter($stats, function ($value) { |
|
148 | - return $value !== null; |
|
149 | - }); |
|
150 | - } |
|
109 | + /** |
|
110 | + * Return the stats array for PUE UXIP stats. |
|
111 | + * |
|
112 | + * @return array |
|
113 | + */ |
|
114 | + public function stats() |
|
115 | + { |
|
116 | + $stats = $this->paymentMethodStats(); |
|
117 | + // a-ok so let's setup our stats. |
|
118 | + $stats = array_merge($stats, array( |
|
119 | + 'is_multisite' => is_multisite() && is_main_site(), |
|
120 | + 'active_theme' => $this->getActiveThemeStat(), |
|
121 | + 'ee4_all_events_count' => $this->getCountFor(self::COUNT_ALL_EVENTS), |
|
122 | + 'ee4_active_events_count' => $this->getCountFor(self::COUNT_ACTIVE_EVENTS), |
|
123 | + 'all_dtts_count' => $this->getCountFor(self::COUNT_DATETIMES), |
|
124 | + 'dtt_sold' => $this->getCountFor(self::COUNT_DATETIMES_SOLD), |
|
125 | + 'all_tkt_count' => $this->getCountFor(self::COUNT_TICKETS), |
|
126 | + 'free_tkt_count' => $this->getCountFor(self::COUNT_TICKETS_FREE), |
|
127 | + 'paid_tkt_count' => $this->getCountFor(self::COUNT_TICKETS_PAID), |
|
128 | + 'tkt_sold' => $this->getCountFor(self::COUNT_TICKETS_SOLD), |
|
129 | + 'approve_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_APPROVED), |
|
130 | + 'pending_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_PENDING), |
|
131 | + 'not_approved_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_NOT_APPROVED), |
|
132 | + 'incomplete_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_INCOMPLETE), |
|
133 | + 'cancelled_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_CANCELLED), |
|
134 | + 'declined_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_DECLINED), |
|
135 | + 'all_registration_count' => $this->getCountFor(self::COUNT_REGISTRATIONS_ALL), |
|
136 | + 'completed_transaction_total_sum' => $this->getCountFor(self::SUM_TRANSACTIONS_COMPLETE_TOTAL), |
|
137 | + 'all_transaction_paid_sum' => $this->getCountFor(self::SUM_TRANSACTIONS_ALL_PAID), |
|
138 | + self::INFO_SITE_CURRENCY => $this->config->currency instanceof EE_Currency_Config |
|
139 | + ? $this->config->currency->code |
|
140 | + : 'unknown', |
|
141 | + 'phpversion' => implode( |
|
142 | + '.', |
|
143 | + array(PHP_MAJOR_VERSION, PHP_MINOR_VERSION, PHP_RELEASE_VERSION) |
|
144 | + ), |
|
145 | + )); |
|
146 | + // remove any values that equal null. This ensures any stats that weren't retrieved successfully are excluded. |
|
147 | + return array_filter($stats, function ($value) { |
|
148 | + return $value !== null; |
|
149 | + }); |
|
150 | + } |
|
151 | 151 | |
152 | - /** |
|
153 | - * @param string $which enum (@see constants prefixed with COUNT) |
|
154 | - * @return int|null |
|
155 | - */ |
|
156 | - private function getCountFor($which) |
|
157 | - { |
|
158 | - try { |
|
159 | - switch ($which) { |
|
160 | - case self::COUNT_ALL_EVENTS: |
|
161 | - $count = $this->event_model->count(); |
|
162 | - break; |
|
163 | - case self::COUNT_TICKETS: |
|
164 | - $count = $this->ticket_model->count(); |
|
165 | - break; |
|
166 | - case self::COUNT_DATETIMES: |
|
167 | - $count = $this->datetime_model->count(); |
|
168 | - break; |
|
169 | - case self::COUNT_ACTIVE_EVENTS: |
|
170 | - $count = $this->event_model->get_active_events(array(), true); |
|
171 | - break; |
|
172 | - case self::COUNT_DATETIMES_SOLD: |
|
173 | - $count = $this->datetime_model->sum(array(), 'DTT_sold'); |
|
174 | - break; |
|
175 | - case self::COUNT_TICKETS_FREE: |
|
176 | - $count = $this->ticket_model->count(array( |
|
177 | - array( |
|
178 | - 'TKT_price' => 0, |
|
179 | - ), |
|
180 | - )); |
|
181 | - break; |
|
182 | - case self::COUNT_TICKETS_PAID: |
|
183 | - $count = $this->ticket_model->count(array( |
|
184 | - array( |
|
185 | - 'TKT_price' => array('>', 0), |
|
186 | - ), |
|
187 | - )); |
|
188 | - break; |
|
189 | - case self::COUNT_TICKETS_SOLD: |
|
190 | - $count = $this->ticket_model->sum(array(), 'TKT_sold'); |
|
191 | - break; |
|
192 | - case self::COUNT_REGISTRATIONS_ALL: |
|
193 | - $count = $this->registration_model->count(); |
|
194 | - break; |
|
195 | - case self::COUNT_REGISTRATIONS_CANCELLED: |
|
196 | - $count = $this->registration_model->count( |
|
197 | - array( |
|
198 | - array( |
|
199 | - 'STS_ID' => EEM_Registration::status_id_cancelled, |
|
200 | - ), |
|
201 | - ) |
|
202 | - ); |
|
203 | - break; |
|
204 | - case self::COUNT_REGISTRATIONS_INCOMPLETE: |
|
205 | - $count = $this->registration_model->count( |
|
206 | - array( |
|
207 | - array( |
|
208 | - 'STS_ID' => EEM_Registration::status_id_incomplete, |
|
209 | - ), |
|
210 | - ) |
|
211 | - ); |
|
212 | - break; |
|
213 | - case self::COUNT_REGISTRATIONS_NOT_APPROVED: |
|
214 | - $count = $this->registration_model->count( |
|
215 | - array( |
|
216 | - array( |
|
217 | - 'STS_ID' => EEM_Registration::status_id_not_approved, |
|
218 | - ), |
|
219 | - ) |
|
220 | - ); |
|
221 | - break; |
|
222 | - case self::COUNT_REGISTRATIONS_DECLINED: |
|
223 | - $count = $this->registration_model->count( |
|
224 | - array( |
|
225 | - array( |
|
226 | - 'STS_ID' => EEM_Registration::status_id_declined, |
|
227 | - ), |
|
228 | - ) |
|
229 | - ); |
|
230 | - break; |
|
231 | - case self::COUNT_REGISTRATIONS_PENDING: |
|
232 | - $count = $this->registration_model->count( |
|
233 | - array( |
|
234 | - array( |
|
235 | - 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
236 | - ), |
|
237 | - ) |
|
238 | - ); |
|
239 | - break; |
|
240 | - case self::COUNT_REGISTRATIONS_APPROVED: |
|
241 | - $count = $this->registration_model->count( |
|
242 | - array( |
|
243 | - array( |
|
244 | - 'STS_ID' => EEM_Registration::status_id_approved, |
|
245 | - ), |
|
246 | - ) |
|
247 | - ); |
|
248 | - break; |
|
249 | - case self::SUM_TRANSACTIONS_COMPLETE_TOTAL: |
|
250 | - $count = $this->transaction_model->sum( |
|
251 | - array( |
|
252 | - array( |
|
253 | - 'STS_ID' => EEM_Transaction::complete_status_code, |
|
254 | - ), |
|
255 | - ), |
|
256 | - 'TXN_total' |
|
257 | - ); |
|
258 | - break; |
|
259 | - case self::SUM_TRANSACTIONS_ALL_PAID: |
|
260 | - $count = $this->transaction_model->sum( |
|
261 | - array(), |
|
262 | - 'TXN_paid' |
|
263 | - ); |
|
264 | - break; |
|
265 | - default: |
|
266 | - $count = null; |
|
267 | - break; |
|
268 | - } |
|
269 | - } catch (Exception $e) { |
|
270 | - $count = null; |
|
271 | - } |
|
272 | - return $count; |
|
273 | - } |
|
152 | + /** |
|
153 | + * @param string $which enum (@see constants prefixed with COUNT) |
|
154 | + * @return int|null |
|
155 | + */ |
|
156 | + private function getCountFor($which) |
|
157 | + { |
|
158 | + try { |
|
159 | + switch ($which) { |
|
160 | + case self::COUNT_ALL_EVENTS: |
|
161 | + $count = $this->event_model->count(); |
|
162 | + break; |
|
163 | + case self::COUNT_TICKETS: |
|
164 | + $count = $this->ticket_model->count(); |
|
165 | + break; |
|
166 | + case self::COUNT_DATETIMES: |
|
167 | + $count = $this->datetime_model->count(); |
|
168 | + break; |
|
169 | + case self::COUNT_ACTIVE_EVENTS: |
|
170 | + $count = $this->event_model->get_active_events(array(), true); |
|
171 | + break; |
|
172 | + case self::COUNT_DATETIMES_SOLD: |
|
173 | + $count = $this->datetime_model->sum(array(), 'DTT_sold'); |
|
174 | + break; |
|
175 | + case self::COUNT_TICKETS_FREE: |
|
176 | + $count = $this->ticket_model->count(array( |
|
177 | + array( |
|
178 | + 'TKT_price' => 0, |
|
179 | + ), |
|
180 | + )); |
|
181 | + break; |
|
182 | + case self::COUNT_TICKETS_PAID: |
|
183 | + $count = $this->ticket_model->count(array( |
|
184 | + array( |
|
185 | + 'TKT_price' => array('>', 0), |
|
186 | + ), |
|
187 | + )); |
|
188 | + break; |
|
189 | + case self::COUNT_TICKETS_SOLD: |
|
190 | + $count = $this->ticket_model->sum(array(), 'TKT_sold'); |
|
191 | + break; |
|
192 | + case self::COUNT_REGISTRATIONS_ALL: |
|
193 | + $count = $this->registration_model->count(); |
|
194 | + break; |
|
195 | + case self::COUNT_REGISTRATIONS_CANCELLED: |
|
196 | + $count = $this->registration_model->count( |
|
197 | + array( |
|
198 | + array( |
|
199 | + 'STS_ID' => EEM_Registration::status_id_cancelled, |
|
200 | + ), |
|
201 | + ) |
|
202 | + ); |
|
203 | + break; |
|
204 | + case self::COUNT_REGISTRATIONS_INCOMPLETE: |
|
205 | + $count = $this->registration_model->count( |
|
206 | + array( |
|
207 | + array( |
|
208 | + 'STS_ID' => EEM_Registration::status_id_incomplete, |
|
209 | + ), |
|
210 | + ) |
|
211 | + ); |
|
212 | + break; |
|
213 | + case self::COUNT_REGISTRATIONS_NOT_APPROVED: |
|
214 | + $count = $this->registration_model->count( |
|
215 | + array( |
|
216 | + array( |
|
217 | + 'STS_ID' => EEM_Registration::status_id_not_approved, |
|
218 | + ), |
|
219 | + ) |
|
220 | + ); |
|
221 | + break; |
|
222 | + case self::COUNT_REGISTRATIONS_DECLINED: |
|
223 | + $count = $this->registration_model->count( |
|
224 | + array( |
|
225 | + array( |
|
226 | + 'STS_ID' => EEM_Registration::status_id_declined, |
|
227 | + ), |
|
228 | + ) |
|
229 | + ); |
|
230 | + break; |
|
231 | + case self::COUNT_REGISTRATIONS_PENDING: |
|
232 | + $count = $this->registration_model->count( |
|
233 | + array( |
|
234 | + array( |
|
235 | + 'STS_ID' => EEM_Registration::status_id_pending_payment, |
|
236 | + ), |
|
237 | + ) |
|
238 | + ); |
|
239 | + break; |
|
240 | + case self::COUNT_REGISTRATIONS_APPROVED: |
|
241 | + $count = $this->registration_model->count( |
|
242 | + array( |
|
243 | + array( |
|
244 | + 'STS_ID' => EEM_Registration::status_id_approved, |
|
245 | + ), |
|
246 | + ) |
|
247 | + ); |
|
248 | + break; |
|
249 | + case self::SUM_TRANSACTIONS_COMPLETE_TOTAL: |
|
250 | + $count = $this->transaction_model->sum( |
|
251 | + array( |
|
252 | + array( |
|
253 | + 'STS_ID' => EEM_Transaction::complete_status_code, |
|
254 | + ), |
|
255 | + ), |
|
256 | + 'TXN_total' |
|
257 | + ); |
|
258 | + break; |
|
259 | + case self::SUM_TRANSACTIONS_ALL_PAID: |
|
260 | + $count = $this->transaction_model->sum( |
|
261 | + array(), |
|
262 | + 'TXN_paid' |
|
263 | + ); |
|
264 | + break; |
|
265 | + default: |
|
266 | + $count = null; |
|
267 | + break; |
|
268 | + } |
|
269 | + } catch (Exception $e) { |
|
270 | + $count = null; |
|
271 | + } |
|
272 | + return $count; |
|
273 | + } |
|
274 | 274 | |
275 | - /** |
|
276 | - * Return the active theme. |
|
277 | - * |
|
278 | - * @return false|string |
|
279 | - */ |
|
280 | - private function getActiveThemeStat() |
|
281 | - { |
|
282 | - $theme = wp_get_theme(); |
|
283 | - return $theme->get('Name'); |
|
284 | - } |
|
275 | + /** |
|
276 | + * Return the active theme. |
|
277 | + * |
|
278 | + * @return false|string |
|
279 | + */ |
|
280 | + private function getActiveThemeStat() |
|
281 | + { |
|
282 | + $theme = wp_get_theme(); |
|
283 | + return $theme->get('Name'); |
|
284 | + } |
|
285 | 285 | |
286 | - /** |
|
287 | - * @return array |
|
288 | - */ |
|
289 | - private function paymentMethodStats() |
|
290 | - { |
|
291 | - $payment_method_stats = array(); |
|
292 | - try { |
|
293 | - $active_payment_methods = $this->payment_method_model->get_all_active( |
|
294 | - null, |
|
295 | - array('group_by' => 'PMD_type') |
|
296 | - ); |
|
297 | - if ($active_payment_methods) { |
|
298 | - foreach ($active_payment_methods as $payment_method) { |
|
299 | - $payment_method_stats[ $payment_method->name() . '_active_payment_method' ] = 1; |
|
300 | - } |
|
301 | - } |
|
302 | - } catch (Exception $e) { |
|
303 | - // do nothing just prevents fatals. |
|
304 | - } |
|
305 | - return $payment_method_stats; |
|
306 | - } |
|
286 | + /** |
|
287 | + * @return array |
|
288 | + */ |
|
289 | + private function paymentMethodStats() |
|
290 | + { |
|
291 | + $payment_method_stats = array(); |
|
292 | + try { |
|
293 | + $active_payment_methods = $this->payment_method_model->get_all_active( |
|
294 | + null, |
|
295 | + array('group_by' => 'PMD_type') |
|
296 | + ); |
|
297 | + if ($active_payment_methods) { |
|
298 | + foreach ($active_payment_methods as $payment_method) { |
|
299 | + $payment_method_stats[ $payment_method->name() . '_active_payment_method' ] = 1; |
|
300 | + } |
|
301 | + } |
|
302 | + } catch (Exception $e) { |
|
303 | + // do nothing just prevents fatals. |
|
304 | + } |
|
305 | + return $payment_method_stats; |
|
306 | + } |
|
307 | 307 | } |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | ), |
145 | 145 | )); |
146 | 146 | // remove any values that equal null. This ensures any stats that weren't retrieved successfully are excluded. |
147 | - return array_filter($stats, function ($value) { |
|
147 | + return array_filter($stats, function($value) { |
|
148 | 148 | return $value !== null; |
149 | 149 | }); |
150 | 150 | } |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | ); |
297 | 297 | if ($active_payment_methods) { |
298 | 298 | foreach ($active_payment_methods as $payment_method) { |
299 | - $payment_method_stats[ $payment_method->name() . '_active_payment_method' ] = 1; |
|
299 | + $payment_method_stats[$payment_method->name().'_active_payment_method'] = 1; |
|
300 | 300 | } |
301 | 301 | } |
302 | 302 | } catch (Exception $e) { |
@@ -76,9 +76,9 @@ discard block |
||
76 | 76 | public function statsCallback() |
77 | 77 | { |
78 | 78 | // returns a callback that can is used to retrieve the stats to send along to the pue server. |
79 | - return function () { |
|
79 | + return function() { |
|
80 | 80 | // we only send stats one a week, so let's see if our stat timestamp has expired. |
81 | - if (! $this->sendStats()) { |
|
81 | + if ( ! $this->sendStats()) { |
|
82 | 82 | return array(); |
83 | 83 | } |
84 | 84 | return $this->stats_gatherer->stats(); |
@@ -126,9 +126,9 @@ discard block |
||
126 | 126 | */ |
127 | 127 | public static function optinText($extra = true) |
128 | 128 | { |
129 | - if (! $extra) { |
|
129 | + if ( ! $extra) { |
|
130 | 130 | echo '<h2 class="ee-admin-settings-hdr" ' |
131 | - . (! $extra ? 'id="UXIP_settings"' : '') |
|
131 | + . ( ! $extra ? 'id="UXIP_settings"' : '') |
|
132 | 132 | . '>' |
133 | 133 | . esc_html__('User eXperience Improvement Program (UXIP)', 'event_espresso') |
134 | 134 | . EEH_Template::get_help_tab_link('organization_logo_info') |
@@ -159,7 +159,7 @@ discard block |
||
159 | 159 | ), |
160 | 160 | '<a href="https://eventespresso.com/about/user-experience-improvement-program-uxip/" target="_blank">', |
161 | 161 | '</a>', |
162 | - '<a href="' . $settings_url . '" target="_blank">', |
|
162 | + '<a href="'.$settings_url.'" target="_blank">', |
|
163 | 163 | '</a>' |
164 | 164 | ); |
165 | 165 | } |
@@ -173,14 +173,14 @@ discard block |
||
173 | 173 | { |
174 | 174 | wp_register_script( |
175 | 175 | 'ee-data-optin-js', |
176 | - EE_GLOBAL_ASSETS_URL . 'scripts/ee-data-optin.js', |
|
176 | + EE_GLOBAL_ASSETS_URL.'scripts/ee-data-optin.js', |
|
177 | 177 | array('jquery'), |
178 | 178 | EVENT_ESPRESSO_VERSION, |
179 | 179 | true |
180 | 180 | ); |
181 | 181 | wp_register_style( |
182 | 182 | 'ee-data-optin-css', |
183 | - EE_GLOBAL_ASSETS_URL . 'css/ee-data-optin.css', |
|
183 | + EE_GLOBAL_ASSETS_URL.'css/ee-data-optin.css', |
|
184 | 184 | array(), |
185 | 185 | EVENT_ESPRESSO_VERSION |
186 | 186 | ); |
@@ -22,86 +22,86 @@ discard block |
||
22 | 22 | class Stats |
23 | 23 | { |
24 | 24 | |
25 | - const OPTIONS_KEY_EXPIRY_TIMESTAMP_FOR_SENDING_STATS = 'ee_uxip_stats_expiry'; |
|
26 | - |
|
27 | - /** |
|
28 | - * @var Config |
|
29 | - */ |
|
30 | - private $config; |
|
31 | - |
|
32 | - |
|
33 | - /** |
|
34 | - * @var StatsGatherer |
|
35 | - */ |
|
36 | - private $stats_gatherer; |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * @var EE_Maintenance_Mode |
|
41 | - */ |
|
42 | - private $maintenance_mode; |
|
43 | - |
|
44 | - public function __construct( |
|
45 | - Config $config, |
|
46 | - EE_Maintenance_Mode $maintenance_mode, |
|
47 | - StatsGatherer $stats_gatherer |
|
48 | - ) { |
|
49 | - $this->config = $config; |
|
50 | - $this->maintenance_mode = $maintenance_mode; |
|
51 | - $this->stats_gatherer = $stats_gatherer; |
|
52 | - $this->setUxipNotices(); |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * Displays uxip opt-in notice if necessary. |
|
58 | - */ |
|
59 | - private function setUxipNotices() |
|
60 | - { |
|
61 | - if ($this->canDisplayNotices()) { |
|
62 | - add_action('admin_notices', array($this, 'optinNotice')); |
|
63 | - add_action('admin_enqueue_scripts', array($this, 'enqueueScripts')); |
|
64 | - add_action('wp_ajax_espresso_data_optin', array($this, 'ajaxHandler')); |
|
65 | - } |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * This returns the callback that PluginUpdateEngineChecker will use for getting any extra stats to send. |
|
71 | - * |
|
72 | - * @return Closure |
|
73 | - */ |
|
74 | - public function statsCallback() |
|
75 | - { |
|
76 | - // returns a callback that can is used to retrieve the stats to send along to the pue server. |
|
77 | - return function () { |
|
78 | - // we only send stats one a week, so let's see if our stat timestamp has expired. |
|
79 | - if (! $this->sendStats()) { |
|
80 | - return array(); |
|
81 | - } |
|
82 | - return $this->stats_gatherer->stats(); |
|
83 | - }; |
|
84 | - } |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * Return whether notices can be displayed or not |
|
89 | - * |
|
90 | - * @return bool |
|
91 | - */ |
|
92 | - private function canDisplayNotices() |
|
93 | - { |
|
94 | - return ! $this->config->hasNotifiedForUxip() |
|
95 | - && $this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance; |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * Callback for the admin_notices hook that outputs the UXIP optin-in notice. |
|
101 | - */ |
|
102 | - public function optinNotice() |
|
103 | - { |
|
104 | - ?> |
|
25 | + const OPTIONS_KEY_EXPIRY_TIMESTAMP_FOR_SENDING_STATS = 'ee_uxip_stats_expiry'; |
|
26 | + |
|
27 | + /** |
|
28 | + * @var Config |
|
29 | + */ |
|
30 | + private $config; |
|
31 | + |
|
32 | + |
|
33 | + /** |
|
34 | + * @var StatsGatherer |
|
35 | + */ |
|
36 | + private $stats_gatherer; |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * @var EE_Maintenance_Mode |
|
41 | + */ |
|
42 | + private $maintenance_mode; |
|
43 | + |
|
44 | + public function __construct( |
|
45 | + Config $config, |
|
46 | + EE_Maintenance_Mode $maintenance_mode, |
|
47 | + StatsGatherer $stats_gatherer |
|
48 | + ) { |
|
49 | + $this->config = $config; |
|
50 | + $this->maintenance_mode = $maintenance_mode; |
|
51 | + $this->stats_gatherer = $stats_gatherer; |
|
52 | + $this->setUxipNotices(); |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * Displays uxip opt-in notice if necessary. |
|
58 | + */ |
|
59 | + private function setUxipNotices() |
|
60 | + { |
|
61 | + if ($this->canDisplayNotices()) { |
|
62 | + add_action('admin_notices', array($this, 'optinNotice')); |
|
63 | + add_action('admin_enqueue_scripts', array($this, 'enqueueScripts')); |
|
64 | + add_action('wp_ajax_espresso_data_optin', array($this, 'ajaxHandler')); |
|
65 | + } |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * This returns the callback that PluginUpdateEngineChecker will use for getting any extra stats to send. |
|
71 | + * |
|
72 | + * @return Closure |
|
73 | + */ |
|
74 | + public function statsCallback() |
|
75 | + { |
|
76 | + // returns a callback that can is used to retrieve the stats to send along to the pue server. |
|
77 | + return function () { |
|
78 | + // we only send stats one a week, so let's see if our stat timestamp has expired. |
|
79 | + if (! $this->sendStats()) { |
|
80 | + return array(); |
|
81 | + } |
|
82 | + return $this->stats_gatherer->stats(); |
|
83 | + }; |
|
84 | + } |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * Return whether notices can be displayed or not |
|
89 | + * |
|
90 | + * @return bool |
|
91 | + */ |
|
92 | + private function canDisplayNotices() |
|
93 | + { |
|
94 | + return ! $this->config->hasNotifiedForUxip() |
|
95 | + && $this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance; |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * Callback for the admin_notices hook that outputs the UXIP optin-in notice. |
|
101 | + */ |
|
102 | + public function optinNotice() |
|
103 | + { |
|
104 | + ?> |
|
105 | 105 | <div class="updated data-collect-optin" id="espresso-data-collect-optin-container"> |
106 | 106 | <div id="data-collect-optin-options-container"> |
107 | 107 | <span class="dashicons dashicons-admin-site"></span> |
@@ -114,125 +114,125 @@ discard block |
||
114 | 114 | </div> |
115 | 115 | </div> |
116 | 116 | <?php |
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - /** |
|
121 | - * Retrieves the optin text (static so it can be used in multiple places as necessary). |
|
122 | - * |
|
123 | - * @param bool $extra |
|
124 | - */ |
|
125 | - public static function optinText($extra = true) |
|
126 | - { |
|
127 | - if (! $extra) { |
|
128 | - echo '<h2 class="ee-admin-settings-hdr" ' |
|
129 | - . (! $extra ? 'id="UXIP_settings"' : '') |
|
130 | - . '>' |
|
131 | - . esc_html__('User eXperience Improvement Program (UXIP)', 'event_espresso') |
|
132 | - . EEH_Template::get_help_tab_link('organization_logo_info') |
|
133 | - . '</h2>'; |
|
134 | - printf( |
|
135 | - esc_html__( |
|
136 | - '%1$sPlease help us make Event Espresso better and vote for your favorite features.%2$s The %3$sUser eXperience Improvement Program (UXIP)%4$s, has been created so when you use Event Espresso you are voting for the features and settings that are important to you. The UXIP helps us understand how you use our products and services, track problems and in what context. If you opt-out of the UXIP you essentially elect for us to disregard how you use Event Espresso as we build new features and make changes. Participation in the program is completely voluntary and it is disabled by default. The end results of the UXIP are software improvements to better meet your needs. The data we collect will never be sold, traded, or misused in any way. %5$sPlease see our %6$sPrivacy Policy%7$s for more information.', |
|
137 | - 'event_espresso' |
|
138 | - ), |
|
139 | - '<p><em>', |
|
140 | - '</em></p>', |
|
141 | - '<a href="https://eventespresso.com/about/user-experience-improvement-program-uxip/" target="_blank">', |
|
142 | - '</a>', |
|
143 | - '<br><br>', |
|
144 | - '<a href="https://eventespresso.com/about/privacy-policy/" target="_blank">', |
|
145 | - '</a>' |
|
146 | - ); |
|
147 | - } else { |
|
148 | - $settings_url = EE_Admin_Page::add_query_args_and_nonce( |
|
149 | - array('action' => 'default'), |
|
150 | - admin_url('admin.php?page=espresso_general_settings') |
|
151 | - ); |
|
152 | - $settings_url .= '#UXIP_settings'; |
|
153 | - printf( |
|
154 | - esc_html__( |
|
155 | - 'The Event Espresso UXIP feature is not yet active on your site. For %1$smore info%2$s and to opt-in %3$sclick here%4$s.', |
|
156 | - 'event_espresso' |
|
157 | - ), |
|
158 | - '<a href="https://eventespresso.com/about/user-experience-improvement-program-uxip/" target="_blank">', |
|
159 | - '</a>', |
|
160 | - '<a href="' . $settings_url . '" target="_blank">', |
|
161 | - '</a>' |
|
162 | - ); |
|
163 | - } |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * Callback for admin_enqueue_scripts that sets up the scripts and styles for the uxip notice |
|
169 | - */ |
|
170 | - public function enqueueScripts() |
|
171 | - { |
|
172 | - wp_register_script( |
|
173 | - 'ee-data-optin-js', |
|
174 | - EE_GLOBAL_ASSETS_URL . 'scripts/ee-data-optin.js', |
|
175 | - array('jquery'), |
|
176 | - EVENT_ESPRESSO_VERSION, |
|
177 | - true |
|
178 | - ); |
|
179 | - wp_register_style( |
|
180 | - 'ee-data-optin-css', |
|
181 | - EE_GLOBAL_ASSETS_URL . 'css/ee-data-optin.css', |
|
182 | - array(), |
|
183 | - EVENT_ESPRESSO_VERSION |
|
184 | - ); |
|
185 | - |
|
186 | - wp_enqueue_script('ee-data-optin-js'); |
|
187 | - wp_enqueue_style('ee-data-optin-css'); |
|
188 | - } |
|
189 | - |
|
190 | - |
|
191 | - /** |
|
192 | - * Callback for wp_ajax_espresso_data_optin that handles the ajax request |
|
193 | - */ |
|
194 | - public function ajaxHandler() |
|
195 | - { |
|
196 | - // verify nonce |
|
197 | - if (isset($_POST['nonce']) && ! wp_verify_nonce($_POST['nonce'], 'ee-data-optin')) { |
|
198 | - exit(); |
|
199 | - } |
|
200 | - |
|
201 | - // update has notified option |
|
202 | - $this->config->setHasNotifiedAboutUxip(); |
|
203 | - exit(); |
|
204 | - } |
|
205 | - |
|
206 | - |
|
207 | - /** |
|
208 | - * Used to determine whether additional stats are sent. |
|
209 | - */ |
|
210 | - private function sendStats() |
|
211 | - { |
|
212 | - return $this->config->isOptedInForUxip() |
|
213 | - && $this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance |
|
214 | - && $this->statSendTimestampExpired(); |
|
215 | - } |
|
216 | - |
|
217 | - |
|
218 | - /** |
|
219 | - * Returns true when the timestamp used to track whether stats get sent (currently a weekly interval) is expired. |
|
220 | - * Returns false otherwise. |
|
221 | - * |
|
222 | - * @return bool |
|
223 | - */ |
|
224 | - private function statSendTimestampExpired() |
|
225 | - { |
|
226 | - $current_expiry = get_option(self::OPTIONS_KEY_EXPIRY_TIMESTAMP_FOR_SENDING_STATS, null); |
|
227 | - if ($current_expiry === null) { |
|
228 | - add_option(self::OPTIONS_KEY_EXPIRY_TIMESTAMP_FOR_SENDING_STATS, time() + WEEK_IN_SECONDS, '', 'no'); |
|
229 | - return true; |
|
230 | - } |
|
231 | - |
|
232 | - if (time() > (int) $current_expiry) { |
|
233 | - update_option(self::OPTIONS_KEY_EXPIRY_TIMESTAMP_FOR_SENDING_STATS, time() + WEEK_IN_SECONDS); |
|
234 | - return true; |
|
235 | - } |
|
236 | - return false; |
|
237 | - } |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + /** |
|
121 | + * Retrieves the optin text (static so it can be used in multiple places as necessary). |
|
122 | + * |
|
123 | + * @param bool $extra |
|
124 | + */ |
|
125 | + public static function optinText($extra = true) |
|
126 | + { |
|
127 | + if (! $extra) { |
|
128 | + echo '<h2 class="ee-admin-settings-hdr" ' |
|
129 | + . (! $extra ? 'id="UXIP_settings"' : '') |
|
130 | + . '>' |
|
131 | + . esc_html__('User eXperience Improvement Program (UXIP)', 'event_espresso') |
|
132 | + . EEH_Template::get_help_tab_link('organization_logo_info') |
|
133 | + . '</h2>'; |
|
134 | + printf( |
|
135 | + esc_html__( |
|
136 | + '%1$sPlease help us make Event Espresso better and vote for your favorite features.%2$s The %3$sUser eXperience Improvement Program (UXIP)%4$s, has been created so when you use Event Espresso you are voting for the features and settings that are important to you. The UXIP helps us understand how you use our products and services, track problems and in what context. If you opt-out of the UXIP you essentially elect for us to disregard how you use Event Espresso as we build new features and make changes. Participation in the program is completely voluntary and it is disabled by default. The end results of the UXIP are software improvements to better meet your needs. The data we collect will never be sold, traded, or misused in any way. %5$sPlease see our %6$sPrivacy Policy%7$s for more information.', |
|
137 | + 'event_espresso' |
|
138 | + ), |
|
139 | + '<p><em>', |
|
140 | + '</em></p>', |
|
141 | + '<a href="https://eventespresso.com/about/user-experience-improvement-program-uxip/" target="_blank">', |
|
142 | + '</a>', |
|
143 | + '<br><br>', |
|
144 | + '<a href="https://eventespresso.com/about/privacy-policy/" target="_blank">', |
|
145 | + '</a>' |
|
146 | + ); |
|
147 | + } else { |
|
148 | + $settings_url = EE_Admin_Page::add_query_args_and_nonce( |
|
149 | + array('action' => 'default'), |
|
150 | + admin_url('admin.php?page=espresso_general_settings') |
|
151 | + ); |
|
152 | + $settings_url .= '#UXIP_settings'; |
|
153 | + printf( |
|
154 | + esc_html__( |
|
155 | + 'The Event Espresso UXIP feature is not yet active on your site. For %1$smore info%2$s and to opt-in %3$sclick here%4$s.', |
|
156 | + 'event_espresso' |
|
157 | + ), |
|
158 | + '<a href="https://eventespresso.com/about/user-experience-improvement-program-uxip/" target="_blank">', |
|
159 | + '</a>', |
|
160 | + '<a href="' . $settings_url . '" target="_blank">', |
|
161 | + '</a>' |
|
162 | + ); |
|
163 | + } |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * Callback for admin_enqueue_scripts that sets up the scripts and styles for the uxip notice |
|
169 | + */ |
|
170 | + public function enqueueScripts() |
|
171 | + { |
|
172 | + wp_register_script( |
|
173 | + 'ee-data-optin-js', |
|
174 | + EE_GLOBAL_ASSETS_URL . 'scripts/ee-data-optin.js', |
|
175 | + array('jquery'), |
|
176 | + EVENT_ESPRESSO_VERSION, |
|
177 | + true |
|
178 | + ); |
|
179 | + wp_register_style( |
|
180 | + 'ee-data-optin-css', |
|
181 | + EE_GLOBAL_ASSETS_URL . 'css/ee-data-optin.css', |
|
182 | + array(), |
|
183 | + EVENT_ESPRESSO_VERSION |
|
184 | + ); |
|
185 | + |
|
186 | + wp_enqueue_script('ee-data-optin-js'); |
|
187 | + wp_enqueue_style('ee-data-optin-css'); |
|
188 | + } |
|
189 | + |
|
190 | + |
|
191 | + /** |
|
192 | + * Callback for wp_ajax_espresso_data_optin that handles the ajax request |
|
193 | + */ |
|
194 | + public function ajaxHandler() |
|
195 | + { |
|
196 | + // verify nonce |
|
197 | + if (isset($_POST['nonce']) && ! wp_verify_nonce($_POST['nonce'], 'ee-data-optin')) { |
|
198 | + exit(); |
|
199 | + } |
|
200 | + |
|
201 | + // update has notified option |
|
202 | + $this->config->setHasNotifiedAboutUxip(); |
|
203 | + exit(); |
|
204 | + } |
|
205 | + |
|
206 | + |
|
207 | + /** |
|
208 | + * Used to determine whether additional stats are sent. |
|
209 | + */ |
|
210 | + private function sendStats() |
|
211 | + { |
|
212 | + return $this->config->isOptedInForUxip() |
|
213 | + && $this->maintenance_mode->level() !== EE_Maintenance_Mode::level_2_complete_maintenance |
|
214 | + && $this->statSendTimestampExpired(); |
|
215 | + } |
|
216 | + |
|
217 | + |
|
218 | + /** |
|
219 | + * Returns true when the timestamp used to track whether stats get sent (currently a weekly interval) is expired. |
|
220 | + * Returns false otherwise. |
|
221 | + * |
|
222 | + * @return bool |
|
223 | + */ |
|
224 | + private function statSendTimestampExpired() |
|
225 | + { |
|
226 | + $current_expiry = get_option(self::OPTIONS_KEY_EXPIRY_TIMESTAMP_FOR_SENDING_STATS, null); |
|
227 | + if ($current_expiry === null) { |
|
228 | + add_option(self::OPTIONS_KEY_EXPIRY_TIMESTAMP_FOR_SENDING_STATS, time() + WEEK_IN_SECONDS, '', 'no'); |
|
229 | + return true; |
|
230 | + } |
|
231 | + |
|
232 | + if (time() > (int) $current_expiry) { |
|
233 | + update_option(self::OPTIONS_KEY_EXPIRY_TIMESTAMP_FOR_SENDING_STATS, time() + WEEK_IN_SECONDS); |
|
234 | + return true; |
|
235 | + } |
|
236 | + return false; |
|
237 | + } |
|
238 | 238 | } |
@@ -20,113 +20,113 @@ |
||
20 | 20 | { |
21 | 21 | |
22 | 22 | |
23 | - /** |
|
24 | - * @param \EE_Registration $registration |
|
25 | - * @param int $quantity |
|
26 | - * @return bool|int |
|
27 | - */ |
|
28 | - public function forRegistration(\EE_Registration $registration, $quantity = 1) |
|
29 | - { |
|
30 | - return $this->cancel( |
|
31 | - $registration->transaction(), |
|
32 | - $registration->ticket(), |
|
33 | - $quantity, |
|
34 | - $registration->ticket_line_item() |
|
35 | - ); |
|
36 | - } |
|
23 | + /** |
|
24 | + * @param \EE_Registration $registration |
|
25 | + * @param int $quantity |
|
26 | + * @return bool|int |
|
27 | + */ |
|
28 | + public function forRegistration(\EE_Registration $registration, $quantity = 1) |
|
29 | + { |
|
30 | + return $this->cancel( |
|
31 | + $registration->transaction(), |
|
32 | + $registration->ticket(), |
|
33 | + $quantity, |
|
34 | + $registration->ticket_line_item() |
|
35 | + ); |
|
36 | + } |
|
37 | 37 | |
38 | 38 | |
39 | - /** |
|
40 | - * @param \EE_Transaction $transaction |
|
41 | - * @param \EE_Ticket $ticket |
|
42 | - * @param int $quantity |
|
43 | - * @param \EE_Line_Item $ticket_line_item |
|
44 | - * @return bool|int |
|
45 | - */ |
|
46 | - public function cancel( |
|
47 | - \EE_Transaction $transaction, |
|
48 | - \EE_Ticket $ticket, |
|
49 | - $quantity = 1, |
|
50 | - \EE_Line_Item $ticket_line_item = null |
|
51 | - ) { |
|
52 | - $ticket_line_item = $ticket_line_item instanceof \EE_Line_Item |
|
53 | - ? $ticket_line_item |
|
54 | - : $this->getTicketLineItem($transaction, $ticket); |
|
55 | - // first we need to decrement the ticket quantity |
|
56 | - \EEH_Line_Item::decrement_quantity($ticket_line_item, $quantity); |
|
57 | - // no tickets left for this line item ? |
|
58 | - if ((int) $ticket_line_item->quantity() === 0) { |
|
59 | - // then just set this line item as cancelled, save, and get out |
|
60 | - $ticket_line_item->set_type(\EEM_Line_Item::type_cancellation); |
|
61 | - $success = $ticket_line_item->save(); |
|
62 | - } else { |
|
63 | - // otherwise create a new cancelled line item, so that we have a record of the cancellation |
|
64 | - $items_subtotal = \EEH_Line_Item::get_pre_tax_subtotal( |
|
65 | - \EEH_Line_Item::get_event_line_item_for_ticket( |
|
66 | - $transaction->total_line_item(), |
|
67 | - $ticket |
|
68 | - ) |
|
69 | - ); |
|
70 | - $cancelled_line_item = \EE_Line_Item::new_instance( |
|
71 | - array( |
|
72 | - 'LIN_name' => $ticket_line_item->name(), |
|
73 | - 'LIN_desc' => sprintf( |
|
74 | - __('%1$s Cancelled: %2$s', 'event_espresso'), |
|
75 | - $ticket_line_item->desc(), |
|
76 | - date('Y-m-d h:i a') |
|
77 | - ), |
|
78 | - 'LIN_unit_price' => (float) $ticket_line_item->unit_price(), |
|
79 | - 'LIN_quantity' => $quantity, |
|
80 | - 'LIN_percent' => null, |
|
81 | - 'LIN_is_taxable' => false, |
|
82 | - 'LIN_order' => $items_subtotal instanceof \EE_Line_Item |
|
83 | - ? count($items_subtotal->children()) |
|
84 | - : 0, |
|
85 | - 'LIN_total' => (float) $ticket_line_item->unit_price(), |
|
86 | - 'LIN_type' => \EEM_Line_Item::type_cancellation, |
|
87 | - ) |
|
88 | - ); |
|
89 | - $success = \EEH_Line_Item::add_item($transaction->total_line_item(), $cancelled_line_item); |
|
90 | - } |
|
91 | - if (! $success) { |
|
92 | - throw new \RuntimeException( |
|
93 | - sprintf( |
|
94 | - __('An error occurred while attempting to cancel ticket line item %1$s', 'event_espresso'), |
|
95 | - $ticket_line_item->ID() |
|
96 | - ) |
|
97 | - ); |
|
98 | - } |
|
99 | - return $success; |
|
100 | - } |
|
39 | + /** |
|
40 | + * @param \EE_Transaction $transaction |
|
41 | + * @param \EE_Ticket $ticket |
|
42 | + * @param int $quantity |
|
43 | + * @param \EE_Line_Item $ticket_line_item |
|
44 | + * @return bool|int |
|
45 | + */ |
|
46 | + public function cancel( |
|
47 | + \EE_Transaction $transaction, |
|
48 | + \EE_Ticket $ticket, |
|
49 | + $quantity = 1, |
|
50 | + \EE_Line_Item $ticket_line_item = null |
|
51 | + ) { |
|
52 | + $ticket_line_item = $ticket_line_item instanceof \EE_Line_Item |
|
53 | + ? $ticket_line_item |
|
54 | + : $this->getTicketLineItem($transaction, $ticket); |
|
55 | + // first we need to decrement the ticket quantity |
|
56 | + \EEH_Line_Item::decrement_quantity($ticket_line_item, $quantity); |
|
57 | + // no tickets left for this line item ? |
|
58 | + if ((int) $ticket_line_item->quantity() === 0) { |
|
59 | + // then just set this line item as cancelled, save, and get out |
|
60 | + $ticket_line_item->set_type(\EEM_Line_Item::type_cancellation); |
|
61 | + $success = $ticket_line_item->save(); |
|
62 | + } else { |
|
63 | + // otherwise create a new cancelled line item, so that we have a record of the cancellation |
|
64 | + $items_subtotal = \EEH_Line_Item::get_pre_tax_subtotal( |
|
65 | + \EEH_Line_Item::get_event_line_item_for_ticket( |
|
66 | + $transaction->total_line_item(), |
|
67 | + $ticket |
|
68 | + ) |
|
69 | + ); |
|
70 | + $cancelled_line_item = \EE_Line_Item::new_instance( |
|
71 | + array( |
|
72 | + 'LIN_name' => $ticket_line_item->name(), |
|
73 | + 'LIN_desc' => sprintf( |
|
74 | + __('%1$s Cancelled: %2$s', 'event_espresso'), |
|
75 | + $ticket_line_item->desc(), |
|
76 | + date('Y-m-d h:i a') |
|
77 | + ), |
|
78 | + 'LIN_unit_price' => (float) $ticket_line_item->unit_price(), |
|
79 | + 'LIN_quantity' => $quantity, |
|
80 | + 'LIN_percent' => null, |
|
81 | + 'LIN_is_taxable' => false, |
|
82 | + 'LIN_order' => $items_subtotal instanceof \EE_Line_Item |
|
83 | + ? count($items_subtotal->children()) |
|
84 | + : 0, |
|
85 | + 'LIN_total' => (float) $ticket_line_item->unit_price(), |
|
86 | + 'LIN_type' => \EEM_Line_Item::type_cancellation, |
|
87 | + ) |
|
88 | + ); |
|
89 | + $success = \EEH_Line_Item::add_item($transaction->total_line_item(), $cancelled_line_item); |
|
90 | + } |
|
91 | + if (! $success) { |
|
92 | + throw new \RuntimeException( |
|
93 | + sprintf( |
|
94 | + __('An error occurred while attempting to cancel ticket line item %1$s', 'event_espresso'), |
|
95 | + $ticket_line_item->ID() |
|
96 | + ) |
|
97 | + ); |
|
98 | + } |
|
99 | + return $success; |
|
100 | + } |
|
101 | 101 | |
102 | 102 | |
103 | - /** |
|
104 | - * @param \EE_Transaction $transaction |
|
105 | - * @param \EE_Ticket $ticket |
|
106 | - * @return \EE_Line_Item |
|
107 | - * @throws EntityNotFoundException |
|
108 | - * @throws \EE_Error |
|
109 | - */ |
|
110 | - protected static function getTicketLineItem(\EE_Transaction $transaction, \EE_Ticket $ticket) |
|
111 | - { |
|
112 | - $line_item = null; |
|
113 | - $ticket_line_items = \EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
114 | - $transaction->total_line_item(), |
|
115 | - 'Ticket', |
|
116 | - array($ticket->ID()) |
|
117 | - ); |
|
118 | - foreach ($ticket_line_items as $ticket_line_item) { |
|
119 | - if ($ticket_line_item instanceof \EE_Line_Item |
|
120 | - && $ticket_line_item->OBJ_type() === 'Ticket' |
|
121 | - && $ticket_line_item->OBJ_ID() === $ticket->ID() |
|
122 | - ) { |
|
123 | - $line_item = $ticket_line_item; |
|
124 | - break; |
|
125 | - } |
|
126 | - } |
|
127 | - if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) { |
|
128 | - throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID()); |
|
129 | - } |
|
130 | - return $line_item; |
|
131 | - } |
|
103 | + /** |
|
104 | + * @param \EE_Transaction $transaction |
|
105 | + * @param \EE_Ticket $ticket |
|
106 | + * @return \EE_Line_Item |
|
107 | + * @throws EntityNotFoundException |
|
108 | + * @throws \EE_Error |
|
109 | + */ |
|
110 | + protected static function getTicketLineItem(\EE_Transaction $transaction, \EE_Ticket $ticket) |
|
111 | + { |
|
112 | + $line_item = null; |
|
113 | + $ticket_line_items = \EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
114 | + $transaction->total_line_item(), |
|
115 | + 'Ticket', |
|
116 | + array($ticket->ID()) |
|
117 | + ); |
|
118 | + foreach ($ticket_line_items as $ticket_line_item) { |
|
119 | + if ($ticket_line_item instanceof \EE_Line_Item |
|
120 | + && $ticket_line_item->OBJ_type() === 'Ticket' |
|
121 | + && $ticket_line_item->OBJ_ID() === $ticket->ID() |
|
122 | + ) { |
|
123 | + $line_item = $ticket_line_item; |
|
124 | + break; |
|
125 | + } |
|
126 | + } |
|
127 | + if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) { |
|
128 | + throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID()); |
|
129 | + } |
|
130 | + return $line_item; |
|
131 | + } |
|
132 | 132 | } |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | ); |
89 | 89 | $success = \EEH_Line_Item::add_item($transaction->total_line_item(), $cancelled_line_item); |
90 | 90 | } |
91 | - if (! $success) { |
|
91 | + if ( ! $success) { |
|
92 | 92 | throw new \RuntimeException( |
93 | 93 | sprintf( |
94 | 94 | __('An error occurred while attempting to cancel ticket line item %1$s', 'event_espresso'), |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | break; |
125 | 125 | } |
126 | 126 | } |
127 | - if (! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) { |
|
127 | + if ( ! ($line_item instanceof \EE_Line_Item && $line_item->OBJ_type() === 'Ticket')) { |
|
128 | 128 | throw new EntityNotFoundException('Line Item Ticket ID', $ticket->ID()); |
129 | 129 | } |
130 | 130 | return $line_item; |
@@ -18,84 +18,84 @@ |
||
18 | 18 | class CapabilitiesChecker implements CapabilitiesCheckerInterface |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @type EE_Capabilities $capabilities |
|
23 | - */ |
|
24 | - private $capabilities; |
|
21 | + /** |
|
22 | + * @type EE_Capabilities $capabilities |
|
23 | + */ |
|
24 | + private $capabilities; |
|
25 | 25 | |
26 | 26 | |
27 | - /** |
|
28 | - * CapabilitiesChecker constructor |
|
29 | - * |
|
30 | - * @param EE_Capabilities $capabilities |
|
31 | - */ |
|
32 | - public function __construct(EE_Capabilities $capabilities) |
|
33 | - { |
|
34 | - $this->capabilities = $capabilities; |
|
35 | - } |
|
27 | + /** |
|
28 | + * CapabilitiesChecker constructor |
|
29 | + * |
|
30 | + * @param EE_Capabilities $capabilities |
|
31 | + */ |
|
32 | + public function __construct(EE_Capabilities $capabilities) |
|
33 | + { |
|
34 | + $this->capabilities = $capabilities; |
|
35 | + } |
|
36 | 36 | |
37 | 37 | |
38 | - /** |
|
39 | - * @return EE_Capabilities |
|
40 | - */ |
|
41 | - protected function capabilities() |
|
42 | - { |
|
43 | - return $this->capabilities; |
|
44 | - } |
|
38 | + /** |
|
39 | + * @return EE_Capabilities |
|
40 | + */ |
|
41 | + protected function capabilities() |
|
42 | + { |
|
43 | + return $this->capabilities; |
|
44 | + } |
|
45 | 45 | |
46 | 46 | |
47 | - /** |
|
48 | - * Verifies that the current user has ALL of the capabilities listed in the CapCheck DTO. |
|
49 | - * If any of the individual capability checks fails, then the command will NOT be executed. |
|
50 | - * |
|
51 | - * @param CapCheckInterface|CapCheckInterface[] $cap_check |
|
52 | - * @return bool |
|
53 | - * @throws InvalidClassException |
|
54 | - * @throws InsufficientPermissionsException |
|
55 | - */ |
|
56 | - public function processCapCheck($cap_check) |
|
57 | - { |
|
58 | - if (is_array($cap_check)) { |
|
59 | - foreach ($cap_check as $check) { |
|
60 | - $this->processCapCheck($check); |
|
61 | - } |
|
62 | - return true; |
|
63 | - } |
|
64 | - // at this point, $cap_check should be an individual instance of CapCheck |
|
65 | - if (! $cap_check instanceof CapCheckInterface) { |
|
66 | - throw new InvalidClassException( |
|
67 | - '\EventEspresso\core\domain\services\capabilities\CapCheckInterface' |
|
68 | - ); |
|
69 | - } |
|
70 | - // sometimes cap checks are conditional, and no capabilities are required |
|
71 | - if ($cap_check instanceof PublicCapabilities) { |
|
72 | - return true; |
|
73 | - } |
|
74 | - $capabilities = (array) $cap_check->capability(); |
|
75 | - foreach ($capabilities as $capability) { |
|
76 | - if (! $this->capabilities()->current_user_can( |
|
77 | - $capability, |
|
78 | - $cap_check->context(), |
|
79 | - $cap_check->ID() |
|
80 | - )) { |
|
81 | - throw new InsufficientPermissionsException($cap_check->context()); |
|
82 | - } |
|
83 | - } |
|
84 | - return true; |
|
85 | - } |
|
47 | + /** |
|
48 | + * Verifies that the current user has ALL of the capabilities listed in the CapCheck DTO. |
|
49 | + * If any of the individual capability checks fails, then the command will NOT be executed. |
|
50 | + * |
|
51 | + * @param CapCheckInterface|CapCheckInterface[] $cap_check |
|
52 | + * @return bool |
|
53 | + * @throws InvalidClassException |
|
54 | + * @throws InsufficientPermissionsException |
|
55 | + */ |
|
56 | + public function processCapCheck($cap_check) |
|
57 | + { |
|
58 | + if (is_array($cap_check)) { |
|
59 | + foreach ($cap_check as $check) { |
|
60 | + $this->processCapCheck($check); |
|
61 | + } |
|
62 | + return true; |
|
63 | + } |
|
64 | + // at this point, $cap_check should be an individual instance of CapCheck |
|
65 | + if (! $cap_check instanceof CapCheckInterface) { |
|
66 | + throw new InvalidClassException( |
|
67 | + '\EventEspresso\core\domain\services\capabilities\CapCheckInterface' |
|
68 | + ); |
|
69 | + } |
|
70 | + // sometimes cap checks are conditional, and no capabilities are required |
|
71 | + if ($cap_check instanceof PublicCapabilities) { |
|
72 | + return true; |
|
73 | + } |
|
74 | + $capabilities = (array) $cap_check->capability(); |
|
75 | + foreach ($capabilities as $capability) { |
|
76 | + if (! $this->capabilities()->current_user_can( |
|
77 | + $capability, |
|
78 | + $cap_check->context(), |
|
79 | + $cap_check->ID() |
|
80 | + )) { |
|
81 | + throw new InsufficientPermissionsException($cap_check->context()); |
|
82 | + } |
|
83 | + } |
|
84 | + return true; |
|
85 | + } |
|
86 | 86 | |
87 | 87 | |
88 | - /** |
|
89 | - * @param string $capability - the capability to be checked, like: 'ee_edit_registrations' |
|
90 | - * @param string $context - what the user is attempting to do, like: 'Edit Registration' |
|
91 | - * @param int $ID - (optional) ID for item where current_user_can is being called from |
|
92 | - * @return bool |
|
93 | - * @throws InvalidDataTypeException |
|
94 | - * @throws InsufficientPermissionsException |
|
95 | - * @throws InvalidClassException |
|
96 | - */ |
|
97 | - public function process($capability, $context, $ID = 0) |
|
98 | - { |
|
99 | - return $this->processCapCheck(new CapCheck($capability, $context, $ID)); |
|
100 | - } |
|
88 | + /** |
|
89 | + * @param string $capability - the capability to be checked, like: 'ee_edit_registrations' |
|
90 | + * @param string $context - what the user is attempting to do, like: 'Edit Registration' |
|
91 | + * @param int $ID - (optional) ID for item where current_user_can is being called from |
|
92 | + * @return bool |
|
93 | + * @throws InvalidDataTypeException |
|
94 | + * @throws InsufficientPermissionsException |
|
95 | + * @throws InvalidClassException |
|
96 | + */ |
|
97 | + public function process($capability, $context, $ID = 0) |
|
98 | + { |
|
99 | + return $this->processCapCheck(new CapCheck($capability, $context, $ID)); |
|
100 | + } |
|
101 | 101 | } |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | return true; |
63 | 63 | } |
64 | 64 | // at this point, $cap_check should be an individual instance of CapCheck |
65 | - if (! $cap_check instanceof CapCheckInterface) { |
|
65 | + if ( ! $cap_check instanceof CapCheckInterface) { |
|
66 | 66 | throw new InvalidClassException( |
67 | 67 | '\EventEspresso\core\domain\services\capabilities\CapCheckInterface' |
68 | 68 | ); |
@@ -73,7 +73,7 @@ discard block |
||
73 | 73 | } |
74 | 74 | $capabilities = (array) $cap_check->capability(); |
75 | 75 | foreach ($capabilities as $capability) { |
76 | - if (! $this->capabilities()->current_user_can( |
|
76 | + if ( ! $this->capabilities()->current_user_can( |
|
77 | 77 | $capability, |
78 | 78 | $cap_check->context(), |
79 | 79 | $cap_check->ID() |
@@ -27,84 +27,84 @@ |
||
27 | 27 | { |
28 | 28 | |
29 | 29 | |
30 | - protected $attendee; |
|
30 | + protected $attendee; |
|
31 | 31 | |
32 | 32 | |
33 | - /** |
|
34 | - * AttendeeContactDetailsMetaboxFormHandler constructor. |
|
35 | - * |
|
36 | - * @param EE_Attendee $attendee |
|
37 | - * @param EE_Registry $registry |
|
38 | - * @throws DomainException |
|
39 | - * @throws InvalidDataTypeException |
|
40 | - * @throws InvalidArgumentException |
|
41 | - */ |
|
42 | - public function __construct(EE_Attendee $attendee, EE_Registry $registry) |
|
43 | - { |
|
44 | - $this->attendee = $attendee; |
|
45 | - $label = esc_html__('Contact Details', 'event_espresso'); |
|
46 | - parent::__construct( |
|
47 | - $label, |
|
48 | - $label, |
|
49 | - 'attendee_contact_details', |
|
50 | - '', |
|
51 | - FormHandler::DO_NOT_SETUP_FORM, |
|
52 | - $registry |
|
53 | - ); |
|
54 | - } |
|
33 | + /** |
|
34 | + * AttendeeContactDetailsMetaboxFormHandler constructor. |
|
35 | + * |
|
36 | + * @param EE_Attendee $attendee |
|
37 | + * @param EE_Registry $registry |
|
38 | + * @throws DomainException |
|
39 | + * @throws InvalidDataTypeException |
|
40 | + * @throws InvalidArgumentException |
|
41 | + */ |
|
42 | + public function __construct(EE_Attendee $attendee, EE_Registry $registry) |
|
43 | + { |
|
44 | + $this->attendee = $attendee; |
|
45 | + $label = esc_html__('Contact Details', 'event_espresso'); |
|
46 | + parent::__construct( |
|
47 | + $label, |
|
48 | + $label, |
|
49 | + 'attendee_contact_details', |
|
50 | + '', |
|
51 | + FormHandler::DO_NOT_SETUP_FORM, |
|
52 | + $registry |
|
53 | + ); |
|
54 | + } |
|
55 | 55 | |
56 | - /** |
|
57 | - * creates and returns the actual form |
|
58 | - * |
|
59 | - * @return EE_Form_Section_Proper |
|
60 | - * @throws EE_Error |
|
61 | - */ |
|
62 | - public function generate() |
|
63 | - { |
|
64 | - return new EE_Form_Section_Proper( |
|
65 | - array( |
|
66 | - 'name' => 'attendee_contact_details', |
|
67 | - 'html_id' => 'attendee-contact-details', |
|
68 | - 'html_class' => 'form-table', |
|
69 | - 'layout_strategy' => new EE_Admin_One_Column_Layout(), |
|
70 | - 'subsections' => array( |
|
71 | - 'ATT_email' => new EE_Email_Input( |
|
72 | - array( |
|
73 | - 'default' => $this->attendee->email(), |
|
74 | - 'html_label_text' => esc_html__('Email Address', 'event_espresso'), |
|
75 | - 'required' => true, |
|
76 | - ) |
|
77 | - ), |
|
78 | - 'ATT_phone' => new EE_Text_Input( |
|
79 | - array( |
|
80 | - 'default' => $this->attendee->phone(), |
|
81 | - 'html_label_text' => esc_html__('Phone Number', 'event_espresso'), |
|
82 | - ) |
|
83 | - ), |
|
84 | - ), |
|
85 | - ) |
|
86 | - ); |
|
87 | - } |
|
56 | + /** |
|
57 | + * creates and returns the actual form |
|
58 | + * |
|
59 | + * @return EE_Form_Section_Proper |
|
60 | + * @throws EE_Error |
|
61 | + */ |
|
62 | + public function generate() |
|
63 | + { |
|
64 | + return new EE_Form_Section_Proper( |
|
65 | + array( |
|
66 | + 'name' => 'attendee_contact_details', |
|
67 | + 'html_id' => 'attendee-contact-details', |
|
68 | + 'html_class' => 'form-table', |
|
69 | + 'layout_strategy' => new EE_Admin_One_Column_Layout(), |
|
70 | + 'subsections' => array( |
|
71 | + 'ATT_email' => new EE_Email_Input( |
|
72 | + array( |
|
73 | + 'default' => $this->attendee->email(), |
|
74 | + 'html_label_text' => esc_html__('Email Address', 'event_espresso'), |
|
75 | + 'required' => true, |
|
76 | + ) |
|
77 | + ), |
|
78 | + 'ATT_phone' => new EE_Text_Input( |
|
79 | + array( |
|
80 | + 'default' => $this->attendee->phone(), |
|
81 | + 'html_label_text' => esc_html__('Phone Number', 'event_espresso'), |
|
82 | + ) |
|
83 | + ), |
|
84 | + ), |
|
85 | + ) |
|
86 | + ); |
|
87 | + } |
|
88 | 88 | |
89 | 89 | |
90 | - /** |
|
91 | - * Process form data. |
|
92 | - * |
|
93 | - * @param array $form_data |
|
94 | - * @return bool |
|
95 | - * @throws EE_Error |
|
96 | - * @throws InvalidFormSubmissionException |
|
97 | - * @throws LogicException |
|
98 | - */ |
|
99 | - public function process($form_data = array()) |
|
100 | - { |
|
101 | - $valid_data = (array) parent::process($form_data); |
|
102 | - if (empty($valid_data)) { |
|
103 | - return false; |
|
104 | - } |
|
105 | - $this->attendee->set_email($valid_data['ATT_email']); |
|
106 | - $this->attendee->set_phone($valid_data['ATT_phone']); |
|
107 | - $updated = $this->attendee->save(); |
|
108 | - return $updated !== false; |
|
109 | - } |
|
90 | + /** |
|
91 | + * Process form data. |
|
92 | + * |
|
93 | + * @param array $form_data |
|
94 | + * @return bool |
|
95 | + * @throws EE_Error |
|
96 | + * @throws InvalidFormSubmissionException |
|
97 | + * @throws LogicException |
|
98 | + */ |
|
99 | + public function process($form_data = array()) |
|
100 | + { |
|
101 | + $valid_data = (array) parent::process($form_data); |
|
102 | + if (empty($valid_data)) { |
|
103 | + return false; |
|
104 | + } |
|
105 | + $this->attendee->set_email($valid_data['ATT_email']); |
|
106 | + $this->attendee->set_phone($valid_data['ATT_phone']); |
|
107 | + $updated = $this->attendee->save(); |
|
108 | + return $updated !== false; |
|
109 | + } |
|
110 | 110 | } |
@@ -15,56 +15,56 @@ |
||
15 | 15 | class EmailAddress |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @var string $email_address |
|
20 | - */ |
|
21 | - private $email_address; |
|
18 | + /** |
|
19 | + * @var string $email_address |
|
20 | + */ |
|
21 | + private $email_address; |
|
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * EmailAddress constructor. |
|
26 | - * |
|
27 | - * @param string $email_address |
|
28 | - * @param EmailValidatorInterface $validator |
|
29 | - * @throws EmailValidationException |
|
30 | - */ |
|
31 | - public function __construct($email_address, EmailValidatorInterface $validator) |
|
32 | - { |
|
33 | - $validator->validate($email_address); |
|
34 | - $this->email_address = $email_address; |
|
35 | - } |
|
24 | + /** |
|
25 | + * EmailAddress constructor. |
|
26 | + * |
|
27 | + * @param string $email_address |
|
28 | + * @param EmailValidatorInterface $validator |
|
29 | + * @throws EmailValidationException |
|
30 | + */ |
|
31 | + public function __construct($email_address, EmailValidatorInterface $validator) |
|
32 | + { |
|
33 | + $validator->validate($email_address); |
|
34 | + $this->email_address = $email_address; |
|
35 | + } |
|
36 | 36 | |
37 | 37 | |
38 | - /** |
|
39 | - * returns the string value for this EmailAddress |
|
40 | - * |
|
41 | - * @return string |
|
42 | - */ |
|
43 | - public function get() |
|
44 | - { |
|
45 | - return $this->email_address; |
|
46 | - } |
|
38 | + /** |
|
39 | + * returns the string value for this EmailAddress |
|
40 | + * |
|
41 | + * @return string |
|
42 | + */ |
|
43 | + public function get() |
|
44 | + { |
|
45 | + return $this->email_address; |
|
46 | + } |
|
47 | 47 | |
48 | 48 | |
49 | - /** |
|
50 | - * compare another EmailAddress to this one to determine if they are the same |
|
51 | - * |
|
52 | - * @param EmailAddress $address |
|
53 | - * @return bool |
|
54 | - */ |
|
55 | - public function equals(EmailAddress $address) |
|
56 | - { |
|
57 | - return strtolower((string) $this) === strtolower((string) $address); |
|
58 | - } |
|
49 | + /** |
|
50 | + * compare another EmailAddress to this one to determine if they are the same |
|
51 | + * |
|
52 | + * @param EmailAddress $address |
|
53 | + * @return bool |
|
54 | + */ |
|
55 | + public function equals(EmailAddress $address) |
|
56 | + { |
|
57 | + return strtolower((string) $this) === strtolower((string) $address); |
|
58 | + } |
|
59 | 59 | |
60 | 60 | |
61 | - /** |
|
62 | - * allows an EmailAddress object to be used as a string |
|
63 | - * |
|
64 | - * @return string |
|
65 | - */ |
|
66 | - public function __toString() |
|
67 | - { |
|
68 | - return $this->email_address; |
|
69 | - } |
|
61 | + /** |
|
62 | + * allows an EmailAddress object to be used as a string |
|
63 | + * |
|
64 | + * @return string |
|
65 | + */ |
|
66 | + public function __toString() |
|
67 | + { |
|
68 | + return $this->email_address; |
|
69 | + } |
|
70 | 70 | } |
@@ -17,339 +17,339 @@ |
||
17 | 17 | */ |
18 | 18 | class CustomSelects |
19 | 19 | { |
20 | - const TYPE_SIMPLE = 'simple'; |
|
21 | - const TYPE_COMPLEX = 'complex'; |
|
22 | - const TYPE_STRUCTURED = 'structured'; |
|
23 | - |
|
24 | - private $valid_operators = array('COUNT', 'SUM'); |
|
25 | - |
|
26 | - |
|
27 | - /** |
|
28 | - * Original incoming select array |
|
29 | - * |
|
30 | - * @var array |
|
31 | - */ |
|
32 | - private $original_selects; |
|
33 | - |
|
34 | - /** |
|
35 | - * Select string that can be added to the query |
|
36 | - * |
|
37 | - * @var string |
|
38 | - */ |
|
39 | - private $columns_to_select_expression; |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * An array of aliases for the columns included in the incoming select array. |
|
44 | - * |
|
45 | - * @var array |
|
46 | - */ |
|
47 | - private $column_aliases_in_select; |
|
48 | - |
|
49 | - |
|
50 | - /** |
|
51 | - * Enum representation of the "type" of array coming into this value object. |
|
52 | - * |
|
53 | - * @var string |
|
54 | - */ |
|
55 | - private $type = ''; |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * CustomSelects constructor. |
|
60 | - * Incoming selects can be in one of the following formats: |
|
61 | - * ---- self::TYPE_SIMPLE array ---- |
|
62 | - * This is considered the "simple" type. In this case the array is an numerically indexed array with single or |
|
63 | - * multiple columns to select as the values. |
|
64 | - * eg. array( 'ATT_ID', 'REG_ID' ) |
|
65 | - * eg. array( '*' ) |
|
66 | - * If you want to use the columns in any WHERE, GROUP BY, or HAVING clauses, you must instead use the "complex" or |
|
67 | - * "structured" method. |
|
68 | - * ---- self::TYPE_COMPLEX array ---- |
|
69 | - * This is considered the "complex" type. In this case the array is indexed by arbitrary strings that serve as |
|
70 | - * column alias, and the value is an numerically indexed array where there are two values. The first value (0) is |
|
71 | - * the selection and the second value (1) is the data type. Data types must be one of the types defined in |
|
72 | - * EEM_Base::$_valid_wpdb_data_types. |
|
73 | - * eg. array( 'count' => array('count(REG_ID)', '%d') ) |
|
74 | - * Complex array configuration allows for using the column alias in any WHERE, GROUP BY, or HAVING clauses. |
|
75 | - * ---- self::TYPE_STRUCTURED array --- |
|
76 | - * This is considered the "structured" type. This type is similar to the complex type except that the array attached |
|
77 | - * to the column alias contains three values. The first value is the qualified column name (which can include |
|
78 | - * join syntax for models). The second value is the operator performed on the column (i.e. 'COUNT', 'SUM' etc)., |
|
79 | - * the third value is the data type. Note, if the select does not have an operator, you can use an empty string for |
|
80 | - * the second value. |
|
81 | - * Note: for now SUM is only for simple single column expressions (i.e. SUM(Transaction.TXN_total)) |
|
82 | - * eg. array( 'registration_count' => array('Registration.REG_ID', 'count', '%d') ); |
|
83 | - * NOTE: mixing array types in the incoming $select will cause errors. |
|
84 | - * |
|
85 | - * @param array $selects |
|
86 | - * @throws InvalidArgumentException |
|
87 | - */ |
|
88 | - public function __construct(array $selects) |
|
89 | - { |
|
90 | - $this->original_selects = $selects; |
|
91 | - $this->deriveType($selects); |
|
92 | - $this->deriveParts($selects); |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * Derives what type of custom select has been sent in. |
|
98 | - * |
|
99 | - * @param array $selects |
|
100 | - * @throws InvalidArgumentException |
|
101 | - */ |
|
102 | - private function deriveType(array $selects) |
|
103 | - { |
|
104 | - // first if the first key for this array is an integer then its coming in as a simple format, so we'll also |
|
105 | - // ensure all elements of the array are simple. |
|
106 | - if (is_int(key($selects))) { |
|
107 | - // let's ensure all keys are ints |
|
108 | - $invalid_keys = array_filter( |
|
109 | - array_keys($selects), |
|
110 | - function ($value) { |
|
111 | - return ! is_int($value); |
|
112 | - } |
|
113 | - ); |
|
114 | - if (! empty($invalid_keys)) { |
|
115 | - throw new InvalidArgumentException( |
|
116 | - sprintf( |
|
117 | - esc_html__( |
|
118 | - 'Incoming array looks like its formatted for "%1$s" type selects, however it has elements that are not indexed numerically', |
|
119 | - 'event_espresso' |
|
120 | - ), |
|
121 | - self::TYPE_SIMPLE |
|
122 | - ) |
|
123 | - ); |
|
124 | - } |
|
125 | - $this->type = self::TYPE_SIMPLE; |
|
126 | - return; |
|
127 | - } |
|
128 | - // made it here so that means we've got either complex or structured selects. Let's find out which by popping |
|
129 | - // the first array element off. |
|
130 | - $first_element = reset($selects); |
|
131 | - |
|
132 | - if (! is_array($first_element)) { |
|
133 | - throw new InvalidArgumentException( |
|
134 | - sprintf( |
|
135 | - esc_html__( |
|
136 | - 'Incoming array looks like its formatted as a "%1$s" or "%2$s" type. However, the values in the array must be arrays themselves and they are not.', |
|
137 | - 'event_espresso' |
|
138 | - ), |
|
139 | - self::TYPE_COMPLEX, |
|
140 | - self::TYPE_STRUCTURED |
|
141 | - ) |
|
142 | - ); |
|
143 | - } |
|
144 | - $this->type = count($first_element) === 2 |
|
145 | - ? self::TYPE_COMPLEX |
|
146 | - : self::TYPE_STRUCTURED; |
|
147 | - } |
|
148 | - |
|
149 | - |
|
150 | - /** |
|
151 | - * Sets up the various properties for the vo depending on type. |
|
152 | - * |
|
153 | - * @param array $selects |
|
154 | - * @throws InvalidArgumentException |
|
155 | - */ |
|
156 | - private function deriveParts(array $selects) |
|
157 | - { |
|
158 | - $column_parts = array(); |
|
159 | - switch ($this->type) { |
|
160 | - case self::TYPE_SIMPLE: |
|
161 | - $column_parts = $selects; |
|
162 | - $this->column_aliases_in_select = $selects; |
|
163 | - break; |
|
164 | - case self::TYPE_COMPLEX: |
|
165 | - foreach ($selects as $alias => $parts) { |
|
166 | - $this->validateSelectValueForType($parts, $alias); |
|
167 | - $column_parts[] = "{$parts[0]} AS {$alias}"; |
|
168 | - $this->column_aliases_in_select[] = $alias; |
|
169 | - } |
|
170 | - break; |
|
171 | - case self::TYPE_STRUCTURED: |
|
172 | - foreach ($selects as $alias => $parts) { |
|
173 | - $this->validateSelectValueForType($parts, $alias); |
|
174 | - $column_parts[] = $parts[1] !== '' |
|
175 | - ? $this->assembleSelectStringWithOperator($parts, $alias) |
|
176 | - : "{$parts[0]} AS {$alias}"; |
|
177 | - $this->column_aliases_in_select[] = $alias; |
|
178 | - } |
|
179 | - break; |
|
180 | - } |
|
181 | - $this->columns_to_select_expression = implode(', ', $column_parts); |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * Validates self::TYPE_COMPLEX and self::TYPE_STRUCTURED select statement parts. |
|
187 | - * |
|
188 | - * @param array $select_parts |
|
189 | - * @param string $alias |
|
190 | - * @throws InvalidArgumentException |
|
191 | - */ |
|
192 | - private function validateSelectValueForType(array $select_parts, $alias) |
|
193 | - { |
|
194 | - $valid_data_types = array('%d', '%s', '%f'); |
|
195 | - if (count($select_parts) !== $this->expectedSelectPartCountForType()) { |
|
196 | - throw new InvalidArgumentException( |
|
197 | - sprintf( |
|
198 | - esc_html__( |
|
199 | - 'The provided select part array for the %1$s column is expected to have a count of %2$d because the incoming select array is of type %3$s. However the count was %4$d.', |
|
200 | - 'event_espresso' |
|
201 | - ), |
|
202 | - $alias, |
|
203 | - $this->expectedSelectPartCountForType(), |
|
204 | - $this->type, |
|
205 | - count($select_parts) |
|
206 | - ) |
|
207 | - ); |
|
208 | - } |
|
209 | - // validate data type. |
|
210 | - $data_type = $this->type === self::TYPE_COMPLEX ? $select_parts[1] : ''; |
|
211 | - $data_type = $this->type === self::TYPE_STRUCTURED ? $select_parts[2] : $data_type; |
|
212 | - |
|
213 | - if (! in_array($data_type, $valid_data_types, true)) { |
|
214 | - throw new InvalidArgumentException( |
|
215 | - sprintf( |
|
216 | - esc_html__( |
|
217 | - 'Datatype %1$s (for selection "%2$s" and alias "%3$s") is not a valid wpdb datatype (eg %%s)', |
|
218 | - 'event_espresso' |
|
219 | - ), |
|
220 | - $data_type, |
|
221 | - $select_parts[0], |
|
222 | - $alias, |
|
223 | - implode(', ', $valid_data_types) |
|
224 | - ) |
|
225 | - ); |
|
226 | - } |
|
227 | - } |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * Each type will have an expected count of array elements, this returns what that expected count is. |
|
232 | - * |
|
233 | - * @param string $type |
|
234 | - * @return int |
|
235 | - */ |
|
236 | - private function expectedSelectPartCountForType($type = '') |
|
237 | - { |
|
238 | - $type = $type === '' ? $this->type : $type; |
|
239 | - $types_count_map = array( |
|
240 | - self::TYPE_COMPLEX => 2, |
|
241 | - self::TYPE_STRUCTURED => 3, |
|
242 | - ); |
|
243 | - return isset($types_count_map[ $type ]) ? $types_count_map[ $type ] : 0; |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * Prepares the select statement part for for structured type selects. |
|
249 | - * |
|
250 | - * @param array $select_parts |
|
251 | - * @param string $alias |
|
252 | - * @return string |
|
253 | - * @throws InvalidArgumentException |
|
254 | - */ |
|
255 | - private function assembleSelectStringWithOperator(array $select_parts, $alias) |
|
256 | - { |
|
257 | - $operator = strtoupper($select_parts[1]); |
|
258 | - // validate operator |
|
259 | - if (! in_array($operator, $this->valid_operators, true)) { |
|
260 | - throw new InvalidArgumentException( |
|
261 | - sprintf( |
|
262 | - esc_html__( |
|
263 | - 'An invalid operator has been provided (%1$s) for the column %2$s. Valid operators must be one of the following: %3$s.', |
|
264 | - 'event_espresso' |
|
265 | - ), |
|
266 | - $operator, |
|
267 | - $alias, |
|
268 | - implode(', ', $this->valid_operators) |
|
269 | - ) |
|
270 | - ); |
|
271 | - } |
|
272 | - return $operator . '(' . $select_parts[0] . ') AS ' . $alias; |
|
273 | - } |
|
274 | - |
|
275 | - |
|
276 | - /** |
|
277 | - * Return the datatype from the given select part. |
|
278 | - * Remember the select_part has already been validated on object instantiation. |
|
279 | - * |
|
280 | - * @param array $select_part |
|
281 | - * @return string |
|
282 | - */ |
|
283 | - private function getDataTypeForSelectType(array $select_part) |
|
284 | - { |
|
285 | - switch ($this->type) { |
|
286 | - case self::TYPE_COMPLEX: |
|
287 | - return $select_part[1]; |
|
288 | - case self::TYPE_STRUCTURED: |
|
289 | - return $select_part[2]; |
|
290 | - default: |
|
291 | - return ''; |
|
292 | - } |
|
293 | - } |
|
294 | - |
|
295 | - |
|
296 | - /** |
|
297 | - * Returns the original select array sent into the VO. |
|
298 | - * |
|
299 | - * @return array |
|
300 | - */ |
|
301 | - public function originalSelects() |
|
302 | - { |
|
303 | - return $this->original_selects; |
|
304 | - } |
|
305 | - |
|
306 | - |
|
307 | - /** |
|
308 | - * Returns the final assembled select expression derived from the incoming select array. |
|
309 | - * |
|
310 | - * @return string |
|
311 | - */ |
|
312 | - public function columnsToSelectExpression() |
|
313 | - { |
|
314 | - return $this->columns_to_select_expression; |
|
315 | - } |
|
316 | - |
|
317 | - |
|
318 | - /** |
|
319 | - * Returns all the column aliases derived from the incoming select array. |
|
320 | - * |
|
321 | - * @return array |
|
322 | - */ |
|
323 | - public function columnAliases() |
|
324 | - { |
|
325 | - return $this->column_aliases_in_select; |
|
326 | - } |
|
327 | - |
|
328 | - |
|
329 | - /** |
|
330 | - * Returns the enum type for the incoming select array. |
|
331 | - * |
|
332 | - * @return string |
|
333 | - */ |
|
334 | - public function type() |
|
335 | - { |
|
336 | - return $this->type; |
|
337 | - } |
|
338 | - |
|
339 | - |
|
340 | - /** |
|
341 | - * Return the datatype for the given column_alias |
|
342 | - * |
|
343 | - * @param string $column_alias |
|
344 | - * @return string (if there's no data type we return string as the default). |
|
345 | - */ |
|
346 | - public function getDataTypeForAlias($column_alias) |
|
347 | - { |
|
348 | - if (isset($this->original_selects[ $column_alias ]) |
|
349 | - && in_array($column_alias, $this->columnAliases(), true) |
|
350 | - ) { |
|
351 | - return $this->getDataTypeForSelectType($this->original_selects[ $column_alias ]); |
|
352 | - } |
|
353 | - return '%s'; |
|
354 | - } |
|
20 | + const TYPE_SIMPLE = 'simple'; |
|
21 | + const TYPE_COMPLEX = 'complex'; |
|
22 | + const TYPE_STRUCTURED = 'structured'; |
|
23 | + |
|
24 | + private $valid_operators = array('COUNT', 'SUM'); |
|
25 | + |
|
26 | + |
|
27 | + /** |
|
28 | + * Original incoming select array |
|
29 | + * |
|
30 | + * @var array |
|
31 | + */ |
|
32 | + private $original_selects; |
|
33 | + |
|
34 | + /** |
|
35 | + * Select string that can be added to the query |
|
36 | + * |
|
37 | + * @var string |
|
38 | + */ |
|
39 | + private $columns_to_select_expression; |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * An array of aliases for the columns included in the incoming select array. |
|
44 | + * |
|
45 | + * @var array |
|
46 | + */ |
|
47 | + private $column_aliases_in_select; |
|
48 | + |
|
49 | + |
|
50 | + /** |
|
51 | + * Enum representation of the "type" of array coming into this value object. |
|
52 | + * |
|
53 | + * @var string |
|
54 | + */ |
|
55 | + private $type = ''; |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * CustomSelects constructor. |
|
60 | + * Incoming selects can be in one of the following formats: |
|
61 | + * ---- self::TYPE_SIMPLE array ---- |
|
62 | + * This is considered the "simple" type. In this case the array is an numerically indexed array with single or |
|
63 | + * multiple columns to select as the values. |
|
64 | + * eg. array( 'ATT_ID', 'REG_ID' ) |
|
65 | + * eg. array( '*' ) |
|
66 | + * If you want to use the columns in any WHERE, GROUP BY, or HAVING clauses, you must instead use the "complex" or |
|
67 | + * "structured" method. |
|
68 | + * ---- self::TYPE_COMPLEX array ---- |
|
69 | + * This is considered the "complex" type. In this case the array is indexed by arbitrary strings that serve as |
|
70 | + * column alias, and the value is an numerically indexed array where there are two values. The first value (0) is |
|
71 | + * the selection and the second value (1) is the data type. Data types must be one of the types defined in |
|
72 | + * EEM_Base::$_valid_wpdb_data_types. |
|
73 | + * eg. array( 'count' => array('count(REG_ID)', '%d') ) |
|
74 | + * Complex array configuration allows for using the column alias in any WHERE, GROUP BY, or HAVING clauses. |
|
75 | + * ---- self::TYPE_STRUCTURED array --- |
|
76 | + * This is considered the "structured" type. This type is similar to the complex type except that the array attached |
|
77 | + * to the column alias contains three values. The first value is the qualified column name (which can include |
|
78 | + * join syntax for models). The second value is the operator performed on the column (i.e. 'COUNT', 'SUM' etc)., |
|
79 | + * the third value is the data type. Note, if the select does not have an operator, you can use an empty string for |
|
80 | + * the second value. |
|
81 | + * Note: for now SUM is only for simple single column expressions (i.e. SUM(Transaction.TXN_total)) |
|
82 | + * eg. array( 'registration_count' => array('Registration.REG_ID', 'count', '%d') ); |
|
83 | + * NOTE: mixing array types in the incoming $select will cause errors. |
|
84 | + * |
|
85 | + * @param array $selects |
|
86 | + * @throws InvalidArgumentException |
|
87 | + */ |
|
88 | + public function __construct(array $selects) |
|
89 | + { |
|
90 | + $this->original_selects = $selects; |
|
91 | + $this->deriveType($selects); |
|
92 | + $this->deriveParts($selects); |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * Derives what type of custom select has been sent in. |
|
98 | + * |
|
99 | + * @param array $selects |
|
100 | + * @throws InvalidArgumentException |
|
101 | + */ |
|
102 | + private function deriveType(array $selects) |
|
103 | + { |
|
104 | + // first if the first key for this array is an integer then its coming in as a simple format, so we'll also |
|
105 | + // ensure all elements of the array are simple. |
|
106 | + if (is_int(key($selects))) { |
|
107 | + // let's ensure all keys are ints |
|
108 | + $invalid_keys = array_filter( |
|
109 | + array_keys($selects), |
|
110 | + function ($value) { |
|
111 | + return ! is_int($value); |
|
112 | + } |
|
113 | + ); |
|
114 | + if (! empty($invalid_keys)) { |
|
115 | + throw new InvalidArgumentException( |
|
116 | + sprintf( |
|
117 | + esc_html__( |
|
118 | + 'Incoming array looks like its formatted for "%1$s" type selects, however it has elements that are not indexed numerically', |
|
119 | + 'event_espresso' |
|
120 | + ), |
|
121 | + self::TYPE_SIMPLE |
|
122 | + ) |
|
123 | + ); |
|
124 | + } |
|
125 | + $this->type = self::TYPE_SIMPLE; |
|
126 | + return; |
|
127 | + } |
|
128 | + // made it here so that means we've got either complex or structured selects. Let's find out which by popping |
|
129 | + // the first array element off. |
|
130 | + $first_element = reset($selects); |
|
131 | + |
|
132 | + if (! is_array($first_element)) { |
|
133 | + throw new InvalidArgumentException( |
|
134 | + sprintf( |
|
135 | + esc_html__( |
|
136 | + 'Incoming array looks like its formatted as a "%1$s" or "%2$s" type. However, the values in the array must be arrays themselves and they are not.', |
|
137 | + 'event_espresso' |
|
138 | + ), |
|
139 | + self::TYPE_COMPLEX, |
|
140 | + self::TYPE_STRUCTURED |
|
141 | + ) |
|
142 | + ); |
|
143 | + } |
|
144 | + $this->type = count($first_element) === 2 |
|
145 | + ? self::TYPE_COMPLEX |
|
146 | + : self::TYPE_STRUCTURED; |
|
147 | + } |
|
148 | + |
|
149 | + |
|
150 | + /** |
|
151 | + * Sets up the various properties for the vo depending on type. |
|
152 | + * |
|
153 | + * @param array $selects |
|
154 | + * @throws InvalidArgumentException |
|
155 | + */ |
|
156 | + private function deriveParts(array $selects) |
|
157 | + { |
|
158 | + $column_parts = array(); |
|
159 | + switch ($this->type) { |
|
160 | + case self::TYPE_SIMPLE: |
|
161 | + $column_parts = $selects; |
|
162 | + $this->column_aliases_in_select = $selects; |
|
163 | + break; |
|
164 | + case self::TYPE_COMPLEX: |
|
165 | + foreach ($selects as $alias => $parts) { |
|
166 | + $this->validateSelectValueForType($parts, $alias); |
|
167 | + $column_parts[] = "{$parts[0]} AS {$alias}"; |
|
168 | + $this->column_aliases_in_select[] = $alias; |
|
169 | + } |
|
170 | + break; |
|
171 | + case self::TYPE_STRUCTURED: |
|
172 | + foreach ($selects as $alias => $parts) { |
|
173 | + $this->validateSelectValueForType($parts, $alias); |
|
174 | + $column_parts[] = $parts[1] !== '' |
|
175 | + ? $this->assembleSelectStringWithOperator($parts, $alias) |
|
176 | + : "{$parts[0]} AS {$alias}"; |
|
177 | + $this->column_aliases_in_select[] = $alias; |
|
178 | + } |
|
179 | + break; |
|
180 | + } |
|
181 | + $this->columns_to_select_expression = implode(', ', $column_parts); |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * Validates self::TYPE_COMPLEX and self::TYPE_STRUCTURED select statement parts. |
|
187 | + * |
|
188 | + * @param array $select_parts |
|
189 | + * @param string $alias |
|
190 | + * @throws InvalidArgumentException |
|
191 | + */ |
|
192 | + private function validateSelectValueForType(array $select_parts, $alias) |
|
193 | + { |
|
194 | + $valid_data_types = array('%d', '%s', '%f'); |
|
195 | + if (count($select_parts) !== $this->expectedSelectPartCountForType()) { |
|
196 | + throw new InvalidArgumentException( |
|
197 | + sprintf( |
|
198 | + esc_html__( |
|
199 | + 'The provided select part array for the %1$s column is expected to have a count of %2$d because the incoming select array is of type %3$s. However the count was %4$d.', |
|
200 | + 'event_espresso' |
|
201 | + ), |
|
202 | + $alias, |
|
203 | + $this->expectedSelectPartCountForType(), |
|
204 | + $this->type, |
|
205 | + count($select_parts) |
|
206 | + ) |
|
207 | + ); |
|
208 | + } |
|
209 | + // validate data type. |
|
210 | + $data_type = $this->type === self::TYPE_COMPLEX ? $select_parts[1] : ''; |
|
211 | + $data_type = $this->type === self::TYPE_STRUCTURED ? $select_parts[2] : $data_type; |
|
212 | + |
|
213 | + if (! in_array($data_type, $valid_data_types, true)) { |
|
214 | + throw new InvalidArgumentException( |
|
215 | + sprintf( |
|
216 | + esc_html__( |
|
217 | + 'Datatype %1$s (for selection "%2$s" and alias "%3$s") is not a valid wpdb datatype (eg %%s)', |
|
218 | + 'event_espresso' |
|
219 | + ), |
|
220 | + $data_type, |
|
221 | + $select_parts[0], |
|
222 | + $alias, |
|
223 | + implode(', ', $valid_data_types) |
|
224 | + ) |
|
225 | + ); |
|
226 | + } |
|
227 | + } |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * Each type will have an expected count of array elements, this returns what that expected count is. |
|
232 | + * |
|
233 | + * @param string $type |
|
234 | + * @return int |
|
235 | + */ |
|
236 | + private function expectedSelectPartCountForType($type = '') |
|
237 | + { |
|
238 | + $type = $type === '' ? $this->type : $type; |
|
239 | + $types_count_map = array( |
|
240 | + self::TYPE_COMPLEX => 2, |
|
241 | + self::TYPE_STRUCTURED => 3, |
|
242 | + ); |
|
243 | + return isset($types_count_map[ $type ]) ? $types_count_map[ $type ] : 0; |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * Prepares the select statement part for for structured type selects. |
|
249 | + * |
|
250 | + * @param array $select_parts |
|
251 | + * @param string $alias |
|
252 | + * @return string |
|
253 | + * @throws InvalidArgumentException |
|
254 | + */ |
|
255 | + private function assembleSelectStringWithOperator(array $select_parts, $alias) |
|
256 | + { |
|
257 | + $operator = strtoupper($select_parts[1]); |
|
258 | + // validate operator |
|
259 | + if (! in_array($operator, $this->valid_operators, true)) { |
|
260 | + throw new InvalidArgumentException( |
|
261 | + sprintf( |
|
262 | + esc_html__( |
|
263 | + 'An invalid operator has been provided (%1$s) for the column %2$s. Valid operators must be one of the following: %3$s.', |
|
264 | + 'event_espresso' |
|
265 | + ), |
|
266 | + $operator, |
|
267 | + $alias, |
|
268 | + implode(', ', $this->valid_operators) |
|
269 | + ) |
|
270 | + ); |
|
271 | + } |
|
272 | + return $operator . '(' . $select_parts[0] . ') AS ' . $alias; |
|
273 | + } |
|
274 | + |
|
275 | + |
|
276 | + /** |
|
277 | + * Return the datatype from the given select part. |
|
278 | + * Remember the select_part has already been validated on object instantiation. |
|
279 | + * |
|
280 | + * @param array $select_part |
|
281 | + * @return string |
|
282 | + */ |
|
283 | + private function getDataTypeForSelectType(array $select_part) |
|
284 | + { |
|
285 | + switch ($this->type) { |
|
286 | + case self::TYPE_COMPLEX: |
|
287 | + return $select_part[1]; |
|
288 | + case self::TYPE_STRUCTURED: |
|
289 | + return $select_part[2]; |
|
290 | + default: |
|
291 | + return ''; |
|
292 | + } |
|
293 | + } |
|
294 | + |
|
295 | + |
|
296 | + /** |
|
297 | + * Returns the original select array sent into the VO. |
|
298 | + * |
|
299 | + * @return array |
|
300 | + */ |
|
301 | + public function originalSelects() |
|
302 | + { |
|
303 | + return $this->original_selects; |
|
304 | + } |
|
305 | + |
|
306 | + |
|
307 | + /** |
|
308 | + * Returns the final assembled select expression derived from the incoming select array. |
|
309 | + * |
|
310 | + * @return string |
|
311 | + */ |
|
312 | + public function columnsToSelectExpression() |
|
313 | + { |
|
314 | + return $this->columns_to_select_expression; |
|
315 | + } |
|
316 | + |
|
317 | + |
|
318 | + /** |
|
319 | + * Returns all the column aliases derived from the incoming select array. |
|
320 | + * |
|
321 | + * @return array |
|
322 | + */ |
|
323 | + public function columnAliases() |
|
324 | + { |
|
325 | + return $this->column_aliases_in_select; |
|
326 | + } |
|
327 | + |
|
328 | + |
|
329 | + /** |
|
330 | + * Returns the enum type for the incoming select array. |
|
331 | + * |
|
332 | + * @return string |
|
333 | + */ |
|
334 | + public function type() |
|
335 | + { |
|
336 | + return $this->type; |
|
337 | + } |
|
338 | + |
|
339 | + |
|
340 | + /** |
|
341 | + * Return the datatype for the given column_alias |
|
342 | + * |
|
343 | + * @param string $column_alias |
|
344 | + * @return string (if there's no data type we return string as the default). |
|
345 | + */ |
|
346 | + public function getDataTypeForAlias($column_alias) |
|
347 | + { |
|
348 | + if (isset($this->original_selects[ $column_alias ]) |
|
349 | + && in_array($column_alias, $this->columnAliases(), true) |
|
350 | + ) { |
|
351 | + return $this->getDataTypeForSelectType($this->original_selects[ $column_alias ]); |
|
352 | + } |
|
353 | + return '%s'; |
|
354 | + } |
|
355 | 355 | } |
@@ -107,11 +107,11 @@ discard block |
||
107 | 107 | // let's ensure all keys are ints |
108 | 108 | $invalid_keys = array_filter( |
109 | 109 | array_keys($selects), |
110 | - function ($value) { |
|
110 | + function($value) { |
|
111 | 111 | return ! is_int($value); |
112 | 112 | } |
113 | 113 | ); |
114 | - if (! empty($invalid_keys)) { |
|
114 | + if ( ! empty($invalid_keys)) { |
|
115 | 115 | throw new InvalidArgumentException( |
116 | 116 | sprintf( |
117 | 117 | esc_html__( |
@@ -129,7 +129,7 @@ discard block |
||
129 | 129 | // the first array element off. |
130 | 130 | $first_element = reset($selects); |
131 | 131 | |
132 | - if (! is_array($first_element)) { |
|
132 | + if ( ! is_array($first_element)) { |
|
133 | 133 | throw new InvalidArgumentException( |
134 | 134 | sprintf( |
135 | 135 | esc_html__( |
@@ -210,7 +210,7 @@ discard block |
||
210 | 210 | $data_type = $this->type === self::TYPE_COMPLEX ? $select_parts[1] : ''; |
211 | 211 | $data_type = $this->type === self::TYPE_STRUCTURED ? $select_parts[2] : $data_type; |
212 | 212 | |
213 | - if (! in_array($data_type, $valid_data_types, true)) { |
|
213 | + if ( ! in_array($data_type, $valid_data_types, true)) { |
|
214 | 214 | throw new InvalidArgumentException( |
215 | 215 | sprintf( |
216 | 216 | esc_html__( |
@@ -240,7 +240,7 @@ discard block |
||
240 | 240 | self::TYPE_COMPLEX => 2, |
241 | 241 | self::TYPE_STRUCTURED => 3, |
242 | 242 | ); |
243 | - return isset($types_count_map[ $type ]) ? $types_count_map[ $type ] : 0; |
|
243 | + return isset($types_count_map[$type]) ? $types_count_map[$type] : 0; |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | { |
257 | 257 | $operator = strtoupper($select_parts[1]); |
258 | 258 | // validate operator |
259 | - if (! in_array($operator, $this->valid_operators, true)) { |
|
259 | + if ( ! in_array($operator, $this->valid_operators, true)) { |
|
260 | 260 | throw new InvalidArgumentException( |
261 | 261 | sprintf( |
262 | 262 | esc_html__( |
@@ -269,7 +269,7 @@ discard block |
||
269 | 269 | ) |
270 | 270 | ); |
271 | 271 | } |
272 | - return $operator . '(' . $select_parts[0] . ') AS ' . $alias; |
|
272 | + return $operator.'('.$select_parts[0].') AS '.$alias; |
|
273 | 273 | } |
274 | 274 | |
275 | 275 | |
@@ -345,10 +345,10 @@ discard block |
||
345 | 345 | */ |
346 | 346 | public function getDataTypeForAlias($column_alias) |
347 | 347 | { |
348 | - if (isset($this->original_selects[ $column_alias ]) |
|
348 | + if (isset($this->original_selects[$column_alias]) |
|
349 | 349 | && in_array($column_alias, $this->columnAliases(), true) |
350 | 350 | ) { |
351 | - return $this->getDataTypeForSelectType($this->original_selects[ $column_alias ]); |
|
351 | + return $this->getDataTypeForSelectType($this->original_selects[$column_alias]); |
|
352 | 352 | } |
353 | 353 | return '%s'; |
354 | 354 | } |
@@ -70,44 +70,44 @@ |
||
70 | 70 | class LoaderFactory |
71 | 71 | { |
72 | 72 | |
73 | - /** |
|
74 | - * @var LoaderInterface $loader ; |
|
75 | - */ |
|
76 | - private static $loader; |
|
73 | + /** |
|
74 | + * @var LoaderInterface $loader ; |
|
75 | + */ |
|
76 | + private static $loader; |
|
77 | 77 | |
78 | 78 | |
79 | - /** |
|
80 | - * @param EE_Registry|CoffeeShop $generator provided during very first instantiation in |
|
81 | - * BootstrapDependencyInjectionContainer::buildLoader() |
|
82 | - * otherwise can be left null |
|
83 | - * @param ClassInterfaceCache|null $class_cache also provided during first instantiation |
|
84 | - * @param ObjectIdentifier|null $object_identifier |
|
85 | - * @return LoaderInterface |
|
86 | - * @throws InvalidArgumentException |
|
87 | - * @throws InvalidDataTypeException |
|
88 | - * @throws InvalidInterfaceException |
|
89 | - */ |
|
90 | - public static function getLoader( |
|
91 | - $generator = null, |
|
92 | - ClassInterfaceCache $class_cache = null, |
|
93 | - ObjectIdentifier $object_identifier = null |
|
94 | - ) { |
|
95 | - if (! LoaderFactory::$loader instanceof LoaderInterface |
|
96 | - && ($generator instanceof EE_Registry || $generator instanceof CoffeeShop) |
|
97 | - && $class_cache instanceof ClassInterfaceCache |
|
98 | - && $object_identifier instanceof ObjectIdentifier |
|
99 | - ) { |
|
100 | - $core_loader = new CoreLoader($generator); |
|
101 | - LoaderFactory::$loader = new Loader( |
|
102 | - $core_loader, |
|
103 | - new CachingLoader( |
|
104 | - $core_loader, |
|
105 | - new LooseCollection(''), |
|
106 | - $object_identifier |
|
107 | - ), |
|
108 | - $class_cache |
|
109 | - ); |
|
110 | - } |
|
111 | - return LoaderFactory::$loader; |
|
112 | - } |
|
79 | + /** |
|
80 | + * @param EE_Registry|CoffeeShop $generator provided during very first instantiation in |
|
81 | + * BootstrapDependencyInjectionContainer::buildLoader() |
|
82 | + * otherwise can be left null |
|
83 | + * @param ClassInterfaceCache|null $class_cache also provided during first instantiation |
|
84 | + * @param ObjectIdentifier|null $object_identifier |
|
85 | + * @return LoaderInterface |
|
86 | + * @throws InvalidArgumentException |
|
87 | + * @throws InvalidDataTypeException |
|
88 | + * @throws InvalidInterfaceException |
|
89 | + */ |
|
90 | + public static function getLoader( |
|
91 | + $generator = null, |
|
92 | + ClassInterfaceCache $class_cache = null, |
|
93 | + ObjectIdentifier $object_identifier = null |
|
94 | + ) { |
|
95 | + if (! LoaderFactory::$loader instanceof LoaderInterface |
|
96 | + && ($generator instanceof EE_Registry || $generator instanceof CoffeeShop) |
|
97 | + && $class_cache instanceof ClassInterfaceCache |
|
98 | + && $object_identifier instanceof ObjectIdentifier |
|
99 | + ) { |
|
100 | + $core_loader = new CoreLoader($generator); |
|
101 | + LoaderFactory::$loader = new Loader( |
|
102 | + $core_loader, |
|
103 | + new CachingLoader( |
|
104 | + $core_loader, |
|
105 | + new LooseCollection(''), |
|
106 | + $object_identifier |
|
107 | + ), |
|
108 | + $class_cache |
|
109 | + ); |
|
110 | + } |
|
111 | + return LoaderFactory::$loader; |
|
112 | + } |
|
113 | 113 | } |
@@ -92,7 +92,7 @@ |
||
92 | 92 | ClassInterfaceCache $class_cache = null, |
93 | 93 | ObjectIdentifier $object_identifier = null |
94 | 94 | ) { |
95 | - if (! LoaderFactory::$loader instanceof LoaderInterface |
|
95 | + if ( ! LoaderFactory::$loader instanceof LoaderInterface |
|
96 | 96 | && ($generator instanceof EE_Registry || $generator instanceof CoffeeShop) |
97 | 97 | && $class_cache instanceof ClassInterfaceCache |
98 | 98 | && $object_identifier instanceof ObjectIdentifier |