Completed
Branch BUG/11302/correct-error-messag... (694f28)
by
unknown
29:47 queued 12:21
created

EE_Price::__construct()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 10

Duplication

Lines 13
Ratio 100 %

Importance

Changes 0
Metric Value
cc 2
eloc 10
nc 2
nop 5
dl 13
loc 13
rs 9.4285
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A EE_Price::set_is_default() 0 3 1
1
<?php if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) {
2
	exit( 'No direct script access allowed' );
3
}
4
/**
5
 * Event Espresso
6
 *
7
 * Event Registration and Management Plugin for WordPress
8
 *
9
 * @ package 		Event Espresso
10
 * @ author 		Event Espresso
11
 * @ copyright 	(c) 2008-2011 Event Espresso  All Rights Reserved.
12
 * @ license 		{@link http://eventespresso.com/support/terms-conditions/}   * see Plugin Licensing *
13
 * @ link 				{@link http://www.eventespresso.com}
14
 * @ since 			4.0
15
 *
16
 */
17
18
19
20
/**
21
 * EE_Price class
22
 *
23
 * @package 			Event Espresso
24
 * @subpackage 	includes/classes/EE_Price.class.php
25
 * @author             Mike Nelson
26
 */
27
class EE_Price extends EE_Soft_Delete_Base_Class {
28
29
	/**
30
	 *
31
	 * @param array $props_n_values  incoming values
32
	 * @param string $timezone  incoming timezone (if not set the timezone set for the website will be
33
	 *                          		used.)
34
	 * @param array $date_formats  incoming date_formats in an array where the first value is the
35
	 *                             		    date_format and the second value is the time format
36
	 * @return EE_Attendee
37
	 */
38
	public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) {
39
		$has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats );
40
		return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats );
41
	}
42
43
44
45
	/**
46
	 * @param array $props_n_values  incoming values from the database
47
	 * @param string $timezone  incoming timezone as set by the model.  If not set the timezone for
48
	 *                          		the website will be used.
49
	 * @return EE_Attendee
50
	 */
51
	public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) {
52
		return new self( $props_n_values, TRUE, $timezone );
53
	}
54
55
56
57
	/**
58
	 *        Set Price type ID
59
	 *
60
	 * @access        public
61
	 * @param        int $PRT_ID
62
	 */
63
	public function set_type( $PRT_ID = 0 ) {
64
		$this->set( 'PRT_ID', $PRT_ID );
65
	}
66
67
68
69
	/**
70
	 *        Set Price Amount
71
	 *
72
	 * @access        public
73
	 * @param        float $PRC_amount
74
	 */
75
	public function set_amount( $PRC_amount = 0.00 ) {
76
		$this->set( 'PRC_amount', $PRC_amount );
77
	}
78
79
80
81
	/**
82
	 *        Set Price Name
83
	 *
84
	 * @access        public
85
	 * @param        string $PRC_name
86
	 */
87
	public function set_name( $PRC_name = '' ) {
88
		$this->set( 'PRC_name', $PRC_name );
89
	}
90
91
92
93
	/**
94
	 *        Set Price Description
95
	 *
96
	 * @access        public
97
	 * @param        string $PRC_desc
98
	 */
99
	public function set_description( $PRC_desc = '' ) {
100
		$this->Set( 'PRC_desc', $PRC_desc );
101
	}
102
103
104
105
	/**
106
	*		set is_default
107
	*
108
	* 		@access		public
109
	*		@param		bool		$PRC_is_default
110
	*/
111
	public function set_is_default( $PRC_is_default = FALSE ) {
112
		$this->set( 'PRC_is_default', $PRC_is_default );
113
	}
114
115
116
117
	/**
118
	*		set deleted
119
	*
120
	* 		@access		public
121
	*		@param		bool		$PRC_deleted
122
	*/
123
	public function set_deleted( $PRC_deleted = NULL ) {
124
		$this->set( 'PRC_deleted', $PRC_deleted );
125
	}
126
127
128
129
	/**
130
	 *    get Price type
131
	 * @access        public
132
	 * @return        int
133
	 */
134
	public function type() {
135
		return $this->get( 'PRT_ID' );
136
	}
137
138
139
140
	/**
141
	 *    get Price Amount
142
	 * @access        public
143
	 * @return        float
144
	 */
145
	public function amount() {
146
		return $this->get( 'PRC_amount' );
147
	}
148
149
150
151
	/**
152
	 *    get Price Name
153
	 * @access        public
154
	 * @return        string
155
	 */
156
	public function name() {
157
		return $this->get( 'PRC_name' );
158
	}
159
160
161
162
	/**
163
	 *    get Price description
164
	 * @access        public
165
	 * @return        string
166
	 */
167
	public function desc() {
168
		return $this->get( 'PRC_desc' );
169
	}
170
171
172
173
	/**
174
	 *    get overrides
175
	 * @access        public
176
	 * @return        int
177
	 */
178
	public function overrides() {
179
		return $this->get( 'PRC_overrides' );
180
	}
181
182
183
184
	/**
185
	 *    get order
186
	 * @access        public
187
	 * @return        int
188
	 */
189
	public function order() {
190
		return $this->get( 'PRC_order' );
191
	}
192
193
194
195
	/**
196
	 * get the author of the price
197
	 *
198
	 * @since 4.5.0
199
	 *
200
	 * @return int
201
	 */
202
	public function wp_user() {
203
		return $this->get('PRC_wp_user');
204
	}
205
206
207
208
	/**
209
	 *    get is_default
210
	 * @access        public
211
	 * @return        bool
212
	 */
213
	public function is_default() {
214
		return $this->get( 'PRC_is_default' );
215
	}
216
217
218
219
	/**
220
	 *    get deleted
221
	 * @access        public
222
	 * @return        bool
223
	 */
224
	public function deleted() {
225
		return $this->get( 'PRC_deleted' );
226
	}
227
228
229
230
	/**
231
	 * @return bool
232
	 */
233
	public function parent() {
234
		return $this->get( 'PRC_parent' );
235
	}
236
237
238
	//some helper methods for getting info on the price_type for this price
239
240
	/**
241
	 * return whether the price is a base price or not
242
	 * @return boolean
243
	 */
244
	public function is_base_price() {
245
		$price_type = $this->type_obj();
246
		return $price_type->base_type() === 1;
247
	}
248
249
250
251
	/**
252
	 *
253
	 * @return EE_Price_Type
254
	 */
255
	public function type_obj() {
256
		return $this->get_first_related( 'Price_Type' );
257
	}
258
259
260
261
	/**
262
	 * Simply indicates whether this price increases or decreases the total
263
	 * @return boolean true = discount, otherwise adds to the total
264
	 */
265
	public function is_discount() {
266
		$price_type = $this->type_obj();
267
		return $price_type->is_discount();
268
	}
269
270
271
272
	/**
273
	 * whether the price is a percentage or not
274
	 * @return boolean
275
	 */
276
	public function is_percent() {
277
		$price_type = $this->type_obj();
278
		return $price_type->get( 'PRT_is_percent' );
279
	}
280
281
282
	/**
283
	 * return pretty price dependant on whether its a dollar or percent.
284
	 *
285
	 * @since 4.4.0
286
	 *
287
	 * @return string
288
	 */
289
	public function pretty_price() {
290
		return ! $this->is_percent() ? $this->get_pretty('PRC_amount') : $this->get('PRC_amount') . '%';
291
	}
292
293
294
295
	/**
296
	 * @return mixed
297
	 */
298
	public function get_price_without_currency_symbol() {
299
		return str_replace( EE_Registry::instance()->CFG->currency->sign, '', $this->get_pretty( 'PRC_amount' ) );
300
	}
301
}
302
303
/* End of file EE_Price.class.php */
304
/* Location: /includes/classes/EE_Price.class.php */
305