@@ -65,18 +65,18 @@ discard block |
||
65 | 65 | // remember the model relation chain to the JOIN model, because we'll |
66 | 66 | // need it for get_join_statement() |
67 | 67 | $this->_model_relation_chain_to_join_model = $model_relation_chain; |
68 | - $this_table_pk_field = $this->get_this_model()->get_primary_key_field();// get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
68 | + $this_table_pk_field = $this->get_this_model()->get_primary_key_field(); // get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
69 | 69 | $join_table_fk_field_to_this_table = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
70 | 70 | $this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
71 | 71 | $model_relation_chain, |
72 | 72 | $this->get_this_model()->get_this_model_name() |
73 | - ) . $this_table_pk_field->get_table_alias(); |
|
73 | + ).$this_table_pk_field->get_table_alias(); |
|
74 | 74 | |
75 | 75 | $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
76 | 76 | $model_relation_chain, |
77 | 77 | $this->get_join_model()->get_this_model_name() |
78 | - ) . $join_table_fk_field_to_this_table->get_table_alias(); |
|
79 | - $join_table = $this->get_join_model()->get_table_for_alias($join_table_alias); |
|
78 | + ).$join_table_fk_field_to_this_table->get_table_alias(); |
|
79 | + $join_table = $this->get_join_model()->get_table_for_alias($join_table_alias); |
|
80 | 80 | // phew! ok, we have all the info we need, now we can create the SQL join string |
81 | 81 | $SQL = $this->_left_join( |
82 | 82 | $join_table, |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | $join_table_fk_field_to_this_table->get_table_column(), |
85 | 85 | $this_table_alias, |
86 | 86 | $this_table_pk_field->get_table_column() |
87 | - ) . $this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias); |
|
87 | + ).$this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias); |
|
88 | 88 | |
89 | 89 | return $SQL; |
90 | 90 | } |
@@ -113,14 +113,14 @@ discard block |
||
113 | 113 | $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
114 | 114 | $this->_model_relation_chain_to_join_model, |
115 | 115 | $this->get_join_model()->get_this_model_name() |
116 | - ) . $join_table_fk_field_to_this_table->get_table_alias(); |
|
116 | + ).$join_table_fk_field_to_this_table->get_table_alias(); |
|
117 | 117 | $other_table_pk_field = $this->get_other_model()->get_primary_key_field(); |
118 | 118 | $join_table_fk_field_to_other_table = $this->get_join_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
119 | 119 | $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
120 | 120 | $model_relation_chain, |
121 | 121 | $this->get_other_model()->get_this_model_name() |
122 | - ) . $other_table_pk_field->get_table_alias(); |
|
123 | - $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias); |
|
122 | + ).$other_table_pk_field->get_table_alias(); |
|
123 | + $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias); |
|
124 | 124 | |
125 | 125 | $SQL = $this->_left_join( |
126 | 126 | $other_table, |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | $other_table_pk_field->get_table_column(), |
129 | 129 | $join_table_alias, |
130 | 130 | $join_table_fk_field_to_other_table->get_table_column() |
131 | - ) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias); |
|
131 | + ).$this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias); |
|
132 | 132 | return $SQL; |
133 | 133 | } |
134 | 134 | |
@@ -161,17 +161,17 @@ discard block |
||
161 | 161 | ); |
162 | 162 | |
163 | 163 | // if $where_query exists lets add them to the query_params. |
164 | - if (! empty($extra_join_model_fields_n_values)) { |
|
164 | + if ( ! empty($extra_join_model_fields_n_values)) { |
|
165 | 165 | // make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name) |
166 | 166 | // make sure we strip THIS models name from the query param |
167 | 167 | $parsed_query = array(); |
168 | 168 | foreach ($extra_join_model_fields_n_values as $query_param => $val) { |
169 | - $query_param = str_replace( |
|
170 | - $this->get_join_model()->get_this_model_name() . ".", |
|
169 | + $query_param = str_replace( |
|
170 | + $this->get_join_model()->get_this_model_name().".", |
|
171 | 171 | "", |
172 | 172 | $query_param |
173 | 173 | ); |
174 | - $parsed_query[ $query_param ] = $val; |
|
174 | + $parsed_query[$query_param] = $val; |
|
175 | 175 | } |
176 | 176 | $all_fields = array_merge($foreign_keys, $parsed_query); |
177 | 177 | } |
@@ -181,7 +181,7 @@ discard block |
||
181 | 181 | // new row. |
182 | 182 | // Again, if you want more sophisticated logic or insertions (handling more columns than just 2 foreign keys to |
183 | 183 | // the other tables) use the joining model directly! |
184 | - if (! $existing_entry_in_join_table) { |
|
184 | + if ( ! $existing_entry_in_join_table) { |
|
185 | 185 | $this->get_join_model()->insert($all_fields); |
186 | 186 | } else { |
187 | 187 | $this->get_join_model()->update( |
@@ -217,17 +217,17 @@ discard block |
||
217 | 217 | ); |
218 | 218 | |
219 | 219 | // if $where_query exists lets add them to the query_params. |
220 | - if (! empty($where_query)) { |
|
220 | + if ( ! empty($where_query)) { |
|
221 | 221 | // make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name) |
222 | 222 | // make sure we strip THIS models name from the query param |
223 | 223 | $parsed_query = array(); |
224 | 224 | foreach ($where_query as $query_param => $val) { |
225 | - $query_param = str_replace( |
|
226 | - $this->get_join_model()->get_this_model_name() . ".", |
|
225 | + $query_param = str_replace( |
|
226 | + $this->get_join_model()->get_this_model_name().".", |
|
227 | 227 | "", |
228 | 228 | $query_param |
229 | 229 | ); |
230 | - $parsed_query[ $query_param ] = $val; |
|
230 | + $parsed_query[$query_param] = $val; |
|
231 | 231 | } |
232 | 232 | $cols_n_values = array_merge($cols_n_values, $parsed_query); |
233 | 233 | } |
@@ -9,266 +9,266 @@ |
||
9 | 9 | */ |
10 | 10 | class EE_HABTM_Relation extends EE_Model_Relation_Base |
11 | 11 | { |
12 | - /** |
|
13 | - * Model which defines the relation between two other models. Eg, the EE_Event_Question_Group model, |
|
14 | - * which joins EE_Event and EE_Question_Group |
|
15 | - * |
|
16 | - * @var EEM_Base |
|
17 | - */ |
|
18 | - protected $_joining_model_name; |
|
12 | + /** |
|
13 | + * Model which defines the relation between two other models. Eg, the EE_Event_Question_Group model, |
|
14 | + * which joins EE_Event and EE_Question_Group |
|
15 | + * |
|
16 | + * @var EEM_Base |
|
17 | + */ |
|
18 | + protected $_joining_model_name; |
|
19 | 19 | |
20 | - protected $_model_relation_chain_to_join_model; |
|
20 | + protected $_model_relation_chain_to_join_model; |
|
21 | 21 | |
22 | 22 | |
23 | - /** |
|
24 | - * Object representing the relationship between two models. HasAndBelongsToMany relations always use a join-table |
|
25 | - * (and an ee joining-model.) This knows how to join the models, |
|
26 | - * get related models across the relation, and add-and-remove the relationships. |
|
27 | - * |
|
28 | - * @param bool $joining_model_name |
|
29 | - * @param boolean $block_deletes for this type of relation, we block by default for now. if there |
|
30 | - * are related models across this relation, block (prevent and add an |
|
31 | - * error) the deletion of this model |
|
32 | - * @param string $blocking_delete_error_message a customized error message on blocking deletes instead of the |
|
33 | - * default |
|
34 | - */ |
|
35 | - public function __construct($joining_model_name, $block_deletes = true, $blocking_delete_error_message = '') |
|
36 | - { |
|
37 | - $this->_joining_model_name = $joining_model_name; |
|
38 | - parent::__construct($block_deletes, $blocking_delete_error_message); |
|
39 | - } |
|
23 | + /** |
|
24 | + * Object representing the relationship between two models. HasAndBelongsToMany relations always use a join-table |
|
25 | + * (and an ee joining-model.) This knows how to join the models, |
|
26 | + * get related models across the relation, and add-and-remove the relationships. |
|
27 | + * |
|
28 | + * @param bool $joining_model_name |
|
29 | + * @param boolean $block_deletes for this type of relation, we block by default for now. if there |
|
30 | + * are related models across this relation, block (prevent and add an |
|
31 | + * error) the deletion of this model |
|
32 | + * @param string $blocking_delete_error_message a customized error message on blocking deletes instead of the |
|
33 | + * default |
|
34 | + */ |
|
35 | + public function __construct($joining_model_name, $block_deletes = true, $blocking_delete_error_message = '') |
|
36 | + { |
|
37 | + $this->_joining_model_name = $joining_model_name; |
|
38 | + parent::__construct($block_deletes, $blocking_delete_error_message); |
|
39 | + } |
|
40 | 40 | |
41 | - /** |
|
42 | - * Gets the joining model's object |
|
43 | - * |
|
44 | - * @return EEM_Base |
|
45 | - */ |
|
46 | - public function get_join_model() |
|
47 | - { |
|
48 | - return $this->_get_model($this->_joining_model_name); |
|
49 | - } |
|
41 | + /** |
|
42 | + * Gets the joining model's object |
|
43 | + * |
|
44 | + * @return EEM_Base |
|
45 | + */ |
|
46 | + public function get_join_model() |
|
47 | + { |
|
48 | + return $this->_get_model($this->_joining_model_name); |
|
49 | + } |
|
50 | 50 | |
51 | 51 | |
52 | - /** |
|
53 | - * Gets the SQL string for joining the main model's table containing the pk to the join table. Eg "LEFT JOIN |
|
54 | - * real_join_table AS join_table_alias ON this_table_alias.pk = join_table_alias.fk_to_this_table" |
|
55 | - * |
|
56 | - * @param string $model_relation_chain like 'Event.Event_Venue.Venue' |
|
57 | - * @return string of SQL |
|
58 | - * @throws \EE_Error |
|
59 | - */ |
|
60 | - public function get_join_to_intermediate_model_statement($model_relation_chain) |
|
61 | - { |
|
62 | - // create sql like |
|
63 | - // LEFT JOIN join_table AS join_table_alias ON this_table_alias.this_table_pk = join_table_alias.join_table_fk_to_this |
|
64 | - // LEFT JOIN other_table AS other_table_alias ON join_table_alias.join_table_fk_to_other = other_table_alias.other_table_pk |
|
65 | - // remember the model relation chain to the JOIN model, because we'll |
|
66 | - // need it for get_join_statement() |
|
67 | - $this->_model_relation_chain_to_join_model = $model_relation_chain; |
|
68 | - $this_table_pk_field = $this->get_this_model()->get_primary_key_field();// get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
69 | - $join_table_fk_field_to_this_table = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
70 | - $this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
71 | - $model_relation_chain, |
|
72 | - $this->get_this_model()->get_this_model_name() |
|
73 | - ) . $this_table_pk_field->get_table_alias(); |
|
52 | + /** |
|
53 | + * Gets the SQL string for joining the main model's table containing the pk to the join table. Eg "LEFT JOIN |
|
54 | + * real_join_table AS join_table_alias ON this_table_alias.pk = join_table_alias.fk_to_this_table" |
|
55 | + * |
|
56 | + * @param string $model_relation_chain like 'Event.Event_Venue.Venue' |
|
57 | + * @return string of SQL |
|
58 | + * @throws \EE_Error |
|
59 | + */ |
|
60 | + public function get_join_to_intermediate_model_statement($model_relation_chain) |
|
61 | + { |
|
62 | + // create sql like |
|
63 | + // LEFT JOIN join_table AS join_table_alias ON this_table_alias.this_table_pk = join_table_alias.join_table_fk_to_this |
|
64 | + // LEFT JOIN other_table AS other_table_alias ON join_table_alias.join_table_fk_to_other = other_table_alias.other_table_pk |
|
65 | + // remember the model relation chain to the JOIN model, because we'll |
|
66 | + // need it for get_join_statement() |
|
67 | + $this->_model_relation_chain_to_join_model = $model_relation_chain; |
|
68 | + $this_table_pk_field = $this->get_this_model()->get_primary_key_field();// get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
69 | + $join_table_fk_field_to_this_table = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
70 | + $this_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
71 | + $model_relation_chain, |
|
72 | + $this->get_this_model()->get_this_model_name() |
|
73 | + ) . $this_table_pk_field->get_table_alias(); |
|
74 | 74 | |
75 | - $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
76 | - $model_relation_chain, |
|
77 | - $this->get_join_model()->get_this_model_name() |
|
78 | - ) . $join_table_fk_field_to_this_table->get_table_alias(); |
|
79 | - $join_table = $this->get_join_model()->get_table_for_alias($join_table_alias); |
|
80 | - // phew! ok, we have all the info we need, now we can create the SQL join string |
|
81 | - $SQL = $this->_left_join( |
|
82 | - $join_table, |
|
83 | - $join_table_alias, |
|
84 | - $join_table_fk_field_to_this_table->get_table_column(), |
|
85 | - $this_table_alias, |
|
86 | - $this_table_pk_field->get_table_column() |
|
87 | - ) . $this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias); |
|
75 | + $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
76 | + $model_relation_chain, |
|
77 | + $this->get_join_model()->get_this_model_name() |
|
78 | + ) . $join_table_fk_field_to_this_table->get_table_alias(); |
|
79 | + $join_table = $this->get_join_model()->get_table_for_alias($join_table_alias); |
|
80 | + // phew! ok, we have all the info we need, now we can create the SQL join string |
|
81 | + $SQL = $this->_left_join( |
|
82 | + $join_table, |
|
83 | + $join_table_alias, |
|
84 | + $join_table_fk_field_to_this_table->get_table_column(), |
|
85 | + $this_table_alias, |
|
86 | + $this_table_pk_field->get_table_column() |
|
87 | + ) . $this->get_join_model()->_construct_internal_join_to_table_with_alias($join_table_alias); |
|
88 | 88 | |
89 | - return $SQL; |
|
90 | - } |
|
89 | + return $SQL; |
|
90 | + } |
|
91 | 91 | |
92 | 92 | |
93 | - /** |
|
94 | - * Gets the SQL string for joining the join table to the other model's pk's table. Eg "LEFT JOIN real_other_table |
|
95 | - * AS other_table_alias ON join_table_alias.fk_to_other_table = other_table_alias.pk" If you want to join between |
|
96 | - * modelA -> joinModelAB -> modelB (eg, Event -> Event_Question_Group -> Question_Group), you should prepend the |
|
97 | - * result of this function with results from get_join_to_intermediate_model_statement(), so that you join first to |
|
98 | - * the intermediate join table, and then to the other model's pk's table |
|
99 | - * |
|
100 | - * @param string $model_relation_chain like 'Event.Event_Venue.Venue' |
|
101 | - * @return string of SQL |
|
102 | - * @throws \EE_Error |
|
103 | - */ |
|
104 | - public function get_join_statement($model_relation_chain) |
|
105 | - { |
|
106 | - if ($this->_model_relation_chain_to_join_model === null) { |
|
107 | - throw new EE_Error(sprintf(__( |
|
108 | - 'When using EE_HABTM_Relation to create a join, you must call get_join_to_intermediate_model_statement BEFORE get_join_statement', |
|
109 | - 'event_espresso' |
|
110 | - ))); |
|
111 | - } |
|
112 | - $join_table_fk_field_to_this_table = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
113 | - $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
114 | - $this->_model_relation_chain_to_join_model, |
|
115 | - $this->get_join_model()->get_this_model_name() |
|
116 | - ) . $join_table_fk_field_to_this_table->get_table_alias(); |
|
117 | - $other_table_pk_field = $this->get_other_model()->get_primary_key_field(); |
|
118 | - $join_table_fk_field_to_other_table = $this->get_join_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
119 | - $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
120 | - $model_relation_chain, |
|
121 | - $this->get_other_model()->get_this_model_name() |
|
122 | - ) . $other_table_pk_field->get_table_alias(); |
|
123 | - $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias); |
|
93 | + /** |
|
94 | + * Gets the SQL string for joining the join table to the other model's pk's table. Eg "LEFT JOIN real_other_table |
|
95 | + * AS other_table_alias ON join_table_alias.fk_to_other_table = other_table_alias.pk" If you want to join between |
|
96 | + * modelA -> joinModelAB -> modelB (eg, Event -> Event_Question_Group -> Question_Group), you should prepend the |
|
97 | + * result of this function with results from get_join_to_intermediate_model_statement(), so that you join first to |
|
98 | + * the intermediate join table, and then to the other model's pk's table |
|
99 | + * |
|
100 | + * @param string $model_relation_chain like 'Event.Event_Venue.Venue' |
|
101 | + * @return string of SQL |
|
102 | + * @throws \EE_Error |
|
103 | + */ |
|
104 | + public function get_join_statement($model_relation_chain) |
|
105 | + { |
|
106 | + if ($this->_model_relation_chain_to_join_model === null) { |
|
107 | + throw new EE_Error(sprintf(__( |
|
108 | + 'When using EE_HABTM_Relation to create a join, you must call get_join_to_intermediate_model_statement BEFORE get_join_statement', |
|
109 | + 'event_espresso' |
|
110 | + ))); |
|
111 | + } |
|
112 | + $join_table_fk_field_to_this_table = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
113 | + $join_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
114 | + $this->_model_relation_chain_to_join_model, |
|
115 | + $this->get_join_model()->get_this_model_name() |
|
116 | + ) . $join_table_fk_field_to_this_table->get_table_alias(); |
|
117 | + $other_table_pk_field = $this->get_other_model()->get_primary_key_field(); |
|
118 | + $join_table_fk_field_to_other_table = $this->get_join_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
119 | + $other_table_alias = EE_Model_Parser::extract_table_alias_model_relation_chain_prefix( |
|
120 | + $model_relation_chain, |
|
121 | + $this->get_other_model()->get_this_model_name() |
|
122 | + ) . $other_table_pk_field->get_table_alias(); |
|
123 | + $other_table = $this->get_other_model()->get_table_for_alias($other_table_alias); |
|
124 | 124 | |
125 | - $SQL = $this->_left_join( |
|
126 | - $other_table, |
|
127 | - $other_table_alias, |
|
128 | - $other_table_pk_field->get_table_column(), |
|
129 | - $join_table_alias, |
|
130 | - $join_table_fk_field_to_other_table->get_table_column() |
|
131 | - ) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias); |
|
132 | - return $SQL; |
|
133 | - } |
|
125 | + $SQL = $this->_left_join( |
|
126 | + $other_table, |
|
127 | + $other_table_alias, |
|
128 | + $other_table_pk_field->get_table_column(), |
|
129 | + $join_table_alias, |
|
130 | + $join_table_fk_field_to_other_table->get_table_column() |
|
131 | + ) . $this->get_other_model()->_construct_internal_join_to_table_with_alias($other_table_alias); |
|
132 | + return $SQL; |
|
133 | + } |
|
134 | 134 | |
135 | 135 | |
136 | - /** |
|
137 | - * Ensures there is an entry in the join table between these two models. Feel free to do this manually if you like. |
|
138 | - * If the join table has additional columns (eg, the Event_Question_Group table has a is_primary column), then |
|
139 | - * you'll want to directly use the EEM_Event_Question_Group model to add the entry to the table and set those extra |
|
140 | - * columns' values |
|
141 | - * |
|
142 | - * @param EE_Base_Class|int $this_obj_or_id |
|
143 | - * @param EE_Base_Class|int $other_obj_or_id |
|
144 | - * @param array $extra_join_model_fields_n_values col=>val pairs that are used as extra conditions for |
|
145 | - * checking existing values and for setting new rows if |
|
146 | - * no exact matches. |
|
147 | - * @return EE_Base_Class |
|
148 | - * @throws \EE_Error |
|
149 | - */ |
|
150 | - public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array()) |
|
151 | - { |
|
152 | - $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
|
153 | - $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
154 | - // check if such a relationship already exists |
|
155 | - $join_model_fk_to_this_model = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
156 | - $join_model_fk_to_other_model = $this->get_join_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
136 | + /** |
|
137 | + * Ensures there is an entry in the join table between these two models. Feel free to do this manually if you like. |
|
138 | + * If the join table has additional columns (eg, the Event_Question_Group table has a is_primary column), then |
|
139 | + * you'll want to directly use the EEM_Event_Question_Group model to add the entry to the table and set those extra |
|
140 | + * columns' values |
|
141 | + * |
|
142 | + * @param EE_Base_Class|int $this_obj_or_id |
|
143 | + * @param EE_Base_Class|int $other_obj_or_id |
|
144 | + * @param array $extra_join_model_fields_n_values col=>val pairs that are used as extra conditions for |
|
145 | + * checking existing values and for setting new rows if |
|
146 | + * no exact matches. |
|
147 | + * @return EE_Base_Class |
|
148 | + * @throws \EE_Error |
|
149 | + */ |
|
150 | + public function add_relation_to($this_obj_or_id, $other_obj_or_id, $extra_join_model_fields_n_values = array()) |
|
151 | + { |
|
152 | + $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
|
153 | + $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
154 | + // check if such a relationship already exists |
|
155 | + $join_model_fk_to_this_model = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
156 | + $join_model_fk_to_other_model = $this->get_join_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
157 | 157 | |
158 | - $foreign_keys = $all_fields = array( |
|
159 | - $join_model_fk_to_this_model->get_name() => $this_model_obj->ID(), |
|
160 | - $join_model_fk_to_other_model->get_name() => $other_model_obj->ID(), |
|
161 | - ); |
|
158 | + $foreign_keys = $all_fields = array( |
|
159 | + $join_model_fk_to_this_model->get_name() => $this_model_obj->ID(), |
|
160 | + $join_model_fk_to_other_model->get_name() => $other_model_obj->ID(), |
|
161 | + ); |
|
162 | 162 | |
163 | - // if $where_query exists lets add them to the query_params. |
|
164 | - if (! empty($extra_join_model_fields_n_values)) { |
|
165 | - // make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name) |
|
166 | - // make sure we strip THIS models name from the query param |
|
167 | - $parsed_query = array(); |
|
168 | - foreach ($extra_join_model_fields_n_values as $query_param => $val) { |
|
169 | - $query_param = str_replace( |
|
170 | - $this->get_join_model()->get_this_model_name() . ".", |
|
171 | - "", |
|
172 | - $query_param |
|
173 | - ); |
|
174 | - $parsed_query[ $query_param ] = $val; |
|
175 | - } |
|
176 | - $all_fields = array_merge($foreign_keys, $parsed_query); |
|
177 | - } |
|
163 | + // if $where_query exists lets add them to the query_params. |
|
164 | + if (! empty($extra_join_model_fields_n_values)) { |
|
165 | + // make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name) |
|
166 | + // make sure we strip THIS models name from the query param |
|
167 | + $parsed_query = array(); |
|
168 | + foreach ($extra_join_model_fields_n_values as $query_param => $val) { |
|
169 | + $query_param = str_replace( |
|
170 | + $this->get_join_model()->get_this_model_name() . ".", |
|
171 | + "", |
|
172 | + $query_param |
|
173 | + ); |
|
174 | + $parsed_query[ $query_param ] = $val; |
|
175 | + } |
|
176 | + $all_fields = array_merge($foreign_keys, $parsed_query); |
|
177 | + } |
|
178 | 178 | |
179 | - $existing_entry_in_join_table = $this->get_join_model()->get_one(array($foreign_keys)); |
|
180 | - // If there is already an entry in the join table, indicating a relationship, update it instead of adding a |
|
181 | - // new row. |
|
182 | - // Again, if you want more sophisticated logic or insertions (handling more columns than just 2 foreign keys to |
|
183 | - // the other tables) use the joining model directly! |
|
184 | - if (! $existing_entry_in_join_table) { |
|
185 | - $this->get_join_model()->insert($all_fields); |
|
186 | - } else { |
|
187 | - $this->get_join_model()->update( |
|
188 | - $all_fields, |
|
189 | - [$foreign_keys] |
|
190 | - ); |
|
191 | - } |
|
192 | - return $other_model_obj; |
|
193 | - } |
|
179 | + $existing_entry_in_join_table = $this->get_join_model()->get_one(array($foreign_keys)); |
|
180 | + // If there is already an entry in the join table, indicating a relationship, update it instead of adding a |
|
181 | + // new row. |
|
182 | + // Again, if you want more sophisticated logic or insertions (handling more columns than just 2 foreign keys to |
|
183 | + // the other tables) use the joining model directly! |
|
184 | + if (! $existing_entry_in_join_table) { |
|
185 | + $this->get_join_model()->insert($all_fields); |
|
186 | + } else { |
|
187 | + $this->get_join_model()->update( |
|
188 | + $all_fields, |
|
189 | + [$foreign_keys] |
|
190 | + ); |
|
191 | + } |
|
192 | + return $other_model_obj; |
|
193 | + } |
|
194 | 194 | |
195 | 195 | |
196 | - /** |
|
197 | - * Deletes any rows in the join table that have foreign keys matching the other model objects specified |
|
198 | - * |
|
199 | - * @param EE_Base_Class|int $this_obj_or_id |
|
200 | - * @param EE_Base_Class|int $other_obj_or_id |
|
201 | - * @param array $where_query col=>val pairs that are used as extra conditions for checking existing |
|
202 | - * values and for removing existing rows if exact matches exist. |
|
203 | - * @return EE_Base_Class |
|
204 | - * @throws \EE_Error |
|
205 | - */ |
|
206 | - public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()) |
|
207 | - { |
|
208 | - $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
|
209 | - $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
210 | - // check if such a relationship already exists |
|
211 | - $join_model_fk_to_this_model = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
212 | - $join_model_fk_to_other_model = $this->get_join_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
196 | + /** |
|
197 | + * Deletes any rows in the join table that have foreign keys matching the other model objects specified |
|
198 | + * |
|
199 | + * @param EE_Base_Class|int $this_obj_or_id |
|
200 | + * @param EE_Base_Class|int $other_obj_or_id |
|
201 | + * @param array $where_query col=>val pairs that are used as extra conditions for checking existing |
|
202 | + * values and for removing existing rows if exact matches exist. |
|
203 | + * @return EE_Base_Class |
|
204 | + * @throws \EE_Error |
|
205 | + */ |
|
206 | + public function remove_relation_to($this_obj_or_id, $other_obj_or_id, $where_query = array()) |
|
207 | + { |
|
208 | + $this_model_obj = $this->get_this_model()->ensure_is_obj($this_obj_or_id, true); |
|
209 | + $other_model_obj = $this->get_other_model()->ensure_is_obj($other_obj_or_id, true); |
|
210 | + // check if such a relationship already exists |
|
211 | + $join_model_fk_to_this_model = $this->get_join_model()->get_foreign_key_to($this->get_this_model()->get_this_model_name()); |
|
212 | + $join_model_fk_to_other_model = $this->get_join_model()->get_foreign_key_to($this->get_other_model()->get_this_model_name()); |
|
213 | 213 | |
214 | - $cols_n_values = array( |
|
215 | - $join_model_fk_to_this_model->get_name() => $this_model_obj->ID(), |
|
216 | - $join_model_fk_to_other_model->get_name() => $other_model_obj->ID(), |
|
217 | - ); |
|
214 | + $cols_n_values = array( |
|
215 | + $join_model_fk_to_this_model->get_name() => $this_model_obj->ID(), |
|
216 | + $join_model_fk_to_other_model->get_name() => $other_model_obj->ID(), |
|
217 | + ); |
|
218 | 218 | |
219 | - // if $where_query exists lets add them to the query_params. |
|
220 | - if (! empty($where_query)) { |
|
221 | - // make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name) |
|
222 | - // make sure we strip THIS models name from the query param |
|
223 | - $parsed_query = array(); |
|
224 | - foreach ($where_query as $query_param => $val) { |
|
225 | - $query_param = str_replace( |
|
226 | - $this->get_join_model()->get_this_model_name() . ".", |
|
227 | - "", |
|
228 | - $query_param |
|
229 | - ); |
|
230 | - $parsed_query[ $query_param ] = $val; |
|
231 | - } |
|
232 | - $cols_n_values = array_merge($cols_n_values, $parsed_query); |
|
233 | - } |
|
219 | + // if $where_query exists lets add them to the query_params. |
|
220 | + if (! empty($where_query)) { |
|
221 | + // make sure we strip any of the join model names from the $where_query cause we don't need that in here (why? because client code may have used the same conditionals for get_all_related which DOES need the join model name) |
|
222 | + // make sure we strip THIS models name from the query param |
|
223 | + $parsed_query = array(); |
|
224 | + foreach ($where_query as $query_param => $val) { |
|
225 | + $query_param = str_replace( |
|
226 | + $this->get_join_model()->get_this_model_name() . ".", |
|
227 | + "", |
|
228 | + $query_param |
|
229 | + ); |
|
230 | + $parsed_query[ $query_param ] = $val; |
|
231 | + } |
|
232 | + $cols_n_values = array_merge($cols_n_values, $parsed_query); |
|
233 | + } |
|
234 | 234 | |
235 | - $this->get_join_model()->delete(array($cols_n_values)); |
|
236 | - return $other_model_obj; |
|
237 | - } |
|
235 | + $this->get_join_model()->delete(array($cols_n_values)); |
|
236 | + return $other_model_obj; |
|
237 | + } |
|
238 | 238 | |
239 | - /** |
|
240 | - * Gets all the non-key fields (ie, not the primary key and not foreign keys) on the join model. |
|
241 | - * @since 4.9.76.p |
|
242 | - * @return EE_Model_Field_Base[] |
|
243 | - * @throws EE_Error |
|
244 | - */ |
|
245 | - public function getNonKeyFields() |
|
246 | - { |
|
247 | - // all fields besides the primary key and two foreign keys should be parameters |
|
248 | - $join_model = $this->get_join_model(); |
|
249 | - $standard_fields = array(); |
|
250 | - if ($join_model->has_primary_key_field()) { |
|
251 | - $standard_fields[] = $join_model->primary_key_name(); |
|
252 | - } |
|
253 | - if ($this->get_this_model()->has_primary_key_field()) { |
|
254 | - $standard_fields[] = $this->get_this_model()->primary_key_name(); |
|
255 | - } |
|
256 | - if ($this->get_other_model()->has_primary_key_field()) { |
|
257 | - $standard_fields[] = $this->get_other_model()->primary_key_name(); |
|
258 | - } |
|
259 | - return array_diff_key( |
|
260 | - $join_model->field_settings(), |
|
261 | - array_flip($standard_fields) |
|
262 | - ); |
|
263 | - } |
|
239 | + /** |
|
240 | + * Gets all the non-key fields (ie, not the primary key and not foreign keys) on the join model. |
|
241 | + * @since 4.9.76.p |
|
242 | + * @return EE_Model_Field_Base[] |
|
243 | + * @throws EE_Error |
|
244 | + */ |
|
245 | + public function getNonKeyFields() |
|
246 | + { |
|
247 | + // all fields besides the primary key and two foreign keys should be parameters |
|
248 | + $join_model = $this->get_join_model(); |
|
249 | + $standard_fields = array(); |
|
250 | + if ($join_model->has_primary_key_field()) { |
|
251 | + $standard_fields[] = $join_model->primary_key_name(); |
|
252 | + } |
|
253 | + if ($this->get_this_model()->has_primary_key_field()) { |
|
254 | + $standard_fields[] = $this->get_this_model()->primary_key_name(); |
|
255 | + } |
|
256 | + if ($this->get_other_model()->has_primary_key_field()) { |
|
257 | + $standard_fields[] = $this->get_other_model()->primary_key_name(); |
|
258 | + } |
|
259 | + return array_diff_key( |
|
260 | + $join_model->field_settings(), |
|
261 | + array_flip($standard_fields) |
|
262 | + ); |
|
263 | + } |
|
264 | 264 | |
265 | - /** |
|
266 | - * Returns true if the join model has non-key fields (ie, fields that aren't the primary key or foreign keys.) |
|
267 | - * @since 4.9.76.p |
|
268 | - * @return boolean |
|
269 | - */ |
|
270 | - public function hasNonKeyFields() |
|
271 | - { |
|
272 | - return count($this->get_join_model()->field_settings()) > 3; |
|
273 | - } |
|
265 | + /** |
|
266 | + * Returns true if the join model has non-key fields (ie, fields that aren't the primary key or foreign keys.) |
|
267 | + * @since 4.9.76.p |
|
268 | + * @return boolean |
|
269 | + */ |
|
270 | + public function hasNonKeyFields() |
|
271 | + { |
|
272 | + return count($this->get_join_model()->field_settings()) > 3; |
|
273 | + } |
|
274 | 274 | } |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | public static function instance(ClassInterfaceCache $class_cache = null) |
123 | 123 | { |
124 | 124 | // check if class object is instantiated, and instantiated properly |
125 | - if (! self::$_instance instanceof EE_Dependency_Map |
|
125 | + if ( ! self::$_instance instanceof EE_Dependency_Map |
|
126 | 126 | && $class_cache instanceof ClassInterfaceCache |
127 | 127 | ) { |
128 | 128 | self::$_instance = new EE_Dependency_Map($class_cache); |
@@ -203,18 +203,18 @@ discard block |
||
203 | 203 | ) { |
204 | 204 | $class = trim($class, '\\'); |
205 | 205 | $registered = false; |
206 | - if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
207 | - self::$_instance->_dependency_map[ $class ] = array(); |
|
206 | + if (empty(self::$_instance->_dependency_map[$class])) { |
|
207 | + self::$_instance->_dependency_map[$class] = array(); |
|
208 | 208 | } |
209 | 209 | // we need to make sure that any aliases used when registering a dependency |
210 | 210 | // get resolved to the correct class name |
211 | 211 | foreach ($dependencies as $dependency => $load_source) { |
212 | 212 | $alias = self::$_instance->getFqnForAlias($dependency); |
213 | 213 | if ($overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
214 | - || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
214 | + || ! isset(self::$_instance->_dependency_map[$class][$alias]) |
|
215 | 215 | ) { |
216 | - unset($dependencies[ $dependency ]); |
|
217 | - $dependencies[ $alias ] = $load_source; |
|
216 | + unset($dependencies[$dependency]); |
|
217 | + $dependencies[$alias] = $load_source; |
|
218 | 218 | $registered = true; |
219 | 219 | } |
220 | 220 | } |
@@ -224,13 +224,13 @@ discard block |
||
224 | 224 | // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
225 | 225 | // Union is way faster than array_merge() but should be used with caution... |
226 | 226 | // especially with numerically indexed arrays |
227 | - $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
227 | + $dependencies += self::$_instance->_dependency_map[$class]; |
|
228 | 228 | // now we need to ensure that the resulting dependencies |
229 | 229 | // array only has the entries that are required for the class |
230 | 230 | // so first count how many dependencies were originally registered for the class |
231 | - $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
231 | + $dependency_count = count(self::$_instance->_dependency_map[$class]); |
|
232 | 232 | // if that count is non-zero (meaning dependencies were already registered) |
233 | - self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
233 | + self::$_instance->_dependency_map[$class] = $dependency_count |
|
234 | 234 | // then truncate the final array to match that count |
235 | 235 | ? array_slice($dependencies, 0, $dependency_count) |
236 | 236 | // otherwise just take the incoming array because nothing previously existed |
@@ -247,13 +247,13 @@ discard block |
||
247 | 247 | */ |
248 | 248 | public static function register_class_loader($class_name, $loader = 'load_core') |
249 | 249 | { |
250 | - if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
250 | + if ( ! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
251 | 251 | throw new DomainException( |
252 | 252 | esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
253 | 253 | ); |
254 | 254 | } |
255 | 255 | // check that loader is callable or method starts with "load_" and exists in EE_Registry |
256 | - if (! is_callable($loader) |
|
256 | + if ( ! is_callable($loader) |
|
257 | 257 | && ( |
258 | 258 | strpos($loader, 'load_') !== 0 |
259 | 259 | || ! method_exists('EE_Registry', $loader) |
@@ -270,8 +270,8 @@ discard block |
||
270 | 270 | ); |
271 | 271 | } |
272 | 272 | $class_name = self::$_instance->getFqnForAlias($class_name); |
273 | - if (! isset(self::$_instance->_class_loaders[ $class_name ])) { |
|
274 | - self::$_instance->_class_loaders[ $class_name ] = $loader; |
|
273 | + if ( ! isset(self::$_instance->_class_loaders[$class_name])) { |
|
274 | + self::$_instance->_class_loaders[$class_name] = $loader; |
|
275 | 275 | return true; |
276 | 276 | } |
277 | 277 | return false; |
@@ -299,7 +299,7 @@ discard block |
||
299 | 299 | if (strpos($class_name, 'EEM_') === 0) { |
300 | 300 | $class_name = 'LEGACY_MODELS'; |
301 | 301 | } |
302 | - return isset($this->_dependency_map[ $class_name ]) ? true : false; |
|
302 | + return isset($this->_dependency_map[$class_name]) ? true : false; |
|
303 | 303 | } |
304 | 304 | |
305 | 305 | |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | $class_name = 'LEGACY_MODELS'; |
318 | 318 | } |
319 | 319 | $dependency = $this->getFqnForAlias($dependency, $class_name); |
320 | - return isset($this->_dependency_map[ $class_name ][ $dependency ]) |
|
320 | + return isset($this->_dependency_map[$class_name][$dependency]) |
|
321 | 321 | ? true |
322 | 322 | : false; |
323 | 323 | } |
@@ -338,7 +338,7 @@ discard block |
||
338 | 338 | } |
339 | 339 | $dependency = $this->getFqnForAlias($dependency); |
340 | 340 | return $this->has_dependency_for_class($class_name, $dependency) |
341 | - ? $this->_dependency_map[ $class_name ][ $dependency ] |
|
341 | + ? $this->_dependency_map[$class_name][$dependency] |
|
342 | 342 | : EE_Dependency_Map::not_registered; |
343 | 343 | } |
344 | 344 | |
@@ -361,7 +361,7 @@ discard block |
||
361 | 361 | return 'load_core'; |
362 | 362 | } |
363 | 363 | $class_name = $this->getFqnForAlias($class_name); |
364 | - return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : ''; |
|
364 | + return isset($this->_class_loaders[$class_name]) ? $this->_class_loaders[$class_name] : ''; |
|
365 | 365 | } |
366 | 366 | |
367 | 367 | |
@@ -882,7 +882,7 @@ discard block |
||
882 | 882 | { |
883 | 883 | $this->_class_loaders = array( |
884 | 884 | // load_core |
885 | - 'EE_Dependency_Map' => function () { |
|
885 | + 'EE_Dependency_Map' => function() { |
|
886 | 886 | return $this; |
887 | 887 | }, |
888 | 888 | 'EE_Capabilities' => 'load_core', |
@@ -890,13 +890,13 @@ discard block |
||
890 | 890 | 'EE_Front_Controller' => 'load_core', |
891 | 891 | 'EE_Module_Request_Router' => 'load_core', |
892 | 892 | 'EE_Registry' => 'load_core', |
893 | - 'EE_Request' => function () { |
|
893 | + 'EE_Request' => function() { |
|
894 | 894 | return $this->legacy_request; |
895 | 895 | }, |
896 | - 'EventEspresso\core\services\request\Request' => function () { |
|
896 | + 'EventEspresso\core\services\request\Request' => function() { |
|
897 | 897 | return $this->request; |
898 | 898 | }, |
899 | - 'EventEspresso\core\services\request\Response' => function () { |
|
899 | + 'EventEspresso\core\services\request\Response' => function() { |
|
900 | 900 | return $this->response; |
901 | 901 | }, |
902 | 902 | 'EE_Base' => 'load_core', |
@@ -929,7 +929,7 @@ discard block |
||
929 | 929 | 'EE_DMS_Core_4_8_0' => 'load_dms', |
930 | 930 | 'EE_DMS_Core_4_9_0' => 'load_dms', |
931 | 931 | 'EE_DMS_Core_4_10_0' => 'load_dms', |
932 | - 'EE_Messages_Generator' => function () { |
|
932 | + 'EE_Messages_Generator' => function() { |
|
933 | 933 | return EE_Registry::instance()->load_lib( |
934 | 934 | 'Messages_Generator', |
935 | 935 | array(), |
@@ -937,7 +937,7 @@ discard block |
||
937 | 937 | false |
938 | 938 | ); |
939 | 939 | }, |
940 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
940 | + 'EE_Messages_Template_Defaults' => function($arguments = array()) { |
|
941 | 941 | return EE_Registry::instance()->load_lib( |
942 | 942 | 'Messages_Template_Defaults', |
943 | 943 | $arguments, |
@@ -946,46 +946,46 @@ discard block |
||
946 | 946 | ); |
947 | 947 | }, |
948 | 948 | // load_helper |
949 | - 'EEH_Parse_Shortcodes' => function () { |
|
949 | + 'EEH_Parse_Shortcodes' => function() { |
|
950 | 950 | if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
951 | 951 | return new EEH_Parse_Shortcodes(); |
952 | 952 | } |
953 | 953 | return null; |
954 | 954 | }, |
955 | - 'EE_Template_Config' => function () { |
|
955 | + 'EE_Template_Config' => function() { |
|
956 | 956 | return EE_Config::instance()->template_settings; |
957 | 957 | }, |
958 | - 'EE_Currency_Config' => function () { |
|
958 | + 'EE_Currency_Config' => function() { |
|
959 | 959 | return EE_Config::instance()->currency; |
960 | 960 | }, |
961 | - 'EE_Registration_Config' => function () { |
|
961 | + 'EE_Registration_Config' => function() { |
|
962 | 962 | return EE_Config::instance()->registration; |
963 | 963 | }, |
964 | - 'EE_Core_Config' => function () { |
|
964 | + 'EE_Core_Config' => function() { |
|
965 | 965 | return EE_Config::instance()->core; |
966 | 966 | }, |
967 | - 'EventEspresso\core\services\loaders\Loader' => function () { |
|
967 | + 'EventEspresso\core\services\loaders\Loader' => function() { |
|
968 | 968 | return LoaderFactory::getLoader(); |
969 | 969 | }, |
970 | - 'EE_Network_Config' => function () { |
|
970 | + 'EE_Network_Config' => function() { |
|
971 | 971 | return EE_Network_Config::instance(); |
972 | 972 | }, |
973 | - 'EE_Config' => function () { |
|
973 | + 'EE_Config' => function() { |
|
974 | 974 | return EE_Config::instance(); |
975 | 975 | }, |
976 | - 'EventEspresso\core\domain\Domain' => function () { |
|
976 | + 'EventEspresso\core\domain\Domain' => function() { |
|
977 | 977 | return DomainFactory::getEventEspressoCoreDomain(); |
978 | 978 | }, |
979 | - 'EE_Admin_Config' => function () { |
|
979 | + 'EE_Admin_Config' => function() { |
|
980 | 980 | return EE_Config::instance()->admin; |
981 | 981 | }, |
982 | - 'EE_Organization_Config' => function () { |
|
982 | + 'EE_Organization_Config' => function() { |
|
983 | 983 | return EE_Config::instance()->organization; |
984 | 984 | }, |
985 | - 'EE_Network_Core_Config' => function () { |
|
985 | + 'EE_Network_Core_Config' => function() { |
|
986 | 986 | return EE_Network_Config::instance()->core; |
987 | 987 | }, |
988 | - 'EE_Environment_Config' => function () { |
|
988 | + 'EE_Environment_Config' => function() { |
|
989 | 989 | return EE_Config::instance()->environment; |
990 | 990 | }, |
991 | 991 | ); |
@@ -1046,7 +1046,7 @@ discard block |
||
1046 | 1046 | } |
1047 | 1047 | $this->class_cache->addAlias($fqn, $alias); |
1048 | 1048 | } |
1049 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
1049 | + if ( ! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
1050 | 1050 | $this->class_cache->addAlias( |
1051 | 1051 | 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
1052 | 1052 | 'EventEspresso\core\services\notices\NoticeConverterInterface' |
@@ -20,1128 +20,1128 @@ |
||
20 | 20 | class EE_Dependency_Map |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * This means that the requested class dependency is not present in the dependency map |
|
25 | - */ |
|
26 | - const not_registered = 0; |
|
27 | - |
|
28 | - /** |
|
29 | - * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
30 | - */ |
|
31 | - const load_new_object = 1; |
|
32 | - |
|
33 | - /** |
|
34 | - * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
35 | - * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
36 | - */ |
|
37 | - const load_from_cache = 2; |
|
38 | - |
|
39 | - /** |
|
40 | - * When registering a dependency, |
|
41 | - * this indicates to keep any existing dependencies that already exist, |
|
42 | - * and simply discard any new dependencies declared in the incoming data |
|
43 | - */ |
|
44 | - const KEEP_EXISTING_DEPENDENCIES = 0; |
|
45 | - |
|
46 | - /** |
|
47 | - * When registering a dependency, |
|
48 | - * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
49 | - */ |
|
50 | - const OVERWRITE_DEPENDENCIES = 1; |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * @type EE_Dependency_Map $_instance |
|
55 | - */ |
|
56 | - protected static $_instance; |
|
57 | - |
|
58 | - /** |
|
59 | - * @var ClassInterfaceCache $class_cache |
|
60 | - */ |
|
61 | - private $class_cache; |
|
62 | - |
|
63 | - /** |
|
64 | - * @type RequestInterface $request |
|
65 | - */ |
|
66 | - protected $request; |
|
67 | - |
|
68 | - /** |
|
69 | - * @type LegacyRequestInterface $legacy_request |
|
70 | - */ |
|
71 | - protected $legacy_request; |
|
72 | - |
|
73 | - /** |
|
74 | - * @type ResponseInterface $response |
|
75 | - */ |
|
76 | - protected $response; |
|
77 | - |
|
78 | - /** |
|
79 | - * @type LoaderInterface $loader |
|
80 | - */ |
|
81 | - protected $loader; |
|
82 | - |
|
83 | - /** |
|
84 | - * @type array $_dependency_map |
|
85 | - */ |
|
86 | - protected $_dependency_map = array(); |
|
87 | - |
|
88 | - /** |
|
89 | - * @type array $_class_loaders |
|
90 | - */ |
|
91 | - protected $_class_loaders = array(); |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * EE_Dependency_Map constructor. |
|
96 | - * |
|
97 | - * @param ClassInterfaceCache $class_cache |
|
98 | - */ |
|
99 | - protected function __construct(ClassInterfaceCache $class_cache) |
|
100 | - { |
|
101 | - $this->class_cache = $class_cache; |
|
102 | - do_action('EE_Dependency_Map____construct', $this); |
|
103 | - } |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * @return void |
|
108 | - */ |
|
109 | - public function initialize() |
|
110 | - { |
|
111 | - $this->_register_core_dependencies(); |
|
112 | - $this->_register_core_class_loaders(); |
|
113 | - $this->_register_core_aliases(); |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * @singleton method used to instantiate class object |
|
119 | - * @param ClassInterfaceCache|null $class_cache |
|
120 | - * @return EE_Dependency_Map |
|
121 | - */ |
|
122 | - public static function instance(ClassInterfaceCache $class_cache = null) |
|
123 | - { |
|
124 | - // check if class object is instantiated, and instantiated properly |
|
125 | - if (! self::$_instance instanceof EE_Dependency_Map |
|
126 | - && $class_cache instanceof ClassInterfaceCache |
|
127 | - ) { |
|
128 | - self::$_instance = new EE_Dependency_Map($class_cache); |
|
129 | - } |
|
130 | - return self::$_instance; |
|
131 | - } |
|
132 | - |
|
133 | - |
|
134 | - /** |
|
135 | - * @param RequestInterface $request |
|
136 | - */ |
|
137 | - public function setRequest(RequestInterface $request) |
|
138 | - { |
|
139 | - $this->request = $request; |
|
140 | - } |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * @param LegacyRequestInterface $legacy_request |
|
145 | - */ |
|
146 | - public function setLegacyRequest(LegacyRequestInterface $legacy_request) |
|
147 | - { |
|
148 | - $this->legacy_request = $legacy_request; |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * @param ResponseInterface $response |
|
154 | - */ |
|
155 | - public function setResponse(ResponseInterface $response) |
|
156 | - { |
|
157 | - $this->response = $response; |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * @param LoaderInterface $loader |
|
163 | - */ |
|
164 | - public function setLoader(LoaderInterface $loader) |
|
165 | - { |
|
166 | - $this->loader = $loader; |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * @param string $class |
|
172 | - * @param array $dependencies |
|
173 | - * @param int $overwrite |
|
174 | - * @return bool |
|
175 | - */ |
|
176 | - public static function register_dependencies( |
|
177 | - $class, |
|
178 | - array $dependencies, |
|
179 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
180 | - ) { |
|
181 | - return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * Assigns an array of class names and corresponding load sources (new or cached) |
|
187 | - * to the class specified by the first parameter. |
|
188 | - * IMPORTANT !!! |
|
189 | - * The order of elements in the incoming $dependencies array MUST match |
|
190 | - * the order of the constructor parameters for the class in question. |
|
191 | - * This is especially important when overriding any existing dependencies that are registered. |
|
192 | - * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
193 | - * |
|
194 | - * @param string $class |
|
195 | - * @param array $dependencies |
|
196 | - * @param int $overwrite |
|
197 | - * @return bool |
|
198 | - */ |
|
199 | - public function registerDependencies( |
|
200 | - $class, |
|
201 | - array $dependencies, |
|
202 | - $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
203 | - ) { |
|
204 | - $class = trim($class, '\\'); |
|
205 | - $registered = false; |
|
206 | - if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
207 | - self::$_instance->_dependency_map[ $class ] = array(); |
|
208 | - } |
|
209 | - // we need to make sure that any aliases used when registering a dependency |
|
210 | - // get resolved to the correct class name |
|
211 | - foreach ($dependencies as $dependency => $load_source) { |
|
212 | - $alias = self::$_instance->getFqnForAlias($dependency); |
|
213 | - if ($overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
214 | - || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
215 | - ) { |
|
216 | - unset($dependencies[ $dependency ]); |
|
217 | - $dependencies[ $alias ] = $load_source; |
|
218 | - $registered = true; |
|
219 | - } |
|
220 | - } |
|
221 | - // now add our two lists of dependencies together. |
|
222 | - // using Union (+=) favours the arrays in precedence from left to right, |
|
223 | - // so $dependencies is NOT overwritten because it is listed first |
|
224 | - // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
225 | - // Union is way faster than array_merge() but should be used with caution... |
|
226 | - // especially with numerically indexed arrays |
|
227 | - $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
228 | - // now we need to ensure that the resulting dependencies |
|
229 | - // array only has the entries that are required for the class |
|
230 | - // so first count how many dependencies were originally registered for the class |
|
231 | - $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
232 | - // if that count is non-zero (meaning dependencies were already registered) |
|
233 | - self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
234 | - // then truncate the final array to match that count |
|
235 | - ? array_slice($dependencies, 0, $dependency_count) |
|
236 | - // otherwise just take the incoming array because nothing previously existed |
|
237 | - : $dependencies; |
|
238 | - return $registered; |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - /** |
|
243 | - * @param string $class_name |
|
244 | - * @param string $loader |
|
245 | - * @return bool |
|
246 | - * @throws DomainException |
|
247 | - */ |
|
248 | - public static function register_class_loader($class_name, $loader = 'load_core') |
|
249 | - { |
|
250 | - if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
251 | - throw new DomainException( |
|
252 | - esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
253 | - ); |
|
254 | - } |
|
255 | - // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
256 | - if (! is_callable($loader) |
|
257 | - && ( |
|
258 | - strpos($loader, 'load_') !== 0 |
|
259 | - || ! method_exists('EE_Registry', $loader) |
|
260 | - ) |
|
261 | - ) { |
|
262 | - throw new DomainException( |
|
263 | - sprintf( |
|
264 | - esc_html__( |
|
265 | - '"%1$s" is not a valid loader method on EE_Registry.', |
|
266 | - 'event_espresso' |
|
267 | - ), |
|
268 | - $loader |
|
269 | - ) |
|
270 | - ); |
|
271 | - } |
|
272 | - $class_name = self::$_instance->getFqnForAlias($class_name); |
|
273 | - if (! isset(self::$_instance->_class_loaders[ $class_name ])) { |
|
274 | - self::$_instance->_class_loaders[ $class_name ] = $loader; |
|
275 | - return true; |
|
276 | - } |
|
277 | - return false; |
|
278 | - } |
|
279 | - |
|
280 | - |
|
281 | - /** |
|
282 | - * @return array |
|
283 | - */ |
|
284 | - public function dependency_map() |
|
285 | - { |
|
286 | - return $this->_dependency_map; |
|
287 | - } |
|
288 | - |
|
289 | - |
|
290 | - /** |
|
291 | - * returns TRUE if dependency map contains a listing for the provided class name |
|
292 | - * |
|
293 | - * @param string $class_name |
|
294 | - * @return boolean |
|
295 | - */ |
|
296 | - public function has($class_name = '') |
|
297 | - { |
|
298 | - // all legacy models have the same dependencies |
|
299 | - if (strpos($class_name, 'EEM_') === 0) { |
|
300 | - $class_name = 'LEGACY_MODELS'; |
|
301 | - } |
|
302 | - return isset($this->_dependency_map[ $class_name ]) ? true : false; |
|
303 | - } |
|
304 | - |
|
305 | - |
|
306 | - /** |
|
307 | - * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
308 | - * |
|
309 | - * @param string $class_name |
|
310 | - * @param string $dependency |
|
311 | - * @return bool |
|
312 | - */ |
|
313 | - public function has_dependency_for_class($class_name = '', $dependency = '') |
|
314 | - { |
|
315 | - // all legacy models have the same dependencies |
|
316 | - if (strpos($class_name, 'EEM_') === 0) { |
|
317 | - $class_name = 'LEGACY_MODELS'; |
|
318 | - } |
|
319 | - $dependency = $this->getFqnForAlias($dependency, $class_name); |
|
320 | - return isset($this->_dependency_map[ $class_name ][ $dependency ]) |
|
321 | - ? true |
|
322 | - : false; |
|
323 | - } |
|
324 | - |
|
325 | - |
|
326 | - /** |
|
327 | - * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
328 | - * |
|
329 | - * @param string $class_name |
|
330 | - * @param string $dependency |
|
331 | - * @return int |
|
332 | - */ |
|
333 | - public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
334 | - { |
|
335 | - // all legacy models have the same dependencies |
|
336 | - if (strpos($class_name, 'EEM_') === 0) { |
|
337 | - $class_name = 'LEGACY_MODELS'; |
|
338 | - } |
|
339 | - $dependency = $this->getFqnForAlias($dependency); |
|
340 | - return $this->has_dependency_for_class($class_name, $dependency) |
|
341 | - ? $this->_dependency_map[ $class_name ][ $dependency ] |
|
342 | - : EE_Dependency_Map::not_registered; |
|
343 | - } |
|
344 | - |
|
345 | - |
|
346 | - /** |
|
347 | - * @param string $class_name |
|
348 | - * @return string | Closure |
|
349 | - */ |
|
350 | - public function class_loader($class_name) |
|
351 | - { |
|
352 | - // all legacy models use load_model() |
|
353 | - if (strpos($class_name, 'EEM_') === 0) { |
|
354 | - return 'load_model'; |
|
355 | - } |
|
356 | - // EE_CPT_*_Strategy classes like EE_CPT_Event_Strategy, EE_CPT_Venue_Strategy, etc |
|
357 | - // perform strpos() first to avoid loading regex every time we load a class |
|
358 | - if (strpos($class_name, 'EE_CPT_') === 0 |
|
359 | - && preg_match('/^EE_CPT_([a-zA-Z]+)_Strategy$/', $class_name) |
|
360 | - ) { |
|
361 | - return 'load_core'; |
|
362 | - } |
|
363 | - $class_name = $this->getFqnForAlias($class_name); |
|
364 | - return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : ''; |
|
365 | - } |
|
366 | - |
|
367 | - |
|
368 | - /** |
|
369 | - * @return array |
|
370 | - */ |
|
371 | - public function class_loaders() |
|
372 | - { |
|
373 | - return $this->_class_loaders; |
|
374 | - } |
|
375 | - |
|
376 | - |
|
377 | - /** |
|
378 | - * adds an alias for a classname |
|
379 | - * |
|
380 | - * @param string $fqcn the class name that should be used (concrete class to replace interface) |
|
381 | - * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
382 | - * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
383 | - */ |
|
384 | - public function add_alias($fqcn, $alias, $for_class = '') |
|
385 | - { |
|
386 | - $this->class_cache->addAlias($fqcn, $alias, $for_class); |
|
387 | - } |
|
388 | - |
|
389 | - |
|
390 | - /** |
|
391 | - * Returns TRUE if the provided fully qualified name IS an alias |
|
392 | - * WHY? |
|
393 | - * Because if a class is type hinting for a concretion, |
|
394 | - * then why would we need to find another class to supply it? |
|
395 | - * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
396 | - * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
397 | - * Don't go looking for some substitute. |
|
398 | - * Whereas if a class is type hinting for an interface... |
|
399 | - * then we need to find an actual class to use. |
|
400 | - * So the interface IS the alias for some other FQN, |
|
401 | - * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
402 | - * represents some other class. |
|
403 | - * |
|
404 | - * @param string $fqn |
|
405 | - * @param string $for_class |
|
406 | - * @return bool |
|
407 | - */ |
|
408 | - public function isAlias($fqn = '', $for_class = '') |
|
409 | - { |
|
410 | - return $this->class_cache->isAlias($fqn, $for_class); |
|
411 | - } |
|
412 | - |
|
413 | - |
|
414 | - /** |
|
415 | - * Returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
416 | - * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
417 | - * for example: |
|
418 | - * if the following two entries were added to the _aliases array: |
|
419 | - * array( |
|
420 | - * 'interface_alias' => 'some\namespace\interface' |
|
421 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
422 | - * ) |
|
423 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
424 | - * to load an instance of 'some\namespace\classname' |
|
425 | - * |
|
426 | - * @param string $alias |
|
427 | - * @param string $for_class |
|
428 | - * @return string |
|
429 | - */ |
|
430 | - public function getFqnForAlias($alias = '', $for_class = '') |
|
431 | - { |
|
432 | - return (string) $this->class_cache->getFqnForAlias($alias, $for_class); |
|
433 | - } |
|
434 | - |
|
435 | - |
|
436 | - /** |
|
437 | - * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
438 | - * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
439 | - * This is done by using the following class constants: |
|
440 | - * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
441 | - * EE_Dependency_Map::load_new_object - generates a new object every time |
|
442 | - */ |
|
443 | - protected function _register_core_dependencies() |
|
444 | - { |
|
445 | - $this->_dependency_map = array( |
|
446 | - 'EE_Request_Handler' => array( |
|
447 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
448 | - ), |
|
449 | - 'EE_System' => array( |
|
450 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
451 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
452 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
453 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
454 | - ), |
|
455 | - 'EE_Session' => array( |
|
456 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
457 | - 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
458 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
459 | - 'EventEspresso\core\services\session\SessionStartHandler' => EE_Dependency_Map::load_from_cache, |
|
460 | - 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
461 | - ), |
|
462 | - 'EE_Cart' => array( |
|
463 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
464 | - ), |
|
465 | - 'EE_Front_Controller' => array( |
|
466 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
467 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
468 | - 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
469 | - ), |
|
470 | - 'EE_Messenger_Collection_Loader' => array( |
|
471 | - 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
472 | - ), |
|
473 | - 'EE_Message_Type_Collection_Loader' => array( |
|
474 | - 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
475 | - ), |
|
476 | - 'EE_Message_Resource_Manager' => array( |
|
477 | - 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
478 | - 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
479 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
480 | - ), |
|
481 | - 'EE_Message_Factory' => array( |
|
482 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
483 | - ), |
|
484 | - 'EE_messages' => array( |
|
485 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
486 | - ), |
|
487 | - 'EE_Messages_Generator' => array( |
|
488 | - 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
489 | - 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
490 | - 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
491 | - 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
492 | - ), |
|
493 | - 'EE_Messages_Processor' => array( |
|
494 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
495 | - ), |
|
496 | - 'EE_Messages_Queue' => array( |
|
497 | - 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
498 | - ), |
|
499 | - 'EE_Messages_Template_Defaults' => array( |
|
500 | - 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
501 | - 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
502 | - ), |
|
503 | - 'EE_Message_To_Generate_From_Request' => array( |
|
504 | - 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
505 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
506 | - ), |
|
507 | - 'EventEspresso\core\services\commands\CommandBus' => array( |
|
508 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
509 | - ), |
|
510 | - 'EventEspresso\services\commands\CommandHandler' => array( |
|
511 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
512 | - 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
513 | - ), |
|
514 | - 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
515 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
516 | - ), |
|
517 | - 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
518 | - 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
519 | - 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
520 | - ), |
|
521 | - 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
522 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
523 | - ), |
|
524 | - 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
525 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
526 | - ), |
|
527 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
528 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
529 | - ), |
|
530 | - 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
531 | - 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
532 | - ), |
|
533 | - 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
534 | - 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
535 | - ), |
|
536 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
537 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
538 | - ), |
|
539 | - 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
540 | - 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
541 | - ), |
|
542 | - 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
543 | - 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
544 | - ), |
|
545 | - 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
546 | - 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
547 | - ), |
|
548 | - 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
549 | - 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
550 | - ), |
|
551 | - 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
552 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
553 | - ), |
|
554 | - 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
555 | - 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
556 | - ), |
|
557 | - 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
558 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
559 | - ), |
|
560 | - 'EventEspresso\core\services\database\TableManager' => array( |
|
561 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
562 | - ), |
|
563 | - 'EE_Data_Migration_Class_Base' => array( |
|
564 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
565 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
566 | - ), |
|
567 | - 'EE_DMS_Core_4_1_0' => array( |
|
568 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
569 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
570 | - ), |
|
571 | - 'EE_DMS_Core_4_2_0' => array( |
|
572 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
573 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
574 | - ), |
|
575 | - 'EE_DMS_Core_4_3_0' => array( |
|
576 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
577 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
578 | - ), |
|
579 | - 'EE_DMS_Core_4_4_0' => array( |
|
580 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
581 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
582 | - ), |
|
583 | - 'EE_DMS_Core_4_5_0' => array( |
|
584 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
585 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
586 | - ), |
|
587 | - 'EE_DMS_Core_4_6_0' => array( |
|
588 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
589 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
590 | - ), |
|
591 | - 'EE_DMS_Core_4_7_0' => array( |
|
592 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
593 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
594 | - ), |
|
595 | - 'EE_DMS_Core_4_8_0' => array( |
|
596 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
597 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
598 | - ), |
|
599 | - 'EE_DMS_Core_4_9_0' => array( |
|
600 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
601 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
602 | - ), |
|
603 | - 'EE_DMS_Core_4_10_0' => array( |
|
604 | - 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
605 | - 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
606 | - 'EE_DMS_Core_4_9_0' => EE_Dependency_Map::load_from_cache, |
|
607 | - ), |
|
608 | - 'EventEspresso\core\services\assets\I18nRegistry' => array( |
|
609 | - array(), |
|
610 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
611 | - ), |
|
612 | - 'EventEspresso\core\services\assets\Registry' => array( |
|
613 | - 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
614 | - 'EventEspresso\core\services\assets\I18nRegistry' => EE_Dependency_Map::load_from_cache, |
|
615 | - ), |
|
616 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
617 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
618 | - ), |
|
619 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
620 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
621 | - ), |
|
622 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
623 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
624 | - ), |
|
625 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
626 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
627 | - ), |
|
628 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
629 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
630 | - ), |
|
631 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
632 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
633 | - ), |
|
634 | - 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
635 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
636 | - ), |
|
637 | - 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
638 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
639 | - ), |
|
640 | - 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
641 | - 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
642 | - ), |
|
643 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
644 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
645 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
646 | - ), |
|
647 | - 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
648 | - null, |
|
649 | - 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
650 | - ), |
|
651 | - 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
652 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
653 | - ), |
|
654 | - 'LEGACY_MODELS' => array( |
|
655 | - null, |
|
656 | - 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
657 | - ), |
|
658 | - 'EE_Module_Request_Router' => array( |
|
659 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
660 | - ), |
|
661 | - 'EE_Registration_Processor' => array( |
|
662 | - 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
663 | - ), |
|
664 | - 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array( |
|
665 | - null, |
|
666 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
667 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
668 | - ), |
|
669 | - 'EventEspresso\core\services\licensing\LicenseService' => array( |
|
670 | - 'EventEspresso\core\domain\services\pue\Stats' => EE_Dependency_Map::load_from_cache, |
|
671 | - 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
672 | - ), |
|
673 | - 'EE_Admin_Transactions_List_Table' => array( |
|
674 | - null, |
|
675 | - 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
676 | - ), |
|
677 | - 'EventEspresso\core\domain\services\pue\Stats' => array( |
|
678 | - 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
679 | - 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
680 | - 'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache, |
|
681 | - ), |
|
682 | - 'EventEspresso\core\domain\services\pue\Config' => array( |
|
683 | - 'EE_Network_Config' => EE_Dependency_Map::load_from_cache, |
|
684 | - 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
685 | - ), |
|
686 | - 'EventEspresso\core\domain\services\pue\StatsGatherer' => array( |
|
687 | - 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
688 | - 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
689 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
690 | - 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
691 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
692 | - 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
693 | - 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
694 | - ), |
|
695 | - 'EventEspresso\core\domain\services\admin\ExitModal' => array( |
|
696 | - 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
697 | - ), |
|
698 | - 'EventEspresso\core\domain\services\admin\PluginUpsells' => array( |
|
699 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
700 | - ), |
|
701 | - 'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => array( |
|
702 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
703 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
704 | - ), |
|
705 | - 'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings' => array( |
|
706 | - 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
707 | - ), |
|
708 | - 'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => array( |
|
709 | - 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
710 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
711 | - 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
712 | - 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
713 | - 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache, |
|
714 | - ), |
|
715 | - 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => array( |
|
716 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
717 | - ), |
|
718 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => array( |
|
719 | - 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
720 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
721 | - ), |
|
722 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' => array( |
|
723 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
724 | - ), |
|
725 | - 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' => array( |
|
726 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
727 | - ), |
|
728 | - 'EE_CPT_Strategy' => array( |
|
729 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
730 | - 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
731 | - ), |
|
732 | - 'EventEspresso\core\services\loaders\ObjectIdentifier' => array( |
|
733 | - 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
734 | - ), |
|
735 | - 'EventEspresso\core\domain\services\assets\CoreAssetManager' => array( |
|
736 | - 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
737 | - 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
738 | - 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
739 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
740 | - 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
741 | - ), |
|
742 | - 'EventEspresso\core\domain\services\admin\privacy\policy\PrivacyPolicy' => array( |
|
743 | - 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
744 | - 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache |
|
745 | - ), |
|
746 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendee' => array( |
|
747 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
748 | - ), |
|
749 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendeeBillingData' => array( |
|
750 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
751 | - 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache |
|
752 | - ), |
|
753 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportCheckins' => array( |
|
754 | - 'EEM_Checkin' => EE_Dependency_Map::load_from_cache, |
|
755 | - ), |
|
756 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportRegistration' => array( |
|
757 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
758 | - ), |
|
759 | - 'EventEspresso\core\domain\services\admin\privacy\export\ExportTransaction' => array( |
|
760 | - 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
761 | - ), |
|
762 | - 'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAttendeeData' => array( |
|
763 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
764 | - ), |
|
765 | - 'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAnswers' => array( |
|
766 | - 'EEM_Answer' => EE_Dependency_Map::load_from_cache, |
|
767 | - 'EEM_Question' => EE_Dependency_Map::load_from_cache, |
|
768 | - ), |
|
769 | - 'EventEspresso\core\CPTs\CptQueryModifier' => array( |
|
770 | - null, |
|
771 | - null, |
|
772 | - null, |
|
773 | - 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
774 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
775 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
776 | - ), |
|
777 | - 'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler' => array( |
|
778 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
779 | - 'EE_Config' => EE_Dependency_Map::load_from_cache |
|
780 | - ), |
|
781 | - 'EventEspresso\core\services\editor\BlockRegistrationManager' => array( |
|
782 | - 'EventEspresso\core\services\assets\BlockAssetManagerCollection' => EE_Dependency_Map::load_from_cache, |
|
783 | - 'EventEspresso\core\domain\entities\editor\BlockCollection' => EE_Dependency_Map::load_from_cache, |
|
784 | - 'EventEspresso\core\services\route_match\RouteMatchSpecificationManager' => EE_Dependency_Map::load_from_cache, |
|
785 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
786 | - ), |
|
787 | - 'EventEspresso\core\domain\entities\editor\CoreBlocksAssetManager' => array( |
|
788 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
789 | - 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
790 | - 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
791 | - ), |
|
792 | - 'EventEspresso\core\domain\services\blocks\EventAttendeesBlockRenderer' => array( |
|
793 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
794 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
795 | - ), |
|
796 | - 'EventEspresso\core\domain\entities\editor\blocks\EventAttendees' => array( |
|
797 | - 'EventEspresso\core\domain\entities\editor\CoreBlocksAssetManager' => self::load_from_cache, |
|
798 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
799 | - 'EventEspresso\core\domain\services\blocks\EventAttendeesBlockRenderer' => self::load_from_cache, |
|
800 | - ), |
|
801 | - 'EventEspresso\core\services\route_match\RouteMatchSpecificationDependencyResolver' => array( |
|
802 | - 'EventEspresso\core\services\container\Mirror' => EE_Dependency_Map::load_from_cache, |
|
803 | - 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
804 | - 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
805 | - ), |
|
806 | - 'EventEspresso\core\services\route_match\RouteMatchSpecificationFactory' => array( |
|
807 | - 'EventEspresso\core\services\route_match\RouteMatchSpecificationDependencyResolver' => EE_Dependency_Map::load_from_cache, |
|
808 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
809 | - ), |
|
810 | - 'EventEspresso\core\services\route_match\RouteMatchSpecificationManager' => array( |
|
811 | - 'EventEspresso\core\services\route_match\RouteMatchSpecificationCollection' => EE_Dependency_Map::load_from_cache, |
|
812 | - 'EventEspresso\core\services\route_match\RouteMatchSpecificationFactory' => EE_Dependency_Map::load_from_cache, |
|
813 | - ), |
|
814 | - 'EventEspresso\core\libraries\rest_api\CalculatedModelFields' => array( |
|
815 | - 'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => EE_Dependency_Map::load_from_cache |
|
816 | - ), |
|
817 | - 'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => array( |
|
818 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
819 | - ), |
|
820 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read' => array( |
|
821 | - 'EventEspresso\core\libraries\rest_api\CalculatedModelFields' => EE_Dependency_Map::load_from_cache |
|
822 | - ), |
|
823 | - 'EventEspresso\core\libraries\rest_api\calculations\Datetime' => array( |
|
824 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
825 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
826 | - ), |
|
827 | - 'EventEspresso\core\libraries\rest_api\calculations\Event' => array( |
|
828 | - 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
829 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
830 | - ), |
|
831 | - 'EventEspresso\core\libraries\rest_api\calculations\Registration' => array( |
|
832 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
833 | - ), |
|
834 | - 'EventEspresso\core\services\session\SessionStartHandler' => array( |
|
835 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
836 | - ), |
|
837 | - 'EE_URL_Validation_Strategy' => array( |
|
838 | - null, |
|
839 | - null, |
|
840 | - 'EventEspresso\core\services\validators\URLValidator' => EE_Dependency_Map::load_from_cache |
|
841 | - ), |
|
842 | - 'EventEspresso\admin_pages\general_settings\OrganizationSettings' => array( |
|
843 | - 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
844 | - 'EE_Organization_Config' => EE_Dependency_Map::load_from_cache, |
|
845 | - 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
846 | - 'EE_Network_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
847 | - 'EventEspresso\core\services\address\CountrySubRegionDao' => EE_Dependency_Map::load_from_cache, |
|
848 | - ), |
|
849 | - 'EventEspresso\core\services\address\CountrySubRegionDao' => array( |
|
850 | - 'EEM_State' => EE_Dependency_Map::load_from_cache, |
|
851 | - 'EventEspresso\core\services\validators\JsonValidator' => EE_Dependency_Map::load_from_cache |
|
852 | - ), |
|
853 | - 'EventEspresso\core\domain\services\admin\ajax\WordpressHeartbeat' => array( |
|
854 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
855 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
856 | - ), |
|
857 | - 'EventEspresso\core\domain\services\admin\ajax\EventEditorHeartbeat' => array( |
|
858 | - 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
859 | - 'EE_Environment_Config' => EE_Dependency_Map::load_from_cache, |
|
860 | - ), |
|
861 | - 'EventEspresso\core\services\request\files\FilesDataHandler' => array( |
|
862 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
863 | - ), |
|
864 | - 'EventEspressoBatchRequest\BatchRequestProcessor' => [ |
|
865 | - 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
866 | - ], |
|
867 | - 'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder' => [ |
|
868 | - null, |
|
869 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
870 | - 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
871 | - ], |
|
872 | - 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\AttendeeFilterHeader' => [ |
|
873 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
874 | - 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
875 | - ], |
|
876 | - 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\DateFilterHeader' => [ |
|
877 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
878 | - 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
879 | - ], |
|
880 | - 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\EventFilterHeader' => [ |
|
881 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
882 | - 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
883 | - ], |
|
884 | - 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\TicketFilterHeader' => [ |
|
885 | - 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
886 | - 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
887 | - ], |
|
888 | - ); |
|
889 | - } |
|
890 | - |
|
891 | - |
|
892 | - /** |
|
893 | - * Registers how core classes are loaded. |
|
894 | - * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
895 | - * 'EE_Request_Handler' => 'load_core' |
|
896 | - * 'EE_Messages_Queue' => 'load_lib' |
|
897 | - * 'EEH_Debug_Tools' => 'load_helper' |
|
898 | - * or, if greater control is required, by providing a custom closure. For example: |
|
899 | - * 'Some_Class' => function () { |
|
900 | - * return new Some_Class(); |
|
901 | - * }, |
|
902 | - * This is required for instantiating dependencies |
|
903 | - * where an interface has been type hinted in a class constructor. For example: |
|
904 | - * 'Required_Interface' => function () { |
|
905 | - * return new A_Class_That_Implements_Required_Interface(); |
|
906 | - * }, |
|
907 | - */ |
|
908 | - protected function _register_core_class_loaders() |
|
909 | - { |
|
910 | - $this->_class_loaders = array( |
|
911 | - // load_core |
|
912 | - 'EE_Dependency_Map' => function () { |
|
913 | - return $this; |
|
914 | - }, |
|
915 | - 'EE_Capabilities' => 'load_core', |
|
916 | - 'EE_Encryption' => 'load_core', |
|
917 | - 'EE_Front_Controller' => 'load_core', |
|
918 | - 'EE_Module_Request_Router' => 'load_core', |
|
919 | - 'EE_Registry' => 'load_core', |
|
920 | - 'EE_Request' => function () { |
|
921 | - return $this->legacy_request; |
|
922 | - }, |
|
923 | - 'EventEspresso\core\services\request\Request' => function () { |
|
924 | - return $this->request; |
|
925 | - }, |
|
926 | - 'EventEspresso\core\services\request\Response' => function () { |
|
927 | - return $this->response; |
|
928 | - }, |
|
929 | - 'EE_Base' => 'load_core', |
|
930 | - 'EE_Request_Handler' => 'load_core', |
|
931 | - 'EE_Session' => 'load_core', |
|
932 | - 'EE_Cron_Tasks' => 'load_core', |
|
933 | - 'EE_System' => 'load_core', |
|
934 | - 'EE_Maintenance_Mode' => 'load_core', |
|
935 | - 'EE_Register_CPTs' => 'load_core', |
|
936 | - 'EE_Admin' => 'load_core', |
|
937 | - 'EE_CPT_Strategy' => 'load_core', |
|
938 | - // load_class |
|
939 | - 'EE_Registration_Processor' => 'load_class', |
|
940 | - // load_lib |
|
941 | - 'EE_Message_Resource_Manager' => 'load_lib', |
|
942 | - 'EE_Message_Type_Collection' => 'load_lib', |
|
943 | - 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
944 | - 'EE_Messenger_Collection' => 'load_lib', |
|
945 | - 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
946 | - 'EE_Messages_Processor' => 'load_lib', |
|
947 | - 'EE_Message_Repository' => 'load_lib', |
|
948 | - 'EE_Messages_Queue' => 'load_lib', |
|
949 | - 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
950 | - 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
951 | - 'EE_Payment_Method_Manager' => 'load_lib', |
|
952 | - 'EE_DMS_Core_4_1_0' => 'load_dms', |
|
953 | - 'EE_DMS_Core_4_2_0' => 'load_dms', |
|
954 | - 'EE_DMS_Core_4_3_0' => 'load_dms', |
|
955 | - 'EE_DMS_Core_4_5_0' => 'load_dms', |
|
956 | - 'EE_DMS_Core_4_6_0' => 'load_dms', |
|
957 | - 'EE_DMS_Core_4_7_0' => 'load_dms', |
|
958 | - 'EE_DMS_Core_4_8_0' => 'load_dms', |
|
959 | - 'EE_DMS_Core_4_9_0' => 'load_dms', |
|
960 | - 'EE_DMS_Core_4_10_0' => 'load_dms', |
|
961 | - 'EE_Messages_Generator' => function () { |
|
962 | - return EE_Registry::instance()->load_lib( |
|
963 | - 'Messages_Generator', |
|
964 | - array(), |
|
965 | - false, |
|
966 | - false |
|
967 | - ); |
|
968 | - }, |
|
969 | - 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
970 | - return EE_Registry::instance()->load_lib( |
|
971 | - 'Messages_Template_Defaults', |
|
972 | - $arguments, |
|
973 | - false, |
|
974 | - false |
|
975 | - ); |
|
976 | - }, |
|
977 | - // load_helper |
|
978 | - 'EEH_Parse_Shortcodes' => function () { |
|
979 | - if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
980 | - return new EEH_Parse_Shortcodes(); |
|
981 | - } |
|
982 | - return null; |
|
983 | - }, |
|
984 | - 'EE_Template_Config' => function () { |
|
985 | - return EE_Config::instance()->template_settings; |
|
986 | - }, |
|
987 | - 'EE_Currency_Config' => function () { |
|
988 | - return EE_Config::instance()->currency; |
|
989 | - }, |
|
990 | - 'EE_Registration_Config' => function () { |
|
991 | - return EE_Config::instance()->registration; |
|
992 | - }, |
|
993 | - 'EE_Core_Config' => function () { |
|
994 | - return EE_Config::instance()->core; |
|
995 | - }, |
|
996 | - 'EventEspresso\core\services\loaders\Loader' => function () { |
|
997 | - return LoaderFactory::getLoader(); |
|
998 | - }, |
|
999 | - 'EE_Network_Config' => function () { |
|
1000 | - return EE_Network_Config::instance(); |
|
1001 | - }, |
|
1002 | - 'EE_Config' => function () { |
|
1003 | - return EE_Config::instance(); |
|
1004 | - }, |
|
1005 | - 'EventEspresso\core\domain\Domain' => function () { |
|
1006 | - return DomainFactory::getEventEspressoCoreDomain(); |
|
1007 | - }, |
|
1008 | - 'EE_Admin_Config' => function () { |
|
1009 | - return EE_Config::instance()->admin; |
|
1010 | - }, |
|
1011 | - 'EE_Organization_Config' => function () { |
|
1012 | - return EE_Config::instance()->organization; |
|
1013 | - }, |
|
1014 | - 'EE_Network_Core_Config' => function () { |
|
1015 | - return EE_Network_Config::instance()->core; |
|
1016 | - }, |
|
1017 | - 'EE_Environment_Config' => function () { |
|
1018 | - return EE_Config::instance()->environment; |
|
1019 | - }, |
|
1020 | - ); |
|
1021 | - } |
|
1022 | - |
|
1023 | - |
|
1024 | - /** |
|
1025 | - * can be used for supplying alternate names for classes, |
|
1026 | - * or for connecting interface names to instantiable classes |
|
1027 | - */ |
|
1028 | - protected function _register_core_aliases() |
|
1029 | - { |
|
1030 | - $aliases = array( |
|
1031 | - 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
1032 | - 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
1033 | - 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
1034 | - 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
1035 | - 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
1036 | - 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
1037 | - 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
1038 | - 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
1039 | - 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
1040 | - 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
1041 | - 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
1042 | - 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
1043 | - 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
1044 | - 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
1045 | - 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
1046 | - 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
1047 | - 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
1048 | - 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
1049 | - 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
1050 | - 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
1051 | - 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
1052 | - 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
1053 | - 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
1054 | - 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
1055 | - 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
1056 | - 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
1057 | - 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
1058 | - 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
1059 | - 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
1060 | - 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
1061 | - 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
1062 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
1063 | - 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
1064 | - 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
1065 | - 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
1066 | - 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
1067 | - 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
|
1068 | - 'Registration_Processor' => 'EE_Registration_Processor', |
|
1069 | - ); |
|
1070 | - foreach ($aliases as $alias => $fqn) { |
|
1071 | - if (is_array($fqn)) { |
|
1072 | - foreach ($fqn as $class => $for_class) { |
|
1073 | - $this->class_cache->addAlias($class, $alias, $for_class); |
|
1074 | - } |
|
1075 | - continue; |
|
1076 | - } |
|
1077 | - $this->class_cache->addAlias($fqn, $alias); |
|
1078 | - } |
|
1079 | - if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
1080 | - $this->class_cache->addAlias( |
|
1081 | - 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
|
1082 | - 'EventEspresso\core\services\notices\NoticeConverterInterface' |
|
1083 | - ); |
|
1084 | - } |
|
1085 | - } |
|
1086 | - |
|
1087 | - |
|
1088 | - /** |
|
1089 | - * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
1090 | - * request Primarily used by unit tests. |
|
1091 | - */ |
|
1092 | - public function reset() |
|
1093 | - { |
|
1094 | - $this->_register_core_class_loaders(); |
|
1095 | - $this->_register_core_dependencies(); |
|
1096 | - } |
|
1097 | - |
|
1098 | - |
|
1099 | - /** |
|
1100 | - * PLZ NOTE: a better name for this method would be is_alias() |
|
1101 | - * because it returns TRUE if the provided fully qualified name IS an alias |
|
1102 | - * WHY? |
|
1103 | - * Because if a class is type hinting for a concretion, |
|
1104 | - * then why would we need to find another class to supply it? |
|
1105 | - * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
1106 | - * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
1107 | - * Don't go looking for some substitute. |
|
1108 | - * Whereas if a class is type hinting for an interface... |
|
1109 | - * then we need to find an actual class to use. |
|
1110 | - * So the interface IS the alias for some other FQN, |
|
1111 | - * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
1112 | - * represents some other class. |
|
1113 | - * |
|
1114 | - * @deprecated 4.9.62.p |
|
1115 | - * @param string $fqn |
|
1116 | - * @param string $for_class |
|
1117 | - * @return bool |
|
1118 | - */ |
|
1119 | - public function has_alias($fqn = '', $for_class = '') |
|
1120 | - { |
|
1121 | - return $this->isAlias($fqn, $for_class); |
|
1122 | - } |
|
1123 | - |
|
1124 | - |
|
1125 | - /** |
|
1126 | - * PLZ NOTE: a better name for this method would be get_fqn_for_alias() |
|
1127 | - * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
1128 | - * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
1129 | - * for example: |
|
1130 | - * if the following two entries were added to the _aliases array: |
|
1131 | - * array( |
|
1132 | - * 'interface_alias' => 'some\namespace\interface' |
|
1133 | - * 'some\namespace\interface' => 'some\namespace\classname' |
|
1134 | - * ) |
|
1135 | - * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
1136 | - * to load an instance of 'some\namespace\classname' |
|
1137 | - * |
|
1138 | - * @deprecated 4.9.62.p |
|
1139 | - * @param string $alias |
|
1140 | - * @param string $for_class |
|
1141 | - * @return string |
|
1142 | - */ |
|
1143 | - public function get_alias($alias = '', $for_class = '') |
|
1144 | - { |
|
1145 | - return $this->getFqnForAlias($alias, $for_class); |
|
1146 | - } |
|
23 | + /** |
|
24 | + * This means that the requested class dependency is not present in the dependency map |
|
25 | + */ |
|
26 | + const not_registered = 0; |
|
27 | + |
|
28 | + /** |
|
29 | + * This instructs class loaders to ALWAYS return a newly instantiated object for the requested class. |
|
30 | + */ |
|
31 | + const load_new_object = 1; |
|
32 | + |
|
33 | + /** |
|
34 | + * This instructs class loaders to return a previously instantiated and cached object for the requested class. |
|
35 | + * IF a previously instantiated object does not exist, a new one will be created and added to the cache. |
|
36 | + */ |
|
37 | + const load_from_cache = 2; |
|
38 | + |
|
39 | + /** |
|
40 | + * When registering a dependency, |
|
41 | + * this indicates to keep any existing dependencies that already exist, |
|
42 | + * and simply discard any new dependencies declared in the incoming data |
|
43 | + */ |
|
44 | + const KEEP_EXISTING_DEPENDENCIES = 0; |
|
45 | + |
|
46 | + /** |
|
47 | + * When registering a dependency, |
|
48 | + * this indicates to overwrite any existing dependencies that already exist using the incoming data |
|
49 | + */ |
|
50 | + const OVERWRITE_DEPENDENCIES = 1; |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * @type EE_Dependency_Map $_instance |
|
55 | + */ |
|
56 | + protected static $_instance; |
|
57 | + |
|
58 | + /** |
|
59 | + * @var ClassInterfaceCache $class_cache |
|
60 | + */ |
|
61 | + private $class_cache; |
|
62 | + |
|
63 | + /** |
|
64 | + * @type RequestInterface $request |
|
65 | + */ |
|
66 | + protected $request; |
|
67 | + |
|
68 | + /** |
|
69 | + * @type LegacyRequestInterface $legacy_request |
|
70 | + */ |
|
71 | + protected $legacy_request; |
|
72 | + |
|
73 | + /** |
|
74 | + * @type ResponseInterface $response |
|
75 | + */ |
|
76 | + protected $response; |
|
77 | + |
|
78 | + /** |
|
79 | + * @type LoaderInterface $loader |
|
80 | + */ |
|
81 | + protected $loader; |
|
82 | + |
|
83 | + /** |
|
84 | + * @type array $_dependency_map |
|
85 | + */ |
|
86 | + protected $_dependency_map = array(); |
|
87 | + |
|
88 | + /** |
|
89 | + * @type array $_class_loaders |
|
90 | + */ |
|
91 | + protected $_class_loaders = array(); |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * EE_Dependency_Map constructor. |
|
96 | + * |
|
97 | + * @param ClassInterfaceCache $class_cache |
|
98 | + */ |
|
99 | + protected function __construct(ClassInterfaceCache $class_cache) |
|
100 | + { |
|
101 | + $this->class_cache = $class_cache; |
|
102 | + do_action('EE_Dependency_Map____construct', $this); |
|
103 | + } |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * @return void |
|
108 | + */ |
|
109 | + public function initialize() |
|
110 | + { |
|
111 | + $this->_register_core_dependencies(); |
|
112 | + $this->_register_core_class_loaders(); |
|
113 | + $this->_register_core_aliases(); |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * @singleton method used to instantiate class object |
|
119 | + * @param ClassInterfaceCache|null $class_cache |
|
120 | + * @return EE_Dependency_Map |
|
121 | + */ |
|
122 | + public static function instance(ClassInterfaceCache $class_cache = null) |
|
123 | + { |
|
124 | + // check if class object is instantiated, and instantiated properly |
|
125 | + if (! self::$_instance instanceof EE_Dependency_Map |
|
126 | + && $class_cache instanceof ClassInterfaceCache |
|
127 | + ) { |
|
128 | + self::$_instance = new EE_Dependency_Map($class_cache); |
|
129 | + } |
|
130 | + return self::$_instance; |
|
131 | + } |
|
132 | + |
|
133 | + |
|
134 | + /** |
|
135 | + * @param RequestInterface $request |
|
136 | + */ |
|
137 | + public function setRequest(RequestInterface $request) |
|
138 | + { |
|
139 | + $this->request = $request; |
|
140 | + } |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * @param LegacyRequestInterface $legacy_request |
|
145 | + */ |
|
146 | + public function setLegacyRequest(LegacyRequestInterface $legacy_request) |
|
147 | + { |
|
148 | + $this->legacy_request = $legacy_request; |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * @param ResponseInterface $response |
|
154 | + */ |
|
155 | + public function setResponse(ResponseInterface $response) |
|
156 | + { |
|
157 | + $this->response = $response; |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * @param LoaderInterface $loader |
|
163 | + */ |
|
164 | + public function setLoader(LoaderInterface $loader) |
|
165 | + { |
|
166 | + $this->loader = $loader; |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * @param string $class |
|
172 | + * @param array $dependencies |
|
173 | + * @param int $overwrite |
|
174 | + * @return bool |
|
175 | + */ |
|
176 | + public static function register_dependencies( |
|
177 | + $class, |
|
178 | + array $dependencies, |
|
179 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
180 | + ) { |
|
181 | + return self::$_instance->registerDependencies($class, $dependencies, $overwrite); |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * Assigns an array of class names and corresponding load sources (new or cached) |
|
187 | + * to the class specified by the first parameter. |
|
188 | + * IMPORTANT !!! |
|
189 | + * The order of elements in the incoming $dependencies array MUST match |
|
190 | + * the order of the constructor parameters for the class in question. |
|
191 | + * This is especially important when overriding any existing dependencies that are registered. |
|
192 | + * the third parameter controls whether any duplicate dependencies are overwritten or not. |
|
193 | + * |
|
194 | + * @param string $class |
|
195 | + * @param array $dependencies |
|
196 | + * @param int $overwrite |
|
197 | + * @return bool |
|
198 | + */ |
|
199 | + public function registerDependencies( |
|
200 | + $class, |
|
201 | + array $dependencies, |
|
202 | + $overwrite = EE_Dependency_Map::KEEP_EXISTING_DEPENDENCIES |
|
203 | + ) { |
|
204 | + $class = trim($class, '\\'); |
|
205 | + $registered = false; |
|
206 | + if (empty(self::$_instance->_dependency_map[ $class ])) { |
|
207 | + self::$_instance->_dependency_map[ $class ] = array(); |
|
208 | + } |
|
209 | + // we need to make sure that any aliases used when registering a dependency |
|
210 | + // get resolved to the correct class name |
|
211 | + foreach ($dependencies as $dependency => $load_source) { |
|
212 | + $alias = self::$_instance->getFqnForAlias($dependency); |
|
213 | + if ($overwrite === EE_Dependency_Map::OVERWRITE_DEPENDENCIES |
|
214 | + || ! isset(self::$_instance->_dependency_map[ $class ][ $alias ]) |
|
215 | + ) { |
|
216 | + unset($dependencies[ $dependency ]); |
|
217 | + $dependencies[ $alias ] = $load_source; |
|
218 | + $registered = true; |
|
219 | + } |
|
220 | + } |
|
221 | + // now add our two lists of dependencies together. |
|
222 | + // using Union (+=) favours the arrays in precedence from left to right, |
|
223 | + // so $dependencies is NOT overwritten because it is listed first |
|
224 | + // ie: with A = B + C, entries in B take precedence over duplicate entries in C |
|
225 | + // Union is way faster than array_merge() but should be used with caution... |
|
226 | + // especially with numerically indexed arrays |
|
227 | + $dependencies += self::$_instance->_dependency_map[ $class ]; |
|
228 | + // now we need to ensure that the resulting dependencies |
|
229 | + // array only has the entries that are required for the class |
|
230 | + // so first count how many dependencies were originally registered for the class |
|
231 | + $dependency_count = count(self::$_instance->_dependency_map[ $class ]); |
|
232 | + // if that count is non-zero (meaning dependencies were already registered) |
|
233 | + self::$_instance->_dependency_map[ $class ] = $dependency_count |
|
234 | + // then truncate the final array to match that count |
|
235 | + ? array_slice($dependencies, 0, $dependency_count) |
|
236 | + // otherwise just take the incoming array because nothing previously existed |
|
237 | + : $dependencies; |
|
238 | + return $registered; |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + /** |
|
243 | + * @param string $class_name |
|
244 | + * @param string $loader |
|
245 | + * @return bool |
|
246 | + * @throws DomainException |
|
247 | + */ |
|
248 | + public static function register_class_loader($class_name, $loader = 'load_core') |
|
249 | + { |
|
250 | + if (! $loader instanceof Closure && strpos($class_name, '\\') !== false) { |
|
251 | + throw new DomainException( |
|
252 | + esc_html__('Don\'t use class loaders for FQCNs.', 'event_espresso') |
|
253 | + ); |
|
254 | + } |
|
255 | + // check that loader is callable or method starts with "load_" and exists in EE_Registry |
|
256 | + if (! is_callable($loader) |
|
257 | + && ( |
|
258 | + strpos($loader, 'load_') !== 0 |
|
259 | + || ! method_exists('EE_Registry', $loader) |
|
260 | + ) |
|
261 | + ) { |
|
262 | + throw new DomainException( |
|
263 | + sprintf( |
|
264 | + esc_html__( |
|
265 | + '"%1$s" is not a valid loader method on EE_Registry.', |
|
266 | + 'event_espresso' |
|
267 | + ), |
|
268 | + $loader |
|
269 | + ) |
|
270 | + ); |
|
271 | + } |
|
272 | + $class_name = self::$_instance->getFqnForAlias($class_name); |
|
273 | + if (! isset(self::$_instance->_class_loaders[ $class_name ])) { |
|
274 | + self::$_instance->_class_loaders[ $class_name ] = $loader; |
|
275 | + return true; |
|
276 | + } |
|
277 | + return false; |
|
278 | + } |
|
279 | + |
|
280 | + |
|
281 | + /** |
|
282 | + * @return array |
|
283 | + */ |
|
284 | + public function dependency_map() |
|
285 | + { |
|
286 | + return $this->_dependency_map; |
|
287 | + } |
|
288 | + |
|
289 | + |
|
290 | + /** |
|
291 | + * returns TRUE if dependency map contains a listing for the provided class name |
|
292 | + * |
|
293 | + * @param string $class_name |
|
294 | + * @return boolean |
|
295 | + */ |
|
296 | + public function has($class_name = '') |
|
297 | + { |
|
298 | + // all legacy models have the same dependencies |
|
299 | + if (strpos($class_name, 'EEM_') === 0) { |
|
300 | + $class_name = 'LEGACY_MODELS'; |
|
301 | + } |
|
302 | + return isset($this->_dependency_map[ $class_name ]) ? true : false; |
|
303 | + } |
|
304 | + |
|
305 | + |
|
306 | + /** |
|
307 | + * returns TRUE if dependency map contains a listing for the provided class name AND dependency |
|
308 | + * |
|
309 | + * @param string $class_name |
|
310 | + * @param string $dependency |
|
311 | + * @return bool |
|
312 | + */ |
|
313 | + public function has_dependency_for_class($class_name = '', $dependency = '') |
|
314 | + { |
|
315 | + // all legacy models have the same dependencies |
|
316 | + if (strpos($class_name, 'EEM_') === 0) { |
|
317 | + $class_name = 'LEGACY_MODELS'; |
|
318 | + } |
|
319 | + $dependency = $this->getFqnForAlias($dependency, $class_name); |
|
320 | + return isset($this->_dependency_map[ $class_name ][ $dependency ]) |
|
321 | + ? true |
|
322 | + : false; |
|
323 | + } |
|
324 | + |
|
325 | + |
|
326 | + /** |
|
327 | + * returns loading strategy for whether a previously cached dependency should be loaded or a new instance returned |
|
328 | + * |
|
329 | + * @param string $class_name |
|
330 | + * @param string $dependency |
|
331 | + * @return int |
|
332 | + */ |
|
333 | + public function loading_strategy_for_class_dependency($class_name = '', $dependency = '') |
|
334 | + { |
|
335 | + // all legacy models have the same dependencies |
|
336 | + if (strpos($class_name, 'EEM_') === 0) { |
|
337 | + $class_name = 'LEGACY_MODELS'; |
|
338 | + } |
|
339 | + $dependency = $this->getFqnForAlias($dependency); |
|
340 | + return $this->has_dependency_for_class($class_name, $dependency) |
|
341 | + ? $this->_dependency_map[ $class_name ][ $dependency ] |
|
342 | + : EE_Dependency_Map::not_registered; |
|
343 | + } |
|
344 | + |
|
345 | + |
|
346 | + /** |
|
347 | + * @param string $class_name |
|
348 | + * @return string | Closure |
|
349 | + */ |
|
350 | + public function class_loader($class_name) |
|
351 | + { |
|
352 | + // all legacy models use load_model() |
|
353 | + if (strpos($class_name, 'EEM_') === 0) { |
|
354 | + return 'load_model'; |
|
355 | + } |
|
356 | + // EE_CPT_*_Strategy classes like EE_CPT_Event_Strategy, EE_CPT_Venue_Strategy, etc |
|
357 | + // perform strpos() first to avoid loading regex every time we load a class |
|
358 | + if (strpos($class_name, 'EE_CPT_') === 0 |
|
359 | + && preg_match('/^EE_CPT_([a-zA-Z]+)_Strategy$/', $class_name) |
|
360 | + ) { |
|
361 | + return 'load_core'; |
|
362 | + } |
|
363 | + $class_name = $this->getFqnForAlias($class_name); |
|
364 | + return isset($this->_class_loaders[ $class_name ]) ? $this->_class_loaders[ $class_name ] : ''; |
|
365 | + } |
|
366 | + |
|
367 | + |
|
368 | + /** |
|
369 | + * @return array |
|
370 | + */ |
|
371 | + public function class_loaders() |
|
372 | + { |
|
373 | + return $this->_class_loaders; |
|
374 | + } |
|
375 | + |
|
376 | + |
|
377 | + /** |
|
378 | + * adds an alias for a classname |
|
379 | + * |
|
380 | + * @param string $fqcn the class name that should be used (concrete class to replace interface) |
|
381 | + * @param string $alias the class name that would be type hinted for (abstract parent or interface) |
|
382 | + * @param string $for_class the class that has the dependency (is type hinting for the interface) |
|
383 | + */ |
|
384 | + public function add_alias($fqcn, $alias, $for_class = '') |
|
385 | + { |
|
386 | + $this->class_cache->addAlias($fqcn, $alias, $for_class); |
|
387 | + } |
|
388 | + |
|
389 | + |
|
390 | + /** |
|
391 | + * Returns TRUE if the provided fully qualified name IS an alias |
|
392 | + * WHY? |
|
393 | + * Because if a class is type hinting for a concretion, |
|
394 | + * then why would we need to find another class to supply it? |
|
395 | + * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
396 | + * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
397 | + * Don't go looking for some substitute. |
|
398 | + * Whereas if a class is type hinting for an interface... |
|
399 | + * then we need to find an actual class to use. |
|
400 | + * So the interface IS the alias for some other FQN, |
|
401 | + * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
402 | + * represents some other class. |
|
403 | + * |
|
404 | + * @param string $fqn |
|
405 | + * @param string $for_class |
|
406 | + * @return bool |
|
407 | + */ |
|
408 | + public function isAlias($fqn = '', $for_class = '') |
|
409 | + { |
|
410 | + return $this->class_cache->isAlias($fqn, $for_class); |
|
411 | + } |
|
412 | + |
|
413 | + |
|
414 | + /** |
|
415 | + * Returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
416 | + * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
417 | + * for example: |
|
418 | + * if the following two entries were added to the _aliases array: |
|
419 | + * array( |
|
420 | + * 'interface_alias' => 'some\namespace\interface' |
|
421 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
422 | + * ) |
|
423 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
424 | + * to load an instance of 'some\namespace\classname' |
|
425 | + * |
|
426 | + * @param string $alias |
|
427 | + * @param string $for_class |
|
428 | + * @return string |
|
429 | + */ |
|
430 | + public function getFqnForAlias($alias = '', $for_class = '') |
|
431 | + { |
|
432 | + return (string) $this->class_cache->getFqnForAlias($alias, $for_class); |
|
433 | + } |
|
434 | + |
|
435 | + |
|
436 | + /** |
|
437 | + * Registers the core dependencies and whether a previously instantiated object should be loaded from the cache, |
|
438 | + * if one exists, or whether a new object should be generated every time the requested class is loaded. |
|
439 | + * This is done by using the following class constants: |
|
440 | + * EE_Dependency_Map::load_from_cache - loads previously instantiated object |
|
441 | + * EE_Dependency_Map::load_new_object - generates a new object every time |
|
442 | + */ |
|
443 | + protected function _register_core_dependencies() |
|
444 | + { |
|
445 | + $this->_dependency_map = array( |
|
446 | + 'EE_Request_Handler' => array( |
|
447 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
448 | + ), |
|
449 | + 'EE_System' => array( |
|
450 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
451 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
452 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
453 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
454 | + ), |
|
455 | + 'EE_Session' => array( |
|
456 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
457 | + 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
458 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
459 | + 'EventEspresso\core\services\session\SessionStartHandler' => EE_Dependency_Map::load_from_cache, |
|
460 | + 'EE_Encryption' => EE_Dependency_Map::load_from_cache, |
|
461 | + ), |
|
462 | + 'EE_Cart' => array( |
|
463 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
464 | + ), |
|
465 | + 'EE_Front_Controller' => array( |
|
466 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
467 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
468 | + 'EE_Module_Request_Router' => EE_Dependency_Map::load_from_cache, |
|
469 | + ), |
|
470 | + 'EE_Messenger_Collection_Loader' => array( |
|
471 | + 'EE_Messenger_Collection' => EE_Dependency_Map::load_new_object, |
|
472 | + ), |
|
473 | + 'EE_Message_Type_Collection_Loader' => array( |
|
474 | + 'EE_Message_Type_Collection' => EE_Dependency_Map::load_new_object, |
|
475 | + ), |
|
476 | + 'EE_Message_Resource_Manager' => array( |
|
477 | + 'EE_Messenger_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
478 | + 'EE_Message_Type_Collection_Loader' => EE_Dependency_Map::load_new_object, |
|
479 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
480 | + ), |
|
481 | + 'EE_Message_Factory' => array( |
|
482 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
483 | + ), |
|
484 | + 'EE_messages' => array( |
|
485 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
486 | + ), |
|
487 | + 'EE_Messages_Generator' => array( |
|
488 | + 'EE_Messages_Queue' => EE_Dependency_Map::load_new_object, |
|
489 | + 'EE_Messages_Data_Handler_Collection' => EE_Dependency_Map::load_new_object, |
|
490 | + 'EE_Message_Template_Group_Collection' => EE_Dependency_Map::load_new_object, |
|
491 | + 'EEH_Parse_Shortcodes' => EE_Dependency_Map::load_from_cache, |
|
492 | + ), |
|
493 | + 'EE_Messages_Processor' => array( |
|
494 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
495 | + ), |
|
496 | + 'EE_Messages_Queue' => array( |
|
497 | + 'EE_Message_Repository' => EE_Dependency_Map::load_new_object, |
|
498 | + ), |
|
499 | + 'EE_Messages_Template_Defaults' => array( |
|
500 | + 'EEM_Message_Template_Group' => EE_Dependency_Map::load_from_cache, |
|
501 | + 'EEM_Message_Template' => EE_Dependency_Map::load_from_cache, |
|
502 | + ), |
|
503 | + 'EE_Message_To_Generate_From_Request' => array( |
|
504 | + 'EE_Message_Resource_Manager' => EE_Dependency_Map::load_from_cache, |
|
505 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
506 | + ), |
|
507 | + 'EventEspresso\core\services\commands\CommandBus' => array( |
|
508 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => EE_Dependency_Map::load_from_cache, |
|
509 | + ), |
|
510 | + 'EventEspresso\services\commands\CommandHandler' => array( |
|
511 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
512 | + 'CommandBusInterface' => EE_Dependency_Map::load_from_cache, |
|
513 | + ), |
|
514 | + 'EventEspresso\core\services\commands\CommandHandlerManager' => array( |
|
515 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
516 | + ), |
|
517 | + 'EventEspresso\core\services\commands\CompositeCommandHandler' => array( |
|
518 | + 'EventEspresso\core\services\commands\CommandBus' => EE_Dependency_Map::load_from_cache, |
|
519 | + 'EventEspresso\core\services\commands\CommandFactory' => EE_Dependency_Map::load_from_cache, |
|
520 | + ), |
|
521 | + 'EventEspresso\core\services\commands\CommandFactory' => array( |
|
522 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
523 | + ), |
|
524 | + 'EventEspresso\core\services\commands\middleware\CapChecker' => array( |
|
525 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
526 | + ), |
|
527 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => array( |
|
528 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
529 | + ), |
|
530 | + 'EventEspresso\core\domain\services\capabilities\RegistrationsCapChecker' => array( |
|
531 | + 'EE_Capabilities' => EE_Dependency_Map::load_from_cache, |
|
532 | + ), |
|
533 | + 'EventEspresso\core\services\commands\registration\CreateRegistrationCommandHandler' => array( |
|
534 | + 'EventEspresso\core\domain\services\registration\CreateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
535 | + ), |
|
536 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommandHandler' => array( |
|
537 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
538 | + ), |
|
539 | + 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommandHandler' => array( |
|
540 | + 'EventEspresso\core\domain\services\registration\CopyRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
541 | + ), |
|
542 | + 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler' => array( |
|
543 | + 'EventEspresso\core\domain\services\registration\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
544 | + ), |
|
545 | + 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler' => array( |
|
546 | + 'EventEspresso\core\domain\services\registration\UpdateRegistrationService' => EE_Dependency_Map::load_from_cache, |
|
547 | + ), |
|
548 | + 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommandHandler' => array( |
|
549 | + 'EventEspresso\core\domain\services\ticket\CreateTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
550 | + ), |
|
551 | + 'EventEspresso\core\services\commands\ticket\CancelTicketLineItemCommandHandler' => array( |
|
552 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
553 | + ), |
|
554 | + 'EventEspresso\core\domain\services\registration\CancelRegistrationService' => array( |
|
555 | + 'EventEspresso\core\domain\services\ticket\CancelTicketLineItemService' => EE_Dependency_Map::load_from_cache, |
|
556 | + ), |
|
557 | + 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler' => array( |
|
558 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
559 | + ), |
|
560 | + 'EventEspresso\core\services\database\TableManager' => array( |
|
561 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
562 | + ), |
|
563 | + 'EE_Data_Migration_Class_Base' => array( |
|
564 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
565 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
566 | + ), |
|
567 | + 'EE_DMS_Core_4_1_0' => array( |
|
568 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
569 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
570 | + ), |
|
571 | + 'EE_DMS_Core_4_2_0' => array( |
|
572 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
573 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
574 | + ), |
|
575 | + 'EE_DMS_Core_4_3_0' => array( |
|
576 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
577 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
578 | + ), |
|
579 | + 'EE_DMS_Core_4_4_0' => array( |
|
580 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
581 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
582 | + ), |
|
583 | + 'EE_DMS_Core_4_5_0' => array( |
|
584 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
585 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
586 | + ), |
|
587 | + 'EE_DMS_Core_4_6_0' => array( |
|
588 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
589 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
590 | + ), |
|
591 | + 'EE_DMS_Core_4_7_0' => array( |
|
592 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
593 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
594 | + ), |
|
595 | + 'EE_DMS_Core_4_8_0' => array( |
|
596 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
597 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
598 | + ), |
|
599 | + 'EE_DMS_Core_4_9_0' => array( |
|
600 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
601 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
602 | + ), |
|
603 | + 'EE_DMS_Core_4_10_0' => array( |
|
604 | + 'EventEspresso\core\services\database\TableAnalysis' => EE_Dependency_Map::load_from_cache, |
|
605 | + 'EventEspresso\core\services\database\TableManager' => EE_Dependency_Map::load_from_cache, |
|
606 | + 'EE_DMS_Core_4_9_0' => EE_Dependency_Map::load_from_cache, |
|
607 | + ), |
|
608 | + 'EventEspresso\core\services\assets\I18nRegistry' => array( |
|
609 | + array(), |
|
610 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
611 | + ), |
|
612 | + 'EventEspresso\core\services\assets\Registry' => array( |
|
613 | + 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
614 | + 'EventEspresso\core\services\assets\I18nRegistry' => EE_Dependency_Map::load_from_cache, |
|
615 | + ), |
|
616 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCancelled' => array( |
|
617 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
618 | + ), |
|
619 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoCheckout' => array( |
|
620 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
621 | + ), |
|
622 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEventAttendees' => array( |
|
623 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
624 | + ), |
|
625 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoEvents' => array( |
|
626 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
627 | + ), |
|
628 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoThankYou' => array( |
|
629 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
630 | + ), |
|
631 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTicketSelector' => array( |
|
632 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
633 | + ), |
|
634 | + 'EventEspresso\core\domain\entities\shortcodes\EspressoTxnPage' => array( |
|
635 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => EE_Dependency_Map::load_from_cache, |
|
636 | + ), |
|
637 | + 'EventEspresso\core\services\cache\BasicCacheManager' => array( |
|
638 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
639 | + ), |
|
640 | + 'EventEspresso\core\services\cache\PostRelatedCacheManager' => array( |
|
641 | + 'EventEspresso\core\services\cache\TransientCacheStorage' => EE_Dependency_Map::load_from_cache, |
|
642 | + ), |
|
643 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => array( |
|
644 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
645 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
646 | + ), |
|
647 | + 'EventEspresso\core\domain\values\EmailAddress' => array( |
|
648 | + null, |
|
649 | + 'EventEspresso\core\domain\services\validation\email\EmailValidationService' => EE_Dependency_Map::load_from_cache, |
|
650 | + ), |
|
651 | + 'EventEspresso\core\services\orm\ModelFieldFactory' => array( |
|
652 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
653 | + ), |
|
654 | + 'LEGACY_MODELS' => array( |
|
655 | + null, |
|
656 | + 'EventEspresso\core\services\database\ModelFieldFactory' => EE_Dependency_Map::load_from_cache, |
|
657 | + ), |
|
658 | + 'EE_Module_Request_Router' => array( |
|
659 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
660 | + ), |
|
661 | + 'EE_Registration_Processor' => array( |
|
662 | + 'EE_Request' => EE_Dependency_Map::load_from_cache, |
|
663 | + ), |
|
664 | + 'EventEspresso\core\services\notifications\PersistentAdminNoticeManager' => array( |
|
665 | + null, |
|
666 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker' => EE_Dependency_Map::load_from_cache, |
|
667 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
668 | + ), |
|
669 | + 'EventEspresso\core\services\licensing\LicenseService' => array( |
|
670 | + 'EventEspresso\core\domain\services\pue\Stats' => EE_Dependency_Map::load_from_cache, |
|
671 | + 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
672 | + ), |
|
673 | + 'EE_Admin_Transactions_List_Table' => array( |
|
674 | + null, |
|
675 | + 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache, |
|
676 | + ), |
|
677 | + 'EventEspresso\core\domain\services\pue\Stats' => array( |
|
678 | + 'EventEspresso\core\domain\services\pue\Config' => EE_Dependency_Map::load_from_cache, |
|
679 | + 'EE_Maintenance_Mode' => EE_Dependency_Map::load_from_cache, |
|
680 | + 'EventEspresso\core\domain\services\pue\StatsGatherer' => EE_Dependency_Map::load_from_cache, |
|
681 | + ), |
|
682 | + 'EventEspresso\core\domain\services\pue\Config' => array( |
|
683 | + 'EE_Network_Config' => EE_Dependency_Map::load_from_cache, |
|
684 | + 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
685 | + ), |
|
686 | + 'EventEspresso\core\domain\services\pue\StatsGatherer' => array( |
|
687 | + 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
688 | + 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
689 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
690 | + 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
691 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
692 | + 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
693 | + 'EE_Config' => EE_Dependency_Map::load_from_cache, |
|
694 | + ), |
|
695 | + 'EventEspresso\core\domain\services\admin\ExitModal' => array( |
|
696 | + 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
697 | + ), |
|
698 | + 'EventEspresso\core\domain\services\admin\PluginUpsells' => array( |
|
699 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
700 | + ), |
|
701 | + 'EventEspresso\caffeinated\modules\recaptcha_invisible\InvisibleRecaptcha' => array( |
|
702 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
703 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
704 | + ), |
|
705 | + 'EventEspresso\caffeinated\modules\recaptcha_invisible\RecaptchaAdminSettings' => array( |
|
706 | + 'EE_Registration_Config' => EE_Dependency_Map::load_from_cache, |
|
707 | + ), |
|
708 | + 'EventEspresso\modules\ticket_selector\ProcessTicketSelector' => array( |
|
709 | + 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
710 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
711 | + 'EE_Session' => EE_Dependency_Map::load_from_cache, |
|
712 | + 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
713 | + 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => EE_Dependency_Map::load_from_cache, |
|
714 | + ), |
|
715 | + 'EventEspresso\modules\ticket_selector\TicketDatetimeAvailabilityTracker' => array( |
|
716 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
717 | + ), |
|
718 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => array( |
|
719 | + 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
720 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
721 | + ), |
|
722 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomPostTypes' => array( |
|
723 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
724 | + ), |
|
725 | + 'EventEspresso\core\domain\services\custom_post_types\RegisterCustomTaxonomies' => array( |
|
726 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
727 | + ), |
|
728 | + 'EE_CPT_Strategy' => array( |
|
729 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomPostTypeDefinitions' => EE_Dependency_Map::load_from_cache, |
|
730 | + 'EventEspresso\core\domain\entities\custom_post_types\CustomTaxonomyDefinitions' => EE_Dependency_Map::load_from_cache, |
|
731 | + ), |
|
732 | + 'EventEspresso\core\services\loaders\ObjectIdentifier' => array( |
|
733 | + 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
734 | + ), |
|
735 | + 'EventEspresso\core\domain\services\assets\CoreAssetManager' => array( |
|
736 | + 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
737 | + 'EE_Currency_Config' => EE_Dependency_Map::load_from_cache, |
|
738 | + 'EE_Template_Config' => EE_Dependency_Map::load_from_cache, |
|
739 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
740 | + 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
741 | + ), |
|
742 | + 'EventEspresso\core\domain\services\admin\privacy\policy\PrivacyPolicy' => array( |
|
743 | + 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache, |
|
744 | + 'EventEspresso\core\domain\values\session\SessionLifespan' => EE_Dependency_Map::load_from_cache |
|
745 | + ), |
|
746 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendee' => array( |
|
747 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
748 | + ), |
|
749 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportAttendeeBillingData' => array( |
|
750 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
751 | + 'EEM_Payment_Method' => EE_Dependency_Map::load_from_cache |
|
752 | + ), |
|
753 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportCheckins' => array( |
|
754 | + 'EEM_Checkin' => EE_Dependency_Map::load_from_cache, |
|
755 | + ), |
|
756 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportRegistration' => array( |
|
757 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
758 | + ), |
|
759 | + 'EventEspresso\core\domain\services\admin\privacy\export\ExportTransaction' => array( |
|
760 | + 'EEM_Transaction' => EE_Dependency_Map::load_from_cache, |
|
761 | + ), |
|
762 | + 'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAttendeeData' => array( |
|
763 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
764 | + ), |
|
765 | + 'EventEspresso\core\domain\services\admin\privacy\erasure\EraseAnswers' => array( |
|
766 | + 'EEM_Answer' => EE_Dependency_Map::load_from_cache, |
|
767 | + 'EEM_Question' => EE_Dependency_Map::load_from_cache, |
|
768 | + ), |
|
769 | + 'EventEspresso\core\CPTs\CptQueryModifier' => array( |
|
770 | + null, |
|
771 | + null, |
|
772 | + null, |
|
773 | + 'EE_Request_Handler' => EE_Dependency_Map::load_from_cache, |
|
774 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
775 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
776 | + ), |
|
777 | + 'EventEspresso\core\domain\services\admin\privacy\forms\PrivacySettingsFormHandler' => array( |
|
778 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
779 | + 'EE_Config' => EE_Dependency_Map::load_from_cache |
|
780 | + ), |
|
781 | + 'EventEspresso\core\services\editor\BlockRegistrationManager' => array( |
|
782 | + 'EventEspresso\core\services\assets\BlockAssetManagerCollection' => EE_Dependency_Map::load_from_cache, |
|
783 | + 'EventEspresso\core\domain\entities\editor\BlockCollection' => EE_Dependency_Map::load_from_cache, |
|
784 | + 'EventEspresso\core\services\route_match\RouteMatchSpecificationManager' => EE_Dependency_Map::load_from_cache, |
|
785 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
786 | + ), |
|
787 | + 'EventEspresso\core\domain\entities\editor\CoreBlocksAssetManager' => array( |
|
788 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
789 | + 'EventEspresso\core\services\assets\AssetCollection' => EE_Dependency_Map::load_from_cache, |
|
790 | + 'EventEspresso\core\services\assets\Registry' => EE_Dependency_Map::load_from_cache, |
|
791 | + ), |
|
792 | + 'EventEspresso\core\domain\services\blocks\EventAttendeesBlockRenderer' => array( |
|
793 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
794 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
795 | + ), |
|
796 | + 'EventEspresso\core\domain\entities\editor\blocks\EventAttendees' => array( |
|
797 | + 'EventEspresso\core\domain\entities\editor\CoreBlocksAssetManager' => self::load_from_cache, |
|
798 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
799 | + 'EventEspresso\core\domain\services\blocks\EventAttendeesBlockRenderer' => self::load_from_cache, |
|
800 | + ), |
|
801 | + 'EventEspresso\core\services\route_match\RouteMatchSpecificationDependencyResolver' => array( |
|
802 | + 'EventEspresso\core\services\container\Mirror' => EE_Dependency_Map::load_from_cache, |
|
803 | + 'EventEspresso\core\services\loaders\ClassInterfaceCache' => EE_Dependency_Map::load_from_cache, |
|
804 | + 'EE_Dependency_Map' => EE_Dependency_Map::load_from_cache, |
|
805 | + ), |
|
806 | + 'EventEspresso\core\services\route_match\RouteMatchSpecificationFactory' => array( |
|
807 | + 'EventEspresso\core\services\route_match\RouteMatchSpecificationDependencyResolver' => EE_Dependency_Map::load_from_cache, |
|
808 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
809 | + ), |
|
810 | + 'EventEspresso\core\services\route_match\RouteMatchSpecificationManager' => array( |
|
811 | + 'EventEspresso\core\services\route_match\RouteMatchSpecificationCollection' => EE_Dependency_Map::load_from_cache, |
|
812 | + 'EventEspresso\core\services\route_match\RouteMatchSpecificationFactory' => EE_Dependency_Map::load_from_cache, |
|
813 | + ), |
|
814 | + 'EventEspresso\core\libraries\rest_api\CalculatedModelFields' => array( |
|
815 | + 'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => EE_Dependency_Map::load_from_cache |
|
816 | + ), |
|
817 | + 'EventEspresso\core\libraries\rest_api\calculations\CalculatedModelFieldsFactory' => array( |
|
818 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
819 | + ), |
|
820 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read' => array( |
|
821 | + 'EventEspresso\core\libraries\rest_api\CalculatedModelFields' => EE_Dependency_Map::load_from_cache |
|
822 | + ), |
|
823 | + 'EventEspresso\core\libraries\rest_api\calculations\Datetime' => array( |
|
824 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
825 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
826 | + ), |
|
827 | + 'EventEspresso\core\libraries\rest_api\calculations\Event' => array( |
|
828 | + 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
829 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
830 | + ), |
|
831 | + 'EventEspresso\core\libraries\rest_api\calculations\Registration' => array( |
|
832 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache |
|
833 | + ), |
|
834 | + 'EventEspresso\core\services\session\SessionStartHandler' => array( |
|
835 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
836 | + ), |
|
837 | + 'EE_URL_Validation_Strategy' => array( |
|
838 | + null, |
|
839 | + null, |
|
840 | + 'EventEspresso\core\services\validators\URLValidator' => EE_Dependency_Map::load_from_cache |
|
841 | + ), |
|
842 | + 'EventEspresso\admin_pages\general_settings\OrganizationSettings' => array( |
|
843 | + 'EE_Registry' => EE_Dependency_Map::load_from_cache, |
|
844 | + 'EE_Organization_Config' => EE_Dependency_Map::load_from_cache, |
|
845 | + 'EE_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
846 | + 'EE_Network_Core_Config' => EE_Dependency_Map::load_from_cache, |
|
847 | + 'EventEspresso\core\services\address\CountrySubRegionDao' => EE_Dependency_Map::load_from_cache, |
|
848 | + ), |
|
849 | + 'EventEspresso\core\services\address\CountrySubRegionDao' => array( |
|
850 | + 'EEM_State' => EE_Dependency_Map::load_from_cache, |
|
851 | + 'EventEspresso\core\services\validators\JsonValidator' => EE_Dependency_Map::load_from_cache |
|
852 | + ), |
|
853 | + 'EventEspresso\core\domain\services\admin\ajax\WordpressHeartbeat' => array( |
|
854 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
855 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
856 | + ), |
|
857 | + 'EventEspresso\core\domain\services\admin\ajax\EventEditorHeartbeat' => array( |
|
858 | + 'EventEspresso\core\domain\Domain' => EE_Dependency_Map::load_from_cache, |
|
859 | + 'EE_Environment_Config' => EE_Dependency_Map::load_from_cache, |
|
860 | + ), |
|
861 | + 'EventEspresso\core\services\request\files\FilesDataHandler' => array( |
|
862 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
863 | + ), |
|
864 | + 'EventEspressoBatchRequest\BatchRequestProcessor' => [ |
|
865 | + 'EventEspresso\core\services\loaders\Loader' => EE_Dependency_Map::load_from_cache, |
|
866 | + ], |
|
867 | + 'EventEspresso\core\domain\services\admin\registrations\list_table\QueryBuilder' => [ |
|
868 | + null, |
|
869 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
870 | + 'EEM_Registration' => EE_Dependency_Map::load_from_cache, |
|
871 | + ], |
|
872 | + 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\AttendeeFilterHeader' => [ |
|
873 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
874 | + 'EEM_Attendee' => EE_Dependency_Map::load_from_cache, |
|
875 | + ], |
|
876 | + 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\DateFilterHeader' => [ |
|
877 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
878 | + 'EEM_Datetime' => EE_Dependency_Map::load_from_cache, |
|
879 | + ], |
|
880 | + 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\EventFilterHeader' => [ |
|
881 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
882 | + 'EEM_Event' => EE_Dependency_Map::load_from_cache, |
|
883 | + ], |
|
884 | + 'EventEspresso\core\domain\services\admin\registrations\list_table\page_header\TicketFilterHeader' => [ |
|
885 | + 'EventEspresso\core\services\request\Request' => EE_Dependency_Map::load_from_cache, |
|
886 | + 'EEM_Ticket' => EE_Dependency_Map::load_from_cache, |
|
887 | + ], |
|
888 | + ); |
|
889 | + } |
|
890 | + |
|
891 | + |
|
892 | + /** |
|
893 | + * Registers how core classes are loaded. |
|
894 | + * This can either be done by simply providing the name of one of the EE_Registry loader methods such as: |
|
895 | + * 'EE_Request_Handler' => 'load_core' |
|
896 | + * 'EE_Messages_Queue' => 'load_lib' |
|
897 | + * 'EEH_Debug_Tools' => 'load_helper' |
|
898 | + * or, if greater control is required, by providing a custom closure. For example: |
|
899 | + * 'Some_Class' => function () { |
|
900 | + * return new Some_Class(); |
|
901 | + * }, |
|
902 | + * This is required for instantiating dependencies |
|
903 | + * where an interface has been type hinted in a class constructor. For example: |
|
904 | + * 'Required_Interface' => function () { |
|
905 | + * return new A_Class_That_Implements_Required_Interface(); |
|
906 | + * }, |
|
907 | + */ |
|
908 | + protected function _register_core_class_loaders() |
|
909 | + { |
|
910 | + $this->_class_loaders = array( |
|
911 | + // load_core |
|
912 | + 'EE_Dependency_Map' => function () { |
|
913 | + return $this; |
|
914 | + }, |
|
915 | + 'EE_Capabilities' => 'load_core', |
|
916 | + 'EE_Encryption' => 'load_core', |
|
917 | + 'EE_Front_Controller' => 'load_core', |
|
918 | + 'EE_Module_Request_Router' => 'load_core', |
|
919 | + 'EE_Registry' => 'load_core', |
|
920 | + 'EE_Request' => function () { |
|
921 | + return $this->legacy_request; |
|
922 | + }, |
|
923 | + 'EventEspresso\core\services\request\Request' => function () { |
|
924 | + return $this->request; |
|
925 | + }, |
|
926 | + 'EventEspresso\core\services\request\Response' => function () { |
|
927 | + return $this->response; |
|
928 | + }, |
|
929 | + 'EE_Base' => 'load_core', |
|
930 | + 'EE_Request_Handler' => 'load_core', |
|
931 | + 'EE_Session' => 'load_core', |
|
932 | + 'EE_Cron_Tasks' => 'load_core', |
|
933 | + 'EE_System' => 'load_core', |
|
934 | + 'EE_Maintenance_Mode' => 'load_core', |
|
935 | + 'EE_Register_CPTs' => 'load_core', |
|
936 | + 'EE_Admin' => 'load_core', |
|
937 | + 'EE_CPT_Strategy' => 'load_core', |
|
938 | + // load_class |
|
939 | + 'EE_Registration_Processor' => 'load_class', |
|
940 | + // load_lib |
|
941 | + 'EE_Message_Resource_Manager' => 'load_lib', |
|
942 | + 'EE_Message_Type_Collection' => 'load_lib', |
|
943 | + 'EE_Message_Type_Collection_Loader' => 'load_lib', |
|
944 | + 'EE_Messenger_Collection' => 'load_lib', |
|
945 | + 'EE_Messenger_Collection_Loader' => 'load_lib', |
|
946 | + 'EE_Messages_Processor' => 'load_lib', |
|
947 | + 'EE_Message_Repository' => 'load_lib', |
|
948 | + 'EE_Messages_Queue' => 'load_lib', |
|
949 | + 'EE_Messages_Data_Handler_Collection' => 'load_lib', |
|
950 | + 'EE_Message_Template_Group_Collection' => 'load_lib', |
|
951 | + 'EE_Payment_Method_Manager' => 'load_lib', |
|
952 | + 'EE_DMS_Core_4_1_0' => 'load_dms', |
|
953 | + 'EE_DMS_Core_4_2_0' => 'load_dms', |
|
954 | + 'EE_DMS_Core_4_3_0' => 'load_dms', |
|
955 | + 'EE_DMS_Core_4_5_0' => 'load_dms', |
|
956 | + 'EE_DMS_Core_4_6_0' => 'load_dms', |
|
957 | + 'EE_DMS_Core_4_7_0' => 'load_dms', |
|
958 | + 'EE_DMS_Core_4_8_0' => 'load_dms', |
|
959 | + 'EE_DMS_Core_4_9_0' => 'load_dms', |
|
960 | + 'EE_DMS_Core_4_10_0' => 'load_dms', |
|
961 | + 'EE_Messages_Generator' => function () { |
|
962 | + return EE_Registry::instance()->load_lib( |
|
963 | + 'Messages_Generator', |
|
964 | + array(), |
|
965 | + false, |
|
966 | + false |
|
967 | + ); |
|
968 | + }, |
|
969 | + 'EE_Messages_Template_Defaults' => function ($arguments = array()) { |
|
970 | + return EE_Registry::instance()->load_lib( |
|
971 | + 'Messages_Template_Defaults', |
|
972 | + $arguments, |
|
973 | + false, |
|
974 | + false |
|
975 | + ); |
|
976 | + }, |
|
977 | + // load_helper |
|
978 | + 'EEH_Parse_Shortcodes' => function () { |
|
979 | + if (EE_Registry::instance()->load_helper('Parse_Shortcodes')) { |
|
980 | + return new EEH_Parse_Shortcodes(); |
|
981 | + } |
|
982 | + return null; |
|
983 | + }, |
|
984 | + 'EE_Template_Config' => function () { |
|
985 | + return EE_Config::instance()->template_settings; |
|
986 | + }, |
|
987 | + 'EE_Currency_Config' => function () { |
|
988 | + return EE_Config::instance()->currency; |
|
989 | + }, |
|
990 | + 'EE_Registration_Config' => function () { |
|
991 | + return EE_Config::instance()->registration; |
|
992 | + }, |
|
993 | + 'EE_Core_Config' => function () { |
|
994 | + return EE_Config::instance()->core; |
|
995 | + }, |
|
996 | + 'EventEspresso\core\services\loaders\Loader' => function () { |
|
997 | + return LoaderFactory::getLoader(); |
|
998 | + }, |
|
999 | + 'EE_Network_Config' => function () { |
|
1000 | + return EE_Network_Config::instance(); |
|
1001 | + }, |
|
1002 | + 'EE_Config' => function () { |
|
1003 | + return EE_Config::instance(); |
|
1004 | + }, |
|
1005 | + 'EventEspresso\core\domain\Domain' => function () { |
|
1006 | + return DomainFactory::getEventEspressoCoreDomain(); |
|
1007 | + }, |
|
1008 | + 'EE_Admin_Config' => function () { |
|
1009 | + return EE_Config::instance()->admin; |
|
1010 | + }, |
|
1011 | + 'EE_Organization_Config' => function () { |
|
1012 | + return EE_Config::instance()->organization; |
|
1013 | + }, |
|
1014 | + 'EE_Network_Core_Config' => function () { |
|
1015 | + return EE_Network_Config::instance()->core; |
|
1016 | + }, |
|
1017 | + 'EE_Environment_Config' => function () { |
|
1018 | + return EE_Config::instance()->environment; |
|
1019 | + }, |
|
1020 | + ); |
|
1021 | + } |
|
1022 | + |
|
1023 | + |
|
1024 | + /** |
|
1025 | + * can be used for supplying alternate names for classes, |
|
1026 | + * or for connecting interface names to instantiable classes |
|
1027 | + */ |
|
1028 | + protected function _register_core_aliases() |
|
1029 | + { |
|
1030 | + $aliases = array( |
|
1031 | + 'CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBusInterface', |
|
1032 | + 'EventEspresso\core\services\commands\CommandBusInterface' => 'EventEspresso\core\services\commands\CommandBus', |
|
1033 | + 'CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManagerInterface', |
|
1034 | + 'EventEspresso\core\services\commands\CommandHandlerManagerInterface' => 'EventEspresso\core\services\commands\CommandHandlerManager', |
|
1035 | + 'CapChecker' => 'EventEspresso\core\services\commands\middleware\CapChecker', |
|
1036 | + 'AddActionHook' => 'EventEspresso\core\services\commands\middleware\AddActionHook', |
|
1037 | + 'CapabilitiesChecker' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
1038 | + 'CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface', |
|
1039 | + 'EventEspresso\core\domain\services\capabilities\CapabilitiesCheckerInterface' => 'EventEspresso\core\domain\services\capabilities\CapabilitiesChecker', |
|
1040 | + 'CreateRegistrationService' => 'EventEspresso\core\domain\services\registration\CreateRegistrationService', |
|
1041 | + 'CreateRegistrationCommandHandler' => 'EventEspresso\core\services\commands\registration\CreateRegistrationCommand', |
|
1042 | + 'CopyRegistrationDetailsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationDetailsCommand', |
|
1043 | + 'CopyRegistrationPaymentsCommandHandler' => 'EventEspresso\core\services\commands\registration\CopyRegistrationPaymentsCommand', |
|
1044 | + 'CancelRegistrationAndTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\registration\CancelRegistrationAndTicketLineItemCommandHandler', |
|
1045 | + 'UpdateRegistrationAndTransactionAfterChangeCommandHandler' => 'EventEspresso\core\services\commands\registration\UpdateRegistrationAndTransactionAfterChangeCommandHandler', |
|
1046 | + 'CreateTicketLineItemCommandHandler' => 'EventEspresso\core\services\commands\ticket\CreateTicketLineItemCommand', |
|
1047 | + 'CreateTransactionCommandHandler' => 'EventEspresso\core\services\commands\transaction\CreateTransactionCommandHandler', |
|
1048 | + 'CreateAttendeeCommandHandler' => 'EventEspresso\core\services\commands\attendee\CreateAttendeeCommandHandler', |
|
1049 | + 'TableManager' => 'EventEspresso\core\services\database\TableManager', |
|
1050 | + 'TableAnalysis' => 'EventEspresso\core\services\database\TableAnalysis', |
|
1051 | + 'EspressoShortcode' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
1052 | + 'ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\ShortcodeInterface', |
|
1053 | + 'EventEspresso\core\services\shortcodes\ShortcodeInterface' => 'EventEspresso\core\services\shortcodes\EspressoShortcode', |
|
1054 | + 'EventEspresso\core\services\cache\CacheStorageInterface' => 'EventEspresso\core\services\cache\TransientCacheStorage', |
|
1055 | + 'LoaderInterface' => 'EventEspresso\core\services\loaders\LoaderInterface', |
|
1056 | + 'EventEspresso\core\services\loaders\LoaderInterface' => 'EventEspresso\core\services\loaders\Loader', |
|
1057 | + 'CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactoryInterface', |
|
1058 | + 'EventEspresso\core\services\commands\CommandFactoryInterface' => 'EventEspresso\core\services\commands\CommandFactory', |
|
1059 | + 'EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface', |
|
1060 | + 'EventEspresso\core\domain\services\validation\email\EmailValidatorInterface' => 'EventEspresso\core\domain\services\validation\email\EmailValidationService', |
|
1061 | + 'NoticeConverterInterface' => 'EventEspresso\core\services\notices\NoticeConverterInterface', |
|
1062 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' => 'EventEspresso\core\services\notices\ConvertNoticesToEeErrors', |
|
1063 | + 'NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainerInterface', |
|
1064 | + 'EventEspresso\core\services\notices\NoticesContainerInterface' => 'EventEspresso\core\services\notices\NoticesContainer', |
|
1065 | + 'EventEspresso\core\services\request\RequestInterface' => 'EventEspresso\core\services\request\Request', |
|
1066 | + 'EventEspresso\core\services\request\ResponseInterface' => 'EventEspresso\core\services\request\Response', |
|
1067 | + 'EventEspresso\core\domain\DomainInterface' => 'EventEspresso\core\domain\Domain', |
|
1068 | + 'Registration_Processor' => 'EE_Registration_Processor', |
|
1069 | + ); |
|
1070 | + foreach ($aliases as $alias => $fqn) { |
|
1071 | + if (is_array($fqn)) { |
|
1072 | + foreach ($fqn as $class => $for_class) { |
|
1073 | + $this->class_cache->addAlias($class, $alias, $for_class); |
|
1074 | + } |
|
1075 | + continue; |
|
1076 | + } |
|
1077 | + $this->class_cache->addAlias($fqn, $alias); |
|
1078 | + } |
|
1079 | + if (! (defined('DOING_AJAX') && DOING_AJAX) && is_admin()) { |
|
1080 | + $this->class_cache->addAlias( |
|
1081 | + 'EventEspresso\core\services\notices\ConvertNoticesToAdminNotices', |
|
1082 | + 'EventEspresso\core\services\notices\NoticeConverterInterface' |
|
1083 | + ); |
|
1084 | + } |
|
1085 | + } |
|
1086 | + |
|
1087 | + |
|
1088 | + /** |
|
1089 | + * This is used to reset the internal map and class_loaders to their original default state at the beginning of the |
|
1090 | + * request Primarily used by unit tests. |
|
1091 | + */ |
|
1092 | + public function reset() |
|
1093 | + { |
|
1094 | + $this->_register_core_class_loaders(); |
|
1095 | + $this->_register_core_dependencies(); |
|
1096 | + } |
|
1097 | + |
|
1098 | + |
|
1099 | + /** |
|
1100 | + * PLZ NOTE: a better name for this method would be is_alias() |
|
1101 | + * because it returns TRUE if the provided fully qualified name IS an alias |
|
1102 | + * WHY? |
|
1103 | + * Because if a class is type hinting for a concretion, |
|
1104 | + * then why would we need to find another class to supply it? |
|
1105 | + * ie: if a class asks for `Fully/Qualified/Namespace/SpecificClassName`, |
|
1106 | + * then give it an instance of `Fully/Qualified/Namespace/SpecificClassName`. |
|
1107 | + * Don't go looking for some substitute. |
|
1108 | + * Whereas if a class is type hinting for an interface... |
|
1109 | + * then we need to find an actual class to use. |
|
1110 | + * So the interface IS the alias for some other FQN, |
|
1111 | + * and we need to find out if `Fully/Qualified/Namespace/SomeInterface` |
|
1112 | + * represents some other class. |
|
1113 | + * |
|
1114 | + * @deprecated 4.9.62.p |
|
1115 | + * @param string $fqn |
|
1116 | + * @param string $for_class |
|
1117 | + * @return bool |
|
1118 | + */ |
|
1119 | + public function has_alias($fqn = '', $for_class = '') |
|
1120 | + { |
|
1121 | + return $this->isAlias($fqn, $for_class); |
|
1122 | + } |
|
1123 | + |
|
1124 | + |
|
1125 | + /** |
|
1126 | + * PLZ NOTE: a better name for this method would be get_fqn_for_alias() |
|
1127 | + * because it returns a FQN for provided alias if one exists, otherwise returns the original $alias |
|
1128 | + * functions recursively, so that multiple aliases can be used to drill down to a FQN |
|
1129 | + * for example: |
|
1130 | + * if the following two entries were added to the _aliases array: |
|
1131 | + * array( |
|
1132 | + * 'interface_alias' => 'some\namespace\interface' |
|
1133 | + * 'some\namespace\interface' => 'some\namespace\classname' |
|
1134 | + * ) |
|
1135 | + * then one could use EE_Registry::instance()->create( 'interface_alias' ) |
|
1136 | + * to load an instance of 'some\namespace\classname' |
|
1137 | + * |
|
1138 | + * @deprecated 4.9.62.p |
|
1139 | + * @param string $alias |
|
1140 | + * @param string $for_class |
|
1141 | + * @return string |
|
1142 | + */ |
|
1143 | + public function get_alias($alias = '', $for_class = '') |
|
1144 | + { |
|
1145 | + return $this->getFqnForAlias($alias, $for_class); |
|
1146 | + } |
|
1147 | 1147 | } |
@@ -16,210 +16,210 @@ |
||
16 | 16 | class espresso_events_Registration_Form_Hooks extends EE_Admin_Hooks |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * @var EE_Event|null |
|
21 | - */ |
|
22 | - protected $_event; |
|
23 | - |
|
24 | - |
|
25 | - protected function _set_hooks_properties() |
|
26 | - { |
|
27 | - |
|
28 | - $this->_name = 'registration_form'; |
|
29 | - $this->_metaboxes = array( |
|
30 | - 0 => array( |
|
31 | - 'page_route' => array('edit', 'create_new'), |
|
32 | - 'func' => 'primary_questions', |
|
33 | - 'label' => esc_html__('Questions for Primary Registrant', 'event_espresso'), |
|
34 | - 'priority' => 'default', |
|
35 | - 'context' => 'side', |
|
36 | - ), |
|
37 | - ); |
|
38 | - |
|
39 | - // hook into the handler for saving question groups |
|
40 | - add_filter( |
|
41 | - 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
42 | - array($this, 'modify_callbacks'), |
|
43 | - 10 |
|
44 | - ); |
|
45 | - |
|
46 | - // hook into revision restores (we're hooking into the global action because EE_Admin_Hooks classes are already |
|
47 | - // restricted by page) |
|
48 | - add_action('AHEE_EE_Admin_Page_CPT__restore_revision', array($this, 'restore_revision'), 10, 2); |
|
49 | - } |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * Callback for FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks hook |
|
54 | - * |
|
55 | - * @param $callbacks |
|
56 | - * @return array |
|
57 | - */ |
|
58 | - public function modify_callbacks($callbacks) |
|
59 | - { |
|
60 | - // now let's add the question group callback |
|
61 | - $callbacks[] = array($this, 'primary_question_group_update'); |
|
62 | - return $callbacks; |
|
63 | - } |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * Hooked into revision restores. |
|
68 | - * |
|
69 | - * @param $post_id |
|
70 | - * @param $revision_id |
|
71 | - * @return EE_Base_Class |
|
72 | - * @throws EE_Error |
|
73 | - * @throws InvalidArgumentException |
|
74 | - * @throws ReflectionException |
|
75 | - * @throws InvalidDataTypeException |
|
76 | - * @throws InvalidInterfaceException |
|
77 | - */ |
|
78 | - public function restore_revision($post_id, $revision_id) |
|
79 | - { |
|
80 | - $EVT_MDL = EE_Registry::instance()->load_model('Event'); |
|
81 | - $post_evt = $EVT_MDL->get_one_by_ID($post_id); |
|
82 | - // restore revision for primary questions |
|
83 | - $post_evt->restore_revision( |
|
84 | - $revision_id, |
|
85 | - ['Question_Group'], |
|
86 | - ['Question_Group' => ['Event_Question_Group.EQG_primary' => true]] |
|
87 | - ); |
|
88 | - return $post_evt; |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * Content of metabox. |
|
94 | - * |
|
95 | - * @param $post_id |
|
96 | - * @param $post |
|
97 | - * @throws EE_Error |
|
98 | - * @throws InvalidArgumentException |
|
99 | - * @throws InvalidDataTypeException |
|
100 | - * @throws InvalidInterfaceException |
|
101 | - */ |
|
102 | - public function primary_questions($post_id, $post) |
|
103 | - { |
|
104 | - $this->_event = $this->_adminpage_obj->get_event_object(); |
|
105 | - $event_id = $this->_event->ID(); |
|
106 | - ?> |
|
19 | + /** |
|
20 | + * @var EE_Event|null |
|
21 | + */ |
|
22 | + protected $_event; |
|
23 | + |
|
24 | + |
|
25 | + protected function _set_hooks_properties() |
|
26 | + { |
|
27 | + |
|
28 | + $this->_name = 'registration_form'; |
|
29 | + $this->_metaboxes = array( |
|
30 | + 0 => array( |
|
31 | + 'page_route' => array('edit', 'create_new'), |
|
32 | + 'func' => 'primary_questions', |
|
33 | + 'label' => esc_html__('Questions for Primary Registrant', 'event_espresso'), |
|
34 | + 'priority' => 'default', |
|
35 | + 'context' => 'side', |
|
36 | + ), |
|
37 | + ); |
|
38 | + |
|
39 | + // hook into the handler for saving question groups |
|
40 | + add_filter( |
|
41 | + 'FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks', |
|
42 | + array($this, 'modify_callbacks'), |
|
43 | + 10 |
|
44 | + ); |
|
45 | + |
|
46 | + // hook into revision restores (we're hooking into the global action because EE_Admin_Hooks classes are already |
|
47 | + // restricted by page) |
|
48 | + add_action('AHEE_EE_Admin_Page_CPT__restore_revision', array($this, 'restore_revision'), 10, 2); |
|
49 | + } |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * Callback for FHEE__Events_Admin_Page___insert_update_cpt_item__event_update_callbacks hook |
|
54 | + * |
|
55 | + * @param $callbacks |
|
56 | + * @return array |
|
57 | + */ |
|
58 | + public function modify_callbacks($callbacks) |
|
59 | + { |
|
60 | + // now let's add the question group callback |
|
61 | + $callbacks[] = array($this, 'primary_question_group_update'); |
|
62 | + return $callbacks; |
|
63 | + } |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * Hooked into revision restores. |
|
68 | + * |
|
69 | + * @param $post_id |
|
70 | + * @param $revision_id |
|
71 | + * @return EE_Base_Class |
|
72 | + * @throws EE_Error |
|
73 | + * @throws InvalidArgumentException |
|
74 | + * @throws ReflectionException |
|
75 | + * @throws InvalidDataTypeException |
|
76 | + * @throws InvalidInterfaceException |
|
77 | + */ |
|
78 | + public function restore_revision($post_id, $revision_id) |
|
79 | + { |
|
80 | + $EVT_MDL = EE_Registry::instance()->load_model('Event'); |
|
81 | + $post_evt = $EVT_MDL->get_one_by_ID($post_id); |
|
82 | + // restore revision for primary questions |
|
83 | + $post_evt->restore_revision( |
|
84 | + $revision_id, |
|
85 | + ['Question_Group'], |
|
86 | + ['Question_Group' => ['Event_Question_Group.EQG_primary' => true]] |
|
87 | + ); |
|
88 | + return $post_evt; |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * Content of metabox. |
|
94 | + * |
|
95 | + * @param $post_id |
|
96 | + * @param $post |
|
97 | + * @throws EE_Error |
|
98 | + * @throws InvalidArgumentException |
|
99 | + * @throws InvalidDataTypeException |
|
100 | + * @throws InvalidInterfaceException |
|
101 | + */ |
|
102 | + public function primary_questions($post_id, $post) |
|
103 | + { |
|
104 | + $this->_event = $this->_adminpage_obj->get_event_object(); |
|
105 | + $event_id = $this->_event->ID(); |
|
106 | + ?> |
|
107 | 107 | <div class="inside"> |
108 | 108 | <p><strong> |
109 | 109 | <?php _e('Question Groups', 'event_espresso'); ?> |
110 | 110 | </strong><br/> |
111 | 111 | <?php |
112 | - printf( |
|
113 | - esc_html__( |
|
114 | - 'Add a pre-populated %1$sgroup of questions%2$s to your event. The personal information group is required for all events', |
|
115 | - 'event_espresso' |
|
116 | - ), |
|
117 | - '<a href="admin.php?page=espresso_registration_form" target="_blank">', |
|
118 | - '</a>' |
|
119 | - ) |
|
120 | - ?> |
|
112 | + printf( |
|
113 | + esc_html__( |
|
114 | + 'Add a pre-populated %1$sgroup of questions%2$s to your event. The personal information group is required for all events', |
|
115 | + 'event_espresso' |
|
116 | + ), |
|
117 | + '<a href="admin.php?page=espresso_registration_form" target="_blank">', |
|
118 | + '</a>' |
|
119 | + ) |
|
120 | + ?> |
|
121 | 121 | </p> |
122 | 122 | <?php |
123 | 123 | |
124 | - $qsg_where['QSG_deleted'] = false; |
|
125 | - $query_params = apply_filters( |
|
126 | - 'FHEE__espresso_events_Registration_Form_Hooks__primary_questions__question_group_query_parameters', |
|
127 | - array($qsg_where, 'order_by' => array('QSG_order' => 'ASC')) |
|
128 | - ); |
|
129 | - $QSGs = EEM_Question_Group::instance()->get_all($query_params); |
|
130 | - $EQGs = ! empty($event_id) |
|
131 | - ? $this->_event->get_many_related( |
|
132 | - 'Question_Group', |
|
133 | - [['Event_Question_Group.EQG_primary' => true]] |
|
134 | - ) |
|
135 | - : array(); |
|
136 | - $EQGids = array_keys($EQGs); |
|
137 | - |
|
138 | - if (! empty($QSGs)) { |
|
139 | - $html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : ''; |
|
140 | - foreach ($QSGs as $QSG) { |
|
141 | - $checked = in_array($QSG->ID(), $EQGids, true) |
|
142 | - || $QSG->get('QSG_system') === 1 |
|
143 | - ? ' checked="checked"' |
|
144 | - : ''; |
|
145 | - $visibility = $QSG->get('QSG_system') === 1 |
|
146 | - ? ' style="visibility:hidden"' |
|
147 | - : ''; |
|
148 | - $edit_query_args = $this->_adminpage_obj->is_caf() ? array( |
|
149 | - 'action' => 'edit_question_group', |
|
150 | - 'QSG_ID' => $QSG->ID(), |
|
151 | - ) : array('action' => 'question_groups'); |
|
152 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce( |
|
153 | - $edit_query_args, |
|
154 | - EE_FORMS_ADMIN_URL |
|
155 | - ); |
|
156 | - |
|
157 | - $html .= ' |
|
124 | + $qsg_where['QSG_deleted'] = false; |
|
125 | + $query_params = apply_filters( |
|
126 | + 'FHEE__espresso_events_Registration_Form_Hooks__primary_questions__question_group_query_parameters', |
|
127 | + array($qsg_where, 'order_by' => array('QSG_order' => 'ASC')) |
|
128 | + ); |
|
129 | + $QSGs = EEM_Question_Group::instance()->get_all($query_params); |
|
130 | + $EQGs = ! empty($event_id) |
|
131 | + ? $this->_event->get_many_related( |
|
132 | + 'Question_Group', |
|
133 | + [['Event_Question_Group.EQG_primary' => true]] |
|
134 | + ) |
|
135 | + : array(); |
|
136 | + $EQGids = array_keys($EQGs); |
|
137 | + |
|
138 | + if (! empty($QSGs)) { |
|
139 | + $html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : ''; |
|
140 | + foreach ($QSGs as $QSG) { |
|
141 | + $checked = in_array($QSG->ID(), $EQGids, true) |
|
142 | + || $QSG->get('QSG_system') === 1 |
|
143 | + ? ' checked="checked"' |
|
144 | + : ''; |
|
145 | + $visibility = $QSG->get('QSG_system') === 1 |
|
146 | + ? ' style="visibility:hidden"' |
|
147 | + : ''; |
|
148 | + $edit_query_args = $this->_adminpage_obj->is_caf() ? array( |
|
149 | + 'action' => 'edit_question_group', |
|
150 | + 'QSG_ID' => $QSG->ID(), |
|
151 | + ) : array('action' => 'question_groups'); |
|
152 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce( |
|
153 | + $edit_query_args, |
|
154 | + EE_FORMS_ADMIN_URL |
|
155 | + ); |
|
156 | + |
|
157 | + $html .= ' |
|
158 | 158 | <p id="event-question-group-' . $QSG->ID() . '"> |
159 | 159 | <input value="' . $QSG->ID() . '" type="checkbox"' |
160 | - . $visibility |
|
161 | - . ' name="question_groups[' . $QSG->ID() . ']"' . $checked . ' /> |
|
160 | + . $visibility |
|
161 | + . ' name="question_groups[' . $QSG->ID() . ']"' . $checked . ' /> |
|
162 | 162 | <a href="' . $edit_link . '" title="' |
163 | - . sprintf( |
|
164 | - esc_attr__('Edit %s Group', 'event_espresso'), |
|
165 | - $QSG->get('QSG_name') |
|
166 | - ) |
|
167 | - . '" target="_blank">' . $QSG->get('QSG_name') . '</a> |
|
163 | + . sprintf( |
|
164 | + esc_attr__('Edit %s Group', 'event_espresso'), |
|
165 | + $QSG->get('QSG_name') |
|
166 | + ) |
|
167 | + . '" target="_blank">' . $QSG->get('QSG_name') . '</a> |
|
168 | 168 | </p>'; |
169 | - } |
|
170 | - $html .= count($QSGs) > 10 ? '</div>' : ''; |
|
171 | - |
|
172 | - echo $html; |
|
173 | - } else { |
|
174 | - esc_html_e( |
|
175 | - 'There seems to be a problem with your questions. Please contact [email protected]', |
|
176 | - 'event_espresso' |
|
177 | - ); |
|
178 | - } |
|
179 | - do_action('AHEE_event_editor_questions_notice'); |
|
180 | - ?> |
|
169 | + } |
|
170 | + $html .= count($QSGs) > 10 ? '</div>' : ''; |
|
171 | + |
|
172 | + echo $html; |
|
173 | + } else { |
|
174 | + esc_html_e( |
|
175 | + 'There seems to be a problem with your questions. Please contact [email protected]', |
|
176 | + 'event_espresso' |
|
177 | + ); |
|
178 | + } |
|
179 | + do_action('AHEE_event_editor_questions_notice'); |
|
180 | + ?> |
|
181 | 181 | </div> |
182 | 182 | <?php |
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - /** |
|
187 | - * @param EE_Event $evtobj |
|
188 | - * @param array $data |
|
189 | - * @return bool |
|
190 | - * @throws EE_Error |
|
191 | - */ |
|
192 | - public function primary_question_group_update($evtobj, $data) |
|
193 | - { |
|
194 | - $question_groups = ! empty($data['question_groups']) ? (array) $data['question_groups'] : array(); |
|
195 | - $added_qgs = array_keys($question_groups); |
|
196 | - $success = array(); |
|
197 | - |
|
198 | - // let's get all current question groups associated with this event. |
|
199 | - $current_qgs = $evtobj->get_many_related( |
|
200 | - 'Question_Group', |
|
201 | - [['Event_Question_Group.EQG_primary' => true]] |
|
202 | - ); |
|
203 | - $current_qgs = array_keys($current_qgs); // we just want the ids |
|
204 | - |
|
205 | - // now let's get the groups selected in the editor and update (IF we have data) |
|
206 | - if (! empty($question_groups)) { |
|
207 | - foreach ($question_groups as $id => $val) { |
|
208 | - // add to event |
|
209 | - if ($val) { |
|
210 | - $qg = $evtobj->_add_relation_to($id, 'Question_Group', ['EQG_primary' => true]); |
|
211 | - } |
|
212 | - $success[] = ! empty($qg) ? 1 : 0; |
|
213 | - } |
|
214 | - } |
|
215 | - |
|
216 | - // wait a minute... are there question groups missing in the saved groups that ARE with the current event? |
|
217 | - $removed_qgs = array_diff($current_qgs, $added_qgs); |
|
218 | - |
|
219 | - foreach ($removed_qgs as $qgid) { |
|
220 | - $qg = $evtobj->_remove_relation_to($qgid, 'Question_Group', ['EQG_primary' => true]); |
|
221 | - $success[] = ! empty($qg) ? 1 : 0; |
|
222 | - } |
|
223 | - return in_array(0, $success, true) ? false : true; |
|
224 | - } |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * @param EE_Event $evtobj |
|
188 | + * @param array $data |
|
189 | + * @return bool |
|
190 | + * @throws EE_Error |
|
191 | + */ |
|
192 | + public function primary_question_group_update($evtobj, $data) |
|
193 | + { |
|
194 | + $question_groups = ! empty($data['question_groups']) ? (array) $data['question_groups'] : array(); |
|
195 | + $added_qgs = array_keys($question_groups); |
|
196 | + $success = array(); |
|
197 | + |
|
198 | + // let's get all current question groups associated with this event. |
|
199 | + $current_qgs = $evtobj->get_many_related( |
|
200 | + 'Question_Group', |
|
201 | + [['Event_Question_Group.EQG_primary' => true]] |
|
202 | + ); |
|
203 | + $current_qgs = array_keys($current_qgs); // we just want the ids |
|
204 | + |
|
205 | + // now let's get the groups selected in the editor and update (IF we have data) |
|
206 | + if (! empty($question_groups)) { |
|
207 | + foreach ($question_groups as $id => $val) { |
|
208 | + // add to event |
|
209 | + if ($val) { |
|
210 | + $qg = $evtobj->_add_relation_to($id, 'Question_Group', ['EQG_primary' => true]); |
|
211 | + } |
|
212 | + $success[] = ! empty($qg) ? 1 : 0; |
|
213 | + } |
|
214 | + } |
|
215 | + |
|
216 | + // wait a minute... are there question groups missing in the saved groups that ARE with the current event? |
|
217 | + $removed_qgs = array_diff($current_qgs, $added_qgs); |
|
218 | + |
|
219 | + foreach ($removed_qgs as $qgid) { |
|
220 | + $qg = $evtobj->_remove_relation_to($qgid, 'Question_Group', ['EQG_primary' => true]); |
|
221 | + $success[] = ! empty($qg) ? 1 : 0; |
|
222 | + } |
|
223 | + return in_array(0, $success, true) ? false : true; |
|
224 | + } |
|
225 | 225 | } |
@@ -32,10 +32,10 @@ |
||
32 | 32 | ); |
33 | 33 | // this model is generally available for reading |
34 | 34 | $path_to_event = 'Event'; |
35 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event); |
|
36 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
37 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
38 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit); |
|
35 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public($path_to_event); |
|
36 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
37 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
38 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit); |
|
39 | 39 | parent::__construct($timezone); |
40 | 40 | } |
41 | 41 |
@@ -7,72 +7,72 @@ |
||
7 | 7 | */ |
8 | 8 | class EEM_Event_Question_Group extends EEM_Base |
9 | 9 | { |
10 | - /** |
|
11 | - * Name of the field indicating an event should use the question group for the primary attendee |
|
12 | - */ |
|
13 | - const PRIMARY = 'EQG_primary'; |
|
10 | + /** |
|
11 | + * Name of the field indicating an event should use the question group for the primary attendee |
|
12 | + */ |
|
13 | + const PRIMARY = 'EQG_primary'; |
|
14 | 14 | |
15 | - /** |
|
16 | - * Name of hte field indicating an event should use the question group for additional attendees |
|
17 | - */ |
|
18 | - const ADDITIONAL = 'EQG_additional'; |
|
15 | + /** |
|
16 | + * Name of hte field indicating an event should use the question group for additional attendees |
|
17 | + */ |
|
18 | + const ADDITIONAL = 'EQG_additional'; |
|
19 | 19 | |
20 | - // private instance of the Event_Question_Group object |
|
21 | - protected static $_instance = null; |
|
20 | + // private instance of the Event_Question_Group object |
|
21 | + protected static $_instance = null; |
|
22 | 22 | |
23 | - protected function __construct($timezone = null) |
|
24 | - { |
|
25 | - $this->singular_item = __('Event to Question Group Link', 'event_espresso'); |
|
26 | - $this->plural_item = __('Event to Question Group Links', 'event_espresso'); |
|
27 | - $this->_tables = array( |
|
28 | - 'Event_Question_Group'=>new EE_Primary_Table('esp_event_question_group', 'EQG_ID') |
|
29 | - ); |
|
30 | - $this->_fields = array( |
|
31 | - 'Event_Question_Group'=>array( |
|
32 | - 'EQG_ID'=>new EE_Primary_Key_Int_Field('EQG_ID', __('Event to Question Group Link ID', 'event_espresso')), |
|
33 | - 'EVT_ID'=>new EE_Foreign_Key_Int_Field('EVT_ID', __('Event ID', 'event_espresso'), false, 0, 'Event'), |
|
34 | - 'QSG_ID'=>new EE_Foreign_Key_Int_Field('QSG_ID', __('Question Group Id', 'event_espresso'), false, 0, 'Question_Group'), |
|
35 | - 'EQG_primary'=>new EE_Boolean_Field('EQG_primary', __('Flag indicating question is only for primary attendees', 'event_espresso'), false, false), |
|
36 | - 'EQG_additional'=>new EE_Boolean_Field('EQG_additional', __('Flag indicating question is only for additional attendees', 'event_espresso'), false, false) |
|
37 | - ) |
|
38 | - ); |
|
39 | - $this->_model_relations = array( |
|
40 | - 'Event'=>new EE_Belongs_To_Relation(), |
|
41 | - 'Question_Group'=>new EE_Belongs_To_Relation() |
|
42 | - ); |
|
43 | - // this model is generally available for reading |
|
44 | - $path_to_event = 'Event'; |
|
45 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event); |
|
46 | - $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
47 | - $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
48 | - $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit); |
|
49 | - parent::__construct($timezone); |
|
50 | - } |
|
23 | + protected function __construct($timezone = null) |
|
24 | + { |
|
25 | + $this->singular_item = __('Event to Question Group Link', 'event_espresso'); |
|
26 | + $this->plural_item = __('Event to Question Group Links', 'event_espresso'); |
|
27 | + $this->_tables = array( |
|
28 | + 'Event_Question_Group'=>new EE_Primary_Table('esp_event_question_group', 'EQG_ID') |
|
29 | + ); |
|
30 | + $this->_fields = array( |
|
31 | + 'Event_Question_Group'=>array( |
|
32 | + 'EQG_ID'=>new EE_Primary_Key_Int_Field('EQG_ID', __('Event to Question Group Link ID', 'event_espresso')), |
|
33 | + 'EVT_ID'=>new EE_Foreign_Key_Int_Field('EVT_ID', __('Event ID', 'event_espresso'), false, 0, 'Event'), |
|
34 | + 'QSG_ID'=>new EE_Foreign_Key_Int_Field('QSG_ID', __('Question Group Id', 'event_espresso'), false, 0, 'Question_Group'), |
|
35 | + 'EQG_primary'=>new EE_Boolean_Field('EQG_primary', __('Flag indicating question is only for primary attendees', 'event_espresso'), false, false), |
|
36 | + 'EQG_additional'=>new EE_Boolean_Field('EQG_additional', __('Flag indicating question is only for additional attendees', 'event_espresso'), false, false) |
|
37 | + ) |
|
38 | + ); |
|
39 | + $this->_model_relations = array( |
|
40 | + 'Event'=>new EE_Belongs_To_Relation(), |
|
41 | + 'Question_Group'=>new EE_Belongs_To_Relation() |
|
42 | + ); |
|
43 | + // this model is generally available for reading |
|
44 | + $path_to_event = 'Event'; |
|
45 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Event_Related_Public($path_to_event); |
|
46 | + $this->_cap_restriction_generators[ EEM_Base::caps_read_admin ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
47 | + $this->_cap_restriction_generators[ EEM_Base::caps_edit ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event); |
|
48 | + $this->_cap_restriction_generators[ EEM_Base::caps_delete ] = new EE_Restriction_Generator_Event_Related_Protected($path_to_event, EEM_Base::caps_edit); |
|
49 | + parent::__construct($timezone); |
|
50 | + } |
|
51 | 51 | |
52 | - /** |
|
53 | - * Decides whether to use the 'EQG_primary' or newer 'EQG_additional' for use in queries, based on whether |
|
54 | - * this is concerning primary attendees or additional attendees. |
|
55 | - * If 1, true, or "primary" is passed in, returns EQG_primary. If 0, false, or "additional" is passed in, returns |
|
56 | - * EQG_additional. |
|
57 | - * @since 4.10.0.p |
|
58 | - * @param string|boolean|int $context |
|
59 | - * @return string |
|
60 | - */ |
|
61 | - public function fieldNameForContext($context) |
|
62 | - { |
|
63 | - // Basically do a strict switch statement. |
|
64 | - switch (true) { |
|
65 | - case $context === 'additional': |
|
66 | - case $context === false: |
|
67 | - case $context === 0: |
|
68 | - $field_name = EEM_Event_Question_Group::ADDITIONAL; |
|
69 | - break; |
|
70 | - case $context === 'primary': |
|
71 | - case $context === true: |
|
72 | - case $context === 1: |
|
73 | - default: |
|
74 | - $field_name = EEM_Event_Question_Group::PRIMARY; |
|
75 | - } |
|
76 | - return apply_filters('FHEE__EEM_Event_Question_Group__fieldNameForContext', $field_name, $context); |
|
77 | - } |
|
52 | + /** |
|
53 | + * Decides whether to use the 'EQG_primary' or newer 'EQG_additional' for use in queries, based on whether |
|
54 | + * this is concerning primary attendees or additional attendees. |
|
55 | + * If 1, true, or "primary" is passed in, returns EQG_primary. If 0, false, or "additional" is passed in, returns |
|
56 | + * EQG_additional. |
|
57 | + * @since 4.10.0.p |
|
58 | + * @param string|boolean|int $context |
|
59 | + * @return string |
|
60 | + */ |
|
61 | + public function fieldNameForContext($context) |
|
62 | + { |
|
63 | + // Basically do a strict switch statement. |
|
64 | + switch (true) { |
|
65 | + case $context === 'additional': |
|
66 | + case $context === false: |
|
67 | + case $context === 0: |
|
68 | + $field_name = EEM_Event_Question_Group::ADDITIONAL; |
|
69 | + break; |
|
70 | + case $context === 'primary': |
|
71 | + case $context === true: |
|
72 | + case $context === 1: |
|
73 | + default: |
|
74 | + $field_name = EEM_Event_Question_Group::PRIMARY; |
|
75 | + } |
|
76 | + return apply_filters('FHEE__EEM_Event_Question_Group__fieldNameForContext', $field_name, $context); |
|
77 | + } |
|
78 | 78 | } |
@@ -16,208 +16,208 @@ |
||
16 | 16 | class espresso_events_Registration_Form_Hooks_Extend extends espresso_events_Registration_Form_Hooks |
17 | 17 | { |
18 | 18 | |
19 | - /** |
|
20 | - * extending the properties set in espresso_events_Registration_From_Hooks |
|
21 | - * |
|
22 | - * @access protected |
|
23 | - * @return void |
|
24 | - */ |
|
25 | - protected function _extend_properties() |
|
26 | - { |
|
27 | - $this->_metaboxes = array_merge( |
|
28 | - $this->_metaboxes, |
|
29 | - array( |
|
30 | - 1 => array( |
|
31 | - 'page_route' => array('create_new', 'edit'), |
|
32 | - 'func' => 'additional_questions', |
|
33 | - 'label' => esc_html__('Questions for Additional Registrants', 'event_espresso'), |
|
34 | - 'priority' => 'default', |
|
35 | - 'context' => 'side', |
|
36 | - ), |
|
37 | - ) |
|
38 | - ); |
|
39 | - $this->_scripts_styles = array( |
|
40 | - 'registers' => array( |
|
41 | - 'extended-event-editor' => array( |
|
42 | - 'url' => EE_CORE_CAF_ADMIN_EXTEND_URL |
|
43 | - . 'registration_form/assets/event-editor-question-groups.js', |
|
44 | - 'depends' => array('jquery'), |
|
45 | - ), |
|
46 | - ), |
|
47 | - 'enqueues' => array( |
|
48 | - 'extended-event-editor' => array('edit', 'create_new'), |
|
49 | - ), |
|
50 | - ); |
|
51 | - } |
|
52 | - |
|
53 | - |
|
54 | - /** |
|
55 | - * @param Callable[] $callbacks |
|
56 | - * @return array |
|
57 | - */ |
|
58 | - public function modify_callbacks($callbacks) |
|
59 | - { |
|
60 | - $callbacks = parent::modify_callbacks($callbacks); |
|
61 | - $callbacks[] = array($this, 'additional_question_group_update'); |
|
62 | - return $callbacks; |
|
63 | - } |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * Call back hooked into revision restores. |
|
68 | - * |
|
69 | - * @param $post_id |
|
70 | - * @param $revision_id |
|
71 | - * @return EE_Base_Class|void |
|
72 | - * @throws EE_Error |
|
73 | - * @throws InvalidArgumentException |
|
74 | - * @throws InvalidDataTypeException |
|
75 | - * @throws InvalidInterfaceException |
|
76 | - * @throws ReflectionException |
|
77 | - */ |
|
78 | - public function restore_revision($post_id, $revision_id) |
|
79 | - { |
|
80 | - $post_evt = parent::restore_revision($post_id, $revision_id); |
|
81 | - |
|
82 | - // restore revision for additional questions |
|
83 | - $post_evt->restore_revision( |
|
84 | - $revision_id, |
|
85 | - ['Question_Group'], |
|
86 | - [ |
|
87 | - 'Question_Group' => ['Event_Question_Group.EQG_additional' => true], |
|
88 | - ] |
|
89 | - ); |
|
90 | - } |
|
91 | - |
|
92 | - |
|
93 | - /** |
|
94 | - * @param $post_id |
|
95 | - * @param $post |
|
96 | - * @throws EE_Error |
|
97 | - * @throws InvalidArgumentException |
|
98 | - * @throws InvalidDataTypeException |
|
99 | - * @throws InvalidInterfaceException |
|
100 | - */ |
|
101 | - public function additional_questions($post_id, $post) |
|
102 | - { |
|
103 | - $this->_event = $this->_adminpage_obj->get_event_object(); |
|
104 | - $event_id = $this->_event->ID(); |
|
105 | - ?> |
|
19 | + /** |
|
20 | + * extending the properties set in espresso_events_Registration_From_Hooks |
|
21 | + * |
|
22 | + * @access protected |
|
23 | + * @return void |
|
24 | + */ |
|
25 | + protected function _extend_properties() |
|
26 | + { |
|
27 | + $this->_metaboxes = array_merge( |
|
28 | + $this->_metaboxes, |
|
29 | + array( |
|
30 | + 1 => array( |
|
31 | + 'page_route' => array('create_new', 'edit'), |
|
32 | + 'func' => 'additional_questions', |
|
33 | + 'label' => esc_html__('Questions for Additional Registrants', 'event_espresso'), |
|
34 | + 'priority' => 'default', |
|
35 | + 'context' => 'side', |
|
36 | + ), |
|
37 | + ) |
|
38 | + ); |
|
39 | + $this->_scripts_styles = array( |
|
40 | + 'registers' => array( |
|
41 | + 'extended-event-editor' => array( |
|
42 | + 'url' => EE_CORE_CAF_ADMIN_EXTEND_URL |
|
43 | + . 'registration_form/assets/event-editor-question-groups.js', |
|
44 | + 'depends' => array('jquery'), |
|
45 | + ), |
|
46 | + ), |
|
47 | + 'enqueues' => array( |
|
48 | + 'extended-event-editor' => array('edit', 'create_new'), |
|
49 | + ), |
|
50 | + ); |
|
51 | + } |
|
52 | + |
|
53 | + |
|
54 | + /** |
|
55 | + * @param Callable[] $callbacks |
|
56 | + * @return array |
|
57 | + */ |
|
58 | + public function modify_callbacks($callbacks) |
|
59 | + { |
|
60 | + $callbacks = parent::modify_callbacks($callbacks); |
|
61 | + $callbacks[] = array($this, 'additional_question_group_update'); |
|
62 | + return $callbacks; |
|
63 | + } |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * Call back hooked into revision restores. |
|
68 | + * |
|
69 | + * @param $post_id |
|
70 | + * @param $revision_id |
|
71 | + * @return EE_Base_Class|void |
|
72 | + * @throws EE_Error |
|
73 | + * @throws InvalidArgumentException |
|
74 | + * @throws InvalidDataTypeException |
|
75 | + * @throws InvalidInterfaceException |
|
76 | + * @throws ReflectionException |
|
77 | + */ |
|
78 | + public function restore_revision($post_id, $revision_id) |
|
79 | + { |
|
80 | + $post_evt = parent::restore_revision($post_id, $revision_id); |
|
81 | + |
|
82 | + // restore revision for additional questions |
|
83 | + $post_evt->restore_revision( |
|
84 | + $revision_id, |
|
85 | + ['Question_Group'], |
|
86 | + [ |
|
87 | + 'Question_Group' => ['Event_Question_Group.EQG_additional' => true], |
|
88 | + ] |
|
89 | + ); |
|
90 | + } |
|
91 | + |
|
92 | + |
|
93 | + /** |
|
94 | + * @param $post_id |
|
95 | + * @param $post |
|
96 | + * @throws EE_Error |
|
97 | + * @throws InvalidArgumentException |
|
98 | + * @throws InvalidDataTypeException |
|
99 | + * @throws InvalidInterfaceException |
|
100 | + */ |
|
101 | + public function additional_questions($post_id, $post) |
|
102 | + { |
|
103 | + $this->_event = $this->_adminpage_obj->get_event_object(); |
|
104 | + $event_id = $this->_event->ID(); |
|
105 | + ?> |
|
106 | 106 | <div class="inside"> |
107 | 107 | <p><strong> |
108 | 108 | <?php _e('Question Groups', 'event_espresso'); ?> |
109 | 109 | </strong><br/> |
110 | 110 | <?php |
111 | - printf( |
|
112 | - esc_html__( |
|
113 | - 'Add a pre-populated %1$sgroup of questions%2$s to your event.', |
|
114 | - 'event_espresso' |
|
115 | - ), |
|
116 | - '<a href="admin.php?page=espresso_registration_form" target="_blank">', |
|
117 | - '</a>' |
|
118 | - ); |
|
119 | - ?> |
|
111 | + printf( |
|
112 | + esc_html__( |
|
113 | + 'Add a pre-populated %1$sgroup of questions%2$s to your event.', |
|
114 | + 'event_espresso' |
|
115 | + ), |
|
116 | + '<a href="admin.php?page=espresso_registration_form" target="_blank">', |
|
117 | + '</a>' |
|
118 | + ); |
|
119 | + ?> |
|
120 | 120 | </p> |
121 | 121 | <?php |
122 | 122 | |
123 | - $qsg_where['QSG_deleted'] = false; |
|
124 | - $query_params = apply_filters( |
|
125 | - 'FHEE__espresso_events_Registration_Form_Hooks_Extend__additional_questions__question_group_query_parameters', |
|
126 | - array($qsg_where, 'order_by' => array('QSG_order' => 'ASC')) |
|
127 | - ); |
|
128 | - $QSGs = EEM_Question_Group::instance()->get_all($query_params); |
|
129 | - $EQGs = ! empty($event_id) |
|
130 | - ? $this->_event->get_many_related( |
|
131 | - 'Question_Group', |
|
132 | - [['Event_Question_Group.EQG_additional' => true]] |
|
133 | - ) |
|
134 | - : []; |
|
135 | - $EQGids = array_keys($EQGs); |
|
136 | - |
|
137 | - if (! empty($QSGs)) { |
|
138 | - $html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : ''; |
|
139 | - foreach ($QSGs as $QSG) { |
|
140 | - $checked = in_array($QSG->ID(), $EQGids, true) ? ' checked="checked" ' : ''; |
|
141 | - $edit_link = EE_Admin_Page::add_query_args_and_nonce( |
|
142 | - array( |
|
143 | - 'action' => 'edit_question_group', |
|
144 | - 'QSG_ID' => $QSG->ID(), |
|
145 | - ), |
|
146 | - EE_FORMS_ADMIN_URL |
|
147 | - ); |
|
148 | - |
|
149 | - $html .= ' |
|
123 | + $qsg_where['QSG_deleted'] = false; |
|
124 | + $query_params = apply_filters( |
|
125 | + 'FHEE__espresso_events_Registration_Form_Hooks_Extend__additional_questions__question_group_query_parameters', |
|
126 | + array($qsg_where, 'order_by' => array('QSG_order' => 'ASC')) |
|
127 | + ); |
|
128 | + $QSGs = EEM_Question_Group::instance()->get_all($query_params); |
|
129 | + $EQGs = ! empty($event_id) |
|
130 | + ? $this->_event->get_many_related( |
|
131 | + 'Question_Group', |
|
132 | + [['Event_Question_Group.EQG_additional' => true]] |
|
133 | + ) |
|
134 | + : []; |
|
135 | + $EQGids = array_keys($EQGs); |
|
136 | + |
|
137 | + if (! empty($QSGs)) { |
|
138 | + $html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : ''; |
|
139 | + foreach ($QSGs as $QSG) { |
|
140 | + $checked = in_array($QSG->ID(), $EQGids, true) ? ' checked="checked" ' : ''; |
|
141 | + $edit_link = EE_Admin_Page::add_query_args_and_nonce( |
|
142 | + array( |
|
143 | + 'action' => 'edit_question_group', |
|
144 | + 'QSG_ID' => $QSG->ID(), |
|
145 | + ), |
|
146 | + EE_FORMS_ADMIN_URL |
|
147 | + ); |
|
148 | + |
|
149 | + $html .= ' |
|
150 | 150 | <p id="event-question-group-' . $QSG->ID() . '"> |
151 | 151 | <input value="' . $QSG->ID() . '"' |
152 | - . ' type="checkbox" name="add_attendee_question_groups[' . $QSG->ID() . ']"' . $checked . ' /> |
|
152 | + . ' type="checkbox" name="add_attendee_question_groups[' . $QSG->ID() . ']"' . $checked . ' /> |
|
153 | 153 | <a href="' . $edit_link . '" title="' |
154 | - . sprintf( |
|
155 | - esc_attr__('Edit %s Group', 'event_espresso'), |
|
156 | - $QSG->get('QSG_name') |
|
157 | - ) |
|
158 | - . '" target="_blank">' . $QSG->get('QSG_name') . '</a> |
|
154 | + . sprintf( |
|
155 | + esc_attr__('Edit %s Group', 'event_espresso'), |
|
156 | + $QSG->get('QSG_name') |
|
157 | + ) |
|
158 | + . '" target="_blank">' . $QSG->get('QSG_name') . '</a> |
|
159 | 159 | </p>'; |
160 | - if ($QSG->ID() === 2) { |
|
161 | - $html .= ' |
|
160 | + if ($QSG->ID() === 2) { |
|
161 | + $html .= ' |
|
162 | 162 | <p id="question-group-requirements-notice-pg" class="important-notice small-text" style="display: none;">' |
163 | - . esc_html__( |
|
164 | - 'The Personal Information question group is required whenever the Address Information question group is activated.', |
|
165 | - 'event_espresso' |
|
166 | - ) |
|
167 | - . '</p>'; |
|
168 | - } |
|
169 | - } |
|
170 | - $html .= count($QSGs) > 10 ? '</div>' : ''; |
|
171 | - |
|
172 | - echo $html; |
|
173 | - } else { |
|
174 | - esc_html_e( |
|
175 | - 'There seems to be a problem with your questions. Please contact [email protected]', |
|
176 | - 'event_espresso' |
|
177 | - ); |
|
178 | - } |
|
179 | - do_action('AHEE__espresso_events_Registration_Form_Hooks__additional_questions__after_content'); |
|
180 | - ?> |
|
163 | + . esc_html__( |
|
164 | + 'The Personal Information question group is required whenever the Address Information question group is activated.', |
|
165 | + 'event_espresso' |
|
166 | + ) |
|
167 | + . '</p>'; |
|
168 | + } |
|
169 | + } |
|
170 | + $html .= count($QSGs) > 10 ? '</div>' : ''; |
|
171 | + |
|
172 | + echo $html; |
|
173 | + } else { |
|
174 | + esc_html_e( |
|
175 | + 'There seems to be a problem with your questions. Please contact [email protected]', |
|
176 | + 'event_espresso' |
|
177 | + ); |
|
178 | + } |
|
179 | + do_action('AHEE__espresso_events_Registration_Form_Hooks__additional_questions__after_content'); |
|
180 | + ?> |
|
181 | 181 | </div> |
182 | 182 | <?php |
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - public function additional_question_group_update($evtobj, $data) |
|
187 | - { |
|
188 | - $question_groups = ! empty($data['add_attendee_question_groups']) |
|
189 | - ? (array) $data['add_attendee_question_groups'] |
|
190 | - : []; |
|
191 | - $added_qgs = array_keys($question_groups); |
|
192 | - $success = []; |
|
193 | - |
|
194 | - // let's get all current question groups associated with this event. |
|
195 | - $current_qgs = $evtobj->get_many_related( |
|
196 | - 'Question_Group', |
|
197 | - [['Event_Question_Group.EQG_additional' => true]] |
|
198 | - ); |
|
199 | - $current_qgs = array_keys($current_qgs); // we just want the ids |
|
200 | - |
|
201 | - // now let's get the groups selected in the editor and update (IF we have data) |
|
202 | - if (! empty($question_groups)) { |
|
203 | - foreach ($question_groups as $qgid) { |
|
204 | - // add to event |
|
205 | - if ($qgid) { |
|
206 | - $qg = $evtobj->add_question_group($qgid, false); |
|
207 | - } |
|
208 | - $success[] = ! empty($qg) ? 1 : 0; |
|
209 | - } |
|
210 | - } |
|
211 | - |
|
212 | - // wait a minute... are there question groups missing in the saved groups that ARE with the current event? |
|
213 | - $removed_qgs = array_diff($current_qgs, $added_qgs); |
|
214 | - |
|
215 | - foreach ($removed_qgs as $qgid) { |
|
216 | - $qg = $evtobj->remove_question_group($qgid, false); |
|
217 | - $success[] = ! empty($qg) ? 1 : 0; |
|
218 | - } |
|
219 | - |
|
220 | - |
|
221 | - return in_array(0, $success, true) ? false : true; |
|
222 | - } |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + public function additional_question_group_update($evtobj, $data) |
|
187 | + { |
|
188 | + $question_groups = ! empty($data['add_attendee_question_groups']) |
|
189 | + ? (array) $data['add_attendee_question_groups'] |
|
190 | + : []; |
|
191 | + $added_qgs = array_keys($question_groups); |
|
192 | + $success = []; |
|
193 | + |
|
194 | + // let's get all current question groups associated with this event. |
|
195 | + $current_qgs = $evtobj->get_many_related( |
|
196 | + 'Question_Group', |
|
197 | + [['Event_Question_Group.EQG_additional' => true]] |
|
198 | + ); |
|
199 | + $current_qgs = array_keys($current_qgs); // we just want the ids |
|
200 | + |
|
201 | + // now let's get the groups selected in the editor and update (IF we have data) |
|
202 | + if (! empty($question_groups)) { |
|
203 | + foreach ($question_groups as $qgid) { |
|
204 | + // add to event |
|
205 | + if ($qgid) { |
|
206 | + $qg = $evtobj->add_question_group($qgid, false); |
|
207 | + } |
|
208 | + $success[] = ! empty($qg) ? 1 : 0; |
|
209 | + } |
|
210 | + } |
|
211 | + |
|
212 | + // wait a minute... are there question groups missing in the saved groups that ARE with the current event? |
|
213 | + $removed_qgs = array_diff($current_qgs, $added_qgs); |
|
214 | + |
|
215 | + foreach ($removed_qgs as $qgid) { |
|
216 | + $qg = $evtobj->remove_question_group($qgid, false); |
|
217 | + $success[] = ! empty($qg) ? 1 : 0; |
|
218 | + } |
|
219 | + |
|
220 | + |
|
221 | + return in_array(0, $success, true) ? false : true; |
|
222 | + } |
|
223 | 223 | } |
@@ -134,7 +134,7 @@ discard block |
||
134 | 134 | : []; |
135 | 135 | $EQGids = array_keys($EQGs); |
136 | 136 | |
137 | - if (! empty($QSGs)) { |
|
137 | + if ( ! empty($QSGs)) { |
|
138 | 138 | $html = count($QSGs) > 10 ? '<div style="height:250px;overflow:auto;">' : ''; |
139 | 139 | foreach ($QSGs as $QSG) { |
140 | 140 | $checked = in_array($QSG->ID(), $EQGids, true) ? ' checked="checked" ' : ''; |
@@ -147,15 +147,15 @@ discard block |
||
147 | 147 | ); |
148 | 148 | |
149 | 149 | $html .= ' |
150 | - <p id="event-question-group-' . $QSG->ID() . '"> |
|
151 | - <input value="' . $QSG->ID() . '"' |
|
152 | - . ' type="checkbox" name="add_attendee_question_groups[' . $QSG->ID() . ']"' . $checked . ' /> |
|
153 | - <a href="' . $edit_link . '" title="' |
|
150 | + <p id="event-question-group-' . $QSG->ID().'"> |
|
151 | + <input value="' . $QSG->ID().'"' |
|
152 | + . ' type="checkbox" name="add_attendee_question_groups['.$QSG->ID().']"'.$checked.' /> |
|
153 | + <a href="' . $edit_link.'" title="' |
|
154 | 154 | . sprintf( |
155 | 155 | esc_attr__('Edit %s Group', 'event_espresso'), |
156 | 156 | $QSG->get('QSG_name') |
157 | 157 | ) |
158 | - . '" target="_blank">' . $QSG->get('QSG_name') . '</a> |
|
158 | + . '" target="_blank">'.$QSG->get('QSG_name').'</a> |
|
159 | 159 | </p>'; |
160 | 160 | if ($QSG->ID() === 2) { |
161 | 161 | $html .= ' |
@@ -199,7 +199,7 @@ discard block |
||
199 | 199 | $current_qgs = array_keys($current_qgs); // we just want the ids |
200 | 200 | |
201 | 201 | // now let's get the groups selected in the editor and update (IF we have data) |
202 | - if (! empty($question_groups)) { |
|
202 | + if ( ! empty($question_groups)) { |
|
203 | 203 | foreach ($question_groups as $qgid) { |
204 | 204 | // add to event |
205 | 205 | if ($qgid) { |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | */ |
72 | 72 | public function getAvailableSpacesCalculator() |
73 | 73 | { |
74 | - if (! $this->available_spaces_calculator instanceof EventSpacesCalculator) { |
|
74 | + if ( ! $this->available_spaces_calculator instanceof EventSpacesCalculator) { |
|
75 | 75 | $this->available_spaces_calculator = new EventSpacesCalculator($this); |
76 | 76 | } |
77 | 77 | return $this->available_spaces_calculator; |
@@ -213,7 +213,7 @@ discard block |
||
213 | 213 | */ |
214 | 214 | public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true) |
215 | 215 | { |
216 | - if (! empty($this->_Primary_Datetime)) { |
|
216 | + if ( ! empty($this->_Primary_Datetime)) { |
|
217 | 217 | return $this->_Primary_Datetime; |
218 | 218 | } |
219 | 219 | $this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)->get_primary_datetime_for_event( |
@@ -236,7 +236,7 @@ discard block |
||
236 | 236 | { |
237 | 237 | // first get all datetimes |
238 | 238 | $datetimes = $this->datetimes_ordered(); |
239 | - if (! $datetimes) { |
|
239 | + if ( ! $datetimes) { |
|
240 | 240 | return array(); |
241 | 241 | } |
242 | 242 | $datetime_ids = array(); |
@@ -429,7 +429,7 @@ discard block |
||
429 | 429 | public function short_description($num_words = 55, $more = null, $not_full_desc = false) |
430 | 430 | { |
431 | 431 | $short_desc = $this->get('EVT_short_desc'); |
432 | - if (! empty($short_desc) || $not_full_desc) { |
|
432 | + if ( ! empty($short_desc) || $not_full_desc) { |
|
433 | 433 | return $short_desc; |
434 | 434 | } |
435 | 435 | $full_desc = $this->get('EVT_desc'); |
@@ -883,7 +883,7 @@ discard block |
||
883 | 883 | ); |
884 | 884 | $all_expired = true; |
885 | 885 | foreach ($tickets as $ticket) { |
886 | - if (! $ticket->is_expired()) { |
|
886 | + if ( ! $ticket->is_expired()) { |
|
887 | 887 | $all_expired = false; |
888 | 888 | break; |
889 | 889 | } |
@@ -972,7 +972,7 @@ discard block |
||
972 | 972 | */ |
973 | 973 | public function is_sold_out($actual = false) |
974 | 974 | { |
975 | - if (! $actual) { |
|
975 | + if ( ! $actual) { |
|
976 | 976 | return $this->status() === EEM_Event::sold_out; |
977 | 977 | } |
978 | 978 | return $this->perform_sold_out_status_check(); |
@@ -1017,11 +1017,11 @@ discard block |
||
1017 | 1017 | public function get_active_status($reset = false) |
1018 | 1018 | { |
1019 | 1019 | // if the active status has already been set, then just use that value (unless we are resetting it) |
1020 | - if (! empty($this->_active_status) && ! $reset) { |
|
1020 | + if ( ! empty($this->_active_status) && ! $reset) { |
|
1021 | 1021 | return $this->_active_status; |
1022 | 1022 | } |
1023 | 1023 | // first check if event id is present on this object |
1024 | - if (! $this->ID()) { |
|
1024 | + if ( ! $this->ID()) { |
|
1025 | 1025 | return false; |
1026 | 1026 | } |
1027 | 1027 | $where_params_for_event = array(array('EVT_ID' => $this->ID())); |
@@ -1106,7 +1106,7 @@ discard block |
||
1106 | 1106 | public function get_number_of_tickets_sold() |
1107 | 1107 | { |
1108 | 1108 | $tkt_sold = 0; |
1109 | - if (! $this->ID()) { |
|
1109 | + if ( ! $this->ID()) { |
|
1110 | 1110 | return 0; |
1111 | 1111 | } |
1112 | 1112 | $datetimes = $this->datetimes(); |
@@ -1290,7 +1290,7 @@ discard block |
||
1290 | 1290 | ] |
1291 | 1291 | ); |
1292 | 1292 | $field_to_update = EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary); |
1293 | - $other_field = EEM_Event_Question_Group::instance()->fieldNameForContext(! $for_primary); |
|
1293 | + $other_field = EEM_Event_Question_Group::instance()->fieldNameForContext( ! $for_primary); |
|
1294 | 1294 | if ($existing_relation->get($other_field) === false) { |
1295 | 1295 | // Delete it. It's now no longer for primary or additional question groups. |
1296 | 1296 | return $this->_remove_relation_to($question_group_id_or_obj, 'Question_Group'); |
@@ -15,1388 +15,1388 @@ |
||
15 | 15 | class EE_Event extends EE_CPT_Base implements EEI_Line_Item_Object, EEI_Admin_Links, EEI_Has_Icon, EEI_Event |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * cached value for the the logical active status for the event |
|
20 | - * |
|
21 | - * @see get_active_status() |
|
22 | - * @var string |
|
23 | - */ |
|
24 | - protected $_active_status = ''; |
|
25 | - |
|
26 | - /** |
|
27 | - * This is just used for caching the Primary Datetime for the Event on initial retrieval |
|
28 | - * |
|
29 | - * @var EE_Datetime |
|
30 | - */ |
|
31 | - protected $_Primary_Datetime; |
|
32 | - |
|
33 | - /** |
|
34 | - * @var EventSpacesCalculator $available_spaces_calculator |
|
35 | - */ |
|
36 | - protected $available_spaces_calculator; |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * @param array $props_n_values incoming values |
|
41 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
42 | - * used.) |
|
43 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
44 | - * date_format and the second value is the time format |
|
45 | - * @return EE_Event |
|
46 | - * @throws EE_Error |
|
47 | - */ |
|
48 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
49 | - { |
|
50 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
51 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
52 | - } |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * @param array $props_n_values incoming values from the database |
|
57 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
58 | - * the website will be used. |
|
59 | - * @return EE_Event |
|
60 | - * @throws EE_Error |
|
61 | - */ |
|
62 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
63 | - { |
|
64 | - return new self($props_n_values, true, $timezone); |
|
65 | - } |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * @return EventSpacesCalculator |
|
70 | - * @throws \EE_Error |
|
71 | - */ |
|
72 | - public function getAvailableSpacesCalculator() |
|
73 | - { |
|
74 | - if (! $this->available_spaces_calculator instanceof EventSpacesCalculator) { |
|
75 | - $this->available_spaces_calculator = new EventSpacesCalculator($this); |
|
76 | - } |
|
77 | - return $this->available_spaces_calculator; |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * Overrides parent set() method so that all calls to set( 'status', $status ) can be routed to internal methods |
|
83 | - * |
|
84 | - * @param string $field_name |
|
85 | - * @param mixed $field_value |
|
86 | - * @param bool $use_default |
|
87 | - * @throws EE_Error |
|
88 | - */ |
|
89 | - public function set($field_name, $field_value, $use_default = false) |
|
90 | - { |
|
91 | - switch ($field_name) { |
|
92 | - case 'status': |
|
93 | - $this->set_status($field_value, $use_default); |
|
94 | - break; |
|
95 | - default: |
|
96 | - parent::set($field_name, $field_value, $use_default); |
|
97 | - } |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * set_status |
|
103 | - * Checks if event status is being changed to SOLD OUT |
|
104 | - * and updates event meta data with previous event status |
|
105 | - * so that we can revert things if/when the event is no longer sold out |
|
106 | - * |
|
107 | - * @access public |
|
108 | - * @param string $new_status |
|
109 | - * @param bool $use_default |
|
110 | - * @return void |
|
111 | - * @throws EE_Error |
|
112 | - */ |
|
113 | - public function set_status($new_status = null, $use_default = false) |
|
114 | - { |
|
115 | - // if nothing is set, and we aren't explicitly wanting to reset the status, then just leave |
|
116 | - if (empty($new_status) && ! $use_default) { |
|
117 | - return; |
|
118 | - } |
|
119 | - // get current Event status |
|
120 | - $old_status = $this->status(); |
|
121 | - // if status has changed |
|
122 | - if ($old_status !== $new_status) { |
|
123 | - // TO sold_out |
|
124 | - if ($new_status === EEM_Event::sold_out) { |
|
125 | - // save the previous event status so that we can revert if the event is no longer sold out |
|
126 | - $this->add_post_meta('_previous_event_status', $old_status); |
|
127 | - do_action('AHEE__EE_Event__set_status__to_sold_out', $this, $old_status, $new_status); |
|
128 | - // OR FROM sold_out |
|
129 | - } elseif ($old_status === EEM_Event::sold_out) { |
|
130 | - $this->delete_post_meta('_previous_event_status'); |
|
131 | - do_action('AHEE__EE_Event__set_status__from_sold_out', $this, $old_status, $new_status); |
|
132 | - } |
|
133 | - // clear out the active status so that it gets reset the next time it is requested |
|
134 | - $this->_active_status = null; |
|
135 | - // update status |
|
136 | - parent::set('status', $new_status, $use_default); |
|
137 | - do_action('AHEE__EE_Event__set_status__after_update', $this); |
|
138 | - return; |
|
139 | - } |
|
140 | - // even though the old value matches the new value, it's still good to |
|
141 | - // allow the parent set method to have a say |
|
142 | - parent::set('status', $new_status, $use_default); |
|
143 | - } |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * Gets all the datetimes for this event |
|
148 | - * |
|
149 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
150 | - * @return EE_Base_Class[]|EE_Datetime[] |
|
151 | - * @throws EE_Error |
|
152 | - */ |
|
153 | - public function datetimes($query_params = array()) |
|
154 | - { |
|
155 | - return $this->get_many_related('Datetime', $query_params); |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * Gets all the datetimes for this event, ordered by DTT_EVT_start in ascending order |
|
161 | - * |
|
162 | - * @return EE_Base_Class[]|EE_Datetime[] |
|
163 | - * @throws EE_Error |
|
164 | - */ |
|
165 | - public function datetimes_in_chronological_order() |
|
166 | - { |
|
167 | - return $this->get_many_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC'))); |
|
168 | - } |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * Gets all the datetimes for this event, ordered by the DTT_order on the datetime. |
|
173 | - * @darren, we should probably UNSET timezone on the EEM_Datetime model |
|
174 | - * after running our query, so that this timezone isn't set for EVERY query |
|
175 | - * on EEM_Datetime for the rest of the request, no? |
|
176 | - * |
|
177 | - * @param boolean $show_expired whether or not to include expired events |
|
178 | - * @param boolean $show_deleted whether or not to include deleted events |
|
179 | - * @param null $limit |
|
180 | - * @return EE_Datetime[] |
|
181 | - * @throws EE_Error |
|
182 | - */ |
|
183 | - public function datetimes_ordered($show_expired = true, $show_deleted = false, $limit = null) |
|
184 | - { |
|
185 | - return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_event_ordered_by_DTT_order( |
|
186 | - $this->ID(), |
|
187 | - $show_expired, |
|
188 | - $show_deleted, |
|
189 | - $limit |
|
190 | - ); |
|
191 | - } |
|
192 | - |
|
193 | - |
|
194 | - /** |
|
195 | - * Returns one related datetime. Mostly only used by some legacy code. |
|
196 | - * |
|
197 | - * @return EE_Base_Class|EE_Datetime |
|
198 | - * @throws EE_Error |
|
199 | - */ |
|
200 | - public function first_datetime() |
|
201 | - { |
|
202 | - return $this->get_first_related('Datetime'); |
|
203 | - } |
|
204 | - |
|
205 | - |
|
206 | - /** |
|
207 | - * Returns the 'primary' datetime for the event |
|
208 | - * |
|
209 | - * @param bool $try_to_exclude_expired |
|
210 | - * @param bool $try_to_exclude_deleted |
|
211 | - * @return EE_Datetime |
|
212 | - * @throws EE_Error |
|
213 | - */ |
|
214 | - public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true) |
|
215 | - { |
|
216 | - if (! empty($this->_Primary_Datetime)) { |
|
217 | - return $this->_Primary_Datetime; |
|
218 | - } |
|
219 | - $this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)->get_primary_datetime_for_event( |
|
220 | - $this->ID(), |
|
221 | - $try_to_exclude_expired, |
|
222 | - $try_to_exclude_deleted |
|
223 | - ); |
|
224 | - return $this->_Primary_Datetime; |
|
225 | - } |
|
226 | - |
|
227 | - |
|
228 | - /** |
|
229 | - * Gets all the tickets available for purchase of this event |
|
230 | - * |
|
231 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
232 | - * @return EE_Base_Class[]|EE_Ticket[] |
|
233 | - * @throws EE_Error |
|
234 | - */ |
|
235 | - public function tickets($query_params = array()) |
|
236 | - { |
|
237 | - // first get all datetimes |
|
238 | - $datetimes = $this->datetimes_ordered(); |
|
239 | - if (! $datetimes) { |
|
240 | - return array(); |
|
241 | - } |
|
242 | - $datetime_ids = array(); |
|
243 | - foreach ($datetimes as $datetime) { |
|
244 | - $datetime_ids[] = $datetime->ID(); |
|
245 | - } |
|
246 | - $where_params = array('Datetime.DTT_ID' => array('IN', $datetime_ids)); |
|
247 | - // if incoming $query_params has where conditions let's merge but not override existing. |
|
248 | - if (is_array($query_params) && isset($query_params[0])) { |
|
249 | - $where_params = array_merge($query_params[0], $where_params); |
|
250 | - unset($query_params[0]); |
|
251 | - } |
|
252 | - // now add $where_params to $query_params |
|
253 | - $query_params[0] = $where_params; |
|
254 | - return EEM_Ticket::instance()->get_all($query_params); |
|
255 | - } |
|
256 | - |
|
257 | - |
|
258 | - /** |
|
259 | - * get all unexpired untrashed tickets |
|
260 | - * |
|
261 | - * @return EE_Ticket[] |
|
262 | - * @throws EE_Error |
|
263 | - */ |
|
264 | - public function active_tickets() |
|
265 | - { |
|
266 | - return $this->tickets( |
|
267 | - array( |
|
268 | - array( |
|
269 | - 'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')), |
|
270 | - 'TKT_deleted' => false, |
|
271 | - ), |
|
272 | - ) |
|
273 | - ); |
|
274 | - } |
|
275 | - |
|
276 | - |
|
277 | - /** |
|
278 | - * @return bool |
|
279 | - * @throws EE_Error |
|
280 | - */ |
|
281 | - public function additional_limit() |
|
282 | - { |
|
283 | - return $this->get('EVT_additional_limit'); |
|
284 | - } |
|
285 | - |
|
286 | - |
|
287 | - /** |
|
288 | - * @return bool |
|
289 | - * @throws EE_Error |
|
290 | - */ |
|
291 | - public function allow_overflow() |
|
292 | - { |
|
293 | - return $this->get('EVT_allow_overflow'); |
|
294 | - } |
|
295 | - |
|
296 | - |
|
297 | - /** |
|
298 | - * @return bool |
|
299 | - * @throws EE_Error |
|
300 | - */ |
|
301 | - public function created() |
|
302 | - { |
|
303 | - return $this->get('EVT_created'); |
|
304 | - } |
|
305 | - |
|
306 | - |
|
307 | - /** |
|
308 | - * @return bool |
|
309 | - * @throws EE_Error |
|
310 | - */ |
|
311 | - public function description() |
|
312 | - { |
|
313 | - return $this->get('EVT_desc'); |
|
314 | - } |
|
315 | - |
|
316 | - |
|
317 | - /** |
|
318 | - * Runs do_shortcode and wpautop on the description |
|
319 | - * |
|
320 | - * @return string of html |
|
321 | - * @throws EE_Error |
|
322 | - */ |
|
323 | - public function description_filtered() |
|
324 | - { |
|
325 | - return $this->get_pretty('EVT_desc'); |
|
326 | - } |
|
327 | - |
|
328 | - |
|
329 | - /** |
|
330 | - * @return bool |
|
331 | - * @throws EE_Error |
|
332 | - */ |
|
333 | - public function display_description() |
|
334 | - { |
|
335 | - return $this->get('EVT_display_desc'); |
|
336 | - } |
|
337 | - |
|
338 | - |
|
339 | - /** |
|
340 | - * @return bool |
|
341 | - * @throws EE_Error |
|
342 | - */ |
|
343 | - public function display_ticket_selector() |
|
344 | - { |
|
345 | - return (bool) $this->get('EVT_display_ticket_selector'); |
|
346 | - } |
|
347 | - |
|
348 | - |
|
349 | - /** |
|
350 | - * @return bool |
|
351 | - * @throws EE_Error |
|
352 | - */ |
|
353 | - public function external_url() |
|
354 | - { |
|
355 | - return $this->get('EVT_external_URL'); |
|
356 | - } |
|
357 | - |
|
358 | - |
|
359 | - /** |
|
360 | - * @return bool |
|
361 | - * @throws EE_Error |
|
362 | - */ |
|
363 | - public function member_only() |
|
364 | - { |
|
365 | - return $this->get('EVT_member_only'); |
|
366 | - } |
|
367 | - |
|
368 | - |
|
369 | - /** |
|
370 | - * @return bool |
|
371 | - * @throws EE_Error |
|
372 | - */ |
|
373 | - public function phone() |
|
374 | - { |
|
375 | - return $this->get('EVT_phone'); |
|
376 | - } |
|
377 | - |
|
378 | - |
|
379 | - /** |
|
380 | - * @return bool |
|
381 | - * @throws EE_Error |
|
382 | - */ |
|
383 | - public function modified() |
|
384 | - { |
|
385 | - return $this->get('EVT_modified'); |
|
386 | - } |
|
387 | - |
|
388 | - |
|
389 | - /** |
|
390 | - * @return bool |
|
391 | - * @throws EE_Error |
|
392 | - */ |
|
393 | - public function name() |
|
394 | - { |
|
395 | - return $this->get('EVT_name'); |
|
396 | - } |
|
397 | - |
|
398 | - |
|
399 | - /** |
|
400 | - * @return bool |
|
401 | - * @throws EE_Error |
|
402 | - */ |
|
403 | - public function order() |
|
404 | - { |
|
405 | - return $this->get('EVT_order'); |
|
406 | - } |
|
407 | - |
|
408 | - |
|
409 | - /** |
|
410 | - * @return bool|string |
|
411 | - * @throws EE_Error |
|
412 | - */ |
|
413 | - public function default_registration_status() |
|
414 | - { |
|
415 | - $event_default_registration_status = $this->get('EVT_default_registration_status'); |
|
416 | - return ! empty($event_default_registration_status) |
|
417 | - ? $event_default_registration_status |
|
418 | - : EE_Registry::instance()->CFG->registration->default_STS_ID; |
|
419 | - } |
|
420 | - |
|
421 | - |
|
422 | - /** |
|
423 | - * @param int $num_words |
|
424 | - * @param null $more |
|
425 | - * @param bool $not_full_desc |
|
426 | - * @return bool|string |
|
427 | - * @throws EE_Error |
|
428 | - */ |
|
429 | - public function short_description($num_words = 55, $more = null, $not_full_desc = false) |
|
430 | - { |
|
431 | - $short_desc = $this->get('EVT_short_desc'); |
|
432 | - if (! empty($short_desc) || $not_full_desc) { |
|
433 | - return $short_desc; |
|
434 | - } |
|
435 | - $full_desc = $this->get('EVT_desc'); |
|
436 | - return wp_trim_words($full_desc, $num_words, $more); |
|
437 | - } |
|
438 | - |
|
439 | - |
|
440 | - /** |
|
441 | - * @return bool |
|
442 | - * @throws EE_Error |
|
443 | - */ |
|
444 | - public function slug() |
|
445 | - { |
|
446 | - return $this->get('EVT_slug'); |
|
447 | - } |
|
448 | - |
|
449 | - |
|
450 | - /** |
|
451 | - * @return bool |
|
452 | - * @throws EE_Error |
|
453 | - */ |
|
454 | - public function timezone_string() |
|
455 | - { |
|
456 | - return $this->get('EVT_timezone_string'); |
|
457 | - } |
|
458 | - |
|
459 | - |
|
460 | - /** |
|
461 | - * @return bool |
|
462 | - * @throws EE_Error |
|
463 | - */ |
|
464 | - public function visible_on() |
|
465 | - { |
|
466 | - return $this->get('EVT_visible_on'); |
|
467 | - } |
|
468 | - |
|
469 | - |
|
470 | - /** |
|
471 | - * @return int |
|
472 | - * @throws EE_Error |
|
473 | - */ |
|
474 | - public function wp_user() |
|
475 | - { |
|
476 | - return $this->get('EVT_wp_user'); |
|
477 | - } |
|
478 | - |
|
479 | - |
|
480 | - /** |
|
481 | - * @return bool |
|
482 | - * @throws EE_Error |
|
483 | - */ |
|
484 | - public function donations() |
|
485 | - { |
|
486 | - return $this->get('EVT_donations'); |
|
487 | - } |
|
488 | - |
|
489 | - |
|
490 | - /** |
|
491 | - * @param $limit |
|
492 | - * @throws EE_Error |
|
493 | - */ |
|
494 | - public function set_additional_limit($limit) |
|
495 | - { |
|
496 | - $this->set('EVT_additional_limit', $limit); |
|
497 | - } |
|
498 | - |
|
499 | - |
|
500 | - /** |
|
501 | - * @param $created |
|
502 | - * @throws EE_Error |
|
503 | - */ |
|
504 | - public function set_created($created) |
|
505 | - { |
|
506 | - $this->set('EVT_created', $created); |
|
507 | - } |
|
508 | - |
|
509 | - |
|
510 | - /** |
|
511 | - * @param $desc |
|
512 | - * @throws EE_Error |
|
513 | - */ |
|
514 | - public function set_description($desc) |
|
515 | - { |
|
516 | - $this->set('EVT_desc', $desc); |
|
517 | - } |
|
518 | - |
|
519 | - |
|
520 | - /** |
|
521 | - * @param $display_desc |
|
522 | - * @throws EE_Error |
|
523 | - */ |
|
524 | - public function set_display_description($display_desc) |
|
525 | - { |
|
526 | - $this->set('EVT_display_desc', $display_desc); |
|
527 | - } |
|
528 | - |
|
529 | - |
|
530 | - /** |
|
531 | - * @param $display_ticket_selector |
|
532 | - * @throws EE_Error |
|
533 | - */ |
|
534 | - public function set_display_ticket_selector($display_ticket_selector) |
|
535 | - { |
|
536 | - $this->set('EVT_display_ticket_selector', $display_ticket_selector); |
|
537 | - } |
|
538 | - |
|
539 | - |
|
540 | - /** |
|
541 | - * @param $external_url |
|
542 | - * @throws EE_Error |
|
543 | - */ |
|
544 | - public function set_external_url($external_url) |
|
545 | - { |
|
546 | - $this->set('EVT_external_URL', $external_url); |
|
547 | - } |
|
548 | - |
|
549 | - |
|
550 | - /** |
|
551 | - * @param $member_only |
|
552 | - * @throws EE_Error |
|
553 | - */ |
|
554 | - public function set_member_only($member_only) |
|
555 | - { |
|
556 | - $this->set('EVT_member_only', $member_only); |
|
557 | - } |
|
558 | - |
|
559 | - |
|
560 | - /** |
|
561 | - * @param $event_phone |
|
562 | - * @throws EE_Error |
|
563 | - */ |
|
564 | - public function set_event_phone($event_phone) |
|
565 | - { |
|
566 | - $this->set('EVT_phone', $event_phone); |
|
567 | - } |
|
568 | - |
|
569 | - |
|
570 | - /** |
|
571 | - * @param $modified |
|
572 | - * @throws EE_Error |
|
573 | - */ |
|
574 | - public function set_modified($modified) |
|
575 | - { |
|
576 | - $this->set('EVT_modified', $modified); |
|
577 | - } |
|
578 | - |
|
579 | - |
|
580 | - /** |
|
581 | - * @param $name |
|
582 | - * @throws EE_Error |
|
583 | - */ |
|
584 | - public function set_name($name) |
|
585 | - { |
|
586 | - $this->set('EVT_name', $name); |
|
587 | - } |
|
588 | - |
|
589 | - |
|
590 | - /** |
|
591 | - * @param $order |
|
592 | - * @throws EE_Error |
|
593 | - */ |
|
594 | - public function set_order($order) |
|
595 | - { |
|
596 | - $this->set('EVT_order', $order); |
|
597 | - } |
|
598 | - |
|
599 | - |
|
600 | - /** |
|
601 | - * @param $short_desc |
|
602 | - * @throws EE_Error |
|
603 | - */ |
|
604 | - public function set_short_description($short_desc) |
|
605 | - { |
|
606 | - $this->set('EVT_short_desc', $short_desc); |
|
607 | - } |
|
608 | - |
|
609 | - |
|
610 | - /** |
|
611 | - * @param $slug |
|
612 | - * @throws EE_Error |
|
613 | - */ |
|
614 | - public function set_slug($slug) |
|
615 | - { |
|
616 | - $this->set('EVT_slug', $slug); |
|
617 | - } |
|
618 | - |
|
619 | - |
|
620 | - /** |
|
621 | - * @param $timezone_string |
|
622 | - * @throws EE_Error |
|
623 | - */ |
|
624 | - public function set_timezone_string($timezone_string) |
|
625 | - { |
|
626 | - $this->set('EVT_timezone_string', $timezone_string); |
|
627 | - } |
|
628 | - |
|
629 | - |
|
630 | - /** |
|
631 | - * @param $visible_on |
|
632 | - * @throws EE_Error |
|
633 | - */ |
|
634 | - public function set_visible_on($visible_on) |
|
635 | - { |
|
636 | - $this->set('EVT_visible_on', $visible_on); |
|
637 | - } |
|
638 | - |
|
639 | - |
|
640 | - /** |
|
641 | - * @param $wp_user |
|
642 | - * @throws EE_Error |
|
643 | - */ |
|
644 | - public function set_wp_user($wp_user) |
|
645 | - { |
|
646 | - $this->set('EVT_wp_user', $wp_user); |
|
647 | - } |
|
648 | - |
|
649 | - |
|
650 | - /** |
|
651 | - * @param $default_registration_status |
|
652 | - * @throws EE_Error |
|
653 | - */ |
|
654 | - public function set_default_registration_status($default_registration_status) |
|
655 | - { |
|
656 | - $this->set('EVT_default_registration_status', $default_registration_status); |
|
657 | - } |
|
658 | - |
|
659 | - |
|
660 | - /** |
|
661 | - * @param $donations |
|
662 | - * @throws EE_Error |
|
663 | - */ |
|
664 | - public function set_donations($donations) |
|
665 | - { |
|
666 | - $this->set('EVT_donations', $donations); |
|
667 | - } |
|
668 | - |
|
669 | - |
|
670 | - /** |
|
671 | - * Adds a venue to this event |
|
672 | - * |
|
673 | - * @param EE_Venue /int $venue_id_or_obj |
|
674 | - * @return EE_Base_Class|EE_Venue |
|
675 | - * @throws EE_Error |
|
676 | - */ |
|
677 | - public function add_venue($venue_id_or_obj) |
|
678 | - { |
|
679 | - return $this->_add_relation_to($venue_id_or_obj, 'Venue'); |
|
680 | - } |
|
681 | - |
|
682 | - |
|
683 | - /** |
|
684 | - * Removes a venue from the event |
|
685 | - * |
|
686 | - * @param EE_Venue /int $venue_id_or_obj |
|
687 | - * @return EE_Base_Class|EE_Venue |
|
688 | - * @throws EE_Error |
|
689 | - */ |
|
690 | - public function remove_venue($venue_id_or_obj) |
|
691 | - { |
|
692 | - return $this->_remove_relation_to($venue_id_or_obj, 'Venue'); |
|
693 | - } |
|
694 | - |
|
695 | - |
|
696 | - /** |
|
697 | - * Gets all the venues related ot the event. May provide additional $query_params if desired |
|
698 | - * |
|
699 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
700 | - * @return EE_Base_Class[]|EE_Venue[] |
|
701 | - * @throws EE_Error |
|
702 | - */ |
|
703 | - public function venues($query_params = array()) |
|
704 | - { |
|
705 | - return $this->get_many_related('Venue', $query_params); |
|
706 | - } |
|
707 | - |
|
708 | - |
|
709 | - /** |
|
710 | - * check if event id is present and if event is published |
|
711 | - * |
|
712 | - * @access public |
|
713 | - * @return boolean true yes, false no |
|
714 | - * @throws EE_Error |
|
715 | - */ |
|
716 | - private function _has_ID_and_is_published() |
|
717 | - { |
|
718 | - // first check if event id is present and not NULL, |
|
719 | - // then check if this event is published (or any of the equivalent "published" statuses) |
|
720 | - return |
|
721 | - $this->ID() && $this->ID() !== null |
|
722 | - && ( |
|
723 | - $this->status() === 'publish' |
|
724 | - || $this->status() === EEM_Event::sold_out |
|
725 | - || $this->status() === EEM_Event::postponed |
|
726 | - || $this->status() === EEM_Event::cancelled |
|
727 | - ); |
|
728 | - } |
|
729 | - |
|
730 | - |
|
731 | - /** |
|
732 | - * This simply compares the internal dates with NOW and determines if the event is upcoming or not. |
|
733 | - * |
|
734 | - * @access public |
|
735 | - * @return boolean true yes, false no |
|
736 | - * @throws EE_Error |
|
737 | - */ |
|
738 | - public function is_upcoming() |
|
739 | - { |
|
740 | - // check if event id is present and if this event is published |
|
741 | - if ($this->is_inactive()) { |
|
742 | - return false; |
|
743 | - } |
|
744 | - // set initial value |
|
745 | - $upcoming = false; |
|
746 | - // next let's get all datetimes and loop through them |
|
747 | - $datetimes = $this->datetimes_in_chronological_order(); |
|
748 | - foreach ($datetimes as $datetime) { |
|
749 | - if ($datetime instanceof EE_Datetime) { |
|
750 | - // if this dtt is expired then we continue cause one of the other datetimes might be upcoming. |
|
751 | - if ($datetime->is_expired()) { |
|
752 | - continue; |
|
753 | - } |
|
754 | - // if this dtt is active then we return false. |
|
755 | - if ($datetime->is_active()) { |
|
756 | - return false; |
|
757 | - } |
|
758 | - // otherwise let's check upcoming status |
|
759 | - $upcoming = $datetime->is_upcoming(); |
|
760 | - } |
|
761 | - } |
|
762 | - return $upcoming; |
|
763 | - } |
|
764 | - |
|
765 | - |
|
766 | - /** |
|
767 | - * @return bool |
|
768 | - * @throws EE_Error |
|
769 | - */ |
|
770 | - public function is_active() |
|
771 | - { |
|
772 | - // check if event id is present and if this event is published |
|
773 | - if ($this->is_inactive()) { |
|
774 | - return false; |
|
775 | - } |
|
776 | - // set initial value |
|
777 | - $active = false; |
|
778 | - // next let's get all datetimes and loop through them |
|
779 | - $datetimes = $this->datetimes_in_chronological_order(); |
|
780 | - foreach ($datetimes as $datetime) { |
|
781 | - if ($datetime instanceof EE_Datetime) { |
|
782 | - // if this dtt is expired then we continue cause one of the other datetimes might be active. |
|
783 | - if ($datetime->is_expired()) { |
|
784 | - continue; |
|
785 | - } |
|
786 | - // if this dtt is upcoming then we return false. |
|
787 | - if ($datetime->is_upcoming()) { |
|
788 | - return false; |
|
789 | - } |
|
790 | - // otherwise let's check active status |
|
791 | - $active = $datetime->is_active(); |
|
792 | - } |
|
793 | - } |
|
794 | - return $active; |
|
795 | - } |
|
796 | - |
|
797 | - |
|
798 | - /** |
|
799 | - * @return bool |
|
800 | - * @throws EE_Error |
|
801 | - */ |
|
802 | - public function is_expired() |
|
803 | - { |
|
804 | - // check if event id is present and if this event is published |
|
805 | - if ($this->is_inactive()) { |
|
806 | - return false; |
|
807 | - } |
|
808 | - // set initial value |
|
809 | - $expired = false; |
|
810 | - // first let's get all datetimes and loop through them |
|
811 | - $datetimes = $this->datetimes_in_chronological_order(); |
|
812 | - foreach ($datetimes as $datetime) { |
|
813 | - if ($datetime instanceof EE_Datetime) { |
|
814 | - // if this dtt is upcoming or active then we return false. |
|
815 | - if ($datetime->is_upcoming() || $datetime->is_active()) { |
|
816 | - return false; |
|
817 | - } |
|
818 | - // otherwise let's check active status |
|
819 | - $expired = $datetime->is_expired(); |
|
820 | - } |
|
821 | - } |
|
822 | - return $expired; |
|
823 | - } |
|
824 | - |
|
825 | - |
|
826 | - /** |
|
827 | - * @return bool |
|
828 | - * @throws EE_Error |
|
829 | - */ |
|
830 | - public function is_inactive() |
|
831 | - { |
|
832 | - // check if event id is present and if this event is published |
|
833 | - if ($this->_has_ID_and_is_published()) { |
|
834 | - return false; |
|
835 | - } |
|
836 | - return true; |
|
837 | - } |
|
838 | - |
|
839 | - |
|
840 | - /** |
|
841 | - * calculate spaces remaining based on "saleable" tickets |
|
842 | - * |
|
843 | - * @param array $tickets |
|
844 | - * @param bool $filtered |
|
845 | - * @return int|float |
|
846 | - * @throws EE_Error |
|
847 | - * @throws DomainException |
|
848 | - * @throws UnexpectedEntityException |
|
849 | - */ |
|
850 | - public function spaces_remaining($tickets = array(), $filtered = true) |
|
851 | - { |
|
852 | - $this->getAvailableSpacesCalculator()->setActiveTickets($tickets); |
|
853 | - $spaces_remaining = $this->getAvailableSpacesCalculator()->spacesRemaining(); |
|
854 | - return $filtered |
|
855 | - ? apply_filters( |
|
856 | - 'FHEE_EE_Event__spaces_remaining', |
|
857 | - $spaces_remaining, |
|
858 | - $this, |
|
859 | - $tickets |
|
860 | - ) |
|
861 | - : $spaces_remaining; |
|
862 | - } |
|
863 | - |
|
864 | - |
|
865 | - /** |
|
866 | - * perform_sold_out_status_check |
|
867 | - * checks all of this events's datetime reg_limit - sold values to determine if ANY datetimes have spaces |
|
868 | - * available... if NOT, then the event status will get toggled to 'sold_out' |
|
869 | - * |
|
870 | - * @return bool return the ACTUAL sold out state. |
|
871 | - * @throws EE_Error |
|
872 | - * @throws DomainException |
|
873 | - * @throws UnexpectedEntityException |
|
874 | - */ |
|
875 | - public function perform_sold_out_status_check() |
|
876 | - { |
|
877 | - // get all tickets |
|
878 | - $tickets = $this->tickets( |
|
879 | - array( |
|
880 | - 'default_where_conditions' => 'none', |
|
881 | - 'order_by' => array('TKT_qty' => 'ASC'), |
|
882 | - ) |
|
883 | - ); |
|
884 | - $all_expired = true; |
|
885 | - foreach ($tickets as $ticket) { |
|
886 | - if (! $ticket->is_expired()) { |
|
887 | - $all_expired = false; |
|
888 | - break; |
|
889 | - } |
|
890 | - } |
|
891 | - // if all the tickets are just expired, then don't update the event status to sold out |
|
892 | - if ($all_expired) { |
|
893 | - return true; |
|
894 | - } |
|
895 | - $spaces_remaining = $this->spaces_remaining($tickets); |
|
896 | - if ($spaces_remaining < 1) { |
|
897 | - if ($this->status() !== EEM_Event::post_status_private) { |
|
898 | - $this->set_status(EEM_Event::sold_out); |
|
899 | - $this->save(); |
|
900 | - } |
|
901 | - $sold_out = true; |
|
902 | - } else { |
|
903 | - $sold_out = false; |
|
904 | - // was event previously marked as sold out ? |
|
905 | - if ($this->status() === EEM_Event::sold_out) { |
|
906 | - // revert status to previous value, if it was set |
|
907 | - $previous_event_status = $this->get_post_meta('_previous_event_status', true); |
|
908 | - if ($previous_event_status) { |
|
909 | - $this->set_status($previous_event_status); |
|
910 | - $this->save(); |
|
911 | - } |
|
912 | - } |
|
913 | - } |
|
914 | - do_action('AHEE__EE_Event__perform_sold_out_status_check__end', $this, $sold_out, $spaces_remaining, $tickets); |
|
915 | - return $sold_out; |
|
916 | - } |
|
917 | - |
|
918 | - |
|
919 | - /** |
|
920 | - * This returns the total remaining spaces for sale on this event. |
|
921 | - * |
|
922 | - * @uses EE_Event::total_available_spaces() |
|
923 | - * @return float|int |
|
924 | - * @throws EE_Error |
|
925 | - * @throws DomainException |
|
926 | - * @throws UnexpectedEntityException |
|
927 | - */ |
|
928 | - public function spaces_remaining_for_sale() |
|
929 | - { |
|
930 | - return $this->total_available_spaces(true); |
|
931 | - } |
|
932 | - |
|
933 | - |
|
934 | - /** |
|
935 | - * This returns the total spaces available for an event |
|
936 | - * while considering all the qtys on the tickets and the reg limits |
|
937 | - * on the datetimes attached to this event. |
|
938 | - * |
|
939 | - * @param bool $consider_sold Whether to consider any tickets that have already sold in our calculation. |
|
940 | - * If this is false, then we return the most tickets that could ever be sold |
|
941 | - * for this event with the datetime and tickets setup on the event under optimal |
|
942 | - * selling conditions. Otherwise we return a live calculation of spaces available |
|
943 | - * based on tickets sold. Depending on setup and stage of sales, this |
|
944 | - * may appear to equal remaining tickets. However, the more tickets are |
|
945 | - * sold out, the more accurate the "live" total is. |
|
946 | - * @return float|int |
|
947 | - * @throws EE_Error |
|
948 | - * @throws DomainException |
|
949 | - * @throws UnexpectedEntityException |
|
950 | - */ |
|
951 | - public function total_available_spaces($consider_sold = false) |
|
952 | - { |
|
953 | - $spaces_available = $consider_sold |
|
954 | - ? $this->getAvailableSpacesCalculator()->spacesRemaining() |
|
955 | - : $this->getAvailableSpacesCalculator()->totalSpacesAvailable(); |
|
956 | - return apply_filters( |
|
957 | - 'FHEE_EE_Event__total_available_spaces__spaces_available', |
|
958 | - $spaces_available, |
|
959 | - $this, |
|
960 | - $this->getAvailableSpacesCalculator()->getDatetimes(), |
|
961 | - $this->getAvailableSpacesCalculator()->getActiveTickets() |
|
962 | - ); |
|
963 | - } |
|
964 | - |
|
965 | - |
|
966 | - /** |
|
967 | - * Checks if the event is set to sold out |
|
968 | - * |
|
969 | - * @param bool $actual whether or not to perform calculations to not only figure the |
|
970 | - * actual status but also to flip the status if necessary to sold |
|
971 | - * out If false, we just check the existing status of the event |
|
972 | - * @return boolean |
|
973 | - * @throws EE_Error |
|
974 | - */ |
|
975 | - public function is_sold_out($actual = false) |
|
976 | - { |
|
977 | - if (! $actual) { |
|
978 | - return $this->status() === EEM_Event::sold_out; |
|
979 | - } |
|
980 | - return $this->perform_sold_out_status_check(); |
|
981 | - } |
|
982 | - |
|
983 | - |
|
984 | - /** |
|
985 | - * Checks if the event is marked as postponed |
|
986 | - * |
|
987 | - * @return boolean |
|
988 | - */ |
|
989 | - public function is_postponed() |
|
990 | - { |
|
991 | - return $this->status() === EEM_Event::postponed; |
|
992 | - } |
|
993 | - |
|
994 | - |
|
995 | - /** |
|
996 | - * Checks if the event is marked as cancelled |
|
997 | - * |
|
998 | - * @return boolean |
|
999 | - */ |
|
1000 | - public function is_cancelled() |
|
1001 | - { |
|
1002 | - return $this->status() === EEM_Event::cancelled; |
|
1003 | - } |
|
1004 | - |
|
1005 | - |
|
1006 | - /** |
|
1007 | - * Get the logical active status in a hierarchical order for all the datetimes. Note |
|
1008 | - * Basically, we order the datetimes by EVT_start_date. Then first test on whether the event is published. If its |
|
1009 | - * NOT published then we test for whether its expired or not. IF it IS published then we test first on whether an |
|
1010 | - * event has any active dates. If no active dates then we check for any upcoming dates. If no upcoming dates then |
|
1011 | - * the event is considered expired. |
|
1012 | - * NOTE: this method does NOT calculate whether the datetimes are sold out when event is published. Sold Out is a |
|
1013 | - * status set on the EVENT when it is not published and thus is done |
|
1014 | - * |
|
1015 | - * @param bool $reset |
|
1016 | - * @return bool | string - based on EE_Datetime active constants or FALSE if error. |
|
1017 | - * @throws EE_Error |
|
1018 | - */ |
|
1019 | - public function get_active_status($reset = false) |
|
1020 | - { |
|
1021 | - // if the active status has already been set, then just use that value (unless we are resetting it) |
|
1022 | - if (! empty($this->_active_status) && ! $reset) { |
|
1023 | - return $this->_active_status; |
|
1024 | - } |
|
1025 | - // first check if event id is present on this object |
|
1026 | - if (! $this->ID()) { |
|
1027 | - return false; |
|
1028 | - } |
|
1029 | - $where_params_for_event = array(array('EVT_ID' => $this->ID())); |
|
1030 | - // if event is published: |
|
1031 | - if ($this->status() === EEM_Event::post_status_publish || $this->status() === EEM_Event::post_status_private) { |
|
1032 | - // active? |
|
1033 | - if (EEM_Datetime::instance()->get_datetime_count_for_status( |
|
1034 | - EE_Datetime::active, |
|
1035 | - $where_params_for_event |
|
1036 | - ) > 0) { |
|
1037 | - $this->_active_status = EE_Datetime::active; |
|
1038 | - } else { |
|
1039 | - // upcoming? |
|
1040 | - if (EEM_Datetime::instance()->get_datetime_count_for_status( |
|
1041 | - EE_Datetime::upcoming, |
|
1042 | - $where_params_for_event |
|
1043 | - ) > 0) { |
|
1044 | - $this->_active_status = EE_Datetime::upcoming; |
|
1045 | - } else { |
|
1046 | - // expired? |
|
1047 | - if (EEM_Datetime::instance()->get_datetime_count_for_status( |
|
1048 | - EE_Datetime::expired, |
|
1049 | - $where_params_for_event |
|
1050 | - ) > 0 |
|
1051 | - ) { |
|
1052 | - $this->_active_status = EE_Datetime::expired; |
|
1053 | - } else { |
|
1054 | - // it would be odd if things make it this far because it basically means there are no datetime's |
|
1055 | - // attached to the event. So in this case it will just be considered inactive. |
|
1056 | - $this->_active_status = EE_Datetime::inactive; |
|
1057 | - } |
|
1058 | - } |
|
1059 | - } |
|
1060 | - } else { |
|
1061 | - // the event is not published, so let's just set it's active status according to its' post status |
|
1062 | - switch ($this->status()) { |
|
1063 | - case EEM_Event::sold_out: |
|
1064 | - $this->_active_status = EE_Datetime::sold_out; |
|
1065 | - break; |
|
1066 | - case EEM_Event::cancelled: |
|
1067 | - $this->_active_status = EE_Datetime::cancelled; |
|
1068 | - break; |
|
1069 | - case EEM_Event::postponed: |
|
1070 | - $this->_active_status = EE_Datetime::postponed; |
|
1071 | - break; |
|
1072 | - default: |
|
1073 | - $this->_active_status = EE_Datetime::inactive; |
|
1074 | - } |
|
1075 | - } |
|
1076 | - return $this->_active_status; |
|
1077 | - } |
|
1078 | - |
|
1079 | - |
|
1080 | - /** |
|
1081 | - * pretty_active_status |
|
1082 | - * |
|
1083 | - * @access public |
|
1084 | - * @param boolean $echo whether to return (FALSE), or echo out the result (TRUE) |
|
1085 | - * @return mixed void|string |
|
1086 | - * @throws EE_Error |
|
1087 | - */ |
|
1088 | - public function pretty_active_status($echo = true) |
|
1089 | - { |
|
1090 | - $active_status = $this->get_active_status(); |
|
1091 | - $status = '<span class="ee-status event-active-status-' |
|
1092 | - . $active_status |
|
1093 | - . '">' |
|
1094 | - . EEH_Template::pretty_status($active_status, false, 'sentence') |
|
1095 | - . '</span>'; |
|
1096 | - if ($echo) { |
|
1097 | - echo $status; |
|
1098 | - return ''; |
|
1099 | - } |
|
1100 | - return $status; |
|
1101 | - } |
|
1102 | - |
|
1103 | - |
|
1104 | - /** |
|
1105 | - * @return bool|int |
|
1106 | - * @throws EE_Error |
|
1107 | - */ |
|
1108 | - public function get_number_of_tickets_sold() |
|
1109 | - { |
|
1110 | - $tkt_sold = 0; |
|
1111 | - if (! $this->ID()) { |
|
1112 | - return 0; |
|
1113 | - } |
|
1114 | - $datetimes = $this->datetimes(); |
|
1115 | - foreach ($datetimes as $datetime) { |
|
1116 | - if ($datetime instanceof EE_Datetime) { |
|
1117 | - $tkt_sold += $datetime->sold(); |
|
1118 | - } |
|
1119 | - } |
|
1120 | - return $tkt_sold; |
|
1121 | - } |
|
1122 | - |
|
1123 | - |
|
1124 | - /** |
|
1125 | - * This just returns a count of all the registrations for this event |
|
1126 | - * |
|
1127 | - * @access public |
|
1128 | - * @return int |
|
1129 | - * @throws EE_Error |
|
1130 | - */ |
|
1131 | - public function get_count_of_all_registrations() |
|
1132 | - { |
|
1133 | - return EEM_Event::instance()->count_related($this, 'Registration'); |
|
1134 | - } |
|
1135 | - |
|
1136 | - |
|
1137 | - /** |
|
1138 | - * This returns the ticket with the earliest start time that is |
|
1139 | - * available for this event (across all datetimes attached to the event) |
|
1140 | - * |
|
1141 | - * @return EE_Base_Class|EE_Ticket|null |
|
1142 | - * @throws EE_Error |
|
1143 | - */ |
|
1144 | - public function get_ticket_with_earliest_start_time() |
|
1145 | - { |
|
1146 | - $where['Datetime.EVT_ID'] = $this->ID(); |
|
1147 | - $query_params = array($where, 'order_by' => array('TKT_start_date' => 'ASC')); |
|
1148 | - return EE_Registry::instance()->load_model('Ticket')->get_one($query_params); |
|
1149 | - } |
|
1150 | - |
|
1151 | - |
|
1152 | - /** |
|
1153 | - * This returns the ticket with the latest end time that is available |
|
1154 | - * for this event (across all datetimes attached to the event) |
|
1155 | - * |
|
1156 | - * @return EE_Base_Class|EE_Ticket|null |
|
1157 | - * @throws EE_Error |
|
1158 | - */ |
|
1159 | - public function get_ticket_with_latest_end_time() |
|
1160 | - { |
|
1161 | - $where['Datetime.EVT_ID'] = $this->ID(); |
|
1162 | - $query_params = array($where, 'order_by' => array('TKT_end_date' => 'DESC')); |
|
1163 | - return EE_Registry::instance()->load_model('Ticket')->get_one($query_params); |
|
1164 | - } |
|
1165 | - |
|
1166 | - |
|
1167 | - /** |
|
1168 | - * This returns the number of different ticket types currently on sale for this event. |
|
1169 | - * |
|
1170 | - * @return int |
|
1171 | - * @throws EE_Error |
|
1172 | - */ |
|
1173 | - public function countTicketsOnSale() |
|
1174 | - { |
|
1175 | - $where = array( |
|
1176 | - 'Datetime.EVT_ID' => $this->ID(), |
|
1177 | - 'TKT_start_date' => array('<', time()), |
|
1178 | - 'TKT_end_date' => array('>', time()), |
|
1179 | - ); |
|
1180 | - return EEM_Ticket::instance()->count(array($where)); |
|
1181 | - } |
|
1182 | - |
|
1183 | - |
|
1184 | - /** |
|
1185 | - * This returns whether there are any tickets on sale for this event. |
|
1186 | - * |
|
1187 | - * @return bool true = YES tickets on sale. |
|
1188 | - * @throws EE_Error |
|
1189 | - */ |
|
1190 | - public function tickets_on_sale() |
|
1191 | - { |
|
1192 | - return $this->countTicketsOnSale() > 0; |
|
1193 | - } |
|
1194 | - |
|
1195 | - |
|
1196 | - /** |
|
1197 | - * Gets the URL for viewing this event on the front-end. Overrides parent |
|
1198 | - * to check for an external URL first |
|
1199 | - * |
|
1200 | - * @return string |
|
1201 | - * @throws EE_Error |
|
1202 | - */ |
|
1203 | - public function get_permalink() |
|
1204 | - { |
|
1205 | - if ($this->external_url()) { |
|
1206 | - return $this->external_url(); |
|
1207 | - } |
|
1208 | - return parent::get_permalink(); |
|
1209 | - } |
|
1210 | - |
|
1211 | - |
|
1212 | - /** |
|
1213 | - * Gets the first term for 'espresso_event_categories' we can find |
|
1214 | - * |
|
1215 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
1216 | - * @return EE_Base_Class|EE_Term|null |
|
1217 | - * @throws EE_Error |
|
1218 | - */ |
|
1219 | - public function first_event_category($query_params = array()) |
|
1220 | - { |
|
1221 | - $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
1222 | - $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID(); |
|
1223 | - return EEM_Term::instance()->get_one($query_params); |
|
1224 | - } |
|
1225 | - |
|
1226 | - |
|
1227 | - /** |
|
1228 | - * Gets all terms for 'espresso_event_categories' we can find |
|
1229 | - * |
|
1230 | - * @param array $query_params |
|
1231 | - * @return EE_Base_Class[]|EE_Term[] |
|
1232 | - * @throws EE_Error |
|
1233 | - */ |
|
1234 | - public function get_all_event_categories($query_params = array()) |
|
1235 | - { |
|
1236 | - $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
1237 | - $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID(); |
|
1238 | - return EEM_Term::instance()->get_all($query_params); |
|
1239 | - } |
|
1240 | - |
|
1241 | - |
|
1242 | - /** |
|
1243 | - * Adds a question group to this event |
|
1244 | - * |
|
1245 | - * @param EE_Question_Group|int $question_group_id_or_obj |
|
1246 | - * @param bool $for_primary if true, the question group will be added for the primary |
|
1247 | - * registrant, if false will be added for others. default: false |
|
1248 | - * @return EE_Base_Class|EE_Question_Group |
|
1249 | - * @throws EE_Error |
|
1250 | - * @throws InvalidArgumentException |
|
1251 | - * @throws InvalidDataTypeException |
|
1252 | - * @throws InvalidInterfaceException |
|
1253 | - * @throws ReflectionException |
|
1254 | - */ |
|
1255 | - public function add_question_group($question_group_id_or_obj, $for_primary = false) |
|
1256 | - { |
|
1257 | - // If the row already exists, it will be updated. If it doesn't, it will be inserted. |
|
1258 | - // That's in EE_HABTM_Relation::add_relation_to(). |
|
1259 | - return $this->_add_relation_to( |
|
1260 | - $question_group_id_or_obj, |
|
1261 | - 'Question_Group', |
|
1262 | - [ |
|
1263 | - EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary) => true |
|
1264 | - ] |
|
1265 | - ); |
|
1266 | - } |
|
1267 | - |
|
1268 | - |
|
1269 | - /** |
|
1270 | - * Removes a question group from the event |
|
1271 | - * |
|
1272 | - * @param EE_Question_Group|int $question_group_id_or_obj |
|
1273 | - * @param bool $for_primary if true, the question group will be removed from the primary |
|
1274 | - * registrant, if false will be removed from others. default: false |
|
1275 | - * @return EE_Base_Class|EE_Question_Group |
|
1276 | - * @throws EE_Error |
|
1277 | - * @throws InvalidArgumentException |
|
1278 | - * @throws ReflectionException |
|
1279 | - * @throws InvalidDataTypeException |
|
1280 | - * @throws InvalidInterfaceException |
|
1281 | - */ |
|
1282 | - public function remove_question_group($question_group_id_or_obj, $for_primary = false) |
|
1283 | - { |
|
1284 | - // If the question group is used for the other type (primary or additional) |
|
1285 | - // then just update it. If not, delete it outright. |
|
1286 | - $existing_relation = $this->get_first_related( |
|
1287 | - 'Event_Question_Group', |
|
1288 | - [ |
|
1289 | - [ |
|
1290 | - 'QSG_ID' => EEM_Question_Group::instance()->ensure_is_ID($question_group_id_or_obj) |
|
1291 | - ] |
|
1292 | - ] |
|
1293 | - ); |
|
1294 | - $field_to_update = EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary); |
|
1295 | - $other_field = EEM_Event_Question_Group::instance()->fieldNameForContext(! $for_primary); |
|
1296 | - if ($existing_relation->get($other_field) === false) { |
|
1297 | - // Delete it. It's now no longer for primary or additional question groups. |
|
1298 | - return $this->_remove_relation_to($question_group_id_or_obj, 'Question_Group'); |
|
1299 | - } |
|
1300 | - // Just update it. They'll still use this question group for the other category |
|
1301 | - $existing_relation->save( |
|
1302 | - [ |
|
1303 | - $field_to_update => false |
|
1304 | - ] |
|
1305 | - ); |
|
1306 | - } |
|
1307 | - |
|
1308 | - |
|
1309 | - /** |
|
1310 | - * Gets all the question groups, ordering them by QSG_order ascending |
|
1311 | - * |
|
1312 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
1313 | - * @return EE_Base_Class[]|EE_Question_Group[] |
|
1314 | - * @throws EE_Error |
|
1315 | - */ |
|
1316 | - public function question_groups($query_params = array()) |
|
1317 | - { |
|
1318 | - $query_params = ! empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC')); |
|
1319 | - return $this->get_many_related('Question_Group', $query_params); |
|
1320 | - } |
|
1321 | - |
|
1322 | - |
|
1323 | - /** |
|
1324 | - * Implementation for EEI_Has_Icon interface method. |
|
1325 | - * |
|
1326 | - * @see EEI_Visual_Representation for comments |
|
1327 | - * @return string |
|
1328 | - */ |
|
1329 | - public function get_icon() |
|
1330 | - { |
|
1331 | - return '<span class="dashicons dashicons-flag"></span>'; |
|
1332 | - } |
|
1333 | - |
|
1334 | - |
|
1335 | - /** |
|
1336 | - * Implementation for EEI_Admin_Links interface method. |
|
1337 | - * |
|
1338 | - * @see EEI_Admin_Links for comments |
|
1339 | - * @return string |
|
1340 | - * @throws EE_Error |
|
1341 | - */ |
|
1342 | - public function get_admin_details_link() |
|
1343 | - { |
|
1344 | - return $this->get_admin_edit_link(); |
|
1345 | - } |
|
1346 | - |
|
1347 | - |
|
1348 | - /** |
|
1349 | - * Implementation for EEI_Admin_Links interface method. |
|
1350 | - * |
|
1351 | - * @see EEI_Admin_Links for comments |
|
1352 | - * @return string |
|
1353 | - * @throws EE_Error |
|
1354 | - */ |
|
1355 | - public function get_admin_edit_link() |
|
1356 | - { |
|
1357 | - return EEH_URL::add_query_args_and_nonce( |
|
1358 | - array( |
|
1359 | - 'page' => 'espresso_events', |
|
1360 | - 'action' => 'edit', |
|
1361 | - 'post' => $this->ID(), |
|
1362 | - ), |
|
1363 | - admin_url('admin.php') |
|
1364 | - ); |
|
1365 | - } |
|
1366 | - |
|
1367 | - |
|
1368 | - /** |
|
1369 | - * Implementation for EEI_Admin_Links interface method. |
|
1370 | - * |
|
1371 | - * @see EEI_Admin_Links for comments |
|
1372 | - * @return string |
|
1373 | - */ |
|
1374 | - public function get_admin_settings_link() |
|
1375 | - { |
|
1376 | - return EEH_URL::add_query_args_and_nonce( |
|
1377 | - array( |
|
1378 | - 'page' => 'espresso_events', |
|
1379 | - 'action' => 'default_event_settings', |
|
1380 | - ), |
|
1381 | - admin_url('admin.php') |
|
1382 | - ); |
|
1383 | - } |
|
1384 | - |
|
1385 | - |
|
1386 | - /** |
|
1387 | - * Implementation for EEI_Admin_Links interface method. |
|
1388 | - * |
|
1389 | - * @see EEI_Admin_Links for comments |
|
1390 | - * @return string |
|
1391 | - */ |
|
1392 | - public function get_admin_overview_link() |
|
1393 | - { |
|
1394 | - return EEH_URL::add_query_args_and_nonce( |
|
1395 | - array( |
|
1396 | - 'page' => 'espresso_events', |
|
1397 | - 'action' => 'default', |
|
1398 | - ), |
|
1399 | - admin_url('admin.php') |
|
1400 | - ); |
|
1401 | - } |
|
18 | + /** |
|
19 | + * cached value for the the logical active status for the event |
|
20 | + * |
|
21 | + * @see get_active_status() |
|
22 | + * @var string |
|
23 | + */ |
|
24 | + protected $_active_status = ''; |
|
25 | + |
|
26 | + /** |
|
27 | + * This is just used for caching the Primary Datetime for the Event on initial retrieval |
|
28 | + * |
|
29 | + * @var EE_Datetime |
|
30 | + */ |
|
31 | + protected $_Primary_Datetime; |
|
32 | + |
|
33 | + /** |
|
34 | + * @var EventSpacesCalculator $available_spaces_calculator |
|
35 | + */ |
|
36 | + protected $available_spaces_calculator; |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * @param array $props_n_values incoming values |
|
41 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
42 | + * used.) |
|
43 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
44 | + * date_format and the second value is the time format |
|
45 | + * @return EE_Event |
|
46 | + * @throws EE_Error |
|
47 | + */ |
|
48 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
49 | + { |
|
50 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
51 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
52 | + } |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * @param array $props_n_values incoming values from the database |
|
57 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
58 | + * the website will be used. |
|
59 | + * @return EE_Event |
|
60 | + * @throws EE_Error |
|
61 | + */ |
|
62 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
63 | + { |
|
64 | + return new self($props_n_values, true, $timezone); |
|
65 | + } |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * @return EventSpacesCalculator |
|
70 | + * @throws \EE_Error |
|
71 | + */ |
|
72 | + public function getAvailableSpacesCalculator() |
|
73 | + { |
|
74 | + if (! $this->available_spaces_calculator instanceof EventSpacesCalculator) { |
|
75 | + $this->available_spaces_calculator = new EventSpacesCalculator($this); |
|
76 | + } |
|
77 | + return $this->available_spaces_calculator; |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * Overrides parent set() method so that all calls to set( 'status', $status ) can be routed to internal methods |
|
83 | + * |
|
84 | + * @param string $field_name |
|
85 | + * @param mixed $field_value |
|
86 | + * @param bool $use_default |
|
87 | + * @throws EE_Error |
|
88 | + */ |
|
89 | + public function set($field_name, $field_value, $use_default = false) |
|
90 | + { |
|
91 | + switch ($field_name) { |
|
92 | + case 'status': |
|
93 | + $this->set_status($field_value, $use_default); |
|
94 | + break; |
|
95 | + default: |
|
96 | + parent::set($field_name, $field_value, $use_default); |
|
97 | + } |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * set_status |
|
103 | + * Checks if event status is being changed to SOLD OUT |
|
104 | + * and updates event meta data with previous event status |
|
105 | + * so that we can revert things if/when the event is no longer sold out |
|
106 | + * |
|
107 | + * @access public |
|
108 | + * @param string $new_status |
|
109 | + * @param bool $use_default |
|
110 | + * @return void |
|
111 | + * @throws EE_Error |
|
112 | + */ |
|
113 | + public function set_status($new_status = null, $use_default = false) |
|
114 | + { |
|
115 | + // if nothing is set, and we aren't explicitly wanting to reset the status, then just leave |
|
116 | + if (empty($new_status) && ! $use_default) { |
|
117 | + return; |
|
118 | + } |
|
119 | + // get current Event status |
|
120 | + $old_status = $this->status(); |
|
121 | + // if status has changed |
|
122 | + if ($old_status !== $new_status) { |
|
123 | + // TO sold_out |
|
124 | + if ($new_status === EEM_Event::sold_out) { |
|
125 | + // save the previous event status so that we can revert if the event is no longer sold out |
|
126 | + $this->add_post_meta('_previous_event_status', $old_status); |
|
127 | + do_action('AHEE__EE_Event__set_status__to_sold_out', $this, $old_status, $new_status); |
|
128 | + // OR FROM sold_out |
|
129 | + } elseif ($old_status === EEM_Event::sold_out) { |
|
130 | + $this->delete_post_meta('_previous_event_status'); |
|
131 | + do_action('AHEE__EE_Event__set_status__from_sold_out', $this, $old_status, $new_status); |
|
132 | + } |
|
133 | + // clear out the active status so that it gets reset the next time it is requested |
|
134 | + $this->_active_status = null; |
|
135 | + // update status |
|
136 | + parent::set('status', $new_status, $use_default); |
|
137 | + do_action('AHEE__EE_Event__set_status__after_update', $this); |
|
138 | + return; |
|
139 | + } |
|
140 | + // even though the old value matches the new value, it's still good to |
|
141 | + // allow the parent set method to have a say |
|
142 | + parent::set('status', $new_status, $use_default); |
|
143 | + } |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * Gets all the datetimes for this event |
|
148 | + * |
|
149 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
150 | + * @return EE_Base_Class[]|EE_Datetime[] |
|
151 | + * @throws EE_Error |
|
152 | + */ |
|
153 | + public function datetimes($query_params = array()) |
|
154 | + { |
|
155 | + return $this->get_many_related('Datetime', $query_params); |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * Gets all the datetimes for this event, ordered by DTT_EVT_start in ascending order |
|
161 | + * |
|
162 | + * @return EE_Base_Class[]|EE_Datetime[] |
|
163 | + * @throws EE_Error |
|
164 | + */ |
|
165 | + public function datetimes_in_chronological_order() |
|
166 | + { |
|
167 | + return $this->get_many_related('Datetime', array('order_by' => array('DTT_EVT_start' => 'ASC'))); |
|
168 | + } |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * Gets all the datetimes for this event, ordered by the DTT_order on the datetime. |
|
173 | + * @darren, we should probably UNSET timezone on the EEM_Datetime model |
|
174 | + * after running our query, so that this timezone isn't set for EVERY query |
|
175 | + * on EEM_Datetime for the rest of the request, no? |
|
176 | + * |
|
177 | + * @param boolean $show_expired whether or not to include expired events |
|
178 | + * @param boolean $show_deleted whether or not to include deleted events |
|
179 | + * @param null $limit |
|
180 | + * @return EE_Datetime[] |
|
181 | + * @throws EE_Error |
|
182 | + */ |
|
183 | + public function datetimes_ordered($show_expired = true, $show_deleted = false, $limit = null) |
|
184 | + { |
|
185 | + return EEM_Datetime::instance($this->_timezone)->get_datetimes_for_event_ordered_by_DTT_order( |
|
186 | + $this->ID(), |
|
187 | + $show_expired, |
|
188 | + $show_deleted, |
|
189 | + $limit |
|
190 | + ); |
|
191 | + } |
|
192 | + |
|
193 | + |
|
194 | + /** |
|
195 | + * Returns one related datetime. Mostly only used by some legacy code. |
|
196 | + * |
|
197 | + * @return EE_Base_Class|EE_Datetime |
|
198 | + * @throws EE_Error |
|
199 | + */ |
|
200 | + public function first_datetime() |
|
201 | + { |
|
202 | + return $this->get_first_related('Datetime'); |
|
203 | + } |
|
204 | + |
|
205 | + |
|
206 | + /** |
|
207 | + * Returns the 'primary' datetime for the event |
|
208 | + * |
|
209 | + * @param bool $try_to_exclude_expired |
|
210 | + * @param bool $try_to_exclude_deleted |
|
211 | + * @return EE_Datetime |
|
212 | + * @throws EE_Error |
|
213 | + */ |
|
214 | + public function primary_datetime($try_to_exclude_expired = true, $try_to_exclude_deleted = true) |
|
215 | + { |
|
216 | + if (! empty($this->_Primary_Datetime)) { |
|
217 | + return $this->_Primary_Datetime; |
|
218 | + } |
|
219 | + $this->_Primary_Datetime = EEM_Datetime::instance($this->_timezone)->get_primary_datetime_for_event( |
|
220 | + $this->ID(), |
|
221 | + $try_to_exclude_expired, |
|
222 | + $try_to_exclude_deleted |
|
223 | + ); |
|
224 | + return $this->_Primary_Datetime; |
|
225 | + } |
|
226 | + |
|
227 | + |
|
228 | + /** |
|
229 | + * Gets all the tickets available for purchase of this event |
|
230 | + * |
|
231 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
232 | + * @return EE_Base_Class[]|EE_Ticket[] |
|
233 | + * @throws EE_Error |
|
234 | + */ |
|
235 | + public function tickets($query_params = array()) |
|
236 | + { |
|
237 | + // first get all datetimes |
|
238 | + $datetimes = $this->datetimes_ordered(); |
|
239 | + if (! $datetimes) { |
|
240 | + return array(); |
|
241 | + } |
|
242 | + $datetime_ids = array(); |
|
243 | + foreach ($datetimes as $datetime) { |
|
244 | + $datetime_ids[] = $datetime->ID(); |
|
245 | + } |
|
246 | + $where_params = array('Datetime.DTT_ID' => array('IN', $datetime_ids)); |
|
247 | + // if incoming $query_params has where conditions let's merge but not override existing. |
|
248 | + if (is_array($query_params) && isset($query_params[0])) { |
|
249 | + $where_params = array_merge($query_params[0], $where_params); |
|
250 | + unset($query_params[0]); |
|
251 | + } |
|
252 | + // now add $where_params to $query_params |
|
253 | + $query_params[0] = $where_params; |
|
254 | + return EEM_Ticket::instance()->get_all($query_params); |
|
255 | + } |
|
256 | + |
|
257 | + |
|
258 | + /** |
|
259 | + * get all unexpired untrashed tickets |
|
260 | + * |
|
261 | + * @return EE_Ticket[] |
|
262 | + * @throws EE_Error |
|
263 | + */ |
|
264 | + public function active_tickets() |
|
265 | + { |
|
266 | + return $this->tickets( |
|
267 | + array( |
|
268 | + array( |
|
269 | + 'TKT_end_date' => array('>=', EEM_Ticket::instance()->current_time_for_query('TKT_end_date')), |
|
270 | + 'TKT_deleted' => false, |
|
271 | + ), |
|
272 | + ) |
|
273 | + ); |
|
274 | + } |
|
275 | + |
|
276 | + |
|
277 | + /** |
|
278 | + * @return bool |
|
279 | + * @throws EE_Error |
|
280 | + */ |
|
281 | + public function additional_limit() |
|
282 | + { |
|
283 | + return $this->get('EVT_additional_limit'); |
|
284 | + } |
|
285 | + |
|
286 | + |
|
287 | + /** |
|
288 | + * @return bool |
|
289 | + * @throws EE_Error |
|
290 | + */ |
|
291 | + public function allow_overflow() |
|
292 | + { |
|
293 | + return $this->get('EVT_allow_overflow'); |
|
294 | + } |
|
295 | + |
|
296 | + |
|
297 | + /** |
|
298 | + * @return bool |
|
299 | + * @throws EE_Error |
|
300 | + */ |
|
301 | + public function created() |
|
302 | + { |
|
303 | + return $this->get('EVT_created'); |
|
304 | + } |
|
305 | + |
|
306 | + |
|
307 | + /** |
|
308 | + * @return bool |
|
309 | + * @throws EE_Error |
|
310 | + */ |
|
311 | + public function description() |
|
312 | + { |
|
313 | + return $this->get('EVT_desc'); |
|
314 | + } |
|
315 | + |
|
316 | + |
|
317 | + /** |
|
318 | + * Runs do_shortcode and wpautop on the description |
|
319 | + * |
|
320 | + * @return string of html |
|
321 | + * @throws EE_Error |
|
322 | + */ |
|
323 | + public function description_filtered() |
|
324 | + { |
|
325 | + return $this->get_pretty('EVT_desc'); |
|
326 | + } |
|
327 | + |
|
328 | + |
|
329 | + /** |
|
330 | + * @return bool |
|
331 | + * @throws EE_Error |
|
332 | + */ |
|
333 | + public function display_description() |
|
334 | + { |
|
335 | + return $this->get('EVT_display_desc'); |
|
336 | + } |
|
337 | + |
|
338 | + |
|
339 | + /** |
|
340 | + * @return bool |
|
341 | + * @throws EE_Error |
|
342 | + */ |
|
343 | + public function display_ticket_selector() |
|
344 | + { |
|
345 | + return (bool) $this->get('EVT_display_ticket_selector'); |
|
346 | + } |
|
347 | + |
|
348 | + |
|
349 | + /** |
|
350 | + * @return bool |
|
351 | + * @throws EE_Error |
|
352 | + */ |
|
353 | + public function external_url() |
|
354 | + { |
|
355 | + return $this->get('EVT_external_URL'); |
|
356 | + } |
|
357 | + |
|
358 | + |
|
359 | + /** |
|
360 | + * @return bool |
|
361 | + * @throws EE_Error |
|
362 | + */ |
|
363 | + public function member_only() |
|
364 | + { |
|
365 | + return $this->get('EVT_member_only'); |
|
366 | + } |
|
367 | + |
|
368 | + |
|
369 | + /** |
|
370 | + * @return bool |
|
371 | + * @throws EE_Error |
|
372 | + */ |
|
373 | + public function phone() |
|
374 | + { |
|
375 | + return $this->get('EVT_phone'); |
|
376 | + } |
|
377 | + |
|
378 | + |
|
379 | + /** |
|
380 | + * @return bool |
|
381 | + * @throws EE_Error |
|
382 | + */ |
|
383 | + public function modified() |
|
384 | + { |
|
385 | + return $this->get('EVT_modified'); |
|
386 | + } |
|
387 | + |
|
388 | + |
|
389 | + /** |
|
390 | + * @return bool |
|
391 | + * @throws EE_Error |
|
392 | + */ |
|
393 | + public function name() |
|
394 | + { |
|
395 | + return $this->get('EVT_name'); |
|
396 | + } |
|
397 | + |
|
398 | + |
|
399 | + /** |
|
400 | + * @return bool |
|
401 | + * @throws EE_Error |
|
402 | + */ |
|
403 | + public function order() |
|
404 | + { |
|
405 | + return $this->get('EVT_order'); |
|
406 | + } |
|
407 | + |
|
408 | + |
|
409 | + /** |
|
410 | + * @return bool|string |
|
411 | + * @throws EE_Error |
|
412 | + */ |
|
413 | + public function default_registration_status() |
|
414 | + { |
|
415 | + $event_default_registration_status = $this->get('EVT_default_registration_status'); |
|
416 | + return ! empty($event_default_registration_status) |
|
417 | + ? $event_default_registration_status |
|
418 | + : EE_Registry::instance()->CFG->registration->default_STS_ID; |
|
419 | + } |
|
420 | + |
|
421 | + |
|
422 | + /** |
|
423 | + * @param int $num_words |
|
424 | + * @param null $more |
|
425 | + * @param bool $not_full_desc |
|
426 | + * @return bool|string |
|
427 | + * @throws EE_Error |
|
428 | + */ |
|
429 | + public function short_description($num_words = 55, $more = null, $not_full_desc = false) |
|
430 | + { |
|
431 | + $short_desc = $this->get('EVT_short_desc'); |
|
432 | + if (! empty($short_desc) || $not_full_desc) { |
|
433 | + return $short_desc; |
|
434 | + } |
|
435 | + $full_desc = $this->get('EVT_desc'); |
|
436 | + return wp_trim_words($full_desc, $num_words, $more); |
|
437 | + } |
|
438 | + |
|
439 | + |
|
440 | + /** |
|
441 | + * @return bool |
|
442 | + * @throws EE_Error |
|
443 | + */ |
|
444 | + public function slug() |
|
445 | + { |
|
446 | + return $this->get('EVT_slug'); |
|
447 | + } |
|
448 | + |
|
449 | + |
|
450 | + /** |
|
451 | + * @return bool |
|
452 | + * @throws EE_Error |
|
453 | + */ |
|
454 | + public function timezone_string() |
|
455 | + { |
|
456 | + return $this->get('EVT_timezone_string'); |
|
457 | + } |
|
458 | + |
|
459 | + |
|
460 | + /** |
|
461 | + * @return bool |
|
462 | + * @throws EE_Error |
|
463 | + */ |
|
464 | + public function visible_on() |
|
465 | + { |
|
466 | + return $this->get('EVT_visible_on'); |
|
467 | + } |
|
468 | + |
|
469 | + |
|
470 | + /** |
|
471 | + * @return int |
|
472 | + * @throws EE_Error |
|
473 | + */ |
|
474 | + public function wp_user() |
|
475 | + { |
|
476 | + return $this->get('EVT_wp_user'); |
|
477 | + } |
|
478 | + |
|
479 | + |
|
480 | + /** |
|
481 | + * @return bool |
|
482 | + * @throws EE_Error |
|
483 | + */ |
|
484 | + public function donations() |
|
485 | + { |
|
486 | + return $this->get('EVT_donations'); |
|
487 | + } |
|
488 | + |
|
489 | + |
|
490 | + /** |
|
491 | + * @param $limit |
|
492 | + * @throws EE_Error |
|
493 | + */ |
|
494 | + public function set_additional_limit($limit) |
|
495 | + { |
|
496 | + $this->set('EVT_additional_limit', $limit); |
|
497 | + } |
|
498 | + |
|
499 | + |
|
500 | + /** |
|
501 | + * @param $created |
|
502 | + * @throws EE_Error |
|
503 | + */ |
|
504 | + public function set_created($created) |
|
505 | + { |
|
506 | + $this->set('EVT_created', $created); |
|
507 | + } |
|
508 | + |
|
509 | + |
|
510 | + /** |
|
511 | + * @param $desc |
|
512 | + * @throws EE_Error |
|
513 | + */ |
|
514 | + public function set_description($desc) |
|
515 | + { |
|
516 | + $this->set('EVT_desc', $desc); |
|
517 | + } |
|
518 | + |
|
519 | + |
|
520 | + /** |
|
521 | + * @param $display_desc |
|
522 | + * @throws EE_Error |
|
523 | + */ |
|
524 | + public function set_display_description($display_desc) |
|
525 | + { |
|
526 | + $this->set('EVT_display_desc', $display_desc); |
|
527 | + } |
|
528 | + |
|
529 | + |
|
530 | + /** |
|
531 | + * @param $display_ticket_selector |
|
532 | + * @throws EE_Error |
|
533 | + */ |
|
534 | + public function set_display_ticket_selector($display_ticket_selector) |
|
535 | + { |
|
536 | + $this->set('EVT_display_ticket_selector', $display_ticket_selector); |
|
537 | + } |
|
538 | + |
|
539 | + |
|
540 | + /** |
|
541 | + * @param $external_url |
|
542 | + * @throws EE_Error |
|
543 | + */ |
|
544 | + public function set_external_url($external_url) |
|
545 | + { |
|
546 | + $this->set('EVT_external_URL', $external_url); |
|
547 | + } |
|
548 | + |
|
549 | + |
|
550 | + /** |
|
551 | + * @param $member_only |
|
552 | + * @throws EE_Error |
|
553 | + */ |
|
554 | + public function set_member_only($member_only) |
|
555 | + { |
|
556 | + $this->set('EVT_member_only', $member_only); |
|
557 | + } |
|
558 | + |
|
559 | + |
|
560 | + /** |
|
561 | + * @param $event_phone |
|
562 | + * @throws EE_Error |
|
563 | + */ |
|
564 | + public function set_event_phone($event_phone) |
|
565 | + { |
|
566 | + $this->set('EVT_phone', $event_phone); |
|
567 | + } |
|
568 | + |
|
569 | + |
|
570 | + /** |
|
571 | + * @param $modified |
|
572 | + * @throws EE_Error |
|
573 | + */ |
|
574 | + public function set_modified($modified) |
|
575 | + { |
|
576 | + $this->set('EVT_modified', $modified); |
|
577 | + } |
|
578 | + |
|
579 | + |
|
580 | + /** |
|
581 | + * @param $name |
|
582 | + * @throws EE_Error |
|
583 | + */ |
|
584 | + public function set_name($name) |
|
585 | + { |
|
586 | + $this->set('EVT_name', $name); |
|
587 | + } |
|
588 | + |
|
589 | + |
|
590 | + /** |
|
591 | + * @param $order |
|
592 | + * @throws EE_Error |
|
593 | + */ |
|
594 | + public function set_order($order) |
|
595 | + { |
|
596 | + $this->set('EVT_order', $order); |
|
597 | + } |
|
598 | + |
|
599 | + |
|
600 | + /** |
|
601 | + * @param $short_desc |
|
602 | + * @throws EE_Error |
|
603 | + */ |
|
604 | + public function set_short_description($short_desc) |
|
605 | + { |
|
606 | + $this->set('EVT_short_desc', $short_desc); |
|
607 | + } |
|
608 | + |
|
609 | + |
|
610 | + /** |
|
611 | + * @param $slug |
|
612 | + * @throws EE_Error |
|
613 | + */ |
|
614 | + public function set_slug($slug) |
|
615 | + { |
|
616 | + $this->set('EVT_slug', $slug); |
|
617 | + } |
|
618 | + |
|
619 | + |
|
620 | + /** |
|
621 | + * @param $timezone_string |
|
622 | + * @throws EE_Error |
|
623 | + */ |
|
624 | + public function set_timezone_string($timezone_string) |
|
625 | + { |
|
626 | + $this->set('EVT_timezone_string', $timezone_string); |
|
627 | + } |
|
628 | + |
|
629 | + |
|
630 | + /** |
|
631 | + * @param $visible_on |
|
632 | + * @throws EE_Error |
|
633 | + */ |
|
634 | + public function set_visible_on($visible_on) |
|
635 | + { |
|
636 | + $this->set('EVT_visible_on', $visible_on); |
|
637 | + } |
|
638 | + |
|
639 | + |
|
640 | + /** |
|
641 | + * @param $wp_user |
|
642 | + * @throws EE_Error |
|
643 | + */ |
|
644 | + public function set_wp_user($wp_user) |
|
645 | + { |
|
646 | + $this->set('EVT_wp_user', $wp_user); |
|
647 | + } |
|
648 | + |
|
649 | + |
|
650 | + /** |
|
651 | + * @param $default_registration_status |
|
652 | + * @throws EE_Error |
|
653 | + */ |
|
654 | + public function set_default_registration_status($default_registration_status) |
|
655 | + { |
|
656 | + $this->set('EVT_default_registration_status', $default_registration_status); |
|
657 | + } |
|
658 | + |
|
659 | + |
|
660 | + /** |
|
661 | + * @param $donations |
|
662 | + * @throws EE_Error |
|
663 | + */ |
|
664 | + public function set_donations($donations) |
|
665 | + { |
|
666 | + $this->set('EVT_donations', $donations); |
|
667 | + } |
|
668 | + |
|
669 | + |
|
670 | + /** |
|
671 | + * Adds a venue to this event |
|
672 | + * |
|
673 | + * @param EE_Venue /int $venue_id_or_obj |
|
674 | + * @return EE_Base_Class|EE_Venue |
|
675 | + * @throws EE_Error |
|
676 | + */ |
|
677 | + public function add_venue($venue_id_or_obj) |
|
678 | + { |
|
679 | + return $this->_add_relation_to($venue_id_or_obj, 'Venue'); |
|
680 | + } |
|
681 | + |
|
682 | + |
|
683 | + /** |
|
684 | + * Removes a venue from the event |
|
685 | + * |
|
686 | + * @param EE_Venue /int $venue_id_or_obj |
|
687 | + * @return EE_Base_Class|EE_Venue |
|
688 | + * @throws EE_Error |
|
689 | + */ |
|
690 | + public function remove_venue($venue_id_or_obj) |
|
691 | + { |
|
692 | + return $this->_remove_relation_to($venue_id_or_obj, 'Venue'); |
|
693 | + } |
|
694 | + |
|
695 | + |
|
696 | + /** |
|
697 | + * Gets all the venues related ot the event. May provide additional $query_params if desired |
|
698 | + * |
|
699 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
700 | + * @return EE_Base_Class[]|EE_Venue[] |
|
701 | + * @throws EE_Error |
|
702 | + */ |
|
703 | + public function venues($query_params = array()) |
|
704 | + { |
|
705 | + return $this->get_many_related('Venue', $query_params); |
|
706 | + } |
|
707 | + |
|
708 | + |
|
709 | + /** |
|
710 | + * check if event id is present and if event is published |
|
711 | + * |
|
712 | + * @access public |
|
713 | + * @return boolean true yes, false no |
|
714 | + * @throws EE_Error |
|
715 | + */ |
|
716 | + private function _has_ID_and_is_published() |
|
717 | + { |
|
718 | + // first check if event id is present and not NULL, |
|
719 | + // then check if this event is published (or any of the equivalent "published" statuses) |
|
720 | + return |
|
721 | + $this->ID() && $this->ID() !== null |
|
722 | + && ( |
|
723 | + $this->status() === 'publish' |
|
724 | + || $this->status() === EEM_Event::sold_out |
|
725 | + || $this->status() === EEM_Event::postponed |
|
726 | + || $this->status() === EEM_Event::cancelled |
|
727 | + ); |
|
728 | + } |
|
729 | + |
|
730 | + |
|
731 | + /** |
|
732 | + * This simply compares the internal dates with NOW and determines if the event is upcoming or not. |
|
733 | + * |
|
734 | + * @access public |
|
735 | + * @return boolean true yes, false no |
|
736 | + * @throws EE_Error |
|
737 | + */ |
|
738 | + public function is_upcoming() |
|
739 | + { |
|
740 | + // check if event id is present and if this event is published |
|
741 | + if ($this->is_inactive()) { |
|
742 | + return false; |
|
743 | + } |
|
744 | + // set initial value |
|
745 | + $upcoming = false; |
|
746 | + // next let's get all datetimes and loop through them |
|
747 | + $datetimes = $this->datetimes_in_chronological_order(); |
|
748 | + foreach ($datetimes as $datetime) { |
|
749 | + if ($datetime instanceof EE_Datetime) { |
|
750 | + // if this dtt is expired then we continue cause one of the other datetimes might be upcoming. |
|
751 | + if ($datetime->is_expired()) { |
|
752 | + continue; |
|
753 | + } |
|
754 | + // if this dtt is active then we return false. |
|
755 | + if ($datetime->is_active()) { |
|
756 | + return false; |
|
757 | + } |
|
758 | + // otherwise let's check upcoming status |
|
759 | + $upcoming = $datetime->is_upcoming(); |
|
760 | + } |
|
761 | + } |
|
762 | + return $upcoming; |
|
763 | + } |
|
764 | + |
|
765 | + |
|
766 | + /** |
|
767 | + * @return bool |
|
768 | + * @throws EE_Error |
|
769 | + */ |
|
770 | + public function is_active() |
|
771 | + { |
|
772 | + // check if event id is present and if this event is published |
|
773 | + if ($this->is_inactive()) { |
|
774 | + return false; |
|
775 | + } |
|
776 | + // set initial value |
|
777 | + $active = false; |
|
778 | + // next let's get all datetimes and loop through them |
|
779 | + $datetimes = $this->datetimes_in_chronological_order(); |
|
780 | + foreach ($datetimes as $datetime) { |
|
781 | + if ($datetime instanceof EE_Datetime) { |
|
782 | + // if this dtt is expired then we continue cause one of the other datetimes might be active. |
|
783 | + if ($datetime->is_expired()) { |
|
784 | + continue; |
|
785 | + } |
|
786 | + // if this dtt is upcoming then we return false. |
|
787 | + if ($datetime->is_upcoming()) { |
|
788 | + return false; |
|
789 | + } |
|
790 | + // otherwise let's check active status |
|
791 | + $active = $datetime->is_active(); |
|
792 | + } |
|
793 | + } |
|
794 | + return $active; |
|
795 | + } |
|
796 | + |
|
797 | + |
|
798 | + /** |
|
799 | + * @return bool |
|
800 | + * @throws EE_Error |
|
801 | + */ |
|
802 | + public function is_expired() |
|
803 | + { |
|
804 | + // check if event id is present and if this event is published |
|
805 | + if ($this->is_inactive()) { |
|
806 | + return false; |
|
807 | + } |
|
808 | + // set initial value |
|
809 | + $expired = false; |
|
810 | + // first let's get all datetimes and loop through them |
|
811 | + $datetimes = $this->datetimes_in_chronological_order(); |
|
812 | + foreach ($datetimes as $datetime) { |
|
813 | + if ($datetime instanceof EE_Datetime) { |
|
814 | + // if this dtt is upcoming or active then we return false. |
|
815 | + if ($datetime->is_upcoming() || $datetime->is_active()) { |
|
816 | + return false; |
|
817 | + } |
|
818 | + // otherwise let's check active status |
|
819 | + $expired = $datetime->is_expired(); |
|
820 | + } |
|
821 | + } |
|
822 | + return $expired; |
|
823 | + } |
|
824 | + |
|
825 | + |
|
826 | + /** |
|
827 | + * @return bool |
|
828 | + * @throws EE_Error |
|
829 | + */ |
|
830 | + public function is_inactive() |
|
831 | + { |
|
832 | + // check if event id is present and if this event is published |
|
833 | + if ($this->_has_ID_and_is_published()) { |
|
834 | + return false; |
|
835 | + } |
|
836 | + return true; |
|
837 | + } |
|
838 | + |
|
839 | + |
|
840 | + /** |
|
841 | + * calculate spaces remaining based on "saleable" tickets |
|
842 | + * |
|
843 | + * @param array $tickets |
|
844 | + * @param bool $filtered |
|
845 | + * @return int|float |
|
846 | + * @throws EE_Error |
|
847 | + * @throws DomainException |
|
848 | + * @throws UnexpectedEntityException |
|
849 | + */ |
|
850 | + public function spaces_remaining($tickets = array(), $filtered = true) |
|
851 | + { |
|
852 | + $this->getAvailableSpacesCalculator()->setActiveTickets($tickets); |
|
853 | + $spaces_remaining = $this->getAvailableSpacesCalculator()->spacesRemaining(); |
|
854 | + return $filtered |
|
855 | + ? apply_filters( |
|
856 | + 'FHEE_EE_Event__spaces_remaining', |
|
857 | + $spaces_remaining, |
|
858 | + $this, |
|
859 | + $tickets |
|
860 | + ) |
|
861 | + : $spaces_remaining; |
|
862 | + } |
|
863 | + |
|
864 | + |
|
865 | + /** |
|
866 | + * perform_sold_out_status_check |
|
867 | + * checks all of this events's datetime reg_limit - sold values to determine if ANY datetimes have spaces |
|
868 | + * available... if NOT, then the event status will get toggled to 'sold_out' |
|
869 | + * |
|
870 | + * @return bool return the ACTUAL sold out state. |
|
871 | + * @throws EE_Error |
|
872 | + * @throws DomainException |
|
873 | + * @throws UnexpectedEntityException |
|
874 | + */ |
|
875 | + public function perform_sold_out_status_check() |
|
876 | + { |
|
877 | + // get all tickets |
|
878 | + $tickets = $this->tickets( |
|
879 | + array( |
|
880 | + 'default_where_conditions' => 'none', |
|
881 | + 'order_by' => array('TKT_qty' => 'ASC'), |
|
882 | + ) |
|
883 | + ); |
|
884 | + $all_expired = true; |
|
885 | + foreach ($tickets as $ticket) { |
|
886 | + if (! $ticket->is_expired()) { |
|
887 | + $all_expired = false; |
|
888 | + break; |
|
889 | + } |
|
890 | + } |
|
891 | + // if all the tickets are just expired, then don't update the event status to sold out |
|
892 | + if ($all_expired) { |
|
893 | + return true; |
|
894 | + } |
|
895 | + $spaces_remaining = $this->spaces_remaining($tickets); |
|
896 | + if ($spaces_remaining < 1) { |
|
897 | + if ($this->status() !== EEM_Event::post_status_private) { |
|
898 | + $this->set_status(EEM_Event::sold_out); |
|
899 | + $this->save(); |
|
900 | + } |
|
901 | + $sold_out = true; |
|
902 | + } else { |
|
903 | + $sold_out = false; |
|
904 | + // was event previously marked as sold out ? |
|
905 | + if ($this->status() === EEM_Event::sold_out) { |
|
906 | + // revert status to previous value, if it was set |
|
907 | + $previous_event_status = $this->get_post_meta('_previous_event_status', true); |
|
908 | + if ($previous_event_status) { |
|
909 | + $this->set_status($previous_event_status); |
|
910 | + $this->save(); |
|
911 | + } |
|
912 | + } |
|
913 | + } |
|
914 | + do_action('AHEE__EE_Event__perform_sold_out_status_check__end', $this, $sold_out, $spaces_remaining, $tickets); |
|
915 | + return $sold_out; |
|
916 | + } |
|
917 | + |
|
918 | + |
|
919 | + /** |
|
920 | + * This returns the total remaining spaces for sale on this event. |
|
921 | + * |
|
922 | + * @uses EE_Event::total_available_spaces() |
|
923 | + * @return float|int |
|
924 | + * @throws EE_Error |
|
925 | + * @throws DomainException |
|
926 | + * @throws UnexpectedEntityException |
|
927 | + */ |
|
928 | + public function spaces_remaining_for_sale() |
|
929 | + { |
|
930 | + return $this->total_available_spaces(true); |
|
931 | + } |
|
932 | + |
|
933 | + |
|
934 | + /** |
|
935 | + * This returns the total spaces available for an event |
|
936 | + * while considering all the qtys on the tickets and the reg limits |
|
937 | + * on the datetimes attached to this event. |
|
938 | + * |
|
939 | + * @param bool $consider_sold Whether to consider any tickets that have already sold in our calculation. |
|
940 | + * If this is false, then we return the most tickets that could ever be sold |
|
941 | + * for this event with the datetime and tickets setup on the event under optimal |
|
942 | + * selling conditions. Otherwise we return a live calculation of spaces available |
|
943 | + * based on tickets sold. Depending on setup and stage of sales, this |
|
944 | + * may appear to equal remaining tickets. However, the more tickets are |
|
945 | + * sold out, the more accurate the "live" total is. |
|
946 | + * @return float|int |
|
947 | + * @throws EE_Error |
|
948 | + * @throws DomainException |
|
949 | + * @throws UnexpectedEntityException |
|
950 | + */ |
|
951 | + public function total_available_spaces($consider_sold = false) |
|
952 | + { |
|
953 | + $spaces_available = $consider_sold |
|
954 | + ? $this->getAvailableSpacesCalculator()->spacesRemaining() |
|
955 | + : $this->getAvailableSpacesCalculator()->totalSpacesAvailable(); |
|
956 | + return apply_filters( |
|
957 | + 'FHEE_EE_Event__total_available_spaces__spaces_available', |
|
958 | + $spaces_available, |
|
959 | + $this, |
|
960 | + $this->getAvailableSpacesCalculator()->getDatetimes(), |
|
961 | + $this->getAvailableSpacesCalculator()->getActiveTickets() |
|
962 | + ); |
|
963 | + } |
|
964 | + |
|
965 | + |
|
966 | + /** |
|
967 | + * Checks if the event is set to sold out |
|
968 | + * |
|
969 | + * @param bool $actual whether or not to perform calculations to not only figure the |
|
970 | + * actual status but also to flip the status if necessary to sold |
|
971 | + * out If false, we just check the existing status of the event |
|
972 | + * @return boolean |
|
973 | + * @throws EE_Error |
|
974 | + */ |
|
975 | + public function is_sold_out($actual = false) |
|
976 | + { |
|
977 | + if (! $actual) { |
|
978 | + return $this->status() === EEM_Event::sold_out; |
|
979 | + } |
|
980 | + return $this->perform_sold_out_status_check(); |
|
981 | + } |
|
982 | + |
|
983 | + |
|
984 | + /** |
|
985 | + * Checks if the event is marked as postponed |
|
986 | + * |
|
987 | + * @return boolean |
|
988 | + */ |
|
989 | + public function is_postponed() |
|
990 | + { |
|
991 | + return $this->status() === EEM_Event::postponed; |
|
992 | + } |
|
993 | + |
|
994 | + |
|
995 | + /** |
|
996 | + * Checks if the event is marked as cancelled |
|
997 | + * |
|
998 | + * @return boolean |
|
999 | + */ |
|
1000 | + public function is_cancelled() |
|
1001 | + { |
|
1002 | + return $this->status() === EEM_Event::cancelled; |
|
1003 | + } |
|
1004 | + |
|
1005 | + |
|
1006 | + /** |
|
1007 | + * Get the logical active status in a hierarchical order for all the datetimes. Note |
|
1008 | + * Basically, we order the datetimes by EVT_start_date. Then first test on whether the event is published. If its |
|
1009 | + * NOT published then we test for whether its expired or not. IF it IS published then we test first on whether an |
|
1010 | + * event has any active dates. If no active dates then we check for any upcoming dates. If no upcoming dates then |
|
1011 | + * the event is considered expired. |
|
1012 | + * NOTE: this method does NOT calculate whether the datetimes are sold out when event is published. Sold Out is a |
|
1013 | + * status set on the EVENT when it is not published and thus is done |
|
1014 | + * |
|
1015 | + * @param bool $reset |
|
1016 | + * @return bool | string - based on EE_Datetime active constants or FALSE if error. |
|
1017 | + * @throws EE_Error |
|
1018 | + */ |
|
1019 | + public function get_active_status($reset = false) |
|
1020 | + { |
|
1021 | + // if the active status has already been set, then just use that value (unless we are resetting it) |
|
1022 | + if (! empty($this->_active_status) && ! $reset) { |
|
1023 | + return $this->_active_status; |
|
1024 | + } |
|
1025 | + // first check if event id is present on this object |
|
1026 | + if (! $this->ID()) { |
|
1027 | + return false; |
|
1028 | + } |
|
1029 | + $where_params_for_event = array(array('EVT_ID' => $this->ID())); |
|
1030 | + // if event is published: |
|
1031 | + if ($this->status() === EEM_Event::post_status_publish || $this->status() === EEM_Event::post_status_private) { |
|
1032 | + // active? |
|
1033 | + if (EEM_Datetime::instance()->get_datetime_count_for_status( |
|
1034 | + EE_Datetime::active, |
|
1035 | + $where_params_for_event |
|
1036 | + ) > 0) { |
|
1037 | + $this->_active_status = EE_Datetime::active; |
|
1038 | + } else { |
|
1039 | + // upcoming? |
|
1040 | + if (EEM_Datetime::instance()->get_datetime_count_for_status( |
|
1041 | + EE_Datetime::upcoming, |
|
1042 | + $where_params_for_event |
|
1043 | + ) > 0) { |
|
1044 | + $this->_active_status = EE_Datetime::upcoming; |
|
1045 | + } else { |
|
1046 | + // expired? |
|
1047 | + if (EEM_Datetime::instance()->get_datetime_count_for_status( |
|
1048 | + EE_Datetime::expired, |
|
1049 | + $where_params_for_event |
|
1050 | + ) > 0 |
|
1051 | + ) { |
|
1052 | + $this->_active_status = EE_Datetime::expired; |
|
1053 | + } else { |
|
1054 | + // it would be odd if things make it this far because it basically means there are no datetime's |
|
1055 | + // attached to the event. So in this case it will just be considered inactive. |
|
1056 | + $this->_active_status = EE_Datetime::inactive; |
|
1057 | + } |
|
1058 | + } |
|
1059 | + } |
|
1060 | + } else { |
|
1061 | + // the event is not published, so let's just set it's active status according to its' post status |
|
1062 | + switch ($this->status()) { |
|
1063 | + case EEM_Event::sold_out: |
|
1064 | + $this->_active_status = EE_Datetime::sold_out; |
|
1065 | + break; |
|
1066 | + case EEM_Event::cancelled: |
|
1067 | + $this->_active_status = EE_Datetime::cancelled; |
|
1068 | + break; |
|
1069 | + case EEM_Event::postponed: |
|
1070 | + $this->_active_status = EE_Datetime::postponed; |
|
1071 | + break; |
|
1072 | + default: |
|
1073 | + $this->_active_status = EE_Datetime::inactive; |
|
1074 | + } |
|
1075 | + } |
|
1076 | + return $this->_active_status; |
|
1077 | + } |
|
1078 | + |
|
1079 | + |
|
1080 | + /** |
|
1081 | + * pretty_active_status |
|
1082 | + * |
|
1083 | + * @access public |
|
1084 | + * @param boolean $echo whether to return (FALSE), or echo out the result (TRUE) |
|
1085 | + * @return mixed void|string |
|
1086 | + * @throws EE_Error |
|
1087 | + */ |
|
1088 | + public function pretty_active_status($echo = true) |
|
1089 | + { |
|
1090 | + $active_status = $this->get_active_status(); |
|
1091 | + $status = '<span class="ee-status event-active-status-' |
|
1092 | + . $active_status |
|
1093 | + . '">' |
|
1094 | + . EEH_Template::pretty_status($active_status, false, 'sentence') |
|
1095 | + . '</span>'; |
|
1096 | + if ($echo) { |
|
1097 | + echo $status; |
|
1098 | + return ''; |
|
1099 | + } |
|
1100 | + return $status; |
|
1101 | + } |
|
1102 | + |
|
1103 | + |
|
1104 | + /** |
|
1105 | + * @return bool|int |
|
1106 | + * @throws EE_Error |
|
1107 | + */ |
|
1108 | + public function get_number_of_tickets_sold() |
|
1109 | + { |
|
1110 | + $tkt_sold = 0; |
|
1111 | + if (! $this->ID()) { |
|
1112 | + return 0; |
|
1113 | + } |
|
1114 | + $datetimes = $this->datetimes(); |
|
1115 | + foreach ($datetimes as $datetime) { |
|
1116 | + if ($datetime instanceof EE_Datetime) { |
|
1117 | + $tkt_sold += $datetime->sold(); |
|
1118 | + } |
|
1119 | + } |
|
1120 | + return $tkt_sold; |
|
1121 | + } |
|
1122 | + |
|
1123 | + |
|
1124 | + /** |
|
1125 | + * This just returns a count of all the registrations for this event |
|
1126 | + * |
|
1127 | + * @access public |
|
1128 | + * @return int |
|
1129 | + * @throws EE_Error |
|
1130 | + */ |
|
1131 | + public function get_count_of_all_registrations() |
|
1132 | + { |
|
1133 | + return EEM_Event::instance()->count_related($this, 'Registration'); |
|
1134 | + } |
|
1135 | + |
|
1136 | + |
|
1137 | + /** |
|
1138 | + * This returns the ticket with the earliest start time that is |
|
1139 | + * available for this event (across all datetimes attached to the event) |
|
1140 | + * |
|
1141 | + * @return EE_Base_Class|EE_Ticket|null |
|
1142 | + * @throws EE_Error |
|
1143 | + */ |
|
1144 | + public function get_ticket_with_earliest_start_time() |
|
1145 | + { |
|
1146 | + $where['Datetime.EVT_ID'] = $this->ID(); |
|
1147 | + $query_params = array($where, 'order_by' => array('TKT_start_date' => 'ASC')); |
|
1148 | + return EE_Registry::instance()->load_model('Ticket')->get_one($query_params); |
|
1149 | + } |
|
1150 | + |
|
1151 | + |
|
1152 | + /** |
|
1153 | + * This returns the ticket with the latest end time that is available |
|
1154 | + * for this event (across all datetimes attached to the event) |
|
1155 | + * |
|
1156 | + * @return EE_Base_Class|EE_Ticket|null |
|
1157 | + * @throws EE_Error |
|
1158 | + */ |
|
1159 | + public function get_ticket_with_latest_end_time() |
|
1160 | + { |
|
1161 | + $where['Datetime.EVT_ID'] = $this->ID(); |
|
1162 | + $query_params = array($where, 'order_by' => array('TKT_end_date' => 'DESC')); |
|
1163 | + return EE_Registry::instance()->load_model('Ticket')->get_one($query_params); |
|
1164 | + } |
|
1165 | + |
|
1166 | + |
|
1167 | + /** |
|
1168 | + * This returns the number of different ticket types currently on sale for this event. |
|
1169 | + * |
|
1170 | + * @return int |
|
1171 | + * @throws EE_Error |
|
1172 | + */ |
|
1173 | + public function countTicketsOnSale() |
|
1174 | + { |
|
1175 | + $where = array( |
|
1176 | + 'Datetime.EVT_ID' => $this->ID(), |
|
1177 | + 'TKT_start_date' => array('<', time()), |
|
1178 | + 'TKT_end_date' => array('>', time()), |
|
1179 | + ); |
|
1180 | + return EEM_Ticket::instance()->count(array($where)); |
|
1181 | + } |
|
1182 | + |
|
1183 | + |
|
1184 | + /** |
|
1185 | + * This returns whether there are any tickets on sale for this event. |
|
1186 | + * |
|
1187 | + * @return bool true = YES tickets on sale. |
|
1188 | + * @throws EE_Error |
|
1189 | + */ |
|
1190 | + public function tickets_on_sale() |
|
1191 | + { |
|
1192 | + return $this->countTicketsOnSale() > 0; |
|
1193 | + } |
|
1194 | + |
|
1195 | + |
|
1196 | + /** |
|
1197 | + * Gets the URL for viewing this event on the front-end. Overrides parent |
|
1198 | + * to check for an external URL first |
|
1199 | + * |
|
1200 | + * @return string |
|
1201 | + * @throws EE_Error |
|
1202 | + */ |
|
1203 | + public function get_permalink() |
|
1204 | + { |
|
1205 | + if ($this->external_url()) { |
|
1206 | + return $this->external_url(); |
|
1207 | + } |
|
1208 | + return parent::get_permalink(); |
|
1209 | + } |
|
1210 | + |
|
1211 | + |
|
1212 | + /** |
|
1213 | + * Gets the first term for 'espresso_event_categories' we can find |
|
1214 | + * |
|
1215 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
1216 | + * @return EE_Base_Class|EE_Term|null |
|
1217 | + * @throws EE_Error |
|
1218 | + */ |
|
1219 | + public function first_event_category($query_params = array()) |
|
1220 | + { |
|
1221 | + $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
1222 | + $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID(); |
|
1223 | + return EEM_Term::instance()->get_one($query_params); |
|
1224 | + } |
|
1225 | + |
|
1226 | + |
|
1227 | + /** |
|
1228 | + * Gets all terms for 'espresso_event_categories' we can find |
|
1229 | + * |
|
1230 | + * @param array $query_params |
|
1231 | + * @return EE_Base_Class[]|EE_Term[] |
|
1232 | + * @throws EE_Error |
|
1233 | + */ |
|
1234 | + public function get_all_event_categories($query_params = array()) |
|
1235 | + { |
|
1236 | + $query_params[0]['Term_Taxonomy.taxonomy'] = 'espresso_event_categories'; |
|
1237 | + $query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $this->ID(); |
|
1238 | + return EEM_Term::instance()->get_all($query_params); |
|
1239 | + } |
|
1240 | + |
|
1241 | + |
|
1242 | + /** |
|
1243 | + * Adds a question group to this event |
|
1244 | + * |
|
1245 | + * @param EE_Question_Group|int $question_group_id_or_obj |
|
1246 | + * @param bool $for_primary if true, the question group will be added for the primary |
|
1247 | + * registrant, if false will be added for others. default: false |
|
1248 | + * @return EE_Base_Class|EE_Question_Group |
|
1249 | + * @throws EE_Error |
|
1250 | + * @throws InvalidArgumentException |
|
1251 | + * @throws InvalidDataTypeException |
|
1252 | + * @throws InvalidInterfaceException |
|
1253 | + * @throws ReflectionException |
|
1254 | + */ |
|
1255 | + public function add_question_group($question_group_id_or_obj, $for_primary = false) |
|
1256 | + { |
|
1257 | + // If the row already exists, it will be updated. If it doesn't, it will be inserted. |
|
1258 | + // That's in EE_HABTM_Relation::add_relation_to(). |
|
1259 | + return $this->_add_relation_to( |
|
1260 | + $question_group_id_or_obj, |
|
1261 | + 'Question_Group', |
|
1262 | + [ |
|
1263 | + EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary) => true |
|
1264 | + ] |
|
1265 | + ); |
|
1266 | + } |
|
1267 | + |
|
1268 | + |
|
1269 | + /** |
|
1270 | + * Removes a question group from the event |
|
1271 | + * |
|
1272 | + * @param EE_Question_Group|int $question_group_id_or_obj |
|
1273 | + * @param bool $for_primary if true, the question group will be removed from the primary |
|
1274 | + * registrant, if false will be removed from others. default: false |
|
1275 | + * @return EE_Base_Class|EE_Question_Group |
|
1276 | + * @throws EE_Error |
|
1277 | + * @throws InvalidArgumentException |
|
1278 | + * @throws ReflectionException |
|
1279 | + * @throws InvalidDataTypeException |
|
1280 | + * @throws InvalidInterfaceException |
|
1281 | + */ |
|
1282 | + public function remove_question_group($question_group_id_or_obj, $for_primary = false) |
|
1283 | + { |
|
1284 | + // If the question group is used for the other type (primary or additional) |
|
1285 | + // then just update it. If not, delete it outright. |
|
1286 | + $existing_relation = $this->get_first_related( |
|
1287 | + 'Event_Question_Group', |
|
1288 | + [ |
|
1289 | + [ |
|
1290 | + 'QSG_ID' => EEM_Question_Group::instance()->ensure_is_ID($question_group_id_or_obj) |
|
1291 | + ] |
|
1292 | + ] |
|
1293 | + ); |
|
1294 | + $field_to_update = EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary); |
|
1295 | + $other_field = EEM_Event_Question_Group::instance()->fieldNameForContext(! $for_primary); |
|
1296 | + if ($existing_relation->get($other_field) === false) { |
|
1297 | + // Delete it. It's now no longer for primary or additional question groups. |
|
1298 | + return $this->_remove_relation_to($question_group_id_or_obj, 'Question_Group'); |
|
1299 | + } |
|
1300 | + // Just update it. They'll still use this question group for the other category |
|
1301 | + $existing_relation->save( |
|
1302 | + [ |
|
1303 | + $field_to_update => false |
|
1304 | + ] |
|
1305 | + ); |
|
1306 | + } |
|
1307 | + |
|
1308 | + |
|
1309 | + /** |
|
1310 | + * Gets all the question groups, ordering them by QSG_order ascending |
|
1311 | + * |
|
1312 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
1313 | + * @return EE_Base_Class[]|EE_Question_Group[] |
|
1314 | + * @throws EE_Error |
|
1315 | + */ |
|
1316 | + public function question_groups($query_params = array()) |
|
1317 | + { |
|
1318 | + $query_params = ! empty($query_params) ? $query_params : array('order_by' => array('QSG_order' => 'ASC')); |
|
1319 | + return $this->get_many_related('Question_Group', $query_params); |
|
1320 | + } |
|
1321 | + |
|
1322 | + |
|
1323 | + /** |
|
1324 | + * Implementation for EEI_Has_Icon interface method. |
|
1325 | + * |
|
1326 | + * @see EEI_Visual_Representation for comments |
|
1327 | + * @return string |
|
1328 | + */ |
|
1329 | + public function get_icon() |
|
1330 | + { |
|
1331 | + return '<span class="dashicons dashicons-flag"></span>'; |
|
1332 | + } |
|
1333 | + |
|
1334 | + |
|
1335 | + /** |
|
1336 | + * Implementation for EEI_Admin_Links interface method. |
|
1337 | + * |
|
1338 | + * @see EEI_Admin_Links for comments |
|
1339 | + * @return string |
|
1340 | + * @throws EE_Error |
|
1341 | + */ |
|
1342 | + public function get_admin_details_link() |
|
1343 | + { |
|
1344 | + return $this->get_admin_edit_link(); |
|
1345 | + } |
|
1346 | + |
|
1347 | + |
|
1348 | + /** |
|
1349 | + * Implementation for EEI_Admin_Links interface method. |
|
1350 | + * |
|
1351 | + * @see EEI_Admin_Links for comments |
|
1352 | + * @return string |
|
1353 | + * @throws EE_Error |
|
1354 | + */ |
|
1355 | + public function get_admin_edit_link() |
|
1356 | + { |
|
1357 | + return EEH_URL::add_query_args_and_nonce( |
|
1358 | + array( |
|
1359 | + 'page' => 'espresso_events', |
|
1360 | + 'action' => 'edit', |
|
1361 | + 'post' => $this->ID(), |
|
1362 | + ), |
|
1363 | + admin_url('admin.php') |
|
1364 | + ); |
|
1365 | + } |
|
1366 | + |
|
1367 | + |
|
1368 | + /** |
|
1369 | + * Implementation for EEI_Admin_Links interface method. |
|
1370 | + * |
|
1371 | + * @see EEI_Admin_Links for comments |
|
1372 | + * @return string |
|
1373 | + */ |
|
1374 | + public function get_admin_settings_link() |
|
1375 | + { |
|
1376 | + return EEH_URL::add_query_args_and_nonce( |
|
1377 | + array( |
|
1378 | + 'page' => 'espresso_events', |
|
1379 | + 'action' => 'default_event_settings', |
|
1380 | + ), |
|
1381 | + admin_url('admin.php') |
|
1382 | + ); |
|
1383 | + } |
|
1384 | + |
|
1385 | + |
|
1386 | + /** |
|
1387 | + * Implementation for EEI_Admin_Links interface method. |
|
1388 | + * |
|
1389 | + * @see EEI_Admin_Links for comments |
|
1390 | + * @return string |
|
1391 | + */ |
|
1392 | + public function get_admin_overview_link() |
|
1393 | + { |
|
1394 | + return EEH_URL::add_query_args_and_nonce( |
|
1395 | + array( |
|
1396 | + 'page' => 'espresso_events', |
|
1397 | + 'action' => 'default', |
|
1398 | + ), |
|
1399 | + admin_url('admin.php') |
|
1400 | + ); |
|
1401 | + } |
|
1402 | 1402 | } |
@@ -27,151 +27,151 @@ |
||
27 | 27 | { |
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * @param EE_Registration $target_registration |
|
32 | - * @param EE_Registration $registration_to_copy |
|
33 | - * @return bool |
|
34 | - * @throws UnexpectedEntityException |
|
35 | - * @throws EntityNotFoundException |
|
36 | - * @throws RuntimeException |
|
37 | - * @throws EE_Error |
|
38 | - */ |
|
39 | - public function copyRegistrationDetails( |
|
40 | - EE_Registration $target_registration, |
|
41 | - EE_Registration $registration_to_copy |
|
42 | - ) { |
|
43 | - // copy attendee |
|
44 | - $target_registration->set_attendee_id($registration_to_copy->attendee_ID()); |
|
45 | - $target_registration->updateStatusBasedOnTotalPaid(false); |
|
46 | - $target_registration->save(); |
|
47 | - // get answers to previous reg questions |
|
48 | - $answers = $this->reindexAnswersByQuestionId($registration_to_copy->answers()); |
|
49 | - // get questions to new event reg form |
|
50 | - $new_event = $target_registration->event(); |
|
51 | - $field_name = 'Event_Question_Group.' |
|
52 | - . EEM_Event_Question_Group::instance()->fieldNameForContext( |
|
53 | - $registration_to_copy->is_primary_registrant() |
|
54 | - ); |
|
55 | - $question_groups = $new_event->question_groups([ |
|
56 | - [ |
|
57 | - 'Event.EVT_ID' => $new_event->ID(), |
|
58 | - $field_name => true, |
|
59 | - ], |
|
60 | - 'order_by' => ['QSG_order' => 'ASC'], |
|
61 | - ]); |
|
62 | - foreach ($question_groups as $question_group) { |
|
63 | - if ($question_group instanceof \EE_Question_Group) { |
|
64 | - foreach ($question_group->questions() as $question) { |
|
65 | - if ($question instanceof EE_Question) { |
|
66 | - $this->generateNewAnswer( |
|
67 | - $question, |
|
68 | - $target_registration, |
|
69 | - $answers |
|
70 | - ); |
|
71 | - } |
|
72 | - } |
|
73 | - } |
|
74 | - } |
|
75 | - return true; |
|
76 | - } |
|
30 | + /** |
|
31 | + * @param EE_Registration $target_registration |
|
32 | + * @param EE_Registration $registration_to_copy |
|
33 | + * @return bool |
|
34 | + * @throws UnexpectedEntityException |
|
35 | + * @throws EntityNotFoundException |
|
36 | + * @throws RuntimeException |
|
37 | + * @throws EE_Error |
|
38 | + */ |
|
39 | + public function copyRegistrationDetails( |
|
40 | + EE_Registration $target_registration, |
|
41 | + EE_Registration $registration_to_copy |
|
42 | + ) { |
|
43 | + // copy attendee |
|
44 | + $target_registration->set_attendee_id($registration_to_copy->attendee_ID()); |
|
45 | + $target_registration->updateStatusBasedOnTotalPaid(false); |
|
46 | + $target_registration->save(); |
|
47 | + // get answers to previous reg questions |
|
48 | + $answers = $this->reindexAnswersByQuestionId($registration_to_copy->answers()); |
|
49 | + // get questions to new event reg form |
|
50 | + $new_event = $target_registration->event(); |
|
51 | + $field_name = 'Event_Question_Group.' |
|
52 | + . EEM_Event_Question_Group::instance()->fieldNameForContext( |
|
53 | + $registration_to_copy->is_primary_registrant() |
|
54 | + ); |
|
55 | + $question_groups = $new_event->question_groups([ |
|
56 | + [ |
|
57 | + 'Event.EVT_ID' => $new_event->ID(), |
|
58 | + $field_name => true, |
|
59 | + ], |
|
60 | + 'order_by' => ['QSG_order' => 'ASC'], |
|
61 | + ]); |
|
62 | + foreach ($question_groups as $question_group) { |
|
63 | + if ($question_group instanceof \EE_Question_Group) { |
|
64 | + foreach ($question_group->questions() as $question) { |
|
65 | + if ($question instanceof EE_Question) { |
|
66 | + $this->generateNewAnswer( |
|
67 | + $question, |
|
68 | + $target_registration, |
|
69 | + $answers |
|
70 | + ); |
|
71 | + } |
|
72 | + } |
|
73 | + } |
|
74 | + } |
|
75 | + return true; |
|
76 | + } |
|
77 | 77 | |
78 | 78 | |
79 | - /** |
|
80 | - * @param EE_Answer[] $answers |
|
81 | - * @return array |
|
82 | - * @throws EE_Error |
|
83 | - */ |
|
84 | - protected function reindexAnswersByQuestionId(array $answers) |
|
85 | - { |
|
86 | - $reindexed_answers = array(); |
|
87 | - foreach ($answers as $answer) { |
|
88 | - if ($answer instanceof EE_Answer) { |
|
89 | - $reindexed_answers[ $answer->question_ID() ] = $answer->value(); |
|
90 | - } |
|
91 | - } |
|
92 | - return $reindexed_answers; |
|
93 | - } |
|
79 | + /** |
|
80 | + * @param EE_Answer[] $answers |
|
81 | + * @return array |
|
82 | + * @throws EE_Error |
|
83 | + */ |
|
84 | + protected function reindexAnswersByQuestionId(array $answers) |
|
85 | + { |
|
86 | + $reindexed_answers = array(); |
|
87 | + foreach ($answers as $answer) { |
|
88 | + if ($answer instanceof EE_Answer) { |
|
89 | + $reindexed_answers[ $answer->question_ID() ] = $answer->value(); |
|
90 | + } |
|
91 | + } |
|
92 | + return $reindexed_answers; |
|
93 | + } |
|
94 | 94 | |
95 | 95 | |
96 | - /** |
|
97 | - * @param EE_Question $question |
|
98 | - * @param EE_Registration $registration |
|
99 | - * @param $previous_answers |
|
100 | - * @return EE_Answer |
|
101 | - * @throws UnexpectedEntityException |
|
102 | - * @throws EE_Error |
|
103 | - */ |
|
104 | - protected function generateNewAnswer( |
|
105 | - EE_Question $question, |
|
106 | - EE_Registration $registration, |
|
107 | - $previous_answers |
|
108 | - ) { |
|
109 | - $old_answer_value = isset($previous_answers[ $question->ID() ]) |
|
110 | - ? $previous_answers[ $question->ID() ] |
|
111 | - : ''; |
|
112 | - $new_answer = EE_Answer::new_instance( |
|
113 | - array( |
|
114 | - 'QST_ID' => $question->ID(), |
|
115 | - 'REG_ID' => $registration->ID(), |
|
116 | - 'ANS_value' => $old_answer_value, |
|
117 | - ) |
|
118 | - ); |
|
119 | - if (! $new_answer instanceof EE_Answer) { |
|
120 | - throw new UnexpectedEntityException($new_answer, 'EE_Answer'); |
|
121 | - } |
|
122 | - $new_answer->save(); |
|
123 | - return $new_answer; |
|
124 | - } |
|
96 | + /** |
|
97 | + * @param EE_Question $question |
|
98 | + * @param EE_Registration $registration |
|
99 | + * @param $previous_answers |
|
100 | + * @return EE_Answer |
|
101 | + * @throws UnexpectedEntityException |
|
102 | + * @throws EE_Error |
|
103 | + */ |
|
104 | + protected function generateNewAnswer( |
|
105 | + EE_Question $question, |
|
106 | + EE_Registration $registration, |
|
107 | + $previous_answers |
|
108 | + ) { |
|
109 | + $old_answer_value = isset($previous_answers[ $question->ID() ]) |
|
110 | + ? $previous_answers[ $question->ID() ] |
|
111 | + : ''; |
|
112 | + $new_answer = EE_Answer::new_instance( |
|
113 | + array( |
|
114 | + 'QST_ID' => $question->ID(), |
|
115 | + 'REG_ID' => $registration->ID(), |
|
116 | + 'ANS_value' => $old_answer_value, |
|
117 | + ) |
|
118 | + ); |
|
119 | + if (! $new_answer instanceof EE_Answer) { |
|
120 | + throw new UnexpectedEntityException($new_answer, 'EE_Answer'); |
|
121 | + } |
|
122 | + $new_answer->save(); |
|
123 | + return $new_answer; |
|
124 | + } |
|
125 | 125 | |
126 | 126 | |
127 | - /** |
|
128 | - * @param EE_Registration $target_registration |
|
129 | - * @param EE_Registration $registration_to_copy |
|
130 | - * @return bool |
|
131 | - * @throws RuntimeException |
|
132 | - * @throws UnexpectedEntityException |
|
133 | - * @throws EE_Error |
|
134 | - */ |
|
135 | - public function copyPaymentDetails( |
|
136 | - EE_Registration $target_registration, |
|
137 | - EE_Registration $registration_to_copy |
|
138 | - ) { |
|
139 | - $save = false; |
|
140 | - $previous_registration_payments = $registration_to_copy->registration_payments(); |
|
141 | - $new_registration_payment_total = 0; |
|
142 | - $registration_to_copy_total = $registration_to_copy->paid(); |
|
143 | - foreach ($previous_registration_payments as $previous_registration_payment) { |
|
144 | - if ($previous_registration_payment instanceof EE_Registration_Payment |
|
145 | - && $previous_registration_payment->payment() instanceof EE_Payment |
|
146 | - && $previous_registration_payment->payment()->is_approved() |
|
147 | - ) { |
|
148 | - $payment_amount = $previous_registration_payment->amount(); |
|
149 | - $new_registration_payment = EE_Registration_Payment::new_instance( |
|
150 | - array( |
|
151 | - 'REG_ID' => $target_registration->ID(), |
|
152 | - 'PAY_ID' => $previous_registration_payment->payment()->ID(), |
|
153 | - 'RPY_amount' => $payment_amount, |
|
154 | - ) |
|
155 | - ); |
|
156 | - if (! $new_registration_payment instanceof EE_Registration_Payment) { |
|
157 | - throw new UnexpectedEntityException($new_registration_payment, 'EE_Registration_Payment'); |
|
158 | - } |
|
159 | - $new_registration_payment->save(); |
|
160 | - // if new reg payment is good, then set old reg payment amount to zero |
|
161 | - $previous_registration_payment->set_amount(0); |
|
162 | - $previous_registration_payment->save(); |
|
163 | - // now increment/decrement payment amounts |
|
164 | - $new_registration_payment_total += $payment_amount; |
|
165 | - $registration_to_copy_total -= $payment_amount; |
|
166 | - $save = true; |
|
167 | - } |
|
168 | - } |
|
169 | - if ($save) { |
|
170 | - $target_registration->set_paid($new_registration_payment_total); |
|
171 | - $target_registration->save(); |
|
172 | - $registration_to_copy->set_paid($registration_to_copy_total); |
|
173 | - $registration_to_copy->save(); |
|
174 | - } |
|
175 | - return true; |
|
176 | - } |
|
127 | + /** |
|
128 | + * @param EE_Registration $target_registration |
|
129 | + * @param EE_Registration $registration_to_copy |
|
130 | + * @return bool |
|
131 | + * @throws RuntimeException |
|
132 | + * @throws UnexpectedEntityException |
|
133 | + * @throws EE_Error |
|
134 | + */ |
|
135 | + public function copyPaymentDetails( |
|
136 | + EE_Registration $target_registration, |
|
137 | + EE_Registration $registration_to_copy |
|
138 | + ) { |
|
139 | + $save = false; |
|
140 | + $previous_registration_payments = $registration_to_copy->registration_payments(); |
|
141 | + $new_registration_payment_total = 0; |
|
142 | + $registration_to_copy_total = $registration_to_copy->paid(); |
|
143 | + foreach ($previous_registration_payments as $previous_registration_payment) { |
|
144 | + if ($previous_registration_payment instanceof EE_Registration_Payment |
|
145 | + && $previous_registration_payment->payment() instanceof EE_Payment |
|
146 | + && $previous_registration_payment->payment()->is_approved() |
|
147 | + ) { |
|
148 | + $payment_amount = $previous_registration_payment->amount(); |
|
149 | + $new_registration_payment = EE_Registration_Payment::new_instance( |
|
150 | + array( |
|
151 | + 'REG_ID' => $target_registration->ID(), |
|
152 | + 'PAY_ID' => $previous_registration_payment->payment()->ID(), |
|
153 | + 'RPY_amount' => $payment_amount, |
|
154 | + ) |
|
155 | + ); |
|
156 | + if (! $new_registration_payment instanceof EE_Registration_Payment) { |
|
157 | + throw new UnexpectedEntityException($new_registration_payment, 'EE_Registration_Payment'); |
|
158 | + } |
|
159 | + $new_registration_payment->save(); |
|
160 | + // if new reg payment is good, then set old reg payment amount to zero |
|
161 | + $previous_registration_payment->set_amount(0); |
|
162 | + $previous_registration_payment->save(); |
|
163 | + // now increment/decrement payment amounts |
|
164 | + $new_registration_payment_total += $payment_amount; |
|
165 | + $registration_to_copy_total -= $payment_amount; |
|
166 | + $save = true; |
|
167 | + } |
|
168 | + } |
|
169 | + if ($save) { |
|
170 | + $target_registration->set_paid($new_registration_payment_total); |
|
171 | + $target_registration->save(); |
|
172 | + $registration_to_copy->set_paid($registration_to_copy_total); |
|
173 | + $registration_to_copy->save(); |
|
174 | + } |
|
175 | + return true; |
|
176 | + } |
|
177 | 177 | } |
@@ -278,7 +278,7 @@ discard block |
||
278 | 278 | 'WP_User' => new EE_Belongs_To_Relation(), |
279 | 279 | ); |
280 | 280 | // this model is generally available for reading |
281 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
281 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Public(); |
|
282 | 282 | $this->model_chain_to_password = ''; |
283 | 283 | parent::__construct($timezone); |
284 | 284 | } |
@@ -371,7 +371,7 @@ discard block |
||
371 | 371 | */ |
372 | 372 | public function get_all_event_question_groups($EVT_ID = 0) |
373 | 373 | { |
374 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
374 | + if ( ! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
375 | 375 | EE_Error::add_error( |
376 | 376 | esc_html__( |
377 | 377 | 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
@@ -405,7 +405,7 @@ discard block |
||
405 | 405 | */ |
406 | 406 | public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true) |
407 | 407 | { |
408 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
408 | + if ( ! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
409 | 409 | EE_Error::add_error( |
410 | 410 | esc_html__( |
411 | 411 | // @codingStandardsIgnoreStart |
@@ -448,7 +448,7 @@ discard block |
||
448 | 448 | */ |
449 | 449 | public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration) |
450 | 450 | { |
451 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
451 | + if ( ! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
452 | 452 | EE_Error::add_error( |
453 | 453 | esc_html__( |
454 | 454 | 'An error occurred. No Question Groups could be retrieved because an Event ID was not received.', |
@@ -861,11 +861,11 @@ discard block |
||
861 | 861 | $questions = array(); |
862 | 862 | // get all question groups for event |
863 | 863 | $qgs = $this->get_question_groups_for_event($EVT_ID, $registration); |
864 | - if (! empty($qgs)) { |
|
864 | + if ( ! empty($qgs)) { |
|
865 | 865 | foreach ($qgs as $qg) { |
866 | 866 | $qsts = $qg->questions(); |
867 | - $questions[ $qg->ID() ] = $qg->model_field_array(); |
|
868 | - $questions[ $qg->ID() ]['QSG_questions'] = array(); |
|
867 | + $questions[$qg->ID()] = $qg->model_field_array(); |
|
868 | + $questions[$qg->ID()]['QSG_questions'] = array(); |
|
869 | 869 | foreach ($qsts as $qst) { |
870 | 870 | if ($qst->is_system_question()) { |
871 | 871 | continue; |
@@ -879,26 +879,26 @@ discard block |
||
879 | 879 | $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object(); |
880 | 880 | $qst_name = $qstn_id = $qst->ID(); |
881 | 881 | $ans_id = $answer->ID(); |
882 | - $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']'; |
|
882 | + $qst_name = ! empty($ans_id) ? '['.$qst_name.']['.$ans_id.']' : '['.$qst_name.']'; |
|
883 | 883 | $input_name = ''; |
884 | 884 | $input_id = sanitize_key($qst->display_text()); |
885 | 885 | $input_class = ''; |
886 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ] = $qst->model_field_array(); |
|
887 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name'] = 'qstn' |
|
886 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()] = $qst->model_field_array(); |
|
887 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn' |
|
888 | 888 | . $input_name |
889 | 889 | . $qst_name; |
890 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id'] = $input_id . '-' . $qstn_id; |
|
891 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class; |
|
892 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'] = array(); |
|
893 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj'] = $qst; |
|
894 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj'] = $answer; |
|
890 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id.'-'.$qstn_id; |
|
891 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class; |
|
892 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'] = array(); |
|
893 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj'] = $qst; |
|
894 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['ans_obj'] = $answer; |
|
895 | 895 | // leave responses as-is, don't convert stuff into html entities please! |
896 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['htmlentities'] = false; |
|
896 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['htmlentities'] = false; |
|
897 | 897 | if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') { |
898 | 898 | $QSOs = $qst->options(true, $answer->value()); |
899 | 899 | if (is_array($QSOs)) { |
900 | 900 | foreach ($QSOs as $QSO_ID => $QSO) { |
901 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] = $QSO->model_field_array(); |
|
901 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'][$QSO_ID] = $QSO->model_field_array(); |
|
902 | 902 | } |
903 | 903 | } |
904 | 904 | } |
@@ -15,913 +15,913 @@ |
||
15 | 15 | class EEM_Event extends EEM_CPT_Base |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the |
|
20 | - * event |
|
21 | - */ |
|
22 | - const sold_out = 'sold_out'; |
|
23 | - |
|
24 | - /** |
|
25 | - * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later |
|
26 | - * date) |
|
27 | - */ |
|
28 | - const postponed = 'postponed'; |
|
29 | - |
|
30 | - /** |
|
31 | - * constant used by status(), indicating that the event will no longer occur |
|
32 | - */ |
|
33 | - const cancelled = 'cancelled'; |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * @var string |
|
38 | - */ |
|
39 | - protected static $_default_reg_status; |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * This is the default for the additional limit field. |
|
44 | - * @var int |
|
45 | - */ |
|
46 | - protected static $_default_additional_limit = 10; |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * private instance of the Event object |
|
51 | - * |
|
52 | - * @var EEM_Event |
|
53 | - */ |
|
54 | - protected static $_instance; |
|
55 | - |
|
56 | - |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * Adds a relationship to Term_Taxonomy for each CPT_Base |
|
61 | - * |
|
62 | - * @param string $timezone |
|
63 | - * @throws \EE_Error |
|
64 | - */ |
|
65 | - protected function __construct($timezone = null) |
|
66 | - { |
|
67 | - EE_Registry::instance()->load_model('Registration'); |
|
68 | - $this->singular_item = esc_html__('Event', 'event_espresso'); |
|
69 | - $this->plural_item = esc_html__('Events', 'event_espresso'); |
|
70 | - // to remove Cancelled events from the frontend, copy the following filter to your functions.php file |
|
71 | - // add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' ); |
|
72 | - // to remove Postponed events from the frontend, copy the following filter to your functions.php file |
|
73 | - // add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' ); |
|
74 | - // to remove Sold Out events from the frontend, copy the following filter to your functions.php file |
|
75 | - // add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' ); |
|
76 | - $this->_custom_stati = apply_filters( |
|
77 | - 'AFEE__EEM_Event__construct___custom_stati', |
|
78 | - array( |
|
79 | - EEM_Event::cancelled => array( |
|
80 | - 'label' => esc_html__('Cancelled', 'event_espresso'), |
|
81 | - 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true), |
|
82 | - ), |
|
83 | - EEM_Event::postponed => array( |
|
84 | - 'label' => esc_html__('Postponed', 'event_espresso'), |
|
85 | - 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true), |
|
86 | - ), |
|
87 | - EEM_Event::sold_out => array( |
|
88 | - 'label' => esc_html__('Sold Out', 'event_espresso'), |
|
89 | - 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true), |
|
90 | - ), |
|
91 | - ) |
|
92 | - ); |
|
93 | - self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment |
|
94 | - : self::$_default_reg_status; |
|
95 | - $this->_tables = array( |
|
96 | - 'Event_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
97 | - 'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'), |
|
98 | - ); |
|
99 | - $this->_fields = array( |
|
100 | - 'Event_CPT' => array( |
|
101 | - 'EVT_ID' => new EE_Primary_Key_Int_Field( |
|
102 | - 'ID', |
|
103 | - esc_html__('Post ID for Event', 'event_espresso') |
|
104 | - ), |
|
105 | - 'EVT_name' => new EE_Plain_Text_Field( |
|
106 | - 'post_title', |
|
107 | - esc_html__('Event Name', 'event_espresso'), |
|
108 | - false, |
|
109 | - '' |
|
110 | - ), |
|
111 | - 'EVT_desc' => new EE_Post_Content_Field( |
|
112 | - 'post_content', |
|
113 | - esc_html__('Event Description', 'event_espresso'), |
|
114 | - false, |
|
115 | - '' |
|
116 | - ), |
|
117 | - 'EVT_slug' => new EE_Slug_Field( |
|
118 | - 'post_name', |
|
119 | - esc_html__('Event Slug', 'event_espresso'), |
|
120 | - false, |
|
121 | - '' |
|
122 | - ), |
|
123 | - 'EVT_created' => new EE_Datetime_Field( |
|
124 | - 'post_date', |
|
125 | - esc_html__('Date/Time Event Created', 'event_espresso'), |
|
126 | - false, |
|
127 | - EE_Datetime_Field::now |
|
128 | - ), |
|
129 | - 'EVT_short_desc' => new EE_Simple_HTML_Field( |
|
130 | - 'post_excerpt', |
|
131 | - esc_html__('Event Short Description', 'event_espresso'), |
|
132 | - false, |
|
133 | - '' |
|
134 | - ), |
|
135 | - 'EVT_modified' => new EE_Datetime_Field( |
|
136 | - 'post_modified', |
|
137 | - esc_html__('Date/Time Event Modified', 'event_espresso'), |
|
138 | - false, |
|
139 | - EE_Datetime_Field::now |
|
140 | - ), |
|
141 | - 'EVT_wp_user' => new EE_WP_User_Field( |
|
142 | - 'post_author', |
|
143 | - esc_html__('Event Creator ID', 'event_espresso'), |
|
144 | - false |
|
145 | - ), |
|
146 | - 'parent' => new EE_Integer_Field( |
|
147 | - 'post_parent', |
|
148 | - esc_html__('Event Parent ID', 'event_espresso'), |
|
149 | - false, |
|
150 | - 0 |
|
151 | - ), |
|
152 | - 'EVT_order' => new EE_Integer_Field( |
|
153 | - 'menu_order', |
|
154 | - esc_html__('Event Menu Order', 'event_espresso'), |
|
155 | - false, |
|
156 | - 1 |
|
157 | - ), |
|
158 | - 'post_type' => new EE_WP_Post_Type_Field('espresso_events'), |
|
159 | - // EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ), |
|
160 | - 'status' => new EE_WP_Post_Status_Field( |
|
161 | - 'post_status', |
|
162 | - esc_html__('Event Status', 'event_espresso'), |
|
163 | - false, |
|
164 | - 'draft', |
|
165 | - $this->_custom_stati |
|
166 | - ), |
|
167 | - 'password' => new EE_Password_Field( |
|
168 | - 'post_password', |
|
169 | - __('Password', 'event_espresso'), |
|
170 | - false, |
|
171 | - '', |
|
172 | - array( |
|
173 | - 'EVT_desc', |
|
174 | - 'EVT_short_desc', |
|
175 | - 'EVT_display_desc', |
|
176 | - 'EVT_display_ticket_selector', |
|
177 | - 'EVT_visible_on', |
|
178 | - 'EVT_additional_limit', |
|
179 | - 'EVT_default_registration_status', |
|
180 | - 'EVT_member_only', |
|
181 | - 'EVT_phone', |
|
182 | - 'EVT_allow_overflow', |
|
183 | - 'EVT_timezone_string', |
|
184 | - 'EVT_external_URL', |
|
185 | - 'EVT_donations' |
|
186 | - ) |
|
187 | - ) |
|
188 | - ), |
|
189 | - 'Event_Meta' => array( |
|
190 | - 'EVTM_ID' => new EE_DB_Only_Float_Field( |
|
191 | - 'EVTM_ID', |
|
192 | - esc_html__('Event Meta Row ID', 'event_espresso'), |
|
193 | - false |
|
194 | - ), |
|
195 | - 'EVT_ID_fk' => new EE_DB_Only_Int_Field( |
|
196 | - 'EVT_ID', |
|
197 | - esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'), |
|
198 | - false |
|
199 | - ), |
|
200 | - 'EVT_display_desc' => new EE_Boolean_Field( |
|
201 | - 'EVT_display_desc', |
|
202 | - esc_html__('Display Description Flag', 'event_espresso'), |
|
203 | - false, |
|
204 | - true |
|
205 | - ), |
|
206 | - 'EVT_display_ticket_selector' => new EE_Boolean_Field( |
|
207 | - 'EVT_display_ticket_selector', |
|
208 | - esc_html__('Display Ticket Selector Flag', 'event_espresso'), |
|
209 | - false, |
|
210 | - true |
|
211 | - ), |
|
212 | - 'EVT_visible_on' => new EE_Datetime_Field( |
|
213 | - 'EVT_visible_on', |
|
214 | - esc_html__('Event Visible Date', 'event_espresso'), |
|
215 | - true, |
|
216 | - EE_Datetime_Field::now |
|
217 | - ), |
|
218 | - 'EVT_additional_limit' => new EE_Integer_Field( |
|
219 | - 'EVT_additional_limit', |
|
220 | - esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
221 | - true, |
|
222 | - self::$_default_additional_limit |
|
223 | - ), |
|
224 | - 'EVT_default_registration_status' => new EE_Enum_Text_Field( |
|
225 | - 'EVT_default_registration_status', |
|
226 | - esc_html__('Default Registration Status on this Event', 'event_espresso'), |
|
227 | - false, |
|
228 | - EEM_Event::$_default_reg_status, |
|
229 | - EEM_Registration::reg_status_array() |
|
230 | - ), |
|
231 | - 'EVT_member_only' => new EE_Boolean_Field( |
|
232 | - 'EVT_member_only', |
|
233 | - esc_html__('Member-Only Event Flag', 'event_espresso'), |
|
234 | - false, |
|
235 | - false |
|
236 | - ), |
|
237 | - 'EVT_phone' => new EE_Plain_Text_Field( |
|
238 | - 'EVT_phone', |
|
239 | - esc_html__('Event Phone Number', 'event_espresso'), |
|
240 | - false, |
|
241 | - '' |
|
242 | - ), |
|
243 | - 'EVT_allow_overflow' => new EE_Boolean_Field( |
|
244 | - 'EVT_allow_overflow', |
|
245 | - esc_html__('Allow Overflow on Event', 'event_espresso'), |
|
246 | - false, |
|
247 | - false |
|
248 | - ), |
|
249 | - 'EVT_timezone_string' => new EE_Plain_Text_Field( |
|
250 | - 'EVT_timezone_string', |
|
251 | - esc_html__('Timezone (name) for Event times', 'event_espresso'), |
|
252 | - false, |
|
253 | - '' |
|
254 | - ), |
|
255 | - 'EVT_external_URL' => new EE_Plain_Text_Field( |
|
256 | - 'EVT_external_URL', |
|
257 | - esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'), |
|
258 | - true |
|
259 | - ), |
|
260 | - 'EVT_donations' => new EE_Boolean_Field( |
|
261 | - 'EVT_donations', |
|
262 | - esc_html__('Accept Donations?', 'event_espresso'), |
|
263 | - false, |
|
264 | - false |
|
265 | - ), |
|
266 | - ), |
|
267 | - ); |
|
268 | - $this->_model_relations = array( |
|
269 | - 'Registration' => new EE_Has_Many_Relation(), |
|
270 | - 'Datetime' => new EE_Has_Many_Relation(), |
|
271 | - 'Question_Group' => new EE_HABTM_Relation('Event_Question_Group'), |
|
272 | - 'Event_Question_Group' => new EE_Has_Many_Relation(), |
|
273 | - 'Venue' => new EE_HABTM_Relation('Event_Venue'), |
|
274 | - 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
275 | - 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
276 | - 'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'), |
|
277 | - 'Attendee' => new EE_HABTM_Relation('Registration'), |
|
278 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
279 | - ); |
|
280 | - // this model is generally available for reading |
|
281 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
282 | - $this->model_chain_to_password = ''; |
|
283 | - parent::__construct($timezone); |
|
284 | - } |
|
285 | - |
|
286 | - |
|
287 | - |
|
288 | - /** |
|
289 | - * @param string $default_reg_status |
|
290 | - */ |
|
291 | - public static function set_default_reg_status($default_reg_status) |
|
292 | - { |
|
293 | - self::$_default_reg_status = $default_reg_status; |
|
294 | - // if EEM_Event has already been instantiated, |
|
295 | - // then we need to reset the `EVT_default_reg_status` field to use the new default. |
|
296 | - if (self::$_instance instanceof EEM_Event) { |
|
297 | - $default_reg_status = new EE_Enum_Text_Field( |
|
298 | - 'EVT_default_registration_status', |
|
299 | - esc_html__('Default Registration Status on this Event', 'event_espresso'), |
|
300 | - false, |
|
301 | - $default_reg_status, |
|
302 | - EEM_Registration::reg_status_array() |
|
303 | - ); |
|
304 | - $default_reg_status->_construct_finalize( |
|
305 | - 'Event_Meta', |
|
306 | - 'EVT_default_registration_status', |
|
307 | - 'EEM_Event' |
|
308 | - ); |
|
309 | - self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status; |
|
310 | - } |
|
311 | - } |
|
312 | - |
|
313 | - |
|
314 | - /** |
|
315 | - * Used to override the default for the additional limit field. |
|
316 | - * @param $additional_limit |
|
317 | - */ |
|
318 | - public static function set_default_additional_limit($additional_limit) |
|
319 | - { |
|
320 | - self::$_default_additional_limit = (int) $additional_limit; |
|
321 | - if (self::$_instance instanceof EEM_Event) { |
|
322 | - self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field( |
|
323 | - 'EVT_additional_limit', |
|
324 | - __('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
325 | - true, |
|
326 | - self::$_default_additional_limit |
|
327 | - ); |
|
328 | - self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize( |
|
329 | - 'Event_Meta', |
|
330 | - 'EVT_additional_limit', |
|
331 | - 'EEM_Event' |
|
332 | - ); |
|
333 | - } |
|
334 | - } |
|
335 | - |
|
336 | - |
|
337 | - /** |
|
338 | - * Return what is currently set as the default additional limit for the event. |
|
339 | - * @return int |
|
340 | - */ |
|
341 | - public static function get_default_additional_limit() |
|
342 | - { |
|
343 | - return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit); |
|
344 | - } |
|
345 | - |
|
346 | - |
|
347 | - /** |
|
348 | - * get_question_groups |
|
349 | - * |
|
350 | - * @return array |
|
351 | - * @throws \EE_Error |
|
352 | - */ |
|
353 | - public function get_all_question_groups() |
|
354 | - { |
|
355 | - return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
356 | - array( |
|
357 | - array('QSG_deleted' => false), |
|
358 | - 'order_by' => array('QSG_order' => 'ASC'), |
|
359 | - ) |
|
360 | - ); |
|
361 | - } |
|
362 | - |
|
363 | - |
|
364 | - |
|
365 | - /** |
|
366 | - * get_question_groups |
|
367 | - * |
|
368 | - * @param int $EVT_ID |
|
369 | - * @return array|bool |
|
370 | - * @throws \EE_Error |
|
371 | - */ |
|
372 | - public function get_all_event_question_groups($EVT_ID = 0) |
|
373 | - { |
|
374 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
375 | - EE_Error::add_error( |
|
376 | - esc_html__( |
|
377 | - 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
378 | - 'event_espresso' |
|
379 | - ), |
|
380 | - __FILE__, |
|
381 | - __FUNCTION__, |
|
382 | - __LINE__ |
|
383 | - ); |
|
384 | - return false; |
|
385 | - } |
|
386 | - return EE_Registry::instance()->load_model('Event_Question_Group')->get_all( |
|
387 | - array( |
|
388 | - array('EVT_ID' => $EVT_ID), |
|
389 | - ) |
|
390 | - ); |
|
391 | - } |
|
392 | - |
|
393 | - |
|
394 | - /** |
|
395 | - * get_question_groups |
|
396 | - * |
|
397 | - * @param int $EVT_ID |
|
398 | - * @param boolean $for_primary_attendee |
|
399 | - * @return array|bool |
|
400 | - * @throws EE_Error |
|
401 | - * @throws InvalidArgumentException |
|
402 | - * @throws ReflectionException |
|
403 | - * @throws InvalidDataTypeException |
|
404 | - * @throws InvalidInterfaceException |
|
405 | - */ |
|
406 | - public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true) |
|
407 | - { |
|
408 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
409 | - EE_Error::add_error( |
|
410 | - esc_html__( |
|
411 | - // @codingStandardsIgnoreStart |
|
412 | - 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
413 | - // @codingStandardsIgnoreEnd |
|
414 | - 'event_espresso' |
|
415 | - ), |
|
416 | - __FILE__, |
|
417 | - __FUNCTION__, |
|
418 | - __LINE__ |
|
419 | - ); |
|
420 | - return false; |
|
421 | - } |
|
422 | - $query_params = [ |
|
423 | - [ |
|
424 | - 'EVT_ID' => $EVT_ID, |
|
425 | - EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary_attendee) => true |
|
426 | - ] |
|
427 | - ]; |
|
428 | - if ($for_primary_attendee) { |
|
429 | - $query_params[0]['EQG_primary'] = true; |
|
430 | - } else { |
|
431 | - $query_params[0]['EQG_additional'] = true; |
|
432 | - } |
|
433 | - return EE_Registry::instance()->load_model('Event_Question_Group')->get_all($query_params); |
|
434 | - } |
|
435 | - |
|
436 | - |
|
437 | - /** |
|
438 | - * get_question_groups |
|
439 | - * |
|
440 | - * @param int $EVT_ID |
|
441 | - * @param EE_Registration $registration |
|
442 | - * @return array|bool |
|
443 | - * @throws EE_Error |
|
444 | - * @throws InvalidArgumentException |
|
445 | - * @throws InvalidDataTypeException |
|
446 | - * @throws InvalidInterfaceException |
|
447 | - * @throws ReflectionException |
|
448 | - */ |
|
449 | - public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration) |
|
450 | - { |
|
451 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
452 | - EE_Error::add_error( |
|
453 | - esc_html__( |
|
454 | - 'An error occurred. No Question Groups could be retrieved because an Event ID was not received.', |
|
455 | - 'event_espresso' |
|
456 | - ), |
|
457 | - __FILE__, |
|
458 | - __FUNCTION__, |
|
459 | - __LINE__ |
|
460 | - ); |
|
461 | - return false; |
|
462 | - } |
|
463 | - return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
464 | - [ |
|
465 | - [ |
|
466 | - 'Event_Question_Group.EVT_ID' => $EVT_ID, |
|
467 | - 'Event_Question_Group.' |
|
468 | - . EEM_Event_Question_Group::instance()->fieldNameForContext( |
|
469 | - $registration->is_primary_registrant() |
|
470 | - ) => true |
|
471 | - ], |
|
472 | - 'order_by' => ['QSG_order' => 'ASC'], |
|
473 | - ] |
|
474 | - ); |
|
475 | - } |
|
476 | - |
|
477 | - |
|
478 | - |
|
479 | - /** |
|
480 | - * get_question_target_db_column |
|
481 | - * |
|
482 | - * @param string $QSG_IDs csv list of $QSG IDs |
|
483 | - * @return array|bool |
|
484 | - * @throws \EE_Error |
|
485 | - */ |
|
486 | - public function get_questions_in_groups($QSG_IDs = '') |
|
487 | - { |
|
488 | - if (empty($QSG_IDs)) { |
|
489 | - EE_Error::add_error( |
|
490 | - esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'), |
|
491 | - __FILE__, |
|
492 | - __FUNCTION__, |
|
493 | - __LINE__ |
|
494 | - ); |
|
495 | - return false; |
|
496 | - } |
|
497 | - return EE_Registry::instance()->load_model('Question')->get_all( |
|
498 | - array( |
|
499 | - array( |
|
500 | - 'Question_Group.QSG_ID' => array('IN', $QSG_IDs), |
|
501 | - 'QST_deleted' => false, |
|
502 | - 'QST_admin_only' => is_admin(), |
|
503 | - ), |
|
504 | - 'order_by' => 'QST_order', |
|
505 | - ) |
|
506 | - ); |
|
507 | - } |
|
508 | - |
|
509 | - |
|
510 | - |
|
511 | - /** |
|
512 | - * get_options_for_question |
|
513 | - * |
|
514 | - * @param string $QST_IDs csv list of $QST IDs |
|
515 | - * @return array|bool |
|
516 | - * @throws \EE_Error |
|
517 | - */ |
|
518 | - public function get_options_for_question($QST_IDs) |
|
519 | - { |
|
520 | - if (empty($QST_IDs)) { |
|
521 | - EE_Error::add_error( |
|
522 | - esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'), |
|
523 | - __FILE__, |
|
524 | - __FUNCTION__, |
|
525 | - __LINE__ |
|
526 | - ); |
|
527 | - return false; |
|
528 | - } |
|
529 | - return EE_Registry::instance()->load_model('Question_Option')->get_all( |
|
530 | - array( |
|
531 | - array( |
|
532 | - 'Question.QST_ID' => array('IN', $QST_IDs), |
|
533 | - 'QSO_deleted' => false, |
|
534 | - ), |
|
535 | - 'order_by' => 'QSO_ID', |
|
536 | - ) |
|
537 | - ); |
|
538 | - } |
|
539 | - |
|
540 | - |
|
541 | - |
|
542 | - |
|
543 | - |
|
544 | - |
|
545 | - |
|
546 | - /** |
|
547 | - * Gets all events that are published |
|
548 | - * and have event start time earlier than now and an event end time later than now |
|
549 | - * |
|
550 | - * @param array $query_params An array of query params to further filter on |
|
551 | - * (note that status and DTT_EVT_start and DTT_EVT_end will be overridden) |
|
552 | - * @param bool $count whether to return the count or not (default FALSE) |
|
553 | - * @return EE_Event[]|int |
|
554 | - * @throws \EE_Error |
|
555 | - */ |
|
556 | - public function get_active_events($query_params, $count = false) |
|
557 | - { |
|
558 | - if (array_key_exists(0, $query_params)) { |
|
559 | - $where_params = $query_params[0]; |
|
560 | - unset($query_params[0]); |
|
561 | - } else { |
|
562 | - $where_params = array(); |
|
563 | - } |
|
564 | - // if we have count make sure we don't include group by |
|
565 | - if ($count && isset($query_params['group_by'])) { |
|
566 | - unset($query_params['group_by']); |
|
567 | - } |
|
568 | - // let's add specific query_params for active_events |
|
569 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
570 | - $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
571 | - // if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions |
|
572 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
573 | - $where_params['Datetime.DTT_EVT_start******'] = array( |
|
574 | - '<', |
|
575 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
576 | - ); |
|
577 | - } else { |
|
578 | - $where_params['Datetime.DTT_EVT_start'] = array( |
|
579 | - '<', |
|
580 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
581 | - ); |
|
582 | - } |
|
583 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
584 | - $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
585 | - '>', |
|
586 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
587 | - ); |
|
588 | - } else { |
|
589 | - $where_params['Datetime.DTT_EVT_end'] = array( |
|
590 | - '>', |
|
591 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
592 | - ); |
|
593 | - } |
|
594 | - $query_params[0] = $where_params; |
|
595 | - // don't use $query_params with count() |
|
596 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
597 | - return $count |
|
598 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
599 | - : $this->get_all($query_params); |
|
600 | - } |
|
601 | - |
|
602 | - |
|
603 | - |
|
604 | - /** |
|
605 | - * get all events that are published and have an event start time later than now |
|
606 | - * |
|
607 | - * @param array $query_params An array of query params to further filter on |
|
608 | - * (Note that status and DTT_EVT_start will be overridden) |
|
609 | - * @param bool $count whether to return the count or not (default FALSE) |
|
610 | - * @return EE_Event[]|int |
|
611 | - * @throws \EE_Error |
|
612 | - */ |
|
613 | - public function get_upcoming_events($query_params, $count = false) |
|
614 | - { |
|
615 | - if (array_key_exists(0, $query_params)) { |
|
616 | - $where_params = $query_params[0]; |
|
617 | - unset($query_params[0]); |
|
618 | - } else { |
|
619 | - $where_params = array(); |
|
620 | - } |
|
621 | - // if we have count make sure we don't include group by |
|
622 | - if ($count && isset($query_params['group_by'])) { |
|
623 | - unset($query_params['group_by']); |
|
624 | - } |
|
625 | - // let's add specific query_params for active_events |
|
626 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
627 | - $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
628 | - // if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
|
629 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
630 | - $where_params['Datetime.DTT_EVT_start*****'] = array( |
|
631 | - '>', |
|
632 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
633 | - ); |
|
634 | - } else { |
|
635 | - $where_params['Datetime.DTT_EVT_start'] = array( |
|
636 | - '>', |
|
637 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
638 | - ); |
|
639 | - } |
|
640 | - $query_params[0] = $where_params; |
|
641 | - // don't use $query_params with count() |
|
642 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
643 | - return $count |
|
644 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
645 | - : $this->get_all($query_params); |
|
646 | - } |
|
647 | - |
|
648 | - |
|
649 | - |
|
650 | - /** |
|
651 | - * Gets all events that are published |
|
652 | - * and have an event end time later than now |
|
653 | - * |
|
654 | - * @param array $query_params An array of query params to further filter on |
|
655 | - * (note that status and DTT_EVT_end will be overridden) |
|
656 | - * @param bool $count whether to return the count or not (default FALSE) |
|
657 | - * @return EE_Event[]|int |
|
658 | - * @throws \EE_Error |
|
659 | - */ |
|
660 | - public function get_active_and_upcoming_events($query_params, $count = false) |
|
661 | - { |
|
662 | - if (array_key_exists(0, $query_params)) { |
|
663 | - $where_params = $query_params[0]; |
|
664 | - unset($query_params[0]); |
|
665 | - } else { |
|
666 | - $where_params = array(); |
|
667 | - } |
|
668 | - // if we have count make sure we don't include group by |
|
669 | - if ($count && isset($query_params['group_by'])) { |
|
670 | - unset($query_params['group_by']); |
|
671 | - } |
|
672 | - // let's add specific query_params for active_events |
|
673 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
674 | - $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
675 | - // add where params for DTT_EVT_end |
|
676 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
677 | - $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
678 | - '>', |
|
679 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
680 | - ); |
|
681 | - } else { |
|
682 | - $where_params['Datetime.DTT_EVT_end'] = array( |
|
683 | - '>', |
|
684 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
685 | - ); |
|
686 | - } |
|
687 | - $query_params[0] = $where_params; |
|
688 | - // don't use $query_params with count() |
|
689 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
690 | - return $count |
|
691 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
692 | - : $this->get_all($query_params); |
|
693 | - } |
|
694 | - |
|
695 | - |
|
696 | - |
|
697 | - /** |
|
698 | - * This only returns events that are expired. |
|
699 | - * They may still be published but all their datetimes have expired. |
|
700 | - * |
|
701 | - * @param array $query_params An array of query params to further filter on |
|
702 | - * (note that status and DTT_EVT_end will be overridden) |
|
703 | - * @param bool $count whether to return the count or not (default FALSE) |
|
704 | - * @return EE_Event[]|int |
|
705 | - * @throws \EE_Error |
|
706 | - */ |
|
707 | - public function get_expired_events($query_params, $count = false) |
|
708 | - { |
|
709 | - $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
710 | - // if we have count make sure we don't include group by |
|
711 | - if ($count && isset($query_params['group_by'])) { |
|
712 | - unset($query_params['group_by']); |
|
713 | - } |
|
714 | - // let's add specific query_params for active_events |
|
715 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
716 | - if (isset($where_params['status'])) { |
|
717 | - unset($where_params['status']); |
|
718 | - } |
|
719 | - $exclude_query = $query_params; |
|
720 | - if (isset($exclude_query[0])) { |
|
721 | - unset($exclude_query[0]); |
|
722 | - } |
|
723 | - $exclude_query[0] = array( |
|
724 | - 'Datetime.DTT_EVT_end' => array( |
|
725 | - '>', |
|
726 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
727 | - ), |
|
728 | - ); |
|
729 | - // first get all events that have datetimes where its not expired. |
|
730 | - $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID'); |
|
731 | - $event_ids = array_keys($event_ids); |
|
732 | - // if we have any additional query_params, let's add them to the 'AND' condition |
|
733 | - $and_condition = array( |
|
734 | - 'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')), |
|
735 | - 'EVT_ID' => array('NOT IN', $event_ids), |
|
736 | - ); |
|
737 | - if (isset($where_params['OR'])) { |
|
738 | - $and_condition['OR'] = $where_params['OR']; |
|
739 | - unset($where_params['OR']); |
|
740 | - } |
|
741 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
742 | - $and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
743 | - unset($where_params['Datetime.DTT_EVT_end']); |
|
744 | - } |
|
745 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
746 | - $and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
747 | - unset($where_params['Datetime.DTT_EVT_start']); |
|
748 | - } |
|
749 | - // merge remaining $where params with the and conditions. |
|
750 | - $where_params['AND'] = array_merge($and_condition, $where_params); |
|
751 | - $query_params[0] = $where_params; |
|
752 | - // don't use $query_params with count() |
|
753 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
754 | - return $count |
|
755 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
756 | - : $this->get_all($query_params); |
|
757 | - } |
|
758 | - |
|
759 | - |
|
760 | - |
|
761 | - /** |
|
762 | - * This basically just returns the events that do not have the publish status. |
|
763 | - * |
|
764 | - * @param array $query_params An array of query params to further filter on |
|
765 | - * (note that status will be overwritten) |
|
766 | - * @param boolean $count whether to return the count or not (default FALSE) |
|
767 | - * @return EE_Event[]|int |
|
768 | - * @throws \EE_Error |
|
769 | - */ |
|
770 | - public function get_inactive_events($query_params, $count = false) |
|
771 | - { |
|
772 | - $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
773 | - // let's add in specific query_params for inactive events. |
|
774 | - if (isset($where_params['status'])) { |
|
775 | - unset($where_params['status']); |
|
776 | - } |
|
777 | - // if we have count make sure we don't include group by |
|
778 | - if ($count && isset($query_params['group_by'])) { |
|
779 | - unset($query_params['group_by']); |
|
780 | - } |
|
781 | - // if we have any additional query_params, let's add them to the 'AND' condition |
|
782 | - $where_params['AND']['status'] = array('!=', 'publish'); |
|
783 | - if (isset($where_params['OR'])) { |
|
784 | - $where_params['AND']['OR'] = $where_params['OR']; |
|
785 | - unset($where_params['OR']); |
|
786 | - } |
|
787 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
788 | - $where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
789 | - unset($where_params['Datetime.DTT_EVT_end']); |
|
790 | - } |
|
791 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
792 | - $where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
793 | - unset($where_params['Datetime.DTT_EVT_start']); |
|
794 | - } |
|
795 | - $query_params[0] = $where_params; |
|
796 | - // don't use $query_params with count() |
|
797 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
798 | - return $count |
|
799 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
800 | - : $this->get_all($query_params); |
|
801 | - } |
|
802 | - |
|
803 | - |
|
804 | - |
|
805 | - /** |
|
806 | - * This is just injecting into the parent add_relationship_to so we do special handling on price relationships |
|
807 | - * because we don't want to override any existing global default prices but instead insert NEW prices that get |
|
808 | - * attached to the event. See parent for param descriptions |
|
809 | - * |
|
810 | - * @param $id_or_obj |
|
811 | - * @param $other_model_id_or_obj |
|
812 | - * @param string $relationName |
|
813 | - * @param array $where_query |
|
814 | - * @return EE_Base_Class |
|
815 | - * @throws EE_Error |
|
816 | - */ |
|
817 | - public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) |
|
818 | - { |
|
819 | - if ($relationName === 'Price') { |
|
820 | - // let's get the PRC object for the given ID to make sure that we aren't dealing with a default |
|
821 | - $prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj); |
|
822 | - // if EVT_ID = 0, then this is a default |
|
823 | - if ((int) $prc_chk->get('EVT_ID') === 0) { |
|
824 | - // let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation |
|
825 | - $prc_chk->set('PRC_ID', 0); |
|
826 | - } |
|
827 | - // run parent |
|
828 | - return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query); |
|
829 | - } |
|
830 | - // otherwise carry on as normal |
|
831 | - return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query); |
|
832 | - } |
|
833 | - |
|
834 | - |
|
835 | - |
|
836 | - /******************** DEPRECATED METHODS ********************/ |
|
837 | - |
|
838 | - |
|
839 | - |
|
840 | - /** |
|
841 | - * _get_question_target_db_column |
|
842 | - * |
|
843 | - * @deprecated as of 4.8.32.rc.001. Instead consider using |
|
844 | - * EE_Registration_Custom_Questions_Form located in |
|
845 | - * admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php |
|
846 | - * @access public |
|
847 | - * @param EE_Registration $registration (so existing answers for registration are included) |
|
848 | - * @param int $EVT_ID so all question groups are included for event (not just answers from |
|
849 | - * registration). |
|
850 | - * @throws EE_Error |
|
851 | - * @return array |
|
852 | - */ |
|
853 | - public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0) |
|
854 | - { |
|
855 | - if (empty($EVT_ID)) { |
|
856 | - throw new EE_Error(__( |
|
857 | - 'An error occurred. No EVT_ID is included. Needed to know which question groups to retrieve.', |
|
858 | - 'event_espresso' |
|
859 | - )); |
|
860 | - } |
|
861 | - $questions = array(); |
|
862 | - // get all question groups for event |
|
863 | - $qgs = $this->get_question_groups_for_event($EVT_ID, $registration); |
|
864 | - if (! empty($qgs)) { |
|
865 | - foreach ($qgs as $qg) { |
|
866 | - $qsts = $qg->questions(); |
|
867 | - $questions[ $qg->ID() ] = $qg->model_field_array(); |
|
868 | - $questions[ $qg->ID() ]['QSG_questions'] = array(); |
|
869 | - foreach ($qsts as $qst) { |
|
870 | - if ($qst->is_system_question()) { |
|
871 | - continue; |
|
872 | - } |
|
873 | - $answer = EEM_Answer::instance()->get_one(array( |
|
874 | - array( |
|
875 | - 'QST_ID' => $qst->ID(), |
|
876 | - 'REG_ID' => $registration->ID(), |
|
877 | - ), |
|
878 | - )); |
|
879 | - $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object(); |
|
880 | - $qst_name = $qstn_id = $qst->ID(); |
|
881 | - $ans_id = $answer->ID(); |
|
882 | - $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']'; |
|
883 | - $input_name = ''; |
|
884 | - $input_id = sanitize_key($qst->display_text()); |
|
885 | - $input_class = ''; |
|
886 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ] = $qst->model_field_array(); |
|
887 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name'] = 'qstn' |
|
888 | - . $input_name |
|
889 | - . $qst_name; |
|
890 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id'] = $input_id . '-' . $qstn_id; |
|
891 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class; |
|
892 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'] = array(); |
|
893 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj'] = $qst; |
|
894 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj'] = $answer; |
|
895 | - // leave responses as-is, don't convert stuff into html entities please! |
|
896 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['htmlentities'] = false; |
|
897 | - if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') { |
|
898 | - $QSOs = $qst->options(true, $answer->value()); |
|
899 | - if (is_array($QSOs)) { |
|
900 | - foreach ($QSOs as $QSO_ID => $QSO) { |
|
901 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] = $QSO->model_field_array(); |
|
902 | - } |
|
903 | - } |
|
904 | - } |
|
905 | - } |
|
906 | - } |
|
907 | - } |
|
908 | - return $questions; |
|
909 | - } |
|
910 | - |
|
911 | - |
|
912 | - /** |
|
913 | - * @param mixed $cols_n_values either an array of where each key is the name of a field, and the value is its value |
|
914 | - * or an stdClass where each property is the name of a column, |
|
915 | - * @return EE_Base_Class |
|
916 | - * @throws \EE_Error |
|
917 | - */ |
|
918 | - public function instantiate_class_from_array_or_object($cols_n_values) |
|
919 | - { |
|
920 | - $classInstance = parent::instantiate_class_from_array_or_object($cols_n_values); |
|
921 | - if ($classInstance instanceof EE_Event) { |
|
922 | - // events have their timezone defined in the DB, so use it immediately |
|
923 | - $this->set_timezone($classInstance->get_timezone()); |
|
924 | - } |
|
925 | - return $classInstance; |
|
926 | - } |
|
18 | + /** |
|
19 | + * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the |
|
20 | + * event |
|
21 | + */ |
|
22 | + const sold_out = 'sold_out'; |
|
23 | + |
|
24 | + /** |
|
25 | + * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later |
|
26 | + * date) |
|
27 | + */ |
|
28 | + const postponed = 'postponed'; |
|
29 | + |
|
30 | + /** |
|
31 | + * constant used by status(), indicating that the event will no longer occur |
|
32 | + */ |
|
33 | + const cancelled = 'cancelled'; |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * @var string |
|
38 | + */ |
|
39 | + protected static $_default_reg_status; |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * This is the default for the additional limit field. |
|
44 | + * @var int |
|
45 | + */ |
|
46 | + protected static $_default_additional_limit = 10; |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * private instance of the Event object |
|
51 | + * |
|
52 | + * @var EEM_Event |
|
53 | + */ |
|
54 | + protected static $_instance; |
|
55 | + |
|
56 | + |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * Adds a relationship to Term_Taxonomy for each CPT_Base |
|
61 | + * |
|
62 | + * @param string $timezone |
|
63 | + * @throws \EE_Error |
|
64 | + */ |
|
65 | + protected function __construct($timezone = null) |
|
66 | + { |
|
67 | + EE_Registry::instance()->load_model('Registration'); |
|
68 | + $this->singular_item = esc_html__('Event', 'event_espresso'); |
|
69 | + $this->plural_item = esc_html__('Events', 'event_espresso'); |
|
70 | + // to remove Cancelled events from the frontend, copy the following filter to your functions.php file |
|
71 | + // add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' ); |
|
72 | + // to remove Postponed events from the frontend, copy the following filter to your functions.php file |
|
73 | + // add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' ); |
|
74 | + // to remove Sold Out events from the frontend, copy the following filter to your functions.php file |
|
75 | + // add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' ); |
|
76 | + $this->_custom_stati = apply_filters( |
|
77 | + 'AFEE__EEM_Event__construct___custom_stati', |
|
78 | + array( |
|
79 | + EEM_Event::cancelled => array( |
|
80 | + 'label' => esc_html__('Cancelled', 'event_espresso'), |
|
81 | + 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true), |
|
82 | + ), |
|
83 | + EEM_Event::postponed => array( |
|
84 | + 'label' => esc_html__('Postponed', 'event_espresso'), |
|
85 | + 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true), |
|
86 | + ), |
|
87 | + EEM_Event::sold_out => array( |
|
88 | + 'label' => esc_html__('Sold Out', 'event_espresso'), |
|
89 | + 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true), |
|
90 | + ), |
|
91 | + ) |
|
92 | + ); |
|
93 | + self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment |
|
94 | + : self::$_default_reg_status; |
|
95 | + $this->_tables = array( |
|
96 | + 'Event_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
97 | + 'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'), |
|
98 | + ); |
|
99 | + $this->_fields = array( |
|
100 | + 'Event_CPT' => array( |
|
101 | + 'EVT_ID' => new EE_Primary_Key_Int_Field( |
|
102 | + 'ID', |
|
103 | + esc_html__('Post ID for Event', 'event_espresso') |
|
104 | + ), |
|
105 | + 'EVT_name' => new EE_Plain_Text_Field( |
|
106 | + 'post_title', |
|
107 | + esc_html__('Event Name', 'event_espresso'), |
|
108 | + false, |
|
109 | + '' |
|
110 | + ), |
|
111 | + 'EVT_desc' => new EE_Post_Content_Field( |
|
112 | + 'post_content', |
|
113 | + esc_html__('Event Description', 'event_espresso'), |
|
114 | + false, |
|
115 | + '' |
|
116 | + ), |
|
117 | + 'EVT_slug' => new EE_Slug_Field( |
|
118 | + 'post_name', |
|
119 | + esc_html__('Event Slug', 'event_espresso'), |
|
120 | + false, |
|
121 | + '' |
|
122 | + ), |
|
123 | + 'EVT_created' => new EE_Datetime_Field( |
|
124 | + 'post_date', |
|
125 | + esc_html__('Date/Time Event Created', 'event_espresso'), |
|
126 | + false, |
|
127 | + EE_Datetime_Field::now |
|
128 | + ), |
|
129 | + 'EVT_short_desc' => new EE_Simple_HTML_Field( |
|
130 | + 'post_excerpt', |
|
131 | + esc_html__('Event Short Description', 'event_espresso'), |
|
132 | + false, |
|
133 | + '' |
|
134 | + ), |
|
135 | + 'EVT_modified' => new EE_Datetime_Field( |
|
136 | + 'post_modified', |
|
137 | + esc_html__('Date/Time Event Modified', 'event_espresso'), |
|
138 | + false, |
|
139 | + EE_Datetime_Field::now |
|
140 | + ), |
|
141 | + 'EVT_wp_user' => new EE_WP_User_Field( |
|
142 | + 'post_author', |
|
143 | + esc_html__('Event Creator ID', 'event_espresso'), |
|
144 | + false |
|
145 | + ), |
|
146 | + 'parent' => new EE_Integer_Field( |
|
147 | + 'post_parent', |
|
148 | + esc_html__('Event Parent ID', 'event_espresso'), |
|
149 | + false, |
|
150 | + 0 |
|
151 | + ), |
|
152 | + 'EVT_order' => new EE_Integer_Field( |
|
153 | + 'menu_order', |
|
154 | + esc_html__('Event Menu Order', 'event_espresso'), |
|
155 | + false, |
|
156 | + 1 |
|
157 | + ), |
|
158 | + 'post_type' => new EE_WP_Post_Type_Field('espresso_events'), |
|
159 | + // EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ), |
|
160 | + 'status' => new EE_WP_Post_Status_Field( |
|
161 | + 'post_status', |
|
162 | + esc_html__('Event Status', 'event_espresso'), |
|
163 | + false, |
|
164 | + 'draft', |
|
165 | + $this->_custom_stati |
|
166 | + ), |
|
167 | + 'password' => new EE_Password_Field( |
|
168 | + 'post_password', |
|
169 | + __('Password', 'event_espresso'), |
|
170 | + false, |
|
171 | + '', |
|
172 | + array( |
|
173 | + 'EVT_desc', |
|
174 | + 'EVT_short_desc', |
|
175 | + 'EVT_display_desc', |
|
176 | + 'EVT_display_ticket_selector', |
|
177 | + 'EVT_visible_on', |
|
178 | + 'EVT_additional_limit', |
|
179 | + 'EVT_default_registration_status', |
|
180 | + 'EVT_member_only', |
|
181 | + 'EVT_phone', |
|
182 | + 'EVT_allow_overflow', |
|
183 | + 'EVT_timezone_string', |
|
184 | + 'EVT_external_URL', |
|
185 | + 'EVT_donations' |
|
186 | + ) |
|
187 | + ) |
|
188 | + ), |
|
189 | + 'Event_Meta' => array( |
|
190 | + 'EVTM_ID' => new EE_DB_Only_Float_Field( |
|
191 | + 'EVTM_ID', |
|
192 | + esc_html__('Event Meta Row ID', 'event_espresso'), |
|
193 | + false |
|
194 | + ), |
|
195 | + 'EVT_ID_fk' => new EE_DB_Only_Int_Field( |
|
196 | + 'EVT_ID', |
|
197 | + esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'), |
|
198 | + false |
|
199 | + ), |
|
200 | + 'EVT_display_desc' => new EE_Boolean_Field( |
|
201 | + 'EVT_display_desc', |
|
202 | + esc_html__('Display Description Flag', 'event_espresso'), |
|
203 | + false, |
|
204 | + true |
|
205 | + ), |
|
206 | + 'EVT_display_ticket_selector' => new EE_Boolean_Field( |
|
207 | + 'EVT_display_ticket_selector', |
|
208 | + esc_html__('Display Ticket Selector Flag', 'event_espresso'), |
|
209 | + false, |
|
210 | + true |
|
211 | + ), |
|
212 | + 'EVT_visible_on' => new EE_Datetime_Field( |
|
213 | + 'EVT_visible_on', |
|
214 | + esc_html__('Event Visible Date', 'event_espresso'), |
|
215 | + true, |
|
216 | + EE_Datetime_Field::now |
|
217 | + ), |
|
218 | + 'EVT_additional_limit' => new EE_Integer_Field( |
|
219 | + 'EVT_additional_limit', |
|
220 | + esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
221 | + true, |
|
222 | + self::$_default_additional_limit |
|
223 | + ), |
|
224 | + 'EVT_default_registration_status' => new EE_Enum_Text_Field( |
|
225 | + 'EVT_default_registration_status', |
|
226 | + esc_html__('Default Registration Status on this Event', 'event_espresso'), |
|
227 | + false, |
|
228 | + EEM_Event::$_default_reg_status, |
|
229 | + EEM_Registration::reg_status_array() |
|
230 | + ), |
|
231 | + 'EVT_member_only' => new EE_Boolean_Field( |
|
232 | + 'EVT_member_only', |
|
233 | + esc_html__('Member-Only Event Flag', 'event_espresso'), |
|
234 | + false, |
|
235 | + false |
|
236 | + ), |
|
237 | + 'EVT_phone' => new EE_Plain_Text_Field( |
|
238 | + 'EVT_phone', |
|
239 | + esc_html__('Event Phone Number', 'event_espresso'), |
|
240 | + false, |
|
241 | + '' |
|
242 | + ), |
|
243 | + 'EVT_allow_overflow' => new EE_Boolean_Field( |
|
244 | + 'EVT_allow_overflow', |
|
245 | + esc_html__('Allow Overflow on Event', 'event_espresso'), |
|
246 | + false, |
|
247 | + false |
|
248 | + ), |
|
249 | + 'EVT_timezone_string' => new EE_Plain_Text_Field( |
|
250 | + 'EVT_timezone_string', |
|
251 | + esc_html__('Timezone (name) for Event times', 'event_espresso'), |
|
252 | + false, |
|
253 | + '' |
|
254 | + ), |
|
255 | + 'EVT_external_URL' => new EE_Plain_Text_Field( |
|
256 | + 'EVT_external_URL', |
|
257 | + esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'), |
|
258 | + true |
|
259 | + ), |
|
260 | + 'EVT_donations' => new EE_Boolean_Field( |
|
261 | + 'EVT_donations', |
|
262 | + esc_html__('Accept Donations?', 'event_espresso'), |
|
263 | + false, |
|
264 | + false |
|
265 | + ), |
|
266 | + ), |
|
267 | + ); |
|
268 | + $this->_model_relations = array( |
|
269 | + 'Registration' => new EE_Has_Many_Relation(), |
|
270 | + 'Datetime' => new EE_Has_Many_Relation(), |
|
271 | + 'Question_Group' => new EE_HABTM_Relation('Event_Question_Group'), |
|
272 | + 'Event_Question_Group' => new EE_Has_Many_Relation(), |
|
273 | + 'Venue' => new EE_HABTM_Relation('Event_Venue'), |
|
274 | + 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
275 | + 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
276 | + 'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'), |
|
277 | + 'Attendee' => new EE_HABTM_Relation('Registration'), |
|
278 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
279 | + ); |
|
280 | + // this model is generally available for reading |
|
281 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
282 | + $this->model_chain_to_password = ''; |
|
283 | + parent::__construct($timezone); |
|
284 | + } |
|
285 | + |
|
286 | + |
|
287 | + |
|
288 | + /** |
|
289 | + * @param string $default_reg_status |
|
290 | + */ |
|
291 | + public static function set_default_reg_status($default_reg_status) |
|
292 | + { |
|
293 | + self::$_default_reg_status = $default_reg_status; |
|
294 | + // if EEM_Event has already been instantiated, |
|
295 | + // then we need to reset the `EVT_default_reg_status` field to use the new default. |
|
296 | + if (self::$_instance instanceof EEM_Event) { |
|
297 | + $default_reg_status = new EE_Enum_Text_Field( |
|
298 | + 'EVT_default_registration_status', |
|
299 | + esc_html__('Default Registration Status on this Event', 'event_espresso'), |
|
300 | + false, |
|
301 | + $default_reg_status, |
|
302 | + EEM_Registration::reg_status_array() |
|
303 | + ); |
|
304 | + $default_reg_status->_construct_finalize( |
|
305 | + 'Event_Meta', |
|
306 | + 'EVT_default_registration_status', |
|
307 | + 'EEM_Event' |
|
308 | + ); |
|
309 | + self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status; |
|
310 | + } |
|
311 | + } |
|
312 | + |
|
313 | + |
|
314 | + /** |
|
315 | + * Used to override the default for the additional limit field. |
|
316 | + * @param $additional_limit |
|
317 | + */ |
|
318 | + public static function set_default_additional_limit($additional_limit) |
|
319 | + { |
|
320 | + self::$_default_additional_limit = (int) $additional_limit; |
|
321 | + if (self::$_instance instanceof EEM_Event) { |
|
322 | + self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field( |
|
323 | + 'EVT_additional_limit', |
|
324 | + __('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
325 | + true, |
|
326 | + self::$_default_additional_limit |
|
327 | + ); |
|
328 | + self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize( |
|
329 | + 'Event_Meta', |
|
330 | + 'EVT_additional_limit', |
|
331 | + 'EEM_Event' |
|
332 | + ); |
|
333 | + } |
|
334 | + } |
|
335 | + |
|
336 | + |
|
337 | + /** |
|
338 | + * Return what is currently set as the default additional limit for the event. |
|
339 | + * @return int |
|
340 | + */ |
|
341 | + public static function get_default_additional_limit() |
|
342 | + { |
|
343 | + return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit); |
|
344 | + } |
|
345 | + |
|
346 | + |
|
347 | + /** |
|
348 | + * get_question_groups |
|
349 | + * |
|
350 | + * @return array |
|
351 | + * @throws \EE_Error |
|
352 | + */ |
|
353 | + public function get_all_question_groups() |
|
354 | + { |
|
355 | + return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
356 | + array( |
|
357 | + array('QSG_deleted' => false), |
|
358 | + 'order_by' => array('QSG_order' => 'ASC'), |
|
359 | + ) |
|
360 | + ); |
|
361 | + } |
|
362 | + |
|
363 | + |
|
364 | + |
|
365 | + /** |
|
366 | + * get_question_groups |
|
367 | + * |
|
368 | + * @param int $EVT_ID |
|
369 | + * @return array|bool |
|
370 | + * @throws \EE_Error |
|
371 | + */ |
|
372 | + public function get_all_event_question_groups($EVT_ID = 0) |
|
373 | + { |
|
374 | + if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
375 | + EE_Error::add_error( |
|
376 | + esc_html__( |
|
377 | + 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
378 | + 'event_espresso' |
|
379 | + ), |
|
380 | + __FILE__, |
|
381 | + __FUNCTION__, |
|
382 | + __LINE__ |
|
383 | + ); |
|
384 | + return false; |
|
385 | + } |
|
386 | + return EE_Registry::instance()->load_model('Event_Question_Group')->get_all( |
|
387 | + array( |
|
388 | + array('EVT_ID' => $EVT_ID), |
|
389 | + ) |
|
390 | + ); |
|
391 | + } |
|
392 | + |
|
393 | + |
|
394 | + /** |
|
395 | + * get_question_groups |
|
396 | + * |
|
397 | + * @param int $EVT_ID |
|
398 | + * @param boolean $for_primary_attendee |
|
399 | + * @return array|bool |
|
400 | + * @throws EE_Error |
|
401 | + * @throws InvalidArgumentException |
|
402 | + * @throws ReflectionException |
|
403 | + * @throws InvalidDataTypeException |
|
404 | + * @throws InvalidInterfaceException |
|
405 | + */ |
|
406 | + public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true) |
|
407 | + { |
|
408 | + if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
409 | + EE_Error::add_error( |
|
410 | + esc_html__( |
|
411 | + // @codingStandardsIgnoreStart |
|
412 | + 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
413 | + // @codingStandardsIgnoreEnd |
|
414 | + 'event_espresso' |
|
415 | + ), |
|
416 | + __FILE__, |
|
417 | + __FUNCTION__, |
|
418 | + __LINE__ |
|
419 | + ); |
|
420 | + return false; |
|
421 | + } |
|
422 | + $query_params = [ |
|
423 | + [ |
|
424 | + 'EVT_ID' => $EVT_ID, |
|
425 | + EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary_attendee) => true |
|
426 | + ] |
|
427 | + ]; |
|
428 | + if ($for_primary_attendee) { |
|
429 | + $query_params[0]['EQG_primary'] = true; |
|
430 | + } else { |
|
431 | + $query_params[0]['EQG_additional'] = true; |
|
432 | + } |
|
433 | + return EE_Registry::instance()->load_model('Event_Question_Group')->get_all($query_params); |
|
434 | + } |
|
435 | + |
|
436 | + |
|
437 | + /** |
|
438 | + * get_question_groups |
|
439 | + * |
|
440 | + * @param int $EVT_ID |
|
441 | + * @param EE_Registration $registration |
|
442 | + * @return array|bool |
|
443 | + * @throws EE_Error |
|
444 | + * @throws InvalidArgumentException |
|
445 | + * @throws InvalidDataTypeException |
|
446 | + * @throws InvalidInterfaceException |
|
447 | + * @throws ReflectionException |
|
448 | + */ |
|
449 | + public function get_question_groups_for_event($EVT_ID = 0, EE_Registration $registration) |
|
450 | + { |
|
451 | + if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
452 | + EE_Error::add_error( |
|
453 | + esc_html__( |
|
454 | + 'An error occurred. No Question Groups could be retrieved because an Event ID was not received.', |
|
455 | + 'event_espresso' |
|
456 | + ), |
|
457 | + __FILE__, |
|
458 | + __FUNCTION__, |
|
459 | + __LINE__ |
|
460 | + ); |
|
461 | + return false; |
|
462 | + } |
|
463 | + return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
464 | + [ |
|
465 | + [ |
|
466 | + 'Event_Question_Group.EVT_ID' => $EVT_ID, |
|
467 | + 'Event_Question_Group.' |
|
468 | + . EEM_Event_Question_Group::instance()->fieldNameForContext( |
|
469 | + $registration->is_primary_registrant() |
|
470 | + ) => true |
|
471 | + ], |
|
472 | + 'order_by' => ['QSG_order' => 'ASC'], |
|
473 | + ] |
|
474 | + ); |
|
475 | + } |
|
476 | + |
|
477 | + |
|
478 | + |
|
479 | + /** |
|
480 | + * get_question_target_db_column |
|
481 | + * |
|
482 | + * @param string $QSG_IDs csv list of $QSG IDs |
|
483 | + * @return array|bool |
|
484 | + * @throws \EE_Error |
|
485 | + */ |
|
486 | + public function get_questions_in_groups($QSG_IDs = '') |
|
487 | + { |
|
488 | + if (empty($QSG_IDs)) { |
|
489 | + EE_Error::add_error( |
|
490 | + esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'), |
|
491 | + __FILE__, |
|
492 | + __FUNCTION__, |
|
493 | + __LINE__ |
|
494 | + ); |
|
495 | + return false; |
|
496 | + } |
|
497 | + return EE_Registry::instance()->load_model('Question')->get_all( |
|
498 | + array( |
|
499 | + array( |
|
500 | + 'Question_Group.QSG_ID' => array('IN', $QSG_IDs), |
|
501 | + 'QST_deleted' => false, |
|
502 | + 'QST_admin_only' => is_admin(), |
|
503 | + ), |
|
504 | + 'order_by' => 'QST_order', |
|
505 | + ) |
|
506 | + ); |
|
507 | + } |
|
508 | + |
|
509 | + |
|
510 | + |
|
511 | + /** |
|
512 | + * get_options_for_question |
|
513 | + * |
|
514 | + * @param string $QST_IDs csv list of $QST IDs |
|
515 | + * @return array|bool |
|
516 | + * @throws \EE_Error |
|
517 | + */ |
|
518 | + public function get_options_for_question($QST_IDs) |
|
519 | + { |
|
520 | + if (empty($QST_IDs)) { |
|
521 | + EE_Error::add_error( |
|
522 | + esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'), |
|
523 | + __FILE__, |
|
524 | + __FUNCTION__, |
|
525 | + __LINE__ |
|
526 | + ); |
|
527 | + return false; |
|
528 | + } |
|
529 | + return EE_Registry::instance()->load_model('Question_Option')->get_all( |
|
530 | + array( |
|
531 | + array( |
|
532 | + 'Question.QST_ID' => array('IN', $QST_IDs), |
|
533 | + 'QSO_deleted' => false, |
|
534 | + ), |
|
535 | + 'order_by' => 'QSO_ID', |
|
536 | + ) |
|
537 | + ); |
|
538 | + } |
|
539 | + |
|
540 | + |
|
541 | + |
|
542 | + |
|
543 | + |
|
544 | + |
|
545 | + |
|
546 | + /** |
|
547 | + * Gets all events that are published |
|
548 | + * and have event start time earlier than now and an event end time later than now |
|
549 | + * |
|
550 | + * @param array $query_params An array of query params to further filter on |
|
551 | + * (note that status and DTT_EVT_start and DTT_EVT_end will be overridden) |
|
552 | + * @param bool $count whether to return the count or not (default FALSE) |
|
553 | + * @return EE_Event[]|int |
|
554 | + * @throws \EE_Error |
|
555 | + */ |
|
556 | + public function get_active_events($query_params, $count = false) |
|
557 | + { |
|
558 | + if (array_key_exists(0, $query_params)) { |
|
559 | + $where_params = $query_params[0]; |
|
560 | + unset($query_params[0]); |
|
561 | + } else { |
|
562 | + $where_params = array(); |
|
563 | + } |
|
564 | + // if we have count make sure we don't include group by |
|
565 | + if ($count && isset($query_params['group_by'])) { |
|
566 | + unset($query_params['group_by']); |
|
567 | + } |
|
568 | + // let's add specific query_params for active_events |
|
569 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
570 | + $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
571 | + // if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions |
|
572 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
573 | + $where_params['Datetime.DTT_EVT_start******'] = array( |
|
574 | + '<', |
|
575 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
576 | + ); |
|
577 | + } else { |
|
578 | + $where_params['Datetime.DTT_EVT_start'] = array( |
|
579 | + '<', |
|
580 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
581 | + ); |
|
582 | + } |
|
583 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
584 | + $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
585 | + '>', |
|
586 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
587 | + ); |
|
588 | + } else { |
|
589 | + $where_params['Datetime.DTT_EVT_end'] = array( |
|
590 | + '>', |
|
591 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
592 | + ); |
|
593 | + } |
|
594 | + $query_params[0] = $where_params; |
|
595 | + // don't use $query_params with count() |
|
596 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
597 | + return $count |
|
598 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
599 | + : $this->get_all($query_params); |
|
600 | + } |
|
601 | + |
|
602 | + |
|
603 | + |
|
604 | + /** |
|
605 | + * get all events that are published and have an event start time later than now |
|
606 | + * |
|
607 | + * @param array $query_params An array of query params to further filter on |
|
608 | + * (Note that status and DTT_EVT_start will be overridden) |
|
609 | + * @param bool $count whether to return the count or not (default FALSE) |
|
610 | + * @return EE_Event[]|int |
|
611 | + * @throws \EE_Error |
|
612 | + */ |
|
613 | + public function get_upcoming_events($query_params, $count = false) |
|
614 | + { |
|
615 | + if (array_key_exists(0, $query_params)) { |
|
616 | + $where_params = $query_params[0]; |
|
617 | + unset($query_params[0]); |
|
618 | + } else { |
|
619 | + $where_params = array(); |
|
620 | + } |
|
621 | + // if we have count make sure we don't include group by |
|
622 | + if ($count && isset($query_params['group_by'])) { |
|
623 | + unset($query_params['group_by']); |
|
624 | + } |
|
625 | + // let's add specific query_params for active_events |
|
626 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
627 | + $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
628 | + // if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
|
629 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
630 | + $where_params['Datetime.DTT_EVT_start*****'] = array( |
|
631 | + '>', |
|
632 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
633 | + ); |
|
634 | + } else { |
|
635 | + $where_params['Datetime.DTT_EVT_start'] = array( |
|
636 | + '>', |
|
637 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
638 | + ); |
|
639 | + } |
|
640 | + $query_params[0] = $where_params; |
|
641 | + // don't use $query_params with count() |
|
642 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
643 | + return $count |
|
644 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
645 | + : $this->get_all($query_params); |
|
646 | + } |
|
647 | + |
|
648 | + |
|
649 | + |
|
650 | + /** |
|
651 | + * Gets all events that are published |
|
652 | + * and have an event end time later than now |
|
653 | + * |
|
654 | + * @param array $query_params An array of query params to further filter on |
|
655 | + * (note that status and DTT_EVT_end will be overridden) |
|
656 | + * @param bool $count whether to return the count or not (default FALSE) |
|
657 | + * @return EE_Event[]|int |
|
658 | + * @throws \EE_Error |
|
659 | + */ |
|
660 | + public function get_active_and_upcoming_events($query_params, $count = false) |
|
661 | + { |
|
662 | + if (array_key_exists(0, $query_params)) { |
|
663 | + $where_params = $query_params[0]; |
|
664 | + unset($query_params[0]); |
|
665 | + } else { |
|
666 | + $where_params = array(); |
|
667 | + } |
|
668 | + // if we have count make sure we don't include group by |
|
669 | + if ($count && isset($query_params['group_by'])) { |
|
670 | + unset($query_params['group_by']); |
|
671 | + } |
|
672 | + // let's add specific query_params for active_events |
|
673 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
674 | + $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
675 | + // add where params for DTT_EVT_end |
|
676 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
677 | + $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
678 | + '>', |
|
679 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
680 | + ); |
|
681 | + } else { |
|
682 | + $where_params['Datetime.DTT_EVT_end'] = array( |
|
683 | + '>', |
|
684 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
685 | + ); |
|
686 | + } |
|
687 | + $query_params[0] = $where_params; |
|
688 | + // don't use $query_params with count() |
|
689 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
690 | + return $count |
|
691 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
692 | + : $this->get_all($query_params); |
|
693 | + } |
|
694 | + |
|
695 | + |
|
696 | + |
|
697 | + /** |
|
698 | + * This only returns events that are expired. |
|
699 | + * They may still be published but all their datetimes have expired. |
|
700 | + * |
|
701 | + * @param array $query_params An array of query params to further filter on |
|
702 | + * (note that status and DTT_EVT_end will be overridden) |
|
703 | + * @param bool $count whether to return the count or not (default FALSE) |
|
704 | + * @return EE_Event[]|int |
|
705 | + * @throws \EE_Error |
|
706 | + */ |
|
707 | + public function get_expired_events($query_params, $count = false) |
|
708 | + { |
|
709 | + $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
710 | + // if we have count make sure we don't include group by |
|
711 | + if ($count && isset($query_params['group_by'])) { |
|
712 | + unset($query_params['group_by']); |
|
713 | + } |
|
714 | + // let's add specific query_params for active_events |
|
715 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
716 | + if (isset($where_params['status'])) { |
|
717 | + unset($where_params['status']); |
|
718 | + } |
|
719 | + $exclude_query = $query_params; |
|
720 | + if (isset($exclude_query[0])) { |
|
721 | + unset($exclude_query[0]); |
|
722 | + } |
|
723 | + $exclude_query[0] = array( |
|
724 | + 'Datetime.DTT_EVT_end' => array( |
|
725 | + '>', |
|
726 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
727 | + ), |
|
728 | + ); |
|
729 | + // first get all events that have datetimes where its not expired. |
|
730 | + $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID'); |
|
731 | + $event_ids = array_keys($event_ids); |
|
732 | + // if we have any additional query_params, let's add them to the 'AND' condition |
|
733 | + $and_condition = array( |
|
734 | + 'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')), |
|
735 | + 'EVT_ID' => array('NOT IN', $event_ids), |
|
736 | + ); |
|
737 | + if (isset($where_params['OR'])) { |
|
738 | + $and_condition['OR'] = $where_params['OR']; |
|
739 | + unset($where_params['OR']); |
|
740 | + } |
|
741 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
742 | + $and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
743 | + unset($where_params['Datetime.DTT_EVT_end']); |
|
744 | + } |
|
745 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
746 | + $and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
747 | + unset($where_params['Datetime.DTT_EVT_start']); |
|
748 | + } |
|
749 | + // merge remaining $where params with the and conditions. |
|
750 | + $where_params['AND'] = array_merge($and_condition, $where_params); |
|
751 | + $query_params[0] = $where_params; |
|
752 | + // don't use $query_params with count() |
|
753 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
754 | + return $count |
|
755 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
756 | + : $this->get_all($query_params); |
|
757 | + } |
|
758 | + |
|
759 | + |
|
760 | + |
|
761 | + /** |
|
762 | + * This basically just returns the events that do not have the publish status. |
|
763 | + * |
|
764 | + * @param array $query_params An array of query params to further filter on |
|
765 | + * (note that status will be overwritten) |
|
766 | + * @param boolean $count whether to return the count or not (default FALSE) |
|
767 | + * @return EE_Event[]|int |
|
768 | + * @throws \EE_Error |
|
769 | + */ |
|
770 | + public function get_inactive_events($query_params, $count = false) |
|
771 | + { |
|
772 | + $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
773 | + // let's add in specific query_params for inactive events. |
|
774 | + if (isset($where_params['status'])) { |
|
775 | + unset($where_params['status']); |
|
776 | + } |
|
777 | + // if we have count make sure we don't include group by |
|
778 | + if ($count && isset($query_params['group_by'])) { |
|
779 | + unset($query_params['group_by']); |
|
780 | + } |
|
781 | + // if we have any additional query_params, let's add them to the 'AND' condition |
|
782 | + $where_params['AND']['status'] = array('!=', 'publish'); |
|
783 | + if (isset($where_params['OR'])) { |
|
784 | + $where_params['AND']['OR'] = $where_params['OR']; |
|
785 | + unset($where_params['OR']); |
|
786 | + } |
|
787 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
788 | + $where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
789 | + unset($where_params['Datetime.DTT_EVT_end']); |
|
790 | + } |
|
791 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
792 | + $where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
793 | + unset($where_params['Datetime.DTT_EVT_start']); |
|
794 | + } |
|
795 | + $query_params[0] = $where_params; |
|
796 | + // don't use $query_params with count() |
|
797 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
798 | + return $count |
|
799 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
800 | + : $this->get_all($query_params); |
|
801 | + } |
|
802 | + |
|
803 | + |
|
804 | + |
|
805 | + /** |
|
806 | + * This is just injecting into the parent add_relationship_to so we do special handling on price relationships |
|
807 | + * because we don't want to override any existing global default prices but instead insert NEW prices that get |
|
808 | + * attached to the event. See parent for param descriptions |
|
809 | + * |
|
810 | + * @param $id_or_obj |
|
811 | + * @param $other_model_id_or_obj |
|
812 | + * @param string $relationName |
|
813 | + * @param array $where_query |
|
814 | + * @return EE_Base_Class |
|
815 | + * @throws EE_Error |
|
816 | + */ |
|
817 | + public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) |
|
818 | + { |
|
819 | + if ($relationName === 'Price') { |
|
820 | + // let's get the PRC object for the given ID to make sure that we aren't dealing with a default |
|
821 | + $prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj); |
|
822 | + // if EVT_ID = 0, then this is a default |
|
823 | + if ((int) $prc_chk->get('EVT_ID') === 0) { |
|
824 | + // let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation |
|
825 | + $prc_chk->set('PRC_ID', 0); |
|
826 | + } |
|
827 | + // run parent |
|
828 | + return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query); |
|
829 | + } |
|
830 | + // otherwise carry on as normal |
|
831 | + return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query); |
|
832 | + } |
|
833 | + |
|
834 | + |
|
835 | + |
|
836 | + /******************** DEPRECATED METHODS ********************/ |
|
837 | + |
|
838 | + |
|
839 | + |
|
840 | + /** |
|
841 | + * _get_question_target_db_column |
|
842 | + * |
|
843 | + * @deprecated as of 4.8.32.rc.001. Instead consider using |
|
844 | + * EE_Registration_Custom_Questions_Form located in |
|
845 | + * admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php |
|
846 | + * @access public |
|
847 | + * @param EE_Registration $registration (so existing answers for registration are included) |
|
848 | + * @param int $EVT_ID so all question groups are included for event (not just answers from |
|
849 | + * registration). |
|
850 | + * @throws EE_Error |
|
851 | + * @return array |
|
852 | + */ |
|
853 | + public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0) |
|
854 | + { |
|
855 | + if (empty($EVT_ID)) { |
|
856 | + throw new EE_Error(__( |
|
857 | + 'An error occurred. No EVT_ID is included. Needed to know which question groups to retrieve.', |
|
858 | + 'event_espresso' |
|
859 | + )); |
|
860 | + } |
|
861 | + $questions = array(); |
|
862 | + // get all question groups for event |
|
863 | + $qgs = $this->get_question_groups_for_event($EVT_ID, $registration); |
|
864 | + if (! empty($qgs)) { |
|
865 | + foreach ($qgs as $qg) { |
|
866 | + $qsts = $qg->questions(); |
|
867 | + $questions[ $qg->ID() ] = $qg->model_field_array(); |
|
868 | + $questions[ $qg->ID() ]['QSG_questions'] = array(); |
|
869 | + foreach ($qsts as $qst) { |
|
870 | + if ($qst->is_system_question()) { |
|
871 | + continue; |
|
872 | + } |
|
873 | + $answer = EEM_Answer::instance()->get_one(array( |
|
874 | + array( |
|
875 | + 'QST_ID' => $qst->ID(), |
|
876 | + 'REG_ID' => $registration->ID(), |
|
877 | + ), |
|
878 | + )); |
|
879 | + $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object(); |
|
880 | + $qst_name = $qstn_id = $qst->ID(); |
|
881 | + $ans_id = $answer->ID(); |
|
882 | + $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']'; |
|
883 | + $input_name = ''; |
|
884 | + $input_id = sanitize_key($qst->display_text()); |
|
885 | + $input_class = ''; |
|
886 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ] = $qst->model_field_array(); |
|
887 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name'] = 'qstn' |
|
888 | + . $input_name |
|
889 | + . $qst_name; |
|
890 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id'] = $input_id . '-' . $qstn_id; |
|
891 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class; |
|
892 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'] = array(); |
|
893 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj'] = $qst; |
|
894 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj'] = $answer; |
|
895 | + // leave responses as-is, don't convert stuff into html entities please! |
|
896 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['htmlentities'] = false; |
|
897 | + if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') { |
|
898 | + $QSOs = $qst->options(true, $answer->value()); |
|
899 | + if (is_array($QSOs)) { |
|
900 | + foreach ($QSOs as $QSO_ID => $QSO) { |
|
901 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] = $QSO->model_field_array(); |
|
902 | + } |
|
903 | + } |
|
904 | + } |
|
905 | + } |
|
906 | + } |
|
907 | + } |
|
908 | + return $questions; |
|
909 | + } |
|
910 | + |
|
911 | + |
|
912 | + /** |
|
913 | + * @param mixed $cols_n_values either an array of where each key is the name of a field, and the value is its value |
|
914 | + * or an stdClass where each property is the name of a column, |
|
915 | + * @return EE_Base_Class |
|
916 | + * @throws \EE_Error |
|
917 | + */ |
|
918 | + public function instantiate_class_from_array_or_object($cols_n_values) |
|
919 | + { |
|
920 | + $classInstance = parent::instantiate_class_from_array_or_object($cols_n_values); |
|
921 | + if ($classInstance instanceof EE_Event) { |
|
922 | + // events have their timezone defined in the DB, so use it immediately |
|
923 | + $this->set_timezone($classInstance->get_timezone()); |
|
924 | + } |
|
925 | + return $classInstance; |
|
926 | + } |
|
927 | 927 | } |
@@ -16,15 +16,13 @@ discard block |
||
16 | 16 | 'EQG_primary'=>new EE_Boolean_Field('EQG_primary', __('Flag indicating question is only for primary attendees','event_espresso'), false, false) |
17 | 17 | ) |
18 | 18 | ); |
19 | - |
|
20 | - |
|
21 | 19 | * |
22 | 20 | */ |
23 | 21 | class EE_DMS_4_1_0_event_question_group extends EE_Data_Migration_Script_Stage_Table |
24 | 22 | { |
25 | - private $_new_table; |
|
26 | - public function _migrate_old_row($old_row) |
|
27 | - { |
|
23 | + private $_new_table; |
|
24 | + public function _migrate_old_row($old_row) |
|
25 | + { |
|
28 | 26 | // $txn_id = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $this->_new_transaction_table); |
29 | 27 | // if ( ! $txn_id ){ |
30 | 28 | // $this->add_error(sprintf(__("Could not find the transaction for the 3.1 attendee %d from row %s", "event_espresso"),$old_row['id'],$this->_json_encode($old_row))); |
@@ -34,8 +32,8 @@ discard block |
||
34 | 32 | // $new_line_items = $this->_insert_new_line_items($txn,$old_row); |
35 | 33 | // $this->get_migration_script()->set_mapping($this->_old_table,$old_row['id'],$this->_new_line_table,$new_line_items); |
36 | 34 | |
37 | - $this->_insert_new_event_question_groups($old_row); |
|
38 | - } |
|
35 | + $this->_insert_new_event_question_groups($old_row); |
|
36 | + } |
|
39 | 37 | // function _migration_step($num_items=50){ |
40 | 38 | // global $wpdb; |
41 | 39 | // $start_at_record = $this->count_records_migrated(); |
@@ -55,109 +53,109 @@ discard block |
||
55 | 53 | // $count = $wpdb->get_var("SELECT COUNT(id) FROM ".$this->_old_table); |
56 | 54 | // return $count; |
57 | 55 | // } |
58 | - public function __construct() |
|
59 | - { |
|
60 | - global $wpdb; |
|
61 | - $this->_old_table = $wpdb->prefix."events_detail"; |
|
62 | - $this->_extra_where_sql = 'WHERE event_status!="D"'; |
|
63 | - $this->_new_table = $wpdb->prefix."esp_event_question_group"; |
|
64 | - $this->_pretty_name = __("Question Groups in each Event", "event_espresso"); |
|
65 | - parent::__construct(); |
|
66 | - } |
|
56 | + public function __construct() |
|
57 | + { |
|
58 | + global $wpdb; |
|
59 | + $this->_old_table = $wpdb->prefix."events_detail"; |
|
60 | + $this->_extra_where_sql = 'WHERE event_status!="D"'; |
|
61 | + $this->_new_table = $wpdb->prefix."esp_event_question_group"; |
|
62 | + $this->_pretty_name = __("Question Groups in each Event", "event_espresso"); |
|
63 | + parent::__construct(); |
|
64 | + } |
|
67 | 65 | |
68 | - /** |
|
69 | - * Attempts to insert a new question group inthe new format given an old one |
|
70 | - * @global type $wpdb |
|
71 | - * @param array $old_event |
|
72 | - * @return void |
|
73 | - */ |
|
74 | - private function _insert_new_event_question_groups($old_event) |
|
75 | - { |
|
76 | - $new_event_question_group_ids = array(); |
|
77 | - $question_groups_for_primary = maybe_unserialize($old_event['question_groups']); |
|
78 | - if (is_array($question_groups_for_primary)) { |
|
79 | - foreach ($question_groups_for_primary as $old_question_group_id) { |
|
80 | - $new_id = $this->_insert_event_question_group($old_event, $old_question_group_id, true); |
|
81 | - if ($new_id) { |
|
82 | - $new_event_question_group_ids[] = $new_id; |
|
83 | - } |
|
84 | - } |
|
85 | - } |
|
86 | - $event_meta = maybe_unserialize($old_event['event_meta']); |
|
87 | - if (isset($event_meta['add_attendee_question_groups'])) { |
|
88 | - if (is_array($event_meta['add_attendee_question_groups'])) { |
|
89 | - foreach ($event_meta['add_attendee_question_groups'] as $old_question_group_id) { |
|
90 | - $new_id = $this->_insert_event_question_group($old_event, $old_question_group_id, false); |
|
91 | - if ($new_id) { |
|
92 | - $new_event_question_group_ids[] = $new_id; |
|
93 | - } |
|
94 | - } |
|
95 | - } |
|
96 | - } |
|
66 | + /** |
|
67 | + * Attempts to insert a new question group inthe new format given an old one |
|
68 | + * @global type $wpdb |
|
69 | + * @param array $old_event |
|
70 | + * @return void |
|
71 | + */ |
|
72 | + private function _insert_new_event_question_groups($old_event) |
|
73 | + { |
|
74 | + $new_event_question_group_ids = array(); |
|
75 | + $question_groups_for_primary = maybe_unserialize($old_event['question_groups']); |
|
76 | + if (is_array($question_groups_for_primary)) { |
|
77 | + foreach ($question_groups_for_primary as $old_question_group_id) { |
|
78 | + $new_id = $this->_insert_event_question_group($old_event, $old_question_group_id, true); |
|
79 | + if ($new_id) { |
|
80 | + $new_event_question_group_ids[] = $new_id; |
|
81 | + } |
|
82 | + } |
|
83 | + } |
|
84 | + $event_meta = maybe_unserialize($old_event['event_meta']); |
|
85 | + if (isset($event_meta['add_attendee_question_groups'])) { |
|
86 | + if (is_array($event_meta['add_attendee_question_groups'])) { |
|
87 | + foreach ($event_meta['add_attendee_question_groups'] as $old_question_group_id) { |
|
88 | + $new_id = $this->_insert_event_question_group($old_event, $old_question_group_id, false); |
|
89 | + if ($new_id) { |
|
90 | + $new_event_question_group_ids[] = $new_id; |
|
91 | + } |
|
92 | + } |
|
93 | + } |
|
94 | + } |
|
97 | 95 | |
98 | 96 | |
99 | - $this->get_migration_script()->set_mapping($this->_old_table, $old_event['id'], $this->_new_table, $new_event_question_group_ids); |
|
100 | - } |
|
97 | + $this->get_migration_script()->set_mapping($this->_old_table, $old_event['id'], $this->_new_table, $new_event_question_group_ids); |
|
98 | + } |
|
101 | 99 | |
102 | - private function _insert_event_question_group($old_event, $old_question_group_id, $primary) |
|
103 | - { |
|
104 | - global $wpdb; |
|
105 | - $new_question_group_id = $this->get_migration_script()->get_mapping_new_pk( |
|
106 | - $wpdb->prefix . "events_qst_group", |
|
107 | - intval($old_question_group_id), |
|
108 | - $wpdb->prefix . "esp_question_group" |
|
109 | - ); |
|
100 | + private function _insert_event_question_group($old_event, $old_question_group_id, $primary) |
|
101 | + { |
|
102 | + global $wpdb; |
|
103 | + $new_question_group_id = $this->get_migration_script()->get_mapping_new_pk( |
|
104 | + $wpdb->prefix . "events_qst_group", |
|
105 | + intval($old_question_group_id), |
|
106 | + $wpdb->prefix . "esp_question_group" |
|
107 | + ); |
|
110 | 108 | |
111 | - if (! $new_question_group_id) { |
|
112 | - $this->add_error( |
|
113 | - sprintf( |
|
114 | - // translators: %s question ID, %s event ID |
|
115 | - __("Could not find 4.1 question ID for 3.1 question id #%s on event $%s", "event_espresso"), |
|
116 | - $old_question_group_id, |
|
117 | - $old_event['id'] |
|
118 | - ) |
|
119 | - ); |
|
120 | - return 0; |
|
121 | - } |
|
122 | - $new_event_id = $this->get_migration_script()->get_mapping_new_pk( |
|
123 | - $wpdb->prefix . "events_detail", |
|
124 | - intval($old_event['id']), |
|
125 | - $wpdb->posts |
|
126 | - ); |
|
127 | - if (! $new_question_group_id) { |
|
128 | - $this->add_error( |
|
129 | - sprintf( |
|
130 | - // translators: %s event ID |
|
131 | - __("Could not find 4.1 event 3.1 event id #%s", "event_espresso"), |
|
132 | - $old_event['id'] |
|
133 | - ) |
|
134 | - ); |
|
135 | - return 0; |
|
136 | - } |
|
137 | - $cols_n_values = array( |
|
138 | - 'EVT_ID'=>$new_event_id, |
|
139 | - 'QSG_ID'=>$new_question_group_id, |
|
140 | - 'EQG_primary' => $primary |
|
141 | - ); |
|
109 | + if (! $new_question_group_id) { |
|
110 | + $this->add_error( |
|
111 | + sprintf( |
|
112 | + // translators: %s question ID, %s event ID |
|
113 | + __("Could not find 4.1 question ID for 3.1 question id #%s on event $%s", "event_espresso"), |
|
114 | + $old_question_group_id, |
|
115 | + $old_event['id'] |
|
116 | + ) |
|
117 | + ); |
|
118 | + return 0; |
|
119 | + } |
|
120 | + $new_event_id = $this->get_migration_script()->get_mapping_new_pk( |
|
121 | + $wpdb->prefix . "events_detail", |
|
122 | + intval($old_event['id']), |
|
123 | + $wpdb->posts |
|
124 | + ); |
|
125 | + if (! $new_question_group_id) { |
|
126 | + $this->add_error( |
|
127 | + sprintf( |
|
128 | + // translators: %s event ID |
|
129 | + __("Could not find 4.1 event 3.1 event id #%s", "event_espresso"), |
|
130 | + $old_event['id'] |
|
131 | + ) |
|
132 | + ); |
|
133 | + return 0; |
|
134 | + } |
|
135 | + $cols_n_values = array( |
|
136 | + 'EVT_ID'=>$new_event_id, |
|
137 | + 'QSG_ID'=>$new_question_group_id, |
|
138 | + 'EQG_primary' => $primary |
|
139 | + ); |
|
142 | 140 | |
143 | - $datatypes = array( |
|
144 | - '%d',// EVT_ID |
|
145 | - '%d',// QSG_ID |
|
146 | - '%d',// EQG_primary |
|
147 | - ); |
|
148 | - $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
|
149 | - if (! $success) { |
|
150 | - $this->add_error( |
|
151 | - $this->get_migration_script()->_create_error_message_for_db_insertion( |
|
152 | - $this->_old_table, |
|
153 | - $old_event, |
|
154 | - $this->_new_table, |
|
155 | - $cols_n_values, |
|
156 | - $datatypes |
|
157 | - ) |
|
158 | - ); |
|
159 | - return 0; |
|
160 | - } |
|
161 | - return $wpdb->insert_id; |
|
162 | - } |
|
141 | + $datatypes = array( |
|
142 | + '%d',// EVT_ID |
|
143 | + '%d',// QSG_ID |
|
144 | + '%d',// EQG_primary |
|
145 | + ); |
|
146 | + $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
|
147 | + if (! $success) { |
|
148 | + $this->add_error( |
|
149 | + $this->get_migration_script()->_create_error_message_for_db_insertion( |
|
150 | + $this->_old_table, |
|
151 | + $old_event, |
|
152 | + $this->_new_table, |
|
153 | + $cols_n_values, |
|
154 | + $datatypes |
|
155 | + ) |
|
156 | + ); |
|
157 | + return 0; |
|
158 | + } |
|
159 | + return $wpdb->insert_id; |
|
160 | + } |
|
163 | 161 | } |
@@ -103,12 +103,12 @@ discard block |
||
103 | 103 | { |
104 | 104 | global $wpdb; |
105 | 105 | $new_question_group_id = $this->get_migration_script()->get_mapping_new_pk( |
106 | - $wpdb->prefix . "events_qst_group", |
|
106 | + $wpdb->prefix."events_qst_group", |
|
107 | 107 | intval($old_question_group_id), |
108 | - $wpdb->prefix . "esp_question_group" |
|
108 | + $wpdb->prefix."esp_question_group" |
|
109 | 109 | ); |
110 | 110 | |
111 | - if (! $new_question_group_id) { |
|
111 | + if ( ! $new_question_group_id) { |
|
112 | 112 | $this->add_error( |
113 | 113 | sprintf( |
114 | 114 | // translators: %s question ID, %s event ID |
@@ -120,11 +120,11 @@ discard block |
||
120 | 120 | return 0; |
121 | 121 | } |
122 | 122 | $new_event_id = $this->get_migration_script()->get_mapping_new_pk( |
123 | - $wpdb->prefix . "events_detail", |
|
123 | + $wpdb->prefix."events_detail", |
|
124 | 124 | intval($old_event['id']), |
125 | 125 | $wpdb->posts |
126 | 126 | ); |
127 | - if (! $new_question_group_id) { |
|
127 | + if ( ! $new_question_group_id) { |
|
128 | 128 | $this->add_error( |
129 | 129 | sprintf( |
130 | 130 | // translators: %s event ID |
@@ -141,12 +141,12 @@ discard block |
||
141 | 141 | ); |
142 | 142 | |
143 | 143 | $datatypes = array( |
144 | - '%d',// EVT_ID |
|
145 | - '%d',// QSG_ID |
|
146 | - '%d',// EQG_primary |
|
144 | + '%d', // EVT_ID |
|
145 | + '%d', // QSG_ID |
|
146 | + '%d', // EQG_primary |
|
147 | 147 | ); |
148 | 148 | $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
149 | - if (! $success) { |
|
149 | + if ( ! $success) { |
|
150 | 150 | $this->add_error( |
151 | 151 | $this->get_migration_script()->_create_error_message_for_db_insertion( |
152 | 152 | $this->_old_table, |