PluginProbe
Booktics – Appointment Booking Calendar for Service Businesses / 1.0.0
Booktics – Appointment Booking Calendar for Service Businesses v1.0.0
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 1.0.4 1.0.5 1.0.6 1.0.7 All 27 releases
booktics / base / models / customer-model.php

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

91 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\User_Model;
7
8 class Customer_Model extends User_Model {
9 /**
10 * Store specific user role
11 *
12 * @var string
13 */
14 protected $role = 'booktics_customer';
15
16 /**
17 * Store specific meta prefix
18 *
19 * @var string
20 */
21 protected $meta_prefix = '_customer_';
22
23 /**
24 * Store user data
25 *
26 * @var array
27 */
28 protected $fillable = [
29 'id' => '',
30 'display_name' => '',
31 'first_name' => '',
32 'last_name' => '',
33 'user_email' => '',
34 'image' => '',
35 'user_login' => '',
36 'phone' => '',
37 'role' => [],
38 'status' => '',
39 'user_registered' => '',
40 'total_booking' => '',
41 'total_amount' => '',
42 ];
43
44 /**
45 * Display name attribute
46 *
47 * @param $customer
48 *
49 * @return string
50 */
51 public function get_display_name_attribute( $customer ) {
52 return $customer->first_name . ' ' . $customer->last_name;
53 }
54
55 /**
56 * email attribute
57 *
58 * @param $customer
59 *
60 * @return string
61 */
62 public function get_email_attribute( $customer ) {
63 return $customer->email ?? $customer->user_email;
64 }
65
66 /**
67 * total booking attribute
68 *
69 * @param $customer
70 *
71 * @return int
72 */
73 public function get_total_booking_attribute( $customer ): int {
74 $db = new Booktics_Database();
75
76 return ( new Order_Model( $db ) )->count( [ 'customer_id' => $customer->id ] );
77 }
78
79 /**
80 * Get total amount of all orders for a customer
81 *
82 * @param object $customer Customer object
83 *
84 * @return float Total amount of customer orders
85 */
86 public function get_total_amount_attribute( $customer ) {
87 $db = new Booktics_Database();
88
89 return ( new Order_Model( $db ) )->sum( 'total', [ 'customer_id' => $customer->id ] );
90 }
91 }