1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
|
<?php // phpcs:ignoreFile
namespace AutomateWoo;
if ( ! defined( 'ABSPATH' ) ) exit;
/** * @class Guest_Factory * @since 2.9 */ class Guest_Factory extends Factory {
static $model = 'AutomateWoo\Guest';
/** * @param int $guest_id * @return Guest|bool */ static function get( $guest_id ) { return parent::get( $guest_id ); }
/** * @param $email * @return Guest|bool */ static function get_by_email( $email ) {
if ( ! is_email( $email ) ) return false;
if ( Cache::exists( $email, 'guest_email' ) ) { return static::get( Cache::get( $email, 'guest_email' ) ); }
$guest = new Guest(); $guest->get_by( 'email', $email );
if ( ! $guest->exists ) { Cache::set( $email, 0, 'guest_email' ); return false; }
return $guest; }
/** * @deprecated * * @param $key * * @return Guest|bool */ static function get_by_key( $key ) {
wc_deprecated_function( __METHOD__, '5.2.0' );
if ( ! $key ) return false;
$guest = new Guest(); $guest->get_by( 'tracking_key', $key );
if ( ! $guest->exists ) { return false; }
return $guest; }
/** * @param Guest $guest */ static function update_cache( $guest ) { parent::update_cache( $guest );
Cache::set( $guest->get_email(), $guest->get_id(), 'guest_email' ); }
/** * @param Guest $guest */ static function clean_cache( $guest ) { parent::clean_cache( $guest );
static::clear_cached_prop( $guest, 'email', 'guest_email' ); }
/** * @param string $email * @return Guest */ static function create( $email ) {
$guest = new Guest(); $guest->set_email( Clean::email( $email) ); $guest->set_date_created( new DateTime() ); $guest->save();
return $guest; }
}
|