activities_controller.php
1 month ago
auth_controller.php
3 months ago
booking_form_settings_controller.php
3 months ago
bookings_controller.php
14 hours ago
calendars_controller.php
3 months ago
carts_controller.php
14 hours ago
controller.php
3 months ago
customer_cabinet_controller.php
2 months ago
customers_controller.php
14 hours ago
dashboard_controller.php
2 months ago
default_agent_controller.php
3 months ago
events_controller.php
3 months ago
form_fields_controller.php
1 week ago
integrations_controller.php
3 months ago
invoices_controller.php
14 hours ago
manage_booking_by_key_controller.php
3 months ago
manage_order_by_key_controller.php
3 months ago
notifications_controller.php
3 months ago
orders_controller.php
14 hours ago
pro_controller.php
2 weeks ago
process_jobs_controller.php
3 months ago
processes_controller.php
1 month ago
razorpay_connect_controller.php
1 week ago
search_controller.php
3 months ago
services_controller.php
3 months ago
settings_controller.php
2 months ago
steps_controller.php
2 weeks ago
stripe_connect_controller.php
1 week ago
support_topics_controller.php
3 months ago
todos_controller.php
3 months ago
transactions_controller.php
14 hours ago
wizard_controller.php
1 week ago
default_agent_controller.php
111 lines
| 1 | <?php |
| 2 | /* |
| 3 | * Copyright (c) 2024 LatePoint LLC. All rights reserved. |
| 4 | */ |
| 5 | |
| 6 | if ( ! defined( 'ABSPATH' ) ) { |
| 7 | exit; // Exit if accessed directly. |
| 8 | } |
| 9 | |
| 10 | |
| 11 | if ( ! class_exists( 'OsDefaultAgentController' ) ) : |
| 12 | |
| 13 | |
| 14 | class OsDefaultAgentController extends OsController { |
| 15 | |
| 16 | |
| 17 | |
| 18 | function __construct() { |
| 19 | parent::__construct(); |
| 20 | |
| 21 | $this->views_folder = plugin_dir_path( __FILE__ ) . '../views/default_agent/'; |
| 22 | $this->vars['page_header'] = OsMenuHelper::get_menu_items_by_id( 'agents' ); |
| 23 | $this->vars['breadcrumbs'][] = array( |
| 24 | 'label' => __( 'Agent', 'latepoint' ), |
| 25 | 'link' => OsRouterHelper::build_link( OsRouterHelper::build_route_name( 'agents', 'index' ) ), |
| 26 | ); |
| 27 | } |
| 28 | |
| 29 | |
| 30 | |
| 31 | /* |
| 32 | Edit agent |
| 33 | */ |
| 34 | |
| 35 | public function edit_form() { |
| 36 | $agent = OsAgentHelper::get_default_agent(); |
| 37 | |
| 38 | if ( ! OsAuthHelper::get_current_user()->check_if_allowed_record_id( $agent->id, 'agent' ) ) { |
| 39 | $this->access_not_allowed(); |
| 40 | } |
| 41 | |
| 42 | $this->vars['page_header'] = __( 'Agents', 'latepoint' ); |
| 43 | $this->vars['breadcrumbs'][] = array( |
| 44 | 'label' => __( 'Agents', 'latepoint' ), |
| 45 | 'link' => false, |
| 46 | ); |
| 47 | |
| 48 | if ( $agent->id ) { |
| 49 | |
| 50 | $this->vars['agent'] = $agent; |
| 51 | |
| 52 | } |
| 53 | |
| 54 | $this->format_render( __FUNCTION__ ); |
| 55 | } |
| 56 | |
| 57 | |
| 58 | public function update() { |
| 59 | $is_new_record = ( isset( $this->params['agent']['id'] ) && $this->params['agent']['id'] ) ? false : true; |
| 60 | |
| 61 | $this->check_nonce( $is_new_record ? 'new_agent' : 'edit_agent_' . $this->params['agent']['id'] ); |
| 62 | $agent = new OsAgentModel(); |
| 63 | $agent->set_data( $this->params['agent'] ); |
| 64 | $agent->set_features( $this->params['agent']['features'] ); |
| 65 | $extra_response_vars = array(); |
| 66 | |
| 67 | if ( $agent->save() && ( empty( $this->params['agent']['services'] ) || $agent->save_locations_and_services( $this->params['agent']['services'] ) ) ) { |
| 68 | if ( $is_new_record ) { |
| 69 | $response_html = __( 'Agent Created. ID:', 'latepoint' ) . $agent->id; |
| 70 | OsActivitiesHelper::create_activity( |
| 71 | array( |
| 72 | 'code' => 'agent_create', |
| 73 | 'agent_id' => $agent->id, |
| 74 | ) |
| 75 | ); |
| 76 | } else { |
| 77 | $response_html = __( 'Agent Updated. ID:', 'latepoint' ) . $agent->id; |
| 78 | OsActivitiesHelper::create_activity( |
| 79 | array( |
| 80 | 'code' => 'agent_update', |
| 81 | 'agent_id' => $agent->id, |
| 82 | ) |
| 83 | ); |
| 84 | } |
| 85 | $status = LATEPOINT_STATUS_SUCCESS; |
| 86 | // save schedules |
| 87 | if ( $this->params['is_custom_schedule'] == 'on' ) { |
| 88 | $agent->save_custom_schedule( $this->params['work_periods'] ); |
| 89 | } elseif ( $this->params['is_custom_schedule'] == 'off' ) { |
| 90 | $agent->delete_custom_schedule(); |
| 91 | } |
| 92 | $extra_response_vars['record_id'] = $agent->id; |
| 93 | do_action( 'latepoint_agent_saved', $agent, $is_new_record, $this->params['agent'] ); |
| 94 | } else { |
| 95 | $response_html = $agent->get_error_messages(); |
| 96 | $status = LATEPOINT_STATUS_ERROR; |
| 97 | } |
| 98 | if ( $this->get_return_format() == 'json' ) { |
| 99 | $this->send_json( |
| 100 | array( |
| 101 | 'status' => $status, |
| 102 | 'message' => $response_html, |
| 103 | ) + $extra_response_vars |
| 104 | ); |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | |
| 110 | endif; |
| 111 |