Passed
Push — master ( 81fed3...23c074 )
by Brian
04:25
created
includes/payments/class-getpaid-form-item.php 1 patch
Indentation   +348 added lines, -348 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined( 'ABSPATH' ) ) {
3
-	exit;
3
+    exit;
4 4
 }
5 5
 
6 6
 /**
@@ -10,60 +10,60 @@  discard block
 block discarded – undo
10 10
 class GetPaid_Form_Item  extends WPInv_Item {
11 11
 
12 12
     /**
13
-	 * Stores a custom description for the item.
14
-	 *
15
-	 * @var string
16
-	 */
17
-	protected $custom_description = null;
18
-
19
-	/**
20
-	 * Stores the item quantity.
21
-	 *
22
-	 * @var int
23
-	 */
24
-	protected $quantity = 1;
25
-
26
-	/**
27
-	 * Stores the item meta.
28
-	 *
29
-	 * @var array
30
-	 */
31
-	protected $meta = array();
32
-
33
-	/**
34
-	 * Is this item required?
35
-	 *
36
-	 * @var int
37
-	 */
38
-	protected $is_required = true;
39
-
40
-	/**
41
-	 * Are quantities allowed?
42
-	 *
43
-	 * @var int
44
-	 */
45
-	protected $allow_quantities = false;
46
-
47
-	/**
48
-	 * Associated invoice.
49
-	 *
50
-	 * @var int
51
-	 */
52
-	public $invoice_id = 0;
53
-
54
-	/**
55
-	 * Item discount.
56
-	 *
57
-	 * @var float
58
-	 */
59
-	public $item_discount = 0;
60
-
61
-	/**
62
-	 * Item tax.
63
-	 *
64
-	 * @var float
65
-	 */
66
-	public $item_tax = 0;
13
+     * Stores a custom description for the item.
14
+     *
15
+     * @var string
16
+     */
17
+    protected $custom_description = null;
18
+
19
+    /**
20
+     * Stores the item quantity.
21
+     *
22
+     * @var int
23
+     */
24
+    protected $quantity = 1;
25
+
26
+    /**
27
+     * Stores the item meta.
28
+     *
29
+     * @var array
30
+     */
31
+    protected $meta = array();
32
+
33
+    /**
34
+     * Is this item required?
35
+     *
36
+     * @var int
37
+     */
38
+    protected $is_required = true;
39
+
40
+    /**
41
+     * Are quantities allowed?
42
+     *
43
+     * @var int
44
+     */
45
+    protected $allow_quantities = false;
46
+
47
+    /**
48
+     * Associated invoice.
49
+     *
50
+     * @var int
51
+     */
52
+    public $invoice_id = 0;
53
+
54
+    /**
55
+     * Item discount.
56
+     *
57
+     * @var float
58
+     */
59
+    public $item_discount = 0;
60
+
61
+    /**
62
+     * Item tax.
63
+     *
64
+     * @var float
65
+     */
66
+    public $item_tax = 0;
67 67
 
68 68
     /*
69 69
 	|--------------------------------------------------------------------------
@@ -81,226 +81,226 @@  discard block
 block discarded – undo
81 81
     */
82 82
 
83 83
     /**
84
-	 * Get the item name.
85
-	 *
86
-	 * @since 1.0.19
87
-	 * @param  string $context View or edit context.
88
-	 * @return string
89
-	 */
90
-	public function get_name( $context = 'view' ) {
91
-		$name = parent::get_name( $context );
92
-		return $name . wpinv_get_item_suffix( $this );
93
-	}
94
-
95
-	/**
96
-	 * Get the item name without a suffix.
97
-	 *
98
-	 * @since 1.0.19
99
-	 * @param  string $context View or edit context.
100
-	 * @return string
101
-	 */
102
-	public function get_raw_name( $context = 'view' ) {
103
-		return parent::get_name( $context );
104
-	}
105
-
106
-	/**
107
-	 * Get the item description.
108
-	 *
109
-	 * @since 1.0.19
110
-	 * @param  string $context View or edit context.
111
-	 * @return string
112
-	 */
113
-	public function get_description( $context = 'view' ) {
114
-
115
-		if ( isset( $this->custom_description ) ) {
116
-			return $this->custom_description;
117
-		}
118
-
119
-		return parent::get_description( $context );
120
-	}
121
-
122
-	/**
123
-	 * Returns the sub total.
124
-	 *
125
-	 * @since 1.0.19
126
-	 * @param  string $context View or edit context.
127
-	 * @return int
128
-	 */
129
-	public function get_sub_total( $context = 'view' ) {
130
-		return $this->get_quantity( $context ) * $this->get_initial_price( $context );
131
-	}
132
-
133
-	/**
134
-	 * Returns the recurring sub total.
135
-	 *
136
-	 * @since 1.0.19
137
-	 * @param  string $context View or edit context.
138
-	 * @return int
139
-	 */
140
-	public function get_recurring_sub_total( $context = 'view' ) {
141
-		return $this->get_quantity( $context ) * $this->get_price( $context );
142
-	}
143
-
144
-	/**
145
-	 * @deprecated
146
-	 */
147
-	public function get_qantity( $context = 'view' ) {
148
-		return $this->get_quantity( $context );
149
-	}
150
-
151
-	/**
152
-	 * Get the item quantity.
153
-	 *
154
-	 * @since 1.0.19
155
-	 * @param  string $context View or edit context.
156
-	 * @return int
157
-	 */
158
-	public function get_quantity( $context = 'view' ) {
159
-		$quantity = (int) $this->quantity;
160
-
161
-		if ( empty( $quantity ) || 1 > $quantity ) {
162
-			$quantity = 1;
163
-		}
164
-
165
-		if ( 'view' == $context ) {
166
-			return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this );
167
-		}
168
-
169
-		return $quantity;
170
-
171
-	}
172
-
173
-	/**
174
-	 * Get the item meta data.
175
-	 *
176
-	 * @since 1.0.19
177
-	 * @param  string $context View or edit context.
178
-	 * @return meta
179
-	 */
180
-	public function get_item_meta( $context = 'view' ) {
181
-		$meta = $this->meta;
182
-
183
-		if ( 'view' == $context ) {
184
-			return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this );
185
-		}
186
-
187
-		return $meta;
188
-
189
-	}
190
-
191
-	/**
192
-	 * Returns whether or not customers can update the item quantity.
193
-	 *
194
-	 * @since 1.0.19
195
-	 * @param  string $context View or edit context.
196
-	 * @return bool
197
-	 */
198
-	public function get_allow_quantities( $context = 'view' ) {
199
-		$allow_quantities = (bool) $this->allow_quantities;
200
-
201
-		if ( 'view' == $context ) {
202
-			return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this );
203
-		}
204
-
205
-		return $allow_quantities;
206
-
207
-	}
208
-
209
-	/**
210
-	 * Returns whether or not the item is required.
211
-	 *
212
-	 * @since 1.0.19
213
-	 * @param  string $context View or edit context.
214
-	 * @return bool
215
-	 */
216
-	public function get_is_required( $context = 'view' ) {
217
-		$is_required = (bool) $this->is_required;
218
-
219
-		if ( 'view' == $context ) {
220
-			return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this );
221
-		}
222
-
223
-		return $is_required;
224
-
225
-	}
226
-
227
-	/**
228
-	 * Prepares form data for use.
229
-	 *
230
-	 * @since 1.0.19
231
-	 * @return array
232
-	 */
233
-	public function prepare_data_for_use() {
234
-
235
-		return array(
236
-			'title'            => strip_tags( $this->get_name() ),
237
-			'id'               => $this->get_id(),
238
-			'price'            => $this->get_price(),
239
-			'recurring'        => $this->is_recurring(),
240
-			'description'      => $this->get_description(),
241
-			'allow_quantities' => $this->allows_quantities(),
242
-			'required'         => $this->is_required(),
243
-		);
244
-
245
-	}
246
-
247
-	/**
248
-	 * Prepares form data for ajax use.
249
-	 *
250
-	 * @since 1.0.19
251
-	 * @return array
252
-	 */
253
-	public function prepare_data_for_invoice_edit_ajax( $currency = '' ) {
254
-
255
-		$description = getpaid_item_recurring_price_help_text( $this, $currency );
256
-
257
-		if ( $description ) {
258
-			$description = "<div class='getpaid-subscription-help-text'>$description</div>";
259
-		}
260
-
261
-		return array(
262
-			'id'     => $this->get_id(),
263
-			'texts'  => array(
264
-				'item-name'        => sanitize_text_field( $this->get_name() ),
265
-				'item-description' => wp_kses_post( $this->get_description() ) . $description,
266
-				'item-quantity'    => absint( $this->get_quantity() ),
267
-				'item-price'       => wpinv_price( wpinv_format_amount ( $this->get_price() ), $currency ),
268
-				'item-total'       => wpinv_price( wpinv_format_amount( $this->get_sub_total() ), $currency ),
269
-			),
270
-			'inputs' => array(
271
-				'item-id'          => $this->get_id(),
272
-				'item-name'        => sanitize_text_field( $this->get_name() ),
273
-				'item-description' => wp_kses_post( $this->get_description() ),
274
-				'item-quantity'    => absint( $this->get_quantity() ),
275
-				'item-price'       => $this->get_price(),
276
-			)
277
-		);
278
-
279
-	}
280
-
281
-	/**
282
-	 * Prepares form data for saving (cart_details).
283
-	 *
284
-	 * @since 1.0.19
285
-	 * @return array
286
-	 */
287
-	public function prepare_data_for_saving() {
288
-
289
-		return array(
290
-			'post_id'           => $this->invoice_id,
291
-			'item_id'           => $this->get_id(),
292
-			'item_name'         => sanitize_text_field( $this->get_raw_name() ),
293
-			'item_description'  => $this->get_description(),
294
-			'tax'               => $this->item_tax,
295
-			'item_price'        => $this->get_price(),
296
-			'quantity'          => (int) $this->get_quantity(),
297
-			'discount'          => $this->item_discount,
298
-			'subtotal'          => $this->get_sub_total(),
299
-			'price'             => $this->get_sub_total() + $this->item_tax + $this->item_discount,
300
-			'meta'              => $this->get_item_meta(),
301
-		);
302
-
303
-	}
84
+     * Get the item name.
85
+     *
86
+     * @since 1.0.19
87
+     * @param  string $context View or edit context.
88
+     * @return string
89
+     */
90
+    public function get_name( $context = 'view' ) {
91
+        $name = parent::get_name( $context );
92
+        return $name . wpinv_get_item_suffix( $this );
93
+    }
94
+
95
+    /**
96
+     * Get the item name without a suffix.
97
+     *
98
+     * @since 1.0.19
99
+     * @param  string $context View or edit context.
100
+     * @return string
101
+     */
102
+    public function get_raw_name( $context = 'view' ) {
103
+        return parent::get_name( $context );
104
+    }
105
+
106
+    /**
107
+     * Get the item description.
108
+     *
109
+     * @since 1.0.19
110
+     * @param  string $context View or edit context.
111
+     * @return string
112
+     */
113
+    public function get_description( $context = 'view' ) {
114
+
115
+        if ( isset( $this->custom_description ) ) {
116
+            return $this->custom_description;
117
+        }
118
+
119
+        return parent::get_description( $context );
120
+    }
121
+
122
+    /**
123
+     * Returns the sub total.
124
+     *
125
+     * @since 1.0.19
126
+     * @param  string $context View or edit context.
127
+     * @return int
128
+     */
129
+    public function get_sub_total( $context = 'view' ) {
130
+        return $this->get_quantity( $context ) * $this->get_initial_price( $context );
131
+    }
132
+
133
+    /**
134
+     * Returns the recurring sub total.
135
+     *
136
+     * @since 1.0.19
137
+     * @param  string $context View or edit context.
138
+     * @return int
139
+     */
140
+    public function get_recurring_sub_total( $context = 'view' ) {
141
+        return $this->get_quantity( $context ) * $this->get_price( $context );
142
+    }
143
+
144
+    /**
145
+     * @deprecated
146
+     */
147
+    public function get_qantity( $context = 'view' ) {
148
+        return $this->get_quantity( $context );
149
+    }
150
+
151
+    /**
152
+     * Get the item quantity.
153
+     *
154
+     * @since 1.0.19
155
+     * @param  string $context View or edit context.
156
+     * @return int
157
+     */
158
+    public function get_quantity( $context = 'view' ) {
159
+        $quantity = (int) $this->quantity;
160
+
161
+        if ( empty( $quantity ) || 1 > $quantity ) {
162
+            $quantity = 1;
163
+        }
164
+
165
+        if ( 'view' == $context ) {
166
+            return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this );
167
+        }
168
+
169
+        return $quantity;
170
+
171
+    }
172
+
173
+    /**
174
+     * Get the item meta data.
175
+     *
176
+     * @since 1.0.19
177
+     * @param  string $context View or edit context.
178
+     * @return meta
179
+     */
180
+    public function get_item_meta( $context = 'view' ) {
181
+        $meta = $this->meta;
182
+
183
+        if ( 'view' == $context ) {
184
+            return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this );
185
+        }
186
+
187
+        return $meta;
188
+
189
+    }
190
+
191
+    /**
192
+     * Returns whether or not customers can update the item quantity.
193
+     *
194
+     * @since 1.0.19
195
+     * @param  string $context View or edit context.
196
+     * @return bool
197
+     */
198
+    public function get_allow_quantities( $context = 'view' ) {
199
+        $allow_quantities = (bool) $this->allow_quantities;
200
+
201
+        if ( 'view' == $context ) {
202
+            return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this );
203
+        }
204
+
205
+        return $allow_quantities;
206
+
207
+    }
208
+
209
+    /**
210
+     * Returns whether or not the item is required.
211
+     *
212
+     * @since 1.0.19
213
+     * @param  string $context View or edit context.
214
+     * @return bool
215
+     */
216
+    public function get_is_required( $context = 'view' ) {
217
+        $is_required = (bool) $this->is_required;
218
+
219
+        if ( 'view' == $context ) {
220
+            return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this );
221
+        }
222
+
223
+        return $is_required;
224
+
225
+    }
226
+
227
+    /**
228
+     * Prepares form data for use.
229
+     *
230
+     * @since 1.0.19
231
+     * @return array
232
+     */
233
+    public function prepare_data_for_use() {
234
+
235
+        return array(
236
+            'title'            => strip_tags( $this->get_name() ),
237
+            'id'               => $this->get_id(),
238
+            'price'            => $this->get_price(),
239
+            'recurring'        => $this->is_recurring(),
240
+            'description'      => $this->get_description(),
241
+            'allow_quantities' => $this->allows_quantities(),
242
+            'required'         => $this->is_required(),
243
+        );
244
+
245
+    }
246
+
247
+    /**
248
+     * Prepares form data for ajax use.
249
+     *
250
+     * @since 1.0.19
251
+     * @return array
252
+     */
253
+    public function prepare_data_for_invoice_edit_ajax( $currency = '' ) {
254
+
255
+        $description = getpaid_item_recurring_price_help_text( $this, $currency );
256
+
257
+        if ( $description ) {
258
+            $description = "<div class='getpaid-subscription-help-text'>$description</div>";
259
+        }
260
+
261
+        return array(
262
+            'id'     => $this->get_id(),
263
+            'texts'  => array(
264
+                'item-name'        => sanitize_text_field( $this->get_name() ),
265
+                'item-description' => wp_kses_post( $this->get_description() ) . $description,
266
+                'item-quantity'    => absint( $this->get_quantity() ),
267
+                'item-price'       => wpinv_price( wpinv_format_amount ( $this->get_price() ), $currency ),
268
+                'item-total'       => wpinv_price( wpinv_format_amount( $this->get_sub_total() ), $currency ),
269
+            ),
270
+            'inputs' => array(
271
+                'item-id'          => $this->get_id(),
272
+                'item-name'        => sanitize_text_field( $this->get_name() ),
273
+                'item-description' => wp_kses_post( $this->get_description() ),
274
+                'item-quantity'    => absint( $this->get_quantity() ),
275
+                'item-price'       => $this->get_price(),
276
+            )
277
+        );
278
+
279
+    }
280
+
281
+    /**
282
+     * Prepares form data for saving (cart_details).
283
+     *
284
+     * @since 1.0.19
285
+     * @return array
286
+     */
287
+    public function prepare_data_for_saving() {
288
+
289
+        return array(
290
+            'post_id'           => $this->invoice_id,
291
+            'item_id'           => $this->get_id(),
292
+            'item_name'         => sanitize_text_field( $this->get_raw_name() ),
293
+            'item_description'  => $this->get_description(),
294
+            'tax'               => $this->item_tax,
295
+            'item_price'        => $this->get_price(),
296
+            'quantity'          => (int) $this->get_quantity(),
297
+            'discount'          => $this->item_discount,
298
+            'subtotal'          => $this->get_sub_total(),
299
+            'price'             => $this->get_sub_total() + $this->item_tax + $this->item_discount,
300
+            'meta'              => $this->get_item_meta(),
301
+        );
302
+
303
+    }
304 304
 
305 305
     /*
306 306
 	|--------------------------------------------------------------------------
@@ -312,70 +312,70 @@  discard block
 block discarded – undo
312 312
 	| object.
313 313
     */
314 314
 
315
-	/**
316
-	 * Set the item qantity.
317
-	 *
318
-	 * @since 1.0.19
319
-	 * @param  int $quantity The item quantity.
320
-	 */
321
-	public function set_quantity( $quantity ) {
322
-
323
-		if ( empty( $quantity ) || ! is_numeric( $quantity ) ) {
324
-			$quantity = 1;
325
-		}
326
-
327
-		$this->quantity = (int) $quantity;
328
-
329
-	}
330
-
331
-	/**
332
-	 * Set the item meta data.
333
-	 *
334
-	 * @since 1.0.19
335
-	 * @param  array $meta The item meta data.
336
-	 */
337
-	public function set_item_meta( $meta ) {
338
-		$this->meta = maybe_unserialize( $meta );
339
-	}
340
-
341
-	/**
342
-	 * Set whether or not the quantities are allowed.
343
-	 *
344
-	 * @since 1.0.19
345
-	 * @param  bool $allow_quantities
346
-	 */
347
-	public function set_allow_quantities( $allow_quantities ) {
348
-		$this->allow_quantities = (bool) $allow_quantities;
349
-	}
350
-
351
-	/**
352
-	 * Set whether or not the item is required.
353
-	 *
354
-	 * @since 1.0.19
355
-	 * @param  bool $is_required
356
-	 */
357
-	public function set_is_required( $is_required ) {
358
-		$this->is_required = (bool) $is_required;
359
-	}
360
-
361
-	/**
362
-	 * Sets the custom item description.
363
-	 *
364
-	 * @since 1.0.19
365
-	 * @param  string $description
366
-	 */
367
-	public function set_custom_description( $description ) {
368
-		$this->custom_description = $description;
369
-	}
315
+    /**
316
+     * Set the item qantity.
317
+     *
318
+     * @since 1.0.19
319
+     * @param  int $quantity The item quantity.
320
+     */
321
+    public function set_quantity( $quantity ) {
322
+
323
+        if ( empty( $quantity ) || ! is_numeric( $quantity ) ) {
324
+            $quantity = 1;
325
+        }
326
+
327
+        $this->quantity = (int) $quantity;
328
+
329
+    }
330
+
331
+    /**
332
+     * Set the item meta data.
333
+     *
334
+     * @since 1.0.19
335
+     * @param  array $meta The item meta data.
336
+     */
337
+    public function set_item_meta( $meta ) {
338
+        $this->meta = maybe_unserialize( $meta );
339
+    }
340
+
341
+    /**
342
+     * Set whether or not the quantities are allowed.
343
+     *
344
+     * @since 1.0.19
345
+     * @param  bool $allow_quantities
346
+     */
347
+    public function set_allow_quantities( $allow_quantities ) {
348
+        $this->allow_quantities = (bool) $allow_quantities;
349
+    }
350
+
351
+    /**
352
+     * Set whether or not the item is required.
353
+     *
354
+     * @since 1.0.19
355
+     * @param  bool $is_required
356
+     */
357
+    public function set_is_required( $is_required ) {
358
+        $this->is_required = (bool) $is_required;
359
+    }
360
+
361
+    /**
362
+     * Sets the custom item description.
363
+     *
364
+     * @since 1.0.19
365
+     * @param  string $description
366
+     */
367
+    public function set_custom_description( $description ) {
368
+        $this->custom_description = $description;
369
+    }
370 370
 
371 371
     /**
372 372
      * We do not want to save items to the database.
373 373
      * 
374
-	 * @return int item id
374
+     * @return int item id
375 375
      */
376 376
     public function save( $data = array() ) {
377 377
         return $this->get_id();
378
-	}
378
+    }
379 379
 
380 380
     /*
381 381
 	|--------------------------------------------------------------------------
@@ -387,23 +387,23 @@  discard block
 block discarded – undo
387 387
 	*/
388 388
 
389 389
     /**
390
-	 * Checks whether the item has enabled dynamic pricing.
391
-	 *
392
-	 * @since 1.0.19
393
-	 * @return bool
394
-	 */
395
-	public function is_required() {
390
+     * Checks whether the item has enabled dynamic pricing.
391
+     *
392
+     * @since 1.0.19
393
+     * @return bool
394
+     */
395
+    public function is_required() {
396 396
         return (bool) $this->get_is_required();
397
-	}
398
-
399
-	/**
400
-	 * Checks whether users can edit the quantities.
401
-	 *
402
-	 * @since 1.0.19
403
-	 * @return bool
404
-	 */
405
-	public function allows_quantities() {
397
+    }
398
+
399
+    /**
400
+     * Checks whether users can edit the quantities.
401
+     *
402
+     * @since 1.0.19
403
+     * @return bool
404
+     */
405
+    public function allows_quantities() {
406 406
         return (bool) $this->get_allow_quantities();
407
-	}
407
+    }
408 408
 
409 409
 }
Please login to merge, or discard this patch.