@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @since 4.0 |
9 | 9 | * |
10 | 10 | */ |
11 | -class EEH_Debug_Tools{ |
|
11 | +class EEH_Debug_Tools { |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * instance of the EEH_Autoloader object |
@@ -41,7 +41,7 @@ discard block |
||
41 | 41 | */ |
42 | 42 | public static function instance() { |
43 | 43 | // check if class object is instantiated, and instantiated properly |
44 | - if ( ! self::$_instance instanceof EEH_Debug_Tools ) { |
|
44 | + if ( ! self::$_instance instanceof EEH_Debug_Tools) { |
|
45 | 45 | self::$_instance = new self(); |
46 | 46 | } |
47 | 47 | return self::$_instance; |
@@ -57,21 +57,21 @@ discard block |
||
57 | 57 | */ |
58 | 58 | private function __construct() { |
59 | 59 | // load Kint PHP debugging library |
60 | - if ( ! class_exists( 'Kint' ) && file_exists( EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php' )){ |
|
60 | + if ( ! class_exists('Kint') && file_exists(EE_PLUGIN_DIR_PATH.'tests'.DS.'kint'.DS.'Kint.class.php')) { |
|
61 | 61 | // despite EE4 having a check for an existing copy of the Kint debugging class, |
62 | 62 | // if another plugin was loaded AFTER EE4 and they did NOT perform a similar check, |
63 | 63 | // then hilarity would ensue as PHP throws a "Cannot redeclare class Kint" error |
64 | 64 | // so we've moved it to our test folder so that it is not included with production releases |
65 | 65 | // plz use https://wordpress.org/plugins/kint-debugger/ if testing production versions of EE |
66 | - require_once( EE_PLUGIN_DIR_PATH . 'tests' . DS . 'kint' . DS . 'Kint.class.php' ); |
|
66 | + require_once(EE_PLUGIN_DIR_PATH.'tests'.DS.'kint'.DS.'Kint.class.php'); |
|
67 | 67 | } |
68 | - if ( ! defined('DOING_AJAX') || ! isset( $_REQUEST['noheader'] ) || $_REQUEST['noheader'] != 'true' || ! isset( $_REQUEST['TB_iframe'] )) { |
|
68 | + if ( ! defined('DOING_AJAX') || ! isset($_REQUEST['noheader']) || $_REQUEST['noheader'] != 'true' || ! isset($_REQUEST['TB_iframe'])) { |
|
69 | 69 | //add_action( 'shutdown', array($this,'espresso_session_footer_dump') ); |
70 | 70 | } |
71 | - $plugin = basename( EE_PLUGIN_DIR_PATH ); |
|
72 | - add_action( "activate_{$plugin}", array( 'EEH_Debug_Tools', 'ee_plugin_activation_errors' )); |
|
73 | - add_action( 'activated_plugin', array( 'EEH_Debug_Tools', 'ee_plugin_activation_errors' )); |
|
74 | - add_action( 'shutdown', array( 'EEH_Debug_Tools', 'show_db_name' )); |
|
71 | + $plugin = basename(EE_PLUGIN_DIR_PATH); |
|
72 | + add_action("activate_{$plugin}", array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
73 | + add_action('activated_plugin', array('EEH_Debug_Tools', 'ee_plugin_activation_errors')); |
|
74 | + add_action('shutdown', array('EEH_Debug_Tools', 'show_db_name')); |
|
75 | 75 | } |
76 | 76 | |
77 | 77 | |
@@ -82,8 +82,8 @@ discard block |
||
82 | 82 | * @return void |
83 | 83 | */ |
84 | 84 | public static function show_db_name() { |
85 | - if ( ! defined( 'DOING_AJAX' ) && ( defined( 'EE_ERROR_EMAILS' ) && EE_ERROR_EMAILS )) { |
|
86 | - echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: '. DB_NAME .'</p>'; |
|
85 | + if ( ! defined('DOING_AJAX') && (defined('EE_ERROR_EMAILS') && EE_ERROR_EMAILS)) { |
|
86 | + echo '<p style="font-size:10px;font-weight:normal;color:#E76700;margin: 1em 2em; text-align: right;">DB_NAME: '.DB_NAME.'</p>'; |
|
87 | 87 | } |
88 | 88 | } |
89 | 89 | |
@@ -95,9 +95,9 @@ discard block |
||
95 | 95 | * @return void |
96 | 96 | */ |
97 | 97 | public function espresso_session_footer_dump() { |
98 | - if ( class_exists('Kint') && function_exists( 'wp_get_current_user' ) && current_user_can('update_core') && ( defined('WP_DEBUG') && WP_DEBUG ) && ! defined('DOING_AJAX') && class_exists( 'EE_Registry' )) { |
|
99 | - Kint::dump( EE_Registry::instance()->SSN->id() ); |
|
100 | - Kint::dump( EE_Registry::instance()->SSN ); |
|
98 | + if (class_exists('Kint') && function_exists('wp_get_current_user') && current_user_can('update_core') && (defined('WP_DEBUG') && WP_DEBUG) && ! defined('DOING_AJAX') && class_exists('EE_Registry')) { |
|
99 | + Kint::dump(EE_Registry::instance()->SSN->id()); |
|
100 | + Kint::dump(EE_Registry::instance()->SSN); |
|
101 | 101 | // Kint::dump( EE_Registry::instance()->SSN->get_session_data('cart')->get_tickets() ); |
102 | 102 | $this->espresso_list_hooked_functions(); |
103 | 103 | $this->show_times(); |
@@ -114,27 +114,27 @@ discard block |
||
114 | 114 | * @param bool $tag |
115 | 115 | * @return void |
116 | 116 | */ |
117 | - public function espresso_list_hooked_functions( $tag=FALSE ){ |
|
117 | + public function espresso_list_hooked_functions($tag = FALSE) { |
|
118 | 118 | global $wp_filter; |
119 | 119 | echo '<br/><br/><br/><h3>Hooked Functions</h3>'; |
120 | - if ( $tag ) { |
|
121 | - $hook[$tag]=$wp_filter[$tag]; |
|
122 | - if ( ! is_array( $hook[$tag] )) { |
|
123 | - trigger_error( "Nothing found for '$tag' hook", E_USER_WARNING ); |
|
120 | + if ($tag) { |
|
121 | + $hook[$tag] = $wp_filter[$tag]; |
|
122 | + if ( ! is_array($hook[$tag])) { |
|
123 | + trigger_error("Nothing found for '$tag' hook", E_USER_WARNING); |
|
124 | 124 | return; |
125 | 125 | } |
126 | - echo '<h5>For Tag: '. $tag .'</h5>'; |
|
126 | + echo '<h5>For Tag: '.$tag.'</h5>'; |
|
127 | 127 | } |
128 | 128 | else { |
129 | - $hook=$wp_filter; |
|
130 | - ksort( $hook ); |
|
129 | + $hook = $wp_filter; |
|
130 | + ksort($hook); |
|
131 | 131 | } |
132 | - foreach( $hook as $tag => $priorities ) { |
|
132 | + foreach ($hook as $tag => $priorities) { |
|
133 | 133 | echo "<br />>>>>>\t<strong>$tag</strong><br />"; |
134 | - ksort( $priorities ); |
|
135 | - foreach( $priorities as $priority => $function ){ |
|
134 | + ksort($priorities); |
|
135 | + foreach ($priorities as $priority => $function) { |
|
136 | 136 | echo $priority; |
137 | - foreach( $function as $name => $properties ) { |
|
137 | + foreach ($function as $name => $properties) { |
|
138 | 138 | echo "\t$name<br />"; |
139 | 139 | } |
140 | 140 | } |
@@ -150,15 +150,15 @@ discard block |
||
150 | 150 | * @param string $hook_name |
151 | 151 | * @return array |
152 | 152 | */ |
153 | - public static function registered_filter_callbacks( $hook_name = '' ) { |
|
153 | + public static function registered_filter_callbacks($hook_name = '') { |
|
154 | 154 | $filters = array(); |
155 | 155 | global $wp_filter; |
156 | - if ( isset( $wp_filter[ $hook_name ] ) ) { |
|
157 | - $filters[ $hook_name ] = array(); |
|
158 | - foreach ( $wp_filter[ $hook_name ] as $priority => $callbacks ) { |
|
159 | - $filters[ $hook_name ][ $priority ] = array(); |
|
160 | - foreach ( $callbacks as $callback ) { |
|
161 | - $filters[ $hook_name ][ $priority ][] = $callback['function']; |
|
156 | + if (isset($wp_filter[$hook_name])) { |
|
157 | + $filters[$hook_name] = array(); |
|
158 | + foreach ($wp_filter[$hook_name] as $priority => $callbacks) { |
|
159 | + $filters[$hook_name][$priority] = array(); |
|
160 | + foreach ($callbacks as $callback) { |
|
161 | + $filters[$hook_name][$priority][] = $callback['function']; |
|
162 | 162 | } |
163 | 163 | } |
164 | 164 | } |
@@ -171,8 +171,8 @@ discard block |
||
171 | 171 | * start_timer |
172 | 172 | * @param null $timer_name |
173 | 173 | */ |
174 | - public function start_timer( $timer_name = NULL ){ |
|
175 | - $this->_start_times[$timer_name] = microtime( TRUE ); |
|
174 | + public function start_timer($timer_name = NULL) { |
|
175 | + $this->_start_times[$timer_name] = microtime(TRUE); |
|
176 | 176 | } |
177 | 177 | |
178 | 178 | |
@@ -181,15 +181,15 @@ discard block |
||
181 | 181 | * stop_timer |
182 | 182 | * @param string $timer_name |
183 | 183 | */ |
184 | - public function stop_timer($timer_name = 'default'){ |
|
185 | - if( isset( $this->_start_times[ $timer_name ] ) ){ |
|
186 | - $start_time = $this->_start_times[ $timer_name ]; |
|
187 | - unset( $this->_start_times[ $timer_name ] ); |
|
188 | - }else{ |
|
189 | - $start_time = array_pop( $this->_start_times ); |
|
184 | + public function stop_timer($timer_name = 'default') { |
|
185 | + if (isset($this->_start_times[$timer_name])) { |
|
186 | + $start_time = $this->_start_times[$timer_name]; |
|
187 | + unset($this->_start_times[$timer_name]); |
|
188 | + } else { |
|
189 | + $start_time = array_pop($this->_start_times); |
|
190 | 190 | } |
191 | - $total_time = microtime( TRUE ) - $start_time; |
|
192 | - switch ( $total_time ) { |
|
191 | + $total_time = microtime(TRUE) - $start_time; |
|
192 | + switch ($total_time) { |
|
193 | 193 | case $total_time < 0.00001 : |
194 | 194 | $color = '#8A549A'; |
195 | 195 | $bold = 'normal'; |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | $bold = 'bold'; |
216 | 216 | break; |
217 | 217 | } |
218 | - $this->_times[] = '<hr /><div style="display: inline-block; min-width: 10px; margin:0 1em; color:'.$color.'; font-weight:'.$bold.'; font-size:1.2em;">' . number_format( $total_time, 8 ) . '</div> ' . $timer_name; |
|
218 | + $this->_times[] = '<hr /><div style="display: inline-block; min-width: 10px; margin:0 1em; color:'.$color.'; font-weight:'.$bold.'; font-size:1.2em;">'.number_format($total_time, 8).'</div> '.$timer_name; |
|
219 | 219 | } |
220 | 220 | /** |
221 | 221 | * Measure the memory usage by PHP so far. |
@@ -223,10 +223,10 @@ discard block |
||
223 | 223 | * @param boolean $output_now whether to echo now, or wait until EEH_Debug_Tools::show_times() is called |
224 | 224 | * @return void |
225 | 225 | */ |
226 | - public function measure_memory( $label, $output_now = false ) { |
|
227 | - $memory_used = $this->convert( memory_get_peak_usage( true ) ); |
|
228 | - $this->_memory_usage_points[ $label ] = $memory_used; |
|
229 | - if( $output_now ) { |
|
226 | + public function measure_memory($label, $output_now = false) { |
|
227 | + $memory_used = $this->convert(memory_get_peak_usage(true)); |
|
228 | + $this->_memory_usage_points[$label] = $memory_used; |
|
229 | + if ($output_now) { |
|
230 | 230 | echo "\r\n<br>$label : $memory_used"; |
231 | 231 | } |
232 | 232 | } |
@@ -236,9 +236,9 @@ discard block |
||
236 | 236 | * @param int $size |
237 | 237 | * @return string |
238 | 238 | */ |
239 | - public function convert( $size ) { |
|
240 | - $unit=array('b','kb','mb','gb','tb','pb'); |
|
241 | - return @round($size/pow(1024,($i=floor(log($size,1024)))),2).' '.$unit[ absint( $i ) ]; |
|
239 | + public function convert($size) { |
|
240 | + $unit = array('b', 'kb', 'mb', 'gb', 'tb', 'pb'); |
|
241 | + return @round($size / pow(1024, ($i = floor(log($size, 1024)))), 2).' '.$unit[absint($i)]; |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | |
@@ -248,9 +248,9 @@ discard block |
||
248 | 248 | * @param bool $output_now |
249 | 249 | * @return string |
250 | 250 | */ |
251 | - public function show_times($output_now=true){ |
|
252 | - $output = '<h2>Times:</h2>' . implode("<br>",$this->_times) . '<h2>Memory</h2>' . implode('<br>', $this->_memory_usage_points ); |
|
253 | - if($output_now){ |
|
251 | + public function show_times($output_now = true) { |
|
252 | + $output = '<h2>Times:</h2>'.implode("<br>", $this->_times).'<h2>Memory</h2>'.implode('<br>', $this->_memory_usage_points); |
|
253 | + if ($output_now) { |
|
254 | 254 | echo $output; |
255 | 255 | return ''; |
256 | 256 | } |
@@ -265,25 +265,25 @@ discard block |
||
265 | 265 | * @return void |
266 | 266 | */ |
267 | 267 | public static function ee_plugin_activation_errors() { |
268 | - if ( WP_DEBUG ) { |
|
268 | + if (WP_DEBUG) { |
|
269 | 269 | $activation_errors = ob_get_contents(); |
270 | - if ( ! empty( $activation_errors ) ) { |
|
271 | - $activation_errors = date( 'Y-m-d H:i:s' ) . "\n" . $activation_errors; |
|
270 | + if ( ! empty($activation_errors)) { |
|
271 | + $activation_errors = date('Y-m-d H:i:s')."\n".$activation_errors; |
|
272 | 272 | } |
273 | - espresso_load_required( 'EEH_File', EE_HELPERS . 'EEH_File.helper.php' ); |
|
274 | - if ( class_exists( 'EEH_File' )) { |
|
273 | + espresso_load_required('EEH_File', EE_HELPERS.'EEH_File.helper.php'); |
|
274 | + if (class_exists('EEH_File')) { |
|
275 | 275 | try { |
276 | - EEH_File::ensure_file_exists_and_is_writable( EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html' ); |
|
277 | - EEH_File::write_to_file( EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', $activation_errors ); |
|
278 | - } catch( EE_Error $e ){ |
|
279 | - EE_Error::add_error( sprintf( __( 'The Event Espresso activation errors file could not be setup because: %s', 'event_espresso' ), $e->getMessage() ), __FILE__, __FUNCTION__, __LINE__ ); |
|
276 | + EEH_File::ensure_file_exists_and_is_writable(EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html'); |
|
277 | + EEH_File::write_to_file(EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html', $activation_errors); |
|
278 | + } catch (EE_Error $e) { |
|
279 | + EE_Error::add_error(sprintf(__('The Event Espresso activation errors file could not be setup because: %s', 'event_espresso'), $e->getMessage()), __FILE__, __FUNCTION__, __LINE__); |
|
280 | 280 | } |
281 | 281 | } else { |
282 | 282 | // old school attempt |
283 | - file_put_contents( EVENT_ESPRESSO_UPLOAD_DIR . 'logs' . DS . 'espresso_plugin_activation_errors.html', $activation_errors ); |
|
283 | + file_put_contents(EVENT_ESPRESSO_UPLOAD_DIR.'logs'.DS.'espresso_plugin_activation_errors.html', $activation_errors); |
|
284 | 284 | } |
285 | - $activation_errors = get_option( 'ee_plugin_activation_errors', '' ) . $activation_errors; |
|
286 | - update_option( 'ee_plugin_activation_errors', $activation_errors ); |
|
285 | + $activation_errors = get_option('ee_plugin_activation_errors', '').$activation_errors; |
|
286 | + update_option('ee_plugin_activation_errors', $activation_errors); |
|
287 | 287 | } |
288 | 288 | } |
289 | 289 | |
@@ -299,22 +299,22 @@ discard block |
||
299 | 299 | * @param int $error_type |
300 | 300 | * @uses trigger_error() |
301 | 301 | */ |
302 | - public function doing_it_wrong( $function, $message, $version, $error_type = E_USER_NOTICE ) { |
|
303 | - do_action( 'AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version); |
|
304 | - $version = is_null( $version ) ? '' : sprintf( __('(This message was added in version %s of Event Espresso.', 'event_espresso' ), $version ); |
|
305 | - $error_message = sprintf( esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s','event_espresso' ), $function, '<strong>', '</strong>', $message, $version ); |
|
302 | + public function doing_it_wrong($function, $message, $version, $error_type = E_USER_NOTICE) { |
|
303 | + do_action('AHEE__EEH_Debug_Tools__doing_it_wrong_run', $function, $message, $version); |
|
304 | + $version = is_null($version) ? '' : sprintf(__('(This message was added in version %s of Event Espresso.', 'event_espresso'), $version); |
|
305 | + $error_message = sprintf(esc_html__('%1$s was called %2$sincorrectly%3$s. %4$s %5$s', 'event_espresso'), $function, '<strong>', '</strong>', $message, $version); |
|
306 | 306 | |
307 | 307 | //don't trigger error if doing ajax, instead we'll add a transient EE_Error notice that in theory should show on the next request. |
308 | - if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) { |
|
309 | - $error_message .= esc_html__( 'This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', 'event_espresso' ); |
|
308 | + if (defined('DOING_AJAX') && DOING_AJAX) { |
|
309 | + $error_message .= esc_html__('This is a doing_it_wrong message that was triggered during an ajax request. The request params on this request were: ', 'event_espresso'); |
|
310 | 310 | $error_message .= '<ul><li>'; |
311 | - $error_message .= implode( '</li><li>', EE_Registry::instance()->REQ->params() ); |
|
311 | + $error_message .= implode('</li><li>', EE_Registry::instance()->REQ->params()); |
|
312 | 312 | $error_message .= '</ul>'; |
313 | - EE_Error::add_error( $error_message, 'debug::doing_it_wrong', $function, '42' ); |
|
313 | + EE_Error::add_error($error_message, 'debug::doing_it_wrong', $function, '42'); |
|
314 | 314 | //now we set this on the transient so it shows up on the next request. |
315 | - EE_Error::get_notices( is_admin(), true ); |
|
315 | + EE_Error::get_notices(is_admin(), true); |
|
316 | 316 | } else { |
317 | - trigger_error( $error_message, $error_type ); |
|
317 | + trigger_error($error_message, $error_type); |
|
318 | 318 | } |
319 | 319 | } |
320 | 320 | |
@@ -336,22 +336,22 @@ discard block |
||
336 | 336 | * @param string $debug_index |
337 | 337 | * @param string $debug_key |
338 | 338 | */ |
339 | - public static function log( $class='', $func = '', $line = '', $info = array(), $display_request = false, $debug_index = '', $debug_key = 'EE_DEBUG_SPCO' ) { |
|
340 | - if ( WP_DEBUG /*&& false*/ ) { |
|
341 | - $debug_key = $debug_key . '_' . EE_Session::instance()->id(); |
|
342 | - $debug_data = get_option( $debug_key, array() ); |
|
339 | + public static function log($class = '', $func = '', $line = '', $info = array(), $display_request = false, $debug_index = '', $debug_key = 'EE_DEBUG_SPCO') { |
|
340 | + if (WP_DEBUG /*&& false*/) { |
|
341 | + $debug_key = $debug_key.'_'.EE_Session::instance()->id(); |
|
342 | + $debug_data = get_option($debug_key, array()); |
|
343 | 343 | $default_data = array( |
344 | - $class => $func . '() : ' . $line, |
|
344 | + $class => $func.'() : '.$line, |
|
345 | 345 | 'REQ' => $display_request ? $_REQUEST : '', |
346 | 346 | ); |
347 | 347 | // don't serialize objects |
348 | - $info = self::strip_objects( $info ); |
|
349 | - $index = ! empty( $debug_index ) ? $debug_index : 0; |
|
350 | - if ( ! isset( $debug_data[$index] ) ) { |
|
348 | + $info = self::strip_objects($info); |
|
349 | + $index = ! empty($debug_index) ? $debug_index : 0; |
|
350 | + if ( ! isset($debug_data[$index])) { |
|
351 | 351 | $debug_data[$index] = array(); |
352 | 352 | } |
353 | - $debug_data[$index][microtime()] = array_merge( $default_data, $info ); |
|
354 | - update_option( $debug_key, $debug_data ); |
|
353 | + $debug_data[$index][microtime()] = array_merge($default_data, $info); |
|
354 | + update_option($debug_key, $debug_data); |
|
355 | 355 | } |
356 | 356 | } |
357 | 357 | |
@@ -363,26 +363,26 @@ discard block |
||
363 | 363 | * @param array $info |
364 | 364 | * @return array |
365 | 365 | */ |
366 | - public static function strip_objects( $info = array() ) { |
|
367 | - foreach ( $info as $key => $value ) { |
|
368 | - if ( is_array( $value ) ) { |
|
369 | - $info[ $key ] = self::strip_objects( $value ); |
|
370 | - } else if ( is_object( $value ) ) { |
|
371 | - $object_class = get_class( $value ); |
|
372 | - $info[ $object_class ] = array(); |
|
373 | - $info[ $object_class ][ 'ID' ] = method_exists( $value, 'ID' ) ? $value->ID() : spl_object_hash( $value ); |
|
374 | - if ( method_exists( $value, 'ID' ) ) { |
|
375 | - $info[ $object_class ][ 'ID' ] = $value->ID(); |
|
366 | + public static function strip_objects($info = array()) { |
|
367 | + foreach ($info as $key => $value) { |
|
368 | + if (is_array($value)) { |
|
369 | + $info[$key] = self::strip_objects($value); |
|
370 | + } else if (is_object($value)) { |
|
371 | + $object_class = get_class($value); |
|
372 | + $info[$object_class] = array(); |
|
373 | + $info[$object_class]['ID'] = method_exists($value, 'ID') ? $value->ID() : spl_object_hash($value); |
|
374 | + if (method_exists($value, 'ID')) { |
|
375 | + $info[$object_class]['ID'] = $value->ID(); |
|
376 | 376 | } |
377 | - if ( method_exists( $value, 'status' ) ) { |
|
378 | - $info[ $object_class ][ 'status' ] = $value->status(); |
|
379 | - } else if ( method_exists( $value, 'status_ID' ) ) { |
|
380 | - $info[ $object_class ][ 'status' ] = $value->status_ID(); |
|
377 | + if (method_exists($value, 'status')) { |
|
378 | + $info[$object_class]['status'] = $value->status(); |
|
379 | + } else if (method_exists($value, 'status_ID')) { |
|
380 | + $info[$object_class]['status'] = $value->status_ID(); |
|
381 | 381 | } |
382 | - unset( $info[ $key ] ); |
|
382 | + unset($info[$key]); |
|
383 | 383 | } |
384 | 384 | } |
385 | - return (array)$info; |
|
385 | + return (array) $info; |
|
386 | 386 | } |
387 | 387 | |
388 | 388 | |
@@ -399,24 +399,24 @@ discard block |
||
399 | 399 | * @param int $header |
400 | 400 | * @param bool $die |
401 | 401 | */ |
402 | - public static function printv( $var, $var_name = false, $file = __FILE__, $line = __LINE__, $header = 5, $die = false ) { |
|
402 | + public static function printv($var, $var_name = false, $file = __FILE__, $line = __LINE__, $header = 5, $die = false) { |
|
403 | 403 | $var_name = ! $var_name ? 'string' : $var_name; |
404 | 404 | $heading_tag = 'h'; |
405 | - $heading_tag .= is_int( $header ) ? $header : 5; |
|
406 | - $var_name = ucwords( str_replace( '$', '', $var_name ) ); |
|
407 | - $is_method = method_exists( $var_name, $var ); |
|
408 | - $var_name = ucwords( str_replace( '_', ' ', $var_name ) ); |
|
405 | + $heading_tag .= is_int($header) ? $header : 5; |
|
406 | + $var_name = ucwords(str_replace('$', '', $var_name)); |
|
407 | + $is_method = method_exists($var_name, $var); |
|
408 | + $var_name = ucwords(str_replace('_', ' ', $var_name)); |
|
409 | 409 | ob_start(); |
410 | - echo '<' . $heading_tag . ' style="color:#2EA2CC; margin:25px 0 0;"><b>' . $var_name . '</b>'; |
|
410 | + echo '<'.$heading_tag.' style="color:#2EA2CC; margin:25px 0 0;"><b>'.$var_name.'</b>'; |
|
411 | 411 | echo $is_method |
412 | - ? '<span style="color:#999">::</span><span style="color:#E76700">' . $var . '()</span><br />' |
|
413 | - : '<span style="color:#999"> : </span><span style="color:#E76700">' . $var . '</span><br />'; |
|
414 | - echo '<span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' . $file; |
|
415 | - echo '<br />line no: ' . $line . '</span>'; |
|
416 | - echo '</' . $heading_tag . '>'; |
|
412 | + ? '<span style="color:#999">::</span><span style="color:#E76700">'.$var.'()</span><br />' |
|
413 | + : '<span style="color:#999"> : </span><span style="color:#E76700">'.$var.'</span><br />'; |
|
414 | + echo '<span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">'.$file; |
|
415 | + echo '<br />line no: '.$line.'</span>'; |
|
416 | + echo '</'.$heading_tag.'>'; |
|
417 | 417 | $result = ob_get_clean(); |
418 | - if ( $die ) { |
|
419 | - die( $result ); |
|
418 | + if ($die) { |
|
419 | + die($result); |
|
420 | 420 | } else { |
421 | 421 | echo $result; |
422 | 422 | } |
@@ -435,36 +435,36 @@ discard block |
||
435 | 435 | * @param int $header |
436 | 436 | * @param bool $die |
437 | 437 | */ |
438 | - public static function printr( $var, $var_name = false, $file = __FILE__, $line = __LINE__, $header = 5, $die = false ) { |
|
439 | - $file = str_replace( rtrim( ABSPATH, '\\/' ), '', $file ); |
|
438 | + public static function printr($var, $var_name = false, $file = __FILE__, $line = __LINE__, $header = 5, $die = false) { |
|
439 | + $file = str_replace(rtrim(ABSPATH, '\\/'), '', $file); |
|
440 | 440 | //$print_r = false; |
441 | - if ( is_string( $var ) ) { |
|
442 | - EEH_Debug_Tools::printv( $var, $var_name, $file, $line, $header, $die ); |
|
441 | + if (is_string($var)) { |
|
442 | + EEH_Debug_Tools::printv($var, $var_name, $file, $line, $header, $die); |
|
443 | 443 | return; |
444 | - } else if ( is_object( $var ) ) { |
|
444 | + } else if (is_object($var)) { |
|
445 | 445 | $var_name = ! $var_name ? 'object' : $var_name; |
446 | 446 | //$print_r = true; |
447 | - } else if ( is_array( $var ) ) { |
|
447 | + } else if (is_array($var)) { |
|
448 | 448 | $var_name = ! $var_name ? 'array' : $var_name; |
449 | 449 | //$print_r = true; |
450 | - } else if ( is_numeric( $var ) ) { |
|
450 | + } else if (is_numeric($var)) { |
|
451 | 451 | $var_name = ! $var_name ? 'numeric' : $var_name; |
452 | - } else if ( is_null( $var ) ) { |
|
452 | + } else if (is_null($var)) { |
|
453 | 453 | $var_name = ! $var_name ? 'null' : $var_name; |
454 | 454 | } |
455 | 455 | $heading_tag = 'h'; |
456 | - $heading_tag .= is_int( $header ) ? $header : 5; |
|
457 | - $var_name = ucwords( str_replace( array( '$', '_' ), array( '', ' ' ), $var_name ) ); |
|
456 | + $heading_tag .= is_int($header) ? $header : 5; |
|
457 | + $var_name = ucwords(str_replace(array('$', '_'), array('', ' '), $var_name)); |
|
458 | 458 | ob_start(); |
459 | - echo '<' . $heading_tag . ' style="color:#2EA2CC; margin:25px 0 0;"><b>' . $var_name . '</b>'; |
|
459 | + echo '<'.$heading_tag.' style="color:#2EA2CC; margin:25px 0 0;"><b>'.$var_name.'</b>'; |
|
460 | 460 | echo '<span style="color:#999;"> : </span><span style="color:#E76700;">'; |
461 | 461 | echo '<pre style="color:#999; padding:1em; background: #fff">'; |
462 | - var_dump( $var ); |
|
463 | - echo '</pre></span><br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">' . $file; |
|
464 | - echo '<br />line no: ' . $line . '</span></' . $heading_tag . '>'; |
|
462 | + var_dump($var); |
|
463 | + echo '</pre></span><br /><span style="font-size:9px;font-weight:normal;color:#666;line-height: 12px;">'.$file; |
|
464 | + echo '<br />line no: '.$line.'</span></'.$heading_tag.'>'; |
|
465 | 465 | $result = ob_get_clean(); |
466 | - if ( $die ) { |
|
467 | - die( $result ); |
|
466 | + if ($die) { |
|
467 | + die($result); |
|
468 | 468 | } else { |
469 | 469 | echo $result; |
470 | 470 | } |
@@ -481,8 +481,8 @@ discard block |
||
481 | 481 | * borrowed from Kint Debugger |
482 | 482 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
483 | 483 | */ |
484 | -if ( class_exists('Kint') && ! function_exists( 'dump_wp_query' ) ) { |
|
485 | - function dump_wp_query(){ |
|
484 | +if (class_exists('Kint') && ! function_exists('dump_wp_query')) { |
|
485 | + function dump_wp_query() { |
|
486 | 486 | global $wp_query; |
487 | 487 | d($wp_query); |
488 | 488 | } |
@@ -492,8 +492,8 @@ discard block |
||
492 | 492 | * borrowed from Kint Debugger |
493 | 493 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
494 | 494 | */ |
495 | -if ( class_exists('Kint') && ! function_exists( 'dump_wp' ) ) { |
|
496 | - function dump_wp(){ |
|
495 | +if (class_exists('Kint') && ! function_exists('dump_wp')) { |
|
496 | + function dump_wp() { |
|
497 | 497 | global $wp; |
498 | 498 | d($wp); |
499 | 499 | } |
@@ -503,8 +503,8 @@ discard block |
||
503 | 503 | * borrowed from Kint Debugger |
504 | 504 | * Plugin URI: http://upthemes.com/plugins/kint-debugger/ |
505 | 505 | */ |
506 | -if ( class_exists('Kint') && ! function_exists( 'dump_post' ) ) { |
|
507 | - function dump_post(){ |
|
506 | +if (class_exists('Kint') && ! function_exists('dump_post')) { |
|
507 | + function dump_post() { |
|
508 | 508 | global $post; |
509 | 509 | d($post); |
510 | 510 | } |
@@ -21,8 +21,8 @@ discard block |
||
21 | 21 | * |
22 | 22 | * ------------------------------------------------------------------------ |
23 | 23 | */ |
24 | -require_once ( EE_MODELS . 'EEM_Soft_Delete_Base.model.php' ); |
|
25 | -require_once ( EE_CLASSES . 'EE_Datetime.class.php' ); |
|
24 | +require_once (EE_MODELS.'EEM_Soft_Delete_Base.model.php'); |
|
25 | +require_once (EE_CLASSES.'EE_Datetime.class.php'); |
|
26 | 26 | |
27 | 27 | class EEM_Datetime extends EEM_Soft_Delete_Base { |
28 | 28 | |
@@ -35,28 +35,28 @@ discard block |
||
35 | 35 | * @access private |
36 | 36 | * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
37 | 37 | */ |
38 | - protected function __construct( $timezone ) { |
|
39 | - $this->singular_item = __('Datetime','event_espresso'); |
|
40 | - $this->plural_item = __('Datetimes','event_espresso'); |
|
38 | + protected function __construct($timezone) { |
|
39 | + $this->singular_item = __('Datetime', 'event_espresso'); |
|
40 | + $this->plural_item = __('Datetimes', 'event_espresso'); |
|
41 | 41 | |
42 | 42 | $this->_tables = array( |
43 | 43 | 'Datetime'=> new EE_Primary_Table('esp_datetime', 'DTT_ID') |
44 | 44 | ); |
45 | 45 | $this->_fields = array( |
46 | 46 | 'Datetime'=>array( |
47 | - 'DTT_ID'=> new EE_Primary_Key_Int_Field('DTT_ID', __('Datetime ID','event_espresso')), |
|
48 | - 'EVT_ID'=>new EE_Foreign_Key_Int_Field('EVT_ID', __('Event ID','event_espresso'), false, 0, 'Event'), |
|
47 | + 'DTT_ID'=> new EE_Primary_Key_Int_Field('DTT_ID', __('Datetime ID', 'event_espresso')), |
|
48 | + 'EVT_ID'=>new EE_Foreign_Key_Int_Field('EVT_ID', __('Event ID', 'event_espresso'), false, 0, 'Event'), |
|
49 | 49 | 'DTT_name' => new EE_Plain_Text_Field('DTT_name', __('Datetime Name', 'event_espresso'), false, ''), |
50 | 50 | 'DTT_description' => new EE_Full_HTML_Field('DTT_description', __('Description for Datetime', 'event_espresso'), false, ''), |
51 | - 'DTT_EVT_start'=>new EE_Datetime_Field('DTT_EVT_start', __('Start time/date of Event','event_espresso'), false, time(), $timezone ), |
|
52 | - 'DTT_EVT_end'=>new EE_Datetime_Field('DTT_EVT_end', __('End time/date of Event','event_espresso'), false, time(), $timezone ), |
|
53 | - 'DTT_reg_limit'=>new EE_Infinite_Integer_Field('DTT_reg_limit', __('Registration Limit for this time','event_espresso'), true, EE_INF), |
|
54 | - 'DTT_sold'=>new EE_Integer_Field('DTT_sold', __('How many sales for this Datetime that have occurred', 'event_espresso'), true, 0 ), |
|
55 | - 'DTT_reserved' => new EE_Integer_Field('DTT_reserved',__('Quantity of tickets that are reserved, but not yet fully purchased','event_espresso'),false,0), |
|
56 | - 'DTT_is_primary'=>new EE_Boolean_Field('DTT_is_primary', __("Flag indicating datetime is primary one for event", "event_espresso"), false,false), |
|
51 | + 'DTT_EVT_start'=>new EE_Datetime_Field('DTT_EVT_start', __('Start time/date of Event', 'event_espresso'), false, time(), $timezone), |
|
52 | + 'DTT_EVT_end'=>new EE_Datetime_Field('DTT_EVT_end', __('End time/date of Event', 'event_espresso'), false, time(), $timezone), |
|
53 | + 'DTT_reg_limit'=>new EE_Infinite_Integer_Field('DTT_reg_limit', __('Registration Limit for this time', 'event_espresso'), true, EE_INF), |
|
54 | + 'DTT_sold'=>new EE_Integer_Field('DTT_sold', __('How many sales for this Datetime that have occurred', 'event_espresso'), true, 0), |
|
55 | + 'DTT_reserved' => new EE_Integer_Field('DTT_reserved', __('Quantity of tickets that are reserved, but not yet fully purchased', 'event_espresso'), false, 0), |
|
56 | + 'DTT_is_primary'=>new EE_Boolean_Field('DTT_is_primary', __("Flag indicating datetime is primary one for event", "event_espresso"), false, false), |
|
57 | 57 | 'DTT_order' => new EE_Integer_Field('DTT_order', __('The order in which the Datetime is displayed', 'event_espresso'), false, 0), |
58 | - 'DTT_parent' => new EE_Integer_Field('DTT_parent', __('Indicates what DTT_ID is the parent of this DTT_ID'), true, 0 ), |
|
59 | - 'DTT_deleted' => new EE_Trashed_Flag_Field('DTT_deleted', __('Flag indicating datetime is archived', 'event_espresso'), false, false ), |
|
58 | + 'DTT_parent' => new EE_Integer_Field('DTT_parent', __('Indicates what DTT_ID is the parent of this DTT_ID'), true, 0), |
|
59 | + 'DTT_deleted' => new EE_Trashed_Flag_Field('DTT_deleted', __('Flag indicating datetime is archived', 'event_espresso'), false, false), |
|
60 | 60 | )); |
61 | 61 | $this->_model_relations = array( |
62 | 62 | 'Ticket'=>new EE_HABTM_Relation('Datetime_Ticket'), |
@@ -65,11 +65,11 @@ discard block |
||
65 | 65 | ); |
66 | 66 | $this->_model_chain_to_wp_user = 'Event'; |
67 | 67 | //this model is generally available for reading |
68 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public( 'Event' ); |
|
69 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected( 'Event' ); |
|
70 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected( 'Event' ); |
|
71 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected( 'Event', EEM_Base::caps_edit ); |
|
72 | - parent::__construct( $timezone ); |
|
68 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public('Event'); |
|
69 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected('Event'); |
|
70 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected('Event'); |
|
71 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected('Event', EEM_Base::caps_edit); |
|
72 | + parent::__construct($timezone); |
|
73 | 73 | } |
74 | 74 | |
75 | 75 | |
@@ -84,16 +84,16 @@ discard block |
||
84 | 84 | public function create_new_blank_datetime() { |
85 | 85 | $blank_datetime = EE_Datetime::new_instance( |
86 | 86 | array( |
87 | - 'DTT_EVT_start' => $this->current_time_for_query( 'DTT_EVT_start', true ) + (60 * 60 * 24 * 30), |
|
88 | - 'DTT_EVT_end' => $this->current_time_for_query( 'DTT_EVT_end', true ) + (60 * 60 * 24 * 30), |
|
87 | + 'DTT_EVT_start' => $this->current_time_for_query('DTT_EVT_start', true) + (60 * 60 * 24 * 30), |
|
88 | + 'DTT_EVT_end' => $this->current_time_for_query('DTT_EVT_end', true) + (60 * 60 * 24 * 30), |
|
89 | 89 | 'DTT_order' => 1, |
90 | 90 | 'DTT_reg_limit' => EE_INF |
91 | 91 | ), |
92 | 92 | $this->_timezone |
93 | 93 | ); |
94 | - $blank_datetime->set_start_time( $this->convert_datetime_for_query( 'DTT_EVT_start', '8am', 'ga', $this->_timezone ) ); |
|
95 | - $blank_datetime->set_end_time( $this->convert_datetime_for_query( 'DTT_EVT_end', '5pm', 'ga', $this->_timezone ) ); |
|
96 | - return array( $blank_datetime ); |
|
94 | + $blank_datetime->set_start_time($this->convert_datetime_for_query('DTT_EVT_start', '8am', 'ga', $this->_timezone)); |
|
95 | + $blank_datetime->set_end_time($this->convert_datetime_for_query('DTT_EVT_end', '5pm', 'ga', $this->_timezone)); |
|
96 | + return array($blank_datetime); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | |
@@ -107,13 +107,13 @@ discard block |
||
107 | 107 | * @param int $EVT_ID |
108 | 108 | * @return EE_Datetime[] array on success, FALSE on fail |
109 | 109 | */ |
110 | - public function get_all_event_dates( $EVT_ID = 0 ) { |
|
111 | - if ( ! $EVT_ID ) { // on add_new_event event_id gets set to 0 |
|
110 | + public function get_all_event_dates($EVT_ID = 0) { |
|
111 | + if ( ! $EVT_ID) { // on add_new_event event_id gets set to 0 |
|
112 | 112 | return $this->create_new_blank_datetime(); |
113 | 113 | } |
114 | - $results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID); |
|
114 | + $results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID); |
|
115 | 115 | |
116 | - if ( empty( $results ) ) { |
|
116 | + if (empty($results)) { |
|
117 | 117 | return $this->create_new_blank_datetime(); |
118 | 118 | } |
119 | 119 | |
@@ -134,26 +134,26 @@ discard block |
||
134 | 134 | * the given number |
135 | 135 | * @return EE_Datetime[] |
136 | 136 | */ |
137 | - public function get_datetimes_for_event_ordered_by_DTT_order( $EVT_ID, $include_expired = TRUE, $include_deleted= TRUE, $limit = NULL ) { |
|
137 | + public function get_datetimes_for_event_ordered_by_DTT_order($EVT_ID, $include_expired = TRUE, $include_deleted = TRUE, $limit = NULL) { |
|
138 | 138 | |
139 | 139 | //sanitize EVT_ID |
140 | - $EVT_ID = intval( $EVT_ID ); |
|
140 | + $EVT_ID = intval($EVT_ID); |
|
141 | 141 | |
142 | 142 | $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
143 | - $this->assume_values_already_prepared_by_model_object( EEM_Base::prepared_for_use_in_db ); |
|
144 | - $where_params = array( 'Event.EVT_ID' => $EVT_ID ); |
|
143 | + $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
144 | + $where_params = array('Event.EVT_ID' => $EVT_ID); |
|
145 | 145 | |
146 | - $query_params = ! empty( $limit ) ? array( $where_params, 'limit' => $limit, 'order_by' => array( 'DTT_order' => 'ASC' ), 'default_where_conditions' => 'none' ) : array( $where_params, 'order_by' => array( 'DTT_order' => 'ASC' ), 'default_where_conditions' => 'none' ); |
|
146 | + $query_params = ! empty($limit) ? array($where_params, 'limit' => $limit, 'order_by' => array('DTT_order' => 'ASC'), 'default_where_conditions' => 'none') : array($where_params, 'order_by' => array('DTT_order' => 'ASC'), 'default_where_conditions' => 'none'); |
|
147 | 147 | |
148 | - if( ! $include_expired){ |
|
149 | - $query_params[0]['DTT_EVT_end'] = array( '>=', current_time( 'mysql', TRUE ) ); |
|
148 | + if ( ! $include_expired) { |
|
149 | + $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', TRUE)); |
|
150 | 150 | } |
151 | - if( $include_deleted){ |
|
152 | - $query_params[0]['DTT_deleted'] = array( 'IN', array( TRUE, FALSE )); |
|
151 | + if ($include_deleted) { |
|
152 | + $query_params[0]['DTT_deleted'] = array('IN', array(TRUE, FALSE)); |
|
153 | 153 | } |
154 | 154 | |
155 | - $result = $this->get_all( $query_params ); |
|
156 | - $this->assume_values_already_prepared_by_model_object( $old_assumption ); |
|
155 | + $result = $this->get_all($query_params); |
|
156 | + $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
157 | 157 | return $result; |
158 | 158 | } |
159 | 159 | |
@@ -168,8 +168,8 @@ discard block |
||
168 | 168 | * @param int $limit |
169 | 169 | * @return EE_Datetime[] |
170 | 170 | */ |
171 | - public function get_datetimes_for_event_ordered_by_importance( $EVT_ID = 0, $limit = NULL){ |
|
172 | - return $this->get_all( array(array('Event.EVT_ID'=>$EVT_ID), |
|
171 | + public function get_datetimes_for_event_ordered_by_importance($EVT_ID = 0, $limit = NULL) { |
|
172 | + return $this->get_all(array(array('Event.EVT_ID'=>$EVT_ID), |
|
173 | 173 | 'limit'=>$limit, |
174 | 174 | 'order_by'=>array('DTT_EVT_start'=>'ASC'), |
175 | 175 | 'default_where_conditions' => 'none')); |
@@ -184,11 +184,11 @@ discard block |
||
184 | 184 | * @param boolean $include_deleted |
185 | 185 | * @return EE_Datetime |
186 | 186 | */ |
187 | - public function get_oldest_datetime_for_event($EVT_ID, $include_expired = false,$include_deleted = false){ |
|
188 | - $results = $this->get_datetimes_for_event_ordered_by_start_time($EVT_ID, $include_expired, $include_deleted, 1); |
|
189 | - if($results){ |
|
187 | + public function get_oldest_datetime_for_event($EVT_ID, $include_expired = false, $include_deleted = false) { |
|
188 | + $results = $this->get_datetimes_for_event_ordered_by_start_time($EVT_ID, $include_expired, $include_deleted, 1); |
|
189 | + if ($results) { |
|
190 | 190 | return array_shift($results); |
191 | - }else{ |
|
191 | + } else { |
|
192 | 192 | return NULL; |
193 | 193 | } |
194 | 194 | } |
@@ -202,16 +202,16 @@ discard block |
||
202 | 202 | * @param bool $try_to_exclude_deleted |
203 | 203 | * @return \EE_Datetime |
204 | 204 | */ |
205 | - public function get_primary_datetime_for_event($EVT_ID,$try_to_exclude_expired = true, $try_to_exclude_deleted = true){ |
|
206 | - if($try_to_exclude_expired){ |
|
207 | - $non_expired = $this->get_oldest_datetime_for_event($EVT_ID, false,false); |
|
208 | - if($non_expired){ |
|
205 | + public function get_primary_datetime_for_event($EVT_ID, $try_to_exclude_expired = true, $try_to_exclude_deleted = true) { |
|
206 | + if ($try_to_exclude_expired) { |
|
207 | + $non_expired = $this->get_oldest_datetime_for_event($EVT_ID, false, false); |
|
208 | + if ($non_expired) { |
|
209 | 209 | return $non_expired; |
210 | 210 | } |
211 | 211 | } |
212 | - if($try_to_exclude_deleted){ |
|
212 | + if ($try_to_exclude_deleted) { |
|
213 | 213 | $expired_even = $this->get_oldest_datetime_for_event($EVT_ID, true); |
214 | - if($expired_even){ |
|
214 | + if ($expired_even) { |
|
215 | 215 | return $expired_even; |
216 | 216 | } |
217 | 217 | } |
@@ -230,23 +230,23 @@ discard block |
||
230 | 230 | * @param int $limit |
231 | 231 | * @return EE_Datetime[] |
232 | 232 | */ |
233 | - public function get_datetimes_for_event_ordered_by_start_time($EVT_ID, $include_expired = true, $include_deleted= true, $limit = NULL ){ |
|
233 | + public function get_datetimes_for_event_ordered_by_start_time($EVT_ID, $include_expired = true, $include_deleted = true, $limit = NULL) { |
|
234 | 234 | //sanitize EVT_ID |
235 | - $EVT_ID = intval( $EVT_ID ); |
|
235 | + $EVT_ID = intval($EVT_ID); |
|
236 | 236 | $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
237 | - $this->assume_values_already_prepared_by_model_object( EEM_Base::prepared_for_use_in_db ); |
|
238 | - $query_params =array(array('Event.EVT_ID'=>$EVT_ID),'order_by'=>array('DTT_EVT_start'=>'asc')); |
|
239 | - if( ! $include_expired){ |
|
240 | - $query_params[0]['DTT_EVT_end'] = array('>=',current_time('mysql', TRUE)); |
|
237 | + $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
238 | + $query_params = array(array('Event.EVT_ID'=>$EVT_ID), 'order_by'=>array('DTT_EVT_start'=>'asc')); |
|
239 | + if ( ! $include_expired) { |
|
240 | + $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', TRUE)); |
|
241 | 241 | } |
242 | - if( $include_deleted){ |
|
243 | - $query_params[0]['DTT_deleted'] = array('IN',array(true,false)); |
|
242 | + if ($include_deleted) { |
|
243 | + $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
244 | 244 | } |
245 | - if($limit){ |
|
245 | + if ($limit) { |
|
246 | 246 | $query_params['limit'] = $limit; |
247 | 247 | } |
248 | - $result = $this->get_all( $query_params ); |
|
249 | - $this->assume_values_already_prepared_by_model_object( $old_assumption ); |
|
248 | + $result = $this->get_all($query_params); |
|
249 | + $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
250 | 250 | return $result; |
251 | 251 | } |
252 | 252 | |
@@ -259,23 +259,23 @@ discard block |
||
259 | 259 | * @param int $limit |
260 | 260 | * @return EE_Datetime[] |
261 | 261 | */ |
262 | - public function get_datetimes_for_ticket_ordered_by_start_time($TKT_ID, $include_expired = true, $include_deleted= true, $limit = NULL){ |
|
262 | + public function get_datetimes_for_ticket_ordered_by_start_time($TKT_ID, $include_expired = true, $include_deleted = true, $limit = NULL) { |
|
263 | 263 | //sanitize TKT_ID |
264 | - $TKT_ID = intval( $TKT_ID ); |
|
264 | + $TKT_ID = intval($TKT_ID); |
|
265 | 265 | $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
266 | - $this->assume_values_already_prepared_by_model_object( EEM_Base::prepared_for_use_in_db ); |
|
267 | - $query_params =array(array('Ticket.TKT_ID'=>$TKT_ID),'order_by'=>array('DTT_EVT_start'=>'asc')); |
|
268 | - if( ! $include_expired){ |
|
269 | - $query_params[0]['DTT_EVT_end'] = array('>=',current_time('mysql', TRUE)); |
|
266 | + $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
267 | + $query_params = array(array('Ticket.TKT_ID'=>$TKT_ID), 'order_by'=>array('DTT_EVT_start'=>'asc')); |
|
268 | + if ( ! $include_expired) { |
|
269 | + $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', TRUE)); |
|
270 | 270 | } |
271 | - if( $include_deleted){ |
|
272 | - $query_params[0]['DTT_deleted'] = array('IN',array(true,false)); |
|
271 | + if ($include_deleted) { |
|
272 | + $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
273 | 273 | } |
274 | - if($limit){ |
|
274 | + if ($limit) { |
|
275 | 275 | $query_params['limit'] = $limit; |
276 | 276 | } |
277 | - $result = $this->get_all( $query_params ); |
|
278 | - $this->assume_values_already_prepared_by_model_object( $old_assumption ); |
|
277 | + $result = $this->get_all($query_params); |
|
278 | + $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
279 | 279 | return $result; |
280 | 280 | } |
281 | 281 | |
@@ -291,24 +291,24 @@ discard block |
||
291 | 291 | * that number |
292 | 292 | * @return EE_Datetime[] |
293 | 293 | */ |
294 | - public function get_datetimes_for_ticket_ordered_by_DTT_order( $TKT_ID, $include_expired = true, $include_deleted = true, $limit = NULL ) { |
|
294 | + public function get_datetimes_for_ticket_ordered_by_DTT_order($TKT_ID, $include_expired = true, $include_deleted = true, $limit = NULL) { |
|
295 | 295 | //sanitize id. |
296 | - $TKT_ID = intval( $TKT_ID ); |
|
296 | + $TKT_ID = intval($TKT_ID); |
|
297 | 297 | $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
298 | - $this->assume_values_already_prepared_by_model_object( EEM_Base::prepared_for_use_in_db ); |
|
299 | - $where_params = array( 'Ticket.TKT_ID' => $TKT_ID ); |
|
300 | - $query_params = array( $where_params, 'order_by' => array( 'DTT_order' => 'ASC' ) ); |
|
301 | - if( ! $include_expired){ |
|
302 | - $query_params[0]['DTT_EVT_end'] = array('>=',current_time('mysql', TRUE)); |
|
298 | + $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
299 | + $where_params = array('Ticket.TKT_ID' => $TKT_ID); |
|
300 | + $query_params = array($where_params, 'order_by' => array('DTT_order' => 'ASC')); |
|
301 | + if ( ! $include_expired) { |
|
302 | + $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', TRUE)); |
|
303 | 303 | } |
304 | - if( $include_deleted){ |
|
305 | - $query_params[0]['DTT_deleted'] = array('IN',array(true,false)); |
|
304 | + if ($include_deleted) { |
|
305 | + $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
306 | 306 | } |
307 | - if($limit){ |
|
307 | + if ($limit) { |
|
308 | 308 | $query_params['limit'] = $limit; |
309 | 309 | } |
310 | - $result = $this->get_all( $query_params ); |
|
311 | - $this->assume_values_already_prepared_by_model_object( $old_assumption ); |
|
310 | + $result = $this->get_all($query_params); |
|
311 | + $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
312 | 312 | return $result; |
313 | 313 | } |
314 | 314 | |
@@ -319,11 +319,11 @@ discard block |
||
319 | 319 | * @param int $EVT_ID |
320 | 320 | * @return EE_Datetime |
321 | 321 | */ |
322 | - public function get_most_important_datetime_for_event($EVT_ID){ |
|
322 | + public function get_most_important_datetime_for_event($EVT_ID) { |
|
323 | 323 | $results = $this->get_datetimes_for_event_ordered_by_importance($EVT_ID, 1); |
324 | - if($results){ |
|
324 | + if ($results) { |
|
325 | 325 | return array_shift($results); |
326 | - }else{ |
|
326 | + } else { |
|
327 | 327 | return null; |
328 | 328 | } |
329 | 329 | } |
@@ -342,78 +342,78 @@ discard block |
||
342 | 342 | * - inactive = Events that are either not published. |
343 | 343 | * @return wpdb results array |
344 | 344 | */ |
345 | - public function get_dtt_months_and_years( $where_params, $evt_active_status = '' ) { |
|
346 | - $current_time_for_DTT_EVT_start = $this->current_time_for_query( 'DTT_EVT_start' ); |
|
347 | - $current_time_for_DTT_EVT_end = $this->current_time_for_query( 'DTT_EVT_end' ); |
|
345 | + public function get_dtt_months_and_years($where_params, $evt_active_status = '') { |
|
346 | + $current_time_for_DTT_EVT_start = $this->current_time_for_query('DTT_EVT_start'); |
|
347 | + $current_time_for_DTT_EVT_end = $this->current_time_for_query('DTT_EVT_end'); |
|
348 | 348 | |
349 | - switch ( $evt_active_status ) { |
|
349 | + switch ($evt_active_status) { |
|
350 | 350 | case 'upcoming' : |
351 | 351 | $where_params['Event.status'] = 'publish'; |
352 | 352 | //if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
353 | - if ( isset( $where_params['DTT_EVT_start'] ) ) { |
|
353 | + if (isset($where_params['DTT_EVT_start'])) { |
|
354 | 354 | $where_params['DTT_EVT_start*****'] = $where_params['DTT_EVT_start']; |
355 | 355 | } |
356 | - $where_params['DTT_EVT_start'] = array('>', $current_time_for_DTT_EVT_start ); |
|
356 | + $where_params['DTT_EVT_start'] = array('>', $current_time_for_DTT_EVT_start); |
|
357 | 357 | break; |
358 | 358 | |
359 | 359 | case 'expired' : |
360 | - if ( isset( $where_params['Event.status'] ) ) unset( $where_params['Event.status'] ); |
|
360 | + if (isset($where_params['Event.status'])) unset($where_params['Event.status']); |
|
361 | 361 | //get events to exclude |
362 | - $exclude_query[0] = array_merge( $where_params, array( 'DTT_EVT_end' => array( '>', $current_time_for_DTT_EVT_end ) ) ); |
|
362 | + $exclude_query[0] = array_merge($where_params, array('DTT_EVT_end' => array('>', $current_time_for_DTT_EVT_end))); |
|
363 | 363 | //first get all events that have datetimes where its not expired. |
364 | - $event_ids = $this->_get_all_wpdb_results( $exclude_query, OBJECT_K, 'Datetime.EVT_ID' ); |
|
365 | - $event_ids = array_keys( $event_ids ); |
|
364 | + $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Datetime.EVT_ID'); |
|
365 | + $event_ids = array_keys($event_ids); |
|
366 | 366 | |
367 | - if ( isset( $where_params['DTT_EVT_end'] ) ) { |
|
367 | + if (isset($where_params['DTT_EVT_end'])) { |
|
368 | 368 | $where_params['DTT_EVT_end****'] = $where_params['DTT_EVT_end']; |
369 | 369 | } |
370 | - $where_params['DTT_EVT_end'] = array( '<', $current_time_for_DTT_EVT_end ); |
|
371 | - $where_params['Event.EVT_ID'] = array( 'NOT IN', $event_ids ); |
|
370 | + $where_params['DTT_EVT_end'] = array('<', $current_time_for_DTT_EVT_end); |
|
371 | + $where_params['Event.EVT_ID'] = array('NOT IN', $event_ids); |
|
372 | 372 | break; |
373 | 373 | |
374 | 374 | case 'active' : |
375 | 375 | $where_params['Event.status'] = 'publish'; |
376 | - if ( isset( $where_params['DTT_EVT_start'] ) ) { |
|
376 | + if (isset($where_params['DTT_EVT_start'])) { |
|
377 | 377 | $where_params['Datetime.DTT_EVT_start******'] = $where_params['DTT_EVT_start']; |
378 | 378 | } |
379 | - if ( isset( $where_params['Datetime.DTT_EVT_end'] ) ) { |
|
379 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
380 | 380 | $where_params['Datetime.DTT_EVT_end*****'] = $where_params['DTT_EVT_end']; |
381 | 381 | } |
382 | - $where_params['DTT_EVT_start'] = array('<', $current_time_for_DTT_EVT_start ); |
|
383 | - $where_params['DTT_EVT_end'] = array('>', $current_time_for_DTT_EVT_end ); |
|
382 | + $where_params['DTT_EVT_start'] = array('<', $current_time_for_DTT_EVT_start); |
|
383 | + $where_params['DTT_EVT_end'] = array('>', $current_time_for_DTT_EVT_end); |
|
384 | 384 | break; |
385 | 385 | |
386 | 386 | case 'inactive' : |
387 | - if ( isset( $where_params['Event.status'] ) ) unset( $where_params['Event.status'] ); |
|
388 | - if ( isset( $where_params['OR'] ) ) { |
|
387 | + if (isset($where_params['Event.status'])) unset($where_params['Event.status']); |
|
388 | + if (isset($where_params['OR'])) { |
|
389 | 389 | $where_params['AND']['OR'] = $where_params['OR']; |
390 | 390 | } |
391 | - if ( isset( $where_params['DTT_EVT_end'] ) ) { |
|
391 | + if (isset($where_params['DTT_EVT_end'])) { |
|
392 | 392 | $where_params['AND']['DTT_EVT_end****'] = $where_params['DTT_EVT_end']; |
393 | - unset( $where_params['DTT_EVT_end'] ); |
|
393 | + unset($where_params['DTT_EVT_end']); |
|
394 | 394 | } |
395 | 395 | |
396 | - if ( isset( $where_params['DTT_EVT_start'] ) ) { |
|
396 | + if (isset($where_params['DTT_EVT_start'])) { |
|
397 | 397 | $where_params['AND']['DTT_EVT_start'] = $where_params['DTT_EVT_start']; |
398 | - unset( $where_params['DTT_EVT_start'] ); |
|
398 | + unset($where_params['DTT_EVT_start']); |
|
399 | 399 | } |
400 | - $where_params['AND']['Event.status'] = array( '!=', 'publish' ); |
|
400 | + $where_params['AND']['Event.status'] = array('!=', 'publish'); |
|
401 | 401 | break; |
402 | 402 | } |
403 | 403 | |
404 | 404 | $query_params[0] = $where_params; |
405 | 405 | $query_params['group_by'] = array('dtt_year', 'dtt_month'); |
406 | - $query_params['order_by'] = array( 'DTT_EVT_start' => 'DESC' ); |
|
406 | + $query_params['order_by'] = array('DTT_EVT_start' => 'DESC'); |
|
407 | 407 | |
408 | - EE_Registry::instance()->load_helper( 'DTT_Helper' ); |
|
409 | - $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset( $this->get_timezone(), 'DTT_EVT_start' ); |
|
408 | + EE_Registry::instance()->load_helper('DTT_Helper'); |
|
409 | + $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'DTT_EVT_start'); |
|
410 | 410 | |
411 | 411 | $columns_to_select = array( |
412 | - 'dtt_year' => array('YEAR(' . $query_interval . ')', '%s'), |
|
413 | - 'dtt_month' => array('MONTHNAME(' . $query_interval . ')', '%s'), |
|
414 | - 'dtt_month_num' => array('MONTH(' . $query_interval .')', '%s') |
|
412 | + 'dtt_year' => array('YEAR('.$query_interval.')', '%s'), |
|
413 | + 'dtt_month' => array('MONTHNAME('.$query_interval.')', '%s'), |
|
414 | + 'dtt_month_num' => array('MONTH('.$query_interval.')', '%s') |
|
415 | 415 | ); |
416 | - return $this->_get_all_wpdb_results( $query_params, OBJECT, $columns_to_select ); |
|
416 | + return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select); |
|
417 | 417 | } |
418 | 418 | |
419 | 419 | /** |
@@ -421,8 +421,8 @@ discard block |
||
421 | 421 | * for the tickets for each datetime) |
422 | 422 | * @param EE_Datetime[] $datetimes |
423 | 423 | */ |
424 | - public function update_sold($datetimes){ |
|
425 | - foreach($datetimes as $datetime){ |
|
424 | + public function update_sold($datetimes) { |
|
425 | + foreach ($datetimes as $datetime) { |
|
426 | 426 | $datetime->update_sold(); |
427 | 427 | } |
428 | 428 | } |
@@ -437,10 +437,10 @@ discard block |
||
437 | 437 | * @param array $query_params |
438 | 438 | * @return int of tickets available. If sold out, return less than 1. If infinite, returns EE_INF, IF there are NO tickets attached to datetime then FALSE is returned. |
439 | 439 | */ |
440 | - public function sum_tickets_currently_available_at_datetime( $DTT_ID, $query_params = array() ) { |
|
441 | - $datetime = $this->get_one_by_ID( $DTT_ID ); |
|
442 | - if ( $datetime instanceof EE_Datetime ) { |
|
443 | - return $datetime->tickets_remaining( $query_params ); |
|
440 | + public function sum_tickets_currently_available_at_datetime($DTT_ID, $query_params = array()) { |
|
441 | + $datetime = $this->get_one_by_ID($DTT_ID); |
|
442 | + if ($datetime instanceof EE_Datetime) { |
|
443 | + return $datetime->tickets_remaining($query_params); |
|
444 | 444 | } |
445 | 445 | return 0; |
446 | 446 | } |
@@ -462,36 +462,36 @@ discard block |
||
462 | 462 | * EE_Datetime::upcoming |
463 | 463 | * EE_Datetime::expired |
464 | 464 | */ |
465 | - public function get_datetime_counts_by_status( $stati_to_include = array(), $query_params = array() ) { |
|
465 | + public function get_datetime_counts_by_status($stati_to_include = array(), $query_params = array()) { |
|
466 | 466 | //only accept where conditions for this query. |
467 | - $_where = isset( $query_params[0] ) ? $query_params[0] : array(); |
|
467 | + $_where = isset($query_params[0]) ? $query_params[0] : array(); |
|
468 | 468 | $status_query_args = array( |
469 | 469 | EE_Datetime::active => array_merge( |
470 | 470 | $_where, |
471 | - array( 'DTT_EVT_start' => array( '<', time() ), 'DTT_EVT_end' => array( '>', time() ) ) |
|
471 | + array('DTT_EVT_start' => array('<', time()), 'DTT_EVT_end' => array('>', time())) |
|
472 | 472 | ), |
473 | 473 | EE_Datetime::upcoming => array_merge( |
474 | 474 | $_where, |
475 | - array( 'DTT_EVT_start' => array( '>', time() ) ) |
|
475 | + array('DTT_EVT_start' => array('>', time())) |
|
476 | 476 | ), |
477 | 477 | EE_Datetime::expired => array_merge( |
478 | 478 | $_where, |
479 | - array( 'DTT_EVT_end' => array('<', time() ) ) |
|
479 | + array('DTT_EVT_end' => array('<', time())) |
|
480 | 480 | ) |
481 | 481 | ); |
482 | 482 | |
483 | - if ( ! empty( $stati_to_include ) ) { |
|
484 | - foreach( array_keys( $status_query_args ) as $status ) { |
|
485 | - if ( ! in_array( $status, $stati_to_include ) ) { |
|
486 | - unset( $status_query_args[$status] ); |
|
483 | + if ( ! empty($stati_to_include)) { |
|
484 | + foreach (array_keys($status_query_args) as $status) { |
|
485 | + if ( ! in_array($status, $stati_to_include)) { |
|
486 | + unset($status_query_args[$status]); |
|
487 | 487 | } |
488 | 488 | } |
489 | 489 | } |
490 | 490 | |
491 | 491 | //loop through and query counts for each stati. |
492 | 492 | $status_query_results = array(); |
493 | - foreach( $status_query_args as $status => $status_where_conditions ) { |
|
494 | - $status_query_results[ $status ] = EEM_Datetime::count( array( $status_where_conditions ), 'DTT_ID', true ); |
|
493 | + foreach ($status_query_args as $status => $status_where_conditions) { |
|
494 | + $status_query_results[$status] = EEM_Datetime::count(array($status_where_conditions), 'DTT_ID', true); |
|
495 | 495 | } |
496 | 496 | |
497 | 497 | return $status_query_results; |
@@ -505,9 +505,9 @@ discard block |
||
505 | 505 | * @param array $query_params |
506 | 506 | * @return int |
507 | 507 | */ |
508 | - public function get_datetime_count_for_status( $status = EE_Datetime::active, $query_params = array() ) { |
|
509 | - $count = $this->get_datetime_counts_by_status( array( $status ), $query_params ); |
|
510 | - return ! empty( $count[$status] ) ? $count[$status] : 0; |
|
508 | + public function get_datetime_count_for_status($status = EE_Datetime::active, $query_params = array()) { |
|
509 | + $count = $this->get_datetime_counts_by_status(array($status), $query_params); |
|
510 | + return ! empty($count[$status]) ? $count[$status] : 0; |
|
511 | 511 | } |
512 | 512 | |
513 | 513 |