@@ -15,7 +15,7 @@ |
||
15 | 15 | */ |
16 | 16 | public function __construct($options = array()) |
17 | 17 | { |
18 | - $select_options = array(true => esc_html__("Yes", "event_espresso"),false => esc_html__("No", "event_espresso")); |
|
18 | + $select_options = array(true => esc_html__("Yes", "event_espresso"), false => esc_html__("No", "event_espresso")); |
|
19 | 19 | |
20 | 20 | parent::__construct($select_options, $options); |
21 | 21 | } |
@@ -9,13 +9,13 @@ |
||
9 | 9 | */ |
10 | 10 | class EE_Yes_No_Input extends EE_Select_Input |
11 | 11 | { |
12 | - /** |
|
13 | - * @param array $options |
|
14 | - */ |
|
15 | - public function __construct($options = array()) |
|
16 | - { |
|
17 | - $select_options = array(true => esc_html__("Yes", "event_espresso"),false => esc_html__("No", "event_espresso")); |
|
12 | + /** |
|
13 | + * @param array $options |
|
14 | + */ |
|
15 | + public function __construct($options = array()) |
|
16 | + { |
|
17 | + $select_options = array(true => esc_html__("Yes", "event_espresso"),false => esc_html__("No", "event_espresso")); |
|
18 | 18 | |
19 | - parent::__construct($select_options, $options); |
|
20 | - } |
|
19 | + parent::__construct($select_options, $options); |
|
20 | + } |
|
21 | 21 | } |
@@ -14,17 +14,17 @@ |
||
14 | 14 | */ |
15 | 15 | class EE_Phone_Input extends EE_Text_Input |
16 | 16 | { |
17 | - /** |
|
18 | - * @param array $options |
|
19 | - */ |
|
20 | - public function __construct($options = array()) |
|
21 | - { |
|
22 | - $this->_add_validation_strategy( |
|
23 | - new EE_Text_Validation_Strategy( |
|
24 | - esc_html__('Please enter a valid phone number. Eg 123-456-7890 or 1234567890', 'event_espresso'), |
|
25 | - '~^(([\d]{10})|(^[\d]{3}-[\d]{3}-[\d]{4}))$~' |
|
26 | - ) |
|
27 | - ); |
|
28 | - parent::__construct($options); |
|
29 | - } |
|
17 | + /** |
|
18 | + * @param array $options |
|
19 | + */ |
|
20 | + public function __construct($options = array()) |
|
21 | + { |
|
22 | + $this->_add_validation_strategy( |
|
23 | + new EE_Text_Validation_Strategy( |
|
24 | + esc_html__('Please enter a valid phone number. Eg 123-456-7890 or 1234567890', 'event_espresso'), |
|
25 | + '~^(([\d]{10})|(^[\d]{3}-[\d]{3}-[\d]{4}))$~' |
|
26 | + ) |
|
27 | + ); |
|
28 | + parent::__construct($options); |
|
29 | + } |
|
30 | 30 | } |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | ); |
75 | 75 | // make sure limit and caps are always set |
76 | 76 | $query_params = array_merge( |
77 | - array( 'limit' => 10, 'caps' => EEM_Base::caps_read_admin ), |
|
77 | + array('limit' => 10, 'caps' => EEM_Base::caps_read_admin), |
|
78 | 78 | $query_params |
79 | 79 | ); |
80 | 80 | $this->_value_field_name = EEH_Array::is_set( |
@@ -155,12 +155,12 @@ discard block |
||
155 | 155 | $values_for_options = (array) $value; |
156 | 156 | $value_field = $this->_get_model()->field_settings_for($this->_value_field_name); |
157 | 157 | $display_field = $this->_get_model()->field_settings_for($this->_display_field_name); |
158 | - $this->_extra_select_columns[] = $value_field->get_qualified_column() . ' AS ' . $this->_value_field_name; |
|
159 | - $this->_extra_select_columns[] = $display_field->get_qualified_column() . ' AS ' . $this->_display_field_name; |
|
158 | + $this->_extra_select_columns[] = $value_field->get_qualified_column().' AS '.$this->_value_field_name; |
|
159 | + $this->_extra_select_columns[] = $display_field->get_qualified_column().' AS '.$this->_display_field_name; |
|
160 | 160 | $display_values = $this->_get_model()->get_all_wpdb_results( |
161 | 161 | array( |
162 | 162 | array( |
163 | - $this->_value_field_name => array( 'IN', $values_for_options ) |
|
163 | + $this->_value_field_name => array('IN', $values_for_options) |
|
164 | 164 | ) |
165 | 165 | ), |
166 | 166 | ARRAY_A, |
@@ -170,9 +170,9 @@ discard block |
||
170 | 170 | if (is_array($select_options)) { |
171 | 171 | foreach ($display_values as $db_rows) { |
172 | 172 | $db_rows = (array) $db_rows; |
173 | - $select_options[ $db_rows[ $this->_value_field_name ] ] = apply_filters( |
|
173 | + $select_options[$db_rows[$this->_value_field_name]] = apply_filters( |
|
174 | 174 | 'FHEE__EE_Select_Ajax_Model_Rest_Input___set_raw_value__select_option_value', |
175 | - $db_rows[ $this->_display_field_name ], |
|
175 | + $db_rows[$this->_display_field_name], |
|
176 | 176 | $db_rows |
177 | 177 | ); |
178 | 178 | } |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | */ |
189 | 189 | protected function _get_model() |
190 | 190 | { |
191 | - if (! EE_Registry::instance()->is_model_name($this->_model_name)) { |
|
191 | + if ( ! EE_Registry::instance()->is_model_name($this->_model_name)) { |
|
192 | 192 | throw new EE_Error( |
193 | 193 | sprintf( |
194 | 194 | esc_html__( |
@@ -16,189 +16,189 @@ |
||
16 | 16 | */ |
17 | 17 | class EE_Select_Ajax_Model_Rest_Input extends EE_Form_Input_With_Options_Base |
18 | 18 | { |
19 | - /** |
|
20 | - * @var string $_model_name |
|
21 | - */ |
|
22 | - protected $_model_name; |
|
19 | + /** |
|
20 | + * @var string $_model_name |
|
21 | + */ |
|
22 | + protected $_model_name; |
|
23 | 23 | |
24 | - /** |
|
25 | - * @var string $_display_field_name |
|
26 | - */ |
|
27 | - protected $_display_field_name; |
|
24 | + /** |
|
25 | + * @var string $_display_field_name |
|
26 | + */ |
|
27 | + protected $_display_field_name; |
|
28 | 28 | |
29 | - /** |
|
30 | - * @var string $_value_field_name |
|
31 | - */ |
|
32 | - protected $_value_field_name; |
|
29 | + /** |
|
30 | + * @var string $_value_field_name |
|
31 | + */ |
|
32 | + protected $_value_field_name; |
|
33 | 33 | |
34 | - /** |
|
35 | - * @var array $_extra_select_columns |
|
36 | - */ |
|
37 | - protected $_extra_select_columns = array(); |
|
34 | + /** |
|
35 | + * @var array $_extra_select_columns |
|
36 | + */ |
|
37 | + protected $_extra_select_columns = array(); |
|
38 | 38 | |
39 | 39 | |
40 | - /** |
|
41 | - * @param array $input_settings { |
|
42 | - * @type string $model_name the name of model to be used for searching, both via the REST API and server-side model queries |
|
43 | - * @type array $query_params default query parameters which will apply to both REST API queries and server-side queries. This should be |
|
44 | - * in the exact format that will be used for server-side model usage (eg use index 0 for where conditions, not |
|
45 | - * the string "where") |
|
46 | - * @type string $value_field_name the name of the model field on this model to |
|
47 | - * be used for the HTML select's option's values |
|
48 | - * @type string $display_field_name the name of the model field on this model |
|
49 | - * to be used for the HTML select's option's display text |
|
50 | - * @type array $select2_args arguments to be passed directly into the select2's JS constructor |
|
51 | - * } |
|
52 | - * And the arguments accepted by EE_Form_Input_With_Options_Base |
|
53 | - * } |
|
54 | - * @throws EE_Error |
|
55 | - * @throws InvalidArgumentException |
|
56 | - * @throws InvalidDataTypeException |
|
57 | - * @throws InvalidInterfaceException |
|
58 | - */ |
|
59 | - public function __construct($input_settings = array()) |
|
60 | - { |
|
61 | - // needed input settings: |
|
62 | - // select2_args |
|
63 | - $this->_model_name = EEH_Array::is_set( |
|
64 | - $input_settings, |
|
65 | - 'model_name', |
|
66 | - null |
|
67 | - ); |
|
68 | - $model = $this->_get_model(); |
|
69 | - $query_params = EEH_Array::is_set( |
|
70 | - $input_settings, |
|
71 | - 'query_params', |
|
72 | - array() |
|
73 | - ); |
|
74 | - // make sure limit and caps are always set |
|
75 | - $query_params = array_merge( |
|
76 | - array( 'limit' => 10, 'caps' => EEM_Base::caps_read_admin ), |
|
77 | - $query_params |
|
78 | - ); |
|
79 | - $this->_value_field_name = EEH_Array::is_set( |
|
80 | - $input_settings, |
|
81 | - 'value_field_name', |
|
82 | - $model->primary_key_name() |
|
83 | - ); |
|
84 | - $this->_display_field_name = EEH_Array::is_set( |
|
85 | - $input_settings, |
|
86 | - 'display_field_name', |
|
87 | - $model->get_a_field_of_type('EE_Text_Field_Base')->get_name() |
|
88 | - ); |
|
89 | - $this->_extra_select_columns = EEH_Array::is_set( |
|
90 | - $input_settings, |
|
91 | - 'extra_select_columns', |
|
92 | - array() |
|
93 | - ); |
|
94 | - $this->_add_validation_strategy( |
|
95 | - new EE_Model_Matching_Query_Validation_Strategy( |
|
96 | - '', |
|
97 | - $this->_model_name, |
|
98 | - $query_params, |
|
99 | - $this->_value_field_name |
|
100 | - ) |
|
101 | - ); |
|
102 | - // get resource endpoint |
|
103 | - $rest_controller = LoaderFactory::getLoader()->getNew( |
|
104 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read' |
|
105 | - ); |
|
106 | - $rest_controller->setRequestedVersion(EED_Core_Rest_Api::latest_rest_api_version()); |
|
107 | - $default_select2_args = array( |
|
108 | - 'ajax' => array( |
|
109 | - 'url' => $rest_controller->getVersionedLinkTo( |
|
110 | - EEH_Inflector::pluralize_and_lower($this->_model_name) |
|
111 | - ), |
|
112 | - 'dataType' => 'json', |
|
113 | - 'delay' => '250', |
|
114 | - 'data_interface' => 'EE_Select2_REST_API_Interface', |
|
115 | - 'data_interface_args' => array( |
|
116 | - 'default_query_params' => (object) ModelDataTranslator::prepareQueryParamsForRestApi( |
|
117 | - $query_params, |
|
118 | - $model |
|
119 | - ), |
|
120 | - 'display_field' => $this->_display_field_name, |
|
121 | - 'value_field' => $this->_value_field_name, |
|
122 | - 'nonce' => wp_create_nonce('wp_rest'), |
|
123 | - 'locale' => str_replace('_', '-', strtolower(get_locale())) |
|
124 | - ), |
|
125 | - ), |
|
126 | - 'cache' => true, |
|
127 | - 'width' => 'resolve' |
|
128 | - ); |
|
129 | - $select2_args = array_replace_recursive( |
|
130 | - $default_select2_args, |
|
131 | - (array) EEH_Array::is_set($input_settings, 'select2_args', array()) |
|
132 | - ); |
|
133 | - $this->set_display_strategy(new EE_Select2_Display_Strategy($select2_args)); |
|
134 | - parent::__construct(array(), $input_settings); |
|
135 | - } |
|
40 | + /** |
|
41 | + * @param array $input_settings { |
|
42 | + * @type string $model_name the name of model to be used for searching, both via the REST API and server-side model queries |
|
43 | + * @type array $query_params default query parameters which will apply to both REST API queries and server-side queries. This should be |
|
44 | + * in the exact format that will be used for server-side model usage (eg use index 0 for where conditions, not |
|
45 | + * the string "where") |
|
46 | + * @type string $value_field_name the name of the model field on this model to |
|
47 | + * be used for the HTML select's option's values |
|
48 | + * @type string $display_field_name the name of the model field on this model |
|
49 | + * to be used for the HTML select's option's display text |
|
50 | + * @type array $select2_args arguments to be passed directly into the select2's JS constructor |
|
51 | + * } |
|
52 | + * And the arguments accepted by EE_Form_Input_With_Options_Base |
|
53 | + * } |
|
54 | + * @throws EE_Error |
|
55 | + * @throws InvalidArgumentException |
|
56 | + * @throws InvalidDataTypeException |
|
57 | + * @throws InvalidInterfaceException |
|
58 | + */ |
|
59 | + public function __construct($input_settings = array()) |
|
60 | + { |
|
61 | + // needed input settings: |
|
62 | + // select2_args |
|
63 | + $this->_model_name = EEH_Array::is_set( |
|
64 | + $input_settings, |
|
65 | + 'model_name', |
|
66 | + null |
|
67 | + ); |
|
68 | + $model = $this->_get_model(); |
|
69 | + $query_params = EEH_Array::is_set( |
|
70 | + $input_settings, |
|
71 | + 'query_params', |
|
72 | + array() |
|
73 | + ); |
|
74 | + // make sure limit and caps are always set |
|
75 | + $query_params = array_merge( |
|
76 | + array( 'limit' => 10, 'caps' => EEM_Base::caps_read_admin ), |
|
77 | + $query_params |
|
78 | + ); |
|
79 | + $this->_value_field_name = EEH_Array::is_set( |
|
80 | + $input_settings, |
|
81 | + 'value_field_name', |
|
82 | + $model->primary_key_name() |
|
83 | + ); |
|
84 | + $this->_display_field_name = EEH_Array::is_set( |
|
85 | + $input_settings, |
|
86 | + 'display_field_name', |
|
87 | + $model->get_a_field_of_type('EE_Text_Field_Base')->get_name() |
|
88 | + ); |
|
89 | + $this->_extra_select_columns = EEH_Array::is_set( |
|
90 | + $input_settings, |
|
91 | + 'extra_select_columns', |
|
92 | + array() |
|
93 | + ); |
|
94 | + $this->_add_validation_strategy( |
|
95 | + new EE_Model_Matching_Query_Validation_Strategy( |
|
96 | + '', |
|
97 | + $this->_model_name, |
|
98 | + $query_params, |
|
99 | + $this->_value_field_name |
|
100 | + ) |
|
101 | + ); |
|
102 | + // get resource endpoint |
|
103 | + $rest_controller = LoaderFactory::getLoader()->getNew( |
|
104 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read' |
|
105 | + ); |
|
106 | + $rest_controller->setRequestedVersion(EED_Core_Rest_Api::latest_rest_api_version()); |
|
107 | + $default_select2_args = array( |
|
108 | + 'ajax' => array( |
|
109 | + 'url' => $rest_controller->getVersionedLinkTo( |
|
110 | + EEH_Inflector::pluralize_and_lower($this->_model_name) |
|
111 | + ), |
|
112 | + 'dataType' => 'json', |
|
113 | + 'delay' => '250', |
|
114 | + 'data_interface' => 'EE_Select2_REST_API_Interface', |
|
115 | + 'data_interface_args' => array( |
|
116 | + 'default_query_params' => (object) ModelDataTranslator::prepareQueryParamsForRestApi( |
|
117 | + $query_params, |
|
118 | + $model |
|
119 | + ), |
|
120 | + 'display_field' => $this->_display_field_name, |
|
121 | + 'value_field' => $this->_value_field_name, |
|
122 | + 'nonce' => wp_create_nonce('wp_rest'), |
|
123 | + 'locale' => str_replace('_', '-', strtolower(get_locale())) |
|
124 | + ), |
|
125 | + ), |
|
126 | + 'cache' => true, |
|
127 | + 'width' => 'resolve' |
|
128 | + ); |
|
129 | + $select2_args = array_replace_recursive( |
|
130 | + $default_select2_args, |
|
131 | + (array) EEH_Array::is_set($input_settings, 'select2_args', array()) |
|
132 | + ); |
|
133 | + $this->set_display_strategy(new EE_Select2_Display_Strategy($select2_args)); |
|
134 | + parent::__construct(array(), $input_settings); |
|
135 | + } |
|
136 | 136 | |
137 | 137 | |
138 | 138 | |
139 | - /** |
|
140 | - * Before setting the raw value (usually because we're setting the default, |
|
141 | - * or we've received a form submission and this might be re-displayed to the user), |
|
142 | - * sets the options so that the current selections appear on initial display. |
|
143 | - * |
|
144 | - * Note: because this input uses EE_Model_Matching_Query_Validation_Strategy |
|
145 | - * for validation, this input's options only affect DISPLAY and NOT validation, |
|
146 | - * which is why its ok to just assume the provided $value to be in the list of acceptable values |
|
147 | - * |
|
148 | - * @param mixed $value |
|
149 | - * @return void |
|
150 | - * @throws \EE_Error |
|
151 | - */ |
|
152 | - public function _set_raw_value($value) |
|
153 | - { |
|
154 | - $values_for_options = (array) $value; |
|
155 | - $value_field = $this->_get_model()->field_settings_for($this->_value_field_name); |
|
156 | - $display_field = $this->_get_model()->field_settings_for($this->_display_field_name); |
|
157 | - $this->_extra_select_columns[] = $value_field->get_qualified_column() . ' AS ' . $this->_value_field_name; |
|
158 | - $this->_extra_select_columns[] = $display_field->get_qualified_column() . ' AS ' . $this->_display_field_name; |
|
159 | - $display_values = $this->_get_model()->get_all_wpdb_results( |
|
160 | - array( |
|
161 | - array( |
|
162 | - $this->_value_field_name => array( 'IN', $values_for_options ) |
|
163 | - ) |
|
164 | - ), |
|
165 | - ARRAY_A, |
|
166 | - implode(',', $this->_extra_select_columns) |
|
167 | - ); |
|
168 | - $select_options = array(); |
|
169 | - if (is_array($select_options)) { |
|
170 | - foreach ($display_values as $db_rows) { |
|
171 | - $db_rows = (array) $db_rows; |
|
172 | - $select_options[ $db_rows[ $this->_value_field_name ] ] = apply_filters( |
|
173 | - 'FHEE__EE_Select_Ajax_Model_Rest_Input___set_raw_value__select_option_value', |
|
174 | - $db_rows[ $this->_display_field_name ], |
|
175 | - $db_rows |
|
176 | - ); |
|
177 | - } |
|
178 | - } |
|
179 | - $this->set_select_options($select_options); |
|
180 | - parent::_set_raw_value($value); |
|
181 | - } |
|
139 | + /** |
|
140 | + * Before setting the raw value (usually because we're setting the default, |
|
141 | + * or we've received a form submission and this might be re-displayed to the user), |
|
142 | + * sets the options so that the current selections appear on initial display. |
|
143 | + * |
|
144 | + * Note: because this input uses EE_Model_Matching_Query_Validation_Strategy |
|
145 | + * for validation, this input's options only affect DISPLAY and NOT validation, |
|
146 | + * which is why its ok to just assume the provided $value to be in the list of acceptable values |
|
147 | + * |
|
148 | + * @param mixed $value |
|
149 | + * @return void |
|
150 | + * @throws \EE_Error |
|
151 | + */ |
|
152 | + public function _set_raw_value($value) |
|
153 | + { |
|
154 | + $values_for_options = (array) $value; |
|
155 | + $value_field = $this->_get_model()->field_settings_for($this->_value_field_name); |
|
156 | + $display_field = $this->_get_model()->field_settings_for($this->_display_field_name); |
|
157 | + $this->_extra_select_columns[] = $value_field->get_qualified_column() . ' AS ' . $this->_value_field_name; |
|
158 | + $this->_extra_select_columns[] = $display_field->get_qualified_column() . ' AS ' . $this->_display_field_name; |
|
159 | + $display_values = $this->_get_model()->get_all_wpdb_results( |
|
160 | + array( |
|
161 | + array( |
|
162 | + $this->_value_field_name => array( 'IN', $values_for_options ) |
|
163 | + ) |
|
164 | + ), |
|
165 | + ARRAY_A, |
|
166 | + implode(',', $this->_extra_select_columns) |
|
167 | + ); |
|
168 | + $select_options = array(); |
|
169 | + if (is_array($select_options)) { |
|
170 | + foreach ($display_values as $db_rows) { |
|
171 | + $db_rows = (array) $db_rows; |
|
172 | + $select_options[ $db_rows[ $this->_value_field_name ] ] = apply_filters( |
|
173 | + 'FHEE__EE_Select_Ajax_Model_Rest_Input___set_raw_value__select_option_value', |
|
174 | + $db_rows[ $this->_display_field_name ], |
|
175 | + $db_rows |
|
176 | + ); |
|
177 | + } |
|
178 | + } |
|
179 | + $this->set_select_options($select_options); |
|
180 | + parent::_set_raw_value($value); |
|
181 | + } |
|
182 | 182 | |
183 | - /** |
|
184 | - * Returns the model, or throws an exception if the model name provided in constructor doesn't exist |
|
185 | - * @return EEM_Base |
|
186 | - * @throws EE_Error |
|
187 | - */ |
|
188 | - protected function _get_model() |
|
189 | - { |
|
190 | - if (! EE_Registry::instance()->is_model_name($this->_model_name)) { |
|
191 | - throw new EE_Error( |
|
192 | - sprintf( |
|
193 | - esc_html__( |
|
194 | - '%1$s is not a proper model name. Please provide a model name in the "model_name" form input argument', |
|
195 | - 'event_espresso' |
|
196 | - ), |
|
197 | - $this->_model_name |
|
198 | - ) |
|
199 | - ); |
|
200 | - } else { |
|
201 | - return EE_Registry::instance()->load_model($this->_model_name); |
|
202 | - } |
|
203 | - } |
|
183 | + /** |
|
184 | + * Returns the model, or throws an exception if the model name provided in constructor doesn't exist |
|
185 | + * @return EEM_Base |
|
186 | + * @throws EE_Error |
|
187 | + */ |
|
188 | + protected function _get_model() |
|
189 | + { |
|
190 | + if (! EE_Registry::instance()->is_model_name($this->_model_name)) { |
|
191 | + throw new EE_Error( |
|
192 | + sprintf( |
|
193 | + esc_html__( |
|
194 | + '%1$s is not a proper model name. Please provide a model name in the "model_name" form input argument', |
|
195 | + 'event_espresso' |
|
196 | + ), |
|
197 | + $this->_model_name |
|
198 | + ) |
|
199 | + ); |
|
200 | + } else { |
|
201 | + return EE_Registry::instance()->load_model($this->_model_name); |
|
202 | + } |
|
203 | + } |
|
204 | 204 | } |
@@ -120,7 +120,7 @@ |
||
120 | 120 | public function _update_config(EE_Config_Base $config_obj = null) |
121 | 121 | { |
122 | 122 | $config_class = $this->config_class(); |
123 | - if (! $config_obj instanceof $config_class) { |
|
123 | + if ( ! $config_obj instanceof $config_class) { |
|
124 | 124 | throw new EE_Error( |
125 | 125 | sprintf( |
126 | 126 | esc_html__('The "%1$s" class is not an instance of %2$s.', 'event_espresso'), |
@@ -9,143 +9,143 @@ |
||
9 | 9 | */ |
10 | 10 | abstract class EE_Configurable extends EE_Base |
11 | 11 | { |
12 | - /** |
|
13 | - * @var $_config |
|
14 | - * @type EE_Config_Base |
|
15 | - */ |
|
16 | - protected $_config; |
|
17 | - |
|
18 | - /** |
|
19 | - * @var $_config_section |
|
20 | - * @type string |
|
21 | - */ |
|
22 | - protected $_config_section = ''; |
|
23 | - |
|
24 | - /** |
|
25 | - * @var $_config_class |
|
26 | - * @type string |
|
27 | - */ |
|
28 | - protected $_config_class = ''; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var $_config_name |
|
32 | - * @type string |
|
33 | - */ |
|
34 | - protected $_config_name = ''; |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * @param string $config_section |
|
39 | - */ |
|
40 | - public function set_config_section($config_section = '') |
|
41 | - { |
|
42 | - $this->_config_section = ! empty($config_section) ? $config_section : 'modules'; |
|
43 | - } |
|
44 | - |
|
45 | - |
|
46 | - /** |
|
47 | - * @return mixed |
|
48 | - */ |
|
49 | - public function config_section() |
|
50 | - { |
|
51 | - return $this->_config_section; |
|
52 | - } |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * @param string $config_class |
|
57 | - */ |
|
58 | - public function set_config_class($config_class = '') |
|
59 | - { |
|
60 | - $this->_config_class = $config_class; |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * @return mixed |
|
66 | - */ |
|
67 | - public function config_class() |
|
68 | - { |
|
69 | - return $this->_config_class; |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * @param mixed $config_name |
|
75 | - */ |
|
76 | - public function set_config_name($config_name) |
|
77 | - { |
|
78 | - $this->_config_name = ! empty($config_name) ? $config_name : get_called_class(); |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * @return mixed |
|
84 | - */ |
|
85 | - public function config_name() |
|
86 | - { |
|
87 | - return $this->_config_name; |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * set_config |
|
93 | - * this method integrates directly with EE_Config to set up the config object for this class |
|
94 | - * |
|
95 | - * @access protected |
|
96 | - * @param EE_Config_Base $config_obj |
|
97 | - * @return mixed EE_Config_Base | NULL |
|
98 | - */ |
|
99 | - protected function _set_config(EE_Config_Base $config_obj = null) |
|
100 | - { |
|
101 | - return EE_Config::instance()->set_config( |
|
102 | - $this->config_section(), |
|
103 | - $this->config_name(), |
|
104 | - $this->config_class(), |
|
105 | - $config_obj |
|
106 | - ); |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * _update_config |
|
112 | - * this method integrates directly with EE_Config to update an existing config object for this class |
|
113 | - * |
|
114 | - * @access protected |
|
115 | - * @param EE_Config_Base $config_obj |
|
116 | - * @throws \EE_Error |
|
117 | - * @return mixed EE_Config_Base | NULL |
|
118 | - */ |
|
119 | - public function _update_config(EE_Config_Base $config_obj = null) |
|
120 | - { |
|
121 | - $config_class = $this->config_class(); |
|
122 | - if (! $config_obj instanceof $config_class) { |
|
123 | - throw new EE_Error( |
|
124 | - sprintf( |
|
125 | - esc_html__('The "%1$s" class is not an instance of %2$s.', 'event_espresso'), |
|
126 | - print_r($config_obj, true), |
|
127 | - $config_class |
|
128 | - ) |
|
129 | - ); |
|
130 | - } |
|
131 | - return EE_Config::instance()->update_config($this->config_section(), $this->config_name(), $config_obj); |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * gets the class's config object |
|
137 | - * |
|
138 | - * @return EE_Config_Base |
|
139 | - */ |
|
140 | - public function config() |
|
141 | - { |
|
142 | - if (empty($this->_config)) { |
|
143 | - $this->_config = EE_Config::instance()->get_config( |
|
144 | - $this->config_section(), |
|
145 | - $this->config_name(), |
|
146 | - $this->config_class() |
|
147 | - ); |
|
148 | - } |
|
149 | - return $this->_config; |
|
150 | - } |
|
12 | + /** |
|
13 | + * @var $_config |
|
14 | + * @type EE_Config_Base |
|
15 | + */ |
|
16 | + protected $_config; |
|
17 | + |
|
18 | + /** |
|
19 | + * @var $_config_section |
|
20 | + * @type string |
|
21 | + */ |
|
22 | + protected $_config_section = ''; |
|
23 | + |
|
24 | + /** |
|
25 | + * @var $_config_class |
|
26 | + * @type string |
|
27 | + */ |
|
28 | + protected $_config_class = ''; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var $_config_name |
|
32 | + * @type string |
|
33 | + */ |
|
34 | + protected $_config_name = ''; |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * @param string $config_section |
|
39 | + */ |
|
40 | + public function set_config_section($config_section = '') |
|
41 | + { |
|
42 | + $this->_config_section = ! empty($config_section) ? $config_section : 'modules'; |
|
43 | + } |
|
44 | + |
|
45 | + |
|
46 | + /** |
|
47 | + * @return mixed |
|
48 | + */ |
|
49 | + public function config_section() |
|
50 | + { |
|
51 | + return $this->_config_section; |
|
52 | + } |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * @param string $config_class |
|
57 | + */ |
|
58 | + public function set_config_class($config_class = '') |
|
59 | + { |
|
60 | + $this->_config_class = $config_class; |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * @return mixed |
|
66 | + */ |
|
67 | + public function config_class() |
|
68 | + { |
|
69 | + return $this->_config_class; |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * @param mixed $config_name |
|
75 | + */ |
|
76 | + public function set_config_name($config_name) |
|
77 | + { |
|
78 | + $this->_config_name = ! empty($config_name) ? $config_name : get_called_class(); |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * @return mixed |
|
84 | + */ |
|
85 | + public function config_name() |
|
86 | + { |
|
87 | + return $this->_config_name; |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * set_config |
|
93 | + * this method integrates directly with EE_Config to set up the config object for this class |
|
94 | + * |
|
95 | + * @access protected |
|
96 | + * @param EE_Config_Base $config_obj |
|
97 | + * @return mixed EE_Config_Base | NULL |
|
98 | + */ |
|
99 | + protected function _set_config(EE_Config_Base $config_obj = null) |
|
100 | + { |
|
101 | + return EE_Config::instance()->set_config( |
|
102 | + $this->config_section(), |
|
103 | + $this->config_name(), |
|
104 | + $this->config_class(), |
|
105 | + $config_obj |
|
106 | + ); |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * _update_config |
|
112 | + * this method integrates directly with EE_Config to update an existing config object for this class |
|
113 | + * |
|
114 | + * @access protected |
|
115 | + * @param EE_Config_Base $config_obj |
|
116 | + * @throws \EE_Error |
|
117 | + * @return mixed EE_Config_Base | NULL |
|
118 | + */ |
|
119 | + public function _update_config(EE_Config_Base $config_obj = null) |
|
120 | + { |
|
121 | + $config_class = $this->config_class(); |
|
122 | + if (! $config_obj instanceof $config_class) { |
|
123 | + throw new EE_Error( |
|
124 | + sprintf( |
|
125 | + esc_html__('The "%1$s" class is not an instance of %2$s.', 'event_espresso'), |
|
126 | + print_r($config_obj, true), |
|
127 | + $config_class |
|
128 | + ) |
|
129 | + ); |
|
130 | + } |
|
131 | + return EE_Config::instance()->update_config($this->config_section(), $this->config_name(), $config_obj); |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * gets the class's config object |
|
137 | + * |
|
138 | + * @return EE_Config_Base |
|
139 | + */ |
|
140 | + public function config() |
|
141 | + { |
|
142 | + if (empty($this->_config)) { |
|
143 | + $this->_config = EE_Config::instance()->get_config( |
|
144 | + $this->config_section(), |
|
145 | + $this->config_name(), |
|
146 | + $this->config_class() |
|
147 | + ); |
|
148 | + } |
|
149 | + return $this->_config; |
|
150 | + } |
|
151 | 151 | } |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | */ |
25 | 25 | protected function __construct($timezone) |
26 | 26 | { |
27 | - require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
27 | + require_once(EE_MODELS.'EEM_Price_Type.model.php'); |
|
28 | 28 | $this->singular_item = esc_html__('Price', 'event_espresso'); |
29 | 29 | $this->plural_item = esc_html__('Prices', 'event_espresso'); |
30 | 30 | |
@@ -52,11 +52,11 @@ discard block |
||
52 | 52 | 'WP_User' => new EE_Belongs_To_Relation(), |
53 | 53 | ); |
54 | 54 | // this model is generally available for reading |
55 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('PRC_is_default', 'Ticket.Datetime.Event'); |
|
55 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Default_Public('PRC_is_default', 'Ticket.Datetime.Event'); |
|
56 | 56 | // account for default tickets in the caps |
57 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event'); |
|
58 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event'); |
|
59 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event'); |
|
57 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event'); |
|
58 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event'); |
|
59 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event'); |
|
60 | 60 | parent::__construct($timezone); |
61 | 61 | } |
62 | 62 | |
@@ -103,7 +103,7 @@ discard block |
||
103 | 103 | return $this->get_all(array( |
104 | 104 | array( |
105 | 105 | 'EVT_ID' => $EVT_ID, |
106 | - 'Price_Type.PBT_ID' => array('!=', EEM_Price_Type::base_type_tax) |
|
106 | + 'Price_Type.PBT_ID' => array('!=', EEM_Price_Type::base_type_tax) |
|
107 | 107 | ), |
108 | 108 | 'order_by' => $this->_order_by_array_for_get_all_method() |
109 | 109 | )); |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | public function get_all_default_prices($count = false) |
122 | 122 | { |
123 | 123 | $_where = array( |
124 | - 'Price_Type.PBT_ID' => array('!=',4), |
|
124 | + 'Price_Type.PBT_ID' => array('!=', 4), |
|
125 | 125 | 'PRC_deleted' => 0, |
126 | 126 | 'PRC_is_default' => 1 |
127 | 127 | ); |
@@ -153,12 +153,12 @@ discard block |
||
153 | 153 | { |
154 | 154 | $taxes = array(); |
155 | 155 | $all_taxes = $this->get_all(array( |
156 | - array( 'Price_Type.PBT_ID' => EEM_Price_Type::base_type_tax ), |
|
157 | - 'order_by' => array( 'Price_Type.PRT_order' => 'ASC', 'PRC_order' => 'ASC' ) |
|
156 | + array('Price_Type.PBT_ID' => EEM_Price_Type::base_type_tax), |
|
157 | + 'order_by' => array('Price_Type.PRT_order' => 'ASC', 'PRC_order' => 'ASC') |
|
158 | 158 | )); |
159 | 159 | foreach ($all_taxes as $tax) { |
160 | 160 | if ($tax instanceof EE_Price) { |
161 | - $taxes[ $tax->order() ][ $tax->ID() ] = $tax; |
|
161 | + $taxes[$tax->order()][$tax->ID()] = $tax; |
|
162 | 162 | } |
163 | 163 | } |
164 | 164 | return $taxes; |
@@ -186,7 +186,7 @@ discard block |
||
186 | 186 | if ($default_prices) { |
187 | 187 | foreach ($default_prices as $price) { |
188 | 188 | if ($price instanceof EE_Price) { |
189 | - $array_of_price_objects[ $price->type() ][] = $price; |
|
189 | + $array_of_price_objects[$price->type()][] = $price; |
|
190 | 190 | } |
191 | 191 | } |
192 | 192 | return $array_of_price_objects; |
@@ -203,10 +203,10 @@ discard block |
||
203 | 203 | )); |
204 | 204 | } |
205 | 205 | |
206 | - if (!empty($ticket_prices)) { |
|
206 | + if ( ! empty($ticket_prices)) { |
|
207 | 207 | foreach ($ticket_prices as $price) { |
208 | 208 | if ($price instanceof EE_Price) { |
209 | - $array_of_price_objects[ $price->type() ][] = $price; |
|
209 | + $array_of_price_objects[$price->type()][] = $price; |
|
210 | 210 | } |
211 | 211 | } |
212 | 212 | return $array_of_price_objects; |
@@ -9,279 +9,279 @@ |
||
9 | 9 | */ |
10 | 10 | class EEM_Price extends EEM_Soft_Delete_Base |
11 | 11 | { |
12 | - // private instance of the EEM_Price object |
|
13 | - protected static $_instance = null; |
|
14 | - |
|
15 | - |
|
16 | - |
|
17 | - /** |
|
18 | - * private constructor to prevent direct creation |
|
19 | - * @Constructor |
|
20 | - * @access protected |
|
21 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
22 | - * @return EEM_Price |
|
23 | - */ |
|
24 | - protected function __construct($timezone) |
|
25 | - { |
|
26 | - require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
27 | - $this->singular_item = esc_html__('Price', 'event_espresso'); |
|
28 | - $this->plural_item = esc_html__('Prices', 'event_espresso'); |
|
29 | - |
|
30 | - $this->_tables = array( |
|
31 | - 'Price' => new EE_Primary_Table('esp_price', 'PRC_ID') |
|
32 | - ); |
|
33 | - $this->_fields = array( |
|
34 | - 'Price' => array( |
|
35 | - 'PRC_ID' => new EE_Primary_Key_Int_Field('PRC_ID', 'Price ID'), |
|
36 | - 'PRT_ID' => new EE_Foreign_Key_Int_Field('PRT_ID', 'Price type Id', false, null, 'Price_Type'), |
|
37 | - 'PRC_amount' => new EE_Money_Field('PRC_amount', 'Price Amount', false, 0), |
|
38 | - 'PRC_name' => new EE_Plain_Text_Field('PRC_name', 'Name of Price', false, ''), |
|
39 | - 'PRC_desc' => new EE_Post_Content_Field('PRC_desc', 'Price Description', false, ''), |
|
40 | - 'PRC_is_default' => new EE_Boolean_Field('PRC_is_default', 'Flag indicating whether price is a default price', false, false), |
|
41 | - 'PRC_overrides' => new EE_Integer_Field('PRC_overrides', 'Price ID for a global Price that will be overridden by this Price ( for replacing default prices )', true, 0), |
|
42 | - 'PRC_order' => new EE_Integer_Field('PRC_order', 'Order of Application of Price (lower numbers apply first?)', false, 1), |
|
43 | - 'PRC_deleted' => new EE_Trashed_Flag_Field('PRC_deleted', 'Flag Indicating if this has been deleted or not', false, false), |
|
44 | - 'PRC_parent' => new EE_Integer_Field('PRC_parent', esc_html__('Indicates what PRC_ID is the parent of this PRC_ID', 'event_espresso'), true, 0), |
|
45 | - 'PRC_wp_user' => new EE_WP_User_Field('PRC_wp_user', esc_html__('Price Creator ID', 'event_espresso'), false), |
|
46 | - ) |
|
47 | - ); |
|
48 | - $this->_model_relations = array( |
|
49 | - 'Ticket' => new EE_HABTM_Relation('Ticket_Price'), |
|
50 | - 'Price_Type' => new EE_Belongs_To_Relation(), |
|
51 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
52 | - ); |
|
53 | - // this model is generally available for reading |
|
54 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('PRC_is_default', 'Ticket.Datetime.Event'); |
|
55 | - // account for default tickets in the caps |
|
56 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event'); |
|
57 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event'); |
|
58 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event'); |
|
59 | - parent::__construct($timezone); |
|
60 | - } |
|
61 | - |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * instantiate a new price object with blank/empty properties |
|
66 | - * |
|
67 | - * @access public |
|
68 | - * @return mixed array on success, FALSE on fail |
|
69 | - */ |
|
70 | - public function get_new_price() |
|
71 | - { |
|
72 | - return $this->create_default_object(); |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * retrieve ALL prices from db |
|
81 | - * |
|
82 | - * @access public |
|
83 | - * @return EE_PRice[] |
|
84 | - */ |
|
85 | - public function get_all_prices() |
|
86 | - { |
|
87 | - // retrieve all prices |
|
88 | - return $this->get_all(array('order_by' => array('PRC_amount' => 'ASC'))); |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * retrieve all active prices for a particular event |
|
95 | - * |
|
96 | - * @access public |
|
97 | - * @param int $EVT_ID |
|
98 | - * @return array on success |
|
99 | - */ |
|
100 | - public function get_all_event_prices($EVT_ID = 0) |
|
101 | - { |
|
102 | - return $this->get_all(array( |
|
103 | - array( |
|
104 | - 'EVT_ID' => $EVT_ID, |
|
105 | - 'Price_Type.PBT_ID' => array('!=', EEM_Price_Type::base_type_tax) |
|
106 | - ), |
|
107 | - 'order_by' => $this->_order_by_array_for_get_all_method() |
|
108 | - )); |
|
109 | - } |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * retrieve all active global prices (that are not taxes (PBT_ID=4)) for a particular event |
|
114 | - * |
|
115 | - * @access public |
|
116 | - * @param boolean $count return count |
|
117 | - * @return array on success |
|
118 | - * @return boolean false on fail |
|
119 | - */ |
|
120 | - public function get_all_default_prices($count = false) |
|
121 | - { |
|
122 | - $_where = array( |
|
123 | - 'Price_Type.PBT_ID' => array('!=',4), |
|
124 | - 'PRC_deleted' => 0, |
|
125 | - 'PRC_is_default' => 1 |
|
126 | - ); |
|
127 | - $_query_params = array( |
|
128 | - $_where, |
|
129 | - 'order_by' => $this->_order_by_array_for_get_all_method() |
|
130 | - ); |
|
131 | - return $count ? $this->count(array($_where)) : $this->get_all($_query_params); |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - |
|
136 | - |
|
137 | - |
|
138 | - |
|
139 | - |
|
140 | - |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * retrieve all prices that are taxes |
|
145 | - * |
|
146 | - * @access public |
|
147 | - * @return array on success |
|
148 | - * @return array top-level keys are the price's order and their values are an array, |
|
149 | - * next-level keys are the price's ID, and their values are EE_Price objects |
|
150 | - */ |
|
151 | - public function get_all_prices_that_are_taxes() |
|
152 | - { |
|
153 | - $taxes = array(); |
|
154 | - $all_taxes = $this->get_all(array( |
|
155 | - array( 'Price_Type.PBT_ID' => EEM_Price_Type::base_type_tax ), |
|
156 | - 'order_by' => array( 'Price_Type.PRT_order' => 'ASC', 'PRC_order' => 'ASC' ) |
|
157 | - )); |
|
158 | - foreach ($all_taxes as $tax) { |
|
159 | - if ($tax instanceof EE_Price) { |
|
160 | - $taxes[ $tax->order() ][ $tax->ID() ] = $tax; |
|
161 | - } |
|
162 | - } |
|
163 | - return $taxes; |
|
164 | - } |
|
165 | - |
|
166 | - |
|
167 | - |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * retrieve all prices for an ticket plus default global prices, but not taxes |
|
172 | - * |
|
173 | - * @access public |
|
174 | - * @param int $TKT_ID the id of the event. If not included then we assume that this is a new ticket. |
|
175 | - * @return boolean false on fail |
|
176 | - */ |
|
177 | - public function get_all_ticket_prices_for_admin($TKT_ID = 0) |
|
178 | - { |
|
179 | - $array_of_price_objects = array(); |
|
180 | - if (empty($TKT_ID)) { |
|
181 | - // if there is no tkt, get prices with no tkt ID, are global, are not a tax, and are active |
|
182 | - // return that list |
|
183 | - $default_prices = $this->get_all_default_prices(); |
|
184 | - |
|
185 | - if ($default_prices) { |
|
186 | - foreach ($default_prices as $price) { |
|
187 | - if ($price instanceof EE_Price) { |
|
188 | - $array_of_price_objects[ $price->type() ][] = $price; |
|
189 | - } |
|
190 | - } |
|
191 | - return $array_of_price_objects; |
|
192 | - } else { |
|
193 | - return array(); |
|
194 | - } |
|
195 | - } else { |
|
196 | - $ticket_prices = $this->get_all(array( |
|
197 | - array( |
|
198 | - 'TKT_ID' => $TKT_ID, |
|
199 | - 'PRC_deleted' => 0 |
|
200 | - ), |
|
201 | - 'order_by' => array('PRC_order' => 'ASC') |
|
202 | - )); |
|
203 | - } |
|
204 | - |
|
205 | - if (!empty($ticket_prices)) { |
|
206 | - foreach ($ticket_prices as $price) { |
|
207 | - if ($price instanceof EE_Price) { |
|
208 | - $array_of_price_objects[ $price->type() ][] = $price; |
|
209 | - } |
|
210 | - } |
|
211 | - return $array_of_price_objects; |
|
212 | - } else { |
|
213 | - return false; |
|
214 | - } |
|
215 | - } |
|
216 | - |
|
217 | - |
|
218 | - |
|
219 | - /** |
|
220 | - * _sort_event_prices_by_type |
|
221 | - * |
|
222 | - * @access public |
|
223 | - * @param \EE_Price $price_a |
|
224 | - * @param \EE_Price $price_b |
|
225 | - * @return bool false on fail |
|
226 | - */ |
|
227 | - public function _sort_event_prices_by_type(EE_Price $price_a, EE_Price $price_b) |
|
228 | - { |
|
229 | - if ($price_a->type_obj()->order() == $price_b->type_obj()->order()) { |
|
230 | - return $this->_sort_event_prices_by_order($price_a, $price_b); |
|
231 | - } |
|
232 | - return $price_a->type_obj()->order() < $price_b->type_obj()->order() ? -1 : 1; |
|
233 | - } |
|
234 | - |
|
235 | - |
|
236 | - |
|
237 | - /** |
|
238 | - * _sort_event_prices_by_order |
|
239 | - * |
|
240 | - * @access public |
|
241 | - * @param \EE_Price $price_a |
|
242 | - * @param \EE_Price $price_b |
|
243 | - * @return bool false on fail |
|
244 | - */ |
|
245 | - public function _sort_event_prices_by_order(EE_Price $price_a, EE_Price $price_b) |
|
246 | - { |
|
247 | - if ($price_a->order() == $price_b->order()) { |
|
248 | - return 0; |
|
249 | - } |
|
250 | - return $price_a->order() < $price_b->order() ? -1 : 1; |
|
251 | - } |
|
252 | - |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * get all prices of a specific type |
|
257 | - * |
|
258 | - * @access public |
|
259 | - * @param int $type - PRT_ID |
|
260 | - * @return boolean false on fail |
|
261 | - */ |
|
262 | - public function get_all_prices_that_are_type($type = 0) |
|
263 | - { |
|
264 | - return $this->get_all(array( |
|
265 | - array( |
|
266 | - 'PRT_ID' => $type |
|
267 | - ), |
|
268 | - 'order_by' => $this->_order_by_array_for_get_all_method() |
|
269 | - )); |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - |
|
274 | - /** |
|
275 | - * Returns an array of the normal 'order_by' query parameter provided to the get_all query. |
|
276 | - * Of course you don't have to use it, but this is the order we usually want to sort prices by |
|
277 | - * @return array which can be used like so: $this->get_all(array(array(...where stuff...),'order_by'=>$this->_order_by_array_for_get_all_method())); |
|
278 | - */ |
|
279 | - public function _order_by_array_for_get_all_method() |
|
280 | - { |
|
281 | - return array( |
|
282 | - 'PRC_order' => 'ASC', |
|
283 | - 'Price_Type.PRT_order' => 'ASC', |
|
284 | - 'PRC_ID' => 'ASC' |
|
285 | - ); |
|
286 | - } |
|
12 | + // private instance of the EEM_Price object |
|
13 | + protected static $_instance = null; |
|
14 | + |
|
15 | + |
|
16 | + |
|
17 | + /** |
|
18 | + * private constructor to prevent direct creation |
|
19 | + * @Constructor |
|
20 | + * @access protected |
|
21 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
22 | + * @return EEM_Price |
|
23 | + */ |
|
24 | + protected function __construct($timezone) |
|
25 | + { |
|
26 | + require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
27 | + $this->singular_item = esc_html__('Price', 'event_espresso'); |
|
28 | + $this->plural_item = esc_html__('Prices', 'event_espresso'); |
|
29 | + |
|
30 | + $this->_tables = array( |
|
31 | + 'Price' => new EE_Primary_Table('esp_price', 'PRC_ID') |
|
32 | + ); |
|
33 | + $this->_fields = array( |
|
34 | + 'Price' => array( |
|
35 | + 'PRC_ID' => new EE_Primary_Key_Int_Field('PRC_ID', 'Price ID'), |
|
36 | + 'PRT_ID' => new EE_Foreign_Key_Int_Field('PRT_ID', 'Price type Id', false, null, 'Price_Type'), |
|
37 | + 'PRC_amount' => new EE_Money_Field('PRC_amount', 'Price Amount', false, 0), |
|
38 | + 'PRC_name' => new EE_Plain_Text_Field('PRC_name', 'Name of Price', false, ''), |
|
39 | + 'PRC_desc' => new EE_Post_Content_Field('PRC_desc', 'Price Description', false, ''), |
|
40 | + 'PRC_is_default' => new EE_Boolean_Field('PRC_is_default', 'Flag indicating whether price is a default price', false, false), |
|
41 | + 'PRC_overrides' => new EE_Integer_Field('PRC_overrides', 'Price ID for a global Price that will be overridden by this Price ( for replacing default prices )', true, 0), |
|
42 | + 'PRC_order' => new EE_Integer_Field('PRC_order', 'Order of Application of Price (lower numbers apply first?)', false, 1), |
|
43 | + 'PRC_deleted' => new EE_Trashed_Flag_Field('PRC_deleted', 'Flag Indicating if this has been deleted or not', false, false), |
|
44 | + 'PRC_parent' => new EE_Integer_Field('PRC_parent', esc_html__('Indicates what PRC_ID is the parent of this PRC_ID', 'event_espresso'), true, 0), |
|
45 | + 'PRC_wp_user' => new EE_WP_User_Field('PRC_wp_user', esc_html__('Price Creator ID', 'event_espresso'), false), |
|
46 | + ) |
|
47 | + ); |
|
48 | + $this->_model_relations = array( |
|
49 | + 'Ticket' => new EE_HABTM_Relation('Ticket_Price'), |
|
50 | + 'Price_Type' => new EE_Belongs_To_Relation(), |
|
51 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
52 | + ); |
|
53 | + // this model is generally available for reading |
|
54 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('PRC_is_default', 'Ticket.Datetime.Event'); |
|
55 | + // account for default tickets in the caps |
|
56 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event'); |
|
57 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event'); |
|
58 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('PRC_is_default', 'Ticket.Datetime.Event'); |
|
59 | + parent::__construct($timezone); |
|
60 | + } |
|
61 | + |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * instantiate a new price object with blank/empty properties |
|
66 | + * |
|
67 | + * @access public |
|
68 | + * @return mixed array on success, FALSE on fail |
|
69 | + */ |
|
70 | + public function get_new_price() |
|
71 | + { |
|
72 | + return $this->create_default_object(); |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * retrieve ALL prices from db |
|
81 | + * |
|
82 | + * @access public |
|
83 | + * @return EE_PRice[] |
|
84 | + */ |
|
85 | + public function get_all_prices() |
|
86 | + { |
|
87 | + // retrieve all prices |
|
88 | + return $this->get_all(array('order_by' => array('PRC_amount' => 'ASC'))); |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * retrieve all active prices for a particular event |
|
95 | + * |
|
96 | + * @access public |
|
97 | + * @param int $EVT_ID |
|
98 | + * @return array on success |
|
99 | + */ |
|
100 | + public function get_all_event_prices($EVT_ID = 0) |
|
101 | + { |
|
102 | + return $this->get_all(array( |
|
103 | + array( |
|
104 | + 'EVT_ID' => $EVT_ID, |
|
105 | + 'Price_Type.PBT_ID' => array('!=', EEM_Price_Type::base_type_tax) |
|
106 | + ), |
|
107 | + 'order_by' => $this->_order_by_array_for_get_all_method() |
|
108 | + )); |
|
109 | + } |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * retrieve all active global prices (that are not taxes (PBT_ID=4)) for a particular event |
|
114 | + * |
|
115 | + * @access public |
|
116 | + * @param boolean $count return count |
|
117 | + * @return array on success |
|
118 | + * @return boolean false on fail |
|
119 | + */ |
|
120 | + public function get_all_default_prices($count = false) |
|
121 | + { |
|
122 | + $_where = array( |
|
123 | + 'Price_Type.PBT_ID' => array('!=',4), |
|
124 | + 'PRC_deleted' => 0, |
|
125 | + 'PRC_is_default' => 1 |
|
126 | + ); |
|
127 | + $_query_params = array( |
|
128 | + $_where, |
|
129 | + 'order_by' => $this->_order_by_array_for_get_all_method() |
|
130 | + ); |
|
131 | + return $count ? $this->count(array($_where)) : $this->get_all($_query_params); |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + |
|
136 | + |
|
137 | + |
|
138 | + |
|
139 | + |
|
140 | + |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * retrieve all prices that are taxes |
|
145 | + * |
|
146 | + * @access public |
|
147 | + * @return array on success |
|
148 | + * @return array top-level keys are the price's order and their values are an array, |
|
149 | + * next-level keys are the price's ID, and their values are EE_Price objects |
|
150 | + */ |
|
151 | + public function get_all_prices_that_are_taxes() |
|
152 | + { |
|
153 | + $taxes = array(); |
|
154 | + $all_taxes = $this->get_all(array( |
|
155 | + array( 'Price_Type.PBT_ID' => EEM_Price_Type::base_type_tax ), |
|
156 | + 'order_by' => array( 'Price_Type.PRT_order' => 'ASC', 'PRC_order' => 'ASC' ) |
|
157 | + )); |
|
158 | + foreach ($all_taxes as $tax) { |
|
159 | + if ($tax instanceof EE_Price) { |
|
160 | + $taxes[ $tax->order() ][ $tax->ID() ] = $tax; |
|
161 | + } |
|
162 | + } |
|
163 | + return $taxes; |
|
164 | + } |
|
165 | + |
|
166 | + |
|
167 | + |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * retrieve all prices for an ticket plus default global prices, but not taxes |
|
172 | + * |
|
173 | + * @access public |
|
174 | + * @param int $TKT_ID the id of the event. If not included then we assume that this is a new ticket. |
|
175 | + * @return boolean false on fail |
|
176 | + */ |
|
177 | + public function get_all_ticket_prices_for_admin($TKT_ID = 0) |
|
178 | + { |
|
179 | + $array_of_price_objects = array(); |
|
180 | + if (empty($TKT_ID)) { |
|
181 | + // if there is no tkt, get prices with no tkt ID, are global, are not a tax, and are active |
|
182 | + // return that list |
|
183 | + $default_prices = $this->get_all_default_prices(); |
|
184 | + |
|
185 | + if ($default_prices) { |
|
186 | + foreach ($default_prices as $price) { |
|
187 | + if ($price instanceof EE_Price) { |
|
188 | + $array_of_price_objects[ $price->type() ][] = $price; |
|
189 | + } |
|
190 | + } |
|
191 | + return $array_of_price_objects; |
|
192 | + } else { |
|
193 | + return array(); |
|
194 | + } |
|
195 | + } else { |
|
196 | + $ticket_prices = $this->get_all(array( |
|
197 | + array( |
|
198 | + 'TKT_ID' => $TKT_ID, |
|
199 | + 'PRC_deleted' => 0 |
|
200 | + ), |
|
201 | + 'order_by' => array('PRC_order' => 'ASC') |
|
202 | + )); |
|
203 | + } |
|
204 | + |
|
205 | + if (!empty($ticket_prices)) { |
|
206 | + foreach ($ticket_prices as $price) { |
|
207 | + if ($price instanceof EE_Price) { |
|
208 | + $array_of_price_objects[ $price->type() ][] = $price; |
|
209 | + } |
|
210 | + } |
|
211 | + return $array_of_price_objects; |
|
212 | + } else { |
|
213 | + return false; |
|
214 | + } |
|
215 | + } |
|
216 | + |
|
217 | + |
|
218 | + |
|
219 | + /** |
|
220 | + * _sort_event_prices_by_type |
|
221 | + * |
|
222 | + * @access public |
|
223 | + * @param \EE_Price $price_a |
|
224 | + * @param \EE_Price $price_b |
|
225 | + * @return bool false on fail |
|
226 | + */ |
|
227 | + public function _sort_event_prices_by_type(EE_Price $price_a, EE_Price $price_b) |
|
228 | + { |
|
229 | + if ($price_a->type_obj()->order() == $price_b->type_obj()->order()) { |
|
230 | + return $this->_sort_event_prices_by_order($price_a, $price_b); |
|
231 | + } |
|
232 | + return $price_a->type_obj()->order() < $price_b->type_obj()->order() ? -1 : 1; |
|
233 | + } |
|
234 | + |
|
235 | + |
|
236 | + |
|
237 | + /** |
|
238 | + * _sort_event_prices_by_order |
|
239 | + * |
|
240 | + * @access public |
|
241 | + * @param \EE_Price $price_a |
|
242 | + * @param \EE_Price $price_b |
|
243 | + * @return bool false on fail |
|
244 | + */ |
|
245 | + public function _sort_event_prices_by_order(EE_Price $price_a, EE_Price $price_b) |
|
246 | + { |
|
247 | + if ($price_a->order() == $price_b->order()) { |
|
248 | + return 0; |
|
249 | + } |
|
250 | + return $price_a->order() < $price_b->order() ? -1 : 1; |
|
251 | + } |
|
252 | + |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * get all prices of a specific type |
|
257 | + * |
|
258 | + * @access public |
|
259 | + * @param int $type - PRT_ID |
|
260 | + * @return boolean false on fail |
|
261 | + */ |
|
262 | + public function get_all_prices_that_are_type($type = 0) |
|
263 | + { |
|
264 | + return $this->get_all(array( |
|
265 | + array( |
|
266 | + 'PRT_ID' => $type |
|
267 | + ), |
|
268 | + 'order_by' => $this->_order_by_array_for_get_all_method() |
|
269 | + )); |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + |
|
274 | + /** |
|
275 | + * Returns an array of the normal 'order_by' query parameter provided to the get_all query. |
|
276 | + * Of course you don't have to use it, but this is the order we usually want to sort prices by |
|
277 | + * @return array which can be used like so: $this->get_all(array(array(...where stuff...),'order_by'=>$this->_order_by_array_for_get_all_method())); |
|
278 | + */ |
|
279 | + public function _order_by_array_for_get_all_method() |
|
280 | + { |
|
281 | + return array( |
|
282 | + 'PRC_order' => 'ASC', |
|
283 | + 'Price_Type.PRT_order' => 'ASC', |
|
284 | + 'PRC_ID' => 'ASC' |
|
285 | + ); |
|
286 | + } |
|
287 | 287 | } |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | ), |
144 | 144 | ], |
145 | 145 | ]; |
146 | - $this->_model_relations = [ |
|
146 | + $this->_model_relations = [ |
|
147 | 147 | 'Registration' => new EE_Has_Many_Relation(), |
148 | 148 | 'Payment' => new EE_Has_Many_Relation(), |
149 | 149 | 'Status' => new EE_Belongs_To_Relation(), |
@@ -211,7 +211,7 @@ discard block |
||
211 | 211 | ], |
212 | 212 | OBJECT, |
213 | 213 | [ |
214 | - 'txnDate' => ['DATE(' . $query_interval . ')', '%s'], |
|
214 | + 'txnDate' => ['DATE('.$query_interval.')', '%s'], |
|
215 | 215 | 'revenue' => ['SUM(TransactionTable.TXN_paid)', '%d'], |
216 | 216 | ] |
217 | 217 | ); |
@@ -230,17 +230,17 @@ discard block |
||
230 | 230 | public function get_revenue_per_event_report($period = '-1 month') |
231 | 231 | { |
232 | 232 | global $wpdb; |
233 | - $transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
234 | - $registration_table = $wpdb->prefix . 'esp_registration'; |
|
235 | - $registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; |
|
233 | + $transaction_table = $wpdb->prefix.'esp_transaction'; |
|
234 | + $registration_table = $wpdb->prefix.'esp_registration'; |
|
235 | + $registration_payment_table = $wpdb->prefix.'esp_registration_payment'; |
|
236 | 236 | $event_table = $wpdb->posts; |
237 | - $payment_table = $wpdb->prefix . 'esp_payment'; |
|
237 | + $payment_table = $wpdb->prefix.'esp_payment'; |
|
238 | 238 | $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
239 | 239 | $approved_payment_status = EEM_Payment::status_id_approved; |
240 | 240 | $extra_event_on_join = ''; |
241 | 241 | // exclude events not authored by user if permissions in effect |
242 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
243 | - $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id(); |
|
242 | + if ( ! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
243 | + $extra_event_on_join = ' AND Event.post_author = '.get_current_user_id(); |
|
244 | 244 | } |
245 | 245 | |
246 | 246 | return $wpdb->get_results( |
@@ -318,7 +318,7 @@ discard block |
||
318 | 318 | public function update_based_on_payments($transaction_obj_or_id, $save_txn = true) |
319 | 319 | { |
320 | 320 | EE_Error::doing_it_wrong( |
321 | - __CLASS__ . '::' . __FUNCTION__, |
|
321 | + __CLASS__.'::'.__FUNCTION__, |
|
322 | 322 | sprintf( |
323 | 323 | esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
324 | 324 | 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()' |
@@ -390,7 +390,7 @@ discard block |
||
390 | 390 | $time_to_leave_alone |
391 | 391 | ); |
392 | 392 | // now that we have the ids to delete |
393 | - if (! empty($txn_ids) && is_array($txn_ids)) { |
|
393 | + if ( ! empty($txn_ids) && is_array($txn_ids)) { |
|
394 | 394 | // first, make sure these TXN's are removed the "ee_locked_transactions" array |
395 | 395 | EEM_Transaction::unset_locked_transactions($txn_ids); |
396 | 396 | |
@@ -403,7 +403,7 @@ discard block |
||
403 | 403 | // let's get deleting... |
404 | 404 | // We got the ids from the original query to get them FROM |
405 | 405 | // the db (which is sanitized) so no need to prepare them again. |
406 | - $query = $wpdb->prepare("DELETE FROM " . $this->table() . " WHERE TXN_ID IN ( $format )", $txn_ids); |
|
406 | + $query = $wpdb->prepare("DELETE FROM ".$this->table()." WHERE TXN_ID IN ( $format )", $txn_ids); |
|
407 | 407 | $deleted = $wpdb->query($query); |
408 | 408 | } |
409 | 409 | if ($deleted) { |
@@ -427,8 +427,8 @@ discard block |
||
427 | 427 | $locked_transactions = get_option('ee_locked_transactions', []); |
428 | 428 | $update = false; |
429 | 429 | foreach ($transaction_IDs as $TXN_ID) { |
430 | - if (isset($locked_transactions[ $TXN_ID ])) { |
|
431 | - unset($locked_transactions[ $TXN_ID ]); |
|
430 | + if (isset($locked_transactions[$TXN_ID])) { |
|
431 | + unset($locked_transactions[$TXN_ID]); |
|
432 | 432 | $update = true; |
433 | 433 | } |
434 | 434 | } |
@@ -19,231 +19,231 @@ discard block |
||
19 | 19 | */ |
20 | 20 | class EEM_Transaction extends EEM_Base |
21 | 21 | { |
22 | - // private instance of the Transaction object |
|
23 | - protected static $_instance; |
|
24 | - |
|
25 | - /** |
|
26 | - * Status ID(STS_ID on esp_status table) to indicate the transaction is complete, |
|
27 | - * but payment is pending. This is the state for transactions where payment is promised |
|
28 | - * from an offline gateway. |
|
29 | - */ |
|
30 | - // const open_status_code = 'TPN'; |
|
31 | - |
|
32 | - /** |
|
33 | - * Status ID(STS_ID on esp_status table) to indicate the transaction failed, |
|
34 | - * either due to a technical reason (server or computer crash during registration), |
|
35 | - * or some other reason that prevent the collection of any useful contact information from any of the registrants |
|
36 | - */ |
|
37 | - const failed_status_code = 'TFL'; |
|
38 | - |
|
39 | - /** |
|
40 | - * Status ID(STS_ID on esp_status table) to indicate the transaction was abandoned, |
|
41 | - * either due to a technical reason (server or computer crash during registration), |
|
42 | - * or due to an abandoned cart after registrant chose not to complete the registration process |
|
43 | - * HOWEVER... |
|
44 | - * an abandoned TXN differs from a failed TXN in that it was able to capture contact information for at least one |
|
45 | - * registrant |
|
46 | - */ |
|
47 | - const abandoned_status_code = 'TAB'; |
|
48 | - |
|
49 | - /** |
|
50 | - * Status ID(STS_ID on esp_status table) to indicate an incomplete transaction, |
|
51 | - * meaning that monies are still owing: TXN_paid < TXN_total |
|
52 | - */ |
|
53 | - const incomplete_status_code = 'TIN'; |
|
54 | - |
|
55 | - /** |
|
56 | - * Status ID (STS_ID on esp_status table) to indicate a complete transaction. |
|
57 | - * meaning that NO monies are owing: TXN_paid == TXN_total |
|
58 | - */ |
|
59 | - const complete_status_code = 'TCM'; |
|
60 | - |
|
61 | - /** |
|
62 | - * Status ID(STS_ID on esp_status table) to indicate the transaction is overpaid. |
|
63 | - * This is the same as complete, but site admins actually owe clients the moneys! TXN_paid > TXN_total |
|
64 | - */ |
|
65 | - const overpaid_status_code = 'TOP'; |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * private constructor to prevent direct creation |
|
70 | - * |
|
71 | - * @Constructor |
|
72 | - * @access protected |
|
73 | - * |
|
74 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any |
|
75 | - * incoming timezone data that gets saved). Note this just sends the timezone info to the |
|
76 | - * date time model field objects. Default is NULL (and will be assumed using the set |
|
77 | - * timezone in the 'timezone_string' wp option) |
|
78 | - * |
|
79 | - * @throws EE_Error |
|
80 | - */ |
|
81 | - protected function __construct($timezone) |
|
82 | - { |
|
83 | - $this->singular_item = esc_html__('Transaction', 'event_espresso'); |
|
84 | - $this->plural_item = esc_html__('Transactions', 'event_espresso'); |
|
85 | - |
|
86 | - $this->_tables = [ |
|
87 | - 'TransactionTable' => new EE_Primary_Table('esp_transaction', 'TXN_ID'), |
|
88 | - ]; |
|
89 | - $this->_fields = [ |
|
90 | - 'TransactionTable' => [ |
|
91 | - 'TXN_ID' => new EE_Primary_Key_Int_Field('TXN_ID', esc_html__('Transaction ID', 'event_espresso')), |
|
92 | - 'TXN_timestamp' => new EE_Datetime_Field( |
|
93 | - 'TXN_timestamp', |
|
94 | - esc_html__('date when transaction was created', 'event_espresso'), |
|
95 | - false, |
|
96 | - EE_Datetime_Field::now, |
|
97 | - $timezone |
|
98 | - ), |
|
99 | - 'TXN_total' => new EE_Money_Field( |
|
100 | - 'TXN_total', |
|
101 | - esc_html__('Total value of Transaction', 'event_espresso'), |
|
102 | - false, |
|
103 | - 0 |
|
104 | - ), |
|
105 | - 'TXN_paid' => new EE_Money_Field( |
|
106 | - 'TXN_paid', |
|
107 | - esc_html__('Amount paid towards transaction to date', 'event_espresso'), |
|
108 | - false, |
|
109 | - 0 |
|
110 | - ), |
|
111 | - 'STS_ID' => new EE_Foreign_Key_String_Field( |
|
112 | - 'STS_ID', |
|
113 | - esc_html__('Status ID', 'event_espresso'), |
|
114 | - false, |
|
115 | - EEM_Transaction::failed_status_code, |
|
116 | - 'Status' |
|
117 | - ), |
|
118 | - 'TXN_session_data' => new EE_Serialized_Text_Field( |
|
119 | - 'TXN_session_data', |
|
120 | - esc_html__('Serialized session data', 'event_espresso'), |
|
121 | - true, |
|
122 | - '' |
|
123 | - ), |
|
124 | - 'TXN_hash_salt' => new EE_Plain_Text_Field( |
|
125 | - 'TXN_hash_salt', |
|
126 | - esc_html__('Transaction Hash Salt', 'event_espresso'), |
|
127 | - true, |
|
128 | - '' |
|
129 | - ), |
|
130 | - 'PMD_ID' => new EE_Foreign_Key_Int_Field( |
|
131 | - 'PMD_ID', |
|
132 | - esc_html__("Last Used Payment Method", 'event_espresso'), |
|
133 | - true, |
|
134 | - null, |
|
135 | - 'Payment_Method' |
|
136 | - ), |
|
137 | - 'TXN_reg_steps' => new EE_Serialized_Text_Field( |
|
138 | - 'TXN_reg_steps', |
|
139 | - esc_html__('Registration Steps', 'event_espresso'), |
|
140 | - false, |
|
141 | - [] |
|
142 | - ), |
|
143 | - ], |
|
144 | - ]; |
|
145 | - $this->_model_relations = [ |
|
146 | - 'Registration' => new EE_Has_Many_Relation(), |
|
147 | - 'Payment' => new EE_Has_Many_Relation(), |
|
148 | - 'Status' => new EE_Belongs_To_Relation(), |
|
149 | - 'Line_Item' => new EE_Has_Many_Relation(false), |
|
150 | - // you can delete a transaction without needing to delete its line items |
|
151 | - 'Payment_Method' => new EE_Belongs_To_Relation(), |
|
152 | - 'Message' => new EE_Has_Many_Relation(), |
|
153 | - ]; |
|
154 | - $this->_model_chain_to_wp_user = 'Registration.Event'; |
|
155 | - parent::__construct($timezone); |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * txn_status_array |
|
161 | - * get list of transaction statuses |
|
162 | - * |
|
163 | - * @access public |
|
164 | - * @return array |
|
165 | - */ |
|
166 | - public static function txn_status_array() |
|
167 | - { |
|
168 | - return apply_filters( |
|
169 | - 'FHEE__EEM_Transaction__txn_status_array', |
|
170 | - [ |
|
171 | - EEM_Transaction::overpaid_status_code, |
|
172 | - EEM_Transaction::complete_status_code, |
|
173 | - EEM_Transaction::incomplete_status_code, |
|
174 | - EEM_Transaction::abandoned_status_code, |
|
175 | - EEM_Transaction::failed_status_code, |
|
176 | - ] |
|
177 | - ); |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * get the revenue per day for the Transaction Admin page Reports Tab |
|
183 | - * |
|
184 | - * @access public |
|
185 | - * |
|
186 | - * @param string $period |
|
187 | - * |
|
188 | - * @return stdClass[] |
|
189 | - * @throws EE_Error |
|
190 | - * @throws EE_Error |
|
191 | - */ |
|
192 | - public function get_revenue_per_day_report($period = '-1 month') |
|
193 | - { |
|
194 | - $sql_date = $this->convert_datetime_for_query( |
|
195 | - 'TXN_timestamp', |
|
196 | - date('Y-m-d H:i:s', strtotime($period)), |
|
197 | - 'Y-m-d H:i:s', |
|
198 | - 'UTC' |
|
199 | - ); |
|
200 | - |
|
201 | - $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'TXN_timestamp'); |
|
202 | - |
|
203 | - return $this->_get_all_wpdb_results( |
|
204 | - [ |
|
205 | - [ |
|
206 | - 'TXN_timestamp' => ['>=', $sql_date], |
|
207 | - ], |
|
208 | - 'group_by' => 'txnDate', |
|
209 | - 'order_by' => ['TXN_timestamp' => 'ASC'], |
|
210 | - ], |
|
211 | - OBJECT, |
|
212 | - [ |
|
213 | - 'txnDate' => ['DATE(' . $query_interval . ')', '%s'], |
|
214 | - 'revenue' => ['SUM(TransactionTable.TXN_paid)', '%d'], |
|
215 | - ] |
|
216 | - ); |
|
217 | - } |
|
218 | - |
|
219 | - |
|
220 | - /** |
|
221 | - * get the revenue per event for the Transaction Admin page Reports Tab |
|
222 | - * |
|
223 | - * @access public |
|
224 | - * |
|
225 | - * @param string $period |
|
226 | - * |
|
227 | - * @return EE_Transaction[] |
|
228 | - */ |
|
229 | - public function get_revenue_per_event_report($period = '-1 month') |
|
230 | - { |
|
231 | - global $wpdb; |
|
232 | - $transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
233 | - $registration_table = $wpdb->prefix . 'esp_registration'; |
|
234 | - $registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; |
|
235 | - $event_table = $wpdb->posts; |
|
236 | - $payment_table = $wpdb->prefix . 'esp_payment'; |
|
237 | - $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
|
238 | - $approved_payment_status = EEM_Payment::status_id_approved; |
|
239 | - $extra_event_on_join = ''; |
|
240 | - // exclude events not authored by user if permissions in effect |
|
241 | - if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
242 | - $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id(); |
|
243 | - } |
|
244 | - |
|
245 | - return $wpdb->get_results( |
|
246 | - "SELECT |
|
22 | + // private instance of the Transaction object |
|
23 | + protected static $_instance; |
|
24 | + |
|
25 | + /** |
|
26 | + * Status ID(STS_ID on esp_status table) to indicate the transaction is complete, |
|
27 | + * but payment is pending. This is the state for transactions where payment is promised |
|
28 | + * from an offline gateway. |
|
29 | + */ |
|
30 | + // const open_status_code = 'TPN'; |
|
31 | + |
|
32 | + /** |
|
33 | + * Status ID(STS_ID on esp_status table) to indicate the transaction failed, |
|
34 | + * either due to a technical reason (server or computer crash during registration), |
|
35 | + * or some other reason that prevent the collection of any useful contact information from any of the registrants |
|
36 | + */ |
|
37 | + const failed_status_code = 'TFL'; |
|
38 | + |
|
39 | + /** |
|
40 | + * Status ID(STS_ID on esp_status table) to indicate the transaction was abandoned, |
|
41 | + * either due to a technical reason (server or computer crash during registration), |
|
42 | + * or due to an abandoned cart after registrant chose not to complete the registration process |
|
43 | + * HOWEVER... |
|
44 | + * an abandoned TXN differs from a failed TXN in that it was able to capture contact information for at least one |
|
45 | + * registrant |
|
46 | + */ |
|
47 | + const abandoned_status_code = 'TAB'; |
|
48 | + |
|
49 | + /** |
|
50 | + * Status ID(STS_ID on esp_status table) to indicate an incomplete transaction, |
|
51 | + * meaning that monies are still owing: TXN_paid < TXN_total |
|
52 | + */ |
|
53 | + const incomplete_status_code = 'TIN'; |
|
54 | + |
|
55 | + /** |
|
56 | + * Status ID (STS_ID on esp_status table) to indicate a complete transaction. |
|
57 | + * meaning that NO monies are owing: TXN_paid == TXN_total |
|
58 | + */ |
|
59 | + const complete_status_code = 'TCM'; |
|
60 | + |
|
61 | + /** |
|
62 | + * Status ID(STS_ID on esp_status table) to indicate the transaction is overpaid. |
|
63 | + * This is the same as complete, but site admins actually owe clients the moneys! TXN_paid > TXN_total |
|
64 | + */ |
|
65 | + const overpaid_status_code = 'TOP'; |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * private constructor to prevent direct creation |
|
70 | + * |
|
71 | + * @Constructor |
|
72 | + * @access protected |
|
73 | + * |
|
74 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any |
|
75 | + * incoming timezone data that gets saved). Note this just sends the timezone info to the |
|
76 | + * date time model field objects. Default is NULL (and will be assumed using the set |
|
77 | + * timezone in the 'timezone_string' wp option) |
|
78 | + * |
|
79 | + * @throws EE_Error |
|
80 | + */ |
|
81 | + protected function __construct($timezone) |
|
82 | + { |
|
83 | + $this->singular_item = esc_html__('Transaction', 'event_espresso'); |
|
84 | + $this->plural_item = esc_html__('Transactions', 'event_espresso'); |
|
85 | + |
|
86 | + $this->_tables = [ |
|
87 | + 'TransactionTable' => new EE_Primary_Table('esp_transaction', 'TXN_ID'), |
|
88 | + ]; |
|
89 | + $this->_fields = [ |
|
90 | + 'TransactionTable' => [ |
|
91 | + 'TXN_ID' => new EE_Primary_Key_Int_Field('TXN_ID', esc_html__('Transaction ID', 'event_espresso')), |
|
92 | + 'TXN_timestamp' => new EE_Datetime_Field( |
|
93 | + 'TXN_timestamp', |
|
94 | + esc_html__('date when transaction was created', 'event_espresso'), |
|
95 | + false, |
|
96 | + EE_Datetime_Field::now, |
|
97 | + $timezone |
|
98 | + ), |
|
99 | + 'TXN_total' => new EE_Money_Field( |
|
100 | + 'TXN_total', |
|
101 | + esc_html__('Total value of Transaction', 'event_espresso'), |
|
102 | + false, |
|
103 | + 0 |
|
104 | + ), |
|
105 | + 'TXN_paid' => new EE_Money_Field( |
|
106 | + 'TXN_paid', |
|
107 | + esc_html__('Amount paid towards transaction to date', 'event_espresso'), |
|
108 | + false, |
|
109 | + 0 |
|
110 | + ), |
|
111 | + 'STS_ID' => new EE_Foreign_Key_String_Field( |
|
112 | + 'STS_ID', |
|
113 | + esc_html__('Status ID', 'event_espresso'), |
|
114 | + false, |
|
115 | + EEM_Transaction::failed_status_code, |
|
116 | + 'Status' |
|
117 | + ), |
|
118 | + 'TXN_session_data' => new EE_Serialized_Text_Field( |
|
119 | + 'TXN_session_data', |
|
120 | + esc_html__('Serialized session data', 'event_espresso'), |
|
121 | + true, |
|
122 | + '' |
|
123 | + ), |
|
124 | + 'TXN_hash_salt' => new EE_Plain_Text_Field( |
|
125 | + 'TXN_hash_salt', |
|
126 | + esc_html__('Transaction Hash Salt', 'event_espresso'), |
|
127 | + true, |
|
128 | + '' |
|
129 | + ), |
|
130 | + 'PMD_ID' => new EE_Foreign_Key_Int_Field( |
|
131 | + 'PMD_ID', |
|
132 | + esc_html__("Last Used Payment Method", 'event_espresso'), |
|
133 | + true, |
|
134 | + null, |
|
135 | + 'Payment_Method' |
|
136 | + ), |
|
137 | + 'TXN_reg_steps' => new EE_Serialized_Text_Field( |
|
138 | + 'TXN_reg_steps', |
|
139 | + esc_html__('Registration Steps', 'event_espresso'), |
|
140 | + false, |
|
141 | + [] |
|
142 | + ), |
|
143 | + ], |
|
144 | + ]; |
|
145 | + $this->_model_relations = [ |
|
146 | + 'Registration' => new EE_Has_Many_Relation(), |
|
147 | + 'Payment' => new EE_Has_Many_Relation(), |
|
148 | + 'Status' => new EE_Belongs_To_Relation(), |
|
149 | + 'Line_Item' => new EE_Has_Many_Relation(false), |
|
150 | + // you can delete a transaction without needing to delete its line items |
|
151 | + 'Payment_Method' => new EE_Belongs_To_Relation(), |
|
152 | + 'Message' => new EE_Has_Many_Relation(), |
|
153 | + ]; |
|
154 | + $this->_model_chain_to_wp_user = 'Registration.Event'; |
|
155 | + parent::__construct($timezone); |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * txn_status_array |
|
161 | + * get list of transaction statuses |
|
162 | + * |
|
163 | + * @access public |
|
164 | + * @return array |
|
165 | + */ |
|
166 | + public static function txn_status_array() |
|
167 | + { |
|
168 | + return apply_filters( |
|
169 | + 'FHEE__EEM_Transaction__txn_status_array', |
|
170 | + [ |
|
171 | + EEM_Transaction::overpaid_status_code, |
|
172 | + EEM_Transaction::complete_status_code, |
|
173 | + EEM_Transaction::incomplete_status_code, |
|
174 | + EEM_Transaction::abandoned_status_code, |
|
175 | + EEM_Transaction::failed_status_code, |
|
176 | + ] |
|
177 | + ); |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * get the revenue per day for the Transaction Admin page Reports Tab |
|
183 | + * |
|
184 | + * @access public |
|
185 | + * |
|
186 | + * @param string $period |
|
187 | + * |
|
188 | + * @return stdClass[] |
|
189 | + * @throws EE_Error |
|
190 | + * @throws EE_Error |
|
191 | + */ |
|
192 | + public function get_revenue_per_day_report($period = '-1 month') |
|
193 | + { |
|
194 | + $sql_date = $this->convert_datetime_for_query( |
|
195 | + 'TXN_timestamp', |
|
196 | + date('Y-m-d H:i:s', strtotime($period)), |
|
197 | + 'Y-m-d H:i:s', |
|
198 | + 'UTC' |
|
199 | + ); |
|
200 | + |
|
201 | + $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'TXN_timestamp'); |
|
202 | + |
|
203 | + return $this->_get_all_wpdb_results( |
|
204 | + [ |
|
205 | + [ |
|
206 | + 'TXN_timestamp' => ['>=', $sql_date], |
|
207 | + ], |
|
208 | + 'group_by' => 'txnDate', |
|
209 | + 'order_by' => ['TXN_timestamp' => 'ASC'], |
|
210 | + ], |
|
211 | + OBJECT, |
|
212 | + [ |
|
213 | + 'txnDate' => ['DATE(' . $query_interval . ')', '%s'], |
|
214 | + 'revenue' => ['SUM(TransactionTable.TXN_paid)', '%d'], |
|
215 | + ] |
|
216 | + ); |
|
217 | + } |
|
218 | + |
|
219 | + |
|
220 | + /** |
|
221 | + * get the revenue per event for the Transaction Admin page Reports Tab |
|
222 | + * |
|
223 | + * @access public |
|
224 | + * |
|
225 | + * @param string $period |
|
226 | + * |
|
227 | + * @return EE_Transaction[] |
|
228 | + */ |
|
229 | + public function get_revenue_per_event_report($period = '-1 month') |
|
230 | + { |
|
231 | + global $wpdb; |
|
232 | + $transaction_table = $wpdb->prefix . 'esp_transaction'; |
|
233 | + $registration_table = $wpdb->prefix . 'esp_registration'; |
|
234 | + $registration_payment_table = $wpdb->prefix . 'esp_registration_payment'; |
|
235 | + $event_table = $wpdb->posts; |
|
236 | + $payment_table = $wpdb->prefix . 'esp_payment'; |
|
237 | + $sql_date = date('Y-m-d H:i:s', strtotime($period)); |
|
238 | + $approved_payment_status = EEM_Payment::status_id_approved; |
|
239 | + $extra_event_on_join = ''; |
|
240 | + // exclude events not authored by user if permissions in effect |
|
241 | + if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) { |
|
242 | + $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id(); |
|
243 | + } |
|
244 | + |
|
245 | + return $wpdb->get_results( |
|
246 | + "SELECT |
|
247 | 247 | Transaction_Event.event_name AS event_name, |
248 | 248 | SUM(Transaction_Event.paid) AS revenue |
249 | 249 | FROM |
@@ -271,236 +271,236 @@ discard block |
||
271 | 271 | $extra_event_on_join |
272 | 272 | ) AS Transaction_Event |
273 | 273 | GROUP BY event_name" |
274 | - ); |
|
275 | - } |
|
276 | - |
|
277 | - |
|
278 | - /** |
|
279 | - * Gets the current transaction given the reg_url_link, or assumes the reg_url_link is in the |
|
280 | - * request global variable. Either way, tries to find the current transaction (through |
|
281 | - * the registration pointed to by reg_url_link), if not returns null |
|
282 | - * |
|
283 | - * @param string $reg_url_link |
|
284 | - * |
|
285 | - * @return EE_Transaction |
|
286 | - * @throws EE_Error |
|
287 | - */ |
|
288 | - public function get_transaction_from_reg_url_link($reg_url_link = '') |
|
289 | - { |
|
290 | - if (empty($reg_url_link)) { |
|
291 | - $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
292 | - $reg_url_link = $request->getRequestParam('e_reg_url_link'); |
|
293 | - } |
|
294 | - return $this->get_one( |
|
295 | - [ |
|
296 | - [ |
|
297 | - 'Registration.REG_url_link' => $reg_url_link, |
|
298 | - ], |
|
299 | - ] |
|
300 | - ); |
|
301 | - } |
|
302 | - |
|
303 | - |
|
304 | - /** |
|
305 | - * Updates the provided EE_Transaction with all the applicable payments |
|
306 | - * (or fetch the EE_Transaction from its ID) |
|
307 | - * |
|
308 | - * @param EE_Transaction|int $transaction_obj_or_id |
|
309 | - * @param boolean $save_txn whether or not to save the transaction during this function call |
|
310 | - * |
|
311 | - * @return array |
|
312 | - * @throws EE_Error |
|
313 | - * @throws ReflectionException |
|
314 | - * @deprecated |
|
315 | - * |
|
316 | - */ |
|
317 | - public function update_based_on_payments($transaction_obj_or_id, $save_txn = true) |
|
318 | - { |
|
319 | - EE_Error::doing_it_wrong( |
|
320 | - __CLASS__ . '::' . __FUNCTION__, |
|
321 | - sprintf( |
|
322 | - esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
323 | - 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()' |
|
324 | - ), |
|
325 | - '4.6.0' |
|
326 | - ); |
|
327 | - /** @type EE_Transaction_Processor $transaction_processor */ |
|
328 | - $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
329 | - |
|
330 | - return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
|
331 | - $this->ensure_is_obj($transaction_obj_or_id) |
|
332 | - ); |
|
333 | - } |
|
334 | - |
|
335 | - |
|
336 | - /** |
|
337 | - * Deletes "junk" transactions that were probably added by bots. There might be TONS |
|
338 | - * of these, so we are very careful to NOT select (which the models do even when deleting), |
|
339 | - * and so we only use wpdb directly and only do minimal joins. |
|
340 | - * Transactions are considered "junk" if they're failed for longer than a week. |
|
341 | - * Also, there is an extra check for payments related to the transaction, because if a transaction has a payment on |
|
342 | - * it, it's probably not junk (regardless of what status it has). |
|
343 | - * The downside to this approach is that is addons are listening for object deletions |
|
344 | - * on EEM_Base::delete() they won't be notified of this. However, there is an action that plugins can hook into |
|
345 | - * to catch these types of deletions. |
|
346 | - * |
|
347 | - * @return int |
|
348 | - * @throws EE_Error |
|
349 | - * @throws EE_Error |
|
350 | - * @global WPDB $wpdb |
|
351 | - */ |
|
352 | - public function delete_junk_transactions() |
|
353 | - { |
|
354 | - global $wpdb; |
|
355 | - $deleted = false; |
|
356 | - $time_to_leave_alone = (int) apply_filters( |
|
357 | - 'FHEE__EEM_Transaction__delete_junk_transactions__time_to_leave_alone', |
|
358 | - WEEK_IN_SECONDS |
|
359 | - ); |
|
360 | - |
|
361 | - |
|
362 | - /** |
|
363 | - * This allows code to filter the query arguments used for retrieving the transaction IDs to delete. |
|
364 | - * Useful for plugins that want to exclude transactions matching certain query parameters. |
|
365 | - * The query parameters should be in the format accepted by the EEM_Base model queries. |
|
366 | - */ |
|
367 | - $ids_query = apply_filters( |
|
368 | - 'FHEE__EEM_Transaction__delete_junk_transactions__initial_query_args', |
|
369 | - [ |
|
370 | - 0 => [ |
|
371 | - 'STS_ID' => EEM_Transaction::failed_status_code, |
|
372 | - 'Payment.PAY_ID' => ['IS NULL'], |
|
373 | - 'TXN_timestamp' => ['<', time() - $time_to_leave_alone], |
|
374 | - ], |
|
375 | - 'order_by' => ['TXN_timestamp' => 'ASC'], |
|
376 | - 'limit' => 1000, |
|
377 | - ], |
|
378 | - $time_to_leave_alone |
|
379 | - ); |
|
380 | - |
|
381 | - |
|
382 | - /** |
|
383 | - * This filter is for when code needs to filter the list of transaction ids that represent transactions |
|
384 | - * about to be deleted based on some other criteria that isn't easily done via the query args filter. |
|
385 | - */ |
|
386 | - $txn_ids = apply_filters( |
|
387 | - 'FHEE__EEM_Transaction__delete_junk_transactions__transaction_ids_to_delete', |
|
388 | - EEM_Transaction::instance()->get_col($ids_query, 'TXN_ID'), |
|
389 | - $time_to_leave_alone |
|
390 | - ); |
|
391 | - // now that we have the ids to delete |
|
392 | - if (! empty($txn_ids) && is_array($txn_ids)) { |
|
393 | - // first, make sure these TXN's are removed the "ee_locked_transactions" array |
|
394 | - EEM_Transaction::unset_locked_transactions($txn_ids); |
|
395 | - |
|
396 | - // Create IDs placeholder. |
|
397 | - $placeholders = array_fill(0, count($txn_ids), '%d'); |
|
398 | - |
|
399 | - // Glue it together to use inside $wpdb->prepare. |
|
400 | - $format = implode(', ', $placeholders); |
|
401 | - |
|
402 | - // let's get deleting... |
|
403 | - // We got the ids from the original query to get them FROM |
|
404 | - // the db (which is sanitized) so no need to prepare them again. |
|
405 | - $query = $wpdb->prepare("DELETE FROM " . $this->table() . " WHERE TXN_ID IN ( $format )", $txn_ids); |
|
406 | - $deleted = $wpdb->query($query); |
|
407 | - } |
|
408 | - if ($deleted) { |
|
409 | - /** |
|
410 | - * Allows code to do something after the transactions have been deleted. |
|
411 | - */ |
|
412 | - do_action('AHEE__EEM_Transaction__delete_junk_transactions__successful_deletion', $txn_ids); |
|
413 | - } |
|
414 | - |
|
415 | - return $deleted; |
|
416 | - } |
|
417 | - |
|
418 | - |
|
419 | - /** |
|
420 | - * @param array $transaction_IDs |
|
421 | - * |
|
422 | - * @return bool |
|
423 | - */ |
|
424 | - public static function unset_locked_transactions(array $transaction_IDs) |
|
425 | - { |
|
426 | - $locked_transactions = get_option('ee_locked_transactions', []); |
|
427 | - $update = false; |
|
428 | - foreach ($transaction_IDs as $TXN_ID) { |
|
429 | - if (isset($locked_transactions[ $TXN_ID ])) { |
|
430 | - unset($locked_transactions[ $TXN_ID ]); |
|
431 | - $update = true; |
|
432 | - } |
|
433 | - } |
|
434 | - if ($update) { |
|
435 | - update_option('ee_locked_transactions', $locked_transactions); |
|
436 | - } |
|
437 | - |
|
438 | - return $update; |
|
439 | - } |
|
440 | - |
|
441 | - |
|
442 | - /** |
|
443 | - * returns an array of EE_Transaction objects whose timestamp is greater than |
|
444 | - * the current time minus the session lifespan, which defaults to 60 minutes |
|
445 | - * |
|
446 | - * @return EE_Base_Class[]|EE_Transaction[] |
|
447 | - * @throws EE_Error |
|
448 | - * @throws InvalidArgumentException |
|
449 | - * @throws InvalidDataTypeException |
|
450 | - * @throws InvalidInterfaceException |
|
451 | - */ |
|
452 | - public function get_transactions_in_progress() |
|
453 | - { |
|
454 | - return $this->_get_transactions_in_progress(); |
|
455 | - } |
|
456 | - |
|
457 | - |
|
458 | - /** |
|
459 | - * returns an array of EE_Transaction objects whose timestamp is less than |
|
460 | - * the current time minus the session lifespan, which defaults to 60 minutes |
|
461 | - * |
|
462 | - * @return EE_Base_Class[]|EE_Transaction[] |
|
463 | - * @throws EE_Error |
|
464 | - * @throws InvalidArgumentException |
|
465 | - * @throws InvalidDataTypeException |
|
466 | - * @throws InvalidInterfaceException |
|
467 | - */ |
|
468 | - public function get_transactions_not_in_progress() |
|
469 | - { |
|
470 | - return $this->_get_transactions_in_progress('<='); |
|
471 | - } |
|
472 | - |
|
473 | - |
|
474 | - /** |
|
475 | - * @param string $comparison |
|
476 | - * @return EE_Transaction[] |
|
477 | - * @throws EE_Error |
|
478 | - * @throws InvalidArgumentException |
|
479 | - * @throws InvalidDataTypeException |
|
480 | - * @throws InvalidInterfaceException |
|
481 | - */ |
|
482 | - private function _get_transactions_in_progress($comparison = '>=') |
|
483 | - { |
|
484 | - $comparison = $comparison === '>=' || $comparison === '<=' |
|
485 | - ? $comparison |
|
486 | - : '>='; |
|
487 | - /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
488 | - $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
489 | - 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
490 | - ); |
|
491 | - return $this->get_all( |
|
492 | - [ |
|
493 | - [ |
|
494 | - 'TXN_timestamp' => [ |
|
495 | - $comparison, |
|
496 | - $session_lifespan->expiration(), |
|
497 | - ], |
|
498 | - 'STS_ID' => [ |
|
499 | - '!=', |
|
500 | - EEM_Transaction::complete_status_code, |
|
501 | - ], |
|
502 | - ], |
|
503 | - ] |
|
504 | - ); |
|
505 | - } |
|
274 | + ); |
|
275 | + } |
|
276 | + |
|
277 | + |
|
278 | + /** |
|
279 | + * Gets the current transaction given the reg_url_link, or assumes the reg_url_link is in the |
|
280 | + * request global variable. Either way, tries to find the current transaction (through |
|
281 | + * the registration pointed to by reg_url_link), if not returns null |
|
282 | + * |
|
283 | + * @param string $reg_url_link |
|
284 | + * |
|
285 | + * @return EE_Transaction |
|
286 | + * @throws EE_Error |
|
287 | + */ |
|
288 | + public function get_transaction_from_reg_url_link($reg_url_link = '') |
|
289 | + { |
|
290 | + if (empty($reg_url_link)) { |
|
291 | + $request = LoaderFactory::getLoader()->getShared(RequestInterface::class); |
|
292 | + $reg_url_link = $request->getRequestParam('e_reg_url_link'); |
|
293 | + } |
|
294 | + return $this->get_one( |
|
295 | + [ |
|
296 | + [ |
|
297 | + 'Registration.REG_url_link' => $reg_url_link, |
|
298 | + ], |
|
299 | + ] |
|
300 | + ); |
|
301 | + } |
|
302 | + |
|
303 | + |
|
304 | + /** |
|
305 | + * Updates the provided EE_Transaction with all the applicable payments |
|
306 | + * (or fetch the EE_Transaction from its ID) |
|
307 | + * |
|
308 | + * @param EE_Transaction|int $transaction_obj_or_id |
|
309 | + * @param boolean $save_txn whether or not to save the transaction during this function call |
|
310 | + * |
|
311 | + * @return array |
|
312 | + * @throws EE_Error |
|
313 | + * @throws ReflectionException |
|
314 | + * @deprecated |
|
315 | + * |
|
316 | + */ |
|
317 | + public function update_based_on_payments($transaction_obj_or_id, $save_txn = true) |
|
318 | + { |
|
319 | + EE_Error::doing_it_wrong( |
|
320 | + __CLASS__ . '::' . __FUNCTION__, |
|
321 | + sprintf( |
|
322 | + esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'), |
|
323 | + 'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()' |
|
324 | + ), |
|
325 | + '4.6.0' |
|
326 | + ); |
|
327 | + /** @type EE_Transaction_Processor $transaction_processor */ |
|
328 | + $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor'); |
|
329 | + |
|
330 | + return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment( |
|
331 | + $this->ensure_is_obj($transaction_obj_or_id) |
|
332 | + ); |
|
333 | + } |
|
334 | + |
|
335 | + |
|
336 | + /** |
|
337 | + * Deletes "junk" transactions that were probably added by bots. There might be TONS |
|
338 | + * of these, so we are very careful to NOT select (which the models do even when deleting), |
|
339 | + * and so we only use wpdb directly and only do minimal joins. |
|
340 | + * Transactions are considered "junk" if they're failed for longer than a week. |
|
341 | + * Also, there is an extra check for payments related to the transaction, because if a transaction has a payment on |
|
342 | + * it, it's probably not junk (regardless of what status it has). |
|
343 | + * The downside to this approach is that is addons are listening for object deletions |
|
344 | + * on EEM_Base::delete() they won't be notified of this. However, there is an action that plugins can hook into |
|
345 | + * to catch these types of deletions. |
|
346 | + * |
|
347 | + * @return int |
|
348 | + * @throws EE_Error |
|
349 | + * @throws EE_Error |
|
350 | + * @global WPDB $wpdb |
|
351 | + */ |
|
352 | + public function delete_junk_transactions() |
|
353 | + { |
|
354 | + global $wpdb; |
|
355 | + $deleted = false; |
|
356 | + $time_to_leave_alone = (int) apply_filters( |
|
357 | + 'FHEE__EEM_Transaction__delete_junk_transactions__time_to_leave_alone', |
|
358 | + WEEK_IN_SECONDS |
|
359 | + ); |
|
360 | + |
|
361 | + |
|
362 | + /** |
|
363 | + * This allows code to filter the query arguments used for retrieving the transaction IDs to delete. |
|
364 | + * Useful for plugins that want to exclude transactions matching certain query parameters. |
|
365 | + * The query parameters should be in the format accepted by the EEM_Base model queries. |
|
366 | + */ |
|
367 | + $ids_query = apply_filters( |
|
368 | + 'FHEE__EEM_Transaction__delete_junk_transactions__initial_query_args', |
|
369 | + [ |
|
370 | + 0 => [ |
|
371 | + 'STS_ID' => EEM_Transaction::failed_status_code, |
|
372 | + 'Payment.PAY_ID' => ['IS NULL'], |
|
373 | + 'TXN_timestamp' => ['<', time() - $time_to_leave_alone], |
|
374 | + ], |
|
375 | + 'order_by' => ['TXN_timestamp' => 'ASC'], |
|
376 | + 'limit' => 1000, |
|
377 | + ], |
|
378 | + $time_to_leave_alone |
|
379 | + ); |
|
380 | + |
|
381 | + |
|
382 | + /** |
|
383 | + * This filter is for when code needs to filter the list of transaction ids that represent transactions |
|
384 | + * about to be deleted based on some other criteria that isn't easily done via the query args filter. |
|
385 | + */ |
|
386 | + $txn_ids = apply_filters( |
|
387 | + 'FHEE__EEM_Transaction__delete_junk_transactions__transaction_ids_to_delete', |
|
388 | + EEM_Transaction::instance()->get_col($ids_query, 'TXN_ID'), |
|
389 | + $time_to_leave_alone |
|
390 | + ); |
|
391 | + // now that we have the ids to delete |
|
392 | + if (! empty($txn_ids) && is_array($txn_ids)) { |
|
393 | + // first, make sure these TXN's are removed the "ee_locked_transactions" array |
|
394 | + EEM_Transaction::unset_locked_transactions($txn_ids); |
|
395 | + |
|
396 | + // Create IDs placeholder. |
|
397 | + $placeholders = array_fill(0, count($txn_ids), '%d'); |
|
398 | + |
|
399 | + // Glue it together to use inside $wpdb->prepare. |
|
400 | + $format = implode(', ', $placeholders); |
|
401 | + |
|
402 | + // let's get deleting... |
|
403 | + // We got the ids from the original query to get them FROM |
|
404 | + // the db (which is sanitized) so no need to prepare them again. |
|
405 | + $query = $wpdb->prepare("DELETE FROM " . $this->table() . " WHERE TXN_ID IN ( $format )", $txn_ids); |
|
406 | + $deleted = $wpdb->query($query); |
|
407 | + } |
|
408 | + if ($deleted) { |
|
409 | + /** |
|
410 | + * Allows code to do something after the transactions have been deleted. |
|
411 | + */ |
|
412 | + do_action('AHEE__EEM_Transaction__delete_junk_transactions__successful_deletion', $txn_ids); |
|
413 | + } |
|
414 | + |
|
415 | + return $deleted; |
|
416 | + } |
|
417 | + |
|
418 | + |
|
419 | + /** |
|
420 | + * @param array $transaction_IDs |
|
421 | + * |
|
422 | + * @return bool |
|
423 | + */ |
|
424 | + public static function unset_locked_transactions(array $transaction_IDs) |
|
425 | + { |
|
426 | + $locked_transactions = get_option('ee_locked_transactions', []); |
|
427 | + $update = false; |
|
428 | + foreach ($transaction_IDs as $TXN_ID) { |
|
429 | + if (isset($locked_transactions[ $TXN_ID ])) { |
|
430 | + unset($locked_transactions[ $TXN_ID ]); |
|
431 | + $update = true; |
|
432 | + } |
|
433 | + } |
|
434 | + if ($update) { |
|
435 | + update_option('ee_locked_transactions', $locked_transactions); |
|
436 | + } |
|
437 | + |
|
438 | + return $update; |
|
439 | + } |
|
440 | + |
|
441 | + |
|
442 | + /** |
|
443 | + * returns an array of EE_Transaction objects whose timestamp is greater than |
|
444 | + * the current time minus the session lifespan, which defaults to 60 minutes |
|
445 | + * |
|
446 | + * @return EE_Base_Class[]|EE_Transaction[] |
|
447 | + * @throws EE_Error |
|
448 | + * @throws InvalidArgumentException |
|
449 | + * @throws InvalidDataTypeException |
|
450 | + * @throws InvalidInterfaceException |
|
451 | + */ |
|
452 | + public function get_transactions_in_progress() |
|
453 | + { |
|
454 | + return $this->_get_transactions_in_progress(); |
|
455 | + } |
|
456 | + |
|
457 | + |
|
458 | + /** |
|
459 | + * returns an array of EE_Transaction objects whose timestamp is less than |
|
460 | + * the current time minus the session lifespan, which defaults to 60 minutes |
|
461 | + * |
|
462 | + * @return EE_Base_Class[]|EE_Transaction[] |
|
463 | + * @throws EE_Error |
|
464 | + * @throws InvalidArgumentException |
|
465 | + * @throws InvalidDataTypeException |
|
466 | + * @throws InvalidInterfaceException |
|
467 | + */ |
|
468 | + public function get_transactions_not_in_progress() |
|
469 | + { |
|
470 | + return $this->_get_transactions_in_progress('<='); |
|
471 | + } |
|
472 | + |
|
473 | + |
|
474 | + /** |
|
475 | + * @param string $comparison |
|
476 | + * @return EE_Transaction[] |
|
477 | + * @throws EE_Error |
|
478 | + * @throws InvalidArgumentException |
|
479 | + * @throws InvalidDataTypeException |
|
480 | + * @throws InvalidInterfaceException |
|
481 | + */ |
|
482 | + private function _get_transactions_in_progress($comparison = '>=') |
|
483 | + { |
|
484 | + $comparison = $comparison === '>=' || $comparison === '<=' |
|
485 | + ? $comparison |
|
486 | + : '>='; |
|
487 | + /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
488 | + $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
489 | + 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
490 | + ); |
|
491 | + return $this->get_all( |
|
492 | + [ |
|
493 | + [ |
|
494 | + 'TXN_timestamp' => [ |
|
495 | + $comparison, |
|
496 | + $session_lifespan->expiration(), |
|
497 | + ], |
|
498 | + 'STS_ID' => [ |
|
499 | + '!=', |
|
500 | + EEM_Transaction::complete_status_code, |
|
501 | + ], |
|
502 | + ], |
|
503 | + ] |
|
504 | + ); |
|
505 | + } |
|
506 | 506 | } |
@@ -23,32 +23,32 @@ |
||
23 | 23 | */ |
24 | 24 | class EEM_Extra_Join extends EEM_Base |
25 | 25 | { |
26 | - // private instance of the Extra Join object |
|
27 | - protected static $_instance = null; |
|
26 | + // private instance of the Extra Join object |
|
27 | + protected static $_instance = null; |
|
28 | 28 | |
29 | - public function __construct($timezone = null) |
|
30 | - { |
|
31 | - $models_this_can_join = array_keys(EE_Registry::instance()->non_abstract_db_models); |
|
32 | - $this->_tables = array( |
|
33 | - 'Extra_Join' => new EE_Primary_Table('esp_extra_join', 'EXJ_ID'), |
|
34 | - ); |
|
35 | - $this->_fields = array( |
|
36 | - 'Extra_Join' => array( |
|
37 | - 'EXJ_ID' => new EE_Primary_Key_Int_Field('EXJ_ID', esc_html__('Extra Join ID', 'event_espresso')), |
|
38 | - 'EXJ_first_model_ID' => new EE_Foreign_Key_String_Field('EXJ_first_model_ID', esc_html__('First Model ID', 'event_espresso'), true, 0, $models_this_can_join), |
|
39 | - 'EXJ_first_model_name' => new EE_Any_Foreign_Model_Name_Field('EXJ_first_model_name', esc_html__('First Model Name', 'event_espresso'), true, '', $models_this_can_join), |
|
40 | - 'EXJ_second_model_ID' => new EE_Foreign_Key_String_Field('EXJ_second_model_ID', esc_html__('Second Model ID', 'event_espresso'), true, 0, $models_this_can_join), |
|
41 | - 'EXJ_second_model_name' => new EE_Any_Foreign_Model_Name_Field('EXJ_second_model_name', esc_html__('Second Model Name', 'event_espresso'), true, '', $models_this_can_join), |
|
29 | + public function __construct($timezone = null) |
|
30 | + { |
|
31 | + $models_this_can_join = array_keys(EE_Registry::instance()->non_abstract_db_models); |
|
32 | + $this->_tables = array( |
|
33 | + 'Extra_Join' => new EE_Primary_Table('esp_extra_join', 'EXJ_ID'), |
|
34 | + ); |
|
35 | + $this->_fields = array( |
|
36 | + 'Extra_Join' => array( |
|
37 | + 'EXJ_ID' => new EE_Primary_Key_Int_Field('EXJ_ID', esc_html__('Extra Join ID', 'event_espresso')), |
|
38 | + 'EXJ_first_model_ID' => new EE_Foreign_Key_String_Field('EXJ_first_model_ID', esc_html__('First Model ID', 'event_espresso'), true, 0, $models_this_can_join), |
|
39 | + 'EXJ_first_model_name' => new EE_Any_Foreign_Model_Name_Field('EXJ_first_model_name', esc_html__('First Model Name', 'event_espresso'), true, '', $models_this_can_join), |
|
40 | + 'EXJ_second_model_ID' => new EE_Foreign_Key_String_Field('EXJ_second_model_ID', esc_html__('Second Model ID', 'event_espresso'), true, 0, $models_this_can_join), |
|
41 | + 'EXJ_second_model_name' => new EE_Any_Foreign_Model_Name_Field('EXJ_second_model_name', esc_html__('Second Model Name', 'event_espresso'), true, '', $models_this_can_join), |
|
42 | 42 | |
43 | - ) |
|
44 | - ); |
|
45 | - // this model is weird in that it has two foreign key columns which can point to any model/table. |
|
46 | - // eg a foreign key to event will be in "EXJ_first_model_ID", provided the other |
|
47 | - // model linked to is alphabetically greater than event (eg venue). |
|
48 | - // but if the model linked to is alphabetically lower (eg attendee), |
|
49 | - // the foreign key to the event will be in "EXJ_second_model_ID" |
|
50 | - // so normal usage of foreign keys is weird. So don't define any |
|
51 | - // relations to other models because they won't work properly with this model |
|
52 | - parent::__construct($timezone); |
|
53 | - } |
|
43 | + ) |
|
44 | + ); |
|
45 | + // this model is weird in that it has two foreign key columns which can point to any model/table. |
|
46 | + // eg a foreign key to event will be in "EXJ_first_model_ID", provided the other |
|
47 | + // model linked to is alphabetically greater than event (eg venue). |
|
48 | + // but if the model linked to is alphabetically lower (eg attendee), |
|
49 | + // the foreign key to the event will be in "EXJ_second_model_ID" |
|
50 | + // so normal usage of foreign keys is weird. So don't define any |
|
51 | + // relations to other models because they won't work properly with this model |
|
52 | + parent::__construct($timezone); |
|
53 | + } |
|
54 | 54 | } |
@@ -21,7 +21,7 @@ |
||
21 | 21 | { |
22 | 22 | |
23 | 23 | $this->singular_item = esc_html__('Registration Payment', 'event_espresso'); |
24 | - $this->plural_item = esc_html__('Registration Payments', 'event_espresso'); |
|
24 | + $this->plural_item = esc_html__('Registration Payments', 'event_espresso'); |
|
25 | 25 | |
26 | 26 | $this->_tables = array( |
27 | 27 | 'Registration_Payment' => new EE_Primary_Table('esp_registration_payment', 'RPY_ID') |
@@ -12,34 +12,34 @@ |
||
12 | 12 | */ |
13 | 13 | class EEM_Registration_Payment extends EEM_Base |
14 | 14 | { |
15 | - // private instance |
|
16 | - protected static $_instance = null; |
|
15 | + // private instance |
|
16 | + protected static $_instance = null; |
|
17 | 17 | |
18 | 18 | |
19 | - protected function __construct($timezone = null) |
|
20 | - { |
|
19 | + protected function __construct($timezone = null) |
|
20 | + { |
|
21 | 21 | |
22 | - $this->singular_item = esc_html__('Registration Payment', 'event_espresso'); |
|
23 | - $this->plural_item = esc_html__('Registration Payments', 'event_espresso'); |
|
22 | + $this->singular_item = esc_html__('Registration Payment', 'event_espresso'); |
|
23 | + $this->plural_item = esc_html__('Registration Payments', 'event_espresso'); |
|
24 | 24 | |
25 | - $this->_tables = array( |
|
26 | - 'Registration_Payment' => new EE_Primary_Table('esp_registration_payment', 'RPY_ID') |
|
27 | - ); |
|
25 | + $this->_tables = array( |
|
26 | + 'Registration_Payment' => new EE_Primary_Table('esp_registration_payment', 'RPY_ID') |
|
27 | + ); |
|
28 | 28 | |
29 | - $this->_fields = array( |
|
30 | - 'Registration_Payment' => array( |
|
31 | - 'RPY_ID' => new EE_Primary_Key_Int_Field('RPY_ID', esc_html__('Registration Payment ID', 'event_espresso')), |
|
32 | - 'REG_ID' => new EE_Foreign_Key_Int_Field('REG_ID', esc_html__('Registration ID', 'event_espresso'), false, 0, 'Registration'), |
|
33 | - 'PAY_ID' => new EE_Foreign_Key_Int_Field('PAY_ID', esc_html__('Payment ID', 'event_espresso'), true, null, 'Payment'), |
|
34 | - 'RPY_amount' => new EE_Money_Field('RPY_amount', esc_html__('Amount attributed to the registration', 'event_espresso'), false, 0), |
|
35 | - ) |
|
36 | - ); |
|
29 | + $this->_fields = array( |
|
30 | + 'Registration_Payment' => array( |
|
31 | + 'RPY_ID' => new EE_Primary_Key_Int_Field('RPY_ID', esc_html__('Registration Payment ID', 'event_espresso')), |
|
32 | + 'REG_ID' => new EE_Foreign_Key_Int_Field('REG_ID', esc_html__('Registration ID', 'event_espresso'), false, 0, 'Registration'), |
|
33 | + 'PAY_ID' => new EE_Foreign_Key_Int_Field('PAY_ID', esc_html__('Payment ID', 'event_espresso'), true, null, 'Payment'), |
|
34 | + 'RPY_amount' => new EE_Money_Field('RPY_amount', esc_html__('Amount attributed to the registration', 'event_espresso'), false, 0), |
|
35 | + ) |
|
36 | + ); |
|
37 | 37 | |
38 | - $this->_model_relations = array( |
|
39 | - 'Registration' => new EE_Belongs_To_Relation(), |
|
40 | - 'Payment' => new EE_Belongs_To_Relation(), |
|
41 | - ); |
|
38 | + $this->_model_relations = array( |
|
39 | + 'Registration' => new EE_Belongs_To_Relation(), |
|
40 | + 'Payment' => new EE_Belongs_To_Relation(), |
|
41 | + ); |
|
42 | 42 | |
43 | - parent::__construct($timezone); |
|
44 | - } |
|
43 | + parent::__construct($timezone); |
|
44 | + } |
|
45 | 45 | } |
@@ -84,63 +84,63 @@ discard block |
||
84 | 84 | } |
85 | 85 | } |
86 | 86 | // set default wp post statuses if child has not already set. |
87 | - if (! isset($this->_fields[ $primary_table_name ]['status'])) { |
|
88 | - $this->_fields[ $primary_table_name ]['status'] = new EE_WP_Post_Status_Field( |
|
87 | + if ( ! isset($this->_fields[$primary_table_name]['status'])) { |
|
88 | + $this->_fields[$primary_table_name]['status'] = new EE_WP_Post_Status_Field( |
|
89 | 89 | 'post_status', |
90 | 90 | esc_html__("Event Status", "event_espresso"), |
91 | 91 | false, |
92 | 92 | 'draft' |
93 | 93 | ); |
94 | 94 | } |
95 | - if (! isset($this->_fields[ $primary_table_name ]['to_ping'])) { |
|
96 | - $this->_fields[ $primary_table_name ]['to_ping'] = new EE_DB_Only_Text_Field( |
|
95 | + if ( ! isset($this->_fields[$primary_table_name]['to_ping'])) { |
|
96 | + $this->_fields[$primary_table_name]['to_ping'] = new EE_DB_Only_Text_Field( |
|
97 | 97 | 'to_ping', |
98 | 98 | esc_html__('To Ping', 'event_espresso'), |
99 | 99 | false, |
100 | 100 | '' |
101 | 101 | ); |
102 | 102 | } |
103 | - if (! isset($this->_fields[ $primary_table_name ]['pinged'])) { |
|
104 | - $this->_fields[ $primary_table_name ]['pinged'] = new EE_DB_Only_Text_Field( |
|
103 | + if ( ! isset($this->_fields[$primary_table_name]['pinged'])) { |
|
104 | + $this->_fields[$primary_table_name]['pinged'] = new EE_DB_Only_Text_Field( |
|
105 | 105 | 'pinged', |
106 | 106 | esc_html__('Pinged', 'event_espresso'), |
107 | 107 | false, |
108 | 108 | '' |
109 | 109 | ); |
110 | 110 | } |
111 | - if (! isset($this->_fields[ $primary_table_name ]['comment_status'])) { |
|
112 | - $this->_fields[ $primary_table_name ]['comment_status'] = new EE_Plain_Text_Field( |
|
111 | + if ( ! isset($this->_fields[$primary_table_name]['comment_status'])) { |
|
112 | + $this->_fields[$primary_table_name]['comment_status'] = new EE_Plain_Text_Field( |
|
113 | 113 | 'comment_status', |
114 | 114 | esc_html__('Comment Status', 'event_espresso'), |
115 | 115 | false, |
116 | 116 | 'open' |
117 | 117 | ); |
118 | 118 | } |
119 | - if (! isset($this->_fields[ $primary_table_name ]['ping_status'])) { |
|
120 | - $this->_fields[ $primary_table_name ]['ping_status'] = new EE_Plain_Text_Field( |
|
119 | + if ( ! isset($this->_fields[$primary_table_name]['ping_status'])) { |
|
120 | + $this->_fields[$primary_table_name]['ping_status'] = new EE_Plain_Text_Field( |
|
121 | 121 | 'ping_status', |
122 | 122 | esc_html__('Ping Status', 'event_espresso'), |
123 | 123 | false, |
124 | 124 | 'open' |
125 | 125 | ); |
126 | 126 | } |
127 | - if (! isset($this->_fields[ $primary_table_name ]['post_content_filtered'])) { |
|
128 | - $this->_fields[ $primary_table_name ]['post_content_filtered'] = new EE_DB_Only_Text_Field( |
|
127 | + if ( ! isset($this->_fields[$primary_table_name]['post_content_filtered'])) { |
|
128 | + $this->_fields[$primary_table_name]['post_content_filtered'] = new EE_DB_Only_Text_Field( |
|
129 | 129 | 'post_content_filtered', |
130 | 130 | esc_html__('Post Content Filtered', 'event_espresso'), |
131 | 131 | false, |
132 | 132 | '' |
133 | 133 | ); |
134 | 134 | } |
135 | - if (! isset($this->_model_relations['Post_Meta'])) { |
|
135 | + if ( ! isset($this->_model_relations['Post_Meta'])) { |
|
136 | 136 | // don't block deletes though because we want to maintain the current behaviour |
137 | 137 | $this->_model_relations['Post_Meta'] = new EE_Has_Many_Relation(false); |
138 | 138 | } |
139 | - if (! $this->_minimum_where_conditions_strategy instanceof EE_Default_Where_Conditions) { |
|
139 | + if ( ! $this->_minimum_where_conditions_strategy instanceof EE_Default_Where_Conditions) { |
|
140 | 140 | // nothing was set during child constructor, so set default |
141 | 141 | $this->_minimum_where_conditions_strategy = new EE_CPT_Minimum_Where_Conditions($this->post_type()); |
142 | 142 | } |
143 | - if (! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) { |
|
143 | + if ( ! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) { |
|
144 | 144 | // nothing was set during child constructor, so set default |
145 | 145 | // it's ok for child classes to specify this, but generally this is more DRY |
146 | 146 | $this->_default_where_conditions_strategy = new EE_CPT_Where_Conditions($this->post_type()); |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | protected function _alter_query_params_so_only_trashed_items_included($query_params) |
215 | 215 | { |
216 | 216 | $post_status_field_name = $this->post_status_field_name(); |
217 | - $query_params[0][ $post_status_field_name ] = self::post_status_trashed; |
|
217 | + $query_params[0][$post_status_field_name] = self::post_status_trashed; |
|
218 | 218 | return $query_params; |
219 | 219 | } |
220 | 220 | |
@@ -282,7 +282,7 @@ discard block |
||
282 | 282 | $all_fields = array_merge($this->_get_fields_for_table($alias), $all_fields); |
283 | 283 | } |
284 | 284 | } |
285 | - if (! $all) { |
|
285 | + if ( ! $all) { |
|
286 | 286 | foreach ($all_fields as $name => $obj) { |
287 | 287 | if ($obj instanceof EE_DB_Only_Field_Base) { |
288 | 288 | continue; |
@@ -314,7 +314,7 @@ discard block |
||
314 | 314 | $parent_term_taxonomy_id = null |
315 | 315 | ) { |
316 | 316 | // create term |
317 | - require_once(EE_MODELS . 'EEM_Term.model.php'); |
|
317 | + require_once(EE_MODELS.'EEM_Term.model.php'); |
|
318 | 318 | // first, check for a term by the same name or slug |
319 | 319 | $category_slug = sanitize_title($category_name); |
320 | 320 | $term = EEM_Term::instance()->get_one( |
@@ -328,7 +328,7 @@ discard block |
||
328 | 328 | ), |
329 | 329 | ) |
330 | 330 | ); |
331 | - if (! $term) { |
|
331 | + if ( ! $term) { |
|
332 | 332 | $term = EE_Term::new_instance( |
333 | 333 | array( |
334 | 334 | 'name' => $category_name, |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | $term->save(); |
339 | 339 | } |
340 | 340 | // make sure there's a term-taxonomy entry too |
341 | - require_once(EE_MODELS . 'EEM_Term_Taxonomy.model.php'); |
|
341 | + require_once(EE_MODELS.'EEM_Term_Taxonomy.model.php'); |
|
342 | 342 | $term_taxonomy = EEM_Term_Taxonomy::instance()->get_one( |
343 | 343 | array( |
344 | 344 | array( |
@@ -348,7 +348,7 @@ discard block |
||
348 | 348 | ) |
349 | 349 | ); |
350 | 350 | /** @var $term_taxonomy EE_Term_Taxonomy */ |
351 | - if (! $term_taxonomy) { |
|
351 | + if ( ! $term_taxonomy) { |
|
352 | 352 | $term_taxonomy = EE_Term_Taxonomy::new_instance( |
353 | 353 | array( |
354 | 354 | 'term_id' => $term->ID(), |
@@ -421,7 +421,7 @@ discard block |
||
421 | 421 | global $wp_post_statuses; |
422 | 422 | $statuses = array(); |
423 | 423 | foreach ($wp_post_statuses as $post_status => $args_object) { |
424 | - $statuses[ $post_status ] = $args_object->label; |
|
424 | + $statuses[$post_status] = $args_object->label; |
|
425 | 425 | } |
426 | 426 | return $statuses; |
427 | 427 | } |
@@ -438,7 +438,7 @@ discard block |
||
438 | 438 | // first the global filter |
439 | 439 | $statuses = apply_filters('FHEE_EEM_CPT_Base__get_status_array', $statuses); |
440 | 440 | // now the class specific filter |
441 | - $statuses = apply_filters('FHEE_EEM_' . get_class($this) . '__get_status_array', $statuses); |
|
441 | + $statuses = apply_filters('FHEE_EEM_'.get_class($this).'__get_status_array', $statuses); |
|
442 | 442 | return $statuses; |
443 | 443 | } |
444 | 444 | |
@@ -452,7 +452,7 @@ discard block |
||
452 | 452 | { |
453 | 453 | $new_stati = array(); |
454 | 454 | foreach ($this->_custom_stati as $status => $props) { |
455 | - $new_stati[ $status ] = $props['label']; |
|
455 | + $new_stati[$status] = $props['label']; |
|
456 | 456 | } |
457 | 457 | return $new_stati; |
458 | 458 | } |
@@ -476,15 +476,15 @@ discard block |
||
476 | 476 | $fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias()); |
477 | 477 | foreach ($fields_for_that_table as $field_obj) { |
478 | 478 | if ( |
479 | - ! isset($post[ $field_obj->get_table_column() ]) |
|
480 | - && ! isset($post[ $field_obj->get_qualified_column() ]) |
|
479 | + ! isset($post[$field_obj->get_table_column()]) |
|
480 | + && ! isset($post[$field_obj->get_qualified_column()]) |
|
481 | 481 | ) { |
482 | 482 | $has_all_necessary_fields_for_table = false; |
483 | 483 | } |
484 | 484 | } |
485 | 485 | } |
486 | 486 | // if we don't have all the fields we need, then just fetch the proper model from the DB |
487 | - if (! $has_all_necessary_fields_for_table) { |
|
487 | + if ( ! $has_all_necessary_fields_for_table) { |
|
488 | 488 | return $this->get_one_by_ID($post['ID']); |
489 | 489 | } else { |
490 | 490 | return $this->instantiate_class_from_array_or_object($post); |
@@ -508,10 +508,10 @@ discard block |
||
508 | 508 | $fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias()); |
509 | 509 | foreach ($fields_for_that_table as $field_obj) { |
510 | 510 | if ( |
511 | - ! isset($post[ $field_obj->get_table_column() ]) |
|
512 | - && ! isset($post[ $field_obj->get_qualified_column() ]) |
|
511 | + ! isset($post[$field_obj->get_table_column()]) |
|
512 | + && ! isset($post[$field_obj->get_qualified_column()]) |
|
513 | 513 | ) { |
514 | - $tables_needing_to_be_queried[ $table_obj->get_table_alias() ] = $table_obj; |
|
514 | + $tables_needing_to_be_queried[$table_obj->get_table_alias()] = $table_obj; |
|
515 | 515 | } |
516 | 516 | } |
517 | 517 | } |
@@ -537,7 +537,7 @@ discard block |
||
537 | 537 | ARRAY_A, |
538 | 538 | ) |
539 | 539 | ); |
540 | - if (! empty($missing_data)) { |
|
540 | + if ( ! empty($missing_data)) { |
|
541 | 541 | $post = array_merge($post, $missing_data); |
542 | 542 | } |
543 | 543 | } else { |
@@ -14,564 +14,564 @@ |
||
14 | 14 | */ |
15 | 15 | abstract class EEM_CPT_Base extends EEM_Soft_Delete_Base |
16 | 16 | { |
17 | - const EVENT_CATEGORY_TAXONOMY = 'espresso_event_categories'; |
|
18 | - |
|
19 | - /** |
|
20 | - * @var string post_status_publish - the wp post status for published cpts |
|
21 | - */ |
|
22 | - const post_status_publish = 'publish'; |
|
23 | - |
|
24 | - /** |
|
25 | - * @var string post_status_future - the wp post status for scheduled cpts |
|
26 | - */ |
|
27 | - const post_status_future = 'future'; |
|
28 | - |
|
29 | - /** |
|
30 | - * @var string post_status_draft - the wp post status for draft cpts |
|
31 | - */ |
|
32 | - const post_status_draft = 'draft'; |
|
33 | - |
|
34 | - /** |
|
35 | - * @var string post_status_pending - the wp post status for pending cpts |
|
36 | - */ |
|
37 | - const post_status_pending = 'pending'; |
|
38 | - |
|
39 | - /** |
|
40 | - * @var string post_status_private - the wp post status for private cpts |
|
41 | - */ |
|
42 | - const post_status_private = 'private'; |
|
43 | - |
|
44 | - /** |
|
45 | - * @var string post_status_trashed - the wp post status for trashed cpts |
|
46 | - */ |
|
47 | - const post_status_trashed = 'trash'; |
|
48 | - |
|
49 | - /** |
|
50 | - * This is an array of custom statuses for the given CPT model (modified by children) |
|
51 | - * format: |
|
52 | - * array( |
|
53 | - * 'status_name' => array( |
|
54 | - * 'label' => esc_html__('Status Name', 'event_espresso'), |
|
55 | - * 'public' => TRUE //whether a public status or not. |
|
56 | - * ) |
|
57 | - * ) |
|
58 | - * |
|
59 | - * @var array |
|
60 | - */ |
|
61 | - protected $_custom_stati = array(); |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * Adds a relationship to Term_Taxonomy for each CPT_Base |
|
66 | - * |
|
67 | - * @param string $timezone |
|
68 | - * @throws \EE_Error |
|
69 | - */ |
|
70 | - protected function __construct($timezone = null) |
|
71 | - { |
|
72 | - // adds a relationship to Term_Taxonomy for all these models. For this to work |
|
73 | - // Term_Relationship must have a relation to each model subclassing EE_CPT_Base explicitly |
|
74 | - // eg, in EEM_Term_Relationship, inside the _model_relations array, there must be an entry |
|
75 | - // with key equalling the subclassing model's model name (eg 'Event' or 'Venue'), and the value |
|
76 | - // must also be new EE_HABTM_Relation('Term_Relationship'); |
|
77 | - $this->_model_relations['Term_Taxonomy'] = new EE_HABTM_Relation('Term_Relationship'); |
|
78 | - $primary_table_name = null; |
|
79 | - // add the common _status field to all CPT primary tables. |
|
80 | - foreach ($this->_tables as $alias => $table_obj) { |
|
81 | - if ($table_obj instanceof EE_Primary_Table) { |
|
82 | - $primary_table_name = $alias; |
|
83 | - } |
|
84 | - } |
|
85 | - // set default wp post statuses if child has not already set. |
|
86 | - if (! isset($this->_fields[ $primary_table_name ]['status'])) { |
|
87 | - $this->_fields[ $primary_table_name ]['status'] = new EE_WP_Post_Status_Field( |
|
88 | - 'post_status', |
|
89 | - esc_html__("Event Status", "event_espresso"), |
|
90 | - false, |
|
91 | - 'draft' |
|
92 | - ); |
|
93 | - } |
|
94 | - if (! isset($this->_fields[ $primary_table_name ]['to_ping'])) { |
|
95 | - $this->_fields[ $primary_table_name ]['to_ping'] = new EE_DB_Only_Text_Field( |
|
96 | - 'to_ping', |
|
97 | - esc_html__('To Ping', 'event_espresso'), |
|
98 | - false, |
|
99 | - '' |
|
100 | - ); |
|
101 | - } |
|
102 | - if (! isset($this->_fields[ $primary_table_name ]['pinged'])) { |
|
103 | - $this->_fields[ $primary_table_name ]['pinged'] = new EE_DB_Only_Text_Field( |
|
104 | - 'pinged', |
|
105 | - esc_html__('Pinged', 'event_espresso'), |
|
106 | - false, |
|
107 | - '' |
|
108 | - ); |
|
109 | - } |
|
110 | - if (! isset($this->_fields[ $primary_table_name ]['comment_status'])) { |
|
111 | - $this->_fields[ $primary_table_name ]['comment_status'] = new EE_Plain_Text_Field( |
|
112 | - 'comment_status', |
|
113 | - esc_html__('Comment Status', 'event_espresso'), |
|
114 | - false, |
|
115 | - 'open' |
|
116 | - ); |
|
117 | - } |
|
118 | - if (! isset($this->_fields[ $primary_table_name ]['ping_status'])) { |
|
119 | - $this->_fields[ $primary_table_name ]['ping_status'] = new EE_Plain_Text_Field( |
|
120 | - 'ping_status', |
|
121 | - esc_html__('Ping Status', 'event_espresso'), |
|
122 | - false, |
|
123 | - 'open' |
|
124 | - ); |
|
125 | - } |
|
126 | - if (! isset($this->_fields[ $primary_table_name ]['post_content_filtered'])) { |
|
127 | - $this->_fields[ $primary_table_name ]['post_content_filtered'] = new EE_DB_Only_Text_Field( |
|
128 | - 'post_content_filtered', |
|
129 | - esc_html__('Post Content Filtered', 'event_espresso'), |
|
130 | - false, |
|
131 | - '' |
|
132 | - ); |
|
133 | - } |
|
134 | - if (! isset($this->_model_relations['Post_Meta'])) { |
|
135 | - // don't block deletes though because we want to maintain the current behaviour |
|
136 | - $this->_model_relations['Post_Meta'] = new EE_Has_Many_Relation(false); |
|
137 | - } |
|
138 | - if (! $this->_minimum_where_conditions_strategy instanceof EE_Default_Where_Conditions) { |
|
139 | - // nothing was set during child constructor, so set default |
|
140 | - $this->_minimum_where_conditions_strategy = new EE_CPT_Minimum_Where_Conditions($this->post_type()); |
|
141 | - } |
|
142 | - if (! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) { |
|
143 | - // nothing was set during child constructor, so set default |
|
144 | - // it's ok for child classes to specify this, but generally this is more DRY |
|
145 | - $this->_default_where_conditions_strategy = new EE_CPT_Where_Conditions($this->post_type()); |
|
146 | - } |
|
147 | - parent::__construct($timezone); |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * @return array |
|
153 | - */ |
|
154 | - public function public_event_stati() |
|
155 | - { |
|
156 | - // @see wp-includes/post.php |
|
157 | - return get_post_stati(array('public' => true)); |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * Searches for field on this model of type 'deleted_flag'. if it is found, |
|
163 | - * returns it's name. BUT That doesn't apply to CPTs. We should instead use post_status_field_name |
|
164 | - * |
|
165 | - * @return string |
|
166 | - * @throws EE_Error |
|
167 | - */ |
|
168 | - public function deleted_field_name() |
|
169 | - { |
|
170 | - throw new EE_Error( |
|
171 | - sprintf( |
|
172 | - esc_html__( |
|
173 | - '%1$s should not call deleted_field_name()! It should instead use post_status_field_name', |
|
174 | - "event_espresso" |
|
175 | - ), |
|
176 | - get_called_class() |
|
177 | - ) |
|
178 | - ); |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * Gets the field's name that sets the post status |
|
184 | - * |
|
185 | - * @return string |
|
186 | - * @throws EE_Error |
|
187 | - */ |
|
188 | - public function post_status_field_name() |
|
189 | - { |
|
190 | - $field = $this->get_a_field_of_type('EE_WP_Post_Status_Field'); |
|
191 | - if ($field) { |
|
192 | - return $field->get_name(); |
|
193 | - } else { |
|
194 | - throw new EE_Error( |
|
195 | - sprintf( |
|
196 | - esc_html__( |
|
197 | - 'We are trying to find the post status flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?', |
|
198 | - 'event_espresso' |
|
199 | - ), |
|
200 | - get_called_class(), |
|
201 | - get_called_class() |
|
202 | - ) |
|
203 | - ); |
|
204 | - } |
|
205 | - } |
|
206 | - |
|
207 | - |
|
208 | - /** |
|
209 | - * Alters the query params so that only trashed/soft-deleted items are considered |
|
210 | - * |
|
211 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
212 | - * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
213 | - */ |
|
214 | - protected function _alter_query_params_so_only_trashed_items_included($query_params) |
|
215 | - { |
|
216 | - $post_status_field_name = $this->post_status_field_name(); |
|
217 | - $query_params[0][ $post_status_field_name ] = self::post_status_trashed; |
|
218 | - return $query_params; |
|
219 | - } |
|
220 | - |
|
221 | - |
|
222 | - /** |
|
223 | - * Alters the query params so each item's deleted status is ignored. |
|
224 | - * |
|
225 | - * @param array $query_params |
|
226 | - * @return array |
|
227 | - */ |
|
228 | - protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params) |
|
229 | - { |
|
230 | - $query_params['default_where_conditions'] = 'minimum'; |
|
231 | - return $query_params; |
|
232 | - } |
|
233 | - |
|
234 | - |
|
235 | - /** |
|
236 | - * Performs deletes or restores on items. Both soft-deleted and non-soft-deleted items considered. |
|
237 | - * |
|
238 | - * @param boolean $delete true to indicate deletion, false to indicate restoration |
|
239 | - * @param array $query_params |
|
240 | - * @return boolean success |
|
241 | - * @throws EE_Error |
|
242 | - * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
243 | - */ |
|
244 | - public function delete_or_restore($delete = true, $query_params = array()) |
|
245 | - { |
|
246 | - $post_status_field_name = $this->post_status_field_name(); |
|
247 | - $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
|
248 | - $new_status = $delete ? self::post_status_trashed : 'draft'; |
|
249 | - return (bool) $this->update([$post_status_field_name => $new_status], $query_params); |
|
250 | - } |
|
251 | - |
|
252 | - |
|
253 | - /** |
|
254 | - * meta_table |
|
255 | - * returns first EE_Secondary_Table table name |
|
256 | - * |
|
257 | - * @access public |
|
258 | - * @return string |
|
259 | - */ |
|
260 | - public function meta_table() |
|
261 | - { |
|
262 | - $meta_table = $this->_get_other_tables(); |
|
263 | - $meta_table = reset($meta_table); |
|
264 | - return $meta_table instanceof EE_Secondary_Table ? $meta_table->get_table_name() : null; |
|
265 | - } |
|
266 | - |
|
267 | - |
|
268 | - /** |
|
269 | - * This simply returns an array of the meta table fields (useful for when we just need to update those fields) |
|
270 | - * |
|
271 | - * @param bool $all triggers whether we include DB_Only fields or JUST non DB_Only fields. Defaults to false (no |
|
272 | - * db only fields) |
|
273 | - * @return array |
|
274 | - */ |
|
275 | - public function get_meta_table_fields($all = false) |
|
276 | - { |
|
277 | - $all_fields = $fields_to_return = array(); |
|
278 | - foreach ($this->_tables as $alias => $table_obj) { |
|
279 | - if ($table_obj instanceof EE_Secondary_Table) { |
|
280 | - $all_fields = array_merge($this->_get_fields_for_table($alias), $all_fields); |
|
281 | - } |
|
282 | - } |
|
283 | - if (! $all) { |
|
284 | - foreach ($all_fields as $name => $obj) { |
|
285 | - if ($obj instanceof EE_DB_Only_Field_Base) { |
|
286 | - continue; |
|
287 | - } |
|
288 | - $fields_to_return[] = $name; |
|
289 | - } |
|
290 | - } else { |
|
291 | - $fields_to_return = array_keys($all_fields); |
|
292 | - } |
|
293 | - return $fields_to_return; |
|
294 | - } |
|
295 | - |
|
296 | - |
|
297 | - /** |
|
298 | - * Adds an event category with the specified name and description to the specified |
|
299 | - * $cpt_model_object. Intelligently adds a term if necessary, and adds a term_taxonomy if necessary, |
|
300 | - * and adds an entry in the term_relationship if necessary. |
|
301 | - * |
|
302 | - * @param EE_CPT_Base $cpt_model_object |
|
303 | - * @param string $category_name (used to derive the term slug too) |
|
304 | - * @param string $category_description |
|
305 | - * @param int $parent_term_taxonomy_id |
|
306 | - * @return EE_Term_Taxonomy |
|
307 | - */ |
|
308 | - public function add_event_category( |
|
309 | - EE_CPT_Base $cpt_model_object, |
|
310 | - $category_name, |
|
311 | - $category_description = '', |
|
312 | - $parent_term_taxonomy_id = null |
|
313 | - ) { |
|
314 | - // create term |
|
315 | - require_once(EE_MODELS . 'EEM_Term.model.php'); |
|
316 | - // first, check for a term by the same name or slug |
|
317 | - $category_slug = sanitize_title($category_name); |
|
318 | - $term = EEM_Term::instance()->get_one( |
|
319 | - array( |
|
320 | - array( |
|
321 | - 'OR' => array( |
|
322 | - 'name' => $category_name, |
|
323 | - 'slug' => $category_slug, |
|
324 | - ), |
|
325 | - 'Term_Taxonomy.taxonomy' => self::EVENT_CATEGORY_TAXONOMY |
|
326 | - ), |
|
327 | - ) |
|
328 | - ); |
|
329 | - if (! $term) { |
|
330 | - $term = EE_Term::new_instance( |
|
331 | - array( |
|
332 | - 'name' => $category_name, |
|
333 | - 'slug' => $category_slug, |
|
334 | - ) |
|
335 | - ); |
|
336 | - $term->save(); |
|
337 | - } |
|
338 | - // make sure there's a term-taxonomy entry too |
|
339 | - require_once(EE_MODELS . 'EEM_Term_Taxonomy.model.php'); |
|
340 | - $term_taxonomy = EEM_Term_Taxonomy::instance()->get_one( |
|
341 | - array( |
|
342 | - array( |
|
343 | - 'term_id' => $term->ID(), |
|
344 | - 'taxonomy' => self::EVENT_CATEGORY_TAXONOMY, |
|
345 | - ), |
|
346 | - ) |
|
347 | - ); |
|
348 | - /** @var $term_taxonomy EE_Term_Taxonomy */ |
|
349 | - if (! $term_taxonomy) { |
|
350 | - $term_taxonomy = EE_Term_Taxonomy::new_instance( |
|
351 | - array( |
|
352 | - 'term_id' => $term->ID(), |
|
353 | - 'taxonomy' => self::EVENT_CATEGORY_TAXONOMY, |
|
354 | - 'description' => $category_description, |
|
355 | - 'term_count' => 1, |
|
356 | - 'parent' => $parent_term_taxonomy_id, |
|
357 | - ) |
|
358 | - ); |
|
359 | - $term_taxonomy->save(); |
|
360 | - } else { |
|
361 | - $term_taxonomy->set_count($term_taxonomy->count() + 1); |
|
362 | - $term_taxonomy->save(); |
|
363 | - } |
|
364 | - return $this->add_relationship_to($cpt_model_object, $term_taxonomy, 'Term_Taxonomy'); |
|
365 | - } |
|
366 | - |
|
367 | - |
|
368 | - /** |
|
369 | - * Removed the category specified by name as having a relation to this event. |
|
370 | - * Does not remove the term or term_taxonomy. |
|
371 | - * |
|
372 | - * @param EE_CPT_Base $cpt_model_object_event |
|
373 | - * @param string $category_name name of the event category (term) |
|
374 | - * @return bool |
|
375 | - */ |
|
376 | - public function remove_event_category(EE_CPT_Base $cpt_model_object_event, $category_name) |
|
377 | - { |
|
378 | - // find the term_taxonomy by that name |
|
379 | - $term_taxonomy = $this->get_first_related( |
|
380 | - $cpt_model_object_event, |
|
381 | - 'Term_Taxonomy', |
|
382 | - array(array('Term.name' => $category_name, 'taxonomy' => self::EVENT_CATEGORY_TAXONOMY)) |
|
383 | - ); |
|
384 | - /** @var $term_taxonomy EE_Term_Taxonomy */ |
|
385 | - if ($term_taxonomy) { |
|
386 | - $term_taxonomy->set_count($term_taxonomy->count() - 1); |
|
387 | - $term_taxonomy->save(); |
|
388 | - } |
|
389 | - return $this->remove_relationship_to($cpt_model_object_event, $term_taxonomy, 'Term_Taxonomy'); |
|
390 | - } |
|
391 | - |
|
392 | - |
|
393 | - /** |
|
394 | - * This is a wrapper for the WordPress get_the_post_thumbnail() function that returns the feature image for the |
|
395 | - * given CPT ID. It accepts the same params as what get_the_post_thumbnail() accepts. |
|
396 | - * |
|
397 | - * @link http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail |
|
398 | - * @access public |
|
399 | - * @param int $id the ID for the cpt we want the feature image for |
|
400 | - * @param string|array $size (optional) Image size. Defaults to 'post-thumbnail' but can also be a 2-item array |
|
401 | - * representing width and height in pixels (i.e. array(32,32) ). |
|
402 | - * @param string|array $attr Optional. Query string or array of attributes. |
|
403 | - * @return string HTML image element |
|
404 | - */ |
|
405 | - public function get_feature_image($id, $size = 'thumbnail', $attr = '') |
|
406 | - { |
|
407 | - return get_the_post_thumbnail($id, $size, $attr); |
|
408 | - } |
|
409 | - |
|
410 | - |
|
411 | - /** |
|
412 | - * Just a handy way to get the list of post statuses currently registered with WP. |
|
413 | - * |
|
414 | - * @global array $wp_post_statuses set in wp core for storing all the post stati |
|
415 | - * @return array |
|
416 | - */ |
|
417 | - public function get_post_statuses() |
|
418 | - { |
|
419 | - global $wp_post_statuses; |
|
420 | - $statuses = array(); |
|
421 | - foreach ($wp_post_statuses as $post_status => $args_object) { |
|
422 | - $statuses[ $post_status ] = $args_object->label; |
|
423 | - } |
|
424 | - return $statuses; |
|
425 | - } |
|
426 | - |
|
427 | - |
|
428 | - /** |
|
429 | - * public method that can be used to retrieve the protected status array on the instantiated cpt model |
|
430 | - * |
|
431 | - * @return array array of statuses. |
|
432 | - */ |
|
433 | - public function get_status_array() |
|
434 | - { |
|
435 | - $statuses = $this->get_post_statuses(); |
|
436 | - // first the global filter |
|
437 | - $statuses = apply_filters('FHEE_EEM_CPT_Base__get_status_array', $statuses); |
|
438 | - // now the class specific filter |
|
439 | - $statuses = apply_filters('FHEE_EEM_' . get_class($this) . '__get_status_array', $statuses); |
|
440 | - return $statuses; |
|
441 | - } |
|
442 | - |
|
443 | - |
|
444 | - /** |
|
445 | - * this returns the post statuses that are NOT the default wordpress status |
|
446 | - * |
|
447 | - * @return array |
|
448 | - */ |
|
449 | - public function get_custom_post_statuses() |
|
450 | - { |
|
451 | - $new_stati = array(); |
|
452 | - foreach ($this->_custom_stati as $status => $props) { |
|
453 | - $new_stati[ $status ] = $props['label']; |
|
454 | - } |
|
455 | - return $new_stati; |
|
456 | - } |
|
457 | - |
|
458 | - |
|
459 | - /** |
|
460 | - * Creates a child of EE_CPT_Base given a WP_Post or array of wpdb results which |
|
461 | - * are a row from the posts table. If we're missing any fields required for the model, |
|
462 | - * we just fetch the entire entry from the DB (ie, if you want to use this to save DB queries, |
|
463 | - * make sure you are attaching all the model's fields onto the post) |
|
464 | - * |
|
465 | - * @param WP_Post|array $post |
|
466 | - * @return EE_Base_Class|EE_Soft_Delete_Base_Class |
|
467 | - */ |
|
468 | - public function instantiate_class_from_post_object_orig($post) |
|
469 | - { |
|
470 | - $post = (array) $post; |
|
471 | - $has_all_necessary_fields_for_table = true; |
|
472 | - // check if the post has fields on the meta table already |
|
473 | - foreach ($this->_get_other_tables() as $table_obj) { |
|
474 | - $fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias()); |
|
475 | - foreach ($fields_for_that_table as $field_obj) { |
|
476 | - if ( |
|
477 | - ! isset($post[ $field_obj->get_table_column() ]) |
|
478 | - && ! isset($post[ $field_obj->get_qualified_column() ]) |
|
479 | - ) { |
|
480 | - $has_all_necessary_fields_for_table = false; |
|
481 | - } |
|
482 | - } |
|
483 | - } |
|
484 | - // if we don't have all the fields we need, then just fetch the proper model from the DB |
|
485 | - if (! $has_all_necessary_fields_for_table) { |
|
486 | - return $this->get_one_by_ID($post['ID']); |
|
487 | - } else { |
|
488 | - return $this->instantiate_class_from_array_or_object($post); |
|
489 | - } |
|
490 | - } |
|
491 | - |
|
492 | - |
|
493 | - /** |
|
494 | - * @param null $post |
|
495 | - * @return EE_Base_Class|EE_Soft_Delete_Base_Class |
|
496 | - */ |
|
497 | - public function instantiate_class_from_post_object($post = null) |
|
498 | - { |
|
499 | - if (empty($post)) { |
|
500 | - global $post; |
|
501 | - } |
|
502 | - $post = (array) $post; |
|
503 | - $tables_needing_to_be_queried = array(); |
|
504 | - // check if the post has fields on the meta table already |
|
505 | - foreach ($this->get_tables() as $table_obj) { |
|
506 | - $fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias()); |
|
507 | - foreach ($fields_for_that_table as $field_obj) { |
|
508 | - if ( |
|
509 | - ! isset($post[ $field_obj->get_table_column() ]) |
|
510 | - && ! isset($post[ $field_obj->get_qualified_column() ]) |
|
511 | - ) { |
|
512 | - $tables_needing_to_be_queried[ $table_obj->get_table_alias() ] = $table_obj; |
|
513 | - } |
|
514 | - } |
|
515 | - } |
|
516 | - // if we don't have all the fields we need, then just fetch the proper model from the DB |
|
517 | - if ($tables_needing_to_be_queried) { |
|
518 | - if ( |
|
519 | - count($tables_needing_to_be_queried) == 1 |
|
520 | - && reset($tables_needing_to_be_queried) |
|
521 | - instanceof |
|
522 | - EE_Secondary_Table |
|
523 | - ) { |
|
524 | - // so we're only missing data from a secondary table. Well that's not too hard to query for |
|
525 | - $table_to_query = reset($tables_needing_to_be_queried); |
|
526 | - $missing_data = $this->_do_wpdb_query( |
|
527 | - 'get_row', |
|
528 | - array( |
|
529 | - 'SELECT * FROM ' |
|
530 | - . $table_to_query->get_table_name() |
|
531 | - . ' WHERE ' |
|
532 | - . $table_to_query->get_fk_on_table() |
|
533 | - . ' = ' |
|
534 | - . $post['ID'], |
|
535 | - ARRAY_A, |
|
536 | - ) |
|
537 | - ); |
|
538 | - if (! empty($missing_data)) { |
|
539 | - $post = array_merge($post, $missing_data); |
|
540 | - } |
|
541 | - } else { |
|
542 | - return $this->get_one_by_ID($post['ID']); |
|
543 | - } |
|
544 | - } |
|
545 | - return $this->instantiate_class_from_array_or_object($post); |
|
546 | - } |
|
547 | - |
|
548 | - |
|
549 | - /** |
|
550 | - * Gets the post type associated with this |
|
551 | - * |
|
552 | - * @throws EE_Error |
|
553 | - * @return string |
|
554 | - */ |
|
555 | - public function post_type() |
|
556 | - { |
|
557 | - $post_type_field = null; |
|
558 | - foreach ($this->field_settings(true) as $field_obj) { |
|
559 | - if ($field_obj instanceof EE_WP_Post_Type_Field) { |
|
560 | - $post_type_field = $field_obj; |
|
561 | - break; |
|
562 | - } |
|
563 | - } |
|
564 | - if ($post_type_field == null) { |
|
565 | - throw new EE_Error( |
|
566 | - sprintf( |
|
567 | - esc_html__( |
|
568 | - "CPT Model %s should have a field of type EE_WP_Post_Type, but doesnt", |
|
569 | - "event_espresso" |
|
570 | - ), |
|
571 | - get_class($this) |
|
572 | - ) |
|
573 | - ); |
|
574 | - } |
|
575 | - return $post_type_field->get_default_value(); |
|
576 | - } |
|
17 | + const EVENT_CATEGORY_TAXONOMY = 'espresso_event_categories'; |
|
18 | + |
|
19 | + /** |
|
20 | + * @var string post_status_publish - the wp post status for published cpts |
|
21 | + */ |
|
22 | + const post_status_publish = 'publish'; |
|
23 | + |
|
24 | + /** |
|
25 | + * @var string post_status_future - the wp post status for scheduled cpts |
|
26 | + */ |
|
27 | + const post_status_future = 'future'; |
|
28 | + |
|
29 | + /** |
|
30 | + * @var string post_status_draft - the wp post status for draft cpts |
|
31 | + */ |
|
32 | + const post_status_draft = 'draft'; |
|
33 | + |
|
34 | + /** |
|
35 | + * @var string post_status_pending - the wp post status for pending cpts |
|
36 | + */ |
|
37 | + const post_status_pending = 'pending'; |
|
38 | + |
|
39 | + /** |
|
40 | + * @var string post_status_private - the wp post status for private cpts |
|
41 | + */ |
|
42 | + const post_status_private = 'private'; |
|
43 | + |
|
44 | + /** |
|
45 | + * @var string post_status_trashed - the wp post status for trashed cpts |
|
46 | + */ |
|
47 | + const post_status_trashed = 'trash'; |
|
48 | + |
|
49 | + /** |
|
50 | + * This is an array of custom statuses for the given CPT model (modified by children) |
|
51 | + * format: |
|
52 | + * array( |
|
53 | + * 'status_name' => array( |
|
54 | + * 'label' => esc_html__('Status Name', 'event_espresso'), |
|
55 | + * 'public' => TRUE //whether a public status or not. |
|
56 | + * ) |
|
57 | + * ) |
|
58 | + * |
|
59 | + * @var array |
|
60 | + */ |
|
61 | + protected $_custom_stati = array(); |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * Adds a relationship to Term_Taxonomy for each CPT_Base |
|
66 | + * |
|
67 | + * @param string $timezone |
|
68 | + * @throws \EE_Error |
|
69 | + */ |
|
70 | + protected function __construct($timezone = null) |
|
71 | + { |
|
72 | + // adds a relationship to Term_Taxonomy for all these models. For this to work |
|
73 | + // Term_Relationship must have a relation to each model subclassing EE_CPT_Base explicitly |
|
74 | + // eg, in EEM_Term_Relationship, inside the _model_relations array, there must be an entry |
|
75 | + // with key equalling the subclassing model's model name (eg 'Event' or 'Venue'), and the value |
|
76 | + // must also be new EE_HABTM_Relation('Term_Relationship'); |
|
77 | + $this->_model_relations['Term_Taxonomy'] = new EE_HABTM_Relation('Term_Relationship'); |
|
78 | + $primary_table_name = null; |
|
79 | + // add the common _status field to all CPT primary tables. |
|
80 | + foreach ($this->_tables as $alias => $table_obj) { |
|
81 | + if ($table_obj instanceof EE_Primary_Table) { |
|
82 | + $primary_table_name = $alias; |
|
83 | + } |
|
84 | + } |
|
85 | + // set default wp post statuses if child has not already set. |
|
86 | + if (! isset($this->_fields[ $primary_table_name ]['status'])) { |
|
87 | + $this->_fields[ $primary_table_name ]['status'] = new EE_WP_Post_Status_Field( |
|
88 | + 'post_status', |
|
89 | + esc_html__("Event Status", "event_espresso"), |
|
90 | + false, |
|
91 | + 'draft' |
|
92 | + ); |
|
93 | + } |
|
94 | + if (! isset($this->_fields[ $primary_table_name ]['to_ping'])) { |
|
95 | + $this->_fields[ $primary_table_name ]['to_ping'] = new EE_DB_Only_Text_Field( |
|
96 | + 'to_ping', |
|
97 | + esc_html__('To Ping', 'event_espresso'), |
|
98 | + false, |
|
99 | + '' |
|
100 | + ); |
|
101 | + } |
|
102 | + if (! isset($this->_fields[ $primary_table_name ]['pinged'])) { |
|
103 | + $this->_fields[ $primary_table_name ]['pinged'] = new EE_DB_Only_Text_Field( |
|
104 | + 'pinged', |
|
105 | + esc_html__('Pinged', 'event_espresso'), |
|
106 | + false, |
|
107 | + '' |
|
108 | + ); |
|
109 | + } |
|
110 | + if (! isset($this->_fields[ $primary_table_name ]['comment_status'])) { |
|
111 | + $this->_fields[ $primary_table_name ]['comment_status'] = new EE_Plain_Text_Field( |
|
112 | + 'comment_status', |
|
113 | + esc_html__('Comment Status', 'event_espresso'), |
|
114 | + false, |
|
115 | + 'open' |
|
116 | + ); |
|
117 | + } |
|
118 | + if (! isset($this->_fields[ $primary_table_name ]['ping_status'])) { |
|
119 | + $this->_fields[ $primary_table_name ]['ping_status'] = new EE_Plain_Text_Field( |
|
120 | + 'ping_status', |
|
121 | + esc_html__('Ping Status', 'event_espresso'), |
|
122 | + false, |
|
123 | + 'open' |
|
124 | + ); |
|
125 | + } |
|
126 | + if (! isset($this->_fields[ $primary_table_name ]['post_content_filtered'])) { |
|
127 | + $this->_fields[ $primary_table_name ]['post_content_filtered'] = new EE_DB_Only_Text_Field( |
|
128 | + 'post_content_filtered', |
|
129 | + esc_html__('Post Content Filtered', 'event_espresso'), |
|
130 | + false, |
|
131 | + '' |
|
132 | + ); |
|
133 | + } |
|
134 | + if (! isset($this->_model_relations['Post_Meta'])) { |
|
135 | + // don't block deletes though because we want to maintain the current behaviour |
|
136 | + $this->_model_relations['Post_Meta'] = new EE_Has_Many_Relation(false); |
|
137 | + } |
|
138 | + if (! $this->_minimum_where_conditions_strategy instanceof EE_Default_Where_Conditions) { |
|
139 | + // nothing was set during child constructor, so set default |
|
140 | + $this->_minimum_where_conditions_strategy = new EE_CPT_Minimum_Where_Conditions($this->post_type()); |
|
141 | + } |
|
142 | + if (! $this->_default_where_conditions_strategy instanceof EE_Default_Where_Conditions) { |
|
143 | + // nothing was set during child constructor, so set default |
|
144 | + // it's ok for child classes to specify this, but generally this is more DRY |
|
145 | + $this->_default_where_conditions_strategy = new EE_CPT_Where_Conditions($this->post_type()); |
|
146 | + } |
|
147 | + parent::__construct($timezone); |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * @return array |
|
153 | + */ |
|
154 | + public function public_event_stati() |
|
155 | + { |
|
156 | + // @see wp-includes/post.php |
|
157 | + return get_post_stati(array('public' => true)); |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * Searches for field on this model of type 'deleted_flag'. if it is found, |
|
163 | + * returns it's name. BUT That doesn't apply to CPTs. We should instead use post_status_field_name |
|
164 | + * |
|
165 | + * @return string |
|
166 | + * @throws EE_Error |
|
167 | + */ |
|
168 | + public function deleted_field_name() |
|
169 | + { |
|
170 | + throw new EE_Error( |
|
171 | + sprintf( |
|
172 | + esc_html__( |
|
173 | + '%1$s should not call deleted_field_name()! It should instead use post_status_field_name', |
|
174 | + "event_espresso" |
|
175 | + ), |
|
176 | + get_called_class() |
|
177 | + ) |
|
178 | + ); |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * Gets the field's name that sets the post status |
|
184 | + * |
|
185 | + * @return string |
|
186 | + * @throws EE_Error |
|
187 | + */ |
|
188 | + public function post_status_field_name() |
|
189 | + { |
|
190 | + $field = $this->get_a_field_of_type('EE_WP_Post_Status_Field'); |
|
191 | + if ($field) { |
|
192 | + return $field->get_name(); |
|
193 | + } else { |
|
194 | + throw new EE_Error( |
|
195 | + sprintf( |
|
196 | + esc_html__( |
|
197 | + 'We are trying to find the post status flag field on %s, but none was found. Are you sure there is a field of type EE_Trashed_Flag_Field in %s constructor?', |
|
198 | + 'event_espresso' |
|
199 | + ), |
|
200 | + get_called_class(), |
|
201 | + get_called_class() |
|
202 | + ) |
|
203 | + ); |
|
204 | + } |
|
205 | + } |
|
206 | + |
|
207 | + |
|
208 | + /** |
|
209 | + * Alters the query params so that only trashed/soft-deleted items are considered |
|
210 | + * |
|
211 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
212 | + * @return array @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
213 | + */ |
|
214 | + protected function _alter_query_params_so_only_trashed_items_included($query_params) |
|
215 | + { |
|
216 | + $post_status_field_name = $this->post_status_field_name(); |
|
217 | + $query_params[0][ $post_status_field_name ] = self::post_status_trashed; |
|
218 | + return $query_params; |
|
219 | + } |
|
220 | + |
|
221 | + |
|
222 | + /** |
|
223 | + * Alters the query params so each item's deleted status is ignored. |
|
224 | + * |
|
225 | + * @param array $query_params |
|
226 | + * @return array |
|
227 | + */ |
|
228 | + protected function _alter_query_params_so_deleted_and_undeleted_items_included($query_params) |
|
229 | + { |
|
230 | + $query_params['default_where_conditions'] = 'minimum'; |
|
231 | + return $query_params; |
|
232 | + } |
|
233 | + |
|
234 | + |
|
235 | + /** |
|
236 | + * Performs deletes or restores on items. Both soft-deleted and non-soft-deleted items considered. |
|
237 | + * |
|
238 | + * @param boolean $delete true to indicate deletion, false to indicate restoration |
|
239 | + * @param array $query_params |
|
240 | + * @return boolean success |
|
241 | + * @throws EE_Error |
|
242 | + * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
243 | + */ |
|
244 | + public function delete_or_restore($delete = true, $query_params = array()) |
|
245 | + { |
|
246 | + $post_status_field_name = $this->post_status_field_name(); |
|
247 | + $query_params = $this->_alter_query_params_so_deleted_and_undeleted_items_included($query_params); |
|
248 | + $new_status = $delete ? self::post_status_trashed : 'draft'; |
|
249 | + return (bool) $this->update([$post_status_field_name => $new_status], $query_params); |
|
250 | + } |
|
251 | + |
|
252 | + |
|
253 | + /** |
|
254 | + * meta_table |
|
255 | + * returns first EE_Secondary_Table table name |
|
256 | + * |
|
257 | + * @access public |
|
258 | + * @return string |
|
259 | + */ |
|
260 | + public function meta_table() |
|
261 | + { |
|
262 | + $meta_table = $this->_get_other_tables(); |
|
263 | + $meta_table = reset($meta_table); |
|
264 | + return $meta_table instanceof EE_Secondary_Table ? $meta_table->get_table_name() : null; |
|
265 | + } |
|
266 | + |
|
267 | + |
|
268 | + /** |
|
269 | + * This simply returns an array of the meta table fields (useful for when we just need to update those fields) |
|
270 | + * |
|
271 | + * @param bool $all triggers whether we include DB_Only fields or JUST non DB_Only fields. Defaults to false (no |
|
272 | + * db only fields) |
|
273 | + * @return array |
|
274 | + */ |
|
275 | + public function get_meta_table_fields($all = false) |
|
276 | + { |
|
277 | + $all_fields = $fields_to_return = array(); |
|
278 | + foreach ($this->_tables as $alias => $table_obj) { |
|
279 | + if ($table_obj instanceof EE_Secondary_Table) { |
|
280 | + $all_fields = array_merge($this->_get_fields_for_table($alias), $all_fields); |
|
281 | + } |
|
282 | + } |
|
283 | + if (! $all) { |
|
284 | + foreach ($all_fields as $name => $obj) { |
|
285 | + if ($obj instanceof EE_DB_Only_Field_Base) { |
|
286 | + continue; |
|
287 | + } |
|
288 | + $fields_to_return[] = $name; |
|
289 | + } |
|
290 | + } else { |
|
291 | + $fields_to_return = array_keys($all_fields); |
|
292 | + } |
|
293 | + return $fields_to_return; |
|
294 | + } |
|
295 | + |
|
296 | + |
|
297 | + /** |
|
298 | + * Adds an event category with the specified name and description to the specified |
|
299 | + * $cpt_model_object. Intelligently adds a term if necessary, and adds a term_taxonomy if necessary, |
|
300 | + * and adds an entry in the term_relationship if necessary. |
|
301 | + * |
|
302 | + * @param EE_CPT_Base $cpt_model_object |
|
303 | + * @param string $category_name (used to derive the term slug too) |
|
304 | + * @param string $category_description |
|
305 | + * @param int $parent_term_taxonomy_id |
|
306 | + * @return EE_Term_Taxonomy |
|
307 | + */ |
|
308 | + public function add_event_category( |
|
309 | + EE_CPT_Base $cpt_model_object, |
|
310 | + $category_name, |
|
311 | + $category_description = '', |
|
312 | + $parent_term_taxonomy_id = null |
|
313 | + ) { |
|
314 | + // create term |
|
315 | + require_once(EE_MODELS . 'EEM_Term.model.php'); |
|
316 | + // first, check for a term by the same name or slug |
|
317 | + $category_slug = sanitize_title($category_name); |
|
318 | + $term = EEM_Term::instance()->get_one( |
|
319 | + array( |
|
320 | + array( |
|
321 | + 'OR' => array( |
|
322 | + 'name' => $category_name, |
|
323 | + 'slug' => $category_slug, |
|
324 | + ), |
|
325 | + 'Term_Taxonomy.taxonomy' => self::EVENT_CATEGORY_TAXONOMY |
|
326 | + ), |
|
327 | + ) |
|
328 | + ); |
|
329 | + if (! $term) { |
|
330 | + $term = EE_Term::new_instance( |
|
331 | + array( |
|
332 | + 'name' => $category_name, |
|
333 | + 'slug' => $category_slug, |
|
334 | + ) |
|
335 | + ); |
|
336 | + $term->save(); |
|
337 | + } |
|
338 | + // make sure there's a term-taxonomy entry too |
|
339 | + require_once(EE_MODELS . 'EEM_Term_Taxonomy.model.php'); |
|
340 | + $term_taxonomy = EEM_Term_Taxonomy::instance()->get_one( |
|
341 | + array( |
|
342 | + array( |
|
343 | + 'term_id' => $term->ID(), |
|
344 | + 'taxonomy' => self::EVENT_CATEGORY_TAXONOMY, |
|
345 | + ), |
|
346 | + ) |
|
347 | + ); |
|
348 | + /** @var $term_taxonomy EE_Term_Taxonomy */ |
|
349 | + if (! $term_taxonomy) { |
|
350 | + $term_taxonomy = EE_Term_Taxonomy::new_instance( |
|
351 | + array( |
|
352 | + 'term_id' => $term->ID(), |
|
353 | + 'taxonomy' => self::EVENT_CATEGORY_TAXONOMY, |
|
354 | + 'description' => $category_description, |
|
355 | + 'term_count' => 1, |
|
356 | + 'parent' => $parent_term_taxonomy_id, |
|
357 | + ) |
|
358 | + ); |
|
359 | + $term_taxonomy->save(); |
|
360 | + } else { |
|
361 | + $term_taxonomy->set_count($term_taxonomy->count() + 1); |
|
362 | + $term_taxonomy->save(); |
|
363 | + } |
|
364 | + return $this->add_relationship_to($cpt_model_object, $term_taxonomy, 'Term_Taxonomy'); |
|
365 | + } |
|
366 | + |
|
367 | + |
|
368 | + /** |
|
369 | + * Removed the category specified by name as having a relation to this event. |
|
370 | + * Does not remove the term or term_taxonomy. |
|
371 | + * |
|
372 | + * @param EE_CPT_Base $cpt_model_object_event |
|
373 | + * @param string $category_name name of the event category (term) |
|
374 | + * @return bool |
|
375 | + */ |
|
376 | + public function remove_event_category(EE_CPT_Base $cpt_model_object_event, $category_name) |
|
377 | + { |
|
378 | + // find the term_taxonomy by that name |
|
379 | + $term_taxonomy = $this->get_first_related( |
|
380 | + $cpt_model_object_event, |
|
381 | + 'Term_Taxonomy', |
|
382 | + array(array('Term.name' => $category_name, 'taxonomy' => self::EVENT_CATEGORY_TAXONOMY)) |
|
383 | + ); |
|
384 | + /** @var $term_taxonomy EE_Term_Taxonomy */ |
|
385 | + if ($term_taxonomy) { |
|
386 | + $term_taxonomy->set_count($term_taxonomy->count() - 1); |
|
387 | + $term_taxonomy->save(); |
|
388 | + } |
|
389 | + return $this->remove_relationship_to($cpt_model_object_event, $term_taxonomy, 'Term_Taxonomy'); |
|
390 | + } |
|
391 | + |
|
392 | + |
|
393 | + /** |
|
394 | + * This is a wrapper for the WordPress get_the_post_thumbnail() function that returns the feature image for the |
|
395 | + * given CPT ID. It accepts the same params as what get_the_post_thumbnail() accepts. |
|
396 | + * |
|
397 | + * @link http://codex.wordpress.org/Function_Reference/get_the_post_thumbnail |
|
398 | + * @access public |
|
399 | + * @param int $id the ID for the cpt we want the feature image for |
|
400 | + * @param string|array $size (optional) Image size. Defaults to 'post-thumbnail' but can also be a 2-item array |
|
401 | + * representing width and height in pixels (i.e. array(32,32) ). |
|
402 | + * @param string|array $attr Optional. Query string or array of attributes. |
|
403 | + * @return string HTML image element |
|
404 | + */ |
|
405 | + public function get_feature_image($id, $size = 'thumbnail', $attr = '') |
|
406 | + { |
|
407 | + return get_the_post_thumbnail($id, $size, $attr); |
|
408 | + } |
|
409 | + |
|
410 | + |
|
411 | + /** |
|
412 | + * Just a handy way to get the list of post statuses currently registered with WP. |
|
413 | + * |
|
414 | + * @global array $wp_post_statuses set in wp core for storing all the post stati |
|
415 | + * @return array |
|
416 | + */ |
|
417 | + public function get_post_statuses() |
|
418 | + { |
|
419 | + global $wp_post_statuses; |
|
420 | + $statuses = array(); |
|
421 | + foreach ($wp_post_statuses as $post_status => $args_object) { |
|
422 | + $statuses[ $post_status ] = $args_object->label; |
|
423 | + } |
|
424 | + return $statuses; |
|
425 | + } |
|
426 | + |
|
427 | + |
|
428 | + /** |
|
429 | + * public method that can be used to retrieve the protected status array on the instantiated cpt model |
|
430 | + * |
|
431 | + * @return array array of statuses. |
|
432 | + */ |
|
433 | + public function get_status_array() |
|
434 | + { |
|
435 | + $statuses = $this->get_post_statuses(); |
|
436 | + // first the global filter |
|
437 | + $statuses = apply_filters('FHEE_EEM_CPT_Base__get_status_array', $statuses); |
|
438 | + // now the class specific filter |
|
439 | + $statuses = apply_filters('FHEE_EEM_' . get_class($this) . '__get_status_array', $statuses); |
|
440 | + return $statuses; |
|
441 | + } |
|
442 | + |
|
443 | + |
|
444 | + /** |
|
445 | + * this returns the post statuses that are NOT the default wordpress status |
|
446 | + * |
|
447 | + * @return array |
|
448 | + */ |
|
449 | + public function get_custom_post_statuses() |
|
450 | + { |
|
451 | + $new_stati = array(); |
|
452 | + foreach ($this->_custom_stati as $status => $props) { |
|
453 | + $new_stati[ $status ] = $props['label']; |
|
454 | + } |
|
455 | + return $new_stati; |
|
456 | + } |
|
457 | + |
|
458 | + |
|
459 | + /** |
|
460 | + * Creates a child of EE_CPT_Base given a WP_Post or array of wpdb results which |
|
461 | + * are a row from the posts table. If we're missing any fields required for the model, |
|
462 | + * we just fetch the entire entry from the DB (ie, if you want to use this to save DB queries, |
|
463 | + * make sure you are attaching all the model's fields onto the post) |
|
464 | + * |
|
465 | + * @param WP_Post|array $post |
|
466 | + * @return EE_Base_Class|EE_Soft_Delete_Base_Class |
|
467 | + */ |
|
468 | + public function instantiate_class_from_post_object_orig($post) |
|
469 | + { |
|
470 | + $post = (array) $post; |
|
471 | + $has_all_necessary_fields_for_table = true; |
|
472 | + // check if the post has fields on the meta table already |
|
473 | + foreach ($this->_get_other_tables() as $table_obj) { |
|
474 | + $fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias()); |
|
475 | + foreach ($fields_for_that_table as $field_obj) { |
|
476 | + if ( |
|
477 | + ! isset($post[ $field_obj->get_table_column() ]) |
|
478 | + && ! isset($post[ $field_obj->get_qualified_column() ]) |
|
479 | + ) { |
|
480 | + $has_all_necessary_fields_for_table = false; |
|
481 | + } |
|
482 | + } |
|
483 | + } |
|
484 | + // if we don't have all the fields we need, then just fetch the proper model from the DB |
|
485 | + if (! $has_all_necessary_fields_for_table) { |
|
486 | + return $this->get_one_by_ID($post['ID']); |
|
487 | + } else { |
|
488 | + return $this->instantiate_class_from_array_or_object($post); |
|
489 | + } |
|
490 | + } |
|
491 | + |
|
492 | + |
|
493 | + /** |
|
494 | + * @param null $post |
|
495 | + * @return EE_Base_Class|EE_Soft_Delete_Base_Class |
|
496 | + */ |
|
497 | + public function instantiate_class_from_post_object($post = null) |
|
498 | + { |
|
499 | + if (empty($post)) { |
|
500 | + global $post; |
|
501 | + } |
|
502 | + $post = (array) $post; |
|
503 | + $tables_needing_to_be_queried = array(); |
|
504 | + // check if the post has fields on the meta table already |
|
505 | + foreach ($this->get_tables() as $table_obj) { |
|
506 | + $fields_for_that_table = $this->_get_fields_for_table($table_obj->get_table_alias()); |
|
507 | + foreach ($fields_for_that_table as $field_obj) { |
|
508 | + if ( |
|
509 | + ! isset($post[ $field_obj->get_table_column() ]) |
|
510 | + && ! isset($post[ $field_obj->get_qualified_column() ]) |
|
511 | + ) { |
|
512 | + $tables_needing_to_be_queried[ $table_obj->get_table_alias() ] = $table_obj; |
|
513 | + } |
|
514 | + } |
|
515 | + } |
|
516 | + // if we don't have all the fields we need, then just fetch the proper model from the DB |
|
517 | + if ($tables_needing_to_be_queried) { |
|
518 | + if ( |
|
519 | + count($tables_needing_to_be_queried) == 1 |
|
520 | + && reset($tables_needing_to_be_queried) |
|
521 | + instanceof |
|
522 | + EE_Secondary_Table |
|
523 | + ) { |
|
524 | + // so we're only missing data from a secondary table. Well that's not too hard to query for |
|
525 | + $table_to_query = reset($tables_needing_to_be_queried); |
|
526 | + $missing_data = $this->_do_wpdb_query( |
|
527 | + 'get_row', |
|
528 | + array( |
|
529 | + 'SELECT * FROM ' |
|
530 | + . $table_to_query->get_table_name() |
|
531 | + . ' WHERE ' |
|
532 | + . $table_to_query->get_fk_on_table() |
|
533 | + . ' = ' |
|
534 | + . $post['ID'], |
|
535 | + ARRAY_A, |
|
536 | + ) |
|
537 | + ); |
|
538 | + if (! empty($missing_data)) { |
|
539 | + $post = array_merge($post, $missing_data); |
|
540 | + } |
|
541 | + } else { |
|
542 | + return $this->get_one_by_ID($post['ID']); |
|
543 | + } |
|
544 | + } |
|
545 | + return $this->instantiate_class_from_array_or_object($post); |
|
546 | + } |
|
547 | + |
|
548 | + |
|
549 | + /** |
|
550 | + * Gets the post type associated with this |
|
551 | + * |
|
552 | + * @throws EE_Error |
|
553 | + * @return string |
|
554 | + */ |
|
555 | + public function post_type() |
|
556 | + { |
|
557 | + $post_type_field = null; |
|
558 | + foreach ($this->field_settings(true) as $field_obj) { |
|
559 | + if ($field_obj instanceof EE_WP_Post_Type_Field) { |
|
560 | + $post_type_field = $field_obj; |
|
561 | + break; |
|
562 | + } |
|
563 | + } |
|
564 | + if ($post_type_field == null) { |
|
565 | + throw new EE_Error( |
|
566 | + sprintf( |
|
567 | + esc_html__( |
|
568 | + "CPT Model %s should have a field of type EE_WP_Post_Type, but doesnt", |
|
569 | + "event_espresso" |
|
570 | + ), |
|
571 | + get_class($this) |
|
572 | + ) |
|
573 | + ); |
|
574 | + } |
|
575 | + return $post_type_field->get_default_value(); |
|
576 | + } |
|
577 | 577 | } |