Completed
Branch master (d4ace2)
by
unknown
04:43
created
core/db_models/EEM_Ticket_Price.model.php 1 patch
Indentation   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -9,49 +9,49 @@
 block discarded – undo
9 9
  */
10 10
 class EEM_Ticket_Price extends EEM_Base
11 11
 {
12
-    protected static ?EEM_Ticket_Price $_instance = null;
12
+	protected static ?EEM_Ticket_Price $_instance = null;
13 13
 
14 14
 
15
-    /**
16
-     * private constructor to prevent direct creation
17
-     *
18
-     * @param string|null $timezone string representing the timezone we want to set for returned Date Time Strings (and
19
-     *                              any incoming timezone data that gets saved).  Note this just sends the timezone
20
-     *                              info to the date time model field objects.  Default is NULL (and will be assumed
21
-     *                              using the set timezone in the 'timezone_string' wp option)
22
-     * @throws EE_Error
23
-     */
24
-    protected function __construct(?string $timezone = '')
25
-    {
26
-        $this->singular_item = esc_html__('Ticket Price', 'event_espresso');
27
-        $this->plural_item   = esc_html__('Ticket Prices', 'event_espresso');
15
+	/**
16
+	 * private constructor to prevent direct creation
17
+	 *
18
+	 * @param string|null $timezone string representing the timezone we want to set for returned Date Time Strings (and
19
+	 *                              any incoming timezone data that gets saved).  Note this just sends the timezone
20
+	 *                              info to the date time model field objects.  Default is NULL (and will be assumed
21
+	 *                              using the set timezone in the 'timezone_string' wp option)
22
+	 * @throws EE_Error
23
+	 */
24
+	protected function __construct(?string $timezone = '')
25
+	{
26
+		$this->singular_item = esc_html__('Ticket Price', 'event_espresso');
27
+		$this->plural_item   = esc_html__('Ticket Prices', 'event_espresso');
28 28
 
29
-        $this->_tables                                            = [
30
-            'Ticket_Price' => new EE_Primary_Table('esp_ticket_price', 'TKP_ID'),
31
-        ];
32
-        $this->_fields                                            = [
33
-            'Ticket_Price' => [
34
-                'TKP_ID' => new EE_Primary_Key_Int_Field('TKP_ID', 'Ticket Price ID'),
35
-                'TKT_ID' => new EE_Foreign_Key_Int_Field('TKT_ID', 'Ticket Id', false, 0, 'Ticket'),
36
-                'PRC_ID' => new EE_Foreign_Key_Int_Field('PRC_ID', 'Price ID', false, 0, 'Price'),
37
-            ],
38
-        ];
39
-        $this->_model_relations                                   = [
40
-            'Ticket' => new EE_Belongs_To_Relation(),
41
-            'Price'  => new EE_Belongs_To_Relation(),
42
-        ];
43
-        $this->_model_chain_to_wp_user                            = 'Ticket';
44
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] =
45
-            new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
46
-        // account for default tickets in the caps
47
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
48
-            new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
49
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ]       =
50
-            new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
51
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ]     =
52
-            new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
53
-        // follow the caps of the ticket
54
-        $this->_caps_slug = 'tickets';
55
-        parent::__construct($timezone);
56
-    }
29
+		$this->_tables                                            = [
30
+			'Ticket_Price' => new EE_Primary_Table('esp_ticket_price', 'TKP_ID'),
31
+		];
32
+		$this->_fields                                            = [
33
+			'Ticket_Price' => [
34
+				'TKP_ID' => new EE_Primary_Key_Int_Field('TKP_ID', 'Ticket Price ID'),
35
+				'TKT_ID' => new EE_Foreign_Key_Int_Field('TKT_ID', 'Ticket Id', false, 0, 'Ticket'),
36
+				'PRC_ID' => new EE_Foreign_Key_Int_Field('PRC_ID', 'Price ID', false, 0, 'Price'),
37
+			],
38
+		];
39
+		$this->_model_relations                                   = [
40
+			'Ticket' => new EE_Belongs_To_Relation(),
41
+			'Price'  => new EE_Belongs_To_Relation(),
42
+		];
43
+		$this->_model_chain_to_wp_user                            = 'Ticket';
44
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] =
45
+			new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
46
+		// account for default tickets in the caps
47
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
48
+			new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
49
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ]       =
50
+			new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
51
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ]     =
52
+			new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event');
53
+		// follow the caps of the ticket
54
+		$this->_caps_slug = 'tickets';
55
+		parent::__construct($timezone);
56
+	}
57 57
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Currency.model.php 1 patch
Indentation   +98 added lines, -98 removed lines patch added patch discarded remove patch
@@ -9,109 +9,109 @@
 block discarded – undo
9 9
  */
10 10
 class EEM_Currency extends EEM_Base
11 11
 {
12
-    protected static ?EEM_Currency $_instance = null;
12
+	protected static ?EEM_Currency $_instance = null;
13 13
 
14 14
 
15
-    /**
16
-     * @param string|null $timezone
17
-     * @throws EE_Error
18
-     */
19
-    protected function __construct(?string $timezone = '')
20
-    {
21
-        $this->singular_item    = esc_html__('Currency', 'event_espresso');
22
-        $this->plural_item      = esc_html__('Currencies', 'event_espresso');
23
-        $this->_tables          = [
24
-            'Currency' => new EE_Primary_Table('esp_currency', 'CUR_code'),
25
-        ];
26
-        $this->_fields          = [
27
-            'Currency' => [
28
-                'CUR_code'    => new EE_Primary_Key_String_Field(
29
-                    'CUR_code',
30
-                    esc_html__('Currency Code', 'event_espresso')
31
-                )
32
-                ,
33
-                'CUR_single'  => new EE_Plain_Text_Field(
34
-                    'CUR_single',
35
-                    esc_html__('Currency Name Singular', 'event_espresso'),
36
-                    false
37
-                ),
38
-                'CUR_plural'  => new EE_Plain_Text_Field(
39
-                    'CUR_plural',
40
-                    esc_html__('Currency Name Plural', 'event_espresso'),
41
-                    false
42
-                ),
43
-                'CUR_sign'    => new EE_Plain_Text_Field(
44
-                    'CUR_sign',
45
-                    esc_html__('Currency Sign', 'event_espresso'),
46
-                    false
47
-                ),
48
-                'CUR_dec_plc' => new EE_Integer_Field(
49
-                    'CUR_dec_plc',
50
-                    esc_html__('Currency Decimal Places', 'event_espresso'),
51
-                    false,
52
-                    2
53
-                ),
54
-                'CUR_active'  => new EE_Boolean_Field(
55
-                    'CUR_active',
56
-                    esc_html__('Active?', 'event_espresso'),
57
-                    false,
58
-                    true
59
-                ),
60
-            ],
61
-        ];
62
-        $this->_model_relations = [
63
-            'Payment_Method' => new EE_HABTM_Relation('Currency_Payment_Method'),
64
-        ];
65
-        // this model is generally available for reading
66
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
15
+	/**
16
+	 * @param string|null $timezone
17
+	 * @throws EE_Error
18
+	 */
19
+	protected function __construct(?string $timezone = '')
20
+	{
21
+		$this->singular_item    = esc_html__('Currency', 'event_espresso');
22
+		$this->plural_item      = esc_html__('Currencies', 'event_espresso');
23
+		$this->_tables          = [
24
+			'Currency' => new EE_Primary_Table('esp_currency', 'CUR_code'),
25
+		];
26
+		$this->_fields          = [
27
+			'Currency' => [
28
+				'CUR_code'    => new EE_Primary_Key_String_Field(
29
+					'CUR_code',
30
+					esc_html__('Currency Code', 'event_espresso')
31
+				)
32
+				,
33
+				'CUR_single'  => new EE_Plain_Text_Field(
34
+					'CUR_single',
35
+					esc_html__('Currency Name Singular', 'event_espresso'),
36
+					false
37
+				),
38
+				'CUR_plural'  => new EE_Plain_Text_Field(
39
+					'CUR_plural',
40
+					esc_html__('Currency Name Plural', 'event_espresso'),
41
+					false
42
+				),
43
+				'CUR_sign'    => new EE_Plain_Text_Field(
44
+					'CUR_sign',
45
+					esc_html__('Currency Sign', 'event_espresso'),
46
+					false
47
+				),
48
+				'CUR_dec_plc' => new EE_Integer_Field(
49
+					'CUR_dec_plc',
50
+					esc_html__('Currency Decimal Places', 'event_espresso'),
51
+					false,
52
+					2
53
+				),
54
+				'CUR_active'  => new EE_Boolean_Field(
55
+					'CUR_active',
56
+					esc_html__('Active?', 'event_espresso'),
57
+					false,
58
+					true
59
+				),
60
+			],
61
+		];
62
+		$this->_model_relations = [
63
+			'Payment_Method' => new EE_HABTM_Relation('Currency_Payment_Method'),
64
+		];
65
+		// this model is generally available for reading
66
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
67 67
 
68
-        parent::__construct($timezone);
69
-    }
68
+		parent::__construct($timezone);
69
+	}
70 70
 
71 71
 
72
-    /**
73
-     * Gets all the active currencies, and orders them by their singular name, and then their code
74
-     * (may be overridden)
75
-     *
76
-     * @param array $query_params
77
-     * @return EE_Currency[]
78
-     * @throws EE_Error
79
-     * @throws ReflectionException
80
-     * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
81
-     */
82
-    public function get_all_active($query_params = [])
83
-    {
84
-        $query_params[0]['CUR_active'] = true;
85
-        if (! isset($query_params['order_by'])) {
86
-            $query_params['order_by'] = ['CUR_code' => 'ASC', 'CUR_single' => 'ASC'];
87
-        }
88
-        return $this->get_all($query_params);
89
-    }
72
+	/**
73
+	 * Gets all the active currencies, and orders them by their singular name, and then their code
74
+	 * (may be overridden)
75
+	 *
76
+	 * @param array $query_params
77
+	 * @return EE_Currency[]
78
+	 * @throws EE_Error
79
+	 * @throws ReflectionException
80
+	 * @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md
81
+	 */
82
+	public function get_all_active($query_params = [])
83
+	{
84
+		$query_params[0]['CUR_active'] = true;
85
+		if (! isset($query_params['order_by'])) {
86
+			$query_params['order_by'] = ['CUR_code' => 'ASC', 'CUR_single' => 'ASC'];
87
+		}
88
+		return $this->get_all($query_params);
89
+	}
90 90
 
91 91
 
92
-    /**
93
-     * Gets all the currencies which can be used by that payment method type
94
-     *
95
-     * @param EE_PMT_Base $payment_method_type
96
-     * @return EE_Currency[]
97
-     * @throws EE_Error
98
-     * @throws ReflectionException
99
-     */
100
-    public function get_all_currencies_usable_by($payment_method_type)
101
-    {
102
-        if (
103
-            $payment_method_type instanceof EE_PMT_Base
104
-            && $payment_method_type->get_gateway()
105
-        ) {
106
-            $currencies_supported = $payment_method_type->get_gateway()->currencies_supported();
107
-        } else {
108
-            $currencies_supported = EE_Gateway::all_currencies_supported;
109
-        }
110
-        if ($currencies_supported == EE_Gateway::all_currencies_supported || empty($currencies_supported)) {
111
-            $currencies = $this->get_all_active();
112
-        } else {
113
-            $currencies = $this->get_all_active([['CUR_code' => ['IN', $currencies_supported]]]);
114
-        }
115
-        return $currencies;
116
-    }
92
+	/**
93
+	 * Gets all the currencies which can be used by that payment method type
94
+	 *
95
+	 * @param EE_PMT_Base $payment_method_type
96
+	 * @return EE_Currency[]
97
+	 * @throws EE_Error
98
+	 * @throws ReflectionException
99
+	 */
100
+	public function get_all_currencies_usable_by($payment_method_type)
101
+	{
102
+		if (
103
+			$payment_method_type instanceof EE_PMT_Base
104
+			&& $payment_method_type->get_gateway()
105
+		) {
106
+			$currencies_supported = $payment_method_type->get_gateway()->currencies_supported();
107
+		} else {
108
+			$currencies_supported = EE_Gateway::all_currencies_supported;
109
+		}
110
+		if ($currencies_supported == EE_Gateway::all_currencies_supported || empty($currencies_supported)) {
111
+			$currencies = $this->get_all_active();
112
+		} else {
113
+			$currencies = $this->get_all_active([['CUR_code' => ['IN', $currencies_supported]]]);
114
+		}
115
+		return $currencies;
116
+	}
117 117
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Event_Venue.model.php 1 patch
Indentation   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -9,67 +9,67 @@
 block discarded – undo
9 9
  */
10 10
 class EEM_Event_Venue extends EEM_Base
11 11
 {
12
-    protected static ?EEM_Event_Venue $_instance = null;
12
+	protected static ?EEM_Event_Venue $_instance = null;
13 13
 
14 14
 
15
-    /**
16
-     * @param string|null $timezone
17
-     * @throws EE_Error
18
-     */
19
-    protected function __construct(?string $timezone = '')
20
-    {
21
-        $this->singular_item    = esc_html__('Event to Question Group Link', 'event_espresso');
22
-        $this->plural_item      = esc_html__('Event to Question Group Links', 'event_espresso');
23
-        $this->_tables          = [
24
-            'Event_Venue' => new EE_Primary_Table('esp_event_venue', 'EVV_ID'),
25
-        ];
26
-        $this->_fields          = [
27
-            'Event_Venue' => [
28
-                'EVV_ID'      => new EE_Primary_Key_Int_Field(
29
-                    'EVV_ID',
30
-                    esc_html__('Event to Venue Link ID', 'event_espresso')
31
-                ),
32
-                'EVT_ID'      => new EE_Foreign_Key_Int_Field(
33
-                    'EVT_ID',
34
-                    esc_html__('Event ID', 'event_espresso'),
35
-                    false,
36
-                    0,
37
-                    'Event'
38
-                ),
39
-                'VNU_ID'      => new EE_Foreign_Key_Int_Field(
40
-                    'VNU_ID',
41
-                    esc_html__('Venue ID', 'event_espresso'),
42
-                    false,
43
-                    0,
44
-                    'Venue'
45
-                ),
46
-                'EVV_primary' => new EE_Boolean_Field(
47
-                    'EVV_primary',
48
-                    esc_html__(
49
-                        "Flag indicating venue is primary one for event",
50
-                        "event_espresso"
51
-                    ),
52
-                    false,
53
-                    true
54
-                ),
15
+	/**
16
+	 * @param string|null $timezone
17
+	 * @throws EE_Error
18
+	 */
19
+	protected function __construct(?string $timezone = '')
20
+	{
21
+		$this->singular_item    = esc_html__('Event to Question Group Link', 'event_espresso');
22
+		$this->plural_item      = esc_html__('Event to Question Group Links', 'event_espresso');
23
+		$this->_tables          = [
24
+			'Event_Venue' => new EE_Primary_Table('esp_event_venue', 'EVV_ID'),
25
+		];
26
+		$this->_fields          = [
27
+			'Event_Venue' => [
28
+				'EVV_ID'      => new EE_Primary_Key_Int_Field(
29
+					'EVV_ID',
30
+					esc_html__('Event to Venue Link ID', 'event_espresso')
31
+				),
32
+				'EVT_ID'      => new EE_Foreign_Key_Int_Field(
33
+					'EVT_ID',
34
+					esc_html__('Event ID', 'event_espresso'),
35
+					false,
36
+					0,
37
+					'Event'
38
+				),
39
+				'VNU_ID'      => new EE_Foreign_Key_Int_Field(
40
+					'VNU_ID',
41
+					esc_html__('Venue ID', 'event_espresso'),
42
+					false,
43
+					0,
44
+					'Venue'
45
+				),
46
+				'EVV_primary' => new EE_Boolean_Field(
47
+					'EVV_primary',
48
+					esc_html__(
49
+						"Flag indicating venue is primary one for event",
50
+						"event_espresso"
51
+					),
52
+					false,
53
+					true
54
+				),
55 55
 
56
-            ],
57
-        ];
58
-        $this->_model_relations = [
59
-            'Event' => new EE_Belongs_To_Relation(),
60
-            'Venue' => new EE_Belongs_To_Relation(),
61
-        ];
62
-        // this model is generally available for reading
63
-        $path_to_event                                                  = 'Event';
64
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ]       =
65
-            new EE_Restriction_Generator_Event_Related_Public($path_to_event);
66
-        $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
67
-            new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
68
-        $this->_cap_restriction_generators[ EEM_Base::caps_edit ]       =
69
-            new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
70
-        $this->_cap_restriction_generators[ EEM_Base::caps_delete ]     =
71
-            new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit);
72
-        $this->model_chain_to_password                                  = $path_to_event;
73
-        parent::__construct($timezone);
74
-    }
56
+			],
57
+		];
58
+		$this->_model_relations = [
59
+			'Event' => new EE_Belongs_To_Relation(),
60
+			'Venue' => new EE_Belongs_To_Relation(),
61
+		];
62
+		// this model is generally available for reading
63
+		$path_to_event                                                  = 'Event';
64
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ]       =
65
+			new EE_Restriction_Generator_Event_Related_Public($path_to_event);
66
+		$this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] =
67
+			new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
68
+		$this->_cap_restriction_generators[ EEM_Base::caps_edit ]       =
69
+			new EE_Restriction_Generator_Event_Related_Protected($path_to_event);
70
+		$this->_cap_restriction_generators[ EEM_Base::caps_delete ]     =
71
+			new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit);
72
+		$this->model_chain_to_password                                  = $path_to_event;
73
+		parent::__construct($timezone);
74
+	}
75 75
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Attendee.model.php 1 patch
Indentation   +408 added lines, -408 removed lines patch added patch discarded remove patch
@@ -13,420 +13,420 @@
 block discarded – undo
13 13
  */
14 14
 class EEM_Attendee extends EEM_CPT_Base
15 15
 {
16
-    protected static ?EEM_Attendee $_instance = null;
16
+	protected static ?EEM_Attendee $_instance = null;
17 17
 
18
-    /**
19
-     * QST_system for questions are strings not integers now,
20
-     * so these constants are deprecated.
21
-     * Please instead use the EEM_Attendee::system_question_* constants
22
-     *
23
-     * @deprecated
24
-     */
25
-    const fname_question_id = 1;
18
+	/**
19
+	 * QST_system for questions are strings not integers now,
20
+	 * so these constants are deprecated.
21
+	 * Please instead use the EEM_Attendee::system_question_* constants
22
+	 *
23
+	 * @deprecated
24
+	 */
25
+	const fname_question_id = 1;
26 26
 
27
-    /**
28
-     * @deprecated
29
-     */
30
-    const lname_question_id = 2;
27
+	/**
28
+	 * @deprecated
29
+	 */
30
+	const lname_question_id = 2;
31 31
 
32 32
 
33
-    /**
34
-     * @deprecated
35
-     */
36
-    const email_question_id = 3;
33
+	/**
34
+	 * @deprecated
35
+	 */
36
+	const email_question_id = 3;
37 37
 
38 38
 
39
-    /**
40
-     * @deprecated
41
-     */
42
-    const address_question_id = 4;
39
+	/**
40
+	 * @deprecated
41
+	 */
42
+	const address_question_id = 4;
43 43
 
44 44
 
45
-    /**
46
-     * @deprecated
47
-     */
48
-    const address2_question_id = 5;
49
-
50
-
51
-    /**
52
-     * @deprecated
53
-     */
54
-    const city_question_id = 6;
55
-
56
-
57
-    /**
58
-     * @deprecated
59
-     */
60
-    const state_question_id = 7;
61
-
62
-
63
-    /**
64
-     * @deprecated
65
-     */
66
-    const country_question_id = 8;
67
-
68
-
69
-    /**
70
-     * @deprecated
71
-     */
72
-    const zip_question_id = 9;
73
-
74
-
75
-    /**
76
-     * @deprecated
77
-     */
78
-    const phone_question_id = 10;
79
-
80
-    /**
81
-     * When looking for questions that correspond to attendee fields,
82
-     * look for the question with this QST_system value.
83
-     * These replace the old constants like EEM_Attendee::*_question_id
84
-     */
85
-    const system_question_fname         = 'fname';
86
-
87
-    const system_question_lname         = 'lname';
88
-
89
-    const system_question_email         = 'email';
90
-
91
-    const system_question_email_confirm = 'email_confirm';
92
-
93
-    const system_question_address       = 'address';
94
-
95
-    const system_question_address2      = 'address2';
96
-
97
-    const system_question_city          = 'city';
98
-
99
-    const system_question_state         = 'state';
100
-
101
-    const system_question_country       = 'country';
102
-
103
-    const system_question_zip           = 'zip';
104
-
105
-    const system_question_phone         = 'phone';
106
-
107
-    /**
108
-     * Keys are all the EEM_Attendee::system_question_* constants, which are
109
-     * also all the values of QST_system in the questions table, and values
110
-     * are their corresponding Attendee field names
111
-     *
112
-     * @var array
113
-     */
114
-    protected $_system_question_to_attendee_field_name = [
115
-        EEM_Attendee::system_question_fname    => 'ATT_fname',
116
-        EEM_Attendee::system_question_lname    => 'ATT_lname',
117
-        EEM_Attendee::system_question_email    => 'ATT_email',
118
-        EEM_Attendee::system_question_address  => 'ATT_address',
119
-        EEM_Attendee::system_question_address2 => 'ATT_address2',
120
-        EEM_Attendee::system_question_city     => 'ATT_city',
121
-        EEM_Attendee::system_question_state    => 'STA_ID',
122
-        EEM_Attendee::system_question_country  => 'CNT_ISO',
123
-        EEM_Attendee::system_question_zip      => 'ATT_zip',
124
-        EEM_Attendee::system_question_phone    => 'ATT_phone',
125
-    ];
126
-
127
-
128
-    /**
129
-     * @param string|null            $timezone
130
-     * @param ModelFieldFactory|null $model_field_factory
131
-     * @throws EE_Error
132
-     */
133
-    protected function __construct(?string $timezone = '', ModelFieldFactory $model_field_factory = null)
134
-    {
135
-        $this->singular_item           = esc_html__('Attendee', 'event_espresso');
136
-        $this->plural_item             = esc_html__('Attendees', 'event_espresso');
137
-        $this->_tables                 = [
138
-            'Attendee_CPT'  => new EE_Primary_Table('posts', 'ID'),
139
-            'Attendee_Meta' => new EE_Secondary_Table(
140
-                'esp_attendee_meta',
141
-                'ATTM_ID',
142
-                'ATT_ID'
143
-            ),
144
-        ];
145
-        $this->_fields                 = [
146
-            'Attendee_CPT'  => [
147
-                'ATT_ID'        => $model_field_factory->createPrimaryKeyIntField(
148
-                    'ID',
149
-                    esc_html__('Attendee ID', 'event_espresso')
150
-                ),
151
-                'ATT_full_name' => $model_field_factory->createPlainTextField(
152
-                    'post_title',
153
-                    esc_html__('Attendee Full Name', 'event_espresso'),
154
-                    false,
155
-                    esc_html__('Unknown', 'event_espresso')
156
-                ),
157
-                'ATT_bio'       => $model_field_factory->createPostContentField(
158
-                    'post_content',
159
-                    esc_html__('Attendee Biography', 'event_espresso'),
160
-                    false,
161
-                    esc_html__('No Biography Provided', 'event_espresso')
162
-                ),
163
-                'ATT_slug'      => $model_field_factory->createSlugField(
164
-                    'post_name',
165
-                    esc_html__('Attendee URL Slug', 'event_espresso')
166
-                ),
167
-                'ATT_created'   => $model_field_factory->createDatetimeField(
168
-                    'post_date',
169
-                    esc_html__('Time Attendee Created', 'event_espresso')
170
-                ),
171
-                'ATT_short_bio' => $model_field_factory->createSimpleHtmlField(
172
-                    'post_excerpt',
173
-                    esc_html__('Attendee Short Biography', 'event_espresso'),
174
-                    true,
175
-                    esc_html__('No Biography Provided', 'event_espresso')
176
-                ),
177
-                'ATT_modified'  => $model_field_factory->createDatetimeField(
178
-                    'post_modified',
179
-                    esc_html__('Time Attendee Last Modified', 'event_espresso')
180
-                ),
181
-                'ATT_author'    => $model_field_factory->createWpUserField(
182
-                    'post_author',
183
-                    esc_html__('Creator ID of the first Event attended', 'event_espresso'),
184
-                    false
185
-                ),
186
-                'ATT_parent'    => $model_field_factory->createDbOnlyIntField(
187
-                    'post_parent',
188
-                    esc_html__('Parent Attendee (unused)', 'event_espresso'),
189
-                    false,
190
-                    0
191
-                ),
192
-                'post_type'     => $model_field_factory->createWpPostTypeField(EspressoPostType::ATTENDEES),
193
-                'status'        => $model_field_factory->createWpPostStatusField(
194
-                    'post_status',
195
-                    esc_html__('Attendee Status', 'event_espresso'),
196
-                    false,
197
-                    'publish'
198
-                ),
199
-                'password'      => new EE_Password_Field(
200
-                    'post_password',
201
-                    esc_html__('Password', 'event_espresso'),
202
-                    false,
203
-                    '',
204
-                    [
205
-                        'ATT_bio',
206
-                        'ATT_short_bio',
207
-                        'ATT_address',
208
-                        'ATT_address2',
209
-                        'ATT_city',
210
-                        'STA_ID',
211
-                        'CNT_ISO',
212
-                        'ATT_zip',
213
-                        'ATT_email',
214
-                        'ATT_phone',
215
-                    ]
216
-                ),
217
-            ],
218
-            'Attendee_Meta' => [
219
-                'ATTM_ID'      => $model_field_factory->createDbOnlyIntField(
220
-                    'ATTM_ID',
221
-                    esc_html__('Attendee Meta Row ID', 'event_espresso'),
222
-                    false
223
-                ),
224
-                'ATT_ID_fk'    => $model_field_factory->createDbOnlyIntField(
225
-                    'ATT_ID',
226
-                    esc_html__('Foreign Key to Attendee in Post Table', 'event_espresso'),
227
-                    false
228
-                ),
229
-                'ATT_fname'    => $model_field_factory->createPlainTextField(
230
-                    'ATT_fname',
231
-                    esc_html__('First Name', 'event_espresso')
232
-                ),
233
-                'ATT_lname'    => $model_field_factory->createPlainTextField(
234
-                    'ATT_lname',
235
-                    esc_html__('Last Name', 'event_espresso')
236
-                ),
237
-                'ATT_address'  => $model_field_factory->createPlainTextField(
238
-                    'ATT_address',
239
-                    esc_html__('Address Part 1', 'event_espresso')
240
-                ),
241
-                'ATT_address2' => $model_field_factory->createPlainTextField(
242
-                    'ATT_address2',
243
-                    esc_html__('Address Part 2', 'event_espresso')
244
-                ),
245
-                'ATT_city'     => $model_field_factory->createPlainTextField(
246
-                    'ATT_city',
247
-                    esc_html__('City', 'event_espresso')
248
-                ),
249
-                'STA_ID'       => $model_field_factory->createForeignKeyIntField(
250
-                    'STA_ID',
251
-                    esc_html__('State', 'event_espresso'),
252
-                    true,
253
-                    0,
254
-                    'State'
255
-                ),
256
-                'CNT_ISO'      => $model_field_factory->createForeignKeyStringField(
257
-                    'CNT_ISO',
258
-                    esc_html__('Country', 'event_espresso'),
259
-                    true,
260
-                    '',
261
-                    'Country'
262
-                ),
263
-                'ATT_zip'      => $model_field_factory->createPlainTextField(
264
-                    'ATT_zip',
265
-                    esc_html__('ZIP/Postal Code', 'event_espresso')
266
-                ),
267
-                'ATT_email'    => $model_field_factory->createEmailField(
268
-                    'ATT_email',
269
-                    esc_html__('Email Address', 'event_espresso')
270
-                ),
271
-                'ATT_phone'    => $model_field_factory->createPlainTextField(
272
-                    'ATT_phone',
273
-                    esc_html__('Phone', 'event_espresso')
274
-                ),
275
-            ],
276
-        ];
277
-        $this->_model_relations        = [
278
-            'Registration'      => new EE_Has_Many_Relation(),
279
-            'State'             => new EE_Belongs_To_Relation(),
280
-            'Country'           => new EE_Belongs_To_Relation(),
281
-            'Event'             => new EE_HABTM_Relation('Registration', false),
282
-            'WP_User'           => new EE_Belongs_To_Relation(),
283
-            'Message'           => new EE_Has_Many_Any_Relation(false),
284
-            // allow deletion of attendees even if they have messages in the queue for them.
285
-            'Term_Relationship' => new EE_Has_Many_Relation(),
286
-            'Term_Taxonomy'     => new EE_HABTM_Relation('Term_Relationship'),
287
-        ];
288
-        $this->_caps_slug              = 'contacts';
289
-        $this->model_chain_to_password = '';
290
-        parent::__construct($timezone);
291
-    }
292
-
293
-
294
-    /**
295
-     * Gets the name of the field on the attendee model corresponding to the system question string
296
-     * which should be one of the keys from EEM_Attendee::_system_question_to_attendee_field_name
297
-     *
298
-     * @param string $system_question_string
299
-     * @return string|null if not found
300
-     */
301
-    public function get_attendee_field_for_system_question($system_question_string)
302
-    {
303
-        return isset($this->_system_question_to_attendee_field_name[ $system_question_string ])
304
-            ? $this->_system_question_to_attendee_field_name[ $system_question_string ]
305
-            : null;
306
-    }
307
-
308
-
309
-    /**
310
-     * Gets mapping from esp_question.QST_system values to their corresponding attendee field names
311
-     *
312
-     * @return array
313
-     */
314
-    public function system_question_to_attendee_field_mapping()
315
-    {
316
-        return $this->_system_question_to_attendee_field_name;
317
-    }
318
-
319
-
320
-    /**
321
-     * Gets all the attendees for a transaction (by using the esp_registration as a join table)
322
-     *
323
-     * @param EE_Transaction /int $transaction_id_or_obj EE_Transaction or its ID
324
-     * @return EE_Attendee[]|EE_Base_Class[]
325
-     * @throws EE_Error
326
-     */
327
-    public function get_attendees_for_transaction($transaction_id_or_obj)
328
-    {
329
-        return $this->get_all(
330
-            [
331
-                [
332
-                    'Registration.Transaction.TXN_ID' => $transaction_id_or_obj instanceof EE_Transaction
333
-                        ? $transaction_id_or_obj->ID()
334
-                        : $transaction_id_or_obj,
335
-                ],
336
-            ]
337
-        );
338
-    }
339
-
340
-
341
-    /**
342
-     * retrieve  a single attendee from db via their ID
343
-     *
344
-     * @param $ATT_ID
345
-     * @return mixed array on success, FALSE on fail
346
-     * @deprecated
347
-     */
348
-    public function get_attendee_by_ID($ATT_ID = false)
349
-    {
350
-        // retrieve a particular EE_Attendee
351
-        return $this->get_one_by_ID($ATT_ID);
352
-    }
353
-
354
-
355
-    /**
356
-     * retrieve  a single attendee from db via their ID
357
-     *
358
-     * @param array $where_cols_n_values
359
-     * @return mixed array on success, FALSE on fail
360
-     * @throws EE_Error
361
-     */
362
-    public function get_attendee($where_cols_n_values = [])
363
-    {
364
-        if (empty($where_cols_n_values)) {
365
-            return false;
366
-        }
367
-        $attendee = $this->get_all([$where_cols_n_values]);
368
-        if (! empty($attendee)) {
369
-            return array_shift($attendee);
370
-        }
371
-        return false;
372
-    }
373
-
374
-
375
-    /**
376
-     * Search for an existing Attendee record in the DB
377
-     *
378
-     * @param array $where_cols_n_values
379
-     * @return bool|mixed
380
-     * @throws EE_Error
381
-     */
382
-    public function find_existing_attendee($where_cols_n_values = null)
383
-    {
384
-        // search by combo of first and last names plus the email address
385
-        $attendee_data_keys = [
386
-            'ATT_fname' => $this->_ATT_fname,
387
-            'ATT_lname' => $this->_ATT_lname,
388
-            'ATT_email' => $this->_ATT_email,
389
-        ];
390
-        // no search params means attendee object already exists.
391
-        $where_cols_n_values = is_array($where_cols_n_values) && ! empty($where_cols_n_values)
392
-            ? $where_cols_n_values
393
-            : $attendee_data_keys;
394
-        $valid_data          = true;
395
-        // check for required values
396
-        $valid_data = isset($where_cols_n_values['ATT_fname']) && ! empty($where_cols_n_values['ATT_fname'])
397
-            ? $valid_data
398
-            : false;
399
-        $valid_data = isset($where_cols_n_values['ATT_lname']) && ! empty($where_cols_n_values['ATT_lname'])
400
-            ? $valid_data
401
-            : false;
402
-        $valid_data = isset($where_cols_n_values['ATT_email']) && ! empty($where_cols_n_values['ATT_email'])
403
-            ? $valid_data
404
-            : false;
405
-        if ($valid_data) {
406
-            $attendee = $this->get_attendee($where_cols_n_values);
407
-            if ($attendee instanceof EE_Attendee) {
408
-                return $attendee;
409
-            }
410
-        }
411
-        return false;
412
-    }
413
-
414
-
415
-    /**
416
-     * Takes an incoming array of EE_Registration ids
417
-     * and sends back a list of corresponding non duplicate EE_Attendee objects.
418
-     *
419
-     * @param array $ids array of EE_Registration ids
420
-     * @return EE_Attendee[]|EE_Base_Class[]
421
-     * @throws EE_Error
422
-     * @since  4.3.0
423
-     */
424
-    public function get_array_of_contacts_from_reg_ids($ids)
425
-    {
426
-        $ids    = (array) $ids;
427
-        $_where = [
428
-            'Registration.REG_ID' => ['in', $ids],
429
-        ];
430
-        return $this->get_all([$_where]);
431
-    }
45
+	/**
46
+	 * @deprecated
47
+	 */
48
+	const address2_question_id = 5;
49
+
50
+
51
+	/**
52
+	 * @deprecated
53
+	 */
54
+	const city_question_id = 6;
55
+
56
+
57
+	/**
58
+	 * @deprecated
59
+	 */
60
+	const state_question_id = 7;
61
+
62
+
63
+	/**
64
+	 * @deprecated
65
+	 */
66
+	const country_question_id = 8;
67
+
68
+
69
+	/**
70
+	 * @deprecated
71
+	 */
72
+	const zip_question_id = 9;
73
+
74
+
75
+	/**
76
+	 * @deprecated
77
+	 */
78
+	const phone_question_id = 10;
79
+
80
+	/**
81
+	 * When looking for questions that correspond to attendee fields,
82
+	 * look for the question with this QST_system value.
83
+	 * These replace the old constants like EEM_Attendee::*_question_id
84
+	 */
85
+	const system_question_fname         = 'fname';
86
+
87
+	const system_question_lname         = 'lname';
88
+
89
+	const system_question_email         = 'email';
90
+
91
+	const system_question_email_confirm = 'email_confirm';
92
+
93
+	const system_question_address       = 'address';
94
+
95
+	const system_question_address2      = 'address2';
96
+
97
+	const system_question_city          = 'city';
98
+
99
+	const system_question_state         = 'state';
100
+
101
+	const system_question_country       = 'country';
102
+
103
+	const system_question_zip           = 'zip';
104
+
105
+	const system_question_phone         = 'phone';
106
+
107
+	/**
108
+	 * Keys are all the EEM_Attendee::system_question_* constants, which are
109
+	 * also all the values of QST_system in the questions table, and values
110
+	 * are their corresponding Attendee field names
111
+	 *
112
+	 * @var array
113
+	 */
114
+	protected $_system_question_to_attendee_field_name = [
115
+		EEM_Attendee::system_question_fname    => 'ATT_fname',
116
+		EEM_Attendee::system_question_lname    => 'ATT_lname',
117
+		EEM_Attendee::system_question_email    => 'ATT_email',
118
+		EEM_Attendee::system_question_address  => 'ATT_address',
119
+		EEM_Attendee::system_question_address2 => 'ATT_address2',
120
+		EEM_Attendee::system_question_city     => 'ATT_city',
121
+		EEM_Attendee::system_question_state    => 'STA_ID',
122
+		EEM_Attendee::system_question_country  => 'CNT_ISO',
123
+		EEM_Attendee::system_question_zip      => 'ATT_zip',
124
+		EEM_Attendee::system_question_phone    => 'ATT_phone',
125
+	];
126
+
127
+
128
+	/**
129
+	 * @param string|null            $timezone
130
+	 * @param ModelFieldFactory|null $model_field_factory
131
+	 * @throws EE_Error
132
+	 */
133
+	protected function __construct(?string $timezone = '', ModelFieldFactory $model_field_factory = null)
134
+	{
135
+		$this->singular_item           = esc_html__('Attendee', 'event_espresso');
136
+		$this->plural_item             = esc_html__('Attendees', 'event_espresso');
137
+		$this->_tables                 = [
138
+			'Attendee_CPT'  => new EE_Primary_Table('posts', 'ID'),
139
+			'Attendee_Meta' => new EE_Secondary_Table(
140
+				'esp_attendee_meta',
141
+				'ATTM_ID',
142
+				'ATT_ID'
143
+			),
144
+		];
145
+		$this->_fields                 = [
146
+			'Attendee_CPT'  => [
147
+				'ATT_ID'        => $model_field_factory->createPrimaryKeyIntField(
148
+					'ID',
149
+					esc_html__('Attendee ID', 'event_espresso')
150
+				),
151
+				'ATT_full_name' => $model_field_factory->createPlainTextField(
152
+					'post_title',
153
+					esc_html__('Attendee Full Name', 'event_espresso'),
154
+					false,
155
+					esc_html__('Unknown', 'event_espresso')
156
+				),
157
+				'ATT_bio'       => $model_field_factory->createPostContentField(
158
+					'post_content',
159
+					esc_html__('Attendee Biography', 'event_espresso'),
160
+					false,
161
+					esc_html__('No Biography Provided', 'event_espresso')
162
+				),
163
+				'ATT_slug'      => $model_field_factory->createSlugField(
164
+					'post_name',
165
+					esc_html__('Attendee URL Slug', 'event_espresso')
166
+				),
167
+				'ATT_created'   => $model_field_factory->createDatetimeField(
168
+					'post_date',
169
+					esc_html__('Time Attendee Created', 'event_espresso')
170
+				),
171
+				'ATT_short_bio' => $model_field_factory->createSimpleHtmlField(
172
+					'post_excerpt',
173
+					esc_html__('Attendee Short Biography', 'event_espresso'),
174
+					true,
175
+					esc_html__('No Biography Provided', 'event_espresso')
176
+				),
177
+				'ATT_modified'  => $model_field_factory->createDatetimeField(
178
+					'post_modified',
179
+					esc_html__('Time Attendee Last Modified', 'event_espresso')
180
+				),
181
+				'ATT_author'    => $model_field_factory->createWpUserField(
182
+					'post_author',
183
+					esc_html__('Creator ID of the first Event attended', 'event_espresso'),
184
+					false
185
+				),
186
+				'ATT_parent'    => $model_field_factory->createDbOnlyIntField(
187
+					'post_parent',
188
+					esc_html__('Parent Attendee (unused)', 'event_espresso'),
189
+					false,
190
+					0
191
+				),
192
+				'post_type'     => $model_field_factory->createWpPostTypeField(EspressoPostType::ATTENDEES),
193
+				'status'        => $model_field_factory->createWpPostStatusField(
194
+					'post_status',
195
+					esc_html__('Attendee Status', 'event_espresso'),
196
+					false,
197
+					'publish'
198
+				),
199
+				'password'      => new EE_Password_Field(
200
+					'post_password',
201
+					esc_html__('Password', 'event_espresso'),
202
+					false,
203
+					'',
204
+					[
205
+						'ATT_bio',
206
+						'ATT_short_bio',
207
+						'ATT_address',
208
+						'ATT_address2',
209
+						'ATT_city',
210
+						'STA_ID',
211
+						'CNT_ISO',
212
+						'ATT_zip',
213
+						'ATT_email',
214
+						'ATT_phone',
215
+					]
216
+				),
217
+			],
218
+			'Attendee_Meta' => [
219
+				'ATTM_ID'      => $model_field_factory->createDbOnlyIntField(
220
+					'ATTM_ID',
221
+					esc_html__('Attendee Meta Row ID', 'event_espresso'),
222
+					false
223
+				),
224
+				'ATT_ID_fk'    => $model_field_factory->createDbOnlyIntField(
225
+					'ATT_ID',
226
+					esc_html__('Foreign Key to Attendee in Post Table', 'event_espresso'),
227
+					false
228
+				),
229
+				'ATT_fname'    => $model_field_factory->createPlainTextField(
230
+					'ATT_fname',
231
+					esc_html__('First Name', 'event_espresso')
232
+				),
233
+				'ATT_lname'    => $model_field_factory->createPlainTextField(
234
+					'ATT_lname',
235
+					esc_html__('Last Name', 'event_espresso')
236
+				),
237
+				'ATT_address'  => $model_field_factory->createPlainTextField(
238
+					'ATT_address',
239
+					esc_html__('Address Part 1', 'event_espresso')
240
+				),
241
+				'ATT_address2' => $model_field_factory->createPlainTextField(
242
+					'ATT_address2',
243
+					esc_html__('Address Part 2', 'event_espresso')
244
+				),
245
+				'ATT_city'     => $model_field_factory->createPlainTextField(
246
+					'ATT_city',
247
+					esc_html__('City', 'event_espresso')
248
+				),
249
+				'STA_ID'       => $model_field_factory->createForeignKeyIntField(
250
+					'STA_ID',
251
+					esc_html__('State', 'event_espresso'),
252
+					true,
253
+					0,
254
+					'State'
255
+				),
256
+				'CNT_ISO'      => $model_field_factory->createForeignKeyStringField(
257
+					'CNT_ISO',
258
+					esc_html__('Country', 'event_espresso'),
259
+					true,
260
+					'',
261
+					'Country'
262
+				),
263
+				'ATT_zip'      => $model_field_factory->createPlainTextField(
264
+					'ATT_zip',
265
+					esc_html__('ZIP/Postal Code', 'event_espresso')
266
+				),
267
+				'ATT_email'    => $model_field_factory->createEmailField(
268
+					'ATT_email',
269
+					esc_html__('Email Address', 'event_espresso')
270
+				),
271
+				'ATT_phone'    => $model_field_factory->createPlainTextField(
272
+					'ATT_phone',
273
+					esc_html__('Phone', 'event_espresso')
274
+				),
275
+			],
276
+		];
277
+		$this->_model_relations        = [
278
+			'Registration'      => new EE_Has_Many_Relation(),
279
+			'State'             => new EE_Belongs_To_Relation(),
280
+			'Country'           => new EE_Belongs_To_Relation(),
281
+			'Event'             => new EE_HABTM_Relation('Registration', false),
282
+			'WP_User'           => new EE_Belongs_To_Relation(),
283
+			'Message'           => new EE_Has_Many_Any_Relation(false),
284
+			// allow deletion of attendees even if they have messages in the queue for them.
285
+			'Term_Relationship' => new EE_Has_Many_Relation(),
286
+			'Term_Taxonomy'     => new EE_HABTM_Relation('Term_Relationship'),
287
+		];
288
+		$this->_caps_slug              = 'contacts';
289
+		$this->model_chain_to_password = '';
290
+		parent::__construct($timezone);
291
+	}
292
+
293
+
294
+	/**
295
+	 * Gets the name of the field on the attendee model corresponding to the system question string
296
+	 * which should be one of the keys from EEM_Attendee::_system_question_to_attendee_field_name
297
+	 *
298
+	 * @param string $system_question_string
299
+	 * @return string|null if not found
300
+	 */
301
+	public function get_attendee_field_for_system_question($system_question_string)
302
+	{
303
+		return isset($this->_system_question_to_attendee_field_name[ $system_question_string ])
304
+			? $this->_system_question_to_attendee_field_name[ $system_question_string ]
305
+			: null;
306
+	}
307
+
308
+
309
+	/**
310
+	 * Gets mapping from esp_question.QST_system values to their corresponding attendee field names
311
+	 *
312
+	 * @return array
313
+	 */
314
+	public function system_question_to_attendee_field_mapping()
315
+	{
316
+		return $this->_system_question_to_attendee_field_name;
317
+	}
318
+
319
+
320
+	/**
321
+	 * Gets all the attendees for a transaction (by using the esp_registration as a join table)
322
+	 *
323
+	 * @param EE_Transaction /int $transaction_id_or_obj EE_Transaction or its ID
324
+	 * @return EE_Attendee[]|EE_Base_Class[]
325
+	 * @throws EE_Error
326
+	 */
327
+	public function get_attendees_for_transaction($transaction_id_or_obj)
328
+	{
329
+		return $this->get_all(
330
+			[
331
+				[
332
+					'Registration.Transaction.TXN_ID' => $transaction_id_or_obj instanceof EE_Transaction
333
+						? $transaction_id_or_obj->ID()
334
+						: $transaction_id_or_obj,
335
+				],
336
+			]
337
+		);
338
+	}
339
+
340
+
341
+	/**
342
+	 * retrieve  a single attendee from db via their ID
343
+	 *
344
+	 * @param $ATT_ID
345
+	 * @return mixed array on success, FALSE on fail
346
+	 * @deprecated
347
+	 */
348
+	public function get_attendee_by_ID($ATT_ID = false)
349
+	{
350
+		// retrieve a particular EE_Attendee
351
+		return $this->get_one_by_ID($ATT_ID);
352
+	}
353
+
354
+
355
+	/**
356
+	 * retrieve  a single attendee from db via their ID
357
+	 *
358
+	 * @param array $where_cols_n_values
359
+	 * @return mixed array on success, FALSE on fail
360
+	 * @throws EE_Error
361
+	 */
362
+	public function get_attendee($where_cols_n_values = [])
363
+	{
364
+		if (empty($where_cols_n_values)) {
365
+			return false;
366
+		}
367
+		$attendee = $this->get_all([$where_cols_n_values]);
368
+		if (! empty($attendee)) {
369
+			return array_shift($attendee);
370
+		}
371
+		return false;
372
+	}
373
+
374
+
375
+	/**
376
+	 * Search for an existing Attendee record in the DB
377
+	 *
378
+	 * @param array $where_cols_n_values
379
+	 * @return bool|mixed
380
+	 * @throws EE_Error
381
+	 */
382
+	public function find_existing_attendee($where_cols_n_values = null)
383
+	{
384
+		// search by combo of first and last names plus the email address
385
+		$attendee_data_keys = [
386
+			'ATT_fname' => $this->_ATT_fname,
387
+			'ATT_lname' => $this->_ATT_lname,
388
+			'ATT_email' => $this->_ATT_email,
389
+		];
390
+		// no search params means attendee object already exists.
391
+		$where_cols_n_values = is_array($where_cols_n_values) && ! empty($where_cols_n_values)
392
+			? $where_cols_n_values
393
+			: $attendee_data_keys;
394
+		$valid_data          = true;
395
+		// check for required values
396
+		$valid_data = isset($where_cols_n_values['ATT_fname']) && ! empty($where_cols_n_values['ATT_fname'])
397
+			? $valid_data
398
+			: false;
399
+		$valid_data = isset($where_cols_n_values['ATT_lname']) && ! empty($where_cols_n_values['ATT_lname'])
400
+			? $valid_data
401
+			: false;
402
+		$valid_data = isset($where_cols_n_values['ATT_email']) && ! empty($where_cols_n_values['ATT_email'])
403
+			? $valid_data
404
+			: false;
405
+		if ($valid_data) {
406
+			$attendee = $this->get_attendee($where_cols_n_values);
407
+			if ($attendee instanceof EE_Attendee) {
408
+				return $attendee;
409
+			}
410
+		}
411
+		return false;
412
+	}
413
+
414
+
415
+	/**
416
+	 * Takes an incoming array of EE_Registration ids
417
+	 * and sends back a list of corresponding non duplicate EE_Attendee objects.
418
+	 *
419
+	 * @param array $ids array of EE_Registration ids
420
+	 * @return EE_Attendee[]|EE_Base_Class[]
421
+	 * @throws EE_Error
422
+	 * @since  4.3.0
423
+	 */
424
+	public function get_array_of_contacts_from_reg_ids($ids)
425
+	{
426
+		$ids    = (array) $ids;
427
+		$_where = [
428
+			'Registration.REG_ID' => ['in', $ids],
429
+		];
430
+		return $this->get_all([$_where]);
431
+	}
432 432
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Message.model.php 1 patch
Indentation   +661 added lines, -661 removed lines patch added patch discarded remove patch
@@ -12,673 +12,673 @@
 block discarded – undo
12 12
  */
13 13
 class EEM_Message extends EEM_Base implements EEI_Query_Filter
14 14
 {
15
-    protected static ?EEM_Message $_instance = null;
15
+	protected static ?EEM_Message $_instance = null;
16 16
 
17 17
 
18
-    /**
19
-     * This priority indicates a message should be generated and sent ASAP
20
-     *
21
-     * @type int
22
-     */
23
-    const priority_high = 10;
24
-
18
+	/**
19
+	 * This priority indicates a message should be generated and sent ASAP
20
+	 *
21
+	 * @type int
22
+	 */
23
+	const priority_high = 10;
24
+
25 25
 
26
-    /**
27
-     * This priority indicates a message should be generated ASAP and queued for sending.
28
-     *
29
-     * @type
30
-     */
31
-    const priority_medium = 20;
32
-
33
-
34
-    /**
35
-     * This priority indicates a message should be queued for generating.
36
-     *
37
-     * @type int
38
-     */
39
-    const priority_low = 30;
40
-
41
-
42
-    /**
43
-     * indicates this message was sent at the time modified
44
-     */
45
-    const status_sent = 'MSN';
46
-
47
-
48
-    /**
49
-     * indicates this message is waiting to be sent
50
-     */
51
-    const status_idle = 'MID';
52
-
53
-
54
-    /**
55
-     * indicates an attempt was a made to send this message
56
-     * at the scheduled time, but it failed at the time modified.  This differs from MDO status in that it will ALWAYS
57
-     * appear to the end user.
58
-     */
59
-    const status_failed = 'MFL';
60
-
61
-
62
-    /**
63
-     * indicates the message has been flagged for resending (at the time modified).
64
-     */
65
-    const status_resend = 'MRS';
66
-
67
-
68
-    /**
69
-     * indicates the message has been flagged for generation but has not been generated yet.  Messages always start as
70
-     * this status when added to the queue.
71
-     */
72
-    const status_incomplete = 'MIC';
73
-
74
-
75
-    /**
76
-     * Indicates everything was generated fine for the message, however, the messenger was unable to send.
77
-     * This status means that its possible to retry sending the message.
78
-     */
79
-    const status_retry = 'MRT';
80
-
81
-
82
-    /**
83
-     * This is used for more informational messages that may not indicate anything is broken but still cannot be
84
-     * generated or sent correctly. An example of a message that would get flagged this way would be when a not
85
-     * approved message was queued for generation, but at time of generation, the attached registration(s) are
86
-     * approved. So the message queued for generation is no longer valid.  Messages for this status will only persist
87
-     * in the db and be viewable in the message activity list table when the messages system is in debug mode.
88
-     *
89
-     * @see EEM_Message::debug()
90
-     */
91
-    const status_debug_only = 'MDO';
92
-
93
-
94
-    /**
95
-     * This status is given to messages it is processed by the messenger send method.
96
-     * Messages with this status should rarely be seen in the Message List table, but if they are, that's usually
97
-     * indicative of a PHP timeout or memory limit issue.
98
-     */
99
-    const status_messenger_executing = 'MEX';
100
-
101
-
102
-    /**
103
-     * Private constructor to prevent direct creation.
104
-     *
105
-     * @param string|null $timezone string representing the timezone we want to set for returned Date Time Strings (and
106
-     *                              any incoming timezone data that gets saved).  Note this just sends the timezone
107
-     *                              info to the date time model field objects.  Default is null (and will be assumed
108
-     *                              using the set timezone in the 'timezone_string' wp option)
109
-     * @throws EE_Error
110
-     */
111
-    protected function __construct(?string $timezone = '')
112
-    {
113
-        $this->singular_item = esc_html__('Message', 'event_espresso');
114
-        $this->plural_item   = esc_html__('Messages', 'event_espresso');
115
-
116
-        $this->_tables = [
117
-            'Message' => new EE_Primary_Table('esp_message', 'MSG_ID'),
118
-        ];
119
-
120
-        $allowed_priority = [
121
-            self::priority_high   => esc_html__('high', 'event_espresso'),
122
-            self::priority_medium => esc_html__('medium', 'event_espresso'),
123
-            self::priority_low    => esc_html__('low', 'event_espresso'),
124
-        ];
125
-
126
-        $this->_fields          = [
127
-            'Message' => [
128
-                'MSG_ID'             => new EE_Primary_Key_Int_Field(
129
-                    'MSG_ID', esc_html__('Message ID', 'event_espresso')
130
-                ),
131
-                'MSG_token'          => new EE_Plain_Text_Field(
132
-                    'MSG_token',
133
-                    esc_html__(
134
-                        'Unique Token used to represent this row in publicly viewable contexts (eg. a url).',
135
-                        'event_espresso'
136
-                    ),
137
-                    false,
138
-                    EEH_URL::generate_unique_token()
139
-                ),
140
-                'GRP_ID'             => new EE_Foreign_Key_Int_Field(
141
-                    'GRP_ID',
142
-                    esc_html__('Foreign key to the EEM_Message_Template_Group table.', 'event_espresso'),
143
-                    true,
144
-                    0,
145
-                    'Message_Template_Group'
146
-                ),
147
-                'TXN_ID'             => new EE_Foreign_Key_Int_Field(
148
-                    'TXN_ID',
149
-                    esc_html__(
150
-                        'Foreign key to the related EE_Transaction.  This is required to give context for regenerating the specific message',
151
-                        'event_espresso'
152
-                    ),
153
-                    true,
154
-                    0,
155
-                    'Transaction'
156
-                ),
157
-                'MSG_messenger'      => new EE_Plain_Text_Field(
158
-                    'MSG_messenger',
159
-                    esc_html__(
160
-                        'Corresponds to the EE_messenger::name used to send this message. This will also be used to attempt any resending of the message.',
161
-                        'event_espresso'
162
-                    ),
163
-                    false,
164
-                    'email'
165
-                ),
166
-                'MSG_message_type'   => new EE_Plain_Text_Field(
167
-                    'MSG_message_type',
168
-                    esc_html__(
169
-                        'Corresponds to the EE_message_type::name used to generate this message.',
170
-                        'event_espresso'
171
-                    ),
172
-                    false,
173
-                    'receipt'
174
-                ),
175
-                'MSG_context'        => new EE_Plain_Text_Field(
176
-                    'MSG_context',
177
-                    esc_html__('Context', 'event_espresso'),
178
-                    false
179
-                ),
180
-                'MSG_recipient_ID'   => new EE_Foreign_Key_Int_Field(
181
-                    'MSG_recipient_ID',
182
-                    esc_html__('Recipient ID', 'event_espresso'),
183
-                    true,
184
-                    null,
185
-                    ['Registration', 'Attendee', 'WP_User']
186
-                ),
187
-                'MSG_recipient_type' => new EE_Any_Foreign_Model_Name_Field(
188
-                    'MSG_recipient_type',
189
-                    esc_html__('Recipient Type', 'event_espresso'),
190
-                    true,
191
-                    null,
192
-                    ['Registration', 'Attendee', 'WP_User']
193
-                ),
194
-                'MSG_content'        => new EE_Maybe_Serialized_Text_Field(
195
-                    'MSG_content',
196
-                    esc_html__('Content', 'event_espresso'),
197
-                    true,
198
-                    ''
199
-                ),
200
-                'MSG_to'             => new EE_Maybe_Serialized_Text_Field(
201
-                    'MSG_to',
202
-                    esc_html__('Address To', 'event_espresso'),
203
-                    true
204
-                ),
205
-                'MSG_from'           => new EE_Maybe_Serialized_Text_Field(
206
-                    'MSG_from',
207
-                    esc_html__('Address From', 'event_espresso'),
208
-                    true
209
-                ),
210
-                'MSG_subject'        => new EE_Maybe_Serialized_Text_Field(
211
-                    'MSG_subject',
212
-                    esc_html__('Subject', 'event_espresso'),
213
-                    true,
214
-                    ''
215
-                ),
216
-                'MSG_priority'       => new EE_Enum_Integer_Field(
217
-                    'MSG_priority',
218
-                    esc_html__('Priority', 'event_espresso'),
219
-                    false,
220
-                    self::priority_low,
221
-                    $allowed_priority
222
-                ),
223
-                'STS_ID'             => new EE_Foreign_Key_String_Field(
224
-                    'STS_ID',
225
-                    esc_html__('Status', 'event_espresso'),
226
-                    false,
227
-                    self::status_incomplete,
228
-                    'Status'
229
-                ),
230
-                'MSG_created'        => new EE_Datetime_Field(
231
-                    'MSG_created',
232
-                    esc_html__('Created', 'event_espresso'),
233
-                    false,
234
-                    EE_Datetime_Field::now
235
-                ),
236
-                'MSG_modified'       => new EE_Datetime_Field(
237
-                    'MSG_modified',
238
-                    esc_html__('Modified', 'event_espresso'),
239
-                    true,
240
-                    EE_Datetime_Field::now
241
-                ),
242
-            ],
243
-        ];
244
-        $this->_model_relations = [
245
-            'Attendee'               => new EE_Belongs_To_Any_Relation(),
246
-            'Registration'           => new EE_Belongs_To_Any_Relation(),
247
-            'WP_User'                => new EE_Belongs_To_Any_Relation(),
248
-            'Message_Template_Group' => new EE_Belongs_To_Relation(),
249
-            'Transaction'            => new EE_Belongs_To_Relation(),
250
-        ];
251
-        parent::__construct($timezone);
252
-    }
253
-
254
-
255
-    /**
256
-     * @return EE_Message
257
-     * @throws EE_Error
258
-     */
259
-    public function create_default_object()
260
-    {
261
-        /** @type EE_Message $message */
262
-        $message = parent::create_default_object();
263
-        if ($message instanceof EE_Message) {
264
-            return EE_Message_Factory::set_messenger_and_message_type($message);
265
-        }
266
-        return null;
267
-    }
268
-
269
-
270
-    /**
271
-     * @param mixed $cols_n_values
272
-     * @return EE_Message
273
-     * @throws EE_Error
274
-     * @throws EE_Error
275
-     */
276
-    public function instantiate_class_from_array_or_object($cols_n_values)
277
-    {
278
-        /** @type EE_Message $message */
279
-        $message = parent::instantiate_class_from_array_or_object($cols_n_values);
280
-        if ($message instanceof EE_Message) {
281
-            return EE_Message_Factory::set_messenger_and_message_type($message);
282
-        }
283
-        return null;
284
-    }
285
-
286
-
287
-    /**
288
-     * Returns whether or not a message of that type was sent for a given attendee.
289
-     *
290
-     * @param EE_Attendee|int $attendee
291
-     * @param string          $message_type the message type slug
292
-     * @return boolean
293
-     * @throws EE_Error
294
-     * @throws EE_Error
295
-     * @throws EE_Error
296
-     */
297
-    public function message_sent_for_attendee($attendee, $message_type)
298
-    {
299
-        $attendee_ID = EEM_Attendee::instance()->ensure_is_ID($attendee);
300
-        return $this->exists(
301
-            [
302
-                [
303
-                    'Attendee.ATT_ID'  => $attendee_ID,
304
-                    'MSG_message_type' => $message_type,
305
-                    'STS_ID'           => ['IN', $this->stati_indicating_sent()],
306
-                ],
307
-            ]
308
-        );
309
-    }
310
-
311
-
312
-    /**
313
-     * Returns whether or not a message of that type was sent for a given registration
314
-     *
315
-     * @param EE_Registration|int $registration
316
-     * @param string              $message_type the message type slug
317
-     * @return boolean
318
-     * @throws EE_Error
319
-     * @throws EE_Error
320
-     * @throws EE_Error
321
-     */
322
-    public function message_sent_for_registration($registration, $message_type)
323
-    {
324
-        $registrationID = EEM_Registration::instance()->ensure_is_ID($registration);
325
-        return $this->exists(
326
-            [
327
-                [
328
-                    'Registration.REG_ID' => $registrationID,
329
-                    'MSG_message_type'    => $message_type,
330
-                    'STS_ID'              => ['IN', $this->stati_indicating_sent()],
331
-                ],
332
-            ]
333
-        );
334
-    }
335
-
336
-
337
-    /**
338
-     * This retrieves an EE_Message object from the db matching the given token string.
339
-     *
340
-     * @param string $token
341
-     * @return EE_Message
342
-     * @throws EE_Error
343
-     */
344
-    public function get_one_by_token($token)
345
-    {
346
-        return $this->get_one(
347
-            [
348
-                [
349
-                    'MSG_token' => $token,
350
-                ],
351
-            ]
352
-        );
353
-    }
354
-
355
-
356
-    /**
357
-     * Returns stati that indicate the message HAS been sent
358
-     *
359
-     * @return array of strings for possible stati
360
-     */
361
-    public function stati_indicating_sent()
362
-    {
363
-        return apply_filters('FHEE__EEM_Message__stati_indicating_sent', [self::status_sent]);
364
-    }
365
-
366
-
367
-    /**
368
-     * Returns stati that indicate the message is waiting to be sent.
369
-     *
370
-     * @return array of strings for possible stati.
371
-     */
372
-    public function stati_indicating_to_send()
373
-    {
374
-        return apply_filters(
375
-            'FHEE__EEM_Message__stati_indicating_to_send',
376
-            [self::status_idle, self::status_resend]
377
-        );
378
-    }
379
-
380
-
381
-    /**
382
-     * Returns stati that indicate the message has failed sending
383
-     *
384
-     * @return array  array of strings for possible stati.
385
-     */
386
-    public function stati_indicating_failed_sending()
387
-    {
388
-        $failed_stati = [
389
-            self::status_failed,
390
-            self::status_retry,
391
-            self::status_messenger_executing,
392
-        ];
393
-        // if WP_DEBUG is set, then let's include debug_only fails
394
-        if (WP_DEBUG) {
395
-            $failed_stati[] = self::status_debug_only;
396
-        }
397
-        return apply_filters('FHEE__EEM_Message__stati_indicating_failed_sending', $failed_stati);
398
-    }
399
-
400
-
401
-    /**
402
-     * Returns filterable array of all EEM_Message statuses.
403
-     *
404
-     * @return array
405
-     */
406
-    public function all_statuses()
407
-    {
408
-        return apply_filters(
409
-            'FHEE__EEM_Message__all_statuses',
410
-            [
411
-                EEM_Message::status_sent,
412
-                EEM_Message::status_incomplete,
413
-                EEM_Message::status_idle,
414
-                EEM_Message::status_resend,
415
-                EEM_Message::status_retry,
416
-                EEM_Message::status_failed,
417
-                EEM_Message::status_messenger_executing,
418
-                EEM_Message::status_debug_only,
419
-            ]
420
-        );
421
-    }
422
-
423
-
424
-    /**
425
-     * Detects any specific query variables in the request and uses those to setup appropriate
426
-     * filter for any queries.
427
-     *
428
-     * @return array
429
-     */
430
-    public function filter_by_query_params()
431
-    {
432
-        /** @var RequestInterface $request */
433
-        $request = EEM_Base::$loader->getShared(RequestInterface::class);
434
-        // expected possible query_vars, the key in this array matches an expected key in the request,
435
-        // the value, matches the corresponding EEM_Base child reference.
436
-        $expected_vars   = $this->_expected_vars_for_query_inject();
437
-        $query_params[0] = [];
438
-        foreach ($expected_vars as $request_key => $model_name) {
439
-            $request_value = $request->getRequestParam($request_key);
440
-            if ($request_value) {
441
-                // special case
442
-                switch ($request_key) {
443
-                    case '_REG_ID':
444
-                        $query_params[0]['AND**filter_by']['OR**filter_by_REG_ID'] = [
445
-                            'Transaction.Registration.REG_ID' => $request_value,
446
-                        ];
447
-                        break;
448
-                    case 'EVT_ID':
449
-                        $query_params[0]['AND**filter_by']['OR**filter_by_EVT_ID'] = [
450
-                            'Transaction.Registration.EVT_ID' => $request_value,
451
-                        ];
452
-                        break;
453
-                    default:
454
-                        $query_params[0]['AND**filter_by'][ 'OR**filter_by_' . $request_key ][ $model_name . '.' . $request_key ] =
455
-                            $request_value;
456
-                        break;
457
-                }
458
-            }
459
-        }
460
-        return $query_params;
461
-    }
462
-
463
-
464
-    /**
465
-     * @return string
466
-     * @throws EE_Error
467
-     * @throws ReflectionException
468
-     */
469
-    public function get_pretty_label_for_results()
470
-    {
471
-        /** @var RequestInterface $request */
472
-        $request       = EEM_Base::$loader->getShared(RequestInterface::class);
473
-        $expected_vars = $this->_expected_vars_for_query_inject();
474
-        $pretty_label  = '';
475
-        $label_parts   = [];
476
-        foreach ($expected_vars as $request_key => $model_name) {
477
-            $model_name        = strpos($model_name, 'EEM_', true) === 0 ? $model_name : "EEM_{$model_name}";
478
-            $model             = EEM_Base::$loader->getShared($model_name);
479
-            $model_field_value = $request->getRequestParam($request_key);
480
-            if ($model instanceof EEM_Base && $model_field_value !== '') {
481
-                switch ($request_key) {
482
-                    case '_REG_ID':
483
-                        $label_parts[] = sprintf(
484
-                            esc_html__('Registration with the ID: %s', 'event_espresso'),
485
-                            $model_field_value
486
-                        );
487
-                        break;
488
-                    case 'ATT_ID':
489
-                        /** @var EE_Attendee $attendee */
490
-                        $attendee      = $model->get_one_by_ID($model_field_value);
491
-                        $label_parts[] = $attendee instanceof EE_Attendee
492
-                            ? sprintf(esc_html__('Attendee %s', 'event_espresso'), $attendee->full_name())
493
-                            : sprintf(esc_html__('Attendee ID: %s', 'event_espresso'), $model_field_value);
494
-                        break;
495
-                    case 'ID':
496
-                        /** @var EE_WP_User $wpUser */
497
-                        $wpUser        = $model->get_one_by_ID($model_field_value);
498
-                        $label_parts[] = $wpUser instanceof EE_WP_User
499
-                            ? sprintf(esc_html__('WP User: %s', 'event_espresso'), $wpUser->name())
500
-                            : sprintf(esc_html__('WP User ID: %s', 'event_espresso'), $model_field_value);
501
-                        break;
502
-                    case 'TXN_ID':
503
-                        $label_parts[] = sprintf(
504
-                            esc_html__('Transaction with the ID: %s', 'event_espresso'),
505
-                            $model_field_value
506
-                        );
507
-                        break;
508
-                    case 'EVT_ID':
509
-                        /** @var EE_Event $Event */
510
-                        $Event         = $model->get_one_by_ID($model_field_value);
511
-                        $label_parts[] = $Event instanceof EE_Event
512
-                            ? sprintf(esc_html__('for the Event: %s', 'event_espresso'), $Event->name())
513
-                            : sprintf(esc_html__('for the Event with ID: %s', 'event_espresso'), $model_field_value);
514
-                        break;
515
-                }
516
-            }
517
-        }
518
-
519
-        if ($label_parts) {
520
-            // prepend to the last element of $label_parts an "and".
521
-            if (count($label_parts) > 1) {
522
-                $label_parts_index_to_prepend                 = count($label_parts) - 1;
523
-                $label_parts[ $label_parts_index_to_prepend ] = 'and' . $label_parts[ $label_parts_index_to_prepend ];
524
-            }
525
-
526
-            $pretty_label .= sprintf(
527
-                esc_html_x(
528
-                    'Showing messages for %s',
529
-                    'A label for the messages returned in a query that are filtered by items in the query. This could be Transaction, Event, Attendee, Registration, or WP_User.',
530
-                    'event_espresso'
531
-                ),
532
-                implode(', ', $label_parts)
533
-            );
534
-        }
535
-        return $pretty_label;
536
-    }
537
-
538
-
539
-    /**
540
-     * This returns the array of expected variables for the EEI_Query_Filter methods being implemented
541
-     * The array is in the format:
542
-     * array(
543
-     *  {$field_name} => {$model_name}
544
-     * );
545
-     *
546
-     * @return array
547
-     * @since 4.9.0
548
-     */
549
-    protected function _expected_vars_for_query_inject()
550
-    {
551
-        return [
552
-            '_REG_ID' => 'Registration',
553
-            'ATT_ID'  => 'Attendee',
554
-            'ID'      => 'WP_User',
555
-            'TXN_ID'  => 'Transaction',
556
-            'EVT_ID'  => 'Event',
557
-        ];
558
-    }
559
-
560
-
561
-    /**
562
-     * This returns whether EEM_Message is in debug mode or not.
563
-     * Currently "debug mode" is used to control the handling of the EEM_Message::debug_only status when
564
-     * generating/sending messages. Debug mode can be set by either:
565
-     * 1. Sending in a value for the $set_debug argument
566
-     * 2. Defining `EE_DEBUG_MESSAGES` constant in wp-config.php
567
-     * 3. Overriding the above via the provided filter.
568
-     *
569
-     * @param bool|null $set_debug      If provided, then the debug mode will be set internally until reset via the
570
-     *                                  provided boolean. When no argument is provided (default null) then the debug
571
-     *                                  mode will be returned.
572
-     * @return bool         true means Messages is in debug mode.  false means messages system is not in debug mode.
573
-     */
574
-    public static function debug($set_debug = null)
575
-    {
576
-        static $is_debugging = null;
577
-
578
-        // initialize (use constant if set).
579
-        if (is_null($set_debug) && is_null($is_debugging)) {
580
-            $is_debugging = defined('EE_DEBUG_MESSAGES') && EE_DEBUG_MESSAGES;
581
-        }
582
-
583
-        if (! is_null($set_debug)) {
584
-            $is_debugging = filter_var($set_debug, FILTER_VALIDATE_BOOLEAN);
585
-        }
586
-
587
-        // return filtered value
588
-        return apply_filters('FHEE__EEM_Message__debug', $is_debugging);
589
-    }
590
-
591
-
592
-    /**
593
-     * Deletes old messages meeting certain criteria for removal from the database.
594
-     * By default, this will delete messages that:
595
-     * - are older than the value of the delete_threshold in months.
596
-     * - have a STS_ID other than EEM_Message::status_idle
597
-     *
598
-     * @param int $delete_threshold This integer will be used to set the boundary for what messages are deleted in
599
-     *                              months.
600
-     * @return bool|false|int Either the number of records affected or false if there was an error (you can call
601
-     *                              $wpdb->last_error to find out what the error was.
602
-     * @throws EE_Error
603
-     * @throws EE_Error
604
-     * @throws EE_Error
605
-     */
606
-    public function delete_old_messages($delete_threshold = 6)
607
-    {
608
-        $number_deleted = 0;
609
-        /**
610
-         * Allows code to change the boundary for what messages are kept.
611
-         * Uses the value of the `delete_threshold` variable by default.
612
-         *
613
-         * @param int $seconds seconds that will be subtracted from the timestamp for now.
614
-         * @return int
615
-         */
616
-        $time_to_leave_alone = absint(
617
-            apply_filters(
618
-                'FHEE__EEM_Message__delete_old_messages__time_to_leave_alone',
619
-                ((int) $delete_threshold) * MONTH_IN_SECONDS
620
-            )
621
-        );
622
-
623
-
624
-        /**
625
-         * Allows code to change what message stati are ignored when deleting.
626
-         * Defaults to only ignore EEM_Message::status_idle messages.
627
-         *
628
-         * @param string $message_stati_to_keep An array of message statuses that will be ignored when deleting.
629
-         */
630
-        $message_stati_to_keep = (array) apply_filters(
631
-            'FHEE__EEM_Message__delete_old_messages__message_stati_to_keep',
632
-            [
633
-                EEM_Message::status_idle,
634
-            ]
635
-        );
636
-
637
-        // first get all the ids of messages being deleted
638
-        $message_ids_to_delete = EEM_Message::instance()->get_col(
639
-            [
640
-                0       => [
641
-                    'STS_ID'       => ['NOT_IN', $message_stati_to_keep],
642
-                    'MSG_modified' => ['<', time() - $time_to_leave_alone],
643
-                ],
644
-                'limit' => apply_filters(
645
-                    'EEM_Message__delete_old_messages__limit',
646
-                    2000,
647
-                    $delete_threshold
648
-                ),
649
-            ]
650
-        );
651
-
652
-        if (! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) {
653
-            global $wpdb;
654
-            $number_deleted = $wpdb->query(
655
-                '
26
+	/**
27
+	 * This priority indicates a message should be generated ASAP and queued for sending.
28
+	 *
29
+	 * @type
30
+	 */
31
+	const priority_medium = 20;
32
+
33
+
34
+	/**
35
+	 * This priority indicates a message should be queued for generating.
36
+	 *
37
+	 * @type int
38
+	 */
39
+	const priority_low = 30;
40
+
41
+
42
+	/**
43
+	 * indicates this message was sent at the time modified
44
+	 */
45
+	const status_sent = 'MSN';
46
+
47
+
48
+	/**
49
+	 * indicates this message is waiting to be sent
50
+	 */
51
+	const status_idle = 'MID';
52
+
53
+
54
+	/**
55
+	 * indicates an attempt was a made to send this message
56
+	 * at the scheduled time, but it failed at the time modified.  This differs from MDO status in that it will ALWAYS
57
+	 * appear to the end user.
58
+	 */
59
+	const status_failed = 'MFL';
60
+
61
+
62
+	/**
63
+	 * indicates the message has been flagged for resending (at the time modified).
64
+	 */
65
+	const status_resend = 'MRS';
66
+
67
+
68
+	/**
69
+	 * indicates the message has been flagged for generation but has not been generated yet.  Messages always start as
70
+	 * this status when added to the queue.
71
+	 */
72
+	const status_incomplete = 'MIC';
73
+
74
+
75
+	/**
76
+	 * Indicates everything was generated fine for the message, however, the messenger was unable to send.
77
+	 * This status means that its possible to retry sending the message.
78
+	 */
79
+	const status_retry = 'MRT';
80
+
81
+
82
+	/**
83
+	 * This is used for more informational messages that may not indicate anything is broken but still cannot be
84
+	 * generated or sent correctly. An example of a message that would get flagged this way would be when a not
85
+	 * approved message was queued for generation, but at time of generation, the attached registration(s) are
86
+	 * approved. So the message queued for generation is no longer valid.  Messages for this status will only persist
87
+	 * in the db and be viewable in the message activity list table when the messages system is in debug mode.
88
+	 *
89
+	 * @see EEM_Message::debug()
90
+	 */
91
+	const status_debug_only = 'MDO';
92
+
93
+
94
+	/**
95
+	 * This status is given to messages it is processed by the messenger send method.
96
+	 * Messages with this status should rarely be seen in the Message List table, but if they are, that's usually
97
+	 * indicative of a PHP timeout or memory limit issue.
98
+	 */
99
+	const status_messenger_executing = 'MEX';
100
+
101
+
102
+	/**
103
+	 * Private constructor to prevent direct creation.
104
+	 *
105
+	 * @param string|null $timezone string representing the timezone we want to set for returned Date Time Strings (and
106
+	 *                              any incoming timezone data that gets saved).  Note this just sends the timezone
107
+	 *                              info to the date time model field objects.  Default is null (and will be assumed
108
+	 *                              using the set timezone in the 'timezone_string' wp option)
109
+	 * @throws EE_Error
110
+	 */
111
+	protected function __construct(?string $timezone = '')
112
+	{
113
+		$this->singular_item = esc_html__('Message', 'event_espresso');
114
+		$this->plural_item   = esc_html__('Messages', 'event_espresso');
115
+
116
+		$this->_tables = [
117
+			'Message' => new EE_Primary_Table('esp_message', 'MSG_ID'),
118
+		];
119
+
120
+		$allowed_priority = [
121
+			self::priority_high   => esc_html__('high', 'event_espresso'),
122
+			self::priority_medium => esc_html__('medium', 'event_espresso'),
123
+			self::priority_low    => esc_html__('low', 'event_espresso'),
124
+		];
125
+
126
+		$this->_fields          = [
127
+			'Message' => [
128
+				'MSG_ID'             => new EE_Primary_Key_Int_Field(
129
+					'MSG_ID', esc_html__('Message ID', 'event_espresso')
130
+				),
131
+				'MSG_token'          => new EE_Plain_Text_Field(
132
+					'MSG_token',
133
+					esc_html__(
134
+						'Unique Token used to represent this row in publicly viewable contexts (eg. a url).',
135
+						'event_espresso'
136
+					),
137
+					false,
138
+					EEH_URL::generate_unique_token()
139
+				),
140
+				'GRP_ID'             => new EE_Foreign_Key_Int_Field(
141
+					'GRP_ID',
142
+					esc_html__('Foreign key to the EEM_Message_Template_Group table.', 'event_espresso'),
143
+					true,
144
+					0,
145
+					'Message_Template_Group'
146
+				),
147
+				'TXN_ID'             => new EE_Foreign_Key_Int_Field(
148
+					'TXN_ID',
149
+					esc_html__(
150
+						'Foreign key to the related EE_Transaction.  This is required to give context for regenerating the specific message',
151
+						'event_espresso'
152
+					),
153
+					true,
154
+					0,
155
+					'Transaction'
156
+				),
157
+				'MSG_messenger'      => new EE_Plain_Text_Field(
158
+					'MSG_messenger',
159
+					esc_html__(
160
+						'Corresponds to the EE_messenger::name used to send this message. This will also be used to attempt any resending of the message.',
161
+						'event_espresso'
162
+					),
163
+					false,
164
+					'email'
165
+				),
166
+				'MSG_message_type'   => new EE_Plain_Text_Field(
167
+					'MSG_message_type',
168
+					esc_html__(
169
+						'Corresponds to the EE_message_type::name used to generate this message.',
170
+						'event_espresso'
171
+					),
172
+					false,
173
+					'receipt'
174
+				),
175
+				'MSG_context'        => new EE_Plain_Text_Field(
176
+					'MSG_context',
177
+					esc_html__('Context', 'event_espresso'),
178
+					false
179
+				),
180
+				'MSG_recipient_ID'   => new EE_Foreign_Key_Int_Field(
181
+					'MSG_recipient_ID',
182
+					esc_html__('Recipient ID', 'event_espresso'),
183
+					true,
184
+					null,
185
+					['Registration', 'Attendee', 'WP_User']
186
+				),
187
+				'MSG_recipient_type' => new EE_Any_Foreign_Model_Name_Field(
188
+					'MSG_recipient_type',
189
+					esc_html__('Recipient Type', 'event_espresso'),
190
+					true,
191
+					null,
192
+					['Registration', 'Attendee', 'WP_User']
193
+				),
194
+				'MSG_content'        => new EE_Maybe_Serialized_Text_Field(
195
+					'MSG_content',
196
+					esc_html__('Content', 'event_espresso'),
197
+					true,
198
+					''
199
+				),
200
+				'MSG_to'             => new EE_Maybe_Serialized_Text_Field(
201
+					'MSG_to',
202
+					esc_html__('Address To', 'event_espresso'),
203
+					true
204
+				),
205
+				'MSG_from'           => new EE_Maybe_Serialized_Text_Field(
206
+					'MSG_from',
207
+					esc_html__('Address From', 'event_espresso'),
208
+					true
209
+				),
210
+				'MSG_subject'        => new EE_Maybe_Serialized_Text_Field(
211
+					'MSG_subject',
212
+					esc_html__('Subject', 'event_espresso'),
213
+					true,
214
+					''
215
+				),
216
+				'MSG_priority'       => new EE_Enum_Integer_Field(
217
+					'MSG_priority',
218
+					esc_html__('Priority', 'event_espresso'),
219
+					false,
220
+					self::priority_low,
221
+					$allowed_priority
222
+				),
223
+				'STS_ID'             => new EE_Foreign_Key_String_Field(
224
+					'STS_ID',
225
+					esc_html__('Status', 'event_espresso'),
226
+					false,
227
+					self::status_incomplete,
228
+					'Status'
229
+				),
230
+				'MSG_created'        => new EE_Datetime_Field(
231
+					'MSG_created',
232
+					esc_html__('Created', 'event_espresso'),
233
+					false,
234
+					EE_Datetime_Field::now
235
+				),
236
+				'MSG_modified'       => new EE_Datetime_Field(
237
+					'MSG_modified',
238
+					esc_html__('Modified', 'event_espresso'),
239
+					true,
240
+					EE_Datetime_Field::now
241
+				),
242
+			],
243
+		];
244
+		$this->_model_relations = [
245
+			'Attendee'               => new EE_Belongs_To_Any_Relation(),
246
+			'Registration'           => new EE_Belongs_To_Any_Relation(),
247
+			'WP_User'                => new EE_Belongs_To_Any_Relation(),
248
+			'Message_Template_Group' => new EE_Belongs_To_Relation(),
249
+			'Transaction'            => new EE_Belongs_To_Relation(),
250
+		];
251
+		parent::__construct($timezone);
252
+	}
253
+
254
+
255
+	/**
256
+	 * @return EE_Message
257
+	 * @throws EE_Error
258
+	 */
259
+	public function create_default_object()
260
+	{
261
+		/** @type EE_Message $message */
262
+		$message = parent::create_default_object();
263
+		if ($message instanceof EE_Message) {
264
+			return EE_Message_Factory::set_messenger_and_message_type($message);
265
+		}
266
+		return null;
267
+	}
268
+
269
+
270
+	/**
271
+	 * @param mixed $cols_n_values
272
+	 * @return EE_Message
273
+	 * @throws EE_Error
274
+	 * @throws EE_Error
275
+	 */
276
+	public function instantiate_class_from_array_or_object($cols_n_values)
277
+	{
278
+		/** @type EE_Message $message */
279
+		$message = parent::instantiate_class_from_array_or_object($cols_n_values);
280
+		if ($message instanceof EE_Message) {
281
+			return EE_Message_Factory::set_messenger_and_message_type($message);
282
+		}
283
+		return null;
284
+	}
285
+
286
+
287
+	/**
288
+	 * Returns whether or not a message of that type was sent for a given attendee.
289
+	 *
290
+	 * @param EE_Attendee|int $attendee
291
+	 * @param string          $message_type the message type slug
292
+	 * @return boolean
293
+	 * @throws EE_Error
294
+	 * @throws EE_Error
295
+	 * @throws EE_Error
296
+	 */
297
+	public function message_sent_for_attendee($attendee, $message_type)
298
+	{
299
+		$attendee_ID = EEM_Attendee::instance()->ensure_is_ID($attendee);
300
+		return $this->exists(
301
+			[
302
+				[
303
+					'Attendee.ATT_ID'  => $attendee_ID,
304
+					'MSG_message_type' => $message_type,
305
+					'STS_ID'           => ['IN', $this->stati_indicating_sent()],
306
+				],
307
+			]
308
+		);
309
+	}
310
+
311
+
312
+	/**
313
+	 * Returns whether or not a message of that type was sent for a given registration
314
+	 *
315
+	 * @param EE_Registration|int $registration
316
+	 * @param string              $message_type the message type slug
317
+	 * @return boolean
318
+	 * @throws EE_Error
319
+	 * @throws EE_Error
320
+	 * @throws EE_Error
321
+	 */
322
+	public function message_sent_for_registration($registration, $message_type)
323
+	{
324
+		$registrationID = EEM_Registration::instance()->ensure_is_ID($registration);
325
+		return $this->exists(
326
+			[
327
+				[
328
+					'Registration.REG_ID' => $registrationID,
329
+					'MSG_message_type'    => $message_type,
330
+					'STS_ID'              => ['IN', $this->stati_indicating_sent()],
331
+				],
332
+			]
333
+		);
334
+	}
335
+
336
+
337
+	/**
338
+	 * This retrieves an EE_Message object from the db matching the given token string.
339
+	 *
340
+	 * @param string $token
341
+	 * @return EE_Message
342
+	 * @throws EE_Error
343
+	 */
344
+	public function get_one_by_token($token)
345
+	{
346
+		return $this->get_one(
347
+			[
348
+				[
349
+					'MSG_token' => $token,
350
+				],
351
+			]
352
+		);
353
+	}
354
+
355
+
356
+	/**
357
+	 * Returns stati that indicate the message HAS been sent
358
+	 *
359
+	 * @return array of strings for possible stati
360
+	 */
361
+	public function stati_indicating_sent()
362
+	{
363
+		return apply_filters('FHEE__EEM_Message__stati_indicating_sent', [self::status_sent]);
364
+	}
365
+
366
+
367
+	/**
368
+	 * Returns stati that indicate the message is waiting to be sent.
369
+	 *
370
+	 * @return array of strings for possible stati.
371
+	 */
372
+	public function stati_indicating_to_send()
373
+	{
374
+		return apply_filters(
375
+			'FHEE__EEM_Message__stati_indicating_to_send',
376
+			[self::status_idle, self::status_resend]
377
+		);
378
+	}
379
+
380
+
381
+	/**
382
+	 * Returns stati that indicate the message has failed sending
383
+	 *
384
+	 * @return array  array of strings for possible stati.
385
+	 */
386
+	public function stati_indicating_failed_sending()
387
+	{
388
+		$failed_stati = [
389
+			self::status_failed,
390
+			self::status_retry,
391
+			self::status_messenger_executing,
392
+		];
393
+		// if WP_DEBUG is set, then let's include debug_only fails
394
+		if (WP_DEBUG) {
395
+			$failed_stati[] = self::status_debug_only;
396
+		}
397
+		return apply_filters('FHEE__EEM_Message__stati_indicating_failed_sending', $failed_stati);
398
+	}
399
+
400
+
401
+	/**
402
+	 * Returns filterable array of all EEM_Message statuses.
403
+	 *
404
+	 * @return array
405
+	 */
406
+	public function all_statuses()
407
+	{
408
+		return apply_filters(
409
+			'FHEE__EEM_Message__all_statuses',
410
+			[
411
+				EEM_Message::status_sent,
412
+				EEM_Message::status_incomplete,
413
+				EEM_Message::status_idle,
414
+				EEM_Message::status_resend,
415
+				EEM_Message::status_retry,
416
+				EEM_Message::status_failed,
417
+				EEM_Message::status_messenger_executing,
418
+				EEM_Message::status_debug_only,
419
+			]
420
+		);
421
+	}
422
+
423
+
424
+	/**
425
+	 * Detects any specific query variables in the request and uses those to setup appropriate
426
+	 * filter for any queries.
427
+	 *
428
+	 * @return array
429
+	 */
430
+	public function filter_by_query_params()
431
+	{
432
+		/** @var RequestInterface $request */
433
+		$request = EEM_Base::$loader->getShared(RequestInterface::class);
434
+		// expected possible query_vars, the key in this array matches an expected key in the request,
435
+		// the value, matches the corresponding EEM_Base child reference.
436
+		$expected_vars   = $this->_expected_vars_for_query_inject();
437
+		$query_params[0] = [];
438
+		foreach ($expected_vars as $request_key => $model_name) {
439
+			$request_value = $request->getRequestParam($request_key);
440
+			if ($request_value) {
441
+				// special case
442
+				switch ($request_key) {
443
+					case '_REG_ID':
444
+						$query_params[0]['AND**filter_by']['OR**filter_by_REG_ID'] = [
445
+							'Transaction.Registration.REG_ID' => $request_value,
446
+						];
447
+						break;
448
+					case 'EVT_ID':
449
+						$query_params[0]['AND**filter_by']['OR**filter_by_EVT_ID'] = [
450
+							'Transaction.Registration.EVT_ID' => $request_value,
451
+						];
452
+						break;
453
+					default:
454
+						$query_params[0]['AND**filter_by'][ 'OR**filter_by_' . $request_key ][ $model_name . '.' . $request_key ] =
455
+							$request_value;
456
+						break;
457
+				}
458
+			}
459
+		}
460
+		return $query_params;
461
+	}
462
+
463
+
464
+	/**
465
+	 * @return string
466
+	 * @throws EE_Error
467
+	 * @throws ReflectionException
468
+	 */
469
+	public function get_pretty_label_for_results()
470
+	{
471
+		/** @var RequestInterface $request */
472
+		$request       = EEM_Base::$loader->getShared(RequestInterface::class);
473
+		$expected_vars = $this->_expected_vars_for_query_inject();
474
+		$pretty_label  = '';
475
+		$label_parts   = [];
476
+		foreach ($expected_vars as $request_key => $model_name) {
477
+			$model_name        = strpos($model_name, 'EEM_', true) === 0 ? $model_name : "EEM_{$model_name}";
478
+			$model             = EEM_Base::$loader->getShared($model_name);
479
+			$model_field_value = $request->getRequestParam($request_key);
480
+			if ($model instanceof EEM_Base && $model_field_value !== '') {
481
+				switch ($request_key) {
482
+					case '_REG_ID':
483
+						$label_parts[] = sprintf(
484
+							esc_html__('Registration with the ID: %s', 'event_espresso'),
485
+							$model_field_value
486
+						);
487
+						break;
488
+					case 'ATT_ID':
489
+						/** @var EE_Attendee $attendee */
490
+						$attendee      = $model->get_one_by_ID($model_field_value);
491
+						$label_parts[] = $attendee instanceof EE_Attendee
492
+							? sprintf(esc_html__('Attendee %s', 'event_espresso'), $attendee->full_name())
493
+							: sprintf(esc_html__('Attendee ID: %s', 'event_espresso'), $model_field_value);
494
+						break;
495
+					case 'ID':
496
+						/** @var EE_WP_User $wpUser */
497
+						$wpUser        = $model->get_one_by_ID($model_field_value);
498
+						$label_parts[] = $wpUser instanceof EE_WP_User
499
+							? sprintf(esc_html__('WP User: %s', 'event_espresso'), $wpUser->name())
500
+							: sprintf(esc_html__('WP User ID: %s', 'event_espresso'), $model_field_value);
501
+						break;
502
+					case 'TXN_ID':
503
+						$label_parts[] = sprintf(
504
+							esc_html__('Transaction with the ID: %s', 'event_espresso'),
505
+							$model_field_value
506
+						);
507
+						break;
508
+					case 'EVT_ID':
509
+						/** @var EE_Event $Event */
510
+						$Event         = $model->get_one_by_ID($model_field_value);
511
+						$label_parts[] = $Event instanceof EE_Event
512
+							? sprintf(esc_html__('for the Event: %s', 'event_espresso'), $Event->name())
513
+							: sprintf(esc_html__('for the Event with ID: %s', 'event_espresso'), $model_field_value);
514
+						break;
515
+				}
516
+			}
517
+		}
518
+
519
+		if ($label_parts) {
520
+			// prepend to the last element of $label_parts an "and".
521
+			if (count($label_parts) > 1) {
522
+				$label_parts_index_to_prepend                 = count($label_parts) - 1;
523
+				$label_parts[ $label_parts_index_to_prepend ] = 'and' . $label_parts[ $label_parts_index_to_prepend ];
524
+			}
525
+
526
+			$pretty_label .= sprintf(
527
+				esc_html_x(
528
+					'Showing messages for %s',
529
+					'A label for the messages returned in a query that are filtered by items in the query. This could be Transaction, Event, Attendee, Registration, or WP_User.',
530
+					'event_espresso'
531
+				),
532
+				implode(', ', $label_parts)
533
+			);
534
+		}
535
+		return $pretty_label;
536
+	}
537
+
538
+
539
+	/**
540
+	 * This returns the array of expected variables for the EEI_Query_Filter methods being implemented
541
+	 * The array is in the format:
542
+	 * array(
543
+	 *  {$field_name} => {$model_name}
544
+	 * );
545
+	 *
546
+	 * @return array
547
+	 * @since 4.9.0
548
+	 */
549
+	protected function _expected_vars_for_query_inject()
550
+	{
551
+		return [
552
+			'_REG_ID' => 'Registration',
553
+			'ATT_ID'  => 'Attendee',
554
+			'ID'      => 'WP_User',
555
+			'TXN_ID'  => 'Transaction',
556
+			'EVT_ID'  => 'Event',
557
+		];
558
+	}
559
+
560
+
561
+	/**
562
+	 * This returns whether EEM_Message is in debug mode or not.
563
+	 * Currently "debug mode" is used to control the handling of the EEM_Message::debug_only status when
564
+	 * generating/sending messages. Debug mode can be set by either:
565
+	 * 1. Sending in a value for the $set_debug argument
566
+	 * 2. Defining `EE_DEBUG_MESSAGES` constant in wp-config.php
567
+	 * 3. Overriding the above via the provided filter.
568
+	 *
569
+	 * @param bool|null $set_debug      If provided, then the debug mode will be set internally until reset via the
570
+	 *                                  provided boolean. When no argument is provided (default null) then the debug
571
+	 *                                  mode will be returned.
572
+	 * @return bool         true means Messages is in debug mode.  false means messages system is not in debug mode.
573
+	 */
574
+	public static function debug($set_debug = null)
575
+	{
576
+		static $is_debugging = null;
577
+
578
+		// initialize (use constant if set).
579
+		if (is_null($set_debug) && is_null($is_debugging)) {
580
+			$is_debugging = defined('EE_DEBUG_MESSAGES') && EE_DEBUG_MESSAGES;
581
+		}
582
+
583
+		if (! is_null($set_debug)) {
584
+			$is_debugging = filter_var($set_debug, FILTER_VALIDATE_BOOLEAN);
585
+		}
586
+
587
+		// return filtered value
588
+		return apply_filters('FHEE__EEM_Message__debug', $is_debugging);
589
+	}
590
+
591
+
592
+	/**
593
+	 * Deletes old messages meeting certain criteria for removal from the database.
594
+	 * By default, this will delete messages that:
595
+	 * - are older than the value of the delete_threshold in months.
596
+	 * - have a STS_ID other than EEM_Message::status_idle
597
+	 *
598
+	 * @param int $delete_threshold This integer will be used to set the boundary for what messages are deleted in
599
+	 *                              months.
600
+	 * @return bool|false|int Either the number of records affected or false if there was an error (you can call
601
+	 *                              $wpdb->last_error to find out what the error was.
602
+	 * @throws EE_Error
603
+	 * @throws EE_Error
604
+	 * @throws EE_Error
605
+	 */
606
+	public function delete_old_messages($delete_threshold = 6)
607
+	{
608
+		$number_deleted = 0;
609
+		/**
610
+		 * Allows code to change the boundary for what messages are kept.
611
+		 * Uses the value of the `delete_threshold` variable by default.
612
+		 *
613
+		 * @param int $seconds seconds that will be subtracted from the timestamp for now.
614
+		 * @return int
615
+		 */
616
+		$time_to_leave_alone = absint(
617
+			apply_filters(
618
+				'FHEE__EEM_Message__delete_old_messages__time_to_leave_alone',
619
+				((int) $delete_threshold) * MONTH_IN_SECONDS
620
+			)
621
+		);
622
+
623
+
624
+		/**
625
+		 * Allows code to change what message stati are ignored when deleting.
626
+		 * Defaults to only ignore EEM_Message::status_idle messages.
627
+		 *
628
+		 * @param string $message_stati_to_keep An array of message statuses that will be ignored when deleting.
629
+		 */
630
+		$message_stati_to_keep = (array) apply_filters(
631
+			'FHEE__EEM_Message__delete_old_messages__message_stati_to_keep',
632
+			[
633
+				EEM_Message::status_idle,
634
+			]
635
+		);
636
+
637
+		// first get all the ids of messages being deleted
638
+		$message_ids_to_delete = EEM_Message::instance()->get_col(
639
+			[
640
+				0       => [
641
+					'STS_ID'       => ['NOT_IN', $message_stati_to_keep],
642
+					'MSG_modified' => ['<', time() - $time_to_leave_alone],
643
+				],
644
+				'limit' => apply_filters(
645
+					'EEM_Message__delete_old_messages__limit',
646
+					2000,
647
+					$delete_threshold
648
+				),
649
+			]
650
+		);
651
+
652
+		if (! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) {
653
+			global $wpdb;
654
+			$number_deleted = $wpdb->query(
655
+				'
656 656
                 DELETE
657 657
                 FROM ' . $this->table() . '
658 658
                 WHERE
659 659
                     MSG_ID IN (' . implode(",", $message_ids_to_delete) . ')
660 660
             '
661
-            );
662
-        }
663
-
664
-        /**
665
-         * This will get called if the number of records deleted 0 or greater.  So a successful deletion is one where
666
-         * there were no errors.  An unsuccessful deletion is where there were errors.  Keep that in mind for the actions
667
-         * below.
668
-         */
669
-        if ($number_deleted !== false) {
670
-            do_action(
671
-                'AHEE__EEM_Message__delete_old_messages__after_successful_deletion',
672
-                $message_ids_to_delete,
673
-                $number_deleted
674
-            );
675
-        } else {
676
-            do_action(
677
-                'AHEE__EEM_Message__delete_old_messages__after_deletion_fail',
678
-                $message_ids_to_delete,
679
-                $number_deleted
680
-            );
681
-        }
682
-        return $number_deleted;
683
-    }
661
+			);
662
+		}
663
+
664
+		/**
665
+		 * This will get called if the number of records deleted 0 or greater.  So a successful deletion is one where
666
+		 * there were no errors.  An unsuccessful deletion is where there were errors.  Keep that in mind for the actions
667
+		 * below.
668
+		 */
669
+		if ($number_deleted !== false) {
670
+			do_action(
671
+				'AHEE__EEM_Message__delete_old_messages__after_successful_deletion',
672
+				$message_ids_to_delete,
673
+				$number_deleted
674
+			);
675
+		} else {
676
+			do_action(
677
+				'AHEE__EEM_Message__delete_old_messages__after_deletion_fail',
678
+				$message_ids_to_delete,
679
+				$number_deleted
680
+			);
681
+		}
682
+		return $number_deleted;
683
+	}
684 684
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Form_Submission.model.php 1 patch
Indentation   +108 added lines, -108 removed lines patch added patch discarded remove patch
@@ -11,124 +11,124 @@
 block discarded – undo
11 11
  */
12 12
 class EEM_Form_Submission extends EEM_Base
13 13
 {
14
-    protected static ?EEM_Form_Submission $_instance = null;
14
+	protected static ?EEM_Form_Submission $_instance = null;
15 15
 
16
-    private RequestInterface $request;
16
+	private RequestInterface $request;
17 17
 
18 18
 
19
-    /**
20
-     * EEM_Form_Submission constructor.
21
-     *
22
-     * @param string|null $timezone
23
-     * @throws EE_Error
24
-     */
25
-    protected function __construct(?string $timezone = '')
26
-    {
27
-        $this->singular_item = esc_html__('Form Submission', 'event_espresso');
28
-        $this->plural_item   = esc_html__('Form Submissions', 'event_espresso');
19
+	/**
20
+	 * EEM_Form_Submission constructor.
21
+	 *
22
+	 * @param string|null $timezone
23
+	 * @throws EE_Error
24
+	 */
25
+	protected function __construct(?string $timezone = '')
26
+	{
27
+		$this->singular_item = esc_html__('Form Submission', 'event_espresso');
28
+		$this->plural_item   = esc_html__('Form Submissions', 'event_espresso');
29 29
 
30
-        $this->_tables          = [
31
-            'Form_Submission' => new EE_Primary_Table('esp_form_submission', 'FSB_UUID'),
32
-        ];
33
-        $this->_fields          = [
34
-            'Form_Submission' => [
35
-                'FSB_UUID'      => new EE_Primary_Key_String_Field(
36
-                    'FSB_UUID',
37
-                    esc_html__('Form Submission UUID (universally unique identifier)', 'event_espresso')
38
-                ),
39
-                'FSC_UUID'      => new EE_Foreign_Key_String_Field(
40
-                    'FSC_UUID',
41
-                    esc_html__('Form Section UUID (universally unique identifier)', 'event_espresso'),
42
-                    false,
43
-                    '',
44
-                    'Form_Section',
45
-                    false
46
-                ),
47
-                'TXN_ID'        => new EE_Foreign_Key_Int_Field(
48
-                    'TXN_ID',
49
-                    esc_html__('Transaction ID', 'event_espresso'),
50
-                    false,
51
-                    0,
52
-                    'Transaction'
53
-                ),
54
-                'FSB_data'      => new EE_JSON_Field(
55
-                    'FSB_data',
56
-                    esc_html__('Serialized form submission data', 'event_espresso'),
57
-                    true,
58
-                    null
59
-                ),
60
-                'FSB_submitted' => new EE_Datetime_Field(
61
-                    'FSB_submitted',
62
-                    esc_html__('Form submission timestamp', 'event_espresso'),
63
-                    false,
64
-                    EE_Datetime_Field::now,
65
-                    $timezone
66
-                ),
67
-            ],
68
-        ];
69
-        $this->_model_relations = [
70
-            'Form_Section' => new EE_Belongs_To_Relation(),
71
-            'Transaction'  => new EE_Belongs_To_Relation(),
72
-        ];
73
-        parent::__construct($timezone);
74
-        $this->request = $this->getLoader()->getShared('EventEspresso\core\services\request\RequestInterface');
75
-    }
30
+		$this->_tables          = [
31
+			'Form_Submission' => new EE_Primary_Table('esp_form_submission', 'FSB_UUID'),
32
+		];
33
+		$this->_fields          = [
34
+			'Form_Submission' => [
35
+				'FSB_UUID'      => new EE_Primary_Key_String_Field(
36
+					'FSB_UUID',
37
+					esc_html__('Form Submission UUID (universally unique identifier)', 'event_espresso')
38
+				),
39
+				'FSC_UUID'      => new EE_Foreign_Key_String_Field(
40
+					'FSC_UUID',
41
+					esc_html__('Form Section UUID (universally unique identifier)', 'event_espresso'),
42
+					false,
43
+					'',
44
+					'Form_Section',
45
+					false
46
+				),
47
+				'TXN_ID'        => new EE_Foreign_Key_Int_Field(
48
+					'TXN_ID',
49
+					esc_html__('Transaction ID', 'event_espresso'),
50
+					false,
51
+					0,
52
+					'Transaction'
53
+				),
54
+				'FSB_data'      => new EE_JSON_Field(
55
+					'FSB_data',
56
+					esc_html__('Serialized form submission data', 'event_espresso'),
57
+					true,
58
+					null
59
+				),
60
+				'FSB_submitted' => new EE_Datetime_Field(
61
+					'FSB_submitted',
62
+					esc_html__('Form submission timestamp', 'event_espresso'),
63
+					false,
64
+					EE_Datetime_Field::now,
65
+					$timezone
66
+				),
67
+			],
68
+		];
69
+		$this->_model_relations = [
70
+			'Form_Section' => new EE_Belongs_To_Relation(),
71
+			'Transaction'  => new EE_Belongs_To_Relation(),
72
+		];
73
+		parent::__construct($timezone);
74
+		$this->request = $this->getLoader()->getShared('EventEspresso\core\services\request\RequestInterface');
75
+	}
76 76
 
77 77
 
78
-    /**
79
-     * adds all default where conditions unless the current request originates from the admin
80
-     *
81
-     * @param array $query_params
82
-     * @return array
83
-     */
84
-    private function addDefaultWhereConditions(array $query_params): array
85
-    {
86
-        // might need to add a way to identify GQL requests for admin domains
87
-        $query_params['default_where_conditions'] = $this->request->isAdmin() || $this->request->isAdminAjax()
88
-            ? EEM_Base::default_where_conditions_none
89
-            : EEM_Base::default_where_conditions_all;
90
-        return $query_params;
91
-    }
78
+	/**
79
+	 * adds all default where conditions unless the current request originates from the admin
80
+	 *
81
+	 * @param array $query_params
82
+	 * @return array
83
+	 */
84
+	private function addDefaultWhereConditions(array $query_params): array
85
+	{
86
+		// might need to add a way to identify GQL requests for admin domains
87
+		$query_params['default_where_conditions'] = $this->request->isAdmin() || $this->request->isAdminAjax()
88
+			? EEM_Base::default_where_conditions_none
89
+			: EEM_Base::default_where_conditions_all;
90
+		return $query_params;
91
+	}
92 92
 
93 93
 
94
-    /**
95
-     * form sections should always be sorted in ascending order via the FSC_order field
96
-     *
97
-     * @param array $query_params
98
-     * @return array
99
-     */
100
-    private function addOrderByQueryParams(array $query_params): array
101
-    {
102
-        $query_params['order_by'] = ['FSB_submitted' => 'ASC'];
103
-        return $query_params;
104
-    }
94
+	/**
95
+	 * form sections should always be sorted in ascending order via the FSC_order field
96
+	 *
97
+	 * @param array $query_params
98
+	 * @return array
99
+	 */
100
+	private function addOrderByQueryParams(array $query_params): array
101
+	{
102
+		$query_params['order_by'] = ['FSB_submitted' => 'ASC'];
103
+		return $query_params;
104
+	}
105 105
 
106 106
 
107
-    /**
108
-     * @param EE_Event $event
109
-     * @return EE_Form_Submission[]|null
110
-     * @throws EE_Error
111
-     * @throws ReflectionException
112
-     */
113
-    public function getAllFormSubmissionsForEvent(EE_Event $event): ?array
114
-    {
115
-        $query_params = [['FSC_UUID' => $event->registrationFormUuid()]];
116
-        $query_params = $this->addDefaultWhereConditions($query_params);
117
-        $query_params = $this->addOrderByQueryParams($query_params);
118
-        return $this->get_all($query_params);
119
-    }
107
+	/**
108
+	 * @param EE_Event $event
109
+	 * @return EE_Form_Submission[]|null
110
+	 * @throws EE_Error
111
+	 * @throws ReflectionException
112
+	 */
113
+	public function getAllFormSubmissionsForEvent(EE_Event $event): ?array
114
+	{
115
+		$query_params = [['FSC_UUID' => $event->registrationFormUuid()]];
116
+		$query_params = $this->addDefaultWhereConditions($query_params);
117
+		$query_params = $this->addOrderByQueryParams($query_params);
118
+		return $this->get_all($query_params);
119
+	}
120 120
 
121 121
 
122
-    /**
123
-     * @param EE_Transaction $transaction
124
-     * @return EE_Form_Submission|null
125
-     * @throws EE_Error
126
-     * @throws ReflectionException
127
-     */
128
-    public function getFormSubmissionForTransaction(EE_Transaction $transaction): ?EE_Form_Submission
129
-    {
130
-        $query_params = [['TXN_ID' => $transaction->ID()]];
131
-        $query_params = $this->addDefaultWhereConditions($query_params);
132
-        return $this->get_one($query_params);
133
-    }
122
+	/**
123
+	 * @param EE_Transaction $transaction
124
+	 * @return EE_Form_Submission|null
125
+	 * @throws EE_Error
126
+	 * @throws ReflectionException
127
+	 */
128
+	public function getFormSubmissionForTransaction(EE_Transaction $transaction): ?EE_Form_Submission
129
+	{
130
+		$query_params = [['TXN_ID' => $transaction->ID()]];
131
+		$query_params = $this->addDefaultWhereConditions($query_params);
132
+		return $this->get_one($query_params);
133
+	}
134 134
 }
Please login to merge, or discard this patch.
core/db_models/EEM_State.model.php 2 patches
Indentation   +210 added lines, -210 removed lines patch added patch discarded remove patch
@@ -9,214 +9,214 @@
 block discarded – undo
9 9
  */
10 10
 class EEM_State extends EEM_Base
11 11
 {
12
-    protected static ?EEM_State $_instance = null;
13
-
14
-    // array of all states
15
-    private static ?array $_all_states = null;
16
-
17
-    // array of all active states
18
-    private static ?array $_active_states = null;
19
-
20
-
21
-    /**
22
-     * @param string|null $timezone
23
-     * @throws EE_Error
24
-     */
25
-    protected function __construct(?string $timezone = '')
26
-    {
27
-        $this->singular_item = esc_html__('State/Province', 'event_espresso');
28
-        $this->plural_item   = esc_html__('States/Provinces', 'event_espresso');
29
-
30
-        $this->_tables = [
31
-            'State' => new EE_Primary_Table('esp_state', 'STA_ID'),
32
-        ];
33
-
34
-        $this->_fields          = [
35
-            'State' => [
36
-                'STA_ID'     => new EE_Primary_Key_Int_Field('STA_ID', esc_html__('State ID', 'event_espresso')),
37
-                'CNT_ISO'    => new EE_Foreign_Key_String_Field(
38
-                    'CNT_ISO',
39
-                    esc_html__('Country ISO Code', 'event_espresso'),
40
-                    false,
41
-                    null,
42
-                    'Country'
43
-                ),
44
-                'STA_abbrev' => new EE_Plain_Text_Field(
45
-                    'STA_abbrev',
46
-                    esc_html__('State Abbreviation', 'event_espresso'),
47
-                    false,
48
-                    ''
49
-                ),
50
-                'STA_name'   => new EE_Plain_Text_Field(
51
-                    'STA_name',
52
-                    esc_html__('State Name', 'event_espresso'),
53
-                    false,
54
-                    ''
55
-                ),
56
-                'STA_active' => new EE_Boolean_Field(
57
-                    'STA_active',
58
-                    esc_html__('State Active Flag', 'event_espresso'),
59
-                    false,
60
-                    false
61
-                ),
62
-            ],
63
-        ];
64
-        $this->_model_relations = [
65
-            'Attendee' => new EE_Has_Many_Relation(),
66
-            'Country'  => new EE_Belongs_To_Relation(),
67
-            'Venue'    => new EE_Has_Many_Relation(),
68
-        ];
69
-        // this model is generally available for reading
70
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
71
-        // @todo: only show STA_active
72
-        parent::__construct($timezone);
73
-    }
74
-
75
-
76
-    /**
77
-     *   reset_cached_states
78
-     *
79
-     * @access     private
80
-     * @return         void
81
-     */
82
-    public function reset_cached_states()
83
-    {
84
-        EEM_State::$_active_states = [];
85
-        EEM_State::$_all_states    = [];
86
-    }
87
-
88
-
89
-    /**
90
-     *       _get_states
91
-     *
92
-     * @access     private
93
-     * @return         array
94
-     */
95
-    public function get_all_states()
96
-    {
97
-        if (! self::$_all_states) {
98
-            self::$_all_states = $this->get_all(['order_by' => ['STA_name' => 'ASC'], 'limit' => [0, 99999]]);
99
-        }
100
-        return self::$_all_states;
101
-    }
102
-
103
-
104
-    /**
105
-     *        _get_states
106
-     *
107
-     * @access        public
108
-     * @param array $countries
109
-     * @param bool  $flush_cache
110
-     * @return        array
111
-     */
112
-    public function get_all_active_states($countries = [], $flush_cache = false)
113
-    {
114
-        if (! self::$_active_states || $flush_cache) {
115
-            $countries            = is_array($countries) && ! empty($countries)
116
-                ? $countries
117
-                : EEM_Country::instance()
118
-                             ->get_all_active_countries();
119
-            self::$_active_states = $this->get_all(
120
-                [
121
-                    ['STA_active' => true, 'CNT_ISO' => ['IN', array_keys($countries)]],
122
-                    'order_by'   => ['STA_name' => 'ASC'],
123
-                    'limit'      => [0, 99999],
124
-                    'force_join' => ['Country'],
125
-                ]
126
-            );
127
-        }
128
-        return self::$_active_states;
129
-    }
130
-
131
-
132
-    /**
133
-     *  get_all_states_of_active_countries
134
-     *
135
-     * @return array
136
-     */
137
-    public function get_all_states_of_active_countries()
138
-    {
139
-        if (
140
-            $states = $this->get_all(
141
-                [
142
-                    ['Country.CNT_active' => true, 'STA_active' => true],
143
-                    'order_by' => ['Country.CNT_name' => 'ASC', 'STA_name' => 'ASC'],
144
-                ]
145
-            )
146
-        ) {
147
-            return $states;
148
-        }
149
-        return false;
150
-    }
151
-
152
-
153
-    /**
154
-     *  get_all_states_of_active_countries
155
-     *
156
-     * @return array
157
-     */
158
-    public function get_all_active_states_for_these_countries($countries)
159
-    {
160
-        if (! $countries) {
161
-            return false;
162
-        }
163
-        if (
164
-            $states = $this->get_all(
165
-                [
166
-                    ['Country.CNT_ISO' => ['IN', array_keys($countries)], 'STA_active' => true],
167
-                    'order_by' => ['Country.CNT_name' => 'ASC', 'STA_name' => 'ASC'],
168
-                ]
169
-            )
170
-        ) {
171
-            return $states;
172
-        }
173
-        return false;
174
-    }
175
-
176
-
177
-    /**
178
-     *  get_all_states_of_active_countries
179
-     *
180
-     * @return array
181
-     */
182
-    public function get_all_states_for_these_countries($countries)
183
-    {
184
-        if (! $countries) {
185
-            return false;
186
-        }
187
-        if (
188
-            $states = $this->get_all(
189
-                [
190
-                    ['Country.CNT_ISO' => ['IN', array_keys($countries)]],
191
-                    'order_by' => ['Country.CNT_name' => 'ASC', 'STA_name' => 'ASC'],
192
-                ]
193
-            )
194
-        ) {
195
-            return $states;
196
-        }
197
-        return false;
198
-    }
199
-
200
-
201
-    /**
202
-     * Gets the state's name by its ID
203
-     *
204
-     * @param string $state_ID
205
-     * @return string
206
-     */
207
-    public function get_state_name_by_ID($state_ID)
208
-    {
209
-        if (
210
-            isset(self::$_all_states[ $state_ID ]) &&
211
-            self::$_all_states[ $state_ID ] instanceof EE_State
212
-        ) {
213
-            return self::$_all_states[ $state_ID ]->name();
214
-        }
215
-        $names = $this->get_col([['STA_ID' => $state_ID], 'limit' => 1], 'STA_name');
216
-        if (is_array($names) && ! empty($names)) {
217
-            return reset($names);
218
-        } else {
219
-            return '';
220
-        }
221
-    }
12
+	protected static ?EEM_State $_instance = null;
13
+
14
+	// array of all states
15
+	private static ?array $_all_states = null;
16
+
17
+	// array of all active states
18
+	private static ?array $_active_states = null;
19
+
20
+
21
+	/**
22
+	 * @param string|null $timezone
23
+	 * @throws EE_Error
24
+	 */
25
+	protected function __construct(?string $timezone = '')
26
+	{
27
+		$this->singular_item = esc_html__('State/Province', 'event_espresso');
28
+		$this->plural_item   = esc_html__('States/Provinces', 'event_espresso');
29
+
30
+		$this->_tables = [
31
+			'State' => new EE_Primary_Table('esp_state', 'STA_ID'),
32
+		];
33
+
34
+		$this->_fields          = [
35
+			'State' => [
36
+				'STA_ID'     => new EE_Primary_Key_Int_Field('STA_ID', esc_html__('State ID', 'event_espresso')),
37
+				'CNT_ISO'    => new EE_Foreign_Key_String_Field(
38
+					'CNT_ISO',
39
+					esc_html__('Country ISO Code', 'event_espresso'),
40
+					false,
41
+					null,
42
+					'Country'
43
+				),
44
+				'STA_abbrev' => new EE_Plain_Text_Field(
45
+					'STA_abbrev',
46
+					esc_html__('State Abbreviation', 'event_espresso'),
47
+					false,
48
+					''
49
+				),
50
+				'STA_name'   => new EE_Plain_Text_Field(
51
+					'STA_name',
52
+					esc_html__('State Name', 'event_espresso'),
53
+					false,
54
+					''
55
+				),
56
+				'STA_active' => new EE_Boolean_Field(
57
+					'STA_active',
58
+					esc_html__('State Active Flag', 'event_espresso'),
59
+					false,
60
+					false
61
+				),
62
+			],
63
+		];
64
+		$this->_model_relations = [
65
+			'Attendee' => new EE_Has_Many_Relation(),
66
+			'Country'  => new EE_Belongs_To_Relation(),
67
+			'Venue'    => new EE_Has_Many_Relation(),
68
+		];
69
+		// this model is generally available for reading
70
+		$this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
71
+		// @todo: only show STA_active
72
+		parent::__construct($timezone);
73
+	}
74
+
75
+
76
+	/**
77
+	 *   reset_cached_states
78
+	 *
79
+	 * @access     private
80
+	 * @return         void
81
+	 */
82
+	public function reset_cached_states()
83
+	{
84
+		EEM_State::$_active_states = [];
85
+		EEM_State::$_all_states    = [];
86
+	}
87
+
88
+
89
+	/**
90
+	 *       _get_states
91
+	 *
92
+	 * @access     private
93
+	 * @return         array
94
+	 */
95
+	public function get_all_states()
96
+	{
97
+		if (! self::$_all_states) {
98
+			self::$_all_states = $this->get_all(['order_by' => ['STA_name' => 'ASC'], 'limit' => [0, 99999]]);
99
+		}
100
+		return self::$_all_states;
101
+	}
102
+
103
+
104
+	/**
105
+	 *        _get_states
106
+	 *
107
+	 * @access        public
108
+	 * @param array $countries
109
+	 * @param bool  $flush_cache
110
+	 * @return        array
111
+	 */
112
+	public function get_all_active_states($countries = [], $flush_cache = false)
113
+	{
114
+		if (! self::$_active_states || $flush_cache) {
115
+			$countries            = is_array($countries) && ! empty($countries)
116
+				? $countries
117
+				: EEM_Country::instance()
118
+							 ->get_all_active_countries();
119
+			self::$_active_states = $this->get_all(
120
+				[
121
+					['STA_active' => true, 'CNT_ISO' => ['IN', array_keys($countries)]],
122
+					'order_by'   => ['STA_name' => 'ASC'],
123
+					'limit'      => [0, 99999],
124
+					'force_join' => ['Country'],
125
+				]
126
+			);
127
+		}
128
+		return self::$_active_states;
129
+	}
130
+
131
+
132
+	/**
133
+	 *  get_all_states_of_active_countries
134
+	 *
135
+	 * @return array
136
+	 */
137
+	public function get_all_states_of_active_countries()
138
+	{
139
+		if (
140
+			$states = $this->get_all(
141
+				[
142
+					['Country.CNT_active' => true, 'STA_active' => true],
143
+					'order_by' => ['Country.CNT_name' => 'ASC', 'STA_name' => 'ASC'],
144
+				]
145
+			)
146
+		) {
147
+			return $states;
148
+		}
149
+		return false;
150
+	}
151
+
152
+
153
+	/**
154
+	 *  get_all_states_of_active_countries
155
+	 *
156
+	 * @return array
157
+	 */
158
+	public function get_all_active_states_for_these_countries($countries)
159
+	{
160
+		if (! $countries) {
161
+			return false;
162
+		}
163
+		if (
164
+			$states = $this->get_all(
165
+				[
166
+					['Country.CNT_ISO' => ['IN', array_keys($countries)], 'STA_active' => true],
167
+					'order_by' => ['Country.CNT_name' => 'ASC', 'STA_name' => 'ASC'],
168
+				]
169
+			)
170
+		) {
171
+			return $states;
172
+		}
173
+		return false;
174
+	}
175
+
176
+
177
+	/**
178
+	 *  get_all_states_of_active_countries
179
+	 *
180
+	 * @return array
181
+	 */
182
+	public function get_all_states_for_these_countries($countries)
183
+	{
184
+		if (! $countries) {
185
+			return false;
186
+		}
187
+		if (
188
+			$states = $this->get_all(
189
+				[
190
+					['Country.CNT_ISO' => ['IN', array_keys($countries)]],
191
+					'order_by' => ['Country.CNT_name' => 'ASC', 'STA_name' => 'ASC'],
192
+				]
193
+			)
194
+		) {
195
+			return $states;
196
+		}
197
+		return false;
198
+	}
199
+
200
+
201
+	/**
202
+	 * Gets the state's name by its ID
203
+	 *
204
+	 * @param string $state_ID
205
+	 * @return string
206
+	 */
207
+	public function get_state_name_by_ID($state_ID)
208
+	{
209
+		if (
210
+			isset(self::$_all_states[ $state_ID ]) &&
211
+			self::$_all_states[ $state_ID ] instanceof EE_State
212
+		) {
213
+			return self::$_all_states[ $state_ID ]->name();
214
+		}
215
+		$names = $this->get_col([['STA_ID' => $state_ID], 'limit' => 1], 'STA_name');
216
+		if (is_array($names) && ! empty($names)) {
217
+			return reset($names);
218
+		} else {
219
+			return '';
220
+		}
221
+	}
222 222
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -12,10 +12,10 @@  discard block
 block discarded – undo
12 12
     protected static ?EEM_State $_instance = null;
13 13
 
14 14
     // array of all states
15
-    private static ?array $_all_states = null;
15
+    private static ? array $_all_states = null;
16 16
 
17 17
     // array of all active states
18
-    private static ?array $_active_states = null;
18
+    private static ? array $_active_states = null;
19 19
 
20 20
 
21 21
     /**
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
             'State' => new EE_Primary_Table('esp_state', 'STA_ID'),
32 32
         ];
33 33
 
34
-        $this->_fields          = [
34
+        $this->_fields = [
35 35
             'State' => [
36 36
                 'STA_ID'     => new EE_Primary_Key_Int_Field('STA_ID', esc_html__('State ID', 'event_espresso')),
37 37
                 'CNT_ISO'    => new EE_Foreign_Key_String_Field(
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
             'Venue'    => new EE_Has_Many_Relation(),
68 68
         ];
69 69
         // this model is generally available for reading
70
-        $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public();
70
+        $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public();
71 71
         // @todo: only show STA_active
72 72
         parent::__construct($timezone);
73 73
     }
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
      */
95 95
     public function get_all_states()
96 96
     {
97
-        if (! self::$_all_states) {
97
+        if ( ! self::$_all_states) {
98 98
             self::$_all_states = $this->get_all(['order_by' => ['STA_name' => 'ASC'], 'limit' => [0, 99999]]);
99 99
         }
100 100
         return self::$_all_states;
@@ -111,8 +111,8 @@  discard block
 block discarded – undo
111 111
      */
112 112
     public function get_all_active_states($countries = [], $flush_cache = false)
113 113
     {
114
-        if (! self::$_active_states || $flush_cache) {
115
-            $countries            = is_array($countries) && ! empty($countries)
114
+        if ( ! self::$_active_states || $flush_cache) {
115
+            $countries = is_array($countries) && ! empty($countries)
116 116
                 ? $countries
117 117
                 : EEM_Country::instance()
118 118
                              ->get_all_active_countries();
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
      */
158 158
     public function get_all_active_states_for_these_countries($countries)
159 159
     {
160
-        if (! $countries) {
160
+        if ( ! $countries) {
161 161
             return false;
162 162
         }
163 163
         if (
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
      */
182 182
     public function get_all_states_for_these_countries($countries)
183 183
     {
184
-        if (! $countries) {
184
+        if ( ! $countries) {
185 185
             return false;
186 186
         }
187 187
         if (
@@ -207,10 +207,10 @@  discard block
 block discarded – undo
207 207
     public function get_state_name_by_ID($state_ID)
208 208
     {
209 209
         if (
210
-            isset(self::$_all_states[ $state_ID ]) &&
211
-            self::$_all_states[ $state_ID ] instanceof EE_State
210
+            isset(self::$_all_states[$state_ID]) &&
211
+            self::$_all_states[$state_ID] instanceof EE_State
212 212
         ) {
213
-            return self::$_all_states[ $state_ID ]->name();
213
+            return self::$_all_states[$state_ID]->name();
214 214
         }
215 215
         $names = $this->get_col([['STA_ID' => $state_ID], 'limit' => 1], 'STA_name');
216 216
         if (is_array($names) && ! empty($names)) {
Please login to merge, or discard this patch.
core/db_models/EEM_Transaction.model.php 1 patch
Indentation   +447 added lines, -447 removed lines patch added patch discarded remove patch
@@ -18,225 +18,225 @@  discard block
 block discarded – undo
18 18
  */
19 19
 class EEM_Transaction extends EEM_Base
20 20
 {
21
-    protected static ?EEM_Transaction $_instance = null;
22
-
23
-    /**
24
-     * Status ID(STS_ID on esp_status table) to indicate the transaction is complete,
25
-     * but payment is pending. This is the state for transactions where payment is promised
26
-     * from an offline gateway.
27
-     */
28
-    //  const open_status_code = 'TPN';
29
-
30
-    /**
31
-     * Status ID(STS_ID on esp_status table) to indicate the transaction failed,
32
-     * either due to a technical reason (server or computer crash during registration),
33
-     *  or some other reason that prevent the collection of any useful contact information from any of the registrants
34
-     */
35
-    const failed_status_code = 'TFL';
36
-
37
-    /**
38
-     * Status ID(STS_ID on esp_status table) to indicate the transaction was abandoned,
39
-     * either due to a technical reason (server or computer crash during registration),
40
-     * or due to an abandoned cart after registrant chose not to complete the registration process
41
-     * HOWEVER...
42
-     * an abandoned TXN differs from a failed TXN in that it was able to capture contact information for at least one
43
-     * registrant
44
-     */
45
-    const abandoned_status_code = 'TAB';
46
-
47
-    /**
48
-     * Status ID(STS_ID on esp_status table) to indicate an incomplete transaction,
49
-     * meaning that monies are still owing: TXN_paid < TXN_total
50
-     */
51
-    const incomplete_status_code = 'TIN';
52
-
53
-    /**
54
-     * Status ID (STS_ID on esp_status table) to indicate a complete transaction.
55
-     * meaning that NO monies are owing: TXN_paid == TXN_total
56
-     */
57
-    const complete_status_code = 'TCM';
58
-
59
-    /**
60
-     *  Status ID(STS_ID on esp_status table) to indicate the transaction is overpaid.
61
-     *  This is the same as complete, but site admins actually owe clients the moneys!  TXN_paid > TXN_total
62
-     */
63
-    const overpaid_status_code = 'TOP';
64
-
65
-
66
-    /**
67
-     * private constructor to prevent direct creation
68
-     *
69
-     * @param string|null $timezone string representing the timezone we want to set for returned Date Time Strings (and
70
-     *                              any incoming timezone data that gets saved). Note this just sends the timezone info
71
-     *                              to the date time model field objects.  Default is NULL (and will be assumed using
72
-     *                              the set timezone in the 'timezone_string' wp option)
73
-     * @throws EE_Error
74
-     * @throws ReflectionException
75
-     */
76
-    protected function __construct(?string $timezone = '')
77
-    {
78
-        $this->singular_item = esc_html__('Transaction', 'event_espresso');
79
-        $this->plural_item   = esc_html__('Transactions', 'event_espresso');
80
-
81
-        $this->_tables                 = [
82
-            'TransactionTable' => new EE_Primary_Table('esp_transaction', 'TXN_ID'),
83
-        ];
84
-        $this->_fields                 = [
85
-            'TransactionTable' => [
86
-                'TXN_ID'           => new EE_Primary_Key_Int_Field(
87
-                    'TXN_ID', esc_html__('Transaction ID', 'event_espresso')
88
-                ),
89
-                'TXN_timestamp'    => new EE_Datetime_Field(
90
-                    'TXN_timestamp',
91
-                    esc_html__('date when transaction was created', 'event_espresso'),
92
-                    false,
93
-                    EE_Datetime_Field::now,
94
-                    $timezone
95
-                ),
96
-                'TXN_total'        => new EE_Money_Field(
97
-                    'TXN_total',
98
-                    esc_html__('Total value of Transaction', 'event_espresso'),
99
-                    false,
100
-                    0
101
-                ),
102
-                'TXN_paid'         => new EE_Money_Field(
103
-                    'TXN_paid',
104
-                    esc_html__('Amount paid towards transaction to date', 'event_espresso'),
105
-                    false,
106
-                    0
107
-                ),
108
-                'STS_ID'           => new EE_Foreign_Key_String_Field(
109
-                    'STS_ID',
110
-                    esc_html__('Status ID', 'event_espresso'),
111
-                    false,
112
-                    EEM_Transaction::failed_status_code,
113
-                    'Status'
114
-                ),
115
-                'TXN_session_data' => new EE_Serialized_Text_Field(
116
-                    'TXN_session_data',
117
-                    esc_html__('Serialized session data', 'event_espresso'),
118
-                    true,
119
-                    ''
120
-                ),
121
-                'TXN_hash_salt'    => new EE_Plain_Text_Field(
122
-                    'TXN_hash_salt',
123
-                    esc_html__('Transaction Hash Salt', 'event_espresso'),
124
-                    true,
125
-                    ''
126
-                ),
127
-                'PMD_ID'           => new EE_Foreign_Key_Int_Field(
128
-                    'PMD_ID',
129
-                    esc_html__("Last Used Payment Method", 'event_espresso'),
130
-                    true,
131
-                    null,
132
-                    'Payment_Method'
133
-                ),
134
-                'TXN_reg_steps'    => new EE_Serialized_Text_Field(
135
-                    'TXN_reg_steps',
136
-                    esc_html__('Registration Steps', 'event_espresso'),
137
-                    false,
138
-                    []
139
-                ),
140
-            ],
141
-        ];
142
-        $this->_model_relations        = [
143
-            'Registration'   => new EE_Has_Many_Relation(),
144
-            'Payment'        => new EE_Has_Many_Relation(),
145
-            'Status'         => new EE_Belongs_To_Relation(),
146
-            'Line_Item'      => new EE_Has_Many_Relation(false),
147
-            // you can delete a transaction without needing to delete its line items
148
-            'Payment_Method' => new EE_Belongs_To_Relation(),
149
-            'Message'        => new EE_Has_Many_Relation(),
150
-        ];
151
-        $this->_model_chain_to_wp_user = 'Registration.Event';
152
-        parent::__construct($timezone);
153
-    }
154
-
155
-
156
-    /**
157
-     *    txn_status_array
158
-     * get list of transaction statuses
159
-     *
160
-     * @access public
161
-     * @return array
162
-     */
163
-    public static function txn_status_array()
164
-    {
165
-        return apply_filters(
166
-            'FHEE__EEM_Transaction__txn_status_array',
167
-            [
168
-                EEM_Transaction::overpaid_status_code,
169
-                EEM_Transaction::complete_status_code,
170
-                EEM_Transaction::incomplete_status_code,
171
-                EEM_Transaction::abandoned_status_code,
172
-                EEM_Transaction::failed_status_code,
173
-            ]
174
-        );
175
-    }
176
-
177
-
178
-    /**
179
-     *        get the revenue per day  for the Transaction Admin page Reports Tab
180
-     *
181
-     * @access        public
182
-     * @param string $period
183
-     * @return stdClass[]
184
-     * @throws EE_Error
185
-     * @throws EE_Error
186
-     */
187
-    public function get_revenue_per_day_report($period = '-1 month')
188
-    {
189
-        $sql_date = $this->convert_datetime_for_query(
190
-            'TXN_timestamp',
191
-            date('Y-m-d H:i:s', strtotime($period)),
192
-            'Y-m-d H:i:s',
193
-            'UTC'
194
-        );
195
-
196
-        $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'TXN_timestamp');
197
-
198
-        return $this->_get_all_wpdb_results(
199
-            [
200
-                [
201
-                    'TXN_timestamp' => ['>=', $sql_date],
202
-                ],
203
-                'group_by' => 'txnDate',
204
-                'order_by' => ['TXN_timestamp' => 'ASC'],
205
-            ],
206
-            OBJECT,
207
-            [
208
-                'txnDate' => ['DATE(' . $query_interval . ')', '%s'],
209
-                'revenue' => ['SUM(TransactionTable.TXN_paid)', '%d'],
210
-            ]
211
-        );
212
-    }
213
-
214
-
215
-    /**
216
-     *        get the revenue per event  for the Transaction Admin page Reports Tab
217
-     *
218
-     * @access        public
219
-     * @param string $period
220
-     * @return EE_Transaction[]
221
-     */
222
-    public function get_revenue_per_event_report($period = '-1 month')
223
-    {
224
-        global $wpdb;
225
-        $transaction_table          = $wpdb->prefix . 'esp_transaction';
226
-        $registration_table         = $wpdb->prefix . 'esp_registration';
227
-        $registration_payment_table = $wpdb->prefix . 'esp_registration_payment';
228
-        $event_table                = $wpdb->posts;
229
-        $payment_table              = $wpdb->prefix . 'esp_payment';
230
-        $sql_date                   = date('Y-m-d H:i:s', strtotime($period));
231
-        $approved_payment_status    = EEM_Payment::status_id_approved;
232
-        $extra_event_on_join        = '';
233
-        // exclude events not authored by user if permissions in effect
234
-        if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
235
-            $extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id();
236
-        }
237
-
238
-        return $wpdb->get_results(
239
-            "SELECT
21
+	protected static ?EEM_Transaction $_instance = null;
22
+
23
+	/**
24
+	 * Status ID(STS_ID on esp_status table) to indicate the transaction is complete,
25
+	 * but payment is pending. This is the state for transactions where payment is promised
26
+	 * from an offline gateway.
27
+	 */
28
+	//  const open_status_code = 'TPN';
29
+
30
+	/**
31
+	 * Status ID(STS_ID on esp_status table) to indicate the transaction failed,
32
+	 * either due to a technical reason (server or computer crash during registration),
33
+	 *  or some other reason that prevent the collection of any useful contact information from any of the registrants
34
+	 */
35
+	const failed_status_code = 'TFL';
36
+
37
+	/**
38
+	 * Status ID(STS_ID on esp_status table) to indicate the transaction was abandoned,
39
+	 * either due to a technical reason (server or computer crash during registration),
40
+	 * or due to an abandoned cart after registrant chose not to complete the registration process
41
+	 * HOWEVER...
42
+	 * an abandoned TXN differs from a failed TXN in that it was able to capture contact information for at least one
43
+	 * registrant
44
+	 */
45
+	const abandoned_status_code = 'TAB';
46
+
47
+	/**
48
+	 * Status ID(STS_ID on esp_status table) to indicate an incomplete transaction,
49
+	 * meaning that monies are still owing: TXN_paid < TXN_total
50
+	 */
51
+	const incomplete_status_code = 'TIN';
52
+
53
+	/**
54
+	 * Status ID (STS_ID on esp_status table) to indicate a complete transaction.
55
+	 * meaning that NO monies are owing: TXN_paid == TXN_total
56
+	 */
57
+	const complete_status_code = 'TCM';
58
+
59
+	/**
60
+	 *  Status ID(STS_ID on esp_status table) to indicate the transaction is overpaid.
61
+	 *  This is the same as complete, but site admins actually owe clients the moneys!  TXN_paid > TXN_total
62
+	 */
63
+	const overpaid_status_code = 'TOP';
64
+
65
+
66
+	/**
67
+	 * private constructor to prevent direct creation
68
+	 *
69
+	 * @param string|null $timezone string representing the timezone we want to set for returned Date Time Strings (and
70
+	 *                              any incoming timezone data that gets saved). Note this just sends the timezone info
71
+	 *                              to the date time model field objects.  Default is NULL (and will be assumed using
72
+	 *                              the set timezone in the 'timezone_string' wp option)
73
+	 * @throws EE_Error
74
+	 * @throws ReflectionException
75
+	 */
76
+	protected function __construct(?string $timezone = '')
77
+	{
78
+		$this->singular_item = esc_html__('Transaction', 'event_espresso');
79
+		$this->plural_item   = esc_html__('Transactions', 'event_espresso');
80
+
81
+		$this->_tables                 = [
82
+			'TransactionTable' => new EE_Primary_Table('esp_transaction', 'TXN_ID'),
83
+		];
84
+		$this->_fields                 = [
85
+			'TransactionTable' => [
86
+				'TXN_ID'           => new EE_Primary_Key_Int_Field(
87
+					'TXN_ID', esc_html__('Transaction ID', 'event_espresso')
88
+				),
89
+				'TXN_timestamp'    => new EE_Datetime_Field(
90
+					'TXN_timestamp',
91
+					esc_html__('date when transaction was created', 'event_espresso'),
92
+					false,
93
+					EE_Datetime_Field::now,
94
+					$timezone
95
+				),
96
+				'TXN_total'        => new EE_Money_Field(
97
+					'TXN_total',
98
+					esc_html__('Total value of Transaction', 'event_espresso'),
99
+					false,
100
+					0
101
+				),
102
+				'TXN_paid'         => new EE_Money_Field(
103
+					'TXN_paid',
104
+					esc_html__('Amount paid towards transaction to date', 'event_espresso'),
105
+					false,
106
+					0
107
+				),
108
+				'STS_ID'           => new EE_Foreign_Key_String_Field(
109
+					'STS_ID',
110
+					esc_html__('Status ID', 'event_espresso'),
111
+					false,
112
+					EEM_Transaction::failed_status_code,
113
+					'Status'
114
+				),
115
+				'TXN_session_data' => new EE_Serialized_Text_Field(
116
+					'TXN_session_data',
117
+					esc_html__('Serialized session data', 'event_espresso'),
118
+					true,
119
+					''
120
+				),
121
+				'TXN_hash_salt'    => new EE_Plain_Text_Field(
122
+					'TXN_hash_salt',
123
+					esc_html__('Transaction Hash Salt', 'event_espresso'),
124
+					true,
125
+					''
126
+				),
127
+				'PMD_ID'           => new EE_Foreign_Key_Int_Field(
128
+					'PMD_ID',
129
+					esc_html__("Last Used Payment Method", 'event_espresso'),
130
+					true,
131
+					null,
132
+					'Payment_Method'
133
+				),
134
+				'TXN_reg_steps'    => new EE_Serialized_Text_Field(
135
+					'TXN_reg_steps',
136
+					esc_html__('Registration Steps', 'event_espresso'),
137
+					false,
138
+					[]
139
+				),
140
+			],
141
+		];
142
+		$this->_model_relations        = [
143
+			'Registration'   => new EE_Has_Many_Relation(),
144
+			'Payment'        => new EE_Has_Many_Relation(),
145
+			'Status'         => new EE_Belongs_To_Relation(),
146
+			'Line_Item'      => new EE_Has_Many_Relation(false),
147
+			// you can delete a transaction without needing to delete its line items
148
+			'Payment_Method' => new EE_Belongs_To_Relation(),
149
+			'Message'        => new EE_Has_Many_Relation(),
150
+		];
151
+		$this->_model_chain_to_wp_user = 'Registration.Event';
152
+		parent::__construct($timezone);
153
+	}
154
+
155
+
156
+	/**
157
+	 *    txn_status_array
158
+	 * get list of transaction statuses
159
+	 *
160
+	 * @access public
161
+	 * @return array
162
+	 */
163
+	public static function txn_status_array()
164
+	{
165
+		return apply_filters(
166
+			'FHEE__EEM_Transaction__txn_status_array',
167
+			[
168
+				EEM_Transaction::overpaid_status_code,
169
+				EEM_Transaction::complete_status_code,
170
+				EEM_Transaction::incomplete_status_code,
171
+				EEM_Transaction::abandoned_status_code,
172
+				EEM_Transaction::failed_status_code,
173
+			]
174
+		);
175
+	}
176
+
177
+
178
+	/**
179
+	 *        get the revenue per day  for the Transaction Admin page Reports Tab
180
+	 *
181
+	 * @access        public
182
+	 * @param string $period
183
+	 * @return stdClass[]
184
+	 * @throws EE_Error
185
+	 * @throws EE_Error
186
+	 */
187
+	public function get_revenue_per_day_report($period = '-1 month')
188
+	{
189
+		$sql_date = $this->convert_datetime_for_query(
190
+			'TXN_timestamp',
191
+			date('Y-m-d H:i:s', strtotime($period)),
192
+			'Y-m-d H:i:s',
193
+			'UTC'
194
+		);
195
+
196
+		$query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'TXN_timestamp');
197
+
198
+		return $this->_get_all_wpdb_results(
199
+			[
200
+				[
201
+					'TXN_timestamp' => ['>=', $sql_date],
202
+				],
203
+				'group_by' => 'txnDate',
204
+				'order_by' => ['TXN_timestamp' => 'ASC'],
205
+			],
206
+			OBJECT,
207
+			[
208
+				'txnDate' => ['DATE(' . $query_interval . ')', '%s'],
209
+				'revenue' => ['SUM(TransactionTable.TXN_paid)', '%d'],
210
+			]
211
+		);
212
+	}
213
+
214
+
215
+	/**
216
+	 *        get the revenue per event  for the Transaction Admin page Reports Tab
217
+	 *
218
+	 * @access        public
219
+	 * @param string $period
220
+	 * @return EE_Transaction[]
221
+	 */
222
+	public function get_revenue_per_event_report($period = '-1 month')
223
+	{
224
+		global $wpdb;
225
+		$transaction_table          = $wpdb->prefix . 'esp_transaction';
226
+		$registration_table         = $wpdb->prefix . 'esp_registration';
227
+		$registration_payment_table = $wpdb->prefix . 'esp_registration_payment';
228
+		$event_table                = $wpdb->posts;
229
+		$payment_table              = $wpdb->prefix . 'esp_payment';
230
+		$sql_date                   = date('Y-m-d H:i:s', strtotime($period));
231
+		$approved_payment_status    = EEM_Payment::status_id_approved;
232
+		$extra_event_on_join        = '';
233
+		// exclude events not authored by user if permissions in effect
234
+		if (! EE_Registry::instance()->CAP->current_user_can('ee_read_others_registrations', 'reg_per_event_report')) {
235
+			$extra_event_on_join = ' AND Event.post_author = ' . get_current_user_id();
236
+		}
237
+
238
+		return $wpdb->get_results(
239
+			"SELECT
240 240
 			Transaction_Event.event_name AS event_name,
241 241
 			SUM(Transaction_Event.paid) AS revenue
242 242
 			FROM
@@ -264,232 +264,232 @@  discard block
 block discarded – undo
264 264
 					$extra_event_on_join
265 265
 				) AS Transaction_Event
266 266
 			GROUP BY event_name"
267
-        );
268
-    }
269
-
270
-
271
-    /**
272
-     * Gets the current transaction given the reg_url_link, or assumes the reg_url_link is in the
273
-     * request global variable. Either way, tries to find the current transaction (through
274
-     * the registration pointed to by reg_url_link), if not returns null
275
-     *
276
-     * @param string $reg_url_link
277
-     * @return EE_Transaction
278
-     * @throws EE_Error
279
-     */
280
-    public function get_transaction_from_reg_url_link($reg_url_link = '')
281
-    {
282
-        if (empty($reg_url_link)) {
283
-            $request      = LoaderFactory::getLoader()->getShared(RequestInterface::class);
284
-            $reg_url_link = $request->getRequestParam('e_reg_url_link');
285
-        }
286
-        return $this->get_one(
287
-            [
288
-                [
289
-                    'Registration.REG_url_link' => $reg_url_link,
290
-                ],
291
-            ]
292
-        );
293
-    }
294
-
295
-
296
-    /**
297
-     * Updates the provided EE_Transaction with all the applicable payments
298
-     * (or fetch the EE_Transaction from its ID)
299
-     *
300
-     * @param EE_Transaction|int $transaction_obj_or_id
301
-     * @param boolean            $save_txn whether or not to save the transaction during this function call
302
-     * @return array
303
-     * @throws EE_Error
304
-     * @throws ReflectionException
305
-     * @deprecated
306
-     */
307
-    public function update_based_on_payments($transaction_obj_or_id, $save_txn = true)
308
-    {
309
-        EE_Error::doing_it_wrong(
310
-            __CLASS__ . '::' . __FUNCTION__,
311
-            sprintf(
312
-                esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
313
-                'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()'
314
-            ),
315
-            '4.6.0'
316
-        );
317
-        /** @type EE_Transaction_Processor $transaction_processor */
318
-        $transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
319
-
320
-        return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment(
321
-            $this->ensure_is_obj($transaction_obj_or_id)
322
-        );
323
-    }
324
-
325
-
326
-    /**
327
-     * Deletes "junk" transactions that were probably added by bots. There might be TONS
328
-     * of these, so we are very careful to NOT select (which the models do even when deleting),
329
-     * and so we only use wpdb directly and only do minimal joins.
330
-     * Transactions are considered "junk" if they're failed for longer than a week.
331
-     * Also, there is an extra check for payments related to the transaction, because if a transaction has a payment on
332
-     * it, it's probably not junk (regardless of what status it has).
333
-     * The downside to this approach is that is addons are listening for object deletions
334
-     * on EEM_Base::delete() they won't be notified of this.  However, there is an action that plugins can hook into
335
-     * to catch these types of deletions.
336
-     *
337
-     * @return int
338
-     * @throws EE_Error
339
-     * @throws EE_Error
340
-     * @global WPDB $wpdb
341
-     */
342
-    public function delete_junk_transactions()
343
-    {
344
-        global $wpdb;
345
-        $deleted             = false;
346
-        $time_to_leave_alone = (int) apply_filters(
347
-            'FHEE__EEM_Transaction__delete_junk_transactions__time_to_leave_alone',
348
-            WEEK_IN_SECONDS
349
-        );
350
-
351
-
352
-        /**
353
-         * This allows code to filter the query arguments used for retrieving the transaction IDs to delete.
354
-         * Useful for plugins that want to exclude transactions matching certain query parameters.
355
-         * The query parameters should be in the format accepted by the EEM_Base model queries.
356
-         */
357
-        $ids_query = apply_filters(
358
-            'FHEE__EEM_Transaction__delete_junk_transactions__initial_query_args',
359
-            [
360
-                0          => [
361
-                    'STS_ID'         => EEM_Transaction::failed_status_code,
362
-                    'Payment.PAY_ID' => ['IS NULL'],
363
-                    'TXN_timestamp'  => ['<', time() - $time_to_leave_alone],
364
-                ],
365
-                'order_by' => ['TXN_timestamp' => 'ASC'],
366
-                'limit'    => 1000,
367
-            ],
368
-            $time_to_leave_alone
369
-        );
370
-
371
-
372
-        /**
373
-         * This filter is for when code needs to filter the list of transaction ids that represent transactions
374
-         * about to be deleted based on some other criteria that isn't easily done via the query args filter.
375
-         */
376
-        $txn_ids = apply_filters(
377
-            'FHEE__EEM_Transaction__delete_junk_transactions__transaction_ids_to_delete',
378
-            EEM_Transaction::instance()->get_col($ids_query, 'TXN_ID'),
379
-            $time_to_leave_alone
380
-        );
381
-        // now that we have the ids to delete
382
-        if (! empty($txn_ids) && is_array($txn_ids)) {
383
-            // first, make sure these TXN's are removed the "ee_locked_transactions" array
384
-            EEM_Transaction::unset_locked_transactions($txn_ids);
385
-
386
-            // Create IDs placeholder.
387
-            $placeholders = array_fill(0, count($txn_ids), '%d');
388
-
389
-            // Glue it together to use inside $wpdb->prepare.
390
-            $format = implode(', ', $placeholders);
391
-
392
-            // let's get deleting...
393
-            // We got the ids from the original query to get them FROM
394
-            // the db (which is sanitized) so no need to prepare them again.
395
-            $query   = $wpdb->prepare("DELETE FROM " . $this->table() . " WHERE TXN_ID IN ( $format )", $txn_ids);
396
-            $deleted = $wpdb->query($query);
397
-        }
398
-        if ($deleted) {
399
-            /**
400
-             * Allows code to do something after the transactions have been deleted.
401
-             */
402
-            do_action('AHEE__EEM_Transaction__delete_junk_transactions__successful_deletion', $txn_ids);
403
-        }
404
-
405
-        return $deleted;
406
-    }
407
-
408
-
409
-    /**
410
-     * @param array $transaction_IDs
411
-     * @return bool
412
-     */
413
-    public static function unset_locked_transactions(array $transaction_IDs)
414
-    {
415
-        $locked_transactions = get_option('ee_locked_transactions', []);
416
-        $update              = false;
417
-        foreach ($transaction_IDs as $TXN_ID) {
418
-            if (isset($locked_transactions[ $TXN_ID ])) {
419
-                unset($locked_transactions[ $TXN_ID ]);
420
-                $update = true;
421
-            }
422
-        }
423
-        if ($update) {
424
-            update_option('ee_locked_transactions', $locked_transactions);
425
-        }
426
-
427
-        return $update;
428
-    }
429
-
430
-
431
-    /**
432
-     * returns an array of EE_Transaction objects whose timestamp is greater than
433
-     * the current time minus the session lifespan, which defaults to 60 minutes
434
-     *
435
-     * @return EE_Base_Class[]|EE_Transaction[]
436
-     * @throws EE_Error
437
-     * @throws InvalidArgumentException
438
-     * @throws InvalidDataTypeException
439
-     * @throws InvalidInterfaceException
440
-     */
441
-    public function get_transactions_in_progress()
442
-    {
443
-        return $this->_get_transactions_in_progress();
444
-    }
445
-
446
-
447
-    /**
448
-     * returns an array of EE_Transaction objects whose timestamp is less than
449
-     * the current time minus the session lifespan, which defaults to 60 minutes
450
-     *
451
-     * @return EE_Base_Class[]|EE_Transaction[]
452
-     * @throws EE_Error
453
-     * @throws InvalidArgumentException
454
-     * @throws InvalidDataTypeException
455
-     * @throws InvalidInterfaceException
456
-     */
457
-    public function get_transactions_not_in_progress()
458
-    {
459
-        return $this->_get_transactions_in_progress('<=');
460
-    }
461
-
462
-
463
-    /**
464
-     * @param string $comparison
465
-     * @return EE_Transaction[]
466
-     * @throws EE_Error
467
-     * @throws InvalidArgumentException
468
-     * @throws InvalidDataTypeException
469
-     * @throws InvalidInterfaceException
470
-     */
471
-    private function _get_transactions_in_progress($comparison = '>=')
472
-    {
473
-        $comparison = $comparison === '>=' || $comparison === '<='
474
-            ? $comparison
475
-            : '>=';
476
-        /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */
477
-        $session_lifespan = LoaderFactory::getLoader()->getShared(
478
-            'EventEspresso\core\domain\values\session\SessionLifespan'
479
-        );
480
-        return $this->get_all(
481
-            [
482
-                [
483
-                    'TXN_timestamp' => [
484
-                        $comparison,
485
-                        $session_lifespan->expiration(),
486
-                    ],
487
-                    'STS_ID'        => [
488
-                        '!=',
489
-                        EEM_Transaction::complete_status_code,
490
-                    ],
491
-                ],
492
-            ]
493
-        );
494
-    }
267
+		);
268
+	}
269
+
270
+
271
+	/**
272
+	 * Gets the current transaction given the reg_url_link, or assumes the reg_url_link is in the
273
+	 * request global variable. Either way, tries to find the current transaction (through
274
+	 * the registration pointed to by reg_url_link), if not returns null
275
+	 *
276
+	 * @param string $reg_url_link
277
+	 * @return EE_Transaction
278
+	 * @throws EE_Error
279
+	 */
280
+	public function get_transaction_from_reg_url_link($reg_url_link = '')
281
+	{
282
+		if (empty($reg_url_link)) {
283
+			$request      = LoaderFactory::getLoader()->getShared(RequestInterface::class);
284
+			$reg_url_link = $request->getRequestParam('e_reg_url_link');
285
+		}
286
+		return $this->get_one(
287
+			[
288
+				[
289
+					'Registration.REG_url_link' => $reg_url_link,
290
+				],
291
+			]
292
+		);
293
+	}
294
+
295
+
296
+	/**
297
+	 * Updates the provided EE_Transaction with all the applicable payments
298
+	 * (or fetch the EE_Transaction from its ID)
299
+	 *
300
+	 * @param EE_Transaction|int $transaction_obj_or_id
301
+	 * @param boolean            $save_txn whether or not to save the transaction during this function call
302
+	 * @return array
303
+	 * @throws EE_Error
304
+	 * @throws ReflectionException
305
+	 * @deprecated
306
+	 */
307
+	public function update_based_on_payments($transaction_obj_or_id, $save_txn = true)
308
+	{
309
+		EE_Error::doing_it_wrong(
310
+			__CLASS__ . '::' . __FUNCTION__,
311
+			sprintf(
312
+				esc_html__('This method is deprecated. Please use "%s" instead', 'event_espresso'),
313
+				'EE_Transaction_Processor::update_transaction_and_registrations_after_checkout_or_payment()'
314
+			),
315
+			'4.6.0'
316
+		);
317
+		/** @type EE_Transaction_Processor $transaction_processor */
318
+		$transaction_processor = EE_Registry::instance()->load_class('Transaction_Processor');
319
+
320
+		return $transaction_processor->update_transaction_and_registrations_after_checkout_or_payment(
321
+			$this->ensure_is_obj($transaction_obj_or_id)
322
+		);
323
+	}
324
+
325
+
326
+	/**
327
+	 * Deletes "junk" transactions that were probably added by bots. There might be TONS
328
+	 * of these, so we are very careful to NOT select (which the models do even when deleting),
329
+	 * and so we only use wpdb directly and only do minimal joins.
330
+	 * Transactions are considered "junk" if they're failed for longer than a week.
331
+	 * Also, there is an extra check for payments related to the transaction, because if a transaction has a payment on
332
+	 * it, it's probably not junk (regardless of what status it has).
333
+	 * The downside to this approach is that is addons are listening for object deletions
334
+	 * on EEM_Base::delete() they won't be notified of this.  However, there is an action that plugins can hook into
335
+	 * to catch these types of deletions.
336
+	 *
337
+	 * @return int
338
+	 * @throws EE_Error
339
+	 * @throws EE_Error
340
+	 * @global WPDB $wpdb
341
+	 */
342
+	public function delete_junk_transactions()
343
+	{
344
+		global $wpdb;
345
+		$deleted             = false;
346
+		$time_to_leave_alone = (int) apply_filters(
347
+			'FHEE__EEM_Transaction__delete_junk_transactions__time_to_leave_alone',
348
+			WEEK_IN_SECONDS
349
+		);
350
+
351
+
352
+		/**
353
+		 * This allows code to filter the query arguments used for retrieving the transaction IDs to delete.
354
+		 * Useful for plugins that want to exclude transactions matching certain query parameters.
355
+		 * The query parameters should be in the format accepted by the EEM_Base model queries.
356
+		 */
357
+		$ids_query = apply_filters(
358
+			'FHEE__EEM_Transaction__delete_junk_transactions__initial_query_args',
359
+			[
360
+				0          => [
361
+					'STS_ID'         => EEM_Transaction::failed_status_code,
362
+					'Payment.PAY_ID' => ['IS NULL'],
363
+					'TXN_timestamp'  => ['<', time() - $time_to_leave_alone],
364
+				],
365
+				'order_by' => ['TXN_timestamp' => 'ASC'],
366
+				'limit'    => 1000,
367
+			],
368
+			$time_to_leave_alone
369
+		);
370
+
371
+
372
+		/**
373
+		 * This filter is for when code needs to filter the list of transaction ids that represent transactions
374
+		 * about to be deleted based on some other criteria that isn't easily done via the query args filter.
375
+		 */
376
+		$txn_ids = apply_filters(
377
+			'FHEE__EEM_Transaction__delete_junk_transactions__transaction_ids_to_delete',
378
+			EEM_Transaction::instance()->get_col($ids_query, 'TXN_ID'),
379
+			$time_to_leave_alone
380
+		);
381
+		// now that we have the ids to delete
382
+		if (! empty($txn_ids) && is_array($txn_ids)) {
383
+			// first, make sure these TXN's are removed the "ee_locked_transactions" array
384
+			EEM_Transaction::unset_locked_transactions($txn_ids);
385
+
386
+			// Create IDs placeholder.
387
+			$placeholders = array_fill(0, count($txn_ids), '%d');
388
+
389
+			// Glue it together to use inside $wpdb->prepare.
390
+			$format = implode(', ', $placeholders);
391
+
392
+			// let's get deleting...
393
+			// We got the ids from the original query to get them FROM
394
+			// the db (which is sanitized) so no need to prepare them again.
395
+			$query   = $wpdb->prepare("DELETE FROM " . $this->table() . " WHERE TXN_ID IN ( $format )", $txn_ids);
396
+			$deleted = $wpdb->query($query);
397
+		}
398
+		if ($deleted) {
399
+			/**
400
+			 * Allows code to do something after the transactions have been deleted.
401
+			 */
402
+			do_action('AHEE__EEM_Transaction__delete_junk_transactions__successful_deletion', $txn_ids);
403
+		}
404
+
405
+		return $deleted;
406
+	}
407
+
408
+
409
+	/**
410
+	 * @param array $transaction_IDs
411
+	 * @return bool
412
+	 */
413
+	public static function unset_locked_transactions(array $transaction_IDs)
414
+	{
415
+		$locked_transactions = get_option('ee_locked_transactions', []);
416
+		$update              = false;
417
+		foreach ($transaction_IDs as $TXN_ID) {
418
+			if (isset($locked_transactions[ $TXN_ID ])) {
419
+				unset($locked_transactions[ $TXN_ID ]);
420
+				$update = true;
421
+			}
422
+		}
423
+		if ($update) {
424
+			update_option('ee_locked_transactions', $locked_transactions);
425
+		}
426
+
427
+		return $update;
428
+	}
429
+
430
+
431
+	/**
432
+	 * returns an array of EE_Transaction objects whose timestamp is greater than
433
+	 * the current time minus the session lifespan, which defaults to 60 minutes
434
+	 *
435
+	 * @return EE_Base_Class[]|EE_Transaction[]
436
+	 * @throws EE_Error
437
+	 * @throws InvalidArgumentException
438
+	 * @throws InvalidDataTypeException
439
+	 * @throws InvalidInterfaceException
440
+	 */
441
+	public function get_transactions_in_progress()
442
+	{
443
+		return $this->_get_transactions_in_progress();
444
+	}
445
+
446
+
447
+	/**
448
+	 * returns an array of EE_Transaction objects whose timestamp is less than
449
+	 * the current time minus the session lifespan, which defaults to 60 minutes
450
+	 *
451
+	 * @return EE_Base_Class[]|EE_Transaction[]
452
+	 * @throws EE_Error
453
+	 * @throws InvalidArgumentException
454
+	 * @throws InvalidDataTypeException
455
+	 * @throws InvalidInterfaceException
456
+	 */
457
+	public function get_transactions_not_in_progress()
458
+	{
459
+		return $this->_get_transactions_in_progress('<=');
460
+	}
461
+
462
+
463
+	/**
464
+	 * @param string $comparison
465
+	 * @return EE_Transaction[]
466
+	 * @throws EE_Error
467
+	 * @throws InvalidArgumentException
468
+	 * @throws InvalidDataTypeException
469
+	 * @throws InvalidInterfaceException
470
+	 */
471
+	private function _get_transactions_in_progress($comparison = '>=')
472
+	{
473
+		$comparison = $comparison === '>=' || $comparison === '<='
474
+			? $comparison
475
+			: '>=';
476
+		/** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */
477
+		$session_lifespan = LoaderFactory::getLoader()->getShared(
478
+			'EventEspresso\core\domain\values\session\SessionLifespan'
479
+		);
480
+		return $this->get_all(
481
+			[
482
+				[
483
+					'TXN_timestamp' => [
484
+						$comparison,
485
+						$session_lifespan->expiration(),
486
+					],
487
+					'STS_ID'        => [
488
+						'!=',
489
+						EEM_Transaction::complete_status_code,
490
+					],
491
+				],
492
+			]
493
+		);
494
+	}
495 495
 }
Please login to merge, or discard this patch.
core/db_models/EEM_Message_Template.model.php 1 patch
Indentation   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -9,75 +9,75 @@
 block discarded – undo
9 9
  */
10 10
 class EEM_Message_Template extends EEM_Base
11 11
 {
12
-    protected static ?EEM_Message_Template $_instance = null;
12
+	protected static ?EEM_Message_Template $_instance = null;
13 13
 
14 14
 
15
-    /**
16
-     * private constructor to prevent direct creation
17
-     *
18
-     * @param string|null $timezone
19
-     * @throws EE_Error
20
-     */
21
-    protected function __construct(?string $timezone = '')
22
-    {
23
-        $this->singular_item = esc_html__('Message Template', 'event_espresso');
24
-        $this->plural_item   = esc_html__('Message Templates', 'event_espresso');
15
+	/**
16
+	 * private constructor to prevent direct creation
17
+	 *
18
+	 * @param string|null $timezone
19
+	 * @throws EE_Error
20
+	 */
21
+	protected function __construct(?string $timezone = '')
22
+	{
23
+		$this->singular_item = esc_html__('Message Template', 'event_espresso');
24
+		$this->plural_item   = esc_html__('Message Templates', 'event_espresso');
25 25
 
26
-        $this->_tables = [
27
-            'Message_Template' => new EE_Primary_Table('esp_message_template', 'MTP_ID'),
28
-        ];
29
-        $this->_fields = [
30
-            'Message_Template' => [
31
-                'MTP_ID'             => new EE_Primary_Key_Int_Field(
32
-                    'MTP_ID',
33
-                    esc_html__('Message Template ID', 'event_espresso')
34
-                ),
35
-                'GRP_ID'             => new EE_Foreign_Key_Int_Field(
36
-                    'GRP_ID',
37
-                    esc_html__('Message Template Group ID', 'event_espresso'),
38
-                    false,
39
-                    0,
40
-                    'Message_Template_Group'
41
-                ),
42
-                'MTP_template_field' => new EE_Plain_Text_Field(
43
-                    'MTP_template_field',
44
-                    esc_html__(
45
-                        'Field Name for this Template',
46
-                        'event_espresso'
47
-                    ),
48
-                    false,
49
-                    'default'
50
-                ),
51
-                'MTP_context'        => new EE_Plain_Text_Field(
52
-                    'MTP_context',
53
-                    esc_html__(
54
-                        'Message Type Context for this field',
55
-                        'event_espresso'
56
-                    ),
57
-                    false,
58
-                    'admin'
59
-                ),
60
-                'MTP_content'        => new EE_Serialized_Text_Field(
61
-                    'MTP_content',
62
-                    esc_html__(
63
-                        'The field content for the template',
64
-                        'event_espresso'
65
-                    ),
66
-                    false,
67
-                    ''
68
-                ),
69
-            ],
70
-        ];
26
+		$this->_tables = [
27
+			'Message_Template' => new EE_Primary_Table('esp_message_template', 'MTP_ID'),
28
+		];
29
+		$this->_fields = [
30
+			'Message_Template' => [
31
+				'MTP_ID'             => new EE_Primary_Key_Int_Field(
32
+					'MTP_ID',
33
+					esc_html__('Message Template ID', 'event_espresso')
34
+				),
35
+				'GRP_ID'             => new EE_Foreign_Key_Int_Field(
36
+					'GRP_ID',
37
+					esc_html__('Message Template Group ID', 'event_espresso'),
38
+					false,
39
+					0,
40
+					'Message_Template_Group'
41
+				),
42
+				'MTP_template_field' => new EE_Plain_Text_Field(
43
+					'MTP_template_field',
44
+					esc_html__(
45
+						'Field Name for this Template',
46
+						'event_espresso'
47
+					),
48
+					false,
49
+					'default'
50
+				),
51
+				'MTP_context'        => new EE_Plain_Text_Field(
52
+					'MTP_context',
53
+					esc_html__(
54
+						'Message Type Context for this field',
55
+						'event_espresso'
56
+					),
57
+					false,
58
+					'admin'
59
+				),
60
+				'MTP_content'        => new EE_Serialized_Text_Field(
61
+					'MTP_content',
62
+					esc_html__(
63
+						'The field content for the template',
64
+						'event_espresso'
65
+					),
66
+					false,
67
+					''
68
+				),
69
+			],
70
+		];
71 71
 
72
-        $this->_model_relations        = [
73
-            'Message_Template_Group' => new EE_Belongs_To_Relation(),
74
-        ];
75
-        $this->_model_chain_to_wp_user = 'Message_Template_Group';
76
-        foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) {
77
-            $this->_cap_restriction_generators[ $context ] =
78
-                new EE_Restriction_Generator_Global('Message_Template_Group.MTP_is_global');
79
-        }
80
-        $this->_caps_slug = 'messages';
81
-        parent::__construct($timezone);
82
-    }
72
+		$this->_model_relations        = [
73
+			'Message_Template_Group' => new EE_Belongs_To_Relation(),
74
+		];
75
+		$this->_model_chain_to_wp_user = 'Message_Template_Group';
76
+		foreach ($this->_cap_contexts_to_cap_action_map as $context => $action) {
77
+			$this->_cap_restriction_generators[ $context ] =
78
+				new EE_Restriction_Generator_Global('Message_Template_Group.MTP_is_global');
79
+		}
80
+		$this->_caps_slug = 'messages';
81
+		parent::__construct($timezone);
82
+	}
83 83
 }
Please login to merge, or discard this patch.