PluginProbe
Booktics – Appointment Booking Calendar for Service Businesses / 1.0.23
Booktics – Appointment Booking Calendar for Service Businesses v1.0.23
1.0.29 1.0.28 1.0.27 1.0.26 1.0.25 1.0.24 1.0.23 1.0.22 1.0.21 1.0.20 1.0.19 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.2 1.0.3 All 31 releases
booktics / base / models / guest-model.php

guest-model.php in Booktics – Appointment Booking Calendar for Service Businesses 1.0.23, at base/models/guest-model.php

71 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Booktics\Models;
4
5 use Booktics\Abstracts\Booktics_Database;
6 use Booktics\Abstracts\Model;
7
8 class Guest_Model extends Model {
9
10 protected $table = 'booktics_guests';
11 protected $fillable = array(
12 'id',
13 'wp_user_id',
14 'name',
15 'user_login',
16 'email',
17 'phone',
18 'description',
19 'status',
20 'image',
21 'created_at',
22 'updated_at',
23 );
24
25 /**
26 * Get virtual attributes for the guest model
27 *
28 * @param object $row
29 *
30 * @return array
31 */
32 protected function get_virtual_attributes( object $row ): array {
33 if ( ! $row ) {
34 return array();
35 }
36
37 $db = new Booktics_Database();
38
39 $total_booking = ( new Order_Model( $db ) )->count( array( 'customer_id' => $row->id ) );
40 $total_amount = ( new Order_Model( $db ) )->sum( 'total', array( 'customer_id' => $row->id ) );
41
42 $orders = ( new Order_Model( $db ) )->get( array( 'customer_id' => $row->id ) );
43
44 // Remove canceled appointment costs from total amount for each customer
45 if ( isset( $orders['items'] ) && is_array( $orders['items'] ) ) {
46 foreach ( $orders['items'] as $order ) {
47 $appointments = (new Appointment_Model())->where('order_id', $order->id);
48
49 if ( ! isset( $appointments ) || ! is_array( $appointments )) {
50 continue;
51 }
52
53 foreach ( $appointments as $appointment) {
54 if ( $appointment->status === 'canceled' ) {
55 $total_amount -= $order->total;
56 $total_booking -= 1;
57 break;
58 }
59 }
60 }
61 }
62
63 return array(
64 'status_label' => ( $row->status == 1 ) ? 'Active' : 'Deactive',
65 'total_booking' => $total_booking,
66 'total_amount' => $total_amount,
67 'user_registered' => gmdate( 'd M Y h:iA', strtotime( $row->created_at ) ),
68 );
69 }
70 }
71