PluginProbe
ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce / 1.2.6
ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce v1.2.6
1.17.9 1.17.8 1.17.7 1.17.6 1.17.5 1.17.4 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 1.3.0 1.3.1 1.3.11 1.3.12 1.3.13 1.3.14 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 All 143 releases
erp / includes / class-people.php

class-people.php in ERP: Complete HR, Accounting & CRM Suite Built for WooCommerce 1.2.6, at includes/class-people.php

161 lines 3.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 namespace WeDevs\ERP;
3
4 /**
5 * People Class
6 */
7 class People extends Item {
8
9 /**
10 * Generate people data
11 *
12 * @param object the item wpdb object
13 *
14 * @return void
15 */
16 protected function populate( $item ) {
17 if ( $item && ! is_wp_error( $item ) ) {
18 $this->id = (int) $item->id;
19 $this->data = $item;
20
21 } else {
22 $this->id = 0;
23 }
24 }
25
26 /**
27 * Fetch a single people
28 *
29 * @param int $people_id
30 *
31 * @return object
32 */
33 protected function get_by_id( $people_id ) {
34 return erp_get_people( $people_id );
35 }
36
37 /**
38 * Check if this people is a WP_User type
39 *
40 * @return boolean
41 */
42 function is_wp_user() {
43 return intval( $this->user_id ) !== 0;
44 }
45
46 /**
47 * Get full name
48 *
49 * @since 1.0.0
50 * @since 1.2.0 Return trimmed string
51 *
52 * @return string
53 */
54 function get_full_name() {
55 $full_name = '';
56
57 if ( in_array( 'company', $this->types ) ) {
58 $full_name = $this->company;
59
60 } elseif ( $this->is_wp_user() ) {
61 $user = \get_user_by( 'id', $this->user_id );
62
63 if ( ! empty( $user->first_name ) ) {
64 $full_name = $user->first_name . ' ' . $user->last_name;
65 }
66
67 $full_name = $user->display_name;
68 } else {
69 $full_name = $this->first_name . ' ' . $this->last_name;
70 }
71
72 return trim( $full_name );
73 }
74
75 /**
76 * Get email address of a user
77 *
78 * @return string
79 */
80 function get_email() {
81 if ( $this->is_wp_user() ) {
82 return \get_user_by( 'id', $this->user_id )->user_email;
83 } else {
84 return $this->email;
85 }
86 }
87
88 /**
89 * Get website address of a user
90 *
91 * @since 1.0
92 *
93 * @return string
94 */
95 function get_website() {
96 if ( $this->is_wp_user() ) {
97 $user = \get_user_by( 'id', $this->user_id );
98 return ( $user->user_url ) ? erp_get_clickable( 'url', $user->user_url ) : '';
99 } else {
100 return ( $this->website ) ? erp_get_clickable( 'url', $this->website ) : '';
101 }
102 }
103
104 /**
105 * Get meta data of a user
106 *
107 * @param string $meta_key
108 * @param string $meta_value
109 */
110 function get_meta( $meta_key, $single = true ) {
111 if ( $this->is_wp_user() ) {
112 return \get_user_meta( $this->user_id, $meta_key, $single );
113 } else {
114 return \erp_people_get_meta( $this->id, $meta_key, $single );
115 }
116 }
117
118 /**
119 * Add meta data to a user
120 *
121 * @param string $meta_key
122 * @param string $meta_value
123 */
124 function add_meta( $meta_key, $meta_value ) {
125 if ( $this->is_wp_user() ) {
126 \add_user_meta( $this->user_id, $meta_key, $meta_value );
127 } else {
128 \erp_people_add_meta( $this->id, $meta_key, $meta_value );
129 }
130 }
131
132 /**
133 * Update meta data to a user
134 *
135 * @param string $meta_key
136 * @param string $meta_value
137 */
138 function update_meta( $meta_key, $meta_value ) {
139 if ( $this->is_wp_user() ) {
140 \update_user_meta( $this->user_id, $meta_key, $meta_value );
141 } else {
142 \erp_people_update_meta( $this->id, $meta_key, $meta_value );
143 }
144 }
145
146 /**
147 * Delete meta data to a user
148 *
149 * @param string $meta_key
150 * @param string $meta_value
151 */
152 function delete_meta( $meta_key ) {
153 if ( $this->is_wp_user() ) {
154 \delete_user_meta( $this->user_id, $meta_key );
155 } else {
156 \erp_people_delete_meta( $this->id, $meta_key );
157 }
158 }
159
160 }
161