@@ -35,9 +35,9 @@ discard block |
||
35 | 35 | * @version $Revision 0.1 $ |
36 | 36 | */ |
37 | 37 | class EEH_Inflector{ |
38 | - // ------ CLASS METHODS ------ // |
|
39 | - // ---- Public methods ---- // |
|
40 | - // {{{ pluralize() |
|
38 | + // ------ CLASS METHODS ------ // |
|
39 | + // ---- Public methods ---- // |
|
40 | + // {{{ pluralize() |
|
41 | 41 | |
42 | 42 | /** |
43 | 43 | * Just calls self::pluralize and strtolower on $word and returns it |
@@ -51,319 +51,319 @@ discard block |
||
51 | 51 | static function singularize_and_upper( $word ) { |
52 | 52 | return str_replace( ' ', '_', self::humanize( self::singularize( $word ), 'all' ) ); |
53 | 53 | } |
54 | - /** |
|
55 | - * Pluralizes English nouns. |
|
56 | - * |
|
57 | - * @access public |
|
58 | - * @static |
|
59 | - * @param string $word English noun to pluralize |
|
60 | - * @return string Plural noun |
|
61 | - */ |
|
62 | - static function pluralize($word){ |
|
63 | - $plural = array( |
|
64 | - '/(quiz)$/i' => '\1zes', |
|
65 | - '/^(ox)$/i' => '\1en', |
|
66 | - '/([m|l])ouse$/i' => '\1ice', |
|
67 | - '/(matr|vert|ind)ix|ex$/i' => '\1ices', |
|
68 | - '/(x|ch|ss|sh)$/i' => '\1es', |
|
69 | - '/([^aeiouy]|qu)ies$/i' => '\1y', |
|
70 | - '/([^aeiouy]|qu)y$/i' => '\1ies', |
|
71 | - '/(hive)$/i' => '\1s', |
|
72 | - '/(?:([^f])fe|([lr])f)$/i' => '\1\2ves', |
|
73 | - '/sis$/i' => 'ses', |
|
74 | - '/([ti])um$/i' => '\1a', |
|
75 | - '/(buffal|tomat)o$/i' => '\1oes', |
|
76 | - '/(bu)s$/i' => '\1ses', |
|
77 | - '/(alias|status)/i' => '\1es', |
|
78 | - '/(octop|vir)us$/i' => '\1i', |
|
79 | - '/(ax|test)is$/i' => '\1es', |
|
80 | - '/s$/i' => 's', |
|
81 | - '/$/' => 's'); |
|
82 | - |
|
83 | - $uncountable = array('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep'); |
|
84 | - |
|
85 | - $irregular = array( |
|
86 | - 'person' => 'people', |
|
87 | - 'man' => 'men', |
|
88 | - 'child' => 'children', |
|
89 | - 'sex' => 'sexes', |
|
90 | - 'move' => 'moves'); |
|
91 | - |
|
92 | - $lowercased_word = strtolower($word); |
|
93 | - |
|
94 | - foreach($uncountable as $_uncountable){ |
|
95 | - if(substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable && //even though the word "price" ends in "rice", it can be pluralized, so check the previous character isnt a letter |
|
54 | + /** |
|
55 | + * Pluralizes English nouns. |
|
56 | + * |
|
57 | + * @access public |
|
58 | + * @static |
|
59 | + * @param string $word English noun to pluralize |
|
60 | + * @return string Plural noun |
|
61 | + */ |
|
62 | + static function pluralize($word){ |
|
63 | + $plural = array( |
|
64 | + '/(quiz)$/i' => '\1zes', |
|
65 | + '/^(ox)$/i' => '\1en', |
|
66 | + '/([m|l])ouse$/i' => '\1ice', |
|
67 | + '/(matr|vert|ind)ix|ex$/i' => '\1ices', |
|
68 | + '/(x|ch|ss|sh)$/i' => '\1es', |
|
69 | + '/([^aeiouy]|qu)ies$/i' => '\1y', |
|
70 | + '/([^aeiouy]|qu)y$/i' => '\1ies', |
|
71 | + '/(hive)$/i' => '\1s', |
|
72 | + '/(?:([^f])fe|([lr])f)$/i' => '\1\2ves', |
|
73 | + '/sis$/i' => 'ses', |
|
74 | + '/([ti])um$/i' => '\1a', |
|
75 | + '/(buffal|tomat)o$/i' => '\1oes', |
|
76 | + '/(bu)s$/i' => '\1ses', |
|
77 | + '/(alias|status)/i' => '\1es', |
|
78 | + '/(octop|vir)us$/i' => '\1i', |
|
79 | + '/(ax|test)is$/i' => '\1es', |
|
80 | + '/s$/i' => 's', |
|
81 | + '/$/' => 's'); |
|
82 | + |
|
83 | + $uncountable = array('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep'); |
|
84 | + |
|
85 | + $irregular = array( |
|
86 | + 'person' => 'people', |
|
87 | + 'man' => 'men', |
|
88 | + 'child' => 'children', |
|
89 | + 'sex' => 'sexes', |
|
90 | + 'move' => 'moves'); |
|
91 | + |
|
92 | + $lowercased_word = strtolower($word); |
|
93 | + |
|
94 | + foreach($uncountable as $_uncountable){ |
|
95 | + if(substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable && //even though the word "price" ends in "rice", it can be pluralized, so check the previous character isnt a letter |
|
96 | 96 | ! ctype_alpha( $lowercased_word[ strlen( $lowercased_word ) - strlen($_uncountable) ] ) ){ |
97 | - return $word; |
|
98 | - } |
|
99 | - } |
|
100 | - |
|
101 | - foreach($irregular as $_plural => $_singular){ |
|
102 | - if(preg_match('/(' . $_plural . ')$/i', $word, $arr)){ |
|
103 | - return preg_replace('/(' . $_plural . ')$/i', substr($arr[0], 0, 1) . substr($_singular, 1), $word); |
|
104 | - } |
|
105 | - } |
|
106 | - |
|
107 | - foreach($plural as $rule => $replacement){ |
|
108 | - if(preg_match($rule, $word)){ |
|
109 | - return preg_replace($rule, $replacement, $word); |
|
110 | - } |
|
111 | - } |
|
112 | - return false; |
|
113 | - } |
|
114 | - |
|
115 | - // }}} |
|
116 | - // {{{ singularize() |
|
117 | - |
|
118 | - /** |
|
119 | - * Singularizes English nouns. |
|
120 | - * |
|
121 | - * @access public |
|
122 | - * @static |
|
123 | - * @param string $word English noun to singularize |
|
124 | - * @return string Singular noun. |
|
125 | - */ |
|
126 | - static function singularize($word){ |
|
127 | - $singular = array( |
|
128 | - '/(quiz)zes$/i' => '\1', |
|
129 | - '/(matr)ices$/i' => '\1ix', |
|
130 | - '/(vert|ind)ices$/i' => '\1ex', |
|
131 | - '/^(ox)en/i' => '\1', |
|
132 | - '/(alias|status)es$/i' => '\1', |
|
133 | - '/([octop|vir])i$/i' => '\1us', |
|
134 | - '/(cris|ax|test)es$/i' => '\1is', |
|
135 | - '/(shoe)s$/i' => '\1', |
|
136 | - '/(o)es$/i' => '\1', |
|
137 | - '/(bus)es$/i' => '\1', |
|
138 | - '/([m|l])ice$/i' => '\1ouse', |
|
139 | - '/(x|ch|ss|sh)es$/i' => '\1', |
|
140 | - '/(m)ovies$/i' => '\1ovie', |
|
141 | - '/(s)eries$/i' => '\1eries', |
|
142 | - '/([^aeiouy]|qu)ies$/i' => '\1y', |
|
143 | - '/([lr])ves$/i' => '\1f', |
|
144 | - '/(tive)s$/i' => '\1', |
|
145 | - '/(hive)s$/i' => '\1', |
|
146 | - '/([^f])ves$/i' => '\1fe', |
|
147 | - '/(^analy)ses$/i' => '\1sis', |
|
148 | - '/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => '\1\2sis', |
|
149 | - '/([ti])a$/i' => '\1um', |
|
150 | - '/(n)ews$/i' => '\1ews', |
|
151 | - '/s$/i' => '', |
|
152 | - ); |
|
153 | - |
|
154 | - $uncountable = array('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep'); |
|
155 | - |
|
156 | - $irregular = array( |
|
157 | - 'person' => 'people', |
|
158 | - 'man' => 'men', |
|
159 | - 'child' => 'children', |
|
160 | - 'sex' => 'sexes', |
|
161 | - 'move' => 'moves'); |
|
162 | - |
|
163 | - $lowercased_word = strtolower($word); |
|
164 | - foreach($uncountable as $_uncountable){ |
|
165 | - if(substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable){ |
|
166 | - return $word; |
|
167 | - } |
|
168 | - } |
|
169 | - |
|
170 | - foreach($irregular as $_plural => $_singular){ |
|
171 | - if(preg_match('/(' . $_singular . ')$/i', $word, $arr)){ |
|
172 | - return preg_replace('/(' . $_singular . ')$/i', substr($arr[0], 0, 1) . substr($_plural, 1), $word); |
|
173 | - } |
|
174 | - } |
|
175 | - |
|
176 | - foreach($singular as $rule => $replacement){ |
|
177 | - if(preg_match($rule, $word)){ |
|
178 | - return preg_replace($rule, $replacement, $word); |
|
179 | - } |
|
180 | - } |
|
181 | - |
|
182 | - return $word; |
|
183 | - } |
|
184 | - |
|
185 | - // }}} |
|
186 | - // {{{ titleize() |
|
187 | - |
|
188 | - /** |
|
189 | - * Converts an underscored or CamelCase word into a English |
|
190 | - * sentence. |
|
191 | - * |
|
192 | - * The titleize static function converts text like "WelcomePage", |
|
193 | - * "welcome_page" or "welcome page" to this "Welcome |
|
194 | - * Page". |
|
195 | - * If second parameter is set to 'first' it will only |
|
196 | - * capitalize the first character of the title. |
|
197 | - * |
|
198 | - * @access public |
|
199 | - * @static |
|
200 | - * @param string $word Word to format as tile |
|
201 | - * @param string $uppercase If set to 'first' it will only uppercase the |
|
202 | - * first character. Otherwise it will uppercase all |
|
203 | - * the words in the title. |
|
204 | - * @return string Text formatted as title |
|
205 | - */ |
|
206 | - static function titleize($word, $uppercase = ''){ |
|
207 | - $uppercase = $uppercase == 'first' ? 'ucfirst' : 'ucwords'; |
|
208 | - return $uppercase(EEH_Inflector::humanize(EEH_Inflector::underscore($word))); |
|
209 | - } |
|
210 | - |
|
211 | - // }}} |
|
212 | - // {{{ camelize() |
|
213 | - |
|
214 | - /** |
|
215 | - * Returns given word as CamelCased |
|
216 | - * |
|
217 | - * Converts a word like "send_email" to "SendEmail". It |
|
218 | - * will remove non alphanumeric character from the word, so |
|
219 | - * "who's online" will be converted to "WhoSOnline" |
|
220 | - * |
|
221 | - * @access public |
|
222 | - * @static |
|
223 | - * @see variablize |
|
224 | - * @param string $word Word to convert to camel case |
|
225 | - * @return string UpperCamelCasedWord |
|
226 | - */ |
|
227 | - static function camelize($word){ |
|
228 | - return str_replace(' ', '', ucwords(preg_replace('/[^A-Z^a-z^0-9]+/', ' ', $word))); |
|
229 | - } |
|
230 | - |
|
231 | - // }}} |
|
232 | - // {{{ underscore() |
|
233 | - |
|
234 | - /** |
|
235 | - * Converts a word "into_it_s_underscored_version" |
|
236 | - * |
|
237 | - * Convert any "CamelCased" or "ordinary Word" into an |
|
238 | - * "underscored_word". |
|
239 | - * |
|
240 | - * This can be really useful for creating friendly URLs. |
|
241 | - * |
|
242 | - * @access public |
|
243 | - * @static |
|
244 | - * @param string $word Word to underscore |
|
245 | - * @return string Underscored word |
|
246 | - */ |
|
247 | - static function underscore($word){ |
|
248 | - return strtolower(preg_replace('/[^A-Z^a-z^0-9]+/', '_', preg_replace('/([a-zd])([A-Z])/', '1_2', preg_replace('/([A-Z]+)([A-Z][a-z])/', '1_2', $word)))); |
|
249 | - } |
|
250 | - |
|
251 | - // }}} |
|
252 | - // {{{ humanize() |
|
253 | - |
|
254 | - /** |
|
255 | - * Returns a human-readable string from $word |
|
256 | - * |
|
257 | - * Returns a human-readable string from $word, by replacing |
|
258 | - * underscores with a space, and by upper-casing the initial |
|
259 | - * character by default. |
|
260 | - * |
|
261 | - * If you need to uppercase all the words you just have to |
|
262 | - * pass 'all' as a second parameter. |
|
263 | - * |
|
264 | - * @access public |
|
265 | - * @static |
|
266 | - * @param string $word String to "humanize" |
|
267 | - * @param string $uppercase If set to 'all' it will uppercase all the words |
|
268 | - * instead of just the first one. |
|
269 | - * @return string Human-readable word |
|
270 | - */ |
|
271 | - static function humanize($word, $uppercase = ''){ |
|
97 | + return $word; |
|
98 | + } |
|
99 | + } |
|
100 | + |
|
101 | + foreach($irregular as $_plural => $_singular){ |
|
102 | + if(preg_match('/(' . $_plural . ')$/i', $word, $arr)){ |
|
103 | + return preg_replace('/(' . $_plural . ')$/i', substr($arr[0], 0, 1) . substr($_singular, 1), $word); |
|
104 | + } |
|
105 | + } |
|
106 | + |
|
107 | + foreach($plural as $rule => $replacement){ |
|
108 | + if(preg_match($rule, $word)){ |
|
109 | + return preg_replace($rule, $replacement, $word); |
|
110 | + } |
|
111 | + } |
|
112 | + return false; |
|
113 | + } |
|
114 | + |
|
115 | + // }}} |
|
116 | + // {{{ singularize() |
|
117 | + |
|
118 | + /** |
|
119 | + * Singularizes English nouns. |
|
120 | + * |
|
121 | + * @access public |
|
122 | + * @static |
|
123 | + * @param string $word English noun to singularize |
|
124 | + * @return string Singular noun. |
|
125 | + */ |
|
126 | + static function singularize($word){ |
|
127 | + $singular = array( |
|
128 | + '/(quiz)zes$/i' => '\1', |
|
129 | + '/(matr)ices$/i' => '\1ix', |
|
130 | + '/(vert|ind)ices$/i' => '\1ex', |
|
131 | + '/^(ox)en/i' => '\1', |
|
132 | + '/(alias|status)es$/i' => '\1', |
|
133 | + '/([octop|vir])i$/i' => '\1us', |
|
134 | + '/(cris|ax|test)es$/i' => '\1is', |
|
135 | + '/(shoe)s$/i' => '\1', |
|
136 | + '/(o)es$/i' => '\1', |
|
137 | + '/(bus)es$/i' => '\1', |
|
138 | + '/([m|l])ice$/i' => '\1ouse', |
|
139 | + '/(x|ch|ss|sh)es$/i' => '\1', |
|
140 | + '/(m)ovies$/i' => '\1ovie', |
|
141 | + '/(s)eries$/i' => '\1eries', |
|
142 | + '/([^aeiouy]|qu)ies$/i' => '\1y', |
|
143 | + '/([lr])ves$/i' => '\1f', |
|
144 | + '/(tive)s$/i' => '\1', |
|
145 | + '/(hive)s$/i' => '\1', |
|
146 | + '/([^f])ves$/i' => '\1fe', |
|
147 | + '/(^analy)ses$/i' => '\1sis', |
|
148 | + '/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)ses$/i' => '\1\2sis', |
|
149 | + '/([ti])a$/i' => '\1um', |
|
150 | + '/(n)ews$/i' => '\1ews', |
|
151 | + '/s$/i' => '', |
|
152 | + ); |
|
153 | + |
|
154 | + $uncountable = array('equipment', 'information', 'rice', 'money', 'species', 'series', 'fish', 'sheep'); |
|
155 | + |
|
156 | + $irregular = array( |
|
157 | + 'person' => 'people', |
|
158 | + 'man' => 'men', |
|
159 | + 'child' => 'children', |
|
160 | + 'sex' => 'sexes', |
|
161 | + 'move' => 'moves'); |
|
162 | + |
|
163 | + $lowercased_word = strtolower($word); |
|
164 | + foreach($uncountable as $_uncountable){ |
|
165 | + if(substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable){ |
|
166 | + return $word; |
|
167 | + } |
|
168 | + } |
|
169 | + |
|
170 | + foreach($irregular as $_plural => $_singular){ |
|
171 | + if(preg_match('/(' . $_singular . ')$/i', $word, $arr)){ |
|
172 | + return preg_replace('/(' . $_singular . ')$/i', substr($arr[0], 0, 1) . substr($_plural, 1), $word); |
|
173 | + } |
|
174 | + } |
|
175 | + |
|
176 | + foreach($singular as $rule => $replacement){ |
|
177 | + if(preg_match($rule, $word)){ |
|
178 | + return preg_replace($rule, $replacement, $word); |
|
179 | + } |
|
180 | + } |
|
181 | + |
|
182 | + return $word; |
|
183 | + } |
|
184 | + |
|
185 | + // }}} |
|
186 | + // {{{ titleize() |
|
187 | + |
|
188 | + /** |
|
189 | + * Converts an underscored or CamelCase word into a English |
|
190 | + * sentence. |
|
191 | + * |
|
192 | + * The titleize static function converts text like "WelcomePage", |
|
193 | + * "welcome_page" or "welcome page" to this "Welcome |
|
194 | + * Page". |
|
195 | + * If second parameter is set to 'first' it will only |
|
196 | + * capitalize the first character of the title. |
|
197 | + * |
|
198 | + * @access public |
|
199 | + * @static |
|
200 | + * @param string $word Word to format as tile |
|
201 | + * @param string $uppercase If set to 'first' it will only uppercase the |
|
202 | + * first character. Otherwise it will uppercase all |
|
203 | + * the words in the title. |
|
204 | + * @return string Text formatted as title |
|
205 | + */ |
|
206 | + static function titleize($word, $uppercase = ''){ |
|
207 | + $uppercase = $uppercase == 'first' ? 'ucfirst' : 'ucwords'; |
|
208 | + return $uppercase(EEH_Inflector::humanize(EEH_Inflector::underscore($word))); |
|
209 | + } |
|
210 | + |
|
211 | + // }}} |
|
212 | + // {{{ camelize() |
|
213 | + |
|
214 | + /** |
|
215 | + * Returns given word as CamelCased |
|
216 | + * |
|
217 | + * Converts a word like "send_email" to "SendEmail". It |
|
218 | + * will remove non alphanumeric character from the word, so |
|
219 | + * "who's online" will be converted to "WhoSOnline" |
|
220 | + * |
|
221 | + * @access public |
|
222 | + * @static |
|
223 | + * @see variablize |
|
224 | + * @param string $word Word to convert to camel case |
|
225 | + * @return string UpperCamelCasedWord |
|
226 | + */ |
|
227 | + static function camelize($word){ |
|
228 | + return str_replace(' ', '', ucwords(preg_replace('/[^A-Z^a-z^0-9]+/', ' ', $word))); |
|
229 | + } |
|
230 | + |
|
231 | + // }}} |
|
232 | + // {{{ underscore() |
|
233 | + |
|
234 | + /** |
|
235 | + * Converts a word "into_it_s_underscored_version" |
|
236 | + * |
|
237 | + * Convert any "CamelCased" or "ordinary Word" into an |
|
238 | + * "underscored_word". |
|
239 | + * |
|
240 | + * This can be really useful for creating friendly URLs. |
|
241 | + * |
|
242 | + * @access public |
|
243 | + * @static |
|
244 | + * @param string $word Word to underscore |
|
245 | + * @return string Underscored word |
|
246 | + */ |
|
247 | + static function underscore($word){ |
|
248 | + return strtolower(preg_replace('/[^A-Z^a-z^0-9]+/', '_', preg_replace('/([a-zd])([A-Z])/', '1_2', preg_replace('/([A-Z]+)([A-Z][a-z])/', '1_2', $word)))); |
|
249 | + } |
|
250 | + |
|
251 | + // }}} |
|
252 | + // {{{ humanize() |
|
253 | + |
|
254 | + /** |
|
255 | + * Returns a human-readable string from $word |
|
256 | + * |
|
257 | + * Returns a human-readable string from $word, by replacing |
|
258 | + * underscores with a space, and by upper-casing the initial |
|
259 | + * character by default. |
|
260 | + * |
|
261 | + * If you need to uppercase all the words you just have to |
|
262 | + * pass 'all' as a second parameter. |
|
263 | + * |
|
264 | + * @access public |
|
265 | + * @static |
|
266 | + * @param string $word String to "humanize" |
|
267 | + * @param string $uppercase If set to 'all' it will uppercase all the words |
|
268 | + * instead of just the first one. |
|
269 | + * @return string Human-readable word |
|
270 | + */ |
|
271 | + static function humanize($word, $uppercase = ''){ |
|
272 | 272 | //make special exceptions for acronyms |
273 | 273 | $word = str_replace('wp_', 'WP_', $word ); |
274 | - $uppercase = $uppercase == 'all' ? 'ucwords' : 'ucfirst'; |
|
275 | - return $uppercase(str_replace('_', ' ', preg_replace('/_id$/', '', $word))); |
|
276 | - } |
|
277 | - |
|
278 | - // }}} |
|
279 | - // {{{ variablize() |
|
280 | - |
|
281 | - /** |
|
282 | - * Same as camelize but first char is underscored |
|
283 | - * |
|
284 | - * Converts a word like "send_email" to "sendEmail". It |
|
285 | - * will remove non alphanumeric character from the word, so |
|
286 | - * "who's online" will be converted to "whoSOnline" |
|
287 | - * |
|
288 | - * @access public |
|
289 | - * @static |
|
290 | - * @see camelize |
|
291 | - * @param string $word Word to lowerCamelCase |
|
292 | - * @return string Returns a lowerCamelCasedWord |
|
293 | - */ |
|
294 | - static function variablize($word){ |
|
295 | - $word = EEH_Inflector::camelize($word); |
|
296 | - return strtolower($word[0]) . substr($word, 1); |
|
297 | - } |
|
298 | - |
|
299 | - // }}} |
|
300 | - // {{{ tableize() |
|
301 | - |
|
302 | - /** |
|
303 | - * Converts a class name to its table name according to rails |
|
304 | - * naming conventions. |
|
305 | - * |
|
306 | - * Converts "Person" to "people" |
|
307 | - * |
|
308 | - * @access public |
|
309 | - * @static |
|
310 | - * @see classify |
|
311 | - * @param string $class_name Class name for getting related table_name. |
|
312 | - * @return string plural_table_name |
|
313 | - */ |
|
314 | - static function tableize($class_name){ |
|
315 | - return EEH_Inflector::pluralize(EEH_Inflector::underscore($class_name)); |
|
316 | - } |
|
317 | - |
|
318 | - // }}} |
|
319 | - // {{{ classify() |
|
320 | - |
|
321 | - /** |
|
322 | - * Converts a table name to its class name according to rails |
|
323 | - * naming conventions. |
|
324 | - * |
|
325 | - * Converts "people" to "Person" |
|
326 | - * |
|
327 | - * @access public |
|
328 | - * @static |
|
329 | - * @see tableize |
|
330 | - * @param string $table_name Table name for getting related ClassName. |
|
331 | - * @return string SingularClassName |
|
332 | - */ |
|
333 | - static function classify($table_name){ |
|
334 | - return EEH_Inflector::camelize(EEH_Inflector::singularize($table_name)); |
|
335 | - } |
|
336 | - |
|
337 | - // }}} |
|
338 | - // {{{ ordinalize() |
|
339 | - |
|
340 | - /** |
|
341 | - * Converts number to its ordinal English form. |
|
342 | - * |
|
343 | - * This method converts 13 to 13th, 2 to 2nd ... |
|
344 | - * |
|
345 | - * @access public |
|
346 | - * @static |
|
347 | - * @param integer $number Number to get its ordinal value |
|
348 | - * @return string Ordinal representation of given string. |
|
349 | - */ |
|
350 | - static function ordinalize($number){ |
|
351 | - if(in_array(($number % 100), range(11, 13))){ |
|
352 | - return $number . 'th'; |
|
353 | - }else{ |
|
354 | - switch(($number % 10)){ |
|
355 | - case 1: |
|
356 | - return $number . 'st'; |
|
357 | - break; |
|
358 | - case 2: |
|
359 | - return $number . 'nd'; |
|
360 | - break; |
|
361 | - case 3: |
|
362 | - return $number . 'rd'; |
|
363 | - default: |
|
364 | - return $number . 'th'; |
|
365 | - break; |
|
366 | - } |
|
367 | - } |
|
368 | - } |
|
274 | + $uppercase = $uppercase == 'all' ? 'ucwords' : 'ucfirst'; |
|
275 | + return $uppercase(str_replace('_', ' ', preg_replace('/_id$/', '', $word))); |
|
276 | + } |
|
277 | + |
|
278 | + // }}} |
|
279 | + // {{{ variablize() |
|
280 | + |
|
281 | + /** |
|
282 | + * Same as camelize but first char is underscored |
|
283 | + * |
|
284 | + * Converts a word like "send_email" to "sendEmail". It |
|
285 | + * will remove non alphanumeric character from the word, so |
|
286 | + * "who's online" will be converted to "whoSOnline" |
|
287 | + * |
|
288 | + * @access public |
|
289 | + * @static |
|
290 | + * @see camelize |
|
291 | + * @param string $word Word to lowerCamelCase |
|
292 | + * @return string Returns a lowerCamelCasedWord |
|
293 | + */ |
|
294 | + static function variablize($word){ |
|
295 | + $word = EEH_Inflector::camelize($word); |
|
296 | + return strtolower($word[0]) . substr($word, 1); |
|
297 | + } |
|
298 | + |
|
299 | + // }}} |
|
300 | + // {{{ tableize() |
|
301 | + |
|
302 | + /** |
|
303 | + * Converts a class name to its table name according to rails |
|
304 | + * naming conventions. |
|
305 | + * |
|
306 | + * Converts "Person" to "people" |
|
307 | + * |
|
308 | + * @access public |
|
309 | + * @static |
|
310 | + * @see classify |
|
311 | + * @param string $class_name Class name for getting related table_name. |
|
312 | + * @return string plural_table_name |
|
313 | + */ |
|
314 | + static function tableize($class_name){ |
|
315 | + return EEH_Inflector::pluralize(EEH_Inflector::underscore($class_name)); |
|
316 | + } |
|
317 | + |
|
318 | + // }}} |
|
319 | + // {{{ classify() |
|
320 | + |
|
321 | + /** |
|
322 | + * Converts a table name to its class name according to rails |
|
323 | + * naming conventions. |
|
324 | + * |
|
325 | + * Converts "people" to "Person" |
|
326 | + * |
|
327 | + * @access public |
|
328 | + * @static |
|
329 | + * @see tableize |
|
330 | + * @param string $table_name Table name for getting related ClassName. |
|
331 | + * @return string SingularClassName |
|
332 | + */ |
|
333 | + static function classify($table_name){ |
|
334 | + return EEH_Inflector::camelize(EEH_Inflector::singularize($table_name)); |
|
335 | + } |
|
336 | + |
|
337 | + // }}} |
|
338 | + // {{{ ordinalize() |
|
339 | + |
|
340 | + /** |
|
341 | + * Converts number to its ordinal English form. |
|
342 | + * |
|
343 | + * This method converts 13 to 13th, 2 to 2nd ... |
|
344 | + * |
|
345 | + * @access public |
|
346 | + * @static |
|
347 | + * @param integer $number Number to get its ordinal value |
|
348 | + * @return string Ordinal representation of given string. |
|
349 | + */ |
|
350 | + static function ordinalize($number){ |
|
351 | + if(in_array(($number % 100), range(11, 13))){ |
|
352 | + return $number . 'th'; |
|
353 | + }else{ |
|
354 | + switch(($number % 10)){ |
|
355 | + case 1: |
|
356 | + return $number . 'st'; |
|
357 | + break; |
|
358 | + case 2: |
|
359 | + return $number . 'nd'; |
|
360 | + break; |
|
361 | + case 3: |
|
362 | + return $number . 'rd'; |
|
363 | + default: |
|
364 | + return $number . 'th'; |
|
365 | + break; |
|
366 | + } |
|
367 | + } |
|
368 | + } |
|
369 | 369 | } |
370 | 370 | \ No newline at end of file |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
3 | - exit( 'No direct script access allowed' ); |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | + exit('No direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | // +----------------------------------------------------------------------+ |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * @since 0.1 |
35 | 35 | * @version $Revision 0.1 $ |
36 | 36 | */ |
37 | -class EEH_Inflector{ |
|
37 | +class EEH_Inflector { |
|
38 | 38 | // ------ CLASS METHODS ------ // |
39 | 39 | // ---- Public methods ---- // |
40 | 40 | // {{{ pluralize() |
@@ -44,12 +44,12 @@ discard block |
||
44 | 44 | * @param string $word |
45 | 45 | * @return string |
46 | 46 | */ |
47 | - static function pluralize_and_lower( $word ){ |
|
48 | - return strtolower( self::pluralize( $word ) ); |
|
47 | + static function pluralize_and_lower($word) { |
|
48 | + return strtolower(self::pluralize($word)); |
|
49 | 49 | } |
50 | 50 | |
51 | - static function singularize_and_upper( $word ) { |
|
52 | - return str_replace( ' ', '_', self::humanize( self::singularize( $word ), 'all' ) ); |
|
51 | + static function singularize_and_upper($word) { |
|
52 | + return str_replace(' ', '_', self::humanize(self::singularize($word), 'all')); |
|
53 | 53 | } |
54 | 54 | /** |
55 | 55 | * Pluralizes English nouns. |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * @param string $word English noun to pluralize |
60 | 60 | * @return string Plural noun |
61 | 61 | */ |
62 | - static function pluralize($word){ |
|
62 | + static function pluralize($word) { |
|
63 | 63 | $plural = array( |
64 | 64 | '/(quiz)$/i' => '\1zes', |
65 | 65 | '/^(ox)$/i' => '\1en', |
@@ -91,21 +91,21 @@ discard block |
||
91 | 91 | |
92 | 92 | $lowercased_word = strtolower($word); |
93 | 93 | |
94 | - foreach($uncountable as $_uncountable){ |
|
95 | - if(substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable && //even though the word "price" ends in "rice", it can be pluralized, so check the previous character isnt a letter |
|
96 | - ! ctype_alpha( $lowercased_word[ strlen( $lowercased_word ) - strlen($_uncountable) ] ) ){ |
|
94 | + foreach ($uncountable as $_uncountable) { |
|
95 | + if (substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable && //even though the word "price" ends in "rice", it can be pluralized, so check the previous character isnt a letter |
|
96 | + ! ctype_alpha($lowercased_word[strlen($lowercased_word) - strlen($_uncountable)])) { |
|
97 | 97 | return $word; |
98 | 98 | } |
99 | 99 | } |
100 | 100 | |
101 | - foreach($irregular as $_plural => $_singular){ |
|
102 | - if(preg_match('/(' . $_plural . ')$/i', $word, $arr)){ |
|
103 | - return preg_replace('/(' . $_plural . ')$/i', substr($arr[0], 0, 1) . substr($_singular, 1), $word); |
|
101 | + foreach ($irregular as $_plural => $_singular) { |
|
102 | + if (preg_match('/('.$_plural.')$/i', $word, $arr)) { |
|
103 | + return preg_replace('/('.$_plural.')$/i', substr($arr[0], 0, 1).substr($_singular, 1), $word); |
|
104 | 104 | } |
105 | 105 | } |
106 | 106 | |
107 | - foreach($plural as $rule => $replacement){ |
|
108 | - if(preg_match($rule, $word)){ |
|
107 | + foreach ($plural as $rule => $replacement) { |
|
108 | + if (preg_match($rule, $word)) { |
|
109 | 109 | return preg_replace($rule, $replacement, $word); |
110 | 110 | } |
111 | 111 | } |
@@ -123,7 +123,7 @@ discard block |
||
123 | 123 | * @param string $word English noun to singularize |
124 | 124 | * @return string Singular noun. |
125 | 125 | */ |
126 | - static function singularize($word){ |
|
126 | + static function singularize($word) { |
|
127 | 127 | $singular = array( |
128 | 128 | '/(quiz)zes$/i' => '\1', |
129 | 129 | '/(matr)ices$/i' => '\1ix', |
@@ -161,20 +161,20 @@ discard block |
||
161 | 161 | 'move' => 'moves'); |
162 | 162 | |
163 | 163 | $lowercased_word = strtolower($word); |
164 | - foreach($uncountable as $_uncountable){ |
|
165 | - if(substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable){ |
|
164 | + foreach ($uncountable as $_uncountable) { |
|
165 | + if (substr($lowercased_word, (-1 * strlen($_uncountable))) == $_uncountable) { |
|
166 | 166 | return $word; |
167 | 167 | } |
168 | 168 | } |
169 | 169 | |
170 | - foreach($irregular as $_plural => $_singular){ |
|
171 | - if(preg_match('/(' . $_singular . ')$/i', $word, $arr)){ |
|
172 | - return preg_replace('/(' . $_singular . ')$/i', substr($arr[0], 0, 1) . substr($_plural, 1), $word); |
|
170 | + foreach ($irregular as $_plural => $_singular) { |
|
171 | + if (preg_match('/('.$_singular.')$/i', $word, $arr)) { |
|
172 | + return preg_replace('/('.$_singular.')$/i', substr($arr[0], 0, 1).substr($_plural, 1), $word); |
|
173 | 173 | } |
174 | 174 | } |
175 | 175 | |
176 | - foreach($singular as $rule => $replacement){ |
|
177 | - if(preg_match($rule, $word)){ |
|
176 | + foreach ($singular as $rule => $replacement) { |
|
177 | + if (preg_match($rule, $word)) { |
|
178 | 178 | return preg_replace($rule, $replacement, $word); |
179 | 179 | } |
180 | 180 | } |
@@ -203,7 +203,7 @@ discard block |
||
203 | 203 | * the words in the title. |
204 | 204 | * @return string Text formatted as title |
205 | 205 | */ |
206 | - static function titleize($word, $uppercase = ''){ |
|
206 | + static function titleize($word, $uppercase = '') { |
|
207 | 207 | $uppercase = $uppercase == 'first' ? 'ucfirst' : 'ucwords'; |
208 | 208 | return $uppercase(EEH_Inflector::humanize(EEH_Inflector::underscore($word))); |
209 | 209 | } |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | * @param string $word Word to convert to camel case |
225 | 225 | * @return string UpperCamelCasedWord |
226 | 226 | */ |
227 | - static function camelize($word){ |
|
227 | + static function camelize($word) { |
|
228 | 228 | return str_replace(' ', '', ucwords(preg_replace('/[^A-Z^a-z^0-9]+/', ' ', $word))); |
229 | 229 | } |
230 | 230 | |
@@ -244,7 +244,7 @@ discard block |
||
244 | 244 | * @param string $word Word to underscore |
245 | 245 | * @return string Underscored word |
246 | 246 | */ |
247 | - static function underscore($word){ |
|
247 | + static function underscore($word) { |
|
248 | 248 | return strtolower(preg_replace('/[^A-Z^a-z^0-9]+/', '_', preg_replace('/([a-zd])([A-Z])/', '1_2', preg_replace('/([A-Z]+)([A-Z][a-z])/', '1_2', $word)))); |
249 | 249 | } |
250 | 250 | |
@@ -268,9 +268,9 @@ discard block |
||
268 | 268 | * instead of just the first one. |
269 | 269 | * @return string Human-readable word |
270 | 270 | */ |
271 | - static function humanize($word, $uppercase = ''){ |
|
271 | + static function humanize($word, $uppercase = '') { |
|
272 | 272 | //make special exceptions for acronyms |
273 | - $word = str_replace('wp_', 'WP_', $word ); |
|
273 | + $word = str_replace('wp_', 'WP_', $word); |
|
274 | 274 | $uppercase = $uppercase == 'all' ? 'ucwords' : 'ucfirst'; |
275 | 275 | return $uppercase(str_replace('_', ' ', preg_replace('/_id$/', '', $word))); |
276 | 276 | } |
@@ -291,9 +291,9 @@ discard block |
||
291 | 291 | * @param string $word Word to lowerCamelCase |
292 | 292 | * @return string Returns a lowerCamelCasedWord |
293 | 293 | */ |
294 | - static function variablize($word){ |
|
294 | + static function variablize($word) { |
|
295 | 295 | $word = EEH_Inflector::camelize($word); |
296 | - return strtolower($word[0]) . substr($word, 1); |
|
296 | + return strtolower($word[0]).substr($word, 1); |
|
297 | 297 | } |
298 | 298 | |
299 | 299 | // }}} |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | * @param string $class_name Class name for getting related table_name. |
312 | 312 | * @return string plural_table_name |
313 | 313 | */ |
314 | - static function tableize($class_name){ |
|
314 | + static function tableize($class_name) { |
|
315 | 315 | return EEH_Inflector::pluralize(EEH_Inflector::underscore($class_name)); |
316 | 316 | } |
317 | 317 | |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | * @param string $table_name Table name for getting related ClassName. |
331 | 331 | * @return string SingularClassName |
332 | 332 | */ |
333 | - static function classify($table_name){ |
|
333 | + static function classify($table_name) { |
|
334 | 334 | return EEH_Inflector::camelize(EEH_Inflector::singularize($table_name)); |
335 | 335 | } |
336 | 336 | |
@@ -347,21 +347,21 @@ discard block |
||
347 | 347 | * @param integer $number Number to get its ordinal value |
348 | 348 | * @return string Ordinal representation of given string. |
349 | 349 | */ |
350 | - static function ordinalize($number){ |
|
351 | - if(in_array(($number % 100), range(11, 13))){ |
|
352 | - return $number . 'th'; |
|
353 | - }else{ |
|
354 | - switch(($number % 10)){ |
|
350 | + static function ordinalize($number) { |
|
351 | + if (in_array(($number % 100), range(11, 13))) { |
|
352 | + return $number.'th'; |
|
353 | + } else { |
|
354 | + switch (($number % 10)) { |
|
355 | 355 | case 1: |
356 | - return $number . 'st'; |
|
356 | + return $number.'st'; |
|
357 | 357 | break; |
358 | 358 | case 2: |
359 | - return $number . 'nd'; |
|
359 | + return $number.'nd'; |
|
360 | 360 | break; |
361 | 361 | case 3: |
362 | - return $number . 'rd'; |
|
362 | + return $number.'rd'; |
|
363 | 363 | default: |
364 | - return $number . 'th'; |
|
364 | + return $number.'th'; |
|
365 | 365 | break; |
366 | 366 | } |
367 | 367 | } |
@@ -350,7 +350,7 @@ |
||
350 | 350 | static function ordinalize($number){ |
351 | 351 | if(in_array(($number % 100), range(11, 13))){ |
352 | 352 | return $number . 'th'; |
353 | - }else{ |
|
353 | + } else{ |
|
354 | 354 | switch(($number % 10)){ |
355 | 355 | case 1: |
356 | 356 | return $number . 'st'; |
@@ -280,7 +280,7 @@ |
||
280 | 280 | $pre_tax_subtotal = self::get_pre_tax_subtotal( $total_line_item ); |
281 | 281 | if ( $pre_tax_subtotal instanceof EE_Line_Item ){ |
282 | 282 | $success = $pre_tax_subtotal->add_child_line_item($item); |
283 | - }else{ |
|
283 | + } else{ |
|
284 | 284 | return FALSE; |
285 | 285 | } |
286 | 286 | $total_line_item->recalculate_total_including_taxes(); |
@@ -551,15 +551,15 @@ discard block |
||
551 | 551 | } |
552 | 552 | |
553 | 553 | /** |
554 | - * Given the grand total line item and a ticket, finds the event sub-total |
|
555 | - * line item the ticket's purchase should be added onto |
|
556 | - * |
|
557 | - * @access public |
|
558 | - * @param EE_Line_Item $grand_total the grand total line item |
|
559 | - * @param EE_Ticket $ticket |
|
560 | - * @throws \EE_Error |
|
561 | - * @return EE_Line_Item |
|
562 | - */ |
|
554 | + * Given the grand total line item and a ticket, finds the event sub-total |
|
555 | + * line item the ticket's purchase should be added onto |
|
556 | + * |
|
557 | + * @access public |
|
558 | + * @param EE_Line_Item $grand_total the grand total line item |
|
559 | + * @param EE_Ticket $ticket |
|
560 | + * @throws \EE_Error |
|
561 | + * @return EE_Line_Item |
|
562 | + */ |
|
563 | 563 | public static function get_event_line_item_for_ticket( EE_Line_Item $grand_total, EE_Ticket $ticket ) { |
564 | 564 | $first_datetime = $ticket->first_datetime(); |
565 | 565 | if ( ! $first_datetime instanceof EE_Datetime ) { |
@@ -807,22 +807,22 @@ discard block |
||
807 | 807 | $add_to_existing_line_item = false |
808 | 808 | ) { |
809 | 809 | $tax_subtotal = self::get_taxes_subtotal( $total_line_item ); |
810 | - $taxable_total = $total_line_item->taxable_total(); |
|
811 | - |
|
812 | - if( $add_to_existing_line_item ) { |
|
813 | - $new_tax = $tax_subtotal->get_child_line_item( $code ); |
|
814 | - EEM_Line_Item::instance()->delete( |
|
815 | - array( array( 'LIN_code' => array( '!=', $code ), 'LIN_parent' => $tax_subtotal->ID() ) ) |
|
816 | - ); |
|
817 | - } else { |
|
818 | - $new_tax = null; |
|
819 | - $tax_subtotal->delete_children_line_items(); |
|
820 | - } |
|
821 | - if( $new_tax ) { |
|
822 | - $new_tax->set_total( $new_tax->total() + $amount ); |
|
823 | - $new_tax->set_percent( $taxable_total ? $new_tax->total() / $taxable_total * 100 : 0 ); |
|
824 | - } else { |
|
825 | - //no existing tax item. Create it |
|
810 | + $taxable_total = $total_line_item->taxable_total(); |
|
811 | + |
|
812 | + if( $add_to_existing_line_item ) { |
|
813 | + $new_tax = $tax_subtotal->get_child_line_item( $code ); |
|
814 | + EEM_Line_Item::instance()->delete( |
|
815 | + array( array( 'LIN_code' => array( '!=', $code ), 'LIN_parent' => $tax_subtotal->ID() ) ) |
|
816 | + ); |
|
817 | + } else { |
|
818 | + $new_tax = null; |
|
819 | + $tax_subtotal->delete_children_line_items(); |
|
820 | + } |
|
821 | + if( $new_tax ) { |
|
822 | + $new_tax->set_total( $new_tax->total() + $amount ); |
|
823 | + $new_tax->set_percent( $taxable_total ? $new_tax->total() / $taxable_total * 100 : 0 ); |
|
824 | + } else { |
|
825 | + //no existing tax item. Create it |
|
826 | 826 | $new_tax = EE_Line_Item::new_instance( array( |
827 | 827 | 'TXN_ID' => $total_line_item->TXN_ID(), |
828 | 828 | 'LIN_name' => $name ? $name : __( 'Tax', 'event_espresso' ), |
@@ -835,16 +835,16 @@ discard block |
||
835 | 835 | ) ); |
836 | 836 | } |
837 | 837 | |
838 | - $new_tax = apply_filters( |
|
838 | + $new_tax = apply_filters( |
|
839 | 839 | 'FHEE__EEH_Line_Item__set_total_tax_to__new_tax_subtotal', |
840 | 840 | $new_tax, |
841 | 841 | $total_line_item |
842 | - ); |
|
843 | - $new_tax->save(); |
|
844 | - $tax_subtotal->set_total( $new_tax->total() ); |
|
845 | - $tax_subtotal->save(); |
|
846 | - $total_line_item->recalculate_total_including_taxes(); |
|
847 | - return $new_tax; |
|
842 | + ); |
|
843 | + $new_tax->save(); |
|
844 | + $tax_subtotal->set_total( $new_tax->total() ); |
|
845 | + $tax_subtotal->save(); |
|
846 | + $total_line_item->recalculate_total_including_taxes(); |
|
847 | + return $new_tax; |
|
848 | 848 | } |
849 | 849 | |
850 | 850 | |
@@ -990,7 +990,7 @@ discard block |
||
990 | 990 | if ( $child_line_item instanceof EE_Line_Item ) { |
991 | 991 | if ( |
992 | 992 | $child_line_item->type() === $line_item_type |
993 | - && ( |
|
993 | + && ( |
|
994 | 994 | $child_line_item->OBJ_type() === $obj_type || $obj_type === null |
995 | 995 | ) |
996 | 996 | ) { |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if (!defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
|
2 | 2 | /** |
3 | 3 | * |
4 | 4 | * EEH_Line_Item |
@@ -45,8 +45,8 @@ discard block |
||
45 | 45 | * @return boolean success |
46 | 46 | * @throws \EE_Error |
47 | 47 | */ |
48 | - public static function add_unrelated_item( EE_Line_Item $parent_line_item, $name, $unit_price, $description = '', $quantity = 1, $taxable = FALSE, $code = NULL ){ |
|
49 | - $items_subtotal = self::get_pre_tax_subtotal( $parent_line_item ); |
|
48 | + public static function add_unrelated_item(EE_Line_Item $parent_line_item, $name, $unit_price, $description = '', $quantity = 1, $taxable = FALSE, $code = NULL) { |
|
49 | + $items_subtotal = self::get_pre_tax_subtotal($parent_line_item); |
|
50 | 50 | $line_item = EE_Line_Item::new_instance(array( |
51 | 51 | 'LIN_name' => $name, |
52 | 52 | 'LIN_desc' => $description, |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | 'LIN_quantity' => $quantity, |
55 | 55 | 'LIN_percent' => null, |
56 | 56 | 'LIN_is_taxable' => $taxable, |
57 | - 'LIN_order' => $items_subtotal instanceof EE_Line_Item ? count( $items_subtotal->children() ) : 0, |
|
57 | + 'LIN_order' => $items_subtotal instanceof EE_Line_Item ? count($items_subtotal->children()) : 0, |
|
58 | 58 | 'LIN_total' => (float) $unit_price * (int) $quantity, |
59 | 59 | 'LIN_type'=> EEM_Line_Item::type_line_item, |
60 | 60 | 'LIN_code' => $code, |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | $line_item, |
65 | 65 | $parent_line_item |
66 | 66 | ); |
67 | - return self::add_item( $parent_line_item, $line_item ); |
|
67 | + return self::add_item($parent_line_item, $line_item); |
|
68 | 68 | } |
69 | 69 | |
70 | 70 | |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * @return boolean success |
87 | 87 | * @throws \EE_Error |
88 | 88 | */ |
89 | - public static function add_percentage_based_item( EE_Line_Item $parent_line_item, $name, $percentage_amount, $description = '', $taxable = FALSE ){ |
|
89 | + public static function add_percentage_based_item(EE_Line_Item $parent_line_item, $name, $percentage_amount, $description = '', $taxable = FALSE) { |
|
90 | 90 | $line_item = EE_Line_Item::new_instance(array( |
91 | 91 | 'LIN_name' => $name, |
92 | 92 | 'LIN_desc' => $description, |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | 'LIN_percent' => $percentage_amount, |
95 | 95 | 'LIN_quantity' => NULL, |
96 | 96 | 'LIN_is_taxable' => $taxable, |
97 | - 'LIN_total' => (float) ( $percentage_amount * ( $parent_line_item->total() / 100 ) ), |
|
97 | + 'LIN_total' => (float) ($percentage_amount * ($parent_line_item->total() / 100)), |
|
98 | 98 | 'LIN_type'=> EEM_Line_Item::type_line_item, |
99 | 99 | 'LIN_parent' => $parent_line_item->ID() |
100 | 100 | )); |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | 'FHEE__EEH_Line_Item__add_percentage_based_item__line_item', |
103 | 103 | $line_item |
104 | 104 | ); |
105 | - return self::add_item( $parent_line_item, $line_item ); |
|
105 | + return self::add_item($parent_line_item, $line_item); |
|
106 | 106 | } |
107 | 107 | |
108 | 108 | |
@@ -123,15 +123,15 @@ discard block |
||
123 | 123 | * @return \EE_Line_Item |
124 | 124 | * @throws \EE_Error |
125 | 125 | */ |
126 | - public static function add_ticket_purchase( EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1 ){ |
|
127 | - if ( ! $total_line_item instanceof EE_Line_Item || ! $total_line_item->is_total() ) { |
|
128 | - throw new EE_Error( sprintf( __( 'A valid line item total is required in order to add tickets. A line item of type "%s" was passed.', 'event_espresso' ), $ticket->ID(), $total_line_item->ID() ) ); |
|
126 | + public static function add_ticket_purchase(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) { |
|
127 | + if ( ! $total_line_item instanceof EE_Line_Item || ! $total_line_item->is_total()) { |
|
128 | + throw new EE_Error(sprintf(__('A valid line item total is required in order to add tickets. A line item of type "%s" was passed.', 'event_espresso'), $ticket->ID(), $total_line_item->ID())); |
|
129 | 129 | } |
130 | 130 | // either increment the qty for an existing ticket |
131 | - $line_item = self::increment_ticket_qty_if_already_in_cart( $total_line_item, $ticket, $qty ); |
|
131 | + $line_item = self::increment_ticket_qty_if_already_in_cart($total_line_item, $ticket, $qty); |
|
132 | 132 | // or add a new one |
133 | - if ( ! $line_item instanceof EE_Line_Item ) { |
|
134 | - $line_item = self::create_ticket_line_item( $total_line_item, $ticket, $qty ); |
|
133 | + if ( ! $line_item instanceof EE_Line_Item) { |
|
134 | + $line_item = self::create_ticket_line_item($total_line_item, $ticket, $qty); |
|
135 | 135 | } |
136 | 136 | $total_line_item->recalculate_total_including_taxes(); |
137 | 137 | return $line_item; |
@@ -147,11 +147,11 @@ discard block |
||
147 | 147 | * @return \EE_Line_Item |
148 | 148 | * @throws \EE_Error |
149 | 149 | */ |
150 | - public static function increment_ticket_qty_if_already_in_cart( EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1 ) { |
|
150 | + public static function increment_ticket_qty_if_already_in_cart(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) { |
|
151 | 151 | $line_item = null; |
152 | - if ( $total_line_item instanceof EE_Line_Item && $total_line_item->is_total() ) { |
|
153 | - $ticket_line_items = EEH_Line_Item::get_ticket_line_items( $total_line_item ); |
|
154 | - foreach ( (array)$ticket_line_items as $ticket_line_item ) { |
|
152 | + if ($total_line_item instanceof EE_Line_Item && $total_line_item->is_total()) { |
|
153 | + $ticket_line_items = EEH_Line_Item::get_ticket_line_items($total_line_item); |
|
154 | + foreach ((array) $ticket_line_items as $ticket_line_item) { |
|
155 | 155 | if ( |
156 | 156 | $ticket_line_item instanceof EE_Line_Item |
157 | 157 | && (int) $ticket_line_item->OBJ_ID() === (int) $ticket->ID() |
@@ -161,8 +161,8 @@ discard block |
||
161 | 161 | } |
162 | 162 | } |
163 | 163 | } |
164 | - if ( $line_item instanceof EE_Line_Item ) { |
|
165 | - EEH_Line_Item::increment_quantity( $line_item, $qty ); |
|
164 | + if ($line_item instanceof EE_Line_Item) { |
|
165 | + EEH_Line_Item::increment_quantity($line_item, $qty); |
|
166 | 166 | return $line_item; |
167 | 167 | } |
168 | 168 | return null; |
@@ -179,16 +179,16 @@ discard block |
||
179 | 179 | * @return void |
180 | 180 | * @throws \EE_Error |
181 | 181 | */ |
182 | - public static function increment_quantity( EE_Line_Item $line_item, $qty = 1 ) { |
|
183 | - if( ! $line_item->is_percent() ) { |
|
182 | + public static function increment_quantity(EE_Line_Item $line_item, $qty = 1) { |
|
183 | + if ( ! $line_item->is_percent()) { |
|
184 | 184 | $qty += $line_item->quantity(); |
185 | - $line_item->set_quantity( $qty ); |
|
186 | - $line_item->set_total( $line_item->unit_price() * $qty ); |
|
185 | + $line_item->set_quantity($qty); |
|
186 | + $line_item->set_total($line_item->unit_price() * $qty); |
|
187 | 187 | $line_item->save(); |
188 | 188 | } |
189 | - foreach( $line_item->children() as $child ) { |
|
190 | - if( $child->is_sub_line_item() ) { |
|
191 | - EEH_Line_Item::update_quantity( $child, $qty ); |
|
189 | + foreach ($line_item->children() as $child) { |
|
190 | + if ($child->is_sub_line_item()) { |
|
191 | + EEH_Line_Item::update_quantity($child, $qty); |
|
192 | 192 | } |
193 | 193 | } |
194 | 194 | } |
@@ -204,17 +204,17 @@ discard block |
||
204 | 204 | * @return void |
205 | 205 | * @throws \EE_Error |
206 | 206 | */ |
207 | - public static function decrement_quantity( EE_Line_Item $line_item, $qty = 1 ) { |
|
208 | - if( ! $line_item->is_percent() ) { |
|
207 | + public static function decrement_quantity(EE_Line_Item $line_item, $qty = 1) { |
|
208 | + if ( ! $line_item->is_percent()) { |
|
209 | 209 | $qty = $line_item->quantity() - $qty; |
210 | - $qty = max( $qty, 0 ); |
|
211 | - $line_item->set_quantity( $qty ); |
|
212 | - $line_item->set_total( $line_item->unit_price() * $qty ); |
|
210 | + $qty = max($qty, 0); |
|
211 | + $line_item->set_quantity($qty); |
|
212 | + $line_item->set_total($line_item->unit_price() * $qty); |
|
213 | 213 | $line_item->save(); |
214 | 214 | } |
215 | - foreach( $line_item->children() as $child ) { |
|
216 | - if( $child->is_sub_line_item() ) { |
|
217 | - EEH_Line_Item::update_quantity( $child, $qty ); |
|
215 | + foreach ($line_item->children() as $child) { |
|
216 | + if ($child->is_sub_line_item()) { |
|
217 | + EEH_Line_Item::update_quantity($child, $qty); |
|
218 | 218 | } |
219 | 219 | } |
220 | 220 | } |
@@ -229,15 +229,15 @@ discard block |
||
229 | 229 | * @param int $new_quantity |
230 | 230 | * @throws \EE_Error |
231 | 231 | */ |
232 | - public static function update_quantity( EE_Line_Item $line_item, $new_quantity ) { |
|
233 | - if( ! $line_item->is_percent() ) { |
|
234 | - $line_item->set_quantity( $new_quantity ); |
|
235 | - $line_item->set_total( $line_item->unit_price() * $new_quantity ); |
|
232 | + public static function update_quantity(EE_Line_Item $line_item, $new_quantity) { |
|
233 | + if ( ! $line_item->is_percent()) { |
|
234 | + $line_item->set_quantity($new_quantity); |
|
235 | + $line_item->set_total($line_item->unit_price() * $new_quantity); |
|
236 | 236 | $line_item->save(); |
237 | 237 | } |
238 | - foreach( $line_item->children() as $child ) { |
|
239 | - if( $child->is_sub_line_item() ) { |
|
240 | - EEH_Line_Item::update_quantity( $child, $new_quantity ); |
|
238 | + foreach ($line_item->children() as $child) { |
|
239 | + if ($child->is_sub_line_item()) { |
|
240 | + EEH_Line_Item::update_quantity($child, $new_quantity); |
|
241 | 241 | } |
242 | 242 | } |
243 | 243 | } |
@@ -252,43 +252,43 @@ discard block |
||
252 | 252 | * @return \EE_Line_Item |
253 | 253 | * @throws \EE_Error |
254 | 254 | */ |
255 | - public static function create_ticket_line_item( EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1 ) { |
|
255 | + public static function create_ticket_line_item(EE_Line_Item $total_line_item, EE_Ticket $ticket, $qty = 1) { |
|
256 | 256 | $datetimes = $ticket->datetimes(); |
257 | - $first_datetime = reset( $datetimes ); |
|
258 | - if( $first_datetime instanceof EE_Datetime && $first_datetime->event() instanceof EE_Event ) { |
|
257 | + $first_datetime = reset($datetimes); |
|
258 | + if ($first_datetime instanceof EE_Datetime && $first_datetime->event() instanceof EE_Event) { |
|
259 | 259 | $first_datetime_name = $first_datetime->event()->name(); |
260 | 260 | } else { |
261 | - $first_datetime_name = __( 'Event', 'event_espresso' ); |
|
261 | + $first_datetime_name = __('Event', 'event_espresso'); |
|
262 | 262 | } |
263 | - $event = sprintf( _x( '(For %1$s)', '(For Event Name)', 'event_espresso' ), $first_datetime_name ); |
|
263 | + $event = sprintf(_x('(For %1$s)', '(For Event Name)', 'event_espresso'), $first_datetime_name); |
|
264 | 264 | // get event subtotal line |
265 | - $events_sub_total = self::get_event_line_item_for_ticket( $total_line_item, $ticket ); |
|
265 | + $events_sub_total = self::get_event_line_item_for_ticket($total_line_item, $ticket); |
|
266 | 266 | // add $ticket to cart |
267 | - $line_item = EE_Line_Item::new_instance( array( |
|
267 | + $line_item = EE_Line_Item::new_instance(array( |
|
268 | 268 | 'LIN_name' => $ticket->name(), |
269 | - 'LIN_desc' => $ticket->description() !== '' ? $ticket->description() . ' ' . $event : $event, |
|
269 | + 'LIN_desc' => $ticket->description() !== '' ? $ticket->description().' '.$event : $event, |
|
270 | 270 | 'LIN_unit_price' => $ticket->price(), |
271 | 271 | 'LIN_quantity' => $qty, |
272 | 272 | 'LIN_is_taxable' => $ticket->taxable(), |
273 | - 'LIN_order' => count( $events_sub_total->children() ), |
|
273 | + 'LIN_order' => count($events_sub_total->children()), |
|
274 | 274 | 'LIN_total' => $ticket->price() * $qty, |
275 | 275 | 'LIN_type' => EEM_Line_Item::type_line_item, |
276 | 276 | 'OBJ_ID' => $ticket->ID(), |
277 | 277 | 'OBJ_type' => 'Ticket' |
278 | - ) ); |
|
278 | + )); |
|
279 | 279 | $line_item = apply_filters( |
280 | 280 | 'FHEE__EEH_Line_Item__create_ticket_line_item__line_item', |
281 | 281 | $line_item |
282 | 282 | ); |
283 | - $events_sub_total->add_child_line_item( $line_item ); |
|
283 | + $events_sub_total->add_child_line_item($line_item); |
|
284 | 284 | //now add the sub-line items |
285 | 285 | $running_total_for_ticket = 0; |
286 | - foreach ( $ticket->prices( array( 'order_by' => array( 'PRC_order' => 'ASC' ) ) ) as $price ) { |
|
286 | + foreach ($ticket->prices(array('order_by' => array('PRC_order' => 'ASC'))) as $price) { |
|
287 | 287 | $sign = $price->is_discount() ? -1 : 1; |
288 | 288 | $price_total = $price->is_percent() |
289 | 289 | ? $running_total_for_ticket * $price->amount() / 100 |
290 | 290 | : $price->amount() * $qty; |
291 | - $sub_line_item = EE_Line_Item::new_instance( array( |
|
291 | + $sub_line_item = EE_Line_Item::new_instance(array( |
|
292 | 292 | 'LIN_name' => $price->name(), |
293 | 293 | 'LIN_desc' => $price->desc(), |
294 | 294 | 'LIN_quantity' => $price->is_percent() ? null : $qty, |
@@ -298,18 +298,18 @@ discard block |
||
298 | 298 | 'LIN_type' => EEM_Line_Item::type_sub_line_item, |
299 | 299 | 'OBJ_ID' => $price->ID(), |
300 | 300 | 'OBJ_type' => 'Price' |
301 | - ) ); |
|
301 | + )); |
|
302 | 302 | $sub_line_item = apply_filters( |
303 | 303 | 'FHEE__EEH_Line_Item__create_ticket_line_item__sub_line_item', |
304 | 304 | $sub_line_item |
305 | 305 | ); |
306 | - if ( $price->is_percent() ) { |
|
307 | - $sub_line_item->set_percent( $sign * $price->amount() ); |
|
306 | + if ($price->is_percent()) { |
|
307 | + $sub_line_item->set_percent($sign * $price->amount()); |
|
308 | 308 | } else { |
309 | - $sub_line_item->set_unit_price( $sign * $price->amount() ); |
|
309 | + $sub_line_item->set_unit_price($sign * $price->amount()); |
|
310 | 310 | } |
311 | 311 | $running_total_for_ticket += $price_total; |
312 | - $line_item->add_child_line_item( $sub_line_item ); |
|
312 | + $line_item->add_child_line_item($sub_line_item); |
|
313 | 313 | } |
314 | 314 | return $line_item; |
315 | 315 | } |
@@ -329,11 +329,11 @@ discard block |
||
329 | 329 | * @return boolean |
330 | 330 | * @throws \EE_Error |
331 | 331 | */ |
332 | - public static function add_item( EE_Line_Item $total_line_item, EE_Line_Item $item ){ |
|
333 | - $pre_tax_subtotal = self::get_pre_tax_subtotal( $total_line_item ); |
|
334 | - if ( $pre_tax_subtotal instanceof EE_Line_Item ){ |
|
332 | + public static function add_item(EE_Line_Item $total_line_item, EE_Line_Item $item) { |
|
333 | + $pre_tax_subtotal = self::get_pre_tax_subtotal($total_line_item); |
|
334 | + if ($pre_tax_subtotal instanceof EE_Line_Item) { |
|
335 | 335 | $success = $pre_tax_subtotal->add_child_line_item($item); |
336 | - }else{ |
|
336 | + } else { |
|
337 | 337 | return FALSE; |
338 | 338 | } |
339 | 339 | $total_line_item->recalculate_total_including_taxes(); |
@@ -352,34 +352,34 @@ discard block |
||
352 | 352 | * @return bool success |
353 | 353 | * @throws \EE_Error |
354 | 354 | */ |
355 | - public static function cancel_ticket_line_item( EE_Line_Item $ticket_line_item, $qty = 1 ) { |
|
355 | + public static function cancel_ticket_line_item(EE_Line_Item $ticket_line_item, $qty = 1) { |
|
356 | 356 | // validate incoming line_item |
357 | - if ( $ticket_line_item->OBJ_type() !== 'Ticket' ) { |
|
357 | + if ($ticket_line_item->OBJ_type() !== 'Ticket') { |
|
358 | 358 | throw new EE_Error( |
359 | 359 | sprintf( |
360 | - __( 'The supplied line item must have an Object Type of "Ticket", not %1$s.', 'event_espresso' ), |
|
360 | + __('The supplied line item must have an Object Type of "Ticket", not %1$s.', 'event_espresso'), |
|
361 | 361 | $ticket_line_item->type() |
362 | 362 | ) |
363 | 363 | ); |
364 | 364 | } |
365 | - if ( $ticket_line_item->quantity() < $qty ) { |
|
365 | + if ($ticket_line_item->quantity() < $qty) { |
|
366 | 366 | throw new EE_Error( |
367 | 367 | sprintf( |
368 | - __( 'Can not cancel %1$d ticket(s) because the supplied line item has a quantity of %2$d.', 'event_espresso' ), |
|
368 | + __('Can not cancel %1$d ticket(s) because the supplied line item has a quantity of %2$d.', 'event_espresso'), |
|
369 | 369 | $qty, |
370 | 370 | $ticket_line_item->quantity() |
371 | 371 | ) |
372 | 372 | ); |
373 | 373 | } |
374 | 374 | // decrement ticket quantity; don't rely on auto-fixing when recalculating totals to do this |
375 | - $ticket_line_item->set_quantity( $ticket_line_item->quantity() - $qty ); |
|
376 | - foreach( $ticket_line_item->children() as $child_line_item ) { |
|
377 | - if( |
|
375 | + $ticket_line_item->set_quantity($ticket_line_item->quantity() - $qty); |
|
376 | + foreach ($ticket_line_item->children() as $child_line_item) { |
|
377 | + if ( |
|
378 | 378 | $child_line_item->is_sub_line_item() |
379 | 379 | && ! $child_line_item->is_percent() |
380 | 380 | && ! $child_line_item->is_cancellation() |
381 | 381 | ) { |
382 | - $child_line_item->set_quantity( $child_line_item->quantity() - $qty ); |
|
382 | + $child_line_item->set_quantity($child_line_item->quantity() - $qty); |
|
383 | 383 | } |
384 | 384 | } |
385 | 385 | // get cancellation sub line item |
@@ -387,37 +387,37 @@ discard block |
||
387 | 387 | $ticket_line_item, |
388 | 388 | EEM_Line_Item::type_cancellation |
389 | 389 | ); |
390 | - $cancellation_line_item = reset( $cancellation_line_item ); |
|
390 | + $cancellation_line_item = reset($cancellation_line_item); |
|
391 | 391 | // verify that this ticket was indeed previously cancelled |
392 | - if ( $cancellation_line_item instanceof EE_Line_Item ) { |
|
392 | + if ($cancellation_line_item instanceof EE_Line_Item) { |
|
393 | 393 | // increment cancelled quantity |
394 | - $cancellation_line_item->set_quantity( $cancellation_line_item->quantity() + $qty ); |
|
394 | + $cancellation_line_item->set_quantity($cancellation_line_item->quantity() + $qty); |
|
395 | 395 | } else { |
396 | 396 | // create cancellation sub line item |
397 | - $cancellation_line_item = EE_Line_Item::new_instance( array( |
|
398 | - 'LIN_name' => __( 'Cancellation', 'event_espresso' ), |
|
397 | + $cancellation_line_item = EE_Line_Item::new_instance(array( |
|
398 | + 'LIN_name' => __('Cancellation', 'event_espresso'), |
|
399 | 399 | 'LIN_desc' => sprintf( |
400 | - _x( 'Cancelled %1$s : %2$s', 'Cancelled Ticket Name : 2015-01-01 11:11', 'event_espresso' ), |
|
400 | + _x('Cancelled %1$s : %2$s', 'Cancelled Ticket Name : 2015-01-01 11:11', 'event_espresso'), |
|
401 | 401 | $ticket_line_item->name(), |
402 | - current_time( get_option( 'date_format' ) . ' ' . get_option( 'time_format' ) ) |
|
402 | + current_time(get_option('date_format').' '.get_option('time_format')) |
|
403 | 403 | ), |
404 | 404 | 'LIN_unit_price' => 0, // $ticket_line_item->unit_price() |
405 | 405 | 'LIN_quantity' => $qty, |
406 | 406 | 'LIN_is_taxable' => $ticket_line_item->is_taxable(), |
407 | - 'LIN_order' => count( $ticket_line_item->children() ), |
|
407 | + 'LIN_order' => count($ticket_line_item->children()), |
|
408 | 408 | 'LIN_total' => 0, // $ticket_line_item->unit_price() |
409 | 409 | 'LIN_type' => EEM_Line_Item::type_cancellation, |
410 | - ) ); |
|
411 | - $ticket_line_item->add_child_line_item( $cancellation_line_item ); |
|
410 | + )); |
|
411 | + $ticket_line_item->add_child_line_item($cancellation_line_item); |
|
412 | 412 | } |
413 | - if ( $ticket_line_item->save_this_and_descendants() > 0 ) { |
|
413 | + if ($ticket_line_item->save_this_and_descendants() > 0) { |
|
414 | 414 | // decrement parent line item quantity |
415 | 415 | $event_line_item = $ticket_line_item->parent(); |
416 | - if ( $event_line_item instanceof EE_Line_Item && $event_line_item->OBJ_type() === 'Event' ) { |
|
417 | - $event_line_item->set_quantity( $event_line_item->quantity() - $qty ); |
|
416 | + if ($event_line_item instanceof EE_Line_Item && $event_line_item->OBJ_type() === 'Event') { |
|
417 | + $event_line_item->set_quantity($event_line_item->quantity() - $qty); |
|
418 | 418 | $event_line_item->save(); |
419 | 419 | } |
420 | - EEH_Line_Item::get_grand_total_and_recalculate_everything( $ticket_line_item ); |
|
420 | + EEH_Line_Item::get_grand_total_and_recalculate_everything($ticket_line_item); |
|
421 | 421 | return true; |
422 | 422 | } |
423 | 423 | return false; |
@@ -435,12 +435,12 @@ discard block |
||
435 | 435 | * @return bool success |
436 | 436 | * @throws \EE_Error |
437 | 437 | */ |
438 | - public static function reinstate_canceled_ticket_line_item( EE_Line_Item $ticket_line_item, $qty = 1 ) { |
|
438 | + public static function reinstate_canceled_ticket_line_item(EE_Line_Item $ticket_line_item, $qty = 1) { |
|
439 | 439 | // validate incoming line_item |
440 | - if ( $ticket_line_item->OBJ_type() !== 'Ticket' ) { |
|
440 | + if ($ticket_line_item->OBJ_type() !== 'Ticket') { |
|
441 | 441 | throw new EE_Error( |
442 | 442 | sprintf( |
443 | - __( 'The supplied line item must have an Object Type of "Ticket", not %1$s.', 'event_espresso' ), |
|
443 | + __('The supplied line item must have an Object Type of "Ticket", not %1$s.', 'event_espresso'), |
|
444 | 444 | $ticket_line_item->type() |
445 | 445 | ) |
446 | 446 | ); |
@@ -450,42 +450,42 @@ discard block |
||
450 | 450 | $ticket_line_item, |
451 | 451 | EEM_Line_Item::type_cancellation |
452 | 452 | ); |
453 | - $cancellation_line_item = reset( $cancellation_line_item ); |
|
453 | + $cancellation_line_item = reset($cancellation_line_item); |
|
454 | 454 | // verify that this ticket was indeed previously cancelled |
455 | - if ( ! $cancellation_line_item instanceof EE_Line_Item ) { |
|
455 | + if ( ! $cancellation_line_item instanceof EE_Line_Item) { |
|
456 | 456 | return false; |
457 | 457 | } |
458 | - if ( $cancellation_line_item->quantity() > $qty ) { |
|
458 | + if ($cancellation_line_item->quantity() > $qty) { |
|
459 | 459 | // decrement cancelled quantity |
460 | - $cancellation_line_item->set_quantity( $cancellation_line_item->quantity() - $qty ); |
|
461 | - } else if ( $cancellation_line_item->quantity() == $qty ) { |
|
460 | + $cancellation_line_item->set_quantity($cancellation_line_item->quantity() - $qty); |
|
461 | + } else if ($cancellation_line_item->quantity() == $qty) { |
|
462 | 462 | // decrement cancelled quantity in case anyone still has the object kicking around |
463 | - $cancellation_line_item->set_quantity( $cancellation_line_item->quantity() - $qty ); |
|
463 | + $cancellation_line_item->set_quantity($cancellation_line_item->quantity() - $qty); |
|
464 | 464 | // delete because quantity will end up as 0 |
465 | 465 | $cancellation_line_item->delete(); |
466 | 466 | // and attempt to destroy the object, |
467 | 467 | // even though PHP won't actually destroy it until it needs the memory |
468 | - unset( $cancellation_line_item ); |
|
468 | + unset($cancellation_line_item); |
|
469 | 469 | } else { |
470 | 470 | // what ?!?! negative quantity ?!?! |
471 | 471 | throw new EE_Error( |
472 | 472 | sprintf( |
473 | - __( 'Can not reinstate %1$d cancelled ticket(s) because the cancelled ticket quantity is only %2$d.', |
|
474 | - 'event_espresso' ), |
|
473 | + __('Can not reinstate %1$d cancelled ticket(s) because the cancelled ticket quantity is only %2$d.', |
|
474 | + 'event_espresso'), |
|
475 | 475 | $qty, |
476 | 476 | $cancellation_line_item->quantity() |
477 | 477 | ) |
478 | 478 | ); |
479 | 479 | } |
480 | 480 | // increment ticket quantity |
481 | - $ticket_line_item->set_quantity( $ticket_line_item->quantity() + $qty ); |
|
482 | - if ( $ticket_line_item->save_this_and_descendants() > 0 ) { |
|
481 | + $ticket_line_item->set_quantity($ticket_line_item->quantity() + $qty); |
|
482 | + if ($ticket_line_item->save_this_and_descendants() > 0) { |
|
483 | 483 | // increment parent line item quantity |
484 | 484 | $event_line_item = $ticket_line_item->parent(); |
485 | - if ( $event_line_item instanceof EE_Line_Item && $event_line_item->OBJ_type() === 'Event' ) { |
|
486 | - $event_line_item->set_quantity( $event_line_item->quantity() + $qty ); |
|
485 | + if ($event_line_item instanceof EE_Line_Item && $event_line_item->OBJ_type() === 'Event') { |
|
486 | + $event_line_item->set_quantity($event_line_item->quantity() + $qty); |
|
487 | 487 | } |
488 | - EEH_Line_Item::get_grand_total_and_recalculate_everything( $ticket_line_item ); |
|
488 | + EEH_Line_Item::get_grand_total_and_recalculate_everything($ticket_line_item); |
|
489 | 489 | return true; |
490 | 490 | } |
491 | 491 | return false; |
@@ -500,8 +500,8 @@ discard block |
||
500 | 500 | * @param EE_Line_Item $line_item |
501 | 501 | * @return \EE_Line_Item |
502 | 502 | */ |
503 | - public static function get_grand_total_and_recalculate_everything( EE_Line_Item $line_item ){ |
|
504 | - $grand_total_line_item = EEH_Line_Item::find_transaction_grand_total_for_line_item( $line_item ); |
|
503 | + public static function get_grand_total_and_recalculate_everything(EE_Line_Item $line_item) { |
|
504 | + $grand_total_line_item = EEH_Line_Item::find_transaction_grand_total_for_line_item($line_item); |
|
505 | 505 | return $grand_total_line_item->recalculate_total_including_taxes(); |
506 | 506 | } |
507 | 507 | |
@@ -514,11 +514,11 @@ discard block |
||
514 | 514 | * @return \EE_Line_Item |
515 | 515 | * @throws \EE_Error |
516 | 516 | */ |
517 | - public static function get_pre_tax_subtotal( EE_Line_Item $total_line_item ){ |
|
518 | - $pre_tax_subtotal = $total_line_item->get_child_line_item( 'pre-tax-subtotal' ); |
|
517 | + public static function get_pre_tax_subtotal(EE_Line_Item $total_line_item) { |
|
518 | + $pre_tax_subtotal = $total_line_item->get_child_line_item('pre-tax-subtotal'); |
|
519 | 519 | return $pre_tax_subtotal instanceof EE_Line_Item |
520 | 520 | ? $pre_tax_subtotal |
521 | - : self::create_pre_tax_subtotal( $total_line_item ); |
|
521 | + : self::create_pre_tax_subtotal($total_line_item); |
|
522 | 522 | } |
523 | 523 | |
524 | 524 | |
@@ -530,9 +530,9 @@ discard block |
||
530 | 530 | * @return \EE_Line_Item |
531 | 531 | * @throws \EE_Error |
532 | 532 | */ |
533 | - public static function get_taxes_subtotal( EE_Line_Item $total_line_item ){ |
|
534 | - $taxes = $total_line_item->get_child_line_item( 'taxes' ); |
|
535 | - return $taxes ? $taxes : self::create_taxes_subtotal( $total_line_item ); |
|
533 | + public static function get_taxes_subtotal(EE_Line_Item $total_line_item) { |
|
534 | + $taxes = $total_line_item->get_child_line_item('taxes'); |
|
535 | + return $taxes ? $taxes : self::create_taxes_subtotal($total_line_item); |
|
536 | 536 | } |
537 | 537 | |
538 | 538 | |
@@ -545,12 +545,12 @@ discard block |
||
545 | 545 | * @return void |
546 | 546 | * @throws \EE_Error |
547 | 547 | */ |
548 | - public static function set_TXN_ID( EE_Line_Item $line_item, $transaction = NULL ){ |
|
549 | - if( $transaction ){ |
|
548 | + public static function set_TXN_ID(EE_Line_Item $line_item, $transaction = NULL) { |
|
549 | + if ($transaction) { |
|
550 | 550 | /** @type EEM_Transaction $EEM_Transaction */ |
551 | - $EEM_Transaction = EE_Registry::instance()->load_model( 'Transaction' ); |
|
552 | - $TXN_ID = $EEM_Transaction->ensure_is_ID( $transaction ); |
|
553 | - $line_item->set_TXN_ID( $TXN_ID ); |
|
551 | + $EEM_Transaction = EE_Registry::instance()->load_model('Transaction'); |
|
552 | + $TXN_ID = $EEM_Transaction->ensure_is_ID($transaction); |
|
553 | + $line_item->set_TXN_ID($TXN_ID); |
|
554 | 554 | } |
555 | 555 | } |
556 | 556 | |
@@ -565,8 +565,8 @@ discard block |
||
565 | 565 | * @return \EE_Line_Item of type total |
566 | 566 | * @throws \EE_Error |
567 | 567 | */ |
568 | - public static function create_total_line_item( $transaction = NULL ){ |
|
569 | - $total_line_item = EE_Line_Item::new_instance( array( |
|
568 | + public static function create_total_line_item($transaction = NULL) { |
|
569 | + $total_line_item = EE_Line_Item::new_instance(array( |
|
570 | 570 | 'LIN_code' => 'total', |
571 | 571 | 'LIN_name' => __('Grand Total', 'event_espresso'), |
572 | 572 | 'LIN_type' => EEM_Line_Item::type_total, |
@@ -576,9 +576,9 @@ discard block |
||
576 | 576 | 'FHEE__EEH_Line_Item__create_total_line_item__total_line_item', |
577 | 577 | $total_line_item |
578 | 578 | ); |
579 | - self::set_TXN_ID( $total_line_item, $transaction ); |
|
580 | - self::create_pre_tax_subtotal( $total_line_item, $transaction ); |
|
581 | - self::create_taxes_subtotal( $total_line_item, $transaction ); |
|
579 | + self::set_TXN_ID($total_line_item, $transaction); |
|
580 | + self::create_pre_tax_subtotal($total_line_item, $transaction); |
|
581 | + self::create_taxes_subtotal($total_line_item, $transaction); |
|
582 | 582 | return $total_line_item; |
583 | 583 | } |
584 | 584 | |
@@ -592,19 +592,19 @@ discard block |
||
592 | 592 | * @return EE_Line_Item |
593 | 593 | * @throws \EE_Error |
594 | 594 | */ |
595 | - protected static function create_pre_tax_subtotal( EE_Line_Item $total_line_item, $transaction = NULL ){ |
|
596 | - $pre_tax_line_item = EE_Line_Item::new_instance( array( |
|
595 | + protected static function create_pre_tax_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
596 | + $pre_tax_line_item = EE_Line_Item::new_instance(array( |
|
597 | 597 | 'LIN_code' => 'pre-tax-subtotal', |
598 | - 'LIN_name' => __( 'Pre-Tax Subtotal', 'event_espresso' ), |
|
598 | + 'LIN_name' => __('Pre-Tax Subtotal', 'event_espresso'), |
|
599 | 599 | 'LIN_type' => EEM_Line_Item::type_sub_total |
600 | - ) ); |
|
600 | + )); |
|
601 | 601 | $pre_tax_line_item = apply_filters( |
602 | 602 | 'FHEE__EEH_Line_Item__create_pre_tax_subtotal__pre_tax_line_item', |
603 | 603 | $pre_tax_line_item |
604 | 604 | ); |
605 | - self::set_TXN_ID( $pre_tax_line_item, $transaction ); |
|
606 | - $total_line_item->add_child_line_item( $pre_tax_line_item ); |
|
607 | - self::create_event_subtotal( $pre_tax_line_item, $transaction ); |
|
605 | + self::set_TXN_ID($pre_tax_line_item, $transaction); |
|
606 | + $total_line_item->add_child_line_item($pre_tax_line_item); |
|
607 | + self::create_event_subtotal($pre_tax_line_item, $transaction); |
|
608 | 608 | return $pre_tax_line_item; |
609 | 609 | } |
610 | 610 | |
@@ -619,21 +619,21 @@ discard block |
||
619 | 619 | * @return EE_Line_Item |
620 | 620 | * @throws \EE_Error |
621 | 621 | */ |
622 | - protected static function create_taxes_subtotal( EE_Line_Item $total_line_item, $transaction = NULL ){ |
|
622 | + protected static function create_taxes_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
623 | 623 | $tax_line_item = EE_Line_Item::new_instance(array( |
624 | 624 | 'LIN_code' => 'taxes', |
625 | 625 | 'LIN_name' => __('Taxes', 'event_espresso'), |
626 | 626 | 'LIN_type' => EEM_Line_Item::type_tax_sub_total, |
627 | - 'LIN_order' => 1000,//this should always come last |
|
627 | + 'LIN_order' => 1000, //this should always come last |
|
628 | 628 | )); |
629 | 629 | $tax_line_item = apply_filters( |
630 | 630 | 'FHEE__EEH_Line_Item__create_taxes_subtotal__tax_line_item', |
631 | 631 | $tax_line_item |
632 | 632 | ); |
633 | - self::set_TXN_ID( $tax_line_item, $transaction ); |
|
634 | - $total_line_item->add_child_line_item( $tax_line_item ); |
|
633 | + self::set_TXN_ID($tax_line_item, $transaction); |
|
634 | + $total_line_item->add_child_line_item($tax_line_item); |
|
635 | 635 | //and lastly, add the actual taxes |
636 | - self::apply_taxes( $total_line_item ); |
|
636 | + self::apply_taxes($total_line_item); |
|
637 | 637 | return $tax_line_item; |
638 | 638 | } |
639 | 639 | |
@@ -648,11 +648,11 @@ discard block |
||
648 | 648 | * @return EE_Line_Item |
649 | 649 | * @throws \EE_Error |
650 | 650 | */ |
651 | - public static function create_event_subtotal( EE_Line_Item $pre_tax_line_item, $transaction = NULL, $event = NULL ){ |
|
651 | + public static function create_event_subtotal(EE_Line_Item $pre_tax_line_item, $transaction = NULL, $event = NULL) { |
|
652 | 652 | $event_line_item = EE_Line_Item::new_instance(array( |
653 | - 'LIN_code' => self::get_event_code( $event ), |
|
654 | - 'LIN_name' => self::get_event_name( $event ), |
|
655 | - 'LIN_desc' => self::get_event_desc( $event ), |
|
653 | + 'LIN_code' => self::get_event_code($event), |
|
654 | + 'LIN_name' => self::get_event_name($event), |
|
655 | + 'LIN_desc' => self::get_event_desc($event), |
|
656 | 656 | 'LIN_type' => EEM_Line_Item::type_sub_total, |
657 | 657 | 'OBJ_type' => 'Event', |
658 | 658 | 'OBJ_ID' => $event instanceof EE_Event ? $event->ID() : 0 |
@@ -661,8 +661,8 @@ discard block |
||
661 | 661 | 'FHEE__EEH_Line_Item__create_event_subtotal__event_line_item', |
662 | 662 | $event_line_item |
663 | 663 | ); |
664 | - self::set_TXN_ID( $event_line_item, $transaction ); |
|
665 | - $pre_tax_line_item->add_child_line_item( $event_line_item ); |
|
664 | + self::set_TXN_ID($event_line_item, $transaction); |
|
665 | + $pre_tax_line_item->add_child_line_item($event_line_item); |
|
666 | 666 | return $event_line_item; |
667 | 667 | } |
668 | 668 | |
@@ -675,8 +675,8 @@ discard block |
||
675 | 675 | * @return string |
676 | 676 | * @throws \EE_Error |
677 | 677 | */ |
678 | - public static function get_event_code( $event ) { |
|
679 | - return 'event-' . ( $event instanceof EE_Event ? $event->ID() : '0' ); |
|
678 | + public static function get_event_code($event) { |
|
679 | + return 'event-'.($event instanceof EE_Event ? $event->ID() : '0'); |
|
680 | 680 | } |
681 | 681 | |
682 | 682 | /** |
@@ -684,8 +684,8 @@ discard block |
||
684 | 684 | * @param EE_Event $event |
685 | 685 | * @return string |
686 | 686 | */ |
687 | - public static function get_event_name( $event ) { |
|
688 | - return $event instanceof EE_Event ? $event->name() : __( 'Event', 'event_espresso' ); |
|
687 | + public static function get_event_name($event) { |
|
688 | + return $event instanceof EE_Event ? $event->name() : __('Event', 'event_espresso'); |
|
689 | 689 | } |
690 | 690 | |
691 | 691 | /** |
@@ -693,7 +693,7 @@ discard block |
||
693 | 693 | * @param EE_Event $event |
694 | 694 | * @return string |
695 | 695 | */ |
696 | - public static function get_event_desc( $event ) { |
|
696 | + public static function get_event_desc($event) { |
|
697 | 697 | return $event instanceof EE_Event ? $event->short_description() : ''; |
698 | 698 | } |
699 | 699 | |
@@ -707,27 +707,27 @@ discard block |
||
707 | 707 | * @throws \EE_Error |
708 | 708 | * @return EE_Line_Item |
709 | 709 | */ |
710 | - public static function get_event_line_item_for_ticket( EE_Line_Item $grand_total, EE_Ticket $ticket ) { |
|
710 | + public static function get_event_line_item_for_ticket(EE_Line_Item $grand_total, EE_Ticket $ticket) { |
|
711 | 711 | $first_datetime = $ticket->first_datetime(); |
712 | - if ( ! $first_datetime instanceof EE_Datetime ) { |
|
712 | + if ( ! $first_datetime instanceof EE_Datetime) { |
|
713 | 713 | throw new EE_Error( |
714 | - sprintf( __( 'The supplied ticket (ID %d) has no datetimes', 'event_espresso' ), $ticket->ID() ) |
|
714 | + sprintf(__('The supplied ticket (ID %d) has no datetimes', 'event_espresso'), $ticket->ID()) |
|
715 | 715 | ); |
716 | 716 | } |
717 | 717 | $event = $first_datetime->event(); |
718 | - if ( ! $event instanceof EE_Event ) { |
|
718 | + if ( ! $event instanceof EE_Event) { |
|
719 | 719 | throw new EE_Error( |
720 | 720 | sprintf( |
721 | - __( 'The supplied ticket (ID %d) has no event data associated with it.', 'event_espresso' ), |
|
721 | + __('The supplied ticket (ID %d) has no event data associated with it.', 'event_espresso'), |
|
722 | 722 | $ticket->ID() |
723 | 723 | ) |
724 | 724 | ); |
725 | 725 | } |
726 | - $events_sub_total = EEH_Line_Item::get_event_line_item( $grand_total, $event ); |
|
727 | - if ( ! $events_sub_total instanceof EE_Line_Item ) { |
|
726 | + $events_sub_total = EEH_Line_Item::get_event_line_item($grand_total, $event); |
|
727 | + if ( ! $events_sub_total instanceof EE_Line_Item) { |
|
728 | 728 | throw new EE_Error( |
729 | 729 | sprintf( |
730 | - __( 'There is no events sub-total for ticket %s on total line item %d', 'event_espresso' ), |
|
730 | + __('There is no events sub-total for ticket %s on total line item %d', 'event_espresso'), |
|
731 | 731 | $ticket->ID(), |
732 | 732 | $grand_total->ID() |
733 | 733 | ) |
@@ -746,31 +746,31 @@ discard block |
||
746 | 746 | * @return EE_Line_Item for the event subtotal which is a child of $grand_total |
747 | 747 | * @throws \EE_Error |
748 | 748 | */ |
749 | - public static function get_event_line_item( EE_Line_Item $grand_total, $event ) { |
|
749 | + public static function get_event_line_item(EE_Line_Item $grand_total, $event) { |
|
750 | 750 | /** @type EE_Event $event */ |
751 | - $event = EEM_Event::instance()->ensure_is_obj( $event, true ); |
|
751 | + $event = EEM_Event::instance()->ensure_is_obj($event, true); |
|
752 | 752 | $event_line_item = NULL; |
753 | 753 | $found = false; |
754 | - foreach ( EEH_Line_Item::get_event_subtotals( $grand_total ) as $event_line_item ) { |
|
754 | + foreach (EEH_Line_Item::get_event_subtotals($grand_total) as $event_line_item) { |
|
755 | 755 | // default event subtotal, we should only ever find this the first time this method is called |
756 | - if ( ! $event_line_item->OBJ_ID() ) { |
|
756 | + if ( ! $event_line_item->OBJ_ID()) { |
|
757 | 757 | // let's use this! but first... set the event details |
758 | - EEH_Line_Item::set_event_subtotal_details( $event_line_item, $event ); |
|
758 | + EEH_Line_Item::set_event_subtotal_details($event_line_item, $event); |
|
759 | 759 | $found = true; |
760 | 760 | break; |
761 | - } else if ( $event_line_item->OBJ_ID() === $event->ID() ) { |
|
761 | + } else if ($event_line_item->OBJ_ID() === $event->ID()) { |
|
762 | 762 | // found existing line item for this event in the cart, so break out of loop and use this one |
763 | 763 | $found = true; |
764 | 764 | break; |
765 | 765 | } |
766 | 766 | } |
767 | - if ( ! $found ) { |
|
767 | + if ( ! $found) { |
|
768 | 768 | //there is no event sub-total yet, so add it |
769 | - $pre_tax_subtotal = EEH_Line_Item::get_pre_tax_subtotal( $grand_total ); |
|
769 | + $pre_tax_subtotal = EEH_Line_Item::get_pre_tax_subtotal($grand_total); |
|
770 | 770 | // create a new "event" subtotal below that |
771 | - $event_line_item = EEH_Line_Item::create_event_subtotal( $pre_tax_subtotal, null, $event ); |
|
771 | + $event_line_item = EEH_Line_Item::create_event_subtotal($pre_tax_subtotal, null, $event); |
|
772 | 772 | // and set the event details |
773 | - EEH_Line_Item::set_event_subtotal_details( $event_line_item, $event ); |
|
773 | + EEH_Line_Item::set_event_subtotal_details($event_line_item, $event); |
|
774 | 774 | } |
775 | 775 | return $event_line_item; |
776 | 776 | } |
@@ -791,13 +791,13 @@ discard block |
||
791 | 791 | EE_Event $event, |
792 | 792 | $transaction = null |
793 | 793 | ) { |
794 | - if ( $event instanceof EE_Event ) { |
|
795 | - $event_line_item->set_code( self::get_event_code( $event ) ); |
|
796 | - $event_line_item->set_name( self::get_event_name( $event ) ); |
|
797 | - $event_line_item->set_desc( self::get_event_desc( $event ) ); |
|
798 | - $event_line_item->set_OBJ_ID( $event->ID() ); |
|
794 | + if ($event instanceof EE_Event) { |
|
795 | + $event_line_item->set_code(self::get_event_code($event)); |
|
796 | + $event_line_item->set_name(self::get_event_name($event)); |
|
797 | + $event_line_item->set_desc(self::get_event_desc($event)); |
|
798 | + $event_line_item->set_OBJ_ID($event->ID()); |
|
799 | 799 | } |
800 | - self::set_TXN_ID( $event_line_item, $transaction ); |
|
800 | + self::set_TXN_ID($event_line_item, $transaction); |
|
801 | 801 | } |
802 | 802 | |
803 | 803 | |
@@ -810,19 +810,19 @@ discard block |
||
810 | 810 | * @param EE_Line_Item $total_line_item of type EEM_Line_Item::type_total |
811 | 811 | * @throws \EE_Error |
812 | 812 | */ |
813 | - public static function apply_taxes( EE_Line_Item $total_line_item ){ |
|
813 | + public static function apply_taxes(EE_Line_Item $total_line_item) { |
|
814 | 814 | /** @type EEM_Price $EEM_Price */ |
815 | - $EEM_Price = EE_Registry::instance()->load_model( 'Price' ); |
|
815 | + $EEM_Price = EE_Registry::instance()->load_model('Price'); |
|
816 | 816 | // get array of taxes via Price Model |
817 | 817 | $ordered_taxes = $EEM_Price->get_all_prices_that_are_taxes(); |
818 | - ksort( $ordered_taxes ); |
|
819 | - $taxes_line_item = self::get_taxes_subtotal( $total_line_item ); |
|
818 | + ksort($ordered_taxes); |
|
819 | + $taxes_line_item = self::get_taxes_subtotal($total_line_item); |
|
820 | 820 | //just to be safe, remove its old tax line items |
821 | 821 | $taxes_line_item->delete_children_line_items(); |
822 | 822 | //loop thru taxes |
823 | - foreach ( $ordered_taxes as $order => $taxes ) { |
|
824 | - foreach ( $taxes as $tax ) { |
|
825 | - if ( $tax instanceof EE_Price ) { |
|
823 | + foreach ($ordered_taxes as $order => $taxes) { |
|
824 | + foreach ($taxes as $tax) { |
|
825 | + if ($tax instanceof EE_Price) { |
|
826 | 826 | $tax_line_item = EE_Line_Item::new_instance( |
827 | 827 | array( |
828 | 828 | 'LIN_name' => $tax->name(), |
@@ -840,7 +840,7 @@ discard block |
||
840 | 840 | 'FHEE__EEH_Line_Item__apply_taxes__tax_line_item', |
841 | 841 | $tax_line_item |
842 | 842 | ); |
843 | - $taxes_line_item->add_child_line_item( $tax_line_item ); |
|
843 | + $taxes_line_item->add_child_line_item($tax_line_item); |
|
844 | 844 | } |
845 | 845 | } |
846 | 846 | } |
@@ -857,10 +857,10 @@ discard block |
||
857 | 857 | * @return float |
858 | 858 | * @throws \EE_Error |
859 | 859 | */ |
860 | - public static function ensure_taxes_applied( $total_line_item ){ |
|
861 | - $taxes_subtotal = self::get_taxes_subtotal( $total_line_item ); |
|
862 | - if( ! $taxes_subtotal->children()){ |
|
863 | - self::apply_taxes( $total_line_item ); |
|
860 | + public static function ensure_taxes_applied($total_line_item) { |
|
861 | + $taxes_subtotal = self::get_taxes_subtotal($total_line_item); |
|
862 | + if ( ! $taxes_subtotal->children()) { |
|
863 | + self::apply_taxes($total_line_item); |
|
864 | 864 | } |
865 | 865 | return $taxes_subtotal->total(); |
866 | 866 | } |
@@ -874,16 +874,16 @@ discard block |
||
874 | 874 | * @return bool |
875 | 875 | * @throws \EE_Error |
876 | 876 | */ |
877 | - public static function delete_all_child_items( EE_Line_Item $parent_line_item ) { |
|
877 | + public static function delete_all_child_items(EE_Line_Item $parent_line_item) { |
|
878 | 878 | $deleted = 0; |
879 | - foreach ( $parent_line_item->children() as $child_line_item ) { |
|
880 | - if ( $child_line_item instanceof EE_Line_Item ) { |
|
881 | - $deleted += EEH_Line_Item::delete_all_child_items( $child_line_item ); |
|
882 | - if ( $child_line_item->ID() ) { |
|
879 | + foreach ($parent_line_item->children() as $child_line_item) { |
|
880 | + if ($child_line_item instanceof EE_Line_Item) { |
|
881 | + $deleted += EEH_Line_Item::delete_all_child_items($child_line_item); |
|
882 | + if ($child_line_item->ID()) { |
|
883 | 883 | $child_line_item->delete(); |
884 | - unset( $child_line_item ); |
|
884 | + unset($child_line_item); |
|
885 | 885 | } else { |
886 | - $parent_line_item->delete_child_line_item( $child_line_item->code() ); |
|
886 | + $parent_line_item->delete_child_line_item($child_line_item->code()); |
|
887 | 887 | } |
888 | 888 | $deleted++; |
889 | 889 | } |
@@ -905,9 +905,9 @@ discard block |
||
905 | 905 | * @param array|bool|string $line_item_codes |
906 | 906 | * @return int number of items successfully removed |
907 | 907 | */ |
908 | - public static function delete_items( EE_Line_Item $total_line_item, $line_item_codes = FALSE ) { |
|
908 | + public static function delete_items(EE_Line_Item $total_line_item, $line_item_codes = FALSE) { |
|
909 | 909 | |
910 | - if( $total_line_item->type() !== EEM_Line_Item::type_total ){ |
|
910 | + if ($total_line_item->type() !== EEM_Line_Item::type_total) { |
|
911 | 911 | EE_Error::doing_it_wrong( |
912 | 912 | 'EEH_Line_Item::delete_items', |
913 | 913 | __( |
@@ -917,20 +917,20 @@ discard block |
||
917 | 917 | '4.6.18' |
918 | 918 | ); |
919 | 919 | } |
920 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
920 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
921 | 921 | |
922 | 922 | // check if only a single line_item_id was passed |
923 | - if ( ! empty( $line_item_codes ) && ! is_array( $line_item_codes )) { |
|
923 | + if ( ! empty($line_item_codes) && ! is_array($line_item_codes)) { |
|
924 | 924 | // place single line_item_id in an array to appear as multiple line_item_ids |
925 | - $line_item_codes = array ( $line_item_codes ); |
|
925 | + $line_item_codes = array($line_item_codes); |
|
926 | 926 | } |
927 | 927 | $removals = 0; |
928 | 928 | // cycle thru line_item_ids |
929 | - foreach ( $line_item_codes as $line_item_id ) { |
|
929 | + foreach ($line_item_codes as $line_item_id) { |
|
930 | 930 | $removals += $total_line_item->delete_child_line_item($line_item_id); |
931 | 931 | } |
932 | 932 | |
933 | - if ( $removals > 0 ) { |
|
933 | + if ($removals > 0) { |
|
934 | 934 | $total_line_item->recalculate_taxes_and_tax_total(); |
935 | 935 | return $removals; |
936 | 936 | } else { |
@@ -963,33 +963,33 @@ discard block |
||
963 | 963 | $code = null, |
964 | 964 | $add_to_existing_line_item = false |
965 | 965 | ) { |
966 | - $tax_subtotal = self::get_taxes_subtotal( $total_line_item ); |
|
966 | + $tax_subtotal = self::get_taxes_subtotal($total_line_item); |
|
967 | 967 | $taxable_total = $total_line_item->taxable_total(); |
968 | 968 | |
969 | - if( $add_to_existing_line_item ) { |
|
970 | - $new_tax = $tax_subtotal->get_child_line_item( $code ); |
|
969 | + if ($add_to_existing_line_item) { |
|
970 | + $new_tax = $tax_subtotal->get_child_line_item($code); |
|
971 | 971 | EEM_Line_Item::instance()->delete( |
972 | - array( array( 'LIN_code' => array( '!=', $code ), 'LIN_parent' => $tax_subtotal->ID() ) ) |
|
972 | + array(array('LIN_code' => array('!=', $code), 'LIN_parent' => $tax_subtotal->ID())) |
|
973 | 973 | ); |
974 | 974 | } else { |
975 | 975 | $new_tax = null; |
976 | 976 | $tax_subtotal->delete_children_line_items(); |
977 | 977 | } |
978 | - if( $new_tax ) { |
|
979 | - $new_tax->set_total( $new_tax->total() + $amount ); |
|
980 | - $new_tax->set_percent( $taxable_total ? $new_tax->total() / $taxable_total * 100 : 0 ); |
|
978 | + if ($new_tax) { |
|
979 | + $new_tax->set_total($new_tax->total() + $amount); |
|
980 | + $new_tax->set_percent($taxable_total ? $new_tax->total() / $taxable_total * 100 : 0); |
|
981 | 981 | } else { |
982 | 982 | //no existing tax item. Create it |
983 | - $new_tax = EE_Line_Item::new_instance( array( |
|
983 | + $new_tax = EE_Line_Item::new_instance(array( |
|
984 | 984 | 'TXN_ID' => $total_line_item->TXN_ID(), |
985 | - 'LIN_name' => $name ? $name : __( 'Tax', 'event_espresso' ), |
|
985 | + 'LIN_name' => $name ? $name : __('Tax', 'event_espresso'), |
|
986 | 986 | 'LIN_desc' => $description ? $description : '', |
987 | - 'LIN_percent' => $taxable_total ? ( $amount / $taxable_total * 100 ) : 0, |
|
987 | + 'LIN_percent' => $taxable_total ? ($amount / $taxable_total * 100) : 0, |
|
988 | 988 | 'LIN_total' => $amount, |
989 | 989 | 'LIN_parent' => $tax_subtotal->ID(), |
990 | 990 | 'LIN_type' => EEM_Line_Item::type_tax, |
991 | 991 | 'LIN_code' => $code |
992 | - ) ); |
|
992 | + )); |
|
993 | 993 | } |
994 | 994 | |
995 | 995 | $new_tax = apply_filters( |
@@ -998,7 +998,7 @@ discard block |
||
998 | 998 | $total_line_item |
999 | 999 | ); |
1000 | 1000 | $new_tax->save(); |
1001 | - $tax_subtotal->set_total( $new_tax->total() ); |
|
1001 | + $tax_subtotal->set_total($new_tax->total()); |
|
1002 | 1002 | $tax_subtotal->save(); |
1003 | 1003 | $total_line_item->recalculate_total_including_taxes(); |
1004 | 1004 | return $new_tax; |
@@ -1020,14 +1020,14 @@ discard block |
||
1020 | 1020 | $code_substring_for_whitelist = null |
1021 | 1021 | ) { |
1022 | 1022 | $whitelisted = false; |
1023 | - if( $code_substring_for_whitelist !== null ) { |
|
1024 | - $whitelisted = strpos( $line_item->code(), $code_substring_for_whitelist ) !== false ? true : false; |
|
1023 | + if ($code_substring_for_whitelist !== null) { |
|
1024 | + $whitelisted = strpos($line_item->code(), $code_substring_for_whitelist) !== false ? true : false; |
|
1025 | 1025 | } |
1026 | - if( ! $whitelisted && $line_item->is_line_item() ) { |
|
1027 | - $line_item->set_is_taxable( $taxable ); |
|
1026 | + if ( ! $whitelisted && $line_item->is_line_item()) { |
|
1027 | + $line_item->set_is_taxable($taxable); |
|
1028 | 1028 | } |
1029 | - foreach( $line_item->children() as $child_line_item ) { |
|
1030 | - EEH_Line_Item::set_line_items_taxable( $child_line_item, $taxable, $code_substring_for_whitelist ); |
|
1029 | + foreach ($line_item->children() as $child_line_item) { |
|
1030 | + EEH_Line_Item::set_line_items_taxable($child_line_item, $taxable, $code_substring_for_whitelist); |
|
1031 | 1031 | } |
1032 | 1032 | } |
1033 | 1033 | |
@@ -1040,8 +1040,8 @@ discard block |
||
1040 | 1040 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
1041 | 1041 | * @return EE_Line_Item[] |
1042 | 1042 | */ |
1043 | - public static function get_event_subtotals( EE_Line_Item $parent_line_item ) { |
|
1044 | - return self::get_subtotals_of_object_type( $parent_line_item, 'Event' ); |
|
1043 | + public static function get_event_subtotals(EE_Line_Item $parent_line_item) { |
|
1044 | + return self::get_subtotals_of_object_type($parent_line_item, 'Event'); |
|
1045 | 1045 | } |
1046 | 1046 | |
1047 | 1047 | |
@@ -1054,7 +1054,7 @@ discard block |
||
1054 | 1054 | * @param string $obj_type |
1055 | 1055 | * @return EE_Line_Item[] |
1056 | 1056 | */ |
1057 | - public static function get_subtotals_of_object_type( EE_Line_Item $parent_line_item, $obj_type = '' ) { |
|
1057 | + public static function get_subtotals_of_object_type(EE_Line_Item $parent_line_item, $obj_type = '') { |
|
1058 | 1058 | return self::_get_descendants_by_type_and_object_type( |
1059 | 1059 | $parent_line_item, |
1060 | 1060 | EEM_Line_Item::type_sub_total, |
@@ -1071,8 +1071,8 @@ discard block |
||
1071 | 1071 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
1072 | 1072 | * @return EE_Line_Item[] |
1073 | 1073 | */ |
1074 | - public static function get_ticket_line_items( EE_Line_Item $parent_line_item ) { |
|
1075 | - return self::get_line_items_of_object_type( $parent_line_item, 'Ticket' ); |
|
1074 | + public static function get_ticket_line_items(EE_Line_Item $parent_line_item) { |
|
1075 | + return self::get_line_items_of_object_type($parent_line_item, 'Ticket'); |
|
1076 | 1076 | } |
1077 | 1077 | |
1078 | 1078 | |
@@ -1085,8 +1085,8 @@ discard block |
||
1085 | 1085 | * @param string $obj_type |
1086 | 1086 | * @return EE_Line_Item[] |
1087 | 1087 | */ |
1088 | - public static function get_line_items_of_object_type( EE_Line_Item $parent_line_item, $obj_type = '' ) { |
|
1089 | - return self::_get_descendants_by_type_and_object_type( $parent_line_item, EEM_Line_Item::type_line_item, $obj_type ); |
|
1088 | + public static function get_line_items_of_object_type(EE_Line_Item $parent_line_item, $obj_type = '') { |
|
1089 | + return self::_get_descendants_by_type_and_object_type($parent_line_item, EEM_Line_Item::type_line_item, $obj_type); |
|
1090 | 1090 | } |
1091 | 1091 | |
1092 | 1092 | |
@@ -1097,8 +1097,8 @@ discard block |
||
1097 | 1097 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
1098 | 1098 | * @return EE_Line_Item[] |
1099 | 1099 | */ |
1100 | - public static function get_tax_descendants( EE_Line_Item $parent_line_item ) { |
|
1101 | - return EEH_Line_Item::get_descendants_of_type( $parent_line_item, EEM_Line_Item::type_tax ); |
|
1100 | + public static function get_tax_descendants(EE_Line_Item $parent_line_item) { |
|
1101 | + return EEH_Line_Item::get_descendants_of_type($parent_line_item, EEM_Line_Item::type_tax); |
|
1102 | 1102 | } |
1103 | 1103 | |
1104 | 1104 | |
@@ -1109,8 +1109,8 @@ discard block |
||
1109 | 1109 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
1110 | 1110 | * @return EE_Line_Item[] |
1111 | 1111 | */ |
1112 | - public static function get_line_item_descendants( EE_Line_Item $parent_line_item ) { |
|
1113 | - return EEH_Line_Item::get_descendants_of_type( $parent_line_item, EEM_Line_Item::type_line_item ); |
|
1112 | + public static function get_line_item_descendants(EE_Line_Item $parent_line_item) { |
|
1113 | + return EEH_Line_Item::get_descendants_of_type($parent_line_item, EEM_Line_Item::type_line_item); |
|
1114 | 1114 | } |
1115 | 1115 | |
1116 | 1116 | |
@@ -1123,8 +1123,8 @@ discard block |
||
1123 | 1123 | * @param string $line_item_type one of the EEM_Line_Item constants |
1124 | 1124 | * @return EE_Line_Item[] |
1125 | 1125 | */ |
1126 | - public static function get_descendants_of_type( EE_Line_Item $parent_line_item, $line_item_type ) { |
|
1127 | - return self::_get_descendants_by_type_and_object_type( $parent_line_item, $line_item_type, NULL ); |
|
1126 | + public static function get_descendants_of_type(EE_Line_Item $parent_line_item, $line_item_type) { |
|
1127 | + return self::_get_descendants_by_type_and_object_type($parent_line_item, $line_item_type, NULL); |
|
1128 | 1128 | } |
1129 | 1129 | |
1130 | 1130 | |
@@ -1143,8 +1143,8 @@ discard block |
||
1143 | 1143 | $obj_type = null |
1144 | 1144 | ) { |
1145 | 1145 | $objects = array(); |
1146 | - foreach ( $parent_line_item->children() as $child_line_item ) { |
|
1147 | - if ( $child_line_item instanceof EE_Line_Item ) { |
|
1146 | + foreach ($parent_line_item->children() as $child_line_item) { |
|
1147 | + if ($child_line_item instanceof EE_Line_Item) { |
|
1148 | 1148 | if ( |
1149 | 1149 | $child_line_item->type() === $line_item_type |
1150 | 1150 | && ( |
@@ -1184,7 +1184,7 @@ discard block |
||
1184 | 1184 | $OBJ_type = '', |
1185 | 1185 | $OBJ_IDs = array() |
1186 | 1186 | ) { |
1187 | - return self::_get_descendants_by_object_type_and_object_ID( $parent_line_item, $OBJ_type, $OBJ_IDs ); |
|
1187 | + return self::_get_descendants_by_object_type_and_object_ID($parent_line_item, $OBJ_type, $OBJ_IDs); |
|
1188 | 1188 | } |
1189 | 1189 | |
1190 | 1190 | |
@@ -1203,12 +1203,12 @@ discard block |
||
1203 | 1203 | $OBJ_IDs |
1204 | 1204 | ) { |
1205 | 1205 | $objects = array(); |
1206 | - foreach ( $parent_line_item->children() as $child_line_item ) { |
|
1207 | - if ( $child_line_item instanceof EE_Line_Item ) { |
|
1206 | + foreach ($parent_line_item->children() as $child_line_item) { |
|
1207 | + if ($child_line_item instanceof EE_Line_Item) { |
|
1208 | 1208 | if ( |
1209 | - is_array( $OBJ_IDs ) |
|
1209 | + is_array($OBJ_IDs) |
|
1210 | 1210 | && $child_line_item->OBJ_type() === $OBJ_type |
1211 | - && in_array( $child_line_item->OBJ_ID(), $OBJ_IDs ) |
|
1211 | + && in_array($child_line_item->OBJ_ID(), $OBJ_IDs) |
|
1212 | 1212 | ) { |
1213 | 1213 | $objects[] = $child_line_item; |
1214 | 1214 | } else { |
@@ -1238,8 +1238,8 @@ discard block |
||
1238 | 1238 | * @param string $type like one of the EEM_Line_Item::type_* |
1239 | 1239 | * @return EE_Line_Item |
1240 | 1240 | */ |
1241 | - public static function get_nearest_descendant_of_type( EE_Line_Item $parent_line_item, $type ) { |
|
1242 | - return self::_get_nearest_descendant( $parent_line_item, 'LIN_type' , $type ); |
|
1241 | + public static function get_nearest_descendant_of_type(EE_Line_Item $parent_line_item, $type) { |
|
1242 | + return self::_get_nearest_descendant($parent_line_item, 'LIN_type', $type); |
|
1243 | 1243 | } |
1244 | 1244 | |
1245 | 1245 | |
@@ -1253,8 +1253,8 @@ discard block |
||
1253 | 1253 | * @param string $code any value used for LIN_code |
1254 | 1254 | * @return EE_Line_Item |
1255 | 1255 | */ |
1256 | - public static function get_nearest_descendant_having_code( EE_Line_Item $parent_line_item, $code ) { |
|
1257 | - return self::_get_nearest_descendant( $parent_line_item, 'LIN_code' , $code ); |
|
1256 | + public static function get_nearest_descendant_having_code(EE_Line_Item $parent_line_item, $code) { |
|
1257 | + return self::_get_nearest_descendant($parent_line_item, 'LIN_code', $code); |
|
1258 | 1258 | } |
1259 | 1259 | |
1260 | 1260 | |
@@ -1268,15 +1268,15 @@ discard block |
||
1268 | 1268 | * @param string $value any value stored in $search_field |
1269 | 1269 | * @return EE_Line_Item |
1270 | 1270 | */ |
1271 | - protected static function _get_nearest_descendant( EE_Line_Item $parent_line_item, $search_field, $value ) { |
|
1272 | - foreach( $parent_line_item->children() as $child ){ |
|
1273 | - if ( $child->get( $search_field ) == $value ){ |
|
1271 | + protected static function _get_nearest_descendant(EE_Line_Item $parent_line_item, $search_field, $value) { |
|
1272 | + foreach ($parent_line_item->children() as $child) { |
|
1273 | + if ($child->get($search_field) == $value) { |
|
1274 | 1274 | return $child; |
1275 | 1275 | } |
1276 | 1276 | } |
1277 | - foreach( $parent_line_item->children() as $child ){ |
|
1278 | - $descendant_found = self::_get_nearest_descendant( $child, $search_field, $value ); |
|
1279 | - if ( $descendant_found ){ |
|
1277 | + foreach ($parent_line_item->children() as $child) { |
|
1278 | + $descendant_found = self::_get_nearest_descendant($child, $search_field, $value); |
|
1279 | + if ($descendant_found) { |
|
1280 | 1280 | return $descendant_found; |
1281 | 1281 | } |
1282 | 1282 | } |
@@ -1293,24 +1293,24 @@ discard block |
||
1293 | 1293 | * @return \EE_Line_Item |
1294 | 1294 | * @throws \EE_Error |
1295 | 1295 | */ |
1296 | - public static function find_transaction_grand_total_for_line_item( EE_Line_Item $line_item ){ |
|
1297 | - if ( $line_item->TXN_ID() ) { |
|
1298 | - $total_line_item = $line_item->transaction()->total_line_item( false ); |
|
1299 | - if ( $total_line_item instanceof EE_Line_Item ) { |
|
1296 | + public static function find_transaction_grand_total_for_line_item(EE_Line_Item $line_item) { |
|
1297 | + if ($line_item->TXN_ID()) { |
|
1298 | + $total_line_item = $line_item->transaction()->total_line_item(false); |
|
1299 | + if ($total_line_item instanceof EE_Line_Item) { |
|
1300 | 1300 | return $total_line_item; |
1301 | 1301 | } |
1302 | 1302 | } else { |
1303 | 1303 | $line_item_parent = $line_item->parent(); |
1304 | - if ( $line_item_parent instanceof EE_Line_Item ) { |
|
1305 | - if ( $line_item_parent->is_total() ) { |
|
1304 | + if ($line_item_parent instanceof EE_Line_Item) { |
|
1305 | + if ($line_item_parent->is_total()) { |
|
1306 | 1306 | return $line_item_parent; |
1307 | 1307 | } |
1308 | - return EEH_Line_Item::find_transaction_grand_total_for_line_item( $line_item_parent ); |
|
1308 | + return EEH_Line_Item::find_transaction_grand_total_for_line_item($line_item_parent); |
|
1309 | 1309 | } |
1310 | 1310 | } |
1311 | 1311 | throw new EE_Error( |
1312 | 1312 | sprintf( |
1313 | - __( 'A valid grand total for line item %1$d was not found.', 'event_espresso' ), |
|
1313 | + __('A valid grand total for line item %1$d was not found.', 'event_espresso'), |
|
1314 | 1314 | $line_item->ID() |
1315 | 1315 | ) |
1316 | 1316 | ); |
@@ -1327,31 +1327,31 @@ discard block |
||
1327 | 1327 | * @return void |
1328 | 1328 | * @throws \EE_Error |
1329 | 1329 | */ |
1330 | - public static function visualize( EE_Line_Item $line_item, $indentation = 0 ){ |
|
1330 | + public static function visualize(EE_Line_Item $line_item, $indentation = 0) { |
|
1331 | 1331 | echo defined('EE_TESTS_DIR') ? "\n" : '<br />'; |
1332 | - if ( ! $indentation ) { |
|
1333 | - echo defined( 'EE_TESTS_DIR' ) ? "\n" : '<br />'; |
|
1332 | + if ( ! $indentation) { |
|
1333 | + echo defined('EE_TESTS_DIR') ? "\n" : '<br />'; |
|
1334 | 1334 | } |
1335 | - for( $i = 0; $i < $indentation; $i++ ){ |
|
1335 | + for ($i = 0; $i < $indentation; $i++) { |
|
1336 | 1336 | echo ". "; |
1337 | 1337 | } |
1338 | 1338 | $breakdown = ''; |
1339 | - if ( $line_item->is_line_item()){ |
|
1340 | - if ( $line_item->is_percent() ) { |
|
1339 | + if ($line_item->is_line_item()) { |
|
1340 | + if ($line_item->is_percent()) { |
|
1341 | 1341 | $breakdown = "{$line_item->percent()}%"; |
1342 | 1342 | } else { |
1343 | - $breakdown = '$' . "{$line_item->unit_price()} x {$line_item->quantity()}"; |
|
1343 | + $breakdown = '$'."{$line_item->unit_price()} x {$line_item->quantity()}"; |
|
1344 | 1344 | } |
1345 | 1345 | } |
1346 | - echo $line_item->name() . " [ ID:{$line_item->ID()} | qty:{$line_item->quantity()} ] {$line_item->type()} : " . '$' . "{$line_item->total()}"; |
|
1347 | - if ( $breakdown ) { |
|
1346 | + echo $line_item->name()." [ ID:{$line_item->ID()} | qty:{$line_item->quantity()} ] {$line_item->type()} : ".'$'."{$line_item->total()}"; |
|
1347 | + if ($breakdown) { |
|
1348 | 1348 | echo " ( {$breakdown} )"; |
1349 | 1349 | } |
1350 | - if( $line_item->is_taxable() ){ |
|
1350 | + if ($line_item->is_taxable()) { |
|
1351 | 1351 | echo " * taxable"; |
1352 | 1352 | } |
1353 | - if( $line_item->children() ){ |
|
1354 | - foreach($line_item->children() as $child){ |
|
1353 | + if ($line_item->children()) { |
|
1354 | + foreach ($line_item->children() as $child) { |
|
1355 | 1355 | self::visualize($child, $indentation + 1); |
1356 | 1356 | } |
1357 | 1357 | } |
@@ -1392,97 +1392,97 @@ discard block |
||
1392 | 1392 | * is theirs, which can be done with |
1393 | 1393 | * `EEM_Line_Item::instance()->get_line_item_for_registration( $registration );` |
1394 | 1394 | */ |
1395 | - public static function calculate_reg_final_prices_per_line_item( EE_Line_Item $line_item, $billable_ticket_quantities = array() ) { |
|
1395 | + public static function calculate_reg_final_prices_per_line_item(EE_Line_Item $line_item, $billable_ticket_quantities = array()) { |
|
1396 | 1396 | //init running grand total if not already |
1397 | - if ( ! isset( $running_totals[ 'total' ] ) ) { |
|
1398 | - $running_totals[ 'total' ] = 0; |
|
1397 | + if ( ! isset($running_totals['total'])) { |
|
1398 | + $running_totals['total'] = 0; |
|
1399 | 1399 | } |
1400 | - if( ! isset( $running_totals[ 'taxable' ] ) ) { |
|
1401 | - $running_totals[ 'taxable' ] = array( 'total' => 0 ); |
|
1400 | + if ( ! isset($running_totals['taxable'])) { |
|
1401 | + $running_totals['taxable'] = array('total' => 0); |
|
1402 | 1402 | } |
1403 | - foreach ( $line_item->children() as $child_line_item ) { |
|
1404 | - switch ( $child_line_item->type() ) { |
|
1403 | + foreach ($line_item->children() as $child_line_item) { |
|
1404 | + switch ($child_line_item->type()) { |
|
1405 | 1405 | |
1406 | 1406 | case EEM_Line_Item::type_sub_total : |
1407 | - $running_totals_from_subtotal = EEH_Line_Item::calculate_reg_final_prices_per_line_item( $child_line_item, $billable_ticket_quantities ); |
|
1407 | + $running_totals_from_subtotal = EEH_Line_Item::calculate_reg_final_prices_per_line_item($child_line_item, $billable_ticket_quantities); |
|
1408 | 1408 | //combine arrays but preserve numeric keys |
1409 | - $running_totals = array_replace_recursive( $running_totals_from_subtotal, $running_totals ); |
|
1410 | - $running_totals[ 'total' ] += $running_totals_from_subtotal[ 'total' ]; |
|
1411 | - $running_totals[ 'taxable'][ 'total' ] += $running_totals_from_subtotal[ 'taxable' ][ 'total' ]; |
|
1409 | + $running_totals = array_replace_recursive($running_totals_from_subtotal, $running_totals); |
|
1410 | + $running_totals['total'] += $running_totals_from_subtotal['total']; |
|
1411 | + $running_totals['taxable']['total'] += $running_totals_from_subtotal['taxable']['total']; |
|
1412 | 1412 | break; |
1413 | 1413 | |
1414 | 1414 | case EEM_Line_Item::type_tax_sub_total : |
1415 | 1415 | |
1416 | 1416 | //find how much the taxes percentage is |
1417 | - if ( $child_line_item->percent() !== 0 ) { |
|
1417 | + if ($child_line_item->percent() !== 0) { |
|
1418 | 1418 | $tax_percent_decimal = $child_line_item->percent() / 100; |
1419 | 1419 | } else { |
1420 | 1420 | $tax_percent_decimal = EE_Taxes::get_total_taxes_percentage() / 100; |
1421 | 1421 | } |
1422 | 1422 | //and apply to all the taxable totals, and add to the pretax totals |
1423 | - foreach ( $running_totals as $line_item_id => $this_running_total ) { |
|
1423 | + foreach ($running_totals as $line_item_id => $this_running_total) { |
|
1424 | 1424 | //"total" and "taxable" array key is an exception |
1425 | - if ( $line_item_id === 'taxable' ) { |
|
1425 | + if ($line_item_id === 'taxable') { |
|
1426 | 1426 | continue; |
1427 | 1427 | } |
1428 | - $taxable_total = $running_totals[ 'taxable' ][ $line_item_id ]; |
|
1429 | - $running_totals[ $line_item_id ] += ( $taxable_total * $tax_percent_decimal ); |
|
1428 | + $taxable_total = $running_totals['taxable'][$line_item_id]; |
|
1429 | + $running_totals[$line_item_id] += ($taxable_total * $tax_percent_decimal); |
|
1430 | 1430 | } |
1431 | 1431 | break; |
1432 | 1432 | |
1433 | 1433 | case EEM_Line_Item::type_line_item : |
1434 | 1434 | |
1435 | 1435 | // ticket line items or ???? |
1436 | - if ( $child_line_item->OBJ_type() === 'Ticket' ) { |
|
1436 | + if ($child_line_item->OBJ_type() === 'Ticket') { |
|
1437 | 1437 | // kk it's a ticket |
1438 | - if ( isset( $running_totals[ $child_line_item->ID() ] ) ) { |
|
1438 | + if (isset($running_totals[$child_line_item->ID()])) { |
|
1439 | 1439 | //huh? that shouldn't happen. |
1440 | - $running_totals[ 'total' ] += $child_line_item->total(); |
|
1440 | + $running_totals['total'] += $child_line_item->total(); |
|
1441 | 1441 | } else { |
1442 | 1442 | //its not in our running totals yet. great. |
1443 | - if ( $child_line_item->is_taxable() ) { |
|
1443 | + if ($child_line_item->is_taxable()) { |
|
1444 | 1444 | $taxable_amount = $child_line_item->unit_price(); |
1445 | 1445 | } else { |
1446 | 1446 | $taxable_amount = 0; |
1447 | 1447 | } |
1448 | 1448 | // are we only calculating totals for some tickets? |
1449 | - if ( isset( $billable_ticket_quantities[ $child_line_item->OBJ_ID() ] ) ) { |
|
1450 | - $quantity = $billable_ticket_quantities[ $child_line_item->OBJ_ID() ]; |
|
1451 | - $running_totals[ $child_line_item->ID() ] = $quantity |
|
1449 | + if (isset($billable_ticket_quantities[$child_line_item->OBJ_ID()])) { |
|
1450 | + $quantity = $billable_ticket_quantities[$child_line_item->OBJ_ID()]; |
|
1451 | + $running_totals[$child_line_item->ID()] = $quantity |
|
1452 | 1452 | ? $child_line_item->unit_price() |
1453 | 1453 | : 0; |
1454 | - $running_totals[ 'taxable' ][ $child_line_item->ID() ] = $quantity |
|
1454 | + $running_totals['taxable'][$child_line_item->ID()] = $quantity |
|
1455 | 1455 | ? $taxable_amount |
1456 | 1456 | : 0; |
1457 | 1457 | } else { |
1458 | 1458 | $quantity = $child_line_item->quantity(); |
1459 | - $running_totals[ $child_line_item->ID() ] = $child_line_item->unit_price(); |
|
1460 | - $running_totals[ 'taxable' ][ $child_line_item->ID() ] = $taxable_amount; |
|
1459 | + $running_totals[$child_line_item->ID()] = $child_line_item->unit_price(); |
|
1460 | + $running_totals['taxable'][$child_line_item->ID()] = $taxable_amount; |
|
1461 | 1461 | } |
1462 | - $running_totals[ 'taxable' ][ 'total' ] += $taxable_amount * $quantity; |
|
1463 | - $running_totals[ 'total' ] += $child_line_item->unit_price() * $quantity; |
|
1462 | + $running_totals['taxable']['total'] += $taxable_amount * $quantity; |
|
1463 | + $running_totals['total'] += $child_line_item->unit_price() * $quantity; |
|
1464 | 1464 | } |
1465 | 1465 | } else { |
1466 | 1466 | // it's some other type of item added to the cart |
1467 | 1467 | // it should affect the running totals |
1468 | 1468 | // basically we want to convert it into a PERCENT modifier. Because |
1469 | 1469 | // more clearly affect all registration's final price equally |
1470 | - $line_items_percent_of_running_total = $running_totals[ 'total' ] > 0 |
|
1471 | - ? ( $child_line_item->total() / $running_totals[ 'total' ] ) + 1 |
|
1470 | + $line_items_percent_of_running_total = $running_totals['total'] > 0 |
|
1471 | + ? ($child_line_item->total() / $running_totals['total']) + 1 |
|
1472 | 1472 | : 1; |
1473 | - foreach ( $running_totals as $line_item_id => $this_running_total ) { |
|
1473 | + foreach ($running_totals as $line_item_id => $this_running_total) { |
|
1474 | 1474 | //the "taxable" array key is an exception |
1475 | - if ( $line_item_id === 'taxable' ) { |
|
1475 | + if ($line_item_id === 'taxable') { |
|
1476 | 1476 | continue; |
1477 | 1477 | } |
1478 | 1478 | // update the running totals |
1479 | 1479 | // yes this actually even works for the running grand total! |
1480 | - $running_totals[ $line_item_id ] = |
|
1480 | + $running_totals[$line_item_id] = |
|
1481 | 1481 | $line_items_percent_of_running_total * $this_running_total; |
1482 | 1482 | |
1483 | - if ( $child_line_item->is_taxable() ) { |
|
1484 | - $running_totals[ 'taxable' ][ $line_item_id ] = |
|
1485 | - $line_items_percent_of_running_total * $running_totals[ 'taxable' ][ $line_item_id ]; |
|
1483 | + if ($child_line_item->is_taxable()) { |
|
1484 | + $running_totals['taxable'][$line_item_id] = |
|
1485 | + $line_items_percent_of_running_total * $running_totals['taxable'][$line_item_id]; |
|
1486 | 1486 | } |
1487 | 1487 | } |
1488 | 1488 | } |
@@ -1500,16 +1500,16 @@ discard block |
||
1500 | 1500 | * @return float | null |
1501 | 1501 | * @throws \OutOfRangeException |
1502 | 1502 | */ |
1503 | - public static function calculate_final_price_for_ticket_line_item( \EE_Line_Item $total_line_item, \EE_Line_Item $ticket_line_item ) { |
|
1503 | + public static function calculate_final_price_for_ticket_line_item(\EE_Line_Item $total_line_item, \EE_Line_Item $ticket_line_item) { |
|
1504 | 1504 | static $final_prices_per_ticket_line_item = array(); |
1505 | - if ( empty( $final_prices_per_ticket_line_item ) ) { |
|
1505 | + if (empty($final_prices_per_ticket_line_item)) { |
|
1506 | 1506 | $final_prices_per_ticket_line_item = \EEH_Line_Item::calculate_reg_final_prices_per_line_item( |
1507 | 1507 | $total_line_item |
1508 | 1508 | ); |
1509 | 1509 | } |
1510 | 1510 | //ok now find this new registration's final price |
1511 | - if ( isset( $final_prices_per_ticket_line_item[ $ticket_line_item->ID() ] ) ) { |
|
1512 | - return $final_prices_per_ticket_line_item[ $ticket_line_item->ID() ]; |
|
1511 | + if (isset($final_prices_per_ticket_line_item[$ticket_line_item->ID()])) { |
|
1512 | + return $final_prices_per_ticket_line_item[$ticket_line_item->ID()]; |
|
1513 | 1513 | } |
1514 | 1514 | $message = sprintf( |
1515 | 1515 | __( |
@@ -1518,10 +1518,10 @@ discard block |
||
1518 | 1518 | ), |
1519 | 1519 | $ticket_line_item->ID() |
1520 | 1520 | ); |
1521 | - if ( WP_DEBUG ) { |
|
1522 | - throw new \OutOfRangeException( $message ); |
|
1521 | + if (WP_DEBUG) { |
|
1522 | + throw new \OutOfRangeException($message); |
|
1523 | 1523 | } else { |
1524 | - EE_Log::instance()->log( __CLASS__, __FUNCTION__, $message ); |
|
1524 | + EE_Log::instance()->log(__CLASS__, __FUNCTION__, $message); |
|
1525 | 1525 | } |
1526 | 1526 | return null; |
1527 | 1527 | } |
@@ -1537,15 +1537,15 @@ discard block |
||
1537 | 1537 | * @return \EE_Line_Item |
1538 | 1538 | * @throws \EE_Error |
1539 | 1539 | */ |
1540 | - public static function billable_line_item_tree( EE_Line_Item $line_item, $registrations ) { |
|
1541 | - $copy_li = EEH_Line_Item::billable_line_item( $line_item, $registrations ); |
|
1542 | - foreach ( $line_item->children() as $child_li ) { |
|
1543 | - $copy_li->add_child_line_item( EEH_Line_Item::billable_line_item_tree( $child_li, $registrations ) ); |
|
1540 | + public static function billable_line_item_tree(EE_Line_Item $line_item, $registrations) { |
|
1541 | + $copy_li = EEH_Line_Item::billable_line_item($line_item, $registrations); |
|
1542 | + foreach ($line_item->children() as $child_li) { |
|
1543 | + $copy_li->add_child_line_item(EEH_Line_Item::billable_line_item_tree($child_li, $registrations)); |
|
1544 | 1544 | } |
1545 | 1545 | //if this is the grand total line item, make sure the totals all add up |
1546 | 1546 | //(we could have duplicated this logic AS we copied the line items, but |
1547 | 1547 | //it seems DRYer this way) |
1548 | - if ( $copy_li->type() === EEM_Line_Item::type_total ) { |
|
1548 | + if ($copy_li->type() === EEM_Line_Item::type_total) { |
|
1549 | 1549 | $copy_li->recalculate_total_including_taxes(); |
1550 | 1550 | } |
1551 | 1551 | return $copy_li; |
@@ -1562,24 +1562,24 @@ discard block |
||
1562 | 1562 | * @throws \EE_Error |
1563 | 1563 | * @param EE_Registration[] $registrations |
1564 | 1564 | */ |
1565 | - public static function billable_line_item( EE_Line_Item $line_item, $registrations ) { |
|
1565 | + public static function billable_line_item(EE_Line_Item $line_item, $registrations) { |
|
1566 | 1566 | $new_li_fields = $line_item->model_field_array(); |
1567 | - if ( $line_item->type() === EEM_Line_Item::type_line_item && |
|
1567 | + if ($line_item->type() === EEM_Line_Item::type_line_item && |
|
1568 | 1568 | $line_item->OBJ_type() === 'Ticket' |
1569 | 1569 | ) { |
1570 | 1570 | $count = 0; |
1571 | - foreach ( $registrations as $registration ) { |
|
1572 | - if ( $line_item->OBJ_ID() === $registration->ticket_ID() && |
|
1573 | - in_array( $registration->status_ID(), EEM_Registration::reg_statuses_that_allow_payment() ) |
|
1571 | + foreach ($registrations as $registration) { |
|
1572 | + if ($line_item->OBJ_ID() === $registration->ticket_ID() && |
|
1573 | + in_array($registration->status_ID(), EEM_Registration::reg_statuses_that_allow_payment()) |
|
1574 | 1574 | ) { |
1575 | 1575 | $count++; |
1576 | 1576 | } |
1577 | 1577 | } |
1578 | - $new_li_fields[ 'LIN_quantity' ] = $count; |
|
1578 | + $new_li_fields['LIN_quantity'] = $count; |
|
1579 | 1579 | } |
1580 | 1580 | //don't set the total. We'll leave that up to the code that calculates it |
1581 | - unset( $new_li_fields[ 'LIN_ID' ], $new_li_fields[ 'LIN_parent' ], $new_li_fields[ 'LIN_total' ] ); |
|
1582 | - return EE_Line_Item::new_instance( $new_li_fields ); |
|
1581 | + unset($new_li_fields['LIN_ID'], $new_li_fields['LIN_parent'], $new_li_fields['LIN_total']); |
|
1582 | + return EE_Line_Item::new_instance($new_li_fields); |
|
1583 | 1583 | } |
1584 | 1584 | |
1585 | 1585 | |
@@ -1592,19 +1592,19 @@ discard block |
||
1592 | 1592 | * @return \EE_Line_Item|null |
1593 | 1593 | * @throws \EE_Error |
1594 | 1594 | */ |
1595 | - public static function non_empty_line_items( EE_Line_Item $line_item ) { |
|
1596 | - $copied_li = EEH_Line_Item::non_empty_line_item( $line_item ); |
|
1597 | - if ( $copied_li === null ) { |
|
1595 | + public static function non_empty_line_items(EE_Line_Item $line_item) { |
|
1596 | + $copied_li = EEH_Line_Item::non_empty_line_item($line_item); |
|
1597 | + if ($copied_li === null) { |
|
1598 | 1598 | return null; |
1599 | 1599 | } |
1600 | 1600 | //if this is an event subtotal, we want to only include it if it |
1601 | 1601 | //has a non-zero total and at least one ticket line item child |
1602 | 1602 | $ticket_children = 0; |
1603 | - foreach ( $line_item->children() as $child_li ) { |
|
1604 | - $child_li_copy = EEH_Line_Item::non_empty_line_items( $child_li ); |
|
1605 | - if ( $child_li_copy !== null ) { |
|
1606 | - $copied_li->add_child_line_item( $child_li_copy ); |
|
1607 | - if ( $child_li_copy->type() === EEM_Line_Item::type_line_item && |
|
1603 | + foreach ($line_item->children() as $child_li) { |
|
1604 | + $child_li_copy = EEH_Line_Item::non_empty_line_items($child_li); |
|
1605 | + if ($child_li_copy !== null) { |
|
1606 | + $copied_li->add_child_line_item($child_li_copy); |
|
1607 | + if ($child_li_copy->type() === EEM_Line_Item::type_line_item && |
|
1608 | 1608 | $child_li_copy->OBJ_type() === 'Ticket' |
1609 | 1609 | ) { |
1610 | 1610 | $ticket_children++; |
@@ -1634,8 +1634,8 @@ discard block |
||
1634 | 1634 | * @return EE_Line_Item |
1635 | 1635 | * @throws \EE_Error |
1636 | 1636 | */ |
1637 | - public static function non_empty_line_item( EE_Line_Item $line_item ) { |
|
1638 | - if ( $line_item->type() === EEM_Line_Item::type_line_item && |
|
1637 | + public static function non_empty_line_item(EE_Line_Item $line_item) { |
|
1638 | + if ($line_item->type() === EEM_Line_Item::type_line_item && |
|
1639 | 1639 | $line_item->OBJ_type() === 'Ticket' && |
1640 | 1640 | $line_item->quantity() === 0 |
1641 | 1641 | ) { |
@@ -1643,8 +1643,8 @@ discard block |
||
1643 | 1643 | } |
1644 | 1644 | $new_li_fields = $line_item->model_field_array(); |
1645 | 1645 | //don't set the total. We'll leave that up to the code that calculates it |
1646 | - unset( $new_li_fields[ 'LIN_ID' ], $new_li_fields[ 'LIN_parent' ] ); |
|
1647 | - return EE_Line_Item::new_instance( $new_li_fields ); |
|
1646 | + unset($new_li_fields['LIN_ID'], $new_li_fields['LIN_parent']); |
|
1647 | + return EE_Line_Item::new_instance($new_li_fields); |
|
1648 | 1648 | } |
1649 | 1649 | |
1650 | 1650 | |
@@ -1656,9 +1656,9 @@ discard block |
||
1656 | 1656 | * @return \EE_Line_Item |
1657 | 1657 | * @throws \EE_Error |
1658 | 1658 | */ |
1659 | - public static function get_items_subtotal( EE_Line_Item $total_line_item ){ |
|
1660 | - EE_Error::doing_it_wrong( 'EEH_Line_Item::get_items_subtotal()', __('Method replaced with EEH_Line_Item::get_pre_tax_subtotal()', 'event_espresso'), '4.6.0' ); |
|
1661 | - return self::get_pre_tax_subtotal( $total_line_item ); |
|
1659 | + public static function get_items_subtotal(EE_Line_Item $total_line_item) { |
|
1660 | + EE_Error::doing_it_wrong('EEH_Line_Item::get_items_subtotal()', __('Method replaced with EEH_Line_Item::get_pre_tax_subtotal()', 'event_espresso'), '4.6.0'); |
|
1661 | + return self::get_pre_tax_subtotal($total_line_item); |
|
1662 | 1662 | } |
1663 | 1663 | |
1664 | 1664 | |
@@ -1669,9 +1669,9 @@ discard block |
||
1669 | 1669 | * @return \EE_Line_Item |
1670 | 1670 | * @throws \EE_Error |
1671 | 1671 | */ |
1672 | - public static function create_default_total_line_item( $transaction = NULL) { |
|
1673 | - EE_Error::doing_it_wrong( 'EEH_Line_Item::create_default_total_line_item()', __('Method replaced with EEH_Line_Item::create_total_line_item()', 'event_espresso'), '4.6.0' ); |
|
1674 | - return self::create_total_line_item( $transaction ); |
|
1672 | + public static function create_default_total_line_item($transaction = NULL) { |
|
1673 | + EE_Error::doing_it_wrong('EEH_Line_Item::create_default_total_line_item()', __('Method replaced with EEH_Line_Item::create_total_line_item()', 'event_espresso'), '4.6.0'); |
|
1674 | + return self::create_total_line_item($transaction); |
|
1675 | 1675 | } |
1676 | 1676 | |
1677 | 1677 | |
@@ -1683,9 +1683,9 @@ discard block |
||
1683 | 1683 | * @return \EE_Line_Item |
1684 | 1684 | * @throws \EE_Error |
1685 | 1685 | */ |
1686 | - public static function create_default_tickets_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) { |
|
1687 | - EE_Error::doing_it_wrong( 'EEH_Line_Item::create_default_tickets_subtotal()', __('Method replaced with EEH_Line_Item::create_pre_tax_subtotal()', 'event_espresso'), '4.6.0' ); |
|
1688 | - return self::create_pre_tax_subtotal( $total_line_item, $transaction ); |
|
1686 | + public static function create_default_tickets_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
1687 | + EE_Error::doing_it_wrong('EEH_Line_Item::create_default_tickets_subtotal()', __('Method replaced with EEH_Line_Item::create_pre_tax_subtotal()', 'event_espresso'), '4.6.0'); |
|
1688 | + return self::create_pre_tax_subtotal($total_line_item, $transaction); |
|
1689 | 1689 | } |
1690 | 1690 | |
1691 | 1691 | |
@@ -1697,9 +1697,9 @@ discard block |
||
1697 | 1697 | * @return \EE_Line_Item |
1698 | 1698 | * @throws \EE_Error |
1699 | 1699 | */ |
1700 | - public static function create_default_taxes_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) { |
|
1701 | - EE_Error::doing_it_wrong( 'EEH_Line_Item::create_default_taxes_subtotal()', __('Method replaced with EEH_Line_Item::create_taxes_subtotal()', 'event_espresso'), '4.6.0' ); |
|
1702 | - return self::create_taxes_subtotal( $total_line_item, $transaction ); |
|
1700 | + public static function create_default_taxes_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
1701 | + EE_Error::doing_it_wrong('EEH_Line_Item::create_default_taxes_subtotal()', __('Method replaced with EEH_Line_Item::create_taxes_subtotal()', 'event_espresso'), '4.6.0'); |
|
1702 | + return self::create_taxes_subtotal($total_line_item, $transaction); |
|
1703 | 1703 | } |
1704 | 1704 | |
1705 | 1705 | |
@@ -1711,9 +1711,9 @@ discard block |
||
1711 | 1711 | * @return \EE_Line_Item |
1712 | 1712 | * @throws \EE_Error |
1713 | 1713 | */ |
1714 | - public static function create_default_event_subtotal( EE_Line_Item $total_line_item, $transaction = NULL) { |
|
1715 | - EE_Error::doing_it_wrong( 'EEH_Line_Item::create_default_event_subtotal()', __('Method replaced with EEH_Line_Item::create_event_subtotal()', 'event_espresso'), '4.6.0' ); |
|
1716 | - return self::create_event_subtotal( $total_line_item, $transaction ); |
|
1714 | + public static function create_default_event_subtotal(EE_Line_Item $total_line_item, $transaction = NULL) { |
|
1715 | + EE_Error::doing_it_wrong('EEH_Line_Item::create_default_event_subtotal()', __('Method replaced with EEH_Line_Item::create_event_subtotal()', 'event_espresso'), '4.6.0'); |
|
1716 | + return self::create_event_subtotal($total_line_item, $transaction); |
|
1717 | 1717 | } |
1718 | 1718 | |
1719 | 1719 |
@@ -871,7 +871,7 @@ discard block |
||
871 | 871 | * Deletes ALL children of the passed line item |
872 | 872 | * |
873 | 873 | * @param EE_Line_Item $parent_line_item |
874 | - * @return bool |
|
874 | + * @return integer |
|
875 | 875 | * @throws \EE_Error |
876 | 876 | */ |
877 | 877 | public static function delete_all_child_items( EE_Line_Item $parent_line_item ) { |
@@ -1135,6 +1135,7 @@ discard block |
||
1135 | 1135 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
1136 | 1136 | * @param string $line_item_type one of the EEM_Line_Item constants |
1137 | 1137 | * @param string | NULL $obj_type object model class name (minus prefix) or NULL to ignore object type when searching |
1138 | + * @param string $obj_type |
|
1138 | 1139 | * @return EE_Line_Item[] |
1139 | 1140 | */ |
1140 | 1141 | protected static function _get_descendants_by_type_and_object_type( |
@@ -1176,7 +1177,7 @@ discard block |
||
1176 | 1177 | * @uses EEH_Line_Item::_get_descendants_by_type_and_object_type() |
1177 | 1178 | * @param \EE_Line_Item $parent_line_item - the line item to find descendants of |
1178 | 1179 | * @param string $OBJ_type object type (like Event) |
1179 | - * @param array $OBJ_IDs array of OBJ_IDs |
|
1180 | + * @param string[] $OBJ_IDs array of OBJ_IDs |
|
1180 | 1181 | * @return EE_Line_Item[] |
1181 | 1182 | */ |
1182 | 1183 | public static function get_line_items_by_object_type_and_IDs( |
@@ -8,18 +8,18 @@ |
||
8 | 8 | */ |
9 | 9 | if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
10 | 10 | /** |
11 | - * |
|
12 | - * Money helper class. |
|
13 | - * This class has helper methods that help with money related conversions and calculations. |
|
14 | - * |
|
15 | - * @since %VER% |
|
16 | - * |
|
17 | - * @package Event Espresso |
|
18 | - * @subpackage helpers |
|
19 | - * @author Darren Ethier |
|
20 | - * |
|
21 | - * ------------------------------------------------------------------------ |
|
22 | - */ |
|
11 | + * |
|
12 | + * Money helper class. |
|
13 | + * This class has helper methods that help with money related conversions and calculations. |
|
14 | + * |
|
15 | + * @since %VER% |
|
16 | + * |
|
17 | + * @package Event Espresso |
|
18 | + * @subpackage helpers |
|
19 | + * @author Darren Ethier |
|
20 | + * |
|
21 | + * ------------------------------------------------------------------------ |
|
22 | + */ |
|
23 | 23 | class EEH_Money extends EEH_Base { |
24 | 24 | |
25 | 25 |
@@ -6,7 +6,9 @@ |
||
6 | 6 | * @package Event Espresso |
7 | 7 | * @subpackage helper |
8 | 8 | */ |
9 | -if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
9 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
10 | + exit('No direct script access allowed'); |
|
11 | +} |
|
10 | 12 | /** |
11 | 13 | * |
12 | 14 | * Money helper class. |
@@ -20,7 +20,7 @@ discard block |
||
20 | 20 | * |
21 | 21 | * ------------------------------------------------------------------------ |
22 | 22 | */ |
23 | -class EEH_Money extends EEH_Base { |
|
23 | +class EEH_Money extends EEH_Base { |
|
24 | 24 | |
25 | 25 | |
26 | 26 | /** |
@@ -29,15 +29,15 @@ discard block |
||
29 | 29 | * @param int|string $incoming_value |
30 | 30 | * @return float |
31 | 31 | */ |
32 | - public static function convert_to_float_from_localized_money( $incoming_value ) { |
|
32 | + public static function convert_to_float_from_localized_money($incoming_value) { |
|
33 | 33 | //remove thousands separator |
34 | - $money_value = str_replace( EE_Registry::instance()->CFG->currency->thsnds, '', $incoming_value ); |
|
34 | + $money_value = str_replace(EE_Registry::instance()->CFG->currency->thsnds, '', $incoming_value); |
|
35 | 35 | |
36 | 36 | //replace decimal place with standard decimal. |
37 | - $money_value = str_replace( EE_Registry::instance()->CFG->currency->dec_mrk, '.', $money_value ); |
|
37 | + $money_value = str_replace(EE_Registry::instance()->CFG->currency->dec_mrk, '.', $money_value); |
|
38 | 38 | |
39 | 39 | //float it! and round to three decimal places |
40 | - $money_value = round ( (float) $money_value, 3 ); |
|
40 | + $money_value = round((float) $money_value, 3); |
|
41 | 41 | return $money_value; |
42 | 42 | } |
43 | 43 | |
@@ -57,12 +57,12 @@ discard block |
||
57 | 57 | * @throws \EE_Error |
58 | 58 | */ |
59 | 59 | |
60 | - public static function compare_floats( $float1, $float2, $operator='=' ) { |
|
60 | + public static function compare_floats($float1, $float2, $operator = '=') { |
|
61 | 61 | // Check numbers to 5 digits of precision |
62 | 62 | $epsilon = 0.00001; |
63 | 63 | |
64 | - $float1 = (float)$float1; |
|
65 | - $float2 = (float)$float2; |
|
64 | + $float1 = (float) $float1; |
|
65 | + $float2 = (float) $float2; |
|
66 | 66 | |
67 | 67 | switch ($operator) { |
68 | 68 | // equal |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | } |
117 | 117 | break; |
118 | 118 | default: |
119 | - throw new EE_Error(__( "Unknown operator '" . $operator . "' in EEH_Money::compare_floats()", 'event_espresso' ) ); |
|
119 | + throw new EE_Error(__("Unknown operator '".$operator."' in EEH_Money::compare_floats()", 'event_espresso')); |
|
120 | 120 | } |
121 | 121 | |
122 | 122 | return false; |
@@ -131,21 +131,21 @@ discard block |
||
131 | 131 | * |
132 | 132 | * @return string |
133 | 133 | */ |
134 | - public static function get_format_for_jqplot( $CNT_ISO = '') { |
|
134 | + public static function get_format_for_jqplot($CNT_ISO = '') { |
|
135 | 135 | //default format |
136 | 136 | $format = 'f'; |
137 | 137 | //if CNT_ISO passed lets try to get currency settings for it. |
138 | - $currency_config = $CNT_ISO !== '' ? new EE_Currency_Config( $CNT_ISO ) : null; |
|
138 | + $currency_config = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null; |
|
139 | 139 | //default currency settings for site if not set |
140 | - if ( ! $currency_config instanceof EE_Currency_Config ) { |
|
140 | + if ( ! $currency_config instanceof EE_Currency_Config) { |
|
141 | 141 | $currency_config = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config ? EE_Registry::instance()->CFG->currency : new EE_Currency_Config(); |
142 | 142 | } |
143 | 143 | |
144 | 144 | //first get the decimal place and number of places |
145 | - $format = "%'." . $currency_config->dec_plc . $format; |
|
145 | + $format = "%'.".$currency_config->dec_plc.$format; |
|
146 | 146 | |
147 | 147 | //currency symbol on right side. |
148 | - $format = $currency_config->sign_b4 ? $currency_config->sign . $format : $format . $currency_config->sign; |
|
148 | + $format = $currency_config->sign_b4 ? $currency_config->sign.$format : $format.$currency_config->sign; |
|
149 | 149 | return $format; |
150 | 150 | } |
151 | 151 | |
@@ -160,27 +160,27 @@ discard block |
||
160 | 160 | * |
161 | 161 | * @return string |
162 | 162 | */ |
163 | - public static function get_format_for_google_charts( $CNT_ISO = '' ) { |
|
163 | + public static function get_format_for_google_charts($CNT_ISO = '') { |
|
164 | 164 | //if CNT_ISO passed lets try to get currency settings for it. |
165 | - $currency_config = $CNT_ISO !== '' ? new EE_Currency_Config( $CNT_ISO ) : null; |
|
165 | + $currency_config = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : null; |
|
166 | 166 | //default currency settings for site if not set |
167 | - if ( ! $currency_config instanceof EE_Currency_Config ) { |
|
167 | + if ( ! $currency_config instanceof EE_Currency_Config) { |
|
168 | 168 | $currency_config = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config ? EE_Registry::instance()->CFG->currency : new EE_Currency_Config(); |
169 | 169 | } |
170 | 170 | |
171 | - $decimal_places_placeholder = str_pad( '', $currency_config->dec_plc, '0' ); |
|
171 | + $decimal_places_placeholder = str_pad('', $currency_config->dec_plc, '0'); |
|
172 | 172 | |
173 | 173 | //first get the decimal place and number of places |
174 | - $format = '#,##0.' . $decimal_places_placeholder; |
|
174 | + $format = '#,##0.'.$decimal_places_placeholder; |
|
175 | 175 | |
176 | 176 | //currency symbol on right side. |
177 | - $format = $currency_config->sign_b4 ? $currency_config->sign . $format : $format . $currency_config->sign; |
|
177 | + $format = $currency_config->sign_b4 ? $currency_config->sign.$format : $format.$currency_config->sign; |
|
178 | 178 | $formatterObject = array( |
179 | 179 | 'decimalSymbol' => $currency_config->dec_mrk, |
180 | 180 | 'groupingSymbol' => $currency_config->thsnds, |
181 | 181 | 'fractionDigits' => $currency_config->dec_plc, |
182 | 182 | ); |
183 | - if ( $currency_config->sign_b4 ) { |
|
183 | + if ($currency_config->sign_b4) { |
|
184 | 184 | $formatterObject['prefix'] = $currency_config->sign; |
185 | 185 | } else { |
186 | 186 | $formatterObject['suffix'] = $currency_config->sign; |
@@ -160,8 +160,9 @@ discard block |
||
160 | 160 | // first use WP locate_template to check for template in the current theme folder |
161 | 161 | $template_path = locate_template( $templates ); |
162 | 162 | |
163 | - if ( $check_if_custom && !empty( $template_path ) ) |
|
164 | - return TRUE; |
|
163 | + if ( $check_if_custom && !empty( $template_path ) ) { |
|
164 | + return TRUE; |
|
165 | + } |
|
165 | 166 | |
166 | 167 | // not in the theme |
167 | 168 | if ( empty( $template_path )) { |
@@ -364,11 +365,11 @@ discard block |
||
364 | 365 | if( $mny->sign_b4 ){ |
365 | 366 | if( $amount >= 0 ){ |
366 | 367 | $amount_formatted = $mny->sign . $amount_formatted; |
367 | - }else{ |
|
368 | + } else{ |
|
368 | 369 | $amount_formatted = '-' . $mny->sign . str_replace( '-', '', $amount_formatted ); |
369 | 370 | } |
370 | 371 | |
371 | - }else{ |
|
372 | + } else{ |
|
372 | 373 | $amount_formatted = $amount_formatted . $mny->sign; |
373 | 374 | } |
374 | 375 | |
@@ -432,11 +433,13 @@ discard block |
||
432 | 433 | */ |
433 | 434 | public static function get_help_tab_link( $help_tab_id, $page = FALSE, $action = FALSE, $icon_style = FALSE, $help_text = FALSE ) { |
434 | 435 | |
435 | - if ( ! $page ) |
|
436 | - $page = isset( $_REQUEST['page'] ) && ! empty( $_REQUEST['page'] ) ? sanitize_key( $_REQUEST['page'] ) : $page; |
|
436 | + if ( ! $page ) { |
|
437 | + $page = isset( $_REQUEST['page'] ) && ! empty( $_REQUEST['page'] ) ? sanitize_key( $_REQUEST['page'] ) : $page; |
|
438 | + } |
|
437 | 439 | |
438 | - if ( ! $action ) |
|
439 | - $action = isset( $_REQUEST['action'] ) && ! empty( $_REQUEST['action'] ) ? sanitize_key( $_REQUEST['action'] ) : $action; |
|
440 | + if ( ! $action ) { |
|
441 | + $action = isset( $_REQUEST['action'] ) && ! empty( $_REQUEST['action'] ) ? sanitize_key( $_REQUEST['action'] ) : $action; |
|
442 | + } |
|
440 | 443 | |
441 | 444 | $action = empty($action) ? 'default' : $action; |
442 | 445 | |
@@ -510,8 +513,9 @@ discard block |
||
510 | 513 | * @return string html structure for status. |
511 | 514 | */ |
512 | 515 | public static function status_legend( $status_array, $active_status = '' ) { |
513 | - if ( !is_array( $status_array ) ) |
|
514 | - throw new EE_Error( __('The EEH_Template::status_legend helper required the incoming status_array argument to be an array!', 'event_espresso') ); |
|
516 | + if ( !is_array( $status_array ) ) { |
|
517 | + throw new EE_Error( __('The EEH_Template::status_legend helper required the incoming status_array argument to be an array!', 'event_espresso') ); |
|
518 | + } |
|
515 | 519 | |
516 | 520 | $setup_array = array(); |
517 | 521 | foreach ( $status_array as $item => $status ) { |
@@ -572,8 +576,7 @@ discard block |
||
572 | 576 | </tbody> |
573 | 577 | </table> |
574 | 578 | <?php |
575 | - } |
|
576 | - else { |
|
579 | + } else { |
|
577 | 580 | ?> |
578 | 581 | <ul> |
579 | 582 | <?php |
@@ -583,8 +586,7 @@ discard block |
||
583 | 586 | </ul> |
584 | 587 | <?php |
585 | 588 | } |
586 | - } |
|
587 | - else { |
|
589 | + } else { |
|
588 | 590 | //simple value |
589 | 591 | echo $data; |
590 | 592 | } |
@@ -664,8 +666,9 @@ discard block |
||
664 | 666 | |
665 | 667 | $total_pages = ceil( $total_items / $per_page ); |
666 | 668 | |
667 | - if ( $total_pages <= 1 ) |
|
668 | - return ''; |
|
669 | + if ( $total_pages <= 1 ) { |
|
670 | + return ''; |
|
671 | + } |
|
669 | 672 | |
670 | 673 | $item_label = $total_items > 1 ? sprintf( $items_label['plural'], $total_items ) : $items_label['single']; |
671 | 674 |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | return array(); |
100 | 100 | } |
101 | 101 | if (( $key = array_search( 'global_assets', $espresso_themes )) !== FALSE ) { |
102 | - unset( $espresso_themes[ $key ] ); |
|
102 | + unset( $espresso_themes[ $key ] ); |
|
103 | 103 | } |
104 | 104 | EEH_Template::$_espresso_themes = array(); |
105 | 105 | foreach ( $espresso_themes as $espresso_theme ) { |
@@ -709,9 +709,9 @@ discard block |
||
709 | 709 | ); |
710 | 710 | |
711 | 711 | if ( empty( $items_label ) |
712 | - || ! is_array( $items_label ) |
|
713 | - || ! isset( $items_label['single'] ) |
|
714 | - || ! isset( $items_label['plural'] ) ) { |
|
712 | + || ! is_array( $items_label ) |
|
713 | + || ! isset( $items_label['single'] ) |
|
714 | + || ! isset( $items_label['plural'] ) ) { |
|
715 | 715 | $items_label = array( |
716 | 716 | 'single' => __( '1 item', 'event_espresso' ), |
717 | 717 | 'plural' => __( '%s items', 'event_espresso' ) |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | |
16 | 16 | |
17 | 17 | |
18 | -if ( ! function_exists( 'espresso_get_template_part' )) { |
|
18 | +if ( ! function_exists('espresso_get_template_part')) { |
|
19 | 19 | /** |
20 | 20 | * espresso_get_template_part |
21 | 21 | * basically a copy of the WordPress get_template_part() function but uses EEH_Template::locate_template() instead, and doesn't add base versions of files |
@@ -25,14 +25,14 @@ discard block |
||
25 | 25 | * @param string $name The name of the specialised template. |
26 | 26 | * @return string the html output for the formatted money value |
27 | 27 | */ |
28 | - function espresso_get_template_part( $slug = NULL, $name = NULL ) { |
|
29 | - EEH_Template::get_template_part( $slug, $name ); |
|
28 | + function espresso_get_template_part($slug = NULL, $name = NULL) { |
|
29 | + EEH_Template::get_template_part($slug, $name); |
|
30 | 30 | } |
31 | 31 | } |
32 | 32 | |
33 | 33 | |
34 | 34 | |
35 | -if ( ! function_exists( 'espresso_get_object_css_class' )) { |
|
35 | +if ( ! function_exists('espresso_get_object_css_class')) { |
|
36 | 36 | /** |
37 | 37 | * espresso_get_object_css_class - attempts to generate a css class based on the type of EE object passed |
38 | 38 | * |
@@ -42,8 +42,8 @@ discard block |
||
42 | 42 | * @param string $suffix added to the end of the generated class |
43 | 43 | * @return string |
44 | 44 | */ |
45 | - function espresso_get_object_css_class( $object = NULL, $prefix = '', $suffix = '' ) { |
|
46 | - return EEH_Template::get_object_css_class( $object, $prefix, $suffix ); |
|
45 | + function espresso_get_object_css_class($object = NULL, $prefix = '', $suffix = '') { |
|
46 | + return EEH_Template::get_object_css_class($object, $prefix, $suffix); |
|
47 | 47 | } |
48 | 48 | } |
49 | 49 | |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | * @return boolean |
71 | 71 | */ |
72 | 72 | public static function is_espresso_theme() { |
73 | - return wp_get_theme()->get( 'TextDomain' ) == 'event_espresso' ? TRUE : FALSE; |
|
73 | + return wp_get_theme()->get('TextDomain') == 'event_espresso' ? TRUE : FALSE; |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
@@ -79,9 +79,9 @@ discard block |
||
79 | 79 | * @return void |
80 | 80 | */ |
81 | 81 | public static function load_espresso_theme_functions() { |
82 | - if ( ! defined( 'EE_THEME_FUNCTIONS_LOADED' )) { |
|
83 | - if ( is_readable( EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php' )) { |
|
84 | - require_once( EE_PUBLIC . EE_Config::get_current_theme() . DS . 'functions.php' ); |
|
82 | + if ( ! defined('EE_THEME_FUNCTIONS_LOADED')) { |
|
83 | + if (is_readable(EE_PUBLIC.EE_Config::get_current_theme().DS.'functions.php')) { |
|
84 | + require_once(EE_PUBLIC.EE_Config::get_current_theme().DS.'functions.php'); |
|
85 | 85 | } |
86 | 86 | } |
87 | 87 | } |
@@ -93,17 +93,17 @@ discard block |
||
93 | 93 | * @return array |
94 | 94 | */ |
95 | 95 | public static function get_espresso_themes() { |
96 | - if ( empty( EEH_Template::$_espresso_themes )) { |
|
97 | - $espresso_themes = glob( EE_PUBLIC . '*', GLOB_ONLYDIR ); |
|
98 | - if ( empty( $espresso_themes ) ) { |
|
96 | + if (empty(EEH_Template::$_espresso_themes)) { |
|
97 | + $espresso_themes = glob(EE_PUBLIC.'*', GLOB_ONLYDIR); |
|
98 | + if (empty($espresso_themes)) { |
|
99 | 99 | return array(); |
100 | 100 | } |
101 | - if (( $key = array_search( 'global_assets', $espresso_themes )) !== FALSE ) { |
|
102 | - unset( $espresso_themes[ $key ] ); |
|
101 | + if (($key = array_search('global_assets', $espresso_themes)) !== FALSE) { |
|
102 | + unset($espresso_themes[$key]); |
|
103 | 103 | } |
104 | 104 | EEH_Template::$_espresso_themes = array(); |
105 | - foreach ( $espresso_themes as $espresso_theme ) { |
|
106 | - EEH_Template::$_espresso_themes[ basename( $espresso_theme ) ] = $espresso_theme; |
|
105 | + foreach ($espresso_themes as $espresso_theme) { |
|
106 | + EEH_Template::$_espresso_themes[basename($espresso_theme)] = $espresso_theme; |
|
107 | 107 | } |
108 | 108 | } |
109 | 109 | return EEH_Template::$_espresso_themes; |
@@ -122,16 +122,16 @@ discard block |
||
122 | 122 | * @param bool $return_string |
123 | 123 | * @return string the html output for the formatted money value |
124 | 124 | */ |
125 | - public static function get_template_part( $slug = NULL, $name = NULL, $template_args = array(), $return_string = FALSE ) { |
|
126 | - do_action( "get_template_part_{$slug}-{$name}", $slug, $name ); |
|
125 | + public static function get_template_part($slug = NULL, $name = NULL, $template_args = array(), $return_string = FALSE) { |
|
126 | + do_action("get_template_part_{$slug}-{$name}", $slug, $name); |
|
127 | 127 | $templates = array(); |
128 | 128 | $name = (string) $name; |
129 | - if ( $name != '' ) { |
|
129 | + if ($name != '') { |
|
130 | 130 | $templates[] = "{$slug}-{$name}.php"; |
131 | 131 | } |
132 | 132 | // allow template parts to be turned off via something like: add_filter( 'FHEE__content_espresso_events_tickets_template__display_datetimes', '__return_false' ); |
133 | - if ( apply_filters( "FHEE__EEH_Template__get_template_part__display__{$slug}_{$name}", TRUE )) { |
|
134 | - EEH_Template::locate_template( $templates, $template_args, TRUE, $return_string ); |
|
133 | + if (apply_filters("FHEE__EEH_Template__get_template_part__display__{$slug}_{$name}", TRUE)) { |
|
134 | + EEH_Template::locate_template($templates, $template_args, TRUE, $return_string); |
|
135 | 135 | } |
136 | 136 | } |
137 | 137 | |
@@ -182,26 +182,26 @@ discard block |
||
182 | 182 | * Used in places where you don't actually load the template, you just want to know if there's a custom version of it. |
183 | 183 | * @return mixed |
184 | 184 | */ |
185 | - public static function locate_template( $templates = array(), $template_args = array(), $load = TRUE, $return_string = TRUE, $check_if_custom = FALSE ) { |
|
185 | + public static function locate_template($templates = array(), $template_args = array(), $load = TRUE, $return_string = TRUE, $check_if_custom = FALSE) { |
|
186 | 186 | // first use WP locate_template to check for template in the current theme folder |
187 | - $template_path = locate_template( $templates ); |
|
187 | + $template_path = locate_template($templates); |
|
188 | 188 | |
189 | - if ( $check_if_custom && !empty( $template_path ) ) |
|
189 | + if ($check_if_custom && ! empty($template_path)) |
|
190 | 190 | return TRUE; |
191 | 191 | |
192 | 192 | // not in the theme |
193 | - if ( empty( $template_path )) { |
|
193 | + if (empty($template_path)) { |
|
194 | 194 | // not even a template to look for ? |
195 | - if ( empty( $templates )) { |
|
195 | + if (empty($templates)) { |
|
196 | 196 | // get post_type |
197 | - $post_type = EE_Registry::instance()->REQ->get( 'post_type' ); |
|
197 | + $post_type = EE_Registry::instance()->REQ->get('post_type'); |
|
198 | 198 | // get array of EE Custom Post Types |
199 | 199 | $EE_CPTs = EE_Register_CPTs::get_CPTs(); |
200 | 200 | // build template name based on request |
201 | - if ( isset( $EE_CPTs[ $post_type ] )) { |
|
202 | - $archive_or_single = is_archive() ? 'archive' : ''; |
|
203 | - $archive_or_single = is_single() ? 'single' : $archive_or_single; |
|
204 | - $templates = $archive_or_single . '-' . $post_type . '.php'; |
|
201 | + if (isset($EE_CPTs[$post_type])) { |
|
202 | + $archive_or_single = is_archive() ? 'archive' : ''; |
|
203 | + $archive_or_single = is_single() ? 'single' : $archive_or_single; |
|
204 | + $templates = $archive_or_single.'-'.$post_type.'.php'; |
|
205 | 205 | } |
206 | 206 | } |
207 | 207 | // currently active EE template theme |
@@ -210,81 +210,81 @@ discard block |
||
210 | 210 | // array of paths to folders that may contain templates |
211 | 211 | $template_folder_paths = array( |
212 | 212 | // first check the /wp-content/uploads/espresso/templates/(current EE theme)/ folder for an EE theme template file |
213 | - EVENT_ESPRESSO_TEMPLATE_DIR . $current_theme, |
|
213 | + EVENT_ESPRESSO_TEMPLATE_DIR.$current_theme, |
|
214 | 214 | // then in the root of the /wp-content/uploads/espresso/templates/ folder |
215 | 215 | EVENT_ESPRESSO_TEMPLATE_DIR |
216 | 216 | ); |
217 | 217 | |
218 | 218 | //add core plugin folders for checking only if we're not $check_if_custom |
219 | - if ( ! $check_if_custom ) { |
|
219 | + if ( ! $check_if_custom) { |
|
220 | 220 | $core_paths = array( |
221 | 221 | // in the /wp-content/plugins/(EE4 folder)/public/(current EE theme)/ folder within the plugin |
222 | - EE_PUBLIC . $current_theme, |
|
222 | + EE_PUBLIC.$current_theme, |
|
223 | 223 | // in the /wp-content/plugins/(EE4 folder)/core/templates/(current EE theme)/ folder within the plugin |
224 | - EE_TEMPLATES . $current_theme, |
|
224 | + EE_TEMPLATES.$current_theme, |
|
225 | 225 | // or maybe relative from the plugin root: /wp-content/plugins/(EE4 folder)/ |
226 | 226 | EE_PLUGIN_DIR_PATH |
227 | 227 | ); |
228 | - $template_folder_paths = array_merge( $template_folder_paths, $core_paths ); |
|
228 | + $template_folder_paths = array_merge($template_folder_paths, $core_paths); |
|
229 | 229 | } |
230 | 230 | |
231 | 231 | // now filter that array |
232 | - $template_folder_paths = apply_filters( 'FHEE__EEH_Template__locate_template__template_folder_paths', $template_folder_paths ); |
|
233 | - $templates = is_array( $templates ) ? $templates : array( $templates ); |
|
234 | - $template_folder_paths = is_array( $template_folder_paths ) ? $template_folder_paths : array( $template_folder_paths ); |
|
232 | + $template_folder_paths = apply_filters('FHEE__EEH_Template__locate_template__template_folder_paths', $template_folder_paths); |
|
233 | + $templates = is_array($templates) ? $templates : array($templates); |
|
234 | + $template_folder_paths = is_array($template_folder_paths) ? $template_folder_paths : array($template_folder_paths); |
|
235 | 235 | // array to hold all possible template paths |
236 | 236 | $full_template_paths = array(); |
237 | 237 | |
238 | 238 | // loop through $templates |
239 | - foreach ( $templates as $template ) { |
|
239 | + foreach ($templates as $template) { |
|
240 | 240 | // normalize directory separators |
241 | - $template = EEH_File::standardise_directory_separators( $template ); |
|
242 | - $file_name = basename( $template ); |
|
243 | - $template_path_minus_file_name = substr( $template, 0, ( strlen( $file_name ) * -1 ) ); |
|
241 | + $template = EEH_File::standardise_directory_separators($template); |
|
242 | + $file_name = basename($template); |
|
243 | + $template_path_minus_file_name = substr($template, 0, (strlen($file_name) * -1)); |
|
244 | 244 | // while looping through all template folder paths |
245 | - foreach ( $template_folder_paths as $template_folder_path ) { |
|
245 | + foreach ($template_folder_paths as $template_folder_path) { |
|
246 | 246 | // normalize directory separators |
247 | - $template_folder_path = EEH_File::standardise_directory_separators( $template_folder_path ); |
|
247 | + $template_folder_path = EEH_File::standardise_directory_separators($template_folder_path); |
|
248 | 248 | // determine if any common base path exists between the two paths |
249 | 249 | $common_base_path = EEH_Template::_find_common_base_path( |
250 | - array( $template_folder_path, $template_path_minus_file_name ) |
|
250 | + array($template_folder_path, $template_path_minus_file_name) |
|
251 | 251 | ); |
252 | - if ( $common_base_path !== '' ) { |
|
252 | + if ($common_base_path !== '') { |
|
253 | 253 | // both paths have a common base, so just tack the filename onto our search path |
254 | - $resolved_path = EEH_File::end_with_directory_separator( $template_folder_path ) . $file_name; |
|
254 | + $resolved_path = EEH_File::end_with_directory_separator($template_folder_path).$file_name; |
|
255 | 255 | } else { |
256 | 256 | // no common base path, so let's just concatenate |
257 | - $resolved_path = EEH_File::end_with_directory_separator( $template_folder_path ) . $template; |
|
257 | + $resolved_path = EEH_File::end_with_directory_separator($template_folder_path).$template; |
|
258 | 258 | } |
259 | 259 | // build up our template locations array by adding our resolved paths |
260 | 260 | $full_template_paths[] = $resolved_path; |
261 | 261 | } |
262 | 262 | // if $template is an absolute path, then we'll tack it onto the start of our array so that it gets searched first |
263 | - array_unshift( $full_template_paths, $template ); |
|
263 | + array_unshift($full_template_paths, $template); |
|
264 | 264 | // path to the directory of the current theme: /wp-content/themes/(current WP theme)/ |
265 | - array_unshift( $full_template_paths, get_stylesheet_directory() . DS . $file_name ); |
|
265 | + array_unshift($full_template_paths, get_stylesheet_directory().DS.$file_name); |
|
266 | 266 | } |
267 | 267 | // filter final array of full template paths |
268 | - $full_template_paths = apply_filters( 'FHEE__EEH_Template__locate_template__full_template_paths', $full_template_paths, $file_name ); |
|
268 | + $full_template_paths = apply_filters('FHEE__EEH_Template__locate_template__full_template_paths', $full_template_paths, $file_name); |
|
269 | 269 | // now loop through our final array of template location paths and check each location |
270 | - foreach ( (array)$full_template_paths as $full_template_path ) { |
|
271 | - if ( is_readable( $full_template_path )) { |
|
272 | - $template_path = str_replace( array( '\\', '/' ), DIRECTORY_SEPARATOR, $full_template_path ); |
|
270 | + foreach ((array) $full_template_paths as $full_template_path) { |
|
271 | + if (is_readable($full_template_path)) { |
|
272 | + $template_path = str_replace(array('\\', '/'), DIRECTORY_SEPARATOR, $full_template_path); |
|
273 | 273 | // hook that can be used to display the full template path that will be used |
274 | - do_action( 'AHEE__EEH_Template__locate_template__full_template_path', $template_path ); |
|
274 | + do_action('AHEE__EEH_Template__locate_template__full_template_path', $template_path); |
|
275 | 275 | break; |
276 | 276 | } |
277 | 277 | } |
278 | 278 | } |
279 | 279 | // if we got it and you want to see it... |
280 | - if ( $template_path && $load && ! $check_if_custom ) { |
|
281 | - if ( $return_string ) { |
|
282 | - return EEH_Template::display_template( $template_path, $template_args, TRUE ); |
|
280 | + if ($template_path && $load && ! $check_if_custom) { |
|
281 | + if ($return_string) { |
|
282 | + return EEH_Template::display_template($template_path, $template_args, TRUE); |
|
283 | 283 | } else { |
284 | - EEH_Template::display_template( $template_path, $template_args, FALSE ); |
|
284 | + EEH_Template::display_template($template_path, $template_args, FALSE); |
|
285 | 285 | } |
286 | 286 | } |
287 | - return $check_if_custom && ! empty( $template_path ) ? TRUE : $template_path; |
|
287 | + return $check_if_custom && ! empty($template_path) ? TRUE : $template_path; |
|
288 | 288 | } |
289 | 289 | |
290 | 290 | |
@@ -297,21 +297,21 @@ discard block |
||
297 | 297 | * @param array $paths |
298 | 298 | * @return string |
299 | 299 | */ |
300 | - protected static function _find_common_base_path( $paths ) { |
|
300 | + protected static function _find_common_base_path($paths) { |
|
301 | 301 | $last_offset = 0; |
302 | 302 | $common_base_path = ''; |
303 | - while ( ( $index = strpos( $paths[ 0 ], DS, $last_offset ) ) !== false ) { |
|
303 | + while (($index = strpos($paths[0], DS, $last_offset)) !== false) { |
|
304 | 304 | $dir_length = $index - $last_offset + 1; |
305 | - $directory = substr( $paths[ 0 ], $last_offset, $dir_length ); |
|
306 | - foreach ( $paths as $path ) { |
|
307 | - if ( substr( $path, $last_offset, $dir_length ) != $directory ) { |
|
305 | + $directory = substr($paths[0], $last_offset, $dir_length); |
|
306 | + foreach ($paths as $path) { |
|
307 | + if (substr($path, $last_offset, $dir_length) != $directory) { |
|
308 | 308 | return $common_base_path; |
309 | 309 | } |
310 | 310 | } |
311 | 311 | $common_base_path .= $directory; |
312 | 312 | $last_offset = $index + 1; |
313 | 313 | } |
314 | - return substr( $common_base_path, 0, -1 ); |
|
314 | + return substr($common_base_path, 0, -1); |
|
315 | 315 | } |
316 | 316 | |
317 | 317 | |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | * @param boolean $return_string whether to send output immediately to screen, or capture and return as a string |
324 | 324 | * @return mixed string |
325 | 325 | */ |
326 | - public static function display_template( $template_path = FALSE, $template_args = array(), $return_string = FALSE ) { |
|
326 | + public static function display_template($template_path = FALSE, $template_args = array(), $return_string = FALSE) { |
|
327 | 327 | |
328 | 328 | /** |
329 | 329 | * These two filters are intended for last minute changes to templates being loaded and/or template arg |
@@ -334,26 +334,26 @@ discard block |
||
334 | 334 | * |
335 | 335 | * @since 4.6.0 |
336 | 336 | */ |
337 | - $template_path = apply_filters( 'FHEE__EEH_Template__display_template__template_path', $template_path ); |
|
338 | - $template_args = apply_filters( 'FHEE__EEH_Template__display_template__template_args', $template_args ); |
|
337 | + $template_path = apply_filters('FHEE__EEH_Template__display_template__template_path', $template_path); |
|
338 | + $template_args = apply_filters('FHEE__EEH_Template__display_template__template_args', $template_args); |
|
339 | 339 | |
340 | 340 | // you gimme nuttin - YOU GET NUTTIN !! |
341 | - if ( ! $template_path || ! is_readable( $template_path )) { |
|
341 | + if ( ! $template_path || ! is_readable($template_path)) { |
|
342 | 342 | return ''; |
343 | 343 | } |
344 | 344 | // if $template_args are not in an array, then make it so |
345 | - if ( ! is_array( $template_args ) && ! is_object( $template_args )) { |
|
346 | - $template_args = array( $template_args ); |
|
345 | + if ( ! is_array($template_args) && ! is_object($template_args)) { |
|
346 | + $template_args = array($template_args); |
|
347 | 347 | } |
348 | - extract( (array) $template_args); |
|
348 | + extract((array) $template_args); |
|
349 | 349 | |
350 | - if ( $return_string ) { |
|
350 | + if ($return_string) { |
|
351 | 351 | // because we want to return a string, we are going to capture the output |
352 | 352 | ob_start(); |
353 | - include( $template_path ); |
|
353 | + include($template_path); |
|
354 | 354 | return ob_get_clean(); |
355 | 355 | } else { |
356 | - include( $template_path ); |
|
356 | + include($template_path); |
|
357 | 357 | } |
358 | 358 | return ''; |
359 | 359 | } |
@@ -371,27 +371,27 @@ discard block |
||
371 | 371 | * @param string $suffix added to the end of the generated class |
372 | 372 | * @return string |
373 | 373 | */ |
374 | - public static function get_object_css_class( $object = NULL, $prefix = '', $suffix = '' ) { |
|
374 | + public static function get_object_css_class($object = NULL, $prefix = '', $suffix = '') { |
|
375 | 375 | // in the beginning... |
376 | - $prefix = ! empty( $prefix ) ? rtrim( $prefix, '-' ) . '-' : ''; |
|
376 | + $prefix = ! empty($prefix) ? rtrim($prefix, '-').'-' : ''; |
|
377 | 377 | // da muddle |
378 | 378 | $class = ''; |
379 | 379 | // the end |
380 | - $suffix = ! empty( $suffix ) ? '-' . ltrim( $suffix, '-' ) : ''; |
|
380 | + $suffix = ! empty($suffix) ? '-'.ltrim($suffix, '-') : ''; |
|
381 | 381 | // is the passed object an EE object ? |
382 | - if ( $object instanceof EE_Base_Class ) { |
|
382 | + if ($object instanceof EE_Base_Class) { |
|
383 | 383 | // grab the exact type of object |
384 | - $obj_class = get_class( $object ); |
|
384 | + $obj_class = get_class($object); |
|
385 | 385 | // depending on the type of object... |
386 | - switch ( $obj_class ) { |
|
386 | + switch ($obj_class) { |
|
387 | 387 | // no specifics just yet... |
388 | 388 | default : |
389 | - $class = strtolower( str_replace( '_', '-', $obj_class )); |
|
390 | - $class .= method_exists( $obj_class, 'name' ) ? '-' . sanitize_title( $object->name() ) : ''; |
|
389 | + $class = strtolower(str_replace('_', '-', $obj_class)); |
|
390 | + $class .= method_exists($obj_class, 'name') ? '-'.sanitize_title($object->name()) : ''; |
|
391 | 391 | |
392 | 392 | } |
393 | 393 | } |
394 | - return $prefix . $class . $suffix; |
|
394 | + return $prefix.$class.$suffix; |
|
395 | 395 | } |
396 | 396 | |
397 | 397 | |
@@ -407,54 +407,54 @@ discard block |
||
407 | 407 | * @param string $cur_code_span_class |
408 | 408 | * @return string the html output for the formatted money value |
409 | 409 | */ |
410 | - public static function format_currency( $amount = NULL, $return_raw = FALSE, $display_code = TRUE, $CNT_ISO = '', $cur_code_span_class = 'currency-code' ) { |
|
410 | + public static function format_currency($amount = NULL, $return_raw = FALSE, $display_code = TRUE, $CNT_ISO = '', $cur_code_span_class = 'currency-code') { |
|
411 | 411 | // ensure amount was received |
412 | - if ( is_null( $amount ) ) { |
|
413 | - $msg = __( 'In order to format currency, an amount needs to be passed.', 'event_espresso' ); |
|
414 | - EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
412 | + if (is_null($amount)) { |
|
413 | + $msg = __('In order to format currency, an amount needs to be passed.', 'event_espresso'); |
|
414 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
415 | 415 | return ''; |
416 | 416 | } |
417 | 417 | //ensure amount is float |
418 | - $amount = apply_filters( 'FHEE__EEH_Template__format_currency__raw_amount', (float) $amount ); |
|
419 | - $CNT_ISO = apply_filters( 'FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount ); |
|
418 | + $amount = apply_filters('FHEE__EEH_Template__format_currency__raw_amount', (float) $amount); |
|
419 | + $CNT_ISO = apply_filters('FHEE__EEH_Template__format_currency__CNT_ISO', $CNT_ISO, $amount); |
|
420 | 420 | // filter raw amount (allows 0.00 to be changed to "free" for example) |
421 | - $amount_formatted = apply_filters( 'FHEE__EEH_Template__format_currency__amount', $amount, $return_raw ); |
|
421 | + $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount', $amount, $return_raw); |
|
422 | 422 | // still a number or was amount converted to a string like "free" ? |
423 | - if ( is_float( $amount_formatted )) { |
|
423 | + if (is_float($amount_formatted)) { |
|
424 | 424 | // was a country ISO code passed ? if so generate currency config object for that country |
425 | - $mny = $CNT_ISO !== '' ? new EE_Currency_Config( $CNT_ISO ) : NULL; |
|
425 | + $mny = $CNT_ISO !== '' ? new EE_Currency_Config($CNT_ISO) : NULL; |
|
426 | 426 | // verify results |
427 | - if ( ! $mny instanceof EE_Currency_Config ) { |
|
427 | + if ( ! $mny instanceof EE_Currency_Config) { |
|
428 | 428 | // set default config country currency settings |
429 | 429 | $mny = EE_Registry::instance()->CFG->currency instanceof EE_Currency_Config ? EE_Registry::instance()->CFG->currency : new EE_Currency_Config(); |
430 | 430 | } |
431 | 431 | // format float |
432 | - $amount_formatted = number_format( $amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds ); |
|
432 | + $amount_formatted = number_format($amount, $mny->dec_plc, $mny->dec_mrk, $mny->thsnds); |
|
433 | 433 | // add formatting ? |
434 | - if ( ! $return_raw ) { |
|
434 | + if ( ! $return_raw) { |
|
435 | 435 | // add currency sign |
436 | - if( $mny->sign_b4 ){ |
|
437 | - if( $amount >= 0 ){ |
|
438 | - $amount_formatted = $mny->sign . $amount_formatted; |
|
439 | - }else{ |
|
440 | - $amount_formatted = '-' . $mny->sign . str_replace( '-', '', $amount_formatted ); |
|
436 | + if ($mny->sign_b4) { |
|
437 | + if ($amount >= 0) { |
|
438 | + $amount_formatted = $mny->sign.$amount_formatted; |
|
439 | + } else { |
|
440 | + $amount_formatted = '-'.$mny->sign.str_replace('-', '', $amount_formatted); |
|
441 | 441 | } |
442 | 442 | |
443 | - }else{ |
|
444 | - $amount_formatted = $amount_formatted . $mny->sign; |
|
443 | + } else { |
|
444 | + $amount_formatted = $amount_formatted.$mny->sign; |
|
445 | 445 | } |
446 | 446 | |
447 | 447 | // filter to allow global setting of display_code |
448 | - $display_code = apply_filters( 'FHEE__EEH_Template__format_currency__display_code', $display_code ); |
|
448 | + $display_code = apply_filters('FHEE__EEH_Template__format_currency__display_code', $display_code); |
|
449 | 449 | |
450 | 450 | // add currency code ? |
451 | - $amount_formatted = $display_code ? $amount_formatted . ' <span class="' . $cur_code_span_class . '">(' . $mny->code . ')</span>' : $amount_formatted; |
|
451 | + $amount_formatted = $display_code ? $amount_formatted.' <span class="'.$cur_code_span_class.'">('.$mny->code.')</span>' : $amount_formatted; |
|
452 | 452 | } |
453 | 453 | // filter results |
454 | - $amount_formatted = apply_filters( 'FHEE__EEH_Template__format_currency__amount_formatted', $amount_formatted, $mny, $return_raw ); |
|
454 | + $amount_formatted = apply_filters('FHEE__EEH_Template__format_currency__amount_formatted', $amount_formatted, $mny, $return_raw); |
|
455 | 455 | } |
456 | 456 | // clean up vars |
457 | - unset( $mny ); |
|
457 | + unset($mny); |
|
458 | 458 | // return formatted currency amount |
459 | 459 | return $amount_formatted; |
460 | 460 | } |
@@ -469,11 +469,11 @@ discard block |
||
469 | 469 | * @param string $schema 'UPPER', 'lower', or 'Sentence' |
470 | 470 | * @return string The localized label for the status id. |
471 | 471 | */ |
472 | - public static function pretty_status( $status_id, $plural = FALSE, $schema = 'upper' ) { |
|
472 | + public static function pretty_status($status_id, $plural = FALSE, $schema = 'upper') { |
|
473 | 473 | /** @type EEM_Status $EEM_Status */ |
474 | - $EEM_Status = EE_Registry::instance()->load_model( 'Status' ); |
|
475 | - $status = $EEM_Status->localized_status( array( $status_id => __( 'unknown', 'event_espresso' )), $plural, $schema ); |
|
476 | - return $status[ $status_id ]; |
|
474 | + $EEM_Status = EE_Registry::instance()->load_model('Status'); |
|
475 | + $status = $EEM_Status->localized_status(array($status_id => __('unknown', 'event_espresso')), $plural, $schema); |
|
476 | + return $status[$status_id]; |
|
477 | 477 | } |
478 | 478 | |
479 | 479 | |
@@ -488,21 +488,21 @@ discard block |
||
488 | 488 | * @param string $title |
489 | 489 | * @return string the html output for the button |
490 | 490 | */ |
491 | - public static function get_button_or_link( $url, $label, $class = 'button-primary', $icon = '', $title = '' ) { |
|
491 | + public static function get_button_or_link($url, $label, $class = 'button-primary', $icon = '', $title = '') { |
|
492 | 492 | $icon_html = ''; |
493 | - if ( ! empty( $icon ) ) { |
|
494 | - $dashicons = preg_split( "(ee-icon |dashicons )", $icon ); |
|
495 | - $dashicons = array_filter( $dashicons ); |
|
496 | - $count = count( $dashicons ); |
|
493 | + if ( ! empty($icon)) { |
|
494 | + $dashicons = preg_split("(ee-icon |dashicons )", $icon); |
|
495 | + $dashicons = array_filter($dashicons); |
|
496 | + $count = count($dashicons); |
|
497 | 497 | $icon_html .= $count > 1 ? '<span class="ee-composite-dashicon">' : ''; |
498 | - foreach ( $dashicons as $dashicon ) { |
|
499 | - $type = strpos( $dashicon, 'ee-icon' ) !== false ? 'ee-icon ' : 'dashicons '; |
|
500 | - $icon_html .= '<span class="' . $type . $dashicon . '"></span>'; |
|
498 | + foreach ($dashicons as $dashicon) { |
|
499 | + $type = strpos($dashicon, 'ee-icon') !== false ? 'ee-icon ' : 'dashicons '; |
|
500 | + $icon_html .= '<span class="'.$type.$dashicon.'"></span>'; |
|
501 | 501 | } |
502 | 502 | $icon_html .= $count > 1 ? '</span>' : ''; |
503 | 503 | } |
504 | - $label = ! empty( $icon ) ? $icon_html . $label : $label; |
|
505 | - $button = '<a id="' . sanitize_title_with_dashes($label) . '" href="' . $url . '" class="' . $class . '" title="' . $title . '">' . $label . '</a>'; |
|
504 | + $label = ! empty($icon) ? $icon_html.$label : $label; |
|
505 | + $button = '<a id="'.sanitize_title_with_dashes($label).'" href="'.$url.'" class="'.$class.'" title="'.$title.'">'.$label.'</a>'; |
|
506 | 506 | return $button; |
507 | 507 | } |
508 | 508 | |
@@ -519,21 +519,21 @@ discard block |
||
519 | 519 | * @param bool|string $help_text (optional) send help text you want to use for the link if default not to be used |
520 | 520 | * @return string generated link |
521 | 521 | */ |
522 | - public static function get_help_tab_link( $help_tab_id, $page = FALSE, $action = FALSE, $icon_style = FALSE, $help_text = FALSE ) { |
|
522 | + public static function get_help_tab_link($help_tab_id, $page = FALSE, $action = FALSE, $icon_style = FALSE, $help_text = FALSE) { |
|
523 | 523 | |
524 | - if ( ! $page ) |
|
525 | - $page = isset( $_REQUEST['page'] ) && ! empty( $_REQUEST['page'] ) ? sanitize_key( $_REQUEST['page'] ) : $page; |
|
524 | + if ( ! $page) |
|
525 | + $page = isset($_REQUEST['page']) && ! empty($_REQUEST['page']) ? sanitize_key($_REQUEST['page']) : $page; |
|
526 | 526 | |
527 | - if ( ! $action ) |
|
528 | - $action = isset( $_REQUEST['action'] ) && ! empty( $_REQUEST['action'] ) ? sanitize_key( $_REQUEST['action'] ) : $action; |
|
527 | + if ( ! $action) |
|
528 | + $action = isset($_REQUEST['action']) && ! empty($_REQUEST['action']) ? sanitize_key($_REQUEST['action']) : $action; |
|
529 | 529 | |
530 | 530 | $action = empty($action) ? 'default' : $action; |
531 | 531 | |
532 | 532 | |
533 | - $help_tab_lnk = $page . '-' . $action . '-' . $help_tab_id; |
|
534 | - $icon = !$icon_style ? ' dashicons-editor-help' : $icon_style; |
|
535 | - $help_text = !$help_text ? '' : $help_text; |
|
536 | - return '<a id="' . $help_tab_lnk . '" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22' . $icon . '" title="' . esc_attr__('Click to open the \'Help\' tab for more information about this feature.', 'event_espresso') . '" > ' . $help_text . ' </a>'; |
|
533 | + $help_tab_lnk = $page.'-'.$action.'-'.$help_tab_id; |
|
534 | + $icon = ! $icon_style ? ' dashicons-editor-help' : $icon_style; |
|
535 | + $help_text = ! $help_text ? '' : $help_text; |
|
536 | + return '<a id="'.$help_tab_lnk.'" class="ee-clickable dashicons espresso-help-tab-lnk ee-icon-size-22'.$icon.'" title="'.esc_attr__('Click to open the \'Help\' tab for more information about this feature.', 'event_espresso').'" > '.$help_text.' </a>'; |
|
537 | 537 | } |
538 | 538 | |
539 | 539 | |
@@ -545,31 +545,31 @@ discard block |
||
545 | 545 | * @param EE_Help_Tour |
546 | 546 | * @return string html |
547 | 547 | */ |
548 | - public static function help_tour_stops_generator( EE_Help_Tour $tour ) { |
|
548 | + public static function help_tour_stops_generator(EE_Help_Tour $tour) { |
|
549 | 549 | $id = $tour->get_slug(); |
550 | 550 | $stops = $tour->get_stops(); |
551 | 551 | |
552 | - $content = '<ol style="display:none" id="' . $id . '">'; |
|
552 | + $content = '<ol style="display:none" id="'.$id.'">'; |
|
553 | 553 | |
554 | - foreach ( $stops as $stop ) { |
|
555 | - $data_id = !empty( $stop['id'] ) ? ' data-id="' . $stop['id'] . '"' : ''; |
|
556 | - $data_class = empty( $data_id ) && !empty( $stop['class'] ) ? ' data-class="' . $stop['class'] . '"' : ''; |
|
554 | + foreach ($stops as $stop) { |
|
555 | + $data_id = ! empty($stop['id']) ? ' data-id="'.$stop['id'].'"' : ''; |
|
556 | + $data_class = empty($data_id) && ! empty($stop['class']) ? ' data-class="'.$stop['class'].'"' : ''; |
|
557 | 557 | |
558 | 558 | //if container is set to modal then let's make sure we set the options accordingly |
559 | - if ( empty( $data_id ) && empty( $data_class ) ) { |
|
559 | + if (empty($data_id) && empty($data_class)) { |
|
560 | 560 | $stop['options']['modal'] = true; |
561 | 561 | $stop['options']['expose'] = true; |
562 | 562 | } |
563 | 563 | |
564 | - $custom_class = !empty( $stop['custom_class'] ) ? ' class="' . $stop['custom_class'] . '"' : ''; |
|
565 | - $button_text = !empty( $stop['button_text'] ) ? ' data-button="' . $stop['button_text'] . '"' : ''; |
|
564 | + $custom_class = ! empty($stop['custom_class']) ? ' class="'.$stop['custom_class'].'"' : ''; |
|
565 | + $button_text = ! empty($stop['button_text']) ? ' data-button="'.$stop['button_text'].'"' : ''; |
|
566 | 566 | $inner_content = isset($stop['content']) ? $stop['content'] : ''; |
567 | 567 | |
568 | 568 | //options |
569 | - if ( isset( $stop['options'] ) && is_array( $stop['options'] ) ) { |
|
569 | + if (isset($stop['options']) && is_array($stop['options'])) { |
|
570 | 570 | $options = ' data-options="'; |
571 | - foreach ( $stop['options'] as $option => $value ) { |
|
572 | - $options .= $option . ':' . $value . ';'; |
|
571 | + foreach ($stop['options'] as $option => $value) { |
|
572 | + $options .= $option.':'.$value.';'; |
|
573 | 573 | } |
574 | 574 | $options .= '"'; |
575 | 575 | } else { |
@@ -577,7 +577,7 @@ discard block |
||
577 | 577 | } |
578 | 578 | |
579 | 579 | //let's put all together |
580 | - $content .= '<li' . $data_id . $data_class . $custom_class . $button_text . $options . '>' . $inner_content . '</li>'; |
|
580 | + $content .= '<li'.$data_id.$data_class.$custom_class.$button_text.$options.'>'.$inner_content.'</li>'; |
|
581 | 581 | } |
582 | 582 | |
583 | 583 | $content .= '</ol>'; |
@@ -598,31 +598,31 @@ discard block |
||
598 | 598 | * @throws EE_Error |
599 | 599 | * @return string html structure for status. |
600 | 600 | */ |
601 | - public static function status_legend( $status_array, $active_status = '' ) { |
|
602 | - if ( !is_array( $status_array ) ) |
|
603 | - throw new EE_Error( __('The EEH_Template::status_legend helper required the incoming status_array argument to be an array!', 'event_espresso') ); |
|
601 | + public static function status_legend($status_array, $active_status = '') { |
|
602 | + if ( ! is_array($status_array)) |
|
603 | + throw new EE_Error(__('The EEH_Template::status_legend helper required the incoming status_array argument to be an array!', 'event_espresso')); |
|
604 | 604 | |
605 | 605 | $setup_array = array(); |
606 | - foreach ( $status_array as $item => $status ) { |
|
606 | + foreach ($status_array as $item => $status) { |
|
607 | 607 | $setup_array[$item] = array( |
608 | - 'class' => 'ee-status-legend ee-status-legend-' . $status, |
|
609 | - 'desc' => EEH_Template::pretty_status( $status, FALSE, 'sentence' ), |
|
608 | + 'class' => 'ee-status-legend ee-status-legend-'.$status, |
|
609 | + 'desc' => EEH_Template::pretty_status($status, FALSE, 'sentence'), |
|
610 | 610 | 'status' => $status |
611 | 611 | ); |
612 | 612 | } |
613 | 613 | |
614 | - $content = '<div class="ee-list-table-legend-container">' . "\n"; |
|
615 | - $content .= '<h3>' . __('Status Legend', 'event_espresso') . '</h3>' . "\n"; |
|
616 | - $content .= '<dl class="ee-list-table-legend">' . "\n\t"; |
|
617 | - foreach ( $setup_array as $item => $details ) { |
|
614 | + $content = '<div class="ee-list-table-legend-container">'."\n"; |
|
615 | + $content .= '<h3>'.__('Status Legend', 'event_espresso').'</h3>'."\n"; |
|
616 | + $content .= '<dl class="ee-list-table-legend">'."\n\t"; |
|
617 | + foreach ($setup_array as $item => $details) { |
|
618 | 618 | $active_class = $active_status == $details['status'] ? ' class="ee-is-active-status"' : ''; |
619 | - $content .= '<dt id="ee-legend-item-tooltip-' . $item . '"' . $active_class . '>' . "\n\t\t"; |
|
620 | - $content .= '<span class="' . $details['class'] . '"></span>' . "\n\t\t"; |
|
621 | - $content .= '<span class="ee-legend-description">' . $details['desc'] . '</span>' . "\n\t"; |
|
622 | - $content .= '</dt>' . "\n"; |
|
619 | + $content .= '<dt id="ee-legend-item-tooltip-'.$item.'"'.$active_class.'>'."\n\t\t"; |
|
620 | + $content .= '<span class="'.$details['class'].'"></span>'."\n\t\t"; |
|
621 | + $content .= '<span class="ee-legend-description">'.$details['desc'].'</span>'."\n\t"; |
|
622 | + $content .= '</dt>'."\n"; |
|
623 | 623 | } |
624 | - $content .= '</dl>' . "\n"; |
|
625 | - $content .= '</div>' . "\n"; |
|
624 | + $content .= '</dl>'."\n"; |
|
625 | + $content .= '</div>'."\n"; |
|
626 | 626 | return $content; |
627 | 627 | } |
628 | 628 | |
@@ -635,8 +635,8 @@ discard block |
||
635 | 635 | * @return string |
636 | 636 | */ |
637 | 637 | public static function layout_array_as_table($data) { |
638 | - if (is_object($data) || $data instanceof __PHP_Incomplete_Class ) { |
|
639 | - $data = (array)$data; |
|
638 | + if (is_object($data) || $data instanceof __PHP_Incomplete_Class) { |
|
639 | + $data = (array) $data; |
|
640 | 640 | } |
641 | 641 | ob_start(); |
642 | 642 | if (is_array($data)) { |
@@ -649,10 +649,10 @@ discard block |
||
649 | 649 | ?> |
650 | 650 | <tr> |
651 | 651 | <td> |
652 | - <?php echo $data_key;?> |
|
652 | + <?php echo $data_key; ?> |
|
653 | 653 | </td> |
654 | 654 | <td> |
655 | - <?php echo self::layout_array_as_table($data_values);?> |
|
655 | + <?php echo self::layout_array_as_table($data_values); ?> |
|
656 | 656 | </td> |
657 | 657 | </tr> |
658 | 658 | <?php |
@@ -666,7 +666,7 @@ discard block |
||
666 | 666 | <ul> |
667 | 667 | <?php |
668 | 668 | foreach ($data as $datum) { |
669 | - echo "<li>"; echo self::layout_array_as_table($datum);echo "</li>"; |
|
669 | + echo "<li>"; echo self::layout_array_as_table($datum); echo "</li>"; |
|
670 | 670 | }?> |
671 | 671 | </ul> |
672 | 672 | <?php |
@@ -696,8 +696,8 @@ discard block |
||
696 | 696 | * |
697 | 697 | * @return string |
698 | 698 | */ |
699 | - public static function paging_html( $total_items, $current, $per_page, $url, $show_num_field = TRUE, $paged_arg_name = 'paged', $items_label = array() ) { |
|
700 | - echo self::get_paging_html( $total_items, $current, $per_page, $url, $show_num_field, $paged_arg_name, $items_label ); |
|
699 | + public static function paging_html($total_items, $current, $per_page, $url, $show_num_field = TRUE, $paged_arg_name = 'paged', $items_label = array()) { |
|
700 | + echo self::get_paging_html($total_items, $current, $per_page, $url, $show_num_field, $paged_arg_name, $items_label); |
|
701 | 701 | } |
702 | 702 | |
703 | 703 | |
@@ -721,13 +721,13 @@ discard block |
||
721 | 721 | * ) |
722 | 722 | * @return string |
723 | 723 | */ |
724 | - public static function get_paging_html( $total_items, $current, $per_page, $url, $show_num_field = TRUE, $paged_arg_name = 'paged', $items_label = array() ) { |
|
724 | + public static function get_paging_html($total_items, $current, $per_page, $url, $show_num_field = TRUE, $paged_arg_name = 'paged', $items_label = array()) { |
|
725 | 725 | $page_links = array(); |
726 | 726 | $disable_first = $disable_last = ''; |
727 | 727 | $total_items = (int) $total_items; |
728 | 728 | $per_page = (int) $per_page; |
729 | 729 | $current = (int) $current; |
730 | - $paged_arg_name = empty( $paged_arg_name ) ? 'paged' : sanitize_key( $paged_arg_name ); |
|
730 | + $paged_arg_name = empty($paged_arg_name) ? 'paged' : sanitize_key($paged_arg_name); |
|
731 | 731 | |
732 | 732 | //filter items_label |
733 | 733 | $items_label = apply_filters( |
@@ -735,68 +735,68 @@ discard block |
||
735 | 735 | $items_label |
736 | 736 | ); |
737 | 737 | |
738 | - if ( empty( $items_label ) |
|
739 | - || ! is_array( $items_label ) |
|
740 | - || ! isset( $items_label['single'] ) |
|
741 | - || ! isset( $items_label['plural'] ) ) { |
|
738 | + if (empty($items_label) |
|
739 | + || ! is_array($items_label) |
|
740 | + || ! isset($items_label['single']) |
|
741 | + || ! isset($items_label['plural'])) { |
|
742 | 742 | $items_label = array( |
743 | - 'single' => __( '1 item', 'event_espresso' ), |
|
744 | - 'plural' => __( '%s items', 'event_espresso' ) |
|
743 | + 'single' => __('1 item', 'event_espresso'), |
|
744 | + 'plural' => __('%s items', 'event_espresso') |
|
745 | 745 | ); |
746 | 746 | } else { |
747 | 747 | $items_label = array( |
748 | - 'single' => '1 ' . esc_html( $items_label['single'] ), |
|
749 | - 'plural' => '%s ' . esc_html( $items_label['plural'] ) |
|
748 | + 'single' => '1 '.esc_html($items_label['single']), |
|
749 | + 'plural' => '%s '.esc_html($items_label['plural']) |
|
750 | 750 | ); |
751 | 751 | } |
752 | 752 | |
753 | - $total_pages = ceil( $total_items / $per_page ); |
|
753 | + $total_pages = ceil($total_items / $per_page); |
|
754 | 754 | |
755 | - if ( $total_pages <= 1 ) |
|
755 | + if ($total_pages <= 1) |
|
756 | 756 | return ''; |
757 | 757 | |
758 | - $item_label = $total_items > 1 ? sprintf( $items_label['plural'], $total_items ) : $items_label['single']; |
|
758 | + $item_label = $total_items > 1 ? sprintf($items_label['plural'], $total_items) : $items_label['single']; |
|
759 | 759 | |
760 | - $output = '<span class="displaying-num">' . $item_label . '</span>'; |
|
760 | + $output = '<span class="displaying-num">'.$item_label.'</span>'; |
|
761 | 761 | |
762 | - if ( $current === 1 ) { |
|
762 | + if ($current === 1) { |
|
763 | 763 | $disable_first = ' disabled'; |
764 | 764 | } |
765 | - if ( $current == $total_pages ) { |
|
765 | + if ($current == $total_pages) { |
|
766 | 766 | $disable_last = ' disabled'; |
767 | 767 | } |
768 | 768 | |
769 | - $page_links[] = sprintf( "<a class='%s' title='%s' href='%s'>%s</a>", |
|
770 | - 'first-page' . $disable_first, |
|
771 | - esc_attr__( 'Go to the first page' ), |
|
772 | - esc_url( remove_query_arg( $paged_arg_name, $url ) ), |
|
769 | + $page_links[] = sprintf("<a class='%s' title='%s' href='%s'>%s</a>", |
|
770 | + 'first-page'.$disable_first, |
|
771 | + esc_attr__('Go to the first page'), |
|
772 | + esc_url(remove_query_arg($paged_arg_name, $url)), |
|
773 | 773 | '«' |
774 | 774 | ); |
775 | 775 | |
776 | 776 | $page_links[] = sprintf( |
777 | 777 | '<a class="%s" title="%s" href="%s">%s</a>', |
778 | - 'prev-page' . $disable_first, |
|
779 | - esc_attr__( 'Go to the previous page' ), |
|
780 | - esc_url( add_query_arg( $paged_arg_name, max( 1, $current-1 ), $url ) ), |
|
778 | + 'prev-page'.$disable_first, |
|
779 | + esc_attr__('Go to the previous page'), |
|
780 | + esc_url(add_query_arg($paged_arg_name, max(1, $current - 1), $url)), |
|
781 | 781 | '‹' |
782 | 782 | ); |
783 | 783 | |
784 | - if ( ! $show_num_field ) { |
|
784 | + if ( ! $show_num_field) { |
|
785 | 785 | $html_current_page = $current; |
786 | 786 | } else { |
787 | - $html_current_page = sprintf( "<input class='current-page' title='%s' type='text' name=$paged_arg_name value='%s' size='%d' />", |
|
788 | - esc_attr__( 'Current page' ), |
|
787 | + $html_current_page = sprintf("<input class='current-page' title='%s' type='text' name=$paged_arg_name value='%s' size='%d' />", |
|
788 | + esc_attr__('Current page'), |
|
789 | 789 | $current, |
790 | - strlen( $total_pages ) |
|
790 | + strlen($total_pages) |
|
791 | 791 | ); |
792 | 792 | } |
793 | 793 | |
794 | 794 | $html_total_pages = sprintf( |
795 | 795 | '<span class="total-pages">%s</span>', |
796 | - number_format_i18n( $total_pages ) |
|
796 | + number_format_i18n($total_pages) |
|
797 | 797 | ); |
798 | 798 | $page_links[] = sprintf( |
799 | - _x( '%3$s%1$s of %2$s%4$s', 'paging' ), |
|
799 | + _x('%3$s%1$s of %2$s%4$s', 'paging'), |
|
800 | 800 | $html_current_page, |
801 | 801 | $html_total_pages, |
802 | 802 | '<span class="paging-input">', |
@@ -805,29 +805,29 @@ discard block |
||
805 | 805 | |
806 | 806 | $page_links[] = sprintf( |
807 | 807 | '<a class="%s" title="%s" href="%s">%s</a>', |
808 | - 'next-page' . $disable_last, |
|
809 | - esc_attr__( 'Go to the next page' ), |
|
810 | - esc_url( add_query_arg( $paged_arg_name, min( $total_pages, $current+1 ), $url ) ), |
|
808 | + 'next-page'.$disable_last, |
|
809 | + esc_attr__('Go to the next page'), |
|
810 | + esc_url(add_query_arg($paged_arg_name, min($total_pages, $current + 1), $url)), |
|
811 | 811 | '›' |
812 | 812 | ); |
813 | 813 | |
814 | 814 | $page_links[] = sprintf( |
815 | 815 | '<a class="%s" title="%s" href="%s">%s</a>', |
816 | - 'last-page' . $disable_last, |
|
817 | - esc_attr__( 'Go to the last page' ), |
|
818 | - esc_url( add_query_arg( $paged_arg_name, $total_pages, $url ) ), |
|
816 | + 'last-page'.$disable_last, |
|
817 | + esc_attr__('Go to the last page'), |
|
818 | + esc_url(add_query_arg($paged_arg_name, $total_pages, $url)), |
|
819 | 819 | '»' |
820 | 820 | ); |
821 | 821 | |
822 | - $output .= "\n" . '<span class="pagination-links">' . join( "\n", $page_links ) . '</span>'; |
|
822 | + $output .= "\n".'<span class="pagination-links">'.join("\n", $page_links).'</span>'; |
|
823 | 823 | // set page class |
824 | - if ( $total_pages ) { |
|
824 | + if ($total_pages) { |
|
825 | 825 | $page_class = $total_pages < 2 ? ' one-page' : ''; |
826 | 826 | } else { |
827 | 827 | $page_class = ' no-pages'; |
828 | 828 | } |
829 | 829 | |
830 | - return '<div class="tablenav"><div class="tablenav-pages' . $page_class . '">' . $output . '</div></div>'; |
|
830 | + return '<div class="tablenav"><div class="tablenav-pages'.$page_class.'">'.$output.'</div></div>'; |
|
831 | 831 | } |
832 | 832 | |
833 | 833 | |
@@ -837,8 +837,8 @@ discard block |
||
837 | 837 | * @param string $wrap_id |
838 | 838 | * @return string |
839 | 839 | */ |
840 | - public static function powered_by_event_espresso( $wrap_class = '', $wrap_id = '' ) { |
|
841 | - $admin = is_admin() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ); |
|
840 | + public static function powered_by_event_espresso($wrap_class = '', $wrap_id = '') { |
|
841 | + $admin = is_admin() && ! (defined('DOING_AJAX') && DOING_AJAX); |
|
842 | 842 | if ( |
843 | 843 | ! $admin && |
844 | 844 | ! apply_filters( |
@@ -848,17 +848,17 @@ discard block |
||
848 | 848 | ) { |
849 | 849 | return ''; |
850 | 850 | } |
851 | - $attributes = ! empty( $wrap_id ) ? " id=\"{$wrap_id}\"" : ''; |
|
851 | + $attributes = ! empty($wrap_id) ? " id=\"{$wrap_id}\"" : ''; |
|
852 | 852 | $wrap_class = $admin ? "{$wrap_class} float-left" : $wrap_class; |
853 | - $attributes .= ! empty( $wrap_class ) |
|
853 | + $attributes .= ! empty($wrap_class) |
|
854 | 854 | ? " class=\"{$wrap_class} powered-by-event-espresso-credit\"" |
855 | 855 | : ' class="powered-by-event-espresso-credit"'; |
856 | 856 | $powered_by = $admin ? EVENT_ESPRESSO_POWERED_BY : 'Event Espresso'; |
857 | 857 | $url = add_query_arg( |
858 | - array( 'ap_id' => EE_Registry::instance()->CFG->admin->affiliate_id() ), |
|
858 | + array('ap_id' => EE_Registry::instance()->CFG->admin->affiliate_id()), |
|
859 | 859 | 'https://eventespresso.com/' |
860 | 860 | ); |
861 | - $url = apply_filters( 'FHEE__EEH_Template__powered_by_event_espresso__url', $url ); |
|
861 | + $url = apply_filters('FHEE__EEH_Template__powered_by_event_espresso__url', $url); |
|
862 | 862 | return (string) apply_filters( |
863 | 863 | 'FHEE__EEH_Template__powered_by_event_espresso__html', |
864 | 864 | sprintf( |
@@ -888,7 +888,7 @@ discard block |
||
888 | 888 | //add_filter( 'FHEE__EEH_Template__format_currency__amount', 'convert_zero_to_free', 10, 2 ); |
889 | 889 | |
890 | 890 | |
891 | -if ( ! function_exists( 'espresso_pagination' ) ) { |
|
891 | +if ( ! function_exists('espresso_pagination')) { |
|
892 | 892 | /** |
893 | 893 | * espresso_pagination |
894 | 894 | * |
@@ -900,21 +900,21 @@ discard block |
||
900 | 900 | $big = 999999999; // need an unlikely integer |
901 | 901 | $pagination = paginate_links( |
902 | 902 | array( |
903 | - 'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ), |
|
903 | + 'base' => str_replace($big, '%#%', esc_url(get_pagenum_link($big))), |
|
904 | 904 | 'format' => '?paged=%#%', |
905 | - 'current' => max( 1, get_query_var( 'paged' ) ), |
|
905 | + 'current' => max(1, get_query_var('paged')), |
|
906 | 906 | 'total' => $wp_query->max_num_pages, |
907 | 907 | 'show_all' => true, |
908 | 908 | 'end_size' => 10, |
909 | 909 | 'mid_size' => 6, |
910 | 910 | 'prev_next' => true, |
911 | - 'prev_text' => __( '‹ PREV', 'event_espresso' ), |
|
912 | - 'next_text' => __( 'NEXT ›', 'event_espresso' ), |
|
911 | + 'prev_text' => __('‹ PREV', 'event_espresso'), |
|
912 | + 'next_text' => __('NEXT ›', 'event_espresso'), |
|
913 | 913 | 'type' => 'plain', |
914 | 914 | 'add_args' => false, |
915 | 915 | 'add_fragment' => '' |
916 | 916 | ) |
917 | 917 | ); |
918 | - echo ! empty( $pagination ) ? '<div class="ee-pagination-dv clear">' . $pagination . '</div>' : ''; |
|
918 | + echo ! empty($pagination) ? '<div class="ee-pagination-dv clear">'.$pagination.'</div>' : ''; |
|
919 | 919 | } |
920 | 920 | } |
921 | 921 | \ No newline at end of file |
@@ -294,7 +294,7 @@ discard block |
||
294 | 294 | * |
295 | 295 | * given two paths, this determines if there is a common base path between the two |
296 | 296 | * |
297 | - * @param array $paths |
|
297 | + * @param string[] $paths |
|
298 | 298 | * @return string |
299 | 299 | */ |
300 | 300 | protected static function _find_common_base_path( $paths ) { |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | * @param bool|string $template_path server path to the file to be loaded, including file name and extension |
322 | 322 | * @param array $template_args an array of arguments to be extracted for use in the template |
323 | 323 | * @param boolean $return_string whether to send output immediately to screen, or capture and return as a string |
324 | - * @return mixed string |
|
324 | + * @return string string |
|
325 | 325 | */ |
326 | 326 | public static function display_template( $template_path = FALSE, $template_args = array(), $return_string = FALSE ) { |
327 | 327 |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
3 | - exit( 'No direct script access allowed' ); |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | + exit('No direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -25,7 +25,7 @@ discard block |
||
25 | 25 | * @param mixed $info |
26 | 26 | * @return bool |
27 | 27 | */ |
28 | - public function add( $object, $info = null ); |
|
28 | + public function add($object, $info = null); |
|
29 | 29 | |
30 | 30 | |
31 | 31 | |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | * @param mixed $info |
40 | 40 | * @return bool |
41 | 41 | */ |
42 | - public function set_info( $object, $info = null ); |
|
42 | + public function set_info($object, $info = null); |
|
43 | 43 | |
44 | 44 | |
45 | 45 | |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * @param mixed |
53 | 53 | * @return null | object |
54 | 54 | */ |
55 | - public function get_by_info( $info ); |
|
55 | + public function get_by_info($info); |
|
56 | 56 | |
57 | 57 | |
58 | 58 | |
@@ -65,7 +65,7 @@ discard block |
||
65 | 65 | * @param object $object |
66 | 66 | * @return bool |
67 | 67 | */ |
68 | - public function has( $object ); |
|
68 | + public function has($object); |
|
69 | 69 | |
70 | 70 | |
71 | 71 | |
@@ -78,7 +78,7 @@ discard block |
||
78 | 78 | * @param $object |
79 | 79 | * @return void |
80 | 80 | */ |
81 | - public function remove( $object ); |
|
81 | + public function remove($object); |
|
82 | 82 | |
83 | 83 | |
84 | 84 |
@@ -1,6 +1,6 @@ |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
3 | - exit( 'No direct script access allowed' ); |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | + exit('No direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
3 | - exit( 'No direct script access allowed' ); |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | + exit('No direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -30,7 +30,7 @@ discard block |
||
30 | 30 | * @return bool | int |
31 | 31 | * @throws \EE_Error |
32 | 32 | */ |
33 | - public function persist( $persistence_callback = '', $persistence_arguments = array() ); |
|
33 | + public function persist($persistence_callback = '', $persistence_arguments = array()); |
|
34 | 34 | |
35 | 35 | |
36 | 36 | |
@@ -43,7 +43,7 @@ discard block |
||
43 | 43 | * @param string $persistence_callback name of method found on object that can be used for persisting it |
44 | 44 | * @return bool | int |
45 | 45 | */ |
46 | - public function persist_all( $persistence_callback = '' ); |
|
46 | + public function persist_all($persistence_callback = ''); |
|
47 | 47 | |
48 | 48 | } |
49 | 49 | // End of file EEI_Repository.interface.php |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
3 | - exit( 'No direct script access allowed' ); |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | + exit('No direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | /** |
6 | 6 | * Class EEI_Line_Item |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | * @param mixed $field_value |
19 | 19 | * @param bool $use_default |
20 | 20 | */ |
21 | - public function set( $field_name, $field_value, $use_default = false ); |
|
21 | + public function set($field_name, $field_value, $use_default = false); |
|
22 | 22 | |
23 | 23 | |
24 | 24 | |
@@ -56,7 +56,7 @@ discard block |
||
56 | 56 | * Sets quantity |
57 | 57 | * @param int $quantity |
58 | 58 | */ |
59 | - function set_quantity( $quantity ); |
|
59 | + function set_quantity($quantity); |
|
60 | 60 | |
61 | 61 | |
62 | 62 | |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | * @param int $txn_id if none is provided, assumes $this->TXN_ID() |
116 | 116 | * @return int count of items saved |
117 | 117 | */ |
118 | - function save_this_and_descendants_to_txn( $txn_id = null ); |
|
118 | + function save_this_and_descendants_to_txn($txn_id = null); |
|
119 | 119 | |
120 | 120 | |
121 | 121 | |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | * @param bool $set_order |
143 | 143 | * @return bool true for success, false for fail |
144 | 144 | */ |
145 | - function add_child_line_item( EEI_Line_Item $line_item, $set_order = true ); |
|
145 | + function add_child_line_item(EEI_Line_Item $line_item, $set_order = true); |
|
146 | 146 | |
147 | 147 | |
148 | 148 | |
@@ -197,14 +197,14 @@ discard block |
||
197 | 197 | * @param float $total |
198 | 198 | * @return boolean |
199 | 199 | */ |
200 | - function set_total( $total ); |
|
200 | + function set_total($total); |
|
201 | 201 | |
202 | 202 | /** |
203 | 203 | * Sets unit_price |
204 | 204 | * @param float $unit_price |
205 | 205 | * @return boolean |
206 | 206 | */ |
207 | - function set_unit_price( $unit_price ); |
|
207 | + function set_unit_price($unit_price); |
|
208 | 208 | |
209 | 209 | /** |
210 | 210 | * If this line item has been saved to the DB, deletes its child with LIN_code == $code. If this line |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | * @param bool $stop_search_once_found |
216 | 216 | * @return int count of items deleted (or simply removed from the line item's cache, if not has not been saved to the DB yet) |
217 | 217 | */ |
218 | - function delete_child_line_item( $code, $stop_search_once_found = true ); |
|
218 | + function delete_child_line_item($code, $stop_search_once_found = true); |
|
219 | 219 | |
220 | 220 | /** |
221 | 221 | * Forgets the cached model of the given relation Name. So the next time we request it, |
@@ -238,7 +238,7 @@ discard block |
||
238 | 238 | * @param boolean $allow_persist |
239 | 239 | * @return boolean |
240 | 240 | */ |
241 | - function set_allow_persist( $allow_persist ); |
|
241 | + function set_allow_persist($allow_persist); |
|
242 | 242 | |
243 | 243 | |
244 | 244 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
3 | - exit( 'No direct script access allowed' ); |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | + exit('No direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -26,7 +26,7 @@ discard block |
||
26 | 26 | * @param \EEI_Line_Item $line_item |
27 | 27 | * @return \EEI_Line_Item |
28 | 28 | */ |
29 | - public function process( EEI_Line_Item $line_item ); |
|
29 | + public function process(EEI_Line_Item $line_item); |
|
30 | 30 | |
31 | 31 | |
32 | 32 |