PluginProbe ʕ •ᴥ•ʔ
LatePoint – Calendar Booking Plugin for Appointments and Events / 5.2.9
LatePoint – Calendar Booking Plugin for Appointments and Events v5.2.9
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 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 / wizard_controller.php
latepoint / lib / controllers Last commit date
activities_controller.php 5 months ago auth_controller.php 9 months ago booking_form_settings_controller.php 4 months ago bookings_controller.php 1 year ago calendars_controller.php 9 months ago carts_controller.php 1 year ago controller.php 9 months ago customer_cabinet_controller.php 9 months ago customers_controller.php 4 months ago dashboard_controller.php 9 months ago default_agent_controller.php 1 year ago events_controller.php 1 year ago form_fields_controller.php 9 months ago integrations_controller.php 9 months 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 4 months ago pro_controller.php 1 year ago process_jobs_controller.php 9 months ago processes_controller.php 1 year ago search_controller.php 1 year ago services_controller.php 9 months ago settings_controller.php 5 months ago steps_controller.php 9 months ago stripe_connect_controller.php 9 months ago support_topics_controller.php 1 year ago todos_controller.php 1 year ago transactions_controller.php 1 year ago wizard_controller.php 5 months ago
wizard_controller.php
315 lines
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit; // Exit if accessed directly.
4 }
5
6
7 if ( ! class_exists( 'OsWizardController' ) ) :
8
9
10 class OsWizardController extends OsController {
11
12 var $steps_info, $steps_in_order;
13
14 protected $show_next_btn = false,
15 $show_prev_btn = false;
16
17
18 function __construct() {
19 parent::__construct();
20
21 $this->views_folder = LATEPOINT_VIEWS_ABSPATH . 'wizard/';
22 $this->vars['page_header'] = __( 'Wizard', 'latepoint' );
23
24 $this->set_layout( 'wizard' );
25 $this->steps_info = array(
26 'default_agent' => array(
27 'show_in_sidemenu' => true,
28 'name' => __( 'Setup Notifications', 'latepoint' )
29 ),
30 'agents' => array( 'show_in_sidemenu' => true, 'name' => __( 'Create Agents', 'latepoint' ) ),
31 'intro' => array( 'show_in_sidemenu' => false, 'name' => __( 'Intro', 'latepoint' ) ),
32 'services' => array( 'show_in_sidemenu' => true, 'name' => __( 'Add Services', 'latepoint' ) ),
33 'work_periods' => array(
34 'show_in_sidemenu' => true,
35 'name' => __( 'Set Working Hours', 'latepoint' )
36 ),
37 'info' => array(
38 'show_in_sidemenu' => true,
39 'name' => __( 'Fill Business Info', 'latepoint' )
40 ),
41 'complete' => array( 'show_in_sidemenu' => true, 'name' => __( 'Setup Complete', 'latepoint' ) ),
42 );
43 $this->steps_in_order = array( 'intro', 'default_agent', 'services', 'work_periods', 'complete' );
44
45 $this->vars['steps_in_order'] = $this->steps_in_order;
46 $this->vars['steps_info'] = $this->steps_info;
47 }
48
49 function save_service() {
50 $this->check_nonce( 'save_service' );
51 $service = new OsServiceModel();
52 $service->set_data( $this->params['service'] );
53
54 if ( $service->save() && $service->save_agents_and_locations( $this->params['service']['agents'] ) ) {
55 $this->vars['current_step_code'] = 'agents';
56 $this->step_services();
57 $response_html = $this->render( $this->get_view_uri( 'steps/_list_services' ) );
58 $status = LATEPOINT_STATUS_SUCCESS;
59 } else {
60 $response_html = $service->get_error_messages();
61 $status = LATEPOINT_STATUS_ERROR;
62 }
63 if ( $this->get_return_format() == 'json' ) {
64 $this->send_json( array( 'status' => $status,
65 'message' => $response_html,
66 'show_prev_btn' => true,
67 'show_next_btn' => $this->show_next_btn
68 ) );
69 }
70 }
71
72 function save_agent() {
73 $this->check_nonce( 'save_agent' );
74 $agent = new OsAgentModel();
75 $agent->set_data( $this->params['agent'] );
76 if ( $agent->save() ) {
77 $this->vars['current_step_code'] = 'agents';
78 $this->step_agents();
79 $response_html = $this->render( $this->get_view_uri( 'steps/_list_agents' ) );
80 $status = LATEPOINT_STATUS_SUCCESS;
81 } else {
82 $response_html = $agent->get_error_messages();
83 $status = LATEPOINT_STATUS_ERROR;
84 }
85 if ( $this->get_return_format() == 'json' ) {
86 $this->send_json( array( 'status' => $status,
87 'message' => $response_html,
88 'show_prev_btn' => $this->show_prev_btn,
89 'show_next_btn' => $this->show_next_btn
90 ) );
91 }
92 }
93
94
95 function setup() {
96 $current_step_code = $this->steps_in_order[0];
97 $step_function_name = 'step_' . $current_step_code;
98 self::$step_function_name();
99
100 add_option( 'latepoint_wizard_visited', true );
101
102 $this->vars['current_step_code'] = $current_step_code;
103 $this->vars['current_step_number'] = array_search( $current_step_code, $this->steps_in_order );
104 $this->vars['step_file_to_include'] = 'steps/_' . $current_step_code . '.php';
105
106 $this->format_render( __FUNCTION__ );
107 }
108
109 function next_step() {
110 $this->show_prev_btn = true;
111 $this->show_next_btn = true;
112
113 // Check if a valid step_code name
114 if ( isset( $this->steps_info[ $this->params['current_step_code'] ] ) ) {
115 $current_step_code = $this->params['current_step_code'];
116 } else {
117 $current_step_code = $this->steps_in_order[0];
118 }
119
120
121 $process_step_function_name = 'process_step_' . $current_step_code;
122 self::$process_step_function_name();
123
124 $new_current_step_code = $this->steps_in_order[ array_search( $current_step_code, $this->steps_in_order ) + 1 ];
125 if ( array_search( $new_current_step_code, $this->steps_in_order ) <= 1 ) {
126 $this->show_prev_btn = false;
127 }
128
129 $step_function_name = 'step_' . $new_current_step_code;
130 self::$step_function_name();
131
132 $this->vars['current_step_code'] = $new_current_step_code;
133 $this->vars['current_step_number'] = array_search( $new_current_step_code, $this->steps_in_order );
134 $this->format_render( 'steps/_' . $new_current_step_code, array(), array( 'step_code' => $new_current_step_code,
135 'show_prev_btn' => $this->show_prev_btn,
136 'show_next_btn' => $this->show_next_btn
137 ) );
138 }
139
140 function prev_step() {
141 // Check if a valid step_code name
142 if ( isset( $this->steps_info[ $this->params['current_step_code'] ] ) ) {
143 $current_step_code = $this->params['current_step_code'];
144 } else {
145 $current_step_code = $this->steps_in_order[0];
146 }
147
148 $new_current_step_code = ( array_search( $current_step_code, $this->steps_in_order ) > 0 ) ? $this->steps_in_order[ array_search( $current_step_code, $this->steps_in_order ) - 1 ] : $this->steps_in_order[0];
149 $this->show_prev_btn = array_search( $new_current_step_code, $this->steps_in_order ) > 0;
150
151 if ( array_search( $new_current_step_code, $this->steps_in_order ) <= 1 ) {
152 $this->show_prev_btn = false;
153 }
154
155 $step_function_name = 'step_' . $new_current_step_code;
156 self::$step_function_name();
157
158 $this->vars['current_step_code'] = $new_current_step_code;
159 $this->vars['current_step_number'] = array_search( $new_current_step_code, $this->steps_in_order );
160 $this->format_render( 'steps/_' . $new_current_step_code, array(), array( 'step_code' => $new_current_step_code,
161 'show_prev_btn' => $this->show_prev_btn,
162 'show_next_btn' => $this->show_next_btn
163 ) );
164 }
165
166 function load_step() {
167 // Check if a valid step_code name
168 if ( isset( $this->steps_info[ $this->params['current_step_code'] ] ) ) {
169 $current_step_code = $this->params['current_step_code'];
170 } else {
171 $current_step_code = $this->steps_in_order[0];
172 }
173
174 $step_function_name = 'step_' . $current_step_code;
175 self::$step_function_name();
176
177 $this->vars['current_step_code'] = $current_step_code;
178 $this->vars['current_step_number'] = array_search( $current_step_code, $this->steps_in_order );
179 $this->format_render( 'steps/_' . $current_step_code, array(), array( 'step_code' => $current_step_code ) );
180 }
181
182 function add_or_edit_agent() {
183 $agents = new OsAgentModel();
184 $this->vars['agents'] = $agents->get_results_as_models();
185
186 $agent = new OsAgentModel();
187 if ( ! empty( $this->params['id'] ) && is_numeric( $this->params['id'] ) ) {
188 $agent->load_by_id( $this->params['id'] );
189 }
190 $this->vars['agent'] = $agent;
191 $this->format_render( 'steps/_form_agent', array(), array() );
192 }
193
194 function add_or_edit_service() {
195 $services = new OsServiceModel();
196 $this->vars['services'] = $services->get_results_as_models();
197
198 $service = new OsServiceModel();
199 if ( isset( $this->params['id'] ) && is_numeric( $this->params['id'] ) ) {
200 $service->load_by_id( $this->params['id'] );
201 }
202 $agents = new OsAgentModel();
203 $service_categories = new OsServiceCategoryModel();
204
205 $this->vars['service_categories_for_select'] = $service_categories->index_for_select();
206 $this->vars['agents'] = $agents->get_results_as_models();
207 $this->vars['location'] = OsLocationHelper::get_default_location();
208
209 $this->vars['service'] = $service;
210 $this->format_render( 'steps/_form_service', array(), array() );
211 }
212
213
214 function step_services() {
215 $services = new OsServiceModel();
216 $services = $services->get_results_as_models();
217 $this->show_prev_btn = false;
218 $this->vars['services'] = $services;
219 $this->vars['location'] = OsLocationHelper::get_default_location();
220 $agents = new OsAgentModel();
221 $this->vars['agents'] = $agents->get_results_as_models();
222 if ( ! $services ) {
223 $service = new OsServiceModel();
224 $this->vars['service'] = $service;
225 $this->show_next_btn = false;
226 } else {
227 $this->show_next_btn = true;
228 $this->show_prev_btn = true;
229 }
230 }
231
232 function step_agents() {
233 $agents = new OsAgentModel();
234 $agents = $agents->get_results_as_models();
235 $this->vars['agents'] = $agents;
236 $this->show_prev_btn = false;
237 if ( ! $agents ) {
238 $agent = new OsAgentModel();
239 $this->vars['agent'] = $agent;
240 $this->show_next_btn = false;
241 } else {
242 $this->show_next_btn = true;
243 }
244 }
245
246
247 function step_default_agent(){
248
249 $this->vars['agent'] = OsAgentHelper::get_default_agent();
250 $this->show_next_btn = true;
251 }
252
253 function step_work_periods() {
254 $work_periods = OsWorkPeriodsHelper::get_work_periods( new \LatePoint\Misc\Filter() );
255 $working_periods_with_weekdays = array();
256 if ( $work_periods ) {
257 foreach ( $work_periods as $work_period ) {
258 $working_periods_with_weekdays[ 'day_' . $work_period->week_day ][] = $work_period;
259 }
260 }
261 $this->vars['working_periods_with_weekdays'] = $working_periods_with_weekdays;
262 }
263
264 function step_intro() {
265 $this->show_next_btn = true;
266 }
267
268
269 function step_settings() {
270
271 }
272
273 function step_complete() {
274 $this->show_next_btn = false;
275 $this->show_prev_btn = false;
276 }
277
278
279 function process_step_agents() {
280
281 }
282
283 function process_step_services() {
284
285 }
286
287 function process_step_intro() {
288
289 }
290
291 function process_step_default_agent() {
292
293 $default_agent = OsAgentHelper::get_default_agent();
294 if ( ! $default_agent->is_new_record() ) {
295 $default_agent->set_data( $this->params['agent'] );
296 $default_agent->save();
297 }
298
299 }
300
301 function process_step_work_periods() {
302 $work_periods_form_data = $this->params['work_periods'];
303 OsWorkPeriodsHelper::save_work_periods( $work_periods_form_data );
304 }
305
306 function process_step_info() {
307
308 }
309
310
311 }
312
313
314 endif;
315