@@ -22,7 +22,6 @@ |
||
22 | 22 | /** |
23 | 23 | * Removes the checkin and checkout endpoints from the index for requests |
24 | 24 | * to api versions lowers than 4.8.33 |
25 | - * @param array $routes_on_this_version |
|
26 | 25 | * @param EventEspresso\core\libraries\rest_api\controllers\Base $controller |
27 | 26 | * @return array like $routes_on_this_version |
28 | 27 | */ |
@@ -13,7 +13,7 @@ discard block |
||
13 | 13 | //is for lower than 4.8.33 |
14 | 14 | add_filter( |
15 | 15 | 'FHEE__EventEspresso\core\libraries\rest_api\controllers\Base___get_response_headers', |
16 | - array( $this, 'remove_response_headers' ), |
|
16 | + array($this, 'remove_response_headers'), |
|
17 | 17 | 10, |
18 | 18 | 3 |
19 | 19 | ); |
@@ -26,9 +26,9 @@ discard block |
||
26 | 26 | * @param EventEspresso\core\libraries\rest_api\controllers\Base $controller |
27 | 27 | * @return array like $routes_on_this_version |
28 | 28 | */ |
29 | - public function remove_response_headers( $response_headers, $controller, $requested_version ) { |
|
30 | - if( $controller instanceof Base |
|
31 | - && $this->applies_to_version( $requested_version ) ) { |
|
29 | + public function remove_response_headers($response_headers, $controller, $requested_version) { |
|
30 | + if ($controller instanceof Base |
|
31 | + && $this->applies_to_version($requested_version)) { |
|
32 | 32 | return array(); |
33 | 33 | } |
34 | 34 | return $response_headers; |
@@ -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 | /** |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | |
32 | 32 | class Event_Categories_Admin_List_Table extends EE_Admin_List_Table { |
33 | 33 | |
34 | - public function __construct( $admin_page ) { |
|
34 | + public function __construct($admin_page) { |
|
35 | 35 | parent::__construct($admin_page); |
36 | 36 | } |
37 | 37 | |
@@ -39,8 +39,8 @@ discard block |
||
39 | 39 | |
40 | 40 | |
41 | 41 | protected function _setup_data() { |
42 | - $this->_data = $this->_admin_page->get_categories( $this->_per_page, $this->_current_page); |
|
43 | - $this->_all_data_count = EEM_Term_Taxonomy::instance()->count( array( array( 'taxonomy' => 'espresso_event_categories' ) ) ); |
|
42 | + $this->_data = $this->_admin_page->get_categories($this->_per_page, $this->_current_page); |
|
43 | + $this->_all_data_count = EEM_Term_Taxonomy::instance()->count(array(array('taxonomy' => 'espresso_event_categories'))); |
|
44 | 44 | } |
45 | 45 | |
46 | 46 | |
@@ -49,8 +49,8 @@ discard block |
||
49 | 49 | |
50 | 50 | protected function _set_properties() { |
51 | 51 | $this->_wp_list_args = array( |
52 | - 'singular' => __('event category', 'event_espresso' ), |
|
53 | - 'plural' => __('event categories', 'event_espresso' ), |
|
52 | + 'singular' => __('event category', 'event_espresso'), |
|
53 | + 'plural' => __('event categories', 'event_espresso'), |
|
54 | 54 | 'ajax' => TRUE, //for now, |
55 | 55 | 'screen' => $this->_admin_page->get_current_screen()->id |
56 | 56 | ); |
@@ -64,9 +64,9 @@ discard block |
||
64 | 64 | ); |
65 | 65 | |
66 | 66 | $this->_sortable_columns = array( |
67 | - 'id' => array( 'Term.term_id' => true ), |
|
68 | - 'name' => array( 'Term.slug' => false ), |
|
69 | - 'count' => array( 'term_count' => false ) |
|
67 | + 'id' => array('Term.term_id' => true), |
|
68 | + 'name' => array('Term.slug' => false), |
|
69 | + 'count' => array('term_count' => false) |
|
70 | 70 | ); |
71 | 71 | |
72 | 72 | $this->_primary_column = 'id'; |
@@ -98,7 +98,7 @@ discard block |
||
98 | 98 | |
99 | 99 | |
100 | 100 | public function column_cb($item) { |
101 | - return sprintf( '<input type="checkbox" name="EVT_CAT_ID[]" value="%s" />', $item->get('term_id') ); |
|
101 | + return sprintf('<input type="checkbox" name="EVT_CAT_ID[]" value="%s" />', $item->get('term_id')); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | |
108 | 108 | public function column_id($item) { |
109 | 109 | $content = $item->get('term_id'); |
110 | - $content .= ' <span class="show-on-mobile-view-only">' . $item->get_first_related('Term')->get('name') . '</span>'; |
|
110 | + $content .= ' <span class="show-on-mobile-view-only">'.$item->get_first_related('Term')->get('name').'</span>'; |
|
111 | 111 | return $content; |
112 | 112 | } |
113 | 113 | |
@@ -127,17 +127,17 @@ discard block |
||
127 | 127 | 'EVT_CAT_ID' => $item->get('term_id') |
128 | 128 | ); |
129 | 129 | |
130 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce( $edit_query_args, EVENTS_ADMIN_URL ); |
|
131 | - $delete_link = EE_Admin_Page::add_query_args_and_nonce( $delete_query_args, EVENTS_ADMIN_URL ); |
|
130 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce($edit_query_args, EVENTS_ADMIN_URL); |
|
131 | + $delete_link = EE_Admin_Page::add_query_args_and_nonce($delete_query_args, EVENTS_ADMIN_URL); |
|
132 | 132 | |
133 | 133 | $actions = array( |
134 | - 'edit' => '<a href="' . $edit_link . '" title="' . esc_attr__('Edit Category', 'event_espresso') . '">' . __('Edit', 'event_espresso') . '</a>' |
|
134 | + 'edit' => '<a href="'.$edit_link.'" title="'.esc_attr__('Edit Category', 'event_espresso').'">'.__('Edit', 'event_espresso').'</a>' |
|
135 | 135 | ); |
136 | 136 | |
137 | 137 | |
138 | - $actions['delete'] = '<a href="' . $delete_link . '" title="' . esc_attr__('Delete Category', 'event_espresso') . '">' . __('Delete', 'event_espresso') . '</a>'; |
|
138 | + $actions['delete'] = '<a href="'.$delete_link.'" title="'.esc_attr__('Delete Category', 'event_espresso').'">'.__('Delete', 'event_espresso').'</a>'; |
|
139 | 139 | |
140 | - $content = '<strong><a class="row-title" href="' . $edit_link . '">' . $item->get_first_related('Term')->get('name') . '</a></strong>'; |
|
140 | + $content = '<strong><a class="row-title" href="'.$edit_link.'">'.$item->get_first_related('Term')->get('name').'</a></strong>'; |
|
141 | 141 | $content .= $this->row_actions($actions); |
142 | 142 | return $content; |
143 | 143 | } |
@@ -146,20 +146,20 @@ discard block |
||
146 | 146 | |
147 | 147 | |
148 | 148 | public function column_shortcode($item) { |
149 | - $content = '[ESPRESSO_EVENTS category_slug=' . $item->get_first_related('Term')->get('slug') . ']'; |
|
149 | + $content = '[ESPRESSO_EVENTS category_slug='.$item->get_first_related('Term')->get('slug').']'; |
|
150 | 150 | return $content; |
151 | 151 | } |
152 | 152 | |
153 | 153 | |
154 | 154 | |
155 | 155 | |
156 | - public function column_count( $item ) { |
|
156 | + public function column_count($item) { |
|
157 | 157 | $e_args = array( |
158 | 158 | 'action' => 'default', |
159 | 159 | 'EVT_CAT' => $item->get_first_related('Term')->ID() |
160 | 160 | ); |
161 | - $e_link = EE_Admin_Page::add_query_args_and_nonce( $e_args, EVENTS_ADMIN_URL ); |
|
162 | - $content = '<a href="' . $e_link . '">' . $item->get('term_count') . '</a>'; |
|
161 | + $e_link = EE_Admin_Page::add_query_args_and_nonce($e_args, EVENTS_ADMIN_URL); |
|
162 | + $content = '<a href="'.$e_link.'">'.$item->get('term_count').'</a>'; |
|
163 | 163 | return $content; |
164 | 164 | } |
165 | 165 | } |
@@ -11,8 +11,8 @@ discard block |
||
11 | 11 | class EE_Email_Validation_Strategy extends EE_Text_Validation_Strategy{ |
12 | 12 | |
13 | 13 | /** |
14 | - * @param null $validation_error_message |
|
15 | - */ |
|
14 | + * @param null $validation_error_message |
|
15 | + */ |
|
16 | 16 | public function __construct( $validation_error_message = NULL ) { |
17 | 17 | if( ! $validation_error_message ){ |
18 | 18 | $validation_error_message = __("Please enter a valid email address.", "event_espresso"); |
@@ -38,8 +38,8 @@ discard block |
||
38 | 38 | |
39 | 39 | |
40 | 40 | /** |
41 | - * @return array |
|
42 | - */ |
|
41 | + * @return array |
|
42 | + */ |
|
43 | 43 | function get_jquery_validation_rule_array(){ |
44 | 44 | return array( 'email'=>true, 'messages' => array( 'email' => $this->get_validation_error_message() ) ); |
45 | 45 | } |
@@ -8,16 +8,16 @@ discard block |
||
8 | 8 | * @since 4.6 |
9 | 9 | * |
10 | 10 | */ |
11 | -class EE_Email_Validation_Strategy extends EE_Text_Validation_Strategy{ |
|
11 | +class EE_Email_Validation_Strategy extends EE_Text_Validation_Strategy { |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * @param null $validation_error_message |
15 | 15 | */ |
16 | - public function __construct( $validation_error_message = NULL ) { |
|
17 | - if( ! $validation_error_message ){ |
|
16 | + public function __construct($validation_error_message = NULL) { |
|
17 | + if ( ! $validation_error_message) { |
|
18 | 18 | $validation_error_message = __("Please enter a valid email address.", "event_espresso"); |
19 | 19 | } |
20 | - parent::__construct( $validation_error_message ); |
|
20 | + parent::__construct($validation_error_message); |
|
21 | 21 | } |
22 | 22 | |
23 | 23 | |
@@ -29,9 +29,9 @@ discard block |
||
29 | 29 | * @return bool |
30 | 30 | * @throws \EE_Validation_Error |
31 | 31 | */ |
32 | - function validate( $normalized_value ) { |
|
33 | - if( $normalized_value && ! $this->_validate_email( $normalized_value ) ){ |
|
34 | - throw new EE_Validation_Error( $this->get_validation_error_message(), 'required'); |
|
32 | + function validate($normalized_value) { |
|
33 | + if ($normalized_value && ! $this->_validate_email($normalized_value)) { |
|
34 | + throw new EE_Validation_Error($this->get_validation_error_message(), 'required'); |
|
35 | 35 | } |
36 | 36 | } |
37 | 37 | |
@@ -40,8 +40,8 @@ discard block |
||
40 | 40 | /** |
41 | 41 | * @return array |
42 | 42 | */ |
43 | - function get_jquery_validation_rule_array(){ |
|
44 | - return array( 'email'=>true, 'messages' => array( 'email' => $this->get_validation_error_message() ) ); |
|
43 | + function get_jquery_validation_rule_array() { |
|
44 | + return array('email'=>true, 'messages' => array('email' => $this->get_validation_error_message())); |
|
45 | 45 | } |
46 | 46 | |
47 | 47 | |
@@ -54,29 +54,29 @@ discard block |
||
54 | 54 | * @return bool of whether the email is valid or not |
55 | 55 | * @throws \EE_Validation_Error |
56 | 56 | */ |
57 | - private function _validate_email( $email ) { |
|
58 | - if ( ! preg_match( '/^.+\@\S+\.\S+$/', $email ) ) { |
|
57 | + private function _validate_email($email) { |
|
58 | + if ( ! preg_match('/^.+\@\S+\.\S+$/', $email)) { |
|
59 | 59 | // email not in correct {string}@{string}.{string} format |
60 | 60 | return false; |
61 | 61 | } else { |
62 | - $atIndex = strrpos( $email, "@" ); |
|
63 | - $domain = substr( $email, $atIndex + 1 ); |
|
64 | - $local = substr( $email, 0, $atIndex ); |
|
65 | - $localLen = strlen( $local ); |
|
66 | - $domainLen = strlen( $domain ); |
|
67 | - if ( $localLen < 1 || $localLen > 64 ) { |
|
62 | + $atIndex = strrpos($email, "@"); |
|
63 | + $domain = substr($email, $atIndex + 1); |
|
64 | + $local = substr($email, 0, $atIndex); |
|
65 | + $localLen = strlen($local); |
|
66 | + $domainLen = strlen($domain); |
|
67 | + if ($localLen < 1 || $localLen > 64) { |
|
68 | 68 | // local part length exceeded |
69 | 69 | return false; |
70 | - } else if ( $domainLen < 1 || $domainLen > 255 ) { |
|
70 | + } else if ($domainLen < 1 || $domainLen > 255) { |
|
71 | 71 | // domain part length exceeded |
72 | 72 | return false; |
73 | - } else if ( $local[ 0 ] == '.' || $local[ $localLen - 1 ] == '.' ) { |
|
73 | + } else if ($local[0] == '.' || $local[$localLen - 1] == '.') { |
|
74 | 74 | // local part starts or ends with '.' |
75 | 75 | return false; |
76 | - } else if ( preg_match( '/\\.\\./', $local ) ) { |
|
76 | + } else if (preg_match('/\\.\\./', $local)) { |
|
77 | 77 | // local part has two consecutive dots |
78 | 78 | return false; |
79 | - } else if ( preg_match( '/\\.\\./', $domain ) ) { |
|
79 | + } else if (preg_match('/\\.\\./', $domain)) { |
|
80 | 80 | // domain part has two consecutive dots |
81 | 81 | return false; |
82 | 82 | } else if ( |
@@ -87,8 +87,8 @@ discard block |
||
87 | 87 | ) |
88 | 88 | ) { |
89 | 89 | return false; |
90 | - } else if ( apply_filters( 'FHEE__EE_Email_Validation_Strategy___validate_email__perform_dns_checks', false ) ) { |
|
91 | - if ( ! checkdnsrr( $domain, "MX" ) ) { |
|
90 | + } else if (apply_filters('FHEE__EE_Email_Validation_Strategy___validate_email__perform_dns_checks', false)) { |
|
91 | + if ( ! checkdnsrr($domain, "MX")) { |
|
92 | 92 | // domain not found in MX records |
93 | 93 | throw new EE_Validation_Error( |
94 | 94 | __( |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | 'event_espresso' |
97 | 97 | ) |
98 | 98 | ); |
99 | - } else if ( ! checkdnsrr( $domain, "A" ) ) { |
|
99 | + } else if ( ! checkdnsrr($domain, "A")) { |
|
100 | 100 | // domain not found in A records |
101 | 101 | throw new EE_Validation_Error( |
102 | 102 | __( |
@@ -11,7 +11,7 @@ discard block |
||
11 | 11 | * @since 4.6 |
12 | 12 | * |
13 | 13 | */ |
14 | -class EE_Text_Input_Display_Strategy extends EE_Display_Strategy_Base{ |
|
14 | +class EE_Text_Input_Display_Strategy extends EE_Display_Strategy_Base { |
|
15 | 15 | /** |
16 | 16 | * The html "type" attribute value. default is "text" |
17 | 17 | * @var string |
@@ -23,7 +23,7 @@ discard block |
||
23 | 23 | /** |
24 | 24 | * @param string $type |
25 | 25 | */ |
26 | - function __construct( $type = 'text' ) { |
|
26 | + function __construct($type = 'text') { |
|
27 | 27 | $this->_type = $type; |
28 | 28 | parent::__construct(); |
29 | 29 | } |
@@ -34,10 +34,10 @@ discard block |
||
34 | 34 | * Gets the html "type" attribute's value |
35 | 35 | * @return string |
36 | 36 | */ |
37 | - function get_type(){ |
|
37 | + function get_type() { |
|
38 | 38 | if ( |
39 | 39 | $this->_type == 'email' |
40 | - && ! apply_filters( 'FHEE__EE_Text_Input_Display_Strategy__use_html5_email', false ) |
|
40 | + && ! apply_filters('FHEE__EE_Text_Input_Display_Strategy__use_html5_email', false) |
|
41 | 41 | ) { |
42 | 42 | return 'text'; |
43 | 43 | } |
@@ -50,16 +50,16 @@ discard block |
||
50 | 50 | * |
51 | 51 | * @return string of html to display the field |
52 | 52 | */ |
53 | - function display(){ |
|
54 | - $input = '<input type="'. $this->get_type() .'"'; |
|
55 | - $input .= ' name="' . $this->_input->html_name() . '"'; |
|
56 | - $input .= ' id="' . $this->_input->html_id() . '"'; |
|
57 | - $class = $this->_input->required() ? $this->_input->required_css_class() . ' ' . $this->_input->html_class() : $this->_input->html_class(); |
|
58 | - $input .= ' class="' . $class . '"'; |
|
53 | + function display() { |
|
54 | + $input = '<input type="'.$this->get_type().'"'; |
|
55 | + $input .= ' name="'.$this->_input->html_name().'"'; |
|
56 | + $input .= ' id="'.$this->_input->html_id().'"'; |
|
57 | + $class = $this->_input->required() ? $this->_input->required_css_class().' '.$this->_input->html_class() : $this->_input->html_class(); |
|
58 | + $input .= ' class="'.$class.'"'; |
|
59 | 59 | // add html5 required |
60 | 60 | $input .= $this->_input->required() ? ' required' : ''; |
61 | - $input .= ' value="' . $this->_input->raw_value_in_form() . '"'; |
|
62 | - $input .= ' style="' . $this->_input->html_style() . '"'; |
|
61 | + $input .= ' value="'.$this->_input->raw_value_in_form().'"'; |
|
62 | + $input .= ' style="'.$this->_input->html_style().'"'; |
|
63 | 63 | $input .= $this->_input->html_other_attributes(); |
64 | 64 | $input .= '/>'; |
65 | 65 | return $input; |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @subpackage |
9 | 9 | * @author Mike Nelson |
10 | 10 | */ |
11 | -abstract class EE_Form_Input_Base extends EE_Form_Section_Validatable{ |
|
11 | +abstract class EE_Form_Input_Base extends EE_Form_Section_Validatable { |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * the input's name attribute |
@@ -141,66 +141,66 @@ discard block |
||
141 | 141 | * @type EE_Validation_Strategy_Base[] $validation_strategies |
142 | 142 | * } |
143 | 143 | */ |
144 | - public function __construct( $input_args = array() ){ |
|
145 | - $input_args = apply_filters( 'FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this ); |
|
144 | + public function __construct($input_args = array()) { |
|
145 | + $input_args = apply_filters('FHEE__EE_Form_Input_Base___construct__input_args', $input_args, $this); |
|
146 | 146 | // the following properties must be cast as arrays |
147 | 147 | $set_as_array = array( |
148 | 148 | 'validation_strategies' => true |
149 | 149 | ); |
150 | 150 | // loop thru incoming options |
151 | - foreach( $input_args as $key => $value ) { |
|
151 | + foreach ($input_args as $key => $value) { |
|
152 | 152 | // add underscore to $key to match property names |
153 | - $_key = '_' . $key; |
|
154 | - if ( property_exists( $this, $_key )) { |
|
153 | + $_key = '_'.$key; |
|
154 | + if (property_exists($this, $_key)) { |
|
155 | 155 | // first check if this property needs to be set as an array |
156 | - if ( isset( $set_as_array[ $key ] )) { |
|
156 | + if (isset($set_as_array[$key])) { |
|
157 | 157 | // ensure value is an array |
158 | - $value = is_array( $value ) ? $value : array( get_class( $value ), $value ); |
|
158 | + $value = is_array($value) ? $value : array(get_class($value), $value); |
|
159 | 159 | // and merge with existing values |
160 | - $this->{$_key} = array_merge( $this->{$_key}, $value ); |
|
160 | + $this->{$_key} = array_merge($this->{$_key}, $value); |
|
161 | 161 | } else { |
162 | 162 | $this->{$_key} = $value; |
163 | 163 | } |
164 | 164 | } |
165 | 165 | } |
166 | 166 | // ensure that "required" is set correctly |
167 | - $this->set_required( $this->_required, isset( $input_args[ 'required_validation_error_message' ] ) ? $input_args[ 'required_validation_error_message' ] : NULL ); |
|
167 | + $this->set_required($this->_required, isset($input_args['required_validation_error_message']) ? $input_args['required_validation_error_message'] : NULL); |
|
168 | 168 | |
169 | 169 | //$this->_html_name_specified = isset( $input_args['html_name'] ) ? TRUE : FALSE; |
170 | 170 | |
171 | 171 | $this->_display_strategy->_construct_finalize($this); |
172 | - if ( $this->_validation_strategies ){ |
|
173 | - foreach( $this->_validation_strategies as $validation_strategy ){ |
|
172 | + if ($this->_validation_strategies) { |
|
173 | + foreach ($this->_validation_strategies as $validation_strategy) { |
|
174 | 174 | $validation_strategy->_construct_finalize($this); |
175 | 175 | } |
176 | 176 | } |
177 | 177 | |
178 | - if( ! $this->_normalization_strategy){ |
|
178 | + if ( ! $this->_normalization_strategy) { |
|
179 | 179 | $this->_normalization_strategy = new EE_Text_Normalization(); |
180 | 180 | } |
181 | 181 | $this->_normalization_strategy->_construct_finalize($this); |
182 | 182 | |
183 | 183 | //at least we can use the normalization strategy to populate the default |
184 | - if( isset( $input_args[ 'default' ] ) ) { |
|
185 | - $this->set_default( $input_args[ 'default' ] ); |
|
184 | + if (isset($input_args['default'])) { |
|
185 | + $this->set_default($input_args['default']); |
|
186 | 186 | } |
187 | 187 | |
188 | - if( ! $this->_sensitive_data_removal_strategy){ |
|
188 | + if ( ! $this->_sensitive_data_removal_strategy) { |
|
189 | 189 | $this->_sensitive_data_removal_strategy = new EE_No_Sensitive_Data_Removal(); |
190 | 190 | } |
191 | 191 | $this->_sensitive_data_removal_strategy->_construct_finalize($this); |
192 | - parent::__construct( $input_args ); |
|
192 | + parent::__construct($input_args); |
|
193 | 193 | } |
194 | 194 | |
195 | 195 | /** |
196 | 196 | * Sets the html_name to its default value, if none was specified in teh constructor. |
197 | 197 | * Calculation involves using the name and the parent's html_name |
198 | 198 | */ |
199 | - protected function _set_default_html_name_if_empty(){ |
|
200 | - if( ! $this->_html_name){ |
|
201 | - if( $this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper){ |
|
202 | - $this->_html_name = $this->_parent_section->html_name_prefix() . "[{$this->name()}]"; |
|
203 | - }else{ |
|
199 | + protected function _set_default_html_name_if_empty() { |
|
200 | + if ( ! $this->_html_name) { |
|
201 | + if ($this->_parent_section && $this->_parent_section instanceof EE_Form_Section_Proper) { |
|
202 | + $this->_html_name = $this->_parent_section->html_name_prefix()."[{$this->name()}]"; |
|
203 | + } else { |
|
204 | 204 | $this->_html_name = $this->name(); |
205 | 205 | } |
206 | 206 | } |
@@ -215,12 +215,12 @@ discard block |
||
215 | 215 | function _construct_finalize($parent_form_section, $name) { |
216 | 216 | parent::_construct_finalize($parent_form_section, $name); |
217 | 217 | $this->_set_default_html_name_if_empty(); |
218 | - if( ! $this->_html_label ){ |
|
219 | - if( ! $this->_html_label_text){ |
|
220 | - $this->_html_label_text = ucwords( str_replace("_"," ",$name)); |
|
218 | + if ( ! $this->_html_label) { |
|
219 | + if ( ! $this->_html_label_text) { |
|
220 | + $this->_html_label_text = ucwords(str_replace("_", " ", $name)); |
|
221 | 221 | } |
222 | 222 | } |
223 | - do_action( 'AHEE__EE_Form_Input_Base___construct_finalize__end', $this, $parent_form_section, $name ); |
|
223 | + do_action('AHEE__EE_Form_Input_Base___construct_finalize__end', $this, $parent_form_section, $name); |
|
224 | 224 | } |
225 | 225 | |
226 | 226 | /** |
@@ -228,10 +228,10 @@ discard block |
||
228 | 228 | * @return EE_Display_Strategy_Base |
229 | 229 | * @throws EE_Error |
230 | 230 | */ |
231 | - protected function _get_display_strategy(){ |
|
232 | - if( ! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base){ |
|
233 | - throw new EE_Error(sprintf(__("Cannot get display strategy for form input with name %s and id %s, because it has not been set in the constructor", "event_espresso"),$this->html_name(),$this->html_id())); |
|
234 | - }else{ |
|
231 | + protected function _get_display_strategy() { |
|
232 | + if ( ! $this->_display_strategy || ! $this->_display_strategy instanceof EE_Display_Strategy_Base) { |
|
233 | + throw new EE_Error(sprintf(__("Cannot get display strategy for form input with name %s and id %s, because it has not been set in the constructor", "event_espresso"), $this->html_name(), $this->html_id())); |
|
234 | + } else { |
|
235 | 235 | return $this->_display_strategy; |
236 | 236 | } |
237 | 237 | } |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | * Sets the display strategy. |
240 | 240 | * @param EE_Display_Strategy_Base $strategy |
241 | 241 | */ |
242 | - protected function _set_display_strategy(EE_Display_Strategy_Base $strategy){ |
|
242 | + protected function _set_display_strategy(EE_Display_Strategy_Base $strategy) { |
|
243 | 243 | $this->_display_strategy = $strategy; |
244 | 244 | } |
245 | 245 | |
@@ -247,7 +247,7 @@ discard block |
||
247 | 247 | * Sets the sanitization strategy |
248 | 248 | * @param EE_Normalization_Strategy_Base $strategy |
249 | 249 | */ |
250 | - protected function _set_normalization_strategy(EE_Normalization_Strategy_Base $strategy){ |
|
250 | + protected function _set_normalization_strategy(EE_Normalization_Strategy_Base $strategy) { |
|
251 | 251 | $this->_normalization_strategy = $strategy; |
252 | 252 | } |
253 | 253 | |
@@ -273,14 +273,14 @@ discard block |
||
273 | 273 | * Gets the display strategy for this input |
274 | 274 | * @return EE_Display_Strategy_Base |
275 | 275 | */ |
276 | - public function get_display_strategy(){ |
|
276 | + public function get_display_strategy() { |
|
277 | 277 | return $this->_display_strategy; |
278 | 278 | } |
279 | 279 | /** |
280 | 280 | * Overwrites the display strategy |
281 | 281 | * @param EE_Display_Strategy_Base $display_strategy |
282 | 282 | */ |
283 | - public function set_display_strategy($display_strategy){ |
|
283 | + public function set_display_strategy($display_strategy) { |
|
284 | 284 | $this->_display_strategy = $display_strategy; |
285 | 285 | $this->_display_strategy->_construct_finalize($this); |
286 | 286 | } |
@@ -288,14 +288,14 @@ discard block |
||
288 | 288 | * Gets the normalization strategy set on this input |
289 | 289 | * @return EE_Normalization_Strategy_Base |
290 | 290 | */ |
291 | - public function get_normalization_strategy(){ |
|
291 | + public function get_normalization_strategy() { |
|
292 | 292 | return $this->_normalization_strategy; |
293 | 293 | } |
294 | 294 | /** |
295 | 295 | * Overwrites the normalization strategy |
296 | 296 | * @param EE_Normalization_Strategy_Base $normalization_strategy |
297 | 297 | */ |
298 | - public function set_normalization_strategy($normalization_strategy){ |
|
298 | + public function set_normalization_strategy($normalization_strategy) { |
|
299 | 299 | $this->_normalization_strategy = $normalization_strategy; |
300 | 300 | $this->_normalization_strategy->_construct_finalize($this); |
301 | 301 | } |
@@ -304,10 +304,10 @@ discard block |
||
304 | 304 | * Returns all teh validation strategies which apply to this field, numerically indexed |
305 | 305 | * @return EE_Validation_Strategy_Base[] |
306 | 306 | */ |
307 | - public function get_validation_strategies(){ |
|
308 | - if(is_array($this->_validation_strategies)){ |
|
307 | + public function get_validation_strategies() { |
|
308 | + if (is_array($this->_validation_strategies)) { |
|
309 | 309 | return $this->_validation_strategies; |
310 | - }else{ |
|
310 | + } else { |
|
311 | 311 | return array(); |
312 | 312 | } |
313 | 313 | |
@@ -317,9 +317,9 @@ discard block |
||
317 | 317 | * @param EE_Validation_Strategy_Base $validation_strategy |
318 | 318 | * @return void |
319 | 319 | */ |
320 | - protected function _add_validation_strategy( EE_Validation_Strategy_Base $validation_strategy ){ |
|
321 | - $validation_strategy->_construct_finalize( $this ); |
|
322 | - $this->_validation_strategies[ get_class($validation_strategy) ] = $validation_strategy; |
|
320 | + protected function _add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy) { |
|
321 | + $validation_strategy->_construct_finalize($this); |
|
322 | + $this->_validation_strategies[get_class($validation_strategy)] = $validation_strategy; |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | /** |
@@ -327,18 +327,18 @@ discard block |
||
327 | 327 | * @param EE_Validation_Strategy_Base $validation_strategy |
328 | 328 | * @return void |
329 | 329 | */ |
330 | - public function add_validation_strategy( EE_Validation_Strategy_Base $validation_strategy ) { |
|
331 | - $this->_add_validation_strategy( $validation_strategy ); |
|
330 | + public function add_validation_strategy(EE_Validation_Strategy_Base $validation_strategy) { |
|
331 | + $this->_add_validation_strategy($validation_strategy); |
|
332 | 332 | } |
333 | 333 | |
334 | 334 | /** |
335 | 335 | * The classname of the validation strategy to remove |
336 | 336 | * @param string $validation_strategy_classname |
337 | 337 | */ |
338 | - public function remove_validation_strategy( $validation_strategy_classname ) { |
|
339 | - foreach( $this->_validation_strategies as $key => $validation_strategy ){ |
|
340 | - if( is_subclass_of( $validation_strategy, $validation_strategy_classname ) ){ |
|
341 | - unset( $this->_validation_strategies[ $key ] ); |
|
338 | + public function remove_validation_strategy($validation_strategy_classname) { |
|
339 | + foreach ($this->_validation_strategies as $key => $validation_strategy) { |
|
340 | + if (is_subclass_of($validation_strategy, $validation_strategy_classname)) { |
|
341 | + unset($this->_validation_strategies[$key]); |
|
342 | 342 | } |
343 | 343 | } |
344 | 344 | } |
@@ -347,7 +347,7 @@ discard block |
||
347 | 347 | * to the parent form's layout strategy |
348 | 348 | * @return string |
349 | 349 | */ |
350 | - public function get_html_and_js(){ |
|
350 | + public function get_html_and_js() { |
|
351 | 351 | return $this->_parent_section->get_html_for_input($this); |
352 | 352 | } |
353 | 353 | /** |
@@ -356,7 +356,7 @@ discard block |
||
356 | 356 | * Makes sure the JS and CSS are enqueued for it |
357 | 357 | * @return string |
358 | 358 | */ |
359 | - public function get_html_for_input(){ |
|
359 | + public function get_html_for_input() { |
|
360 | 360 | return $this->_get_display_strategy()->display(); |
361 | 361 | } |
362 | 362 | |
@@ -366,7 +366,7 @@ discard block |
||
366 | 366 | * @return string |
367 | 367 | */ |
368 | 368 | public function html_other_attributes() { |
369 | - return ! empty( $this->_html_other_attributes ) ? ' ' . $this->_html_other_attributes : ''; |
|
369 | + return ! empty($this->_html_other_attributes) ? ' '.$this->_html_other_attributes : ''; |
|
370 | 370 | } |
371 | 371 | |
372 | 372 | |
@@ -374,7 +374,7 @@ discard block |
||
374 | 374 | /** |
375 | 375 | * @param string $html_other_attributes |
376 | 376 | */ |
377 | - public function set_html_other_attributes( $html_other_attributes ) { |
|
377 | + public function set_html_other_attributes($html_other_attributes) { |
|
378 | 378 | $this->_html_other_attributes = $html_other_attributes; |
379 | 379 | } |
380 | 380 | |
@@ -383,7 +383,7 @@ discard block |
||
383 | 383 | * according to the form section's layout strategy |
384 | 384 | * @return string |
385 | 385 | */ |
386 | - public function get_html_for_label(){ |
|
386 | + public function get_html_for_label() { |
|
387 | 387 | return $this->_parent_section->get_layout_strategy()->display_label($this); |
388 | 388 | } |
389 | 389 | /** |
@@ -391,7 +391,7 @@ discard block |
||
391 | 391 | * according to the form section's layout strategy |
392 | 392 | * @return string |
393 | 393 | */ |
394 | - public function get_html_for_errors(){ |
|
394 | + public function get_html_for_errors() { |
|
395 | 395 | return $this->_parent_section->get_layout_strategy()->display_errors($this); |
396 | 396 | } |
397 | 397 | /** |
@@ -399,7 +399,7 @@ discard block |
||
399 | 399 | * according to the form section's layout strategy |
400 | 400 | * @return string |
401 | 401 | */ |
402 | - public function get_html_for_help(){ |
|
402 | + public function get_html_for_help() { |
|
403 | 403 | return $this->_parent_section->get_layout_strategy()->display_help_text($this); |
404 | 404 | } |
405 | 405 | /** |
@@ -408,20 +408,20 @@ discard block |
||
408 | 408 | * @return boolean |
409 | 409 | */ |
410 | 410 | protected function _validate() { |
411 | - if(is_array($this->_validation_strategies)){ |
|
412 | - foreach($this->_validation_strategies as $validation_strategy){ |
|
413 | - if ( $validation_strategy instanceof EE_Validation_Strategy_Base ) { |
|
414 | - try{ |
|
411 | + if (is_array($this->_validation_strategies)) { |
|
412 | + foreach ($this->_validation_strategies as $validation_strategy) { |
|
413 | + if ($validation_strategy instanceof EE_Validation_Strategy_Base) { |
|
414 | + try { |
|
415 | 415 | $validation_strategy->validate($this->normalized_value()); |
416 | - }catch(EE_Validation_Error $e){ |
|
416 | + } catch (EE_Validation_Error $e) { |
|
417 | 417 | $this->add_validation_error($e); |
418 | 418 | } |
419 | 419 | } |
420 | 420 | } |
421 | 421 | } |
422 | - if( $this->get_validation_errors()){ |
|
422 | + if ($this->get_validation_errors()) { |
|
423 | 423 | return false; |
424 | - }else{ |
|
424 | + } else { |
|
425 | 425 | return true; |
426 | 426 | } |
427 | 427 | } |
@@ -434,8 +434,8 @@ discard block |
||
434 | 434 | * @param string $value |
435 | 435 | * @return null|string |
436 | 436 | */ |
437 | - private function _sanitize($value){ |
|
438 | - return $value !== NULL ?stripslashes(html_entity_decode($value)) : NULL;//don't sanitize_text_field |
|
437 | + private function _sanitize($value) { |
|
438 | + return $value !== NULL ? stripslashes(html_entity_decode($value)) : NULL; //don't sanitize_text_field |
|
439 | 439 | } |
440 | 440 | |
441 | 441 | |
@@ -447,24 +447,24 @@ discard block |
||
447 | 447 | * @param array $req_data like $_POST |
448 | 448 | * @return boolean whether or not there was an error |
449 | 449 | */ |
450 | - protected function _normalize( $req_data ) { |
|
450 | + protected function _normalize($req_data) { |
|
451 | 451 | //any existing validation errors don't apply so clear them |
452 | 452 | $this->_validation_errors = array(); |
453 | 453 | try { |
454 | - $raw_input = $this->find_form_data_for_this_section( $req_data ); |
|
454 | + $raw_input = $this->find_form_data_for_this_section($req_data); |
|
455 | 455 | //super simple sanitization for now |
456 | - if ( is_array( $raw_input )) { |
|
456 | + if (is_array($raw_input)) { |
|
457 | 457 | $this->_raw_value = array(); |
458 | - foreach( $raw_input as $key => $value ) { |
|
459 | - $this->_raw_value[ $key ] = $this->_sanitize( $value ); |
|
458 | + foreach ($raw_input as $key => $value) { |
|
459 | + $this->_raw_value[$key] = $this->_sanitize($value); |
|
460 | 460 | } |
461 | 461 | } else { |
462 | - $this->_raw_value = $this->_sanitize( $raw_input ); |
|
462 | + $this->_raw_value = $this->_sanitize($raw_input); |
|
463 | 463 | } |
464 | 464 | //we want ot mostly leave the input alone in case we need to re-display it to the user |
465 | - $this->_normalized_value = $this->_normalization_strategy->normalize( $this->raw_value() ); |
|
466 | - } catch ( EE_Validation_Error $e ) { |
|
467 | - $this->add_validation_error( $e ); |
|
465 | + $this->_normalized_value = $this->_normalization_strategy->normalize($this->raw_value()); |
|
466 | + } catch (EE_Validation_Error $e) { |
|
467 | + $this->add_validation_error($e); |
|
468 | 468 | } |
469 | 469 | } |
470 | 470 | |
@@ -473,7 +473,7 @@ discard block |
||
473 | 473 | /** |
474 | 474 | * @return string |
475 | 475 | */ |
476 | - public function html_name(){ |
|
476 | + public function html_name() { |
|
477 | 477 | return $this->_html_name; |
478 | 478 | } |
479 | 479 | |
@@ -482,8 +482,8 @@ discard block |
||
482 | 482 | /** |
483 | 483 | * @return string |
484 | 484 | */ |
485 | - function html_label_id(){ |
|
486 | - return ! empty( $this->_html_label_id ) ? $this->_html_label_id : $this->_html_id . '-lbl'; |
|
485 | + function html_label_id() { |
|
486 | + return ! empty($this->_html_label_id) ? $this->_html_label_id : $this->_html_id.'-lbl'; |
|
487 | 487 | } |
488 | 488 | |
489 | 489 | |
@@ -491,7 +491,7 @@ discard block |
||
491 | 491 | /** |
492 | 492 | * @return string |
493 | 493 | */ |
494 | - function html_label_class(){ |
|
494 | + function html_label_class() { |
|
495 | 495 | return $this->_html_label_class; |
496 | 496 | } |
497 | 497 | |
@@ -500,7 +500,7 @@ discard block |
||
500 | 500 | /** |
501 | 501 | * @return string |
502 | 502 | */ |
503 | - function html_label_style(){ |
|
503 | + function html_label_style() { |
|
504 | 504 | return $this->_html_label_style; |
505 | 505 | } |
506 | 506 | |
@@ -509,7 +509,7 @@ discard block |
||
509 | 509 | /** |
510 | 510 | * @return string |
511 | 511 | */ |
512 | - function html_label_text(){ |
|
512 | + function html_label_text() { |
|
513 | 513 | return $this->_html_label_text; |
514 | 514 | } |
515 | 515 | |
@@ -518,7 +518,7 @@ discard block |
||
518 | 518 | /** |
519 | 519 | * @return string |
520 | 520 | */ |
521 | - function html_help_text(){ |
|
521 | + function html_help_text() { |
|
522 | 522 | return $this->_html_help_text; |
523 | 523 | } |
524 | 524 | |
@@ -527,7 +527,7 @@ discard block |
||
527 | 527 | /** |
528 | 528 | * @return string |
529 | 529 | */ |
530 | - function html_help_class(){ |
|
530 | + function html_help_class() { |
|
531 | 531 | return $this->_html_help_class; |
532 | 532 | } |
533 | 533 | |
@@ -536,7 +536,7 @@ discard block |
||
536 | 536 | /** |
537 | 537 | * @return string |
538 | 538 | */ |
539 | - function html_help_style(){ |
|
539 | + function html_help_style() { |
|
540 | 540 | return $this->_html_style; |
541 | 541 | } |
542 | 542 | /** |
@@ -549,7 +549,7 @@ discard block |
||
549 | 549 | * in which case, we would have stored the malicious content to our database. |
550 | 550 | * @return string |
551 | 551 | */ |
552 | - function raw_value(){ |
|
552 | + function raw_value() { |
|
553 | 553 | return $this->_raw_value; |
554 | 554 | } |
555 | 555 | /** |
@@ -557,15 +557,15 @@ discard block |
||
557 | 557 | * it escapes all html entities |
558 | 558 | * @return string |
559 | 559 | */ |
560 | - function raw_value_in_form(){ |
|
561 | - return htmlentities($this->raw_value(),ENT_QUOTES, 'UTF-8'); |
|
560 | + function raw_value_in_form() { |
|
561 | + return htmlentities($this->raw_value(), ENT_QUOTES, 'UTF-8'); |
|
562 | 562 | } |
563 | 563 | /** |
564 | 564 | * returns the value after it's been sanitized, and then converted into it's proper type |
565 | 565 | * in PHP. Eg, a string, an int, an array, |
566 | 566 | * @return mixed |
567 | 567 | */ |
568 | - function normalized_value(){ |
|
568 | + function normalized_value() { |
|
569 | 569 | return $this->_normalized_value; |
570 | 570 | } |
571 | 571 | |
@@ -575,7 +575,7 @@ discard block |
||
575 | 575 | * the best thing to display |
576 | 576 | * @return string |
577 | 577 | */ |
578 | - function pretty_value(){ |
|
578 | + function pretty_value() { |
|
579 | 579 | return $this->_normalized_value; |
580 | 580 | } |
581 | 581 | /** |
@@ -594,19 +594,19 @@ discard block |
||
594 | 594 | }</code> |
595 | 595 | * @return array |
596 | 596 | */ |
597 | - function get_jquery_validation_rules(){ |
|
597 | + function get_jquery_validation_rules() { |
|
598 | 598 | |
599 | 599 | $jquery_validation_rules = array(); |
600 | - foreach($this->get_validation_strategies() as $validation_strategy){ |
|
600 | + foreach ($this->get_validation_strategies() as $validation_strategy) { |
|
601 | 601 | $jquery_validation_rules = array_replace_recursive( |
602 | 602 | $jquery_validation_rules, |
603 | 603 | $validation_strategy->get_jquery_validation_rule_array() |
604 | 604 | ); |
605 | 605 | } |
606 | 606 | |
607 | - if(! empty($jquery_validation_rules)){ |
|
608 | - $jquery_validation_js[ $this->html_id( TRUE ) ] = $jquery_validation_rules; |
|
609 | - }else{ |
|
607 | + if ( ! empty($jquery_validation_rules)) { |
|
608 | + $jquery_validation_js[$this->html_id(TRUE)] = $jquery_validation_rules; |
|
609 | + } else { |
|
610 | 610 | return array(); |
611 | 611 | } |
612 | 612 | return $jquery_validation_js; |
@@ -618,9 +618,9 @@ discard block |
||
618 | 618 | * @param mixed $value |
619 | 619 | * @return void |
620 | 620 | */ |
621 | - function set_default($value){ |
|
621 | + function set_default($value) { |
|
622 | 622 | $this->_normalized_value = $value; |
623 | - $this->_raw_value = $this->_normalization_strategy->unnormalize( $value ); |
|
623 | + $this->_raw_value = $this->_normalization_strategy->unnormalize($value); |
|
624 | 624 | } |
625 | 625 | |
626 | 626 | /** |
@@ -628,7 +628,7 @@ discard block |
||
628 | 628 | * @param string $label |
629 | 629 | * @return void |
630 | 630 | */ |
631 | - function set_html_label_text($label){ |
|
631 | + function set_html_label_text($label) { |
|
632 | 632 | $this->_html_label_text = $label; |
633 | 633 | } |
634 | 634 | |
@@ -640,12 +640,12 @@ discard block |
||
640 | 640 | * @param boolean $required |
641 | 641 | * @param null $required_text |
642 | 642 | */ |
643 | - function set_required($required = true, $required_text = NULL ){ |
|
644 | - $required = filter_var( $required, FILTER_VALIDATE_BOOLEAN ); |
|
645 | - if ( $required ) { |
|
646 | - $this->_add_validation_strategy( new EE_Required_Validation_Strategy( $required_text ) ); |
|
643 | + function set_required($required = true, $required_text = NULL) { |
|
644 | + $required = filter_var($required, FILTER_VALIDATE_BOOLEAN); |
|
645 | + if ($required) { |
|
646 | + $this->_add_validation_strategy(new EE_Required_Validation_Strategy($required_text)); |
|
647 | 647 | } else { |
648 | - unset( $this->_validation_strategies[ 'EE_Required_Validation_Strategy' ] ); |
|
648 | + unset($this->_validation_strategies['EE_Required_Validation_Strategy']); |
|
649 | 649 | } |
650 | 650 | $this->_required = $required; |
651 | 651 | } |
@@ -653,7 +653,7 @@ discard block |
||
653 | 653 | * Returns whether or not this field is required |
654 | 654 | * @return boolean |
655 | 655 | */ |
656 | - public function required(){ |
|
656 | + public function required() { |
|
657 | 657 | return $this->_required; |
658 | 658 | } |
659 | 659 | |
@@ -662,7 +662,7 @@ discard block |
||
662 | 662 | /** |
663 | 663 | * @param string $required_css_class |
664 | 664 | */ |
665 | - public function set_required_css_class( $required_css_class ) { |
|
665 | + public function set_required_css_class($required_css_class) { |
|
666 | 666 | $this->_required_css_class = $required_css_class; |
667 | 667 | } |
668 | 668 | |
@@ -681,7 +681,7 @@ discard block |
||
681 | 681 | * Sets the help text, in case |
682 | 682 | * @param string $text |
683 | 683 | */ |
684 | - public function set_html_help_text($text){ |
|
684 | + public function set_html_help_text($text) { |
|
685 | 685 | $this->_html_help_text = $text; |
686 | 686 | } |
687 | 687 | /** |
@@ -693,8 +693,8 @@ discard block |
||
693 | 693 | public function clean_sensitive_data() { |
694 | 694 | //if we do ANY kind of sensitive data removal on this, then just clear out the raw value |
695 | 695 | //if we need more logic than this we'll make a strategy for it |
696 | - if( $this->_sensitive_data_removal_strategy && |
|
697 | - ! $this->_sensitive_data_removal_strategy instanceof EE_No_Sensitive_Data_Removal ){ |
|
696 | + if ($this->_sensitive_data_removal_strategy && |
|
697 | + ! $this->_sensitive_data_removal_strategy instanceof EE_No_Sensitive_Data_Removal) { |
|
698 | 698 | $this->_raw_value = NULL; |
699 | 699 | } |
700 | 700 | //and clean the normalized value according to the appropriate strategy |
@@ -708,10 +708,10 @@ discard block |
||
708 | 708 | * @param string $button_size |
709 | 709 | * @param string $other_attributes |
710 | 710 | */ |
711 | - public function set_button_css_attributes( $primary = TRUE, $button_size = '', $other_attributes = '' ) { |
|
711 | + public function set_button_css_attributes($primary = TRUE, $button_size = '', $other_attributes = '') { |
|
712 | 712 | $button_css_attributes = 'button'; |
713 | 713 | $button_css_attributes .= $primary === TRUE ? ' button-primary' : ' button-secondary'; |
714 | - switch ( $button_size ) { |
|
714 | + switch ($button_size) { |
|
715 | 715 | case 'xs' : |
716 | 716 | case 'extra-small' : |
717 | 717 | $button_css_attributes .= ' button-xs'; |
@@ -732,7 +732,7 @@ discard block |
||
732 | 732 | default : |
733 | 733 | $button_css_attributes .= ''; |
734 | 734 | } |
735 | - $this->_button_css_attributes .= ! empty( $other_attributes ) ? $button_css_attributes . ' ' . $other_attributes : $button_css_attributes; |
|
735 | + $this->_button_css_attributes .= ! empty($other_attributes) ? $button_css_attributes.' '.$other_attributes : $button_css_attributes; |
|
736 | 736 | } |
737 | 737 | |
738 | 738 | |
@@ -741,7 +741,7 @@ discard block |
||
741 | 741 | * @return string |
742 | 742 | */ |
743 | 743 | public function button_css_attributes() { |
744 | - if ( empty( $this->_button_css_attributes )) { |
|
744 | + if (empty($this->_button_css_attributes)) { |
|
745 | 745 | $this->set_button_css_attributes(); |
746 | 746 | } |
747 | 747 | return $this->_button_css_attributes; |
@@ -761,27 +761,27 @@ discard block |
||
761 | 761 | * @param array $req_data |
762 | 762 | * @return mixed whatever the raw value of this form section is in the request data |
763 | 763 | */ |
764 | - public function find_form_data_for_this_section( $req_data ){ |
|
764 | + public function find_form_data_for_this_section($req_data) { |
|
765 | 765 | // break up the html name by "[]" |
766 | - if ( strpos( $this->html_name(), '[' ) !== FALSE ) { |
|
767 | - $before_any_brackets = substr( $this->html_name(), 0, strpos($this->html_name(), '[') ); |
|
766 | + if (strpos($this->html_name(), '[') !== FALSE) { |
|
767 | + $before_any_brackets = substr($this->html_name(), 0, strpos($this->html_name(), '[')); |
|
768 | 768 | } else { |
769 | 769 | $before_any_brackets = $this->html_name(); |
770 | 770 | } |
771 | 771 | // grab all of the segments |
772 | - preg_match_all('~\[([^]]*)\]~',$this->html_name(), $matches); |
|
773 | - if( isset( $matches[ 1 ] ) && is_array( $matches[ 1 ] ) ){ |
|
774 | - $name_parts = $matches[ 1 ]; |
|
772 | + preg_match_all('~\[([^]]*)\]~', $this->html_name(), $matches); |
|
773 | + if (isset($matches[1]) && is_array($matches[1])) { |
|
774 | + $name_parts = $matches[1]; |
|
775 | 775 | array_unshift($name_parts, $before_any_brackets); |
776 | - }else{ |
|
777 | - $name_parts = array( $before_any_brackets ); |
|
776 | + } else { |
|
777 | + $name_parts = array($before_any_brackets); |
|
778 | 778 | } |
779 | 779 | // now get the value for the input |
780 | 780 | $value = $this->_find_form_data_for_this_section_using_name_parts($name_parts, $req_data); |
781 | - if( $value === NULL ){ |
|
781 | + if ($value === NULL) { |
|
782 | 782 | //check if this thing's name is at the TOP level of the request data |
783 | - if( isset( $req_data[ $this->name() ] ) ){ |
|
784 | - $value = $req_data[ $this->name() ]; |
|
783 | + if (isset($req_data[$this->name()])) { |
|
784 | + $value = $req_data[$this->name()]; |
|
785 | 785 | } |
786 | 786 | } |
787 | 787 | return $value; |
@@ -795,15 +795,15 @@ discard block |
||
795 | 795 | * @param array $req_data |
796 | 796 | * @return array | NULL |
797 | 797 | */ |
798 | - public function _find_form_data_for_this_section_using_name_parts($html_name_parts, $req_data){ |
|
799 | - $first_part_to_consider = array_shift( $html_name_parts ); |
|
800 | - if( isset( $req_data[ $first_part_to_consider ] ) ){ |
|
801 | - if( empty($html_name_parts ) ){ |
|
802 | - return $req_data[ $first_part_to_consider ]; |
|
803 | - }else{ |
|
804 | - return $this->_find_form_data_for_this_section_using_name_parts($html_name_parts, $req_data[ $first_part_to_consider ] ); |
|
798 | + public function _find_form_data_for_this_section_using_name_parts($html_name_parts, $req_data) { |
|
799 | + $first_part_to_consider = array_shift($html_name_parts); |
|
800 | + if (isset($req_data[$first_part_to_consider])) { |
|
801 | + if (empty($html_name_parts)) { |
|
802 | + return $req_data[$first_part_to_consider]; |
|
803 | + } else { |
|
804 | + return $this->_find_form_data_for_this_section_using_name_parts($html_name_parts, $req_data[$first_part_to_consider]); |
|
805 | 805 | } |
806 | - }else{ |
|
806 | + } else { |
|
807 | 807 | return NULL; |
808 | 808 | } |
809 | 809 | } |
@@ -815,14 +815,14 @@ discard block |
||
815 | 815 | * @param array $req_data like $_POST |
816 | 816 | * @return boolean |
817 | 817 | */ |
818 | - public function form_data_present_in($req_data = NULL){ |
|
819 | - if( $req_data === NULL ){ |
|
818 | + public function form_data_present_in($req_data = NULL) { |
|
819 | + if ($req_data === NULL) { |
|
820 | 820 | $req_data = $_POST; |
821 | 821 | } |
822 | - $checked_value = $this->find_form_data_for_this_section( $req_data ); |
|
823 | - if( $checked_value !== null ){ |
|
822 | + $checked_value = $this->find_form_data_for_this_section($req_data); |
|
823 | + if ($checked_value !== null) { |
|
824 | 824 | return TRUE; |
825 | - }else{ |
|
825 | + } else { |
|
826 | 826 | return FALSE; |
827 | 827 | } |
828 | 828 | } |
@@ -6,22 +6,22 @@ |
||
6 | 6 | * @subpackage |
7 | 7 | * @author Mike Nelson |
8 | 8 | */ |
9 | -class EE_Email_Input extends EE_Form_Input_Base{ |
|
9 | +class EE_Email_Input extends EE_Form_Input_Base { |
|
10 | 10 | |
11 | 11 | /** |
12 | 12 | * @param array $input_settings |
13 | 13 | */ |
14 | - function __construct( $input_settings = array() ){ |
|
15 | - $this->_set_display_strategy( new EE_Text_Input_Display_Strategy('email') ); |
|
16 | - $this->_set_normalization_strategy( new EE_Text_Normalization() ); |
|
14 | + function __construct($input_settings = array()) { |
|
15 | + $this->_set_display_strategy(new EE_Text_Input_Display_Strategy('email')); |
|
16 | + $this->_set_normalization_strategy(new EE_Text_Normalization()); |
|
17 | 17 | $this->_add_validation_strategy( |
18 | 18 | new EE_Email_Validation_Strategy( |
19 | - isset( $input_settings[ 'validation_error_message' ] ) |
|
20 | - ? $input_settings[ 'validation_error_message' ] |
|
19 | + isset($input_settings['validation_error_message']) |
|
20 | + ? $input_settings['validation_error_message'] |
|
21 | 21 | : NULL |
22 | 22 | ) |
23 | 23 | ); |
24 | - parent::__construct( $input_settings ); |
|
25 | - $this->set_html_class( $this->html_class() . ' email' ); |
|
24 | + parent::__construct($input_settings); |
|
25 | + $this->set_html_class($this->html_class().' email'); |
|
26 | 26 | } |
27 | 27 | } |
28 | 28 | \ No newline at end of file |
@@ -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,37 +1415,37 @@ 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 = reset( $times ); |
|
1430 | + $first_datetime = reset($times); |
|
1431 | 1431 | //do we get related tickets? |
1432 | - if ( $first_datetime instanceof EE_Datetime |
|
1433 | - && $first_datetime->ID() !== 0 ) { |
|
1432 | + if ($first_datetime instanceof EE_Datetime |
|
1433 | + && $first_datetime->ID() !== 0) { |
|
1434 | 1434 | $existing_datetime_ids[] = $first_datetime->get('DTT_ID'); |
1435 | 1435 | $template_args['time'] = $first_datetime; |
1436 | 1436 | $related_tickets = $first_datetime->tickets( |
1437 | 1437 | array( |
1438 | - array( 'OR' => array( 'TKT_deleted' => 1, 'TKT_deleted*' => 0 ) ), |
|
1438 | + array('OR' => array('TKT_deleted' => 1, 'TKT_deleted*' => 0)), |
|
1439 | 1439 | 'default_where_conditions' => 'none' |
1440 | 1440 | ) |
1441 | 1441 | ); |
1442 | 1442 | |
1443 | - if ( !empty($related_tickets) ) { |
|
1443 | + if ( ! empty($related_tickets)) { |
|
1444 | 1444 | $template_args['total_ticket_rows'] = count($related_tickets); |
1445 | 1445 | $row = 0; |
1446 | - foreach ( $related_tickets as $ticket ) { |
|
1446 | + foreach ($related_tickets as $ticket) { |
|
1447 | 1447 | $existing_ticket_ids[] = $ticket->get('TKT_ID'); |
1448 | - $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, FALSE, $row ); |
|
1448 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket, FALSE, $row); |
|
1449 | 1449 | |
1450 | 1450 | $row++; |
1451 | 1451 | } |
@@ -1453,13 +1453,13 @@ discard block |
||
1453 | 1453 | $template_args['total_ticket_rows'] = 1; |
1454 | 1454 | /** @type EE_Ticket $ticket */ |
1455 | 1455 | $ticket = EE_Registry::instance()->load_model('Ticket')->create_default_object(); |
1456 | - $template_args['ticket_rows'] .= $this->_get_ticket_row( $ticket ); |
|
1456 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket); |
|
1457 | 1457 | } |
1458 | 1458 | } else { |
1459 | 1459 | $template_args['time'] = $times[0]; |
1460 | 1460 | /** @type EE_Ticket $ticket */ |
1461 | 1461 | $ticket = EE_Registry::instance()->load_model('Ticket')->get_all_default_tickets(); |
1462 | - $template_args['ticket_rows'] .= $this->_get_ticket_row( $ticket[1] ); |
|
1462 | + $template_args['ticket_rows'] .= $this->_get_ticket_row($ticket[1]); |
|
1463 | 1463 | // NOTE: we're just sending the first default row |
1464 | 1464 | // (decaf can't manage default tickets so this should be sufficient); |
1465 | 1465 | } |
@@ -1468,8 +1468,8 @@ discard block |
||
1468 | 1468 | $template_args['ticket_options_help_link'] = $this->_get_help_tab_link('ticket_options_info'); |
1469 | 1469 | $template_args['existing_datetime_ids'] = implode(',', $existing_datetime_ids); |
1470 | 1470 | $template_args['existing_ticket_ids'] = implode(',', $existing_ticket_ids); |
1471 | - $template_args['ticket_js_structure'] = $this->_get_ticket_row( EE_Registry::instance()->load_model('Ticket')->create_default_object(), TRUE ); |
|
1472 | - $template = apply_filters( 'FHEE__Events_Admin_Page__ticket_metabox__template', EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_main.template.php' ); |
|
1471 | + $template_args['ticket_js_structure'] = $this->_get_ticket_row(EE_Registry::instance()->load_model('Ticket')->create_default_object(), TRUE); |
|
1472 | + $template = apply_filters('FHEE__Events_Admin_Page__ticket_metabox__template', EVENTS_TEMPLATE_PATH.'event_tickets_metabox_main.template.php'); |
|
1473 | 1473 | EEH_Template::display_template($template, $template_args); |
1474 | 1474 | } |
1475 | 1475 | |
@@ -1484,21 +1484,21 @@ discard block |
||
1484 | 1484 | * @param int $row |
1485 | 1485 | * @return string generated html for the ticket row. |
1486 | 1486 | */ |
1487 | - private function _get_ticket_row( $ticket, $skeleton = FALSE, $row = 0 ) { |
|
1487 | + private function _get_ticket_row($ticket, $skeleton = FALSE, $row = 0) { |
|
1488 | 1488 | $template_args = array( |
1489 | - 'tkt_status_class' => ' tkt-status-' . $ticket->ticket_status(), |
|
1490 | - 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && !$skeleton ? ' tkt-archived' : '', |
|
1489 | + 'tkt_status_class' => ' tkt-status-'.$ticket->ticket_status(), |
|
1490 | + 'tkt_archive_class' => $ticket->ticket_status() === EE_Ticket::archived && ! $skeleton ? ' tkt-archived' : '', |
|
1491 | 1491 | 'ticketrow' => $skeleton ? 'TICKETNUM' : $row, |
1492 | 1492 | 'TKT_ID' => $ticket->get('TKT_ID'), |
1493 | 1493 | 'TKT_name' => $ticket->get('TKT_name'), |
1494 | 1494 | 'TKT_start_date' => $skeleton ? '' : $ticket->get_date('TKT_start_date', 'Y-m-d h:i a'), |
1495 | 1495 | 'TKT_end_date' => $skeleton ? '' : $ticket->get_date('TKT_end_date', 'Y-m-d h:i a'), |
1496 | 1496 | 'TKT_is_default' => $ticket->get('TKT_is_default'), |
1497 | - 'TKT_qty' => $ticket->get_pretty('TKT_qty','input'), |
|
1497 | + 'TKT_qty' => $ticket->get_pretty('TKT_qty', 'input'), |
|
1498 | 1498 | 'edit_ticketrow_name' => $skeleton ? 'TICKETNAMEATTR' : 'edit_tickets', |
1499 | 1499 | 'TKT_sold' => $skeleton ? 0 : $ticket->get('TKT_sold'), |
1500 | - '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', |
|
1501 | - 'disabled' => $skeleton || ( !empty( $ticket ) && ! $ticket->get('TKT_deleted' ) ) ? '' : ' disabled=disabled' |
|
1500 | + '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', |
|
1501 | + 'disabled' => $skeleton || ( ! empty($ticket) && ! $ticket->get('TKT_deleted')) ? '' : ' disabled=disabled' |
|
1502 | 1502 | ); |
1503 | 1503 | |
1504 | 1504 | $price = $ticket->ID() !== 0 ? $ticket->get_first_related('Price', array('default_where_conditions' => 'none')) : EE_Registry::instance()->load_model('Price')->create_default_object(); |
@@ -1514,23 +1514,23 @@ discard block |
||
1514 | 1514 | |
1515 | 1515 | //make sure we have default start and end dates if skeleton |
1516 | 1516 | //handle rows that should NOT be empty |
1517 | - if ( empty( $template_args['TKT_start_date'] ) ) { |
|
1517 | + if (empty($template_args['TKT_start_date'])) { |
|
1518 | 1518 | //if empty then the start date will be now. |
1519 | 1519 | $template_args['TKT_start_date'] = date('Y-m-d h:i a', current_time('timestamp')); |
1520 | 1520 | } |
1521 | 1521 | |
1522 | - if ( empty( $template_args['TKT_end_date'] ) ) { |
|
1522 | + if (empty($template_args['TKT_end_date'])) { |
|
1523 | 1523 | //get the earliest datetime (if present); |
1524 | - $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; |
|
1524 | + $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; |
|
1525 | 1525 | |
1526 | - if ( !empty( $earliest_dtt ) ) |
|
1526 | + if ( ! empty($earliest_dtt)) |
|
1527 | 1527 | $template_args['TKT_end_date'] = $earliest_dtt->get_datetime('DTT_EVT_start', 'Y-m-d', 'h:i a'); |
1528 | 1528 | else |
1529 | - $template_args['TKT_end_date'] = date('Y-m-d h:i a', mktime(0, 0, 0, date("m"), date("d")+7, date("Y") ) ); |
|
1529 | + $template_args['TKT_end_date'] = date('Y-m-d h:i a', mktime(0, 0, 0, date("m"), date("d") + 7, date("Y"))); |
|
1530 | 1530 | } |
1531 | 1531 | |
1532 | - $template_args = array_merge( $template_args, $price_args ); |
|
1533 | - $template = apply_filters( 'FHEE__Events_Admin_Page__get_ticket_row__template', EVENTS_TEMPLATE_PATH . 'event_tickets_metabox_ticket_row.template.php', $ticket); |
|
1532 | + $template_args = array_merge($template_args, $price_args); |
|
1533 | + $template = apply_filters('FHEE__Events_Admin_Page__get_ticket_row__template', EVENTS_TEMPLATE_PATH.'event_tickets_metabox_ticket_row.template.php', $ticket); |
|
1534 | 1534 | return EEH_Template::display_template($template, $template_args, TRUE); |
1535 | 1535 | } |
1536 | 1536 | |
@@ -1559,8 +1559,8 @@ discard block |
||
1559 | 1559 | $template_args['default_registration_status'] = EEH_Form_Fields::select_input('default_reg_status', $default_reg_status_values, $this->_cpt_model_obj->default_registration_status()); |
1560 | 1560 | $template_args['display_description'] = EEH_Form_Fields::select_input('display_desc', $yes_no_values, $this->_cpt_model_obj->display_description()); |
1561 | 1561 | $template_args['display_ticket_selector'] = EEH_Form_Fields::select_input('display_ticket_selector', $yes_no_values, $this->_cpt_model_obj->display_ticket_selector(), '', '', false); |
1562 | - $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 ); |
|
1563 | - $templatepath = EVENTS_TEMPLATE_PATH . 'event_registration_options.template.php'; |
|
1562 | + $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); |
|
1563 | + $templatepath = EVENTS_TEMPLATE_PATH.'event_registration_options.template.php'; |
|
1564 | 1564 | EEH_Template::display_template($templatepath, $template_args); |
1565 | 1565 | } |
1566 | 1566 | |
@@ -1588,21 +1588,21 @@ discard block |
||
1588 | 1588 | $EEME = $this->_event_model(); |
1589 | 1589 | |
1590 | 1590 | $offset = ($current_page - 1) * $per_page; |
1591 | - $limit = $count ? NULL : $offset . ',' . $per_page; |
|
1591 | + $limit = $count ? NULL : $offset.','.$per_page; |
|
1592 | 1592 | $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'EVT_ID'; |
1593 | 1593 | $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : "DESC"; |
1594 | 1594 | |
1595 | 1595 | if (isset($this->_req_data['month_range'])) { |
1596 | 1596 | $pieces = explode(' ', $this->_req_data['month_range'], 3); |
1597 | - $month_r = !empty($pieces[0]) ? date('m', strtotime($pieces[0])) : ''; |
|
1598 | - $year_r = !empty($pieces[1]) ? $pieces[1] : ''; |
|
1597 | + $month_r = ! empty($pieces[0]) ? date('m', strtotime($pieces[0])) : ''; |
|
1598 | + $year_r = ! empty($pieces[1]) ? $pieces[1] : ''; |
|
1599 | 1599 | } |
1600 | 1600 | |
1601 | 1601 | $where = array(); |
1602 | 1602 | |
1603 | - $status = isset( $this->_req_data['status'] ) ? $this->_req_data['status'] : NULL; |
|
1603 | + $status = isset($this->_req_data['status']) ? $this->_req_data['status'] : NULL; |
|
1604 | 1604 | //determine what post_status our condition will have for the query. |
1605 | - switch ( $status ) { |
|
1605 | + switch ($status) { |
|
1606 | 1606 | case 'month' : |
1607 | 1607 | case 'today' : |
1608 | 1608 | case NULL : |
@@ -1610,7 +1610,7 @@ discard block |
||
1610 | 1610 | break; |
1611 | 1611 | |
1612 | 1612 | case 'draft' : |
1613 | - $where['status'] = array( 'IN', array('draft', 'auto-draft') ); |
|
1613 | + $where['status'] = array('IN', array('draft', 'auto-draft')); |
|
1614 | 1614 | break; |
1615 | 1615 | |
1616 | 1616 | default : |
@@ -1618,43 +1618,43 @@ discard block |
||
1618 | 1618 | } |
1619 | 1619 | |
1620 | 1620 | //categories? |
1621 | - $category = isset( $this->_req_data['EVT_CAT'] ) && $this->_req_data['EVT_CAT'] > 0 ? $this->_req_data['EVT_CAT'] : NULL; |
|
1621 | + $category = isset($this->_req_data['EVT_CAT']) && $this->_req_data['EVT_CAT'] > 0 ? $this->_req_data['EVT_CAT'] : NULL; |
|
1622 | 1622 | |
1623 | - if ( !empty ( $category ) ) { |
|
1623 | + if ( ! empty ($category)) { |
|
1624 | 1624 | $where['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
1625 | 1625 | $where['Term_Taxonomy.term_id'] = $category; |
1626 | 1626 | } |
1627 | 1627 | |
1628 | 1628 | //date where conditions |
1629 | - $start_formats = EEM_Datetime::instance()->get_formats_for( 'DTT_EVT_start' ); |
|
1629 | + $start_formats = EEM_Datetime::instance()->get_formats_for('DTT_EVT_start'); |
|
1630 | 1630 | if (isset($this->_req_data['month_range']) && $this->_req_data['month_range'] != '') { |
1631 | - $DateTime = new DateTime( $year_r . '-' . $month_r . '-01 00:00:00', new DateTimeZone( EEM_Datetime::instance()->get_timezone() ) ); |
|
1632 | - $start = $DateTime->format( implode( ' ', $start_formats ) ); |
|
1633 | - $end = $DateTime->setDate( $year_r, $month_r, $DateTime->format('t') )->setTime(23,59,59)->format( implode( ' ', $start_formats ) ); |
|
1634 | - $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array( $start, $end ) ); |
|
1631 | + $DateTime = new DateTime($year_r.'-'.$month_r.'-01 00:00:00', new DateTimeZone(EEM_Datetime::instance()->get_timezone())); |
|
1632 | + $start = $DateTime->format(implode(' ', $start_formats)); |
|
1633 | + $end = $DateTime->setDate($year_r, $month_r, $DateTime->format('t'))->setTime(23, 59, 59)->format(implode(' ', $start_formats)); |
|
1634 | + $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
1635 | 1635 | } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'today') { |
1636 | - $DateTime = new DateTime( 'now', new DateTimeZone( EEM_Event::instance()->get_timezone() ) ); |
|
1637 | - $start = $DateTime->setTime( 0,0,0 )->format( implode( ' ', $start_formats ) ); |
|
1638 | - $end = $DateTime->setTime( 23, 59, 59 )->format( implode( ' ', $start_formats ) ); |
|
1639 | - $where['Datetime.DTT_EVT_start'] = array( 'BETWEEN', array( $start, $end ) ); |
|
1640 | - } else if ( isset($this->_req_data['status']) && $this->_req_data['status'] == 'month' ) { |
|
1641 | - $now = date( 'Y-m-01' ); |
|
1642 | - $DateTime = new DateTime( $now, new DateTimeZone( EEM_Event::instance()->get_timezone() ) ); |
|
1643 | - $start = $DateTime->setTime( 0, 0, 0 )->format( implode( ' ', $start_formats ) ); |
|
1644 | - $end = $DateTime->setDate( date('Y'), date('m'), $DateTime->format('t' ) )->setTime( 23, 59, 59 )->format( implode( ' ', $start_formats ) ); |
|
1645 | - $where['Datetime.DTT_EVT_start'] = array( 'BETWEEN', array( $start, $end ) ); |
|
1636 | + $DateTime = new DateTime('now', new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
1637 | + $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
1638 | + $end = $DateTime->setTime(23, 59, 59)->format(implode(' ', $start_formats)); |
|
1639 | + $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
1640 | + } else if (isset($this->_req_data['status']) && $this->_req_data['status'] == 'month') { |
|
1641 | + $now = date('Y-m-01'); |
|
1642 | + $DateTime = new DateTime($now, new DateTimeZone(EEM_Event::instance()->get_timezone())); |
|
1643 | + $start = $DateTime->setTime(0, 0, 0)->format(implode(' ', $start_formats)); |
|
1644 | + $end = $DateTime->setDate(date('Y'), date('m'), $DateTime->format('t'))->setTime(23, 59, 59)->format(implode(' ', $start_formats)); |
|
1645 | + $where['Datetime.DTT_EVT_start'] = array('BETWEEN', array($start, $end)); |
|
1646 | 1646 | } |
1647 | 1647 | |
1648 | 1648 | |
1649 | - if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_others_events', 'get_events' ) ) { |
|
1650 | - $where['EVT_wp_user'] = get_current_user_id(); |
|
1649 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
1650 | + $where['EVT_wp_user'] = get_current_user_id(); |
|
1651 | 1651 | } else { |
1652 | - if ( ! isset( $where['status'] ) ) { |
|
1653 | - if ( ! EE_Registry::instance()->CAP->current_user_can( 'ee_read_private_events', 'get_events' ) ) { |
|
1652 | + if ( ! isset($where['status'])) { |
|
1653 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_events')) { |
|
1654 | 1654 | $where['OR'] = array( |
1655 | - 'status*restrict_private' => array( '!=', 'private' ), |
|
1655 | + 'status*restrict_private' => array('!=', 'private'), |
|
1656 | 1656 | 'AND' => array( |
1657 | - 'status*inclusive' => array( '=', 'private' ), |
|
1657 | + 'status*inclusive' => array('=', 'private'), |
|
1658 | 1658 | 'EVT_wp_user' => get_current_user_id() |
1659 | 1659 | ) |
1660 | 1660 | ); |
@@ -1662,16 +1662,16 @@ discard block |
||
1662 | 1662 | } |
1663 | 1663 | } |
1664 | 1664 | |
1665 | - if ( isset( $this->_req_data['EVT_wp_user'] ) ) { |
|
1666 | - if ( $this->_req_data['EVT_wp_user'] != get_current_user_id() && EE_Registry::instance()->CAP->current_user_can( 'ee_read_others_events', 'get_events' ) ) { |
|
1665 | + if (isset($this->_req_data['EVT_wp_user'])) { |
|
1666 | + if ($this->_req_data['EVT_wp_user'] != get_current_user_id() && EE_Registry::instance()->CAP->current_user_can('ee_read_others_events', 'get_events')) { |
|
1667 | 1667 | $where['EVT_wp_user'] = $this->_req_data['EVT_wp_user']; |
1668 | 1668 | } |
1669 | 1669 | } |
1670 | 1670 | |
1671 | 1671 | |
1672 | 1672 | //search query handling |
1673 | - if ( isset( $this->_req_data['s'] ) ) { |
|
1674 | - $search_string = '%' . $this->_req_data['s'] . '%'; |
|
1673 | + if (isset($this->_req_data['s'])) { |
|
1674 | + $search_string = '%'.$this->_req_data['s'].'%'; |
|
1675 | 1675 | $where['OR'] = array( |
1676 | 1676 | 'EVT_name' => array('LIKE', $search_string), |
1677 | 1677 | 'EVT_desc' => array('LIKE', $search_string), |
@@ -1680,32 +1680,32 @@ discard block |
||
1680 | 1680 | } |
1681 | 1681 | |
1682 | 1682 | |
1683 | - $where = apply_filters( 'FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data ); |
|
1684 | - $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 ); |
|
1683 | + $where = apply_filters('FHEE__Events_Admin_Page__get_events__where', $where, $this->_req_data); |
|
1684 | + $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); |
|
1685 | 1685 | |
1686 | 1686 | |
1687 | 1687 | //let's first check if we have special requests coming in. |
1688 | - if ( isset( $this->_req_data['active_status'] ) ) { |
|
1689 | - switch ( $this->_req_data['active_status'] ) { |
|
1688 | + if (isset($this->_req_data['active_status'])) { |
|
1689 | + switch ($this->_req_data['active_status']) { |
|
1690 | 1690 | case 'upcoming' : |
1691 | - return $EEME->get_upcoming_events( $query_params, $count ); |
|
1691 | + return $EEME->get_upcoming_events($query_params, $count); |
|
1692 | 1692 | break; |
1693 | 1693 | |
1694 | 1694 | case 'expired' : |
1695 | - return $EEME->get_expired_events( $query_params, $count ); |
|
1695 | + return $EEME->get_expired_events($query_params, $count); |
|
1696 | 1696 | break; |
1697 | 1697 | |
1698 | 1698 | case 'active' : |
1699 | - return $EEME->get_active_events( $query_params, $count ); |
|
1699 | + return $EEME->get_active_events($query_params, $count); |
|
1700 | 1700 | break; |
1701 | 1701 | |
1702 | 1702 | case 'inactive' : |
1703 | - return $EEME->get_inactive_events( $query_params, $count ); |
|
1703 | + return $EEME->get_inactive_events($query_params, $count); |
|
1704 | 1704 | break; |
1705 | 1705 | } |
1706 | 1706 | } |
1707 | 1707 | |
1708 | - $events = $count ? $EEME->count( array( $where ), 'EVT_ID', true ) : $EEME->get_all( $query_params ); |
|
1708 | + $events = $count ? $EEME->count(array($where), 'EVT_ID', true) : $EEME->get_all($query_params); |
|
1709 | 1709 | |
1710 | 1710 | return $events; |
1711 | 1711 | } |
@@ -1714,23 +1714,23 @@ discard block |
||
1714 | 1714 | |
1715 | 1715 | |
1716 | 1716 | //handling for WordPress CPT actions (trash, restore, delete) |
1717 | - public function trash_cpt_item( $post_id ) { |
|
1717 | + public function trash_cpt_item($post_id) { |
|
1718 | 1718 | $this->_req_data['EVT_ID'] = $post_id; |
1719 | - $this->_trash_or_restore_event( 'trash', FALSE ); |
|
1719 | + $this->_trash_or_restore_event('trash', FALSE); |
|
1720 | 1720 | } |
1721 | 1721 | |
1722 | 1722 | |
1723 | 1723 | |
1724 | 1724 | |
1725 | - public function restore_cpt_item( $post_id ) { |
|
1725 | + public function restore_cpt_item($post_id) { |
|
1726 | 1726 | $this->_req_data['EVT_ID'] = $post_id; |
1727 | - $this->_trash_or_restore_event( 'draft', FALSE ); |
|
1727 | + $this->_trash_or_restore_event('draft', FALSE); |
|
1728 | 1728 | } |
1729 | 1729 | |
1730 | 1730 | |
1731 | - public function delete_cpt_item( $post_id ) { |
|
1731 | + public function delete_cpt_item($post_id) { |
|
1732 | 1732 | $this->_req_data['EVT_ID'] = $post_id; |
1733 | - $this->_delete_event( FALSE ); |
|
1733 | + $this->_delete_event(FALSE); |
|
1734 | 1734 | } |
1735 | 1735 | |
1736 | 1736 | |
@@ -1742,7 +1742,7 @@ discard block |
||
1742 | 1742 | * @param string $event_status |
1743 | 1743 | * @return void |
1744 | 1744 | */ |
1745 | - protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = TRUE ) { |
|
1745 | + protected function _trash_or_restore_event($event_status = 'trash', $redirect_after = TRUE) { |
|
1746 | 1746 | //determine the event id and set to array. |
1747 | 1747 | $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : FALSE; |
1748 | 1748 | // loop thru events |
@@ -1750,7 +1750,7 @@ discard block |
||
1750 | 1750 | // clean status |
1751 | 1751 | $event_status = sanitize_key($event_status); |
1752 | 1752 | // grab status |
1753 | - if (!empty($event_status)) { |
|
1753 | + if ( ! empty($event_status)) { |
|
1754 | 1754 | $success = $this->_change_event_status($EVT_ID, $event_status); |
1755 | 1755 | } else { |
1756 | 1756 | $success = FALSE; |
@@ -1764,7 +1764,7 @@ discard block |
||
1764 | 1764 | } |
1765 | 1765 | $action = $event_status == 'trash' ? 'moved to the trash' : 'restored from the trash'; |
1766 | 1766 | |
1767 | - if ( $redirect_after ) |
|
1767 | + if ($redirect_after) |
|
1768 | 1768 | $this->_redirect_after_action($success, 'Event', $action, array('action' => 'default')); |
1769 | 1769 | } |
1770 | 1770 | |
@@ -1779,7 +1779,7 @@ discard block |
||
1779 | 1779 | // clean status |
1780 | 1780 | $event_status = sanitize_key($event_status); |
1781 | 1781 | // grab status |
1782 | - if (!empty($event_status)) { |
|
1782 | + if ( ! empty($event_status)) { |
|
1783 | 1783 | $success = TRUE; |
1784 | 1784 | //determine the event id and set to array. |
1785 | 1785 | $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array(); |
@@ -1814,15 +1814,15 @@ discard block |
||
1814 | 1814 | * @param string $event_status |
1815 | 1815 | * @return bool |
1816 | 1816 | */ |
1817 | - private function _change_event_status( $EVT_ID = 0, $event_status = '') { |
|
1817 | + private function _change_event_status($EVT_ID = 0, $event_status = '') { |
|
1818 | 1818 | // grab event id |
1819 | - if (!$EVT_ID) { |
|
1819 | + if ( ! $EVT_ID) { |
|
1820 | 1820 | $msg = __('An error occurred. No Event ID or an invalid Event ID was received.', 'event_espresso'); |
1821 | 1821 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
1822 | 1822 | return FALSE; |
1823 | 1823 | } |
1824 | 1824 | |
1825 | - $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID( $EVT_ID ); |
|
1825 | + $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
1826 | 1826 | |
1827 | 1827 | // clean status |
1828 | 1828 | $event_status = sanitize_key($event_status); |
@@ -1848,7 +1848,7 @@ discard block |
||
1848 | 1848 | $hook = FALSE; |
1849 | 1849 | } |
1850 | 1850 | //use class to change status |
1851 | - $this->_cpt_model_obj->set_status( $event_status ); |
|
1851 | + $this->_cpt_model_obj->set_status($event_status); |
|
1852 | 1852 | $success = $this->_cpt_model_obj->save(); |
1853 | 1853 | |
1854 | 1854 | if ($success === FALSE) { |
@@ -1870,15 +1870,15 @@ discard block |
||
1870 | 1870 | * @access protected |
1871 | 1871 | * @param bool $redirect_after |
1872 | 1872 | */ |
1873 | - protected function _delete_event( $redirect_after = TRUE ) { |
|
1873 | + protected function _delete_event($redirect_after = TRUE) { |
|
1874 | 1874 | //determine the event id and set to array. |
1875 | 1875 | $EVT_ID = isset($this->_req_data['EVT_ID']) ? absint($this->_req_data['EVT_ID']) : NULL; |
1876 | - $EVT_ID = isset( $this->_req_data['post'] ) ? absint( $this->_req_data['post'] ) : $EVT_ID; |
|
1876 | + $EVT_ID = isset($this->_req_data['post']) ? absint($this->_req_data['post']) : $EVT_ID; |
|
1877 | 1877 | |
1878 | 1878 | |
1879 | 1879 | // loop thru events |
1880 | 1880 | if ($EVT_ID) { |
1881 | - $success = $this->_permanently_delete_event( $EVT_ID ); |
|
1881 | + $success = $this->_permanently_delete_event($EVT_ID); |
|
1882 | 1882 | // get list of events with no prices |
1883 | 1883 | $espresso_no_ticket_prices = get_option('ee_no_ticket_prices', array()); |
1884 | 1884 | // remove this event from the list of events with no prices |
@@ -1892,7 +1892,7 @@ discard block |
||
1892 | 1892 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
1893 | 1893 | } |
1894 | 1894 | |
1895 | - if ( $redirect_after ) |
|
1895 | + if ($redirect_after) |
|
1896 | 1896 | $this->_redirect_after_action($success, 'Event', 'deleted', array('action' => 'default', 'status' => 'trash')); |
1897 | 1897 | } |
1898 | 1898 | |
@@ -1910,12 +1910,12 @@ discard block |
||
1910 | 1910 | $EVT_IDs = isset($this->_req_data['EVT_IDs']) ? (array) $this->_req_data['EVT_IDs'] : array(); |
1911 | 1911 | // loop thru events |
1912 | 1912 | foreach ($EVT_IDs as $EVT_ID) { |
1913 | - $EVT_ID = absint( $EVT_ID ); |
|
1914 | - if ( $EVT_ID ) { |
|
1915 | - $results = $this->_permanently_delete_event( $EVT_ID ); |
|
1913 | + $EVT_ID = absint($EVT_ID); |
|
1914 | + if ($EVT_ID) { |
|
1915 | + $results = $this->_permanently_delete_event($EVT_ID); |
|
1916 | 1916 | $success = $results !== FALSE ? $success : FALSE; |
1917 | 1917 | // remove this event from the list of events with no prices |
1918 | - unset( $espresso_no_ticket_prices[ $EVT_ID ] ); |
|
1918 | + unset($espresso_no_ticket_prices[$EVT_ID]); |
|
1919 | 1919 | } else { |
1920 | 1920 | $success = FALSE; |
1921 | 1921 | $msg = __('An error occurred. An event could not be deleted because a valid event ID was not not supplied.', 'event_espresso'); |
@@ -1935,21 +1935,21 @@ discard block |
||
1935 | 1935 | * @param int $EVT_ID |
1936 | 1936 | * @return bool |
1937 | 1937 | */ |
1938 | - private function _permanently_delete_event( $EVT_ID = 0 ) { |
|
1938 | + private function _permanently_delete_event($EVT_ID = 0) { |
|
1939 | 1939 | // grab event id |
1940 | - if ( ! $EVT_ID ) { |
|
1940 | + if ( ! $EVT_ID) { |
|
1941 | 1941 | $msg = __('An error occurred. No Event ID or an invalid Event ID was received.', 'event_espresso'); |
1942 | 1942 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
1943 | 1943 | return FALSE; |
1944 | 1944 | } |
1945 | - $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID( $EVT_ID ); |
|
1945 | + $this->_cpt_model_obj = EEM_Event::instance()->get_one_by_ID($EVT_ID); |
|
1946 | 1946 | |
1947 | 1947 | //need to delete related tickets and prices first. |
1948 | 1948 | $datetimes = $this->_cpt_model_obj->get_many_related('Datetime'); |
1949 | - foreach ( $datetimes as $datetime ) { |
|
1949 | + foreach ($datetimes as $datetime) { |
|
1950 | 1950 | $this->_cpt_model_obj->_remove_relation_to($datetime, 'Datetime'); |
1951 | 1951 | $tickets = $datetime->get_many_related('Ticket'); |
1952 | - foreach ( $tickets as $ticket ) { |
|
1952 | + foreach ($tickets as $ticket) { |
|
1953 | 1953 | $ticket->_remove_relation_to($datetime, 'Datetime'); |
1954 | 1954 | $ticket->delete_related_permanently('Price'); |
1955 | 1955 | $ticket->delete_permanently(); |
@@ -1959,14 +1959,14 @@ discard block |
||
1959 | 1959 | |
1960 | 1960 | //what about related venues or terms? |
1961 | 1961 | $venues = $this->_cpt_model_obj->get_many_related('Venue'); |
1962 | - foreach ( $venues as $venue ) { |
|
1962 | + foreach ($venues as $venue) { |
|
1963 | 1963 | $this->_cpt_model_obj->_remove_relation_to($venue, 'Venue'); |
1964 | 1964 | } |
1965 | 1965 | |
1966 | 1966 | //any attached question groups? |
1967 | 1967 | $question_groups = $this->_cpt_model_obj->get_many_related('Question_Group'); |
1968 | - if ( !empty( $question_groups ) ) { |
|
1969 | - foreach ( $question_groups as $question_group ) { |
|
1968 | + if ( ! empty($question_groups)) { |
|
1969 | + foreach ($question_groups as $question_group) { |
|
1970 | 1970 | $this->_cpt_model_obj->_remove_relation_to($question_group, 'Question_Group'); |
1971 | 1971 | } |
1972 | 1972 | } |
@@ -1975,12 +1975,12 @@ discard block |
||
1975 | 1975 | |
1976 | 1976 | |
1977 | 1977 | //Message Template Groups |
1978 | - $this->_cpt_model_obj->_remove_relations( 'Message_Template_Group' ); |
|
1978 | + $this->_cpt_model_obj->_remove_relations('Message_Template_Group'); |
|
1979 | 1979 | |
1980 | 1980 | /** @type EE_Term_Taxonomy[] $term_taxonomies */ |
1981 | 1981 | $term_taxonomies = $this->_cpt_model_obj->term_taxonomies(); |
1982 | 1982 | |
1983 | - foreach ( $term_taxonomies as $term_taxonomy ) { |
|
1983 | + foreach ($term_taxonomies as $term_taxonomy) { |
|
1984 | 1984 | $this->_cpt_model_obj->remove_relation_to_term_taxonomy($term_taxonomy); |
1985 | 1985 | } |
1986 | 1986 | |
@@ -1994,7 +1994,7 @@ discard block |
||
1994 | 1994 | EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
1995 | 1995 | return FALSE; |
1996 | 1996 | } |
1997 | - do_action( 'AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID ); |
|
1997 | + do_action('AHEE__Events_Admin_Page___permanently_delete_event__after_event_deleted', $EVT_ID); |
|
1998 | 1998 | return TRUE; |
1999 | 1999 | } |
2000 | 2000 | |
@@ -2011,7 +2011,7 @@ discard block |
||
2011 | 2011 | */ |
2012 | 2012 | public function total_events() { |
2013 | 2013 | |
2014 | - $count = EEM_Event::instance()->count( array( 'caps' => 'read_admin' ), 'EVT_ID', true ); |
|
2014 | + $count = EEM_Event::instance()->count(array('caps' => 'read_admin'), 'EVT_ID', true); |
|
2015 | 2015 | return $count; |
2016 | 2016 | } |
2017 | 2017 | |
@@ -2026,10 +2026,10 @@ discard block |
||
2026 | 2026 | */ |
2027 | 2027 | public function total_events_draft() { |
2028 | 2028 | $where = array( |
2029 | - 'status' => array( 'IN', array('draft', 'auto-draft' ) ) |
|
2029 | + 'status' => array('IN', array('draft', 'auto-draft')) |
|
2030 | 2030 | ); |
2031 | 2031 | |
2032 | - $count = EEM_Event::instance()->count( array( $where, 'caps' => 'read_admin' ), 'EVT_ID', true ); |
|
2032 | + $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
2033 | 2033 | return $count; |
2034 | 2034 | } |
2035 | 2035 | |
@@ -2048,7 +2048,7 @@ discard block |
||
2048 | 2048 | 'status' => 'trash' |
2049 | 2049 | ); |
2050 | 2050 | |
2051 | - $count = EEM_Event::instance()->count( array( $where, 'caps' => 'read_admin' ), 'EVT_ID', true ); |
|
2051 | + $count = EEM_Event::instance()->count(array($where, 'caps' => 'read_admin'), 'EVT_ID', true); |
|
2052 | 2052 | return $count; |
2053 | 2053 | } |
2054 | 2054 | |
@@ -2076,11 +2076,11 @@ discard block |
||
2076 | 2076 | // translated |
2077 | 2077 | TRUE |
2078 | 2078 | ); |
2079 | - $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; |
|
2079 | + $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; |
|
2080 | 2080 | |
2081 | 2081 | $this->_set_add_edit_form_tags('update_default_event_settings'); |
2082 | 2082 | $this->_set_publish_post_box_vars(NULL, FALSE, FALSE, NULL, FALSE); |
2083 | - $this->_template_args['admin_page_content'] = EEH_Template::display_template(EVENTS_TEMPLATE_PATH . 'event_settings.template.php', $this->_template_args, TRUE); |
|
2083 | + $this->_template_args['admin_page_content'] = EEH_Template::display_template(EVENTS_TEMPLATE_PATH.'event_settings.template.php', $this->_template_args, TRUE); |
|
2084 | 2084 | $this->display_admin_page_with_sidebar(); |
2085 | 2085 | } |
2086 | 2086 | |
@@ -2106,9 +2106,9 @@ discard block |
||
2106 | 2106 | |
2107 | 2107 | protected function _template_settings() { |
2108 | 2108 | $this->_admin_page_title = __('Template Settings (Preview)', 'event_espresso'); |
2109 | - $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' ) . '" />'; |
|
2110 | - $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>'; |
|
2111 | - $this->display_admin_caf_preview_page( 'template_settings_tab' ); |
|
2109 | + $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').'" />'; |
|
2110 | + $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>'; |
|
2111 | + $this->display_admin_caf_preview_page('template_settings_tab'); |
|
2112 | 2112 | } |
2113 | 2113 | |
2114 | 2114 | |
@@ -2121,22 +2121,22 @@ discard block |
||
2121 | 2121 | * @return void |
2122 | 2122 | */ |
2123 | 2123 | private function _set_category_object() { |
2124 | - if ( isset( $this->_category->id ) && !empty( $this->_category->id ) ) |
|
2124 | + if (isset($this->_category->id) && ! empty($this->_category->id)) |
|
2125 | 2125 | return; //already have the category object so get out. |
2126 | 2126 | |
2127 | 2127 | //set default category object |
2128 | 2128 | $this->_set_empty_category_object(); |
2129 | 2129 | |
2130 | 2130 | //only set if we've got an id |
2131 | - if ( !isset($this->_req_data['EVT_CAT_ID'] ) ) { |
|
2131 | + if ( ! isset($this->_req_data['EVT_CAT_ID'])) { |
|
2132 | 2132 | return; |
2133 | 2133 | } |
2134 | 2134 | |
2135 | 2135 | $category_id = absint($this->_req_data['EVT_CAT_ID']); |
2136 | 2136 | |
2137 | - $term = get_term( $category_id, 'espresso_event_categories' ); |
|
2137 | + $term = get_term($category_id, 'espresso_event_categories'); |
|
2138 | 2138 | |
2139 | - if ( !empty( $term ) ) { |
|
2139 | + if ( ! empty($term)) { |
|
2140 | 2140 | $this->_category->category_name = $term->name; |
2141 | 2141 | $this->_category->category_identifier = $term->slug; |
2142 | 2142 | $this->_category->category_desc = $term->description; |
@@ -2150,13 +2150,13 @@ discard block |
||
2150 | 2150 | |
2151 | 2151 | private function _set_empty_category_object() { |
2152 | 2152 | $this->_category = new stdClass(); |
2153 | - $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = ''; |
|
2153 | + $this->_category->category_name = $this->_category->category_identifier = $this->_category->category_desc = ''; |
|
2154 | 2154 | $this->_category->id = $this->_category->parent = 0; |
2155 | 2155 | } |
2156 | 2156 | |
2157 | 2157 | |
2158 | 2158 | protected function _category_list_table() { |
2159 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
2159 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
2160 | 2160 | $this->_search_btn_label = __('Categories', 'event_espresso'); |
2161 | 2161 | $this->_admin_page_title .= $this->get_action_link_or_button('add_category', 'add_category', array(), 'add-new-h2'); |
2162 | 2162 | $this->display_admin_list_table_page_with_sidebar(); |
@@ -2166,22 +2166,22 @@ discard block |
||
2166 | 2166 | protected function _category_details($view) { |
2167 | 2167 | |
2168 | 2168 | //load formatter helper |
2169 | - EE_Registry::instance()->load_helper( 'Formatter' ); |
|
2169 | + EE_Registry::instance()->load_helper('Formatter'); |
|
2170 | 2170 | //load field generator helper |
2171 | - EE_Registry::instance()->load_helper( 'Form_Fields' ); |
|
2171 | + EE_Registry::instance()->load_helper('Form_Fields'); |
|
2172 | 2172 | |
2173 | 2173 | $route = $view == 'edit' ? 'update_category' : 'insert_category'; |
2174 | 2174 | $this->_set_add_edit_form_tags($route); |
2175 | 2175 | |
2176 | 2176 | $this->_set_category_object(); |
2177 | - $id = !empty($this->_category->id) ? $this->_category->id : ''; |
|
2177 | + $id = ! empty($this->_category->id) ? $this->_category->id : ''; |
|
2178 | 2178 | |
2179 | 2179 | $delete_action = 'delete_category'; |
2180 | 2180 | |
2181 | 2181 | //custom redirect |
2182 | - $redirect = EE_Admin_Page::add_query_args_and_nonce( array('action' => 'category_list'), $this->_admin_base_url ); |
|
2182 | + $redirect = EE_Admin_Page::add_query_args_and_nonce(array('action' => 'category_list'), $this->_admin_base_url); |
|
2183 | 2183 | |
2184 | - $this->_set_publish_post_box_vars( 'EVT_CAT_ID', $id, $delete_action, $redirect ); |
|
2184 | + $this->_set_publish_post_box_vars('EVT_CAT_ID', $id, $delete_action, $redirect); |
|
2185 | 2185 | |
2186 | 2186 | //take care of contents |
2187 | 2187 | $this->_template_args['admin_page_content'] = $this->_category_details_content(); |
@@ -2195,25 +2195,25 @@ discard block |
||
2195 | 2195 | 'type' => 'wp_editor', |
2196 | 2196 | 'value' => EEH_Formatter::admin_format_content($this->_category->category_desc), |
2197 | 2197 | 'class' => 'my_editor_custom', |
2198 | - 'wpeditor_args' => array('media_buttons' => FALSE ) |
|
2198 | + 'wpeditor_args' => array('media_buttons' => FALSE) |
|
2199 | 2199 | ); |
2200 | - $_wp_editor = $this->_generate_admin_form_fields( $editor_args, 'array' ); |
|
2200 | + $_wp_editor = $this->_generate_admin_form_fields($editor_args, 'array'); |
|
2201 | 2201 | |
2202 | - $all_terms = get_terms( array('espresso_event_categories' ), array( 'hide_empty' => 0, 'exclude' => array( $this->_category->id ) ) ); |
|
2202 | + $all_terms = get_terms(array('espresso_event_categories'), array('hide_empty' => 0, 'exclude' => array($this->_category->id))); |
|
2203 | 2203 | |
2204 | 2204 | //setup category select for term parents. |
2205 | 2205 | $category_select_values[] = array( |
2206 | 2206 | 'text' => __('No Parent', 'event_espresso'), |
2207 | 2207 | 'id' => 0 |
2208 | 2208 | ); |
2209 | - foreach ( $all_terms as $term ) { |
|
2209 | + foreach ($all_terms as $term) { |
|
2210 | 2210 | $category_select_values[] = array( |
2211 | 2211 | 'text' => $term->name, |
2212 | 2212 | 'id' => $term->term_id |
2213 | 2213 | ); |
2214 | 2214 | } |
2215 | 2215 | |
2216 | - $category_select = EEH_Form_Fields::select_input( 'category_parent', $category_select_values, $this->_category->parent ); |
|
2216 | + $category_select = EEH_Form_Fields::select_input('category_parent', $category_select_values, $this->_category->parent); |
|
2217 | 2217 | |
2218 | 2218 | $template_args = array( |
2219 | 2219 | 'category' => $this->_category, |
@@ -2223,15 +2223,15 @@ discard block |
||
2223 | 2223 | 'disable' => '', |
2224 | 2224 | 'disabled_message' => FALSE |
2225 | 2225 | ); |
2226 | - $template = EVENTS_TEMPLATE_PATH . 'event_category_details.template.php'; |
|
2227 | - return EEH_Template::display_template($template, $template_args, TRUE ); |
|
2226 | + $template = EVENTS_TEMPLATE_PATH.'event_category_details.template.php'; |
|
2227 | + return EEH_Template::display_template($template, $template_args, TRUE); |
|
2228 | 2228 | } |
2229 | 2229 | |
2230 | 2230 | |
2231 | 2231 | protected function _delete_categories() { |
2232 | - $cat_ids = isset( $this->_req_data['EVT_CAT_ID'] ) ? (array) $this->_req_data['EVT_CAT_ID'] : (array) $this->_req_data['category_id']; |
|
2232 | + $cat_ids = isset($this->_req_data['EVT_CAT_ID']) ? (array) $this->_req_data['EVT_CAT_ID'] : (array) $this->_req_data['category_id']; |
|
2233 | 2233 | |
2234 | - foreach ( $cat_ids as $cat_id ) { |
|
2234 | + foreach ($cat_ids as $cat_id) { |
|
2235 | 2235 | $this->_delete_category($cat_id); |
2236 | 2236 | } |
2237 | 2237 | |
@@ -2239,7 +2239,7 @@ discard block |
||
2239 | 2239 | $query_args = array( |
2240 | 2240 | 'action' => 'category_list' |
2241 | 2241 | ); |
2242 | - $this->_redirect_after_action(0,'','',$query_args); |
|
2242 | + $this->_redirect_after_action(0, '', '', $query_args); |
|
2243 | 2243 | |
2244 | 2244 | } |
2245 | 2245 | |
@@ -2249,61 +2249,61 @@ discard block |
||
2249 | 2249 | |
2250 | 2250 | protected function _delete_category($cat_id) { |
2251 | 2251 | global $wpdb; |
2252 | - $cat_id = absint( $cat_id ); |
|
2253 | - wp_delete_term( $cat_id, 'espresso_event_categories' ); |
|
2252 | + $cat_id = absint($cat_id); |
|
2253 | + wp_delete_term($cat_id, 'espresso_event_categories'); |
|
2254 | 2254 | } |
2255 | 2255 | |
2256 | 2256 | |
2257 | 2257 | |
2258 | 2258 | protected function _insert_or_update_category($new_category) { |
2259 | 2259 | |
2260 | - $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category( TRUE ); |
|
2260 | + $cat_id = $new_category ? $this->_insert_category() : $this->_insert_category(TRUE); |
|
2261 | 2261 | $success = 0; //we already have a success message so lets not send another. |
2262 | 2262 | |
2263 | - if ( $cat_id ) { |
|
2263 | + if ($cat_id) { |
|
2264 | 2264 | $query_args = array( |
2265 | 2265 | 'action' => 'edit_category', |
2266 | 2266 | 'EVT_CAT_ID' => $cat_id |
2267 | 2267 | ); |
2268 | 2268 | } else { |
2269 | - $query_args = array( 'action' => 'add_category' ); |
|
2269 | + $query_args = array('action' => 'add_category'); |
|
2270 | 2270 | } |
2271 | - $this->_redirect_after_action( $success, '','', $query_args, TRUE ); |
|
2271 | + $this->_redirect_after_action($success, '', '', $query_args, TRUE); |
|
2272 | 2272 | |
2273 | 2273 | } |
2274 | 2274 | |
2275 | 2275 | |
2276 | 2276 | |
2277 | - private function _insert_category( $update = FALSE ) { |
|
2277 | + private function _insert_category($update = FALSE) { |
|
2278 | 2278 | $cat_id = $update ? $this->_req_data['EVT_CAT_ID'] : ''; |
2279 | - $category_name= isset( $this->_req_data['category_name'] ) ? $this->_req_data['category_name'] : ''; |
|
2280 | - $category_desc= isset( $this->_req_data['category_desc'] ) ? $this->_req_data['category_desc'] : ''; |
|
2281 | - $category_parent = isset( $this->_req_data['category_parent'] ) ? $this->_req_data['category_parent'] : 0; |
|
2279 | + $category_name = isset($this->_req_data['category_name']) ? $this->_req_data['category_name'] : ''; |
|
2280 | + $category_desc = isset($this->_req_data['category_desc']) ? $this->_req_data['category_desc'] : ''; |
|
2281 | + $category_parent = isset($this->_req_data['category_parent']) ? $this->_req_data['category_parent'] : 0; |
|
2282 | 2282 | |
2283 | - if ( empty( $category_name ) ) { |
|
2284 | - $msg = __( 'You must add a name for the category.', 'event_espresso' ); |
|
2285 | - EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
2283 | + if (empty($category_name)) { |
|
2284 | + $msg = __('You must add a name for the category.', 'event_espresso'); |
|
2285 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2286 | 2286 | return false; |
2287 | 2287 | } |
2288 | 2288 | |
2289 | - $term_args=array( |
|
2289 | + $term_args = array( |
|
2290 | 2290 | 'name'=>$category_name, |
2291 | 2291 | 'description'=>$category_desc, |
2292 | 2292 | 'parent'=>$category_parent |
2293 | 2293 | ); |
2294 | 2294 | //was the category_identifier input disabled? |
2295 | - if(isset($this->_req_data['category_identifier'])){ |
|
2295 | + if (isset($this->_req_data['category_identifier'])) { |
|
2296 | 2296 | $term_args['slug'] = $this->_req_data['category_identifier']; |
2297 | 2297 | } |
2298 | - $insert_ids = $update ? wp_update_term( $cat_id, 'espresso_event_categories', $term_args ) :wp_insert_term( $category_name, 'espresso_event_categories', $term_args ); |
|
2298 | + $insert_ids = $update ? wp_update_term($cat_id, 'espresso_event_categories', $term_args) : wp_insert_term($category_name, 'espresso_event_categories', $term_args); |
|
2299 | 2299 | |
2300 | - if ( !is_array( $insert_ids ) ) { |
|
2301 | - $msg = __( 'An error occurred and the category has not been saved to the database.', 'event_espresso' ); |
|
2302 | - EE_Error::add_error( $msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
2300 | + if ( ! is_array($insert_ids)) { |
|
2301 | + $msg = __('An error occurred and the category has not been saved to the database.', 'event_espresso'); |
|
2302 | + EE_Error::add_error($msg, __FILE__, __FUNCTION__, __LINE__); |
|
2303 | 2303 | } else { |
2304 | 2304 | $cat_id = $insert_ids['term_id']; |
2305 | - $msg = sprintf ( __('The category %s was successfuly saved', 'event_espresso'), $category_name ); |
|
2306 | - EE_Error::add_success( $msg ); |
|
2305 | + $msg = sprintf(__('The category %s was successfuly saved', 'event_espresso'), $category_name); |
|
2306 | + EE_Error::add_success($msg); |
|
2307 | 2307 | } |
2308 | 2308 | |
2309 | 2309 | return $cat_id; |
@@ -2312,32 +2312,32 @@ discard block |
||
2312 | 2312 | |
2313 | 2313 | |
2314 | 2314 | |
2315 | - public function get_categories( $per_page = 10, $current_page = 1, $count = FALSE ) { |
|
2315 | + public function get_categories($per_page = 10, $current_page = 1, $count = FALSE) { |
|
2316 | 2316 | global $wpdb; |
2317 | 2317 | |
2318 | 2318 | //testing term stuff |
2319 | - $orderby = isset( $this->_req_data['orderby'] ) ? $this->_req_data['orderby'] : 'Term.term_id'; |
|
2320 | - $order = isset( $this->_req_data['order'] ) ? $this->_req_data['order'] : 'DESC'; |
|
2321 | - $limit = ($current_page-1)*$per_page; |
|
2319 | + $orderby = isset($this->_req_data['orderby']) ? $this->_req_data['orderby'] : 'Term.term_id'; |
|
2320 | + $order = isset($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC'; |
|
2321 | + $limit = ($current_page - 1) * $per_page; |
|
2322 | 2322 | |
2323 | - $where = array( 'taxonomy' => 'espresso_event_categories' ); |
|
2323 | + $where = array('taxonomy' => 'espresso_event_categories'); |
|
2324 | 2324 | |
2325 | - if ( isset( $this->_req_data['s'] ) ) { |
|
2326 | - $sstr = '%' . $this->_req_data['s'] . '%'; |
|
2325 | + if (isset($this->_req_data['s'])) { |
|
2326 | + $sstr = '%'.$this->_req_data['s'].'%'; |
|
2327 | 2327 | $where['OR'] = array( |
2328 | - 'Term.name' => array( 'LIKE', $sstr), |
|
2329 | - 'description' => array( 'LIKE', $sstr ) |
|
2328 | + 'Term.name' => array('LIKE', $sstr), |
|
2329 | + 'description' => array('LIKE', $sstr) |
|
2330 | 2330 | ); |
2331 | 2331 | } |
2332 | 2332 | |
2333 | 2333 | $query_params = array( |
2334 | - $where , |
|
2335 | - 'order_by' => array( $orderby => $order ), |
|
2336 | - 'limit' => $limit . ',' . $per_page, |
|
2334 | + $where, |
|
2335 | + 'order_by' => array($orderby => $order), |
|
2336 | + 'limit' => $limit.','.$per_page, |
|
2337 | 2337 | 'force_join' => array('Term') |
2338 | 2338 | ); |
2339 | 2339 | |
2340 | - $categories = $count ? EEM_Term_Taxonomy::instance()->count( $query_params, 'term_id' ) :EEM_Term_Taxonomy::instance()->get_all( $query_params ); |
|
2340 | + $categories = $count ? EEM_Term_Taxonomy::instance()->count($query_params, 'term_id') : EEM_Term_Taxonomy::instance()->get_all($query_params); |
|
2341 | 2341 | |
2342 | 2342 | return $categories; |
2343 | 2343 | } |
@@ -239,7 +239,7 @@ discard block |
||
239 | 239 | ){ |
240 | 240 | if( $relation instanceof \EE_Belongs_To_Relation ) { |
241 | 241 | $related_model_name_maybe_plural = strtolower( $related_model->get_this_model_name() ); |
242 | - }else{ |
|
242 | + } else{ |
|
243 | 243 | $related_model_name_maybe_plural = \EEH_Inflector::pluralize_and_lower( $related_model->get_this_model_name() ); |
244 | 244 | } |
245 | 245 | return new \WP_Error( |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | } |
292 | 292 | if( $relation instanceof \EE_Belongs_To_Relation ){ |
293 | 293 | return array_shift( $nice_results ); |
294 | - }else{ |
|
294 | + } else{ |
|
295 | 295 | return $nice_results; |
296 | 296 | } |
297 | 297 | } |
@@ -405,14 +405,14 @@ discard block |
||
405 | 405 | $field_value = $field_obj->prepare_for_set_from_db( $raw_field_value ); |
406 | 406 | if( $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_ignored() ) ){ |
407 | 407 | unset( $result[ $field_name ] ); |
408 | - }elseif( |
|
408 | + } elseif( |
|
409 | 409 | $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_that_have_rendered_format() ) |
410 | 410 | ){ |
411 | 411 | $result[ $field_name ] = array( |
412 | 412 | 'raw' => $field_obj->prepare_for_get( $field_value ), |
413 | 413 | 'rendered' => $field_obj->prepare_for_pretty_echoing( $field_value ) |
414 | 414 | ); |
415 | - }elseif( |
|
415 | + } elseif( |
|
416 | 416 | $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_that_have_pretty_format() ) |
417 | 417 | ){ |
418 | 418 | $result[ $field_name ] = array( |
@@ -595,7 +595,7 @@ discard block |
||
595 | 595 | public static function get_related_entity_name( $relation_name, $relation_obj ){ |
596 | 596 | if( $relation_obj instanceof \EE_Belongs_To_Relation ) { |
597 | 597 | return strtolower( $relation_name ); |
598 | - }else{ |
|
598 | + } else{ |
|
599 | 599 | return \EEH_Inflector::pluralize_and_lower( $relation_name ); |
600 | 600 | } |
601 | 601 | } |
@@ -665,7 +665,7 @@ discard block |
||
665 | 665 | $valid_contexts = \EEM_Base::valid_cap_contexts(); |
666 | 666 | if( in_array( $context, $valid_contexts ) ){ |
667 | 667 | return $context; |
668 | - }else{ |
|
668 | + } else{ |
|
669 | 669 | return \EEM_Base::caps_read; |
670 | 670 | } |
671 | 671 | } |
@@ -690,7 +690,7 @@ discard block |
||
690 | 690 | $order_by = $query_parameters[ 'order_by' ]; |
691 | 691 | } elseif ( isset( $query_parameters[ 'orderby' ] ) ) { |
692 | 692 | $order_by = $query_parameters[ 'orderby' ]; |
693 | - }else{ |
|
693 | + } else{ |
|
694 | 694 | $order_by = null; |
695 | 695 | } |
696 | 696 | if( $order_by !== null ){ |
@@ -700,7 +700,7 @@ discard block |
||
700 | 700 | $group_by = $query_parameters[ 'group_by' ]; |
701 | 701 | } elseif ( isset( $query_parameters[ 'groupby' ] ) ) { |
702 | 702 | $group_by = $query_parameters[ 'groupby' ]; |
703 | - }else{ |
|
703 | + } else{ |
|
704 | 704 | $group_by = null; |
705 | 705 | } |
706 | 706 | if( $group_by !== null ){ |
@@ -723,7 +723,7 @@ discard block |
||
723 | 723 | //limit should be either a string like '23' or '23,43', or an array with two items in it |
724 | 724 | if( ! is_array( $query_parameters[ 'limit' ] ) ) { |
725 | 725 | $limit_array = explode(',', (string)$query_parameters['limit']); |
726 | - }else { |
|
726 | + } else { |
|
727 | 727 | $limit_array = $query_parameters[ 'limit' ]; |
728 | 728 | } |
729 | 729 | $sanitized_limit = array(); |
@@ -739,12 +739,12 @@ discard block |
||
739 | 739 | $sanitized_limit[] = intval( $limit_part ); |
740 | 740 | } |
741 | 741 | $model_query_params[ 'limit' ] = implode( ',', $sanitized_limit ); |
742 | - }else{ |
|
742 | + } else{ |
|
743 | 743 | $model_query_params[ 'limit' ] = \EED_Core_Rest_Api::get_default_query_limit(); |
744 | 744 | } |
745 | 745 | if( isset( $query_parameters[ 'caps' ] ) ) { |
746 | 746 | $model_query_params[ 'caps' ] = $this->validate_context( $query_parameters[ 'caps' ] ); |
747 | - }else{ |
|
747 | + } else{ |
|
748 | 748 | $model_query_params[ 'caps' ] = \EEM_Base::caps_read; |
749 | 749 | } |
750 | 750 | return apply_filters( 'FHEE__Read__create_model_query_params', $model_query_params, $query_parameters, $model ); |
@@ -764,7 +764,7 @@ discard block |
||
764 | 764 | foreach( $query_params as $key => $value ) { |
765 | 765 | if( is_array( $value ) ) { |
766 | 766 | $model_ready_query_params[ $key ] = $this->prepare_rest_query_params_key_for_models( $model, $value ); |
767 | - }else{ |
|
767 | + } else{ |
|
768 | 768 | $model_ready_query_params[ $key ] = $value; |
769 | 769 | } |
770 | 770 | } |
@@ -816,11 +816,11 @@ discard block |
||
816 | 816 | //found the model name at the exact start |
817 | 817 | $field_sans_model_name = str_replace( $model_name . '.', '', $field_to_include ); |
818 | 818 | $extracted_fields_to_include[] = $field_sans_model_name; |
819 | - }elseif( $field_to_include == $model_name ){ |
|
819 | + } elseif( $field_to_include == $model_name ){ |
|
820 | 820 | $extracted_fields_to_include[] = '*'; |
821 | 821 | } |
822 | 822 | } |
823 | - }else{ |
|
823 | + } else{ |
|
824 | 824 | //look for ones with no period |
825 | 825 | foreach( $includes as $field_to_include ) { |
826 | 826 | $field_to_include = trim( $field_to_include ); |
@@ -6,8 +6,8 @@ discard block |
||
6 | 6 | use EventEspresso\core\libraries\rest_api\Rest_Exception; |
7 | 7 | use EventEspresso\core\libraries\rest_api\Model_Data_Translator; |
8 | 8 | |
9 | -if ( !defined( 'EVENT_ESPRESSO_VERSION' ) ) { |
|
10 | - exit( 'No direct script access allowed' ); |
|
9 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
10 | + exit('No direct script access allowed'); |
|
11 | 11 | } |
12 | 12 | |
13 | 13 | /** |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | |
34 | 34 | public function __construct() { |
35 | 35 | parent::__construct(); |
36 | - \EE_Registry::instance()->load_helper( 'Inflector' ); |
|
36 | + \EE_Registry::instance()->load_helper('Inflector'); |
|
37 | 37 | $this->_fields_calculator = new Calculated_Model_Fields(); |
38 | 38 | } |
39 | 39 | |
@@ -42,22 +42,22 @@ discard block |
||
42 | 42 | * @param \WP_REST_Request $request |
43 | 43 | * @return \WP_REST_Response|\WP_Error |
44 | 44 | */ |
45 | - public static function handle_request_get_all( \WP_REST_Request $request) { |
|
45 | + public static function handle_request_get_all(\WP_REST_Request $request) { |
|
46 | 46 | $controller = new Read(); |
47 | - try{ |
|
47 | + try { |
|
48 | 48 | $matches = $controller->parse_route( |
49 | 49 | $request->get_route(), |
50 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)~', |
|
51 | - array( 'version', 'model' ) |
|
50 | + '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)~', |
|
51 | + array('version', 'model') |
|
52 | 52 | ); |
53 | - $controller->set_requested_version( $matches[ 'version' ] ); |
|
54 | - $model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'model' ] ); |
|
55 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $model_name_singular ) ) { |
|
53 | + $controller->set_requested_version($matches['version']); |
|
54 | + $model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
|
55 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) { |
|
56 | 56 | return $controller->send_response( |
57 | 57 | new \WP_Error( |
58 | 58 | 'endpoint_parsing_error', |
59 | 59 | sprintf( |
60 | - __( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ), |
|
60 | + __('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), |
|
61 | 61 | $model_name_singular |
62 | 62 | ) |
63 | 63 | ) |
@@ -65,12 +65,12 @@ discard block |
||
65 | 65 | } |
66 | 66 | return $controller->send_response( |
67 | 67 | $controller->get_entities_from_model( |
68 | - $controller->get_model_version_info()->load_model( $model_name_singular ), |
|
68 | + $controller->get_model_version_info()->load_model($model_name_singular), |
|
69 | 69 | $request |
70 | 70 | ) |
71 | 71 | ); |
72 | - } catch( \Exception $e ) { |
|
73 | - return $controller->send_response( $e ); |
|
72 | + } catch (\Exception $e) { |
|
73 | + return $controller->send_response($e); |
|
74 | 74 | } |
75 | 75 | } |
76 | 76 | |
@@ -80,21 +80,21 @@ discard block |
||
80 | 80 | * @param \WP_Rest_Request $request |
81 | 81 | * @return \WP_REST_Response|\WP_Error |
82 | 82 | */ |
83 | - public static function handle_request_get_one( \WP_Rest_Request $request ) { |
|
83 | + public static function handle_request_get_one(\WP_Rest_Request $request) { |
|
84 | 84 | $controller = new Read(); |
85 | - try{ |
|
85 | + try { |
|
86 | 86 | $matches = $controller->parse_route( |
87 | 87 | $request->get_route(), |
88 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)~', |
|
89 | - array( 'version', 'model', 'id' ) ); |
|
90 | - $controller->set_requested_version( $matches[ 'version' ] ); |
|
91 | - $model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'model' ] ); |
|
92 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $model_name_singular ) ) { |
|
88 | + '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)/(.*)~', |
|
89 | + array('version', 'model', 'id') ); |
|
90 | + $controller->set_requested_version($matches['version']); |
|
91 | + $model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
|
92 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($model_name_singular)) { |
|
93 | 93 | return $controller->send_response( |
94 | 94 | new \WP_Error( |
95 | 95 | 'endpoint_parsing_error', |
96 | 96 | sprintf( |
97 | - __( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ), |
|
97 | + __('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), |
|
98 | 98 | $model_name_singular |
99 | 99 | ) |
100 | 100 | ) |
@@ -102,12 +102,12 @@ discard block |
||
102 | 102 | } |
103 | 103 | return $controller->send_response( |
104 | 104 | $controller->get_entity_from_model( |
105 | - $controller->get_model_version_info()->load_model( $model_name_singular ), |
|
105 | + $controller->get_model_version_info()->load_model($model_name_singular), |
|
106 | 106 | $request |
107 | 107 | ) |
108 | 108 | ); |
109 | - } catch( \Exception $e ) { |
|
110 | - return $controller->send_response( $e ); |
|
109 | + } catch (\Exception $e) { |
|
110 | + return $controller->send_response($e); |
|
111 | 111 | } |
112 | 112 | } |
113 | 113 | |
@@ -119,40 +119,40 @@ discard block |
||
119 | 119 | * @param \WP_REST_Request $request |
120 | 120 | * @return \WP_REST_Response|\WP_Error |
121 | 121 | */ |
122 | - public static function handle_request_get_related( \WP_REST_Request $request ) { |
|
122 | + public static function handle_request_get_related(\WP_REST_Request $request) { |
|
123 | 123 | $controller = new Read(); |
124 | - try{ |
|
124 | + try { |
|
125 | 125 | $matches = $controller->parse_route( |
126 | 126 | $request->get_route(), |
127 | - '~' . \EED_Core_Rest_Api::ee_api_namespace_for_regex . '(.*)/(.*)/(.*)~', |
|
128 | - array( 'version', 'model', 'id', 'related_model' ) |
|
127 | + '~'.\EED_Core_Rest_Api::ee_api_namespace_for_regex.'(.*)/(.*)/(.*)~', |
|
128 | + array('version', 'model', 'id', 'related_model') |
|
129 | 129 | ); |
130 | - $controller->set_requested_version( $matches[ 'version' ] ); |
|
131 | - $main_model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'model' ] ); |
|
132 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $main_model_name_singular ) ) { |
|
130 | + $controller->set_requested_version($matches['version']); |
|
131 | + $main_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['model']); |
|
132 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($main_model_name_singular)) { |
|
133 | 133 | return $controller->send_response( |
134 | 134 | new \WP_Error( |
135 | 135 | 'endpoint_parsing_error', |
136 | 136 | sprintf( |
137 | - __( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ), |
|
137 | + __('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), |
|
138 | 138 | $main_model_name_singular |
139 | 139 | ) |
140 | 140 | ) |
141 | 141 | ); |
142 | 142 | } |
143 | - $main_model = $controller->get_model_version_info()->load_model( $main_model_name_singular ); |
|
143 | + $main_model = $controller->get_model_version_info()->load_model($main_model_name_singular); |
|
144 | 144 | //assume the related model name is plural and try to find the model's name |
145 | - $related_model_name_singular = \EEH_Inflector::singularize_and_upper( $matches[ 'related_model' ] ); |
|
146 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $related_model_name_singular ) ) { |
|
145 | + $related_model_name_singular = \EEH_Inflector::singularize_and_upper($matches['related_model']); |
|
146 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) { |
|
147 | 147 | //so the word didn't singularize well. Maybe that's just because it's a singular word? |
148 | - $related_model_name_singular = \EEH_Inflector::humanize( $matches[ 'related_model' ] ); |
|
148 | + $related_model_name_singular = \EEH_Inflector::humanize($matches['related_model']); |
|
149 | 149 | } |
150 | - if ( ! $controller->get_model_version_info()->is_model_name_in_this_version( $related_model_name_singular ) ) { |
|
150 | + if ( ! $controller->get_model_version_info()->is_model_name_in_this_version($related_model_name_singular)) { |
|
151 | 151 | return $controller->send_response( |
152 | 152 | new \WP_Error( |
153 | 153 | 'endpoint_parsing_error', |
154 | 154 | sprintf( |
155 | - __( 'There is no model for endpoint %s. Please contact event espresso support', 'event_espresso' ), |
|
155 | + __('There is no model for endpoint %s. Please contact event espresso support', 'event_espresso'), |
|
156 | 156 | $related_model_name_singular |
157 | 157 | ) |
158 | 158 | ) |
@@ -161,13 +161,13 @@ discard block |
||
161 | 161 | |
162 | 162 | return $controller->send_response( |
163 | 163 | $controller->get_entities_from_relation( |
164 | - $request->get_param( 'id' ), |
|
165 | - $main_model->related_settings_for( $related_model_name_singular ) , |
|
164 | + $request->get_param('id'), |
|
165 | + $main_model->related_settings_for($related_model_name_singular), |
|
166 | 166 | $request |
167 | 167 | ) |
168 | 168 | ); |
169 | - } catch( \Exception $e ) { |
|
170 | - return $controller->send_response( $e ); |
|
169 | + } catch (\Exception $e) { |
|
170 | + return $controller->send_response($e); |
|
171 | 171 | } |
172 | 172 | } |
173 | 173 | |
@@ -180,27 +180,27 @@ discard block |
||
180 | 180 | * @param \WP_REST_Request $request |
181 | 181 | * @return array |
182 | 182 | */ |
183 | - public function get_entities_from_model( $model, $request) { |
|
184 | - $query_params = $this->create_model_query_params( $model, $request->get_params() ); |
|
185 | - if( ! Capabilities::current_user_has_partial_access_to( $model, $query_params[ 'caps' ] ) ) { |
|
186 | - $model_name_plural = \EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() ); |
|
183 | + public function get_entities_from_model($model, $request) { |
|
184 | + $query_params = $this->create_model_query_params($model, $request->get_params()); |
|
185 | + if ( ! Capabilities::current_user_has_partial_access_to($model, $query_params['caps'])) { |
|
186 | + $model_name_plural = \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()); |
|
187 | 187 | return new \WP_Error( |
188 | - sprintf( 'rest_%s_cannot_list', $model_name_plural ), |
|
188 | + sprintf('rest_%s_cannot_list', $model_name_plural), |
|
189 | 189 | sprintf( |
190 | - __( 'Sorry, you are not allowed to list %1$s. Missing permissions: %2$s', 'event_espresso' ), |
|
190 | + __('Sorry, you are not allowed to list %1$s. Missing permissions: %2$s', 'event_espresso'), |
|
191 | 191 | $model_name_plural, |
192 | - Capabilities::get_missing_permissions_string( $model, $query_params[ 'caps' ] ) |
|
192 | + Capabilities::get_missing_permissions_string($model, $query_params['caps']) |
|
193 | 193 | ), |
194 | - array( 'status' => 403 ) |
|
194 | + array('status' => 403) |
|
195 | 195 | ); |
196 | 196 | } |
197 | 197 | |
198 | - $this->_set_headers_from_query_params( $model, $query_params ); |
|
198 | + $this->_set_headers_from_query_params($model, $query_params); |
|
199 | 199 | /** @type array $results */ |
200 | - $results = $model->get_all_wpdb_results( $query_params ); |
|
200 | + $results = $model->get_all_wpdb_results($query_params); |
|
201 | 201 | $nice_results = array( ); |
202 | - foreach ( $results as $result ) { |
|
203 | - $nice_results[ ] = $this->create_entity_from_wpdb_result( |
|
202 | + foreach ($results as $result) { |
|
203 | + $nice_results[] = $this->create_entity_from_wpdb_result( |
|
204 | 204 | $model, |
205 | 205 | $result, |
206 | 206 | $request |
@@ -221,62 +221,62 @@ discard block |
||
221 | 221 | * @param \WP_REST_Request $request |
222 | 222 | * @return array |
223 | 223 | */ |
224 | - public function get_entities_from_relation( $id, $relation, $request ) { |
|
225 | - $context = $this->validate_context( $request->get_param( 'caps' )); |
|
224 | + public function get_entities_from_relation($id, $relation, $request) { |
|
225 | + $context = $this->validate_context($request->get_param('caps')); |
|
226 | 226 | $model = $relation->get_this_model(); |
227 | 227 | $related_model = $relation->get_other_model(); |
228 | 228 | //check if they can access the 1st model object |
229 | - $query_params = array( array( $model->primary_key_name() => $id ),'limit' => 1 ); |
|
230 | - if( $model instanceof \EEM_Soft_Delete_Base ){ |
|
229 | + $query_params = array(array($model->primary_key_name() => $id), 'limit' => 1); |
|
230 | + if ($model instanceof \EEM_Soft_Delete_Base) { |
|
231 | 231 | $query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
232 | 232 | } |
233 | 233 | $restricted_query_params = $query_params; |
234 | - $restricted_query_params[ 'caps' ] = $context; |
|
235 | - $this->_set_debug_info( 'main model query params', $restricted_query_params ); |
|
236 | - $this->_set_debug_info( 'missing caps', Capabilities::get_missing_permissions_string( $related_model, $context ) ); |
|
234 | + $restricted_query_params['caps'] = $context; |
|
235 | + $this->_set_debug_info('main model query params', $restricted_query_params); |
|
236 | + $this->_set_debug_info('missing caps', Capabilities::get_missing_permissions_string($related_model, $context)); |
|
237 | 237 | |
238 | - if( |
|
238 | + if ( |
|
239 | 239 | ! ( |
240 | - Capabilities::current_user_has_partial_access_to( $related_model, $context ) |
|
241 | - && $model->exists( $restricted_query_params ) |
|
240 | + Capabilities::current_user_has_partial_access_to($related_model, $context) |
|
241 | + && $model->exists($restricted_query_params) |
|
242 | 242 | ) |
243 | - ){ |
|
244 | - if( $relation instanceof \EE_Belongs_To_Relation ) { |
|
245 | - $related_model_name_maybe_plural = strtolower( $related_model->get_this_model_name() ); |
|
246 | - }else{ |
|
247 | - $related_model_name_maybe_plural = \EEH_Inflector::pluralize_and_lower( $related_model->get_this_model_name() ); |
|
243 | + ) { |
|
244 | + if ($relation instanceof \EE_Belongs_To_Relation) { |
|
245 | + $related_model_name_maybe_plural = strtolower($related_model->get_this_model_name()); |
|
246 | + } else { |
|
247 | + $related_model_name_maybe_plural = \EEH_Inflector::pluralize_and_lower($related_model->get_this_model_name()); |
|
248 | 248 | } |
249 | 249 | return new \WP_Error( |
250 | - sprintf( 'rest_%s_cannot_list', $related_model_name_maybe_plural ), |
|
250 | + sprintf('rest_%s_cannot_list', $related_model_name_maybe_plural), |
|
251 | 251 | sprintf( |
252 | - __( 'Sorry, you are not allowed to list %1$s related to %2$s. Missing permissions: %3$s', 'event_espresso' ), |
|
252 | + __('Sorry, you are not allowed to list %1$s related to %2$s. Missing permissions: %3$s', 'event_espresso'), |
|
253 | 253 | $related_model_name_maybe_plural, |
254 | 254 | $relation->get_this_model()->get_this_model_name(), |
255 | 255 | implode( |
256 | 256 | ',', |
257 | 257 | array_keys( |
258 | - Capabilities::get_missing_permissions( $related_model, $context ) |
|
258 | + Capabilities::get_missing_permissions($related_model, $context) |
|
259 | 259 | ) |
260 | 260 | ) |
261 | 261 | ), |
262 | - array( 'status' => 403 ) |
|
262 | + array('status' => 403) |
|
263 | 263 | ); |
264 | 264 | } |
265 | - $query_params = $this->create_model_query_params( $relation->get_other_model(), $request->get_params() ); |
|
266 | - $query_params[0][ $relation->get_this_model()->get_this_model_name() . '.' . $relation->get_this_model()->primary_key_name() ] = $id; |
|
267 | - $query_params[ 'default_where_conditions' ] = 'none'; |
|
268 | - $query_params[ 'caps' ] = $context; |
|
269 | - $this->_set_headers_from_query_params( $relation->get_other_model(), $query_params ); |
|
265 | + $query_params = $this->create_model_query_params($relation->get_other_model(), $request->get_params()); |
|
266 | + $query_params[0][$relation->get_this_model()->get_this_model_name().'.'.$relation->get_this_model()->primary_key_name()] = $id; |
|
267 | + $query_params['default_where_conditions'] = 'none'; |
|
268 | + $query_params['caps'] = $context; |
|
269 | + $this->_set_headers_from_query_params($relation->get_other_model(), $query_params); |
|
270 | 270 | /** @type array $results */ |
271 | - $results = $relation->get_other_model()->get_all_wpdb_results( $query_params ); |
|
271 | + $results = $relation->get_other_model()->get_all_wpdb_results($query_params); |
|
272 | 272 | $nice_results = array(); |
273 | - foreach( $results as $result ) { |
|
273 | + foreach ($results as $result) { |
|
274 | 274 | $nice_result = $this->create_entity_from_wpdb_result( |
275 | 275 | $relation->get_other_model(), |
276 | 276 | $result, |
277 | 277 | $request |
278 | 278 | ); |
279 | - if( $relation instanceof \EE_HABTM_Relation ) { |
|
279 | + if ($relation instanceof \EE_HABTM_Relation) { |
|
280 | 280 | //put the unusual stuff (properties from the HABTM relation) first, and make sure |
281 | 281 | //if there are conflicts we prefer the properties from the main model |
282 | 282 | $join_model_result = $this->create_entity_from_wpdb_result( |
@@ -284,18 +284,18 @@ discard block |
||
284 | 284 | $result, |
285 | 285 | $request |
286 | 286 | ); |
287 | - $joined_result = array_merge( $nice_result, $join_model_result ); |
|
287 | + $joined_result = array_merge($nice_result, $join_model_result); |
|
288 | 288 | //but keep the meta stuff from the main model |
289 | - if( isset( $nice_result['meta'] ) ){ |
|
289 | + if (isset($nice_result['meta'])) { |
|
290 | 290 | $joined_result['meta'] = $nice_result['meta']; |
291 | 291 | } |
292 | 292 | $nice_result = $joined_result; |
293 | 293 | } |
294 | 294 | $nice_results[] = $nice_result; |
295 | 295 | } |
296 | - if( $relation instanceof \EE_Belongs_To_Relation ){ |
|
297 | - return array_shift( $nice_results ); |
|
298 | - }else{ |
|
296 | + if ($relation instanceof \EE_Belongs_To_Relation) { |
|
297 | + return array_shift($nice_results); |
|
298 | + } else { |
|
299 | 299 | return $nice_results; |
300 | 300 | } |
301 | 301 | } |
@@ -307,32 +307,32 @@ discard block |
||
307 | 307 | * @param array $query_params |
308 | 308 | * @return void |
309 | 309 | */ |
310 | - protected function _set_headers_from_query_params( $model, $query_params ) { |
|
311 | - $this->_set_debug_info( 'model query params', $query_params ); |
|
312 | - $this->_set_debug_info( 'missing caps', Capabilities::get_missing_permissions_string( $model, $query_params[ 'caps' ] ) ); |
|
310 | + protected function _set_headers_from_query_params($model, $query_params) { |
|
311 | + $this->_set_debug_info('model query params', $query_params); |
|
312 | + $this->_set_debug_info('missing caps', Capabilities::get_missing_permissions_string($model, $query_params['caps'])); |
|
313 | 313 | //normally the limit to a 2-part array, where the 2nd item is the limit |
314 | - if( ! isset( $query_params[ 'limit' ] ) ) { |
|
315 | - $query_params[ 'limit' ] = \EED_Core_Rest_Api::get_default_query_limit(); |
|
314 | + if ( ! isset($query_params['limit'])) { |
|
315 | + $query_params['limit'] = \EED_Core_Rest_Api::get_default_query_limit(); |
|
316 | 316 | } |
317 | - if( is_array( $query_params[ 'limit' ] ) ) { |
|
318 | - $limit_parts = $query_params[ 'limit' ]; |
|
317 | + if (is_array($query_params['limit'])) { |
|
318 | + $limit_parts = $query_params['limit']; |
|
319 | 319 | } else { |
320 | - $limit_parts = explode(',', $query_params[ 'limit' ] ); |
|
321 | - if( count( $limit_parts ) == 1 ){ |
|
322 | - $limit_parts = array(0, $limit_parts[ 0 ] ); |
|
320 | + $limit_parts = explode(',', $query_params['limit']); |
|
321 | + if (count($limit_parts) == 1) { |
|
322 | + $limit_parts = array(0, $limit_parts[0]); |
|
323 | 323 | } |
324 | 324 | } |
325 | 325 | //remove the group by and having parts of the query, as those will |
326 | 326 | //make the sql query return an array of values, instead of just a single value |
327 | - unset( $query_params[ 'group_by' ] ); |
|
328 | - unset( $query_params[ 'having' ] ); |
|
329 | - unset( $query_params[ 'limit' ] ); |
|
330 | - $count = $model->count( $query_params, null, true ); |
|
331 | - |
|
332 | - $pages = $count / $limit_parts[ 1 ]; |
|
333 | - $this->_set_response_header( 'Total', $count, false ); |
|
334 | - $this->_set_response_header( 'PageSize', $limit_parts[ 1 ], false ); |
|
335 | - $this->_set_response_header( 'TotalPages', ceil( $pages ), false ); |
|
327 | + unset($query_params['group_by']); |
|
328 | + unset($query_params['having']); |
|
329 | + unset($query_params['limit']); |
|
330 | + $count = $model->count($query_params, null, true); |
|
331 | + |
|
332 | + $pages = $count / $limit_parts[1]; |
|
333 | + $this->_set_response_header('Total', $count, false); |
|
334 | + $this->_set_response_header('PageSize', $limit_parts[1], false); |
|
335 | + $this->_set_response_header('TotalPages', ceil($pages), false); |
|
336 | 336 | } |
337 | 337 | |
338 | 338 | |
@@ -345,47 +345,47 @@ discard block |
||
345 | 345 | * @param string $deprecated no longer used |
346 | 346 | * @return array ready for being converted into json for sending to client |
347 | 347 | */ |
348 | - public function create_entity_from_wpdb_result( $model, $db_row, $rest_request, $deprecated = null ) { |
|
349 | - if( ! $rest_request instanceof \WP_REST_Request ) { |
|
348 | + public function create_entity_from_wpdb_result($model, $db_row, $rest_request, $deprecated = null) { |
|
349 | + if ( ! $rest_request instanceof \WP_REST_Request) { |
|
350 | 350 | //ok so this was called in the old style, where the 3rd arg was |
351 | 351 | //$include, and the 4th arg was $context |
352 | 352 | //now setup the request just to avoid fatal errors, although we won't be able |
353 | 353 | //to truly make use of it because it's kinda devoid of info |
354 | 354 | $rest_request = new \WP_REST_Request(); |
355 | - $rest_request->set_param( 'include', $rest_request ); |
|
356 | - $rest_request->set_param( 'caps', $deprecated ); |
|
355 | + $rest_request->set_param('include', $rest_request); |
|
356 | + $rest_request->set_param('caps', $deprecated); |
|
357 | 357 | } |
358 | - if( $rest_request->get_param( 'caps' ) == null ) { |
|
359 | - $rest_request->set_param( 'caps', \EEM_Base::caps_read ); |
|
358 | + if ($rest_request->get_param('caps') == null) { |
|
359 | + $rest_request->set_param('caps', \EEM_Base::caps_read); |
|
360 | 360 | } |
361 | - $entity_array = $this->_create_bare_entity_from_wpdb_results( $model, $db_row ); |
|
362 | - $entity_array = $this->_add_extra_fields( $model, $db_row, $entity_array ); |
|
363 | - $entity_array[ '_links' ] = $this->_get_entity_links( $model, $db_row, $entity_array ); |
|
364 | - $entity_array[ '_calculated_fields'] = $this->_get_entity_calculations( $model, $db_row, $rest_request ); |
|
365 | - $entity_array = $this->_include_requested_models( $model, $rest_request, $entity_array ); |
|
361 | + $entity_array = $this->_create_bare_entity_from_wpdb_results($model, $db_row); |
|
362 | + $entity_array = $this->_add_extra_fields($model, $db_row, $entity_array); |
|
363 | + $entity_array['_links'] = $this->_get_entity_links($model, $db_row, $entity_array); |
|
364 | + $entity_array['_calculated_fields'] = $this->_get_entity_calculations($model, $db_row, $rest_request); |
|
365 | + $entity_array = $this->_include_requested_models($model, $rest_request, $entity_array); |
|
366 | 366 | $entity_array = apply_filters( |
367 | 367 | 'FHEE__Read__create_entity_from_wpdb_results__entity_before_inaccessible_field_removal', |
368 | 368 | $entity_array, |
369 | 369 | $model, |
370 | - $rest_request->get_param( 'caps' ), |
|
370 | + $rest_request->get_param('caps'), |
|
371 | 371 | $rest_request, |
372 | 372 | $this |
373 | 373 | ); |
374 | 374 | $result_without_inaccessible_fields = Capabilities::filter_out_inaccessible_entity_fields( |
375 | 375 | $entity_array, |
376 | 376 | $model, |
377 | - $rest_request->get_param( 'caps' ), |
|
377 | + $rest_request->get_param('caps'), |
|
378 | 378 | $this->get_model_version_info() |
379 | 379 | ); |
380 | 380 | $this->_set_debug_info( |
381 | 381 | 'inaccessible fields', |
382 | - array_keys( array_diff_key( $entity_array, $result_without_inaccessible_fields ) ) |
|
382 | + array_keys(array_diff_key($entity_array, $result_without_inaccessible_fields)) |
|
383 | 383 | ); |
384 | 384 | return apply_filters( |
385 | 385 | 'FHEE__Read__create_entity_from_wpdb_results__entity_return', |
386 | 386 | $result_without_inaccessible_fields, |
387 | 387 | $model, |
388 | - $rest_request->get_param( 'caps' ) |
|
388 | + $rest_request->get_param('caps') |
|
389 | 389 | ); |
390 | 390 | } |
391 | 391 | |
@@ -397,38 +397,38 @@ discard block |
||
397 | 397 | * @param array $db_row |
398 | 398 | * @return array entity mostly ready for converting to JSON and sending in the response |
399 | 399 | */ |
400 | - protected function _create_bare_entity_from_wpdb_results( \EEM_Base $model, $db_row ) { |
|
401 | - $result = $model->deduce_fields_n_values_from_cols_n_values( $db_row ); |
|
402 | - $result = array_intersect_key( $result, $this->get_model_version_info()->fields_on_model_in_this_version( $model ) ); |
|
403 | - foreach( $result as $field_name => $raw_field_value ) { |
|
400 | + protected function _create_bare_entity_from_wpdb_results(\EEM_Base $model, $db_row) { |
|
401 | + $result = $model->deduce_fields_n_values_from_cols_n_values($db_row); |
|
402 | + $result = array_intersect_key($result, $this->get_model_version_info()->fields_on_model_in_this_version($model)); |
|
403 | + foreach ($result as $field_name => $raw_field_value) { |
|
404 | 404 | $field_obj = $model->field_settings_for($field_name); |
405 | - $field_value = $field_obj->prepare_for_set_from_db( $raw_field_value ); |
|
406 | - if( $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_ignored() ) ){ |
|
407 | - unset( $result[ $field_name ] ); |
|
408 | - }elseif( |
|
409 | - $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_that_have_rendered_format() ) |
|
410 | - ){ |
|
411 | - $result[ $field_name ] = array( |
|
412 | - 'raw' => $field_obj->prepare_for_get( $field_value ), |
|
413 | - 'rendered' => $field_obj->prepare_for_pretty_echoing( $field_value ) |
|
405 | + $field_value = $field_obj->prepare_for_set_from_db($raw_field_value); |
|
406 | + if ($this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_ignored())) { |
|
407 | + unset($result[$field_name]); |
|
408 | + }elseif ( |
|
409 | + $this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_that_have_rendered_format()) |
|
410 | + ) { |
|
411 | + $result[$field_name] = array( |
|
412 | + 'raw' => $field_obj->prepare_for_get($field_value), |
|
413 | + 'rendered' => $field_obj->prepare_for_pretty_echoing($field_value) |
|
414 | 414 | ); |
415 | - }elseif( |
|
416 | - $this->is_subclass_of_one( $field_obj, $this->get_model_version_info()->fields_that_have_pretty_format() ) |
|
417 | - ){ |
|
418 | - $result[ $field_name ] = array( |
|
419 | - 'raw' => $field_obj->prepare_for_get( $field_value ), |
|
420 | - 'pretty' => $field_obj->prepare_for_pretty_echoing( $field_value ) |
|
415 | + }elseif ( |
|
416 | + $this->is_subclass_of_one($field_obj, $this->get_model_version_info()->fields_that_have_pretty_format()) |
|
417 | + ) { |
|
418 | + $result[$field_name] = array( |
|
419 | + 'raw' => $field_obj->prepare_for_get($field_value), |
|
420 | + 'pretty' => $field_obj->prepare_for_pretty_echoing($field_value) |
|
421 | 421 | ); |
422 | - } elseif ( $field_obj instanceof \EE_Datetime_Field ) { |
|
423 | - $result[ $field_name ] = Model_Data_Translator::prepare_field_value_for_json( |
|
422 | + } elseif ($field_obj instanceof \EE_Datetime_Field) { |
|
423 | + $result[$field_name] = Model_Data_Translator::prepare_field_value_for_json( |
|
424 | 424 | $field_obj, |
425 | 425 | $field_value, |
426 | 426 | $this->get_model_version_info()->requested_version() |
427 | 427 | ); |
428 | 428 | } else { |
429 | - $result[ $field_name ] = Model_Data_Translator::prepare_field_value_for_json( |
|
429 | + $result[$field_name] = Model_Data_Translator::prepare_field_value_for_json( |
|
430 | 430 | $field_obj, |
431 | - $field_obj->prepare_for_get( $field_value ), |
|
431 | + $field_obj->prepare_for_get($field_value), |
|
432 | 432 | $this->get_model_version_info()->requested_version() |
433 | 433 | ); |
434 | 434 | } |
@@ -443,9 +443,9 @@ discard block |
||
443 | 443 | * @param array $entity_array |
444 | 444 | * @return array modified entity |
445 | 445 | */ |
446 | - protected function _add_extra_fields( \EEM_Base $model, $db_row, $entity_array ) { |
|
447 | - if( $model instanceof \EEM_CPT_Base ) { |
|
448 | - $entity_array[ 'link' ] = get_permalink( $db_row[ $model->get_primary_key_field()->get_qualified_column() ] ); |
|
446 | + protected function _add_extra_fields(\EEM_Base $model, $db_row, $entity_array) { |
|
447 | + if ($model instanceof \EEM_CPT_Base) { |
|
448 | + $entity_array['link'] = get_permalink($db_row[$model->get_primary_key_field()->get_qualified_column()]); |
|
449 | 449 | } |
450 | 450 | return $entity_array; |
451 | 451 | } |
@@ -459,20 +459,20 @@ discard block |
||
459 | 459 | * @param array $entity_array |
460 | 460 | * @return array the _links item in the entity |
461 | 461 | */ |
462 | - protected function _get_entity_links( $model, $db_row, $entity_array ) { |
|
462 | + protected function _get_entity_links($model, $db_row, $entity_array) { |
|
463 | 463 | //add basic links |
464 | 464 | $links = array( |
465 | 465 | 'self' => array( |
466 | 466 | array( |
467 | 467 | 'href' => $this->get_versioned_link_to( |
468 | - \EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() ) . '/' . $entity_array[ $model->primary_key_name() ] |
|
468 | + \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()).'/'.$entity_array[$model->primary_key_name()] |
|
469 | 469 | ) |
470 | 470 | ) |
471 | 471 | ), |
472 | 472 | 'collection' => array( |
473 | 473 | array( |
474 | 474 | 'href' => $this->get_versioned_link_to( |
475 | - \EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() ) |
|
475 | + \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()) |
|
476 | 476 | ) |
477 | 477 | ) |
478 | 478 | ), |
@@ -480,24 +480,24 @@ discard block |
||
480 | 480 | |
481 | 481 | //add link to the wp core endpoint, if wp api is active |
482 | 482 | global $wp_rest_server; |
483 | - if( $model instanceof \EEM_CPT_Base && |
|
483 | + if ($model instanceof \EEM_CPT_Base && |
|
484 | 484 | $wp_rest_server instanceof \WP_REST_Server && |
485 | - $wp_rest_server->get_route_options( '/wp/v2/posts' ) ) { |
|
486 | - $links[ \EED_Core_Rest_Api::ee_api_link_namespace . 'self_wp_post' ] = array( |
|
485 | + $wp_rest_server->get_route_options('/wp/v2/posts')) { |
|
486 | + $links[\EED_Core_Rest_Api::ee_api_link_namespace.'self_wp_post'] = array( |
|
487 | 487 | array( |
488 | - 'href' => rest_url( '/wp/v2/posts/' . $db_row[ $model->get_primary_key_field()->get_qualified_column() ] ), |
|
488 | + 'href' => rest_url('/wp/v2/posts/'.$db_row[$model->get_primary_key_field()->get_qualified_column()]), |
|
489 | 489 | 'single' => true |
490 | 490 | ) |
491 | 491 | ); |
492 | 492 | } |
493 | 493 | |
494 | 494 | //add links to related models |
495 | - foreach( $this->get_model_version_info()->relation_settings( $model ) as $relation_name => $relation_obj ) { |
|
496 | - $related_model_part = $this->get_related_entity_name( $relation_name, $relation_obj ); |
|
497 | - $links[ \EED_Core_Rest_Api::ee_api_link_namespace . $related_model_part ] = array( |
|
495 | + foreach ($this->get_model_version_info()->relation_settings($model) as $relation_name => $relation_obj) { |
|
496 | + $related_model_part = $this->get_related_entity_name($relation_name, $relation_obj); |
|
497 | + $links[\EED_Core_Rest_Api::ee_api_link_namespace.$related_model_part] = array( |
|
498 | 498 | array( |
499 | 499 | 'href' => $this->get_versioned_link_to( |
500 | - \EEH_Inflector::pluralize_and_lower( $model->get_this_model_name() ) . '/' . $entity_array[ $model->primary_key_name() ] . '/' . $related_model_part |
|
500 | + \EEH_Inflector::pluralize_and_lower($model->get_this_model_name()).'/'.$entity_array[$model->primary_key_name()].'/'.$related_model_part |
|
501 | 501 | ), |
502 | 502 | 'single' => $relation_obj instanceof \EE_Belongs_To_Relation ? true : false |
503 | 503 | ) |
@@ -513,50 +513,50 @@ discard block |
||
513 | 513 | * @param array $entity_array |
514 | 514 | * @return array the modified entity |
515 | 515 | */ |
516 | - protected function _include_requested_models( \EEM_Base $model, \WP_REST_Request $rest_request, $entity_array ) { |
|
517 | - $includes_for_this_model = $this->explode_and_get_items_prefixed_with( $rest_request->get_param( 'include' ), '' ); |
|
518 | - $includes_for_this_model = $this->_remove_model_names_from_array( $includes_for_this_model ); |
|
516 | + protected function _include_requested_models(\EEM_Base $model, \WP_REST_Request $rest_request, $entity_array) { |
|
517 | + $includes_for_this_model = $this->explode_and_get_items_prefixed_with($rest_request->get_param('include'), ''); |
|
518 | + $includes_for_this_model = $this->_remove_model_names_from_array($includes_for_this_model); |
|
519 | 519 | //if they passed in * or didn't specify any includes, return everything |
520 | - if( ! in_array( '*', $includes_for_this_model ) |
|
521 | - && ! empty( $includes_for_this_model ) ) { |
|
522 | - if( $model->has_primary_key_field() ) { |
|
520 | + if ( ! in_array('*', $includes_for_this_model) |
|
521 | + && ! empty($includes_for_this_model)) { |
|
522 | + if ($model->has_primary_key_field()) { |
|
523 | 523 | //always include the primary key. ya just gotta know that at least |
524 | 524 | $includes_for_this_model[] = $model->primary_key_name(); |
525 | 525 | } |
526 | - if( $this->explode_and_get_items_prefixed_with( $rest_request->get_param( 'calculate' ), '' ) ) { |
|
526 | + if ($this->explode_and_get_items_prefixed_with($rest_request->get_param('calculate'), '')) { |
|
527 | 527 | $includes_for_this_model[] = '_calculated_fields'; |
528 | 528 | } |
529 | - $entity_array = array_intersect_key( $entity_array, array_flip( $includes_for_this_model ) ); |
|
529 | + $entity_array = array_intersect_key($entity_array, array_flip($includes_for_this_model)); |
|
530 | 530 | } |
531 | - $relation_settings = $this->get_model_version_info()->relation_settings( $model ); |
|
532 | - foreach( $relation_settings as $relation_name => $relation_obj ) { |
|
531 | + $relation_settings = $this->get_model_version_info()->relation_settings($model); |
|
532 | + foreach ($relation_settings as $relation_name => $relation_obj) { |
|
533 | 533 | $related_fields_to_include = $this->explode_and_get_items_prefixed_with( |
534 | - $rest_request->get_param( 'include' ), |
|
534 | + $rest_request->get_param('include'), |
|
535 | 535 | $relation_name |
536 | 536 | ); |
537 | 537 | $related_fields_to_calculate = $this->explode_and_get_items_prefixed_with( |
538 | - $rest_request->get_param( 'calculate' ), |
|
538 | + $rest_request->get_param('calculate'), |
|
539 | 539 | $relation_name |
540 | 540 | ); |
541 | 541 | //did they specify they wanted to include a related model, or |
542 | 542 | //specific fields from a related model? |
543 | 543 | //or did they specify to calculate a field from a related model? |
544 | - if( $related_fields_to_include || $related_fields_to_calculate ) { |
|
544 | + if ($related_fields_to_include || $related_fields_to_calculate) { |
|
545 | 545 | //if so, we should include at least some part of the related model |
546 | 546 | $pretend_related_request = new \WP_REST_Request(); |
547 | 547 | $pretend_related_request->set_query_params( |
548 | 548 | array( |
549 | - 'caps' => $rest_request->get_param( 'caps' ), |
|
549 | + 'caps' => $rest_request->get_param('caps'), |
|
550 | 550 | 'include' => $related_fields_to_include, |
551 | 551 | 'calculate' => $related_fields_to_calculate, |
552 | 552 | ) |
553 | 553 | ); |
554 | 554 | $related_results = $this->get_entities_from_relation( |
555 | - $entity_array[ $model->primary_key_name() ], |
|
555 | + $entity_array[$model->primary_key_name()], |
|
556 | 556 | $relation_obj, |
557 | 557 | $pretend_related_request |
558 | 558 | ); |
559 | - $entity_array[ $this->get_related_entity_name( $relation_name, $relation_obj ) ] = $related_results instanceof \WP_Error ? null : $related_results; |
|
559 | + $entity_array[$this->get_related_entity_name($relation_name, $relation_obj)] = $related_results instanceof \WP_Error ? null : $related_results; |
|
560 | 560 | } |
561 | 561 | } |
562 | 562 | return $entity_array; |
@@ -568,8 +568,8 @@ discard block |
||
568 | 568 | * @param array $arr |
569 | 569 | * @return array |
570 | 570 | */ |
571 | - private function _remove_model_names_from_array( $arr ) { |
|
572 | - return array_diff( $arr, array_keys( \EE_Registry::instance()->non_abstract_db_models ) ); |
|
571 | + private function _remove_model_names_from_array($arr) { |
|
572 | + return array_diff($arr, array_keys(\EE_Registry::instance()->non_abstract_db_models)); |
|
573 | 573 | } |
574 | 574 | /** |
575 | 575 | * Gets the calculated fields for the response |
@@ -579,16 +579,16 @@ discard block |
||
579 | 579 | * @param \WP_REST_Request $rest_request |
580 | 580 | * @return array the _calculations item in the entity |
581 | 581 | */ |
582 | - protected function _get_entity_calculations( $model, $wpdb_row, $rest_request ) { |
|
582 | + protected function _get_entity_calculations($model, $wpdb_row, $rest_request) { |
|
583 | 583 | $calculated_fields = $this->explode_and_get_items_prefixed_with( |
584 | - $rest_request->get_param( 'calculate' ), |
|
584 | + $rest_request->get_param('calculate'), |
|
585 | 585 | '' |
586 | 586 | ); |
587 | 587 | //note: setting calculate=* doesn't do anything |
588 | 588 | $calculated_fields_to_return = array(); |
589 | - foreach( $calculated_fields as $field_to_calculate ) { |
|
590 | - try{ |
|
591 | - $calculated_fields_to_return[ $field_to_calculate ] = Model_Data_Translator::prepare_field_value_for_json( |
|
589 | + foreach ($calculated_fields as $field_to_calculate) { |
|
590 | + try { |
|
591 | + $calculated_fields_to_return[$field_to_calculate] = Model_Data_Translator::prepare_field_value_for_json( |
|
592 | 592 | null, |
593 | 593 | $this->_fields_calculator->retrieve_calculated_field_value( |
594 | 594 | $model, |
@@ -599,10 +599,10 @@ discard block |
||
599 | 599 | ), |
600 | 600 | $this->get_model_version_info()->requested_version() |
601 | 601 | ); |
602 | - } catch( Rest_Exception $e ) { |
|
602 | + } catch (Rest_Exception $e) { |
|
603 | 603 | //if we don't have permission to read it, just leave it out. but let devs know about the problem |
604 | 604 | $this->_set_response_header( |
605 | - 'Notices-Field-Calculation-Errors[' . $e->get_string_code() . '][' . $model->get_this_model_name() . '][' . $field_to_calculate . ']', |
|
605 | + 'Notices-Field-Calculation-Errors['.$e->get_string_code().']['.$model->get_this_model_name().']['.$field_to_calculate.']', |
|
606 | 606 | $e->getMessage(), |
607 | 607 | true |
608 | 608 | ); |
@@ -616,7 +616,7 @@ discard block |
||
616 | 616 | * @param string $link_part_after_version_and_slash eg "events/10/datetimes" |
617 | 617 | * @return string url eg "http://mysite.com/wp-json/ee/v4.6/events/10/datetimes" |
618 | 618 | */ |
619 | - public function get_versioned_link_to( $link_part_after_version_and_slash ) { |
|
619 | + public function get_versioned_link_to($link_part_after_version_and_slash) { |
|
620 | 620 | return rest_url( |
621 | 621 | \EED_Core_Rest_Api::ee_api_namespace |
622 | 622 | . $this->get_model_version_info()->requested_version() |
@@ -632,11 +632,11 @@ discard block |
||
632 | 632 | * @param \EE_Model_Relation_Base $relation_obj |
633 | 633 | * @return string |
634 | 634 | */ |
635 | - public static function get_related_entity_name( $relation_name, $relation_obj ){ |
|
636 | - if( $relation_obj instanceof \EE_Belongs_To_Relation ) { |
|
637 | - return strtolower( $relation_name ); |
|
638 | - }else{ |
|
639 | - return \EEH_Inflector::pluralize_and_lower( $relation_name ); |
|
635 | + public static function get_related_entity_name($relation_name, $relation_obj) { |
|
636 | + if ($relation_obj instanceof \EE_Belongs_To_Relation) { |
|
637 | + return strtolower($relation_name); |
|
638 | + } else { |
|
639 | + return \EEH_Inflector::pluralize_and_lower($relation_name); |
|
640 | 640 | } |
641 | 641 | } |
642 | 642 | |
@@ -649,43 +649,43 @@ discard block |
||
649 | 649 | * @param \WP_REST_Request $request |
650 | 650 | * @return array |
651 | 651 | */ |
652 | - public function get_entity_from_model( $model, $request ) { |
|
653 | - $query_params = array( array( $model->primary_key_name() => $request->get_param( 'id' ) ),'limit' => 1); |
|
654 | - if( $model instanceof \EEM_Soft_Delete_Base ){ |
|
652 | + public function get_entity_from_model($model, $request) { |
|
653 | + $query_params = array(array($model->primary_key_name() => $request->get_param('id')), 'limit' => 1); |
|
654 | + if ($model instanceof \EEM_Soft_Delete_Base) { |
|
655 | 655 | $query_params = $model->alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
656 | 656 | } |
657 | 657 | $restricted_query_params = $query_params; |
658 | - $restricted_query_params[ 'caps' ] = $this->validate_context( $request->get_param( 'caps' ) ); |
|
659 | - $this->_set_debug_info( 'model query params', $restricted_query_params ); |
|
660 | - $model_rows = $model->get_all_wpdb_results( $restricted_query_params ); |
|
661 | - if ( ! empty ( $model_rows ) ) { |
|
658 | + $restricted_query_params['caps'] = $this->validate_context($request->get_param('caps')); |
|
659 | + $this->_set_debug_info('model query params', $restricted_query_params); |
|
660 | + $model_rows = $model->get_all_wpdb_results($restricted_query_params); |
|
661 | + if ( ! empty ($model_rows)) { |
|
662 | 662 | return $this->create_entity_from_wpdb_result( |
663 | 663 | $model, |
664 | - array_shift( $model_rows ), |
|
664 | + array_shift($model_rows), |
|
665 | 665 | $request ); |
666 | 666 | } else { |
667 | 667 | //ok let's test to see if we WOULD have found it, had we not had restrictions from missing capabilities |
668 | - $lowercase_model_name = strtolower( $model->get_this_model_name() ); |
|
669 | - $model_rows_found_sans_restrictions = $model->get_all_wpdb_results( $query_params ); |
|
670 | - if( ! empty( $model_rows_found_sans_restrictions ) ) { |
|
668 | + $lowercase_model_name = strtolower($model->get_this_model_name()); |
|
669 | + $model_rows_found_sans_restrictions = $model->get_all_wpdb_results($query_params); |
|
670 | + if ( ! empty($model_rows_found_sans_restrictions)) { |
|
671 | 671 | //you got shafted- it existed but we didn't want to tell you! |
672 | 672 | return new \WP_Error( |
673 | 673 | 'rest_user_cannot_read', |
674 | 674 | sprintf( |
675 | - __( 'Sorry, you cannot read this %1$s. Missing permissions are: %2$s', 'event_espresso' ), |
|
676 | - strtolower( $model->get_this_model_name() ), |
|
675 | + __('Sorry, you cannot read this %1$s. Missing permissions are: %2$s', 'event_espresso'), |
|
676 | + strtolower($model->get_this_model_name()), |
|
677 | 677 | Capabilities::get_missing_permissions_string( |
678 | 678 | $model, |
679 | - $this->validate_context( $request->get_param( 'caps' ) ) ) |
|
679 | + $this->validate_context($request->get_param('caps')) ) |
|
680 | 680 | ), |
681 | - array( 'status' => 403 ) |
|
681 | + array('status' => 403) |
|
682 | 682 | ); |
683 | 683 | } else { |
684 | 684 | //it's not you. It just doesn't exist |
685 | 685 | return new \WP_Error( |
686 | - sprintf( 'rest_%s_invalid_id', $lowercase_model_name ), |
|
687 | - sprintf( __( 'Invalid %s ID.', 'event_espresso' ), $lowercase_model_name ), |
|
688 | - array( 'status' => 404 ) |
|
686 | + sprintf('rest_%s_invalid_id', $lowercase_model_name), |
|
687 | + sprintf(__('Invalid %s ID.', 'event_espresso'), $lowercase_model_name), |
|
688 | + array('status' => 404) |
|
689 | 689 | ); |
690 | 690 | } |
691 | 691 | } |
@@ -698,14 +698,14 @@ discard block |
||
698 | 698 | * @param string $context |
699 | 699 | * @return string array key of EEM_Base::cap_contexts_to_cap_action_map() |
700 | 700 | */ |
701 | - public function validate_context( $context ) { |
|
702 | - if( ! $context ) { |
|
701 | + public function validate_context($context) { |
|
702 | + if ( ! $context) { |
|
703 | 703 | $context = \EEM_Base::caps_read; |
704 | 704 | } |
705 | 705 | $valid_contexts = \EEM_Base::valid_cap_contexts(); |
706 | - if( in_array( $context, $valid_contexts ) ){ |
|
706 | + if (in_array($context, $valid_contexts)) { |
|
707 | 707 | return $context; |
708 | - }else{ |
|
708 | + } else { |
|
709 | 709 | return \EEM_Base::caps_read; |
710 | 710 | } |
711 | 711 | } |
@@ -724,77 +724,77 @@ discard block |
||
724 | 724 | * that absolutely no results should be returned |
725 | 725 | * @throws \EE_Error |
726 | 726 | */ |
727 | - public function create_model_query_params( $model, $query_parameters ) { |
|
727 | + public function create_model_query_params($model, $query_parameters) { |
|
728 | 728 | $model_query_params = array( ); |
729 | - if ( isset( $query_parameters[ 'where' ] ) ) { |
|
730 | - $model_query_params[ 0 ] = Model_Data_Translator::prepare_conditions_query_params_for_models( |
|
731 | - $query_parameters[ 'where' ], |
|
729 | + if (isset($query_parameters['where'])) { |
|
730 | + $model_query_params[0] = Model_Data_Translator::prepare_conditions_query_params_for_models( |
|
731 | + $query_parameters['where'], |
|
732 | 732 | $model, |
733 | 733 | $this->get_model_version_info()->requested_version() |
734 | 734 | ); |
735 | 735 | } |
736 | - if ( isset( $query_parameters[ 'order_by' ] ) ) { |
|
737 | - $order_by = $query_parameters[ 'order_by' ]; |
|
738 | - } elseif ( isset( $query_parameters[ 'orderby' ] ) ) { |
|
739 | - $order_by = $query_parameters[ 'orderby' ]; |
|
740 | - }else{ |
|
736 | + if (isset($query_parameters['order_by'])) { |
|
737 | + $order_by = $query_parameters['order_by']; |
|
738 | + } elseif (isset($query_parameters['orderby'])) { |
|
739 | + $order_by = $query_parameters['orderby']; |
|
740 | + } else { |
|
741 | 741 | $order_by = null; |
742 | 742 | } |
743 | - if( $order_by !== null ){ |
|
744 | - $model_query_params[ 'order_by' ] = $order_by; |
|
743 | + if ($order_by !== null) { |
|
744 | + $model_query_params['order_by'] = $order_by; |
|
745 | 745 | } |
746 | - if ( isset( $query_parameters[ 'group_by' ] ) ) { |
|
747 | - $group_by = $query_parameters[ 'group_by' ]; |
|
748 | - } elseif ( isset( $query_parameters[ 'groupby' ] ) ) { |
|
749 | - $group_by = $query_parameters[ 'groupby' ]; |
|
750 | - }else{ |
|
746 | + if (isset($query_parameters['group_by'])) { |
|
747 | + $group_by = $query_parameters['group_by']; |
|
748 | + } elseif (isset($query_parameters['groupby'])) { |
|
749 | + $group_by = $query_parameters['groupby']; |
|
750 | + } else { |
|
751 | 751 | $group_by = null; |
752 | 752 | } |
753 | - if( $group_by !== null ){ |
|
754 | - $model_query_params[ 'group_by' ] = $group_by; |
|
753 | + if ($group_by !== null) { |
|
754 | + $model_query_params['group_by'] = $group_by; |
|
755 | 755 | } |
756 | - if ( isset( $query_parameters[ 'having' ] ) ) { |
|
757 | - $model_query_params[ 'having' ] = Model_Data_Translator::prepare_conditions_query_params_for_models( |
|
758 | - $query_parameters[ 'having' ], |
|
756 | + if (isset($query_parameters['having'])) { |
|
757 | + $model_query_params['having'] = Model_Data_Translator::prepare_conditions_query_params_for_models( |
|
758 | + $query_parameters['having'], |
|
759 | 759 | $model, |
760 | 760 | $this->get_model_version_info()->requested_version() |
761 | 761 | ); |
762 | 762 | } |
763 | - if ( isset( $query_parameters[ 'order' ] ) ) { |
|
764 | - $model_query_params[ 'order' ] = $query_parameters[ 'order' ]; |
|
763 | + if (isset($query_parameters['order'])) { |
|
764 | + $model_query_params['order'] = $query_parameters['order']; |
|
765 | 765 | } |
766 | - if ( isset( $query_parameters[ 'mine' ] ) ){ |
|
767 | - $model_query_params = $model->alter_query_params_to_only_include_mine( $model_query_params ); |
|
766 | + if (isset($query_parameters['mine'])) { |
|
767 | + $model_query_params = $model->alter_query_params_to_only_include_mine($model_query_params); |
|
768 | 768 | } |
769 | - if( isset( $query_parameters[ 'limit' ] ) ) { |
|
769 | + if (isset($query_parameters['limit'])) { |
|
770 | 770 | //limit should be either a string like '23' or '23,43', or an array with two items in it |
771 | - if( ! is_array( $query_parameters[ 'limit' ] ) ) { |
|
772 | - $limit_array = explode(',', (string)$query_parameters['limit']); |
|
773 | - }else { |
|
774 | - $limit_array = $query_parameters[ 'limit' ]; |
|
771 | + if ( ! is_array($query_parameters['limit'])) { |
|
772 | + $limit_array = explode(',', (string) $query_parameters['limit']); |
|
773 | + } else { |
|
774 | + $limit_array = $query_parameters['limit']; |
|
775 | 775 | } |
776 | 776 | $sanitized_limit = array(); |
777 | - foreach( $limit_array as $key => $limit_part ) { |
|
778 | - if( $this->_debug_mode && ( ! is_numeric( $limit_part ) || count( $sanitized_limit ) > 2 ) ) { |
|
777 | + foreach ($limit_array as $key => $limit_part) { |
|
778 | + if ($this->_debug_mode && ( ! is_numeric($limit_part) || count($sanitized_limit) > 2)) { |
|
779 | 779 | throw new \EE_Error( |
780 | 780 | sprintf( |
781 | - __( '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' ), |
|
782 | - json_encode( $query_parameters[ 'limit' ] ) |
|
781 | + __('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'), |
|
782 | + json_encode($query_parameters['limit']) |
|
783 | 783 | ) |
784 | 784 | ); |
785 | 785 | } |
786 | - $sanitized_limit[] = intval( $limit_part ); |
|
786 | + $sanitized_limit[] = intval($limit_part); |
|
787 | 787 | } |
788 | - $model_query_params[ 'limit' ] = implode( ',', $sanitized_limit ); |
|
789 | - }else{ |
|
790 | - $model_query_params[ 'limit' ] = \EED_Core_Rest_Api::get_default_query_limit(); |
|
788 | + $model_query_params['limit'] = implode(',', $sanitized_limit); |
|
789 | + } else { |
|
790 | + $model_query_params['limit'] = \EED_Core_Rest_Api::get_default_query_limit(); |
|
791 | 791 | } |
792 | - if( isset( $query_parameters[ 'caps' ] ) ) { |
|
793 | - $model_query_params[ 'caps' ] = $this->validate_context( $query_parameters[ 'caps' ] ); |
|
794 | - }else{ |
|
795 | - $model_query_params[ 'caps' ] = \EEM_Base::caps_read; |
|
792 | + if (isset($query_parameters['caps'])) { |
|
793 | + $model_query_params['caps'] = $this->validate_context($query_parameters['caps']); |
|
794 | + } else { |
|
795 | + $model_query_params['caps'] = \EEM_Base::caps_read; |
|
796 | 796 | } |
797 | - return apply_filters( 'FHEE__Read__create_model_query_params', $model_query_params, $query_parameters, $model ); |
|
797 | + return apply_filters('FHEE__Read__create_model_query_params', $model_query_params, $query_parameters, $model); |
|
798 | 798 | } |
799 | 799 | |
800 | 800 | |
@@ -806,13 +806,13 @@ discard block |
||
806 | 806 | * @param array $query_params sub-array from @see EEM_Base::get_all() |
807 | 807 | * @return array |
808 | 808 | */ |
809 | - public function prepare_rest_query_params_key_for_models( $model, $query_params ) { |
|
809 | + public function prepare_rest_query_params_key_for_models($model, $query_params) { |
|
810 | 810 | $model_ready_query_params = array(); |
811 | - foreach( $query_params as $key => $value ) { |
|
812 | - if( is_array( $value ) ) { |
|
813 | - $model_ready_query_params[ $key ] = $this->prepare_rest_query_params_key_for_models( $model, $value ); |
|
814 | - }else{ |
|
815 | - $model_ready_query_params[ $key ] = $value; |
|
811 | + foreach ($query_params as $key => $value) { |
|
812 | + if (is_array($value)) { |
|
813 | + $model_ready_query_params[$key] = $this->prepare_rest_query_params_key_for_models($model, $value); |
|
814 | + } else { |
|
815 | + $model_ready_query_params[$key] = $value; |
|
816 | 816 | } |
817 | 817 | } |
818 | 818 | return $model_ready_query_params; |
@@ -826,13 +826,13 @@ discard block |
||
826 | 826 | * @param $query_params |
827 | 827 | * @return array |
828 | 828 | */ |
829 | - public function prepare_rest_query_params_values_for_models( $model, $query_params ) { |
|
829 | + public function prepare_rest_query_params_values_for_models($model, $query_params) { |
|
830 | 830 | $model_ready_query_params = array(); |
831 | - foreach( $query_params as $key => $value ) { |
|
832 | - if( is_array( $value ) ) { |
|
833 | - $model_ready_query_params[ $key ] = $this->prepare_rest_query_params_values_for_models( $model, $value ); |
|
831 | + foreach ($query_params as $key => $value) { |
|
832 | + if (is_array($value)) { |
|
833 | + $model_ready_query_params[$key] = $this->prepare_rest_query_params_values_for_models($model, $value); |
|
834 | 834 | } else { |
835 | - $model_ready_query_params[ $key ] = $value; |
|
835 | + $model_ready_query_params[$key] = $value; |
|
836 | 836 | } |
837 | 837 | } |
838 | 838 | return $model_ready_query_params; |
@@ -847,33 +847,33 @@ discard block |
||
847 | 847 | * we only return strings starting with that and a period; if no prefix was specified |
848 | 848 | * we return all items containing NO periods |
849 | 849 | */ |
850 | - public function explode_and_get_items_prefixed_with( $string_to_explode, $prefix ) { |
|
851 | - if( is_string( $string_to_explode ) ) { |
|
852 | - $exploded_contents = explode( ',', $string_to_explode ); |
|
853 | - } else if( is_array( $string_to_explode ) ) { |
|
850 | + public function explode_and_get_items_prefixed_with($string_to_explode, $prefix) { |
|
851 | + if (is_string($string_to_explode)) { |
|
852 | + $exploded_contents = explode(',', $string_to_explode); |
|
853 | + } else if (is_array($string_to_explode)) { |
|
854 | 854 | $exploded_contents = $string_to_explode; |
855 | 855 | } else { |
856 | 856 | $exploded_contents = array(); |
857 | 857 | } |
858 | 858 | //if the string was empty, we want an empty array |
859 | - $exploded_contents = array_filter( $exploded_contents ); |
|
859 | + $exploded_contents = array_filter($exploded_contents); |
|
860 | 860 | $contents_with_prefix = array(); |
861 | - foreach( $exploded_contents as $item ) { |
|
862 | - $item = trim( $item ); |
|
861 | + foreach ($exploded_contents as $item) { |
|
862 | + $item = trim($item); |
|
863 | 863 | //if no prefix was provided, so we look for items with no "." in them |
864 | - if( ! $prefix ) { |
|
864 | + if ( ! $prefix) { |
|
865 | 865 | //does this item have a period? |
866 | - if( strpos( $item, '.' ) === false ) { |
|
866 | + if (strpos($item, '.') === false) { |
|
867 | 867 | //if not, then its what we're looking for |
868 | 868 | $contents_with_prefix[] = $item; |
869 | 869 | } |
870 | - } else if( strpos( $item, $prefix . '.' ) === 0 ) { |
|
870 | + } else if (strpos($item, $prefix.'.') === 0) { |
|
871 | 871 | //this item has the prefix and a period, grab it |
872 | 872 | $contents_with_prefix[] = substr( |
873 | 873 | $item, |
874 | - strpos( $item, $prefix . '.' ) + strlen( $prefix . '.' ) |
|
874 | + strpos($item, $prefix.'.') + strlen($prefix.'.') |
|
875 | 875 | ); |
876 | - } else if( $item === $prefix ) { |
|
876 | + } else if ($item === $prefix) { |
|
877 | 877 | //this item is JUST the prefix |
878 | 878 | //so let's grab everything after, which is a blank string |
879 | 879 | $contents_with_prefix[] = ''; |
@@ -896,33 +896,33 @@ discard block |
||
896 | 896 | * the fields for that model, with the model's name removed from each. |
897 | 897 | * If $include_string was blank or '*' returns an empty array |
898 | 898 | */ |
899 | - public function extract_includes_for_this_model( $include_string, $model_name = null ) { |
|
900 | - if( is_array( $include_string ) ) { |
|
901 | - $include_string = implode( ',', $include_string ); |
|
899 | + public function extract_includes_for_this_model($include_string, $model_name = null) { |
|
900 | + if (is_array($include_string)) { |
|
901 | + $include_string = implode(',', $include_string); |
|
902 | 902 | } |
903 | - if( $include_string === '*' || $include_string === '' ) { |
|
903 | + if ($include_string === '*' || $include_string === '') { |
|
904 | 904 | return array(); |
905 | 905 | } |
906 | - $includes = explode( ',', $include_string ); |
|
906 | + $includes = explode(',', $include_string); |
|
907 | 907 | $extracted_fields_to_include = array(); |
908 | - if( $model_name ){ |
|
909 | - foreach( $includes as $field_to_include ) { |
|
910 | - $field_to_include = trim( $field_to_include ); |
|
911 | - if( strpos( $field_to_include, $model_name . '.' ) === 0 ) { |
|
908 | + if ($model_name) { |
|
909 | + foreach ($includes as $field_to_include) { |
|
910 | + $field_to_include = trim($field_to_include); |
|
911 | + if (strpos($field_to_include, $model_name.'.') === 0) { |
|
912 | 912 | //found the model name at the exact start |
913 | - $field_sans_model_name = str_replace( $model_name . '.', '', $field_to_include ); |
|
913 | + $field_sans_model_name = str_replace($model_name.'.', '', $field_to_include); |
|
914 | 914 | $extracted_fields_to_include[] = $field_sans_model_name; |
915 | - }elseif( $field_to_include == $model_name ){ |
|
915 | + }elseif ($field_to_include == $model_name) { |
|
916 | 916 | $extracted_fields_to_include[] = '*'; |
917 | 917 | } |
918 | 918 | } |
919 | - }else{ |
|
919 | + } else { |
|
920 | 920 | //look for ones with no period |
921 | - foreach( $includes as $field_to_include ) { |
|
922 | - $field_to_include = trim( $field_to_include ); |
|
921 | + foreach ($includes as $field_to_include) { |
|
922 | + $field_to_include = trim($field_to_include); |
|
923 | 923 | if ( |
924 | - strpos( $field_to_include, '.' ) === false |
|
925 | - && ! $this->get_model_version_info()->is_model_name_in_this_version( $field_to_include ) |
|
924 | + strpos($field_to_include, '.') === false |
|
925 | + && ! $this->get_model_version_info()->is_model_name_in_this_version($field_to_include) |
|
926 | 926 | ) { |
927 | 927 | $extracted_fields_to_include[] = $field_to_include; |
928 | 928 | } |
@@ -1,8 +1,8 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | namespace EventEspresso\core\libraries\rest_api; |
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 | /** |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | protected $_cached_fields_on_models = array(); |
89 | 89 | |
90 | 90 | |
91 | - public function __construct( $requested_version ) { |
|
91 | + public function __construct($requested_version) { |
|
92 | 92 | $this->_requested_version = $requested_version; |
93 | 93 | $this->_model_changes = array( |
94 | 94 | '4.8.29' => array( |
@@ -110,13 +110,13 @@ discard block |
||
110 | 110 | 'table_column' => 'N/A', |
111 | 111 | 'always_available' => true, |
112 | 112 | ); |
113 | - foreach( $this->_resource_changes as $version => $model_classnames ) { |
|
114 | - foreach( $model_classnames as $model_classname => $extra_fields ) { |
|
115 | - foreach( $extra_fields as $fieldname => $field_data ) { |
|
116 | - $this->_resource_changes[ $model_classname ][ $fieldname ][ 'name' ] = $fieldname; |
|
117 | - foreach( $defaults as $attribute => $default_value ) { |
|
118 | - if( ! isset( $this->_resource_changes[ $model_classname ][ $fieldname ][ $attribute ] ) ) { |
|
119 | - $this->_resource_changes[ $model_classname ][ $fieldname ][ $attribute ] = $default_value; |
|
113 | + foreach ($this->_resource_changes as $version => $model_classnames) { |
|
114 | + foreach ($model_classnames as $model_classname => $extra_fields) { |
|
115 | + foreach ($extra_fields as $fieldname => $field_data) { |
|
116 | + $this->_resource_changes[$model_classname][$fieldname]['name'] = $fieldname; |
|
117 | + foreach ($defaults as $attribute => $default_value) { |
|
118 | + if ( ! isset($this->_resource_changes[$model_classname][$fieldname][$attribute])) { |
|
119 | + $this->_resource_changes[$model_classname][$fieldname][$attribute] = $default_value; |
|
120 | 120 | } |
121 | 121 | } |
122 | 122 | } |
@@ -132,11 +132,11 @@ discard block |
||
132 | 132 | * @return array |
133 | 133 | */ |
134 | 134 | public function model_changes_between_requested_version_and_current() { |
135 | - if( $this->_cached_model_changes_between_requested_version_and_current === null ) { |
|
135 | + if ($this->_cached_model_changes_between_requested_version_and_current === null) { |
|
136 | 136 | $model_changes = array(); |
137 | - foreach( $this->model_changes() as $version => $models_changed_in_version ) { |
|
138 | - if( $version <= \EED_Core_Rest_Api::core_version() && $version > $this->requested_version() ) { |
|
139 | - $model_changes[ $version ] = $models_changed_in_version; |
|
137 | + foreach ($this->model_changes() as $version => $models_changed_in_version) { |
|
138 | + if ($version <= \EED_Core_Rest_Api::core_version() && $version > $this->requested_version()) { |
|
139 | + $model_changes[$version] = $models_changed_in_version; |
|
140 | 140 | } |
141 | 141 | } |
142 | 142 | $this->_cached_model_changes_between_requested_version_and_current = $model_changes; |
@@ -152,11 +152,11 @@ discard block |
||
152 | 152 | * @return array |
153 | 153 | */ |
154 | 154 | public function resource_changes_between_requested_version_and_current() { |
155 | - if( $this->_cached_resource_changes_between_requested_version_and_current === null ) { |
|
155 | + if ($this->_cached_resource_changes_between_requested_version_and_current === null) { |
|
156 | 156 | $resource_changes = array(); |
157 | - foreach( $this->resource_changes() as $version => $model_classnames ) { |
|
158 | - if( $version <= \EED_Core_Rest_Api::core_version() && $version > $this->requested_version() ) { |
|
159 | - $resource_changes[ $version ] = $model_classnames; |
|
157 | + foreach ($this->resource_changes() as $version => $model_classnames) { |
|
158 | + if ($version <= \EED_Core_Rest_Api::core_version() && $version > $this->requested_version()) { |
|
159 | + $resource_changes[$version] = $model_classnames; |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | $this->_cached_resource_changes_between_requested_version_and_current = $resource_changes; |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | * If a request was sent to 'wp-json/ee/v4.7/events' this would be '4.7' |
169 | 169 | * @return string like '4.6' |
170 | 170 | */ |
171 | - public function requested_version(){ |
|
171 | + public function requested_version() { |
|
172 | 172 | return $this->_requested_version; |
173 | 173 | } |
174 | 174 | |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | * If a version is missing then we don't know anything about what changes it introduced from the previous version |
183 | 183 | * @return array |
184 | 184 | */ |
185 | - public function model_changes(){ |
|
185 | + public function model_changes() { |
|
186 | 186 | return $this->_model_changes; |
187 | 187 | } |
188 | 188 | |
@@ -193,12 +193,12 @@ discard block |
||
193 | 193 | * @return array keys are model names, values are their classname |
194 | 194 | */ |
195 | 195 | public function models_for_requested_version() { |
196 | - if( $this->_cached_models_for_requested_version === null ) { |
|
196 | + if ($this->_cached_models_for_requested_version === null) { |
|
197 | 197 | $all_models_in_current_version = \EE_Registry::instance()->non_abstract_db_models; |
198 | - foreach( $this->model_changes_between_requested_version_and_current() as $version => $models_changed ) { |
|
199 | - foreach( $models_changed as $model_name => $new_indicator_or_fields_added ) { |
|
200 | - if( $new_indicator_or_fields_added === Model_Version_Info::model_added ) { |
|
201 | - unset( $all_models_in_current_version[ $model_name ] ); |
|
198 | + foreach ($this->model_changes_between_requested_version_and_current() as $version => $models_changed) { |
|
199 | + foreach ($models_changed as $model_name => $new_indicator_or_fields_added) { |
|
200 | + if ($new_indicator_or_fields_added === Model_Version_Info::model_added) { |
|
201 | + unset($all_models_in_current_version[$model_name]); |
|
202 | 202 | } |
203 | 203 | } |
204 | 204 | } |
@@ -217,11 +217,11 @@ discard block |
||
217 | 217 | * @param string $model_name eg 'Event' |
218 | 218 | * @return boolean |
219 | 219 | */ |
220 | - public function is_model_name_in_this_version( $model_name ) { |
|
220 | + public function is_model_name_in_this_version($model_name) { |
|
221 | 221 | $model_names = $this->models_for_requested_version(); |
222 | - if( isset( $model_names[ $model_name ] ) ) { |
|
222 | + if (isset($model_names[$model_name])) { |
|
223 | 223 | return true; |
224 | - }else{ |
|
224 | + } else { |
|
225 | 225 | return false; |
226 | 226 | } |
227 | 227 | } |
@@ -236,10 +236,10 @@ discard block |
||
236 | 236 | * @return \EEM_Base |
237 | 237 | * @throws \EE_Error |
238 | 238 | */ |
239 | - public function load_model( $model_name ) { |
|
240 | - if( $this->is_model_name_in_this_version( $model_name ) ) { |
|
241 | - return \EE_Registry::instance()->load_model( $model_name ); |
|
242 | - }else{ |
|
239 | + public function load_model($model_name) { |
|
240 | + if ($this->is_model_name_in_this_version($model_name)) { |
|
241 | + return \EE_Registry::instance()->load_model($model_name); |
|
242 | + } else { |
|
243 | 243 | throw new \EE_Error( |
244 | 244 | sprintf( |
245 | 245 | __( |
@@ -261,21 +261,21 @@ discard block |
||
261 | 261 | * @param \EEM_Base $model |
262 | 262 | * @return array|\EE_Model_Field_Base[] |
263 | 263 | */ |
264 | - public function fields_on_model_in_this_version( $model ) { |
|
265 | - if( ! isset( $this->_cached_fields_on_models[ $model->get_this_model_name() ] ) ) { |
|
264 | + public function fields_on_model_in_this_version($model) { |
|
265 | + if ( ! isset($this->_cached_fields_on_models[$model->get_this_model_name()])) { |
|
266 | 266 | //get all model changes between the requested version and current core version |
267 | 267 | $changes = $this->model_changes_between_requested_version_and_current(); |
268 | 268 | //fetch all fields currently on this model |
269 | 269 | $current_fields = $model->field_settings(); |
270 | 270 | //remove all fields that have been added since |
271 | - foreach( $changes as $version => $changes_in_version ) { |
|
272 | - if( |
|
273 | - isset( $changes_in_version[ $model->get_this_model_name() ] ) |
|
274 | - && $changes_in_version[ $model->get_this_model_name() ] !== Model_Version_Info::model_added |
|
271 | + foreach ($changes as $version => $changes_in_version) { |
|
272 | + if ( |
|
273 | + isset($changes_in_version[$model->get_this_model_name()]) |
|
274 | + && $changes_in_version[$model->get_this_model_name()] !== Model_Version_Info::model_added |
|
275 | 275 | ) { |
276 | 276 | $current_fields = array_diff_key( |
277 | 277 | $current_fields, |
278 | - array_flip( $changes_in_version[ $model->get_this_model_name() ] ) |
|
278 | + array_flip($changes_in_version[$model->get_this_model_name()]) |
|
279 | 279 | ); |
280 | 280 | } |
281 | 281 | } |
@@ -293,9 +293,9 @@ discard block |
||
293 | 293 | * @param array $classnames |
294 | 294 | * @return boolean |
295 | 295 | */ |
296 | - public function is_subclass_of_one( $object, $classnames ) { |
|
297 | - foreach( $classnames as $classname ) { |
|
298 | - if( is_a( $object, $classname ) ) { |
|
296 | + public function is_subclass_of_one($object, $classnames) { |
|
297 | + foreach ($classnames as $classname) { |
|
298 | + if (is_a($object, $classname)) { |
|
299 | 299 | return true; |
300 | 300 | } |
301 | 301 | } |
@@ -306,10 +306,10 @@ discard block |
||
306 | 306 | * Returns the list of model field classes that that the API basically ignores |
307 | 307 | * @return array |
308 | 308 | */ |
309 | - public function fields_ignored(){ |
|
309 | + public function fields_ignored() { |
|
310 | 310 | return apply_filters( |
311 | 311 | 'FHEE__Controller_Model_Read_fields_ignored', |
312 | - array( 'EE_Foreign_Key_Field_Base', 'EE_Any_Foreign_Model_Name_Field' ) |
|
312 | + array('EE_Foreign_Key_Field_Base', 'EE_Any_Foreign_Model_Name_Field') |
|
313 | 313 | ); |
314 | 314 | } |
315 | 315 | |
@@ -318,8 +318,8 @@ discard block |
||
318 | 318 | * @param EE_Model_Field_Base |
319 | 319 | * @return boolean |
320 | 320 | */ |
321 | - public function field_is_ignored( $field_obj ){ |
|
322 | - return $this->is_subclass_of_one( $field_obj, $this->fields_ignored() ); |
|
321 | + public function field_is_ignored($field_obj) { |
|
322 | + return $this->is_subclass_of_one($field_obj, $this->fields_ignored()); |
|
323 | 323 | } |
324 | 324 | |
325 | 325 | /** |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | public function fields_that_have_rendered_format() { |
331 | 331 | return apply_filters( |
332 | 332 | 'FHEE__Controller_Model_Read__fields_raw', |
333 | - array( 'EE_Post_Content_Field', 'EE_Full_HTML_Field' ) |
|
333 | + array('EE_Post_Content_Field', 'EE_Full_HTML_Field') |
|
334 | 334 | ); |
335 | 335 | } |
336 | 336 | |
@@ -339,8 +339,8 @@ discard block |
||
339 | 339 | * @param EE_Model_Field_Base |
340 | 340 | * @return boolean |
341 | 341 | */ |
342 | - public function field_has_rendered_format( $field_obj ){ |
|
343 | - return $this->is_subclass_of_one( $field_obj, $this->fields_that_have_rendered_format() ); |
|
342 | + public function field_has_rendered_format($field_obj) { |
|
343 | + return $this->is_subclass_of_one($field_obj, $this->fields_that_have_rendered_format()); |
|
344 | 344 | } |
345 | 345 | |
346 | 346 | /** |
@@ -352,7 +352,7 @@ discard block |
||
352 | 352 | public function fields_that_have_pretty_format() { |
353 | 353 | return apply_filters( |
354 | 354 | 'FHEE__Controller_Model_Read__fields_pretty', |
355 | - array( 'EE_Enum_Integer_Field', 'EE_Enum_Text_Field', 'EE_Money_Field' ) |
|
355 | + array('EE_Enum_Integer_Field', 'EE_Enum_Text_Field', 'EE_Money_Field') |
|
356 | 356 | ); |
357 | 357 | } |
358 | 358 | |
@@ -361,8 +361,8 @@ discard block |
||
361 | 361 | * @param EE_Model_Field_Base |
362 | 362 | * @return boolean |
363 | 363 | */ |
364 | - public function field_has_pretty_format( $field_obj ){ |
|
365 | - return $this->is_subclass_of_one( $field_obj, $this->fields_that_have_pretty_format() ); |
|
364 | + public function field_has_pretty_format($field_obj) { |
|
365 | + return $this->is_subclass_of_one($field_obj, $this->fields_that_have_pretty_format()); |
|
366 | 366 | } |
367 | 367 | |
368 | 368 | /** |
@@ -379,12 +379,12 @@ discard block |
||
379 | 379 | * @param \EEM_Base $model |
380 | 380 | * @return array |
381 | 381 | */ |
382 | - public function extra_resource_properties_for_model( $model ) { |
|
382 | + public function extra_resource_properties_for_model($model) { |
|
383 | 383 | $extra_properties = array(); |
384 | - foreach( $this->resource_changes_between_requested_version_and_current() as $version => $model_classnames ) { |
|
385 | - foreach( $model_classnames as $model_classname => $properties_added_in_this_version ) { |
|
386 | - if( is_subclass_of( $model, $model_classname ) ) { |
|
387 | - $extra_properties = array_merge( $extra_properties, $properties_added_in_this_version ); |
|
384 | + foreach ($this->resource_changes_between_requested_version_and_current() as $version => $model_classnames) { |
|
385 | + foreach ($model_classnames as $model_classname => $properties_added_in_this_version) { |
|
386 | + if (is_subclass_of($model, $model_classname)) { |
|
387 | + $extra_properties = array_merge($extra_properties, $properties_added_in_this_version); |
|
388 | 388 | } |
389 | 389 | } |
390 | 390 | } |
@@ -397,11 +397,11 @@ discard block |
||
397 | 397 | * @param \EEM_Base $model |
398 | 398 | * @return \EE_Model_Relation_Base[] |
399 | 399 | */ |
400 | - public function relation_settings( \EEM_Base $model ) { |
|
400 | + public function relation_settings(\EEM_Base $model) { |
|
401 | 401 | $relations = array(); |
402 | - foreach( $model->relation_settings() as $relation_name => $relation_obj ) { |
|
403 | - if( $this->is_model_name_in_this_version( $relation_name ) ) { |
|
404 | - $relations[ $relation_name ] = $relation_obj; |
|
402 | + foreach ($model->relation_settings() as $relation_name => $relation_obj) { |
|
403 | + if ($this->is_model_name_in_this_version($relation_name)) { |
|
404 | + $relations[$relation_name] = $relation_obj; |
|
405 | 405 | } |
406 | 406 | } |
407 | 407 | //filter the results, but use the old filter name |