Completed
Branch EDTR/production (9ccccb)
by
unknown
34:07 queued 25:47
created
core/domain/services/admin/entities/DefaultPrices.php 2 patches
Indentation   +115 added lines, -115 removed lines patch added patch discarded remove patch
@@ -25,126 +25,126 @@
 block discarded – undo
25 25
 class DefaultPrices implements DefaultEntityGeneratorInterface
26 26
 {
27 27
 
28
-    /**
29
-     * @var EEM_Price $price_model
30
-     */
31
-    protected $price_model;
28
+	/**
29
+	 * @var EEM_Price $price_model
30
+	 */
31
+	protected $price_model;
32 32
 
33
-    /**
34
-     * @var EEM_Price_Type $price_type_model
35
-     */
36
-    protected $price_type_model;
33
+	/**
34
+	 * @var EEM_Price_Type $price_type_model
35
+	 */
36
+	protected $price_type_model;
37 37
 
38 38
 
39
-    /**
40
-     * @param EEM_Price      $price_model
41
-     * @param EEM_Price_Type $price_type_model
42
-     */
43
-    public function __construct(EEM_Price $price_model, EEM_Price_Type $price_type_model)
44
-    {
45
-        $this->price_model = $price_model;
46
-        $this->price_type_model = $price_type_model;
47
-    }
39
+	/**
40
+	 * @param EEM_Price      $price_model
41
+	 * @param EEM_Price_Type $price_type_model
42
+	 */
43
+	public function __construct(EEM_Price $price_model, EEM_Price_Type $price_type_model)
44
+	{
45
+		$this->price_model = $price_model;
46
+		$this->price_type_model = $price_type_model;
47
+	}
48 48
 
49 49
 
50
-    /**
51
-     * @param EE_Ticket|EE_Base_Class $entity
52
-     * @return EE_Price[]
53
-     * @throws EE_Error
54
-     * @throws InvalidInterfaceException
55
-     * @throws ReflectionException
56
-     * @since $VID:$
57
-     */
58
-    public function create(EE_Base_Class $entity)
59
-    {
60
-        if (! $entity instanceof EE_Ticket) {
61
-            throw new InvalidEntityException($entity, 'EE_Ticket');
62
-        }
63
-        $taxes = [];
64
-        $new_prices = [];
65
-        $is_free = true;
66
-        $has_base_price = false;
67
-        $default_prices = $this->price_model->get_all_default_prices(false, true);
68
-        if (is_array($default_prices)) {
69
-            foreach ($default_prices as $default_price) {
70
-                if (! $default_price instanceof EE_Price) {
71
-                    throw new InvalidEntityException($default_price, 'EE_Price');
72
-                }
73
-                // grab any taxes but don't do anything just yet
74
-                if ($default_price->is_tax()) {
75
-                    $taxes[] = $default_price;
76
-                    continue;
77
-                }
78
-                // duplicate the default price so that it does not get mutated
79
-                /** @var EE_Price $default_price_clone */
80
-                $default_price_clone = clone $default_price;
81
-                if ((
82
-                    // has non-zero base price
83
-                    $default_price_clone->is_base_price()
84
-                    && $default_price_clone->amount() > 0
85
-                ) ||(
86
-                    // or has fixed amount surcharge
87
-                    $default_price_clone->is_surcharge()
88
-                    && ! $default_price_clone->is_percent()
89
-                )) {
90
-                    $is_free = false;
91
-                }
92
-                $default_price_clone->set('PRC_ID', null);
93
-                $default_price_clone->set('PRC_is_default', false);
94
-                $default_price_clone->save();
95
-                $default_price_clone->_add_relation_to($entity, 'Ticket');
96
-                // verify that a base price has been set
97
-                $has_base_price = $default_price_clone->is_base_price() ? true : $has_base_price;
98
-                $new_prices[ $default_price_clone->ID() ] = $default_price_clone;
99
-            }
100
-        }
101
-        if (! $is_free && ! empty($taxes)) {
102
-            foreach ($taxes as $tax) {
103
-                // assign taxes but don't duplicate them because they operate globally
104
-                $entity->set_taxable(true);
105
-                $tax->_add_relation_to($entity, 'Ticket');
106
-            }
107
-        }
108
-        if (! $has_base_price) {
109
-            $new_base_price = $this->createNewBasePrice($entity);
110
-            $new_prices[ $new_base_price->ID() ] = $new_base_price;
111
-        }
112
-        $ticket_total = $entity->get_ticket_total_with_taxes(true);
113
-        if ($ticket_total !== $entity->ticket_price()) {
114
-            $entity->set_price($ticket_total);
115
-            $entity->save();
116
-        }
117
-        return $new_prices;
118
-    }
50
+	/**
51
+	 * @param EE_Ticket|EE_Base_Class $entity
52
+	 * @return EE_Price[]
53
+	 * @throws EE_Error
54
+	 * @throws InvalidInterfaceException
55
+	 * @throws ReflectionException
56
+	 * @since $VID:$
57
+	 */
58
+	public function create(EE_Base_Class $entity)
59
+	{
60
+		if (! $entity instanceof EE_Ticket) {
61
+			throw new InvalidEntityException($entity, 'EE_Ticket');
62
+		}
63
+		$taxes = [];
64
+		$new_prices = [];
65
+		$is_free = true;
66
+		$has_base_price = false;
67
+		$default_prices = $this->price_model->get_all_default_prices(false, true);
68
+		if (is_array($default_prices)) {
69
+			foreach ($default_prices as $default_price) {
70
+				if (! $default_price instanceof EE_Price) {
71
+					throw new InvalidEntityException($default_price, 'EE_Price');
72
+				}
73
+				// grab any taxes but don't do anything just yet
74
+				if ($default_price->is_tax()) {
75
+					$taxes[] = $default_price;
76
+					continue;
77
+				}
78
+				// duplicate the default price so that it does not get mutated
79
+				/** @var EE_Price $default_price_clone */
80
+				$default_price_clone = clone $default_price;
81
+				if ((
82
+					// has non-zero base price
83
+					$default_price_clone->is_base_price()
84
+					&& $default_price_clone->amount() > 0
85
+				) ||(
86
+					// or has fixed amount surcharge
87
+					$default_price_clone->is_surcharge()
88
+					&& ! $default_price_clone->is_percent()
89
+				)) {
90
+					$is_free = false;
91
+				}
92
+				$default_price_clone->set('PRC_ID', null);
93
+				$default_price_clone->set('PRC_is_default', false);
94
+				$default_price_clone->save();
95
+				$default_price_clone->_add_relation_to($entity, 'Ticket');
96
+				// verify that a base price has been set
97
+				$has_base_price = $default_price_clone->is_base_price() ? true : $has_base_price;
98
+				$new_prices[ $default_price_clone->ID() ] = $default_price_clone;
99
+			}
100
+		}
101
+		if (! $is_free && ! empty($taxes)) {
102
+			foreach ($taxes as $tax) {
103
+				// assign taxes but don't duplicate them because they operate globally
104
+				$entity->set_taxable(true);
105
+				$tax->_add_relation_to($entity, 'Ticket');
106
+			}
107
+		}
108
+		if (! $has_base_price) {
109
+			$new_base_price = $this->createNewBasePrice($entity);
110
+			$new_prices[ $new_base_price->ID() ] = $new_base_price;
111
+		}
112
+		$ticket_total = $entity->get_ticket_total_with_taxes(true);
113
+		if ($ticket_total !== $entity->ticket_price()) {
114
+			$entity->set_price($ticket_total);
115
+			$entity->save();
116
+		}
117
+		return $new_prices;
118
+	}
119 119
 
120 120
 
121
-    /**
122
-     * @param EE_Ticket $ticket
123
-     * @return EE_Price
124
-     * @throws EE_Error
125
-     * @throws ReflectionException
126
-     * @since $VID:$
127
-     */
128
-    protected function createNewBasePrice(EE_Ticket $ticket)
129
-    {
130
-        $new_base_price = $this->price_model->get_new_price();
131
-        $base_price_type = $this->price_type_model->get_one([
132
-            [
133
-                'PBT_ID' => EEM_Price_Type::base_type_base_price
134
-            ]
135
-        ]);
136
-        if (! $base_price_type instanceof EE_Price_Type) {
137
-            throw new RuntimeException(
138
-                esc_html__(
139
-                    'A valid base price type could not be retrieved from the database.',
140
-                    'event_espresso'
141
-                )
142
-            );
143
-        }
144
-        $new_base_price->set('PRT_ID', $base_price_type->ID());
145
-        $new_base_price->set('PRC_is_default', false);
146
-        $new_base_price->save();
147
-        $new_base_price->_add_relation_to($ticket, 'Ticket');
148
-        return $new_base_price;
149
-    }
121
+	/**
122
+	 * @param EE_Ticket $ticket
123
+	 * @return EE_Price
124
+	 * @throws EE_Error
125
+	 * @throws ReflectionException
126
+	 * @since $VID:$
127
+	 */
128
+	protected function createNewBasePrice(EE_Ticket $ticket)
129
+	{
130
+		$new_base_price = $this->price_model->get_new_price();
131
+		$base_price_type = $this->price_type_model->get_one([
132
+			[
133
+				'PBT_ID' => EEM_Price_Type::base_type_base_price
134
+			]
135
+		]);
136
+		if (! $base_price_type instanceof EE_Price_Type) {
137
+			throw new RuntimeException(
138
+				esc_html__(
139
+					'A valid base price type could not be retrieved from the database.',
140
+					'event_espresso'
141
+				)
142
+			);
143
+		}
144
+		$new_base_price->set('PRT_ID', $base_price_type->ID());
145
+		$new_base_price->set('PRC_is_default', false);
146
+		$new_base_price->save();
147
+		$new_base_price->_add_relation_to($ticket, 'Ticket');
148
+		return $new_base_price;
149
+	}
150 150
 }
Please login to merge, or discard this patch.
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
      */
58 58
     public function create(EE_Base_Class $entity)
59 59
     {
60
-        if (! $entity instanceof EE_Ticket) {
60
+        if ( ! $entity instanceof EE_Ticket) {
61 61
             throw new InvalidEntityException($entity, 'EE_Ticket');
62 62
         }
63 63
         $taxes = [];
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
         $default_prices = $this->price_model->get_all_default_prices(false, true);
68 68
         if (is_array($default_prices)) {
69 69
             foreach ($default_prices as $default_price) {
70
-                if (! $default_price instanceof EE_Price) {
70
+                if ( ! $default_price instanceof EE_Price) {
71 71
                     throw new InvalidEntityException($default_price, 'EE_Price');
72 72
                 }
73 73
                 // grab any taxes but don't do anything just yet
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
                     // has non-zero base price
83 83
                     $default_price_clone->is_base_price()
84 84
                     && $default_price_clone->amount() > 0
85
-                ) ||(
85
+                ) || (
86 86
                     // or has fixed amount surcharge
87 87
                     $default_price_clone->is_surcharge()
88 88
                     && ! $default_price_clone->is_percent()
@@ -95,19 +95,19 @@  discard block
 block discarded – undo
95 95
                 $default_price_clone->_add_relation_to($entity, 'Ticket');
96 96
                 // verify that a base price has been set
97 97
                 $has_base_price = $default_price_clone->is_base_price() ? true : $has_base_price;
98
-                $new_prices[ $default_price_clone->ID() ] = $default_price_clone;
98
+                $new_prices[$default_price_clone->ID()] = $default_price_clone;
99 99
             }
100 100
         }
101
-        if (! $is_free && ! empty($taxes)) {
101
+        if ( ! $is_free && ! empty($taxes)) {
102 102
             foreach ($taxes as $tax) {
103 103
                 // assign taxes but don't duplicate them because they operate globally
104 104
                 $entity->set_taxable(true);
105 105
                 $tax->_add_relation_to($entity, 'Ticket');
106 106
             }
107 107
         }
108
-        if (! $has_base_price) {
108
+        if ( ! $has_base_price) {
109 109
             $new_base_price = $this->createNewBasePrice($entity);
110
-            $new_prices[ $new_base_price->ID() ] = $new_base_price;
110
+            $new_prices[$new_base_price->ID()] = $new_base_price;
111 111
         }
112 112
         $ticket_total = $entity->get_ticket_total_with_taxes(true);
113 113
         if ($ticket_total !== $entity->ticket_price()) {
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
                 'PBT_ID' => EEM_Price_Type::base_type_base_price
134 134
             ]
135 135
         ]);
136
-        if (! $base_price_type instanceof EE_Price_Type) {
136
+        if ( ! $base_price_type instanceof EE_Price_Type) {
137 137
             throw new RuntimeException(
138 138
                 esc_html__(
139 139
                     'A valid base price type could not be retrieved from the database.',
Please login to merge, or discard this patch.
core/db_classes/EE_Price.class.php 1 patch
Indentation   +442 added lines, -442 removed lines patch added patch discarded remove patch
@@ -13,446 +13,446 @@
 block discarded – undo
13 13
 class EE_Price extends EE_Soft_Delete_Base_Class
14 14
 {
15 15
 
16
-    /**
17
-     * @param array  $props_n_values          incoming values
18
-     * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
19
-     *                                        used.)
20
-     * @param array  $date_formats            incoming date_formats in an array where the first value is the
21
-     *                                        date_format and the second value is the time format
22
-     * @return EE_Price
23
-     * @throws EE_Error
24
-     * @throws InvalidArgumentException
25
-     * @throws ReflectionException
26
-     * @throws InvalidDataTypeException
27
-     * @throws InvalidInterfaceException
28
-     */
29
-    public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
30
-    {
31
-        $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
32
-        return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
33
-    }
34
-
35
-
36
-    /**
37
-     * @param array  $props_n_values  incoming values from the database
38
-     * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
39
-     *                                the website will be used.
40
-     * @return EE_Price
41
-     * @throws EE_Error
42
-     * @throws InvalidArgumentException
43
-     * @throws ReflectionException
44
-     * @throws InvalidDataTypeException
45
-     * @throws InvalidInterfaceException
46
-     */
47
-    public static function new_instance_from_db($props_n_values = array(), $timezone = null)
48
-    {
49
-        return new self($props_n_values, true, $timezone);
50
-    }
51
-
52
-
53
-    /**
54
-     * Set Price type ID
55
-     *
56
-     * @param int $PRT_ID
57
-     * @throws EE_Error
58
-     * @throws InvalidArgumentException
59
-     * @throws ReflectionException
60
-     * @throws InvalidDataTypeException
61
-     * @throws InvalidInterfaceException
62
-     */
63
-    public function set_type($PRT_ID = 0)
64
-    {
65
-        $this->set('PRT_ID', $PRT_ID);
66
-    }
67
-
68
-
69
-    /**
70
-     * Set Price Amount
71
-     *
72
-     * @param float $PRC_amount
73
-     * @throws EE_Error
74
-     * @throws InvalidArgumentException
75
-     * @throws ReflectionException
76
-     * @throws InvalidDataTypeException
77
-     * @throws InvalidInterfaceException
78
-     */
79
-    public function set_amount($PRC_amount = 0.00)
80
-    {
81
-        $this->set('PRC_amount', $PRC_amount);
82
-    }
83
-
84
-
85
-    /**
86
-     * Set Price Name
87
-     *
88
-     * @param string $PRC_name
89
-     * @throws EE_Error
90
-     * @throws InvalidArgumentException
91
-     * @throws ReflectionException
92
-     * @throws InvalidDataTypeException
93
-     * @throws InvalidInterfaceException
94
-     */
95
-    public function set_name($PRC_name = '')
96
-    {
97
-        $this->set('PRC_name', $PRC_name);
98
-    }
99
-
100
-
101
-    /**
102
-     * Set Price Description
103
-     *
104
-     * @param string $PRC_desc
105
-     * @throws EE_Error
106
-     * @throws InvalidArgumentException
107
-     * @throws ReflectionException
108
-     * @throws InvalidDataTypeException
109
-     * @throws InvalidInterfaceException
110
-     */
111
-    public function set_description($PRC_desc = '')
112
-    {
113
-        $this->Set('PRC_desc', $PRC_desc);
114
-    }
115
-
116
-
117
-    /**
118
-     * set is_default
119
-     *
120
-     * @param bool $PRC_is_default
121
-     * @throws EE_Error
122
-     * @throws InvalidArgumentException
123
-     * @throws ReflectionException
124
-     * @throws InvalidDataTypeException
125
-     * @throws InvalidInterfaceException
126
-     */
127
-    public function set_is_default($PRC_is_default = false)
128
-    {
129
-        $this->set('PRC_is_default', $PRC_is_default);
130
-    }
131
-
132
-
133
-    /**
134
-     * set deleted
135
-     *
136
-     * @param bool $PRC_deleted
137
-     * @throws EE_Error
138
-     * @throws InvalidArgumentException
139
-     * @throws ReflectionException
140
-     * @throws InvalidDataTypeException
141
-     * @throws InvalidInterfaceException
142
-     */
143
-    public function set_deleted($PRC_deleted = null)
144
-    {
145
-        $this->set('PRC_deleted', $PRC_deleted);
146
-    }
147
-
148
-
149
-    /**
150
-     * get Price type
151
-     *
152
-     * @return        int
153
-     * @throws EE_Error
154
-     * @throws InvalidArgumentException
155
-     * @throws ReflectionException
156
-     * @throws InvalidDataTypeException
157
-     * @throws InvalidInterfaceException
158
-     */
159
-    public function type()
160
-    {
161
-        return $this->get('PRT_ID');
162
-    }
163
-
164
-
165
-    /**
166
-     * get Price Amount
167
-     *
168
-     * @return        float
169
-     * @throws EE_Error
170
-     * @throws InvalidArgumentException
171
-     * @throws ReflectionException
172
-     * @throws InvalidDataTypeException
173
-     * @throws InvalidInterfaceException
174
-     */
175
-    public function amount()
176
-    {
177
-        return $this->get('PRC_amount');
178
-    }
179
-
180
-
181
-    /**
182
-     * get Price Name
183
-     *
184
-     * @return        string
185
-     * @throws EE_Error
186
-     * @throws InvalidArgumentException
187
-     * @throws ReflectionException
188
-     * @throws InvalidDataTypeException
189
-     * @throws InvalidInterfaceException
190
-     */
191
-    public function name()
192
-    {
193
-        return $this->get('PRC_name');
194
-    }
195
-
196
-
197
-    /**
198
-     * get Price description
199
-     *
200
-     * @return        string
201
-     * @throws EE_Error
202
-     * @throws InvalidArgumentException
203
-     * @throws ReflectionException
204
-     * @throws InvalidDataTypeException
205
-     * @throws InvalidInterfaceException
206
-     */
207
-    public function desc()
208
-    {
209
-        return $this->get('PRC_desc');
210
-    }
211
-
212
-
213
-    /**
214
-     * get overrides
215
-     *
216
-     * @return        int
217
-     * @throws EE_Error
218
-     * @throws InvalidArgumentException
219
-     * @throws ReflectionException
220
-     * @throws InvalidDataTypeException
221
-     * @throws InvalidInterfaceException
222
-     */
223
-    public function overrides()
224
-    {
225
-        return $this->get('PRC_overrides');
226
-    }
227
-
228
-
229
-    /**
230
-     * get order
231
-     *
232
-     * @return int
233
-     * @throws EE_Error
234
-     * @throws InvalidArgumentException
235
-     * @throws ReflectionException
236
-     * @throws InvalidDataTypeException
237
-     * @throws InvalidInterfaceException
238
-     */
239
-    public function order()
240
-    {
241
-        return $this->get('PRC_order');
242
-    }
243
-
244
-
245
-    /**
246
-     * get the author of the price
247
-     *
248
-     * @return int
249
-     * @throws EE_Error
250
-     * @throws InvalidArgumentException
251
-     * @throws ReflectionException
252
-     * @throws InvalidDataTypeException
253
-     * @throws InvalidInterfaceException
254
-     * @since 4.5.0
255
-     */
256
-    public function wp_user()
257
-    {
258
-        return $this->get('PRC_wp_user');
259
-    }
260
-
261
-
262
-    /**
263
-     * get is_default
264
-     *
265
-     * @return bool
266
-     * @throws EE_Error
267
-     * @throws InvalidArgumentException
268
-     * @throws ReflectionException
269
-     * @throws InvalidDataTypeException
270
-     * @throws InvalidInterfaceException
271
-     */
272
-    public function is_default()
273
-    {
274
-        return $this->get('PRC_is_default');
275
-    }
276
-
277
-
278
-    /**
279
-     * get deleted
280
-     *
281
-     * @return bool
282
-     * @throws EE_Error
283
-     * @throws InvalidArgumentException
284
-     * @throws ReflectionException
285
-     * @throws InvalidDataTypeException
286
-     * @throws InvalidInterfaceException
287
-     */
288
-    public function deleted()
289
-    {
290
-        return $this->get('PRC_deleted');
291
-    }
292
-
293
-
294
-    /**
295
-     * @return bool
296
-     * @throws EE_Error
297
-     * @throws InvalidArgumentException
298
-     * @throws ReflectionException
299
-     * @throws InvalidDataTypeException
300
-     * @throws InvalidInterfaceException
301
-     */
302
-    public function parent()
303
-    {
304
-        return $this->get('PRC_parent');
305
-    }
306
-
307
-
308
-    // some helper methods for getting info on the price_type for this price
309
-
310
-
311
-    /**
312
-     * return whether the price is a base price or not
313
-     *
314
-     * @return boolean
315
-     * @throws EE_Error
316
-     * @throws InvalidArgumentException
317
-     * @throws InvalidDataTypeException
318
-     * @throws InvalidInterfaceException
319
-     * @throws ReflectionException
320
-     */
321
-    public function is_base_price()
322
-    {
323
-        $price_type = $this->type_obj();
324
-        return $price_type->is_base_price();
325
-    }
326
-
327
-
328
-    /**
329
-     * @return EE_Base_Class|EE_Price_Type
330
-     * @throws EE_Error
331
-     * @throws InvalidArgumentException
332
-     * @throws ReflectionException
333
-     * @throws InvalidDataTypeException
334
-     * @throws InvalidInterfaceException
335
-     */
336
-    public function type_obj()
337
-    {
338
-        return $this->get_first_related('Price_Type');
339
-    }
340
-
341
-
342
-    /**
343
-     * @return int
344
-     * @throws EE_Error
345
-     * @throws InvalidArgumentException
346
-     * @throws ReflectionException
347
-     * @throws InvalidDataTypeException
348
-     * @throws InvalidInterfaceException
349
-     */
350
-    public function type_order()
351
-    {
352
-        return $this->get_first_related('Price_Type')->order();
353
-    }
354
-
355
-
356
-    /**
357
-     * Simply indicates whether this price increases or decreases the total
358
-     *
359
-     * @return boolean true = discount, otherwise adds to the total
360
-     * @throws EE_Error
361
-     * @throws InvalidArgumentException
362
-     * @throws ReflectionException
363
-     * @throws InvalidDataTypeException
364
-     * @throws InvalidInterfaceException
365
-     */
366
-    public function is_discount()
367
-    {
368
-        $price_type = $this->type_obj();
369
-        return $price_type->is_discount();
370
-    }
371
-
372
-
373
-    /**
374
-     * whether the price is a percentage or not
375
-     *
376
-     * @return boolean
377
-     * @throws EE_Error
378
-     * @throws InvalidArgumentException
379
-     * @throws InvalidDataTypeException
380
-     * @throws InvalidInterfaceException
381
-     * @throws ReflectionException
382
-     */
383
-    public function is_percent()
384
-    {
385
-        $price_type = $this->type_obj();
386
-        return $price_type->is_percent();
387
-    }
388
-
389
-
390
-    /**
391
-     * whether the price is a percentage or not
392
-     *
393
-     * @return boolean
394
-     * @throws EE_Error
395
-     * @throws InvalidArgumentException
396
-     * @throws ReflectionException
397
-     * @throws InvalidDataTypeException
398
-     * @throws InvalidInterfaceException
399
-     */
400
-    public function is_surcharge()
401
-    {
402
-        $price_type = $this->type_obj();
403
-        return $price_type->is_surcharge();
404
-    }
405
-
406
-    /**
407
-     * whether the price is a percentage or not
408
-     *
409
-     * @return boolean
410
-     * @throws EE_Error
411
-     * @throws InvalidArgumentException
412
-     * @throws ReflectionException
413
-     * @throws InvalidDataTypeException
414
-     * @throws InvalidInterfaceException
415
-     */
416
-    public function is_tax()
417
-    {
418
-        $price_type = $this->type_obj();
419
-        return $price_type->is_tax();
420
-    }
421
-
422
-
423
-    /**
424
-     * return pretty price dependant on whether its a dollar or percent.
425
-     *
426
-     * @return string
427
-     * @throws EE_Error
428
-     * @throws InvalidArgumentException
429
-     * @throws ReflectionException
430
-     * @throws InvalidDataTypeException
431
-     * @throws InvalidInterfaceException
432
-     * @since 4.4.0
433
-     */
434
-    public function pretty_price()
435
-    {
436
-        return ! $this->is_percent()
437
-            ? $this->get_pretty('PRC_amount')
438
-            : $this->get('PRC_amount') . '%';
439
-    }
440
-
441
-
442
-    /**
443
-     * @return mixed
444
-     * @throws EE_Error
445
-     * @throws InvalidArgumentException
446
-     * @throws ReflectionException
447
-     * @throws InvalidDataTypeException
448
-     * @throws InvalidInterfaceException
449
-     */
450
-    public function get_price_without_currency_symbol()
451
-    {
452
-        return str_replace(
453
-            EE_Registry::instance()->CFG->currency->sign,
454
-            '',
455
-            $this->get_pretty('PRC_amount')
456
-        );
457
-    }
16
+	/**
17
+	 * @param array  $props_n_values          incoming values
18
+	 * @param string $timezone                incoming timezone (if not set the timezone set for the website will be
19
+	 *                                        used.)
20
+	 * @param array  $date_formats            incoming date_formats in an array where the first value is the
21
+	 *                                        date_format and the second value is the time format
22
+	 * @return EE_Price
23
+	 * @throws EE_Error
24
+	 * @throws InvalidArgumentException
25
+	 * @throws ReflectionException
26
+	 * @throws InvalidDataTypeException
27
+	 * @throws InvalidInterfaceException
28
+	 */
29
+	public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array())
30
+	{
31
+		$has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats);
32
+		return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats);
33
+	}
34
+
35
+
36
+	/**
37
+	 * @param array  $props_n_values  incoming values from the database
38
+	 * @param string $timezone        incoming timezone as set by the model.  If not set the timezone for
39
+	 *                                the website will be used.
40
+	 * @return EE_Price
41
+	 * @throws EE_Error
42
+	 * @throws InvalidArgumentException
43
+	 * @throws ReflectionException
44
+	 * @throws InvalidDataTypeException
45
+	 * @throws InvalidInterfaceException
46
+	 */
47
+	public static function new_instance_from_db($props_n_values = array(), $timezone = null)
48
+	{
49
+		return new self($props_n_values, true, $timezone);
50
+	}
51
+
52
+
53
+	/**
54
+	 * Set Price type ID
55
+	 *
56
+	 * @param int $PRT_ID
57
+	 * @throws EE_Error
58
+	 * @throws InvalidArgumentException
59
+	 * @throws ReflectionException
60
+	 * @throws InvalidDataTypeException
61
+	 * @throws InvalidInterfaceException
62
+	 */
63
+	public function set_type($PRT_ID = 0)
64
+	{
65
+		$this->set('PRT_ID', $PRT_ID);
66
+	}
67
+
68
+
69
+	/**
70
+	 * Set Price Amount
71
+	 *
72
+	 * @param float $PRC_amount
73
+	 * @throws EE_Error
74
+	 * @throws InvalidArgumentException
75
+	 * @throws ReflectionException
76
+	 * @throws InvalidDataTypeException
77
+	 * @throws InvalidInterfaceException
78
+	 */
79
+	public function set_amount($PRC_amount = 0.00)
80
+	{
81
+		$this->set('PRC_amount', $PRC_amount);
82
+	}
83
+
84
+
85
+	/**
86
+	 * Set Price Name
87
+	 *
88
+	 * @param string $PRC_name
89
+	 * @throws EE_Error
90
+	 * @throws InvalidArgumentException
91
+	 * @throws ReflectionException
92
+	 * @throws InvalidDataTypeException
93
+	 * @throws InvalidInterfaceException
94
+	 */
95
+	public function set_name($PRC_name = '')
96
+	{
97
+		$this->set('PRC_name', $PRC_name);
98
+	}
99
+
100
+
101
+	/**
102
+	 * Set Price Description
103
+	 *
104
+	 * @param string $PRC_desc
105
+	 * @throws EE_Error
106
+	 * @throws InvalidArgumentException
107
+	 * @throws ReflectionException
108
+	 * @throws InvalidDataTypeException
109
+	 * @throws InvalidInterfaceException
110
+	 */
111
+	public function set_description($PRC_desc = '')
112
+	{
113
+		$this->Set('PRC_desc', $PRC_desc);
114
+	}
115
+
116
+
117
+	/**
118
+	 * set is_default
119
+	 *
120
+	 * @param bool $PRC_is_default
121
+	 * @throws EE_Error
122
+	 * @throws InvalidArgumentException
123
+	 * @throws ReflectionException
124
+	 * @throws InvalidDataTypeException
125
+	 * @throws InvalidInterfaceException
126
+	 */
127
+	public function set_is_default($PRC_is_default = false)
128
+	{
129
+		$this->set('PRC_is_default', $PRC_is_default);
130
+	}
131
+
132
+
133
+	/**
134
+	 * set deleted
135
+	 *
136
+	 * @param bool $PRC_deleted
137
+	 * @throws EE_Error
138
+	 * @throws InvalidArgumentException
139
+	 * @throws ReflectionException
140
+	 * @throws InvalidDataTypeException
141
+	 * @throws InvalidInterfaceException
142
+	 */
143
+	public function set_deleted($PRC_deleted = null)
144
+	{
145
+		$this->set('PRC_deleted', $PRC_deleted);
146
+	}
147
+
148
+
149
+	/**
150
+	 * get Price type
151
+	 *
152
+	 * @return        int
153
+	 * @throws EE_Error
154
+	 * @throws InvalidArgumentException
155
+	 * @throws ReflectionException
156
+	 * @throws InvalidDataTypeException
157
+	 * @throws InvalidInterfaceException
158
+	 */
159
+	public function type()
160
+	{
161
+		return $this->get('PRT_ID');
162
+	}
163
+
164
+
165
+	/**
166
+	 * get Price Amount
167
+	 *
168
+	 * @return        float
169
+	 * @throws EE_Error
170
+	 * @throws InvalidArgumentException
171
+	 * @throws ReflectionException
172
+	 * @throws InvalidDataTypeException
173
+	 * @throws InvalidInterfaceException
174
+	 */
175
+	public function amount()
176
+	{
177
+		return $this->get('PRC_amount');
178
+	}
179
+
180
+
181
+	/**
182
+	 * get Price Name
183
+	 *
184
+	 * @return        string
185
+	 * @throws EE_Error
186
+	 * @throws InvalidArgumentException
187
+	 * @throws ReflectionException
188
+	 * @throws InvalidDataTypeException
189
+	 * @throws InvalidInterfaceException
190
+	 */
191
+	public function name()
192
+	{
193
+		return $this->get('PRC_name');
194
+	}
195
+
196
+
197
+	/**
198
+	 * get Price description
199
+	 *
200
+	 * @return        string
201
+	 * @throws EE_Error
202
+	 * @throws InvalidArgumentException
203
+	 * @throws ReflectionException
204
+	 * @throws InvalidDataTypeException
205
+	 * @throws InvalidInterfaceException
206
+	 */
207
+	public function desc()
208
+	{
209
+		return $this->get('PRC_desc');
210
+	}
211
+
212
+
213
+	/**
214
+	 * get overrides
215
+	 *
216
+	 * @return        int
217
+	 * @throws EE_Error
218
+	 * @throws InvalidArgumentException
219
+	 * @throws ReflectionException
220
+	 * @throws InvalidDataTypeException
221
+	 * @throws InvalidInterfaceException
222
+	 */
223
+	public function overrides()
224
+	{
225
+		return $this->get('PRC_overrides');
226
+	}
227
+
228
+
229
+	/**
230
+	 * get order
231
+	 *
232
+	 * @return int
233
+	 * @throws EE_Error
234
+	 * @throws InvalidArgumentException
235
+	 * @throws ReflectionException
236
+	 * @throws InvalidDataTypeException
237
+	 * @throws InvalidInterfaceException
238
+	 */
239
+	public function order()
240
+	{
241
+		return $this->get('PRC_order');
242
+	}
243
+
244
+
245
+	/**
246
+	 * get the author of the price
247
+	 *
248
+	 * @return int
249
+	 * @throws EE_Error
250
+	 * @throws InvalidArgumentException
251
+	 * @throws ReflectionException
252
+	 * @throws InvalidDataTypeException
253
+	 * @throws InvalidInterfaceException
254
+	 * @since 4.5.0
255
+	 */
256
+	public function wp_user()
257
+	{
258
+		return $this->get('PRC_wp_user');
259
+	}
260
+
261
+
262
+	/**
263
+	 * get is_default
264
+	 *
265
+	 * @return bool
266
+	 * @throws EE_Error
267
+	 * @throws InvalidArgumentException
268
+	 * @throws ReflectionException
269
+	 * @throws InvalidDataTypeException
270
+	 * @throws InvalidInterfaceException
271
+	 */
272
+	public function is_default()
273
+	{
274
+		return $this->get('PRC_is_default');
275
+	}
276
+
277
+
278
+	/**
279
+	 * get deleted
280
+	 *
281
+	 * @return bool
282
+	 * @throws EE_Error
283
+	 * @throws InvalidArgumentException
284
+	 * @throws ReflectionException
285
+	 * @throws InvalidDataTypeException
286
+	 * @throws InvalidInterfaceException
287
+	 */
288
+	public function deleted()
289
+	{
290
+		return $this->get('PRC_deleted');
291
+	}
292
+
293
+
294
+	/**
295
+	 * @return bool
296
+	 * @throws EE_Error
297
+	 * @throws InvalidArgumentException
298
+	 * @throws ReflectionException
299
+	 * @throws InvalidDataTypeException
300
+	 * @throws InvalidInterfaceException
301
+	 */
302
+	public function parent()
303
+	{
304
+		return $this->get('PRC_parent');
305
+	}
306
+
307
+
308
+	// some helper methods for getting info on the price_type for this price
309
+
310
+
311
+	/**
312
+	 * return whether the price is a base price or not
313
+	 *
314
+	 * @return boolean
315
+	 * @throws EE_Error
316
+	 * @throws InvalidArgumentException
317
+	 * @throws InvalidDataTypeException
318
+	 * @throws InvalidInterfaceException
319
+	 * @throws ReflectionException
320
+	 */
321
+	public function is_base_price()
322
+	{
323
+		$price_type = $this->type_obj();
324
+		return $price_type->is_base_price();
325
+	}
326
+
327
+
328
+	/**
329
+	 * @return EE_Base_Class|EE_Price_Type
330
+	 * @throws EE_Error
331
+	 * @throws InvalidArgumentException
332
+	 * @throws ReflectionException
333
+	 * @throws InvalidDataTypeException
334
+	 * @throws InvalidInterfaceException
335
+	 */
336
+	public function type_obj()
337
+	{
338
+		return $this->get_first_related('Price_Type');
339
+	}
340
+
341
+
342
+	/**
343
+	 * @return int
344
+	 * @throws EE_Error
345
+	 * @throws InvalidArgumentException
346
+	 * @throws ReflectionException
347
+	 * @throws InvalidDataTypeException
348
+	 * @throws InvalidInterfaceException
349
+	 */
350
+	public function type_order()
351
+	{
352
+		return $this->get_first_related('Price_Type')->order();
353
+	}
354
+
355
+
356
+	/**
357
+	 * Simply indicates whether this price increases or decreases the total
358
+	 *
359
+	 * @return boolean true = discount, otherwise adds to the total
360
+	 * @throws EE_Error
361
+	 * @throws InvalidArgumentException
362
+	 * @throws ReflectionException
363
+	 * @throws InvalidDataTypeException
364
+	 * @throws InvalidInterfaceException
365
+	 */
366
+	public function is_discount()
367
+	{
368
+		$price_type = $this->type_obj();
369
+		return $price_type->is_discount();
370
+	}
371
+
372
+
373
+	/**
374
+	 * whether the price is a percentage or not
375
+	 *
376
+	 * @return boolean
377
+	 * @throws EE_Error
378
+	 * @throws InvalidArgumentException
379
+	 * @throws InvalidDataTypeException
380
+	 * @throws InvalidInterfaceException
381
+	 * @throws ReflectionException
382
+	 */
383
+	public function is_percent()
384
+	{
385
+		$price_type = $this->type_obj();
386
+		return $price_type->is_percent();
387
+	}
388
+
389
+
390
+	/**
391
+	 * whether the price is a percentage or not
392
+	 *
393
+	 * @return boolean
394
+	 * @throws EE_Error
395
+	 * @throws InvalidArgumentException
396
+	 * @throws ReflectionException
397
+	 * @throws InvalidDataTypeException
398
+	 * @throws InvalidInterfaceException
399
+	 */
400
+	public function is_surcharge()
401
+	{
402
+		$price_type = $this->type_obj();
403
+		return $price_type->is_surcharge();
404
+	}
405
+
406
+	/**
407
+	 * whether the price is a percentage or not
408
+	 *
409
+	 * @return boolean
410
+	 * @throws EE_Error
411
+	 * @throws InvalidArgumentException
412
+	 * @throws ReflectionException
413
+	 * @throws InvalidDataTypeException
414
+	 * @throws InvalidInterfaceException
415
+	 */
416
+	public function is_tax()
417
+	{
418
+		$price_type = $this->type_obj();
419
+		return $price_type->is_tax();
420
+	}
421
+
422
+
423
+	/**
424
+	 * return pretty price dependant on whether its a dollar or percent.
425
+	 *
426
+	 * @return string
427
+	 * @throws EE_Error
428
+	 * @throws InvalidArgumentException
429
+	 * @throws ReflectionException
430
+	 * @throws InvalidDataTypeException
431
+	 * @throws InvalidInterfaceException
432
+	 * @since 4.4.0
433
+	 */
434
+	public function pretty_price()
435
+	{
436
+		return ! $this->is_percent()
437
+			? $this->get_pretty('PRC_amount')
438
+			: $this->get('PRC_amount') . '%';
439
+	}
440
+
441
+
442
+	/**
443
+	 * @return mixed
444
+	 * @throws EE_Error
445
+	 * @throws InvalidArgumentException
446
+	 * @throws ReflectionException
447
+	 * @throws InvalidDataTypeException
448
+	 * @throws InvalidInterfaceException
449
+	 */
450
+	public function get_price_without_currency_symbol()
451
+	{
452
+		return str_replace(
453
+			EE_Registry::instance()->CFG->currency->sign,
454
+			'',
455
+			$this->get_pretty('PRC_amount')
456
+		);
457
+	}
458 458
 }
Please login to merge, or discard this patch.