PluginProbe ʕ •ᴥ•ʔ
LatePoint – Calendar Booking Plugin for Appointments and Events / 5.1.6
LatePoint – Calendar Booking Plugin for Appointments and Events v5.1.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 5.1.8 5.1.9 5.1.91 5.1.92 5.1.93 5.1.94 5.2.0 5.2.1 5.2.10 5.2.11 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.0 5.3.1 5.3.2 5.4.0 5.4.1
latepoint / lib / controllers / services_controller.php
latepoint / lib / controllers Last commit date
activities_controller.php 1 year ago auth_controller.php 1 year ago booking_form_settings_controller.php 1 year ago bookings_controller.php 1 year ago calendars_controller.php 1 year ago carts_controller.php 1 year ago controller.php 1 year ago customer_cabinet_controller.php 1 year ago customers_controller.php 1 year ago dashboard_controller.php 1 year ago default_agent_controller.php 1 year ago events_controller.php 1 year ago form_fields_controller.php 1 year ago integrations_controller.php 1 year ago invoices_controller.php 1 year ago manage_booking_by_key_controller.php 1 year ago manage_order_by_key_controller.php 1 year ago notifications_controller.php 1 year ago orders_controller.php 1 year ago pro_controller.php 1 year ago process_jobs_controller.php 1 year ago processes_controller.php 1 year ago search_controller.php 1 year ago services_controller.php 1 year ago settings_controller.php 1 year ago steps_controller.php 1 year ago stripe_connect_controller.php 1 year ago support_topics_controller.php 1 year ago todos_controller.php 1 year ago transactions_controller.php 1 year ago wizard_controller.php 1 year ago
services_controller.php
193 lines
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit; // Exit if accessed directly.
4 }
5
6
7 if ( ! class_exists( 'OsServicesController' ) ) :
8
9
10 class OsServicesController extends OsController {
11
12
13 function __construct() {
14 parent::__construct();
15
16 $this->views_folder = LATEPOINT_VIEWS_ABSPATH . 'services/';
17 $this->vars['page_header'] = OsMenuHelper::get_menu_items_by_id( 'services' );
18 $this->vars['pre_page_header'] = OsMenuHelper::get_label_by_id( 'services' );
19 $this->vars['breadcrumbs'][] = array( 'label' => __( 'Services', 'latepoint' ), 'link' => OsRouterHelper::build_link( OsRouterHelper::build_route_name( 'services', 'index' ) ) );
20 }
21
22 /*
23 Edit service
24 */
25
26 public function edit_form() {
27 $service_id = $this->params['id'];
28
29 $this->vars['pre_page_header'] = '';
30 $this->vars['page_header'] = __( 'Edit Service', 'latepoint' );
31 $this->vars['breadcrumbs'][] = array( 'label' => __( 'Edit Service', 'latepoint' ), 'link' => false );
32
33
34 $service = new OsServiceModel( $service_id );
35 $service_categories = new OsServiceCategoryModel();
36 $agents = new OsAgentModel();
37 $locations = new OsLocationModel();
38
39
40 $this->vars['service'] = $service;
41 $this->vars['service_categories_for_select'] = $service_categories->index_for_select();
42 $this->vars['agents'] = $agents->get_results_as_models();
43 $this->vars['locations'] = $locations->get_results_as_models();
44
45 $custom_work_periods = OsWorkPeriodsHelper::get_work_periods( new \LatePoint\Misc\Filter( [ 'service_id' => $service_id, 'exact_match' => true ] ), true );
46 $this->vars['custom_work_periods'] = $custom_work_periods;
47 $this->vars['is_custom_schedule'] = ( $custom_work_periods && ( count( $custom_work_periods ) > 0 ) );
48
49 $this->format_render( __FUNCTION__ );
50 }
51
52
53 /*
54 New service form
55 */
56
57 public function new_form() {
58 $this->vars['pre_page_header'] = '';
59 $this->vars['page_header'] = __( 'New Service', 'latepoint' );
60 $this->vars['breadcrumbs'][] = array( 'label' => __( 'Create New Service', 'latepoint' ), 'link' => false );
61
62
63 $service = new OsServiceModel();
64 $service_categories = new OsServiceCategoryModel();
65 $agents = new OsAgentModel();
66 $locations = new OsLocationModel();
67
68
69 $service->bg_color = $service->generate_new_bg_color();
70
71 if ( isset( $this->params['service_category_id'] ) ) {
72 $service->category_id = $this->params['service_category_id'];
73 }
74
75 $this->vars['service'] = $service;
76 $this->vars['service_categories_for_select'] = $service_categories->index_for_select();
77 $this->vars['agents'] = $agents->get_results_as_models();
78 $this->vars['locations'] = $locations->get_results_as_models();
79
80 $this->vars['custom_work_periods'] = [];
81 $this->vars['is_custom_schedule'] = false;
82
83
84 $this->format_render( __FUNCTION__ );
85 }
86
87
88 /*
89 Index of services
90 */
91
92 public function index() {
93 $service_categories = new OsServiceCategoryModel();
94 $service_categories = $service_categories->order_by( 'order_number asc' )->get_results_as_models();
95
96
97 $this->vars['service_categories'] = $service_categories;
98
99 $services = new OsServiceModel();
100 $this->vars['uncategorized_services'] = $services->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();
108 $this->vars['disabled_services'] = $services->where( [ 'status' => LATEPOINT_SERVICE_STATUS_DISABLED ] )->get_results_as_models();
109
110 $this->format_render( __FUNCTION__ );
111 }
112
113
114 /*
115 Create service
116 */
117
118 public function create() {
119 $this->update();
120 }
121
122
123 /*
124 Update service
125 */
126
127 public function update() {
128 $is_new_record = ( isset( $this->params['service']['id'] ) && $this->params['service']['id'] ) ? false : true;
129
130 $this->check_nonce( $is_new_record ? 'new_service' : 'edit_service_' . $this->params['service']['id'] );
131 $service = new OsServiceModel();
132 $service->set_data( $this->params['service'] );
133 $extra_response_vars = array();
134
135 $this->params['service']['durations'] = isset( $this->params['service']['durations'] ) ? $this->params['service']['durations'] : [];
136 $this->params['service']['agents'] = isset( $this->params['service']['agents'] ) ? $this->params['service']['agents'] : [];
137
138 if ( $service->save() && $service->save_durations( $this->params['service']['durations'] ) && $service->save_agents_and_locations( $this->params['service']['agents'] ) ) {
139 if ( $is_new_record ) {
140 $response_html = __( 'Service Created. ID:', 'latepoint' ) . $service->id;
141 OsActivitiesHelper::create_activity( array( 'code' => 'service_create', 'service_id' => $service->id ) );
142 } else {
143 $response_html = __( 'Service Updated. ID:', 'latepoint' ) . $service->id;
144 OsActivitiesHelper::create_activity( array( 'code' => 'service_update', 'service_id' => $service->id ) );
145 }
146 $status = LATEPOINT_STATUS_SUCCESS;
147 // save schedules
148 if ( $this->params['is_custom_schedule'] == 'on' ) {
149 $service->save_custom_schedule( $this->params['work_periods'] );
150 } elseif ( $this->params['is_custom_schedule'] == 'off' ) {
151 $service->delete_custom_schedule();
152 }
153 $extra_response_vars['record_id'] = $service->id;
154 do_action( 'latepoint_service_saved', $service, $is_new_record, $this->params['service'] );
155 } else {
156 $response_html = $service->get_error_messages();
157 $status = LATEPOINT_STATUS_ERROR;
158 }
159 if ( $this->get_return_format() == 'json' ) {
160 $this->send_json( array( 'status' => $status, 'message' => $response_html ) + $extra_response_vars );
161 }
162 }
163
164
165 /*
166 Delete service
167 */
168
169 public function destroy() {
170 if ( filter_var( $this->params['id'], FILTER_VALIDATE_INT ) ) {
171 $this->check_nonce( 'destroy_service_' . $this->params['id'] );
172 $service = new OsServiceModel( $this->params['id'] );
173 if ( $service->delete() ) {
174 $status = LATEPOINT_STATUS_SUCCESS;
175 $response_html = __( 'Service Removed', 'latepoint' );
176 } else {
177 $status = LATEPOINT_STATUS_ERROR;
178 $response_html = __( 'Error Removing Service', 'latepoint' );
179 }
180 } else {
181 $status = LATEPOINT_STATUS_ERROR;
182 $response_html = __( 'Error Removing Service', 'latepoint' );
183 }
184
185 if ( $this->get_return_format() == 'json' ) {
186 $this->send_json( array( 'status' => $status, 'message' => $response_html ) );
187 }
188 }
189
190 }
191
192
193 endif;