@@ -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; |
@@ -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,21 +1,21 @@ discard block |
||
1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
2 | 2 | EE_Registry::instance()->load_class( 'Processor_Base' ); |
3 | 3 | /** |
4 | - * |
|
5 | - * EE_Payment_Processor |
|
6 | - * |
|
7 | - * Class for handling processing of payments for transactions. |
|
8 | - * |
|
9 | - * @package Event Espresso |
|
10 | - * @subpackage core/libraries/payment_methods |
|
11 | - * @author Mike Nelson |
|
12 | - * |
|
13 | - */ |
|
4 | + * |
|
5 | + * EE_Payment_Processor |
|
6 | + * |
|
7 | + * Class for handling processing of payments for transactions. |
|
8 | + * |
|
9 | + * @package Event Espresso |
|
10 | + * @subpackage core/libraries/payment_methods |
|
11 | + * @author Mike Nelson |
|
12 | + * |
|
13 | + */ |
|
14 | 14 | class EE_Payment_Processor extends EE_Processor_Base { |
15 | 15 | /** |
16 | - * @var EE_Payment_Processor $_instance |
|
16 | + * @var EE_Payment_Processor $_instance |
|
17 | 17 | * @access private |
18 | - */ |
|
18 | + */ |
|
19 | 19 | private static $_instance = NULL; |
20 | 20 | |
21 | 21 | |
@@ -48,9 +48,8 @@ discard block |
||
48 | 48 | |
49 | 49 | |
50 | 50 | /** |
51 | - |
|
52 | 51 | * Using the selected gateway, processes the payment for that transaction, and updates the transaction appropriately. |
53 | - * Saves the payment that is generated |
|
52 | + * Saves the payment that is generated |
|
54 | 53 | * |
55 | 54 | * @param EE_Payment_Method $payment_method |
56 | 55 | * @param EE_Transaction $transaction |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
2 | -EE_Registry::instance()->load_class( 'Processor_Base' ); |
|
2 | +EE_Registry::instance()->load_class('Processor_Base'); |
|
3 | 3 | /** |
4 | 4 | * |
5 | 5 | * EE_Payment_Processor |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | */ |
28 | 28 | public static function instance() { |
29 | 29 | // check if class object is instantiated |
30 | - if ( ! self::$_instance instanceof EE_Payment_Processor ) { |
|
30 | + if ( ! self::$_instance instanceof EE_Payment_Processor) { |
|
31 | 31 | self::$_instance = new self(); |
32 | 32 | } |
33 | 33 | return self::$_instance; |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | *@return EE_Payment_Processor |
43 | 43 | */ |
44 | 44 | private function __construct() { |
45 | - do_action( 'AHEE__EE_Payment_Processor__construct' ); |
|
45 | + do_action('AHEE__EE_Payment_Processor__construct'); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | |
@@ -64,42 +64,42 @@ discard block |
||
64 | 64 | * @param string $cancel_url URL to return to if off-site payments are cancelled |
65 | 65 | * @return EE_Payment |
66 | 66 | */ |
67 | - public function process_payment( EE_Payment_Method $payment_method, EE_Transaction $transaction, $amount = NULL, $billing_form = NULL, $return_url = NULL, $method = 'CART', $by_admin = FALSE, $update_txn = TRUE, $cancel_url = '' ) { |
|
68 | - if( $amount < 0 ) { |
|
67 | + public function process_payment(EE_Payment_Method $payment_method, EE_Transaction $transaction, $amount = NULL, $billing_form = NULL, $return_url = NULL, $method = 'CART', $by_admin = FALSE, $update_txn = TRUE, $cancel_url = '') { |
|
68 | + if ($amount < 0) { |
|
69 | 69 | throw new EE_Error( |
70 | 70 | sprintf( |
71 | - __( 'Attempting to make a payment for a negative amount of %1$d for transaction %2$d. That should be a refund', 'event_espresso' ), |
|
71 | + __('Attempting to make a payment for a negative amount of %1$d for transaction %2$d. That should be a refund', 'event_espresso'), |
|
72 | 72 | $amount, |
73 | 73 | $transaction->ID() ) ); |
74 | 74 | } |
75 | 75 | // verify payment method |
76 | - $payment_method = EEM_Payment_Method::instance()->ensure_is_obj( $payment_method, TRUE ); |
|
76 | + $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method, TRUE); |
|
77 | 77 | // verify transaction |
78 | - EEM_Transaction::instance()->ensure_is_obj( $transaction ); |
|
79 | - $transaction->set_payment_method_ID( $payment_method->ID() ); |
|
78 | + EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
79 | + $transaction->set_payment_method_ID($payment_method->ID()); |
|
80 | 80 | // verify payment method type |
81 | - if ( $payment_method->type_obj() instanceof EE_PMT_Base ){ |
|
81 | + if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
82 | 82 | $payment = $payment_method->type_obj()->process_payment( |
83 | 83 | $transaction, |
84 | - min( $amount, $transaction->remaining() ),//make sure we don't overcharge |
|
84 | + min($amount, $transaction->remaining()), //make sure we don't overcharge |
|
85 | 85 | $billing_form, |
86 | 86 | $return_url, |
87 | - add_query_arg( array( 'ee_cancel_payment' => true ), $cancel_url ), |
|
87 | + add_query_arg(array('ee_cancel_payment' => true), $cancel_url), |
|
88 | 88 | $method, |
89 | 89 | $by_admin |
90 | 90 | ); |
91 | 91 | // check if payment method uses an off-site gateway |
92 | - if ( $payment_method->type_obj()->payment_occurs() != EE_PMT_Base::offsite ) { |
|
92 | + if ($payment_method->type_obj()->payment_occurs() != EE_PMT_Base::offsite) { |
|
93 | 93 | // don't process payments for off-site gateways yet because no payment has occurred yet |
94 | - $this->update_txn_based_on_payment( $transaction, $payment, $update_txn ); |
|
94 | + $this->update_txn_based_on_payment($transaction, $payment, $update_txn); |
|
95 | 95 | } |
96 | 96 | return $payment; |
97 | 97 | } else { |
98 | 98 | EE_Error::add_error( |
99 | 99 | sprintf( |
100 | - __( 'A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', 'event_espresso' ), |
|
100 | + __('A valid payment method could not be determined due to a technical issue.%sPlease try again or contact %s for assistance.', 'event_espresso'), |
|
101 | 101 | '<br/>', |
102 | - EE_Registry::instance()->CFG->organization->get_pretty( 'email' ) |
|
102 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
103 | 103 | ), __FILE__, __FUNCTION__, __LINE__ |
104 | 104 | ); |
105 | 105 | return NULL; |
@@ -115,14 +115,14 @@ discard block |
||
115 | 115 | * @throws EE_Error |
116 | 116 | * @return string |
117 | 117 | */ |
118 | - public function get_ipn_url_for_payment_method( $transaction, $payment_method ){ |
|
118 | + public function get_ipn_url_for_payment_method($transaction, $payment_method) { |
|
119 | 119 | /** @type EE_Transaction $transaction */ |
120 | - $transaction = EEM_Transaction::instance()->ensure_is_obj( $transaction ); |
|
120 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
121 | 121 | $primary_reg = $transaction->primary_registration(); |
122 | - if( ! $primary_reg instanceof EE_Registration ){ |
|
123 | - throw new EE_Error(sprintf(__("Cannot get IPN URL for transaction with ID %d because it has no primary registration", "event_espresso"),$transaction->ID())); |
|
122 | + if ( ! $primary_reg instanceof EE_Registration) { |
|
123 | + throw new EE_Error(sprintf(__("Cannot get IPN URL for transaction with ID %d because it has no primary registration", "event_espresso"), $transaction->ID())); |
|
124 | 124 | } |
125 | - $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method,true); |
|
125 | + $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method, true); |
|
126 | 126 | $url = add_query_arg( |
127 | 127 | array( |
128 | 128 | 'e_reg_url_link'=>$primary_reg->reg_url_link(), |
@@ -149,81 +149,81 @@ discard block |
||
149 | 149 | * @throws Exception |
150 | 150 | * @return EE_Payment |
151 | 151 | */ |
152 | - public function process_ipn( $_req_data, $transaction = NULL, $payment_method = NULL, $update_txn = true, $separate_IPN_request = true ){ |
|
153 | - $_req_data = $this->_remove_unusable_characters( $_req_data ); |
|
154 | - EE_Registry::instance()->load_model( 'Change_Log' ); |
|
155 | - EE_Processor_Base::set_IPN( $separate_IPN_request ); |
|
156 | - if( $transaction instanceof EE_Transaction && $payment_method instanceof EE_Payment_Method ){ |
|
157 | - $obj_for_log = EEM_Payment::instance()->get_one( array( array( 'TXN_ID' => $transaction->ID(), 'PMD_ID' => $payment_method->ID() ), 'order_by' => array( 'PAY_timestamp' => 'desc' ) ) ); |
|
158 | - }elseif( $payment_method instanceof EE_Payment ){ |
|
152 | + public function process_ipn($_req_data, $transaction = NULL, $payment_method = NULL, $update_txn = true, $separate_IPN_request = true) { |
|
153 | + $_req_data = $this->_remove_unusable_characters($_req_data); |
|
154 | + EE_Registry::instance()->load_model('Change_Log'); |
|
155 | + EE_Processor_Base::set_IPN($separate_IPN_request); |
|
156 | + if ($transaction instanceof EE_Transaction && $payment_method instanceof EE_Payment_Method) { |
|
157 | + $obj_for_log = EEM_Payment::instance()->get_one(array(array('TXN_ID' => $transaction->ID(), 'PMD_ID' => $payment_method->ID()), 'order_by' => array('PAY_timestamp' => 'desc'))); |
|
158 | + }elseif ($payment_method instanceof EE_Payment) { |
|
159 | 159 | $obj_for_log = $payment_method; |
160 | - }elseif( $transaction instanceof EE_Transaction ){ |
|
160 | + }elseif ($transaction instanceof EE_Transaction) { |
|
161 | 161 | $obj_for_log = $transaction; |
162 | - }else{ |
|
162 | + } else { |
|
163 | 163 | $obj_for_log = null; |
164 | 164 | } |
165 | 165 | $log = EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data received'=>$_req_data), $obj_for_log); |
166 | - try{ |
|
166 | + try { |
|
167 | 167 | /** |
168 | 168 | * @var EE_Payment $payment |
169 | 169 | */ |
170 | 170 | $payment = NULL; |
171 | - if($transaction && $payment_method){ |
|
171 | + if ($transaction && $payment_method) { |
|
172 | 172 | /** @type EE_Transaction $transaction */ |
173 | 173 | $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
174 | 174 | /** @type EE_Payment_Method $payment_method */ |
175 | 175 | $payment_method = EEM_Payment_Method::instance()->ensure_is_obj($payment_method); |
176 | - if ( $payment_method->type_obj() instanceof EE_PMT_Base ) { |
|
177 | - $payment = $payment_method->type_obj()->handle_ipn( $_req_data, $transaction ); |
|
176 | + if ($payment_method->type_obj() instanceof EE_PMT_Base) { |
|
177 | + $payment = $payment_method->type_obj()->handle_ipn($_req_data, $transaction); |
|
178 | 178 | $log->set_object($payment); |
179 | 179 | } else { |
180 | 180 | // not a payment |
181 | 181 | EE_Error::add_error( |
182 | 182 | sprintf( |
183 | - __( 'A valid payment method could not be determined due to a technical issue.%sPlease refresh your browser and try again or contact %s for assistance.', 'event_espresso' ), |
|
183 | + __('A valid payment method could not be determined due to a technical issue.%sPlease refresh your browser and try again or contact %s for assistance.', 'event_espresso'), |
|
184 | 184 | '<br/>', |
185 | - EE_Registry::instance()->CFG->organization->get_pretty( 'email' ) |
|
185 | + EE_Registry::instance()->CFG->organization->get_pretty('email') |
|
186 | 186 | ), |
187 | 187 | __FILE__, __FUNCTION__, __LINE__ |
188 | 188 | ); |
189 | 189 | } |
190 | - }else{ |
|
190 | + } else { |
|
191 | 191 | //that's actually pretty ok. The IPN just wasn't able |
192 | 192 | //to identify which transaction or payment method this was for |
193 | 193 | // give all active payment methods a chance to claim it |
194 | 194 | $active_pms = EEM_Payment_Method::instance()->get_all_active(); |
195 | - foreach( $active_pms as $payment_method ){ |
|
196 | - try{ |
|
197 | - $payment = $payment_method->type_obj()->handle_unclaimed_ipn( $_req_data ); |
|
195 | + foreach ($active_pms as $payment_method) { |
|
196 | + try { |
|
197 | + $payment = $payment_method->type_obj()->handle_unclaimed_ipn($_req_data); |
|
198 | 198 | EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data'=>$_req_data), $payment); |
199 | 199 | break; |
200 | - } catch( EE_Error $e ) { |
|
200 | + } catch (EE_Error $e) { |
|
201 | 201 | //that's fine- it apparently couldn't handle the IPN |
202 | 202 | } |
203 | 203 | } |
204 | 204 | |
205 | 205 | } |
206 | 206 | // EEM_Payment_Log::instance()->log("got to 7",$transaction,$payment_method); |
207 | - if( $payment instanceof EE_Payment){ |
|
207 | + if ($payment instanceof EE_Payment) { |
|
208 | 208 | $payment->save(); |
209 | 209 | // update the TXN |
210 | - $this->update_txn_based_on_payment( $transaction, $payment, $update_txn, $separate_IPN_request ); |
|
211 | - }else{ |
|
210 | + $this->update_txn_based_on_payment($transaction, $payment, $update_txn, $separate_IPN_request); |
|
211 | + } else { |
|
212 | 212 | //we couldn't find the payment for this IPN... let's try and log at least SOMETHING |
213 | - if($payment_method){ |
|
213 | + if ($payment_method) { |
|
214 | 214 | EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data'=>$_req_data), $payment_method); |
215 | - }elseif($transaction){ |
|
215 | + }elseif ($transaction) { |
|
216 | 216 | EEM_Change_Log::instance()->log(EEM_Change_Log::type_gateway, array('IPN data'=>$_req_data), $transaction); |
217 | 217 | } |
218 | 218 | } |
219 | 219 | return $payment; |
220 | 220 | |
221 | - } catch( EE_Error $e ) { |
|
221 | + } catch (EE_Error $e) { |
|
222 | 222 | do_action( |
223 | 223 | 'AHEE__log', __FILE__, __FUNCTION__, sprintf( |
224 | - __( 'Error occurred while receiving IPN. Transaction: %1$s, req data: %2$s. The error was "%3$s"', 'event_espresso' ), |
|
225 | - print_r( $transaction, TRUE ), |
|
226 | - print_r( $_req_data, TRUE ), |
|
224 | + __('Error occurred while receiving IPN. Transaction: %1$s, req data: %2$s. The error was "%3$s"', 'event_espresso'), |
|
225 | + print_r($transaction, TRUE), |
|
226 | + print_r($_req_data, TRUE), |
|
227 | 227 | $e->getMessage() |
228 | 228 | ) |
229 | 229 | ); |
@@ -237,14 +237,14 @@ discard block |
||
237 | 237 | * @param array $request_data |
238 | 238 | * @return array|string |
239 | 239 | */ |
240 | - protected function _remove_unusable_characters( $request_data ) { |
|
241 | - if( is_array( $request_data ) ) { |
|
240 | + protected function _remove_unusable_characters($request_data) { |
|
241 | + if (is_array($request_data)) { |
|
242 | 242 | $return_data = array(); |
243 | - foreach( $request_data as $key => $value ) { |
|
244 | - $return_data[ $this->_remove_unusable_characters( $key ) ] = $this->_remove_unusable_characters( $value ); |
|
243 | + foreach ($request_data as $key => $value) { |
|
244 | + $return_data[$this->_remove_unusable_characters($key)] = $this->_remove_unusable_characters($value); |
|
245 | 245 | } |
246 | - }else{ |
|
247 | - $return_data = preg_replace('/[^[:print:]]/', '', $request_data); |
|
246 | + } else { |
|
247 | + $return_data = preg_replace('/[^[:print:]]/', '', $request_data); |
|
248 | 248 | } |
249 | 249 | return $return_data; |
250 | 250 | } |
@@ -266,13 +266,13 @@ discard block |
||
266 | 266 | * @return EE_Payment |
267 | 267 | * @deprecated 4.6.24 method is no longer used. Instead it is up to client code, like SPCO, to call handle_ipn() for offsite gateways that don't receive separate IPNs |
268 | 268 | */ |
269 | - public function finalize_payment_for( $transaction, $update_txn = TRUE ){ |
|
269 | + public function finalize_payment_for($transaction, $update_txn = TRUE) { |
|
270 | 270 | /** @var $transaction EE_Transaction */ |
271 | - $transaction = EEM_Transaction::instance()->ensure_is_obj( $transaction ); |
|
271 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
272 | 272 | $last_payment_method = $transaction->payment_method(); |
273 | - if ( $last_payment_method instanceof EE_Payment_Method ) { |
|
274 | - $payment = $last_payment_method->type_obj()->finalize_payment_for( $transaction ); |
|
275 | - $this->update_txn_based_on_payment( $transaction, $payment, $update_txn ); |
|
273 | + if ($last_payment_method instanceof EE_Payment_Method) { |
|
274 | + $payment = $last_payment_method->type_obj()->finalize_payment_for($transaction); |
|
275 | + $this->update_txn_based_on_payment($transaction, $payment, $update_txn); |
|
276 | 276 | return $payment; |
277 | 277 | } else { |
278 | 278 | return NULL; |
@@ -289,10 +289,10 @@ discard block |
||
289 | 289 | * @internal param float $amount |
290 | 290 | * @return EE_Payment |
291 | 291 | */ |
292 | - public function process_refund( EE_Payment_Method $payment_method, EE_Payment $payment_to_refund, $refund_info = array() ){ |
|
293 | - if ( $payment_method instanceof EE_Payment_Method && $payment_method->type_obj()->supports_sending_refunds() ) { |
|
294 | - $payment_method->type_obj()->process_refund( $payment_to_refund, $refund_info ); |
|
295 | - $this->update_txn_based_on_payment( $payment_to_refund->transaction(), $payment_to_refund ); |
|
292 | + public function process_refund(EE_Payment_Method $payment_method, EE_Payment $payment_to_refund, $refund_info = array()) { |
|
293 | + if ($payment_method instanceof EE_Payment_Method && $payment_method->type_obj()->supports_sending_refunds()) { |
|
294 | + $payment_method->type_obj()->process_refund($payment_to_refund, $refund_info); |
|
295 | + $this->update_txn_based_on_payment($payment_to_refund->transaction(), $payment_to_refund); |
|
296 | 296 | } |
297 | 297 | return $payment_to_refund; |
298 | 298 | } |
@@ -334,12 +334,12 @@ discard block |
||
334 | 334 | * TXN is locked before updating |
335 | 335 | * @throws \EE_Error |
336 | 336 | */ |
337 | - public function update_txn_based_on_payment( $transaction, $payment, $update_txn = true, $IPN = false ){ |
|
337 | + public function update_txn_based_on_payment($transaction, $payment, $update_txn = true, $IPN = false) { |
|
338 | 338 | $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__not_successful'; |
339 | 339 | /** @type EE_Transaction $transaction */ |
340 | - $transaction = EEM_Transaction::instance()->ensure_is_obj( $transaction ); |
|
340 | + $transaction = EEM_Transaction::instance()->ensure_is_obj($transaction); |
|
341 | 341 | // can we freely update the TXN at this moment? |
342 | - if ( $IPN && $transaction->is_locked() ) { |
|
342 | + if ($IPN && $transaction->is_locked()) { |
|
343 | 343 | // don't update the transaction at this exact moment |
344 | 344 | // because the TXN is active in another request |
345 | 345 | EE_Cron_Tasks::schedule_update_transaction_with_payment( |
@@ -349,7 +349,7 @@ discard block |
||
349 | 349 | ); |
350 | 350 | } else { |
351 | 351 | // verify payment and that it has been saved |
352 | - if ( $payment instanceof EE_Payment && $payment->ID() ) { |
|
352 | + if ($payment instanceof EE_Payment && $payment->ID()) { |
|
353 | 353 | //$this->log( |
354 | 354 | // __CLASS__, __FUNCTION__, __LINE__, |
355 | 355 | // $payment->transaction(), |
@@ -358,8 +358,8 @@ discard block |
||
358 | 358 | // 'payment' => $payment, |
359 | 359 | // ) |
360 | 360 | //); |
361 | - if( $payment->payment_method() instanceof EE_Payment_Method && $payment->payment_method()->type_obj() instanceof EE_PMT_Base ){ |
|
362 | - $payment->payment_method()->type_obj()->update_txn_based_on_payment( $payment ); |
|
361 | + if ($payment->payment_method() instanceof EE_Payment_Method && $payment->payment_method()->type_obj() instanceof EE_PMT_Base) { |
|
362 | + $payment->payment_method()->type_obj()->update_txn_based_on_payment($payment); |
|
363 | 363 | //$this->log( |
364 | 364 | // __CLASS__, __FUNCTION__, __LINE__, |
365 | 365 | // $payment->transaction(), |
@@ -368,36 +368,36 @@ discard block |
||
368 | 368 | // ) |
369 | 369 | //); |
370 | 370 | // update TXN registrations with payment info |
371 | - $this->process_registration_payments( $transaction, $payment ); |
|
371 | + $this->process_registration_payments($transaction, $payment); |
|
372 | 372 | } |
373 | 373 | $do_action = $payment->just_approved() ? 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__successful' : $do_action; |
374 | 374 | } else { |
375 | 375 | // send out notifications |
376 | - add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true' ); |
|
376 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
377 | 377 | $do_action = 'AHEE__EE_Payment_Processor__update_txn_based_on_payment__no_payment_made'; |
378 | 378 | } |
379 | 379 | // if this is an IPN, then we want to know the initial TXN status prior to updating the TXN |
380 | 380 | // so that we know whether the status has changed and notifications should be triggered |
381 | - if ( $IPN ) { |
|
381 | + if ($IPN) { |
|
382 | 382 | /** @type EE_Transaction_Processor $transaction_processor */ |
383 | - $transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' ); |
|
384 | - $transaction_processor->set_old_txn_status( $transaction->status_ID() ); |
|
383 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
384 | + $transaction_processor->set_old_txn_status($transaction->status_ID()); |
|
385 | 385 | } |
386 | - if ( $payment->status() !== EEM_Payment::status_id_failed ) { |
|
386 | + if ($payment->status() !== EEM_Payment::status_id_failed) { |
|
387 | 387 | /** @type EE_Transaction_Payments $transaction_payments */ |
388 | - $transaction_payments = EE_Registry::instance()->load_class( 'Transaction_Payments' ); |
|
388 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
389 | 389 | // set new value for total paid |
390 | - $transaction_payments->calculate_total_payments_and_update_status( $transaction ); |
|
390 | + $transaction_payments->calculate_total_payments_and_update_status($transaction); |
|
391 | 391 | // call EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment() ??? |
392 | - if ( $update_txn ) { |
|
393 | - $this->_post_payment_processing( $transaction, $payment, $IPN ); |
|
392 | + if ($update_txn) { |
|
393 | + $this->_post_payment_processing($transaction, $payment, $IPN); |
|
394 | 394 | } |
395 | 395 | } |
396 | 396 | // granular hook for others to use. |
397 | - do_action( $do_action, $transaction, $payment ); |
|
398 | - do_action( 'AHEE_log', __CLASS__, __FUNCTION__, $do_action, '$do_action' ); |
|
397 | + do_action($do_action, $transaction, $payment); |
|
398 | + do_action('AHEE_log', __CLASS__, __FUNCTION__, $do_action, '$do_action'); |
|
399 | 399 | //global hook for others to use. |
400 | - do_action( 'AHEE__EE_Payment_Processor__update_txn_based_on_payment', $transaction, $payment ); |
|
400 | + do_action('AHEE__EE_Payment_Processor__update_txn_based_on_payment', $transaction, $payment); |
|
401 | 401 | } |
402 | 402 | } |
403 | 403 | |
@@ -411,25 +411,25 @@ discard block |
||
411 | 411 | * @param EE_Registration[] $registrations |
412 | 412 | * @throws \EE_Error |
413 | 413 | */ |
414 | - public function process_registration_payments( EE_Transaction $transaction, EE_Payment $payment, $registrations = array() ) { |
|
414 | + public function process_registration_payments(EE_Transaction $transaction, EE_Payment $payment, $registrations = array()) { |
|
415 | 415 | // only process if payment was successful |
416 | - if ( $payment->status() !== EEM_Payment::status_id_approved ) { |
|
416 | + if ($payment->status() !== EEM_Payment::status_id_approved) { |
|
417 | 417 | return; |
418 | 418 | } |
419 | 419 | //EEM_Registration::instance()->show_next_x_db_queries(); |
420 | - if ( empty( $registrations )) { |
|
420 | + if (empty($registrations)) { |
|
421 | 421 | // find registrations with monies owing that can receive a payment |
422 | - $registrations = $transaction->registrations( array( |
|
422 | + $registrations = $transaction->registrations(array( |
|
423 | 423 | array( |
424 | 424 | // only these reg statuses can receive payments |
425 | - 'STS_ID' => array( 'IN', EEM_Registration::reg_statuses_that_allow_payment() ), |
|
426 | - 'REG_final_price' => array( '!=', 0 ), |
|
427 | - 'REG_final_price*' => array( '!=', 'REG_paid', true ), |
|
425 | + 'STS_ID' => array('IN', EEM_Registration::reg_statuses_that_allow_payment()), |
|
426 | + 'REG_final_price' => array('!=', 0), |
|
427 | + 'REG_final_price*' => array('!=', 'REG_paid', true), |
|
428 | 428 | ) |
429 | - ) ); |
|
429 | + )); |
|
430 | 430 | } |
431 | 431 | // still nothing ??!?? |
432 | - if ( empty( $registrations )) { |
|
432 | + if (empty($registrations)) { |
|
433 | 433 | return; |
434 | 434 | } |
435 | 435 | // todo: break out the following logic into a separate strategy class |
@@ -441,28 +441,28 @@ discard block |
||
441 | 441 | |
442 | 442 | $refund = $payment->is_a_refund(); |
443 | 443 | // how much is available to apply to registrations? |
444 | - $available_payment_amount = abs( $payment->amount() ); |
|
445 | - foreach ( $registrations as $registration ) { |
|
446 | - if ( $registration instanceof EE_Registration ) { |
|
444 | + $available_payment_amount = abs($payment->amount()); |
|
445 | + foreach ($registrations as $registration) { |
|
446 | + if ($registration instanceof EE_Registration) { |
|
447 | 447 | // nothing left? |
448 | - if ( $available_payment_amount <= 0 ) { |
|
448 | + if ($available_payment_amount <= 0) { |
|
449 | 449 | break; |
450 | 450 | } |
451 | - if ( $refund ) { |
|
452 | - $available_payment_amount = $this->process_registration_refund( $registration, $payment, $available_payment_amount ); |
|
451 | + if ($refund) { |
|
452 | + $available_payment_amount = $this->process_registration_refund($registration, $payment, $available_payment_amount); |
|
453 | 453 | } else { |
454 | - $available_payment_amount = $this->process_registration_payment( $registration, $payment, $available_payment_amount ); |
|
454 | + $available_payment_amount = $this->process_registration_payment($registration, $payment, $available_payment_amount); |
|
455 | 455 | } |
456 | 456 | } |
457 | 457 | } |
458 | - if ( $available_payment_amount > 0 && apply_filters( 'FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', false ) ) { |
|
458 | + if ($available_payment_amount > 0 && apply_filters('FHEE__EE_Payment_Processor__process_registration_payments__display_notifications', false)) { |
|
459 | 459 | EE_Error::add_attention( |
460 | 460 | sprintf( |
461 | - __( 'A remainder of %1$s exists after applying this payment to Registration(s) %2$s.%3$sPlease verify that the original payment amount of %4$s is correct. If so, you should edit this payment and select at least one additional registration in the "Registrations to Apply Payment to" section, so that the remainder of this payment can be applied to the additional registration(s).', 'event_espresso' ), |
|
462 | - EEH_Template::format_currency( $available_payment_amount ), |
|
463 | - implode( ', ', array_keys( $registrations ) ), |
|
461 | + __('A remainder of %1$s exists after applying this payment to Registration(s) %2$s.%3$sPlease verify that the original payment amount of %4$s is correct. If so, you should edit this payment and select at least one additional registration in the "Registrations to Apply Payment to" section, so that the remainder of this payment can be applied to the additional registration(s).', 'event_espresso'), |
|
462 | + EEH_Template::format_currency($available_payment_amount), |
|
463 | + implode(', ', array_keys($registrations)), |
|
464 | 464 | '<br/>', |
465 | - EEH_Template::format_currency( $payment->amount() ) |
|
465 | + EEH_Template::format_currency($payment->amount()) |
|
466 | 466 | ), |
467 | 467 | __FILE__, __FUNCTION__, __LINE__ |
468 | 468 | ); |
@@ -479,17 +479,17 @@ discard block |
||
479 | 479 | * @param float $available_payment_amount |
480 | 480 | * @return float |
481 | 481 | */ |
482 | - public function process_registration_payment( EE_Registration $registration, EE_Payment $payment, $available_payment_amount = 0.00 ) { |
|
482 | + public function process_registration_payment(EE_Registration $registration, EE_Payment $payment, $available_payment_amount = 0.00) { |
|
483 | 483 | $owing = $registration->final_price() - $registration->paid(); |
484 | - if ( $owing > 0 ) { |
|
484 | + if ($owing > 0) { |
|
485 | 485 | // don't allow payment amount to exceed the available payment amount, OR the amount owing |
486 | - $payment_amount = min( $available_payment_amount, $owing ); |
|
486 | + $payment_amount = min($available_payment_amount, $owing); |
|
487 | 487 | // update $available_payment_amount |
488 | 488 | $available_payment_amount = $available_payment_amount - $payment_amount; |
489 | 489 | //calculate and set new REG_paid |
490 | - $registration->set_paid( $registration->paid() + $payment_amount ); |
|
490 | + $registration->set_paid($registration->paid() + $payment_amount); |
|
491 | 491 | // now save it |
492 | - $this->_apply_registration_payment( $registration, $payment, $payment_amount ); |
|
492 | + $this->_apply_registration_payment($registration, $payment, $payment_amount); |
|
493 | 493 | } |
494 | 494 | return $available_payment_amount; |
495 | 495 | } |
@@ -504,19 +504,19 @@ discard block |
||
504 | 504 | * @param float $payment_amount |
505 | 505 | * @return float |
506 | 506 | */ |
507 | - protected function _apply_registration_payment( EE_Registration $registration, EE_Payment $payment, $payment_amount = 0.00 ) { |
|
507 | + protected function _apply_registration_payment(EE_Registration $registration, EE_Payment $payment, $payment_amount = 0.00) { |
|
508 | 508 | // find any existing reg payment records for this registration and payment |
509 | 509 | $existing_reg_payment = EEM_Registration_Payment::instance()->get_one( |
510 | - array( array( 'REG_ID' => $registration->ID(), 'PAY_ID' => $payment->ID() ) ) |
|
510 | + array(array('REG_ID' => $registration->ID(), 'PAY_ID' => $payment->ID())) |
|
511 | 511 | ); |
512 | 512 | // if existing registration payment exists |
513 | - if ( $existing_reg_payment instanceof EE_Registration_Payment ) { |
|
513 | + if ($existing_reg_payment instanceof EE_Registration_Payment) { |
|
514 | 514 | // then update that record |
515 | - $existing_reg_payment->set_amount( $payment_amount ); |
|
515 | + $existing_reg_payment->set_amount($payment_amount); |
|
516 | 516 | $existing_reg_payment->save(); |
517 | 517 | } else { |
518 | 518 | // or add new relation between registration and payment and set amount |
519 | - $registration->_add_relation_to( $payment, 'Payment', array( 'RPY_amount' => $payment_amount ) ); |
|
519 | + $registration->_add_relation_to($payment, 'Payment', array('RPY_amount' => $payment_amount)); |
|
520 | 520 | // make it stick |
521 | 521 | $registration->save(); |
522 | 522 | } |
@@ -532,21 +532,21 @@ discard block |
||
532 | 532 | * @param float $available_refund_amount - IMPORTANT !!! SEND AVAILABLE REFUND AMOUNT AS A POSITIVE NUMBER |
533 | 533 | * @return float |
534 | 534 | */ |
535 | - public function process_registration_refund( EE_Registration $registration, EE_Payment $payment, $available_refund_amount = 0.00 ) { |
|
535 | + public function process_registration_refund(EE_Registration $registration, EE_Payment $payment, $available_refund_amount = 0.00) { |
|
536 | 536 | //EEH_Debug_Tools::printr( $payment->amount(), '$payment->amount()', __FILE__, __LINE__ ); |
537 | - if ( $registration->paid() > 0 ) { |
|
537 | + if ($registration->paid() > 0) { |
|
538 | 538 | // ensure $available_refund_amount is NOT negative |
539 | - $available_refund_amount = abs( $available_refund_amount ); |
|
539 | + $available_refund_amount = abs($available_refund_amount); |
|
540 | 540 | // don't allow refund amount to exceed the available payment amount, OR the amount paid |
541 | - $refund_amount = min( $available_refund_amount, $registration->paid() ); |
|
541 | + $refund_amount = min($available_refund_amount, $registration->paid()); |
|
542 | 542 | // update $available_payment_amount |
543 | 543 | $available_refund_amount = $available_refund_amount - $refund_amount; |
544 | 544 | //calculate and set new REG_paid |
545 | - $registration->set_paid( $registration->paid() - $refund_amount ); |
|
545 | + $registration->set_paid($registration->paid() - $refund_amount); |
|
546 | 546 | // convert payment amount back to a negative value for storage in the db |
547 | - $refund_amount = abs( $refund_amount ) * -1; |
|
547 | + $refund_amount = abs($refund_amount) * -1; |
|
548 | 548 | // now save it |
549 | - $this->_apply_registration_payment( $registration, $payment, $refund_amount ); |
|
549 | + $this->_apply_registration_payment($registration, $payment, $refund_amount); |
|
550 | 550 | } |
551 | 551 | return $available_refund_amount; |
552 | 552 | } |
@@ -564,12 +564,12 @@ discard block |
||
564 | 564 | * @param EE_Payment $payment |
565 | 565 | * @param bool $IPN |
566 | 566 | */ |
567 | - protected function _post_payment_processing( EE_Transaction $transaction, EE_Payment $payment, $IPN = false ) { |
|
567 | + protected function _post_payment_processing(EE_Transaction $transaction, EE_Payment $payment, $IPN = false) { |
|
568 | 568 | |
569 | 569 | /** @type EE_Transaction_Processor $transaction_processor */ |
570 | - $transaction_processor = EE_Registry::instance()->load_class( 'Transaction_Processor' ); |
|
570 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
571 | 571 | // is the Payment Options Reg Step completed ? |
572 | - $payment_options_step_completed = $transaction_processor->reg_step_completed( $transaction, 'payment_options' ); |
|
572 | + $payment_options_step_completed = $transaction_processor->reg_step_completed($transaction, 'payment_options'); |
|
573 | 573 | // DEBUG LOG |
574 | 574 | //$this->log( |
575 | 575 | // __CLASS__, __FUNCTION__, __LINE__, |
@@ -582,14 +582,14 @@ discard block |
||
582 | 582 | // if the Payment Options Reg Step is completed... |
583 | 583 | $revisit = $payment_options_step_completed === true ? true : false; |
584 | 584 | // then this is kinda sorta a revisit with regards to payments at least |
585 | - $transaction_processor->set_revisit( $revisit ); |
|
585 | + $transaction_processor->set_revisit($revisit); |
|
586 | 586 | // if this is an IPN, let's consider the Payment Options Reg Step completed if not already |
587 | 587 | if ( |
588 | 588 | $IPN && |
589 | 589 | $payment_options_step_completed !== true && |
590 | - ( $payment->is_approved() || $payment->is_pending() ) |
|
590 | + ($payment->is_approved() || $payment->is_pending()) |
|
591 | 591 | ) { |
592 | - $payment_options_step_completed = $transaction_processor->set_reg_step_completed( $transaction, 'payment_options' ); |
|
592 | + $payment_options_step_completed = $transaction_processor->set_reg_step_completed($transaction, 'payment_options'); |
|
593 | 593 | } |
594 | 594 | // DEBUG LOG |
595 | 595 | //$this->log( |
@@ -601,11 +601,11 @@ discard block |
||
601 | 601 | // ) |
602 | 602 | //); |
603 | 603 | /** @type EE_Transaction_Payments $transaction_payments */ |
604 | - $transaction_payments = EE_Registry::instance()->load_class( 'Transaction_Payments' ); |
|
604 | + $transaction_payments = EE_Registry::instance()->load_class('Transaction_Payments'); |
|
605 | 605 | // maybe update status, but don't save transaction just yet |
606 | - $transaction_payments->update_transaction_status_based_on_total_paid( $transaction, false ); |
|
606 | + $transaction_payments->update_transaction_status_based_on_total_paid($transaction, false); |
|
607 | 607 | // check if 'finalize_registration' step has been completed... |
608 | - $finalized = $transaction_processor->reg_step_completed( $transaction, 'finalize_registration' ); |
|
608 | + $finalized = $transaction_processor->reg_step_completed($transaction, 'finalize_registration'); |
|
609 | 609 | // DEBUG LOG |
610 | 610 | //$this->log( |
611 | 611 | // __CLASS__, __FUNCTION__, __LINE__, |
@@ -616,9 +616,9 @@ discard block |
||
616 | 616 | // ) |
617 | 617 | //); |
618 | 618 | // if this is an IPN and the final step has not been initiated |
619 | - if ( $IPN && $payment_options_step_completed && $finalized === false ) { |
|
619 | + if ($IPN && $payment_options_step_completed && $finalized === false) { |
|
620 | 620 | // and if it hasn't already been set as being started... |
621 | - $finalized = $transaction_processor->set_reg_step_initiated( $transaction, 'finalize_registration' ); |
|
621 | + $finalized = $transaction_processor->set_reg_step_initiated($transaction, 'finalize_registration'); |
|
622 | 622 | // DEBUG LOG |
623 | 623 | //$this->log( |
624 | 624 | // __CLASS__, __FUNCTION__, __LINE__, |
@@ -631,13 +631,13 @@ discard block |
||
631 | 631 | } |
632 | 632 | $transaction->save(); |
633 | 633 | // because the above will return false if the final step was not fully completed, we need to check again... |
634 | - if ( $IPN && $finalized !== false ) { |
|
634 | + if ($IPN && $finalized !== false) { |
|
635 | 635 | // and if we are all good to go, then send out notifications |
636 | - add_filter( 'FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true' ); |
|
636 | + add_filter('FHEE__EED_Messages___maybe_registration__deliver_notifications', '__return_true'); |
|
637 | 637 | // DEBUG LOG |
638 | 638 | //$this->log( __CLASS__, __FUNCTION__, __LINE__, $transaction ); |
639 | 639 | //ok, now process the transaction according to the payment |
640 | - $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( $transaction, $payment ); |
|
640 | + $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment($transaction, $payment); |
|
641 | 641 | } |
642 | 642 | // DEBUG LOG |
643 | 643 | //$this->log( |
@@ -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 |