PluginProbe ʕ •ᴥ•ʔ
LatePoint – Calendar Booking Plugin for Appointments and Events / 5.2.4
LatePoint – Calendar Booking Plugin for Appointments and Events v5.2.4
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 11 months ago auth_controller.php 9 months ago booking_form_settings_controller.php 1 year 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 9 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 1 year 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 1 year 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 1 year ago
wizard_controller.php
313 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 $service = new OsServiceModel();
51 $service->set_data( $this->params['service'] );
52
53 if ( $service->save() && $service->save_agents_and_locations( $this->params['service']['agents'] ) ) {
54 $this->vars['current_step_code'] = 'agents';
55 $this->step_services();
56 $response_html = $this->render( $this->get_view_uri( 'steps/_list_services' ) );
57 $status = LATEPOINT_STATUS_SUCCESS;
58 } else {
59 $response_html = $service->get_error_messages();
60 $status = LATEPOINT_STATUS_ERROR;
61 }
62 if ( $this->get_return_format() == 'json' ) {
63 $this->send_json( array( 'status' => $status,
64 'message' => $response_html,
65 'show_prev_btn' => true,
66 'show_next_btn' => $this->show_next_btn
67 ) );
68 }
69 }
70
71 function save_agent() {
72 $agent = new OsAgentModel();
73 $agent->set_data( $this->params['agent'] );
74 if ( $agent->save() ) {
75 $this->vars['current_step_code'] = 'agents';
76 $this->step_agents();
77 $response_html = $this->render( $this->get_view_uri( 'steps/_list_agents' ) );
78 $status = LATEPOINT_STATUS_SUCCESS;
79 } else {
80 $response_html = $agent->get_error_messages();
81 $status = LATEPOINT_STATUS_ERROR;
82 }
83 if ( $this->get_return_format() == 'json' ) {
84 $this->send_json( array( 'status' => $status,
85 'message' => $response_html,
86 'show_prev_btn' => $this->show_prev_btn,
87 'show_next_btn' => $this->show_next_btn
88 ) );
89 }
90 }
91
92
93 function setup() {
94 $current_step_code = $this->steps_in_order[0];
95 $step_function_name = 'step_' . $current_step_code;
96 self::$step_function_name();
97
98 add_option( 'latepoint_wizard_visited', true );
99
100 $this->vars['current_step_code'] = $current_step_code;
101 $this->vars['current_step_number'] = array_search( $current_step_code, $this->steps_in_order );
102 $this->vars['step_file_to_include'] = 'steps/_' . $current_step_code . '.php';
103
104 $this->format_render( __FUNCTION__ );
105 }
106
107 function next_step() {
108 $this->show_prev_btn = true;
109 $this->show_next_btn = true;
110
111 // Check if a valid step_code name
112 if ( isset( $this->steps_info[ $this->params['current_step_code'] ] ) ) {
113 $current_step_code = $this->params['current_step_code'];
114 } else {
115 $current_step_code = $this->steps_in_order[0];
116 }
117
118
119 $process_step_function_name = 'process_step_' . $current_step_code;
120 self::$process_step_function_name();
121
122 $new_current_step_code = $this->steps_in_order[ array_search( $current_step_code, $this->steps_in_order ) + 1 ];
123 if ( array_search( $new_current_step_code, $this->steps_in_order ) <= 1 ) {
124 $this->show_prev_btn = false;
125 }
126
127 $step_function_name = 'step_' . $new_current_step_code;
128 self::$step_function_name();
129
130 $this->vars['current_step_code'] = $new_current_step_code;
131 $this->vars['current_step_number'] = array_search( $new_current_step_code, $this->steps_in_order );
132 $this->format_render( 'steps/_' . $new_current_step_code, array(), array( 'step_code' => $new_current_step_code,
133 'show_prev_btn' => $this->show_prev_btn,
134 'show_next_btn' => $this->show_next_btn
135 ) );
136 }
137
138 function prev_step() {
139 // Check if a valid step_code name
140 if ( isset( $this->steps_info[ $this->params['current_step_code'] ] ) ) {
141 $current_step_code = $this->params['current_step_code'];
142 } else {
143 $current_step_code = $this->steps_in_order[0];
144 }
145
146 $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];
147 $this->show_prev_btn = array_search( $new_current_step_code, $this->steps_in_order ) > 0;
148
149 if ( array_search( $new_current_step_code, $this->steps_in_order ) <= 1 ) {
150 $this->show_prev_btn = false;
151 }
152
153 $step_function_name = 'step_' . $new_current_step_code;
154 self::$step_function_name();
155
156 $this->vars['current_step_code'] = $new_current_step_code;
157 $this->vars['current_step_number'] = array_search( $new_current_step_code, $this->steps_in_order );
158 $this->format_render( 'steps/_' . $new_current_step_code, array(), array( 'step_code' => $new_current_step_code,
159 'show_prev_btn' => $this->show_prev_btn,
160 'show_next_btn' => $this->show_next_btn
161 ) );
162 }
163
164 function load_step() {
165 // Check if a valid step_code name
166 if ( isset( $this->steps_info[ $this->params['current_step_code'] ] ) ) {
167 $current_step_code = $this->params['current_step_code'];
168 } else {
169 $current_step_code = $this->steps_in_order[0];
170 }
171
172 $step_function_name = 'step_' . $current_step_code;
173 self::$step_function_name();
174
175 $this->vars['current_step_code'] = $current_step_code;
176 $this->vars['current_step_number'] = array_search( $current_step_code, $this->steps_in_order );
177 $this->format_render( 'steps/_' . $current_step_code, array(), array( 'step_code' => $current_step_code ) );
178 }
179
180 function add_or_edit_agent() {
181 $agents = new OsAgentModel();
182 $this->vars['agents'] = $agents->get_results_as_models();
183
184 $agent = new OsAgentModel();
185 if ( ! empty( $this->params['id'] ) && is_numeric( $this->params['id'] ) ) {
186 $agent->load_by_id( $this->params['id'] );
187 }
188 $this->vars['agent'] = $agent;
189 $this->format_render( 'steps/_form_agent', array(), array() );
190 }
191
192 function add_or_edit_service() {
193 $services = new OsServiceModel();
194 $this->vars['services'] = $services->get_results_as_models();
195
196 $service = new OsServiceModel();
197 if ( isset( $this->params['id'] ) && is_numeric( $this->params['id'] ) ) {
198 $service->load_by_id( $this->params['id'] );
199 }
200 $agents = new OsAgentModel();
201 $service_categories = new OsServiceCategoryModel();
202
203 $this->vars['service_categories_for_select'] = $service_categories->index_for_select();
204 $this->vars['agents'] = $agents->get_results_as_models();
205 $this->vars['location'] = OsLocationHelper::get_default_location();
206
207 $this->vars['service'] = $service;
208 $this->format_render( 'steps/_form_service', array(), array() );
209 }
210
211
212 function step_services() {
213 $services = new OsServiceModel();
214 $services = $services->get_results_as_models();
215 $this->show_prev_btn = false;
216 $this->vars['services'] = $services;
217 $this->vars['location'] = OsLocationHelper::get_default_location();
218 $agents = new OsAgentModel();
219 $this->vars['agents'] = $agents->get_results_as_models();
220 if ( ! $services ) {
221 $service = new OsServiceModel();
222 $this->vars['service'] = $service;
223 $this->show_next_btn = false;
224 } else {
225 $this->show_next_btn = true;
226 $this->show_prev_btn = true;
227 }
228 }
229
230 function step_agents() {
231 $agents = new OsAgentModel();
232 $agents = $agents->get_results_as_models();
233 $this->vars['agents'] = $agents;
234 $this->show_prev_btn = false;
235 if ( ! $agents ) {
236 $agent = new OsAgentModel();
237 $this->vars['agent'] = $agent;
238 $this->show_next_btn = false;
239 } else {
240 $this->show_next_btn = true;
241 }
242 }
243
244
245 function step_default_agent(){
246
247 $this->vars['agent'] = OsAgentHelper::get_default_agent();
248 $this->show_next_btn = true;
249 }
250
251 function step_work_periods() {
252 $work_periods = OsWorkPeriodsHelper::get_work_periods( new \LatePoint\Misc\Filter() );
253 $working_periods_with_weekdays = array();
254 if ( $work_periods ) {
255 foreach ( $work_periods as $work_period ) {
256 $working_periods_with_weekdays[ 'day_' . $work_period->week_day ][] = $work_period;
257 }
258 }
259 $this->vars['working_periods_with_weekdays'] = $working_periods_with_weekdays;
260 }
261
262 function step_intro() {
263 $this->show_next_btn = true;
264 }
265
266
267 function step_settings() {
268
269 }
270
271 function step_complete() {
272 $this->show_next_btn = false;
273 $this->show_prev_btn = false;
274 }
275
276
277 function process_step_agents() {
278
279 }
280
281 function process_step_services() {
282
283 }
284
285 function process_step_intro() {
286
287 }
288
289 function process_step_default_agent() {
290
291 $default_agent = OsAgentHelper::get_default_agent();
292 if ( ! $default_agent->is_new_record() ) {
293 $default_agent->set_data( $this->params['agent'] );
294 $default_agent->save();
295 }
296
297 }
298
299 function process_step_work_periods() {
300 $work_periods_form_data = $this->params['work_periods'];
301 OsWorkPeriodsHelper::save_work_periods( $work_periods_form_data );
302 }
303
304 function process_step_info() {
305
306 }
307
308
309 }
310
311
312 endif;
313