PluginProbe
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress / 5.1.92
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress v5.1.92
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/default_agent_controller.php +56 -77 5.5.05.1.92 View file →
@@ -3,9 +3,9 @@
3 3 * Copyright (c) 2024 LatePoint LLC. All rights reserved.
4 4 */
5 5
6 6 if ( ! defined( 'ABSPATH' ) ) {
7 - exit; // Exit if accessed directly.
7 + exit; // Exit if accessed directly.
8 8 }
9 9
10 10
11 11 if ( ! class_exists( 'OsDefaultAgentController' ) ) :
@@ -10,101 +10,80 @@
10 10
11 11 if ( ! class_exists( 'OsDefaultAgentController' ) ) :
12 12
13 13
14 - class OsDefaultAgentController extends OsController {
14 + class OsDefaultAgentController extends OsController {
15 15
16 16
17 17
18 - function __construct() {
19 - parent::__construct();
18 + function __construct(){
19 + parent::__construct();
20 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 - }
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('label' => __('Agent', 'latepoint'), 'link' => OsRouterHelper::build_link(OsRouterHelper::build_route_name('agents', 'index') ) );
24 + }
28 25
29 26
30 27
31 - /*
32 - Edit agent
33 - */
28 + /*
29 + Edit agent
30 + */
34 31
35 - public function edit_form() {
32 + public function edit_form(){
36 33 $agent = OsAgentHelper::get_default_agent();
37 34
38 - if ( ! OsAuthHelper::get_current_user()->check_if_allowed_record_id( $agent->id, 'agent' ) ) {
39 - $this->access_not_allowed();
40 - }
35 + if(!OsAuthHelper::get_current_user()->check_if_allowed_record_id($agent->id, 'agent')) $this->access_not_allowed();
41 36
42 - $this->vars['page_header'] = __( 'Agents', 'latepoint' );
43 - $this->vars['breadcrumbs'][] = array(
44 - 'label' => __( 'Agents', 'latepoint' ),
45 - 'link' => false,
46 - );
37 + $this->vars['page_header'] = __('Agents', 'latepoint');
38 + $this->vars['breadcrumbs'][] = array('label' => __('Agents', 'latepoint'), 'link' => false );
47 39
48 - if ( $agent->id ) {
40 + if($agent->id){
49 41
50 - $this->vars['agent'] = $agent;
42 + $this->vars['agent'] = $agent;
51 43
52 - }
44 + }
53 45
54 - $this->format_render( __FUNCTION__ );
55 - }
46 + $this->format_render(__FUNCTION__);
47 + }
56 48
57 49
58 - public function update() {
59 - $is_new_record = ( isset( $this->params['agent']['id'] ) && $this->params['agent']['id'] ) ? false : true;
50 + public function update(){
51 + $is_new_record = (isset($this->params['agent']['id']) && $this->params['agent']['id']) ? false : true;
60 52
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();
53 + $this->check_nonce($is_new_record ? 'new_agent' : 'edit_agent_'. $this->params['agent']['id']);
54 + $agent = new OsAgentModel();
55 + $agent->set_data($this->params['agent']);
56 + $agent->set_features($this->params['agent']['features']);
57 + $extra_response_vars = array();
66 58
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 - }
59 + if($agent->save() && (empty($this->params['agent']['services']) || $agent->save_locations_and_services($this->params['agent']['services']))){
60 + if($is_new_record){
61 + $response_html = __('Agent Created. ID:', 'latepoint') . $agent->id;
62 + OsActivitiesHelper::create_activity(array('code' => 'agent_create', 'agent_id' => $agent->id));
63 + }else{
64 + $response_html = __('Agent Updated. ID:', 'latepoint') . $agent->id;
65 + OsActivitiesHelper::create_activity(array('code' => 'agent_update', 'agent_id' => $agent->id));
66 + }
67 + $status = LATEPOINT_STATUS_SUCCESS;
68 + // save schedules
69 + if($this->params['is_custom_schedule'] == 'on'){
70 + $agent->save_custom_schedule($this->params['work_periods']);
71 + }elseif($this->params['is_custom_schedule'] == 'off'){
72 + $agent->delete_custom_schedule();
73 + }
74 + $extra_response_vars['record_id'] = $agent->id;
75 + do_action('latepoint_agent_saved', $agent, $is_new_record, $this->params['agent']);
76 + }else{
77 + $response_html = $agent->get_error_messages();
78 + $status = LATEPOINT_STATUS_ERROR;
79 + }
80 + if($this->get_return_format() == 'json'){
81 + $this->send_json(array('status' => $status, 'message' => $response_html) + $extra_response_vars);
82 + }
83 + }
108 84
109 85
110 -endif;
86 + }
87 +
88 +
89 +endif;