@@ -17,362 +17,362 @@ |
||
17 | 17 | class EE_Maintenance_Mode implements ResettableInterface |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * constants available to client code for interpreting the values of EE_Maintenance_Mode::level(). |
|
22 | - * level_0_not_in_maintenance means the site is NOT in maintenance mode (so everything's normal) |
|
23 | - */ |
|
24 | - const level_0_not_in_maintenance = 0; |
|
25 | - |
|
26 | - /** |
|
27 | - * level_1_frontend_only_maintenance means that the site's frontend EE code should be completely disabled |
|
28 | - * but the admin backend should be running as normal. Maybe an admin can view the frontend though |
|
29 | - */ |
|
30 | - const level_1_frontend_only_maintenance = 1; |
|
31 | - |
|
32 | - /** |
|
33 | - * level_2_complete_maintenance means the frontend AND EE backend code are disabled. The only system running |
|
34 | - * is the maintenance mode stuff, which will require users to update all addons, and then finish running all |
|
35 | - * migration scripts before taking the site out of maintenance mode |
|
36 | - */ |
|
37 | - const level_2_complete_maintenance = 2; |
|
38 | - |
|
39 | - /** |
|
40 | - * the name of the option which stores the current level of maintenance mode |
|
41 | - */ |
|
42 | - const option_name_maintenance_mode = 'ee_maintenance_mode'; |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * @var EE_Maintenance_Mode $_instance |
|
47 | - */ |
|
48 | - private static $_instance; |
|
49 | - |
|
50 | - /** |
|
51 | - * @var EE_Registry $EE |
|
52 | - */ |
|
53 | - protected $EE; |
|
54 | - |
|
55 | - |
|
56 | - |
|
57 | - /** |
|
58 | - * @singleton method used to instantiate class object |
|
59 | - * @return EE_Maintenance_Mode |
|
60 | - */ |
|
61 | - public static function instance() |
|
62 | - { |
|
63 | - // check if class object is instantiated |
|
64 | - if (! self::$_instance instanceof EE_Maintenance_Mode) { |
|
65 | - self::$_instance = new self(); |
|
66 | - } |
|
67 | - return self::$_instance; |
|
68 | - } |
|
69 | - |
|
70 | - |
|
71 | - |
|
72 | - /** |
|
73 | - * Resets maintenance mode (mostly just re-checks whether or not we should be in maintenance mode) |
|
74 | - * |
|
75 | - * @return EE_Maintenance_Mode |
|
76 | - */ |
|
77 | - public static function reset() |
|
78 | - { |
|
79 | - self::instance()->set_maintenance_mode_if_db_old(); |
|
80 | - return self::instance(); |
|
81 | - } |
|
82 | - |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - *private constructor to prevent direct creation |
|
87 | - */ |
|
88 | - private function __construct() |
|
89 | - { |
|
90 | - // if M-Mode level 2 is engaged, we still need basic assets loaded |
|
91 | - add_action('wp_enqueue_scripts', array($this, 'load_assets_required_for_m_mode')); |
|
92 | - // shut 'er down down for maintenance ? |
|
93 | - add_filter('the_content', array($this, 'the_content'), 2); |
|
94 | - // add powered by EE msg |
|
95 | - add_action('shutdown', array($this, 'display_maintenance_mode_notice'), 10); |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * retrieves the maintenance mode option value from the db |
|
102 | - * |
|
103 | - * @return int |
|
104 | - */ |
|
105 | - public function real_level() |
|
106 | - { |
|
107 | - return get_option(self::option_name_maintenance_mode, EE_Maintenance_Mode::level_0_not_in_maintenance); |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * Returns whether or not the models reportedly are able to run queries or not |
|
114 | - * (ie, if the system thinks their tables are present and up-to-date). |
|
115 | - * |
|
116 | - * @return boolean |
|
117 | - */ |
|
118 | - public function models_can_query() |
|
119 | - { |
|
120 | - return $this->real_level() !== EE_Maintenance_Mode::level_2_complete_maintenance; |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * Determines whether or not we're in maintenance mode and what level. However, while the site |
|
127 | - * is in level 1 maintenance, and an admin visits the frontend, this function makes it appear |
|
128 | - * to them as if teh site isn't in maintenance mode. |
|
129 | - * EE_Maintenance_Mode::level_0_not_in_maintenance => not in maintenance mode (in normal mode) |
|
130 | - * EE_Maintenance_Mode::level_1_frontend_only_maintenance=> frontend-only maintenance mode |
|
131 | - * EE_Maintenance_Mode::level_2_complete_maintenance => frontend and backend maintenance mode |
|
132 | - * |
|
133 | - * @return int |
|
134 | - */ |
|
135 | - public function level() |
|
136 | - { |
|
137 | - $maintenance_mode_level = $this->real_level(); |
|
138 | - // if this is an admin request, we'll be honest... except if it's ajax, because that might be from the frontend |
|
139 | - if ( |
|
140 | - $maintenance_mode_level === EE_Maintenance_Mode::level_1_frontend_only_maintenance// we're in level 1 |
|
141 | - && ((defined('DOING_AJAX') && DOING_AJAX) || ! is_admin()) // on non-ajax frontend requests |
|
142 | - && current_user_can('administrator') // when the user is an admin |
|
143 | - ) { |
|
144 | - $maintenance_mode_level = EE_Maintenance_Mode::level_0_not_in_maintenance; |
|
145 | - } |
|
146 | - return $maintenance_mode_level; |
|
147 | - } |
|
148 | - |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * Determines if we need to put EE in maintenance mode because the database needs updating |
|
153 | - * |
|
154 | - * @return boolean true if DB is old and maintenance mode was triggered; false otherwise |
|
155 | - */ |
|
156 | - public function set_maintenance_mode_if_db_old() |
|
157 | - { |
|
158 | - EE_Registry::instance()->load_core('Data_Migration_Manager'); |
|
159 | - if (EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) { |
|
160 | - update_option(self::option_name_maintenance_mode, self::level_2_complete_maintenance); |
|
161 | - return true; |
|
162 | - } |
|
163 | - if ($this->level() === self::level_2_complete_maintenance) { |
|
164 | - //we also want to handle the opposite: if the site is mm2, but there aren't any migrations to run |
|
165 | - //then we shouldn't be in mm2. (Maybe an addon got deactivated?) |
|
166 | - update_option(self::option_name_maintenance_mode, self::level_0_not_in_maintenance); |
|
167 | - return false; |
|
168 | - } |
|
169 | - return false; |
|
170 | - } |
|
171 | - |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * Updates the maintenance level on the site |
|
176 | - * |
|
177 | - * @param int $level |
|
178 | - * @return void |
|
179 | - */ |
|
180 | - public function set_maintenance_level($level) |
|
181 | - { |
|
182 | - do_action('AHEE__EE_Maintenance_Mode__set_maintenance_level', $level); |
|
183 | - update_option(self::option_name_maintenance_mode, (int)$level); |
|
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - |
|
188 | - /** |
|
189 | - * returns TRUE if M-Mode is engaged and the current request is not for the admin |
|
190 | - * |
|
191 | - * @return string |
|
192 | - */ |
|
193 | - public static function disable_frontend_for_maintenance() |
|
194 | - { |
|
195 | - return (! is_admin() && EE_Maintenance_Mode::instance()->level()); |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - |
|
200 | - /** |
|
201 | - * @return void |
|
202 | - */ |
|
203 | - public function load_assets_required_for_m_mode() |
|
204 | - { |
|
205 | - if ( |
|
206 | - $this->real_level() === EE_Maintenance_Mode::level_2_complete_maintenance |
|
207 | - && ! wp_script_is('espresso_core') |
|
208 | - ) { |
|
209 | - wp_register_style( |
|
210 | - 'espresso_default', |
|
211 | - EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
212 | - array('dashicons'), |
|
213 | - EVENT_ESPRESSO_VERSION |
|
214 | - ); |
|
215 | - wp_enqueue_style('espresso_default'); |
|
216 | - wp_register_script( |
|
217 | - 'espresso_core', |
|
218 | - EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
219 | - array('jquery'), |
|
220 | - EVENT_ESPRESSO_VERSION, |
|
221 | - true |
|
222 | - ); |
|
223 | - wp_enqueue_script('espresso_core'); |
|
224 | - } |
|
225 | - } |
|
226 | - |
|
227 | - |
|
228 | - |
|
229 | - /** |
|
230 | - * replacement EE CPT template that displays message notifying site visitors |
|
231 | - * that EE has been temporarily placed into maintenance mode |
|
232 | - * does NOT get called on non-EE-CPT requests |
|
233 | - * |
|
234 | - * @return string |
|
235 | - */ |
|
236 | - public static function template_include() |
|
237 | - { |
|
238 | - // shut 'er down down for maintenance ? then don't use any of our templates for our endpoints |
|
239 | - return get_template_directory() . '/index.php'; |
|
240 | - } |
|
241 | - |
|
242 | - |
|
243 | - |
|
244 | - /** |
|
245 | - * displays message notifying site visitors that EE has been temporarily |
|
246 | - * placed into maintenance mode when post_type != EE CPT |
|
247 | - * |
|
248 | - * @param string $the_content |
|
249 | - * @return string |
|
250 | - */ |
|
251 | - public function the_content($the_content) |
|
252 | - { |
|
253 | - // check if M-mode is engaged and for EE shortcode |
|
254 | - if ($this->level() && strpos($the_content, '[ESPRESSO_') !== false) { |
|
255 | - // this can eventually be moved to a template, or edited via admin. But for now... |
|
256 | - $the_content = sprintf( |
|
257 | - esc_html__( |
|
258 | - '%sMaintenance Mode%sEvent Registration has been temporarily closed while system maintenance is being performed. We\'re sorry for any inconveniences this may have caused. Please try back again later.%s', |
|
259 | - 'event_espresso' |
|
260 | - ), |
|
261 | - '<h3>', |
|
262 | - '</h3><p>', |
|
263 | - '</p>' |
|
264 | - ); |
|
265 | - } |
|
266 | - return $the_content; |
|
267 | - } |
|
20 | + /** |
|
21 | + * constants available to client code for interpreting the values of EE_Maintenance_Mode::level(). |
|
22 | + * level_0_not_in_maintenance means the site is NOT in maintenance mode (so everything's normal) |
|
23 | + */ |
|
24 | + const level_0_not_in_maintenance = 0; |
|
25 | + |
|
26 | + /** |
|
27 | + * level_1_frontend_only_maintenance means that the site's frontend EE code should be completely disabled |
|
28 | + * but the admin backend should be running as normal. Maybe an admin can view the frontend though |
|
29 | + */ |
|
30 | + const level_1_frontend_only_maintenance = 1; |
|
31 | + |
|
32 | + /** |
|
33 | + * level_2_complete_maintenance means the frontend AND EE backend code are disabled. The only system running |
|
34 | + * is the maintenance mode stuff, which will require users to update all addons, and then finish running all |
|
35 | + * migration scripts before taking the site out of maintenance mode |
|
36 | + */ |
|
37 | + const level_2_complete_maintenance = 2; |
|
38 | + |
|
39 | + /** |
|
40 | + * the name of the option which stores the current level of maintenance mode |
|
41 | + */ |
|
42 | + const option_name_maintenance_mode = 'ee_maintenance_mode'; |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * @var EE_Maintenance_Mode $_instance |
|
47 | + */ |
|
48 | + private static $_instance; |
|
49 | + |
|
50 | + /** |
|
51 | + * @var EE_Registry $EE |
|
52 | + */ |
|
53 | + protected $EE; |
|
54 | + |
|
55 | + |
|
56 | + |
|
57 | + /** |
|
58 | + * @singleton method used to instantiate class object |
|
59 | + * @return EE_Maintenance_Mode |
|
60 | + */ |
|
61 | + public static function instance() |
|
62 | + { |
|
63 | + // check if class object is instantiated |
|
64 | + if (! self::$_instance instanceof EE_Maintenance_Mode) { |
|
65 | + self::$_instance = new self(); |
|
66 | + } |
|
67 | + return self::$_instance; |
|
68 | + } |
|
69 | + |
|
70 | + |
|
71 | + |
|
72 | + /** |
|
73 | + * Resets maintenance mode (mostly just re-checks whether or not we should be in maintenance mode) |
|
74 | + * |
|
75 | + * @return EE_Maintenance_Mode |
|
76 | + */ |
|
77 | + public static function reset() |
|
78 | + { |
|
79 | + self::instance()->set_maintenance_mode_if_db_old(); |
|
80 | + return self::instance(); |
|
81 | + } |
|
82 | + |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + *private constructor to prevent direct creation |
|
87 | + */ |
|
88 | + private function __construct() |
|
89 | + { |
|
90 | + // if M-Mode level 2 is engaged, we still need basic assets loaded |
|
91 | + add_action('wp_enqueue_scripts', array($this, 'load_assets_required_for_m_mode')); |
|
92 | + // shut 'er down down for maintenance ? |
|
93 | + add_filter('the_content', array($this, 'the_content'), 2); |
|
94 | + // add powered by EE msg |
|
95 | + add_action('shutdown', array($this, 'display_maintenance_mode_notice'), 10); |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * retrieves the maintenance mode option value from the db |
|
102 | + * |
|
103 | + * @return int |
|
104 | + */ |
|
105 | + public function real_level() |
|
106 | + { |
|
107 | + return get_option(self::option_name_maintenance_mode, EE_Maintenance_Mode::level_0_not_in_maintenance); |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * Returns whether or not the models reportedly are able to run queries or not |
|
114 | + * (ie, if the system thinks their tables are present and up-to-date). |
|
115 | + * |
|
116 | + * @return boolean |
|
117 | + */ |
|
118 | + public function models_can_query() |
|
119 | + { |
|
120 | + return $this->real_level() !== EE_Maintenance_Mode::level_2_complete_maintenance; |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * Determines whether or not we're in maintenance mode and what level. However, while the site |
|
127 | + * is in level 1 maintenance, and an admin visits the frontend, this function makes it appear |
|
128 | + * to them as if teh site isn't in maintenance mode. |
|
129 | + * EE_Maintenance_Mode::level_0_not_in_maintenance => not in maintenance mode (in normal mode) |
|
130 | + * EE_Maintenance_Mode::level_1_frontend_only_maintenance=> frontend-only maintenance mode |
|
131 | + * EE_Maintenance_Mode::level_2_complete_maintenance => frontend and backend maintenance mode |
|
132 | + * |
|
133 | + * @return int |
|
134 | + */ |
|
135 | + public function level() |
|
136 | + { |
|
137 | + $maintenance_mode_level = $this->real_level(); |
|
138 | + // if this is an admin request, we'll be honest... except if it's ajax, because that might be from the frontend |
|
139 | + if ( |
|
140 | + $maintenance_mode_level === EE_Maintenance_Mode::level_1_frontend_only_maintenance// we're in level 1 |
|
141 | + && ((defined('DOING_AJAX') && DOING_AJAX) || ! is_admin()) // on non-ajax frontend requests |
|
142 | + && current_user_can('administrator') // when the user is an admin |
|
143 | + ) { |
|
144 | + $maintenance_mode_level = EE_Maintenance_Mode::level_0_not_in_maintenance; |
|
145 | + } |
|
146 | + return $maintenance_mode_level; |
|
147 | + } |
|
148 | + |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * Determines if we need to put EE in maintenance mode because the database needs updating |
|
153 | + * |
|
154 | + * @return boolean true if DB is old and maintenance mode was triggered; false otherwise |
|
155 | + */ |
|
156 | + public function set_maintenance_mode_if_db_old() |
|
157 | + { |
|
158 | + EE_Registry::instance()->load_core('Data_Migration_Manager'); |
|
159 | + if (EE_Data_Migration_Manager::instance()->check_for_applicable_data_migration_scripts()) { |
|
160 | + update_option(self::option_name_maintenance_mode, self::level_2_complete_maintenance); |
|
161 | + return true; |
|
162 | + } |
|
163 | + if ($this->level() === self::level_2_complete_maintenance) { |
|
164 | + //we also want to handle the opposite: if the site is mm2, but there aren't any migrations to run |
|
165 | + //then we shouldn't be in mm2. (Maybe an addon got deactivated?) |
|
166 | + update_option(self::option_name_maintenance_mode, self::level_0_not_in_maintenance); |
|
167 | + return false; |
|
168 | + } |
|
169 | + return false; |
|
170 | + } |
|
171 | + |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * Updates the maintenance level on the site |
|
176 | + * |
|
177 | + * @param int $level |
|
178 | + * @return void |
|
179 | + */ |
|
180 | + public function set_maintenance_level($level) |
|
181 | + { |
|
182 | + do_action('AHEE__EE_Maintenance_Mode__set_maintenance_level', $level); |
|
183 | + update_option(self::option_name_maintenance_mode, (int)$level); |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + |
|
188 | + /** |
|
189 | + * returns TRUE if M-Mode is engaged and the current request is not for the admin |
|
190 | + * |
|
191 | + * @return string |
|
192 | + */ |
|
193 | + public static function disable_frontend_for_maintenance() |
|
194 | + { |
|
195 | + return (! is_admin() && EE_Maintenance_Mode::instance()->level()); |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + |
|
200 | + /** |
|
201 | + * @return void |
|
202 | + */ |
|
203 | + public function load_assets_required_for_m_mode() |
|
204 | + { |
|
205 | + if ( |
|
206 | + $this->real_level() === EE_Maintenance_Mode::level_2_complete_maintenance |
|
207 | + && ! wp_script_is('espresso_core') |
|
208 | + ) { |
|
209 | + wp_register_style( |
|
210 | + 'espresso_default', |
|
211 | + EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css', |
|
212 | + array('dashicons'), |
|
213 | + EVENT_ESPRESSO_VERSION |
|
214 | + ); |
|
215 | + wp_enqueue_style('espresso_default'); |
|
216 | + wp_register_script( |
|
217 | + 'espresso_core', |
|
218 | + EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js', |
|
219 | + array('jquery'), |
|
220 | + EVENT_ESPRESSO_VERSION, |
|
221 | + true |
|
222 | + ); |
|
223 | + wp_enqueue_script('espresso_core'); |
|
224 | + } |
|
225 | + } |
|
226 | + |
|
227 | + |
|
228 | + |
|
229 | + /** |
|
230 | + * replacement EE CPT template that displays message notifying site visitors |
|
231 | + * that EE has been temporarily placed into maintenance mode |
|
232 | + * does NOT get called on non-EE-CPT requests |
|
233 | + * |
|
234 | + * @return string |
|
235 | + */ |
|
236 | + public static function template_include() |
|
237 | + { |
|
238 | + // shut 'er down down for maintenance ? then don't use any of our templates for our endpoints |
|
239 | + return get_template_directory() . '/index.php'; |
|
240 | + } |
|
241 | + |
|
242 | + |
|
243 | + |
|
244 | + /** |
|
245 | + * displays message notifying site visitors that EE has been temporarily |
|
246 | + * placed into maintenance mode when post_type != EE CPT |
|
247 | + * |
|
248 | + * @param string $the_content |
|
249 | + * @return string |
|
250 | + */ |
|
251 | + public function the_content($the_content) |
|
252 | + { |
|
253 | + // check if M-mode is engaged and for EE shortcode |
|
254 | + if ($this->level() && strpos($the_content, '[ESPRESSO_') !== false) { |
|
255 | + // this can eventually be moved to a template, or edited via admin. But for now... |
|
256 | + $the_content = sprintf( |
|
257 | + esc_html__( |
|
258 | + '%sMaintenance Mode%sEvent Registration has been temporarily closed while system maintenance is being performed. We\'re sorry for any inconveniences this may have caused. Please try back again later.%s', |
|
259 | + 'event_espresso' |
|
260 | + ), |
|
261 | + '<h3>', |
|
262 | + '</h3><p>', |
|
263 | + '</p>' |
|
264 | + ); |
|
265 | + } |
|
266 | + return $the_content; |
|
267 | + } |
|
268 | 268 | |
269 | 269 | |
270 | 270 | |
271 | - /** |
|
272 | - * displays message on frontend of site notifying admin that EE has been temporarily placed into maintenance mode |
|
273 | - */ |
|
274 | - public function display_maintenance_mode_notice() |
|
275 | - { |
|
276 | - // check if M-mode is engaged and for EE shortcode |
|
277 | - if ( |
|
278 | - ! (defined('DOING_AJAX') && DOING_AJAX) |
|
279 | - && $this->real_level() |
|
280 | - && ! is_admin() |
|
281 | - && current_user_can('administrator') |
|
282 | - && EE_Registry::instance()->REQ->is_espresso_page() |
|
283 | - ) { |
|
284 | - printf( |
|
285 | - esc_html__( |
|
286 | - '%sclose%sEvent Registration is currently disabled because Event Espresso has been placed into Maintenance Mode. To change Maintenance Mode settings, click here %sEE Maintenance Mode Admin Page%s', |
|
287 | - 'event_espresso' |
|
288 | - ), |
|
289 | - '<div id="ee-m-mode-admin-notice-dv" class="ee-really-important-notice-dv"><a class="close-espresso-notice" title="', |
|
290 | - '"><span class="dashicons dashicons-no"></span></a><p>', |
|
291 | - ' » <a href="' . add_query_arg( |
|
292 | - array('page' => 'espresso_maintenance_settings'), admin_url('admin.php') |
|
293 | - ) . '">', |
|
294 | - '</a></p></div>' |
|
295 | - ); |
|
296 | - } |
|
297 | - } |
|
298 | - // espresso-notices important-notice ee-attention |
|
271 | + /** |
|
272 | + * displays message on frontend of site notifying admin that EE has been temporarily placed into maintenance mode |
|
273 | + */ |
|
274 | + public function display_maintenance_mode_notice() |
|
275 | + { |
|
276 | + // check if M-mode is engaged and for EE shortcode |
|
277 | + if ( |
|
278 | + ! (defined('DOING_AJAX') && DOING_AJAX) |
|
279 | + && $this->real_level() |
|
280 | + && ! is_admin() |
|
281 | + && current_user_can('administrator') |
|
282 | + && EE_Registry::instance()->REQ->is_espresso_page() |
|
283 | + ) { |
|
284 | + printf( |
|
285 | + esc_html__( |
|
286 | + '%sclose%sEvent Registration is currently disabled because Event Espresso has been placed into Maintenance Mode. To change Maintenance Mode settings, click here %sEE Maintenance Mode Admin Page%s', |
|
287 | + 'event_espresso' |
|
288 | + ), |
|
289 | + '<div id="ee-m-mode-admin-notice-dv" class="ee-really-important-notice-dv"><a class="close-espresso-notice" title="', |
|
290 | + '"><span class="dashicons dashicons-no"></span></a><p>', |
|
291 | + ' » <a href="' . add_query_arg( |
|
292 | + array('page' => 'espresso_maintenance_settings'), admin_url('admin.php') |
|
293 | + ) . '">', |
|
294 | + '</a></p></div>' |
|
295 | + ); |
|
296 | + } |
|
297 | + } |
|
298 | + // espresso-notices important-notice ee-attention |
|
299 | 299 | |
300 | 300 | |
301 | 301 | |
302 | - /** |
|
303 | - * override magic methods |
|
304 | - */ |
|
305 | - final public function __destruct() |
|
306 | - { |
|
307 | - } |
|
302 | + /** |
|
303 | + * override magic methods |
|
304 | + */ |
|
305 | + final public function __destruct() |
|
306 | + { |
|
307 | + } |
|
308 | 308 | |
309 | 309 | |
310 | 310 | |
311 | - final public function __call($a, $b) |
|
312 | - { |
|
313 | - } |
|
311 | + final public function __call($a, $b) |
|
312 | + { |
|
313 | + } |
|
314 | 314 | |
315 | 315 | |
316 | 316 | |
317 | - final public function __get($a) |
|
318 | - { |
|
319 | - } |
|
317 | + final public function __get($a) |
|
318 | + { |
|
319 | + } |
|
320 | 320 | |
321 | 321 | |
322 | 322 | |
323 | - final public function __set($a, $b) |
|
324 | - { |
|
325 | - } |
|
323 | + final public function __set($a, $b) |
|
324 | + { |
|
325 | + } |
|
326 | 326 | |
327 | 327 | |
328 | 328 | |
329 | - final public function __isset($a) |
|
330 | - { |
|
331 | - } |
|
329 | + final public function __isset($a) |
|
330 | + { |
|
331 | + } |
|
332 | 332 | |
333 | 333 | |
334 | 334 | |
335 | - final public function __unset($a) |
|
336 | - { |
|
337 | - } |
|
335 | + final public function __unset($a) |
|
336 | + { |
|
337 | + } |
|
338 | 338 | |
339 | 339 | |
340 | 340 | |
341 | - final public function __sleep() |
|
342 | - { |
|
343 | - return array(); |
|
344 | - } |
|
341 | + final public function __sleep() |
|
342 | + { |
|
343 | + return array(); |
|
344 | + } |
|
345 | 345 | |
346 | 346 | |
347 | 347 | |
348 | - final public function __wakeup() |
|
349 | - { |
|
350 | - } |
|
348 | + final public function __wakeup() |
|
349 | + { |
|
350 | + } |
|
351 | 351 | |
352 | 352 | |
353 | 353 | |
354 | - final public function __invoke() |
|
355 | - { |
|
356 | - } |
|
354 | + final public function __invoke() |
|
355 | + { |
|
356 | + } |
|
357 | 357 | |
358 | 358 | |
359 | 359 | |
360 | - final public static function __set_state($a = null) |
|
361 | - { |
|
362 | - return EE_Maintenance_Mode::instance(); |
|
363 | - } |
|
360 | + final public static function __set_state($a = null) |
|
361 | + { |
|
362 | + return EE_Maintenance_Mode::instance(); |
|
363 | + } |
|
364 | 364 | |
365 | 365 | |
366 | 366 | |
367 | - final public function __clone() |
|
368 | - { |
|
369 | - } |
|
367 | + final public function __clone() |
|
368 | + { |
|
369 | + } |
|
370 | 370 | |
371 | 371 | |
372 | 372 | |
373 | - final public static function __callStatic($a, $b) |
|
374 | - { |
|
375 | - } |
|
373 | + final public static function __callStatic($a, $b) |
|
374 | + { |
|
375 | + } |
|
376 | 376 | |
377 | 377 | } |
378 | 378 | // End of file EE_Maintenance_Mode.core.php |
@@ -351,7 +351,7 @@ |
||
351 | 351 | * retrieve a single attendee from db via their ID |
352 | 352 | * |
353 | 353 | * @param $ATT_ID |
354 | - * @return mixed array on success, FALSE on fail |
|
354 | + * @return EE_Base_Class|null array on success, FALSE on fail |
|
355 | 355 | * @deprecated |
356 | 356 | */ |
357 | 357 | public function get_attendee_by_ID($ATT_ID = false) |
@@ -17,413 +17,413 @@ |
||
17 | 17 | class EEM_Attendee extends EEM_CPT_Base |
18 | 18 | { |
19 | 19 | |
20 | - // private instance of the Attendee object |
|
21 | - protected static $_instance = null; |
|
20 | + // private instance of the Attendee object |
|
21 | + protected static $_instance = null; |
|
22 | 22 | |
23 | - /** |
|
24 | - * QST_system for questions are strings not integers now, |
|
25 | - * so these constants are deprecated. |
|
26 | - * Please instead use the EEM_Attendee::system_question_* constants |
|
27 | - * |
|
28 | - * @deprecated |
|
29 | - */ |
|
30 | - const fname_question_id = 1; |
|
23 | + /** |
|
24 | + * QST_system for questions are strings not integers now, |
|
25 | + * so these constants are deprecated. |
|
26 | + * Please instead use the EEM_Attendee::system_question_* constants |
|
27 | + * |
|
28 | + * @deprecated |
|
29 | + */ |
|
30 | + const fname_question_id = 1; |
|
31 | 31 | |
32 | - /** |
|
33 | - * @deprecated |
|
34 | - */ |
|
35 | - const lname_question_id = 2; |
|
32 | + /** |
|
33 | + * @deprecated |
|
34 | + */ |
|
35 | + const lname_question_id = 2; |
|
36 | 36 | |
37 | 37 | |
38 | - /** |
|
39 | - * @deprecated |
|
40 | - */ |
|
41 | - const email_question_id = 3; |
|
38 | + /** |
|
39 | + * @deprecated |
|
40 | + */ |
|
41 | + const email_question_id = 3; |
|
42 | 42 | |
43 | 43 | |
44 | - /** |
|
45 | - * @deprecated |
|
46 | - */ |
|
47 | - const address_question_id = 4; |
|
44 | + /** |
|
45 | + * @deprecated |
|
46 | + */ |
|
47 | + const address_question_id = 4; |
|
48 | 48 | |
49 | 49 | |
50 | - /** |
|
51 | - * @deprecated |
|
52 | - */ |
|
53 | - const address2_question_id = 5; |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * @deprecated |
|
58 | - */ |
|
59 | - const city_question_id = 6; |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * @deprecated |
|
64 | - */ |
|
65 | - const state_question_id = 7; |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * @deprecated |
|
70 | - */ |
|
71 | - const country_question_id = 8; |
|
72 | - |
|
73 | - |
|
74 | - /** |
|
75 | - * @deprecated |
|
76 | - */ |
|
77 | - const zip_question_id = 9; |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * @deprecated |
|
82 | - */ |
|
83 | - const phone_question_id = 10; |
|
84 | - |
|
85 | - /** |
|
86 | - * When looking for questions that correspond to attendee fields, |
|
87 | - * look for the question with this QST_system value. |
|
88 | - * These replace the old constants like EEM_Attendee::*_question_id |
|
89 | - */ |
|
90 | - const system_question_fname = 'fname'; |
|
91 | - |
|
92 | - const system_question_lname = 'lname'; |
|
93 | - |
|
94 | - const system_question_email = 'email'; |
|
95 | - |
|
96 | - const system_question_address = 'address'; |
|
97 | - |
|
98 | - const system_question_address2 = 'address2'; |
|
99 | - |
|
100 | - const system_question_city = 'city'; |
|
101 | - |
|
102 | - const system_question_state = 'state'; |
|
103 | - |
|
104 | - const system_question_country = 'country'; |
|
105 | - |
|
106 | - const system_question_zip = 'zip'; |
|
107 | - |
|
108 | - const system_question_phone = 'phone'; |
|
109 | - |
|
110 | - /** |
|
111 | - * Keys are all the EEM_Attendee::system_question_* constants, which are |
|
112 | - * also all the values of QST_system in the questions table, and values |
|
113 | - * are their corresponding Attendee field names |
|
114 | - * |
|
115 | - * @var array |
|
116 | - */ |
|
117 | - protected $_system_question_to_attendee_field_name = array( |
|
118 | - EEM_Attendee::system_question_fname => 'ATT_fname', |
|
119 | - EEM_Attendee::system_question_lname => 'ATT_lname', |
|
120 | - EEM_Attendee::system_question_email => 'ATT_email', |
|
121 | - EEM_Attendee::system_question_address => 'ATT_address', |
|
122 | - EEM_Attendee::system_question_address2 => 'ATT_address2', |
|
123 | - EEM_Attendee::system_question_city => 'ATT_city', |
|
124 | - EEM_Attendee::system_question_state => 'STA_ID', |
|
125 | - EEM_Attendee::system_question_country => 'CNT_ISO', |
|
126 | - EEM_Attendee::system_question_zip => 'ATT_zip', |
|
127 | - EEM_Attendee::system_question_phone => 'ATT_phone', |
|
128 | - ); |
|
129 | - |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * EEM_Attendee constructor. |
|
134 | - * |
|
135 | - * @param null $timezone |
|
136 | - * @param ModelFieldFactory $model_field_factory |
|
137 | - * @throws EE_Error |
|
138 | - * @throws InvalidArgumentException |
|
139 | - */ |
|
140 | - protected function __construct($timezone = null, ModelFieldFactory $model_field_factory) |
|
141 | - { |
|
142 | - $this->singular_item = esc_html__('Attendee', 'event_espresso'); |
|
143 | - $this->plural_item = esc_html__('Attendees', 'event_espresso'); |
|
144 | - $this->_tables = array( |
|
145 | - 'Attendee_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
146 | - 'Attendee_Meta' => new EE_Secondary_Table( |
|
147 | - 'esp_attendee_meta', |
|
148 | - 'ATTM_ID', |
|
149 | - 'ATT_ID' |
|
150 | - ), |
|
151 | - ); |
|
152 | - $this->_fields = array( |
|
153 | - 'Attendee_CPT' => array( |
|
154 | - 'ATT_ID' => $model_field_factory->createPrimaryKeyIntField( |
|
155 | - 'ID', |
|
156 | - esc_html__('Attendee ID', 'event_espresso') |
|
157 | - ), |
|
158 | - 'ATT_full_name' => $model_field_factory->createPlainTextField( |
|
159 | - 'post_title', |
|
160 | - esc_html__('Attendee Full Name', 'event_espresso'), |
|
161 | - false, |
|
162 | - esc_html__('Unknown', 'event_espresso') |
|
163 | - ), |
|
164 | - 'ATT_bio' => $model_field_factory->createPostContentField( |
|
165 | - 'post_content', |
|
166 | - esc_html__('Attendee Biography', 'event_espresso'), |
|
167 | - false, |
|
168 | - esc_html__('No Biography Provided', 'event_espresso') |
|
169 | - ), |
|
170 | - 'ATT_slug' => $model_field_factory->createSlugField( |
|
171 | - 'post_name', |
|
172 | - esc_html__('Attendee URL Slug', 'event_espresso') |
|
173 | - ), |
|
174 | - 'ATT_created' => $model_field_factory->createDatetimeField( |
|
175 | - 'post_date', |
|
176 | - esc_html__('Time Attendee Created', 'event_espresso') |
|
177 | - ), |
|
178 | - 'ATT_short_bio' => $model_field_factory->createSimpleHtmlField( |
|
179 | - 'post_excerpt', |
|
180 | - esc_html__('Attendee Short Biography', 'event_espresso'), |
|
181 | - true, |
|
182 | - esc_html__('No Biography Provided', 'event_espresso') |
|
183 | - ), |
|
184 | - 'ATT_modified' => $model_field_factory->createDatetimeField( |
|
185 | - 'post_modified', |
|
186 | - esc_html__('Time Attendee Last Modified', 'event_espresso') |
|
187 | - ), |
|
188 | - 'ATT_author' => $model_field_factory->createWpUserField( |
|
189 | - 'post_author', |
|
190 | - esc_html__('Creator ID of the first Event attended', 'event_espresso'), |
|
191 | - false |
|
192 | - ), |
|
193 | - 'ATT_parent' => $model_field_factory->createDbOnlyIntField( |
|
194 | - 'post_parent', |
|
195 | - esc_html__('Parent Attendee (unused)', 'event_espresso'), |
|
196 | - false, |
|
197 | - 0 |
|
198 | - ), |
|
199 | - 'post_type' => $model_field_factory->createWpPostTypeField('espresso_attendees'), |
|
200 | - 'status' => $model_field_factory->createWpPostStatusField( |
|
201 | - 'post_status', |
|
202 | - esc_html__('Attendee Status', 'event_espresso'), |
|
203 | - false, |
|
204 | - 'publish' |
|
205 | - ), |
|
206 | - ), |
|
207 | - 'Attendee_Meta' => array( |
|
208 | - 'ATTM_ID' => $model_field_factory->createDbOnlyIntField( |
|
209 | - 'ATTM_ID', |
|
210 | - esc_html__('Attendee Meta Row ID', 'event_espresso'), |
|
211 | - false |
|
212 | - ), |
|
213 | - 'ATT_ID_fk' => $model_field_factory->createDbOnlyIntField( |
|
214 | - 'ATT_ID', |
|
215 | - esc_html__('Foreign Key to Attendee in Post Table', 'event_espresso'), |
|
216 | - false |
|
217 | - ), |
|
218 | - 'ATT_fname' => $model_field_factory->createPlainTextField( |
|
219 | - 'ATT_fname', |
|
220 | - esc_html__('First Name', 'event_espresso') |
|
221 | - ), |
|
222 | - 'ATT_lname' => $model_field_factory->createPlainTextField( |
|
223 | - 'ATT_lname', |
|
224 | - esc_html__('Last Name', 'event_espresso') |
|
225 | - ), |
|
226 | - 'ATT_address' => $model_field_factory->createPlainTextField( |
|
227 | - 'ATT_address', |
|
228 | - esc_html__('Address Part 1', 'event_espresso') |
|
229 | - ), |
|
230 | - 'ATT_address2' => $model_field_factory->createPlainTextField( |
|
231 | - 'ATT_address2', |
|
232 | - esc_html__('Address Part 2', 'event_espresso') |
|
233 | - ), |
|
234 | - 'ATT_city' => $model_field_factory->createPlainTextField( |
|
235 | - 'ATT_city', |
|
236 | - esc_html__('City', 'event_espresso') |
|
237 | - ), |
|
238 | - 'STA_ID' => $model_field_factory->createForeignKeyIntField( |
|
239 | - 'STA_ID', |
|
240 | - esc_html__('State', 'event_espresso'), |
|
241 | - true, |
|
242 | - 0, |
|
243 | - 'State' |
|
244 | - ), |
|
245 | - 'CNT_ISO' => $model_field_factory->createForeignKeyStringField( |
|
246 | - 'CNT_ISO', |
|
247 | - esc_html__('Country', 'event_espresso'), |
|
248 | - true, |
|
249 | - '', |
|
250 | - 'Country' |
|
251 | - ), |
|
252 | - 'ATT_zip' => $model_field_factory->createPlainTextField( |
|
253 | - 'ATT_zip', |
|
254 | - esc_html__('ZIP/Postal Code', 'event_espresso') |
|
255 | - ), |
|
256 | - 'ATT_email' => $model_field_factory->createEmailField( |
|
257 | - 'ATT_email', |
|
258 | - esc_html__('Email Address', 'event_espresso') |
|
259 | - ), |
|
260 | - 'ATT_phone' => $model_field_factory->createPlainTextField( |
|
261 | - 'ATT_phone', |
|
262 | - esc_html__('Phone', 'event_espresso') |
|
263 | - ), |
|
264 | - ), |
|
265 | - ); |
|
266 | - $this->_model_relations = array( |
|
267 | - 'Registration' => new EE_Has_Many_Relation(), |
|
268 | - 'State' => new EE_Belongs_To_Relation(), |
|
269 | - 'Country' => new EE_Belongs_To_Relation(), |
|
270 | - 'Event' => new EE_HABTM_Relation('Registration', false), |
|
271 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
272 | - 'Message' => new EE_Has_Many_Any_Relation(false), |
|
273 | - //allow deletion of attendees even if they have messages in the queue for them. |
|
274 | - 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
275 | - 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
276 | - ); |
|
277 | - $this->_caps_slug = 'contacts'; |
|
278 | - parent::__construct($timezone); |
|
279 | - } |
|
280 | - |
|
281 | - |
|
282 | - |
|
283 | - /** |
|
284 | - * Gets the name of the field on the attendee model corresponding to the system question string |
|
285 | - * which should be one of the keys from EEM_Attendee::_system_question_to_attendee_field_name |
|
286 | - * |
|
287 | - * @param string $system_question_string |
|
288 | - * @return string|null if not found |
|
289 | - */ |
|
290 | - public function get_attendee_field_for_system_question($system_question_string) |
|
291 | - { |
|
292 | - return isset($this->_system_question_to_attendee_field_name[$system_question_string]) |
|
293 | - ? $this->_system_question_to_attendee_field_name[$system_question_string] |
|
294 | - : null; |
|
295 | - } |
|
296 | - |
|
297 | - |
|
298 | - |
|
299 | - /** |
|
300 | - * Gets mapping from esp_question.QST_system values to their corresponding attendee field names |
|
301 | - * |
|
302 | - * @return array |
|
303 | - */ |
|
304 | - public function system_question_to_attendee_field_mapping() |
|
305 | - { |
|
306 | - return $this->_system_question_to_attendee_field_name; |
|
307 | - } |
|
308 | - |
|
309 | - |
|
310 | - |
|
311 | - /** |
|
312 | - * Gets all the attendees for a transaction (by using the esp_registration as a join table) |
|
313 | - * |
|
314 | - * @param EE_Transaction /int $transaction_id_or_obj EE_Transaction or its ID |
|
315 | - * @return EE_Attendee[]|EE_Base_Class[] |
|
316 | - * @throws EE_Error |
|
317 | - */ |
|
318 | - public function get_attendees_for_transaction($transaction_id_or_obj) |
|
319 | - { |
|
320 | - return $this->get_all( |
|
321 | - array( |
|
322 | - array( |
|
323 | - 'Registration.Transaction.TXN_ID' => $transaction_id_or_obj instanceof EE_Transaction |
|
324 | - ? $transaction_id_or_obj->ID() |
|
325 | - : $transaction_id_or_obj, |
|
326 | - ), |
|
327 | - ) |
|
328 | - ); |
|
329 | - } |
|
330 | - |
|
331 | - |
|
332 | - |
|
333 | - /** |
|
334 | - * retrieve a single attendee from db via their ID |
|
335 | - * |
|
336 | - * @param $ATT_ID |
|
337 | - * @return mixed array on success, FALSE on fail |
|
338 | - * @deprecated |
|
339 | - */ |
|
340 | - public function get_attendee_by_ID($ATT_ID = false) |
|
341 | - { |
|
342 | - // retrieve a particular EE_Attendee |
|
343 | - return $this->get_one_by_ID($ATT_ID); |
|
344 | - } |
|
345 | - |
|
346 | - |
|
347 | - |
|
348 | - /** |
|
349 | - * retrieve a single attendee from db via their ID |
|
350 | - * |
|
351 | - * @param array $where_cols_n_values |
|
352 | - * @return mixed array on success, FALSE on fail |
|
353 | - * @throws EE_Error |
|
354 | - */ |
|
355 | - public function get_attendee($where_cols_n_values = array()) |
|
356 | - { |
|
357 | - if (empty($where_cols_n_values)) { |
|
358 | - return false; |
|
359 | - } |
|
360 | - $attendee = $this->get_all(array($where_cols_n_values)); |
|
361 | - if (! empty($attendee)) { |
|
362 | - return array_shift($attendee); |
|
363 | - } |
|
364 | - return false; |
|
365 | - } |
|
366 | - |
|
367 | - |
|
368 | - |
|
369 | - /** |
|
370 | - * Search for an existing Attendee record in the DB |
|
371 | - * |
|
372 | - * @param array $where_cols_n_values |
|
373 | - * @return bool|mixed |
|
374 | - * @throws EE_Error |
|
375 | - */ |
|
376 | - public function find_existing_attendee($where_cols_n_values = null) |
|
377 | - { |
|
378 | - // search by combo of first and last names plus the email address |
|
379 | - $attendee_data_keys = array( |
|
380 | - 'ATT_fname' => $this->_ATT_fname, |
|
381 | - 'ATT_lname' => $this->_ATT_lname, |
|
382 | - 'ATT_email' => $this->_ATT_email, |
|
383 | - ); |
|
384 | - // no search params means attendee object already exists. |
|
385 | - $where_cols_n_values = is_array($where_cols_n_values) && ! empty($where_cols_n_values) |
|
386 | - ? $where_cols_n_values |
|
387 | - : $attendee_data_keys; |
|
388 | - $valid_data = true; |
|
389 | - // check for required values |
|
390 | - $valid_data = isset($where_cols_n_values['ATT_fname']) && ! empty($where_cols_n_values['ATT_fname']) |
|
391 | - ? $valid_data |
|
392 | - : false; |
|
393 | - $valid_data = isset($where_cols_n_values['ATT_lname']) && ! empty($where_cols_n_values['ATT_lname']) |
|
394 | - ? $valid_data |
|
395 | - : false; |
|
396 | - $valid_data = isset($where_cols_n_values['ATT_email']) && ! empty($where_cols_n_values['ATT_email']) |
|
397 | - ? $valid_data |
|
398 | - : false; |
|
399 | - if ($valid_data) { |
|
400 | - $attendee = $this->get_attendee($where_cols_n_values); |
|
401 | - if ($attendee instanceof EE_Attendee) { |
|
402 | - return $attendee; |
|
403 | - } |
|
404 | - } |
|
405 | - return false; |
|
406 | - } |
|
407 | - |
|
408 | - |
|
409 | - |
|
410 | - /** |
|
411 | - * Takes an incoming array of EE_Registration ids |
|
412 | - * and sends back a list of corresponding non duplicate EE_Attendee objects. |
|
413 | - * |
|
414 | - * @since 4.3.0 |
|
415 | - * @param array $ids array of EE_Registration ids |
|
416 | - * @return EE_Attendee[]|EE_Base_Class[] |
|
417 | - * @throws EE_Error |
|
418 | - */ |
|
419 | - public function get_array_of_contacts_from_reg_ids($ids) |
|
420 | - { |
|
421 | - $ids = (array)$ids; |
|
422 | - $_where = array( |
|
423 | - 'Registration.REG_ID' => array('in', $ids), |
|
424 | - ); |
|
425 | - return $this->get_all(array($_where)); |
|
426 | - } |
|
50 | + /** |
|
51 | + * @deprecated |
|
52 | + */ |
|
53 | + const address2_question_id = 5; |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * @deprecated |
|
58 | + */ |
|
59 | + const city_question_id = 6; |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * @deprecated |
|
64 | + */ |
|
65 | + const state_question_id = 7; |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * @deprecated |
|
70 | + */ |
|
71 | + const country_question_id = 8; |
|
72 | + |
|
73 | + |
|
74 | + /** |
|
75 | + * @deprecated |
|
76 | + */ |
|
77 | + const zip_question_id = 9; |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * @deprecated |
|
82 | + */ |
|
83 | + const phone_question_id = 10; |
|
84 | + |
|
85 | + /** |
|
86 | + * When looking for questions that correspond to attendee fields, |
|
87 | + * look for the question with this QST_system value. |
|
88 | + * These replace the old constants like EEM_Attendee::*_question_id |
|
89 | + */ |
|
90 | + const system_question_fname = 'fname'; |
|
91 | + |
|
92 | + const system_question_lname = 'lname'; |
|
93 | + |
|
94 | + const system_question_email = 'email'; |
|
95 | + |
|
96 | + const system_question_address = 'address'; |
|
97 | + |
|
98 | + const system_question_address2 = 'address2'; |
|
99 | + |
|
100 | + const system_question_city = 'city'; |
|
101 | + |
|
102 | + const system_question_state = 'state'; |
|
103 | + |
|
104 | + const system_question_country = 'country'; |
|
105 | + |
|
106 | + const system_question_zip = 'zip'; |
|
107 | + |
|
108 | + const system_question_phone = 'phone'; |
|
109 | + |
|
110 | + /** |
|
111 | + * Keys are all the EEM_Attendee::system_question_* constants, which are |
|
112 | + * also all the values of QST_system in the questions table, and values |
|
113 | + * are their corresponding Attendee field names |
|
114 | + * |
|
115 | + * @var array |
|
116 | + */ |
|
117 | + protected $_system_question_to_attendee_field_name = array( |
|
118 | + EEM_Attendee::system_question_fname => 'ATT_fname', |
|
119 | + EEM_Attendee::system_question_lname => 'ATT_lname', |
|
120 | + EEM_Attendee::system_question_email => 'ATT_email', |
|
121 | + EEM_Attendee::system_question_address => 'ATT_address', |
|
122 | + EEM_Attendee::system_question_address2 => 'ATT_address2', |
|
123 | + EEM_Attendee::system_question_city => 'ATT_city', |
|
124 | + EEM_Attendee::system_question_state => 'STA_ID', |
|
125 | + EEM_Attendee::system_question_country => 'CNT_ISO', |
|
126 | + EEM_Attendee::system_question_zip => 'ATT_zip', |
|
127 | + EEM_Attendee::system_question_phone => 'ATT_phone', |
|
128 | + ); |
|
129 | + |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * EEM_Attendee constructor. |
|
134 | + * |
|
135 | + * @param null $timezone |
|
136 | + * @param ModelFieldFactory $model_field_factory |
|
137 | + * @throws EE_Error |
|
138 | + * @throws InvalidArgumentException |
|
139 | + */ |
|
140 | + protected function __construct($timezone = null, ModelFieldFactory $model_field_factory) |
|
141 | + { |
|
142 | + $this->singular_item = esc_html__('Attendee', 'event_espresso'); |
|
143 | + $this->plural_item = esc_html__('Attendees', 'event_espresso'); |
|
144 | + $this->_tables = array( |
|
145 | + 'Attendee_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
146 | + 'Attendee_Meta' => new EE_Secondary_Table( |
|
147 | + 'esp_attendee_meta', |
|
148 | + 'ATTM_ID', |
|
149 | + 'ATT_ID' |
|
150 | + ), |
|
151 | + ); |
|
152 | + $this->_fields = array( |
|
153 | + 'Attendee_CPT' => array( |
|
154 | + 'ATT_ID' => $model_field_factory->createPrimaryKeyIntField( |
|
155 | + 'ID', |
|
156 | + esc_html__('Attendee ID', 'event_espresso') |
|
157 | + ), |
|
158 | + 'ATT_full_name' => $model_field_factory->createPlainTextField( |
|
159 | + 'post_title', |
|
160 | + esc_html__('Attendee Full Name', 'event_espresso'), |
|
161 | + false, |
|
162 | + esc_html__('Unknown', 'event_espresso') |
|
163 | + ), |
|
164 | + 'ATT_bio' => $model_field_factory->createPostContentField( |
|
165 | + 'post_content', |
|
166 | + esc_html__('Attendee Biography', 'event_espresso'), |
|
167 | + false, |
|
168 | + esc_html__('No Biography Provided', 'event_espresso') |
|
169 | + ), |
|
170 | + 'ATT_slug' => $model_field_factory->createSlugField( |
|
171 | + 'post_name', |
|
172 | + esc_html__('Attendee URL Slug', 'event_espresso') |
|
173 | + ), |
|
174 | + 'ATT_created' => $model_field_factory->createDatetimeField( |
|
175 | + 'post_date', |
|
176 | + esc_html__('Time Attendee Created', 'event_espresso') |
|
177 | + ), |
|
178 | + 'ATT_short_bio' => $model_field_factory->createSimpleHtmlField( |
|
179 | + 'post_excerpt', |
|
180 | + esc_html__('Attendee Short Biography', 'event_espresso'), |
|
181 | + true, |
|
182 | + esc_html__('No Biography Provided', 'event_espresso') |
|
183 | + ), |
|
184 | + 'ATT_modified' => $model_field_factory->createDatetimeField( |
|
185 | + 'post_modified', |
|
186 | + esc_html__('Time Attendee Last Modified', 'event_espresso') |
|
187 | + ), |
|
188 | + 'ATT_author' => $model_field_factory->createWpUserField( |
|
189 | + 'post_author', |
|
190 | + esc_html__('Creator ID of the first Event attended', 'event_espresso'), |
|
191 | + false |
|
192 | + ), |
|
193 | + 'ATT_parent' => $model_field_factory->createDbOnlyIntField( |
|
194 | + 'post_parent', |
|
195 | + esc_html__('Parent Attendee (unused)', 'event_espresso'), |
|
196 | + false, |
|
197 | + 0 |
|
198 | + ), |
|
199 | + 'post_type' => $model_field_factory->createWpPostTypeField('espresso_attendees'), |
|
200 | + 'status' => $model_field_factory->createWpPostStatusField( |
|
201 | + 'post_status', |
|
202 | + esc_html__('Attendee Status', 'event_espresso'), |
|
203 | + false, |
|
204 | + 'publish' |
|
205 | + ), |
|
206 | + ), |
|
207 | + 'Attendee_Meta' => array( |
|
208 | + 'ATTM_ID' => $model_field_factory->createDbOnlyIntField( |
|
209 | + 'ATTM_ID', |
|
210 | + esc_html__('Attendee Meta Row ID', 'event_espresso'), |
|
211 | + false |
|
212 | + ), |
|
213 | + 'ATT_ID_fk' => $model_field_factory->createDbOnlyIntField( |
|
214 | + 'ATT_ID', |
|
215 | + esc_html__('Foreign Key to Attendee in Post Table', 'event_espresso'), |
|
216 | + false |
|
217 | + ), |
|
218 | + 'ATT_fname' => $model_field_factory->createPlainTextField( |
|
219 | + 'ATT_fname', |
|
220 | + esc_html__('First Name', 'event_espresso') |
|
221 | + ), |
|
222 | + 'ATT_lname' => $model_field_factory->createPlainTextField( |
|
223 | + 'ATT_lname', |
|
224 | + esc_html__('Last Name', 'event_espresso') |
|
225 | + ), |
|
226 | + 'ATT_address' => $model_field_factory->createPlainTextField( |
|
227 | + 'ATT_address', |
|
228 | + esc_html__('Address Part 1', 'event_espresso') |
|
229 | + ), |
|
230 | + 'ATT_address2' => $model_field_factory->createPlainTextField( |
|
231 | + 'ATT_address2', |
|
232 | + esc_html__('Address Part 2', 'event_espresso') |
|
233 | + ), |
|
234 | + 'ATT_city' => $model_field_factory->createPlainTextField( |
|
235 | + 'ATT_city', |
|
236 | + esc_html__('City', 'event_espresso') |
|
237 | + ), |
|
238 | + 'STA_ID' => $model_field_factory->createForeignKeyIntField( |
|
239 | + 'STA_ID', |
|
240 | + esc_html__('State', 'event_espresso'), |
|
241 | + true, |
|
242 | + 0, |
|
243 | + 'State' |
|
244 | + ), |
|
245 | + 'CNT_ISO' => $model_field_factory->createForeignKeyStringField( |
|
246 | + 'CNT_ISO', |
|
247 | + esc_html__('Country', 'event_espresso'), |
|
248 | + true, |
|
249 | + '', |
|
250 | + 'Country' |
|
251 | + ), |
|
252 | + 'ATT_zip' => $model_field_factory->createPlainTextField( |
|
253 | + 'ATT_zip', |
|
254 | + esc_html__('ZIP/Postal Code', 'event_espresso') |
|
255 | + ), |
|
256 | + 'ATT_email' => $model_field_factory->createEmailField( |
|
257 | + 'ATT_email', |
|
258 | + esc_html__('Email Address', 'event_espresso') |
|
259 | + ), |
|
260 | + 'ATT_phone' => $model_field_factory->createPlainTextField( |
|
261 | + 'ATT_phone', |
|
262 | + esc_html__('Phone', 'event_espresso') |
|
263 | + ), |
|
264 | + ), |
|
265 | + ); |
|
266 | + $this->_model_relations = array( |
|
267 | + 'Registration' => new EE_Has_Many_Relation(), |
|
268 | + 'State' => new EE_Belongs_To_Relation(), |
|
269 | + 'Country' => new EE_Belongs_To_Relation(), |
|
270 | + 'Event' => new EE_HABTM_Relation('Registration', false), |
|
271 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
272 | + 'Message' => new EE_Has_Many_Any_Relation(false), |
|
273 | + //allow deletion of attendees even if they have messages in the queue for them. |
|
274 | + 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
275 | + 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
276 | + ); |
|
277 | + $this->_caps_slug = 'contacts'; |
|
278 | + parent::__construct($timezone); |
|
279 | + } |
|
280 | + |
|
281 | + |
|
282 | + |
|
283 | + /** |
|
284 | + * Gets the name of the field on the attendee model corresponding to the system question string |
|
285 | + * which should be one of the keys from EEM_Attendee::_system_question_to_attendee_field_name |
|
286 | + * |
|
287 | + * @param string $system_question_string |
|
288 | + * @return string|null if not found |
|
289 | + */ |
|
290 | + public function get_attendee_field_for_system_question($system_question_string) |
|
291 | + { |
|
292 | + return isset($this->_system_question_to_attendee_field_name[$system_question_string]) |
|
293 | + ? $this->_system_question_to_attendee_field_name[$system_question_string] |
|
294 | + : null; |
|
295 | + } |
|
296 | + |
|
297 | + |
|
298 | + |
|
299 | + /** |
|
300 | + * Gets mapping from esp_question.QST_system values to their corresponding attendee field names |
|
301 | + * |
|
302 | + * @return array |
|
303 | + */ |
|
304 | + public function system_question_to_attendee_field_mapping() |
|
305 | + { |
|
306 | + return $this->_system_question_to_attendee_field_name; |
|
307 | + } |
|
308 | + |
|
309 | + |
|
310 | + |
|
311 | + /** |
|
312 | + * Gets all the attendees for a transaction (by using the esp_registration as a join table) |
|
313 | + * |
|
314 | + * @param EE_Transaction /int $transaction_id_or_obj EE_Transaction or its ID |
|
315 | + * @return EE_Attendee[]|EE_Base_Class[] |
|
316 | + * @throws EE_Error |
|
317 | + */ |
|
318 | + public function get_attendees_for_transaction($transaction_id_or_obj) |
|
319 | + { |
|
320 | + return $this->get_all( |
|
321 | + array( |
|
322 | + array( |
|
323 | + 'Registration.Transaction.TXN_ID' => $transaction_id_or_obj instanceof EE_Transaction |
|
324 | + ? $transaction_id_or_obj->ID() |
|
325 | + : $transaction_id_or_obj, |
|
326 | + ), |
|
327 | + ) |
|
328 | + ); |
|
329 | + } |
|
330 | + |
|
331 | + |
|
332 | + |
|
333 | + /** |
|
334 | + * retrieve a single attendee from db via their ID |
|
335 | + * |
|
336 | + * @param $ATT_ID |
|
337 | + * @return mixed array on success, FALSE on fail |
|
338 | + * @deprecated |
|
339 | + */ |
|
340 | + public function get_attendee_by_ID($ATT_ID = false) |
|
341 | + { |
|
342 | + // retrieve a particular EE_Attendee |
|
343 | + return $this->get_one_by_ID($ATT_ID); |
|
344 | + } |
|
345 | + |
|
346 | + |
|
347 | + |
|
348 | + /** |
|
349 | + * retrieve a single attendee from db via their ID |
|
350 | + * |
|
351 | + * @param array $where_cols_n_values |
|
352 | + * @return mixed array on success, FALSE on fail |
|
353 | + * @throws EE_Error |
|
354 | + */ |
|
355 | + public function get_attendee($where_cols_n_values = array()) |
|
356 | + { |
|
357 | + if (empty($where_cols_n_values)) { |
|
358 | + return false; |
|
359 | + } |
|
360 | + $attendee = $this->get_all(array($where_cols_n_values)); |
|
361 | + if (! empty($attendee)) { |
|
362 | + return array_shift($attendee); |
|
363 | + } |
|
364 | + return false; |
|
365 | + } |
|
366 | + |
|
367 | + |
|
368 | + |
|
369 | + /** |
|
370 | + * Search for an existing Attendee record in the DB |
|
371 | + * |
|
372 | + * @param array $where_cols_n_values |
|
373 | + * @return bool|mixed |
|
374 | + * @throws EE_Error |
|
375 | + */ |
|
376 | + public function find_existing_attendee($where_cols_n_values = null) |
|
377 | + { |
|
378 | + // search by combo of first and last names plus the email address |
|
379 | + $attendee_data_keys = array( |
|
380 | + 'ATT_fname' => $this->_ATT_fname, |
|
381 | + 'ATT_lname' => $this->_ATT_lname, |
|
382 | + 'ATT_email' => $this->_ATT_email, |
|
383 | + ); |
|
384 | + // no search params means attendee object already exists. |
|
385 | + $where_cols_n_values = is_array($where_cols_n_values) && ! empty($where_cols_n_values) |
|
386 | + ? $where_cols_n_values |
|
387 | + : $attendee_data_keys; |
|
388 | + $valid_data = true; |
|
389 | + // check for required values |
|
390 | + $valid_data = isset($where_cols_n_values['ATT_fname']) && ! empty($where_cols_n_values['ATT_fname']) |
|
391 | + ? $valid_data |
|
392 | + : false; |
|
393 | + $valid_data = isset($where_cols_n_values['ATT_lname']) && ! empty($where_cols_n_values['ATT_lname']) |
|
394 | + ? $valid_data |
|
395 | + : false; |
|
396 | + $valid_data = isset($where_cols_n_values['ATT_email']) && ! empty($where_cols_n_values['ATT_email']) |
|
397 | + ? $valid_data |
|
398 | + : false; |
|
399 | + if ($valid_data) { |
|
400 | + $attendee = $this->get_attendee($where_cols_n_values); |
|
401 | + if ($attendee instanceof EE_Attendee) { |
|
402 | + return $attendee; |
|
403 | + } |
|
404 | + } |
|
405 | + return false; |
|
406 | + } |
|
407 | + |
|
408 | + |
|
409 | + |
|
410 | + /** |
|
411 | + * Takes an incoming array of EE_Registration ids |
|
412 | + * and sends back a list of corresponding non duplicate EE_Attendee objects. |
|
413 | + * |
|
414 | + * @since 4.3.0 |
|
415 | + * @param array $ids array of EE_Registration ids |
|
416 | + * @return EE_Attendee[]|EE_Base_Class[] |
|
417 | + * @throws EE_Error |
|
418 | + */ |
|
419 | + public function get_array_of_contacts_from_reg_ids($ids) |
|
420 | + { |
|
421 | + $ids = (array)$ids; |
|
422 | + $_where = array( |
|
423 | + 'Registration.REG_ID' => array('in', $ids), |
|
424 | + ); |
|
425 | + return $this->get_all(array($_where)); |
|
426 | + } |
|
427 | 427 | |
428 | 428 | |
429 | 429 | } |
@@ -1,5 +1,4 @@ |
||
1 | 1 | <?php |
2 | -use EventEspresso\core\services\loaders\Loader; |
|
3 | 2 | use EventEspresso\core\services\orm\ModelFieldFactory; |
4 | 3 | |
5 | 4 | defined('EVENT_ESPRESSO_VERSION') || exit('No direct script access allowed'); |
@@ -358,7 +358,7 @@ discard block |
||
358 | 358 | return false; |
359 | 359 | } |
360 | 360 | $attendee = $this->get_all(array($where_cols_n_values)); |
361 | - if (! empty($attendee)) { |
|
361 | + if ( ! empty($attendee)) { |
|
362 | 362 | return array_shift($attendee); |
363 | 363 | } |
364 | 364 | return false; |
@@ -418,7 +418,7 @@ discard block |
||
418 | 418 | */ |
419 | 419 | public function get_array_of_contacts_from_reg_ids($ids) |
420 | 420 | { |
421 | - $ids = (array)$ids; |
|
421 | + $ids = (array) $ids; |
|
422 | 422 | $_where = array( |
423 | 423 | 'Registration.REG_ID' => array('in', $ids), |
424 | 424 | ); |
@@ -61,15 +61,15 @@ discard block |
||
61 | 61 | |
62 | 62 | |
63 | 63 | |
64 | - /** |
|
65 | - * @param array $props_n_values incoming values |
|
66 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
67 | - * used.) |
|
68 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
69 | - * date_format and the second value is the time format |
|
70 | - * @return EE_Ticket |
|
71 | - * @throws \EE_Error |
|
72 | - */ |
|
64 | + /** |
|
65 | + * @param array $props_n_values incoming values |
|
66 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
67 | + * used.) |
|
68 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
69 | + * date_format and the second value is the time format |
|
70 | + * @return EE_Ticket |
|
71 | + * @throws \EE_Error |
|
72 | + */ |
|
73 | 73 | public static function new_instance( $props_n_values = array(), $timezone = null, $date_formats = array() ) { |
74 | 74 | $has_object = parent::_check_for_object( $props_n_values, __CLASS__, $timezone, $date_formats ); |
75 | 75 | return $has_object ? $has_object : new self( $props_n_values, false, $timezone, $date_formats ); |
@@ -77,36 +77,36 @@ discard block |
||
77 | 77 | |
78 | 78 | |
79 | 79 | |
80 | - /** |
|
81 | - * @param array $props_n_values incoming values from the database |
|
82 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
83 | - * the website will be used. |
|
84 | - * @return EE_Ticket |
|
85 | - * @throws \EE_Error |
|
86 | - */ |
|
80 | + /** |
|
81 | + * @param array $props_n_values incoming values from the database |
|
82 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
83 | + * the website will be used. |
|
84 | + * @return EE_Ticket |
|
85 | + * @throws \EE_Error |
|
86 | + */ |
|
87 | 87 | public static function new_instance_from_db( $props_n_values = array(), $timezone = null ) { |
88 | 88 | return new self( $props_n_values, TRUE, $timezone ); |
89 | 89 | } |
90 | 90 | |
91 | 91 | |
92 | 92 | |
93 | - /** |
|
94 | - * @return bool |
|
95 | - * @throws \EE_Error |
|
96 | - */ |
|
93 | + /** |
|
94 | + * @return bool |
|
95 | + * @throws \EE_Error |
|
96 | + */ |
|
97 | 97 | public function parent() { |
98 | 98 | return $this->get( 'TKT_parent' ); |
99 | 99 | } |
100 | 100 | |
101 | 101 | |
102 | 102 | |
103 | - /** |
|
104 | - * return if a ticket has quantities available for purchase |
|
105 | - * |
|
106 | - * @param int $DTT_ID the primary key for a particular datetime |
|
107 | - * @return boolean |
|
108 | - * @throws \EE_Error |
|
109 | - */ |
|
103 | + /** |
|
104 | + * return if a ticket has quantities available for purchase |
|
105 | + * |
|
106 | + * @param int $DTT_ID the primary key for a particular datetime |
|
107 | + * @return boolean |
|
108 | + * @throws \EE_Error |
|
109 | + */ |
|
110 | 110 | public function available( $DTT_ID = 0 ) { |
111 | 111 | // are we checking availability for a particular datetime ? |
112 | 112 | if ( $DTT_ID ) { |
@@ -123,14 +123,14 @@ discard block |
||
123 | 123 | |
124 | 124 | |
125 | 125 | |
126 | - /** |
|
127 | - * Using the start date and end date this method calculates whether the ticket is On Sale, Pending, or Expired |
|
128 | - * |
|
129 | - * @param bool $display true = we'll return a localized string, otherwise we just return the value of the relevant status const |
|
130 | - * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save further processing |
|
131 | - * @return mixed status int if the display string isn't requested |
|
132 | - * @throws \EE_Error |
|
133 | - */ |
|
126 | + /** |
|
127 | + * Using the start date and end date this method calculates whether the ticket is On Sale, Pending, or Expired |
|
128 | + * |
|
129 | + * @param bool $display true = we'll return a localized string, otherwise we just return the value of the relevant status const |
|
130 | + * @param bool | null $remaining if it is already known that tickets are available, then simply pass a bool to save further processing |
|
131 | + * @return mixed status int if the display string isn't requested |
|
132 | + * @throws \EE_Error |
|
133 | + */ |
|
134 | 134 | public function ticket_status( $display = FALSE, $remaining = null ) { |
135 | 135 | $remaining = is_bool( $remaining ) ? $remaining : $this->is_remaining(); |
136 | 136 | if ( ! $remaining ) { |
@@ -153,14 +153,14 @@ discard block |
||
153 | 153 | |
154 | 154 | |
155 | 155 | |
156 | - /** |
|
157 | - * The purpose of this method is to simply return a boolean for whether there are any tickets remaining for sale considering ALL the factors used for figuring that out. |
|
158 | - * |
|
159 | - * @access public |
|
160 | - * @param int $DTT_ID if an int above 0 is included here then we get a specific dtt. |
|
161 | - * @return boolean true = tickets remaining, false not. |
|
162 | - * @throws \EE_Error |
|
163 | - */ |
|
156 | + /** |
|
157 | + * The purpose of this method is to simply return a boolean for whether there are any tickets remaining for sale considering ALL the factors used for figuring that out. |
|
158 | + * |
|
159 | + * @access public |
|
160 | + * @param int $DTT_ID if an int above 0 is included here then we get a specific dtt. |
|
161 | + * @return boolean true = tickets remaining, false not. |
|
162 | + * @throws \EE_Error |
|
163 | + */ |
|
164 | 164 | public function is_remaining( $DTT_ID = 0 ) { |
165 | 165 | $num_remaining = $this->remaining( $DTT_ID ); |
166 | 166 | if ( $num_remaining === 0 ) { |
@@ -174,76 +174,76 @@ discard block |
||
174 | 174 | |
175 | 175 | |
176 | 176 | |
177 | - /** |
|
178 | - * return the total number of tickets available for purchase |
|
179 | - * |
|
180 | - * @param int $DTT_ID the primary key for a particular datetime. |
|
181 | - * set to 0 for all related datetimes |
|
182 | - * @return int |
|
183 | - * @throws \EE_Error |
|
184 | - */ |
|
177 | + /** |
|
178 | + * return the total number of tickets available for purchase |
|
179 | + * |
|
180 | + * @param int $DTT_ID the primary key for a particular datetime. |
|
181 | + * set to 0 for all related datetimes |
|
182 | + * @return int |
|
183 | + * @throws \EE_Error |
|
184 | + */ |
|
185 | 185 | public function remaining( $DTT_ID = 0 ) { |
186 | 186 | return $this->real_quantity_on_ticket('saleable', $DTT_ID ); |
187 | 187 | } |
188 | 188 | |
189 | 189 | |
190 | 190 | |
191 | - /** |
|
192 | - * Gets min |
|
193 | - * |
|
194 | - * @return int |
|
195 | - * @throws \EE_Error |
|
196 | - */ |
|
191 | + /** |
|
192 | + * Gets min |
|
193 | + * |
|
194 | + * @return int |
|
195 | + * @throws \EE_Error |
|
196 | + */ |
|
197 | 197 | public function min() { |
198 | 198 | return $this->get( 'TKT_min' ); |
199 | 199 | } |
200 | 200 | |
201 | 201 | |
202 | 202 | |
203 | - /** |
|
204 | - * return if a ticket is no longer available cause its available dates have expired. |
|
205 | - * |
|
206 | - * @return boolean |
|
207 | - * @throws \EE_Error |
|
208 | - */ |
|
203 | + /** |
|
204 | + * return if a ticket is no longer available cause its available dates have expired. |
|
205 | + * |
|
206 | + * @return boolean |
|
207 | + * @throws \EE_Error |
|
208 | + */ |
|
209 | 209 | public function is_expired() { |
210 | 210 | return ( $this->get_raw( 'TKT_end_date' ) < time() ); |
211 | 211 | } |
212 | 212 | |
213 | 213 | |
214 | 214 | |
215 | - /** |
|
216 | - * Return if a ticket is yet to go on sale or not |
|
217 | - * |
|
218 | - * @return boolean |
|
219 | - * @throws \EE_Error |
|
220 | - */ |
|
215 | + /** |
|
216 | + * Return if a ticket is yet to go on sale or not |
|
217 | + * |
|
218 | + * @return boolean |
|
219 | + * @throws \EE_Error |
|
220 | + */ |
|
221 | 221 | public function is_pending() { |
222 | 222 | return ( $this->get_raw( 'TKT_start_date' ) > time() ); |
223 | 223 | } |
224 | 224 | |
225 | 225 | |
226 | 226 | |
227 | - /** |
|
228 | - * Return if a ticket is on sale or not |
|
229 | - * |
|
230 | - * @return boolean |
|
231 | - * @throws \EE_Error |
|
232 | - */ |
|
227 | + /** |
|
228 | + * Return if a ticket is on sale or not |
|
229 | + * |
|
230 | + * @return boolean |
|
231 | + * @throws \EE_Error |
|
232 | + */ |
|
233 | 233 | public function is_on_sale() { |
234 | 234 | return ( $this->get_raw( 'TKT_start_date' ) < time() && $this->get_raw( 'TKT_end_date' ) > time() ); |
235 | 235 | } |
236 | 236 | |
237 | 237 | |
238 | 238 | |
239 | - /** |
|
240 | - * This returns the chronologically last datetime that this ticket is associated with |
|
241 | - * |
|
242 | - * @param string $dt_frmt |
|
243 | - * @param string $conjunction - conjunction junction what's your function ? this string joins the start date with the end date ie: Jan 01 "to" Dec 31 |
|
244 | - * @return string |
|
245 | - * @throws \EE_Error |
|
246 | - */ |
|
239 | + /** |
|
240 | + * This returns the chronologically last datetime that this ticket is associated with |
|
241 | + * |
|
242 | + * @param string $dt_frmt |
|
243 | + * @param string $conjunction - conjunction junction what's your function ? this string joins the start date with the end date ie: Jan 01 "to" Dec 31 |
|
244 | + * @return string |
|
245 | + * @throws \EE_Error |
|
246 | + */ |
|
247 | 247 | public function date_range( $dt_frmt = '', $conjunction = ' - ' ) { |
248 | 248 | $first_date = $this->first_datetime() instanceof EE_Datetime ? $this->first_datetime()->start_date( $dt_frmt ) : ''; |
249 | 249 | $last_date = $this->last_datetime() instanceof EE_Datetime ? $this->last_datetime()->end_date( $dt_frmt ) : ''; |
@@ -253,12 +253,12 @@ discard block |
||
253 | 253 | |
254 | 254 | |
255 | 255 | |
256 | - /** |
|
257 | - * This returns the chronologically first datetime that this ticket is associated with |
|
258 | - * |
|
259 | - * @return EE_Datetime |
|
260 | - * @throws \EE_Error |
|
261 | - */ |
|
256 | + /** |
|
257 | + * This returns the chronologically first datetime that this ticket is associated with |
|
258 | + * |
|
259 | + * @return EE_Datetime |
|
260 | + * @throws \EE_Error |
|
261 | + */ |
|
262 | 262 | public function first_datetime() { |
263 | 263 | $datetimes = $this->datetimes( array( 'limit' => 1 ) ); |
264 | 264 | return reset( $datetimes ); |
@@ -266,14 +266,14 @@ discard block |
||
266 | 266 | |
267 | 267 | |
268 | 268 | |
269 | - /** |
|
270 | - * Gets all the datetimes this ticket can be used for attending. |
|
271 | - * Unless otherwise specified, orders datetimes by start date. |
|
272 | - * |
|
273 | - * @param array $query_params see EEM_Base::get_all() |
|
274 | - * @return EE_Datetime[]|EE_Base_Class[] |
|
275 | - * @throws \EE_Error |
|
276 | - */ |
|
269 | + /** |
|
270 | + * Gets all the datetimes this ticket can be used for attending. |
|
271 | + * Unless otherwise specified, orders datetimes by start date. |
|
272 | + * |
|
273 | + * @param array $query_params see EEM_Base::get_all() |
|
274 | + * @return EE_Datetime[]|EE_Base_Class[] |
|
275 | + * @throws \EE_Error |
|
276 | + */ |
|
277 | 277 | public function datetimes( $query_params = array() ) { |
278 | 278 | if ( ! isset( $query_params[ 'order_by' ] ) ) { |
279 | 279 | $query_params[ 'order_by' ][ 'DTT_order' ] = 'ASC'; |
@@ -283,12 +283,12 @@ discard block |
||
283 | 283 | |
284 | 284 | |
285 | 285 | |
286 | - /** |
|
287 | - * This returns the chronologically last datetime that this ticket is associated with |
|
288 | - * |
|
289 | - * @return EE_Datetime |
|
290 | - * @throws \EE_Error |
|
291 | - */ |
|
286 | + /** |
|
287 | + * This returns the chronologically last datetime that this ticket is associated with |
|
288 | + * |
|
289 | + * @return EE_Datetime |
|
290 | + * @throws \EE_Error |
|
291 | + */ |
|
292 | 292 | public function last_datetime() { |
293 | 293 | $datetimes = $this->datetimes( array( 'limit' => 1, 'order_by' => array( 'DTT_EVT_start' => 'DESC' ) ) ); |
294 | 294 | return end( $datetimes ); |
@@ -296,19 +296,19 @@ discard block |
||
296 | 296 | |
297 | 297 | |
298 | 298 | |
299 | - /** |
|
300 | - * This returns the total tickets sold depending on the given parameters. |
|
301 | - * |
|
302 | - * @param string $what Can be one of two options: 'ticket', 'datetime'. |
|
303 | - * 'ticket' = total ticket sales for all datetimes this ticket is related to |
|
304 | - * 'datetime' = total ticket sales for a specified datetime (required $dtt_id) |
|
305 | - * 'datetime' = total ticket sales in the datetime_ticket table. |
|
306 | - * If $dtt_id is not given then we return an array of sales indexed by datetime. |
|
307 | - * If $dtt_id IS given then we return the tickets sold for that given datetime. |
|
308 | - * @param int $dtt_id [optional] include the dtt_id with $what = 'datetime'. |
|
309 | - * @return mixed (array|int) how many tickets have sold |
|
310 | - * @throws \EE_Error |
|
311 | - */ |
|
299 | + /** |
|
300 | + * This returns the total tickets sold depending on the given parameters. |
|
301 | + * |
|
302 | + * @param string $what Can be one of two options: 'ticket', 'datetime'. |
|
303 | + * 'ticket' = total ticket sales for all datetimes this ticket is related to |
|
304 | + * 'datetime' = total ticket sales for a specified datetime (required $dtt_id) |
|
305 | + * 'datetime' = total ticket sales in the datetime_ticket table. |
|
306 | + * If $dtt_id is not given then we return an array of sales indexed by datetime. |
|
307 | + * If $dtt_id IS given then we return the tickets sold for that given datetime. |
|
308 | + * @param int $dtt_id [optional] include the dtt_id with $what = 'datetime'. |
|
309 | + * @return mixed (array|int) how many tickets have sold |
|
310 | + * @throws \EE_Error |
|
311 | + */ |
|
312 | 312 | public function tickets_sold( $what = 'ticket', $dtt_id = NULL ) { |
313 | 313 | $total = 0; |
314 | 314 | $tickets_sold = $this->_all_tickets_sold(); |
@@ -333,12 +333,12 @@ discard block |
||
333 | 333 | |
334 | 334 | |
335 | 335 | |
336 | - /** |
|
337 | - * This returns an array indexed by datetime_id for tickets sold with this ticket. |
|
338 | - * |
|
339 | - * @return EE_Ticket[] |
|
340 | - * @throws \EE_Error |
|
341 | - */ |
|
336 | + /** |
|
337 | + * This returns an array indexed by datetime_id for tickets sold with this ticket. |
|
338 | + * |
|
339 | + * @return EE_Ticket[] |
|
340 | + * @throws \EE_Error |
|
341 | + */ |
|
342 | 342 | protected function _all_tickets_sold() { |
343 | 343 | $datetimes = $this->get_many_related( 'Datetime' ); |
344 | 344 | $tickets_sold = array(); |
@@ -354,29 +354,29 @@ discard block |
||
354 | 354 | |
355 | 355 | |
356 | 356 | |
357 | - /** |
|
358 | - * This returns the base price object for the ticket. |
|
359 | - * |
|
360 | - * @param bool $return_array whether to return as an array indexed by price id or just the object. |
|
361 | - * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[] |
|
362 | - * @throws \EE_Error |
|
363 | - */ |
|
357 | + /** |
|
358 | + * This returns the base price object for the ticket. |
|
359 | + * |
|
360 | + * @param bool $return_array whether to return as an array indexed by price id or just the object. |
|
361 | + * @return EE_Price|EE_Base_Class|EE_Price[]|EE_Base_Class[] |
|
362 | + * @throws \EE_Error |
|
363 | + */ |
|
364 | 364 | public function base_price( $return_array = FALSE ) { |
365 | 365 | $_where = array( 'Price_Type.PBT_ID' => EEM_Price_Type::base_type_base_price ); |
366 | 366 | return $return_array |
367 | - ? $this->get_many_related( 'Price', array( $_where ) ) |
|
368 | - : $this->get_first_related( 'Price', array( $_where ) ); |
|
367 | + ? $this->get_many_related( 'Price', array( $_where ) ) |
|
368 | + : $this->get_first_related( 'Price', array( $_where ) ); |
|
369 | 369 | } |
370 | 370 | |
371 | 371 | |
372 | 372 | |
373 | - /** |
|
374 | - * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price) |
|
375 | - * |
|
376 | - * @access public |
|
377 | - * @return EE_Price[] |
|
378 | - * @throws \EE_Error |
|
379 | - */ |
|
373 | + /** |
|
374 | + * This returns ONLY the price modifiers for the ticket (i.e. no taxes or base price) |
|
375 | + * |
|
376 | + * @access public |
|
377 | + * @return EE_Price[] |
|
378 | + * @throws \EE_Error |
|
379 | + */ |
|
380 | 380 | public function price_modifiers() { |
381 | 381 | $query_params = array( 0 => array( 'Price_Type.PBT_ID' => array( 'NOT IN', array( EEM_Price_Type::base_type_base_price, EEM_Price_Type::base_type_tax ) ) ) ); |
382 | 382 | return $this->prices( $query_params ); |
@@ -384,132 +384,132 @@ discard block |
||
384 | 384 | |
385 | 385 | |
386 | 386 | |
387 | - /** |
|
388 | - * Gets all the prices that combine to form the final price of this ticket |
|
389 | - * |
|
390 | - * @param array $query_params like EEM_Base::get_all |
|
391 | - * @return EE_Price[]|EE_Base_Class[] |
|
392 | - * @throws \EE_Error |
|
393 | - */ |
|
387 | + /** |
|
388 | + * Gets all the prices that combine to form the final price of this ticket |
|
389 | + * |
|
390 | + * @param array $query_params like EEM_Base::get_all |
|
391 | + * @return EE_Price[]|EE_Base_Class[] |
|
392 | + * @throws \EE_Error |
|
393 | + */ |
|
394 | 394 | public function prices( $query_params = array() ) { |
395 | 395 | return $this->get_many_related( 'Price', $query_params ); |
396 | 396 | } |
397 | 397 | |
398 | 398 | |
399 | 399 | |
400 | - /** |
|
401 | - * Gets all the ticket applicabilities (ie, relations between datetimes and tickets) |
|
402 | - * |
|
403 | - * @param array $query_params see EEM_Base::get_all() |
|
404 | - * @return EE_Datetime_Ticket|EE_Base_Class[] |
|
405 | - * @throws \EE_Error |
|
406 | - */ |
|
400 | + /** |
|
401 | + * Gets all the ticket applicabilities (ie, relations between datetimes and tickets) |
|
402 | + * |
|
403 | + * @param array $query_params see EEM_Base::get_all() |
|
404 | + * @return EE_Datetime_Ticket|EE_Base_Class[] |
|
405 | + * @throws \EE_Error |
|
406 | + */ |
|
407 | 407 | public function datetime_tickets( $query_params = array() ) { |
408 | 408 | return $this->get_many_related( 'Datetime_Ticket', $query_params ); |
409 | 409 | } |
410 | 410 | |
411 | 411 | |
412 | 412 | |
413 | - /** |
|
414 | - * Gets all the datetimes from the db ordered by DTT_order |
|
415 | - * |
|
416 | - * @param boolean $show_expired |
|
417 | - * @param boolean $show_deleted |
|
418 | - * @return EE_Datetime[] |
|
419 | - * @throws \EE_Error |
|
420 | - */ |
|
413 | + /** |
|
414 | + * Gets all the datetimes from the db ordered by DTT_order |
|
415 | + * |
|
416 | + * @param boolean $show_expired |
|
417 | + * @param boolean $show_deleted |
|
418 | + * @return EE_Datetime[] |
|
419 | + * @throws \EE_Error |
|
420 | + */ |
|
421 | 421 | public function datetimes_ordered( $show_expired = TRUE, $show_deleted = FALSE ) { |
422 | 422 | return EEM_Datetime::instance( $this->_timezone )->get_datetimes_for_ticket_ordered_by_DTT_order( $this->ID(), $show_expired, $show_deleted ); |
423 | 423 | } |
424 | 424 | |
425 | 425 | |
426 | 426 | |
427 | - /** |
|
428 | - * Gets ID |
|
429 | - * |
|
430 | - * @return string |
|
431 | - * @throws \EE_Error |
|
432 | - */ |
|
427 | + /** |
|
428 | + * Gets ID |
|
429 | + * |
|
430 | + * @return string |
|
431 | + * @throws \EE_Error |
|
432 | + */ |
|
433 | 433 | public function ID() { |
434 | 434 | return $this->get( 'TKT_ID' ); |
435 | 435 | } |
436 | 436 | |
437 | 437 | |
438 | 438 | |
439 | - /** |
|
440 | - * get the author of the ticket. |
|
441 | - * |
|
442 | - * @since 4.5.0 |
|
443 | - * @return int |
|
444 | - * @throws \EE_Error |
|
445 | - */ |
|
439 | + /** |
|
440 | + * get the author of the ticket. |
|
441 | + * |
|
442 | + * @since 4.5.0 |
|
443 | + * @return int |
|
444 | + * @throws \EE_Error |
|
445 | + */ |
|
446 | 446 | public function wp_user() { |
447 | 447 | return $this->get('TKT_wp_user'); |
448 | 448 | } |
449 | 449 | |
450 | 450 | |
451 | 451 | |
452 | - /** |
|
453 | - * Gets the template for the ticket |
|
454 | - * |
|
455 | - * @return EE_Ticket_Template|EE_Base_Class |
|
456 | - * @throws \EE_Error |
|
457 | - */ |
|
452 | + /** |
|
453 | + * Gets the template for the ticket |
|
454 | + * |
|
455 | + * @return EE_Ticket_Template|EE_Base_Class |
|
456 | + * @throws \EE_Error |
|
457 | + */ |
|
458 | 458 | public function template() { |
459 | 459 | return $this->get_first_related( 'Ticket_Template' ); |
460 | 460 | } |
461 | 461 | |
462 | 462 | |
463 | 463 | |
464 | - /** |
|
465 | - * Simply returns an array of EE_Price objects that are taxes. |
|
466 | - * |
|
467 | - * @return EE_Price[] |
|
468 | - * @throws \EE_Error |
|
469 | - */ |
|
464 | + /** |
|
465 | + * Simply returns an array of EE_Price objects that are taxes. |
|
466 | + * |
|
467 | + * @return EE_Price[] |
|
468 | + * @throws \EE_Error |
|
469 | + */ |
|
470 | 470 | public function get_ticket_taxes_for_admin() { |
471 | 471 | return EE_Taxes::get_taxes_for_admin(); |
472 | 472 | } |
473 | 473 | |
474 | 474 | |
475 | 475 | |
476 | - /** |
|
477 | - * @return float |
|
478 | - * @throws \EE_Error |
|
479 | - */ |
|
476 | + /** |
|
477 | + * @return float |
|
478 | + * @throws \EE_Error |
|
479 | + */ |
|
480 | 480 | public function ticket_price() { |
481 | 481 | return $this->get( 'TKT_price' ); |
482 | 482 | } |
483 | 483 | |
484 | 484 | |
485 | 485 | |
486 | - /** |
|
487 | - * @return mixed |
|
488 | - * @throws \EE_Error |
|
489 | - */ |
|
486 | + /** |
|
487 | + * @return mixed |
|
488 | + * @throws \EE_Error |
|
489 | + */ |
|
490 | 490 | public function pretty_price() { |
491 | 491 | return $this->get_pretty( 'TKT_price' ); |
492 | 492 | } |
493 | 493 | |
494 | 494 | |
495 | 495 | |
496 | - /** |
|
497 | - * @return bool |
|
498 | - * @throws \EE_Error |
|
499 | - */ |
|
496 | + /** |
|
497 | + * @return bool |
|
498 | + * @throws \EE_Error |
|
499 | + */ |
|
500 | 500 | public function is_free() { |
501 | 501 | return $this->get_ticket_total_with_taxes() === (float) 0; |
502 | 502 | } |
503 | 503 | |
504 | 504 | |
505 | 505 | |
506 | - /** |
|
507 | - * get_ticket_total_with_taxes |
|
508 | - * |
|
509 | - * @param bool $no_cache |
|
510 | - * @return float |
|
511 | - * @throws \EE_Error |
|
512 | - */ |
|
506 | + /** |
|
507 | + * get_ticket_total_with_taxes |
|
508 | + * |
|
509 | + * @param bool $no_cache |
|
510 | + * @return float |
|
511 | + * @throws \EE_Error |
|
512 | + */ |
|
513 | 513 | public function get_ticket_total_with_taxes( $no_cache = FALSE ) { |
514 | 514 | if ($this->_ticket_total_with_taxes === null || $no_cache ) { |
515 | 515 | $this->_ticket_total_with_taxes = $this->get_ticket_subtotal() + $this->get_ticket_taxes_total_for_admin(); |
@@ -526,201 +526,201 @@ discard block |
||
526 | 526 | |
527 | 527 | |
528 | 528 | |
529 | - /** |
|
530 | - * @return float |
|
531 | - * @throws \EE_Error |
|
532 | - */ |
|
529 | + /** |
|
530 | + * @return float |
|
531 | + * @throws \EE_Error |
|
532 | + */ |
|
533 | 533 | public function get_ticket_subtotal() { |
534 | 534 | return EE_Taxes::get_subtotal_for_admin( $this ); |
535 | 535 | } |
536 | 536 | |
537 | 537 | |
538 | 538 | |
539 | - /** |
|
540 | - * Returns the total taxes applied to this ticket |
|
541 | - * |
|
542 | - * @return float |
|
543 | - * @throws \EE_Error |
|
544 | - */ |
|
539 | + /** |
|
540 | + * Returns the total taxes applied to this ticket |
|
541 | + * |
|
542 | + * @return float |
|
543 | + * @throws \EE_Error |
|
544 | + */ |
|
545 | 545 | public function get_ticket_taxes_total_for_admin() { |
546 | 546 | return EE_Taxes::get_total_taxes_for_admin( $this ); |
547 | 547 | } |
548 | 548 | |
549 | 549 | |
550 | 550 | |
551 | - /** |
|
552 | - * Sets name |
|
553 | - * |
|
554 | - * @param string $name |
|
555 | - * @throws \EE_Error |
|
556 | - */ |
|
551 | + /** |
|
552 | + * Sets name |
|
553 | + * |
|
554 | + * @param string $name |
|
555 | + * @throws \EE_Error |
|
556 | + */ |
|
557 | 557 | public function set_name( $name ) { |
558 | 558 | $this->set( 'TKT_name', $name ); |
559 | 559 | } |
560 | 560 | |
561 | 561 | |
562 | 562 | |
563 | - /** |
|
564 | - * Gets description |
|
565 | - * |
|
566 | - * @return string |
|
567 | - * @throws \EE_Error |
|
568 | - */ |
|
563 | + /** |
|
564 | + * Gets description |
|
565 | + * |
|
566 | + * @return string |
|
567 | + * @throws \EE_Error |
|
568 | + */ |
|
569 | 569 | public function description() { |
570 | 570 | return $this->get( 'TKT_description' ); |
571 | 571 | } |
572 | 572 | |
573 | 573 | |
574 | 574 | |
575 | - /** |
|
576 | - * Sets description |
|
577 | - * |
|
578 | - * @param string $description |
|
579 | - * @throws \EE_Error |
|
580 | - */ |
|
575 | + /** |
|
576 | + * Sets description |
|
577 | + * |
|
578 | + * @param string $description |
|
579 | + * @throws \EE_Error |
|
580 | + */ |
|
581 | 581 | public function set_description( $description ) { |
582 | 582 | $this->set( 'TKT_description', $description ); |
583 | 583 | } |
584 | 584 | |
585 | 585 | |
586 | 586 | |
587 | - /** |
|
588 | - * Gets start_date |
|
589 | - * |
|
590 | - * @param string $dt_frmt |
|
591 | - * @param string $tm_frmt |
|
592 | - * @return string |
|
593 | - * @throws \EE_Error |
|
594 | - */ |
|
587 | + /** |
|
588 | + * Gets start_date |
|
589 | + * |
|
590 | + * @param string $dt_frmt |
|
591 | + * @param string $tm_frmt |
|
592 | + * @return string |
|
593 | + * @throws \EE_Error |
|
594 | + */ |
|
595 | 595 | public function start_date( $dt_frmt = '', $tm_frmt = '' ) { |
596 | 596 | return $this->_get_datetime( 'TKT_start_date', $dt_frmt, $tm_frmt ); |
597 | 597 | } |
598 | 598 | |
599 | 599 | |
600 | 600 | |
601 | - /** |
|
602 | - * Sets start_date |
|
603 | - * |
|
604 | - * @param string $start_date |
|
605 | - * @return void |
|
606 | - * @throws \EE_Error |
|
607 | - */ |
|
601 | + /** |
|
602 | + * Sets start_date |
|
603 | + * |
|
604 | + * @param string $start_date |
|
605 | + * @return void |
|
606 | + * @throws \EE_Error |
|
607 | + */ |
|
608 | 608 | public function set_start_date( $start_date ) { |
609 | 609 | $this->_set_date_time( 'B', $start_date, 'TKT_start_date' ); |
610 | 610 | } |
611 | 611 | |
612 | 612 | |
613 | 613 | |
614 | - /** |
|
615 | - * Gets end_date |
|
616 | - * |
|
617 | - * @param string $dt_frmt |
|
618 | - * @param string $tm_frmt |
|
619 | - * @return string |
|
620 | - * @throws \EE_Error |
|
621 | - */ |
|
614 | + /** |
|
615 | + * Gets end_date |
|
616 | + * |
|
617 | + * @param string $dt_frmt |
|
618 | + * @param string $tm_frmt |
|
619 | + * @return string |
|
620 | + * @throws \EE_Error |
|
621 | + */ |
|
622 | 622 | public function end_date( $dt_frmt = '', $tm_frmt = '' ) { |
623 | 623 | return $this->_get_datetime( 'TKT_end_date', $dt_frmt, $tm_frmt ); |
624 | 624 | } |
625 | 625 | |
626 | 626 | |
627 | 627 | |
628 | - /** |
|
629 | - * Sets end_date |
|
630 | - * |
|
631 | - * @param string $end_date |
|
632 | - * @return void |
|
633 | - * @throws \EE_Error |
|
634 | - */ |
|
628 | + /** |
|
629 | + * Sets end_date |
|
630 | + * |
|
631 | + * @param string $end_date |
|
632 | + * @return void |
|
633 | + * @throws \EE_Error |
|
634 | + */ |
|
635 | 635 | public function set_end_date( $end_date ) { |
636 | 636 | $this->_set_date_time( 'B', $end_date, 'TKT_end_date' ); |
637 | 637 | } |
638 | 638 | |
639 | 639 | |
640 | 640 | |
641 | - /** |
|
642 | - * Sets sell until time |
|
643 | - * |
|
644 | - * @since 4.5.0 |
|
645 | - * @param string $time a string representation of the sell until time (ex 9am or 7:30pm) |
|
646 | - * @throws \EE_Error |
|
647 | - */ |
|
641 | + /** |
|
642 | + * Sets sell until time |
|
643 | + * |
|
644 | + * @since 4.5.0 |
|
645 | + * @param string $time a string representation of the sell until time (ex 9am or 7:30pm) |
|
646 | + * @throws \EE_Error |
|
647 | + */ |
|
648 | 648 | public function set_end_time( $time ) { |
649 | 649 | $this->_set_time_for( $time, 'TKT_end_date' ); |
650 | 650 | } |
651 | 651 | |
652 | 652 | |
653 | 653 | |
654 | - /** |
|
655 | - * Sets min |
|
656 | - * |
|
657 | - * @param int $min |
|
658 | - * @return void |
|
659 | - * @throws \EE_Error |
|
660 | - */ |
|
654 | + /** |
|
655 | + * Sets min |
|
656 | + * |
|
657 | + * @param int $min |
|
658 | + * @return void |
|
659 | + * @throws \EE_Error |
|
660 | + */ |
|
661 | 661 | public function set_min( $min ) { |
662 | 662 | $this->set( 'TKT_min', $min ); |
663 | 663 | } |
664 | 664 | |
665 | 665 | |
666 | 666 | |
667 | - /** |
|
668 | - * Gets max |
|
669 | - * |
|
670 | - * @return int |
|
671 | - * @throws \EE_Error |
|
672 | - */ |
|
667 | + /** |
|
668 | + * Gets max |
|
669 | + * |
|
670 | + * @return int |
|
671 | + * @throws \EE_Error |
|
672 | + */ |
|
673 | 673 | public function max() { |
674 | 674 | return $this->get( 'TKT_max' ); |
675 | 675 | } |
676 | 676 | |
677 | 677 | |
678 | 678 | |
679 | - /** |
|
680 | - * Sets max |
|
681 | - * |
|
682 | - * @param int $max |
|
683 | - * @return void |
|
684 | - * @throws \EE_Error |
|
685 | - */ |
|
679 | + /** |
|
680 | + * Sets max |
|
681 | + * |
|
682 | + * @param int $max |
|
683 | + * @return void |
|
684 | + * @throws \EE_Error |
|
685 | + */ |
|
686 | 686 | public function set_max( $max ) { |
687 | 687 | $this->set( 'TKT_max', $max ); |
688 | 688 | } |
689 | 689 | |
690 | 690 | |
691 | 691 | |
692 | - /** |
|
693 | - * Sets price |
|
694 | - * |
|
695 | - * @param float $price |
|
696 | - * @return void |
|
697 | - * @throws \EE_Error |
|
698 | - */ |
|
692 | + /** |
|
693 | + * Sets price |
|
694 | + * |
|
695 | + * @param float $price |
|
696 | + * @return void |
|
697 | + * @throws \EE_Error |
|
698 | + */ |
|
699 | 699 | public function set_price( $price ) { |
700 | 700 | $this->set( 'TKT_price', $price ); |
701 | 701 | } |
702 | 702 | |
703 | 703 | |
704 | 704 | |
705 | - /** |
|
706 | - * Gets sold |
|
707 | - * |
|
708 | - * @return int |
|
709 | - * @throws \EE_Error |
|
710 | - */ |
|
705 | + /** |
|
706 | + * Gets sold |
|
707 | + * |
|
708 | + * @return int |
|
709 | + * @throws \EE_Error |
|
710 | + */ |
|
711 | 711 | public function sold() { |
712 | 712 | return $this->get_raw( 'TKT_sold' ); |
713 | 713 | } |
714 | 714 | |
715 | 715 | |
716 | 716 | |
717 | - /** |
|
718 | - * Sets sold |
|
719 | - * |
|
720 | - * @param int $sold |
|
721 | - * @return void |
|
722 | - * @throws \EE_Error |
|
723 | - */ |
|
717 | + /** |
|
718 | + * Sets sold |
|
719 | + * |
|
720 | + * @param int $sold |
|
721 | + * @return void |
|
722 | + * @throws \EE_Error |
|
723 | + */ |
|
724 | 724 | public function set_sold( $sold ) { |
725 | 725 | // sold can not go below zero |
726 | 726 | $sold = max( 0, $sold ); |
@@ -729,13 +729,13 @@ discard block |
||
729 | 729 | |
730 | 730 | |
731 | 731 | |
732 | - /** |
|
733 | - * increments sold by amount passed by $qty |
|
734 | - * |
|
735 | - * @param int $qty |
|
736 | - * @return void |
|
737 | - * @throws \EE_Error |
|
738 | - */ |
|
732 | + /** |
|
733 | + * increments sold by amount passed by $qty |
|
734 | + * |
|
735 | + * @param int $qty |
|
736 | + * @return void |
|
737 | + * @throws \EE_Error |
|
738 | + */ |
|
739 | 739 | public function increase_sold( $qty = 1 ) { |
740 | 740 | $sold = $this->sold() + $qty; |
741 | 741 | // remove ticket reservation, but don't adjust datetime reservations, because that will happen |
@@ -747,13 +747,13 @@ discard block |
||
747 | 747 | |
748 | 748 | |
749 | 749 | |
750 | - /** |
|
751 | - * Increases sold on related datetimes |
|
752 | - * |
|
753 | - * @param int $qty |
|
754 | - * @return void |
|
755 | - * @throws \EE_Error |
|
756 | - */ |
|
750 | + /** |
|
751 | + * Increases sold on related datetimes |
|
752 | + * |
|
753 | + * @param int $qty |
|
754 | + * @return void |
|
755 | + * @throws \EE_Error |
|
756 | + */ |
|
757 | 757 | protected function _increase_sold_for_datetimes( $qty = 1 ) { |
758 | 758 | $datetimes = $this->datetimes(); |
759 | 759 | if ( is_array( $datetimes ) ) { |
@@ -768,13 +768,13 @@ discard block |
||
768 | 768 | |
769 | 769 | |
770 | 770 | |
771 | - /** |
|
772 | - * decrements (subtracts) sold by amount passed by $qty |
|
773 | - * |
|
774 | - * @param int $qty |
|
775 | - * @return void |
|
776 | - * @throws \EE_Error |
|
777 | - */ |
|
771 | + /** |
|
772 | + * decrements (subtracts) sold by amount passed by $qty |
|
773 | + * |
|
774 | + * @param int $qty |
|
775 | + * @return void |
|
776 | + * @throws \EE_Error |
|
777 | + */ |
|
778 | 778 | public function decrease_sold( $qty = 1 ) { |
779 | 779 | $sold = $this->sold() - $qty; |
780 | 780 | $this->_decrease_sold_for_datetimes( $qty ); |
@@ -783,13 +783,13 @@ discard block |
||
783 | 783 | |
784 | 784 | |
785 | 785 | |
786 | - /** |
|
787 | - * Decreases sold on related datetimes |
|
788 | - * |
|
789 | - * @param int $qty |
|
790 | - * @return void |
|
791 | - * @throws \EE_Error |
|
792 | - */ |
|
786 | + /** |
|
787 | + * Decreases sold on related datetimes |
|
788 | + * |
|
789 | + * @param int $qty |
|
790 | + * @return void |
|
791 | + * @throws \EE_Error |
|
792 | + */ |
|
793 | 793 | protected function _decrease_sold_for_datetimes( $qty = 1 ) { |
794 | 794 | $datetimes = $this->datetimes(); |
795 | 795 | if ( is_array( $datetimes ) ) { |
@@ -804,25 +804,25 @@ discard block |
||
804 | 804 | |
805 | 805 | |
806 | 806 | |
807 | - /** |
|
808 | - * Gets qty of reserved tickets |
|
809 | - * |
|
810 | - * @return int |
|
811 | - * @throws \EE_Error |
|
812 | - */ |
|
807 | + /** |
|
808 | + * Gets qty of reserved tickets |
|
809 | + * |
|
810 | + * @return int |
|
811 | + * @throws \EE_Error |
|
812 | + */ |
|
813 | 813 | public function reserved() { |
814 | 814 | return $this->get_raw( 'TKT_reserved' ); |
815 | 815 | } |
816 | 816 | |
817 | 817 | |
818 | 818 | |
819 | - /** |
|
820 | - * Sets reserved |
|
821 | - * |
|
822 | - * @param int $reserved |
|
823 | - * @return void |
|
824 | - * @throws \EE_Error |
|
825 | - */ |
|
819 | + /** |
|
820 | + * Sets reserved |
|
821 | + * |
|
822 | + * @param int $reserved |
|
823 | + * @return void |
|
824 | + * @throws \EE_Error |
|
825 | + */ |
|
826 | 826 | public function set_reserved( $reserved ) { |
827 | 827 | // reserved can not go below zero |
828 | 828 | $reserved = max( 0, (int) $reserved ); |
@@ -831,13 +831,13 @@ discard block |
||
831 | 831 | |
832 | 832 | |
833 | 833 | |
834 | - /** |
|
835 | - * increments reserved by amount passed by $qty |
|
836 | - * |
|
837 | - * @param int $qty |
|
838 | - * @return void |
|
839 | - * @throws \EE_Error |
|
840 | - */ |
|
834 | + /** |
|
835 | + * increments reserved by amount passed by $qty |
|
836 | + * |
|
837 | + * @param int $qty |
|
838 | + * @return void |
|
839 | + * @throws \EE_Error |
|
840 | + */ |
|
841 | 841 | public function increase_reserved( $qty = 1 ) { |
842 | 842 | $qty = absint( $qty ); |
843 | 843 | $reserved = $this->reserved() + $qty; |
@@ -847,13 +847,13 @@ discard block |
||
847 | 847 | |
848 | 848 | |
849 | 849 | |
850 | - /** |
|
851 | - * Increases sold on related datetimes |
|
852 | - * |
|
853 | - * @param int $qty |
|
854 | - * @return void |
|
855 | - * @throws \EE_Error |
|
856 | - */ |
|
850 | + /** |
|
851 | + * Increases sold on related datetimes |
|
852 | + * |
|
853 | + * @param int $qty |
|
854 | + * @return void |
|
855 | + * @throws \EE_Error |
|
856 | + */ |
|
857 | 857 | protected function _increase_reserved_for_datetimes( $qty = 1 ) { |
858 | 858 | $datetimes = $this->datetimes(); |
859 | 859 | if ( is_array( $datetimes ) ) { |
@@ -868,14 +868,14 @@ discard block |
||
868 | 868 | |
869 | 869 | |
870 | 870 | |
871 | - /** |
|
872 | - * decrements (subtracts) reserved by amount passed by $qty |
|
873 | - * |
|
874 | - * @param int $qty |
|
875 | - * @param bool $adjust_datetimes |
|
876 | - * @return void |
|
877 | - * @throws \EE_Error |
|
878 | - */ |
|
871 | + /** |
|
872 | + * decrements (subtracts) reserved by amount passed by $qty |
|
873 | + * |
|
874 | + * @param int $qty |
|
875 | + * @param bool $adjust_datetimes |
|
876 | + * @return void |
|
877 | + * @throws \EE_Error |
|
878 | + */ |
|
879 | 879 | public function decrease_reserved( $qty = 1, $adjust_datetimes = true ) { |
880 | 880 | $reserved = $this->reserved() - absint( $qty ); |
881 | 881 | if ( $adjust_datetimes ) { |
@@ -886,13 +886,13 @@ discard block |
||
886 | 886 | |
887 | 887 | |
888 | 888 | |
889 | - /** |
|
890 | - * Increases sold on related datetimes |
|
891 | - * |
|
892 | - * @param int $qty |
|
893 | - * @return void |
|
894 | - * @throws \EE_Error |
|
895 | - */ |
|
889 | + /** |
|
890 | + * Increases sold on related datetimes |
|
891 | + * |
|
892 | + * @param int $qty |
|
893 | + * @return void |
|
894 | + * @throws \EE_Error |
|
895 | + */ |
|
896 | 896 | protected function _decrease_reserved_for_datetimes( $qty = 1 ) { |
897 | 897 | $datetimes = $this->datetimes(); |
898 | 898 | if ( is_array( $datetimes ) ) { |
@@ -907,18 +907,18 @@ discard block |
||
907 | 907 | |
908 | 908 | |
909 | 909 | |
910 | - /** |
|
911 | - * Gets ticket quantity |
|
912 | - * |
|
913 | - * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
|
914 | - * therefore $context can be one of three values: '', 'reg_limit', or 'saleable' |
|
915 | - * '' (default) quantity is the actual db value for TKT_qty, unaffected by other objects |
|
916 | - * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
|
917 | - * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
|
918 | - * is therefore the truest measure of tickets that can be purchased at the moment |
|
919 | - * @return int |
|
920 | - * @throws \EE_Error |
|
921 | - */ |
|
910 | + /** |
|
911 | + * Gets ticket quantity |
|
912 | + * |
|
913 | + * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
|
914 | + * therefore $context can be one of three values: '', 'reg_limit', or 'saleable' |
|
915 | + * '' (default) quantity is the actual db value for TKT_qty, unaffected by other objects |
|
916 | + * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
|
917 | + * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
|
918 | + * is therefore the truest measure of tickets that can be purchased at the moment |
|
919 | + * @return int |
|
920 | + * @throws \EE_Error |
|
921 | + */ |
|
922 | 922 | public function qty( $context = '' ) { |
923 | 923 | switch ( $context ) { |
924 | 924 | case 'reg_limit' : |
@@ -932,19 +932,19 @@ discard block |
||
932 | 932 | |
933 | 933 | |
934 | 934 | |
935 | - /** |
|
936 | - * Gets ticket quantity |
|
937 | - * |
|
938 | - * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
|
939 | - * therefore $context can be one of two values: 'reg_limit', or 'saleable' |
|
940 | - * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
|
941 | - * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
|
942 | - * is therefore the truest measure of tickets that can be purchased at the moment |
|
943 | - * @param int $DTT_ID the primary key for a particular datetime. |
|
944 | - * set to 0 for all related datetimes |
|
945 | - * @return int |
|
946 | - * @throws \EE_Error |
|
947 | - */ |
|
935 | + /** |
|
936 | + * Gets ticket quantity |
|
937 | + * |
|
938 | + * @param string $context ticket quantity is somewhat subjective depending on the exact information sought |
|
939 | + * therefore $context can be one of two values: 'reg_limit', or 'saleable' |
|
940 | + * REG LIMIT: caps qty based on DTT_reg_limit for ALL related datetimes |
|
941 | + * SALEABLE: also considers datetime sold and returns zero if ANY DTT is sold out, and |
|
942 | + * is therefore the truest measure of tickets that can be purchased at the moment |
|
943 | + * @param int $DTT_ID the primary key for a particular datetime. |
|
944 | + * set to 0 for all related datetimes |
|
945 | + * @return int |
|
946 | + * @throws \EE_Error |
|
947 | + */ |
|
948 | 948 | public function real_quantity_on_ticket( $context = 'reg_limit', $DTT_ID = 0 ) { |
949 | 949 | $raw = $this->get_raw( 'TKT_qty' ); |
950 | 950 | // return immediately if it's zero |
@@ -1027,212 +1027,212 @@ discard block |
||
1027 | 1027 | |
1028 | 1028 | |
1029 | 1029 | |
1030 | - /** |
|
1031 | - * Gets uses |
|
1032 | - * |
|
1033 | - * @return int |
|
1034 | - * @throws \EE_Error |
|
1035 | - */ |
|
1030 | + /** |
|
1031 | + * Gets uses |
|
1032 | + * |
|
1033 | + * @return int |
|
1034 | + * @throws \EE_Error |
|
1035 | + */ |
|
1036 | 1036 | public function uses() { |
1037 | 1037 | return $this->get( 'TKT_uses' ); |
1038 | 1038 | } |
1039 | 1039 | |
1040 | 1040 | |
1041 | 1041 | |
1042 | - /** |
|
1043 | - * Sets uses |
|
1044 | - * |
|
1045 | - * @param int $uses |
|
1046 | - * @return void |
|
1047 | - * @throws \EE_Error |
|
1048 | - */ |
|
1042 | + /** |
|
1043 | + * Sets uses |
|
1044 | + * |
|
1045 | + * @param int $uses |
|
1046 | + * @return void |
|
1047 | + * @throws \EE_Error |
|
1048 | + */ |
|
1049 | 1049 | public function set_uses( $uses ) { |
1050 | 1050 | $this->set( 'TKT_uses', $uses ); |
1051 | 1051 | } |
1052 | 1052 | |
1053 | 1053 | |
1054 | 1054 | |
1055 | - /** |
|
1056 | - * returns whether ticket is required or not. |
|
1057 | - * |
|
1058 | - * @return boolean |
|
1059 | - * @throws \EE_Error |
|
1060 | - */ |
|
1055 | + /** |
|
1056 | + * returns whether ticket is required or not. |
|
1057 | + * |
|
1058 | + * @return boolean |
|
1059 | + * @throws \EE_Error |
|
1060 | + */ |
|
1061 | 1061 | public function required() { |
1062 | 1062 | return $this->get( 'TKT_required' ); |
1063 | 1063 | } |
1064 | 1064 | |
1065 | 1065 | |
1066 | 1066 | |
1067 | - /** |
|
1068 | - * sets the TKT_required property |
|
1069 | - * |
|
1070 | - * @param boolean $required |
|
1071 | - * @return void |
|
1072 | - * @throws \EE_Error |
|
1073 | - */ |
|
1067 | + /** |
|
1068 | + * sets the TKT_required property |
|
1069 | + * |
|
1070 | + * @param boolean $required |
|
1071 | + * @return void |
|
1072 | + * @throws \EE_Error |
|
1073 | + */ |
|
1074 | 1074 | public function set_required( $required ) { |
1075 | 1075 | $this->set( 'TKT_required', $required ); |
1076 | 1076 | } |
1077 | 1077 | |
1078 | 1078 | |
1079 | 1079 | |
1080 | - /** |
|
1081 | - * Gets taxable |
|
1082 | - * |
|
1083 | - * @return boolean |
|
1084 | - * @throws \EE_Error |
|
1085 | - */ |
|
1080 | + /** |
|
1081 | + * Gets taxable |
|
1082 | + * |
|
1083 | + * @return boolean |
|
1084 | + * @throws \EE_Error |
|
1085 | + */ |
|
1086 | 1086 | public function taxable() { |
1087 | 1087 | return $this->get( 'TKT_taxable' ); |
1088 | 1088 | } |
1089 | 1089 | |
1090 | 1090 | |
1091 | 1091 | |
1092 | - /** |
|
1093 | - * Sets taxable |
|
1094 | - * |
|
1095 | - * @param boolean $taxable |
|
1096 | - * @return void |
|
1097 | - * @throws \EE_Error |
|
1098 | - */ |
|
1092 | + /** |
|
1093 | + * Sets taxable |
|
1094 | + * |
|
1095 | + * @param boolean $taxable |
|
1096 | + * @return void |
|
1097 | + * @throws \EE_Error |
|
1098 | + */ |
|
1099 | 1099 | public function set_taxable( $taxable ) { |
1100 | 1100 | $this->set( 'TKT_taxable', $taxable ); |
1101 | 1101 | } |
1102 | 1102 | |
1103 | 1103 | |
1104 | 1104 | |
1105 | - /** |
|
1106 | - * Gets is_default |
|
1107 | - * |
|
1108 | - * @return boolean |
|
1109 | - * @throws \EE_Error |
|
1110 | - */ |
|
1105 | + /** |
|
1106 | + * Gets is_default |
|
1107 | + * |
|
1108 | + * @return boolean |
|
1109 | + * @throws \EE_Error |
|
1110 | + */ |
|
1111 | 1111 | public function is_default() { |
1112 | 1112 | return $this->get( 'TKT_is_default' ); |
1113 | 1113 | } |
1114 | 1114 | |
1115 | 1115 | |
1116 | 1116 | |
1117 | - /** |
|
1118 | - * Sets is_default |
|
1119 | - * |
|
1120 | - * @param boolean $is_default |
|
1121 | - * @return void |
|
1122 | - * @throws \EE_Error |
|
1123 | - */ |
|
1117 | + /** |
|
1118 | + * Sets is_default |
|
1119 | + * |
|
1120 | + * @param boolean $is_default |
|
1121 | + * @return void |
|
1122 | + * @throws \EE_Error |
|
1123 | + */ |
|
1124 | 1124 | public function set_is_default( $is_default ) { |
1125 | 1125 | $this->set( 'TKT_is_default', $is_default ); |
1126 | 1126 | } |
1127 | 1127 | |
1128 | 1128 | |
1129 | 1129 | |
1130 | - /** |
|
1131 | - * Gets order |
|
1132 | - * |
|
1133 | - * @return int |
|
1134 | - * @throws \EE_Error |
|
1135 | - */ |
|
1130 | + /** |
|
1131 | + * Gets order |
|
1132 | + * |
|
1133 | + * @return int |
|
1134 | + * @throws \EE_Error |
|
1135 | + */ |
|
1136 | 1136 | public function order() { |
1137 | 1137 | return $this->get( 'TKT_order' ); |
1138 | 1138 | } |
1139 | 1139 | |
1140 | 1140 | |
1141 | 1141 | |
1142 | - /** |
|
1143 | - * Sets order |
|
1144 | - * |
|
1145 | - * @param int $order |
|
1146 | - * @return void |
|
1147 | - * @throws \EE_Error |
|
1148 | - */ |
|
1142 | + /** |
|
1143 | + * Sets order |
|
1144 | + * |
|
1145 | + * @param int $order |
|
1146 | + * @return void |
|
1147 | + * @throws \EE_Error |
|
1148 | + */ |
|
1149 | 1149 | public function set_order( $order ) { |
1150 | 1150 | $this->set( 'TKT_order', $order ); |
1151 | 1151 | } |
1152 | 1152 | |
1153 | 1153 | |
1154 | 1154 | |
1155 | - /** |
|
1156 | - * Gets row |
|
1157 | - * |
|
1158 | - * @return int |
|
1159 | - * @throws \EE_Error |
|
1160 | - */ |
|
1155 | + /** |
|
1156 | + * Gets row |
|
1157 | + * |
|
1158 | + * @return int |
|
1159 | + * @throws \EE_Error |
|
1160 | + */ |
|
1161 | 1161 | public function row() { |
1162 | 1162 | return $this->get( 'TKT_row' ); |
1163 | 1163 | } |
1164 | 1164 | |
1165 | 1165 | |
1166 | 1166 | |
1167 | - /** |
|
1168 | - * Sets row |
|
1169 | - * |
|
1170 | - * @param int $row |
|
1171 | - * @return void |
|
1172 | - * @throws \EE_Error |
|
1173 | - */ |
|
1167 | + /** |
|
1168 | + * Sets row |
|
1169 | + * |
|
1170 | + * @param int $row |
|
1171 | + * @return void |
|
1172 | + * @throws \EE_Error |
|
1173 | + */ |
|
1174 | 1174 | public function set_row( $row ) { |
1175 | 1175 | $this->set( 'TKT_row', $row ); |
1176 | 1176 | } |
1177 | 1177 | |
1178 | 1178 | |
1179 | 1179 | |
1180 | - /** |
|
1181 | - * Gets deleted |
|
1182 | - * |
|
1183 | - * @return boolean |
|
1184 | - * @throws \EE_Error |
|
1185 | - */ |
|
1180 | + /** |
|
1181 | + * Gets deleted |
|
1182 | + * |
|
1183 | + * @return boolean |
|
1184 | + * @throws \EE_Error |
|
1185 | + */ |
|
1186 | 1186 | public function deleted() { |
1187 | 1187 | return $this->get( 'TKT_deleted' ); |
1188 | 1188 | } |
1189 | 1189 | |
1190 | 1190 | |
1191 | 1191 | |
1192 | - /** |
|
1193 | - * Sets deleted |
|
1194 | - * |
|
1195 | - * @param boolean $deleted |
|
1196 | - * @return void |
|
1197 | - * @throws \EE_Error |
|
1198 | - */ |
|
1192 | + /** |
|
1193 | + * Sets deleted |
|
1194 | + * |
|
1195 | + * @param boolean $deleted |
|
1196 | + * @return void |
|
1197 | + * @throws \EE_Error |
|
1198 | + */ |
|
1199 | 1199 | public function set_deleted( $deleted ) { |
1200 | 1200 | $this->set( 'TKT_deleted', $deleted ); |
1201 | 1201 | } |
1202 | 1202 | |
1203 | 1203 | |
1204 | 1204 | |
1205 | - /** |
|
1206 | - * Gets parent |
|
1207 | - * |
|
1208 | - * @return int |
|
1209 | - * @throws \EE_Error |
|
1210 | - */ |
|
1205 | + /** |
|
1206 | + * Gets parent |
|
1207 | + * |
|
1208 | + * @return int |
|
1209 | + * @throws \EE_Error |
|
1210 | + */ |
|
1211 | 1211 | public function parent_ID() { |
1212 | 1212 | return $this->get( 'TKT_parent' ); |
1213 | 1213 | } |
1214 | 1214 | |
1215 | 1215 | |
1216 | 1216 | |
1217 | - /** |
|
1218 | - * Sets parent |
|
1219 | - * |
|
1220 | - * @param int $parent |
|
1221 | - * @return void |
|
1222 | - * @throws \EE_Error |
|
1223 | - */ |
|
1217 | + /** |
|
1218 | + * Sets parent |
|
1219 | + * |
|
1220 | + * @param int $parent |
|
1221 | + * @return void |
|
1222 | + * @throws \EE_Error |
|
1223 | + */ |
|
1224 | 1224 | public function set_parent_ID( $parent ) { |
1225 | 1225 | $this->set( 'TKT_parent', $parent ); |
1226 | 1226 | } |
1227 | 1227 | |
1228 | 1228 | |
1229 | 1229 | |
1230 | - /** |
|
1231 | - * Gets a string which is handy for showing in gateways etc that describes the ticket. |
|
1232 | - * |
|
1233 | - * @return string |
|
1234 | - * @throws \EE_Error |
|
1235 | - */ |
|
1230 | + /** |
|
1231 | + * Gets a string which is handy for showing in gateways etc that describes the ticket. |
|
1232 | + * |
|
1233 | + * @return string |
|
1234 | + * @throws \EE_Error |
|
1235 | + */ |
|
1236 | 1236 | public function name_and_info() { |
1237 | 1237 | $times = array(); |
1238 | 1238 | foreach ( $this->datetimes() as $datetime ) { |
@@ -1243,67 +1243,67 @@ discard block |
||
1243 | 1243 | |
1244 | 1244 | |
1245 | 1245 | |
1246 | - /** |
|
1247 | - * Gets name |
|
1248 | - * |
|
1249 | - * @return string |
|
1250 | - * @throws \EE_Error |
|
1251 | - */ |
|
1246 | + /** |
|
1247 | + * Gets name |
|
1248 | + * |
|
1249 | + * @return string |
|
1250 | + * @throws \EE_Error |
|
1251 | + */ |
|
1252 | 1252 | public function name() { |
1253 | 1253 | return $this->get( 'TKT_name' ); |
1254 | 1254 | } |
1255 | 1255 | |
1256 | 1256 | |
1257 | 1257 | |
1258 | - /** |
|
1259 | - * Gets price |
|
1260 | - * |
|
1261 | - * @return float |
|
1262 | - * @throws \EE_Error |
|
1263 | - */ |
|
1258 | + /** |
|
1259 | + * Gets price |
|
1260 | + * |
|
1261 | + * @return float |
|
1262 | + * @throws \EE_Error |
|
1263 | + */ |
|
1264 | 1264 | public function price() { |
1265 | 1265 | return $this->get( 'TKT_price' ); |
1266 | 1266 | } |
1267 | 1267 | |
1268 | 1268 | |
1269 | 1269 | |
1270 | - /** |
|
1271 | - * Gets all the registrations for this ticket |
|
1272 | - * |
|
1273 | - * @param array $query_params like EEM_Base::get_all's |
|
1274 | - * @return EE_Registration[]|EE_Base_Class[] |
|
1275 | - * @throws \EE_Error |
|
1276 | - */ |
|
1270 | + /** |
|
1271 | + * Gets all the registrations for this ticket |
|
1272 | + * |
|
1273 | + * @param array $query_params like EEM_Base::get_all's |
|
1274 | + * @return EE_Registration[]|EE_Base_Class[] |
|
1275 | + * @throws \EE_Error |
|
1276 | + */ |
|
1277 | 1277 | public function registrations( $query_params = array() ) { |
1278 | 1278 | return $this->get_many_related( 'Registration', $query_params ); |
1279 | 1279 | } |
1280 | 1280 | |
1281 | 1281 | |
1282 | 1282 | |
1283 | - /** |
|
1284 | - * Updates the TKT_sold attribute (and saves) based on the number of APPROVED registrations for this ticket. |
|
1285 | - * into account |
|
1286 | - * |
|
1287 | - * @return int |
|
1288 | - * @throws \EE_Error |
|
1289 | - */ |
|
1283 | + /** |
|
1284 | + * Updates the TKT_sold attribute (and saves) based on the number of APPROVED registrations for this ticket. |
|
1285 | + * into account |
|
1286 | + * |
|
1287 | + * @return int |
|
1288 | + * @throws \EE_Error |
|
1289 | + */ |
|
1290 | 1290 | public function update_tickets_sold() { |
1291 | - $count_regs_for_this_ticket = $this->count_registrations( |
|
1292 | - array( |
|
1293 | - array( |
|
1294 | - 'STS_ID' => EEM_Registration::status_id_approved, |
|
1295 | - 'REG_deleted' => 0, |
|
1296 | - ), |
|
1297 | - ) |
|
1298 | - ); |
|
1299 | - $sold = $this->sold(); |
|
1300 | - if ($count_regs_for_this_ticket > $sold) { |
|
1301 | - $this->increase_sold($count_regs_for_this_ticket - $sold); |
|
1302 | - $this->save(); |
|
1303 | - } else if ($count_regs_for_this_ticket < $sold) { |
|
1304 | - $this->decrease_sold($count_regs_for_this_ticket - $sold); |
|
1305 | - $this->save(); |
|
1306 | - } |
|
1291 | + $count_regs_for_this_ticket = $this->count_registrations( |
|
1292 | + array( |
|
1293 | + array( |
|
1294 | + 'STS_ID' => EEM_Registration::status_id_approved, |
|
1295 | + 'REG_deleted' => 0, |
|
1296 | + ), |
|
1297 | + ) |
|
1298 | + ); |
|
1299 | + $sold = $this->sold(); |
|
1300 | + if ($count_regs_for_this_ticket > $sold) { |
|
1301 | + $this->increase_sold($count_regs_for_this_ticket - $sold); |
|
1302 | + $this->save(); |
|
1303 | + } else if ($count_regs_for_this_ticket < $sold) { |
|
1304 | + $this->decrease_sold($count_regs_for_this_ticket - $sold); |
|
1305 | + $this->save(); |
|
1306 | + } |
|
1307 | 1307 | return $count_regs_for_this_ticket; |
1308 | 1308 | } |
1309 | 1309 | |
@@ -1331,21 +1331,21 @@ discard block |
||
1331 | 1331 | |
1332 | 1332 | |
1333 | 1333 | |
1334 | - /** |
|
1335 | - * Implementation of the EEI_Event_Relation interface method |
|
1336 | - * |
|
1337 | - * @see EEI_Event_Relation for comments |
|
1338 | - * @return EE_Event |
|
1339 | - * @throws \EE_Error |
|
1340 | - * @throws UnexpectedEntityException |
|
1341 | - */ |
|
1334 | + /** |
|
1335 | + * Implementation of the EEI_Event_Relation interface method |
|
1336 | + * |
|
1337 | + * @see EEI_Event_Relation for comments |
|
1338 | + * @return EE_Event |
|
1339 | + * @throws \EE_Error |
|
1340 | + * @throws UnexpectedEntityException |
|
1341 | + */ |
|
1342 | 1342 | public function get_related_event() { |
1343 | 1343 | //get one datetime to use for getting the event |
1344 | 1344 | $datetime = $this->first_datetime(); |
1345 | 1345 | if ( ! $datetime instanceof \EE_Datetime ) { |
1346 | 1346 | throw new UnexpectedEntityException( |
1347 | 1347 | $datetime, |
1348 | - 'EE_Datetime', |
|
1348 | + 'EE_Datetime', |
|
1349 | 1349 | sprintf( |
1350 | 1350 | __( 'The ticket (%s) is not associated with any valid datetimes.', 'event_espresso'), |
1351 | 1351 | $this->name() |
@@ -1356,7 +1356,7 @@ discard block |
||
1356 | 1356 | if ( ! $event instanceof \EE_Event ) { |
1357 | 1357 | throw new UnexpectedEntityException( |
1358 | 1358 | $event, |
1359 | - 'EE_Event', |
|
1359 | + 'EE_Event', |
|
1360 | 1360 | sprintf( |
1361 | 1361 | __( 'The ticket (%s) is not associated with a valid event.', 'event_espresso'), |
1362 | 1362 | $this->name() |
@@ -1368,14 +1368,14 @@ discard block |
||
1368 | 1368 | |
1369 | 1369 | |
1370 | 1370 | |
1371 | - /** |
|
1372 | - * Implementation of the EEI_Event_Relation interface method |
|
1373 | - * |
|
1374 | - * @see EEI_Event_Relation for comments |
|
1375 | - * @return string |
|
1376 | - * @throws UnexpectedEntityException |
|
1377 | - * @throws \EE_Error |
|
1378 | - */ |
|
1371 | + /** |
|
1372 | + * Implementation of the EEI_Event_Relation interface method |
|
1373 | + * |
|
1374 | + * @see EEI_Event_Relation for comments |
|
1375 | + * @return string |
|
1376 | + * @throws UnexpectedEntityException |
|
1377 | + * @throws \EE_Error |
|
1378 | + */ |
|
1379 | 1379 | public function get_event_name() { |
1380 | 1380 | $event = $this->get_related_event(); |
1381 | 1381 | return $event instanceof EE_Event ? $event->name() : ''; |
@@ -1383,28 +1383,28 @@ discard block |
||
1383 | 1383 | |
1384 | 1384 | |
1385 | 1385 | |
1386 | - /** |
|
1387 | - * Implementation of the EEI_Event_Relation interface method |
|
1388 | - * |
|
1389 | - * @see EEI_Event_Relation for comments |
|
1390 | - * @return int |
|
1391 | - * @throws UnexpectedEntityException |
|
1392 | - * @throws \EE_Error |
|
1393 | - */ |
|
1386 | + /** |
|
1387 | + * Implementation of the EEI_Event_Relation interface method |
|
1388 | + * |
|
1389 | + * @see EEI_Event_Relation for comments |
|
1390 | + * @return int |
|
1391 | + * @throws UnexpectedEntityException |
|
1392 | + * @throws \EE_Error |
|
1393 | + */ |
|
1394 | 1394 | public function get_event_ID() { |
1395 | 1395 | $event = $this->get_related_event(); |
1396 | 1396 | return $event instanceof EE_Event ? $event->ID() : 0; |
1397 | 1397 | } |
1398 | 1398 | |
1399 | 1399 | |
1400 | - /** |
|
1401 | - * This simply returns whether a ticket can be permanently deleted or not. |
|
1402 | - * The criteria for determining this is whether the ticket has any related registrations. |
|
1403 | - * If there are none then it can be permanently deleted. |
|
1404 | - * |
|
1405 | - * @return bool |
|
1406 | - */ |
|
1400 | + /** |
|
1401 | + * This simply returns whether a ticket can be permanently deleted or not. |
|
1402 | + * The criteria for determining this is whether the ticket has any related registrations. |
|
1403 | + * If there are none then it can be permanently deleted. |
|
1404 | + * |
|
1405 | + * @return bool |
|
1406 | + */ |
|
1407 | 1407 | public function is_permanently_deleteable() { |
1408 | - return $this->count_registrations() === 0; |
|
1409 | - } |
|
1408 | + return $this->count_registrations() === 0; |
|
1409 | + } |
|
1410 | 1410 | } //end EE_Ticket class |
@@ -15,2114 +15,2114 @@ |
||
15 | 15 | class espresso_events_Pricing_Hooks extends EE_Admin_Hooks |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * This property is just used to hold the status of whether an event is currently being |
|
20 | - * created (true) or edited (false) |
|
21 | - * |
|
22 | - * @access protected |
|
23 | - * @var bool |
|
24 | - */ |
|
25 | - protected $_is_creating_event; |
|
26 | - |
|
27 | - |
|
28 | - /** |
|
29 | - * Used to contain the format strings for date and time that will be used for php date and |
|
30 | - * time. |
|
31 | - * Is set in the _set_hooks_properties() method. |
|
32 | - * |
|
33 | - * @var array |
|
34 | - */ |
|
35 | - protected $_date_format_strings; |
|
36 | - |
|
37 | - |
|
38 | - /** |
|
39 | - * @var string $_date_time_format |
|
40 | - */ |
|
41 | - protected $_date_time_format; |
|
42 | - |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * |
|
47 | - */ |
|
48 | - protected function _set_hooks_properties() |
|
49 | - { |
|
50 | - $this->_name = 'pricing'; |
|
51 | - //capability check |
|
52 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
53 | - 'ee_read_default_prices', |
|
54 | - 'advanced_ticket_datetime_metabox' |
|
55 | - )) { |
|
56 | - return; |
|
57 | - } |
|
58 | - $this->_setup_metaboxes(); |
|
59 | - $this->_set_date_time_formats(); |
|
60 | - $this->_validate_format_strings(); |
|
61 | - $this->_set_scripts_styles(); |
|
62 | - // commented out temporarily until logic is implemented in callback |
|
63 | - // add_action( |
|
64 | - // 'AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page', |
|
65 | - // array($this, 'autosave_handling') |
|
66 | - // ); |
|
67 | - add_filter( |
|
68 | - 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
69 | - array($this, 'caf_updates') |
|
70 | - ); |
|
71 | - } |
|
72 | - |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * @return void |
|
77 | - */ |
|
78 | - protected function _setup_metaboxes() |
|
79 | - { |
|
80 | - //if we were going to add our own metaboxes we'd use the below. |
|
81 | - $this->_metaboxes = array( |
|
82 | - 0 => array( |
|
83 | - 'page_route' => array('edit', 'create_new'), |
|
84 | - 'func' => 'pricing_metabox', |
|
85 | - 'label' => esc_html__('Event Tickets & Datetimes', 'event_espresso'), |
|
86 | - 'priority' => 'high', |
|
87 | - 'context' => 'normal', |
|
88 | - ), |
|
89 | - ); |
|
90 | - $this->_remove_metaboxes = array( |
|
91 | - 0 => array( |
|
92 | - 'page_route' => array('edit', 'create_new'), |
|
93 | - 'id' => 'espresso_event_editor_tickets', |
|
94 | - 'context' => 'normal', |
|
95 | - ), |
|
96 | - ); |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * @return void |
|
103 | - */ |
|
104 | - protected function _set_date_time_formats() |
|
105 | - { |
|
106 | - /** |
|
107 | - * Format strings for date and time. Defaults are existing behaviour from 4.1. |
|
108 | - * Note, that if you return null as the value for 'date', and 'time' in the array, then |
|
109 | - * EE will automatically use the set wp_options, 'date_format', and 'time_format'. |
|
110 | - * |
|
111 | - * @since 4.6.7 |
|
112 | - * @var array Expected an array returned with 'date' and 'time' keys. |
|
113 | - */ |
|
114 | - $this->_date_format_strings = apply_filters( |
|
115 | - 'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings', |
|
116 | - array( |
|
117 | - 'date' => 'Y-m-d', |
|
118 | - 'time' => 'h:i a', |
|
119 | - ) |
|
120 | - ); |
|
121 | - //validate |
|
122 | - $this->_date_format_strings['date'] = isset($this->_date_format_strings['date']) |
|
123 | - ? $this->_date_format_strings['date'] |
|
124 | - : null; |
|
125 | - $this->_date_format_strings['time'] = isset($this->_date_format_strings['time']) |
|
126 | - ? $this->_date_format_strings['time'] |
|
127 | - : null; |
|
128 | - $this->_date_time_format = $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']; |
|
129 | - } |
|
130 | - |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * @return void |
|
135 | - */ |
|
136 | - protected function _validate_format_strings() |
|
137 | - { |
|
138 | - //validate format strings |
|
139 | - $format_validation = EEH_DTT_Helper::validate_format_string( |
|
140 | - $this->_date_time_format |
|
141 | - ); |
|
142 | - if (is_array($format_validation)) { |
|
143 | - $msg = '<p>'; |
|
144 | - $msg .= sprintf( |
|
145 | - esc_html__( |
|
146 | - 'The format "%s" was likely added via a filter and is invalid for the following reasons:', |
|
147 | - 'event_espresso' |
|
148 | - ), |
|
149 | - $this->_date_time_format |
|
150 | - ); |
|
151 | - $msg .= '</p><ul>'; |
|
152 | - foreach ($format_validation as $error) { |
|
153 | - $msg .= '<li>' . $error . '</li>'; |
|
154 | - } |
|
155 | - $msg .= '</ul><p>'; |
|
156 | - $msg .= sprintf( |
|
157 | - esc_html__( |
|
158 | - '%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s', |
|
159 | - 'event_espresso' |
|
160 | - ), |
|
161 | - '<span style="color:#D54E21;">', |
|
162 | - '</span>' |
|
163 | - ); |
|
164 | - $msg .= '</p>'; |
|
165 | - EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
166 | - $this->_date_format_strings = array( |
|
167 | - 'date' => 'Y-m-d', |
|
168 | - 'time' => 'h:i a', |
|
169 | - ); |
|
170 | - } |
|
171 | - } |
|
172 | - |
|
173 | - |
|
174 | - |
|
175 | - /** |
|
176 | - * @return void |
|
177 | - */ |
|
178 | - protected function _set_scripts_styles() |
|
179 | - { |
|
180 | - $this->_scripts_styles = array( |
|
181 | - 'registers' => array( |
|
182 | - 'ee-tickets-datetimes-css' => array( |
|
183 | - 'url' => PRICING_ASSETS_URL . 'event-tickets-datetimes.css', |
|
184 | - 'type' => 'css', |
|
185 | - ), |
|
186 | - 'ee-dtt-ticket-metabox' => array( |
|
187 | - 'url' => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js', |
|
188 | - 'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'), |
|
189 | - ), |
|
190 | - ), |
|
191 | - 'deregisters' => array( |
|
192 | - 'event-editor-css' => array('type' => 'css'), |
|
193 | - 'event-datetime-metabox' => array('type' => 'js'), |
|
194 | - ), |
|
195 | - 'enqueues' => array( |
|
196 | - 'ee-tickets-datetimes-css' => array('edit', 'create_new'), |
|
197 | - 'ee-dtt-ticket-metabox' => array('edit', 'create_new'), |
|
198 | - ), |
|
199 | - 'localize' => array( |
|
200 | - 'ee-dtt-ticket-metabox' => array( |
|
201 | - 'DTT_TRASH_BLOCK' => array( |
|
202 | - 'main_warning' => esc_html__( |
|
203 | - 'The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):', |
|
204 | - 'event_espresso' |
|
205 | - ), |
|
206 | - 'after_warning' => esc_html__( |
|
207 | - 'In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.', |
|
208 | - 'event_espresso' |
|
209 | - ), |
|
210 | - 'cancel_button' => '<button class="button-secondary ee-modal-cancel">' |
|
211 | - . esc_html__('Cancel', 'event_espresso') . '</button>', |
|
212 | - 'close_button' => '<button class="button-secondary ee-modal-cancel">' |
|
213 | - . esc_html__('Close', 'event_espresso') . '</button>', |
|
214 | - 'single_warning_from_tkt' => esc_html__( |
|
215 | - 'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.', |
|
216 | - 'event_espresso' |
|
217 | - ), |
|
218 | - 'single_warning_from_dtt' => esc_html__( |
|
219 | - 'The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket. Tickets must always have at least one datetime assigned to them.', |
|
220 | - 'event_espresso' |
|
221 | - ), |
|
222 | - 'dismiss_button' => '<button class="button-secondary ee-modal-cancel">' |
|
223 | - . esc_html__('Dismiss', 'event_espresso') . '</button>', |
|
224 | - ), |
|
225 | - 'DTT_ERROR_MSG' => array( |
|
226 | - 'no_ticket_name' => esc_html__('General Admission', 'event_espresso'), |
|
227 | - 'dismiss_button' => '<div class="save-cancel-button-container"><button class="button-secondary ee-modal-cancel">' |
|
228 | - . esc_html__('Dismiss', 'event_espresso') . '</button></div>', |
|
229 | - ), |
|
230 | - 'DTT_OVERSELL_WARNING' => array( |
|
231 | - 'datetime_ticket' => esc_html__( |
|
232 | - 'You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.', |
|
233 | - 'event_espresso' |
|
234 | - ), |
|
235 | - 'ticket_datetime' => esc_html__( |
|
236 | - 'You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.', |
|
237 | - 'event_espresso' |
|
238 | - ), |
|
239 | - ), |
|
240 | - 'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats( |
|
241 | - $this->_date_format_strings['date'], |
|
242 | - $this->_date_format_strings['time'] |
|
243 | - ), |
|
244 | - 'DTT_START_OF_WEEK' => array('dayValue' => (int)get_option('start_of_week')), |
|
245 | - ), |
|
246 | - ), |
|
247 | - ); |
|
248 | - } |
|
249 | - |
|
250 | - |
|
251 | - |
|
252 | - /** |
|
253 | - * @param array $update_callbacks |
|
254 | - * @return array |
|
255 | - */ |
|
256 | - public function caf_updates(array $update_callbacks) |
|
257 | - { |
|
258 | - foreach ($update_callbacks as $key => $callback) { |
|
259 | - if ($callback[1] === '_default_tickets_update') { |
|
260 | - unset($update_callbacks[$key]); |
|
261 | - } |
|
262 | - } |
|
263 | - $update_callbacks[] = array($this, 'datetime_and_tickets_caf_update'); |
|
264 | - return $update_callbacks; |
|
265 | - } |
|
266 | - |
|
267 | - |
|
268 | - /** |
|
269 | - * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
270 | - * |
|
271 | - * @param EE_Event $event The Event object we're attaching data to |
|
272 | - * @param array $data The request data from the form |
|
273 | - * @throws EE_Error |
|
274 | - * @throws InvalidArgumentException |
|
275 | - */ |
|
276 | - public function datetime_and_tickets_caf_update($event, $data) |
|
277 | - { |
|
278 | - //first we need to start with datetimes cause they are the "root" items attached to events. |
|
279 | - $saved_datetimes = $this->_update_datetimes($event, $data); |
|
280 | - //next tackle the tickets (and prices?) |
|
281 | - $this->_update_tickets($event, $saved_datetimes, $data); |
|
282 | - } |
|
283 | - |
|
284 | - |
|
285 | - /** |
|
286 | - * update event_datetimes |
|
287 | - * |
|
288 | - * @param EE_Event $event Event being updated |
|
289 | - * @param array $data the request data from the form |
|
290 | - * @return EE_Datetime[] |
|
291 | - * @throws InvalidArgumentException |
|
292 | - * @throws EE_Error |
|
293 | - */ |
|
294 | - protected function _update_datetimes($event, $data) |
|
295 | - { |
|
296 | - $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
297 | - $saved_dtt_ids = array(); |
|
298 | - $saved_dtt_objs = array(); |
|
299 | - if (empty($data['edit_event_datetimes']) || !is_array($data['edit_event_datetimes'])) { |
|
300 | - throw new InvalidArgumentException( |
|
301 | - esc_html__( |
|
302 | - 'The "edit_event_datetimes" array is invalid therefore the event can not be updated.', |
|
303 | - 'event_espresso' |
|
304 | - ) |
|
305 | - ); |
|
306 | - } |
|
307 | - foreach ($data['edit_event_datetimes'] as $row => $datetime_data) { |
|
308 | - //trim all values to ensure any excess whitespace is removed. |
|
309 | - $datetime_data = array_map( |
|
310 | - function ($datetime_data) { |
|
311 | - return is_array($datetime_data) ? $datetime_data : trim($datetime_data); |
|
312 | - }, |
|
313 | - $datetime_data |
|
314 | - ); |
|
315 | - $datetime_data['DTT_EVT_end'] = isset($datetime_data['DTT_EVT_end']) |
|
316 | - && ! empty($datetime_data['DTT_EVT_end']) |
|
317 | - ? $datetime_data['DTT_EVT_end'] |
|
318 | - : $datetime_data['DTT_EVT_start']; |
|
319 | - $datetime_values = array( |
|
320 | - 'DTT_ID' => ! empty($datetime_data['DTT_ID']) |
|
321 | - ? $datetime_data['DTT_ID'] |
|
322 | - : null, |
|
323 | - 'DTT_name' => ! empty($datetime_data['DTT_name']) |
|
324 | - ? $datetime_data['DTT_name'] |
|
325 | - : '', |
|
326 | - 'DTT_description' => ! empty($datetime_data['DTT_description']) |
|
327 | - ? $datetime_data['DTT_description'] |
|
328 | - : '', |
|
329 | - 'DTT_EVT_start' => $datetime_data['DTT_EVT_start'], |
|
330 | - 'DTT_EVT_end' => $datetime_data['DTT_EVT_end'], |
|
331 | - 'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) |
|
332 | - ? EE_INF |
|
333 | - : $datetime_data['DTT_reg_limit'], |
|
334 | - 'DTT_order' => ! isset($datetime_data['DTT_order']) |
|
335 | - ? $row |
|
336 | - : $datetime_data['DTT_order'], |
|
337 | - ); |
|
338 | - // if we have an id then let's get existing object first and then set the new values. |
|
339 | - // Otherwise we instantiate a new object for save. |
|
340 | - if (! empty($datetime_data['DTT_ID'])) { |
|
341 | - $datetime = EE_Registry::instance() |
|
342 | - ->load_model('Datetime', array($timezone)) |
|
343 | - ->get_one_by_ID($datetime_data['DTT_ID']); |
|
344 | - //set date and time format according to what is set in this class. |
|
345 | - $datetime->set_date_format($this->_date_format_strings['date']); |
|
346 | - $datetime->set_time_format($this->_date_format_strings['time']); |
|
347 | - foreach ($datetime_values as $field => $value) { |
|
348 | - $datetime->set($field, $value); |
|
349 | - } |
|
350 | - // make sure the $dtt_id here is saved just in case |
|
351 | - // after the add_relation_to() the autosave replaces it. |
|
352 | - // We need to do this so we dont' TRASH the parent DTT. |
|
353 | - // (save the ID for both key and value to avoid duplications) |
|
354 | - $saved_dtt_ids[$datetime->ID()] = $datetime->ID(); |
|
355 | - } else { |
|
356 | - $datetime = EE_Registry::instance()->load_class( |
|
357 | - 'Datetime', |
|
358 | - array( |
|
359 | - $datetime_values, |
|
360 | - $timezone, |
|
361 | - array($this->_date_format_strings['date'], $this->_date_format_strings['time']), |
|
362 | - ), |
|
363 | - false, |
|
364 | - false |
|
365 | - ); |
|
366 | - foreach ($datetime_values as $field => $value) { |
|
367 | - $datetime->set($field, $value); |
|
368 | - } |
|
369 | - } |
|
370 | - $datetime->save(); |
|
371 | - $datetime = $event->_add_relation_to($datetime, 'Datetime'); |
|
372 | - // before going any further make sure our dates are setup correctly |
|
373 | - // so that the end date is always equal or greater than the start date. |
|
374 | - if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) { |
|
375 | - $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start')); |
|
376 | - $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days'); |
|
377 | - $datetime->save(); |
|
378 | - } |
|
379 | - // now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array |
|
380 | - // because it is possible there was a new one created for the autosave. |
|
381 | - // (save the ID for both key and value to avoid duplications) |
|
382 | - $DTT_ID = $datetime->ID(); |
|
383 | - $saved_dtt_ids[$DTT_ID] = $DTT_ID; |
|
384 | - $saved_dtt_objs[$row] = $datetime; |
|
385 | - //todo if ANY of these updates fail then we want the appropriate global error message. |
|
386 | - } |
|
387 | - $event->save(); |
|
388 | - // now we need to REMOVE any datetimes that got deleted. |
|
389 | - // Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them. |
|
390 | - // So its safe to permanently delete at this point. |
|
391 | - $old_datetimes = explode(',', $data['datetime_IDs']); |
|
392 | - $old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes; |
|
393 | - if (is_array($old_datetimes)) { |
|
394 | - $datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids); |
|
395 | - foreach ($datetimes_to_delete as $id) { |
|
396 | - $id = absint($id); |
|
397 | - if (empty($id)) { |
|
398 | - continue; |
|
399 | - } |
|
400 | - $dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id); |
|
401 | - //remove tkt relationships. |
|
402 | - $related_tickets = $dtt_to_remove->get_many_related('Ticket'); |
|
403 | - foreach ($related_tickets as $tkt) { |
|
404 | - $dtt_to_remove->_remove_relation_to($tkt, 'Ticket'); |
|
405 | - } |
|
406 | - $event->_remove_relation_to($id, 'Datetime'); |
|
407 | - $dtt_to_remove->refresh_cache_of_related_objects(); |
|
408 | - } |
|
409 | - } |
|
410 | - return $saved_dtt_objs; |
|
411 | - } |
|
412 | - |
|
413 | - |
|
414 | - /** |
|
415 | - * update tickets |
|
416 | - * |
|
417 | - * @param EE_Event $event Event object being updated |
|
418 | - * @param EE_Datetime[] $saved_datetimes an array of datetime ids being updated |
|
419 | - * @param array $data incoming request data |
|
420 | - * @return EE_Ticket[] |
|
421 | - * @throws InvalidArgumentException |
|
422 | - * @throws EE_Error |
|
423 | - */ |
|
424 | - protected function _update_tickets($event, $saved_datetimes, $data) |
|
425 | - { |
|
426 | - $new_tkt = null; |
|
427 | - $new_default = null; |
|
428 | - //stripslashes because WP filtered the $_POST ($data) array to add slashes |
|
429 | - $data = stripslashes_deep($data); |
|
430 | - $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
431 | - $saved_tickets = $datetimes_on_existing = array(); |
|
432 | - $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
433 | - if(empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])){ |
|
434 | - throw new InvalidArgumentException( |
|
435 | - esc_html__( |
|
436 | - 'The "edit_tickets" array is invalid therefore the event can not be updated.', |
|
437 | - 'event_espresso' |
|
438 | - ) |
|
439 | - ); |
|
440 | - } |
|
441 | - foreach ($data['edit_tickets'] as $row => $tkt) { |
|
442 | - $update_prices = $create_new_TKT = false; |
|
443 | - // figure out what datetimes were added to the ticket |
|
444 | - // and what datetimes were removed from the ticket in the session. |
|
445 | - $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][$row]); |
|
446 | - $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][$row]); |
|
447 | - $datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows); |
|
448 | - $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows); |
|
449 | - // trim inputs to ensure any excess whitespace is removed. |
|
450 | - $tkt = array_map( |
|
451 | - function ($ticket_data) { |
|
452 | - return is_array($ticket_data) ? $ticket_data : trim($ticket_data); |
|
453 | - }, |
|
454 | - $tkt |
|
455 | - ); |
|
456 | - // note we are doing conversions to floats here instead of allowing EE_Money_Field to handle |
|
457 | - // because we're doing calculations prior to using the models. |
|
458 | - // note incoming ['TKT_price'] value is already in standard notation (via js). |
|
459 | - $ticket_price = isset($tkt['TKT_price']) |
|
460 | - ? round((float)$tkt['TKT_price'], 3) |
|
461 | - : 0; |
|
462 | - //note incoming base price needs converted from localized value. |
|
463 | - $base_price = isset($tkt['TKT_base_price']) |
|
464 | - ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price']) |
|
465 | - : 0; |
|
466 | - //if ticket price == 0 and $base_price != 0 then ticket price == base_price |
|
467 | - $ticket_price = $ticket_price === 0 && $base_price !== 0 |
|
468 | - ? $base_price |
|
469 | - : $ticket_price; |
|
470 | - $base_price_id = isset($tkt['TKT_base_price_ID']) |
|
471 | - ? $tkt['TKT_base_price_ID'] |
|
472 | - : 0; |
|
473 | - $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][$row]) |
|
474 | - ? $data['edit_prices'][$row] |
|
475 | - : array(); |
|
476 | - $now = null; |
|
477 | - if (empty($tkt['TKT_start_date'])) { |
|
478 | - //lets' use now in the set timezone. |
|
479 | - $now = new DateTime('now', new DateTimeZone($event->get_timezone())); |
|
480 | - $tkt['TKT_start_date'] = $now->format($this->_date_time_format); |
|
481 | - } |
|
482 | - if (empty($tkt['TKT_end_date'])) { |
|
483 | - /** |
|
484 | - * set the TKT_end_date to the first datetime attached to the ticket. |
|
485 | - */ |
|
486 | - $first_dtt = $saved_datetimes[reset($tkt_dtt_rows)]; |
|
487 | - $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format); |
|
488 | - } |
|
489 | - $TKT_values = array( |
|
490 | - 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
491 | - 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
492 | - 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
493 | - 'TKT_description' => ! empty($tkt['TKT_description']) |
|
494 | - && $tkt['TKT_description'] !== esc_html__( |
|
495 | - 'You can modify this description', |
|
496 | - 'event_espresso' |
|
497 | - ) |
|
498 | - ? $tkt['TKT_description'] |
|
499 | - : '', |
|
500 | - 'TKT_start_date' => $tkt['TKT_start_date'], |
|
501 | - 'TKT_end_date' => $tkt['TKT_end_date'], |
|
502 | - 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' |
|
503 | - ? EE_INF |
|
504 | - : $tkt['TKT_qty'], |
|
505 | - 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' |
|
506 | - ? EE_INF |
|
507 | - : $tkt['TKT_uses'], |
|
508 | - 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
509 | - 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
510 | - 'TKT_row' => $row, |
|
511 | - 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0, |
|
512 | - 'TKT_taxable' => ! empty($tkt['TKT_taxable']) ? 1 : 0, |
|
513 | - 'TKT_required' => ! empty($tkt['TKT_required']) ? 1 : 0, |
|
514 | - 'TKT_price' => $ticket_price, |
|
515 | - ); |
|
516 | - // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, |
|
517 | - // which means in turn that the prices will become new prices as well. |
|
518 | - if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
519 | - $TKT_values['TKT_ID'] = 0; |
|
520 | - $TKT_values['TKT_is_default'] = 0; |
|
521 | - $update_prices = true; |
|
522 | - } |
|
523 | - // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
524 | - // we actually do our saves ahead of doing any add_relations to |
|
525 | - // because its entirely possible that this ticket wasn't removed or added to any datetime in the session |
|
526 | - // but DID have it's items modified. |
|
527 | - // keep in mind that if the TKT has been sold (and we have changed pricing information), |
|
528 | - // then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
529 | - if (absint($TKT_values['TKT_ID'])) { |
|
530 | - $ticket = EE_Registry::instance() |
|
531 | - ->load_model('Ticket', array($timezone)) |
|
532 | - ->get_one_by_ID($tkt['TKT_ID']); |
|
533 | - if ($ticket instanceof EE_Ticket) { |
|
534 | - $ticket = $this->_update_ticket_datetimes( |
|
535 | - $ticket, |
|
536 | - $saved_datetimes, |
|
537 | - $datetimes_added, |
|
538 | - $datetimes_removed |
|
539 | - ); |
|
540 | - // are there any registrations using this ticket ? |
|
541 | - $tickets_sold = $ticket->count_related( |
|
542 | - 'Registration', |
|
543 | - array( |
|
544 | - array( |
|
545 | - 'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)), |
|
546 | - ), |
|
547 | - ) |
|
548 | - ); |
|
549 | - //set ticket formats |
|
550 | - $ticket->set_date_format($this->_date_format_strings['date']); |
|
551 | - $ticket->set_time_format($this->_date_format_strings['time']); |
|
552 | - // let's just check the total price for the existing ticket |
|
553 | - // and determine if it matches the new total price. |
|
554 | - // if they are different then we create a new ticket (if tickets sold) |
|
555 | - // if they aren't different then we go ahead and modify existing ticket. |
|
556 | - $create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted(); |
|
557 | - //set new values |
|
558 | - foreach ($TKT_values as $field => $value) { |
|
559 | - if ($field === 'TKT_qty') { |
|
560 | - $ticket->set_qty($value); |
|
561 | - } else { |
|
562 | - $ticket->set($field, $value); |
|
563 | - } |
|
564 | - } |
|
565 | - // if $create_new_TKT is false then we can safely update the existing ticket. |
|
566 | - // Otherwise we have to create a new ticket. |
|
567 | - if ($create_new_TKT) { |
|
568 | - $new_tkt = $this->_duplicate_ticket($ticket, $price_rows, $ticket_price, $base_price, |
|
569 | - $base_price_id); |
|
570 | - } |
|
571 | - } |
|
572 | - } else { |
|
573 | - // no TKT_id so a new TKT |
|
574 | - $ticket = EE_Ticket::new_instance( |
|
575 | - $TKT_values, |
|
576 | - $timezone, |
|
577 | - array($this->_date_format_strings['date'], $this->_date_format_strings['time']) |
|
578 | - ); |
|
579 | - if ($ticket instanceof EE_Ticket) { |
|
580 | - // make sure ticket has an ID of setting relations won't work |
|
581 | - $ticket->save(); |
|
582 | - $ticket = $this->_update_ticket_datetimes( |
|
583 | - $ticket, |
|
584 | - $saved_datetimes, |
|
585 | - $datetimes_added, |
|
586 | - $datetimes_removed |
|
587 | - ); |
|
588 | - $update_prices = true; |
|
589 | - } |
|
590 | - } |
|
591 | - //make sure any current values have been saved. |
|
592 | - //$ticket->save(); |
|
593 | - // before going any further make sure our dates are setup correctly |
|
594 | - // so that the end date is always equal or greater than the start date. |
|
595 | - if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) { |
|
596 | - $ticket->set('TKT_end_date', $ticket->get('TKT_start_date')); |
|
597 | - $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days'); |
|
598 | - } |
|
599 | - //let's make sure the base price is handled |
|
600 | - $ticket = ! $create_new_TKT ? $this->_add_prices_to_ticket(array(), $ticket, $update_prices, $base_price, |
|
601 | - $base_price_id) : $ticket; |
|
602 | - //add/update price_modifiers |
|
603 | - $ticket = ! $create_new_TKT ? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices) : $ticket; |
|
604 | - //need to make sue that the TKT_price is accurate after saving the prices. |
|
605 | - $ticket->ensure_TKT_Price_correct(); |
|
606 | - //handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave. |
|
607 | - if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) { |
|
608 | - $update_prices = true; |
|
609 | - $new_default = clone $ticket; |
|
610 | - $new_default->set('TKT_ID', 0); |
|
611 | - $new_default->set('TKT_is_default', 1); |
|
612 | - $new_default->set('TKT_row', 1); |
|
613 | - $new_default->set('TKT_price', $ticket_price); |
|
614 | - // remove any dtt relations cause we DON'T want dtt relations attached |
|
615 | - // (note this is just removing the cached relations in the object) |
|
616 | - $new_default->_remove_relations('Datetime'); |
|
617 | - //todo we need to add the current attached prices as new prices to the new default ticket. |
|
618 | - $new_default = $this->_add_prices_to_ticket($price_rows, $new_default, $update_prices); |
|
619 | - //don't forget the base price! |
|
620 | - $new_default = $this->_add_prices_to_ticket( |
|
621 | - array(), |
|
622 | - $new_default, |
|
623 | - $update_prices, |
|
624 | - $base_price, |
|
625 | - $base_price_id |
|
626 | - ); |
|
627 | - $new_default->save(); |
|
628 | - do_action( |
|
629 | - 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket', |
|
630 | - $new_default, |
|
631 | - $row, |
|
632 | - $ticket, |
|
633 | - $data |
|
634 | - ); |
|
635 | - } |
|
636 | - // DO ALL dtt relationships for both current tickets and any archived tickets |
|
637 | - // for the given dtt that are related to the current ticket. |
|
638 | - // TODO... not sure exactly how we're going to do this considering we don't know |
|
639 | - // what current ticket the archived tickets are related to |
|
640 | - // (and TKT_parent is used for autosaves so that's not a field we can reliably use). |
|
641 | - //let's assign any tickets that have been setup to the saved_tickets tracker |
|
642 | - //save existing TKT |
|
643 | - $ticket->save(); |
|
644 | - if ($create_new_TKT && $new_tkt instanceof EE_Ticket) { |
|
645 | - //save new TKT |
|
646 | - $new_tkt->save(); |
|
647 | - //add new ticket to array |
|
648 | - $saved_tickets[$new_tkt->ID()] = $new_tkt; |
|
649 | - do_action( |
|
650 | - 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket', |
|
651 | - $new_tkt, |
|
652 | - $row, |
|
653 | - $tkt, |
|
654 | - $data |
|
655 | - ); |
|
656 | - } else { |
|
657 | - //add tkt to saved tkts |
|
658 | - $saved_tickets[$ticket->ID()] = $ticket; |
|
659 | - do_action( |
|
660 | - 'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket', |
|
661 | - $ticket, |
|
662 | - $row, |
|
663 | - $tkt, |
|
664 | - $data |
|
665 | - ); |
|
666 | - } |
|
667 | - } |
|
668 | - // now we need to handle tickets actually "deleted permanently". |
|
669 | - // There are cases where we'd want this to happen |
|
670 | - // (i.e. autosaves are happening and then in between autosaves the user trashes a ticket). |
|
671 | - // Or a draft event was saved and in the process of editing a ticket is trashed. |
|
672 | - // No sense in keeping all the related data in the db! |
|
673 | - $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets; |
|
674 | - $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
675 | - foreach ($tickets_removed as $id) { |
|
676 | - $id = absint($id); |
|
677 | - //get the ticket for this id |
|
678 | - $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
679 | - //if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime |
|
680 | - if ($tkt_to_remove->get('TKT_is_default')) { |
|
681 | - continue; |
|
682 | - } |
|
683 | - // if this tkt has any registrations attached so then we just ARCHIVE |
|
684 | - // because we don't actually permanently delete these tickets. |
|
685 | - if ($tkt_to_remove->count_related('Registration') > 0) { |
|
686 | - $tkt_to_remove->delete(); |
|
687 | - continue; |
|
688 | - } |
|
689 | - // need to get all the related datetimes on this ticket and remove from every single one of them |
|
690 | - // (remember this process can ONLY kick off if there are NO tkts_sold) |
|
691 | - $datetimes = $tkt_to_remove->get_many_related('Datetime'); |
|
692 | - foreach ($datetimes as $datetime) { |
|
693 | - $tkt_to_remove->_remove_relation_to($datetime, 'Datetime'); |
|
694 | - } |
|
695 | - // need to do the same for prices (except these prices can also be deleted because again, |
|
696 | - // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
697 | - $tkt_to_remove->delete_related_permanently('Price'); |
|
698 | - do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove); |
|
699 | - // finally let's delete this ticket |
|
700 | - // (which should not be blocked at this point b/c we've removed all our relationships) |
|
701 | - $tkt_to_remove->delete_permanently(); |
|
702 | - } |
|
703 | - return $saved_tickets; |
|
704 | - } |
|
705 | - |
|
706 | - |
|
707 | - |
|
708 | - /** |
|
709 | - * @access protected |
|
710 | - * @param \EE_Ticket $ticket |
|
711 | - * @param \EE_Datetime[] $saved_datetimes |
|
712 | - * @param \EE_Datetime[] $added_datetimes |
|
713 | - * @param \EE_Datetime[] $removed_datetimes |
|
714 | - * @return \EE_Ticket |
|
715 | - * @throws \EE_Error |
|
716 | - */ |
|
717 | - protected function _update_ticket_datetimes( |
|
718 | - EE_Ticket $ticket, |
|
719 | - $saved_datetimes = array(), |
|
720 | - $added_datetimes = array(), |
|
721 | - $removed_datetimes = array() |
|
722 | - ) { |
|
723 | - // to start we have to add the ticket to all the datetimes its supposed to be with, |
|
724 | - // and removing the ticket from datetimes it got removed from. |
|
725 | - // first let's add datetimes |
|
726 | - if (! empty($added_datetimes) && is_array($added_datetimes)) { |
|
727 | - foreach ($added_datetimes as $row_id) { |
|
728 | - $row_id = (int)$row_id; |
|
729 | - if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
|
730 | - $ticket->_add_relation_to($saved_datetimes[$row_id], 'Datetime'); |
|
731 | - // Is this an existing ticket (has an ID) and does it have any sold? |
|
732 | - // If so, then we need to add that to the DTT sold because this DTT is getting added. |
|
733 | - if ($ticket->ID() && $ticket->sold() > 0) { |
|
734 | - $saved_datetimes[$row_id]->increase_sold($ticket->sold()); |
|
735 | - $saved_datetimes[$row_id]->save(); |
|
736 | - } |
|
737 | - } |
|
738 | - } |
|
739 | - } |
|
740 | - // then remove datetimes |
|
741 | - if (! empty($removed_datetimes) && is_array($removed_datetimes)) { |
|
742 | - foreach ($removed_datetimes as $row_id) { |
|
743 | - $row_id = (int)$row_id; |
|
744 | - // its entirely possible that a datetime got deleted (instead of just removed from relationship. |
|
745 | - // So make sure we skip over this if the dtt isn't in the $saved_datetimes array) |
|
746 | - if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
|
747 | - $ticket->_remove_relation_to($saved_datetimes[$row_id], 'Datetime'); |
|
748 | - // Is this an existing ticket (has an ID) and does it have any sold? |
|
749 | - // If so, then we need to remove it's sold from the DTT_sold. |
|
750 | - if ($ticket->ID() && $ticket->sold() > 0) { |
|
751 | - $saved_datetimes[$row_id]->decrease_sold($ticket->sold()); |
|
752 | - $saved_datetimes[$row_id]->save(); |
|
753 | - } |
|
754 | - } |
|
755 | - } |
|
756 | - } |
|
757 | - // cap ticket qty by datetime reg limits |
|
758 | - $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit'))); |
|
759 | - return $ticket; |
|
760 | - } |
|
761 | - |
|
762 | - |
|
763 | - |
|
764 | - /** |
|
765 | - * @access protected |
|
766 | - * @param \EE_Ticket $ticket |
|
767 | - * @param array $price_rows |
|
768 | - * @param int $ticket_price |
|
769 | - * @param int $base_price |
|
770 | - * @param int $base_price_id |
|
771 | - * @return \EE_Ticket |
|
772 | - * @throws \EE_Error |
|
773 | - */ |
|
774 | - protected function _duplicate_ticket( |
|
775 | - EE_Ticket $ticket, |
|
776 | - $price_rows = array(), |
|
777 | - $ticket_price = 0, |
|
778 | - $base_price = 0, |
|
779 | - $base_price_id = 0 |
|
780 | - ) { |
|
781 | - // create new ticket that's a copy of the existing |
|
782 | - // except a new id of course (and not archived) |
|
783 | - // AND has the new TKT_price associated with it. |
|
784 | - $new_ticket = clone $ticket; |
|
785 | - $new_ticket->set('TKT_ID', 0); |
|
786 | - $new_ticket->set_deleted(0); |
|
787 | - $new_ticket->set_price($ticket_price); |
|
788 | - $new_ticket->set_sold(0); |
|
789 | - // let's get a new ID for this ticket |
|
790 | - $new_ticket->save(); |
|
791 | - // we also need to make sure this new ticket gets the same datetime attachments as the archived ticket |
|
792 | - $datetimes_on_existing = $ticket->datetimes(); |
|
793 | - $new_ticket = $this->_update_ticket_datetimes( |
|
794 | - $new_ticket, |
|
795 | - $datetimes_on_existing, |
|
796 | - array_keys($datetimes_on_existing) |
|
797 | - ); |
|
798 | - // $ticket will get archived later b/c we are NOT adding it to the saved_tickets array. |
|
799 | - // if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining |
|
800 | - // available. |
|
801 | - if ($ticket->sold() > 0) { |
|
802 | - $new_qty = $ticket->qty() - $ticket->sold(); |
|
803 | - $new_ticket->set_qty($new_qty); |
|
804 | - } |
|
805 | - //now we update the prices just for this ticket |
|
806 | - $new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true); |
|
807 | - //and we update the base price |
|
808 | - $new_ticket = $this->_add_prices_to_ticket(array(), $new_ticket, true, $base_price, $base_price_id); |
|
809 | - return $new_ticket; |
|
810 | - } |
|
811 | - |
|
812 | - |
|
813 | - |
|
814 | - /** |
|
815 | - * This attaches a list of given prices to a ticket. |
|
816 | - * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
817 | - * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
818 | - * price info and prices are automatically "archived" via the ticket. |
|
819 | - * |
|
820 | - * @access private |
|
821 | - * @param array $prices Array of prices from the form. |
|
822 | - * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
823 | - * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
824 | - * @param int|bool $base_price if FALSE then NOT doing a base price add. |
|
825 | - * @param int|bool $base_price_id if present then this is the base_price_id being updated. |
|
826 | - * @return EE_Ticket |
|
827 | - * @throws EE_Error |
|
828 | - */ |
|
829 | - protected function _add_prices_to_ticket( |
|
830 | - $prices = array(), |
|
831 | - EE_Ticket $ticket, |
|
832 | - $new_prices = false, |
|
833 | - $base_price = false, |
|
834 | - $base_price_id = false |
|
835 | - ) { |
|
836 | - // let's just get any current prices that may exist on the given ticket |
|
837 | - // so we can remove any prices that got trashed in this session. |
|
838 | - $current_prices_on_ticket = $base_price !== false |
|
839 | - ? $ticket->base_price(true) |
|
840 | - : $ticket->price_modifiers(); |
|
841 | - $updated_prices = array(); |
|
842 | - // if $base_price ! FALSE then updating a base price. |
|
843 | - if ($base_price !== false) { |
|
844 | - $prices[1] = array( |
|
845 | - 'PRC_ID' => $new_prices || $base_price_id === 1 ? null : $base_price_id, |
|
846 | - 'PRT_ID' => 1, |
|
847 | - 'PRC_amount' => $base_price, |
|
848 | - 'PRC_name' => $ticket->get('TKT_name'), |
|
849 | - 'PRC_desc' => $ticket->get('TKT_description'), |
|
850 | - ); |
|
851 | - } |
|
852 | - //possibly need to save tkt |
|
853 | - if (! $ticket->ID()) { |
|
854 | - $ticket->save(); |
|
855 | - } |
|
856 | - foreach ($prices as $row => $prc) { |
|
857 | - $prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null; |
|
858 | - if (empty($prt_id)) { |
|
859 | - continue; |
|
860 | - } //prices MUST have a price type id. |
|
861 | - $PRC_values = array( |
|
862 | - 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
863 | - 'PRT_ID' => $prt_id, |
|
864 | - 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
865 | - 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
866 | - 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
867 | - 'PRC_is_default' => false, |
|
868 | - //make sure we set PRC_is_default to false for all ticket saves from event_editor |
|
869 | - 'PRC_order' => $row, |
|
870 | - ); |
|
871 | - if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
872 | - $PRC_values['PRC_ID'] = 0; |
|
873 | - $price = EE_Registry::instance()->load_class( |
|
874 | - 'Price', |
|
875 | - array($PRC_values), |
|
876 | - false, |
|
877 | - false |
|
878 | - ); |
|
879 | - } else { |
|
880 | - $price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
881 | - //update this price with new values |
|
882 | - foreach ($PRC_values as $field => $value) { |
|
883 | - $price->set($field, $value); |
|
884 | - } |
|
885 | - } |
|
886 | - $price->save(); |
|
887 | - $updated_prices[$price->ID()] = $price; |
|
888 | - $ticket->_add_relation_to($price, 'Price'); |
|
889 | - } |
|
890 | - //now let's remove any prices that got removed from the ticket |
|
891 | - if (! empty ($current_prices_on_ticket)) { |
|
892 | - $current = array_keys($current_prices_on_ticket); |
|
893 | - $updated = array_keys($updated_prices); |
|
894 | - $prices_to_remove = array_diff($current, $updated); |
|
895 | - if (! empty($prices_to_remove)) { |
|
896 | - foreach ($prices_to_remove as $prc_id) { |
|
897 | - $p = $current_prices_on_ticket[$prc_id]; |
|
898 | - $ticket->_remove_relation_to($p, 'Price'); |
|
899 | - //delete permanently the price |
|
900 | - $p->delete_permanently(); |
|
901 | - } |
|
902 | - } |
|
903 | - } |
|
904 | - return $ticket; |
|
905 | - } |
|
906 | - |
|
907 | - |
|
908 | - |
|
909 | - /** |
|
910 | - * @param Events_Admin_Page $event_admin_obj |
|
911 | - * @return Events_Admin_Page |
|
912 | - */ |
|
913 | - public function autosave_handling( Events_Admin_Page $event_admin_obj) |
|
914 | - { |
|
915 | - return $event_admin_obj; |
|
916 | - //doing nothing for the moment. |
|
917 | - // todo when I get to this remember that I need to set the template args on the $event_admin_obj |
|
918 | - // (use the set_template_args() method) |
|
919 | - /** |
|
920 | - * need to remember to handle TICKET DEFAULT saves correctly: I've got two input fields in the dom: |
|
921 | - * 1. TKT_is_default_selector (visible) |
|
922 | - * 2. TKT_is_default (hidden) |
|
923 | - * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket |
|
924 | - * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want |
|
925 | - * this ticket to be saved as a default. |
|
926 | - * The tricky part is, on an initial display on create or edit (or after manually updating), |
|
927 | - * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true |
|
928 | - * if this is a create. However, after an autosave, users will want some sort of indicator that |
|
929 | - * the TKT HAS been saved as a default.. |
|
930 | - * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking. |
|
931 | - * On Autosave: |
|
932 | - * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements, |
|
933 | - * then set the TKT_is_default to false. |
|
934 | - * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well). |
|
935 | - * We do NOT create a new default ticket. The checkbox stays selected after autosave. |
|
936 | - * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket. |
|
937 | - */ |
|
938 | - } |
|
939 | - |
|
940 | - |
|
941 | - |
|
942 | - /** |
|
943 | - * @throws DomainException |
|
944 | - * @throws EE_Error |
|
945 | - */ |
|
946 | - public function pricing_metabox() |
|
947 | - { |
|
948 | - $existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array(); |
|
949 | - $event = $this->_adminpage_obj->get_cpt_model_obj(); |
|
950 | - //set is_creating_event property. |
|
951 | - $EVT_ID = $event->ID(); |
|
952 | - $this->_is_creating_event = absint($EVT_ID) === 0; |
|
953 | - //default main template args |
|
954 | - $main_template_args = array( |
|
955 | - 'event_datetime_help_link' => EEH_Template::get_help_tab_link( |
|
956 | - 'event_editor_event_datetimes_help_tab', |
|
957 | - $this->_adminpage_obj->page_slug, |
|
958 | - $this->_adminpage_obj->get_req_action(), |
|
959 | - false, |
|
960 | - false |
|
961 | - ), |
|
962 | - // todo need to add a filter to the template for the help text |
|
963 | - // in the Events_Admin_Page core file so we can add further help |
|
964 | - 'existing_datetime_ids' => '', |
|
965 | - 'total_dtt_rows' => 1, |
|
966 | - 'add_new_dtt_help_link' => EEH_Template::get_help_tab_link( |
|
967 | - 'add_new_dtt_info', |
|
968 | - $this->_adminpage_obj->page_slug, |
|
969 | - $this->_adminpage_obj->get_req_action(), |
|
970 | - false, |
|
971 | - false |
|
972 | - ), |
|
973 | - //todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
974 | - 'datetime_rows' => '', |
|
975 | - 'show_tickets_container' => '', |
|
976 | - //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '', |
|
977 | - 'ticket_rows' => '', |
|
978 | - 'existing_ticket_ids' => '', |
|
979 | - 'total_ticket_rows' => 1, |
|
980 | - 'ticket_js_structure' => '', |
|
981 | - 'ee_collapsible_status' => ' ee-collapsible-open' |
|
982 | - //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open' |
|
983 | - ); |
|
984 | - $timezone = $event instanceof EE_Event ? $event->timezone_string() : null; |
|
985 | - do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
986 | - /** |
|
987 | - * 1. Start with retrieving Datetimes |
|
988 | - * 2. For each datetime get related tickets |
|
989 | - * 3. For each ticket get related prices |
|
990 | - */ |
|
991 | - /** @var EEM_Datetime $datetime_model */ |
|
992 | - $datetime_model = EE_Registry::instance()->load_model('Datetime', array($timezone)); |
|
993 | - $datetimes = $datetime_model->get_all_event_dates($EVT_ID); |
|
994 | - $main_template_args['total_dtt_rows'] = count($datetimes); |
|
995 | - /** |
|
996 | - * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486 |
|
997 | - * for why we are counting $datetime_row and then setting that on the Datetime object |
|
998 | - */ |
|
999 | - $datetime_row = 1; |
|
1000 | - foreach ($datetimes as $datetime) { |
|
1001 | - $DTT_ID = $datetime->get('DTT_ID'); |
|
1002 | - $datetime->set('DTT_order', $datetime_row); |
|
1003 | - $existing_datetime_ids[] = $DTT_ID; |
|
1004 | - //tickets attached |
|
1005 | - $related_tickets = $datetime->ID() > 0 |
|
1006 | - ? $datetime->get_many_related( |
|
1007 | - 'Ticket', |
|
1008 | - array( |
|
1009 | - array( |
|
1010 | - 'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0), |
|
1011 | - ), |
|
1012 | - 'default_where_conditions' => 'none', |
|
1013 | - 'order_by' => array('TKT_order' => 'ASC'), |
|
1014 | - ) |
|
1015 | - ) |
|
1016 | - : array(); |
|
1017 | - //if there are no related tickets this is likely a new event OR autodraft |
|
1018 | - // event so we need to generate the default tickets because datetimes |
|
1019 | - // ALWAYS have at least one related ticket!!. EXCEPT, we dont' do this if there is already more than one |
|
1020 | - // datetime on the event. |
|
1021 | - if (empty ($related_tickets) && count($datetimes) < 2) { |
|
1022 | - /** @var EEM_Ticket $ticket_model */ |
|
1023 | - $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
1024 | - $related_tickets = $ticket_model->get_all_default_tickets(); |
|
1025 | - // this should be ordered by TKT_ID, so let's grab the first default ticket |
|
1026 | - // (which will be the main default) and ensure it has any default prices added to it (but do NOT save). |
|
1027 | - $default_prices = EEM_Price::instance()->get_all_default_prices(); |
|
1028 | - $main_default_ticket = reset($related_tickets); |
|
1029 | - if ($main_default_ticket instanceof EE_Ticket) { |
|
1030 | - foreach ($default_prices as $default_price) { |
|
1031 | - if ($default_price instanceof EE_Price && $default_price->is_base_price()) { |
|
1032 | - continue; |
|
1033 | - } |
|
1034 | - $main_default_ticket->cache('Price', $default_price); |
|
1035 | - } |
|
1036 | - } |
|
1037 | - } |
|
1038 | - // we can't actually setup rows in this loop yet cause we don't know all |
|
1039 | - // the unique tickets for this event yet (tickets are linked through all datetimes). |
|
1040 | - // So we're going to temporarily cache some of that information. |
|
1041 | - //loop through and setup the ticket rows and make sure the order is set. |
|
1042 | - foreach ($related_tickets as $ticket) { |
|
1043 | - $TKT_ID = $ticket->get('TKT_ID'); |
|
1044 | - $ticket_row = $ticket->get('TKT_row'); |
|
1045 | - //we only want unique tickets in our final display!! |
|
1046 | - if (! in_array($TKT_ID, $existing_ticket_ids, true)) { |
|
1047 | - $existing_ticket_ids[] = $TKT_ID; |
|
1048 | - $all_tickets[] = $ticket; |
|
1049 | - } |
|
1050 | - //temporary cache of this ticket info for this datetime for later processing of datetime rows. |
|
1051 | - $datetime_tickets[$DTT_ID][] = $ticket_row; |
|
1052 | - //temporary cache of this datetime info for this ticket for later processing of ticket rows. |
|
1053 | - if ( |
|
1054 | - ! isset($ticket_datetimes[$TKT_ID]) |
|
1055 | - || ! in_array($datetime_row, $ticket_datetimes[$TKT_ID], true) |
|
1056 | - ) { |
|
1057 | - $ticket_datetimes[$TKT_ID][] = $datetime_row; |
|
1058 | - } |
|
1059 | - } |
|
1060 | - $datetime_row++; |
|
1061 | - } |
|
1062 | - $main_template_args['total_ticket_rows'] = count($existing_ticket_ids); |
|
1063 | - $main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
1064 | - $main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
1065 | - //sort $all_tickets by order |
|
1066 | - usort( |
|
1067 | - $all_tickets, |
|
1068 | - function (EE_Ticket $a, EE_Ticket $b) { |
|
1069 | - $a_order = (int)$a->get('TKT_order'); |
|
1070 | - $b_order = (int)$b->get('TKT_order'); |
|
1071 | - if ($a_order === $b_order) { |
|
1072 | - return 0; |
|
1073 | - } |
|
1074 | - return ($a_order < $b_order) ? -1 : 1; |
|
1075 | - } |
|
1076 | - ); |
|
1077 | - // k NOW we have all the data we need for setting up the dtt rows |
|
1078 | - // and ticket rows so we start our dtt loop again. |
|
1079 | - $datetime_row = 1; |
|
1080 | - foreach ($datetimes as $datetime) { |
|
1081 | - $main_template_args['datetime_rows'] .= $this->_get_datetime_row( |
|
1082 | - $datetime_row, |
|
1083 | - $datetime, |
|
1084 | - $datetime_tickets, |
|
1085 | - $all_tickets, |
|
1086 | - false, |
|
1087 | - $datetimes |
|
1088 | - ); |
|
1089 | - $datetime_row++; |
|
1090 | - } |
|
1091 | - //then loop through all tickets for the ticket rows. |
|
1092 | - $ticket_row = 1; |
|
1093 | - foreach ($all_tickets as $ticket) { |
|
1094 | - $main_template_args['ticket_rows'] .= $this->_get_ticket_row( |
|
1095 | - $ticket_row, |
|
1096 | - $ticket, |
|
1097 | - $ticket_datetimes, |
|
1098 | - $datetimes, |
|
1099 | - false, |
|
1100 | - $all_tickets |
|
1101 | - ); |
|
1102 | - $ticket_row++; |
|
1103 | - } |
|
1104 | - $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets); |
|
1105 | - EEH_Template::display_template( |
|
1106 | - PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php', |
|
1107 | - $main_template_args |
|
1108 | - ); |
|
1109 | - } |
|
1110 | - |
|
1111 | - |
|
1112 | - |
|
1113 | - /** |
|
1114 | - * @param int $datetime_row |
|
1115 | - * @param EE_Datetime $datetime |
|
1116 | - * @param array $datetime_tickets |
|
1117 | - * @param array $all_tickets |
|
1118 | - * @param bool $default |
|
1119 | - * @param array $all_datetimes |
|
1120 | - * @return mixed |
|
1121 | - * @throws DomainException |
|
1122 | - * @throws EE_Error |
|
1123 | - */ |
|
1124 | - protected function _get_datetime_row( |
|
1125 | - $datetime_row, |
|
1126 | - EE_Datetime $datetime, |
|
1127 | - $datetime_tickets = array(), |
|
1128 | - $all_tickets = array(), |
|
1129 | - $default = false, |
|
1130 | - $all_datetimes = array() |
|
1131 | - ) { |
|
1132 | - $dtt_display_template_args = array( |
|
1133 | - 'dtt_edit_row' => $this->_get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes), |
|
1134 | - 'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row( |
|
1135 | - $datetime_row, |
|
1136 | - $datetime, |
|
1137 | - $datetime_tickets, |
|
1138 | - $all_tickets, |
|
1139 | - $default |
|
1140 | - ), |
|
1141 | - 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
1142 | - ); |
|
1143 | - return EEH_Template::display_template( |
|
1144 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php', |
|
1145 | - $dtt_display_template_args, |
|
1146 | - true |
|
1147 | - ); |
|
1148 | - } |
|
1149 | - |
|
1150 | - |
|
1151 | - |
|
1152 | - /** |
|
1153 | - * This method is used to generate a dtt fields edit row. |
|
1154 | - * The same row is used to generate a row with valid DTT objects |
|
1155 | - * and the default row that is used as the skeleton by the js. |
|
1156 | - * |
|
1157 | - * @param int $datetime_row The row number for the row being generated. |
|
1158 | - * @param EE_Datetime $datetime |
|
1159 | - * @param bool $default Whether a default row is being generated or not. |
|
1160 | - * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor. |
|
1161 | - * @return string |
|
1162 | - * @throws DomainException |
|
1163 | - * @throws EE_Error |
|
1164 | - */ |
|
1165 | - protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes) |
|
1166 | - { |
|
1167 | - // if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true. |
|
1168 | - $default = ! $datetime instanceof EE_Datetime ? true : $default; |
|
1169 | - $template_args = array( |
|
1170 | - 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
1171 | - 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
1172 | - 'edit_dtt_expanded' => '', |
|
1173 | - 'DTT_ID' => $default ? '' : $datetime->ID(), |
|
1174 | - 'DTT_name' => $default ? '' : $datetime->name(), |
|
1175 | - 'DTT_description' => $default ? '' : $datetime->description(), |
|
1176 | - 'DTT_EVT_start' => $default ? '' : $datetime->start_date($this->_date_time_format), |
|
1177 | - 'DTT_EVT_end' => $default ? '' : $datetime->end_date($this->_date_time_format), |
|
1178 | - 'DTT_reg_limit' => $default |
|
1179 | - ? '' |
|
1180 | - : $datetime->get_pretty( |
|
1181 | - 'DTT_reg_limit', |
|
1182 | - 'input' |
|
1183 | - ), |
|
1184 | - 'DTT_order' => $default ? 'DTTNUM' : $datetime_row, |
|
1185 | - 'dtt_sold' => $default ? '0' : $datetime->get('DTT_sold'), |
|
1186 | - 'dtt_reserved' => $default ? '0' : $datetime->reserved(), |
|
1187 | - 'clone_icon' => ! empty($datetime) && $datetime->get('DTT_sold') > 0 |
|
1188 | - ? '' |
|
1189 | - : 'clone-icon ee-icon ee-icon-clone clickable', |
|
1190 | - 'trash_icon' => ! empty($datetime) && $datetime->get('DTT_sold') > 0 |
|
1191 | - ? 'ee-lock-icon' |
|
1192 | - : 'trash-icon dashicons dashicons-post-trash clickable', |
|
1193 | - 'reg_list_url' => $default || ! $datetime->event() instanceof \EE_Event |
|
1194 | - ? '' |
|
1195 | - : EE_Admin_Page::add_query_args_and_nonce( |
|
1196 | - array('event_id' => $datetime->event()->ID(), 'datetime_id' => $datetime->ID()), |
|
1197 | - REG_ADMIN_URL |
|
1198 | - ), |
|
1199 | - ); |
|
1200 | - $template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' |
|
1201 | - ? ' style="display:none"' |
|
1202 | - : ''; |
|
1203 | - //allow filtering of template args at this point. |
|
1204 | - $template_args = apply_filters( |
|
1205 | - 'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args', |
|
1206 | - $template_args, |
|
1207 | - $datetime_row, |
|
1208 | - $datetime, |
|
1209 | - $default, |
|
1210 | - $all_datetimes, |
|
1211 | - $this->_is_creating_event |
|
1212 | - ); |
|
1213 | - return EEH_Template::display_template( |
|
1214 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php', |
|
1215 | - $template_args, |
|
1216 | - true |
|
1217 | - ); |
|
1218 | - } |
|
1219 | - |
|
1220 | - |
|
1221 | - |
|
1222 | - /** |
|
1223 | - * @param int $datetime_row |
|
1224 | - * @param EE_Datetime $datetime |
|
1225 | - * @param array $datetime_tickets |
|
1226 | - * @param array $all_tickets |
|
1227 | - * @param bool $default |
|
1228 | - * @return mixed |
|
1229 | - * @throws DomainException |
|
1230 | - * @throws EE_Error |
|
1231 | - */ |
|
1232 | - protected function _get_dtt_attached_tickets_row( |
|
1233 | - $datetime_row, |
|
1234 | - $datetime, |
|
1235 | - $datetime_tickets = array(), |
|
1236 | - $all_tickets = array(), |
|
1237 | - $default |
|
1238 | - ) { |
|
1239 | - $template_args = array( |
|
1240 | - 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
1241 | - 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
1242 | - 'DTT_description' => $default ? '' : $datetime->description(), |
|
1243 | - 'datetime_tickets_list' => $default ? '<li class="hidden"></li>' : '', |
|
1244 | - 'show_tickets_row' => ' style="display:none;"', |
|
1245 | - 'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link( |
|
1246 | - 'add_new_ticket_via_datetime', |
|
1247 | - $this->_adminpage_obj->page_slug, |
|
1248 | - $this->_adminpage_obj->get_req_action(), |
|
1249 | - false, |
|
1250 | - false |
|
1251 | - ), |
|
1252 | - //todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
1253 | - 'DTT_ID' => $default ? '' : $datetime->ID(), |
|
1254 | - ); |
|
1255 | - //need to setup the list items (but only if this isn't a default skeleton setup) |
|
1256 | - if (! $default) { |
|
1257 | - $ticket_row = 1; |
|
1258 | - foreach ($all_tickets as $ticket) { |
|
1259 | - $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
|
1260 | - $datetime_row, |
|
1261 | - $ticket_row, |
|
1262 | - $datetime, |
|
1263 | - $ticket, |
|
1264 | - $datetime_tickets, |
|
1265 | - $default |
|
1266 | - ); |
|
1267 | - $ticket_row++; |
|
1268 | - } |
|
1269 | - } |
|
1270 | - //filter template args at this point |
|
1271 | - $template_args = apply_filters( |
|
1272 | - 'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args', |
|
1273 | - $template_args, |
|
1274 | - $datetime_row, |
|
1275 | - $datetime, |
|
1276 | - $datetime_tickets, |
|
1277 | - $all_tickets, |
|
1278 | - $default, |
|
1279 | - $this->_is_creating_event |
|
1280 | - ); |
|
1281 | - return EEH_Template::display_template( |
|
1282 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php', |
|
1283 | - $template_args, |
|
1284 | - true |
|
1285 | - ); |
|
1286 | - } |
|
1287 | - |
|
1288 | - |
|
1289 | - |
|
1290 | - /** |
|
1291 | - * @param int $datetime_row |
|
1292 | - * @param int $ticket_row |
|
1293 | - * @param EE_Datetime $datetime |
|
1294 | - * @param EE_Ticket $ticket |
|
1295 | - * @param array $datetime_tickets |
|
1296 | - * @param bool $default |
|
1297 | - * @return mixed |
|
1298 | - * @throws DomainException |
|
1299 | - * @throws EE_Error |
|
1300 | - */ |
|
1301 | - protected function _get_datetime_tickets_list_item( |
|
1302 | - $datetime_row, |
|
1303 | - $ticket_row, |
|
1304 | - $datetime, |
|
1305 | - $ticket, |
|
1306 | - $datetime_tickets = array(), |
|
1307 | - $default |
|
1308 | - ) { |
|
1309 | - $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[$datetime->ID()]) |
|
1310 | - ? $datetime_tickets[$datetime->ID()] |
|
1311 | - : array(); |
|
1312 | - $display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0; |
|
1313 | - $no_ticket = $default && empty($ticket); |
|
1314 | - $template_args = array( |
|
1315 | - 'dtt_row' => $default |
|
1316 | - ? 'DTTNUM' |
|
1317 | - : $datetime_row, |
|
1318 | - 'tkt_row' => $no_ticket |
|
1319 | - ? 'TICKETNUM' |
|
1320 | - : $ticket_row, |
|
1321 | - 'datetime_ticket_checked' => in_array($display_row, $dtt_tkts, true) |
|
1322 | - ? ' checked="checked"' |
|
1323 | - : '', |
|
1324 | - 'ticket_selected' => in_array($display_row, $dtt_tkts, true) |
|
1325 | - ? ' ticket-selected' |
|
1326 | - : '', |
|
1327 | - 'TKT_name' => $no_ticket |
|
1328 | - ? 'TKTNAME' |
|
1329 | - : $ticket->get('TKT_name'), |
|
1330 | - 'tkt_status_class' => $no_ticket || $this->_is_creating_event |
|
1331 | - ? ' tkt-status-' . EE_Ticket::onsale |
|
1332 | - : ' tkt-status-' . $ticket->ticket_status(), |
|
1333 | - ); |
|
1334 | - //filter template args |
|
1335 | - $template_args = apply_filters( |
|
1336 | - 'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args', |
|
1337 | - $template_args, |
|
1338 | - $datetime_row, |
|
1339 | - $ticket_row, |
|
1340 | - $datetime, |
|
1341 | - $ticket, |
|
1342 | - $datetime_tickets, |
|
1343 | - $default, |
|
1344 | - $this->_is_creating_event |
|
1345 | - ); |
|
1346 | - return EEH_Template::display_template( |
|
1347 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php', |
|
1348 | - $template_args, |
|
1349 | - true |
|
1350 | - ); |
|
1351 | - } |
|
1352 | - |
|
1353 | - |
|
1354 | - |
|
1355 | - /** |
|
1356 | - * This generates the ticket row for tickets. |
|
1357 | - * This same method is used to generate both the actual rows and the js skeleton row |
|
1358 | - * (when default === true) |
|
1359 | - * |
|
1360 | - * @param int $ticket_row Represents the row number being generated. |
|
1361 | - * @param $ticket |
|
1362 | - * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket |
|
1363 | - * or empty for default |
|
1364 | - * @param EE_Datetime[] $all_datetimes All Datetimes on the event or empty for default. |
|
1365 | - * @param bool $default Whether default row being generated or not. |
|
1366 | - * @param EE_Ticket[] $all_tickets This is an array of all tickets attached to the event |
|
1367 | - * (or empty in the case of defaults) |
|
1368 | - * @return mixed |
|
1369 | - * @throws DomainException |
|
1370 | - * @throws EE_Error |
|
1371 | - */ |
|
1372 | - protected function _get_ticket_row( |
|
1373 | - $ticket_row, |
|
1374 | - $ticket, |
|
1375 | - $ticket_datetimes, |
|
1376 | - $all_datetimes, |
|
1377 | - $default = false, |
|
1378 | - $all_tickets = array() |
|
1379 | - ) { |
|
1380 | - // if $ticket is not an instance of EE_Ticket then force default to true. |
|
1381 | - $default = ! $ticket instanceof EE_Ticket ? true : $default; |
|
1382 | - $prices = ! empty($ticket) && ! $default ? $ticket->get_many_related('Price', |
|
1383 | - array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC'))) : array(); |
|
1384 | - // if there is only one price (which would be the base price) |
|
1385 | - // or NO prices and this ticket is a default ticket, |
|
1386 | - // let's just make sure there are no cached default prices on the object. |
|
1387 | - // This is done by not including any query_params. |
|
1388 | - if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) { |
|
1389 | - $prices = $ticket->prices(); |
|
1390 | - } |
|
1391 | - // check if we're dealing with a default ticket in which case |
|
1392 | - // we don't want any starting_ticket_datetime_row values set |
|
1393 | - // (otherwise there won't be any new relationships created for tickets based off of the default ticket). |
|
1394 | - // This will future proof in case there is ever any behaviour change between what the primary_key defaults to. |
|
1395 | - $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->is_default()); |
|
1396 | - $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) |
|
1397 | - ? $ticket_datetimes[$ticket->ID()] |
|
1398 | - : array(); |
|
1399 | - $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal(); |
|
1400 | - $base_price = $default ? null : $ticket->base_price(); |
|
1401 | - $count_price_mods = EEM_Price::instance()->get_all_default_prices(true); |
|
1402 | - //breaking out complicated condition for ticket_status |
|
1403 | - if ($default) { |
|
1404 | - $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale; |
|
1405 | - } else { |
|
1406 | - $ticket_status_class = $ticket->is_default() |
|
1407 | - ? ' tkt-status-' . EE_Ticket::onsale |
|
1408 | - : ' tkt-status-' . $ticket->ticket_status(); |
|
1409 | - } |
|
1410 | - //breaking out complicated condition for TKT_taxable |
|
1411 | - if ($default) { |
|
1412 | - $TKT_taxable = ''; |
|
1413 | - } else { |
|
1414 | - $TKT_taxable = $ticket->taxable() |
|
1415 | - ? ' checked="checked"' |
|
1416 | - : ''; |
|
1417 | - } |
|
1418 | - if ($default) { |
|
1419 | - $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence'); |
|
1420 | - } elseif ($ticket->is_default()) { |
|
1421 | - $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence'); |
|
1422 | - } else { |
|
1423 | - $TKT_status = $ticket->ticket_status(true); |
|
1424 | - } |
|
1425 | - if ($default) { |
|
1426 | - $TKT_min = ''; |
|
1427 | - } else { |
|
1428 | - $TKT_min = $ticket->min(); |
|
1429 | - if ($TKT_min === -1 || $TKT_min === 0) { |
|
1430 | - $TKT_min = ''; |
|
1431 | - } |
|
1432 | - } |
|
1433 | - $template_args = array( |
|
1434 | - 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
1435 | - 'TKT_order' => $default ? 'TICKETNUM' : $ticket_row, |
|
1436 | - //on initial page load this will always be the correct order. |
|
1437 | - 'tkt_status_class' => $ticket_status_class, |
|
1438 | - 'display_edit_tkt_row' => ' style="display:none;"', |
|
1439 | - 'edit_tkt_expanded' => '', |
|
1440 | - 'edit_tickets_name' => $default ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
1441 | - 'TKT_name' => $default ? '' : $ticket->name(), |
|
1442 | - 'TKT_start_date' => $default |
|
1443 | - ? '' |
|
1444 | - : $ticket->get_date('TKT_start_date', $this->_date_time_format), |
|
1445 | - 'TKT_end_date' => $default |
|
1446 | - ? '' |
|
1447 | - : $ticket->get_date('TKT_end_date', $this->_date_time_format), |
|
1448 | - 'TKT_status' => $TKT_status, |
|
1449 | - 'TKT_price' => $default |
|
1450 | - ? '' |
|
1451 | - : EEH_Template::format_currency( |
|
1452 | - $ticket->get_ticket_total_with_taxes(), |
|
1453 | - false, |
|
1454 | - false |
|
1455 | - ), |
|
1456 | - 'TKT_price_code' => EE_Registry::instance()->CFG->currency->code, |
|
1457 | - 'TKT_price_amount' => $default ? 0 : $ticket_subtotal, |
|
1458 | - 'TKT_qty' => $default |
|
1459 | - ? '' |
|
1460 | - : $ticket->get_pretty('TKT_qty', 'symbol'), |
|
1461 | - 'TKT_qty_for_input' => $default |
|
1462 | - ? '' |
|
1463 | - : $ticket->get_pretty('TKT_qty', 'input'), |
|
1464 | - 'TKT_uses' => $default |
|
1465 | - ? '' |
|
1466 | - : $ticket->get_pretty('TKT_uses', 'input'), |
|
1467 | - 'TKT_min' => $TKT_min, |
|
1468 | - 'TKT_max' => $default |
|
1469 | - ? '' |
|
1470 | - : $ticket->get_pretty('TKT_max', 'input'), |
|
1471 | - 'TKT_sold' => $default ? 0 : $ticket->tickets_sold('ticket'), |
|
1472 | - 'TKT_reserved' => $default ? 0 : $ticket->reserved(), |
|
1473 | - 'TKT_registrations' => $default |
|
1474 | - ? 0 |
|
1475 | - : $ticket->count_registrations( |
|
1476 | - array( |
|
1477 | - array( |
|
1478 | - 'STS_ID' => array( |
|
1479 | - '!=', |
|
1480 | - EEM_Registration::status_id_incomplete, |
|
1481 | - ), |
|
1482 | - ), |
|
1483 | - ) |
|
1484 | - ), |
|
1485 | - 'TKT_ID' => $default ? 0 : $ticket->ID(), |
|
1486 | - 'TKT_description' => $default ? '' : $ticket->description(), |
|
1487 | - 'TKT_is_default' => $default ? 0 : $ticket->is_default(), |
|
1488 | - 'TKT_required' => $default ? 0 : $ticket->required(), |
|
1489 | - 'TKT_is_default_selector' => '', |
|
1490 | - 'ticket_price_rows' => '', |
|
1491 | - 'TKT_base_price' => $default || ! $base_price instanceof EE_Price |
|
1492 | - ? '' |
|
1493 | - : $base_price->get_pretty('PRC_amount', 'localized_float'), |
|
1494 | - 'TKT_base_price_ID' => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(), |
|
1495 | - 'show_price_modifier' => count($prices) > 1 || ($default && $count_price_mods > 0) |
|
1496 | - ? '' |
|
1497 | - : ' style="display:none;"', |
|
1498 | - 'show_price_mod_button' => count($prices) > 1 |
|
1499 | - || ($default && $count_price_mods > 0) |
|
1500 | - || (! $default && $ticket->deleted()) |
|
1501 | - ? ' style="display:none;"' |
|
1502 | - : '', |
|
1503 | - 'total_price_rows' => count($prices) > 1 ? count($prices) : 1, |
|
1504 | - 'ticket_datetimes_list' => $default ? '<li class="hidden"></li>' : '', |
|
1505 | - 'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_datetimes), |
|
1506 | - 'ticket_datetime_rows' => $default ? '' : implode(',', $tkt_datetimes), |
|
1507 | - 'existing_ticket_price_ids' => $default ? '' : implode(',', array_keys($prices)), |
|
1508 | - 'ticket_template_id' => $default ? 0 : $ticket->get('TTM_ID'), |
|
1509 | - 'TKT_taxable' => $TKT_taxable, |
|
1510 | - 'display_subtotal' => $ticket instanceof EE_Ticket && $ticket->taxable() |
|
1511 | - ? '' |
|
1512 | - : ' style="display:none"', |
|
1513 | - 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
1514 | - 'TKT_subtotal_amount_display' => EEH_Template::format_currency( |
|
1515 | - $ticket_subtotal, |
|
1516 | - false, |
|
1517 | - false |
|
1518 | - ), |
|
1519 | - 'TKT_subtotal_amount' => $ticket_subtotal, |
|
1520 | - 'tax_rows' => $this->_get_tax_rows($ticket_row, $ticket), |
|
1521 | - 'disabled' => $ticket instanceof EE_Ticket && $ticket->deleted(), |
|
1522 | - 'ticket_archive_class' => $ticket instanceof EE_Ticket && $ticket->deleted() |
|
1523 | - ? ' ticket-archived' |
|
1524 | - : '', |
|
1525 | - 'trash_icon' => $ticket instanceof EE_Ticket |
|
1526 | - && $ticket->deleted() |
|
1527 | - && ! $ticket->is_permanently_deleteable() |
|
1528 | - ? 'ee-lock-icon ' |
|
1529 | - : 'trash-icon dashicons dashicons-post-trash clickable', |
|
1530 | - 'clone_icon' => $ticket instanceof EE_Ticket && $ticket->deleted() |
|
1531 | - ? '' |
|
1532 | - : 'clone-icon ee-icon ee-icon-clone clickable', |
|
1533 | - ); |
|
1534 | - $template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' |
|
1535 | - ? ' style="display:none"' |
|
1536 | - : ''; |
|
1537 | - //handle rows that should NOT be empty |
|
1538 | - if (empty($template_args['TKT_start_date'])) { |
|
1539 | - //if empty then the start date will be now. |
|
1540 | - $template_args['TKT_start_date'] = date($this->_date_time_format, |
|
1541 | - current_time('timestamp')); |
|
1542 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
1543 | - } |
|
1544 | - if (empty($template_args['TKT_end_date'])) { |
|
1545 | - //get the earliest datetime (if present); |
|
1546 | - $earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 |
|
1547 | - ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related( |
|
1548 | - 'Datetime', |
|
1549 | - array('order_by' => array('DTT_EVT_start' => 'ASC')) |
|
1550 | - ) |
|
1551 | - : null; |
|
1552 | - if (! empty($earliest_dtt)) { |
|
1553 | - $template_args['TKT_end_date'] = $earliest_dtt->get_datetime( |
|
1554 | - 'DTT_EVT_start', |
|
1555 | - $this->_date_time_format |
|
1556 | - ); |
|
1557 | - } else { |
|
1558 | - //default so let's just use what's been set for the default date-time which is 30 days from now. |
|
1559 | - $template_args['TKT_end_date'] = date( |
|
1560 | - $this->_date_time_format, |
|
1561 | - mktime(24, 0, 0, date('m'), date('d') + 29, date('Y') |
|
1562 | - ) |
|
1563 | - ); |
|
1564 | - } |
|
1565 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
1566 | - } |
|
1567 | - //generate ticket_datetime items |
|
1568 | - if (! $default) { |
|
1569 | - $datetime_row = 1; |
|
1570 | - foreach ($all_datetimes as $datetime) { |
|
1571 | - $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
|
1572 | - $datetime_row, |
|
1573 | - $ticket_row, |
|
1574 | - $datetime, |
|
1575 | - $ticket, |
|
1576 | - $ticket_datetimes, |
|
1577 | - $default |
|
1578 | - ); |
|
1579 | - $datetime_row++; |
|
1580 | - } |
|
1581 | - } |
|
1582 | - $price_row = 1; |
|
1583 | - foreach ($prices as $price) { |
|
1584 | - if (! $price instanceof EE_Price) { |
|
1585 | - continue; |
|
1586 | - } |
|
1587 | - if ($price->is_base_price()) { |
|
1588 | - $price_row++; |
|
1589 | - continue; |
|
1590 | - } |
|
1591 | - $show_trash = !((count($prices) > 1 && $price_row === 1) || count($prices) === 1); |
|
1592 | - $show_create = !(count($prices) > 1 && count($prices) !== $price_row); |
|
1593 | - $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row( |
|
1594 | - $ticket_row, |
|
1595 | - $price_row, |
|
1596 | - $price, |
|
1597 | - $default, |
|
1598 | - $ticket, |
|
1599 | - $show_trash, |
|
1600 | - $show_create |
|
1601 | - ); |
|
1602 | - $price_row++; |
|
1603 | - } |
|
1604 | - //filter $template_args |
|
1605 | - $template_args = apply_filters( |
|
1606 | - 'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args', |
|
1607 | - $template_args, |
|
1608 | - $ticket_row, |
|
1609 | - $ticket, |
|
1610 | - $ticket_datetimes, |
|
1611 | - $all_datetimes, |
|
1612 | - $default, |
|
1613 | - $all_tickets, |
|
1614 | - $this->_is_creating_event |
|
1615 | - ); |
|
1616 | - return EEH_Template::display_template( |
|
1617 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php', |
|
1618 | - $template_args, |
|
1619 | - true |
|
1620 | - ); |
|
1621 | - } |
|
1622 | - |
|
1623 | - |
|
1624 | - |
|
1625 | - /** |
|
1626 | - * @param int $ticket_row |
|
1627 | - * @param EE_Ticket|null $ticket |
|
1628 | - * @return string |
|
1629 | - * @throws DomainException |
|
1630 | - * @throws EE_Error |
|
1631 | - */ |
|
1632 | - protected function _get_tax_rows($ticket_row, $ticket) |
|
1633 | - { |
|
1634 | - $tax_rows = ''; |
|
1635 | - /** @var EE_Price[] $taxes */ |
|
1636 | - $taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin(); |
|
1637 | - foreach ($taxes as $tax) { |
|
1638 | - $tax_added = $this->_get_tax_added($tax, $ticket); |
|
1639 | - $template_args = array( |
|
1640 | - 'display_tax' => ! empty($ticket) && $ticket->get('TKT_taxable') |
|
1641 | - ? '' |
|
1642 | - : ' style="display:none;"', |
|
1643 | - 'tax_id' => $tax->ID(), |
|
1644 | - 'tkt_row' => $ticket_row, |
|
1645 | - 'tax_label' => $tax->get('PRC_name'), |
|
1646 | - 'tax_added' => $tax_added, |
|
1647 | - 'tax_added_display' => EEH_Template::format_currency($tax_added, false, false), |
|
1648 | - 'tax_amount' => $tax->get('PRC_amount'), |
|
1649 | - ); |
|
1650 | - $template_args = apply_filters( |
|
1651 | - 'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args', |
|
1652 | - $template_args, |
|
1653 | - $ticket_row, |
|
1654 | - $ticket, |
|
1655 | - $this->_is_creating_event |
|
1656 | - ); |
|
1657 | - $tax_rows .= EEH_Template::display_template( |
|
1658 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php', |
|
1659 | - $template_args, |
|
1660 | - true |
|
1661 | - ); |
|
1662 | - } |
|
1663 | - return $tax_rows; |
|
1664 | - } |
|
1665 | - |
|
1666 | - |
|
1667 | - |
|
1668 | - /** |
|
1669 | - * @param EE_Price $tax |
|
1670 | - * @param EE_Ticket|null $ticket |
|
1671 | - * @return float|int |
|
1672 | - * @throws EE_Error |
|
1673 | - */ |
|
1674 | - protected function _get_tax_added(EE_Price $tax, $ticket) |
|
1675 | - { |
|
1676 | - $subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal(); |
|
1677 | - return $subtotal * $tax->get('PRC_amount') / 100; |
|
1678 | - } |
|
1679 | - |
|
1680 | - |
|
1681 | - |
|
1682 | - /** |
|
1683 | - * @param int $ticket_row |
|
1684 | - * @param int $price_row |
|
1685 | - * @param EE_Price|null $price |
|
1686 | - * @param bool $default |
|
1687 | - * @param EE_Ticket|null $ticket |
|
1688 | - * @param bool $show_trash |
|
1689 | - * @param bool $show_create |
|
1690 | - * @return mixed |
|
1691 | - * @throws DomainException |
|
1692 | - * @throws EE_Error |
|
1693 | - */ |
|
1694 | - protected function _get_ticket_price_row( |
|
1695 | - $ticket_row, |
|
1696 | - $price_row, |
|
1697 | - $price, |
|
1698 | - $default, |
|
1699 | - $ticket, |
|
1700 | - $show_trash = true, |
|
1701 | - $show_create = true |
|
1702 | - ) { |
|
1703 | - $send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted'); |
|
1704 | - $template_args = array( |
|
1705 | - 'tkt_row' => $default && empty($ticket) |
|
1706 | - ? 'TICKETNUM' |
|
1707 | - : $ticket_row, |
|
1708 | - 'PRC_order' => $default && empty($price) |
|
1709 | - ? 'PRICENUM' |
|
1710 | - : $price_row, |
|
1711 | - 'edit_prices_name' => $default && empty($price) |
|
1712 | - ? 'PRICENAMEATTR' |
|
1713 | - : 'edit_prices', |
|
1714 | - 'price_type_selector' => $default && empty($price) |
|
1715 | - ? $this->_get_base_price_template($ticket_row, $price_row, $price, $default) |
|
1716 | - : $this->_get_price_type_selector($ticket_row, $price_row, $price, $default, $send_disabled), |
|
1717 | - 'PRC_ID' => $default && empty($price) |
|
1718 | - ? 0 |
|
1719 | - : $price->ID(), |
|
1720 | - 'PRC_is_default' => $default && empty($price) |
|
1721 | - ? 0 |
|
1722 | - : $price->get('PRC_is_default'), |
|
1723 | - 'PRC_name' => $default && empty($price) |
|
1724 | - ? '' |
|
1725 | - : $price->get('PRC_name'), |
|
1726 | - 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
1727 | - 'show_plus_or_minus' => $default && empty($price) |
|
1728 | - ? '' |
|
1729 | - : ' style="display:none;"', |
|
1730 | - 'show_plus' => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price()) |
|
1731 | - ? ' style="display:none;"' |
|
1732 | - : '', |
|
1733 | - 'show_minus' => ($default && empty($price)) || ! $price->is_discount() |
|
1734 | - ? ' style="display:none;"' |
|
1735 | - : '', |
|
1736 | - 'show_currency_symbol' => ($default && empty($price)) || $price->is_percent() |
|
1737 | - ? ' style="display:none"' |
|
1738 | - : '', |
|
1739 | - 'PRC_amount' => $default && empty($price) |
|
1740 | - ? 0 |
|
1741 | - : $price->get_pretty('PRC_amount', |
|
1742 | - 'localized_float'), |
|
1743 | - 'show_percentage' => ($default && empty($price)) || ! $price->is_percent() |
|
1744 | - ? ' style="display:none;"' |
|
1745 | - : '', |
|
1746 | - 'show_trash_icon' => $show_trash |
|
1747 | - ? '' |
|
1748 | - : ' style="display:none;"', |
|
1749 | - 'show_create_button' => $show_create |
|
1750 | - ? '' |
|
1751 | - : ' style="display:none;"', |
|
1752 | - 'PRC_desc' => $default && empty($price) |
|
1753 | - ? '' |
|
1754 | - : $price->get('PRC_desc'), |
|
1755 | - 'disabled' => ! empty($ticket) && $ticket->get('TKT_deleted'), |
|
1756 | - ); |
|
1757 | - $template_args = apply_filters( |
|
1758 | - 'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args', |
|
1759 | - $template_args, |
|
1760 | - $ticket_row, |
|
1761 | - $price_row, |
|
1762 | - $price, |
|
1763 | - $default, |
|
1764 | - $ticket, |
|
1765 | - $show_trash, |
|
1766 | - $show_create, |
|
1767 | - $this->_is_creating_event |
|
1768 | - ); |
|
1769 | - return EEH_Template::display_template( |
|
1770 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php', |
|
1771 | - $template_args, |
|
1772 | - true |
|
1773 | - ); |
|
1774 | - } |
|
1775 | - |
|
1776 | - |
|
1777 | - |
|
1778 | - /** |
|
1779 | - * @param int $ticket_row |
|
1780 | - * @param int $price_row |
|
1781 | - * @param EE_Price $price |
|
1782 | - * @param bool $default |
|
1783 | - * @param bool $disabled |
|
1784 | - * @return mixed |
|
1785 | - * @throws DomainException |
|
1786 | - * @throws EE_Error |
|
1787 | - */ |
|
1788 | - protected function _get_price_type_selector($ticket_row, $price_row, $price, $default, $disabled = false) |
|
1789 | - { |
|
1790 | - if ($price->is_base_price()) { |
|
1791 | - return $this->_get_base_price_template($ticket_row, $price_row, $price, $default); |
|
1792 | - } |
|
1793 | - return $this->_get_price_modifier_template($ticket_row, $price_row, $price, $default, $disabled); |
|
1794 | - } |
|
1795 | - |
|
1796 | - |
|
1797 | - |
|
1798 | - /** |
|
1799 | - * @param int $ticket_row |
|
1800 | - * @param int $price_row |
|
1801 | - * @param EE_Price $price |
|
1802 | - * @param bool $default |
|
1803 | - * @return mixed |
|
1804 | - * @throws DomainException |
|
1805 | - * @throws EE_Error |
|
1806 | - */ |
|
1807 | - protected function _get_base_price_template($ticket_row, $price_row, $price, $default) |
|
1808 | - { |
|
1809 | - $template_args = array( |
|
1810 | - 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
1811 | - 'PRC_order' => $default && empty($price) ? 'PRICENUM' : $price_row, |
|
1812 | - 'PRT_ID' => $default && empty($price) ? 1 : $price->get('PRT_ID'), |
|
1813 | - 'PRT_name' => esc_html__('Price', 'event_espresso'), |
|
1814 | - 'price_selected_operator' => '+', |
|
1815 | - 'price_selected_is_percent' => 0, |
|
1816 | - ); |
|
1817 | - $template_args = apply_filters( |
|
1818 | - 'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args', |
|
1819 | - $template_args, |
|
1820 | - $ticket_row, |
|
1821 | - $price_row, |
|
1822 | - $price, |
|
1823 | - $default, |
|
1824 | - $this->_is_creating_event |
|
1825 | - ); |
|
1826 | - return EEH_Template::display_template( |
|
1827 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php', |
|
1828 | - $template_args, |
|
1829 | - true |
|
1830 | - ); |
|
1831 | - } |
|
1832 | - |
|
1833 | - |
|
1834 | - |
|
1835 | - /** |
|
1836 | - * @param int $ticket_row |
|
1837 | - * @param int $price_row |
|
1838 | - * @param EE_Price $price |
|
1839 | - * @param bool $default |
|
1840 | - * @param bool $disabled |
|
1841 | - * @return mixed |
|
1842 | - * @throws DomainException |
|
1843 | - * @throws EE_Error |
|
1844 | - */ |
|
1845 | - protected function _get_price_modifier_template( |
|
1846 | - $ticket_row, |
|
1847 | - $price_row, |
|
1848 | - $price, |
|
1849 | - $default, |
|
1850 | - $disabled = false |
|
1851 | - ) { |
|
1852 | - $select_name = $default && ! $price instanceof EE_Price |
|
1853 | - ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]' |
|
1854 | - : 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]'; |
|
1855 | - /** @var EEM_Price_Type $price_type_model */ |
|
1856 | - $price_type_model = EE_Registry::instance()->load_model('Price_Type'); |
|
1857 | - $price_types = $price_type_model->get_all(array( |
|
1858 | - array( |
|
1859 | - 'OR' => array( |
|
1860 | - 'PBT_ID' => '2', |
|
1861 | - 'PBT_ID*' => '3', |
|
1862 | - ), |
|
1863 | - ), |
|
1864 | - )); |
|
1865 | - $all_price_types = $default && ! $price instanceof EE_Price |
|
1866 | - ? array(esc_html__('Select Modifier', 'event_espresso')) |
|
1867 | - : array(); |
|
1868 | - $selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type(); |
|
1869 | - $price_option_spans = ''; |
|
1870 | - //setup price types for selector |
|
1871 | - foreach ($price_types as $price_type) { |
|
1872 | - if (! $price_type instanceof EE_Price_Type) { |
|
1873 | - continue; |
|
1874 | - } |
|
1875 | - $all_price_types[$price_type->ID()] = $price_type->get('PRT_name'); |
|
1876 | - //while we're in the loop let's setup the option spans used by js |
|
1877 | - $span_args = array( |
|
1878 | - 'PRT_ID' => $price_type->ID(), |
|
1879 | - 'PRT_operator' => $price_type->is_discount() ? '-' : '+', |
|
1880 | - 'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0, |
|
1881 | - ); |
|
1882 | - $price_option_spans .= EEH_Template::display_template( |
|
1883 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php', |
|
1884 | - $span_args, |
|
1885 | - true |
|
1886 | - ); |
|
1887 | - } |
|
1888 | - $select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]' : $select_name; |
|
1889 | - $select_input = new EE_Select_Input( |
|
1890 | - $all_price_types, |
|
1891 | - array( |
|
1892 | - 'default' => $selected_price_type_id, |
|
1893 | - 'html_name' => $select_name, |
|
1894 | - 'html_class' => 'edit-price-PRT_ID', |
|
1895 | - 'html_other_attributes' => $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"', |
|
1896 | - ) |
|
1897 | - ); |
|
1898 | - $price_selected_operator = $price instanceof EE_Price && $price->is_discount() ? '-' : '+'; |
|
1899 | - $price_selected_operator = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator; |
|
1900 | - $price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0; |
|
1901 | - $price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent; |
|
1902 | - $template_args = array( |
|
1903 | - 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
1904 | - 'PRC_order' => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row, |
|
1905 | - 'price_modifier_selector' => $select_input->get_html_for_input(), |
|
1906 | - 'main_name' => $select_name, |
|
1907 | - 'selected_price_type_id' => $selected_price_type_id, |
|
1908 | - 'price_option_spans' => $price_option_spans, |
|
1909 | - 'price_selected_operator' => $price_selected_operator, |
|
1910 | - 'price_selected_is_percent' => $price_selected_is_percent, |
|
1911 | - 'disabled' => $disabled, |
|
1912 | - ); |
|
1913 | - $template_args = apply_filters( |
|
1914 | - 'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args', |
|
1915 | - $template_args, |
|
1916 | - $ticket_row, |
|
1917 | - $price_row, |
|
1918 | - $price, |
|
1919 | - $default, |
|
1920 | - $disabled, |
|
1921 | - $this->_is_creating_event |
|
1922 | - ); |
|
1923 | - return EEH_Template::display_template( |
|
1924 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php', |
|
1925 | - $template_args, |
|
1926 | - true |
|
1927 | - ); |
|
1928 | - } |
|
1929 | - |
|
1930 | - |
|
1931 | - |
|
1932 | - /** |
|
1933 | - * @param int $datetime_row |
|
1934 | - * @param int $ticket_row |
|
1935 | - * @param EE_Datetime|null $datetime |
|
1936 | - * @param EE_Ticket|null $ticket |
|
1937 | - * @param array $ticket_datetimes |
|
1938 | - * @param bool $default |
|
1939 | - * @return mixed |
|
1940 | - * @throws DomainException |
|
1941 | - * @throws EE_Error |
|
1942 | - */ |
|
1943 | - protected function _get_ticket_datetime_list_item( |
|
1944 | - $datetime_row, |
|
1945 | - $ticket_row, |
|
1946 | - $datetime, |
|
1947 | - $ticket, |
|
1948 | - $ticket_datetimes = array(), |
|
1949 | - $default |
|
1950 | - ) { |
|
1951 | - $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) |
|
1952 | - ? $ticket_datetimes[$ticket->ID()] |
|
1953 | - : array(); |
|
1954 | - $template_args = array( |
|
1955 | - 'dtt_row' => $default && ! $datetime instanceof EE_Datetime |
|
1956 | - ? 'DTTNUM' |
|
1957 | - : $datetime_row, |
|
1958 | - 'tkt_row' => $default |
|
1959 | - ? 'TICKETNUM' |
|
1960 | - : $ticket_row, |
|
1961 | - 'ticket_datetime_selected' => in_array($datetime_row, $tkt_datetimes, true) |
|
1962 | - ? ' ticket-selected' |
|
1963 | - : '', |
|
1964 | - 'ticket_datetime_checked' => in_array($datetime_row, $tkt_datetimes, true) |
|
1965 | - ? ' checked="checked"' |
|
1966 | - : '', |
|
1967 | - 'DTT_name' => $default && empty($datetime) |
|
1968 | - ? 'DTTNAME' |
|
1969 | - : $datetime->get_dtt_display_name(true), |
|
1970 | - 'tkt_status_class' => '', |
|
1971 | - ); |
|
1972 | - $template_args = apply_filters( |
|
1973 | - 'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args', |
|
1974 | - $template_args, |
|
1975 | - $datetime_row, |
|
1976 | - $ticket_row, |
|
1977 | - $datetime, |
|
1978 | - $ticket, |
|
1979 | - $ticket_datetimes, |
|
1980 | - $default, |
|
1981 | - $this->_is_creating_event |
|
1982 | - ); |
|
1983 | - return EEH_Template::display_template( |
|
1984 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php', |
|
1985 | - $template_args, |
|
1986 | - true |
|
1987 | - ); |
|
1988 | - } |
|
1989 | - |
|
1990 | - |
|
1991 | - |
|
1992 | - /** |
|
1993 | - * @param array $all_datetimes |
|
1994 | - * @param array $all_tickets |
|
1995 | - * @return mixed |
|
1996 | - * @throws DomainException |
|
1997 | - * @throws EE_Error |
|
1998 | - */ |
|
1999 | - protected function _get_ticket_js_structure($all_datetimes = array(), $all_tickets = array()) |
|
2000 | - { |
|
2001 | - $template_args = array( |
|
2002 | - 'default_datetime_edit_row' => $this->_get_dtt_edit_row( |
|
2003 | - 'DTTNUM', |
|
2004 | - null, |
|
2005 | - true, |
|
2006 | - $all_datetimes |
|
2007 | - ), |
|
2008 | - 'default_ticket_row' => $this->_get_ticket_row( |
|
2009 | - 'TICKETNUM', |
|
2010 | - null, |
|
2011 | - array(), |
|
2012 | - array(), |
|
2013 | - true |
|
2014 | - ), |
|
2015 | - 'default_price_row' => $this->_get_ticket_price_row( |
|
2016 | - 'TICKETNUM', |
|
2017 | - 'PRICENUM', |
|
2018 | - null, |
|
2019 | - true, |
|
2020 | - null |
|
2021 | - ), |
|
2022 | - 'default_price_rows' => '', |
|
2023 | - 'default_base_price_amount' => 0, |
|
2024 | - 'default_base_price_name' => '', |
|
2025 | - 'default_base_price_description' => '', |
|
2026 | - 'default_price_modifier_selector_row' => $this->_get_price_modifier_template( |
|
2027 | - 'TICKETNUM', |
|
2028 | - 'PRICENUM', |
|
2029 | - null, |
|
2030 | - true |
|
2031 | - ), |
|
2032 | - 'default_available_tickets_for_datetime' => $this->_get_dtt_attached_tickets_row( |
|
2033 | - 'DTTNUM', |
|
2034 | - null, |
|
2035 | - array(), |
|
2036 | - array(), |
|
2037 | - true |
|
2038 | - ), |
|
2039 | - 'existing_available_datetime_tickets_list' => '', |
|
2040 | - 'existing_available_ticket_datetimes_list' => '', |
|
2041 | - 'new_available_datetime_ticket_list_item' => $this->_get_datetime_tickets_list_item( |
|
2042 | - 'DTTNUM', |
|
2043 | - 'TICKETNUM', |
|
2044 | - null, |
|
2045 | - null, |
|
2046 | - array(), |
|
2047 | - true |
|
2048 | - ), |
|
2049 | - 'new_available_ticket_datetime_list_item' => $this->_get_ticket_datetime_list_item( |
|
2050 | - 'DTTNUM', |
|
2051 | - 'TICKETNUM', |
|
2052 | - null, |
|
2053 | - null, |
|
2054 | - array(), |
|
2055 | - true |
|
2056 | - ), |
|
2057 | - ); |
|
2058 | - $ticket_row = 1; |
|
2059 | - foreach ($all_tickets as $ticket) { |
|
2060 | - $template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
|
2061 | - 'DTTNUM', |
|
2062 | - $ticket_row, |
|
2063 | - null, |
|
2064 | - $ticket, |
|
2065 | - array(), |
|
2066 | - true |
|
2067 | - ); |
|
2068 | - $ticket_row++; |
|
2069 | - } |
|
2070 | - $datetime_row = 1; |
|
2071 | - foreach ($all_datetimes as $datetime) { |
|
2072 | - $template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
|
2073 | - $datetime_row, |
|
2074 | - 'TICKETNUM', |
|
2075 | - $datetime, |
|
2076 | - null, |
|
2077 | - array(), |
|
2078 | - true |
|
2079 | - ); |
|
2080 | - $datetime_row++; |
|
2081 | - } |
|
2082 | - /** @var EEM_Price $price_model */ |
|
2083 | - $price_model = EE_Registry::instance()->load_model('Price'); |
|
2084 | - $default_prices = $price_model->get_all_default_prices(); |
|
2085 | - $price_row = 1; |
|
2086 | - foreach ($default_prices as $price) { |
|
2087 | - if (! $price instanceof EE_Price) { |
|
2088 | - continue; |
|
2089 | - } |
|
2090 | - if ($price->is_base_price()) { |
|
2091 | - $template_args['default_base_price_amount'] = $price->get_pretty( |
|
2092 | - 'PRC_amount', |
|
2093 | - 'localized_float' |
|
2094 | - ); |
|
2095 | - $template_args['default_base_price_name'] = $price->get('PRC_name'); |
|
2096 | - $template_args['default_base_price_description'] = $price->get('PRC_desc'); |
|
2097 | - $price_row++; |
|
2098 | - continue; |
|
2099 | - } |
|
2100 | - $show_trash = !((count($default_prices) > 1 && $price_row === 1) || count($default_prices) === 1); |
|
2101 | - $show_create = !(count($default_prices) > 1 && count($default_prices) !== $price_row); |
|
2102 | - $template_args['default_price_rows'] .= $this->_get_ticket_price_row( |
|
2103 | - 'TICKETNUM', |
|
2104 | - $price_row, |
|
2105 | - $price, |
|
2106 | - true, |
|
2107 | - null, |
|
2108 | - $show_trash, |
|
2109 | - $show_create |
|
2110 | - ); |
|
2111 | - $price_row++; |
|
2112 | - } |
|
2113 | - $template_args = apply_filters( |
|
2114 | - 'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args', |
|
2115 | - $template_args, |
|
2116 | - $all_datetimes, |
|
2117 | - $all_tickets, |
|
2118 | - $this->_is_creating_event |
|
2119 | - ); |
|
2120 | - return EEH_Template::display_template( |
|
2121 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php', |
|
2122 | - $template_args, |
|
2123 | - true |
|
2124 | - ); |
|
2125 | - } |
|
18 | + /** |
|
19 | + * This property is just used to hold the status of whether an event is currently being |
|
20 | + * created (true) or edited (false) |
|
21 | + * |
|
22 | + * @access protected |
|
23 | + * @var bool |
|
24 | + */ |
|
25 | + protected $_is_creating_event; |
|
26 | + |
|
27 | + |
|
28 | + /** |
|
29 | + * Used to contain the format strings for date and time that will be used for php date and |
|
30 | + * time. |
|
31 | + * Is set in the _set_hooks_properties() method. |
|
32 | + * |
|
33 | + * @var array |
|
34 | + */ |
|
35 | + protected $_date_format_strings; |
|
36 | + |
|
37 | + |
|
38 | + /** |
|
39 | + * @var string $_date_time_format |
|
40 | + */ |
|
41 | + protected $_date_time_format; |
|
42 | + |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * |
|
47 | + */ |
|
48 | + protected function _set_hooks_properties() |
|
49 | + { |
|
50 | + $this->_name = 'pricing'; |
|
51 | + //capability check |
|
52 | + if (! EE_Registry::instance()->CAP->current_user_can( |
|
53 | + 'ee_read_default_prices', |
|
54 | + 'advanced_ticket_datetime_metabox' |
|
55 | + )) { |
|
56 | + return; |
|
57 | + } |
|
58 | + $this->_setup_metaboxes(); |
|
59 | + $this->_set_date_time_formats(); |
|
60 | + $this->_validate_format_strings(); |
|
61 | + $this->_set_scripts_styles(); |
|
62 | + // commented out temporarily until logic is implemented in callback |
|
63 | + // add_action( |
|
64 | + // 'AHEE__EE_Admin_Page_CPT__do_extra_autosave_stuff__after_Extend_Events_Admin_Page', |
|
65 | + // array($this, 'autosave_handling') |
|
66 | + // ); |
|
67 | + add_filter( |
|
68 | + 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
69 | + array($this, 'caf_updates') |
|
70 | + ); |
|
71 | + } |
|
72 | + |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * @return void |
|
77 | + */ |
|
78 | + protected function _setup_metaboxes() |
|
79 | + { |
|
80 | + //if we were going to add our own metaboxes we'd use the below. |
|
81 | + $this->_metaboxes = array( |
|
82 | + 0 => array( |
|
83 | + 'page_route' => array('edit', 'create_new'), |
|
84 | + 'func' => 'pricing_metabox', |
|
85 | + 'label' => esc_html__('Event Tickets & Datetimes', 'event_espresso'), |
|
86 | + 'priority' => 'high', |
|
87 | + 'context' => 'normal', |
|
88 | + ), |
|
89 | + ); |
|
90 | + $this->_remove_metaboxes = array( |
|
91 | + 0 => array( |
|
92 | + 'page_route' => array('edit', 'create_new'), |
|
93 | + 'id' => 'espresso_event_editor_tickets', |
|
94 | + 'context' => 'normal', |
|
95 | + ), |
|
96 | + ); |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * @return void |
|
103 | + */ |
|
104 | + protected function _set_date_time_formats() |
|
105 | + { |
|
106 | + /** |
|
107 | + * Format strings for date and time. Defaults are existing behaviour from 4.1. |
|
108 | + * Note, that if you return null as the value for 'date', and 'time' in the array, then |
|
109 | + * EE will automatically use the set wp_options, 'date_format', and 'time_format'. |
|
110 | + * |
|
111 | + * @since 4.6.7 |
|
112 | + * @var array Expected an array returned with 'date' and 'time' keys. |
|
113 | + */ |
|
114 | + $this->_date_format_strings = apply_filters( |
|
115 | + 'FHEE__espresso_events_Pricing_Hooks___set_hooks_properties__date_format_strings', |
|
116 | + array( |
|
117 | + 'date' => 'Y-m-d', |
|
118 | + 'time' => 'h:i a', |
|
119 | + ) |
|
120 | + ); |
|
121 | + //validate |
|
122 | + $this->_date_format_strings['date'] = isset($this->_date_format_strings['date']) |
|
123 | + ? $this->_date_format_strings['date'] |
|
124 | + : null; |
|
125 | + $this->_date_format_strings['time'] = isset($this->_date_format_strings['time']) |
|
126 | + ? $this->_date_format_strings['time'] |
|
127 | + : null; |
|
128 | + $this->_date_time_format = $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']; |
|
129 | + } |
|
130 | + |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * @return void |
|
135 | + */ |
|
136 | + protected function _validate_format_strings() |
|
137 | + { |
|
138 | + //validate format strings |
|
139 | + $format_validation = EEH_DTT_Helper::validate_format_string( |
|
140 | + $this->_date_time_format |
|
141 | + ); |
|
142 | + if (is_array($format_validation)) { |
|
143 | + $msg = '<p>'; |
|
144 | + $msg .= sprintf( |
|
145 | + esc_html__( |
|
146 | + 'The format "%s" was likely added via a filter and is invalid for the following reasons:', |
|
147 | + 'event_espresso' |
|
148 | + ), |
|
149 | + $this->_date_time_format |
|
150 | + ); |
|
151 | + $msg .= '</p><ul>'; |
|
152 | + foreach ($format_validation as $error) { |
|
153 | + $msg .= '<li>' . $error . '</li>'; |
|
154 | + } |
|
155 | + $msg .= '</ul><p>'; |
|
156 | + $msg .= sprintf( |
|
157 | + esc_html__( |
|
158 | + '%sPlease note that your date and time formats have been reset to "Y-m-d" and "h:i a" respectively.%s', |
|
159 | + 'event_espresso' |
|
160 | + ), |
|
161 | + '<span style="color:#D54E21;">', |
|
162 | + '</span>' |
|
163 | + ); |
|
164 | + $msg .= '</p>'; |
|
165 | + EE_Error::add_attention($msg, __FILE__, __FUNCTION__, __LINE__); |
|
166 | + $this->_date_format_strings = array( |
|
167 | + 'date' => 'Y-m-d', |
|
168 | + 'time' => 'h:i a', |
|
169 | + ); |
|
170 | + } |
|
171 | + } |
|
172 | + |
|
173 | + |
|
174 | + |
|
175 | + /** |
|
176 | + * @return void |
|
177 | + */ |
|
178 | + protected function _set_scripts_styles() |
|
179 | + { |
|
180 | + $this->_scripts_styles = array( |
|
181 | + 'registers' => array( |
|
182 | + 'ee-tickets-datetimes-css' => array( |
|
183 | + 'url' => PRICING_ASSETS_URL . 'event-tickets-datetimes.css', |
|
184 | + 'type' => 'css', |
|
185 | + ), |
|
186 | + 'ee-dtt-ticket-metabox' => array( |
|
187 | + 'url' => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js', |
|
188 | + 'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'), |
|
189 | + ), |
|
190 | + ), |
|
191 | + 'deregisters' => array( |
|
192 | + 'event-editor-css' => array('type' => 'css'), |
|
193 | + 'event-datetime-metabox' => array('type' => 'js'), |
|
194 | + ), |
|
195 | + 'enqueues' => array( |
|
196 | + 'ee-tickets-datetimes-css' => array('edit', 'create_new'), |
|
197 | + 'ee-dtt-ticket-metabox' => array('edit', 'create_new'), |
|
198 | + ), |
|
199 | + 'localize' => array( |
|
200 | + 'ee-dtt-ticket-metabox' => array( |
|
201 | + 'DTT_TRASH_BLOCK' => array( |
|
202 | + 'main_warning' => esc_html__( |
|
203 | + 'The Datetime you are attempting to trash is the only datetime selected for the following ticket(s):', |
|
204 | + 'event_espresso' |
|
205 | + ), |
|
206 | + 'after_warning' => esc_html__( |
|
207 | + 'In order to trash this datetime you must first make sure the above ticket(s) are assigned to other datetimes.', |
|
208 | + 'event_espresso' |
|
209 | + ), |
|
210 | + 'cancel_button' => '<button class="button-secondary ee-modal-cancel">' |
|
211 | + . esc_html__('Cancel', 'event_espresso') . '</button>', |
|
212 | + 'close_button' => '<button class="button-secondary ee-modal-cancel">' |
|
213 | + . esc_html__('Close', 'event_espresso') . '</button>', |
|
214 | + 'single_warning_from_tkt' => esc_html__( |
|
215 | + 'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.', |
|
216 | + 'event_espresso' |
|
217 | + ), |
|
218 | + 'single_warning_from_dtt' => esc_html__( |
|
219 | + 'The ticket you are attempting to unassign from this datetime cannot be unassigned because the datetime is the only remaining datetime for the ticket. Tickets must always have at least one datetime assigned to them.', |
|
220 | + 'event_espresso' |
|
221 | + ), |
|
222 | + 'dismiss_button' => '<button class="button-secondary ee-modal-cancel">' |
|
223 | + . esc_html__('Dismiss', 'event_espresso') . '</button>', |
|
224 | + ), |
|
225 | + 'DTT_ERROR_MSG' => array( |
|
226 | + 'no_ticket_name' => esc_html__('General Admission', 'event_espresso'), |
|
227 | + 'dismiss_button' => '<div class="save-cancel-button-container"><button class="button-secondary ee-modal-cancel">' |
|
228 | + . esc_html__('Dismiss', 'event_espresso') . '</button></div>', |
|
229 | + ), |
|
230 | + 'DTT_OVERSELL_WARNING' => array( |
|
231 | + 'datetime_ticket' => esc_html__( |
|
232 | + 'You cannot add this ticket to this datetime because it has a sold amount that is greater than the amount of spots remaining for this datetime.', |
|
233 | + 'event_espresso' |
|
234 | + ), |
|
235 | + 'ticket_datetime' => esc_html__( |
|
236 | + 'You cannot add this datetime to this ticket because the ticket has a sold amount that is greater than the amount of spots remaining on the datetime.', |
|
237 | + 'event_espresso' |
|
238 | + ), |
|
239 | + ), |
|
240 | + 'DTT_CONVERTED_FORMATS' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats( |
|
241 | + $this->_date_format_strings['date'], |
|
242 | + $this->_date_format_strings['time'] |
|
243 | + ), |
|
244 | + 'DTT_START_OF_WEEK' => array('dayValue' => (int)get_option('start_of_week')), |
|
245 | + ), |
|
246 | + ), |
|
247 | + ); |
|
248 | + } |
|
249 | + |
|
250 | + |
|
251 | + |
|
252 | + /** |
|
253 | + * @param array $update_callbacks |
|
254 | + * @return array |
|
255 | + */ |
|
256 | + public function caf_updates(array $update_callbacks) |
|
257 | + { |
|
258 | + foreach ($update_callbacks as $key => $callback) { |
|
259 | + if ($callback[1] === '_default_tickets_update') { |
|
260 | + unset($update_callbacks[$key]); |
|
261 | + } |
|
262 | + } |
|
263 | + $update_callbacks[] = array($this, 'datetime_and_tickets_caf_update'); |
|
264 | + return $update_callbacks; |
|
265 | + } |
|
266 | + |
|
267 | + |
|
268 | + /** |
|
269 | + * Handles saving everything related to Tickets (datetimes, tickets, prices) |
|
270 | + * |
|
271 | + * @param EE_Event $event The Event object we're attaching data to |
|
272 | + * @param array $data The request data from the form |
|
273 | + * @throws EE_Error |
|
274 | + * @throws InvalidArgumentException |
|
275 | + */ |
|
276 | + public function datetime_and_tickets_caf_update($event, $data) |
|
277 | + { |
|
278 | + //first we need to start with datetimes cause they are the "root" items attached to events. |
|
279 | + $saved_datetimes = $this->_update_datetimes($event, $data); |
|
280 | + //next tackle the tickets (and prices?) |
|
281 | + $this->_update_tickets($event, $saved_datetimes, $data); |
|
282 | + } |
|
283 | + |
|
284 | + |
|
285 | + /** |
|
286 | + * update event_datetimes |
|
287 | + * |
|
288 | + * @param EE_Event $event Event being updated |
|
289 | + * @param array $data the request data from the form |
|
290 | + * @return EE_Datetime[] |
|
291 | + * @throws InvalidArgumentException |
|
292 | + * @throws EE_Error |
|
293 | + */ |
|
294 | + protected function _update_datetimes($event, $data) |
|
295 | + { |
|
296 | + $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
297 | + $saved_dtt_ids = array(); |
|
298 | + $saved_dtt_objs = array(); |
|
299 | + if (empty($data['edit_event_datetimes']) || !is_array($data['edit_event_datetimes'])) { |
|
300 | + throw new InvalidArgumentException( |
|
301 | + esc_html__( |
|
302 | + 'The "edit_event_datetimes" array is invalid therefore the event can not be updated.', |
|
303 | + 'event_espresso' |
|
304 | + ) |
|
305 | + ); |
|
306 | + } |
|
307 | + foreach ($data['edit_event_datetimes'] as $row => $datetime_data) { |
|
308 | + //trim all values to ensure any excess whitespace is removed. |
|
309 | + $datetime_data = array_map( |
|
310 | + function ($datetime_data) { |
|
311 | + return is_array($datetime_data) ? $datetime_data : trim($datetime_data); |
|
312 | + }, |
|
313 | + $datetime_data |
|
314 | + ); |
|
315 | + $datetime_data['DTT_EVT_end'] = isset($datetime_data['DTT_EVT_end']) |
|
316 | + && ! empty($datetime_data['DTT_EVT_end']) |
|
317 | + ? $datetime_data['DTT_EVT_end'] |
|
318 | + : $datetime_data['DTT_EVT_start']; |
|
319 | + $datetime_values = array( |
|
320 | + 'DTT_ID' => ! empty($datetime_data['DTT_ID']) |
|
321 | + ? $datetime_data['DTT_ID'] |
|
322 | + : null, |
|
323 | + 'DTT_name' => ! empty($datetime_data['DTT_name']) |
|
324 | + ? $datetime_data['DTT_name'] |
|
325 | + : '', |
|
326 | + 'DTT_description' => ! empty($datetime_data['DTT_description']) |
|
327 | + ? $datetime_data['DTT_description'] |
|
328 | + : '', |
|
329 | + 'DTT_EVT_start' => $datetime_data['DTT_EVT_start'], |
|
330 | + 'DTT_EVT_end' => $datetime_data['DTT_EVT_end'], |
|
331 | + 'DTT_reg_limit' => empty($datetime_data['DTT_reg_limit']) |
|
332 | + ? EE_INF |
|
333 | + : $datetime_data['DTT_reg_limit'], |
|
334 | + 'DTT_order' => ! isset($datetime_data['DTT_order']) |
|
335 | + ? $row |
|
336 | + : $datetime_data['DTT_order'], |
|
337 | + ); |
|
338 | + // if we have an id then let's get existing object first and then set the new values. |
|
339 | + // Otherwise we instantiate a new object for save. |
|
340 | + if (! empty($datetime_data['DTT_ID'])) { |
|
341 | + $datetime = EE_Registry::instance() |
|
342 | + ->load_model('Datetime', array($timezone)) |
|
343 | + ->get_one_by_ID($datetime_data['DTT_ID']); |
|
344 | + //set date and time format according to what is set in this class. |
|
345 | + $datetime->set_date_format($this->_date_format_strings['date']); |
|
346 | + $datetime->set_time_format($this->_date_format_strings['time']); |
|
347 | + foreach ($datetime_values as $field => $value) { |
|
348 | + $datetime->set($field, $value); |
|
349 | + } |
|
350 | + // make sure the $dtt_id here is saved just in case |
|
351 | + // after the add_relation_to() the autosave replaces it. |
|
352 | + // We need to do this so we dont' TRASH the parent DTT. |
|
353 | + // (save the ID for both key and value to avoid duplications) |
|
354 | + $saved_dtt_ids[$datetime->ID()] = $datetime->ID(); |
|
355 | + } else { |
|
356 | + $datetime = EE_Registry::instance()->load_class( |
|
357 | + 'Datetime', |
|
358 | + array( |
|
359 | + $datetime_values, |
|
360 | + $timezone, |
|
361 | + array($this->_date_format_strings['date'], $this->_date_format_strings['time']), |
|
362 | + ), |
|
363 | + false, |
|
364 | + false |
|
365 | + ); |
|
366 | + foreach ($datetime_values as $field => $value) { |
|
367 | + $datetime->set($field, $value); |
|
368 | + } |
|
369 | + } |
|
370 | + $datetime->save(); |
|
371 | + $datetime = $event->_add_relation_to($datetime, 'Datetime'); |
|
372 | + // before going any further make sure our dates are setup correctly |
|
373 | + // so that the end date is always equal or greater than the start date. |
|
374 | + if ($datetime->get_raw('DTT_EVT_start') > $datetime->get_raw('DTT_EVT_end')) { |
|
375 | + $datetime->set('DTT_EVT_end', $datetime->get('DTT_EVT_start')); |
|
376 | + $datetime = EEH_DTT_Helper::date_time_add($datetime, 'DTT_EVT_end', 'days'); |
|
377 | + $datetime->save(); |
|
378 | + } |
|
379 | + // now we have to make sure we add the new DTT_ID to the $saved_dtt_ids array |
|
380 | + // because it is possible there was a new one created for the autosave. |
|
381 | + // (save the ID for both key and value to avoid duplications) |
|
382 | + $DTT_ID = $datetime->ID(); |
|
383 | + $saved_dtt_ids[$DTT_ID] = $DTT_ID; |
|
384 | + $saved_dtt_objs[$row] = $datetime; |
|
385 | + //todo if ANY of these updates fail then we want the appropriate global error message. |
|
386 | + } |
|
387 | + $event->save(); |
|
388 | + // now we need to REMOVE any datetimes that got deleted. |
|
389 | + // Keep in mind that this process will only kick in for datetimes that don't have any DTT_sold on them. |
|
390 | + // So its safe to permanently delete at this point. |
|
391 | + $old_datetimes = explode(',', $data['datetime_IDs']); |
|
392 | + $old_datetimes = $old_datetimes[0] === '' ? array() : $old_datetimes; |
|
393 | + if (is_array($old_datetimes)) { |
|
394 | + $datetimes_to_delete = array_diff($old_datetimes, $saved_dtt_ids); |
|
395 | + foreach ($datetimes_to_delete as $id) { |
|
396 | + $id = absint($id); |
|
397 | + if (empty($id)) { |
|
398 | + continue; |
|
399 | + } |
|
400 | + $dtt_to_remove = EE_Registry::instance()->load_model('Datetime')->get_one_by_ID($id); |
|
401 | + //remove tkt relationships. |
|
402 | + $related_tickets = $dtt_to_remove->get_many_related('Ticket'); |
|
403 | + foreach ($related_tickets as $tkt) { |
|
404 | + $dtt_to_remove->_remove_relation_to($tkt, 'Ticket'); |
|
405 | + } |
|
406 | + $event->_remove_relation_to($id, 'Datetime'); |
|
407 | + $dtt_to_remove->refresh_cache_of_related_objects(); |
|
408 | + } |
|
409 | + } |
|
410 | + return $saved_dtt_objs; |
|
411 | + } |
|
412 | + |
|
413 | + |
|
414 | + /** |
|
415 | + * update tickets |
|
416 | + * |
|
417 | + * @param EE_Event $event Event object being updated |
|
418 | + * @param EE_Datetime[] $saved_datetimes an array of datetime ids being updated |
|
419 | + * @param array $data incoming request data |
|
420 | + * @return EE_Ticket[] |
|
421 | + * @throws InvalidArgumentException |
|
422 | + * @throws EE_Error |
|
423 | + */ |
|
424 | + protected function _update_tickets($event, $saved_datetimes, $data) |
|
425 | + { |
|
426 | + $new_tkt = null; |
|
427 | + $new_default = null; |
|
428 | + //stripslashes because WP filtered the $_POST ($data) array to add slashes |
|
429 | + $data = stripslashes_deep($data); |
|
430 | + $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
|
431 | + $saved_tickets = $datetimes_on_existing = array(); |
|
432 | + $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
433 | + if(empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])){ |
|
434 | + throw new InvalidArgumentException( |
|
435 | + esc_html__( |
|
436 | + 'The "edit_tickets" array is invalid therefore the event can not be updated.', |
|
437 | + 'event_espresso' |
|
438 | + ) |
|
439 | + ); |
|
440 | + } |
|
441 | + foreach ($data['edit_tickets'] as $row => $tkt) { |
|
442 | + $update_prices = $create_new_TKT = false; |
|
443 | + // figure out what datetimes were added to the ticket |
|
444 | + // and what datetimes were removed from the ticket in the session. |
|
445 | + $starting_tkt_dtt_rows = explode(',', $data['starting_ticket_datetime_rows'][$row]); |
|
446 | + $tkt_dtt_rows = explode(',', $data['ticket_datetime_rows'][$row]); |
|
447 | + $datetimes_added = array_diff($tkt_dtt_rows, $starting_tkt_dtt_rows); |
|
448 | + $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows); |
|
449 | + // trim inputs to ensure any excess whitespace is removed. |
|
450 | + $tkt = array_map( |
|
451 | + function ($ticket_data) { |
|
452 | + return is_array($ticket_data) ? $ticket_data : trim($ticket_data); |
|
453 | + }, |
|
454 | + $tkt |
|
455 | + ); |
|
456 | + // note we are doing conversions to floats here instead of allowing EE_Money_Field to handle |
|
457 | + // because we're doing calculations prior to using the models. |
|
458 | + // note incoming ['TKT_price'] value is already in standard notation (via js). |
|
459 | + $ticket_price = isset($tkt['TKT_price']) |
|
460 | + ? round((float)$tkt['TKT_price'], 3) |
|
461 | + : 0; |
|
462 | + //note incoming base price needs converted from localized value. |
|
463 | + $base_price = isset($tkt['TKT_base_price']) |
|
464 | + ? EEH_Money::convert_to_float_from_localized_money($tkt['TKT_base_price']) |
|
465 | + : 0; |
|
466 | + //if ticket price == 0 and $base_price != 0 then ticket price == base_price |
|
467 | + $ticket_price = $ticket_price === 0 && $base_price !== 0 |
|
468 | + ? $base_price |
|
469 | + : $ticket_price; |
|
470 | + $base_price_id = isset($tkt['TKT_base_price_ID']) |
|
471 | + ? $tkt['TKT_base_price_ID'] |
|
472 | + : 0; |
|
473 | + $price_rows = is_array($data['edit_prices']) && isset($data['edit_prices'][$row]) |
|
474 | + ? $data['edit_prices'][$row] |
|
475 | + : array(); |
|
476 | + $now = null; |
|
477 | + if (empty($tkt['TKT_start_date'])) { |
|
478 | + //lets' use now in the set timezone. |
|
479 | + $now = new DateTime('now', new DateTimeZone($event->get_timezone())); |
|
480 | + $tkt['TKT_start_date'] = $now->format($this->_date_time_format); |
|
481 | + } |
|
482 | + if (empty($tkt['TKT_end_date'])) { |
|
483 | + /** |
|
484 | + * set the TKT_end_date to the first datetime attached to the ticket. |
|
485 | + */ |
|
486 | + $first_dtt = $saved_datetimes[reset($tkt_dtt_rows)]; |
|
487 | + $tkt['TKT_end_date'] = $first_dtt->start_date_and_time($this->_date_time_format); |
|
488 | + } |
|
489 | + $TKT_values = array( |
|
490 | + 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : null, |
|
491 | + 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
492 | + 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
493 | + 'TKT_description' => ! empty($tkt['TKT_description']) |
|
494 | + && $tkt['TKT_description'] !== esc_html__( |
|
495 | + 'You can modify this description', |
|
496 | + 'event_espresso' |
|
497 | + ) |
|
498 | + ? $tkt['TKT_description'] |
|
499 | + : '', |
|
500 | + 'TKT_start_date' => $tkt['TKT_start_date'], |
|
501 | + 'TKT_end_date' => $tkt['TKT_end_date'], |
|
502 | + 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' |
|
503 | + ? EE_INF |
|
504 | + : $tkt['TKT_qty'], |
|
505 | + 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' |
|
506 | + ? EE_INF |
|
507 | + : $tkt['TKT_uses'], |
|
508 | + 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
509 | + 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
510 | + 'TKT_row' => $row, |
|
511 | + 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : 0, |
|
512 | + 'TKT_taxable' => ! empty($tkt['TKT_taxable']) ? 1 : 0, |
|
513 | + 'TKT_required' => ! empty($tkt['TKT_required']) ? 1 : 0, |
|
514 | + 'TKT_price' => $ticket_price, |
|
515 | + ); |
|
516 | + // if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, |
|
517 | + // which means in turn that the prices will become new prices as well. |
|
518 | + if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
519 | + $TKT_values['TKT_ID'] = 0; |
|
520 | + $TKT_values['TKT_is_default'] = 0; |
|
521 | + $update_prices = true; |
|
522 | + } |
|
523 | + // if we have a TKT_ID then we need to get that existing TKT_obj and update it |
|
524 | + // we actually do our saves ahead of doing any add_relations to |
|
525 | + // because its entirely possible that this ticket wasn't removed or added to any datetime in the session |
|
526 | + // but DID have it's items modified. |
|
527 | + // keep in mind that if the TKT has been sold (and we have changed pricing information), |
|
528 | + // then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
|
529 | + if (absint($TKT_values['TKT_ID'])) { |
|
530 | + $ticket = EE_Registry::instance() |
|
531 | + ->load_model('Ticket', array($timezone)) |
|
532 | + ->get_one_by_ID($tkt['TKT_ID']); |
|
533 | + if ($ticket instanceof EE_Ticket) { |
|
534 | + $ticket = $this->_update_ticket_datetimes( |
|
535 | + $ticket, |
|
536 | + $saved_datetimes, |
|
537 | + $datetimes_added, |
|
538 | + $datetimes_removed |
|
539 | + ); |
|
540 | + // are there any registrations using this ticket ? |
|
541 | + $tickets_sold = $ticket->count_related( |
|
542 | + 'Registration', |
|
543 | + array( |
|
544 | + array( |
|
545 | + 'STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete)), |
|
546 | + ), |
|
547 | + ) |
|
548 | + ); |
|
549 | + //set ticket formats |
|
550 | + $ticket->set_date_format($this->_date_format_strings['date']); |
|
551 | + $ticket->set_time_format($this->_date_format_strings['time']); |
|
552 | + // let's just check the total price for the existing ticket |
|
553 | + // and determine if it matches the new total price. |
|
554 | + // if they are different then we create a new ticket (if tickets sold) |
|
555 | + // if they aren't different then we go ahead and modify existing ticket. |
|
556 | + $create_new_TKT = $tickets_sold > 0 && $ticket_price !== $ticket->price() && ! $ticket->deleted(); |
|
557 | + //set new values |
|
558 | + foreach ($TKT_values as $field => $value) { |
|
559 | + if ($field === 'TKT_qty') { |
|
560 | + $ticket->set_qty($value); |
|
561 | + } else { |
|
562 | + $ticket->set($field, $value); |
|
563 | + } |
|
564 | + } |
|
565 | + // if $create_new_TKT is false then we can safely update the existing ticket. |
|
566 | + // Otherwise we have to create a new ticket. |
|
567 | + if ($create_new_TKT) { |
|
568 | + $new_tkt = $this->_duplicate_ticket($ticket, $price_rows, $ticket_price, $base_price, |
|
569 | + $base_price_id); |
|
570 | + } |
|
571 | + } |
|
572 | + } else { |
|
573 | + // no TKT_id so a new TKT |
|
574 | + $ticket = EE_Ticket::new_instance( |
|
575 | + $TKT_values, |
|
576 | + $timezone, |
|
577 | + array($this->_date_format_strings['date'], $this->_date_format_strings['time']) |
|
578 | + ); |
|
579 | + if ($ticket instanceof EE_Ticket) { |
|
580 | + // make sure ticket has an ID of setting relations won't work |
|
581 | + $ticket->save(); |
|
582 | + $ticket = $this->_update_ticket_datetimes( |
|
583 | + $ticket, |
|
584 | + $saved_datetimes, |
|
585 | + $datetimes_added, |
|
586 | + $datetimes_removed |
|
587 | + ); |
|
588 | + $update_prices = true; |
|
589 | + } |
|
590 | + } |
|
591 | + //make sure any current values have been saved. |
|
592 | + //$ticket->save(); |
|
593 | + // before going any further make sure our dates are setup correctly |
|
594 | + // so that the end date is always equal or greater than the start date. |
|
595 | + if ($ticket->get_raw('TKT_start_date') > $ticket->get_raw('TKT_end_date')) { |
|
596 | + $ticket->set('TKT_end_date', $ticket->get('TKT_start_date')); |
|
597 | + $ticket = EEH_DTT_Helper::date_time_add($ticket, 'TKT_end_date', 'days'); |
|
598 | + } |
|
599 | + //let's make sure the base price is handled |
|
600 | + $ticket = ! $create_new_TKT ? $this->_add_prices_to_ticket(array(), $ticket, $update_prices, $base_price, |
|
601 | + $base_price_id) : $ticket; |
|
602 | + //add/update price_modifiers |
|
603 | + $ticket = ! $create_new_TKT ? $this->_add_prices_to_ticket($price_rows, $ticket, $update_prices) : $ticket; |
|
604 | + //need to make sue that the TKT_price is accurate after saving the prices. |
|
605 | + $ticket->ensure_TKT_Price_correct(); |
|
606 | + //handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave. |
|
607 | + if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) { |
|
608 | + $update_prices = true; |
|
609 | + $new_default = clone $ticket; |
|
610 | + $new_default->set('TKT_ID', 0); |
|
611 | + $new_default->set('TKT_is_default', 1); |
|
612 | + $new_default->set('TKT_row', 1); |
|
613 | + $new_default->set('TKT_price', $ticket_price); |
|
614 | + // remove any dtt relations cause we DON'T want dtt relations attached |
|
615 | + // (note this is just removing the cached relations in the object) |
|
616 | + $new_default->_remove_relations('Datetime'); |
|
617 | + //todo we need to add the current attached prices as new prices to the new default ticket. |
|
618 | + $new_default = $this->_add_prices_to_ticket($price_rows, $new_default, $update_prices); |
|
619 | + //don't forget the base price! |
|
620 | + $new_default = $this->_add_prices_to_ticket( |
|
621 | + array(), |
|
622 | + $new_default, |
|
623 | + $update_prices, |
|
624 | + $base_price, |
|
625 | + $base_price_id |
|
626 | + ); |
|
627 | + $new_default->save(); |
|
628 | + do_action( |
|
629 | + 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_default_ticket', |
|
630 | + $new_default, |
|
631 | + $row, |
|
632 | + $ticket, |
|
633 | + $data |
|
634 | + ); |
|
635 | + } |
|
636 | + // DO ALL dtt relationships for both current tickets and any archived tickets |
|
637 | + // for the given dtt that are related to the current ticket. |
|
638 | + // TODO... not sure exactly how we're going to do this considering we don't know |
|
639 | + // what current ticket the archived tickets are related to |
|
640 | + // (and TKT_parent is used for autosaves so that's not a field we can reliably use). |
|
641 | + //let's assign any tickets that have been setup to the saved_tickets tracker |
|
642 | + //save existing TKT |
|
643 | + $ticket->save(); |
|
644 | + if ($create_new_TKT && $new_tkt instanceof EE_Ticket) { |
|
645 | + //save new TKT |
|
646 | + $new_tkt->save(); |
|
647 | + //add new ticket to array |
|
648 | + $saved_tickets[$new_tkt->ID()] = $new_tkt; |
|
649 | + do_action( |
|
650 | + 'AHEE__espresso_events_Pricing_Hooks___update_tkts_new_ticket', |
|
651 | + $new_tkt, |
|
652 | + $row, |
|
653 | + $tkt, |
|
654 | + $data |
|
655 | + ); |
|
656 | + } else { |
|
657 | + //add tkt to saved tkts |
|
658 | + $saved_tickets[$ticket->ID()] = $ticket; |
|
659 | + do_action( |
|
660 | + 'AHEE__espresso_events_Pricing_Hooks___update_tkts_update_ticket', |
|
661 | + $ticket, |
|
662 | + $row, |
|
663 | + $tkt, |
|
664 | + $data |
|
665 | + ); |
|
666 | + } |
|
667 | + } |
|
668 | + // now we need to handle tickets actually "deleted permanently". |
|
669 | + // There are cases where we'd want this to happen |
|
670 | + // (i.e. autosaves are happening and then in between autosaves the user trashes a ticket). |
|
671 | + // Or a draft event was saved and in the process of editing a ticket is trashed. |
|
672 | + // No sense in keeping all the related data in the db! |
|
673 | + $old_tickets = isset($old_tickets[0]) && $old_tickets[0] === '' ? array() : $old_tickets; |
|
674 | + $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
675 | + foreach ($tickets_removed as $id) { |
|
676 | + $id = absint($id); |
|
677 | + //get the ticket for this id |
|
678 | + $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
|
679 | + //if this tkt is a default tkt we leave it alone cause it won't be attached to the datetime |
|
680 | + if ($tkt_to_remove->get('TKT_is_default')) { |
|
681 | + continue; |
|
682 | + } |
|
683 | + // if this tkt has any registrations attached so then we just ARCHIVE |
|
684 | + // because we don't actually permanently delete these tickets. |
|
685 | + if ($tkt_to_remove->count_related('Registration') > 0) { |
|
686 | + $tkt_to_remove->delete(); |
|
687 | + continue; |
|
688 | + } |
|
689 | + // need to get all the related datetimes on this ticket and remove from every single one of them |
|
690 | + // (remember this process can ONLY kick off if there are NO tkts_sold) |
|
691 | + $datetimes = $tkt_to_remove->get_many_related('Datetime'); |
|
692 | + foreach ($datetimes as $datetime) { |
|
693 | + $tkt_to_remove->_remove_relation_to($datetime, 'Datetime'); |
|
694 | + } |
|
695 | + // need to do the same for prices (except these prices can also be deleted because again, |
|
696 | + // tickets can only be trashed if they don't have any TKTs sold (otherwise they are just archived)) |
|
697 | + $tkt_to_remove->delete_related_permanently('Price'); |
|
698 | + do_action('AHEE__espresso_events_Pricing_Hooks___update_tkts_delete_ticket', $tkt_to_remove); |
|
699 | + // finally let's delete this ticket |
|
700 | + // (which should not be blocked at this point b/c we've removed all our relationships) |
|
701 | + $tkt_to_remove->delete_permanently(); |
|
702 | + } |
|
703 | + return $saved_tickets; |
|
704 | + } |
|
705 | + |
|
706 | + |
|
707 | + |
|
708 | + /** |
|
709 | + * @access protected |
|
710 | + * @param \EE_Ticket $ticket |
|
711 | + * @param \EE_Datetime[] $saved_datetimes |
|
712 | + * @param \EE_Datetime[] $added_datetimes |
|
713 | + * @param \EE_Datetime[] $removed_datetimes |
|
714 | + * @return \EE_Ticket |
|
715 | + * @throws \EE_Error |
|
716 | + */ |
|
717 | + protected function _update_ticket_datetimes( |
|
718 | + EE_Ticket $ticket, |
|
719 | + $saved_datetimes = array(), |
|
720 | + $added_datetimes = array(), |
|
721 | + $removed_datetimes = array() |
|
722 | + ) { |
|
723 | + // to start we have to add the ticket to all the datetimes its supposed to be with, |
|
724 | + // and removing the ticket from datetimes it got removed from. |
|
725 | + // first let's add datetimes |
|
726 | + if (! empty($added_datetimes) && is_array($added_datetimes)) { |
|
727 | + foreach ($added_datetimes as $row_id) { |
|
728 | + $row_id = (int)$row_id; |
|
729 | + if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
|
730 | + $ticket->_add_relation_to($saved_datetimes[$row_id], 'Datetime'); |
|
731 | + // Is this an existing ticket (has an ID) and does it have any sold? |
|
732 | + // If so, then we need to add that to the DTT sold because this DTT is getting added. |
|
733 | + if ($ticket->ID() && $ticket->sold() > 0) { |
|
734 | + $saved_datetimes[$row_id]->increase_sold($ticket->sold()); |
|
735 | + $saved_datetimes[$row_id]->save(); |
|
736 | + } |
|
737 | + } |
|
738 | + } |
|
739 | + } |
|
740 | + // then remove datetimes |
|
741 | + if (! empty($removed_datetimes) && is_array($removed_datetimes)) { |
|
742 | + foreach ($removed_datetimes as $row_id) { |
|
743 | + $row_id = (int)$row_id; |
|
744 | + // its entirely possible that a datetime got deleted (instead of just removed from relationship. |
|
745 | + // So make sure we skip over this if the dtt isn't in the $saved_datetimes array) |
|
746 | + if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
|
747 | + $ticket->_remove_relation_to($saved_datetimes[$row_id], 'Datetime'); |
|
748 | + // Is this an existing ticket (has an ID) and does it have any sold? |
|
749 | + // If so, then we need to remove it's sold from the DTT_sold. |
|
750 | + if ($ticket->ID() && $ticket->sold() > 0) { |
|
751 | + $saved_datetimes[$row_id]->decrease_sold($ticket->sold()); |
|
752 | + $saved_datetimes[$row_id]->save(); |
|
753 | + } |
|
754 | + } |
|
755 | + } |
|
756 | + } |
|
757 | + // cap ticket qty by datetime reg limits |
|
758 | + $ticket->set_qty(min($ticket->qty(), $ticket->qty('reg_limit'))); |
|
759 | + return $ticket; |
|
760 | + } |
|
761 | + |
|
762 | + |
|
763 | + |
|
764 | + /** |
|
765 | + * @access protected |
|
766 | + * @param \EE_Ticket $ticket |
|
767 | + * @param array $price_rows |
|
768 | + * @param int $ticket_price |
|
769 | + * @param int $base_price |
|
770 | + * @param int $base_price_id |
|
771 | + * @return \EE_Ticket |
|
772 | + * @throws \EE_Error |
|
773 | + */ |
|
774 | + protected function _duplicate_ticket( |
|
775 | + EE_Ticket $ticket, |
|
776 | + $price_rows = array(), |
|
777 | + $ticket_price = 0, |
|
778 | + $base_price = 0, |
|
779 | + $base_price_id = 0 |
|
780 | + ) { |
|
781 | + // create new ticket that's a copy of the existing |
|
782 | + // except a new id of course (and not archived) |
|
783 | + // AND has the new TKT_price associated with it. |
|
784 | + $new_ticket = clone $ticket; |
|
785 | + $new_ticket->set('TKT_ID', 0); |
|
786 | + $new_ticket->set_deleted(0); |
|
787 | + $new_ticket->set_price($ticket_price); |
|
788 | + $new_ticket->set_sold(0); |
|
789 | + // let's get a new ID for this ticket |
|
790 | + $new_ticket->save(); |
|
791 | + // we also need to make sure this new ticket gets the same datetime attachments as the archived ticket |
|
792 | + $datetimes_on_existing = $ticket->datetimes(); |
|
793 | + $new_ticket = $this->_update_ticket_datetimes( |
|
794 | + $new_ticket, |
|
795 | + $datetimes_on_existing, |
|
796 | + array_keys($datetimes_on_existing) |
|
797 | + ); |
|
798 | + // $ticket will get archived later b/c we are NOT adding it to the saved_tickets array. |
|
799 | + // if existing $ticket has sold amount, then we need to adjust the qty for the new TKT to = the remaining |
|
800 | + // available. |
|
801 | + if ($ticket->sold() > 0) { |
|
802 | + $new_qty = $ticket->qty() - $ticket->sold(); |
|
803 | + $new_ticket->set_qty($new_qty); |
|
804 | + } |
|
805 | + //now we update the prices just for this ticket |
|
806 | + $new_ticket = $this->_add_prices_to_ticket($price_rows, $new_ticket, true); |
|
807 | + //and we update the base price |
|
808 | + $new_ticket = $this->_add_prices_to_ticket(array(), $new_ticket, true, $base_price, $base_price_id); |
|
809 | + return $new_ticket; |
|
810 | + } |
|
811 | + |
|
812 | + |
|
813 | + |
|
814 | + /** |
|
815 | + * This attaches a list of given prices to a ticket. |
|
816 | + * Note we dont' have to worry about ever removing relationships (or archiving prices) because if there is a change |
|
817 | + * in price information on a ticket, a new ticket is created anyways so the archived ticket will retain the old |
|
818 | + * price info and prices are automatically "archived" via the ticket. |
|
819 | + * |
|
820 | + * @access private |
|
821 | + * @param array $prices Array of prices from the form. |
|
822 | + * @param EE_Ticket $ticket EE_Ticket object that prices are being attached to. |
|
823 | + * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
|
824 | + * @param int|bool $base_price if FALSE then NOT doing a base price add. |
|
825 | + * @param int|bool $base_price_id if present then this is the base_price_id being updated. |
|
826 | + * @return EE_Ticket |
|
827 | + * @throws EE_Error |
|
828 | + */ |
|
829 | + protected function _add_prices_to_ticket( |
|
830 | + $prices = array(), |
|
831 | + EE_Ticket $ticket, |
|
832 | + $new_prices = false, |
|
833 | + $base_price = false, |
|
834 | + $base_price_id = false |
|
835 | + ) { |
|
836 | + // let's just get any current prices that may exist on the given ticket |
|
837 | + // so we can remove any prices that got trashed in this session. |
|
838 | + $current_prices_on_ticket = $base_price !== false |
|
839 | + ? $ticket->base_price(true) |
|
840 | + : $ticket->price_modifiers(); |
|
841 | + $updated_prices = array(); |
|
842 | + // if $base_price ! FALSE then updating a base price. |
|
843 | + if ($base_price !== false) { |
|
844 | + $prices[1] = array( |
|
845 | + 'PRC_ID' => $new_prices || $base_price_id === 1 ? null : $base_price_id, |
|
846 | + 'PRT_ID' => 1, |
|
847 | + 'PRC_amount' => $base_price, |
|
848 | + 'PRC_name' => $ticket->get('TKT_name'), |
|
849 | + 'PRC_desc' => $ticket->get('TKT_description'), |
|
850 | + ); |
|
851 | + } |
|
852 | + //possibly need to save tkt |
|
853 | + if (! $ticket->ID()) { |
|
854 | + $ticket->save(); |
|
855 | + } |
|
856 | + foreach ($prices as $row => $prc) { |
|
857 | + $prt_id = ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : null; |
|
858 | + if (empty($prt_id)) { |
|
859 | + continue; |
|
860 | + } //prices MUST have a price type id. |
|
861 | + $PRC_values = array( |
|
862 | + 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : null, |
|
863 | + 'PRT_ID' => $prt_id, |
|
864 | + 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
865 | + 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
866 | + 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
867 | + 'PRC_is_default' => false, |
|
868 | + //make sure we set PRC_is_default to false for all ticket saves from event_editor |
|
869 | + 'PRC_order' => $row, |
|
870 | + ); |
|
871 | + if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
872 | + $PRC_values['PRC_ID'] = 0; |
|
873 | + $price = EE_Registry::instance()->load_class( |
|
874 | + 'Price', |
|
875 | + array($PRC_values), |
|
876 | + false, |
|
877 | + false |
|
878 | + ); |
|
879 | + } else { |
|
880 | + $price = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
881 | + //update this price with new values |
|
882 | + foreach ($PRC_values as $field => $value) { |
|
883 | + $price->set($field, $value); |
|
884 | + } |
|
885 | + } |
|
886 | + $price->save(); |
|
887 | + $updated_prices[$price->ID()] = $price; |
|
888 | + $ticket->_add_relation_to($price, 'Price'); |
|
889 | + } |
|
890 | + //now let's remove any prices that got removed from the ticket |
|
891 | + if (! empty ($current_prices_on_ticket)) { |
|
892 | + $current = array_keys($current_prices_on_ticket); |
|
893 | + $updated = array_keys($updated_prices); |
|
894 | + $prices_to_remove = array_diff($current, $updated); |
|
895 | + if (! empty($prices_to_remove)) { |
|
896 | + foreach ($prices_to_remove as $prc_id) { |
|
897 | + $p = $current_prices_on_ticket[$prc_id]; |
|
898 | + $ticket->_remove_relation_to($p, 'Price'); |
|
899 | + //delete permanently the price |
|
900 | + $p->delete_permanently(); |
|
901 | + } |
|
902 | + } |
|
903 | + } |
|
904 | + return $ticket; |
|
905 | + } |
|
906 | + |
|
907 | + |
|
908 | + |
|
909 | + /** |
|
910 | + * @param Events_Admin_Page $event_admin_obj |
|
911 | + * @return Events_Admin_Page |
|
912 | + */ |
|
913 | + public function autosave_handling( Events_Admin_Page $event_admin_obj) |
|
914 | + { |
|
915 | + return $event_admin_obj; |
|
916 | + //doing nothing for the moment. |
|
917 | + // todo when I get to this remember that I need to set the template args on the $event_admin_obj |
|
918 | + // (use the set_template_args() method) |
|
919 | + /** |
|
920 | + * need to remember to handle TICKET DEFAULT saves correctly: I've got two input fields in the dom: |
|
921 | + * 1. TKT_is_default_selector (visible) |
|
922 | + * 2. TKT_is_default (hidden) |
|
923 | + * I think we'll use the TKT_is_default for recording whether the ticket displayed IS a default ticket |
|
924 | + * (on new event creations). Whereas the TKT_is_default_selector is for the user to indicate they want |
|
925 | + * this ticket to be saved as a default. |
|
926 | + * The tricky part is, on an initial display on create or edit (or after manually updating), |
|
927 | + * the TKT_is_default_selector will always be unselected and the TKT_is_default will only be true |
|
928 | + * if this is a create. However, after an autosave, users will want some sort of indicator that |
|
929 | + * the TKT HAS been saved as a default.. |
|
930 | + * in other words we don't want to remove the check on TKT_is_default_selector. So here's what I'm thinking. |
|
931 | + * On Autosave: |
|
932 | + * 1. If TKT_is_default is true: we create a new TKT, send back the new id and add id to related elements, |
|
933 | + * then set the TKT_is_default to false. |
|
934 | + * 2. If TKT_is_default_selector is true: we create/edit existing ticket (following conditions above as well). |
|
935 | + * We do NOT create a new default ticket. The checkbox stays selected after autosave. |
|
936 | + * 3. only on MANUAL update do we check for the selection and if selected create the new default ticket. |
|
937 | + */ |
|
938 | + } |
|
939 | + |
|
940 | + |
|
941 | + |
|
942 | + /** |
|
943 | + * @throws DomainException |
|
944 | + * @throws EE_Error |
|
945 | + */ |
|
946 | + public function pricing_metabox() |
|
947 | + { |
|
948 | + $existing_datetime_ids = $existing_ticket_ids = $datetime_tickets = $ticket_datetimes = array(); |
|
949 | + $event = $this->_adminpage_obj->get_cpt_model_obj(); |
|
950 | + //set is_creating_event property. |
|
951 | + $EVT_ID = $event->ID(); |
|
952 | + $this->_is_creating_event = absint($EVT_ID) === 0; |
|
953 | + //default main template args |
|
954 | + $main_template_args = array( |
|
955 | + 'event_datetime_help_link' => EEH_Template::get_help_tab_link( |
|
956 | + 'event_editor_event_datetimes_help_tab', |
|
957 | + $this->_adminpage_obj->page_slug, |
|
958 | + $this->_adminpage_obj->get_req_action(), |
|
959 | + false, |
|
960 | + false |
|
961 | + ), |
|
962 | + // todo need to add a filter to the template for the help text |
|
963 | + // in the Events_Admin_Page core file so we can add further help |
|
964 | + 'existing_datetime_ids' => '', |
|
965 | + 'total_dtt_rows' => 1, |
|
966 | + 'add_new_dtt_help_link' => EEH_Template::get_help_tab_link( |
|
967 | + 'add_new_dtt_info', |
|
968 | + $this->_adminpage_obj->page_slug, |
|
969 | + $this->_adminpage_obj->get_req_action(), |
|
970 | + false, |
|
971 | + false |
|
972 | + ), |
|
973 | + //todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
974 | + 'datetime_rows' => '', |
|
975 | + 'show_tickets_container' => '', |
|
976 | + //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 1 ? ' style="display:none;"' : '', |
|
977 | + 'ticket_rows' => '', |
|
978 | + 'existing_ticket_ids' => '', |
|
979 | + 'total_ticket_rows' => 1, |
|
980 | + 'ticket_js_structure' => '', |
|
981 | + 'ee_collapsible_status' => ' ee-collapsible-open' |
|
982 | + //$this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 ? ' ee-collapsible-closed' : ' ee-collapsible-open' |
|
983 | + ); |
|
984 | + $timezone = $event instanceof EE_Event ? $event->timezone_string() : null; |
|
985 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
986 | + /** |
|
987 | + * 1. Start with retrieving Datetimes |
|
988 | + * 2. For each datetime get related tickets |
|
989 | + * 3. For each ticket get related prices |
|
990 | + */ |
|
991 | + /** @var EEM_Datetime $datetime_model */ |
|
992 | + $datetime_model = EE_Registry::instance()->load_model('Datetime', array($timezone)); |
|
993 | + $datetimes = $datetime_model->get_all_event_dates($EVT_ID); |
|
994 | + $main_template_args['total_dtt_rows'] = count($datetimes); |
|
995 | + /** |
|
996 | + * @see https://events.codebasehq.com/projects/event-espresso/tickets/9486 |
|
997 | + * for why we are counting $datetime_row and then setting that on the Datetime object |
|
998 | + */ |
|
999 | + $datetime_row = 1; |
|
1000 | + foreach ($datetimes as $datetime) { |
|
1001 | + $DTT_ID = $datetime->get('DTT_ID'); |
|
1002 | + $datetime->set('DTT_order', $datetime_row); |
|
1003 | + $existing_datetime_ids[] = $DTT_ID; |
|
1004 | + //tickets attached |
|
1005 | + $related_tickets = $datetime->ID() > 0 |
|
1006 | + ? $datetime->get_many_related( |
|
1007 | + 'Ticket', |
|
1008 | + array( |
|
1009 | + array( |
|
1010 | + 'OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0), |
|
1011 | + ), |
|
1012 | + 'default_where_conditions' => 'none', |
|
1013 | + 'order_by' => array('TKT_order' => 'ASC'), |
|
1014 | + ) |
|
1015 | + ) |
|
1016 | + : array(); |
|
1017 | + //if there are no related tickets this is likely a new event OR autodraft |
|
1018 | + // event so we need to generate the default tickets because datetimes |
|
1019 | + // ALWAYS have at least one related ticket!!. EXCEPT, we dont' do this if there is already more than one |
|
1020 | + // datetime on the event. |
|
1021 | + if (empty ($related_tickets) && count($datetimes) < 2) { |
|
1022 | + /** @var EEM_Ticket $ticket_model */ |
|
1023 | + $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
1024 | + $related_tickets = $ticket_model->get_all_default_tickets(); |
|
1025 | + // this should be ordered by TKT_ID, so let's grab the first default ticket |
|
1026 | + // (which will be the main default) and ensure it has any default prices added to it (but do NOT save). |
|
1027 | + $default_prices = EEM_Price::instance()->get_all_default_prices(); |
|
1028 | + $main_default_ticket = reset($related_tickets); |
|
1029 | + if ($main_default_ticket instanceof EE_Ticket) { |
|
1030 | + foreach ($default_prices as $default_price) { |
|
1031 | + if ($default_price instanceof EE_Price && $default_price->is_base_price()) { |
|
1032 | + continue; |
|
1033 | + } |
|
1034 | + $main_default_ticket->cache('Price', $default_price); |
|
1035 | + } |
|
1036 | + } |
|
1037 | + } |
|
1038 | + // we can't actually setup rows in this loop yet cause we don't know all |
|
1039 | + // the unique tickets for this event yet (tickets are linked through all datetimes). |
|
1040 | + // So we're going to temporarily cache some of that information. |
|
1041 | + //loop through and setup the ticket rows and make sure the order is set. |
|
1042 | + foreach ($related_tickets as $ticket) { |
|
1043 | + $TKT_ID = $ticket->get('TKT_ID'); |
|
1044 | + $ticket_row = $ticket->get('TKT_row'); |
|
1045 | + //we only want unique tickets in our final display!! |
|
1046 | + if (! in_array($TKT_ID, $existing_ticket_ids, true)) { |
|
1047 | + $existing_ticket_ids[] = $TKT_ID; |
|
1048 | + $all_tickets[] = $ticket; |
|
1049 | + } |
|
1050 | + //temporary cache of this ticket info for this datetime for later processing of datetime rows. |
|
1051 | + $datetime_tickets[$DTT_ID][] = $ticket_row; |
|
1052 | + //temporary cache of this datetime info for this ticket for later processing of ticket rows. |
|
1053 | + if ( |
|
1054 | + ! isset($ticket_datetimes[$TKT_ID]) |
|
1055 | + || ! in_array($datetime_row, $ticket_datetimes[$TKT_ID], true) |
|
1056 | + ) { |
|
1057 | + $ticket_datetimes[$TKT_ID][] = $datetime_row; |
|
1058 | + } |
|
1059 | + } |
|
1060 | + $datetime_row++; |
|
1061 | + } |
|
1062 | + $main_template_args['total_ticket_rows'] = count($existing_ticket_ids); |
|
1063 | + $main_template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
|
1064 | + $main_template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
|
1065 | + //sort $all_tickets by order |
|
1066 | + usort( |
|
1067 | + $all_tickets, |
|
1068 | + function (EE_Ticket $a, EE_Ticket $b) { |
|
1069 | + $a_order = (int)$a->get('TKT_order'); |
|
1070 | + $b_order = (int)$b->get('TKT_order'); |
|
1071 | + if ($a_order === $b_order) { |
|
1072 | + return 0; |
|
1073 | + } |
|
1074 | + return ($a_order < $b_order) ? -1 : 1; |
|
1075 | + } |
|
1076 | + ); |
|
1077 | + // k NOW we have all the data we need for setting up the dtt rows |
|
1078 | + // and ticket rows so we start our dtt loop again. |
|
1079 | + $datetime_row = 1; |
|
1080 | + foreach ($datetimes as $datetime) { |
|
1081 | + $main_template_args['datetime_rows'] .= $this->_get_datetime_row( |
|
1082 | + $datetime_row, |
|
1083 | + $datetime, |
|
1084 | + $datetime_tickets, |
|
1085 | + $all_tickets, |
|
1086 | + false, |
|
1087 | + $datetimes |
|
1088 | + ); |
|
1089 | + $datetime_row++; |
|
1090 | + } |
|
1091 | + //then loop through all tickets for the ticket rows. |
|
1092 | + $ticket_row = 1; |
|
1093 | + foreach ($all_tickets as $ticket) { |
|
1094 | + $main_template_args['ticket_rows'] .= $this->_get_ticket_row( |
|
1095 | + $ticket_row, |
|
1096 | + $ticket, |
|
1097 | + $ticket_datetimes, |
|
1098 | + $datetimes, |
|
1099 | + false, |
|
1100 | + $all_tickets |
|
1101 | + ); |
|
1102 | + $ticket_row++; |
|
1103 | + } |
|
1104 | + $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets); |
|
1105 | + EEH_Template::display_template( |
|
1106 | + PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php', |
|
1107 | + $main_template_args |
|
1108 | + ); |
|
1109 | + } |
|
1110 | + |
|
1111 | + |
|
1112 | + |
|
1113 | + /** |
|
1114 | + * @param int $datetime_row |
|
1115 | + * @param EE_Datetime $datetime |
|
1116 | + * @param array $datetime_tickets |
|
1117 | + * @param array $all_tickets |
|
1118 | + * @param bool $default |
|
1119 | + * @param array $all_datetimes |
|
1120 | + * @return mixed |
|
1121 | + * @throws DomainException |
|
1122 | + * @throws EE_Error |
|
1123 | + */ |
|
1124 | + protected function _get_datetime_row( |
|
1125 | + $datetime_row, |
|
1126 | + EE_Datetime $datetime, |
|
1127 | + $datetime_tickets = array(), |
|
1128 | + $all_tickets = array(), |
|
1129 | + $default = false, |
|
1130 | + $all_datetimes = array() |
|
1131 | + ) { |
|
1132 | + $dtt_display_template_args = array( |
|
1133 | + 'dtt_edit_row' => $this->_get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes), |
|
1134 | + 'dtt_attached_tickets_row' => $this->_get_dtt_attached_tickets_row( |
|
1135 | + $datetime_row, |
|
1136 | + $datetime, |
|
1137 | + $datetime_tickets, |
|
1138 | + $all_tickets, |
|
1139 | + $default |
|
1140 | + ), |
|
1141 | + 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
1142 | + ); |
|
1143 | + return EEH_Template::display_template( |
|
1144 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php', |
|
1145 | + $dtt_display_template_args, |
|
1146 | + true |
|
1147 | + ); |
|
1148 | + } |
|
1149 | + |
|
1150 | + |
|
1151 | + |
|
1152 | + /** |
|
1153 | + * This method is used to generate a dtt fields edit row. |
|
1154 | + * The same row is used to generate a row with valid DTT objects |
|
1155 | + * and the default row that is used as the skeleton by the js. |
|
1156 | + * |
|
1157 | + * @param int $datetime_row The row number for the row being generated. |
|
1158 | + * @param EE_Datetime $datetime |
|
1159 | + * @param bool $default Whether a default row is being generated or not. |
|
1160 | + * @param EE_Datetime[] $all_datetimes This is the array of all datetimes used in the editor. |
|
1161 | + * @return string |
|
1162 | + * @throws DomainException |
|
1163 | + * @throws EE_Error |
|
1164 | + */ |
|
1165 | + protected function _get_dtt_edit_row($datetime_row, $datetime, $default, $all_datetimes) |
|
1166 | + { |
|
1167 | + // if the incoming $datetime object is NOT an instance of EE_Datetime then force default to true. |
|
1168 | + $default = ! $datetime instanceof EE_Datetime ? true : $default; |
|
1169 | + $template_args = array( |
|
1170 | + 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
1171 | + 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
1172 | + 'edit_dtt_expanded' => '', |
|
1173 | + 'DTT_ID' => $default ? '' : $datetime->ID(), |
|
1174 | + 'DTT_name' => $default ? '' : $datetime->name(), |
|
1175 | + 'DTT_description' => $default ? '' : $datetime->description(), |
|
1176 | + 'DTT_EVT_start' => $default ? '' : $datetime->start_date($this->_date_time_format), |
|
1177 | + 'DTT_EVT_end' => $default ? '' : $datetime->end_date($this->_date_time_format), |
|
1178 | + 'DTT_reg_limit' => $default |
|
1179 | + ? '' |
|
1180 | + : $datetime->get_pretty( |
|
1181 | + 'DTT_reg_limit', |
|
1182 | + 'input' |
|
1183 | + ), |
|
1184 | + 'DTT_order' => $default ? 'DTTNUM' : $datetime_row, |
|
1185 | + 'dtt_sold' => $default ? '0' : $datetime->get('DTT_sold'), |
|
1186 | + 'dtt_reserved' => $default ? '0' : $datetime->reserved(), |
|
1187 | + 'clone_icon' => ! empty($datetime) && $datetime->get('DTT_sold') > 0 |
|
1188 | + ? '' |
|
1189 | + : 'clone-icon ee-icon ee-icon-clone clickable', |
|
1190 | + 'trash_icon' => ! empty($datetime) && $datetime->get('DTT_sold') > 0 |
|
1191 | + ? 'ee-lock-icon' |
|
1192 | + : 'trash-icon dashicons dashicons-post-trash clickable', |
|
1193 | + 'reg_list_url' => $default || ! $datetime->event() instanceof \EE_Event |
|
1194 | + ? '' |
|
1195 | + : EE_Admin_Page::add_query_args_and_nonce( |
|
1196 | + array('event_id' => $datetime->event()->ID(), 'datetime_id' => $datetime->ID()), |
|
1197 | + REG_ADMIN_URL |
|
1198 | + ), |
|
1199 | + ); |
|
1200 | + $template_args['show_trash'] = count($all_datetimes) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' |
|
1201 | + ? ' style="display:none"' |
|
1202 | + : ''; |
|
1203 | + //allow filtering of template args at this point. |
|
1204 | + $template_args = apply_filters( |
|
1205 | + 'FHEE__espresso_events_Pricing_Hooks___get_dtt_edit_row__template_args', |
|
1206 | + $template_args, |
|
1207 | + $datetime_row, |
|
1208 | + $datetime, |
|
1209 | + $default, |
|
1210 | + $all_datetimes, |
|
1211 | + $this->_is_creating_event |
|
1212 | + ); |
|
1213 | + return EEH_Template::display_template( |
|
1214 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php', |
|
1215 | + $template_args, |
|
1216 | + true |
|
1217 | + ); |
|
1218 | + } |
|
1219 | + |
|
1220 | + |
|
1221 | + |
|
1222 | + /** |
|
1223 | + * @param int $datetime_row |
|
1224 | + * @param EE_Datetime $datetime |
|
1225 | + * @param array $datetime_tickets |
|
1226 | + * @param array $all_tickets |
|
1227 | + * @param bool $default |
|
1228 | + * @return mixed |
|
1229 | + * @throws DomainException |
|
1230 | + * @throws EE_Error |
|
1231 | + */ |
|
1232 | + protected function _get_dtt_attached_tickets_row( |
|
1233 | + $datetime_row, |
|
1234 | + $datetime, |
|
1235 | + $datetime_tickets = array(), |
|
1236 | + $all_tickets = array(), |
|
1237 | + $default |
|
1238 | + ) { |
|
1239 | + $template_args = array( |
|
1240 | + 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
|
1241 | + 'event_datetimes_name' => $default ? 'DTTNAMEATTR' : 'edit_event_datetimes', |
|
1242 | + 'DTT_description' => $default ? '' : $datetime->description(), |
|
1243 | + 'datetime_tickets_list' => $default ? '<li class="hidden"></li>' : '', |
|
1244 | + 'show_tickets_row' => ' style="display:none;"', |
|
1245 | + 'add_new_datetime_ticket_help_link' => EEH_Template::get_help_tab_link( |
|
1246 | + 'add_new_ticket_via_datetime', |
|
1247 | + $this->_adminpage_obj->page_slug, |
|
1248 | + $this->_adminpage_obj->get_req_action(), |
|
1249 | + false, |
|
1250 | + false |
|
1251 | + ), |
|
1252 | + //todo need to add this help info id to the Events_Admin_Page core file so we can access it here. |
|
1253 | + 'DTT_ID' => $default ? '' : $datetime->ID(), |
|
1254 | + ); |
|
1255 | + //need to setup the list items (but only if this isn't a default skeleton setup) |
|
1256 | + if (! $default) { |
|
1257 | + $ticket_row = 1; |
|
1258 | + foreach ($all_tickets as $ticket) { |
|
1259 | + $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
|
1260 | + $datetime_row, |
|
1261 | + $ticket_row, |
|
1262 | + $datetime, |
|
1263 | + $ticket, |
|
1264 | + $datetime_tickets, |
|
1265 | + $default |
|
1266 | + ); |
|
1267 | + $ticket_row++; |
|
1268 | + } |
|
1269 | + } |
|
1270 | + //filter template args at this point |
|
1271 | + $template_args = apply_filters( |
|
1272 | + 'FHEE__espresso_events_Pricing_Hooks___get_dtt_attached_ticket_row__template_args', |
|
1273 | + $template_args, |
|
1274 | + $datetime_row, |
|
1275 | + $datetime, |
|
1276 | + $datetime_tickets, |
|
1277 | + $all_tickets, |
|
1278 | + $default, |
|
1279 | + $this->_is_creating_event |
|
1280 | + ); |
|
1281 | + return EEH_Template::display_template( |
|
1282 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php', |
|
1283 | + $template_args, |
|
1284 | + true |
|
1285 | + ); |
|
1286 | + } |
|
1287 | + |
|
1288 | + |
|
1289 | + |
|
1290 | + /** |
|
1291 | + * @param int $datetime_row |
|
1292 | + * @param int $ticket_row |
|
1293 | + * @param EE_Datetime $datetime |
|
1294 | + * @param EE_Ticket $ticket |
|
1295 | + * @param array $datetime_tickets |
|
1296 | + * @param bool $default |
|
1297 | + * @return mixed |
|
1298 | + * @throws DomainException |
|
1299 | + * @throws EE_Error |
|
1300 | + */ |
|
1301 | + protected function _get_datetime_tickets_list_item( |
|
1302 | + $datetime_row, |
|
1303 | + $ticket_row, |
|
1304 | + $datetime, |
|
1305 | + $ticket, |
|
1306 | + $datetime_tickets = array(), |
|
1307 | + $default |
|
1308 | + ) { |
|
1309 | + $dtt_tkts = $datetime instanceof EE_Datetime && isset($datetime_tickets[$datetime->ID()]) |
|
1310 | + ? $datetime_tickets[$datetime->ID()] |
|
1311 | + : array(); |
|
1312 | + $display_row = $ticket instanceof EE_Ticket ? $ticket->get('TKT_row') : 0; |
|
1313 | + $no_ticket = $default && empty($ticket); |
|
1314 | + $template_args = array( |
|
1315 | + 'dtt_row' => $default |
|
1316 | + ? 'DTTNUM' |
|
1317 | + : $datetime_row, |
|
1318 | + 'tkt_row' => $no_ticket |
|
1319 | + ? 'TICKETNUM' |
|
1320 | + : $ticket_row, |
|
1321 | + 'datetime_ticket_checked' => in_array($display_row, $dtt_tkts, true) |
|
1322 | + ? ' checked="checked"' |
|
1323 | + : '', |
|
1324 | + 'ticket_selected' => in_array($display_row, $dtt_tkts, true) |
|
1325 | + ? ' ticket-selected' |
|
1326 | + : '', |
|
1327 | + 'TKT_name' => $no_ticket |
|
1328 | + ? 'TKTNAME' |
|
1329 | + : $ticket->get('TKT_name'), |
|
1330 | + 'tkt_status_class' => $no_ticket || $this->_is_creating_event |
|
1331 | + ? ' tkt-status-' . EE_Ticket::onsale |
|
1332 | + : ' tkt-status-' . $ticket->ticket_status(), |
|
1333 | + ); |
|
1334 | + //filter template args |
|
1335 | + $template_args = apply_filters( |
|
1336 | + 'FHEE__espresso_events_Pricing_Hooks___get_datetime_tickets_list_item__template_args', |
|
1337 | + $template_args, |
|
1338 | + $datetime_row, |
|
1339 | + $ticket_row, |
|
1340 | + $datetime, |
|
1341 | + $ticket, |
|
1342 | + $datetime_tickets, |
|
1343 | + $default, |
|
1344 | + $this->_is_creating_event |
|
1345 | + ); |
|
1346 | + return EEH_Template::display_template( |
|
1347 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php', |
|
1348 | + $template_args, |
|
1349 | + true |
|
1350 | + ); |
|
1351 | + } |
|
1352 | + |
|
1353 | + |
|
1354 | + |
|
1355 | + /** |
|
1356 | + * This generates the ticket row for tickets. |
|
1357 | + * This same method is used to generate both the actual rows and the js skeleton row |
|
1358 | + * (when default === true) |
|
1359 | + * |
|
1360 | + * @param int $ticket_row Represents the row number being generated. |
|
1361 | + * @param $ticket |
|
1362 | + * @param EE_Datetime[] $ticket_datetimes Either an array of all datetimes on all tickets indexed by each ticket |
|
1363 | + * or empty for default |
|
1364 | + * @param EE_Datetime[] $all_datetimes All Datetimes on the event or empty for default. |
|
1365 | + * @param bool $default Whether default row being generated or not. |
|
1366 | + * @param EE_Ticket[] $all_tickets This is an array of all tickets attached to the event |
|
1367 | + * (or empty in the case of defaults) |
|
1368 | + * @return mixed |
|
1369 | + * @throws DomainException |
|
1370 | + * @throws EE_Error |
|
1371 | + */ |
|
1372 | + protected function _get_ticket_row( |
|
1373 | + $ticket_row, |
|
1374 | + $ticket, |
|
1375 | + $ticket_datetimes, |
|
1376 | + $all_datetimes, |
|
1377 | + $default = false, |
|
1378 | + $all_tickets = array() |
|
1379 | + ) { |
|
1380 | + // if $ticket is not an instance of EE_Ticket then force default to true. |
|
1381 | + $default = ! $ticket instanceof EE_Ticket ? true : $default; |
|
1382 | + $prices = ! empty($ticket) && ! $default ? $ticket->get_many_related('Price', |
|
1383 | + array('default_where_conditions' => 'none', 'order_by' => array('PRC_order' => 'ASC'))) : array(); |
|
1384 | + // if there is only one price (which would be the base price) |
|
1385 | + // or NO prices and this ticket is a default ticket, |
|
1386 | + // let's just make sure there are no cached default prices on the object. |
|
1387 | + // This is done by not including any query_params. |
|
1388 | + if ($ticket instanceof EE_Ticket && $ticket->is_default() && (count($prices) === 1 || empty($prices))) { |
|
1389 | + $prices = $ticket->prices(); |
|
1390 | + } |
|
1391 | + // check if we're dealing with a default ticket in which case |
|
1392 | + // we don't want any starting_ticket_datetime_row values set |
|
1393 | + // (otherwise there won't be any new relationships created for tickets based off of the default ticket). |
|
1394 | + // This will future proof in case there is ever any behaviour change between what the primary_key defaults to. |
|
1395 | + $default_dtt = $default || ($ticket instanceof EE_Ticket && $ticket->is_default()); |
|
1396 | + $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) |
|
1397 | + ? $ticket_datetimes[$ticket->ID()] |
|
1398 | + : array(); |
|
1399 | + $ticket_subtotal = $default ? 0 : $ticket->get_ticket_subtotal(); |
|
1400 | + $base_price = $default ? null : $ticket->base_price(); |
|
1401 | + $count_price_mods = EEM_Price::instance()->get_all_default_prices(true); |
|
1402 | + //breaking out complicated condition for ticket_status |
|
1403 | + if ($default) { |
|
1404 | + $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale; |
|
1405 | + } else { |
|
1406 | + $ticket_status_class = $ticket->is_default() |
|
1407 | + ? ' tkt-status-' . EE_Ticket::onsale |
|
1408 | + : ' tkt-status-' . $ticket->ticket_status(); |
|
1409 | + } |
|
1410 | + //breaking out complicated condition for TKT_taxable |
|
1411 | + if ($default) { |
|
1412 | + $TKT_taxable = ''; |
|
1413 | + } else { |
|
1414 | + $TKT_taxable = $ticket->taxable() |
|
1415 | + ? ' checked="checked"' |
|
1416 | + : ''; |
|
1417 | + } |
|
1418 | + if ($default) { |
|
1419 | + $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence'); |
|
1420 | + } elseif ($ticket->is_default()) { |
|
1421 | + $TKT_status = EEH_Template::pretty_status(EE_Ticket::onsale, false, 'sentence'); |
|
1422 | + } else { |
|
1423 | + $TKT_status = $ticket->ticket_status(true); |
|
1424 | + } |
|
1425 | + if ($default) { |
|
1426 | + $TKT_min = ''; |
|
1427 | + } else { |
|
1428 | + $TKT_min = $ticket->min(); |
|
1429 | + if ($TKT_min === -1 || $TKT_min === 0) { |
|
1430 | + $TKT_min = ''; |
|
1431 | + } |
|
1432 | + } |
|
1433 | + $template_args = array( |
|
1434 | + 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
1435 | + 'TKT_order' => $default ? 'TICKETNUM' : $ticket_row, |
|
1436 | + //on initial page load this will always be the correct order. |
|
1437 | + 'tkt_status_class' => $ticket_status_class, |
|
1438 | + 'display_edit_tkt_row' => ' style="display:none;"', |
|
1439 | + 'edit_tkt_expanded' => '', |
|
1440 | + 'edit_tickets_name' => $default ? 'TICKETNAMEATTR' : 'edit_tickets', |
|
1441 | + 'TKT_name' => $default ? '' : $ticket->name(), |
|
1442 | + 'TKT_start_date' => $default |
|
1443 | + ? '' |
|
1444 | + : $ticket->get_date('TKT_start_date', $this->_date_time_format), |
|
1445 | + 'TKT_end_date' => $default |
|
1446 | + ? '' |
|
1447 | + : $ticket->get_date('TKT_end_date', $this->_date_time_format), |
|
1448 | + 'TKT_status' => $TKT_status, |
|
1449 | + 'TKT_price' => $default |
|
1450 | + ? '' |
|
1451 | + : EEH_Template::format_currency( |
|
1452 | + $ticket->get_ticket_total_with_taxes(), |
|
1453 | + false, |
|
1454 | + false |
|
1455 | + ), |
|
1456 | + 'TKT_price_code' => EE_Registry::instance()->CFG->currency->code, |
|
1457 | + 'TKT_price_amount' => $default ? 0 : $ticket_subtotal, |
|
1458 | + 'TKT_qty' => $default |
|
1459 | + ? '' |
|
1460 | + : $ticket->get_pretty('TKT_qty', 'symbol'), |
|
1461 | + 'TKT_qty_for_input' => $default |
|
1462 | + ? '' |
|
1463 | + : $ticket->get_pretty('TKT_qty', 'input'), |
|
1464 | + 'TKT_uses' => $default |
|
1465 | + ? '' |
|
1466 | + : $ticket->get_pretty('TKT_uses', 'input'), |
|
1467 | + 'TKT_min' => $TKT_min, |
|
1468 | + 'TKT_max' => $default |
|
1469 | + ? '' |
|
1470 | + : $ticket->get_pretty('TKT_max', 'input'), |
|
1471 | + 'TKT_sold' => $default ? 0 : $ticket->tickets_sold('ticket'), |
|
1472 | + 'TKT_reserved' => $default ? 0 : $ticket->reserved(), |
|
1473 | + 'TKT_registrations' => $default |
|
1474 | + ? 0 |
|
1475 | + : $ticket->count_registrations( |
|
1476 | + array( |
|
1477 | + array( |
|
1478 | + 'STS_ID' => array( |
|
1479 | + '!=', |
|
1480 | + EEM_Registration::status_id_incomplete, |
|
1481 | + ), |
|
1482 | + ), |
|
1483 | + ) |
|
1484 | + ), |
|
1485 | + 'TKT_ID' => $default ? 0 : $ticket->ID(), |
|
1486 | + 'TKT_description' => $default ? '' : $ticket->description(), |
|
1487 | + 'TKT_is_default' => $default ? 0 : $ticket->is_default(), |
|
1488 | + 'TKT_required' => $default ? 0 : $ticket->required(), |
|
1489 | + 'TKT_is_default_selector' => '', |
|
1490 | + 'ticket_price_rows' => '', |
|
1491 | + 'TKT_base_price' => $default || ! $base_price instanceof EE_Price |
|
1492 | + ? '' |
|
1493 | + : $base_price->get_pretty('PRC_amount', 'localized_float'), |
|
1494 | + 'TKT_base_price_ID' => $default || ! $base_price instanceof EE_Price ? 0 : $base_price->ID(), |
|
1495 | + 'show_price_modifier' => count($prices) > 1 || ($default && $count_price_mods > 0) |
|
1496 | + ? '' |
|
1497 | + : ' style="display:none;"', |
|
1498 | + 'show_price_mod_button' => count($prices) > 1 |
|
1499 | + || ($default && $count_price_mods > 0) |
|
1500 | + || (! $default && $ticket->deleted()) |
|
1501 | + ? ' style="display:none;"' |
|
1502 | + : '', |
|
1503 | + 'total_price_rows' => count($prices) > 1 ? count($prices) : 1, |
|
1504 | + 'ticket_datetimes_list' => $default ? '<li class="hidden"></li>' : '', |
|
1505 | + 'starting_ticket_datetime_rows' => $default || $default_dtt ? '' : implode(',', $tkt_datetimes), |
|
1506 | + 'ticket_datetime_rows' => $default ? '' : implode(',', $tkt_datetimes), |
|
1507 | + 'existing_ticket_price_ids' => $default ? '' : implode(',', array_keys($prices)), |
|
1508 | + 'ticket_template_id' => $default ? 0 : $ticket->get('TTM_ID'), |
|
1509 | + 'TKT_taxable' => $TKT_taxable, |
|
1510 | + 'display_subtotal' => $ticket instanceof EE_Ticket && $ticket->taxable() |
|
1511 | + ? '' |
|
1512 | + : ' style="display:none"', |
|
1513 | + 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
1514 | + 'TKT_subtotal_amount_display' => EEH_Template::format_currency( |
|
1515 | + $ticket_subtotal, |
|
1516 | + false, |
|
1517 | + false |
|
1518 | + ), |
|
1519 | + 'TKT_subtotal_amount' => $ticket_subtotal, |
|
1520 | + 'tax_rows' => $this->_get_tax_rows($ticket_row, $ticket), |
|
1521 | + 'disabled' => $ticket instanceof EE_Ticket && $ticket->deleted(), |
|
1522 | + 'ticket_archive_class' => $ticket instanceof EE_Ticket && $ticket->deleted() |
|
1523 | + ? ' ticket-archived' |
|
1524 | + : '', |
|
1525 | + 'trash_icon' => $ticket instanceof EE_Ticket |
|
1526 | + && $ticket->deleted() |
|
1527 | + && ! $ticket->is_permanently_deleteable() |
|
1528 | + ? 'ee-lock-icon ' |
|
1529 | + : 'trash-icon dashicons dashicons-post-trash clickable', |
|
1530 | + 'clone_icon' => $ticket instanceof EE_Ticket && $ticket->deleted() |
|
1531 | + ? '' |
|
1532 | + : 'clone-icon ee-icon ee-icon-clone clickable', |
|
1533 | + ); |
|
1534 | + $template_args['trash_hidden'] = count($all_tickets) === 1 && $template_args['trash_icon'] !== 'ee-lock-icon' |
|
1535 | + ? ' style="display:none"' |
|
1536 | + : ''; |
|
1537 | + //handle rows that should NOT be empty |
|
1538 | + if (empty($template_args['TKT_start_date'])) { |
|
1539 | + //if empty then the start date will be now. |
|
1540 | + $template_args['TKT_start_date'] = date($this->_date_time_format, |
|
1541 | + current_time('timestamp')); |
|
1542 | + $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
1543 | + } |
|
1544 | + if (empty($template_args['TKT_end_date'])) { |
|
1545 | + //get the earliest datetime (if present); |
|
1546 | + $earliest_dtt = $this->_adminpage_obj->get_cpt_model_obj()->ID() > 0 |
|
1547 | + ? $this->_adminpage_obj->get_cpt_model_obj()->get_first_related( |
|
1548 | + 'Datetime', |
|
1549 | + array('order_by' => array('DTT_EVT_start' => 'ASC')) |
|
1550 | + ) |
|
1551 | + : null; |
|
1552 | + if (! empty($earliest_dtt)) { |
|
1553 | + $template_args['TKT_end_date'] = $earliest_dtt->get_datetime( |
|
1554 | + 'DTT_EVT_start', |
|
1555 | + $this->_date_time_format |
|
1556 | + ); |
|
1557 | + } else { |
|
1558 | + //default so let's just use what's been set for the default date-time which is 30 days from now. |
|
1559 | + $template_args['TKT_end_date'] = date( |
|
1560 | + $this->_date_time_format, |
|
1561 | + mktime(24, 0, 0, date('m'), date('d') + 29, date('Y') |
|
1562 | + ) |
|
1563 | + ); |
|
1564 | + } |
|
1565 | + $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
1566 | + } |
|
1567 | + //generate ticket_datetime items |
|
1568 | + if (! $default) { |
|
1569 | + $datetime_row = 1; |
|
1570 | + foreach ($all_datetimes as $datetime) { |
|
1571 | + $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
|
1572 | + $datetime_row, |
|
1573 | + $ticket_row, |
|
1574 | + $datetime, |
|
1575 | + $ticket, |
|
1576 | + $ticket_datetimes, |
|
1577 | + $default |
|
1578 | + ); |
|
1579 | + $datetime_row++; |
|
1580 | + } |
|
1581 | + } |
|
1582 | + $price_row = 1; |
|
1583 | + foreach ($prices as $price) { |
|
1584 | + if (! $price instanceof EE_Price) { |
|
1585 | + continue; |
|
1586 | + } |
|
1587 | + if ($price->is_base_price()) { |
|
1588 | + $price_row++; |
|
1589 | + continue; |
|
1590 | + } |
|
1591 | + $show_trash = !((count($prices) > 1 && $price_row === 1) || count($prices) === 1); |
|
1592 | + $show_create = !(count($prices) > 1 && count($prices) !== $price_row); |
|
1593 | + $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row( |
|
1594 | + $ticket_row, |
|
1595 | + $price_row, |
|
1596 | + $price, |
|
1597 | + $default, |
|
1598 | + $ticket, |
|
1599 | + $show_trash, |
|
1600 | + $show_create |
|
1601 | + ); |
|
1602 | + $price_row++; |
|
1603 | + } |
|
1604 | + //filter $template_args |
|
1605 | + $template_args = apply_filters( |
|
1606 | + 'FHEE__espresso_events_Pricing_Hooks___get_ticket_row__template_args', |
|
1607 | + $template_args, |
|
1608 | + $ticket_row, |
|
1609 | + $ticket, |
|
1610 | + $ticket_datetimes, |
|
1611 | + $all_datetimes, |
|
1612 | + $default, |
|
1613 | + $all_tickets, |
|
1614 | + $this->_is_creating_event |
|
1615 | + ); |
|
1616 | + return EEH_Template::display_template( |
|
1617 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php', |
|
1618 | + $template_args, |
|
1619 | + true |
|
1620 | + ); |
|
1621 | + } |
|
1622 | + |
|
1623 | + |
|
1624 | + |
|
1625 | + /** |
|
1626 | + * @param int $ticket_row |
|
1627 | + * @param EE_Ticket|null $ticket |
|
1628 | + * @return string |
|
1629 | + * @throws DomainException |
|
1630 | + * @throws EE_Error |
|
1631 | + */ |
|
1632 | + protected function _get_tax_rows($ticket_row, $ticket) |
|
1633 | + { |
|
1634 | + $tax_rows = ''; |
|
1635 | + /** @var EE_Price[] $taxes */ |
|
1636 | + $taxes = empty($ticket) ? EE_Taxes::get_taxes_for_admin() : $ticket->get_ticket_taxes_for_admin(); |
|
1637 | + foreach ($taxes as $tax) { |
|
1638 | + $tax_added = $this->_get_tax_added($tax, $ticket); |
|
1639 | + $template_args = array( |
|
1640 | + 'display_tax' => ! empty($ticket) && $ticket->get('TKT_taxable') |
|
1641 | + ? '' |
|
1642 | + : ' style="display:none;"', |
|
1643 | + 'tax_id' => $tax->ID(), |
|
1644 | + 'tkt_row' => $ticket_row, |
|
1645 | + 'tax_label' => $tax->get('PRC_name'), |
|
1646 | + 'tax_added' => $tax_added, |
|
1647 | + 'tax_added_display' => EEH_Template::format_currency($tax_added, false, false), |
|
1648 | + 'tax_amount' => $tax->get('PRC_amount'), |
|
1649 | + ); |
|
1650 | + $template_args = apply_filters( |
|
1651 | + 'FHEE__espresso_events_Pricing_Hooks___get_tax_rows__template_args', |
|
1652 | + $template_args, |
|
1653 | + $ticket_row, |
|
1654 | + $ticket, |
|
1655 | + $this->_is_creating_event |
|
1656 | + ); |
|
1657 | + $tax_rows .= EEH_Template::display_template( |
|
1658 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php', |
|
1659 | + $template_args, |
|
1660 | + true |
|
1661 | + ); |
|
1662 | + } |
|
1663 | + return $tax_rows; |
|
1664 | + } |
|
1665 | + |
|
1666 | + |
|
1667 | + |
|
1668 | + /** |
|
1669 | + * @param EE_Price $tax |
|
1670 | + * @param EE_Ticket|null $ticket |
|
1671 | + * @return float|int |
|
1672 | + * @throws EE_Error |
|
1673 | + */ |
|
1674 | + protected function _get_tax_added(EE_Price $tax, $ticket) |
|
1675 | + { |
|
1676 | + $subtotal = empty($ticket) ? 0 : $ticket->get_ticket_subtotal(); |
|
1677 | + return $subtotal * $tax->get('PRC_amount') / 100; |
|
1678 | + } |
|
1679 | + |
|
1680 | + |
|
1681 | + |
|
1682 | + /** |
|
1683 | + * @param int $ticket_row |
|
1684 | + * @param int $price_row |
|
1685 | + * @param EE_Price|null $price |
|
1686 | + * @param bool $default |
|
1687 | + * @param EE_Ticket|null $ticket |
|
1688 | + * @param bool $show_trash |
|
1689 | + * @param bool $show_create |
|
1690 | + * @return mixed |
|
1691 | + * @throws DomainException |
|
1692 | + * @throws EE_Error |
|
1693 | + */ |
|
1694 | + protected function _get_ticket_price_row( |
|
1695 | + $ticket_row, |
|
1696 | + $price_row, |
|
1697 | + $price, |
|
1698 | + $default, |
|
1699 | + $ticket, |
|
1700 | + $show_trash = true, |
|
1701 | + $show_create = true |
|
1702 | + ) { |
|
1703 | + $send_disabled = ! empty($ticket) && $ticket->get('TKT_deleted'); |
|
1704 | + $template_args = array( |
|
1705 | + 'tkt_row' => $default && empty($ticket) |
|
1706 | + ? 'TICKETNUM' |
|
1707 | + : $ticket_row, |
|
1708 | + 'PRC_order' => $default && empty($price) |
|
1709 | + ? 'PRICENUM' |
|
1710 | + : $price_row, |
|
1711 | + 'edit_prices_name' => $default && empty($price) |
|
1712 | + ? 'PRICENAMEATTR' |
|
1713 | + : 'edit_prices', |
|
1714 | + 'price_type_selector' => $default && empty($price) |
|
1715 | + ? $this->_get_base_price_template($ticket_row, $price_row, $price, $default) |
|
1716 | + : $this->_get_price_type_selector($ticket_row, $price_row, $price, $default, $send_disabled), |
|
1717 | + 'PRC_ID' => $default && empty($price) |
|
1718 | + ? 0 |
|
1719 | + : $price->ID(), |
|
1720 | + 'PRC_is_default' => $default && empty($price) |
|
1721 | + ? 0 |
|
1722 | + : $price->get('PRC_is_default'), |
|
1723 | + 'PRC_name' => $default && empty($price) |
|
1724 | + ? '' |
|
1725 | + : $price->get('PRC_name'), |
|
1726 | + 'price_currency_symbol' => EE_Registry::instance()->CFG->currency->sign, |
|
1727 | + 'show_plus_or_minus' => $default && empty($price) |
|
1728 | + ? '' |
|
1729 | + : ' style="display:none;"', |
|
1730 | + 'show_plus' => ($default && empty($price)) || ($price->is_discount() || $price->is_base_price()) |
|
1731 | + ? ' style="display:none;"' |
|
1732 | + : '', |
|
1733 | + 'show_minus' => ($default && empty($price)) || ! $price->is_discount() |
|
1734 | + ? ' style="display:none;"' |
|
1735 | + : '', |
|
1736 | + 'show_currency_symbol' => ($default && empty($price)) || $price->is_percent() |
|
1737 | + ? ' style="display:none"' |
|
1738 | + : '', |
|
1739 | + 'PRC_amount' => $default && empty($price) |
|
1740 | + ? 0 |
|
1741 | + : $price->get_pretty('PRC_amount', |
|
1742 | + 'localized_float'), |
|
1743 | + 'show_percentage' => ($default && empty($price)) || ! $price->is_percent() |
|
1744 | + ? ' style="display:none;"' |
|
1745 | + : '', |
|
1746 | + 'show_trash_icon' => $show_trash |
|
1747 | + ? '' |
|
1748 | + : ' style="display:none;"', |
|
1749 | + 'show_create_button' => $show_create |
|
1750 | + ? '' |
|
1751 | + : ' style="display:none;"', |
|
1752 | + 'PRC_desc' => $default && empty($price) |
|
1753 | + ? '' |
|
1754 | + : $price->get('PRC_desc'), |
|
1755 | + 'disabled' => ! empty($ticket) && $ticket->get('TKT_deleted'), |
|
1756 | + ); |
|
1757 | + $template_args = apply_filters( |
|
1758 | + 'FHEE__espresso_events_Pricing_Hooks___get_ticket_price_row__template_args', |
|
1759 | + $template_args, |
|
1760 | + $ticket_row, |
|
1761 | + $price_row, |
|
1762 | + $price, |
|
1763 | + $default, |
|
1764 | + $ticket, |
|
1765 | + $show_trash, |
|
1766 | + $show_create, |
|
1767 | + $this->_is_creating_event |
|
1768 | + ); |
|
1769 | + return EEH_Template::display_template( |
|
1770 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php', |
|
1771 | + $template_args, |
|
1772 | + true |
|
1773 | + ); |
|
1774 | + } |
|
1775 | + |
|
1776 | + |
|
1777 | + |
|
1778 | + /** |
|
1779 | + * @param int $ticket_row |
|
1780 | + * @param int $price_row |
|
1781 | + * @param EE_Price $price |
|
1782 | + * @param bool $default |
|
1783 | + * @param bool $disabled |
|
1784 | + * @return mixed |
|
1785 | + * @throws DomainException |
|
1786 | + * @throws EE_Error |
|
1787 | + */ |
|
1788 | + protected function _get_price_type_selector($ticket_row, $price_row, $price, $default, $disabled = false) |
|
1789 | + { |
|
1790 | + if ($price->is_base_price()) { |
|
1791 | + return $this->_get_base_price_template($ticket_row, $price_row, $price, $default); |
|
1792 | + } |
|
1793 | + return $this->_get_price_modifier_template($ticket_row, $price_row, $price, $default, $disabled); |
|
1794 | + } |
|
1795 | + |
|
1796 | + |
|
1797 | + |
|
1798 | + /** |
|
1799 | + * @param int $ticket_row |
|
1800 | + * @param int $price_row |
|
1801 | + * @param EE_Price $price |
|
1802 | + * @param bool $default |
|
1803 | + * @return mixed |
|
1804 | + * @throws DomainException |
|
1805 | + * @throws EE_Error |
|
1806 | + */ |
|
1807 | + protected function _get_base_price_template($ticket_row, $price_row, $price, $default) |
|
1808 | + { |
|
1809 | + $template_args = array( |
|
1810 | + 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
1811 | + 'PRC_order' => $default && empty($price) ? 'PRICENUM' : $price_row, |
|
1812 | + 'PRT_ID' => $default && empty($price) ? 1 : $price->get('PRT_ID'), |
|
1813 | + 'PRT_name' => esc_html__('Price', 'event_espresso'), |
|
1814 | + 'price_selected_operator' => '+', |
|
1815 | + 'price_selected_is_percent' => 0, |
|
1816 | + ); |
|
1817 | + $template_args = apply_filters( |
|
1818 | + 'FHEE__espresso_events_Pricing_Hooks___get_base_price_template__template_args', |
|
1819 | + $template_args, |
|
1820 | + $ticket_row, |
|
1821 | + $price_row, |
|
1822 | + $price, |
|
1823 | + $default, |
|
1824 | + $this->_is_creating_event |
|
1825 | + ); |
|
1826 | + return EEH_Template::display_template( |
|
1827 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php', |
|
1828 | + $template_args, |
|
1829 | + true |
|
1830 | + ); |
|
1831 | + } |
|
1832 | + |
|
1833 | + |
|
1834 | + |
|
1835 | + /** |
|
1836 | + * @param int $ticket_row |
|
1837 | + * @param int $price_row |
|
1838 | + * @param EE_Price $price |
|
1839 | + * @param bool $default |
|
1840 | + * @param bool $disabled |
|
1841 | + * @return mixed |
|
1842 | + * @throws DomainException |
|
1843 | + * @throws EE_Error |
|
1844 | + */ |
|
1845 | + protected function _get_price_modifier_template( |
|
1846 | + $ticket_row, |
|
1847 | + $price_row, |
|
1848 | + $price, |
|
1849 | + $default, |
|
1850 | + $disabled = false |
|
1851 | + ) { |
|
1852 | + $select_name = $default && ! $price instanceof EE_Price |
|
1853 | + ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]' |
|
1854 | + : 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]'; |
|
1855 | + /** @var EEM_Price_Type $price_type_model */ |
|
1856 | + $price_type_model = EE_Registry::instance()->load_model('Price_Type'); |
|
1857 | + $price_types = $price_type_model->get_all(array( |
|
1858 | + array( |
|
1859 | + 'OR' => array( |
|
1860 | + 'PBT_ID' => '2', |
|
1861 | + 'PBT_ID*' => '3', |
|
1862 | + ), |
|
1863 | + ), |
|
1864 | + )); |
|
1865 | + $all_price_types = $default && ! $price instanceof EE_Price |
|
1866 | + ? array(esc_html__('Select Modifier', 'event_espresso')) |
|
1867 | + : array(); |
|
1868 | + $selected_price_type_id = $default && ! $price instanceof EE_Price ? 0 : $price->type(); |
|
1869 | + $price_option_spans = ''; |
|
1870 | + //setup price types for selector |
|
1871 | + foreach ($price_types as $price_type) { |
|
1872 | + if (! $price_type instanceof EE_Price_Type) { |
|
1873 | + continue; |
|
1874 | + } |
|
1875 | + $all_price_types[$price_type->ID()] = $price_type->get('PRT_name'); |
|
1876 | + //while we're in the loop let's setup the option spans used by js |
|
1877 | + $span_args = array( |
|
1878 | + 'PRT_ID' => $price_type->ID(), |
|
1879 | + 'PRT_operator' => $price_type->is_discount() ? '-' : '+', |
|
1880 | + 'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0, |
|
1881 | + ); |
|
1882 | + $price_option_spans .= EEH_Template::display_template( |
|
1883 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php', |
|
1884 | + $span_args, |
|
1885 | + true |
|
1886 | + ); |
|
1887 | + } |
|
1888 | + $select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]' : $select_name; |
|
1889 | + $select_input = new EE_Select_Input( |
|
1890 | + $all_price_types, |
|
1891 | + array( |
|
1892 | + 'default' => $selected_price_type_id, |
|
1893 | + 'html_name' => $select_name, |
|
1894 | + 'html_class' => 'edit-price-PRT_ID', |
|
1895 | + 'html_other_attributes' => $disabled ? 'style="width:auto;" disabled' : 'style="width:auto;"', |
|
1896 | + ) |
|
1897 | + ); |
|
1898 | + $price_selected_operator = $price instanceof EE_Price && $price->is_discount() ? '-' : '+'; |
|
1899 | + $price_selected_operator = $default && ! $price instanceof EE_Price ? '' : $price_selected_operator; |
|
1900 | + $price_selected_is_percent = $price instanceof EE_Price && $price->is_percent() ? 1 : 0; |
|
1901 | + $price_selected_is_percent = $default && ! $price instanceof EE_Price ? '' : $price_selected_is_percent; |
|
1902 | + $template_args = array( |
|
1903 | + 'tkt_row' => $default ? 'TICKETNUM' : $ticket_row, |
|
1904 | + 'PRC_order' => $default && ! $price instanceof EE_Price ? 'PRICENUM' : $price_row, |
|
1905 | + 'price_modifier_selector' => $select_input->get_html_for_input(), |
|
1906 | + 'main_name' => $select_name, |
|
1907 | + 'selected_price_type_id' => $selected_price_type_id, |
|
1908 | + 'price_option_spans' => $price_option_spans, |
|
1909 | + 'price_selected_operator' => $price_selected_operator, |
|
1910 | + 'price_selected_is_percent' => $price_selected_is_percent, |
|
1911 | + 'disabled' => $disabled, |
|
1912 | + ); |
|
1913 | + $template_args = apply_filters( |
|
1914 | + 'FHEE__espresso_events_Pricing_Hooks___get_price_modifier_template__template_args', |
|
1915 | + $template_args, |
|
1916 | + $ticket_row, |
|
1917 | + $price_row, |
|
1918 | + $price, |
|
1919 | + $default, |
|
1920 | + $disabled, |
|
1921 | + $this->_is_creating_event |
|
1922 | + ); |
|
1923 | + return EEH_Template::display_template( |
|
1924 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php', |
|
1925 | + $template_args, |
|
1926 | + true |
|
1927 | + ); |
|
1928 | + } |
|
1929 | + |
|
1930 | + |
|
1931 | + |
|
1932 | + /** |
|
1933 | + * @param int $datetime_row |
|
1934 | + * @param int $ticket_row |
|
1935 | + * @param EE_Datetime|null $datetime |
|
1936 | + * @param EE_Ticket|null $ticket |
|
1937 | + * @param array $ticket_datetimes |
|
1938 | + * @param bool $default |
|
1939 | + * @return mixed |
|
1940 | + * @throws DomainException |
|
1941 | + * @throws EE_Error |
|
1942 | + */ |
|
1943 | + protected function _get_ticket_datetime_list_item( |
|
1944 | + $datetime_row, |
|
1945 | + $ticket_row, |
|
1946 | + $datetime, |
|
1947 | + $ticket, |
|
1948 | + $ticket_datetimes = array(), |
|
1949 | + $default |
|
1950 | + ) { |
|
1951 | + $tkt_datetimes = $ticket instanceof EE_Ticket && isset($ticket_datetimes[$ticket->ID()]) |
|
1952 | + ? $ticket_datetimes[$ticket->ID()] |
|
1953 | + : array(); |
|
1954 | + $template_args = array( |
|
1955 | + 'dtt_row' => $default && ! $datetime instanceof EE_Datetime |
|
1956 | + ? 'DTTNUM' |
|
1957 | + : $datetime_row, |
|
1958 | + 'tkt_row' => $default |
|
1959 | + ? 'TICKETNUM' |
|
1960 | + : $ticket_row, |
|
1961 | + 'ticket_datetime_selected' => in_array($datetime_row, $tkt_datetimes, true) |
|
1962 | + ? ' ticket-selected' |
|
1963 | + : '', |
|
1964 | + 'ticket_datetime_checked' => in_array($datetime_row, $tkt_datetimes, true) |
|
1965 | + ? ' checked="checked"' |
|
1966 | + : '', |
|
1967 | + 'DTT_name' => $default && empty($datetime) |
|
1968 | + ? 'DTTNAME' |
|
1969 | + : $datetime->get_dtt_display_name(true), |
|
1970 | + 'tkt_status_class' => '', |
|
1971 | + ); |
|
1972 | + $template_args = apply_filters( |
|
1973 | + 'FHEE__espresso_events_Pricing_Hooks___get_ticket_datetime_list_item__template_args', |
|
1974 | + $template_args, |
|
1975 | + $datetime_row, |
|
1976 | + $ticket_row, |
|
1977 | + $datetime, |
|
1978 | + $ticket, |
|
1979 | + $ticket_datetimes, |
|
1980 | + $default, |
|
1981 | + $this->_is_creating_event |
|
1982 | + ); |
|
1983 | + return EEH_Template::display_template( |
|
1984 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php', |
|
1985 | + $template_args, |
|
1986 | + true |
|
1987 | + ); |
|
1988 | + } |
|
1989 | + |
|
1990 | + |
|
1991 | + |
|
1992 | + /** |
|
1993 | + * @param array $all_datetimes |
|
1994 | + * @param array $all_tickets |
|
1995 | + * @return mixed |
|
1996 | + * @throws DomainException |
|
1997 | + * @throws EE_Error |
|
1998 | + */ |
|
1999 | + protected function _get_ticket_js_structure($all_datetimes = array(), $all_tickets = array()) |
|
2000 | + { |
|
2001 | + $template_args = array( |
|
2002 | + 'default_datetime_edit_row' => $this->_get_dtt_edit_row( |
|
2003 | + 'DTTNUM', |
|
2004 | + null, |
|
2005 | + true, |
|
2006 | + $all_datetimes |
|
2007 | + ), |
|
2008 | + 'default_ticket_row' => $this->_get_ticket_row( |
|
2009 | + 'TICKETNUM', |
|
2010 | + null, |
|
2011 | + array(), |
|
2012 | + array(), |
|
2013 | + true |
|
2014 | + ), |
|
2015 | + 'default_price_row' => $this->_get_ticket_price_row( |
|
2016 | + 'TICKETNUM', |
|
2017 | + 'PRICENUM', |
|
2018 | + null, |
|
2019 | + true, |
|
2020 | + null |
|
2021 | + ), |
|
2022 | + 'default_price_rows' => '', |
|
2023 | + 'default_base_price_amount' => 0, |
|
2024 | + 'default_base_price_name' => '', |
|
2025 | + 'default_base_price_description' => '', |
|
2026 | + 'default_price_modifier_selector_row' => $this->_get_price_modifier_template( |
|
2027 | + 'TICKETNUM', |
|
2028 | + 'PRICENUM', |
|
2029 | + null, |
|
2030 | + true |
|
2031 | + ), |
|
2032 | + 'default_available_tickets_for_datetime' => $this->_get_dtt_attached_tickets_row( |
|
2033 | + 'DTTNUM', |
|
2034 | + null, |
|
2035 | + array(), |
|
2036 | + array(), |
|
2037 | + true |
|
2038 | + ), |
|
2039 | + 'existing_available_datetime_tickets_list' => '', |
|
2040 | + 'existing_available_ticket_datetimes_list' => '', |
|
2041 | + 'new_available_datetime_ticket_list_item' => $this->_get_datetime_tickets_list_item( |
|
2042 | + 'DTTNUM', |
|
2043 | + 'TICKETNUM', |
|
2044 | + null, |
|
2045 | + null, |
|
2046 | + array(), |
|
2047 | + true |
|
2048 | + ), |
|
2049 | + 'new_available_ticket_datetime_list_item' => $this->_get_ticket_datetime_list_item( |
|
2050 | + 'DTTNUM', |
|
2051 | + 'TICKETNUM', |
|
2052 | + null, |
|
2053 | + null, |
|
2054 | + array(), |
|
2055 | + true |
|
2056 | + ), |
|
2057 | + ); |
|
2058 | + $ticket_row = 1; |
|
2059 | + foreach ($all_tickets as $ticket) { |
|
2060 | + $template_args['existing_available_datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
|
2061 | + 'DTTNUM', |
|
2062 | + $ticket_row, |
|
2063 | + null, |
|
2064 | + $ticket, |
|
2065 | + array(), |
|
2066 | + true |
|
2067 | + ); |
|
2068 | + $ticket_row++; |
|
2069 | + } |
|
2070 | + $datetime_row = 1; |
|
2071 | + foreach ($all_datetimes as $datetime) { |
|
2072 | + $template_args['existing_available_ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
|
2073 | + $datetime_row, |
|
2074 | + 'TICKETNUM', |
|
2075 | + $datetime, |
|
2076 | + null, |
|
2077 | + array(), |
|
2078 | + true |
|
2079 | + ); |
|
2080 | + $datetime_row++; |
|
2081 | + } |
|
2082 | + /** @var EEM_Price $price_model */ |
|
2083 | + $price_model = EE_Registry::instance()->load_model('Price'); |
|
2084 | + $default_prices = $price_model->get_all_default_prices(); |
|
2085 | + $price_row = 1; |
|
2086 | + foreach ($default_prices as $price) { |
|
2087 | + if (! $price instanceof EE_Price) { |
|
2088 | + continue; |
|
2089 | + } |
|
2090 | + if ($price->is_base_price()) { |
|
2091 | + $template_args['default_base_price_amount'] = $price->get_pretty( |
|
2092 | + 'PRC_amount', |
|
2093 | + 'localized_float' |
|
2094 | + ); |
|
2095 | + $template_args['default_base_price_name'] = $price->get('PRC_name'); |
|
2096 | + $template_args['default_base_price_description'] = $price->get('PRC_desc'); |
|
2097 | + $price_row++; |
|
2098 | + continue; |
|
2099 | + } |
|
2100 | + $show_trash = !((count($default_prices) > 1 && $price_row === 1) || count($default_prices) === 1); |
|
2101 | + $show_create = !(count($default_prices) > 1 && count($default_prices) !== $price_row); |
|
2102 | + $template_args['default_price_rows'] .= $this->_get_ticket_price_row( |
|
2103 | + 'TICKETNUM', |
|
2104 | + $price_row, |
|
2105 | + $price, |
|
2106 | + true, |
|
2107 | + null, |
|
2108 | + $show_trash, |
|
2109 | + $show_create |
|
2110 | + ); |
|
2111 | + $price_row++; |
|
2112 | + } |
|
2113 | + $template_args = apply_filters( |
|
2114 | + 'FHEE__espresso_events_Pricing_Hooks___get_ticket_js_structure__template_args', |
|
2115 | + $template_args, |
|
2116 | + $all_datetimes, |
|
2117 | + $all_tickets, |
|
2118 | + $this->_is_creating_event |
|
2119 | + ); |
|
2120 | + return EEH_Template::display_template( |
|
2121 | + PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php', |
|
2122 | + $template_args, |
|
2123 | + true |
|
2124 | + ); |
|
2125 | + } |
|
2126 | 2126 | |
2127 | 2127 | |
2128 | 2128 | } //end class espresso_events_Pricing_Hooks |
@@ -49,7 +49,7 @@ discard block |
||
49 | 49 | { |
50 | 50 | $this->_name = 'pricing'; |
51 | 51 | //capability check |
52 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
52 | + if ( ! EE_Registry::instance()->CAP->current_user_can( |
|
53 | 53 | 'ee_read_default_prices', |
54 | 54 | 'advanced_ticket_datetime_metabox' |
55 | 55 | )) { |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | $this->_date_format_strings['time'] = isset($this->_date_format_strings['time']) |
126 | 126 | ? $this->_date_format_strings['time'] |
127 | 127 | : null; |
128 | - $this->_date_time_format = $this->_date_format_strings['date'] . ' ' . $this->_date_format_strings['time']; |
|
128 | + $this->_date_time_format = $this->_date_format_strings['date'].' '.$this->_date_format_strings['time']; |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | ); |
151 | 151 | $msg .= '</p><ul>'; |
152 | 152 | foreach ($format_validation as $error) { |
153 | - $msg .= '<li>' . $error . '</li>'; |
|
153 | + $msg .= '<li>'.$error.'</li>'; |
|
154 | 154 | } |
155 | 155 | $msg .= '</ul><p>'; |
156 | 156 | $msg .= sprintf( |
@@ -180,11 +180,11 @@ discard block |
||
180 | 180 | $this->_scripts_styles = array( |
181 | 181 | 'registers' => array( |
182 | 182 | 'ee-tickets-datetimes-css' => array( |
183 | - 'url' => PRICING_ASSETS_URL . 'event-tickets-datetimes.css', |
|
183 | + 'url' => PRICING_ASSETS_URL.'event-tickets-datetimes.css', |
|
184 | 184 | 'type' => 'css', |
185 | 185 | ), |
186 | 186 | 'ee-dtt-ticket-metabox' => array( |
187 | - 'url' => PRICING_ASSETS_URL . 'ee-datetime-ticket-metabox.js', |
|
187 | + 'url' => PRICING_ASSETS_URL.'ee-datetime-ticket-metabox.js', |
|
188 | 188 | 'depends' => array('ee-datepicker', 'ee-dialog', 'underscore'), |
189 | 189 | ), |
190 | 190 | ), |
@@ -208,9 +208,9 @@ discard block |
||
208 | 208 | 'event_espresso' |
209 | 209 | ), |
210 | 210 | 'cancel_button' => '<button class="button-secondary ee-modal-cancel">' |
211 | - . esc_html__('Cancel', 'event_espresso') . '</button>', |
|
211 | + . esc_html__('Cancel', 'event_espresso').'</button>', |
|
212 | 212 | 'close_button' => '<button class="button-secondary ee-modal-cancel">' |
213 | - . esc_html__('Close', 'event_espresso') . '</button>', |
|
213 | + . esc_html__('Close', 'event_espresso').'</button>', |
|
214 | 214 | 'single_warning_from_tkt' => esc_html__( |
215 | 215 | 'The Datetime you are attempting to unassign from this ticket is the only remaining datetime for this ticket. Tickets must always have at least one datetime assigned to them.', |
216 | 216 | 'event_espresso' |
@@ -220,12 +220,12 @@ discard block |
||
220 | 220 | 'event_espresso' |
221 | 221 | ), |
222 | 222 | 'dismiss_button' => '<button class="button-secondary ee-modal-cancel">' |
223 | - . esc_html__('Dismiss', 'event_espresso') . '</button>', |
|
223 | + . esc_html__('Dismiss', 'event_espresso').'</button>', |
|
224 | 224 | ), |
225 | 225 | 'DTT_ERROR_MSG' => array( |
226 | 226 | 'no_ticket_name' => esc_html__('General Admission', 'event_espresso'), |
227 | 227 | 'dismiss_button' => '<div class="save-cancel-button-container"><button class="button-secondary ee-modal-cancel">' |
228 | - . esc_html__('Dismiss', 'event_espresso') . '</button></div>', |
|
228 | + . esc_html__('Dismiss', 'event_espresso').'</button></div>', |
|
229 | 229 | ), |
230 | 230 | 'DTT_OVERSELL_WARNING' => array( |
231 | 231 | 'datetime_ticket' => esc_html__( |
@@ -241,7 +241,7 @@ discard block |
||
241 | 241 | $this->_date_format_strings['date'], |
242 | 242 | $this->_date_format_strings['time'] |
243 | 243 | ), |
244 | - 'DTT_START_OF_WEEK' => array('dayValue' => (int)get_option('start_of_week')), |
|
244 | + 'DTT_START_OF_WEEK' => array('dayValue' => (int) get_option('start_of_week')), |
|
245 | 245 | ), |
246 | 246 | ), |
247 | 247 | ); |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
297 | 297 | $saved_dtt_ids = array(); |
298 | 298 | $saved_dtt_objs = array(); |
299 | - if (empty($data['edit_event_datetimes']) || !is_array($data['edit_event_datetimes'])) { |
|
299 | + if (empty($data['edit_event_datetimes']) || ! is_array($data['edit_event_datetimes'])) { |
|
300 | 300 | throw new InvalidArgumentException( |
301 | 301 | esc_html__( |
302 | 302 | 'The "edit_event_datetimes" array is invalid therefore the event can not be updated.', |
@@ -307,7 +307,7 @@ discard block |
||
307 | 307 | foreach ($data['edit_event_datetimes'] as $row => $datetime_data) { |
308 | 308 | //trim all values to ensure any excess whitespace is removed. |
309 | 309 | $datetime_data = array_map( |
310 | - function ($datetime_data) { |
|
310 | + function($datetime_data) { |
|
311 | 311 | return is_array($datetime_data) ? $datetime_data : trim($datetime_data); |
312 | 312 | }, |
313 | 313 | $datetime_data |
@@ -337,7 +337,7 @@ discard block |
||
337 | 337 | ); |
338 | 338 | // if we have an id then let's get existing object first and then set the new values. |
339 | 339 | // Otherwise we instantiate a new object for save. |
340 | - if (! empty($datetime_data['DTT_ID'])) { |
|
340 | + if ( ! empty($datetime_data['DTT_ID'])) { |
|
341 | 341 | $datetime = EE_Registry::instance() |
342 | 342 | ->load_model('Datetime', array($timezone)) |
343 | 343 | ->get_one_by_ID($datetime_data['DTT_ID']); |
@@ -430,7 +430,7 @@ discard block |
||
430 | 430 | $timezone = isset($data['timezone_string']) ? $data['timezone_string'] : null; |
431 | 431 | $saved_tickets = $datetimes_on_existing = array(); |
432 | 432 | $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
433 | - if(empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])){ |
|
433 | + if (empty($data['edit_tickets']) || ! is_array($data['edit_tickets'])) { |
|
434 | 434 | throw new InvalidArgumentException( |
435 | 435 | esc_html__( |
436 | 436 | 'The "edit_tickets" array is invalid therefore the event can not be updated.', |
@@ -448,7 +448,7 @@ discard block |
||
448 | 448 | $datetimes_removed = array_diff($starting_tkt_dtt_rows, $tkt_dtt_rows); |
449 | 449 | // trim inputs to ensure any excess whitespace is removed. |
450 | 450 | $tkt = array_map( |
451 | - function ($ticket_data) { |
|
451 | + function($ticket_data) { |
|
452 | 452 | return is_array($ticket_data) ? $ticket_data : trim($ticket_data); |
453 | 453 | }, |
454 | 454 | $tkt |
@@ -457,7 +457,7 @@ discard block |
||
457 | 457 | // because we're doing calculations prior to using the models. |
458 | 458 | // note incoming ['TKT_price'] value is already in standard notation (via js). |
459 | 459 | $ticket_price = isset($tkt['TKT_price']) |
460 | - ? round((float)$tkt['TKT_price'], 3) |
|
460 | + ? round((float) $tkt['TKT_price'], 3) |
|
461 | 461 | : 0; |
462 | 462 | //note incoming base price needs converted from localized value. |
463 | 463 | $base_price = isset($tkt['TKT_base_price']) |
@@ -604,7 +604,7 @@ discard block |
||
604 | 604 | //need to make sue that the TKT_price is accurate after saving the prices. |
605 | 605 | $ticket->ensure_TKT_Price_correct(); |
606 | 606 | //handle CREATING a default tkt from the incoming tkt but ONLY if this isn't an autosave. |
607 | - if (! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) { |
|
607 | + if ( ! defined('DOING_AUTOSAVE') && ! empty($tkt['TKT_is_default_selector'])) { |
|
608 | 608 | $update_prices = true; |
609 | 609 | $new_default = clone $ticket; |
610 | 610 | $new_default->set('TKT_ID', 0); |
@@ -723,9 +723,9 @@ discard block |
||
723 | 723 | // to start we have to add the ticket to all the datetimes its supposed to be with, |
724 | 724 | // and removing the ticket from datetimes it got removed from. |
725 | 725 | // first let's add datetimes |
726 | - if (! empty($added_datetimes) && is_array($added_datetimes)) { |
|
726 | + if ( ! empty($added_datetimes) && is_array($added_datetimes)) { |
|
727 | 727 | foreach ($added_datetimes as $row_id) { |
728 | - $row_id = (int)$row_id; |
|
728 | + $row_id = (int) $row_id; |
|
729 | 729 | if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
730 | 730 | $ticket->_add_relation_to($saved_datetimes[$row_id], 'Datetime'); |
731 | 731 | // Is this an existing ticket (has an ID) and does it have any sold? |
@@ -738,9 +738,9 @@ discard block |
||
738 | 738 | } |
739 | 739 | } |
740 | 740 | // then remove datetimes |
741 | - if (! empty($removed_datetimes) && is_array($removed_datetimes)) { |
|
741 | + if ( ! empty($removed_datetimes) && is_array($removed_datetimes)) { |
|
742 | 742 | foreach ($removed_datetimes as $row_id) { |
743 | - $row_id = (int)$row_id; |
|
743 | + $row_id = (int) $row_id; |
|
744 | 744 | // its entirely possible that a datetime got deleted (instead of just removed from relationship. |
745 | 745 | // So make sure we skip over this if the dtt isn't in the $saved_datetimes array) |
746 | 746 | if (isset($saved_datetimes[$row_id]) && $saved_datetimes[$row_id] instanceof EE_Datetime) { |
@@ -850,7 +850,7 @@ discard block |
||
850 | 850 | ); |
851 | 851 | } |
852 | 852 | //possibly need to save tkt |
853 | - if (! $ticket->ID()) { |
|
853 | + if ( ! $ticket->ID()) { |
|
854 | 854 | $ticket->save(); |
855 | 855 | } |
856 | 856 | foreach ($prices as $row => $prc) { |
@@ -888,11 +888,11 @@ discard block |
||
888 | 888 | $ticket->_add_relation_to($price, 'Price'); |
889 | 889 | } |
890 | 890 | //now let's remove any prices that got removed from the ticket |
891 | - if (! empty ($current_prices_on_ticket)) { |
|
891 | + if ( ! empty ($current_prices_on_ticket)) { |
|
892 | 892 | $current = array_keys($current_prices_on_ticket); |
893 | 893 | $updated = array_keys($updated_prices); |
894 | 894 | $prices_to_remove = array_diff($current, $updated); |
895 | - if (! empty($prices_to_remove)) { |
|
895 | + if ( ! empty($prices_to_remove)) { |
|
896 | 896 | foreach ($prices_to_remove as $prc_id) { |
897 | 897 | $p = $current_prices_on_ticket[$prc_id]; |
898 | 898 | $ticket->_remove_relation_to($p, 'Price'); |
@@ -910,7 +910,7 @@ discard block |
||
910 | 910 | * @param Events_Admin_Page $event_admin_obj |
911 | 911 | * @return Events_Admin_Page |
912 | 912 | */ |
913 | - public function autosave_handling( Events_Admin_Page $event_admin_obj) |
|
913 | + public function autosave_handling(Events_Admin_Page $event_admin_obj) |
|
914 | 914 | { |
915 | 915 | return $event_admin_obj; |
916 | 916 | //doing nothing for the moment. |
@@ -1043,7 +1043,7 @@ discard block |
||
1043 | 1043 | $TKT_ID = $ticket->get('TKT_ID'); |
1044 | 1044 | $ticket_row = $ticket->get('TKT_row'); |
1045 | 1045 | //we only want unique tickets in our final display!! |
1046 | - if (! in_array($TKT_ID, $existing_ticket_ids, true)) { |
|
1046 | + if ( ! in_array($TKT_ID, $existing_ticket_ids, true)) { |
|
1047 | 1047 | $existing_ticket_ids[] = $TKT_ID; |
1048 | 1048 | $all_tickets[] = $ticket; |
1049 | 1049 | } |
@@ -1065,9 +1065,9 @@ discard block |
||
1065 | 1065 | //sort $all_tickets by order |
1066 | 1066 | usort( |
1067 | 1067 | $all_tickets, |
1068 | - function (EE_Ticket $a, EE_Ticket $b) { |
|
1069 | - $a_order = (int)$a->get('TKT_order'); |
|
1070 | - $b_order = (int)$b->get('TKT_order'); |
|
1068 | + function(EE_Ticket $a, EE_Ticket $b) { |
|
1069 | + $a_order = (int) $a->get('TKT_order'); |
|
1070 | + $b_order = (int) $b->get('TKT_order'); |
|
1071 | 1071 | if ($a_order === $b_order) { |
1072 | 1072 | return 0; |
1073 | 1073 | } |
@@ -1103,7 +1103,7 @@ discard block |
||
1103 | 1103 | } |
1104 | 1104 | $main_template_args['ticket_js_structure'] = $this->_get_ticket_js_structure($datetimes, $all_tickets); |
1105 | 1105 | EEH_Template::display_template( |
1106 | - PRICING_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php', |
|
1106 | + PRICING_TEMPLATE_PATH.'event_tickets_metabox_main.template.php', |
|
1107 | 1107 | $main_template_args |
1108 | 1108 | ); |
1109 | 1109 | } |
@@ -1141,7 +1141,7 @@ discard block |
||
1141 | 1141 | 'dtt_row' => $default ? 'DTTNUM' : $datetime_row, |
1142 | 1142 | ); |
1143 | 1143 | return EEH_Template::display_template( |
1144 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_row_wrapper.template.php', |
|
1144 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_row_wrapper.template.php', |
|
1145 | 1145 | $dtt_display_template_args, |
1146 | 1146 | true |
1147 | 1147 | ); |
@@ -1211,7 +1211,7 @@ discard block |
||
1211 | 1211 | $this->_is_creating_event |
1212 | 1212 | ); |
1213 | 1213 | return EEH_Template::display_template( |
1214 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_edit_row.template.php', |
|
1214 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_edit_row.template.php', |
|
1215 | 1215 | $template_args, |
1216 | 1216 | true |
1217 | 1217 | ); |
@@ -1253,7 +1253,7 @@ discard block |
||
1253 | 1253 | 'DTT_ID' => $default ? '' : $datetime->ID(), |
1254 | 1254 | ); |
1255 | 1255 | //need to setup the list items (but only if this isn't a default skeleton setup) |
1256 | - if (! $default) { |
|
1256 | + if ( ! $default) { |
|
1257 | 1257 | $ticket_row = 1; |
1258 | 1258 | foreach ($all_tickets as $ticket) { |
1259 | 1259 | $template_args['datetime_tickets_list'] .= $this->_get_datetime_tickets_list_item( |
@@ -1279,7 +1279,7 @@ discard block |
||
1279 | 1279 | $this->_is_creating_event |
1280 | 1280 | ); |
1281 | 1281 | return EEH_Template::display_template( |
1282 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_attached_tickets_row.template.php', |
|
1282 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_attached_tickets_row.template.php', |
|
1283 | 1283 | $template_args, |
1284 | 1284 | true |
1285 | 1285 | ); |
@@ -1328,8 +1328,8 @@ discard block |
||
1328 | 1328 | ? 'TKTNAME' |
1329 | 1329 | : $ticket->get('TKT_name'), |
1330 | 1330 | 'tkt_status_class' => $no_ticket || $this->_is_creating_event |
1331 | - ? ' tkt-status-' . EE_Ticket::onsale |
|
1332 | - : ' tkt-status-' . $ticket->ticket_status(), |
|
1331 | + ? ' tkt-status-'.EE_Ticket::onsale |
|
1332 | + : ' tkt-status-'.$ticket->ticket_status(), |
|
1333 | 1333 | ); |
1334 | 1334 | //filter template args |
1335 | 1335 | $template_args = apply_filters( |
@@ -1344,7 +1344,7 @@ discard block |
||
1344 | 1344 | $this->_is_creating_event |
1345 | 1345 | ); |
1346 | 1346 | return EEH_Template::display_template( |
1347 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_dtt_tickets_list.template.php', |
|
1347 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_dtt_tickets_list.template.php', |
|
1348 | 1348 | $template_args, |
1349 | 1349 | true |
1350 | 1350 | ); |
@@ -1401,11 +1401,11 @@ discard block |
||
1401 | 1401 | $count_price_mods = EEM_Price::instance()->get_all_default_prices(true); |
1402 | 1402 | //breaking out complicated condition for ticket_status |
1403 | 1403 | if ($default) { |
1404 | - $ticket_status_class = ' tkt-status-' . EE_Ticket::onsale; |
|
1404 | + $ticket_status_class = ' tkt-status-'.EE_Ticket::onsale; |
|
1405 | 1405 | } else { |
1406 | 1406 | $ticket_status_class = $ticket->is_default() |
1407 | - ? ' tkt-status-' . EE_Ticket::onsale |
|
1408 | - : ' tkt-status-' . $ticket->ticket_status(); |
|
1407 | + ? ' tkt-status-'.EE_Ticket::onsale |
|
1408 | + : ' tkt-status-'.$ticket->ticket_status(); |
|
1409 | 1409 | } |
1410 | 1410 | //breaking out complicated condition for TKT_taxable |
1411 | 1411 | if ($default) { |
@@ -1497,7 +1497,7 @@ discard block |
||
1497 | 1497 | : ' style="display:none;"', |
1498 | 1498 | 'show_price_mod_button' => count($prices) > 1 |
1499 | 1499 | || ($default && $count_price_mods > 0) |
1500 | - || (! $default && $ticket->deleted()) |
|
1500 | + || ( ! $default && $ticket->deleted()) |
|
1501 | 1501 | ? ' style="display:none;"' |
1502 | 1502 | : '', |
1503 | 1503 | 'total_price_rows' => count($prices) > 1 ? count($prices) : 1, |
@@ -1539,7 +1539,7 @@ discard block |
||
1539 | 1539 | //if empty then the start date will be now. |
1540 | 1540 | $template_args['TKT_start_date'] = date($this->_date_time_format, |
1541 | 1541 | current_time('timestamp')); |
1542 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
1542 | + $template_args['tkt_status_class'] = ' tkt-status-'.EE_Ticket::onsale; |
|
1543 | 1543 | } |
1544 | 1544 | if (empty($template_args['TKT_end_date'])) { |
1545 | 1545 | //get the earliest datetime (if present); |
@@ -1549,7 +1549,7 @@ discard block |
||
1549 | 1549 | array('order_by' => array('DTT_EVT_start' => 'ASC')) |
1550 | 1550 | ) |
1551 | 1551 | : null; |
1552 | - if (! empty($earliest_dtt)) { |
|
1552 | + if ( ! empty($earliest_dtt)) { |
|
1553 | 1553 | $template_args['TKT_end_date'] = $earliest_dtt->get_datetime( |
1554 | 1554 | 'DTT_EVT_start', |
1555 | 1555 | $this->_date_time_format |
@@ -1562,10 +1562,10 @@ discard block |
||
1562 | 1562 | ) |
1563 | 1563 | ); |
1564 | 1564 | } |
1565 | - $template_args['tkt_status_class'] = ' tkt-status-' . EE_Ticket::onsale; |
|
1565 | + $template_args['tkt_status_class'] = ' tkt-status-'.EE_Ticket::onsale; |
|
1566 | 1566 | } |
1567 | 1567 | //generate ticket_datetime items |
1568 | - if (! $default) { |
|
1568 | + if ( ! $default) { |
|
1569 | 1569 | $datetime_row = 1; |
1570 | 1570 | foreach ($all_datetimes as $datetime) { |
1571 | 1571 | $template_args['ticket_datetimes_list'] .= $this->_get_ticket_datetime_list_item( |
@@ -1581,15 +1581,15 @@ discard block |
||
1581 | 1581 | } |
1582 | 1582 | $price_row = 1; |
1583 | 1583 | foreach ($prices as $price) { |
1584 | - if (! $price instanceof EE_Price) { |
|
1584 | + if ( ! $price instanceof EE_Price) { |
|
1585 | 1585 | continue; |
1586 | 1586 | } |
1587 | 1587 | if ($price->is_base_price()) { |
1588 | 1588 | $price_row++; |
1589 | 1589 | continue; |
1590 | 1590 | } |
1591 | - $show_trash = !((count($prices) > 1 && $price_row === 1) || count($prices) === 1); |
|
1592 | - $show_create = !(count($prices) > 1 && count($prices) !== $price_row); |
|
1591 | + $show_trash = ! ((count($prices) > 1 && $price_row === 1) || count($prices) === 1); |
|
1592 | + $show_create = ! (count($prices) > 1 && count($prices) !== $price_row); |
|
1593 | 1593 | $template_args['ticket_price_rows'] .= $this->_get_ticket_price_row( |
1594 | 1594 | $ticket_row, |
1595 | 1595 | $price_row, |
@@ -1614,7 +1614,7 @@ discard block |
||
1614 | 1614 | $this->_is_creating_event |
1615 | 1615 | ); |
1616 | 1616 | return EEH_Template::display_template( |
1617 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_row.template.php', |
|
1617 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_row.template.php', |
|
1618 | 1618 | $template_args, |
1619 | 1619 | true |
1620 | 1620 | ); |
@@ -1655,7 +1655,7 @@ discard block |
||
1655 | 1655 | $this->_is_creating_event |
1656 | 1656 | ); |
1657 | 1657 | $tax_rows .= EEH_Template::display_template( |
1658 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_tax_row.template.php', |
|
1658 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_tax_row.template.php', |
|
1659 | 1659 | $template_args, |
1660 | 1660 | true |
1661 | 1661 | ); |
@@ -1767,7 +1767,7 @@ discard block |
||
1767 | 1767 | $this->_is_creating_event |
1768 | 1768 | ); |
1769 | 1769 | return EEH_Template::display_template( |
1770 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_price_row.template.php', |
|
1770 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_price_row.template.php', |
|
1771 | 1771 | $template_args, |
1772 | 1772 | true |
1773 | 1773 | ); |
@@ -1824,7 +1824,7 @@ discard block |
||
1824 | 1824 | $this->_is_creating_event |
1825 | 1825 | ); |
1826 | 1826 | return EEH_Template::display_template( |
1827 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_type_base.template.php', |
|
1827 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_type_base.template.php', |
|
1828 | 1828 | $template_args, |
1829 | 1829 | true |
1830 | 1830 | ); |
@@ -1851,7 +1851,7 @@ discard block |
||
1851 | 1851 | ) { |
1852 | 1852 | $select_name = $default && ! $price instanceof EE_Price |
1853 | 1853 | ? 'edit_prices[TICKETNUM][PRICENUM][PRT_ID]' |
1854 | - : 'edit_prices[' . $ticket_row . '][' . $price_row . '][PRT_ID]'; |
|
1854 | + : 'edit_prices['.$ticket_row.']['.$price_row.'][PRT_ID]'; |
|
1855 | 1855 | /** @var EEM_Price_Type $price_type_model */ |
1856 | 1856 | $price_type_model = EE_Registry::instance()->load_model('Price_Type'); |
1857 | 1857 | $price_types = $price_type_model->get_all(array( |
@@ -1869,7 +1869,7 @@ discard block |
||
1869 | 1869 | $price_option_spans = ''; |
1870 | 1870 | //setup price types for selector |
1871 | 1871 | foreach ($price_types as $price_type) { |
1872 | - if (! $price_type instanceof EE_Price_Type) { |
|
1872 | + if ( ! $price_type instanceof EE_Price_Type) { |
|
1873 | 1873 | continue; |
1874 | 1874 | } |
1875 | 1875 | $all_price_types[$price_type->ID()] = $price_type->get('PRT_name'); |
@@ -1880,12 +1880,12 @@ discard block |
||
1880 | 1880 | 'PRT_is_percent' => $price_type->get('PRT_is_percent') ? 1 : 0, |
1881 | 1881 | ); |
1882 | 1882 | $price_option_spans .= EEH_Template::display_template( |
1883 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_option_span.template.php', |
|
1883 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_option_span.template.php', |
|
1884 | 1884 | $span_args, |
1885 | 1885 | true |
1886 | 1886 | ); |
1887 | 1887 | } |
1888 | - $select_name = $disabled ? 'archive_price[' . $ticket_row . '][' . $price_row . '][PRT_ID]' : $select_name; |
|
1888 | + $select_name = $disabled ? 'archive_price['.$ticket_row.']['.$price_row.'][PRT_ID]' : $select_name; |
|
1889 | 1889 | $select_input = new EE_Select_Input( |
1890 | 1890 | $all_price_types, |
1891 | 1891 | array( |
@@ -1921,7 +1921,7 @@ discard block |
||
1921 | 1921 | $this->_is_creating_event |
1922 | 1922 | ); |
1923 | 1923 | return EEH_Template::display_template( |
1924 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_price_modifier_selector.template.php', |
|
1924 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_price_modifier_selector.template.php', |
|
1925 | 1925 | $template_args, |
1926 | 1926 | true |
1927 | 1927 | ); |
@@ -1981,7 +1981,7 @@ discard block |
||
1981 | 1981 | $this->_is_creating_event |
1982 | 1982 | ); |
1983 | 1983 | return EEH_Template::display_template( |
1984 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_datetimes_list_item.template.php', |
|
1984 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_datetimes_list_item.template.php', |
|
1985 | 1985 | $template_args, |
1986 | 1986 | true |
1987 | 1987 | ); |
@@ -2084,7 +2084,7 @@ discard block |
||
2084 | 2084 | $default_prices = $price_model->get_all_default_prices(); |
2085 | 2085 | $price_row = 1; |
2086 | 2086 | foreach ($default_prices as $price) { |
2087 | - if (! $price instanceof EE_Price) { |
|
2087 | + if ( ! $price instanceof EE_Price) { |
|
2088 | 2088 | continue; |
2089 | 2089 | } |
2090 | 2090 | if ($price->is_base_price()) { |
@@ -2097,8 +2097,8 @@ discard block |
||
2097 | 2097 | $price_row++; |
2098 | 2098 | continue; |
2099 | 2099 | } |
2100 | - $show_trash = !((count($default_prices) > 1 && $price_row === 1) || count($default_prices) === 1); |
|
2101 | - $show_create = !(count($default_prices) > 1 && count($default_prices) !== $price_row); |
|
2100 | + $show_trash = ! ((count($default_prices) > 1 && $price_row === 1) || count($default_prices) === 1); |
|
2101 | + $show_create = ! (count($default_prices) > 1 && count($default_prices) !== $price_row); |
|
2102 | 2102 | $template_args['default_price_rows'] .= $this->_get_ticket_price_row( |
2103 | 2103 | 'TICKETNUM', |
2104 | 2104 | $price_row, |
@@ -2118,7 +2118,7 @@ discard block |
||
2118 | 2118 | $this->_is_creating_event |
2119 | 2119 | ); |
2120 | 2120 | return EEH_Template::display_template( |
2121 | - PRICING_TEMPLATE_PATH . 'event_tickets_datetime_ticket_js_structure.template.php', |
|
2121 | + PRICING_TEMPLATE_PATH.'event_tickets_datetime_ticket_js_structure.template.php', |
|
2122 | 2122 | $template_args, |
2123 | 2123 | true |
2124 | 2124 | ); |
@@ -98,7 +98,7 @@ |
||
98 | 98 | * |
99 | 99 | * @param EE_Event $event EE event object |
100 | 100 | * @param array $data The request data from the form |
101 | - * @return bool success or fail |
|
101 | + * @return integer success or fail |
|
102 | 102 | * @throws EE_Error |
103 | 103 | */ |
104 | 104 | public function attach_evt_message_templates($event, $data) |
@@ -14,276 +14,276 @@ |
||
14 | 14 | */ |
15 | 15 | class espresso_events_Messages_Hooks_Extend extends espresso_events_Messages_Hooks |
16 | 16 | { |
17 | - /** |
|
18 | - * espresso_events_Messages_Hooks_Extend constructor. |
|
19 | - * |
|
20 | - * @param \EE_Admin_Page $admin_page |
|
21 | - */ |
|
22 | - public function __construct(EE_Admin_Page $admin_page) |
|
23 | - { |
|
24 | - /** |
|
25 | - * Add cap restriction ... metaboxes should not show if user does not have the ability to edit_custom_messages |
|
26 | - */ |
|
27 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
28 | - 'ee_edit_messages', |
|
29 | - 'messages_events_editor_metabox' |
|
30 | - )) { |
|
31 | - return; |
|
32 | - } |
|
33 | - add_filter( |
|
34 | - 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
35 | - array($this, 'caf_updates'), |
|
36 | - 10 |
|
37 | - ); |
|
38 | - add_action( |
|
39 | - 'AHEE__Extend_Events_Admin_Page___duplicate_event__after', |
|
40 | - array($this, 'duplicate_custom_message_settings'), |
|
41 | - 10, |
|
42 | - 2 |
|
43 | - ); |
|
44 | - parent::__construct($admin_page); |
|
45 | - } |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * extending the properties set in espresso_events_Messages_Hooks |
|
50 | - * |
|
51 | - * @access protected |
|
52 | - * @return void |
|
53 | - */ |
|
54 | - protected function _extend_properties() |
|
55 | - { |
|
56 | - define('EE_MSGS_EXTEND_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'messages/assets/'); |
|
57 | - $this->_ajax_func = array( |
|
58 | - 'ee_msgs_create_new_custom' => 'create_new_custom', |
|
59 | - ); |
|
60 | - $this->_metaboxes = array( |
|
61 | - 0 => array( |
|
62 | - 'page_route' => array('edit', 'create_new'), |
|
63 | - 'func' => 'messages_metabox', |
|
64 | - 'label' => esc_html__('Notifications', 'event_espresso'), |
|
65 | - 'priority' => 'high', |
|
66 | - ), |
|
67 | - ); |
|
68 | - |
|
69 | - //see explanation for layout in EE_Admin_Hooks |
|
70 | - $this->_scripts_styles = array( |
|
71 | - 'registers' => array( |
|
72 | - 'events_msg_admin' => array( |
|
73 | - 'url' => EE_MSGS_EXTEND_ASSETS_URL . 'events_messages_admin.js', |
|
74 | - 'depends' => array('ee-dialog', 'ee-parse-uri', 'ee-serialize-full-array'), |
|
75 | - ), |
|
76 | - 'events_msg_admin_css' => array( |
|
77 | - 'url' => EE_MSGS_EXTEND_ASSETS_URL . 'ee_msg_events_admin.css', |
|
78 | - 'type' => 'css', |
|
79 | - ), |
|
80 | - ), |
|
81 | - 'enqueues' => array( |
|
82 | - 'events_msg_admin' => array('edit', 'create_new'), |
|
83 | - 'events_msg_admin_css' => array('edit', 'create_new'), |
|
84 | - ), |
|
85 | - ); |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - public function caf_updates($update_callbacks) |
|
90 | - { |
|
91 | - $update_callbacks[] = array($this, 'attach_evt_message_templates'); |
|
92 | - return $update_callbacks; |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * Handles attaching Message Templates to the Event on save. |
|
98 | - * |
|
99 | - * @param EE_Event $event EE event object |
|
100 | - * @param array $data The request data from the form |
|
101 | - * @return bool success or fail |
|
102 | - * @throws EE_Error |
|
103 | - */ |
|
104 | - public function attach_evt_message_templates($event, $data) |
|
105 | - { |
|
106 | - //first we remove all existing relations on the Event for message types. |
|
107 | - $event->_remove_relations('Message_Template_Group'); |
|
108 | - //now let's just loop through the selected templates and add relations! |
|
109 | - if (isset($data['event_message_templates_relation'])) { |
|
110 | - foreach ($data['event_message_templates_relation'] as $grp_ID) { |
|
111 | - $event->_add_relation_to($grp_ID, 'Message_Template_Group'); |
|
112 | - } |
|
113 | - } |
|
114 | - //now save |
|
115 | - return $event->save(); |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * @param $event |
|
121 | - * @param $callback_args |
|
122 | - * @return string |
|
123 | - * @throws \EE_Error |
|
124 | - */ |
|
125 | - public function messages_metabox($event, $callback_args) |
|
126 | - { |
|
127 | - //let's get the active messengers (b/c messenger objects have the active message templates) |
|
128 | - //convert 'evt_id' to 'EVT_ID' |
|
129 | - $this->_req_data['EVT_ID'] = isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null; |
|
130 | - $this->_req_data['EVT_ID'] = isset($this->_req_data['post']) && empty($this->_req_data['EVT_ID']) |
|
131 | - ? $this->_req_data['post'] |
|
132 | - : $this->_req_data['EVT_ID']; |
|
133 | - |
|
134 | - $this->_req_data['EVT_ID'] = empty($this->_req_data['EVT_ID']) && isset($this->_req_data['evt_id']) |
|
135 | - ? $this->_req_data['evt_id'] |
|
136 | - : $this->_req_data['EVT_ID']; |
|
137 | - /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
138 | - $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
139 | - $active_messengers = $message_resource_manager->active_messengers(); |
|
140 | - $tabs = array(); |
|
141 | - |
|
142 | - //empty messengers? |
|
143 | - //Note message types will always have at least one available because every messenger has a default message type |
|
144 | - // associated with it (payment) if no other message types are selected. |
|
145 | - if (empty($active_messengers)) { |
|
146 | - $msg_activate_url = EE_Admin_Page::add_query_args_and_nonce( |
|
147 | - array('action' => 'settings'), |
|
148 | - EE_MSG_ADMIN_URL |
|
149 | - ); |
|
150 | - $error_msg = sprintf( |
|
151 | - esc_html__( |
|
152 | - 'There are no active messengers. So no notifications will go out for %1$sany%2$s events. You will want to %3$sActivate a Messenger%4$s.', |
|
153 | - 'event_espresso' |
|
154 | - ), |
|
155 | - '<strong>', |
|
156 | - '</strong>', |
|
157 | - '<a href="' . $msg_activate_url . '">', |
|
158 | - '</a>' |
|
159 | - ); |
|
160 | - $error_content = '<div class="error"><p>' . $error_msg . '</p></div>'; |
|
161 | - $internal_content = '<div id="messages-error"><p>' . $error_msg . '</p></div>'; |
|
162 | - |
|
163 | - echo $error_content; |
|
164 | - echo $internal_content; |
|
165 | - return ''; |
|
166 | - } |
|
167 | - |
|
168 | - $event_id = isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null; |
|
169 | - //get content for active messengers |
|
170 | - foreach ($active_messengers as $name => $messenger) { |
|
171 | - //first check if there are any active message types for this messenger. |
|
172 | - $active_mts = $message_resource_manager->get_active_message_types_for_messenger($name); |
|
173 | - if (empty($active_mts)) { |
|
174 | - continue; |
|
175 | - } |
|
176 | - |
|
177 | - $tab_content = $messenger->get_messenger_admin_page_content( |
|
178 | - 'events', |
|
179 | - 'edit', |
|
180 | - array('event' => $event_id) |
|
181 | - ); |
|
182 | - |
|
183 | - if (! empty($tab_content)) { |
|
184 | - $tabs[$name] = $tab_content; |
|
185 | - } |
|
186 | - } |
|
187 | - |
|
188 | - |
|
189 | - //we want this to be tabbed content so let's use the EEH_Tabbed_Content::display helper. |
|
190 | - $tabbed_content = EEH_Tabbed_Content::display($tabs); |
|
191 | - if ($tabbed_content instanceof WP_Error) { |
|
192 | - $tabbed_content = $tabbed_content->get_error_message(); |
|
193 | - } |
|
194 | - |
|
195 | - $notices = ' |
|
17 | + /** |
|
18 | + * espresso_events_Messages_Hooks_Extend constructor. |
|
19 | + * |
|
20 | + * @param \EE_Admin_Page $admin_page |
|
21 | + */ |
|
22 | + public function __construct(EE_Admin_Page $admin_page) |
|
23 | + { |
|
24 | + /** |
|
25 | + * Add cap restriction ... metaboxes should not show if user does not have the ability to edit_custom_messages |
|
26 | + */ |
|
27 | + if (! EE_Registry::instance()->CAP->current_user_can( |
|
28 | + 'ee_edit_messages', |
|
29 | + 'messages_events_editor_metabox' |
|
30 | + )) { |
|
31 | + return; |
|
32 | + } |
|
33 | + add_filter( |
|
34 | + 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
35 | + array($this, 'caf_updates'), |
|
36 | + 10 |
|
37 | + ); |
|
38 | + add_action( |
|
39 | + 'AHEE__Extend_Events_Admin_Page___duplicate_event__after', |
|
40 | + array($this, 'duplicate_custom_message_settings'), |
|
41 | + 10, |
|
42 | + 2 |
|
43 | + ); |
|
44 | + parent::__construct($admin_page); |
|
45 | + } |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * extending the properties set in espresso_events_Messages_Hooks |
|
50 | + * |
|
51 | + * @access protected |
|
52 | + * @return void |
|
53 | + */ |
|
54 | + protected function _extend_properties() |
|
55 | + { |
|
56 | + define('EE_MSGS_EXTEND_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'messages/assets/'); |
|
57 | + $this->_ajax_func = array( |
|
58 | + 'ee_msgs_create_new_custom' => 'create_new_custom', |
|
59 | + ); |
|
60 | + $this->_metaboxes = array( |
|
61 | + 0 => array( |
|
62 | + 'page_route' => array('edit', 'create_new'), |
|
63 | + 'func' => 'messages_metabox', |
|
64 | + 'label' => esc_html__('Notifications', 'event_espresso'), |
|
65 | + 'priority' => 'high', |
|
66 | + ), |
|
67 | + ); |
|
68 | + |
|
69 | + //see explanation for layout in EE_Admin_Hooks |
|
70 | + $this->_scripts_styles = array( |
|
71 | + 'registers' => array( |
|
72 | + 'events_msg_admin' => array( |
|
73 | + 'url' => EE_MSGS_EXTEND_ASSETS_URL . 'events_messages_admin.js', |
|
74 | + 'depends' => array('ee-dialog', 'ee-parse-uri', 'ee-serialize-full-array'), |
|
75 | + ), |
|
76 | + 'events_msg_admin_css' => array( |
|
77 | + 'url' => EE_MSGS_EXTEND_ASSETS_URL . 'ee_msg_events_admin.css', |
|
78 | + 'type' => 'css', |
|
79 | + ), |
|
80 | + ), |
|
81 | + 'enqueues' => array( |
|
82 | + 'events_msg_admin' => array('edit', 'create_new'), |
|
83 | + 'events_msg_admin_css' => array('edit', 'create_new'), |
|
84 | + ), |
|
85 | + ); |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + public function caf_updates($update_callbacks) |
|
90 | + { |
|
91 | + $update_callbacks[] = array($this, 'attach_evt_message_templates'); |
|
92 | + return $update_callbacks; |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * Handles attaching Message Templates to the Event on save. |
|
98 | + * |
|
99 | + * @param EE_Event $event EE event object |
|
100 | + * @param array $data The request data from the form |
|
101 | + * @return bool success or fail |
|
102 | + * @throws EE_Error |
|
103 | + */ |
|
104 | + public function attach_evt_message_templates($event, $data) |
|
105 | + { |
|
106 | + //first we remove all existing relations on the Event for message types. |
|
107 | + $event->_remove_relations('Message_Template_Group'); |
|
108 | + //now let's just loop through the selected templates and add relations! |
|
109 | + if (isset($data['event_message_templates_relation'])) { |
|
110 | + foreach ($data['event_message_templates_relation'] as $grp_ID) { |
|
111 | + $event->_add_relation_to($grp_ID, 'Message_Template_Group'); |
|
112 | + } |
|
113 | + } |
|
114 | + //now save |
|
115 | + return $event->save(); |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * @param $event |
|
121 | + * @param $callback_args |
|
122 | + * @return string |
|
123 | + * @throws \EE_Error |
|
124 | + */ |
|
125 | + public function messages_metabox($event, $callback_args) |
|
126 | + { |
|
127 | + //let's get the active messengers (b/c messenger objects have the active message templates) |
|
128 | + //convert 'evt_id' to 'EVT_ID' |
|
129 | + $this->_req_data['EVT_ID'] = isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null; |
|
130 | + $this->_req_data['EVT_ID'] = isset($this->_req_data['post']) && empty($this->_req_data['EVT_ID']) |
|
131 | + ? $this->_req_data['post'] |
|
132 | + : $this->_req_data['EVT_ID']; |
|
133 | + |
|
134 | + $this->_req_data['EVT_ID'] = empty($this->_req_data['EVT_ID']) && isset($this->_req_data['evt_id']) |
|
135 | + ? $this->_req_data['evt_id'] |
|
136 | + : $this->_req_data['EVT_ID']; |
|
137 | + /** @type EE_Message_Resource_Manager $message_resource_manager */ |
|
138 | + $message_resource_manager = EE_Registry::instance()->load_lib('Message_Resource_Manager'); |
|
139 | + $active_messengers = $message_resource_manager->active_messengers(); |
|
140 | + $tabs = array(); |
|
141 | + |
|
142 | + //empty messengers? |
|
143 | + //Note message types will always have at least one available because every messenger has a default message type |
|
144 | + // associated with it (payment) if no other message types are selected. |
|
145 | + if (empty($active_messengers)) { |
|
146 | + $msg_activate_url = EE_Admin_Page::add_query_args_and_nonce( |
|
147 | + array('action' => 'settings'), |
|
148 | + EE_MSG_ADMIN_URL |
|
149 | + ); |
|
150 | + $error_msg = sprintf( |
|
151 | + esc_html__( |
|
152 | + 'There are no active messengers. So no notifications will go out for %1$sany%2$s events. You will want to %3$sActivate a Messenger%4$s.', |
|
153 | + 'event_espresso' |
|
154 | + ), |
|
155 | + '<strong>', |
|
156 | + '</strong>', |
|
157 | + '<a href="' . $msg_activate_url . '">', |
|
158 | + '</a>' |
|
159 | + ); |
|
160 | + $error_content = '<div class="error"><p>' . $error_msg . '</p></div>'; |
|
161 | + $internal_content = '<div id="messages-error"><p>' . $error_msg . '</p></div>'; |
|
162 | + |
|
163 | + echo $error_content; |
|
164 | + echo $internal_content; |
|
165 | + return ''; |
|
166 | + } |
|
167 | + |
|
168 | + $event_id = isset($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : null; |
|
169 | + //get content for active messengers |
|
170 | + foreach ($active_messengers as $name => $messenger) { |
|
171 | + //first check if there are any active message types for this messenger. |
|
172 | + $active_mts = $message_resource_manager->get_active_message_types_for_messenger($name); |
|
173 | + if (empty($active_mts)) { |
|
174 | + continue; |
|
175 | + } |
|
176 | + |
|
177 | + $tab_content = $messenger->get_messenger_admin_page_content( |
|
178 | + 'events', |
|
179 | + 'edit', |
|
180 | + array('event' => $event_id) |
|
181 | + ); |
|
182 | + |
|
183 | + if (! empty($tab_content)) { |
|
184 | + $tabs[$name] = $tab_content; |
|
185 | + } |
|
186 | + } |
|
187 | + |
|
188 | + |
|
189 | + //we want this to be tabbed content so let's use the EEH_Tabbed_Content::display helper. |
|
190 | + $tabbed_content = EEH_Tabbed_Content::display($tabs); |
|
191 | + if ($tabbed_content instanceof WP_Error) { |
|
192 | + $tabbed_content = $tabbed_content->get_error_message(); |
|
193 | + } |
|
194 | + |
|
195 | + $notices = ' |
|
196 | 196 | <div id="espresso-ajax-loading" class="ajax-loader-grey"> |
197 | 197 | <span class="ee-spinner ee-spin"></span><span class="hidden">' |
198 | - . esc_html__('loading...', 'event_espresso') |
|
199 | - . '</span> |
|
198 | + . esc_html__('loading...', 'event_espresso') |
|
199 | + . '</span> |
|
200 | 200 | </div> |
201 | 201 | <div class="ee-notices"></div>'; |
202 | 202 | |
203 | - if (defined('DOING_AJAX')) { |
|
204 | - return $tabbed_content; |
|
205 | - } |
|
206 | - |
|
207 | - do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__before_content'); |
|
208 | - echo $notices . '<div class="messages-tabs-content">' . $tabbed_content . '</div>'; |
|
209 | - do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__after_content'); |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - /** |
|
214 | - * Ajax callback for ee_msgs_create_new_custom ajax request. |
|
215 | - * Takes incoming GRP_ID and name and description values from ajax request |
|
216 | - * to create a new custom template based off of the incoming GRP_ID. |
|
217 | - * |
|
218 | - * @access public |
|
219 | - * @return string either an html string will be returned or a success message |
|
220 | - * @throws EE_Error |
|
221 | - */ |
|
222 | - public function create_new_custom() |
|
223 | - { |
|
224 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'create_new_custom_ajax')) { |
|
225 | - wp_die(__('You don\'t have privileges to do this action', 'event_espresso')); |
|
226 | - } |
|
227 | - |
|
228 | - //let's clean up the _POST global a bit for downstream usage of name and description. |
|
229 | - $_POST['templateName'] = ! empty($this->_req_data['custom_template_args']['MTP_name']) |
|
230 | - ? $this->_req_data['custom_template_args']['MTP_name'] |
|
231 | - : ''; |
|
232 | - $_POST['templateDescription'] = ! empty($this->_req_data['custom_template_args']['MTP_description']) |
|
233 | - ? $this->_req_data['custom_template_args']['MTP_description'] |
|
234 | - : ''; |
|
235 | - |
|
236 | - |
|
237 | - // set EE_Admin_Page object (see method details in EE_Admin_Hooks parent |
|
238 | - $this->_set_page_object(); |
|
239 | - |
|
240 | - // is this a template switch if so EE_Admin_Page child needs this object |
|
241 | - $this->_page_object->set_hook_object($this); |
|
242 | - |
|
243 | - $this->_page_object->add_message_template( |
|
244 | - $this->_req_data['messageType'], |
|
245 | - $this->_req_data['messenger'], |
|
246 | - $this->_req_data['group_ID'] |
|
247 | - ); |
|
248 | - } |
|
249 | - |
|
250 | - |
|
251 | - public function create_new_admin_footer() |
|
252 | - { |
|
253 | - $this->edit_admin_footer(); |
|
254 | - } |
|
255 | - |
|
256 | - |
|
257 | - /** |
|
258 | - * This is the dynamic method for this class |
|
259 | - * that will end up hooking into the 'admin_footer' hook on the 'edit_event' route in the events page. |
|
260 | - * |
|
261 | - * @return string |
|
262 | - * @throws DomainException |
|
263 | - */ |
|
264 | - public function edit_admin_footer() |
|
265 | - { |
|
266 | - EEH_Template::display_template( |
|
267 | - EE_CORE_CAF_ADMIN_EXTEND . 'messages/templates/create_custom_template_form.template.php' |
|
268 | - ); |
|
269 | - } |
|
270 | - |
|
271 | - |
|
272 | - /** |
|
273 | - * Callback for AHEE__Extend_Events_Admin_Page___duplicate_event__after hook used to ensure new events duplicate |
|
274 | - * the assigned custom message templates. |
|
275 | - * |
|
276 | - * @param EE_Event $new_event |
|
277 | - * @param EE_Event $original_event |
|
278 | - * @throws EE_Error |
|
279 | - */ |
|
280 | - public function duplicate_custom_message_settings(EE_Event $new_event, EE_Event $original_event) |
|
281 | - { |
|
282 | - $message_template_groups = $original_event->get_many_related('Message_Template_Group'); |
|
283 | - foreach ($message_template_groups as $message_template_group) { |
|
284 | - $new_event->_add_relation_to($message_template_group, 'Message_Template_Group'); |
|
285 | - } |
|
286 | - //save new event |
|
287 | - $new_event->save(); |
|
288 | - } |
|
203 | + if (defined('DOING_AJAX')) { |
|
204 | + return $tabbed_content; |
|
205 | + } |
|
206 | + |
|
207 | + do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__before_content'); |
|
208 | + echo $notices . '<div class="messages-tabs-content">' . $tabbed_content . '</div>'; |
|
209 | + do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__after_content'); |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + /** |
|
214 | + * Ajax callback for ee_msgs_create_new_custom ajax request. |
|
215 | + * Takes incoming GRP_ID and name and description values from ajax request |
|
216 | + * to create a new custom template based off of the incoming GRP_ID. |
|
217 | + * |
|
218 | + * @access public |
|
219 | + * @return string either an html string will be returned or a success message |
|
220 | + * @throws EE_Error |
|
221 | + */ |
|
222 | + public function create_new_custom() |
|
223 | + { |
|
224 | + if (! EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'create_new_custom_ajax')) { |
|
225 | + wp_die(__('You don\'t have privileges to do this action', 'event_espresso')); |
|
226 | + } |
|
227 | + |
|
228 | + //let's clean up the _POST global a bit for downstream usage of name and description. |
|
229 | + $_POST['templateName'] = ! empty($this->_req_data['custom_template_args']['MTP_name']) |
|
230 | + ? $this->_req_data['custom_template_args']['MTP_name'] |
|
231 | + : ''; |
|
232 | + $_POST['templateDescription'] = ! empty($this->_req_data['custom_template_args']['MTP_description']) |
|
233 | + ? $this->_req_data['custom_template_args']['MTP_description'] |
|
234 | + : ''; |
|
235 | + |
|
236 | + |
|
237 | + // set EE_Admin_Page object (see method details in EE_Admin_Hooks parent |
|
238 | + $this->_set_page_object(); |
|
239 | + |
|
240 | + // is this a template switch if so EE_Admin_Page child needs this object |
|
241 | + $this->_page_object->set_hook_object($this); |
|
242 | + |
|
243 | + $this->_page_object->add_message_template( |
|
244 | + $this->_req_data['messageType'], |
|
245 | + $this->_req_data['messenger'], |
|
246 | + $this->_req_data['group_ID'] |
|
247 | + ); |
|
248 | + } |
|
249 | + |
|
250 | + |
|
251 | + public function create_new_admin_footer() |
|
252 | + { |
|
253 | + $this->edit_admin_footer(); |
|
254 | + } |
|
255 | + |
|
256 | + |
|
257 | + /** |
|
258 | + * This is the dynamic method for this class |
|
259 | + * that will end up hooking into the 'admin_footer' hook on the 'edit_event' route in the events page. |
|
260 | + * |
|
261 | + * @return string |
|
262 | + * @throws DomainException |
|
263 | + */ |
|
264 | + public function edit_admin_footer() |
|
265 | + { |
|
266 | + EEH_Template::display_template( |
|
267 | + EE_CORE_CAF_ADMIN_EXTEND . 'messages/templates/create_custom_template_form.template.php' |
|
268 | + ); |
|
269 | + } |
|
270 | + |
|
271 | + |
|
272 | + /** |
|
273 | + * Callback for AHEE__Extend_Events_Admin_Page___duplicate_event__after hook used to ensure new events duplicate |
|
274 | + * the assigned custom message templates. |
|
275 | + * |
|
276 | + * @param EE_Event $new_event |
|
277 | + * @param EE_Event $original_event |
|
278 | + * @throws EE_Error |
|
279 | + */ |
|
280 | + public function duplicate_custom_message_settings(EE_Event $new_event, EE_Event $original_event) |
|
281 | + { |
|
282 | + $message_template_groups = $original_event->get_many_related('Message_Template_Group'); |
|
283 | + foreach ($message_template_groups as $message_template_group) { |
|
284 | + $new_event->_add_relation_to($message_template_group, 'Message_Template_Group'); |
|
285 | + } |
|
286 | + //save new event |
|
287 | + $new_event->save(); |
|
288 | + } |
|
289 | 289 | } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | /** |
25 | 25 | * Add cap restriction ... metaboxes should not show if user does not have the ability to edit_custom_messages |
26 | 26 | */ |
27 | - if (! EE_Registry::instance()->CAP->current_user_can( |
|
27 | + if ( ! EE_Registry::instance()->CAP->current_user_can( |
|
28 | 28 | 'ee_edit_messages', |
29 | 29 | 'messages_events_editor_metabox' |
30 | 30 | )) { |
@@ -53,7 +53,7 @@ discard block |
||
53 | 53 | */ |
54 | 54 | protected function _extend_properties() |
55 | 55 | { |
56 | - define('EE_MSGS_EXTEND_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'messages/assets/'); |
|
56 | + define('EE_MSGS_EXTEND_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'messages/assets/'); |
|
57 | 57 | $this->_ajax_func = array( |
58 | 58 | 'ee_msgs_create_new_custom' => 'create_new_custom', |
59 | 59 | ); |
@@ -70,11 +70,11 @@ discard block |
||
70 | 70 | $this->_scripts_styles = array( |
71 | 71 | 'registers' => array( |
72 | 72 | 'events_msg_admin' => array( |
73 | - 'url' => EE_MSGS_EXTEND_ASSETS_URL . 'events_messages_admin.js', |
|
73 | + 'url' => EE_MSGS_EXTEND_ASSETS_URL.'events_messages_admin.js', |
|
74 | 74 | 'depends' => array('ee-dialog', 'ee-parse-uri', 'ee-serialize-full-array'), |
75 | 75 | ), |
76 | 76 | 'events_msg_admin_css' => array( |
77 | - 'url' => EE_MSGS_EXTEND_ASSETS_URL . 'ee_msg_events_admin.css', |
|
77 | + 'url' => EE_MSGS_EXTEND_ASSETS_URL.'ee_msg_events_admin.css', |
|
78 | 78 | 'type' => 'css', |
79 | 79 | ), |
80 | 80 | ), |
@@ -147,18 +147,18 @@ discard block |
||
147 | 147 | array('action' => 'settings'), |
148 | 148 | EE_MSG_ADMIN_URL |
149 | 149 | ); |
150 | - $error_msg = sprintf( |
|
150 | + $error_msg = sprintf( |
|
151 | 151 | esc_html__( |
152 | 152 | 'There are no active messengers. So no notifications will go out for %1$sany%2$s events. You will want to %3$sActivate a Messenger%4$s.', |
153 | 153 | 'event_espresso' |
154 | 154 | ), |
155 | 155 | '<strong>', |
156 | 156 | '</strong>', |
157 | - '<a href="' . $msg_activate_url . '">', |
|
157 | + '<a href="'.$msg_activate_url.'">', |
|
158 | 158 | '</a>' |
159 | 159 | ); |
160 | - $error_content = '<div class="error"><p>' . $error_msg . '</p></div>'; |
|
161 | - $internal_content = '<div id="messages-error"><p>' . $error_msg . '</p></div>'; |
|
160 | + $error_content = '<div class="error"><p>'.$error_msg.'</p></div>'; |
|
161 | + $internal_content = '<div id="messages-error"><p>'.$error_msg.'</p></div>'; |
|
162 | 162 | |
163 | 163 | echo $error_content; |
164 | 164 | echo $internal_content; |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | array('event' => $event_id) |
181 | 181 | ); |
182 | 182 | |
183 | - if (! empty($tab_content)) { |
|
183 | + if ( ! empty($tab_content)) { |
|
184 | 184 | $tabs[$name] = $tab_content; |
185 | 185 | } |
186 | 186 | } |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | } |
206 | 206 | |
207 | 207 | do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__before_content'); |
208 | - echo $notices . '<div class="messages-tabs-content">' . $tabbed_content . '</div>'; |
|
208 | + echo $notices.'<div class="messages-tabs-content">'.$tabbed_content.'</div>'; |
|
209 | 209 | do_action('AHEE__espresso_events_Messages_Hooks_Extend__messages_metabox__after_content'); |
210 | 210 | } |
211 | 211 | |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | */ |
222 | 222 | public function create_new_custom() |
223 | 223 | { |
224 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'create_new_custom_ajax')) { |
|
224 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_edit_messages', 'create_new_custom_ajax')) { |
|
225 | 225 | wp_die(__('You don\'t have privileges to do this action', 'event_espresso')); |
226 | 226 | } |
227 | 227 | |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | public function edit_admin_footer() |
265 | 265 | { |
266 | 266 | EEH_Template::display_template( |
267 | - EE_CORE_CAF_ADMIN_EXTEND . 'messages/templates/create_custom_template_form.template.php' |
|
267 | + EE_CORE_CAF_ADMIN_EXTEND.'messages/templates/create_custom_template_form.template.php' |
|
268 | 268 | ); |
269 | 269 | } |
270 | 270 |
@@ -13,7 +13,7 @@ |
||
13 | 13 | * @param string $table_column |
14 | 14 | * @param string $nicename |
15 | 15 | * @param bool $nullable |
16 | - * @param null $default_value |
|
16 | + * @param string $default_value |
|
17 | 17 | */ |
18 | 18 | public function __construct($table_column, $nicename, $nullable, $default_value = null) |
19 | 19 | { |
@@ -8,133 +8,133 @@ |
||
8 | 8 | class EE_Post_Content_Field extends EE_Text_Field_Base |
9 | 9 | { |
10 | 10 | |
11 | - /** |
|
12 | - * @param string $table_column |
|
13 | - * @param string $nicename |
|
14 | - * @param bool $nullable |
|
15 | - * @param null $default_value |
|
16 | - */ |
|
17 | - public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
18 | - { |
|
19 | - parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
20 | - $this->setSchemaType('object'); |
|
21 | - } |
|
11 | + /** |
|
12 | + * @param string $table_column |
|
13 | + * @param string $nicename |
|
14 | + * @param bool $nullable |
|
15 | + * @param null $default_value |
|
16 | + */ |
|
17 | + public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
18 | + { |
|
19 | + parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
20 | + $this->setSchemaType('object'); |
|
21 | + } |
|
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * removes all tags which a WP Post wouldn't allow in its content normally |
|
26 | - * |
|
27 | - * @param string $value |
|
28 | - * @return string |
|
29 | - */ |
|
30 | - function prepare_for_set($value) |
|
31 | - { |
|
32 | - if (! current_user_can('unfiltered_html')) { |
|
33 | - $value = wp_kses("$value", wp_kses_allowed_html('post')); |
|
34 | - } |
|
35 | - return parent::prepare_for_set($value); |
|
36 | - } |
|
24 | + /** |
|
25 | + * removes all tags which a WP Post wouldn't allow in its content normally |
|
26 | + * |
|
27 | + * @param string $value |
|
28 | + * @return string |
|
29 | + */ |
|
30 | + function prepare_for_set($value) |
|
31 | + { |
|
32 | + if (! current_user_can('unfiltered_html')) { |
|
33 | + $value = wp_kses("$value", wp_kses_allowed_html('post')); |
|
34 | + } |
|
35 | + return parent::prepare_for_set($value); |
|
36 | + } |
|
37 | 37 | |
38 | - function prepare_for_set_from_db($value_found_in_db_for_model_object) |
|
39 | - { |
|
40 | - return $value_found_in_db_for_model_object; |
|
41 | - } |
|
38 | + function prepare_for_set_from_db($value_found_in_db_for_model_object) |
|
39 | + { |
|
40 | + return $value_found_in_db_for_model_object; |
|
41 | + } |
|
42 | 42 | |
43 | 43 | |
44 | 44 | |
45 | - /** |
|
46 | - * Runs the content through `the_content`, or if prepares the content for placing in a form input |
|
47 | - * @param string $value_on_field_to_be_outputted |
|
48 | - * @param string $schema possible values: 'form_input' or null (if null, will run through 'the_content') |
|
49 | - * @return string |
|
50 | - * @throws EE_Error when WP_DEBUG is on and recursive calling is detected |
|
51 | - */ |
|
52 | - public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) |
|
53 | - { |
|
54 | - switch($schema){ |
|
55 | - case 'form_input': |
|
56 | - return parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema); |
|
57 | - case 'the_content': |
|
45 | + /** |
|
46 | + * Runs the content through `the_content`, or if prepares the content for placing in a form input |
|
47 | + * @param string $value_on_field_to_be_outputted |
|
48 | + * @param string $schema possible values: 'form_input' or null (if null, will run through 'the_content') |
|
49 | + * @return string |
|
50 | + * @throws EE_Error when WP_DEBUG is on and recursive calling is detected |
|
51 | + */ |
|
52 | + public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) |
|
53 | + { |
|
54 | + switch($schema){ |
|
55 | + case 'form_input': |
|
56 | + return parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema); |
|
57 | + case 'the_content': |
|
58 | 58 | |
59 | - if(doing_filter( 'the_content')){ |
|
60 | - if( defined('WP_DEBUG') && WP_DEBUG){ |
|
61 | - throw new EE_Error( |
|
62 | - sprintf( |
|
63 | - esc_html__('You have recursively called "%1$s" with %2$s set to %3$s which uses "%2$s" filter. You should use it with %2$s "%3$s" instead here.', 'event_espresso'), |
|
64 | - 'EE_Post_Content_Field::prepare_for_pretty_echoing', |
|
65 | - '$schema', |
|
66 | - 'the_content', |
|
67 | - 'the_content_wp_core_only' |
|
68 | - ) |
|
69 | - ); |
|
70 | - } else { |
|
71 | - return $this->prepare_for_pretty_echoing($value_on_field_to_be_outputted, 'the_content_wp_core_only'); |
|
72 | - } |
|
73 | - } |
|
74 | - return apply_filters( |
|
75 | - 'the_content', |
|
76 | - parent::prepare_for_pretty_echoing( |
|
77 | - $value_on_field_to_be_outputted, |
|
78 | - $schema |
|
79 | - ) |
|
80 | - ); |
|
81 | - case 'the_content_wp_core_only': |
|
82 | - default: |
|
83 | - self::_setup_the_content_wp_core_only_filters(); |
|
84 | - $return_value = apply_filters( |
|
85 | - 'the_content_wp_core_only', |
|
86 | - parent::prepare_for_pretty_echoing( |
|
87 | - $value_on_field_to_be_outputted, |
|
88 | - $schema |
|
89 | - ) |
|
90 | - ); |
|
91 | - //ya know what? adding these filters is super fast. Let's just |
|
92 | - //avoid needing to maintain global state and set this up as-needed |
|
93 | - remove_all_filters('the_content_wp_core_only'); |
|
94 | - do_action( 'AHEE__EE_Post_Content_Field__prepare_for_pretty_echoing__the_content_wp_core_only__done'); |
|
95 | - return $return_value; |
|
96 | - } |
|
97 | - } |
|
59 | + if(doing_filter( 'the_content')){ |
|
60 | + if( defined('WP_DEBUG') && WP_DEBUG){ |
|
61 | + throw new EE_Error( |
|
62 | + sprintf( |
|
63 | + esc_html__('You have recursively called "%1$s" with %2$s set to %3$s which uses "%2$s" filter. You should use it with %2$s "%3$s" instead here.', 'event_espresso'), |
|
64 | + 'EE_Post_Content_Field::prepare_for_pretty_echoing', |
|
65 | + '$schema', |
|
66 | + 'the_content', |
|
67 | + 'the_content_wp_core_only' |
|
68 | + ) |
|
69 | + ); |
|
70 | + } else { |
|
71 | + return $this->prepare_for_pretty_echoing($value_on_field_to_be_outputted, 'the_content_wp_core_only'); |
|
72 | + } |
|
73 | + } |
|
74 | + return apply_filters( |
|
75 | + 'the_content', |
|
76 | + parent::prepare_for_pretty_echoing( |
|
77 | + $value_on_field_to_be_outputted, |
|
78 | + $schema |
|
79 | + ) |
|
80 | + ); |
|
81 | + case 'the_content_wp_core_only': |
|
82 | + default: |
|
83 | + self::_setup_the_content_wp_core_only_filters(); |
|
84 | + $return_value = apply_filters( |
|
85 | + 'the_content_wp_core_only', |
|
86 | + parent::prepare_for_pretty_echoing( |
|
87 | + $value_on_field_to_be_outputted, |
|
88 | + $schema |
|
89 | + ) |
|
90 | + ); |
|
91 | + //ya know what? adding these filters is super fast. Let's just |
|
92 | + //avoid needing to maintain global state and set this up as-needed |
|
93 | + remove_all_filters('the_content_wp_core_only'); |
|
94 | + do_action( 'AHEE__EE_Post_Content_Field__prepare_for_pretty_echoing__the_content_wp_core_only__done'); |
|
95 | + return $return_value; |
|
96 | + } |
|
97 | + } |
|
98 | 98 | |
99 | 99 | |
100 | 100 | |
101 | - /** |
|
102 | - * Verifies we've setup the standard WP core filters on 'the_content_wp_core_only' filter |
|
103 | - */ |
|
104 | - protected static function _setup_the_content_wp_core_only_filters() |
|
105 | - { |
|
106 | - add_filter('the_content_wp_core_only', array( $GLOBALS['wp_embed'], 'run_shortcode'), 8); |
|
107 | - add_filter('the_content_wp_core_only', array( $GLOBALS['wp_embed'], 'autoembed'), 8); |
|
108 | - add_filter('the_content_wp_core_only', 'wptexturize', 10); |
|
109 | - add_filter('the_content_wp_core_only', 'wpautop', 10); |
|
110 | - add_filter('the_content_wp_core_only', 'shortcode_unautop', 10); |
|
111 | - add_filter('the_content_wp_core_only', 'prepend_attachment', 10); |
|
112 | - if(function_exists('wp_make_content_images_responsive')) { |
|
113 | - add_filter('the_content_wp_core_only', 'wp_make_content_images_responsive', 10); |
|
114 | - } |
|
115 | - add_filter('the_content_wp_core_only', 'do_shortcode', 11); |
|
116 | - add_filter('the_content_wp_core_only', 'convert_smilies', 20); |
|
117 | - } |
|
101 | + /** |
|
102 | + * Verifies we've setup the standard WP core filters on 'the_content_wp_core_only' filter |
|
103 | + */ |
|
104 | + protected static function _setup_the_content_wp_core_only_filters() |
|
105 | + { |
|
106 | + add_filter('the_content_wp_core_only', array( $GLOBALS['wp_embed'], 'run_shortcode'), 8); |
|
107 | + add_filter('the_content_wp_core_only', array( $GLOBALS['wp_embed'], 'autoembed'), 8); |
|
108 | + add_filter('the_content_wp_core_only', 'wptexturize', 10); |
|
109 | + add_filter('the_content_wp_core_only', 'wpautop', 10); |
|
110 | + add_filter('the_content_wp_core_only', 'shortcode_unautop', 10); |
|
111 | + add_filter('the_content_wp_core_only', 'prepend_attachment', 10); |
|
112 | + if(function_exists('wp_make_content_images_responsive')) { |
|
113 | + add_filter('the_content_wp_core_only', 'wp_make_content_images_responsive', 10); |
|
114 | + } |
|
115 | + add_filter('the_content_wp_core_only', 'do_shortcode', 11); |
|
116 | + add_filter('the_content_wp_core_only', 'convert_smilies', 20); |
|
117 | + } |
|
118 | 118 | |
119 | 119 | |
120 | 120 | |
121 | - public function getSchemaProperties() |
|
122 | - { |
|
123 | - return array( |
|
124 | - 'raw' => array( |
|
125 | - 'description' => sprintf( |
|
126 | - __('%s - the content as it exists in the database.', 'event_espresso'), |
|
127 | - $this->get_nicename() |
|
128 | - ), |
|
129 | - 'type' => 'string' |
|
130 | - ), |
|
131 | - 'rendered' => array( |
|
132 | - 'description' => sprintf( |
|
133 | - __('%s - the content rendered for display.', 'event_espresso'), |
|
134 | - $this->get_nicename() |
|
135 | - ), |
|
136 | - 'type' => 'string' |
|
137 | - ) |
|
138 | - ); |
|
139 | - } |
|
121 | + public function getSchemaProperties() |
|
122 | + { |
|
123 | + return array( |
|
124 | + 'raw' => array( |
|
125 | + 'description' => sprintf( |
|
126 | + __('%s - the content as it exists in the database.', 'event_espresso'), |
|
127 | + $this->get_nicename() |
|
128 | + ), |
|
129 | + 'type' => 'string' |
|
130 | + ), |
|
131 | + 'rendered' => array( |
|
132 | + 'description' => sprintf( |
|
133 | + __('%s - the content rendered for display.', 'event_espresso'), |
|
134 | + $this->get_nicename() |
|
135 | + ), |
|
136 | + 'type' => 'string' |
|
137 | + ) |
|
138 | + ); |
|
139 | + } |
|
140 | 140 | } |
141 | 141 | \ No newline at end of file |
@@ -29,7 +29,7 @@ discard block |
||
29 | 29 | */ |
30 | 30 | function prepare_for_set($value) |
31 | 31 | { |
32 | - if (! current_user_can('unfiltered_html')) { |
|
32 | + if ( ! current_user_can('unfiltered_html')) { |
|
33 | 33 | $value = wp_kses("$value", wp_kses_allowed_html('post')); |
34 | 34 | } |
35 | 35 | return parent::prepare_for_set($value); |
@@ -51,13 +51,13 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) |
53 | 53 | { |
54 | - switch($schema){ |
|
54 | + switch ($schema) { |
|
55 | 55 | case 'form_input': |
56 | 56 | return parent::prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema); |
57 | 57 | case 'the_content': |
58 | 58 | |
59 | - if(doing_filter( 'the_content')){ |
|
60 | - if( defined('WP_DEBUG') && WP_DEBUG){ |
|
59 | + if (doing_filter('the_content')) { |
|
60 | + if (defined('WP_DEBUG') && WP_DEBUG) { |
|
61 | 61 | throw new EE_Error( |
62 | 62 | sprintf( |
63 | 63 | esc_html__('You have recursively called "%1$s" with %2$s set to %3$s which uses "%2$s" filter. You should use it with %2$s "%3$s" instead here.', 'event_espresso'), |
@@ -91,7 +91,7 @@ discard block |
||
91 | 91 | //ya know what? adding these filters is super fast. Let's just |
92 | 92 | //avoid needing to maintain global state and set this up as-needed |
93 | 93 | remove_all_filters('the_content_wp_core_only'); |
94 | - do_action( 'AHEE__EE_Post_Content_Field__prepare_for_pretty_echoing__the_content_wp_core_only__done'); |
|
94 | + do_action('AHEE__EE_Post_Content_Field__prepare_for_pretty_echoing__the_content_wp_core_only__done'); |
|
95 | 95 | return $return_value; |
96 | 96 | } |
97 | 97 | } |
@@ -103,13 +103,13 @@ discard block |
||
103 | 103 | */ |
104 | 104 | protected static function _setup_the_content_wp_core_only_filters() |
105 | 105 | { |
106 | - add_filter('the_content_wp_core_only', array( $GLOBALS['wp_embed'], 'run_shortcode'), 8); |
|
107 | - add_filter('the_content_wp_core_only', array( $GLOBALS['wp_embed'], 'autoembed'), 8); |
|
106 | + add_filter('the_content_wp_core_only', array($GLOBALS['wp_embed'], 'run_shortcode'), 8); |
|
107 | + add_filter('the_content_wp_core_only', array($GLOBALS['wp_embed'], 'autoembed'), 8); |
|
108 | 108 | add_filter('the_content_wp_core_only', 'wptexturize', 10); |
109 | 109 | add_filter('the_content_wp_core_only', 'wpautop', 10); |
110 | 110 | add_filter('the_content_wp_core_only', 'shortcode_unautop', 10); |
111 | 111 | add_filter('the_content_wp_core_only', 'prepend_attachment', 10); |
112 | - if(function_exists('wp_make_content_images_responsive')) { |
|
112 | + if (function_exists('wp_make_content_images_responsive')) { |
|
113 | 113 | add_filter('the_content_wp_core_only', 'wp_make_content_images_responsive', 10); |
114 | 114 | } |
115 | 115 | add_filter('the_content_wp_core_only', 'do_shortcode', 11); |
@@ -456,7 +456,7 @@ |
||
456 | 456 | * be empty |
457 | 457 | * |
458 | 458 | * @since 4.3.1 |
459 | - * @return array |
|
459 | + * @return string[] |
|
460 | 460 | */ |
461 | 461 | private function _parse_from() |
462 | 462 | { |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
4 | - exit('NO direct script access allowed'); |
|
4 | + exit('NO direct script access allowed'); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -28,548 +28,548 @@ discard block |
||
28 | 28 | class EE_Email_messenger extends EE_messenger |
29 | 29 | { |
30 | 30 | |
31 | - /** |
|
32 | - * The following are the properties that email requires for the message going out. |
|
33 | - */ |
|
34 | - protected $_to; |
|
35 | - protected $_from; |
|
36 | - protected $_subject; |
|
37 | - protected $_content; |
|
38 | - |
|
39 | - |
|
40 | - /** |
|
41 | - * constructor |
|
42 | - * |
|
43 | - * @access public |
|
44 | - */ |
|
45 | - public function __construct() |
|
46 | - { |
|
47 | - //set name and description properties |
|
48 | - $this->name = 'email'; |
|
49 | - $this->description = __('This messenger delivers messages via email using the built-in <code>wp_mail</code> function included with WordPress', |
|
50 | - 'event_espresso'); |
|
51 | - $this->label = array( |
|
52 | - 'singular' => __('email', 'event_espresso'), |
|
53 | - 'plural' => __('emails', 'event_espresso'), |
|
54 | - ); |
|
55 | - $this->activate_on_install = true; |
|
56 | - |
|
57 | - //we're using defaults so let's call parent constructor that will take care of setting up all the other properties |
|
58 | - parent::__construct(); |
|
59 | - } |
|
60 | - |
|
61 | - |
|
62 | - /** |
|
63 | - * see abstract declaration in parent class for details. |
|
64 | - */ |
|
65 | - protected function _set_admin_pages() |
|
66 | - { |
|
67 | - $this->admin_registered_pages = array( |
|
68 | - 'events_edit' => true, |
|
69 | - ); |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * see abstract declaration in parent class for details |
|
75 | - */ |
|
76 | - protected function _set_valid_shortcodes() |
|
77 | - { |
|
78 | - //remember by leaving the other fields not set, those fields will inherit the valid shortcodes from the message type. |
|
79 | - $this->_valid_shortcodes = array( |
|
80 | - 'to' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), |
|
81 | - 'from' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), |
|
82 | - ); |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * see abstract declaration in parent class for details |
|
88 | - * |
|
89 | - * @access protected |
|
90 | - * @return void |
|
91 | - */ |
|
92 | - protected function _set_validator_config() |
|
93 | - { |
|
94 | - $valid_shortcodes = $this->get_valid_shortcodes(); |
|
95 | - |
|
96 | - $this->_validator_config = array( |
|
97 | - 'to' => array( |
|
98 | - 'shortcodes' => $valid_shortcodes['to'], |
|
99 | - 'type' => 'email', |
|
100 | - ), |
|
101 | - 'from' => array( |
|
102 | - 'shortcodes' => $valid_shortcodes['from'], |
|
103 | - 'type' => 'email', |
|
104 | - ), |
|
105 | - 'subject' => array( |
|
106 | - 'shortcodes' => array( |
|
107 | - 'organization', |
|
108 | - 'primary_registration_details', |
|
109 | - 'event_author', |
|
110 | - 'primary_registration_details', |
|
111 | - 'recipient_details', |
|
112 | - ), |
|
113 | - ), |
|
114 | - 'content' => array( |
|
115 | - 'shortcodes' => array( |
|
116 | - 'event_list', |
|
117 | - 'attendee_list', |
|
118 | - 'ticket_list', |
|
119 | - 'organization', |
|
120 | - 'primary_registration_details', |
|
121 | - 'primary_registration_list', |
|
122 | - 'event_author', |
|
123 | - 'recipient_details', |
|
124 | - 'recipient_list', |
|
125 | - 'transaction', |
|
126 | - 'messenger', |
|
127 | - ), |
|
128 | - ), |
|
129 | - 'attendee_list' => array( |
|
130 | - 'shortcodes' => array('attendee', 'event_list', 'ticket_list'), |
|
131 | - 'required' => array('[ATTENDEE_LIST]'), |
|
132 | - ), |
|
133 | - 'event_list' => array( |
|
134 | - 'shortcodes' => array( |
|
135 | - 'event', |
|
136 | - 'attendee_list', |
|
137 | - 'ticket_list', |
|
138 | - 'venue', |
|
139 | - 'datetime_list', |
|
140 | - 'attendee', |
|
141 | - 'primary_registration_details', |
|
142 | - 'primary_registration_list', |
|
143 | - 'event_author', |
|
144 | - 'recipient_details', |
|
145 | - 'recipient_list', |
|
146 | - ), |
|
147 | - 'required' => array('[EVENT_LIST]'), |
|
148 | - ), |
|
149 | - 'ticket_list' => array( |
|
150 | - 'shortcodes' => array( |
|
151 | - 'event_list', |
|
152 | - 'attendee_list', |
|
153 | - 'ticket', |
|
154 | - 'datetime_list', |
|
155 | - 'primary_registration_details', |
|
156 | - 'recipient_details', |
|
157 | - ), |
|
158 | - 'required' => array('[TICKET_LIST]'), |
|
159 | - ), |
|
160 | - 'datetime_list' => array( |
|
161 | - 'shortcodes' => array('datetime'), |
|
162 | - 'required' => array('[DATETIME_LIST]'), |
|
163 | - ), |
|
164 | - ); |
|
165 | - } |
|
166 | - |
|
167 | - |
|
168 | - /** |
|
169 | - * @see parent EE_messenger class for docs |
|
170 | - * @since 4.5.0 |
|
171 | - */ |
|
172 | - public function do_secondary_messenger_hooks($sending_messenger_name) |
|
173 | - { |
|
174 | - if ($sending_messenger_name = 'html') { |
|
175 | - add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8); |
|
176 | - } |
|
177 | - } |
|
178 | - |
|
179 | - |
|
180 | - public function add_email_css( |
|
181 | - $variation_path, |
|
182 | - $messenger, |
|
183 | - $message_type, |
|
184 | - $type, |
|
185 | - $variation, |
|
186 | - $file_extension, |
|
187 | - $url, |
|
188 | - EE_Messages_Template_Pack $template_pack |
|
189 | - ) { |
|
190 | - //prevent recursion on this callback. |
|
191 | - remove_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10); |
|
192 | - $variation = $this->get_variation($template_pack, $message_type, $url, 'main', $variation, false); |
|
193 | - |
|
194 | - add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8); |
|
195 | - return $variation; |
|
196 | - } |
|
197 | - |
|
198 | - |
|
199 | - /** |
|
200 | - * See parent for details |
|
201 | - * |
|
202 | - * @access protected |
|
203 | - * @return void |
|
204 | - */ |
|
205 | - protected function _set_test_settings_fields() |
|
206 | - { |
|
207 | - $this->_test_settings_fields = array( |
|
208 | - 'to' => array( |
|
209 | - 'input' => 'text', |
|
210 | - 'label' => __('Send a test email to', 'event_espresso'), |
|
211 | - 'type' => 'email', |
|
212 | - 'required' => true, |
|
213 | - 'validation' => true, |
|
214 | - 'css_class' => 'large-text', |
|
215 | - 'format' => '%s', |
|
216 | - 'default' => get_bloginfo('admin_email'), |
|
217 | - ), |
|
218 | - 'subject' => array( |
|
219 | - 'input' => 'hidden', |
|
220 | - 'label' => '', |
|
221 | - 'type' => 'string', |
|
222 | - 'required' => false, |
|
223 | - 'validation' => false, |
|
224 | - 'format' => '%s', |
|
225 | - 'value' => sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')), |
|
226 | - 'default' => '', |
|
227 | - 'css_class' => '', |
|
228 | - ), |
|
229 | - ); |
|
230 | - } |
|
231 | - |
|
232 | - |
|
233 | - /** |
|
234 | - * _set_template_fields |
|
235 | - * This sets up the fields that a messenger requires for the message to go out. |
|
236 | - * |
|
237 | - * @access protected |
|
238 | - * @return void |
|
239 | - */ |
|
240 | - protected function _set_template_fields() |
|
241 | - { |
|
242 | - // any extra template fields that are NOT used by the messenger but will get used by a messenger field for shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field they relate to. This is important for the Messages_admin to know what fields to display to the user. Also, notice that the "values" are equal to the field type that messages admin will use to know what kind of field to display. The values ALSO have one index labeled "shortcode". the values in that array indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be displayed. If the required shortcode isn't part of the shortcodes array then the field is not needed and will not be displayed/parsed. |
|
243 | - $this->_template_fields = array( |
|
244 | - 'to' => array( |
|
245 | - 'input' => 'text', |
|
246 | - 'label' => __('To', 'event_espresso'), |
|
247 | - 'type' => 'string', |
|
248 | - 'required' => true, |
|
249 | - 'validation' => true, |
|
250 | - 'css_class' => 'large-text', |
|
251 | - 'format' => '%s', |
|
252 | - ), |
|
253 | - 'from' => array( |
|
254 | - 'input' => 'text', |
|
255 | - 'label' => __('From', 'event_espresso'), |
|
256 | - 'type' => 'string', |
|
257 | - 'required' => true, |
|
258 | - 'validation' => true, |
|
259 | - 'css_class' => 'large-text', |
|
260 | - 'format' => '%s', |
|
261 | - ), |
|
262 | - 'subject' => array( |
|
263 | - 'input' => 'text', |
|
264 | - 'label' => __('Subject', 'event_espresso'), |
|
265 | - 'type' => 'string', |
|
266 | - 'required' => true, |
|
267 | - 'validation' => true, |
|
268 | - 'css_class' => 'large-text', |
|
269 | - 'format' => '%s', |
|
270 | - ), |
|
271 | - 'content' => '', |
|
272 | - //left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field. |
|
273 | - 'extra' => array( |
|
274 | - 'content' => array( |
|
275 | - 'main' => array( |
|
276 | - 'input' => 'wp_editor', |
|
277 | - 'label' => __('Main Content', 'event_espresso'), |
|
278 | - 'type' => 'string', |
|
279 | - 'required' => true, |
|
280 | - 'validation' => true, |
|
281 | - 'format' => '%s', |
|
282 | - 'rows' => '15', |
|
283 | - ), |
|
284 | - 'event_list' => array( |
|
285 | - 'input' => 'wp_editor', |
|
286 | - 'label' => '[EVENT_LIST]', |
|
287 | - 'type' => 'string', |
|
288 | - 'required' => true, |
|
289 | - 'validation' => true, |
|
290 | - 'format' => '%s', |
|
291 | - 'rows' => '15', |
|
292 | - 'shortcodes_required' => array('[EVENT_LIST]'), |
|
293 | - ), |
|
294 | - 'attendee_list' => array( |
|
295 | - 'input' => 'textarea', |
|
296 | - 'label' => '[ATTENDEE_LIST]', |
|
297 | - 'type' => 'string', |
|
298 | - 'required' => true, |
|
299 | - 'validation' => true, |
|
300 | - 'format' => '%s', |
|
301 | - 'css_class' => 'large-text', |
|
302 | - 'rows' => '5', |
|
303 | - 'shortcodes_required' => array('[ATTENDEE_LIST]'), |
|
304 | - ), |
|
305 | - 'ticket_list' => array( |
|
306 | - 'input' => 'textarea', |
|
307 | - 'label' => '[TICKET_LIST]', |
|
308 | - 'type' => 'string', |
|
309 | - 'required' => true, |
|
310 | - 'validation' => true, |
|
311 | - 'format' => '%s', |
|
312 | - 'css_class' => 'large-text', |
|
313 | - 'rows' => '10', |
|
314 | - 'shortcodes_required' => array('[TICKET_LIST]'), |
|
315 | - ), |
|
316 | - 'datetime_list' => array( |
|
317 | - 'input' => 'textarea', |
|
318 | - 'label' => '[DATETIME_LIST]', |
|
319 | - 'type' => 'string', |
|
320 | - 'required' => true, |
|
321 | - 'validation' => true, |
|
322 | - 'format' => '%s', |
|
323 | - 'css_class' => 'large-text', |
|
324 | - 'rows' => '10', |
|
325 | - 'shortcodes_required' => array('[DATETIME_LIST]'), |
|
326 | - ), |
|
327 | - ), |
|
328 | - ), |
|
329 | - ); |
|
330 | - } |
|
331 | - |
|
332 | - |
|
333 | - /** |
|
334 | - * See definition of this class in parent |
|
335 | - */ |
|
336 | - protected function _set_default_message_types() |
|
337 | - { |
|
338 | - $this->_default_message_types = array( |
|
339 | - 'payment', |
|
340 | - 'payment_refund', |
|
341 | - 'registration', |
|
342 | - 'not_approved_registration', |
|
343 | - 'pending_approval', |
|
344 | - ); |
|
345 | - } |
|
346 | - |
|
347 | - |
|
348 | - /** |
|
349 | - * @see definition of this class in parent |
|
350 | - * @since 4.5.0 |
|
351 | - */ |
|
352 | - protected function _set_valid_message_types() |
|
353 | - { |
|
354 | - $this->_valid_message_types = array( |
|
355 | - 'payment', |
|
356 | - 'registration', |
|
357 | - 'not_approved_registration', |
|
358 | - 'declined_registration', |
|
359 | - 'cancelled_registration', |
|
360 | - 'pending_approval', |
|
361 | - 'registration_summary', |
|
362 | - 'payment_reminder', |
|
363 | - 'payment_declined', |
|
364 | - 'payment_refund', |
|
365 | - ); |
|
366 | - } |
|
367 | - |
|
368 | - |
|
369 | - /** |
|
370 | - * setting up admin_settings_fields for messenger. |
|
371 | - */ |
|
372 | - protected function _set_admin_settings_fields() |
|
373 | - { |
|
374 | - } |
|
375 | - |
|
376 | - /** |
|
377 | - * We just deliver the messages don't kill us!! |
|
378 | - * |
|
379 | - * @return bool | WP_Error true if message delivered, false if it didn't deliver OR bubble up any error object if |
|
380 | - * present. |
|
381 | - */ |
|
382 | - protected function _send_message() |
|
383 | - { |
|
384 | - $success = wp_mail( |
|
385 | - html_entity_decode($this->_to, ENT_QUOTES, "UTF-8"), |
|
386 | - stripslashes(html_entity_decode($this->_subject, ENT_QUOTES, "UTF-8")), |
|
387 | - $this->_body(), |
|
388 | - $this->_headers() |
|
389 | - ); |
|
390 | - if (! $success) { |
|
391 | - EE_Error::add_error( |
|
392 | - sprintf( |
|
393 | - __('The email did not send successfully.%3$sThe WordPress wp_mail function is used for sending mails but does not give any useful information when an email fails to send.%3$sIt is possible the "to" address (%1$s) or "from" address (%2$s) is invalid.%3$s', |
|
394 | - 'event_espresso'), |
|
395 | - $this->_to, |
|
396 | - $this->_from, |
|
397 | - '<br />' |
|
398 | - ), |
|
399 | - __FILE__, __FUNCTION__, __LINE__ |
|
400 | - ); |
|
401 | - } |
|
402 | - return $success; |
|
403 | - } |
|
404 | - |
|
405 | - |
|
406 | - /** |
|
407 | - * see parent for definition |
|
408 | - * |
|
409 | - * @return string html body of the message content and the related css. |
|
410 | - */ |
|
411 | - protected function _preview() |
|
412 | - { |
|
413 | - return $this->_body(true); |
|
414 | - } |
|
415 | - |
|
416 | - |
|
417 | - /** |
|
418 | - * Setup headers for email |
|
419 | - * |
|
420 | - * @access protected |
|
421 | - * @return string formatted header for email |
|
422 | - */ |
|
423 | - protected function _headers() |
|
424 | - { |
|
425 | - $this->_ensure_has_from_email_address(); |
|
426 | - $from = stripslashes_deep(html_entity_decode($this->_from, ENT_QUOTES, "UTF-8")); |
|
427 | - $headers = array( |
|
428 | - 'MIME-Version: 1.0', |
|
429 | - 'From:' . $from, |
|
430 | - 'Reply-To:' . $from, |
|
431 | - 'Content-Type:text/html; charset=utf-8', |
|
432 | - ); |
|
433 | - |
|
434 | - //but wait! Header's for the from is NOT reliable because some plugins don't respect From: as set in the header. |
|
435 | - add_filter('wp_mail_from', array($this, 'set_from_address'), 100); |
|
436 | - add_filter('wp_mail_from_name', array($this, 'set_from_name'), 100); |
|
437 | - return apply_filters('FHEE__EE_Email_messenger___headers', $headers, $this->_incoming_message_type, $this); |
|
438 | - } |
|
439 | - |
|
440 | - |
|
441 | - /** |
|
442 | - * This simply ensures that the from address is not empty. If it is, then we use whatever is set as the site email |
|
443 | - * address for the from address to avoid problems with sending emails. |
|
444 | - */ |
|
445 | - protected function _ensure_has_from_email_address() |
|
446 | - { |
|
447 | - if (empty($this->_from)) { |
|
448 | - $this->_from = get_bloginfo('admin_email'); |
|
449 | - } |
|
450 | - } |
|
451 | - |
|
452 | - |
|
453 | - /** |
|
454 | - * This simply parses whatever is set as the $_from address and determines if it is in the format {name} <{email}> |
|
455 | - * or just {email} and returns an array with the "from_name" and "from_email" as the values. Note from_name *MAY* |
|
456 | - * be empty |
|
457 | - * |
|
458 | - * @since 4.3.1 |
|
459 | - * @return array |
|
460 | - */ |
|
461 | - private function _parse_from() |
|
462 | - { |
|
463 | - if (strpos($this->_from, '<') !== false) { |
|
464 | - $from_name = substr($this->_from, 0, strpos($this->_from, '<') - 1); |
|
465 | - $from_name = str_replace('"', '', $from_name); |
|
466 | - $from_name = trim($from_name); |
|
467 | - |
|
468 | - $from_email = substr($this->_from, strpos($this->_from, '<') + 1); |
|
469 | - $from_email = str_replace('>', '', $from_email); |
|
470 | - $from_email = trim($from_email); |
|
471 | - } elseif (trim($this->_from) !== '') { |
|
472 | - $from_name = ''; |
|
473 | - $from_email = trim($this->_from); |
|
474 | - } else { |
|
475 | - $from_name = $from_email = ''; |
|
476 | - } |
|
477 | - return array($from_name, $from_email); |
|
478 | - } |
|
479 | - |
|
480 | - |
|
481 | - /** |
|
482 | - * Callback for the wp_mail_from filter. |
|
483 | - * |
|
484 | - * @since 4.3.1 |
|
485 | - * @param string $from_email What the original from_email is. |
|
486 | - */ |
|
487 | - public function set_from_address($from_email) |
|
488 | - { |
|
489 | - $parsed_from = $this->_parse_from(); |
|
490 | - //includes fallback if the parsing failed. |
|
491 | - $from_email = is_array($parsed_from) && ! empty($parsed_from[1]) ? $parsed_from[1] : get_bloginfo('admin_email'); |
|
492 | - return $from_email; |
|
493 | - } |
|
494 | - |
|
495 | - |
|
496 | - /** |
|
497 | - * Callback fro the wp_mail_from_name filter. |
|
498 | - * |
|
499 | - * @since 4.3.1 |
|
500 | - * @param string $from_name The original from_name. |
|
501 | - */ |
|
502 | - public function set_from_name($from_name) |
|
503 | - { |
|
504 | - $parsed_from = $this->_parse_from(); |
|
505 | - if (is_array($parsed_from) && ! empty($parsed_from[0])) { |
|
506 | - $from_name = $parsed_from[0]; |
|
507 | - } |
|
508 | - |
|
509 | - //if from name is "WordPress" let's sub in the site name instead (more friendly!) |
|
510 | - $from_name = $from_name == 'WordPress' ? get_bloginfo() : $from_name; |
|
511 | - |
|
512 | - return stripslashes_deep(html_entity_decode($from_name, ENT_QUOTES, "UTF-8")); |
|
513 | - } |
|
514 | - |
|
515 | - |
|
516 | - /** |
|
517 | - * setup body for email |
|
518 | - * |
|
519 | - * @param bool $preview will determine whether this is preview template or not. |
|
520 | - * @return string formatted body for email. |
|
521 | - */ |
|
522 | - protected function _body($preview = false) |
|
523 | - { |
|
524 | - //setup template args! |
|
525 | - $this->_template_args = array( |
|
526 | - 'subject' => $this->_subject, |
|
527 | - 'from' => $this->_from, |
|
528 | - 'main_body' => wpautop(stripslashes_deep(html_entity_decode($this->_content, ENT_QUOTES, "UTF-8"))), |
|
529 | - ); |
|
530 | - $body = $this->_get_main_template($preview); |
|
531 | - |
|
532 | - /** |
|
533 | - * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched. |
|
534 | - * |
|
535 | - * @type bool $preview Indicates whether a preview is being generated or not. |
|
536 | - * @return bool true indicates to use the inliner, false bypasses it. |
|
537 | - */ |
|
538 | - if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) { |
|
539 | - |
|
540 | - //require CssToInlineStyles library and its dependencies via composer autoloader |
|
541 | - require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php'; |
|
542 | - |
|
543 | - //now if this isn't a preview, let's setup the body so it has inline styles |
|
544 | - if (! $preview || ($preview && defined('DOING_AJAX'))) { |
|
545 | - $style = file_get_contents($this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, |
|
546 | - false, 'main', $this->_variation), true); |
|
547 | - $CSS = new TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($body, $style); |
|
548 | - $body = ltrim($CSS->convert(true), |
|
549 | - ">\n"); //for some reason the library has a bracket and new line at the beginning. This takes care of that. |
|
550 | - $body = ltrim($body, "<?"); //see https://events.codebasehq.com/projects/event-espresso/tickets/8609 |
|
551 | - } |
|
552 | - |
|
553 | - } |
|
554 | - return $body; |
|
555 | - } |
|
556 | - |
|
557 | - |
|
558 | - /** |
|
559 | - * This just returns any existing test settings that might be saved in the database |
|
560 | - * |
|
561 | - * @access public |
|
562 | - * @return array |
|
563 | - */ |
|
564 | - public function get_existing_test_settings() |
|
565 | - { |
|
566 | - $settings = parent::get_existing_test_settings(); |
|
567 | - //override subject if present because we always want it to be fresh. |
|
568 | - if (is_array($settings) && ! empty($settings['subject'])) { |
|
569 | - $settings['subject'] = sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')); |
|
570 | - } |
|
571 | - return $settings; |
|
572 | - } |
|
31 | + /** |
|
32 | + * The following are the properties that email requires for the message going out. |
|
33 | + */ |
|
34 | + protected $_to; |
|
35 | + protected $_from; |
|
36 | + protected $_subject; |
|
37 | + protected $_content; |
|
38 | + |
|
39 | + |
|
40 | + /** |
|
41 | + * constructor |
|
42 | + * |
|
43 | + * @access public |
|
44 | + */ |
|
45 | + public function __construct() |
|
46 | + { |
|
47 | + //set name and description properties |
|
48 | + $this->name = 'email'; |
|
49 | + $this->description = __('This messenger delivers messages via email using the built-in <code>wp_mail</code> function included with WordPress', |
|
50 | + 'event_espresso'); |
|
51 | + $this->label = array( |
|
52 | + 'singular' => __('email', 'event_espresso'), |
|
53 | + 'plural' => __('emails', 'event_espresso'), |
|
54 | + ); |
|
55 | + $this->activate_on_install = true; |
|
56 | + |
|
57 | + //we're using defaults so let's call parent constructor that will take care of setting up all the other properties |
|
58 | + parent::__construct(); |
|
59 | + } |
|
60 | + |
|
61 | + |
|
62 | + /** |
|
63 | + * see abstract declaration in parent class for details. |
|
64 | + */ |
|
65 | + protected function _set_admin_pages() |
|
66 | + { |
|
67 | + $this->admin_registered_pages = array( |
|
68 | + 'events_edit' => true, |
|
69 | + ); |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * see abstract declaration in parent class for details |
|
75 | + */ |
|
76 | + protected function _set_valid_shortcodes() |
|
77 | + { |
|
78 | + //remember by leaving the other fields not set, those fields will inherit the valid shortcodes from the message type. |
|
79 | + $this->_valid_shortcodes = array( |
|
80 | + 'to' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), |
|
81 | + 'from' => array('email', 'event_author', 'primary_registration_details', 'recipient_details'), |
|
82 | + ); |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * see abstract declaration in parent class for details |
|
88 | + * |
|
89 | + * @access protected |
|
90 | + * @return void |
|
91 | + */ |
|
92 | + protected function _set_validator_config() |
|
93 | + { |
|
94 | + $valid_shortcodes = $this->get_valid_shortcodes(); |
|
95 | + |
|
96 | + $this->_validator_config = array( |
|
97 | + 'to' => array( |
|
98 | + 'shortcodes' => $valid_shortcodes['to'], |
|
99 | + 'type' => 'email', |
|
100 | + ), |
|
101 | + 'from' => array( |
|
102 | + 'shortcodes' => $valid_shortcodes['from'], |
|
103 | + 'type' => 'email', |
|
104 | + ), |
|
105 | + 'subject' => array( |
|
106 | + 'shortcodes' => array( |
|
107 | + 'organization', |
|
108 | + 'primary_registration_details', |
|
109 | + 'event_author', |
|
110 | + 'primary_registration_details', |
|
111 | + 'recipient_details', |
|
112 | + ), |
|
113 | + ), |
|
114 | + 'content' => array( |
|
115 | + 'shortcodes' => array( |
|
116 | + 'event_list', |
|
117 | + 'attendee_list', |
|
118 | + 'ticket_list', |
|
119 | + 'organization', |
|
120 | + 'primary_registration_details', |
|
121 | + 'primary_registration_list', |
|
122 | + 'event_author', |
|
123 | + 'recipient_details', |
|
124 | + 'recipient_list', |
|
125 | + 'transaction', |
|
126 | + 'messenger', |
|
127 | + ), |
|
128 | + ), |
|
129 | + 'attendee_list' => array( |
|
130 | + 'shortcodes' => array('attendee', 'event_list', 'ticket_list'), |
|
131 | + 'required' => array('[ATTENDEE_LIST]'), |
|
132 | + ), |
|
133 | + 'event_list' => array( |
|
134 | + 'shortcodes' => array( |
|
135 | + 'event', |
|
136 | + 'attendee_list', |
|
137 | + 'ticket_list', |
|
138 | + 'venue', |
|
139 | + 'datetime_list', |
|
140 | + 'attendee', |
|
141 | + 'primary_registration_details', |
|
142 | + 'primary_registration_list', |
|
143 | + 'event_author', |
|
144 | + 'recipient_details', |
|
145 | + 'recipient_list', |
|
146 | + ), |
|
147 | + 'required' => array('[EVENT_LIST]'), |
|
148 | + ), |
|
149 | + 'ticket_list' => array( |
|
150 | + 'shortcodes' => array( |
|
151 | + 'event_list', |
|
152 | + 'attendee_list', |
|
153 | + 'ticket', |
|
154 | + 'datetime_list', |
|
155 | + 'primary_registration_details', |
|
156 | + 'recipient_details', |
|
157 | + ), |
|
158 | + 'required' => array('[TICKET_LIST]'), |
|
159 | + ), |
|
160 | + 'datetime_list' => array( |
|
161 | + 'shortcodes' => array('datetime'), |
|
162 | + 'required' => array('[DATETIME_LIST]'), |
|
163 | + ), |
|
164 | + ); |
|
165 | + } |
|
166 | + |
|
167 | + |
|
168 | + /** |
|
169 | + * @see parent EE_messenger class for docs |
|
170 | + * @since 4.5.0 |
|
171 | + */ |
|
172 | + public function do_secondary_messenger_hooks($sending_messenger_name) |
|
173 | + { |
|
174 | + if ($sending_messenger_name = 'html') { |
|
175 | + add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8); |
|
176 | + } |
|
177 | + } |
|
178 | + |
|
179 | + |
|
180 | + public function add_email_css( |
|
181 | + $variation_path, |
|
182 | + $messenger, |
|
183 | + $message_type, |
|
184 | + $type, |
|
185 | + $variation, |
|
186 | + $file_extension, |
|
187 | + $url, |
|
188 | + EE_Messages_Template_Pack $template_pack |
|
189 | + ) { |
|
190 | + //prevent recursion on this callback. |
|
191 | + remove_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10); |
|
192 | + $variation = $this->get_variation($template_pack, $message_type, $url, 'main', $variation, false); |
|
193 | + |
|
194 | + add_filter('FHEE__EE_Messages_Template_Pack__get_variation', array($this, 'add_email_css'), 10, 8); |
|
195 | + return $variation; |
|
196 | + } |
|
197 | + |
|
198 | + |
|
199 | + /** |
|
200 | + * See parent for details |
|
201 | + * |
|
202 | + * @access protected |
|
203 | + * @return void |
|
204 | + */ |
|
205 | + protected function _set_test_settings_fields() |
|
206 | + { |
|
207 | + $this->_test_settings_fields = array( |
|
208 | + 'to' => array( |
|
209 | + 'input' => 'text', |
|
210 | + 'label' => __('Send a test email to', 'event_espresso'), |
|
211 | + 'type' => 'email', |
|
212 | + 'required' => true, |
|
213 | + 'validation' => true, |
|
214 | + 'css_class' => 'large-text', |
|
215 | + 'format' => '%s', |
|
216 | + 'default' => get_bloginfo('admin_email'), |
|
217 | + ), |
|
218 | + 'subject' => array( |
|
219 | + 'input' => 'hidden', |
|
220 | + 'label' => '', |
|
221 | + 'type' => 'string', |
|
222 | + 'required' => false, |
|
223 | + 'validation' => false, |
|
224 | + 'format' => '%s', |
|
225 | + 'value' => sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')), |
|
226 | + 'default' => '', |
|
227 | + 'css_class' => '', |
|
228 | + ), |
|
229 | + ); |
|
230 | + } |
|
231 | + |
|
232 | + |
|
233 | + /** |
|
234 | + * _set_template_fields |
|
235 | + * This sets up the fields that a messenger requires for the message to go out. |
|
236 | + * |
|
237 | + * @access protected |
|
238 | + * @return void |
|
239 | + */ |
|
240 | + protected function _set_template_fields() |
|
241 | + { |
|
242 | + // any extra template fields that are NOT used by the messenger but will get used by a messenger field for shortcode replacement get added to the 'extra' key in an associated array indexed by the messenger field they relate to. This is important for the Messages_admin to know what fields to display to the user. Also, notice that the "values" are equal to the field type that messages admin will use to know what kind of field to display. The values ALSO have one index labeled "shortcode". the values in that array indicate which ACTUAL SHORTCODE (i.e. [SHORTCODE]) is required in order for this extra field to be displayed. If the required shortcode isn't part of the shortcodes array then the field is not needed and will not be displayed/parsed. |
|
243 | + $this->_template_fields = array( |
|
244 | + 'to' => array( |
|
245 | + 'input' => 'text', |
|
246 | + 'label' => __('To', 'event_espresso'), |
|
247 | + 'type' => 'string', |
|
248 | + 'required' => true, |
|
249 | + 'validation' => true, |
|
250 | + 'css_class' => 'large-text', |
|
251 | + 'format' => '%s', |
|
252 | + ), |
|
253 | + 'from' => array( |
|
254 | + 'input' => 'text', |
|
255 | + 'label' => __('From', 'event_espresso'), |
|
256 | + 'type' => 'string', |
|
257 | + 'required' => true, |
|
258 | + 'validation' => true, |
|
259 | + 'css_class' => 'large-text', |
|
260 | + 'format' => '%s', |
|
261 | + ), |
|
262 | + 'subject' => array( |
|
263 | + 'input' => 'text', |
|
264 | + 'label' => __('Subject', 'event_espresso'), |
|
265 | + 'type' => 'string', |
|
266 | + 'required' => true, |
|
267 | + 'validation' => true, |
|
268 | + 'css_class' => 'large-text', |
|
269 | + 'format' => '%s', |
|
270 | + ), |
|
271 | + 'content' => '', |
|
272 | + //left empty b/c it is in the "extra array" but messenger still needs needs to know this is a field. |
|
273 | + 'extra' => array( |
|
274 | + 'content' => array( |
|
275 | + 'main' => array( |
|
276 | + 'input' => 'wp_editor', |
|
277 | + 'label' => __('Main Content', 'event_espresso'), |
|
278 | + 'type' => 'string', |
|
279 | + 'required' => true, |
|
280 | + 'validation' => true, |
|
281 | + 'format' => '%s', |
|
282 | + 'rows' => '15', |
|
283 | + ), |
|
284 | + 'event_list' => array( |
|
285 | + 'input' => 'wp_editor', |
|
286 | + 'label' => '[EVENT_LIST]', |
|
287 | + 'type' => 'string', |
|
288 | + 'required' => true, |
|
289 | + 'validation' => true, |
|
290 | + 'format' => '%s', |
|
291 | + 'rows' => '15', |
|
292 | + 'shortcodes_required' => array('[EVENT_LIST]'), |
|
293 | + ), |
|
294 | + 'attendee_list' => array( |
|
295 | + 'input' => 'textarea', |
|
296 | + 'label' => '[ATTENDEE_LIST]', |
|
297 | + 'type' => 'string', |
|
298 | + 'required' => true, |
|
299 | + 'validation' => true, |
|
300 | + 'format' => '%s', |
|
301 | + 'css_class' => 'large-text', |
|
302 | + 'rows' => '5', |
|
303 | + 'shortcodes_required' => array('[ATTENDEE_LIST]'), |
|
304 | + ), |
|
305 | + 'ticket_list' => array( |
|
306 | + 'input' => 'textarea', |
|
307 | + 'label' => '[TICKET_LIST]', |
|
308 | + 'type' => 'string', |
|
309 | + 'required' => true, |
|
310 | + 'validation' => true, |
|
311 | + 'format' => '%s', |
|
312 | + 'css_class' => 'large-text', |
|
313 | + 'rows' => '10', |
|
314 | + 'shortcodes_required' => array('[TICKET_LIST]'), |
|
315 | + ), |
|
316 | + 'datetime_list' => array( |
|
317 | + 'input' => 'textarea', |
|
318 | + 'label' => '[DATETIME_LIST]', |
|
319 | + 'type' => 'string', |
|
320 | + 'required' => true, |
|
321 | + 'validation' => true, |
|
322 | + 'format' => '%s', |
|
323 | + 'css_class' => 'large-text', |
|
324 | + 'rows' => '10', |
|
325 | + 'shortcodes_required' => array('[DATETIME_LIST]'), |
|
326 | + ), |
|
327 | + ), |
|
328 | + ), |
|
329 | + ); |
|
330 | + } |
|
331 | + |
|
332 | + |
|
333 | + /** |
|
334 | + * See definition of this class in parent |
|
335 | + */ |
|
336 | + protected function _set_default_message_types() |
|
337 | + { |
|
338 | + $this->_default_message_types = array( |
|
339 | + 'payment', |
|
340 | + 'payment_refund', |
|
341 | + 'registration', |
|
342 | + 'not_approved_registration', |
|
343 | + 'pending_approval', |
|
344 | + ); |
|
345 | + } |
|
346 | + |
|
347 | + |
|
348 | + /** |
|
349 | + * @see definition of this class in parent |
|
350 | + * @since 4.5.0 |
|
351 | + */ |
|
352 | + protected function _set_valid_message_types() |
|
353 | + { |
|
354 | + $this->_valid_message_types = array( |
|
355 | + 'payment', |
|
356 | + 'registration', |
|
357 | + 'not_approved_registration', |
|
358 | + 'declined_registration', |
|
359 | + 'cancelled_registration', |
|
360 | + 'pending_approval', |
|
361 | + 'registration_summary', |
|
362 | + 'payment_reminder', |
|
363 | + 'payment_declined', |
|
364 | + 'payment_refund', |
|
365 | + ); |
|
366 | + } |
|
367 | + |
|
368 | + |
|
369 | + /** |
|
370 | + * setting up admin_settings_fields for messenger. |
|
371 | + */ |
|
372 | + protected function _set_admin_settings_fields() |
|
373 | + { |
|
374 | + } |
|
375 | + |
|
376 | + /** |
|
377 | + * We just deliver the messages don't kill us!! |
|
378 | + * |
|
379 | + * @return bool | WP_Error true if message delivered, false if it didn't deliver OR bubble up any error object if |
|
380 | + * present. |
|
381 | + */ |
|
382 | + protected function _send_message() |
|
383 | + { |
|
384 | + $success = wp_mail( |
|
385 | + html_entity_decode($this->_to, ENT_QUOTES, "UTF-8"), |
|
386 | + stripslashes(html_entity_decode($this->_subject, ENT_QUOTES, "UTF-8")), |
|
387 | + $this->_body(), |
|
388 | + $this->_headers() |
|
389 | + ); |
|
390 | + if (! $success) { |
|
391 | + EE_Error::add_error( |
|
392 | + sprintf( |
|
393 | + __('The email did not send successfully.%3$sThe WordPress wp_mail function is used for sending mails but does not give any useful information when an email fails to send.%3$sIt is possible the "to" address (%1$s) or "from" address (%2$s) is invalid.%3$s', |
|
394 | + 'event_espresso'), |
|
395 | + $this->_to, |
|
396 | + $this->_from, |
|
397 | + '<br />' |
|
398 | + ), |
|
399 | + __FILE__, __FUNCTION__, __LINE__ |
|
400 | + ); |
|
401 | + } |
|
402 | + return $success; |
|
403 | + } |
|
404 | + |
|
405 | + |
|
406 | + /** |
|
407 | + * see parent for definition |
|
408 | + * |
|
409 | + * @return string html body of the message content and the related css. |
|
410 | + */ |
|
411 | + protected function _preview() |
|
412 | + { |
|
413 | + return $this->_body(true); |
|
414 | + } |
|
415 | + |
|
416 | + |
|
417 | + /** |
|
418 | + * Setup headers for email |
|
419 | + * |
|
420 | + * @access protected |
|
421 | + * @return string formatted header for email |
|
422 | + */ |
|
423 | + protected function _headers() |
|
424 | + { |
|
425 | + $this->_ensure_has_from_email_address(); |
|
426 | + $from = stripslashes_deep(html_entity_decode($this->_from, ENT_QUOTES, "UTF-8")); |
|
427 | + $headers = array( |
|
428 | + 'MIME-Version: 1.0', |
|
429 | + 'From:' . $from, |
|
430 | + 'Reply-To:' . $from, |
|
431 | + 'Content-Type:text/html; charset=utf-8', |
|
432 | + ); |
|
433 | + |
|
434 | + //but wait! Header's for the from is NOT reliable because some plugins don't respect From: as set in the header. |
|
435 | + add_filter('wp_mail_from', array($this, 'set_from_address'), 100); |
|
436 | + add_filter('wp_mail_from_name', array($this, 'set_from_name'), 100); |
|
437 | + return apply_filters('FHEE__EE_Email_messenger___headers', $headers, $this->_incoming_message_type, $this); |
|
438 | + } |
|
439 | + |
|
440 | + |
|
441 | + /** |
|
442 | + * This simply ensures that the from address is not empty. If it is, then we use whatever is set as the site email |
|
443 | + * address for the from address to avoid problems with sending emails. |
|
444 | + */ |
|
445 | + protected function _ensure_has_from_email_address() |
|
446 | + { |
|
447 | + if (empty($this->_from)) { |
|
448 | + $this->_from = get_bloginfo('admin_email'); |
|
449 | + } |
|
450 | + } |
|
451 | + |
|
452 | + |
|
453 | + /** |
|
454 | + * This simply parses whatever is set as the $_from address and determines if it is in the format {name} <{email}> |
|
455 | + * or just {email} and returns an array with the "from_name" and "from_email" as the values. Note from_name *MAY* |
|
456 | + * be empty |
|
457 | + * |
|
458 | + * @since 4.3.1 |
|
459 | + * @return array |
|
460 | + */ |
|
461 | + private function _parse_from() |
|
462 | + { |
|
463 | + if (strpos($this->_from, '<') !== false) { |
|
464 | + $from_name = substr($this->_from, 0, strpos($this->_from, '<') - 1); |
|
465 | + $from_name = str_replace('"', '', $from_name); |
|
466 | + $from_name = trim($from_name); |
|
467 | + |
|
468 | + $from_email = substr($this->_from, strpos($this->_from, '<') + 1); |
|
469 | + $from_email = str_replace('>', '', $from_email); |
|
470 | + $from_email = trim($from_email); |
|
471 | + } elseif (trim($this->_from) !== '') { |
|
472 | + $from_name = ''; |
|
473 | + $from_email = trim($this->_from); |
|
474 | + } else { |
|
475 | + $from_name = $from_email = ''; |
|
476 | + } |
|
477 | + return array($from_name, $from_email); |
|
478 | + } |
|
479 | + |
|
480 | + |
|
481 | + /** |
|
482 | + * Callback for the wp_mail_from filter. |
|
483 | + * |
|
484 | + * @since 4.3.1 |
|
485 | + * @param string $from_email What the original from_email is. |
|
486 | + */ |
|
487 | + public function set_from_address($from_email) |
|
488 | + { |
|
489 | + $parsed_from = $this->_parse_from(); |
|
490 | + //includes fallback if the parsing failed. |
|
491 | + $from_email = is_array($parsed_from) && ! empty($parsed_from[1]) ? $parsed_from[1] : get_bloginfo('admin_email'); |
|
492 | + return $from_email; |
|
493 | + } |
|
494 | + |
|
495 | + |
|
496 | + /** |
|
497 | + * Callback fro the wp_mail_from_name filter. |
|
498 | + * |
|
499 | + * @since 4.3.1 |
|
500 | + * @param string $from_name The original from_name. |
|
501 | + */ |
|
502 | + public function set_from_name($from_name) |
|
503 | + { |
|
504 | + $parsed_from = $this->_parse_from(); |
|
505 | + if (is_array($parsed_from) && ! empty($parsed_from[0])) { |
|
506 | + $from_name = $parsed_from[0]; |
|
507 | + } |
|
508 | + |
|
509 | + //if from name is "WordPress" let's sub in the site name instead (more friendly!) |
|
510 | + $from_name = $from_name == 'WordPress' ? get_bloginfo() : $from_name; |
|
511 | + |
|
512 | + return stripslashes_deep(html_entity_decode($from_name, ENT_QUOTES, "UTF-8")); |
|
513 | + } |
|
514 | + |
|
515 | + |
|
516 | + /** |
|
517 | + * setup body for email |
|
518 | + * |
|
519 | + * @param bool $preview will determine whether this is preview template or not. |
|
520 | + * @return string formatted body for email. |
|
521 | + */ |
|
522 | + protected function _body($preview = false) |
|
523 | + { |
|
524 | + //setup template args! |
|
525 | + $this->_template_args = array( |
|
526 | + 'subject' => $this->_subject, |
|
527 | + 'from' => $this->_from, |
|
528 | + 'main_body' => wpautop(stripslashes_deep(html_entity_decode($this->_content, ENT_QUOTES, "UTF-8"))), |
|
529 | + ); |
|
530 | + $body = $this->_get_main_template($preview); |
|
531 | + |
|
532 | + /** |
|
533 | + * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched. |
|
534 | + * |
|
535 | + * @type bool $preview Indicates whether a preview is being generated or not. |
|
536 | + * @return bool true indicates to use the inliner, false bypasses it. |
|
537 | + */ |
|
538 | + if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) { |
|
539 | + |
|
540 | + //require CssToInlineStyles library and its dependencies via composer autoloader |
|
541 | + require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php'; |
|
542 | + |
|
543 | + //now if this isn't a preview, let's setup the body so it has inline styles |
|
544 | + if (! $preview || ($preview && defined('DOING_AJAX'))) { |
|
545 | + $style = file_get_contents($this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, |
|
546 | + false, 'main', $this->_variation), true); |
|
547 | + $CSS = new TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($body, $style); |
|
548 | + $body = ltrim($CSS->convert(true), |
|
549 | + ">\n"); //for some reason the library has a bracket and new line at the beginning. This takes care of that. |
|
550 | + $body = ltrim($body, "<?"); //see https://events.codebasehq.com/projects/event-espresso/tickets/8609 |
|
551 | + } |
|
552 | + |
|
553 | + } |
|
554 | + return $body; |
|
555 | + } |
|
556 | + |
|
557 | + |
|
558 | + /** |
|
559 | + * This just returns any existing test settings that might be saved in the database |
|
560 | + * |
|
561 | + * @access public |
|
562 | + * @return array |
|
563 | + */ |
|
564 | + public function get_existing_test_settings() |
|
565 | + { |
|
566 | + $settings = parent::get_existing_test_settings(); |
|
567 | + //override subject if present because we always want it to be fresh. |
|
568 | + if (is_array($settings) && ! empty($settings['subject'])) { |
|
569 | + $settings['subject'] = sprintf(__('Test email sent from %s', 'event_espresso'), get_bloginfo('name')); |
|
570 | + } |
|
571 | + return $settings; |
|
572 | + } |
|
573 | 573 | |
574 | 574 | |
575 | 575 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
4 | 4 | exit('NO direct script access allowed'); |
5 | 5 | } |
6 | 6 | |
@@ -387,7 +387,7 @@ discard block |
||
387 | 387 | $this->_body(), |
388 | 388 | $this->_headers() |
389 | 389 | ); |
390 | - if (! $success) { |
|
390 | + if ( ! $success) { |
|
391 | 391 | EE_Error::add_error( |
392 | 392 | sprintf( |
393 | 393 | __('The email did not send successfully.%3$sThe WordPress wp_mail function is used for sending mails but does not give any useful information when an email fails to send.%3$sIt is possible the "to" address (%1$s) or "from" address (%2$s) is invalid.%3$s', |
@@ -426,8 +426,8 @@ discard block |
||
426 | 426 | $from = stripslashes_deep(html_entity_decode($this->_from, ENT_QUOTES, "UTF-8")); |
427 | 427 | $headers = array( |
428 | 428 | 'MIME-Version: 1.0', |
429 | - 'From:' . $from, |
|
430 | - 'Reply-To:' . $from, |
|
429 | + 'From:'.$from, |
|
430 | + 'Reply-To:'.$from, |
|
431 | 431 | 'Content-Type:text/html; charset=utf-8', |
432 | 432 | ); |
433 | 433 | |
@@ -527,7 +527,7 @@ discard block |
||
527 | 527 | 'from' => $this->_from, |
528 | 528 | 'main_body' => wpautop(stripslashes_deep(html_entity_decode($this->_content, ENT_QUOTES, "UTF-8"))), |
529 | 529 | ); |
530 | - $body = $this->_get_main_template($preview); |
|
530 | + $body = $this->_get_main_template($preview); |
|
531 | 531 | |
532 | 532 | /** |
533 | 533 | * This filter allows one to bypass the CSSToInlineStyles tool and leave the body untouched. |
@@ -538,10 +538,10 @@ discard block |
||
538 | 538 | if (apply_filters('FHEE__EE_Email_messenger__apply_CSSInliner ', true, $preview)) { |
539 | 539 | |
540 | 540 | //require CssToInlineStyles library and its dependencies via composer autoloader |
541 | - require_once EE_THIRD_PARTY . 'cssinliner/vendor/autoload.php'; |
|
541 | + require_once EE_THIRD_PARTY.'cssinliner/vendor/autoload.php'; |
|
542 | 542 | |
543 | 543 | //now if this isn't a preview, let's setup the body so it has inline styles |
544 | - if (! $preview || ($preview && defined('DOING_AJAX'))) { |
|
544 | + if ( ! $preview || ($preview && defined('DOING_AJAX'))) { |
|
545 | 545 | $style = file_get_contents($this->get_variation($this->_tmp_pack, $this->_incoming_message_type->name, |
546 | 546 | false, 'main', $this->_variation), true); |
547 | 547 | $CSS = new TijsVerkoyen\CssToInlineStyles\CssToInlineStyles($body, $style); |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | use EventEspresso\core\services\loaders\LoaderFactory; |
5 | 5 | |
6 | 6 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
7 | - exit('No direct script access allowed'); |
|
7 | + exit('No direct script access allowed'); |
|
8 | 8 | } |
9 | 9 | |
10 | 10 | |
@@ -24,222 +24,222 @@ discard block |
||
24 | 24 | class EE_Load_Espresso_Core implements EEI_Request_Decorator, EEI_Request_Stack_Core_App |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * @var EE_Request $request |
|
29 | - */ |
|
30 | - protected $request; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var EE_Response $response |
|
34 | - */ |
|
35 | - protected $response; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var EE_Dependency_Map $dependency_map |
|
39 | - */ |
|
40 | - protected $dependency_map; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var EE_Registry $registry |
|
44 | - */ |
|
45 | - protected $registry; |
|
46 | - |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * EE_Load_Espresso_Core constructor |
|
51 | - */ |
|
52 | - public function __construct() |
|
53 | - { |
|
54 | - espresso_load_required('EventEspresso\core\Factory', EE_CORE . 'Factory.php'); |
|
55 | - } |
|
56 | - |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * handle |
|
61 | - * sets hooks for running rest of system |
|
62 | - * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
63 | - * starting EE Addons from any other point may lead to problems |
|
64 | - * |
|
65 | - * @param EE_Request $request |
|
66 | - * @param EE_Response $response |
|
67 | - * @return EE_Response |
|
68 | - * @throws EE_Error |
|
69 | - * @throws InvalidDataTypeException |
|
70 | - * @throws InvalidInterfaceException |
|
71 | - * @throws InvalidArgumentException |
|
72 | - */ |
|
73 | - public function handle_request(EE_Request $request, EE_Response $response) |
|
74 | - { |
|
75 | - $this->request = $request; |
|
76 | - $this->response = $response; |
|
77 | - // info about how to load classes required by other classes |
|
78 | - $this->dependency_map = $this->_load_dependency_map(); |
|
79 | - // central repository for classes |
|
80 | - $this->registry = $this->_load_registry(); |
|
81 | - // PSR4 Autoloaders |
|
82 | - $this->registry->load_core('EE_Psr4AutoloaderInit'); |
|
83 | - do_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading'); |
|
84 | - $loader = LoaderFactory::getLoader($this->registry); |
|
85 | - $this->dependency_map->setLoader($loader); |
|
86 | - // build DI container |
|
87 | - // $OpenCoffeeShop = new EventEspresso\core\services\container\OpenCoffeeShop(); |
|
88 | - // $OpenCoffeeShop->addRecipes(); |
|
89 | - // $CoffeeShop = $OpenCoffeeShop->CoffeeShop(); |
|
90 | - // create and cache the CommandBus, and also add middleware |
|
91 | - $loader->getShared( |
|
92 | - 'CommandBusInterface', |
|
93 | - array( |
|
94 | - null, |
|
95 | - apply_filters( |
|
96 | - 'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware', |
|
97 | - array( |
|
98 | - $loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'), |
|
99 | - $loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'), |
|
100 | - ) |
|
101 | - ), |
|
102 | - ) |
|
103 | - ); |
|
104 | - // workarounds for PHP < 5.3 |
|
105 | - $this->_load_class_tools(); |
|
106 | - // load interfaces |
|
107 | - espresso_load_required('EEI_Payment_Method_Interfaces', |
|
108 | - EE_LIBRARIES . 'payment_methods' . DS . 'EEI_Payment_Method_Interfaces.php'); |
|
109 | - // deprecated functions |
|
110 | - espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php'); |
|
111 | - // WP cron jobs |
|
112 | - $loader->getShared('EE_Cron_Tasks'); |
|
113 | - $loader->getShared('EE_Request_Handler'); |
|
114 | - $loader->getShared('EE_System'); |
|
115 | - return $this->response; |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - |
|
120 | - /** |
|
121 | - * @return EE_Request |
|
122 | - */ |
|
123 | - public function request() |
|
124 | - { |
|
125 | - return $this->request; |
|
126 | - } |
|
127 | - |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * @return EE_Response |
|
132 | - */ |
|
133 | - public function response() |
|
134 | - { |
|
135 | - return $this->response; |
|
136 | - } |
|
137 | - |
|
138 | - |
|
139 | - |
|
140 | - /** |
|
141 | - * @return EE_Dependency_Map |
|
142 | - * @throws EE_Error |
|
143 | - */ |
|
144 | - public function dependency_map() |
|
145 | - { |
|
146 | - if (! $this->dependency_map instanceof EE_Dependency_Map) { |
|
147 | - throw new EE_Error( |
|
148 | - sprintf( |
|
149 | - __('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'), |
|
150 | - print_r($this->dependency_map, true) |
|
151 | - ) |
|
152 | - ); |
|
153 | - } |
|
154 | - return $this->dependency_map; |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * @return EE_Registry |
|
161 | - * @throws EE_Error |
|
162 | - */ |
|
163 | - public function registry() |
|
164 | - { |
|
165 | - if (! $this->registry instanceof EE_Registry) { |
|
166 | - throw new EE_Error( |
|
167 | - sprintf( |
|
168 | - __('Invalid EE_Registry: "%1$s"', 'event_espresso'), |
|
169 | - print_r($this->registry, true) |
|
170 | - ) |
|
171 | - ); |
|
172 | - } |
|
173 | - return $this->registry; |
|
174 | - } |
|
175 | - |
|
176 | - |
|
177 | - |
|
178 | - /** |
|
179 | - * @return EE_Dependency_Map |
|
180 | - */ |
|
181 | - private function _load_dependency_map() |
|
182 | - { |
|
183 | - if (! is_readable(EE_CORE . 'EE_Dependency_Map.core.php')) { |
|
184 | - EE_Error::add_error( |
|
185 | - __('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'), |
|
186 | - __FILE__, __FUNCTION__, __LINE__ |
|
187 | - ); |
|
188 | - wp_die(EE_Error::get_notices()); |
|
189 | - } |
|
190 | - require_once(EE_CORE . 'EE_Dependency_Map.core.php'); |
|
191 | - return EE_Dependency_Map::instance($this->request, $this->response); |
|
192 | - } |
|
193 | - |
|
194 | - |
|
195 | - |
|
196 | - /** |
|
197 | - * @return EE_Registry |
|
198 | - */ |
|
199 | - private function _load_registry() |
|
200 | - { |
|
201 | - if (! is_readable(EE_CORE . 'EE_Registry.core.php')) { |
|
202 | - EE_Error::add_error( |
|
203 | - __('The EE_Registry core class could not be loaded.', 'event_espresso'), |
|
204 | - __FILE__, __FUNCTION__, __LINE__ |
|
205 | - ); |
|
206 | - wp_die(EE_Error::get_notices()); |
|
207 | - } |
|
208 | - require_once(EE_CORE . 'EE_Registry.core.php'); |
|
209 | - return EE_Registry::instance($this->dependency_map); |
|
210 | - } |
|
211 | - |
|
212 | - |
|
213 | - |
|
214 | - /** |
|
215 | - * @return void |
|
216 | - */ |
|
217 | - private function _load_class_tools() |
|
218 | - { |
|
219 | - if (! is_readable(EE_HELPERS . 'EEH_Class_Tools.helper.php')) { |
|
220 | - EE_Error::add_error( |
|
221 | - __('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'), |
|
222 | - __FILE__, __FUNCTION__, __LINE__ |
|
223 | - ); |
|
224 | - } |
|
225 | - require_once(EE_HELPERS . 'EEH_Class_Tools.helper.php'); |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * called after the request stack has been fully processed |
|
232 | - * if any of the middleware apps has requested the plugin be deactivated, then we do that now |
|
233 | - * |
|
234 | - * @param EE_Request $request |
|
235 | - * @param EE_Response $response |
|
236 | - */ |
|
237 | - public function handle_response(EE_Request $request, EE_Response $response) |
|
238 | - { |
|
239 | - if ($response->plugin_deactivated()) { |
|
240 | - espresso_deactivate_plugin(EE_PLUGIN_BASENAME); |
|
241 | - } |
|
242 | - } |
|
27 | + /** |
|
28 | + * @var EE_Request $request |
|
29 | + */ |
|
30 | + protected $request; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var EE_Response $response |
|
34 | + */ |
|
35 | + protected $response; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var EE_Dependency_Map $dependency_map |
|
39 | + */ |
|
40 | + protected $dependency_map; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var EE_Registry $registry |
|
44 | + */ |
|
45 | + protected $registry; |
|
46 | + |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * EE_Load_Espresso_Core constructor |
|
51 | + */ |
|
52 | + public function __construct() |
|
53 | + { |
|
54 | + espresso_load_required('EventEspresso\core\Factory', EE_CORE . 'Factory.php'); |
|
55 | + } |
|
56 | + |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * handle |
|
61 | + * sets hooks for running rest of system |
|
62 | + * provides "AHEE__EE_System__construct__complete" hook for EE Addons to use as their starting point |
|
63 | + * starting EE Addons from any other point may lead to problems |
|
64 | + * |
|
65 | + * @param EE_Request $request |
|
66 | + * @param EE_Response $response |
|
67 | + * @return EE_Response |
|
68 | + * @throws EE_Error |
|
69 | + * @throws InvalidDataTypeException |
|
70 | + * @throws InvalidInterfaceException |
|
71 | + * @throws InvalidArgumentException |
|
72 | + */ |
|
73 | + public function handle_request(EE_Request $request, EE_Response $response) |
|
74 | + { |
|
75 | + $this->request = $request; |
|
76 | + $this->response = $response; |
|
77 | + // info about how to load classes required by other classes |
|
78 | + $this->dependency_map = $this->_load_dependency_map(); |
|
79 | + // central repository for classes |
|
80 | + $this->registry = $this->_load_registry(); |
|
81 | + // PSR4 Autoloaders |
|
82 | + $this->registry->load_core('EE_Psr4AutoloaderInit'); |
|
83 | + do_action('EE_Load_Espresso_Core__handle_request__initialize_core_loading'); |
|
84 | + $loader = LoaderFactory::getLoader($this->registry); |
|
85 | + $this->dependency_map->setLoader($loader); |
|
86 | + // build DI container |
|
87 | + // $OpenCoffeeShop = new EventEspresso\core\services\container\OpenCoffeeShop(); |
|
88 | + // $OpenCoffeeShop->addRecipes(); |
|
89 | + // $CoffeeShop = $OpenCoffeeShop->CoffeeShop(); |
|
90 | + // create and cache the CommandBus, and also add middleware |
|
91 | + $loader->getShared( |
|
92 | + 'CommandBusInterface', |
|
93 | + array( |
|
94 | + null, |
|
95 | + apply_filters( |
|
96 | + 'FHEE__EE_Load_Espresso_Core__handle_request__CommandBus_middleware', |
|
97 | + array( |
|
98 | + $loader->getShared('EventEspresso\core\services\commands\middleware\CapChecker'), |
|
99 | + $loader->getShared('EventEspresso\core\services\commands\middleware\AddActionHook'), |
|
100 | + ) |
|
101 | + ), |
|
102 | + ) |
|
103 | + ); |
|
104 | + // workarounds for PHP < 5.3 |
|
105 | + $this->_load_class_tools(); |
|
106 | + // load interfaces |
|
107 | + espresso_load_required('EEI_Payment_Method_Interfaces', |
|
108 | + EE_LIBRARIES . 'payment_methods' . DS . 'EEI_Payment_Method_Interfaces.php'); |
|
109 | + // deprecated functions |
|
110 | + espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php'); |
|
111 | + // WP cron jobs |
|
112 | + $loader->getShared('EE_Cron_Tasks'); |
|
113 | + $loader->getShared('EE_Request_Handler'); |
|
114 | + $loader->getShared('EE_System'); |
|
115 | + return $this->response; |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + |
|
120 | + /** |
|
121 | + * @return EE_Request |
|
122 | + */ |
|
123 | + public function request() |
|
124 | + { |
|
125 | + return $this->request; |
|
126 | + } |
|
127 | + |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * @return EE_Response |
|
132 | + */ |
|
133 | + public function response() |
|
134 | + { |
|
135 | + return $this->response; |
|
136 | + } |
|
137 | + |
|
138 | + |
|
139 | + |
|
140 | + /** |
|
141 | + * @return EE_Dependency_Map |
|
142 | + * @throws EE_Error |
|
143 | + */ |
|
144 | + public function dependency_map() |
|
145 | + { |
|
146 | + if (! $this->dependency_map instanceof EE_Dependency_Map) { |
|
147 | + throw new EE_Error( |
|
148 | + sprintf( |
|
149 | + __('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'), |
|
150 | + print_r($this->dependency_map, true) |
|
151 | + ) |
|
152 | + ); |
|
153 | + } |
|
154 | + return $this->dependency_map; |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * @return EE_Registry |
|
161 | + * @throws EE_Error |
|
162 | + */ |
|
163 | + public function registry() |
|
164 | + { |
|
165 | + if (! $this->registry instanceof EE_Registry) { |
|
166 | + throw new EE_Error( |
|
167 | + sprintf( |
|
168 | + __('Invalid EE_Registry: "%1$s"', 'event_espresso'), |
|
169 | + print_r($this->registry, true) |
|
170 | + ) |
|
171 | + ); |
|
172 | + } |
|
173 | + return $this->registry; |
|
174 | + } |
|
175 | + |
|
176 | + |
|
177 | + |
|
178 | + /** |
|
179 | + * @return EE_Dependency_Map |
|
180 | + */ |
|
181 | + private function _load_dependency_map() |
|
182 | + { |
|
183 | + if (! is_readable(EE_CORE . 'EE_Dependency_Map.core.php')) { |
|
184 | + EE_Error::add_error( |
|
185 | + __('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'), |
|
186 | + __FILE__, __FUNCTION__, __LINE__ |
|
187 | + ); |
|
188 | + wp_die(EE_Error::get_notices()); |
|
189 | + } |
|
190 | + require_once(EE_CORE . 'EE_Dependency_Map.core.php'); |
|
191 | + return EE_Dependency_Map::instance($this->request, $this->response); |
|
192 | + } |
|
193 | + |
|
194 | + |
|
195 | + |
|
196 | + /** |
|
197 | + * @return EE_Registry |
|
198 | + */ |
|
199 | + private function _load_registry() |
|
200 | + { |
|
201 | + if (! is_readable(EE_CORE . 'EE_Registry.core.php')) { |
|
202 | + EE_Error::add_error( |
|
203 | + __('The EE_Registry core class could not be loaded.', 'event_espresso'), |
|
204 | + __FILE__, __FUNCTION__, __LINE__ |
|
205 | + ); |
|
206 | + wp_die(EE_Error::get_notices()); |
|
207 | + } |
|
208 | + require_once(EE_CORE . 'EE_Registry.core.php'); |
|
209 | + return EE_Registry::instance($this->dependency_map); |
|
210 | + } |
|
211 | + |
|
212 | + |
|
213 | + |
|
214 | + /** |
|
215 | + * @return void |
|
216 | + */ |
|
217 | + private function _load_class_tools() |
|
218 | + { |
|
219 | + if (! is_readable(EE_HELPERS . 'EEH_Class_Tools.helper.php')) { |
|
220 | + EE_Error::add_error( |
|
221 | + __('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'), |
|
222 | + __FILE__, __FUNCTION__, __LINE__ |
|
223 | + ); |
|
224 | + } |
|
225 | + require_once(EE_HELPERS . 'EEH_Class_Tools.helper.php'); |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * called after the request stack has been fully processed |
|
232 | + * if any of the middleware apps has requested the plugin be deactivated, then we do that now |
|
233 | + * |
|
234 | + * @param EE_Request $request |
|
235 | + * @param EE_Response $response |
|
236 | + */ |
|
237 | + public function handle_response(EE_Request $request, EE_Response $response) |
|
238 | + { |
|
239 | + if ($response->plugin_deactivated()) { |
|
240 | + espresso_deactivate_plugin(EE_PLUGIN_BASENAME); |
|
241 | + } |
|
242 | + } |
|
243 | 243 | |
244 | 244 | |
245 | 245 |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
4 | 4 | use EventEspresso\core\services\loaders\LoaderFactory; |
5 | 5 | |
6 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
6 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
7 | 7 | exit('No direct script access allowed'); |
8 | 8 | } |
9 | 9 | |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function __construct() |
53 | 53 | { |
54 | - espresso_load_required('EventEspresso\core\Factory', EE_CORE . 'Factory.php'); |
|
54 | + espresso_load_required('EventEspresso\core\Factory', EE_CORE.'Factory.php'); |
|
55 | 55 | } |
56 | 56 | |
57 | 57 | |
@@ -105,9 +105,9 @@ discard block |
||
105 | 105 | $this->_load_class_tools(); |
106 | 106 | // load interfaces |
107 | 107 | espresso_load_required('EEI_Payment_Method_Interfaces', |
108 | - EE_LIBRARIES . 'payment_methods' . DS . 'EEI_Payment_Method_Interfaces.php'); |
|
108 | + EE_LIBRARIES.'payment_methods'.DS.'EEI_Payment_Method_Interfaces.php'); |
|
109 | 109 | // deprecated functions |
110 | - espresso_load_required('EE_Deprecated', EE_CORE . 'EE_Deprecated.core.php'); |
|
110 | + espresso_load_required('EE_Deprecated', EE_CORE.'EE_Deprecated.core.php'); |
|
111 | 111 | // WP cron jobs |
112 | 112 | $loader->getShared('EE_Cron_Tasks'); |
113 | 113 | $loader->getShared('EE_Request_Handler'); |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | */ |
144 | 144 | public function dependency_map() |
145 | 145 | { |
146 | - if (! $this->dependency_map instanceof EE_Dependency_Map) { |
|
146 | + if ( ! $this->dependency_map instanceof EE_Dependency_Map) { |
|
147 | 147 | throw new EE_Error( |
148 | 148 | sprintf( |
149 | 149 | __('Invalid EE_Dependency_Map: "%1$s"', 'event_espresso'), |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | */ |
163 | 163 | public function registry() |
164 | 164 | { |
165 | - if (! $this->registry instanceof EE_Registry) { |
|
165 | + if ( ! $this->registry instanceof EE_Registry) { |
|
166 | 166 | throw new EE_Error( |
167 | 167 | sprintf( |
168 | 168 | __('Invalid EE_Registry: "%1$s"', 'event_espresso'), |
@@ -180,14 +180,14 @@ discard block |
||
180 | 180 | */ |
181 | 181 | private function _load_dependency_map() |
182 | 182 | { |
183 | - if (! is_readable(EE_CORE . 'EE_Dependency_Map.core.php')) { |
|
183 | + if ( ! is_readable(EE_CORE.'EE_Dependency_Map.core.php')) { |
|
184 | 184 | EE_Error::add_error( |
185 | 185 | __('The EE_Dependency_Map core class could not be loaded.', 'event_espresso'), |
186 | 186 | __FILE__, __FUNCTION__, __LINE__ |
187 | 187 | ); |
188 | 188 | wp_die(EE_Error::get_notices()); |
189 | 189 | } |
190 | - require_once(EE_CORE . 'EE_Dependency_Map.core.php'); |
|
190 | + require_once(EE_CORE.'EE_Dependency_Map.core.php'); |
|
191 | 191 | return EE_Dependency_Map::instance($this->request, $this->response); |
192 | 192 | } |
193 | 193 | |
@@ -198,14 +198,14 @@ discard block |
||
198 | 198 | */ |
199 | 199 | private function _load_registry() |
200 | 200 | { |
201 | - if (! is_readable(EE_CORE . 'EE_Registry.core.php')) { |
|
201 | + if ( ! is_readable(EE_CORE.'EE_Registry.core.php')) { |
|
202 | 202 | EE_Error::add_error( |
203 | 203 | __('The EE_Registry core class could not be loaded.', 'event_espresso'), |
204 | 204 | __FILE__, __FUNCTION__, __LINE__ |
205 | 205 | ); |
206 | 206 | wp_die(EE_Error::get_notices()); |
207 | 207 | } |
208 | - require_once(EE_CORE . 'EE_Registry.core.php'); |
|
208 | + require_once(EE_CORE.'EE_Registry.core.php'); |
|
209 | 209 | return EE_Registry::instance($this->dependency_map); |
210 | 210 | } |
211 | 211 | |
@@ -216,13 +216,13 @@ discard block |
||
216 | 216 | */ |
217 | 217 | private function _load_class_tools() |
218 | 218 | { |
219 | - if (! is_readable(EE_HELPERS . 'EEH_Class_Tools.helper.php')) { |
|
219 | + if ( ! is_readable(EE_HELPERS.'EEH_Class_Tools.helper.php')) { |
|
220 | 220 | EE_Error::add_error( |
221 | 221 | __('The EEH_Class_Tools helper could not be loaded.', 'event_espresso'), |
222 | 222 | __FILE__, __FUNCTION__, __LINE__ |
223 | 223 | ); |
224 | 224 | } |
225 | - require_once(EE_HELPERS . 'EEH_Class_Tools.helper.php'); |
|
225 | + require_once(EE_HELPERS.'EEH_Class_Tools.helper.php'); |
|
226 | 226 | } |
227 | 227 | |
228 | 228 |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | |
3 | 3 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
4 | - exit('No direct script access allowed'); |
|
4 | + exit('No direct script access allowed'); |
|
5 | 5 | } |
6 | 6 | require_once(EE_MODELS . 'EEM_Base.model.php'); |
7 | 7 | |
@@ -17,193 +17,193 @@ discard block |
||
17 | 17 | class EEM_Transaction extends EEM_Base |
18 | 18 | { |
19 | 19 | |
20 | - // private instance of the Transaction object |
|
21 | - protected static $_instance; |
|
22 | - |
|
23 | - /** |
|
24 | - * Status ID(STS_ID on esp_status table) to indicate the transaction is complete, |
|
25 | - * but payment is pending. This is the state for transactions where payment is promised |
|
26 | - * from an offline gateway. |
|
27 | - */ |
|
28 | - // const open_status_code = 'TPN'; |
|
29 | - |
|
30 | - /** |
|
31 | - * Status ID(STS_ID on esp_status table) to indicate the transaction failed, |
|
32 | - * either due to a technical reason (server or computer crash during registration), |
|
33 | - * or some other reason that prevent the collection of any useful contact information from any of the registrants |
|
34 | - */ |
|
35 | - const failed_status_code = 'TFL'; |
|
36 | - |
|
37 | - /** |
|
38 | - * Status ID(STS_ID on esp_status table) to indicate the transaction was abandoned, |
|
39 | - * either due to a technical reason (server or computer crash during registration), |
|
40 | - * or due to an abandoned cart after registrant chose not to complete the registration process |
|
41 | - * HOWEVER... |
|
42 | - * an abandoned TXN differs from a failed TXN in that it was able to capture contact information for at least one |
|
43 | - * registrant |
|
44 | - */ |
|
45 | - const abandoned_status_code = 'TAB'; |
|
46 | - |
|
47 | - /** |
|
48 | - * Status ID(STS_ID on esp_status table) to indicate an incomplete transaction, |
|
49 | - * meaning that monies are still owing: TXN_paid < TXN_total |
|
50 | - */ |
|
51 | - const incomplete_status_code = 'TIN'; |
|
52 | - |
|
53 | - /** |
|
54 | - * Status ID (STS_ID on esp_status table) to indicate a complete transaction. |
|
55 | - * meaning that NO monies are owing: TXN_paid == TXN_total |
|
56 | - */ |
|
57 | - const complete_status_code = 'TCM'; |
|
58 | - |
|
59 | - /** |
|
60 | - * Status ID(STS_ID on esp_status table) to indicate the transaction is overpaid. |
|
61 | - * This is the same as complete, but site admins actually owe clients the moneys! TXN_paid > TXN_total |
|
62 | - */ |
|
63 | - const overpaid_status_code = 'TOP'; |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * private constructor to prevent direct creation |
|
68 | - * |
|
69 | - * @Constructor |
|
70 | - * @access protected |
|
71 | - * |
|
72 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any |
|
73 | - * incoming timezone data that gets saved). Note this just sends the timezone info to the |
|
74 | - * date time model field objects. Default is NULL (and will be assumed using the set |
|
75 | - * timezone in the 'timezone_string' wp option) |
|
76 | - * |
|
77 | - * @return EEM_Transaction |
|
78 | - * @throws \EE_Error |
|
79 | - */ |
|
80 | - protected function __construct($timezone) |
|
81 | - { |
|
82 | - $this->singular_item = __('Transaction', 'event_espresso'); |
|
83 | - $this->plural_item = __('Transactions', 'event_espresso'); |
|
84 | - |
|
85 | - $this->_tables = array( |
|
86 | - 'TransactionTable' => new EE_Primary_Table('esp_transaction', 'TXN_ID') |
|
87 | - ); |
|
88 | - $this->_fields = array( |
|
89 | - 'TransactionTable' => array( |
|
90 | - 'TXN_ID' => new EE_Primary_Key_Int_Field('TXN_ID', __('Transaction ID', 'event_espresso')), |
|
91 | - 'TXN_timestamp' => new EE_Datetime_Field('TXN_timestamp', |
|
92 | - __('date when transaction was created', 'event_espresso'), false, EE_Datetime_Field::now, |
|
93 | - $timezone), |
|
94 | - 'TXN_total' => new EE_Money_Field('TXN_total', |
|
95 | - __('Total value of Transaction', 'event_espresso'), false, 0), |
|
96 | - 'TXN_paid' => new EE_Money_Field('TXN_paid', |
|
97 | - __('Amount paid towards transaction to date', 'event_espresso'), false, 0), |
|
98 | - 'STS_ID' => new EE_Foreign_Key_String_Field('STS_ID', __('Status ID', 'event_espresso'), |
|
99 | - false, EEM_Transaction::failed_status_code, 'Status'), |
|
100 | - 'TXN_session_data' => new EE_Serialized_Text_Field('TXN_session_data', |
|
101 | - __('Serialized session data', 'event_espresso'), true, ''), |
|
102 | - 'TXN_hash_salt' => new EE_Plain_Text_Field('TXN_hash_salt', |
|
103 | - __('Transaction Hash Salt', 'event_espresso'), true, ''), |
|
104 | - 'PMD_ID' => new EE_Foreign_Key_Int_Field('PMD_ID', |
|
105 | - __("Last Used Payment Method", 'event_espresso'), true, null, 'Payment_Method'), |
|
106 | - 'TXN_reg_steps' => new EE_Serialized_Text_Field('TXN_reg_steps', |
|
107 | - __('Registration Steps', 'event_espresso'), false, array()), |
|
108 | - ) |
|
109 | - ); |
|
110 | - $this->_model_relations = array( |
|
111 | - 'Registration' => new EE_Has_Many_Relation(), |
|
112 | - 'Payment' => new EE_Has_Many_Relation(), |
|
113 | - 'Status' => new EE_Belongs_To_Relation(), |
|
114 | - 'Line_Item' => new EE_Has_Many_Relation(false), |
|
115 | - //you can delete a transaction without needing to delete its line items |
|
116 | - 'Payment_Method' => new EE_Belongs_To_Relation(), |
|
117 | - 'Message' => new EE_Has_Many_Relation() |
|
118 | - ); |
|
119 | - $this->_model_chain_to_wp_user = 'Registration.Event'; |
|
120 | - parent::__construct($timezone); |
|
121 | - |
|
122 | - } |
|
123 | - |
|
124 | - |
|
125 | - /** |
|
126 | - * txn_status_array |
|
127 | - * get list of transaction statuses |
|
128 | - * |
|
129 | - * @access public |
|
130 | - * @return array |
|
131 | - */ |
|
132 | - public static function txn_status_array() |
|
133 | - { |
|
134 | - return apply_filters( |
|
135 | - 'FHEE__EEM_Transaction__txn_status_array', |
|
136 | - array( |
|
137 | - EEM_Transaction::overpaid_status_code, |
|
138 | - EEM_Transaction::complete_status_code, |
|
139 | - EEM_Transaction::incomplete_status_code, |
|
140 | - EEM_Transaction::abandoned_status_code, |
|
141 | - EEM_Transaction::failed_status_code, |
|
142 | - ) |
|
143 | - ); |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * get the revenue per day for the Transaction Admin page Reports Tab |
|
148 | - * |
|
149 | - * @access public |
|
150 | - * |
|
151 | - * @param string $period |
|
152 | - * |
|
153 | - * @return \stdClass[] |
|
154 | - */ |
|
155 | - public function get_revenue_per_day_report($period = '-1 month') |
|
156 | - { |
|
157 | - $sql_date = $this->convert_datetime_for_query('TXN_timestamp', date('Y-m-d H:i:s', strtotime($period)), |
|
158 | - 'Y-m-d H:i:s', 'UTC'); |
|
159 | - |
|
160 | - $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'TXN_timestamp'); |
|
161 | - |
|
162 | - return $this->_get_all_wpdb_results( |
|
163 | - array( |
|
164 | - array( |
|
165 | - 'TXN_timestamp' => array('>=', $sql_date) |
|
166 | - ), |
|
167 | - 'group_by' => 'txnDate', |
|
168 | - 'order_by' => array('TXN_timestamp' => 'ASC') |
|
169 | - ), |
|
170 | - OBJECT, |
|
171 | - array( |
|
172 | - 'txnDate' => array('DATE(' . $query_interval . ')', '%s'), |
|
173 | - 'revenue' => array('SUM(TransactionTable.TXN_paid)', '%d') |
|
174 | - ) |
|
175 | - ); |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * get the revenue per event for the Transaction Admin page Reports Tab |
|
181 | - * |
|
182 | - * @access public |
|
183 | - * |
|
184 | - * @param string $period |
|
185 | - * |
|
186 | - * @throws \EE_Error |
|
187 | - * @return mixed |
|
188 | - */ |
|
189 | - public function get_revenue_per_event_report($period = '-1 month') |
|
190 | - { |
|
191 | - global $wpdb; |
|
192 | - $transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
193 | - $registration_table = $wpdb->prefix . 'esp_registration'; |
|
194 | - $registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; |
|
195 | - $event_table = $wpdb->posts; |
|
196 | - $payment_table = $wpdb->prefix . 'esp_payment'; |
|
197 | - $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
|
198 | - $approved_payment_status = EEM_Payment::status_id_approved; |
|
199 | - $extra_event_on_join = ''; |
|
200 | - //exclude events not authored by user if permissions in effect |
|
201 | - if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
202 | - $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id(); |
|
203 | - } |
|
204 | - |
|
205 | - return $wpdb->get_results( |
|
206 | - "SELECT |
|
20 | + // private instance of the Transaction object |
|
21 | + protected static $_instance; |
|
22 | + |
|
23 | + /** |
|
24 | + * Status ID(STS_ID on esp_status table) to indicate the transaction is complete, |
|
25 | + * but payment is pending. This is the state for transactions where payment is promised |
|
26 | + * from an offline gateway. |
|
27 | + */ |
|
28 | + // const open_status_code = 'TPN'; |
|
29 | + |
|
30 | + /** |
|
31 | + * Status ID(STS_ID on esp_status table) to indicate the transaction failed, |
|
32 | + * either due to a technical reason (server or computer crash during registration), |
|
33 | + * or some other reason that prevent the collection of any useful contact information from any of the registrants |
|
34 | + */ |
|
35 | + const failed_status_code = 'TFL'; |
|
36 | + |
|
37 | + /** |
|
38 | + * Status ID(STS_ID on esp_status table) to indicate the transaction was abandoned, |
|
39 | + * either due to a technical reason (server or computer crash during registration), |
|
40 | + * or due to an abandoned cart after registrant chose not to complete the registration process |
|
41 | + * HOWEVER... |
|
42 | + * an abandoned TXN differs from a failed TXN in that it was able to capture contact information for at least one |
|
43 | + * registrant |
|
44 | + */ |
|
45 | + const abandoned_status_code = 'TAB'; |
|
46 | + |
|
47 | + /** |
|
48 | + * Status ID(STS_ID on esp_status table) to indicate an incomplete transaction, |
|
49 | + * meaning that monies are still owing: TXN_paid < TXN_total |
|
50 | + */ |
|
51 | + const incomplete_status_code = 'TIN'; |
|
52 | + |
|
53 | + /** |
|
54 | + * Status ID (STS_ID on esp_status table) to indicate a complete transaction. |
|
55 | + * meaning that NO monies are owing: TXN_paid == TXN_total |
|
56 | + */ |
|
57 | + const complete_status_code = 'TCM'; |
|
58 | + |
|
59 | + /** |
|
60 | + * Status ID(STS_ID on esp_status table) to indicate the transaction is overpaid. |
|
61 | + * This is the same as complete, but site admins actually owe clients the moneys! TXN_paid > TXN_total |
|
62 | + */ |
|
63 | + const overpaid_status_code = 'TOP'; |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * private constructor to prevent direct creation |
|
68 | + * |
|
69 | + * @Constructor |
|
70 | + * @access protected |
|
71 | + * |
|
72 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any |
|
73 | + * incoming timezone data that gets saved). Note this just sends the timezone info to the |
|
74 | + * date time model field objects. Default is NULL (and will be assumed using the set |
|
75 | + * timezone in the 'timezone_string' wp option) |
|
76 | + * |
|
77 | + * @return EEM_Transaction |
|
78 | + * @throws \EE_Error |
|
79 | + */ |
|
80 | + protected function __construct($timezone) |
|
81 | + { |
|
82 | + $this->singular_item = __('Transaction', 'event_espresso'); |
|
83 | + $this->plural_item = __('Transactions', 'event_espresso'); |
|
84 | + |
|
85 | + $this->_tables = array( |
|
86 | + 'TransactionTable' => new EE_Primary_Table('esp_transaction', 'TXN_ID') |
|
87 | + ); |
|
88 | + $this->_fields = array( |
|
89 | + 'TransactionTable' => array( |
|
90 | + 'TXN_ID' => new EE_Primary_Key_Int_Field('TXN_ID', __('Transaction ID', 'event_espresso')), |
|
91 | + 'TXN_timestamp' => new EE_Datetime_Field('TXN_timestamp', |
|
92 | + __('date when transaction was created', 'event_espresso'), false, EE_Datetime_Field::now, |
|
93 | + $timezone), |
|
94 | + 'TXN_total' => new EE_Money_Field('TXN_total', |
|
95 | + __('Total value of Transaction', 'event_espresso'), false, 0), |
|
96 | + 'TXN_paid' => new EE_Money_Field('TXN_paid', |
|
97 | + __('Amount paid towards transaction to date', 'event_espresso'), false, 0), |
|
98 | + 'STS_ID' => new EE_Foreign_Key_String_Field('STS_ID', __('Status ID', 'event_espresso'), |
|
99 | + false, EEM_Transaction::failed_status_code, 'Status'), |
|
100 | + 'TXN_session_data' => new EE_Serialized_Text_Field('TXN_session_data', |
|
101 | + __('Serialized session data', 'event_espresso'), true, ''), |
|
102 | + 'TXN_hash_salt' => new EE_Plain_Text_Field('TXN_hash_salt', |
|
103 | + __('Transaction Hash Salt', 'event_espresso'), true, ''), |
|
104 | + 'PMD_ID' => new EE_Foreign_Key_Int_Field('PMD_ID', |
|
105 | + __("Last Used Payment Method", 'event_espresso'), true, null, 'Payment_Method'), |
|
106 | + 'TXN_reg_steps' => new EE_Serialized_Text_Field('TXN_reg_steps', |
|
107 | + __('Registration Steps', 'event_espresso'), false, array()), |
|
108 | + ) |
|
109 | + ); |
|
110 | + $this->_model_relations = array( |
|
111 | + 'Registration' => new EE_Has_Many_Relation(), |
|
112 | + 'Payment' => new EE_Has_Many_Relation(), |
|
113 | + 'Status' => new EE_Belongs_To_Relation(), |
|
114 | + 'Line_Item' => new EE_Has_Many_Relation(false), |
|
115 | + //you can delete a transaction without needing to delete its line items |
|
116 | + 'Payment_Method' => new EE_Belongs_To_Relation(), |
|
117 | + 'Message' => new EE_Has_Many_Relation() |
|
118 | + ); |
|
119 | + $this->_model_chain_to_wp_user = 'Registration.Event'; |
|
120 | + parent::__construct($timezone); |
|
121 | + |
|
122 | + } |
|
123 | + |
|
124 | + |
|
125 | + /** |
|
126 | + * txn_status_array |
|
127 | + * get list of transaction statuses |
|
128 | + * |
|
129 | + * @access public |
|
130 | + * @return array |
|
131 | + */ |
|
132 | + public static function txn_status_array() |
|
133 | + { |
|
134 | + return apply_filters( |
|
135 | + 'FHEE__EEM_Transaction__txn_status_array', |
|
136 | + array( |
|
137 | + EEM_Transaction::overpaid_status_code, |
|
138 | + EEM_Transaction::complete_status_code, |
|
139 | + EEM_Transaction::incomplete_status_code, |
|
140 | + EEM_Transaction::abandoned_status_code, |
|
141 | + EEM_Transaction::failed_status_code, |
|
142 | + ) |
|
143 | + ); |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * get the revenue per day for the Transaction Admin page Reports Tab |
|
148 | + * |
|
149 | + * @access public |
|
150 | + * |
|
151 | + * @param string $period |
|
152 | + * |
|
153 | + * @return \stdClass[] |
|
154 | + */ |
|
155 | + public function get_revenue_per_day_report($period = '-1 month') |
|
156 | + { |
|
157 | + $sql_date = $this->convert_datetime_for_query('TXN_timestamp', date('Y-m-d H:i:s', strtotime($period)), |
|
158 | + 'Y-m-d H:i:s', 'UTC'); |
|
159 | + |
|
160 | + $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'TXN_timestamp'); |
|
161 | + |
|
162 | + return $this->_get_all_wpdb_results( |
|
163 | + array( |
|
164 | + array( |
|
165 | + 'TXN_timestamp' => array('>=', $sql_date) |
|
166 | + ), |
|
167 | + 'group_by' => 'txnDate', |
|
168 | + 'order_by' => array('TXN_timestamp' => 'ASC') |
|
169 | + ), |
|
170 | + OBJECT, |
|
171 | + array( |
|
172 | + 'txnDate' => array('DATE(' . $query_interval . ')', '%s'), |
|
173 | + 'revenue' => array('SUM(TransactionTable.TXN_paid)', '%d') |
|
174 | + ) |
|
175 | + ); |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * get the revenue per event for the Transaction Admin page Reports Tab |
|
181 | + * |
|
182 | + * @access public |
|
183 | + * |
|
184 | + * @param string $period |
|
185 | + * |
|
186 | + * @throws \EE_Error |
|
187 | + * @return mixed |
|
188 | + */ |
|
189 | + public function get_revenue_per_event_report($period = '-1 month') |
|
190 | + { |
|
191 | + global $wpdb; |
|
192 | + $transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
193 | + $registration_table = $wpdb->prefix . 'esp_registration'; |
|
194 | + $registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; |
|
195 | + $event_table = $wpdb->posts; |
|
196 | + $payment_table = $wpdb->prefix . 'esp_payment'; |
|
197 | + $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
|
198 | + $approved_payment_status = EEM_Payment::status_id_approved; |
|
199 | + $extra_event_on_join = ''; |
|
200 | + //exclude events not authored by user if permissions in effect |
|
201 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
202 | + $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id(); |
|
203 | + } |
|
204 | + |
|
205 | + return $wpdb->get_results( |
|
206 | + "SELECT |
|
207 | 207 | Transaction_Event.event_name AS event_name, |
208 | 208 | SUM(Transaction_Event.paid) AS revenue |
209 | 209 | FROM |
@@ -230,185 +230,185 @@ discard block |
||
230 | 230 | $extra_event_on_join |
231 | 231 | ) AS Transaction_Event |
232 | 232 | GROUP BY event_name", |
233 | - OBJECT |
|
234 | - ); |
|
235 | - } |
|
236 | - |
|
237 | - |
|
238 | - /** |
|
239 | - * Gets the current transaction given the reg_url_link, or assumes the reg_url_link is in the |
|
240 | - * $_REQUEST global variable. Either way, tries to find the current transaction (through |
|
241 | - * the registration pointed to by reg_url_link), if not returns null |
|
242 | - * |
|
243 | - * @param string $reg_url_link |
|
244 | - * |
|
245 | - * @return EE_Transaction |
|
246 | - */ |
|
247 | - public function get_transaction_from_reg_url_link($reg_url_link = '') |
|
248 | - { |
|
249 | - return $this->get_one(array( |
|
250 | - array( |
|
251 | - 'Registration.REG_url_link' => ! empty($reg_url_link) ? $reg_url_link : EE_Registry::instance()->REQ->get('e_reg_url_link', |
|
252 | - '') |
|
253 | - ) |
|
254 | - )); |
|
255 | - } |
|
256 | - |
|
257 | - |
|
258 | - /** |
|
259 | - * Updates the provided EE_Transaction with all the applicable payments |
|
260 | - * (or fetch the EE_Transaction from its ID) |
|
261 | - * |
|
262 | - * @deprecated |
|
263 | - * |
|
264 | - * @param EE_Transaction|int $transaction_obj_or_id |
|
265 | - * @param boolean $save_txn whether or not to save the transaction during this function call |
|
266 | - * |
|
267 | - * @return boolean |
|
268 | - * @throws \EE_Error |
|
269 | - */ |
|
270 | - public function update_based_on_payments($transaction_obj_or_id, $save_txn = true) |
|
271 | - { |
|
272 | - EE_Error::doing_it_wrong( |
|
273 | - __CLASS__ . '::' . __FUNCTION__, |
|
274 | - sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
275 | - 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()'), |
|
276 | - '4.6.0' |
|
277 | - ); |
|
278 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
279 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
280 | - |
|
281 | - return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
|
282 | - $this->ensure_is_obj($transaction_obj_or_id) |
|
283 | - ); |
|
284 | - } |
|
285 | - |
|
286 | - /** |
|
287 | - * Deletes "junk" transactions that were probably added by bots. There might be TONS |
|
288 | - * of these, so we are very careful to NOT select (which the models do even when deleting), |
|
289 | - * and so we only use wpdb directly and only do minimal joins. |
|
290 | - * Transactions are considered "junk" if they're failed for longer than a week. |
|
291 | - * Also, there is an extra check for payments related to the transaction, because if a transaction has a payment on |
|
292 | - * it, it's probably not junk (regardless of what status it has). |
|
293 | - * The downside to this approach is that is addons are listening for object deletions |
|
294 | - * on EEM_Base::delete() they won't be notified of this. However, there is an action that plugins can hook into |
|
295 | - * to catch these types of deletions. |
|
296 | - * |
|
297 | - * @global WPDB $wpdb |
|
298 | - * @return mixed |
|
299 | - */ |
|
300 | - public function delete_junk_transactions() |
|
301 | - { |
|
302 | - /** @type WPDB $wpdb */ |
|
303 | - global $wpdb; |
|
304 | - $deleted = false; |
|
305 | - $time_to_leave_alone = apply_filters( |
|
306 | - 'FHEE__EEM_Transaction__delete_junk_transactions__time_to_leave_alone' |
|
307 | - , WEEK_IN_SECONDS |
|
308 | - ); |
|
309 | - |
|
310 | - |
|
311 | - /** |
|
312 | - * This allows code to filter the query arguments used for retrieving the transaction IDs to delete. |
|
313 | - * Useful for plugins that want to exclude transactions matching certain query parameters. |
|
314 | - * The query parameters should be in the format accepted by the EEM_Base model queries. |
|
315 | - */ |
|
316 | - $ids_query = apply_filters( |
|
317 | - 'FHEE__EEM_Transaction__delete_junk_transactions__initial_query_args', |
|
318 | - array( |
|
319 | - 0 => array( |
|
320 | - 'STS_ID' => EEM_Transaction::failed_status_code, |
|
321 | - 'Payment.PAY_ID' => array( 'IS NULL' ), |
|
322 | - 'TXN_timestamp' => array('<', time() - $time_to_leave_alone) |
|
323 | - ) |
|
324 | - ), |
|
325 | - $time_to_leave_alone |
|
326 | - ); |
|
327 | - |
|
328 | - |
|
329 | - /** |
|
330 | - * This filter is for when code needs to filter the list of transaction ids that represent transactions |
|
331 | - * about to be deleted based on some other criteria that isn't easily done via the query args filter. |
|
332 | - */ |
|
333 | - $txn_ids = apply_filters( |
|
334 | - 'FHEE__EEM_Transaction__delete_junk_transactions__transaction_ids_to_delete', |
|
335 | - EEM_Transaction::instance()->get_col($ids_query, 'TXN_ID'), |
|
336 | - $time_to_leave_alone |
|
337 | - ); |
|
338 | - //now that we have the ids to delete |
|
339 | - if (! empty($txn_ids) && is_array($txn_ids)) { |
|
340 | - // first, make sure these TXN's are removed the "ee_locked_transactions" array |
|
341 | - EEM_Transaction::unset_locked_transactions($txn_ids); |
|
342 | - // let's get deletin'... |
|
343 | - // Why no wpdb->prepare? Because the data is trusted. |
|
344 | - // We got the ids from the original query to get them FROM |
|
345 | - // the db (which is sanitized) so no need to prepare them again. |
|
346 | - $query = ' |
|
233 | + OBJECT |
|
234 | + ); |
|
235 | + } |
|
236 | + |
|
237 | + |
|
238 | + /** |
|
239 | + * Gets the current transaction given the reg_url_link, or assumes the reg_url_link is in the |
|
240 | + * $_REQUEST global variable. Either way, tries to find the current transaction (through |
|
241 | + * the registration pointed to by reg_url_link), if not returns null |
|
242 | + * |
|
243 | + * @param string $reg_url_link |
|
244 | + * |
|
245 | + * @return EE_Transaction |
|
246 | + */ |
|
247 | + public function get_transaction_from_reg_url_link($reg_url_link = '') |
|
248 | + { |
|
249 | + return $this->get_one(array( |
|
250 | + array( |
|
251 | + 'Registration.REG_url_link' => ! empty($reg_url_link) ? $reg_url_link : EE_Registry::instance()->REQ->get('e_reg_url_link', |
|
252 | + '') |
|
253 | + ) |
|
254 | + )); |
|
255 | + } |
|
256 | + |
|
257 | + |
|
258 | + /** |
|
259 | + * Updates the provided EE_Transaction with all the applicable payments |
|
260 | + * (or fetch the EE_Transaction from its ID) |
|
261 | + * |
|
262 | + * @deprecated |
|
263 | + * |
|
264 | + * @param EE_Transaction|int $transaction_obj_or_id |
|
265 | + * @param boolean $save_txn whether or not to save the transaction during this function call |
|
266 | + * |
|
267 | + * @return boolean |
|
268 | + * @throws \EE_Error |
|
269 | + */ |
|
270 | + public function update_based_on_payments($transaction_obj_or_id, $save_txn = true) |
|
271 | + { |
|
272 | + EE_Error::doing_it_wrong( |
|
273 | + __CLASS__ . '::' . __FUNCTION__, |
|
274 | + sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
275 | + 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()'), |
|
276 | + '4.6.0' |
|
277 | + ); |
|
278 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
279 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
280 | + |
|
281 | + return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
|
282 | + $this->ensure_is_obj($transaction_obj_or_id) |
|
283 | + ); |
|
284 | + } |
|
285 | + |
|
286 | + /** |
|
287 | + * Deletes "junk" transactions that were probably added by bots. There might be TONS |
|
288 | + * of these, so we are very careful to NOT select (which the models do even when deleting), |
|
289 | + * and so we only use wpdb directly and only do minimal joins. |
|
290 | + * Transactions are considered "junk" if they're failed for longer than a week. |
|
291 | + * Also, there is an extra check for payments related to the transaction, because if a transaction has a payment on |
|
292 | + * it, it's probably not junk (regardless of what status it has). |
|
293 | + * The downside to this approach is that is addons are listening for object deletions |
|
294 | + * on EEM_Base::delete() they won't be notified of this. However, there is an action that plugins can hook into |
|
295 | + * to catch these types of deletions. |
|
296 | + * |
|
297 | + * @global WPDB $wpdb |
|
298 | + * @return mixed |
|
299 | + */ |
|
300 | + public function delete_junk_transactions() |
|
301 | + { |
|
302 | + /** @type WPDB $wpdb */ |
|
303 | + global $wpdb; |
|
304 | + $deleted = false; |
|
305 | + $time_to_leave_alone = apply_filters( |
|
306 | + 'FHEE__EEM_Transaction__delete_junk_transactions__time_to_leave_alone' |
|
307 | + , WEEK_IN_SECONDS |
|
308 | + ); |
|
309 | + |
|
310 | + |
|
311 | + /** |
|
312 | + * This allows code to filter the query arguments used for retrieving the transaction IDs to delete. |
|
313 | + * Useful for plugins that want to exclude transactions matching certain query parameters. |
|
314 | + * The query parameters should be in the format accepted by the EEM_Base model queries. |
|
315 | + */ |
|
316 | + $ids_query = apply_filters( |
|
317 | + 'FHEE__EEM_Transaction__delete_junk_transactions__initial_query_args', |
|
318 | + array( |
|
319 | + 0 => array( |
|
320 | + 'STS_ID' => EEM_Transaction::failed_status_code, |
|
321 | + 'Payment.PAY_ID' => array( 'IS NULL' ), |
|
322 | + 'TXN_timestamp' => array('<', time() - $time_to_leave_alone) |
|
323 | + ) |
|
324 | + ), |
|
325 | + $time_to_leave_alone |
|
326 | + ); |
|
327 | + |
|
328 | + |
|
329 | + /** |
|
330 | + * This filter is for when code needs to filter the list of transaction ids that represent transactions |
|
331 | + * about to be deleted based on some other criteria that isn't easily done via the query args filter. |
|
332 | + */ |
|
333 | + $txn_ids = apply_filters( |
|
334 | + 'FHEE__EEM_Transaction__delete_junk_transactions__transaction_ids_to_delete', |
|
335 | + EEM_Transaction::instance()->get_col($ids_query, 'TXN_ID'), |
|
336 | + $time_to_leave_alone |
|
337 | + ); |
|
338 | + //now that we have the ids to delete |
|
339 | + if (! empty($txn_ids) && is_array($txn_ids)) { |
|
340 | + // first, make sure these TXN's are removed the "ee_locked_transactions" array |
|
341 | + EEM_Transaction::unset_locked_transactions($txn_ids); |
|
342 | + // let's get deletin'... |
|
343 | + // Why no wpdb->prepare? Because the data is trusted. |
|
344 | + // We got the ids from the original query to get them FROM |
|
345 | + // the db (which is sanitized) so no need to prepare them again. |
|
346 | + $query = ' |
|
347 | 347 | DELETE |
348 | 348 | FROM ' . $this->table() . ' |
349 | 349 | WHERE |
350 | 350 | TXN_ID IN ( ' . implode(",", $txn_ids) . ')'; |
351 | - $deleted = $wpdb->query($query); |
|
352 | - } |
|
353 | - if ($deleted) { |
|
354 | - /** |
|
355 | - * Allows code to do something after the transactions have been deleted. |
|
356 | - */ |
|
357 | - do_action('AHEE__EEM_Transaction__delete_junk_transactions__successful_deletion', $txn_ids); |
|
358 | - } |
|
359 | - |
|
360 | - return $deleted; |
|
361 | - } |
|
362 | - |
|
363 | - |
|
364 | - /** |
|
365 | - * @param array $transaction_IDs |
|
366 | - * |
|
367 | - * @return bool |
|
368 | - */ |
|
369 | - public static function unset_locked_transactions(array $transaction_IDs) |
|
370 | - { |
|
371 | - $locked_transactions = get_option('ee_locked_transactions', array()); |
|
372 | - $update = false; |
|
373 | - foreach ($transaction_IDs as $TXN_ID) { |
|
374 | - if (isset($locked_transactions[$TXN_ID])) { |
|
375 | - unset($locked_transactions[$TXN_ID]); |
|
376 | - $update = true; |
|
377 | - } |
|
378 | - } |
|
379 | - if ($update) { |
|
380 | - update_option('ee_locked_transactions', $locked_transactions); |
|
381 | - } |
|
382 | - |
|
383 | - return $update; |
|
384 | - } |
|
385 | - |
|
386 | - |
|
387 | - |
|
388 | - /** |
|
389 | - * returns an array of EE_Transaction objects whose timestamp is less than |
|
390 | - * the current time minus the session lifespan, which defaults to 60 minutes |
|
391 | - * |
|
392 | - * @return EE_Base_Class[]|EE_Transaction[] |
|
393 | - * @throws \EE_Error |
|
394 | - */ |
|
395 | - public function get_transactions_in_progress() |
|
396 | - { |
|
397 | - return $this->get_all( |
|
398 | - array( |
|
399 | - array( |
|
400 | - 'TXN_timestamp' => array( |
|
401 | - '>', |
|
402 | - time() - EE_Registry::instance()->SSN->lifespan() |
|
403 | - ), |
|
404 | - 'STS_ID' => array( |
|
405 | - '!=', |
|
406 | - EEM_Transaction::complete_status_code |
|
407 | - ), |
|
408 | - ) |
|
409 | - ) |
|
410 | - ); |
|
411 | - } |
|
351 | + $deleted = $wpdb->query($query); |
|
352 | + } |
|
353 | + if ($deleted) { |
|
354 | + /** |
|
355 | + * Allows code to do something after the transactions have been deleted. |
|
356 | + */ |
|
357 | + do_action('AHEE__EEM_Transaction__delete_junk_transactions__successful_deletion', $txn_ids); |
|
358 | + } |
|
359 | + |
|
360 | + return $deleted; |
|
361 | + } |
|
362 | + |
|
363 | + |
|
364 | + /** |
|
365 | + * @param array $transaction_IDs |
|
366 | + * |
|
367 | + * @return bool |
|
368 | + */ |
|
369 | + public static function unset_locked_transactions(array $transaction_IDs) |
|
370 | + { |
|
371 | + $locked_transactions = get_option('ee_locked_transactions', array()); |
|
372 | + $update = false; |
|
373 | + foreach ($transaction_IDs as $TXN_ID) { |
|
374 | + if (isset($locked_transactions[$TXN_ID])) { |
|
375 | + unset($locked_transactions[$TXN_ID]); |
|
376 | + $update = true; |
|
377 | + } |
|
378 | + } |
|
379 | + if ($update) { |
|
380 | + update_option('ee_locked_transactions', $locked_transactions); |
|
381 | + } |
|
382 | + |
|
383 | + return $update; |
|
384 | + } |
|
385 | + |
|
386 | + |
|
387 | + |
|
388 | + /** |
|
389 | + * returns an array of EE_Transaction objects whose timestamp is less than |
|
390 | + * the current time minus the session lifespan, which defaults to 60 minutes |
|
391 | + * |
|
392 | + * @return EE_Base_Class[]|EE_Transaction[] |
|
393 | + * @throws \EE_Error |
|
394 | + */ |
|
395 | + public function get_transactions_in_progress() |
|
396 | + { |
|
397 | + return $this->get_all( |
|
398 | + array( |
|
399 | + array( |
|
400 | + 'TXN_timestamp' => array( |
|
401 | + '>', |
|
402 | + time() - EE_Registry::instance()->SSN->lifespan() |
|
403 | + ), |
|
404 | + 'STS_ID' => array( |
|
405 | + '!=', |
|
406 | + EEM_Transaction::complete_status_code |
|
407 | + ), |
|
408 | + ) |
|
409 | + ) |
|
410 | + ); |
|
411 | + } |
|
412 | 412 | |
413 | 413 | |
414 | 414 | } |
@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
4 | 4 | exit('No direct script access allowed'); |
5 | 5 | } |
6 | -require_once(EE_MODELS . 'EEM_Base.model.php'); |
|
6 | +require_once(EE_MODELS.'EEM_Base.model.php'); |
|
7 | 7 | |
8 | 8 | /** |
9 | 9 | * |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | __('Registration Steps', 'event_espresso'), false, array()), |
108 | 108 | ) |
109 | 109 | ); |
110 | - $this->_model_relations = array( |
|
110 | + $this->_model_relations = array( |
|
111 | 111 | 'Registration' => new EE_Has_Many_Relation(), |
112 | 112 | 'Payment' => new EE_Has_Many_Relation(), |
113 | 113 | 'Status' => new EE_Belongs_To_Relation(), |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | ), |
170 | 170 | OBJECT, |
171 | 171 | array( |
172 | - 'txnDate' => array('DATE(' . $query_interval . ')', '%s'), |
|
172 | + 'txnDate' => array('DATE('.$query_interval.')', '%s'), |
|
173 | 173 | 'revenue' => array('SUM(TransactionTable.TXN_paid)', '%d') |
174 | 174 | ) |
175 | 175 | ); |
@@ -189,17 +189,17 @@ discard block |
||
189 | 189 | public function get_revenue_per_event_report($period = '-1 month') |
190 | 190 | { |
191 | 191 | global $wpdb; |
192 | - $transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
193 | - $registration_table = $wpdb->prefix . 'esp_registration'; |
|
194 | - $registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; |
|
192 | + $transaction_table = $wpdb->prefix.'esp_transaction'; |
|
193 | + $registration_table = $wpdb->prefix.'esp_registration'; |
|
194 | + $registration_payment_table = $wpdb->prefix.'esp_registration_payment'; |
|
195 | 195 | $event_table = $wpdb->posts; |
196 | - $payment_table = $wpdb->prefix . 'esp_payment'; |
|
196 | + $payment_table = $wpdb->prefix.'esp_payment'; |
|
197 | 197 | $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
198 | 198 | $approved_payment_status = EEM_Payment::status_id_approved; |
199 | 199 | $extra_event_on_join = ''; |
200 | 200 | //exclude events not authored by user if permissions in effect |
201 | 201 | if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
202 | - $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id(); |
|
202 | + $extra_event_on_join = ' AND Event.post_author = '.get_current_user_id(); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | return $wpdb->get_results( |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | public function update_based_on_payments($transaction_obj_or_id, $save_txn = true) |
271 | 271 | { |
272 | 272 | EE_Error::doing_it_wrong( |
273 | - __CLASS__ . '::' . __FUNCTION__, |
|
273 | + __CLASS__.'::'.__FUNCTION__, |
|
274 | 274 | sprintf(__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
275 | 275 | 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()'), |
276 | 276 | '4.6.0' |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | array( |
319 | 319 | 0 => array( |
320 | 320 | 'STS_ID' => EEM_Transaction::failed_status_code, |
321 | - 'Payment.PAY_ID' => array( 'IS NULL' ), |
|
321 | + 'Payment.PAY_ID' => array('IS NULL'), |
|
322 | 322 | 'TXN_timestamp' => array('<', time() - $time_to_leave_alone) |
323 | 323 | ) |
324 | 324 | ), |
@@ -336,18 +336,18 @@ discard block |
||
336 | 336 | $time_to_leave_alone |
337 | 337 | ); |
338 | 338 | //now that we have the ids to delete |
339 | - if (! empty($txn_ids) && is_array($txn_ids)) { |
|
339 | + if ( ! empty($txn_ids) && is_array($txn_ids)) { |
|
340 | 340 | // first, make sure these TXN's are removed the "ee_locked_transactions" array |
341 | 341 | EEM_Transaction::unset_locked_transactions($txn_ids); |
342 | 342 | // let's get deletin'... |
343 | 343 | // Why no wpdb->prepare? Because the data is trusted. |
344 | 344 | // We got the ids from the original query to get them FROM |
345 | 345 | // the db (which is sanitized) so no need to prepare them again. |
346 | - $query = ' |
|
346 | + $query = ' |
|
347 | 347 | DELETE |
348 | - FROM ' . $this->table() . ' |
|
348 | + FROM ' . $this->table().' |
|
349 | 349 | WHERE |
350 | - TXN_ID IN ( ' . implode(",", $txn_ids) . ')'; |
|
350 | + TXN_ID IN ( ' . implode(",", $txn_ids).')'; |
|
351 | 351 | $deleted = $wpdb->query($query); |
352 | 352 | } |
353 | 353 | if ($deleted) { |