PluginProbe
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress / 5.2.4
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress v5.2.4
5.6.11 5.6.10 5.6.9 5.6.8 5.6.7 5.6.6 5.6.5 5.6.4 5.6.3 5.6.2 5.6.1 5.6.0 5.5.2 5.5.1 5.5.0 5.4.2 trunk 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 All 48 releases
← All changes | lib/controllers/services_controller.php +55 -103 trunk5.2.4 View file →
@@ -15,12 +15,9 @@
15 15
16 16 $this->views_folder = LATEPOINT_VIEWS_ABSPATH . 'services/';
17 17 $this->vars['page_header'] = OsMenuHelper::get_menu_items_by_id( 'services' );
18 18 $this->vars['pre_page_header'] = OsMenuHelper::get_label_by_id( 'services' );
19 - $this->vars['breadcrumbs'][] = array(
20 - 'label' => __( 'Services', 'latepoint' ),
21 - 'link' => OsRouterHelper::build_link( OsRouterHelper::build_route_name( 'services', 'index' ) ),
22 - );
19 + $this->vars['breadcrumbs'][] = array( 'label' => __( 'Services', 'latepoint' ), 'link' => OsRouterHelper::build_link( OsRouterHelper::build_route_name( 'services', 'index' ) ) );
23 20 }
24 21
25 22 /*
26 23 Edit service
@@ -30,12 +27,9 @@
30 27 $service_id = $this->params['id'];
31 28
32 29 $this->vars['pre_page_header'] = '';
33 30 $this->vars['page_header'] = __( 'Edit Service', 'latepoint' );
34 - $this->vars['breadcrumbs'][] = array(
35 - 'label' => __( 'Edit Service', 'latepoint' ),
36 - 'link' => false,
37 - );
31 + $this->vars['breadcrumbs'][] = array( 'label' => __( 'Edit Service', 'latepoint' ), 'link' => false );
38 32
39 33
40 34 $service = new OsServiceModel( $service_id );
41 35 $service_categories = new OsServiceCategoryModel();
@@ -47,17 +41,9 @@
47 41 $this->vars['service_categories_for_select'] = $service_categories->index_for_select();
48 42 $this->vars['agents'] = $agents->get_results_as_models();
49 43 $this->vars['locations'] = $locations->get_results_as_models();
50 44
51 - $custom_work_periods = OsWorkPeriodsHelper::get_work_periods(
52 - new \LatePoint\Misc\Filter(
53 - [
54 - 'service_id' => $service_id,
55 - 'exact_match' => true,
56 - ]
57 - ),
58 - true
59 - );
45 + $custom_work_periods = OsWorkPeriodsHelper::get_work_periods( new \LatePoint\Misc\Filter( [ 'service_id' => $service_id, 'exact_match' => true ] ), true );
60 46 $this->vars['custom_work_periods'] = $custom_work_periods;
61 47 $this->vars['is_custom_schedule'] = ( $custom_work_periods && ( count( $custom_work_periods ) > 0 ) );
62 48
63 49 $this->format_render( __FUNCTION__ );
@@ -70,12 +56,9 @@
70 56
71 57 public function new_form() {
72 58 $this->vars['pre_page_header'] = '';
73 59 $this->vars['page_header'] = __( 'New Service', 'latepoint' );
74 - $this->vars['breadcrumbs'][] = array(
75 - 'label' => __( 'Create New Service', 'latepoint' ),
76 - 'link' => false,
77 - );
60 + $this->vars['breadcrumbs'][] = array( 'label' => __( 'Create New Service', 'latepoint' ), 'link' => false );
78 61
79 62
80 63 $service = new OsServiceModel();
81 64 $service_categories = new OsServiceCategoryModel();
@@ -112,22 +95,20 @@
112 95
113 96
114 97 $this->vars['service_categories'] = $service_categories;
115 98
116 - $uncategorized_services = new OsServiceModel();
117 - $this->vars['uncategorized_services'] = $uncategorized_services->filter_allowed_records()->should_be_active()->where(
118 - array(
119 - 'category_id' => [
120 - 'OR' => [
121 - 0,
122 - 'IS NULL',
123 - ],
124 - ],
125 - )
126 - )->order_by( 'order_number asc' )->get_results_as_models();
99 + $uncategorized_services = new OsServiceModel();
100 + $this->vars['uncategorized_services'] = $uncategorized_services->filter_allowed_records()->should_be_active()->where( array(
101 + 'category_id' => [
102 + 'OR' => [
103 + 0,
104 + 'IS NULL'
105 + ]
106 + ]
107 + ) )->order_by( 'order_number asc' )->get_results_as_models();
127 108
128 - $disabled_services = new OsServiceModel();
129 - $this->vars['disabled_services'] = $disabled_services->filter_allowed_records()->where( [ 'status' => LATEPOINT_SERVICE_STATUS_DISABLED ] )->get_results_as_models();
109 + $disabled_services = new OsServiceModel();
110 + $this->vars['disabled_services'] = $disabled_services->filter_allowed_records()->where( [ 'status' => LATEPOINT_SERVICE_STATUS_DISABLED ] )->get_results_as_models();
130 111
131 112 $this->format_render( __FUNCTION__ );
132 113 }
133 114
@@ -158,22 +139,12 @@
158 139
159 140 if ( $service->save() && $service->save_durations( $this->params['service']['durations'] ) && $service->save_agents_and_locations( $this->params['service']['agents'] ) ) {
160 141 if ( $is_new_record ) {
161 142 $response_html = __( 'Service Created. ID:', 'latepoint' ) . $service->id;
162 - OsActivitiesHelper::create_activity(
163 - array(
164 - 'code' => 'service_created',
165 - 'service_id' => $service->id,
166 - )
167 - );
143 + OsActivitiesHelper::create_activity( array( 'code' => 'service_created', 'service_id' => $service->id ) );
168 144 } else {
169 145 $response_html = __( 'Service Updated. ID:', 'latepoint' ) . $service->id;
170 - OsActivitiesHelper::create_activity(
171 - array(
172 - 'code' => 'service_updated',
173 - 'service_id' => $service->id,
174 - )
175 - );
146 + OsActivitiesHelper::create_activity( array( 'code' => 'service_updated', 'service_id' => $service->id ) );
176 147 }
177 148 $status = LATEPOINT_STATUS_SUCCESS;
178 149 // save schedules
179 150 if ( $this->params['is_custom_schedule'] == 'on' ) {
@@ -187,14 +158,9 @@
187 158 $response_html = $service->get_error_messages();
188 159 $status = LATEPOINT_STATUS_ERROR;
189 160 }
190 161 if ( $this->get_return_format() == 'json' ) {
191 - $this->send_json(
192 - array(
193 - 'status' => $status,
194 - 'message' => $response_html,
195 - ) + $extra_response_vars
196 - );
162 + $this->send_json( array( 'status' => $status, 'message' => $response_html ) + $extra_response_vars );
197 163 }
198 164 }
199 165
200 166
@@ -218,73 +184,63 @@
218 184 $response_html = __( 'Error Removing Service', 'latepoint' );
219 185 }
220 186
221 187 if ( $this->get_return_format() == 'json' ) {
222 - $this->send_json(
223 - array(
224 - 'status' => $status,
225 - 'message' => $response_html,
226 - )
227 - );
188 + $this->send_json( array( 'status' => $status, 'message' => $response_html ) );
228 189 }
229 190 }
230 191
231 - public function duplicate() {
232 - if ( filter_var( $this->params['id'], FILTER_VALIDATE_INT ) ) {
192 + public function duplicate( ) {
193 + if(filter_var($this->params['id'], FILTER_VALIDATE_INT)) {
233 194 $this->check_nonce( 'duplicate_service_' . $this->params['id'] );
234 195
235 - $original_service = new OsServiceModel( $this->params['id'] );
236 - $cloned_service = clone $original_service;
237 - $cloned_service->id = null; // reset ID to create a new record
238 - $cloned_service->name = $cloned_service->name . ' - ' . __( 'Copy', 'latepoint' );
196 + $original_service = new OsServiceModel( $this->params['id'] );
197 + $cloned_service = clone $original_service;
198 + $cloned_service->id = null; // reset ID to create a new record
199 + $cloned_service->name = $cloned_service->name . ' - ' . __('Copy', 'latepoint');
239 200
240 - if ( $cloned_service->save() ) {
241 - $status = LATEPOINT_STATUS_SUCCESS;
242 - $response_html = OsRouterHelper::build_link( OsRouterHelper::build_route_name( 'services', 'edit_form' ), array( 'id' => $cloned_service->id ) );
243 - OsActivitiesHelper::create_activity(
244 - array(
245 - 'code' => 'service_created',
246 - 'service_id' => $cloned_service->id,
247 - )
248 - );
201 + if($cloned_service->save()){
202 + $status = LATEPOINT_STATUS_SUCCESS;
203 + $response_html = OsRouterHelper::build_link( OsRouterHelper::build_route_name( 'services', 'edit_form' ), array('id' => $cloned_service->id) );
204 + OsActivitiesHelper::create_activity( array( 'code' => 'service_created', 'service_id' => $cloned_service->id ) );
249 205
250 206 $work_periods = new OsWorkPeriodModel();
251 - $work_periods = $work_periods->where( [ 'service_id' => $original_service->id ] )->get_results_as_models();
252 - foreach ( $work_periods as $work_period ) {
253 - $new_period = clone $work_period;
254 - $new_period->id = null; // reset ID to create a new record
207 + $work_periods = $work_periods->where(['service_id' => $original_service->id])->get_results_as_models();
208 + foreach($work_periods as $work_period){
209 + $new_period = clone $work_period;
210 + $new_period->id = null; // reset ID to create a new record
255 211 $new_period->service_id = $cloned_service->id; // set new service ID
256 212 $new_period->save();
257 213 }
258 214
259 215 $connection_model = new OsConnectorModel();
260 - $connectors = $connection_model->where( [ 'service_id' => $original_service->id ] )->get_results_as_models();
216 + $connectors = $connection_model->where(['service_id' => $original_service->id])->get_results_as_models();
261 217
262 - foreach ( $connectors as $connector ) {
263 - $new_connector = clone $connector;
264 - $new_connector->id = null;
218 + foreach($connectors as $connector){
219 + $new_connector = clone $connector;
220 + $new_connector->id = null;
265 221 $new_connector->service_id = $cloned_service->id; // set new location ID
266 222 $new_connector->save();
267 223 }
268 224
269 - $meta = new OsServiceMetaModel();
270 - $meta_items = $meta->where( [ 'object_id' => $original_service->id ] )
271 - ->where_not_in( 'meta_key', [ 'woocommerce_product_id', 'surecart_product_id' ] )
272 - ->get_results_as_models();
273 - foreach ( $meta_items as $meta_item ) {
274 - $new_meta_item = clone $meta_item;
275 - $new_meta_item->id = null;
225 + $meta = new OsServiceMetaModel();
226 + $meta_items = $meta->where(['object_id' => $original_service->id])
227 + ->where_not_in('meta_key', ['woocommerce_product_id', 'surecart_product_id'])
228 + ->get_results_as_models();
229 + foreach($meta_items as $meta_item){
230 + $new_meta_item = clone $meta_item;
231 + $new_meta_item->id = null;
276 232 $new_meta_item->object_id = $cloned_service->id;
277 233 $new_meta_item->save();
278 234 }
279 235
280 236 #available in pro version only
281 - if ( class_exists( 'OsServiceExtraConnectorModel' ) ) {
237 + if (class_exists('OsServiceExtraConnectorModel')) {
282 238 $extras = new OsServiceExtraConnectorModel();
283 - $extras = $extras->where( [ 'service_id' => $original_service->id ] )->get_results_as_models();
284 - foreach ( $extras as $extra ) {
285 - $new_extra = clone $extra;
286 - $new_extra->id = null;
239 + $extras = $extras->where(['service_id' => $original_service->id])->get_results_as_models();
240 + foreach($extras as $extra){
241 + $new_extra = clone $extra;
242 + $new_extra->id = null;
287 243 $new_extra->service_id = $cloned_service->id;
288 244 $new_extra->save();
289 245 }
290 246 }
@@ -289,21 +245,17 @@
289 245 }
290 246 }
291 247 }
292 248 } else {
293 - $status = LATEPOINT_STATUS_ERROR;
294 - $response_html = __( 'Error Creating Service', 'latepoint' );
249 + $status = LATEPOINT_STATUS_ERROR;
250 + $response_html = __('Error Creating Service', 'latepoint');
295 251 }
296 252
297 - if ( $this->get_return_format() == 'json' ) {
298 - $this->send_json(
299 - array(
300 - 'status' => $status,
301 - 'message' => $response_html,
302 - )
303 - );
253 + if($this->get_return_format() == 'json'){
254 + $this->send_json(array('status' => $status, 'message' => $response_html));
304 255 }
305 256 }
257 +
306 258 }
307 259
308 260
309 -endif;
261 +endif;