Completed
Branch FET-10416-autoload-b4-bootstra... (42a01c)
by
unknown
13:17
created
core/db_models/EEM_Ticket.model.php 2 patches
Indentation   +301 added lines, -301 removed lines patch added patch discarded remove patch
@@ -12,328 +12,328 @@
 block discarded – undo
12 12
 class EEM_Ticket extends EEM_Soft_Delete_Base
13 13
 {
14 14
 
15
-    /**
16
-     * private instance of the EEM_Ticket object
17
-     *
18
-     * @var EEM_Ticket $_instance
19
-     */
20
-    protected static $_instance;
15
+	/**
16
+	 * private instance of the EEM_Ticket object
17
+	 *
18
+	 * @var EEM_Ticket $_instance
19
+	 */
20
+	protected static $_instance;
21 21
 
22 22
 
23 23
 
24
-    /**
25
-     * private constructor to prevent direct creation
26
-     *
27
-     * @Constructor
28
-     * @access private
29
-     * @param string $timezone string representing the timezone we want to set for returned Date Time Strings
30
-     *                         (and any incoming timezone data that gets saved).
31
-     *                         Note this just sends the timezone info to the date time model field objects.
32
-     *                         Default is NULL
33
-     *                         (and will be assumed using the set timezone in the 'timezone_string' wp option)
34
-     * @throws EE_Error
35
-     */
36
-    protected function __construct($timezone)
37
-    {
38
-        $this->singular_item = esc_html__('Ticket', 'event_espresso');
39
-        $this->plural_item = esc_html__('Tickets', 'event_espresso');
40
-        $this->_tables = array(
41
-            'Ticket' => new EE_Primary_Table('esp_ticket', 'TKT_ID'),
42
-        );
43
-        $this->_fields = array(
44
-            'Ticket' => array(
45
-                'TKT_ID'          => new EE_Primary_Key_Int_Field(
46
-                    'TKT_ID',
47
-                    esc_html__('Ticket ID', 'event_espresso')
48
-                ),
49
-                'TTM_ID'          => new EE_Foreign_Key_Int_Field(
50
-                    'TTM_ID',
51
-                    esc_html__('Ticket Template ID', 'event_espresso'),
52
-                    false,
53
-                    0,
54
-                    'Ticket_Template'
55
-                ),
56
-                'TKT_name'        => new EE_Plain_Text_Field(
57
-                    'TKT_name',
58
-                    esc_html__('Ticket Name', 'event_espresso'),
59
-                    false,
60
-                    ''
61
-                ),
62
-                'TKT_description' => new EE_Post_Content_Field(
63
-                    'TKT_description',
64
-                    esc_html__('Description of Ticket', 'event_espresso'),
65
-                    false,
66
-                    ''
67
-                ),
68
-                'TKT_start_date'  => new EE_Datetime_Field(
69
-                    'TKT_start_date',
70
-                    esc_html__('Start time/date of Ticket', 'event_espresso'),
71
-                    false,
72
-                    EE_Datetime_Field::now,
73
-                    $timezone
74
-                ),
75
-                'TKT_end_date'    => new EE_Datetime_Field(
76
-                    'TKT_end_date',
77
-                    esc_html__('End time/date of Ticket', 'event_espresso'),
78
-                    false,
79
-                    EE_Datetime_Field::now,
80
-                    $timezone
81
-                ),
82
-                'TKT_min'         => new EE_Integer_Field(
83
-                    'TKT_min',
84
-                    esc_html__('Minimum quantity of this ticket that must be purchased', 'event_espresso'),
85
-                    false,
86
-                    0
87
-                ),
88
-                'TKT_max'         => new EE_Infinite_Integer_Field(
89
-                    'TKT_max',
90
-                    esc_html__(
91
-                        'Maximum quantity of this ticket that can be purchased in one transaction',
92
-                        'event_espresso'
93
-                    ),
94
-                    false,
95
-                    EE_INF
96
-                ),
97
-                'TKT_price'       => new EE_Money_Field(
98
-                    'TKT_price',
99
-                    esc_html__('Final calculated price for ticket', 'event_espresso'),
100
-                    false,
101
-                    0
102
-                ),
103
-                'TKT_sold'        => new EE_Integer_Field(
104
-                    'TKT_sold',
105
-                    esc_html__('Number of this ticket sold', 'event_espresso'),
106
-                    false,
107
-                    0
108
-                ),
109
-                'TKT_qty'         => new EE_Infinite_Integer_Field(
110
-                    'TKT_qty',
111
-                    esc_html__('Quantity of this ticket that is available', 'event_espresso'),
112
-                    false,
113
-                    EE_INF
114
-                ),
115
-                'TKT_reserved'    => new EE_Integer_Field(
116
-                    'TKT_reserved',
117
-                    esc_html__(
118
-                        'Quantity of this ticket that is reserved, but not yet fully purchased',
119
-                        'event_espresso'
120
-                    ),
121
-                    false,
122
-                    0
123
-                ),
124
-                'TKT_uses'        => new EE_Infinite_Integer_Field(
125
-                    'TKT_uses',
126
-                    esc_html__('Number of datetimes this ticket can be used at', 'event_espresso'),
127
-                    false,
128
-                    EE_INF
129
-                ),
130
-                'TKT_required'    => new EE_Boolean_Field(
131
-                    'TKT_required',
132
-                    esc_html__(
133
-                        'Flag indicating whether this ticket must be purchased with a transaction',
134
-                        'event_espresso'
135
-                    ),
136
-                    false,
137
-                    false
138
-                ),
139
-                'TKT_taxable'     => new EE_Boolean_Field(
140
-                    'TKT_taxable',
141
-                    esc_html__(
142
-                        'Flag indicating whether there is tax applied on this ticket',
143
-                        'event_espresso'
144
-                    ),
145
-                    false,
146
-                    false
147
-                ),
148
-                'TKT_is_default'  => new EE_Boolean_Field(
149
-                    'TKT_is_default',
150
-                    esc_html__('Flag indicating that this ticket is a default ticket', 'event_espresso'),
151
-                    false,
152
-                    false
153
-                ),
154
-                'TKT_order'       => new EE_Integer_Field(
155
-                    'TKT_order',
156
-                    esc_html__(
157
-                        'The order in which the Ticket is displayed in the editor (used for autosaves when the form doesn\'t have the ticket ID yet)',
158
-                        'event_espresso'
159
-                    ),
160
-                    false,
161
-                    0
162
-                ),
163
-                'TKT_row'         => new EE_Integer_Field(
164
-                    'TKT_row',
165
-                    esc_html__('How tickets are displayed in the ui', 'event_espresso'),
166
-                    false,
167
-                    0
168
-                ),
169
-                'TKT_deleted'     => new EE_Trashed_Flag_Field(
170
-                    'TKT_deleted',
171
-                    esc_html__('Flag indicating if this has been archived or not', 'event_espresso'),
172
-                    false,
173
-                    false
174
-                ),
175
-                'TKT_wp_user'     => new EE_WP_User_Field(
176
-                    'TKT_wp_user',
177
-                    esc_html__('Ticket Creator ID', 'event_espresso'),
178
-                    false
179
-                ),
180
-                'TKT_parent'      => new EE_Integer_Field(
181
-                    'TKT_parent',
182
-                    esc_html__(
183
-                        'Indicates what TKT_ID is the parent of this TKT_ID (used in autosaves/revisions)',
184
-                        'event_espresso'
185
-                    ),
186
-                    true,
187
-                    0
188
-                ),
189
-            ),
190
-        );
191
-        $this->_model_relations = array(
192
-            'Datetime'        => new EE_HABTM_Relation('Datetime_Ticket'),
193
-            'Datetime_Ticket' => new EE_Has_Many_Relation(),
194
-            'Price'           => new EE_HABTM_Relation('Ticket_Price'),
195
-            'Ticket_Template' => new EE_Belongs_To_Relation(),
196
-            'Registration'    => new EE_Has_Many_Relation(),
197
-            'WP_User'         => new EE_Belongs_To_Relation(),
198
-        );
199
-        //this model is generally available for reading
200
-        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Default_Public(
201
-            'TKT_is_default',
202
-            'Datetime.Event'
203
-        );
204
-        //account for default tickets in the caps
205
-        $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Default_Protected(
206
-            'TKT_is_default',
207
-            'Datetime.Event'
208
-        );
209
-        $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Default_Protected(
210
-            'TKT_is_default',
211
-            'Datetime.Event'
212
-        );
213
-        $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Default_Protected(
214
-            'TKT_is_default',
215
-            'Datetime.Event'
216
-        );
217
-        parent::__construct($timezone);
218
-    }
24
+	/**
25
+	 * private constructor to prevent direct creation
26
+	 *
27
+	 * @Constructor
28
+	 * @access private
29
+	 * @param string $timezone string representing the timezone we want to set for returned Date Time Strings
30
+	 *                         (and any incoming timezone data that gets saved).
31
+	 *                         Note this just sends the timezone info to the date time model field objects.
32
+	 *                         Default is NULL
33
+	 *                         (and will be assumed using the set timezone in the 'timezone_string' wp option)
34
+	 * @throws EE_Error
35
+	 */
36
+	protected function __construct($timezone)
37
+	{
38
+		$this->singular_item = esc_html__('Ticket', 'event_espresso');
39
+		$this->plural_item = esc_html__('Tickets', 'event_espresso');
40
+		$this->_tables = array(
41
+			'Ticket' => new EE_Primary_Table('esp_ticket', 'TKT_ID'),
42
+		);
43
+		$this->_fields = array(
44
+			'Ticket' => array(
45
+				'TKT_ID'          => new EE_Primary_Key_Int_Field(
46
+					'TKT_ID',
47
+					esc_html__('Ticket ID', 'event_espresso')
48
+				),
49
+				'TTM_ID'          => new EE_Foreign_Key_Int_Field(
50
+					'TTM_ID',
51
+					esc_html__('Ticket Template ID', 'event_espresso'),
52
+					false,
53
+					0,
54
+					'Ticket_Template'
55
+				),
56
+				'TKT_name'        => new EE_Plain_Text_Field(
57
+					'TKT_name',
58
+					esc_html__('Ticket Name', 'event_espresso'),
59
+					false,
60
+					''
61
+				),
62
+				'TKT_description' => new EE_Post_Content_Field(
63
+					'TKT_description',
64
+					esc_html__('Description of Ticket', 'event_espresso'),
65
+					false,
66
+					''
67
+				),
68
+				'TKT_start_date'  => new EE_Datetime_Field(
69
+					'TKT_start_date',
70
+					esc_html__('Start time/date of Ticket', 'event_espresso'),
71
+					false,
72
+					EE_Datetime_Field::now,
73
+					$timezone
74
+				),
75
+				'TKT_end_date'    => new EE_Datetime_Field(
76
+					'TKT_end_date',
77
+					esc_html__('End time/date of Ticket', 'event_espresso'),
78
+					false,
79
+					EE_Datetime_Field::now,
80
+					$timezone
81
+				),
82
+				'TKT_min'         => new EE_Integer_Field(
83
+					'TKT_min',
84
+					esc_html__('Minimum quantity of this ticket that must be purchased', 'event_espresso'),
85
+					false,
86
+					0
87
+				),
88
+				'TKT_max'         => new EE_Infinite_Integer_Field(
89
+					'TKT_max',
90
+					esc_html__(
91
+						'Maximum quantity of this ticket that can be purchased in one transaction',
92
+						'event_espresso'
93
+					),
94
+					false,
95
+					EE_INF
96
+				),
97
+				'TKT_price'       => new EE_Money_Field(
98
+					'TKT_price',
99
+					esc_html__('Final calculated price for ticket', 'event_espresso'),
100
+					false,
101
+					0
102
+				),
103
+				'TKT_sold'        => new EE_Integer_Field(
104
+					'TKT_sold',
105
+					esc_html__('Number of this ticket sold', 'event_espresso'),
106
+					false,
107
+					0
108
+				),
109
+				'TKT_qty'         => new EE_Infinite_Integer_Field(
110
+					'TKT_qty',
111
+					esc_html__('Quantity of this ticket that is available', 'event_espresso'),
112
+					false,
113
+					EE_INF
114
+				),
115
+				'TKT_reserved'    => new EE_Integer_Field(
116
+					'TKT_reserved',
117
+					esc_html__(
118
+						'Quantity of this ticket that is reserved, but not yet fully purchased',
119
+						'event_espresso'
120
+					),
121
+					false,
122
+					0
123
+				),
124
+				'TKT_uses'        => new EE_Infinite_Integer_Field(
125
+					'TKT_uses',
126
+					esc_html__('Number of datetimes this ticket can be used at', 'event_espresso'),
127
+					false,
128
+					EE_INF
129
+				),
130
+				'TKT_required'    => new EE_Boolean_Field(
131
+					'TKT_required',
132
+					esc_html__(
133
+						'Flag indicating whether this ticket must be purchased with a transaction',
134
+						'event_espresso'
135
+					),
136
+					false,
137
+					false
138
+				),
139
+				'TKT_taxable'     => new EE_Boolean_Field(
140
+					'TKT_taxable',
141
+					esc_html__(
142
+						'Flag indicating whether there is tax applied on this ticket',
143
+						'event_espresso'
144
+					),
145
+					false,
146
+					false
147
+				),
148
+				'TKT_is_default'  => new EE_Boolean_Field(
149
+					'TKT_is_default',
150
+					esc_html__('Flag indicating that this ticket is a default ticket', 'event_espresso'),
151
+					false,
152
+					false
153
+				),
154
+				'TKT_order'       => new EE_Integer_Field(
155
+					'TKT_order',
156
+					esc_html__(
157
+						'The order in which the Ticket is displayed in the editor (used for autosaves when the form doesn\'t have the ticket ID yet)',
158
+						'event_espresso'
159
+					),
160
+					false,
161
+					0
162
+				),
163
+				'TKT_row'         => new EE_Integer_Field(
164
+					'TKT_row',
165
+					esc_html__('How tickets are displayed in the ui', 'event_espresso'),
166
+					false,
167
+					0
168
+				),
169
+				'TKT_deleted'     => new EE_Trashed_Flag_Field(
170
+					'TKT_deleted',
171
+					esc_html__('Flag indicating if this has been archived or not', 'event_espresso'),
172
+					false,
173
+					false
174
+				),
175
+				'TKT_wp_user'     => new EE_WP_User_Field(
176
+					'TKT_wp_user',
177
+					esc_html__('Ticket Creator ID', 'event_espresso'),
178
+					false
179
+				),
180
+				'TKT_parent'      => new EE_Integer_Field(
181
+					'TKT_parent',
182
+					esc_html__(
183
+						'Indicates what TKT_ID is the parent of this TKT_ID (used in autosaves/revisions)',
184
+						'event_espresso'
185
+					),
186
+					true,
187
+					0
188
+				),
189
+			),
190
+		);
191
+		$this->_model_relations = array(
192
+			'Datetime'        => new EE_HABTM_Relation('Datetime_Ticket'),
193
+			'Datetime_Ticket' => new EE_Has_Many_Relation(),
194
+			'Price'           => new EE_HABTM_Relation('Ticket_Price'),
195
+			'Ticket_Template' => new EE_Belongs_To_Relation(),
196
+			'Registration'    => new EE_Has_Many_Relation(),
197
+			'WP_User'         => new EE_Belongs_To_Relation(),
198
+		);
199
+		//this model is generally available for reading
200
+		$this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Default_Public(
201
+			'TKT_is_default',
202
+			'Datetime.Event'
203
+		);
204
+		//account for default tickets in the caps
205
+		$this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Default_Protected(
206
+			'TKT_is_default',
207
+			'Datetime.Event'
208
+		);
209
+		$this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Default_Protected(
210
+			'TKT_is_default',
211
+			'Datetime.Event'
212
+		);
213
+		$this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Default_Protected(
214
+			'TKT_is_default',
215
+			'Datetime.Event'
216
+		);
217
+		parent::__construct($timezone);
218
+	}
219 219
 
220 220
 
221 221
 
222
-    /**
223
-     * This returns all tickets that are defaults from the db
224
-     *
225
-     * @return EE_Ticket[]
226
-     * @throws EE_Error
227
-     */
228
-    public function get_all_default_tickets()
229
-    {
230
-        /** @type EE_Ticket[] $tickets */
231
-        $tickets = $this->get_all(array(array('TKT_is_default' => 1), 'order_by' => array('TKT_ID' => 'ASC')));
232
-        //we need to set the start date and end date to today's date and the start of the default dtt
233
-        return $this->_set_default_dates($tickets);
234
-    }
222
+	/**
223
+	 * This returns all tickets that are defaults from the db
224
+	 *
225
+	 * @return EE_Ticket[]
226
+	 * @throws EE_Error
227
+	 */
228
+	public function get_all_default_tickets()
229
+	{
230
+		/** @type EE_Ticket[] $tickets */
231
+		$tickets = $this->get_all(array(array('TKT_is_default' => 1), 'order_by' => array('TKT_ID' => 'ASC')));
232
+		//we need to set the start date and end date to today's date and the start of the default dtt
233
+		return $this->_set_default_dates($tickets);
234
+	}
235 235
 
236 236
 
237 237
 
238
-    /**
239
-     * sets up relevant start and end date for EE_Ticket (s)
240
-     *
241
-     * @param EE_Ticket[] $tickets
242
-     * @return EE_Ticket[]
243
-     * @throws EE_Error
244
-     */
245
-    private function _set_default_dates($tickets)
246
-    {
247
-        foreach ($tickets as $ticket) {
248
-            $ticket->set(
249
-                'TKT_start_date',
250
-                (int)$this->current_time_for_query('TKT_start_date', true)
251
-            );
252
-            $ticket->set(
253
-                'TKT_end_date',
254
-                (int)$this->current_time_for_query('TKT_end_date', true) + MONTH_IN_SECONDS
255
-            );
256
-            $ticket->set_end_time(
257
-                $this->convert_datetime_for_query(
258
-                    'TKT_end_date',
259
-                    '11:59 pm',
260
-                    'g:i a', $this->_timezone
261
-                )
262
-            );
263
-        }
264
-        return $tickets;
265
-    }
238
+	/**
239
+	 * sets up relevant start and end date for EE_Ticket (s)
240
+	 *
241
+	 * @param EE_Ticket[] $tickets
242
+	 * @return EE_Ticket[]
243
+	 * @throws EE_Error
244
+	 */
245
+	private function _set_default_dates($tickets)
246
+	{
247
+		foreach ($tickets as $ticket) {
248
+			$ticket->set(
249
+				'TKT_start_date',
250
+				(int)$this->current_time_for_query('TKT_start_date', true)
251
+			);
252
+			$ticket->set(
253
+				'TKT_end_date',
254
+				(int)$this->current_time_for_query('TKT_end_date', true) + MONTH_IN_SECONDS
255
+			);
256
+			$ticket->set_end_time(
257
+				$this->convert_datetime_for_query(
258
+					'TKT_end_date',
259
+					'11:59 pm',
260
+					'g:i a', $this->_timezone
261
+				)
262
+			);
263
+		}
264
+		return $tickets;
265
+	}
266 266
 
267 267
 
268 268
 
269
-    /**
270
-     * Gets the total number of tickets available at a particular datetime (does
271
-     * NOT take int account the datetime's spaces available)
272
-     *
273
-     * @param int   $DTT_ID
274
-     * @param array $query_params
275
-     * @return int
276
-     */
277
-    public function sum_tickets_currently_available_at_datetime($DTT_ID, $query_params = array())
278
-    {
279
-        return EEM_Datetime::instance()->sum_tickets_currently_available_at_datetime($DTT_ID, $query_params);
280
-    }
269
+	/**
270
+	 * Gets the total number of tickets available at a particular datetime (does
271
+	 * NOT take int account the datetime's spaces available)
272
+	 *
273
+	 * @param int   $DTT_ID
274
+	 * @param array $query_params
275
+	 * @return int
276
+	 */
277
+	public function sum_tickets_currently_available_at_datetime($DTT_ID, $query_params = array())
278
+	{
279
+		return EEM_Datetime::instance()->sum_tickets_currently_available_at_datetime($DTT_ID, $query_params);
280
+	}
281 281
 
282 282
 
283 283
 
284
-    /**
285
-     * Updates the TKT_sold quantity on all the tickets matching $query_params
286
-     *
287
-     * @param EE_Ticket[] $tickets
288
-     * @return void
289
-     * @throws EE_Error
290
-     */
291
-    public function update_tickets_sold($tickets)
292
-    {
293
-        foreach ($tickets as $ticket) {
294
-            /* @var  $ticket EE_Ticket */
295
-            $ticket->update_tickets_sold();
296
-        }
297
-    }
284
+	/**
285
+	 * Updates the TKT_sold quantity on all the tickets matching $query_params
286
+	 *
287
+	 * @param EE_Ticket[] $tickets
288
+	 * @return void
289
+	 * @throws EE_Error
290
+	 */
291
+	public function update_tickets_sold($tickets)
292
+	{
293
+		foreach ($tickets as $ticket) {
294
+			/* @var  $ticket EE_Ticket */
295
+			$ticket->update_tickets_sold();
296
+		}
297
+	}
298 298
 
299 299
 
300 300
 
301
-    /**
302
-     * returns an array of EE_Ticket objects with a non-zero value for TKT_reserved
303
-     *
304
-     * @return EE_Base_Class[]|EE_Ticket[]
305
-     * @throws EE_Error
306
-     */
307
-    public function get_tickets_with_reservations()
308
-    {
309
-        return $this->get_all(
310
-            array(
311
-                array(
312
-                    'TKT_reserved' => array('>', 0),
313
-                ),
314
-            )
315
-        );
316
-    }
301
+	/**
302
+	 * returns an array of EE_Ticket objects with a non-zero value for TKT_reserved
303
+	 *
304
+	 * @return EE_Base_Class[]|EE_Ticket[]
305
+	 * @throws EE_Error
306
+	 */
307
+	public function get_tickets_with_reservations()
308
+	{
309
+		return $this->get_all(
310
+			array(
311
+				array(
312
+					'TKT_reserved' => array('>', 0),
313
+				),
314
+			)
315
+		);
316
+	}
317 317
 
318 318
 
319 319
 
320
-    /**
321
-     * returns an array of EE_Ticket objects matching the supplied list of IDs
322
-     *
323
-     * @param array $ticket_IDs
324
-     * @return EE_Base_Class[]|EE_Ticket[]
325
-     * @throws EE_Error
326
-     */
327
-    public function get_tickets_with_IDs(array $ticket_IDs)
328
-    {
329
-        return $this->get_all(
330
-            array(
331
-                array(
332
-                    'TKT_ID' => array('IN', $ticket_IDs)
333
-                )
334
-            )
335
-        );
336
-    }
320
+	/**
321
+	 * returns an array of EE_Ticket objects matching the supplied list of IDs
322
+	 *
323
+	 * @param array $ticket_IDs
324
+	 * @return EE_Base_Class[]|EE_Ticket[]
325
+	 * @throws EE_Error
326
+	 */
327
+	public function get_tickets_with_IDs(array $ticket_IDs)
328
+	{
329
+		return $this->get_all(
330
+			array(
331
+				array(
332
+					'TKT_ID' => array('IN', $ticket_IDs)
333
+				)
334
+			)
335
+		);
336
+	}
337 337
 
338 338
 
339 339
 
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -247,11 +247,11 @@
 block discarded – undo
247 247
         foreach ($tickets as $ticket) {
248 248
             $ticket->set(
249 249
                 'TKT_start_date',
250
-                (int)$this->current_time_for_query('TKT_start_date', true)
250
+                (int) $this->current_time_for_query('TKT_start_date', true)
251 251
             );
252 252
             $ticket->set(
253 253
                 'TKT_end_date',
254
-                (int)$this->current_time_for_query('TKT_end_date', true) + MONTH_IN_SECONDS
254
+                (int) $this->current_time_for_query('TKT_end_date', true) + MONTH_IN_SECONDS
255 255
             );
256 256
             $ticket->set_end_time(
257 257
                 $this->convert_datetime_for_query(
Please login to merge, or discard this patch.
public/Espresso_Arabica_2014/loop-espresso_events.php 2 patches
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -11,48 +11,48 @@
 block discarded – undo
11 11
  * @version     4+
12 12
  */
13 13
 if (have_posts()) :
14
-    if (apply_filters('FHEE__archive_espresso_events_template__show_header', true)) : ?>
14
+	if (apply_filters('FHEE__archive_espresso_events_template__show_header', true)) : ?>
15 15
         <header class="page-header">
16 16
             <h1 class="page-title">
17 17
                 <?php
18
-                if (is_day()) :
19
-                    printf(__('Today\'s Events: %s', 'event_espresso'), get_the_date());
20
-                elseif (is_month()) :
21
-                    printf(
22
-                        __('Events This Month: %s', 'event_espresso'),
23
-                        get_the_date(_x('F Y', 'monthly archives date format', 'event_espresso'))
24
-                    );
25
-                elseif (is_year()) :
26
-                    printf(
27
-                        __('Events This Year: %s', 'event_espresso'),
28
-                        get_the_date(_x('Y', 'yearly archives date format', 'event_espresso'))
29
-                    );
30
-                else :
31
-                    echo apply_filters(
32
-                        'FHEE__archive_espresso_events_template__upcoming_events_h1',
33
-                        __('Upcoming Events', 'event_espresso')
34
-                    );
35
-                endif;
36
-                ?>
18
+				if (is_day()) :
19
+					printf(__('Today\'s Events: %s', 'event_espresso'), get_the_date());
20
+				elseif (is_month()) :
21
+					printf(
22
+						__('Events This Month: %s', 'event_espresso'),
23
+						get_the_date(_x('F Y', 'monthly archives date format', 'event_espresso'))
24
+					);
25
+				elseif (is_year()) :
26
+					printf(
27
+						__('Events This Year: %s', 'event_espresso'),
28
+						get_the_date(_x('Y', 'yearly archives date format', 'event_espresso'))
29
+					);
30
+				else :
31
+					echo apply_filters(
32
+						'FHEE__archive_espresso_events_template__upcoming_events_h1',
33
+						__('Upcoming Events', 'event_espresso')
34
+					);
35
+				endif;
36
+				?>
37 37
             </h1>
38 38
 
39 39
         </header><!-- .page-header -->
40 40
 
41 41
         <?php
42
-    endif;
43
-    // allow other stuff
44
-    do_action('AHEE__archive_espresso_events_template__before_loop');
45
-    // Start the Loop.
46
-    while (have_posts()) : the_post();
47
-        // Include the post TYPE-specific template for the content.
48
-        espresso_get_template_part('content', 'espresso_events-shortcode');
49
-    endwhile;
50
-    // Previous/next page navigation.
51
-    espresso_pagination();
52
-    // allow moar other stuff
53
-    do_action('AHEE__archive_espresso_events_template__after_loop');
42
+	endif;
43
+	// allow other stuff
44
+	do_action('AHEE__archive_espresso_events_template__before_loop');
45
+	// Start the Loop.
46
+	while (have_posts()) : the_post();
47
+		// Include the post TYPE-specific template for the content.
48
+		espresso_get_template_part('content', 'espresso_events-shortcode');
49
+	endwhile;
50
+	// Previous/next page navigation.
51
+	espresso_pagination();
52
+	// allow moar other stuff
53
+	do_action('AHEE__archive_espresso_events_template__after_loop');
54 54
 else :
55
-    // If no content, include the "No posts found" template.
56
-    espresso_get_template_part('content', 'none');
55
+	// If no content, include the "No posts found" template.
56
+	espresso_get_template_part('content', 'none');
57 57
 endif;
58 58
 
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -27,11 +27,13 @@  discard block
 block discarded – undo
27 27
                         __('Events This Year: %s', 'event_espresso'),
28 28
                         get_the_date(_x('Y', 'yearly archives date format', 'event_espresso'))
29 29
                     );
30
-                else :
30
+                else {
31
+                	:
31 32
                     echo apply_filters(
32 33
                         'FHEE__archive_espresso_events_template__upcoming_events_h1',
33 34
                         __('Upcoming Events', 'event_espresso')
34 35
                     );
36
+                }
35 37
                 endif;
36 38
                 ?>
37 39
             </h1>
@@ -51,8 +53,10 @@  discard block
 block discarded – undo
51 53
     espresso_pagination();
52 54
     // allow moar other stuff
53 55
     do_action('AHEE__archive_espresso_events_template__after_loop');
54
-else :
56
+else {
57
+	:
55 58
     // If no content, include the "No posts found" template.
56 59
     espresso_get_template_part('content', 'none');
60
+}
57 61
 endif;
58 62
 
Please login to merge, or discard this patch.
templates/support_admin_details_shortcodes_event_listings.template.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <div class="padding">
2 2
 	<p>
3
-        <?php esc_html_e('Displays a list of events based on a set of criteria on a WordPress page or post. Unless otherwise specified, events are sorted by start date.', 'event_espresso'); ?> <?php echo sprintf( esc_html__('For a full list of available shortcodes, please view the %sshortcode documentation%s on our website.', 'event_espresso'), '<a href="https://eventespresso.com/wiki/ee4-shortcodes-template-variables/">', '</a>' ); ?>
3
+        <?php esc_html_e('Displays a list of events based on a set of criteria on a WordPress page or post. Unless otherwise specified, events are sorted by start date.', 'event_espresso'); ?> <?php echo sprintf(esc_html__('For a full list of available shortcodes, please view the %sshortcode documentation%s on our website.', 'event_espresso'), '<a href="https://eventespresso.com/wiki/ee4-shortcodes-template-variables/">', '</a>'); ?>
4 4
     </p>
5 5
 		<ul>
6 6
 			<li><strong><?php esc_html_e('Show a list of all of your events', 'event_espresso'); ?></strong><br /> [ESPRESSO_EVENTS]</li>
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 			<li><strong><?php esc_html_e('Don\'t display a title/heading before the event list', 'event_espresso'); ?></strong><br /> [ESPRESSO_EVENTS show_title=false]</li>
9 9
 			<li><strong><?php esc_html_e('Limit (paginate) the number of events that are shown in the event list on a page or post', 'event_espresso'); ?></strong><br />[ESPRESSO_EVENTS limit=5]</li>
10 10
 			<li><strong><?php esc_html_e('Add a custom CSS class to each event post/article', 'event_espresso'); ?></strong><br /> [ESPRESSO_EVENTS css_class=my-custom-class]</li>
11
-			<li><strong><?php esc_html_e('Filter the event list by month and year', 'event_espresso'); ?></strong><br />[ESPRESSO_EVENTS month="<?php echo date( 'F Y' ); ?>"]</li>
11
+			<li><strong><?php esc_html_e('Filter the event list by month and year', 'event_espresso'); ?></strong><br />[ESPRESSO_EVENTS month="<?php echo date('F Y'); ?>"]</li>
12 12
 			<li><strong><?php esc_html_e('Show expired events in the event list', 'event_espresso'); ?></strong><br />[ESPRESSO_EVENTS show_expired=true]</li>
13 13
 			<li><strong><?php esc_html_e('Sorts the event list in ascending order', 'event_espresso'); ?></strong><br />[ESPRESSO_EVENTS sort=ASC]</li>
14 14
 			<li><strong><?php esc_html_e('Sorts the event list in descending order', 'event_espresso'); ?></strong><br />[ESPRESSO_EVENTS sort=DESC]</li>
Please login to merge, or discard this patch.
caffeinated/payment_methods/Paypal_Pro/EEG_Paypal_Pro.gateway.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -450,7 +450,7 @@
 block discarded – undo
450 450
 
451 451
 
452 452
     /**
453
-     * @param $Request
453
+     * @param string $Request
454 454
      * @return mixed
455 455
      */
456 456
     private function _CURLRequest($Request)
Please login to merge, or discard this patch.
Indentation   +587 added lines, -587 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if (! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('No direct script access allowed');
3
+	exit('No direct script access allowed');
4 4
 }
5 5
 
6 6
 
@@ -25,591 +25,591 @@  discard block
 block discarded – undo
25 25
 class EEG_Paypal_Pro extends EE_Onsite_Gateway
26 26
 {
27 27
 
28
-    /**
29
-     * @var $_paypal_api_username string
30
-     */
31
-    protected $_username = null;
32
-
33
-    /**
34
-     * @var $_password string
35
-     */
36
-    protected $_password = null;
37
-
38
-    /**
39
-     * @var $_signature string
40
-     */
41
-    protected $_signature = null;
42
-
43
-    /**
44
-     * @var $_credit_card_types array with the keys for credit card types accepted on this account
45
-     */
46
-    protected $_credit_card_types    = null;
47
-
48
-    protected $_currencies_supported = array(
49
-        'USD',
50
-        'GBP',
51
-        'CAD',
52
-        'AUD',
53
-        'BRL',
54
-        'CHF',
55
-        'CZK',
56
-        'DKK',
57
-        'EUR',
58
-        'HKD',
59
-        'HUF',
60
-        'ILS',
61
-        'JPY',
62
-        'MXN',
63
-        'MYR',
64
-        'NOK',
65
-        'NZD',
66
-        'PHP',
67
-        'PLN',
68
-        'SEK',
69
-        'SGD',
70
-        'THB',
71
-        'TRY',
72
-        'TWD',
73
-        'RUB',
74
-    );
75
-
76
-
77
-
78
-    /**
79
-     * @param EEI_Payment $payment
80
-     * @param array       $billing_info {
81
-     * @type string $credit_card
82
-     * @type string $credit_card_type
83
-     * @type string $exp_month always 2 characters
84
-     * @type string $exp_year always 4 characters
85
-     * @type string $cvv
86
-     * }
87
-     * @see      parent::do_direct_payment for more info
88
-     * @return EE_Payment|EEI_Payment
89
-     * @throws EE_Error
90
-     */
91
-    public function do_direct_payment($payment, $billing_info = null)
92
-    {
93
-        $transaction = $payment->transaction();
94
-        if (! $transaction instanceof EEI_Transaction) {
95
-            throw new EE_Error(
96
-                esc_html__('No transaction for payment while paying with PayPal Pro.', 'event_espresso')
97
-            );
98
-        }
99
-        $primary_registrant = $transaction->primary_registration();
100
-        if (! $primary_registrant instanceof EEI_Registration) {
101
-            throw new EE_Error(
102
-                esc_html__(
103
-                    'No primary registration on transaction while paying with PayPal Pro.',
104
-                    'event_espresso'
105
-                )
106
-            );
107
-        }
108
-        $attendee = $primary_registrant->attendee();
109
-        if (! $attendee instanceof EEI_Attendee) {
110
-            throw new EE_Error(
111
-                esc_html__(
112
-                    'No attendee on primary registration while paying with PayPal Pro.',
113
-                    'event_espresso'
114
-                )
115
-            );
116
-        }
117
-        $order_description = substr($this->_format_order_description($payment), 0, 127);
118
-        //charge for the full amount. Show itemized list
119
-        if ($this->_can_easily_itemize_transaction_for($payment)) {
120
-            $item_num = 1;
121
-            $total_line_item = $transaction->total_line_item();
122
-            $order_items = array();
123
-            foreach ($total_line_item->get_items() as $line_item) {
124
-                //ignore line items with a quantity of 0
125
-                if ($line_item->quantity() == 0) {
126
-                    continue;
127
-                }
128
-                $item = array(
129
-                    // Item Name.  127 char max.
130
-                    'l_name'                 => substr(
131
-                        $this->_format_line_item_name($line_item, $payment),
132
-                        0,
133
-                        127
134
-                    ),
135
-                    // Item description.  127 char max.
136
-                    'l_desc'                 => substr(
137
-                        $this->_format_line_item_desc($line_item, $payment),
138
-                        0,
139
-                        127
140
-                    ),
141
-                    // Cost of individual item.
142
-                    'l_amt'                  => $line_item->unit_price(),
143
-                    // Item Number.  127 char max.
144
-                    'l_number'               => $item_num++,
145
-                    // Item quantity.  Must be any positive integer.
146
-                    'l_qty'                  => $line_item->quantity(),
147
-                    // Item's sales tax amount.
148
-                    'l_taxamt'               => '',
149
-                    // eBay auction number of item.
150
-                    'l_ebayitemnumber'       => '',
151
-                    // eBay transaction ID of purchased item.
152
-                    'l_ebayitemauctiontxnid' => '',
153
-                    // eBay order ID for the item.
154
-                    'l_ebayitemorderid'      => '',
155
-                );
156
-                // add to array of all items
157
-                array_push($order_items, $item);
158
-            }
159
-            $item_amount = $total_line_item->get_items_total();
160
-            $tax_amount = $total_line_item->get_total_tax();
161
-        } else {
162
-            $order_items = array();
163
-            $item_amount = $payment->amount();
164
-            $tax_amount = 0;
165
-            array_push($order_items, array(
166
-                // Item Name.  127 char max.
167
-                'l_name'   => substr(
168
-                    $this->_format_partial_payment_line_item_name($payment),
169
-                    0,
170
-                    127
171
-                ),
172
-                // Item description.  127 char max.
173
-                'l_desc'   => substr(
174
-                    $this->_format_partial_payment_line_item_desc($payment),
175
-                    0,
176
-                    127
177
-                ),
178
-                // Cost of individual item.
179
-                'l_amt'    => $payment->amount(),
180
-                // Item Number.  127 char max.
181
-                'l_number' => 1,
182
-                // Item quantity.  Must be any positive integer.
183
-                'l_qty'    => 1,
184
-            ));
185
-        }
186
-        // Populate data arrays with order data.
187
-        $DPFields = array(
188
-            // How you want to obtain payment ?
189
-            // Authorization indicates the payment is a basic auth subject to settlement with Auth & Capture.
190
-            // Sale indicates that this is a final sale for which you are requesting payment.  Default is Sale.
191
-            'paymentaction'    => 'Sale',
192
-            // Required.  IP address of the payer's browser.
193
-            'ipaddress'        => $_SERVER['REMOTE_ADDR'],
194
-            // Flag to determine whether you want the results returned by FMF.  1 or 0.  Default is 0.
195
-            'returnfmfdetails' => '1',
196
-        );
197
-        $CCDetails = array(
198
-            // Required. Type of credit card.  Visa, MasterCard, Discover, Amex, Maestro, Solo.
199
-            // If Maestro or Solo, the currency code must be GBP.
200
-            //  In addition, either start date or issue number must be specified.
201
-            'creditcardtype' => $billing_info['credit_card_type'],
202
-            // Required.  Credit card number.  No spaces or punctuation.
203
-            'acct'           => $billing_info['credit_card'],
204
-            // Required.  Credit card expiration date.  Format is MMYYYY
205
-            'expdate'        => $billing_info['exp_month'] . $billing_info['exp_year'],
206
-            // Requirements determined by your PayPal account settings.  Security digits for credit card.
207
-            'cvv2'           => $billing_info['cvv'],
208
-        );
209
-        $PayerInfo = array(
210
-            // Email address of payer.
211
-            'email'       => $billing_info['email'],
212
-            // Unique PayPal customer ID for payer.
213
-            'payerid'     => '',
214
-            // Status of payer.  Values are verified or unverified
215
-            'payerstatus' => '',
216
-            // Payer's business name.
217
-            'business'    => '',
218
-        );
219
-        $PayerName = array(
220
-            // Payer's salutation.  20 char max.
221
-            'salutation' => '',
222
-            // Payer's first name.  25 char max.
223
-            'firstname'  => substr($billing_info['first_name'], 0, 25),
224
-            // Payer's middle name.  25 char max.
225
-            'middlename' => '',
226
-            // Payer's last name.  25 char max.
227
-            'lastname'   => substr($billing_info['last_name'], 0, 25),
228
-            // Payer's suffix.  12 char max.
229
-            'suffix'     => '',
230
-        );
231
-        $BillingAddress = array(
232
-            // Required.  First street address.
233
-            'street'      => $billing_info['address'],
234
-            // Second street address.
235
-            'street2'     => $billing_info['address2'],
236
-            // Required.  Name of City.
237
-            'city'        => $billing_info['city'],
238
-            // Required. Name of State or Province.
239
-            'state'       => substr($billing_info['state'], 0, 40),
240
-            // Required.  Country code.
241
-            'countrycode' => $billing_info['country'],
242
-            // Required.  Postal code of payer.
243
-            'zip'         => $billing_info['zip'],
244
-        );
245
-        //check if the registration info contains the needed fields for paypal pro
246
-        //(see https://developer.paypal.com/docs/classic/api/merchant/DoDirectPayment_API_Operation_NVP/)
247
-        if ($attendee->address() && $attendee->city() && $attendee->country_ID()) {
248
-            $use_registration_address_info = true;
249
-        } else {
250
-            $use_registration_address_info = false;
251
-        }
252
-        //so if the attendee has enough data to fill out PayPal Pro's shipping info, use it.
253
-        // If not, use the billing info again
254
-        $ShippingAddress = array(
255
-            'shiptoname'     => substr($use_registration_address_info
256
-                ? $attendee->full_name()
257
-                : $billing_info['first_name'] . ' ' . $billing_info['last_name'], 0, 32),
258
-            'shiptostreet'   => substr($use_registration_address_info
259
-                ? $attendee->address()
260
-                : $billing_info['address'], 0, 100),
261
-            'shiptostreet2'  => substr($use_registration_address_info
262
-                ? $attendee->address2() : $billing_info['address2'], 0, 100),
263
-            'shiptocity'     => substr($use_registration_address_info
264
-                ? $attendee->city()
265
-                : $billing_info['city'], 0, 40),
266
-            'state'          => substr($use_registration_address_info
267
-                ? $attendee->state_name()
268
-                : $billing_info['state'], 0, 40),
269
-            'shiptocountry'  => $use_registration_address_info
270
-                ? $attendee->country_ID()
271
-                : $billing_info['country'],
272
-            'shiptozip'      => substr($use_registration_address_info
273
-                ? $attendee->zip()
274
-                : $billing_info['zip'], 0, 20),
275
-            'shiptophonenum' => substr($use_registration_address_info
276
-                ? $attendee->phone()
277
-                : $billing_info['phone'], 0, 20),
278
-        );
279
-        $PaymentDetails = array(
280
-            // Required.  Total amount of order, including shipping, handling, and tax.
281
-            'amt'          => $this->format_currency($payment->amount()),
282
-            // Required.  Three-letter currency code.  Default is USD.
283
-            'currencycode' => $payment->currency_code(),
284
-            // Required if you include itemized cart details. (L_AMTn, etc.)
285
-            //Subtotal of items not including S&H, or tax.
286
-            'itemamt'      => $this->format_currency($item_amount),//
287
-            // Total shipping costs for the order.  If you specify shippingamt, you must also specify itemamt.
288
-            'shippingamt'  => '',
289
-            // Total handling costs for the order.  If you specify handlingamt, you must also specify itemamt.
290
-            'handlingamt'  => '',
291
-            // Required if you specify itemized cart tax details.
292
-            // Sum of tax for all items on the order.  Total sales tax.
293
-            'taxamt'       => $this->format_currency($tax_amount),
294
-            // Description of the order the customer is purchasing.  127 char max.
295
-            'desc'         => $order_description,
296
-            // Free-form field for your own use.  256 char max.
297
-            'custom'       => $primary_registrant ? $primary_registrant->ID() : '',
298
-            // Your own invoice or tracking number
299
-            'invnum'       => wp_generate_password(12, false),//$transaction->ID(),
300
-            // URL for receiving Instant Payment Notifications.  This overrides what your profile is set to use.
301
-            'notifyurl'    => '',
302
-            'buttonsource' => 'EventEspresso_SP',//EE will blow up if you change this
303
-        );
304
-        // Wrap all data arrays into a single, "master" array which will be passed into the class function.
305
-        $PayPalRequestData = array(
306
-            'DPFields'        => $DPFields,
307
-            'CCDetails'       => $CCDetails,
308
-            'PayerInfo'       => $PayerInfo,
309
-            'PayerName'       => $PayerName,
310
-            'BillingAddress'  => $BillingAddress,
311
-            'ShippingAddress' => $ShippingAddress,
312
-            'PaymentDetails'  => $PaymentDetails,
313
-            'OrderItems'      => $order_items,
314
-        );
315
-        $this->_log_clean_request($PayPalRequestData, $payment);
316
-        try {
317
-            $PayPalResult = $this->prep_and_curl_request($PayPalRequestData);
318
-            //remove PCI-sensitive data so it doesn't get stored
319
-            $PayPalResult = $this->_log_clean_response($PayPalResult, $payment);
320
-            $message = isset($PayPalResult['L_LONGMESSAGE0']) ? $PayPalResult['L_LONGMESSAGE0'] : $PayPalResult['ACK'];
321
-            if (empty($PayPalResult['RAWRESPONSE'])) {
322
-                $payment->set_status($this->_pay_model->failed_status());
323
-                $payment->set_gateway_response(__('No response received from Paypal Pro', 'event_espresso'));
324
-                $payment->set_details($PayPalResult);
325
-            } else {
326
-                if ($this->_APICallSuccessful($PayPalResult)) {
327
-                    $payment->set_status($this->_pay_model->approved_status());
328
-                } else {
329
-                    $payment->set_status($this->_pay_model->declined_status());
330
-                }
331
-                //make sure we interpret the AMT as a float, not an international string
332
-                // (where periods are thousand separators)
333
-                $payment->set_amount(isset($PayPalResult['AMT']) ? floatval($PayPalResult['AMT']) : 0);
334
-                $payment->set_gateway_response($message);
335
-                $payment->set_txn_id_chq_nmbr(isset($PayPalResult['TRANSACTIONID'])
336
-                    ? $PayPalResult['TRANSACTIONID']
337
-                    : null);
338
-                $primary_registration_code = $primary_registrant instanceof EE_Registration
339
-                    ? $primary_registrant->reg_code()
340
-                    : '';
341
-                $payment->set_extra_accntng($primary_registration_code);
342
-                $payment->set_details($PayPalResult);
343
-            }
344
-        } catch (Exception $e) {
345
-            $payment->set_status($this->_pay_model->failed_status());
346
-            $payment->set_gateway_response($e->getMessage());
347
-        }
348
-        //$payment->set_status( $this->_pay_model->declined_status() );
349
-        //$payment->set_gateway_response( '' );
350
-        return $payment;
351
-    }
352
-
353
-
354
-
355
-    /**
356
-     * CLeans out sensitive CC data and then logs it, and returns the cleaned request
357
-     *
358
-     * @param array       $request
359
-     * @param EEI_Payment $payment
360
-     * @return void
361
-     */
362
-    private function _log_clean_request($request, $payment)
363
-    {
364
-        $cleaned_request_data = $request;
365
-        unset($cleaned_request_data['CCDetails']['acct']);
366
-        unset($cleaned_request_data['CCDetails']['cvv2']);
367
-        unset($cleaned_request_data['CCDetails']['expdate']);
368
-        $this->log(array('Paypal Request' => $cleaned_request_data), $payment);
369
-    }
370
-
371
-
372
-
373
-    /**
374
-     * Cleans the response, logs it, and returns it
375
-     *
376
-     * @param array       $response
377
-     * @param EEI_Payment $payment
378
-     * @return array cleaned
379
-     */
380
-    private function _log_clean_response($response, $payment)
381
-    {
382
-        unset($response['REQUESTDATA']['CREDITCARDTYPE']);
383
-        unset($response['REQUESTDATA']['ACCT']);
384
-        unset($response['REQUESTDATA']['EXPDATE']);
385
-        unset($response['REQUESTDATA']['CVV2']);
386
-        unset($response['RAWREQUEST']);
387
-        $this->log(array('Paypal Response' => $response), $payment);
388
-        return $response;
389
-    }
390
-
391
-
392
-
393
-    /**
394
-     * @param $DataArray
395
-     * @return array
396
-     */
397
-    private function prep_and_curl_request($DataArray)
398
-    {
399
-        // Create empty holders for each portion of the NVP string
400
-        $DPFieldsNVP = '&METHOD=DoDirectPayment&BUTTONSOURCE=AngellEYE_PHP_Class_DDP';
401
-        $CCDetailsNVP = '';
402
-        $PayerInfoNVP = '';
403
-        $PayerNameNVP = '';
404
-        $BillingAddressNVP = '';
405
-        $ShippingAddressNVP = '';
406
-        $PaymentDetailsNVP = '';
407
-        $OrderItemsNVP = '';
408
-        $Secure3DNVP = '';
409
-        // DP Fields
410
-        $DPFields = isset($DataArray['DPFields']) ? $DataArray['DPFields'] : array();
411
-        foreach ($DPFields as $DPFieldsVar => $DPFieldsVal) {
412
-            $DPFieldsNVP .= '&' . strtoupper($DPFieldsVar) . '=' . urlencode($DPFieldsVal);
413
-        }
414
-        // CC Details Fields
415
-        $CCDetails = isset($DataArray['CCDetails']) ? $DataArray['CCDetails'] : array();
416
-        foreach ($CCDetails as $CCDetailsVar => $CCDetailsVal) {
417
-            $CCDetailsNVP .= '&' . strtoupper($CCDetailsVar) . '=' . urlencode($CCDetailsVal);
418
-        }
419
-        // PayerInfo Type Fields
420
-        $PayerInfo = isset($DataArray['PayerInfo']) ? $DataArray['PayerInfo'] : array();
421
-        foreach ($PayerInfo as $PayerInfoVar => $PayerInfoVal) {
422
-            $PayerInfoNVP .= '&' . strtoupper($PayerInfoVar) . '=' . urlencode($PayerInfoVal);
423
-        }
424
-        // Payer Name Fields
425
-        $PayerName = isset($DataArray['PayerName']) ? $DataArray['PayerName'] : array();
426
-        foreach ($PayerName as $PayerNameVar => $PayerNameVal) {
427
-            $PayerNameNVP .= '&' . strtoupper($PayerNameVar) . '=' . urlencode($PayerNameVal);
428
-        }
429
-        // Address Fields (Billing)
430
-        $BillingAddress = isset($DataArray['BillingAddress']) ? $DataArray['BillingAddress'] : array();
431
-        foreach ($BillingAddress as $BillingAddressVar => $BillingAddressVal) {
432
-            $BillingAddressNVP .= '&' . strtoupper($BillingAddressVar) . '=' . urlencode($BillingAddressVal);
433
-        }
434
-        // Payment Details Type Fields
435
-        $PaymentDetails = isset($DataArray['PaymentDetails']) ? $DataArray['PaymentDetails'] : array();
436
-        foreach ($PaymentDetails as $PaymentDetailsVar => $PaymentDetailsVal) {
437
-            $PaymentDetailsNVP .= '&' . strtoupper($PaymentDetailsVar) . '=' . urlencode($PaymentDetailsVal);
438
-        }
439
-        // Payment Details Item Type Fields
440
-        $OrderItems = isset($DataArray['OrderItems']) ? $DataArray['OrderItems'] : array();
441
-        $n = 0;
442
-        foreach ($OrderItems as $OrderItemsVar => $OrderItemsVal) {
443
-            $CurrentItem = $OrderItems[$OrderItemsVar];
444
-            foreach ($CurrentItem as $CurrentItemVar => $CurrentItemVal) {
445
-                $OrderItemsNVP .= '&' . strtoupper($CurrentItemVar) . $n . '=' . urlencode($CurrentItemVal);
446
-            }
447
-            $n++;
448
-        }
449
-        // Ship To Address Fields
450
-        $ShippingAddress = isset($DataArray['ShippingAddress']) ? $DataArray['ShippingAddress'] : array();
451
-        foreach ($ShippingAddress as $ShippingAddressVar => $ShippingAddressVal) {
452
-            $ShippingAddressNVP .= '&' . strtoupper($ShippingAddressVar) . '=' . urlencode($ShippingAddressVal);
453
-        }
454
-        // 3D Secure Fields
455
-        $Secure3D = isset($DataArray['Secure3D']) ? $DataArray['Secure3D'] : array();
456
-        foreach ($Secure3D as $Secure3DVar => $Secure3DVal) {
457
-            $Secure3DNVP .= '&' . strtoupper($Secure3DVar) . '=' . urlencode($Secure3DVal);
458
-        }
459
-        // Now that we have each chunk we need to go ahead and append them all together for our entire NVP string
460
-        $NVPRequest = 'USER='
461
-                      . $this->_username
462
-                      . '&PWD='
463
-                      . $this->_password
464
-                      . '&VERSION=64.0'
465
-                      . '&SIGNATURE='
466
-                      . $this->_signature
467
-                      . $DPFieldsNVP
468
-                      . $CCDetailsNVP
469
-                      . $PayerInfoNVP
470
-                      . $PayerNameNVP
471
-                      . $BillingAddressNVP
472
-                      . $PaymentDetailsNVP
473
-                      . $OrderItemsNVP
474
-                      . $ShippingAddressNVP
475
-                      . $Secure3DNVP;
476
-        $NVPResponse = $this->_CURLRequest($NVPRequest);
477
-        $NVPRequestArray = $this->_NVPToArray($NVPRequest);
478
-        $NVPResponseArray = $this->_NVPToArray($NVPResponse);
479
-        $Errors = $this->_GetErrors($NVPResponseArray);
480
-        $NVPResponseArray['ERRORS'] = $Errors;
481
-        $NVPResponseArray['REQUESTDATA'] = $NVPRequestArray;
482
-        $NVPResponseArray['RAWREQUEST'] = $NVPRequest;
483
-        $NVPResponseArray['RAWRESPONSE'] = $NVPResponse;
484
-        return $NVPResponseArray;
485
-    }
486
-
487
-
488
-
489
-    /**
490
-     * @param $Request
491
-     * @return mixed
492
-     */
493
-    private function _CURLRequest($Request)
494
-    {
495
-        $EndPointURL = $this->_debug_mode ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp';
496
-        $curl = curl_init();
497
-        curl_setopt($curl, CURLOPT_VERBOSE, apply_filters('FHEE__EEG_Paypal_Pro__CurlRequest__CURLOPT_VERBOSE', true));
498
-        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
499
-        curl_setopt($curl, CURLOPT_TIMEOUT, 60);
500
-        curl_setopt($curl, CURLOPT_URL, $EndPointURL);
501
-        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
502
-        curl_setopt($curl, CURLOPT_POSTFIELDS, $Request);
503
-        curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
504
-        //execute the curl POST
505
-        $Response = curl_exec($curl);
506
-        curl_close($curl);
507
-        return $Response;
508
-    }
509
-
510
-
511
-
512
-    /**
513
-     * @param $NVPString
514
-     * @return array
515
-     */
516
-    private function _NVPToArray($NVPString)
517
-    {
518
-        // prepare responses into array
519
-        $proArray = array();
520
-        while (strlen($NVPString)) {
521
-            // name
522
-            $keypos = strpos($NVPString, '=');
523
-            $keyval = substr($NVPString, 0, $keypos);
524
-            // value
525
-            $valuepos = strpos($NVPString, '&') ? strpos($NVPString, '&') : strlen($NVPString);
526
-            $valval = substr($NVPString, $keypos + 1, $valuepos - $keypos - 1);
527
-            // decoding the response
528
-            $proArray[$keyval] = urldecode($valval);
529
-            $NVPString = substr($NVPString, $valuepos + 1, strlen($NVPString));
530
-        }
531
-        return $proArray;
532
-    }
533
-
534
-
535
-
536
-    /**
537
-     * @param array $PayPalResult
538
-     * @return bool
539
-     */
540
-    private function _APICallSuccessful($PayPalResult)
541
-    {
542
-        $approved = false;
543
-        // check main response message from PayPal
544
-        if (isset($PayPalResult['ACK']) && ! empty($PayPalResult['ACK'])) {
545
-            $ack = strtoupper($PayPalResult['ACK']);
546
-            $approved = ($ack == 'SUCCESS' || $ack == 'SUCCESSWITHWARNING' || $ack == 'PARTIALSUCCESS') ? true : false;
547
-        }
548
-        return $approved;
549
-    }
550
-
551
-
552
-
553
-    /**
554
-     * @param $DataArray
555
-     * @return array
556
-     */
557
-    private function _GetErrors($DataArray)
558
-    {
559
-        $Errors = array();
560
-        $n = 0;
561
-        while (isset($DataArray['L_ERRORCODE' . $n . ''])) {
562
-            $LErrorCode = isset($DataArray['L_ERRORCODE' . $n . '']) ? $DataArray['L_ERRORCODE' . $n . ''] : '';
563
-            $LShortMessage = isset($DataArray['L_SHORTMESSAGE' . $n . ''])
564
-                ? $DataArray['L_SHORTMESSAGE' . $n . '']
565
-                : '';
566
-            $LLongMessage = isset($DataArray['L_LONGMESSAGE' . $n . ''])
567
-                ? $DataArray['L_LONGMESSAGE' . $n . '']
568
-                : '';
569
-            $LSeverityCode = isset($DataArray['L_SEVERITYCODE' . $n . ''])
570
-                ? $DataArray['L_SEVERITYCODE' . $n . '']
571
-                : '';
572
-            $CurrentItem = array(
573
-                'L_ERRORCODE'    => $LErrorCode,
574
-                'L_SHORTMESSAGE' => $LShortMessage,
575
-                'L_LONGMESSAGE'  => $LLongMessage,
576
-                'L_SEVERITYCODE' => $LSeverityCode,
577
-            );
578
-            array_push($Errors, $CurrentItem);
579
-            $n++;
580
-        }
581
-        return $Errors;
582
-    }
583
-
584
-
585
-
586
-    /**
587
-     *        nothing to see here...  move along....
588
-     *
589
-     * @access protected
590
-     * @param $Errors
591
-     * @return string
592
-     */
593
-    private function _DisplayErrors($Errors)
594
-    {
595
-        $error = '';
596
-        foreach ($Errors as $ErrorVar => $ErrorVal) {
597
-            $CurrentError = $Errors[$ErrorVar];
598
-            foreach ($CurrentError as $CurrentErrorVar => $CurrentErrorVal) {
599
-                $CurrentVarName = '';
600
-                if ($CurrentErrorVar == 'L_ERRORCODE') {
601
-                    $CurrentVarName = 'Error Code';
602
-                } elseif ($CurrentErrorVar == 'L_SHORTMESSAGE') {
603
-                    $CurrentVarName = 'Short Message';
604
-                } elseif ($CurrentErrorVar == 'L_LONGMESSAGE') {
605
-                    $CurrentVarName = 'Long Message';
606
-                } elseif ($CurrentErrorVar == 'L_SEVERITYCODE') {
607
-                    $CurrentVarName = 'Severity Code';
608
-                }
609
-                $error .= '<br />' . $CurrentVarName . ': ' . $CurrentErrorVal;
610
-            }
611
-        }
612
-        return $error;
613
-    }
28
+	/**
29
+	 * @var $_paypal_api_username string
30
+	 */
31
+	protected $_username = null;
32
+
33
+	/**
34
+	 * @var $_password string
35
+	 */
36
+	protected $_password = null;
37
+
38
+	/**
39
+	 * @var $_signature string
40
+	 */
41
+	protected $_signature = null;
42
+
43
+	/**
44
+	 * @var $_credit_card_types array with the keys for credit card types accepted on this account
45
+	 */
46
+	protected $_credit_card_types    = null;
47
+
48
+	protected $_currencies_supported = array(
49
+		'USD',
50
+		'GBP',
51
+		'CAD',
52
+		'AUD',
53
+		'BRL',
54
+		'CHF',
55
+		'CZK',
56
+		'DKK',
57
+		'EUR',
58
+		'HKD',
59
+		'HUF',
60
+		'ILS',
61
+		'JPY',
62
+		'MXN',
63
+		'MYR',
64
+		'NOK',
65
+		'NZD',
66
+		'PHP',
67
+		'PLN',
68
+		'SEK',
69
+		'SGD',
70
+		'THB',
71
+		'TRY',
72
+		'TWD',
73
+		'RUB',
74
+	);
75
+
76
+
77
+
78
+	/**
79
+	 * @param EEI_Payment $payment
80
+	 * @param array       $billing_info {
81
+	 * @type string $credit_card
82
+	 * @type string $credit_card_type
83
+	 * @type string $exp_month always 2 characters
84
+	 * @type string $exp_year always 4 characters
85
+	 * @type string $cvv
86
+	 * }
87
+	 * @see      parent::do_direct_payment for more info
88
+	 * @return EE_Payment|EEI_Payment
89
+	 * @throws EE_Error
90
+	 */
91
+	public function do_direct_payment($payment, $billing_info = null)
92
+	{
93
+		$transaction = $payment->transaction();
94
+		if (! $transaction instanceof EEI_Transaction) {
95
+			throw new EE_Error(
96
+				esc_html__('No transaction for payment while paying with PayPal Pro.', 'event_espresso')
97
+			);
98
+		}
99
+		$primary_registrant = $transaction->primary_registration();
100
+		if (! $primary_registrant instanceof EEI_Registration) {
101
+			throw new EE_Error(
102
+				esc_html__(
103
+					'No primary registration on transaction while paying with PayPal Pro.',
104
+					'event_espresso'
105
+				)
106
+			);
107
+		}
108
+		$attendee = $primary_registrant->attendee();
109
+		if (! $attendee instanceof EEI_Attendee) {
110
+			throw new EE_Error(
111
+				esc_html__(
112
+					'No attendee on primary registration while paying with PayPal Pro.',
113
+					'event_espresso'
114
+				)
115
+			);
116
+		}
117
+		$order_description = substr($this->_format_order_description($payment), 0, 127);
118
+		//charge for the full amount. Show itemized list
119
+		if ($this->_can_easily_itemize_transaction_for($payment)) {
120
+			$item_num = 1;
121
+			$total_line_item = $transaction->total_line_item();
122
+			$order_items = array();
123
+			foreach ($total_line_item->get_items() as $line_item) {
124
+				//ignore line items with a quantity of 0
125
+				if ($line_item->quantity() == 0) {
126
+					continue;
127
+				}
128
+				$item = array(
129
+					// Item Name.  127 char max.
130
+					'l_name'                 => substr(
131
+						$this->_format_line_item_name($line_item, $payment),
132
+						0,
133
+						127
134
+					),
135
+					// Item description.  127 char max.
136
+					'l_desc'                 => substr(
137
+						$this->_format_line_item_desc($line_item, $payment),
138
+						0,
139
+						127
140
+					),
141
+					// Cost of individual item.
142
+					'l_amt'                  => $line_item->unit_price(),
143
+					// Item Number.  127 char max.
144
+					'l_number'               => $item_num++,
145
+					// Item quantity.  Must be any positive integer.
146
+					'l_qty'                  => $line_item->quantity(),
147
+					// Item's sales tax amount.
148
+					'l_taxamt'               => '',
149
+					// eBay auction number of item.
150
+					'l_ebayitemnumber'       => '',
151
+					// eBay transaction ID of purchased item.
152
+					'l_ebayitemauctiontxnid' => '',
153
+					// eBay order ID for the item.
154
+					'l_ebayitemorderid'      => '',
155
+				);
156
+				// add to array of all items
157
+				array_push($order_items, $item);
158
+			}
159
+			$item_amount = $total_line_item->get_items_total();
160
+			$tax_amount = $total_line_item->get_total_tax();
161
+		} else {
162
+			$order_items = array();
163
+			$item_amount = $payment->amount();
164
+			$tax_amount = 0;
165
+			array_push($order_items, array(
166
+				// Item Name.  127 char max.
167
+				'l_name'   => substr(
168
+					$this->_format_partial_payment_line_item_name($payment),
169
+					0,
170
+					127
171
+				),
172
+				// Item description.  127 char max.
173
+				'l_desc'   => substr(
174
+					$this->_format_partial_payment_line_item_desc($payment),
175
+					0,
176
+					127
177
+				),
178
+				// Cost of individual item.
179
+				'l_amt'    => $payment->amount(),
180
+				// Item Number.  127 char max.
181
+				'l_number' => 1,
182
+				// Item quantity.  Must be any positive integer.
183
+				'l_qty'    => 1,
184
+			));
185
+		}
186
+		// Populate data arrays with order data.
187
+		$DPFields = array(
188
+			// How you want to obtain payment ?
189
+			// Authorization indicates the payment is a basic auth subject to settlement with Auth & Capture.
190
+			// Sale indicates that this is a final sale for which you are requesting payment.  Default is Sale.
191
+			'paymentaction'    => 'Sale',
192
+			// Required.  IP address of the payer's browser.
193
+			'ipaddress'        => $_SERVER['REMOTE_ADDR'],
194
+			// Flag to determine whether you want the results returned by FMF.  1 or 0.  Default is 0.
195
+			'returnfmfdetails' => '1',
196
+		);
197
+		$CCDetails = array(
198
+			// Required. Type of credit card.  Visa, MasterCard, Discover, Amex, Maestro, Solo.
199
+			// If Maestro or Solo, the currency code must be GBP.
200
+			//  In addition, either start date or issue number must be specified.
201
+			'creditcardtype' => $billing_info['credit_card_type'],
202
+			// Required.  Credit card number.  No spaces or punctuation.
203
+			'acct'           => $billing_info['credit_card'],
204
+			// Required.  Credit card expiration date.  Format is MMYYYY
205
+			'expdate'        => $billing_info['exp_month'] . $billing_info['exp_year'],
206
+			// Requirements determined by your PayPal account settings.  Security digits for credit card.
207
+			'cvv2'           => $billing_info['cvv'],
208
+		);
209
+		$PayerInfo = array(
210
+			// Email address of payer.
211
+			'email'       => $billing_info['email'],
212
+			// Unique PayPal customer ID for payer.
213
+			'payerid'     => '',
214
+			// Status of payer.  Values are verified or unverified
215
+			'payerstatus' => '',
216
+			// Payer's business name.
217
+			'business'    => '',
218
+		);
219
+		$PayerName = array(
220
+			// Payer's salutation.  20 char max.
221
+			'salutation' => '',
222
+			// Payer's first name.  25 char max.
223
+			'firstname'  => substr($billing_info['first_name'], 0, 25),
224
+			// Payer's middle name.  25 char max.
225
+			'middlename' => '',
226
+			// Payer's last name.  25 char max.
227
+			'lastname'   => substr($billing_info['last_name'], 0, 25),
228
+			// Payer's suffix.  12 char max.
229
+			'suffix'     => '',
230
+		);
231
+		$BillingAddress = array(
232
+			// Required.  First street address.
233
+			'street'      => $billing_info['address'],
234
+			// Second street address.
235
+			'street2'     => $billing_info['address2'],
236
+			// Required.  Name of City.
237
+			'city'        => $billing_info['city'],
238
+			// Required. Name of State or Province.
239
+			'state'       => substr($billing_info['state'], 0, 40),
240
+			// Required.  Country code.
241
+			'countrycode' => $billing_info['country'],
242
+			// Required.  Postal code of payer.
243
+			'zip'         => $billing_info['zip'],
244
+		);
245
+		//check if the registration info contains the needed fields for paypal pro
246
+		//(see https://developer.paypal.com/docs/classic/api/merchant/DoDirectPayment_API_Operation_NVP/)
247
+		if ($attendee->address() && $attendee->city() && $attendee->country_ID()) {
248
+			$use_registration_address_info = true;
249
+		} else {
250
+			$use_registration_address_info = false;
251
+		}
252
+		//so if the attendee has enough data to fill out PayPal Pro's shipping info, use it.
253
+		// If not, use the billing info again
254
+		$ShippingAddress = array(
255
+			'shiptoname'     => substr($use_registration_address_info
256
+				? $attendee->full_name()
257
+				: $billing_info['first_name'] . ' ' . $billing_info['last_name'], 0, 32),
258
+			'shiptostreet'   => substr($use_registration_address_info
259
+				? $attendee->address()
260
+				: $billing_info['address'], 0, 100),
261
+			'shiptostreet2'  => substr($use_registration_address_info
262
+				? $attendee->address2() : $billing_info['address2'], 0, 100),
263
+			'shiptocity'     => substr($use_registration_address_info
264
+				? $attendee->city()
265
+				: $billing_info['city'], 0, 40),
266
+			'state'          => substr($use_registration_address_info
267
+				? $attendee->state_name()
268
+				: $billing_info['state'], 0, 40),
269
+			'shiptocountry'  => $use_registration_address_info
270
+				? $attendee->country_ID()
271
+				: $billing_info['country'],
272
+			'shiptozip'      => substr($use_registration_address_info
273
+				? $attendee->zip()
274
+				: $billing_info['zip'], 0, 20),
275
+			'shiptophonenum' => substr($use_registration_address_info
276
+				? $attendee->phone()
277
+				: $billing_info['phone'], 0, 20),
278
+		);
279
+		$PaymentDetails = array(
280
+			// Required.  Total amount of order, including shipping, handling, and tax.
281
+			'amt'          => $this->format_currency($payment->amount()),
282
+			// Required.  Three-letter currency code.  Default is USD.
283
+			'currencycode' => $payment->currency_code(),
284
+			// Required if you include itemized cart details. (L_AMTn, etc.)
285
+			//Subtotal of items not including S&H, or tax.
286
+			'itemamt'      => $this->format_currency($item_amount),//
287
+			// Total shipping costs for the order.  If you specify shippingamt, you must also specify itemamt.
288
+			'shippingamt'  => '',
289
+			// Total handling costs for the order.  If you specify handlingamt, you must also specify itemamt.
290
+			'handlingamt'  => '',
291
+			// Required if you specify itemized cart tax details.
292
+			// Sum of tax for all items on the order.  Total sales tax.
293
+			'taxamt'       => $this->format_currency($tax_amount),
294
+			// Description of the order the customer is purchasing.  127 char max.
295
+			'desc'         => $order_description,
296
+			// Free-form field for your own use.  256 char max.
297
+			'custom'       => $primary_registrant ? $primary_registrant->ID() : '',
298
+			// Your own invoice or tracking number
299
+			'invnum'       => wp_generate_password(12, false),//$transaction->ID(),
300
+			// URL for receiving Instant Payment Notifications.  This overrides what your profile is set to use.
301
+			'notifyurl'    => '',
302
+			'buttonsource' => 'EventEspresso_SP',//EE will blow up if you change this
303
+		);
304
+		// Wrap all data arrays into a single, "master" array which will be passed into the class function.
305
+		$PayPalRequestData = array(
306
+			'DPFields'        => $DPFields,
307
+			'CCDetails'       => $CCDetails,
308
+			'PayerInfo'       => $PayerInfo,
309
+			'PayerName'       => $PayerName,
310
+			'BillingAddress'  => $BillingAddress,
311
+			'ShippingAddress' => $ShippingAddress,
312
+			'PaymentDetails'  => $PaymentDetails,
313
+			'OrderItems'      => $order_items,
314
+		);
315
+		$this->_log_clean_request($PayPalRequestData, $payment);
316
+		try {
317
+			$PayPalResult = $this->prep_and_curl_request($PayPalRequestData);
318
+			//remove PCI-sensitive data so it doesn't get stored
319
+			$PayPalResult = $this->_log_clean_response($PayPalResult, $payment);
320
+			$message = isset($PayPalResult['L_LONGMESSAGE0']) ? $PayPalResult['L_LONGMESSAGE0'] : $PayPalResult['ACK'];
321
+			if (empty($PayPalResult['RAWRESPONSE'])) {
322
+				$payment->set_status($this->_pay_model->failed_status());
323
+				$payment->set_gateway_response(__('No response received from Paypal Pro', 'event_espresso'));
324
+				$payment->set_details($PayPalResult);
325
+			} else {
326
+				if ($this->_APICallSuccessful($PayPalResult)) {
327
+					$payment->set_status($this->_pay_model->approved_status());
328
+				} else {
329
+					$payment->set_status($this->_pay_model->declined_status());
330
+				}
331
+				//make sure we interpret the AMT as a float, not an international string
332
+				// (where periods are thousand separators)
333
+				$payment->set_amount(isset($PayPalResult['AMT']) ? floatval($PayPalResult['AMT']) : 0);
334
+				$payment->set_gateway_response($message);
335
+				$payment->set_txn_id_chq_nmbr(isset($PayPalResult['TRANSACTIONID'])
336
+					? $PayPalResult['TRANSACTIONID']
337
+					: null);
338
+				$primary_registration_code = $primary_registrant instanceof EE_Registration
339
+					? $primary_registrant->reg_code()
340
+					: '';
341
+				$payment->set_extra_accntng($primary_registration_code);
342
+				$payment->set_details($PayPalResult);
343
+			}
344
+		} catch (Exception $e) {
345
+			$payment->set_status($this->_pay_model->failed_status());
346
+			$payment->set_gateway_response($e->getMessage());
347
+		}
348
+		//$payment->set_status( $this->_pay_model->declined_status() );
349
+		//$payment->set_gateway_response( '' );
350
+		return $payment;
351
+	}
352
+
353
+
354
+
355
+	/**
356
+	 * CLeans out sensitive CC data and then logs it, and returns the cleaned request
357
+	 *
358
+	 * @param array       $request
359
+	 * @param EEI_Payment $payment
360
+	 * @return void
361
+	 */
362
+	private function _log_clean_request($request, $payment)
363
+	{
364
+		$cleaned_request_data = $request;
365
+		unset($cleaned_request_data['CCDetails']['acct']);
366
+		unset($cleaned_request_data['CCDetails']['cvv2']);
367
+		unset($cleaned_request_data['CCDetails']['expdate']);
368
+		$this->log(array('Paypal Request' => $cleaned_request_data), $payment);
369
+	}
370
+
371
+
372
+
373
+	/**
374
+	 * Cleans the response, logs it, and returns it
375
+	 *
376
+	 * @param array       $response
377
+	 * @param EEI_Payment $payment
378
+	 * @return array cleaned
379
+	 */
380
+	private function _log_clean_response($response, $payment)
381
+	{
382
+		unset($response['REQUESTDATA']['CREDITCARDTYPE']);
383
+		unset($response['REQUESTDATA']['ACCT']);
384
+		unset($response['REQUESTDATA']['EXPDATE']);
385
+		unset($response['REQUESTDATA']['CVV2']);
386
+		unset($response['RAWREQUEST']);
387
+		$this->log(array('Paypal Response' => $response), $payment);
388
+		return $response;
389
+	}
390
+
391
+
392
+
393
+	/**
394
+	 * @param $DataArray
395
+	 * @return array
396
+	 */
397
+	private function prep_and_curl_request($DataArray)
398
+	{
399
+		// Create empty holders for each portion of the NVP string
400
+		$DPFieldsNVP = '&METHOD=DoDirectPayment&BUTTONSOURCE=AngellEYE_PHP_Class_DDP';
401
+		$CCDetailsNVP = '';
402
+		$PayerInfoNVP = '';
403
+		$PayerNameNVP = '';
404
+		$BillingAddressNVP = '';
405
+		$ShippingAddressNVP = '';
406
+		$PaymentDetailsNVP = '';
407
+		$OrderItemsNVP = '';
408
+		$Secure3DNVP = '';
409
+		// DP Fields
410
+		$DPFields = isset($DataArray['DPFields']) ? $DataArray['DPFields'] : array();
411
+		foreach ($DPFields as $DPFieldsVar => $DPFieldsVal) {
412
+			$DPFieldsNVP .= '&' . strtoupper($DPFieldsVar) . '=' . urlencode($DPFieldsVal);
413
+		}
414
+		// CC Details Fields
415
+		$CCDetails = isset($DataArray['CCDetails']) ? $DataArray['CCDetails'] : array();
416
+		foreach ($CCDetails as $CCDetailsVar => $CCDetailsVal) {
417
+			$CCDetailsNVP .= '&' . strtoupper($CCDetailsVar) . '=' . urlencode($CCDetailsVal);
418
+		}
419
+		// PayerInfo Type Fields
420
+		$PayerInfo = isset($DataArray['PayerInfo']) ? $DataArray['PayerInfo'] : array();
421
+		foreach ($PayerInfo as $PayerInfoVar => $PayerInfoVal) {
422
+			$PayerInfoNVP .= '&' . strtoupper($PayerInfoVar) . '=' . urlencode($PayerInfoVal);
423
+		}
424
+		// Payer Name Fields
425
+		$PayerName = isset($DataArray['PayerName']) ? $DataArray['PayerName'] : array();
426
+		foreach ($PayerName as $PayerNameVar => $PayerNameVal) {
427
+			$PayerNameNVP .= '&' . strtoupper($PayerNameVar) . '=' . urlencode($PayerNameVal);
428
+		}
429
+		// Address Fields (Billing)
430
+		$BillingAddress = isset($DataArray['BillingAddress']) ? $DataArray['BillingAddress'] : array();
431
+		foreach ($BillingAddress as $BillingAddressVar => $BillingAddressVal) {
432
+			$BillingAddressNVP .= '&' . strtoupper($BillingAddressVar) . '=' . urlencode($BillingAddressVal);
433
+		}
434
+		// Payment Details Type Fields
435
+		$PaymentDetails = isset($DataArray['PaymentDetails']) ? $DataArray['PaymentDetails'] : array();
436
+		foreach ($PaymentDetails as $PaymentDetailsVar => $PaymentDetailsVal) {
437
+			$PaymentDetailsNVP .= '&' . strtoupper($PaymentDetailsVar) . '=' . urlencode($PaymentDetailsVal);
438
+		}
439
+		// Payment Details Item Type Fields
440
+		$OrderItems = isset($DataArray['OrderItems']) ? $DataArray['OrderItems'] : array();
441
+		$n = 0;
442
+		foreach ($OrderItems as $OrderItemsVar => $OrderItemsVal) {
443
+			$CurrentItem = $OrderItems[$OrderItemsVar];
444
+			foreach ($CurrentItem as $CurrentItemVar => $CurrentItemVal) {
445
+				$OrderItemsNVP .= '&' . strtoupper($CurrentItemVar) . $n . '=' . urlencode($CurrentItemVal);
446
+			}
447
+			$n++;
448
+		}
449
+		// Ship To Address Fields
450
+		$ShippingAddress = isset($DataArray['ShippingAddress']) ? $DataArray['ShippingAddress'] : array();
451
+		foreach ($ShippingAddress as $ShippingAddressVar => $ShippingAddressVal) {
452
+			$ShippingAddressNVP .= '&' . strtoupper($ShippingAddressVar) . '=' . urlencode($ShippingAddressVal);
453
+		}
454
+		// 3D Secure Fields
455
+		$Secure3D = isset($DataArray['Secure3D']) ? $DataArray['Secure3D'] : array();
456
+		foreach ($Secure3D as $Secure3DVar => $Secure3DVal) {
457
+			$Secure3DNVP .= '&' . strtoupper($Secure3DVar) . '=' . urlencode($Secure3DVal);
458
+		}
459
+		// Now that we have each chunk we need to go ahead and append them all together for our entire NVP string
460
+		$NVPRequest = 'USER='
461
+					  . $this->_username
462
+					  . '&PWD='
463
+					  . $this->_password
464
+					  . '&VERSION=64.0'
465
+					  . '&SIGNATURE='
466
+					  . $this->_signature
467
+					  . $DPFieldsNVP
468
+					  . $CCDetailsNVP
469
+					  . $PayerInfoNVP
470
+					  . $PayerNameNVP
471
+					  . $BillingAddressNVP
472
+					  . $PaymentDetailsNVP
473
+					  . $OrderItemsNVP
474
+					  . $ShippingAddressNVP
475
+					  . $Secure3DNVP;
476
+		$NVPResponse = $this->_CURLRequest($NVPRequest);
477
+		$NVPRequestArray = $this->_NVPToArray($NVPRequest);
478
+		$NVPResponseArray = $this->_NVPToArray($NVPResponse);
479
+		$Errors = $this->_GetErrors($NVPResponseArray);
480
+		$NVPResponseArray['ERRORS'] = $Errors;
481
+		$NVPResponseArray['REQUESTDATA'] = $NVPRequestArray;
482
+		$NVPResponseArray['RAWREQUEST'] = $NVPRequest;
483
+		$NVPResponseArray['RAWRESPONSE'] = $NVPResponse;
484
+		return $NVPResponseArray;
485
+	}
486
+
487
+
488
+
489
+	/**
490
+	 * @param $Request
491
+	 * @return mixed
492
+	 */
493
+	private function _CURLRequest($Request)
494
+	{
495
+		$EndPointURL = $this->_debug_mode ? 'https://api-3t.sandbox.paypal.com/nvp' : 'https://api-3t.paypal.com/nvp';
496
+		$curl = curl_init();
497
+		curl_setopt($curl, CURLOPT_VERBOSE, apply_filters('FHEE__EEG_Paypal_Pro__CurlRequest__CURLOPT_VERBOSE', true));
498
+		curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
499
+		curl_setopt($curl, CURLOPT_TIMEOUT, 60);
500
+		curl_setopt($curl, CURLOPT_URL, $EndPointURL);
501
+		curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
502
+		curl_setopt($curl, CURLOPT_POSTFIELDS, $Request);
503
+		curl_setopt($curl, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
504
+		//execute the curl POST
505
+		$Response = curl_exec($curl);
506
+		curl_close($curl);
507
+		return $Response;
508
+	}
509
+
510
+
511
+
512
+	/**
513
+	 * @param $NVPString
514
+	 * @return array
515
+	 */
516
+	private function _NVPToArray($NVPString)
517
+	{
518
+		// prepare responses into array
519
+		$proArray = array();
520
+		while (strlen($NVPString)) {
521
+			// name
522
+			$keypos = strpos($NVPString, '=');
523
+			$keyval = substr($NVPString, 0, $keypos);
524
+			// value
525
+			$valuepos = strpos($NVPString, '&') ? strpos($NVPString, '&') : strlen($NVPString);
526
+			$valval = substr($NVPString, $keypos + 1, $valuepos - $keypos - 1);
527
+			// decoding the response
528
+			$proArray[$keyval] = urldecode($valval);
529
+			$NVPString = substr($NVPString, $valuepos + 1, strlen($NVPString));
530
+		}
531
+		return $proArray;
532
+	}
533
+
534
+
535
+
536
+	/**
537
+	 * @param array $PayPalResult
538
+	 * @return bool
539
+	 */
540
+	private function _APICallSuccessful($PayPalResult)
541
+	{
542
+		$approved = false;
543
+		// check main response message from PayPal
544
+		if (isset($PayPalResult['ACK']) && ! empty($PayPalResult['ACK'])) {
545
+			$ack = strtoupper($PayPalResult['ACK']);
546
+			$approved = ($ack == 'SUCCESS' || $ack == 'SUCCESSWITHWARNING' || $ack == 'PARTIALSUCCESS') ? true : false;
547
+		}
548
+		return $approved;
549
+	}
550
+
551
+
552
+
553
+	/**
554
+	 * @param $DataArray
555
+	 * @return array
556
+	 */
557
+	private function _GetErrors($DataArray)
558
+	{
559
+		$Errors = array();
560
+		$n = 0;
561
+		while (isset($DataArray['L_ERRORCODE' . $n . ''])) {
562
+			$LErrorCode = isset($DataArray['L_ERRORCODE' . $n . '']) ? $DataArray['L_ERRORCODE' . $n . ''] : '';
563
+			$LShortMessage = isset($DataArray['L_SHORTMESSAGE' . $n . ''])
564
+				? $DataArray['L_SHORTMESSAGE' . $n . '']
565
+				: '';
566
+			$LLongMessage = isset($DataArray['L_LONGMESSAGE' . $n . ''])
567
+				? $DataArray['L_LONGMESSAGE' . $n . '']
568
+				: '';
569
+			$LSeverityCode = isset($DataArray['L_SEVERITYCODE' . $n . ''])
570
+				? $DataArray['L_SEVERITYCODE' . $n . '']
571
+				: '';
572
+			$CurrentItem = array(
573
+				'L_ERRORCODE'    => $LErrorCode,
574
+				'L_SHORTMESSAGE' => $LShortMessage,
575
+				'L_LONGMESSAGE'  => $LLongMessage,
576
+				'L_SEVERITYCODE' => $LSeverityCode,
577
+			);
578
+			array_push($Errors, $CurrentItem);
579
+			$n++;
580
+		}
581
+		return $Errors;
582
+	}
583
+
584
+
585
+
586
+	/**
587
+	 *        nothing to see here...  move along....
588
+	 *
589
+	 * @access protected
590
+	 * @param $Errors
591
+	 * @return string
592
+	 */
593
+	private function _DisplayErrors($Errors)
594
+	{
595
+		$error = '';
596
+		foreach ($Errors as $ErrorVar => $ErrorVal) {
597
+			$CurrentError = $Errors[$ErrorVar];
598
+			foreach ($CurrentError as $CurrentErrorVar => $CurrentErrorVal) {
599
+				$CurrentVarName = '';
600
+				if ($CurrentErrorVar == 'L_ERRORCODE') {
601
+					$CurrentVarName = 'Error Code';
602
+				} elseif ($CurrentErrorVar == 'L_SHORTMESSAGE') {
603
+					$CurrentVarName = 'Short Message';
604
+				} elseif ($CurrentErrorVar == 'L_LONGMESSAGE') {
605
+					$CurrentVarName = 'Long Message';
606
+				} elseif ($CurrentErrorVar == 'L_SEVERITYCODE') {
607
+					$CurrentVarName = 'Severity Code';
608
+				}
609
+				$error .= '<br />' . $CurrentVarName . ': ' . $CurrentErrorVal;
610
+			}
611
+		}
612
+		return $error;
613
+	}
614 614
 }
615 615
 // End of file EEG_Paypal_Pro.gateway.php
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (! defined('EVENT_ESPRESSO_VERSION')) {
2
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3 3
     exit('No direct script access allowed');
4 4
 }
5 5
 
@@ -91,13 +91,13 @@  discard block
 block discarded – undo
91 91
     public function do_direct_payment($payment, $billing_info = null)
92 92
     {
93 93
         $transaction = $payment->transaction();
94
-        if (! $transaction instanceof EEI_Transaction) {
94
+        if ( ! $transaction instanceof EEI_Transaction) {
95 95
             throw new EE_Error(
96 96
                 esc_html__('No transaction for payment while paying with PayPal Pro.', 'event_espresso')
97 97
             );
98 98
         }
99 99
         $primary_registrant = $transaction->primary_registration();
100
-        if (! $primary_registrant instanceof EEI_Registration) {
100
+        if ( ! $primary_registrant instanceof EEI_Registration) {
101 101
             throw new EE_Error(
102 102
                 esc_html__(
103 103
                     'No primary registration on transaction while paying with PayPal Pro.',
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
             );
107 107
         }
108 108
         $attendee = $primary_registrant->attendee();
109
-        if (! $attendee instanceof EEI_Attendee) {
109
+        if ( ! $attendee instanceof EEI_Attendee) {
110 110
             throw new EE_Error(
111 111
                 esc_html__(
112 112
                     'No attendee on primary registration while paying with PayPal Pro.',
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
             // Required.  Credit card number.  No spaces or punctuation.
203 203
             'acct'           => $billing_info['credit_card'],
204 204
             // Required.  Credit card expiration date.  Format is MMYYYY
205
-            'expdate'        => $billing_info['exp_month'] . $billing_info['exp_year'],
205
+            'expdate'        => $billing_info['exp_month'].$billing_info['exp_year'],
206 206
             // Requirements determined by your PayPal account settings.  Security digits for credit card.
207 207
             'cvv2'           => $billing_info['cvv'],
208 208
         );
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
         $ShippingAddress = array(
255 255
             'shiptoname'     => substr($use_registration_address_info
256 256
                 ? $attendee->full_name()
257
-                : $billing_info['first_name'] . ' ' . $billing_info['last_name'], 0, 32),
257
+                : $billing_info['first_name'].' '.$billing_info['last_name'], 0, 32),
258 258
             'shiptostreet'   => substr($use_registration_address_info
259 259
                 ? $attendee->address()
260 260
                 : $billing_info['address'], 0, 100),
@@ -283,7 +283,7 @@  discard block
 block discarded – undo
283 283
             'currencycode' => $payment->currency_code(),
284 284
             // Required if you include itemized cart details. (L_AMTn, etc.)
285 285
             //Subtotal of items not including S&H, or tax.
286
-            'itemamt'      => $this->format_currency($item_amount),//
286
+            'itemamt'      => $this->format_currency($item_amount), //
287 287
             // Total shipping costs for the order.  If you specify shippingamt, you must also specify itemamt.
288 288
             'shippingamt'  => '',
289 289
             // Total handling costs for the order.  If you specify handlingamt, you must also specify itemamt.
@@ -296,10 +296,10 @@  discard block
 block discarded – undo
296 296
             // Free-form field for your own use.  256 char max.
297 297
             'custom'       => $primary_registrant ? $primary_registrant->ID() : '',
298 298
             // Your own invoice or tracking number
299
-            'invnum'       => wp_generate_password(12, false),//$transaction->ID(),
299
+            'invnum'       => wp_generate_password(12, false), //$transaction->ID(),
300 300
             // URL for receiving Instant Payment Notifications.  This overrides what your profile is set to use.
301 301
             'notifyurl'    => '',
302
-            'buttonsource' => 'EventEspresso_SP',//EE will blow up if you change this
302
+            'buttonsource' => 'EventEspresso_SP', //EE will blow up if you change this
303 303
         );
304 304
         // Wrap all data arrays into a single, "master" array which will be passed into the class function.
305 305
         $PayPalRequestData = array(
@@ -409,32 +409,32 @@  discard block
 block discarded – undo
409 409
         // DP Fields
410 410
         $DPFields = isset($DataArray['DPFields']) ? $DataArray['DPFields'] : array();
411 411
         foreach ($DPFields as $DPFieldsVar => $DPFieldsVal) {
412
-            $DPFieldsNVP .= '&' . strtoupper($DPFieldsVar) . '=' . urlencode($DPFieldsVal);
412
+            $DPFieldsNVP .= '&'.strtoupper($DPFieldsVar).'='.urlencode($DPFieldsVal);
413 413
         }
414 414
         // CC Details Fields
415 415
         $CCDetails = isset($DataArray['CCDetails']) ? $DataArray['CCDetails'] : array();
416 416
         foreach ($CCDetails as $CCDetailsVar => $CCDetailsVal) {
417
-            $CCDetailsNVP .= '&' . strtoupper($CCDetailsVar) . '=' . urlencode($CCDetailsVal);
417
+            $CCDetailsNVP .= '&'.strtoupper($CCDetailsVar).'='.urlencode($CCDetailsVal);
418 418
         }
419 419
         // PayerInfo Type Fields
420 420
         $PayerInfo = isset($DataArray['PayerInfo']) ? $DataArray['PayerInfo'] : array();
421 421
         foreach ($PayerInfo as $PayerInfoVar => $PayerInfoVal) {
422
-            $PayerInfoNVP .= '&' . strtoupper($PayerInfoVar) . '=' . urlencode($PayerInfoVal);
422
+            $PayerInfoNVP .= '&'.strtoupper($PayerInfoVar).'='.urlencode($PayerInfoVal);
423 423
         }
424 424
         // Payer Name Fields
425 425
         $PayerName = isset($DataArray['PayerName']) ? $DataArray['PayerName'] : array();
426 426
         foreach ($PayerName as $PayerNameVar => $PayerNameVal) {
427
-            $PayerNameNVP .= '&' . strtoupper($PayerNameVar) . '=' . urlencode($PayerNameVal);
427
+            $PayerNameNVP .= '&'.strtoupper($PayerNameVar).'='.urlencode($PayerNameVal);
428 428
         }
429 429
         // Address Fields (Billing)
430 430
         $BillingAddress = isset($DataArray['BillingAddress']) ? $DataArray['BillingAddress'] : array();
431 431
         foreach ($BillingAddress as $BillingAddressVar => $BillingAddressVal) {
432
-            $BillingAddressNVP .= '&' . strtoupper($BillingAddressVar) . '=' . urlencode($BillingAddressVal);
432
+            $BillingAddressNVP .= '&'.strtoupper($BillingAddressVar).'='.urlencode($BillingAddressVal);
433 433
         }
434 434
         // Payment Details Type Fields
435 435
         $PaymentDetails = isset($DataArray['PaymentDetails']) ? $DataArray['PaymentDetails'] : array();
436 436
         foreach ($PaymentDetails as $PaymentDetailsVar => $PaymentDetailsVal) {
437
-            $PaymentDetailsNVP .= '&' . strtoupper($PaymentDetailsVar) . '=' . urlencode($PaymentDetailsVal);
437
+            $PaymentDetailsNVP .= '&'.strtoupper($PaymentDetailsVar).'='.urlencode($PaymentDetailsVal);
438 438
         }
439 439
         // Payment Details Item Type Fields
440 440
         $OrderItems = isset($DataArray['OrderItems']) ? $DataArray['OrderItems'] : array();
@@ -442,19 +442,19 @@  discard block
 block discarded – undo
442 442
         foreach ($OrderItems as $OrderItemsVar => $OrderItemsVal) {
443 443
             $CurrentItem = $OrderItems[$OrderItemsVar];
444 444
             foreach ($CurrentItem as $CurrentItemVar => $CurrentItemVal) {
445
-                $OrderItemsNVP .= '&' . strtoupper($CurrentItemVar) . $n . '=' . urlencode($CurrentItemVal);
445
+                $OrderItemsNVP .= '&'.strtoupper($CurrentItemVar).$n.'='.urlencode($CurrentItemVal);
446 446
             }
447 447
             $n++;
448 448
         }
449 449
         // Ship To Address Fields
450 450
         $ShippingAddress = isset($DataArray['ShippingAddress']) ? $DataArray['ShippingAddress'] : array();
451 451
         foreach ($ShippingAddress as $ShippingAddressVar => $ShippingAddressVal) {
452
-            $ShippingAddressNVP .= '&' . strtoupper($ShippingAddressVar) . '=' . urlencode($ShippingAddressVal);
452
+            $ShippingAddressNVP .= '&'.strtoupper($ShippingAddressVar).'='.urlencode($ShippingAddressVal);
453 453
         }
454 454
         // 3D Secure Fields
455 455
         $Secure3D = isset($DataArray['Secure3D']) ? $DataArray['Secure3D'] : array();
456 456
         foreach ($Secure3D as $Secure3DVar => $Secure3DVal) {
457
-            $Secure3DNVP .= '&' . strtoupper($Secure3DVar) . '=' . urlencode($Secure3DVal);
457
+            $Secure3DNVP .= '&'.strtoupper($Secure3DVar).'='.urlencode($Secure3DVal);
458 458
         }
459 459
         // Now that we have each chunk we need to go ahead and append them all together for our entire NVP string
460 460
         $NVPRequest = 'USER='
@@ -558,16 +558,16 @@  discard block
 block discarded – undo
558 558
     {
559 559
         $Errors = array();
560 560
         $n = 0;
561
-        while (isset($DataArray['L_ERRORCODE' . $n . ''])) {
562
-            $LErrorCode = isset($DataArray['L_ERRORCODE' . $n . '']) ? $DataArray['L_ERRORCODE' . $n . ''] : '';
563
-            $LShortMessage = isset($DataArray['L_SHORTMESSAGE' . $n . ''])
564
-                ? $DataArray['L_SHORTMESSAGE' . $n . '']
561
+        while (isset($DataArray['L_ERRORCODE'.$n.''])) {
562
+            $LErrorCode = isset($DataArray['L_ERRORCODE'.$n.'']) ? $DataArray['L_ERRORCODE'.$n.''] : '';
563
+            $LShortMessage = isset($DataArray['L_SHORTMESSAGE'.$n.''])
564
+                ? $DataArray['L_SHORTMESSAGE'.$n.'']
565 565
                 : '';
566
-            $LLongMessage = isset($DataArray['L_LONGMESSAGE' . $n . ''])
567
-                ? $DataArray['L_LONGMESSAGE' . $n . '']
566
+            $LLongMessage = isset($DataArray['L_LONGMESSAGE'.$n.''])
567
+                ? $DataArray['L_LONGMESSAGE'.$n.'']
568 568
                 : '';
569
-            $LSeverityCode = isset($DataArray['L_SEVERITYCODE' . $n . ''])
570
-                ? $DataArray['L_SEVERITYCODE' . $n . '']
569
+            $LSeverityCode = isset($DataArray['L_SEVERITYCODE'.$n.''])
570
+                ? $DataArray['L_SEVERITYCODE'.$n.'']
571 571
                 : '';
572 572
             $CurrentItem = array(
573 573
                 'L_ERRORCODE'    => $LErrorCode,
@@ -606,7 +606,7 @@  discard block
 block discarded – undo
606 606
                 } elseif ($CurrentErrorVar == 'L_SEVERITYCODE') {
607 607
                     $CurrentVarName = 'Severity Code';
608 608
                 }
609
-                $error .= '<br />' . $CurrentVarName . ': ' . $CurrentErrorVal;
609
+                $error .= '<br />'.$CurrentVarName.': '.$CurrentErrorVal;
610 610
             }
611 611
         }
612 612
         return $error;
Please login to merge, or discard this patch.
libraries/line_item_display/EE_SPCO_Line_Item_Display_Strategy.strategy.php 3 patches
Doc Comments   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
      * @param EE_Line_Item $line_item
78 78
      * @param array        $options
79 79
      * @param EE_Line_Item $parent_line_item
80
-     * @return mixed
80
+     * @return string
81 81
      * @throws EE_Error
82 82
      */
83 83
     public function display_line_item(
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
      * _event_row - basically a Heading row displayed once above each event's ticket rows
224 224
      *
225 225
      * @param EE_Line_Item $line_item
226
-     * @return mixed
226
+     * @return string
227 227
      */
228 228
     private function _event_row(EE_Line_Item $line_item)
229 229
     {
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
      *
250 250
      * @param EE_Line_Item $line_item
251 251
      * @param array        $options
252
-     * @return mixed
252
+     * @return string
253 253
      * @throws EE_Error
254 254
      */
255 255
     private function _ticket_row(EE_Line_Item $line_item, $options = array())
@@ -303,7 +303,7 @@  discard block
 block discarded – undo
303 303
      *
304 304
      * @param EE_Line_Item $line_item
305 305
      * @param array        $options
306
-     * @return mixed
306
+     * @return string
307 307
      * @throws EE_Error
308 308
      */
309 309
     private function _item_row(EE_Line_Item $line_item, $options = array())
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
      * @param EE_Line_Item $line_item
364 364
      * @param array        $options
365 365
      * @param EE_Line_Item $parent_line_item
366
-     * @return mixed
366
+     * @return string
367 367
      * @throws EE_Error
368 368
      */
369 369
     private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null)
@@ -407,7 +407,7 @@  discard block
 block discarded – undo
407 407
      *
408 408
      * @param EE_Line_Item $line_item
409 409
      * @param array        $options
410
-     * @return mixed
410
+     * @return string
411 411
      * @throws EE_Error
412 412
      */
413 413
     private function _tax_row(EE_Line_Item $line_item, $options = array())
@@ -444,7 +444,7 @@  discard block
 block discarded – undo
444 444
      *
445 445
      * @param EE_Line_Item $line_item
446 446
      * @param string       $text
447
-     * @return mixed
447
+     * @return string
448 448
      * @throws EE_Error
449 449
      */
450 450
     private function _total_tax_row(EE_Line_Item $line_item, $text = '')
@@ -483,7 +483,7 @@  discard block
 block discarded – undo
483 483
      * @param EE_Line_Item $line_item
484 484
      * @param string       $text
485 485
      * @param array        $options
486
-     * @return mixed
486
+     * @return string
487 487
      * @throws EE_Error
488 488
      */
489 489
     private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array())
@@ -519,7 +519,7 @@  discard block
 block discarded – undo
519 519
      *
520 520
      * @param EE_Line_Item $line_item
521 521
      * @param string       $text
522
-     * @return mixed
522
+     * @return string
523 523
      * @throws EE_Error
524 524
      */
525 525
     private function _total_row(EE_Line_Item $line_item, $text = '')
@@ -546,7 +546,7 @@  discard block
 block discarded – undo
546 546
      *
547 547
      * @param EE_Line_Item $line_item
548 548
      * @param array        $options
549
-     * @return mixed
549
+     * @return string
550 550
      * @throws EE_Error
551 551
      */
552 552
     private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array())
Please login to merge, or discard this patch.
Indentation   +606 added lines, -606 removed lines patch added patch discarded remove patch
@@ -16,612 +16,612 @@
 block discarded – undo
16 16
 class EE_SPCO_Line_Item_Display_Strategy implements EEI_Line_Item_Display
17 17
 {
18 18
 
19
-    /**
20
-     * array of events
21
-     *
22
-     * @type EE_Line_Item[] $_events
23
-     */
24
-    private $_events = array();
25
-
26
-    /**
27
-     * whether to display the taxes row or not
28
-     *
29
-     * @type bool $_show_taxes
30
-     */
31
-    private $_show_taxes = false;
32
-
33
-    /**
34
-     * html for any tax rows
35
-     *
36
-     * @type string $_show_taxes
37
-     */
38
-    private $_taxes_html = '';
39
-
40
-    /**
41
-     * total amount including tax we can bill for at this time
42
-     *
43
-     * @type float $_grand_total
44
-     */
45
-    private $_grand_total = 0.00;
46
-
47
-    /**
48
-     * total number of items being billed for
49
-     *
50
-     * @type int $_total_items
51
-     */
52
-    private $_total_items = 0;
53
-
54
-
55
-
56
-    /**
57
-     * @return float
58
-     */
59
-    public function grand_total()
60
-    {
61
-        return $this->_grand_total;
62
-    }
63
-
64
-
65
-
66
-    /**
67
-     * @return int
68
-     */
69
-    public function total_items()
70
-    {
71
-        return $this->_total_items;
72
-    }
73
-
74
-
75
-
76
-    /**
77
-     * @param EE_Line_Item $line_item
78
-     * @param array        $options
79
-     * @param EE_Line_Item $parent_line_item
80
-     * @return mixed
81
-     * @throws EE_Error
82
-     */
83
-    public function display_line_item(
84
-        EE_Line_Item $line_item,
85
-        $options = array(),
86
-        EE_Line_Item $parent_line_item = null
87
-    ) {
88
-        $html = '';
89
-        // set some default options and merge with incoming
90
-        $default_options = array(
91
-            'show_desc' => true,  // 	true 		false
92
-            'odd'       => false,
93
-        );
94
-        $options = array_merge($default_options, (array)$options);
95
-        switch ($line_item->type()) {
96
-            case EEM_Line_Item::type_line_item:
97
-                $this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes;
98
-                if ($line_item->OBJ_type() === 'Ticket') {
99
-                    // item row
100
-                    $html .= $this->_ticket_row($line_item, $options);
101
-                } else {
102
-                    // item row
103
-                    $html .= $this->_item_row($line_item, $options);
104
-                }
105
-                if (
106
-                apply_filters(
107
-                    'FHEE__EE_SPCO_Line_Item_Display_Strategy__display_line_item__display_sub_line_items',
108
-                    true
109
-                )
110
-                ) {
111
-                    // got any kids?
112
-                    foreach ($line_item->children() as $child_line_item) {
113
-                        $html .= $this->display_line_item($child_line_item, $options, $line_item);
114
-                    }
115
-                }
116
-                break;
117
-            case EEM_Line_Item::type_sub_line_item:
118
-                $html .= $this->_sub_item_row($line_item, $options, $parent_line_item);
119
-                break;
120
-            case EEM_Line_Item::type_sub_total:
121
-                static $sub_total = 0;
122
-                $event_sub_total = 0;
123
-                $text = esc_html__('Sub-Total', 'event_espresso');
124
-                if ($line_item->OBJ_type() === 'Event') {
125
-                    $options['event_id'] = $event_id = $line_item->OBJ_ID();
126
-                    if (! isset($this->_events[$options['event_id']])) {
127
-                        $event = EEM_Event::instance()->get_one_by_ID($options['event_id']);
128
-                        // if event has default reg status of Not Approved, then don't display info on it
129
-                        if (
130
-                            $event instanceof EE_Event
131
-                            && $event->default_registration_status() === EEM_Registration::status_id_not_approved
132
-                        ) {
133
-                            $display_event = false;
134
-                            // unless there are registrations for it that are returning to pay
135
-                            if (isset($options['registrations']) && is_array($options['registrations'])) {
136
-                                foreach ($options['registrations'] as $registration) {
137
-                                    if (! $registration instanceof EE_Registration) {
138
-                                        continue;
139
-                                    }
140
-                                    $display_event = $registration->event_ID() === $options['event_id']
141
-                                                     && $registration->status_ID() !== EEM_Registration::status_id_not_approved
142
-                                        ? true
143
-                                        : $display_event;
144
-                                }
145
-                            }
146
-                            if (! $display_event) {
147
-                                return '';
148
-                            }
149
-                        }
150
-                        $this->_events[$options['event_id']] = 0;
151
-                        $html .= $this->_event_row($line_item);
152
-                        $text = esc_html__('Event Sub-Total', 'event_espresso');
153
-                    }
154
-                }
155
-                $child_line_items = $line_item->children();
156
-                // loop thru children
157
-                foreach ($child_line_items as $child_line_item) {
158
-                    // recursively feed children back into this method
159
-                    $html .= $this->display_line_item($child_line_item, $options, $line_item);
160
-                }
161
-                $event_sub_total += isset($options['event_id']) ? $this->_events[$options['event_id']] : 0;
162
-                $sub_total += $event_sub_total;
163
-                if (
164
-                    (
165
-                        // event subtotals
166
-                        $line_item->code() !== 'pre-tax-subtotal' && count($child_line_items) > 1
167
-                    )
168
-                    || (
169
-                        // pre-tax subtotals
170
-                        $line_item->code() === 'pre-tax-subtotal' && count($this->_events) > 1
171
-                    )
172
-                ) {
173
-                    $options['sub_total'] = $line_item->OBJ_type() === 'Event' ? $event_sub_total : $sub_total;
174
-                    $html .= $this->_sub_total_row($line_item, $text, $options);
175
-                }
176
-                break;
177
-            case EEM_Line_Item::type_tax:
178
-                if ($this->_show_taxes) {
179
-                    $this->_taxes_html .= $this->_tax_row($line_item, $options);
180
-                }
181
-                break;
182
-            case EEM_Line_Item::type_tax_sub_total:
183
-                if ($this->_show_taxes) {
184
-                    $child_line_items = $line_item->children();
185
-                    // loop thru children
186
-                    foreach ($child_line_items as $child_line_item) {
187
-                        // recursively feed children back into this method
188
-                        $html .= $this->display_line_item($child_line_item, $options, $line_item);
189
-                    }
190
-                    if (count($child_line_items) > 1) {
191
-                        $this->_taxes_html .= $this->_total_tax_row($line_item, esc_html__('Tax Total', 'event_espresso'));
192
-                    }
193
-                }
194
-                break;
195
-            case EEM_Line_Item::type_total:
196
-                // get all child line items
197
-                $children = $line_item->children();
198
-                // loop thru all non-tax child line items
199
-                foreach ($children as $child_line_item) {
200
-                    if ($child_line_item->type() !== EEM_Line_Item::type_tax_sub_total) {
201
-                        // recursively feed children back into this method
202
-                        $html .= $this->display_line_item($child_line_item, $options, $line_item);
203
-                    }
204
-                }
205
-                // now loop thru  tax child line items
206
-                foreach ($children as $child_line_item) {
207
-                    if ($child_line_item->type() === EEM_Line_Item::type_tax_sub_total) {
208
-                        // recursively feed children back into this method
209
-                        $html .= $this->display_line_item($child_line_item, $options, $line_item);
210
-                    }
211
-                }
212
-                $html .= $this->_taxes_html;
213
-                $html .= $this->_total_row($line_item, esc_html__('Total', 'event_espresso'));
214
-                $html .= $this->_payments_and_amount_owing_rows($line_item, $options);
215
-                break;
216
-        }
217
-        return $html;
218
-    }
219
-
220
-
221
-
222
-    /**
223
-     * _event_row - basically a Heading row displayed once above each event's ticket rows
224
-     *
225
-     * @param EE_Line_Item $line_item
226
-     * @return mixed
227
-     */
228
-    private function _event_row(EE_Line_Item $line_item)
229
-    {
230
-        // start of row
231
-        $html = EEH_HTML::tr('', 'event-cart-total-row', 'total_tr odd');
232
-        // event name td
233
-        $html .= EEH_HTML::td(
234
-            EEH_HTML::strong($line_item->name()),
235
-            '',
236
-            'event-header',
237
-            '',
238
-            ' colspan="4"'
239
-        );
240
-        // end of row
241
-        $html .= EEH_HTML::trx();
242
-        return $html;
243
-    }
244
-
245
-
246
-
247
-    /**
248
-     * _ticket_row
249
-     *
250
-     * @param EE_Line_Item $line_item
251
-     * @param array        $options
252
-     * @return mixed
253
-     * @throws EE_Error
254
-     */
255
-    private function _ticket_row(EE_Line_Item $line_item, $options = array())
256
-    {
257
-        // start of row
258
-        $row_class = $options['odd'] ? 'item odd' : 'item';
259
-        $html = EEH_HTML::tr('', '', $row_class);
260
-        // name && desc
261
-        $name_and_desc = apply_filters(
262
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
263
-            $line_item->name(),
264
-            $line_item
265
-        );
266
-        $name_and_desc .= apply_filters(
267
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
268
-            (
269
-                $options['show_desc']
270
-                    ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
271
-                    : ''
272
-            ),
273
-            $line_item,
274
-            $options
275
-        );
276
-        $name_and_desc .= $line_item->is_taxable() ? ' * ' : '';
277
-        // name td
278
-        $html .= EEH_HTML::td( /*__FUNCTION__ .*/
279
-            $name_and_desc, '', 'item_l');
280
-        // price td
281
-        $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
282
-        // quantity td
283
-        $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght');
284
-        $this->_total_items += $line_item->quantity();
285
-        // determine total for line item
286
-        $total = $line_item->total();
287
-        $this->_events[$options['event_id']] += $total;
288
-        // total td
289
-        $html .= EEH_HTML::td(
290
-            EEH_Template::format_currency($total, false, false),
291
-            '',
292
-            'item_r jst-rght'
293
-        );
294
-        // end of row
295
-        $html .= EEH_HTML::trx();
296
-        return $html;
297
-    }
298
-
299
-
300
-
301
-    /**
302
-     * _item_row
303
-     *
304
-     * @param EE_Line_Item $line_item
305
-     * @param array        $options
306
-     * @return mixed
307
-     * @throws EE_Error
308
-     */
309
-    private function _item_row(EE_Line_Item $line_item, $options = array())
310
-    {
311
-        // start of row
312
-        $row_class = $options['odd'] ? 'item odd' : 'item';
313
-        $html = EEH_HTML::tr('', '', $row_class);
314
-        $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : '';
315
-        // name && desc
316
-        $name_and_desc = apply_filters(
317
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
318
-            $obj_name . $line_item->name(),
319
-            $line_item
320
-        );
321
-        $name_and_desc .= apply_filters(
322
-            'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
323
-            (
324
-                $options['show_desc']
325
-                ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
326
-                : ''
327
-            ),
328
-            $line_item,
329
-            $options
330
-        );
331
-        $name_and_desc .= $line_item->is_taxable() ? ' * ' : '';
332
-        // name td
333
-        $html .= EEH_HTML::td($name_and_desc, '', 'item_l');
334
-        // price td
335
-        if ($line_item->is_percent()) {
336
-            $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c jst-rght');
337
-        } else {
338
-            $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
339
-        }
340
-        // quantity td
341
-        $html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght');
342
-        //$total = $line_item->total() * $line_item->quantity();
343
-        $total = $line_item->total();
344
-        if (isset($options['event_id'], $this->_events[$options['event_id']])) {
345
-            $this->_events[$options['event_id']] += $total;
346
-        }
347
-        // total td
348
-        $html .= EEH_HTML::td(
349
-            EEH_Template::format_currency($total, false, false),
350
-            '',
351
-            'item_r jst-rght'
352
-        );
353
-        // end of row
354
-        $html .= EEH_HTML::trx();
355
-        return $html;
356
-    }
357
-
358
-
359
-
360
-    /**
361
-     * _sub_item_row
362
-     *
363
-     * @param EE_Line_Item $line_item
364
-     * @param array        $options
365
-     * @param EE_Line_Item $parent_line_item
366
-     * @return mixed
367
-     * @throws EE_Error
368
-     */
369
-    private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null)
370
-    {
371
-        if($parent_line_item instanceof  EE_Line_Item && $line_item->name() === $parent_line_item->name()) {
372
-            return '';
373
-        }
374
-        // start of row
375
-        $html = EEH_HTML::tr('', '', 'item sub-item-row');
376
-        // name && desc
377
-        $name_and_desc = EEH_HTML::span('', '', 'sub-item-row-bullet dashicons dashicons-arrow-right')
378
-                         . $line_item->name();
379
-        $name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: '
380
-                                                  . $line_item->desc()
381
-                                                  . '</span>' : '';
382
-        // name td
383
-        $html .= EEH_HTML::td( $name_and_desc, '', 'item_l sub-item');
384
-        $qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1;
385
-        // discount/surcharge td
386
-        if ($line_item->is_percent()) {
387
-            $html .= EEH_HTML::td(
388
-                EEH_Template::format_currency(
389
-                    $line_item->total() / $qty,
390
-                    false, false
391
-                ),
392
-                '', 'item_c jst-rght'
393
-            );
394
-        } else {
395
-            $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
396
-        }
397
-        // no quantity td
398
-        $html .= EEH_HTML::td();
399
-        // no total td
400
-        $html .= EEH_HTML::td();
401
-        // end of row
402
-        $html .= EEH_HTML::trx();
403
-        return $html;
404
-    }
405
-
406
-
407
-
408
-    /**
409
-     * _tax_row
410
-     *
411
-     * @param EE_Line_Item $line_item
412
-     * @param array        $options
413
-     * @return mixed
414
-     * @throws EE_Error
415
-     */
416
-    private function _tax_row(EE_Line_Item $line_item, $options = array())
417
-    {
418
-        // start of row
419
-        $html = EEH_HTML::tr('', 'item sub-item tax-total');
420
-        // name && desc
421
-        $name_and_desc = $line_item->name();
422
-        $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">'
423
-                          . esc_html__(' * taxable items', 'event_espresso') . '</span>';
424
-        $name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : '';
425
-        // name td
426
-        $html .= EEH_HTML::td( /*__FUNCTION__ .*/
427
-            $name_and_desc, '', 'item_l sub-item');
428
-        // percent td
429
-        $html .= EEH_HTML::td($line_item->percent() . '%', '', ' jst-rght', '');
430
-        // empty td (price)
431
-        $html .= EEH_HTML::td(EEH_HTML::nbsp());
432
-        // total td
433
-        $html .= EEH_HTML::td(EEH_Template::format_currency(
434
-            $line_item->total(), false, false),
435
-            '',
436
-            'item_r jst-rght'
437
-        );
438
-        // end of row
439
-        $html .= EEH_HTML::trx();
440
-        return $html;
441
-    }
442
-
443
-
444
-
445
-    /**
446
-     * _total_row
447
-     *
448
-     * @param EE_Line_Item $line_item
449
-     * @param string       $text
450
-     * @return mixed
451
-     * @throws EE_Error
452
-     */
453
-    private function _total_tax_row(EE_Line_Item $line_item, $text = '')
454
-    {
455
-        $html = '';
456
-        if ($line_item->total()) {
457
-            // start of row
458
-            $html = EEH_HTML::tr('', '', 'total_tr odd');
459
-            // total td
460
-            $html .= EEH_HTML::td(
461
-                $text,
462
-                '',
463
-                'total_currency total jst-rght',
464
-                '',
465
-                ' colspan="2"'
466
-            );
467
-            // empty td (price)
468
-            $html .= EEH_HTML::td(EEH_HTML::nbsp());
469
-            // total td
470
-            $html .= EEH_HTML::td(
471
-                EEH_Template::format_currency($line_item->total(), false, false),
472
-                '',
473
-                'total jst-rght'
474
-            );
475
-            // end of row
476
-            $html .= EEH_HTML::trx();
477
-        }
478
-        return $html;
479
-    }
480
-
481
-
482
-
483
-    /**
484
-     * _total_row
485
-     *
486
-     * @param EE_Line_Item $line_item
487
-     * @param string       $text
488
-     * @param array        $options
489
-     * @return mixed
490
-     * @throws EE_Error
491
-     */
492
-    private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array())
493
-    {
494
-        $html = '';
495
-        if ($line_item->total()) {
496
-            // start of row
497
-            $html = EEH_HTML::tr('', '', 'total_tr odd');
498
-            // total td
499
-            $html .= EEH_HTML::td(
500
-                $text,
501
-                '',
502
-                'total_currency total jst-rght',
503
-                '',
504
-                ' colspan="3"'
505
-            );
506
-            // total td
507
-            $html .= EEH_HTML::td(
508
-                EEH_Template::format_currency($options['sub_total'], false, false),
509
-                '',
510
-                'total jst-rght'
511
-            );
512
-            // end of row
513
-            $html .= EEH_HTML::trx();
514
-        }
515
-        return $html;
516
-    }
517
-
518
-
519
-
520
-    /**
521
-     * _total_row
522
-     *
523
-     * @param EE_Line_Item $line_item
524
-     * @param string       $text
525
-     * @return mixed
526
-     * @throws EE_Error
527
-     */
528
-    private function _total_row(EE_Line_Item $line_item, $text = '')
529
-    {
530
-        // start of row
531
-        $html = EEH_HTML::tr('', '', 'spco-grand-total total_tr odd');
532
-        // total td
533
-        $html .= EEH_HTML::td($text, '', 'total_currency total jst-rght', '', ' colspan="3"');
534
-        // total td
535
-        $html .= EEH_HTML::td(
536
-            EEH_Template::format_currency($line_item->total(), false, false),
537
-            '',
538
-            'total jst-rght'
539
-        );
540
-        // end of row
541
-        $html .= EEH_HTML::trx();
542
-        return $html;
543
-    }
544
-
545
-
546
-
547
-    /**
548
-     * _payments_and_amount_owing_rows
549
-     *
550
-     * @param EE_Line_Item $line_item
551
-     * @param array        $options
552
-     * @return mixed
553
-     * @throws EE_Error
554
-     */
555
-    private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array())
556
-    {
557
-        $html = '';
558
-        $owing = $line_item->total();
559
-        $transaction = EEM_Transaction::instance()->get_one_by_ID($line_item->TXN_ID());
560
-        if ($transaction instanceof EE_Transaction) {
561
-            $registration_payments = array();
562
-            $registrations = ! empty($options['registrations'])
563
-                ? $options['registrations']
564
-                : $transaction->registrations();
565
-            foreach ($registrations as $registration) {
566
-                if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) {
567
-                    $registration_payments += $registration->registration_payments();
568
-                }
569
-            }
570
-            if (! empty($registration_payments)) {
571
-                foreach ($registration_payments as $registration_payment) {
572
-                    if ($registration_payment instanceof EE_Registration_Payment) {
573
-                        $owing -= $registration_payment->amount();
574
-                        $payment = $registration_payment->payment();
575
-                        $payment_desc = '';
576
-                        if ($payment instanceof EE_Payment) {
577
-                            $payment_desc = sprintf(
578
-                                esc_html__('Payment%1$s Received: %2$s', 'event_espresso'),
579
-                                $payment->txn_id_chq_nmbr() !== ''
580
-                                    ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> '
581
-                                    : '',
582
-                                $payment->timestamp()
583
-                            );
584
-                        }
585
-                        // start of row
586
-                        $html .= EEH_HTML::tr('', '', 'total_tr odd');
587
-                        // payment desc
588
-                        $html .= EEH_HTML::td($payment_desc, '', '', '', ' colspan="3"');
589
-                        // total td
590
-                        $html .= EEH_HTML::td(
591
-                            EEH_Template::format_currency(
592
-                                $registration_payment->amount(),
593
-                                false,
594
-                                false
595
-                            ),
596
-                            '',
597
-                            'total jst-rght'
598
-                        );
599
-                        // end of row
600
-                        $html .= EEH_HTML::trx();
601
-                    }
602
-                }
603
-                if ($line_item->total()) {
604
-                    // start of row
605
-                    $html .= EEH_HTML::tr('', '', 'total_tr odd');
606
-                    // total td
607
-                    $html .= EEH_HTML::td(
608
-                        esc_html__('Amount Owing', 'event_espresso'),
609
-                        '', 'total_currency total jst-rght', '', ' colspan="3"'
610
-                    );
611
-                    // total td
612
-                    $html .= EEH_HTML::td(
613
-                        EEH_Template::format_currency($owing, false, false),
614
-                        '',
615
-                        'total jst-rght'
616
-                    );
617
-                    // end of row
618
-                    $html .= EEH_HTML::trx();
619
-                }
620
-            }
621
-        }
622
-        $this->_grand_total = $owing;
623
-        return $html;
624
-    }
19
+	/**
20
+	 * array of events
21
+	 *
22
+	 * @type EE_Line_Item[] $_events
23
+	 */
24
+	private $_events = array();
25
+
26
+	/**
27
+	 * whether to display the taxes row or not
28
+	 *
29
+	 * @type bool $_show_taxes
30
+	 */
31
+	private $_show_taxes = false;
32
+
33
+	/**
34
+	 * html for any tax rows
35
+	 *
36
+	 * @type string $_show_taxes
37
+	 */
38
+	private $_taxes_html = '';
39
+
40
+	/**
41
+	 * total amount including tax we can bill for at this time
42
+	 *
43
+	 * @type float $_grand_total
44
+	 */
45
+	private $_grand_total = 0.00;
46
+
47
+	/**
48
+	 * total number of items being billed for
49
+	 *
50
+	 * @type int $_total_items
51
+	 */
52
+	private $_total_items = 0;
53
+
54
+
55
+
56
+	/**
57
+	 * @return float
58
+	 */
59
+	public function grand_total()
60
+	{
61
+		return $this->_grand_total;
62
+	}
63
+
64
+
65
+
66
+	/**
67
+	 * @return int
68
+	 */
69
+	public function total_items()
70
+	{
71
+		return $this->_total_items;
72
+	}
73
+
74
+
75
+
76
+	/**
77
+	 * @param EE_Line_Item $line_item
78
+	 * @param array        $options
79
+	 * @param EE_Line_Item $parent_line_item
80
+	 * @return mixed
81
+	 * @throws EE_Error
82
+	 */
83
+	public function display_line_item(
84
+		EE_Line_Item $line_item,
85
+		$options = array(),
86
+		EE_Line_Item $parent_line_item = null
87
+	) {
88
+		$html = '';
89
+		// set some default options and merge with incoming
90
+		$default_options = array(
91
+			'show_desc' => true,  // 	true 		false
92
+			'odd'       => false,
93
+		);
94
+		$options = array_merge($default_options, (array)$options);
95
+		switch ($line_item->type()) {
96
+			case EEM_Line_Item::type_line_item:
97
+				$this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes;
98
+				if ($line_item->OBJ_type() === 'Ticket') {
99
+					// item row
100
+					$html .= $this->_ticket_row($line_item, $options);
101
+				} else {
102
+					// item row
103
+					$html .= $this->_item_row($line_item, $options);
104
+				}
105
+				if (
106
+				apply_filters(
107
+					'FHEE__EE_SPCO_Line_Item_Display_Strategy__display_line_item__display_sub_line_items',
108
+					true
109
+				)
110
+				) {
111
+					// got any kids?
112
+					foreach ($line_item->children() as $child_line_item) {
113
+						$html .= $this->display_line_item($child_line_item, $options, $line_item);
114
+					}
115
+				}
116
+				break;
117
+			case EEM_Line_Item::type_sub_line_item:
118
+				$html .= $this->_sub_item_row($line_item, $options, $parent_line_item);
119
+				break;
120
+			case EEM_Line_Item::type_sub_total:
121
+				static $sub_total = 0;
122
+				$event_sub_total = 0;
123
+				$text = esc_html__('Sub-Total', 'event_espresso');
124
+				if ($line_item->OBJ_type() === 'Event') {
125
+					$options['event_id'] = $event_id = $line_item->OBJ_ID();
126
+					if (! isset($this->_events[$options['event_id']])) {
127
+						$event = EEM_Event::instance()->get_one_by_ID($options['event_id']);
128
+						// if event has default reg status of Not Approved, then don't display info on it
129
+						if (
130
+							$event instanceof EE_Event
131
+							&& $event->default_registration_status() === EEM_Registration::status_id_not_approved
132
+						) {
133
+							$display_event = false;
134
+							// unless there are registrations for it that are returning to pay
135
+							if (isset($options['registrations']) && is_array($options['registrations'])) {
136
+								foreach ($options['registrations'] as $registration) {
137
+									if (! $registration instanceof EE_Registration) {
138
+										continue;
139
+									}
140
+									$display_event = $registration->event_ID() === $options['event_id']
141
+													 && $registration->status_ID() !== EEM_Registration::status_id_not_approved
142
+										? true
143
+										: $display_event;
144
+								}
145
+							}
146
+							if (! $display_event) {
147
+								return '';
148
+							}
149
+						}
150
+						$this->_events[$options['event_id']] = 0;
151
+						$html .= $this->_event_row($line_item);
152
+						$text = esc_html__('Event Sub-Total', 'event_espresso');
153
+					}
154
+				}
155
+				$child_line_items = $line_item->children();
156
+				// loop thru children
157
+				foreach ($child_line_items as $child_line_item) {
158
+					// recursively feed children back into this method
159
+					$html .= $this->display_line_item($child_line_item, $options, $line_item);
160
+				}
161
+				$event_sub_total += isset($options['event_id']) ? $this->_events[$options['event_id']] : 0;
162
+				$sub_total += $event_sub_total;
163
+				if (
164
+					(
165
+						// event subtotals
166
+						$line_item->code() !== 'pre-tax-subtotal' && count($child_line_items) > 1
167
+					)
168
+					|| (
169
+						// pre-tax subtotals
170
+						$line_item->code() === 'pre-tax-subtotal' && count($this->_events) > 1
171
+					)
172
+				) {
173
+					$options['sub_total'] = $line_item->OBJ_type() === 'Event' ? $event_sub_total : $sub_total;
174
+					$html .= $this->_sub_total_row($line_item, $text, $options);
175
+				}
176
+				break;
177
+			case EEM_Line_Item::type_tax:
178
+				if ($this->_show_taxes) {
179
+					$this->_taxes_html .= $this->_tax_row($line_item, $options);
180
+				}
181
+				break;
182
+			case EEM_Line_Item::type_tax_sub_total:
183
+				if ($this->_show_taxes) {
184
+					$child_line_items = $line_item->children();
185
+					// loop thru children
186
+					foreach ($child_line_items as $child_line_item) {
187
+						// recursively feed children back into this method
188
+						$html .= $this->display_line_item($child_line_item, $options, $line_item);
189
+					}
190
+					if (count($child_line_items) > 1) {
191
+						$this->_taxes_html .= $this->_total_tax_row($line_item, esc_html__('Tax Total', 'event_espresso'));
192
+					}
193
+				}
194
+				break;
195
+			case EEM_Line_Item::type_total:
196
+				// get all child line items
197
+				$children = $line_item->children();
198
+				// loop thru all non-tax child line items
199
+				foreach ($children as $child_line_item) {
200
+					if ($child_line_item->type() !== EEM_Line_Item::type_tax_sub_total) {
201
+						// recursively feed children back into this method
202
+						$html .= $this->display_line_item($child_line_item, $options, $line_item);
203
+					}
204
+				}
205
+				// now loop thru  tax child line items
206
+				foreach ($children as $child_line_item) {
207
+					if ($child_line_item->type() === EEM_Line_Item::type_tax_sub_total) {
208
+						// recursively feed children back into this method
209
+						$html .= $this->display_line_item($child_line_item, $options, $line_item);
210
+					}
211
+				}
212
+				$html .= $this->_taxes_html;
213
+				$html .= $this->_total_row($line_item, esc_html__('Total', 'event_espresso'));
214
+				$html .= $this->_payments_and_amount_owing_rows($line_item, $options);
215
+				break;
216
+		}
217
+		return $html;
218
+	}
219
+
220
+
221
+
222
+	/**
223
+	 * _event_row - basically a Heading row displayed once above each event's ticket rows
224
+	 *
225
+	 * @param EE_Line_Item $line_item
226
+	 * @return mixed
227
+	 */
228
+	private function _event_row(EE_Line_Item $line_item)
229
+	{
230
+		// start of row
231
+		$html = EEH_HTML::tr('', 'event-cart-total-row', 'total_tr odd');
232
+		// event name td
233
+		$html .= EEH_HTML::td(
234
+			EEH_HTML::strong($line_item->name()),
235
+			'',
236
+			'event-header',
237
+			'',
238
+			' colspan="4"'
239
+		);
240
+		// end of row
241
+		$html .= EEH_HTML::trx();
242
+		return $html;
243
+	}
244
+
245
+
246
+
247
+	/**
248
+	 * _ticket_row
249
+	 *
250
+	 * @param EE_Line_Item $line_item
251
+	 * @param array        $options
252
+	 * @return mixed
253
+	 * @throws EE_Error
254
+	 */
255
+	private function _ticket_row(EE_Line_Item $line_item, $options = array())
256
+	{
257
+		// start of row
258
+		$row_class = $options['odd'] ? 'item odd' : 'item';
259
+		$html = EEH_HTML::tr('', '', $row_class);
260
+		// name && desc
261
+		$name_and_desc = apply_filters(
262
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
263
+			$line_item->name(),
264
+			$line_item
265
+		);
266
+		$name_and_desc .= apply_filters(
267
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
268
+			(
269
+				$options['show_desc']
270
+					? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
271
+					: ''
272
+			),
273
+			$line_item,
274
+			$options
275
+		);
276
+		$name_and_desc .= $line_item->is_taxable() ? ' * ' : '';
277
+		// name td
278
+		$html .= EEH_HTML::td( /*__FUNCTION__ .*/
279
+			$name_and_desc, '', 'item_l');
280
+		// price td
281
+		$html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
282
+		// quantity td
283
+		$html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght');
284
+		$this->_total_items += $line_item->quantity();
285
+		// determine total for line item
286
+		$total = $line_item->total();
287
+		$this->_events[$options['event_id']] += $total;
288
+		// total td
289
+		$html .= EEH_HTML::td(
290
+			EEH_Template::format_currency($total, false, false),
291
+			'',
292
+			'item_r jst-rght'
293
+		);
294
+		// end of row
295
+		$html .= EEH_HTML::trx();
296
+		return $html;
297
+	}
298
+
299
+
300
+
301
+	/**
302
+	 * _item_row
303
+	 *
304
+	 * @param EE_Line_Item $line_item
305
+	 * @param array        $options
306
+	 * @return mixed
307
+	 * @throws EE_Error
308
+	 */
309
+	private function _item_row(EE_Line_Item $line_item, $options = array())
310
+	{
311
+		// start of row
312
+		$row_class = $options['odd'] ? 'item odd' : 'item';
313
+		$html = EEH_HTML::tr('', '', $row_class);
314
+		$obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : '';
315
+		// name && desc
316
+		$name_and_desc = apply_filters(
317
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
318
+			$obj_name . $line_item->name(),
319
+			$line_item
320
+		);
321
+		$name_and_desc .= apply_filters(
322
+			'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
323
+			(
324
+				$options['show_desc']
325
+				? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
326
+				: ''
327
+			),
328
+			$line_item,
329
+			$options
330
+		);
331
+		$name_and_desc .= $line_item->is_taxable() ? ' * ' : '';
332
+		// name td
333
+		$html .= EEH_HTML::td($name_and_desc, '', 'item_l');
334
+		// price td
335
+		if ($line_item->is_percent()) {
336
+			$html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c jst-rght');
337
+		} else {
338
+			$html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
339
+		}
340
+		// quantity td
341
+		$html .= EEH_HTML::td($line_item->quantity(), '', 'item_l jst-rght');
342
+		//$total = $line_item->total() * $line_item->quantity();
343
+		$total = $line_item->total();
344
+		if (isset($options['event_id'], $this->_events[$options['event_id']])) {
345
+			$this->_events[$options['event_id']] += $total;
346
+		}
347
+		// total td
348
+		$html .= EEH_HTML::td(
349
+			EEH_Template::format_currency($total, false, false),
350
+			'',
351
+			'item_r jst-rght'
352
+		);
353
+		// end of row
354
+		$html .= EEH_HTML::trx();
355
+		return $html;
356
+	}
357
+
358
+
359
+
360
+	/**
361
+	 * _sub_item_row
362
+	 *
363
+	 * @param EE_Line_Item $line_item
364
+	 * @param array        $options
365
+	 * @param EE_Line_Item $parent_line_item
366
+	 * @return mixed
367
+	 * @throws EE_Error
368
+	 */
369
+	private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null)
370
+	{
371
+		if($parent_line_item instanceof  EE_Line_Item && $line_item->name() === $parent_line_item->name()) {
372
+			return '';
373
+		}
374
+		// start of row
375
+		$html = EEH_HTML::tr('', '', 'item sub-item-row');
376
+		// name && desc
377
+		$name_and_desc = EEH_HTML::span('', '', 'sub-item-row-bullet dashicons dashicons-arrow-right')
378
+						 . $line_item->name();
379
+		$name_and_desc .= $options['show_desc'] ? '<span class="line-sub-item-desc-spn smaller-text">: '
380
+												  . $line_item->desc()
381
+												  . '</span>' : '';
382
+		// name td
383
+		$html .= EEH_HTML::td( $name_and_desc, '', 'item_l sub-item');
384
+		$qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1;
385
+		// discount/surcharge td
386
+		if ($line_item->is_percent()) {
387
+			$html .= EEH_HTML::td(
388
+				EEH_Template::format_currency(
389
+					$line_item->total() / $qty,
390
+					false, false
391
+				),
392
+				'', 'item_c jst-rght'
393
+			);
394
+		} else {
395
+			$html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
396
+		}
397
+		// no quantity td
398
+		$html .= EEH_HTML::td();
399
+		// no total td
400
+		$html .= EEH_HTML::td();
401
+		// end of row
402
+		$html .= EEH_HTML::trx();
403
+		return $html;
404
+	}
405
+
406
+
407
+
408
+	/**
409
+	 * _tax_row
410
+	 *
411
+	 * @param EE_Line_Item $line_item
412
+	 * @param array        $options
413
+	 * @return mixed
414
+	 * @throws EE_Error
415
+	 */
416
+	private function _tax_row(EE_Line_Item $line_item, $options = array())
417
+	{
418
+		// start of row
419
+		$html = EEH_HTML::tr('', 'item sub-item tax-total');
420
+		// name && desc
421
+		$name_and_desc = $line_item->name();
422
+		$name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">'
423
+						  . esc_html__(' * taxable items', 'event_espresso') . '</span>';
424
+		$name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : '';
425
+		// name td
426
+		$html .= EEH_HTML::td( /*__FUNCTION__ .*/
427
+			$name_and_desc, '', 'item_l sub-item');
428
+		// percent td
429
+		$html .= EEH_HTML::td($line_item->percent() . '%', '', ' jst-rght', '');
430
+		// empty td (price)
431
+		$html .= EEH_HTML::td(EEH_HTML::nbsp());
432
+		// total td
433
+		$html .= EEH_HTML::td(EEH_Template::format_currency(
434
+			$line_item->total(), false, false),
435
+			'',
436
+			'item_r jst-rght'
437
+		);
438
+		// end of row
439
+		$html .= EEH_HTML::trx();
440
+		return $html;
441
+	}
442
+
443
+
444
+
445
+	/**
446
+	 * _total_row
447
+	 *
448
+	 * @param EE_Line_Item $line_item
449
+	 * @param string       $text
450
+	 * @return mixed
451
+	 * @throws EE_Error
452
+	 */
453
+	private function _total_tax_row(EE_Line_Item $line_item, $text = '')
454
+	{
455
+		$html = '';
456
+		if ($line_item->total()) {
457
+			// start of row
458
+			$html = EEH_HTML::tr('', '', 'total_tr odd');
459
+			// total td
460
+			$html .= EEH_HTML::td(
461
+				$text,
462
+				'',
463
+				'total_currency total jst-rght',
464
+				'',
465
+				' colspan="2"'
466
+			);
467
+			// empty td (price)
468
+			$html .= EEH_HTML::td(EEH_HTML::nbsp());
469
+			// total td
470
+			$html .= EEH_HTML::td(
471
+				EEH_Template::format_currency($line_item->total(), false, false),
472
+				'',
473
+				'total jst-rght'
474
+			);
475
+			// end of row
476
+			$html .= EEH_HTML::trx();
477
+		}
478
+		return $html;
479
+	}
480
+
481
+
482
+
483
+	/**
484
+	 * _total_row
485
+	 *
486
+	 * @param EE_Line_Item $line_item
487
+	 * @param string       $text
488
+	 * @param array        $options
489
+	 * @return mixed
490
+	 * @throws EE_Error
491
+	 */
492
+	private function _sub_total_row(EE_Line_Item $line_item, $text = '', $options = array())
493
+	{
494
+		$html = '';
495
+		if ($line_item->total()) {
496
+			// start of row
497
+			$html = EEH_HTML::tr('', '', 'total_tr odd');
498
+			// total td
499
+			$html .= EEH_HTML::td(
500
+				$text,
501
+				'',
502
+				'total_currency total jst-rght',
503
+				'',
504
+				' colspan="3"'
505
+			);
506
+			// total td
507
+			$html .= EEH_HTML::td(
508
+				EEH_Template::format_currency($options['sub_total'], false, false),
509
+				'',
510
+				'total jst-rght'
511
+			);
512
+			// end of row
513
+			$html .= EEH_HTML::trx();
514
+		}
515
+		return $html;
516
+	}
517
+
518
+
519
+
520
+	/**
521
+	 * _total_row
522
+	 *
523
+	 * @param EE_Line_Item $line_item
524
+	 * @param string       $text
525
+	 * @return mixed
526
+	 * @throws EE_Error
527
+	 */
528
+	private function _total_row(EE_Line_Item $line_item, $text = '')
529
+	{
530
+		// start of row
531
+		$html = EEH_HTML::tr('', '', 'spco-grand-total total_tr odd');
532
+		// total td
533
+		$html .= EEH_HTML::td($text, '', 'total_currency total jst-rght', '', ' colspan="3"');
534
+		// total td
535
+		$html .= EEH_HTML::td(
536
+			EEH_Template::format_currency($line_item->total(), false, false),
537
+			'',
538
+			'total jst-rght'
539
+		);
540
+		// end of row
541
+		$html .= EEH_HTML::trx();
542
+		return $html;
543
+	}
544
+
545
+
546
+
547
+	/**
548
+	 * _payments_and_amount_owing_rows
549
+	 *
550
+	 * @param EE_Line_Item $line_item
551
+	 * @param array        $options
552
+	 * @return mixed
553
+	 * @throws EE_Error
554
+	 */
555
+	private function _payments_and_amount_owing_rows(EE_Line_Item $line_item, $options = array())
556
+	{
557
+		$html = '';
558
+		$owing = $line_item->total();
559
+		$transaction = EEM_Transaction::instance()->get_one_by_ID($line_item->TXN_ID());
560
+		if ($transaction instanceof EE_Transaction) {
561
+			$registration_payments = array();
562
+			$registrations = ! empty($options['registrations'])
563
+				? $options['registrations']
564
+				: $transaction->registrations();
565
+			foreach ($registrations as $registration) {
566
+				if ($registration instanceof EE_Registration && $registration->owes_monies_and_can_pay()) {
567
+					$registration_payments += $registration->registration_payments();
568
+				}
569
+			}
570
+			if (! empty($registration_payments)) {
571
+				foreach ($registration_payments as $registration_payment) {
572
+					if ($registration_payment instanceof EE_Registration_Payment) {
573
+						$owing -= $registration_payment->amount();
574
+						$payment = $registration_payment->payment();
575
+						$payment_desc = '';
576
+						if ($payment instanceof EE_Payment) {
577
+							$payment_desc = sprintf(
578
+								esc_html__('Payment%1$s Received: %2$s', 'event_espresso'),
579
+								$payment->txn_id_chq_nmbr() !== ''
580
+									? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> '
581
+									: '',
582
+								$payment->timestamp()
583
+							);
584
+						}
585
+						// start of row
586
+						$html .= EEH_HTML::tr('', '', 'total_tr odd');
587
+						// payment desc
588
+						$html .= EEH_HTML::td($payment_desc, '', '', '', ' colspan="3"');
589
+						// total td
590
+						$html .= EEH_HTML::td(
591
+							EEH_Template::format_currency(
592
+								$registration_payment->amount(),
593
+								false,
594
+								false
595
+							),
596
+							'',
597
+							'total jst-rght'
598
+						);
599
+						// end of row
600
+						$html .= EEH_HTML::trx();
601
+					}
602
+				}
603
+				if ($line_item->total()) {
604
+					// start of row
605
+					$html .= EEH_HTML::tr('', '', 'total_tr odd');
606
+					// total td
607
+					$html .= EEH_HTML::td(
608
+						esc_html__('Amount Owing', 'event_espresso'),
609
+						'', 'total_currency total jst-rght', '', ' colspan="3"'
610
+					);
611
+					// total td
612
+					$html .= EEH_HTML::td(
613
+						EEH_Template::format_currency($owing, false, false),
614
+						'',
615
+						'total jst-rght'
616
+					);
617
+					// end of row
618
+					$html .= EEH_HTML::trx();
619
+				}
620
+			}
621
+		}
622
+		$this->_grand_total = $owing;
623
+		return $html;
624
+	}
625 625
 
626 626
 
627 627
 }
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -88,10 +88,10 @@  discard block
 block discarded – undo
88 88
         $html = '';
89 89
         // set some default options and merge with incoming
90 90
         $default_options = array(
91
-            'show_desc' => true,  // 	true 		false
91
+            'show_desc' => true, // 	true 		false
92 92
             'odd'       => false,
93 93
         );
94
-        $options = array_merge($default_options, (array)$options);
94
+        $options = array_merge($default_options, (array) $options);
95 95
         switch ($line_item->type()) {
96 96
             case EEM_Line_Item::type_line_item:
97 97
                 $this->_show_taxes = $line_item->is_taxable() ? true : $this->_show_taxes;
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
                 $text = esc_html__('Sub-Total', 'event_espresso');
124 124
                 if ($line_item->OBJ_type() === 'Event') {
125 125
                     $options['event_id'] = $event_id = $line_item->OBJ_ID();
126
-                    if (! isset($this->_events[$options['event_id']])) {
126
+                    if ( ! isset($this->_events[$options['event_id']])) {
127 127
                         $event = EEM_Event::instance()->get_one_by_ID($options['event_id']);
128 128
                         // if event has default reg status of Not Approved, then don't display info on it
129 129
                         if (
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
                             // unless there are registrations for it that are returning to pay
135 135
                             if (isset($options['registrations']) && is_array($options['registrations'])) {
136 136
                                 foreach ($options['registrations'] as $registration) {
137
-                                    if (! $registration instanceof EE_Registration) {
137
+                                    if ( ! $registration instanceof EE_Registration) {
138 138
                                         continue;
139 139
                                     }
140 140
                                     $display_event = $registration->event_ID() === $options['event_id']
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
                                         : $display_event;
144 144
                                 }
145 145
                             }
146
-                            if (! $display_event) {
146
+                            if ( ! $display_event) {
147 147
                                 return '';
148 148
                             }
149 149
                         }
@@ -267,7 +267,7 @@  discard block
 block discarded – undo
267 267
             'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
268 268
             (
269 269
                 $options['show_desc']
270
-                    ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
270
+                    ? '<span class="line-item-desc-spn smaller-text">: '.$line_item->desc().'</span>'
271 271
                     : ''
272 272
             ),
273 273
             $line_item,
@@ -311,18 +311,18 @@  discard block
 block discarded – undo
311 311
         // start of row
312 312
         $row_class = $options['odd'] ? 'item odd' : 'item';
313 313
         $html = EEH_HTML::tr('', '', $row_class);
314
-        $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n() . ': ' : '';
314
+        $obj_name = $line_item->OBJ_type() ? $line_item->OBJ_type_i18n().': ' : '';
315 315
         // name && desc
316 316
         $name_and_desc = apply_filters(
317 317
             'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__name',
318
-            $obj_name . $line_item->name(),
318
+            $obj_name.$line_item->name(),
319 319
             $line_item
320 320
         );
321 321
         $name_and_desc .= apply_filters(
322 322
             'FHEE__EE_SPCO_Line_Item_Display_Strategy__item_row__desc',
323 323
             (
324 324
                 $options['show_desc']
325
-                ? '<span class="line-item-desc-spn smaller-text">: ' . $line_item->desc() . '</span>'
325
+                ? '<span class="line-item-desc-spn smaller-text">: '.$line_item->desc().'</span>'
326 326
                 : ''
327 327
             ),
328 328
             $line_item,
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
         $html .= EEH_HTML::td($name_and_desc, '', 'item_l');
334 334
         // price td
335 335
         if ($line_item->is_percent()) {
336
-            $html .= EEH_HTML::td($line_item->percent() . '%', '', 'item_c jst-rght');
336
+            $html .= EEH_HTML::td($line_item->percent().'%', '', 'item_c jst-rght');
337 337
         } else {
338 338
             $html .= EEH_HTML::td($line_item->unit_price_no_code(), '', 'item_c jst-rght');
339 339
         }
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
      */
369 369
     private function _sub_item_row(EE_Line_Item $line_item, $options = array(), EE_Line_Item $parent_line_item = null)
370 370
     {
371
-        if($parent_line_item instanceof  EE_Line_Item && $line_item->name() === $parent_line_item->name()) {
371
+        if ($parent_line_item instanceof  EE_Line_Item && $line_item->name() === $parent_line_item->name()) {
372 372
             return '';
373 373
         }
374 374
         // start of row
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
                                                   . $line_item->desc()
381 381
                                                   . '</span>' : '';
382 382
         // name td
383
-        $html .= EEH_HTML::td( $name_and_desc, '', 'item_l sub-item');
383
+        $html .= EEH_HTML::td($name_and_desc, '', 'item_l sub-item');
384 384
         $qty = $parent_line_item instanceof EE_Line_Item ? $parent_line_item->quantity() : 1;
385 385
         // discount/surcharge td
386 386
         if ($line_item->is_percent()) {
@@ -420,13 +420,13 @@  discard block
 block discarded – undo
420 420
         // name && desc
421 421
         $name_and_desc = $line_item->name();
422 422
         $name_and_desc .= '<span class="smaller-text lt-grey-text" style="margin:0 0 0 2em;">'
423
-                          . esc_html__(' * taxable items', 'event_espresso') . '</span>';
424
-        $name_and_desc .= $options['show_desc'] ? '<br/>' . $line_item->desc() : '';
423
+                          . esc_html__(' * taxable items', 'event_espresso').'</span>';
424
+        $name_and_desc .= $options['show_desc'] ? '<br/>'.$line_item->desc() : '';
425 425
         // name td
426 426
         $html .= EEH_HTML::td( /*__FUNCTION__ .*/
427 427
             $name_and_desc, '', 'item_l sub-item');
428 428
         // percent td
429
-        $html .= EEH_HTML::td($line_item->percent() . '%', '', ' jst-rght', '');
429
+        $html .= EEH_HTML::td($line_item->percent().'%', '', ' jst-rght', '');
430 430
         // empty td (price)
431 431
         $html .= EEH_HTML::td(EEH_HTML::nbsp());
432 432
         // total td
@@ -567,7 +567,7 @@  discard block
 block discarded – undo
567 567
                     $registration_payments += $registration->registration_payments();
568 568
                 }
569 569
             }
570
-            if (! empty($registration_payments)) {
570
+            if ( ! empty($registration_payments)) {
571 571
                 foreach ($registration_payments as $registration_payment) {
572 572
                     if ($registration_payment instanceof EE_Registration_Payment) {
573 573
                         $owing -= $registration_payment->amount();
@@ -577,7 +577,7 @@  discard block
 block discarded – undo
577 577
                             $payment_desc = sprintf(
578 578
                                 esc_html__('Payment%1$s Received: %2$s', 'event_espresso'),
579 579
                                 $payment->txn_id_chq_nmbr() !== ''
580
-                                    ? ' <span class="small-text">(#' . $payment->txn_id_chq_nmbr() . ')</span> '
580
+                                    ? ' <span class="small-text">(#'.$payment->txn_id_chq_nmbr().')</span> '
581 581
                                     : '',
582 582
                                 $payment->timestamp()
583 583
                             );
Please login to merge, or discard this patch.
core/libraries/line_item_filters/EE_Non_Zero_Line_Item_Filter.class.php 2 patches
Indentation   +97 added lines, -97 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if (! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('No direct script access allowed');
3
+	exit('No direct script access allowed');
4 4
 }
5 5
 
6 6
 
@@ -19,102 +19,102 @@  discard block
 block discarded – undo
19 19
 class EE_Non_Zero_Line_Item_Filter extends EE_Line_Item_Filter_Base
20 20
 {
21 21
 
22
-    /**
23
-     * EE_Non_Zero_Line_Item_Filter constructor.
24
-     */
25
-    public function __construct()
26
-    {
27
-    }
28
-
29
-
30
-
31
-    /**
32
-     * Creates a duplicate of the line item tree, except only includes billable items
33
-     * and the portion of line items attributed to billable things
34
-     *
35
-     * @param EEI_Line_Item $line_item
36
-     * @return EEI_Line_Item
37
-     */
38
-    public function process(EEI_Line_Item $line_item)
39
-    {
40
-        $non_zero_line_item = $this->_filter_zero_line_item($line_item);
41
-        if (! $non_zero_line_item instanceof EEI_Line_Item) {
42
-            return null;
43
-        }
44
-        //if this is an event subtotal, we want to only include it if it
45
-        //has a non-zero total and at least one ticket line item child
46
-        if ($line_item->children()) {
47
-            $ticket_or_subtotals_with_tkt_children_count = 0;
48
-            foreach ($line_item->children() as $child_line_item) {
49
-                $code = $child_line_item->code();
50
-                $child_line_item = $this->process($child_line_item);
51
-                if (! $child_line_item instanceof EEI_Line_Item) {
52
-                    $line_item->delete_child_line_item($code);
53
-                    continue;
54
-                }
55
-                if (
56
-                    (
57
-                        $child_line_item instanceof EEI_Line_Item
58
-                        && $child_line_item->type() === EEM_Line_Item::type_sub_total
59
-                    )
60
-                    || (
61
-                        $child_line_item instanceof EEI_Line_Item
62
-                        && $child_line_item->type() === EEM_Line_Item::type_line_item
63
-                        && $child_line_item->OBJ_type() === 'Ticket'
64
-                    )
65
-                ) {
66
-                    $ticket_or_subtotals_with_tkt_children_count++;
67
-                }
68
-            }
69
-            // if this is an event subtotal with NO ticket children
70
-            // we basically want to ignore it
71
-            return $this->_filter_zero_subtotal_line_item($non_zero_line_item,
72
-                $ticket_or_subtotals_with_tkt_children_count);
73
-        }
74
-        return $non_zero_line_item;
75
-    }
76
-
77
-
78
-
79
-    /**
80
-     * Creates a new, unsaved line item, but if it's a ticket line item
81
-     * with a total of 0, or a subtotal of 0, returns null instead
82
-     *
83
-     * @param EEI_Line_Item $line_item
84
-     * @return EEI_Line_Item
85
-     */
86
-    protected function _filter_zero_line_item(EEI_Line_Item $line_item)
87
-    {
88
-        if (
89
-            $line_item->type() === EEM_Line_Item::type_line_item
90
-            && $line_item->OBJ_type() === 'Ticket'
91
-            && (int)$line_item->quantity() === 0
92
-        ) {
93
-            return null;
94
-        }
95
-        return $line_item;
96
-    }
97
-
98
-
99
-
100
-    /**
101
-     * Creates a new, unsaved line item, but if it's a ticket line item
102
-     * with a total of 0, or a subtotal of 0, returns null instead
103
-     *
104
-     * @param EEI_Line_Item $line_item
105
-     * @param int           $ticket_children
106
-     * @return EEI_Line_Item
107
-     */
108
-    protected function _filter_zero_subtotal_line_item(EEI_Line_Item $line_item, $ticket_children = 0)
109
-    {
110
-        if (
111
-            (int)$ticket_children === 0
112
-            && $line_item->type() === EEM_Line_Item::type_sub_total
113
-        ) {
114
-            return null;
115
-        }
116
-        return $line_item;
117
-    }
22
+	/**
23
+	 * EE_Non_Zero_Line_Item_Filter constructor.
24
+	 */
25
+	public function __construct()
26
+	{
27
+	}
28
+
29
+
30
+
31
+	/**
32
+	 * Creates a duplicate of the line item tree, except only includes billable items
33
+	 * and the portion of line items attributed to billable things
34
+	 *
35
+	 * @param EEI_Line_Item $line_item
36
+	 * @return EEI_Line_Item
37
+	 */
38
+	public function process(EEI_Line_Item $line_item)
39
+	{
40
+		$non_zero_line_item = $this->_filter_zero_line_item($line_item);
41
+		if (! $non_zero_line_item instanceof EEI_Line_Item) {
42
+			return null;
43
+		}
44
+		//if this is an event subtotal, we want to only include it if it
45
+		//has a non-zero total and at least one ticket line item child
46
+		if ($line_item->children()) {
47
+			$ticket_or_subtotals_with_tkt_children_count = 0;
48
+			foreach ($line_item->children() as $child_line_item) {
49
+				$code = $child_line_item->code();
50
+				$child_line_item = $this->process($child_line_item);
51
+				if (! $child_line_item instanceof EEI_Line_Item) {
52
+					$line_item->delete_child_line_item($code);
53
+					continue;
54
+				}
55
+				if (
56
+					(
57
+						$child_line_item instanceof EEI_Line_Item
58
+						&& $child_line_item->type() === EEM_Line_Item::type_sub_total
59
+					)
60
+					|| (
61
+						$child_line_item instanceof EEI_Line_Item
62
+						&& $child_line_item->type() === EEM_Line_Item::type_line_item
63
+						&& $child_line_item->OBJ_type() === 'Ticket'
64
+					)
65
+				) {
66
+					$ticket_or_subtotals_with_tkt_children_count++;
67
+				}
68
+			}
69
+			// if this is an event subtotal with NO ticket children
70
+			// we basically want to ignore it
71
+			return $this->_filter_zero_subtotal_line_item($non_zero_line_item,
72
+				$ticket_or_subtotals_with_tkt_children_count);
73
+		}
74
+		return $non_zero_line_item;
75
+	}
76
+
77
+
78
+
79
+	/**
80
+	 * Creates a new, unsaved line item, but if it's a ticket line item
81
+	 * with a total of 0, or a subtotal of 0, returns null instead
82
+	 *
83
+	 * @param EEI_Line_Item $line_item
84
+	 * @return EEI_Line_Item
85
+	 */
86
+	protected function _filter_zero_line_item(EEI_Line_Item $line_item)
87
+	{
88
+		if (
89
+			$line_item->type() === EEM_Line_Item::type_line_item
90
+			&& $line_item->OBJ_type() === 'Ticket'
91
+			&& (int)$line_item->quantity() === 0
92
+		) {
93
+			return null;
94
+		}
95
+		return $line_item;
96
+	}
97
+
98
+
99
+
100
+	/**
101
+	 * Creates a new, unsaved line item, but if it's a ticket line item
102
+	 * with a total of 0, or a subtotal of 0, returns null instead
103
+	 *
104
+	 * @param EEI_Line_Item $line_item
105
+	 * @param int           $ticket_children
106
+	 * @return EEI_Line_Item
107
+	 */
108
+	protected function _filter_zero_subtotal_line_item(EEI_Line_Item $line_item, $ticket_children = 0)
109
+	{
110
+		if (
111
+			(int)$ticket_children === 0
112
+			&& $line_item->type() === EEM_Line_Item::type_sub_total
113
+		) {
114
+			return null;
115
+		}
116
+		return $line_item;
117
+	}
118 118
 
119 119
 
120 120
 
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (! defined('EVENT_ESPRESSO_VERSION')) {
2
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3 3
     exit('No direct script access allowed');
4 4
 }
5 5
 
@@ -38,7 +38,7 @@  discard block
 block discarded – undo
38 38
     public function process(EEI_Line_Item $line_item)
39 39
     {
40 40
         $non_zero_line_item = $this->_filter_zero_line_item($line_item);
41
-        if (! $non_zero_line_item instanceof EEI_Line_Item) {
41
+        if ( ! $non_zero_line_item instanceof EEI_Line_Item) {
42 42
             return null;
43 43
         }
44 44
         //if this is an event subtotal, we want to only include it if it
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
             foreach ($line_item->children() as $child_line_item) {
49 49
                 $code = $child_line_item->code();
50 50
                 $child_line_item = $this->process($child_line_item);
51
-                if (! $child_line_item instanceof EEI_Line_Item) {
51
+                if ( ! $child_line_item instanceof EEI_Line_Item) {
52 52
                     $line_item->delete_child_line_item($code);
53 53
                     continue;
54 54
                 }
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
         if (
89 89
             $line_item->type() === EEM_Line_Item::type_line_item
90 90
             && $line_item->OBJ_type() === 'Ticket'
91
-            && (int)$line_item->quantity() === 0
91
+            && (int) $line_item->quantity() === 0
92 92
         ) {
93 93
             return null;
94 94
         }
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
     protected function _filter_zero_subtotal_line_item(EEI_Line_Item $line_item, $ticket_children = 0)
109 109
     {
110 110
         if (
111
-            (int)$ticket_children === 0
111
+            (int) $ticket_children === 0
112 112
             && $line_item->type() === EEM_Line_Item::type_sub_total
113 113
         ) {
114 114
             return null;
Please login to merge, or discard this patch.
line_item_filters/EE_Specific_Registrations_Line_Item_Filter.class.php 2 patches
Indentation   +187 added lines, -187 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if (! defined('EVENT_ESPRESSO_VERSION')) {
3
-    exit('No direct script access allowed');
3
+	exit('No direct script access allowed');
4 4
 }
5 5
 
6 6
 
@@ -18,192 +18,192 @@  discard block
 block discarded – undo
18 18
 class EE_Specific_Registrations_Line_Item_Filter extends EE_Line_Item_Filter_Base
19 19
 {
20 20
 
21
-    /**
22
-     * array of line item codes and their corresponding quantities for registrations
23
-     *
24
-     * @type array $_line_item_registrations
25
-     */
26
-    protected $_line_item_registrations = array();
27
-
28
-    /**
29
-     * Just kept in case we want it someday. Currently unused
30
-     *
31
-     * @var EE_Registration[]
32
-     */
33
-    protected $_registrations = array();
34
-
35
-    /**
36
-     * @var EE_Registration
37
-     */
38
-    protected $_current_registration;
39
-
40
-    /**
41
-     * these reg statuses should NOT increment the line item quantity
42
-     *
43
-     * @var array
44
-     */
45
-    protected $_closed_reg_statuses = array();
46
-
47
-
48
-
49
-    /**
50
-     * EE_Billable_Line_Item_Filter constructor.
51
-     *
52
-     * @param EE_Registration[] $registrations
53
-     * @throws EE_Error
54
-     */
55
-    public function __construct($registrations)
56
-    {
57
-        $this->_registrations = $registrations;
58
-        $this->_calculate_registrations_per_line_item_code($registrations);
59
-        // these reg statuses should NOT increment the line item quantity
60
-        $this->_closed_reg_statuses = EEM_Registration::closed_reg_statuses();
61
-    }
62
-
63
-
64
-
65
-    /**
66
-     * sets the _line_item_registrations from the provided registrations
67
-     *
68
-     * @param EE_Registration[] $registrations
69
-     * @return void
70
-     * @throws EE_Error
71
-     */
72
-    protected function _calculate_registrations_per_line_item_code($registrations)
73
-    {
74
-        foreach ($registrations as $registration) {
75
-            $line_item_code = EEM_Line_Item::instance()->get_var(
76
-                EEM_Line_Item::instance()->line_item_for_registration_query_params(
77
-                    $registration,
78
-                    array('limit' => 1)
79
-                ),
80
-                'LIN_code'
81
-            );
82
-            if ($line_item_code) {
83
-                if (! isset($this->_line_item_registrations[$line_item_code])) {
84
-                    $this->_line_item_registrations[$line_item_code] = array();
85
-                }
86
-                $this->_line_item_registrations[$line_item_code][$registration->ID()] = $registration;
87
-            }
88
-        }
89
-    }
90
-
91
-
92
-
93
-    /**
94
-     * Creates a duplicate of the line item tree, except only includes billable items
95
-     * and the portion of line items attributed to billable things
96
-     *
97
-     * @param EEI_Line_Item $line_item
98
-     * @return EEI_Line_Item
99
-     * @throws EE_Error
100
-     */
101
-    public function process(EEI_Line_Item $line_item)
102
-    {
103
-        $this->_adjust_line_item_quantity($line_item);
104
-        if (! $line_item->children()) {
105
-            return $line_item;
106
-        }
107
-        //the original running total (taking ALL tickets into account)
108
-        $running_total_of_children = 0;
109
-        //the new running total (only taking the specified ticket quantities into account)
110
-        $running_total_of_children_under_consideration = 0;
111
-        // let's also track the quantity of tickets that pertain to the registrations
112
-        $total_child_ticket_quantity = 0;
113
-        foreach ($line_item->children() as $child_line_item) {
114
-            $original_li_total = $child_line_item->is_percent()
115
-                ? $running_total_of_children * $child_line_item->percent() / 100
116
-                : $child_line_item->unit_price() * $child_line_item->quantity();
117
-            $this->process($child_line_item);
118
-            // If this line item is a normal line item that isn't for a ticket,
119
-            // we want to modify its total (and unit price if not a percentage line item)
120
-            // so it reflects only that portion of the surcharge/discount shared by these registrations
121
-            if (
122
-                $child_line_item->type() === EEM_Line_Item::type_line_item
123
-                && $child_line_item->OBJ_type() !== 'Ticket'
124
-            ) {
125
-                $percent_of_running_total = $running_total_of_children
126
-                    ? $original_li_total / $running_total_of_children
127
-                    : 0;
128
-                $child_line_item->set_total(
129
-                    $running_total_of_children_under_consideration * $percent_of_running_total
130
-                );
131
-                if (! $child_line_item->is_percent()) {
132
-                    $child_line_item->set_unit_price($child_line_item->total() / $child_line_item->quantity());
133
-                }
134
-            } else if (
135
-                //make sure this item's quantity and total matches its parent
136
-                $line_item->type() === EEM_Line_Item::type_line_item
137
-                && $line_item->OBJ_type() === 'Ticket'
138
-                // but not if it's a percentage modifier
139
-                && ! $child_line_item->is_percent()
140
-                && ! (
141
-                    // or a cancellation
142
-                    $child_line_item->is_cancelled()
143
-                    && ! (
144
-                        // unless it IS a cancellation and the current registration is cancelled
145
-                        $child_line_item->is_cancelled()
146
-                        && $this->_current_registration instanceof EE_Registration
147
-                        && in_array($this->_current_registration->status_ID(), $this->_closed_reg_statuses, true)
148
-                    )
149
-                )
150
-            ) {
151
-                $child_line_item->set_quantity($line_item->quantity());
152
-                $child_line_item->set_total($child_line_item->unit_price() * $child_line_item->quantity());
153
-            }
154
-            $running_total_of_children += $original_li_total;
155
-            $running_total_of_children_under_consideration += $child_line_item->total();
156
-            if ($child_line_item->OBJ_type() === 'Ticket') {
157
-                $total_child_ticket_quantity += $child_line_item->quantity();
158
-            }
159
-        }
160
-        $line_item->set_total($running_total_of_children_under_consideration);
161
-        if ($line_item->quantity()) {
162
-            $line_item->set_unit_price($running_total_of_children_under_consideration / $line_item->quantity());
163
-        } else {
164
-            $line_item->set_unit_price(0);
165
-        }
166
-        if ($line_item->OBJ_type() === 'Event') {
167
-            $line_item->set_quantity($total_child_ticket_quantity);
168
-        }
169
-        return $line_item;
170
-    }
171
-
172
-
173
-
174
-    /**
175
-     * Adjusts quantities for line items for tickets according to the registrations provided
176
-     * in the constructor
177
-     *
178
-     * @param EEI_Line_Item $line_item
179
-     * @return EEI_Line_Item
180
-     */
181
-    protected function _adjust_line_item_quantity(EEI_Line_Item $line_item)
182
-    {
183
-        // is this a ticket ?
184
-        if ($line_item->type() === EEM_Line_Item::type_line_item && $line_item->OBJ_type() === 'Ticket') {
185
-            $this->_current_registration = null;
186
-            $quantity = 0;
187
-            // if this ticket is billable at this moment, then we should have a positive quantity
188
-            if (
189
-                isset($this->_line_item_registrations[$line_item->code()])
190
-                && is_array($this->_line_item_registrations[$line_item->code()])
191
-            ) {
192
-                // set quantity based on number of open registrations for this ticket
193
-                foreach ($this->_line_item_registrations[$line_item->code()] as $registration) {
194
-                    if (
195
-                        $registration instanceof EE_Registration
196
-                    ) {
197
-                        $quantity++;
198
-                        $this->_current_registration = $registration;
199
-                    }
200
-                }
201
-            }
202
-            $line_item->set_quantity($quantity);
203
-            $line_item->set_total($line_item->unit_price() * $line_item->quantity());
204
-        }
205
-        return $line_item;
206
-    }
21
+	/**
22
+	 * array of line item codes and their corresponding quantities for registrations
23
+	 *
24
+	 * @type array $_line_item_registrations
25
+	 */
26
+	protected $_line_item_registrations = array();
27
+
28
+	/**
29
+	 * Just kept in case we want it someday. Currently unused
30
+	 *
31
+	 * @var EE_Registration[]
32
+	 */
33
+	protected $_registrations = array();
34
+
35
+	/**
36
+	 * @var EE_Registration
37
+	 */
38
+	protected $_current_registration;
39
+
40
+	/**
41
+	 * these reg statuses should NOT increment the line item quantity
42
+	 *
43
+	 * @var array
44
+	 */
45
+	protected $_closed_reg_statuses = array();
46
+
47
+
48
+
49
+	/**
50
+	 * EE_Billable_Line_Item_Filter constructor.
51
+	 *
52
+	 * @param EE_Registration[] $registrations
53
+	 * @throws EE_Error
54
+	 */
55
+	public function __construct($registrations)
56
+	{
57
+		$this->_registrations = $registrations;
58
+		$this->_calculate_registrations_per_line_item_code($registrations);
59
+		// these reg statuses should NOT increment the line item quantity
60
+		$this->_closed_reg_statuses = EEM_Registration::closed_reg_statuses();
61
+	}
62
+
63
+
64
+
65
+	/**
66
+	 * sets the _line_item_registrations from the provided registrations
67
+	 *
68
+	 * @param EE_Registration[] $registrations
69
+	 * @return void
70
+	 * @throws EE_Error
71
+	 */
72
+	protected function _calculate_registrations_per_line_item_code($registrations)
73
+	{
74
+		foreach ($registrations as $registration) {
75
+			$line_item_code = EEM_Line_Item::instance()->get_var(
76
+				EEM_Line_Item::instance()->line_item_for_registration_query_params(
77
+					$registration,
78
+					array('limit' => 1)
79
+				),
80
+				'LIN_code'
81
+			);
82
+			if ($line_item_code) {
83
+				if (! isset($this->_line_item_registrations[$line_item_code])) {
84
+					$this->_line_item_registrations[$line_item_code] = array();
85
+				}
86
+				$this->_line_item_registrations[$line_item_code][$registration->ID()] = $registration;
87
+			}
88
+		}
89
+	}
90
+
91
+
92
+
93
+	/**
94
+	 * Creates a duplicate of the line item tree, except only includes billable items
95
+	 * and the portion of line items attributed to billable things
96
+	 *
97
+	 * @param EEI_Line_Item $line_item
98
+	 * @return EEI_Line_Item
99
+	 * @throws EE_Error
100
+	 */
101
+	public function process(EEI_Line_Item $line_item)
102
+	{
103
+		$this->_adjust_line_item_quantity($line_item);
104
+		if (! $line_item->children()) {
105
+			return $line_item;
106
+		}
107
+		//the original running total (taking ALL tickets into account)
108
+		$running_total_of_children = 0;
109
+		//the new running total (only taking the specified ticket quantities into account)
110
+		$running_total_of_children_under_consideration = 0;
111
+		// let's also track the quantity of tickets that pertain to the registrations
112
+		$total_child_ticket_quantity = 0;
113
+		foreach ($line_item->children() as $child_line_item) {
114
+			$original_li_total = $child_line_item->is_percent()
115
+				? $running_total_of_children * $child_line_item->percent() / 100
116
+				: $child_line_item->unit_price() * $child_line_item->quantity();
117
+			$this->process($child_line_item);
118
+			// If this line item is a normal line item that isn't for a ticket,
119
+			// we want to modify its total (and unit price if not a percentage line item)
120
+			// so it reflects only that portion of the surcharge/discount shared by these registrations
121
+			if (
122
+				$child_line_item->type() === EEM_Line_Item::type_line_item
123
+				&& $child_line_item->OBJ_type() !== 'Ticket'
124
+			) {
125
+				$percent_of_running_total = $running_total_of_children
126
+					? $original_li_total / $running_total_of_children
127
+					: 0;
128
+				$child_line_item->set_total(
129
+					$running_total_of_children_under_consideration * $percent_of_running_total
130
+				);
131
+				if (! $child_line_item->is_percent()) {
132
+					$child_line_item->set_unit_price($child_line_item->total() / $child_line_item->quantity());
133
+				}
134
+			} else if (
135
+				//make sure this item's quantity and total matches its parent
136
+				$line_item->type() === EEM_Line_Item::type_line_item
137
+				&& $line_item->OBJ_type() === 'Ticket'
138
+				// but not if it's a percentage modifier
139
+				&& ! $child_line_item->is_percent()
140
+				&& ! (
141
+					// or a cancellation
142
+					$child_line_item->is_cancelled()
143
+					&& ! (
144
+						// unless it IS a cancellation and the current registration is cancelled
145
+						$child_line_item->is_cancelled()
146
+						&& $this->_current_registration instanceof EE_Registration
147
+						&& in_array($this->_current_registration->status_ID(), $this->_closed_reg_statuses, true)
148
+					)
149
+				)
150
+			) {
151
+				$child_line_item->set_quantity($line_item->quantity());
152
+				$child_line_item->set_total($child_line_item->unit_price() * $child_line_item->quantity());
153
+			}
154
+			$running_total_of_children += $original_li_total;
155
+			$running_total_of_children_under_consideration += $child_line_item->total();
156
+			if ($child_line_item->OBJ_type() === 'Ticket') {
157
+				$total_child_ticket_quantity += $child_line_item->quantity();
158
+			}
159
+		}
160
+		$line_item->set_total($running_total_of_children_under_consideration);
161
+		if ($line_item->quantity()) {
162
+			$line_item->set_unit_price($running_total_of_children_under_consideration / $line_item->quantity());
163
+		} else {
164
+			$line_item->set_unit_price(0);
165
+		}
166
+		if ($line_item->OBJ_type() === 'Event') {
167
+			$line_item->set_quantity($total_child_ticket_quantity);
168
+		}
169
+		return $line_item;
170
+	}
171
+
172
+
173
+
174
+	/**
175
+	 * Adjusts quantities for line items for tickets according to the registrations provided
176
+	 * in the constructor
177
+	 *
178
+	 * @param EEI_Line_Item $line_item
179
+	 * @return EEI_Line_Item
180
+	 */
181
+	protected function _adjust_line_item_quantity(EEI_Line_Item $line_item)
182
+	{
183
+		// is this a ticket ?
184
+		if ($line_item->type() === EEM_Line_Item::type_line_item && $line_item->OBJ_type() === 'Ticket') {
185
+			$this->_current_registration = null;
186
+			$quantity = 0;
187
+			// if this ticket is billable at this moment, then we should have a positive quantity
188
+			if (
189
+				isset($this->_line_item_registrations[$line_item->code()])
190
+				&& is_array($this->_line_item_registrations[$line_item->code()])
191
+			) {
192
+				// set quantity based on number of open registrations for this ticket
193
+				foreach ($this->_line_item_registrations[$line_item->code()] as $registration) {
194
+					if (
195
+						$registration instanceof EE_Registration
196
+					) {
197
+						$quantity++;
198
+						$this->_current_registration = $registration;
199
+					}
200
+				}
201
+			}
202
+			$line_item->set_quantity($quantity);
203
+			$line_item->set_total($line_item->unit_price() * $line_item->quantity());
204
+		}
205
+		return $line_item;
206
+	}
207 207
 
208 208
 
209 209
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if (! defined('EVENT_ESPRESSO_VERSION')) {
2
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
3 3
     exit('No direct script access allowed');
4 4
 }
5 5
 
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
                 'LIN_code'
81 81
             );
82 82
             if ($line_item_code) {
83
-                if (! isset($this->_line_item_registrations[$line_item_code])) {
83
+                if ( ! isset($this->_line_item_registrations[$line_item_code])) {
84 84
                     $this->_line_item_registrations[$line_item_code] = array();
85 85
                 }
86 86
                 $this->_line_item_registrations[$line_item_code][$registration->ID()] = $registration;
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
     public function process(EEI_Line_Item $line_item)
102 102
     {
103 103
         $this->_adjust_line_item_quantity($line_item);
104
-        if (! $line_item->children()) {
104
+        if ( ! $line_item->children()) {
105 105
             return $line_item;
106 106
         }
107 107
         //the original running total (taking ALL tickets into account)
@@ -128,7 +128,7 @@  discard block
 block discarded – undo
128 128
                 $child_line_item->set_total(
129 129
                     $running_total_of_children_under_consideration * $percent_of_running_total
130 130
                 );
131
-                if (! $child_line_item->is_percent()) {
131
+                if ( ! $child_line_item->is_percent()) {
132 132
                     $child_line_item->set_unit_price($child_line_item->total() / $child_line_item->quantity());
133 133
                 }
134 134
             } else if (
Please login to merge, or discard this patch.
core/libraries/form_sections/form_handlers/SequentialStepForm.php 2 patches
Indentation   +223 added lines, -223 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 use InvalidArgumentException;
9 9
 
10 10
 if (! defined('EVENT_ESPRESSO_VERSION')) {
11
-    exit('No direct script access allowed');
11
+	exit('No direct script access allowed');
12 12
 }
13 13
 
14 14
 
@@ -25,228 +25,228 @@  discard block
 block discarded – undo
25 25
 abstract class SequentialStepForm extends FormHandler implements SequentialStepFormInterface
26 26
 {
27 27
 
28
-    const REDIRECT_TO_NEXT_STEP    = 'redirect_to_next_step';
29
-
30
-    const REDIRECT_TO_CURRENT_STEP = 'redirect_to_current_step';
31
-
32
-    const REDIRECT_TO_PREV_STEP    = 'redirect_to_prev_step';
33
-
34
-    const REDIRECT_TO_OTHER        = 'redirect_to_other';
35
-
36
-    /**
37
-     * numerical value used for sorting form steps
38
-     *
39
-     * @var int $order
40
-     */
41
-    private $order = 1;
42
-
43
-    /**
44
-     * a final URL with all form related parameters added
45
-     * that will be used to advance to the next step
46
-     *
47
-     * @var string $redirect_url
48
-     */
49
-    private $redirect_url = '';
50
-
51
-    /**
52
-     * URL params in key value pairs
53
-     *
54
-     * @var array $redirect_args
55
-     */
56
-    private $redirect_args = array();
57
-
58
-    /**
59
-     * Which step should be redirected to after form processing.
60
-     * Usually after successfully processing this value would be REDIRECT_TO_NEXT_STEP
61
-     * If a form is invalid and requires errors to be corrected,
62
-     * then this value would be REDIRECT_TO_CURRENT_STEP so that form can be resubmitted
63
-     * Some form handlers do not have a form that is displayable,
64
-     * and only perform data processing, but if an error occurs,
65
-     * then this value needs to be set to REDIRECT_TO_PREV_STEP
66
-     * since the current step has no displayable content.
67
-     * if the form is completely finished, and needs to redirect to somewhere
68
-     * completely different, then this value will be REDIRECT_TO_OTHER
69
-     *
70
-     * @var string $redirect_to
71
-     */
72
-    private $redirect_to = SequentialStepForm::REDIRECT_TO_CURRENT_STEP;
73
-
74
-
75
-
76
-    /**
77
-     * SequentialStepForm constructor
78
-     *
79
-     * @param int         $order
80
-     * @param string      $form_name
81
-     * @param string      $admin_name
82
-     * @param string      $slug
83
-     * @param string      $form_action
84
-     * @param string      $form_config
85
-     * @param EE_Registry $registry
86
-     * @throws InvalidArgumentException
87
-     * @throws InvalidDataTypeException
88
-     * @throws DomainException
89
-     */
90
-    public function __construct(
91
-        $order,
92
-        $form_name,
93
-        $admin_name,
94
-        $slug,
95
-        $form_action = '',
96
-        $form_config = 'add_form_tags_and_submit',
97
-        EE_Registry $registry
98
-    ) {
99
-        $this->setOrder($order);
100
-        parent::__construct($form_name, $admin_name, $slug, $form_action, $form_config, $registry);
101
-    }
102
-
103
-
104
-
105
-    /**
106
-     * @return int
107
-     */
108
-    public function order()
109
-    {
110
-        return $this->order;
111
-    }
112
-
113
-
114
-
115
-    /**
116
-     * @param int $order
117
-     * @throws InvalidArgumentException
118
-     */
119
-    public function setOrder($order)
120
-    {
121
-        $order = absint($order);
122
-        if (! $order > 0) {
123
-            throw new InvalidArgumentException(
124
-                esc_html__('The form order property must be a positive integer.', 'event_espresso')
125
-            );
126
-        }
127
-        $this->order = $order;
128
-    }
129
-
130
-
131
-
132
-    /**
133
-     * @return string
134
-     */
135
-    public function redirectUrl()
136
-    {
137
-        return ! empty($this->redirect_args)
138
-            ? add_query_arg($this->redirect_args, $this->redirect_url)
139
-            : $this->redirect_url;
140
-    }
141
-
142
-
143
-
144
-    /**
145
-     * @param string $redirect_url
146
-     * @throws InvalidDataTypeException
147
-     * @throws InvalidArgumentException
148
-     */
149
-    public function setRedirectUrl($redirect_url)
150
-    {
151
-        if (! is_string($redirect_url)) {
152
-            throw new InvalidDataTypeException('$redirect_url', $redirect_url, 'string');
153
-        }
154
-        if (empty($redirect_url)) {
155
-            throw new InvalidArgumentException(
156
-                esc_html__('The redirect URL can not be an empty string.', 'event_espresso')
157
-            );
158
-        }
159
-        $this->redirect_url = $redirect_url;
160
-    }
161
-
162
-
163
-
164
-    /**
165
-     * @param array $redirect_args
166
-     * @throws InvalidDataTypeException
167
-     * @throws InvalidArgumentException
168
-     */
169
-    public function addRedirectArgs($redirect_args = array())
170
-    {
171
-        if (is_object($redirect_args)) {
172
-            throw new InvalidDataTypeException(
173
-                '$redirect_args',
174
-                $redirect_args,
175
-                'anything other than an object was expected.'
176
-            );
177
-        }
178
-        if (empty($redirect_args)) {
179
-            throw new InvalidArgumentException(
180
-                esc_html__('The redirect argument can not be an empty array.', 'event_espresso')
181
-            );
182
-        }
183
-        $this->redirect_args = array_merge($this->redirect_args, (array)$redirect_args);
184
-    }
185
-
186
-
187
-
188
-    /**
189
-     * @param array $redirect_arg_keys_to_remove
190
-     * @throws InvalidDataTypeException
191
-     * @throws InvalidArgumentException
192
-     */
193
-    public function removeRedirectArgs($redirect_arg_keys_to_remove = array())
194
-    {
195
-        if (is_object($redirect_arg_keys_to_remove)) {
196
-            throw new InvalidDataTypeException(
197
-                '$redirect_arg_keys_to_remove',
198
-                $redirect_arg_keys_to_remove,
199
-                'anything other than an object was expected.'
200
-            );
201
-        }
202
-        if (empty($redirect_arg_keys_to_remove)) {
203
-            throw new InvalidArgumentException(
204
-                esc_html__('The $redirect_arg_keys_to_remove argument can not be an empty array.', 'event_espresso')
205
-            );
206
-        }
207
-        foreach ($redirect_arg_keys_to_remove as $redirect_arg_key) {
208
-            unset($this->redirect_args[$redirect_arg_key]);
209
-        }
210
-    }
211
-
212
-
213
-
214
-    /**
215
-     * @return string
216
-     */
217
-    public function redirectTo()
218
-    {
219
-        return $this->redirect_to;
220
-    }
221
-
222
-
223
-
224
-    /**
225
-     * @param string $redirect_to
226
-     * @throws InvalidDataTypeException
227
-     */
228
-    public function setRedirectTo($redirect_to)
229
-    {
230
-        if (
231
-            ! in_array(
232
-                $redirect_to,
233
-                array(
234
-                    SequentialStepForm::REDIRECT_TO_NEXT_STEP,
235
-                    SequentialStepForm::REDIRECT_TO_CURRENT_STEP,
236
-                    SequentialStepForm::REDIRECT_TO_PREV_STEP,
237
-                    SequentialStepForm::REDIRECT_TO_OTHER,
238
-                ),
239
-                true
240
-            )
241
-        ) {
242
-            throw new InvalidDataTypeException(
243
-                'setRedirectTo()',
244
-                $redirect_to,
245
-                'one of the SequentialStepForm class constants was expected.'
246
-            );
247
-        }
248
-        $this->redirect_to = $redirect_to;
249
-    }
28
+	const REDIRECT_TO_NEXT_STEP    = 'redirect_to_next_step';
29
+
30
+	const REDIRECT_TO_CURRENT_STEP = 'redirect_to_current_step';
31
+
32
+	const REDIRECT_TO_PREV_STEP    = 'redirect_to_prev_step';
33
+
34
+	const REDIRECT_TO_OTHER        = 'redirect_to_other';
35
+
36
+	/**
37
+	 * numerical value used for sorting form steps
38
+	 *
39
+	 * @var int $order
40
+	 */
41
+	private $order = 1;
42
+
43
+	/**
44
+	 * a final URL with all form related parameters added
45
+	 * that will be used to advance to the next step
46
+	 *
47
+	 * @var string $redirect_url
48
+	 */
49
+	private $redirect_url = '';
50
+
51
+	/**
52
+	 * URL params in key value pairs
53
+	 *
54
+	 * @var array $redirect_args
55
+	 */
56
+	private $redirect_args = array();
57
+
58
+	/**
59
+	 * Which step should be redirected to after form processing.
60
+	 * Usually after successfully processing this value would be REDIRECT_TO_NEXT_STEP
61
+	 * If a form is invalid and requires errors to be corrected,
62
+	 * then this value would be REDIRECT_TO_CURRENT_STEP so that form can be resubmitted
63
+	 * Some form handlers do not have a form that is displayable,
64
+	 * and only perform data processing, but if an error occurs,
65
+	 * then this value needs to be set to REDIRECT_TO_PREV_STEP
66
+	 * since the current step has no displayable content.
67
+	 * if the form is completely finished, and needs to redirect to somewhere
68
+	 * completely different, then this value will be REDIRECT_TO_OTHER
69
+	 *
70
+	 * @var string $redirect_to
71
+	 */
72
+	private $redirect_to = SequentialStepForm::REDIRECT_TO_CURRENT_STEP;
73
+
74
+
75
+
76
+	/**
77
+	 * SequentialStepForm constructor
78
+	 *
79
+	 * @param int         $order
80
+	 * @param string      $form_name
81
+	 * @param string      $admin_name
82
+	 * @param string      $slug
83
+	 * @param string      $form_action
84
+	 * @param string      $form_config
85
+	 * @param EE_Registry $registry
86
+	 * @throws InvalidArgumentException
87
+	 * @throws InvalidDataTypeException
88
+	 * @throws DomainException
89
+	 */
90
+	public function __construct(
91
+		$order,
92
+		$form_name,
93
+		$admin_name,
94
+		$slug,
95
+		$form_action = '',
96
+		$form_config = 'add_form_tags_and_submit',
97
+		EE_Registry $registry
98
+	) {
99
+		$this->setOrder($order);
100
+		parent::__construct($form_name, $admin_name, $slug, $form_action, $form_config, $registry);
101
+	}
102
+
103
+
104
+
105
+	/**
106
+	 * @return int
107
+	 */
108
+	public function order()
109
+	{
110
+		return $this->order;
111
+	}
112
+
113
+
114
+
115
+	/**
116
+	 * @param int $order
117
+	 * @throws InvalidArgumentException
118
+	 */
119
+	public function setOrder($order)
120
+	{
121
+		$order = absint($order);
122
+		if (! $order > 0) {
123
+			throw new InvalidArgumentException(
124
+				esc_html__('The form order property must be a positive integer.', 'event_espresso')
125
+			);
126
+		}
127
+		$this->order = $order;
128
+	}
129
+
130
+
131
+
132
+	/**
133
+	 * @return string
134
+	 */
135
+	public function redirectUrl()
136
+	{
137
+		return ! empty($this->redirect_args)
138
+			? add_query_arg($this->redirect_args, $this->redirect_url)
139
+			: $this->redirect_url;
140
+	}
141
+
142
+
143
+
144
+	/**
145
+	 * @param string $redirect_url
146
+	 * @throws InvalidDataTypeException
147
+	 * @throws InvalidArgumentException
148
+	 */
149
+	public function setRedirectUrl($redirect_url)
150
+	{
151
+		if (! is_string($redirect_url)) {
152
+			throw new InvalidDataTypeException('$redirect_url', $redirect_url, 'string');
153
+		}
154
+		if (empty($redirect_url)) {
155
+			throw new InvalidArgumentException(
156
+				esc_html__('The redirect URL can not be an empty string.', 'event_espresso')
157
+			);
158
+		}
159
+		$this->redirect_url = $redirect_url;
160
+	}
161
+
162
+
163
+
164
+	/**
165
+	 * @param array $redirect_args
166
+	 * @throws InvalidDataTypeException
167
+	 * @throws InvalidArgumentException
168
+	 */
169
+	public function addRedirectArgs($redirect_args = array())
170
+	{
171
+		if (is_object($redirect_args)) {
172
+			throw new InvalidDataTypeException(
173
+				'$redirect_args',
174
+				$redirect_args,
175
+				'anything other than an object was expected.'
176
+			);
177
+		}
178
+		if (empty($redirect_args)) {
179
+			throw new InvalidArgumentException(
180
+				esc_html__('The redirect argument can not be an empty array.', 'event_espresso')
181
+			);
182
+		}
183
+		$this->redirect_args = array_merge($this->redirect_args, (array)$redirect_args);
184
+	}
185
+
186
+
187
+
188
+	/**
189
+	 * @param array $redirect_arg_keys_to_remove
190
+	 * @throws InvalidDataTypeException
191
+	 * @throws InvalidArgumentException
192
+	 */
193
+	public function removeRedirectArgs($redirect_arg_keys_to_remove = array())
194
+	{
195
+		if (is_object($redirect_arg_keys_to_remove)) {
196
+			throw new InvalidDataTypeException(
197
+				'$redirect_arg_keys_to_remove',
198
+				$redirect_arg_keys_to_remove,
199
+				'anything other than an object was expected.'
200
+			);
201
+		}
202
+		if (empty($redirect_arg_keys_to_remove)) {
203
+			throw new InvalidArgumentException(
204
+				esc_html__('The $redirect_arg_keys_to_remove argument can not be an empty array.', 'event_espresso')
205
+			);
206
+		}
207
+		foreach ($redirect_arg_keys_to_remove as $redirect_arg_key) {
208
+			unset($this->redirect_args[$redirect_arg_key]);
209
+		}
210
+	}
211
+
212
+
213
+
214
+	/**
215
+	 * @return string
216
+	 */
217
+	public function redirectTo()
218
+	{
219
+		return $this->redirect_to;
220
+	}
221
+
222
+
223
+
224
+	/**
225
+	 * @param string $redirect_to
226
+	 * @throws InvalidDataTypeException
227
+	 */
228
+	public function setRedirectTo($redirect_to)
229
+	{
230
+		if (
231
+			! in_array(
232
+				$redirect_to,
233
+				array(
234
+					SequentialStepForm::REDIRECT_TO_NEXT_STEP,
235
+					SequentialStepForm::REDIRECT_TO_CURRENT_STEP,
236
+					SequentialStepForm::REDIRECT_TO_PREV_STEP,
237
+					SequentialStepForm::REDIRECT_TO_OTHER,
238
+				),
239
+				true
240
+			)
241
+		) {
242
+			throw new InvalidDataTypeException(
243
+				'setRedirectTo()',
244
+				$redirect_to,
245
+				'one of the SequentialStepForm class constants was expected.'
246
+			);
247
+		}
248
+		$this->redirect_to = $redirect_to;
249
+	}
250 250
 
251 251
 
252 252
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
 use EventEspresso\core\exceptions\InvalidDataTypeException;
8 8
 use InvalidArgumentException;
9 9
 
10
-if (! defined('EVENT_ESPRESSO_VERSION')) {
10
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
11 11
     exit('No direct script access allowed');
12 12
 }
13 13
 
@@ -119,7 +119,7 @@  discard block
 block discarded – undo
119 119
     public function setOrder($order)
120 120
     {
121 121
         $order = absint($order);
122
-        if (! $order > 0) {
122
+        if ( ! $order > 0) {
123 123
             throw new InvalidArgumentException(
124 124
                 esc_html__('The form order property must be a positive integer.', 'event_espresso')
125 125
             );
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
      */
149 149
     public function setRedirectUrl($redirect_url)
150 150
     {
151
-        if (! is_string($redirect_url)) {
151
+        if ( ! is_string($redirect_url)) {
152 152
             throw new InvalidDataTypeException('$redirect_url', $redirect_url, 'string');
153 153
         }
154 154
         if (empty($redirect_url)) {
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
                 esc_html__('The redirect argument can not be an empty array.', 'event_espresso')
181 181
             );
182 182
         }
183
-        $this->redirect_args = array_merge($this->redirect_args, (array)$redirect_args);
183
+        $this->redirect_args = array_merge($this->redirect_args, (array) $redirect_args);
184 184
     }
185 185
 
186 186
 
Please login to merge, or discard this patch.
core/libraries/form_sections/form_handlers/SequentialStepFormManager.php 3 patches
Indentation   +614 added lines, -614 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@  discard block
 block discarded – undo
18 18
 use InvalidArgumentException;
19 19
 
20 20
 if (! defined('EVENT_ESPRESSO_VERSION')) {
21
-    exit('No direct script access allowed');
21
+	exit('No direct script access allowed');
22 22
 }
23 23
 
24 24
 
@@ -35,619 +35,619 @@  discard block
 block discarded – undo
35 35
 abstract class SequentialStepFormManager
36 36
 {
37 37
 
38
-    /**
39
-     * a simplified URL with no form related parameters
40
-     * that will be used to build the form's redirect URLs
41
-     *
42
-     * @var string $base_url
43
-     */
44
-    private $base_url = '';
45
-
46
-    /**
47
-     * the key used for the URL param that denotes the current form step
48
-     * defaults to 'ee-form-step'
49
-     *
50
-     * @var string $form_step_url_key
51
-     */
52
-    private $form_step_url_key = '';
53
-
54
-    /**
55
-     * @var string $default_form_step
56
-     */
57
-    private $default_form_step = '';
58
-
59
-    /**
60
-     * @var string $form_action
61
-     */
62
-    private $form_action;
63
-
64
-    /**
65
-     * value of one of the string constant above
66
-     *
67
-     * @var string $form_config
68
-     */
69
-    private $form_config;
70
-
71
-    /**
72
-     * @var string $progress_step_style
73
-     */
74
-    private $progress_step_style = '';
75
-
76
-    /**
77
-     * @var EE_Request $request
78
-     */
79
-    private $request;
80
-
81
-    /**
82
-     * @var Collection $form_steps
83
-     */
84
-    protected $form_steps;
85
-
86
-    /**
87
-     * @var ProgressStepManager $progress_step_manager
88
-     */
89
-    protected $progress_step_manager;
90
-
91
-
92
-
93
-    /**
94
-     * @return Collection|null
95
-     */
96
-    abstract protected function getFormStepsCollection();
97
-
98
-
99
-
100
-    /**
101
-     * StepsManager constructor
102
-     *
103
-     * @param string     $base_url
104
-     * @param string     $default_form_step
105
-     * @param string     $form_action
106
-     * @param string     $form_config
107
-     * @param EE_Request $request
108
-     * @param string     $progress_step_style
109
-     * @throws InvalidDataTypeException
110
-     * @throws InvalidArgumentException
111
-     */
112
-    public function __construct(
113
-        $base_url,
114
-        $default_form_step,
115
-        $form_action = '',
116
-        $form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
117
-        $progress_step_style = 'number_bubbles',
118
-        EE_Request $request
119
-    ) {
120
-        $this->setBaseUrl($base_url);
121
-        $this->setDefaultFormStep($default_form_step);
122
-        $this->setFormAction($form_action);
123
-        $this->setFormConfig($form_config);
124
-        $this->setProgressStepStyle($progress_step_style);
125
-        $this->request = $request;
126
-    }
127
-
128
-
129
-
130
-    /**
131
-     * @return string
132
-     * @throws InvalidFormHandlerException
133
-     */
134
-    public function baseUrl()
135
-    {
136
-        if (strpos($this->base_url, $this->getCurrentStep()->slug()) === false) {
137
-            add_query_arg(
138
-                array($this->form_step_url_key => $this->getCurrentStep()->slug()),
139
-                $this->base_url
140
-            );
141
-        }
142
-        return $this->base_url;
143
-    }
144
-
145
-
146
-
147
-    /**
148
-     * @param string $base_url
149
-     * @throws InvalidDataTypeException
150
-     * @throws InvalidArgumentException
151
-     */
152
-    protected function setBaseUrl($base_url)
153
-    {
154
-        if (! is_string($base_url)) {
155
-            throw new InvalidDataTypeException('$base_url', $base_url, 'string');
156
-        }
157
-        if (empty($base_url)) {
158
-            throw new InvalidArgumentException(
159
-                esc_html__('The base URL can not be an empty string.', 'event_espresso')
160
-            );
161
-        }
162
-        $this->base_url = $base_url;
163
-    }
164
-
165
-
166
-
167
-    /**
168
-     * @return string
169
-     * @throws InvalidDataTypeException
170
-     */
171
-    public function formStepUrlKey()
172
-    {
173
-        if (empty($this->form_step_url_key)) {
174
-            $this->setFormStepUrlKey();
175
-        }
176
-        return $this->form_step_url_key;
177
-    }
178
-
179
-
180
-
181
-    /**
182
-     * @param string $form_step_url_key
183
-     * @throws InvalidDataTypeException
184
-     */
185
-    public function setFormStepUrlKey($form_step_url_key = 'ee-form-step')
186
-    {
187
-        if (! is_string($form_step_url_key)) {
188
-            throw new InvalidDataTypeException('$form_step_key', $form_step_url_key, 'string');
189
-        }
190
-        $this->form_step_url_key = ! empty($form_step_url_key) ? $form_step_url_key : 'ee-form-step';
191
-    }
192
-
193
-
194
-
195
-    /**
196
-     * @return string
197
-     */
198
-    public function defaultFormStep()
199
-    {
200
-        return $this->default_form_step;
201
-    }
202
-
203
-
204
-
205
-    /**
206
-     * @param $default_form_step
207
-     * @throws InvalidDataTypeException
208
-     */
209
-    protected function setDefaultFormStep($default_form_step)
210
-    {
211
-        if (! is_string($default_form_step)) {
212
-            throw new InvalidDataTypeException('$default_form_step', $default_form_step, 'string');
213
-        }
214
-        $this->default_form_step = $default_form_step;
215
-    }
216
-
217
-
218
-
219
-    /**
220
-     * @return void
221
-     * @throws \EventEspresso\core\exceptions\InvalidIdentifierException
222
-     * @throws InvalidDataTypeException
223
-     */
224
-    protected function setCurrentStepFromRequest()
225
-    {
226
-        $current_step_slug = $this->request()->get($this->formStepUrlKey(), $this->defaultFormStep());
227
-        if (! $this->form_steps->setCurrent($current_step_slug)) {
228
-            throw new InvalidIdentifierException(
229
-                $current_step_slug,
230
-                $this->defaultFormStep(),
231
-                $message = sprintf(
232
-                    esc_html__(
233
-                        'The "%1$s" form step could not be set.',
234
-                        'event_espresso'
235
-                    ),
236
-                    $current_step_slug
237
-                )
238
-            );
239
-        }
240
-    }
241
-
242
-
243
-
244
-    /**
245
-     * @return object|SequentialStepFormInterface
246
-     * @throws InvalidFormHandlerException
247
-     */
248
-    public function getCurrentStep()
249
-    {
250
-        if (! $this->form_steps->current() instanceof SequentialStepForm) {
251
-            throw new InvalidFormHandlerException($this->form_steps->current());
252
-        }
253
-        return $this->form_steps->current();
254
-    }
255
-
256
-
257
-
258
-    /**
259
-     * @return string
260
-     * @throws InvalidFormHandlerException
261
-     */
262
-    public function formAction()
263
-    {
264
-        if (! is_string($this->form_action) || empty($this->form_action)) {
265
-            $this->form_action = $this->baseUrl();
266
-        }
267
-        return $this->form_action;
268
-    }
269
-
270
-
271
-
272
-    /**
273
-     * @param string $form_action
274
-     * @throws InvalidDataTypeException
275
-     */
276
-    public function setFormAction($form_action)
277
-    {
278
-        if (! is_string($form_action)) {
279
-            throw new InvalidDataTypeException('$form_action', $form_action, 'string');
280
-        }
281
-        $this->form_action = $form_action;
282
-    }
283
-
284
-
285
-
286
-    /**
287
-     * @param array $form_action_args
288
-     * @throws InvalidDataTypeException
289
-     * @throws InvalidFormHandlerException
290
-     */
291
-    public function addFormActionArgs($form_action_args = array())
292
-    {
293
-        if (! is_array($form_action_args)) {
294
-            throw new InvalidDataTypeException('$form_action_args', $form_action_args, 'array');
295
-        }
296
-        $form_action_args = ! empty($form_action_args)
297
-            ? $form_action_args
298
-            : array($this->formStepUrlKey() => $this->form_steps->current()->slug());
299
-        $this->getCurrentStep()->setFormAction(
300
-            add_query_arg($form_action_args, $this->formAction())
301
-        );
302
-        $this->form_action = $this->getCurrentStep()->formAction();
303
-    }
304
-
305
-
306
-
307
-    /**
308
-     * @return string
309
-     */
310
-    public function formConfig()
311
-    {
312
-        return $this->form_config;
313
-    }
314
-
315
-
316
-
317
-    /**
318
-     * @param string $form_config
319
-     */
320
-    public function setFormConfig($form_config)
321
-    {
322
-        $this->form_config = $form_config;
323
-    }
324
-
325
-
326
-
327
-    /**
328
-     * @return string
329
-     */
330
-    public function progressStepStyle()
331
-    {
332
-        return $this->progress_step_style;
333
-    }
334
-
335
-
336
-
337
-    /**
338
-     * @param string $progress_step_style
339
-     */
340
-    public function setProgressStepStyle($progress_step_style)
341
-    {
342
-        $this->progress_step_style = $progress_step_style;
343
-    }
344
-
345
-
346
-
347
-    /**
348
-     * @return EE_Request
349
-     */
350
-    public function request()
351
-    {
352
-        return $this->request;
353
-    }
354
-
355
-
356
-
357
-    /**
358
-     * @return Collection|null
359
-     * @throws InvalidInterfaceException
360
-     */
361
-    protected function getProgressStepsCollection()
362
-    {
363
-        static $collection = null;
364
-        if (! $collection instanceof ProgressStepCollection) {
365
-            $collection = new ProgressStepCollection();
366
-        }
367
-        return $collection;
368
-    }
369
-
370
-
371
-
372
-    /**
373
-     * @param Collection $progress_steps_collection
374
-     * @return ProgressStepManager
375
-     * @throws InvalidInterfaceException
376
-     * @throws InvalidClassException
377
-     * @throws InvalidDataTypeException
378
-     * @throws InvalidEntityException
379
-     * @throws InvalidFormHandlerException
380
-     */
381
-    protected function generateProgressSteps(Collection $progress_steps_collection)
382
-    {
383
-        $current_step = $this->getCurrentStep();
384
-        /** @var SequentialStepForm $form_step */
385
-        foreach ($this->form_steps as $form_step) {
386
-            // is this step active ?
387
-            if (! $form_step->initialize()) {
388
-                continue;
389
-            }
390
-            $progress_steps_collection->add(
391
-                new ProgressStep(
392
-                    $form_step->order(),
393
-                    $form_step->slug(),
394
-                    $form_step->slug(),
395
-                    $form_step->formName()
396
-                ),
397
-                $form_step->slug()
398
-            );
399
-        }
400
-        // set collection pointer back to current step
401
-        $this->form_steps->setCurrentUsingObject($current_step);
402
-        return new ProgressStepManager(
403
-            $this->progressStepStyle(),
404
-            $this->defaultFormStep(),
405
-            $this->formStepUrlKey(),
406
-            $progress_steps_collection
407
-        );
408
-    }
409
-
410
-
411
-
412
-    /**
413
-     * @throws InvalidClassException
414
-     * @throws InvalidDataTypeException
415
-     * @throws InvalidEntityException
416
-     * @throws InvalidIdentifierException
417
-     * @throws InvalidInterfaceException
418
-     * @throws InvalidArgumentException
419
-     * @throws InvalidFormHandlerException
420
-     */
421
-    public function buildForm()
422
-    {
423
-        $this->buildCurrentStepFormForDisplay();
424
-    }
425
-
426
-
427
-
428
-    /**
429
-     * @param array $form_data
430
-     * @throws InvalidArgumentException
431
-     * @throws InvalidClassException
432
-     * @throws InvalidDataTypeException
433
-     * @throws InvalidEntityException
434
-     * @throws InvalidFormHandlerException
435
-     * @throws InvalidIdentifierException
436
-     * @throws InvalidInterfaceException
437
-     */
438
-    public function processForm($form_data = array())
439
-    {
440
-        $this->buildCurrentStepFormForProcessing();
441
-        $this->processCurrentStepForm($form_data);
442
-    }
443
-
444
-
445
-
446
-    /**
447
-     * @throws InvalidClassException
448
-     * @throws InvalidDataTypeException
449
-     * @throws InvalidEntityException
450
-     * @throws InvalidInterfaceException
451
-     * @throws InvalidIdentifierException
452
-     * @throws InvalidArgumentException
453
-     * @throws InvalidFormHandlerException
454
-     */
455
-    public function buildCurrentStepFormForDisplay()
456
-    {
457
-        $form_step = $this->buildCurrentStepForm();
458
-        // no displayable content ? then skip straight to processing
459
-        if (! $form_step->displayable()) {
460
-            $this->addFormActionArgs();
461
-            $form_step->setFormAction($this->formAction());
462
-            wp_safe_redirect($form_step->formAction());
463
-        }
464
-    }
465
-
466
-
467
-
468
-    /**
469
-     * @throws InvalidClassException
470
-     * @throws InvalidDataTypeException
471
-     * @throws InvalidEntityException
472
-     * @throws InvalidInterfaceException
473
-     * @throws InvalidIdentifierException
474
-     * @throws InvalidArgumentException
475
-     * @throws InvalidFormHandlerException
476
-     */
477
-    public function buildCurrentStepFormForProcessing()
478
-    {
479
-        $this->buildCurrentStepForm(false);
480
-    }
481
-
482
-
483
-
484
-    /**
485
-     * @param bool $for_display
486
-     * @return SequentialStepFormInterface
487
-     * @throws InvalidArgumentException
488
-     * @throws InvalidClassException
489
-     * @throws InvalidDataTypeException
490
-     * @throws InvalidEntityException
491
-     * @throws InvalidFormHandlerException
492
-     * @throws InvalidIdentifierException
493
-     * @throws InvalidInterfaceException
494
-     */
495
-    private function buildCurrentStepForm($for_display = true)
496
-    {
497
-        $this->form_steps = $this->getFormStepsCollection();
498
-        $this->setCurrentStepFromRequest();
499
-        $form_step = $this->getCurrentStep();
500
-        if ($form_step->submitBtnText() === esc_html__('Submit', 'event_espresso')) {
501
-            $form_step->setSubmitBtnText(esc_html__('Next Step', 'event_espresso'));
502
-        }
503
-        if ($for_display && $form_step->displayable()) {
504
-            $this->progress_step_manager = $this->generateProgressSteps(
505
-                $this->getProgressStepsCollection()
506
-            );
507
-            $this->progress_step_manager->setCurrentStep(
508
-                $form_step->slug()
509
-            );
510
-            // mark all previous progress steps as completed
511
-            $this->progress_step_manager->setPreviousStepsCompleted();
512
-            $this->progress_step_manager->enqueueStylesAndScripts();
513
-            $this->addFormActionArgs();
514
-            $form_step->setFormAction($this->formAction());
515
-        } else {
516
-            $form_step->setRedirectUrl($this->baseUrl());
517
-            $form_step->addRedirectArgs(
518
-                array($this->formStepUrlKey() => $this->form_steps->current()->slug())
519
-            );
520
-        }
521
-        $form_step->generate();
522
-        if ($for_display) {
523
-            $form_step->enqueueStylesAndScripts();
524
-        }
525
-        return $form_step;
526
-    }
527
-
528
-
529
-
530
-    /**
531
-     * @param bool $return_as_string
532
-     * @return string
533
-     * @throws InvalidFormHandlerException
534
-     */
535
-    public function displayProgressSteps($return_as_string = true)
536
-    {
537
-        $form_step = $this->getCurrentStep();
538
-        if (! $form_step->displayable()) {
539
-            return '';
540
-        }
541
-        $progress_steps = apply_filters(
542
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_SequentialStepFormManager__displayProgressSteps__before_steps',
543
-            ''
544
-        );
545
-        $progress_steps .= $this->progress_step_manager->displaySteps();
546
-        $progress_steps .= apply_filters(
547
-            'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_SequentialStepFormManager__displayProgressSteps__after_steps',
548
-            ''
549
-        );
550
-        if ($return_as_string) {
551
-            return $progress_steps;
552
-        }
553
-        echo $progress_steps;
554
-        return '';
555
-    }
556
-
557
-
558
-
559
-    /**
560
-     * @param bool $return_as_string
561
-     * @return string
562
-     * @throws InvalidFormHandlerException
563
-     */
564
-    public function displayCurrentStepForm($return_as_string = true)
565
-    {
566
-        if ($return_as_string) {
567
-            return $this->getCurrentStep()->display();
568
-        }
569
-        echo $this->getCurrentStep()->display();
570
-        return '';
571
-    }
572
-
573
-
574
-
575
-    /**
576
-     * @param array $form_data
577
-     * @return void
578
-     * @throws InvalidArgumentException
579
-     * @throws InvalidDataTypeException
580
-     * @throws InvalidFormHandlerException
581
-     */
582
-    public function processCurrentStepForm($form_data = array())
583
-    {
584
-        // grab instance of current step because after calling next() below,
585
-        // any calls to getCurrentStep() will return the "next" step because we advanced
586
-        $current_step = $this->getCurrentStep();
587
-        try {
588
-            // form processing should either throw exceptions or return true
589
-            $current_step->process($form_data);
590
-        } catch (Exception $e) {
591
-            // something went wrong, so...
592
-            // if WP_DEBUG === true, display the Exception and stack trace right now
593
-            new ExceptionStackTraceDisplay($e);
594
-            // else convert the Exception to an EE_Error
595
-            EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
596
-            // prevent redirect to next step or other if exception was thrown
597
-            if (
598
-                $current_step->redirectTo() === SequentialStepForm::REDIRECT_TO_NEXT_STEP
599
-                || $current_step->redirectTo() === SequentialStepForm::REDIRECT_TO_OTHER
600
-            ) {
601
-                $current_step->setRedirectTo(SequentialStepForm::REDIRECT_TO_CURRENT_STEP);
602
-            }
603
-        }
604
-        // save notices to a transient so that when we redirect back
605
-        // to the display portion for this step
606
-        // those notices can be displayed
607
-        EE_Error::get_notices(false, true);
608
-        $this->redirectForm($current_step);
609
-    }
610
-
611
-
612
-
613
-    /**
614
-     * handles where to go to next
615
-     *
616
-     * @param SequentialStepFormInterface $current_step
617
-     * @throws InvalidArgumentException
618
-     * @throws InvalidDataTypeException
619
-     * @throws InvalidFormHandlerException
620
-     */
621
-    public function redirectForm(SequentialStepFormInterface $current_step)
622
-    {
623
-        $redirect_step = $current_step;
624
-        switch ($current_step->redirectTo()) {
625
-            case SequentialStepForm::REDIRECT_TO_OTHER:
626
-                // going somewhere else, so just check out now
627
-                wp_safe_redirect($redirect_step->redirectUrl());
628
-                exit();
629
-                break;
630
-            case SequentialStepForm::REDIRECT_TO_PREV_STEP:
631
-                $redirect_step = $this->form_steps->previous();
632
-                break;
633
-            case SequentialStepForm::REDIRECT_TO_NEXT_STEP:
634
-                $this->form_steps->next();
635
-                if ($this->form_steps->valid()) {
636
-                    $redirect_step = $this->form_steps->current();
637
-                }
638
-                break;
639
-            case SequentialStepForm::REDIRECT_TO_CURRENT_STEP:
640
-            default :
641
-                // $redirect_step is already set
642
-        }
643
-        $current_step->setRedirectUrl($this->baseUrl());
644
-        $current_step->addRedirectArgs(
645
-        // use the slug for whatever step we are redirecting too
646
-            array($this->formStepUrlKey() => $redirect_step->slug())
647
-        );
648
-        wp_safe_redirect($current_step->redirectUrl());
649
-        exit();
650
-    }
38
+	/**
39
+	 * a simplified URL with no form related parameters
40
+	 * that will be used to build the form's redirect URLs
41
+	 *
42
+	 * @var string $base_url
43
+	 */
44
+	private $base_url = '';
45
+
46
+	/**
47
+	 * the key used for the URL param that denotes the current form step
48
+	 * defaults to 'ee-form-step'
49
+	 *
50
+	 * @var string $form_step_url_key
51
+	 */
52
+	private $form_step_url_key = '';
53
+
54
+	/**
55
+	 * @var string $default_form_step
56
+	 */
57
+	private $default_form_step = '';
58
+
59
+	/**
60
+	 * @var string $form_action
61
+	 */
62
+	private $form_action;
63
+
64
+	/**
65
+	 * value of one of the string constant above
66
+	 *
67
+	 * @var string $form_config
68
+	 */
69
+	private $form_config;
70
+
71
+	/**
72
+	 * @var string $progress_step_style
73
+	 */
74
+	private $progress_step_style = '';
75
+
76
+	/**
77
+	 * @var EE_Request $request
78
+	 */
79
+	private $request;
80
+
81
+	/**
82
+	 * @var Collection $form_steps
83
+	 */
84
+	protected $form_steps;
85
+
86
+	/**
87
+	 * @var ProgressStepManager $progress_step_manager
88
+	 */
89
+	protected $progress_step_manager;
90
+
91
+
92
+
93
+	/**
94
+	 * @return Collection|null
95
+	 */
96
+	abstract protected function getFormStepsCollection();
97
+
98
+
99
+
100
+	/**
101
+	 * StepsManager constructor
102
+	 *
103
+	 * @param string     $base_url
104
+	 * @param string     $default_form_step
105
+	 * @param string     $form_action
106
+	 * @param string     $form_config
107
+	 * @param EE_Request $request
108
+	 * @param string     $progress_step_style
109
+	 * @throws InvalidDataTypeException
110
+	 * @throws InvalidArgumentException
111
+	 */
112
+	public function __construct(
113
+		$base_url,
114
+		$default_form_step,
115
+		$form_action = '',
116
+		$form_config = FormHandler::ADD_FORM_TAGS_AND_SUBMIT,
117
+		$progress_step_style = 'number_bubbles',
118
+		EE_Request $request
119
+	) {
120
+		$this->setBaseUrl($base_url);
121
+		$this->setDefaultFormStep($default_form_step);
122
+		$this->setFormAction($form_action);
123
+		$this->setFormConfig($form_config);
124
+		$this->setProgressStepStyle($progress_step_style);
125
+		$this->request = $request;
126
+	}
127
+
128
+
129
+
130
+	/**
131
+	 * @return string
132
+	 * @throws InvalidFormHandlerException
133
+	 */
134
+	public function baseUrl()
135
+	{
136
+		if (strpos($this->base_url, $this->getCurrentStep()->slug()) === false) {
137
+			add_query_arg(
138
+				array($this->form_step_url_key => $this->getCurrentStep()->slug()),
139
+				$this->base_url
140
+			);
141
+		}
142
+		return $this->base_url;
143
+	}
144
+
145
+
146
+
147
+	/**
148
+	 * @param string $base_url
149
+	 * @throws InvalidDataTypeException
150
+	 * @throws InvalidArgumentException
151
+	 */
152
+	protected function setBaseUrl($base_url)
153
+	{
154
+		if (! is_string($base_url)) {
155
+			throw new InvalidDataTypeException('$base_url', $base_url, 'string');
156
+		}
157
+		if (empty($base_url)) {
158
+			throw new InvalidArgumentException(
159
+				esc_html__('The base URL can not be an empty string.', 'event_espresso')
160
+			);
161
+		}
162
+		$this->base_url = $base_url;
163
+	}
164
+
165
+
166
+
167
+	/**
168
+	 * @return string
169
+	 * @throws InvalidDataTypeException
170
+	 */
171
+	public function formStepUrlKey()
172
+	{
173
+		if (empty($this->form_step_url_key)) {
174
+			$this->setFormStepUrlKey();
175
+		}
176
+		return $this->form_step_url_key;
177
+	}
178
+
179
+
180
+
181
+	/**
182
+	 * @param string $form_step_url_key
183
+	 * @throws InvalidDataTypeException
184
+	 */
185
+	public function setFormStepUrlKey($form_step_url_key = 'ee-form-step')
186
+	{
187
+		if (! is_string($form_step_url_key)) {
188
+			throw new InvalidDataTypeException('$form_step_key', $form_step_url_key, 'string');
189
+		}
190
+		$this->form_step_url_key = ! empty($form_step_url_key) ? $form_step_url_key : 'ee-form-step';
191
+	}
192
+
193
+
194
+
195
+	/**
196
+	 * @return string
197
+	 */
198
+	public function defaultFormStep()
199
+	{
200
+		return $this->default_form_step;
201
+	}
202
+
203
+
204
+
205
+	/**
206
+	 * @param $default_form_step
207
+	 * @throws InvalidDataTypeException
208
+	 */
209
+	protected function setDefaultFormStep($default_form_step)
210
+	{
211
+		if (! is_string($default_form_step)) {
212
+			throw new InvalidDataTypeException('$default_form_step', $default_form_step, 'string');
213
+		}
214
+		$this->default_form_step = $default_form_step;
215
+	}
216
+
217
+
218
+
219
+	/**
220
+	 * @return void
221
+	 * @throws \EventEspresso\core\exceptions\InvalidIdentifierException
222
+	 * @throws InvalidDataTypeException
223
+	 */
224
+	protected function setCurrentStepFromRequest()
225
+	{
226
+		$current_step_slug = $this->request()->get($this->formStepUrlKey(), $this->defaultFormStep());
227
+		if (! $this->form_steps->setCurrent($current_step_slug)) {
228
+			throw new InvalidIdentifierException(
229
+				$current_step_slug,
230
+				$this->defaultFormStep(),
231
+				$message = sprintf(
232
+					esc_html__(
233
+						'The "%1$s" form step could not be set.',
234
+						'event_espresso'
235
+					),
236
+					$current_step_slug
237
+				)
238
+			);
239
+		}
240
+	}
241
+
242
+
243
+
244
+	/**
245
+	 * @return object|SequentialStepFormInterface
246
+	 * @throws InvalidFormHandlerException
247
+	 */
248
+	public function getCurrentStep()
249
+	{
250
+		if (! $this->form_steps->current() instanceof SequentialStepForm) {
251
+			throw new InvalidFormHandlerException($this->form_steps->current());
252
+		}
253
+		return $this->form_steps->current();
254
+	}
255
+
256
+
257
+
258
+	/**
259
+	 * @return string
260
+	 * @throws InvalidFormHandlerException
261
+	 */
262
+	public function formAction()
263
+	{
264
+		if (! is_string($this->form_action) || empty($this->form_action)) {
265
+			$this->form_action = $this->baseUrl();
266
+		}
267
+		return $this->form_action;
268
+	}
269
+
270
+
271
+
272
+	/**
273
+	 * @param string $form_action
274
+	 * @throws InvalidDataTypeException
275
+	 */
276
+	public function setFormAction($form_action)
277
+	{
278
+		if (! is_string($form_action)) {
279
+			throw new InvalidDataTypeException('$form_action', $form_action, 'string');
280
+		}
281
+		$this->form_action = $form_action;
282
+	}
283
+
284
+
285
+
286
+	/**
287
+	 * @param array $form_action_args
288
+	 * @throws InvalidDataTypeException
289
+	 * @throws InvalidFormHandlerException
290
+	 */
291
+	public function addFormActionArgs($form_action_args = array())
292
+	{
293
+		if (! is_array($form_action_args)) {
294
+			throw new InvalidDataTypeException('$form_action_args', $form_action_args, 'array');
295
+		}
296
+		$form_action_args = ! empty($form_action_args)
297
+			? $form_action_args
298
+			: array($this->formStepUrlKey() => $this->form_steps->current()->slug());
299
+		$this->getCurrentStep()->setFormAction(
300
+			add_query_arg($form_action_args, $this->formAction())
301
+		);
302
+		$this->form_action = $this->getCurrentStep()->formAction();
303
+	}
304
+
305
+
306
+
307
+	/**
308
+	 * @return string
309
+	 */
310
+	public function formConfig()
311
+	{
312
+		return $this->form_config;
313
+	}
314
+
315
+
316
+
317
+	/**
318
+	 * @param string $form_config
319
+	 */
320
+	public function setFormConfig($form_config)
321
+	{
322
+		$this->form_config = $form_config;
323
+	}
324
+
325
+
326
+
327
+	/**
328
+	 * @return string
329
+	 */
330
+	public function progressStepStyle()
331
+	{
332
+		return $this->progress_step_style;
333
+	}
334
+
335
+
336
+
337
+	/**
338
+	 * @param string $progress_step_style
339
+	 */
340
+	public function setProgressStepStyle($progress_step_style)
341
+	{
342
+		$this->progress_step_style = $progress_step_style;
343
+	}
344
+
345
+
346
+
347
+	/**
348
+	 * @return EE_Request
349
+	 */
350
+	public function request()
351
+	{
352
+		return $this->request;
353
+	}
354
+
355
+
356
+
357
+	/**
358
+	 * @return Collection|null
359
+	 * @throws InvalidInterfaceException
360
+	 */
361
+	protected function getProgressStepsCollection()
362
+	{
363
+		static $collection = null;
364
+		if (! $collection instanceof ProgressStepCollection) {
365
+			$collection = new ProgressStepCollection();
366
+		}
367
+		return $collection;
368
+	}
369
+
370
+
371
+
372
+	/**
373
+	 * @param Collection $progress_steps_collection
374
+	 * @return ProgressStepManager
375
+	 * @throws InvalidInterfaceException
376
+	 * @throws InvalidClassException
377
+	 * @throws InvalidDataTypeException
378
+	 * @throws InvalidEntityException
379
+	 * @throws InvalidFormHandlerException
380
+	 */
381
+	protected function generateProgressSteps(Collection $progress_steps_collection)
382
+	{
383
+		$current_step = $this->getCurrentStep();
384
+		/** @var SequentialStepForm $form_step */
385
+		foreach ($this->form_steps as $form_step) {
386
+			// is this step active ?
387
+			if (! $form_step->initialize()) {
388
+				continue;
389
+			}
390
+			$progress_steps_collection->add(
391
+				new ProgressStep(
392
+					$form_step->order(),
393
+					$form_step->slug(),
394
+					$form_step->slug(),
395
+					$form_step->formName()
396
+				),
397
+				$form_step->slug()
398
+			);
399
+		}
400
+		// set collection pointer back to current step
401
+		$this->form_steps->setCurrentUsingObject($current_step);
402
+		return new ProgressStepManager(
403
+			$this->progressStepStyle(),
404
+			$this->defaultFormStep(),
405
+			$this->formStepUrlKey(),
406
+			$progress_steps_collection
407
+		);
408
+	}
409
+
410
+
411
+
412
+	/**
413
+	 * @throws InvalidClassException
414
+	 * @throws InvalidDataTypeException
415
+	 * @throws InvalidEntityException
416
+	 * @throws InvalidIdentifierException
417
+	 * @throws InvalidInterfaceException
418
+	 * @throws InvalidArgumentException
419
+	 * @throws InvalidFormHandlerException
420
+	 */
421
+	public function buildForm()
422
+	{
423
+		$this->buildCurrentStepFormForDisplay();
424
+	}
425
+
426
+
427
+
428
+	/**
429
+	 * @param array $form_data
430
+	 * @throws InvalidArgumentException
431
+	 * @throws InvalidClassException
432
+	 * @throws InvalidDataTypeException
433
+	 * @throws InvalidEntityException
434
+	 * @throws InvalidFormHandlerException
435
+	 * @throws InvalidIdentifierException
436
+	 * @throws InvalidInterfaceException
437
+	 */
438
+	public function processForm($form_data = array())
439
+	{
440
+		$this->buildCurrentStepFormForProcessing();
441
+		$this->processCurrentStepForm($form_data);
442
+	}
443
+
444
+
445
+
446
+	/**
447
+	 * @throws InvalidClassException
448
+	 * @throws InvalidDataTypeException
449
+	 * @throws InvalidEntityException
450
+	 * @throws InvalidInterfaceException
451
+	 * @throws InvalidIdentifierException
452
+	 * @throws InvalidArgumentException
453
+	 * @throws InvalidFormHandlerException
454
+	 */
455
+	public function buildCurrentStepFormForDisplay()
456
+	{
457
+		$form_step = $this->buildCurrentStepForm();
458
+		// no displayable content ? then skip straight to processing
459
+		if (! $form_step->displayable()) {
460
+			$this->addFormActionArgs();
461
+			$form_step->setFormAction($this->formAction());
462
+			wp_safe_redirect($form_step->formAction());
463
+		}
464
+	}
465
+
466
+
467
+
468
+	/**
469
+	 * @throws InvalidClassException
470
+	 * @throws InvalidDataTypeException
471
+	 * @throws InvalidEntityException
472
+	 * @throws InvalidInterfaceException
473
+	 * @throws InvalidIdentifierException
474
+	 * @throws InvalidArgumentException
475
+	 * @throws InvalidFormHandlerException
476
+	 */
477
+	public function buildCurrentStepFormForProcessing()
478
+	{
479
+		$this->buildCurrentStepForm(false);
480
+	}
481
+
482
+
483
+
484
+	/**
485
+	 * @param bool $for_display
486
+	 * @return SequentialStepFormInterface
487
+	 * @throws InvalidArgumentException
488
+	 * @throws InvalidClassException
489
+	 * @throws InvalidDataTypeException
490
+	 * @throws InvalidEntityException
491
+	 * @throws InvalidFormHandlerException
492
+	 * @throws InvalidIdentifierException
493
+	 * @throws InvalidInterfaceException
494
+	 */
495
+	private function buildCurrentStepForm($for_display = true)
496
+	{
497
+		$this->form_steps = $this->getFormStepsCollection();
498
+		$this->setCurrentStepFromRequest();
499
+		$form_step = $this->getCurrentStep();
500
+		if ($form_step->submitBtnText() === esc_html__('Submit', 'event_espresso')) {
501
+			$form_step->setSubmitBtnText(esc_html__('Next Step', 'event_espresso'));
502
+		}
503
+		if ($for_display && $form_step->displayable()) {
504
+			$this->progress_step_manager = $this->generateProgressSteps(
505
+				$this->getProgressStepsCollection()
506
+			);
507
+			$this->progress_step_manager->setCurrentStep(
508
+				$form_step->slug()
509
+			);
510
+			// mark all previous progress steps as completed
511
+			$this->progress_step_manager->setPreviousStepsCompleted();
512
+			$this->progress_step_manager->enqueueStylesAndScripts();
513
+			$this->addFormActionArgs();
514
+			$form_step->setFormAction($this->formAction());
515
+		} else {
516
+			$form_step->setRedirectUrl($this->baseUrl());
517
+			$form_step->addRedirectArgs(
518
+				array($this->formStepUrlKey() => $this->form_steps->current()->slug())
519
+			);
520
+		}
521
+		$form_step->generate();
522
+		if ($for_display) {
523
+			$form_step->enqueueStylesAndScripts();
524
+		}
525
+		return $form_step;
526
+	}
527
+
528
+
529
+
530
+	/**
531
+	 * @param bool $return_as_string
532
+	 * @return string
533
+	 * @throws InvalidFormHandlerException
534
+	 */
535
+	public function displayProgressSteps($return_as_string = true)
536
+	{
537
+		$form_step = $this->getCurrentStep();
538
+		if (! $form_step->displayable()) {
539
+			return '';
540
+		}
541
+		$progress_steps = apply_filters(
542
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_SequentialStepFormManager__displayProgressSteps__before_steps',
543
+			''
544
+		);
545
+		$progress_steps .= $this->progress_step_manager->displaySteps();
546
+		$progress_steps .= apply_filters(
547
+			'FHEE__EventEspresso_core_libraries_form_sections_form_handlers_SequentialStepFormManager__displayProgressSteps__after_steps',
548
+			''
549
+		);
550
+		if ($return_as_string) {
551
+			return $progress_steps;
552
+		}
553
+		echo $progress_steps;
554
+		return '';
555
+	}
556
+
557
+
558
+
559
+	/**
560
+	 * @param bool $return_as_string
561
+	 * @return string
562
+	 * @throws InvalidFormHandlerException
563
+	 */
564
+	public function displayCurrentStepForm($return_as_string = true)
565
+	{
566
+		if ($return_as_string) {
567
+			return $this->getCurrentStep()->display();
568
+		}
569
+		echo $this->getCurrentStep()->display();
570
+		return '';
571
+	}
572
+
573
+
574
+
575
+	/**
576
+	 * @param array $form_data
577
+	 * @return void
578
+	 * @throws InvalidArgumentException
579
+	 * @throws InvalidDataTypeException
580
+	 * @throws InvalidFormHandlerException
581
+	 */
582
+	public function processCurrentStepForm($form_data = array())
583
+	{
584
+		// grab instance of current step because after calling next() below,
585
+		// any calls to getCurrentStep() will return the "next" step because we advanced
586
+		$current_step = $this->getCurrentStep();
587
+		try {
588
+			// form processing should either throw exceptions or return true
589
+			$current_step->process($form_data);
590
+		} catch (Exception $e) {
591
+			// something went wrong, so...
592
+			// if WP_DEBUG === true, display the Exception and stack trace right now
593
+			new ExceptionStackTraceDisplay($e);
594
+			// else convert the Exception to an EE_Error
595
+			EE_Error::add_error($e->getMessage(), __FILE__, __FUNCTION__, __LINE__);
596
+			// prevent redirect to next step or other if exception was thrown
597
+			if (
598
+				$current_step->redirectTo() === SequentialStepForm::REDIRECT_TO_NEXT_STEP
599
+				|| $current_step->redirectTo() === SequentialStepForm::REDIRECT_TO_OTHER
600
+			) {
601
+				$current_step->setRedirectTo(SequentialStepForm::REDIRECT_TO_CURRENT_STEP);
602
+			}
603
+		}
604
+		// save notices to a transient so that when we redirect back
605
+		// to the display portion for this step
606
+		// those notices can be displayed
607
+		EE_Error::get_notices(false, true);
608
+		$this->redirectForm($current_step);
609
+	}
610
+
611
+
612
+
613
+	/**
614
+	 * handles where to go to next
615
+	 *
616
+	 * @param SequentialStepFormInterface $current_step
617
+	 * @throws InvalidArgumentException
618
+	 * @throws InvalidDataTypeException
619
+	 * @throws InvalidFormHandlerException
620
+	 */
621
+	public function redirectForm(SequentialStepFormInterface $current_step)
622
+	{
623
+		$redirect_step = $current_step;
624
+		switch ($current_step->redirectTo()) {
625
+			case SequentialStepForm::REDIRECT_TO_OTHER:
626
+				// going somewhere else, so just check out now
627
+				wp_safe_redirect($redirect_step->redirectUrl());
628
+				exit();
629
+				break;
630
+			case SequentialStepForm::REDIRECT_TO_PREV_STEP:
631
+				$redirect_step = $this->form_steps->previous();
632
+				break;
633
+			case SequentialStepForm::REDIRECT_TO_NEXT_STEP:
634
+				$this->form_steps->next();
635
+				if ($this->form_steps->valid()) {
636
+					$redirect_step = $this->form_steps->current();
637
+				}
638
+				break;
639
+			case SequentialStepForm::REDIRECT_TO_CURRENT_STEP:
640
+			default :
641
+				// $redirect_step is already set
642
+		}
643
+		$current_step->setRedirectUrl($this->baseUrl());
644
+		$current_step->addRedirectArgs(
645
+		// use the slug for whatever step we are redirecting too
646
+			array($this->formStepUrlKey() => $redirect_step->slug())
647
+		);
648
+		wp_safe_redirect($current_step->redirectUrl());
649
+		exit();
650
+	}
651 651
 
652 652
 
653 653
 }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
 use Exception;
18 18
 use InvalidArgumentException;
19 19
 
20
-if (! defined('EVENT_ESPRESSO_VERSION')) {
20
+if ( ! defined('EVENT_ESPRESSO_VERSION')) {
21 21
     exit('No direct script access allowed');
22 22
 }
23 23
 
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
      */
152 152
     protected function setBaseUrl($base_url)
153 153
     {
154
-        if (! is_string($base_url)) {
154
+        if ( ! is_string($base_url)) {
155 155
             throw new InvalidDataTypeException('$base_url', $base_url, 'string');
156 156
         }
157 157
         if (empty($base_url)) {
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
      */
185 185
     public function setFormStepUrlKey($form_step_url_key = 'ee-form-step')
186 186
     {
187
-        if (! is_string($form_step_url_key)) {
187
+        if ( ! is_string($form_step_url_key)) {
188 188
             throw new InvalidDataTypeException('$form_step_key', $form_step_url_key, 'string');
189 189
         }
190 190
         $this->form_step_url_key = ! empty($form_step_url_key) ? $form_step_url_key : 'ee-form-step';
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
      */
209 209
     protected function setDefaultFormStep($default_form_step)
210 210
     {
211
-        if (! is_string($default_form_step)) {
211
+        if ( ! is_string($default_form_step)) {
212 212
             throw new InvalidDataTypeException('$default_form_step', $default_form_step, 'string');
213 213
         }
214 214
         $this->default_form_step = $default_form_step;
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
     protected function setCurrentStepFromRequest()
225 225
     {
226 226
         $current_step_slug = $this->request()->get($this->formStepUrlKey(), $this->defaultFormStep());
227
-        if (! $this->form_steps->setCurrent($current_step_slug)) {
227
+        if ( ! $this->form_steps->setCurrent($current_step_slug)) {
228 228
             throw new InvalidIdentifierException(
229 229
                 $current_step_slug,
230 230
                 $this->defaultFormStep(),
@@ -247,7 +247,7 @@  discard block
 block discarded – undo
247 247
      */
248 248
     public function getCurrentStep()
249 249
     {
250
-        if (! $this->form_steps->current() instanceof SequentialStepForm) {
250
+        if ( ! $this->form_steps->current() instanceof SequentialStepForm) {
251 251
             throw new InvalidFormHandlerException($this->form_steps->current());
252 252
         }
253 253
         return $this->form_steps->current();
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
      */
262 262
     public function formAction()
263 263
     {
264
-        if (! is_string($this->form_action) || empty($this->form_action)) {
264
+        if ( ! is_string($this->form_action) || empty($this->form_action)) {
265 265
             $this->form_action = $this->baseUrl();
266 266
         }
267 267
         return $this->form_action;
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
      */
276 276
     public function setFormAction($form_action)
277 277
     {
278
-        if (! is_string($form_action)) {
278
+        if ( ! is_string($form_action)) {
279 279
             throw new InvalidDataTypeException('$form_action', $form_action, 'string');
280 280
         }
281 281
         $this->form_action = $form_action;
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
      */
291 291
     public function addFormActionArgs($form_action_args = array())
292 292
     {
293
-        if (! is_array($form_action_args)) {
293
+        if ( ! is_array($form_action_args)) {
294 294
             throw new InvalidDataTypeException('$form_action_args', $form_action_args, 'array');
295 295
         }
296 296
         $form_action_args = ! empty($form_action_args)
@@ -361,7 +361,7 @@  discard block
 block discarded – undo
361 361
     protected function getProgressStepsCollection()
362 362
     {
363 363
         static $collection = null;
364
-        if (! $collection instanceof ProgressStepCollection) {
364
+        if ( ! $collection instanceof ProgressStepCollection) {
365 365
             $collection = new ProgressStepCollection();
366 366
         }
367 367
         return $collection;
@@ -384,7 +384,7 @@  discard block
 block discarded – undo
384 384
         /** @var SequentialStepForm $form_step */
385 385
         foreach ($this->form_steps as $form_step) {
386 386
             // is this step active ?
387
-            if (! $form_step->initialize()) {
387
+            if ( ! $form_step->initialize()) {
388 388
                 continue;
389 389
             }
390 390
             $progress_steps_collection->add(
@@ -456,7 +456,7 @@  discard block
 block discarded – undo
456 456
     {
457 457
         $form_step = $this->buildCurrentStepForm();
458 458
         // no displayable content ? then skip straight to processing
459
-        if (! $form_step->displayable()) {
459
+        if ( ! $form_step->displayable()) {
460 460
             $this->addFormActionArgs();
461 461
             $form_step->setFormAction($this->formAction());
462 462
             wp_safe_redirect($form_step->formAction());
@@ -535,7 +535,7 @@  discard block
 block discarded – undo
535 535
     public function displayProgressSteps($return_as_string = true)
536 536
     {
537 537
         $form_step = $this->getCurrentStep();
538
-        if (! $form_step->displayable()) {
538
+        if ( ! $form_step->displayable()) {
539 539
             return '';
540 540
         }
541 541
         $progress_steps = apply_filters(
Please login to merge, or discard this patch.
Doc Comments   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 
204 204
 
205 205
     /**
206
-     * @param $default_form_step
206
+     * @param string $default_form_step
207 207
      * @throws InvalidDataTypeException
208 208
      */
209 209
     protected function setDefaultFormStep($default_form_step)
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
 
243 243
 
244 244
     /**
245
-     * @return object|SequentialStepFormInterface
245
+     * @return SequentialStepForm
246 246
      * @throws InvalidFormHandlerException
247 247
      */
248 248
     public function getCurrentStep()
Please login to merge, or discard this patch.