@@ -18,27 +18,27 @@ |
||
18 | 18 | */ |
19 | 19 | class ModelConfigurationException extends DomainException |
20 | 20 | { |
21 | - /** |
|
22 | - * ModelConfigurationException constructor. |
|
23 | - * |
|
24 | - * @param EEM_Base $model |
|
25 | - * @param string $message Describe what's misconfigured about this model (don't bother mentioning which model, |
|
26 | - * that will be automatically added to the message based on the $model provided in the previous parameter). |
|
27 | - * @param int $code |
|
28 | - * @param Exception $previous |
|
29 | - */ |
|
30 | - public function __construct(EEM_Base $model, $message, $code = 0, Exception $previous = null) |
|
31 | - { |
|
32 | - $message_part_1 = sprintf( |
|
33 | - /* |
|
21 | + /** |
|
22 | + * ModelConfigurationException constructor. |
|
23 | + * |
|
24 | + * @param EEM_Base $model |
|
25 | + * @param string $message Describe what's misconfigured about this model (don't bother mentioning which model, |
|
26 | + * that will be automatically added to the message based on the $model provided in the previous parameter). |
|
27 | + * @param int $code |
|
28 | + * @param Exception $previous |
|
29 | + */ |
|
30 | + public function __construct(EEM_Base $model, $message, $code = 0, Exception $previous = null) |
|
31 | + { |
|
32 | + $message_part_1 = sprintf( |
|
33 | + /* |
|
34 | 34 | * translators: 1: the model name |
35 | 35 | */ |
36 | - esc_html__('The model "%1$s" appears to be misconfigured.', 'event_espresso'), |
|
37 | - $model->get_this_model_name() |
|
38 | - ); |
|
39 | - $message = $message_part_1 . ' ' . $message; |
|
40 | - parent::__construct($message, $code, $previous); |
|
41 | - } |
|
36 | + esc_html__('The model "%1$s" appears to be misconfigured.', 'event_espresso'), |
|
37 | + $model->get_this_model_name() |
|
38 | + ); |
|
39 | + $message = $message_part_1 . ' ' . $message; |
|
40 | + parent::__construct($message, $code, $previous); |
|
41 | + } |
|
42 | 42 | } |
43 | 43 | // End of file ModelConfigurationException.php |
44 | 44 | // Location: EventEspresso\core\exceptions/ModelConfigurationException.php |
@@ -36,7 +36,7 @@ |
||
36 | 36 | esc_html__('The model "%1$s" appears to be misconfigured.', 'event_espresso'), |
37 | 37 | $model->get_this_model_name() |
38 | 38 | ); |
39 | - $message = $message_part_1 . ' ' . $message; |
|
39 | + $message = $message_part_1.' '.$message; |
|
40 | 40 | parent::__construct($message, $code, $previous); |
41 | 41 | } |
42 | 42 | } |
@@ -16,17 +16,17 @@ |
||
16 | 16 | */ |
17 | 17 | class RestPasswordIncorrectException extends RestException |
18 | 18 | { |
19 | - public function __construct($previous = null) |
|
20 | - { |
|
21 | - parent::__construct( |
|
22 | - 'rest_post_incorrect_password', |
|
23 | - esc_html__('Incorrect password.', 'event_espresso'), |
|
24 | - array( |
|
25 | - 'status' => 403, |
|
26 | - ), |
|
27 | - $previous |
|
28 | - ); |
|
29 | - } |
|
19 | + public function __construct($previous = null) |
|
20 | + { |
|
21 | + parent::__construct( |
|
22 | + 'rest_post_incorrect_password', |
|
23 | + esc_html__('Incorrect password.', 'event_espresso'), |
|
24 | + array( |
|
25 | + 'status' => 403, |
|
26 | + ), |
|
27 | + $previous |
|
28 | + ); |
|
29 | + } |
|
30 | 30 | } |
31 | 31 | // End of file RestPasswordIncorrectException.php |
32 | 32 | // Location: EventEspresso\core\exceptions/RestPasswordIncorrectException.php |
@@ -42,10 +42,10 @@ |
||
42 | 42 | ); |
43 | 43 | // this model is generally available for reading |
44 | 44 | $path_to_event = 'Datetime.Event'; |
45 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event); |
|
46 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
47 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
48 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit); |
|
45 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public($path_to_event); |
|
46 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
47 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
48 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit); |
|
49 | 49 | $this->model_chain_to_password = $path_to_event; |
50 | 50 | parent::__construct($timezone); |
51 | 51 | } |
@@ -11,41 +11,41 @@ |
||
11 | 11 | */ |
12 | 12 | class EEM_Datetime_Ticket extends EEM_Base |
13 | 13 | { |
14 | - // private instance of the EEM_Datetime_Ticket object |
|
15 | - protected static $_instance = null; |
|
14 | + // private instance of the EEM_Datetime_Ticket object |
|
15 | + protected static $_instance = null; |
|
16 | 16 | |
17 | - /** |
|
18 | - * private constructor to prevent direct creation |
|
19 | - * @Constructor |
|
20 | - * @access private |
|
21 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
22 | - * @return void |
|
23 | - */ |
|
24 | - protected function __construct($timezone) |
|
25 | - { |
|
26 | - $this->singular_item = esc_html__('Datetime Ticket', 'event_espresso'); |
|
27 | - $this->plural_item = esc_html__('Datetime Tickets', 'event_espresso'); |
|
17 | + /** |
|
18 | + * private constructor to prevent direct creation |
|
19 | + * @Constructor |
|
20 | + * @access private |
|
21 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any incoming timezone data that gets saved). Note this just sends the timezone info to the date time model field objects. Default is NULL (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
22 | + * @return void |
|
23 | + */ |
|
24 | + protected function __construct($timezone) |
|
25 | + { |
|
26 | + $this->singular_item = esc_html__('Datetime Ticket', 'event_espresso'); |
|
27 | + $this->plural_item = esc_html__('Datetime Tickets', 'event_espresso'); |
|
28 | 28 | |
29 | - $this->_tables = array( |
|
30 | - 'Datetime_Ticket' => new EE_Primary_Table('esp_datetime_ticket', 'DTK_ID') |
|
31 | - ); |
|
32 | - $this->_fields = array( |
|
33 | - 'Datetime_Ticket' => array( |
|
34 | - 'DTK_ID' => new EE_Primary_Key_Int_Field('DTK_ID', esc_html__('Datetime Ticket ID', 'event_espresso')), |
|
35 | - 'DTT_ID' => new EE_Foreign_Key_Int_Field('DTT_ID', esc_html__('The ID to the Datetime', 'event_espresso'), false, 0, 'Datetime'), |
|
36 | - 'TKT_ID' => new EE_Foreign_Key_Int_Field('TKT_ID', esc_html__('The ID to the Ticket', 'event_espresso'), false, 0, 'Ticket') |
|
37 | - )); |
|
38 | - $this->_model_relations = array( |
|
39 | - 'Ticket' => new EE_Belongs_To_Relation(), |
|
40 | - 'Datetime' => new EE_Belongs_To_Relation() |
|
41 | - ); |
|
42 | - // this model is generally available for reading |
|
43 | - $path_to_event = 'Datetime.Event'; |
|
44 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event); |
|
45 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
46 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
47 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit); |
|
48 | - $this->model_chain_to_password = $path_to_event; |
|
49 | - parent::__construct($timezone); |
|
50 | - } |
|
29 | + $this->_tables = array( |
|
30 | + 'Datetime_Ticket' => new EE_Primary_Table('esp_datetime_ticket', 'DTK_ID') |
|
31 | + ); |
|
32 | + $this->_fields = array( |
|
33 | + 'Datetime_Ticket' => array( |
|
34 | + 'DTK_ID' => new EE_Primary_Key_Int_Field('DTK_ID', esc_html__('Datetime Ticket ID', 'event_espresso')), |
|
35 | + 'DTT_ID' => new EE_Foreign_Key_Int_Field('DTT_ID', esc_html__('The ID to the Datetime', 'event_espresso'), false, 0, 'Datetime'), |
|
36 | + 'TKT_ID' => new EE_Foreign_Key_Int_Field('TKT_ID', esc_html__('The ID to the Ticket', 'event_espresso'), false, 0, 'Ticket') |
|
37 | + )); |
|
38 | + $this->_model_relations = array( |
|
39 | + 'Ticket' => new EE_Belongs_To_Relation(), |
|
40 | + 'Datetime' => new EE_Belongs_To_Relation() |
|
41 | + ); |
|
42 | + // this model is generally available for reading |
|
43 | + $path_to_event = 'Datetime.Event'; |
|
44 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event); |
|
45 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
46 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
47 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit); |
|
48 | + $this->model_chain_to_password = $path_to_event; |
|
49 | + parent::__construct($timezone); |
|
50 | + } |
|
51 | 51 | } |
@@ -58,24 +58,24 @@ discard block |
||
58 | 58 | 'Term_Taxonomy' => new EE_Belongs_To_Relation(), |
59 | 59 | ); |
60 | 60 | foreach ($models_this_can_attach_to as $model_name) { |
61 | - $this->_model_relations[ $model_name ] = new EE_Belongs_To_Relation(); |
|
61 | + $this->_model_relations[$model_name] = new EE_Belongs_To_Relation(); |
|
62 | 62 | } |
63 | 63 | $this->_wp_core_model = true; |
64 | 64 | $this->_indexes = array( |
65 | 65 | 'PRIMARY' => new EE_Primary_Key_Index(array('object_id', 'term_taxonomy_id')), |
66 | 66 | ); |
67 | 67 | $path_to_event_model = 'Event'; |
68 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public( |
|
68 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public( |
|
69 | 69 | $path_to_event_model |
70 | 70 | ); |
71 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
71 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = |
|
72 | 72 | new EE_Restriction_Generator_Event_Related_Protected( |
73 | 73 | $path_to_event_model |
74 | 74 | ); |
75 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
75 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected( |
|
76 | 76 | $path_to_event_model |
77 | 77 | ); |
78 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
78 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = |
|
79 | 79 | new EE_Restriction_Generator_Event_Related_Protected( |
80 | 80 | $path_to_event_model, |
81 | 81 | EEM_Base::caps_edit |
@@ -85,27 +85,27 @@ discard block |
||
85 | 85 | // and for deleting term relations too |
86 | 86 | $cap_contexts_affected = array(EEM_Base::caps_edit, EEM_Base::caps_delete); |
87 | 87 | foreach ($cap_contexts_affected as $cap_context_affected) { |
88 | - $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_event_category'] = |
|
88 | + $this->_cap_restrictions[$cap_context_affected]['ee_assign_event_category'] = |
|
89 | 89 | new EE_Default_Where_Conditions( |
90 | 90 | array( |
91 | - $path_to_tax_model . 'taxonomy*ee_assign_event_category' => array( |
|
91 | + $path_to_tax_model.'taxonomy*ee_assign_event_category' => array( |
|
92 | 92 | '!=', |
93 | 93 | 'espresso_event_categories', |
94 | 94 | ), |
95 | 95 | ) |
96 | 96 | ); |
97 | - $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_venue_category'] = |
|
97 | + $this->_cap_restrictions[$cap_context_affected]['ee_assign_venue_category'] = |
|
98 | 98 | new EE_Default_Where_Conditions( |
99 | 99 | array( |
100 | - $path_to_tax_model . 'taxonomy*ee_assign_venue_category' => array( |
|
100 | + $path_to_tax_model.'taxonomy*ee_assign_venue_category' => array( |
|
101 | 101 | '!=', |
102 | 102 | 'espresso_venue_categories', |
103 | 103 | ), |
104 | 104 | ) |
105 | 105 | ); |
106 | - $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_event_type'] = new EE_Default_Where_Conditions( |
|
106 | + $this->_cap_restrictions[$cap_context_affected]['ee_assign_event_type'] = new EE_Default_Where_Conditions( |
|
107 | 107 | array( |
108 | - $path_to_tax_model . 'taxonomy*ee_assign_event_type' => array('!=', 'espresso_event_type'), |
|
108 | + $path_to_tax_model.'taxonomy*ee_assign_event_type' => array('!=', 'espresso_event_type'), |
|
109 | 109 | ) |
110 | 110 | ); |
111 | 111 | } |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | { |
233 | 233 | if ($model === EEM_Term_Relationship::instance()) { |
234 | 234 | $taxonomies = get_taxonomies(array('show_in_rest' => true)); |
235 | - if (! empty($taxonomies)) { |
|
235 | + if ( ! empty($taxonomies)) { |
|
236 | 236 | $model_query_params[0]['Term_Taxonomy.taxonomy'] = array('IN', $taxonomies); |
237 | 237 | } |
238 | 238 | } |
@@ -9,233 +9,233 @@ |
||
9 | 9 | */ |
10 | 10 | class EEM_Term_Relationship extends EEM_Base |
11 | 11 | { |
12 | - // private instance of the Attendee object |
|
13 | - protected static $_instance = null; |
|
14 | - |
|
15 | - |
|
16 | - |
|
17 | - /** |
|
18 | - * EEM_Term_Relationship constructor. |
|
19 | - * |
|
20 | - * @param string $timezone |
|
21 | - */ |
|
22 | - protected function __construct($timezone = null) |
|
23 | - { |
|
24 | - $this->singular_item = esc_html__('Term Relationship', 'event_espresso'); |
|
25 | - $this->plural_item = esc_html__('Term Relationships', 'event_espresso'); |
|
26 | - $this->_tables = array( |
|
27 | - 'Term_Relationship' => new EE_Primary_Table('term_relationships'), |
|
28 | - ); |
|
29 | - $models_this_can_attach_to = array_keys(EE_Registry::instance()->cpt_models()); |
|
30 | - $this->_fields = array( |
|
31 | - 'Term_Relationship' => array( |
|
32 | - 'object_id' => new EE_Foreign_Key_Int_Field( |
|
33 | - 'object_id', |
|
34 | - esc_html__('Object(Post) ID', 'event_espresso'), |
|
35 | - false, |
|
36 | - 0, |
|
37 | - $models_this_can_attach_to |
|
38 | - ), |
|
39 | - 'term_taxonomy_id' => new EE_Foreign_Key_Int_Field( |
|
40 | - 'term_taxonomy_id', |
|
41 | - esc_html__( |
|
42 | - 'Term (in context of a taxonomy) ID', |
|
43 | - 'event_espresso' |
|
44 | - ), |
|
45 | - false, |
|
46 | - 0, |
|
47 | - 'Term_Taxonomy' |
|
48 | - ), |
|
49 | - 'term_order' => new EE_Integer_Field( |
|
50 | - 'term_order', |
|
51 | - esc_html__('Term Order', 'event_espresso'), |
|
52 | - false, |
|
53 | - 0 |
|
54 | - ), |
|
55 | - ), |
|
56 | - ); |
|
57 | - $this->_model_relations = array( |
|
58 | - 'Term_Taxonomy' => new EE_Belongs_To_Relation(), |
|
59 | - ); |
|
60 | - foreach ($models_this_can_attach_to as $model_name) { |
|
61 | - $this->_model_relations[ $model_name ] = new EE_Belongs_To_Relation(); |
|
62 | - } |
|
63 | - $this->_wp_core_model = true; |
|
64 | - $this->_indexes = array( |
|
65 | - 'PRIMARY' => new EE_Primary_Key_Index(array('object_id', 'term_taxonomy_id')), |
|
66 | - ); |
|
67 | - $path_to_event_model = 'Event'; |
|
68 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public( |
|
69 | - $path_to_event_model |
|
70 | - ); |
|
71 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
72 | - new EE_Restriction_Generator_Event_Related_Protected( |
|
73 | - $path_to_event_model |
|
74 | - ); |
|
75 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
76 | - $path_to_event_model |
|
77 | - ); |
|
78 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
79 | - new EE_Restriction_Generator_Event_Related_Protected( |
|
80 | - $path_to_event_model, |
|
81 | - EEM_Base::caps_edit |
|
82 | - ); |
|
83 | - $path_to_tax_model = 'Term_Taxonomy.'; |
|
84 | - // add cap restrictions for editing term relations to the "ee_assign_*" |
|
85 | - // and for deleting term relations too |
|
86 | - $cap_contexts_affected = array(EEM_Base::caps_edit, EEM_Base::caps_delete); |
|
87 | - foreach ($cap_contexts_affected as $cap_context_affected) { |
|
88 | - $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_event_category'] = |
|
89 | - new EE_Default_Where_Conditions( |
|
90 | - array( |
|
91 | - $path_to_tax_model . 'taxonomy*ee_assign_event_category' => array( |
|
92 | - '!=', |
|
93 | - 'espresso_event_categories', |
|
94 | - ), |
|
95 | - ) |
|
96 | - ); |
|
97 | - $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_venue_category'] = |
|
98 | - new EE_Default_Where_Conditions( |
|
99 | - array( |
|
100 | - $path_to_tax_model . 'taxonomy*ee_assign_venue_category' => array( |
|
101 | - '!=', |
|
102 | - 'espresso_venue_categories', |
|
103 | - ), |
|
104 | - ) |
|
105 | - ); |
|
106 | - $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_event_type'] = new EE_Default_Where_Conditions( |
|
107 | - array( |
|
108 | - $path_to_tax_model . 'taxonomy*ee_assign_event_type' => array('!=', 'espresso_event_type'), |
|
109 | - ) |
|
110 | - ); |
|
111 | - } |
|
112 | - parent::__construct($timezone); |
|
113 | - add_filter( |
|
114 | - 'FHEE__Read__create_model_query_params', |
|
115 | - array('EEM_Term_Relationship', 'rest_api_query_params'), |
|
116 | - 10, |
|
117 | - 3 |
|
118 | - ); |
|
119 | - } |
|
120 | - |
|
121 | - |
|
122 | - /** |
|
123 | - * Makes sure all term-taxonomy counts are correct |
|
124 | - * |
|
125 | - * @param int $term_taxonomy_id the id of the term taxonomy to update. If NULL, updates ALL |
|
126 | - * @global wpdb $wpdb |
|
127 | - * @return int the number of rows affected |
|
128 | - * @throws EE_Error |
|
129 | - */ |
|
130 | - public function update_term_taxonomy_counts($term_taxonomy_id = null) |
|
131 | - { |
|
132 | - // because this uses a subquery and sometimes assigning to column to be another column's |
|
133 | - // value, we just write the SQL directly. |
|
134 | - global $wpdb; |
|
135 | - |
|
136 | - $query = " |
|
12 | + // private instance of the Attendee object |
|
13 | + protected static $_instance = null; |
|
14 | + |
|
15 | + |
|
16 | + |
|
17 | + /** |
|
18 | + * EEM_Term_Relationship constructor. |
|
19 | + * |
|
20 | + * @param string $timezone |
|
21 | + */ |
|
22 | + protected function __construct($timezone = null) |
|
23 | + { |
|
24 | + $this->singular_item = esc_html__('Term Relationship', 'event_espresso'); |
|
25 | + $this->plural_item = esc_html__('Term Relationships', 'event_espresso'); |
|
26 | + $this->_tables = array( |
|
27 | + 'Term_Relationship' => new EE_Primary_Table('term_relationships'), |
|
28 | + ); |
|
29 | + $models_this_can_attach_to = array_keys(EE_Registry::instance()->cpt_models()); |
|
30 | + $this->_fields = array( |
|
31 | + 'Term_Relationship' => array( |
|
32 | + 'object_id' => new EE_Foreign_Key_Int_Field( |
|
33 | + 'object_id', |
|
34 | + esc_html__('Object(Post) ID', 'event_espresso'), |
|
35 | + false, |
|
36 | + 0, |
|
37 | + $models_this_can_attach_to |
|
38 | + ), |
|
39 | + 'term_taxonomy_id' => new EE_Foreign_Key_Int_Field( |
|
40 | + 'term_taxonomy_id', |
|
41 | + esc_html__( |
|
42 | + 'Term (in context of a taxonomy) ID', |
|
43 | + 'event_espresso' |
|
44 | + ), |
|
45 | + false, |
|
46 | + 0, |
|
47 | + 'Term_Taxonomy' |
|
48 | + ), |
|
49 | + 'term_order' => new EE_Integer_Field( |
|
50 | + 'term_order', |
|
51 | + esc_html__('Term Order', 'event_espresso'), |
|
52 | + false, |
|
53 | + 0 |
|
54 | + ), |
|
55 | + ), |
|
56 | + ); |
|
57 | + $this->_model_relations = array( |
|
58 | + 'Term_Taxonomy' => new EE_Belongs_To_Relation(), |
|
59 | + ); |
|
60 | + foreach ($models_this_can_attach_to as $model_name) { |
|
61 | + $this->_model_relations[ $model_name ] = new EE_Belongs_To_Relation(); |
|
62 | + } |
|
63 | + $this->_wp_core_model = true; |
|
64 | + $this->_indexes = array( |
|
65 | + 'PRIMARY' => new EE_Primary_Key_Index(array('object_id', 'term_taxonomy_id')), |
|
66 | + ); |
|
67 | + $path_to_event_model = 'Event'; |
|
68 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public( |
|
69 | + $path_to_event_model |
|
70 | + ); |
|
71 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = |
|
72 | + new EE_Restriction_Generator_Event_Related_Protected( |
|
73 | + $path_to_event_model |
|
74 | + ); |
|
75 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected( |
|
76 | + $path_to_event_model |
|
77 | + ); |
|
78 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = |
|
79 | + new EE_Restriction_Generator_Event_Related_Protected( |
|
80 | + $path_to_event_model, |
|
81 | + EEM_Base::caps_edit |
|
82 | + ); |
|
83 | + $path_to_tax_model = 'Term_Taxonomy.'; |
|
84 | + // add cap restrictions for editing term relations to the "ee_assign_*" |
|
85 | + // and for deleting term relations too |
|
86 | + $cap_contexts_affected = array(EEM_Base::caps_edit, EEM_Base::caps_delete); |
|
87 | + foreach ($cap_contexts_affected as $cap_context_affected) { |
|
88 | + $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_event_category'] = |
|
89 | + new EE_Default_Where_Conditions( |
|
90 | + array( |
|
91 | + $path_to_tax_model . 'taxonomy*ee_assign_event_category' => array( |
|
92 | + '!=', |
|
93 | + 'espresso_event_categories', |
|
94 | + ), |
|
95 | + ) |
|
96 | + ); |
|
97 | + $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_venue_category'] = |
|
98 | + new EE_Default_Where_Conditions( |
|
99 | + array( |
|
100 | + $path_to_tax_model . 'taxonomy*ee_assign_venue_category' => array( |
|
101 | + '!=', |
|
102 | + 'espresso_venue_categories', |
|
103 | + ), |
|
104 | + ) |
|
105 | + ); |
|
106 | + $this->_cap_restrictions[ $cap_context_affected ]['ee_assign_event_type'] = new EE_Default_Where_Conditions( |
|
107 | + array( |
|
108 | + $path_to_tax_model . 'taxonomy*ee_assign_event_type' => array('!=', 'espresso_event_type'), |
|
109 | + ) |
|
110 | + ); |
|
111 | + } |
|
112 | + parent::__construct($timezone); |
|
113 | + add_filter( |
|
114 | + 'FHEE__Read__create_model_query_params', |
|
115 | + array('EEM_Term_Relationship', 'rest_api_query_params'), |
|
116 | + 10, |
|
117 | + 3 |
|
118 | + ); |
|
119 | + } |
|
120 | + |
|
121 | + |
|
122 | + /** |
|
123 | + * Makes sure all term-taxonomy counts are correct |
|
124 | + * |
|
125 | + * @param int $term_taxonomy_id the id of the term taxonomy to update. If NULL, updates ALL |
|
126 | + * @global wpdb $wpdb |
|
127 | + * @return int the number of rows affected |
|
128 | + * @throws EE_Error |
|
129 | + */ |
|
130 | + public function update_term_taxonomy_counts($term_taxonomy_id = null) |
|
131 | + { |
|
132 | + // because this uses a subquery and sometimes assigning to column to be another column's |
|
133 | + // value, we just write the SQL directly. |
|
134 | + global $wpdb; |
|
135 | + |
|
136 | + $query = " |
|
137 | 137 | UPDATE {$wpdb->term_taxonomy} AS tt |
138 | 138 | SET count = ( |
139 | 139 | select count(*) as proper_count from {$wpdb->term_relationships} AS tr |
140 | 140 | WHERE tt.term_taxonomy_id = tr.term_taxonomy_id |
141 | 141 | )"; |
142 | 142 | |
143 | - if ($term_taxonomy_id) { |
|
144 | - $query .= ' WHERE tt.term_taxonomy_id = %d'; |
|
145 | - $query = $wpdb->prepare( |
|
146 | - $query, |
|
147 | - $term_taxonomy_id |
|
148 | - ); |
|
149 | - } |
|
150 | - $rows_affected = $this->_do_wpdb_query( |
|
151 | - 'query', |
|
152 | - array( |
|
153 | - $query, |
|
154 | - ) |
|
155 | - ); |
|
156 | - return $rows_affected; |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * Overrides the parent to also make sure term-taxonomy counts are up-to-date after |
|
163 | - * inserting |
|
164 | - * |
|
165 | - * @param array $field_n_values @see EEM_Base::insert |
|
166 | - * @return boolean |
|
167 | - */ |
|
168 | - public function insert($field_n_values) |
|
169 | - { |
|
170 | - $return = parent::insert($field_n_values); |
|
171 | - if (isset($field_n_values['term_taxonomy_id'])) { |
|
172 | - $this->update_term_taxonomy_counts($field_n_values['term_taxonomy_id']); |
|
173 | - } |
|
174 | - return $return; |
|
175 | - } |
|
176 | - |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * Overrides parent so that after an update, we also check the term_taxonomy_counts are |
|
181 | - * all ok |
|
182 | - * |
|
183 | - * @param array $fields_n_values see EEM_Base::update |
|
184 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
185 | - * @param boolean $keep_model_objs_in_sync if TRUE, makes sure we ALSO update model objects |
|
186 | - * in this model's entity map according to $fields_n_values that match |
|
187 | - * $query_params. This obviously has some overhead, so you can disable it |
|
188 | - * by setting this to FALSE, but be aware that model objects being used |
|
189 | - * could get out-of-sync with the database |
|
190 | - * @return int |
|
191 | - */ |
|
192 | - public function update($fields_n_values, $query_params, $keep_model_objs_in_sync = true) |
|
193 | - { |
|
194 | - $count = parent::update($fields_n_values, $query_params, $keep_model_objs_in_sync); |
|
195 | - if ($count) { |
|
196 | - $this->update_term_taxonomy_counts(); |
|
197 | - } |
|
198 | - return $count; |
|
199 | - } |
|
200 | - |
|
201 | - |
|
202 | - |
|
203 | - /** |
|
204 | - * Overrides parent so that after running this, we also double-check |
|
205 | - * the term taxonomy counts are up-to-date |
|
206 | - * |
|
207 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
208 | - * @param boolean $allow_blocking |
|
209 | - * @return int @see EEM_Base::delete |
|
210 | - */ |
|
211 | - public function delete($query_params, $allow_blocking = true) |
|
212 | - { |
|
213 | - $count = parent::delete($query_params, $allow_blocking); |
|
214 | - if ($count) { |
|
215 | - $this->update_term_taxonomy_counts(); |
|
216 | - } |
|
217 | - return $count; |
|
218 | - } |
|
219 | - |
|
220 | - |
|
221 | - |
|
222 | - /** |
|
223 | - * Makes sure that during REST API queries, we only return term relationships |
|
224 | - * for term taxonomies which should be shown in the rest api |
|
225 | - * |
|
226 | - * @param array $model_query_params |
|
227 | - * @param array $querystring_query_params |
|
228 | - * @param EEM_Base $model |
|
229 | - * @return array |
|
230 | - */ |
|
231 | - public static function rest_api_query_params($model_query_params, $querystring_query_params, $model) |
|
232 | - { |
|
233 | - if ($model === EEM_Term_Relationship::instance()) { |
|
234 | - $taxonomies = get_taxonomies(array('show_in_rest' => true)); |
|
235 | - if (! empty($taxonomies)) { |
|
236 | - $model_query_params[0]['Term_Taxonomy.taxonomy'] = array('IN', $taxonomies); |
|
237 | - } |
|
238 | - } |
|
239 | - return $model_query_params; |
|
240 | - } |
|
143 | + if ($term_taxonomy_id) { |
|
144 | + $query .= ' WHERE tt.term_taxonomy_id = %d'; |
|
145 | + $query = $wpdb->prepare( |
|
146 | + $query, |
|
147 | + $term_taxonomy_id |
|
148 | + ); |
|
149 | + } |
|
150 | + $rows_affected = $this->_do_wpdb_query( |
|
151 | + 'query', |
|
152 | + array( |
|
153 | + $query, |
|
154 | + ) |
|
155 | + ); |
|
156 | + return $rows_affected; |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * Overrides the parent to also make sure term-taxonomy counts are up-to-date after |
|
163 | + * inserting |
|
164 | + * |
|
165 | + * @param array $field_n_values @see EEM_Base::insert |
|
166 | + * @return boolean |
|
167 | + */ |
|
168 | + public function insert($field_n_values) |
|
169 | + { |
|
170 | + $return = parent::insert($field_n_values); |
|
171 | + if (isset($field_n_values['term_taxonomy_id'])) { |
|
172 | + $this->update_term_taxonomy_counts($field_n_values['term_taxonomy_id']); |
|
173 | + } |
|
174 | + return $return; |
|
175 | + } |
|
176 | + |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * Overrides parent so that after an update, we also check the term_taxonomy_counts are |
|
181 | + * all ok |
|
182 | + * |
|
183 | + * @param array $fields_n_values see EEM_Base::update |
|
184 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
185 | + * @param boolean $keep_model_objs_in_sync if TRUE, makes sure we ALSO update model objects |
|
186 | + * in this model's entity map according to $fields_n_values that match |
|
187 | + * $query_params. This obviously has some overhead, so you can disable it |
|
188 | + * by setting this to FALSE, but be aware that model objects being used |
|
189 | + * could get out-of-sync with the database |
|
190 | + * @return int |
|
191 | + */ |
|
192 | + public function update($fields_n_values, $query_params, $keep_model_objs_in_sync = true) |
|
193 | + { |
|
194 | + $count = parent::update($fields_n_values, $query_params, $keep_model_objs_in_sync); |
|
195 | + if ($count) { |
|
196 | + $this->update_term_taxonomy_counts(); |
|
197 | + } |
|
198 | + return $count; |
|
199 | + } |
|
200 | + |
|
201 | + |
|
202 | + |
|
203 | + /** |
|
204 | + * Overrides parent so that after running this, we also double-check |
|
205 | + * the term taxonomy counts are up-to-date |
|
206 | + * |
|
207 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
208 | + * @param boolean $allow_blocking |
|
209 | + * @return int @see EEM_Base::delete |
|
210 | + */ |
|
211 | + public function delete($query_params, $allow_blocking = true) |
|
212 | + { |
|
213 | + $count = parent::delete($query_params, $allow_blocking); |
|
214 | + if ($count) { |
|
215 | + $this->update_term_taxonomy_counts(); |
|
216 | + } |
|
217 | + return $count; |
|
218 | + } |
|
219 | + |
|
220 | + |
|
221 | + |
|
222 | + /** |
|
223 | + * Makes sure that during REST API queries, we only return term relationships |
|
224 | + * for term taxonomies which should be shown in the rest api |
|
225 | + * |
|
226 | + * @param array $model_query_params |
|
227 | + * @param array $querystring_query_params |
|
228 | + * @param EEM_Base $model |
|
229 | + * @return array |
|
230 | + */ |
|
231 | + public static function rest_api_query_params($model_query_params, $querystring_query_params, $model) |
|
232 | + { |
|
233 | + if ($model === EEM_Term_Relationship::instance()) { |
|
234 | + $taxonomies = get_taxonomies(array('show_in_rest' => true)); |
|
235 | + if (! empty($taxonomies)) { |
|
236 | + $model_query_params[0]['Term_Taxonomy.taxonomy'] = array('IN', $taxonomies); |
|
237 | + } |
|
238 | + } |
|
239 | + return $model_query_params; |
|
240 | + } |
|
241 | 241 | } |
@@ -32,10 +32,10 @@ |
||
32 | 32 | ); |
33 | 33 | // this model is generally available for reading |
34 | 34 | $path_to_event = 'Event'; |
35 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event); |
|
36 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
37 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
38 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit); |
|
35 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public($path_to_event); |
|
36 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
37 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
38 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit); |
|
39 | 39 | $this->model_chain_to_password = $path_to_event; |
40 | 40 | parent::__construct($timezone); |
41 | 41 | } |
@@ -8,36 +8,36 @@ |
||
8 | 8 | */ |
9 | 9 | class EEM_Event_Venue extends EEM_Base |
10 | 10 | { |
11 | - // private instance of the Attendee object |
|
12 | - protected static $_instance = null; |
|
11 | + // private instance of the Attendee object |
|
12 | + protected static $_instance = null; |
|
13 | 13 | |
14 | - protected function __construct($timezone = null) |
|
15 | - { |
|
16 | - $this->singular_item = esc_html__('Event to Question Group Link', 'event_espresso'); |
|
17 | - $this->plural_item = esc_html__('Event to Question Group Links', 'event_espresso'); |
|
18 | - $this->_tables = array( |
|
19 | - 'Event_Venue' => new EE_Primary_Table('esp_event_venue', 'EVV_ID') |
|
20 | - ); |
|
21 | - $this->_fields = array( |
|
22 | - 'Event_Venue' => array( |
|
23 | - 'EVV_ID' => new EE_Primary_Key_Int_Field('EVV_ID', esc_html__('Event to Venue Link ID', 'event_espresso')), |
|
24 | - 'EVT_ID' => new EE_Foreign_Key_Int_Field('EVT_ID', esc_html__('Event ID', 'event_espresso'), false, 0, 'Event'), |
|
25 | - 'VNU_ID' => new EE_Foreign_Key_Int_Field('VNU_ID', esc_html__('Venue ID', 'event_espresso'), false, 0, 'Venue'), |
|
26 | - 'EVV_primary' => new EE_Boolean_Field('EVV_primary', esc_html__("Flag indicating venue is primary one for event", "event_espresso"), false, true) |
|
14 | + protected function __construct($timezone = null) |
|
15 | + { |
|
16 | + $this->singular_item = esc_html__('Event to Question Group Link', 'event_espresso'); |
|
17 | + $this->plural_item = esc_html__('Event to Question Group Links', 'event_espresso'); |
|
18 | + $this->_tables = array( |
|
19 | + 'Event_Venue' => new EE_Primary_Table('esp_event_venue', 'EVV_ID') |
|
20 | + ); |
|
21 | + $this->_fields = array( |
|
22 | + 'Event_Venue' => array( |
|
23 | + 'EVV_ID' => new EE_Primary_Key_Int_Field('EVV_ID', esc_html__('Event to Venue Link ID', 'event_espresso')), |
|
24 | + 'EVT_ID' => new EE_Foreign_Key_Int_Field('EVT_ID', esc_html__('Event ID', 'event_espresso'), false, 0, 'Event'), |
|
25 | + 'VNU_ID' => new EE_Foreign_Key_Int_Field('VNU_ID', esc_html__('Venue ID', 'event_espresso'), false, 0, 'Venue'), |
|
26 | + 'EVV_primary' => new EE_Boolean_Field('EVV_primary', esc_html__("Flag indicating venue is primary one for event", "event_espresso"), false, true) |
|
27 | 27 | |
28 | - ) |
|
29 | - ); |
|
30 | - $this->_model_relations = array( |
|
31 | - 'Event' => new EE_Belongs_To_Relation(), |
|
32 | - 'Venue' => new EE_Belongs_To_Relation() |
|
33 | - ); |
|
34 | - // this model is generally available for reading |
|
35 | - $path_to_event = 'Event'; |
|
36 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event); |
|
37 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
38 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
39 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit); |
|
40 | - $this->model_chain_to_password = $path_to_event; |
|
41 | - parent::__construct($timezone); |
|
42 | - } |
|
28 | + ) |
|
29 | + ); |
|
30 | + $this->_model_relations = array( |
|
31 | + 'Event' => new EE_Belongs_To_Relation(), |
|
32 | + 'Venue' => new EE_Belongs_To_Relation() |
|
33 | + ); |
|
34 | + // this model is generally available for reading |
|
35 | + $path_to_event = 'Event'; |
|
36 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event); |
|
37 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
38 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
39 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit); |
|
40 | + $this->model_chain_to_password = $path_to_event; |
|
41 | + parent::__construct($timezone); |
|
42 | + } |
|
43 | 43 | } |
@@ -12,45 +12,45 @@ |
||
12 | 12 | */ |
13 | 13 | class EE_Password_Field extends EE_Text_Field_Base |
14 | 14 | { |
15 | - /** |
|
16 | - * @var array |
|
17 | - */ |
|
18 | - protected $protected_fields; |
|
15 | + /** |
|
16 | + * @var array |
|
17 | + */ |
|
18 | + protected $protected_fields; |
|
19 | 19 | |
20 | - /** |
|
21 | - * EE_Password_Field constructor. |
|
22 | - * @param $table_column |
|
23 | - * @param $nicename |
|
24 | - * @param $nullable |
|
25 | - * @param null $default_value |
|
26 | - * @param array $protected_fields |
|
27 | - */ |
|
28 | - public function __construct($table_column, $nicename, $nullable, $default_value = null, $protected_fields = array()) |
|
29 | - { |
|
30 | - $this->protected_fields = $protected_fields; |
|
31 | - parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
32 | - } |
|
20 | + /** |
|
21 | + * EE_Password_Field constructor. |
|
22 | + * @param $table_column |
|
23 | + * @param $nicename |
|
24 | + * @param $nullable |
|
25 | + * @param null $default_value |
|
26 | + * @param array $protected_fields |
|
27 | + */ |
|
28 | + public function __construct($table_column, $nicename, $nullable, $default_value = null, $protected_fields = array()) |
|
29 | + { |
|
30 | + $this->protected_fields = $protected_fields; |
|
31 | + parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
32 | + } |
|
33 | 33 | |
34 | - /** |
|
35 | - * Returns the names of the fields on this model that this password field should protect |
|
36 | - * @since 4.9.74.p |
|
37 | - * @return array |
|
38 | - */ |
|
39 | - public function protectedFields() |
|
40 | - { |
|
41 | - return $this->protected_fields; |
|
42 | - } |
|
34 | + /** |
|
35 | + * Returns the names of the fields on this model that this password field should protect |
|
36 | + * @since 4.9.74.p |
|
37 | + * @return array |
|
38 | + */ |
|
39 | + public function protectedFields() |
|
40 | + { |
|
41 | + return $this->protected_fields; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * Returns whether or not the specified field is protected by this model |
|
46 | - * @since 4.9.74.p |
|
47 | - * @param $field_name |
|
48 | - * @return bool |
|
49 | - */ |
|
50 | - public function fieldIsProtected($field_name) |
|
51 | - { |
|
52 | - return in_array($field_name, $this->protectedFields(), true); |
|
53 | - } |
|
44 | + /** |
|
45 | + * Returns whether or not the specified field is protected by this model |
|
46 | + * @since 4.9.74.p |
|
47 | + * @param $field_name |
|
48 | + * @return bool |
|
49 | + */ |
|
50 | + public function fieldIsProtected($field_name) |
|
51 | + { |
|
52 | + return in_array($field_name, $this->protectedFields(), true); |
|
53 | + } |
|
54 | 54 | } |
55 | 55 | // End of file EE_Password_Field.php |
56 | 56 | // Location: ${NAMESPACE}/EE_Password_Field.php |
@@ -57,7 +57,7 @@ |
||
57 | 57 | * check whether count of tickets is approaching the potential |
58 | 58 | * limits for the server. |
59 | 59 | */ |
60 | - if (! empty($data['input_count'])) { |
|
60 | + if ( ! empty($data['input_count'])) { |
|
61 | 61 | $response['max_input_vars_check'] = $this->environment->max_input_vars_limit_check( |
62 | 62 | $data['input_count'] |
63 | 63 | ); |
@@ -15,52 +15,52 @@ |
||
15 | 15 | */ |
16 | 16 | class EventEditorHeartbeat |
17 | 17 | { |
18 | - /** |
|
19 | - * @var Domain $domain |
|
20 | - */ |
|
21 | - protected $domain; |
|
18 | + /** |
|
19 | + * @var Domain $domain |
|
20 | + */ |
|
21 | + protected $domain; |
|
22 | 22 | |
23 | - /** |
|
24 | - * @var EE_Environment_Config $environment |
|
25 | - */ |
|
26 | - protected $environment; |
|
23 | + /** |
|
24 | + * @var EE_Environment_Config $environment |
|
25 | + */ |
|
26 | + protected $environment; |
|
27 | 27 | |
28 | 28 | |
29 | - /** |
|
30 | - * EventEditorHeartbeat constructor. |
|
31 | - * |
|
32 | - * @param Domain $domain |
|
33 | - * @param EE_Environment_Config $environment |
|
34 | - */ |
|
35 | - public function __construct(Domain $domain, EE_Environment_Config $environment) |
|
36 | - { |
|
37 | - $this->domain = $domain; |
|
38 | - $this->environment = $environment; |
|
39 | - if ($this->domain->isCaffeinated()) { |
|
40 | - add_filter('heartbeat_received', array($this, 'heartbeatResponse'), 10, 2); |
|
41 | - } |
|
42 | - } |
|
29 | + /** |
|
30 | + * EventEditorHeartbeat constructor. |
|
31 | + * |
|
32 | + * @param Domain $domain |
|
33 | + * @param EE_Environment_Config $environment |
|
34 | + */ |
|
35 | + public function __construct(Domain $domain, EE_Environment_Config $environment) |
|
36 | + { |
|
37 | + $this->domain = $domain; |
|
38 | + $this->environment = $environment; |
|
39 | + if ($this->domain->isCaffeinated()) { |
|
40 | + add_filter('heartbeat_received', array($this, 'heartbeatResponse'), 10, 2); |
|
41 | + } |
|
42 | + } |
|
43 | 43 | |
44 | 44 | |
45 | - /** |
|
46 | - * This will be used to listen for any heartbeat data packages coming via the WordPress heartbeat API and handle |
|
47 | - * accordingly. |
|
48 | - * |
|
49 | - * @param array $response The existing heartbeat response array. |
|
50 | - * @param array $data The incoming data package. |
|
51 | - * @return array possibly appended response. |
|
52 | - */ |
|
53 | - public function heartbeatResponse($response, $data) |
|
54 | - { |
|
55 | - /** |
|
56 | - * check whether count of tickets is approaching the potential |
|
57 | - * limits for the server. |
|
58 | - */ |
|
59 | - if (! empty($data['input_count'])) { |
|
60 | - $response['max_input_vars_check'] = $this->environment->max_input_vars_limit_check( |
|
61 | - $data['input_count'] |
|
62 | - ); |
|
63 | - } |
|
64 | - return $response; |
|
65 | - } |
|
45 | + /** |
|
46 | + * This will be used to listen for any heartbeat data packages coming via the WordPress heartbeat API and handle |
|
47 | + * accordingly. |
|
48 | + * |
|
49 | + * @param array $response The existing heartbeat response array. |
|
50 | + * @param array $data The incoming data package. |
|
51 | + * @return array possibly appended response. |
|
52 | + */ |
|
53 | + public function heartbeatResponse($response, $data) |
|
54 | + { |
|
55 | + /** |
|
56 | + * check whether count of tickets is approaching the potential |
|
57 | + * limits for the server. |
|
58 | + */ |
|
59 | + if (! empty($data['input_count'])) { |
|
60 | + $response['max_input_vars_check'] = $this->environment->max_input_vars_limit_check( |
|
61 | + $data['input_count'] |
|
62 | + ); |
|
63 | + } |
|
64 | + return $response; |
|
65 | + } |
|
66 | 66 | } |
@@ -19,53 +19,53 @@ |
||
19 | 19 | */ |
20 | 20 | class SettingsForm extends PayPalSettingsForm |
21 | 21 | { |
22 | - /** |
|
23 | - * SettingsForm constructor. |
|
24 | - * |
|
25 | - * @param array $options_array |
|
26 | - * @param string $help_tab_link |
|
27 | - * @throws InvalidDataTypeException |
|
28 | - * @throws InvalidInterfaceException |
|
29 | - * @throws InvalidArgumentException |
|
30 | - */ |
|
31 | - public function __construct(array $options_array = array(), $help_tab_link = '') |
|
32 | - { |
|
33 | - $options_array = array_replace_recursive( |
|
34 | - array( |
|
35 | - 'extra_meta_inputs' => array( |
|
36 | - 'request_shipping_addr' => new EE_Yes_No_Input( |
|
37 | - array( |
|
38 | - 'html_label_text' => sprintf( |
|
39 | - esc_html__('Request Shipping Address %s', 'event_espresso'), |
|
40 | - $help_tab_link |
|
41 | - ), |
|
42 | - 'html_help_text' => esc_html__( |
|
43 | - // @codingStandardsIgnoreStart |
|
44 | - 'If set to "Yes", then a shipping address will be requested on the PayPal checkout page.', |
|
45 | - // @codingStandardsIgnoreEnd |
|
46 | - 'event_espresso' |
|
47 | - ), |
|
48 | - 'required' => true, |
|
49 | - 'default' => false, |
|
50 | - ) |
|
51 | - ), |
|
52 | - 'image_url' => new EE_Admin_File_Uploader_Input( |
|
53 | - array( |
|
54 | - 'html_label_text' => sprintf( |
|
55 | - esc_html__('Image URL %s', 'event_espresso'), |
|
56 | - $help_tab_link |
|
57 | - ), |
|
58 | - 'html_help_text' => esc_html__( |
|
59 | - 'Used for your business/personal logo on the PayPal page', |
|
60 | - 'event_espresso' |
|
61 | - ), |
|
62 | - 'required' => false, |
|
63 | - ) |
|
64 | - ), |
|
65 | - ) |
|
66 | - ), |
|
67 | - $options_array |
|
68 | - ); |
|
69 | - parent::__construct($options_array, $help_tab_link); |
|
70 | - } |
|
22 | + /** |
|
23 | + * SettingsForm constructor. |
|
24 | + * |
|
25 | + * @param array $options_array |
|
26 | + * @param string $help_tab_link |
|
27 | + * @throws InvalidDataTypeException |
|
28 | + * @throws InvalidInterfaceException |
|
29 | + * @throws InvalidArgumentException |
|
30 | + */ |
|
31 | + public function __construct(array $options_array = array(), $help_tab_link = '') |
|
32 | + { |
|
33 | + $options_array = array_replace_recursive( |
|
34 | + array( |
|
35 | + 'extra_meta_inputs' => array( |
|
36 | + 'request_shipping_addr' => new EE_Yes_No_Input( |
|
37 | + array( |
|
38 | + 'html_label_text' => sprintf( |
|
39 | + esc_html__('Request Shipping Address %s', 'event_espresso'), |
|
40 | + $help_tab_link |
|
41 | + ), |
|
42 | + 'html_help_text' => esc_html__( |
|
43 | + // @codingStandardsIgnoreStart |
|
44 | + 'If set to "Yes", then a shipping address will be requested on the PayPal checkout page.', |
|
45 | + // @codingStandardsIgnoreEnd |
|
46 | + 'event_espresso' |
|
47 | + ), |
|
48 | + 'required' => true, |
|
49 | + 'default' => false, |
|
50 | + ) |
|
51 | + ), |
|
52 | + 'image_url' => new EE_Admin_File_Uploader_Input( |
|
53 | + array( |
|
54 | + 'html_label_text' => sprintf( |
|
55 | + esc_html__('Image URL %s', 'event_espresso'), |
|
56 | + $help_tab_link |
|
57 | + ), |
|
58 | + 'html_help_text' => esc_html__( |
|
59 | + 'Used for your business/personal logo on the PayPal page', |
|
60 | + 'event_espresso' |
|
61 | + ), |
|
62 | + 'required' => false, |
|
63 | + ) |
|
64 | + ), |
|
65 | + ) |
|
66 | + ), |
|
67 | + $options_array |
|
68 | + ); |
|
69 | + parent::__construct($options_array, $help_tab_link); |
|
70 | + } |
|
71 | 71 | } |
@@ -324,8 +324,8 @@ discard block |
||
324 | 324 | ); |
325 | 325 | $query = $wpdb->prepare( |
326 | 326 | 'DELETE li |
327 | - FROM ' . $this->table() . ' li |
|
328 | - LEFT JOIN ' . EEM_Transaction::instance()->table() . ' t ON li.TXN_ID = t.TXN_ID |
|
327 | + FROM ' . $this->table().' li |
|
328 | + LEFT JOIN ' . EEM_Transaction::instance()->table().' t ON li.TXN_ID = t.TXN_ID |
|
329 | 329 | WHERE t.TXN_ID IS NULL AND li.LIN_timestamp < %s', |
330 | 330 | // use GMT time because that's what TXN_timestamps are in |
331 | 331 | date('Y-m-d H:i:s', time() - $time_to_leave_alone) |
@@ -598,7 +598,7 @@ discard block |
||
598 | 598 | */ |
599 | 599 | public function getTicketLineItemsForExpiredCarts($timestamp = 0) |
600 | 600 | { |
601 | - if (! absint($timestamp)) { |
|
601 | + if ( ! absint($timestamp)) { |
|
602 | 602 | /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
603 | 603 | $session_lifespan = LoaderFactory::getLoader()->getShared( |
604 | 604 | 'EventEspresso\core\domain\values\session\SessionLifespan' |
@@ -27,616 +27,616 @@ |
||
27 | 27 | */ |
28 | 28 | class EEM_Line_Item extends EEM_Base |
29 | 29 | { |
30 | - /** |
|
31 | - * Tax sub-total is just the total of all the taxes, which should be children |
|
32 | - * of this line item. There should only ever be one tax sub-total, and it should |
|
33 | - * be a direct child of. Its quantity and LIN_unit_price = 1. |
|
34 | - */ |
|
35 | - const type_tax_sub_total = 'tax-sub-total'; |
|
36 | - |
|
37 | - /** |
|
38 | - * Tax line items indicate a tax applied to all the taxable line items. |
|
39 | - * Should not have any children line items. Its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal |
|
40 | - * (eg 10% tax = 10, not 0.1). Its LIN_total = LIN_unit_price * pre-tax-total. Quantity = 1. |
|
41 | - */ |
|
42 | - const type_tax = 'tax'; |
|
43 | - |
|
44 | - /** |
|
45 | - * Indicating individual items purchased, or discounts or surcharges. |
|
46 | - * The sum of all the regular line items plus the tax items should equal the grand total. |
|
47 | - * Possible children are sub-line-items and cancellations. |
|
48 | - * For flat items, LIN_unit_price * LIN_quantity = LIN_total. Its LIN_total is the sum of all the children |
|
49 | - * LIN_totals. Its LIN_percent = 0. |
|
50 | - * For percent items, its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal (eg 10% = 10, not 0.1). |
|
51 | - * Its LIN_total is LIN_percent / 100 * sum of lower-priority sibling line items. Quantity = 1. |
|
52 | - */ |
|
53 | - const type_line_item = 'line-item'; |
|
54 | - |
|
55 | - /** |
|
56 | - * Line item indicating all the factors that make a single line item. |
|
57 | - * Sub-line items should have NO children line items. |
|
58 | - * For flat sub-items, their quantity should match their parent item, their LIN_unit_price should be this sub-item's |
|
59 | - * contribution towards the price of ONE of their parent items, and its LIN_total should be |
|
60 | - * = LIN_quantity * LIN_unit_price. Its LIN_percent = 0. |
|
61 | - * For percent sub-items, the quantity should be 1, LIN_unit_price should be 0, and its LIN_total should |
|
62 | - * = LIN_percent / 100 * sum of lower-priority sibling line items.. |
|
63 | - */ |
|
64 | - const type_sub_line_item = 'sub-item'; |
|
65 | - |
|
66 | - /** |
|
67 | - * SubTax line items indicate a tax that is only applied to the pre-tax total of their parent line item. |
|
68 | - * Should not have any children line items. Its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal |
|
69 | - * (eg 10% tax = 10, not 0.1). Its LIN_total = LIN_unit_price * pre-tax-total. Quantity = 1. |
|
70 | - */ |
|
71 | - const type_sub_tax = 'sub-tax'; |
|
72 | - |
|
73 | - /** |
|
74 | - * Line item indicating a sub-total (eg total for an event, or pre-tax subtotal). |
|
75 | - * Direct children should be event subtotals. |
|
76 | - * Should have quantity of 1, and a LIN_total and LIN_unit_price of the sum of all its sub-items' LIN_totals. |
|
77 | - */ |
|
78 | - const type_sub_total = 'sub-total'; |
|
79 | - |
|
80 | - /** |
|
81 | - * Line item for the grand total of an order. |
|
82 | - * Its direct children should be tax subtotals and (pre-tax) subtotals, |
|
83 | - * and possibly a regular line item indicating a transaction-wide discount/surcharge. |
|
84 | - * Should have a quantity of 1, a LIN_total and LIN_unit_price of the entire order's amount. |
|
85 | - */ |
|
86 | - const type_total = 'total'; |
|
87 | - |
|
88 | - /** |
|
89 | - * When a line item is cancelled, a sub-line-item of type 'cancellation' |
|
90 | - * should be created, indicating the quantity that were cancelled |
|
91 | - * (because a line item could have a quantity of 1, and its cancellation item |
|
92 | - * could be for 3, indicating that originally 4 were purchased, but 3 have been |
|
93 | - * cancelled, and only one remains). |
|
94 | - * When items are refunded, a cancellation line item should be made, which points |
|
95 | - * to teh payment model object which actually refunded the payment. |
|
96 | - * Cancellations should NOT have any children line items; the should NOT affect |
|
97 | - * any calculations, and are only meant as a record that cancellations have occurred. |
|
98 | - * Their LIN_percent should be 0. |
|
99 | - */ |
|
100 | - const type_cancellation = 'cancellation'; |
|
101 | - |
|
102 | - // various line item object types |
|
103 | - const OBJ_TYPE_EVENT = 'Event'; |
|
104 | - |
|
105 | - const OBJ_TYPE_PRICE = 'Price'; |
|
106 | - |
|
107 | - const OBJ_TYPE_PROMOTION = 'Promotion'; |
|
108 | - |
|
109 | - const OBJ_TYPE_TICKET = 'Ticket'; |
|
110 | - |
|
111 | - const OBJ_TYPE_TRANSACTION = 'Transaction'; |
|
112 | - |
|
113 | - /** |
|
114 | - * @var EEM_Line_Item $_instance |
|
115 | - */ |
|
116 | - protected static $_instance; |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * private constructor to prevent direct creation |
|
121 | - * |
|
122 | - * @Constructor |
|
123 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings |
|
124 | - * (and any incoming timezone data that gets saved). |
|
125 | - * Note this just sends the timezone info to the date time model field objects. |
|
126 | - * Default is NULL |
|
127 | - * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
128 | - * @throws EE_Error |
|
129 | - * @throws InvalidArgumentException |
|
130 | - */ |
|
131 | - protected function __construct($timezone) |
|
132 | - { |
|
133 | - $this->singular_item = esc_html__('Line Item', 'event_espresso'); |
|
134 | - $this->plural_item = esc_html__('Line Items', 'event_espresso'); |
|
135 | - |
|
136 | - $this->_tables = array( |
|
137 | - 'Line_Item' => new EE_Primary_Table('esp_line_item', 'LIN_ID'), |
|
138 | - ); |
|
139 | - $line_items_can_be_for = apply_filters( |
|
140 | - 'FHEE__EEM_Line_Item__line_items_can_be_for', |
|
141 | - array('Ticket', 'Price', 'Event') |
|
142 | - ); |
|
143 | - $this->_fields = array( |
|
144 | - 'Line_Item' => array( |
|
145 | - 'LIN_ID' => new EE_Primary_Key_Int_Field( |
|
146 | - 'LIN_ID', |
|
147 | - esc_html__('ID', 'event_espresso') |
|
148 | - ), |
|
149 | - 'LIN_code' => new EE_Slug_Field( |
|
150 | - 'LIN_code', |
|
151 | - esc_html__('Code for index into Cart', 'event_espresso'), |
|
152 | - true |
|
153 | - ), |
|
154 | - 'TXN_ID' => new EE_Foreign_Key_Int_Field( |
|
155 | - 'TXN_ID', |
|
156 | - esc_html__('Transaction ID', 'event_espresso'), |
|
157 | - true, |
|
158 | - null, |
|
159 | - 'Transaction' |
|
160 | - ), |
|
161 | - 'LIN_name' => new EE_Full_HTML_Field( |
|
162 | - 'LIN_name', |
|
163 | - esc_html__('Line Item Name', 'event_espresso'), |
|
164 | - false, |
|
165 | - '' |
|
166 | - ), |
|
167 | - 'LIN_desc' => new EE_Full_HTML_Field( |
|
168 | - 'LIN_desc', |
|
169 | - esc_html__('Line Item Description', 'event_espresso'), |
|
170 | - true |
|
171 | - ), |
|
172 | - 'LIN_unit_price' => new EE_Money_Field( |
|
173 | - 'LIN_unit_price', |
|
174 | - esc_html__('Unit Price', 'event_espresso'), |
|
175 | - false, |
|
176 | - 0 |
|
177 | - ), |
|
178 | - 'LIN_percent' => new EE_Float_Field( |
|
179 | - 'LIN_percent', |
|
180 | - esc_html__('Percent', 'event_espresso'), |
|
181 | - false, |
|
182 | - 0 |
|
183 | - ), |
|
184 | - 'LIN_is_taxable' => new EE_Boolean_Field( |
|
185 | - 'LIN_is_taxable', |
|
186 | - esc_html__('Taxable', 'event_espresso'), |
|
187 | - false, |
|
188 | - false |
|
189 | - ), |
|
190 | - 'LIN_order' => new EE_Integer_Field( |
|
191 | - 'LIN_order', |
|
192 | - esc_html__('Order of Application towards total of parent', 'event_espresso'), |
|
193 | - false, |
|
194 | - 1 |
|
195 | - ), |
|
196 | - 'LIN_total' => new EE_Money_Field( |
|
197 | - 'LIN_total', |
|
198 | - esc_html__('Total (unit price x quantity) after taxes', 'event_espresso'), |
|
199 | - false, |
|
200 | - 0 |
|
201 | - ), |
|
202 | - 'LIN_pretax' => new EE_Money_Field( |
|
203 | - 'LIN_pretax', |
|
204 | - esc_html__('Total (unit price x quantity) before taxes', 'event_espresso'), |
|
205 | - false, |
|
206 | - 0 |
|
207 | - ), |
|
208 | - 'LIN_quantity' => new EE_Integer_Field( |
|
209 | - 'LIN_quantity', |
|
210 | - esc_html__('Quantity', 'event_espresso'), |
|
211 | - true, |
|
212 | - 1 |
|
213 | - ), |
|
214 | - 'LIN_parent' => new EE_Integer_Field( |
|
215 | - 'LIN_parent', |
|
216 | - esc_html__("Parent ID (this item goes towards that Line Item's total)", 'event_espresso'), |
|
217 | - true, |
|
218 | - null |
|
219 | - ), |
|
220 | - 'LIN_type' => new EE_Enum_Text_Field( |
|
221 | - 'LIN_type', |
|
222 | - esc_html__('Type', 'event_espresso'), |
|
223 | - false, |
|
224 | - 'line-item', |
|
225 | - array( |
|
226 | - self::type_line_item => esc_html__('Line Item', 'event_espresso'), |
|
227 | - self::type_sub_line_item => esc_html__('Sub-Item', 'event_espresso'), |
|
228 | - self::type_sub_tax => esc_html__('Sub-Tax', 'event_espresso'), |
|
229 | - self::type_sub_total => esc_html__('Subtotal', 'event_espresso'), |
|
230 | - self::type_tax_sub_total => esc_html__('Tax Subtotal', 'event_espresso'), |
|
231 | - self::type_tax => esc_html__('Tax', 'event_espresso'), |
|
232 | - self::type_total => esc_html__('Total', 'event_espresso'), |
|
233 | - self::type_cancellation => esc_html__('Cancellation', 'event_espresso'), |
|
234 | - ) |
|
235 | - ), |
|
236 | - 'OBJ_ID' => new EE_Foreign_Key_Int_Field( |
|
237 | - 'OBJ_ID', |
|
238 | - esc_html__('ID of Item purchased.', 'event_espresso'), |
|
239 | - true, |
|
240 | - null, |
|
241 | - $line_items_can_be_for |
|
242 | - ), |
|
243 | - 'OBJ_type' => new EE_Any_Foreign_Model_Name_Field( |
|
244 | - 'OBJ_type', |
|
245 | - esc_html__('Model Name this Line Item is for', 'event_espresso'), |
|
246 | - true, |
|
247 | - null, |
|
248 | - $line_items_can_be_for |
|
249 | - ), |
|
250 | - 'LIN_timestamp' => new EE_Datetime_Field( |
|
251 | - 'LIN_timestamp', |
|
252 | - esc_html__('When the line item was created', 'event_espresso'), |
|
253 | - false, |
|
254 | - EE_Datetime_Field::now, |
|
255 | - $timezone |
|
256 | - ), |
|
257 | - ), |
|
258 | - ); |
|
259 | - $this->_model_relations = array( |
|
260 | - 'Transaction' => new EE_Belongs_To_Relation(), |
|
261 | - 'Ticket' => new EE_Belongs_To_Any_Relation(), |
|
262 | - 'Price' => new EE_Belongs_To_Any_Relation(), |
|
263 | - 'Event' => new EE_Belongs_To_Any_Relation(), |
|
264 | - ); |
|
265 | - $this->_model_chain_to_wp_user = 'Transaction.Registration.Event'; |
|
266 | - $this->_caps_slug = 'transactions'; |
|
267 | - parent::__construct($timezone); |
|
268 | - } |
|
269 | - |
|
270 | - |
|
271 | - /** |
|
272 | - * Gets all the line items for this transaction of the given type |
|
273 | - * |
|
274 | - * @param string $line_item_type like one of EEM_Line_Item::type_* |
|
275 | - * @param EE_Transaction|int $transaction |
|
276 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
277 | - * @throws EE_Error |
|
278 | - * @throws InvalidArgumentException |
|
279 | - * @throws InvalidDataTypeException |
|
280 | - * @throws InvalidInterfaceException |
|
281 | - */ |
|
282 | - public function get_all_of_type_for_transaction($line_item_type, $transaction) |
|
283 | - { |
|
284 | - $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction); |
|
285 | - return $this->get_all(array( |
|
286 | - array( |
|
287 | - 'LIN_type' => $line_item_type, |
|
288 | - 'TXN_ID' => $transaction, |
|
289 | - ), |
|
290 | - )); |
|
291 | - } |
|
292 | - |
|
293 | - |
|
294 | - /** |
|
295 | - * Gets all line items unrelated to tickets that are normal line items |
|
296 | - * (eg shipping, promotions, and miscellaneous other stuff should probably fit in this category) |
|
297 | - * |
|
298 | - * @param EE_Transaction|int $transaction |
|
299 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
300 | - * @throws EE_Error |
|
301 | - * @throws InvalidArgumentException |
|
302 | - * @throws InvalidDataTypeException |
|
303 | - * @throws InvalidInterfaceException |
|
304 | - */ |
|
305 | - public function get_all_non_ticket_line_items_for_transaction($transaction) |
|
306 | - { |
|
307 | - $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction); |
|
308 | - return $this->get_all(array( |
|
309 | - array( |
|
310 | - 'LIN_type' => self::type_line_item, |
|
311 | - 'TXN_ID' => $transaction, |
|
312 | - 'OR' => array( |
|
313 | - 'OBJ_type*notticket' => array('!=', EEM_Line_Item::OBJ_TYPE_TICKET), |
|
314 | - 'OBJ_type*null' => array('IS_NULL'), |
|
315 | - ), |
|
316 | - ), |
|
317 | - )); |
|
318 | - } |
|
319 | - |
|
320 | - |
|
321 | - /** |
|
322 | - * Deletes line items with no transaction who have passed the transaction cutoff time. |
|
323 | - * This needs to be very efficient |
|
324 | - * because if there are spam bots afoot there will be LOTS of line items. Also MySQL doesn't allow a limit when |
|
325 | - * deleting and joining tables like this. |
|
326 | - * |
|
327 | - * @return int count of how many deleted |
|
328 | - * @throws EE_Error |
|
329 | - * @throws InvalidArgumentException |
|
330 | - * @throws InvalidDataTypeException |
|
331 | - * @throws InvalidInterfaceException |
|
332 | - */ |
|
333 | - public function delete_line_items_with_no_transaction() |
|
334 | - { |
|
335 | - /** @type WPDB $wpdb */ |
|
336 | - global $wpdb; |
|
337 | - $time_to_leave_alone = apply_filters( |
|
338 | - 'FHEE__EEM_Line_Item__delete_line_items_with_no_transaction__time_to_leave_alone', |
|
339 | - WEEK_IN_SECONDS |
|
340 | - ); |
|
341 | - $query = $wpdb->prepare( |
|
342 | - 'DELETE li |
|
30 | + /** |
|
31 | + * Tax sub-total is just the total of all the taxes, which should be children |
|
32 | + * of this line item. There should only ever be one tax sub-total, and it should |
|
33 | + * be a direct child of. Its quantity and LIN_unit_price = 1. |
|
34 | + */ |
|
35 | + const type_tax_sub_total = 'tax-sub-total'; |
|
36 | + |
|
37 | + /** |
|
38 | + * Tax line items indicate a tax applied to all the taxable line items. |
|
39 | + * Should not have any children line items. Its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal |
|
40 | + * (eg 10% tax = 10, not 0.1). Its LIN_total = LIN_unit_price * pre-tax-total. Quantity = 1. |
|
41 | + */ |
|
42 | + const type_tax = 'tax'; |
|
43 | + |
|
44 | + /** |
|
45 | + * Indicating individual items purchased, or discounts or surcharges. |
|
46 | + * The sum of all the regular line items plus the tax items should equal the grand total. |
|
47 | + * Possible children are sub-line-items and cancellations. |
|
48 | + * For flat items, LIN_unit_price * LIN_quantity = LIN_total. Its LIN_total is the sum of all the children |
|
49 | + * LIN_totals. Its LIN_percent = 0. |
|
50 | + * For percent items, its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal (eg 10% = 10, not 0.1). |
|
51 | + * Its LIN_total is LIN_percent / 100 * sum of lower-priority sibling line items. Quantity = 1. |
|
52 | + */ |
|
53 | + const type_line_item = 'line-item'; |
|
54 | + |
|
55 | + /** |
|
56 | + * Line item indicating all the factors that make a single line item. |
|
57 | + * Sub-line items should have NO children line items. |
|
58 | + * For flat sub-items, their quantity should match their parent item, their LIN_unit_price should be this sub-item's |
|
59 | + * contribution towards the price of ONE of their parent items, and its LIN_total should be |
|
60 | + * = LIN_quantity * LIN_unit_price. Its LIN_percent = 0. |
|
61 | + * For percent sub-items, the quantity should be 1, LIN_unit_price should be 0, and its LIN_total should |
|
62 | + * = LIN_percent / 100 * sum of lower-priority sibling line items.. |
|
63 | + */ |
|
64 | + const type_sub_line_item = 'sub-item'; |
|
65 | + |
|
66 | + /** |
|
67 | + * SubTax line items indicate a tax that is only applied to the pre-tax total of their parent line item. |
|
68 | + * Should not have any children line items. Its LIN_unit_price = 0. Its LIN_percent is a percent, not a decimal |
|
69 | + * (eg 10% tax = 10, not 0.1). Its LIN_total = LIN_unit_price * pre-tax-total. Quantity = 1. |
|
70 | + */ |
|
71 | + const type_sub_tax = 'sub-tax'; |
|
72 | + |
|
73 | + /** |
|
74 | + * Line item indicating a sub-total (eg total for an event, or pre-tax subtotal). |
|
75 | + * Direct children should be event subtotals. |
|
76 | + * Should have quantity of 1, and a LIN_total and LIN_unit_price of the sum of all its sub-items' LIN_totals. |
|
77 | + */ |
|
78 | + const type_sub_total = 'sub-total'; |
|
79 | + |
|
80 | + /** |
|
81 | + * Line item for the grand total of an order. |
|
82 | + * Its direct children should be tax subtotals and (pre-tax) subtotals, |
|
83 | + * and possibly a regular line item indicating a transaction-wide discount/surcharge. |
|
84 | + * Should have a quantity of 1, a LIN_total and LIN_unit_price of the entire order's amount. |
|
85 | + */ |
|
86 | + const type_total = 'total'; |
|
87 | + |
|
88 | + /** |
|
89 | + * When a line item is cancelled, a sub-line-item of type 'cancellation' |
|
90 | + * should be created, indicating the quantity that were cancelled |
|
91 | + * (because a line item could have a quantity of 1, and its cancellation item |
|
92 | + * could be for 3, indicating that originally 4 were purchased, but 3 have been |
|
93 | + * cancelled, and only one remains). |
|
94 | + * When items are refunded, a cancellation line item should be made, which points |
|
95 | + * to teh payment model object which actually refunded the payment. |
|
96 | + * Cancellations should NOT have any children line items; the should NOT affect |
|
97 | + * any calculations, and are only meant as a record that cancellations have occurred. |
|
98 | + * Their LIN_percent should be 0. |
|
99 | + */ |
|
100 | + const type_cancellation = 'cancellation'; |
|
101 | + |
|
102 | + // various line item object types |
|
103 | + const OBJ_TYPE_EVENT = 'Event'; |
|
104 | + |
|
105 | + const OBJ_TYPE_PRICE = 'Price'; |
|
106 | + |
|
107 | + const OBJ_TYPE_PROMOTION = 'Promotion'; |
|
108 | + |
|
109 | + const OBJ_TYPE_TICKET = 'Ticket'; |
|
110 | + |
|
111 | + const OBJ_TYPE_TRANSACTION = 'Transaction'; |
|
112 | + |
|
113 | + /** |
|
114 | + * @var EEM_Line_Item $_instance |
|
115 | + */ |
|
116 | + protected static $_instance; |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * private constructor to prevent direct creation |
|
121 | + * |
|
122 | + * @Constructor |
|
123 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings |
|
124 | + * (and any incoming timezone data that gets saved). |
|
125 | + * Note this just sends the timezone info to the date time model field objects. |
|
126 | + * Default is NULL |
|
127 | + * (and will be assumed using the set timezone in the 'timezone_string' wp option) |
|
128 | + * @throws EE_Error |
|
129 | + * @throws InvalidArgumentException |
|
130 | + */ |
|
131 | + protected function __construct($timezone) |
|
132 | + { |
|
133 | + $this->singular_item = esc_html__('Line Item', 'event_espresso'); |
|
134 | + $this->plural_item = esc_html__('Line Items', 'event_espresso'); |
|
135 | + |
|
136 | + $this->_tables = array( |
|
137 | + 'Line_Item' => new EE_Primary_Table('esp_line_item', 'LIN_ID'), |
|
138 | + ); |
|
139 | + $line_items_can_be_for = apply_filters( |
|
140 | + 'FHEE__EEM_Line_Item__line_items_can_be_for', |
|
141 | + array('Ticket', 'Price', 'Event') |
|
142 | + ); |
|
143 | + $this->_fields = array( |
|
144 | + 'Line_Item' => array( |
|
145 | + 'LIN_ID' => new EE_Primary_Key_Int_Field( |
|
146 | + 'LIN_ID', |
|
147 | + esc_html__('ID', 'event_espresso') |
|
148 | + ), |
|
149 | + 'LIN_code' => new EE_Slug_Field( |
|
150 | + 'LIN_code', |
|
151 | + esc_html__('Code for index into Cart', 'event_espresso'), |
|
152 | + true |
|
153 | + ), |
|
154 | + 'TXN_ID' => new EE_Foreign_Key_Int_Field( |
|
155 | + 'TXN_ID', |
|
156 | + esc_html__('Transaction ID', 'event_espresso'), |
|
157 | + true, |
|
158 | + null, |
|
159 | + 'Transaction' |
|
160 | + ), |
|
161 | + 'LIN_name' => new EE_Full_HTML_Field( |
|
162 | + 'LIN_name', |
|
163 | + esc_html__('Line Item Name', 'event_espresso'), |
|
164 | + false, |
|
165 | + '' |
|
166 | + ), |
|
167 | + 'LIN_desc' => new EE_Full_HTML_Field( |
|
168 | + 'LIN_desc', |
|
169 | + esc_html__('Line Item Description', 'event_espresso'), |
|
170 | + true |
|
171 | + ), |
|
172 | + 'LIN_unit_price' => new EE_Money_Field( |
|
173 | + 'LIN_unit_price', |
|
174 | + esc_html__('Unit Price', 'event_espresso'), |
|
175 | + false, |
|
176 | + 0 |
|
177 | + ), |
|
178 | + 'LIN_percent' => new EE_Float_Field( |
|
179 | + 'LIN_percent', |
|
180 | + esc_html__('Percent', 'event_espresso'), |
|
181 | + false, |
|
182 | + 0 |
|
183 | + ), |
|
184 | + 'LIN_is_taxable' => new EE_Boolean_Field( |
|
185 | + 'LIN_is_taxable', |
|
186 | + esc_html__('Taxable', 'event_espresso'), |
|
187 | + false, |
|
188 | + false |
|
189 | + ), |
|
190 | + 'LIN_order' => new EE_Integer_Field( |
|
191 | + 'LIN_order', |
|
192 | + esc_html__('Order of Application towards total of parent', 'event_espresso'), |
|
193 | + false, |
|
194 | + 1 |
|
195 | + ), |
|
196 | + 'LIN_total' => new EE_Money_Field( |
|
197 | + 'LIN_total', |
|
198 | + esc_html__('Total (unit price x quantity) after taxes', 'event_espresso'), |
|
199 | + false, |
|
200 | + 0 |
|
201 | + ), |
|
202 | + 'LIN_pretax' => new EE_Money_Field( |
|
203 | + 'LIN_pretax', |
|
204 | + esc_html__('Total (unit price x quantity) before taxes', 'event_espresso'), |
|
205 | + false, |
|
206 | + 0 |
|
207 | + ), |
|
208 | + 'LIN_quantity' => new EE_Integer_Field( |
|
209 | + 'LIN_quantity', |
|
210 | + esc_html__('Quantity', 'event_espresso'), |
|
211 | + true, |
|
212 | + 1 |
|
213 | + ), |
|
214 | + 'LIN_parent' => new EE_Integer_Field( |
|
215 | + 'LIN_parent', |
|
216 | + esc_html__("Parent ID (this item goes towards that Line Item's total)", 'event_espresso'), |
|
217 | + true, |
|
218 | + null |
|
219 | + ), |
|
220 | + 'LIN_type' => new EE_Enum_Text_Field( |
|
221 | + 'LIN_type', |
|
222 | + esc_html__('Type', 'event_espresso'), |
|
223 | + false, |
|
224 | + 'line-item', |
|
225 | + array( |
|
226 | + self::type_line_item => esc_html__('Line Item', 'event_espresso'), |
|
227 | + self::type_sub_line_item => esc_html__('Sub-Item', 'event_espresso'), |
|
228 | + self::type_sub_tax => esc_html__('Sub-Tax', 'event_espresso'), |
|
229 | + self::type_sub_total => esc_html__('Subtotal', 'event_espresso'), |
|
230 | + self::type_tax_sub_total => esc_html__('Tax Subtotal', 'event_espresso'), |
|
231 | + self::type_tax => esc_html__('Tax', 'event_espresso'), |
|
232 | + self::type_total => esc_html__('Total', 'event_espresso'), |
|
233 | + self::type_cancellation => esc_html__('Cancellation', 'event_espresso'), |
|
234 | + ) |
|
235 | + ), |
|
236 | + 'OBJ_ID' => new EE_Foreign_Key_Int_Field( |
|
237 | + 'OBJ_ID', |
|
238 | + esc_html__('ID of Item purchased.', 'event_espresso'), |
|
239 | + true, |
|
240 | + null, |
|
241 | + $line_items_can_be_for |
|
242 | + ), |
|
243 | + 'OBJ_type' => new EE_Any_Foreign_Model_Name_Field( |
|
244 | + 'OBJ_type', |
|
245 | + esc_html__('Model Name this Line Item is for', 'event_espresso'), |
|
246 | + true, |
|
247 | + null, |
|
248 | + $line_items_can_be_for |
|
249 | + ), |
|
250 | + 'LIN_timestamp' => new EE_Datetime_Field( |
|
251 | + 'LIN_timestamp', |
|
252 | + esc_html__('When the line item was created', 'event_espresso'), |
|
253 | + false, |
|
254 | + EE_Datetime_Field::now, |
|
255 | + $timezone |
|
256 | + ), |
|
257 | + ), |
|
258 | + ); |
|
259 | + $this->_model_relations = array( |
|
260 | + 'Transaction' => new EE_Belongs_To_Relation(), |
|
261 | + 'Ticket' => new EE_Belongs_To_Any_Relation(), |
|
262 | + 'Price' => new EE_Belongs_To_Any_Relation(), |
|
263 | + 'Event' => new EE_Belongs_To_Any_Relation(), |
|
264 | + ); |
|
265 | + $this->_model_chain_to_wp_user = 'Transaction.Registration.Event'; |
|
266 | + $this->_caps_slug = 'transactions'; |
|
267 | + parent::__construct($timezone); |
|
268 | + } |
|
269 | + |
|
270 | + |
|
271 | + /** |
|
272 | + * Gets all the line items for this transaction of the given type |
|
273 | + * |
|
274 | + * @param string $line_item_type like one of EEM_Line_Item::type_* |
|
275 | + * @param EE_Transaction|int $transaction |
|
276 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
277 | + * @throws EE_Error |
|
278 | + * @throws InvalidArgumentException |
|
279 | + * @throws InvalidDataTypeException |
|
280 | + * @throws InvalidInterfaceException |
|
281 | + */ |
|
282 | + public function get_all_of_type_for_transaction($line_item_type, $transaction) |
|
283 | + { |
|
284 | + $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction); |
|
285 | + return $this->get_all(array( |
|
286 | + array( |
|
287 | + 'LIN_type' => $line_item_type, |
|
288 | + 'TXN_ID' => $transaction, |
|
289 | + ), |
|
290 | + )); |
|
291 | + } |
|
292 | + |
|
293 | + |
|
294 | + /** |
|
295 | + * Gets all line items unrelated to tickets that are normal line items |
|
296 | + * (eg shipping, promotions, and miscellaneous other stuff should probably fit in this category) |
|
297 | + * |
|
298 | + * @param EE_Transaction|int $transaction |
|
299 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
300 | + * @throws EE_Error |
|
301 | + * @throws InvalidArgumentException |
|
302 | + * @throws InvalidDataTypeException |
|
303 | + * @throws InvalidInterfaceException |
|
304 | + */ |
|
305 | + public function get_all_non_ticket_line_items_for_transaction($transaction) |
|
306 | + { |
|
307 | + $transaction = EEM_Transaction::instance()->ensure_is_ID($transaction); |
|
308 | + return $this->get_all(array( |
|
309 | + array( |
|
310 | + 'LIN_type' => self::type_line_item, |
|
311 | + 'TXN_ID' => $transaction, |
|
312 | + 'OR' => array( |
|
313 | + 'OBJ_type*notticket' => array('!=', EEM_Line_Item::OBJ_TYPE_TICKET), |
|
314 | + 'OBJ_type*null' => array('IS_NULL'), |
|
315 | + ), |
|
316 | + ), |
|
317 | + )); |
|
318 | + } |
|
319 | + |
|
320 | + |
|
321 | + /** |
|
322 | + * Deletes line items with no transaction who have passed the transaction cutoff time. |
|
323 | + * This needs to be very efficient |
|
324 | + * because if there are spam bots afoot there will be LOTS of line items. Also MySQL doesn't allow a limit when |
|
325 | + * deleting and joining tables like this. |
|
326 | + * |
|
327 | + * @return int count of how many deleted |
|
328 | + * @throws EE_Error |
|
329 | + * @throws InvalidArgumentException |
|
330 | + * @throws InvalidDataTypeException |
|
331 | + * @throws InvalidInterfaceException |
|
332 | + */ |
|
333 | + public function delete_line_items_with_no_transaction() |
|
334 | + { |
|
335 | + /** @type WPDB $wpdb */ |
|
336 | + global $wpdb; |
|
337 | + $time_to_leave_alone = apply_filters( |
|
338 | + 'FHEE__EEM_Line_Item__delete_line_items_with_no_transaction__time_to_leave_alone', |
|
339 | + WEEK_IN_SECONDS |
|
340 | + ); |
|
341 | + $query = $wpdb->prepare( |
|
342 | + 'DELETE li |
|
343 | 343 | FROM ' . $this->table() . ' li |
344 | 344 | LEFT JOIN ' . EEM_Transaction::instance()->table() . ' t ON li.TXN_ID = t.TXN_ID |
345 | 345 | WHERE t.TXN_ID IS NULL AND li.LIN_timestamp < %s', |
346 | - // use GMT time because that's what TXN_timestamps are in |
|
347 | - date('Y-m-d H:i:s', time() - $time_to_leave_alone) |
|
348 | - ); |
|
349 | - return $wpdb->query($query); |
|
350 | - } |
|
351 | - |
|
352 | - |
|
353 | - /** |
|
354 | - * get_line_item_for_transaction_object |
|
355 | - * Gets a transaction's line item record for a specific object such as a EE_Event or EE_Ticket |
|
356 | - * |
|
357 | - * @param int $TXN_ID |
|
358 | - * @param EE_Base_Class $object |
|
359 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
360 | - * @throws EE_Error |
|
361 | - * @throws InvalidArgumentException |
|
362 | - * @throws InvalidDataTypeException |
|
363 | - * @throws InvalidInterfaceException |
|
364 | - * @throws ReflectionException |
|
365 | - */ |
|
366 | - public function get_line_item_for_transaction_object($TXN_ID, EE_Base_Class $object) |
|
367 | - { |
|
368 | - return $this->get_all(array( |
|
369 | - array( |
|
370 | - 'TXN_ID' => $TXN_ID, |
|
371 | - 'OBJ_type' => str_replace('EE_', '', get_class($object)), |
|
372 | - 'OBJ_ID' => $object->ID(), |
|
373 | - ), |
|
374 | - )); |
|
375 | - } |
|
376 | - |
|
377 | - |
|
378 | - /** |
|
379 | - * get_object_line_items_for_transaction |
|
380 | - * Gets all of the the object line items for a transaction, based on an object type plus an array of object IDs |
|
381 | - * |
|
382 | - * @param int $TXN_ID |
|
383 | - * @param string $OBJ_type |
|
384 | - * @param array $OBJ_IDs |
|
385 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
386 | - * @throws EE_Error |
|
387 | - */ |
|
388 | - public function get_object_line_items_for_transaction( |
|
389 | - $TXN_ID, |
|
390 | - $OBJ_type = EEM_Line_Item::OBJ_TYPE_EVENT, |
|
391 | - $OBJ_IDs = array() |
|
392 | - ) { |
|
393 | - $query_params = array( |
|
394 | - 'OBJ_type' => $OBJ_type, |
|
395 | - // if incoming $OBJ_IDs is an array, then make sure it is formatted correctly for the query |
|
396 | - 'OBJ_ID' => is_array($OBJ_IDs) && ! isset($OBJ_IDs['IN']) ? array('IN', $OBJ_IDs) : $OBJ_IDs, |
|
397 | - ); |
|
398 | - if ($TXN_ID) { |
|
399 | - $query_params['TXN_ID'] = $TXN_ID; |
|
400 | - } |
|
401 | - return $this->get_all(array($query_params)); |
|
402 | - } |
|
403 | - |
|
404 | - |
|
405 | - /** |
|
406 | - * get_all_ticket_line_items_for_transaction |
|
407 | - * |
|
408 | - * @param EE_Transaction $transaction |
|
409 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
410 | - * @throws EE_Error |
|
411 | - * @throws InvalidArgumentException |
|
412 | - * @throws InvalidDataTypeException |
|
413 | - * @throws InvalidInterfaceException |
|
414 | - * @throws ReflectionException |
|
415 | - */ |
|
416 | - public function get_all_ticket_line_items_for_transaction(EE_Transaction $transaction) |
|
417 | - { |
|
418 | - return $this->get_all(array( |
|
419 | - array( |
|
420 | - 'TXN_ID' => $transaction->ID(), |
|
421 | - 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET, |
|
422 | - ), |
|
423 | - )); |
|
424 | - } |
|
425 | - |
|
426 | - |
|
427 | - /** |
|
428 | - * get_ticket_line_item_for_transaction |
|
429 | - * |
|
430 | - * @param int $TXN_ID |
|
431 | - * @param int $TKT_ID |
|
432 | - * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL |
|
433 | - * @throws EE_Error |
|
434 | - * @throws InvalidArgumentException |
|
435 | - * @throws InvalidDataTypeException |
|
436 | - * @throws InvalidInterfaceException |
|
437 | - */ |
|
438 | - public function get_ticket_line_item_for_transaction($TXN_ID, $TKT_ID) |
|
439 | - { |
|
440 | - return $this->get_one(array( |
|
441 | - array( |
|
442 | - 'TXN_ID' => EEM_Transaction::instance()->ensure_is_ID($TXN_ID), |
|
443 | - 'OBJ_ID' => $TKT_ID, |
|
444 | - 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET, |
|
445 | - ), |
|
446 | - )); |
|
447 | - } |
|
448 | - |
|
449 | - |
|
450 | - /** |
|
451 | - * get_existing_promotion_line_item |
|
452 | - * searches the cart for existing line items for the specified promotion |
|
453 | - * |
|
454 | - * @since 1.0.0 |
|
455 | - * @param EE_Line_Item $parent_line_item |
|
456 | - * @param EE_Promotion $promotion |
|
457 | - * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL |
|
458 | - * @throws EE_Error |
|
459 | - * @throws InvalidArgumentException |
|
460 | - * @throws InvalidDataTypeException |
|
461 | - * @throws InvalidInterfaceException |
|
462 | - * @throws ReflectionException |
|
463 | - */ |
|
464 | - public function get_existing_promotion_line_item(EE_Line_Item $parent_line_item, EE_Promotion $promotion) |
|
465 | - { |
|
466 | - return $this->get_one(array( |
|
467 | - array( |
|
468 | - 'TXN_ID' => $parent_line_item->TXN_ID(), |
|
469 | - 'LIN_parent' => $parent_line_item->ID(), |
|
470 | - 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_PROMOTION, |
|
471 | - 'OBJ_ID' => $promotion->ID(), |
|
472 | - ), |
|
473 | - )); |
|
474 | - } |
|
475 | - |
|
476 | - |
|
477 | - /** |
|
478 | - * get_all_promotion_line_items |
|
479 | - * searches the cart for any and all existing promotion line items |
|
480 | - * |
|
481 | - * @since 1.0.0 |
|
482 | - * @param EE_Line_Item $parent_line_item |
|
483 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
484 | - * @throws EE_Error |
|
485 | - * @throws InvalidArgumentException |
|
486 | - * @throws InvalidDataTypeException |
|
487 | - * @throws InvalidInterfaceException |
|
488 | - * @throws ReflectionException |
|
489 | - */ |
|
490 | - public function get_all_promotion_line_items(EE_Line_Item $parent_line_item) |
|
491 | - { |
|
492 | - return $this->get_all(array( |
|
493 | - array( |
|
494 | - 'TXN_ID' => $parent_line_item->TXN_ID(), |
|
495 | - 'LIN_parent' => $parent_line_item->ID(), |
|
496 | - 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_PROMOTION, |
|
497 | - ), |
|
498 | - )); |
|
499 | - } |
|
500 | - |
|
501 | - |
|
502 | - /** |
|
503 | - * Gets the registration's corresponding line item. |
|
504 | - * Note: basically does NOT support having multiple line items for a single ticket, |
|
505 | - * which would happen if some of the registrations had a price modifier while others didn't. |
|
506 | - * In order to support that, we'd probably need a LIN_ID on registrations or something. |
|
507 | - * |
|
508 | - * @param EE_Registration $registration |
|
509 | - * @return EE_Base_Class|EE_Line_ITem|EE_Soft_Delete_Base_Class|NULL |
|
510 | - * @throws EE_Error |
|
511 | - */ |
|
512 | - public function get_line_item_for_registration(EE_Registration $registration) |
|
513 | - { |
|
514 | - return $this->get_one($this->line_item_for_registration_query_params($registration)); |
|
515 | - } |
|
516 | - |
|
517 | - |
|
518 | - /** |
|
519 | - * Gets the query params used to retrieve a specific line item for the given registration |
|
520 | - * |
|
521 | - * @param EE_Registration $registration |
|
522 | - * @param array $original_query_params any extra query params you'd like to be merged with |
|
523 | - * @return array @see |
|
524 | - * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
525 | - * @throws EE_Error |
|
526 | - */ |
|
527 | - public function line_item_for_registration_query_params( |
|
528 | - EE_Registration $registration, |
|
529 | - $original_query_params = array() |
|
530 | - ) { |
|
531 | - return array_replace_recursive($original_query_params, array( |
|
532 | - array( |
|
533 | - 'OBJ_ID' => $registration->ticket_ID(), |
|
534 | - 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET, |
|
535 | - 'TXN_ID' => $registration->transaction_ID(), |
|
536 | - ), |
|
537 | - )); |
|
538 | - } |
|
539 | - |
|
540 | - |
|
541 | - /** |
|
542 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
543 | - * @throws InvalidInterfaceException |
|
544 | - * @throws InvalidDataTypeException |
|
545 | - * @throws EE_Error |
|
546 | - * @throws InvalidArgumentException |
|
547 | - */ |
|
548 | - public function get_total_line_items_with_no_transaction() |
|
549 | - { |
|
550 | - return $this->get_total_line_items_for_carts(); |
|
551 | - } |
|
552 | - |
|
553 | - |
|
554 | - /** |
|
555 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
556 | - * @throws InvalidInterfaceException |
|
557 | - * @throws InvalidDataTypeException |
|
558 | - * @throws EE_Error |
|
559 | - * @throws InvalidArgumentException |
|
560 | - */ |
|
561 | - public function get_total_line_items_for_active_carts() |
|
562 | - { |
|
563 | - return $this->get_total_line_items_for_carts(false); |
|
564 | - } |
|
565 | - |
|
566 | - |
|
567 | - /** |
|
568 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
569 | - * @throws InvalidInterfaceException |
|
570 | - * @throws InvalidDataTypeException |
|
571 | - * @throws EE_Error |
|
572 | - * @throws InvalidArgumentException |
|
573 | - */ |
|
574 | - public function get_total_line_items_for_expired_carts() |
|
575 | - { |
|
576 | - return $this->get_total_line_items_for_carts(true); |
|
577 | - } |
|
578 | - |
|
579 | - |
|
580 | - /** |
|
581 | - * Returns an array of grand total line items where the TXN_ID is 0. |
|
582 | - * If $expired is set to true, then only line items for expired sessions will be returned. |
|
583 | - * If $expired is set to false, then only line items for active sessions will be returned. |
|
584 | - * |
|
585 | - * @param null $expired |
|
586 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
587 | - * @throws EE_Error |
|
588 | - * @throws InvalidArgumentException |
|
589 | - * @throws InvalidDataTypeException |
|
590 | - * @throws InvalidInterfaceException |
|
591 | - */ |
|
592 | - private function get_total_line_items_for_carts($expired = null) |
|
593 | - { |
|
594 | - $where_params = array( |
|
595 | - 'TXN_ID' => 0, |
|
596 | - 'LIN_type' => 'total', |
|
597 | - ); |
|
598 | - if ($expired !== null) { |
|
599 | - /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
600 | - $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
601 | - 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
602 | - ); |
|
603 | - $where_params['LIN_timestamp'] = array( |
|
604 | - $expired ? '<=' : '>', |
|
605 | - $session_lifespan->expiration(), |
|
606 | - ); |
|
607 | - } |
|
608 | - return $this->get_all(array($where_params)); |
|
609 | - } |
|
610 | - |
|
611 | - |
|
612 | - /** |
|
613 | - * Returns an array of ticket total line items where the TXN_ID is 0 |
|
614 | - * AND the timestamp is older than the session lifespan. |
|
615 | - * |
|
616 | - * @param int $timestamp |
|
617 | - * @return EE_Base_Class[]|EE_Line_Item[] |
|
618 | - * @throws EE_Error |
|
619 | - * @throws InvalidArgumentException |
|
620 | - * @throws InvalidDataTypeException |
|
621 | - * @throws InvalidInterfaceException |
|
622 | - */ |
|
623 | - public function getTicketLineItemsForExpiredCarts($timestamp = 0) |
|
624 | - { |
|
625 | - if (! absint($timestamp)) { |
|
626 | - /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
627 | - $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
628 | - 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
629 | - ); |
|
630 | - $timestamp = $session_lifespan->expiration(); |
|
631 | - } |
|
632 | - return $this->get_all( |
|
633 | - array( |
|
634 | - array( |
|
635 | - 'TXN_ID' => 0, |
|
636 | - 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET, |
|
637 | - 'LIN_timestamp' => array('<=', $timestamp), |
|
638 | - ), |
|
639 | - ) |
|
640 | - ); |
|
641 | - } |
|
346 | + // use GMT time because that's what TXN_timestamps are in |
|
347 | + date('Y-m-d H:i:s', time() - $time_to_leave_alone) |
|
348 | + ); |
|
349 | + return $wpdb->query($query); |
|
350 | + } |
|
351 | + |
|
352 | + |
|
353 | + /** |
|
354 | + * get_line_item_for_transaction_object |
|
355 | + * Gets a transaction's line item record for a specific object such as a EE_Event or EE_Ticket |
|
356 | + * |
|
357 | + * @param int $TXN_ID |
|
358 | + * @param EE_Base_Class $object |
|
359 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
360 | + * @throws EE_Error |
|
361 | + * @throws InvalidArgumentException |
|
362 | + * @throws InvalidDataTypeException |
|
363 | + * @throws InvalidInterfaceException |
|
364 | + * @throws ReflectionException |
|
365 | + */ |
|
366 | + public function get_line_item_for_transaction_object($TXN_ID, EE_Base_Class $object) |
|
367 | + { |
|
368 | + return $this->get_all(array( |
|
369 | + array( |
|
370 | + 'TXN_ID' => $TXN_ID, |
|
371 | + 'OBJ_type' => str_replace('EE_', '', get_class($object)), |
|
372 | + 'OBJ_ID' => $object->ID(), |
|
373 | + ), |
|
374 | + )); |
|
375 | + } |
|
376 | + |
|
377 | + |
|
378 | + /** |
|
379 | + * get_object_line_items_for_transaction |
|
380 | + * Gets all of the the object line items for a transaction, based on an object type plus an array of object IDs |
|
381 | + * |
|
382 | + * @param int $TXN_ID |
|
383 | + * @param string $OBJ_type |
|
384 | + * @param array $OBJ_IDs |
|
385 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
386 | + * @throws EE_Error |
|
387 | + */ |
|
388 | + public function get_object_line_items_for_transaction( |
|
389 | + $TXN_ID, |
|
390 | + $OBJ_type = EEM_Line_Item::OBJ_TYPE_EVENT, |
|
391 | + $OBJ_IDs = array() |
|
392 | + ) { |
|
393 | + $query_params = array( |
|
394 | + 'OBJ_type' => $OBJ_type, |
|
395 | + // if incoming $OBJ_IDs is an array, then make sure it is formatted correctly for the query |
|
396 | + 'OBJ_ID' => is_array($OBJ_IDs) && ! isset($OBJ_IDs['IN']) ? array('IN', $OBJ_IDs) : $OBJ_IDs, |
|
397 | + ); |
|
398 | + if ($TXN_ID) { |
|
399 | + $query_params['TXN_ID'] = $TXN_ID; |
|
400 | + } |
|
401 | + return $this->get_all(array($query_params)); |
|
402 | + } |
|
403 | + |
|
404 | + |
|
405 | + /** |
|
406 | + * get_all_ticket_line_items_for_transaction |
|
407 | + * |
|
408 | + * @param EE_Transaction $transaction |
|
409 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
410 | + * @throws EE_Error |
|
411 | + * @throws InvalidArgumentException |
|
412 | + * @throws InvalidDataTypeException |
|
413 | + * @throws InvalidInterfaceException |
|
414 | + * @throws ReflectionException |
|
415 | + */ |
|
416 | + public function get_all_ticket_line_items_for_transaction(EE_Transaction $transaction) |
|
417 | + { |
|
418 | + return $this->get_all(array( |
|
419 | + array( |
|
420 | + 'TXN_ID' => $transaction->ID(), |
|
421 | + 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET, |
|
422 | + ), |
|
423 | + )); |
|
424 | + } |
|
425 | + |
|
426 | + |
|
427 | + /** |
|
428 | + * get_ticket_line_item_for_transaction |
|
429 | + * |
|
430 | + * @param int $TXN_ID |
|
431 | + * @param int $TKT_ID |
|
432 | + * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL |
|
433 | + * @throws EE_Error |
|
434 | + * @throws InvalidArgumentException |
|
435 | + * @throws InvalidDataTypeException |
|
436 | + * @throws InvalidInterfaceException |
|
437 | + */ |
|
438 | + public function get_ticket_line_item_for_transaction($TXN_ID, $TKT_ID) |
|
439 | + { |
|
440 | + return $this->get_one(array( |
|
441 | + array( |
|
442 | + 'TXN_ID' => EEM_Transaction::instance()->ensure_is_ID($TXN_ID), |
|
443 | + 'OBJ_ID' => $TKT_ID, |
|
444 | + 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET, |
|
445 | + ), |
|
446 | + )); |
|
447 | + } |
|
448 | + |
|
449 | + |
|
450 | + /** |
|
451 | + * get_existing_promotion_line_item |
|
452 | + * searches the cart for existing line items for the specified promotion |
|
453 | + * |
|
454 | + * @since 1.0.0 |
|
455 | + * @param EE_Line_Item $parent_line_item |
|
456 | + * @param EE_Promotion $promotion |
|
457 | + * @return EE_Base_Class|EE_Line_Item|EE_Soft_Delete_Base_Class|NULL |
|
458 | + * @throws EE_Error |
|
459 | + * @throws InvalidArgumentException |
|
460 | + * @throws InvalidDataTypeException |
|
461 | + * @throws InvalidInterfaceException |
|
462 | + * @throws ReflectionException |
|
463 | + */ |
|
464 | + public function get_existing_promotion_line_item(EE_Line_Item $parent_line_item, EE_Promotion $promotion) |
|
465 | + { |
|
466 | + return $this->get_one(array( |
|
467 | + array( |
|
468 | + 'TXN_ID' => $parent_line_item->TXN_ID(), |
|
469 | + 'LIN_parent' => $parent_line_item->ID(), |
|
470 | + 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_PROMOTION, |
|
471 | + 'OBJ_ID' => $promotion->ID(), |
|
472 | + ), |
|
473 | + )); |
|
474 | + } |
|
475 | + |
|
476 | + |
|
477 | + /** |
|
478 | + * get_all_promotion_line_items |
|
479 | + * searches the cart for any and all existing promotion line items |
|
480 | + * |
|
481 | + * @since 1.0.0 |
|
482 | + * @param EE_Line_Item $parent_line_item |
|
483 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
484 | + * @throws EE_Error |
|
485 | + * @throws InvalidArgumentException |
|
486 | + * @throws InvalidDataTypeException |
|
487 | + * @throws InvalidInterfaceException |
|
488 | + * @throws ReflectionException |
|
489 | + */ |
|
490 | + public function get_all_promotion_line_items(EE_Line_Item $parent_line_item) |
|
491 | + { |
|
492 | + return $this->get_all(array( |
|
493 | + array( |
|
494 | + 'TXN_ID' => $parent_line_item->TXN_ID(), |
|
495 | + 'LIN_parent' => $parent_line_item->ID(), |
|
496 | + 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_PROMOTION, |
|
497 | + ), |
|
498 | + )); |
|
499 | + } |
|
500 | + |
|
501 | + |
|
502 | + /** |
|
503 | + * Gets the registration's corresponding line item. |
|
504 | + * Note: basically does NOT support having multiple line items for a single ticket, |
|
505 | + * which would happen if some of the registrations had a price modifier while others didn't. |
|
506 | + * In order to support that, we'd probably need a LIN_ID on registrations or something. |
|
507 | + * |
|
508 | + * @param EE_Registration $registration |
|
509 | + * @return EE_Base_Class|EE_Line_ITem|EE_Soft_Delete_Base_Class|NULL |
|
510 | + * @throws EE_Error |
|
511 | + */ |
|
512 | + public function get_line_item_for_registration(EE_Registration $registration) |
|
513 | + { |
|
514 | + return $this->get_one($this->line_item_for_registration_query_params($registration)); |
|
515 | + } |
|
516 | + |
|
517 | + |
|
518 | + /** |
|
519 | + * Gets the query params used to retrieve a specific line item for the given registration |
|
520 | + * |
|
521 | + * @param EE_Registration $registration |
|
522 | + * @param array $original_query_params any extra query params you'd like to be merged with |
|
523 | + * @return array @see |
|
524 | + * https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
525 | + * @throws EE_Error |
|
526 | + */ |
|
527 | + public function line_item_for_registration_query_params( |
|
528 | + EE_Registration $registration, |
|
529 | + $original_query_params = array() |
|
530 | + ) { |
|
531 | + return array_replace_recursive($original_query_params, array( |
|
532 | + array( |
|
533 | + 'OBJ_ID' => $registration->ticket_ID(), |
|
534 | + 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET, |
|
535 | + 'TXN_ID' => $registration->transaction_ID(), |
|
536 | + ), |
|
537 | + )); |
|
538 | + } |
|
539 | + |
|
540 | + |
|
541 | + /** |
|
542 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
543 | + * @throws InvalidInterfaceException |
|
544 | + * @throws InvalidDataTypeException |
|
545 | + * @throws EE_Error |
|
546 | + * @throws InvalidArgumentException |
|
547 | + */ |
|
548 | + public function get_total_line_items_with_no_transaction() |
|
549 | + { |
|
550 | + return $this->get_total_line_items_for_carts(); |
|
551 | + } |
|
552 | + |
|
553 | + |
|
554 | + /** |
|
555 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
556 | + * @throws InvalidInterfaceException |
|
557 | + * @throws InvalidDataTypeException |
|
558 | + * @throws EE_Error |
|
559 | + * @throws InvalidArgumentException |
|
560 | + */ |
|
561 | + public function get_total_line_items_for_active_carts() |
|
562 | + { |
|
563 | + return $this->get_total_line_items_for_carts(false); |
|
564 | + } |
|
565 | + |
|
566 | + |
|
567 | + /** |
|
568 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
569 | + * @throws InvalidInterfaceException |
|
570 | + * @throws InvalidDataTypeException |
|
571 | + * @throws EE_Error |
|
572 | + * @throws InvalidArgumentException |
|
573 | + */ |
|
574 | + public function get_total_line_items_for_expired_carts() |
|
575 | + { |
|
576 | + return $this->get_total_line_items_for_carts(true); |
|
577 | + } |
|
578 | + |
|
579 | + |
|
580 | + /** |
|
581 | + * Returns an array of grand total line items where the TXN_ID is 0. |
|
582 | + * If $expired is set to true, then only line items for expired sessions will be returned. |
|
583 | + * If $expired is set to false, then only line items for active sessions will be returned. |
|
584 | + * |
|
585 | + * @param null $expired |
|
586 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
587 | + * @throws EE_Error |
|
588 | + * @throws InvalidArgumentException |
|
589 | + * @throws InvalidDataTypeException |
|
590 | + * @throws InvalidInterfaceException |
|
591 | + */ |
|
592 | + private function get_total_line_items_for_carts($expired = null) |
|
593 | + { |
|
594 | + $where_params = array( |
|
595 | + 'TXN_ID' => 0, |
|
596 | + 'LIN_type' => 'total', |
|
597 | + ); |
|
598 | + if ($expired !== null) { |
|
599 | + /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
600 | + $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
601 | + 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
602 | + ); |
|
603 | + $where_params['LIN_timestamp'] = array( |
|
604 | + $expired ? '<=' : '>', |
|
605 | + $session_lifespan->expiration(), |
|
606 | + ); |
|
607 | + } |
|
608 | + return $this->get_all(array($where_params)); |
|
609 | + } |
|
610 | + |
|
611 | + |
|
612 | + /** |
|
613 | + * Returns an array of ticket total line items where the TXN_ID is 0 |
|
614 | + * AND the timestamp is older than the session lifespan. |
|
615 | + * |
|
616 | + * @param int $timestamp |
|
617 | + * @return EE_Base_Class[]|EE_Line_Item[] |
|
618 | + * @throws EE_Error |
|
619 | + * @throws InvalidArgumentException |
|
620 | + * @throws InvalidDataTypeException |
|
621 | + * @throws InvalidInterfaceException |
|
622 | + */ |
|
623 | + public function getTicketLineItemsForExpiredCarts($timestamp = 0) |
|
624 | + { |
|
625 | + if (! absint($timestamp)) { |
|
626 | + /** @var EventEspresso\core\domain\values\session\SessionLifespan $session_lifespan */ |
|
627 | + $session_lifespan = LoaderFactory::getLoader()->getShared( |
|
628 | + 'EventEspresso\core\domain\values\session\SessionLifespan' |
|
629 | + ); |
|
630 | + $timestamp = $session_lifespan->expiration(); |
|
631 | + } |
|
632 | + return $this->get_all( |
|
633 | + array( |
|
634 | + array( |
|
635 | + 'TXN_ID' => 0, |
|
636 | + 'OBJ_type' => EEM_Line_Item::OBJ_TYPE_TICKET, |
|
637 | + 'LIN_timestamp' => array('<=', $timestamp), |
|
638 | + ), |
|
639 | + ) |
|
640 | + ); |
|
641 | + } |
|
642 | 642 | } |