| @@ -1,91 +1,65 @@ | ||
| 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 | - } | |
| 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 | + } | |
| 91 | 65 | } |