PluginProbe ʕ •ᴥ•ʔ
LatePoint – Calendar Booking Plugin for Appointments and Events / 5.2.7
LatePoint – Calendar Booking Plugin for Appointments and Events v5.2.7
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 / models / activity_model.php
latepoint / lib / models Last commit date
activity_model.php 1 year ago agent_meta_model.php 1 year ago agent_model.php 1 year ago booking_meta_model.php 1 year ago booking_model.php 1 year ago bundle_meta_model.php 1 year ago bundle_model.php 1 year ago cart_item_model.php 1 year ago cart_meta_model.php 1 year ago cart_model.php 1 year ago connector_model.php 1 year ago customer_meta_model.php 1 year ago customer_model.php 9 months ago invoice_model.php 1 year ago join_bundles_services_model.php 1 year ago location_category_model.php 9 months ago location_model.php 1 year ago meta_model.php 1 year ago model.php 9 months ago off_period_model.php 1 year ago order_intent_meta_model.php 1 year ago order_intent_model.php 9 months ago order_item_model.php 1 year ago order_meta_model.php 1 year ago order_model.php 1 year ago otp_model.php 9 months ago payment_request_model.php 1 year ago process_job_model.php 1 year ago process_model.php 1 year ago recurrence_model.php 1 year ago service_category_model.php 9 months ago service_meta_model.php 1 year ago service_model.php 9 months ago session_model.php 1 year ago settings_model.php 1 year ago step_settings_model.php 1 year ago transaction_intent_model.php 1 year ago transaction_model.php 1 year ago transaction_refund_model.php 1 year ago work_period_model.php 1 year ago
activity_model.php
176 lines
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 $coupon_id,
12 $code,
13 $description,
14 $initiated_by,
15 $initiated_by_id,
16 $updated_at,
17 $created_at;
18
19
20
21
22
23 protected $codes;
24
25 function __construct($id = false){
26 parent::__construct();
27 $this->table_name = LATEPOINT_TABLE_ACTIVITIES;
28 $this->nice_names = array();
29
30 $this->codes = $this->get_codes();
31
32 if($id){
33 $this->load_by_id($id);
34 }
35 }
36
37 protected function get_codes(){
38 return OsActivitiesHelper::get_codes();
39 }
40
41 public function get_link_to_object($label = false){
42 $label = ($label) ? $label : esc_html__('View', 'latepoint');
43 $href = '#';
44 $attrs = '';
45 switch($this->code){
46 case 'agent_updated':
47 case 'agent_created':
48 $href = OsRouterHelper::build_link(OsRouterHelper::build_route_name('agents', 'edit_form'), array('id' => $this->agent_id) );
49 break;
50 case 'service_updated':
51 case 'service_created':
52 $href = OsRouterHelper::build_link(OsRouterHelper::build_route_name('services', 'edit_form'), array('id' => $this->service_id) );
53 break;
54 default:
55 $attrs = 'data-os-params="' . esc_attr(http_build_query(['id' => $this->id])) . '"
56 data-os-action="' . esc_attr(OsRouterHelper::build_route_name( 'activities', 'view' )) . '"
57 data-os-lightbox-classes="width-800"
58 data-os-after-call="latepoint_init_json_view"
59 data-os-output-target="side-panel"';
60 break;
61 }
62 $link = '<a class="view-activity-link" href="'.esc_url($href).'" '.$attrs.'>'.$label.'</a>';
63 $link = apply_filters('latepoint_activity_link_to_object', $link, $this, $label);
64 return $link;
65 }
66
67
68 public function get_user_link_with_avatar() {
69 return $this->get_user_link( true );
70 }
71
72
73 public function get_user_link($show_avatar = false){
74 $link = '#';
75 $name = 'n/a';
76 $attrs = '';
77 $avatar_url = LATEPOINT_DEFAULT_AVATAR_URL;
78
79 switch($this->initiated_by){
80 case 'wp_user':
81 case LATEPOINT_USER_TYPE_ADMIN:
82 case LATEPOINT_USER_TYPE_CUSTOM:
83 $link = get_edit_user_link($this->initiated_by_id);
84 $userdata = get_userdata($this->initiated_by_id);
85 $name = $userdata->display_name;
86 $avatar_url = get_avatar_url($this->initiated_by_id, array('size' => 200));
87 break;
88 case LATEPOINT_USER_TYPE_AGENT:
89 $agent = new OsAgentModel($this->initiated_by_id);
90 $link = OsRouterHelper::build_link(OsRouterHelper::build_route_name('agents', 'edit_form'), array('id' => $this->initiated_by_id) );
91 $name = $agent->full_name;
92 $avatar_url = $agent->get_avatar_url();
93 break;
94 case LATEPOINT_USER_TYPE_CUSTOMER:
95 $customer = new OsCustomerModel($this->initiated_by_id);
96 $attrs = OsCustomerHelper::quick_customer_btn_html($this->initiated_by_id);
97 $name = $customer->full_name;
98 $avatar_url = $customer->get_avatar_url();
99 break;
100 default:
101 return esc_html($this->initiated_by ?? 'n/a');
102 }
103 $avatar_url = esc_url($avatar_url);
104 $name = esc_html($name);
105 $link = esc_url($link);
106 $avatar = $show_avatar ? "<span class='ula-avatar' style='background-image: url({$avatar_url})'></span>" : "";
107
108 return "<a class='user-link-with-avatar' target='_blank' href='{$link}' {$attrs}>{$avatar}<span class='ula-name'>{$name}</span><span class='latepoint-icon latepoint-icon-external-link'></span></a>";
109 }
110
111 public function get_description() {
112 if ($this->code == 'sms_sent') {
113 $this->description = json_decode($this->description, true);
114 }
115
116 return $this->description;
117 }
118
119
120 protected function get_nice_created_at($include_time = true){
121 $format = $include_time ? OsSettingsHelper::get_readable_date_format() . ' ' . OsSettingsHelper::get_readable_time_format() : OsSettingsHelper::get_readable_date_format();
122 $utc_date = date_create_from_format( LATEPOINT_DATETIME_DB_FORMAT, $this->created_at );
123 $wp_timezone_date = $utc_date->setTimezone(OsTimeHelper::get_wp_timezone());
124
125 return date_format( $wp_timezone_date, $format );
126 }
127
128
129 protected function get_name(){
130 if($this->code && isset($this->codes[$this->code])){
131 return $this->codes[$this->code];
132 }else{
133 return $this->code;
134 }
135 }
136
137 protected function params_to_save($role = 'admin'){
138 $params_to_save = array('id',
139 'agent_id',
140 'order_id',
141 'order_item_id',
142 'booking_id',
143 'service_id',
144 'customer_id',
145 'coupon_id',
146 'code',
147 'description',
148 'initiated_by',
149 'initiated_by_id');
150 return $params_to_save;
151 }
152
153 protected function allowed_params($role = 'admin'){
154 $allowed_params = array('id',
155 'agent_id',
156 'booking_id',
157 'order_id',
158 'order_item_id',
159 'service_id',
160 'customer_id',
161 'coupon_id',
162 'code',
163 'description',
164 'initiated_by',
165 'initiated_by_id');
166 return $allowed_params;
167 }
168
169
170 protected function properties_to_validate(){
171 $validations = array(
172 'code' => array('presence')
173 );
174 return $validations;
175 }
176 }