Passed
Push — master ( 9218e5...432370 )
by Brian
04:20
created
includes/payments/class-getpaid-form-item.php 1 patch
Indentation   +354 added lines, -354 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,232 +81,232 @@  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 float
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 float
139
-	 */
140
-	public function get_recurring_sub_total( $context = 'view' ) {
141
-
142
-		if ( $this->is_recurring() ) {
143
-			return $this->get_quantity( $context ) * $this->get_price( $context );
144
-		}
145
-
146
-		return 0;
147
-	}
148
-
149
-	/**
150
-	 * @deprecated
151
-	 */
152
-	public function get_qantity( $context = 'view' ) {
153
-		return $this->get_quantity( $context );
154
-	}
155
-
156
-	/**
157
-	 * Get the item quantity.
158
-	 *
159
-	 * @since 1.0.19
160
-	 * @param  string $context View or edit context.
161
-	 * @return int
162
-	 */
163
-	public function get_quantity( $context = 'view' ) {
164
-		$quantity = (int) $this->quantity;
165
-
166
-		if ( empty( $quantity ) || 1 > $quantity ) {
167
-			$quantity = 1;
168
-		}
169
-
170
-		if ( 'view' == $context ) {
171
-			return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this );
172
-		}
173
-
174
-		return $quantity;
175
-
176
-	}
177
-
178
-	/**
179
-	 * Get the item meta data.
180
-	 *
181
-	 * @since 1.0.19
182
-	 * @param  string $context View or edit context.
183
-	 * @return meta
184
-	 */
185
-	public function get_item_meta( $context = 'view' ) {
186
-		$meta = $this->meta;
187
-
188
-		if ( 'view' == $context ) {
189
-			return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this );
190
-		}
191
-
192
-		return $meta;
193
-
194
-	}
195
-
196
-	/**
197
-	 * Returns whether or not customers can update the item quantity.
198
-	 *
199
-	 * @since 1.0.19
200
-	 * @param  string $context View or edit context.
201
-	 * @return bool
202
-	 */
203
-	public function get_allow_quantities( $context = 'view' ) {
204
-		$allow_quantities = (bool) $this->allow_quantities;
205
-
206
-		if ( 'view' == $context ) {
207
-			return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this );
208
-		}
209
-
210
-		return $allow_quantities;
211
-
212
-	}
213
-
214
-	/**
215
-	 * Returns whether or not the item is required.
216
-	 *
217
-	 * @since 1.0.19
218
-	 * @param  string $context View or edit context.
219
-	 * @return bool
220
-	 */
221
-	public function get_is_required( $context = 'view' ) {
222
-		$is_required = (bool) $this->is_required;
223
-
224
-		if ( 'view' == $context ) {
225
-			return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this );
226
-		}
227
-
228
-		return $is_required;
229
-
230
-	}
231
-
232
-	/**
233
-	 * Prepares form data for use.
234
-	 *
235
-	 * @since 1.0.19
236
-	 * @return array
237
-	 */
238
-	public function prepare_data_for_use( $required = null ) {
239
-
240
-		$required = is_null( $required ) ? $this->is_required() : $required;
241
-		return array(
242
-			'title'            => strip_tags( $this->get_name() ),
243
-			'id'               => $this->get_id(),
244
-			'price'            => $this->get_price(),
245
-			'recurring'        => $this->is_recurring(),
246
-			'description'      => $this->get_description(),
247
-			'allow_quantities' => $this->allows_quantities(),
248
-			'required'         => $required,
249
-		);
250
-
251
-	}
252
-
253
-	/**
254
-	 * Prepares form data for ajax use.
255
-	 *
256
-	 * @since 1.0.19
257
-	 * @return array
258
-	 */
259
-	public function prepare_data_for_invoice_edit_ajax( $currency = '' ) {
260
-
261
-		$description = getpaid_item_recurring_price_help_text( $this, $currency );
262
-
263
-		if ( $description ) {
264
-			$description = "<div class='getpaid-subscription-help-text'>$description</div>";
265
-		}
266
-
267
-		return array(
268
-			'id'     => $this->get_id(),
269
-			'texts'  => array(
270
-				'item-name'        => sanitize_text_field( $this->get_name() ),
271
-				'item-description' => wp_kses_post( $this->get_description() ) . $description,
272
-				'item-quantity'    => absint( $this->get_quantity() ),
273
-				'item-price'       => wpinv_price( $this->get_price(), $currency ),
274
-				'item-total'       => wpinv_price( $this->get_sub_total(), $currency ),
275
-			),
276
-			'inputs' => array(
277
-				'item-id'          => $this->get_id(),
278
-				'item-name'        => sanitize_text_field( $this->get_name() ),
279
-				'item-description' => wp_kses_post( $this->get_description() ),
280
-				'item-quantity'    => absint( $this->get_quantity() ),
281
-				'item-price'       => $this->get_price(),
282
-			)
283
-		);
284
-
285
-	}
286
-
287
-	/**
288
-	 * Prepares form data for saving (cart_details).
289
-	 *
290
-	 * @since 1.0.19
291
-	 * @return array
292
-	 */
293
-	public function prepare_data_for_saving() {
294
-
295
-		return array(
296
-			'post_id'           => $this->invoice_id,
297
-			'item_id'           => $this->get_id(),
298
-			'item_name'         => sanitize_text_field( $this->get_raw_name() ),
299
-			'item_description'  => $this->get_description(),
300
-			'tax'               => $this->item_tax,
301
-			'item_price'        => $this->get_price(),
302
-			'quantity'          => (int) $this->get_quantity(),
303
-			'discount'          => $this->item_discount,
304
-			'subtotal'          => $this->get_sub_total(),
305
-			'price'             => $this->get_sub_total() + $this->item_tax + $this->item_discount,
306
-			'meta'              => $this->get_item_meta(),
307
-		);
308
-
309
-	}
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 float
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 float
139
+     */
140
+    public function get_recurring_sub_total( $context = 'view' ) {
141
+
142
+        if ( $this->is_recurring() ) {
143
+            return $this->get_quantity( $context ) * $this->get_price( $context );
144
+        }
145
+
146
+        return 0;
147
+    }
148
+
149
+    /**
150
+     * @deprecated
151
+     */
152
+    public function get_qantity( $context = 'view' ) {
153
+        return $this->get_quantity( $context );
154
+    }
155
+
156
+    /**
157
+     * Get the item quantity.
158
+     *
159
+     * @since 1.0.19
160
+     * @param  string $context View or edit context.
161
+     * @return int
162
+     */
163
+    public function get_quantity( $context = 'view' ) {
164
+        $quantity = (int) $this->quantity;
165
+
166
+        if ( empty( $quantity ) || 1 > $quantity ) {
167
+            $quantity = 1;
168
+        }
169
+
170
+        if ( 'view' == $context ) {
171
+            return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this );
172
+        }
173
+
174
+        return $quantity;
175
+
176
+    }
177
+
178
+    /**
179
+     * Get the item meta data.
180
+     *
181
+     * @since 1.0.19
182
+     * @param  string $context View or edit context.
183
+     * @return meta
184
+     */
185
+    public function get_item_meta( $context = 'view' ) {
186
+        $meta = $this->meta;
187
+
188
+        if ( 'view' == $context ) {
189
+            return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this );
190
+        }
191
+
192
+        return $meta;
193
+
194
+    }
195
+
196
+    /**
197
+     * Returns whether or not customers can update the item quantity.
198
+     *
199
+     * @since 1.0.19
200
+     * @param  string $context View or edit context.
201
+     * @return bool
202
+     */
203
+    public function get_allow_quantities( $context = 'view' ) {
204
+        $allow_quantities = (bool) $this->allow_quantities;
205
+
206
+        if ( 'view' == $context ) {
207
+            return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this );
208
+        }
209
+
210
+        return $allow_quantities;
211
+
212
+    }
213
+
214
+    /**
215
+     * Returns whether or not the item is required.
216
+     *
217
+     * @since 1.0.19
218
+     * @param  string $context View or edit context.
219
+     * @return bool
220
+     */
221
+    public function get_is_required( $context = 'view' ) {
222
+        $is_required = (bool) $this->is_required;
223
+
224
+        if ( 'view' == $context ) {
225
+            return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this );
226
+        }
227
+
228
+        return $is_required;
229
+
230
+    }
231
+
232
+    /**
233
+     * Prepares form data for use.
234
+     *
235
+     * @since 1.0.19
236
+     * @return array
237
+     */
238
+    public function prepare_data_for_use( $required = null ) {
239
+
240
+        $required = is_null( $required ) ? $this->is_required() : $required;
241
+        return array(
242
+            'title'            => strip_tags( $this->get_name() ),
243
+            'id'               => $this->get_id(),
244
+            'price'            => $this->get_price(),
245
+            'recurring'        => $this->is_recurring(),
246
+            'description'      => $this->get_description(),
247
+            'allow_quantities' => $this->allows_quantities(),
248
+            'required'         => $required,
249
+        );
250
+
251
+    }
252
+
253
+    /**
254
+     * Prepares form data for ajax use.
255
+     *
256
+     * @since 1.0.19
257
+     * @return array
258
+     */
259
+    public function prepare_data_for_invoice_edit_ajax( $currency = '' ) {
260
+
261
+        $description = getpaid_item_recurring_price_help_text( $this, $currency );
262
+
263
+        if ( $description ) {
264
+            $description = "<div class='getpaid-subscription-help-text'>$description</div>";
265
+        }
266
+
267
+        return array(
268
+            'id'     => $this->get_id(),
269
+            'texts'  => array(
270
+                'item-name'        => sanitize_text_field( $this->get_name() ),
271
+                'item-description' => wp_kses_post( $this->get_description() ) . $description,
272
+                'item-quantity'    => absint( $this->get_quantity() ),
273
+                'item-price'       => wpinv_price( $this->get_price(), $currency ),
274
+                'item-total'       => wpinv_price( $this->get_sub_total(), $currency ),
275
+            ),
276
+            'inputs' => array(
277
+                'item-id'          => $this->get_id(),
278
+                'item-name'        => sanitize_text_field( $this->get_name() ),
279
+                'item-description' => wp_kses_post( $this->get_description() ),
280
+                'item-quantity'    => absint( $this->get_quantity() ),
281
+                'item-price'       => $this->get_price(),
282
+            )
283
+        );
284
+
285
+    }
286
+
287
+    /**
288
+     * Prepares form data for saving (cart_details).
289
+     *
290
+     * @since 1.0.19
291
+     * @return array
292
+     */
293
+    public function prepare_data_for_saving() {
294
+
295
+        return array(
296
+            'post_id'           => $this->invoice_id,
297
+            'item_id'           => $this->get_id(),
298
+            'item_name'         => sanitize_text_field( $this->get_raw_name() ),
299
+            'item_description'  => $this->get_description(),
300
+            'tax'               => $this->item_tax,
301
+            'item_price'        => $this->get_price(),
302
+            'quantity'          => (int) $this->get_quantity(),
303
+            'discount'          => $this->item_discount,
304
+            'subtotal'          => $this->get_sub_total(),
305
+            'price'             => $this->get_sub_total() + $this->item_tax + $this->item_discount,
306
+            'meta'              => $this->get_item_meta(),
307
+        );
308
+
309
+    }
310 310
 
311 311
     /*
312 312
 	|--------------------------------------------------------------------------
@@ -318,70 +318,70 @@  discard block
 block discarded – undo
318 318
 	| object.
319 319
     */
320 320
 
321
-	/**
322
-	 * Set the item qantity.
323
-	 *
324
-	 * @since 1.0.19
325
-	 * @param  int $quantity The item quantity.
326
-	 */
327
-	public function set_quantity( $quantity ) {
328
-
329
-		if ( empty( $quantity ) || ! is_numeric( $quantity ) ) {
330
-			$quantity = 1;
331
-		}
332
-
333
-		$this->quantity = (int) $quantity;
334
-
335
-	}
336
-
337
-	/**
338
-	 * Set the item meta data.
339
-	 *
340
-	 * @since 1.0.19
341
-	 * @param  array $meta The item meta data.
342
-	 */
343
-	public function set_item_meta( $meta ) {
344
-		$this->meta = maybe_unserialize( $meta );
345
-	}
346
-
347
-	/**
348
-	 * Set whether or not the quantities are allowed.
349
-	 *
350
-	 * @since 1.0.19
351
-	 * @param  bool $allow_quantities
352
-	 */
353
-	public function set_allow_quantities( $allow_quantities ) {
354
-		$this->allow_quantities = (bool) $allow_quantities;
355
-	}
356
-
357
-	/**
358
-	 * Set whether or not the item is required.
359
-	 *
360
-	 * @since 1.0.19
361
-	 * @param  bool $is_required
362
-	 */
363
-	public function set_is_required( $is_required ) {
364
-		$this->is_required = (bool) $is_required;
365
-	}
366
-
367
-	/**
368
-	 * Sets the custom item description.
369
-	 *
370
-	 * @since 1.0.19
371
-	 * @param  string $description
372
-	 */
373
-	public function set_custom_description( $description ) {
374
-		$this->custom_description = $description;
375
-	}
321
+    /**
322
+     * Set the item qantity.
323
+     *
324
+     * @since 1.0.19
325
+     * @param  int $quantity The item quantity.
326
+     */
327
+    public function set_quantity( $quantity ) {
328
+
329
+        if ( empty( $quantity ) || ! is_numeric( $quantity ) ) {
330
+            $quantity = 1;
331
+        }
332
+
333
+        $this->quantity = (int) $quantity;
334
+
335
+    }
336
+
337
+    /**
338
+     * Set the item meta data.
339
+     *
340
+     * @since 1.0.19
341
+     * @param  array $meta The item meta data.
342
+     */
343
+    public function set_item_meta( $meta ) {
344
+        $this->meta = maybe_unserialize( $meta );
345
+    }
346
+
347
+    /**
348
+     * Set whether or not the quantities are allowed.
349
+     *
350
+     * @since 1.0.19
351
+     * @param  bool $allow_quantities
352
+     */
353
+    public function set_allow_quantities( $allow_quantities ) {
354
+        $this->allow_quantities = (bool) $allow_quantities;
355
+    }
356
+
357
+    /**
358
+     * Set whether or not the item is required.
359
+     *
360
+     * @since 1.0.19
361
+     * @param  bool $is_required
362
+     */
363
+    public function set_is_required( $is_required ) {
364
+        $this->is_required = (bool) $is_required;
365
+    }
366
+
367
+    /**
368
+     * Sets the custom item description.
369
+     *
370
+     * @since 1.0.19
371
+     * @param  string $description
372
+     */
373
+    public function set_custom_description( $description ) {
374
+        $this->custom_description = $description;
375
+    }
376 376
 
377 377
     /**
378 378
      * We do not want to save items to the database.
379 379
      * 
380
-	 * @return int item id
380
+     * @return int item id
381 381
      */
382 382
     public function save( $data = array() ) {
383 383
         return $this->get_id();
384
-	}
384
+    }
385 385
 
386 386
     /*
387 387
 	|--------------------------------------------------------------------------
@@ -393,23 +393,23 @@  discard block
 block discarded – undo
393 393
 	*/
394 394
 
395 395
     /**
396
-	 * Checks whether the item has enabled dynamic pricing.
397
-	 *
398
-	 * @since 1.0.19
399
-	 * @return bool
400
-	 */
401
-	public function is_required() {
396
+     * Checks whether the item has enabled dynamic pricing.
397
+     *
398
+     * @since 1.0.19
399
+     * @return bool
400
+     */
401
+    public function is_required() {
402 402
         return (bool) $this->get_is_required();
403
-	}
404
-
405
-	/**
406
-	 * Checks whether users can edit the quantities.
407
-	 *
408
-	 * @since 1.0.19
409
-	 * @return bool
410
-	 */
411
-	public function allows_quantities() {
403
+    }
404
+
405
+    /**
406
+     * Checks whether users can edit the quantities.
407
+     *
408
+     * @since 1.0.19
409
+     * @return bool
410
+     */
411
+    public function allows_quantities() {
412 412
         return (bool) $this->get_allow_quantities();
413
-	}
413
+    }
414 414
 
415 415
 }
Please login to merge, or discard this patch.