Conditions | 1 |
Paths | 1 |
Total Lines | 211 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
60 | protected function __construct($timezone) |
||
61 | { |
||
62 | $this->singular_item = esc_html__('Ticket', 'event_espresso'); |
||
63 | $this->plural_item = esc_html__('Tickets', 'event_espresso'); |
||
64 | $this->_tables = array( |
||
65 | 'Ticket' => new EE_Primary_Table('esp_ticket', 'TKT_ID'), |
||
66 | ); |
||
67 | $this->ticket_visibility = (array) apply_filters( |
||
68 | 'FHEE__EEM_Ticket__construct__ticket_visibility', |
||
69 | [ |
||
70 | EEM_Ticket::TICKET_VISIBILITY_PUBLIC => esc_html__('Public', 'event_espresso'), |
||
71 | EEM_Ticket::TICKET_VISIBILITY_MEMBERS_ONLY => esc_html__('Members only', 'event_espresso'), |
||
72 | EEM_Ticket::TICKET_VISIBILITY_ADMINS_ONLY => esc_html__('Admins only', 'event_espresso'), |
||
73 | EEM_Ticket::TICKET_VISIBILITY_ADMIN_UI_ONLY => esc_html__('Admin UI only', 'event_espresso'), |
||
74 | EEM_Ticket::TICKET_VISIBILITY_NONE => esc_html__('None', 'event_espresso'), |
||
75 | ] |
||
76 | ); |
||
77 | $this->_fields = array( |
||
78 | 'Ticket' => array( |
||
79 | 'TKT_ID' => new EE_Primary_Key_Int_Field( |
||
80 | 'TKT_ID', |
||
81 | esc_html__('Ticket ID', 'event_espresso') |
||
82 | ), |
||
83 | 'TTM_ID' => new EE_Foreign_Key_Int_Field( |
||
84 | 'TTM_ID', |
||
85 | esc_html__('Ticket Template ID', 'event_espresso'), |
||
86 | false, |
||
87 | 0, |
||
88 | 'Ticket_Template' |
||
89 | ), |
||
90 | 'TKT_name' => new EE_Plain_Text_Field( |
||
91 | 'TKT_name', |
||
92 | esc_html__('Ticket Name', 'event_espresso'), |
||
93 | false, |
||
94 | '' |
||
95 | ), |
||
96 | 'TKT_description' => new EE_Post_Content_Field( |
||
97 | 'TKT_description', |
||
98 | esc_html__('Description of Ticket', 'event_espresso'), |
||
99 | false, |
||
100 | '' |
||
101 | ), |
||
102 | 'TKT_start_date' => new EE_Datetime_Field( |
||
103 | 'TKT_start_date', |
||
104 | esc_html__('Start time/date of Ticket', 'event_espresso'), |
||
105 | false, |
||
106 | EE_Datetime_Field::now, |
||
107 | $timezone |
||
108 | ), |
||
109 | 'TKT_end_date' => new EE_Datetime_Field( |
||
110 | 'TKT_end_date', |
||
111 | esc_html__('End time/date of Ticket', 'event_espresso'), |
||
112 | false, |
||
113 | EE_Datetime_Field::now, |
||
114 | $timezone |
||
115 | ), |
||
116 | 'TKT_min' => new EE_Integer_Field( |
||
117 | 'TKT_min', |
||
118 | esc_html__('Minimum quantity of this ticket that must be purchased', 'event_espresso'), |
||
119 | false, |
||
120 | 0 |
||
121 | ), |
||
122 | 'TKT_max' => new EE_Infinite_Integer_Field( |
||
123 | 'TKT_max', |
||
124 | esc_html__( |
||
125 | 'Maximum quantity of this ticket that can be purchased in one transaction', |
||
126 | 'event_espresso' |
||
127 | ), |
||
128 | false, |
||
129 | EE_INF |
||
130 | ), |
||
131 | 'TKT_price' => new EE_Money_Field( |
||
132 | 'TKT_price', |
||
133 | esc_html__('Final calculated price for ticket', 'event_espresso'), |
||
134 | false, |
||
135 | 0 |
||
136 | ), |
||
137 | 'TKT_sold' => new EE_Integer_Field( |
||
138 | 'TKT_sold', |
||
139 | esc_html__('Number of this ticket sold', 'event_espresso'), |
||
140 | false, |
||
141 | 0 |
||
142 | ), |
||
143 | 'TKT_qty' => new EE_Infinite_Integer_Field( |
||
144 | 'TKT_qty', |
||
145 | esc_html__('Quantity of this ticket that is available', 'event_espresso'), |
||
146 | false, |
||
147 | EE_INF |
||
148 | ), |
||
149 | 'TKT_reserved' => new EE_Integer_Field( |
||
150 | 'TKT_reserved', |
||
151 | esc_html__( |
||
152 | 'Quantity of this ticket that is reserved, but not yet fully purchased', |
||
153 | 'event_espresso' |
||
154 | ), |
||
155 | false, |
||
156 | 0 |
||
157 | ), |
||
158 | 'TKT_uses' => new EE_Infinite_Integer_Field( |
||
159 | 'TKT_uses', |
||
160 | esc_html__('Number of datetimes this ticket can be used at', 'event_espresso'), |
||
161 | false, |
||
162 | EE_INF |
||
163 | ), |
||
164 | 'TKT_required' => new EE_Boolean_Field( |
||
165 | 'TKT_required', |
||
166 | esc_html__( |
||
167 | 'Flag indicating whether this ticket must be purchased with a transaction', |
||
168 | 'event_espresso' |
||
169 | ), |
||
170 | false, |
||
171 | false |
||
172 | ), |
||
173 | 'TKT_taxable' => new EE_Boolean_Field( |
||
174 | 'TKT_taxable', |
||
175 | esc_html__( |
||
176 | 'Flag indicating whether there is tax applied on this ticket', |
||
177 | 'event_espresso' |
||
178 | ), |
||
179 | false, |
||
180 | false |
||
181 | ), |
||
182 | 'TKT_is_default' => new EE_Boolean_Field( |
||
183 | 'TKT_is_default', |
||
184 | esc_html__('Flag indicating that this ticket is a default ticket', 'event_espresso'), |
||
185 | false, |
||
186 | false |
||
187 | ), |
||
188 | 'TKT_order' => new EE_Integer_Field( |
||
189 | 'TKT_order', |
||
190 | esc_html__( |
||
191 | 'The order in which the Ticket is displayed in the editor (used for autosaves when the form doesn\'t have the ticket ID yet)', |
||
192 | 'event_espresso' |
||
193 | ), |
||
194 | false, |
||
195 | 0 |
||
196 | ), |
||
197 | 'TKT_row' => new EE_Integer_Field( |
||
198 | 'TKT_row', |
||
199 | esc_html__('How tickets are displayed in the ui', 'event_espresso'), |
||
200 | false, |
||
201 | 0 |
||
202 | ), |
||
203 | 'TKT_deleted' => new EE_Trashed_Flag_Field( |
||
204 | 'TKT_deleted', |
||
205 | esc_html__('Flag indicating if this has been archived or not', 'event_espresso'), |
||
206 | false, |
||
207 | false |
||
208 | ), |
||
209 | 'TKT_wp_user' => new EE_WP_User_Field( |
||
210 | 'TKT_wp_user', |
||
211 | esc_html__('Ticket Creator ID', 'event_espresso'), |
||
212 | false |
||
213 | ), |
||
214 | 'TKT_parent' => new EE_Integer_Field( |
||
215 | 'TKT_parent', |
||
216 | esc_html__( |
||
217 | 'Indicates what TKT_ID is the parent of this TKT_ID (used in autosaves/revisions)', |
||
218 | 'event_espresso' |
||
219 | ), |
||
220 | true, |
||
221 | 0 |
||
222 | ), |
||
223 | 'TKT_reverse_calculate' => new EE_Boolean_Field( |
||
224 | 'TKT_reverse_calculate', |
||
225 | esc_html__( |
||
226 | 'Flag indicating whether ticket calculations should run in reverse and calculate the base ticket price from the provided ticket total.', |
||
227 | 'event_espresso' |
||
228 | ), |
||
229 | false, |
||
230 | false |
||
231 | ), |
||
232 | 'TKT_visibility' => new EE_Enum_Integer_Field( |
||
233 | 'TKT_visibility', |
||
234 | esc_html__('Defines where the ticket can be viewed throughout the UI.', 'event_espresso'), |
||
235 | false, |
||
236 | EEM_Ticket::TICKET_VISIBILITY_PUBLIC, |
||
237 | $this->ticket_visibility |
||
238 | ), |
||
239 | ), |
||
240 | ); |
||
241 | $this->_model_relations = array( |
||
242 | 'Datetime' => new EE_HABTM_Relation('Datetime_Ticket'), |
||
243 | 'Datetime_Ticket' => new EE_Has_Many_Relation(), |
||
244 | 'Price' => new EE_HABTM_Relation('Ticket_Price'), |
||
245 | 'Ticket_Template' => new EE_Belongs_To_Relation(), |
||
246 | 'Registration' => new EE_Has_Many_Relation(), |
||
247 | 'WP_User' => new EE_Belongs_To_Relation(), |
||
248 | ); |
||
249 | // this model is generally available for reading |
||
250 | $path_to_event = 'Datetime.Event'; |
||
251 | $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public( |
||
252 | 'TKT_is_default', |
||
253 | $path_to_event |
||
254 | ); |
||
255 | // account for default tickets in the caps |
||
256 | $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected( |
||
257 | 'TKT_is_default', |
||
258 | $path_to_event |
||
259 | ); |
||
260 | $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected( |
||
261 | 'TKT_is_default', |
||
262 | $path_to_event |
||
263 | ); |
||
264 | $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected( |
||
265 | 'TKT_is_default', |
||
266 | $path_to_event |
||
267 | ); |
||
268 | $this->model_chain_to_password = $path_to_event; |
||
269 | parent::__construct($timezone); |
||
270 | } |
||
271 | |||
394 |