@@ -3,7 +3,7 @@ discard block |
||
3 | 3 | <?php _e('Adjust the settings for the PayPal Standard payment gateway.', 'event_espresso'); ?> |
4 | 4 | </p> |
5 | 5 | <p> |
6 | -<?php printf( __( 'See %1$shere%2$s for list of currencies supported by Paypal Standard.', 'event_espresso' ), "<a href='https://www.paypal.com/multicurrency' target='_blank'>","</a>" ); ?> |
|
6 | +<?php printf(__('See %1$shere%2$s for list of currencies supported by Paypal Standard.', 'event_espresso'), "<a href='https://www.paypal.com/multicurrency' target='_blank'>", "</a>"); ?> |
|
7 | 7 | </p> |
8 | 8 | <h3><?php _e('PayPal Standard Settings', 'event_espresso'); ?></h3> |
9 | 9 | <ul> |
@@ -21,18 +21,18 @@ discard block |
||
21 | 21 | </li> |
22 | 22 | <li> |
23 | 23 | <strong><?php _e('PayPal Calculates Taxes', 'event_espresso'); ?></strong><br /> |
24 | -<?php printf( __('If set to "Yes", we will indicate to PayPal that it should calculate the taxes on the order and add it. This means PayPal\'s tax calculations will be used on the order instead of Event Espresso\'s. %1$sRead here for more information.%2$s', 'event_espresso'), "<a href='https://www.paypal.com/ca/cgi-bin/webscr?cmd=xpt/Marketing/shipping/EasyCalculateShipAndTax-outside' target='_blank'>", '</a>' ); ?><br/> |
|
25 | -<?php _e( 'Note: It may confuse users if Event Espresso initially calculates taxes on the order, and then they go to PayPal and it calculates taxes differently. So it is recommended that if PayPal is calculating taxes, that you do not set any taxes in Event Espresso.', 'event_espresso' );?> |
|
24 | +<?php printf(__('If set to "Yes", we will indicate to PayPal that it should calculate the taxes on the order and add it. This means PayPal\'s tax calculations will be used on the order instead of Event Espresso\'s. %1$sRead here for more information.%2$s', 'event_espresso'), "<a href='https://www.paypal.com/ca/cgi-bin/webscr?cmd=xpt/Marketing/shipping/EasyCalculateShipAndTax-outside' target='_blank'>", '</a>'); ?><br/> |
|
25 | +<?php _e('Note: It may confuse users if Event Espresso initially calculates taxes on the order, and then they go to PayPal and it calculates taxes differently. So it is recommended that if PayPal is calculating taxes, that you do not set any taxes in Event Espresso.', 'event_espresso'); ?> |
|
26 | 26 | </li> |
27 | 27 | <li> |
28 | 28 | <strong><?php _e('PayPal Calculates Shipping', 'event_espresso'); ?></strong><br /> |
29 | 29 | <?php _e('Similar to the "PayPal Calculates Taxes" setting, if this is set to "Yes", we will indicate to PayPal that it should calculate the shipping on each payment (if there are multiple payments for a single transaction, PayPal is permitted to add shipping charges to each payment.)', 'event_espresso'); ?><br/> |
30 | -<?php _e( 'Important Note: PayPal will ONLY calculate shipping on an order if "Shipping Address Options" is set to "Prompt for an Address" (otherwise how will PayPal know how much to charge for shipping if it doesn\'t know where it\'s shipping to?)', 'event_espresso' );?> |
|
30 | +<?php _e('Important Note: PayPal will ONLY calculate shipping on an order if "Shipping Address Options" is set to "Prompt for an Address" (otherwise how will PayPal know how much to charge for shipping if it doesn\'t know where it\'s shipping to?)', 'event_espresso'); ?> |
|
31 | 31 | <li> |
32 | -<strong><?php _e( 'Notes Regarding Paypal Taxes and Shipping', 'event_espresso' );?></strong><br/> |
|
33 | -<?php _e( 'If you want PayPal to calculate taxes and shipping on an order, those changes will NOT appear during the initial registration process until the user is redirected to PayPal for payment.', 'event_espresso' );?><br/> |
|
34 | -<?php _e( 'However, after the user has returned from PayPal, their order in Event Espresso will be updated with the new taxes and added shipping charges (e.g. it will appear on their receipt.)', 'event_espresso' );?><br/> |
|
35 | -<?php _e( 'Also Note: In order for PayPal to properly calculate taxes and shipping, they need to receive the entire order at the same time. So if a user goes to make a payment using PayPal, and their order somehow already has a payment on it, PayPal CANNOT calculate taxes or shipping on that order.', 'event_espresso' );?> |
|
32 | +<strong><?php _e('Notes Regarding Paypal Taxes and Shipping', 'event_espresso'); ?></strong><br/> |
|
33 | +<?php _e('If you want PayPal to calculate taxes and shipping on an order, those changes will NOT appear during the initial registration process until the user is redirected to PayPal for payment.', 'event_espresso'); ?><br/> |
|
34 | +<?php _e('However, after the user has returned from PayPal, their order in Event Espresso will be updated with the new taxes and added shipping charges (e.g. it will appear on their receipt.)', 'event_espresso'); ?><br/> |
|
35 | +<?php _e('Also Note: In order for PayPal to properly calculate taxes and shipping, they need to receive the entire order at the same time. So if a user goes to make a payment using PayPal, and their order somehow already has a payment on it, PayPal CANNOT calculate taxes or shipping on that order.', 'event_espresso'); ?> |
|
36 | 36 | </li> |
37 | 37 | <li> |
38 | 38 | <strong><?php _e('Shipping Address Options', 'event_espresso'); ?></strong><br /> |
@@ -129,7 +129,7 @@ |
||
129 | 129 | * |
130 | 130 | * @param string $route |
131 | 131 | * @param string $regex |
132 | - * @param array $match_keys EXCLUDING matching the entire regex |
|
132 | + * @param string[] $match_keys EXCLUDING matching the entire regex |
|
133 | 133 | * @return array where $match_keys are the keys (the first value of $match_keys |
134 | 134 | * becomes the first key of the return value, etc. Eg passing in $match_keys of |
135 | 135 | * array( 'model', 'id' ), will, if the regex is successful, will return |
@@ -1,8 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | namespace EventEspresso\core\libraries\rest_api\controllers; |
3 | 3 | |
4 | -if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
5 | - exit( 'No direct script access allowed' ); |
|
4 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
5 | + exit('No direct script access allowed'); |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | /** |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | protected $_requested_version; |
37 | 37 | |
38 | 38 | public function __construct() { |
39 | - $this->_debug_mode = defined( 'EE_REST_API_DEBUG_MODE' ) ? EE_REST_API_DEBUG_MODE : false; |
|
39 | + $this->_debug_mode = defined('EE_REST_API_DEBUG_MODE') ? EE_REST_API_DEBUG_MODE : false; |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | * Sets the version the user requested |
45 | 45 | * @param string $version eg '4.8' |
46 | 46 | */ |
47 | - public function set_requested_version( $version ) { |
|
47 | + public function set_requested_version($version) { |
|
48 | 48 | $this->_requested_version = $version; |
49 | 49 | } |
50 | 50 | |
@@ -53,8 +53,8 @@ discard block |
||
53 | 53 | * @param string $key |
54 | 54 | * @param string|array $info |
55 | 55 | */ |
56 | - protected function _set_debug_info( $key, $info ){ |
|
57 | - $this->_debug_info[ $key ] = $info; |
|
56 | + protected function _set_debug_info($key, $info) { |
|
57 | + $this->_debug_info[$key] = $info; |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | |
@@ -69,52 +69,52 @@ discard block |
||
69 | 69 | * @param array|\WP_Error|\Exception $response |
70 | 70 | * @return \WP_REST_Response |
71 | 71 | */ |
72 | - public function send_response( $response ) { |
|
73 | - if( $response instanceof \Exception ) { |
|
74 | - $response = new \WP_Error( $response->getCode(), $response->getMessage() ); |
|
72 | + public function send_response($response) { |
|
73 | + if ($response instanceof \Exception) { |
|
74 | + $response = new \WP_Error($response->getCode(), $response->getMessage()); |
|
75 | 75 | } |
76 | - if( $response instanceof \WP_Error ) { |
|
76 | + if ($response instanceof \WP_Error) { |
|
77 | 77 | //we want to send a "normal"-looking WP error response, but we also |
78 | 78 | //want to add headers. It doesn't seem WP API 1.2 supports this. |
79 | 79 | //I'd like to use WP_JSON_Server::error_to_response() but its protected |
80 | 80 | //so here's most of it copy-and-pasted :P |
81 | 81 | $error_data = $response->get_error_data(); |
82 | - if ( is_array( $error_data ) && isset( $error_data['status'] ) ) { |
|
82 | + if (is_array($error_data) && isset($error_data['status'])) { |
|
83 | 83 | $status = $error_data['status']; |
84 | 84 | } else { |
85 | 85 | $status = 500; |
86 | 86 | } |
87 | 87 | |
88 | 88 | $errors = array(); |
89 | - foreach ( (array) $response->errors as $code => $messages ) { |
|
90 | - foreach ( (array) $messages as $message ) { |
|
89 | + foreach ((array) $response->errors as $code => $messages) { |
|
90 | + foreach ((array) $messages as $message) { |
|
91 | 91 | $errors[] = array( |
92 | 92 | 'code' => $code, |
93 | 93 | 'message' => $message, |
94 | - 'data' => $response->get_error_data( $code ) |
|
94 | + 'data' => $response->get_error_data($code) |
|
95 | 95 | ); |
96 | 96 | } |
97 | 97 | } |
98 | - $data = isset( $errors[0] ) ? $errors[0] : array(); |
|
99 | - if ( count( $errors ) > 1 ) { |
|
98 | + $data = isset($errors[0]) ? $errors[0] : array(); |
|
99 | + if (count($errors) > 1) { |
|
100 | 100 | // Remove the primary error. |
101 | - array_shift( $errors ); |
|
101 | + array_shift($errors); |
|
102 | 102 | $data['additional_errors'] = $errors; |
103 | 103 | } |
104 | - $rest_response = new \WP_REST_Response( $data, $status ); |
|
105 | - }else{ |
|
106 | - $rest_response = new \WP_REST_Response( $response, 200 ); |
|
104 | + $rest_response = new \WP_REST_Response($data, $status); |
|
105 | + } else { |
|
106 | + $rest_response = new \WP_REST_Response($response, 200); |
|
107 | 107 | } |
108 | 108 | $headers = array(); |
109 | - if( $this->_debug_mode && is_array( $this->_debug_info ) ) { |
|
110 | - foreach( $this->_debug_info as $debug_key => $debug_info ) { |
|
111 | - if( is_array( $debug_info ) ) { |
|
112 | - $debug_info = json_encode( $debug_info ); |
|
109 | + if ($this->_debug_mode && is_array($this->_debug_info)) { |
|
110 | + foreach ($this->_debug_info as $debug_key => $debug_info) { |
|
111 | + if (is_array($debug_info)) { |
|
112 | + $debug_info = json_encode($debug_info); |
|
113 | 113 | } |
114 | - $headers[ 'X-EE4-Debug-' . ucwords( $debug_key ) ] = $debug_info; |
|
114 | + $headers['X-EE4-Debug-'.ucwords($debug_key)] = $debug_info; |
|
115 | 115 | } |
116 | 116 | } |
117 | - $rest_response->set_headers( $headers ); |
|
117 | + $rest_response->set_headers($headers); |
|
118 | 118 | return $rest_response; |
119 | 119 | } |
120 | 120 | |
@@ -136,23 +136,23 @@ discard block |
||
136 | 136 | * array( 'model' => 'foo', 'id' => 'bar' ) |
137 | 137 | * @throws \EE_Error if it couldn't be parsed |
138 | 138 | */ |
139 | - public function parse_route( $route, $regex, $match_keys ) { |
|
139 | + public function parse_route($route, $regex, $match_keys) { |
|
140 | 140 | $indexed_matches = array(); |
141 | - $success = preg_match( $regex, $route, $matches ); |
|
142 | - if( |
|
143 | - is_array( $matches ) ) { |
|
141 | + $success = preg_match($regex, $route, $matches); |
|
142 | + if ( |
|
143 | + is_array($matches) ) { |
|
144 | 144 | //skip the overall regex match. Who cares |
145 | - for( $i = 1; $i <= count( $match_keys ); $i++ ) { |
|
146 | - if( ! isset( $matches[ $i ] ) ) { |
|
145 | + for ($i = 1; $i <= count($match_keys); $i++) { |
|
146 | + if ( ! isset($matches[$i])) { |
|
147 | 147 | $success = false; |
148 | 148 | } else { |
149 | - $indexed_matches[ $match_keys[ $i - 1 ] ] = $matches[ $i ]; |
|
149 | + $indexed_matches[$match_keys[$i - 1]] = $matches[$i]; |
|
150 | 150 | } |
151 | 151 | } |
152 | 152 | } |
153 | - if( ! $success ) { |
|
153 | + if ( ! $success) { |
|
154 | 154 | throw new \EE_Error( |
155 | - __( 'We could not parse the URL. Please contact Event Espresso Support', 'event_espresso' ), |
|
155 | + __('We could not parse the URL. Please contact Event Espresso Support', 'event_espresso'), |
|
156 | 156 | 'endpoint_parsing_error' |
157 | 157 | ); |
158 | 158 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | namespace EventEspresso\core\libraries\rest_api; |
3 | -if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
4 | - exit( 'No direct script access allowed' ); |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
4 | + exit('No direct script access allowed'); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -21,16 +21,16 @@ discard block |
||
21 | 21 | * @param string $model_context one of the return values from EEM_Base::valid_cap_contexts() |
22 | 22 | * @return boolean |
23 | 23 | */ |
24 | - public static function current_user_has_partial_access_to( $model, $model_context = \EEM_Base::caps_read ) { |
|
25 | - if( apply_filters( 'FHEE__Capabilities__current_user_has_partial_access_to__override_begin', false, $model, $model ) ) { |
|
24 | + public static function current_user_has_partial_access_to($model, $model_context = \EEM_Base::caps_read) { |
|
25 | + if (apply_filters('FHEE__Capabilities__current_user_has_partial_access_to__override_begin', false, $model, $model)) { |
|
26 | 26 | return true; |
27 | 27 | } |
28 | - foreach( $model->caps_missing( $model_context ) as $capability_name => $restriction_obj ) { |
|
29 | - if( $restriction_obj instanceof \EE_Return_None_Where_Conditions ){ |
|
28 | + foreach ($model->caps_missing($model_context) as $capability_name => $restriction_obj) { |
|
29 | + if ($restriction_obj instanceof \EE_Return_None_Where_Conditions) { |
|
30 | 30 | return false; |
31 | 31 | } |
32 | 32 | } |
33 | - if( apply_filters( 'FHEE__Capabilities__current_user_has_partial_access_to__override_end', false, $model, $model ) ) { |
|
33 | + if (apply_filters('FHEE__Capabilities__current_user_has_partial_access_to__override_end', false, $model, $model)) { |
|
34 | 34 | return false; |
35 | 35 | } |
36 | 36 | return true; |
@@ -43,8 +43,8 @@ discard block |
||
43 | 43 | * @param string $request_type one of the constants on WP_JSON_Server |
44 | 44 | * @return array |
45 | 45 | */ |
46 | - public static function get_missing_permissions( $model, $request_type = \EEM_Base::caps_read ) { |
|
47 | - return $model->caps_missing( $request_type ); |
|
46 | + public static function get_missing_permissions($model, $request_type = \EEM_Base::caps_read) { |
|
47 | + return $model->caps_missing($request_type); |
|
48 | 48 | } |
49 | 49 | /** |
50 | 50 | * Gets a string of all the capabilities the current user is missing that affected |
@@ -54,8 +54,8 @@ discard block |
||
54 | 54 | * @param string $model_context one of the return values from EEM_Base::valid_cap_contexts() |
55 | 55 | * @return string |
56 | 56 | */ |
57 | - public static function get_missing_permissions_string( $model, $model_context = \EEM_Base::caps_read ) { |
|
58 | - return implode(',', array_keys( self::get_missing_permissions( $model, $model_context ) ) ); |
|
57 | + public static function get_missing_permissions_string($model, $model_context = \EEM_Base::caps_read) { |
|
58 | + return implode(',', array_keys(self::get_missing_permissions($model, $model_context))); |
|
59 | 59 | } |
60 | 60 | |
61 | 61 | /** |
@@ -66,25 +66,25 @@ discard block |
||
66 | 66 | * @param Model_Version_Info $model_version_info |
67 | 67 | * @return array ready for converting into json |
68 | 68 | */ |
69 | - public static function filter_out_inaccessible_entity_fields( $entity, $model, $request_type, $model_version_info ) { |
|
69 | + public static function filter_out_inaccessible_entity_fields($entity, $model, $request_type, $model_version_info) { |
|
70 | 70 | //we only care to do this for frontend reads and when the user can't edit the item |
71 | - if( $request_type !== \EEM_Base::caps_read || |
|
72 | - $model->exists( array( |
|
73 | - array( $model->primary_key_name() => $entity[ $model->primary_key_name() ] ), |
|
71 | + if ($request_type !== \EEM_Base::caps_read || |
|
72 | + $model->exists(array( |
|
73 | + array($model->primary_key_name() => $entity[$model->primary_key_name()]), |
|
74 | 74 | 'default_where_conditions' => 'none', |
75 | - 'caps' => \EEM_Base::caps_edit ) ) ) { |
|
75 | + 'caps' => \EEM_Base::caps_edit ))) { |
|
76 | 76 | return $entity; |
77 | 77 | } |
78 | - foreach( $model->field_settings() as $field_name => $field_obj ){ |
|
79 | - if( $model_version_info->field_has_rendered_format( $field_obj ) |
|
80 | - && isset( $entity[ $field_name ][ 'raw' ] ) |
|
78 | + foreach ($model->field_settings() as $field_name => $field_obj) { |
|
79 | + if ($model_version_info->field_has_rendered_format($field_obj) |
|
80 | + && isset($entity[$field_name]['raw']) |
|
81 | 81 | ) { |
82 | - unset( $entity[ $field_name ][ 'raw' ] ); |
|
82 | + unset($entity[$field_name]['raw']); |
|
83 | 83 | } |
84 | 84 | } |
85 | 85 | //theoretically we may want to filter out specific fields for specific models |
86 | 86 | |
87 | - return apply_filters( 'FHEE__Capabilities__filter_out_inaccessible_entity_fields', $entity, $model, $request_type ); |
|
87 | + return apply_filters('FHEE__Capabilities__filter_out_inaccessible_entity_fields', $entity, $model, $request_type); |
|
88 | 88 | } |
89 | 89 | } |
90 | 90 |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | namespace EventEspresso\core\libraries\rest_api\controllers\config; |
3 | -if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
4 | - exit( 'No direct script access allowed' ); |
|
3 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
4 | + exit('No direct script access allowed'); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | /** |
@@ -21,11 +21,11 @@ discard block |
||
21 | 21 | * @param \WP_REST_Request $request |
22 | 22 | * @return \EE_Config|\WP_Error |
23 | 23 | */ |
24 | - public static function handle_request( \WP_REST_Request $request) { |
|
24 | + public static function handle_request(\WP_REST_Request $request) { |
|
25 | 25 | $cap = \EE_Restriction_Generator_Base::get_default_restrictions_cap(); |
26 | - if( \EE_Capabilities::instance()->current_user_can( $cap, 'read_over_api' ) ){ |
|
26 | + if (\EE_Capabilities::instance()->current_user_can($cap, 'read_over_api')) { |
|
27 | 27 | return \EE_Config::instance(); |
28 | - }else{ |
|
28 | + } else { |
|
29 | 29 | return new \WP_Error( |
30 | 30 | 'cannot_read_config', |
31 | 31 | sprintf( |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | ), |
36 | 36 | $cap |
37 | 37 | ), |
38 | - array( 'status' => 403 ) |
|
38 | + array('status' => 403) |
|
39 | 39 | ); |
40 | 40 | } |
41 | 41 | } |
@@ -293,7 +293,7 @@ |
||
293 | 293 | //if it's not above the current core version, and it's compatible with the current version of core |
294 | 294 | if( $possibly_served_version < EED_REST_API::core_version() && $possibly_served_version >= $lowest_compatible_version ) { |
295 | 295 | $versions_served[ $possibly_served_version ] = true; |
296 | - }else { |
|
296 | + } else { |
|
297 | 297 | $versions_served[ $possibly_served_version ] = false; |
298 | 298 | } |
299 | 299 | } |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
3 | - exit( 'No direct script access allowed' ); |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
3 | + exit('No direct script access allowed'); |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * @return EED_Core_Rest_Api |
23 | 23 | */ |
24 | 24 | public static function instance() { |
25 | - return parent::get_instance( __CLASS__ ); |
|
25 | + return parent::get_instance(__CLASS__); |
|
26 | 26 | } |
27 | 27 | |
28 | 28 | |
@@ -52,9 +52,9 @@ discard block |
||
52 | 52 | |
53 | 53 | |
54 | 54 | public static function set_hooks_both() { |
55 | - add_action( 'rest_api_init', array( 'EED_Core_REST_API', 'register_routes' ) ); |
|
56 | - add_filter( 'rest_route_data', array( 'EED_Core_REST_API', 'hide_old_endpoints' ), 10, 2 ); |
|
57 | - add_filter( 'rest_index', array( 'EventEspresso\core\libraries\rest_api\controllers\model\Meta', 'filter_ee_metadata_into_index' ) ); |
|
55 | + add_action('rest_api_init', array('EED_Core_REST_API', 'register_routes')); |
|
56 | + add_filter('rest_route_data', array('EED_Core_REST_API', 'hide_old_endpoints'), 10, 2); |
|
57 | + add_filter('rest_index', array('EventEspresso\core\libraries\rest_api\controllers\model\Meta', 'filter_ee_metadata_into_index')); |
|
58 | 58 | } |
59 | 59 | |
60 | 60 | |
@@ -63,16 +63,16 @@ discard block |
||
63 | 63 | * so we actually prefer to only do it when an EE plugin is activated or upgraded |
64 | 64 | */ |
65 | 65 | public static function register_routes() { |
66 | - foreach( EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls ) { |
|
67 | - foreach( $relative_urls as $endpoint => $routes ) { |
|
68 | - foreach( $routes as $route ) { |
|
66 | + foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) { |
|
67 | + foreach ($relative_urls as $endpoint => $routes) { |
|
68 | + foreach ($routes as $route) { |
|
69 | 69 | register_rest_route( |
70 | 70 | $namespace, |
71 | 71 | $endpoint, |
72 | 72 | array( |
73 | - 'callback' => $route[ 'callback' ], |
|
74 | - 'methods' => $route[ 'methods' ], |
|
75 | - 'args' => isset( $route[ 'args' ] ) ? $route[ 'args' ] : array(), |
|
73 | + 'callback' => $route['callback'], |
|
74 | + 'methods' => $route['methods'], |
|
75 | + 'args' => isset($route['args']) ? $route['args'] : array(), |
|
76 | 76 | ) |
77 | 77 | ); |
78 | 78 | } |
@@ -89,10 +89,10 @@ discard block |
||
89 | 89 | * } |
90 | 90 | */ |
91 | 91 | public static function get_ee_route_data() { |
92 | - $ee_routes = get_option( self::saved_routes_option_names, null ); |
|
93 | - if( ! $ee_routes || ( defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE )){ |
|
92 | + $ee_routes = get_option(self::saved_routes_option_names, null); |
|
93 | + if ( ! $ee_routes || (defined('EE_REST_API_DEBUG_MODE') && EE_REST_API_DEBUG_MODE)) { |
|
94 | 94 | self::save_ee_routes(); |
95 | - $ee_routes = get_option( self::saved_routes_option_names, array() ); |
|
95 | + $ee_routes = get_option(self::saved_routes_option_names, array()); |
|
96 | 96 | } |
97 | 97 | return $ee_routes; |
98 | 98 | } |
@@ -103,14 +103,14 @@ discard block |
||
103 | 103 | * @return void |
104 | 104 | */ |
105 | 105 | public static function save_ee_routes() { |
106 | - if( EE_Maintenance_Mode::instance()->models_can_query() ){ |
|
106 | + if (EE_Maintenance_Mode::instance()->models_can_query()) { |
|
107 | 107 | $instance = self::instance(); |
108 | 108 | $routes = array_replace_recursive( |
109 | 109 | $instance->_register_config_routes(), |
110 | 110 | $instance->_register_meta_routes(), |
111 | 111 | $instance->_register_model_routes() |
112 | 112 | ); |
113 | - update_option( self::saved_routes_option_names, $routes, true ); |
|
113 | + update_option(self::saved_routes_option_names, $routes, true); |
|
114 | 114 | } |
115 | 115 | } |
116 | 116 | |
@@ -119,7 +119,7 @@ discard block |
||
119 | 119 | * @return array @see get_ee_route_data |
120 | 120 | */ |
121 | 121 | protected function _register_model_routes() { |
122 | - EE_Registry::instance()->load_helper( 'Inflector' ); |
|
122 | + EE_Registry::instance()->load_helper('Inflector'); |
|
123 | 123 | $models_to_register = apply_filters( |
124 | 124 | 'FHEE__EED_Core_REST_API___register_model_routes', |
125 | 125 | EE_Registry::instance()->non_abstract_db_models |
@@ -128,23 +128,23 @@ discard block |
||
128 | 128 | unset($models_to_register['Extra_Meta']); |
129 | 129 | unset($models_to_register['Extra_Join']); |
130 | 130 | $model_routes = array( ); |
131 | - foreach( self::versions_served() as $version => $hidden_endpoint ) { |
|
131 | + foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
132 | 132 | |
133 | - foreach ( $models_to_register as $model_name => $model_classname ) { |
|
133 | + foreach ($models_to_register as $model_name => $model_classname) { |
|
134 | 134 | //yes we could just register one route for ALL models, but then they wouldn't show up in the index |
135 | - $ee_namespace = self::ee_api_namespace . $version; |
|
136 | - $plural_model_route = EEH_Inflector::pluralize_and_lower( $model_name ); |
|
137 | - $singular_model_route = $plural_model_route . '/(?P<id>\d+)' ; |
|
138 | - $model_routes[ $ee_namespace ][ $plural_model_route ] = array( |
|
135 | + $ee_namespace = self::ee_api_namespace.$version; |
|
136 | + $plural_model_route = EEH_Inflector::pluralize_and_lower($model_name); |
|
137 | + $singular_model_route = $plural_model_route.'/(?P<id>\d+)'; |
|
138 | + $model_routes[$ee_namespace][$plural_model_route] = array( |
|
139 | 139 | array( |
140 | 140 | 'callback' => array( |
141 | 141 | 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
142 | 142 | 'handle_request_get_all' ), |
143 | 143 | 'methods' => WP_REST_Server::READABLE, |
144 | 144 | 'hidden_endpoint' => $hidden_endpoint, |
145 | - 'args' => $this->_get_read_query_params( $model_name ), |
|
145 | + 'args' => $this->_get_read_query_params($model_name), |
|
146 | 146 | '_links' => array( |
147 | - 'self' => rest_url( $ee_namespace . $singular_model_route ), |
|
147 | + 'self' => rest_url($ee_namespace.$singular_model_route), |
|
148 | 148 | ) |
149 | 149 | ), |
150 | 150 | // array( |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | // 'hidden_endpoint' => $hidden_endpoint |
156 | 156 | // ) |
157 | 157 | ); |
158 | - $model_routes[ $ee_namespace ][ $singular_model_route ] = array( |
|
158 | + $model_routes[$ee_namespace][$singular_model_route] = array( |
|
159 | 159 | array( |
160 | 160 | 'callback' => array( |
161 | 161 | 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | 'include' => array( |
167 | 167 | 'required' => false, |
168 | 168 | 'default' => '*', |
169 | - 'description' => __( 'See http://developer.eventespresso.com/docs/ee4-rest-api-reading/#Including_Specific_Fields_and_Related_Entities_in_Results for documentation', 'event_espresso' ), |
|
169 | + 'description' => __('See http://developer.eventespresso.com/docs/ee4-rest-api-reading/#Including_Specific_Fields_and_Related_Entities_in_Results for documentation', 'event_espresso'), |
|
170 | 170 | ), |
171 | 171 | ) |
172 | 172 | ), |
@@ -179,20 +179,20 @@ discard block |
||
179 | 179 | // ), |
180 | 180 | ); |
181 | 181 | //@todo: also handle DELETE for a single item |
182 | - $model = EE_Registry::instance()->load_model( $model_classname ); |
|
183 | - foreach ( $model->relation_settings() as $relation_name => $relation_obj ) { |
|
182 | + $model = EE_Registry::instance()->load_model($model_classname); |
|
183 | + foreach ($model->relation_settings() as $relation_name => $relation_obj) { |
|
184 | 184 | $related_model_name_endpoint_part = EventEspresso\core\libraries\rest_api\controllers\model\Read::get_related_entity_name( |
185 | 185 | $relation_name, |
186 | 186 | $relation_obj |
187 | 187 | ); |
188 | - $model_routes[ $ee_namespace ][ $singular_model_route . '/' . $related_model_name_endpoint_part ] = array( |
|
188 | + $model_routes[$ee_namespace][$singular_model_route.'/'.$related_model_name_endpoint_part] = array( |
|
189 | 189 | array( |
190 | 190 | 'callback' => array( |
191 | 191 | 'EventEspresso\core\libraries\rest_api\controllers\model\Read', |
192 | 192 | 'handle_request_get_related' ), |
193 | 193 | 'methods' => WP_REST_Server::READABLE, |
194 | 194 | 'hidden_endpoint' => $hidden_endpoint, |
195 | - 'args' => $this->_get_read_query_params( $relation_name ), |
|
195 | + 'args' => $this->_get_read_query_params($relation_name), |
|
196 | 196 | ), |
197 | 197 | // array( |
198 | 198 | // 'callback' => array( |
@@ -215,47 +215,47 @@ discard block |
||
215 | 215 | * @param string $model_name eg 'Event' or 'Venue' |
216 | 216 | * @return array describing the args acceptable when querying this model |
217 | 217 | */ |
218 | - protected function _get_read_query_params( $model_name ) { |
|
219 | - $model = EE_Registry::instance()->load_model( $model_name ); |
|
218 | + protected function _get_read_query_params($model_name) { |
|
219 | + $model = EE_Registry::instance()->load_model($model_name); |
|
220 | 220 | $default_orderby = array(); |
221 | - foreach( $model->get_combined_primary_key_fields() as $key_field ) { |
|
222 | - $default_orderby[ $key_field->get_name() ] = 'ASC'; |
|
221 | + foreach ($model->get_combined_primary_key_fields() as $key_field) { |
|
222 | + $default_orderby[$key_field->get_name()] = 'ASC'; |
|
223 | 223 | } |
224 | 224 | return array( |
225 | 225 | 'where' => array( |
226 | 226 | 'required' => false, |
227 | 227 | 'default' => array(), |
228 | - 'description' => __( 'See http://developer.eventespresso.com/docs/ee4-rest-api-reading/#where for documentation', 'event_espresso' ), |
|
228 | + 'description' => __('See http://developer.eventespresso.com/docs/ee4-rest-api-reading/#where for documentation', 'event_espresso'), |
|
229 | 229 | ), |
230 | 230 | 'limit' => array( |
231 | 231 | 'required' => false, |
232 | 232 | 'default' => 50, |
233 | - 'description' => __( 'See http://developer.eventespresso.com/docs/ee4-rest-api-reading/#limit for documentation', 'event_espresso' ) |
|
233 | + 'description' => __('See http://developer.eventespresso.com/docs/ee4-rest-api-reading/#limit for documentation', 'event_espresso') |
|
234 | 234 | ), |
235 | 235 | 'order_by' => array( |
236 | 236 | 'required' => false, |
237 | 237 | 'default' => $default_orderby, |
238 | - 'description' => __( 'See http://developer.eventespresso.com/docs/ee4-rest-api-reading/#order_by for documentation', 'event_espresso' ) |
|
238 | + 'description' => __('See http://developer.eventespresso.com/docs/ee4-rest-api-reading/#order_by for documentation', 'event_espresso') |
|
239 | 239 | ), |
240 | 240 | 'group_by' => array( |
241 | 241 | 'required' => false, |
242 | 242 | 'default' => null, |
243 | - 'description' => __( 'See http://developer.eventespresso.com/docs/ee4-rest-api-reading/#group_by for documentation', 'event_espresso' ) |
|
243 | + 'description' => __('See http://developer.eventespresso.com/docs/ee4-rest-api-reading/#group_by for documentation', 'event_espresso') |
|
244 | 244 | ), |
245 | 245 | 'having' => array( |
246 | 246 | 'required' => false, |
247 | 247 | 'default' => null, |
248 | - 'description' => __( 'See http://developer.eventespresso.com/docs/ee4-rest-api-reading/#having for documentation', 'event_espresso' ) |
|
248 | + 'description' => __('See http://developer.eventespresso.com/docs/ee4-rest-api-reading/#having for documentation', 'event_espresso') |
|
249 | 249 | ), |
250 | 250 | 'caps' => array( |
251 | 251 | 'required' => false, |
252 | 252 | 'default' => EEM_Base::caps_read, |
253 | - 'description' => __( 'See http://developer.eventespresso.com/docs/ee4-rest-api-reading/#caps for documentation', 'event_espresso' ) |
|
253 | + 'description' => __('See http://developer.eventespresso.com/docs/ee4-rest-api-reading/#caps for documentation', 'event_espresso') |
|
254 | 254 | ), |
255 | 255 | 'include' => array( |
256 | 256 | 'required' => false, |
257 | 257 | 'default' => '*', |
258 | - 'description' => __( 'See http://developer.eventespresso.com/docs/ee4-rest-api-reading/#Including_Specific_Fields_and_Related_Entities_in_Results for documentation', 'event_espresso' ), |
|
258 | + 'description' => __('See http://developer.eventespresso.com/docs/ee4-rest-api-reading/#Including_Specific_Fields_and_Related_Entities_in_Results for documentation', 'event_espresso'), |
|
259 | 259 | ), |
260 | 260 | ); |
261 | 261 | } |
@@ -266,8 +266,8 @@ discard block |
||
266 | 266 | */ |
267 | 267 | protected function _register_config_routes() { |
268 | 268 | $config_routes = array(); |
269 | - foreach( self::versions_served() as $version => $hidden_endpoint ) { |
|
270 | - $config_routes[ self::ee_api_namespace . $version ][ 'config' ] = array( |
|
269 | + foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
270 | + $config_routes[self::ee_api_namespace.$version]['config'] = array( |
|
271 | 271 | array( |
272 | 272 | 'callback' => array( |
273 | 273 | 'EventEspresso\core\libraries\rest_api\controllers\config\Read', |
@@ -286,8 +286,8 @@ discard block |
||
286 | 286 | */ |
287 | 287 | protected function _register_meta_routes() { |
288 | 288 | $meta_routes = array(); |
289 | - foreach( self::versions_served() as $version => $hidden_endpoint ) { |
|
290 | - $meta_routes[ self::ee_api_namespace . $version ][ '/resources' ] = array( |
|
289 | + foreach (self::versions_served() as $version => $hidden_endpoint) { |
|
290 | + $meta_routes[self::ee_api_namespace.$version]['/resources'] = array( |
|
291 | 291 | array( |
292 | 292 | 'callback' => array( |
293 | 293 | 'EventEspresso\core\libraries\rest_api\controllers\model\Meta', |
@@ -308,13 +308,13 @@ discard block |
||
308 | 308 | * @param array $route_data |
309 | 309 | * @return array |
310 | 310 | */ |
311 | - public function hide_old_endpoints( $route_data ) { |
|
312 | - foreach( EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls ) { |
|
313 | - foreach( $relative_urls as $endpoint => $routes ) { |
|
314 | - foreach( $routes as $route ) { |
|
315 | - if( $route[ 'hidden_endpoint' ] ) { |
|
316 | - $full_route = '/' . ltrim( $namespace, '/' ) . '/' . ltrim( $endpoint, '/' ); |
|
317 | - unset( $route_data[ $full_route ] ); |
|
311 | + public function hide_old_endpoints($route_data) { |
|
312 | + foreach (EED_Core_Rest_Api::get_ee_route_data() as $namespace => $relative_urls) { |
|
313 | + foreach ($relative_urls as $endpoint => $routes) { |
|
314 | + foreach ($routes as $route) { |
|
315 | + if ($route['hidden_endpoint']) { |
|
316 | + $full_route = '/'.ltrim($namespace, '/').'/'.ltrim($endpoint, '/'); |
|
317 | + unset($route_data[$full_route]); |
|
318 | 318 | } |
319 | 319 | } |
320 | 320 | } |
@@ -334,7 +334,7 @@ discard block |
||
334 | 334 | * @return array |
335 | 335 | */ |
336 | 336 | public static function version_compatibilities() { |
337 | - return apply_filters( 'FHEE__EED_Core_REST_API__version_compatibilities', array( '4.8.29' => '4.8.29' ) ); |
|
337 | + return apply_filters('FHEE__EED_Core_REST_API__version_compatibilities', array('4.8.29' => '4.8.29')); |
|
338 | 338 | } |
339 | 339 | |
340 | 340 | /** |
@@ -348,17 +348,17 @@ discard block |
||
348 | 348 | public static function versions_served() { |
349 | 349 | $version_compatibilities = EED_Core_Rest_Api::version_compatibilities(); |
350 | 350 | $versions_served = array(); |
351 | - $lowest_compatible_version = $version_compatibilities[ EED_Core_Rest_Api::core_version() ]; |
|
351 | + $lowest_compatible_version = $version_compatibilities[EED_Core_Rest_Api::core_version()]; |
|
352 | 352 | //for each version of core we have ever served: |
353 | - foreach( array_keys( EED_Core_Rest_Api::version_compatibilities() ) as $possibly_served_version ) { |
|
353 | + foreach (array_keys(EED_Core_Rest_Api::version_compatibilities()) as $possibly_served_version) { |
|
354 | 354 | //if it's not above the current core version, and it's compatible with the current version of core |
355 | - if( |
|
355 | + if ( |
|
356 | 356 | $possibly_served_version < EED_Core_Rest_Api::core_version() |
357 | 357 | && $possibly_served_version >= $lowest_compatible_version |
358 | 358 | ) { |
359 | - $versions_served[ $possibly_served_version ] = true; |
|
360 | - }else { |
|
361 | - $versions_served[ $possibly_served_version ] = false; |
|
359 | + $versions_served[$possibly_served_version] = true; |
|
360 | + } else { |
|
361 | + $versions_served[$possibly_served_version] = false; |
|
362 | 362 | } |
363 | 363 | } |
364 | 364 | return $versions_served; |
@@ -371,7 +371,7 @@ discard block |
||
371 | 371 | * @return string |
372 | 372 | */ |
373 | 373 | public static function core_version() { |
374 | - return apply_filters( 'FHEE__EED_Core_REST_API__core_version', implode('.', array_slice( explode( '.', espresso_version() ), 0, 3 ) ) ); |
|
374 | + return apply_filters('FHEE__EED_Core_REST_API__core_version', implode('.', array_slice(explode('.', espresso_version()), 0, 3))); |
|
375 | 375 | } |
376 | 376 | |
377 | 377 | |
@@ -383,7 +383,7 @@ discard block |
||
383 | 383 | * @param WP $WP |
384 | 384 | * @return void |
385 | 385 | */ |
386 | - public function run( $WP ) { |
|
386 | + public function run($WP) { |
|
387 | 387 | |
388 | 388 | } |
389 | 389 |
@@ -653,6 +653,10 @@ |
||
653 | 653 | } |
654 | 654 | return $model_ready_query_params; |
655 | 655 | } |
656 | + |
|
657 | + /** |
|
658 | + * @param \EEM_Base $model |
|
659 | + */ |
|
656 | 660 | public function prepare_rest_query_params_values_for_models( $model, $query_params ) { |
657 | 661 | $model_ready_query_params = array(); |
658 | 662 | foreach( $query_params as $key => $value ) { |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | ){ |
228 | 228 | if( $relation instanceof \EE_Belongs_To_Relation ) { |
229 | 229 | $related_model_name_maybe_plural = strtolower( $related_model->get_this_model_name() ); |
230 | - }else{ |
|
230 | + } else{ |
|
231 | 231 | $related_model_name_maybe_plural = \EEH_Inflector::pluralize_and_lower( $related_model->get_this_model_name() ); |
232 | 232 | } |
233 | 233 | return new \WP_Error( |
@@ -280,7 +280,7 @@ discard block |
||
280 | 280 | } |
281 | 281 | if( $relation instanceof \EE_Belongs_To_Relation ){ |
282 | 282 | return array_shift( $nice_results ); |
283 | - }else{ |
|
283 | + } else{ |
|
284 | 284 | return $nice_results; |
285 | 285 | } |
286 | 286 | } |
@@ -331,26 +331,26 @@ discard block |
||
331 | 331 | $field_value = $field_obj->prepare_for_set_from_db( $raw_field_value ); |
332 | 332 | if( $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_ignored() ) ){ |
333 | 333 | unset( $result[ $field_name ] ); |
334 | - }elseif( |
|
334 | + } elseif( |
|
335 | 335 | $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_that_have_rendered_format() ) |
336 | 336 | ){ |
337 | 337 | $result[ $field_name ] = array( |
338 | 338 | 'raw' => $field_obj->prepare_for_get( $field_value ), |
339 | 339 | 'rendered' => $field_obj->prepare_for_pretty_echoing( $field_value ) |
340 | 340 | ); |
341 | - }elseif( |
|
341 | + } elseif( |
|
342 | 342 | $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_that_have_pretty_format() ) |
343 | 343 | ){ |
344 | 344 | $result[ $field_name ] = array( |
345 | 345 | 'raw' => $field_obj->prepare_for_get( $field_value ), |
346 | 346 | 'pretty' => $field_obj->prepare_for_pretty_echoing( $field_value ) |
347 | 347 | ); |
348 | - }elseif( $field_obj instanceof \EE_Datetime_Field ){ |
|
348 | + } elseif( $field_obj instanceof \EE_Datetime_Field ){ |
|
349 | 349 | if( $raw_field_value instanceof \DateTime ) { |
350 | 350 | $raw_field_value = $raw_field_value->format( 'c' ); |
351 | 351 | } |
352 | 352 | $result[ $field_name ] = mysql_to_rfc3339( $raw_field_value ); |
353 | - }else{ |
|
353 | + } else{ |
|
354 | 354 | $value_prepared = $field_obj->prepare_for_get( $field_value ); |
355 | 355 | |
356 | 356 | $result[ $field_name ] = $value_prepared === INF ? EE_INF_IN_DB : $value_prepared; |
@@ -479,7 +479,7 @@ discard block |
||
479 | 479 | public static function get_related_entity_name( $relation_name, $relation_obj ){ |
480 | 480 | if( $relation_obj instanceof \EE_Belongs_To_Relation ) { |
481 | 481 | return strtolower( $relation_name ); |
482 | - }else{ |
|
482 | + } else{ |
|
483 | 483 | return \EEH_Inflector::pluralize_and_lower( $relation_name ); |
484 | 484 | } |
485 | 485 | } |
@@ -548,7 +548,7 @@ discard block |
||
548 | 548 | $valid_contexts = \EEM_Base::valid_cap_contexts(); |
549 | 549 | if( in_array( $context, $valid_contexts ) ){ |
550 | 550 | return $context; |
551 | - }else{ |
|
551 | + } else{ |
|
552 | 552 | return \EEM_Base::caps_read; |
553 | 553 | } |
554 | 554 | } |
@@ -573,7 +573,7 @@ discard block |
||
573 | 573 | $order_by = $query_parameters[ 'order_by' ]; |
574 | 574 | } elseif ( isset( $query_parameters[ 'orderby' ] ) ) { |
575 | 575 | $order_by = $query_parameters[ 'orderby' ]; |
576 | - }else{ |
|
576 | + } else{ |
|
577 | 577 | $order_by = null; |
578 | 578 | } |
579 | 579 | if( $order_by !== null ){ |
@@ -583,7 +583,7 @@ discard block |
||
583 | 583 | $group_by = $query_parameters[ 'group_by' ]; |
584 | 584 | } elseif ( isset( $query_parameters[ 'groupby' ] ) ) { |
585 | 585 | $group_by = $query_parameters[ 'groupby' ]; |
586 | - }else{ |
|
586 | + } else{ |
|
587 | 587 | $group_by = null; |
588 | 588 | } |
589 | 589 | if( $group_by !== null ){ |
@@ -606,7 +606,7 @@ discard block |
||
606 | 606 | //limit should be either a string like '23' or '23,43', or an array with two items in it |
607 | 607 | if( is_string( $query_parameters[ 'limit' ] ) ) { |
608 | 608 | $limit_array = explode(',', $query_parameters['limit']); |
609 | - }else { |
|
609 | + } else { |
|
610 | 610 | $limit_array = $query_parameters[ 'limit' ]; |
611 | 611 | } |
612 | 612 | $sanitized_limit = array(); |
@@ -622,12 +622,12 @@ discard block |
||
622 | 622 | $sanitized_limit[] = intval( $limit_part ); |
623 | 623 | } |
624 | 624 | $model_query_params[ 'limit' ] = implode( ',', $sanitized_limit ); |
625 | - }else{ |
|
625 | + } else{ |
|
626 | 626 | $model_query_params[ 'limit' ] = 50; |
627 | 627 | } |
628 | 628 | if( isset( $query_parameters[ 'caps' ] ) ) { |
629 | 629 | $model_query_params[ 'caps' ] = $this->validate_context( $query_parameters[ 'caps' ] ); |
630 | - }else{ |
|
630 | + } else{ |
|
631 | 631 | $model_query_params[ 'caps' ] = \EEM_Base::caps_read; |
632 | 632 | } |
633 | 633 | return apply_filters( 'FHEE__Read__create_model_query_params', $model_query_params, $query_parameters, $model ); |
@@ -647,7 +647,7 @@ discard block |
||
647 | 647 | foreach( $query_params as $key => $value ) { |
648 | 648 | if( is_array( $value ) ) { |
649 | 649 | $model_ready_query_params[ $key ] = $this->prepare_rest_query_params_key_for_models( $model, $value ); |
650 | - }else{ |
|
650 | + } else{ |
|
651 | 651 | $model_ready_query_params[ $key ] = $value; |
652 | 652 | } |
653 | 653 | } |
@@ -689,11 +689,11 @@ discard block |
||
689 | 689 | //found the model name at the exact start |
690 | 690 | $field_sans_model_name = str_replace( $model_name . '.', '', $field_to_include ); |
691 | 691 | $extracted_fields_to_include[] = $field_sans_model_name; |
692 | - }elseif( $field_to_include == $model_name ){ |
|
692 | + } elseif( $field_to_include == $model_name ){ |
|
693 | 693 | $extracted_fields_to_include[] = '*'; |
694 | 694 | } |
695 | 695 | } |
696 | - }else{ |
|
696 | + } else{ |
|
697 | 697 | //look for ones with no period |
698 | 698 | foreach( $includes as $field_to_include ) { |
699 | 699 | $field_to_include = trim( $field_to_include ); |
@@ -1,8 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | namespace EventEspresso\core\libraries\rest_api\controllers\model; |
3 | 3 | use EventEspresso\core\libraries\rest_api\Capabilities; |
4 | -if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
5 | - exit( 'No direct script access allowed' ); |
|
4 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
5 | + exit('No direct script access allowed'); |
|
6 | 6 | } |
7 | 7 | |
8 | 8 | /** |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | |
25 | 25 | public function __construct() { |
26 | 26 | parent::__construct(); |
27 | - \EE_Registry::instance()->load_helper( 'Inflector' ); |
|
27 | + \EE_Registry::instance()->load_helper('Inflector'); |
|
28 | 28 | } |
29 | 29 | |
30 | 30 | /** |
@@ -32,22 +32,22 @@ discard block |
||
32 | 32 | * @param \WP_REST_Request $request |
33 | 33 | * @return \WP_REST_Response|\WP_Error |
34 | 34 | */ |
35 | - public static function handle_request_get_all( \WP_REST_Request $request) { |
|
35 | + public static function handle_request_get_all(\WP_REST_Request $request) { |
|
36 | 36 | $controller = new Read(); |
37 | - try{ |
|
37 | + try { |
|
38 | 38 | $matches = $controller->parse_route( |
39 | 39 | $request->get_route(), |
40 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)~', |
|
41 | - array( 'version', 'model' ) |
|
40 | + '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)~', |
|
41 | + array('version', 'model') |
|
42 | 42 | ); |
43 | - $controller->set_requested_version( $matches[ 'version' ] ); |
|
44 | - $model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'model' ] ); |
|
45 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $model_name_singular ) ) { |
|
43 | + $controller->set_requested_version($matches['version']); |
|
44 | + $model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
|
45 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) { |
|
46 | 46 | return $controller->send_response( |
47 | 47 | new \WP_Error( |
48 | 48 | 'endpoint_parsing_error', |
49 | 49 | sprintf( |
50 | - __( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ), |
|
50 | + __('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), |
|
51 | 51 | $model_name_singular |
52 | 52 | ) |
53 | 53 | ) |
@@ -55,12 +55,12 @@ discard block |
||
55 | 55 | } |
56 | 56 | return $controller->send_response( |
57 | 57 | $controller->get_entities_from_model( |
58 | - $controller->get_model_version_info()->load_model( $model_name_singular ), |
|
58 | + $controller->get_model_version_info()->load_model($model_name_singular), |
|
59 | 59 | $request |
60 | 60 | ) |
61 | 61 | ); |
62 | - } catch( \Exception $e ) { |
|
63 | - return $controller->send_response( $e ); |
|
62 | + } catch (\Exception $e) { |
|
63 | + return $controller->send_response($e); |
|
64 | 64 | } |
65 | 65 | } |
66 | 66 | |
@@ -70,21 +70,21 @@ discard block |
||
70 | 70 | * @param \WP_Rest_Request $request |
71 | 71 | * @return \WP_REST_Response|\WP_Error |
72 | 72 | */ |
73 | - public static function handle_request_get_one( \WP_Rest_Request $request ) { |
|
73 | + public static function handle_request_get_one(\WP_Rest_Request $request) { |
|
74 | 74 | $controller = new Read(); |
75 | - try{ |
|
75 | + try { |
|
76 | 76 | $matches = $controller->parse_route( |
77 | 77 | $request->get_route(), |
78 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)~', |
|
79 | - array( 'version', 'model', 'id' ) ); |
|
80 | - $controller->set_requested_version( $matches[ 'version' ] ); |
|
81 | - $model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'model' ] ); |
|
82 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $model_name_singular ) ) { |
|
78 | + '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)/(.*)~', |
|
79 | + array('version', 'model', 'id') ); |
|
80 | + $controller->set_requested_version($matches['version']); |
|
81 | + $model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
|
82 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) { |
|
83 | 83 | return $controller->send_response( |
84 | 84 | new \WP_Error( |
85 | 85 | 'endpoint_parsing_error', |
86 | 86 | sprintf( |
87 | - __( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ), |
|
87 | + __('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), |
|
88 | 88 | $model_name_singular |
89 | 89 | ) |
90 | 90 | ) |
@@ -92,12 +92,12 @@ discard block |
||
92 | 92 | } |
93 | 93 | return $controller->send_response( |
94 | 94 | $controller->get_entity_from_model( |
95 | - $controller->get_model_version_info()->load_model( $model_name_singular ), |
|
95 | + $controller->get_model_version_info()->load_model($model_name_singular), |
|
96 | 96 | $request |
97 | 97 | ) |
98 | 98 | ); |
99 | - } catch( \Exception $e ) { |
|
100 | - return $controller->send_response( $e ); |
|
99 | + } catch (\Exception $e) { |
|
100 | + return $controller->send_response($e); |
|
101 | 101 | } |
102 | 102 | } |
103 | 103 | |
@@ -109,35 +109,35 @@ discard block |
||
109 | 109 | * @param \WP_REST_Request $request |
110 | 110 | * @return \WP_REST_Response|\WP_Error |
111 | 111 | */ |
112 | - public static function handle_request_get_related( \WP_REST_Request $request ) { |
|
112 | + public static function handle_request_get_related(\WP_REST_Request $request) { |
|
113 | 113 | $controller = new Read(); |
114 | - try{ |
|
114 | + try { |
|
115 | 115 | $matches = $controller->parse_route( |
116 | 116 | $request->get_route(), |
117 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)/(.*)~', |
|
118 | - array( 'version', 'model', 'id', 'related_model' ) |
|
117 | + '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)/(.*)/(.*)~', |
|
118 | + array('version', 'model', 'id', 'related_model') |
|
119 | 119 | ); |
120 | - $controller->set_requested_version( $matches[ 'version' ] ); |
|
121 | - $main_model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'model' ] ); |
|
122 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $main_model_name_singular ) ) { |
|
120 | + $controller->set_requested_version($matches['version']); |
|
121 | + $main_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
|
122 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($main_model_name_singular)) { |
|
123 | 123 | return $controller->send_response( |
124 | 124 | new \WP_Error( |
125 | 125 | 'endpoint_parsing_error', |
126 | 126 | sprintf( |
127 | - __( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ), |
|
127 | + __('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), |
|
128 | 128 | $main_model_name_singular |
129 | 129 | ) |
130 | 130 | ) |
131 | 131 | ); |
132 | 132 | } |
133 | - $main_model = $controller->get_model_version_info()->load_model( $main_model_name_singular ); |
|
134 | - $related_model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'related_model' ] ); |
|
135 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $related_model_name_singular ) ) { |
|
133 | + $main_model = $controller->get_model_version_info()->load_model($main_model_name_singular); |
|
134 | + $related_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['related_model']); |
|
135 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) { |
|
136 | 136 | return $controller->send_response( |
137 | 137 | new \WP_Error( |
138 | 138 | 'endpoint_parsing_error', |
139 | 139 | sprintf( |
140 | - __( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ), |
|
140 | + __('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), |
|
141 | 141 | $related_model_name_singular |
142 | 142 | ) |
143 | 143 | ) |
@@ -146,13 +146,13 @@ discard block |
||
146 | 146 | |
147 | 147 | return $controller->send_response( |
148 | 148 | $controller->get_entities_from_relation( |
149 | - $request->get_param( 'id' ), |
|
150 | - $main_model->related_settings_for( $related_model_name_singular ) , |
|
149 | + $request->get_param('id'), |
|
150 | + $main_model->related_settings_for($related_model_name_singular), |
|
151 | 151 | $request |
152 | 152 | ) |
153 | 153 | ); |
154 | - } catch( \Exception $e ) { |
|
155 | - return $controller->send_response( $e ); |
|
154 | + } catch (\Exception $e) { |
|
155 | + return $controller->send_response($e); |
|
156 | 156 | } |
157 | 157 | } |
158 | 158 | |
@@ -165,30 +165,30 @@ discard block |
||
165 | 165 | * @param \WP_REST_Request $request |
166 | 166 | * @return array |
167 | 167 | */ |
168 | - public function get_entities_from_model( $model, $request) { |
|
169 | - $query_params = $this->create_model_query_params( $model, $request->get_params() ); |
|
170 | - if( ! Capabilities::current_user_has_partial_access_to( $model, $query_params[ 'caps' ] ) ) { |
|
171 | - $model_name_plural = \EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() ); |
|
168 | + public function get_entities_from_model($model, $request) { |
|
169 | + $query_params = $this->create_model_query_params($model, $request->get_params()); |
|
170 | + if ( ! Capabilities::current_user_has_partial_access_to($model, $query_params['caps'])) { |
|
171 | + $model_name_plural = \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()); |
|
172 | 172 | return new \WP_Error( |
173 | - sprintf( 'rest_%s_cannot_list', $model_name_plural ), |
|
173 | + sprintf('rest_%s_cannot_list', $model_name_plural), |
|
174 | 174 | sprintf( |
175 | - __( 'Sorry, you are not allowed to list %1$s. Missing permissions: %2$s', 'event_espresso' ), |
|
175 | + __('Sorry, you are not allowed to list %1$s. Missing permissions: %2$s', 'event_espresso'), |
|
176 | 176 | $model_name_plural, |
177 | - Capabilities::get_missing_permissions_string( $model, $query_params[ 'caps' ] ) |
|
177 | + Capabilities::get_missing_permissions_string($model, $query_params['caps']) |
|
178 | 178 | ), |
179 | - array( 'status' => 403 ) |
|
179 | + array('status' => 403) |
|
180 | 180 | ); |
181 | 181 | } |
182 | 182 | |
183 | - $this->_set_debug_info( 'model query params', $query_params ); |
|
184 | - $results = $model->get_all_wpdb_results( $query_params ); |
|
183 | + $this->_set_debug_info('model query params', $query_params); |
|
184 | + $results = $model->get_all_wpdb_results($query_params); |
|
185 | 185 | $nice_results = array( ); |
186 | - foreach ( $results as $result ) { |
|
187 | - $nice_results[ ] = $this->create_entity_from_wpdb_result( |
|
186 | + foreach ($results as $result) { |
|
187 | + $nice_results[] = $this->create_entity_from_wpdb_result( |
|
188 | 188 | $model, |
189 | 189 | $result, |
190 | - $request->get_param( 'include' ), |
|
191 | - $query_params[ 'caps' ] |
|
190 | + $request->get_param('include'), |
|
191 | + $query_params['caps'] |
|
192 | 192 | ); |
193 | 193 | } |
194 | 194 | return $nice_results; |
@@ -205,82 +205,82 @@ discard block |
||
205 | 205 | * @param \WP_REST_Request $request |
206 | 206 | * @return array |
207 | 207 | */ |
208 | - public function get_entities_from_relation( $id, $relation, $request ) { |
|
209 | - $context = $this->validate_context( $request->get_param( 'caps' )); |
|
208 | + public function get_entities_from_relation($id, $relation, $request) { |
|
209 | + $context = $this->validate_context($request->get_param('caps')); |
|
210 | 210 | $model = $relation->get_this_model(); |
211 | 211 | $related_model = $relation->get_other_model(); |
212 | 212 | //check if they can access the 1st model object |
213 | - $query_params = array( array( $model->primary_key_name() => $id ),'limit' => 1 ); |
|
214 | - if( $model instanceof \EEM_Soft_Delete_Base ){ |
|
213 | + $query_params = array(array($model->primary_key_name() => $id), 'limit' => 1); |
|
214 | + if ($model instanceof \EEM_Soft_Delete_Base) { |
|
215 | 215 | $query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
216 | 216 | } |
217 | 217 | $restricted_query_params = $query_params; |
218 | - $restricted_query_params[ 'caps' ] = $context; |
|
219 | - $this->_set_debug_info( 'main model query params', $restricted_query_params ); |
|
220 | - $this->_set_debug_info( 'missing caps', Capabilities::get_missing_permissions_string( $related_model, $context ) ); |
|
218 | + $restricted_query_params['caps'] = $context; |
|
219 | + $this->_set_debug_info('main model query params', $restricted_query_params); |
|
220 | + $this->_set_debug_info('missing caps', Capabilities::get_missing_permissions_string($related_model, $context)); |
|
221 | 221 | |
222 | - if( |
|
222 | + if ( |
|
223 | 223 | ! ( |
224 | - Capabilities::current_user_has_partial_access_to( $related_model, $context ) |
|
225 | - && $model->exists( $restricted_query_params ) |
|
224 | + Capabilities::current_user_has_partial_access_to($related_model, $context) |
|
225 | + && $model->exists($restricted_query_params) |
|
226 | 226 | ) |
227 | - ){ |
|
228 | - if( $relation instanceof \EE_Belongs_To_Relation ) { |
|
229 | - $related_model_name_maybe_plural = strtolower( $related_model->get_this_model_name() ); |
|
230 | - }else{ |
|
231 | - $related_model_name_maybe_plural = \EEH_Inflector::pluralize_and_lower( $related_model->get_this_model_name() ); |
|
227 | + ) { |
|
228 | + if ($relation instanceof \EE_Belongs_To_Relation) { |
|
229 | + $related_model_name_maybe_plural = strtolower($related_model->get_this_model_name()); |
|
230 | + } else { |
|
231 | + $related_model_name_maybe_plural = \EEH_Inflector::pluralize_and_lower($related_model->get_this_model_name()); |
|
232 | 232 | } |
233 | 233 | return new \WP_Error( |
234 | - sprintf( 'rest_%s_cannot_list', $related_model_name_maybe_plural ), |
|
234 | + sprintf('rest_%s_cannot_list', $related_model_name_maybe_plural), |
|
235 | 235 | sprintf( |
236 | - __( 'Sorry, you are not allowed to list %1$s related to %2$s. Missing permissions: %3$s', 'event_espresso' ), |
|
236 | + __('Sorry, you are not allowed to list %1$s related to %2$s. Missing permissions: %3$s', 'event_espresso'), |
|
237 | 237 | $related_model_name_maybe_plural, |
238 | 238 | $relation->get_this_model()->get_this_model_name(), |
239 | 239 | implode( |
240 | 240 | ',', |
241 | 241 | array_keys( |
242 | - Capabilities::get_missing_permissions( $related_model, $context ) |
|
242 | + Capabilities::get_missing_permissions($related_model, $context) |
|
243 | 243 | ) |
244 | 244 | ) |
245 | 245 | ), |
246 | - array( 'status' => 403 ) |
|
246 | + array('status' => 403) |
|
247 | 247 | ); |
248 | 248 | } |
249 | - $query_params = $this->create_model_query_params( $relation->get_other_model(), $request->get_params() ); |
|
250 | - $query_params[0][ $relation->get_this_model()->get_this_model_name() . '.' . $relation->get_this_model()->primary_key_name() ] = $id; |
|
251 | - $query_params[ 'default_where_conditions' ] = 'none'; |
|
252 | - $query_params[ 'caps' ] = $context; |
|
253 | - $this->_set_debug_info( 'model query params', $query_params ); |
|
254 | - $results = $relation->get_other_model()->get_all_wpdb_results( $query_params ); |
|
249 | + $query_params = $this->create_model_query_params($relation->get_other_model(), $request->get_params()); |
|
250 | + $query_params[0][$relation->get_this_model()->get_this_model_name().'.'.$relation->get_this_model()->primary_key_name()] = $id; |
|
251 | + $query_params['default_where_conditions'] = 'none'; |
|
252 | + $query_params['caps'] = $context; |
|
253 | + $this->_set_debug_info('model query params', $query_params); |
|
254 | + $results = $relation->get_other_model()->get_all_wpdb_results($query_params); |
|
255 | 255 | $nice_results = array(); |
256 | - foreach( $results as $result ) { |
|
256 | + foreach ($results as $result) { |
|
257 | 257 | $nice_result = $this->create_entity_from_wpdb_result( |
258 | 258 | $relation->get_other_model(), |
259 | 259 | $result, |
260 | - $request->get_param( 'include' ), |
|
261 | - $query_params[ 'caps' ] |
|
260 | + $request->get_param('include'), |
|
261 | + $query_params['caps'] |
|
262 | 262 | ); |
263 | - if( $relation instanceof \EE_HABTM_Relation ) { |
|
263 | + if ($relation instanceof \EE_HABTM_Relation) { |
|
264 | 264 | //put the unusual stuff (properties from the HABTM relation) first, and make sure |
265 | 265 | //if there are conflicts we prefer the properties from the main model |
266 | 266 | $join_model_result = $this->create_entity_from_wpdb_result( |
267 | 267 | $relation->get_join_model(), |
268 | 268 | $result, |
269 | - $request->get_param( 'include' ), |
|
270 | - $query_params[ 'caps' ] |
|
269 | + $request->get_param('include'), |
|
270 | + $query_params['caps'] |
|
271 | 271 | ); |
272 | - $joined_result = array_merge( $nice_result, $join_model_result ); |
|
272 | + $joined_result = array_merge($nice_result, $join_model_result); |
|
273 | 273 | //but keep the meta stuff from the main model |
274 | - if( isset( $nice_result['meta'] ) ){ |
|
274 | + if (isset($nice_result['meta'])) { |
|
275 | 275 | $joined_result['meta'] = $nice_result['meta']; |
276 | 276 | } |
277 | 277 | $nice_result = $joined_result; |
278 | 278 | } |
279 | 279 | $nice_results[] = $nice_result; |
280 | 280 | } |
281 | - if( $relation instanceof \EE_Belongs_To_Relation ){ |
|
282 | - return array_shift( $nice_results ); |
|
283 | - }else{ |
|
281 | + if ($relation instanceof \EE_Belongs_To_Relation) { |
|
282 | + return array_shift($nice_results); |
|
283 | + } else { |
|
284 | 284 | return $nice_results; |
285 | 285 | } |
286 | 286 | } |
@@ -317,110 +317,110 @@ discard block |
||
317 | 317 | * @param string $context one of the return values from EEM_Base::valid_cap_contexts() |
318 | 318 | * @return array ready for being converted into json for sending to client |
319 | 319 | */ |
320 | - public function create_entity_from_wpdb_result( $model, $db_row, $include, $context ) { |
|
321 | - if( $include == null ) { |
|
320 | + public function create_entity_from_wpdb_result($model, $db_row, $include, $context) { |
|
321 | + if ($include == null) { |
|
322 | 322 | $include = '*'; |
323 | 323 | } |
324 | - if( $context == null ) { |
|
324 | + if ($context == null) { |
|
325 | 325 | $context = \EEM_Base::caps_read; |
326 | 326 | } |
327 | - $result = $model->deduce_fields_n_values_from_cols_n_values( $db_row ); |
|
328 | - $result = array_intersect_key( $result, $this->get_model_version_info()->fields_on_model_in_this_version( $model ) ); |
|
329 | - foreach( $result as $field_name => $raw_field_value ) { |
|
327 | + $result = $model->deduce_fields_n_values_from_cols_n_values($db_row); |
|
328 | + $result = array_intersect_key($result, $this->get_model_version_info()->fields_on_model_in_this_version($model)); |
|
329 | + foreach ($result as $field_name => $raw_field_value) { |
|
330 | 330 | $field_obj = $model->field_settings_for($field_name); |
331 | - $field_value = $field_obj->prepare_for_set_from_db( $raw_field_value ); |
|
332 | - if( $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_ignored() ) ){ |
|
333 | - unset( $result[ $field_name ] ); |
|
334 | - }elseif( |
|
335 | - $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_that_have_rendered_format() ) |
|
336 | - ){ |
|
337 | - $result[ $field_name ] = array( |
|
338 | - 'raw' => $field_obj->prepare_for_get( $field_value ), |
|
339 | - 'rendered' => $field_obj->prepare_for_pretty_echoing( $field_value ) |
|
331 | + $field_value = $field_obj->prepare_for_set_from_db($raw_field_value); |
|
332 | + if ($this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_ignored())) { |
|
333 | + unset($result[$field_name]); |
|
334 | + }elseif ( |
|
335 | + $this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_that_have_rendered_format()) |
|
336 | + ) { |
|
337 | + $result[$field_name] = array( |
|
338 | + 'raw' => $field_obj->prepare_for_get($field_value), |
|
339 | + 'rendered' => $field_obj->prepare_for_pretty_echoing($field_value) |
|
340 | 340 | ); |
341 | - }elseif( |
|
342 | - $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_that_have_pretty_format() ) |
|
343 | - ){ |
|
344 | - $result[ $field_name ] = array( |
|
345 | - 'raw' => $field_obj->prepare_for_get( $field_value ), |
|
346 | - 'pretty' => $field_obj->prepare_for_pretty_echoing( $field_value ) |
|
341 | + }elseif ( |
|
342 | + $this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_that_have_pretty_format()) |
|
343 | + ) { |
|
344 | + $result[$field_name] = array( |
|
345 | + 'raw' => $field_obj->prepare_for_get($field_value), |
|
346 | + 'pretty' => $field_obj->prepare_for_pretty_echoing($field_value) |
|
347 | 347 | ); |
348 | - }elseif( $field_obj instanceof \EE_Datetime_Field ){ |
|
349 | - if( $raw_field_value instanceof \DateTime ) { |
|
350 | - $raw_field_value = $raw_field_value->format( 'c' ); |
|
348 | + }elseif ($field_obj instanceof \EE_Datetime_Field) { |
|
349 | + if ($raw_field_value instanceof \DateTime) { |
|
350 | + $raw_field_value = $raw_field_value->format('c'); |
|
351 | 351 | } |
352 | - $result[ $field_name ] = mysql_to_rfc3339( $raw_field_value ); |
|
353 | - }else{ |
|
354 | - $value_prepared = $field_obj->prepare_for_get( $field_value ); |
|
352 | + $result[$field_name] = mysql_to_rfc3339($raw_field_value); |
|
353 | + } else { |
|
354 | + $value_prepared = $field_obj->prepare_for_get($field_value); |
|
355 | 355 | |
356 | - $result[ $field_name ] = $value_prepared === INF ? EE_INF_IN_DB : $value_prepared; |
|
356 | + $result[$field_name] = $value_prepared === INF ? EE_INF_IN_DB : $value_prepared; |
|
357 | 357 | } |
358 | 358 | } |
359 | - if( $model instanceof \EEM_CPT_Base ) { |
|
359 | + if ($model instanceof \EEM_CPT_Base) { |
|
360 | 360 | $attachment = wp_get_attachment_image_src( |
361 | - get_post_thumbnail_id( $db_row[ $model->get_primary_key_field()->get_qualified_column() ] ), |
|
361 | + get_post_thumbnail_id($db_row[$model->get_primary_key_field()->get_qualified_column()]), |
|
362 | 362 | 'full' |
363 | 363 | ); |
364 | - $result[ 'featured_image_url' ] = !empty( $attachment ) ? $attachment[ 0 ] : null; |
|
365 | - $result[ 'link' ] = get_permalink( $db_row[ $model->get_primary_key_field()->get_qualified_column() ] ); |
|
364 | + $result['featured_image_url'] = ! empty($attachment) ? $attachment[0] : null; |
|
365 | + $result['link'] = get_permalink($db_row[$model->get_primary_key_field()->get_qualified_column()]); |
|
366 | 366 | } |
367 | 367 | //add links to related data |
368 | 368 | $result['_links'] = array( |
369 | 369 | 'self' => array( |
370 | 370 | array( |
371 | 371 | 'href' => $this->get_versioned_link_to( |
372 | - \EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() ) . '/' . $result[ $model->primary_key_name() ] |
|
372 | + \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()).'/'.$result[$model->primary_key_name()] |
|
373 | 373 | ) |
374 | 374 | ) |
375 | 375 | ), |
376 | 376 | 'collection' => array( |
377 | 377 | array( |
378 | 378 | 'href' => $this->get_versioned_link_to( |
379 | - \EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() ) |
|
379 | + \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()) |
|
380 | 380 | ) |
381 | 381 | ) |
382 | 382 | ), |
383 | 383 | ); |
384 | 384 | global $wp_rest_server; |
385 | - if( $model instanceof \EEM_CPT_Base && |
|
385 | + if ($model instanceof \EEM_CPT_Base && |
|
386 | 386 | $wp_rest_server instanceof \WP_REST_Server && |
387 | - $wp_rest_server->get_route_options( '/wp/v2/posts' ) ) { |
|
388 | - $result[ '_links' ][ 'https://api.eventespresso.com/self_wp_post' ] = array( |
|
387 | + $wp_rest_server->get_route_options('/wp/v2/posts')) { |
|
388 | + $result['_links']['https://api.eventespresso.com/self_wp_post'] = array( |
|
389 | 389 | array( |
390 | - 'href' => rest_url( '/wp/v2/posts/' . $db_row[ $model->get_primary_key_field()->get_qualified_column() ] ), |
|
390 | + 'href' => rest_url('/wp/v2/posts/'.$db_row[$model->get_primary_key_field()->get_qualified_column()]), |
|
391 | 391 | 'single' => true |
392 | 392 | ) |
393 | 393 | ); |
394 | 394 | } |
395 | 395 | |
396 | 396 | //filter fields if specified |
397 | - $includes_for_this_model = $this->extract_includes_for_this_model( $include ); |
|
398 | - if( ! empty( $includes_for_this_model ) ) { |
|
399 | - if( $model->has_primary_key_field() ) { |
|
397 | + $includes_for_this_model = $this->extract_includes_for_this_model($include); |
|
398 | + if ( ! empty($includes_for_this_model)) { |
|
399 | + if ($model->has_primary_key_field()) { |
|
400 | 400 | //always include the primary key |
401 | 401 | $includes_for_this_model[] = $model->primary_key_name(); |
402 | 402 | } |
403 | - $result = array_intersect_key( $result, array_flip( $includes_for_this_model ) ); |
|
403 | + $result = array_intersect_key($result, array_flip($includes_for_this_model)); |
|
404 | 404 | } |
405 | 405 | //add meta links and possibly include related models |
406 | 406 | $relation_settings = apply_filters( |
407 | 407 | 'FHEE__Read__create_entity_from_wpdb_result__related_models_to_include', |
408 | 408 | $model->relation_settings() |
409 | 409 | ); |
410 | - foreach( $relation_settings as $relation_name => $relation_obj ) { |
|
411 | - $related_model_part = $this->get_related_entity_name( $relation_name, $relation_obj ); |
|
412 | - if( empty( $includes_for_this_model ) || isset( $includes_for_this_model['meta'] ) ) { |
|
413 | - $result['_links']['https://api.eventespresso.com/' . $related_model_part] = array( |
|
410 | + foreach ($relation_settings as $relation_name => $relation_obj) { |
|
411 | + $related_model_part = $this->get_related_entity_name($relation_name, $relation_obj); |
|
412 | + if (empty($includes_for_this_model) || isset($includes_for_this_model['meta'])) { |
|
413 | + $result['_links']['https://api.eventespresso.com/'.$related_model_part] = array( |
|
414 | 414 | array( |
415 | 415 | 'href' => $this->get_versioned_link_to( |
416 | - \EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() ) . '/' . $result[ $model->primary_key_name() ] . '/' . $related_model_part |
|
416 | + \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()).'/'.$result[$model->primary_key_name()].'/'.$related_model_part |
|
417 | 417 | ), |
418 | 418 | 'single' => $relation_obj instanceof \EE_Belongs_To_Relation ? true : false |
419 | 419 | ) |
420 | 420 | ); |
421 | 421 | } |
422 | - $related_fields_to_include = $this->extract_includes_for_this_model( $include, $relation_name ); |
|
423 | - if( $related_fields_to_include ) { |
|
422 | + $related_fields_to_include = $this->extract_includes_for_this_model($include, $relation_name); |
|
423 | + if ($related_fields_to_include) { |
|
424 | 424 | $pretend_related_request = new \WP_REST_Request(); |
425 | 425 | $pretend_related_request->set_query_params( |
426 | 426 | array( |
@@ -432,11 +432,11 @@ discard block |
||
432 | 432 | ) |
433 | 433 | ); |
434 | 434 | $related_results = $this->get_entities_from_relation( |
435 | - $result[ $model->primary_key_name() ], |
|
435 | + $result[$model->primary_key_name()], |
|
436 | 436 | $relation_obj, |
437 | 437 | $pretend_related_request |
438 | 438 | ); |
439 | - $result[ $related_model_part ] = $related_results instanceof \WP_Error ? null : $related_results; |
|
439 | + $result[$related_model_part] = $related_results instanceof \WP_Error ? null : $related_results; |
|
440 | 440 | } |
441 | 441 | } |
442 | 442 | $result = apply_filters( |
@@ -453,7 +453,7 @@ discard block |
||
453 | 453 | ); |
454 | 454 | $this->_set_debug_info( |
455 | 455 | 'inaccessible fields', |
456 | - array_keys( array_diff_key( $result, $result_without_inaccessible_fields ) ) |
|
456 | + array_keys(array_diff_key($result, $result_without_inaccessible_fields)) |
|
457 | 457 | ); |
458 | 458 | return apply_filters( |
459 | 459 | 'FHEE__Read__create_entity_from_wpdb_results__entity_return', |
@@ -468,8 +468,8 @@ discard block |
||
468 | 468 | * @param string $link_part_after_version_and_slash eg "events/10/datetimes" |
469 | 469 | * @return string url eg "http://mysite.com/wp-json/ee/v4.6/events/10/datetimes" |
470 | 470 | */ |
471 | - public function get_versioned_link_to( $link_part_after_version_and_slash ) { |
|
472 | - return rest_url( \EED_Core_Rest_Api::ee_api_namespace . $this->get_model_version_info()->requested_version() . '/' . $link_part_after_version_and_slash ); |
|
471 | + public function get_versioned_link_to($link_part_after_version_and_slash) { |
|
472 | + return rest_url(\EED_Core_Rest_Api::ee_api_namespace.$this->get_model_version_info()->requested_version().'/'.$link_part_after_version_and_slash); |
|
473 | 473 | } |
474 | 474 | |
475 | 475 | /** |
@@ -479,11 +479,11 @@ discard block |
||
479 | 479 | * @param \EE_Model_Relation_Base $relation_obj |
480 | 480 | * @return string |
481 | 481 | */ |
482 | - public static function get_related_entity_name( $relation_name, $relation_obj ){ |
|
483 | - if( $relation_obj instanceof \EE_Belongs_To_Relation ) { |
|
484 | - return strtolower( $relation_name ); |
|
485 | - }else{ |
|
486 | - return \EEH_Inflector::pluralize_and_lower( $relation_name ); |
|
482 | + public static function get_related_entity_name($relation_name, $relation_obj) { |
|
483 | + if ($relation_obj instanceof \EE_Belongs_To_Relation) { |
|
484 | + return strtolower($relation_name); |
|
485 | + } else { |
|
486 | + return \EEH_Inflector::pluralize_and_lower($relation_name); |
|
487 | 487 | } |
488 | 488 | } |
489 | 489 | |
@@ -496,44 +496,44 @@ discard block |
||
496 | 496 | * @param \WP_REST_Request $request |
497 | 497 | * @return array |
498 | 498 | */ |
499 | - public function get_entity_from_model( $model, $request ) { |
|
500 | - $query_params = array( array( $model->primary_key_name() => $request->get_param( 'id' ) ),'limit' => 1); |
|
501 | - if( $model instanceof \EEM_Soft_Delete_Base ){ |
|
499 | + public function get_entity_from_model($model, $request) { |
|
500 | + $query_params = array(array($model->primary_key_name() => $request->get_param('id')), 'limit' => 1); |
|
501 | + if ($model instanceof \EEM_Soft_Delete_Base) { |
|
502 | 502 | $query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
503 | 503 | } |
504 | 504 | $restricted_query_params = $query_params; |
505 | - $restricted_query_params[ 'caps' ] = $this->validate_context( $request->get_param( 'caps' ) ); |
|
506 | - $this->_set_debug_info( 'model query params', $restricted_query_params ); |
|
507 | - $model_rows = $model->get_all_wpdb_results( $restricted_query_params ); |
|
508 | - if ( ! empty ( $model_rows ) ) { |
|
505 | + $restricted_query_params['caps'] = $this->validate_context($request->get_param('caps')); |
|
506 | + $this->_set_debug_info('model query params', $restricted_query_params); |
|
507 | + $model_rows = $model->get_all_wpdb_results($restricted_query_params); |
|
508 | + if ( ! empty ($model_rows)) { |
|
509 | 509 | return $this->create_entity_from_wpdb_result( |
510 | 510 | $model, |
511 | - array_shift( $model_rows ), |
|
512 | - $request->get_param( 'include' ), |
|
513 | - $this->validate_context( $request->get_param( 'caps' ) ) ); |
|
511 | + array_shift($model_rows), |
|
512 | + $request->get_param('include'), |
|
513 | + $this->validate_context($request->get_param('caps')) ); |
|
514 | 514 | } else { |
515 | 515 | //ok let's test to see if we WOULD have found it, had we not had restrictions from missing capabilities |
516 | - $lowercase_model_name = strtolower( $model->get_this_model_name() ); |
|
517 | - $model_rows_found_sans_restrictions = $model->get_all_wpdb_results( $query_params ); |
|
518 | - if( ! empty( $model_rows_found_sans_restrictions ) ) { |
|
516 | + $lowercase_model_name = strtolower($model->get_this_model_name()); |
|
517 | + $model_rows_found_sans_restrictions = $model->get_all_wpdb_results($query_params); |
|
518 | + if ( ! empty($model_rows_found_sans_restrictions)) { |
|
519 | 519 | //you got shafted- it existed but we didn't want to tell you! |
520 | 520 | return new \WP_Error( |
521 | 521 | 'rest_user_cannot_read', |
522 | 522 | sprintf( |
523 | - __( 'Sorry, you cannot read this %1$s. Missing permissions are: %2$s', 'event_espresso' ), |
|
524 | - strtolower( $model->get_this_model_name() ), |
|
523 | + __('Sorry, you cannot read this %1$s. Missing permissions are: %2$s', 'event_espresso'), |
|
524 | + strtolower($model->get_this_model_name()), |
|
525 | 525 | Capabilities::get_missing_permissions_string( |
526 | 526 | $model, |
527 | - $this->validate_context( $request->get_param( 'caps' ) ) ) |
|
527 | + $this->validate_context($request->get_param('caps')) ) |
|
528 | 528 | ), |
529 | - array( 'status' => 403 ) |
|
529 | + array('status' => 403) |
|
530 | 530 | ); |
531 | 531 | } else { |
532 | 532 | //it's not you. It just doesn't exist |
533 | 533 | return new \WP_Error( |
534 | - sprintf( 'rest_%s_invalid_id', $lowercase_model_name ), |
|
535 | - sprintf( __( 'Invalid %s ID.', 'event_espresso' ), $lowercase_model_name ), |
|
536 | - array( 'status' => 404 ) |
|
534 | + sprintf('rest_%s_invalid_id', $lowercase_model_name), |
|
535 | + sprintf(__('Invalid %s ID.', 'event_espresso'), $lowercase_model_name), |
|
536 | + array('status' => 404) |
|
537 | 537 | ); |
538 | 538 | } |
539 | 539 | } |
@@ -546,14 +546,14 @@ discard block |
||
546 | 546 | * @param string $context |
547 | 547 | * @return string array key of EEM_Base::cap_contexts_to_cap_action_map() |
548 | 548 | */ |
549 | - public function validate_context( $context ) { |
|
550 | - if( ! $context ) { |
|
549 | + public function validate_context($context) { |
|
550 | + if ( ! $context) { |
|
551 | 551 | $context = \EEM_Base::caps_read; |
552 | 552 | } |
553 | 553 | $valid_contexts = \EEM_Base::valid_cap_contexts(); |
554 | - if( in_array( $context, $valid_contexts ) ){ |
|
554 | + if (in_array($context, $valid_contexts)) { |
|
555 | 555 | return $context; |
556 | - }else{ |
|
556 | + } else { |
|
557 | 557 | return \EEM_Base::caps_read; |
558 | 558 | } |
559 | 559 | } |
@@ -569,73 +569,73 @@ discard block |
||
569 | 569 | * that absolutely no results should be returned |
570 | 570 | * @throws \EE_Error |
571 | 571 | */ |
572 | - public function create_model_query_params( $model, $query_parameters ) { |
|
572 | + public function create_model_query_params($model, $query_parameters) { |
|
573 | 573 | $model_query_params = array( ); |
574 | - if ( isset( $query_parameters[ 'where' ] ) ) { |
|
575 | - $model_query_params[ 0 ] = $this->prepare_rest_query_params_key_for_models( $model, $query_parameters[ 'where' ] ); |
|
576 | - } |
|
577 | - if ( isset( $query_parameters[ 'order_by' ] ) ) { |
|
578 | - $order_by = $query_parameters[ 'order_by' ]; |
|
579 | - } elseif ( isset( $query_parameters[ 'orderby' ] ) ) { |
|
580 | - $order_by = $query_parameters[ 'orderby' ]; |
|
581 | - }else{ |
|
574 | + if (isset($query_parameters['where'])) { |
|
575 | + $model_query_params[0] = $this->prepare_rest_query_params_key_for_models($model, $query_parameters['where']); |
|
576 | + } |
|
577 | + if (isset($query_parameters['order_by'])) { |
|
578 | + $order_by = $query_parameters['order_by']; |
|
579 | + } elseif (isset($query_parameters['orderby'])) { |
|
580 | + $order_by = $query_parameters['orderby']; |
|
581 | + } else { |
|
582 | 582 | $order_by = null; |
583 | 583 | } |
584 | - if( $order_by !== null ){ |
|
585 | - $model_query_params[ 'order_by' ] = $this->prepare_rest_query_params_key_for_models( $model, $order_by ); |
|
584 | + if ($order_by !== null) { |
|
585 | + $model_query_params['order_by'] = $this->prepare_rest_query_params_key_for_models($model, $order_by); |
|
586 | 586 | } |
587 | - if ( isset( $query_parameters[ 'group_by' ] ) ) { |
|
588 | - $group_by = $query_parameters[ 'group_by' ]; |
|
589 | - } elseif ( isset( $query_parameters[ 'groupby' ] ) ) { |
|
590 | - $group_by = $query_parameters[ 'groupby' ]; |
|
591 | - }else{ |
|
587 | + if (isset($query_parameters['group_by'])) { |
|
588 | + $group_by = $query_parameters['group_by']; |
|
589 | + } elseif (isset($query_parameters['groupby'])) { |
|
590 | + $group_by = $query_parameters['groupby']; |
|
591 | + } else { |
|
592 | 592 | $group_by = null; |
593 | 593 | } |
594 | - if( $group_by !== null ){ |
|
595 | - if( is_array( $group_by ) ) { |
|
596 | - $group_by = $this->prepare_rest_query_params_values_for_models( $model, $group_by ); |
|
594 | + if ($group_by !== null) { |
|
595 | + if (is_array($group_by)) { |
|
596 | + $group_by = $this->prepare_rest_query_params_values_for_models($model, $group_by); |
|
597 | 597 | } |
598 | - $model_query_params[ 'group_by' ] = $group_by; |
|
598 | + $model_query_params['group_by'] = $group_by; |
|
599 | 599 | } |
600 | - if ( isset( $query_parameters[ 'having' ] ) ) { |
|
600 | + if (isset($query_parameters['having'])) { |
|
601 | 601 | //@todo: no good for permissions |
602 | - $model_query_params[ 'having' ] = $this->prepare_rest_query_params_key_for_models( $model, $query_parameters[ 'having' ] ); |
|
602 | + $model_query_params['having'] = $this->prepare_rest_query_params_key_for_models($model, $query_parameters['having']); |
|
603 | 603 | } |
604 | - if ( isset( $query_parameters[ 'order' ] ) ) { |
|
605 | - $model_query_params[ 'order' ] = $query_parameters[ 'order' ]; |
|
604 | + if (isset($query_parameters['order'])) { |
|
605 | + $model_query_params['order'] = $query_parameters['order']; |
|
606 | 606 | } |
607 | - if ( isset( $query_parameters[ 'mine' ] ) ){ |
|
608 | - $model_query_params = $model->alter_query_params_to_only_include_mine( $model_query_params ); |
|
607 | + if (isset($query_parameters['mine'])) { |
|
608 | + $model_query_params = $model->alter_query_params_to_only_include_mine($model_query_params); |
|
609 | 609 | } |
610 | - if( isset( $query_parameters[ 'limit' ] ) ) { |
|
610 | + if (isset($query_parameters['limit'])) { |
|
611 | 611 | //limit should be either a string like '23' or '23,43', or an array with two items in it |
612 | - if( is_string( $query_parameters[ 'limit' ] ) ) { |
|
612 | + if (is_string($query_parameters['limit'])) { |
|
613 | 613 | $limit_array = explode(',', $query_parameters['limit']); |
614 | - }else { |
|
615 | - $limit_array = $query_parameters[ 'limit' ]; |
|
614 | + } else { |
|
615 | + $limit_array = $query_parameters['limit']; |
|
616 | 616 | } |
617 | 617 | $sanitized_limit = array(); |
618 | - foreach( $limit_array as $key => $limit_part ) { |
|
619 | - if( $this->_debug_mode && ( ! is_numeric( $limit_part ) || count( $sanitized_limit ) > 2 ) ) { |
|
618 | + foreach ($limit_array as $key => $limit_part) { |
|
619 | + if ($this->_debug_mode && ( ! is_numeric($limit_part) || count($sanitized_limit) > 2)) { |
|
620 | 620 | throw new \EE_Error( |
621 | 621 | sprintf( |
622 | - __( 'An invalid limit filter was provided. It was: %s. If the EE4 JSON REST API weren\'t in debug mode, this message would not appear.', 'event_espresso' ), |
|
623 | - json_encode( $query_parameters[ 'limit' ] ) |
|
622 | + __('An invalid limit filter was provided. It was: %s. If the EE4 JSON REST API weren\'t in debug mode, this message would not appear.', 'event_espresso'), |
|
623 | + json_encode($query_parameters['limit']) |
|
624 | 624 | ) |
625 | 625 | ); |
626 | 626 | } |
627 | - $sanitized_limit[] = intval( $limit_part ); |
|
627 | + $sanitized_limit[] = intval($limit_part); |
|
628 | 628 | } |
629 | - $model_query_params[ 'limit' ] = implode( ',', $sanitized_limit ); |
|
630 | - }else{ |
|
631 | - $model_query_params[ 'limit' ] = 50; |
|
629 | + $model_query_params['limit'] = implode(',', $sanitized_limit); |
|
630 | + } else { |
|
631 | + $model_query_params['limit'] = 50; |
|
632 | 632 | } |
633 | - if( isset( $query_parameters[ 'caps' ] ) ) { |
|
634 | - $model_query_params[ 'caps' ] = $this->validate_context( $query_parameters[ 'caps' ] ); |
|
635 | - }else{ |
|
636 | - $model_query_params[ 'caps' ] = \EEM_Base::caps_read; |
|
633 | + if (isset($query_parameters['caps'])) { |
|
634 | + $model_query_params['caps'] = $this->validate_context($query_parameters['caps']); |
|
635 | + } else { |
|
636 | + $model_query_params['caps'] = \EEM_Base::caps_read; |
|
637 | 637 | } |
638 | - return apply_filters( 'FHEE__Read__create_model_query_params', $model_query_params, $query_parameters, $model ); |
|
638 | + return apply_filters('FHEE__Read__create_model_query_params', $model_query_params, $query_parameters, $model); |
|
639 | 639 | } |
640 | 640 | |
641 | 641 | |
@@ -647,24 +647,24 @@ discard block |
||
647 | 647 | * @param array $query_params sub-array from @see EEM_Base::get_all() |
648 | 648 | * @return array |
649 | 649 | */ |
650 | - public function prepare_rest_query_params_key_for_models( $model, $query_params ) { |
|
650 | + public function prepare_rest_query_params_key_for_models($model, $query_params) { |
|
651 | 651 | $model_ready_query_params = array(); |
652 | - foreach( $query_params as $key => $value ) { |
|
653 | - if( is_array( $value ) ) { |
|
654 | - $model_ready_query_params[ $key ] = $this->prepare_rest_query_params_key_for_models( $model, $value ); |
|
655 | - }else{ |
|
656 | - $model_ready_query_params[ $key ] = $value; |
|
652 | + foreach ($query_params as $key => $value) { |
|
653 | + if (is_array($value)) { |
|
654 | + $model_ready_query_params[$key] = $this->prepare_rest_query_params_key_for_models($model, $value); |
|
655 | + } else { |
|
656 | + $model_ready_query_params[$key] = $value; |
|
657 | 657 | } |
658 | 658 | } |
659 | 659 | return $model_ready_query_params; |
660 | 660 | } |
661 | - public function prepare_rest_query_params_values_for_models( $model, $query_params ) { |
|
661 | + public function prepare_rest_query_params_values_for_models($model, $query_params) { |
|
662 | 662 | $model_ready_query_params = array(); |
663 | - foreach( $query_params as $key => $value ) { |
|
664 | - if( is_array( $value ) ) { |
|
665 | - $model_ready_query_params[ $key ] = $this->prepare_rest_query_params_values_for_models( $model, $value ); |
|
663 | + foreach ($query_params as $key => $value) { |
|
664 | + if (is_array($value)) { |
|
665 | + $model_ready_query_params[$key] = $this->prepare_rest_query_params_values_for_models($model, $value); |
|
666 | 666 | } else { |
667 | - $model_ready_query_params[ $key ] = $value; |
|
667 | + $model_ready_query_params[$key] = $value; |
|
668 | 668 | } |
669 | 669 | } |
670 | 670 | return $model_ready_query_params; |
@@ -680,33 +680,33 @@ discard block |
||
680 | 680 | * @return array of fields for this model. If $model_name is provided, then |
681 | 681 | * the fields for that model, with the model's name removed from each. |
682 | 682 | */ |
683 | - public function extract_includes_for_this_model( $include_string, $model_name = null ) { |
|
684 | - if( is_array( $include_string ) ) { |
|
685 | - $include_string = implode( ',', $include_string ); |
|
683 | + public function extract_includes_for_this_model($include_string, $model_name = null) { |
|
684 | + if (is_array($include_string)) { |
|
685 | + $include_string = implode(',', $include_string); |
|
686 | 686 | } |
687 | - if( $include_string === '*' ) { |
|
687 | + if ($include_string === '*') { |
|
688 | 688 | return array(); |
689 | 689 | } |
690 | - $includes = explode( ',', $include_string ); |
|
690 | + $includes = explode(',', $include_string); |
|
691 | 691 | $extracted_fields_to_include = array(); |
692 | - if( $model_name ){ |
|
693 | - foreach( $includes as $field_to_include ) { |
|
694 | - $field_to_include = trim( $field_to_include ); |
|
695 | - if( strpos( $field_to_include, $model_name . '.' ) === 0 ) { |
|
692 | + if ($model_name) { |
|
693 | + foreach ($includes as $field_to_include) { |
|
694 | + $field_to_include = trim($field_to_include); |
|
695 | + if (strpos($field_to_include, $model_name.'.') === 0) { |
|
696 | 696 | //found the model name at the exact start |
697 | - $field_sans_model_name = str_replace( $model_name . '.', '', $field_to_include ); |
|
697 | + $field_sans_model_name = str_replace($model_name.'.', '', $field_to_include); |
|
698 | 698 | $extracted_fields_to_include[] = $field_sans_model_name; |
699 | - }elseif( $field_to_include == $model_name ){ |
|
699 | + }elseif ($field_to_include == $model_name) { |
|
700 | 700 | $extracted_fields_to_include[] = '*'; |
701 | 701 | } |
702 | 702 | } |
703 | - }else{ |
|
703 | + } else { |
|
704 | 704 | //look for ones with no period |
705 | - foreach( $includes as $field_to_include ) { |
|
706 | - $field_to_include = trim( $field_to_include ); |
|
705 | + foreach ($includes as $field_to_include) { |
|
706 | + $field_to_include = trim($field_to_include); |
|
707 | 707 | if ( |
708 | - strpos( $field_to_include, '.' ) === false |
|
709 | - && ! $this->get_model_version_info()->is_model_name_in_this_version( $field_to_include ) |
|
708 | + strpos($field_to_include, '.') === false |
|
709 | + && ! $this->get_model_version_info()->is_model_name_in_this_version($field_to_include) |
|
710 | 710 | ) { |
711 | 711 | $extracted_fields_to_include[] = $field_to_include; |
712 | 712 | } |
@@ -126,7 +126,7 @@ |
||
126 | 126 | * being address info, and 0 being neither) |
127 | 127 | * @global type $wpdb |
128 | 128 | * @param type $new_question_group_id |
129 | - * @return boolean |
|
129 | + * @return integer |
|
130 | 130 | */ |
131 | 131 | private function _is_system_question_group($new_question_group_id){ |
132 | 132 | global $wpdb; |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if (!defined('EVENT_ESPRESSO_VERSION') ) |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
3 | 3 | exit('NO direct script access allowed'); |
4 | 4 | |
5 | 5 | /** |
@@ -30,13 +30,13 @@ discard block |
||
30 | 30 | |
31 | 31 | |
32 | 32 | |
33 | - public function __construct( $routing = TRUE ) { |
|
34 | - define( 'REGISTRATION_FORM_CAF_ADMIN', EE_CORE_CAF_ADMIN_EXTEND . 'registration_form' . DS ); |
|
35 | - define( 'REGISTRATION_FORM_CAF_ASSETS_PATH', REGISTRATION_FORM_CAF_ADMIN . 'assets' . DS ); |
|
36 | - define( 'REGISTRATION_FORM_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/assets/' ); |
|
37 | - define( 'REGISTRATION_FORM_CAF_TEMPLATE_PATH', REGISTRATION_FORM_CAF_ADMIN . 'templates' . DS ); |
|
38 | - define( 'REGISTRATION_FORM_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL . 'registration_form/templates/' ); |
|
39 | - parent::__construct( $routing ); |
|
33 | + public function __construct($routing = TRUE) { |
|
34 | + define('REGISTRATION_FORM_CAF_ADMIN', EE_CORE_CAF_ADMIN_EXTEND.'registration_form'.DS); |
|
35 | + define('REGISTRATION_FORM_CAF_ASSETS_PATH', REGISTRATION_FORM_CAF_ADMIN.'assets'.DS); |
|
36 | + define('REGISTRATION_FORM_CAF_ASSETS_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'registration_form/assets/'); |
|
37 | + define('REGISTRATION_FORM_CAF_TEMPLATE_PATH', REGISTRATION_FORM_CAF_ADMIN.'templates'.DS); |
|
38 | + define('REGISTRATION_FORM_CAF_TEMPLATE_URL', EE_CORE_CAF_ADMIN_EXTEND_URL.'registration_form/templates/'); |
|
39 | + parent::__construct($routing); |
|
40 | 40 | } |
41 | 41 | |
42 | 42 | |
@@ -46,8 +46,8 @@ discard block |
||
46 | 46 | |
47 | 47 | protected function _extend_page_config() { |
48 | 48 | $this->_admin_base_path = REGISTRATION_FORM_CAF_ADMIN; |
49 | - $qst_id = ! empty( $this->_req_data['QST_ID'] ) && ! is_array( $this->_req_data['QST_ID'] ) ? $this->_req_data['QST_ID'] : 0; |
|
50 | - $qsg_id = ! empty( $this->_req_data['QSG_ID'] ) && ! is_array( $this->_req_data['QSG_ID'] ) ? $this->_req_data['QSG_ID'] : 0; |
|
49 | + $qst_id = ! empty($this->_req_data['QST_ID']) && ! is_array($this->_req_data['QST_ID']) ? $this->_req_data['QST_ID'] : 0; |
|
50 | + $qsg_id = ! empty($this->_req_data['QSG_ID']) && ! is_array($this->_req_data['QSG_ID']) ? $this->_req_data['QSG_ID'] : 0; |
|
51 | 51 | |
52 | 52 | $new_page_routes = array( |
53 | 53 | 'question_groups' => array( |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | 'func' => '_trash_or_restore_questions', |
81 | 81 | 'capability' => 'ee_delete_question', |
82 | 82 | 'obj_id' => $qst_id, |
83 | - 'args' => array( 'trash' => FALSE ), |
|
83 | + 'args' => array('trash' => FALSE), |
|
84 | 84 | 'noheader' => TRUE |
85 | 85 | ), |
86 | 86 | |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | |
140 | 140 | 'trash_question_group' => array( |
141 | 141 | 'func' => '_trash_or_restore_question_groups', |
142 | - 'args' => array( 'trash' => TRUE ), |
|
142 | + 'args' => array('trash' => TRUE), |
|
143 | 143 | 'capability' => 'ee_delete_question_group', |
144 | 144 | 'obj_id' => $qsg_id, |
145 | 145 | 'noheader' => TRUE |
@@ -147,7 +147,7 @@ discard block |
||
147 | 147 | |
148 | 148 | 'restore_question_group' => array( |
149 | 149 | 'func' => '_trash_or_restore_question_groups', |
150 | - 'args' => array( 'trash' => FALSE ), |
|
150 | + 'args' => array('trash' => FALSE), |
|
151 | 151 | 'capability' => 'ee_delete_question_group', |
152 | 152 | 'obj_id' => $qsg_id, |
153 | 153 | 'noheader' => TRUE |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | |
163 | 163 | 'update_question_group' => array( |
164 | 164 | 'func' => '_insert_or_update_question_group', |
165 | - 'args' => array('new_question_group' => FALSE ), |
|
165 | + 'args' => array('new_question_group' => FALSE), |
|
166 | 166 | 'capability' => 'ee_edit_question_group', |
167 | 167 | 'obj_id' => $qsg_id, |
168 | 168 | 'noheader' => TRUE, |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | 'noheader' => TRUE |
201 | 201 | ), |
202 | 202 | ); |
203 | - $this->_page_routes = array_merge( $this->_page_routes, $new_page_routes ); |
|
203 | + $this->_page_routes = array_merge($this->_page_routes, $new_page_routes); |
|
204 | 204 | |
205 | 205 | $new_page_config = array( |
206 | 206 | |
@@ -224,7 +224,7 @@ discard block |
||
224 | 224 | 'filename' => 'registration_form_question_groups_views_bulk_actions_search' |
225 | 225 | ), |
226 | 226 | ), |
227 | - 'help_tour' => array( 'Registration_Form_Question_Groups_Help_Tour'), |
|
227 | + 'help_tour' => array('Registration_Form_Question_Groups_Help_Tour'), |
|
228 | 228 | 'metaboxes' => $this->_default_espresso_metaboxes, |
229 | 229 | 'require_nonce' => FALSE, |
230 | 230 | 'qtips' => array( |
@@ -238,14 +238,14 @@ discard block |
||
238 | 238 | 'order' => 5, |
239 | 239 | 'persistent' => FALSE |
240 | 240 | ), |
241 | - 'metaboxes' => array_merge( $this->_default_espresso_metaboxes, array('_publish_post_box' ) ), |
|
241 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
242 | 242 | 'help_tabs' => array( |
243 | 243 | 'registration_form_add_question_help_tab' => array( |
244 | 244 | 'title' => __('Add Question', 'event_espresso'), |
245 | 245 | 'filename' => 'registration_form_add_question' |
246 | 246 | ), |
247 | 247 | ), |
248 | - 'help_tour' => array( 'Registration_Form_Add_Question_Help_Tour'), |
|
248 | + 'help_tour' => array('Registration_Form_Add_Question_Help_Tour'), |
|
249 | 249 | 'require_nonce' => FALSE |
250 | 250 | ), |
251 | 251 | |
@@ -255,14 +255,14 @@ discard block |
||
255 | 255 | 'order' => 5, |
256 | 256 | 'persistent' => FALSE |
257 | 257 | ), |
258 | - 'metaboxes' => array_merge( $this->_default_espresso_metaboxes, array('_publish_post_box' ) ), |
|
258 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
259 | 259 | 'help_tabs' => array( |
260 | 260 | 'registration_form_add_question_group_help_tab' => array( |
261 | 261 | 'title' => __('Add Question Group', 'event_espresso'), |
262 | 262 | 'filename' => 'registration_form_add_question_group' |
263 | 263 | ), |
264 | 264 | ), |
265 | - 'help_tour' => array( 'Registration_Form_Add_Question_Group_Help_Tour'), |
|
265 | + 'help_tour' => array('Registration_Form_Add_Question_Group_Help_Tour'), |
|
266 | 266 | 'require_nonce' => FALSE |
267 | 267 | ), |
268 | 268 | |
@@ -271,16 +271,16 @@ discard block |
||
271 | 271 | 'label' => __('Edit Question Group', 'event_espresso'), |
272 | 272 | 'order' => 5, |
273 | 273 | 'persistent' => FALSE, |
274 | - 'url' => isset($this->_req_data['question_group_id']) ? add_query_arg(array('question_group_id' => $this->_req_data['question_group_id'] ), $this->_current_page_view_url ) : $this->_admin_base_url |
|
274 | + 'url' => isset($this->_req_data['question_group_id']) ? add_query_arg(array('question_group_id' => $this->_req_data['question_group_id']), $this->_current_page_view_url) : $this->_admin_base_url |
|
275 | 275 | ), |
276 | - 'metaboxes' => array_merge( $this->_default_espresso_metaboxes, array('_publish_post_box' ) ), |
|
276 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
277 | 277 | 'help_tabs' => array( |
278 | 278 | 'registration_form_edit_question_group_help_tab' => array( |
279 | 279 | 'title' => __('Edit Question Group', 'event_espresso'), |
280 | 280 | 'filename' => 'registration_form_edit_question_group' |
281 | 281 | ), |
282 | 282 | ), |
283 | - 'help_tour' => array( 'Registration_Form_Edit_Question_Group_Help_Tour'), |
|
283 | + 'help_tour' => array('Registration_Form_Edit_Question_Group_Help_Tour'), |
|
284 | 284 | 'require_nonce' => FALSE |
285 | 285 | ), |
286 | 286 | |
@@ -292,19 +292,19 @@ discard block |
||
292 | 292 | 'labels' => array( |
293 | 293 | 'publishbox' => __('Update Settings', 'event_espresso') |
294 | 294 | ), |
295 | - 'metaboxes' => array_merge( $this->_default_espresso_metaboxes, array( '_publish_post_box' ) ), |
|
295 | + 'metaboxes' => array_merge($this->_default_espresso_metaboxes, array('_publish_post_box')), |
|
296 | 296 | 'help_tabs' => array( |
297 | 297 | 'registration_form_reg_form_settings_help_tab' => array( |
298 | 298 | 'title' => __('Registration Form Settings', 'event_espresso'), |
299 | 299 | 'filename' => 'registration_form_reg_form_settings' |
300 | 300 | ), |
301 | 301 | ), |
302 | - 'help_tour' => array( 'Registration_Form_Settings_Help_Tour'), |
|
302 | + 'help_tour' => array('Registration_Form_Settings_Help_Tour'), |
|
303 | 303 | 'require_nonce' => FALSE |
304 | 304 | ) |
305 | 305 | |
306 | 306 | ); |
307 | - $this->_page_config = array_merge( $this->_page_config, $new_page_config ); |
|
307 | + $this->_page_config = array_merge($this->_page_config, $new_page_config); |
|
308 | 308 | |
309 | 309 | //change the list table we're going to use so it's the NEW list table! |
310 | 310 | $this->_page_config['default']['list_table'] = 'Extend_Registration_Form_Questions_Admin_List_Table'; |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | 'edit_question_group' => __('Edit Question Group', 'event_espresso'), |
319 | 319 | 'delete_question_group' => __('Delete Question Group', 'event_espresso'), |
320 | 320 | ); |
321 | - $this->_labels['buttons'] = array_merge( $this->_labels['buttons'], $new_labels ); |
|
321 | + $this->_labels['buttons'] = array_merge($this->_labels['buttons'], $new_labels); |
|
322 | 322 | |
323 | 323 | } |
324 | 324 | |
@@ -327,14 +327,14 @@ discard block |
||
327 | 327 | |
328 | 328 | |
329 | 329 | protected function _ajax_hooks() { |
330 | - add_action('wp_ajax_espresso_update_question_group_order', array( $this, 'update_question_group_order' )); |
|
330 | + add_action('wp_ajax_espresso_update_question_group_order', array($this, 'update_question_group_order')); |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | |
334 | 334 | |
335 | 335 | |
336 | 336 | public function load_scripts_styles_question_groups() { |
337 | - wp_enqueue_script( 'espresso_ajax_table_sorting' ); |
|
337 | + wp_enqueue_script('espresso_ajax_table_sorting'); |
|
338 | 338 | } |
339 | 339 | |
340 | 340 | |
@@ -355,7 +355,7 @@ discard block |
||
355 | 355 | * @return void |
356 | 356 | */ |
357 | 357 | public function load_sortable_question_script() { |
358 | - wp_register_script('ee-question-sortable', REGISTRATION_FORM_CAF_ASSETS_URL . 'ee_question_order.js', array('jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true); |
|
358 | + wp_register_script('ee-question-sortable', REGISTRATION_FORM_CAF_ASSETS_URL.'ee_question_order.js', array('jquery-ui-sortable'), EVENT_ESPRESSO_VERSION, true); |
|
359 | 359 | wp_enqueue_script('ee-question-sortable'); |
360 | 360 | } |
361 | 361 | |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | ) |
375 | 375 | ); |
376 | 376 | |
377 | - if ( EE_Registry::instance()->CAP->current_user_can('ee_delete_questions', 'espresso_registration_form_trash_questions' ) ) { |
|
377 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_questions', 'espresso_registration_form_trash_questions')) { |
|
378 | 378 | $this->_views['trash'] = array( |
379 | 379 | 'slug' => 'trash', |
380 | 380 | 'label' => __('Trash', 'event_espresso'), |
@@ -404,7 +404,7 @@ discard block |
||
404 | 404 | ) |
405 | 405 | ); |
406 | 406 | |
407 | - if ( EE_Registry::instance()->CAP->current_user_can( 'ee_delete_question_groups', 'espresso_registration_form_trash_question_groups' ) ) { |
|
407 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_question_groups', 'espresso_registration_form_trash_question_groups')) { |
|
408 | 408 | $this->_views['trash'] = array( |
409 | 409 | 'slug' => 'trash', |
410 | 410 | 'label' => __('Trash', 'event_espresso'), |
@@ -440,24 +440,24 @@ discard block |
||
440 | 440 | |
441 | 441 | |
442 | 442 | |
443 | - protected function _delete_question(){ |
|
444 | - $success = $this->_delete_items( $this->_question_model ); |
|
443 | + protected function _delete_question() { |
|
444 | + $success = $this->_delete_items($this->_question_model); |
|
445 | 445 | $this->_redirect_after_action( |
446 | 446 | $success, |
447 | - $this->_question_model->item_name( $success ), |
|
447 | + $this->_question_model->item_name($success), |
|
448 | 448 | 'deleted', |
449 | - array( 'action' => 'default', 'status' => 'all' ) |
|
449 | + array('action' => 'default', 'status' => 'all') |
|
450 | 450 | ); |
451 | 451 | } |
452 | 452 | |
453 | 453 | |
454 | 454 | protected function _delete_questions() { |
455 | - $success = $this->_delete_items( $this->_question_model ); |
|
455 | + $success = $this->_delete_items($this->_question_model); |
|
456 | 456 | $this->_redirect_after_action( |
457 | 457 | $success, |
458 | - $this->_question_model->item_name( $success ), |
|
458 | + $this->_question_model->item_name($success), |
|
459 | 459 | 'deleted permanently', |
460 | - array( 'action' => 'default', 'status' => 'trash' ) |
|
460 | + array('action' => 'default', 'status' => 'trash') |
|
461 | 461 | ); |
462 | 462 | } |
463 | 463 | |
@@ -468,26 +468,26 @@ discard block |
||
468 | 468 | * @param EEM_Soft_Delete_Base $model |
469 | 469 | * @return int number of items deleted permanently |
470 | 470 | */ |
471 | - private function _delete_items(EEM_Soft_Delete_Base $model){ |
|
471 | + private function _delete_items(EEM_Soft_Delete_Base $model) { |
|
472 | 472 | $success = 0; |
473 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
474 | - if (!empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
473 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
474 | + if ( ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
475 | 475 | // if array has more than one element than success message should be plural |
476 | - $success = count( $this->_req_data['checkbox'] ) > 1 ? 2 : 1; |
|
476 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
477 | 477 | // cycle thru bulk action checkboxes |
478 | - while (list( $ID, $value ) = each($this->_req_data['checkbox'])) { |
|
479 | - if ( ! $this->_delete_item( $ID, $model ) ) { |
|
478 | + while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
|
479 | + if ( ! $this->_delete_item($ID, $model)) { |
|
480 | 480 | $success = 0; |
481 | 481 | } |
482 | 482 | } |
483 | 483 | |
484 | - }elseif( !empty($this->_req_data['QSG_ID'])){ |
|
485 | - $success = $this->_delete_item( $this->_req_data['QSG_ID'], $model ); |
|
484 | + }elseif ( ! empty($this->_req_data['QSG_ID'])) { |
|
485 | + $success = $this->_delete_item($this->_req_data['QSG_ID'], $model); |
|
486 | 486 | |
487 | - }elseif( !empty($this->_req_data['QST_ID'])){ |
|
488 | - $success = $this->_delete_item( $this->_req_data['QST_ID'], $model ); |
|
489 | - }else{ |
|
490 | - EE_Error::add_error( sprintf(__("No Questions or Question Groups were selected for deleting. This error usually shows when you've attempted to delete via bulk action but there were no selections.", "event_espresso")), __FILE__, __FUNCTION__, __LINE__ ); |
|
487 | + }elseif ( ! empty($this->_req_data['QST_ID'])) { |
|
488 | + $success = $this->_delete_item($this->_req_data['QST_ID'], $model); |
|
489 | + } else { |
|
490 | + EE_Error::add_error(sprintf(__("No Questions or Question Groups were selected for deleting. This error usually shows when you've attempted to delete via bulk action but there were no selections.", "event_espresso")), __FILE__, __FUNCTION__, __LINE__); |
|
491 | 491 | } |
492 | 492 | return $success; |
493 | 493 | } |
@@ -498,11 +498,11 @@ discard block |
||
498 | 498 | * @param EEM_Soft_Delete_Base $model |
499 | 499 | * @return boolean |
500 | 500 | */ |
501 | - protected function _delete_item( $id, $model ) { |
|
502 | - if( $model instanceof EEM_Question ) { |
|
503 | - EEM_Question_Option::instance()->delete_permanently( array( array( 'QST_ID' => absint( $id ) ) ) ); |
|
501 | + protected function _delete_item($id, $model) { |
|
502 | + if ($model instanceof EEM_Question) { |
|
503 | + EEM_Question_Option::instance()->delete_permanently(array(array('QST_ID' => absint($id)))); |
|
504 | 504 | } |
505 | - return $model->delete_permanently_by_ID( absint( $id ) ); |
|
505 | + return $model->delete_permanently_by_ID(absint($id)); |
|
506 | 506 | } |
507 | 507 | |
508 | 508 | |
@@ -514,29 +514,29 @@ discard block |
||
514 | 514 | |
515 | 515 | |
516 | 516 | |
517 | - protected function _edit_question_group( $type = 'add' ) { |
|
518 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
519 | - $ID=isset( $this->_req_data['QSG_ID'] ) && ! empty( $this->_req_data['QSG_ID'] ) ? absint( $this->_req_data['QSG_ID'] ) : FALSE; |
|
520 | - $this->_admin_page_title = ucwords( str_replace( '_', ' ', $this->_req_action )); |
|
517 | + protected function _edit_question_group($type = 'add') { |
|
518 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
519 | + $ID = isset($this->_req_data['QSG_ID']) && ! empty($this->_req_data['QSG_ID']) ? absint($this->_req_data['QSG_ID']) : FALSE; |
|
520 | + $this->_admin_page_title = ucwords(str_replace('_', ' ', $this->_req_action)); |
|
521 | 521 | // add ID to title if editing |
522 | - $this->_admin_page_title = $ID ? $this->_admin_page_title . ' # ' . $ID : $this->_admin_page_title; |
|
523 | - if($ID){ |
|
524 | - $questionGroup=$this->_question_group_model->get_one_by_ID($ID); |
|
525 | - $additional_hidden_fields=array('QSG_ID'=>array('type'=>'hidden','value'=>$ID)); |
|
522 | + $this->_admin_page_title = $ID ? $this->_admin_page_title.' # '.$ID : $this->_admin_page_title; |
|
523 | + if ($ID) { |
|
524 | + $questionGroup = $this->_question_group_model->get_one_by_ID($ID); |
|
525 | + $additional_hidden_fields = array('QSG_ID'=>array('type'=>'hidden', 'value'=>$ID)); |
|
526 | 526 | $this->_set_add_edit_form_tags('update_question_group', $additional_hidden_fields); |
527 | - }else{ |
|
527 | + } else { |
|
528 | 528 | $questionGroup = EEM_Question_Group::instance()->create_default_object(); |
529 | 529 | $questionGroup->set_order_to_latest(); |
530 | 530 | $this->_set_add_edit_form_tags('insert_question_group'); |
531 | 531 | } |
532 | 532 | $this->_template_args['values'] = $this->_yes_no_values; |
533 | - $this->_template_args['all_questions']=$questionGroup->questions_in_and_not_in_group(); |
|
534 | - $this->_template_args['QSG_ID']=$ID ? $ID : TRUE; |
|
535 | - $this->_template_args['question_group']=$questionGroup; |
|
533 | + $this->_template_args['all_questions'] = $questionGroup->questions_in_and_not_in_group(); |
|
534 | + $this->_template_args['QSG_ID'] = $ID ? $ID : TRUE; |
|
535 | + $this->_template_args['question_group'] = $questionGroup; |
|
536 | 536 | |
537 | - $redirect_URL = add_query_arg( array( 'action' => 'question_groups'), $this->_admin_base_url ); |
|
538 | - $this->_set_publish_post_box_vars( 'id', $ID, FALSE, $redirect_URL ); |
|
539 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'question_groups_main_meta_box.template.php', $this->_template_args, TRUE ); |
|
537 | + $redirect_URL = add_query_arg(array('action' => 'question_groups'), $this->_admin_base_url); |
|
538 | + $this->_set_publish_post_box_vars('id', $ID, FALSE, $redirect_URL); |
|
539 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template(REGISTRATION_FORM_CAF_TEMPLATE_PATH.'question_groups_main_meta_box.template.php', $this->_template_args, TRUE); |
|
540 | 540 | |
541 | 541 | // the details template wrapper |
542 | 542 | $this->display_admin_page_with_sidebar(); |
@@ -547,76 +547,76 @@ discard block |
||
547 | 547 | |
548 | 548 | protected function _delete_question_groups() { |
549 | 549 | $success = $this->_delete_items($this->_question_group_model); |
550 | - $this->_redirect_after_action( $success, $this->_question_group_model->item_name($success), 'deleted permanently', array( 'action'=>'question_groups', 'status'=>'trash' )); |
|
550 | + $this->_redirect_after_action($success, $this->_question_group_model->item_name($success), 'deleted permanently', array('action'=>'question_groups', 'status'=>'trash')); |
|
551 | 551 | } |
552 | 552 | |
553 | 553 | |
554 | 554 | |
555 | - protected function _insert_or_update_question_group( $new_question_group = TRUE) { |
|
556 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
557 | - $set_column_values=$this->_set_column_values_for($this->_question_group_model); |
|
558 | - if ( $new_question_group ){ |
|
555 | + protected function _insert_or_update_question_group($new_question_group = TRUE) { |
|
556 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
557 | + $set_column_values = $this->_set_column_values_for($this->_question_group_model); |
|
558 | + if ($new_question_group) { |
|
559 | 559 | $QSG_ID = $this->_question_group_model->insert($set_column_values); |
560 | 560 | $success = $QSG_ID ? 1 : 0; |
561 | 561 | } else { |
562 | 562 | $QSG_ID = absint($this->_req_data['QSG_ID']); |
563 | - unset( $set_column_values[ 'QSG_ID' ] ); |
|
564 | - $success= $this->_question_group_model->update( $set_column_values, array( array( 'QSG_ID' => $QSG_ID ))); |
|
563 | + unset($set_column_values['QSG_ID']); |
|
564 | + $success = $this->_question_group_model->update($set_column_values, array(array('QSG_ID' => $QSG_ID))); |
|
565 | 565 | } |
566 | - $phone_question_id = EEM_Question::instance()->get_Question_ID_from_system_string( EEM_Attendee::system_question_phone ); |
|
566 | + $phone_question_id = EEM_Question::instance()->get_Question_ID_from_system_string(EEM_Attendee::system_question_phone); |
|
567 | 567 | // update the existing related questions |
568 | 568 | // BUT FIRST... delete the phone question from the Question_Group_Question if it is being added to this question group (therefore removed from the existing group) |
569 | - if ( isset( $this->_req_data['questions'], $this->_req_data['questions'][ $phone_question_id ] )) { |
|
569 | + if (isset($this->_req_data['questions'], $this->_req_data['questions'][$phone_question_id])) { |
|
570 | 570 | // delete where QST ID = system phone question ID and Question Group ID is NOT this group |
571 | - EEM_Question_Group_Question::instance()->delete( array( array( 'QST_ID' => $phone_question_id, 'QSG_ID' => array( '!=', $QSG_ID )))); |
|
571 | + EEM_Question_Group_Question::instance()->delete(array(array('QST_ID' => $phone_question_id, 'QSG_ID' => array('!=', $QSG_ID)))); |
|
572 | 572 | } |
573 | 573 | /** @type EE_Question_Group $question_group */ |
574 | - $question_group=$this->_question_group_model->get_one_by_ID( $QSG_ID ); |
|
574 | + $question_group = $this->_question_group_model->get_one_by_ID($QSG_ID); |
|
575 | 575 | $questions = $question_group->questions(); |
576 | 576 | // make sure system phone question is added to list of questions for this group |
577 | - if ( ! isset( $questions[$phone_question_id ] )) { |
|
578 | - $questions[ $phone_question_id ] = EEM_Question::instance()->get_one_by_ID( $phone_question_id ); |
|
577 | + if ( ! isset($questions[$phone_question_id])) { |
|
578 | + $questions[$phone_question_id] = EEM_Question::instance()->get_one_by_ID($phone_question_id); |
|
579 | 579 | } |
580 | 580 | |
581 | - foreach( $questions as $question_ID => $question ){ |
|
581 | + foreach ($questions as $question_ID => $question) { |
|
582 | 582 | // first we always check for order. |
583 | - if ( ! empty( $this->_req_data['question_orders'][ $question_ID ] ) ){ |
|
583 | + if ( ! empty($this->_req_data['question_orders'][$question_ID])) { |
|
584 | 584 | //update question order |
585 | - $question_group->update_question_order( $question_ID, $this->_req_data['question_orders'][ $question_ID ] ); |
|
585 | + $question_group->update_question_order($question_ID, $this->_req_data['question_orders'][$question_ID]); |
|
586 | 586 | } |
587 | 587 | |
588 | 588 | // then we always check if adding or removing. |
589 | - if ( isset( $this->_req_data['questions'], $this->_req_data['questions'][ $question_ID ] )) { |
|
590 | - $question_group->add_question( $question_ID ); |
|
589 | + if (isset($this->_req_data['questions'], $this->_req_data['questions'][$question_ID])) { |
|
590 | + $question_group->add_question($question_ID); |
|
591 | 591 | } else { |
592 | 592 | // not found, remove it (but only if not a system question for the personal group with the exception of lname system question - we allow removal of it) |
593 | 593 | if ( |
594 | 594 | in_array( |
595 | 595 | $question->system_ID(), |
596 | - EEM_Question::instance()->required_system_questions_in_system_question_group( $question_group->system_group() ) |
|
596 | + EEM_Question::instance()->required_system_questions_in_system_question_group($question_group->system_group()) |
|
597 | 597 | ) |
598 | 598 | ) { |
599 | 599 | continue; |
600 | 600 | } else { |
601 | - $question_group->remove_question( $question_ID ); |
|
601 | + $question_group->remove_question($question_ID); |
|
602 | 602 | } |
603 | 603 | } |
604 | 604 | } |
605 | 605 | // save new related questions |
606 | - if ( isset( $this->_req_data['questions'] )) { |
|
607 | - foreach( $this->_req_data['questions'] as $QST_ID ){ |
|
608 | - $question_group->add_question( $QST_ID ); |
|
609 | - if ( isset( $this->_req_data['question_orders'][ $QST_ID ] )) { |
|
610 | - $question_group->update_question_order( $QST_ID, $this->_req_data['question_orders'][ $QST_ID ] ); |
|
606 | + if (isset($this->_req_data['questions'])) { |
|
607 | + foreach ($this->_req_data['questions'] as $QST_ID) { |
|
608 | + $question_group->add_question($QST_ID); |
|
609 | + if (isset($this->_req_data['question_orders'][$QST_ID])) { |
|
610 | + $question_group->update_question_order($QST_ID, $this->_req_data['question_orders'][$QST_ID]); |
|
611 | 611 | } |
612 | 612 | } |
613 | 613 | } |
614 | 614 | |
615 | - if ( $success !== FALSE ) { |
|
616 | - $msg = $new_question_group ? sprintf( __('The %s has been created', 'event_espresso'), $this->_question_group_model->item_name() ) : sprintf( __('The %s has been updated', 'event_espresso' ), $this->_question_group_model->item_name() ); |
|
617 | - EE_Error::add_success( $msg ); |
|
615 | + if ($success !== FALSE) { |
|
616 | + $msg = $new_question_group ? sprintf(__('The %s has been created', 'event_espresso'), $this->_question_group_model->item_name()) : sprintf(__('The %s has been updated', 'event_espresso'), $this->_question_group_model->item_name()); |
|
617 | + EE_Error::add_success($msg); |
|
618 | 618 | } |
619 | - $this->_redirect_after_action(FALSE, '', '', array('action'=>'edit_question_group','QSG_ID'=>$QSG_ID), TRUE); |
|
619 | + $this->_redirect_after_action(FALSE, '', '', array('action'=>'edit_question_group', 'QSG_ID'=>$QSG_ID), TRUE); |
|
620 | 620 | |
621 | 621 | } |
622 | 622 | |
@@ -624,39 +624,39 @@ discard block |
||
624 | 624 | * duplicates a question and all its question options and redirects to the new question. |
625 | 625 | */ |
626 | 626 | public function _duplicate_question() { |
627 | - $question_ID = intval( $this->_req_data[ 'QST_ID' ] ); |
|
628 | - $question = EEM_Question::instance()->get_one_by_ID( $question_ID ); |
|
629 | - if( $question instanceof EE_Question ) { |
|
627 | + $question_ID = intval($this->_req_data['QST_ID']); |
|
628 | + $question = EEM_Question::instance()->get_one_by_ID($question_ID); |
|
629 | + if ($question instanceof EE_Question) { |
|
630 | 630 | $new_question = $question->duplicate(); |
631 | - if( $new_question instanceof EE_Question ) { |
|
632 | - $this->_redirect_after_action( true, __( 'Question', 'event_espresso' ), __( 'Duplicated', 'event_espresso' ), array('action'=>'edit_question', 'QST_ID' => $new_question->ID() ), TRUE); |
|
631 | + if ($new_question instanceof EE_Question) { |
|
632 | + $this->_redirect_after_action(true, __('Question', 'event_espresso'), __('Duplicated', 'event_espresso'), array('action'=>'edit_question', 'QST_ID' => $new_question->ID()), TRUE); |
|
633 | 633 | } else { |
634 | 634 | global $wpdb; |
635 | - EE_Error::add_error( sprintf( __( 'Could not duplicate question with ID %1$d because: %2$s', 'event_espresso' ), $question_ID, $wpdb->last_error ), __FILE__, __FUNCTION__, __LINE__ ); |
|
636 | - $this->_redirect_after_action(false, '', '', array('action'=>'default'), false ); |
|
635 | + EE_Error::add_error(sprintf(__('Could not duplicate question with ID %1$d because: %2$s', 'event_espresso'), $question_ID, $wpdb->last_error), __FILE__, __FUNCTION__, __LINE__); |
|
636 | + $this->_redirect_after_action(false, '', '', array('action'=>'default'), false); |
|
637 | 637 | } |
638 | 638 | } else { |
639 | - EE_Error::add_error( sprintf( __( 'Could not duplicate question with ID %d because it didn\'t exist!', 'event_espresso' ), $question_ID ), __FILE__, __FUNCTION__, __LINE__ ); |
|
640 | - $this->_redirect_after_action( false, '', '', array( 'action' => 'default' ), false ); |
|
639 | + EE_Error::add_error(sprintf(__('Could not duplicate question with ID %d because it didn\'t exist!', 'event_espresso'), $question_ID), __FILE__, __FUNCTION__, __LINE__); |
|
640 | + $this->_redirect_after_action(false, '', '', array('action' => 'default'), false); |
|
641 | 641 | } |
642 | 642 | } |
643 | 643 | |
644 | 644 | |
645 | 645 | |
646 | 646 | protected function _trash_or_restore_question_groups($trash = TRUE) { |
647 | - return $this->_trash_or_restore_items( $this->_question_group_model, $trash ); |
|
647 | + return $this->_trash_or_restore_items($this->_question_group_model, $trash); |
|
648 | 648 | } |
649 | 649 | |
650 | - protected function _trash_question(){ |
|
651 | - $success=$this->_question_model->delete_by_ID(intval($this->_req_data['QST_ID'])); |
|
652 | - $query_args=array('action'=>'default','status'=>'all'); |
|
650 | + protected function _trash_question() { |
|
651 | + $success = $this->_question_model->delete_by_ID(intval($this->_req_data['QST_ID'])); |
|
652 | + $query_args = array('action'=>'default', 'status'=>'all'); |
|
653 | 653 | $this->_redirect_after_action($success, $this->_question_model->item_name($success), 'trashed', $query_args); |
654 | 654 | } |
655 | 655 | |
656 | 656 | |
657 | 657 | |
658 | - protected function _trash_or_restore_questions($trash=TRUE){ |
|
659 | - $this->_trash_or_restore_items( $this->_question_model, $trash ); |
|
658 | + protected function _trash_or_restore_questions($trash = TRUE) { |
|
659 | + $this->_trash_or_restore_items($this->_question_model, $trash); |
|
660 | 660 | } |
661 | 661 | |
662 | 662 | |
@@ -667,21 +667,21 @@ discard block |
||
667 | 667 | * @param EEM_Base $model |
668 | 668 | * @param boolean $trash wehter to trash or restore |
669 | 669 | */ |
670 | - private function _trash_or_restore_items( EEM_Base $model, $trash = TRUE ) { |
|
670 | + private function _trash_or_restore_items(EEM_Base $model, $trash = TRUE) { |
|
671 | 671 | |
672 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
672 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
673 | 673 | |
674 | 674 | $success = 1; |
675 | 675 | //Checkboxes |
676 | 676 | //echo "trash $trash"; |
677 | 677 | //var_dump($this->_req_data['checkbox']);die; |
678 | - if ( isset( $this->_req_data['checkbox'] )) { |
|
679 | - if ( isset( $this->_req_data['checkbox'] ) && ! empty( $this->_req_data['checkbox'] ) && is_array( $this->_req_data['checkbox'] )) { |
|
678 | + if (isset($this->_req_data['checkbox'])) { |
|
679 | + if (isset($this->_req_data['checkbox']) && ! empty($this->_req_data['checkbox']) && is_array($this->_req_data['checkbox'])) { |
|
680 | 680 | // if array has more than one element than success message should be plural |
681 | - $success = count( $this->_req_data['checkbox'] ) > 1 ? 2 : 1; |
|
681 | + $success = count($this->_req_data['checkbox']) > 1 ? 2 : 1; |
|
682 | 682 | // cycle thru bulk action checkboxes |
683 | - while (list( $ID, $value ) = each($this->_req_data['checkbox'])) { |
|
684 | - if ( ! $model->delete_or_restore_by_ID($trash,absint($ID))) { |
|
683 | + while (list($ID, $value) = each($this->_req_data['checkbox'])) { |
|
684 | + if ( ! $model->delete_or_restore_by_ID($trash, absint($ID))) { |
|
685 | 685 | $success = 0; |
686 | 686 | } |
687 | 687 | } |
@@ -689,7 +689,7 @@ discard block |
||
689 | 689 | } else { |
690 | 690 | // grab single id and delete |
691 | 691 | $ID = absint($this->_req_data['checkbox']); |
692 | - if ( ! $model->delete_or_restore_by_ID($trash,$ID)) { |
|
692 | + if ( ! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
693 | 693 | $success = 0; |
694 | 694 | } |
695 | 695 | } |
@@ -697,53 +697,53 @@ discard block |
||
697 | 697 | } else { |
698 | 698 | // delete via trash link |
699 | 699 | // grab single id and delete |
700 | - $ID = absint($this->_req_data[ $model->primary_key_name() ]); |
|
701 | - if ( ! $model->delete_or_restore_by_ID($trash,$ID)) { |
|
700 | + $ID = absint($this->_req_data[$model->primary_key_name()]); |
|
701 | + if ( ! $model->delete_or_restore_by_ID($trash, $ID)) { |
|
702 | 702 | $success = 0; |
703 | 703 | } |
704 | 704 | |
705 | 705 | } |
706 | 706 | |
707 | 707 | |
708 | - $action = $model instanceof EEM_Question ? 'default' : 'question_groups';//strtolower( $model->item_name(2) ); |
|
708 | + $action = $model instanceof EEM_Question ? 'default' : 'question_groups'; //strtolower( $model->item_name(2) ); |
|
709 | 709 | //echo "action :$action"; |
710 | 710 | //$action = 'questions' ? 'default' : $action; |
711 | - if($trash){ |
|
711 | + if ($trash) { |
|
712 | 712 | $action_desc = 'trashed'; |
713 | 713 | $status = 'trash'; |
714 | - }else{ |
|
714 | + } else { |
|
715 | 715 | $action_desc = 'restored'; |
716 | 716 | $status = 'all'; |
717 | 717 | } |
718 | - $this->_redirect_after_action( $success, $model->item_name($success), $action_desc, array( 'action' => $action, 'status'=>$status ) ); |
|
718 | + $this->_redirect_after_action($success, $model->item_name($success), $action_desc, array('action' => $action, 'status'=>$status)); |
|
719 | 719 | } |
720 | 720 | |
721 | 721 | |
722 | 722 | |
723 | 723 | |
724 | - public function get_trashed_questions( $per_page,$current_page = 1, $count = FALSE ) { |
|
724 | + public function get_trashed_questions($per_page, $current_page = 1, $count = FALSE) { |
|
725 | 725 | $query_params = $this->get_query_params(EEM_Question::instance(), $per_page, $current_page); |
726 | 726 | |
727 | - if( $count ){ |
|
727 | + if ($count) { |
|
728 | 728 | //note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
729 | - $where = isset( $query_params[0] ) ? array( $query_params[0] ) : array(); |
|
730 | - $results=$this->_question_model->count_deleted($where); |
|
731 | - }else{ |
|
729 | + $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
730 | + $results = $this->_question_model->count_deleted($where); |
|
731 | + } else { |
|
732 | 732 | //note: this a subclass of EEM_Soft_Delete_Base, so this is actually only getting non-trashed items |
733 | - $results=$this->_question_model->get_all_deleted($query_params); |
|
733 | + $results = $this->_question_model->get_all_deleted($query_params); |
|
734 | 734 | } |
735 | 735 | return $results; |
736 | 736 | } |
737 | 737 | |
738 | 738 | |
739 | 739 | |
740 | - public function get_question_groups( $per_page, $current_page = 1, $count = FALSE ) { |
|
741 | - $questionGroupModel=EEM_Question_Group::instance(); |
|
742 | - $query_params=$this->get_query_params($questionGroupModel,$per_page,$current_page); |
|
743 | - if ($count){ |
|
744 | - $where = isset( $query_params[0] ) ? array( $query_params[0] ) : array(); |
|
740 | + public function get_question_groups($per_page, $current_page = 1, $count = FALSE) { |
|
741 | + $questionGroupModel = EEM_Question_Group::instance(); |
|
742 | + $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page); |
|
743 | + if ($count) { |
|
744 | + $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
745 | 745 | $results = $questionGroupModel->count($where); |
746 | - }else{ |
|
746 | + } else { |
|
747 | 747 | $results = $questionGroupModel->get_all($query_params); |
748 | 748 | } |
749 | 749 | return $results; |
@@ -751,14 +751,14 @@ discard block |
||
751 | 751 | |
752 | 752 | |
753 | 753 | |
754 | - public function get_trashed_question_groups( $per_page,$current_page = 1, $count = FALSE ) { |
|
755 | - $questionGroupModel=EEM_Question_Group::instance(); |
|
756 | - $query_params=$this->get_query_params($questionGroupModel,$per_page,$current_page); |
|
757 | - if($count){ |
|
758 | - $where = isset( $query_params[0] ) ? array($query_params[0]) : array(); |
|
754 | + public function get_trashed_question_groups($per_page, $current_page = 1, $count = FALSE) { |
|
755 | + $questionGroupModel = EEM_Question_Group::instance(); |
|
756 | + $query_params = $this->get_query_params($questionGroupModel, $per_page, $current_page); |
|
757 | + if ($count) { |
|
758 | + $where = isset($query_params[0]) ? array($query_params[0]) : array(); |
|
759 | 759 | $query_params['limit'] = NULL; |
760 | 760 | $results = $questionGroupModel->count_deleted($where); |
761 | - }else{ |
|
761 | + } else { |
|
762 | 762 | $results = $questionGroupModel->get_all_deleted($query_params); |
763 | 763 | } |
764 | 764 | return $results; |
@@ -771,22 +771,22 @@ discard block |
||
771 | 771 | */ |
772 | 772 | public function update_question_group_order() { |
773 | 773 | |
774 | - $success = __( 'Question group order was updated successfully.', 'event_espresso' ); |
|
774 | + $success = __('Question group order was updated successfully.', 'event_espresso'); |
|
775 | 775 | |
776 | 776 | // grab our row IDs |
777 | - $row_ids = isset( $this->_req_data['row_ids'] ) && ! empty( $this->_req_data['row_ids'] ) ? explode( ',', rtrim( $this->_req_data['row_ids'], ',' )) : FALSE; |
|
777 | + $row_ids = isset($this->_req_data['row_ids']) && ! empty($this->_req_data['row_ids']) ? explode(',', rtrim($this->_req_data['row_ids'], ',')) : FALSE; |
|
778 | 778 | |
779 | - $perpage = !empty( $this->_req_data['perpage'] ) ? (int) $this->_req_data['perpage'] : NULL; |
|
780 | - $curpage = !empty( $this->_req_data['curpage'] ) ? (int) $this->_req_data['curpage'] : NULL; |
|
779 | + $perpage = ! empty($this->_req_data['perpage']) ? (int) $this->_req_data['perpage'] : NULL; |
|
780 | + $curpage = ! empty($this->_req_data['curpage']) ? (int) $this->_req_data['curpage'] : NULL; |
|
781 | 781 | |
782 | - if ( is_array( $row_ids )) { |
|
782 | + if (is_array($row_ids)) { |
|
783 | 783 | //figure out where we start the row_id count at for the current page. |
784 | - $qsgcount = empty( $curpage ) ? 0 : ($curpage - 1 ) * $perpage; |
|
784 | + $qsgcount = empty($curpage) ? 0 : ($curpage - 1) * $perpage; |
|
785 | 785 | |
786 | 786 | global $wpdb; |
787 | - for ( $i = 0; $i < count($row_ids); $i++ ) { |
|
787 | + for ($i = 0; $i < count($row_ids); $i++) { |
|
788 | 788 | //Update the questions when re-ordering |
789 | - if ( EEM_Question_Group::instance()->update ( array( 'QSG_order' => $qsgcount ), array(array( 'QSG_ID' => $row_ids[$i] ))) === FALSE ) { |
|
789 | + if (EEM_Question_Group::instance()->update(array('QSG_order' => $qsgcount), array(array('QSG_ID' => $row_ids[$i]))) === FALSE) { |
|
790 | 790 | $success = FALSE; |
791 | 791 | } |
792 | 792 | $qsgcount++; |
@@ -795,9 +795,9 @@ discard block |
||
795 | 795 | $success = FALSE; |
796 | 796 | } |
797 | 797 | |
798 | - $errors = ! $success ? __( 'An error occurred. The question group order was not updated.', 'event_espresso' ) : FALSE; |
|
798 | + $errors = ! $success ? __('An error occurred. The question group order was not updated.', 'event_espresso') : FALSE; |
|
799 | 799 | |
800 | - echo json_encode( array( 'return_data' => FALSE, 'success' => $success, 'errors' => $errors )); |
|
800 | + echo json_encode(array('return_data' => FALSE, 'success' => $success, 'errors' => $errors)); |
|
801 | 801 | die(); |
802 | 802 | |
803 | 803 | } |
@@ -814,10 +814,10 @@ discard block |
||
814 | 814 | |
815 | 815 | protected function _reg_form_settings() { |
816 | 816 | $this->_template_args['values'] = $this->_yes_no_values; |
817 | - $this->_template_args = apply_filters( 'FHEE__Extend_Registration_Form_Admin_Page___reg_form_settings___template_args', $this->_template_args ); |
|
818 | - $this->_set_add_edit_form_tags( 'update_reg_form_settings' ); |
|
819 | - $this->_set_publish_post_box_vars( NULL, FALSE, FALSE, NULL, FALSE ); |
|
820 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template( REGISTRATION_FORM_CAF_TEMPLATE_PATH . 'reg_form_settings.template.php', $this->_template_args, TRUE ); |
|
817 | + $this->_template_args = apply_filters('FHEE__Extend_Registration_Form_Admin_Page___reg_form_settings___template_args', $this->_template_args); |
|
818 | + $this->_set_add_edit_form_tags('update_reg_form_settings'); |
|
819 | + $this->_set_publish_post_box_vars(NULL, FALSE, FALSE, NULL, FALSE); |
|
820 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template(REGISTRATION_FORM_CAF_TEMPLATE_PATH.'reg_form_settings.template.php', $this->_template_args, TRUE); |
|
821 | 821 | $this->display_admin_page_with_sidebar(); |
822 | 822 | } |
823 | 823 | |
@@ -825,9 +825,9 @@ discard block |
||
825 | 825 | |
826 | 826 | |
827 | 827 | protected function _update_reg_form_settings() { |
828 | - EE_Registry::instance()->CFG->registration = apply_filters( 'FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', EE_Registry::instance()->CFG->registration ); |
|
829 | - $success = $this->_update_espresso_configuration( __('Registration Form Options', 'event_espresso'), EE_Registry::instance()->CFG, __FILE__, __FUNCTION__, __LINE__ ); |
|
830 | - $this->_redirect_after_action( $success, __('Registration Form Options', 'event_espresso'), 'updated', array( 'action' => 'view_reg_form_settings' ) ); |
|
828 | + EE_Registry::instance()->CFG->registration = apply_filters('FHEE__Extend_Registration_Form_Admin_Page___update_reg_form_settings__CFG_registration', EE_Registry::instance()->CFG->registration); |
|
829 | + $success = $this->_update_espresso_configuration(__('Registration Form Options', 'event_espresso'), EE_Registry::instance()->CFG, __FILE__, __FUNCTION__, __LINE__); |
|
830 | + $this->_redirect_after_action($success, __('Registration Form Options', 'event_espresso'), 'updated', array('action' => 'view_reg_form_settings')); |
|
831 | 831 | } |
832 | 832 | |
833 | 833 | } |
@@ -510,7 +510,7 @@ discard block |
||
510 | 510 | * @access protected |
511 | 511 | * @param string $fieldname the property item the corresponding value is for. |
512 | 512 | * @param mixed $value The value we are caching. |
513 | - * @param null $cache_type |
|
513 | + * @param string $cache_type |
|
514 | 514 | * @return void |
515 | 515 | */ |
516 | 516 | protected function _set_cached_property( $fieldname, $value, $cache_type = NULL ) { |
@@ -823,7 +823,7 @@ discard block |
||
823 | 823 | * |
824 | 824 | * @param null $field_to_order_by What field is being used as the reference point. |
825 | 825 | * @param array $query_params Any additional conditions on the query. |
826 | - * @param null $columns_to_select If left null, then an array of EE_Base_Class objects is returned, otherwise |
|
826 | + * @param string $columns_to_select If left null, then an array of EE_Base_Class objects is returned, otherwise |
|
827 | 827 | * you can indicate just the columns you want returned |
828 | 828 | * |
829 | 829 | * @return array|EE_Base_Class |
@@ -848,7 +848,7 @@ discard block |
||
848 | 848 | * |
849 | 849 | * @param null $field_to_order_by What field is being used as the reference point. |
850 | 850 | * @param array $query_params Any additional conditions on the query. |
851 | - * @param null $columns_to_select If left null, then an EE_Base_Class object is returned, otherwise |
|
851 | + * @param string $columns_to_select If left null, then an EE_Base_Class object is returned, otherwise |
|
852 | 852 | * you can indicate just the column you want returned |
853 | 853 | * |
854 | 854 | * @return array|EE_Base_Class |
@@ -911,7 +911,7 @@ discard block |
||
911 | 911 | /** |
912 | 912 | * This method simply returns the RAW unprocessed value for the given property in this class |
913 | 913 | * @param string $field_name A valid fieldname |
914 | - * @return mixed Whatever the raw value stored on the property is. |
|
914 | + * @return integer|null Whatever the raw value stored on the property is. |
|
915 | 915 | * @throws EE_Error if fieldSettings is misconfigured or the field doesn't exist. |
916 | 916 | */ |
917 | 917 | public function get_raw($field_name) { |
@@ -985,11 +985,11 @@ discard block |
||
985 | 985 | * |
986 | 986 | * @access protected |
987 | 987 | * @param string $field_name Field on the instantiated EE_Base_Class child object |
988 | - * @param null $dt_frmt valid datetime format used for date (if '' then we just use the default on the field, if NULL we use the last-used format) |
|
989 | - * @param null $tm_frmt Same as above except this is for time format |
|
988 | + * @param string|null $dt_frmt valid datetime format used for date (if '' then we just use the default on the field, if NULL we use the last-used format) |
|
989 | + * @param null|string $tm_frmt Same as above except this is for time format |
|
990 | 990 | * @param string $date_or_time if NULL then both are returned, otherwise "D" = only date and "T" = only time. |
991 | 991 | * @param boolean $echo Whether the dtt is echoing using pretty echoing or just returned using vanilla get |
992 | - * @return void | string | bool | EE_Error string on success, FALSE on fail, or EE_Error Exception is thrown if field is not a valid dtt field, or void if echoing |
|
992 | + * @return string|boolean | string | bool | EE_Error string on success, FALSE on fail, or EE_Error Exception is thrown if field is not a valid dtt field, or void if echoing |
|
993 | 993 | */ |
994 | 994 | protected function _get_datetime( $field_name, $dt_frmt = NULL, $tm_frmt = NULL, $date_or_time = NULL, $echo = FALSE ) { |
995 | 995 | |
@@ -1162,7 +1162,7 @@ discard block |
||
1162 | 1162 | * sets the time on a datetime property |
1163 | 1163 | * |
1164 | 1164 | * @access protected |
1165 | - * @param string|Datetime $time a valid time string for php datetime functions (or DateTime object) |
|
1165 | + * @param string $time a valid time string for php datetime functions (or DateTime object) |
|
1166 | 1166 | * @param string $fieldname the name of the field the time is being set on (must match a EE_Datetime_Field) |
1167 | 1167 | */ |
1168 | 1168 | protected function _set_time_for( $time, $fieldname ) { |
@@ -1177,7 +1177,7 @@ discard block |
||
1177 | 1177 | * sets the date on a datetime property |
1178 | 1178 | * |
1179 | 1179 | * @access protected |
1180 | - * @param string|DateTime $date a valid date string for php datetime functions ( or DateTime object) |
|
1180 | + * @param string $date a valid date string for php datetime functions ( or DateTime object) |
|
1181 | 1181 | * @param string $fieldname the name of the field the date is being set on (must match a EE_Datetime_Field) |
1182 | 1182 | */ |
1183 | 1183 | protected function _set_date_for( $date, $fieldname ) { |
@@ -1506,7 +1506,7 @@ discard block |
||
1506 | 1506 | |
1507 | 1507 | /** |
1508 | 1508 | * for getting a model while instantiated. |
1509 | - * @return \EEM_Base | \EEM_CPT_Base |
|
1509 | + * @return boolean | \EEM_CPT_Base |
|
1510 | 1510 | */ |
1511 | 1511 | public function get_model() { |
1512 | 1512 | $modelName = self::_get_model_classname( get_class($this) ); |
@@ -1537,7 +1537,7 @@ discard block |
||
1537 | 1537 | * If there is a key in the incoming array that matches the primary key for the model AND it is not null, then we check the db. If there's a an object we return it. If not we return false. |
1538 | 1538 | * @param array $props_n_values incoming array of properties and their values |
1539 | 1539 | * @param string $classname the classname of the child class |
1540 | - * @param null $timezone |
|
1540 | + * @param null|string $timezone |
|
1541 | 1541 | * @return mixed (EE_Base_Class|bool) |
1542 | 1542 | */ |
1543 | 1543 | protected static function _check_for_object( $props_n_values, $classname, $timezone = NULL ) { |
@@ -1573,7 +1573,7 @@ discard block |
||
1573 | 1573 | * @param $classname |
1574 | 1574 | * @param null $timezone |
1575 | 1575 | * @throws EE_Error |
1576 | - * @return EEM_Base |
|
1576 | + * @return boolean |
|
1577 | 1577 | */ |
1578 | 1578 | protected static function _get_model( $classname, $timezone = NULL ){ |
1579 | 1579 | //find model for this class |
@@ -1589,8 +1589,8 @@ discard block |
||
1589 | 1589 | /** |
1590 | 1590 | * Gets the model instance (eg instance of EEM_Attendee) given its classname (eg EE_Attendee) |
1591 | 1591 | * @param string $model_classname |
1592 | - * @param null $timezone |
|
1593 | - * @return EEM_Base |
|
1592 | + * @param string|null $timezone |
|
1593 | + * @return boolean |
|
1594 | 1594 | */ |
1595 | 1595 | protected static function _get_model_instance_with_name($model_classname, $timezone = NULL){ |
1596 | 1596 | $model_classname = str_replace( 'EEM_', '', $model_classname ); |
@@ -47,25 +47,25 @@ discard block |
||
47 | 47 | |
48 | 48 | |
49 | 49 | /** |
50 | - * date format |
|
51 | - * |
|
52 | - * pattern or format for displaying dates |
|
53 | - * |
|
54 | - * @access protected |
|
55 | - * @var string |
|
56 | - */ |
|
50 | + * date format |
|
51 | + * |
|
52 | + * pattern or format for displaying dates |
|
53 | + * |
|
54 | + * @access protected |
|
55 | + * @var string |
|
56 | + */ |
|
57 | 57 | protected $_dt_frmt; |
58 | 58 | |
59 | 59 | |
60 | 60 | |
61 | - /** |
|
62 | - * time format |
|
63 | - * |
|
64 | - * pattern or format for displaying time |
|
65 | - * |
|
66 | - * @access protected |
|
67 | - * @var string |
|
68 | - */ |
|
61 | + /** |
|
62 | + * time format |
|
63 | + * |
|
64 | + * pattern or format for displaying time |
|
65 | + * |
|
66 | + * @access protected |
|
67 | + * @var string |
|
68 | + */ |
|
69 | 69 | protected $_tm_frmt; |
70 | 70 | |
71 | 71 | |
@@ -205,12 +205,12 @@ discard block |
||
205 | 205 | |
206 | 206 | |
207 | 207 | /** |
208 | - * Gets the field's original value when this object was constructed during this request. |
|
209 | - * This can be helpful when determining if a model object has changed or not |
|
210 | - * |
|
211 | - * @param string $field_name |
|
212 | - * @return mixed|null |
|
213 | - */ |
|
208 | + * Gets the field's original value when this object was constructed during this request. |
|
209 | + * This can be helpful when determining if a model object has changed or not |
|
210 | + * |
|
211 | + * @param string $field_name |
|
212 | + * @return mixed|null |
|
213 | + */ |
|
214 | 214 | public function get_original( $field_name ){ |
215 | 215 | if( isset( $this->_props_n_values_provided_in_constructor[ $field_name ] ) && |
216 | 216 | $field_settings = $this->get_Model()->field_settings_for( $field_name )){ |
@@ -1310,28 +1310,28 @@ discard block |
||
1310 | 1310 | return $result ? true : false; |
1311 | 1311 | } |
1312 | 1312 | |
1313 | - /** |
|
1314 | - * When this model object is deleted, it may still be cached on related model objects. This clears the cache of |
|
1315 | - * related model objects |
|
1316 | - */ |
|
1317 | - public function refresh_cache_of_related_objects() { |
|
1318 | - foreach( $this->get_model()->relation_settings() as $relation_name => $relation_obj ) { |
|
1319 | - if( ! empty( $this->_model_relations[ $relation_name ] ) ) { |
|
1320 | - $related_objects = $this->_model_relations[ $relation_name ]; |
|
1321 | - if( $relation_obj instanceof EE_Belongs_To_Relation ) { |
|
1322 | - //this relation only stores a single model object, not an array |
|
1323 | - //but let's make it consistent |
|
1324 | - $related_objects = array( $related_objects ); |
|
1325 | - } |
|
1326 | - foreach( $related_objects as $related_object ) { |
|
1327 | - //only refresh their cache if they're in memory |
|
1328 | - if( $related_object instanceof EE_Base_Class ) { |
|
1313 | + /** |
|
1314 | + * When this model object is deleted, it may still be cached on related model objects. This clears the cache of |
|
1315 | + * related model objects |
|
1316 | + */ |
|
1317 | + public function refresh_cache_of_related_objects() { |
|
1318 | + foreach( $this->get_model()->relation_settings() as $relation_name => $relation_obj ) { |
|
1319 | + if( ! empty( $this->_model_relations[ $relation_name ] ) ) { |
|
1320 | + $related_objects = $this->_model_relations[ $relation_name ]; |
|
1321 | + if( $relation_obj instanceof EE_Belongs_To_Relation ) { |
|
1322 | + //this relation only stores a single model object, not an array |
|
1323 | + //but let's make it consistent |
|
1324 | + $related_objects = array( $related_objects ); |
|
1325 | + } |
|
1326 | + foreach( $related_objects as $related_object ) { |
|
1327 | + //only refresh their cache if they're in memory |
|
1328 | + if( $related_object instanceof EE_Base_Class ) { |
|
1329 | 1329 | $related_object->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
1330 | - } |
|
1331 | - } |
|
1332 | - } |
|
1333 | - } |
|
1334 | - } |
|
1330 | + } |
|
1331 | + } |
|
1332 | + } |
|
1333 | + } |
|
1334 | + } |
|
1335 | 1335 | |
1336 | 1336 | |
1337 | 1337 | |
@@ -1681,9 +1681,9 @@ discard block |
||
1681 | 1681 | $otherObject = $this->get_model()->add_relationship_to( $this, $otherObjectModelObjectOrID, $relationName, $extra_join_model_fields_n_values ); |
1682 | 1682 | //clear cache so future get_many_related and get_first_related() return new results. |
1683 | 1683 | $this->clear_cache( $relationName, $otherObject, TRUE ); |
1684 | - if( $otherObject instanceof EE_Base_Class ) { |
|
1685 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
1686 | - } |
|
1684 | + if( $otherObject instanceof EE_Base_Class ) { |
|
1685 | + $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
1686 | + } |
|
1687 | 1687 | } else { |
1688 | 1688 | //this thing doesn't exist in the DB, so just cache it |
1689 | 1689 | if( ! $otherObjectModelObjectOrID instanceof EE_Base_Class){ |
@@ -1697,18 +1697,18 @@ discard block |
||
1697 | 1697 | } |
1698 | 1698 | $this->cache( $relationName, $otherObjectModelObjectOrID, $cache_id ); |
1699 | 1699 | } |
1700 | - if( $otherObject instanceof EE_Base_Class ) { |
|
1701 | - //fix the reciprocal relation too |
|
1702 | - if( $otherObject->ID() ) { |
|
1703 | - //its saved so assumed relations exist in the DB, so we can just |
|
1704 | - //clear the cache so future queries use the updated info in the DB |
|
1705 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), null, true ); |
|
1706 | - } else { |
|
1707 | - |
|
1708 | - //it's not saved, so it caches relations like this |
|
1709 | - $otherObject->cache( $this->get_model()->get_this_model_name(), $this ); |
|
1710 | - } |
|
1711 | - } |
|
1700 | + if( $otherObject instanceof EE_Base_Class ) { |
|
1701 | + //fix the reciprocal relation too |
|
1702 | + if( $otherObject->ID() ) { |
|
1703 | + //its saved so assumed relations exist in the DB, so we can just |
|
1704 | + //clear the cache so future queries use the updated info in the DB |
|
1705 | + $otherObject->clear_cache( $this->get_model()->get_this_model_name(), null, true ); |
|
1706 | + } else { |
|
1707 | + |
|
1708 | + //it's not saved, so it caches relations like this |
|
1709 | + $otherObject->cache( $this->get_model()->get_this_model_name(), $this ); |
|
1710 | + } |
|
1711 | + } |
|
1712 | 1712 | return $otherObject; |
1713 | 1713 | } |
1714 | 1714 | |
@@ -1738,9 +1738,9 @@ discard block |
||
1738 | 1738 | //this doesn't exist in the DB, just remove it from the cache |
1739 | 1739 | $otherObject = $this->clear_cache( $relationName, $otherObjectModelObjectOrID ); |
1740 | 1740 | } |
1741 | - if( $otherObject instanceof EE_Base_Class ) { |
|
1742 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
1743 | - } |
|
1741 | + if( $otherObject instanceof EE_Base_Class ) { |
|
1742 | + $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
1743 | + } |
|
1744 | 1744 | return $otherObject; |
1745 | 1745 | } |
1746 | 1746 | |
@@ -1759,11 +1759,11 @@ discard block |
||
1759 | 1759 | //this doesn't exist in the DB, just remove it from the cache |
1760 | 1760 | $otherObjects = $this->clear_cache( $relationName, null, true ); |
1761 | 1761 | } |
1762 | - if( is_array( $otherObjects ) ) { |
|
1763 | - foreach ( $otherObjects as $otherObject ) { |
|
1764 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
1765 | - } |
|
1766 | - } |
|
1762 | + if( is_array( $otherObjects ) ) { |
|
1763 | + foreach ( $otherObjects as $otherObject ) { |
|
1764 | + $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
1765 | + } |
|
1766 | + } |
|
1767 | 1767 | return $otherObjects; |
1768 | 1768 | } |
1769 | 1769 |
@@ -1,5 +1,5 @@ discard block |
||
1 | -<?php if (!defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
2 | -do_action( 'AHEE_log', __FILE__, ' FILE LOADED', '' ); |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
2 | +do_action('AHEE_log', __FILE__, ' FILE LOADED', ''); |
|
3 | 3 | /** |
4 | 4 | * |
5 | 5 | * Event Espresso |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * ------------------------------------------------------------------------ |
25 | 25 | */ |
26 | 26 | |
27 | -abstract class EE_Base_Class{ |
|
27 | +abstract class EE_Base_Class { |
|
28 | 28 | |
29 | 29 | /** |
30 | 30 | * This is an array of the original properties and values provided during construction |
@@ -117,60 +117,60 @@ discard block |
||
117 | 117 | * @throws EE_Error |
118 | 118 | * @return \EE_Base_Class |
119 | 119 | */ |
120 | - protected function __construct( $fieldValues = array(), $bydb = FALSE, $timezone = '', $date_formats = array() ){ |
|
120 | + protected function __construct($fieldValues = array(), $bydb = FALSE, $timezone = '', $date_formats = array()) { |
|
121 | 121 | |
122 | - $className=get_class($this); |
|
122 | + $className = get_class($this); |
|
123 | 123 | |
124 | - do_action("AHEE__{$className}__construct",$this,$fieldValues); |
|
125 | - $model=$this->get_model(); |
|
126 | - $model_fields = $model->field_settings( FALSE ); |
|
124 | + do_action("AHEE__{$className}__construct", $this, $fieldValues); |
|
125 | + $model = $this->get_model(); |
|
126 | + $model_fields = $model->field_settings(FALSE); |
|
127 | 127 | // ensure $fieldValues is an array |
128 | - $fieldValues = is_array( $fieldValues ) ? $fieldValues : array( $fieldValues ); |
|
128 | + $fieldValues = is_array($fieldValues) ? $fieldValues : array($fieldValues); |
|
129 | 129 | // EEH_Debug_Tools::printr( $fieldValues, '$fieldValues <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
130 | 130 | // verify client code has not passed any invalid field names |
131 | - foreach($fieldValues as $field_name=> $field_value){ |
|
132 | - if( ! isset( $model_fields[ $field_name] ) ){ |
|
133 | - throw new EE_Error(sprintf(__("Invalid field (%s) passed to constructor of %s. Allowed fields are :%s", "event_espresso"),$field_name,get_class($this),implode(", ",array_keys($model_fields)))); |
|
131 | + foreach ($fieldValues as $field_name=> $field_value) { |
|
132 | + if ( ! isset($model_fields[$field_name])) { |
|
133 | + throw new EE_Error(sprintf(__("Invalid field (%s) passed to constructor of %s. Allowed fields are :%s", "event_espresso"), $field_name, get_class($this), implode(", ", array_keys($model_fields)))); |
|
134 | 134 | } |
135 | 135 | } |
136 | 136 | // EEH_Debug_Tools::printr( $model_fields, '$model_fields <br /><span style="font-size:10px;font-weight:normal;">' . __FILE__ . '<br />line no: ' . __LINE__ . '</span>', 'auto' ); |
137 | - EE_Registry::instance()->load_helper( 'DTT_Helper' ); |
|
138 | - $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string( $timezone ); |
|
137 | + EE_Registry::instance()->load_helper('DTT_Helper'); |
|
138 | + $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone); |
|
139 | 139 | |
140 | - if ( ! empty( $date_formats ) && is_array( $date_formats ) ) { |
|
140 | + if ( ! empty($date_formats) && is_array($date_formats)) { |
|
141 | 141 | $this->_dt_frmt = $date_formats[0]; |
142 | 142 | $this->_tm_frmt = $date_formats[1]; |
143 | 143 | } else { |
144 | 144 | //set default formats for date and time |
145 | - $this->_dt_frmt = get_option( 'date_format' ); |
|
146 | - $this->_tm_frmt = get_option( 'time_format' ); |
|
145 | + $this->_dt_frmt = get_option('date_format'); |
|
146 | + $this->_tm_frmt = get_option('time_format'); |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | //if db model is instantiating |
150 | - if ( $bydb ){ |
|
150 | + if ($bydb) { |
|
151 | 151 | //client code has indicated these field values are from the database |
152 | - foreach( $model_fields as $fieldName => $field ){ |
|
153 | - $this->set_from_db( $fieldName, isset( $fieldValues[ $fieldName] ) ? $fieldValues[ $fieldName ] : null ); |
|
152 | + foreach ($model_fields as $fieldName => $field) { |
|
153 | + $this->set_from_db($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null); |
|
154 | 154 | } |
155 | 155 | } else { |
156 | 156 | //we're constructing a brand |
157 | 157 | //new instance of the model object. Generally, this means we'll need to do more field validation |
158 | - foreach( $model_fields as $fieldName => $field ){ |
|
159 | - $this->set( $fieldName, isset( $fieldValues[ $fieldName ] ) ? $fieldValues[ $fieldName ] : null, true ); |
|
158 | + foreach ($model_fields as $fieldName => $field) { |
|
159 | + $this->set($fieldName, isset($fieldValues[$fieldName]) ? $fieldValues[$fieldName] : null, true); |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | |
163 | 163 | //remember what values were passed to this constructor |
164 | 164 | $this->_props_n_values_provided_in_constructor = $fieldValues; |
165 | 165 | //remember in entity mapper |
166 | - if($model->has_primary_key_field() && $this->ID() && ! $bydb ){ |
|
166 | + if ($model->has_primary_key_field() && $this->ID() && ! $bydb) { |
|
167 | 167 | $model->add_to_entity_map($this); |
168 | 168 | } |
169 | 169 | //setup all the relations |
170 | - foreach($this->get_model()->relation_settings() as $relation_name=>$relation_obj){ |
|
171 | - if($relation_obj instanceof EE_Belongs_To_Relation){ |
|
170 | + foreach ($this->get_model()->relation_settings() as $relation_name=>$relation_obj) { |
|
171 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
172 | 172 | $this->_model_relations[$relation_name] = NULL; |
173 | - }else{ |
|
173 | + } else { |
|
174 | 174 | $this->_model_relations[$relation_name] = array(); |
175 | 175 | } |
176 | 176 | } |
@@ -178,7 +178,7 @@ discard block |
||
178 | 178 | * Action done at the end of each model object construction |
179 | 179 | * @param EE_Base_Class $this the model object just created |
180 | 180 | */ |
181 | - do_action( 'AHEE__EE_Base_Class__construct__finished', $this ); |
|
181 | + do_action('AHEE__EE_Base_Class__construct__finished', $this); |
|
182 | 182 | } |
183 | 183 | |
184 | 184 | /** |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | * @param boolean $allow_persist |
199 | 199 | * @return boolean |
200 | 200 | */ |
201 | - function set_allow_persist( $allow_persist ) { |
|
201 | + function set_allow_persist($allow_persist) { |
|
202 | 202 | return $this->_allow_persist = $allow_persist; |
203 | 203 | } |
204 | 204 | |
@@ -211,11 +211,11 @@ discard block |
||
211 | 211 | * @param string $field_name |
212 | 212 | * @return mixed|null |
213 | 213 | */ |
214 | - public function get_original( $field_name ){ |
|
215 | - if( isset( $this->_props_n_values_provided_in_constructor[ $field_name ] ) && |
|
216 | - $field_settings = $this->get_Model()->field_settings_for( $field_name )){ |
|
217 | - return $field_settings->prepare_for_get( $this->_props_n_values_provided_in_constructor[ $field_name ] ); |
|
218 | - }else{ |
|
214 | + public function get_original($field_name) { |
|
215 | + if (isset($this->_props_n_values_provided_in_constructor[$field_name]) && |
|
216 | + $field_settings = $this->get_Model()->field_settings_for($field_name)) { |
|
217 | + return $field_settings->prepare_for_get($this->_props_n_values_provided_in_constructor[$field_name]); |
|
218 | + } else { |
|
219 | 219 | return NULL; |
220 | 220 | } |
221 | 221 | } |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | * @param EE_Base_Class $obj |
226 | 226 | * @return string |
227 | 227 | */ |
228 | - public function get_class($obj){ |
|
228 | + public function get_class($obj) { |
|
229 | 229 | return get_class($obj); |
230 | 230 | } |
231 | 231 | |
@@ -238,19 +238,19 @@ discard block |
||
238 | 238 | * @param mixed $field_value |
239 | 239 | * @param bool $use_default |
240 | 240 | */ |
241 | - public function set( $field_name, $field_value, $use_default = FALSE ){ |
|
242 | - $field_obj = $this->get_model()->field_settings_for( $field_name ); |
|
243 | - if ( $field_obj instanceof EE_Model_Field_Base ) { |
|
241 | + public function set($field_name, $field_value, $use_default = FALSE) { |
|
242 | + $field_obj = $this->get_model()->field_settings_for($field_name); |
|
243 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
244 | 244 | // if ( method_exists( $field_obj, 'set_timezone' )) { |
245 | - if ( $field_obj instanceof EE_Datetime_Field ) { |
|
246 | - $field_obj->set_timezone( $this->_timezone ); |
|
247 | - $field_obj->set_date_format( $this->_dt_frmt ); |
|
248 | - $field_obj->set_time_format( $this->_tm_frmt ); |
|
245 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
246 | + $field_obj->set_timezone($this->_timezone); |
|
247 | + $field_obj->set_date_format($this->_dt_frmt); |
|
248 | + $field_obj->set_time_format($this->_tm_frmt); |
|
249 | 249 | } |
250 | 250 | |
251 | 251 | $holder_of_value = $field_obj->prepare_for_set($field_value); |
252 | 252 | //should the value be null? |
253 | - if( ($field_value === NULL || $holder_of_value === NULL || $holder_of_value ==='') && $use_default){ |
|
253 | + if (($field_value === NULL || $holder_of_value === NULL || $holder_of_value === '') && $use_default) { |
|
254 | 254 | $this->_fields[$field_name] = $field_obj->get_default_value(); |
255 | 255 | |
256 | 256 | /** |
@@ -260,19 +260,19 @@ discard block |
||
260 | 260 | * object. |
261 | 261 | * @since 4.6.10+ |
262 | 262 | */ |
263 | - if ( $field_obj instanceof EE_Datetime_Field && ! is_null( $this->_fields[$field_name] ) && ! $this->_fields[$field_name] instanceof DateTime ) { |
|
264 | - empty( $this->_fields[$field_name] ) ? $this->set( $field_name, time() ) : $this->set( $field_name, $this->_fields[$field_name] ); |
|
263 | + if ($field_obj instanceof EE_Datetime_Field && ! is_null($this->_fields[$field_name]) && ! $this->_fields[$field_name] instanceof DateTime) { |
|
264 | + empty($this->_fields[$field_name]) ? $this->set($field_name, time()) : $this->set($field_name, $this->_fields[$field_name]); |
|
265 | 265 | } |
266 | 266 | |
267 | - }else{ |
|
267 | + } else { |
|
268 | 268 | $this->_fields[$field_name] = $holder_of_value; |
269 | 269 | } |
270 | 270 | |
271 | 271 | //if we're not in the constructor... |
272 | 272 | //now check if what we set was a primary key |
273 | - if($this->_props_n_values_provided_in_constructor && //note: props_n_values_provided_in_constructor is only set at the END of the constructor |
|
273 | + if ($this->_props_n_values_provided_in_constructor && //note: props_n_values_provided_in_constructor is only set at the END of the constructor |
|
274 | 274 | $field_name == $this->_get_primary_key_name(get_class($this)) && |
275 | - $field_value){ |
|
275 | + $field_value) { |
|
276 | 276 | //if so, we want all this object's fields to be filled either with |
277 | 277 | //what we've explicitly set on this model |
278 | 278 | //or what we have in the db |
@@ -280,20 +280,20 @@ discard block |
||
280 | 280 | $fields_on_model = $this->_get_model(get_class($this))->field_settings(); |
281 | 281 | |
282 | 282 | $obj_in_db = $this->_get_model(get_class($this))->get_one_by_ID($field_value); |
283 | - foreach($fields_on_model as $field_obj){ |
|
284 | - if( ! array_key_exists($field_obj->get_name(), $this->_props_n_values_provided_in_constructor) |
|
285 | - && $field_obj->get_name() != $field_name ){ |
|
283 | + foreach ($fields_on_model as $field_obj) { |
|
284 | + if ( ! array_key_exists($field_obj->get_name(), $this->_props_n_values_provided_in_constructor) |
|
285 | + && $field_obj->get_name() != $field_name) { |
|
286 | 286 | |
287 | - $this->set($field_obj->get_name(),$obj_in_db->get($field_obj->get_name())); |
|
287 | + $this->set($field_obj->get_name(), $obj_in_db->get($field_obj->get_name())); |
|
288 | 288 | } |
289 | 289 | } |
290 | 290 | //oh this model object has an ID? well make sure its in the entity mapper |
291 | 291 | $this->get_model()->add_to_entity_map($this); |
292 | 292 | } |
293 | 293 | //let's unset any cache for this field_name from the $_cached_properties property. |
294 | - $this->_clear_cached_property( $field_name ); |
|
295 | - }else{ |
|
296 | - throw new EE_Error( sprintf( __( "A valid EE_Model_Field_Base could not be found for the given field name: %s", "event_espresso" ), $field_name ) ); |
|
294 | + $this->_clear_cached_property($field_name); |
|
295 | + } else { |
|
296 | + throw new EE_Error(sprintf(__("A valid EE_Model_Field_Base could not be found for the given field name: %s", "event_espresso"), $field_name)); |
|
297 | 297 | } |
298 | 298 | |
299 | 299 | } |
@@ -312,14 +312,14 @@ discard block |
||
312 | 312 | * @param mixed $field_value The value to set. |
313 | 313 | * @return int|bool @see EE_Base_Class::update_extra_meta() for return docs. |
314 | 314 | */ |
315 | - public function set_field_or_extra_meta( $field_name, $field_value ) { |
|
316 | - if ( $this->get_model()->has_field( $field_name ) ) { |
|
317 | - $this->set( $field_name, $field_value ); |
|
315 | + public function set_field_or_extra_meta($field_name, $field_value) { |
|
316 | + if ($this->get_model()->has_field($field_name)) { |
|
317 | + $this->set($field_name, $field_value); |
|
318 | 318 | return true; |
319 | 319 | } else { |
320 | 320 | //ensure this object is saved first so that extra meta can be properly related. |
321 | 321 | $this->save(); |
322 | - return $this->update_extra_meta( $field_name, $field_value ); |
|
322 | + return $this->update_extra_meta($field_name, $field_value); |
|
323 | 323 | } |
324 | 324 | } |
325 | 325 | |
@@ -343,12 +343,12 @@ discard block |
||
343 | 343 | * @param string $field_name expecting the fully qualified field name. |
344 | 344 | * @return mixed|null value for the field if found. null if not found. |
345 | 345 | */ |
346 | - public function get_field_or_extra_meta( $field_name ) { |
|
347 | - if ( $this->get_model()->has_field( $field_name ) ) { |
|
348 | - $column_value = $this->get( $field_name ); |
|
346 | + public function get_field_or_extra_meta($field_name) { |
|
347 | + if ($this->get_model()->has_field($field_name)) { |
|
348 | + $column_value = $this->get($field_name); |
|
349 | 349 | } else { |
350 | 350 | //This isn't a column in the main table, let's see if it is in the extra meta. |
351 | - $column_value = $this->get_extra_meta( $field_name, true, null ); |
|
351 | + $column_value = $this->get_extra_meta($field_name, true, null); |
|
352 | 352 | } |
353 | 353 | return $column_value; |
354 | 354 | } |
@@ -367,19 +367,19 @@ discard block |
||
367 | 367 | * @param string $timezone A valid timezone string as described by @link http://www.php.net/manual/en/timezones.php |
368 | 368 | * @return void |
369 | 369 | */ |
370 | - public function set_timezone( $timezone = '' ) { |
|
370 | + public function set_timezone($timezone = '') { |
|
371 | 371 | EE_Registry::instance()->load_helper('DTT_Helper'); |
372 | - $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string( $timezone ); |
|
372 | + $this->_timezone = EEH_DTT_Helper::get_valid_timezone_string($timezone); |
|
373 | 373 | //make sure we clear all cached properties because they won't be relevant now |
374 | 374 | $this->_clear_cached_properties(); |
375 | 375 | |
376 | 376 | //make sure we update field settings and the date for all EE_Datetime_Fields |
377 | - $model_fields = $this->get_model()->field_settings( false ); |
|
378 | - foreach ( $model_fields as $field_name => $field_obj ) { |
|
379 | - if ( $field_obj instanceof EE_Datetime_Field ) { |
|
380 | - $field_obj->set_timezone( $this->_timezone ); |
|
381 | - if ( isset( $this->_fields[$field_name] ) && $this->_fields[$field_name] instanceof DateTime ) { |
|
382 | - $this->_fields[$field_name]->setTimezone( new DateTimeZone( $this->_timezone ) ); |
|
377 | + $model_fields = $this->get_model()->field_settings(false); |
|
378 | + foreach ($model_fields as $field_name => $field_obj) { |
|
379 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
380 | + $field_obj->set_timezone($this->_timezone); |
|
381 | + if (isset($this->_fields[$field_name]) && $this->_fields[$field_name] instanceof DateTime) { |
|
382 | + $this->_fields[$field_name]->setTimezone(new DateTimeZone($this->_timezone)); |
|
383 | 383 | } |
384 | 384 | } |
385 | 385 | } |
@@ -408,7 +408,7 @@ discard block |
||
408 | 408 | * |
409 | 409 | * @param string $format should be a format recognizable by PHP date() functions. |
410 | 410 | */ |
411 | - public function set_date_format( $format ) { |
|
411 | + public function set_date_format($format) { |
|
412 | 412 | $this->_dt_frmt = $format; |
413 | 413 | //clear cached_properties because they won't be relevant now. |
414 | 414 | $this->_clear_cached_properties(); |
@@ -424,7 +424,7 @@ discard block |
||
424 | 424 | * @since 4.6 |
425 | 425 | * @param string $format should be a format recognizable by PHP date() functions. |
426 | 426 | */ |
427 | - public function set_time_format( $format ) { |
|
427 | + public function set_time_format($format) { |
|
428 | 428 | $this->_tm_frmt = $format; |
429 | 429 | //clear cached_properties because they won't be relevant now. |
430 | 430 | $this->_clear_cached_properties(); |
@@ -441,8 +441,8 @@ discard block |
||
441 | 441 | * |
442 | 442 | * @return mixed string|array |
443 | 443 | */ |
444 | - public function get_format( $full = true ) { |
|
445 | - return $full ? $this->_dt_frmt . ' ' . $this->_tm_frmt : array( $this->_dt_frmt, $this->_tm_frmt ); |
|
444 | + public function get_format($full = true) { |
|
445 | + return $full ? $this->_dt_frmt.' '.$this->_tm_frmt : array($this->_dt_frmt, $this->_tm_frmt); |
|
446 | 446 | } |
447 | 447 | |
448 | 448 | |
@@ -460,17 +460,17 @@ discard block |
||
460 | 460 | * @throws EE_Error |
461 | 461 | * @return mixed index into cache, or just TRUE if the relation is of type Belongs_To (because there's only one related thing, no array) |
462 | 462 | */ |
463 | - public function cache( $relationName = '', $object_to_cache = NULL, $cache_id = NULL ){ |
|
463 | + public function cache($relationName = '', $object_to_cache = NULL, $cache_id = NULL) { |
|
464 | 464 | // its entirely possible that there IS no related object yet in which case there is nothing to cache. |
465 | - if ( ! $object_to_cache instanceof EE_Base_Class ) { |
|
465 | + if ( ! $object_to_cache instanceof EE_Base_Class) { |
|
466 | 466 | return FALSE; |
467 | 467 | } |
468 | 468 | // also get "how" the object is related, or throw an error |
469 | - if( ! $relationship_to_model = $this->get_model()->related_settings_for( $relationName )) { |
|
470 | - throw new EE_Error( sprintf( __( 'There is no relationship to %s on a %s. Cannot cache it', 'event_espresso' ), $relationName, get_class( $this ))); |
|
469 | + if ( ! $relationship_to_model = $this->get_model()->related_settings_for($relationName)) { |
|
470 | + throw new EE_Error(sprintf(__('There is no relationship to %s on a %s. Cannot cache it', 'event_espresso'), $relationName, get_class($this))); |
|
471 | 471 | } |
472 | 472 | // how many things are related ? |
473 | - if( $relationship_to_model instanceof EE_Belongs_To_Relation ){ |
|
473 | + if ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
474 | 474 | // if it's a "belongs to" relationship, then there's only one related model object eg, if this is a registration, there's only 1 attendee for it |
475 | 475 | // so for these model objects just set it to be cached |
476 | 476 | $this->_model_relations[$relationName] = $object_to_cache; |
@@ -478,26 +478,26 @@ discard block |
||
478 | 478 | } else { |
479 | 479 | // otherwise, this is the "many" side of a one to many relationship, so we'll add the object to the array of related objects for that type. |
480 | 480 | // eg: if this is an event, there are many registrations for that event, so we cache the registrations in an array |
481 | - if( ! is_array( $this->_model_relations[$relationName] )) { |
|
481 | + if ( ! is_array($this->_model_relations[$relationName])) { |
|
482 | 482 | // if for some reason, the cached item is a model object, then stick that in the array, otherwise start with an empty array |
483 | - $this->_model_relations[$relationName] = $this->_model_relations[$relationName] instanceof EE_Base_Class ? array( $this->_model_relations[$relationName] ) : array(); |
|
483 | + $this->_model_relations[$relationName] = $this->_model_relations[$relationName] instanceof EE_Base_Class ? array($this->_model_relations[$relationName]) : array(); |
|
484 | 484 | } |
485 | 485 | // first check for a cache_id which is normally empty |
486 | - if ( ! empty( $cache_id )) { |
|
486 | + if ( ! empty($cache_id)) { |
|
487 | 487 | // if the cache_id exists, then it means we are purposely trying to cache this with a known key that can then be used to retrieve the object later on |
488 | - $this->_model_relations[$relationName][ $cache_id ] = $object_to_cache; |
|
488 | + $this->_model_relations[$relationName][$cache_id] = $object_to_cache; |
|
489 | 489 | $return = $cache_id; |
490 | - } elseif ( $object_to_cache->ID() ) { |
|
490 | + } elseif ($object_to_cache->ID()) { |
|
491 | 491 | // OR the cached object originally came from the db, so let's just use it's PK for an ID |
492 | - $this->_model_relations[$relationName][ $object_to_cache->ID() ] = $object_to_cache; |
|
492 | + $this->_model_relations[$relationName][$object_to_cache->ID()] = $object_to_cache; |
|
493 | 493 | $return = $object_to_cache->ID(); |
494 | 494 | } else { |
495 | 495 | // OR it's a new object with no ID, so just throw it in the array with an auto-incremented ID |
496 | 496 | $this->_model_relations[$relationName][] = $object_to_cache; |
497 | 497 | // move the internal pointer to the end of the array |
498 | - end( $this->_model_relations[$relationName] ); |
|
498 | + end($this->_model_relations[$relationName]); |
|
499 | 499 | // and grab the key so that we can return it |
500 | - $return = key( $this->_model_relations[$relationName] ); |
|
500 | + $return = key($this->_model_relations[$relationName]); |
|
501 | 501 | } |
502 | 502 | |
503 | 503 | } |
@@ -515,11 +515,11 @@ discard block |
||
515 | 515 | * @param null $cache_type |
516 | 516 | * @return void |
517 | 517 | */ |
518 | - protected function _set_cached_property( $fieldname, $value, $cache_type = NULL ) { |
|
518 | + protected function _set_cached_property($fieldname, $value, $cache_type = NULL) { |
|
519 | 519 | //first make sure this property exists |
520 | 520 | $this->get_model()->field_settings_for($fieldname); |
521 | 521 | |
522 | - $cache_type = empty( $cache_type ) ? 'standard' : $cache_type; |
|
522 | + $cache_type = empty($cache_type) ? 'standard' : $cache_type; |
|
523 | 523 | $this->_cached_properties[$fieldname][$cache_type] = $value; |
524 | 524 | } |
525 | 525 | |
@@ -534,34 +534,34 @@ discard block |
||
534 | 534 | * It can also accept certain pre-defined "schema" strings to define how to output the property. see the field's prepare_for_pretty_echoing for what strings can be used |
535 | 535 | * @return mixed whatever the value for the property is we're retrieving |
536 | 536 | */ |
537 | - protected function _get_cached_property( $fieldname, $pretty = FALSE, $extra_cache_ref = NULL ) { |
|
537 | + protected function _get_cached_property($fieldname, $pretty = FALSE, $extra_cache_ref = NULL) { |
|
538 | 538 | //verify the field exists |
539 | 539 | $this->get_model()->field_settings_for($fieldname); |
540 | 540 | |
541 | 541 | $cache_type = $pretty ? 'pretty' : 'standard'; |
542 | - $cache_type .= !empty( $extra_cache_ref ) ? '_' . $extra_cache_ref : ''; |
|
542 | + $cache_type .= ! empty($extra_cache_ref) ? '_'.$extra_cache_ref : ''; |
|
543 | 543 | |
544 | - if ( isset( $this->_cached_properties[$fieldname][$cache_type] ) ) { |
|
544 | + if (isset($this->_cached_properties[$fieldname][$cache_type])) { |
|
545 | 545 | return $this->_cached_properties[$fieldname][$cache_type]; |
546 | 546 | } |
547 | 547 | |
548 | 548 | $field_obj = $this->get_model()->field_settings_for($fieldname); |
549 | - if ( $field_obj instanceof EE_Model_Field_Base ) { |
|
549 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
550 | 550 | /** |
551 | 551 | * maybe this is EE_Datetime_Field. If so we need to make sure timezone and |
552 | 552 | * formats are correct. |
553 | 553 | */ |
554 | - if ( $field_obj instanceof EE_Datetime_Field ) { |
|
555 | - $field_obj->set_timezone( $this->_timezone ); |
|
556 | - $field_obj->set_date_format( $this->_dt_frmt, $pretty ); |
|
557 | - $field_obj->set_time_format( $this->_tm_frmt, $pretty ); |
|
554 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
555 | + $field_obj->set_timezone($this->_timezone); |
|
556 | + $field_obj->set_date_format($this->_dt_frmt, $pretty); |
|
557 | + $field_obj->set_time_format($this->_tm_frmt, $pretty); |
|
558 | 558 | } |
559 | 559 | |
560 | - if( ! isset($this->_fields[$fieldname])){ |
|
560 | + if ( ! isset($this->_fields[$fieldname])) { |
|
561 | 561 | $this->_fields[$fieldname] = NULL; |
562 | 562 | } |
563 | - $value = $pretty ? $field_obj->prepare_for_pretty_echoing($this->_fields[$fieldname], $extra_cache_ref) : $field_obj->prepare_for_get($this->_fields[$fieldname] ); |
|
564 | - $this->_set_cached_property( $fieldname, $value, $cache_type ); |
|
563 | + $value = $pretty ? $field_obj->prepare_for_pretty_echoing($this->_fields[$fieldname], $extra_cache_ref) : $field_obj->prepare_for_get($this->_fields[$fieldname]); |
|
564 | + $this->_set_cached_property($fieldname, $value, $cache_type); |
|
565 | 565 | return $value; |
566 | 566 | } |
567 | 567 | return FALSE; |
@@ -587,9 +587,9 @@ discard block |
||
587 | 587 | * @param string $property_name the property to remove if it exists (from the _cached_properties array) |
588 | 588 | * @return void |
589 | 589 | */ |
590 | - protected function _clear_cached_property( $property_name ) { |
|
591 | - if ( isset( $this->_cached_properties[ $property_name ] ) ) |
|
592 | - unset( $this->_cached_properties[ $property_name ] ); |
|
590 | + protected function _clear_cached_property($property_name) { |
|
591 | + if (isset($this->_cached_properties[$property_name])) |
|
592 | + unset($this->_cached_properties[$property_name]); |
|
593 | 593 | } |
594 | 594 | |
595 | 595 | |
@@ -600,7 +600,7 @@ discard block |
||
600 | 600 | * @param string $model_name name of the related thing, eg 'Attendee', |
601 | 601 | * @return EE_Base_Class |
602 | 602 | */ |
603 | - protected function ensure_related_thing_is_model_obj($object_or_id,$model_name){ |
|
603 | + protected function ensure_related_thing_is_model_obj($object_or_id, $model_name) { |
|
604 | 604 | $other_model_instance = self::_get_model_instance_with_name(self::_get_model_classname($model_name), $this->_timezone); |
605 | 605 | $model_obj = $other_model_instance->ensure_is_obj($object_or_id); |
606 | 606 | return $model_obj; |
@@ -620,55 +620,55 @@ discard block |
||
620 | 620 | * @throws EE_Error |
621 | 621 | * @return EE_Base_Class | boolean from which was cleared from the cache, or true if we requested to remove a relation from all |
622 | 622 | */ |
623 | - public function clear_cache($relationName, $object_to_remove_or_index_into_array = NULL, $clear_all = FALSE){ |
|
623 | + public function clear_cache($relationName, $object_to_remove_or_index_into_array = NULL, $clear_all = FALSE) { |
|
624 | 624 | $relationship_to_model = $this->get_model()->related_settings_for($relationName); |
625 | 625 | $index_in_cache = ''; |
626 | - if( ! $relationship_to_model){ |
|
627 | - throw new EE_Error(sprintf(__("There is no relationship to %s on a %s. Cannot clear that cache",'event_espresso'),$relationName,get_class($this))); |
|
626 | + if ( ! $relationship_to_model) { |
|
627 | + throw new EE_Error(sprintf(__("There is no relationship to %s on a %s. Cannot clear that cache", 'event_espresso'), $relationName, get_class($this))); |
|
628 | 628 | } |
629 | - if($clear_all){ |
|
629 | + if ($clear_all) { |
|
630 | 630 | $obj_removed = true; |
631 | 631 | $this->_model_relations[$relationName] = null; |
632 | - }elseif($relationship_to_model instanceof EE_Belongs_To_Relation){ |
|
632 | + }elseif ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
633 | 633 | $obj_removed = $this->_model_relations[$relationName]; |
634 | 634 | $this->_model_relations[$relationName] = null; |
635 | - }else{ |
|
636 | - if($object_to_remove_or_index_into_array instanceof EE_Base_Class && $object_to_remove_or_index_into_array->ID()){ |
|
635 | + } else { |
|
636 | + if ($object_to_remove_or_index_into_array instanceof EE_Base_Class && $object_to_remove_or_index_into_array->ID()) { |
|
637 | 637 | $index_in_cache = $object_to_remove_or_index_into_array->ID(); |
638 | - if( is_array($this->_model_relations[$relationName]) && ! isset($this->_model_relations[$relationName][$index_in_cache])){ |
|
638 | + if (is_array($this->_model_relations[$relationName]) && ! isset($this->_model_relations[$relationName][$index_in_cache])) { |
|
639 | 639 | $index_found_at = NULL; |
640 | 640 | //find this object in the array even though it has a different key |
641 | - foreach($this->_model_relations[$relationName] as $index=>$obj){ |
|
642 | - if( $obj instanceof EE_Base_Class && ( $obj == $object_to_remove_or_index_into_array || $obj->ID() == $object_to_remove_or_index_into_array->ID() )) { |
|
641 | + foreach ($this->_model_relations[$relationName] as $index=>$obj) { |
|
642 | + if ($obj instanceof EE_Base_Class && ($obj == $object_to_remove_or_index_into_array || $obj->ID() == $object_to_remove_or_index_into_array->ID())) { |
|
643 | 643 | $index_found_at = $index; |
644 | 644 | break; |
645 | 645 | } |
646 | 646 | } |
647 | - if($index_found_at){ |
|
647 | + if ($index_found_at) { |
|
648 | 648 | $index_in_cache = $index_found_at; |
649 | - }else{ |
|
649 | + } else { |
|
650 | 650 | //it wasn't found. huh. well obviously it doesn't need to be removed from teh cache |
651 | 651 | //if it wasn't in it to begin with. So we're done |
652 | 652 | return $object_to_remove_or_index_into_array; |
653 | 653 | } |
654 | 654 | } |
655 | - }elseif($object_to_remove_or_index_into_array instanceof EE_Base_Class){ |
|
655 | + }elseif ($object_to_remove_or_index_into_array instanceof EE_Base_Class) { |
|
656 | 656 | //so they provided a model object, but it's not yet saved to the DB... so let's go hunting for it! |
657 | - foreach($this->get_all_from_cache($relationName) as $index => $potentially_obj_we_want){ |
|
658 | - if($potentially_obj_we_want == $object_to_remove_or_index_into_array){ |
|
657 | + foreach ($this->get_all_from_cache($relationName) as $index => $potentially_obj_we_want) { |
|
658 | + if ($potentially_obj_we_want == $object_to_remove_or_index_into_array) { |
|
659 | 659 | $index_in_cache = $index; |
660 | 660 | } |
661 | 661 | } |
662 | - }else{ |
|
662 | + } else { |
|
663 | 663 | $index_in_cache = $object_to_remove_or_index_into_array; |
664 | 664 | } |
665 | 665 | //supposedly we've found it. But it could just be that the client code |
666 | 666 | //provided a bad index/object |
667 | - if(isset( $this->_model_relations[$relationName]) && |
|
668 | - isset( $this->_model_relations[$relationName][$index_in_cache])){ |
|
667 | + if (isset($this->_model_relations[$relationName]) && |
|
668 | + isset($this->_model_relations[$relationName][$index_in_cache])) { |
|
669 | 669 | $obj_removed = $this->_model_relations[$relationName][$index_in_cache]; |
670 | 670 | unset($this->_model_relations[$relationName][$index_in_cache]); |
671 | - }else{ |
|
671 | + } else { |
|
672 | 672 | //that thing was never cached anyways. |
673 | 673 | $obj_removed = NULL; |
674 | 674 | } |
@@ -687,24 +687,24 @@ discard block |
||
687 | 687 | * @param string $current_cache_id - the ID that was used when originally caching the object |
688 | 688 | * @return boolean TRUE on success, FALSE on fail |
689 | 689 | */ |
690 | - public function update_cache_after_object_save( $relationName, EE_Base_Class $newly_saved_object, $current_cache_id = '') { |
|
690 | + public function update_cache_after_object_save($relationName, EE_Base_Class $newly_saved_object, $current_cache_id = '') { |
|
691 | 691 | // verify that incoming object is of the correct type |
692 | - $obj_class = 'EE_' . $relationName; |
|
693 | - if ( $newly_saved_object instanceof $obj_class ) { |
|
692 | + $obj_class = 'EE_'.$relationName; |
|
693 | + if ($newly_saved_object instanceof $obj_class) { |
|
694 | 694 | /* @type EE_Base_Class $newly_saved_object*/ |
695 | 695 | // now get the type of relation |
696 | - $relationship_to_model = $this->get_model()->related_settings_for( $relationName ); |
|
696 | + $relationship_to_model = $this->get_model()->related_settings_for($relationName); |
|
697 | 697 | // if this is a 1:1 relationship |
698 | - if( $relationship_to_model instanceof EE_Belongs_To_Relation ) { |
|
698 | + if ($relationship_to_model instanceof EE_Belongs_To_Relation) { |
|
699 | 699 | // then just replace the cached object with the newly saved object |
700 | 700 | $this->_model_relations[$relationName] = $newly_saved_object; |
701 | 701 | return TRUE; |
702 | 702 | // or if it's some kind of sordid feral polyamorous relationship... |
703 | - } elseif ( is_array( $this->_model_relations[$relationName] ) && isset( $this->_model_relations[$relationName][ $current_cache_id ] )) { |
|
703 | + } elseif (is_array($this->_model_relations[$relationName]) && isset($this->_model_relations[$relationName][$current_cache_id])) { |
|
704 | 704 | // then remove the current cached item |
705 | - unset( $this->_model_relations[$relationName][ $current_cache_id ] ); |
|
705 | + unset($this->_model_relations[$relationName][$current_cache_id]); |
|
706 | 706 | // and cache the newly saved object using it's new ID |
707 | - $this->_model_relations[$relationName][ $newly_saved_object->ID() ] = $newly_saved_object; |
|
707 | + $this->_model_relations[$relationName][$newly_saved_object->ID()] = $newly_saved_object; |
|
708 | 708 | return TRUE; |
709 | 709 | } |
710 | 710 | } |
@@ -720,11 +720,11 @@ discard block |
||
720 | 720 | * @param string $relationName |
721 | 721 | * @return EE_Base_Class |
722 | 722 | */ |
723 | - public function get_one_from_cache($relationName){ |
|
724 | - $cached_array_or_object = isset( $this->_model_relations[$relationName] ) ? $this->_model_relations[$relationName] : null; |
|
725 | - if(is_array($cached_array_or_object)){ |
|
723 | + public function get_one_from_cache($relationName) { |
|
724 | + $cached_array_or_object = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] : null; |
|
725 | + if (is_array($cached_array_or_object)) { |
|
726 | 726 | return array_shift($cached_array_or_object); |
727 | - }else{ |
|
727 | + } else { |
|
728 | 728 | return $cached_array_or_object; |
729 | 729 | } |
730 | 730 | } |
@@ -739,14 +739,14 @@ discard block |
||
739 | 739 | * @throws \EE_Error |
740 | 740 | * @return EE_Base_Class[] NOT necessarily indexed by primary keys |
741 | 741 | */ |
742 | - public function get_all_from_cache($relationName){ |
|
743 | - $cached_array_or_object = isset( $this->_model_relations[$relationName] ) ? $this->_model_relations[$relationName] : array(); |
|
744 | - if(is_array($cached_array_or_object)){ |
|
742 | + public function get_all_from_cache($relationName) { |
|
743 | + $cached_array_or_object = isset($this->_model_relations[$relationName]) ? $this->_model_relations[$relationName] : array(); |
|
744 | + if (is_array($cached_array_or_object)) { |
|
745 | 745 | $objects = $cached_array_or_object; |
746 | - }elseif($cached_array_or_object){ |
|
746 | + }elseif ($cached_array_or_object) { |
|
747 | 747 | //if the result is not an array, but exists, make it an array |
748 | 748 | $objects = array($cached_array_or_object); |
749 | - }else{ |
|
749 | + } else { |
|
750 | 750 | //if nothing was found, return an empty array |
751 | 751 | $objects = array(); |
752 | 752 | } |
@@ -754,15 +754,15 @@ discard block |
||
754 | 754 | //basically, if this model object was stored in the session, and these cached model objects |
755 | 755 | //already have IDs, let's make sure they're in their model's entity mapper |
756 | 756 | //otherwise we will have duplicates next time we call EE_Registry::instance()->load_model( $relationName )->get_one_by_ID( $result->ID() ); |
757 | - foreach( $objects as $model_object ){ |
|
758 | - $model = EE_Registry::instance()->load_model( $relationName ); |
|
759 | - if( $model instanceof EEM_Base && $model_object instanceof EE_Base_Class ){ |
|
757 | + foreach ($objects as $model_object) { |
|
758 | + $model = EE_Registry::instance()->load_model($relationName); |
|
759 | + if ($model instanceof EEM_Base && $model_object instanceof EE_Base_Class) { |
|
760 | 760 | //ensure its in the map if it has an ID; otherwise it will be added to the map when its saved |
761 | - if( $model_object->ID() ){ |
|
762 | - $model->add_to_entity_map( $model_object ); |
|
761 | + if ($model_object->ID()) { |
|
762 | + $model->add_to_entity_map($model_object); |
|
763 | 763 | } |
764 | - }else{ |
|
765 | - throw new EE_Error( sprintf( __( 'Error retrieving related model objects. Either $1%s is not a model or $2%s is not a model object', 'event_espresso' ), $relationName, gettype( $model_object ))); |
|
764 | + } else { |
|
765 | + throw new EE_Error(sprintf(__('Error retrieving related model objects. Either $1%s is not a model or $2%s is not a model object', 'event_espresso'), $relationName, gettype($model_object))); |
|
766 | 766 | } |
767 | 767 | } |
768 | 768 | return $objects; |
@@ -781,13 +781,13 @@ discard block |
||
781 | 781 | * |
782 | 782 | * @return array|EE_Base_Class[] |
783 | 783 | */ |
784 | - public function next_x( $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) { |
|
785 | - $field = empty( $field_to_order_by ) && $this->get_model()->has_primary_key_field() ? $this->get_model()->get_primary_key_field()->get_name() : $field_to_order_by; |
|
786 | - $current_value = ! empty( $field ) ? $this->get( $field ) : null; |
|
787 | - if ( empty( $field ) || empty( $current_value ) ) { |
|
784 | + public function next_x($field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) { |
|
785 | + $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() ? $this->get_model()->get_primary_key_field()->get_name() : $field_to_order_by; |
|
786 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
787 | + if (empty($field) || empty($current_value)) { |
|
788 | 788 | return array(); |
789 | 789 | } |
790 | - return $this->get_model()->next_x( $current_value, $field, $limit, $query_params, $columns_to_select ); |
|
790 | + return $this->get_model()->next_x($current_value, $field, $limit, $query_params, $columns_to_select); |
|
791 | 791 | } |
792 | 792 | |
793 | 793 | |
@@ -806,13 +806,13 @@ discard block |
||
806 | 806 | * |
807 | 807 | * @return array|EE_Base_Class[] |
808 | 808 | */ |
809 | - public function previous_x( $field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null ) { |
|
810 | - $field = empty( $field_to_order_by ) && $this->get_model()->has_primary_key_field() ? $this->get_model()->get_primary_key_field()->get_name() : $field_to_order_by; |
|
811 | - $current_value = ! empty( $field ) ? $this->get( $field ) : null; |
|
812 | - if ( empty( $field ) || empty( $current_value ) ) { |
|
809 | + public function previous_x($field_to_order_by = null, $limit = 1, $query_params = array(), $columns_to_select = null) { |
|
810 | + $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() ? $this->get_model()->get_primary_key_field()->get_name() : $field_to_order_by; |
|
811 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
812 | + if (empty($field) || empty($current_value)) { |
|
813 | 813 | return array(); |
814 | 814 | } |
815 | - return $this->get_model()->previous_x( $current_value, $field, $limit, $query_params, $columns_to_select ); |
|
815 | + return $this->get_model()->previous_x($current_value, $field, $limit, $query_params, $columns_to_select); |
|
816 | 816 | } |
817 | 817 | |
818 | 818 | |
@@ -830,13 +830,13 @@ discard block |
||
830 | 830 | * |
831 | 831 | * @return array|EE_Base_Class |
832 | 832 | */ |
833 | - public function next( $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) { |
|
834 | - $field = empty( $field_to_order_by ) && $this->get_model()->has_primary_key_field() ? $this->get_model()->get_primary_key_field()->get_name() : $field_to_order_by; |
|
835 | - $current_value = ! empty( $field ) ? $this->get( $field ) : null; |
|
836 | - if ( empty( $field ) || empty( $current_value ) ) { |
|
833 | + public function next($field_to_order_by = null, $query_params = array(), $columns_to_select = null) { |
|
834 | + $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() ? $this->get_model()->get_primary_key_field()->get_name() : $field_to_order_by; |
|
835 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
836 | + if (empty($field) || empty($current_value)) { |
|
837 | 837 | return array(); |
838 | 838 | } |
839 | - return $this->get_model()->next( $current_value, $field, $query_params, $columns_to_select ); |
|
839 | + return $this->get_model()->next($current_value, $field, $query_params, $columns_to_select); |
|
840 | 840 | } |
841 | 841 | |
842 | 842 | |
@@ -855,13 +855,13 @@ discard block |
||
855 | 855 | * |
856 | 856 | * @return array|EE_Base_Class |
857 | 857 | */ |
858 | - public function previous( $field_to_order_by = null, $query_params = array(), $columns_to_select = null ) { |
|
859 | - $field = empty( $field_to_order_by ) && $this->get_model()->has_primary_key_field() ? $this->get_model()->get_primary_key_field()->get_name() : $field_to_order_by; |
|
860 | - $current_value = ! empty( $field ) ? $this->get( $field ) : null; |
|
861 | - if ( empty( $field ) || empty( $current_value ) ) { |
|
858 | + public function previous($field_to_order_by = null, $query_params = array(), $columns_to_select = null) { |
|
859 | + $field = empty($field_to_order_by) && $this->get_model()->has_primary_key_field() ? $this->get_model()->get_primary_key_field()->get_name() : $field_to_order_by; |
|
860 | + $current_value = ! empty($field) ? $this->get($field) : null; |
|
861 | + if (empty($field) || empty($current_value)) { |
|
862 | 862 | return array(); |
863 | 863 | } |
864 | - return $this->get_model()->previous( $current_value, $field, $query_params, $columns_to_select ); |
|
864 | + return $this->get_model()->previous($current_value, $field, $query_params, $columns_to_select); |
|
865 | 865 | } |
866 | 866 | |
867 | 867 | |
@@ -875,25 +875,25 @@ discard block |
||
875 | 875 | * @param string $field_name |
876 | 876 | * @param mixed $field_value_from_db |
877 | 877 | */ |
878 | - public function set_from_db($field_name,$field_value_from_db){ |
|
878 | + public function set_from_db($field_name, $field_value_from_db) { |
|
879 | 879 | $field_obj = $this->get_model()->field_settings_for($field_name); |
880 | - if ( $field_obj instanceof EE_Model_Field_Base ) { |
|
880 | + if ($field_obj instanceof EE_Model_Field_Base) { |
|
881 | 881 | //you would think the DB has no NULLs for non-null label fields right? wrong! |
882 | 882 | //eg, a CPT model object could have an entry in the posts table, but no |
883 | 883 | //entry in the meta table. Meaning that all its columns in the meta table |
884 | 884 | //are null! yikes! so when we find one like that, use defaults for its meta columns |
885 | - if($field_value_from_db === NULL ){ |
|
886 | - if( $field_obj->is_nullable()){ |
|
885 | + if ($field_value_from_db === NULL) { |
|
886 | + if ($field_obj->is_nullable()) { |
|
887 | 887 | //if the field allows nulls, then let it be null |
888 | 888 | $field_value = NULL; |
889 | - }else{ |
|
889 | + } else { |
|
890 | 890 | $field_value = $field_obj->get_default_value(); |
891 | 891 | } |
892 | - }else{ |
|
893 | - $field_value = $field_obj->prepare_for_set_from_db( $field_value_from_db ); |
|
892 | + } else { |
|
893 | + $field_value = $field_obj->prepare_for_set_from_db($field_value_from_db); |
|
894 | 894 | } |
895 | 895 | $this->_fields[$field_name] = $field_value; |
896 | - $this->_clear_cached_property( $field_name ); |
|
896 | + $this->_clear_cached_property($field_name); |
|
897 | 897 | } |
898 | 898 | } |
899 | 899 | |
@@ -905,8 +905,8 @@ discard block |
||
905 | 905 | * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property (in cases where the same property may be used for different outputs - i.e. datetime, money etc.) |
906 | 906 | * @return boolean |
907 | 907 | */ |
908 | - public function get($field_name, $extra_cache_ref = NULL ){ |
|
909 | - return $this->_get_cached_property( $field_name, FALSE, $extra_cache_ref ); |
|
908 | + public function get($field_name, $extra_cache_ref = NULL) { |
|
909 | + return $this->_get_cached_property($field_name, FALSE, $extra_cache_ref); |
|
910 | 910 | } |
911 | 911 | |
912 | 912 | |
@@ -936,11 +936,11 @@ discard block |
||
936 | 936 | * just null is returned (because that indicates that likely |
937 | 937 | * this field is nullable). |
938 | 938 | */ |
939 | - public function get_DateTime_object( $field_name ) { |
|
940 | - $field_settings = $this->get_model()->field_settings_for( $field_name ); |
|
939 | + public function get_DateTime_object($field_name) { |
|
940 | + $field_settings = $this->get_model()->field_settings_for($field_name); |
|
941 | 941 | |
942 | - if ( ! $field_settings instanceof EE_Datetime_Field ) { |
|
943 | - EE_Error::add_error( sprintf( __('The field %s is not an EE_Datetime_Field field. There is no DateTime object stored on this field type.', 'event_espresso' ), $field_name ), __FILE__, __FUNCTION__, __LINE__ ); |
|
942 | + if ( ! $field_settings instanceof EE_Datetime_Field) { |
|
943 | + EE_Error::add_error(sprintf(__('The field %s is not an EE_Datetime_Field field. There is no DateTime object stored on this field type.', 'event_espresso'), $field_name), __FILE__, __FUNCTION__, __LINE__); |
|
944 | 944 | return false; |
945 | 945 | } |
946 | 946 | |
@@ -956,7 +956,7 @@ discard block |
||
956 | 956 | * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property (in cases where the same property may be used for different outputs - i.e. datetime, money etc.) |
957 | 957 | * @return void |
958 | 958 | */ |
959 | - public function e($field_name, $extra_cache_ref = NULL){ |
|
959 | + public function e($field_name, $extra_cache_ref = NULL) { |
|
960 | 960 | echo $this->get_pretty($field_name, $extra_cache_ref); |
961 | 961 | } |
962 | 962 | /** |
@@ -965,8 +965,8 @@ discard block |
||
965 | 965 | * @param string $field_name |
966 | 966 | * @return void |
967 | 967 | */ |
968 | - public function f($field_name){ |
|
969 | - $this->e($field_name,'form_input'); |
|
968 | + public function f($field_name) { |
|
969 | + $this->e($field_name, 'form_input'); |
|
970 | 970 | } |
971 | 971 | |
972 | 972 | /** |
@@ -975,8 +975,8 @@ discard block |
||
975 | 975 | * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property (in cases where the same property may be used for different outputs - i.e. datetime, money etc.) |
976 | 976 | * @return mixed |
977 | 977 | */ |
978 | - public function get_pretty($field_name, $extra_cache_ref = NULL){ |
|
979 | - return $this->_get_cached_property( $field_name, TRUE, $extra_cache_ref ); |
|
978 | + public function get_pretty($field_name, $extra_cache_ref = NULL) { |
|
979 | + return $this->_get_cached_property($field_name, TRUE, $extra_cache_ref); |
|
980 | 980 | } |
981 | 981 | |
982 | 982 | |
@@ -993,37 +993,37 @@ discard block |
||
993 | 993 | * @param boolean $echo Whether the dtt is echoing using pretty echoing or just returned using vanilla get |
994 | 994 | * @return void | string | bool | EE_Error string on success, FALSE on fail, or EE_Error Exception is thrown if field is not a valid dtt field, or void if echoing |
995 | 995 | */ |
996 | - protected function _get_datetime( $field_name, $dt_frmt = NULL, $tm_frmt = NULL, $date_or_time = NULL, $echo = FALSE ) { |
|
996 | + protected function _get_datetime($field_name, $dt_frmt = NULL, $tm_frmt = NULL, $date_or_time = NULL, $echo = FALSE) { |
|
997 | 997 | |
998 | - $in_dt_frmt = empty($dt_frmt) ? $this->_dt_frmt : $dt_frmt; |
|
998 | + $in_dt_frmt = empty($dt_frmt) ? $this->_dt_frmt : $dt_frmt; |
|
999 | 999 | $in_tm_frmt = empty($tm_frmt) ? $this->_tm_frmt : $tm_frmt; |
1000 | 1000 | |
1001 | 1001 | //validate field for datetime and returns field settings if valid. |
1002 | - $field = $this->_get_dtt_field_settings( $field_name ); |
|
1002 | + $field = $this->_get_dtt_field_settings($field_name); |
|
1003 | 1003 | |
1004 | 1004 | //clear cached property if either formats are not null. |
1005 | - if( $dt_frmt !== null || $tm_frmt !== null ) { |
|
1006 | - $this->_clear_cached_property( $field_name ); |
|
1005 | + if ($dt_frmt !== null || $tm_frmt !== null) { |
|
1006 | + $this->_clear_cached_property($field_name); |
|
1007 | 1007 | //reset format properties because they are used in get() |
1008 | 1008 | $this->_dt_frmt = $in_dt_frmt; |
1009 | 1009 | $this->_tm_frmt = $in_tm_frmt; |
1010 | 1010 | } |
1011 | 1011 | |
1012 | - if ( $echo ) |
|
1013 | - $field->set_pretty_date_format( $in_dt_frmt ); |
|
1012 | + if ($echo) |
|
1013 | + $field->set_pretty_date_format($in_dt_frmt); |
|
1014 | 1014 | else |
1015 | - $field->set_date_format( $in_dt_frmt ); |
|
1015 | + $field->set_date_format($in_dt_frmt); |
|
1016 | 1016 | |
1017 | - if ( $echo ) |
|
1018 | - $field->set_pretty_time_format( $in_tm_frmt ); |
|
1017 | + if ($echo) |
|
1018 | + $field->set_pretty_time_format($in_tm_frmt); |
|
1019 | 1019 | else |
1020 | - $field->set_time_format( $in_tm_frmt ); |
|
1020 | + $field->set_time_format($in_tm_frmt); |
|
1021 | 1021 | |
1022 | 1022 | //set timezone in field object |
1023 | - $field->set_timezone( $this->_timezone ); |
|
1023 | + $field->set_timezone($this->_timezone); |
|
1024 | 1024 | |
1025 | 1025 | //set the output returned |
1026 | - switch ( $date_or_time ) { |
|
1026 | + switch ($date_or_time) { |
|
1027 | 1027 | |
1028 | 1028 | case 'D' : |
1029 | 1029 | $field->set_date_time_output('date'); |
@@ -1038,11 +1038,11 @@ discard block |
||
1038 | 1038 | } |
1039 | 1039 | |
1040 | 1040 | |
1041 | - if ( $echo ) { |
|
1042 | - $this->e( $field_name, $date_or_time ); |
|
1041 | + if ($echo) { |
|
1042 | + $this->e($field_name, $date_or_time); |
|
1043 | 1043 | return ''; |
1044 | 1044 | } |
1045 | - return $this->get( $field_name, $date_or_time ); |
|
1045 | + return $this->get($field_name, $date_or_time); |
|
1046 | 1046 | } |
1047 | 1047 | |
1048 | 1048 | |
@@ -1052,8 +1052,8 @@ discard block |
||
1052 | 1052 | * @param string $format format for the date returned (if NULL we use default in dt_frmt property) |
1053 | 1053 | * @return string datetime value formatted |
1054 | 1054 | */ |
1055 | - public function get_date( $field_name, $format = NULL ) { |
|
1056 | - return $this->_get_datetime( $field_name, $format, NULL, 'D' ); |
|
1055 | + public function get_date($field_name, $format = NULL) { |
|
1056 | + return $this->_get_datetime($field_name, $format, NULL, 'D'); |
|
1057 | 1057 | } |
1058 | 1058 | |
1059 | 1059 | |
@@ -1062,8 +1062,8 @@ discard block |
||
1062 | 1062 | * @param $field_name |
1063 | 1063 | * @param null $format |
1064 | 1064 | */ |
1065 | - public function e_date( $field_name, $format = NULL ) { |
|
1066 | - $this->_get_datetime( $field_name, $format, NULL, 'D', TRUE ); |
|
1065 | + public function e_date($field_name, $format = NULL) { |
|
1066 | + $this->_get_datetime($field_name, $format, NULL, 'D', TRUE); |
|
1067 | 1067 | } |
1068 | 1068 | |
1069 | 1069 | |
@@ -1073,8 +1073,8 @@ discard block |
||
1073 | 1073 | * @param string $format format for the time returned ( if NULL we use default in tm_frmt property) |
1074 | 1074 | * @return string datetime value formatted |
1075 | 1075 | */ |
1076 | - public function get_time( $field_name, $format = NULL ) { |
|
1077 | - return $this->_get_datetime( $field_name, NULL, $format, 'T' ); |
|
1076 | + public function get_time($field_name, $format = NULL) { |
|
1077 | + return $this->_get_datetime($field_name, NULL, $format, 'T'); |
|
1078 | 1078 | } |
1079 | 1079 | |
1080 | 1080 | |
@@ -1083,8 +1083,8 @@ discard block |
||
1083 | 1083 | * @param $field_name |
1084 | 1084 | * @param null $format |
1085 | 1085 | */ |
1086 | - public function e_time( $field_name, $format = NULL ) { |
|
1087 | - $this->_get_datetime( $field_name, NULL, $format, 'T', TRUE ); |
|
1086 | + public function e_time($field_name, $format = NULL) { |
|
1087 | + $this->_get_datetime($field_name, NULL, $format, 'T', TRUE); |
|
1088 | 1088 | } |
1089 | 1089 | |
1090 | 1090 | |
@@ -1097,8 +1097,8 @@ discard block |
||
1097 | 1097 | * @param string $tm_frmt format for the time returned (if NULL we use default in tm_frmt property) |
1098 | 1098 | * @return string datetime value formatted |
1099 | 1099 | */ |
1100 | - public function get_datetime( $field_name, $dt_frmt = NULL, $tm_frmt = NULL ) { |
|
1101 | - return $this->_get_datetime( $field_name, $dt_frmt, $tm_frmt ); |
|
1100 | + public function get_datetime($field_name, $dt_frmt = NULL, $tm_frmt = NULL) { |
|
1101 | + return $this->_get_datetime($field_name, $dt_frmt, $tm_frmt); |
|
1102 | 1102 | } |
1103 | 1103 | |
1104 | 1104 | |
@@ -1108,8 +1108,8 @@ discard block |
||
1108 | 1108 | * @param null $dt_frmt |
1109 | 1109 | * @param null $tm_frmt |
1110 | 1110 | */ |
1111 | - public function e_datetime( $field_name, $dt_frmt = NULL, $tm_frmt = NULL ) { |
|
1112 | - $this->_get_datetime( $field_name, $dt_frmt, $tm_frmt, NULL, TRUE); |
|
1111 | + public function e_datetime($field_name, $dt_frmt = NULL, $tm_frmt = NULL) { |
|
1112 | + $this->_get_datetime($field_name, $dt_frmt, $tm_frmt, NULL, TRUE); |
|
1113 | 1113 | } |
1114 | 1114 | |
1115 | 1115 | |
@@ -1124,10 +1124,10 @@ discard block |
||
1124 | 1124 | * @return string Date and time string in set locale or false if no field exists for the given |
1125 | 1125 | * field name. |
1126 | 1126 | */ |
1127 | - public function get_i18n_datetime( $field_name, $format = NULL ) { |
|
1128 | - EE_Registry::instance()->load_helper( 'DTT_Helper' ); |
|
1129 | - $format = empty( $format ) ? $this->_dt_frmt . ' ' . $this->_tm_frmt : $format; |
|
1130 | - return date_i18n( $format, EEH_DTT_Helper::get_timestamp_with_offset( $this->get_raw( $field_name ), $this->_timezone ) ); |
|
1127 | + public function get_i18n_datetime($field_name, $format = NULL) { |
|
1128 | + EE_Registry::instance()->load_helper('DTT_Helper'); |
|
1129 | + $format = empty($format) ? $this->_dt_frmt.' '.$this->_tm_frmt : $format; |
|
1130 | + return date_i18n($format, EEH_DTT_Helper::get_timestamp_with_offset($this->get_raw($field_name), $this->_timezone)); |
|
1131 | 1131 | } |
1132 | 1132 | |
1133 | 1133 | |
@@ -1139,14 +1139,14 @@ discard block |
||
1139 | 1139 | * @throws EE_Error |
1140 | 1140 | * @return EE_Datetime_Field |
1141 | 1141 | */ |
1142 | - protected function _get_dtt_field_settings( $field_name ) { |
|
1142 | + protected function _get_dtt_field_settings($field_name) { |
|
1143 | 1143 | $field = $this->get_model()->field_settings_for($field_name); |
1144 | 1144 | |
1145 | 1145 | //check if field is dtt |
1146 | - if ( $field instanceof EE_Datetime_Field ) { |
|
1146 | + if ($field instanceof EE_Datetime_Field) { |
|
1147 | 1147 | return $field; |
1148 | 1148 | } else { |
1149 | - throw new EE_Error( sprintf( __('The field name "%s" has been requested for the EE_Base_Class datetime functions and it is not a valid EE_Datetime_Field. Please check the spelling of the field and make sure it has been setup as a EE_Datetime_Field in the %s model constructor', 'event_espresso'), $field_name, self::_get_model_classname( get_class($this) ) ) ); |
|
1149 | + throw new EE_Error(sprintf(__('The field name "%s" has been requested for the EE_Base_Class datetime functions and it is not a valid EE_Datetime_Field. Please check the spelling of the field and make sure it has been setup as a EE_Datetime_Field in the %s model constructor', 'event_espresso'), $field_name, self::_get_model_classname(get_class($this)))); |
|
1150 | 1150 | } |
1151 | 1151 | } |
1152 | 1152 | |
@@ -1167,8 +1167,8 @@ discard block |
||
1167 | 1167 | * @param string|Datetime $time a valid time string for php datetime functions (or DateTime object) |
1168 | 1168 | * @param string $fieldname the name of the field the time is being set on (must match a EE_Datetime_Field) |
1169 | 1169 | */ |
1170 | - protected function _set_time_for( $time, $fieldname ) { |
|
1171 | - $this->_set_date_time( 'T', $time, $fieldname ); |
|
1170 | + protected function _set_time_for($time, $fieldname) { |
|
1171 | + $this->_set_date_time('T', $time, $fieldname); |
|
1172 | 1172 | } |
1173 | 1173 | |
1174 | 1174 | |
@@ -1182,8 +1182,8 @@ discard block |
||
1182 | 1182 | * @param string|DateTime $date a valid date string for php datetime functions ( or DateTime object) |
1183 | 1183 | * @param string $fieldname the name of the field the date is being set on (must match a EE_Datetime_Field) |
1184 | 1184 | */ |
1185 | - protected function _set_date_for( $date, $fieldname ) { |
|
1186 | - $this->_set_date_time( 'D', $date, $fieldname ); |
|
1185 | + protected function _set_date_for($date, $fieldname) { |
|
1186 | + $this->_set_date_time('D', $date, $fieldname); |
|
1187 | 1187 | } |
1188 | 1188 | |
1189 | 1189 | |
@@ -1199,21 +1199,21 @@ discard block |
||
1199 | 1199 | * @param string|DateTime $datetime_value A valid Date or Time string (or DateTime object) |
1200 | 1200 | * @param string $fieldname the name of the field the date OR time is being set on (must match a EE_Datetime_Field property) |
1201 | 1201 | */ |
1202 | - protected function _set_date_time( $what = 'T', $datetime_value, $fieldname ) { |
|
1203 | - $field = $this->_get_dtt_field_settings( $fieldname ); |
|
1204 | - $field->set_timezone( $this->_timezone ); |
|
1205 | - $field->set_date_format( $this->_dt_frmt ); |
|
1206 | - $field->set_time_format( $this->_tm_frmt ); |
|
1202 | + protected function _set_date_time($what = 'T', $datetime_value, $fieldname) { |
|
1203 | + $field = $this->_get_dtt_field_settings($fieldname); |
|
1204 | + $field->set_timezone($this->_timezone); |
|
1205 | + $field->set_date_format($this->_dt_frmt); |
|
1206 | + $field->set_time_format($this->_tm_frmt); |
|
1207 | 1207 | |
1208 | - switch ( $what ) { |
|
1208 | + switch ($what) { |
|
1209 | 1209 | case 'T' : |
1210 | - $this->_fields[$fieldname] = $field->prepare_for_set_with_new_time( $datetime_value, $this->_fields[$fieldname] ); |
|
1210 | + $this->_fields[$fieldname] = $field->prepare_for_set_with_new_time($datetime_value, $this->_fields[$fieldname]); |
|
1211 | 1211 | break; |
1212 | 1212 | case 'D' : |
1213 | - $this->_fields[$fieldname] = $field->prepare_for_set_with_new_date( $datetime_value, $this->_fields[$fieldname] ); |
|
1213 | + $this->_fields[$fieldname] = $field->prepare_for_set_with_new_date($datetime_value, $this->_fields[$fieldname]); |
|
1214 | 1214 | break; |
1215 | 1215 | case 'B' : |
1216 | - $this->_fields[$fieldname] = $field->prepare_for_set( $datetime_value ); |
|
1216 | + $this->_fields[$fieldname] = $field->prepare_for_set($datetime_value); |
|
1217 | 1217 | break; |
1218 | 1218 | } |
1219 | 1219 | |
@@ -1236,25 +1236,25 @@ discard block |
||
1236 | 1236 | * @throws EE_Error |
1237 | 1237 | * @return string timestamp |
1238 | 1238 | */ |
1239 | - public function display_in_my_timezone( $field_name, $callback = 'get_datetime', $args = NULL, $prepend = '', $append = '' ) { |
|
1239 | + public function display_in_my_timezone($field_name, $callback = 'get_datetime', $args = NULL, $prepend = '', $append = '') { |
|
1240 | 1240 | EE_Registry::instance()->load_helper('DTT_Helper'); |
1241 | 1241 | $timezone = EEH_DTT_Helper::get_timezone(); |
1242 | 1242 | |
1243 | - if ( $timezone == $this->_timezone ) |
|
1243 | + if ($timezone == $this->_timezone) |
|
1244 | 1244 | return ''; |
1245 | 1245 | |
1246 | 1246 | $original_timezone = $this->_timezone; |
1247 | - $this->set_timezone( $timezone ); |
|
1247 | + $this->set_timezone($timezone); |
|
1248 | 1248 | |
1249 | 1249 | $fn = (array) $field_name; |
1250 | - $args = array_merge( $fn, (array) $args ); |
|
1250 | + $args = array_merge($fn, (array) $args); |
|
1251 | 1251 | |
1252 | - if ( !method_exists( $this, $callback ) ) |
|
1253 | - throw new EE_Error(sprintf( __('The method named "%s" given as the callback param in "display_in_my_timezone" does not exist. Please check your spelling', 'event_espresso'), $callback ) ); |
|
1252 | + if ( ! method_exists($this, $callback)) |
|
1253 | + throw new EE_Error(sprintf(__('The method named "%s" given as the callback param in "display_in_my_timezone" does not exist. Please check your spelling', 'event_espresso'), $callback)); |
|
1254 | 1254 | $args = (array) $args; |
1255 | - $return = $prepend . call_user_func_array( array( $this, $callback ), $args ) . $append; |
|
1255 | + $return = $prepend.call_user_func_array(array($this, $callback), $args).$append; |
|
1256 | 1256 | |
1257 | - $this->set_timezone( $original_timezone ); |
|
1257 | + $this->set_timezone($original_timezone); |
|
1258 | 1258 | return $return; |
1259 | 1259 | } |
1260 | 1260 | |
@@ -1265,15 +1265,15 @@ discard block |
||
1265 | 1265 | * Deletes this model object. That may mean just 'soft deleting' it though. |
1266 | 1266 | * @return boolean | int |
1267 | 1267 | */ |
1268 | - public function delete(){ |
|
1268 | + public function delete() { |
|
1269 | 1269 | /** |
1270 | 1270 | * Called just before SOFT deleting a model object (if soft deleting is |
1271 | 1271 | * possible for this model; otherwise a regular hard delete it performed) |
1272 | 1272 | * |
1273 | 1273 | * @param EE_Base_Class $model_object about to be 'deleted' |
1274 | 1274 | */ |
1275 | - do_action( 'AHEE__EE_Base_Class__delete__before', $this ); |
|
1276 | - $result = $this->get_model()->delete_by_ID( $this->ID() ); |
|
1275 | + do_action('AHEE__EE_Base_Class__delete__before', $this); |
|
1276 | + $result = $this->get_model()->delete_by_ID($this->ID()); |
|
1277 | 1277 | $this->refresh_cache_of_related_objects(); |
1278 | 1278 | /** |
1279 | 1279 | * Called just after SOFT deleting a model object (if soft deleting is |
@@ -1281,7 +1281,7 @@ discard block |
||
1281 | 1281 | * @param EE_Base_Class $model_object that was just 'deleted' |
1282 | 1282 | * @param boolean $result |
1283 | 1283 | */ |
1284 | - do_action( 'AHEE__EE_Base_Class__delete__end', $this, $result ); |
|
1284 | + do_action('AHEE__EE_Base_Class__delete__end', $this, $result); |
|
1285 | 1285 | return $result; |
1286 | 1286 | } |
1287 | 1287 | |
@@ -1291,22 +1291,22 @@ discard block |
||
1291 | 1291 | * Deletes this model object permanently from db (but keep in mind related models my block the delete and return an error) |
1292 | 1292 | * @return bool |
1293 | 1293 | */ |
1294 | - public function delete_permanently(){ |
|
1294 | + public function delete_permanently() { |
|
1295 | 1295 | /** |
1296 | 1296 | * Called just before HARD deleting a model object |
1297 | 1297 | * |
1298 | 1298 | * @param EE_Base_Class $model_object about to be 'deleted' |
1299 | 1299 | */ |
1300 | - do_action( 'AHEE__EE_Base_Class__delete_permanently__before', $this ); |
|
1301 | - $model=$this->get_model(); |
|
1302 | - $result=$model->delete_permanently_by_ID($this->ID()); |
|
1300 | + do_action('AHEE__EE_Base_Class__delete_permanently__before', $this); |
|
1301 | + $model = $this->get_model(); |
|
1302 | + $result = $model->delete_permanently_by_ID($this->ID()); |
|
1303 | 1303 | $this->refresh_cache_of_related_objects(); |
1304 | 1304 | /** |
1305 | 1305 | * Called just after HARD deleting a model object |
1306 | 1306 | * @param EE_Base_Class $model_object that was just 'deleted' |
1307 | 1307 | * @param boolean $result |
1308 | 1308 | */ |
1309 | - do_action( 'AHEE__EE_Base_Class__delete_permanently__end', $this, $result ); |
|
1309 | + do_action('AHEE__EE_Base_Class__delete_permanently__end', $this, $result); |
|
1310 | 1310 | return $result ? true : false; |
1311 | 1311 | } |
1312 | 1312 | |
@@ -1315,18 +1315,18 @@ discard block |
||
1315 | 1315 | * related model objects |
1316 | 1316 | */ |
1317 | 1317 | public function refresh_cache_of_related_objects() { |
1318 | - foreach( $this->get_model()->relation_settings() as $relation_name => $relation_obj ) { |
|
1319 | - if( ! empty( $this->_model_relations[ $relation_name ] ) ) { |
|
1320 | - $related_objects = $this->_model_relations[ $relation_name ]; |
|
1321 | - if( $relation_obj instanceof EE_Belongs_To_Relation ) { |
|
1318 | + foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
1319 | + if ( ! empty($this->_model_relations[$relation_name])) { |
|
1320 | + $related_objects = $this->_model_relations[$relation_name]; |
|
1321 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
1322 | 1322 | //this relation only stores a single model object, not an array |
1323 | 1323 | //but let's make it consistent |
1324 | - $related_objects = array( $related_objects ); |
|
1324 | + $related_objects = array($related_objects); |
|
1325 | 1325 | } |
1326 | - foreach( $related_objects as $related_object ) { |
|
1326 | + foreach ($related_objects as $related_object) { |
|
1327 | 1327 | //only refresh their cache if they're in memory |
1328 | - if( $related_object instanceof EE_Base_Class ) { |
|
1329 | - $related_object->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
1328 | + if ($related_object instanceof EE_Base_Class) { |
|
1329 | + $related_object->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
1330 | 1330 | } |
1331 | 1331 | } |
1332 | 1332 | } |
@@ -1346,17 +1346,17 @@ discard block |
||
1346 | 1346 | * @return int , 1 on a successful update, the ID of the new entry on insert; 0 on failure or if the model object |
1347 | 1347 | * isn't allowed to persist (as determined by EE_Base_Class::allow_persist()) |
1348 | 1348 | */ |
1349 | - public function save($set_cols_n_values=array()) { |
|
1349 | + public function save($set_cols_n_values = array()) { |
|
1350 | 1350 | /** |
1351 | 1351 | * Filters the fields we're about to save on the model object |
1352 | 1352 | * |
1353 | 1353 | * @param array $set_cols_n_values |
1354 | 1354 | * @param EE_Base_Class $model_object |
1355 | 1355 | */ |
1356 | - $set_cols_n_values = apply_filters( 'FHEE__EE_Base_Class__save__set_cols_n_values', $set_cols_n_values, $this ); |
|
1356 | + $set_cols_n_values = apply_filters('FHEE__EE_Base_Class__save__set_cols_n_values', $set_cols_n_values, $this); |
|
1357 | 1357 | //set attributes as provided in $set_cols_n_values |
1358 | - foreach($set_cols_n_values as $column=>$value){ |
|
1359 | - $this->set($column,$value); |
|
1358 | + foreach ($set_cols_n_values as $column=>$value) { |
|
1359 | + $this->set($column, $value); |
|
1360 | 1360 | } |
1361 | 1361 | /** |
1362 | 1362 | * Saving a model object. |
@@ -1364,8 +1364,8 @@ discard block |
||
1364 | 1364 | * Before we perform a save, this action is fired. |
1365 | 1365 | * @param EE_Base_Class $model_object the model object about to be saved. |
1366 | 1366 | */ |
1367 | - do_action( 'AHEE__EE_Base_Class__save__begin', $this ); |
|
1368 | - if( ! $this->allow_persist() ) { |
|
1367 | + do_action('AHEE__EE_Base_Class__save__begin', $this); |
|
1368 | + if ( ! $this->allow_persist()) { |
|
1369 | 1369 | return 0; |
1370 | 1370 | } |
1371 | 1371 | //now get current attribute values |
@@ -1375,61 +1375,61 @@ discard block |
||
1375 | 1375 | $old_assumption_concerning_value_preparation = $this->get_model()->get_assumption_concerning_values_already_prepared_by_model_object(); |
1376 | 1376 | $this->get_model()->assume_values_already_prepared_by_model_object(true); |
1377 | 1377 | //does this model have an autoincrement PK? |
1378 | - if($this->get_model()->has_primary_key_field()){ |
|
1379 | - if($this->get_model()->get_primary_key_field()->is_auto_increment()){ |
|
1378 | + if ($this->get_model()->has_primary_key_field()) { |
|
1379 | + if ($this->get_model()->get_primary_key_field()->is_auto_increment()) { |
|
1380 | 1380 | //ok check if it's set, if so: update; if not, insert |
1381 | - if ( ! empty( $save_cols_n_values[self::_get_primary_key_name( get_class($this) )] ) ){ |
|
1382 | - $results = $this->get_model()->update_by_ID ( $save_cols_n_values, $this->ID() ); |
|
1381 | + if ( ! empty($save_cols_n_values[self::_get_primary_key_name(get_class($this))])) { |
|
1382 | + $results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID()); |
|
1383 | 1383 | } else { |
1384 | - unset($save_cols_n_values[self::_get_primary_key_name( get_class( $this) )]); |
|
1385 | - $results = $this->get_model()->insert( $save_cols_n_values, true); |
|
1386 | - if($results){ |
|
1384 | + unset($save_cols_n_values[self::_get_primary_key_name(get_class($this))]); |
|
1385 | + $results = $this->get_model()->insert($save_cols_n_values, true); |
|
1386 | + if ($results) { |
|
1387 | 1387 | //if successful, set the primary key |
1388 | 1388 | //but don't use the normal SET method, because it will check if |
1389 | 1389 | //an item with the same ID exists in the mapper & db, then |
1390 | 1390 | //will find it in the db (because we just added it) and THAT object |
1391 | 1391 | //will get added to the mapper before we can add this one! |
1392 | 1392 | //but if we just avoid using the SET method, all that headache can be avoided |
1393 | - $pk_field_name =self::_get_primary_key_name( get_class($this)); |
|
1393 | + $pk_field_name = self::_get_primary_key_name(get_class($this)); |
|
1394 | 1394 | $this->_fields[$pk_field_name] = $results; |
1395 | 1395 | $this->_clear_cached_property($pk_field_name); |
1396 | - $this->get_model()->add_to_entity_map( $this ); |
|
1396 | + $this->get_model()->add_to_entity_map($this); |
|
1397 | 1397 | $this->_update_cached_related_model_objs_fks(); |
1398 | 1398 | } |
1399 | 1399 | } |
1400 | - }else{//PK is NOT auto-increment |
|
1400 | + } else {//PK is NOT auto-increment |
|
1401 | 1401 | //so check if one like it already exists in the db |
1402 | - if( $this->get_model()->exists_by_ID( $this->ID() ) ){ |
|
1403 | - if( ! $this->in_entity_map() && WP_DEBUG ){ |
|
1402 | + if ($this->get_model()->exists_by_ID($this->ID())) { |
|
1403 | + if ( ! $this->in_entity_map() && WP_DEBUG) { |
|
1404 | 1404 | throw new EE_Error( |
1405 | 1405 | sprintf( |
1406 | - __( 'Using a model object %1$s that is NOT in the entity map, can lead to unexpected errors. You should either: %4$s 1. Put it in the entity mapper by calling %2$s %4$s 2. Discard this model object and use what is in the entity mapper %4$s 3. Fetch from the database using %3$s', 'event_espresso' ), |
|
1406 | + __('Using a model object %1$s that is NOT in the entity map, can lead to unexpected errors. You should either: %4$s 1. Put it in the entity mapper by calling %2$s %4$s 2. Discard this model object and use what is in the entity mapper %4$s 3. Fetch from the database using %3$s', 'event_espresso'), |
|
1407 | 1407 | get_class($this), |
1408 | - get_class( $this->get_model() ) . '::instance()->add_to_entity_map()', |
|
1409 | - get_class( $this->get_model() ) . '::instance()->get_one_by_ID()', |
|
1408 | + get_class($this->get_model()).'::instance()->add_to_entity_map()', |
|
1409 | + get_class($this->get_model()).'::instance()->get_one_by_ID()', |
|
1410 | 1410 | '<br />' |
1411 | 1411 | ) |
1412 | 1412 | ); |
1413 | 1413 | } |
1414 | 1414 | $results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID()); |
1415 | - }else{ |
|
1415 | + } else { |
|
1416 | 1416 | $results = $this->get_model()->insert($save_cols_n_values); |
1417 | 1417 | $this->_update_cached_related_model_objs_fks(); |
1418 | 1418 | } |
1419 | 1419 | } |
1420 | - }else{//there is NO primary key |
|
1420 | + } else {//there is NO primary key |
|
1421 | 1421 | $already_in_db = false; |
1422 | - foreach($this->get_model()->unique_indexes() as $index){ |
|
1422 | + foreach ($this->get_model()->unique_indexes() as $index) { |
|
1423 | 1423 | $uniqueness_where_params = array_intersect_key($save_cols_n_values, $index->fields()); |
1424 | - if($this->get_model()->exists(array($uniqueness_where_params))){ |
|
1424 | + if ($this->get_model()->exists(array($uniqueness_where_params))) { |
|
1425 | 1425 | $already_in_db = true; |
1426 | 1426 | } |
1427 | 1427 | } |
1428 | - if( $already_in_db ){ |
|
1429 | - $combined_pk_fields_n_values = array_intersect_key( $save_cols_n_values, $this->get_model()->get_combined_primary_key_fields() ); |
|
1430 | - $results = $this->get_model()->update( $save_cols_n_values,$combined_pk_fields_n_values ); |
|
1431 | - }else{ |
|
1432 | - $results = $this->get_model()->insert( $save_cols_n_values ); |
|
1428 | + if ($already_in_db) { |
|
1429 | + $combined_pk_fields_n_values = array_intersect_key($save_cols_n_values, $this->get_model()->get_combined_primary_key_fields()); |
|
1430 | + $results = $this->get_model()->update($save_cols_n_values, $combined_pk_fields_n_values); |
|
1431 | + } else { |
|
1432 | + $results = $this->get_model()->insert($save_cols_n_values); |
|
1433 | 1433 | } |
1434 | 1434 | } |
1435 | 1435 | //restore the old assumption about values being prepared by the model object |
@@ -1442,7 +1442,7 @@ discard block |
||
1442 | 1442 | * @param boolean|int $results if it were updated, TRUE or FALSE; if it were newly inserted |
1443 | 1443 | * the new ID (or 0 if an error occurred and it wasn't updated) |
1444 | 1444 | */ |
1445 | - do_action( 'AHEE__EE_Base_Class__save__end', $this, $results ); |
|
1445 | + do_action('AHEE__EE_Base_Class__save__end', $this, $results); |
|
1446 | 1446 | return $results; |
1447 | 1447 | } |
1448 | 1448 | |
@@ -1454,13 +1454,13 @@ discard block |
||
1454 | 1454 | * and we want to let its cached relations with foreign keys to it know about that change. Eg: we've created a transaction but haven't saved it to the db. We also create a registration and don't save it to the DB, but we DO cache it on the transaction. Now, when we save the transaction, the registration's TXN_ID will be automatically updated, whether or not they exist in the DB (if they do, their DB records will be automatically updated) |
1455 | 1455 | * @return void |
1456 | 1456 | */ |
1457 | - protected function _update_cached_related_model_objs_fks(){ |
|
1458 | - foreach( $this->get_model()->relation_settings() as $relation_name => $relation_obj ){ |
|
1459 | - if( $relation_obj instanceof EE_Has_Many_Relation ){ |
|
1460 | - foreach( $this->get_all_from_cache( $relation_name ) as $related_model_obj_in_cache) { |
|
1461 | - $fk_to_this = $related_model_obj_in_cache->get_model()->get_foreign_key_to( $this->get_model()->get_this_model_name() ); |
|
1462 | - $related_model_obj_in_cache->set($fk_to_this->get_name(), $this->ID() ); |
|
1463 | - if( $related_model_obj_in_cache->ID() ){ |
|
1457 | + protected function _update_cached_related_model_objs_fks() { |
|
1458 | + foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
1459 | + if ($relation_obj instanceof EE_Has_Many_Relation) { |
|
1460 | + foreach ($this->get_all_from_cache($relation_name) as $related_model_obj_in_cache) { |
|
1461 | + $fk_to_this = $related_model_obj_in_cache->get_model()->get_foreign_key_to($this->get_model()->get_this_model_name()); |
|
1462 | + $related_model_obj_in_cache->set($fk_to_this->get_name(), $this->ID()); |
|
1463 | + if ($related_model_obj_in_cache->ID()) { |
|
1464 | 1464 | $related_model_obj_in_cache->save(); |
1465 | 1465 | } |
1466 | 1466 | } |
@@ -1476,21 +1476,21 @@ discard block |
||
1476 | 1476 | * and this object and properly setup |
1477 | 1477 | * @return int ID of new model object on save; 0 on failure+ |
1478 | 1478 | */ |
1479 | - public function save_new_cached_related_model_objs(){ |
|
1479 | + public function save_new_cached_related_model_objs() { |
|
1480 | 1480 | //make sure this has been saved |
1481 | - if( ! $this->ID()){ |
|
1481 | + if ( ! $this->ID()) { |
|
1482 | 1482 | $id = $this->save(); |
1483 | - }else{ |
|
1483 | + } else { |
|
1484 | 1484 | $id = $this->ID(); |
1485 | 1485 | } |
1486 | 1486 | //now save all the NEW cached model objects (ie they don't exist in the DB) |
1487 | - foreach($this->get_model()->relation_settings() as $relationName => $relationObj){ |
|
1487 | + foreach ($this->get_model()->relation_settings() as $relationName => $relationObj) { |
|
1488 | 1488 | |
1489 | 1489 | |
1490 | - if($this->_model_relations[$relationName]){ |
|
1490 | + if ($this->_model_relations[$relationName]) { |
|
1491 | 1491 | //is this a relation where we should expect just ONE related object (ie, EE_Belongs_To_relation) |
1492 | 1492 | //or MANY related objects (ie, EE_HABTM_Relation or EE_Has_Many_Relation)? |
1493 | - if($relationObj instanceof EE_Belongs_To_Relation){ |
|
1493 | + if ($relationObj instanceof EE_Belongs_To_Relation) { |
|
1494 | 1494 | //add a relation to that relation type (which saves the appropriate thing in the process) |
1495 | 1495 | //but ONLY if it DOES NOT exist in the DB |
1496 | 1496 | /* @var $related_model_obj EE_Base_Class */ |
@@ -1499,8 +1499,8 @@ discard block |
||
1499 | 1499 | $this->_add_relation_to($related_model_obj, $relationName); |
1500 | 1500 | $related_model_obj->save_new_cached_related_model_objs(); |
1501 | 1501 | // } |
1502 | - }else{ |
|
1503 | - foreach($this->_model_relations[$relationName] as $related_model_obj){ |
|
1502 | + } else { |
|
1503 | + foreach ($this->_model_relations[$relationName] as $related_model_obj) { |
|
1504 | 1504 | //add a relation to that relation type (which saves the appropriate thing in the process) |
1505 | 1505 | //but ONLY if it DOES NOT exist in the DB |
1506 | 1506 | // if( ! $related_model_obj->ID()){ |
@@ -1521,8 +1521,8 @@ discard block |
||
1521 | 1521 | * @return \EEM_Base | \EEM_CPT_Base |
1522 | 1522 | */ |
1523 | 1523 | public function get_model() { |
1524 | - $modelName = self::_get_model_classname( get_class($this) ); |
|
1525 | - return self::_get_model_instance_with_name($modelName, $this->_timezone ); |
|
1524 | + $modelName = self::_get_model_classname(get_class($this)); |
|
1525 | + return self::_get_model_instance_with_name($modelName, $this->_timezone); |
|
1526 | 1526 | } |
1527 | 1527 | |
1528 | 1528 | |
@@ -1532,10 +1532,10 @@ discard block |
||
1532 | 1532 | * @param $classname |
1533 | 1533 | * @return mixed bool|EE_Base_Class|EEM_CPT_Base |
1534 | 1534 | */ |
1535 | - protected static function _get_object_from_entity_mapper($props_n_values, $classname){ |
|
1535 | + protected static function _get_object_from_entity_mapper($props_n_values, $classname) { |
|
1536 | 1536 | //TODO: will not work for Term_Relationships because they have no PK! |
1537 | - $primary_id_ref = self::_get_primary_key_name( $classname ); |
|
1538 | - if ( array_key_exists( $primary_id_ref, $props_n_values ) && !empty( $props_n_values[$primary_id_ref] ) ) { |
|
1537 | + $primary_id_ref = self::_get_primary_key_name($classname); |
|
1538 | + if (array_key_exists($primary_id_ref, $props_n_values) && ! empty($props_n_values[$primary_id_ref])) { |
|
1539 | 1539 | $id = $props_n_values[$primary_id_ref]; |
1540 | 1540 | return self::_get_model($classname)->get_from_entity_map($id); |
1541 | 1541 | } |
@@ -1552,24 +1552,24 @@ discard block |
||
1552 | 1552 | * @param null $timezone |
1553 | 1553 | * @return mixed (EE_Base_Class|bool) |
1554 | 1554 | */ |
1555 | - protected static function _check_for_object( $props_n_values, $classname, $timezone = NULL ) { |
|
1556 | - if( self::_get_model( $classname )->has_primary_key_field()){ |
|
1557 | - $primary_id_ref = self::_get_primary_key_name( $classname ); |
|
1555 | + protected static function _check_for_object($props_n_values, $classname, $timezone = NULL) { |
|
1556 | + if (self::_get_model($classname)->has_primary_key_field()) { |
|
1557 | + $primary_id_ref = self::_get_primary_key_name($classname); |
|
1558 | 1558 | |
1559 | - if ( array_key_exists( $primary_id_ref, $props_n_values ) && !empty( $props_n_values[$primary_id_ref] ) ) { |
|
1560 | - $existing = self::_get_model( $classname, $timezone )->get_one_by_ID( $props_n_values[$primary_id_ref] ); |
|
1561 | - }else{ |
|
1559 | + if (array_key_exists($primary_id_ref, $props_n_values) && ! empty($props_n_values[$primary_id_ref])) { |
|
1560 | + $existing = self::_get_model($classname, $timezone)->get_one_by_ID($props_n_values[$primary_id_ref]); |
|
1561 | + } else { |
|
1562 | 1562 | $existing = null; |
1563 | 1563 | } |
1564 | - }elseif( self::_get_model( $classname, $timezone )->has_all_combined_primary_key_fields( $props_n_values ) ){ |
|
1564 | + }elseif (self::_get_model($classname, $timezone)->has_all_combined_primary_key_fields($props_n_values)) { |
|
1565 | 1565 | //no primary key on this model, but there's still a matching item in the DB |
1566 | - $existing = self::_get_model($classname, $timezone)->get_one_by_ID( self::_get_model($classname, $timezone)->get_index_primary_key_string( $props_n_values ) ); |
|
1567 | - }else{ |
|
1566 | + $existing = self::_get_model($classname, $timezone)->get_one_by_ID(self::_get_model($classname, $timezone)->get_index_primary_key_string($props_n_values)); |
|
1567 | + } else { |
|
1568 | 1568 | $existing = null; |
1569 | 1569 | } |
1570 | - if ( $existing ) { |
|
1571 | - foreach ( $props_n_values as $property => $field_value ) { |
|
1572 | - $existing->set( $property, $field_value ); |
|
1570 | + if ($existing) { |
|
1571 | + foreach ($props_n_values as $property => $field_value) { |
|
1572 | + $existing->set($property, $field_value); |
|
1573 | 1573 | } |
1574 | 1574 | return $existing; |
1575 | 1575 | } else { |
@@ -1587,13 +1587,13 @@ discard block |
||
1587 | 1587 | * @throws EE_Error |
1588 | 1588 | * @return EEM_Base |
1589 | 1589 | */ |
1590 | - protected static function _get_model( $classname, $timezone = NULL ){ |
|
1590 | + protected static function _get_model($classname, $timezone = NULL) { |
|
1591 | 1591 | //find model for this class |
1592 | - if( ! $classname ){ |
|
1593 | - throw new EE_Error(sprintf(__("What were you thinking calling _get_model(%s)?? You need to specify the class name", "event_espresso"),$classname)); |
|
1592 | + if ( ! $classname) { |
|
1593 | + throw new EE_Error(sprintf(__("What were you thinking calling _get_model(%s)?? You need to specify the class name", "event_espresso"), $classname)); |
|
1594 | 1594 | } |
1595 | - $modelName=self::_get_model_classname($classname); |
|
1596 | - return self::_get_model_instance_with_name($modelName, $timezone ); |
|
1595 | + $modelName = self::_get_model_classname($classname); |
|
1596 | + return self::_get_model_instance_with_name($modelName, $timezone); |
|
1597 | 1597 | } |
1598 | 1598 | |
1599 | 1599 | |
@@ -1604,10 +1604,10 @@ discard block |
||
1604 | 1604 | * @param null $timezone |
1605 | 1605 | * @return EEM_Base |
1606 | 1606 | */ |
1607 | - protected static function _get_model_instance_with_name($model_classname, $timezone = NULL){ |
|
1608 | - $model_classname = str_replace( 'EEM_', '', $model_classname ); |
|
1609 | - $model = EE_Registry::instance()->load_model( $model_classname ); |
|
1610 | - $model->set_timezone( $timezone ); |
|
1607 | + protected static function _get_model_instance_with_name($model_classname, $timezone = NULL) { |
|
1608 | + $model_classname = str_replace('EEM_', '', $model_classname); |
|
1609 | + $model = EE_Registry::instance()->load_model($model_classname); |
|
1610 | + $model->set_timezone($timezone); |
|
1611 | 1611 | return $model; |
1612 | 1612 | } |
1613 | 1613 | |
@@ -1619,10 +1619,10 @@ discard block |
||
1619 | 1619 | * @param null $model_name |
1620 | 1620 | * @return string like EEM_Attendee |
1621 | 1621 | */ |
1622 | - private static function _get_model_classname( $model_name = null){ |
|
1623 | - if(strpos($model_name,"EE_")===0){ |
|
1624 | - $model_classname=str_replace("EE_","EEM_",$model_name); |
|
1625 | - }else{ |
|
1622 | + private static function _get_model_classname($model_name = null) { |
|
1623 | + if (strpos($model_name, "EE_") === 0) { |
|
1624 | + $model_classname = str_replace("EE_", "EEM_", $model_name); |
|
1625 | + } else { |
|
1626 | 1626 | $model_classname = "EEM_".$model_name; |
1627 | 1627 | } |
1628 | 1628 | return $model_classname; |
@@ -1636,11 +1636,11 @@ discard block |
||
1636 | 1636 | * @throws EE_Error |
1637 | 1637 | * @return string |
1638 | 1638 | */ |
1639 | - protected static function _get_primary_key_name( $classname = NULL ){ |
|
1640 | - if( ! $classname){ |
|
1641 | - throw new EE_Error(sprintf(__("What were you thinking calling _get_primary_key_name(%s)", "event_espresso"),$classname)); |
|
1639 | + protected static function _get_primary_key_name($classname = NULL) { |
|
1640 | + if ( ! $classname) { |
|
1641 | + throw new EE_Error(sprintf(__("What were you thinking calling _get_primary_key_name(%s)", "event_espresso"), $classname)); |
|
1642 | 1642 | } |
1643 | - return self::_get_model( $classname )->get_primary_key_field()->get_name(); |
|
1643 | + return self::_get_model($classname)->get_primary_key_field()->get_name(); |
|
1644 | 1644 | } |
1645 | 1645 | |
1646 | 1646 | |
@@ -1652,12 +1652,12 @@ discard block |
||
1652 | 1652 | * Usually defaults for integer primary keys are 0; string primary keys are usually NULL). |
1653 | 1653 | * @return mixed, if the primary key is of type INT it'll be an int. Otherwise it could be a string |
1654 | 1654 | */ |
1655 | - public function ID(){ |
|
1655 | + public function ID() { |
|
1656 | 1656 | //now that we know the name of the variable, use a variable variable to get its value and return its |
1657 | - if( $this->get_model()->has_primary_key_field() ) { |
|
1658 | - return $this->_fields[self::_get_primary_key_name( get_class($this) )]; |
|
1659 | - }else{ |
|
1660 | - return $this->get_model()->get_index_primary_key_string( $this->_fields ); |
|
1657 | + if ($this->get_model()->has_primary_key_field()) { |
|
1658 | + return $this->_fields[self::_get_primary_key_name(get_class($this))]; |
|
1659 | + } else { |
|
1660 | + return $this->get_model()->get_index_primary_key_string($this->_fields); |
|
1661 | 1661 | } |
1662 | 1662 | } |
1663 | 1663 | |
@@ -1675,38 +1675,38 @@ discard block |
||
1675 | 1675 | * @throws EE_Error |
1676 | 1676 | * @return EE_Base_Class the object the relation was added to |
1677 | 1677 | */ |
1678 | - public function _add_relation_to( $otherObjectModelObjectOrID,$relationName, $extra_join_model_fields_n_values = array(), $cache_id = NULL ){ |
|
1678 | + public function _add_relation_to($otherObjectModelObjectOrID, $relationName, $extra_join_model_fields_n_values = array(), $cache_id = NULL) { |
|
1679 | 1679 | //if this thing exists in the DB, save the relation to the DB |
1680 | - if( $this->ID() ){ |
|
1681 | - $otherObject = $this->get_model()->add_relationship_to( $this, $otherObjectModelObjectOrID, $relationName, $extra_join_model_fields_n_values ); |
|
1680 | + if ($this->ID()) { |
|
1681 | + $otherObject = $this->get_model()->add_relationship_to($this, $otherObjectModelObjectOrID, $relationName, $extra_join_model_fields_n_values); |
|
1682 | 1682 | //clear cache so future get_many_related and get_first_related() return new results. |
1683 | - $this->clear_cache( $relationName, $otherObject, TRUE ); |
|
1684 | - if( $otherObject instanceof EE_Base_Class ) { |
|
1685 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
1683 | + $this->clear_cache($relationName, $otherObject, TRUE); |
|
1684 | + if ($otherObject instanceof EE_Base_Class) { |
|
1685 | + $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
1686 | 1686 | } |
1687 | 1687 | } else { |
1688 | 1688 | //this thing doesn't exist in the DB, so just cache it |
1689 | - if( ! $otherObjectModelObjectOrID instanceof EE_Base_Class){ |
|
1690 | - throw new EE_Error( sprintf( |
|
1691 | - __( 'Before a model object is saved to the database, calls to _add_relation_to must be passed an actual object, not just an ID. You provided %s as the model object to a %s', 'event_espresso' ), |
|
1689 | + if ( ! $otherObjectModelObjectOrID instanceof EE_Base_Class) { |
|
1690 | + throw new EE_Error(sprintf( |
|
1691 | + __('Before a model object is saved to the database, calls to _add_relation_to must be passed an actual object, not just an ID. You provided %s as the model object to a %s', 'event_espresso'), |
|
1692 | 1692 | $otherObjectModelObjectOrID, |
1693 | - get_class( $this ) |
|
1693 | + get_class($this) |
|
1694 | 1694 | )); |
1695 | 1695 | } else { |
1696 | 1696 | $otherObject = $otherObjectModelObjectOrID; |
1697 | 1697 | } |
1698 | - $this->cache( $relationName, $otherObjectModelObjectOrID, $cache_id ); |
|
1698 | + $this->cache($relationName, $otherObjectModelObjectOrID, $cache_id); |
|
1699 | 1699 | } |
1700 | - if( $otherObject instanceof EE_Base_Class ) { |
|
1700 | + if ($otherObject instanceof EE_Base_Class) { |
|
1701 | 1701 | //fix the reciprocal relation too |
1702 | - if( $otherObject->ID() ) { |
|
1702 | + if ($otherObject->ID()) { |
|
1703 | 1703 | //its saved so assumed relations exist in the DB, so we can just |
1704 | 1704 | //clear the cache so future queries use the updated info in the DB |
1705 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), null, true ); |
|
1705 | + $otherObject->clear_cache($this->get_model()->get_this_model_name(), null, true); |
|
1706 | 1706 | } else { |
1707 | 1707 | |
1708 | 1708 | //it's not saved, so it caches relations like this |
1709 | - $otherObject->cache( $this->get_model()->get_this_model_name(), $this ); |
|
1709 | + $otherObject->cache($this->get_model()->get_this_model_name(), $this); |
|
1710 | 1710 | } |
1711 | 1711 | } |
1712 | 1712 | return $otherObject; |
@@ -1729,17 +1729,17 @@ discard block |
||
1729 | 1729 | * Also remember that if an exact match isn't found for these extra cols/val pairs, then a NEW row is created in the join table. |
1730 | 1730 | * @return EE_Base_Class the relation was removed from |
1731 | 1731 | */ |
1732 | - public function _remove_relation_to($otherObjectModelObjectOrID,$relationName, $where_query = array() ){ |
|
1733 | - if ( $this->ID() ) { |
|
1732 | + public function _remove_relation_to($otherObjectModelObjectOrID, $relationName, $where_query = array()) { |
|
1733 | + if ($this->ID()) { |
|
1734 | 1734 | //if this exists in the DB, save the relation change to the DB too |
1735 | - $otherObject = $this->get_model()->remove_relationship_to( $this, $otherObjectModelObjectOrID, $relationName, $where_query ); |
|
1736 | - $this->clear_cache( $relationName, $otherObject ); |
|
1735 | + $otherObject = $this->get_model()->remove_relationship_to($this, $otherObjectModelObjectOrID, $relationName, $where_query); |
|
1736 | + $this->clear_cache($relationName, $otherObject); |
|
1737 | 1737 | } else { |
1738 | 1738 | //this doesn't exist in the DB, just remove it from the cache |
1739 | - $otherObject = $this->clear_cache( $relationName, $otherObjectModelObjectOrID ); |
|
1739 | + $otherObject = $this->clear_cache($relationName, $otherObjectModelObjectOrID); |
|
1740 | 1740 | } |
1741 | - if( $otherObject instanceof EE_Base_Class ) { |
|
1742 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
1741 | + if ($otherObject instanceof EE_Base_Class) { |
|
1742 | + $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
1743 | 1743 | } |
1744 | 1744 | return $otherObject; |
1745 | 1745 | } |
@@ -1750,18 +1750,18 @@ discard block |
||
1750 | 1750 | * @param array $where_query_params like EEM_Base::get_all's $query_params[0] (where conditions) |
1751 | 1751 | * @return EE_Base_Class |
1752 | 1752 | */ |
1753 | - public function _remove_relations($relationName,$where_query_params = array()){ |
|
1754 | - if ( $this->ID() ) { |
|
1753 | + public function _remove_relations($relationName, $where_query_params = array()) { |
|
1754 | + if ($this->ID()) { |
|
1755 | 1755 | //if this exists in the DB, save the relation change to the DB too |
1756 | - $otherObjects = $this->get_model()->remove_relations( $this, $relationName, $where_query_params ); |
|
1757 | - $this->clear_cache( $relationName, null, true ); |
|
1756 | + $otherObjects = $this->get_model()->remove_relations($this, $relationName, $where_query_params); |
|
1757 | + $this->clear_cache($relationName, null, true); |
|
1758 | 1758 | } else { |
1759 | 1759 | //this doesn't exist in the DB, just remove it from the cache |
1760 | - $otherObjects = $this->clear_cache( $relationName, null, true ); |
|
1760 | + $otherObjects = $this->clear_cache($relationName, null, true); |
|
1761 | 1761 | } |
1762 | - if( is_array( $otherObjects ) ) { |
|
1763 | - foreach ( $otherObjects as $otherObject ) { |
|
1764 | - $otherObject->clear_cache( $this->get_model()->get_this_model_name(), $this ); |
|
1762 | + if (is_array($otherObjects)) { |
|
1763 | + foreach ($otherObjects as $otherObject) { |
|
1764 | + $otherObject->clear_cache($this->get_model()->get_this_model_name(), $this); |
|
1765 | 1765 | } |
1766 | 1766 | } |
1767 | 1767 | return $otherObjects; |
@@ -1779,26 +1779,26 @@ discard block |
||
1779 | 1779 | * @return EE_Base_Class[] Results not necessarily indexed by IDs, because some results might not have primary keys |
1780 | 1780 | * or might not be saved yet. Consider using EEM_Base::get_IDs() on these results if you want IDs |
1781 | 1781 | */ |
1782 | - public function get_many_related($relationName,$query_params = array()){ |
|
1783 | - if($this->ID()){//this exists in the DB, so get the related things from either the cache or the DB |
|
1782 | + public function get_many_related($relationName, $query_params = array()) { |
|
1783 | + if ($this->ID()) {//this exists in the DB, so get the related things from either the cache or the DB |
|
1784 | 1784 | //if there are query parameters, forget about caching the related model objects. |
1785 | - if( $query_params ){ |
|
1785 | + if ($query_params) { |
|
1786 | 1786 | $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params); |
1787 | - }else{ |
|
1787 | + } else { |
|
1788 | 1788 | //did we already cache the result of this query? |
1789 | 1789 | $cached_results = $this->get_all_from_cache($relationName); |
1790 | - if ( ! $cached_results ){ |
|
1790 | + if ( ! $cached_results) { |
|
1791 | 1791 | $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params); |
1792 | 1792 | //if no query parameters were passed, then we got all the related model objects |
1793 | 1793 | //for that relation. We can cache them then. |
1794 | - foreach($related_model_objects as $related_model_object){ |
|
1794 | + foreach ($related_model_objects as $related_model_object) { |
|
1795 | 1795 | $this->cache($relationName, $related_model_object); |
1796 | 1796 | } |
1797 | - }else{ |
|
1797 | + } else { |
|
1798 | 1798 | $related_model_objects = $cached_results; |
1799 | 1799 | } |
1800 | 1800 | } |
1801 | - }else{//this doesn't exist itn eh DB, so just get the related things from the cache |
|
1801 | + } else {//this doesn't exist itn eh DB, so just get the related things from the cache |
|
1802 | 1802 | $related_model_objects = $this->get_all_from_cache($relationName); |
1803 | 1803 | } |
1804 | 1804 | return $related_model_objects; |
@@ -1815,8 +1815,8 @@ discard block |
||
1815 | 1815 | * @param bool $distinct if we want to only count the distinct values for the column then you can trigger that by the setting $distinct to TRUE; |
1816 | 1816 | * @return int |
1817 | 1817 | */ |
1818 | - public function count_related($relation_name, $query_params =array(),$field_to_count = NULL, $distinct = FALSE){ |
|
1819 | - return $this->get_model()->count_related($this,$relation_name,$query_params,$field_to_count,$distinct); |
|
1818 | + public function count_related($relation_name, $query_params = array(), $field_to_count = NULL, $distinct = FALSE) { |
|
1819 | + return $this->get_model()->count_related($this, $relation_name, $query_params, $field_to_count, $distinct); |
|
1820 | 1820 | } |
1821 | 1821 | |
1822 | 1822 | |
@@ -1830,7 +1830,7 @@ discard block |
||
1830 | 1830 | * By default, uses primary key (which doesn't make much sense, so you should probably change it) |
1831 | 1831 | * @return int |
1832 | 1832 | */ |
1833 | - public function sum_related($relation_name, $query_params = array(), $field_to_sum = null){ |
|
1833 | + public function sum_related($relation_name, $query_params = array(), $field_to_sum = null) { |
|
1834 | 1834 | return $this->get_model()->sum_related($this, $relation_name, $query_params, $field_to_sum); |
1835 | 1835 | } |
1836 | 1836 | |
@@ -1842,34 +1842,34 @@ discard block |
||
1842 | 1842 | * @param array $query_params like EEM_Base::get_all |
1843 | 1843 | * @return EE_Base_Class (not an array, a single object) |
1844 | 1844 | */ |
1845 | - public function get_first_related($relationName,$query_params = array()){ |
|
1846 | - if($this->ID()){//this exists in the DB, get from the cache OR the DB |
|
1845 | + public function get_first_related($relationName, $query_params = array()) { |
|
1846 | + if ($this->ID()) {//this exists in the DB, get from the cache OR the DB |
|
1847 | 1847 | |
1848 | 1848 | //if they've provided some query parameters, don't bother trying to cache the result |
1849 | 1849 | //also make sure we're not caching the result of get_first_related |
1850 | 1850 | //on a relation which should have an array of objects (because the cache might have an array of objects) |
1851 | - if ($query_params || ! $this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation){ |
|
1852 | - $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
1853 | - }else{ |
|
1851 | + if ($query_params || ! $this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation) { |
|
1852 | + $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
1853 | + } else { |
|
1854 | 1854 | //first, check if we've already cached the result of this query |
1855 | 1855 | $cached_result = $this->get_one_from_cache($relationName); |
1856 | - if ( ! $cached_result ){ |
|
1856 | + if ( ! $cached_result) { |
|
1857 | 1857 | |
1858 | 1858 | $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
1859 | - $this->cache($relationName,$related_model_object); |
|
1860 | - }else{ |
|
1859 | + $this->cache($relationName, $related_model_object); |
|
1860 | + } else { |
|
1861 | 1861 | $related_model_object = $cached_result; |
1862 | 1862 | } |
1863 | 1863 | } |
1864 | - }else{ |
|
1864 | + } else { |
|
1865 | 1865 | //this doesn't exist in the Db, but maybe the relation is of type belongs to, and so the related thing might |
1866 | - if( $this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation){ |
|
1867 | - $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
1868 | - }else{ |
|
1866 | + if ($this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation) { |
|
1867 | + $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
|
1868 | + } else { |
|
1869 | 1869 | $related_model_object = null; |
1870 | 1870 | } |
1871 | 1871 | //this doesn't exist in the DB and apparently the thing it belongs to doesn't either, just get what's cached on this object |
1872 | - if( ! $related_model_object){ |
|
1872 | + if ( ! $related_model_object) { |
|
1873 | 1873 | $related_model_object = $this->get_one_from_cache($relationName); |
1874 | 1874 | } |
1875 | 1875 | |
@@ -1888,12 +1888,12 @@ discard block |
||
1888 | 1888 | * @param array $query_params like EEM_Base::get_all's |
1889 | 1889 | * @return int how many deleted |
1890 | 1890 | */ |
1891 | - public function delete_related($relationName,$query_params = array()){ |
|
1892 | - if($this->ID()){ |
|
1893 | - $count = $this->get_model()->delete_related($this, $relationName, $query_params); |
|
1894 | - }else{ |
|
1891 | + public function delete_related($relationName, $query_params = array()) { |
|
1892 | + if ($this->ID()) { |
|
1893 | + $count = $this->get_model()->delete_related($this, $relationName, $query_params); |
|
1894 | + } else { |
|
1895 | 1895 | $count = count($this->get_all_from_cache($relationName)); |
1896 | - $this->clear_cache($relationName,NULL,TRUE); |
|
1896 | + $this->clear_cache($relationName, NULL, TRUE); |
|
1897 | 1897 | } |
1898 | 1898 | return $count; |
1899 | 1899 | } |
@@ -1908,13 +1908,13 @@ discard block |
||
1908 | 1908 | * @param array $query_params like EEM_Base::get_all's |
1909 | 1909 | * @return int how many deleted (including those soft deleted) |
1910 | 1910 | */ |
1911 | - public function delete_related_permanently($relationName,$query_params = array()){ |
|
1912 | - if($this->ID()){ |
|
1913 | - $count = $this->get_model()->delete_related_permanently($this, $relationName, $query_params); |
|
1914 | - }else{ |
|
1911 | + public function delete_related_permanently($relationName, $query_params = array()) { |
|
1912 | + if ($this->ID()) { |
|
1913 | + $count = $this->get_model()->delete_related_permanently($this, $relationName, $query_params); |
|
1914 | + } else { |
|
1915 | 1915 | $count = count($this->get_all_from_cache($relationName)); |
1916 | 1916 | } |
1917 | - $this->clear_cache($relationName,NULL,TRUE); |
|
1917 | + $this->clear_cache($relationName, NULL, TRUE); |
|
1918 | 1918 | return $count; |
1919 | 1919 | } |
1920 | 1920 | |
@@ -1930,7 +1930,7 @@ discard block |
||
1930 | 1930 | * @param string $field_name property to check |
1931 | 1931 | * @return bool TRUE if existing,FALSE if not. |
1932 | 1932 | */ |
1933 | - public function is_set( $field_name ) { |
|
1933 | + public function is_set($field_name) { |
|
1934 | 1934 | return isset($this->_fields[$field_name]); |
1935 | 1935 | } |
1936 | 1936 | |
@@ -1942,12 +1942,12 @@ discard block |
||
1942 | 1942 | * @throws EE_Error |
1943 | 1943 | * @return bool TRUE if existing, throw EE_Error if not. |
1944 | 1944 | */ |
1945 | - protected function _property_exists( $properties ) { |
|
1945 | + protected function _property_exists($properties) { |
|
1946 | 1946 | |
1947 | - foreach ( (array) $properties as $property_name ) { |
|
1947 | + foreach ((array) $properties as $property_name) { |
|
1948 | 1948 | //first make sure this property exists |
1949 | - if ( ! $this->_fields[ $property_name ] ) |
|
1950 | - throw new EE_Error( sprintf( __('Trying to retrieve a non-existent property (%s). Double check the spelling please', 'event_espresso'), $property_name ) ); |
|
1949 | + if ( ! $this->_fields[$property_name]) |
|
1950 | + throw new EE_Error(sprintf(__('Trying to retrieve a non-existent property (%s). Double check the spelling please', 'event_espresso'), $property_name)); |
|
1951 | 1951 | } |
1952 | 1952 | |
1953 | 1953 | return TRUE; |
@@ -1964,7 +1964,7 @@ discard block |
||
1964 | 1964 | $fields = $this->get_model()->field_settings(FALSE); |
1965 | 1965 | $properties = array(); |
1966 | 1966 | //remove prepended underscore |
1967 | - foreach ( $fields as $field_name => $settings ) { |
|
1967 | + foreach ($fields as $field_name => $settings) { |
|
1968 | 1968 | $properties[$field_name] = $this->get($field_name); |
1969 | 1969 | } |
1970 | 1970 | return $properties; |
@@ -1994,14 +1994,14 @@ discard block |
||
1994 | 1994 | * @throws EE_Error |
1995 | 1995 | * @return mixed whatever the plugin which calls add_filter decides |
1996 | 1996 | */ |
1997 | - public function __call($methodName,$args){ |
|
1998 | - $className=get_class($this); |
|
1999 | - $tagName="FHEE__{$className}__{$methodName}"; |
|
2000 | - if(!has_filter($tagName)){ |
|
2001 | - throw new EE_Error(sprintf(__("Method %s on class %s does not exist! You can create one with the following code in functions.php or in a plugin: add_filter('%s','my_callback',10,3);function my_callback(\$previousReturnValue,EE_Base_Class \$object, \$argsArray){/*function body*/return \$whatever;}","event_espresso"), |
|
2002 | - $methodName,$className,$tagName)); |
|
1997 | + public function __call($methodName, $args) { |
|
1998 | + $className = get_class($this); |
|
1999 | + $tagName = "FHEE__{$className}__{$methodName}"; |
|
2000 | + if ( ! has_filter($tagName)) { |
|
2001 | + throw new EE_Error(sprintf(__("Method %s on class %s does not exist! You can create one with the following code in functions.php or in a plugin: add_filter('%s','my_callback',10,3);function my_callback(\$previousReturnValue,EE_Base_Class \$object, \$argsArray){/*function body*/return \$whatever;}", "event_espresso"), |
|
2002 | + $methodName, $className, $tagName)); |
|
2003 | 2003 | } |
2004 | - return apply_filters($tagName,null,$this,$args); |
|
2004 | + return apply_filters($tagName, null, $this, $args); |
|
2005 | 2005 | } |
2006 | 2006 | |
2007 | 2007 | |
@@ -2016,22 +2016,22 @@ discard block |
||
2016 | 2016 | * @return int records updated (or BOOLEAN if we actually ended up inserting the extra meta row) |
2017 | 2017 | * NOTE: if the values haven't changed, returns 0 |
2018 | 2018 | */ |
2019 | - public function update_extra_meta($meta_key,$meta_value,$previous_value = NULL){ |
|
2020 | - $query_params = array(array( |
|
2019 | + public function update_extra_meta($meta_key, $meta_value, $previous_value = NULL) { |
|
2020 | + $query_params = array(array( |
|
2021 | 2021 | 'EXM_key'=>$meta_key, |
2022 | 2022 | 'OBJ_ID'=>$this->ID(), |
2023 | 2023 | 'EXM_type'=>$this->get_model()->get_this_model_name())); |
2024 | - if($previous_value !== NULL){ |
|
2024 | + if ($previous_value !== NULL) { |
|
2025 | 2025 | $query_params[0]['EXM_value'] = $meta_value; |
2026 | 2026 | } |
2027 | 2027 | $existing_rows_like_that = EEM_Extra_Meta::instance()->get_all($query_params); |
2028 | - if( ! $existing_rows_like_that){ |
|
2028 | + if ( ! $existing_rows_like_that) { |
|
2029 | 2029 | return $this->add_extra_meta($meta_key, $meta_value); |
2030 | - }else{ |
|
2031 | - foreach( $existing_rows_like_that as $existing_row){ |
|
2032 | - $existing_row->save( array( 'EXM_value' => $meta_value ) ); |
|
2030 | + } else { |
|
2031 | + foreach ($existing_rows_like_that as $existing_row) { |
|
2032 | + $existing_row->save(array('EXM_value' => $meta_value)); |
|
2033 | 2033 | } |
2034 | - return count( $existing_rows_like_that ); |
|
2034 | + return count($existing_rows_like_that); |
|
2035 | 2035 | } |
2036 | 2036 | } |
2037 | 2037 | |
@@ -2044,10 +2044,10 @@ discard block |
||
2044 | 2044 | * @param boolean $unique |
2045 | 2045 | * @return boolean |
2046 | 2046 | */ |
2047 | - public function add_extra_meta($meta_key,$meta_value,$unique = false){ |
|
2048 | - if($unique){ |
|
2049 | - $existing_extra_meta = EEM_Extra_Meta::instance()->get_one(array(array('EXM_key'=>$meta_key,'OBJ_ID'=>$this->ID(),'EXM_type'=>$this->_get_model_classname(get_class($this))))); |
|
2050 | - if($existing_extra_meta){ |
|
2047 | + public function add_extra_meta($meta_key, $meta_value, $unique = false) { |
|
2048 | + if ($unique) { |
|
2049 | + $existing_extra_meta = EEM_Extra_Meta::instance()->get_one(array(array('EXM_key'=>$meta_key, 'OBJ_ID'=>$this->ID(), 'EXM_type'=>$this->_get_model_classname(get_class($this))))); |
|
2050 | + if ($existing_extra_meta) { |
|
2051 | 2051 | return false; |
2052 | 2052 | } |
2053 | 2053 | } |
@@ -2067,12 +2067,12 @@ discard block |
||
2067 | 2067 | * @param string $meta_value |
2068 | 2068 | * @return int number of extra meta rows deleted |
2069 | 2069 | */ |
2070 | - public function delete_extra_meta($meta_key,$meta_value = NULL){ |
|
2071 | - $query_params = array(array( |
|
2070 | + public function delete_extra_meta($meta_key, $meta_value = NULL) { |
|
2071 | + $query_params = array(array( |
|
2072 | 2072 | 'EXM_key'=>$meta_key, |
2073 | 2073 | 'OBJ_ID'=>$this->ID(), |
2074 | 2074 | 'EXM_type'=>$this->get_model()->get_this_model_name())); |
2075 | - if($meta_value !== NULL){ |
|
2075 | + if ($meta_value !== NULL) { |
|
2076 | 2076 | $query_params[0]['EXM_value'] = $meta_value; |
2077 | 2077 | } |
2078 | 2078 | $count_deleted = EEM_Extra_Meta::instance()->delete($query_params); |
@@ -2088,25 +2088,25 @@ discard block |
||
2088 | 2088 | * @param mixed $default if we don't find anything, what should we return? |
2089 | 2089 | * @return mixed single value if $single; array if ! $single |
2090 | 2090 | */ |
2091 | - public function get_extra_meta($meta_key,$single = FALSE,$default = NULL){ |
|
2092 | - if($single){ |
|
2093 | - $result = $this->get_first_related('Extra_Meta',array(array('EXM_key'=>$meta_key))); |
|
2094 | - if ( $result instanceof EE_Extra_Meta ){ |
|
2091 | + public function get_extra_meta($meta_key, $single = FALSE, $default = NULL) { |
|
2092 | + if ($single) { |
|
2093 | + $result = $this->get_first_related('Extra_Meta', array(array('EXM_key'=>$meta_key))); |
|
2094 | + if ($result instanceof EE_Extra_Meta) { |
|
2095 | 2095 | return $result->value(); |
2096 | - }else{ |
|
2096 | + } else { |
|
2097 | 2097 | return $default; |
2098 | 2098 | } |
2099 | - }else{ |
|
2100 | - $results = $this->get_many_related('Extra_Meta',array(array('EXM_key'=>$meta_key))); |
|
2101 | - if($results){ |
|
2099 | + } else { |
|
2100 | + $results = $this->get_many_related('Extra_Meta', array(array('EXM_key'=>$meta_key))); |
|
2101 | + if ($results) { |
|
2102 | 2102 | $values = array(); |
2103 | - foreach($results as $result){ |
|
2104 | - if ( $result instanceof EE_Extra_Meta ){ |
|
2103 | + foreach ($results as $result) { |
|
2104 | + if ($result instanceof EE_Extra_Meta) { |
|
2105 | 2105 | $values[$result->ID()] = $result->value(); |
2106 | 2106 | } |
2107 | 2107 | } |
2108 | 2108 | return $values; |
2109 | - }else{ |
|
2109 | + } else { |
|
2110 | 2110 | return $default; |
2111 | 2111 | } |
2112 | 2112 | } |
@@ -2123,20 +2123,20 @@ discard block |
||
2123 | 2123 | * @param boolean $one_of_each_key |
2124 | 2124 | * @return array |
2125 | 2125 | */ |
2126 | - public function all_extra_meta_array($one_of_each_key = true){ |
|
2126 | + public function all_extra_meta_array($one_of_each_key = true) { |
|
2127 | 2127 | $return_array = array(); |
2128 | - if($one_of_each_key){ |
|
2128 | + if ($one_of_each_key) { |
|
2129 | 2129 | $extra_meta_objs = $this->get_many_related('Extra_Meta', array('group_by'=>'EXM_key')); |
2130 | - foreach($extra_meta_objs as $extra_meta_obj){ |
|
2131 | - if ( $extra_meta_obj instanceof EE_Extra_Meta ) { |
|
2130 | + foreach ($extra_meta_objs as $extra_meta_obj) { |
|
2131 | + if ($extra_meta_obj instanceof EE_Extra_Meta) { |
|
2132 | 2132 | $return_array[$extra_meta_obj->key()] = $extra_meta_obj->value(); |
2133 | 2133 | } |
2134 | 2134 | } |
2135 | - }else{ |
|
2135 | + } else { |
|
2136 | 2136 | $extra_meta_objs = $this->get_many_related('Extra_Meta'); |
2137 | - foreach($extra_meta_objs as $extra_meta_obj){ |
|
2138 | - if ( $extra_meta_obj instanceof EE_Extra_Meta ) { |
|
2139 | - if( ! isset($return_array[$extra_meta_obj->key()])){ |
|
2137 | + foreach ($extra_meta_objs as $extra_meta_obj) { |
|
2138 | + if ($extra_meta_obj instanceof EE_Extra_Meta) { |
|
2139 | + if ( ! isset($return_array[$extra_meta_obj->key()])) { |
|
2140 | 2140 | $return_array[$extra_meta_obj->key()] = array(); |
2141 | 2141 | } |
2142 | 2142 | $return_array[$extra_meta_obj->key()][$extra_meta_obj->ID()] = $extra_meta_obj->value(); |
@@ -2149,19 +2149,19 @@ discard block |
||
2149 | 2149 | * Gets a pretty nice displayable nice for this model object. Often overridden |
2150 | 2150 | * @return string |
2151 | 2151 | */ |
2152 | - public function name(){ |
|
2152 | + public function name() { |
|
2153 | 2153 | //find a field that's not a text field |
2154 | 2154 | $field_we_can_use = $this->get_model()->get_a_field_of_type('EE_Text_Field_Base'); |
2155 | - if($field_we_can_use){ |
|
2155 | + if ($field_we_can_use) { |
|
2156 | 2156 | return $this->get($field_we_can_use->get_name()); |
2157 | - }else{ |
|
2157 | + } else { |
|
2158 | 2158 | $first_few_properties = $this->model_field_array(); |
2159 | - $first_few_properties = array_slice($first_few_properties,0,3); |
|
2159 | + $first_few_properties = array_slice($first_few_properties, 0, 3); |
|
2160 | 2160 | $name_parts = array(); |
2161 | - foreach( $first_few_properties as $name=> $value ){ |
|
2161 | + foreach ($first_few_properties as $name=> $value) { |
|
2162 | 2162 | $name_parts[] = "$name:$value"; |
2163 | 2163 | } |
2164 | - return implode(",",$name_parts); |
|
2164 | + return implode(",", $name_parts); |
|
2165 | 2165 | } |
2166 | 2166 | } |
2167 | 2167 | |
@@ -2170,11 +2170,11 @@ discard block |
||
2170 | 2170 | * Checks if this model object has been proven to already be in the entity map |
2171 | 2171 | * @return boolean |
2172 | 2172 | */ |
2173 | - public function in_entity_map(){ |
|
2174 | - if( $this->ID() && $this->get_model()->get_from_entity_map( $this->ID() ) === $this ) { |
|
2173 | + public function in_entity_map() { |
|
2174 | + if ($this->ID() && $this->get_model()->get_from_entity_map($this->ID()) === $this) { |
|
2175 | 2175 | //well, if we looked, did we find it in the entity map? |
2176 | 2176 | return TRUE; |
2177 | - }else{ |
|
2177 | + } else { |
|
2178 | 2178 | return FALSE; |
2179 | 2179 | } |
2180 | 2180 | } |
@@ -2185,21 +2185,21 @@ discard block |
||
2185 | 2185 | * @throws EE_Error if this model object isn't in the entity mapper (because then you should |
2186 | 2186 | * just use what's in the entity mapper and refresh it) and WP_DEBUG is TRUE |
2187 | 2187 | */ |
2188 | - public function refresh_from_db(){ |
|
2189 | - if( $this->ID() && $this->in_entity_map() ){ |
|
2190 | - $this->get_model()->refresh_entity_map_from_db( $this->ID() ); |
|
2191 | - }else{ |
|
2188 | + public function refresh_from_db() { |
|
2189 | + if ($this->ID() && $this->in_entity_map()) { |
|
2190 | + $this->get_model()->refresh_entity_map_from_db($this->ID()); |
|
2191 | + } else { |
|
2192 | 2192 | //if it doesn't have ID, you shouldn't be asking to refresh it from teh database (because its not in the database) |
2193 | 2193 | //if it has an ID but it's not in the map, and you're asking me to refresh it |
2194 | 2194 | //that's kinda dangerous. You should just use what's in the entity map, or add this to the entity map if there's |
2195 | 2195 | //absolutely nothing in it for this ID |
2196 | - if( WP_DEBUG ) { |
|
2196 | + if (WP_DEBUG) { |
|
2197 | 2197 | throw new EE_Error( |
2198 | 2198 | sprintf( |
2199 | - __( 'Trying to refresh a model object with ID "%1$s" that\'s not in the entity map? First off: you should put it in the entity map by calling %2$s. Second off, if you want what\'s in the database right now, you should just call %3$s yourself and discard this model object.', 'event_espresso' ), |
|
2199 | + __('Trying to refresh a model object with ID "%1$s" that\'s not in the entity map? First off: you should put it in the entity map by calling %2$s. Second off, if you want what\'s in the database right now, you should just call %3$s yourself and discard this model object.', 'event_espresso'), |
|
2200 | 2200 | $this->ID(), |
2201 | - get_class( $this->get_model() ) . '::instance()->add_to_entity_map()', |
|
2202 | - get_class( $this->get_model() ) . '::instance()->refresh_entity_map()' |
|
2201 | + get_class($this->get_model()).'::instance()->add_to_entity_map()', |
|
2202 | + get_class($this->get_model()).'::instance()->refresh_entity_map()' |
|
2203 | 2203 | ) |
2204 | 2204 | ); |
2205 | 2205 | } |
@@ -2211,8 +2211,8 @@ discard block |
||
2211 | 2211 | * (probably a bad assumption they have made, oh well) |
2212 | 2212 | * @return string |
2213 | 2213 | */ |
2214 | - public function __toString(){ |
|
2215 | - return sprintf( '%s (%s)', $this->name(), $this->ID() ); |
|
2214 | + public function __toString() { |
|
2215 | + return sprintf('%s (%s)', $this->name(), $this->ID()); |
|
2216 | 2216 | } |
2217 | 2217 | |
2218 | 2218 | /** |
@@ -2244,16 +2244,16 @@ discard block |
||
2244 | 2244 | * @return array |
2245 | 2245 | */ |
2246 | 2246 | public function __sleep() { |
2247 | - foreach( $this->get_model()->relation_settings() as $relation_name => $relation_obj ) { |
|
2248 | - if( $relation_obj instanceof EE_Belongs_To_Relation ) { |
|
2249 | - $classname = 'EE_' . $this->get_model()->get_this_model_name(); |
|
2250 | - if( $this->get_one_from_cache( $relation_name ) instanceof $classname && |
|
2251 | - $this->get_one_from_cache( $relation_name )->ID() ) { |
|
2252 | - $this->clear_cache( $relation_name, $this->get_one_from_cache( $relation_name )->ID() ); |
|
2247 | + foreach ($this->get_model()->relation_settings() as $relation_name => $relation_obj) { |
|
2248 | + if ($relation_obj instanceof EE_Belongs_To_Relation) { |
|
2249 | + $classname = 'EE_'.$this->get_model()->get_this_model_name(); |
|
2250 | + if ($this->get_one_from_cache($relation_name) instanceof $classname && |
|
2251 | + $this->get_one_from_cache($relation_name)->ID()) { |
|
2252 | + $this->clear_cache($relation_name, $this->get_one_from_cache($relation_name)->ID()); |
|
2253 | 2253 | } |
2254 | 2254 | } |
2255 | 2255 | } |
2256 | - return array_keys( get_object_vars( $this ) ); |
|
2256 | + return array_keys(get_object_vars($this)); |
|
2257 | 2257 | } |
2258 | 2258 | |
2259 | 2259 |
@@ -1,4 +1,6 @@ discard block |
||
1 | -<?php if (!defined('EVENT_ESPRESSO_VERSION')) exit('No direct script access allowed'); |
|
1 | +<?php if (!defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | + exit('No direct script access allowed'); |
|
3 | +} |
|
2 | 4 | do_action( 'AHEE_log', __FILE__, ' FILE LOADED', '' ); |
3 | 5 | /** |
4 | 6 | * |
@@ -170,7 +172,7 @@ discard block |
||
170 | 172 | foreach($this->get_model()->relation_settings() as $relation_name=>$relation_obj){ |
171 | 173 | if($relation_obj instanceof EE_Belongs_To_Relation){ |
172 | 174 | $this->_model_relations[$relation_name] = NULL; |
173 | - }else{ |
|
175 | + } else{ |
|
174 | 176 | $this->_model_relations[$relation_name] = array(); |
175 | 177 | } |
176 | 178 | } |
@@ -215,7 +217,7 @@ discard block |
||
215 | 217 | if( isset( $this->_props_n_values_provided_in_constructor[ $field_name ] ) && |
216 | 218 | $field_settings = $this->get_Model()->field_settings_for( $field_name )){ |
217 | 219 | return $field_settings->prepare_for_get( $this->_props_n_values_provided_in_constructor[ $field_name ] ); |
218 | - }else{ |
|
220 | + } else{ |
|
219 | 221 | return NULL; |
220 | 222 | } |
221 | 223 | } |
@@ -264,7 +266,7 @@ discard block |
||
264 | 266 | empty( $this->_fields[$field_name] ) ? $this->set( $field_name, time() ) : $this->set( $field_name, $this->_fields[$field_name] ); |
265 | 267 | } |
266 | 268 | |
267 | - }else{ |
|
269 | + } else{ |
|
268 | 270 | $this->_fields[$field_name] = $holder_of_value; |
269 | 271 | } |
270 | 272 | |
@@ -292,7 +294,7 @@ discard block |
||
292 | 294 | } |
293 | 295 | //let's unset any cache for this field_name from the $_cached_properties property. |
294 | 296 | $this->_clear_cached_property( $field_name ); |
295 | - }else{ |
|
297 | + } else{ |
|
296 | 298 | throw new EE_Error( sprintf( __( "A valid EE_Model_Field_Base could not be found for the given field name: %s", "event_espresso" ), $field_name ) ); |
297 | 299 | } |
298 | 300 | |
@@ -588,8 +590,9 @@ discard block |
||
588 | 590 | * @return void |
589 | 591 | */ |
590 | 592 | protected function _clear_cached_property( $property_name ) { |
591 | - if ( isset( $this->_cached_properties[ $property_name ] ) ) |
|
592 | - unset( $this->_cached_properties[ $property_name ] ); |
|
593 | + if ( isset( $this->_cached_properties[ $property_name ] ) ) { |
|
594 | + unset( $this->_cached_properties[ $property_name ] ); |
|
595 | + } |
|
593 | 596 | } |
594 | 597 | |
595 | 598 | |
@@ -629,10 +632,10 @@ discard block |
||
629 | 632 | if($clear_all){ |
630 | 633 | $obj_removed = true; |
631 | 634 | $this->_model_relations[$relationName] = null; |
632 | - }elseif($relationship_to_model instanceof EE_Belongs_To_Relation){ |
|
635 | + } elseif($relationship_to_model instanceof EE_Belongs_To_Relation){ |
|
633 | 636 | $obj_removed = $this->_model_relations[$relationName]; |
634 | 637 | $this->_model_relations[$relationName] = null; |
635 | - }else{ |
|
638 | + } else{ |
|
636 | 639 | if($object_to_remove_or_index_into_array instanceof EE_Base_Class && $object_to_remove_or_index_into_array->ID()){ |
637 | 640 | $index_in_cache = $object_to_remove_or_index_into_array->ID(); |
638 | 641 | if( is_array($this->_model_relations[$relationName]) && ! isset($this->_model_relations[$relationName][$index_in_cache])){ |
@@ -646,20 +649,20 @@ discard block |
||
646 | 649 | } |
647 | 650 | if($index_found_at){ |
648 | 651 | $index_in_cache = $index_found_at; |
649 | - }else{ |
|
652 | + } else{ |
|
650 | 653 | //it wasn't found. huh. well obviously it doesn't need to be removed from teh cache |
651 | 654 | //if it wasn't in it to begin with. So we're done |
652 | 655 | return $object_to_remove_or_index_into_array; |
653 | 656 | } |
654 | 657 | } |
655 | - }elseif($object_to_remove_or_index_into_array instanceof EE_Base_Class){ |
|
658 | + } elseif($object_to_remove_or_index_into_array instanceof EE_Base_Class){ |
|
656 | 659 | //so they provided a model object, but it's not yet saved to the DB... so let's go hunting for it! |
657 | 660 | foreach($this->get_all_from_cache($relationName) as $index => $potentially_obj_we_want){ |
658 | 661 | if($potentially_obj_we_want == $object_to_remove_or_index_into_array){ |
659 | 662 | $index_in_cache = $index; |
660 | 663 | } |
661 | 664 | } |
662 | - }else{ |
|
665 | + } else{ |
|
663 | 666 | $index_in_cache = $object_to_remove_or_index_into_array; |
664 | 667 | } |
665 | 668 | //supposedly we've found it. But it could just be that the client code |
@@ -668,7 +671,7 @@ discard block |
||
668 | 671 | isset( $this->_model_relations[$relationName][$index_in_cache])){ |
669 | 672 | $obj_removed = $this->_model_relations[$relationName][$index_in_cache]; |
670 | 673 | unset($this->_model_relations[$relationName][$index_in_cache]); |
671 | - }else{ |
|
674 | + } else{ |
|
672 | 675 | //that thing was never cached anyways. |
673 | 676 | $obj_removed = NULL; |
674 | 677 | } |
@@ -724,7 +727,7 @@ discard block |
||
724 | 727 | $cached_array_or_object = isset( $this->_model_relations[$relationName] ) ? $this->_model_relations[$relationName] : null; |
725 | 728 | if(is_array($cached_array_or_object)){ |
726 | 729 | return array_shift($cached_array_or_object); |
727 | - }else{ |
|
730 | + } else{ |
|
728 | 731 | return $cached_array_or_object; |
729 | 732 | } |
730 | 733 | } |
@@ -743,10 +746,10 @@ discard block |
||
743 | 746 | $cached_array_or_object = isset( $this->_model_relations[$relationName] ) ? $this->_model_relations[$relationName] : array(); |
744 | 747 | if(is_array($cached_array_or_object)){ |
745 | 748 | $objects = $cached_array_or_object; |
746 | - }elseif($cached_array_or_object){ |
|
749 | + } elseif($cached_array_or_object){ |
|
747 | 750 | //if the result is not an array, but exists, make it an array |
748 | 751 | $objects = array($cached_array_or_object); |
749 | - }else{ |
|
752 | + } else{ |
|
750 | 753 | //if nothing was found, return an empty array |
751 | 754 | $objects = array(); |
752 | 755 | } |
@@ -761,7 +764,7 @@ discard block |
||
761 | 764 | if( $model_object->ID() ){ |
762 | 765 | $model->add_to_entity_map( $model_object ); |
763 | 766 | } |
764 | - }else{ |
|
767 | + } else{ |
|
765 | 768 | throw new EE_Error( sprintf( __( 'Error retrieving related model objects. Either $1%s is not a model or $2%s is not a model object', 'event_espresso' ), $relationName, gettype( $model_object ))); |
766 | 769 | } |
767 | 770 | } |
@@ -886,10 +889,10 @@ discard block |
||
886 | 889 | if( $field_obj->is_nullable()){ |
887 | 890 | //if the field allows nulls, then let it be null |
888 | 891 | $field_value = NULL; |
889 | - }else{ |
|
892 | + } else{ |
|
890 | 893 | $field_value = $field_obj->get_default_value(); |
891 | 894 | } |
892 | - }else{ |
|
895 | + } else{ |
|
893 | 896 | $field_value = $field_obj->prepare_for_set_from_db( $field_value_from_db ); |
894 | 897 | } |
895 | 898 | $this->_fields[$field_name] = $field_value; |
@@ -1009,15 +1012,17 @@ discard block |
||
1009 | 1012 | $this->_tm_frmt = $in_tm_frmt; |
1010 | 1013 | } |
1011 | 1014 | |
1012 | - if ( $echo ) |
|
1013 | - $field->set_pretty_date_format( $in_dt_frmt ); |
|
1014 | - else |
|
1015 | - $field->set_date_format( $in_dt_frmt ); |
|
1015 | + if ( $echo ) { |
|
1016 | + $field->set_pretty_date_format( $in_dt_frmt ); |
|
1017 | + } else { |
|
1018 | + $field->set_date_format( $in_dt_frmt ); |
|
1019 | + } |
|
1016 | 1020 | |
1017 | - if ( $echo ) |
|
1018 | - $field->set_pretty_time_format( $in_tm_frmt ); |
|
1019 | - else |
|
1020 | - $field->set_time_format( $in_tm_frmt ); |
|
1021 | + if ( $echo ) { |
|
1022 | + $field->set_pretty_time_format( $in_tm_frmt ); |
|
1023 | + } else { |
|
1024 | + $field->set_time_format( $in_tm_frmt ); |
|
1025 | + } |
|
1021 | 1026 | |
1022 | 1027 | //set timezone in field object |
1023 | 1028 | $field->set_timezone( $this->_timezone ); |
@@ -1240,8 +1245,9 @@ discard block |
||
1240 | 1245 | EE_Registry::instance()->load_helper('DTT_Helper'); |
1241 | 1246 | $timezone = EEH_DTT_Helper::get_timezone(); |
1242 | 1247 | |
1243 | - if ( $timezone == $this->_timezone ) |
|
1244 | - return ''; |
|
1248 | + if ( $timezone == $this->_timezone ) { |
|
1249 | + return ''; |
|
1250 | + } |
|
1245 | 1251 | |
1246 | 1252 | $original_timezone = $this->_timezone; |
1247 | 1253 | $this->set_timezone( $timezone ); |
@@ -1249,8 +1255,9 @@ discard block |
||
1249 | 1255 | $fn = (array) $field_name; |
1250 | 1256 | $args = array_merge( $fn, (array) $args ); |
1251 | 1257 | |
1252 | - if ( !method_exists( $this, $callback ) ) |
|
1253 | - throw new EE_Error(sprintf( __('The method named "%s" given as the callback param in "display_in_my_timezone" does not exist. Please check your spelling', 'event_espresso'), $callback ) ); |
|
1258 | + if ( !method_exists( $this, $callback ) ) { |
|
1259 | + throw new EE_Error(sprintf( __('The method named "%s" given as the callback param in "display_in_my_timezone" does not exist. Please check your spelling', 'event_espresso'), $callback ) ); |
|
1260 | + } |
|
1254 | 1261 | $args = (array) $args; |
1255 | 1262 | $return = $prepend . call_user_func_array( array( $this, $callback ), $args ) . $append; |
1256 | 1263 | |
@@ -1397,7 +1404,7 @@ discard block |
||
1397 | 1404 | $this->_update_cached_related_model_objs_fks(); |
1398 | 1405 | } |
1399 | 1406 | } |
1400 | - }else{//PK is NOT auto-increment |
|
1407 | + } else{//PK is NOT auto-increment |
|
1401 | 1408 | //so check if one like it already exists in the db |
1402 | 1409 | if( $this->get_model()->exists_by_ID( $this->ID() ) ){ |
1403 | 1410 | if( ! $this->in_entity_map() && WP_DEBUG ){ |
@@ -1412,12 +1419,12 @@ discard block |
||
1412 | 1419 | ); |
1413 | 1420 | } |
1414 | 1421 | $results = $this->get_model()->update_by_ID($save_cols_n_values, $this->ID()); |
1415 | - }else{ |
|
1422 | + } else{ |
|
1416 | 1423 | $results = $this->get_model()->insert($save_cols_n_values); |
1417 | 1424 | $this->_update_cached_related_model_objs_fks(); |
1418 | 1425 | } |
1419 | 1426 | } |
1420 | - }else{//there is NO primary key |
|
1427 | + } else{//there is NO primary key |
|
1421 | 1428 | $already_in_db = false; |
1422 | 1429 | foreach($this->get_model()->unique_indexes() as $index){ |
1423 | 1430 | $uniqueness_where_params = array_intersect_key($save_cols_n_values, $index->fields()); |
@@ -1428,7 +1435,7 @@ discard block |
||
1428 | 1435 | if( $already_in_db ){ |
1429 | 1436 | $combined_pk_fields_n_values = array_intersect_key( $save_cols_n_values, $this->get_model()->get_combined_primary_key_fields() ); |
1430 | 1437 | $results = $this->get_model()->update( $save_cols_n_values,$combined_pk_fields_n_values ); |
1431 | - }else{ |
|
1438 | + } else{ |
|
1432 | 1439 | $results = $this->get_model()->insert( $save_cols_n_values ); |
1433 | 1440 | } |
1434 | 1441 | } |
@@ -1480,7 +1487,7 @@ discard block |
||
1480 | 1487 | //make sure this has been saved |
1481 | 1488 | if( ! $this->ID()){ |
1482 | 1489 | $id = $this->save(); |
1483 | - }else{ |
|
1490 | + } else{ |
|
1484 | 1491 | $id = $this->ID(); |
1485 | 1492 | } |
1486 | 1493 | //now save all the NEW cached model objects (ie they don't exist in the DB) |
@@ -1499,7 +1506,7 @@ discard block |
||
1499 | 1506 | $this->_add_relation_to($related_model_obj, $relationName); |
1500 | 1507 | $related_model_obj->save_new_cached_related_model_objs(); |
1501 | 1508 | // } |
1502 | - }else{ |
|
1509 | + } else{ |
|
1503 | 1510 | foreach($this->_model_relations[$relationName] as $related_model_obj){ |
1504 | 1511 | //add a relation to that relation type (which saves the appropriate thing in the process) |
1505 | 1512 | //but ONLY if it DOES NOT exist in the DB |
@@ -1558,13 +1565,13 @@ discard block |
||
1558 | 1565 | |
1559 | 1566 | if ( array_key_exists( $primary_id_ref, $props_n_values ) && !empty( $props_n_values[$primary_id_ref] ) ) { |
1560 | 1567 | $existing = self::_get_model( $classname, $timezone )->get_one_by_ID( $props_n_values[$primary_id_ref] ); |
1561 | - }else{ |
|
1568 | + } else{ |
|
1562 | 1569 | $existing = null; |
1563 | 1570 | } |
1564 | - }elseif( self::_get_model( $classname, $timezone )->has_all_combined_primary_key_fields( $props_n_values ) ){ |
|
1571 | + } elseif( self::_get_model( $classname, $timezone )->has_all_combined_primary_key_fields( $props_n_values ) ){ |
|
1565 | 1572 | //no primary key on this model, but there's still a matching item in the DB |
1566 | 1573 | $existing = self::_get_model($classname, $timezone)->get_one_by_ID( self::_get_model($classname, $timezone)->get_index_primary_key_string( $props_n_values ) ); |
1567 | - }else{ |
|
1574 | + } else{ |
|
1568 | 1575 | $existing = null; |
1569 | 1576 | } |
1570 | 1577 | if ( $existing ) { |
@@ -1622,7 +1629,7 @@ discard block |
||
1622 | 1629 | private static function _get_model_classname( $model_name = null){ |
1623 | 1630 | if(strpos($model_name,"EE_")===0){ |
1624 | 1631 | $model_classname=str_replace("EE_","EEM_",$model_name); |
1625 | - }else{ |
|
1632 | + } else{ |
|
1626 | 1633 | $model_classname = "EEM_".$model_name; |
1627 | 1634 | } |
1628 | 1635 | return $model_classname; |
@@ -1656,7 +1663,7 @@ discard block |
||
1656 | 1663 | //now that we know the name of the variable, use a variable variable to get its value and return its |
1657 | 1664 | if( $this->get_model()->has_primary_key_field() ) { |
1658 | 1665 | return $this->_fields[self::_get_primary_key_name( get_class($this) )]; |
1659 | - }else{ |
|
1666 | + } else{ |
|
1660 | 1667 | return $this->get_model()->get_index_primary_key_string( $this->_fields ); |
1661 | 1668 | } |
1662 | 1669 | } |
@@ -1784,7 +1791,7 @@ discard block |
||
1784 | 1791 | //if there are query parameters, forget about caching the related model objects. |
1785 | 1792 | if( $query_params ){ |
1786 | 1793 | $related_model_objects = $this->get_model()->get_all_related($this, $relationName, $query_params); |
1787 | - }else{ |
|
1794 | + } else{ |
|
1788 | 1795 | //did we already cache the result of this query? |
1789 | 1796 | $cached_results = $this->get_all_from_cache($relationName); |
1790 | 1797 | if ( ! $cached_results ){ |
@@ -1794,11 +1801,11 @@ discard block |
||
1794 | 1801 | foreach($related_model_objects as $related_model_object){ |
1795 | 1802 | $this->cache($relationName, $related_model_object); |
1796 | 1803 | } |
1797 | - }else{ |
|
1804 | + } else{ |
|
1798 | 1805 | $related_model_objects = $cached_results; |
1799 | 1806 | } |
1800 | 1807 | } |
1801 | - }else{//this doesn't exist itn eh DB, so just get the related things from the cache |
|
1808 | + } else{//this doesn't exist itn eh DB, so just get the related things from the cache |
|
1802 | 1809 | $related_model_objects = $this->get_all_from_cache($relationName); |
1803 | 1810 | } |
1804 | 1811 | return $related_model_objects; |
@@ -1850,22 +1857,22 @@ discard block |
||
1850 | 1857 | //on a relation which should have an array of objects (because the cache might have an array of objects) |
1851 | 1858 | if ($query_params || ! $this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation){ |
1852 | 1859 | $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
1853 | - }else{ |
|
1860 | + } else{ |
|
1854 | 1861 | //first, check if we've already cached the result of this query |
1855 | 1862 | $cached_result = $this->get_one_from_cache($relationName); |
1856 | 1863 | if ( ! $cached_result ){ |
1857 | 1864 | |
1858 | 1865 | $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
1859 | 1866 | $this->cache($relationName,$related_model_object); |
1860 | - }else{ |
|
1867 | + } else{ |
|
1861 | 1868 | $related_model_object = $cached_result; |
1862 | 1869 | } |
1863 | 1870 | } |
1864 | - }else{ |
|
1871 | + } else{ |
|
1865 | 1872 | //this doesn't exist in the Db, but maybe the relation is of type belongs to, and so the related thing might |
1866 | 1873 | if( $this->get_model()->related_settings_for($relationName) instanceof EE_Belongs_To_Relation){ |
1867 | 1874 | $related_model_object = $this->get_model()->get_first_related($this, $relationName, $query_params); |
1868 | - }else{ |
|
1875 | + } else{ |
|
1869 | 1876 | $related_model_object = null; |
1870 | 1877 | } |
1871 | 1878 | //this doesn't exist in the DB and apparently the thing it belongs to doesn't either, just get what's cached on this object |
@@ -1891,7 +1898,7 @@ discard block |
||
1891 | 1898 | public function delete_related($relationName,$query_params = array()){ |
1892 | 1899 | if($this->ID()){ |
1893 | 1900 | $count = $this->get_model()->delete_related($this, $relationName, $query_params); |
1894 | - }else{ |
|
1901 | + } else{ |
|
1895 | 1902 | $count = count($this->get_all_from_cache($relationName)); |
1896 | 1903 | $this->clear_cache($relationName,NULL,TRUE); |
1897 | 1904 | } |
@@ -1911,7 +1918,7 @@ discard block |
||
1911 | 1918 | public function delete_related_permanently($relationName,$query_params = array()){ |
1912 | 1919 | if($this->ID()){ |
1913 | 1920 | $count = $this->get_model()->delete_related_permanently($this, $relationName, $query_params); |
1914 | - }else{ |
|
1921 | + } else{ |
|
1915 | 1922 | $count = count($this->get_all_from_cache($relationName)); |
1916 | 1923 | } |
1917 | 1924 | $this->clear_cache($relationName,NULL,TRUE); |
@@ -1946,8 +1953,9 @@ discard block |
||
1946 | 1953 | |
1947 | 1954 | foreach ( (array) $properties as $property_name ) { |
1948 | 1955 | //first make sure this property exists |
1949 | - if ( ! $this->_fields[ $property_name ] ) |
|
1950 | - throw new EE_Error( sprintf( __('Trying to retrieve a non-existent property (%s). Double check the spelling please', 'event_espresso'), $property_name ) ); |
|
1956 | + if ( ! $this->_fields[ $property_name ] ) { |
|
1957 | + throw new EE_Error( sprintf( __('Trying to retrieve a non-existent property (%s). Double check the spelling please', 'event_espresso'), $property_name ) ); |
|
1958 | + } |
|
1951 | 1959 | } |
1952 | 1960 | |
1953 | 1961 | return TRUE; |
@@ -2027,7 +2035,7 @@ discard block |
||
2027 | 2035 | $existing_rows_like_that = EEM_Extra_Meta::instance()->get_all($query_params); |
2028 | 2036 | if( ! $existing_rows_like_that){ |
2029 | 2037 | return $this->add_extra_meta($meta_key, $meta_value); |
2030 | - }else{ |
|
2038 | + } else{ |
|
2031 | 2039 | foreach( $existing_rows_like_that as $existing_row){ |
2032 | 2040 | $existing_row->save( array( 'EXM_value' => $meta_value ) ); |
2033 | 2041 | } |
@@ -2093,10 +2101,10 @@ discard block |
||
2093 | 2101 | $result = $this->get_first_related('Extra_Meta',array(array('EXM_key'=>$meta_key))); |
2094 | 2102 | if ( $result instanceof EE_Extra_Meta ){ |
2095 | 2103 | return $result->value(); |
2096 | - }else{ |
|
2104 | + } else{ |
|
2097 | 2105 | return $default; |
2098 | 2106 | } |
2099 | - }else{ |
|
2107 | + } else{ |
|
2100 | 2108 | $results = $this->get_many_related('Extra_Meta',array(array('EXM_key'=>$meta_key))); |
2101 | 2109 | if($results){ |
2102 | 2110 | $values = array(); |
@@ -2106,7 +2114,7 @@ discard block |
||
2106 | 2114 | } |
2107 | 2115 | } |
2108 | 2116 | return $values; |
2109 | - }else{ |
|
2117 | + } else{ |
|
2110 | 2118 | return $default; |
2111 | 2119 | } |
2112 | 2120 | } |
@@ -2132,7 +2140,7 @@ discard block |
||
2132 | 2140 | $return_array[$extra_meta_obj->key()] = $extra_meta_obj->value(); |
2133 | 2141 | } |
2134 | 2142 | } |
2135 | - }else{ |
|
2143 | + } else{ |
|
2136 | 2144 | $extra_meta_objs = $this->get_many_related('Extra_Meta'); |
2137 | 2145 | foreach($extra_meta_objs as $extra_meta_obj){ |
2138 | 2146 | if ( $extra_meta_obj instanceof EE_Extra_Meta ) { |
@@ -2154,7 +2162,7 @@ discard block |
||
2154 | 2162 | $field_we_can_use = $this->get_model()->get_a_field_of_type('EE_Text_Field_Base'); |
2155 | 2163 | if($field_we_can_use){ |
2156 | 2164 | return $this->get($field_we_can_use->get_name()); |
2157 | - }else{ |
|
2165 | + } else{ |
|
2158 | 2166 | $first_few_properties = $this->model_field_array(); |
2159 | 2167 | $first_few_properties = array_slice($first_few_properties,0,3); |
2160 | 2168 | $name_parts = array(); |
@@ -2174,7 +2182,7 @@ discard block |
||
2174 | 2182 | if( $this->ID() && $this->get_model()->get_from_entity_map( $this->ID() ) === $this ) { |
2175 | 2183 | //well, if we looked, did we find it in the entity map? |
2176 | 2184 | return TRUE; |
2177 | - }else{ |
|
2185 | + } else{ |
|
2178 | 2186 | return FALSE; |
2179 | 2187 | } |
2180 | 2188 | } |
@@ -2188,7 +2196,7 @@ discard block |
||
2188 | 2196 | public function refresh_from_db(){ |
2189 | 2197 | if( $this->ID() && $this->in_entity_map() ){ |
2190 | 2198 | $this->get_model()->refresh_entity_map_from_db( $this->ID() ); |
2191 | - }else{ |
|
2199 | + } else{ |
|
2192 | 2200 | //if it doesn't have ID, you shouldn't be asking to refresh it from teh database (because its not in the database) |
2193 | 2201 | //if it has an ID but it's not in the map, and you're asking me to refresh it |
2194 | 2202 | //that's kinda dangerous. You should just use what's in the entity map, or add this to the entity map if there's |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if (!defined('EVENT_ESPRESSO_VERSION')) |
|
2 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) |
|
3 | 3 | exit('NO direct script access allowed'); |
4 | 4 | |
5 | 5 | /** |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | 'espresso_events' => 'edit' |
68 | 68 | ); |
69 | 69 | |
70 | - add_action('AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', array( $this, 'verify_event_edit' ) ); |
|
70 | + add_action('AHEE__EE_Admin_Page_CPT__set_model_object__after_set_object', array($this, 'verify_event_edit')); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | protected function _ajax_hooks() { |
@@ -93,20 +93,20 @@ discard block |
||
93 | 93 | 'edit' => __('Update Event', 'event_espresso'), |
94 | 94 | 'add_category' => __('Save New Category', 'event_espresso'), |
95 | 95 | 'edit_category' => __('Update Category', 'event_espresso'), |
96 | - 'template_settings' => __( 'Update Settings', 'event_espresso' ) |
|
96 | + 'template_settings' => __('Update Settings', 'event_espresso') |
|
97 | 97 | ) |
98 | 98 | ); |
99 | 99 | } |
100 | 100 | |
101 | 101 | protected function _set_page_routes() { |
102 | 102 | //load formatter helper |
103 | - EE_Registry::instance()->load_helper( 'Formatter' ); |
|
103 | + EE_Registry::instance()->load_helper('Formatter'); |
|
104 | 104 | //load field generator helper |
105 | - EE_Registry::instance()->load_helper( 'Form_Fields' ); |
|
105 | + EE_Registry::instance()->load_helper('Form_Fields'); |
|
106 | 106 | |
107 | 107 | //is there a evt_id in the request? |
108 | - $evt_id = ! empty( $this->_req_data['EVT_ID'] ) && ! is_array( $this->_req_data['EVT_ID'] ) ? $this->_req_data['EVT_ID'] : 0; |
|
109 | - $evt_id = ! empty( $this->_req_data['post'] ) ? $this->_req_data['post'] : $evt_id; |
|
108 | + $evt_id = ! empty($this->_req_data['EVT_ID']) && ! is_array($this->_req_data['EVT_ID']) ? $this->_req_data['EVT_ID'] : 0; |
|
109 | + $evt_id = ! empty($this->_req_data['post']) ? $this->_req_data['post'] : $evt_id; |
|
110 | 110 | |
111 | 111 | |
112 | 112 | $this->_page_routes = array( |
@@ -320,7 +320,7 @@ discard block |
||
320 | 320 | 'help_tour' => array( |
321 | 321 | 'Event_Editor_Help_Tour' |
322 | 322 | ), |
323 | - 'qtips' => array( 'EE_Event_Editor_Decaf_Tips' ), |
|
323 | + 'qtips' => array('EE_Event_Editor_Decaf_Tips'), |
|
324 | 324 | 'require_nonce' => FALSE |
325 | 325 | ), |
326 | 326 | 'edit' => array( |
@@ -376,7 +376,7 @@ discard block |
||
376 | 376 | 'help_tour' => array( |
377 | 377 | 'Event_Edit_Help_Tour' |
378 | 378 | ), |
379 | - 'qtips' => array( 'EE_Event_Editor_Decaf_Tips' ), |
|
379 | + 'qtips' => array('EE_Event_Editor_Decaf_Tips'), |
|
380 | 380 | 'require_nonce' => FALSE |
381 | 381 | ), |
382 | 382 | 'default_event_settings' => array( |
@@ -398,7 +398,7 @@ discard block |
||
398 | 398 | 'filename' => 'events_default_settings_status' |
399 | 399 | ) |
400 | 400 | ), |
401 | - 'help_tour' => array( 'Event_Default_Settings_Help_Tour'), |
|
401 | + 'help_tour' => array('Event_Default_Settings_Help_Tour'), |
|
402 | 402 | 'require_nonce' => FALSE |
403 | 403 | ), |
404 | 404 | //template settings |
@@ -414,7 +414,7 @@ discard block |
||
414 | 414 | 'filename' => 'general_settings_templates' |
415 | 415 | ) |
416 | 416 | ), |
417 | - 'help_tour' => array( 'Templates_Help_Tour' ), |
|
417 | + 'help_tour' => array('Templates_Help_Tour'), |
|
418 | 418 | 'require_nonce' => FALSE |
419 | 419 | ), |
420 | 420 | //event category stuff |
@@ -438,7 +438,7 @@ discard block |
||
438 | 438 | 'label' => __('Edit Category', 'event_espresso'), |
439 | 439 | 'order' => 15, |
440 | 440 | 'persistent' => FALSE, |
441 | - 'url' => isset($this->_req_data['EVT_CAT_ID']) ? add_query_arg(array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID'] ), $this->_current_page_view_url ) : $this->_admin_base_url |
|
441 | + 'url' => isset($this->_req_data['EVT_CAT_ID']) ? add_query_arg(array('EVT_CAT_ID' => $this->_req_data['EVT_CAT_ID']), $this->_current_page_view_url) : $this->_admin_base_url |
|
442 | 442 | ), |
443 | 443 | 'help_tabs' => array( |
444 | 444 | 'edit_category_help_tab' => array( |
@@ -508,14 +508,14 @@ discard block |
||
508 | 508 | |
509 | 509 | public function load_scripts_styles() { |
510 | 510 | |
511 | - wp_register_style('events-admin-css', EVENTS_ASSETS_URL . 'events-admin-page.css', array(), EVENT_ESPRESSO_VERSION); |
|
512 | - wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL . 'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION ); |
|
511 | + wp_register_style('events-admin-css', EVENTS_ASSETS_URL.'events-admin-page.css', array(), EVENT_ESPRESSO_VERSION); |
|
512 | + wp_register_style('ee-cat-admin', EVENTS_ASSETS_URL.'ee-cat-admin.css', array(), EVENT_ESPRESSO_VERSION); |
|
513 | 513 | wp_enqueue_style('events-admin-css'); |
514 | 514 | wp_enqueue_style('ee-cat-admin'); |
515 | 515 | //todo note: we also need to load_scripts_styles per view (i.e. default/view_report/event_details |
516 | 516 | //registers for all views |
517 | 517 | //scripts |
518 | - wp_register_script('event_editor_js', EVENTS_ASSETS_URL . 'event_editor.js', array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'), EVENT_ESPRESSO_VERSION, TRUE); |
|
518 | + wp_register_script('event_editor_js', EVENTS_ASSETS_URL.'event_editor.js', array('ee_admin_js', 'jquery-ui-slider', 'jquery-ui-timepicker-addon'), EVENT_ESPRESSO_VERSION, TRUE); |
|
519 | 519 | } |
520 | 520 | |
521 | 521 | /** |
@@ -533,11 +533,11 @@ discard block |
||
533 | 533 | public function load_scripts_styles_edit() { |
534 | 534 | //styles |
535 | 535 | wp_enqueue_style('espresso-ui-theme'); |
536 | - wp_register_style('event-editor-css', EVENTS_ASSETS_URL . 'event-editor.css', array('ee-admin-css'), EVENT_ESPRESSO_VERSION ); |
|
536 | + wp_register_style('event-editor-css', EVENTS_ASSETS_URL.'event-editor.css', array('ee-admin-css'), EVENT_ESPRESSO_VERSION); |
|
537 | 537 | wp_enqueue_style('event-editor-css'); |
538 | 538 | |
539 | 539 | //scripts |
540 | - wp_register_script('event-datetime-metabox', EVENTS_ASSETS_URL . 'event-datetime-metabox.js', array('event_editor_js', 'ee-datepicker'), EVENT_ESPRESSO_VERSION ); |
|
540 | + wp_register_script('event-datetime-metabox', EVENTS_ASSETS_URL.'event-datetime-metabox.js', array('event_editor_js', 'ee-datepicker'), EVENT_ESPRESSO_VERSION); |
|
541 | 541 | wp_enqueue_script('event-datetime-metabox'); |
542 | 542 | |
543 | 543 | } |
@@ -572,7 +572,7 @@ discard block |
||
572 | 572 | |
573 | 573 | |
574 | 574 | public function admin_init() { |
575 | - EE_Registry::$i18n_js_strings[ 'image_confirm' ] = __( 'Do you really want to delete this image? Please remember to update your event to complete the removal.', 'event_espresso' ); |
|
575 | + EE_Registry::$i18n_js_strings['image_confirm'] = __('Do you really want to delete this image? Please remember to update your event to complete the removal.', 'event_espresso'); |
|
576 | 576 | } |
577 | 577 | |
578 | 578 | |
@@ -593,45 +593,45 @@ discard block |
||
593 | 593 | */ |
594 | 594 | public function verify_event_edit($event = NULL) { |
595 | 595 | // no event? |
596 | - if ( empty( $event )) { |
|
596 | + if (empty($event)) { |
|
597 | 597 | // set event |
598 | 598 | $event = $this->_cpt_model_obj; |
599 | 599 | } |
600 | 600 | // STILL no event? |
601 | - if ( empty ( $event )) { |
|
601 | + if (empty ($event)) { |
|
602 | 602 | return; |
603 | 603 | } |
604 | 604 | // first check if event is active. |
605 | - if ( $event->is_expired() || $event->is_inactive() || $event->status() == EEM_Event::cancelled || $event->status() == EEM_Event::postponed ) { |
|
605 | + if ($event->is_expired() || $event->is_inactive() || $event->status() == EEM_Event::cancelled || $event->status() == EEM_Event::postponed) { |
|
606 | 606 | return; |
607 | 607 | } |
608 | 608 | $orig_status = $event->status(); |
609 | 609 | //made it here so it IS active... next check that any of the tickets are sold. |
610 | - if ( $event->is_sold_out( true ) ) { |
|
611 | - if ( $event->status() !== $orig_status && $orig_status !== EEM_Event::sold_out ) { |
|
610 | + if ($event->is_sold_out(true)) { |
|
611 | + if ($event->status() !== $orig_status && $orig_status !== EEM_Event::sold_out) { |
|
612 | 612 | EE_Error::add_attention( |
613 | 613 | sprintf( |
614 | - __( 'Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event. However, this change is not permanent until you update the event. You can change the status back to something else before updating if you wish.', 'event_espresso' ), |
|
615 | - EEH_Template::pretty_status( EEM_Event::sold_out, FALSE, 'sentence' ) |
|
614 | + __('Please note that the Event Status has automatically been changed to %s because there are no more spaces available for this event. However, this change is not permanent until you update the event. You can change the status back to something else before updating if you wish.', 'event_espresso'), |
|
615 | + EEH_Template::pretty_status(EEM_Event::sold_out, FALSE, 'sentence') |
|
616 | 616 | ) |
617 | 617 | ); |
618 | 618 | } |
619 | 619 | return; |
620 | - } else if ( $orig_status === EEM_Event::sold_out ) { |
|
620 | + } else if ($orig_status === EEM_Event::sold_out) { |
|
621 | 621 | EE_Error::add_attention( |
622 | 622 | sprintf( |
623 | - __( 'Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets. However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.', |
|
624 | - 'event_espresso' ), |
|
625 | - EEH_Template::pretty_status( $event->status(), false, 'sentence' ) |
|
623 | + __('Please note that the Event Status has automatically been changed to %s because more spaces have become available for this event, most likely due to abandoned transactions freeing up reserved tickets. However, this change is not permanent until you update the event. If you wish, you can change the status back to something else before updating.', |
|
624 | + 'event_espresso'), |
|
625 | + EEH_Template::pretty_status($event->status(), false, 'sentence') |
|
626 | 626 | ) |
627 | 627 | ); |
628 | 628 | } |
629 | 629 | //now we need to determine if the event has any tickets on sale. If not then we dont' show the error |
630 | - if ( ! $event->tickets_on_sale() ) { |
|
630 | + if ( ! $event->tickets_on_sale()) { |
|
631 | 631 | return; |
632 | 632 | } |
633 | 633 | //made it here so show warning |
634 | - EE_Error::add_attention( $this->_edit_event_warning() ); |
|
634 | + EE_Error::add_attention($this->_edit_event_warning()); |
|
635 | 635 | } |
636 | 636 | |
637 | 637 | |
@@ -671,7 +671,7 @@ discard block |
||
671 | 671 | ), |
672 | 672 | ); |
673 | 673 | |
674 | - if ( EE_Registry::instance()->CAP->current_user_can( 'ee_delete_events', 'espresso_events_trash_events' ) ) { |
|
674 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_events', 'espresso_events_trash_events')) { |
|
675 | 675 | $this->_views['trash'] = array( |
676 | 676 | 'slug' => 'trash', |
677 | 677 | 'label' => __('Trash', 'event_espresso'), |
@@ -701,39 +701,39 @@ discard block |
||
701 | 701 | 'desc' => __('View Registrations for Event', 'event_espresso') |
702 | 702 | ) |
703 | 703 | ); |
704 | - $items = apply_filters( 'FHEE__Events_Admin_Page___event_legend_items__items', $items ); |
|
704 | + $items = apply_filters('FHEE__Events_Admin_Page___event_legend_items__items', $items); |
|
705 | 705 | $statuses = array( |
706 | 706 | 'sold_out_status' => array( |
707 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::sold_out, |
|
708 | - 'desc' => EEH_Template::pretty_status( EE_Datetime::sold_out, FALSE, 'sentence' ) |
|
707 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::sold_out, |
|
708 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::sold_out, FALSE, 'sentence') |
|
709 | 709 | ), |
710 | 710 | 'active_status' => array( |
711 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::active, |
|
712 | - 'desc' => EEH_Template::pretty_status( EE_Datetime::active, FALSE, 'sentence' ) |
|
711 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::active, |
|
712 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::active, FALSE, 'sentence') |
|
713 | 713 | ), |
714 | 714 | 'upcoming_status' => array( |
715 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::upcoming, |
|
716 | - 'desc' => EEH_Template::pretty_status( EE_Datetime::upcoming, FALSE, 'sentence' ) |
|
715 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::upcoming, |
|
716 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::upcoming, FALSE, 'sentence') |
|
717 | 717 | ), |
718 | 718 | 'postponed_status' => array( |
719 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::postponed, |
|
720 | - 'desc' => EEH_Template::pretty_status( EE_Datetime::postponed, FALSE, 'sentence' ) |
|
719 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::postponed, |
|
720 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::postponed, FALSE, 'sentence') |
|
721 | 721 | ), |
722 | 722 | 'cancelled_status' => array( |
723 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::cancelled, |
|
724 | - 'desc' => EEH_Template::pretty_status( EE_Datetime::cancelled, FALSE, 'sentence' ) |
|
723 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::cancelled, |
|
724 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::cancelled, FALSE, 'sentence') |
|
725 | 725 | ), |
726 | 726 | 'expired_status' => array( |
727 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::expired, |
|
728 | - 'desc' => EEH_Template::pretty_status( EE_Datetime::expired, FALSE, 'sentence' ) |
|
727 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::expired, |
|
728 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::expired, FALSE, 'sentence') |
|
729 | 729 | ), |
730 | 730 | 'inactive_status' => array( |
731 | - 'class' => 'ee-status-legend ee-status-legend-' . EE_Datetime::inactive, |
|
732 | - 'desc' => EEH_Template::pretty_status( EE_Datetime::inactive, FALSE, 'sentence' ) |
|
731 | + 'class' => 'ee-status-legend ee-status-legend-'.EE_Datetime::inactive, |
|
732 | + 'desc' => EEH_Template::pretty_status(EE_Datetime::inactive, FALSE, 'sentence') |
|
733 | 733 | ) |
734 | 734 | ); |
735 | - $statuses = apply_filters( 'FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses ); |
|
736 | - return array_merge( $items, $statuses ); |
|
735 | + $statuses = apply_filters('FHEE__Events_Admin_Page__event_legend_items__statuses', $statuses); |
|
736 | + return array_merge($items, $statuses); |
|
737 | 737 | } |
738 | 738 | |
739 | 739 | |
@@ -745,8 +745,8 @@ discard block |
||
745 | 745 | * @return EEM_Event |
746 | 746 | */ |
747 | 747 | private function _event_model() { |
748 | - if ( ! $this->_event_model instanceof EEM_Event ) { |
|
749 | - $this->_event_model = EE_Registry::instance()->load_model( 'Event' ); |
|
748 | + if ( ! $this->_event_model instanceof EEM_Event) { |
|
749 | + $this->_event_model = EE_Registry::instance()->load_model('Event'); |
|
750 | 750 | } |
751 | 751 | return $this->_event_model; |
752 | 752 | } |
@@ -765,12 +765,12 @@ discard block |
||
765 | 765 | * @param string $new_slug what the slug is |
766 | 766 | * @return string The new html string for the permalink area |
767 | 767 | */ |
768 | - public function extra_permalink_field_buttons( $return, $id, $new_title, $new_slug ) { |
|
768 | + public function extra_permalink_field_buttons($return, $id, $new_title, $new_slug) { |
|
769 | 769 | //make sure this is only when editing |
770 | - if ( !empty( $id ) ) { |
|
771 | - $post = get_post( $id ); |
|
772 | - $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#" tabindex="-1">' . __('Shortcode', 'event_espresso') . '</a> '; |
|
773 | - $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id=\'' . $post->ID . '\']"">'; |
|
770 | + if ( ! empty($id)) { |
|
771 | + $post = get_post($id); |
|
772 | + $return .= '<a class="button button-small" onclick="prompt(\'Shortcode:\', jQuery(\'#shortcode\').val()); return false;" href="#" tabindex="-1">'.__('Shortcode', 'event_espresso').'</a> '; |
|
773 | + $return .= '<input id="shortcode" type="hidden" value="[ESPRESSO_TICKET_SELECTOR event_id=\''.$post->ID.'\']"">'; |
|
774 | 774 | } |
775 | 775 | return $return; |
776 | 776 | } |
@@ -786,8 +786,8 @@ discard block |
||
786 | 786 | * @return string html for generated table |
787 | 787 | */ |
788 | 788 | protected function _events_overview_list_table() { |
789 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
790 | - $this->_template_args['after_list_table'] = EEH_Template::get_button_or_link( get_post_type_archive_link('espresso_events'), __("View Event Archive Page", "event_espresso"), 'button' ) . |
|
789 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
790 | + $this->_template_args['after_list_table'] = EEH_Template::get_button_or_link(get_post_type_archive_link('espresso_events'), __("View Event Archive Page", "event_espresso"), 'button'). |
|
791 | 791 | $this->_display_legend($this->_event_legend_items()); |
792 | 792 | $this->_admin_page_title .= $this->get_action_link_or_button('create_new', 'add', array(), 'add-new-h2'); |
793 | 793 | $this->display_admin_list_table_page_with_no_sidebar(); |
@@ -805,51 +805,51 @@ discard block |
||
805 | 805 | |
806 | 806 | |
807 | 807 | |
808 | - protected function _insert_update_cpt_item( $post_id, $post ) { |
|
808 | + protected function _insert_update_cpt_item($post_id, $post) { |
|
809 | 809 | |
810 | - if ( $post instanceof WP_Post && $post->post_type !== 'espresso_events' ) { |
|
810 | + if ($post instanceof WP_Post && $post->post_type !== 'espresso_events') { |
|
811 | 811 | //getout we're not processing an event save. |
812 | 812 | return; |
813 | 813 | } |
814 | 814 | |
815 | 815 | $event_values = array( |
816 | - 'EVT_display_desc' => !empty( $this->_req_data['display_desc'] ) ? 1 : 0, |
|
817 | - 'EVT_display_ticket_selector' => !empty( $this->_req_data['display_ticket_selector'] ) ? 1 : 0, |
|
816 | + 'EVT_display_desc' => ! empty($this->_req_data['display_desc']) ? 1 : 0, |
|
817 | + 'EVT_display_ticket_selector' => ! empty($this->_req_data['display_ticket_selector']) ? 1 : 0, |
|
818 | 818 | 'EVT_additional_limit' => min( |
819 | - apply_filters( 'FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255 ), |
|
820 | - !empty( $this->_req_data['additional_limit'] ) ? $this->_req_data['additional_limit'] : NULL ), |
|
821 | - 'EVT_default_registration_status' => !empty( $this->_req_data['EVT_default_registration_status'] ) ? $this->_req_data['EVT_default_registration_status'] : EE_Registry::instance()->CFG->registration->default_STS_ID, |
|
822 | - 'EVT_member_only' => !empty( $this->_req_data['member_only'] ) ? 1 : 0, |
|
823 | - 'EVT_allow_overflow' => !empty( $this->_req_data['EVT_allow_overflow'] ) ? 1 : 0, |
|
824 | - 'EVT_timezone_string' => !empty( $this->_req_data['timezone_string'] ) ? $this->_req_data['timezone_string'] : NULL, |
|
825 | - 'EVT_external_URL' => !empty( $this->_req_data['externalURL'] ) ? $this->_req_data['externalURL'] : NULL, |
|
826 | - 'EVT_phone' => !empty( $this->_req_data['event_phone'] ) ? $this->_req_data['event_phone'] : NULL |
|
819 | + apply_filters('FHEE__EE_Events_Admin__insert_update_cpt_item__EVT_additional_limit_max', 255), |
|
820 | + ! empty($this->_req_data['additional_limit']) ? $this->_req_data['additional_limit'] : NULL ), |
|
821 | + 'EVT_default_registration_status' => ! empty($this->_req_data['EVT_default_registration_status']) ? $this->_req_data['EVT_default_registration_status'] : EE_Registry::instance()->CFG->registration->default_STS_ID, |
|
822 | + 'EVT_member_only' => ! empty($this->_req_data['member_only']) ? 1 : 0, |
|
823 | + 'EVT_allow_overflow' => ! empty($this->_req_data['EVT_allow_overflow']) ? 1 : 0, |
|
824 | + 'EVT_timezone_string' => ! empty($this->_req_data['timezone_string']) ? $this->_req_data['timezone_string'] : NULL, |
|
825 | + 'EVT_external_URL' => ! empty($this->_req_data['externalURL']) ? $this->_req_data['externalURL'] : NULL, |
|
826 | + 'EVT_phone' => ! empty($this->_req_data['event_phone']) ? $this->_req_data['event_phone'] : NULL |
|
827 | 827 | ); |
828 | 828 | |
829 | 829 | //update event |
830 | - $success = $this->_event_model()->update_by_ID( $event_values, $post_id ); |
|
830 | + $success = $this->_event_model()->update_by_ID($event_values, $post_id); |
|
831 | 831 | |
832 | 832 | |
833 | 833 | //get event_object for other metaboxes... though it would seem to make sense to just use $this->_event_model()->get_one_by_ID( $post_id ).. i have to setup where conditions to override the filters in the model that filter out autodraft and inherit statuses so we GET the inherit id! |
834 | - $get_one_where = array( $this->_event_model()->primary_key_name() => $post_id, 'status' => $post->post_status ); |
|
835 | - $event = $this->_event_model()->get_one( array($get_one_where) ); |
|
834 | + $get_one_where = array($this->_event_model()->primary_key_name() => $post_id, 'status' => $post->post_status); |
|
835 | + $event = $this->_event_model()->get_one(array($get_one_where)); |
|
836 | 836 | |
837 | 837 | |
838 | 838 | //the following are default callbacks for event attachment updates that can be overridden by caffeinated functionality and/or addons. |
839 | - $event_update_callbacks = apply_filters( 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', array( array($this, '_default_venue_update' ), array( $this, '_default_tickets_update') ) ); |
|
839 | + $event_update_callbacks = apply_filters('FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', array(array($this, '_default_venue_update'), array($this, '_default_tickets_update'))); |
|
840 | 840 | |
841 | 841 | $att_success = TRUE; |
842 | 842 | |
843 | - foreach ( $event_update_callbacks as $e_callback ) { |
|
844 | - $_succ = call_user_func_array( $e_callback, array( $event, $this->_req_data ) ); |
|
845 | - $att_success = !$att_success ? $att_success : $_succ; //if ANY of these updates fail then we want the appropriate global error message |
|
843 | + foreach ($event_update_callbacks as $e_callback) { |
|
844 | + $_succ = call_user_func_array($e_callback, array($event, $this->_req_data)); |
|
845 | + $att_success = ! $att_success ? $att_success : $_succ; //if ANY of these updates fail then we want the appropriate global error message |
|
846 | 846 | } |
847 | 847 | |
848 | 848 | //any errors? |
849 | - if ( $success && FALSE === $att_success ) { |
|
850 | - EE_Error::add_error( __('Event Details saved successfully but something went wrong with saving attachments.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ ); |
|
851 | - } else if ( $success === FALSE ) { |
|
852 | - EE_Error::add_error( __('Event Details did not save successfully.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__ ); |
|
849 | + if ($success && FALSE === $att_success) { |
|
850 | + EE_Error::add_error(__('Event Details saved successfully but something went wrong with saving attachments.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
851 | + } else if ($success === FALSE) { |
|
852 | + EE_Error::add_error(__('Event Details did not save successfully.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
853 | 853 | } |
854 | 854 | } |
855 | 855 | |
@@ -859,14 +859,14 @@ discard block |
||
859 | 859 | /** |
860 | 860 | * @see parent::restore_item() |
861 | 861 | */ |
862 | - protected function _restore_cpt_item( $post_id, $revision_id ) { |
|
862 | + protected function _restore_cpt_item($post_id, $revision_id) { |
|
863 | 863 | //copy existing event meta to new post |
864 | 864 | $post_evt = $this->_event_model()->get_one_by_ID($post_id); |
865 | - if ( $post_evt instanceof EE_Event ) { |
|
865 | + if ($post_evt instanceof EE_Event) { |
|
866 | 866 | //meta revision restore |
867 | - $post_evt->restore_revision( $revision_id ); |
|
867 | + $post_evt->restore_revision($revision_id); |
|
868 | 868 | //related objs restore |
869 | - $post_evt->restore_revision( $revision_id, array( 'Venue', 'Datetime', 'Price' ) ); |
|
869 | + $post_evt->restore_revision($revision_id, array('Venue', 'Datetime', 'Price')); |
|
870 | 870 | } |
871 | 871 | } |
872 | 872 | |
@@ -879,52 +879,52 @@ discard block |
||
879 | 879 | * @param array $data The request data from the form |
880 | 880 | * @return bool Success or fail. |
881 | 881 | */ |
882 | - protected function _default_venue_update( $evtobj, $data ) { |
|
883 | - require_once( EE_MODELS . 'EEM_Venue.model.php' ); |
|
882 | + protected function _default_venue_update($evtobj, $data) { |
|
883 | + require_once(EE_MODELS.'EEM_Venue.model.php'); |
|
884 | 884 | $venue_model = EE_Registry::instance()->load_model('Venue'); |
885 | 885 | $rows_affected = NULL; |
886 | - $venue_id = !empty( $data['venue_id'] ) ? $data['venue_id'] : NULL; |
|
886 | + $venue_id = ! empty($data['venue_id']) ? $data['venue_id'] : NULL; |
|
887 | 887 | |
888 | 888 | // very important. If we don't have a venue name... |
889 | 889 | // then we'll get out because not necessary to create empty venue |
890 | - if ( empty( $data['venue_title'] ) ) { |
|
890 | + if (empty($data['venue_title'])) { |
|
891 | 891 | return false; |
892 | 892 | } |
893 | 893 | |
894 | 894 | $venue_array = array( |
895 | 895 | 'VNU_wp_user' => $evtobj->get('EVT_wp_user'), |
896 | - 'VNU_name' => !empty( $data['venue_title'] ) ? $data['venue_title'] : NULL, |
|
897 | - 'VNU_desc' => !empty( $data['venue_description'] ) ? $data['venue_description'] : NULL, |
|
898 | - 'VNU_identifier' => !empty( $data['venue_identifier'] ) ? $data['venue_identifier'] : NULL, |
|
899 | - 'VNU_short_desc' => !empty( $data['venue_short_description'] ) ? $data['venue_short_description'] : NULL, |
|
900 | - 'VNU_address' => !empty( $data['address'] ) ? $data['address'] : NULL, |
|
901 | - 'VNU_address2' => !empty( $data['address2'] ) ? $data['address2'] : NULL, |
|
902 | - 'VNU_city' => !empty( $data['city'] ) ? $data['city'] : NULL, |
|
903 | - 'STA_ID' => !empty( $data['state'] ) ? $data['state'] : NULL, |
|
904 | - 'CNT_ISO' => !empty( $data['countries'] ) ? $data['countries'] : NULL, |
|
905 | - 'VNU_zip' => !empty( $data['zip'] ) ? $data['zip'] : NULL, |
|
906 | - 'VNU_phone' => !empty( $data['venue_phone'] ) ? $data['venue_phone'] : NULL, |
|
907 | - 'VNU_capacity' => !empty( $data['venue_capacity'] ) ? $data['venue_capacity'] : NULL, |
|
908 | - 'VNU_url' => !empty($data['venue_url'] ) ? $data['venue_url'] : NULL, |
|
909 | - 'VNU_virtual_phone' => !empty($data['virtual_phone']) ? $data['virtual_phone'] : NULL, |
|
910 | - 'VNU_virtual_url' => !empty( $data['virtual_url'] ) ? $data['virtual_url'] : NULL, |
|
911 | - 'VNU_enable_for_gmap' => isset( $data['enable_for_gmap'] ) ? 1 : 0, |
|
896 | + 'VNU_name' => ! empty($data['venue_title']) ? $data['venue_title'] : NULL, |
|
897 | + 'VNU_desc' => ! empty($data['venue_description']) ? $data['venue_description'] : NULL, |
|
898 | + 'VNU_identifier' => ! empty($data['venue_identifier']) ? $data['venue_identifier'] : NULL, |
|
899 | + 'VNU_short_desc' => ! empty($data['venue_short_description']) ? $data['venue_short_description'] : NULL, |
|
900 | + 'VNU_address' => ! empty($data['address']) ? $data['address'] : NULL, |
|
901 | + 'VNU_address2' => ! empty($data['address2']) ? $data['address2'] : NULL, |
|
902 | + 'VNU_city' => ! empty($data['city']) ? $data['city'] : NULL, |
|
903 | + 'STA_ID' => ! empty($data['state']) ? $data['state'] : NULL, |
|
904 | + 'CNT_ISO' => ! empty($data['countries']) ? $data['countries'] : NULL, |
|
905 | + 'VNU_zip' => ! empty($data['zip']) ? $data['zip'] : NULL, |
|
906 | + 'VNU_phone' => ! empty($data['venue_phone']) ? $data['venue_phone'] : NULL, |
|
907 | + 'VNU_capacity' => ! empty($data['venue_capacity']) ? $data['venue_capacity'] : NULL, |
|
908 | + 'VNU_url' => ! empty($data['venue_url']) ? $data['venue_url'] : NULL, |
|
909 | + 'VNU_virtual_phone' => ! empty($data['virtual_phone']) ? $data['virtual_phone'] : NULL, |
|
910 | + 'VNU_virtual_url' => ! empty($data['virtual_url']) ? $data['virtual_url'] : NULL, |
|
911 | + 'VNU_enable_for_gmap' => isset($data['enable_for_gmap']) ? 1 : 0, |
|
912 | 912 | 'status' => 'publish' |
913 | 913 | ); |
914 | 914 | |
915 | 915 | |
916 | 916 | //if we've got the venue_id then we're just updating the existing venue so let's do that and then get out. |
917 | - if ( !empty( $venue_id ) ) { |
|
918 | - $update_where = array( $venue_model->primary_key_name() => $venue_id ); |
|
919 | - $rows_affected = $venue_model->update( $venue_array, array( $update_where ) ); |
|
917 | + if ( ! empty($venue_id)) { |
|
918 | + $update_where = array($venue_model->primary_key_name() => $venue_id); |
|
919 | + $rows_affected = $venue_model->update($venue_array, array($update_where)); |
|
920 | 920 | //we've gotta make sure that the venue is always attached to a revision.. add_relation_to should take care of making sure that the relation is already present. |
921 | - $evtobj->_add_relation_to( $venue_id, 'Venue' ); |
|
921 | + $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
922 | 922 | return $rows_affected > 0 ? TRUE : FALSE; |
923 | 923 | } else { |
924 | 924 | //we insert the venue |
925 | - $venue_id = $venue_model->insert( $venue_array ); |
|
926 | - $evtobj->_add_relation_to( $venue_id, 'Venue' ); |
|
927 | - return !empty( $venue_id ) ? TRUE : FALSE; |
|
925 | + $venue_id = $venue_model->insert($venue_array); |
|
926 | + $evtobj->_add_relation_to($venue_id, 'Venue'); |
|
927 | + return ! empty($venue_id) ? TRUE : FALSE; |
|
928 | 928 | } |
929 | 929 | //when we have the ancestor come in it's already been handled by the revision save. |
930 | 930 | } |
@@ -938,55 +938,55 @@ discard block |
||
938 | 938 | * @param array $data The request data from the form |
939 | 939 | * @return bool success or fail |
940 | 940 | */ |
941 | - protected function _default_tickets_update( EE_Event $evtobj, $data ) { |
|
941 | + protected function _default_tickets_update(EE_Event $evtobj, $data) { |
|
942 | 942 | $success = true; |
943 | 943 | $saved_dtt = null; |
944 | 944 | $saved_tickets = array(); |
945 | - $incoming_date_formats = array( 'Y-m-d', 'h:i a' ); |
|
945 | + $incoming_date_formats = array('Y-m-d', 'h:i a'); |
|
946 | 946 | |
947 | - foreach ( $data['edit_event_datetimes'] as $row => $dtt ) { |
|
947 | + foreach ($data['edit_event_datetimes'] as $row => $dtt) { |
|
948 | 948 | //trim all values to ensure any excess whitespace is removed. |
949 | - $dtt = array_map( 'trim', $dtt ); |
|
950 | - $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty( $dtt['DTT_EVT_end'] ) ? $dtt['DTT_EVT_end'] : $dtt['DTT_EVT_start']; |
|
949 | + $dtt = array_map('trim', $dtt); |
|
950 | + $dtt['DTT_EVT_end'] = isset($dtt['DTT_EVT_end']) && ! empty($dtt['DTT_EVT_end']) ? $dtt['DTT_EVT_end'] : $dtt['DTT_EVT_start']; |
|
951 | 951 | $datetime_values = array( |
952 | - 'DTT_ID' => ! empty( $dtt['DTT_ID'] ) ? $dtt['DTT_ID'] : NULL, |
|
952 | + 'DTT_ID' => ! empty($dtt['DTT_ID']) ? $dtt['DTT_ID'] : NULL, |
|
953 | 953 | 'DTT_EVT_start' => $dtt['DTT_EVT_start'], |
954 | 954 | 'DTT_EVT_end' => $dtt['DTT_EVT_end'], |
955 | - 'DTT_reg_limit' => empty( $dtt['DTT_reg_limit'] ) ? EE_INF : $dtt['DTT_reg_limit'], |
|
955 | + 'DTT_reg_limit' => empty($dtt['DTT_reg_limit']) ? EE_INF : $dtt['DTT_reg_limit'], |
|
956 | 956 | 'DTT_order' => $row, |
957 | 957 | ); |
958 | 958 | |
959 | 959 | //if we have an id then let's get existing object first and then set the new values. Otherwise we instantiate a new object for save. |
960 | 960 | |
961 | - if ( !empty( $dtt['DTT_ID'] ) ) { |
|
962 | - $DTM = EE_Registry::instance()->load_model('Datetime', array( $evtobj->get_timezone() ) )->get_one_by_ID($dtt['DTT_ID'] ); |
|
963 | - $DTM->set_date_format( $incoming_date_formats[0] ); |
|
964 | - $DTM->set_time_format( $incoming_date_formats[1] ); |
|
965 | - foreach ( $datetime_values as $field => $value ) { |
|
966 | - $DTM->set( $field, $value ); |
|
961 | + if ( ! empty($dtt['DTT_ID'])) { |
|
962 | + $DTM = EE_Registry::instance()->load_model('Datetime', array($evtobj->get_timezone()))->get_one_by_ID($dtt['DTT_ID']); |
|
963 | + $DTM->set_date_format($incoming_date_formats[0]); |
|
964 | + $DTM->set_time_format($incoming_date_formats[1]); |
|
965 | + foreach ($datetime_values as $field => $value) { |
|
966 | + $DTM->set($field, $value); |
|
967 | 967 | } |
968 | 968 | |
969 | 969 | //make sure the $dtt_id here is saved just in case after the add_relation_to() the autosave replaces it. We need to do this so we dont' TRASH the parent DTT. |
970 | 970 | $saved_dtts[$DTM->ID()] = $DTM; |
971 | 971 | } else { |
972 | - $DTM = EE_Registry::instance()->load_class('Datetime', array( $datetime_values ), FALSE, FALSE ); |
|
973 | - $DTM->set_date_format( $incoming_date_formats[0] ); |
|
974 | - $DTM->set_time_format( $incoming_date_formats[1] ); |
|
975 | - $DTM->set_timezone( $evtobj->get_timezone() ); |
|
976 | - foreach ( $datetime_values as $field => $value ) { |
|
977 | - $DTM->set( $field, $value ); |
|
972 | + $DTM = EE_Registry::instance()->load_class('Datetime', array($datetime_values), FALSE, FALSE); |
|
973 | + $DTM->set_date_format($incoming_date_formats[0]); |
|
974 | + $DTM->set_time_format($incoming_date_formats[1]); |
|
975 | + $DTM->set_timezone($evtobj->get_timezone()); |
|
976 | + foreach ($datetime_values as $field => $value) { |
|
977 | + $DTM->set($field, $value); |
|
978 | 978 | } |
979 | 979 | } |
980 | 980 | $DTM->save(); |
981 | 981 | |
982 | - $DTT = $evtobj->_add_relation_to( $DTM, 'Datetime' ); |
|
982 | + $DTT = $evtobj->_add_relation_to($DTM, 'Datetime'); |
|
983 | 983 | |
984 | 984 | //load DTT helper |
985 | 985 | EE_Registry::instance()->load_helper('DTT_Helper'); |
986 | 986 | |
987 | 987 | //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
988 | - if( $DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end') ) { |
|
989 | - $DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start') ); |
|
988 | + if ($DTT->get_raw('DTT_EVT_start') > $DTT->get_raw('DTT_EVT_end')) { |
|
989 | + $DTT->set('DTT_EVT_end', $DTT->get('DTT_EVT_start')); |
|
990 | 990 | $DTT = EEH_DTT_Helper::date_time_add($DTT, 'DTT_EVT_end', 'days'); |
991 | 991 | $DTT->save(); |
992 | 992 | } |
@@ -994,45 +994,45 @@ discard block |
||
994 | 994 | //now we got to make sure we add the new DTT_ID to the $saved_dtts array because it is possible there was a new one created for the autosave. |
995 | 995 | $saved_dtt = $DTT; |
996 | 996 | |
997 | - $success = !$success ? $success : $DTT; //if ANY of these updates fail then we want the appropriate global error message. //todod this is actually sucky we need a better error message but this is what it is for now. |
|
997 | + $success = ! $success ? $success : $DTT; //if ANY of these updates fail then we want the appropriate global error message. //todod this is actually sucky we need a better error message but this is what it is for now. |
|
998 | 998 | } |
999 | 999 | |
1000 | 1000 | //no dtts get deleted so we don't do any of that logic here. |
1001 | 1001 | //update tickets next |
1002 | - $old_tickets = isset( $data['ticket_IDs'] ) ? explode(',', $data['ticket_IDs'] ) : array(); |
|
1003 | - foreach ( $data['edit_tickets'] as $row => $tkt ) { |
|
1004 | - $incoming_date_formats = array( 'Y-m-d', 'h:i a' ); |
|
1002 | + $old_tickets = isset($data['ticket_IDs']) ? explode(',', $data['ticket_IDs']) : array(); |
|
1003 | + foreach ($data['edit_tickets'] as $row => $tkt) { |
|
1004 | + $incoming_date_formats = array('Y-m-d', 'h:i a'); |
|
1005 | 1005 | $update_prices = false; |
1006 | - $ticket_price = isset( $data['edit_prices'][$row][1]['PRC_amount'] ) ? $data['edit_prices'][$row][1]['PRC_amount'] : 0; |
|
1006 | + $ticket_price = isset($data['edit_prices'][$row][1]['PRC_amount']) ? $data['edit_prices'][$row][1]['PRC_amount'] : 0; |
|
1007 | 1007 | |
1008 | 1008 | // trim inputs to ensure any excess whitespace is removed. |
1009 | - $tkt = array_map( 'trim', $tkt ); |
|
1009 | + $tkt = array_map('trim', $tkt); |
|
1010 | 1010 | |
1011 | - if ( empty( $tkt['TKT_start_date'] ) ) { |
|
1011 | + if (empty($tkt['TKT_start_date'])) { |
|
1012 | 1012 | //let's use now in the set timezone. |
1013 | - $now = new DateTime( 'now', new DateTimeZone( $evtobj->get_timezone() ) ); |
|
1014 | - $tkt['TKT_start_date'] = $now->format( $incoming_date_formats[0] . ' ' . $incoming_date_formats[1] ); |
|
1013 | + $now = new DateTime('now', new DateTimeZone($evtobj->get_timezone())); |
|
1014 | + $tkt['TKT_start_date'] = $now->format($incoming_date_formats[0].' '.$incoming_date_formats[1]); |
|
1015 | 1015 | } |
1016 | 1016 | |
1017 | - if ( empty( $tkt['TKT_end_date'] ) ) { |
|
1017 | + if (empty($tkt['TKT_end_date'])) { |
|
1018 | 1018 | //use the start date of the first datetime |
1019 | 1019 | $dtt = $evtobj->first_datetime(); |
1020 | - $tkt['TKT_end_date'] = $dtt->start_date_and_time( $incoming_date_formats[0], $incoming_date_formats[1] ); |
|
1020 | + $tkt['TKT_end_date'] = $dtt->start_date_and_time($incoming_date_formats[0], $incoming_date_formats[1]); |
|
1021 | 1021 | } |
1022 | 1022 | |
1023 | 1023 | $TKT_values = array( |
1024 | - 'TKT_ID' => !empty( $tkt['TKT_ID'] ) ? $tkt['TKT_ID'] : NULL, |
|
1025 | - 'TTM_ID' => !empty( $tkt['TTM_ID'] ) ? $tkt['TTM_ID'] : 0, |
|
1026 | - 'TKT_name' => !empty( $tkt['TKT_name'] ) ? $tkt['TKT_name'] : '', |
|
1027 | - 'TKT_description' => !empty( $tkt['TKT_description'] ) ? $tkt['TKT_description'] : '', |
|
1024 | + 'TKT_ID' => ! empty($tkt['TKT_ID']) ? $tkt['TKT_ID'] : NULL, |
|
1025 | + 'TTM_ID' => ! empty($tkt['TTM_ID']) ? $tkt['TTM_ID'] : 0, |
|
1026 | + 'TKT_name' => ! empty($tkt['TKT_name']) ? $tkt['TKT_name'] : '', |
|
1027 | + 'TKT_description' => ! empty($tkt['TKT_description']) ? $tkt['TKT_description'] : '', |
|
1028 | 1028 | 'TKT_start_date' => $tkt['TKT_start_date'], |
1029 | 1029 | 'TKT_end_date' => $tkt['TKT_end_date'], |
1030 | - 'TKT_qty' => ! isset( $tkt[ 'TKT_qty' ] ) || $tkt[ 'TKT_qty' ] === '' ? EE_INF : $tkt['TKT_qty'], |
|
1031 | - 'TKT_uses' => ! isset( $tkt[ 'TKT_uses' ] ) || $tkt[ 'TKT_uses' ] === '' ? EE_INF : $tkt[ 'TKT_uses' ], |
|
1032 | - 'TKT_min' => empty( $tkt['TKT_min'] ) ? 0 : $tkt['TKT_min'], |
|
1033 | - 'TKT_max' => empty( $tkt['TKT_max'] ) ? EE_INF : $tkt['TKT_max'], |
|
1030 | + 'TKT_qty' => ! isset($tkt['TKT_qty']) || $tkt['TKT_qty'] === '' ? EE_INF : $tkt['TKT_qty'], |
|
1031 | + 'TKT_uses' => ! isset($tkt['TKT_uses']) || $tkt['TKT_uses'] === '' ? EE_INF : $tkt['TKT_uses'], |
|
1032 | + 'TKT_min' => empty($tkt['TKT_min']) ? 0 : $tkt['TKT_min'], |
|
1033 | + 'TKT_max' => empty($tkt['TKT_max']) ? EE_INF : $tkt['TKT_max'], |
|
1034 | 1034 | 'TKT_row' => $row, |
1035 | - 'TKT_order' => isset( $tkt['TKT_order'] ) ? $tkt['TKT_order'] : $row, |
|
1035 | + 'TKT_order' => isset($tkt['TKT_order']) ? $tkt['TKT_order'] : $row, |
|
1036 | 1036 | 'TKT_price' => $ticket_price |
1037 | 1037 | ); |
1038 | 1038 | |
@@ -1040,7 +1040,7 @@ discard block |
||
1040 | 1040 | |
1041 | 1041 | |
1042 | 1042 | //if this is a default TKT, then we need to set the TKT_ID to 0 and update accordingly, which means in turn that the prices will become new prices as well. |
1043 | - if ( isset( $tkt['TKT_is_default'] ) && $tkt['TKT_is_default'] ) { |
|
1043 | + if (isset($tkt['TKT_is_default']) && $tkt['TKT_is_default']) { |
|
1044 | 1044 | $TKT_values['TKT_ID'] = 0; |
1045 | 1045 | $TKT_values['TKT_is_default'] = 0; |
1046 | 1046 | $TKT_values['TKT_price'] = $ticket_price; |
@@ -1051,58 +1051,58 @@ discard block |
||
1051 | 1051 | //we actually do our saves a head of doing any add_relations to because its entirely possible that this ticket didn't removed or added to any datetime in the session but DID have it's items modified. |
1052 | 1052 | //keep in mind that if the TKT has been sold (and we have changed pricing information), then we won't be updating the tkt but instead a new tkt will be created and the old one archived. |
1053 | 1053 | |
1054 | - if ( !empty( $tkt['TKT_ID'] ) ) { |
|
1055 | - $TKT = EE_Registry::instance()->load_model( 'Ticket', array( $evtobj->get_timezone() ) )->get_one_by_ID( $tkt['TKT_ID'] ); |
|
1056 | - if ( $TKT instanceof EE_Ticket ) { |
|
1057 | - $ticket_sold = $TKT->count_related( 'Registration', array( array( 'STS_ID' => array( 'NOT IN', array( EEM_Registration::status_id_incomplete ) ) ) ) ) > 0 ? true : false; |
|
1054 | + if ( ! empty($tkt['TKT_ID'])) { |
|
1055 | + $TKT = EE_Registry::instance()->load_model('Ticket', array($evtobj->get_timezone()))->get_one_by_ID($tkt['TKT_ID']); |
|
1056 | + if ($TKT instanceof EE_Ticket) { |
|
1057 | + $ticket_sold = $TKT->count_related('Registration', array(array('STS_ID' => array('NOT IN', array(EEM_Registration::status_id_incomplete))))) > 0 ? true : false; |
|
1058 | 1058 | //let's just check the total price for the existing ticket and determine if it matches the new total price. if they are different then we create a new ticket (if tkts sold) if they aren't different then we go ahead and modify existing ticket. |
1059 | - $create_new_TKT = $ticket_sold && $ticket_price != $TKT->get( 'TKT_price' ) && ! $TKT->get( 'TKT_deleted' ) ? true : false; |
|
1060 | - $TKT->set_date_format( $incoming_date_formats[ 0 ] ); |
|
1061 | - $TKT->set_time_format( $incoming_date_formats[ 1 ] ); |
|
1059 | + $create_new_TKT = $ticket_sold && $ticket_price != $TKT->get('TKT_price') && ! $TKT->get('TKT_deleted') ? true : false; |
|
1060 | + $TKT->set_date_format($incoming_date_formats[0]); |
|
1061 | + $TKT->set_time_format($incoming_date_formats[1]); |
|
1062 | 1062 | //set new values |
1063 | - foreach ( $TKT_values as $field => $value ) { |
|
1064 | - if ( $field == 'TKT_qty' ) { |
|
1065 | - $TKT->set_qty( $value ); |
|
1063 | + foreach ($TKT_values as $field => $value) { |
|
1064 | + if ($field == 'TKT_qty') { |
|
1065 | + $TKT->set_qty($value); |
|
1066 | 1066 | } else { |
1067 | - $TKT->set( $field, $value ); |
|
1067 | + $TKT->set($field, $value); |
|
1068 | 1068 | } |
1069 | 1069 | } |
1070 | 1070 | //if $create_new_TKT is false then we can safely update the existing ticket. Otherwise we have to create a new ticket. |
1071 | - if ( $create_new_TKT ) { |
|
1071 | + if ($create_new_TKT) { |
|
1072 | 1072 | //archive the old ticket first |
1073 | - $TKT->set( 'TKT_deleted', 1 ); |
|
1073 | + $TKT->set('TKT_deleted', 1); |
|
1074 | 1074 | $TKT->save(); |
1075 | 1075 | //make sure this ticket is still recorded in our saved_tkts so we don't run it through the regular trash routine. |
1076 | - $saved_tickets[ $TKT->ID() ] = $TKT; |
|
1076 | + $saved_tickets[$TKT->ID()] = $TKT; |
|
1077 | 1077 | //create new ticket that's a copy of the existing except a new id of course (and not archived) AND has the new TKT_price associated with it. |
1078 | 1078 | $TKT = clone $TKT; |
1079 | - $TKT->set( 'TKT_ID', 0 ); |
|
1080 | - $TKT->set( 'TKT_deleted', 0 ); |
|
1081 | - $TKT->set( 'TKT_price', $ticket_price ); |
|
1082 | - $TKT->set( 'TKT_sold', 0 ); |
|
1079 | + $TKT->set('TKT_ID', 0); |
|
1080 | + $TKT->set('TKT_deleted', 0); |
|
1081 | + $TKT->set('TKT_price', $ticket_price); |
|
1082 | + $TKT->set('TKT_sold', 0); |
|
1083 | 1083 | //now we need to make sure that $new prices are created as well and attached to new ticket. |
1084 | 1084 | $update_prices = true; |
1085 | 1085 | } |
1086 | 1086 | //make sure price is set if it hasn't been already |
1087 | - $TKT->set( 'TKT_price', $ticket_price ); |
|
1087 | + $TKT->set('TKT_price', $ticket_price); |
|
1088 | 1088 | } |
1089 | 1089 | |
1090 | 1090 | } else { |
1091 | 1091 | //no TKT_id so a new TKT |
1092 | 1092 | $TKT_values['TKT_price'] = $ticket_price; |
1093 | - $TKT = EE_Registry::instance()->load_class('Ticket', array( $TKT_values ), FALSE, FALSE ); |
|
1094 | - if ( $TKT instanceof EE_Ticket ) { |
|
1093 | + $TKT = EE_Registry::instance()->load_class('Ticket', array($TKT_values), FALSE, FALSE); |
|
1094 | + if ($TKT instanceof EE_Ticket) { |
|
1095 | 1095 | //need to reset values to properly account for the date formats |
1096 | - $TKT->set_date_format( $incoming_date_formats[0] ); |
|
1097 | - $TKT->set_time_format( $incoming_date_formats[1] ); |
|
1098 | - $TKT->set_timezone( $evtobj->get_timezone() ); |
|
1096 | + $TKT->set_date_format($incoming_date_formats[0]); |
|
1097 | + $TKT->set_time_format($incoming_date_formats[1]); |
|
1098 | + $TKT->set_timezone($evtobj->get_timezone()); |
|
1099 | 1099 | |
1100 | 1100 | //set new values |
1101 | - foreach ( $TKT_values as $field => $value ) { |
|
1102 | - if ( $field == 'TKT_qty' ) { |
|
1103 | - $TKT->set_qty( $value ); |
|
1101 | + foreach ($TKT_values as $field => $value) { |
|
1102 | + if ($field == 'TKT_qty') { |
|
1103 | + $TKT->set_qty($value); |
|
1104 | 1104 | } else { |
1105 | - $TKT->set( $field, $value ); |
|
1105 | + $TKT->set($field, $value); |
|
1106 | 1106 | } |
1107 | 1107 | } |
1108 | 1108 | |
@@ -1110,32 +1110,32 @@ discard block |
||
1110 | 1110 | } |
1111 | 1111 | } |
1112 | 1112 | // cap ticket qty by datetime reg limits |
1113 | - $TKT->set_qty( min( $TKT->qty(), $TKT->qty( 'reg_limit' ) ) ); |
|
1113 | + $TKT->set_qty(min($TKT->qty(), $TKT->qty('reg_limit'))); |
|
1114 | 1114 | //update ticket. |
1115 | 1115 | $TKT->save(); |
1116 | 1116 | |
1117 | 1117 | //before going any further make sure our dates are setup correctly so that the end date is always equal or greater than the start date. |
1118 | - if( $TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date') ) { |
|
1119 | - $TKT->set('TKT_end_date', $TKT->get('TKT_start_date') ); |
|
1118 | + if ($TKT->get_raw('TKT_start_date') > $TKT->get_raw('TKT_end_date')) { |
|
1119 | + $TKT->set('TKT_end_date', $TKT->get('TKT_start_date')); |
|
1120 | 1120 | EE_Registry::instance()->load_helper('DTT_Helper'); |
1121 | 1121 | $TKT = EEH_DTT_Helper::date_time_add($TKT, 'TKT_end_date', 'days'); |
1122 | 1122 | $TKT->save(); |
1123 | 1123 | } |
1124 | 1124 | |
1125 | 1125 | //initially let's add the ticket to the dtt |
1126 | - $saved_dtt->_add_relation_to( $TKT, 'Ticket' ); |
|
1126 | + $saved_dtt->_add_relation_to($TKT, 'Ticket'); |
|
1127 | 1127 | |
1128 | 1128 | $saved_tickets[$TKT->ID()] = $TKT; |
1129 | 1129 | |
1130 | 1130 | //add prices to ticket |
1131 | - $this->_add_prices_to_ticket( $data['edit_prices'][$row], $TKT, $update_prices ); |
|
1131 | + $this->_add_prices_to_ticket($data['edit_prices'][$row], $TKT, $update_prices); |
|
1132 | 1132 | } |
1133 | 1133 | //however now we need to handle permanently deleting tickets via the ui. Keep in mind that the ui does not allow deleting/archiving tickets that have ticket sold. However, it does allow for deleting tickets that have no tickets sold, in which case we want to get rid of permanently because there is no need to save in db. |
1134 | - $old_tickets = isset( $old_tickets[0] ) && $old_tickets[0] == '' ? array() : $old_tickets; |
|
1135 | - $tickets_removed = array_diff( $old_tickets, array_keys( $saved_tickets ) ); |
|
1134 | + $old_tickets = isset($old_tickets[0]) && $old_tickets[0] == '' ? array() : $old_tickets; |
|
1135 | + $tickets_removed = array_diff($old_tickets, array_keys($saved_tickets)); |
|
1136 | 1136 | |
1137 | - foreach ( $tickets_removed as $id ) { |
|
1138 | - $id = absint( $id ); |
|
1137 | + foreach ($tickets_removed as $id) { |
|
1138 | + $id = absint($id); |
|
1139 | 1139 | |
1140 | 1140 | //get the ticket for this id |
1141 | 1141 | $tkt_to_remove = EE_Registry::instance()->load_model('Ticket')->get_one_by_ID($id); |
@@ -1143,7 +1143,7 @@ discard block |
||
1143 | 1143 | //need to get all the related datetimes on this ticket and remove from every single one of them (remember this process can ONLY kick off if there are NO tkts_sold) |
1144 | 1144 | $dtts = $tkt_to_remove->get_many_related('Datetime'); |
1145 | 1145 | |
1146 | - foreach( $dtts as $dtt ) { |
|
1146 | + foreach ($dtts as $dtt) { |
|
1147 | 1147 | $tkt_to_remove->_remove_relation_to($dtt, 'Datetime'); |
1148 | 1148 | } |
1149 | 1149 | |
@@ -1154,7 +1154,7 @@ discard block |
||
1154 | 1154 | //finally let's delete this ticket (which should not be blocked at this point b/c we've removed all our relationships) |
1155 | 1155 | $tkt_to_remove->delete_permanently(); |
1156 | 1156 | } |
1157 | - return array( $saved_dtt, $saved_tickets ); |
|
1157 | + return array($saved_dtt, $saved_tickets); |
|
1158 | 1158 | } |
1159 | 1159 | |
1160 | 1160 | |
@@ -1169,31 +1169,31 @@ discard block |
||
1169 | 1169 | * @param bool $new_prices Whether attach existing incoming prices or create new ones. |
1170 | 1170 | * @return void |
1171 | 1171 | */ |
1172 | - private function _add_prices_to_ticket( $prices, EE_Ticket $ticket, $new_prices = FALSE ) { |
|
1173 | - foreach ( $prices as $row => $prc ) { |
|
1172 | + private function _add_prices_to_ticket($prices, EE_Ticket $ticket, $new_prices = FALSE) { |
|
1173 | + foreach ($prices as $row => $prc) { |
|
1174 | 1174 | $PRC_values = array( |
1175 | - 'PRC_ID' => !empty( $prc['PRC_ID'] ) ? $prc['PRC_ID'] : NULL, |
|
1176 | - 'PRT_ID' => !empty( $prc['PRT_ID'] ) ? $prc['PRT_ID'] : NULL, |
|
1177 | - 'PRC_amount' => !empty( $prc['PRC_amount'] ) ? $prc['PRC_amount'] : 0, |
|
1178 | - 'PRC_name' => !empty( $prc['PRC_name'] ) ? $prc['PRC_name'] : '', |
|
1179 | - 'PRC_desc' => !empty( $prc['PRC_desc'] ) ? $prc['PRC_desc'] : '', |
|
1175 | + 'PRC_ID' => ! empty($prc['PRC_ID']) ? $prc['PRC_ID'] : NULL, |
|
1176 | + 'PRT_ID' => ! empty($prc['PRT_ID']) ? $prc['PRT_ID'] : NULL, |
|
1177 | + 'PRC_amount' => ! empty($prc['PRC_amount']) ? $prc['PRC_amount'] : 0, |
|
1178 | + 'PRC_name' => ! empty($prc['PRC_name']) ? $prc['PRC_name'] : '', |
|
1179 | + 'PRC_desc' => ! empty($prc['PRC_desc']) ? $prc['PRC_desc'] : '', |
|
1180 | 1180 | 'PRC_is_default' => 0, //make sure prices are NOT set as default from this context |
1181 | 1181 | 'PRC_order' => $row |
1182 | 1182 | ); |
1183 | 1183 | |
1184 | - if ( $new_prices || empty( $PRC_values['PRC_ID'] ) ) { |
|
1184 | + if ($new_prices || empty($PRC_values['PRC_ID'])) { |
|
1185 | 1185 | $PRC_values['PRC_ID'] = 0; |
1186 | - $PRC = EE_Registry::instance()->load_class('Price', array( $PRC_values ), FALSE, FALSE); |
|
1186 | + $PRC = EE_Registry::instance()->load_class('Price', array($PRC_values), FALSE, FALSE); |
|
1187 | 1187 | } else { |
1188 | - $PRC = EE_Registry::instance()->load_model( 'Price' )->get_one_by_ID( $prc['PRC_ID'] ); |
|
1188 | + $PRC = EE_Registry::instance()->load_model('Price')->get_one_by_ID($prc['PRC_ID']); |
|
1189 | 1189 | //update this price with new values |
1190 | - foreach ( $PRC_values as $field => $newprc ) { |
|
1191 | - $PRC->set( $field, $newprc ); |
|
1190 | + foreach ($PRC_values as $field => $newprc) { |
|
1191 | + $PRC->set($field, $newprc); |
|
1192 | 1192 | } |
1193 | 1193 | $PRC->save(); |
1194 | 1194 | } |
1195 | 1195 | |
1196 | - $ticket->_add_relation_to( $PRC, 'Price' ); |
|
1196 | + $ticket->_add_relation_to($PRC, 'Price'); |
|
1197 | 1197 | } |
1198 | 1198 | } |
1199 | 1199 | |
@@ -1216,33 +1216,33 @@ discard block |
||
1216 | 1216 | |
1217 | 1217 | return; //TEMPORARILY EXITING CAUSE THIS IS A TODO |
1218 | 1218 | |
1219 | - $postid = isset( $this->_req_data['post_ID'] ) ? $this->_req_data['post_ID'] : NULL; |
|
1219 | + $postid = isset($this->_req_data['post_ID']) ? $this->_req_data['post_ID'] : NULL; |
|
1220 | 1220 | |
1221 | 1221 | |
1222 | 1222 | //if no postid then get out cause we need it for stuff in here |
1223 | - if ( empty( $postid ) ) return; |
|
1223 | + if (empty($postid)) return; |
|
1224 | 1224 | |
1225 | 1225 | |
1226 | 1226 | //handle datetime saves |
1227 | 1227 | $items = array(); |
1228 | 1228 | |
1229 | - $get_one_where = array( $this->_event_model()->primary_key_name() => $postid ); |
|
1230 | - $event = $this->_event_model()->get_one( array($get_one_where) ); |
|
1229 | + $get_one_where = array($this->_event_model()->primary_key_name() => $postid); |
|
1230 | + $event = $this->_event_model()->get_one(array($get_one_where)); |
|
1231 | 1231 | |
1232 | 1232 | //now let's get the attached datetimes from the most recent autosave |
1233 | 1233 | $dtts = $event->get_many_related('Datetime'); |
1234 | 1234 | |
1235 | 1235 | $dtt_ids = array(); |
1236 | - foreach( $dtts as $dtt ) { |
|
1236 | + foreach ($dtts as $dtt) { |
|
1237 | 1237 | $dtt_ids[] = $dtt->ID(); |
1238 | 1238 | $order = $dtt->order(); |
1239 | 1239 | $this->_template_args['data']['items']['ID-'.$order] = $dtt->ID(); |
1240 | 1240 | } |
1241 | - $this->_template_args['data']['items']['datetime_IDS'] = serialize( $dtt_ids ); |
|
1241 | + $this->_template_args['data']['items']['datetime_IDS'] = serialize($dtt_ids); |
|
1242 | 1242 | |
1243 | 1243 | //handle DECAF venues |
1244 | 1244 | //we need to make sure that the venue_id gets updated in the form so that future autosaves will properly conntect that venue to the event. |
1245 | - if ( $do_venue_autosaves = apply_filters( 'FHEE__Events_Admin_Page__ee_autosave_edit_do_decaf_venue_save', TRUE ) ) { |
|
1245 | + if ($do_venue_autosaves = apply_filters('FHEE__Events_Admin_Page__ee_autosave_edit_do_decaf_venue_save', TRUE)) { |
|
1246 | 1246 | $venue = $event->get_first_related('Venue'); |
1247 | 1247 | $this->_template_args['data']['items']['venue-id'] = $venue->ID(); |
1248 | 1248 | } |
@@ -1253,23 +1253,23 @@ discard block |
||
1253 | 1253 | |
1254 | 1254 | $ticket_ids = array(); |
1255 | 1255 | $price_ids = array(); |
1256 | - foreach ( $tickets as $ticket ) { |
|
1256 | + foreach ($tickets as $ticket) { |
|
1257 | 1257 | $ticket_ids[] = $price->ID(); |
1258 | 1258 | $ticket_order = $price->get('TKT_order'); |
1259 | - $this->_template_args['data']['items']['edit-ticket-id-' . $ticket_order] = $ticket->ID(); |
|
1260 | - $this->_template_args['data']['items']['edit-ticket-event-id-' . $order] = $event->ID(); |
|
1259 | + $this->_template_args['data']['items']['edit-ticket-id-'.$ticket_order] = $ticket->ID(); |
|
1260 | + $this->_template_args['data']['items']['edit-ticket-event-id-'.$order] = $event->ID(); |
|
1261 | 1261 | |
1262 | 1262 | //now we have to make sure the prices are updated appropriately |
1263 | 1263 | $prices = $ticket->get_many_related('Prices'); |
1264 | 1264 | |
1265 | - foreach ( $prices as $price ) { |
|
1265 | + foreach ($prices as $price) { |
|
1266 | 1266 | $price_ids[] = $price->ID(); |
1267 | 1267 | $price_order = $price->get('PRC_order'); |
1268 | - $this->_template_args['data']['items']['quick-edit-ticket-price-id-ticketrow-' . $ticket_order . '-' . $price_order] = $price->ID(); |
|
1269 | - $this->_template_args['data']['items']['edit-ticket-price-id-ticketrow-' . $ticket_row . '-' . $price_row] = $price->ID(); |
|
1270 | - $this->_template_args['data']['items']['edit-ticket-price-is-default-ticketrow-' . $ticket_row . '-' . $price_row] = $price->get('PRC_is_default'); |
|
1268 | + $this->_template_args['data']['items']['quick-edit-ticket-price-id-ticketrow-'.$ticket_order.'-'.$price_order] = $price->ID(); |
|
1269 | + $this->_template_args['data']['items']['edit-ticket-price-id-ticketrow-'.$ticket_row.'-'.$price_row] = $price->ID(); |
|
1270 | + $this->_template_args['data']['items']['edit-ticket-price-is-default-ticketrow-'.$ticket_row.'-'.$price_row] = $price->get('PRC_is_default'); |
|
1271 | 1271 | } |
1272 | - $this->_template_args['data']['items']['price-IDs-ticketrow-' . $ticket_row] = implode(',', $price_ids); |
|
1272 | + $this->_template_args['data']['items']['price-IDs-ticketrow-'.$ticket_row] = implode(',', $price_ids); |
|
1273 | 1273 | } |
1274 | 1274 | $this->_template_args['data']['items']['ticket-IDs'] = implode(',', $ticket_ids); |
1275 | 1275 | } |
@@ -1287,12 +1287,12 @@ discard block |
||
1287 | 1287 | private function _generate_publish_box_extra_content() { |
1288 | 1288 | |
1289 | 1289 | //load formatter helper |
1290 | - EE_Registry::instance()->load_helper( 'Formatter' ); |
|
1290 | + EE_Registry::instance()->load_helper('Formatter'); |
|
1291 | 1291 | |
1292 | 1292 | //args for getting related registrations |
1293 | - $approved_query_args = array( array( 'REG_deleted' => 0, 'STS_ID' => EEM_Registration::status_id_approved ) ); |
|
1294 | - $not_approved_query_args = array( array( 'REG_deleted' => 0, 'STS_ID' => EEM_Registration::status_id_not_approved ) ); |
|
1295 | - $pending_payment_query_args = array( array( 'REG_deleted' => 0, 'STS_ID' => EEM_Registration::status_id_pending_payment ) ); |
|
1293 | + $approved_query_args = array(array('REG_deleted' => 0, 'STS_ID' => EEM_Registration::status_id_approved)); |
|
1294 | + $not_approved_query_args = array(array('REG_deleted' => 0, 'STS_ID' => EEM_Registration::status_id_not_approved)); |
|
1295 | + $pending_payment_query_args = array(array('REG_deleted' => 0, 'STS_ID' => EEM_Registration::status_id_pending_payment)); |
|
1296 | 1296 | |
1297 | 1297 | |
1298 | 1298 | // publish box |
@@ -1321,9 +1321,9 @@ discard block |
||
1321 | 1321 | ), |
1322 | 1322 | REG_ADMIN_URL |
1323 | 1323 | ), |
1324 | - 'approved_regs' => $this->_cpt_model_obj->count_related( 'Registration', $approved_query_args ), |
|
1325 | - 'not_approved_regs' => $this->_cpt_model_obj->count_related( 'Registration', $not_approved_query_args ), |
|
1326 | - 'pending_payment_regs' => $this->_cpt_model_obj->count_related( 'Registration', $pending_payment_query_args ), |
|
1324 | + 'approved_regs' => $this->_cpt_model_obj->count_related('Registration', $approved_query_args), |
|
1325 | + 'not_approved_regs' => $this->_cpt_model_obj->count_related('Registration', $not_approved_query_args), |
|
1326 | + 'pending_payment_regs' => $this->_cpt_model_obj->count_related('Registration', $pending_payment_query_args), |
|
1327 | 1327 | 'misc_pub_section_class' => apply_filters( |
1328 | 1328 | 'FHEE_Events_Admin_Page___generate_publish_box_extra_content__misc_pub_section_class', |
1329 | 1329 | 'misc-pub-section' |
@@ -1342,9 +1342,9 @@ discard block |
||
1342 | 1342 | 'AHEE__Events_Admin_Page___generate_publish_box_extra_content__event_editor_overview_add', |
1343 | 1343 | $this->_cpt_model_obj |
1344 | 1344 | ); |
1345 | - $publish_box_extra_args[ 'event_editor_overview_add' ] = ob_get_clean(); |
|
1345 | + $publish_box_extra_args['event_editor_overview_add'] = ob_get_clean(); |
|
1346 | 1346 | // load template |
1347 | - EEH_Template::display_template( EVENTS_TEMPLATE_PATH . 'event_publish_box_extras.template.php', $publish_box_extra_args ); |
|
1347 | + EEH_Template::display_template(EVENTS_TEMPLATE_PATH.'event_publish_box_extras.template.php', $publish_box_extra_args); |
|
1348 | 1348 | } |
1349 | 1349 | |
1350 | 1350 | |
@@ -1376,16 +1376,16 @@ discard block |
||
1376 | 1376 | $this->verify_cpt_object(); |
1377 | 1377 | add_meta_box( |
1378 | 1378 | 'espresso_event_editor_tickets', |
1379 | - __( 'Event Datetime & Ticket', 'event_espresso' ), |
|
1380 | - array( $this, 'ticket_metabox' ), |
|
1379 | + __('Event Datetime & Ticket', 'event_espresso'), |
|
1380 | + array($this, 'ticket_metabox'), |
|
1381 | 1381 | $this->page_slug, |
1382 | 1382 | 'normal', |
1383 | 1383 | 'high' |
1384 | 1384 | ); |
1385 | 1385 | add_meta_box( |
1386 | 1386 | 'espresso_event_editor_event_options', |
1387 | - __( 'Event Registration Options', 'event_espresso' ), |
|
1388 | - array( $this, 'registration_options_meta_box' ), |
|
1387 | + __('Event Registration Options', 'event_espresso'), |
|
1388 | + array($this, 'registration_options_meta_box'), |
|
1389 | 1389 | $this->page_slug, |
1390 | 1390 | 'side', |
1391 | 1391 | 'default' |
@@ -1415,38 +1415,38 @@ discard block |
||
1415 | 1415 | 'disabled' => '' |
1416 | 1416 | ); |
1417 | 1417 | |
1418 | - $event_id = is_object( $this->_cpt_model_obj ) ? $this->_cpt_model_obj->ID() : NULL; |
|
1418 | + $event_id = is_object($this->_cpt_model_obj) ? $this->_cpt_model_obj->ID() : NULL; |
|
1419 | 1419 | |
1420 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
1420 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
1421 | 1421 | |
1422 | 1422 | /** |
1423 | 1423 | * 1. Start with retrieving Datetimes |
1424 | 1424 | * 2. Fore each datetime get related tickets |
1425 | 1425 | * 3. For each ticket get related prices |
1426 | 1426 | */ |
1427 | - $times = EE_Registry::instance()->load_model('Datetime' )->get_all_event_dates( $event_id ); |
|
1428 | - EE_Registry::instance()->load_helper('DTT_Helper' ); |
|
1427 | + $times = EE_Registry::instance()->load_model('Datetime')->get_all_event_dates($event_id); |
|
1428 | + EE_Registry::instance()->load_helper('DTT_Helper'); |
|
1429 | 1429 | /** @type EE_Datetime $first_datetime */ |
1430 | - $first_datetime = array_slice( $times, 0, 1 ); |
|
1430 | + $first_datetime = array_slice($times, 0, 1); |
|
1431 | 1431 | //do we get related tickets? |
1432 | - if ( $first_datetime[ 0 ]->get( 'DTT_ID' ) !== 0 ) { |
|
1433 | - foreach ( $times as $time ) { |
|
1434 | - if ( $time instanceof EE_Datetime ) { |
|
1432 | + if ($first_datetime[0]->get('DTT_ID') !== 0) { |
|
1433 | + foreach ($times as $time) { |
|
1434 | + if ($time instanceof EE_Datetime) { |
|
1435 | 1435 | $existing_datetime_ids[] = $time->get('DTT_ID'); |
1436 | 1436 | $template_args['time'] = $time; |
1437 | 1437 | $related_tickets = $time->tickets( |
1438 | 1438 | array( |
1439 | - array( 'OR' => array( 'TKT_deleted' => 1, 'TKT_deleted*' => 0 ) ), |
|
1439 | + array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)), |
|
1440 | 1440 | 'default_where_conditions' => 'none' |
1441 | 1441 | ) |
1442 | 1442 | ); |
1443 | 1443 | |
1444 | - if ( !empty($related_tickets) ) { |
|
1444 | + if ( ! empty($related_tickets)) { |
|
1445 | 1445 | $template_args['total_ticket_rows'] = count($related_tickets); |
1446 | 1446 | $row = 0; |
1447 | - foreach ( $related_tickets as $ticket ) { |
|
1447 | + foreach ($related_tickets as $ticket) { |
|
1448 | 1448 | $existing_ticket_ids[] = $ticket->get('TKT_ID'); |
1449 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, FALSE, $row ); |
|
1449 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, FALSE, $row); |
|
1450 | 1450 | |
1451 | 1451 | $row++; |
1452 | 1452 | } |
@@ -1454,7 +1454,7 @@ discard block |
||
1454 | 1454 | $template_args['total_ticket_rows'] = 1; |
1455 | 1455 | /** @type EE_Ticket $ticket */ |
1456 | 1456 | $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object(); |
1457 | - $template_args['ticket_rows'] .= $this->_get_ticket_row( $ticket ); |
|
1457 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket); |
|
1458 | 1458 | } |
1459 | 1459 | } |
1460 | 1460 | } |
@@ -1462,7 +1462,7 @@ discard block |
||
1462 | 1462 | $template_args['time'] = $times[0]; |
1463 | 1463 | /** @type EE_Ticket $ticket */ |
1464 | 1464 | $ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets(); |
1465 | - $template_args['ticket_rows'] .= $this->_get_ticket_row( $ticket[1] ); |
|
1465 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]); |
|
1466 | 1466 | // NOTE: we're just sending the first default row |
1467 | 1467 | // (decaf can't manage default tickets so this should be sufficient); |
1468 | 1468 | } |
@@ -1471,8 +1471,8 @@ discard block |
||
1471 | 1471 | $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info'); |
1472 | 1472 | $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
1473 | 1473 | $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
1474 | - $template_args['ticket_js_structure'] = $this->_get_ticket_row( EE_Registry::instance()->load_model('Ticket')->create_default_object(), TRUE ); |
|
1475 | - $template = apply_filters( 'FHEE__Events_Admin_Page__ticket_metabox__template', EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' ); |
|
1474 | + $template_args['ticket_js_structure'] = $this->_get_ticket_row(EE_Registry::instance()->load_model('Ticket')->create_default_object(), TRUE); |
|
1475 | + $template = apply_filters('FHEE__Events_Admin_Page__ticket_metabox__template', EVENTS_TEMPLATE_PATH.'event_tickets_metabox_main.template.php'); |
|
1476 | 1476 | EEH_Template::display_template($template, $template_args); |
1477 | 1477 | } |
1478 | 1478 | |
@@ -1487,21 +1487,21 @@ discard block |
||
1487 | 1487 | * @param int $row |
1488 | 1488 | * @return string generated html for the ticket row. |
1489 | 1489 | */ |
1490 | - private function _get_ticket_row( $ticket, $skeleton = FALSE, $row = 0 ) { |
|
1490 | + private function _get_ticket_row($ticket, $skeleton = FALSE, $row = 0) { |
|
1491 | 1491 | $template_args = array( |
1492 | - 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
1493 | - 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && !$skeleton ? ' tkt-archived' : '', |
|
1492 | + 'tkt_status_class' => ' tkt-status-'.$ticket->ticket_status(), |
|
1493 | + 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' : '', |
|
1494 | 1494 | 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
1495 | 1495 | 'TKT_ID' => $ticket->get('TKT_ID'), |
1496 | 1496 | 'TKT_name' => $ticket->get('TKT_name'), |
1497 | 1497 | 'TKT_start_date' => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'), |
1498 | 1498 | 'TKT_end_date' => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'), |
1499 | 1499 | 'TKT_is_default' => $ticket->get('TKT_is_default'), |
1500 | - 'TKT_qty' => $ticket->get_pretty('TKT_qty','input'), |
|
1500 | + 'TKT_qty' => $ticket->get_pretty('TKT_qty', 'input'), |
|
1501 | 1501 | 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets', |
1502 | 1502 | 'TKT_sold' => $skeleton ? 0 : $ticket->get('TKT_sold'), |
1503 | - 'trash_icon' => ( $skeleton || ( !empty( $ticket ) && ! $ticket->get('TKT_deleted') ) ) && ( !empty( $ticket ) && $ticket->get('TKT_sold') === 0 ) ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon', |
|
1504 | - 'disabled' => $skeleton || ( !empty( $ticket ) && ! $ticket->get('TKT_deleted' ) ) ? '' : ' disabled=disabled' |
|
1503 | + 'trash_icon' => ($skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted'))) && ( ! empty($ticket) && $ticket->get('TKT_sold') === 0) ? 'trash-icon dashicons dashicons-post-trash clickable' : 'ee-lock-icon', |
|
1504 | + 'disabled' => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' : ' disabled=disabled' |
|
1505 | 1505 | ); |
1506 | 1506 | |
1507 | 1507 | $price = $ticket->ID() !== 0 ? $ticket->get_first_related('Price', array('default_where_conditions' => 'none')) : EE_Registry::instance()->load_model('Price')->create_default_object(); |
@@ -1517,23 +1517,23 @@ discard block |
||
1517 | 1517 | |
1518 | 1518 | //make sure we have default start and end dates if skeleton |
1519 | 1519 | //handle rows that should NOT be empty |
1520 | - if ( empty( $template_args['TKT_start_date'] ) ) { |
|
1520 | + if (empty($template_args['TKT_start_date'])) { |
|
1521 | 1521 | //if empty then the start date will be now. |
1522 | 1522 | $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp')); |
1523 | 1523 | } |
1524 | 1524 | |
1525 | - if ( empty( $template_args['TKT_end_date'] ) ) { |
|
1525 | + if (empty($template_args['TKT_end_date'])) { |
|
1526 | 1526 | //get the earliest datetime (if present); |
1527 | - $earliest_dtt = $this->_cpt_model_obj->ID() > 0 ? $this->_cpt_model_obj->get_first_related('Datetime', array('order_by'=> array('DTT_EVT_start' => 'ASC' ) ) ) : NULL; |
|
1527 | + $earliest_dtt = $this->_cpt_model_obj->ID() > 0 ? $this->_cpt_model_obj->get_first_related('Datetime', array('order_by'=> array('DTT_EVT_start' => 'ASC'))) : NULL; |
|
1528 | 1528 | |
1529 | - if ( !empty( $earliest_dtt ) ) |
|
1529 | + if ( ! empty($earliest_dtt)) |
|
1530 | 1530 | $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a'); |
1531 | 1531 | else |
1532 | - $template_args['TKT_end_date'] = date('Y-m-d h:i a', mktime(0, 0, 0, date("m"), date("d")+7, date("Y") ) ); |
|
1532 | + $template_args['TKT_end_date'] = date('Y-m-d h:i a', mktime(0, 0, 0, date("m"), date("d") + 7, date("Y"))); |
|
1533 | 1533 | } |
1534 | 1534 | |
1535 | - $template_args = array_merge( $template_args, $price_args ); |
|
1536 | - $template = apply_filters( 'FHEE__Events_Admin_Page__get_ticket_row__template', EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', $ticket); |
|
1535 | + $template_args = array_merge($template_args, $price_args); |
|
1536 | + $template = apply_filters('FHEE__Events_Admin_Page__get_ticket_row__template', EVENTS_TEMPLATE_PATH.'event_tickets_metabox_ticket_row.template.php', $ticket); |
|
1537 | 1537 | return EEH_Template::display_template($template, $template_args, TRUE); |
1538 | 1538 | } |
1539 | 1539 | |
@@ -1562,8 +1562,8 @@ discard block |
||
1562 | 1562 | $template_args['default_registration_status'] = EEH_Form_Fields::select_input('default_reg_status', $default_reg_status_values, $this->_cpt_model_obj->default_registration_status()); |
1563 | 1563 | $template_args['display_description'] = EEH_Form_Fields::select_input('display_desc', $yes_no_values, $this->_cpt_model_obj->display_description()); |
1564 | 1564 | $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input('display_ticket_selector', $yes_no_values, $this->_cpt_model_obj->display_ticket_selector(), '', '', false); |
1565 | - $template_args['additional_registration_options'] = apply_filters( 'FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', '', $template_args, $yes_no_values, $default_reg_status_values ); |
|
1566 | - $templatepath = EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php'; |
|
1565 | + $template_args['additional_registration_options'] = apply_filters('FHEE__Events_Admin_Page__registration_options_meta_box__additional_registration_options', '', $template_args, $yes_no_values, $default_reg_status_values); |
|
1566 | + $templatepath = EVENTS_TEMPLATE_PATH.'event_registration_options.template.php'; |
|
1567 | 1567 | EEH_Template::display_template($templatepath, $template_args); |
1568 | 1568 | } |
1569 | 1569 | |
@@ -1591,21 +1591,21 @@ discard block |
||
1591 | 1591 | $EEME = $this->_event_model(); |
1592 | 1592 | |
1593 | 1593 | $offset = ($current_page - 1) * $per_page; |
1594 | - $limit = $count ? NULL : $offset . ',' . $per_page; |
|
1594 | + $limit = $count ? NULL : $offset.','.$per_page; |
|
1595 | 1595 | $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID'; |
1596 | 1596 | $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC"; |
1597 | 1597 | |
1598 | 1598 | if (isset($this->_req_data['month_range'])) { |
1599 | 1599 | $pieces = explode(' ', $this->_req_data['month_range'], 3); |
1600 | - $month_r = !empty($pieces[0]) ? date('m', strtotime($pieces[0])) : ''; |
|
1601 | - $year_r = !empty($pieces[1]) ? $pieces[1] : ''; |
|
1600 | + $month_r = ! empty($pieces[0]) ? date('m', strtotime($pieces[0])) : ''; |
|
1601 | + $year_r = ! empty($pieces[1]) ? $pieces[1] : ''; |
|
1602 | 1602 | } |
1603 | 1603 | |
1604 | 1604 | $where = array(); |
1605 | 1605 | |
1606 | - $status = isset( $this->_req_data['status'] ) ? $this->_req_data['status'] : NULL; |
|
1606 | + $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : NULL; |
|
1607 | 1607 | //determine what post_status our condition will have for the query. |
1608 | - switch ( $status ) { |
|
1608 | + switch ($status) { |
|
1609 | 1609 | case 'month' : |
1610 | 1610 | case 'today' : |
1611 | 1611 | case NULL : |
@@ -1613,7 +1613,7 @@ discard block |
||
1613 | 1613 | break; |
1614 | 1614 | |
1615 | 1615 | case 'draft' : |
1616 | - $where['status'] = array( 'IN', array('draft', 'auto-draft') ); |
|
1616 | + $where['status'] = array('IN', array('draft', 'auto-draft')); |
|
1617 | 1617 | break; |
1618 | 1618 | |
1619 | 1619 | default : |
@@ -1621,43 +1621,43 @@ discard block |
||
1621 | 1621 | } |
1622 | 1622 | |
1623 | 1623 | //categories? |
1624 | - $category = isset( $this->_req_data['EVT_CAT'] ) && $this->_req_data['EVT_CAT'] > 0 ? $this->_req_data['EVT_CAT'] : NULL; |
|
1624 | + $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 ? $this->_req_data['EVT_CAT'] : NULL; |
|
1625 | 1625 | |
1626 | - if ( !empty ( $category ) ) { |
|
1626 | + if ( ! empty ($category)) { |
|
1627 | 1627 | $where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
1628 | 1628 | $where['Term_Taxonomy.term_id'] = $category; |
1629 | 1629 | } |
1630 | 1630 | |
1631 | 1631 | //date where conditions |
1632 | - $start_formats = EEM_Datetime::instance()->get_formats_for( 'DTT_EVT_start' ); |
|
1632 | + $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
|
1633 | 1633 | if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') { |
1634 | - $DateTime = new DateTime( $year_r . '-' . $month_r . '-01 00:00:00', new DateTimeZone( EEM_Datetime::instance()->get_timezone() ) ); |
|
1635 | - $start = $DateTime->format( implode( ' ', $start_formats ) ); |
|
1636 | - $end = $DateTime->setDate( $year_r, $month_r, $DateTime->format('t') )->setTime(23,59,59)->format( implode( ' ', $start_formats ) ); |
|
1637 | - $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array( $start, $end ) ); |
|
1634 | + $DateTime = new DateTime($year_r.'-'.$month_r.'-01 00:00:00', new DateTimeZone(EEM_Datetime::instance()->get_timezone())); |
|
1635 | + $start = $DateTime->format(implode(' ', $start_formats)); |
|
1636 | + $end = $DateTime->setDate($year_r, $month_r, $DateTime->format('t'))->setTime(23, 59, 59)->format(implode(' ', $start_formats)); |
|
1637 | + $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
1638 | 1638 | } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') { |
1639 | - $DateTime = new DateTime( 'now', new DateTimeZone( EEM_Event::instance()->get_timezone() ) ); |
|
1640 | - $start = $DateTime->setTime( 0,0,0 )->format( implode( ' ', $start_formats ) ); |
|
1641 | - $end = $DateTime->setTime( 23, 59, 59 )->format( implode( ' ', $start_formats ) ); |
|
1642 | - $where['Datetime.DTT_EVT_start'] = array( 'BETWEEN', array( $start, $end ) ); |
|
1643 | - } else if ( isset($this->_req_data['status']) && $this->_req_data['status'] == 'month' ) { |
|
1644 | - $now = date( 'Y-m-01' ); |
|
1645 | - $DateTime = new DateTime( $now, new DateTimeZone( EEM_Event::instance()->get_timezone() ) ); |
|
1646 | - $start = $DateTime->setTime( 0, 0, 0 )->format( implode( ' ', $start_formats ) ); |
|
1647 | - $end = $DateTime->setDate( date('Y'), date('m'), $DateTime->format('t' ) )->setTime( 23, 59, 59 )->format( implode( ' ', $start_formats ) ); |
|
1648 | - $where['Datetime.DTT_EVT_start'] = array( 'BETWEEN', array( $start, $end ) ); |
|
1639 | + $DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
1640 | + $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
1641 | + $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats)); |
|
1642 | + $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
1643 | + } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') { |
|
1644 | + $now = date('Y-m-01'); |
|
1645 | + $DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
1646 | + $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
1647 | + $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))->setTime(23, 59, 59)->format(implode(' ', $start_formats)); |
|
1648 | + $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
1649 | 1649 | } |
1650 | 1650 | |
1651 | 1651 | |
1652 | - if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_others_events', 'get_events' ) ) { |
|
1653 | - $where['EVT_wp_user'] = get_current_user_id(); |
|
1652 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
1653 | + $where['EVT_wp_user'] = get_current_user_id(); |
|
1654 | 1654 | } else { |
1655 | - if ( ! isset( $where['status'] ) ) { |
|
1656 | - if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_private_events', 'get_events' ) ) { |
|
1655 | + if ( ! isset($where['status'])) { |
|
1656 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
1657 | 1657 | $where['OR'] = array( |
1658 | - 'status*restrict_private' => array( '!=', 'private' ), |
|
1658 | + 'status*restrict_private' => array('!=', 'private'), |
|
1659 | 1659 | 'AND' => array( |
1660 | - 'status*inclusive' => array( '=', 'private' ), |
|
1660 | + 'status*inclusive' => array('=', 'private'), |
|
1661 | 1661 | 'EVT_wp_user' => get_current_user_id() |
1662 | 1662 | ) |
1663 | 1663 | ); |
@@ -1665,16 +1665,16 @@ discard block |
||
1665 | 1665 | } |
1666 | 1666 | } |
1667 | 1667 | |
1668 | - if ( isset( $this->_req_data['EVT_wp_user'] ) ) { |
|
1669 | - if ( $this->_req_data['EVT_wp_user'] != get_current_user_id() && EE_Registry::instance()->CAP->current_user_can( 'ee_read_others_events', 'get_events' ) ) { |
|
1668 | + if (isset($this->_req_data['EVT_wp_user'])) { |
|
1669 | + if ($this->_req_data['EVT_wp_user'] != get_current_user_id() && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
1670 | 1670 | $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user']; |
1671 | 1671 | } |
1672 | 1672 | } |
1673 | 1673 | |
1674 | 1674 | |
1675 | 1675 | //search query handling |
1676 | - if ( isset( $this->_req_data['s'] ) ) { |
|
1677 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
1676 | + if (isset($this->_req_data['s'])) { |
|
1677 | + $search_string = '%'.$this->_req_data['s'].'%'; |
|
1678 | 1678 | $where['OR'] = array( |
1679 | 1679 | 'EVT_name' => array('LIKE', $search_string), |
1680 | 1680 | 'EVT_desc' => array('LIKE', $search_string), |
@@ -1683,32 +1683,32 @@ discard block |
||
1683 | 1683 | } |
1684 | 1684 | |
1685 | 1685 | |
1686 | - $where = apply_filters( 'FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data ); |
|
1687 | - $query_params = apply_filters( 'FHEE__Events_Admin_Page__get_events__query_params', array($where, 'limit' => $limit, 'order_by' => $orderby, 'order' => $order, 'group_by' => 'EVT_ID' ), $this->_req_data ); |
|
1686 | + $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data); |
|
1687 | + $query_params = apply_filters('FHEE__Events_Admin_Page__get_events__query_params', array($where, 'limit' => $limit, 'order_by' => $orderby, 'order' => $order, 'group_by' => 'EVT_ID'), $this->_req_data); |
|
1688 | 1688 | |
1689 | 1689 | |
1690 | 1690 | //let's first check if we have special requests coming in. |
1691 | - if ( isset( $this->_req_data['active_status'] ) ) { |
|
1692 | - switch ( $this->_req_data['active_status'] ) { |
|
1691 | + if (isset($this->_req_data['active_status'])) { |
|
1692 | + switch ($this->_req_data['active_status']) { |
|
1693 | 1693 | case 'upcoming' : |
1694 | - return $EEME->get_upcoming_events( $query_params, $count ); |
|
1694 | + return $EEME->get_upcoming_events($query_params, $count); |
|
1695 | 1695 | break; |
1696 | 1696 | |
1697 | 1697 | case 'expired' : |
1698 | - return $EEME->get_expired_events( $query_params, $count ); |
|
1698 | + return $EEME->get_expired_events($query_params, $count); |
|
1699 | 1699 | break; |
1700 | 1700 | |
1701 | 1701 | case 'active' : |
1702 | - return $EEME->get_active_events( $query_params, $count ); |
|
1702 | + return $EEME->get_active_events($query_params, $count); |
|
1703 | 1703 | break; |
1704 | 1704 | |
1705 | 1705 | case 'inactive' : |
1706 | - return $EEME->get_inactive_events( $query_params, $count ); |
|
1706 | + return $EEME->get_inactive_events($query_params, $count); |
|
1707 | 1707 | break; |
1708 | 1708 | } |
1709 | 1709 | } |
1710 | 1710 | |
1711 | - $events = $count ? $EEME->count( array( $where ), 'EVT_ID', true ) : $EEME->get_all( $query_params ); |
|
1711 | + $events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params); |
|
1712 | 1712 | |
1713 | 1713 | return $events; |
1714 | 1714 | } |
@@ -1717,23 +1717,23 @@ discard block |
||
1717 | 1717 | |
1718 | 1718 | |
1719 | 1719 | //handling for WordPress CPT actions (trash, restore, delete) |
1720 | - public function trash_cpt_item( $post_id ) { |
|
1720 | + public function trash_cpt_item($post_id) { |
|
1721 | 1721 | $this->_req_data['EVT_ID'] = $post_id; |
1722 | - $this->_trash_or_restore_event( 'trash', FALSE ); |
|
1722 | + $this->_trash_or_restore_event('trash', FALSE); |
|
1723 | 1723 | } |
1724 | 1724 | |
1725 | 1725 | |
1726 | 1726 | |
1727 | 1727 | |
1728 | - public function restore_cpt_item( $post_id ) { |
|
1728 | + public function restore_cpt_item($post_id) { |
|
1729 | 1729 | $this->_req_data['EVT_ID'] = $post_id; |
1730 | - $this->_trash_or_restore_event( 'draft', FALSE ); |
|
1730 | + $this->_trash_or_restore_event('draft', FALSE); |
|
1731 | 1731 | } |
1732 | 1732 | |
1733 | 1733 | |
1734 | - public function delete_cpt_item( $post_id ) { |
|
1734 | + public function delete_cpt_item($post_id) { |
|
1735 | 1735 | $this->_req_data['EVT_ID'] = $post_id; |
1736 | - $this->_delete_event( FALSE ); |
|
1736 | + $this->_delete_event(FALSE); |
|
1737 | 1737 | } |
1738 | 1738 | |
1739 | 1739 | |
@@ -1745,7 +1745,7 @@ discard block |
||
1745 | 1745 | * @param string $event_status |
1746 | 1746 | * @return void |
1747 | 1747 | */ |
1748 | - protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = TRUE ) { |
|
1748 | + protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = TRUE) { |
|
1749 | 1749 | //determine the event id and set to array. |
1750 | 1750 | $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : FALSE; |
1751 | 1751 | // loop thru events |
@@ -1753,7 +1753,7 @@ discard block |
||
1753 | 1753 | // clean status |
1754 | 1754 | $event_status = sanitize_key($event_status); |
1755 | 1755 | // grab status |
1756 | - if (!empty($event_status)) { |
|
1756 | + if ( ! empty($event_status)) { |
|
1757 | 1757 | $success = $this->_change_event_status($EVT_ID, $event_status); |
1758 | 1758 | } else { |
1759 | 1759 | $success = FALSE; |
@@ -1767,7 +1767,7 @@ discard block |
||
1767 | 1767 | } |
1768 | 1768 | $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
1769 | 1769 | |
1770 | - if ( $redirect_after ) |
|
1770 | + if ($redirect_after) |
|
1771 | 1771 | $this->_redirect_after_action($success, 'Event', $action, array('action' => 'default')); |
1772 | 1772 | } |
1773 | 1773 | |
@@ -1782,7 +1782,7 @@ discard block |
||
1782 | 1782 | // clean status |
1783 | 1783 | $event_status = sanitize_key($event_status); |
1784 | 1784 | // grab status |
1785 | - if (!empty($event_status)) { |
|
1785 | + if ( ! empty($event_status)) { |
|
1786 | 1786 | $success = TRUE; |
1787 | 1787 | //determine the event id and set to array. |
1788 | 1788 | $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array(); |
@@ -1817,15 +1817,15 @@ discard block |
||
1817 | 1817 | * @param string $event_status |
1818 | 1818 | * @return bool |
1819 | 1819 | */ |
1820 | - private function _change_event_status( $EVT_ID = 0, $event_status = '') { |
|
1820 | + private function _change_event_status($EVT_ID = 0, $event_status = '') { |
|
1821 | 1821 | // grab event id |
1822 | - if (!$EVT_ID) { |
|
1822 | + if ( ! $EVT_ID) { |
|
1823 | 1823 | $msg = __('An error occurred. No Event ID or an invalid Event ID was received.', 'event_espresso'); |
1824 | 1824 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
1825 | 1825 | return FALSE; |
1826 | 1826 | } |
1827 | 1827 | |
1828 | - $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID( $EVT_ID ); |
|
1828 | + $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
1829 | 1829 | |
1830 | 1830 | // clean status |
1831 | 1831 | $event_status = sanitize_key($event_status); |
@@ -1851,7 +1851,7 @@ discard block |
||
1851 | 1851 | $hook = FALSE; |
1852 | 1852 | } |
1853 | 1853 | //use class to change status |
1854 | - $this->_cpt_model_obj->set_status( $event_status ); |
|
1854 | + $this->_cpt_model_obj->set_status($event_status); |
|
1855 | 1855 | $success = $this->_cpt_model_obj->save(); |
1856 | 1856 | |
1857 | 1857 | if ($success === FALSE) { |
@@ -1873,15 +1873,15 @@ discard block |
||
1873 | 1873 | * @access protected |
1874 | 1874 | * @param bool $redirect_after |
1875 | 1875 | */ |
1876 | - protected function _delete_event( $redirect_after = TRUE ) { |
|
1876 | + protected function _delete_event($redirect_after = TRUE) { |
|
1877 | 1877 | //determine the event id and set to array. |
1878 | 1878 | $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : NULL; |
1879 | - $EVT_ID = isset( $this->_req_data['post'] ) ? absint( $this->_req_data['post'] ) : $EVT_ID; |
|
1879 | + $EVT_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $EVT_ID; |
|
1880 | 1880 | |
1881 | 1881 | |
1882 | 1882 | // loop thru events |
1883 | 1883 | if ($EVT_ID) { |
1884 | - $success = $this->_permanently_delete_event( $EVT_ID ); |
|
1884 | + $success = $this->_permanently_delete_event($EVT_ID); |
|
1885 | 1885 | // get list of events with no prices |
1886 | 1886 | $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array()); |
1887 | 1887 | // remove this event from the list of events with no prices |
@@ -1895,7 +1895,7 @@ discard block |
||
1895 | 1895 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
1896 | 1896 | } |
1897 | 1897 | |
1898 | - if ( $redirect_after ) |
|
1898 | + if ($redirect_after) |
|
1899 | 1899 | $this->_redirect_after_action($success, 'Event', 'deleted', array('action' => 'default', 'status' => 'trash')); |
1900 | 1900 | } |
1901 | 1901 | |
@@ -1913,12 +1913,12 @@ discard block |
||
1913 | 1913 | $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array(); |
1914 | 1914 | // loop thru events |
1915 | 1915 | foreach ($EVT_IDs as $EVT_ID) { |
1916 | - $EVT_ID = absint( $EVT_ID ); |
|
1917 | - if ( $EVT_ID ) { |
|
1918 | - $results = $this->_permanently_delete_event( $EVT_ID ); |
|
1916 | + $EVT_ID = absint($EVT_ID); |
|
1917 | + if ($EVT_ID) { |
|
1918 | + $results = $this->_permanently_delete_event($EVT_ID); |
|
1919 | 1919 | $success = $results !== FALSE ? $success : FALSE; |
1920 | 1920 | // remove this event from the list of events with no prices |
1921 | - unset( $espresso_no_ticket_prices[ $EVT_ID ] ); |
|
1921 | + unset($espresso_no_ticket_prices[$EVT_ID]); |
|
1922 | 1922 | } else { |
1923 | 1923 | $success = FALSE; |
1924 | 1924 | $msg = __('An error occurred. An event could not be deleted because a valid event ID was not not supplied.', 'event_espresso'); |
@@ -1938,21 +1938,21 @@ discard block |
||
1938 | 1938 | * @param int $EVT_ID |
1939 | 1939 | * @return bool |
1940 | 1940 | */ |
1941 | - private function _permanently_delete_event( $EVT_ID = 0 ) { |
|
1941 | + private function _permanently_delete_event($EVT_ID = 0) { |
|
1942 | 1942 | // grab event id |
1943 | - if ( ! $EVT_ID ) { |
|
1943 | + if ( ! $EVT_ID) { |
|
1944 | 1944 | $msg = __('An error occurred. No Event ID or an invalid Event ID was received.', 'event_espresso'); |
1945 | 1945 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
1946 | 1946 | return FALSE; |
1947 | 1947 | } |
1948 | - $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID( $EVT_ID ); |
|
1948 | + $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
1949 | 1949 | |
1950 | 1950 | //need to delete related tickets and prices first. |
1951 | 1951 | $datetimes = $this->_cpt_model_obj->get_many_related('Datetime'); |
1952 | - foreach ( $datetimes as $datetime ) { |
|
1952 | + foreach ($datetimes as $datetime) { |
|
1953 | 1953 | $this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime'); |
1954 | 1954 | $tickets = $datetime->get_many_related('Ticket'); |
1955 | - foreach ( $tickets as $ticket ) { |
|
1955 | + foreach ($tickets as $ticket) { |
|
1956 | 1956 | $ticket->_remove_relation_to($datetime, 'Datetime'); |
1957 | 1957 | $ticket->delete_related_permanently('Price'); |
1958 | 1958 | $ticket->delete_permanently(); |
@@ -1962,14 +1962,14 @@ discard block |
||
1962 | 1962 | |
1963 | 1963 | //what about related venues or terms? |
1964 | 1964 | $venues = $this->_cpt_model_obj->get_many_related('Venue'); |
1965 | - foreach ( $venues as $venue ) { |
|
1965 | + foreach ($venues as $venue) { |
|
1966 | 1966 | $this->_cpt_model_obj->_remove_relation_to($venue, 'Venue'); |
1967 | 1967 | } |
1968 | 1968 | |
1969 | 1969 | //any attached question groups? |
1970 | 1970 | $question_groups = $this->_cpt_model_obj->get_many_related('Question_Group'); |
1971 | - if ( !empty( $question_groups ) ) { |
|
1972 | - foreach ( $question_groups as $question_group ) { |
|
1971 | + if ( ! empty($question_groups)) { |
|
1972 | + foreach ($question_groups as $question_group) { |
|
1973 | 1973 | $this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group'); |
1974 | 1974 | } |
1975 | 1975 | } |
@@ -1978,12 +1978,12 @@ discard block |
||
1978 | 1978 | |
1979 | 1979 | |
1980 | 1980 | //Message Template Groups |
1981 | - $this->_cpt_model_obj->_remove_relations( 'Message_Template_Group' ); |
|
1981 | + $this->_cpt_model_obj->_remove_relations('Message_Template_Group'); |
|
1982 | 1982 | |
1983 | 1983 | /** @type EE_Term_Taxonomy[] $term_taxonomies */ |
1984 | 1984 | $term_taxonomies = $this->_cpt_model_obj->term_taxonomies(); |
1985 | 1985 | |
1986 | - foreach ( $term_taxonomies as $term_taxonomy ) { |
|
1986 | + foreach ($term_taxonomies as $term_taxonomy) { |
|
1987 | 1987 | $this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy); |
1988 | 1988 | } |
1989 | 1989 | |
@@ -1997,7 +1997,7 @@ discard block |
||
1997 | 1997 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
1998 | 1998 | return FALSE; |
1999 | 1999 | } |
2000 | - do_action( 'AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID ); |
|
2000 | + do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID); |
|
2001 | 2001 | return TRUE; |
2002 | 2002 | } |
2003 | 2003 | |
@@ -2014,7 +2014,7 @@ discard block |
||
2014 | 2014 | */ |
2015 | 2015 | public function total_events() { |
2016 | 2016 | |
2017 | - $count = EEM_Event::instance()->count( array( 'caps' => 'read_admin' ), 'EVT_ID', true ); |
|
2017 | + $count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true); |
|
2018 | 2018 | return $count; |
2019 | 2019 | } |
2020 | 2020 | |
@@ -2029,10 +2029,10 @@ discard block |
||
2029 | 2029 | */ |
2030 | 2030 | public function total_events_draft() { |
2031 | 2031 | $where = array( |
2032 | - 'status' => array( 'IN', array('draft', 'auto-draft' ) ) |
|
2032 | + 'status' => array('IN', array('draft', 'auto-draft')) |
|
2033 | 2033 | ); |
2034 | 2034 | |
2035 | - $count = EEM_Event::instance()->count( array( $where, 'caps' => 'read_admin' ), 'EVT_ID', true ); |
|
2035 | + $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
2036 | 2036 | return $count; |
2037 | 2037 | } |
2038 | 2038 | |
@@ -2051,7 +2051,7 @@ discard block |
||
2051 | 2051 | 'status' => 'trash' |
2052 | 2052 | ); |
2053 | 2053 | |
2054 | - $count = EEM_Event::instance()->count( array( $where, 'caps' => 'read_admin' ), 'EVT_ID', true ); |
|
2054 | + $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
2055 | 2055 | return $count; |
2056 | 2056 | } |
2057 | 2057 | |
@@ -2079,11 +2079,11 @@ discard block |
||
2079 | 2079 | // translated |
2080 | 2080 | TRUE |
2081 | 2081 | ); |
2082 | - $this->_template_args['default_reg_status'] = isset( EE_Registry::instance()->CFG->registration->default_STS_ID ) ? sanitize_text_field( EE_Registry::instance()->CFG->registration->default_STS_ID ) : EEM_Registration::status_id_pending_payment; |
|
2082 | + $this->_template_args['default_reg_status'] = isset(EE_Registry::instance()->CFG->registration->default_STS_ID) ? sanitize_text_field(EE_Registry::instance()->CFG->registration->default_STS_ID) : EEM_Registration::status_id_pending_payment; |
|
2083 | 2083 | |
2084 | 2084 | $this->_set_add_edit_form_tags('update_default_event_settings'); |
2085 | 2085 | $this->_set_publish_post_box_vars(NULL, FALSE, FALSE, NULL, FALSE); |
2086 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template(EVENTS_TEMPLATE_PATH . 'event_settings.template.php', $this->_template_args, TRUE); |
|
2086 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template(EVENTS_TEMPLATE_PATH.'event_settings.template.php', $this->_template_args, TRUE); |
|
2087 | 2087 | $this->display_admin_page_with_sidebar(); |
2088 | 2088 | } |
2089 | 2089 | |
@@ -2109,9 +2109,9 @@ discard block |
||
2109 | 2109 | |
2110 | 2110 | protected function _template_settings() { |
2111 | 2111 | $this->_admin_page_title = __('Template Settings (Preview)', 'event_espresso'); |
2112 | - $this->_template_args['preview_img'] = '<img src="' . EVENTS_ASSETS_URL . DS . 'images' . DS . 'caffeinated_template_features.jpg" alt="' . esc_attr__( 'Template Settings Preview screenshot', 'event_espresso' ) . '" />'; |
|
2113 | - $this->_template_args['preview_text'] = '<strong>'.__( 'Template Settings is a feature that is only available in the Caffeinated version of Event Espresso. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.', 'event_espresso' ).'</strong>'; |
|
2114 | - $this->display_admin_caf_preview_page( 'template_settings_tab' ); |
|
2112 | + $this->_template_args['preview_img'] = '<img src="'.EVENTS_ASSETS_URL.DS.'images'.DS.'caffeinated_template_features.jpg" alt="'.esc_attr__('Template Settings Preview screenshot', 'event_espresso').'" />'; |
|
2113 | + $this->_template_args['preview_text'] = '<strong>'.__('Template Settings is a feature that is only available in the Caffeinated version of Event Espresso. Template Settings allow you to configure some of the appearance options for both the Event List and Event Details pages.', 'event_espresso').'</strong>'; |
|
2114 | + $this->display_admin_caf_preview_page('template_settings_tab'); |
|
2115 | 2115 | } |
2116 | 2116 | |
2117 | 2117 | |
@@ -2124,22 +2124,22 @@ discard block |
||
2124 | 2124 | * @return void |
2125 | 2125 | */ |
2126 | 2126 | private function _set_category_object() { |
2127 | - if ( isset( $this->_category->id ) && !empty( $this->_category->id ) ) |
|
2127 | + if (isset($this->_category->id) && ! empty($this->_category->id)) |
|
2128 | 2128 | return; //already have the category object so get out. |
2129 | 2129 | |
2130 | 2130 | //set default category object |
2131 | 2131 | $this->_set_empty_category_object(); |
2132 | 2132 | |
2133 | 2133 | //only set if we've got an id |
2134 | - if ( !isset($this->_req_data['EVT_CAT_ID'] ) ) { |
|
2134 | + if ( ! isset($this->_req_data['EVT_CAT_ID'])) { |
|
2135 | 2135 | return; |
2136 | 2136 | } |
2137 | 2137 | |
2138 | 2138 | $category_id = absint($this->_req_data['EVT_CAT_ID']); |
2139 | 2139 | |
2140 | - $term = get_term( $category_id, 'espresso_event_categories' ); |
|
2140 | + $term = get_term($category_id, 'espresso_event_categories'); |
|
2141 | 2141 | |
2142 | - if ( !empty( $term ) ) { |
|
2142 | + if ( ! empty($term)) { |
|
2143 | 2143 | $this->_category->category_name = $term->name; |
2144 | 2144 | $this->_category->category_identifier = $term->slug; |
2145 | 2145 | $this->_category->category_desc = $term->description; |
@@ -2153,13 +2153,13 @@ discard block |
||
2153 | 2153 | |
2154 | 2154 | private function _set_empty_category_object() { |
2155 | 2155 | $this->_category = new stdClass(); |
2156 | - $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = ''; |
|
2156 | + $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = ''; |
|
2157 | 2157 | $this->_category->id = $this->_category->parent = 0; |
2158 | 2158 | } |
2159 | 2159 | |
2160 | 2160 | |
2161 | 2161 | protected function _category_list_table() { |
2162 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
2162 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
2163 | 2163 | $this->_search_btn_label = __('Categories', 'event_espresso'); |
2164 | 2164 | $this->_admin_page_title .= $this->get_action_link_or_button('add_category', 'add_category', array(), 'add-new-h2'); |
2165 | 2165 | $this->display_admin_list_table_page_with_sidebar(); |
@@ -2169,22 +2169,22 @@ discard block |
||
2169 | 2169 | protected function _category_details($view) { |
2170 | 2170 | |
2171 | 2171 | //load formatter helper |
2172 | - EE_Registry::instance()->load_helper( 'Formatter' ); |
|
2172 | + EE_Registry::instance()->load_helper('Formatter'); |
|
2173 | 2173 | //load field generator helper |
2174 | - EE_Registry::instance()->load_helper( 'Form_Fields' ); |
|
2174 | + EE_Registry::instance()->load_helper('Form_Fields'); |
|
2175 | 2175 | |
2176 | 2176 | $route = $view == 'edit' ? 'update_category' : 'insert_category'; |
2177 | 2177 | $this->_set_add_edit_form_tags($route); |
2178 | 2178 | |
2179 | 2179 | $this->_set_category_object(); |
2180 | - $id = !empty($this->_category->id) ? $this->_category->id : ''; |
|
2180 | + $id = ! empty($this->_category->id) ? $this->_category->id : ''; |
|
2181 | 2181 | |
2182 | 2182 | $delete_action = 'delete_category'; |
2183 | 2183 | |
2184 | 2184 | //custom redirect |
2185 | - $redirect = EE_Admin_Page::add_query_args_and_nonce( array('action' => 'category_list'), $this->_admin_base_url ); |
|
2185 | + $redirect = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'category_list'), $this->_admin_base_url); |
|
2186 | 2186 | |
2187 | - $this->_set_publish_post_box_vars( 'EVT_CAT_ID', $id, $delete_action, $redirect ); |
|
2187 | + $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect); |
|
2188 | 2188 | |
2189 | 2189 | //take care of contents |
2190 | 2190 | $this->_template_args['admin_page_content'] = $this->_category_details_content(); |
@@ -2198,25 +2198,25 @@ discard block |
||
2198 | 2198 | 'type' => 'wp_editor', |
2199 | 2199 | 'value' => EEH_Formatter::admin_format_content($this->_category->category_desc), |
2200 | 2200 | 'class' => 'my_editor_custom', |
2201 | - 'wpeditor_args' => array('media_buttons' => FALSE ) |
|
2201 | + 'wpeditor_args' => array('media_buttons' => FALSE) |
|
2202 | 2202 | ); |
2203 | - $_wp_editor = $this->_generate_admin_form_fields( $editor_args, 'array' ); |
|
2203 | + $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array'); |
|
2204 | 2204 | |
2205 | - $all_terms = get_terms( array('espresso_event_categories' ), array( 'hide_empty' => 0, 'exclude' => array( $this->_category->id ) ) ); |
|
2205 | + $all_terms = get_terms(array('espresso_event_categories'), array('hide_empty' => 0, 'exclude' => array($this->_category->id))); |
|
2206 | 2206 | |
2207 | 2207 | //setup category select for term parents. |
2208 | 2208 | $category_select_values[] = array( |
2209 | 2209 | 'text' => __('No Parent', 'event_espresso'), |
2210 | 2210 | 'id' => 0 |
2211 | 2211 | ); |
2212 | - foreach ( $all_terms as $term ) { |
|
2212 | + foreach ($all_terms as $term) { |
|
2213 | 2213 | $category_select_values[] = array( |
2214 | 2214 | 'text' => $term->name, |
2215 | 2215 | 'id' => $term->term_id |
2216 | 2216 | ); |
2217 | 2217 | } |
2218 | 2218 | |
2219 | - $category_select = EEH_Form_Fields::select_input( 'category_parent', $category_select_values, $this->_category->parent ); |
|
2219 | + $category_select = EEH_Form_Fields::select_input('category_parent', $category_select_values, $this->_category->parent); |
|
2220 | 2220 | |
2221 | 2221 | $template_args = array( |
2222 | 2222 | 'category' => $this->_category, |
@@ -2226,15 +2226,15 @@ discard block |
||
2226 | 2226 | 'disable' => '', |
2227 | 2227 | 'disabled_message' => FALSE |
2228 | 2228 | ); |
2229 | - $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
2230 | - return EEH_Template::display_template($template, $template_args, TRUE ); |
|
2229 | + $template = EVENTS_TEMPLATE_PATH.'event_category_details.template.php'; |
|
2230 | + return EEH_Template::display_template($template, $template_args, TRUE); |
|
2231 | 2231 | } |
2232 | 2232 | |
2233 | 2233 | |
2234 | 2234 | protected function _delete_categories() { |
2235 | - $cat_ids = isset( $this->_req_data['EVT_CAT_ID'] ) ? (array) $this->_req_data['EVT_CAT_ID'] : (array) $this->_req_data['category_id']; |
|
2235 | + $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID'] : (array) $this->_req_data['category_id']; |
|
2236 | 2236 | |
2237 | - foreach ( $cat_ids as $cat_id ) { |
|
2237 | + foreach ($cat_ids as $cat_id) { |
|
2238 | 2238 | $this->_delete_category($cat_id); |
2239 | 2239 | } |
2240 | 2240 | |
@@ -2242,7 +2242,7 @@ discard block |
||
2242 | 2242 | $query_args = array( |
2243 | 2243 | 'action' => 'category_list' |
2244 | 2244 | ); |
2245 | - $this->_redirect_after_action(0,'','',$query_args); |
|
2245 | + $this->_redirect_after_action(0, '', '', $query_args); |
|
2246 | 2246 | |
2247 | 2247 | } |
2248 | 2248 | |
@@ -2252,61 +2252,61 @@ discard block |
||
2252 | 2252 | |
2253 | 2253 | protected function _delete_category($cat_id) { |
2254 | 2254 | global $wpdb; |
2255 | - $cat_id = absint( $cat_id ); |
|
2256 | - wp_delete_term( $cat_id, 'espresso_event_categories' ); |
|
2255 | + $cat_id = absint($cat_id); |
|
2256 | + wp_delete_term($cat_id, 'espresso_event_categories'); |
|
2257 | 2257 | } |
2258 | 2258 | |
2259 | 2259 | |
2260 | 2260 | |
2261 | 2261 | protected function _insert_or_update_category($new_category) { |
2262 | 2262 | |
2263 | - $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category( TRUE ); |
|
2263 | + $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(TRUE); |
|
2264 | 2264 | $success = 0; //we already have a success message so lets not send another. |
2265 | 2265 | |
2266 | - if ( $cat_id ) { |
|
2266 | + if ($cat_id) { |
|
2267 | 2267 | $query_args = array( |
2268 | 2268 | 'action' => 'edit_category', |
2269 | 2269 | 'EVT_CAT_ID' => $cat_id |
2270 | 2270 | ); |
2271 | 2271 | } else { |
2272 | - $query_args = array( 'action' => 'add_category' ); |
|
2272 | + $query_args = array('action' => 'add_category'); |
|
2273 | 2273 | } |
2274 | - $this->_redirect_after_action( $success, '','', $query_args, TRUE ); |
|
2274 | + $this->_redirect_after_action($success, '', '', $query_args, TRUE); |
|
2275 | 2275 | |
2276 | 2276 | } |
2277 | 2277 | |
2278 | 2278 | |
2279 | 2279 | |
2280 | - private function _insert_category( $update = FALSE ) { |
|
2280 | + private function _insert_category($update = FALSE) { |
|
2281 | 2281 | $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : ''; |
2282 | - $category_name= isset( $this->_req_data['category_name'] ) ? $this->_req_data['category_name'] : ''; |
|
2283 | - $category_desc= isset( $this->_req_data['category_desc'] ) ? $this->_req_data['category_desc'] : ''; |
|
2284 | - $category_parent = isset( $this->_req_data['category_parent'] ) ? $this->_req_data['category_parent'] : 0; |
|
2282 | + $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : ''; |
|
2283 | + $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : ''; |
|
2284 | + $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0; |
|
2285 | 2285 | |
2286 | - if ( empty( $category_name ) ) { |
|
2287 | - $msg = __( 'You must add a name for the category.', 'event_espresso' ); |
|
2288 | - EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
2286 | + if (empty($category_name)) { |
|
2287 | + $msg = __('You must add a name for the category.', 'event_espresso'); |
|
2288 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2289 | 2289 | return false; |
2290 | 2290 | } |
2291 | 2291 | |
2292 | - $term_args=array( |
|
2292 | + $term_args = array( |
|
2293 | 2293 | 'name'=>$category_name, |
2294 | 2294 | 'description'=>$category_desc, |
2295 | 2295 | 'parent'=>$category_parent |
2296 | 2296 | ); |
2297 | 2297 | //was the category_identifier input disabled? |
2298 | - if(isset($this->_req_data['category_identifier'])){ |
|
2298 | + if (isset($this->_req_data['category_identifier'])) { |
|
2299 | 2299 | $term_args['slug'] = $this->_req_data['category_identifier']; |
2300 | 2300 | } |
2301 | - $insert_ids = $update ? wp_update_term( $cat_id, 'espresso_event_categories', $term_args ) :wp_insert_term( $category_name, 'espresso_event_categories', $term_args ); |
|
2301 | + $insert_ids = $update ? wp_update_term($cat_id, 'espresso_event_categories', $term_args) : wp_insert_term($category_name, 'espresso_event_categories', $term_args); |
|
2302 | 2302 | |
2303 | - if ( !is_array( $insert_ids ) ) { |
|
2304 | - $msg = __( 'An error occurred and the category has not been saved to the database.', 'event_espresso' ); |
|
2305 | - EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
2303 | + if ( ! is_array($insert_ids)) { |
|
2304 | + $msg = __('An error occurred and the category has not been saved to the database.', 'event_espresso'); |
|
2305 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2306 | 2306 | } else { |
2307 | 2307 | $cat_id = $insert_ids['term_id']; |
2308 | - $msg = sprintf ( __('The category %s was successfuly saved', 'event_espresso'), $category_name ); |
|
2309 | - EE_Error::add_success( $msg ); |
|
2308 | + $msg = sprintf(__('The category %s was successfuly saved', 'event_espresso'), $category_name); |
|
2309 | + EE_Error::add_success($msg); |
|
2310 | 2310 | } |
2311 | 2311 | |
2312 | 2312 | return $cat_id; |
@@ -2315,32 +2315,32 @@ discard block |
||
2315 | 2315 | |
2316 | 2316 | |
2317 | 2317 | |
2318 | - public function get_categories( $per_page = 10, $current_page = 1, $count = FALSE ) { |
|
2318 | + public function get_categories($per_page = 10, $current_page = 1, $count = FALSE) { |
|
2319 | 2319 | global $wpdb; |
2320 | 2320 | |
2321 | 2321 | //testing term stuff |
2322 | - $orderby = isset( $this->_req_data['orderby'] ) ? $this->_req_data['orderby'] : 'Term.term_id'; |
|
2323 | - $order = isset( $this->_req_data['order'] ) ? $this->_req_data['order'] : 'DESC'; |
|
2324 | - $limit = ($current_page-1)*$per_page; |
|
2322 | + $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id'; |
|
2323 | + $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
2324 | + $limit = ($current_page - 1) * $per_page; |
|
2325 | 2325 | |
2326 | - $where = array( 'taxonomy' => 'espresso_event_categories' ); |
|
2326 | + $where = array('taxonomy' => 'espresso_event_categories'); |
|
2327 | 2327 | |
2328 | - if ( isset( $this->_req_data['s'] ) ) { |
|
2329 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
2328 | + if (isset($this->_req_data['s'])) { |
|
2329 | + $sstr = '%'.$this->_req_data['s'].'%'; |
|
2330 | 2330 | $where['OR'] = array( |
2331 | - 'Term.name' => array( 'LIKE', $sstr), |
|
2332 | - 'description' => array( 'LIKE', $sstr ) |
|
2331 | + 'Term.name' => array('LIKE', $sstr), |
|
2332 | + 'description' => array('LIKE', $sstr) |
|
2333 | 2333 | ); |
2334 | 2334 | } |
2335 | 2335 | |
2336 | 2336 | $query_params = array( |
2337 | - $where , |
|
2338 | - 'order_by' => array( $orderby => $order ), |
|
2339 | - 'limit' => $limit . ',' . $per_page, |
|
2337 | + $where, |
|
2338 | + 'order_by' => array($orderby => $order), |
|
2339 | + 'limit' => $limit.','.$per_page, |
|
2340 | 2340 | 'force_join' => array('Term') |
2341 | 2341 | ); |
2342 | 2342 | |
2343 | - $categories = $count ? EEM_Term_Taxonomy::instance()->count( $query_params, 'term_id' ) :EEM_Term_Taxonomy::instance()->get_all( $query_params ); |
|
2343 | + $categories = $count ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id') : EEM_Term_Taxonomy::instance()->get_all($query_params); |
|
2344 | 2344 | |
2345 | 2345 | return $categories; |
2346 | 2346 | } |