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
latepoint / lib / models / activity_model.php

activity_model.php in Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress 5.1.92, at lib/models/activity_model.php

173 lines 5.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class OsActivityModel extends OsModel{
4 public $id,
5 $agent_id,
6 $order_id,
7 $order_item_id,
8 $booking_id,
9 $service_id,
10 $customer_id,
11 $code,
12 $description,
13 $initiated_by,
14 $initiated_by_id,
15 $updated_at,
16 $created_at;
17
18
19
20
21
22 protected $codes;
23
24 function __construct($id = false){
25 parent::__construct();
26 $this->table_name = LATEPOINT_TABLE_ACTIVITIES;
27 $this->nice_names = array();
28
29 $this->codes = $this->get_codes();
30
31 if($id){
32 $this->load_by_id($id);
33 }
34 }
35
36 protected function get_codes(){
37 return OsActivitiesHelper::get_codes();
38 }
39
40 public function get_link_to_object($label = false){
41 $label = ($label) ? $label : esc_html__('View', 'latepoint');
42 $href = '#';
43 $attrs = '';
44 switch($this->code){
45 case 'customer_created':
46 case 'customer_updated':
47 $attrs = OsCustomerHelper::quick_customer_btn_html($this->customer_id);
48 break;
49 case 'agent_updated':
50 case 'agent_created':
51 $href = OsRouterHelper::build_link(OsRouterHelper::build_route_name('agents', 'edit_form'), array('id' => $this->agent_id) );
52 break;
53 case 'service_updated':
54 case 'service_created':
55 $href = OsRouterHelper::build_link(OsRouterHelper::build_route_name('services', 'edit_form'), array('id' => $this->service_id) );
56 break;
57 default:
58 $attrs = 'data-os-params="' . esc_attr(http_build_query(['id' => $this->id])) . '"
59 data-os-action="' . esc_attr(OsRouterHelper::build_route_name( 'activities', 'view' )) . '"
60 data-os-lightbox-classes="width-800"
61 data-os-after-call="latepoint_init_json_view"
62 data-os-output-target="side-panel"';
63 break;
64 }
65 $link = '<a class="view-activity-link" href="'.esc_url($href).'" '.$attrs.'>'.$label.'</a>';
66 $link = apply_filters('latepoint_activity_link_to_object', $link, $this, $label);
67 return $link;
68 }
69
70
71
72 protected function get_user_link_with_avatar(){
73 $link = '#';
74 $name = 'n/a';
75 $attrs = '';
76 $avatar_url = LATEPOINT_DEFAULT_AVATAR_URL;
77 switch($this->initiated_by){
78 case 'wp_user':
79 case 'admin':
80 case 'custom':
81 $link = get_edit_user_link($this->initiated_by_id);
82 $userdata = get_userdata($this->initiated_by_id);
83 $name = $userdata->display_name;
84 $avatar_url = get_avatar_url($this->initiated_by_id, array('size' => 200));
85 break;
86 case 'agent':
87 $agent = new OsAgentModel($this->initiated_by_id);
88 $link = OsRouterHelper::build_link(OsRouterHelper::build_route_name('agents', 'edit_form'), array('id' => $this->initiated_by_id) );
89 $name = $agent->full_name;
90 $avatar_url = $agent->get_avatar_url();
91 break;
92 case 'customer':
93 $customer = new OsCustomerModel($this->initiated_by_id);
94 $attrs = $attrs = OsCustomerHelper::quick_customer_btn_html($this->initiated_by_id);
95 $name = $customer->full_name;
96 $avatar_url = $customer->get_avatar_url();
97 break;
98 default:
99 $link = '#';
100 $name = 'n/a';
101 $avatar_url = LATEPOINT_IMAGES_URL . 'default-avatar.jpg';
102 break;
103 }
104 $avatar_url = esc_url($avatar_url);
105 $name = esc_html($name);
106 $link = esc_url($link);
107 return "<a class='user-link-with-avatar' target='_blank' href='{$link}' {$attrs}><span class='ula-avatar' style='background-image: url({$avatar_url})'></span><span class='ula-name'>{$name}</span><span class='latepoint-icon latepoint-icon-external-link'></span></a>";
108 }
109
110 public function get_description() {
111 if ($this->code == 'sms_sent') {
112 $this->description = json_decode($this->description, true);
113 }
114
115 return $this->description;
116 }
117
118
119 protected function get_nice_created_at($include_time = true){
120 $format = $include_time ? OsSettingsHelper::get_readable_date_format() . ' ' . OsSettingsHelper::get_readable_time_format() : OsSettingsHelper::get_readable_date_format();
121 $utc_date = date_create_from_format( LATEPOINT_DATETIME_DB_FORMAT, $this->created_at );
122 $wp_timezone_date = $utc_date->setTimezone(OsTimeHelper::get_wp_timezone());
123
124 return date_format( $wp_timezone_date, $format );
125 }
126
127
128 protected function get_name(){
129 if($this->code && isset($this->codes[$this->code])){
130 return $this->codes[$this->code];
131 }else{
132 return $this->code;
133 }
134 }
135
136 protected function params_to_save($role = 'admin'){
137 $params_to_save = array('id',
138 'agent_id',
139 'order_id',
140 'order_item_id',
141 'booking_id',
142 'service_id',
143 'customer_id',
144 'code',
145 'description',
146 'initiated_by',
147 'initiated_by_id');
148 return $params_to_save;
149 }
150
151 protected function allowed_params($role = 'admin'){
152 $allowed_params = array('id',
153 'agent_id',
154 'booking_id',
155 'order_id',
156 'order_item_id',
157 'service_id',
158 'customer_id',
159 'code',
160 'description',
161 'initiated_by',
162 'initiated_by_id');
163 return $allowed_params;
164 }
165
166
167 protected function properties_to_validate(){
168 $validations = array(
169 'code' => array('presence')
170 );
171 return $validations;
172 }
173 }