@@ -6,63 +6,63 @@ |
||
6 | 6 | interface EEI_Transaction extends EEI_Base |
7 | 7 | { |
8 | 8 | |
9 | - /** |
|
10 | - * @return EEI_Payment |
|
11 | - */ |
|
12 | - public function last_payment(); |
|
9 | + /** |
|
10 | + * @return EEI_Payment |
|
11 | + */ |
|
12 | + public function last_payment(); |
|
13 | 13 | |
14 | 14 | |
15 | 15 | |
16 | - /** |
|
17 | - * Gets the total that should eb paid for this transaction |
|
18 | - * |
|
19 | - * @return float |
|
20 | - */ |
|
21 | - public function total(); |
|
16 | + /** |
|
17 | + * Gets the total that should eb paid for this transaction |
|
18 | + * |
|
19 | + * @return float |
|
20 | + */ |
|
21 | + public function total(); |
|
22 | 22 | |
23 | 23 | |
24 | 24 | |
25 | - /** |
|
26 | - * Get the line item that represents the total for the transaction |
|
27 | - * |
|
28 | - * @return EE_Line_Item |
|
29 | - */ |
|
30 | - public function total_line_item(); |
|
25 | + /** |
|
26 | + * Get the line item that represents the total for the transaction |
|
27 | + * |
|
28 | + * @return EE_Line_Item |
|
29 | + */ |
|
30 | + public function total_line_item(); |
|
31 | 31 | |
32 | 32 | |
33 | 33 | |
34 | - /** |
|
35 | - * Gets the primary registration for this transaction |
|
36 | - * |
|
37 | - * @return EEI_Registration |
|
38 | - */ |
|
39 | - public function primary_registration(); |
|
34 | + /** |
|
35 | + * Gets the primary registration for this transaction |
|
36 | + * |
|
37 | + * @return EEI_Registration |
|
38 | + */ |
|
39 | + public function primary_registration(); |
|
40 | 40 | |
41 | 41 | |
42 | 42 | |
43 | - /** |
|
44 | - * Returns the balance due on the transaction |
|
45 | - * |
|
46 | - * @return float |
|
47 | - */ |
|
48 | - public function remaining(); |
|
43 | + /** |
|
44 | + * Returns the balance due on the transaction |
|
45 | + * |
|
46 | + * @return float |
|
47 | + */ |
|
48 | + public function remaining(); |
|
49 | 49 | |
50 | 50 | |
51 | 51 | |
52 | - /** |
|
53 | - * get Total Amount Paid to Date |
|
54 | - * |
|
55 | - * @access public |
|
56 | - * @return float |
|
57 | - */ |
|
58 | - public function paid(); |
|
52 | + /** |
|
53 | + * get Total Amount Paid to Date |
|
54 | + * |
|
55 | + * @access public |
|
56 | + * @return float |
|
57 | + */ |
|
58 | + public function paid(); |
|
59 | 59 | |
60 | 60 | |
61 | 61 | |
62 | - /** |
|
63 | - * Retrieves all the pending payments on this transaction |
|
64 | - * |
|
65 | - * @return EEI_Payment[] |
|
66 | - */ |
|
67 | - public function pending_payments(); |
|
62 | + /** |
|
63 | + * Retrieves all the pending payments on this transaction |
|
64 | + * |
|
65 | + * @return EEI_Payment[] |
|
66 | + */ |
|
67 | + public function pending_payments(); |
|
68 | 68 | } |
@@ -15,11 +15,11 @@ |
||
15 | 15 | */ |
16 | 16 | interface EE_Line_Item_Filter |
17 | 17 | { |
18 | - /** |
|
19 | - * process |
|
20 | - * |
|
21 | - * @param EE_Line_Item $line_item |
|
22 | - * @return EE_Line_Item |
|
23 | - */ |
|
24 | - public function process(EE_Line_Item $line_item): ?EE_Line_Item; |
|
18 | + /** |
|
19 | + * process |
|
20 | + * |
|
21 | + * @param EE_Line_Item $line_item |
|
22 | + * @return EE_Line_Item |
|
23 | + */ |
|
24 | + public function process(EE_Line_Item $line_item): ?EE_Line_Item; |
|
25 | 25 | } |
@@ -11,231 +11,231 @@ |
||
11 | 11 | interface EEI_Line_Item |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * generic setter |
|
16 | - * @param string $field_name |
|
17 | - * @param mixed $field_value |
|
18 | - * @param bool $use_default |
|
19 | - */ |
|
20 | - public function set($field_name, $field_value, $use_default = false); |
|
14 | + /** |
|
15 | + * generic setter |
|
16 | + * @param string $field_name |
|
17 | + * @param mixed $field_value |
|
18 | + * @param bool $use_default |
|
19 | + */ |
|
20 | + public function set($field_name, $field_value, $use_default = false); |
|
21 | 21 | |
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * @return string |
|
26 | - */ |
|
27 | - public function name(); |
|
24 | + /** |
|
25 | + * @return string |
|
26 | + */ |
|
27 | + public function name(); |
|
28 | 28 | |
29 | 29 | |
30 | 30 | |
31 | - /** |
|
32 | - * @return string |
|
33 | - */ |
|
34 | - public function desc(); |
|
31 | + /** |
|
32 | + * @return string |
|
33 | + */ |
|
34 | + public function desc(); |
|
35 | 35 | |
36 | 36 | |
37 | 37 | |
38 | - /** |
|
39 | - * The unit price for the items of this line item |
|
40 | - * @return float |
|
41 | - */ |
|
42 | - public function unit_price(); |
|
38 | + /** |
|
39 | + * The unit price for the items of this line item |
|
40 | + * @return float |
|
41 | + */ |
|
42 | + public function unit_price(); |
|
43 | 43 | |
44 | 44 | |
45 | 45 | |
46 | - /** |
|
47 | - * Returns the number of items in this line item |
|
48 | - * @return int |
|
49 | - */ |
|
50 | - public function quantity(); |
|
46 | + /** |
|
47 | + * Returns the number of items in this line item |
|
48 | + * @return int |
|
49 | + */ |
|
50 | + public function quantity(); |
|
51 | 51 | |
52 | 52 | |
53 | 53 | |
54 | - /** |
|
55 | - * Sets quantity |
|
56 | - * @param int $quantity |
|
57 | - */ |
|
58 | - public function set_quantity($quantity); |
|
54 | + /** |
|
55 | + * Sets quantity |
|
56 | + * @param int $quantity |
|
57 | + */ |
|
58 | + public function set_quantity($quantity); |
|
59 | 59 | |
60 | 60 | |
61 | 61 | |
62 | - /** |
|
63 | - * Returns the total amount due for this line item |
|
64 | - * (usually quantity x unit_price) |
|
65 | - * @return float |
|
66 | - */ |
|
67 | - public function total(); |
|
62 | + /** |
|
63 | + * Returns the total amount due for this line item |
|
64 | + * (usually quantity x unit_price) |
|
65 | + * @return float |
|
66 | + */ |
|
67 | + public function total(); |
|
68 | 68 | |
69 | 69 | |
70 | 70 | |
71 | - /** |
|
72 | - * Gets all teh children line items of type 'line-item' |
|
73 | - * @return EE_Line_Item[] |
|
74 | - */ |
|
75 | - public function get_items(); |
|
71 | + /** |
|
72 | + * Gets all teh children line items of type 'line-item' |
|
73 | + * @return EE_Line_Item[] |
|
74 | + */ |
|
75 | + public function get_items(); |
|
76 | 76 | |
77 | 77 | |
78 | 78 | |
79 | - /** |
|
80 | - * Gets the total for all the items purchased only |
|
81 | - * @return float |
|
82 | - */ |
|
83 | - public function get_items_total(); |
|
79 | + /** |
|
80 | + * Gets the total for all the items purchased only |
|
81 | + * @return float |
|
82 | + */ |
|
83 | + public function get_items_total(); |
|
84 | 84 | |
85 | 85 | |
86 | 86 | |
87 | - /** |
|
88 | - * Gets all the children line items of type 'tax' |
|
89 | - * @return EE_Line_Item[] |
|
90 | - */ |
|
91 | - public function tax_descendants(); |
|
87 | + /** |
|
88 | + * Gets all the children line items of type 'tax' |
|
89 | + * @return EE_Line_Item[] |
|
90 | + */ |
|
91 | + public function tax_descendants(); |
|
92 | 92 | |
93 | 93 | |
94 | 94 | |
95 | - /** |
|
96 | - * Gets the total amount of the tax sub-line items |
|
97 | - * @return float |
|
98 | - */ |
|
99 | - public function get_total_tax(); |
|
95 | + /** |
|
96 | + * Gets the total amount of the tax sub-line items |
|
97 | + * @return float |
|
98 | + */ |
|
99 | + public function get_total_tax(); |
|
100 | 100 | |
101 | 101 | |
102 | 102 | |
103 | - /** |
|
104 | - * Returns the name of the event the ticket is for |
|
105 | - * @return string |
|
106 | - */ |
|
107 | - public function ticket_event_name(); |
|
103 | + /** |
|
104 | + * Returns the name of the event the ticket is for |
|
105 | + * @return string |
|
106 | + */ |
|
107 | + public function ticket_event_name(); |
|
108 | 108 | |
109 | 109 | |
110 | 110 | |
111 | - /** |
|
112 | - * Saves this line item to the DB, and recursively saves its descendants. |
|
113 | - * Also sets the transaction on this line item and all its descendants before saving |
|
114 | - * @param int $txn_id if none is provided, assumes $this->TXN_ID() |
|
115 | - * @return int count of items saved |
|
116 | - */ |
|
117 | - public function save_this_and_descendants_to_txn($txn_id = null); |
|
111 | + /** |
|
112 | + * Saves this line item to the DB, and recursively saves its descendants. |
|
113 | + * Also sets the transaction on this line item and all its descendants before saving |
|
114 | + * @param int $txn_id if none is provided, assumes $this->TXN_ID() |
|
115 | + * @return int count of items saved |
|
116 | + */ |
|
117 | + public function save_this_and_descendants_to_txn($txn_id = null); |
|
118 | 118 | |
119 | 119 | |
120 | 120 | |
121 | - /** |
|
122 | - * Indicates whether or not taxes should apply to this line item |
|
123 | - * @return boolean |
|
124 | - */ |
|
125 | - public function is_taxable(); |
|
121 | + /** |
|
122 | + * Indicates whether or not taxes should apply to this line item |
|
123 | + * @return boolean |
|
124 | + */ |
|
125 | + public function is_taxable(); |
|
126 | 126 | |
127 | 127 | |
128 | 128 | |
129 | - /** |
|
130 | - * Gets ALL the children of this line item (ie, all the parts that contribute towards this total). |
|
131 | - * @return EE_Line_Item[] |
|
132 | - */ |
|
133 | - public function children(); |
|
129 | + /** |
|
130 | + * Gets ALL the children of this line item (ie, all the parts that contribute towards this total). |
|
131 | + * @return EE_Line_Item[] |
|
132 | + */ |
|
133 | + public function children(); |
|
134 | 134 | |
135 | 135 | |
136 | 136 | |
137 | - /** |
|
138 | - * Adds the line item as a child to this line item. If there is another child line |
|
139 | - * item with the same LIN_code, it is overwritten by this new one |
|
140 | - * @param EE_Line_Item $line_item |
|
141 | - * @param bool $set_order |
|
142 | - * @return bool true for success, false for fail |
|
143 | - */ |
|
144 | - public function add_child_line_item(EE_Line_Item $line_item, $set_order = true); |
|
137 | + /** |
|
138 | + * Adds the line item as a child to this line item. If there is another child line |
|
139 | + * item with the same LIN_code, it is overwritten by this new one |
|
140 | + * @param EE_Line_Item $line_item |
|
141 | + * @param bool $set_order |
|
142 | + * @return bool true for success, false for fail |
|
143 | + */ |
|
144 | + public function add_child_line_item(EE_Line_Item $line_item, $set_order = true); |
|
145 | 145 | |
146 | 146 | |
147 | 147 | |
148 | - /** |
|
149 | - * Gets the line item type |
|
150 | - * @return string |
|
151 | - */ |
|
152 | - public function type(); |
|
148 | + /** |
|
149 | + * Gets the line item type |
|
150 | + * @return string |
|
151 | + */ |
|
152 | + public function type(); |
|
153 | 153 | |
154 | 154 | |
155 | 155 | |
156 | - /** |
|
157 | - * Gets item_id |
|
158 | - * @return string |
|
159 | - */ |
|
160 | - public function OBJ_ID(); |
|
156 | + /** |
|
157 | + * Gets item_id |
|
158 | + * @return string |
|
159 | + */ |
|
160 | + public function OBJ_ID(); |
|
161 | 161 | |
162 | 162 | |
163 | 163 | |
164 | - /** |
|
165 | - * Gets the related item type ( like: Ticket or Event ) |
|
166 | - * @return string |
|
167 | - */ |
|
168 | - public function OBJ_type(); |
|
164 | + /** |
|
165 | + * Gets the related item type ( like: Ticket or Event ) |
|
166 | + * @return string |
|
167 | + */ |
|
168 | + public function OBJ_type(); |
|
169 | 169 | |
170 | 170 | |
171 | 171 | |
172 | - /** |
|
173 | - * Gets the final total on this item, taking taxes into account. |
|
174 | - * Has the side-effect of setting the sub-total as it was just calculated. |
|
175 | - * If this is used on a grand-total line item, also updates the transaction's |
|
176 | - * TXN_total |
|
177 | - * @return float |
|
178 | - */ |
|
179 | - public function recalculate_total_including_taxes(); |
|
172 | + /** |
|
173 | + * Gets the final total on this item, taking taxes into account. |
|
174 | + * Has the side-effect of setting the sub-total as it was just calculated. |
|
175 | + * If this is used on a grand-total line item, also updates the transaction's |
|
176 | + * TXN_total |
|
177 | + * @return float |
|
178 | + */ |
|
179 | + public function recalculate_total_including_taxes(); |
|
180 | 180 | |
181 | - /** |
|
182 | - * Checks if this item is a percentage modifier or not |
|
183 | - * @throws EE_Error |
|
184 | - * @return boolean |
|
185 | - */ |
|
186 | - public function is_percent(); |
|
187 | - |
|
188 | - /** |
|
189 | - * Gets percent (between 100-.001) |
|
190 | - * @return float |
|
191 | - */ |
|
192 | - public function percent(); |
|
193 | - |
|
194 | - /** |
|
195 | - * Sets total |
|
196 | - * @param float $total |
|
197 | - * @return boolean |
|
198 | - */ |
|
199 | - public function set_total($total); |
|
200 | - |
|
201 | - /** |
|
202 | - * Sets unit_price |
|
203 | - * @param float $unit_price |
|
204 | - * @return boolean |
|
205 | - */ |
|
206 | - public function set_unit_price($unit_price); |
|
207 | - |
|
208 | - /** |
|
209 | - * If this line item has been saved to the DB, deletes its child with LIN_code == $code. If this line |
|
210 | - * HAS NOT been saved to the DB, removes the child line item with index $code. |
|
211 | - * Also searches through the child's children for a matching line item. However, once a line item has been found |
|
212 | - * and deleted, stops searching (so if there are line items with duplicate codes, only the first one found will be deleted) |
|
213 | - * @param string $code |
|
214 | - * @param bool $stop_search_once_found |
|
215 | - * @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) |
|
216 | - */ |
|
217 | - public function delete_child_line_item($code, $stop_search_once_found = true); |
|
218 | - |
|
219 | - /** |
|
220 | - * Forgets the cached model of the given relation Name. So the next time we request it, |
|
221 | - * we will fetch it again from the database. (Handy if you know it's changed somehow). |
|
222 | - * If a specific object is supplied, and the relationship to it is either a HasMany or HABTM, |
|
223 | - * then only remove that one object from our cached array. Otherwise, clear the entire list |
|
224 | - * @param string $relationName one of the keys in the _model_relations array on the model. Eg 'Registration' |
|
225 | - * @param mixed $object_to_remove_or_index_into_array or an index into the array of cached things, or NULL |
|
226 | - * if you intend to use $clear_all = TRUE, or the relation only has 1 object anyways (ie, it's a BelongsToRelation) |
|
227 | - * @param bool $clear_all This flags clearing the entire cache relation property if this is HasMany or HABTM. |
|
228 | - * @throws EE_Error |
|
229 | - * @return EE_Base_Class | boolean from which was cleared from the cache, or true if we requested to remove a relation from all |
|
230 | - */ |
|
231 | - public function clear_cache($relationName, $object_to_remove_or_index_into_array = null, $clear_all = false); |
|
232 | - |
|
233 | - /** |
|
234 | - * Sets whether or not this model object should be allowed to be saved to the DB. |
|
235 | - * Normally once this is set to FALSE you wouldn't set it back to TRUE, unless |
|
236 | - * you got new information that somehow made you change your mind. |
|
237 | - * @param boolean $allow_persist |
|
238 | - * @return boolean |
|
239 | - */ |
|
240 | - public function set_allow_persist($allow_persist); |
|
181 | + /** |
|
182 | + * Checks if this item is a percentage modifier or not |
|
183 | + * @throws EE_Error |
|
184 | + * @return boolean |
|
185 | + */ |
|
186 | + public function is_percent(); |
|
187 | + |
|
188 | + /** |
|
189 | + * Gets percent (between 100-.001) |
|
190 | + * @return float |
|
191 | + */ |
|
192 | + public function percent(); |
|
193 | + |
|
194 | + /** |
|
195 | + * Sets total |
|
196 | + * @param float $total |
|
197 | + * @return boolean |
|
198 | + */ |
|
199 | + public function set_total($total); |
|
200 | + |
|
201 | + /** |
|
202 | + * Sets unit_price |
|
203 | + * @param float $unit_price |
|
204 | + * @return boolean |
|
205 | + */ |
|
206 | + public function set_unit_price($unit_price); |
|
207 | + |
|
208 | + /** |
|
209 | + * If this line item has been saved to the DB, deletes its child with LIN_code == $code. If this line |
|
210 | + * HAS NOT been saved to the DB, removes the child line item with index $code. |
|
211 | + * Also searches through the child's children for a matching line item. However, once a line item has been found |
|
212 | + * and deleted, stops searching (so if there are line items with duplicate codes, only the first one found will be deleted) |
|
213 | + * @param string $code |
|
214 | + * @param bool $stop_search_once_found |
|
215 | + * @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) |
|
216 | + */ |
|
217 | + public function delete_child_line_item($code, $stop_search_once_found = true); |
|
218 | + |
|
219 | + /** |
|
220 | + * Forgets the cached model of the given relation Name. So the next time we request it, |
|
221 | + * we will fetch it again from the database. (Handy if you know it's changed somehow). |
|
222 | + * If a specific object is supplied, and the relationship to it is either a HasMany or HABTM, |
|
223 | + * then only remove that one object from our cached array. Otherwise, clear the entire list |
|
224 | + * @param string $relationName one of the keys in the _model_relations array on the model. Eg 'Registration' |
|
225 | + * @param mixed $object_to_remove_or_index_into_array or an index into the array of cached things, or NULL |
|
226 | + * if you intend to use $clear_all = TRUE, or the relation only has 1 object anyways (ie, it's a BelongsToRelation) |
|
227 | + * @param bool $clear_all This flags clearing the entire cache relation property if this is HasMany or HABTM. |
|
228 | + * @throws EE_Error |
|
229 | + * @return EE_Base_Class | boolean from which was cleared from the cache, or true if we requested to remove a relation from all |
|
230 | + */ |
|
231 | + public function clear_cache($relationName, $object_to_remove_or_index_into_array = null, $clear_all = false); |
|
232 | + |
|
233 | + /** |
|
234 | + * Sets whether or not this model object should be allowed to be saved to the DB. |
|
235 | + * Normally once this is set to FALSE you wouldn't set it back to TRUE, unless |
|
236 | + * you got new information that somehow made you change your mind. |
|
237 | + * @param boolean $allow_persist |
|
238 | + * @return boolean |
|
239 | + */ |
|
240 | + public function set_allow_persist($allow_persist); |
|
241 | 241 | } |
@@ -13,369 +13,369 @@ |
||
13 | 13 | class EEM_Price extends EEM_Soft_Delete_Base |
14 | 14 | { |
15 | 15 | |
16 | - // private instance of the EEM_Price object |
|
17 | - protected static $_instance; |
|
16 | + // private instance of the EEM_Price object |
|
17 | + protected static $_instance; |
|
18 | 18 | |
19 | 19 | |
20 | - /** |
|
21 | - * private constructor to prevent direct creation |
|
22 | - * |
|
23 | - * @Constructor |
|
24 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings |
|
25 | - * (and any incoming timezone data that gets saved). |
|
26 | - * Note this just sends the timezone info to the date time model field objects. |
|
27 | - * Default is NULL |
|
28 | - * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
29 | - */ |
|
30 | - protected function __construct($timezone) |
|
31 | - { |
|
32 | - require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
33 | - $this->singular_item = __('Price', 'event_espresso'); |
|
34 | - $this->plural_item = __('Prices', 'event_espresso'); |
|
20 | + /** |
|
21 | + * private constructor to prevent direct creation |
|
22 | + * |
|
23 | + * @Constructor |
|
24 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings |
|
25 | + * (and any incoming timezone data that gets saved). |
|
26 | + * Note this just sends the timezone info to the date time model field objects. |
|
27 | + * Default is NULL |
|
28 | + * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
29 | + */ |
|
30 | + protected function __construct($timezone) |
|
31 | + { |
|
32 | + require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
33 | + $this->singular_item = __('Price', 'event_espresso'); |
|
34 | + $this->plural_item = __('Prices', 'event_espresso'); |
|
35 | 35 | |
36 | - $this->_tables = [ |
|
37 | - 'Price' => new EE_Primary_Table('esp_price', 'PRC_ID'), |
|
38 | - ]; |
|
39 | - $this->_fields = [ |
|
40 | - 'Price' => [ |
|
41 | - 'PRC_ID' => new EE_Primary_Key_Int_Field( |
|
42 | - 'PRC_ID', |
|
43 | - 'Price ID' |
|
44 | - ), |
|
45 | - 'PRT_ID' => new EE_Foreign_Key_Int_Field( |
|
46 | - 'PRT_ID', |
|
47 | - esc_html__('Price type Id', 'event_espresso'), |
|
48 | - false, |
|
49 | - null, |
|
50 | - 'Price_Type' |
|
51 | - ), |
|
52 | - 'PRC_amount' => new EE_Money_Field( |
|
53 | - 'PRC_amount', |
|
54 | - esc_html__('Price Amount', 'event_espresso'), |
|
55 | - false, |
|
56 | - 0 |
|
57 | - ), |
|
58 | - 'PRC_name' => new EE_Plain_Text_Field( |
|
59 | - 'PRC_name', |
|
60 | - esc_html__('Name of Price', 'event_espresso'), |
|
61 | - false, |
|
62 | - '' |
|
63 | - ), |
|
64 | - 'PRC_desc' => new EE_Post_Content_Field( |
|
65 | - 'PRC_desc', |
|
66 | - esc_html__('Price Description', 'event_espresso'), |
|
67 | - false, |
|
68 | - '' |
|
69 | - ), |
|
70 | - 'PRC_is_default' => new EE_Boolean_Field( |
|
71 | - 'PRC_is_default', |
|
72 | - esc_html__('Flag indicating whether price is a default price', 'event_espresso'), |
|
73 | - false, |
|
74 | - false |
|
75 | - ), |
|
76 | - 'PRC_overrides' => new EE_Integer_Field( |
|
77 | - 'PRC_overrides', |
|
78 | - esc_html__( |
|
79 | - 'Price ID for a global Price that will be overridden by this Price ( for replacing default prices )', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - true, |
|
83 | - 0 |
|
84 | - ), |
|
85 | - 'PRC_order' => new EE_Integer_Field( |
|
86 | - 'PRC_order', |
|
87 | - esc_html__( |
|
88 | - 'Order of Application of Price (lower numbers apply first?)', |
|
89 | - 'event_espresso' |
|
90 | - ), |
|
91 | - false, |
|
92 | - 1 |
|
93 | - ), |
|
94 | - 'PRC_deleted' => new EE_Trashed_Flag_Field( |
|
95 | - 'PRC_deleted', |
|
96 | - esc_html__('Flag Indicating if this has been deleted or not', 'event_espresso'), |
|
97 | - false, |
|
98 | - false |
|
99 | - ), |
|
100 | - 'PRC_parent' => new EE_Integer_Field( |
|
101 | - 'PRC_parent', |
|
102 | - esc_html__('Indicates what PRC_ID is the parent of this PRC_ID', 'event_espresso'), |
|
103 | - true, |
|
104 | - 0 |
|
105 | - ), |
|
106 | - 'PRC_wp_user' => new EE_WP_User_Field( |
|
107 | - 'PRC_wp_user', |
|
108 | - esc_html__('Price Creator ID', 'event_espresso'), |
|
109 | - false |
|
110 | - ), |
|
111 | - ], |
|
112 | - ]; |
|
113 | - $this->_model_relations = [ |
|
114 | - 'Ticket' => new EE_HABTM_Relation('Ticket_Price'), |
|
115 | - 'Price_Type' => new EE_Belongs_To_Relation(), |
|
116 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
117 | - ]; |
|
118 | - // this model is generally available for reading |
|
119 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = |
|
120 | - new EE_Restriction_Generator_Default_Public( |
|
121 | - 'PRC_is_default', |
|
122 | - 'Ticket.Datetime.Event' |
|
123 | - ); |
|
124 | - // account for default tickets in the caps |
|
125 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
126 | - new EE_Restriction_Generator_Default_Protected( |
|
127 | - 'PRC_is_default', |
|
128 | - 'Ticket.Datetime.Event' |
|
129 | - ); |
|
130 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = |
|
131 | - new EE_Restriction_Generator_Default_Protected( |
|
132 | - 'PRC_is_default', |
|
133 | - 'Ticket.Datetime.Event' |
|
134 | - ); |
|
135 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
136 | - new EE_Restriction_Generator_Default_Protected( |
|
137 | - 'PRC_is_default', |
|
138 | - 'Ticket.Datetime.Event' |
|
139 | - ); |
|
140 | - parent::__construct($timezone); |
|
141 | - } |
|
36 | + $this->_tables = [ |
|
37 | + 'Price' => new EE_Primary_Table('esp_price', 'PRC_ID'), |
|
38 | + ]; |
|
39 | + $this->_fields = [ |
|
40 | + 'Price' => [ |
|
41 | + 'PRC_ID' => new EE_Primary_Key_Int_Field( |
|
42 | + 'PRC_ID', |
|
43 | + 'Price ID' |
|
44 | + ), |
|
45 | + 'PRT_ID' => new EE_Foreign_Key_Int_Field( |
|
46 | + 'PRT_ID', |
|
47 | + esc_html__('Price type Id', 'event_espresso'), |
|
48 | + false, |
|
49 | + null, |
|
50 | + 'Price_Type' |
|
51 | + ), |
|
52 | + 'PRC_amount' => new EE_Money_Field( |
|
53 | + 'PRC_amount', |
|
54 | + esc_html__('Price Amount', 'event_espresso'), |
|
55 | + false, |
|
56 | + 0 |
|
57 | + ), |
|
58 | + 'PRC_name' => new EE_Plain_Text_Field( |
|
59 | + 'PRC_name', |
|
60 | + esc_html__('Name of Price', 'event_espresso'), |
|
61 | + false, |
|
62 | + '' |
|
63 | + ), |
|
64 | + 'PRC_desc' => new EE_Post_Content_Field( |
|
65 | + 'PRC_desc', |
|
66 | + esc_html__('Price Description', 'event_espresso'), |
|
67 | + false, |
|
68 | + '' |
|
69 | + ), |
|
70 | + 'PRC_is_default' => new EE_Boolean_Field( |
|
71 | + 'PRC_is_default', |
|
72 | + esc_html__('Flag indicating whether price is a default price', 'event_espresso'), |
|
73 | + false, |
|
74 | + false |
|
75 | + ), |
|
76 | + 'PRC_overrides' => new EE_Integer_Field( |
|
77 | + 'PRC_overrides', |
|
78 | + esc_html__( |
|
79 | + 'Price ID for a global Price that will be overridden by this Price ( for replacing default prices )', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + true, |
|
83 | + 0 |
|
84 | + ), |
|
85 | + 'PRC_order' => new EE_Integer_Field( |
|
86 | + 'PRC_order', |
|
87 | + esc_html__( |
|
88 | + 'Order of Application of Price (lower numbers apply first?)', |
|
89 | + 'event_espresso' |
|
90 | + ), |
|
91 | + false, |
|
92 | + 1 |
|
93 | + ), |
|
94 | + 'PRC_deleted' => new EE_Trashed_Flag_Field( |
|
95 | + 'PRC_deleted', |
|
96 | + esc_html__('Flag Indicating if this has been deleted or not', 'event_espresso'), |
|
97 | + false, |
|
98 | + false |
|
99 | + ), |
|
100 | + 'PRC_parent' => new EE_Integer_Field( |
|
101 | + 'PRC_parent', |
|
102 | + esc_html__('Indicates what PRC_ID is the parent of this PRC_ID', 'event_espresso'), |
|
103 | + true, |
|
104 | + 0 |
|
105 | + ), |
|
106 | + 'PRC_wp_user' => new EE_WP_User_Field( |
|
107 | + 'PRC_wp_user', |
|
108 | + esc_html__('Price Creator ID', 'event_espresso'), |
|
109 | + false |
|
110 | + ), |
|
111 | + ], |
|
112 | + ]; |
|
113 | + $this->_model_relations = [ |
|
114 | + 'Ticket' => new EE_HABTM_Relation('Ticket_Price'), |
|
115 | + 'Price_Type' => new EE_Belongs_To_Relation(), |
|
116 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
117 | + ]; |
|
118 | + // this model is generally available for reading |
|
119 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = |
|
120 | + new EE_Restriction_Generator_Default_Public( |
|
121 | + 'PRC_is_default', |
|
122 | + 'Ticket.Datetime.Event' |
|
123 | + ); |
|
124 | + // account for default tickets in the caps |
|
125 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
126 | + new EE_Restriction_Generator_Default_Protected( |
|
127 | + 'PRC_is_default', |
|
128 | + 'Ticket.Datetime.Event' |
|
129 | + ); |
|
130 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = |
|
131 | + new EE_Restriction_Generator_Default_Protected( |
|
132 | + 'PRC_is_default', |
|
133 | + 'Ticket.Datetime.Event' |
|
134 | + ); |
|
135 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
136 | + new EE_Restriction_Generator_Default_Protected( |
|
137 | + 'PRC_is_default', |
|
138 | + 'Ticket.Datetime.Event' |
|
139 | + ); |
|
140 | + parent::__construct($timezone); |
|
141 | + } |
|
142 | 142 | |
143 | 143 | |
144 | - /** |
|
145 | - * instantiate a new price object with blank/empty properties |
|
146 | - * |
|
147 | - * @return mixed array on success, FALSE on fail |
|
148 | - */ |
|
149 | - public function get_new_price() |
|
150 | - { |
|
151 | - return $this->create_default_object(); |
|
152 | - } |
|
144 | + /** |
|
145 | + * instantiate a new price object with blank/empty properties |
|
146 | + * |
|
147 | + * @return mixed array on success, FALSE on fail |
|
148 | + */ |
|
149 | + public function get_new_price() |
|
150 | + { |
|
151 | + return $this->create_default_object(); |
|
152 | + } |
|
153 | 153 | |
154 | 154 | |
155 | - /** |
|
156 | - * retrieve ALL prices from db |
|
157 | - * |
|
158 | - * @return EE_Base_Class[]|EE_PRice[] |
|
159 | - * @throws EE_Error |
|
160 | - */ |
|
161 | - public function get_all_prices() |
|
162 | - { |
|
163 | - // retrieve all prices |
|
164 | - return $this->get_all(['order_by' => ['PRC_amount' => 'ASC']]); |
|
165 | - } |
|
155 | + /** |
|
156 | + * retrieve ALL prices from db |
|
157 | + * |
|
158 | + * @return EE_Base_Class[]|EE_PRice[] |
|
159 | + * @throws EE_Error |
|
160 | + */ |
|
161 | + public function get_all_prices() |
|
162 | + { |
|
163 | + // retrieve all prices |
|
164 | + return $this->get_all(['order_by' => ['PRC_amount' => 'ASC']]); |
|
165 | + } |
|
166 | 166 | |
167 | 167 | |
168 | - /** |
|
169 | - * retrieve all active prices for a particular event |
|
170 | - * |
|
171 | - * @param int $EVT_ID |
|
172 | - * @return array on success |
|
173 | - * @throws EE_Error |
|
174 | - */ |
|
175 | - public function get_all_event_prices($EVT_ID = 0) |
|
176 | - { |
|
177 | - return $this->get_all( |
|
178 | - [ |
|
179 | - [ |
|
180 | - 'EVT_ID' => $EVT_ID, |
|
181 | - 'Price_Type.PBT_ID' => ['!=', EEM_Price_Type::base_type_tax], |
|
182 | - ], |
|
183 | - 'order_by' => $this->_order_by_array_for_get_all_method(), |
|
184 | - ] |
|
185 | - ); |
|
186 | - } |
|
168 | + /** |
|
169 | + * retrieve all active prices for a particular event |
|
170 | + * |
|
171 | + * @param int $EVT_ID |
|
172 | + * @return array on success |
|
173 | + * @throws EE_Error |
|
174 | + */ |
|
175 | + public function get_all_event_prices($EVT_ID = 0) |
|
176 | + { |
|
177 | + return $this->get_all( |
|
178 | + [ |
|
179 | + [ |
|
180 | + 'EVT_ID' => $EVT_ID, |
|
181 | + 'Price_Type.PBT_ID' => ['!=', EEM_Price_Type::base_type_tax], |
|
182 | + ], |
|
183 | + 'order_by' => $this->_order_by_array_for_get_all_method(), |
|
184 | + ] |
|
185 | + ); |
|
186 | + } |
|
187 | 187 | |
188 | 188 | |
189 | - /** |
|
190 | - * retrieve all active global prices (that are not taxes (PBT_ID=4)) for a particular event |
|
191 | - * |
|
192 | - * @param boolean $count return count |
|
193 | - * @param bool $include_taxes |
|
194 | - * @return bool|EE_Base_Class[]|EE_PRice[] |
|
195 | - * @throws EE_Error |
|
196 | - */ |
|
197 | - public function get_all_default_prices($count = false, $include_taxes = false) |
|
198 | - { |
|
199 | - $_where = [ |
|
200 | - 'PRC_deleted' => 0, |
|
201 | - 'PRC_is_default' => 1, |
|
202 | - ]; |
|
203 | - if (! $include_taxes) { |
|
204 | - $_where['Price_Type.PBT_ID'] = ['!=', 4]; |
|
205 | - } |
|
206 | - $_query_params = [ |
|
207 | - $_where, |
|
208 | - 'order_by' => $this->_order_by_array_for_get_all_method(), |
|
209 | - ]; |
|
210 | - return $count ? $this->count([$_where]) : $this->get_all($_query_params); |
|
211 | - } |
|
189 | + /** |
|
190 | + * retrieve all active global prices (that are not taxes (PBT_ID=4)) for a particular event |
|
191 | + * |
|
192 | + * @param boolean $count return count |
|
193 | + * @param bool $include_taxes |
|
194 | + * @return bool|EE_Base_Class[]|EE_PRice[] |
|
195 | + * @throws EE_Error |
|
196 | + */ |
|
197 | + public function get_all_default_prices($count = false, $include_taxes = false) |
|
198 | + { |
|
199 | + $_where = [ |
|
200 | + 'PRC_deleted' => 0, |
|
201 | + 'PRC_is_default' => 1, |
|
202 | + ]; |
|
203 | + if (! $include_taxes) { |
|
204 | + $_where['Price_Type.PBT_ID'] = ['!=', 4]; |
|
205 | + } |
|
206 | + $_query_params = [ |
|
207 | + $_where, |
|
208 | + 'order_by' => $this->_order_by_array_for_get_all_method(), |
|
209 | + ]; |
|
210 | + return $count ? $this->count([$_where]) : $this->get_all($_query_params); |
|
211 | + } |
|
212 | 212 | |
213 | 213 | |
214 | - /** |
|
215 | - * retrieve all active global prices that are taxes |
|
216 | - * |
|
217 | - * @return bool|EE_Base_Class[]|EE_PRice[] |
|
218 | - * @throws EE_Error |
|
219 | - * @since $VID:$ |
|
220 | - */ |
|
221 | - public function getAllDefaultTaxes() |
|
222 | - { |
|
223 | - return $this->get_all( |
|
224 | - [ |
|
225 | - [ |
|
226 | - 'PRC_deleted' => 0, |
|
227 | - 'PRC_is_default' => 1, |
|
228 | - 'Price_Type.PBT_ID' => EEM_Price_Type::base_type_tax |
|
229 | - ], |
|
230 | - 'order_by' => [ |
|
231 | - 'Price_Type.PRT_order' => 'ASC', |
|
232 | - 'PRC_order' => 'ASC' |
|
233 | - ], |
|
234 | - ] |
|
235 | - ); |
|
236 | - } |
|
214 | + /** |
|
215 | + * retrieve all active global prices that are taxes |
|
216 | + * |
|
217 | + * @return bool|EE_Base_Class[]|EE_PRice[] |
|
218 | + * @throws EE_Error |
|
219 | + * @since $VID:$ |
|
220 | + */ |
|
221 | + public function getAllDefaultTaxes() |
|
222 | + { |
|
223 | + return $this->get_all( |
|
224 | + [ |
|
225 | + [ |
|
226 | + 'PRC_deleted' => 0, |
|
227 | + 'PRC_is_default' => 1, |
|
228 | + 'Price_Type.PBT_ID' => EEM_Price_Type::base_type_tax |
|
229 | + ], |
|
230 | + 'order_by' => [ |
|
231 | + 'Price_Type.PRT_order' => 'ASC', |
|
232 | + 'PRC_order' => 'ASC' |
|
233 | + ], |
|
234 | + ] |
|
235 | + ); |
|
236 | + } |
|
237 | 237 | |
238 | 238 | |
239 | - /** |
|
240 | - * retrieve all prices that are taxes |
|
241 | - * |
|
242 | - * @return EE_Base_Class[]|EE_PRice[] |
|
243 | - * @throws EE_Error |
|
244 | - * @throws InvalidArgumentException |
|
245 | - * @throws ReflectionException |
|
246 | - * @throws InvalidDataTypeException |
|
247 | - * @throws InvalidInterfaceException |
|
248 | - */ |
|
249 | - public function get_all_prices_that_are_taxes() |
|
250 | - { |
|
251 | - $taxes = []; |
|
252 | - $all_taxes = $this->get_all( |
|
253 | - [ |
|
254 | - ['Price_Type.PBT_ID' => EEM_Price_Type::base_type_tax, 'PRC_is_default' => 1], |
|
255 | - 'order_by' => ['Price_Type.PRT_order' => 'ASC', 'PRC_order' => 'ASC'], |
|
256 | - ] |
|
257 | - ); |
|
258 | - foreach ($all_taxes as $tax) { |
|
259 | - if ($tax instanceof EE_Price) { |
|
260 | - $taxes[ $tax->order() ][ $tax->ID() ] = $tax; |
|
261 | - } |
|
262 | - } |
|
263 | - return $taxes; |
|
264 | - } |
|
239 | + /** |
|
240 | + * retrieve all prices that are taxes |
|
241 | + * |
|
242 | + * @return EE_Base_Class[]|EE_PRice[] |
|
243 | + * @throws EE_Error |
|
244 | + * @throws InvalidArgumentException |
|
245 | + * @throws ReflectionException |
|
246 | + * @throws InvalidDataTypeException |
|
247 | + * @throws InvalidInterfaceException |
|
248 | + */ |
|
249 | + public function get_all_prices_that_are_taxes() |
|
250 | + { |
|
251 | + $taxes = []; |
|
252 | + $all_taxes = $this->get_all( |
|
253 | + [ |
|
254 | + ['Price_Type.PBT_ID' => EEM_Price_Type::base_type_tax, 'PRC_is_default' => 1], |
|
255 | + 'order_by' => ['Price_Type.PRT_order' => 'ASC', 'PRC_order' => 'ASC'], |
|
256 | + ] |
|
257 | + ); |
|
258 | + foreach ($all_taxes as $tax) { |
|
259 | + if ($tax instanceof EE_Price) { |
|
260 | + $taxes[ $tax->order() ][ $tax->ID() ] = $tax; |
|
261 | + } |
|
262 | + } |
|
263 | + return $taxes; |
|
264 | + } |
|
265 | 265 | |
266 | 266 | |
267 | - /** |
|
268 | - * retrieve all prices for an ticket plus default global prices, but not taxes |
|
269 | - * |
|
270 | - * @param int $TKT_ID the id of the event. If not included then we assume that this is a new ticket. |
|
271 | - * @return EE_Base_Class[]|EE_PRice[]|boolean |
|
272 | - * @throws EE_Error |
|
273 | - */ |
|
274 | - public function get_all_ticket_prices_for_admin($TKT_ID = 0) |
|
275 | - { |
|
276 | - $array_of_price_objects = []; |
|
277 | - if (empty($TKT_ID)) { |
|
278 | - // if there is no tkt, get prices with no tkt ID, are global, are not a tax, and are active |
|
279 | - // return that list |
|
280 | - $default_prices = $this->get_all_default_prices(); |
|
267 | + /** |
|
268 | + * retrieve all prices for an ticket plus default global prices, but not taxes |
|
269 | + * |
|
270 | + * @param int $TKT_ID the id of the event. If not included then we assume that this is a new ticket. |
|
271 | + * @return EE_Base_Class[]|EE_PRice[]|boolean |
|
272 | + * @throws EE_Error |
|
273 | + */ |
|
274 | + public function get_all_ticket_prices_for_admin($TKT_ID = 0) |
|
275 | + { |
|
276 | + $array_of_price_objects = []; |
|
277 | + if (empty($TKT_ID)) { |
|
278 | + // if there is no tkt, get prices with no tkt ID, are global, are not a tax, and are active |
|
279 | + // return that list |
|
280 | + $default_prices = $this->get_all_default_prices(); |
|
281 | 281 | |
282 | - if ($default_prices) { |
|
283 | - foreach ($default_prices as $price) { |
|
284 | - if ($price instanceof EE_Price) { |
|
285 | - $array_of_price_objects[ $price->type() ][] = $price; |
|
286 | - } |
|
287 | - } |
|
288 | - return $array_of_price_objects; |
|
289 | - } |
|
290 | - return []; |
|
291 | - } |
|
292 | - $ticket_prices = $this->get_all( |
|
293 | - [ |
|
294 | - [ |
|
295 | - 'TKT_ID' => $TKT_ID, |
|
296 | - 'PRC_deleted' => 0, |
|
297 | - ], |
|
298 | - 'order_by' => ['PRC_order' => 'ASC'], |
|
299 | - ] |
|
300 | - ); |
|
282 | + if ($default_prices) { |
|
283 | + foreach ($default_prices as $price) { |
|
284 | + if ($price instanceof EE_Price) { |
|
285 | + $array_of_price_objects[ $price->type() ][] = $price; |
|
286 | + } |
|
287 | + } |
|
288 | + return $array_of_price_objects; |
|
289 | + } |
|
290 | + return []; |
|
291 | + } |
|
292 | + $ticket_prices = $this->get_all( |
|
293 | + [ |
|
294 | + [ |
|
295 | + 'TKT_ID' => $TKT_ID, |
|
296 | + 'PRC_deleted' => 0, |
|
297 | + ], |
|
298 | + 'order_by' => ['PRC_order' => 'ASC'], |
|
299 | + ] |
|
300 | + ); |
|
301 | 301 | |
302 | - if (! empty($ticket_prices)) { |
|
303 | - foreach ($ticket_prices as $price) { |
|
304 | - if ($price instanceof EE_Price) { |
|
305 | - $array_of_price_objects[ $price->type() ][] = $price; |
|
306 | - } |
|
307 | - } |
|
308 | - return $array_of_price_objects; |
|
309 | - } |
|
310 | - return false; |
|
311 | - } |
|
302 | + if (! empty($ticket_prices)) { |
|
303 | + foreach ($ticket_prices as $price) { |
|
304 | + if ($price instanceof EE_Price) { |
|
305 | + $array_of_price_objects[ $price->type() ][] = $price; |
|
306 | + } |
|
307 | + } |
|
308 | + return $array_of_price_objects; |
|
309 | + } |
|
310 | + return false; |
|
311 | + } |
|
312 | 312 | |
313 | 313 | |
314 | - /** |
|
315 | - * _sort_event_prices_by_type |
|
316 | - * |
|
317 | - * @param EE_Price $price_a |
|
318 | - * @param EE_Price $price_b |
|
319 | - * @return bool false on fail |
|
320 | - */ |
|
321 | - public function _sort_event_prices_by_type(EE_Price $price_a, EE_Price $price_b) |
|
322 | - { |
|
323 | - if ($price_a->type_obj()->order() === $price_b->type_obj()->order()) { |
|
324 | - return $this->_sort_event_prices_by_order($price_a, $price_b); |
|
325 | - } |
|
326 | - return $price_a->type_obj()->order() < $price_b->type_obj()->order() ? -1 : 1; |
|
327 | - } |
|
314 | + /** |
|
315 | + * _sort_event_prices_by_type |
|
316 | + * |
|
317 | + * @param EE_Price $price_a |
|
318 | + * @param EE_Price $price_b |
|
319 | + * @return bool false on fail |
|
320 | + */ |
|
321 | + public function _sort_event_prices_by_type(EE_Price $price_a, EE_Price $price_b) |
|
322 | + { |
|
323 | + if ($price_a->type_obj()->order() === $price_b->type_obj()->order()) { |
|
324 | + return $this->_sort_event_prices_by_order($price_a, $price_b); |
|
325 | + } |
|
326 | + return $price_a->type_obj()->order() < $price_b->type_obj()->order() ? -1 : 1; |
|
327 | + } |
|
328 | 328 | |
329 | 329 | |
330 | - /** |
|
331 | - * _sort_event_prices_by_order |
|
332 | - * |
|
333 | - * @param EE_Price $price_a |
|
334 | - * @param EE_Price $price_b |
|
335 | - * @return bool false on fail |
|
336 | - */ |
|
337 | - public function _sort_event_prices_by_order(EE_Price $price_a, EE_Price $price_b) |
|
338 | - { |
|
339 | - if ($price_a->order() === $price_b->order()) { |
|
340 | - return 0; |
|
341 | - } |
|
342 | - return $price_a->order() < $price_b->order() ? -1 : 1; |
|
343 | - } |
|
330 | + /** |
|
331 | + * _sort_event_prices_by_order |
|
332 | + * |
|
333 | + * @param EE_Price $price_a |
|
334 | + * @param EE_Price $price_b |
|
335 | + * @return bool false on fail |
|
336 | + */ |
|
337 | + public function _sort_event_prices_by_order(EE_Price $price_a, EE_Price $price_b) |
|
338 | + { |
|
339 | + if ($price_a->order() === $price_b->order()) { |
|
340 | + return 0; |
|
341 | + } |
|
342 | + return $price_a->order() < $price_b->order() ? -1 : 1; |
|
343 | + } |
|
344 | 344 | |
345 | 345 | |
346 | - /** |
|
347 | - * get all prices of a specific type |
|
348 | - * |
|
349 | - * @param int $type - PRT_ID |
|
350 | - * @return EE_Base_Class[]|EE_PRice[] |
|
351 | - * @throws EE_Error |
|
352 | - */ |
|
353 | - public function get_all_prices_that_are_type($type = 0) |
|
354 | - { |
|
355 | - return $this->get_all( |
|
356 | - [ |
|
357 | - [ |
|
358 | - 'PRT_ID' => $type, |
|
359 | - ], |
|
360 | - 'order_by' => $this->_order_by_array_for_get_all_method(), |
|
361 | - ] |
|
362 | - ); |
|
363 | - } |
|
346 | + /** |
|
347 | + * get all prices of a specific type |
|
348 | + * |
|
349 | + * @param int $type - PRT_ID |
|
350 | + * @return EE_Base_Class[]|EE_PRice[] |
|
351 | + * @throws EE_Error |
|
352 | + */ |
|
353 | + public function get_all_prices_that_are_type($type = 0) |
|
354 | + { |
|
355 | + return $this->get_all( |
|
356 | + [ |
|
357 | + [ |
|
358 | + 'PRT_ID' => $type, |
|
359 | + ], |
|
360 | + 'order_by' => $this->_order_by_array_for_get_all_method(), |
|
361 | + ] |
|
362 | + ); |
|
363 | + } |
|
364 | 364 | |
365 | 365 | |
366 | - /** |
|
367 | - * Returns an array of the normal 'order_by' query parameter provided to the get_all query. |
|
368 | - * Of course you don't have to use it, but this is the order we usually want to sort prices by |
|
369 | - * |
|
370 | - * @return array which can be used like so: $this->get_all(array(array(...where |
|
371 | - * stuff...),'order_by'=>$this->_order_by_array_for_get_all_method())); |
|
372 | - */ |
|
373 | - public function _order_by_array_for_get_all_method() |
|
374 | - { |
|
375 | - return [ |
|
376 | - 'PRC_order' => 'ASC', |
|
377 | - 'Price_Type.PRT_order' => 'ASC', |
|
378 | - 'PRC_ID' => 'ASC', |
|
379 | - ]; |
|
380 | - } |
|
366 | + /** |
|
367 | + * Returns an array of the normal 'order_by' query parameter provided to the get_all query. |
|
368 | + * Of course you don't have to use it, but this is the order we usually want to sort prices by |
|
369 | + * |
|
370 | + * @return array which can be used like so: $this->get_all(array(array(...where |
|
371 | + * stuff...),'order_by'=>$this->_order_by_array_for_get_all_method())); |
|
372 | + */ |
|
373 | + public function _order_by_array_for_get_all_method() |
|
374 | + { |
|
375 | + return [ |
|
376 | + 'PRC_order' => 'ASC', |
|
377 | + 'Price_Type.PRT_order' => 'ASC', |
|
378 | + 'PRC_ID' => 'ASC', |
|
379 | + ]; |
|
380 | + } |
|
381 | 381 | } |
@@ -28,616 +28,616 @@ |
||
28 | 28 | class EEM_Line_Item extends EEM_Base |
29 | 29 | { |
30 | 30 | |
31 | - /** |
|
32 | - * Tax sub-total is just the total of all the taxes, which should be children |
|
33 | - * of this line item. There should only ever be one tax sub-total, and it should |
|
34 | - * be a direct child of. Its quantity and LIN_unit_price = 1. |
|
35 | - */ |
|
36 | - const type_tax_sub_total = 'tax-sub-total'; |
|
37 | - |
|
38 | - /** |
|
39 | - * Tax line items indicate a tax applied to all the taxable line items. |
|
40 | - * Should not have any children line items. Its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal |
|
41 | - * (eg 10% tax = 10, not 0.1). Its LIN_total = LIN_unit_price * pre-tax-total. Quantity = 1. |
|
42 | - */ |
|
43 | - const type_tax = 'tax'; |
|
44 | - |
|
45 | - /** |
|
46 | - * Indicating individual items purchased, or discounts or surcharges. |
|
47 | - * The sum of all the regular line items plus the tax items should equal the grand total. |
|
48 | - * Possible children are sub-line-items and cancellations. |
|
49 | - * For flat items, LIN_unit_price * LIN_quantity = LIN_total. Its LIN_total is the sum of all the children |
|
50 | - * LIN_totals. Its LIN_percent = 0. |
|
51 | - * For percent items, its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal (eg 10% = 10, not 0.1). |
|
52 | - * Its LIN_total is LIN_percent / 100 * sum of lower-priority sibling line items. Quantity = 1. |
|
53 | - */ |
|
54 | - const type_line_item = 'line-item'; |
|
55 | - |
|
56 | - /** |
|
57 | - * Line item indicating all the factors that make a single line item. |
|
58 | - * Sub-line items should have NO children line items. |
|
59 | - * For flat sub-items, their quantity should match their parent item, their LIN_unit_price should be this sub-item's |
|
60 | - * contribution towards the price of ONE of their parent items, and its LIN_total should be |
|
61 | - * = LIN_quantity * LIN_unit_price. Its LIN_percent = 0. |
|
62 | - * For percent sub-items, the quantity should be 1, LIN_unit_price should be 0, and its LIN_total should |
|
63 | - * = LIN_percent / 100 * sum of lower-priority sibling line items.. |
|
64 | - */ |
|
65 | - const type_sub_line_item = 'sub-item'; |
|
66 | - |
|
67 | - /** |
|
68 | - * SubTax line items indicate a tax that is only applied to the pre-tax total of their parent line item. |
|
69 | - * Should not have any children line items. Its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal |
|
70 | - * (eg 10% tax = 10, not 0.1). Its LIN_total = LIN_unit_price * pre-tax-total. Quantity = 1. |
|
71 | - */ |
|
72 | - const type_sub_tax = 'sub-tax'; |
|
73 | - |
|
74 | - /** |
|
75 | - * Line item indicating a sub-total (eg total for an event, or pre-tax subtotal). |
|
76 | - * Direct children should be event subtotals. |
|
77 | - * Should have quantity of 1, and a LIN_total and LIN_unit_price of the sum of all its sub-items' LIN_totals. |
|
78 | - */ |
|
79 | - const type_sub_total = 'sub-total'; |
|
80 | - |
|
81 | - /** |
|
82 | - * Line item for the grand total of an order. |
|
83 | - * Its direct children should be tax subtotals and (pre-tax) subtotals, |
|
84 | - * and possibly a regular line item indicating a transaction-wide discount/surcharge. |
|
85 | - * Should have a quantity of 1, a LIN_total and LIN_unit_price of the entire order's amount. |
|
86 | - */ |
|
87 | - const type_total = 'total'; |
|
88 | - |
|
89 | - /** |
|
90 | - * When a line item is cancelled, a sub-line-item of type 'cancellation' |
|
91 | - * should be created, indicating the quantity that were cancelled |
|
92 | - * (because a line item could have a quantity of 1, and its cancellation item |
|
93 | - * could be for 3, indicating that originally 4 were purchased, but 3 have been |
|
94 | - * cancelled, and only one remains). |
|
95 | - * When items are refunded, a cancellation line item should be made, which points |
|
96 | - * to teh payment model object which actually refunded the payment. |
|
97 | - * Cancellations should NOT have any children line items; the should NOT affect |
|
98 | - * any calculations, and are only meant as a record that cancellations have occurred. |
|
99 | - * Their LIN_percent should be 0. |
|
100 | - */ |
|
101 | - const type_cancellation = 'cancellation'; |
|
102 | - |
|
103 | - // various line item object types |
|
104 | - const OBJ_TYPE_EVENT = 'Event'; |
|
105 | - |
|
106 | - const OBJ_TYPE_PRICE = 'Price'; |
|
107 | - |
|
108 | - const OBJ_TYPE_PROMOTION = 'Promotion'; |
|
109 | - |
|
110 | - const OBJ_TYPE_TICKET = 'Ticket'; |
|
111 | - |
|
112 | - const OBJ_TYPE_TRANSACTION = 'Transaction'; |
|
113 | - |
|
114 | - /** |
|
115 | - * @var EEM_Line_Item $_instance |
|
116 | - */ |
|
117 | - protected static $_instance; |
|
118 | - |
|
119 | - |
|
120 | - /** |
|
121 | - * private constructor to prevent direct creation |
|
122 | - * |
|
123 | - * @Constructor |
|
124 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings |
|
125 | - * (and any incoming timezone data that gets saved). |
|
126 | - * Note this just sends the timezone info to the date time model field objects. |
|
127 | - * Default is NULL |
|
128 | - * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
129 | - * @throws EE_Error |
|
130 | - * @throws InvalidArgumentException |
|
131 | - */ |
|
132 | - protected function __construct($timezone) |
|
133 | - { |
|
134 | - $this->singular_item = esc_html__('Line Item', 'event_espresso'); |
|
135 | - $this->plural_item = esc_html__('Line Items', 'event_espresso'); |
|
136 | - |
|
137 | - $this->_tables = array( |
|
138 | - 'Line_Item' => new EE_Primary_Table('esp_line_item', 'LIN_ID'), |
|
139 | - ); |
|
140 | - $line_items_can_be_for = apply_filters( |
|
141 | - 'FHEE__EEM_Line_Item__line_items_can_be_for', |
|
142 | - array('Ticket', 'Price', 'Event') |
|
143 | - ); |
|
144 | - $this->_fields = array( |
|
145 | - 'Line_Item' => array( |
|
146 | - 'LIN_ID' => new EE_Primary_Key_Int_Field( |
|
147 | - 'LIN_ID', |
|
148 | - esc_html__('ID', 'event_espresso') |
|
149 | - ), |
|
150 | - 'LIN_code' => new EE_Slug_Field( |
|
151 | - 'LIN_code', |
|
152 | - esc_html__('Code for index into Cart', 'event_espresso'), |
|
153 | - true |
|
154 | - ), |
|
155 | - 'TXN_ID' => new EE_Foreign_Key_Int_Field( |
|
156 | - 'TXN_ID', |
|
157 | - esc_html__('Transaction ID', 'event_espresso'), |
|
158 | - true, |
|
159 | - null, |
|
160 | - 'Transaction' |
|
161 | - ), |
|
162 | - 'LIN_name' => new EE_Full_HTML_Field( |
|
163 | - 'LIN_name', |
|
164 | - esc_html__('Line Item Name', 'event_espresso'), |
|
165 | - false, |
|
166 | - '' |
|
167 | - ), |
|
168 | - 'LIN_desc' => new EE_Full_HTML_Field( |
|
169 | - 'LIN_desc', |
|
170 | - esc_html__('Line Item Description', 'event_espresso'), |
|
171 | - true |
|
172 | - ), |
|
173 | - 'LIN_unit_price' => new EE_Money_Field( |
|
174 | - 'LIN_unit_price', |
|
175 | - esc_html__('Unit Price', 'event_espresso'), |
|
176 | - false, |
|
177 | - 0 |
|
178 | - ), |
|
179 | - 'LIN_percent' => new EE_Float_Field( |
|
180 | - 'LIN_percent', |
|
181 | - esc_html__('Percent', 'event_espresso'), |
|
182 | - false, |
|
183 | - 0 |
|
184 | - ), |
|
185 | - 'LIN_is_taxable' => new EE_Boolean_Field( |
|
186 | - 'LIN_is_taxable', |
|
187 | - esc_html__('Taxable', 'event_espresso'), |
|
188 | - false, |
|
189 | - false |
|
190 | - ), |
|
191 | - 'LIN_order' => new EE_Integer_Field( |
|
192 | - 'LIN_order', |
|
193 | - esc_html__('Order of Application towards total of parent', 'event_espresso'), |
|
194 | - false, |
|
195 | - 1 |
|
196 | - ), |
|
197 | - 'LIN_total' => new EE_Money_Field( |
|
198 | - 'LIN_total', |
|
199 | - esc_html__('Total (unit price x quantity) after taxes', 'event_espresso'), |
|
200 | - false, |
|
201 | - 0 |
|
202 | - ), |
|
203 | - 'LIN_pretax' => new EE_Money_Field( |
|
204 | - 'LIN_pretax', |
|
205 | - esc_html__('Total (unit price x quantity) before taxes', 'event_espresso'), |
|
206 | - false, |
|
207 | - 0 |
|
208 | - ), |
|
209 | - 'LIN_quantity' => new EE_Integer_Field( |
|
210 | - 'LIN_quantity', |
|
211 | - esc_html__('Quantity', 'event_espresso'), |
|
212 | - true, |
|
213 | - 1 |
|
214 | - ), |
|
215 | - 'LIN_parent' => new EE_Integer_Field( |
|
216 | - 'LIN_parent', |
|
217 | - esc_html__("Parent ID (this item goes towards that Line Item's total)", 'event_espresso'), |
|
218 | - true, |
|
219 | - null |
|
220 | - ), |
|
221 | - 'LIN_type' => new EE_Enum_Text_Field( |
|
222 | - 'LIN_type', |
|
223 | - esc_html__('Type', 'event_espresso'), |
|
224 | - false, |
|
225 | - 'line-item', |
|
226 | - array( |
|
227 | - self::type_line_item => esc_html__('Line Item', 'event_espresso'), |
|
228 | - self::type_sub_line_item => esc_html__('Sub-Item', 'event_espresso'), |
|
229 | - self::type_sub_tax => esc_html__('Sub-Tax', 'event_espresso'), |
|
230 | - self::type_sub_total => esc_html__('Subtotal', 'event_espresso'), |
|
231 | - self::type_tax_sub_total => esc_html__('Tax Subtotal', 'event_espresso'), |
|
232 | - self::type_tax => esc_html__('Tax', 'event_espresso'), |
|
233 | - self::type_total => esc_html__('Total', 'event_espresso'), |
|
234 | - self::type_cancellation => esc_html__('Cancellation', 'event_espresso'), |
|
235 | - ) |
|
236 | - ), |
|
237 | - 'OBJ_ID' => new EE_Foreign_Key_Int_Field( |
|
238 | - 'OBJ_ID', |
|
239 | - esc_html__('ID of Item purchased.', 'event_espresso'), |
|
240 | - true, |
|
241 | - null, |
|
242 | - $line_items_can_be_for |
|
243 | - ), |
|
244 | - 'OBJ_type' => new EE_Any_Foreign_Model_Name_Field( |
|
245 | - 'OBJ_type', |
|
246 | - esc_html__('Model Name this Line Item is for', 'event_espresso'), |
|
247 | - true, |
|
248 | - null, |
|
249 | - $line_items_can_be_for |
|
250 | - ), |
|
251 | - 'LIN_timestamp' => new EE_Datetime_Field( |
|
252 | - 'LIN_timestamp', |
|
253 | - esc_html__('When the line item was created', 'event_espresso'), |
|
254 | - false, |
|
255 | - EE_Datetime_Field::now, |
|
256 | - $timezone |
|
257 | - ), |
|
258 | - ), |
|
259 | - ); |
|
260 | - $this->_model_relations = array( |
|
261 | - 'Transaction' => new EE_Belongs_To_Relation(), |
|
262 | - 'Ticket' => new EE_Belongs_To_Any_Relation(), |
|
263 | - 'Price' => new EE_Belongs_To_Any_Relation(), |
|
264 | - 'Event' => new EE_Belongs_To_Any_Relation(), |
|
265 | - ); |
|
266 | - $this->_model_chain_to_wp_user = 'Transaction.Registration.Event'; |
|
267 | - $this->_caps_slug = 'transactions'; |
|
268 | - parent::__construct($timezone); |
|
269 | - } |
|
270 | - |
|
271 | - |
|
272 | - /** |
|
273 | - * Gets all the line items for this transaction of the given type |
|
274 | - * |
|
275 | - * @param string $line_item_type like one of EEM_Line_Item::type_* |
|
276 | - * @param EE_Transaction|int $transaction |
|
277 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
278 | - * @throws EE_Error |
|
279 | - * @throws InvalidArgumentException |
|
280 | - * @throws InvalidDataTypeException |
|
281 | - * @throws InvalidInterfaceException |
|
282 | - */ |
|
283 | - public function get_all_of_type_for_transaction($line_item_type, $transaction) |
|
284 | - { |
|
285 | - $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction); |
|
286 | - return $this->get_all(array( |
|
287 | - array( |
|
288 | - 'LIN_type' => $line_item_type, |
|
289 | - 'TXN_ID' => $transaction, |
|
290 | - ), |
|
291 | - )); |
|
292 | - } |
|
293 | - |
|
294 | - |
|
295 | - /** |
|
296 | - * Gets all line items unrelated to tickets that are normal line items |
|
297 | - * (eg shipping, promotions, and miscellaneous other stuff should probably fit in this category) |
|
298 | - * |
|
299 | - * @param EE_Transaction|int $transaction |
|
300 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
301 | - * @throws EE_Error |
|
302 | - * @throws InvalidArgumentException |
|
303 | - * @throws InvalidDataTypeException |
|
304 | - * @throws InvalidInterfaceException |
|
305 | - */ |
|
306 | - public function get_all_non_ticket_line_items_for_transaction($transaction) |
|
307 | - { |
|
308 | - $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction); |
|
309 | - return $this->get_all(array( |
|
310 | - array( |
|
311 | - 'LIN_type' => self::type_line_item, |
|
312 | - 'TXN_ID' => $transaction, |
|
313 | - 'OR' => array( |
|
314 | - 'OBJ_type*notticket' => array('!=', EEM_Line_Item::OBJ_TYPE_TICKET), |
|
315 | - 'OBJ_type*null' => array('IS_NULL'), |
|
316 | - ), |
|
317 | - ), |
|
318 | - )); |
|
319 | - } |
|
320 | - |
|
321 | - |
|
322 | - /** |
|
323 | - * Deletes line items with no transaction who have passed the transaction cutoff time. |
|
324 | - * This needs to be very efficient |
|
325 | - * because if there are spam bots afoot there will be LOTS of line items. Also MySQL doesn't allow a limit when |
|
326 | - * deleting and joining tables like this. |
|
327 | - * |
|
328 | - * @return int count of how many deleted |
|
329 | - * @throws EE_Error |
|
330 | - * @throws InvalidArgumentException |
|
331 | - * @throws InvalidDataTypeException |
|
332 | - * @throws InvalidInterfaceException |
|
333 | - */ |
|
334 | - public function delete_line_items_with_no_transaction() |
|
335 | - { |
|
336 | - /** @type WPDB $wpdb */ |
|
337 | - global $wpdb; |
|
338 | - $time_to_leave_alone = apply_filters( |
|
339 | - 'FHEE__EEM_Line_Item__delete_line_items_with_no_transaction__time_to_leave_alone', |
|
340 | - WEEK_IN_SECONDS |
|
341 | - ); |
|
342 | - $query = $wpdb->prepare( |
|
343 | - 'DELETE li |
|
31 | + /** |
|
32 | + * Tax sub-total is just the total of all the taxes, which should be children |
|
33 | + * of this line item. There should only ever be one tax sub-total, and it should |
|
34 | + * be a direct child of. Its quantity and LIN_unit_price = 1. |
|
35 | + */ |
|
36 | + const type_tax_sub_total = 'tax-sub-total'; |
|
37 | + |
|
38 | + /** |
|
39 | + * Tax line items indicate a tax applied to all the taxable line items. |
|
40 | + * Should not have any children line items. Its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal |
|
41 | + * (eg 10% tax = 10, not 0.1). Its LIN_total = LIN_unit_price * pre-tax-total. Quantity = 1. |
|
42 | + */ |
|
43 | + const type_tax = 'tax'; |
|
44 | + |
|
45 | + /** |
|
46 | + * Indicating individual items purchased, or discounts or surcharges. |
|
47 | + * The sum of all the regular line items plus the tax items should equal the grand total. |
|
48 | + * Possible children are sub-line-items and cancellations. |
|
49 | + * For flat items, LIN_unit_price * LIN_quantity = LIN_total. Its LIN_total is the sum of all the children |
|
50 | + * LIN_totals. Its LIN_percent = 0. |
|
51 | + * For percent items, its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal (eg 10% = 10, not 0.1). |
|
52 | + * Its LIN_total is LIN_percent / 100 * sum of lower-priority sibling line items. Quantity = 1. |
|
53 | + */ |
|
54 | + const type_line_item = 'line-item'; |
|
55 | + |
|
56 | + /** |
|
57 | + * Line item indicating all the factors that make a single line item. |
|
58 | + * Sub-line items should have NO children line items. |
|
59 | + * For flat sub-items, their quantity should match their parent item, their LIN_unit_price should be this sub-item's |
|
60 | + * contribution towards the price of ONE of their parent items, and its LIN_total should be |
|
61 | + * = LIN_quantity * LIN_unit_price. Its LIN_percent = 0. |
|
62 | + * For percent sub-items, the quantity should be 1, LIN_unit_price should be 0, and its LIN_total should |
|
63 | + * = LIN_percent / 100 * sum of lower-priority sibling line items.. |
|
64 | + */ |
|
65 | + const type_sub_line_item = 'sub-item'; |
|
66 | + |
|
67 | + /** |
|
68 | + * SubTax line items indicate a tax that is only applied to the pre-tax total of their parent line item. |
|
69 | + * Should not have any children line items. Its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal |
|
70 | + * (eg 10% tax = 10, not 0.1). Its LIN_total = LIN_unit_price * pre-tax-total. Quantity = 1. |
|
71 | + */ |
|
72 | + const type_sub_tax = 'sub-tax'; |
|
73 | + |
|
74 | + /** |
|
75 | + * Line item indicating a sub-total (eg total for an event, or pre-tax subtotal). |
|
76 | + * Direct children should be event subtotals. |
|
77 | + * Should have quantity of 1, and a LIN_total and LIN_unit_price of the sum of all its sub-items' LIN_totals. |
|
78 | + */ |
|
79 | + const type_sub_total = 'sub-total'; |
|
80 | + |
|
81 | + /** |
|
82 | + * Line item for the grand total of an order. |
|
83 | + * Its direct children should be tax subtotals and (pre-tax) subtotals, |
|
84 | + * and possibly a regular line item indicating a transaction-wide discount/surcharge. |
|
85 | + * Should have a quantity of 1, a LIN_total and LIN_unit_price of the entire order's amount. |
|
86 | + */ |
|
87 | + const type_total = 'total'; |
|
88 | + |
|
89 | + /** |
|
90 | + * When a line item is cancelled, a sub-line-item of type 'cancellation' |
|
91 | + * should be created, indicating the quantity that were cancelled |
|
92 | + * (because a line item could have a quantity of 1, and its cancellation item |
|
93 | + * could be for 3, indicating that originally 4 were purchased, but 3 have been |
|
94 | + * cancelled, and only one remains). |
|
95 | + * When items are refunded, a cancellation line item should be made, which points |
|
96 | + * to teh payment model object which actually refunded the payment. |
|
97 | + * Cancellations should NOT have any children line items; the should NOT affect |
|
98 | + * any calculations, and are only meant as a record that cancellations have occurred. |
|
99 | + * Their LIN_percent should be 0. |
|
100 | + */ |
|
101 | + const type_cancellation = 'cancellation'; |
|
102 | + |
|
103 | + // various line item object types |
|
104 | + const OBJ_TYPE_EVENT = 'Event'; |
|
105 | + |
|
106 | + const OBJ_TYPE_PRICE = 'Price'; |
|
107 | + |
|
108 | + const OBJ_TYPE_PROMOTION = 'Promotion'; |
|
109 | + |
|
110 | + const OBJ_TYPE_TICKET = 'Ticket'; |
|
111 | + |
|
112 | + const OBJ_TYPE_TRANSACTION = 'Transaction'; |
|
113 | + |
|
114 | + /** |
|
115 | + * @var EEM_Line_Item $_instance |
|
116 | + */ |
|
117 | + protected static $_instance; |
|
118 | + |
|
119 | + |
|
120 | + /** |
|
121 | + * private constructor to prevent direct creation |
|
122 | + * |
|
123 | + * @Constructor |
|
124 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings |
|
125 | + * (and any incoming timezone data that gets saved). |
|
126 | + * Note this just sends the timezone info to the date time model field objects. |
|
127 | + * Default is NULL |
|
128 | + * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
129 | + * @throws EE_Error |
|
130 | + * @throws InvalidArgumentException |
|
131 | + */ |
|
132 | + protected function __construct($timezone) |
|
133 | + { |
|
134 | + $this->singular_item = esc_html__('Line Item', 'event_espresso'); |
|
135 | + $this->plural_item = esc_html__('Line Items', 'event_espresso'); |
|
136 | + |
|
137 | + $this->_tables = array( |
|
138 | + 'Line_Item' => new EE_Primary_Table('esp_line_item', 'LIN_ID'), |
|
139 | + ); |
|
140 | + $line_items_can_be_for = apply_filters( |
|
141 | + 'FHEE__EEM_Line_Item__line_items_can_be_for', |
|
142 | + array('Ticket', 'Price', 'Event') |
|
143 | + ); |
|
144 | + $this->_fields = array( |
|
145 | + 'Line_Item' => array( |
|
146 | + 'LIN_ID' => new EE_Primary_Key_Int_Field( |
|
147 | + 'LIN_ID', |
|
148 | + esc_html__('ID', 'event_espresso') |
|
149 | + ), |
|
150 | + 'LIN_code' => new EE_Slug_Field( |
|
151 | + 'LIN_code', |
|
152 | + esc_html__('Code for index into Cart', 'event_espresso'), |
|
153 | + true |
|
154 | + ), |
|
155 | + 'TXN_ID' => new EE_Foreign_Key_Int_Field( |
|
156 | + 'TXN_ID', |
|
157 | + esc_html__('Transaction ID', 'event_espresso'), |
|
158 | + true, |
|
159 | + null, |
|
160 | + 'Transaction' |
|
161 | + ), |
|
162 | + 'LIN_name' => new EE_Full_HTML_Field( |
|
163 | + 'LIN_name', |
|
164 | + esc_html__('Line Item Name', 'event_espresso'), |
|
165 | + false, |
|
166 | + '' |
|
167 | + ), |
|
168 | + 'LIN_desc' => new EE_Full_HTML_Field( |
|
169 | + 'LIN_desc', |
|
170 | + esc_html__('Line Item Description', 'event_espresso'), |
|
171 | + true |
|
172 | + ), |
|
173 | + 'LIN_unit_price' => new EE_Money_Field( |
|
174 | + 'LIN_unit_price', |
|
175 | + esc_html__('Unit Price', 'event_espresso'), |
|
176 | + false, |
|
177 | + 0 |
|
178 | + ), |
|
179 | + 'LIN_percent' => new EE_Float_Field( |
|
180 | + 'LIN_percent', |
|
181 | + esc_html__('Percent', 'event_espresso'), |
|
182 | + false, |
|
183 | + 0 |
|
184 | + ), |
|
185 | + 'LIN_is_taxable' => new EE_Boolean_Field( |
|
186 | + 'LIN_is_taxable', |
|
187 | + esc_html__('Taxable', 'event_espresso'), |
|
188 | + false, |
|
189 | + false |
|
190 | + ), |
|
191 | + 'LIN_order' => new EE_Integer_Field( |
|
192 | + 'LIN_order', |
|
193 | + esc_html__('Order of Application towards total of parent', 'event_espresso'), |
|
194 | + false, |
|
195 | + 1 |
|
196 | + ), |
|
197 | + 'LIN_total' => new EE_Money_Field( |
|
198 | + 'LIN_total', |
|
199 | + esc_html__('Total (unit price x quantity) after taxes', 'event_espresso'), |
|
200 | + false, |
|
201 | + 0 |
|
202 | + ), |
|
203 | + 'LIN_pretax' => new EE_Money_Field( |
|
204 | + 'LIN_pretax', |
|
205 | + esc_html__('Total (unit price x quantity) before taxes', 'event_espresso'), |
|
206 | + false, |
|
207 | + 0 |
|
208 | + ), |
|
209 | + 'LIN_quantity' => new EE_Integer_Field( |
|
210 | + 'LIN_quantity', |
|
211 | + esc_html__('Quantity', 'event_espresso'), |
|
212 | + true, |
|
213 | + 1 |
|
214 | + ), |
|
215 | + 'LIN_parent' => new EE_Integer_Field( |
|
216 | + 'LIN_parent', |
|
217 | + esc_html__("Parent ID (this item goes towards that Line Item's total)", 'event_espresso'), |
|
218 | + true, |
|
219 | + null |
|
220 | + ), |
|
221 | + 'LIN_type' => new EE_Enum_Text_Field( |
|
222 | + 'LIN_type', |
|
223 | + esc_html__('Type', 'event_espresso'), |
|
224 | + false, |
|
225 | + 'line-item', |
|
226 | + array( |
|
227 | + self::type_line_item => esc_html__('Line Item', 'event_espresso'), |
|
228 | + self::type_sub_line_item => esc_html__('Sub-Item', 'event_espresso'), |
|
229 | + self::type_sub_tax => esc_html__('Sub-Tax', 'event_espresso'), |
|
230 | + self::type_sub_total => esc_html__('Subtotal', 'event_espresso'), |
|
231 | + self::type_tax_sub_total => esc_html__('Tax Subtotal', 'event_espresso'), |
|
232 | + self::type_tax => esc_html__('Tax', 'event_espresso'), |
|
233 | + self::type_total => esc_html__('Total', 'event_espresso'), |
|
234 | + self::type_cancellation => esc_html__('Cancellation', 'event_espresso'), |
|
235 | + ) |
|
236 | + ), |
|
237 | + 'OBJ_ID' => new EE_Foreign_Key_Int_Field( |
|
238 | + 'OBJ_ID', |
|
239 | + esc_html__('ID of Item purchased.', 'event_espresso'), |
|
240 | + true, |
|
241 | + null, |
|
242 | + $line_items_can_be_for |
|
243 | + ), |
|
244 | + 'OBJ_type' => new EE_Any_Foreign_Model_Name_Field( |
|
245 | + 'OBJ_type', |
|
246 | + esc_html__('Model Name this Line Item is for', 'event_espresso'), |
|
247 | + true, |
|
248 | + null, |
|
249 | + $line_items_can_be_for |
|
250 | + ), |
|
251 | + 'LIN_timestamp' => new EE_Datetime_Field( |
|
252 | + 'LIN_timestamp', |
|
253 | + esc_html__('When the line item was created', 'event_espresso'), |
|
254 | + false, |
|
255 | + EE_Datetime_Field::now, |
|
256 | + $timezone |
|
257 | + ), |
|
258 | + ), |
|
259 | + ); |
|
260 | + $this->_model_relations = array( |
|
261 | + 'Transaction' => new EE_Belongs_To_Relation(), |
|
262 | + 'Ticket' => new EE_Belongs_To_Any_Relation(), |
|
263 | + 'Price' => new EE_Belongs_To_Any_Relation(), |
|
264 | + 'Event' => new EE_Belongs_To_Any_Relation(), |
|
265 | + ); |
|
266 | + $this->_model_chain_to_wp_user = 'Transaction.Registration.Event'; |
|
267 | + $this->_caps_slug = 'transactions'; |
|
268 | + parent::__construct($timezone); |
|
269 | + } |
|
270 | + |
|
271 | + |
|
272 | + /** |
|
273 | + * Gets all the line items for this transaction of the given type |
|
274 | + * |
|
275 | + * @param string $line_item_type like one of EEM_Line_Item::type_* |
|
276 | + * @param EE_Transaction|int $transaction |
|
277 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
278 | + * @throws EE_Error |
|
279 | + * @throws InvalidArgumentException |
|
280 | + * @throws InvalidDataTypeException |
|
281 | + * @throws InvalidInterfaceException |
|
282 | + */ |
|
283 | + public function get_all_of_type_for_transaction($line_item_type, $transaction) |
|
284 | + { |
|
285 | + $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction); |
|
286 | + return $this->get_all(array( |
|
287 | + array( |
|
288 | + 'LIN_type' => $line_item_type, |
|
289 | + 'TXN_ID' => $transaction, |
|
290 | + ), |
|
291 | + )); |
|
292 | + } |
|
293 | + |
|
294 | + |
|
295 | + /** |
|
296 | + * Gets all line items unrelated to tickets that are normal line items |
|
297 | + * (eg shipping, promotions, and miscellaneous other stuff should probably fit in this category) |
|
298 | + * |
|
299 | + * @param EE_Transaction|int $transaction |
|
300 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
301 | + * @throws EE_Error |
|
302 | + * @throws InvalidArgumentException |
|
303 | + * @throws InvalidDataTypeException |
|
304 | + * @throws InvalidInterfaceException |
|
305 | + */ |
|
306 | + public function get_all_non_ticket_line_items_for_transaction($transaction) |
|
307 | + { |
|
308 | + $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction); |
|
309 | + return $this->get_all(array( |
|
310 | + array( |
|
311 | + 'LIN_type' => self::type_line_item, |
|
312 | + 'TXN_ID' => $transaction, |
|
313 | + 'OR' => array( |
|
314 | + 'OBJ_type*notticket' => array('!=', EEM_Line_Item::OBJ_TYPE_TICKET), |
|
315 | + 'OBJ_type*null' => array('IS_NULL'), |
|
316 | + ), |
|
317 | + ), |
|
318 | + )); |
|
319 | + } |
|
320 | + |
|
321 | + |
|
322 | + /** |
|
323 | + * Deletes line items with no transaction who have passed the transaction cutoff time. |
|
324 | + * This needs to be very efficient |
|
325 | + * because if there are spam bots afoot there will be LOTS of line items. Also MySQL doesn't allow a limit when |
|
326 | + * deleting and joining tables like this. |
|
327 | + * |
|
328 | + * @return int count of how many deleted |
|
329 | + * @throws EE_Error |
|
330 | + * @throws InvalidArgumentException |
|
331 | + * @throws InvalidDataTypeException |
|
332 | + * @throws InvalidInterfaceException |
|
333 | + */ |
|
334 | + public function delete_line_items_with_no_transaction() |
|
335 | + { |
|
336 | + /** @type WPDB $wpdb */ |
|
337 | + global $wpdb; |
|
338 | + $time_to_leave_alone = apply_filters( |
|
339 | + 'FHEE__EEM_Line_Item__delete_line_items_with_no_transaction__time_to_leave_alone', |
|
340 | + WEEK_IN_SECONDS |
|
341 | + ); |
|
342 | + $query = $wpdb->prepare( |
|
343 | + 'DELETE li |
|
344 | 344 | FROM ' . $this->table() . ' li |
345 | 345 | LEFT JOIN ' . EEM_Transaction::instance()->table() . ' t ON li.TXN_ID = t.TXN_ID |
346 | 346 | WHERE t.TXN_ID IS NULL AND li.LIN_timestamp < %s', |
347 | - // use GMT time because that's what TXN_timestamps are in |
|
348 | - date('Y-m-d H:i:s', time() - $time_to_leave_alone) |
|
349 | - ); |
|
350 | - return $wpdb->query($query); |
|
351 | - } |
|
352 | - |
|
353 | - |
|
354 | - /** |
|
355 | - * get_line_item_for_transaction_object |
|
356 | - * Gets a transaction's line item record for a specific object such as a EE_Event or EE_Ticket |
|
357 | - * |
|
358 | - * @param int $TXN_ID |
|
359 | - * @param EE_Base_Class $object |
|
360 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
361 | - * @throws EE_Error |
|
362 | - * @throws InvalidArgumentException |
|
363 | - * @throws InvalidDataTypeException |
|
364 | - * @throws InvalidInterfaceException |
|
365 | - * @throws ReflectionException |
|
366 | - */ |
|
367 | - public function get_line_item_for_transaction_object($TXN_ID, EE_Base_Class $object) |
|
368 | - { |
|
369 | - return $this->get_all(array( |
|
370 | - array( |
|
371 | - 'TXN_ID' => $TXN_ID, |
|
372 | - 'OBJ_type' => str_replace('EE_', '', get_class($object)), |
|
373 | - 'OBJ_ID' => $object->ID(), |
|
374 | - ), |
|
375 | - )); |
|
376 | - } |
|
377 | - |
|
378 | - |
|
379 | - /** |
|
380 | - * get_object_line_items_for_transaction |
|
381 | - * Gets all of the the object line items for a transaction, based on an object type plus an array of object IDs |
|
382 | - * |
|
383 | - * @param int $TXN_ID |
|
384 | - * @param string $OBJ_type |
|
385 | - * @param array $OBJ_IDs |
|
386 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
387 | - * @throws EE_Error |
|
388 | - */ |
|
389 | - public function get_object_line_items_for_transaction( |
|
390 | - $TXN_ID, |
|
391 | - $OBJ_type = EEM_Line_Item::OBJ_TYPE_EVENT, |
|
392 | - $OBJ_IDs = array() |
|
393 | - ) { |
|
394 | - $query_params = array( |
|
395 | - 'OBJ_type' => $OBJ_type, |
|
396 | - // if incoming $OBJ_IDs is an array, then make sure it is formatted correctly for the query |
|
397 | - 'OBJ_ID' => is_array($OBJ_IDs) && ! isset($OBJ_IDs['IN']) ? array('IN', $OBJ_IDs) : $OBJ_IDs, |
|
398 | - ); |
|
399 | - if ($TXN_ID) { |
|
400 | - $query_params['TXN_ID'] = $TXN_ID; |
|
401 | - } |
|
402 | - return $this->get_all(array($query_params)); |
|
403 | - } |
|
404 | - |
|
405 | - |
|
406 | - /** |
|
407 | - * get_all_ticket_line_items_for_transaction |
|
408 | - * |
|
409 | - * @param EE_Transaction $transaction |
|
410 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
411 | - * @throws EE_Error |
|
412 | - * @throws InvalidArgumentException |
|
413 | - * @throws InvalidDataTypeException |
|
414 | - * @throws InvalidInterfaceException |
|
415 | - * @throws ReflectionException |
|
416 | - */ |
|
417 | - public function get_all_ticket_line_items_for_transaction(EE_Transaction $transaction) |
|
418 | - { |
|
419 | - return $this->get_all(array( |
|
420 | - array( |
|
421 | - 'TXN_ID' => $transaction->ID(), |
|
422 | - 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET, |
|
423 | - ), |
|
424 | - )); |
|
425 | - } |
|
426 | - |
|
427 | - |
|
428 | - /** |
|
429 | - * get_ticket_line_item_for_transaction |
|
430 | - * |
|
431 | - * @param int $TXN_ID |
|
432 | - * @param int $TKT_ID |
|
433 | - * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL |
|
434 | - * @throws EE_Error |
|
435 | - * @throws InvalidArgumentException |
|
436 | - * @throws InvalidDataTypeException |
|
437 | - * @throws InvalidInterfaceException |
|
438 | - */ |
|
439 | - public function get_ticket_line_item_for_transaction($TXN_ID, $TKT_ID) |
|
440 | - { |
|
441 | - return $this->get_one(array( |
|
442 | - array( |
|
443 | - 'TXN_ID' => EEM_Transaction::instance()->ensure_is_ID($TXN_ID), |
|
444 | - 'OBJ_ID' => $TKT_ID, |
|
445 | - 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET, |
|
446 | - ), |
|
447 | - )); |
|
448 | - } |
|
449 | - |
|
450 | - |
|
451 | - /** |
|
452 | - * get_existing_promotion_line_item |
|
453 | - * searches the cart for existing line items for the specified promotion |
|
454 | - * |
|
455 | - * @since 1.0.0 |
|
456 | - * @param EE_Line_Item $parent_line_item |
|
457 | - * @param EE_Promotion $promotion |
|
458 | - * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL |
|
459 | - * @throws EE_Error |
|
460 | - * @throws InvalidArgumentException |
|
461 | - * @throws InvalidDataTypeException |
|
462 | - * @throws InvalidInterfaceException |
|
463 | - * @throws ReflectionException |
|
464 | - */ |
|
465 | - public function get_existing_promotion_line_item(EE_Line_Item $parent_line_item, EE_Promotion $promotion) |
|
466 | - { |
|
467 | - return $this->get_one(array( |
|
468 | - array( |
|
469 | - 'TXN_ID' => $parent_line_item->TXN_ID(), |
|
470 | - 'LIN_parent' => $parent_line_item->ID(), |
|
471 | - 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_PROMOTION, |
|
472 | - 'OBJ_ID' => $promotion->ID(), |
|
473 | - ), |
|
474 | - )); |
|
475 | - } |
|
476 | - |
|
477 | - |
|
478 | - /** |
|
479 | - * get_all_promotion_line_items |
|
480 | - * searches the cart for any and all existing promotion line items |
|
481 | - * |
|
482 | - * @since 1.0.0 |
|
483 | - * @param EE_Line_Item $parent_line_item |
|
484 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
485 | - * @throws EE_Error |
|
486 | - * @throws InvalidArgumentException |
|
487 | - * @throws InvalidDataTypeException |
|
488 | - * @throws InvalidInterfaceException |
|
489 | - * @throws ReflectionException |
|
490 | - */ |
|
491 | - public function get_all_promotion_line_items(EE_Line_Item $parent_line_item) |
|
492 | - { |
|
493 | - return $this->get_all(array( |
|
494 | - array( |
|
495 | - 'TXN_ID' => $parent_line_item->TXN_ID(), |
|
496 | - 'LIN_parent' => $parent_line_item->ID(), |
|
497 | - 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_PROMOTION, |
|
498 | - ), |
|
499 | - )); |
|
500 | - } |
|
501 | - |
|
502 | - |
|
503 | - /** |
|
504 | - * Gets the registration's corresponding line item. |
|
505 | - * Note: basically does NOT support having multiple line items for a single ticket, |
|
506 | - * which would happen if some of the registrations had a price modifier while others didn't. |
|
507 | - * In order to support that, we'd probably need a LIN_ID on registrations or something. |
|
508 | - * |
|
509 | - * @param EE_Registration $registration |
|
510 | - * @return EE_Base_Class|EE_Line_ITem|EE_Soft_Delete_Base_Class|NULL |
|
511 | - * @throws EE_Error |
|
512 | - */ |
|
513 | - public function get_line_item_for_registration(EE_Registration $registration) |
|
514 | - { |
|
515 | - return $this->get_one($this->line_item_for_registration_query_params($registration)); |
|
516 | - } |
|
517 | - |
|
518 | - |
|
519 | - /** |
|
520 | - * Gets the query params used to retrieve a specific line item for the given registration |
|
521 | - * |
|
522 | - * @param EE_Registration $registration |
|
523 | - * @param array $original_query_params any extra query params you'd like to be merged with |
|
524 | - * @return array @see |
|
525 | - * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
526 | - * @throws EE_Error |
|
527 | - */ |
|
528 | - public function line_item_for_registration_query_params( |
|
529 | - EE_Registration $registration, |
|
530 | - $original_query_params = array() |
|
531 | - ) { |
|
532 | - return array_replace_recursive($original_query_params, array( |
|
533 | - array( |
|
534 | - 'OBJ_ID' => $registration->ticket_ID(), |
|
535 | - 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET, |
|
536 | - 'TXN_ID' => $registration->transaction_ID(), |
|
537 | - ), |
|
538 | - )); |
|
539 | - } |
|
540 | - |
|
541 | - |
|
542 | - /** |
|
543 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
544 | - * @throws InvalidInterfaceException |
|
545 | - * @throws InvalidDataTypeException |
|
546 | - * @throws EE_Error |
|
547 | - * @throws InvalidArgumentException |
|
548 | - */ |
|
549 | - public function get_total_line_items_with_no_transaction() |
|
550 | - { |
|
551 | - return $this->get_total_line_items_for_carts(); |
|
552 | - } |
|
553 | - |
|
554 | - |
|
555 | - /** |
|
556 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
557 | - * @throws InvalidInterfaceException |
|
558 | - * @throws InvalidDataTypeException |
|
559 | - * @throws EE_Error |
|
560 | - * @throws InvalidArgumentException |
|
561 | - */ |
|
562 | - public function get_total_line_items_for_active_carts() |
|
563 | - { |
|
564 | - return $this->get_total_line_items_for_carts(false); |
|
565 | - } |
|
566 | - |
|
567 | - |
|
568 | - /** |
|
569 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
570 | - * @throws InvalidInterfaceException |
|
571 | - * @throws InvalidDataTypeException |
|
572 | - * @throws EE_Error |
|
573 | - * @throws InvalidArgumentException |
|
574 | - */ |
|
575 | - public function get_total_line_items_for_expired_carts() |
|
576 | - { |
|
577 | - return $this->get_total_line_items_for_carts(true); |
|
578 | - } |
|
579 | - |
|
580 | - |
|
581 | - /** |
|
582 | - * Returns an array of grand total line items where the TXN_ID is 0. |
|
583 | - * If $expired is set to true, then only line items for expired sessions will be returned. |
|
584 | - * If $expired is set to false, then only line items for active sessions will be returned. |
|
585 | - * |
|
586 | - * @param null $expired |
|
587 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
588 | - * @throws EE_Error |
|
589 | - * @throws InvalidArgumentException |
|
590 | - * @throws InvalidDataTypeException |
|
591 | - * @throws InvalidInterfaceException |
|
592 | - */ |
|
593 | - private function get_total_line_items_for_carts($expired = null) |
|
594 | - { |
|
595 | - $where_params = array( |
|
596 | - 'TXN_ID' => 0, |
|
597 | - 'LIN_type' => 'total', |
|
598 | - ); |
|
599 | - if ($expired !== null) { |
|
600 | - /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
601 | - $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
602 | - 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
603 | - ); |
|
604 | - $where_params['LIN_timestamp'] = array( |
|
605 | - $expired ? '<=' : '>', |
|
606 | - $session_lifespan->expiration(), |
|
607 | - ); |
|
608 | - } |
|
609 | - return $this->get_all(array($where_params)); |
|
610 | - } |
|
611 | - |
|
612 | - |
|
613 | - /** |
|
614 | - * Returns an array of ticket total line items where the TXN_ID is 0 |
|
615 | - * AND the timestamp is older than the session lifespan. |
|
616 | - * |
|
617 | - * @param int $timestamp |
|
618 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
619 | - * @throws EE_Error |
|
620 | - * @throws InvalidArgumentException |
|
621 | - * @throws InvalidDataTypeException |
|
622 | - * @throws InvalidInterfaceException |
|
623 | - */ |
|
624 | - public function getTicketLineItemsForExpiredCarts($timestamp = 0) |
|
625 | - { |
|
626 | - if (! absint($timestamp)) { |
|
627 | - /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
628 | - $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
629 | - 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
630 | - ); |
|
631 | - $timestamp = $session_lifespan->expiration(); |
|
632 | - } |
|
633 | - return $this->get_all( |
|
634 | - array( |
|
635 | - array( |
|
636 | - 'TXN_ID' => 0, |
|
637 | - 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET, |
|
638 | - 'LIN_timestamp' => array('<=', $timestamp), |
|
639 | - ), |
|
640 | - ) |
|
641 | - ); |
|
642 | - } |
|
347 | + // use GMT time because that's what TXN_timestamps are in |
|
348 | + date('Y-m-d H:i:s', time() - $time_to_leave_alone) |
|
349 | + ); |
|
350 | + return $wpdb->query($query); |
|
351 | + } |
|
352 | + |
|
353 | + |
|
354 | + /** |
|
355 | + * get_line_item_for_transaction_object |
|
356 | + * Gets a transaction's line item record for a specific object such as a EE_Event or EE_Ticket |
|
357 | + * |
|
358 | + * @param int $TXN_ID |
|
359 | + * @param EE_Base_Class $object |
|
360 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
361 | + * @throws EE_Error |
|
362 | + * @throws InvalidArgumentException |
|
363 | + * @throws InvalidDataTypeException |
|
364 | + * @throws InvalidInterfaceException |
|
365 | + * @throws ReflectionException |
|
366 | + */ |
|
367 | + public function get_line_item_for_transaction_object($TXN_ID, EE_Base_Class $object) |
|
368 | + { |
|
369 | + return $this->get_all(array( |
|
370 | + array( |
|
371 | + 'TXN_ID' => $TXN_ID, |
|
372 | + 'OBJ_type' => str_replace('EE_', '', get_class($object)), |
|
373 | + 'OBJ_ID' => $object->ID(), |
|
374 | + ), |
|
375 | + )); |
|
376 | + } |
|
377 | + |
|
378 | + |
|
379 | + /** |
|
380 | + * get_object_line_items_for_transaction |
|
381 | + * Gets all of the the object line items for a transaction, based on an object type plus an array of object IDs |
|
382 | + * |
|
383 | + * @param int $TXN_ID |
|
384 | + * @param string $OBJ_type |
|
385 | + * @param array $OBJ_IDs |
|
386 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
387 | + * @throws EE_Error |
|
388 | + */ |
|
389 | + public function get_object_line_items_for_transaction( |
|
390 | + $TXN_ID, |
|
391 | + $OBJ_type = EEM_Line_Item::OBJ_TYPE_EVENT, |
|
392 | + $OBJ_IDs = array() |
|
393 | + ) { |
|
394 | + $query_params = array( |
|
395 | + 'OBJ_type' => $OBJ_type, |
|
396 | + // if incoming $OBJ_IDs is an array, then make sure it is formatted correctly for the query |
|
397 | + 'OBJ_ID' => is_array($OBJ_IDs) && ! isset($OBJ_IDs['IN']) ? array('IN', $OBJ_IDs) : $OBJ_IDs, |
|
398 | + ); |
|
399 | + if ($TXN_ID) { |
|
400 | + $query_params['TXN_ID'] = $TXN_ID; |
|
401 | + } |
|
402 | + return $this->get_all(array($query_params)); |
|
403 | + } |
|
404 | + |
|
405 | + |
|
406 | + /** |
|
407 | + * get_all_ticket_line_items_for_transaction |
|
408 | + * |
|
409 | + * @param EE_Transaction $transaction |
|
410 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
411 | + * @throws EE_Error |
|
412 | + * @throws InvalidArgumentException |
|
413 | + * @throws InvalidDataTypeException |
|
414 | + * @throws InvalidInterfaceException |
|
415 | + * @throws ReflectionException |
|
416 | + */ |
|
417 | + public function get_all_ticket_line_items_for_transaction(EE_Transaction $transaction) |
|
418 | + { |
|
419 | + return $this->get_all(array( |
|
420 | + array( |
|
421 | + 'TXN_ID' => $transaction->ID(), |
|
422 | + 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET, |
|
423 | + ), |
|
424 | + )); |
|
425 | + } |
|
426 | + |
|
427 | + |
|
428 | + /** |
|
429 | + * get_ticket_line_item_for_transaction |
|
430 | + * |
|
431 | + * @param int $TXN_ID |
|
432 | + * @param int $TKT_ID |
|
433 | + * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL |
|
434 | + * @throws EE_Error |
|
435 | + * @throws InvalidArgumentException |
|
436 | + * @throws InvalidDataTypeException |
|
437 | + * @throws InvalidInterfaceException |
|
438 | + */ |
|
439 | + public function get_ticket_line_item_for_transaction($TXN_ID, $TKT_ID) |
|
440 | + { |
|
441 | + return $this->get_one(array( |
|
442 | + array( |
|
443 | + 'TXN_ID' => EEM_Transaction::instance()->ensure_is_ID($TXN_ID), |
|
444 | + 'OBJ_ID' => $TKT_ID, |
|
445 | + 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET, |
|
446 | + ), |
|
447 | + )); |
|
448 | + } |
|
449 | + |
|
450 | + |
|
451 | + /** |
|
452 | + * get_existing_promotion_line_item |
|
453 | + * searches the cart for existing line items for the specified promotion |
|
454 | + * |
|
455 | + * @since 1.0.0 |
|
456 | + * @param EE_Line_Item $parent_line_item |
|
457 | + * @param EE_Promotion $promotion |
|
458 | + * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL |
|
459 | + * @throws EE_Error |
|
460 | + * @throws InvalidArgumentException |
|
461 | + * @throws InvalidDataTypeException |
|
462 | + * @throws InvalidInterfaceException |
|
463 | + * @throws ReflectionException |
|
464 | + */ |
|
465 | + public function get_existing_promotion_line_item(EE_Line_Item $parent_line_item, EE_Promotion $promotion) |
|
466 | + { |
|
467 | + return $this->get_one(array( |
|
468 | + array( |
|
469 | + 'TXN_ID' => $parent_line_item->TXN_ID(), |
|
470 | + 'LIN_parent' => $parent_line_item->ID(), |
|
471 | + 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_PROMOTION, |
|
472 | + 'OBJ_ID' => $promotion->ID(), |
|
473 | + ), |
|
474 | + )); |
|
475 | + } |
|
476 | + |
|
477 | + |
|
478 | + /** |
|
479 | + * get_all_promotion_line_items |
|
480 | + * searches the cart for any and all existing promotion line items |
|
481 | + * |
|
482 | + * @since 1.0.0 |
|
483 | + * @param EE_Line_Item $parent_line_item |
|
484 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
485 | + * @throws EE_Error |
|
486 | + * @throws InvalidArgumentException |
|
487 | + * @throws InvalidDataTypeException |
|
488 | + * @throws InvalidInterfaceException |
|
489 | + * @throws ReflectionException |
|
490 | + */ |
|
491 | + public function get_all_promotion_line_items(EE_Line_Item $parent_line_item) |
|
492 | + { |
|
493 | + return $this->get_all(array( |
|
494 | + array( |
|
495 | + 'TXN_ID' => $parent_line_item->TXN_ID(), |
|
496 | + 'LIN_parent' => $parent_line_item->ID(), |
|
497 | + 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_PROMOTION, |
|
498 | + ), |
|
499 | + )); |
|
500 | + } |
|
501 | + |
|
502 | + |
|
503 | + /** |
|
504 | + * Gets the registration's corresponding line item. |
|
505 | + * Note: basically does NOT support having multiple line items for a single ticket, |
|
506 | + * which would happen if some of the registrations had a price modifier while others didn't. |
|
507 | + * In order to support that, we'd probably need a LIN_ID on registrations or something. |
|
508 | + * |
|
509 | + * @param EE_Registration $registration |
|
510 | + * @return EE_Base_Class|EE_Line_ITem|EE_Soft_Delete_Base_Class|NULL |
|
511 | + * @throws EE_Error |
|
512 | + */ |
|
513 | + public function get_line_item_for_registration(EE_Registration $registration) |
|
514 | + { |
|
515 | + return $this->get_one($this->line_item_for_registration_query_params($registration)); |
|
516 | + } |
|
517 | + |
|
518 | + |
|
519 | + /** |
|
520 | + * Gets the query params used to retrieve a specific line item for the given registration |
|
521 | + * |
|
522 | + * @param EE_Registration $registration |
|
523 | + * @param array $original_query_params any extra query params you'd like to be merged with |
|
524 | + * @return array @see |
|
525 | + * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
526 | + * @throws EE_Error |
|
527 | + */ |
|
528 | + public function line_item_for_registration_query_params( |
|
529 | + EE_Registration $registration, |
|
530 | + $original_query_params = array() |
|
531 | + ) { |
|
532 | + return array_replace_recursive($original_query_params, array( |
|
533 | + array( |
|
534 | + 'OBJ_ID' => $registration->ticket_ID(), |
|
535 | + 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET, |
|
536 | + 'TXN_ID' => $registration->transaction_ID(), |
|
537 | + ), |
|
538 | + )); |
|
539 | + } |
|
540 | + |
|
541 | + |
|
542 | + /** |
|
543 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
544 | + * @throws InvalidInterfaceException |
|
545 | + * @throws InvalidDataTypeException |
|
546 | + * @throws EE_Error |
|
547 | + * @throws InvalidArgumentException |
|
548 | + */ |
|
549 | + public function get_total_line_items_with_no_transaction() |
|
550 | + { |
|
551 | + return $this->get_total_line_items_for_carts(); |
|
552 | + } |
|
553 | + |
|
554 | + |
|
555 | + /** |
|
556 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
557 | + * @throws InvalidInterfaceException |
|
558 | + * @throws InvalidDataTypeException |
|
559 | + * @throws EE_Error |
|
560 | + * @throws InvalidArgumentException |
|
561 | + */ |
|
562 | + public function get_total_line_items_for_active_carts() |
|
563 | + { |
|
564 | + return $this->get_total_line_items_for_carts(false); |
|
565 | + } |
|
566 | + |
|
567 | + |
|
568 | + /** |
|
569 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
570 | + * @throws InvalidInterfaceException |
|
571 | + * @throws InvalidDataTypeException |
|
572 | + * @throws EE_Error |
|
573 | + * @throws InvalidArgumentException |
|
574 | + */ |
|
575 | + public function get_total_line_items_for_expired_carts() |
|
576 | + { |
|
577 | + return $this->get_total_line_items_for_carts(true); |
|
578 | + } |
|
579 | + |
|
580 | + |
|
581 | + /** |
|
582 | + * Returns an array of grand total line items where the TXN_ID is 0. |
|
583 | + * If $expired is set to true, then only line items for expired sessions will be returned. |
|
584 | + * If $expired is set to false, then only line items for active sessions will be returned. |
|
585 | + * |
|
586 | + * @param null $expired |
|
587 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
588 | + * @throws EE_Error |
|
589 | + * @throws InvalidArgumentException |
|
590 | + * @throws InvalidDataTypeException |
|
591 | + * @throws InvalidInterfaceException |
|
592 | + */ |
|
593 | + private function get_total_line_items_for_carts($expired = null) |
|
594 | + { |
|
595 | + $where_params = array( |
|
596 | + 'TXN_ID' => 0, |
|
597 | + 'LIN_type' => 'total', |
|
598 | + ); |
|
599 | + if ($expired !== null) { |
|
600 | + /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
601 | + $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
602 | + 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
603 | + ); |
|
604 | + $where_params['LIN_timestamp'] = array( |
|
605 | + $expired ? '<=' : '>', |
|
606 | + $session_lifespan->expiration(), |
|
607 | + ); |
|
608 | + } |
|
609 | + return $this->get_all(array($where_params)); |
|
610 | + } |
|
611 | + |
|
612 | + |
|
613 | + /** |
|
614 | + * Returns an array of ticket total line items where the TXN_ID is 0 |
|
615 | + * AND the timestamp is older than the session lifespan. |
|
616 | + * |
|
617 | + * @param int $timestamp |
|
618 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
619 | + * @throws EE_Error |
|
620 | + * @throws InvalidArgumentException |
|
621 | + * @throws InvalidDataTypeException |
|
622 | + * @throws InvalidInterfaceException |
|
623 | + */ |
|
624 | + public function getTicketLineItemsForExpiredCarts($timestamp = 0) |
|
625 | + { |
|
626 | + if (! absint($timestamp)) { |
|
627 | + /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
628 | + $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
629 | + 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
630 | + ); |
|
631 | + $timestamp = $session_lifespan->expiration(); |
|
632 | + } |
|
633 | + return $this->get_all( |
|
634 | + array( |
|
635 | + array( |
|
636 | + 'TXN_ID' => 0, |
|
637 | + 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET, |
|
638 | + 'LIN_timestamp' => array('<=', $timestamp), |
|
639 | + ), |
|
640 | + ) |
|
641 | + ); |
|
642 | + } |
|
643 | 643 | } |
@@ -7,77 +7,77 @@ |
||
7 | 7 | class EE_Float_Field extends EE_Model_Field_Base |
8 | 8 | { |
9 | 9 | |
10 | - /** |
|
11 | - * @param string $table_column |
|
12 | - * @param string $nicename |
|
13 | - * @param bool $nullable |
|
14 | - * @param null $default_value |
|
15 | - */ |
|
16 | - public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
17 | - { |
|
18 | - parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
19 | - $this->setSchemaType('number'); |
|
20 | - } |
|
10 | + /** |
|
11 | + * @param string $table_column |
|
12 | + * @param string $nicename |
|
13 | + * @param bool $nullable |
|
14 | + * @param null $default_value |
|
15 | + */ |
|
16 | + public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
17 | + { |
|
18 | + parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
19 | + $this->setSchemaType('number'); |
|
20 | + } |
|
21 | 21 | |
22 | 22 | |
23 | - /** |
|
24 | - * If provided a string, strips out number-related formatting, like commas, periods, spaces, other junk, etc. |
|
25 | - * However, treats commas and periods as thousand-separators ro decimal marks, as indicate by the config's currency. |
|
26 | - * So if you want to pass in a string that NEEDS to interpret periods as decimal marks, call floatval() on it first. |
|
27 | - * Returns a float |
|
28 | - * |
|
29 | - * @param float|string $value_inputted_for_field_on_model_object |
|
30 | - * @return float |
|
31 | - */ |
|
32 | - public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
33 | - { |
|
23 | + /** |
|
24 | + * If provided a string, strips out number-related formatting, like commas, periods, spaces, other junk, etc. |
|
25 | + * However, treats commas and periods as thousand-separators ro decimal marks, as indicate by the config's currency. |
|
26 | + * So if you want to pass in a string that NEEDS to interpret periods as decimal marks, call floatval() on it first. |
|
27 | + * Returns a float |
|
28 | + * |
|
29 | + * @param float|string $value_inputted_for_field_on_model_object |
|
30 | + * @return float |
|
31 | + */ |
|
32 | + public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
33 | + { |
|
34 | 34 | // echo __LINE__."$value_inputted_for_field_on_model_object<br>"; |
35 | - // remove whitespaces and thousands separators |
|
36 | - if (is_string($value_inputted_for_field_on_model_object)) { |
|
37 | - $value_inputted_for_field_on_model_object = str_replace( |
|
38 | - array(" ", EE_Config::instance()->currency->thsnds), |
|
39 | - "", |
|
40 | - $value_inputted_for_field_on_model_object |
|
41 | - ); |
|
35 | + // remove whitespaces and thousands separators |
|
36 | + if (is_string($value_inputted_for_field_on_model_object)) { |
|
37 | + $value_inputted_for_field_on_model_object = str_replace( |
|
38 | + array(" ", EE_Config::instance()->currency->thsnds), |
|
39 | + "", |
|
40 | + $value_inputted_for_field_on_model_object |
|
41 | + ); |
|
42 | 42 | // echo __LINE__."$value_inputted_for_field_on_model_object<br>"; |
43 | 43 | // normalize it so periods are decimal marks (we don't care where you're from: we're talking PHP now) |
44 | - $value_inputted_for_field_on_model_object = str_replace( |
|
45 | - EE_Config::instance()->currency->dec_mrk, |
|
46 | - ".", |
|
47 | - $value_inputted_for_field_on_model_object |
|
48 | - ); |
|
44 | + $value_inputted_for_field_on_model_object = str_replace( |
|
45 | + EE_Config::instance()->currency->dec_mrk, |
|
46 | + ".", |
|
47 | + $value_inputted_for_field_on_model_object |
|
48 | + ); |
|
49 | 49 | // echo __LINE__."$value_inputted_for_field_on_model_object<br>"; |
50 | 50 | // double-check there's absolutely nothing left on this string besides numbers |
51 | - $value_inputted_for_field_on_model_object = preg_replace( |
|
52 | - "/[^0-9,.]/", |
|
53 | - "", |
|
54 | - $value_inputted_for_field_on_model_object |
|
55 | - ); |
|
56 | - } |
|
51 | + $value_inputted_for_field_on_model_object = preg_replace( |
|
52 | + "/[^0-9,.]/", |
|
53 | + "", |
|
54 | + $value_inputted_for_field_on_model_object |
|
55 | + ); |
|
56 | + } |
|
57 | 57 | // echo __LINE__."$value_inputted_for_field_on_model_object<br>"; |
58 | - return floatval($value_inputted_for_field_on_model_object); |
|
59 | - } |
|
58 | + return floatval($value_inputted_for_field_on_model_object); |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * Returns the number formatted according to local custom (set by the country of the blog). |
|
63 | - * |
|
64 | - * @param float $value_on_field_to_be_outputted |
|
65 | - * @return string |
|
66 | - */ |
|
67 | - public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) |
|
68 | - { |
|
69 | - $EE = EE_Registry::instance(); |
|
70 | - return number_format( |
|
71 | - $value_on_field_to_be_outputted, |
|
72 | - $EE->CFG->currency->dec_plc, |
|
73 | - $EE->CFG->currency->dec_mrk, |
|
74 | - $EE->CFG->currency->thsnds |
|
75 | - ); |
|
76 | - } |
|
61 | + /** |
|
62 | + * Returns the number formatted according to local custom (set by the country of the blog). |
|
63 | + * |
|
64 | + * @param float $value_on_field_to_be_outputted |
|
65 | + * @return string |
|
66 | + */ |
|
67 | + public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) |
|
68 | + { |
|
69 | + $EE = EE_Registry::instance(); |
|
70 | + return number_format( |
|
71 | + $value_on_field_to_be_outputted, |
|
72 | + $EE->CFG->currency->dec_plc, |
|
73 | + $EE->CFG->currency->dec_mrk, |
|
74 | + $EE->CFG->currency->thsnds |
|
75 | + ); |
|
76 | + } |
|
77 | 77 | |
78 | - public function prepare_for_set_from_db($value_found_in_db_for_model_object) |
|
79 | - { |
|
78 | + public function prepare_for_set_from_db($value_found_in_db_for_model_object) |
|
79 | + { |
|
80 | 80 | // echo "prepare for set from db of ";d($value_found_in_db_for_model_object); |
81 | - return floatval($value_found_in_db_for_model_object); |
|
82 | - } |
|
81 | + return floatval($value_found_in_db_for_model_object); |
|
82 | + } |
|
83 | 83 | } |
@@ -20,234 +20,234 @@ |
||
20 | 20 | */ |
21 | 21 | class TicketPriceModifiers |
22 | 22 | { |
23 | - /** |
|
24 | - * @var EE_Ticket |
|
25 | - */ |
|
26 | - private $ticket; |
|
27 | - |
|
28 | - |
|
29 | - /** |
|
30 | - * @var EE_Price[] |
|
31 | - */ |
|
32 | - private $ticket_prices; |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * @param EE_Ticket $ticket |
|
37 | - * @throws EE_Error |
|
38 | - * @throws ReflectionException |
|
39 | - */ |
|
40 | - public function __construct(EE_Ticket $ticket) |
|
41 | - { |
|
42 | - $this->ticket = $ticket; |
|
43 | - // run a query to retrieve ALL of this ticket's related prices before doing anything else |
|
44 | - $this->ticket_prices = $this->ticket->prices(); |
|
45 | - } |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * @param callable $filter |
|
50 | - * @return array |
|
51 | - * @throws EE_Error |
|
52 | - * @throws ReflectionException |
|
53 | - */ |
|
54 | - private function filterModifiersForTicket(callable $filter): array |
|
55 | - { |
|
56 | - $ticket_modifiers = $this->ticket->get_all_from_cache('Price'); |
|
57 | - if (empty($ticket_modifiers)) { |
|
58 | - $ticket_modifiers = $this->ticket_prices; |
|
59 | - } |
|
60 | - return array_filter($ticket_modifiers, $filter); |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * retrieve all price modifiers for the this ticket |
|
66 | - * |
|
67 | - * @return array |
|
68 | - * @throws EE_Error |
|
69 | - * @throws ReflectionException |
|
70 | - */ |
|
71 | - public function getAllModifiersForTicket(): array |
|
72 | - { |
|
73 | - return $this->filterModifiersForTicket([$this, 'allModifiersFilter']); |
|
74 | - } |
|
75 | - |
|
76 | - |
|
77 | - /** |
|
78 | - * pass to filterModifiersForTicket() with a ticket to retrieve all price modifiers for the this ticket |
|
79 | - * |
|
80 | - * @param EE_Price $price_modifier |
|
81 | - * @return bool |
|
82 | - * @throws EE_Error |
|
83 | - * @throws ReflectionException |
|
84 | - */ |
|
85 | - public function allModifiersFilter(EE_Price $price_modifier): bool |
|
86 | - { |
|
87 | - return ! $price_modifier->is_base_price(); |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * retrieve all discounts for the this ticket |
|
93 | - * |
|
94 | - * @return array |
|
95 | - * @throws EE_Error |
|
96 | - * @throws ReflectionException |
|
97 | - */ |
|
98 | - public function getAllDiscountModifiersForTicket(): array |
|
99 | - { |
|
100 | - return $this->filterModifiersForTicket([$this, 'discountModifierFilter']); |
|
101 | - } |
|
102 | - |
|
103 | - |
|
104 | - /** |
|
105 | - * pass to filterModifiersForTicket() with a ticket to retrieve all discounts for the this ticket |
|
106 | - * |
|
107 | - * @param EE_Price $price_modifier |
|
108 | - * @return bool |
|
109 | - * @throws EE_Error |
|
110 | - * @throws ReflectionException |
|
111 | - */ |
|
112 | - public function discountModifierFilter(EE_Price $price_modifier): bool |
|
113 | - { |
|
114 | - return $price_modifier->is_discount(); |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * retrieve all surcharges for the this ticket |
|
120 | - * |
|
121 | - * @return array |
|
122 | - * @throws EE_Error |
|
123 | - * @throws ReflectionException |
|
124 | - */ |
|
125 | - public function getAllSurchargeModifiersForTicket(): array |
|
126 | - { |
|
127 | - return $this->filterModifiersForTicket([$this, 'surchargeModifierFilter']); |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * pass to filterModifiersForTicket() with a ticket to retrieve all surcharges for the this ticket |
|
133 | - * |
|
134 | - * @param EE_Price $price_modifier |
|
135 | - * @return bool |
|
136 | - * @throws EE_Error |
|
137 | - * @throws ReflectionException |
|
138 | - */ |
|
139 | - public function surchargeModifierFilter(EE_Price $price_modifier): bool |
|
140 | - { |
|
141 | - return $price_modifier->is_surcharge(); |
|
142 | - } |
|
143 | - |
|
144 | - |
|
145 | - /** |
|
146 | - * retrieve all discounts AND surcharges for the this ticket |
|
147 | - * |
|
148 | - * @return array |
|
149 | - * @throws EE_Error |
|
150 | - * @throws ReflectionException |
|
151 | - */ |
|
152 | - public function getAllDiscountAndSurchargeModifiersForTicket(): array |
|
153 | - { |
|
154 | - return $this->filterModifiersForTicket([$this, 'discountAndSurchargeModifierFilter']); |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * pass to filterModifiersForTicket() with a ticket to retrieve all discounts AND surcharges for the this ticket |
|
160 | - * |
|
161 | - * @param EE_Price $price_modifier |
|
162 | - * @return bool |
|
163 | - * @throws EE_Error |
|
164 | - * @throws ReflectionException |
|
165 | - */ |
|
166 | - public function discountAndSurchargeModifierFilter(EE_Price $price_modifier): bool |
|
167 | - { |
|
168 | - return $price_modifier->is_discount() || $price_modifier->is_surcharge(); |
|
169 | - } |
|
170 | - |
|
171 | - |
|
172 | - /** |
|
173 | - * retrieve all taxes for the this ticket |
|
174 | - * |
|
175 | - * @return array |
|
176 | - * @throws EE_Error |
|
177 | - * @throws ReflectionException |
|
178 | - */ |
|
179 | - public function getAllTaxesForTicket(): array |
|
180 | - { |
|
181 | - return $this->filterModifiersForTicket([$this, 'taxModifierFilter']); |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * pass to filterModifiersForTicket() with a ticket to retrieve all taxes for the this ticket |
|
187 | - * |
|
188 | - * @param EE_Price $price_modifier |
|
189 | - * @return bool |
|
190 | - * @throws EE_Error |
|
191 | - * @throws ReflectionException |
|
192 | - */ |
|
193 | - public function taxModifierFilter(EE_Price $price_modifier): bool |
|
194 | - { |
|
195 | - return $price_modifier->is_tax(); |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - /** |
|
200 | - * retrieve ALL PRICES that are NOT taxes for the this ticket |
|
201 | - * |
|
202 | - * @return array |
|
203 | - * @throws EE_Error |
|
204 | - * @throws ReflectionException |
|
205 | - */ |
|
206 | - public function getAllNonTaxPricesForTicket(): array |
|
207 | - { |
|
208 | - return $this->filterModifiersForTicket([$this, 'nonTaxPriceFilter']); |
|
209 | - } |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * pass to filterModifiersForTicket() with a ticket |
|
214 | - * to retrieve ALL PRICES that are NOT taxes for the this ticket |
|
215 | - * |
|
216 | - * @param EE_Price $price_modifier |
|
217 | - * @return bool |
|
218 | - * @throws EE_Error |
|
219 | - * @throws ReflectionException |
|
220 | - */ |
|
221 | - public function nonTaxPriceFilter(EE_Price $price_modifier): bool |
|
222 | - { |
|
223 | - return ! $price_modifier->is_base_price() && ! $price_modifier->is_tax(); |
|
224 | - } |
|
225 | - |
|
226 | - |
|
227 | - /** |
|
228 | - * retrieve the base price for the this ticket |
|
229 | - * |
|
230 | - * @return array |
|
231 | - * @throws EE_Error |
|
232 | - * @throws ReflectionException |
|
233 | - */ |
|
234 | - public function getBasePrice(): array |
|
235 | - { |
|
236 | - return $this->filterModifiersForTicket([$this, 'basePriceFilter']); |
|
237 | - } |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * pass to filterModifiersForTicket() |
|
242 | - * to retrieve the base price for the this ticket |
|
243 | - * |
|
244 | - * @param EE_Price $price_modifier |
|
245 | - * @return bool |
|
246 | - * @throws EE_Error |
|
247 | - * @throws ReflectionException |
|
248 | - */ |
|
249 | - public function basePriceFilter(EE_Price $price_modifier): bool |
|
250 | - { |
|
251 | - return $price_modifier->is_base_price(); |
|
252 | - } |
|
23 | + /** |
|
24 | + * @var EE_Ticket |
|
25 | + */ |
|
26 | + private $ticket; |
|
27 | + |
|
28 | + |
|
29 | + /** |
|
30 | + * @var EE_Price[] |
|
31 | + */ |
|
32 | + private $ticket_prices; |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * @param EE_Ticket $ticket |
|
37 | + * @throws EE_Error |
|
38 | + * @throws ReflectionException |
|
39 | + */ |
|
40 | + public function __construct(EE_Ticket $ticket) |
|
41 | + { |
|
42 | + $this->ticket = $ticket; |
|
43 | + // run a query to retrieve ALL of this ticket's related prices before doing anything else |
|
44 | + $this->ticket_prices = $this->ticket->prices(); |
|
45 | + } |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * @param callable $filter |
|
50 | + * @return array |
|
51 | + * @throws EE_Error |
|
52 | + * @throws ReflectionException |
|
53 | + */ |
|
54 | + private function filterModifiersForTicket(callable $filter): array |
|
55 | + { |
|
56 | + $ticket_modifiers = $this->ticket->get_all_from_cache('Price'); |
|
57 | + if (empty($ticket_modifiers)) { |
|
58 | + $ticket_modifiers = $this->ticket_prices; |
|
59 | + } |
|
60 | + return array_filter($ticket_modifiers, $filter); |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * retrieve all price modifiers for the this ticket |
|
66 | + * |
|
67 | + * @return array |
|
68 | + * @throws EE_Error |
|
69 | + * @throws ReflectionException |
|
70 | + */ |
|
71 | + public function getAllModifiersForTicket(): array |
|
72 | + { |
|
73 | + return $this->filterModifiersForTicket([$this, 'allModifiersFilter']); |
|
74 | + } |
|
75 | + |
|
76 | + |
|
77 | + /** |
|
78 | + * pass to filterModifiersForTicket() with a ticket to retrieve all price modifiers for the this ticket |
|
79 | + * |
|
80 | + * @param EE_Price $price_modifier |
|
81 | + * @return bool |
|
82 | + * @throws EE_Error |
|
83 | + * @throws ReflectionException |
|
84 | + */ |
|
85 | + public function allModifiersFilter(EE_Price $price_modifier): bool |
|
86 | + { |
|
87 | + return ! $price_modifier->is_base_price(); |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * retrieve all discounts for the this ticket |
|
93 | + * |
|
94 | + * @return array |
|
95 | + * @throws EE_Error |
|
96 | + * @throws ReflectionException |
|
97 | + */ |
|
98 | + public function getAllDiscountModifiersForTicket(): array |
|
99 | + { |
|
100 | + return $this->filterModifiersForTicket([$this, 'discountModifierFilter']); |
|
101 | + } |
|
102 | + |
|
103 | + |
|
104 | + /** |
|
105 | + * pass to filterModifiersForTicket() with a ticket to retrieve all discounts for the this ticket |
|
106 | + * |
|
107 | + * @param EE_Price $price_modifier |
|
108 | + * @return bool |
|
109 | + * @throws EE_Error |
|
110 | + * @throws ReflectionException |
|
111 | + */ |
|
112 | + public function discountModifierFilter(EE_Price $price_modifier): bool |
|
113 | + { |
|
114 | + return $price_modifier->is_discount(); |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * retrieve all surcharges for the this ticket |
|
120 | + * |
|
121 | + * @return array |
|
122 | + * @throws EE_Error |
|
123 | + * @throws ReflectionException |
|
124 | + */ |
|
125 | + public function getAllSurchargeModifiersForTicket(): array |
|
126 | + { |
|
127 | + return $this->filterModifiersForTicket([$this, 'surchargeModifierFilter']); |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * pass to filterModifiersForTicket() with a ticket to retrieve all surcharges for the this ticket |
|
133 | + * |
|
134 | + * @param EE_Price $price_modifier |
|
135 | + * @return bool |
|
136 | + * @throws EE_Error |
|
137 | + * @throws ReflectionException |
|
138 | + */ |
|
139 | + public function surchargeModifierFilter(EE_Price $price_modifier): bool |
|
140 | + { |
|
141 | + return $price_modifier->is_surcharge(); |
|
142 | + } |
|
143 | + |
|
144 | + |
|
145 | + /** |
|
146 | + * retrieve all discounts AND surcharges for the this ticket |
|
147 | + * |
|
148 | + * @return array |
|
149 | + * @throws EE_Error |
|
150 | + * @throws ReflectionException |
|
151 | + */ |
|
152 | + public function getAllDiscountAndSurchargeModifiersForTicket(): array |
|
153 | + { |
|
154 | + return $this->filterModifiersForTicket([$this, 'discountAndSurchargeModifierFilter']); |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * pass to filterModifiersForTicket() with a ticket to retrieve all discounts AND surcharges for the this ticket |
|
160 | + * |
|
161 | + * @param EE_Price $price_modifier |
|
162 | + * @return bool |
|
163 | + * @throws EE_Error |
|
164 | + * @throws ReflectionException |
|
165 | + */ |
|
166 | + public function discountAndSurchargeModifierFilter(EE_Price $price_modifier): bool |
|
167 | + { |
|
168 | + return $price_modifier->is_discount() || $price_modifier->is_surcharge(); |
|
169 | + } |
|
170 | + |
|
171 | + |
|
172 | + /** |
|
173 | + * retrieve all taxes for the this ticket |
|
174 | + * |
|
175 | + * @return array |
|
176 | + * @throws EE_Error |
|
177 | + * @throws ReflectionException |
|
178 | + */ |
|
179 | + public function getAllTaxesForTicket(): array |
|
180 | + { |
|
181 | + return $this->filterModifiersForTicket([$this, 'taxModifierFilter']); |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * pass to filterModifiersForTicket() with a ticket to retrieve all taxes for the this ticket |
|
187 | + * |
|
188 | + * @param EE_Price $price_modifier |
|
189 | + * @return bool |
|
190 | + * @throws EE_Error |
|
191 | + * @throws ReflectionException |
|
192 | + */ |
|
193 | + public function taxModifierFilter(EE_Price $price_modifier): bool |
|
194 | + { |
|
195 | + return $price_modifier->is_tax(); |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + /** |
|
200 | + * retrieve ALL PRICES that are NOT taxes for the this ticket |
|
201 | + * |
|
202 | + * @return array |
|
203 | + * @throws EE_Error |
|
204 | + * @throws ReflectionException |
|
205 | + */ |
|
206 | + public function getAllNonTaxPricesForTicket(): array |
|
207 | + { |
|
208 | + return $this->filterModifiersForTicket([$this, 'nonTaxPriceFilter']); |
|
209 | + } |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * pass to filterModifiersForTicket() with a ticket |
|
214 | + * to retrieve ALL PRICES that are NOT taxes for the this ticket |
|
215 | + * |
|
216 | + * @param EE_Price $price_modifier |
|
217 | + * @return bool |
|
218 | + * @throws EE_Error |
|
219 | + * @throws ReflectionException |
|
220 | + */ |
|
221 | + public function nonTaxPriceFilter(EE_Price $price_modifier): bool |
|
222 | + { |
|
223 | + return ! $price_modifier->is_base_price() && ! $price_modifier->is_tax(); |
|
224 | + } |
|
225 | + |
|
226 | + |
|
227 | + /** |
|
228 | + * retrieve the base price for the this ticket |
|
229 | + * |
|
230 | + * @return array |
|
231 | + * @throws EE_Error |
|
232 | + * @throws ReflectionException |
|
233 | + */ |
|
234 | + public function getBasePrice(): array |
|
235 | + { |
|
236 | + return $this->filterModifiersForTicket([$this, 'basePriceFilter']); |
|
237 | + } |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * pass to filterModifiersForTicket() |
|
242 | + * to retrieve the base price for the this ticket |
|
243 | + * |
|
244 | + * @param EE_Price $price_modifier |
|
245 | + * @return bool |
|
246 | + * @throws EE_Error |
|
247 | + * @throws ReflectionException |
|
248 | + */ |
|
249 | + public function basePriceFilter(EE_Price $price_modifier): bool |
|
250 | + { |
|
251 | + return $price_modifier->is_base_price(); |
|
252 | + } |
|
253 | 253 | } |
@@ -16,14 +16,14 @@ |
||
16 | 16 | { |
17 | 17 | |
18 | 18 | |
19 | - /** |
|
20 | - * process |
|
21 | - * |
|
22 | - * @param EE_Line_Item $line_item |
|
23 | - * @return EE_Line_Item |
|
24 | - */ |
|
25 | - public function process(EE_Line_Item $line_item): ?EE_Line_Item |
|
26 | - { |
|
27 | - return $line_item; |
|
28 | - } |
|
19 | + /** |
|
20 | + * process |
|
21 | + * |
|
22 | + * @param EE_Line_Item $line_item |
|
23 | + * @return EE_Line_Item |
|
24 | + */ |
|
25 | + public function process(EE_Line_Item $line_item): ?EE_Line_Item |
|
26 | + { |
|
27 | + return $line_item; |
|
28 | + } |
|
29 | 29 | } |
@@ -36,95 +36,95 @@ |
||
36 | 36 | class EE_Line_Item_Filter_Processor |
37 | 37 | { |
38 | 38 | |
39 | - /** |
|
40 | - * @type EE_Line_Item_Filter_Collection $line_item_filters |
|
41 | - */ |
|
42 | - protected $line_item_filters; |
|
39 | + /** |
|
40 | + * @type EE_Line_Item_Filter_Collection $line_item_filters |
|
41 | + */ |
|
42 | + protected $line_item_filters; |
|
43 | 43 | |
44 | - /** |
|
45 | - * @type EE_Line_Item $grand_total_line_item |
|
46 | - */ |
|
47 | - protected $grand_total_line_item; |
|
44 | + /** |
|
45 | + * @type EE_Line_Item $grand_total_line_item |
|
46 | + */ |
|
47 | + protected $grand_total_line_item; |
|
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * EE_Line_Item_Filter_Processor constructor. |
|
52 | - * |
|
53 | - * @param EE_Line_Item_Filter_Collection $line_item_filters |
|
54 | - * @param EE_Line_Item $grand_total_line_item |
|
55 | - * @throws EE_Error |
|
56 | - * @throws ReflectionException |
|
57 | - */ |
|
58 | - public function __construct(EE_Line_Item_Filter_Collection $line_item_filters, EE_Line_Item $grand_total_line_item) |
|
59 | - { |
|
60 | - $this->line_item_filters = $line_item_filters; |
|
61 | - if ($grand_total_line_item->type() !== EEM_Line_Item::type_total) { |
|
62 | - throw new EE_Error(__('A Line Item of the type total is required', 'event_espresso')); |
|
63 | - } |
|
64 | - $this->grand_total_line_item = $this->clone_and_reset_line_item_tree($grand_total_line_item); |
|
65 | - } |
|
50 | + /** |
|
51 | + * EE_Line_Item_Filter_Processor constructor. |
|
52 | + * |
|
53 | + * @param EE_Line_Item_Filter_Collection $line_item_filters |
|
54 | + * @param EE_Line_Item $grand_total_line_item |
|
55 | + * @throws EE_Error |
|
56 | + * @throws ReflectionException |
|
57 | + */ |
|
58 | + public function __construct(EE_Line_Item_Filter_Collection $line_item_filters, EE_Line_Item $grand_total_line_item) |
|
59 | + { |
|
60 | + $this->line_item_filters = $line_item_filters; |
|
61 | + if ($grand_total_line_item->type() !== EEM_Line_Item::type_total) { |
|
62 | + throw new EE_Error(__('A Line Item of the type total is required', 'event_espresso')); |
|
63 | + } |
|
64 | + $this->grand_total_line_item = $this->clone_and_reset_line_item_tree($grand_total_line_item); |
|
65 | + } |
|
66 | 66 | |
67 | 67 | |
68 | - /** |
|
69 | - * clone_and_reset_line_item_tree |
|
70 | - * |
|
71 | - * @param EE_Line_Item $line_item |
|
72 | - * @return EE_Line_Item |
|
73 | - * @throws EE_Error |
|
74 | - * @throws ReflectionException |
|
75 | - */ |
|
76 | - protected function clone_and_reset_line_item_tree(EE_Line_Item $line_item): EE_Line_Item |
|
77 | - { |
|
78 | - $cloned_line_item = $this->clone_and_reset_line_item($line_item); |
|
79 | - foreach ($line_item->children() as $child_line_item) { |
|
80 | - $cloned_line_item->add_child_line_item($this->clone_and_reset_line_item_tree($child_line_item)); |
|
81 | - } |
|
82 | - return $cloned_line_item; |
|
83 | - } |
|
68 | + /** |
|
69 | + * clone_and_reset_line_item_tree |
|
70 | + * |
|
71 | + * @param EE_Line_Item $line_item |
|
72 | + * @return EE_Line_Item |
|
73 | + * @throws EE_Error |
|
74 | + * @throws ReflectionException |
|
75 | + */ |
|
76 | + protected function clone_and_reset_line_item_tree(EE_Line_Item $line_item): EE_Line_Item |
|
77 | + { |
|
78 | + $cloned_line_item = $this->clone_and_reset_line_item($line_item); |
|
79 | + foreach ($line_item->children() as $child_line_item) { |
|
80 | + $cloned_line_item->add_child_line_item($this->clone_and_reset_line_item_tree($child_line_item)); |
|
81 | + } |
|
82 | + return $cloned_line_item; |
|
83 | + } |
|
84 | 84 | |
85 | 85 | |
86 | - /** |
|
87 | - * clone_and_reset_line_item |
|
88 | - * |
|
89 | - * clones the incoming object |
|
90 | - * resets any fields that represent database primary keys |
|
91 | - * resets total |
|
92 | - * |
|
93 | - * @param EE_Line_Item $line_item |
|
94 | - * @return EE_Line_Item |
|
95 | - * @throws EE_Error |
|
96 | - * @throws ReflectionException |
|
97 | - */ |
|
98 | - protected function clone_and_reset_line_item(EE_Line_Item $line_item): EE_Line_Item |
|
99 | - { |
|
100 | - // we don't actually want to work with the original line item, so clone it |
|
101 | - $cloned_line_item = clone $line_item; |
|
102 | - $cloned_line_item->set('LIN_ID', null); |
|
103 | - $cloned_line_item->set('LIN_parent', null); |
|
104 | - $cloned_line_item->clear_related_line_item_cache(); |
|
105 | - foreach (array_keys(EEM_Line_Item::instance()->relation_settings()) as $relation_name) { |
|
106 | - $cloned_line_item->clear_cache($relation_name, null, true); |
|
107 | - } |
|
108 | - $cloned_line_item->set_allow_persist(false); |
|
109 | - return $cloned_line_item; |
|
110 | - } |
|
86 | + /** |
|
87 | + * clone_and_reset_line_item |
|
88 | + * |
|
89 | + * clones the incoming object |
|
90 | + * resets any fields that represent database primary keys |
|
91 | + * resets total |
|
92 | + * |
|
93 | + * @param EE_Line_Item $line_item |
|
94 | + * @return EE_Line_Item |
|
95 | + * @throws EE_Error |
|
96 | + * @throws ReflectionException |
|
97 | + */ |
|
98 | + protected function clone_and_reset_line_item(EE_Line_Item $line_item): EE_Line_Item |
|
99 | + { |
|
100 | + // we don't actually want to work with the original line item, so clone it |
|
101 | + $cloned_line_item = clone $line_item; |
|
102 | + $cloned_line_item->set('LIN_ID', null); |
|
103 | + $cloned_line_item->set('LIN_parent', null); |
|
104 | + $cloned_line_item->clear_related_line_item_cache(); |
|
105 | + foreach (array_keys(EEM_Line_Item::instance()->relation_settings()) as $relation_name) { |
|
106 | + $cloned_line_item->clear_cache($relation_name, null, true); |
|
107 | + } |
|
108 | + $cloned_line_item->set_allow_persist(false); |
|
109 | + return $cloned_line_item; |
|
110 | + } |
|
111 | 111 | |
112 | 112 | |
113 | - /** |
|
114 | - * process |
|
115 | - * |
|
116 | - * @return EE_Line_Item |
|
117 | - * @throws EE_Error |
|
118 | - * @throws ReflectionException |
|
119 | - */ |
|
120 | - public function process(): ?EE_Line_Item |
|
121 | - { |
|
122 | - $this->line_item_filters->rewind(); |
|
123 | - while ($this->line_item_filters->valid()) { |
|
124 | - $this->grand_total_line_item = $this->line_item_filters->current()->process($this->grand_total_line_item); |
|
125 | - $this->line_item_filters->next(); |
|
126 | - } |
|
127 | - $this->grand_total_line_item->recalculate_total_including_taxes(); |
|
128 | - return $this->grand_total_line_item; |
|
129 | - } |
|
113 | + /** |
|
114 | + * process |
|
115 | + * |
|
116 | + * @return EE_Line_Item |
|
117 | + * @throws EE_Error |
|
118 | + * @throws ReflectionException |
|
119 | + */ |
|
120 | + public function process(): ?EE_Line_Item |
|
121 | + { |
|
122 | + $this->line_item_filters->rewind(); |
|
123 | + while ($this->line_item_filters->valid()) { |
|
124 | + $this->grand_total_line_item = $this->line_item_filters->current()->process($this->grand_total_line_item); |
|
125 | + $this->line_item_filters->next(); |
|
126 | + } |
|
127 | + $this->grand_total_line_item->recalculate_total_including_taxes(); |
|
128 | + return $this->grand_total_line_item; |
|
129 | + } |
|
130 | 130 | } |