PluginProbe ʕ •ᴥ•ʔ
LatePoint – Calendar Booking Plugin for Appointments and Events / trunk
LatePoint – Calendar Booking Plugin for Appointments and Events vtrunk
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 / activities_controller.php
latepoint / lib / controllers Last commit date
activities_controller.php 1 month ago auth_controller.php 3 months ago booking_form_settings_controller.php 3 months ago bookings_controller.php 13 hours ago calendars_controller.php 3 months ago carts_controller.php 13 hours ago controller.php 3 months ago customer_cabinet_controller.php 2 months ago customers_controller.php 13 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 13 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 13 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 13 hours ago wizard_controller.php 1 week ago
activities_controller.php
324 lines
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit; // Exit if accessed directly.
4 }
5
6
7 if ( ! class_exists( 'OsActivitiesController' ) ) :
8
9
10 class OsActivitiesController extends OsController {
11
12
13 function __construct() {
14 parent::__construct();
15
16 $this->views_folder = LATEPOINT_VIEWS_ABSPATH . 'activities/';
17 $this->vars['page_header'] = OsMenuHelper::get_menu_items_by_id( 'processes' );
18 $this->vars['pre_page_header'] = OsMenuHelper::get_label_by_id( 'processes' );
19 $this->vars['breadcrumbs'][] = array(
20 'label' => __( 'Activities', 'latepoint' ),
21 'link' => OsRouterHelper::build_link( OsRouterHelper::build_route_name( 'activities', 'index' ) ),
22 );
23 }
24
25 public function clear_all() {
26 $this->check_nonce( 'clear_activities' );
27 global $wpdb;
28 $wpdb->query( $wpdb->prepare( 'TRUNCATE TABLE %i', esc_sql( LATEPOINT_TABLE_ACTIVITIES ) ) );
29 if ( $this->get_return_format() == 'json' ) {
30 $this->send_json(
31 array(
32 'status' => LATEPOINT_STATUS_SUCCESS,
33 'message' => __( 'Activities log cleared', 'latepoint' ),
34 )
35 );
36 }
37 }
38
39 public function export() {
40 // Verify nonce.
41 $this->check_nonce( 'export_activities' );
42
43 $csv_filename = 'activities_log_' . OsUtilHelper::random_text() . '.csv';
44
45 header( 'Content-Type: text/csv' );
46 header( "Content-Disposition: attachment; filename={$csv_filename}" );
47
48 $labels_row = [
49 __( 'Type', 'latepoint' ),
50 __( 'Agent ID', 'latepoint' ),
51 __( 'Booking ID', 'latepoint' ),
52 __( 'Service ID', 'latepoint' ),
53 __( 'Customer ID', 'latepoint' ),
54 __( 'Location ID', 'latepoint' ),
55 __( 'Action By User Type', 'latepoint' ),
56 __( 'Action By User ID', 'latepoint' ),
57 __( 'Date, Time', 'latepoint' ),
58 __( 'Description', 'latepoint' ),
59 ];
60
61
62 $activities_data = [];
63 $activities_data[] = $labels_row;
64
65 $activities = new OsActivityModel();
66 $activities_arr = $activities->order_by( 'created_at' )->get_results( ARRAY_A );
67
68 if ( $activities_arr ) {
69 foreach ( $activities_arr as $activity ) {
70 $values_row = [
71 $activity['code'],
72 $activity['agent_id'],
73 $activity['booking_id'],
74 $activity['service_id'],
75 $activity['customer_id'],
76 $activity['location_id'],
77 $activity['initiated_by'],
78 $activity['initiated_by_id'],
79 $activity['created_at'],
80 $activity['description'],
81 ];
82 $activities_data[] = $values_row;
83 }
84 }
85
86 OsCSVHelper::array_to_csv( $activities_data );
87
88 return;
89 }
90
91 /*
92 Index of activities
93 */
94
95 public function index() {
96 $per_page = OsSettingsHelper::get_number_of_records_per_page();
97 $page_number = isset( $this->params['page_number'] ) ? $this->params['page_number'] : 1;
98
99 $activities = new OsActivityModel();
100 $count_activities = new OsActivityModel();
101
102 // TABLE SEARCH FILTERS
103 $filter = isset( $this->params['filter'] ) ? $this->params['filter'] : false;
104
105 $query_args = [];
106 if ( $filter ) {
107 if ( ! empty( $filter['code'] ) ) {
108 $query_args['code'] = $filter['code'];
109 }
110 if ( ! empty( $filter['initiated_by_id'] ) ) {
111 $query_args['initiated_by_id'] = $filter['initiated_by_id'];
112 }
113
114 if ( ! empty( $filter['created_at_from'] ) && ! empty( $filter['created_at_to'] ) ) {
115 $query_args['created_at >='] = $filter['created_at_from'];
116 $query_args['created_at <='] = $filter['created_at_to'];
117 }
118 }
119
120 $total_activities = $count_activities->where( $query_args )->count();
121
122 $activities = $activities->where( $query_args )->order_by( 'id desc' )->set_limit( $per_page );
123 if ( $page_number > 1 ) {
124 $activities = $activities->set_offset( ( $page_number - 1 ) * $per_page );
125 }
126
127 $this->vars['activities'] = $activities->get_results_as_models();
128
129 $this->vars['total_activities'] = $total_activities;
130 $this->vars['current_page_number'] = $page_number;
131 $this->vars['per_page'] = $per_page;
132 $total_pages = ceil( $total_activities / $per_page );
133 $this->vars['total_pages'] = $total_pages;
134
135 $this->vars['showing_from'] = ( ( $page_number - 1 ) * $per_page ) ? ( ( $page_number - 1 ) * $per_page ) : 1;
136 $this->vars['showing_to'] = min( $page_number * $per_page, $total_activities );
137
138
139 $this->vars['breadcrumbs'][] = array(
140 'label' => __( 'Index', 'latepoint' ),
141 'link' => false,
142 );
143
144 $this->format_render(
145 [
146 'json_view_name' => '_table_body',
147 'html_view_name' => __FUNCTION__,
148 ],
149 [],
150 [
151 'total_pages' => $total_pages,
152 'showing_from' => $this->vars['showing_from'],
153 'showing_to' => $this->vars['showing_to'],
154 'total_records' => $total_activities,
155 ]
156 );
157 }
158
159 public function destroy() {
160 if ( filter_var( $this->params['id'], FILTER_VALIDATE_INT ) ) {
161
162 $this->check_nonce( 'destroy_activity_' . $this->params['id'] );
163 $activity = new OsActivityModel( $this->params['id'] );
164 if ( $activity->delete() ) {
165 $status = LATEPOINT_STATUS_SUCCESS;
166 $response_html = __( 'Activity Removed', 'latepoint' );
167 } else {
168 $status = LATEPOINT_STATUS_ERROR;
169 $response_html = __( 'Error Removing Activity', 'latepoint' );
170 }
171 } else {
172 $status = LATEPOINT_STATUS_ERROR;
173 $response_html = __( 'Error Removing Activity', 'latepoint' );
174 }
175
176 if ( $this->get_return_format() == 'json' ) {
177 $this->send_json(
178 array(
179 'status' => $status,
180 'message' => $response_html,
181 )
182 );
183 }
184 }
185
186 public function view() {
187 $activity = new OsActivityModel( $this->params['id'] );
188 $data = json_decode( $activity->description, true );
189
190 $this->vars['activity_id'] = $activity->id;
191 $this->vars['activity_name'] = $activity->name;
192 $this->vars['activity_type'] = $activity->code;
193 $this->vars['status'] = $data['status'] ?? '';
194
195 $status_html = '';
196 if ( ! empty( $data['status'] ) ) {
197 $status_html = '<div class="status-item">' . __( 'Status:', 'latepoint' ) . ' <strong>' . esc_html( $data['status'] ) . '</strong></div>';
198 $status_html .= '<div class="status-item">' . __( 'Processed on:', 'latepoint' ) . ' <strong>' . esc_html( $data['processed_datetime'] ) . '</strong></div>';
199 if ( ! empty( $data['errors'] ) ) {
200 $status_html .= '<div class="status-item">' . __( 'Errors:', 'latepoint' ) . '<strong>' . esc_html( is_array( $data['errors'] ) ? implode( ', ', $data['errors'] ) : $data['errors'] ) . '</strong></div>';
201 }
202 }
203
204 switch ( $activity->code ) {
205 // orders
206 case 'order_intent_updated':
207 $link_to_order = $activity->order_id ? '<a href="#" ' . OsOrdersHelper::quick_order_btn_html( $activity->order_id ) . '>' . __( 'View Order', 'latepoint' ) . '</a>' : '';
208 $meta_html = '<div class="activity-preview-to">' . ( $link_to_order ? ( '<span class="os-value">' . $link_to_order . '</span>' ) : '' ) . '<span class="os-label">' . __( 'Created On:', 'latepoint' ) . '</span><span class="os-value">' . $activity->nice_created_at . '</span></div>';
209 $content_html = '<pre class="format-json">' . esc_html( wp_json_encode( $data['order_data_vars'], JSON_PRETTY_PRINT | JSON_HEX_TAG ) ) . '</pre>';
210 break;
211 case 'order_intent_created':
212 $link_to_order = $activity->order_id ? '<a href="#" ' . OsOrdersHelper::quick_order_btn_html( $activity->order_id ) . '>' . __( 'View Order', 'latepoint' ) . '</a>' : '';
213 $meta_html = '<div class="activity-preview-to">' . ( $link_to_order ? ( '<span class="os-value">' . $link_to_order . '</span>' ) : '' ) . '<span class="os-label">' . __( 'Created On:', 'latepoint' ) . '</span><span class="os-value">' . $activity->nice_created_at . '</span></div>';
214 $content_html = '<pre class="format-json">' . esc_html( wp_json_encode( $data['order_data_vars'], JSON_PRETTY_PRINT | JSON_HEX_TAG ) ) . '</pre>';
215 break;
216 case 'order_intent_converted':
217 $link_to_order = '<a href="#" ' . OsOrdersHelper::quick_order_btn_html( $activity->order_id ) . '>' . __( 'View Order', 'latepoint' ) . '</a>';
218 $meta_html = '<div class="activity-preview-to"><span class="os-value">' . $link_to_order . '</span><span class="os-label">' . __( 'Created On:', 'latepoint' ) . '</span><span class="os-value">' . $activity->nice_created_at . '</span></div>';
219 $content_html = '<pre class="format-json">' . esc_html( wp_json_encode( $data['order_data_vars'], JSON_PRETTY_PRINT | JSON_HEX_TAG ) ) . '</pre>';
220 break;
221 case 'order_created':
222 $link_to_order = '<a href="#" ' . OsOrdersHelper::quick_order_btn_html( $activity->order_id ) . '>' . __( 'View Order', 'latepoint' ) . '</a>';
223 $meta_html = '<div class="activity-preview-to"><span class="os-value">' . $link_to_order . '</span><span class="os-label">' . __( 'Created On:', 'latepoint' ) . '</span><span class="os-value">' . $activity->nice_created_at . '</span><span class="os-label">' . esc_html__( 'by:', 'latepoint' ) . '</span><span class="os-value">' . $activity->get_user_link() . '</span></div>';
224 $content_html = '<pre class="format-json">' . esc_html( wp_json_encode( $data['order_data_vars'], JSON_PRETTY_PRINT | JSON_HEX_TAG ) ) . '</pre>';
225 break;
226 case 'order_updated':
227 $link_to_order = '<a href="#" ' . OsOrdersHelper::quick_order_btn_html( $activity->order_id ) . '>' . __( 'View Order', 'latepoint' ) . '</a>';
228 $meta_html = '<div class="activity-preview-to"><span class="os-value">' . $link_to_order . '</span><span class="os-label">' . __( 'Updated On:', 'latepoint' ) . '</span><span class="os-value">' . $activity->nice_created_at . '</span><span class="os-label">' . esc_html__( 'by:', 'latepoint' ) . '</span><span class="os-value">' . $activity->get_user_link() . '</span></div>';
229 $changes = OsUtilHelper::compare_model_data_vars( $data['order_data_vars']['new'], $data['order_data_vars']['old'] );
230 $content_html = '<pre class="format-json">' . esc_html( wp_json_encode( $changes, JSON_PRETTY_PRINT | JSON_HEX_TAG ) ) . '</pre>';
231 break;
232
233 case 'customer_created':
234 $link_to_customer = '<a href="#" ' . OsCustomerHelper::quick_customer_btn_html( $activity->customer_id ) . '>' . __( 'View Customer', 'latepoint' ) . '</a>';
235 $meta_html = '<div class="activity-preview-to"><span class="os-value">' . $link_to_customer . '</span><span class="os-label">' . __( 'Created On:', 'latepoint' ) . '</span><span class="os-value">' . $activity->nice_created_at . '</span><span class="os-label">' . esc_html__( 'by:', 'latepoint' ) . '</span><span class="os-value">' . $activity->get_user_link() . '</span></div>';
236 $content_html = '<pre class="format-json">' . esc_html( wp_json_encode( $data['customer_data_vars'], JSON_PRETTY_PRINT | JSON_HEX_TAG ) ) . '</pre>';
237 break;
238 case 'customer_updated':
239 $link_to_customer = '<a href="#" ' . OsCustomerHelper::quick_customer_btn_html( $activity->customer_id ) . '>' . __( 'View Customer', 'latepoint' ) . '</a>';
240 $meta_html = '<div class="activity-preview-to"><span class="os-value">' . $link_to_customer . '</span><span class="os-label">' . __( 'Updated On:', 'latepoint' ) . '</span><span class="os-value">' . $activity->nice_created_at . '</span><span class="os-label">' . esc_html__( 'by:', 'latepoint' ) . '</span><span class="os-value">' . $activity->get_user_link() . '</span></div>';
241 $changes = OsUtilHelper::compare_model_data_vars( $data['customer_data_vars']['new'], $data['customer_data_vars']['old'] );
242 $content_html = '<pre class="format-json">' . esc_html( wp_json_encode( $changes, JSON_PRETTY_PRINT | JSON_HEX_TAG ) ) . '</pre>';
243 break;
244 case 'payment_request_created':
245 $link_to_order = '<a href="#" ' . OsOrdersHelper::quick_order_btn_html( $activity->order_id ) . '>' . __( 'View Order', 'latepoint' ) . '</a>';
246 $meta_html = '<div class="activity-preview-to"><span class="os-value">' . $link_to_order . '</span><span class="os-label">' . __( 'Created On:', 'latepoint' ) . '</span><span class="os-value">' . $activity->nice_created_at . '</span></div>';
247 $content_html = '<pre class="format-json">' . esc_html( wp_json_encode( $data['payment_request_data_vars'], JSON_PRETTY_PRINT | JSON_HEX_TAG ) ) . '</pre>';
248 break;
249
250 // bookings
251 case 'booking_change_status':
252 $link_to_order = $activity->order_id ? '<a href="#" ' . OsBookingHelper::quick_booking_btn_html( $activity->booking_id ) . '>' . __( 'View Booking', 'latepoint' ) . '</a>' : '';
253 $meta_html = '<div class="activity-preview-to">' . ( $link_to_order ? ( '<span class="os-value">' . $link_to_order . '</span>' ) : '' ) . '<span class="os-label">' . __( 'Created On:', 'latepoint' ) . '</span><span class="os-value">' . $activity->nice_created_at . '</span><span class="os-label">' . esc_html__( 'by:', 'latepoint' ) . '</span><span class="os-value">' . $activity->get_user_link() . '</span></div>';
254 $content_html = '<div class="activity-preview-content">' . wp_kses_post( $activity->description ) . '</div>';
255 break;
256 case 'booking_created':
257 $link_to_booking = '<a href="#" ' . OsBookingHelper::quick_booking_btn_html( $activity->booking_id ) . '>' . __( 'View Booking', 'latepoint' ) . '</a>';
258 $meta_html = '<div class="activity-preview-to"><span class="os-value">' . $link_to_booking . '</span><span class="os-label">' . __( 'Created On:', 'latepoint' ) . '</span><span class="os-value">' . $activity->nice_created_at . '</span><span class="os-label">' . esc_html__( 'by:', 'latepoint' ) . '</span><span class="os-value">' . $activity->get_user_link() . '</span></div>';
259 $content_html = '<pre class="format-json">' . esc_html( wp_json_encode( $data['booking_data_vars'], JSON_PRETTY_PRINT | JSON_HEX_TAG ) ) . '</pre>';
260 break;
261 case 'booking_updated':
262 $link_to_booking = '<a href="#" ' . OsBookingHelper::quick_booking_btn_html( $activity->booking_id ) . '>' . __( 'View Booking', 'latepoint' ) . '</a>';
263 $meta_html = '<div class="activity-preview-to"><span class="os-value">' . $link_to_booking . '</span><span class="os-label">' . __( 'Updated On:', 'latepoint' ) . '</span><span class="os-value">' . $activity->nice_created_at . '</span><span class="os-label">' . esc_html__( 'by:', 'latepoint' ) . '</span><span class="os-value">' . $activity->get_user_link() . '</span></div>';
264 $changes = OsUtilHelper::compare_model_data_vars( $data['booking_data_vars']['new'], $data['booking_data_vars']['old'] );
265 $content_html = '<pre class="format-json">' . esc_html( wp_json_encode( $changes, JSON_PRETTY_PRINT | JSON_HEX_TAG ) ) . '</pre>';
266 break;
267 case 'email_sent':
268 $meta_html = '<div class="activity-preview-subject">' . esc_html( $data['extra_data']['subject'] ) . '</div>';
269 $meta_html .= '<div class="activity-preview-to"><span class="os-label">' . __( 'To:', 'latepoint' ) . '</span><span class="os-value">' . esc_html( $data['to'] ) . '</span></div>';
270 $content_html = '<div class="activity-preview-content">' . wp_kses_post( $data['content'] ) . '</div>';
271 break;
272 case 'sms_sent':
273 $meta_html = '<div class="activity-preview-to"><span class="os-label">' . __( 'To:', 'latepoint' ) . '</span><span class="os-value">' . esc_html( $data['to'] ) . '</span></div>';
274 $content_html = '<div class="activity-preview-content">' . wp_kses_post( $data['content'] ) . '</div>';
275 break;
276 case 'http_request':
277 $meta_html = '<div class="activity-preview-to"><span class="os-label">' . __( 'URL:', 'latepoint' ) . '</span><span class="os-value"><a href="#" target="_blank">' . esc_html( $data['to'] ) . '</a></span></div>';
278 $content_html = '<pre class="format-json">' . esc_html( wp_json_encode( $data['content'], JSON_PRETTY_PRINT | JSON_HEX_TAG ) ) . '</pre>';
279 break;
280 case 'process_job_run':
281 $job = new OsProcessJobModel( $data['job_id'] );
282 $name = $job->process->name . ', ID: ' . $job->process->id;
283 $meta_html = '<div class="activity-preview-to"><span class="os-label">' . __( 'Process:', 'latepoint' ) . '</span><span class="os-value">' . esc_html( $name ) . '</span></div>';
284 $content_html = '<pre class="format-json">' . esc_html( $data['run_result'] ) . '</pre>';
285 break;
286 case 'error':
287 $meta_html = '<div class="activity-preview-to"><span class="os-label">' . __( 'Error Message:', 'latepoint' ) . '</span><span class="os-value">' . esc_html( $data['message'] ) . ' | ' . esc_html( $data['error_code'] ) . '</span></div>';
288 $content_html = '<pre class="format-json">' . esc_html( wp_json_encode( $data['extra_description'], JSON_PRETTY_PRINT | JSON_HEX_TAG ) ) . '</pre>';
289 break;
290
291 default:
292 /**
293 * Allow to add custom activity
294 *
295 * @since 5.1.8
296 * @hook latepoint_custom_activity_html
297 *
298 * @param {OsActivityModel} $activity
299 * @param {array} $data
300 *
301 * @returns {array} The array of meta and content HTML
302 */
303 $custom_activity_html = apply_filters( 'latepoint_custom_activity_html', false, $activity, $data );
304 if ( $custom_activity_html !== false ) {
305 $meta_html = $custom_activity_html['meta_html'] ?? '';
306 $content_html = $custom_activity_html['content_html'] ?? '';
307 break;
308 }
309 break;
310 }
311
312 $this->vars['content_html'] = $content_html ?? '';
313 $this->vars['meta_html'] = $meta_html ?? '';
314 $this->vars['status_html'] = $status_html ?? '';
315
316 $this->vars = apply_filters( 'latepoint_activity_view_vars', $this->vars, $activity );
317
318 $this->format_render( __FUNCTION__ );
319 }
320 }
321
322
323 endif;
324