@@ -13,40 +13,40 @@ |
||
13 | 13 | |
14 | 14 | |
15 | 15 | |
16 | - // private instance of the EEM_Ticket_Template object |
|
17 | - protected static $_instance = null; |
|
16 | + // private instance of the EEM_Ticket_Template object |
|
17 | + protected static $_instance = null; |
|
18 | 18 | |
19 | - /** |
|
20 | - * private constructor to prevent direct creation |
|
21 | - * @Constructor |
|
22 | - * @access private |
|
23 | - * @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) |
|
24 | - * @return void |
|
25 | - */ |
|
26 | - protected function __construct($timezone) |
|
27 | - { |
|
28 | - $this->singular_item = __('Ticket Template', 'event_espresso'); |
|
29 | - $this->plural_item = __('Ticket Templates', 'event_espresso'); |
|
19 | + /** |
|
20 | + * private constructor to prevent direct creation |
|
21 | + * @Constructor |
|
22 | + * @access private |
|
23 | + * @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) |
|
24 | + * @return void |
|
25 | + */ |
|
26 | + protected function __construct($timezone) |
|
27 | + { |
|
28 | + $this->singular_item = __('Ticket Template', 'event_espresso'); |
|
29 | + $this->plural_item = __('Ticket Templates', 'event_espresso'); |
|
30 | 30 | |
31 | - $this->_tables = array( |
|
32 | - 'Ticket_Template'=> new EE_Primary_Table('esp_ticket_template', 'TTM_ID') |
|
33 | - ); |
|
34 | - $this->_fields = array( |
|
35 | - 'Ticket_Template'=>array( |
|
36 | - 'TTM_ID'=>new EE_Primary_Key_Int_Field('TTM_ID', __('Ticket Template ID', 'event_espresso')), |
|
37 | - 'TTM_name'=>new EE_Plain_Text_Field('TTM_name', __('The name of the ticket template', 'event_espresso'), false, ''), |
|
38 | - 'TTM_description'=>new EE_Plain_Text_Field('TTM_description', __('The description for the ticket template', 'event_espresso'), true, ''), |
|
39 | - 'TTM_file'=>new EE_Plain_Text_Field('TTM_file', __('The file name for the actual template file saved on disk', 'event_espresso'), true, ''), |
|
40 | - )); |
|
41 | - $this->_model_relations = array( |
|
42 | - 'Ticket'=>new EE_Has_Many_Relation() |
|
43 | - ); |
|
44 | - $this->_model_chain_to_wp_user = 'Ticket'; |
|
45 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
46 | - // account for default tickets in the caps |
|
47 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
48 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
49 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
50 | - parent::__construct($timezone); |
|
51 | - } |
|
31 | + $this->_tables = array( |
|
32 | + 'Ticket_Template'=> new EE_Primary_Table('esp_ticket_template', 'TTM_ID') |
|
33 | + ); |
|
34 | + $this->_fields = array( |
|
35 | + 'Ticket_Template'=>array( |
|
36 | + 'TTM_ID'=>new EE_Primary_Key_Int_Field('TTM_ID', __('Ticket Template ID', 'event_espresso')), |
|
37 | + 'TTM_name'=>new EE_Plain_Text_Field('TTM_name', __('The name of the ticket template', 'event_espresso'), false, ''), |
|
38 | + 'TTM_description'=>new EE_Plain_Text_Field('TTM_description', __('The description for the ticket template', 'event_espresso'), true, ''), |
|
39 | + 'TTM_file'=>new EE_Plain_Text_Field('TTM_file', __('The file name for the actual template file saved on disk', 'event_espresso'), true, ''), |
|
40 | + )); |
|
41 | + $this->_model_relations = array( |
|
42 | + 'Ticket'=>new EE_Has_Many_Relation() |
|
43 | + ); |
|
44 | + $this->_model_chain_to_wp_user = 'Ticket'; |
|
45 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
46 | + // account for default tickets in the caps |
|
47 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
48 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
49 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
50 | + parent::__construct($timezone); |
|
51 | + } |
|
52 | 52 | } |
@@ -42,11 +42,11 @@ |
||
42 | 42 | 'Ticket'=>new EE_Has_Many_Relation() |
43 | 43 | ); |
44 | 44 | $this->_model_chain_to_wp_user = 'Ticket'; |
45 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
45 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Default_Public('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
46 | 46 | // account for default tickets in the caps |
47 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
48 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
49 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
47 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
48 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
49 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Default_Protected('Ticket.TKT_is_default', 'Ticket.Datetime.Event'); |
|
50 | 50 | parent::__construct($timezone); |
51 | 51 | } |
52 | 52 | } |
@@ -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 | } |
@@ -227,7 +227,7 @@ discard block |
||
227 | 227 | { |
228 | 228 | if ($model === EEM_Term_Relationship::instance()) { |
229 | 229 | $taxonomies = get_taxonomies(array('show_in_rest' => true)); |
230 | - if (! empty($taxonomies)) { |
|
230 | + if ( ! empty($taxonomies)) { |
|
231 | 231 | $model_query_params[0]['Term_Taxonomy.taxonomy'] = array('IN', $taxonomies); |
232 | 232 | } |
233 | 233 | } |
@@ -9,233 +9,233 @@ |
||
9 | 9 | class EEM_Term_Relationship extends EEM_Base |
10 | 10 | { |
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 = __('Term Relationship', 'event_espresso'); |
|
25 | - $this->plural_item = __('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 | - __('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 | - __( |
|
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 | - __('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 = __('Term Relationship', 'event_espresso'); |
|
25 | + $this->plural_item = __('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 | + __('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 | + __( |
|
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 | + __('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 EEM_Base::get_all |
|
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 EEM_Base::get_all |
|
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 EEM_Base::get_all |
|
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 EEM_Base::get_all |
|
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 | } |
@@ -9,623 +9,623 @@ |
||
9 | 9 | class EEM_Message extends EEM_Base implements EEI_Query_Filter |
10 | 10 | { |
11 | 11 | |
12 | - // private instance of the Message object |
|
13 | - protected static $_instance = null; |
|
12 | + // private instance of the Message object |
|
13 | + protected static $_instance = null; |
|
14 | 14 | |
15 | 15 | |
16 | - /** |
|
17 | - * This priority indicates a message should be generated and sent ASAP |
|
18 | - * |
|
19 | - * @type int |
|
20 | - */ |
|
21 | - const priority_high = 10; |
|
22 | - |
|
23 | - |
|
24 | - /** |
|
25 | - * This priority indicates a message should be generated ASAP and queued for sending. |
|
26 | - * |
|
27 | - * @type |
|
28 | - */ |
|
29 | - const priority_medium = 20; |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * This priority indicates a message should be queued for generating. |
|
34 | - * |
|
35 | - * @type int |
|
36 | - */ |
|
37 | - const priority_low = 30; |
|
38 | - |
|
39 | - |
|
40 | - /** |
|
41 | - * indicates this message was sent at the time modified |
|
42 | - */ |
|
43 | - const status_sent = 'MSN'; |
|
44 | - |
|
45 | - |
|
46 | - /** |
|
47 | - * indicates this message is waiting to be sent |
|
48 | - */ |
|
49 | - const status_idle = 'MID'; |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * indicates an attempt was a made to send this message |
|
54 | - * at the scheduled time, but it failed at the time modified. This differs from MDO status in that it will ALWAYS |
|
55 | - * appear to the end user. |
|
56 | - */ |
|
57 | - const status_failed = 'MFL'; |
|
58 | - |
|
59 | - |
|
60 | - /** |
|
61 | - * indicates the message has been flagged for resending (at the time modified). |
|
62 | - */ |
|
63 | - const status_resend = 'MRS'; |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * indicates the message has been flagged for generation but has not been generated yet. Messages always start as |
|
68 | - * this status when added to the queue. |
|
69 | - */ |
|
70 | - const status_incomplete = 'MIC'; |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * Indicates everything was generated fine for the message, however, the messenger was unable to send. |
|
75 | - * This status means that its possible to retry sending the message. |
|
76 | - */ |
|
77 | - const status_retry = 'MRT'; |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * This is used for more informational messages that may not indicate anything is broken but still cannot be |
|
82 | - * generated or sent correctly. An example of a message that would get flagged this way would be when a not |
|
83 | - * approved message was queued for generation, but at time of generation, the attached registration(s) are |
|
84 | - * approved. So the message queued for generation is no longer valid. Messages for this status will only persist |
|
85 | - * in the db and be viewable in the message activity list table when the messages system is in debug mode. |
|
86 | - * |
|
87 | - * @see EEM_Message::debug() |
|
88 | - */ |
|
89 | - const status_debug_only = 'MDO'; |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * This status is given to messages it is processed by the messenger send method. |
|
94 | - * Messages with this status should rarely be seen in the Message List table, but if they are, that's usually |
|
95 | - * indicative of a PHP timeout or memory limit issue. |
|
96 | - */ |
|
97 | - const status_messenger_executing = 'MEX'; |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * Private constructor to prevent direct creation. |
|
102 | - * |
|
103 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and |
|
104 | - * any incoming timezone data that gets saved). Note this just sends the timezone info to |
|
105 | - * the date time model field objects. Default is null (and will be assumed using the set |
|
106 | - * timezone in the 'timezone_string' wp option) |
|
107 | - * @return EEM_Message |
|
108 | - */ |
|
109 | - protected function __construct($timezone = null) |
|
110 | - { |
|
111 | - $this->singular_item = __('Message', 'event_espresso'); |
|
112 | - $this->plural_item = __('Messages', 'event_espresso'); |
|
113 | - |
|
114 | - // used for token generator |
|
115 | - EE_Registry::instance()->load_helper('URL'); |
|
116 | - |
|
117 | - $this->_tables = array( |
|
118 | - 'Message' => new EE_Primary_Table('esp_message', 'MSG_ID'), |
|
119 | - ); |
|
120 | - |
|
121 | - $allowed_priority = array( |
|
122 | - self::priority_high => __('high', 'event_espresso'), |
|
123 | - self::priority_medium => __('medium', 'event_espresso'), |
|
124 | - self::priority_low => __('low', 'event_espresso'), |
|
125 | - ); |
|
126 | - |
|
127 | - $this->_fields = array( |
|
128 | - 'Message' => array( |
|
129 | - 'MSG_ID' => new EE_Primary_Key_Int_Field('MSG_ID', __('Message ID', 'event_espresso')), |
|
130 | - 'MSG_token' => new EE_Plain_Text_Field( |
|
131 | - 'MSG_token', |
|
132 | - __( |
|
133 | - 'Unique Token used to represent this row in publicly viewable contexts (eg. a url).', |
|
134 | - 'event_espresso' |
|
135 | - ), |
|
136 | - false, |
|
137 | - EEH_URL::generate_unique_token() |
|
138 | - ), |
|
139 | - 'GRP_ID' => new EE_Foreign_Key_Int_Field( |
|
140 | - 'GRP_ID', |
|
141 | - __('Foreign key to the EEM_Message_Template_Group table.', 'event_espresso'), |
|
142 | - true, |
|
143 | - 0, |
|
144 | - 'Message_Template_Group' |
|
145 | - ), |
|
146 | - 'TXN_ID' => new EE_Foreign_Key_Int_Field( |
|
147 | - 'TXN_ID', |
|
148 | - __( |
|
149 | - 'Foreign key to the related EE_Transaction. This is required to give context for regenerating the specific message', |
|
150 | - 'event_espresso' |
|
151 | - ), |
|
152 | - true, |
|
153 | - 0, |
|
154 | - 'Transaction' |
|
155 | - ), |
|
156 | - 'MSG_messenger' => new EE_Plain_Text_Field( |
|
157 | - 'MSG_messenger', |
|
158 | - __( |
|
159 | - 'Corresponds to the EE_messenger::name used to send this message. This will also be used to attempt any resending of the message.', |
|
160 | - 'event_espresso' |
|
161 | - ), |
|
162 | - false, |
|
163 | - 'email' |
|
164 | - ), |
|
165 | - 'MSG_message_type' => new EE_Plain_Text_Field( |
|
166 | - 'MSG_message_type', |
|
167 | - __('Corresponds to the EE_message_type::name used to generate this message.', 'event_espresso'), |
|
168 | - false, |
|
169 | - 'receipt' |
|
170 | - ), |
|
171 | - 'MSG_context' => new EE_Plain_Text_Field('MSG_context', __('Context', 'event_espresso'), false), |
|
172 | - 'MSG_recipient_ID' => new EE_Foreign_Key_Int_Field( |
|
173 | - 'MSG_recipient_ID', |
|
174 | - __('Recipient ID', 'event_espresso'), |
|
175 | - true, |
|
176 | - null, |
|
177 | - array('Registration', 'Attendee', 'WP_User') |
|
178 | - ), |
|
179 | - 'MSG_recipient_type' => new EE_Any_Foreign_Model_Name_Field( |
|
180 | - 'MSG_recipient_type', |
|
181 | - __('Recipient Type', 'event_espresso'), |
|
182 | - true, |
|
183 | - null, |
|
184 | - array('Registration', 'Attendee', 'WP_User') |
|
185 | - ), |
|
186 | - 'MSG_content' => new EE_Maybe_Serialized_Text_Field( |
|
187 | - 'MSG_content', |
|
188 | - __('Content', 'event_espresso'), |
|
189 | - true, |
|
190 | - '' |
|
191 | - ), |
|
192 | - 'MSG_to' => new EE_Maybe_Serialized_Text_Field( |
|
193 | - 'MSG_to', |
|
194 | - __('Address To', 'event_espresso'), |
|
195 | - true |
|
196 | - ), |
|
197 | - 'MSG_from' => new EE_Maybe_Serialized_Text_Field( |
|
198 | - 'MSG_from', |
|
199 | - __('Address From', 'event_espresso'), |
|
200 | - true |
|
201 | - ), |
|
202 | - 'MSG_subject' => new EE_Maybe_Serialized_Text_Field( |
|
203 | - 'MSG_subject', |
|
204 | - __('Subject', 'event_espresso'), |
|
205 | - true, |
|
206 | - '' |
|
207 | - ), |
|
208 | - 'MSG_priority' => new EE_Enum_Integer_Field( |
|
209 | - 'MSG_priority', |
|
210 | - __('Priority', 'event_espresso'), |
|
211 | - false, |
|
212 | - self::priority_low, |
|
213 | - $allowed_priority |
|
214 | - ), |
|
215 | - 'STS_ID' => new EE_Foreign_Key_String_Field( |
|
216 | - 'STS_ID', |
|
217 | - __('Status', 'event_espresso'), |
|
218 | - false, |
|
219 | - self::status_incomplete, |
|
220 | - 'Status' |
|
221 | - ), |
|
222 | - 'MSG_created' => new EE_Datetime_Field( |
|
223 | - 'MSG_created', |
|
224 | - __('Created', 'event_espresso'), |
|
225 | - false, |
|
226 | - EE_Datetime_Field::now |
|
227 | - ), |
|
228 | - 'MSG_modified' => new EE_Datetime_Field( |
|
229 | - 'MSG_modified', |
|
230 | - __('Modified', 'event_espresso'), |
|
231 | - true, |
|
232 | - EE_Datetime_Field::now |
|
233 | - ), |
|
234 | - ), |
|
235 | - ); |
|
236 | - $this->_model_relations = array( |
|
237 | - 'Attendee' => new EE_Belongs_To_Any_Relation(), |
|
238 | - 'Registration' => new EE_Belongs_To_Any_Relation(), |
|
239 | - 'WP_User' => new EE_Belongs_To_Any_Relation(), |
|
240 | - 'Message_Template_Group' => new EE_Belongs_To_Relation(), |
|
241 | - 'Transaction' => new EE_Belongs_To_Relation(), |
|
242 | - ); |
|
243 | - parent::__construct($timezone); |
|
244 | - } |
|
245 | - |
|
246 | - |
|
247 | - /** |
|
248 | - * @return \EE_Message |
|
249 | - */ |
|
250 | - public function create_default_object() |
|
251 | - { |
|
252 | - /** @type EE_Message $message */ |
|
253 | - $message = parent::create_default_object(); |
|
254 | - if ($message instanceof EE_Message) { |
|
255 | - return EE_Message_Factory::set_messenger_and_message_type($message); |
|
256 | - } |
|
257 | - return null; |
|
258 | - } |
|
259 | - |
|
260 | - |
|
261 | - /** |
|
262 | - * @param mixed $cols_n_values |
|
263 | - * @return \EE_Message |
|
264 | - */ |
|
265 | - public function instantiate_class_from_array_or_object($cols_n_values) |
|
266 | - { |
|
267 | - /** @type EE_Message $message */ |
|
268 | - $message = parent::instantiate_class_from_array_or_object($cols_n_values); |
|
269 | - if ($message instanceof EE_Message) { |
|
270 | - return EE_Message_Factory::set_messenger_and_message_type($message); |
|
271 | - } |
|
272 | - return null; |
|
273 | - } |
|
274 | - |
|
275 | - |
|
276 | - /** |
|
277 | - * Returns whether or not a message of that type was sent for a given attendee. |
|
278 | - * |
|
279 | - * @param EE_Attendee|int $attendee |
|
280 | - * @param string $message_type the message type slug |
|
281 | - * @return boolean |
|
282 | - */ |
|
283 | - public function message_sent_for_attendee($attendee, $message_type) |
|
284 | - { |
|
285 | - $attendee_ID = EEM_Attendee::instance()->ensure_is_ID($attendee); |
|
286 | - return $this->exists(array( |
|
287 | - array( |
|
288 | - 'Attendee.ATT_ID' => $attendee_ID, |
|
289 | - 'MSG_message_type' => $message_type, |
|
290 | - 'STS_ID' => array('IN', $this->stati_indicating_sent()), |
|
291 | - ), |
|
292 | - )); |
|
293 | - } |
|
294 | - |
|
295 | - |
|
296 | - /** |
|
297 | - * Returns whether or not a message of that type was sent for a given registration |
|
298 | - * |
|
299 | - * @param EE_Registration|int $registration |
|
300 | - * @param string $message_type the message type slug |
|
301 | - * @return boolean |
|
302 | - */ |
|
303 | - public function message_sent_for_registration($registration, $message_type) |
|
304 | - { |
|
305 | - $registrationID = EEM_Registration::instance()->ensure_is_ID($registration); |
|
306 | - return $this->exists(array( |
|
307 | - array( |
|
308 | - 'Registration.REG_ID' => $registrationID, |
|
309 | - 'MSG_message_type' => $message_type, |
|
310 | - 'STS_ID' => array('IN', $this->stati_indicating_sent()), |
|
311 | - ), |
|
312 | - )); |
|
313 | - } |
|
314 | - |
|
315 | - |
|
316 | - /** |
|
317 | - * This retrieves an EE_Message object from the db matching the given token string. |
|
318 | - * |
|
319 | - * @param string $token |
|
320 | - * @return EE_Message |
|
321 | - */ |
|
322 | - public function get_one_by_token($token) |
|
323 | - { |
|
324 | - return $this->get_one(array( |
|
325 | - array( |
|
326 | - 'MSG_token' => $token, |
|
327 | - ), |
|
328 | - )); |
|
329 | - } |
|
330 | - |
|
331 | - |
|
332 | - /** |
|
333 | - * Returns stati that indicate the message HAS been sent |
|
334 | - * |
|
335 | - * @return array of strings for possible stati |
|
336 | - */ |
|
337 | - public function stati_indicating_sent() |
|
338 | - { |
|
339 | - return apply_filters('FHEE__EEM_Message__stati_indicating_sent', array(self::status_sent)); |
|
340 | - } |
|
341 | - |
|
342 | - |
|
343 | - /** |
|
344 | - * Returns stati that indicate the message is waiting to be sent. |
|
345 | - * |
|
346 | - * @return array of strings for possible stati. |
|
347 | - */ |
|
348 | - public function stati_indicating_to_send() |
|
349 | - { |
|
350 | - return apply_filters( |
|
351 | - 'FHEE__EEM_Message__stati_indicating_to_send', |
|
352 | - array(self::status_idle, self::status_resend) |
|
353 | - ); |
|
354 | - } |
|
355 | - |
|
356 | - |
|
357 | - /** |
|
358 | - * Returns stati that indicate the message has failed sending |
|
359 | - * |
|
360 | - * @return array array of strings for possible stati. |
|
361 | - */ |
|
362 | - public function stati_indicating_failed_sending() |
|
363 | - { |
|
364 | - $failed_stati = array( |
|
365 | - self::status_failed, |
|
366 | - self::status_retry, |
|
367 | - self::status_messenger_executing, |
|
368 | - ); |
|
369 | - // if WP_DEBUG is set, then let's include debug_only fails |
|
370 | - if (WP_DEBUG) { |
|
371 | - $failed_stati[] = self::status_debug_only; |
|
372 | - } |
|
373 | - return apply_filters('FHEE__EEM_Message__stati_indicating_failed_sending', $failed_stati); |
|
374 | - } |
|
375 | - |
|
376 | - |
|
377 | - /** |
|
378 | - * Returns filterable array of all EEM_Message statuses. |
|
379 | - * |
|
380 | - * @return array |
|
381 | - */ |
|
382 | - public function all_statuses() |
|
383 | - { |
|
384 | - return apply_filters( |
|
385 | - 'FHEE__EEM_Message__all_statuses', |
|
386 | - array( |
|
387 | - EEM_Message::status_sent, |
|
388 | - EEM_Message::status_incomplete, |
|
389 | - EEM_Message::status_idle, |
|
390 | - EEM_Message::status_resend, |
|
391 | - EEM_Message::status_retry, |
|
392 | - EEM_Message::status_failed, |
|
393 | - EEM_Message::status_messenger_executing, |
|
394 | - EEM_Message::status_debug_only, |
|
395 | - ) |
|
396 | - ); |
|
397 | - } |
|
398 | - |
|
399 | - /** |
|
400 | - * Detects any specific query variables in the request and uses those to setup appropriate |
|
401 | - * filter for any queries. |
|
402 | - * |
|
403 | - * @return array |
|
404 | - */ |
|
405 | - public function filter_by_query_params() |
|
406 | - { |
|
407 | - // expected possible query_vars, the key in this array matches an expected key in the request, |
|
408 | - // the value, matches the corresponding EEM_Base child reference. |
|
409 | - $expected_vars = $this->_expected_vars_for_query_inject(); |
|
410 | - $query_params[0] = array(); |
|
411 | - foreach ($expected_vars as $request_key => $model_name) { |
|
412 | - $request_value = EE_Registry::instance()->REQ->get($request_key); |
|
413 | - if ($request_value) { |
|
414 | - // special case |
|
415 | - switch ($request_key) { |
|
416 | - case '_REG_ID': |
|
417 | - $query_params[0]['AND**filter_by']['OR**filter_by_REG_ID'] = array( |
|
418 | - 'Transaction.Registration.REG_ID' => $request_value, |
|
419 | - ); |
|
420 | - break; |
|
421 | - case 'EVT_ID': |
|
422 | - $query_params[0]['AND**filter_by']['OR**filter_by_EVT_ID'] = array( |
|
423 | - 'Transaction.Registration.EVT_ID' => $request_value, |
|
424 | - ); |
|
425 | - break; |
|
426 | - default: |
|
427 | - $query_params[0]['AND**filter_by'][ 'OR**filter_by_' . $request_key ][ $model_name . '.' . $request_key ] = $request_value; |
|
428 | - break; |
|
429 | - } |
|
430 | - } |
|
431 | - } |
|
432 | - return $query_params; |
|
433 | - } |
|
434 | - |
|
435 | - |
|
436 | - /** |
|
437 | - * @return string |
|
438 | - */ |
|
439 | - public function get_pretty_label_for_results() |
|
440 | - { |
|
441 | - $expected_vars = $this->_expected_vars_for_query_inject(); |
|
442 | - $pretty_label = ''; |
|
443 | - $label_parts = array(); |
|
444 | - foreach ($expected_vars as $request_key => $model_name) { |
|
445 | - $model = EE_Registry::instance()->load_model($model_name); |
|
446 | - if ($model_field_value = EE_Registry::instance()->REQ->get($request_key)) { |
|
447 | - switch ($request_key) { |
|
448 | - case '_REG_ID': |
|
449 | - $label_parts[] = sprintf( |
|
450 | - esc_html__('Registration with the ID: %s', 'event_espresso'), |
|
451 | - $model_field_value |
|
452 | - ); |
|
453 | - break; |
|
454 | - case 'ATT_ID': |
|
455 | - /** @var EE_Attendee $attendee */ |
|
456 | - $attendee = $model->get_one_by_ID($model_field_value); |
|
457 | - $label_parts[] = $attendee instanceof EE_Attendee |
|
458 | - ? sprintf(esc_html__('Attendee %s', 'event_espresso'), $attendee->full_name()) |
|
459 | - : sprintf(esc_html__('Attendee ID: %s', 'event_espresso'), $model_field_value); |
|
460 | - break; |
|
461 | - case 'ID': |
|
462 | - /** @var EE_WP_User $wpUser */ |
|
463 | - $wpUser = $model->get_one_by_ID($model_field_value); |
|
464 | - $label_parts[] = $wpUser instanceof EE_WP_User |
|
465 | - ? sprintf(esc_html__('WP User: %s', 'event_espresso'), $wpUser->name()) |
|
466 | - : sprintf(esc_html__('WP User ID: %s', 'event_espresso'), $model_field_value); |
|
467 | - break; |
|
468 | - case 'TXN_ID': |
|
469 | - $label_parts[] = sprintf( |
|
470 | - esc_html__('Transaction with the ID: %s', 'event_espresso'), |
|
471 | - $model_field_value |
|
472 | - ); |
|
473 | - break; |
|
474 | - case 'EVT_ID': |
|
475 | - /** @var EE_Event $Event */ |
|
476 | - $Event = $model->get_one_by_ID($model_field_value); |
|
477 | - $label_parts[] = $Event instanceof EE_Event |
|
478 | - ? sprintf(esc_html__('for the Event: %s', 'event_espresso'), $Event->name()) |
|
479 | - : sprintf(esc_html__('for the Event with ID: %s', 'event_espresso'), $model_field_value); |
|
480 | - break; |
|
481 | - } |
|
482 | - } |
|
483 | - } |
|
484 | - |
|
485 | - if ($label_parts) { |
|
486 | - // prepend to the last element of $label_parts an "and". |
|
487 | - if (count($label_parts) > 1) { |
|
488 | - $label_parts_index_to_prepend = count($label_parts) - 1; |
|
489 | - $label_parts[ $label_parts_index_to_prepend ] = 'and' . $label_parts[ $label_parts_index_to_prepend ]; |
|
490 | - } |
|
491 | - |
|
492 | - $pretty_label .= sprintf( |
|
493 | - esc_html_x( |
|
494 | - 'Showing messages for %s', |
|
495 | - 'A label for the messages returned in a query that are filtered by items in the query. This could be Transaction, Event, Attendee, Registration, or WP_User.', |
|
496 | - 'event_espresso' |
|
497 | - ), |
|
498 | - implode(', ', $label_parts) |
|
499 | - ); |
|
500 | - } |
|
501 | - return $pretty_label; |
|
502 | - } |
|
503 | - |
|
504 | - |
|
505 | - /** |
|
506 | - * This returns the array of expected variables for the EEI_Query_Filter methods being implemented |
|
507 | - * The array is in the format: |
|
508 | - * array( |
|
509 | - * {$field_name} => {$model_name} |
|
510 | - * ); |
|
511 | - * |
|
512 | - * @since 4.9.0 |
|
513 | - * @return array |
|
514 | - */ |
|
515 | - protected function _expected_vars_for_query_inject() |
|
516 | - { |
|
517 | - return array( |
|
518 | - '_REG_ID' => 'Registration', |
|
519 | - 'ATT_ID' => 'Attendee', |
|
520 | - 'ID' => 'WP_User', |
|
521 | - 'TXN_ID' => 'Transaction', |
|
522 | - 'EVT_ID' => 'Event', |
|
523 | - ); |
|
524 | - } |
|
525 | - |
|
526 | - |
|
527 | - /** |
|
528 | - * This returns whether EEM_Message is in debug mode or not. |
|
529 | - * Currently "debug mode" is used to control the handling of the EEM_Message::debug_only status when |
|
530 | - * generating/sending messages. Debug mode can be set by either: |
|
531 | - * 1. Sending in a value for the $set_debug argument |
|
532 | - * 2. Defining `EE_DEBUG_MESSAGES` constant in wp-config.php |
|
533 | - * 3. Overriding the above via the provided filter. |
|
534 | - * |
|
535 | - * @param bool|null $set_debug If provided, then the debug mode will be set internally until reset via the |
|
536 | - * provided boolean. When no argument is provided (default null) then the debug |
|
537 | - * mode will be returned. |
|
538 | - * @return bool true means Messages is in debug mode. false means messages system is not in debug mode. |
|
539 | - */ |
|
540 | - public static function debug($set_debug = null) |
|
541 | - { |
|
542 | - static $is_debugging = null; |
|
543 | - |
|
544 | - // initialize (use constant if set). |
|
545 | - if (is_null($set_debug) && is_null($is_debugging)) { |
|
546 | - $is_debugging = defined('EE_DEBUG_MESSAGES') && EE_DEBUG_MESSAGES; |
|
547 | - } |
|
548 | - |
|
549 | - if (! is_null($set_debug)) { |
|
550 | - $is_debugging = filter_var($set_debug, FILTER_VALIDATE_BOOLEAN); |
|
551 | - } |
|
552 | - |
|
553 | - // return filtered value |
|
554 | - return apply_filters('FHEE__EEM_Message__debug', $is_debugging); |
|
555 | - } |
|
556 | - |
|
557 | - |
|
558 | - /** |
|
559 | - * Deletes old messages meeting certain criteria for removal from the database. |
|
560 | - * By default, this will delete messages that: |
|
561 | - * - are older than the value of the delete_threshold in months. |
|
562 | - * - have a STS_ID other than EEM_Message::status_idle |
|
563 | - * |
|
564 | - * @param int $delete_threshold This integer will be used to set the boundary for what messages are deleted in months. |
|
565 | - * @return bool|false|int Either the number of records affected or false if there was an error (you can call |
|
566 | - * $wpdb->last_error to find out what the error was. |
|
567 | - */ |
|
568 | - public function delete_old_messages($delete_threshold = 6) |
|
569 | - { |
|
570 | - $number_deleted = 0; |
|
571 | - /** |
|
572 | - * Allows code to change the boundary for what messages are kept. |
|
573 | - * Uses the value of the `delete_threshold` variable by default. |
|
574 | - * |
|
575 | - * @param int $seconds seconds that will be subtracted from the timestamp for now. |
|
576 | - * @return int |
|
577 | - */ |
|
578 | - $time_to_leave_alone = absint( |
|
579 | - apply_filters( |
|
580 | - 'FHEE__EEM_Message__delete_old_messages__time_to_leave_alone', |
|
581 | - ((int) $delete_threshold) * MONTH_IN_SECONDS |
|
582 | - ) |
|
583 | - ); |
|
584 | - |
|
585 | - |
|
586 | - /** |
|
587 | - * Allows code to change what message stati are ignored when deleting. |
|
588 | - * Defaults to only ignore EEM_Message::status_idle messages. |
|
589 | - * |
|
590 | - * @param string $message_stati_to_keep An array of message statuses that will be ignored when deleting. |
|
591 | - */ |
|
592 | - $message_stati_to_keep = (array) apply_filters( |
|
593 | - 'FHEE__EEM_Message__delete_old_messages__message_stati_to_keep', |
|
594 | - array( |
|
595 | - EEM_Message::status_idle |
|
596 | - ) |
|
597 | - ); |
|
598 | - |
|
599 | - // first get all the ids of messages being deleted |
|
600 | - $message_ids_to_delete = EEM_Message::instance()->get_col( |
|
601 | - array( |
|
602 | - 0 => array( |
|
603 | - 'STS_ID' => array('NOT_IN', $message_stati_to_keep), |
|
604 | - 'MSG_modified' => array('<', time() - $time_to_leave_alone) |
|
605 | - ) |
|
606 | - ) |
|
607 | - ); |
|
608 | - |
|
609 | - if (! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) { |
|
610 | - global $wpdb; |
|
611 | - $number_deleted = $wpdb->query(' |
|
16 | + /** |
|
17 | + * This priority indicates a message should be generated and sent ASAP |
|
18 | + * |
|
19 | + * @type int |
|
20 | + */ |
|
21 | + const priority_high = 10; |
|
22 | + |
|
23 | + |
|
24 | + /** |
|
25 | + * This priority indicates a message should be generated ASAP and queued for sending. |
|
26 | + * |
|
27 | + * @type |
|
28 | + */ |
|
29 | + const priority_medium = 20; |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * This priority indicates a message should be queued for generating. |
|
34 | + * |
|
35 | + * @type int |
|
36 | + */ |
|
37 | + const priority_low = 30; |
|
38 | + |
|
39 | + |
|
40 | + /** |
|
41 | + * indicates this message was sent at the time modified |
|
42 | + */ |
|
43 | + const status_sent = 'MSN'; |
|
44 | + |
|
45 | + |
|
46 | + /** |
|
47 | + * indicates this message is waiting to be sent |
|
48 | + */ |
|
49 | + const status_idle = 'MID'; |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * indicates an attempt was a made to send this message |
|
54 | + * at the scheduled time, but it failed at the time modified. This differs from MDO status in that it will ALWAYS |
|
55 | + * appear to the end user. |
|
56 | + */ |
|
57 | + const status_failed = 'MFL'; |
|
58 | + |
|
59 | + |
|
60 | + /** |
|
61 | + * indicates the message has been flagged for resending (at the time modified). |
|
62 | + */ |
|
63 | + const status_resend = 'MRS'; |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * indicates the message has been flagged for generation but has not been generated yet. Messages always start as |
|
68 | + * this status when added to the queue. |
|
69 | + */ |
|
70 | + const status_incomplete = 'MIC'; |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * Indicates everything was generated fine for the message, however, the messenger was unable to send. |
|
75 | + * This status means that its possible to retry sending the message. |
|
76 | + */ |
|
77 | + const status_retry = 'MRT'; |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * This is used for more informational messages that may not indicate anything is broken but still cannot be |
|
82 | + * generated or sent correctly. An example of a message that would get flagged this way would be when a not |
|
83 | + * approved message was queued for generation, but at time of generation, the attached registration(s) are |
|
84 | + * approved. So the message queued for generation is no longer valid. Messages for this status will only persist |
|
85 | + * in the db and be viewable in the message activity list table when the messages system is in debug mode. |
|
86 | + * |
|
87 | + * @see EEM_Message::debug() |
|
88 | + */ |
|
89 | + const status_debug_only = 'MDO'; |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * This status is given to messages it is processed by the messenger send method. |
|
94 | + * Messages with this status should rarely be seen in the Message List table, but if they are, that's usually |
|
95 | + * indicative of a PHP timeout or memory limit issue. |
|
96 | + */ |
|
97 | + const status_messenger_executing = 'MEX'; |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * Private constructor to prevent direct creation. |
|
102 | + * |
|
103 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and |
|
104 | + * any incoming timezone data that gets saved). Note this just sends the timezone info to |
|
105 | + * the date time model field objects. Default is null (and will be assumed using the set |
|
106 | + * timezone in the 'timezone_string' wp option) |
|
107 | + * @return EEM_Message |
|
108 | + */ |
|
109 | + protected function __construct($timezone = null) |
|
110 | + { |
|
111 | + $this->singular_item = __('Message', 'event_espresso'); |
|
112 | + $this->plural_item = __('Messages', 'event_espresso'); |
|
113 | + |
|
114 | + // used for token generator |
|
115 | + EE_Registry::instance()->load_helper('URL'); |
|
116 | + |
|
117 | + $this->_tables = array( |
|
118 | + 'Message' => new EE_Primary_Table('esp_message', 'MSG_ID'), |
|
119 | + ); |
|
120 | + |
|
121 | + $allowed_priority = array( |
|
122 | + self::priority_high => __('high', 'event_espresso'), |
|
123 | + self::priority_medium => __('medium', 'event_espresso'), |
|
124 | + self::priority_low => __('low', 'event_espresso'), |
|
125 | + ); |
|
126 | + |
|
127 | + $this->_fields = array( |
|
128 | + 'Message' => array( |
|
129 | + 'MSG_ID' => new EE_Primary_Key_Int_Field('MSG_ID', __('Message ID', 'event_espresso')), |
|
130 | + 'MSG_token' => new EE_Plain_Text_Field( |
|
131 | + 'MSG_token', |
|
132 | + __( |
|
133 | + 'Unique Token used to represent this row in publicly viewable contexts (eg. a url).', |
|
134 | + 'event_espresso' |
|
135 | + ), |
|
136 | + false, |
|
137 | + EEH_URL::generate_unique_token() |
|
138 | + ), |
|
139 | + 'GRP_ID' => new EE_Foreign_Key_Int_Field( |
|
140 | + 'GRP_ID', |
|
141 | + __('Foreign key to the EEM_Message_Template_Group table.', 'event_espresso'), |
|
142 | + true, |
|
143 | + 0, |
|
144 | + 'Message_Template_Group' |
|
145 | + ), |
|
146 | + 'TXN_ID' => new EE_Foreign_Key_Int_Field( |
|
147 | + 'TXN_ID', |
|
148 | + __( |
|
149 | + 'Foreign key to the related EE_Transaction. This is required to give context for regenerating the specific message', |
|
150 | + 'event_espresso' |
|
151 | + ), |
|
152 | + true, |
|
153 | + 0, |
|
154 | + 'Transaction' |
|
155 | + ), |
|
156 | + 'MSG_messenger' => new EE_Plain_Text_Field( |
|
157 | + 'MSG_messenger', |
|
158 | + __( |
|
159 | + 'Corresponds to the EE_messenger::name used to send this message. This will also be used to attempt any resending of the message.', |
|
160 | + 'event_espresso' |
|
161 | + ), |
|
162 | + false, |
|
163 | + 'email' |
|
164 | + ), |
|
165 | + 'MSG_message_type' => new EE_Plain_Text_Field( |
|
166 | + 'MSG_message_type', |
|
167 | + __('Corresponds to the EE_message_type::name used to generate this message.', 'event_espresso'), |
|
168 | + false, |
|
169 | + 'receipt' |
|
170 | + ), |
|
171 | + 'MSG_context' => new EE_Plain_Text_Field('MSG_context', __('Context', 'event_espresso'), false), |
|
172 | + 'MSG_recipient_ID' => new EE_Foreign_Key_Int_Field( |
|
173 | + 'MSG_recipient_ID', |
|
174 | + __('Recipient ID', 'event_espresso'), |
|
175 | + true, |
|
176 | + null, |
|
177 | + array('Registration', 'Attendee', 'WP_User') |
|
178 | + ), |
|
179 | + 'MSG_recipient_type' => new EE_Any_Foreign_Model_Name_Field( |
|
180 | + 'MSG_recipient_type', |
|
181 | + __('Recipient Type', 'event_espresso'), |
|
182 | + true, |
|
183 | + null, |
|
184 | + array('Registration', 'Attendee', 'WP_User') |
|
185 | + ), |
|
186 | + 'MSG_content' => new EE_Maybe_Serialized_Text_Field( |
|
187 | + 'MSG_content', |
|
188 | + __('Content', 'event_espresso'), |
|
189 | + true, |
|
190 | + '' |
|
191 | + ), |
|
192 | + 'MSG_to' => new EE_Maybe_Serialized_Text_Field( |
|
193 | + 'MSG_to', |
|
194 | + __('Address To', 'event_espresso'), |
|
195 | + true |
|
196 | + ), |
|
197 | + 'MSG_from' => new EE_Maybe_Serialized_Text_Field( |
|
198 | + 'MSG_from', |
|
199 | + __('Address From', 'event_espresso'), |
|
200 | + true |
|
201 | + ), |
|
202 | + 'MSG_subject' => new EE_Maybe_Serialized_Text_Field( |
|
203 | + 'MSG_subject', |
|
204 | + __('Subject', 'event_espresso'), |
|
205 | + true, |
|
206 | + '' |
|
207 | + ), |
|
208 | + 'MSG_priority' => new EE_Enum_Integer_Field( |
|
209 | + 'MSG_priority', |
|
210 | + __('Priority', 'event_espresso'), |
|
211 | + false, |
|
212 | + self::priority_low, |
|
213 | + $allowed_priority |
|
214 | + ), |
|
215 | + 'STS_ID' => new EE_Foreign_Key_String_Field( |
|
216 | + 'STS_ID', |
|
217 | + __('Status', 'event_espresso'), |
|
218 | + false, |
|
219 | + self::status_incomplete, |
|
220 | + 'Status' |
|
221 | + ), |
|
222 | + 'MSG_created' => new EE_Datetime_Field( |
|
223 | + 'MSG_created', |
|
224 | + __('Created', 'event_espresso'), |
|
225 | + false, |
|
226 | + EE_Datetime_Field::now |
|
227 | + ), |
|
228 | + 'MSG_modified' => new EE_Datetime_Field( |
|
229 | + 'MSG_modified', |
|
230 | + __('Modified', 'event_espresso'), |
|
231 | + true, |
|
232 | + EE_Datetime_Field::now |
|
233 | + ), |
|
234 | + ), |
|
235 | + ); |
|
236 | + $this->_model_relations = array( |
|
237 | + 'Attendee' => new EE_Belongs_To_Any_Relation(), |
|
238 | + 'Registration' => new EE_Belongs_To_Any_Relation(), |
|
239 | + 'WP_User' => new EE_Belongs_To_Any_Relation(), |
|
240 | + 'Message_Template_Group' => new EE_Belongs_To_Relation(), |
|
241 | + 'Transaction' => new EE_Belongs_To_Relation(), |
|
242 | + ); |
|
243 | + parent::__construct($timezone); |
|
244 | + } |
|
245 | + |
|
246 | + |
|
247 | + /** |
|
248 | + * @return \EE_Message |
|
249 | + */ |
|
250 | + public function create_default_object() |
|
251 | + { |
|
252 | + /** @type EE_Message $message */ |
|
253 | + $message = parent::create_default_object(); |
|
254 | + if ($message instanceof EE_Message) { |
|
255 | + return EE_Message_Factory::set_messenger_and_message_type($message); |
|
256 | + } |
|
257 | + return null; |
|
258 | + } |
|
259 | + |
|
260 | + |
|
261 | + /** |
|
262 | + * @param mixed $cols_n_values |
|
263 | + * @return \EE_Message |
|
264 | + */ |
|
265 | + public function instantiate_class_from_array_or_object($cols_n_values) |
|
266 | + { |
|
267 | + /** @type EE_Message $message */ |
|
268 | + $message = parent::instantiate_class_from_array_or_object($cols_n_values); |
|
269 | + if ($message instanceof EE_Message) { |
|
270 | + return EE_Message_Factory::set_messenger_and_message_type($message); |
|
271 | + } |
|
272 | + return null; |
|
273 | + } |
|
274 | + |
|
275 | + |
|
276 | + /** |
|
277 | + * Returns whether or not a message of that type was sent for a given attendee. |
|
278 | + * |
|
279 | + * @param EE_Attendee|int $attendee |
|
280 | + * @param string $message_type the message type slug |
|
281 | + * @return boolean |
|
282 | + */ |
|
283 | + public function message_sent_for_attendee($attendee, $message_type) |
|
284 | + { |
|
285 | + $attendee_ID = EEM_Attendee::instance()->ensure_is_ID($attendee); |
|
286 | + return $this->exists(array( |
|
287 | + array( |
|
288 | + 'Attendee.ATT_ID' => $attendee_ID, |
|
289 | + 'MSG_message_type' => $message_type, |
|
290 | + 'STS_ID' => array('IN', $this->stati_indicating_sent()), |
|
291 | + ), |
|
292 | + )); |
|
293 | + } |
|
294 | + |
|
295 | + |
|
296 | + /** |
|
297 | + * Returns whether or not a message of that type was sent for a given registration |
|
298 | + * |
|
299 | + * @param EE_Registration|int $registration |
|
300 | + * @param string $message_type the message type slug |
|
301 | + * @return boolean |
|
302 | + */ |
|
303 | + public function message_sent_for_registration($registration, $message_type) |
|
304 | + { |
|
305 | + $registrationID = EEM_Registration::instance()->ensure_is_ID($registration); |
|
306 | + return $this->exists(array( |
|
307 | + array( |
|
308 | + 'Registration.REG_ID' => $registrationID, |
|
309 | + 'MSG_message_type' => $message_type, |
|
310 | + 'STS_ID' => array('IN', $this->stati_indicating_sent()), |
|
311 | + ), |
|
312 | + )); |
|
313 | + } |
|
314 | + |
|
315 | + |
|
316 | + /** |
|
317 | + * This retrieves an EE_Message object from the db matching the given token string. |
|
318 | + * |
|
319 | + * @param string $token |
|
320 | + * @return EE_Message |
|
321 | + */ |
|
322 | + public function get_one_by_token($token) |
|
323 | + { |
|
324 | + return $this->get_one(array( |
|
325 | + array( |
|
326 | + 'MSG_token' => $token, |
|
327 | + ), |
|
328 | + )); |
|
329 | + } |
|
330 | + |
|
331 | + |
|
332 | + /** |
|
333 | + * Returns stati that indicate the message HAS been sent |
|
334 | + * |
|
335 | + * @return array of strings for possible stati |
|
336 | + */ |
|
337 | + public function stati_indicating_sent() |
|
338 | + { |
|
339 | + return apply_filters('FHEE__EEM_Message__stati_indicating_sent', array(self::status_sent)); |
|
340 | + } |
|
341 | + |
|
342 | + |
|
343 | + /** |
|
344 | + * Returns stati that indicate the message is waiting to be sent. |
|
345 | + * |
|
346 | + * @return array of strings for possible stati. |
|
347 | + */ |
|
348 | + public function stati_indicating_to_send() |
|
349 | + { |
|
350 | + return apply_filters( |
|
351 | + 'FHEE__EEM_Message__stati_indicating_to_send', |
|
352 | + array(self::status_idle, self::status_resend) |
|
353 | + ); |
|
354 | + } |
|
355 | + |
|
356 | + |
|
357 | + /** |
|
358 | + * Returns stati that indicate the message has failed sending |
|
359 | + * |
|
360 | + * @return array array of strings for possible stati. |
|
361 | + */ |
|
362 | + public function stati_indicating_failed_sending() |
|
363 | + { |
|
364 | + $failed_stati = array( |
|
365 | + self::status_failed, |
|
366 | + self::status_retry, |
|
367 | + self::status_messenger_executing, |
|
368 | + ); |
|
369 | + // if WP_DEBUG is set, then let's include debug_only fails |
|
370 | + if (WP_DEBUG) { |
|
371 | + $failed_stati[] = self::status_debug_only; |
|
372 | + } |
|
373 | + return apply_filters('FHEE__EEM_Message__stati_indicating_failed_sending', $failed_stati); |
|
374 | + } |
|
375 | + |
|
376 | + |
|
377 | + /** |
|
378 | + * Returns filterable array of all EEM_Message statuses. |
|
379 | + * |
|
380 | + * @return array |
|
381 | + */ |
|
382 | + public function all_statuses() |
|
383 | + { |
|
384 | + return apply_filters( |
|
385 | + 'FHEE__EEM_Message__all_statuses', |
|
386 | + array( |
|
387 | + EEM_Message::status_sent, |
|
388 | + EEM_Message::status_incomplete, |
|
389 | + EEM_Message::status_idle, |
|
390 | + EEM_Message::status_resend, |
|
391 | + EEM_Message::status_retry, |
|
392 | + EEM_Message::status_failed, |
|
393 | + EEM_Message::status_messenger_executing, |
|
394 | + EEM_Message::status_debug_only, |
|
395 | + ) |
|
396 | + ); |
|
397 | + } |
|
398 | + |
|
399 | + /** |
|
400 | + * Detects any specific query variables in the request and uses those to setup appropriate |
|
401 | + * filter for any queries. |
|
402 | + * |
|
403 | + * @return array |
|
404 | + */ |
|
405 | + public function filter_by_query_params() |
|
406 | + { |
|
407 | + // expected possible query_vars, the key in this array matches an expected key in the request, |
|
408 | + // the value, matches the corresponding EEM_Base child reference. |
|
409 | + $expected_vars = $this->_expected_vars_for_query_inject(); |
|
410 | + $query_params[0] = array(); |
|
411 | + foreach ($expected_vars as $request_key => $model_name) { |
|
412 | + $request_value = EE_Registry::instance()->REQ->get($request_key); |
|
413 | + if ($request_value) { |
|
414 | + // special case |
|
415 | + switch ($request_key) { |
|
416 | + case '_REG_ID': |
|
417 | + $query_params[0]['AND**filter_by']['OR**filter_by_REG_ID'] = array( |
|
418 | + 'Transaction.Registration.REG_ID' => $request_value, |
|
419 | + ); |
|
420 | + break; |
|
421 | + case 'EVT_ID': |
|
422 | + $query_params[0]['AND**filter_by']['OR**filter_by_EVT_ID'] = array( |
|
423 | + 'Transaction.Registration.EVT_ID' => $request_value, |
|
424 | + ); |
|
425 | + break; |
|
426 | + default: |
|
427 | + $query_params[0]['AND**filter_by'][ 'OR**filter_by_' . $request_key ][ $model_name . '.' . $request_key ] = $request_value; |
|
428 | + break; |
|
429 | + } |
|
430 | + } |
|
431 | + } |
|
432 | + return $query_params; |
|
433 | + } |
|
434 | + |
|
435 | + |
|
436 | + /** |
|
437 | + * @return string |
|
438 | + */ |
|
439 | + public function get_pretty_label_for_results() |
|
440 | + { |
|
441 | + $expected_vars = $this->_expected_vars_for_query_inject(); |
|
442 | + $pretty_label = ''; |
|
443 | + $label_parts = array(); |
|
444 | + foreach ($expected_vars as $request_key => $model_name) { |
|
445 | + $model = EE_Registry::instance()->load_model($model_name); |
|
446 | + if ($model_field_value = EE_Registry::instance()->REQ->get($request_key)) { |
|
447 | + switch ($request_key) { |
|
448 | + case '_REG_ID': |
|
449 | + $label_parts[] = sprintf( |
|
450 | + esc_html__('Registration with the ID: %s', 'event_espresso'), |
|
451 | + $model_field_value |
|
452 | + ); |
|
453 | + break; |
|
454 | + case 'ATT_ID': |
|
455 | + /** @var EE_Attendee $attendee */ |
|
456 | + $attendee = $model->get_one_by_ID($model_field_value); |
|
457 | + $label_parts[] = $attendee instanceof EE_Attendee |
|
458 | + ? sprintf(esc_html__('Attendee %s', 'event_espresso'), $attendee->full_name()) |
|
459 | + : sprintf(esc_html__('Attendee ID: %s', 'event_espresso'), $model_field_value); |
|
460 | + break; |
|
461 | + case 'ID': |
|
462 | + /** @var EE_WP_User $wpUser */ |
|
463 | + $wpUser = $model->get_one_by_ID($model_field_value); |
|
464 | + $label_parts[] = $wpUser instanceof EE_WP_User |
|
465 | + ? sprintf(esc_html__('WP User: %s', 'event_espresso'), $wpUser->name()) |
|
466 | + : sprintf(esc_html__('WP User ID: %s', 'event_espresso'), $model_field_value); |
|
467 | + break; |
|
468 | + case 'TXN_ID': |
|
469 | + $label_parts[] = sprintf( |
|
470 | + esc_html__('Transaction with the ID: %s', 'event_espresso'), |
|
471 | + $model_field_value |
|
472 | + ); |
|
473 | + break; |
|
474 | + case 'EVT_ID': |
|
475 | + /** @var EE_Event $Event */ |
|
476 | + $Event = $model->get_one_by_ID($model_field_value); |
|
477 | + $label_parts[] = $Event instanceof EE_Event |
|
478 | + ? sprintf(esc_html__('for the Event: %s', 'event_espresso'), $Event->name()) |
|
479 | + : sprintf(esc_html__('for the Event with ID: %s', 'event_espresso'), $model_field_value); |
|
480 | + break; |
|
481 | + } |
|
482 | + } |
|
483 | + } |
|
484 | + |
|
485 | + if ($label_parts) { |
|
486 | + // prepend to the last element of $label_parts an "and". |
|
487 | + if (count($label_parts) > 1) { |
|
488 | + $label_parts_index_to_prepend = count($label_parts) - 1; |
|
489 | + $label_parts[ $label_parts_index_to_prepend ] = 'and' . $label_parts[ $label_parts_index_to_prepend ]; |
|
490 | + } |
|
491 | + |
|
492 | + $pretty_label .= sprintf( |
|
493 | + esc_html_x( |
|
494 | + 'Showing messages for %s', |
|
495 | + 'A label for the messages returned in a query that are filtered by items in the query. This could be Transaction, Event, Attendee, Registration, or WP_User.', |
|
496 | + 'event_espresso' |
|
497 | + ), |
|
498 | + implode(', ', $label_parts) |
|
499 | + ); |
|
500 | + } |
|
501 | + return $pretty_label; |
|
502 | + } |
|
503 | + |
|
504 | + |
|
505 | + /** |
|
506 | + * This returns the array of expected variables for the EEI_Query_Filter methods being implemented |
|
507 | + * The array is in the format: |
|
508 | + * array( |
|
509 | + * {$field_name} => {$model_name} |
|
510 | + * ); |
|
511 | + * |
|
512 | + * @since 4.9.0 |
|
513 | + * @return array |
|
514 | + */ |
|
515 | + protected function _expected_vars_for_query_inject() |
|
516 | + { |
|
517 | + return array( |
|
518 | + '_REG_ID' => 'Registration', |
|
519 | + 'ATT_ID' => 'Attendee', |
|
520 | + 'ID' => 'WP_User', |
|
521 | + 'TXN_ID' => 'Transaction', |
|
522 | + 'EVT_ID' => 'Event', |
|
523 | + ); |
|
524 | + } |
|
525 | + |
|
526 | + |
|
527 | + /** |
|
528 | + * This returns whether EEM_Message is in debug mode or not. |
|
529 | + * Currently "debug mode" is used to control the handling of the EEM_Message::debug_only status when |
|
530 | + * generating/sending messages. Debug mode can be set by either: |
|
531 | + * 1. Sending in a value for the $set_debug argument |
|
532 | + * 2. Defining `EE_DEBUG_MESSAGES` constant in wp-config.php |
|
533 | + * 3. Overriding the above via the provided filter. |
|
534 | + * |
|
535 | + * @param bool|null $set_debug If provided, then the debug mode will be set internally until reset via the |
|
536 | + * provided boolean. When no argument is provided (default null) then the debug |
|
537 | + * mode will be returned. |
|
538 | + * @return bool true means Messages is in debug mode. false means messages system is not in debug mode. |
|
539 | + */ |
|
540 | + public static function debug($set_debug = null) |
|
541 | + { |
|
542 | + static $is_debugging = null; |
|
543 | + |
|
544 | + // initialize (use constant if set). |
|
545 | + if (is_null($set_debug) && is_null($is_debugging)) { |
|
546 | + $is_debugging = defined('EE_DEBUG_MESSAGES') && EE_DEBUG_MESSAGES; |
|
547 | + } |
|
548 | + |
|
549 | + if (! is_null($set_debug)) { |
|
550 | + $is_debugging = filter_var($set_debug, FILTER_VALIDATE_BOOLEAN); |
|
551 | + } |
|
552 | + |
|
553 | + // return filtered value |
|
554 | + return apply_filters('FHEE__EEM_Message__debug', $is_debugging); |
|
555 | + } |
|
556 | + |
|
557 | + |
|
558 | + /** |
|
559 | + * Deletes old messages meeting certain criteria for removal from the database. |
|
560 | + * By default, this will delete messages that: |
|
561 | + * - are older than the value of the delete_threshold in months. |
|
562 | + * - have a STS_ID other than EEM_Message::status_idle |
|
563 | + * |
|
564 | + * @param int $delete_threshold This integer will be used to set the boundary for what messages are deleted in months. |
|
565 | + * @return bool|false|int Either the number of records affected or false if there was an error (you can call |
|
566 | + * $wpdb->last_error to find out what the error was. |
|
567 | + */ |
|
568 | + public function delete_old_messages($delete_threshold = 6) |
|
569 | + { |
|
570 | + $number_deleted = 0; |
|
571 | + /** |
|
572 | + * Allows code to change the boundary for what messages are kept. |
|
573 | + * Uses the value of the `delete_threshold` variable by default. |
|
574 | + * |
|
575 | + * @param int $seconds seconds that will be subtracted from the timestamp for now. |
|
576 | + * @return int |
|
577 | + */ |
|
578 | + $time_to_leave_alone = absint( |
|
579 | + apply_filters( |
|
580 | + 'FHEE__EEM_Message__delete_old_messages__time_to_leave_alone', |
|
581 | + ((int) $delete_threshold) * MONTH_IN_SECONDS |
|
582 | + ) |
|
583 | + ); |
|
584 | + |
|
585 | + |
|
586 | + /** |
|
587 | + * Allows code to change what message stati are ignored when deleting. |
|
588 | + * Defaults to only ignore EEM_Message::status_idle messages. |
|
589 | + * |
|
590 | + * @param string $message_stati_to_keep An array of message statuses that will be ignored when deleting. |
|
591 | + */ |
|
592 | + $message_stati_to_keep = (array) apply_filters( |
|
593 | + 'FHEE__EEM_Message__delete_old_messages__message_stati_to_keep', |
|
594 | + array( |
|
595 | + EEM_Message::status_idle |
|
596 | + ) |
|
597 | + ); |
|
598 | + |
|
599 | + // first get all the ids of messages being deleted |
|
600 | + $message_ids_to_delete = EEM_Message::instance()->get_col( |
|
601 | + array( |
|
602 | + 0 => array( |
|
603 | + 'STS_ID' => array('NOT_IN', $message_stati_to_keep), |
|
604 | + 'MSG_modified' => array('<', time() - $time_to_leave_alone) |
|
605 | + ) |
|
606 | + ) |
|
607 | + ); |
|
608 | + |
|
609 | + if (! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) { |
|
610 | + global $wpdb; |
|
611 | + $number_deleted = $wpdb->query(' |
|
612 | 612 | DELETE |
613 | 613 | FROM ' . $this->table() . ' |
614 | 614 | WHERE |
615 | 615 | MSG_ID IN (' . implode(",", $message_ids_to_delete) . ') |
616 | 616 | '); |
617 | - } |
|
618 | - |
|
619 | - /** |
|
620 | - * This will get called if the number of records deleted 0 or greater. So a successful deletion is one where |
|
621 | - * there were no errors. An unsuccessful deletion is where there were errors. Keep that in mind for the actions |
|
622 | - * below. |
|
623 | - */ |
|
624 | - if ($number_deleted !== false) { |
|
625 | - do_action('AHEE__EEM_Message__delete_old_messages__after_successful_deletion', $message_ids_to_delete, $number_deleted); |
|
626 | - } else { |
|
627 | - do_action('AHEE__EEM_Message__delete_old_messages__after_deletion_fail', $message_ids_to_delete, $number_deleted); |
|
628 | - } |
|
629 | - return $number_deleted; |
|
630 | - } |
|
617 | + } |
|
618 | + |
|
619 | + /** |
|
620 | + * This will get called if the number of records deleted 0 or greater. So a successful deletion is one where |
|
621 | + * there were no errors. An unsuccessful deletion is where there were errors. Keep that in mind for the actions |
|
622 | + * below. |
|
623 | + */ |
|
624 | + if ($number_deleted !== false) { |
|
625 | + do_action('AHEE__EEM_Message__delete_old_messages__after_successful_deletion', $message_ids_to_delete, $number_deleted); |
|
626 | + } else { |
|
627 | + do_action('AHEE__EEM_Message__delete_old_messages__after_deletion_fail', $message_ids_to_delete, $number_deleted); |
|
628 | + } |
|
629 | + return $number_deleted; |
|
630 | + } |
|
631 | 631 | } |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | self::priority_low => __('low', 'event_espresso'), |
125 | 125 | ); |
126 | 126 | |
127 | - $this->_fields = array( |
|
127 | + $this->_fields = array( |
|
128 | 128 | 'Message' => array( |
129 | 129 | 'MSG_ID' => new EE_Primary_Key_Int_Field('MSG_ID', __('Message ID', 'event_espresso')), |
130 | 130 | 'MSG_token' => new EE_Plain_Text_Field( |
@@ -424,7 +424,7 @@ discard block |
||
424 | 424 | ); |
425 | 425 | break; |
426 | 426 | default: |
427 | - $query_params[0]['AND**filter_by'][ 'OR**filter_by_' . $request_key ][ $model_name . '.' . $request_key ] = $request_value; |
|
427 | + $query_params[0]['AND**filter_by']['OR**filter_by_'.$request_key][$model_name.'.'.$request_key] = $request_value; |
|
428 | 428 | break; |
429 | 429 | } |
430 | 430 | } |
@@ -485,8 +485,8 @@ discard block |
||
485 | 485 | if ($label_parts) { |
486 | 486 | // prepend to the last element of $label_parts an "and". |
487 | 487 | if (count($label_parts) > 1) { |
488 | - $label_parts_index_to_prepend = count($label_parts) - 1; |
|
489 | - $label_parts[ $label_parts_index_to_prepend ] = 'and' . $label_parts[ $label_parts_index_to_prepend ]; |
|
488 | + $label_parts_index_to_prepend = count($label_parts) - 1; |
|
489 | + $label_parts[$label_parts_index_to_prepend] = 'and'.$label_parts[$label_parts_index_to_prepend]; |
|
490 | 490 | } |
491 | 491 | |
492 | 492 | $pretty_label .= sprintf( |
@@ -546,7 +546,7 @@ discard block |
||
546 | 546 | $is_debugging = defined('EE_DEBUG_MESSAGES') && EE_DEBUG_MESSAGES; |
547 | 547 | } |
548 | 548 | |
549 | - if (! is_null($set_debug)) { |
|
549 | + if ( ! is_null($set_debug)) { |
|
550 | 550 | $is_debugging = filter_var($set_debug, FILTER_VALIDATE_BOOLEAN); |
551 | 551 | } |
552 | 552 | |
@@ -606,13 +606,13 @@ discard block |
||
606 | 606 | ) |
607 | 607 | ); |
608 | 608 | |
609 | - if (! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) { |
|
609 | + if ( ! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) { |
|
610 | 610 | global $wpdb; |
611 | 611 | $number_deleted = $wpdb->query(' |
612 | 612 | DELETE |
613 | - FROM ' . $this->table() . ' |
|
613 | + FROM ' . $this->table().' |
|
614 | 614 | WHERE |
615 | - MSG_ID IN (' . implode(",", $message_ids_to_delete) . ') |
|
615 | + MSG_ID IN (' . implode(",", $message_ids_to_delete).') |
|
616 | 616 | '); |
617 | 617 | } |
618 | 618 |
@@ -7,34 +7,34 @@ |
||
7 | 7 | */ |
8 | 8 | class EEM_Event_Venue extends EEM_Base |
9 | 9 | { |
10 | - // private instance of the Attendee object |
|
11 | - protected static $_instance = null; |
|
10 | + // private instance of the Attendee object |
|
11 | + protected static $_instance = null; |
|
12 | 12 | |
13 | - protected function __construct($timezone = null) |
|
14 | - { |
|
15 | - $this->singular_item = __('Event to Question Group Link', 'event_espresso'); |
|
16 | - $this->plural_item = __('Event to Question Group Links', 'event_espresso'); |
|
17 | - $this->_tables = array( |
|
18 | - 'Event_Venue'=>new EE_Primary_Table('esp_event_venue', 'EVV_ID') |
|
19 | - ); |
|
20 | - $this->_fields = array( |
|
21 | - 'Event_Venue'=>array( |
|
22 | - 'EVV_ID'=>new EE_Primary_Key_Int_Field('EVV_ID', __('Event to Venue Link ID', 'event_espresso')), |
|
23 | - 'EVT_ID'=>new EE_Foreign_Key_Int_Field('EVT_ID', __('Event ID', 'event_espresso'), false, 0, 'Event'), |
|
24 | - 'VNU_ID'=>new EE_Foreign_Key_Int_Field('VNU_ID', __('Venue ID', 'event_espresso'), false, 0, 'Venue'), |
|
25 | - 'EVV_primary'=>new EE_Boolean_Field('EVV_primary', __("Flag indicating venue is primary one for event", "event_espresso"), false, true) |
|
13 | + protected function __construct($timezone = null) |
|
14 | + { |
|
15 | + $this->singular_item = __('Event to Question Group Link', 'event_espresso'); |
|
16 | + $this->plural_item = __('Event to Question Group Links', 'event_espresso'); |
|
17 | + $this->_tables = array( |
|
18 | + 'Event_Venue'=>new EE_Primary_Table('esp_event_venue', 'EVV_ID') |
|
19 | + ); |
|
20 | + $this->_fields = array( |
|
21 | + 'Event_Venue'=>array( |
|
22 | + 'EVV_ID'=>new EE_Primary_Key_Int_Field('EVV_ID', __('Event to Venue Link ID', 'event_espresso')), |
|
23 | + 'EVT_ID'=>new EE_Foreign_Key_Int_Field('EVT_ID', __('Event ID', 'event_espresso'), false, 0, 'Event'), |
|
24 | + 'VNU_ID'=>new EE_Foreign_Key_Int_Field('VNU_ID', __('Venue ID', 'event_espresso'), false, 0, 'Venue'), |
|
25 | + 'EVV_primary'=>new EE_Boolean_Field('EVV_primary', __("Flag indicating venue is primary one for event", "event_espresso"), false, true) |
|
26 | 26 | |
27 | - ) |
|
28 | - ); |
|
29 | - $this->_model_relations = array( |
|
30 | - 'Event'=>new EE_Belongs_To_Relation(), |
|
31 | - 'Venue'=>new EE_Belongs_To_Relation() |
|
32 | - ); |
|
33 | - // this model is generally available for reading |
|
34 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public('Event'); |
|
35 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected('Event'); |
|
36 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected('Event'); |
|
37 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected('Event', EEM_Base::caps_edit); |
|
38 | - parent::__construct($timezone); |
|
39 | - } |
|
27 | + ) |
|
28 | + ); |
|
29 | + $this->_model_relations = array( |
|
30 | + 'Event'=>new EE_Belongs_To_Relation(), |
|
31 | + 'Venue'=>new EE_Belongs_To_Relation() |
|
32 | + ); |
|
33 | + // this model is generally available for reading |
|
34 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public('Event'); |
|
35 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected('Event'); |
|
36 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected('Event'); |
|
37 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected('Event', EEM_Base::caps_edit); |
|
38 | + parent::__construct($timezone); |
|
39 | + } |
|
40 | 40 | } |
@@ -31,10 +31,10 @@ |
||
31 | 31 | 'Venue'=>new EE_Belongs_To_Relation() |
32 | 32 | ); |
33 | 33 | // this model is generally available for reading |
34 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public('Event'); |
|
35 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected('Event'); |
|
36 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected('Event'); |
|
37 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected('Event', EEM_Base::caps_edit); |
|
34 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public('Event'); |
|
35 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected('Event'); |
|
36 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected('Event'); |
|
37 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected('Event', EEM_Base::caps_edit); |
|
38 | 38 | parent::__construct($timezone); |
39 | 39 | } |
40 | 40 | } |
@@ -12,39 +12,39 @@ |
||
12 | 12 | { |
13 | 13 | |
14 | 14 | |
15 | - // private instance of the EEM_Datetime_Ticket object |
|
16 | - protected static $_instance = null; |
|
15 | + // private instance of the EEM_Datetime_Ticket object |
|
16 | + protected static $_instance = null; |
|
17 | 17 | |
18 | - /** |
|
19 | - * private constructor to prevent direct creation |
|
20 | - * @Constructor |
|
21 | - * @access private |
|
22 | - * @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) |
|
23 | - * @return void |
|
24 | - */ |
|
25 | - protected function __construct($timezone) |
|
26 | - { |
|
27 | - $this->singular_item = __('Datetime Ticket', 'event_espresso'); |
|
28 | - $this->plural_item = __('Datetime Tickets', 'event_espresso'); |
|
18 | + /** |
|
19 | + * private constructor to prevent direct creation |
|
20 | + * @Constructor |
|
21 | + * @access private |
|
22 | + * @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) |
|
23 | + * @return void |
|
24 | + */ |
|
25 | + protected function __construct($timezone) |
|
26 | + { |
|
27 | + $this->singular_item = __('Datetime Ticket', 'event_espresso'); |
|
28 | + $this->plural_item = __('Datetime Tickets', 'event_espresso'); |
|
29 | 29 | |
30 | - $this->_tables = array( |
|
31 | - 'Datetime_Ticket'=> new EE_Primary_Table('esp_datetime_ticket', 'DTK_ID') |
|
32 | - ); |
|
33 | - $this->_fields = array( |
|
34 | - 'Datetime_Ticket'=>array( |
|
35 | - 'DTK_ID'=>new EE_Primary_Key_Int_Field('DTK_ID', __('Datetime Ticket ID', 'event_espresso')), |
|
36 | - 'DTT_ID'=>new EE_Foreign_Key_Int_Field('DTT_ID', __('The ID to the Datetime', 'event_espresso'), false, 0, 'Datetime'), |
|
37 | - 'TKT_ID'=>new EE_Foreign_Key_Int_Field('TKT_ID', __('The ID to the Ticket', 'event_espresso'), false, 0, 'Ticket') |
|
38 | - )); |
|
39 | - $this->_model_relations = array( |
|
40 | - 'Ticket'=>new EE_Belongs_To_Relation(), |
|
41 | - 'Datetime'=>new EE_Belongs_To_Relation() |
|
42 | - ); |
|
43 | - // this model is generally available for reading |
|
44 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public('Datetime.Event'); |
|
45 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected('Datetime.Event'); |
|
46 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected('Datetime.Event'); |
|
47 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected('Datetime.Event', EEM_Base::caps_edit); |
|
48 | - parent::__construct($timezone); |
|
49 | - } |
|
30 | + $this->_tables = array( |
|
31 | + 'Datetime_Ticket'=> new EE_Primary_Table('esp_datetime_ticket', 'DTK_ID') |
|
32 | + ); |
|
33 | + $this->_fields = array( |
|
34 | + 'Datetime_Ticket'=>array( |
|
35 | + 'DTK_ID'=>new EE_Primary_Key_Int_Field('DTK_ID', __('Datetime Ticket ID', 'event_espresso')), |
|
36 | + 'DTT_ID'=>new EE_Foreign_Key_Int_Field('DTT_ID', __('The ID to the Datetime', 'event_espresso'), false, 0, 'Datetime'), |
|
37 | + 'TKT_ID'=>new EE_Foreign_Key_Int_Field('TKT_ID', __('The ID to the Ticket', 'event_espresso'), false, 0, 'Ticket') |
|
38 | + )); |
|
39 | + $this->_model_relations = array( |
|
40 | + 'Ticket'=>new EE_Belongs_To_Relation(), |
|
41 | + 'Datetime'=>new EE_Belongs_To_Relation() |
|
42 | + ); |
|
43 | + // this model is generally available for reading |
|
44 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public('Datetime.Event'); |
|
45 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected('Datetime.Event'); |
|
46 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected('Datetime.Event'); |
|
47 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected('Datetime.Event', EEM_Base::caps_edit); |
|
48 | + parent::__construct($timezone); |
|
49 | + } |
|
50 | 50 | } |
@@ -41,10 +41,10 @@ |
||
41 | 41 | 'Datetime'=>new EE_Belongs_To_Relation() |
42 | 42 | ); |
43 | 43 | // this model is generally available for reading |
44 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public('Datetime.Event'); |
|
45 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected('Datetime.Event'); |
|
46 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected('Datetime.Event'); |
|
47 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected('Datetime.Event', EEM_Base::caps_edit); |
|
44 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public('Datetime.Event'); |
|
45 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected('Datetime.Event'); |
|
46 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected('Datetime.Event'); |
|
47 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected('Datetime.Event', EEM_Base::caps_edit); |
|
48 | 48 | parent::__construct($timezone); |
49 | 49 | } |
50 | 50 | } |
@@ -18,56 +18,56 @@ |
||
18 | 18 | class EEM_Post_Meta extends EEM_Base |
19 | 19 | { |
20 | 20 | |
21 | - // private instance of the EE_Post_Meta object |
|
22 | - protected static $_instance = null; |
|
21 | + // private instance of the EE_Post_Meta object |
|
22 | + protected static $_instance = null; |
|
23 | 23 | |
24 | 24 | |
25 | 25 | |
26 | - protected function __construct($timezone = null) |
|
27 | - { |
|
28 | - $this->singular_item = __('Post Meta', 'event_espresso'); |
|
29 | - $this->plural_item = __('Post Metas', 'event_espresso'); |
|
30 | - $this->_tables = array( |
|
31 | - 'Post_Meta' => new EE_Primary_Table('postmeta', 'meta_id'), |
|
32 | - ); |
|
33 | - $models_this_can_attach_to = array_keys(EE_Registry::instance()->cpt_models()); |
|
34 | - $this->_fields = array( |
|
35 | - 'Post_Meta' => array( |
|
36 | - 'meta_id' => new EE_Primary_Key_Int_Field( |
|
37 | - 'meta_id', |
|
38 | - __("Meta ID", "event_espresso") |
|
39 | - ), |
|
40 | - 'post_id' => new EE_Foreign_Key_Int_Field( |
|
41 | - 'post_id', |
|
42 | - __("Primary Key of Post", "event_espresso"), |
|
43 | - false, |
|
44 | - 0, |
|
45 | - $models_this_can_attach_to |
|
46 | - ), |
|
47 | - 'meta_key' => new EE_Plain_Text_Field( |
|
48 | - 'meta_key', |
|
49 | - __("Meta Key", "event_espresso"), |
|
50 | - false, |
|
51 | - '' |
|
52 | - ), |
|
53 | - 'meta_value' => new EE_Maybe_Serialized_Text_Field( |
|
54 | - 'meta_value', |
|
55 | - __("Meta Value", "event_espresso"), |
|
56 | - true |
|
57 | - ), |
|
58 | - ), |
|
59 | - ); |
|
60 | - $this->_model_relations = array(); |
|
61 | - foreach ($models_this_can_attach_to as $model) { |
|
62 | - $this->_model_relations[ $model ] = new EE_Belongs_To_Relation(); |
|
63 | - } |
|
64 | - $this->_wp_core_model = true; |
|
65 | - foreach ($this->cap_contexts_to_cap_action_map() as $cap_context => $action) { |
|
66 | - $this->_cap_restriction_generators[ $cap_context ] = new EE_Restriction_Generator_Meta( |
|
67 | - 'meta_key', |
|
68 | - 'meta_value' |
|
69 | - ); |
|
70 | - } |
|
71 | - parent::__construct($timezone); |
|
72 | - } |
|
26 | + protected function __construct($timezone = null) |
|
27 | + { |
|
28 | + $this->singular_item = __('Post Meta', 'event_espresso'); |
|
29 | + $this->plural_item = __('Post Metas', 'event_espresso'); |
|
30 | + $this->_tables = array( |
|
31 | + 'Post_Meta' => new EE_Primary_Table('postmeta', 'meta_id'), |
|
32 | + ); |
|
33 | + $models_this_can_attach_to = array_keys(EE_Registry::instance()->cpt_models()); |
|
34 | + $this->_fields = array( |
|
35 | + 'Post_Meta' => array( |
|
36 | + 'meta_id' => new EE_Primary_Key_Int_Field( |
|
37 | + 'meta_id', |
|
38 | + __("Meta ID", "event_espresso") |
|
39 | + ), |
|
40 | + 'post_id' => new EE_Foreign_Key_Int_Field( |
|
41 | + 'post_id', |
|
42 | + __("Primary Key of Post", "event_espresso"), |
|
43 | + false, |
|
44 | + 0, |
|
45 | + $models_this_can_attach_to |
|
46 | + ), |
|
47 | + 'meta_key' => new EE_Plain_Text_Field( |
|
48 | + 'meta_key', |
|
49 | + __("Meta Key", "event_espresso"), |
|
50 | + false, |
|
51 | + '' |
|
52 | + ), |
|
53 | + 'meta_value' => new EE_Maybe_Serialized_Text_Field( |
|
54 | + 'meta_value', |
|
55 | + __("Meta Value", "event_espresso"), |
|
56 | + true |
|
57 | + ), |
|
58 | + ), |
|
59 | + ); |
|
60 | + $this->_model_relations = array(); |
|
61 | + foreach ($models_this_can_attach_to as $model) { |
|
62 | + $this->_model_relations[ $model ] = new EE_Belongs_To_Relation(); |
|
63 | + } |
|
64 | + $this->_wp_core_model = true; |
|
65 | + foreach ($this->cap_contexts_to_cap_action_map() as $cap_context => $action) { |
|
66 | + $this->_cap_restriction_generators[ $cap_context ] = new EE_Restriction_Generator_Meta( |
|
67 | + 'meta_key', |
|
68 | + 'meta_value' |
|
69 | + ); |
|
70 | + } |
|
71 | + parent::__construct($timezone); |
|
72 | + } |
|
73 | 73 | } |
@@ -59,11 +59,11 @@ |
||
59 | 59 | ); |
60 | 60 | $this->_model_relations = array(); |
61 | 61 | foreach ($models_this_can_attach_to as $model) { |
62 | - $this->_model_relations[ $model ] = new EE_Belongs_To_Relation(); |
|
62 | + $this->_model_relations[$model] = new EE_Belongs_To_Relation(); |
|
63 | 63 | } |
64 | 64 | $this->_wp_core_model = true; |
65 | 65 | foreach ($this->cap_contexts_to_cap_action_map() as $cap_context => $action) { |
66 | - $this->_cap_restriction_generators[ $cap_context ] = new EE_Restriction_Generator_Meta( |
|
66 | + $this->_cap_restriction_generators[$cap_context] = new EE_Restriction_Generator_Meta( |
|
67 | 67 | 'meta_key', |
68 | 68 | 'meta_value' |
69 | 69 | ); |
@@ -10,205 +10,205 @@ |
||
10 | 10 | class EEM_Term extends EEM_Base |
11 | 11 | { |
12 | 12 | |
13 | - // private instance of the Attendee object |
|
14 | - protected static $_instance = null; |
|
15 | - |
|
16 | - |
|
17 | - |
|
18 | - /** |
|
19 | - *__construct |
|
20 | - * |
|
21 | - * @param string $timezone |
|
22 | - */ |
|
23 | - protected function __construct($timezone = null) |
|
24 | - { |
|
25 | - $this->singular_item = __('Term', 'event_espresso'); |
|
26 | - $this->plural_item = __('Terms', 'event_espresso'); |
|
27 | - $this->_tables = array( |
|
28 | - 'Term' => new EE_Primary_Table('terms', 'term_id'), |
|
29 | - ); |
|
30 | - $this->_fields = array( |
|
31 | - 'Term' => array( |
|
32 | - 'term_id' => new EE_Primary_Key_Int_Field('term_id', __('Term ID', 'event_espresso')), |
|
33 | - 'name' => new EE_Plain_Text_Field('name', __('Term Name', 'event_espresso'), false, ''), |
|
34 | - 'slug' => new EE_Slug_Field('slug', __('Term Slug', 'event_espresso'), false), |
|
35 | - 'term_group' => new EE_Integer_Field('term_group', __("Term Group", "event_espresso"), false, 0), |
|
36 | - ), |
|
37 | - ); |
|
38 | - $this->_model_relations = array( |
|
39 | - 'Term_Taxonomy' => new EE_Has_Many_Relation(), |
|
40 | - ); |
|
41 | - $this->_wp_core_model = true; |
|
42 | - $path_to_tax_model = 'Term_Taxonomy'; |
|
43 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
44 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Taxonomy_Protected( |
|
45 | - $path_to_tax_model |
|
46 | - ); |
|
47 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = false; |
|
48 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = false; |
|
49 | - $path_to_tax_model = $path_to_tax_model . '.'; |
|
50 | - // add cap restrictions for editing relating to the "ee_edit_*" |
|
51 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_category'] = new EE_Default_Where_Conditions( |
|
52 | - array( |
|
53 | - $path_to_tax_model . 'taxonomy*ee_edit_event_category' => array('!=', 'espresso_event_categories'), |
|
54 | - ) |
|
55 | - ); |
|
56 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_venue_category'] = new EE_Default_Where_Conditions( |
|
57 | - array( |
|
58 | - $path_to_tax_model . 'taxonomy*ee_edit_venue_category' => array('!=', 'espresso_venue_categories'), |
|
59 | - ) |
|
60 | - ); |
|
61 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_type'] = new EE_Default_Where_Conditions( |
|
62 | - array( |
|
63 | - $path_to_tax_model . 'taxonomy*ee_edit_event_type' => array('!=', 'espresso_event_type'), |
|
64 | - ) |
|
65 | - ); |
|
66 | - // add cap restrictions for deleting relating to the "ee_deleting_*" |
|
67 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_category'] = new EE_Default_Where_Conditions( |
|
68 | - array( |
|
69 | - $path_to_tax_model . 'taxonomy*ee_delete_event_category' => array('!=', 'espresso_event_categories'), |
|
70 | - ) |
|
71 | - ); |
|
72 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_venue_category'] = new EE_Default_Where_Conditions( |
|
73 | - array( |
|
74 | - $path_to_tax_model . 'taxonomy*ee_delete_venue_category' => array('!=', 'espresso_venue_categories'), |
|
75 | - ) |
|
76 | - ); |
|
77 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_type'] = new EE_Default_Where_Conditions( |
|
78 | - array( |
|
79 | - $path_to_tax_model . 'taxonomy*ee_delete_event_type' => array('!=', 'espresso_event_type'), |
|
80 | - ) |
|
81 | - ); |
|
82 | - parent::__construct($timezone); |
|
83 | - add_filter('FHEE__Read__create_model_query_params', array('EEM_Term', 'rest_api_query_params'), 10, 3); |
|
84 | - } |
|
85 | - |
|
86 | - |
|
87 | - |
|
88 | - /** |
|
89 | - * retrieves a list of all EE event categories |
|
90 | - * |
|
91 | - * @access public |
|
92 | - * @param bool $show_uncategorized |
|
93 | - * @return \EE_Base_Class[] |
|
94 | - */ |
|
95 | - public function get_all_ee_categories($show_uncategorized = false) |
|
96 | - { |
|
97 | - $where_params = array( |
|
98 | - 'Term_Taxonomy.taxonomy' => 'espresso_event_categories', |
|
99 | - 'NOT' => array('name' => __('Uncategorized', 'event_espresso')), |
|
100 | - ); |
|
101 | - if ($show_uncategorized) { |
|
102 | - unset($where_params['NOT']); |
|
103 | - } |
|
104 | - return EEM_Term::instance()->get_all( |
|
105 | - array( |
|
106 | - $where_params, |
|
107 | - 'order_by' => array('name' => 'ASC'), |
|
108 | - ) |
|
109 | - ); |
|
110 | - } |
|
111 | - |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * retrieves a list of all post_tags associated with an EE CPT |
|
116 | - * |
|
117 | - * @access public |
|
118 | - * @param string $post_type |
|
119 | - * @return array |
|
120 | - */ |
|
121 | - public function get_all_CPT_post_tags($post_type = '') |
|
122 | - { |
|
123 | - switch ($post_type) { |
|
124 | - case 'espresso_events': |
|
125 | - return $this->get_all_event_post_tags(); |
|
126 | - break; |
|
127 | - case 'espresso_venues': |
|
128 | - return $this->get_all_venue_post_tags(); |
|
129 | - break; |
|
130 | - default: |
|
131 | - $event_tags = $this->get_all_event_post_tags(); |
|
132 | - $venue_tags = $this->get_all_venue_post_tags(); |
|
133 | - return array_merge($event_tags, $venue_tags); |
|
134 | - } |
|
135 | - } |
|
136 | - |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * get_all_event_post_tags |
|
141 | - * |
|
142 | - * @return EE_Base_Class[] |
|
143 | - */ |
|
144 | - public function get_all_event_post_tags() |
|
145 | - { |
|
146 | - $post_tags = EEM_Term::instance()->get_all( |
|
147 | - array( |
|
148 | - array( |
|
149 | - 'Term_Taxonomy.taxonomy' => 'post_tag', |
|
150 | - 'Term_Taxonomy.Event.post_type' => 'espresso_events', |
|
151 | - ), |
|
152 | - 'order_by' => array('name' => 'ASC'), |
|
153 | - 'force_join' => array('Term_Taxonomy.Event'), |
|
154 | - ) |
|
155 | - ); |
|
156 | - foreach ($post_tags as $key => $post_tag) { |
|
157 | - if (! isset($post_tags[ $key ]->post_type)) { |
|
158 | - $post_tags[ $key ]->post_type = array(); |
|
159 | - } |
|
160 | - $post_tags[ $key ]->post_type[] = 'espresso_events'; |
|
161 | - } |
|
162 | - return $post_tags; |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * get_all_venue_post_tags |
|
169 | - * |
|
170 | - * @return EE_Base_Class[] |
|
171 | - */ |
|
172 | - public function get_all_venue_post_tags() |
|
173 | - { |
|
174 | - $post_tags = EEM_Term::instance()->get_all( |
|
175 | - array( |
|
176 | - array( |
|
177 | - 'Term_Taxonomy.taxonomy' => 'post_tag', |
|
178 | - 'Term_Taxonomy.Venue.post_type' => 'espresso_venues', |
|
179 | - ), |
|
180 | - 'order_by' => array('name' => 'ASC'), |
|
181 | - 'force_join' => array('Term_Taxonomy'), |
|
182 | - ) |
|
183 | - ); |
|
184 | - foreach ($post_tags as $key => $post_tag) { |
|
185 | - if (! isset($post_tags[ $key ]->post_type)) { |
|
186 | - $post_tags[ $key ]->post_type = array(); |
|
187 | - } |
|
188 | - $post_tags[ $key ]->post_type[] = 'espresso_venues'; |
|
189 | - } |
|
190 | - return $post_tags; |
|
191 | - } |
|
192 | - |
|
193 | - |
|
194 | - |
|
195 | - /** |
|
196 | - * Makes sure that during REST API queries, we only return terms |
|
197 | - * for term taxonomies which should be shown in the rest api |
|
198 | - * |
|
199 | - * @param array $model_query_params |
|
200 | - * @param array $querystring_query_params |
|
201 | - * @param EEM_Base $model |
|
202 | - * @return array |
|
203 | - */ |
|
204 | - public static function rest_api_query_params($model_query_params, $querystring_query_params, $model) |
|
205 | - { |
|
206 | - if ($model === EEM_Term::instance()) { |
|
207 | - $taxonomies = get_taxonomies(array('show_in_rest' => true)); |
|
208 | - if (! empty($taxonomies)) { |
|
209 | - $model_query_params[0]['Term_Taxonomy.taxonomy'] = array('IN', $taxonomies); |
|
210 | - } |
|
211 | - } |
|
212 | - return $model_query_params; |
|
213 | - } |
|
13 | + // private instance of the Attendee object |
|
14 | + protected static $_instance = null; |
|
15 | + |
|
16 | + |
|
17 | + |
|
18 | + /** |
|
19 | + *__construct |
|
20 | + * |
|
21 | + * @param string $timezone |
|
22 | + */ |
|
23 | + protected function __construct($timezone = null) |
|
24 | + { |
|
25 | + $this->singular_item = __('Term', 'event_espresso'); |
|
26 | + $this->plural_item = __('Terms', 'event_espresso'); |
|
27 | + $this->_tables = array( |
|
28 | + 'Term' => new EE_Primary_Table('terms', 'term_id'), |
|
29 | + ); |
|
30 | + $this->_fields = array( |
|
31 | + 'Term' => array( |
|
32 | + 'term_id' => new EE_Primary_Key_Int_Field('term_id', __('Term ID', 'event_espresso')), |
|
33 | + 'name' => new EE_Plain_Text_Field('name', __('Term Name', 'event_espresso'), false, ''), |
|
34 | + 'slug' => new EE_Slug_Field('slug', __('Term Slug', 'event_espresso'), false), |
|
35 | + 'term_group' => new EE_Integer_Field('term_group', __("Term Group", "event_espresso"), false, 0), |
|
36 | + ), |
|
37 | + ); |
|
38 | + $this->_model_relations = array( |
|
39 | + 'Term_Taxonomy' => new EE_Has_Many_Relation(), |
|
40 | + ); |
|
41 | + $this->_wp_core_model = true; |
|
42 | + $path_to_tax_model = 'Term_Taxonomy'; |
|
43 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
44 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Taxonomy_Protected( |
|
45 | + $path_to_tax_model |
|
46 | + ); |
|
47 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = false; |
|
48 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = false; |
|
49 | + $path_to_tax_model = $path_to_tax_model . '.'; |
|
50 | + // add cap restrictions for editing relating to the "ee_edit_*" |
|
51 | + $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_category'] = new EE_Default_Where_Conditions( |
|
52 | + array( |
|
53 | + $path_to_tax_model . 'taxonomy*ee_edit_event_category' => array('!=', 'espresso_event_categories'), |
|
54 | + ) |
|
55 | + ); |
|
56 | + $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_venue_category'] = new EE_Default_Where_Conditions( |
|
57 | + array( |
|
58 | + $path_to_tax_model . 'taxonomy*ee_edit_venue_category' => array('!=', 'espresso_venue_categories'), |
|
59 | + ) |
|
60 | + ); |
|
61 | + $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_type'] = new EE_Default_Where_Conditions( |
|
62 | + array( |
|
63 | + $path_to_tax_model . 'taxonomy*ee_edit_event_type' => array('!=', 'espresso_event_type'), |
|
64 | + ) |
|
65 | + ); |
|
66 | + // add cap restrictions for deleting relating to the "ee_deleting_*" |
|
67 | + $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_category'] = new EE_Default_Where_Conditions( |
|
68 | + array( |
|
69 | + $path_to_tax_model . 'taxonomy*ee_delete_event_category' => array('!=', 'espresso_event_categories'), |
|
70 | + ) |
|
71 | + ); |
|
72 | + $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_venue_category'] = new EE_Default_Where_Conditions( |
|
73 | + array( |
|
74 | + $path_to_tax_model . 'taxonomy*ee_delete_venue_category' => array('!=', 'espresso_venue_categories'), |
|
75 | + ) |
|
76 | + ); |
|
77 | + $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_type'] = new EE_Default_Where_Conditions( |
|
78 | + array( |
|
79 | + $path_to_tax_model . 'taxonomy*ee_delete_event_type' => array('!=', 'espresso_event_type'), |
|
80 | + ) |
|
81 | + ); |
|
82 | + parent::__construct($timezone); |
|
83 | + add_filter('FHEE__Read__create_model_query_params', array('EEM_Term', 'rest_api_query_params'), 10, 3); |
|
84 | + } |
|
85 | + |
|
86 | + |
|
87 | + |
|
88 | + /** |
|
89 | + * retrieves a list of all EE event categories |
|
90 | + * |
|
91 | + * @access public |
|
92 | + * @param bool $show_uncategorized |
|
93 | + * @return \EE_Base_Class[] |
|
94 | + */ |
|
95 | + public function get_all_ee_categories($show_uncategorized = false) |
|
96 | + { |
|
97 | + $where_params = array( |
|
98 | + 'Term_Taxonomy.taxonomy' => 'espresso_event_categories', |
|
99 | + 'NOT' => array('name' => __('Uncategorized', 'event_espresso')), |
|
100 | + ); |
|
101 | + if ($show_uncategorized) { |
|
102 | + unset($where_params['NOT']); |
|
103 | + } |
|
104 | + return EEM_Term::instance()->get_all( |
|
105 | + array( |
|
106 | + $where_params, |
|
107 | + 'order_by' => array('name' => 'ASC'), |
|
108 | + ) |
|
109 | + ); |
|
110 | + } |
|
111 | + |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * retrieves a list of all post_tags associated with an EE CPT |
|
116 | + * |
|
117 | + * @access public |
|
118 | + * @param string $post_type |
|
119 | + * @return array |
|
120 | + */ |
|
121 | + public function get_all_CPT_post_tags($post_type = '') |
|
122 | + { |
|
123 | + switch ($post_type) { |
|
124 | + case 'espresso_events': |
|
125 | + return $this->get_all_event_post_tags(); |
|
126 | + break; |
|
127 | + case 'espresso_venues': |
|
128 | + return $this->get_all_venue_post_tags(); |
|
129 | + break; |
|
130 | + default: |
|
131 | + $event_tags = $this->get_all_event_post_tags(); |
|
132 | + $venue_tags = $this->get_all_venue_post_tags(); |
|
133 | + return array_merge($event_tags, $venue_tags); |
|
134 | + } |
|
135 | + } |
|
136 | + |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * get_all_event_post_tags |
|
141 | + * |
|
142 | + * @return EE_Base_Class[] |
|
143 | + */ |
|
144 | + public function get_all_event_post_tags() |
|
145 | + { |
|
146 | + $post_tags = EEM_Term::instance()->get_all( |
|
147 | + array( |
|
148 | + array( |
|
149 | + 'Term_Taxonomy.taxonomy' => 'post_tag', |
|
150 | + 'Term_Taxonomy.Event.post_type' => 'espresso_events', |
|
151 | + ), |
|
152 | + 'order_by' => array('name' => 'ASC'), |
|
153 | + 'force_join' => array('Term_Taxonomy.Event'), |
|
154 | + ) |
|
155 | + ); |
|
156 | + foreach ($post_tags as $key => $post_tag) { |
|
157 | + if (! isset($post_tags[ $key ]->post_type)) { |
|
158 | + $post_tags[ $key ]->post_type = array(); |
|
159 | + } |
|
160 | + $post_tags[ $key ]->post_type[] = 'espresso_events'; |
|
161 | + } |
|
162 | + return $post_tags; |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * get_all_venue_post_tags |
|
169 | + * |
|
170 | + * @return EE_Base_Class[] |
|
171 | + */ |
|
172 | + public function get_all_venue_post_tags() |
|
173 | + { |
|
174 | + $post_tags = EEM_Term::instance()->get_all( |
|
175 | + array( |
|
176 | + array( |
|
177 | + 'Term_Taxonomy.taxonomy' => 'post_tag', |
|
178 | + 'Term_Taxonomy.Venue.post_type' => 'espresso_venues', |
|
179 | + ), |
|
180 | + 'order_by' => array('name' => 'ASC'), |
|
181 | + 'force_join' => array('Term_Taxonomy'), |
|
182 | + ) |
|
183 | + ); |
|
184 | + foreach ($post_tags as $key => $post_tag) { |
|
185 | + if (! isset($post_tags[ $key ]->post_type)) { |
|
186 | + $post_tags[ $key ]->post_type = array(); |
|
187 | + } |
|
188 | + $post_tags[ $key ]->post_type[] = 'espresso_venues'; |
|
189 | + } |
|
190 | + return $post_tags; |
|
191 | + } |
|
192 | + |
|
193 | + |
|
194 | + |
|
195 | + /** |
|
196 | + * Makes sure that during REST API queries, we only return terms |
|
197 | + * for term taxonomies which should be shown in the rest api |
|
198 | + * |
|
199 | + * @param array $model_query_params |
|
200 | + * @param array $querystring_query_params |
|
201 | + * @param EEM_Base $model |
|
202 | + * @return array |
|
203 | + */ |
|
204 | + public static function rest_api_query_params($model_query_params, $querystring_query_params, $model) |
|
205 | + { |
|
206 | + if ($model === EEM_Term::instance()) { |
|
207 | + $taxonomies = get_taxonomies(array('show_in_rest' => true)); |
|
208 | + if (! empty($taxonomies)) { |
|
209 | + $model_query_params[0]['Term_Taxonomy.taxonomy'] = array('IN', $taxonomies); |
|
210 | + } |
|
211 | + } |
|
212 | + return $model_query_params; |
|
213 | + } |
|
214 | 214 | } |
@@ -40,43 +40,43 @@ discard block |
||
40 | 40 | ); |
41 | 41 | $this->_wp_core_model = true; |
42 | 42 | $path_to_tax_model = 'Term_Taxonomy'; |
43 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
44 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Taxonomy_Protected( |
|
43 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
44 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Taxonomy_Protected( |
|
45 | 45 | $path_to_tax_model |
46 | 46 | ); |
47 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = false; |
|
48 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = false; |
|
49 | - $path_to_tax_model = $path_to_tax_model . '.'; |
|
47 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = false; |
|
48 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = false; |
|
49 | + $path_to_tax_model = $path_to_tax_model.'.'; |
|
50 | 50 | // add cap restrictions for editing relating to the "ee_edit_*" |
51 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_category'] = new EE_Default_Where_Conditions( |
|
51 | + $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_category'] = new EE_Default_Where_Conditions( |
|
52 | 52 | array( |
53 | - $path_to_tax_model . 'taxonomy*ee_edit_event_category' => array('!=', 'espresso_event_categories'), |
|
53 | + $path_to_tax_model.'taxonomy*ee_edit_event_category' => array('!=', 'espresso_event_categories'), |
|
54 | 54 | ) |
55 | 55 | ); |
56 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_venue_category'] = new EE_Default_Where_Conditions( |
|
56 | + $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_venue_category'] = new EE_Default_Where_Conditions( |
|
57 | 57 | array( |
58 | - $path_to_tax_model . 'taxonomy*ee_edit_venue_category' => array('!=', 'espresso_venue_categories'), |
|
58 | + $path_to_tax_model.'taxonomy*ee_edit_venue_category' => array('!=', 'espresso_venue_categories'), |
|
59 | 59 | ) |
60 | 60 | ); |
61 | - $this->_cap_restrictions[ EEM_Base::caps_edit ]['ee_edit_event_type'] = new EE_Default_Where_Conditions( |
|
61 | + $this->_cap_restrictions[EEM_Base::caps_edit]['ee_edit_event_type'] = new EE_Default_Where_Conditions( |
|
62 | 62 | array( |
63 | - $path_to_tax_model . 'taxonomy*ee_edit_event_type' => array('!=', 'espresso_event_type'), |
|
63 | + $path_to_tax_model.'taxonomy*ee_edit_event_type' => array('!=', 'espresso_event_type'), |
|
64 | 64 | ) |
65 | 65 | ); |
66 | 66 | // add cap restrictions for deleting relating to the "ee_deleting_*" |
67 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_category'] = new EE_Default_Where_Conditions( |
|
67 | + $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_category'] = new EE_Default_Where_Conditions( |
|
68 | 68 | array( |
69 | - $path_to_tax_model . 'taxonomy*ee_delete_event_category' => array('!=', 'espresso_event_categories'), |
|
69 | + $path_to_tax_model.'taxonomy*ee_delete_event_category' => array('!=', 'espresso_event_categories'), |
|
70 | 70 | ) |
71 | 71 | ); |
72 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_venue_category'] = new EE_Default_Where_Conditions( |
|
72 | + $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_venue_category'] = new EE_Default_Where_Conditions( |
|
73 | 73 | array( |
74 | - $path_to_tax_model . 'taxonomy*ee_delete_venue_category' => array('!=', 'espresso_venue_categories'), |
|
74 | + $path_to_tax_model.'taxonomy*ee_delete_venue_category' => array('!=', 'espresso_venue_categories'), |
|
75 | 75 | ) |
76 | 76 | ); |
77 | - $this->_cap_restrictions[ EEM_Base::caps_delete ]['ee_delete_event_type'] = new EE_Default_Where_Conditions( |
|
77 | + $this->_cap_restrictions[EEM_Base::caps_delete]['ee_delete_event_type'] = new EE_Default_Where_Conditions( |
|
78 | 78 | array( |
79 | - $path_to_tax_model . 'taxonomy*ee_delete_event_type' => array('!=', 'espresso_event_type'), |
|
79 | + $path_to_tax_model.'taxonomy*ee_delete_event_type' => array('!=', 'espresso_event_type'), |
|
80 | 80 | ) |
81 | 81 | ); |
82 | 82 | parent::__construct($timezone); |
@@ -154,10 +154,10 @@ discard block |
||
154 | 154 | ) |
155 | 155 | ); |
156 | 156 | foreach ($post_tags as $key => $post_tag) { |
157 | - if (! isset($post_tags[ $key ]->post_type)) { |
|
158 | - $post_tags[ $key ]->post_type = array(); |
|
157 | + if ( ! isset($post_tags[$key]->post_type)) { |
|
158 | + $post_tags[$key]->post_type = array(); |
|
159 | 159 | } |
160 | - $post_tags[ $key ]->post_type[] = 'espresso_events'; |
|
160 | + $post_tags[$key]->post_type[] = 'espresso_events'; |
|
161 | 161 | } |
162 | 162 | return $post_tags; |
163 | 163 | } |
@@ -182,10 +182,10 @@ discard block |
||
182 | 182 | ) |
183 | 183 | ); |
184 | 184 | foreach ($post_tags as $key => $post_tag) { |
185 | - if (! isset($post_tags[ $key ]->post_type)) { |
|
186 | - $post_tags[ $key ]->post_type = array(); |
|
185 | + if ( ! isset($post_tags[$key]->post_type)) { |
|
186 | + $post_tags[$key]->post_type = array(); |
|
187 | 187 | } |
188 | - $post_tags[ $key ]->post_type[] = 'espresso_venues'; |
|
188 | + $post_tags[$key]->post_type[] = 'espresso_venues'; |
|
189 | 189 | } |
190 | 190 | return $post_tags; |
191 | 191 | } |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | { |
206 | 206 | if ($model === EEM_Term::instance()) { |
207 | 207 | $taxonomies = get_taxonomies(array('show_in_rest' => true)); |
208 | - if (! empty($taxonomies)) { |
|
208 | + if ( ! empty($taxonomies)) { |
|
209 | 209 | $model_query_params[0]['Term_Taxonomy.taxonomy'] = array('IN', $taxonomies); |
210 | 210 | } |
211 | 211 | } |
@@ -7,77 +7,77 @@ |
||
7 | 7 | class EE_Float_Field extends EE_Model_Field_Base |
8 | 8 | { |
9 | 9 | |
10 | - /** |
|
11 | - * @param string $table_column |
|
12 | - * @param string $nicename |
|
13 | - * @param bool $nullable |
|
14 | - * @param null $default_value |
|
15 | - */ |
|
16 | - public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
17 | - { |
|
18 | - parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
19 | - $this->setSchemaType('number'); |
|
20 | - } |
|
10 | + /** |
|
11 | + * @param string $table_column |
|
12 | + * @param string $nicename |
|
13 | + * @param bool $nullable |
|
14 | + * @param null $default_value |
|
15 | + */ |
|
16 | + public function __construct($table_column, $nicename, $nullable, $default_value = null) |
|
17 | + { |
|
18 | + parent::__construct($table_column, $nicename, $nullable, $default_value); |
|
19 | + $this->setSchemaType('number'); |
|
20 | + } |
|
21 | 21 | |
22 | 22 | |
23 | - /** |
|
24 | - * If provided a string, strips out number-related formatting, like commas, periods, spaces, other junk, etc. |
|
25 | - * However, treats commas and periods as thousand-separators ro decimal marks, as indicate by the config's currency. |
|
26 | - * So if you want to pass in a string that NEEDS to interpret periods as decimal marks, call floatval() on it first. |
|
27 | - * Returns a float |
|
28 | - * |
|
29 | - * @param type $value_inputted_for_field_on_model_object |
|
30 | - * @return float |
|
31 | - */ |
|
32 | - public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
33 | - { |
|
23 | + /** |
|
24 | + * If provided a string, strips out number-related formatting, like commas, periods, spaces, other junk, etc. |
|
25 | + * However, treats commas and periods as thousand-separators ro decimal marks, as indicate by the config's currency. |
|
26 | + * So if you want to pass in a string that NEEDS to interpret periods as decimal marks, call floatval() on it first. |
|
27 | + * Returns a float |
|
28 | + * |
|
29 | + * @param type $value_inputted_for_field_on_model_object |
|
30 | + * @return float |
|
31 | + */ |
|
32 | + public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
33 | + { |
|
34 | 34 | // echo __LINE__."$value_inputted_for_field_on_model_object<br>"; |
35 | - // remove whitespaces and thousands separators |
|
36 | - if (is_string($value_inputted_for_field_on_model_object)) { |
|
37 | - $value_inputted_for_field_on_model_object = str_replace( |
|
38 | - array(" ", EE_Config::instance()->currency->thsnds), |
|
39 | - "", |
|
40 | - $value_inputted_for_field_on_model_object |
|
41 | - ); |
|
35 | + // remove whitespaces and thousands separators |
|
36 | + if (is_string($value_inputted_for_field_on_model_object)) { |
|
37 | + $value_inputted_for_field_on_model_object = str_replace( |
|
38 | + array(" ", EE_Config::instance()->currency->thsnds), |
|
39 | + "", |
|
40 | + $value_inputted_for_field_on_model_object |
|
41 | + ); |
|
42 | 42 | // echo __LINE__."$value_inputted_for_field_on_model_object<br>"; |
43 | 43 | // normalize it so periods are decimal marks (we don't care where you're from: we're talking PHP now) |
44 | - $value_inputted_for_field_on_model_object = str_replace( |
|
45 | - EE_Config::instance()->currency->dec_mrk, |
|
46 | - ".", |
|
47 | - $value_inputted_for_field_on_model_object |
|
48 | - ); |
|
44 | + $value_inputted_for_field_on_model_object = str_replace( |
|
45 | + EE_Config::instance()->currency->dec_mrk, |
|
46 | + ".", |
|
47 | + $value_inputted_for_field_on_model_object |
|
48 | + ); |
|
49 | 49 | // echo __LINE__."$value_inputted_for_field_on_model_object<br>"; |
50 | 50 | // double-check there's absolutely nothing left on this string besides numbers |
51 | - $value_inputted_for_field_on_model_object = preg_replace( |
|
52 | - "/[^0-9,.]/", |
|
53 | - "", |
|
54 | - $value_inputted_for_field_on_model_object |
|
55 | - ); |
|
56 | - } |
|
51 | + $value_inputted_for_field_on_model_object = preg_replace( |
|
52 | + "/[^0-9,.]/", |
|
53 | + "", |
|
54 | + $value_inputted_for_field_on_model_object |
|
55 | + ); |
|
56 | + } |
|
57 | 57 | // echo __LINE__."$value_inputted_for_field_on_model_object<br>"; |
58 | - return floatval($value_inputted_for_field_on_model_object); |
|
59 | - } |
|
58 | + return floatval($value_inputted_for_field_on_model_object); |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * Returns the number formatted according to local custom (set by the country of the blog). |
|
63 | - * |
|
64 | - * @param float $value_on_field_to_be_outputted |
|
65 | - * @return string |
|
66 | - */ |
|
67 | - public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) |
|
68 | - { |
|
69 | - $EE = EE_Registry::instance(); |
|
70 | - return number_format( |
|
71 | - $value_on_field_to_be_outputted, |
|
72 | - $EE->CFG->currency->dec_plc, |
|
73 | - $EE->CFG->currency->dec_mrk, |
|
74 | - $EE->CFG->currency->thsnds |
|
75 | - ); |
|
76 | - } |
|
61 | + /** |
|
62 | + * Returns the number formatted according to local custom (set by the country of the blog). |
|
63 | + * |
|
64 | + * @param float $value_on_field_to_be_outputted |
|
65 | + * @return string |
|
66 | + */ |
|
67 | + public function prepare_for_pretty_echoing($value_on_field_to_be_outputted, $schema = null) |
|
68 | + { |
|
69 | + $EE = EE_Registry::instance(); |
|
70 | + return number_format( |
|
71 | + $value_on_field_to_be_outputted, |
|
72 | + $EE->CFG->currency->dec_plc, |
|
73 | + $EE->CFG->currency->dec_mrk, |
|
74 | + $EE->CFG->currency->thsnds |
|
75 | + ); |
|
76 | + } |
|
77 | 77 | |
78 | - public function prepare_for_set_from_db($value_found_in_db_for_model_object) |
|
79 | - { |
|
78 | + public function prepare_for_set_from_db($value_found_in_db_for_model_object) |
|
79 | + { |
|
80 | 80 | // echo "prepare for set from db of ";d($value_found_in_db_for_model_object); |
81 | - return floatval($value_found_in_db_for_model_object); |
|
82 | - } |
|
81 | + return floatval($value_found_in_db_for_model_object); |
|
82 | + } |
|
83 | 83 | } |
@@ -6,14 +6,14 @@ |
||
6 | 6 | */ |
7 | 7 | class EE_All_Caps_Text_Field extends EE_Text_Field_Base |
8 | 8 | { |
9 | - /** |
|
10 | - * makes it all upper case, and key-like |
|
11 | - * |
|
12 | - * @param string $value_inputted_for_field_on_model_object |
|
13 | - * @return string |
|
14 | - */ |
|
15 | - public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
16 | - { |
|
17 | - return strtoupper(sanitize_key($value_inputted_for_field_on_model_object)); |
|
18 | - } |
|
9 | + /** |
|
10 | + * makes it all upper case, and key-like |
|
11 | + * |
|
12 | + * @param string $value_inputted_for_field_on_model_object |
|
13 | + * @return string |
|
14 | + */ |
|
15 | + public function prepare_for_set($value_inputted_for_field_on_model_object) |
|
16 | + { |
|
17 | + return strtoupper(sanitize_key($value_inputted_for_field_on_model_object)); |
|
18 | + } |
|
19 | 19 | } |