@@ -26,160 +26,160 @@ |
||
26 | 26 | |
27 | 27 | class EE_DMS_4_1_0_checkins extends EE_Data_Migration_Script_Stage_Table |
28 | 28 | { |
29 | - private $_new_table; |
|
30 | - public function __construct() |
|
31 | - { |
|
32 | - global $wpdb; |
|
33 | - $this->_pretty_name = esc_html__('Checkins', 'event_espresso'); |
|
34 | - $this->_old_table = $wpdb->prefix . "events_attendee"; |
|
35 | - $this->select_expression = 'att.*, e.event_status'; |
|
36 | - $this->_extra_where_sql = 'AS att |
|
29 | + private $_new_table; |
|
30 | + public function __construct() |
|
31 | + { |
|
32 | + global $wpdb; |
|
33 | + $this->_pretty_name = esc_html__('Checkins', 'event_espresso'); |
|
34 | + $this->_old_table = $wpdb->prefix . "events_attendee"; |
|
35 | + $this->select_expression = 'att.*, e.event_status'; |
|
36 | + $this->_extra_where_sql = 'AS att |
|
37 | 37 | INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id |
38 | 38 | WHERE e.event_status!="D"'; |
39 | - $this->_new_table = $wpdb->prefix . "esp_checkin"; |
|
40 | - parent::__construct(); |
|
41 | - } |
|
42 | - protected function _migrate_old_row($old_row) |
|
43 | - { |
|
44 | - global $wpdb; |
|
45 | - $new_reg_table = $wpdb->prefix . "esp_registration"; |
|
39 | + $this->_new_table = $wpdb->prefix . "esp_checkin"; |
|
40 | + parent::__construct(); |
|
41 | + } |
|
42 | + protected function _migrate_old_row($old_row) |
|
43 | + { |
|
44 | + global $wpdb; |
|
45 | + $new_reg_table = $wpdb->prefix . "esp_registration"; |
|
46 | 46 | |
47 | - $num_to_checkin_at_this_time = max(array(intval($old_row['checked_in_quantity']),intval($old_row['checked_in']))) ; |
|
47 | + $num_to_checkin_at_this_time = max(array(intval($old_row['checked_in_quantity']),intval($old_row['checked_in']))) ; |
|
48 | 48 | |
49 | - $new_registrations_for_attendee = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $new_reg_table); |
|
50 | - if (! $new_registrations_for_attendee) { |
|
51 | - $new_registrations_for_attendee = array(); |
|
52 | - } |
|
53 | - $new_datetime = $this->_try_to_find_datetime($old_row); |
|
49 | + $new_registrations_for_attendee = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $new_reg_table); |
|
50 | + if (! $new_registrations_for_attendee) { |
|
51 | + $new_registrations_for_attendee = array(); |
|
52 | + } |
|
53 | + $new_datetime = $this->_try_to_find_datetime($old_row); |
|
54 | 54 | |
55 | - // make sure registrations array is numerically indexed starting at 0 (it probably already is) |
|
56 | - $new_registrations_for_attendee = array_values($new_registrations_for_attendee); |
|
57 | - $new_checkin_ids = array(); |
|
58 | - for ($i = 0; $i < abs($num_to_checkin_at_this_time); $i++) { |
|
59 | - $new_reg_id = $new_registrations_for_attendee[ $i ]; |
|
60 | - if (! $new_reg_id) { |
|
61 | - $this->add_error(sprintf( |
|
62 | - esc_html__( |
|
63 | - /* translators: %1$s database row represented in JSON, %2$s number of registrations to check-in |
|
55 | + // make sure registrations array is numerically indexed starting at 0 (it probably already is) |
|
56 | + $new_registrations_for_attendee = array_values($new_registrations_for_attendee); |
|
57 | + $new_checkin_ids = array(); |
|
58 | + for ($i = 0; $i < abs($num_to_checkin_at_this_time); $i++) { |
|
59 | + $new_reg_id = $new_registrations_for_attendee[ $i ]; |
|
60 | + if (! $new_reg_id) { |
|
61 | + $this->add_error(sprintf( |
|
62 | + esc_html__( |
|
63 | + /* translators: %1$s database row represented in JSON, %2$s number of registrations to check-in |
|
64 | 64 | * %3$s number of registrations for the attendee, %4$s new registration rows represented in JSON |
65 | 65 | */ |
66 | - // @codingStandardsIgnoreStart |
|
67 | - 'It appears we wanted to check-in more registrations than actually exist. The old attendee record (%1$s) indicated we should check-in %2$d registrations, but there are only %3$d registrations for that attendee (%4$s)', |
|
68 | - // @codingStandardsIgnoreEnd |
|
69 | - 'event_espresso' |
|
70 | - ), |
|
71 | - $this->_json_encode($old_row), |
|
72 | - abs($num_to_checkin_at_this_time), |
|
73 | - count($new_registrations_for_attendee), |
|
74 | - $this->_json_encode($new_registrations_for_attendee) |
|
75 | - )); |
|
76 | - break; |
|
77 | - } |
|
78 | - $existing_checkin_record = $wpdb->get_var( |
|
79 | - $wpdb->prepare( |
|
80 | - "SELECT CHK_ID FROM $this->_new_table WHERE REG_ID = %d ORDER BY CHK_ID DESC LIMIT 1", |
|
81 | - $new_reg_id |
|
82 | - ) |
|
83 | - ); |
|
84 | - if (! $existing_checkin_record) { |
|
85 | - $new_id = $this->_insert_checkin_record($new_reg_id, $new_datetime); |
|
86 | - if ($new_id) { |
|
87 | - $new_checkin_ids[] = $new_id; |
|
88 | - } |
|
89 | - } |
|
90 | - } |
|
91 | - if ($new_checkin_ids) { |
|
92 | - $this->get_migration_script()->set_mapping( |
|
93 | - $this->_old_table, |
|
94 | - $old_row['id'], |
|
95 | - $this->_new_table, |
|
96 | - $new_checkin_ids |
|
97 | - ); |
|
98 | - } |
|
99 | - } |
|
66 | + // @codingStandardsIgnoreStart |
|
67 | + 'It appears we wanted to check-in more registrations than actually exist. The old attendee record (%1$s) indicated we should check-in %2$d registrations, but there are only %3$d registrations for that attendee (%4$s)', |
|
68 | + // @codingStandardsIgnoreEnd |
|
69 | + 'event_espresso' |
|
70 | + ), |
|
71 | + $this->_json_encode($old_row), |
|
72 | + abs($num_to_checkin_at_this_time), |
|
73 | + count($new_registrations_for_attendee), |
|
74 | + $this->_json_encode($new_registrations_for_attendee) |
|
75 | + )); |
|
76 | + break; |
|
77 | + } |
|
78 | + $existing_checkin_record = $wpdb->get_var( |
|
79 | + $wpdb->prepare( |
|
80 | + "SELECT CHK_ID FROM $this->_new_table WHERE REG_ID = %d ORDER BY CHK_ID DESC LIMIT 1", |
|
81 | + $new_reg_id |
|
82 | + ) |
|
83 | + ); |
|
84 | + if (! $existing_checkin_record) { |
|
85 | + $new_id = $this->_insert_checkin_record($new_reg_id, $new_datetime); |
|
86 | + if ($new_id) { |
|
87 | + $new_checkin_ids[] = $new_id; |
|
88 | + } |
|
89 | + } |
|
90 | + } |
|
91 | + if ($new_checkin_ids) { |
|
92 | + $this->get_migration_script()->set_mapping( |
|
93 | + $this->_old_table, |
|
94 | + $old_row['id'], |
|
95 | + $this->_new_table, |
|
96 | + $new_checkin_ids |
|
97 | + ); |
|
98 | + } |
|
99 | + } |
|
100 | 100 | |
101 | 101 | |
102 | - /** |
|
103 | - * Tries to find the new datetime the Check-in was for, based on the attendee row |
|
104 | - * (because we know the attendee was for an event as a specific time, and we know |
|
105 | - * the event's OLD ID...) |
|
106 | - * @global type $wpdb |
|
107 | - * @param array $old_attendee_row |
|
108 | - * @return array row of datetime from DB |
|
109 | - */ |
|
110 | - private function _try_to_find_datetime($old_attendee) |
|
111 | - { |
|
112 | - global $wpdb; |
|
102 | + /** |
|
103 | + * Tries to find the new datetime the Check-in was for, based on the attendee row |
|
104 | + * (because we know the attendee was for an event as a specific time, and we know |
|
105 | + * the event's OLD ID...) |
|
106 | + * @global type $wpdb |
|
107 | + * @param array $old_attendee_row |
|
108 | + * @return array row of datetime from DB |
|
109 | + */ |
|
110 | + private function _try_to_find_datetime($old_attendee) |
|
111 | + { |
|
112 | + global $wpdb; |
|
113 | 113 | |
114 | - $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_detail", $old_attendee['event_id'], $wpdb->posts); |
|
115 | - if (! $new_event_id) { |
|
116 | - $this->add_error( |
|
117 | - sprintf( |
|
118 | - esc_html__( |
|
119 | - /* translators: 1: original event ID, 2: original attendee database row */ |
|
120 | - // @codingStandardsIgnoreStart |
|
121 | - 'Could not find new event ID with old event ID %1$d, on attendee row %2$s; and because of that couldn\'t find the correct datetime for Check-in', |
|
122 | - // @codingStandardsIgnoreEnd |
|
123 | - 'event_espresso' |
|
124 | - ), |
|
125 | - $old_attendee['event_id'], |
|
126 | - $this->_json_encode($old_attendee) |
|
127 | - ) |
|
128 | - ); |
|
129 | - return 0; |
|
130 | - } |
|
131 | - $old_att_start_date = $old_attendee['start_date']; |
|
132 | - $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
|
133 | - $old_att_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00"); |
|
114 | + $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_detail", $old_attendee['event_id'], $wpdb->posts); |
|
115 | + if (! $new_event_id) { |
|
116 | + $this->add_error( |
|
117 | + sprintf( |
|
118 | + esc_html__( |
|
119 | + /* translators: 1: original event ID, 2: original attendee database row */ |
|
120 | + // @codingStandardsIgnoreStart |
|
121 | + 'Could not find new event ID with old event ID %1$d, on attendee row %2$s; and because of that couldn\'t find the correct datetime for Check-in', |
|
122 | + // @codingStandardsIgnoreEnd |
|
123 | + 'event_espresso' |
|
124 | + ), |
|
125 | + $old_attendee['event_id'], |
|
126 | + $this->_json_encode($old_attendee) |
|
127 | + ) |
|
128 | + ); |
|
129 | + return 0; |
|
130 | + } |
|
131 | + $old_att_start_date = $old_attendee['start_date']; |
|
132 | + $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
|
133 | + $old_att_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00"); |
|
134 | 134 | |
135 | - $datetime_table = $wpdb->prefix . "esp_datetime"; |
|
136 | - // add all conditions to an array from which we can SHIFT conditions off in order to widen our search |
|
137 | - // the most important condition should be last, as it will be array_shift'ed off last |
|
138 | - $conditions = array( |
|
139 | - $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match? |
|
140 | - $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match? |
|
141 | - ); |
|
142 | - // start running queries, widening search each time by removing a condition |
|
143 | - $datetime_found = null; |
|
144 | - do { |
|
145 | - $full_query = "SELECT * FROM $datetime_table WHERE " . implode(" AND ", $conditions) . " LIMIT 1"; |
|
146 | - $datetime_found = $wpdb->get_row($full_query, ARRAY_A); |
|
147 | - array_shift($conditions); |
|
148 | - } while (! $datetime_found && $conditions); |
|
149 | - return $datetime_found; |
|
150 | - } |
|
135 | + $datetime_table = $wpdb->prefix . "esp_datetime"; |
|
136 | + // add all conditions to an array from which we can SHIFT conditions off in order to widen our search |
|
137 | + // the most important condition should be last, as it will be array_shift'ed off last |
|
138 | + $conditions = array( |
|
139 | + $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match? |
|
140 | + $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match? |
|
141 | + ); |
|
142 | + // start running queries, widening search each time by removing a condition |
|
143 | + $datetime_found = null; |
|
144 | + do { |
|
145 | + $full_query = "SELECT * FROM $datetime_table WHERE " . implode(" AND ", $conditions) . " LIMIT 1"; |
|
146 | + $datetime_found = $wpdb->get_row($full_query, ARRAY_A); |
|
147 | + array_shift($conditions); |
|
148 | + } while (! $datetime_found && $conditions); |
|
149 | + return $datetime_found; |
|
150 | + } |
|
151 | 151 | |
152 | - /** |
|
153 | - * Adds a new Check-in/checkout record according for $new_reg_id,$new_datetime_id,$checking_in, and $timestmap |
|
154 | - * @param int $new_reg_id |
|
155 | - * @param int $new_datetime_id |
|
156 | - * @param string $timestamp mysql datetime |
|
157 | - * @return int new Check-in id |
|
158 | - */ |
|
159 | - private function _insert_checkin_record($new_reg_id, $new_datetime) |
|
160 | - { |
|
161 | - global $wpdb; |
|
152 | + /** |
|
153 | + * Adds a new Check-in/checkout record according for $new_reg_id,$new_datetime_id,$checking_in, and $timestmap |
|
154 | + * @param int $new_reg_id |
|
155 | + * @param int $new_datetime_id |
|
156 | + * @param string $timestamp mysql datetime |
|
157 | + * @return int new Check-in id |
|
158 | + */ |
|
159 | + private function _insert_checkin_record($new_reg_id, $new_datetime) |
|
160 | + { |
|
161 | + global $wpdb; |
|
162 | 162 | |
163 | 163 | |
164 | - // ok we can actually do what we set out to do: add a checkin/checkout record |
|
165 | - $cols_n_values = array( |
|
166 | - 'REG_ID' => $new_reg_id, |
|
167 | - 'DTT_ID' => $new_datetime['DTT_ID'], |
|
168 | - 'CHK_in' => true, |
|
169 | - 'CHK_timestamp' => $new_datetime['DTT_EVT_start'] |
|
170 | - ); |
|
171 | - $datatypes = array( |
|
172 | - '%d',// REG_ID |
|
173 | - '%d',// DTT_ID |
|
174 | - '%d',// CHK_in |
|
175 | - '%s',// CHK_timestamp |
|
176 | - ); |
|
177 | - $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
|
178 | - if (! $success) { |
|
179 | - $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_checkin, $this->_new_table, $cols_n_values, $datatypes)); |
|
180 | - return 0; |
|
181 | - } |
|
182 | - $new_id = $wpdb->insert_id; |
|
183 | - return $new_id; |
|
184 | - } |
|
164 | + // ok we can actually do what we set out to do: add a checkin/checkout record |
|
165 | + $cols_n_values = array( |
|
166 | + 'REG_ID' => $new_reg_id, |
|
167 | + 'DTT_ID' => $new_datetime['DTT_ID'], |
|
168 | + 'CHK_in' => true, |
|
169 | + 'CHK_timestamp' => $new_datetime['DTT_EVT_start'] |
|
170 | + ); |
|
171 | + $datatypes = array( |
|
172 | + '%d',// REG_ID |
|
173 | + '%d',// DTT_ID |
|
174 | + '%d',// CHK_in |
|
175 | + '%s',// CHK_timestamp |
|
176 | + ); |
|
177 | + $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
|
178 | + if (! $success) { |
|
179 | + $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_checkin, $this->_new_table, $cols_n_values, $datatypes)); |
|
180 | + return 0; |
|
181 | + } |
|
182 | + $new_id = $wpdb->insert_id; |
|
183 | + return $new_id; |
|
184 | + } |
|
185 | 185 | } |
@@ -31,23 +31,23 @@ discard block |
||
31 | 31 | { |
32 | 32 | global $wpdb; |
33 | 33 | $this->_pretty_name = esc_html__('Checkins', 'event_espresso'); |
34 | - $this->_old_table = $wpdb->prefix . "events_attendee"; |
|
34 | + $this->_old_table = $wpdb->prefix."events_attendee"; |
|
35 | 35 | $this->select_expression = 'att.*, e.event_status'; |
36 | 36 | $this->_extra_where_sql = 'AS att |
37 | - INNER JOIN ' . $wpdb->prefix . 'events_detail AS e ON att.event_id=e.id |
|
37 | + INNER JOIN ' . $wpdb->prefix.'events_detail AS e ON att.event_id=e.id |
|
38 | 38 | WHERE e.event_status!="D"'; |
39 | - $this->_new_table = $wpdb->prefix . "esp_checkin"; |
|
39 | + $this->_new_table = $wpdb->prefix."esp_checkin"; |
|
40 | 40 | parent::__construct(); |
41 | 41 | } |
42 | 42 | protected function _migrate_old_row($old_row) |
43 | 43 | { |
44 | 44 | global $wpdb; |
45 | - $new_reg_table = $wpdb->prefix . "esp_registration"; |
|
45 | + $new_reg_table = $wpdb->prefix."esp_registration"; |
|
46 | 46 | |
47 | - $num_to_checkin_at_this_time = max(array(intval($old_row['checked_in_quantity']),intval($old_row['checked_in']))) ; |
|
47 | + $num_to_checkin_at_this_time = max(array(intval($old_row['checked_in_quantity']), intval($old_row['checked_in']))); |
|
48 | 48 | |
49 | 49 | $new_registrations_for_attendee = $this->get_migration_script()->get_mapping_new_pk($this->_old_table, $old_row['id'], $new_reg_table); |
50 | - if (! $new_registrations_for_attendee) { |
|
50 | + if ( ! $new_registrations_for_attendee) { |
|
51 | 51 | $new_registrations_for_attendee = array(); |
52 | 52 | } |
53 | 53 | $new_datetime = $this->_try_to_find_datetime($old_row); |
@@ -56,8 +56,8 @@ discard block |
||
56 | 56 | $new_registrations_for_attendee = array_values($new_registrations_for_attendee); |
57 | 57 | $new_checkin_ids = array(); |
58 | 58 | for ($i = 0; $i < abs($num_to_checkin_at_this_time); $i++) { |
59 | - $new_reg_id = $new_registrations_for_attendee[ $i ]; |
|
60 | - if (! $new_reg_id) { |
|
59 | + $new_reg_id = $new_registrations_for_attendee[$i]; |
|
60 | + if ( ! $new_reg_id) { |
|
61 | 61 | $this->add_error(sprintf( |
62 | 62 | esc_html__( |
63 | 63 | /* translators: %1$s database row represented in JSON, %2$s number of registrations to check-in |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | $new_reg_id |
82 | 82 | ) |
83 | 83 | ); |
84 | - if (! $existing_checkin_record) { |
|
84 | + if ( ! $existing_checkin_record) { |
|
85 | 85 | $new_id = $this->_insert_checkin_record($new_reg_id, $new_datetime); |
86 | 86 | if ($new_id) { |
87 | 87 | $new_checkin_ids[] = $new_id; |
@@ -111,8 +111,8 @@ discard block |
||
111 | 111 | { |
112 | 112 | global $wpdb; |
113 | 113 | |
114 | - $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix . "events_detail", $old_attendee['event_id'], $wpdb->posts); |
|
115 | - if (! $new_event_id) { |
|
114 | + $new_event_id = $this->get_migration_script()->get_mapping_new_pk($wpdb->prefix."events_detail", $old_attendee['event_id'], $wpdb->posts); |
|
115 | + if ( ! $new_event_id) { |
|
116 | 116 | $this->add_error( |
117 | 117 | sprintf( |
118 | 118 | esc_html__( |
@@ -132,20 +132,20 @@ discard block |
||
132 | 132 | $old_att_start_time = $this->get_migration_script()->convertTimeFromAMPM($old_attendee['event_time']); |
133 | 133 | $old_att_datetime = $this->get_migration_script()->convert_date_string_to_utc($this, $old_attendee, "$old_att_start_date $old_att_start_time:00"); |
134 | 134 | |
135 | - $datetime_table = $wpdb->prefix . "esp_datetime"; |
|
135 | + $datetime_table = $wpdb->prefix."esp_datetime"; |
|
136 | 136 | // add all conditions to an array from which we can SHIFT conditions off in order to widen our search |
137 | 137 | // the most important condition should be last, as it will be array_shift'ed off last |
138 | 138 | $conditions = array( |
139 | - $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime),// times match? |
|
140 | - $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id),// events match? |
|
139 | + $wpdb->prepare("$datetime_table.DTT_EVT_start = %s", $old_att_datetime), // times match? |
|
140 | + $wpdb->prepare("$datetime_table.EVT_ID = %d", $new_event_id), // events match? |
|
141 | 141 | ); |
142 | 142 | // start running queries, widening search each time by removing a condition |
143 | 143 | $datetime_found = null; |
144 | 144 | do { |
145 | - $full_query = "SELECT * FROM $datetime_table WHERE " . implode(" AND ", $conditions) . " LIMIT 1"; |
|
145 | + $full_query = "SELECT * FROM $datetime_table WHERE ".implode(" AND ", $conditions)." LIMIT 1"; |
|
146 | 146 | $datetime_found = $wpdb->get_row($full_query, ARRAY_A); |
147 | 147 | array_shift($conditions); |
148 | - } while (! $datetime_found && $conditions); |
|
148 | + }while ( ! $datetime_found && $conditions); |
|
149 | 149 | return $datetime_found; |
150 | 150 | } |
151 | 151 | |
@@ -169,13 +169,13 @@ discard block |
||
169 | 169 | 'CHK_timestamp' => $new_datetime['DTT_EVT_start'] |
170 | 170 | ); |
171 | 171 | $datatypes = array( |
172 | - '%d',// REG_ID |
|
173 | - '%d',// DTT_ID |
|
174 | - '%d',// CHK_in |
|
175 | - '%s',// CHK_timestamp |
|
172 | + '%d', // REG_ID |
|
173 | + '%d', // DTT_ID |
|
174 | + '%d', // CHK_in |
|
175 | + '%s', // CHK_timestamp |
|
176 | 176 | ); |
177 | 177 | $success = $wpdb->insert($this->_new_table, $cols_n_values, $datatypes); |
178 | - if (! $success) { |
|
178 | + if ( ! $success) { |
|
179 | 179 | $this->add_error($this->get_migration_script()->_create_error_message_for_db_insertion($this->_old_table, $old_checkin, $this->_new_table, $cols_n_values, $datatypes)); |
180 | 180 | return 0; |
181 | 181 | } |
@@ -9,12 +9,12 @@ discard block |
||
9 | 9 | // unfortunately, this needs to be done upon INCLUSION of this file, |
10 | 10 | // instead of construction, because it only gets constructed on first page load |
11 | 11 | // (all other times it gets resurrected from a wordpress option) |
12 | -$stages = glob(EE_CORE . 'data_migration_scripts/4_9_0_stages/*'); |
|
12 | +$stages = glob(EE_CORE.'data_migration_scripts/4_9_0_stages/*'); |
|
13 | 13 | $class_to_filepath = array(); |
14 | 14 | foreach ($stages as $filepath) { |
15 | 15 | $matches = array(); |
16 | 16 | preg_match('~4_9_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
17 | - $class_to_filepath[ $matches[1] ] = $filepath; |
|
17 | + $class_to_filepath[$matches[1]] = $filepath; |
|
18 | 18 | } |
19 | 19 | // give addons a chance to autoload their stages too |
20 | 20 | $class_to_filepath = apply_filters('FHEE__EE_DMS_4_9_0__autoloaded_stages', $class_to_filepath); |
@@ -65,10 +65,10 @@ discard block |
||
65 | 65 | if (version_compare($version_string, '4.9.0.decaf', '<') && version_compare($version_string, '4.8.0.decaf', '>=')) { |
66 | 66 | // echo "$version_string can be migrated from"; |
67 | 67 | return true; |
68 | - } elseif (! $version_string) { |
|
68 | + } elseif ( ! $version_string) { |
|
69 | 69 | // echo "no version string provided: $version_string"; |
70 | 70 | // no version string provided... this must be pre 4.3 |
71 | - return false;// changed mind. dont want people thinking they should migrate yet because they cant |
|
71 | + return false; // changed mind. dont want people thinking they should migrate yet because they cant |
|
72 | 72 | } else { |
73 | 73 | // echo "$version_string doesnt apply"; |
74 | 74 | return false; |
@@ -82,7 +82,7 @@ discard block |
||
82 | 82 | */ |
83 | 83 | public function schema_changes_before_migration() |
84 | 84 | { |
85 | - require_once(EE_HELPERS . 'EEH_Activation.helper.php'); |
|
85 | + require_once(EE_HELPERS.'EEH_Activation.helper.php'); |
|
86 | 86 | $now_in_mysql = current_time('mysql', true); |
87 | 87 | $table_name = 'esp_answer'; |
88 | 88 | $sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
@@ -12,9 +12,9 @@ discard block |
||
12 | 12 | $stages = glob(EE_CORE . 'data_migration_scripts/4_9_0_stages/*'); |
13 | 13 | $class_to_filepath = array(); |
14 | 14 | foreach ($stages as $filepath) { |
15 | - $matches = array(); |
|
16 | - preg_match('~4_9_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
|
17 | - $class_to_filepath[ $matches[1] ] = $filepath; |
|
15 | + $matches = array(); |
|
16 | + preg_match('~4_9_0_stages/(.*).dmsstage.php~', $filepath, $matches); |
|
17 | + $class_to_filepath[ $matches[1] ] = $filepath; |
|
18 | 18 | } |
19 | 19 | // give addons a chance to autoload their stages too |
20 | 20 | $class_to_filepath = apply_filters('FHEE__EE_DMS_4_9_0__autoloaded_stages', $class_to_filepath); |
@@ -33,68 +33,68 @@ discard block |
||
33 | 33 | */ |
34 | 34 | class EE_DMS_Core_4_9_0 extends EE_Data_Migration_Script_Base |
35 | 35 | { |
36 | - /** |
|
37 | - * return EE_DMS_Core_4_9_0 |
|
38 | - * |
|
39 | - * @param TableManager $table_manager |
|
40 | - * @param TableAnalysis $table_analysis |
|
41 | - */ |
|
42 | - public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
43 | - { |
|
44 | - $this->_pretty_name = esc_html__("Data Update to Event Espresso 4.9.0", "event_espresso"); |
|
45 | - $this->_priority = 10; |
|
46 | - $this->_migration_stages = array( |
|
47 | - new EE_DMS_4_9_0_Email_System_Question(), |
|
48 | - new EE_DMS_4_9_0_Answers_With_No_Registration(), |
|
49 | - ); |
|
50 | - parent::__construct($table_manager, $table_analysis); |
|
51 | - } |
|
36 | + /** |
|
37 | + * return EE_DMS_Core_4_9_0 |
|
38 | + * |
|
39 | + * @param TableManager $table_manager |
|
40 | + * @param TableAnalysis $table_analysis |
|
41 | + */ |
|
42 | + public function __construct(TableManager $table_manager = null, TableAnalysis $table_analysis = null) |
|
43 | + { |
|
44 | + $this->_pretty_name = esc_html__("Data Update to Event Espresso 4.9.0", "event_espresso"); |
|
45 | + $this->_priority = 10; |
|
46 | + $this->_migration_stages = array( |
|
47 | + new EE_DMS_4_9_0_Email_System_Question(), |
|
48 | + new EE_DMS_4_9_0_Answers_With_No_Registration(), |
|
49 | + ); |
|
50 | + parent::__construct($table_manager, $table_analysis); |
|
51 | + } |
|
52 | 52 | |
53 | 53 | |
54 | 54 | |
55 | - /** |
|
56 | - * Whether to migrate or not. |
|
57 | - * |
|
58 | - * @param array $version_array |
|
59 | - * @return bool |
|
60 | - */ |
|
61 | - public function can_migrate_from_version($version_array) |
|
62 | - { |
|
63 | - $version_string = $version_array['Core']; |
|
64 | - if (version_compare($version_string, '4.9.0.decaf', '<') && version_compare($version_string, '4.8.0.decaf', '>=')) { |
|
65 | - // echo "$version_string can be migrated from"; |
|
66 | - return true; |
|
67 | - } elseif (! $version_string) { |
|
68 | - // echo "no version string provided: $version_string"; |
|
69 | - // no version string provided... this must be pre 4.3 |
|
70 | - return false;// changed mind. dont want people thinking they should migrate yet because they cant |
|
71 | - } else { |
|
72 | - // echo "$version_string doesnt apply"; |
|
73 | - return false; |
|
74 | - } |
|
75 | - } |
|
55 | + /** |
|
56 | + * Whether to migrate or not. |
|
57 | + * |
|
58 | + * @param array $version_array |
|
59 | + * @return bool |
|
60 | + */ |
|
61 | + public function can_migrate_from_version($version_array) |
|
62 | + { |
|
63 | + $version_string = $version_array['Core']; |
|
64 | + if (version_compare($version_string, '4.9.0.decaf', '<') && version_compare($version_string, '4.8.0.decaf', '>=')) { |
|
65 | + // echo "$version_string can be migrated from"; |
|
66 | + return true; |
|
67 | + } elseif (! $version_string) { |
|
68 | + // echo "no version string provided: $version_string"; |
|
69 | + // no version string provided... this must be pre 4.3 |
|
70 | + return false;// changed mind. dont want people thinking they should migrate yet because they cant |
|
71 | + } else { |
|
72 | + // echo "$version_string doesnt apply"; |
|
73 | + return false; |
|
74 | + } |
|
75 | + } |
|
76 | 76 | |
77 | 77 | |
78 | 78 | |
79 | - /** |
|
80 | - * @return bool |
|
81 | - */ |
|
82 | - public function schema_changes_before_migration() |
|
83 | - { |
|
84 | - require_once(EE_HELPERS . 'EEH_Activation.helper.php'); |
|
85 | - $now_in_mysql = current_time('mysql', true); |
|
86 | - $table_name = 'esp_answer'; |
|
87 | - $sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
79 | + /** |
|
80 | + * @return bool |
|
81 | + */ |
|
82 | + public function schema_changes_before_migration() |
|
83 | + { |
|
84 | + require_once(EE_HELPERS . 'EEH_Activation.helper.php'); |
|
85 | + $now_in_mysql = current_time('mysql', true); |
|
86 | + $table_name = 'esp_answer'; |
|
87 | + $sql = " ANS_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
88 | 88 | REG_ID int(10) unsigned NOT NULL, |
89 | 89 | QST_ID int(10) unsigned NOT NULL, |
90 | 90 | ANS_value text NOT NULL, |
91 | 91 | PRIMARY KEY (ANS_ID), |
92 | 92 | KEY REG_ID (REG_ID), |
93 | 93 | KEY QST_ID (QST_ID)"; |
94 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
95 | - $table_name = 'esp_attendee_meta'; |
|
96 | - $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'ATT_email'); |
|
97 | - $sql = "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
94 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
95 | + $table_name = 'esp_attendee_meta'; |
|
96 | + $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'ATT_email'); |
|
97 | + $sql = "ATTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
98 | 98 | ATT_ID bigint(20) unsigned NOT NULL, |
99 | 99 | ATT_fname varchar(45) NOT NULL, |
100 | 100 | ATT_lname varchar(45) NOT NULL, |
@@ -111,9 +111,9 @@ discard block |
||
111 | 111 | KEY ATT_email (ATT_email(191)), |
112 | 112 | KEY ATT_lname (ATT_lname), |
113 | 113 | KEY ATT_fname (ATT_fname)"; |
114 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
115 | - $table_name = 'esp_checkin'; |
|
116 | - $sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
114 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
115 | + $table_name = 'esp_checkin'; |
|
116 | + $sql = "CHK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
117 | 117 | REG_ID int(10) unsigned NOT NULL, |
118 | 118 | DTT_ID int(10) unsigned NOT NULL, |
119 | 119 | CHK_in tinyint(1) unsigned NOT NULL DEFAULT 1, |
@@ -121,9 +121,9 @@ discard block |
||
121 | 121 | PRIMARY KEY (CHK_ID), |
122 | 122 | KEY REG_ID (REG_ID), |
123 | 123 | KEY DTT_ID (DTT_ID)"; |
124 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
125 | - $table_name = 'esp_country'; |
|
126 | - $sql = "CNT_ISO varchar(2) NOT NULL, |
|
124 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
125 | + $table_name = 'esp_country'; |
|
126 | + $sql = "CNT_ISO varchar(2) NOT NULL, |
|
127 | 127 | CNT_ISO3 varchar(3) NOT NULL, |
128 | 128 | RGN_ID tinyint(3) unsigned DEFAULT NULL, |
129 | 129 | CNT_name varchar(45) NOT NULL, |
@@ -139,29 +139,29 @@ discard block |
||
139 | 139 | CNT_is_EU tinyint(1) DEFAULT '0', |
140 | 140 | CNT_active tinyint(1) DEFAULT '0', |
141 | 141 | PRIMARY KEY (CNT_ISO)"; |
142 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
143 | - $table_name = 'esp_currency'; |
|
144 | - $sql = "CUR_code varchar(6) NOT NULL, |
|
142 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
143 | + $table_name = 'esp_currency'; |
|
144 | + $sql = "CUR_code varchar(6) NOT NULL, |
|
145 | 145 | CUR_single varchar(45) DEFAULT 'dollar', |
146 | 146 | CUR_plural varchar(45) DEFAULT 'dollars', |
147 | 147 | CUR_sign varchar(45) DEFAULT '$', |
148 | 148 | CUR_dec_plc varchar(1) NOT NULL DEFAULT '2', |
149 | 149 | CUR_active tinyint(1) DEFAULT '0', |
150 | 150 | PRIMARY KEY (CUR_code)"; |
151 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
152 | - // note: although this table is no longer in use, |
|
153 | - // it hasn't been removed because then queries to the model will have errors. |
|
154 | - // but you should expect this table and its corresponding model to be removed in |
|
155 | - // the next few months |
|
156 | - $table_name = 'esp_currency_payment_method'; |
|
157 | - $sql = "CPM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
151 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
152 | + // note: although this table is no longer in use, |
|
153 | + // it hasn't been removed because then queries to the model will have errors. |
|
154 | + // but you should expect this table and its corresponding model to be removed in |
|
155 | + // the next few months |
|
156 | + $table_name = 'esp_currency_payment_method'; |
|
157 | + $sql = "CPM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
158 | 158 | CUR_code varchar(6) NOT NULL, |
159 | 159 | PMD_ID int(11) NOT NULL, |
160 | 160 | PRIMARY KEY (CPM_ID), |
161 | 161 | KEY PMD_ID (PMD_ID)"; |
162 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
163 | - $table_name = 'esp_datetime'; |
|
164 | - $sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
162 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
163 | + $table_name = 'esp_datetime'; |
|
164 | + $sql = "DTT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
165 | 165 | EVT_ID bigint(20) unsigned NOT NULL, |
166 | 166 | DTT_name varchar(255) NOT NULL DEFAULT '', |
167 | 167 | DTT_description text NOT NULL, |
@@ -178,25 +178,25 @@ discard block |
||
178 | 178 | KEY DTT_EVT_start (DTT_EVT_start), |
179 | 179 | KEY EVT_ID (EVT_ID), |
180 | 180 | KEY DTT_is_primary (DTT_is_primary)"; |
181 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
182 | - $table_name = "esp_datetime_ticket"; |
|
183 | - $sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
181 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
182 | + $table_name = "esp_datetime_ticket"; |
|
183 | + $sql = "DTK_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
184 | 184 | DTT_ID int(10) unsigned NOT NULL, |
185 | 185 | TKT_ID int(10) unsigned NOT NULL, |
186 | 186 | PRIMARY KEY (DTK_ID), |
187 | 187 | KEY DTT_ID (DTT_ID), |
188 | 188 | KEY TKT_ID (TKT_ID)"; |
189 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
190 | - $table_name = 'esp_event_message_template'; |
|
191 | - $sql = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
189 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
190 | + $table_name = 'esp_event_message_template'; |
|
191 | + $sql = "EMT_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
192 | 192 | EVT_ID bigint(20) unsigned NOT NULL DEFAULT 0, |
193 | 193 | GRP_ID int(10) unsigned NOT NULL DEFAULT 0, |
194 | 194 | PRIMARY KEY (EMT_ID), |
195 | 195 | KEY EVT_ID (EVT_ID), |
196 | 196 | KEY GRP_ID (GRP_ID)"; |
197 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
198 | - $table_name = 'esp_event_meta'; |
|
199 | - $sql = "EVTM_ID int(10) NOT NULL AUTO_INCREMENT, |
|
197 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
198 | + $table_name = 'esp_event_meta'; |
|
199 | + $sql = "EVTM_ID int(10) NOT NULL AUTO_INCREMENT, |
|
200 | 200 | EVT_ID bigint(20) unsigned NOT NULL, |
201 | 201 | EVT_display_desc tinyint(1) unsigned NOT NULL DEFAULT 1, |
202 | 202 | EVT_display_ticket_selector tinyint(1) unsigned NOT NULL DEFAULT 1, |
@@ -211,34 +211,34 @@ discard block |
||
211 | 211 | EVT_donations tinyint(1) NULL, |
212 | 212 | PRIMARY KEY (EVTM_ID), |
213 | 213 | KEY EVT_ID (EVT_ID)"; |
214 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
215 | - $table_name = 'esp_event_question_group'; |
|
216 | - $sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
214 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
215 | + $table_name = 'esp_event_question_group'; |
|
216 | + $sql = "EQG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
217 | 217 | EVT_ID bigint(20) unsigned NOT NULL, |
218 | 218 | QSG_ID int(10) unsigned NOT NULL, |
219 | 219 | EQG_primary tinyint(1) unsigned NOT NULL DEFAULT 0, |
220 | 220 | PRIMARY KEY (EQG_ID), |
221 | 221 | KEY EVT_ID (EVT_ID), |
222 | 222 | KEY QSG_ID (QSG_ID)"; |
223 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
224 | - $table_name = 'esp_event_venue'; |
|
225 | - $sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT, |
|
223 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
224 | + $table_name = 'esp_event_venue'; |
|
225 | + $sql = "EVV_ID int(11) NOT NULL AUTO_INCREMENT, |
|
226 | 226 | EVT_ID bigint(20) unsigned NOT NULL, |
227 | 227 | VNU_ID bigint(20) unsigned NOT NULL, |
228 | 228 | EVV_primary tinyint(1) unsigned NOT NULL DEFAULT 0, |
229 | 229 | PRIMARY KEY (EVV_ID)"; |
230 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
231 | - $table_name = 'esp_extra_meta'; |
|
232 | - $sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
230 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
231 | + $table_name = 'esp_extra_meta'; |
|
232 | + $sql = "EXM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
233 | 233 | OBJ_ID int(11) DEFAULT NULL, |
234 | 234 | EXM_type varchar(45) DEFAULT NULL, |
235 | 235 | EXM_key varchar(45) DEFAULT NULL, |
236 | 236 | EXM_value text, |
237 | 237 | PRIMARY KEY (EXM_ID), |
238 | 238 | KEY EXM_type (EXM_type,OBJ_ID,EXM_key)"; |
239 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
240 | - $table_name = 'esp_extra_join'; |
|
241 | - $sql = "EXJ_ID int(11) NOT NULL AUTO_INCREMENT, |
|
239 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
240 | + $table_name = 'esp_extra_join'; |
|
241 | + $sql = "EXJ_ID int(11) NOT NULL AUTO_INCREMENT, |
|
242 | 242 | EXJ_first_model_id varchar(6) NOT NULL, |
243 | 243 | EXJ_first_model_name varchar(20) NOT NULL, |
244 | 244 | EXJ_second_model_id varchar(6) NOT NULL, |
@@ -246,9 +246,9 @@ discard block |
||
246 | 246 | PRIMARY KEY (EXJ_ID), |
247 | 247 | KEY first_model (EXJ_first_model_name,EXJ_first_model_id), |
248 | 248 | KEY second_model (EXJ_second_model_name,EXJ_second_model_id)"; |
249 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
250 | - $table_name = 'esp_line_item'; |
|
251 | - $sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT, |
|
249 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
250 | + $table_name = 'esp_line_item'; |
|
251 | + $sql = "LIN_ID int(11) NOT NULL AUTO_INCREMENT, |
|
252 | 252 | LIN_code varchar(245) NOT NULL DEFAULT '', |
253 | 253 | TXN_ID int(11) DEFAULT NULL, |
254 | 254 | LIN_name varchar(245) NOT NULL DEFAULT '', |
@@ -269,11 +269,11 @@ discard block |
||
269 | 269 | KEY txn_type_timestamp (TXN_ID,LIN_type,LIN_timestamp), |
270 | 270 | KEY txn_obj_id_obj_type (TXN_ID,OBJ_ID,OBJ_type), |
271 | 271 | KEY obj_id_obj_type (OBJ_ID,OBJ_type)"; |
272 | - $this->_get_table_manager()->dropIndex('esp_line_item', 'TXN_ID'); |
|
273 | - $this->_get_table_manager()->dropIndex('esp_line_item', 'LIN_code'); |
|
274 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
275 | - $table_name = 'esp_log'; |
|
276 | - $sql = "LOG_ID int(11) NOT NULL AUTO_INCREMENT, |
|
272 | + $this->_get_table_manager()->dropIndex('esp_line_item', 'TXN_ID'); |
|
273 | + $this->_get_table_manager()->dropIndex('esp_line_item', 'LIN_code'); |
|
274 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
275 | + $table_name = 'esp_log'; |
|
276 | + $sql = "LOG_ID int(11) NOT NULL AUTO_INCREMENT, |
|
277 | 277 | LOG_time datetime DEFAULT NULL, |
278 | 278 | OBJ_ID varchar(45) DEFAULT NULL, |
279 | 279 | OBJ_type varchar(45) DEFAULT NULL, |
@@ -284,12 +284,12 @@ discard block |
||
284 | 284 | KEY LOG_time (LOG_time), |
285 | 285 | KEY OBJ (OBJ_type,OBJ_ID), |
286 | 286 | KEY LOG_type (LOG_type)"; |
287 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
288 | - $table_name = 'esp_message'; |
|
289 | - $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_to'); |
|
290 | - $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_from'); |
|
291 | - $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_subject'); |
|
292 | - $sql = "MSG_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
287 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
288 | + $table_name = 'esp_message'; |
|
289 | + $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_to'); |
|
290 | + $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_from'); |
|
291 | + $this->_get_table_manager()->dropIndexIfSizeNot($table_name, 'MSG_subject'); |
|
292 | + $sql = "MSG_ID bigint(20) unsigned NOT NULL AUTO_INCREMENT, |
|
293 | 293 | GRP_ID int(10) unsigned NULL, |
294 | 294 | MSG_token varchar(255) NULL, |
295 | 295 | TXN_ID int(10) unsigned NULL, |
@@ -321,18 +321,18 @@ discard block |
||
321 | 321 | KEY STS_ID (STS_ID), |
322 | 322 | KEY MSG_created (MSG_created), |
323 | 323 | KEY MSG_modified (MSG_modified)"; |
324 | - $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
325 | - $table_name = 'esp_message_template'; |
|
326 | - $sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
324 | + $this->_table_is_new_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
325 | + $table_name = 'esp_message_template'; |
|
326 | + $sql = "MTP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
327 | 327 | GRP_ID int(10) unsigned NOT NULL, |
328 | 328 | MTP_context varchar(50) NOT NULL, |
329 | 329 | MTP_template_field varchar(30) NOT NULL, |
330 | 330 | MTP_content text NOT NULL, |
331 | 331 | PRIMARY KEY (MTP_ID), |
332 | 332 | KEY GRP_ID (GRP_ID)"; |
333 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
334 | - $table_name = 'esp_message_template_group'; |
|
335 | - $sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
333 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
334 | + $table_name = 'esp_message_template_group'; |
|
335 | + $sql = "GRP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
336 | 336 | MTP_user_id int(10) NOT NULL DEFAULT '1', |
337 | 337 | MTP_name varchar(245) NOT NULL DEFAULT '', |
338 | 338 | MTP_description varchar(245) NOT NULL DEFAULT '', |
@@ -344,9 +344,9 @@ discard block |
||
344 | 344 | MTP_is_active tinyint(1) NOT NULL DEFAULT '1', |
345 | 345 | PRIMARY KEY (GRP_ID), |
346 | 346 | KEY MTP_user_id (MTP_user_id)"; |
347 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
348 | - $table_name = 'esp_payment'; |
|
349 | - $sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
347 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
348 | + $table_name = 'esp_payment'; |
|
349 | + $sql = "PAY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
350 | 350 | TXN_ID int(10) unsigned DEFAULT NULL, |
351 | 351 | STS_ID varchar(3) DEFAULT NULL, |
352 | 352 | PAY_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00', |
@@ -363,9 +363,9 @@ discard block |
||
363 | 363 | PRIMARY KEY (PAY_ID), |
364 | 364 | KEY PAY_timestamp (PAY_timestamp), |
365 | 365 | KEY TXN_ID (TXN_ID)"; |
366 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
367 | - $table_name = 'esp_payment_method'; |
|
368 | - $sql = "PMD_ID int(11) NOT NULL AUTO_INCREMENT, |
|
366 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
367 | + $table_name = 'esp_payment_method'; |
|
368 | + $sql = "PMD_ID int(11) NOT NULL AUTO_INCREMENT, |
|
369 | 369 | PMD_type varchar(124) DEFAULT NULL, |
370 | 370 | PMD_name varchar(255) DEFAULT NULL, |
371 | 371 | PMD_desc text, |
@@ -381,24 +381,24 @@ discard block |
||
381 | 381 | PRIMARY KEY (PMD_ID), |
382 | 382 | UNIQUE KEY PMD_slug_UNIQUE (PMD_slug), |
383 | 383 | KEY PMD_type (PMD_type)"; |
384 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
385 | - $table_name = "esp_ticket_price"; |
|
386 | - $sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
384 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
385 | + $table_name = "esp_ticket_price"; |
|
386 | + $sql = "TKP_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
387 | 387 | TKT_ID int(10) unsigned NOT NULL, |
388 | 388 | PRC_ID int(10) unsigned NOT NULL, |
389 | 389 | PRIMARY KEY (TKP_ID), |
390 | 390 | KEY TKT_ID (TKT_ID), |
391 | 391 | KEY PRC_ID (PRC_ID)"; |
392 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
393 | - $table_name = "esp_ticket_template"; |
|
394 | - $sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
392 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
393 | + $table_name = "esp_ticket_template"; |
|
394 | + $sql = "TTM_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
395 | 395 | TTM_name varchar(45) NOT NULL, |
396 | 396 | TTM_description text, |
397 | 397 | TTM_file varchar(45), |
398 | 398 | PRIMARY KEY (TTM_ID)"; |
399 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
400 | - $table_name = 'esp_question'; |
|
401 | - $sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
399 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
400 | + $table_name = 'esp_question'; |
|
401 | + $sql = 'QST_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
402 | 402 | QST_display_text text NOT NULL, |
403 | 403 | QST_admin_label varchar(255) NOT NULL, |
404 | 404 | QST_system varchar(25) DEFAULT NULL, |
@@ -412,18 +412,18 @@ discard block |
||
412 | 412 | QST_deleted tinyint(2) unsigned NOT NULL DEFAULT 0, |
413 | 413 | PRIMARY KEY (QST_ID), |
414 | 414 | KEY QST_order (QST_order)'; |
415 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
416 | - $table_name = 'esp_question_group_question'; |
|
417 | - $sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
415 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
416 | + $table_name = 'esp_question_group_question'; |
|
417 | + $sql = "QGQ_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
418 | 418 | QSG_ID int(10) unsigned NOT NULL, |
419 | 419 | QST_ID int(10) unsigned NOT NULL, |
420 | 420 | QGQ_order int(10) unsigned NOT NULL DEFAULT 0, |
421 | 421 | PRIMARY KEY (QGQ_ID), |
422 | 422 | KEY QST_ID (QST_ID), |
423 | 423 | KEY QSG_ID_order (QSG_ID,QGQ_order)"; |
424 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
425 | - $table_name = 'esp_question_option'; |
|
426 | - $sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
424 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
425 | + $table_name = 'esp_question_option'; |
|
426 | + $sql = "QSO_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
427 | 427 | QSO_value varchar(255) NOT NULL, |
428 | 428 | QSO_desc text NOT NULL, |
429 | 429 | QST_ID int(10) unsigned NOT NULL, |
@@ -433,9 +433,9 @@ discard block |
||
433 | 433 | PRIMARY KEY (QSO_ID), |
434 | 434 | KEY QST_ID (QST_ID), |
435 | 435 | KEY QSO_order (QSO_order)"; |
436 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
437 | - $table_name = 'esp_registration'; |
|
438 | - $sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
436 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
437 | + $table_name = 'esp_registration'; |
|
438 | + $sql = "REG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
439 | 439 | EVT_ID bigint(20) unsigned NOT NULL, |
440 | 440 | ATT_ID bigint(20) unsigned NOT NULL, |
441 | 441 | TXN_ID int(10) unsigned NOT NULL, |
@@ -459,18 +459,18 @@ discard block |
||
459 | 459 | KEY TKT_ID (TKT_ID), |
460 | 460 | KEY EVT_ID (EVT_ID), |
461 | 461 | KEY STS_ID (STS_ID)"; |
462 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
463 | - $table_name = 'esp_registration_payment'; |
|
464 | - $sql = "RPY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
462 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
463 | + $table_name = 'esp_registration_payment'; |
|
464 | + $sql = "RPY_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
465 | 465 | REG_ID int(10) unsigned NOT NULL, |
466 | 466 | PAY_ID int(10) unsigned NULL, |
467 | 467 | RPY_amount decimal(12,3) NOT NULL DEFAULT '0.00', |
468 | 468 | PRIMARY KEY (RPY_ID), |
469 | 469 | KEY REG_ID (REG_ID), |
470 | 470 | KEY PAY_ID (PAY_ID)"; |
471 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
472 | - $table_name = 'esp_state'; |
|
473 | - $sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT, |
|
471 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB '); |
|
472 | + $table_name = 'esp_state'; |
|
473 | + $sql = "STA_ID smallint(5) unsigned NOT NULL AUTO_INCREMENT, |
|
474 | 474 | CNT_ISO varchar(2) NOT NULL, |
475 | 475 | STA_abbrev varchar(24) NOT NULL, |
476 | 476 | STA_name varchar(100) NOT NULL, |
@@ -478,9 +478,9 @@ discard block |
||
478 | 478 | PRIMARY KEY (STA_ID), |
479 | 479 | KEY STA_abbrev (STA_abbrev), |
480 | 480 | KEY CNT_ISO (CNT_ISO)"; |
481 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
482 | - $table_name = 'esp_status'; |
|
483 | - $sql = "STS_ID varchar(3) NOT NULL, |
|
481 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
482 | + $table_name = 'esp_status'; |
|
483 | + $sql = "STS_ID varchar(3) NOT NULL, |
|
484 | 484 | STS_code varchar(45) NOT NULL, |
485 | 485 | STS_type varchar(45) NOT NULL, |
486 | 486 | STS_can_edit tinyint(1) NOT NULL DEFAULT 0, |
@@ -488,9 +488,9 @@ discard block |
||
488 | 488 | STS_open tinyint(1) NOT NULL DEFAULT 1, |
489 | 489 | UNIQUE KEY STS_ID_UNIQUE (STS_ID), |
490 | 490 | KEY STS_type (STS_type)"; |
491 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
492 | - $table_name = 'esp_transaction'; |
|
493 | - $sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
491 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
492 | + $table_name = 'esp_transaction'; |
|
493 | + $sql = "TXN_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
494 | 494 | TXN_timestamp datetime NOT NULL DEFAULT '0000-00-00 00:00:00', |
495 | 495 | TXN_total decimal(12,3) DEFAULT '0.00', |
496 | 496 | TXN_paid decimal(12,3) NOT NULL DEFAULT '0.00', |
@@ -502,9 +502,9 @@ discard block |
||
502 | 502 | PRIMARY KEY (TXN_ID), |
503 | 503 | KEY TXN_timestamp (TXN_timestamp), |
504 | 504 | KEY STS_ID (STS_ID)"; |
505 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
506 | - $table_name = 'esp_venue_meta'; |
|
507 | - $sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
505 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
506 | + $table_name = 'esp_venue_meta'; |
|
507 | + $sql = "VNUM_ID int(11) NOT NULL AUTO_INCREMENT, |
|
508 | 508 | VNU_ID bigint(20) unsigned NOT NULL DEFAULT 0, |
509 | 509 | VNU_address varchar(255) DEFAULT NULL, |
510 | 510 | VNU_address2 varchar(255) DEFAULT NULL, |
@@ -523,10 +523,10 @@ discard block |
||
523 | 523 | KEY VNU_ID (VNU_ID), |
524 | 524 | KEY STA_ID (STA_ID), |
525 | 525 | KEY CNT_ISO (CNT_ISO)"; |
526 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
527 | - // modified tables |
|
528 | - $table_name = "esp_price"; |
|
529 | - $sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
526 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
527 | + // modified tables |
|
528 | + $table_name = "esp_price"; |
|
529 | + $sql = "PRC_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
530 | 530 | PRT_ID tinyint(3) unsigned NOT NULL, |
531 | 531 | PRC_amount decimal(12,3) NOT NULL DEFAULT '0.00', |
532 | 532 | PRC_name varchar(245) NOT NULL, |
@@ -539,9 +539,9 @@ discard block |
||
539 | 539 | PRC_parent int(10) unsigned DEFAULT 0, |
540 | 540 | PRIMARY KEY (PRC_ID), |
541 | 541 | KEY PRT_ID (PRT_ID)"; |
542 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
543 | - $table_name = "esp_price_type"; |
|
544 | - $sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT, |
|
542 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
543 | + $table_name = "esp_price_type"; |
|
544 | + $sql = "PRT_ID tinyint(3) unsigned NOT NULL AUTO_INCREMENT, |
|
545 | 545 | PRT_name varchar(45) NOT NULL, |
546 | 546 | PBT_ID tinyint(3) unsigned NOT NULL DEFAULT '1', |
547 | 547 | PRT_is_percent tinyint(1) NOT NULL DEFAULT '0', |
@@ -550,9 +550,9 @@ discard block |
||
550 | 550 | PRT_deleted tinyint(1) NOT NULL DEFAULT '0', |
551 | 551 | UNIQUE KEY PRT_name_UNIQUE (PRT_name), |
552 | 552 | PRIMARY KEY (PRT_ID)"; |
553 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
554 | - $table_name = "esp_ticket"; |
|
555 | - $sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
553 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB '); |
|
554 | + $table_name = "esp_ticket"; |
|
555 | + $sql = "TKT_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
556 | 556 | TTM_ID int(10) unsigned NOT NULL, |
557 | 557 | TKT_name varchar(245) NOT NULL DEFAULT '', |
558 | 558 | TKT_description text NOT NULL, |
@@ -575,9 +575,9 @@ discard block |
||
575 | 575 | TKT_deleted tinyint(1) NOT NULL DEFAULT '0', |
576 | 576 | PRIMARY KEY (TKT_ID), |
577 | 577 | KEY TKT_start_date (TKT_start_date)"; |
578 | - $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
579 | - $table_name = 'esp_question_group'; |
|
580 | - $sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
578 | + $this->_table_is_changed_in_this_version($table_name, $sql, 'ENGINE=InnoDB'); |
|
579 | + $table_name = 'esp_question_group'; |
|
580 | + $sql = 'QSG_ID int(10) unsigned NOT NULL AUTO_INCREMENT, |
|
581 | 581 | QSG_name varchar(255) NOT NULL, |
582 | 582 | QSG_identifier varchar(100) NOT NULL, |
583 | 583 | QSG_desc text NULL, |
@@ -590,165 +590,165 @@ discard block |
||
590 | 590 | PRIMARY KEY (QSG_ID), |
591 | 591 | UNIQUE KEY QSG_identifier_UNIQUE (QSG_identifier), |
592 | 592 | KEY QSG_order (QSG_order)'; |
593 | - $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
594 | - $this->insert_default_data(); |
|
595 | - return true; |
|
596 | - } |
|
593 | + $this->_table_has_not_changed_since_previous($table_name, $sql, 'ENGINE=InnoDB'); |
|
594 | + $this->insert_default_data(); |
|
595 | + return true; |
|
596 | + } |
|
597 | 597 | |
598 | - /** |
|
599 | - * Inserts default data after parent was called. |
|
600 | - * @since 4.10.0.p |
|
601 | - * @throws EE_Error |
|
602 | - * @throws InvalidArgumentException |
|
603 | - * @throws ReflectionException |
|
604 | - * @throws InvalidDataTypeException |
|
605 | - * @throws InvalidInterfaceException |
|
606 | - */ |
|
607 | - public function insert_default_data() |
|
608 | - { |
|
609 | - /** @var EE_DMS_Core_4_1_0 $script_4_1_defaults */ |
|
610 | - $script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0'); |
|
611 | - // (because many need to convert old string states to foreign keys into the states table) |
|
612 | - $script_4_1_defaults->insert_default_states(); |
|
613 | - $script_4_1_defaults->insert_default_countries(); |
|
614 | - /** @var EE_DMS_Core_4_5_0 $script_4_5_defaults */ |
|
615 | - $script_4_5_defaults = EE_Registry::instance()->load_dms('Core_4_5_0'); |
|
616 | - $script_4_5_defaults->insert_default_price_types(); |
|
617 | - $script_4_5_defaults->insert_default_prices(); |
|
618 | - $script_4_5_defaults->insert_default_tickets(); |
|
619 | - /** @var EE_DMS_Core_4_6_0 $script_4_6_defaults */ |
|
620 | - $script_4_6_defaults = EE_Registry::instance()->load_dms('Core_4_6_0'); |
|
621 | - $script_4_6_defaults->add_default_admin_only_payments(); |
|
622 | - $script_4_6_defaults->insert_default_currencies(); |
|
623 | - /** @var EE_DMS_Core_4_8_0 $script_4_8_defaults */ |
|
624 | - $script_4_8_defaults = EE_Registry::instance()->load_dms('Core_4_8_0'); |
|
625 | - $script_4_8_defaults->verify_new_countries(); |
|
626 | - $script_4_8_defaults->verify_new_currencies(); |
|
627 | - $this->verify_db_collations(); |
|
628 | - $this->verify_db_collations_again(); |
|
629 | - } |
|
598 | + /** |
|
599 | + * Inserts default data after parent was called. |
|
600 | + * @since 4.10.0.p |
|
601 | + * @throws EE_Error |
|
602 | + * @throws InvalidArgumentException |
|
603 | + * @throws ReflectionException |
|
604 | + * @throws InvalidDataTypeException |
|
605 | + * @throws InvalidInterfaceException |
|
606 | + */ |
|
607 | + public function insert_default_data() |
|
608 | + { |
|
609 | + /** @var EE_DMS_Core_4_1_0 $script_4_1_defaults */ |
|
610 | + $script_4_1_defaults = EE_Registry::instance()->load_dms('Core_4_1_0'); |
|
611 | + // (because many need to convert old string states to foreign keys into the states table) |
|
612 | + $script_4_1_defaults->insert_default_states(); |
|
613 | + $script_4_1_defaults->insert_default_countries(); |
|
614 | + /** @var EE_DMS_Core_4_5_0 $script_4_5_defaults */ |
|
615 | + $script_4_5_defaults = EE_Registry::instance()->load_dms('Core_4_5_0'); |
|
616 | + $script_4_5_defaults->insert_default_price_types(); |
|
617 | + $script_4_5_defaults->insert_default_prices(); |
|
618 | + $script_4_5_defaults->insert_default_tickets(); |
|
619 | + /** @var EE_DMS_Core_4_6_0 $script_4_6_defaults */ |
|
620 | + $script_4_6_defaults = EE_Registry::instance()->load_dms('Core_4_6_0'); |
|
621 | + $script_4_6_defaults->add_default_admin_only_payments(); |
|
622 | + $script_4_6_defaults->insert_default_currencies(); |
|
623 | + /** @var EE_DMS_Core_4_8_0 $script_4_8_defaults */ |
|
624 | + $script_4_8_defaults = EE_Registry::instance()->load_dms('Core_4_8_0'); |
|
625 | + $script_4_8_defaults->verify_new_countries(); |
|
626 | + $script_4_8_defaults->verify_new_currencies(); |
|
627 | + $this->verify_db_collations(); |
|
628 | + $this->verify_db_collations_again(); |
|
629 | + } |
|
630 | 630 | |
631 | 631 | |
632 | 632 | |
633 | - /** |
|
634 | - * @return boolean |
|
635 | - */ |
|
636 | - public function schema_changes_after_migration() |
|
637 | - { |
|
638 | - return true; |
|
639 | - } |
|
633 | + /** |
|
634 | + * @return boolean |
|
635 | + */ |
|
636 | + public function schema_changes_after_migration() |
|
637 | + { |
|
638 | + return true; |
|
639 | + } |
|
640 | 640 | |
641 | 641 | |
642 | 642 | |
643 | - public function migration_page_hooks() |
|
644 | - { |
|
645 | - } |
|
643 | + public function migration_page_hooks() |
|
644 | + { |
|
645 | + } |
|
646 | 646 | |
647 | 647 | |
648 | 648 | |
649 | - /** |
|
650 | - * Verify all EE4 models' tables use utf8mb4 collation |
|
651 | - * |
|
652 | - * @return void |
|
653 | - */ |
|
654 | - public function verify_db_collations() |
|
655 | - { |
|
656 | - global $wpdb; |
|
657 | - // double-check we haven't already done it or that that the DB doesn't support utf8mb4 |
|
658 | - if ( |
|
659 | - 'utf8mb4' !== $wpdb->charset |
|
660 | - || get_option('ee_verified_db_collations', false) |
|
661 | - ) { |
|
662 | - return; |
|
663 | - } |
|
664 | - // grab tables from each model |
|
665 | - $tables_to_check = array(); |
|
666 | - foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
667 | - if (method_exists($model_name, 'instance')) { |
|
668 | - $model_obj = call_user_func(array($model_name, 'instance')); |
|
669 | - if ($model_obj instanceof EEM_Base) { |
|
670 | - foreach ($model_obj->get_tables() as $table) { |
|
671 | - if ( |
|
672 | - strpos($table->get_table_name(), 'esp_') |
|
673 | - && (is_main_site()// for main tables, verify global tables |
|
674 | - || ! $table->is_global()// if not the main site, then only verify non-global tables (avoid doubling up) |
|
675 | - ) |
|
676 | - && function_exists('maybe_convert_table_to_utf8mb4') |
|
677 | - ) { |
|
678 | - $tables_to_check[] = $table->get_table_name(); |
|
679 | - } |
|
680 | - } |
|
681 | - } |
|
682 | - } |
|
683 | - } |
|
684 | - // and let's just be sure these addons' tables get migrated too. They already get handled if their addons are active |
|
685 | - // when this code is run, but not otherwise. Once we record what tables EE added, we'll be able to use that instead |
|
686 | - // of hard-coding this |
|
687 | - $addon_tables = array( |
|
688 | - // mailchimp |
|
689 | - 'esp_event_mailchimp_list_group', |
|
690 | - 'esp_event_question_mailchimp_field', |
|
691 | - // multisite |
|
692 | - 'esp_blog_meta', |
|
693 | - // people |
|
694 | - 'esp_people_to_post', |
|
695 | - // promotions |
|
696 | - 'esp_promotion', |
|
697 | - 'esp_promotion_object', |
|
698 | - ); |
|
699 | - foreach ($addon_tables as $table_name) { |
|
700 | - $tables_to_check[] = $table_name; |
|
701 | - } |
|
702 | - $this->_verify_db_collations_for_tables(array_unique($tables_to_check)); |
|
703 | - // ok and now let's remember this was done (without needing to check the db schemas all over again) |
|
704 | - add_option('ee_verified_db_collations', true, null, 'no'); |
|
705 | - // seeing how this ran with the fix from 10435, no need to check again |
|
706 | - add_option('ee_verified_db_collations_again', true, null, 'no'); |
|
707 | - } |
|
649 | + /** |
|
650 | + * Verify all EE4 models' tables use utf8mb4 collation |
|
651 | + * |
|
652 | + * @return void |
|
653 | + */ |
|
654 | + public function verify_db_collations() |
|
655 | + { |
|
656 | + global $wpdb; |
|
657 | + // double-check we haven't already done it or that that the DB doesn't support utf8mb4 |
|
658 | + if ( |
|
659 | + 'utf8mb4' !== $wpdb->charset |
|
660 | + || get_option('ee_verified_db_collations', false) |
|
661 | + ) { |
|
662 | + return; |
|
663 | + } |
|
664 | + // grab tables from each model |
|
665 | + $tables_to_check = array(); |
|
666 | + foreach (EE_Registry::instance()->non_abstract_db_models as $model_name) { |
|
667 | + if (method_exists($model_name, 'instance')) { |
|
668 | + $model_obj = call_user_func(array($model_name, 'instance')); |
|
669 | + if ($model_obj instanceof EEM_Base) { |
|
670 | + foreach ($model_obj->get_tables() as $table) { |
|
671 | + if ( |
|
672 | + strpos($table->get_table_name(), 'esp_') |
|
673 | + && (is_main_site()// for main tables, verify global tables |
|
674 | + || ! $table->is_global()// if not the main site, then only verify non-global tables (avoid doubling up) |
|
675 | + ) |
|
676 | + && function_exists('maybe_convert_table_to_utf8mb4') |
|
677 | + ) { |
|
678 | + $tables_to_check[] = $table->get_table_name(); |
|
679 | + } |
|
680 | + } |
|
681 | + } |
|
682 | + } |
|
683 | + } |
|
684 | + // and let's just be sure these addons' tables get migrated too. They already get handled if their addons are active |
|
685 | + // when this code is run, but not otherwise. Once we record what tables EE added, we'll be able to use that instead |
|
686 | + // of hard-coding this |
|
687 | + $addon_tables = array( |
|
688 | + // mailchimp |
|
689 | + 'esp_event_mailchimp_list_group', |
|
690 | + 'esp_event_question_mailchimp_field', |
|
691 | + // multisite |
|
692 | + 'esp_blog_meta', |
|
693 | + // people |
|
694 | + 'esp_people_to_post', |
|
695 | + // promotions |
|
696 | + 'esp_promotion', |
|
697 | + 'esp_promotion_object', |
|
698 | + ); |
|
699 | + foreach ($addon_tables as $table_name) { |
|
700 | + $tables_to_check[] = $table_name; |
|
701 | + } |
|
702 | + $this->_verify_db_collations_for_tables(array_unique($tables_to_check)); |
|
703 | + // ok and now let's remember this was done (without needing to check the db schemas all over again) |
|
704 | + add_option('ee_verified_db_collations', true, null, 'no'); |
|
705 | + // seeing how this ran with the fix from 10435, no need to check again |
|
706 | + add_option('ee_verified_db_collations_again', true, null, 'no'); |
|
707 | + } |
|
708 | 708 | |
709 | 709 | |
710 | 710 | |
711 | - /** |
|
712 | - * Verifies DB collations because a bug was discovered on https://events.codebasehq.com/projects/event-espresso/tickets/10435 |
|
713 | - * which meant some DB collations might not have been updated |
|
714 | - * @return void |
|
715 | - */ |
|
716 | - public function verify_db_collations_again() |
|
717 | - { |
|
718 | - global $wpdb; |
|
719 | - // double-check we haven't already done this or that the DB doesn't support it |
|
720 | - // compare to how WordPress' upgrade_430() function does this check |
|
721 | - if ( |
|
722 | - 'utf8mb4' !== $wpdb->charset |
|
723 | - || get_option('ee_verified_db_collations_again', false) |
|
724 | - ) { |
|
725 | - return; |
|
726 | - } |
|
727 | - $tables_to_check = array( |
|
728 | - 'esp_attendee_meta', |
|
729 | - 'esp_message' |
|
730 | - ); |
|
731 | - $this->_verify_db_collations_for_tables(array_unique($tables_to_check)); |
|
732 | - add_option('ee_verified_db_collations_again', true, null, 'no'); |
|
733 | - } |
|
711 | + /** |
|
712 | + * Verifies DB collations because a bug was discovered on https://events.codebasehq.com/projects/event-espresso/tickets/10435 |
|
713 | + * which meant some DB collations might not have been updated |
|
714 | + * @return void |
|
715 | + */ |
|
716 | + public function verify_db_collations_again() |
|
717 | + { |
|
718 | + global $wpdb; |
|
719 | + // double-check we haven't already done this or that the DB doesn't support it |
|
720 | + // compare to how WordPress' upgrade_430() function does this check |
|
721 | + if ( |
|
722 | + 'utf8mb4' !== $wpdb->charset |
|
723 | + || get_option('ee_verified_db_collations_again', false) |
|
724 | + ) { |
|
725 | + return; |
|
726 | + } |
|
727 | + $tables_to_check = array( |
|
728 | + 'esp_attendee_meta', |
|
729 | + 'esp_message' |
|
730 | + ); |
|
731 | + $this->_verify_db_collations_for_tables(array_unique($tables_to_check)); |
|
732 | + add_option('ee_verified_db_collations_again', true, null, 'no'); |
|
733 | + } |
|
734 | 734 | |
735 | 735 | |
736 | 736 | |
737 | - /** |
|
738 | - * Runs maybe_convert_table_to_utf8mb4 on the specified tables |
|
739 | - * @param $tables_to_check |
|
740 | - * @return boolean true if logic ran, false if it didn't |
|
741 | - */ |
|
742 | - protected function _verify_db_collations_for_tables($tables_to_check) |
|
743 | - { |
|
744 | - foreach ($tables_to_check as $table_name) { |
|
745 | - $table_name = $this->_table_analysis->ensureTableNameHasPrefix($table_name); |
|
746 | - if ( |
|
747 | - ! apply_filters('FHEE__EE_DMS_Core_4_9_0__verify_db_collations__check_overridden', false, $table_name) |
|
748 | - && $this->_get_table_analysis()->tableExists($table_name) |
|
749 | - ) { |
|
750 | - maybe_convert_table_to_utf8mb4($table_name); |
|
751 | - } |
|
752 | - } |
|
753 | - } |
|
737 | + /** |
|
738 | + * Runs maybe_convert_table_to_utf8mb4 on the specified tables |
|
739 | + * @param $tables_to_check |
|
740 | + * @return boolean true if logic ran, false if it didn't |
|
741 | + */ |
|
742 | + protected function _verify_db_collations_for_tables($tables_to_check) |
|
743 | + { |
|
744 | + foreach ($tables_to_check as $table_name) { |
|
745 | + $table_name = $this->_table_analysis->ensureTableNameHasPrefix($table_name); |
|
746 | + if ( |
|
747 | + ! apply_filters('FHEE__EE_DMS_Core_4_9_0__verify_db_collations__check_overridden', false, $table_name) |
|
748 | + && $this->_get_table_analysis()->tableExists($table_name) |
|
749 | + ) { |
|
750 | + maybe_convert_table_to_utf8mb4($table_name); |
|
751 | + } |
|
752 | + } |
|
753 | + } |
|
754 | 754 | } |
@@ -66,8 +66,8 @@ |
||
66 | 66 | { |
67 | 67 | |
68 | 68 | $templates_relative_path = 'modules/gateways/Invoice/lib/templates/'; |
69 | - $overridden_invoice_body = EEH_Template::locate_template($templates_relative_path . 'invoice_body.template.php', null, false, false, true); |
|
70 | - $overridden_receipt_body = EEH_Template::locate_template($templates_relative_path . 'receipt_body.template.php', null, false, false, true); |
|
69 | + $overridden_invoice_body = EEH_Template::locate_template($templates_relative_path.'invoice_body.template.php', null, false, false, true); |
|
70 | + $overridden_receipt_body = EEH_Template::locate_template($templates_relative_path.'receipt_body.template.php', null, false, false, true); |
|
71 | 71 | if ($overridden_invoice_body || $overridden_receipt_body) { |
72 | 72 | new PersistentAdminNotice( |
73 | 73 | 'invoice_overriding_templates', |
@@ -27,59 +27,59 @@ |
||
27 | 27 | */ |
28 | 28 | class EE_DMS_4_6_0_invoice_settings extends EE_Data_Migration_Script_Stage |
29 | 29 | { |
30 | - /** |
|
31 | - * Just initializes the status of the migration |
|
32 | - */ |
|
33 | - public function __construct() |
|
34 | - { |
|
35 | - $this->_pretty_name = esc_html__('Update Invoice Settings', 'event_espresso'); |
|
36 | - parent::__construct(); |
|
37 | - } |
|
30 | + /** |
|
31 | + * Just initializes the status of the migration |
|
32 | + */ |
|
33 | + public function __construct() |
|
34 | + { |
|
35 | + $this->_pretty_name = esc_html__('Update Invoice Settings', 'event_espresso'); |
|
36 | + parent::__construct(); |
|
37 | + } |
|
38 | 38 | |
39 | 39 | |
40 | 40 | |
41 | - /** |
|
42 | - * _count_records_to_migrate |
|
43 | - * Counts the records to migrate; the public version may cache it |
|
44 | - * |
|
45 | - * @access protected |
|
46 | - * @return int |
|
47 | - */ |
|
48 | - protected function _count_records_to_migrate() |
|
49 | - { |
|
50 | - return 1; |
|
51 | - } |
|
41 | + /** |
|
42 | + * _count_records_to_migrate |
|
43 | + * Counts the records to migrate; the public version may cache it |
|
44 | + * |
|
45 | + * @access protected |
|
46 | + * @return int |
|
47 | + */ |
|
48 | + protected function _count_records_to_migrate() |
|
49 | + { |
|
50 | + return 1; |
|
51 | + } |
|
52 | 52 | |
53 | 53 | |
54 | 54 | |
55 | - /** |
|
56 | - * _migration_step |
|
57 | - * |
|
58 | - * @access protected |
|
59 | - * @param int $num_items |
|
60 | - * @throws EE_Error |
|
61 | - * @return int number of items ACTUALLY migrated |
|
62 | - * @throws InvalidDataTypeException |
|
63 | - */ |
|
64 | - protected function _migration_step($num_items = 1) |
|
65 | - { |
|
55 | + /** |
|
56 | + * _migration_step |
|
57 | + * |
|
58 | + * @access protected |
|
59 | + * @param int $num_items |
|
60 | + * @throws EE_Error |
|
61 | + * @return int number of items ACTUALLY migrated |
|
62 | + * @throws InvalidDataTypeException |
|
63 | + */ |
|
64 | + protected function _migration_step($num_items = 1) |
|
65 | + { |
|
66 | 66 | |
67 | - $templates_relative_path = 'modules/gateways/Invoice/lib/templates/'; |
|
68 | - $overridden_invoice_body = EEH_Template::locate_template($templates_relative_path . 'invoice_body.template.php', null, false, false, true); |
|
69 | - $overridden_receipt_body = EEH_Template::locate_template($templates_relative_path . 'receipt_body.template.php', null, false, false, true); |
|
70 | - if ($overridden_invoice_body || $overridden_receipt_body) { |
|
71 | - new PersistentAdminNotice( |
|
72 | - 'invoice_overriding_templates', |
|
73 | - esc_html__( |
|
74 | - 'Note: in this version of Event Espresso, PDF and HTML Invoices and Receipts are now Messages and can be changed just like any other messages; however we noticed you had previously overridden the old default Invoice/Receipt templates. Because of this, your old Invoice/Receipt templates will continue to be used INSTEAD of the new Invoice/Receipt message equivalents (but this will be removed in an upcoming version). We recommend deleting your old Invoice/Receipt templates and using the new messages system. Then modify the new Invoice and Receipt messages\'s content in Messages -> Invoice and Messages -> Receipt.', |
|
75 | - 'event_espresso' |
|
76 | - ), |
|
77 | - true |
|
78 | - ); |
|
79 | - } |
|
67 | + $templates_relative_path = 'modules/gateways/Invoice/lib/templates/'; |
|
68 | + $overridden_invoice_body = EEH_Template::locate_template($templates_relative_path . 'invoice_body.template.php', null, false, false, true); |
|
69 | + $overridden_receipt_body = EEH_Template::locate_template($templates_relative_path . 'receipt_body.template.php', null, false, false, true); |
|
70 | + if ($overridden_invoice_body || $overridden_receipt_body) { |
|
71 | + new PersistentAdminNotice( |
|
72 | + 'invoice_overriding_templates', |
|
73 | + esc_html__( |
|
74 | + 'Note: in this version of Event Espresso, PDF and HTML Invoices and Receipts are now Messages and can be changed just like any other messages; however we noticed you had previously overridden the old default Invoice/Receipt templates. Because of this, your old Invoice/Receipt templates will continue to be used INSTEAD of the new Invoice/Receipt message equivalents (but this will be removed in an upcoming version). We recommend deleting your old Invoice/Receipt templates and using the new messages system. Then modify the new Invoice and Receipt messages\'s content in Messages -> Invoice and Messages -> Receipt.', |
|
75 | + 'event_espresso' |
|
76 | + ), |
|
77 | + true |
|
78 | + ); |
|
79 | + } |
|
80 | 80 | |
81 | - // regardless of whether it worked or not, we ought to continue the migration |
|
82 | - $this->set_completed(); |
|
83 | - return 1; |
|
84 | - } |
|
81 | + // regardless of whether it worked or not, we ought to continue the migration |
|
82 | + $this->set_completed(); |
|
83 | + return 1; |
|
84 | + } |
|
85 | 85 | } |
@@ -36,19 +36,19 @@ discard block |
||
36 | 36 | { |
37 | 37 | EE_Load_Textdomain::loadTranslationsForLocale(); |
38 | 38 | // now load the textdomain |
39 | - if (!empty(EE_Load_Textdomain::$locale)) { |
|
40 | - $github_mo_path = EE_LANGUAGES_SAFE_DIR . 'event_espresso-' . EE_Load_Textdomain::$locale . '.mo'; |
|
39 | + if ( ! empty(EE_Load_Textdomain::$locale)) { |
|
40 | + $github_mo_path = EE_LANGUAGES_SAFE_DIR.'event_espresso-'.EE_Load_Textdomain::$locale.'.mo'; |
|
41 | 41 | if (is_readable($github_mo_path)) { |
42 | 42 | load_plugin_textdomain('event_espresso', false, EE_LANGUAGES_SAFE_LOC); |
43 | 43 | return; |
44 | 44 | } |
45 | - $glotpress_mo_path = EE_LANGUAGES_SAFE_DIR . 'event-espresso-4-' . EE_Load_Textdomain::$locale . '.mo'; |
|
45 | + $glotpress_mo_path = EE_LANGUAGES_SAFE_DIR.'event-espresso-4-'.EE_Load_Textdomain::$locale.'.mo'; |
|
46 | 46 | if (is_readable($glotpress_mo_path)) { |
47 | 47 | load_textdomain('event_espresso', $glotpress_mo_path); |
48 | 48 | return; |
49 | 49 | } |
50 | 50 | } |
51 | - load_plugin_textdomain('event_espresso', false, dirname(EE_PLUGIN_BASENAME) . '/languages/'); |
|
51 | + load_plugin_textdomain('event_espresso', false, dirname(EE_PLUGIN_BASENAME).'/languages/'); |
|
52 | 52 | } |
53 | 53 | |
54 | 54 | |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | if (empty(EE_Load_Textdomain::$locale)) { |
72 | 72 | return; |
73 | 73 | } |
74 | - $language_check_option_name = 'ee_lang_check_' . EE_Load_Textdomain::$locale . '_' . EVENT_ESPRESSO_VERSION; |
|
74 | + $language_check_option_name = 'ee_lang_check_'.EE_Load_Textdomain::$locale.'_'.EVENT_ESPRESSO_VERSION; |
|
75 | 75 | // check if language files has already been sideloaded |
76 | 76 | if (get_option($language_check_option_name)) { |
77 | 77 | return; |
@@ -81,8 +81,8 @@ discard block |
||
81 | 81 | |
82 | 82 | // load sideloader and sideload the .POT file as this should always be included. |
83 | 83 | $sideloader_args = array( |
84 | - '_upload_to' => EE_PLUGIN_DIR_PATH . 'languages/', |
|
85 | - '_download_from' => $repo_base_URL . '.pot?raw=true', |
|
84 | + '_upload_to' => EE_PLUGIN_DIR_PATH.'languages/', |
|
85 | + '_download_from' => $repo_base_URL.'.pot?raw=true', |
|
86 | 86 | '_new_file_name' => 'event_espresso.pot', |
87 | 87 | ); |
88 | 88 | /** @var EEH_Sideloader $sideloader */ |
@@ -98,8 +98,8 @@ discard block |
||
98 | 98 | update_option($language_check_option_name, 1); |
99 | 99 | return; |
100 | 100 | } |
101 | - $repo_locale_URL = $repo_base_URL . '-' . EE_Load_Textdomain::$locale; |
|
102 | - $file_name_base = 'event_espresso-' . EE_Load_Textdomain::$locale; |
|
101 | + $repo_locale_URL = $repo_base_URL.'-'.EE_Load_Textdomain::$locale; |
|
102 | + $file_name_base = 'event_espresso-'.EE_Load_Textdomain::$locale; |
|
103 | 103 | |
104 | 104 | // made it here so let's get the language files from the github repo, first the .mo file |
105 | 105 | $sideloader->set_download_from("{$repo_locale_URL}.mo?raw=true"); |
@@ -12,105 +12,105 @@ |
||
12 | 12 | */ |
13 | 13 | class EE_Load_Textdomain extends EE_Base |
14 | 14 | { |
15 | - /** |
|
16 | - * holds the current lang in WP |
|
17 | - * |
|
18 | - * @var string |
|
19 | - */ |
|
20 | - private static $locale; |
|
15 | + /** |
|
16 | + * holds the current lang in WP |
|
17 | + * |
|
18 | + * @var string |
|
19 | + */ |
|
20 | + private static $locale; |
|
21 | 21 | |
22 | 22 | |
23 | - /** |
|
24 | - * this takes care of retrieving a matching textdomain for event espresso for the current WPLANG from EE GitHub |
|
25 | - * repo (if necessary) and then loading it for translations. should only be called in wp plugins_loaded callback |
|
26 | - * |
|
27 | - * @return void |
|
28 | - * @throws EE_Error |
|
29 | - * @throws InvalidArgumentException |
|
30 | - * @throws ReflectionException |
|
31 | - * @throws InvalidDataTypeException |
|
32 | - * @throws InvalidInterfaceException |
|
33 | - */ |
|
34 | - public static function load_textdomain() |
|
35 | - { |
|
36 | - EE_Load_Textdomain::loadTranslationsForLocale(); |
|
37 | - // now load the textdomain |
|
38 | - if (!empty(EE_Load_Textdomain::$locale)) { |
|
39 | - $github_mo_path = EE_LANGUAGES_SAFE_DIR . 'event_espresso-' . EE_Load_Textdomain::$locale . '.mo'; |
|
40 | - if (is_readable($github_mo_path)) { |
|
41 | - load_plugin_textdomain('event_espresso', false, EE_LANGUAGES_SAFE_LOC); |
|
42 | - return; |
|
43 | - } |
|
44 | - $glotpress_mo_path = EE_LANGUAGES_SAFE_DIR . 'event-espresso-4-' . EE_Load_Textdomain::$locale . '.mo'; |
|
45 | - if (is_readable($glotpress_mo_path)) { |
|
46 | - load_textdomain('event_espresso', $glotpress_mo_path); |
|
47 | - return; |
|
48 | - } |
|
49 | - } |
|
50 | - load_plugin_textdomain('event_espresso', false, dirname(EE_PLUGIN_BASENAME) . '/languages/'); |
|
51 | - } |
|
23 | + /** |
|
24 | + * this takes care of retrieving a matching textdomain for event espresso for the current WPLANG from EE GitHub |
|
25 | + * repo (if necessary) and then loading it for translations. should only be called in wp plugins_loaded callback |
|
26 | + * |
|
27 | + * @return void |
|
28 | + * @throws EE_Error |
|
29 | + * @throws InvalidArgumentException |
|
30 | + * @throws ReflectionException |
|
31 | + * @throws InvalidDataTypeException |
|
32 | + * @throws InvalidInterfaceException |
|
33 | + */ |
|
34 | + public static function load_textdomain() |
|
35 | + { |
|
36 | + EE_Load_Textdomain::loadTranslationsForLocale(); |
|
37 | + // now load the textdomain |
|
38 | + if (!empty(EE_Load_Textdomain::$locale)) { |
|
39 | + $github_mo_path = EE_LANGUAGES_SAFE_DIR . 'event_espresso-' . EE_Load_Textdomain::$locale . '.mo'; |
|
40 | + if (is_readable($github_mo_path)) { |
|
41 | + load_plugin_textdomain('event_espresso', false, EE_LANGUAGES_SAFE_LOC); |
|
42 | + return; |
|
43 | + } |
|
44 | + $glotpress_mo_path = EE_LANGUAGES_SAFE_DIR . 'event-espresso-4-' . EE_Load_Textdomain::$locale . '.mo'; |
|
45 | + if (is_readable($glotpress_mo_path)) { |
|
46 | + load_textdomain('event_espresso', $glotpress_mo_path); |
|
47 | + return; |
|
48 | + } |
|
49 | + } |
|
50 | + load_plugin_textdomain('event_espresso', false, dirname(EE_PLUGIN_BASENAME) . '/languages/'); |
|
51 | + } |
|
52 | 52 | |
53 | 53 | |
54 | - /** |
|
55 | - * The purpose of this method is to sideload all of the lang files for EE, this includes the POT file and also the PO/MO files for the given WPLANG locale (if necessary). |
|
56 | - * |
|
57 | - * @access private |
|
58 | - * @static |
|
59 | - * @return void |
|
60 | - * @throws EE_Error |
|
61 | - * @throws InvalidArgumentException |
|
62 | - * @throws ReflectionException |
|
63 | - * @throws InvalidDataTypeException |
|
64 | - * @throws InvalidInterfaceException |
|
65 | - */ |
|
66 | - private static function loadTranslationsForLocale() |
|
67 | - { |
|
68 | - EE_Load_Textdomain::$locale = get_locale(); |
|
69 | - // can't download a language file if a language isn't set <taps temple> |
|
70 | - if (empty(EE_Load_Textdomain::$locale)) { |
|
71 | - return; |
|
72 | - } |
|
73 | - $language_check_option_name = 'ee_lang_check_' . EE_Load_Textdomain::$locale . '_' . EVENT_ESPRESSO_VERSION; |
|
74 | - // check if language files has already been sideloaded |
|
75 | - if (get_option($language_check_option_name)) { |
|
76 | - return; |
|
77 | - } |
|
54 | + /** |
|
55 | + * The purpose of this method is to sideload all of the lang files for EE, this includes the POT file and also the PO/MO files for the given WPLANG locale (if necessary). |
|
56 | + * |
|
57 | + * @access private |
|
58 | + * @static |
|
59 | + * @return void |
|
60 | + * @throws EE_Error |
|
61 | + * @throws InvalidArgumentException |
|
62 | + * @throws ReflectionException |
|
63 | + * @throws InvalidDataTypeException |
|
64 | + * @throws InvalidInterfaceException |
|
65 | + */ |
|
66 | + private static function loadTranslationsForLocale() |
|
67 | + { |
|
68 | + EE_Load_Textdomain::$locale = get_locale(); |
|
69 | + // can't download a language file if a language isn't set <taps temple> |
|
70 | + if (empty(EE_Load_Textdomain::$locale)) { |
|
71 | + return; |
|
72 | + } |
|
73 | + $language_check_option_name = 'ee_lang_check_' . EE_Load_Textdomain::$locale . '_' . EVENT_ESPRESSO_VERSION; |
|
74 | + // check if language files has already been sideloaded |
|
75 | + if (get_option($language_check_option_name)) { |
|
76 | + return; |
|
77 | + } |
|
78 | 78 | |
79 | - $repo_base_URL = 'https://github.com/eventespresso/languages-ee4/blob/master/event_espresso'; |
|
79 | + $repo_base_URL = 'https://github.com/eventespresso/languages-ee4/blob/master/event_espresso'; |
|
80 | 80 | |
81 | - // load sideloader and sideload the .POT file as this should always be included. |
|
82 | - $sideloader_args = array( |
|
83 | - '_upload_to' => EE_PLUGIN_DIR_PATH . 'languages/', |
|
84 | - '_download_from' => $repo_base_URL . '.pot?raw=true', |
|
85 | - '_new_file_name' => 'event_espresso.pot', |
|
86 | - ); |
|
87 | - /** @var EEH_Sideloader $sideloader */ |
|
88 | - $sideloader = EE_Registry::instance()->load_helper('Sideloader', $sideloader_args, false); |
|
89 | - // sideload the .POT file only for main site of the network, or if not running Multisite. |
|
90 | - if (is_main_site()) { |
|
91 | - $sideloader->sideload(); |
|
92 | - } |
|
81 | + // load sideloader and sideload the .POT file as this should always be included. |
|
82 | + $sideloader_args = array( |
|
83 | + '_upload_to' => EE_PLUGIN_DIR_PATH . 'languages/', |
|
84 | + '_download_from' => $repo_base_URL . '.pot?raw=true', |
|
85 | + '_new_file_name' => 'event_espresso.pot', |
|
86 | + ); |
|
87 | + /** @var EEH_Sideloader $sideloader */ |
|
88 | + $sideloader = EE_Registry::instance()->load_helper('Sideloader', $sideloader_args, false); |
|
89 | + // sideload the .POT file only for main site of the network, or if not running Multisite. |
|
90 | + if (is_main_site()) { |
|
91 | + $sideloader->sideload(); |
|
92 | + } |
|
93 | 93 | |
94 | - // if locale is "en_US" then lets just get out, since Event Espresso core is already "en_US" |
|
95 | - if (EE_Load_Textdomain::$locale === 'en_US') { |
|
96 | - // but set option first else we'll forever be downloading the pot file |
|
97 | - update_option($language_check_option_name, 1); |
|
98 | - return; |
|
99 | - } |
|
100 | - $repo_locale_URL = $repo_base_URL . '-' . EE_Load_Textdomain::$locale; |
|
101 | - $file_name_base = 'event_espresso-' . EE_Load_Textdomain::$locale; |
|
94 | + // if locale is "en_US" then lets just get out, since Event Espresso core is already "en_US" |
|
95 | + if (EE_Load_Textdomain::$locale === 'en_US') { |
|
96 | + // but set option first else we'll forever be downloading the pot file |
|
97 | + update_option($language_check_option_name, 1); |
|
98 | + return; |
|
99 | + } |
|
100 | + $repo_locale_URL = $repo_base_URL . '-' . EE_Load_Textdomain::$locale; |
|
101 | + $file_name_base = 'event_espresso-' . EE_Load_Textdomain::$locale; |
|
102 | 102 | |
103 | - // made it here so let's get the language files from the github repo, first the .mo file |
|
104 | - $sideloader->set_download_from("{$repo_locale_URL}.mo?raw=true"); |
|
105 | - $sideloader->set_new_file_name("{$file_name_base}.mo"); |
|
106 | - $sideloader->sideload(); |
|
103 | + // made it here so let's get the language files from the github repo, first the .mo file |
|
104 | + $sideloader->set_download_from("{$repo_locale_URL}.mo?raw=true"); |
|
105 | + $sideloader->set_new_file_name("{$file_name_base}.mo"); |
|
106 | + $sideloader->sideload(); |
|
107 | 107 | |
108 | - // now the .po file: |
|
109 | - $sideloader->set_download_from("{$repo_locale_URL}.po?raw=true"); |
|
110 | - $sideloader->set_new_file_name("{$file_name_base}.po"); |
|
111 | - $sideloader->sideload(); |
|
108 | + // now the .po file: |
|
109 | + $sideloader->set_download_from("{$repo_locale_URL}.po?raw=true"); |
|
110 | + $sideloader->set_new_file_name("{$file_name_base}.po"); |
|
111 | + $sideloader->sideload(); |
|
112 | 112 | |
113 | - // set option so the above only runs when EE updates. |
|
114 | - update_option($language_check_option_name, 1); |
|
115 | - } |
|
113 | + // set option so the above only runs when EE updates. |
|
114 | + update_option($language_check_option_name, 1); |
|
115 | + } |
|
116 | 116 | } |
@@ -296,7 +296,7 @@ discard block |
||
296 | 296 | */ |
297 | 297 | public function timestamp($dt_frmt = '', $tm_frmt = '') |
298 | 298 | { |
299 | - return $this->get_i18n_datetime('PAY_timestamp', trim($dt_frmt . ' ' . $tm_frmt)); |
|
299 | + return $this->get_i18n_datetime('PAY_timestamp', trim($dt_frmt.' '.$tm_frmt)); |
|
300 | 300 | } |
301 | 301 | |
302 | 302 | |
@@ -481,7 +481,7 @@ discard block |
||
481 | 481 | : ''; |
482 | 482 | break; |
483 | 483 | } |
484 | - return $icon . $status[ $this->STS_ID() ]; |
|
484 | + return $icon.$status[$this->STS_ID()]; |
|
485 | 485 | } |
486 | 486 | |
487 | 487 | |
@@ -627,7 +627,7 @@ discard block |
||
627 | 627 | public function redirect_form($inside_form_html = null) |
628 | 628 | { |
629 | 629 | $redirect_url = $this->redirect_url(); |
630 | - if (! empty($redirect_url)) { |
|
630 | + if ( ! empty($redirect_url)) { |
|
631 | 631 | // what ? no inner form content? |
632 | 632 | if ($inside_form_html === null) { |
633 | 633 | $inside_form_html = EEH_HTML::p( |
@@ -657,7 +657,7 @@ discard block |
||
657 | 657 | $get_params = null; |
658 | 658 | parse_str($querystring, $get_params); |
659 | 659 | $inside_form_html .= $this->_args_as_inputs($get_params); |
660 | - $redirect_url = str_replace('?' . $querystring, '', $redirect_url); |
|
660 | + $redirect_url = str_replace('?'.$querystring, '', $redirect_url); |
|
661 | 661 | } |
662 | 662 | $form = EEH_HTML::nl(1) |
663 | 663 | . '<form method="' |
@@ -665,9 +665,9 @@ discard block |
||
665 | 665 | . '" name="gateway_form" action="' |
666 | 666 | . $redirect_url |
667 | 667 | . '">'; |
668 | - $form .= EEH_HTML::nl(1) . $this->redirect_args_as_inputs(); |
|
668 | + $form .= EEH_HTML::nl(1).$this->redirect_args_as_inputs(); |
|
669 | 669 | $form .= $inside_form_html; |
670 | - $form .= EEH_HTML::nl(-1) . '</form>' . EEH_HTML::nl(-1); |
|
670 | + $form .= EEH_HTML::nl(-1).'</form>'.EEH_HTML::nl(-1); |
|
671 | 671 | return $form; |
672 | 672 | } else { |
673 | 673 | return null; |
@@ -725,8 +725,8 @@ discard block |
||
725 | 725 | return $html; |
726 | 726 | } |
727 | 727 | return EEH_HTML::nl() |
728 | - . '<input type="hidden" name="' . $name . '"' |
|
729 | - . ' value="' . esc_attr($value) . '"/>'; |
|
728 | + . '<input type="hidden" name="'.$name.'"' |
|
729 | + . ' value="'.esc_attr($value).'"/>'; |
|
730 | 730 | } |
731 | 731 | |
732 | 732 |
@@ -11,874 +11,874 @@ |
||
11 | 11 | */ |
12 | 12 | class EE_Payment extends EE_Base_Class implements EEI_Payment |
13 | 13 | { |
14 | - /** |
|
15 | - * @param array $props_n_values incoming values |
|
16 | - * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
17 | - * used.) |
|
18 | - * @param array $date_formats incoming date_formats in an array where the first value is the |
|
19 | - * date_format and the second value is the time format |
|
20 | - * @return EE_Payment |
|
21 | - * @throws \EE_Error |
|
22 | - */ |
|
23 | - public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
24 | - { |
|
25 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
26 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
27 | - } |
|
28 | - |
|
29 | - |
|
30 | - /** |
|
31 | - * @param array $props_n_values incoming values from the database |
|
32 | - * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
33 | - * the website will be used. |
|
34 | - * @return EE_Payment |
|
35 | - * @throws \EE_Error |
|
36 | - */ |
|
37 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
38 | - { |
|
39 | - return new self($props_n_values, true, $timezone); |
|
40 | - } |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * Set Transaction ID |
|
45 | - * |
|
46 | - * @access public |
|
47 | - * @param int $TXN_ID |
|
48 | - * @throws \EE_Error |
|
49 | - */ |
|
50 | - public function set_transaction_id($TXN_ID = 0) |
|
51 | - { |
|
52 | - $this->set('TXN_ID', $TXN_ID); |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * Gets the transaction related to this payment |
|
58 | - * |
|
59 | - * @return EE_Transaction |
|
60 | - * @throws \EE_Error |
|
61 | - */ |
|
62 | - public function transaction() |
|
63 | - { |
|
64 | - return $this->get_first_related('Transaction'); |
|
65 | - } |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * Set Status |
|
70 | - * |
|
71 | - * @access public |
|
72 | - * @param string $STS_ID |
|
73 | - * @throws \EE_Error |
|
74 | - */ |
|
75 | - public function set_status($STS_ID = '') |
|
76 | - { |
|
77 | - $this->set('STS_ID', $STS_ID); |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - /** |
|
82 | - * Set Payment Timestamp |
|
83 | - * |
|
84 | - * @access public |
|
85 | - * @param int $timestamp |
|
86 | - * @throws \EE_Error |
|
87 | - */ |
|
88 | - public function set_timestamp($timestamp = 0) |
|
89 | - { |
|
90 | - $this->set('PAY_timestamp', $timestamp); |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * Set Payment Method |
|
96 | - * |
|
97 | - * @access public |
|
98 | - * @param string $PAY_source |
|
99 | - * @throws \EE_Error |
|
100 | - */ |
|
101 | - public function set_source($PAY_source = '') |
|
102 | - { |
|
103 | - $this->set('PAY_source', $PAY_source); |
|
104 | - } |
|
105 | - |
|
106 | - |
|
107 | - /** |
|
108 | - * Set Payment Amount |
|
109 | - * |
|
110 | - * @access public |
|
111 | - * @param float $amount |
|
112 | - * @throws \EE_Error |
|
113 | - */ |
|
114 | - public function set_amount($amount = 0.00) |
|
115 | - { |
|
116 | - $this->set('PAY_amount', (float) $amount); |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - /** |
|
121 | - * Set Payment Gateway Response |
|
122 | - * |
|
123 | - * @access public |
|
124 | - * @param string $gateway_response |
|
125 | - * @throws \EE_Error |
|
126 | - */ |
|
127 | - public function set_gateway_response($gateway_response = '') |
|
128 | - { |
|
129 | - $this->set('PAY_gateway_response', $gateway_response); |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * Returns the name of the payment method used on this payment (previously known merely as 'gateway') |
|
135 | - * but since 4.6.0, payment methods are models and the payment keeps a foreign key to the payment method |
|
136 | - * used on it |
|
137 | - * |
|
138 | - * @deprecated |
|
139 | - * @return string |
|
140 | - * @throws \EE_Error |
|
141 | - */ |
|
142 | - public function gateway() |
|
143 | - { |
|
144 | - EE_Error::doing_it_wrong( |
|
145 | - 'EE_Payment::gateway', |
|
146 | - esc_html__( |
|
147 | - 'The method EE_Payment::gateway() has been deprecated. Consider instead using EE_Payment::payment_method()->name()', |
|
148 | - 'event_espresso' |
|
149 | - ), |
|
150 | - '4.6.0' |
|
151 | - ); |
|
152 | - return $this->payment_method() ? $this->payment_method()->name() : esc_html__('Unknown', 'event_espresso'); |
|
153 | - } |
|
154 | - |
|
155 | - |
|
156 | - /** |
|
157 | - * Set Gateway Transaction ID |
|
158 | - * |
|
159 | - * @access public |
|
160 | - * @param string $txn_id_chq_nmbr |
|
161 | - * @throws \EE_Error |
|
162 | - */ |
|
163 | - public function set_txn_id_chq_nmbr($txn_id_chq_nmbr = '') |
|
164 | - { |
|
165 | - $this->set('PAY_txn_id_chq_nmbr', $txn_id_chq_nmbr); |
|
166 | - } |
|
167 | - |
|
168 | - |
|
169 | - /** |
|
170 | - * Set Purchase Order Number |
|
171 | - * |
|
172 | - * @access public |
|
173 | - * @param string $po_number |
|
174 | - * @throws \EE_Error |
|
175 | - */ |
|
176 | - public function set_po_number($po_number = '') |
|
177 | - { |
|
178 | - $this->set('PAY_po_number', $po_number); |
|
179 | - } |
|
180 | - |
|
181 | - |
|
182 | - /** |
|
183 | - * Set Extra Accounting Field |
|
184 | - * |
|
185 | - * @access public |
|
186 | - * @param string $extra_accntng |
|
187 | - * @throws \EE_Error |
|
188 | - */ |
|
189 | - public function set_extra_accntng($extra_accntng = '') |
|
190 | - { |
|
191 | - $this->set('PAY_extra_accntng', $extra_accntng); |
|
192 | - } |
|
193 | - |
|
194 | - |
|
195 | - /** |
|
196 | - * Set Payment made via admin flag |
|
197 | - * |
|
198 | - * @access public |
|
199 | - * @param bool $via_admin |
|
200 | - * @throws \EE_Error |
|
201 | - */ |
|
202 | - public function set_payment_made_via_admin($via_admin = false) |
|
203 | - { |
|
204 | - if ($via_admin) { |
|
205 | - $this->set('PAY_source', EEM_Payment_Method::scope_admin); |
|
206 | - } else { |
|
207 | - $this->set('PAY_source', EEM_Payment_Method::scope_cart); |
|
208 | - } |
|
209 | - } |
|
210 | - |
|
211 | - |
|
212 | - /** |
|
213 | - * Set Payment Details |
|
214 | - * |
|
215 | - * @access public |
|
216 | - * @param string|array $details |
|
217 | - * @throws \EE_Error |
|
218 | - */ |
|
219 | - public function set_details($details = '') |
|
220 | - { |
|
221 | - if (is_array($details)) { |
|
222 | - array_walk_recursive($details, array($this, '_strip_all_tags_within_array')); |
|
223 | - } else { |
|
224 | - $details = wp_strip_all_tags($details); |
|
225 | - } |
|
226 | - $this->set('PAY_details', $details); |
|
227 | - } |
|
228 | - |
|
229 | - |
|
230 | - /** |
|
231 | - * Sets redirect_url |
|
232 | - * |
|
233 | - * @param string $redirect_url |
|
234 | - * @throws \EE_Error |
|
235 | - */ |
|
236 | - public function set_redirect_url($redirect_url) |
|
237 | - { |
|
238 | - $this->set('PAY_redirect_url', $redirect_url); |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - /** |
|
243 | - * Sets redirect_args |
|
244 | - * |
|
245 | - * @param array $redirect_args |
|
246 | - * @throws \EE_Error |
|
247 | - */ |
|
248 | - public function set_redirect_args($redirect_args) |
|
249 | - { |
|
250 | - $this->set('PAY_redirect_args', $redirect_args); |
|
251 | - } |
|
252 | - |
|
253 | - |
|
254 | - /** |
|
255 | - * get Payment Transaction ID |
|
256 | - * |
|
257 | - * @access public |
|
258 | - * @throws \EE_Error |
|
259 | - */ |
|
260 | - public function TXN_ID() |
|
261 | - { |
|
262 | - return $this->get('TXN_ID'); |
|
263 | - } |
|
264 | - |
|
265 | - |
|
266 | - /** |
|
267 | - * get Payment Status |
|
268 | - * |
|
269 | - * @access public |
|
270 | - * @throws \EE_Error |
|
271 | - */ |
|
272 | - public function status() |
|
273 | - { |
|
274 | - return $this->get('STS_ID'); |
|
275 | - } |
|
276 | - |
|
277 | - |
|
278 | - /** |
|
279 | - * get Payment Status |
|
280 | - * |
|
281 | - * @access public |
|
282 | - * @throws \EE_Error |
|
283 | - */ |
|
284 | - public function STS_ID() |
|
285 | - { |
|
286 | - return $this->get('STS_ID'); |
|
287 | - } |
|
288 | - |
|
289 | - |
|
290 | - /** |
|
291 | - * get Payment Timestamp |
|
292 | - * |
|
293 | - * @access public |
|
294 | - * @param string $dt_frmt |
|
295 | - * @param string $tm_frmt |
|
296 | - * @return string |
|
297 | - * @throws \EE_Error |
|
298 | - */ |
|
299 | - public function timestamp($dt_frmt = '', $tm_frmt = '') |
|
300 | - { |
|
301 | - return $this->get_i18n_datetime('PAY_timestamp', trim($dt_frmt . ' ' . $tm_frmt)); |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - /** |
|
306 | - * get Payment Source |
|
307 | - * |
|
308 | - * @access public |
|
309 | - * @throws \EE_Error |
|
310 | - */ |
|
311 | - public function source() |
|
312 | - { |
|
313 | - return $this->get('PAY_source'); |
|
314 | - } |
|
315 | - |
|
316 | - |
|
317 | - /** |
|
318 | - * get Payment Amount |
|
319 | - * |
|
320 | - * @access public |
|
321 | - * @return float |
|
322 | - * @throws \EE_Error |
|
323 | - */ |
|
324 | - public function amount() |
|
325 | - { |
|
326 | - return (float) $this->get('PAY_amount'); |
|
327 | - } |
|
328 | - |
|
329 | - |
|
330 | - /** |
|
331 | - * @return mixed |
|
332 | - * @throws \EE_Error |
|
333 | - */ |
|
334 | - public function amount_no_code() |
|
335 | - { |
|
336 | - return $this->get_pretty('PAY_amount', 'no_currency_code'); |
|
337 | - } |
|
338 | - |
|
339 | - |
|
340 | - /** |
|
341 | - * get Payment Gateway Response |
|
342 | - * |
|
343 | - * @access public |
|
344 | - * @throws \EE_Error |
|
345 | - */ |
|
346 | - public function gateway_response() |
|
347 | - { |
|
348 | - return $this->get('PAY_gateway_response'); |
|
349 | - } |
|
350 | - |
|
351 | - |
|
352 | - /** |
|
353 | - * get Payment Gateway Transaction ID |
|
354 | - * |
|
355 | - * @access public |
|
356 | - * @throws \EE_Error |
|
357 | - */ |
|
358 | - public function txn_id_chq_nmbr() |
|
359 | - { |
|
360 | - return $this->get('PAY_txn_id_chq_nmbr'); |
|
361 | - } |
|
362 | - |
|
363 | - |
|
364 | - /** |
|
365 | - * get Purchase Order Number |
|
366 | - * |
|
367 | - * @access public |
|
368 | - * @throws \EE_Error |
|
369 | - */ |
|
370 | - public function po_number() |
|
371 | - { |
|
372 | - return $this->get('PAY_po_number'); |
|
373 | - } |
|
374 | - |
|
375 | - |
|
376 | - /** |
|
377 | - * get Extra Accounting Field |
|
378 | - * |
|
379 | - * @access public |
|
380 | - * @throws \EE_Error |
|
381 | - */ |
|
382 | - public function extra_accntng() |
|
383 | - { |
|
384 | - return $this->get('PAY_extra_accntng'); |
|
385 | - } |
|
386 | - |
|
387 | - |
|
388 | - /** |
|
389 | - * get Payment made via admin source |
|
390 | - * |
|
391 | - * @access public |
|
392 | - * @throws \EE_Error |
|
393 | - */ |
|
394 | - public function payment_made_via_admin() |
|
395 | - { |
|
396 | - return ($this->get('PAY_source') === EEM_Payment_Method::scope_admin); |
|
397 | - } |
|
398 | - |
|
399 | - |
|
400 | - /** |
|
401 | - * get Payment Details |
|
402 | - * |
|
403 | - * @access public |
|
404 | - * @throws \EE_Error |
|
405 | - */ |
|
406 | - public function details() |
|
407 | - { |
|
408 | - return $this->get('PAY_details'); |
|
409 | - } |
|
410 | - |
|
411 | - |
|
412 | - /** |
|
413 | - * Gets redirect_url |
|
414 | - * |
|
415 | - * @return string |
|
416 | - * @throws \EE_Error |
|
417 | - */ |
|
418 | - public function redirect_url() |
|
419 | - { |
|
420 | - return $this->get('PAY_redirect_url'); |
|
421 | - } |
|
422 | - |
|
423 | - |
|
424 | - /** |
|
425 | - * Gets redirect_args |
|
426 | - * |
|
427 | - * @return array |
|
428 | - * @throws \EE_Error |
|
429 | - */ |
|
430 | - public function redirect_args() |
|
431 | - { |
|
432 | - return $this->get('PAY_redirect_args'); |
|
433 | - } |
|
434 | - |
|
435 | - |
|
436 | - /** |
|
437 | - * echoes $this->pretty_status() |
|
438 | - * |
|
439 | - * @param bool $show_icons |
|
440 | - * @return void |
|
441 | - * @throws \EE_Error |
|
442 | - */ |
|
443 | - public function e_pretty_status($show_icons = false) |
|
444 | - { |
|
445 | - echo wp_kses($this->pretty_status($show_icons), AllowedTags::getAllowedTags()); |
|
446 | - } |
|
447 | - |
|
448 | - |
|
449 | - /** |
|
450 | - * returns a pretty version of the status, good for displaying to users |
|
451 | - * |
|
452 | - * @param bool $show_icons |
|
453 | - * @return string |
|
454 | - * @throws \EE_Error |
|
455 | - */ |
|
456 | - public function pretty_status($show_icons = false) |
|
457 | - { |
|
458 | - $status = EEM_Status::instance()->localized_status( |
|
459 | - array($this->STS_ID() => esc_html__('unknown', 'event_espresso')), |
|
460 | - false, |
|
461 | - 'sentence' |
|
462 | - ); |
|
463 | - $icon = ''; |
|
464 | - switch ($this->STS_ID()) { |
|
465 | - case EEM_Payment::status_id_approved: |
|
466 | - $icon = $show_icons |
|
467 | - ? '<span class="dashicons dashicons-yes ee-icon-size-24 green-text"></span>' |
|
468 | - : ''; |
|
469 | - break; |
|
470 | - case EEM_Payment::status_id_pending: |
|
471 | - $icon = $show_icons |
|
472 | - ? '<span class="dashicons dashicons-clock ee-icon-size-16 orange-text"></span>' |
|
473 | - : ''; |
|
474 | - break; |
|
475 | - case EEM_Payment::status_id_cancelled: |
|
476 | - $icon = $show_icons |
|
477 | - ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>' |
|
478 | - : ''; |
|
479 | - break; |
|
480 | - case EEM_Payment::status_id_declined: |
|
481 | - $icon = $show_icons |
|
482 | - ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' |
|
483 | - : ''; |
|
484 | - break; |
|
485 | - } |
|
486 | - return $icon . $status[ $this->STS_ID() ]; |
|
487 | - } |
|
488 | - |
|
489 | - |
|
490 | - /** |
|
491 | - * For determining the status of the payment |
|
492 | - * |
|
493 | - * @return boolean whether the payment is approved or not |
|
494 | - * @throws \EE_Error |
|
495 | - */ |
|
496 | - public function is_approved() |
|
497 | - { |
|
498 | - return $this->status_is(EEM_Payment::status_id_approved); |
|
499 | - } |
|
500 | - |
|
501 | - |
|
502 | - /** |
|
503 | - * Generally determines if the status of this payment equals |
|
504 | - * the $STS_ID string |
|
505 | - * |
|
506 | - * @param string $STS_ID an ID from the esp_status table/ |
|
507 | - * one of the status_id_* on the EEM_Payment model |
|
508 | - * @return boolean whether the status of this payment equals the status id |
|
509 | - * @throws \EE_Error |
|
510 | - */ |
|
511 | - protected function status_is($STS_ID) |
|
512 | - { |
|
513 | - return $STS_ID === $this->STS_ID() ? true : false; |
|
514 | - } |
|
515 | - |
|
516 | - |
|
517 | - /** |
|
518 | - * For determining the status of the payment |
|
519 | - * |
|
520 | - * @return boolean whether the payment is pending or not |
|
521 | - * @throws \EE_Error |
|
522 | - */ |
|
523 | - public function is_pending() |
|
524 | - { |
|
525 | - return $this->status_is(EEM_Payment::status_id_pending); |
|
526 | - } |
|
527 | - |
|
528 | - |
|
529 | - /** |
|
530 | - * For determining the status of the payment |
|
531 | - * |
|
532 | - * @return boolean |
|
533 | - * @throws \EE_Error |
|
534 | - */ |
|
535 | - public function is_cancelled() |
|
536 | - { |
|
537 | - return $this->status_is(EEM_Payment::status_id_cancelled); |
|
538 | - } |
|
539 | - |
|
540 | - |
|
541 | - /** |
|
542 | - * For determining the status of the payment |
|
543 | - * |
|
544 | - * @return boolean |
|
545 | - * @throws \EE_Error |
|
546 | - */ |
|
547 | - public function is_declined() |
|
548 | - { |
|
549 | - return $this->status_is(EEM_Payment::status_id_declined); |
|
550 | - } |
|
551 | - |
|
552 | - |
|
553 | - /** |
|
554 | - * For determining the status of the payment |
|
555 | - * |
|
556 | - * @return boolean |
|
557 | - * @throws \EE_Error |
|
558 | - */ |
|
559 | - public function is_failed() |
|
560 | - { |
|
561 | - return $this->status_is(EEM_Payment::status_id_failed); |
|
562 | - } |
|
563 | - |
|
564 | - |
|
565 | - /** |
|
566 | - * For determining if the payment is actually a refund ( ie: has a negative value ) |
|
567 | - * |
|
568 | - * @return boolean |
|
569 | - * @throws \EE_Error |
|
570 | - */ |
|
571 | - public function is_a_refund() |
|
572 | - { |
|
573 | - return $this->amount() < 0 ? true : false; |
|
574 | - } |
|
575 | - |
|
576 | - |
|
577 | - /** |
|
578 | - * Get the status object of this object |
|
579 | - * |
|
580 | - * @return EE_Status |
|
581 | - * @throws \EE_Error |
|
582 | - */ |
|
583 | - public function status_obj() |
|
584 | - { |
|
585 | - return $this->get_first_related('Status'); |
|
586 | - } |
|
587 | - |
|
588 | - |
|
589 | - /** |
|
590 | - * Gets all the extra meta info on this payment |
|
591 | - * |
|
592 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
593 | - * @return EE_Extra_Meta |
|
594 | - * @throws \EE_Error |
|
595 | - */ |
|
596 | - public function extra_meta($query_params = array()) |
|
597 | - { |
|
598 | - return $this->get_many_related('Extra_Meta', $query_params); |
|
599 | - } |
|
600 | - |
|
601 | - |
|
602 | - /** |
|
603 | - * Gets the last-used payment method on this transaction |
|
604 | - * (we COULD just use the last-made payment, but some payment methods, namely |
|
605 | - * offline ones, dont' create payments) |
|
606 | - * |
|
607 | - * @return EE_Payment_Method |
|
608 | - * @throws \EE_Error |
|
609 | - */ |
|
610 | - public function payment_method() |
|
611 | - { |
|
612 | - return $this->get_first_related('Payment_Method'); |
|
613 | - } |
|
614 | - |
|
615 | - |
|
616 | - /** |
|
617 | - * Gets the HTML for redirecting the user to an offsite gateway |
|
618 | - * You can pass it special content to put inside the form, or use |
|
619 | - * the default inner content (or possibly generate this all yourself using |
|
620 | - * redirect_url() and redirect_args() or redirect_args_as_inputs()). |
|
621 | - * Creates a POST request by default, but if no redirect args are specified, creates a GET request instead |
|
622 | - * (and any querystring variables in the redirect_url are converted into html inputs |
|
623 | - * so browsers submit them properly) |
|
624 | - * |
|
625 | - * @param string $inside_form_html |
|
626 | - * @return string html |
|
627 | - * @throws \EE_Error |
|
628 | - */ |
|
629 | - public function redirect_form($inside_form_html = null) |
|
630 | - { |
|
631 | - $redirect_url = $this->redirect_url(); |
|
632 | - if (! empty($redirect_url)) { |
|
633 | - // what ? no inner form content? |
|
634 | - if ($inside_form_html === null) { |
|
635 | - $inside_form_html = EEH_HTML::p( |
|
636 | - sprintf( |
|
637 | - esc_html__( |
|
638 | - 'If you are not automatically redirected to the payment website within 10 seconds... %1$s %2$s Click Here %3$s', |
|
639 | - 'event_espresso' |
|
640 | - ), |
|
641 | - EEH_HTML::br(2), |
|
642 | - '<input type="submit" value="', |
|
643 | - '">' |
|
644 | - ), |
|
645 | - '', |
|
646 | - '', |
|
647 | - 'text-align:center;' |
|
648 | - ); |
|
649 | - } |
|
650 | - $method = apply_filters( |
|
651 | - 'FHEE__EE_Payment__redirect_form__method', |
|
652 | - $this->redirect_args() ? 'POST' : 'GET', |
|
653 | - $this |
|
654 | - ); |
|
655 | - // if it's a GET request, we need to remove all the GET params in the querystring |
|
656 | - // and put them into the form instead |
|
657 | - if ($method === 'GET') { |
|
658 | - $querystring = parse_url($redirect_url, PHP_URL_QUERY); |
|
659 | - $get_params = null; |
|
660 | - parse_str($querystring, $get_params); |
|
661 | - $inside_form_html .= $this->_args_as_inputs($get_params); |
|
662 | - $redirect_url = str_replace('?' . $querystring, '', $redirect_url); |
|
663 | - } |
|
664 | - $form = EEH_HTML::nl(1) |
|
665 | - . '<form method="' |
|
666 | - . $method |
|
667 | - . '" name="gateway_form" action="' |
|
668 | - . $redirect_url |
|
669 | - . '">'; |
|
670 | - $form .= EEH_HTML::nl(1) . $this->redirect_args_as_inputs(); |
|
671 | - $form .= $inside_form_html; |
|
672 | - $form .= EEH_HTML::nl(-1) . '</form>' . EEH_HTML::nl(-1); |
|
673 | - return $form; |
|
674 | - } else { |
|
675 | - return null; |
|
676 | - } |
|
677 | - } |
|
678 | - |
|
679 | - |
|
680 | - /** |
|
681 | - * Changes all the name-value pairs of the redirect args into html inputs |
|
682 | - * and returns the html as a string |
|
683 | - * |
|
684 | - * @return string |
|
685 | - * @throws \EE_Error |
|
686 | - */ |
|
687 | - public function redirect_args_as_inputs() |
|
688 | - { |
|
689 | - return $this->_args_as_inputs($this->redirect_args()); |
|
690 | - } |
|
691 | - |
|
692 | - |
|
693 | - /** |
|
694 | - * Converts a 2d array of key-value pairs into html hidden inputs |
|
695 | - * and returns the string of html |
|
696 | - * |
|
697 | - * @param array $args key-value pairs |
|
698 | - * @return string |
|
699 | - */ |
|
700 | - protected function _args_as_inputs($args) |
|
701 | - { |
|
702 | - $html = ''; |
|
703 | - if ($args !== null && is_array($args)) { |
|
704 | - foreach ($args as $name => $value) { |
|
705 | - $html .= $this->generateInput($name, $value); |
|
706 | - } |
|
707 | - } |
|
708 | - return $html; |
|
709 | - } |
|
710 | - |
|
711 | - /** |
|
712 | - * Converts either a single name and value or array of values into html hidden inputs |
|
713 | - * and returns the string of html |
|
714 | - * |
|
715 | - * @param string $name |
|
716 | - * @param string|array $value |
|
717 | - * @return string |
|
718 | - */ |
|
719 | - private function generateInput($name, $value) |
|
720 | - { |
|
721 | - if (is_array($value)) { |
|
722 | - $html = ''; |
|
723 | - $name = "{$name}[]"; |
|
724 | - foreach ($value as $array_value) { |
|
725 | - $html .= $this->generateInput($name, $array_value); |
|
726 | - } |
|
727 | - return $html; |
|
728 | - } |
|
729 | - return EEH_HTML::nl() |
|
730 | - . '<input type="hidden" name="' . $name . '"' |
|
731 | - . ' value="' . esc_attr($value) . '"/>'; |
|
732 | - } |
|
733 | - |
|
734 | - |
|
735 | - /** |
|
736 | - * Returns the currency of the payment. |
|
737 | - * (At the time of writing, this will always be the currency in the configuration; |
|
738 | - * however in the future it is anticipated that this will be stored on the payment |
|
739 | - * object itself) |
|
740 | - * |
|
741 | - * @return string for the currency code |
|
742 | - */ |
|
743 | - public function currency_code() |
|
744 | - { |
|
745 | - return EE_Config::instance()->currency->code; |
|
746 | - } |
|
747 | - |
|
748 | - |
|
749 | - /** |
|
750 | - * apply wp_strip_all_tags to all elements within an array |
|
751 | - * |
|
752 | - * @access private |
|
753 | - * @param mixed $item |
|
754 | - */ |
|
755 | - private function _strip_all_tags_within_array(&$item) |
|
756 | - { |
|
757 | - if (is_object($item)) { |
|
758 | - $item = (array) $item; |
|
759 | - } |
|
760 | - if (is_array($item)) { |
|
761 | - array_walk_recursive($item, array($this, '_strip_all_tags_within_array')); |
|
762 | - } else { |
|
763 | - $item = wp_strip_all_tags($item); |
|
764 | - } |
|
765 | - } |
|
766 | - |
|
767 | - |
|
768 | - /** |
|
769 | - * Returns TRUE is this payment was set to approved during this request (or |
|
770 | - * is approved and was created during this request). False otherwise. |
|
771 | - * |
|
772 | - * @return boolean |
|
773 | - * @throws \EE_Error |
|
774 | - */ |
|
775 | - public function just_approved() |
|
776 | - { |
|
777 | - $original_status = EEH_Array::is_set( |
|
778 | - $this->_props_n_values_provided_in_constructor, |
|
779 | - 'STS_ID', |
|
780 | - $this->get_model()->field_settings_for('STS_ID')->get_default_value() |
|
781 | - ); |
|
782 | - $current_status = $this->status(); |
|
783 | - if ( |
|
784 | - $original_status !== EEM_Payment::status_id_approved |
|
785 | - && $current_status === EEM_Payment::status_id_approved |
|
786 | - ) { |
|
787 | - return true; |
|
788 | - } else { |
|
789 | - return false; |
|
790 | - } |
|
791 | - } |
|
792 | - |
|
793 | - |
|
794 | - /** |
|
795 | - * Overrides parents' get_pretty() function just for legacy reasons |
|
796 | - * (to allow ticket https://events.codebasehq.com/projects/event-espresso/tickets/7420) |
|
797 | - * |
|
798 | - * @param string $field_name |
|
799 | - * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
800 | - * (in cases where the same property may be used for different outputs |
|
801 | - * - i.e. datetime, money etc.) |
|
802 | - * @return mixed |
|
803 | - * @throws \EE_Error |
|
804 | - */ |
|
805 | - public function get_pretty($field_name, $extra_cache_ref = null) |
|
806 | - { |
|
807 | - if ($field_name === 'PAY_gateway') { |
|
808 | - return $this->payment_method() ? $this->payment_method()->name() : esc_html__('Unknown', 'event_espresso'); |
|
809 | - } |
|
810 | - return $this->_get_cached_property($field_name, true, $extra_cache_ref); |
|
811 | - } |
|
812 | - |
|
813 | - |
|
814 | - /** |
|
815 | - * Gets details regarding which registrations this payment was applied to |
|
816 | - * |
|
817 | - * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
818 | - * @return EE_Registration_Payment[] |
|
819 | - * @throws \EE_Error |
|
820 | - */ |
|
821 | - public function registration_payments($query_params = array()) |
|
822 | - { |
|
823 | - return $this->get_many_related('Registration_Payment', $query_params); |
|
824 | - } |
|
825 | - |
|
826 | - |
|
827 | - /** |
|
828 | - * Gets the first event for this payment (it's possible that it could be for multiple) |
|
829 | - * |
|
830 | - * @return EE_Event|null |
|
831 | - */ |
|
832 | - public function get_first_event() |
|
833 | - { |
|
834 | - $transaction = $this->transaction(); |
|
835 | - if ($transaction instanceof EE_Transaction) { |
|
836 | - $primary_registrant = $transaction->primary_registration(); |
|
837 | - if ($primary_registrant instanceof EE_Registration) { |
|
838 | - return $primary_registrant->event_obj(); |
|
839 | - } |
|
840 | - } |
|
841 | - return null; |
|
842 | - } |
|
843 | - |
|
844 | - |
|
845 | - /** |
|
846 | - * Gets the name of the first event for which is being paid |
|
847 | - * |
|
848 | - * @return string |
|
849 | - */ |
|
850 | - public function get_first_event_name() |
|
851 | - { |
|
852 | - $event = $this->get_first_event(); |
|
853 | - return $event instanceof EE_Event ? $event->name() : esc_html__('Event', 'event_espresso'); |
|
854 | - } |
|
855 | - |
|
856 | - |
|
857 | - /** |
|
858 | - * Returns the payment's transaction's primary registration |
|
859 | - * |
|
860 | - * @return EE_Registration|null |
|
861 | - */ |
|
862 | - public function get_primary_registration() |
|
863 | - { |
|
864 | - if ($this->transaction() instanceof EE_Transaction) { |
|
865 | - return $this->transaction()->primary_registration(); |
|
866 | - } |
|
867 | - return null; |
|
868 | - } |
|
869 | - |
|
870 | - |
|
871 | - /** |
|
872 | - * Gets the payment's transaction's primary registration's attendee, or null |
|
873 | - * |
|
874 | - * @return EE_Attendee|null |
|
875 | - */ |
|
876 | - public function get_primary_attendee() |
|
877 | - { |
|
878 | - $primary_reg = $this->get_primary_registration(); |
|
879 | - if ($primary_reg instanceof EE_Registration) { |
|
880 | - return $primary_reg->attendee(); |
|
881 | - } |
|
882 | - return null; |
|
883 | - } |
|
14 | + /** |
|
15 | + * @param array $props_n_values incoming values |
|
16 | + * @param string $timezone incoming timezone (if not set the timezone set for the website will be |
|
17 | + * used.) |
|
18 | + * @param array $date_formats incoming date_formats in an array where the first value is the |
|
19 | + * date_format and the second value is the time format |
|
20 | + * @return EE_Payment |
|
21 | + * @throws \EE_Error |
|
22 | + */ |
|
23 | + public static function new_instance($props_n_values = array(), $timezone = null, $date_formats = array()) |
|
24 | + { |
|
25 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
26 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
27 | + } |
|
28 | + |
|
29 | + |
|
30 | + /** |
|
31 | + * @param array $props_n_values incoming values from the database |
|
32 | + * @param string $timezone incoming timezone as set by the model. If not set the timezone for |
|
33 | + * the website will be used. |
|
34 | + * @return EE_Payment |
|
35 | + * @throws \EE_Error |
|
36 | + */ |
|
37 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
38 | + { |
|
39 | + return new self($props_n_values, true, $timezone); |
|
40 | + } |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * Set Transaction ID |
|
45 | + * |
|
46 | + * @access public |
|
47 | + * @param int $TXN_ID |
|
48 | + * @throws \EE_Error |
|
49 | + */ |
|
50 | + public function set_transaction_id($TXN_ID = 0) |
|
51 | + { |
|
52 | + $this->set('TXN_ID', $TXN_ID); |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * Gets the transaction related to this payment |
|
58 | + * |
|
59 | + * @return EE_Transaction |
|
60 | + * @throws \EE_Error |
|
61 | + */ |
|
62 | + public function transaction() |
|
63 | + { |
|
64 | + return $this->get_first_related('Transaction'); |
|
65 | + } |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * Set Status |
|
70 | + * |
|
71 | + * @access public |
|
72 | + * @param string $STS_ID |
|
73 | + * @throws \EE_Error |
|
74 | + */ |
|
75 | + public function set_status($STS_ID = '') |
|
76 | + { |
|
77 | + $this->set('STS_ID', $STS_ID); |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + /** |
|
82 | + * Set Payment Timestamp |
|
83 | + * |
|
84 | + * @access public |
|
85 | + * @param int $timestamp |
|
86 | + * @throws \EE_Error |
|
87 | + */ |
|
88 | + public function set_timestamp($timestamp = 0) |
|
89 | + { |
|
90 | + $this->set('PAY_timestamp', $timestamp); |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * Set Payment Method |
|
96 | + * |
|
97 | + * @access public |
|
98 | + * @param string $PAY_source |
|
99 | + * @throws \EE_Error |
|
100 | + */ |
|
101 | + public function set_source($PAY_source = '') |
|
102 | + { |
|
103 | + $this->set('PAY_source', $PAY_source); |
|
104 | + } |
|
105 | + |
|
106 | + |
|
107 | + /** |
|
108 | + * Set Payment Amount |
|
109 | + * |
|
110 | + * @access public |
|
111 | + * @param float $amount |
|
112 | + * @throws \EE_Error |
|
113 | + */ |
|
114 | + public function set_amount($amount = 0.00) |
|
115 | + { |
|
116 | + $this->set('PAY_amount', (float) $amount); |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + /** |
|
121 | + * Set Payment Gateway Response |
|
122 | + * |
|
123 | + * @access public |
|
124 | + * @param string $gateway_response |
|
125 | + * @throws \EE_Error |
|
126 | + */ |
|
127 | + public function set_gateway_response($gateway_response = '') |
|
128 | + { |
|
129 | + $this->set('PAY_gateway_response', $gateway_response); |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * Returns the name of the payment method used on this payment (previously known merely as 'gateway') |
|
135 | + * but since 4.6.0, payment methods are models and the payment keeps a foreign key to the payment method |
|
136 | + * used on it |
|
137 | + * |
|
138 | + * @deprecated |
|
139 | + * @return string |
|
140 | + * @throws \EE_Error |
|
141 | + */ |
|
142 | + public function gateway() |
|
143 | + { |
|
144 | + EE_Error::doing_it_wrong( |
|
145 | + 'EE_Payment::gateway', |
|
146 | + esc_html__( |
|
147 | + 'The method EE_Payment::gateway() has been deprecated. Consider instead using EE_Payment::payment_method()->name()', |
|
148 | + 'event_espresso' |
|
149 | + ), |
|
150 | + '4.6.0' |
|
151 | + ); |
|
152 | + return $this->payment_method() ? $this->payment_method()->name() : esc_html__('Unknown', 'event_espresso'); |
|
153 | + } |
|
154 | + |
|
155 | + |
|
156 | + /** |
|
157 | + * Set Gateway Transaction ID |
|
158 | + * |
|
159 | + * @access public |
|
160 | + * @param string $txn_id_chq_nmbr |
|
161 | + * @throws \EE_Error |
|
162 | + */ |
|
163 | + public function set_txn_id_chq_nmbr($txn_id_chq_nmbr = '') |
|
164 | + { |
|
165 | + $this->set('PAY_txn_id_chq_nmbr', $txn_id_chq_nmbr); |
|
166 | + } |
|
167 | + |
|
168 | + |
|
169 | + /** |
|
170 | + * Set Purchase Order Number |
|
171 | + * |
|
172 | + * @access public |
|
173 | + * @param string $po_number |
|
174 | + * @throws \EE_Error |
|
175 | + */ |
|
176 | + public function set_po_number($po_number = '') |
|
177 | + { |
|
178 | + $this->set('PAY_po_number', $po_number); |
|
179 | + } |
|
180 | + |
|
181 | + |
|
182 | + /** |
|
183 | + * Set Extra Accounting Field |
|
184 | + * |
|
185 | + * @access public |
|
186 | + * @param string $extra_accntng |
|
187 | + * @throws \EE_Error |
|
188 | + */ |
|
189 | + public function set_extra_accntng($extra_accntng = '') |
|
190 | + { |
|
191 | + $this->set('PAY_extra_accntng', $extra_accntng); |
|
192 | + } |
|
193 | + |
|
194 | + |
|
195 | + /** |
|
196 | + * Set Payment made via admin flag |
|
197 | + * |
|
198 | + * @access public |
|
199 | + * @param bool $via_admin |
|
200 | + * @throws \EE_Error |
|
201 | + */ |
|
202 | + public function set_payment_made_via_admin($via_admin = false) |
|
203 | + { |
|
204 | + if ($via_admin) { |
|
205 | + $this->set('PAY_source', EEM_Payment_Method::scope_admin); |
|
206 | + } else { |
|
207 | + $this->set('PAY_source', EEM_Payment_Method::scope_cart); |
|
208 | + } |
|
209 | + } |
|
210 | + |
|
211 | + |
|
212 | + /** |
|
213 | + * Set Payment Details |
|
214 | + * |
|
215 | + * @access public |
|
216 | + * @param string|array $details |
|
217 | + * @throws \EE_Error |
|
218 | + */ |
|
219 | + public function set_details($details = '') |
|
220 | + { |
|
221 | + if (is_array($details)) { |
|
222 | + array_walk_recursive($details, array($this, '_strip_all_tags_within_array')); |
|
223 | + } else { |
|
224 | + $details = wp_strip_all_tags($details); |
|
225 | + } |
|
226 | + $this->set('PAY_details', $details); |
|
227 | + } |
|
228 | + |
|
229 | + |
|
230 | + /** |
|
231 | + * Sets redirect_url |
|
232 | + * |
|
233 | + * @param string $redirect_url |
|
234 | + * @throws \EE_Error |
|
235 | + */ |
|
236 | + public function set_redirect_url($redirect_url) |
|
237 | + { |
|
238 | + $this->set('PAY_redirect_url', $redirect_url); |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + /** |
|
243 | + * Sets redirect_args |
|
244 | + * |
|
245 | + * @param array $redirect_args |
|
246 | + * @throws \EE_Error |
|
247 | + */ |
|
248 | + public function set_redirect_args($redirect_args) |
|
249 | + { |
|
250 | + $this->set('PAY_redirect_args', $redirect_args); |
|
251 | + } |
|
252 | + |
|
253 | + |
|
254 | + /** |
|
255 | + * get Payment Transaction ID |
|
256 | + * |
|
257 | + * @access public |
|
258 | + * @throws \EE_Error |
|
259 | + */ |
|
260 | + public function TXN_ID() |
|
261 | + { |
|
262 | + return $this->get('TXN_ID'); |
|
263 | + } |
|
264 | + |
|
265 | + |
|
266 | + /** |
|
267 | + * get Payment Status |
|
268 | + * |
|
269 | + * @access public |
|
270 | + * @throws \EE_Error |
|
271 | + */ |
|
272 | + public function status() |
|
273 | + { |
|
274 | + return $this->get('STS_ID'); |
|
275 | + } |
|
276 | + |
|
277 | + |
|
278 | + /** |
|
279 | + * get Payment Status |
|
280 | + * |
|
281 | + * @access public |
|
282 | + * @throws \EE_Error |
|
283 | + */ |
|
284 | + public function STS_ID() |
|
285 | + { |
|
286 | + return $this->get('STS_ID'); |
|
287 | + } |
|
288 | + |
|
289 | + |
|
290 | + /** |
|
291 | + * get Payment Timestamp |
|
292 | + * |
|
293 | + * @access public |
|
294 | + * @param string $dt_frmt |
|
295 | + * @param string $tm_frmt |
|
296 | + * @return string |
|
297 | + * @throws \EE_Error |
|
298 | + */ |
|
299 | + public function timestamp($dt_frmt = '', $tm_frmt = '') |
|
300 | + { |
|
301 | + return $this->get_i18n_datetime('PAY_timestamp', trim($dt_frmt . ' ' . $tm_frmt)); |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + /** |
|
306 | + * get Payment Source |
|
307 | + * |
|
308 | + * @access public |
|
309 | + * @throws \EE_Error |
|
310 | + */ |
|
311 | + public function source() |
|
312 | + { |
|
313 | + return $this->get('PAY_source'); |
|
314 | + } |
|
315 | + |
|
316 | + |
|
317 | + /** |
|
318 | + * get Payment Amount |
|
319 | + * |
|
320 | + * @access public |
|
321 | + * @return float |
|
322 | + * @throws \EE_Error |
|
323 | + */ |
|
324 | + public function amount() |
|
325 | + { |
|
326 | + return (float) $this->get('PAY_amount'); |
|
327 | + } |
|
328 | + |
|
329 | + |
|
330 | + /** |
|
331 | + * @return mixed |
|
332 | + * @throws \EE_Error |
|
333 | + */ |
|
334 | + public function amount_no_code() |
|
335 | + { |
|
336 | + return $this->get_pretty('PAY_amount', 'no_currency_code'); |
|
337 | + } |
|
338 | + |
|
339 | + |
|
340 | + /** |
|
341 | + * get Payment Gateway Response |
|
342 | + * |
|
343 | + * @access public |
|
344 | + * @throws \EE_Error |
|
345 | + */ |
|
346 | + public function gateway_response() |
|
347 | + { |
|
348 | + return $this->get('PAY_gateway_response'); |
|
349 | + } |
|
350 | + |
|
351 | + |
|
352 | + /** |
|
353 | + * get Payment Gateway Transaction ID |
|
354 | + * |
|
355 | + * @access public |
|
356 | + * @throws \EE_Error |
|
357 | + */ |
|
358 | + public function txn_id_chq_nmbr() |
|
359 | + { |
|
360 | + return $this->get('PAY_txn_id_chq_nmbr'); |
|
361 | + } |
|
362 | + |
|
363 | + |
|
364 | + /** |
|
365 | + * get Purchase Order Number |
|
366 | + * |
|
367 | + * @access public |
|
368 | + * @throws \EE_Error |
|
369 | + */ |
|
370 | + public function po_number() |
|
371 | + { |
|
372 | + return $this->get('PAY_po_number'); |
|
373 | + } |
|
374 | + |
|
375 | + |
|
376 | + /** |
|
377 | + * get Extra Accounting Field |
|
378 | + * |
|
379 | + * @access public |
|
380 | + * @throws \EE_Error |
|
381 | + */ |
|
382 | + public function extra_accntng() |
|
383 | + { |
|
384 | + return $this->get('PAY_extra_accntng'); |
|
385 | + } |
|
386 | + |
|
387 | + |
|
388 | + /** |
|
389 | + * get Payment made via admin source |
|
390 | + * |
|
391 | + * @access public |
|
392 | + * @throws \EE_Error |
|
393 | + */ |
|
394 | + public function payment_made_via_admin() |
|
395 | + { |
|
396 | + return ($this->get('PAY_source') === EEM_Payment_Method::scope_admin); |
|
397 | + } |
|
398 | + |
|
399 | + |
|
400 | + /** |
|
401 | + * get Payment Details |
|
402 | + * |
|
403 | + * @access public |
|
404 | + * @throws \EE_Error |
|
405 | + */ |
|
406 | + public function details() |
|
407 | + { |
|
408 | + return $this->get('PAY_details'); |
|
409 | + } |
|
410 | + |
|
411 | + |
|
412 | + /** |
|
413 | + * Gets redirect_url |
|
414 | + * |
|
415 | + * @return string |
|
416 | + * @throws \EE_Error |
|
417 | + */ |
|
418 | + public function redirect_url() |
|
419 | + { |
|
420 | + return $this->get('PAY_redirect_url'); |
|
421 | + } |
|
422 | + |
|
423 | + |
|
424 | + /** |
|
425 | + * Gets redirect_args |
|
426 | + * |
|
427 | + * @return array |
|
428 | + * @throws \EE_Error |
|
429 | + */ |
|
430 | + public function redirect_args() |
|
431 | + { |
|
432 | + return $this->get('PAY_redirect_args'); |
|
433 | + } |
|
434 | + |
|
435 | + |
|
436 | + /** |
|
437 | + * echoes $this->pretty_status() |
|
438 | + * |
|
439 | + * @param bool $show_icons |
|
440 | + * @return void |
|
441 | + * @throws \EE_Error |
|
442 | + */ |
|
443 | + public function e_pretty_status($show_icons = false) |
|
444 | + { |
|
445 | + echo wp_kses($this->pretty_status($show_icons), AllowedTags::getAllowedTags()); |
|
446 | + } |
|
447 | + |
|
448 | + |
|
449 | + /** |
|
450 | + * returns a pretty version of the status, good for displaying to users |
|
451 | + * |
|
452 | + * @param bool $show_icons |
|
453 | + * @return string |
|
454 | + * @throws \EE_Error |
|
455 | + */ |
|
456 | + public function pretty_status($show_icons = false) |
|
457 | + { |
|
458 | + $status = EEM_Status::instance()->localized_status( |
|
459 | + array($this->STS_ID() => esc_html__('unknown', 'event_espresso')), |
|
460 | + false, |
|
461 | + 'sentence' |
|
462 | + ); |
|
463 | + $icon = ''; |
|
464 | + switch ($this->STS_ID()) { |
|
465 | + case EEM_Payment::status_id_approved: |
|
466 | + $icon = $show_icons |
|
467 | + ? '<span class="dashicons dashicons-yes ee-icon-size-24 green-text"></span>' |
|
468 | + : ''; |
|
469 | + break; |
|
470 | + case EEM_Payment::status_id_pending: |
|
471 | + $icon = $show_icons |
|
472 | + ? '<span class="dashicons dashicons-clock ee-icon-size-16 orange-text"></span>' |
|
473 | + : ''; |
|
474 | + break; |
|
475 | + case EEM_Payment::status_id_cancelled: |
|
476 | + $icon = $show_icons |
|
477 | + ? '<span class="dashicons dashicons-no ee-icon-size-16 lt-grey-text"></span>' |
|
478 | + : ''; |
|
479 | + break; |
|
480 | + case EEM_Payment::status_id_declined: |
|
481 | + $icon = $show_icons |
|
482 | + ? '<span class="dashicons dashicons-no ee-icon-size-16 red-text"></span>' |
|
483 | + : ''; |
|
484 | + break; |
|
485 | + } |
|
486 | + return $icon . $status[ $this->STS_ID() ]; |
|
487 | + } |
|
488 | + |
|
489 | + |
|
490 | + /** |
|
491 | + * For determining the status of the payment |
|
492 | + * |
|
493 | + * @return boolean whether the payment is approved or not |
|
494 | + * @throws \EE_Error |
|
495 | + */ |
|
496 | + public function is_approved() |
|
497 | + { |
|
498 | + return $this->status_is(EEM_Payment::status_id_approved); |
|
499 | + } |
|
500 | + |
|
501 | + |
|
502 | + /** |
|
503 | + * Generally determines if the status of this payment equals |
|
504 | + * the $STS_ID string |
|
505 | + * |
|
506 | + * @param string $STS_ID an ID from the esp_status table/ |
|
507 | + * one of the status_id_* on the EEM_Payment model |
|
508 | + * @return boolean whether the status of this payment equals the status id |
|
509 | + * @throws \EE_Error |
|
510 | + */ |
|
511 | + protected function status_is($STS_ID) |
|
512 | + { |
|
513 | + return $STS_ID === $this->STS_ID() ? true : false; |
|
514 | + } |
|
515 | + |
|
516 | + |
|
517 | + /** |
|
518 | + * For determining the status of the payment |
|
519 | + * |
|
520 | + * @return boolean whether the payment is pending or not |
|
521 | + * @throws \EE_Error |
|
522 | + */ |
|
523 | + public function is_pending() |
|
524 | + { |
|
525 | + return $this->status_is(EEM_Payment::status_id_pending); |
|
526 | + } |
|
527 | + |
|
528 | + |
|
529 | + /** |
|
530 | + * For determining the status of the payment |
|
531 | + * |
|
532 | + * @return boolean |
|
533 | + * @throws \EE_Error |
|
534 | + */ |
|
535 | + public function is_cancelled() |
|
536 | + { |
|
537 | + return $this->status_is(EEM_Payment::status_id_cancelled); |
|
538 | + } |
|
539 | + |
|
540 | + |
|
541 | + /** |
|
542 | + * For determining the status of the payment |
|
543 | + * |
|
544 | + * @return boolean |
|
545 | + * @throws \EE_Error |
|
546 | + */ |
|
547 | + public function is_declined() |
|
548 | + { |
|
549 | + return $this->status_is(EEM_Payment::status_id_declined); |
|
550 | + } |
|
551 | + |
|
552 | + |
|
553 | + /** |
|
554 | + * For determining the status of the payment |
|
555 | + * |
|
556 | + * @return boolean |
|
557 | + * @throws \EE_Error |
|
558 | + */ |
|
559 | + public function is_failed() |
|
560 | + { |
|
561 | + return $this->status_is(EEM_Payment::status_id_failed); |
|
562 | + } |
|
563 | + |
|
564 | + |
|
565 | + /** |
|
566 | + * For determining if the payment is actually a refund ( ie: has a negative value ) |
|
567 | + * |
|
568 | + * @return boolean |
|
569 | + * @throws \EE_Error |
|
570 | + */ |
|
571 | + public function is_a_refund() |
|
572 | + { |
|
573 | + return $this->amount() < 0 ? true : false; |
|
574 | + } |
|
575 | + |
|
576 | + |
|
577 | + /** |
|
578 | + * Get the status object of this object |
|
579 | + * |
|
580 | + * @return EE_Status |
|
581 | + * @throws \EE_Error |
|
582 | + */ |
|
583 | + public function status_obj() |
|
584 | + { |
|
585 | + return $this->get_first_related('Status'); |
|
586 | + } |
|
587 | + |
|
588 | + |
|
589 | + /** |
|
590 | + * Gets all the extra meta info on this payment |
|
591 | + * |
|
592 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
593 | + * @return EE_Extra_Meta |
|
594 | + * @throws \EE_Error |
|
595 | + */ |
|
596 | + public function extra_meta($query_params = array()) |
|
597 | + { |
|
598 | + return $this->get_many_related('Extra_Meta', $query_params); |
|
599 | + } |
|
600 | + |
|
601 | + |
|
602 | + /** |
|
603 | + * Gets the last-used payment method on this transaction |
|
604 | + * (we COULD just use the last-made payment, but some payment methods, namely |
|
605 | + * offline ones, dont' create payments) |
|
606 | + * |
|
607 | + * @return EE_Payment_Method |
|
608 | + * @throws \EE_Error |
|
609 | + */ |
|
610 | + public function payment_method() |
|
611 | + { |
|
612 | + return $this->get_first_related('Payment_Method'); |
|
613 | + } |
|
614 | + |
|
615 | + |
|
616 | + /** |
|
617 | + * Gets the HTML for redirecting the user to an offsite gateway |
|
618 | + * You can pass it special content to put inside the form, or use |
|
619 | + * the default inner content (or possibly generate this all yourself using |
|
620 | + * redirect_url() and redirect_args() or redirect_args_as_inputs()). |
|
621 | + * Creates a POST request by default, but if no redirect args are specified, creates a GET request instead |
|
622 | + * (and any querystring variables in the redirect_url are converted into html inputs |
|
623 | + * so browsers submit them properly) |
|
624 | + * |
|
625 | + * @param string $inside_form_html |
|
626 | + * @return string html |
|
627 | + * @throws \EE_Error |
|
628 | + */ |
|
629 | + public function redirect_form($inside_form_html = null) |
|
630 | + { |
|
631 | + $redirect_url = $this->redirect_url(); |
|
632 | + if (! empty($redirect_url)) { |
|
633 | + // what ? no inner form content? |
|
634 | + if ($inside_form_html === null) { |
|
635 | + $inside_form_html = EEH_HTML::p( |
|
636 | + sprintf( |
|
637 | + esc_html__( |
|
638 | + 'If you are not automatically redirected to the payment website within 10 seconds... %1$s %2$s Click Here %3$s', |
|
639 | + 'event_espresso' |
|
640 | + ), |
|
641 | + EEH_HTML::br(2), |
|
642 | + '<input type="submit" value="', |
|
643 | + '">' |
|
644 | + ), |
|
645 | + '', |
|
646 | + '', |
|
647 | + 'text-align:center;' |
|
648 | + ); |
|
649 | + } |
|
650 | + $method = apply_filters( |
|
651 | + 'FHEE__EE_Payment__redirect_form__method', |
|
652 | + $this->redirect_args() ? 'POST' : 'GET', |
|
653 | + $this |
|
654 | + ); |
|
655 | + // if it's a GET request, we need to remove all the GET params in the querystring |
|
656 | + // and put them into the form instead |
|
657 | + if ($method === 'GET') { |
|
658 | + $querystring = parse_url($redirect_url, PHP_URL_QUERY); |
|
659 | + $get_params = null; |
|
660 | + parse_str($querystring, $get_params); |
|
661 | + $inside_form_html .= $this->_args_as_inputs($get_params); |
|
662 | + $redirect_url = str_replace('?' . $querystring, '', $redirect_url); |
|
663 | + } |
|
664 | + $form = EEH_HTML::nl(1) |
|
665 | + . '<form method="' |
|
666 | + . $method |
|
667 | + . '" name="gateway_form" action="' |
|
668 | + . $redirect_url |
|
669 | + . '">'; |
|
670 | + $form .= EEH_HTML::nl(1) . $this->redirect_args_as_inputs(); |
|
671 | + $form .= $inside_form_html; |
|
672 | + $form .= EEH_HTML::nl(-1) . '</form>' . EEH_HTML::nl(-1); |
|
673 | + return $form; |
|
674 | + } else { |
|
675 | + return null; |
|
676 | + } |
|
677 | + } |
|
678 | + |
|
679 | + |
|
680 | + /** |
|
681 | + * Changes all the name-value pairs of the redirect args into html inputs |
|
682 | + * and returns the html as a string |
|
683 | + * |
|
684 | + * @return string |
|
685 | + * @throws \EE_Error |
|
686 | + */ |
|
687 | + public function redirect_args_as_inputs() |
|
688 | + { |
|
689 | + return $this->_args_as_inputs($this->redirect_args()); |
|
690 | + } |
|
691 | + |
|
692 | + |
|
693 | + /** |
|
694 | + * Converts a 2d array of key-value pairs into html hidden inputs |
|
695 | + * and returns the string of html |
|
696 | + * |
|
697 | + * @param array $args key-value pairs |
|
698 | + * @return string |
|
699 | + */ |
|
700 | + protected function _args_as_inputs($args) |
|
701 | + { |
|
702 | + $html = ''; |
|
703 | + if ($args !== null && is_array($args)) { |
|
704 | + foreach ($args as $name => $value) { |
|
705 | + $html .= $this->generateInput($name, $value); |
|
706 | + } |
|
707 | + } |
|
708 | + return $html; |
|
709 | + } |
|
710 | + |
|
711 | + /** |
|
712 | + * Converts either a single name and value or array of values into html hidden inputs |
|
713 | + * and returns the string of html |
|
714 | + * |
|
715 | + * @param string $name |
|
716 | + * @param string|array $value |
|
717 | + * @return string |
|
718 | + */ |
|
719 | + private function generateInput($name, $value) |
|
720 | + { |
|
721 | + if (is_array($value)) { |
|
722 | + $html = ''; |
|
723 | + $name = "{$name}[]"; |
|
724 | + foreach ($value as $array_value) { |
|
725 | + $html .= $this->generateInput($name, $array_value); |
|
726 | + } |
|
727 | + return $html; |
|
728 | + } |
|
729 | + return EEH_HTML::nl() |
|
730 | + . '<input type="hidden" name="' . $name . '"' |
|
731 | + . ' value="' . esc_attr($value) . '"/>'; |
|
732 | + } |
|
733 | + |
|
734 | + |
|
735 | + /** |
|
736 | + * Returns the currency of the payment. |
|
737 | + * (At the time of writing, this will always be the currency in the configuration; |
|
738 | + * however in the future it is anticipated that this will be stored on the payment |
|
739 | + * object itself) |
|
740 | + * |
|
741 | + * @return string for the currency code |
|
742 | + */ |
|
743 | + public function currency_code() |
|
744 | + { |
|
745 | + return EE_Config::instance()->currency->code; |
|
746 | + } |
|
747 | + |
|
748 | + |
|
749 | + /** |
|
750 | + * apply wp_strip_all_tags to all elements within an array |
|
751 | + * |
|
752 | + * @access private |
|
753 | + * @param mixed $item |
|
754 | + */ |
|
755 | + private function _strip_all_tags_within_array(&$item) |
|
756 | + { |
|
757 | + if (is_object($item)) { |
|
758 | + $item = (array) $item; |
|
759 | + } |
|
760 | + if (is_array($item)) { |
|
761 | + array_walk_recursive($item, array($this, '_strip_all_tags_within_array')); |
|
762 | + } else { |
|
763 | + $item = wp_strip_all_tags($item); |
|
764 | + } |
|
765 | + } |
|
766 | + |
|
767 | + |
|
768 | + /** |
|
769 | + * Returns TRUE is this payment was set to approved during this request (or |
|
770 | + * is approved and was created during this request). False otherwise. |
|
771 | + * |
|
772 | + * @return boolean |
|
773 | + * @throws \EE_Error |
|
774 | + */ |
|
775 | + public function just_approved() |
|
776 | + { |
|
777 | + $original_status = EEH_Array::is_set( |
|
778 | + $this->_props_n_values_provided_in_constructor, |
|
779 | + 'STS_ID', |
|
780 | + $this->get_model()->field_settings_for('STS_ID')->get_default_value() |
|
781 | + ); |
|
782 | + $current_status = $this->status(); |
|
783 | + if ( |
|
784 | + $original_status !== EEM_Payment::status_id_approved |
|
785 | + && $current_status === EEM_Payment::status_id_approved |
|
786 | + ) { |
|
787 | + return true; |
|
788 | + } else { |
|
789 | + return false; |
|
790 | + } |
|
791 | + } |
|
792 | + |
|
793 | + |
|
794 | + /** |
|
795 | + * Overrides parents' get_pretty() function just for legacy reasons |
|
796 | + * (to allow ticket https://events.codebasehq.com/projects/event-espresso/tickets/7420) |
|
797 | + * |
|
798 | + * @param string $field_name |
|
799 | + * @param string $extra_cache_ref This allows the user to specify an extra cache ref for the given property |
|
800 | + * (in cases where the same property may be used for different outputs |
|
801 | + * - i.e. datetime, money etc.) |
|
802 | + * @return mixed |
|
803 | + * @throws \EE_Error |
|
804 | + */ |
|
805 | + public function get_pretty($field_name, $extra_cache_ref = null) |
|
806 | + { |
|
807 | + if ($field_name === 'PAY_gateway') { |
|
808 | + return $this->payment_method() ? $this->payment_method()->name() : esc_html__('Unknown', 'event_espresso'); |
|
809 | + } |
|
810 | + return $this->_get_cached_property($field_name, true, $extra_cache_ref); |
|
811 | + } |
|
812 | + |
|
813 | + |
|
814 | + /** |
|
815 | + * Gets details regarding which registrations this payment was applied to |
|
816 | + * |
|
817 | + * @param array $query_params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
818 | + * @return EE_Registration_Payment[] |
|
819 | + * @throws \EE_Error |
|
820 | + */ |
|
821 | + public function registration_payments($query_params = array()) |
|
822 | + { |
|
823 | + return $this->get_many_related('Registration_Payment', $query_params); |
|
824 | + } |
|
825 | + |
|
826 | + |
|
827 | + /** |
|
828 | + * Gets the first event for this payment (it's possible that it could be for multiple) |
|
829 | + * |
|
830 | + * @return EE_Event|null |
|
831 | + */ |
|
832 | + public function get_first_event() |
|
833 | + { |
|
834 | + $transaction = $this->transaction(); |
|
835 | + if ($transaction instanceof EE_Transaction) { |
|
836 | + $primary_registrant = $transaction->primary_registration(); |
|
837 | + if ($primary_registrant instanceof EE_Registration) { |
|
838 | + return $primary_registrant->event_obj(); |
|
839 | + } |
|
840 | + } |
|
841 | + return null; |
|
842 | + } |
|
843 | + |
|
844 | + |
|
845 | + /** |
|
846 | + * Gets the name of the first event for which is being paid |
|
847 | + * |
|
848 | + * @return string |
|
849 | + */ |
|
850 | + public function get_first_event_name() |
|
851 | + { |
|
852 | + $event = $this->get_first_event(); |
|
853 | + return $event instanceof EE_Event ? $event->name() : esc_html__('Event', 'event_espresso'); |
|
854 | + } |
|
855 | + |
|
856 | + |
|
857 | + /** |
|
858 | + * Returns the payment's transaction's primary registration |
|
859 | + * |
|
860 | + * @return EE_Registration|null |
|
861 | + */ |
|
862 | + public function get_primary_registration() |
|
863 | + { |
|
864 | + if ($this->transaction() instanceof EE_Transaction) { |
|
865 | + return $this->transaction()->primary_registration(); |
|
866 | + } |
|
867 | + return null; |
|
868 | + } |
|
869 | + |
|
870 | + |
|
871 | + /** |
|
872 | + * Gets the payment's transaction's primary registration's attendee, or null |
|
873 | + * |
|
874 | + * @return EE_Attendee|null |
|
875 | + */ |
|
876 | + public function get_primary_attendee() |
|
877 | + { |
|
878 | + $primary_reg = $this->get_primary_registration(); |
|
879 | + if ($primary_reg instanceof EE_Registration) { |
|
880 | + return $primary_reg->attendee(); |
|
881 | + } |
|
882 | + return null; |
|
883 | + } |
|
884 | 884 | } |
@@ -445,11 +445,11 @@ discard block |
||
445 | 445 | */ |
446 | 446 | public function type_obj() |
447 | 447 | { |
448 | - if (! $this->_type_obj) { |
|
448 | + if ( ! $this->_type_obj) { |
|
449 | 449 | EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
450 | 450 | if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($this->type())) { |
451 | 451 | $class_name = EE_Payment_Method_Manager::instance()->payment_method_class_from_type($this->type()); |
452 | - if (! class_exists($class_name)) { |
|
452 | + if ( ! class_exists($class_name)) { |
|
453 | 453 | throw new EE_Error( |
454 | 454 | sprintf( |
455 | 455 | esc_html__( |
@@ -458,7 +458,7 @@ discard block |
||
458 | 458 | ), |
459 | 459 | $class_name, |
460 | 460 | '<br />', |
461 | - '<a href="' . admin_url('plugins.php') . '">', |
|
461 | + '<a href="'.admin_url('plugins.php').'">', |
|
462 | 462 | '</a>' |
463 | 463 | ) |
464 | 464 | ); |
@@ -499,7 +499,7 @@ discard block |
||
499 | 499 | foreach ($fields as $key => $value) { |
500 | 500 | if (strpos($key, 'PMD_') === 0) { |
501 | 501 | $key_sans_model_prefix = str_replace('PMD_', '', $key); |
502 | - $combined_settings_array [ $key_sans_model_prefix ] = $value; |
|
502 | + $combined_settings_array [$key_sans_model_prefix] = $value; |
|
503 | 503 | } |
504 | 504 | } |
505 | 505 | $combined_settings_array = array_merge($extra_meta, $combined_settings_array); |
@@ -522,14 +522,14 @@ discard block |
||
522 | 522 | <div id="' |
523 | 523 | . $this->slug() |
524 | 524 | . '-payment-option-dv" class="' |
525 | - . $payment_occurs . '-payment-gateway reg-page-payment-option-dv' . $css_class . '"> |
|
525 | + . $payment_occurs.'-payment-gateway reg-page-payment-option-dv'.$css_class.'"> |
|
526 | 526 | <a id="payment-gateway-button-' . $this->slug() |
527 | 527 | . '" class="reg-page-payment-option-lnk" rel="' |
528 | - . $this->slug() . '" href="' . $url . '" > |
|
529 | - <img src="' . $this->button_url() . '" alt="' . sprintf( |
|
528 | + . $this->slug().'" href="'.$url.'" > |
|
529 | + <img src="' . $this->button_url().'" alt="'.sprintf( |
|
530 | 530 | esc_attr__('Pay using %s', 'event_espresso'), |
531 | 531 | $this->get_pretty('PMD_name', 'form_input') |
532 | - ) . '" /> |
|
532 | + ).'" /> |
|
533 | 533 | </a> |
534 | 534 | </div> |
535 | 535 | '; |
@@ -13,582 +13,582 @@ |
||
13 | 13 | */ |
14 | 14 | class EE_Payment_Method extends EE_Base_Class |
15 | 15 | { |
16 | - /** |
|
17 | - * Payment Method type object, which has all the info about this type of payment method, |
|
18 | - * including functions for processing payments, to get settings forms, etc. |
|
19 | - * |
|
20 | - * @var EE_PMT_Base |
|
21 | - */ |
|
22 | - protected $_type_obj; |
|
23 | - |
|
24 | - |
|
25 | - /** |
|
26 | - * @param array $props_n_values |
|
27 | - * @return EE_Payment_Method |
|
28 | - * @throws \EE_Error |
|
29 | - */ |
|
30 | - public static function new_instance($props_n_values = array()) |
|
31 | - { |
|
32 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
33 | - return $has_object ? $has_object : new self($props_n_values, false); |
|
34 | - } |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * @param array $props_n_values |
|
39 | - * @return EE_Payment_Method |
|
40 | - * @throws \EE_Error |
|
41 | - */ |
|
42 | - public static function new_instance_from_db($props_n_values = array()) |
|
43 | - { |
|
44 | - return new self($props_n_values, true); |
|
45 | - } |
|
46 | - |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * Checks if there is a payment method class of the given 'PMD_type', and if so returns the classname. |
|
51 | - * Otherwise returns a normal EE_Payment_Method |
|
52 | - * |
|
53 | - * @param array $props_n_values where 'PMD_type' is a gateway name like 'Paypal_Standard','Invoice',etc (basically |
|
54 | - * the classname minus 'EEPM_') |
|
55 | - * @return string |
|
56 | - */ |
|
57 | - // private static function _payment_method_type($props_n_values) |
|
58 | - // { |
|
59 | - // EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
60 | - // $type_string = isset($props_n_values['PMD_type']) ? $props_n_values['PMD_type'] : null; |
|
61 | - // if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($type_string)) { |
|
62 | - // return 'EEPM_' . $type_string; |
|
63 | - // } else { |
|
64 | - // return __CLASS__; |
|
65 | - // } |
|
66 | - // } |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * Gets whether this payment method can be used anywhere at all (ie frontend cart, admin, etc) |
|
71 | - * |
|
72 | - * @return boolean |
|
73 | - */ |
|
74 | - public function active() |
|
75 | - { |
|
76 | - return array_intersect(array_keys(EEM_Payment_Method::instance()->scopes()), $this->scope()); |
|
77 | - } |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * Sets this PM as active by making it usable within the CART scope. Offline gateways |
|
82 | - * are also usable from the admin-scope as well. DOES NOT SAVE it |
|
83 | - * |
|
84 | - * @throws \EE_Error |
|
85 | - */ |
|
86 | - public function set_active() |
|
87 | - { |
|
88 | - $default_scopes = array(EEM_Payment_Method::scope_cart); |
|
89 | - if ( |
|
90 | - $this->type_obj() && |
|
91 | - $this->type_obj()->payment_occurs() === EE_PMT_Base::offline |
|
92 | - ) { |
|
93 | - $default_scopes[] = EEM_Payment_Method::scope_admin; |
|
94 | - } |
|
95 | - $this->set_scope($default_scopes); |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * Makes this payment method apply to NO scopes at all. DOES NOT SAVE it. |
|
101 | - */ |
|
102 | - public function deactivate() |
|
103 | - { |
|
104 | - $this->set_scope(array()); |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * Gets button_url |
|
110 | - * |
|
111 | - * @return string |
|
112 | - */ |
|
113 | - public function button_url() |
|
114 | - { |
|
115 | - return $this->get('PMD_button_url'); |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - /** |
|
120 | - * Sets button_url |
|
121 | - * |
|
122 | - * @param string $button_url |
|
123 | - */ |
|
124 | - public function set_button_url($button_url) |
|
125 | - { |
|
126 | - $this->set('PMD_button_url', $button_url); |
|
127 | - } |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * Gets debug_mode |
|
132 | - * |
|
133 | - * @return boolean |
|
134 | - */ |
|
135 | - public function debug_mode() |
|
136 | - { |
|
137 | - return $this->get('PMD_debug_mode'); |
|
138 | - } |
|
139 | - |
|
140 | - |
|
141 | - /** |
|
142 | - * Sets debug_mode |
|
143 | - * |
|
144 | - * @param boolean $debug_mode |
|
145 | - */ |
|
146 | - public function set_debug_mode($debug_mode) |
|
147 | - { |
|
148 | - $this->set('PMD_debug_mode', $debug_mode); |
|
149 | - } |
|
150 | - |
|
151 | - |
|
152 | - /** |
|
153 | - * Gets description |
|
154 | - * |
|
155 | - * @return string |
|
156 | - */ |
|
157 | - public function description() |
|
158 | - { |
|
159 | - return $this->get('PMD_desc'); |
|
160 | - } |
|
161 | - |
|
162 | - |
|
163 | - /** |
|
164 | - * Sets description |
|
165 | - * |
|
166 | - * @param string $description |
|
167 | - */ |
|
168 | - public function set_description($description) |
|
169 | - { |
|
170 | - $this->set('PMD_desc', $description); |
|
171 | - } |
|
172 | - |
|
173 | - |
|
174 | - /** |
|
175 | - * Gets name |
|
176 | - * |
|
177 | - * @return string |
|
178 | - */ |
|
179 | - public function name() |
|
180 | - { |
|
181 | - return $this->get('PMD_name'); |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * Sets name |
|
187 | - * |
|
188 | - * @param string $name |
|
189 | - */ |
|
190 | - public function set_name($name) |
|
191 | - { |
|
192 | - $this->set('PMD_name', $name); |
|
193 | - } |
|
194 | - |
|
195 | - |
|
196 | - /** |
|
197 | - * Gets open_by_default |
|
198 | - * |
|
199 | - * @return boolean |
|
200 | - */ |
|
201 | - public function open_by_default() |
|
202 | - { |
|
203 | - return $this->get('PMD_open_by_default'); |
|
204 | - } |
|
205 | - |
|
206 | - |
|
207 | - /** |
|
208 | - * Sets open_by_default |
|
209 | - * |
|
210 | - * @param boolean $open_by_default |
|
211 | - */ |
|
212 | - public function set_open_by_default($open_by_default) |
|
213 | - { |
|
214 | - $this->set('PMD_open_by_default', $open_by_default); |
|
215 | - } |
|
216 | - |
|
217 | - |
|
218 | - /** |
|
219 | - * Gets order |
|
220 | - * |
|
221 | - * @return int |
|
222 | - */ |
|
223 | - public function order() |
|
224 | - { |
|
225 | - return $this->get('PMD_order'); |
|
226 | - } |
|
227 | - |
|
228 | - |
|
229 | - /** |
|
230 | - * Sets order |
|
231 | - * |
|
232 | - * @param int $order |
|
233 | - */ |
|
234 | - public function set_order($order) |
|
235 | - { |
|
236 | - $this->set('PMD_order', $order); |
|
237 | - } |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * Gets slug |
|
242 | - * |
|
243 | - * @return string |
|
244 | - */ |
|
245 | - public function slug() |
|
246 | - { |
|
247 | - return $this->get('PMD_slug'); |
|
248 | - } |
|
249 | - |
|
250 | - |
|
251 | - /** |
|
252 | - * Sets slug |
|
253 | - * |
|
254 | - * @param string $slug |
|
255 | - */ |
|
256 | - public function set_slug($slug) |
|
257 | - { |
|
258 | - $this->set('PMD_slug', $slug); |
|
259 | - } |
|
260 | - |
|
261 | - |
|
262 | - /** |
|
263 | - * Gets type |
|
264 | - * |
|
265 | - * @return string |
|
266 | - */ |
|
267 | - public function type() |
|
268 | - { |
|
269 | - return $this->get('PMD_type'); |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - /** |
|
274 | - * Sets type |
|
275 | - * |
|
276 | - * @param string $type |
|
277 | - */ |
|
278 | - public function set_type($type) |
|
279 | - { |
|
280 | - $this->set('PMD_type', $type); |
|
281 | - } |
|
282 | - |
|
283 | - |
|
284 | - /** |
|
285 | - * Gets wp_user |
|
286 | - * |
|
287 | - * @return int |
|
288 | - */ |
|
289 | - public function wp_user() |
|
290 | - { |
|
291 | - return $this->get('PMD_wp_user'); |
|
292 | - } |
|
293 | - |
|
294 | - |
|
295 | - /** |
|
296 | - * Sets wp_user |
|
297 | - * |
|
298 | - * @param int $wp_user_id |
|
299 | - */ |
|
300 | - public function set_wp_user($wp_user_id) |
|
301 | - { |
|
302 | - $this->set('PMD_wp_user', $wp_user_id); |
|
303 | - } |
|
304 | - |
|
305 | - /** |
|
306 | - * Overrides parent so when PMD_type is changed we refresh the _type_obj |
|
307 | - * |
|
308 | - * @param string $field_name |
|
309 | - * @param mixed $field_value |
|
310 | - * @param boolean $use_default |
|
311 | - */ |
|
312 | - public function set($field_name, $field_value, $use_default = false) |
|
313 | - { |
|
314 | - if ($field_name === 'PMD_type') { |
|
315 | - // the type has probably changed, so forget about its old type object |
|
316 | - $this->_type_obj = null; |
|
317 | - } |
|
318 | - parent::set($field_name, $field_value, $use_default); |
|
319 | - } |
|
320 | - |
|
321 | - |
|
322 | - /** |
|
323 | - * Gets admin_name |
|
324 | - * |
|
325 | - * @return string |
|
326 | - */ |
|
327 | - public function admin_name() |
|
328 | - { |
|
329 | - return $this->get('PMD_admin_name'); |
|
330 | - } |
|
331 | - |
|
332 | - |
|
333 | - /** |
|
334 | - * Sets admin_name |
|
335 | - * |
|
336 | - * @param string $admin_name |
|
337 | - */ |
|
338 | - public function set_admin_name($admin_name) |
|
339 | - { |
|
340 | - $this->set('PMD_admin_name', $admin_name); |
|
341 | - } |
|
342 | - |
|
343 | - |
|
344 | - /** |
|
345 | - * Gets admin_desc |
|
346 | - * |
|
347 | - * @return string |
|
348 | - */ |
|
349 | - public function admin_desc() |
|
350 | - { |
|
351 | - return $this->get('PMD_admin_desc'); |
|
352 | - } |
|
353 | - |
|
354 | - |
|
355 | - /** |
|
356 | - * Sets admin_desc |
|
357 | - * |
|
358 | - * @param string $admin_desc |
|
359 | - */ |
|
360 | - public function set_admin_desc($admin_desc) |
|
361 | - { |
|
362 | - $this->set('PMD_admin_desc', $admin_desc); |
|
363 | - } |
|
364 | - |
|
365 | - |
|
366 | - /** |
|
367 | - * Gets scope |
|
368 | - * |
|
369 | - * @return array |
|
370 | - */ |
|
371 | - public function scope() |
|
372 | - { |
|
373 | - return $this->get('PMD_scope'); |
|
374 | - } |
|
375 | - |
|
376 | - |
|
377 | - /** |
|
378 | - * Sets scope |
|
379 | - * |
|
380 | - * @param array $scope |
|
381 | - */ |
|
382 | - public function set_scope($scope) |
|
383 | - { |
|
384 | - $this->set('PMD_scope', $scope); |
|
385 | - } |
|
386 | - |
|
387 | - |
|
388 | - /** |
|
389 | - * Gets the payment method type for this payment method instance |
|
390 | - * |
|
391 | - * @return EE_PMT_Base |
|
392 | - * @throws EE_Error |
|
393 | - */ |
|
394 | - public function type_obj() |
|
395 | - { |
|
396 | - if (! $this->_type_obj) { |
|
397 | - EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
398 | - if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($this->type())) { |
|
399 | - $class_name = EE_Payment_Method_Manager::instance()->payment_method_class_from_type($this->type()); |
|
400 | - if (! class_exists($class_name)) { |
|
401 | - throw new EE_Error( |
|
402 | - sprintf( |
|
403 | - esc_html__( |
|
404 | - 'An attempt to use the "%1$s" payment method failed, so it was deactivated.%2$sWas the "%1$s" Plugin recently deactivated? It can be reactivated on the %3$sPlugins Admin Page%4$s', |
|
405 | - 'event_espresso' |
|
406 | - ), |
|
407 | - $class_name, |
|
408 | - '<br />', |
|
409 | - '<a href="' . admin_url('plugins.php') . '">', |
|
410 | - '</a>' |
|
411 | - ) |
|
412 | - ); |
|
413 | - } |
|
414 | - $r = new ReflectionClass($class_name); |
|
415 | - $this->_type_obj = $r->newInstanceArgs(array($this)); |
|
416 | - } else { |
|
417 | - throw new EE_Error( |
|
418 | - sprintf( |
|
419 | - esc_html__( |
|
420 | - 'A payment method of type "%1$s" does not exist. Only ones existing are: %2$s', |
|
421 | - 'event_espresso' |
|
422 | - ), |
|
423 | - $this->type(), |
|
424 | - implode(',', EE_Payment_Method_Manager::instance()->payment_method_type_names()) |
|
425 | - ) |
|
426 | - ); |
|
427 | - } |
|
428 | - } |
|
429 | - return $this->_type_obj; |
|
430 | - } |
|
431 | - |
|
432 | - |
|
433 | - /** |
|
434 | - * Returns a simple array of key-value pairs combining the payment method's fields (without the 'PMD_' prefix) |
|
435 | - * and the extra meta. Mostly used for passing off ot gateways. * |
|
436 | - * |
|
437 | - * @return array |
|
438 | - */ |
|
439 | - public function settings_array() |
|
440 | - { |
|
441 | - $fields = $this->model_field_array(); |
|
442 | - $extra_meta = $this->all_extra_meta_array(); |
|
443 | - // remove the model's prefix from the fields |
|
444 | - $combined_settings_array = array(); |
|
445 | - foreach ($fields as $key => $value) { |
|
446 | - if (strpos($key, 'PMD_') === 0) { |
|
447 | - $key_sans_model_prefix = str_replace('PMD_', '', $key); |
|
448 | - $combined_settings_array [ $key_sans_model_prefix ] = $value; |
|
449 | - } |
|
450 | - } |
|
451 | - $combined_settings_array = array_merge($extra_meta, $combined_settings_array); |
|
452 | - return $combined_settings_array; |
|
453 | - } |
|
454 | - |
|
455 | - |
|
456 | - /** |
|
457 | - * Gets the HTML for displaying the payment method on a page. |
|
458 | - * |
|
459 | - * @param string $url |
|
460 | - * @param string $css_class |
|
461 | - * @return string of HTML for displaying the button |
|
462 | - * @throws \EE_Error |
|
463 | - */ |
|
464 | - public function button_html($url = '', $css_class = '') |
|
465 | - { |
|
466 | - $payment_occurs = $this->type_obj()->payment_occurs(); |
|
467 | - return ' |
|
16 | + /** |
|
17 | + * Payment Method type object, which has all the info about this type of payment method, |
|
18 | + * including functions for processing payments, to get settings forms, etc. |
|
19 | + * |
|
20 | + * @var EE_PMT_Base |
|
21 | + */ |
|
22 | + protected $_type_obj; |
|
23 | + |
|
24 | + |
|
25 | + /** |
|
26 | + * @param array $props_n_values |
|
27 | + * @return EE_Payment_Method |
|
28 | + * @throws \EE_Error |
|
29 | + */ |
|
30 | + public static function new_instance($props_n_values = array()) |
|
31 | + { |
|
32 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
33 | + return $has_object ? $has_object : new self($props_n_values, false); |
|
34 | + } |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * @param array $props_n_values |
|
39 | + * @return EE_Payment_Method |
|
40 | + * @throws \EE_Error |
|
41 | + */ |
|
42 | + public static function new_instance_from_db($props_n_values = array()) |
|
43 | + { |
|
44 | + return new self($props_n_values, true); |
|
45 | + } |
|
46 | + |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * Checks if there is a payment method class of the given 'PMD_type', and if so returns the classname. |
|
51 | + * Otherwise returns a normal EE_Payment_Method |
|
52 | + * |
|
53 | + * @param array $props_n_values where 'PMD_type' is a gateway name like 'Paypal_Standard','Invoice',etc (basically |
|
54 | + * the classname minus 'EEPM_') |
|
55 | + * @return string |
|
56 | + */ |
|
57 | + // private static function _payment_method_type($props_n_values) |
|
58 | + // { |
|
59 | + // EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
60 | + // $type_string = isset($props_n_values['PMD_type']) ? $props_n_values['PMD_type'] : null; |
|
61 | + // if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($type_string)) { |
|
62 | + // return 'EEPM_' . $type_string; |
|
63 | + // } else { |
|
64 | + // return __CLASS__; |
|
65 | + // } |
|
66 | + // } |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * Gets whether this payment method can be used anywhere at all (ie frontend cart, admin, etc) |
|
71 | + * |
|
72 | + * @return boolean |
|
73 | + */ |
|
74 | + public function active() |
|
75 | + { |
|
76 | + return array_intersect(array_keys(EEM_Payment_Method::instance()->scopes()), $this->scope()); |
|
77 | + } |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * Sets this PM as active by making it usable within the CART scope. Offline gateways |
|
82 | + * are also usable from the admin-scope as well. DOES NOT SAVE it |
|
83 | + * |
|
84 | + * @throws \EE_Error |
|
85 | + */ |
|
86 | + public function set_active() |
|
87 | + { |
|
88 | + $default_scopes = array(EEM_Payment_Method::scope_cart); |
|
89 | + if ( |
|
90 | + $this->type_obj() && |
|
91 | + $this->type_obj()->payment_occurs() === EE_PMT_Base::offline |
|
92 | + ) { |
|
93 | + $default_scopes[] = EEM_Payment_Method::scope_admin; |
|
94 | + } |
|
95 | + $this->set_scope($default_scopes); |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * Makes this payment method apply to NO scopes at all. DOES NOT SAVE it. |
|
101 | + */ |
|
102 | + public function deactivate() |
|
103 | + { |
|
104 | + $this->set_scope(array()); |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * Gets button_url |
|
110 | + * |
|
111 | + * @return string |
|
112 | + */ |
|
113 | + public function button_url() |
|
114 | + { |
|
115 | + return $this->get('PMD_button_url'); |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + /** |
|
120 | + * Sets button_url |
|
121 | + * |
|
122 | + * @param string $button_url |
|
123 | + */ |
|
124 | + public function set_button_url($button_url) |
|
125 | + { |
|
126 | + $this->set('PMD_button_url', $button_url); |
|
127 | + } |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * Gets debug_mode |
|
132 | + * |
|
133 | + * @return boolean |
|
134 | + */ |
|
135 | + public function debug_mode() |
|
136 | + { |
|
137 | + return $this->get('PMD_debug_mode'); |
|
138 | + } |
|
139 | + |
|
140 | + |
|
141 | + /** |
|
142 | + * Sets debug_mode |
|
143 | + * |
|
144 | + * @param boolean $debug_mode |
|
145 | + */ |
|
146 | + public function set_debug_mode($debug_mode) |
|
147 | + { |
|
148 | + $this->set('PMD_debug_mode', $debug_mode); |
|
149 | + } |
|
150 | + |
|
151 | + |
|
152 | + /** |
|
153 | + * Gets description |
|
154 | + * |
|
155 | + * @return string |
|
156 | + */ |
|
157 | + public function description() |
|
158 | + { |
|
159 | + return $this->get('PMD_desc'); |
|
160 | + } |
|
161 | + |
|
162 | + |
|
163 | + /** |
|
164 | + * Sets description |
|
165 | + * |
|
166 | + * @param string $description |
|
167 | + */ |
|
168 | + public function set_description($description) |
|
169 | + { |
|
170 | + $this->set('PMD_desc', $description); |
|
171 | + } |
|
172 | + |
|
173 | + |
|
174 | + /** |
|
175 | + * Gets name |
|
176 | + * |
|
177 | + * @return string |
|
178 | + */ |
|
179 | + public function name() |
|
180 | + { |
|
181 | + return $this->get('PMD_name'); |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * Sets name |
|
187 | + * |
|
188 | + * @param string $name |
|
189 | + */ |
|
190 | + public function set_name($name) |
|
191 | + { |
|
192 | + $this->set('PMD_name', $name); |
|
193 | + } |
|
194 | + |
|
195 | + |
|
196 | + /** |
|
197 | + * Gets open_by_default |
|
198 | + * |
|
199 | + * @return boolean |
|
200 | + */ |
|
201 | + public function open_by_default() |
|
202 | + { |
|
203 | + return $this->get('PMD_open_by_default'); |
|
204 | + } |
|
205 | + |
|
206 | + |
|
207 | + /** |
|
208 | + * Sets open_by_default |
|
209 | + * |
|
210 | + * @param boolean $open_by_default |
|
211 | + */ |
|
212 | + public function set_open_by_default($open_by_default) |
|
213 | + { |
|
214 | + $this->set('PMD_open_by_default', $open_by_default); |
|
215 | + } |
|
216 | + |
|
217 | + |
|
218 | + /** |
|
219 | + * Gets order |
|
220 | + * |
|
221 | + * @return int |
|
222 | + */ |
|
223 | + public function order() |
|
224 | + { |
|
225 | + return $this->get('PMD_order'); |
|
226 | + } |
|
227 | + |
|
228 | + |
|
229 | + /** |
|
230 | + * Sets order |
|
231 | + * |
|
232 | + * @param int $order |
|
233 | + */ |
|
234 | + public function set_order($order) |
|
235 | + { |
|
236 | + $this->set('PMD_order', $order); |
|
237 | + } |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * Gets slug |
|
242 | + * |
|
243 | + * @return string |
|
244 | + */ |
|
245 | + public function slug() |
|
246 | + { |
|
247 | + return $this->get('PMD_slug'); |
|
248 | + } |
|
249 | + |
|
250 | + |
|
251 | + /** |
|
252 | + * Sets slug |
|
253 | + * |
|
254 | + * @param string $slug |
|
255 | + */ |
|
256 | + public function set_slug($slug) |
|
257 | + { |
|
258 | + $this->set('PMD_slug', $slug); |
|
259 | + } |
|
260 | + |
|
261 | + |
|
262 | + /** |
|
263 | + * Gets type |
|
264 | + * |
|
265 | + * @return string |
|
266 | + */ |
|
267 | + public function type() |
|
268 | + { |
|
269 | + return $this->get('PMD_type'); |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + /** |
|
274 | + * Sets type |
|
275 | + * |
|
276 | + * @param string $type |
|
277 | + */ |
|
278 | + public function set_type($type) |
|
279 | + { |
|
280 | + $this->set('PMD_type', $type); |
|
281 | + } |
|
282 | + |
|
283 | + |
|
284 | + /** |
|
285 | + * Gets wp_user |
|
286 | + * |
|
287 | + * @return int |
|
288 | + */ |
|
289 | + public function wp_user() |
|
290 | + { |
|
291 | + return $this->get('PMD_wp_user'); |
|
292 | + } |
|
293 | + |
|
294 | + |
|
295 | + /** |
|
296 | + * Sets wp_user |
|
297 | + * |
|
298 | + * @param int $wp_user_id |
|
299 | + */ |
|
300 | + public function set_wp_user($wp_user_id) |
|
301 | + { |
|
302 | + $this->set('PMD_wp_user', $wp_user_id); |
|
303 | + } |
|
304 | + |
|
305 | + /** |
|
306 | + * Overrides parent so when PMD_type is changed we refresh the _type_obj |
|
307 | + * |
|
308 | + * @param string $field_name |
|
309 | + * @param mixed $field_value |
|
310 | + * @param boolean $use_default |
|
311 | + */ |
|
312 | + public function set($field_name, $field_value, $use_default = false) |
|
313 | + { |
|
314 | + if ($field_name === 'PMD_type') { |
|
315 | + // the type has probably changed, so forget about its old type object |
|
316 | + $this->_type_obj = null; |
|
317 | + } |
|
318 | + parent::set($field_name, $field_value, $use_default); |
|
319 | + } |
|
320 | + |
|
321 | + |
|
322 | + /** |
|
323 | + * Gets admin_name |
|
324 | + * |
|
325 | + * @return string |
|
326 | + */ |
|
327 | + public function admin_name() |
|
328 | + { |
|
329 | + return $this->get('PMD_admin_name'); |
|
330 | + } |
|
331 | + |
|
332 | + |
|
333 | + /** |
|
334 | + * Sets admin_name |
|
335 | + * |
|
336 | + * @param string $admin_name |
|
337 | + */ |
|
338 | + public function set_admin_name($admin_name) |
|
339 | + { |
|
340 | + $this->set('PMD_admin_name', $admin_name); |
|
341 | + } |
|
342 | + |
|
343 | + |
|
344 | + /** |
|
345 | + * Gets admin_desc |
|
346 | + * |
|
347 | + * @return string |
|
348 | + */ |
|
349 | + public function admin_desc() |
|
350 | + { |
|
351 | + return $this->get('PMD_admin_desc'); |
|
352 | + } |
|
353 | + |
|
354 | + |
|
355 | + /** |
|
356 | + * Sets admin_desc |
|
357 | + * |
|
358 | + * @param string $admin_desc |
|
359 | + */ |
|
360 | + public function set_admin_desc($admin_desc) |
|
361 | + { |
|
362 | + $this->set('PMD_admin_desc', $admin_desc); |
|
363 | + } |
|
364 | + |
|
365 | + |
|
366 | + /** |
|
367 | + * Gets scope |
|
368 | + * |
|
369 | + * @return array |
|
370 | + */ |
|
371 | + public function scope() |
|
372 | + { |
|
373 | + return $this->get('PMD_scope'); |
|
374 | + } |
|
375 | + |
|
376 | + |
|
377 | + /** |
|
378 | + * Sets scope |
|
379 | + * |
|
380 | + * @param array $scope |
|
381 | + */ |
|
382 | + public function set_scope($scope) |
|
383 | + { |
|
384 | + $this->set('PMD_scope', $scope); |
|
385 | + } |
|
386 | + |
|
387 | + |
|
388 | + /** |
|
389 | + * Gets the payment method type for this payment method instance |
|
390 | + * |
|
391 | + * @return EE_PMT_Base |
|
392 | + * @throws EE_Error |
|
393 | + */ |
|
394 | + public function type_obj() |
|
395 | + { |
|
396 | + if (! $this->_type_obj) { |
|
397 | + EE_Registry::instance()->load_lib('Payment_Method_Manager'); |
|
398 | + if (EE_Payment_Method_Manager::instance()->payment_method_type_exists($this->type())) { |
|
399 | + $class_name = EE_Payment_Method_Manager::instance()->payment_method_class_from_type($this->type()); |
|
400 | + if (! class_exists($class_name)) { |
|
401 | + throw new EE_Error( |
|
402 | + sprintf( |
|
403 | + esc_html__( |
|
404 | + 'An attempt to use the "%1$s" payment method failed, so it was deactivated.%2$sWas the "%1$s" Plugin recently deactivated? It can be reactivated on the %3$sPlugins Admin Page%4$s', |
|
405 | + 'event_espresso' |
|
406 | + ), |
|
407 | + $class_name, |
|
408 | + '<br />', |
|
409 | + '<a href="' . admin_url('plugins.php') . '">', |
|
410 | + '</a>' |
|
411 | + ) |
|
412 | + ); |
|
413 | + } |
|
414 | + $r = new ReflectionClass($class_name); |
|
415 | + $this->_type_obj = $r->newInstanceArgs(array($this)); |
|
416 | + } else { |
|
417 | + throw new EE_Error( |
|
418 | + sprintf( |
|
419 | + esc_html__( |
|
420 | + 'A payment method of type "%1$s" does not exist. Only ones existing are: %2$s', |
|
421 | + 'event_espresso' |
|
422 | + ), |
|
423 | + $this->type(), |
|
424 | + implode(',', EE_Payment_Method_Manager::instance()->payment_method_type_names()) |
|
425 | + ) |
|
426 | + ); |
|
427 | + } |
|
428 | + } |
|
429 | + return $this->_type_obj; |
|
430 | + } |
|
431 | + |
|
432 | + |
|
433 | + /** |
|
434 | + * Returns a simple array of key-value pairs combining the payment method's fields (without the 'PMD_' prefix) |
|
435 | + * and the extra meta. Mostly used for passing off ot gateways. * |
|
436 | + * |
|
437 | + * @return array |
|
438 | + */ |
|
439 | + public function settings_array() |
|
440 | + { |
|
441 | + $fields = $this->model_field_array(); |
|
442 | + $extra_meta = $this->all_extra_meta_array(); |
|
443 | + // remove the model's prefix from the fields |
|
444 | + $combined_settings_array = array(); |
|
445 | + foreach ($fields as $key => $value) { |
|
446 | + if (strpos($key, 'PMD_') === 0) { |
|
447 | + $key_sans_model_prefix = str_replace('PMD_', '', $key); |
|
448 | + $combined_settings_array [ $key_sans_model_prefix ] = $value; |
|
449 | + } |
|
450 | + } |
|
451 | + $combined_settings_array = array_merge($extra_meta, $combined_settings_array); |
|
452 | + return $combined_settings_array; |
|
453 | + } |
|
454 | + |
|
455 | + |
|
456 | + /** |
|
457 | + * Gets the HTML for displaying the payment method on a page. |
|
458 | + * |
|
459 | + * @param string $url |
|
460 | + * @param string $css_class |
|
461 | + * @return string of HTML for displaying the button |
|
462 | + * @throws \EE_Error |
|
463 | + */ |
|
464 | + public function button_html($url = '', $css_class = '') |
|
465 | + { |
|
466 | + $payment_occurs = $this->type_obj()->payment_occurs(); |
|
467 | + return ' |
|
468 | 468 | <div id="' |
469 | - . $this->slug() |
|
470 | - . '-payment-option-dv" class="' |
|
471 | - . $payment_occurs . '-payment-gateway reg-page-payment-option-dv' . $css_class . '"> |
|
469 | + . $this->slug() |
|
470 | + . '-payment-option-dv" class="' |
|
471 | + . $payment_occurs . '-payment-gateway reg-page-payment-option-dv' . $css_class . '"> |
|
472 | 472 | <a id="payment-gateway-button-' . $this->slug() |
473 | - . '" class="reg-page-payment-option-lnk" rel="' |
|
474 | - . $this->slug() . '" href="' . $url . '" > |
|
473 | + . '" class="reg-page-payment-option-lnk" rel="' |
|
474 | + . $this->slug() . '" href="' . $url . '" > |
|
475 | 475 | <img src="' . $this->button_url() . '" alt="' . sprintf( |
476 | - esc_attr__('Pay using %s', 'event_espresso'), |
|
477 | - $this->get_pretty('PMD_name', 'form_input') |
|
478 | - ) . '" /> |
|
476 | + esc_attr__('Pay using %s', 'event_espresso'), |
|
477 | + $this->get_pretty('PMD_name', 'form_input') |
|
478 | + ) . '" /> |
|
479 | 479 | </a> |
480 | 480 | </div> |
481 | 481 | '; |
482 | - } |
|
483 | - |
|
484 | - |
|
485 | - /** |
|
486 | - * Gets all the currencies which are an option for this payment method |
|
487 | - * (as defined by the gateway and the currently active currencies) |
|
488 | - * |
|
489 | - * @return EE_Currency[] |
|
490 | - * @throws \EE_Error |
|
491 | - */ |
|
492 | - public function get_all_usable_currencies() |
|
493 | - { |
|
494 | - return EEM_Currency::instance()->get_all_currencies_usable_by($this->type_obj()); |
|
495 | - } |
|
496 | - |
|
497 | - |
|
498 | - /** |
|
499 | - * Reports whether or not this payment method can be used for this payment method |
|
500 | - * |
|
501 | - * @param string $currency_code currency ID (code) |
|
502 | - * @return boolean |
|
503 | - * @throws \EE_Error |
|
504 | - */ |
|
505 | - public function usable_for_currency($currency_code) |
|
506 | - { |
|
507 | - foreach ($this->get_all_usable_currencies() as $currency_obj) { |
|
508 | - if ($currency_obj->ID() === $currency_code) { |
|
509 | - return true; |
|
510 | - } |
|
511 | - } |
|
512 | - return false; |
|
513 | - } |
|
514 | - |
|
515 | - |
|
516 | - /** |
|
517 | - * Returns TRUE if this payment method's gateway is an instance of EE_Onsite_Gateway |
|
518 | - * |
|
519 | - * @return bool |
|
520 | - * @throws \EE_Error |
|
521 | - */ |
|
522 | - public function is_on_site() |
|
523 | - { |
|
524 | - return $this->type_obj()->payment_occurs() === EE_PMT_Base::onsite; |
|
525 | - } |
|
526 | - |
|
527 | - |
|
528 | - /** |
|
529 | - * Returns TRUE if this payment method's gateway is an instance of EE_Offsite_Gateway |
|
530 | - * |
|
531 | - * @return bool |
|
532 | - * @throws \EE_Error |
|
533 | - */ |
|
534 | - public function is_off_site() |
|
535 | - { |
|
536 | - return $this->type_obj()->payment_occurs() === EE_PMT_Base::offsite; |
|
537 | - } |
|
538 | - |
|
539 | - |
|
540 | - /** |
|
541 | - * Returns TRUE if this payment method does not utilize a gateway |
|
542 | - * |
|
543 | - * @return bool |
|
544 | - * @throws \EE_Error |
|
545 | - */ |
|
546 | - public function is_off_line() |
|
547 | - { |
|
548 | - return $this->type_obj()->payment_occurs() === EE_PMT_Base::offline; |
|
549 | - } |
|
550 | - |
|
551 | - /** |
|
552 | - * Overrides default __sleep so the object type is NOT cached. |
|
553 | - * This way we can rely on the normal EE_Payment_Method::type_obj() logic |
|
554 | - * to load the required classes, and don't need them at the time of unserialization |
|
555 | - * |
|
556 | - * @return array |
|
557 | - */ |
|
558 | - public function __sleep() |
|
559 | - { |
|
560 | - $properties = get_object_vars($this); |
|
561 | - unset($properties['_type_obj']); |
|
562 | - return array_keys($properties); |
|
563 | - } |
|
564 | - |
|
565 | - |
|
566 | - /** |
|
567 | - * Overrides parent to add some logging for when payment methods get deactivated |
|
568 | - * |
|
569 | - * @param array $set_cols_n_values |
|
570 | - * @return int @see EE_Base_Class::save() |
|
571 | - * @throws \EE_Error |
|
572 | - */ |
|
573 | - public function save($set_cols_n_values = array()) |
|
574 | - { |
|
575 | - $results = parent::save($set_cols_n_values); |
|
576 | - if ($this->get_original('PMD_scope') !== $this->get('PMD_scope')) { |
|
577 | - /** @var CurrentPage $current_page */ |
|
578 | - $current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class); |
|
579 | - EE_Log::instance()->log( |
|
580 | - __FILE__, |
|
581 | - __FUNCTION__, |
|
582 | - sprintf( |
|
583 | - esc_html__('Set new scope on payment method %1$s to %2$s from %3$s on URL %4$s', 'event_espresso'), |
|
584 | - $this->name(), |
|
585 | - serialize($this->get_original('PMD_scope')), |
|
586 | - serialize($this->get('PMD_scope')), |
|
587 | - $current_page->getPermalink() |
|
588 | - ), |
|
589 | - 'payment_method_change' |
|
590 | - ); |
|
591 | - } |
|
592 | - return $results; |
|
593 | - } |
|
482 | + } |
|
483 | + |
|
484 | + |
|
485 | + /** |
|
486 | + * Gets all the currencies which are an option for this payment method |
|
487 | + * (as defined by the gateway and the currently active currencies) |
|
488 | + * |
|
489 | + * @return EE_Currency[] |
|
490 | + * @throws \EE_Error |
|
491 | + */ |
|
492 | + public function get_all_usable_currencies() |
|
493 | + { |
|
494 | + return EEM_Currency::instance()->get_all_currencies_usable_by($this->type_obj()); |
|
495 | + } |
|
496 | + |
|
497 | + |
|
498 | + /** |
|
499 | + * Reports whether or not this payment method can be used for this payment method |
|
500 | + * |
|
501 | + * @param string $currency_code currency ID (code) |
|
502 | + * @return boolean |
|
503 | + * @throws \EE_Error |
|
504 | + */ |
|
505 | + public function usable_for_currency($currency_code) |
|
506 | + { |
|
507 | + foreach ($this->get_all_usable_currencies() as $currency_obj) { |
|
508 | + if ($currency_obj->ID() === $currency_code) { |
|
509 | + return true; |
|
510 | + } |
|
511 | + } |
|
512 | + return false; |
|
513 | + } |
|
514 | + |
|
515 | + |
|
516 | + /** |
|
517 | + * Returns TRUE if this payment method's gateway is an instance of EE_Onsite_Gateway |
|
518 | + * |
|
519 | + * @return bool |
|
520 | + * @throws \EE_Error |
|
521 | + */ |
|
522 | + public function is_on_site() |
|
523 | + { |
|
524 | + return $this->type_obj()->payment_occurs() === EE_PMT_Base::onsite; |
|
525 | + } |
|
526 | + |
|
527 | + |
|
528 | + /** |
|
529 | + * Returns TRUE if this payment method's gateway is an instance of EE_Offsite_Gateway |
|
530 | + * |
|
531 | + * @return bool |
|
532 | + * @throws \EE_Error |
|
533 | + */ |
|
534 | + public function is_off_site() |
|
535 | + { |
|
536 | + return $this->type_obj()->payment_occurs() === EE_PMT_Base::offsite; |
|
537 | + } |
|
538 | + |
|
539 | + |
|
540 | + /** |
|
541 | + * Returns TRUE if this payment method does not utilize a gateway |
|
542 | + * |
|
543 | + * @return bool |
|
544 | + * @throws \EE_Error |
|
545 | + */ |
|
546 | + public function is_off_line() |
|
547 | + { |
|
548 | + return $this->type_obj()->payment_occurs() === EE_PMT_Base::offline; |
|
549 | + } |
|
550 | + |
|
551 | + /** |
|
552 | + * Overrides default __sleep so the object type is NOT cached. |
|
553 | + * This way we can rely on the normal EE_Payment_Method::type_obj() logic |
|
554 | + * to load the required classes, and don't need them at the time of unserialization |
|
555 | + * |
|
556 | + * @return array |
|
557 | + */ |
|
558 | + public function __sleep() |
|
559 | + { |
|
560 | + $properties = get_object_vars($this); |
|
561 | + unset($properties['_type_obj']); |
|
562 | + return array_keys($properties); |
|
563 | + } |
|
564 | + |
|
565 | + |
|
566 | + /** |
|
567 | + * Overrides parent to add some logging for when payment methods get deactivated |
|
568 | + * |
|
569 | + * @param array $set_cols_n_values |
|
570 | + * @return int @see EE_Base_Class::save() |
|
571 | + * @throws \EE_Error |
|
572 | + */ |
|
573 | + public function save($set_cols_n_values = array()) |
|
574 | + { |
|
575 | + $results = parent::save($set_cols_n_values); |
|
576 | + if ($this->get_original('PMD_scope') !== $this->get('PMD_scope')) { |
|
577 | + /** @var CurrentPage $current_page */ |
|
578 | + $current_page = LoaderFactory::getLoader()->getShared(CurrentPage::class); |
|
579 | + EE_Log::instance()->log( |
|
580 | + __FILE__, |
|
581 | + __FUNCTION__, |
|
582 | + sprintf( |
|
583 | + esc_html__('Set new scope on payment method %1$s to %2$s from %3$s on URL %4$s', 'event_espresso'), |
|
584 | + $this->name(), |
|
585 | + serialize($this->get_original('PMD_scope')), |
|
586 | + serialize($this->get('PMD_scope')), |
|
587 | + $current_page->getPermalink() |
|
588 | + ), |
|
589 | + 'payment_method_change' |
|
590 | + ); |
|
591 | + } |
|
592 | + return $results; |
|
593 | + } |
|
594 | 594 | } |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | self::priority_low => esc_html__('low', 'event_espresso'), |
127 | 127 | ); |
128 | 128 | |
129 | - $this->_fields = array( |
|
129 | + $this->_fields = array( |
|
130 | 130 | 'Message' => array( |
131 | 131 | 'MSG_ID' => new EE_Primary_Key_Int_Field('MSG_ID', esc_html__('Message ID', 'event_espresso')), |
132 | 132 | 'MSG_token' => new EE_Plain_Text_Field( |
@@ -436,7 +436,7 @@ discard block |
||
436 | 436 | ); |
437 | 437 | break; |
438 | 438 | default: |
439 | - $query_params[0]['AND**filter_by'][ 'OR**filter_by_' . $request_key ][ $model_name . '.' . $request_key ] = $request_value; |
|
439 | + $query_params[0]['AND**filter_by']['OR**filter_by_'.$request_key][$model_name.'.'.$request_key] = $request_value; |
|
440 | 440 | break; |
441 | 441 | } |
442 | 442 | } |
@@ -499,8 +499,8 @@ discard block |
||
499 | 499 | if ($label_parts) { |
500 | 500 | // prepend to the last element of $label_parts an "and". |
501 | 501 | if (count($label_parts) > 1) { |
502 | - $label_parts_index_to_prepend = count($label_parts) - 1; |
|
503 | - $label_parts[ $label_parts_index_to_prepend ] = 'and' . $label_parts[ $label_parts_index_to_prepend ]; |
|
502 | + $label_parts_index_to_prepend = count($label_parts) - 1; |
|
503 | + $label_parts[$label_parts_index_to_prepend] = 'and'.$label_parts[$label_parts_index_to_prepend]; |
|
504 | 504 | } |
505 | 505 | |
506 | 506 | $pretty_label .= sprintf( |
@@ -560,7 +560,7 @@ discard block |
||
560 | 560 | $is_debugging = defined('EE_DEBUG_MESSAGES') && EE_DEBUG_MESSAGES; |
561 | 561 | } |
562 | 562 | |
563 | - if (! is_null($set_debug)) { |
|
563 | + if ( ! is_null($set_debug)) { |
|
564 | 564 | $is_debugging = filter_var($set_debug, FILTER_VALIDATE_BOOLEAN); |
565 | 565 | } |
566 | 566 | |
@@ -627,13 +627,13 @@ discard block |
||
627 | 627 | ) |
628 | 628 | ); |
629 | 629 | |
630 | - if (! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) { |
|
630 | + if ( ! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) { |
|
631 | 631 | global $wpdb; |
632 | 632 | $number_deleted = $wpdb->query(' |
633 | 633 | DELETE |
634 | - FROM ' . $this->table() . ' |
|
634 | + FROM ' . $this->table().' |
|
635 | 635 | WHERE |
636 | - MSG_ID IN (' . implode(",", $message_ids_to_delete) . ') |
|
636 | + MSG_ID IN (' . implode(",", $message_ids_to_delete).') |
|
637 | 637 | '); |
638 | 638 | } |
639 | 639 |
@@ -12,649 +12,649 @@ |
||
12 | 12 | */ |
13 | 13 | class EEM_Message extends EEM_Base implements EEI_Query_Filter |
14 | 14 | { |
15 | - // private instance of the Message object |
|
16 | - protected static $_instance = null; |
|
17 | - |
|
18 | - |
|
19 | - /** |
|
20 | - * This priority indicates a message should be generated and sent ASAP |
|
21 | - * |
|
22 | - * @type int |
|
23 | - */ |
|
24 | - const priority_high = 10; |
|
25 | - |
|
26 | - |
|
27 | - /** |
|
28 | - * This priority indicates a message should be generated ASAP and queued for sending. |
|
29 | - * |
|
30 | - * @type |
|
31 | - */ |
|
32 | - const priority_medium = 20; |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * This priority indicates a message should be queued for generating. |
|
37 | - * |
|
38 | - * @type int |
|
39 | - */ |
|
40 | - const priority_low = 30; |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * indicates this message was sent at the time modified |
|
45 | - */ |
|
46 | - const status_sent = 'MSN'; |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * indicates this message is waiting to be sent |
|
51 | - */ |
|
52 | - const status_idle = 'MID'; |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * indicates an attempt was a made to send this message |
|
57 | - * at the scheduled time, but it failed at the time modified. This differs from MDO status in that it will ALWAYS |
|
58 | - * appear to the end user. |
|
59 | - */ |
|
60 | - const status_failed = 'MFL'; |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * indicates the message has been flagged for resending (at the time modified). |
|
65 | - */ |
|
66 | - const status_resend = 'MRS'; |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * indicates the message has been flagged for generation but has not been generated yet. Messages always start as |
|
71 | - * this status when added to the queue. |
|
72 | - */ |
|
73 | - const status_incomplete = 'MIC'; |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * Indicates everything was generated fine for the message, however, the messenger was unable to send. |
|
78 | - * This status means that its possible to retry sending the message. |
|
79 | - */ |
|
80 | - const status_retry = 'MRT'; |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * This is used for more informational messages that may not indicate anything is broken but still cannot be |
|
85 | - * generated or sent correctly. An example of a message that would get flagged this way would be when a not |
|
86 | - * approved message was queued for generation, but at time of generation, the attached registration(s) are |
|
87 | - * approved. So the message queued for generation is no longer valid. Messages for this status will only persist |
|
88 | - * in the db and be viewable in the message activity list table when the messages system is in debug mode. |
|
89 | - * |
|
90 | - * @see EEM_Message::debug() |
|
91 | - */ |
|
92 | - const status_debug_only = 'MDO'; |
|
93 | - |
|
94 | - |
|
95 | - /** |
|
96 | - * This status is given to messages it is processed by the messenger send method. |
|
97 | - * Messages with this status should rarely be seen in the Message List table, but if they are, that's usually |
|
98 | - * indicative of a PHP timeout or memory limit issue. |
|
99 | - */ |
|
100 | - const status_messenger_executing = 'MEX'; |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * Private constructor to prevent direct creation. |
|
105 | - * |
|
106 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and |
|
107 | - * any incoming timezone data that gets saved). Note this just sends the timezone info to |
|
108 | - * the date time model field objects. Default is null (and will be assumed using the set |
|
109 | - * timezone in the 'timezone_string' wp option) |
|
110 | - * @throws EE_Error |
|
111 | - * @throws EE_Error |
|
112 | - * @throws EE_Error |
|
113 | - */ |
|
114 | - protected function __construct($timezone = null) |
|
115 | - { |
|
116 | - $this->singular_item = esc_html__('Message', 'event_espresso'); |
|
117 | - $this->plural_item = esc_html__('Messages', 'event_espresso'); |
|
118 | - |
|
119 | - $this->_tables = array( |
|
120 | - 'Message' => new EE_Primary_Table('esp_message', 'MSG_ID'), |
|
121 | - ); |
|
122 | - |
|
123 | - $allowed_priority = array( |
|
124 | - self::priority_high => esc_html__('high', 'event_espresso'), |
|
125 | - self::priority_medium => esc_html__('medium', 'event_espresso'), |
|
126 | - self::priority_low => esc_html__('low', 'event_espresso'), |
|
127 | - ); |
|
128 | - |
|
129 | - $this->_fields = array( |
|
130 | - 'Message' => array( |
|
131 | - 'MSG_ID' => new EE_Primary_Key_Int_Field('MSG_ID', esc_html__('Message ID', 'event_espresso')), |
|
132 | - 'MSG_token' => new EE_Plain_Text_Field( |
|
133 | - 'MSG_token', |
|
134 | - esc_html__( |
|
135 | - 'Unique Token used to represent this row in publicly viewable contexts (eg. a url).', |
|
136 | - 'event_espresso' |
|
137 | - ), |
|
138 | - false, |
|
139 | - EEH_URL::generate_unique_token() |
|
140 | - ), |
|
141 | - 'GRP_ID' => new EE_Foreign_Key_Int_Field( |
|
142 | - 'GRP_ID', |
|
143 | - esc_html__('Foreign key to the EEM_Message_Template_Group table.', 'event_espresso'), |
|
144 | - true, |
|
145 | - 0, |
|
146 | - 'Message_Template_Group' |
|
147 | - ), |
|
148 | - 'TXN_ID' => new EE_Foreign_Key_Int_Field( |
|
149 | - 'TXN_ID', |
|
150 | - esc_html__( |
|
151 | - 'Foreign key to the related EE_Transaction. This is required to give context for regenerating the specific message', |
|
152 | - 'event_espresso' |
|
153 | - ), |
|
154 | - true, |
|
155 | - 0, |
|
156 | - 'Transaction' |
|
157 | - ), |
|
158 | - 'MSG_messenger' => new EE_Plain_Text_Field( |
|
159 | - 'MSG_messenger', |
|
160 | - esc_html__( |
|
161 | - 'Corresponds to the EE_messenger::name used to send this message. This will also be used to attempt any resending of the message.', |
|
162 | - 'event_espresso' |
|
163 | - ), |
|
164 | - false, |
|
165 | - 'email' |
|
166 | - ), |
|
167 | - 'MSG_message_type' => new EE_Plain_Text_Field( |
|
168 | - 'MSG_message_type', |
|
169 | - esc_html__('Corresponds to the EE_message_type::name used to generate this message.', 'event_espresso'), |
|
170 | - false, |
|
171 | - 'receipt' |
|
172 | - ), |
|
173 | - 'MSG_context' => new EE_Plain_Text_Field('MSG_context', esc_html__('Context', 'event_espresso'), false), |
|
174 | - 'MSG_recipient_ID' => new EE_Foreign_Key_Int_Field( |
|
175 | - 'MSG_recipient_ID', |
|
176 | - esc_html__('Recipient ID', 'event_espresso'), |
|
177 | - true, |
|
178 | - null, |
|
179 | - array('Registration', 'Attendee', 'WP_User') |
|
180 | - ), |
|
181 | - 'MSG_recipient_type' => new EE_Any_Foreign_Model_Name_Field( |
|
182 | - 'MSG_recipient_type', |
|
183 | - esc_html__('Recipient Type', 'event_espresso'), |
|
184 | - true, |
|
185 | - null, |
|
186 | - array('Registration', 'Attendee', 'WP_User') |
|
187 | - ), |
|
188 | - 'MSG_content' => new EE_Maybe_Serialized_Text_Field( |
|
189 | - 'MSG_content', |
|
190 | - esc_html__('Content', 'event_espresso'), |
|
191 | - true, |
|
192 | - '' |
|
193 | - ), |
|
194 | - 'MSG_to' => new EE_Maybe_Serialized_Text_Field( |
|
195 | - 'MSG_to', |
|
196 | - esc_html__('Address To', 'event_espresso'), |
|
197 | - true |
|
198 | - ), |
|
199 | - 'MSG_from' => new EE_Maybe_Serialized_Text_Field( |
|
200 | - 'MSG_from', |
|
201 | - esc_html__('Address From', 'event_espresso'), |
|
202 | - true |
|
203 | - ), |
|
204 | - 'MSG_subject' => new EE_Maybe_Serialized_Text_Field( |
|
205 | - 'MSG_subject', |
|
206 | - esc_html__('Subject', 'event_espresso'), |
|
207 | - true, |
|
208 | - '' |
|
209 | - ), |
|
210 | - 'MSG_priority' => new EE_Enum_Integer_Field( |
|
211 | - 'MSG_priority', |
|
212 | - esc_html__('Priority', 'event_espresso'), |
|
213 | - false, |
|
214 | - self::priority_low, |
|
215 | - $allowed_priority |
|
216 | - ), |
|
217 | - 'STS_ID' => new EE_Foreign_Key_String_Field( |
|
218 | - 'STS_ID', |
|
219 | - esc_html__('Status', 'event_espresso'), |
|
220 | - false, |
|
221 | - self::status_incomplete, |
|
222 | - 'Status' |
|
223 | - ), |
|
224 | - 'MSG_created' => new EE_Datetime_Field( |
|
225 | - 'MSG_created', |
|
226 | - esc_html__('Created', 'event_espresso'), |
|
227 | - false, |
|
228 | - EE_Datetime_Field::now |
|
229 | - ), |
|
230 | - 'MSG_modified' => new EE_Datetime_Field( |
|
231 | - 'MSG_modified', |
|
232 | - esc_html__('Modified', 'event_espresso'), |
|
233 | - true, |
|
234 | - EE_Datetime_Field::now |
|
235 | - ), |
|
236 | - ), |
|
237 | - ); |
|
238 | - $this->_model_relations = array( |
|
239 | - 'Attendee' => new EE_Belongs_To_Any_Relation(), |
|
240 | - 'Registration' => new EE_Belongs_To_Any_Relation(), |
|
241 | - 'WP_User' => new EE_Belongs_To_Any_Relation(), |
|
242 | - 'Message_Template_Group' => new EE_Belongs_To_Relation(), |
|
243 | - 'Transaction' => new EE_Belongs_To_Relation(), |
|
244 | - ); |
|
245 | - parent::__construct($timezone); |
|
246 | - } |
|
247 | - |
|
248 | - |
|
249 | - /** |
|
250 | - * @return EE_Message |
|
251 | - * @throws EE_Error |
|
252 | - */ |
|
253 | - public function create_default_object() |
|
254 | - { |
|
255 | - /** @type EE_Message $message */ |
|
256 | - $message = parent::create_default_object(); |
|
257 | - if ($message instanceof EE_Message) { |
|
258 | - return EE_Message_Factory::set_messenger_and_message_type($message); |
|
259 | - } |
|
260 | - return null; |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - /** |
|
265 | - * @param mixed $cols_n_values |
|
266 | - * @return EE_Message |
|
267 | - * @throws EE_Error |
|
268 | - * @throws EE_Error |
|
269 | - */ |
|
270 | - public function instantiate_class_from_array_or_object($cols_n_values) |
|
271 | - { |
|
272 | - /** @type EE_Message $message */ |
|
273 | - $message = parent::instantiate_class_from_array_or_object($cols_n_values); |
|
274 | - if ($message instanceof EE_Message) { |
|
275 | - return EE_Message_Factory::set_messenger_and_message_type($message); |
|
276 | - } |
|
277 | - return null; |
|
278 | - } |
|
279 | - |
|
280 | - |
|
281 | - /** |
|
282 | - * Returns whether or not a message of that type was sent for a given attendee. |
|
283 | - * |
|
284 | - * @param EE_Attendee|int $attendee |
|
285 | - * @param string $message_type the message type slug |
|
286 | - * @return boolean |
|
287 | - * @throws EE_Error |
|
288 | - * @throws EE_Error |
|
289 | - * @throws EE_Error |
|
290 | - */ |
|
291 | - public function message_sent_for_attendee($attendee, $message_type) |
|
292 | - { |
|
293 | - $attendee_ID = EEM_Attendee::instance()->ensure_is_ID($attendee); |
|
294 | - return $this->exists(array( |
|
295 | - array( |
|
296 | - 'Attendee.ATT_ID' => $attendee_ID, |
|
297 | - 'MSG_message_type' => $message_type, |
|
298 | - 'STS_ID' => array('IN', $this->stati_indicating_sent()), |
|
299 | - ), |
|
300 | - )); |
|
301 | - } |
|
302 | - |
|
303 | - |
|
304 | - /** |
|
305 | - * Returns whether or not a message of that type was sent for a given registration |
|
306 | - * |
|
307 | - * @param EE_Registration|int $registration |
|
308 | - * @param string $message_type the message type slug |
|
309 | - * @return boolean |
|
310 | - * @throws EE_Error |
|
311 | - * @throws EE_Error |
|
312 | - * @throws EE_Error |
|
313 | - */ |
|
314 | - public function message_sent_for_registration($registration, $message_type) |
|
315 | - { |
|
316 | - $registrationID = EEM_Registration::instance()->ensure_is_ID($registration); |
|
317 | - return $this->exists(array( |
|
318 | - array( |
|
319 | - 'Registration.REG_ID' => $registrationID, |
|
320 | - 'MSG_message_type' => $message_type, |
|
321 | - 'STS_ID' => array('IN', $this->stati_indicating_sent()), |
|
322 | - ), |
|
323 | - )); |
|
324 | - } |
|
325 | - |
|
326 | - |
|
327 | - /** |
|
328 | - * This retrieves an EE_Message object from the db matching the given token string. |
|
329 | - * |
|
330 | - * @param string $token |
|
331 | - * @return EE_Message |
|
332 | - * @throws EE_Error |
|
333 | - */ |
|
334 | - public function get_one_by_token($token) |
|
335 | - { |
|
336 | - return $this->get_one(array( |
|
337 | - array( |
|
338 | - 'MSG_token' => $token, |
|
339 | - ), |
|
340 | - )); |
|
341 | - } |
|
342 | - |
|
343 | - |
|
344 | - /** |
|
345 | - * Returns stati that indicate the message HAS been sent |
|
346 | - * |
|
347 | - * @return array of strings for possible stati |
|
348 | - */ |
|
349 | - public function stati_indicating_sent() |
|
350 | - { |
|
351 | - return apply_filters('FHEE__EEM_Message__stati_indicating_sent', array(self::status_sent)); |
|
352 | - } |
|
353 | - |
|
354 | - |
|
355 | - /** |
|
356 | - * Returns stati that indicate the message is waiting to be sent. |
|
357 | - * |
|
358 | - * @return array of strings for possible stati. |
|
359 | - */ |
|
360 | - public function stati_indicating_to_send() |
|
361 | - { |
|
362 | - return apply_filters( |
|
363 | - 'FHEE__EEM_Message__stati_indicating_to_send', |
|
364 | - array(self::status_idle, self::status_resend) |
|
365 | - ); |
|
366 | - } |
|
367 | - |
|
368 | - |
|
369 | - /** |
|
370 | - * Returns stati that indicate the message has failed sending |
|
371 | - * |
|
372 | - * @return array array of strings for possible stati. |
|
373 | - */ |
|
374 | - public function stati_indicating_failed_sending() |
|
375 | - { |
|
376 | - $failed_stati = array( |
|
377 | - self::status_failed, |
|
378 | - self::status_retry, |
|
379 | - self::status_messenger_executing, |
|
380 | - ); |
|
381 | - // if WP_DEBUG is set, then let's include debug_only fails |
|
382 | - if (WP_DEBUG) { |
|
383 | - $failed_stati[] = self::status_debug_only; |
|
384 | - } |
|
385 | - return apply_filters('FHEE__EEM_Message__stati_indicating_failed_sending', $failed_stati); |
|
386 | - } |
|
387 | - |
|
388 | - |
|
389 | - /** |
|
390 | - * Returns filterable array of all EEM_Message statuses. |
|
391 | - * |
|
392 | - * @return array |
|
393 | - */ |
|
394 | - public function all_statuses() |
|
395 | - { |
|
396 | - return apply_filters( |
|
397 | - 'FHEE__EEM_Message__all_statuses', |
|
398 | - array( |
|
399 | - EEM_Message::status_sent, |
|
400 | - EEM_Message::status_incomplete, |
|
401 | - EEM_Message::status_idle, |
|
402 | - EEM_Message::status_resend, |
|
403 | - EEM_Message::status_retry, |
|
404 | - EEM_Message::status_failed, |
|
405 | - EEM_Message::status_messenger_executing, |
|
406 | - EEM_Message::status_debug_only, |
|
407 | - ) |
|
408 | - ); |
|
409 | - } |
|
410 | - |
|
411 | - /** |
|
412 | - * Detects any specific query variables in the request and uses those to setup appropriate |
|
413 | - * filter for any queries. |
|
414 | - * |
|
415 | - * @return array |
|
416 | - */ |
|
417 | - public function filter_by_query_params() |
|
418 | - { |
|
419 | - /** @var RequestInterface $request */ |
|
420 | - $request = EEM_Base::$loader->getShared(RequestInterface::class); |
|
421 | - // expected possible query_vars, the key in this array matches an expected key in the request, |
|
422 | - // the value, matches the corresponding EEM_Base child reference. |
|
423 | - $expected_vars = $this->_expected_vars_for_query_inject(); |
|
424 | - $query_params[0] = array(); |
|
425 | - foreach ($expected_vars as $request_key => $model_name) { |
|
426 | - $request_value = $request->getRequestParam($request_key); |
|
427 | - if ($request_value) { |
|
428 | - // special case |
|
429 | - switch ($request_key) { |
|
430 | - case '_REG_ID': |
|
431 | - $query_params[0]['AND**filter_by']['OR**filter_by_REG_ID'] = array( |
|
432 | - 'Transaction.Registration.REG_ID' => $request_value, |
|
433 | - ); |
|
434 | - break; |
|
435 | - case 'EVT_ID': |
|
436 | - $query_params[0]['AND**filter_by']['OR**filter_by_EVT_ID'] = array( |
|
437 | - 'Transaction.Registration.EVT_ID' => $request_value, |
|
438 | - ); |
|
439 | - break; |
|
440 | - default: |
|
441 | - $query_params[0]['AND**filter_by'][ 'OR**filter_by_' . $request_key ][ $model_name . '.' . $request_key ] = $request_value; |
|
442 | - break; |
|
443 | - } |
|
444 | - } |
|
445 | - } |
|
446 | - return $query_params; |
|
447 | - } |
|
448 | - |
|
449 | - |
|
450 | - /** |
|
451 | - * @return string |
|
452 | - * @throws EE_Error |
|
453 | - * @throws ReflectionException |
|
454 | - */ |
|
455 | - public function get_pretty_label_for_results() |
|
456 | - { |
|
457 | - /** @var RequestInterface $request */ |
|
458 | - $request = EEM_Base::$loader->getShared(RequestInterface::class); |
|
459 | - $expected_vars = $this->_expected_vars_for_query_inject(); |
|
460 | - $pretty_label = ''; |
|
461 | - $label_parts = array(); |
|
462 | - foreach ($expected_vars as $request_key => $model_name) { |
|
463 | - $model_name = strpos($model_name, 'EEM_', true) === 0 ? $model_name : "EEM_{$model_name}"; |
|
464 | - $model = EEM_Base::$loader->getShared($model_name); |
|
465 | - $model_field_value = $request->getRequestParam($request_key); |
|
466 | - if ($model instanceof EEM_Base && $model_field_value !== '') { |
|
467 | - switch ($request_key) { |
|
468 | - case '_REG_ID': |
|
469 | - $label_parts[] = sprintf( |
|
470 | - esc_html__('Registration with the ID: %s', 'event_espresso'), |
|
471 | - $model_field_value |
|
472 | - ); |
|
473 | - break; |
|
474 | - case 'ATT_ID': |
|
475 | - /** @var EE_Attendee $attendee */ |
|
476 | - $attendee = $model->get_one_by_ID($model_field_value); |
|
477 | - $label_parts[] = $attendee instanceof EE_Attendee |
|
478 | - ? sprintf(esc_html__('Attendee %s', 'event_espresso'), $attendee->full_name()) |
|
479 | - : sprintf(esc_html__('Attendee ID: %s', 'event_espresso'), $model_field_value); |
|
480 | - break; |
|
481 | - case 'ID': |
|
482 | - /** @var EE_WP_User $wpUser */ |
|
483 | - $wpUser = $model->get_one_by_ID($model_field_value); |
|
484 | - $label_parts[] = $wpUser instanceof EE_WP_User |
|
485 | - ? sprintf(esc_html__('WP User: %s', 'event_espresso'), $wpUser->name()) |
|
486 | - : sprintf(esc_html__('WP User ID: %s', 'event_espresso'), $model_field_value); |
|
487 | - break; |
|
488 | - case 'TXN_ID': |
|
489 | - $label_parts[] = sprintf( |
|
490 | - esc_html__('Transaction with the ID: %s', 'event_espresso'), |
|
491 | - $model_field_value |
|
492 | - ); |
|
493 | - break; |
|
494 | - case 'EVT_ID': |
|
495 | - /** @var EE_Event $Event */ |
|
496 | - $Event = $model->get_one_by_ID($model_field_value); |
|
497 | - $label_parts[] = $Event instanceof EE_Event |
|
498 | - ? sprintf(esc_html__('for the Event: %s', 'event_espresso'), $Event->name()) |
|
499 | - : sprintf(esc_html__('for the Event with ID: %s', 'event_espresso'), $model_field_value); |
|
500 | - break; |
|
501 | - } |
|
502 | - } |
|
503 | - } |
|
504 | - |
|
505 | - if ($label_parts) { |
|
506 | - // prepend to the last element of $label_parts an "and". |
|
507 | - if (count($label_parts) > 1) { |
|
508 | - $label_parts_index_to_prepend = count($label_parts) - 1; |
|
509 | - $label_parts[ $label_parts_index_to_prepend ] = 'and' . $label_parts[ $label_parts_index_to_prepend ]; |
|
510 | - } |
|
511 | - |
|
512 | - $pretty_label .= sprintf( |
|
513 | - esc_html_x( |
|
514 | - 'Showing messages for %s', |
|
515 | - 'A label for the messages returned in a query that are filtered by items in the query. This could be Transaction, Event, Attendee, Registration, or WP_User.', |
|
516 | - 'event_espresso' |
|
517 | - ), |
|
518 | - implode(', ', $label_parts) |
|
519 | - ); |
|
520 | - } |
|
521 | - return $pretty_label; |
|
522 | - } |
|
523 | - |
|
524 | - |
|
525 | - /** |
|
526 | - * This returns the array of expected variables for the EEI_Query_Filter methods being implemented |
|
527 | - * The array is in the format: |
|
528 | - * array( |
|
529 | - * {$field_name} => {$model_name} |
|
530 | - * ); |
|
531 | - * |
|
532 | - * @since 4.9.0 |
|
533 | - * @return array |
|
534 | - */ |
|
535 | - protected function _expected_vars_for_query_inject() |
|
536 | - { |
|
537 | - return array( |
|
538 | - '_REG_ID' => 'Registration', |
|
539 | - 'ATT_ID' => 'Attendee', |
|
540 | - 'ID' => 'WP_User', |
|
541 | - 'TXN_ID' => 'Transaction', |
|
542 | - 'EVT_ID' => 'Event', |
|
543 | - ); |
|
544 | - } |
|
545 | - |
|
546 | - |
|
547 | - /** |
|
548 | - * This returns whether EEM_Message is in debug mode or not. |
|
549 | - * Currently "debug mode" is used to control the handling of the EEM_Message::debug_only status when |
|
550 | - * generating/sending messages. Debug mode can be set by either: |
|
551 | - * 1. Sending in a value for the $set_debug argument |
|
552 | - * 2. Defining `EE_DEBUG_MESSAGES` constant in wp-config.php |
|
553 | - * 3. Overriding the above via the provided filter. |
|
554 | - * |
|
555 | - * @param bool|null $set_debug If provided, then the debug mode will be set internally until reset via the |
|
556 | - * provided boolean. When no argument is provided (default null) then the debug |
|
557 | - * mode will be returned. |
|
558 | - * @return bool true means Messages is in debug mode. false means messages system is not in debug mode. |
|
559 | - */ |
|
560 | - public static function debug($set_debug = null) |
|
561 | - { |
|
562 | - static $is_debugging = null; |
|
563 | - |
|
564 | - // initialize (use constant if set). |
|
565 | - if (is_null($set_debug) && is_null($is_debugging)) { |
|
566 | - $is_debugging = defined('EE_DEBUG_MESSAGES') && EE_DEBUG_MESSAGES; |
|
567 | - } |
|
568 | - |
|
569 | - if (! is_null($set_debug)) { |
|
570 | - $is_debugging = filter_var($set_debug, FILTER_VALIDATE_BOOLEAN); |
|
571 | - } |
|
572 | - |
|
573 | - // return filtered value |
|
574 | - return apply_filters('FHEE__EEM_Message__debug', $is_debugging); |
|
575 | - } |
|
576 | - |
|
577 | - |
|
578 | - /** |
|
579 | - * Deletes old messages meeting certain criteria for removal from the database. |
|
580 | - * By default, this will delete messages that: |
|
581 | - * - are older than the value of the delete_threshold in months. |
|
582 | - * - have a STS_ID other than EEM_Message::status_idle |
|
583 | - * |
|
584 | - * @param int $delete_threshold This integer will be used to set the boundary for what messages are deleted in |
|
585 | - * months. |
|
586 | - * @return bool|false|int Either the number of records affected or false if there was an error (you can call |
|
587 | - * $wpdb->last_error to find out what the error was. |
|
588 | - * @throws EE_Error |
|
589 | - * @throws EE_Error |
|
590 | - * @throws EE_Error |
|
591 | - */ |
|
592 | - public function delete_old_messages($delete_threshold = 6) |
|
593 | - { |
|
594 | - $number_deleted = 0; |
|
595 | - /** |
|
596 | - * Allows code to change the boundary for what messages are kept. |
|
597 | - * Uses the value of the `delete_threshold` variable by default. |
|
598 | - * |
|
599 | - * @param int $seconds seconds that will be subtracted from the timestamp for now. |
|
600 | - * @return int |
|
601 | - */ |
|
602 | - $time_to_leave_alone = absint( |
|
603 | - apply_filters( |
|
604 | - 'FHEE__EEM_Message__delete_old_messages__time_to_leave_alone', |
|
605 | - ((int) $delete_threshold) * MONTH_IN_SECONDS |
|
606 | - ) |
|
607 | - ); |
|
608 | - |
|
609 | - |
|
610 | - /** |
|
611 | - * Allows code to change what message stati are ignored when deleting. |
|
612 | - * Defaults to only ignore EEM_Message::status_idle messages. |
|
613 | - * |
|
614 | - * @param string $message_stati_to_keep An array of message statuses that will be ignored when deleting. |
|
615 | - */ |
|
616 | - $message_stati_to_keep = (array) apply_filters( |
|
617 | - 'FHEE__EEM_Message__delete_old_messages__message_stati_to_keep', |
|
618 | - array( |
|
619 | - EEM_Message::status_idle |
|
620 | - ) |
|
621 | - ); |
|
622 | - |
|
623 | - // first get all the ids of messages being deleted |
|
624 | - $message_ids_to_delete = EEM_Message::instance()->get_col( |
|
625 | - array( |
|
626 | - 0 => array( |
|
627 | - 'STS_ID' => array('NOT_IN', $message_stati_to_keep), |
|
628 | - 'MSG_modified' => array('<', time() - $time_to_leave_alone) |
|
629 | - ), |
|
630 | - 'limit' => apply_filters( |
|
631 | - 'EEM_Message__delete_old_messages__limit', |
|
632 | - 2000, |
|
633 | - $delete_threshold |
|
634 | - ) |
|
635 | - ) |
|
636 | - ); |
|
637 | - |
|
638 | - if (! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) { |
|
639 | - global $wpdb; |
|
640 | - $number_deleted = $wpdb->query(' |
|
15 | + // private instance of the Message object |
|
16 | + protected static $_instance = null; |
|
17 | + |
|
18 | + |
|
19 | + /** |
|
20 | + * This priority indicates a message should be generated and sent ASAP |
|
21 | + * |
|
22 | + * @type int |
|
23 | + */ |
|
24 | + const priority_high = 10; |
|
25 | + |
|
26 | + |
|
27 | + /** |
|
28 | + * This priority indicates a message should be generated ASAP and queued for sending. |
|
29 | + * |
|
30 | + * @type |
|
31 | + */ |
|
32 | + const priority_medium = 20; |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * This priority indicates a message should be queued for generating. |
|
37 | + * |
|
38 | + * @type int |
|
39 | + */ |
|
40 | + const priority_low = 30; |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * indicates this message was sent at the time modified |
|
45 | + */ |
|
46 | + const status_sent = 'MSN'; |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * indicates this message is waiting to be sent |
|
51 | + */ |
|
52 | + const status_idle = 'MID'; |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * indicates an attempt was a made to send this message |
|
57 | + * at the scheduled time, but it failed at the time modified. This differs from MDO status in that it will ALWAYS |
|
58 | + * appear to the end user. |
|
59 | + */ |
|
60 | + const status_failed = 'MFL'; |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * indicates the message has been flagged for resending (at the time modified). |
|
65 | + */ |
|
66 | + const status_resend = 'MRS'; |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * indicates the message has been flagged for generation but has not been generated yet. Messages always start as |
|
71 | + * this status when added to the queue. |
|
72 | + */ |
|
73 | + const status_incomplete = 'MIC'; |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * Indicates everything was generated fine for the message, however, the messenger was unable to send. |
|
78 | + * This status means that its possible to retry sending the message. |
|
79 | + */ |
|
80 | + const status_retry = 'MRT'; |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * This is used for more informational messages that may not indicate anything is broken but still cannot be |
|
85 | + * generated or sent correctly. An example of a message that would get flagged this way would be when a not |
|
86 | + * approved message was queued for generation, but at time of generation, the attached registration(s) are |
|
87 | + * approved. So the message queued for generation is no longer valid. Messages for this status will only persist |
|
88 | + * in the db and be viewable in the message activity list table when the messages system is in debug mode. |
|
89 | + * |
|
90 | + * @see EEM_Message::debug() |
|
91 | + */ |
|
92 | + const status_debug_only = 'MDO'; |
|
93 | + |
|
94 | + |
|
95 | + /** |
|
96 | + * This status is given to messages it is processed by the messenger send method. |
|
97 | + * Messages with this status should rarely be seen in the Message List table, but if they are, that's usually |
|
98 | + * indicative of a PHP timeout or memory limit issue. |
|
99 | + */ |
|
100 | + const status_messenger_executing = 'MEX'; |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * Private constructor to prevent direct creation. |
|
105 | + * |
|
106 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and |
|
107 | + * any incoming timezone data that gets saved). Note this just sends the timezone info to |
|
108 | + * the date time model field objects. Default is null (and will be assumed using the set |
|
109 | + * timezone in the 'timezone_string' wp option) |
|
110 | + * @throws EE_Error |
|
111 | + * @throws EE_Error |
|
112 | + * @throws EE_Error |
|
113 | + */ |
|
114 | + protected function __construct($timezone = null) |
|
115 | + { |
|
116 | + $this->singular_item = esc_html__('Message', 'event_espresso'); |
|
117 | + $this->plural_item = esc_html__('Messages', 'event_espresso'); |
|
118 | + |
|
119 | + $this->_tables = array( |
|
120 | + 'Message' => new EE_Primary_Table('esp_message', 'MSG_ID'), |
|
121 | + ); |
|
122 | + |
|
123 | + $allowed_priority = array( |
|
124 | + self::priority_high => esc_html__('high', 'event_espresso'), |
|
125 | + self::priority_medium => esc_html__('medium', 'event_espresso'), |
|
126 | + self::priority_low => esc_html__('low', 'event_espresso'), |
|
127 | + ); |
|
128 | + |
|
129 | + $this->_fields = array( |
|
130 | + 'Message' => array( |
|
131 | + 'MSG_ID' => new EE_Primary_Key_Int_Field('MSG_ID', esc_html__('Message ID', 'event_espresso')), |
|
132 | + 'MSG_token' => new EE_Plain_Text_Field( |
|
133 | + 'MSG_token', |
|
134 | + esc_html__( |
|
135 | + 'Unique Token used to represent this row in publicly viewable contexts (eg. a url).', |
|
136 | + 'event_espresso' |
|
137 | + ), |
|
138 | + false, |
|
139 | + EEH_URL::generate_unique_token() |
|
140 | + ), |
|
141 | + 'GRP_ID' => new EE_Foreign_Key_Int_Field( |
|
142 | + 'GRP_ID', |
|
143 | + esc_html__('Foreign key to the EEM_Message_Template_Group table.', 'event_espresso'), |
|
144 | + true, |
|
145 | + 0, |
|
146 | + 'Message_Template_Group' |
|
147 | + ), |
|
148 | + 'TXN_ID' => new EE_Foreign_Key_Int_Field( |
|
149 | + 'TXN_ID', |
|
150 | + esc_html__( |
|
151 | + 'Foreign key to the related EE_Transaction. This is required to give context for regenerating the specific message', |
|
152 | + 'event_espresso' |
|
153 | + ), |
|
154 | + true, |
|
155 | + 0, |
|
156 | + 'Transaction' |
|
157 | + ), |
|
158 | + 'MSG_messenger' => new EE_Plain_Text_Field( |
|
159 | + 'MSG_messenger', |
|
160 | + esc_html__( |
|
161 | + 'Corresponds to the EE_messenger::name used to send this message. This will also be used to attempt any resending of the message.', |
|
162 | + 'event_espresso' |
|
163 | + ), |
|
164 | + false, |
|
165 | + 'email' |
|
166 | + ), |
|
167 | + 'MSG_message_type' => new EE_Plain_Text_Field( |
|
168 | + 'MSG_message_type', |
|
169 | + esc_html__('Corresponds to the EE_message_type::name used to generate this message.', 'event_espresso'), |
|
170 | + false, |
|
171 | + 'receipt' |
|
172 | + ), |
|
173 | + 'MSG_context' => new EE_Plain_Text_Field('MSG_context', esc_html__('Context', 'event_espresso'), false), |
|
174 | + 'MSG_recipient_ID' => new EE_Foreign_Key_Int_Field( |
|
175 | + 'MSG_recipient_ID', |
|
176 | + esc_html__('Recipient ID', 'event_espresso'), |
|
177 | + true, |
|
178 | + null, |
|
179 | + array('Registration', 'Attendee', 'WP_User') |
|
180 | + ), |
|
181 | + 'MSG_recipient_type' => new EE_Any_Foreign_Model_Name_Field( |
|
182 | + 'MSG_recipient_type', |
|
183 | + esc_html__('Recipient Type', 'event_espresso'), |
|
184 | + true, |
|
185 | + null, |
|
186 | + array('Registration', 'Attendee', 'WP_User') |
|
187 | + ), |
|
188 | + 'MSG_content' => new EE_Maybe_Serialized_Text_Field( |
|
189 | + 'MSG_content', |
|
190 | + esc_html__('Content', 'event_espresso'), |
|
191 | + true, |
|
192 | + '' |
|
193 | + ), |
|
194 | + 'MSG_to' => new EE_Maybe_Serialized_Text_Field( |
|
195 | + 'MSG_to', |
|
196 | + esc_html__('Address To', 'event_espresso'), |
|
197 | + true |
|
198 | + ), |
|
199 | + 'MSG_from' => new EE_Maybe_Serialized_Text_Field( |
|
200 | + 'MSG_from', |
|
201 | + esc_html__('Address From', 'event_espresso'), |
|
202 | + true |
|
203 | + ), |
|
204 | + 'MSG_subject' => new EE_Maybe_Serialized_Text_Field( |
|
205 | + 'MSG_subject', |
|
206 | + esc_html__('Subject', 'event_espresso'), |
|
207 | + true, |
|
208 | + '' |
|
209 | + ), |
|
210 | + 'MSG_priority' => new EE_Enum_Integer_Field( |
|
211 | + 'MSG_priority', |
|
212 | + esc_html__('Priority', 'event_espresso'), |
|
213 | + false, |
|
214 | + self::priority_low, |
|
215 | + $allowed_priority |
|
216 | + ), |
|
217 | + 'STS_ID' => new EE_Foreign_Key_String_Field( |
|
218 | + 'STS_ID', |
|
219 | + esc_html__('Status', 'event_espresso'), |
|
220 | + false, |
|
221 | + self::status_incomplete, |
|
222 | + 'Status' |
|
223 | + ), |
|
224 | + 'MSG_created' => new EE_Datetime_Field( |
|
225 | + 'MSG_created', |
|
226 | + esc_html__('Created', 'event_espresso'), |
|
227 | + false, |
|
228 | + EE_Datetime_Field::now |
|
229 | + ), |
|
230 | + 'MSG_modified' => new EE_Datetime_Field( |
|
231 | + 'MSG_modified', |
|
232 | + esc_html__('Modified', 'event_espresso'), |
|
233 | + true, |
|
234 | + EE_Datetime_Field::now |
|
235 | + ), |
|
236 | + ), |
|
237 | + ); |
|
238 | + $this->_model_relations = array( |
|
239 | + 'Attendee' => new EE_Belongs_To_Any_Relation(), |
|
240 | + 'Registration' => new EE_Belongs_To_Any_Relation(), |
|
241 | + 'WP_User' => new EE_Belongs_To_Any_Relation(), |
|
242 | + 'Message_Template_Group' => new EE_Belongs_To_Relation(), |
|
243 | + 'Transaction' => new EE_Belongs_To_Relation(), |
|
244 | + ); |
|
245 | + parent::__construct($timezone); |
|
246 | + } |
|
247 | + |
|
248 | + |
|
249 | + /** |
|
250 | + * @return EE_Message |
|
251 | + * @throws EE_Error |
|
252 | + */ |
|
253 | + public function create_default_object() |
|
254 | + { |
|
255 | + /** @type EE_Message $message */ |
|
256 | + $message = parent::create_default_object(); |
|
257 | + if ($message instanceof EE_Message) { |
|
258 | + return EE_Message_Factory::set_messenger_and_message_type($message); |
|
259 | + } |
|
260 | + return null; |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + /** |
|
265 | + * @param mixed $cols_n_values |
|
266 | + * @return EE_Message |
|
267 | + * @throws EE_Error |
|
268 | + * @throws EE_Error |
|
269 | + */ |
|
270 | + public function instantiate_class_from_array_or_object($cols_n_values) |
|
271 | + { |
|
272 | + /** @type EE_Message $message */ |
|
273 | + $message = parent::instantiate_class_from_array_or_object($cols_n_values); |
|
274 | + if ($message instanceof EE_Message) { |
|
275 | + return EE_Message_Factory::set_messenger_and_message_type($message); |
|
276 | + } |
|
277 | + return null; |
|
278 | + } |
|
279 | + |
|
280 | + |
|
281 | + /** |
|
282 | + * Returns whether or not a message of that type was sent for a given attendee. |
|
283 | + * |
|
284 | + * @param EE_Attendee|int $attendee |
|
285 | + * @param string $message_type the message type slug |
|
286 | + * @return boolean |
|
287 | + * @throws EE_Error |
|
288 | + * @throws EE_Error |
|
289 | + * @throws EE_Error |
|
290 | + */ |
|
291 | + public function message_sent_for_attendee($attendee, $message_type) |
|
292 | + { |
|
293 | + $attendee_ID = EEM_Attendee::instance()->ensure_is_ID($attendee); |
|
294 | + return $this->exists(array( |
|
295 | + array( |
|
296 | + 'Attendee.ATT_ID' => $attendee_ID, |
|
297 | + 'MSG_message_type' => $message_type, |
|
298 | + 'STS_ID' => array('IN', $this->stati_indicating_sent()), |
|
299 | + ), |
|
300 | + )); |
|
301 | + } |
|
302 | + |
|
303 | + |
|
304 | + /** |
|
305 | + * Returns whether or not a message of that type was sent for a given registration |
|
306 | + * |
|
307 | + * @param EE_Registration|int $registration |
|
308 | + * @param string $message_type the message type slug |
|
309 | + * @return boolean |
|
310 | + * @throws EE_Error |
|
311 | + * @throws EE_Error |
|
312 | + * @throws EE_Error |
|
313 | + */ |
|
314 | + public function message_sent_for_registration($registration, $message_type) |
|
315 | + { |
|
316 | + $registrationID = EEM_Registration::instance()->ensure_is_ID($registration); |
|
317 | + return $this->exists(array( |
|
318 | + array( |
|
319 | + 'Registration.REG_ID' => $registrationID, |
|
320 | + 'MSG_message_type' => $message_type, |
|
321 | + 'STS_ID' => array('IN', $this->stati_indicating_sent()), |
|
322 | + ), |
|
323 | + )); |
|
324 | + } |
|
325 | + |
|
326 | + |
|
327 | + /** |
|
328 | + * This retrieves an EE_Message object from the db matching the given token string. |
|
329 | + * |
|
330 | + * @param string $token |
|
331 | + * @return EE_Message |
|
332 | + * @throws EE_Error |
|
333 | + */ |
|
334 | + public function get_one_by_token($token) |
|
335 | + { |
|
336 | + return $this->get_one(array( |
|
337 | + array( |
|
338 | + 'MSG_token' => $token, |
|
339 | + ), |
|
340 | + )); |
|
341 | + } |
|
342 | + |
|
343 | + |
|
344 | + /** |
|
345 | + * Returns stati that indicate the message HAS been sent |
|
346 | + * |
|
347 | + * @return array of strings for possible stati |
|
348 | + */ |
|
349 | + public function stati_indicating_sent() |
|
350 | + { |
|
351 | + return apply_filters('FHEE__EEM_Message__stati_indicating_sent', array(self::status_sent)); |
|
352 | + } |
|
353 | + |
|
354 | + |
|
355 | + /** |
|
356 | + * Returns stati that indicate the message is waiting to be sent. |
|
357 | + * |
|
358 | + * @return array of strings for possible stati. |
|
359 | + */ |
|
360 | + public function stati_indicating_to_send() |
|
361 | + { |
|
362 | + return apply_filters( |
|
363 | + 'FHEE__EEM_Message__stati_indicating_to_send', |
|
364 | + array(self::status_idle, self::status_resend) |
|
365 | + ); |
|
366 | + } |
|
367 | + |
|
368 | + |
|
369 | + /** |
|
370 | + * Returns stati that indicate the message has failed sending |
|
371 | + * |
|
372 | + * @return array array of strings for possible stati. |
|
373 | + */ |
|
374 | + public function stati_indicating_failed_sending() |
|
375 | + { |
|
376 | + $failed_stati = array( |
|
377 | + self::status_failed, |
|
378 | + self::status_retry, |
|
379 | + self::status_messenger_executing, |
|
380 | + ); |
|
381 | + // if WP_DEBUG is set, then let's include debug_only fails |
|
382 | + if (WP_DEBUG) { |
|
383 | + $failed_stati[] = self::status_debug_only; |
|
384 | + } |
|
385 | + return apply_filters('FHEE__EEM_Message__stati_indicating_failed_sending', $failed_stati); |
|
386 | + } |
|
387 | + |
|
388 | + |
|
389 | + /** |
|
390 | + * Returns filterable array of all EEM_Message statuses. |
|
391 | + * |
|
392 | + * @return array |
|
393 | + */ |
|
394 | + public function all_statuses() |
|
395 | + { |
|
396 | + return apply_filters( |
|
397 | + 'FHEE__EEM_Message__all_statuses', |
|
398 | + array( |
|
399 | + EEM_Message::status_sent, |
|
400 | + EEM_Message::status_incomplete, |
|
401 | + EEM_Message::status_idle, |
|
402 | + EEM_Message::status_resend, |
|
403 | + EEM_Message::status_retry, |
|
404 | + EEM_Message::status_failed, |
|
405 | + EEM_Message::status_messenger_executing, |
|
406 | + EEM_Message::status_debug_only, |
|
407 | + ) |
|
408 | + ); |
|
409 | + } |
|
410 | + |
|
411 | + /** |
|
412 | + * Detects any specific query variables in the request and uses those to setup appropriate |
|
413 | + * filter for any queries. |
|
414 | + * |
|
415 | + * @return array |
|
416 | + */ |
|
417 | + public function filter_by_query_params() |
|
418 | + { |
|
419 | + /** @var RequestInterface $request */ |
|
420 | + $request = EEM_Base::$loader->getShared(RequestInterface::class); |
|
421 | + // expected possible query_vars, the key in this array matches an expected key in the request, |
|
422 | + // the value, matches the corresponding EEM_Base child reference. |
|
423 | + $expected_vars = $this->_expected_vars_for_query_inject(); |
|
424 | + $query_params[0] = array(); |
|
425 | + foreach ($expected_vars as $request_key => $model_name) { |
|
426 | + $request_value = $request->getRequestParam($request_key); |
|
427 | + if ($request_value) { |
|
428 | + // special case |
|
429 | + switch ($request_key) { |
|
430 | + case '_REG_ID': |
|
431 | + $query_params[0]['AND**filter_by']['OR**filter_by_REG_ID'] = array( |
|
432 | + 'Transaction.Registration.REG_ID' => $request_value, |
|
433 | + ); |
|
434 | + break; |
|
435 | + case 'EVT_ID': |
|
436 | + $query_params[0]['AND**filter_by']['OR**filter_by_EVT_ID'] = array( |
|
437 | + 'Transaction.Registration.EVT_ID' => $request_value, |
|
438 | + ); |
|
439 | + break; |
|
440 | + default: |
|
441 | + $query_params[0]['AND**filter_by'][ 'OR**filter_by_' . $request_key ][ $model_name . '.' . $request_key ] = $request_value; |
|
442 | + break; |
|
443 | + } |
|
444 | + } |
|
445 | + } |
|
446 | + return $query_params; |
|
447 | + } |
|
448 | + |
|
449 | + |
|
450 | + /** |
|
451 | + * @return string |
|
452 | + * @throws EE_Error |
|
453 | + * @throws ReflectionException |
|
454 | + */ |
|
455 | + public function get_pretty_label_for_results() |
|
456 | + { |
|
457 | + /** @var RequestInterface $request */ |
|
458 | + $request = EEM_Base::$loader->getShared(RequestInterface::class); |
|
459 | + $expected_vars = $this->_expected_vars_for_query_inject(); |
|
460 | + $pretty_label = ''; |
|
461 | + $label_parts = array(); |
|
462 | + foreach ($expected_vars as $request_key => $model_name) { |
|
463 | + $model_name = strpos($model_name, 'EEM_', true) === 0 ? $model_name : "EEM_{$model_name}"; |
|
464 | + $model = EEM_Base::$loader->getShared($model_name); |
|
465 | + $model_field_value = $request->getRequestParam($request_key); |
|
466 | + if ($model instanceof EEM_Base && $model_field_value !== '') { |
|
467 | + switch ($request_key) { |
|
468 | + case '_REG_ID': |
|
469 | + $label_parts[] = sprintf( |
|
470 | + esc_html__('Registration with the ID: %s', 'event_espresso'), |
|
471 | + $model_field_value |
|
472 | + ); |
|
473 | + break; |
|
474 | + case 'ATT_ID': |
|
475 | + /** @var EE_Attendee $attendee */ |
|
476 | + $attendee = $model->get_one_by_ID($model_field_value); |
|
477 | + $label_parts[] = $attendee instanceof EE_Attendee |
|
478 | + ? sprintf(esc_html__('Attendee %s', 'event_espresso'), $attendee->full_name()) |
|
479 | + : sprintf(esc_html__('Attendee ID: %s', 'event_espresso'), $model_field_value); |
|
480 | + break; |
|
481 | + case 'ID': |
|
482 | + /** @var EE_WP_User $wpUser */ |
|
483 | + $wpUser = $model->get_one_by_ID($model_field_value); |
|
484 | + $label_parts[] = $wpUser instanceof EE_WP_User |
|
485 | + ? sprintf(esc_html__('WP User: %s', 'event_espresso'), $wpUser->name()) |
|
486 | + : sprintf(esc_html__('WP User ID: %s', 'event_espresso'), $model_field_value); |
|
487 | + break; |
|
488 | + case 'TXN_ID': |
|
489 | + $label_parts[] = sprintf( |
|
490 | + esc_html__('Transaction with the ID: %s', 'event_espresso'), |
|
491 | + $model_field_value |
|
492 | + ); |
|
493 | + break; |
|
494 | + case 'EVT_ID': |
|
495 | + /** @var EE_Event $Event */ |
|
496 | + $Event = $model->get_one_by_ID($model_field_value); |
|
497 | + $label_parts[] = $Event instanceof EE_Event |
|
498 | + ? sprintf(esc_html__('for the Event: %s', 'event_espresso'), $Event->name()) |
|
499 | + : sprintf(esc_html__('for the Event with ID: %s', 'event_espresso'), $model_field_value); |
|
500 | + break; |
|
501 | + } |
|
502 | + } |
|
503 | + } |
|
504 | + |
|
505 | + if ($label_parts) { |
|
506 | + // prepend to the last element of $label_parts an "and". |
|
507 | + if (count($label_parts) > 1) { |
|
508 | + $label_parts_index_to_prepend = count($label_parts) - 1; |
|
509 | + $label_parts[ $label_parts_index_to_prepend ] = 'and' . $label_parts[ $label_parts_index_to_prepend ]; |
|
510 | + } |
|
511 | + |
|
512 | + $pretty_label .= sprintf( |
|
513 | + esc_html_x( |
|
514 | + 'Showing messages for %s', |
|
515 | + 'A label for the messages returned in a query that are filtered by items in the query. This could be Transaction, Event, Attendee, Registration, or WP_User.', |
|
516 | + 'event_espresso' |
|
517 | + ), |
|
518 | + implode(', ', $label_parts) |
|
519 | + ); |
|
520 | + } |
|
521 | + return $pretty_label; |
|
522 | + } |
|
523 | + |
|
524 | + |
|
525 | + /** |
|
526 | + * This returns the array of expected variables for the EEI_Query_Filter methods being implemented |
|
527 | + * The array is in the format: |
|
528 | + * array( |
|
529 | + * {$field_name} => {$model_name} |
|
530 | + * ); |
|
531 | + * |
|
532 | + * @since 4.9.0 |
|
533 | + * @return array |
|
534 | + */ |
|
535 | + protected function _expected_vars_for_query_inject() |
|
536 | + { |
|
537 | + return array( |
|
538 | + '_REG_ID' => 'Registration', |
|
539 | + 'ATT_ID' => 'Attendee', |
|
540 | + 'ID' => 'WP_User', |
|
541 | + 'TXN_ID' => 'Transaction', |
|
542 | + 'EVT_ID' => 'Event', |
|
543 | + ); |
|
544 | + } |
|
545 | + |
|
546 | + |
|
547 | + /** |
|
548 | + * This returns whether EEM_Message is in debug mode or not. |
|
549 | + * Currently "debug mode" is used to control the handling of the EEM_Message::debug_only status when |
|
550 | + * generating/sending messages. Debug mode can be set by either: |
|
551 | + * 1. Sending in a value for the $set_debug argument |
|
552 | + * 2. Defining `EE_DEBUG_MESSAGES` constant in wp-config.php |
|
553 | + * 3. Overriding the above via the provided filter. |
|
554 | + * |
|
555 | + * @param bool|null $set_debug If provided, then the debug mode will be set internally until reset via the |
|
556 | + * provided boolean. When no argument is provided (default null) then the debug |
|
557 | + * mode will be returned. |
|
558 | + * @return bool true means Messages is in debug mode. false means messages system is not in debug mode. |
|
559 | + */ |
|
560 | + public static function debug($set_debug = null) |
|
561 | + { |
|
562 | + static $is_debugging = null; |
|
563 | + |
|
564 | + // initialize (use constant if set). |
|
565 | + if (is_null($set_debug) && is_null($is_debugging)) { |
|
566 | + $is_debugging = defined('EE_DEBUG_MESSAGES') && EE_DEBUG_MESSAGES; |
|
567 | + } |
|
568 | + |
|
569 | + if (! is_null($set_debug)) { |
|
570 | + $is_debugging = filter_var($set_debug, FILTER_VALIDATE_BOOLEAN); |
|
571 | + } |
|
572 | + |
|
573 | + // return filtered value |
|
574 | + return apply_filters('FHEE__EEM_Message__debug', $is_debugging); |
|
575 | + } |
|
576 | + |
|
577 | + |
|
578 | + /** |
|
579 | + * Deletes old messages meeting certain criteria for removal from the database. |
|
580 | + * By default, this will delete messages that: |
|
581 | + * - are older than the value of the delete_threshold in months. |
|
582 | + * - have a STS_ID other than EEM_Message::status_idle |
|
583 | + * |
|
584 | + * @param int $delete_threshold This integer will be used to set the boundary for what messages are deleted in |
|
585 | + * months. |
|
586 | + * @return bool|false|int Either the number of records affected or false if there was an error (you can call |
|
587 | + * $wpdb->last_error to find out what the error was. |
|
588 | + * @throws EE_Error |
|
589 | + * @throws EE_Error |
|
590 | + * @throws EE_Error |
|
591 | + */ |
|
592 | + public function delete_old_messages($delete_threshold = 6) |
|
593 | + { |
|
594 | + $number_deleted = 0; |
|
595 | + /** |
|
596 | + * Allows code to change the boundary for what messages are kept. |
|
597 | + * Uses the value of the `delete_threshold` variable by default. |
|
598 | + * |
|
599 | + * @param int $seconds seconds that will be subtracted from the timestamp for now. |
|
600 | + * @return int |
|
601 | + */ |
|
602 | + $time_to_leave_alone = absint( |
|
603 | + apply_filters( |
|
604 | + 'FHEE__EEM_Message__delete_old_messages__time_to_leave_alone', |
|
605 | + ((int) $delete_threshold) * MONTH_IN_SECONDS |
|
606 | + ) |
|
607 | + ); |
|
608 | + |
|
609 | + |
|
610 | + /** |
|
611 | + * Allows code to change what message stati are ignored when deleting. |
|
612 | + * Defaults to only ignore EEM_Message::status_idle messages. |
|
613 | + * |
|
614 | + * @param string $message_stati_to_keep An array of message statuses that will be ignored when deleting. |
|
615 | + */ |
|
616 | + $message_stati_to_keep = (array) apply_filters( |
|
617 | + 'FHEE__EEM_Message__delete_old_messages__message_stati_to_keep', |
|
618 | + array( |
|
619 | + EEM_Message::status_idle |
|
620 | + ) |
|
621 | + ); |
|
622 | + |
|
623 | + // first get all the ids of messages being deleted |
|
624 | + $message_ids_to_delete = EEM_Message::instance()->get_col( |
|
625 | + array( |
|
626 | + 0 => array( |
|
627 | + 'STS_ID' => array('NOT_IN', $message_stati_to_keep), |
|
628 | + 'MSG_modified' => array('<', time() - $time_to_leave_alone) |
|
629 | + ), |
|
630 | + 'limit' => apply_filters( |
|
631 | + 'EEM_Message__delete_old_messages__limit', |
|
632 | + 2000, |
|
633 | + $delete_threshold |
|
634 | + ) |
|
635 | + ) |
|
636 | + ); |
|
637 | + |
|
638 | + if (! empty($message_ids_to_delete) && is_array($message_ids_to_delete)) { |
|
639 | + global $wpdb; |
|
640 | + $number_deleted = $wpdb->query(' |
|
641 | 641 | DELETE |
642 | 642 | FROM ' . $this->table() . ' |
643 | 643 | WHERE |
644 | 644 | MSG_ID IN (' . implode(",", $message_ids_to_delete) . ') |
645 | 645 | '); |
646 | - } |
|
647 | - |
|
648 | - /** |
|
649 | - * This will get called if the number of records deleted 0 or greater. So a successful deletion is one where |
|
650 | - * there were no errors. An unsuccessful deletion is where there were errors. Keep that in mind for the actions |
|
651 | - * below. |
|
652 | - */ |
|
653 | - if ($number_deleted !== false) { |
|
654 | - do_action('AHEE__EEM_Message__delete_old_messages__after_successful_deletion', $message_ids_to_delete, $number_deleted); |
|
655 | - } else { |
|
656 | - do_action('AHEE__EEM_Message__delete_old_messages__after_deletion_fail', $message_ids_to_delete, $number_deleted); |
|
657 | - } |
|
658 | - return $number_deleted; |
|
659 | - } |
|
646 | + } |
|
647 | + |
|
648 | + /** |
|
649 | + * This will get called if the number of records deleted 0 or greater. So a successful deletion is one where |
|
650 | + * there were no errors. An unsuccessful deletion is where there were errors. Keep that in mind for the actions |
|
651 | + * below. |
|
652 | + */ |
|
653 | + if ($number_deleted !== false) { |
|
654 | + do_action('AHEE__EEM_Message__delete_old_messages__after_successful_deletion', $message_ids_to_delete, $number_deleted); |
|
655 | + } else { |
|
656 | + do_action('AHEE__EEM_Message__delete_old_messages__after_deletion_fail', $message_ids_to_delete, $number_deleted); |
|
657 | + } |
|
658 | + return $number_deleted; |
|
659 | + } |
|
660 | 660 | } |
@@ -5,12 +5,12 @@ |
||
5 | 5 | */ |
6 | 6 | class EE_WP_Post_Type_Field extends EE_DB_Only_Text_Field |
7 | 7 | { |
8 | - /** |
|
9 | - * @param string $post_type the exact string to be used for the post type |
|
10 | - * of all these post type model objects/rows |
|
11 | - */ |
|
12 | - public function __construct($post_type) |
|
13 | - { |
|
14 | - parent::__construct('post_type', esc_html__("Post Type", 'event_espresso'), false, $post_type); |
|
15 | - } |
|
8 | + /** |
|
9 | + * @param string $post_type the exact string to be used for the post type |
|
10 | + * of all these post type model objects/rows |
|
11 | + */ |
|
12 | + public function __construct($post_type) |
|
13 | + { |
|
14 | + parent::__construct('post_type', esc_html__("Post Type", 'event_espresso'), false, $post_type); |
|
15 | + } |
|
16 | 16 | } |
@@ -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, 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.', |
@@ -867,11 +867,11 @@ discard block |
||
867 | 867 | $questions = array(); |
868 | 868 | // get all question groups for event |
869 | 869 | $qgs = $this->get_question_groups_for_event($EVT_ID, $registration); |
870 | - if (! empty($qgs)) { |
|
870 | + if ( ! empty($qgs)) { |
|
871 | 871 | foreach ($qgs as $qg) { |
872 | 872 | $qsts = $qg->questions(); |
873 | - $questions[ $qg->ID() ] = $qg->model_field_array(); |
|
874 | - $questions[ $qg->ID() ]['QSG_questions'] = array(); |
|
873 | + $questions[$qg->ID()] = $qg->model_field_array(); |
|
874 | + $questions[$qg->ID()]['QSG_questions'] = array(); |
|
875 | 875 | foreach ($qsts as $qst) { |
876 | 876 | if ($qst->is_system_question()) { |
877 | 877 | continue; |
@@ -885,26 +885,26 @@ discard block |
||
885 | 885 | $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object(); |
886 | 886 | $qst_name = $qstn_id = $qst->ID(); |
887 | 887 | $ans_id = $answer->ID(); |
888 | - $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']'; |
|
888 | + $qst_name = ! empty($ans_id) ? '['.$qst_name.']['.$ans_id.']' : '['.$qst_name.']'; |
|
889 | 889 | $input_name = ''; |
890 | 890 | $input_id = sanitize_key($qst->display_text()); |
891 | 891 | $input_class = ''; |
892 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ] = $qst->model_field_array(); |
|
893 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name'] = 'qstn' |
|
892 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()] = $qst->model_field_array(); |
|
893 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_name'] = 'qstn' |
|
894 | 894 | . $input_name |
895 | 895 | . $qst_name; |
896 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id'] = $input_id . '-' . $qstn_id; |
|
897 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class; |
|
898 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'] = array(); |
|
899 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj'] = $qst; |
|
900 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj'] = $answer; |
|
896 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_id'] = $input_id.'-'.$qstn_id; |
|
897 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_input_class'] = $input_class; |
|
898 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'] = array(); |
|
899 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['qst_obj'] = $qst; |
|
900 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['ans_obj'] = $answer; |
|
901 | 901 | // leave responses as-is, don't convert stuff into html entities please! |
902 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['htmlentities'] = false; |
|
902 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['htmlentities'] = false; |
|
903 | 903 | if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') { |
904 | 904 | $QSOs = $qst->options(true, $answer->value()); |
905 | 905 | if (is_array($QSOs)) { |
906 | 906 | foreach ($QSOs as $QSO_ID => $QSO) { |
907 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] = $QSO->model_field_array(); |
|
907 | + $questions[$qg->ID()]['QSG_questions'][$qst->ID()]['QST_options'][$QSO_ID] = $QSO->model_field_array(); |
|
908 | 908 | } |
909 | 909 | } |
910 | 910 | } |
@@ -14,919 +14,919 @@ |
||
14 | 14 | */ |
15 | 15 | class EEM_Event extends EEM_CPT_Base |
16 | 16 | { |
17 | - /** |
|
18 | - * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the |
|
19 | - * event |
|
20 | - */ |
|
21 | - const sold_out = 'sold_out'; |
|
22 | - |
|
23 | - /** |
|
24 | - * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later |
|
25 | - * date) |
|
26 | - */ |
|
27 | - const postponed = 'postponed'; |
|
28 | - |
|
29 | - /** |
|
30 | - * constant used by status(), indicating that the event will no longer occur |
|
31 | - */ |
|
32 | - const cancelled = 'cancelled'; |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * @var string |
|
37 | - */ |
|
38 | - protected static $_default_reg_status; |
|
39 | - |
|
40 | - |
|
41 | - /** |
|
42 | - * This is the default for the additional limit field. |
|
43 | - * @var int |
|
44 | - */ |
|
45 | - protected static $_default_additional_limit = 10; |
|
46 | - |
|
47 | - |
|
48 | - /** |
|
49 | - * private instance of the Event object |
|
50 | - * |
|
51 | - * @var EEM_Event |
|
52 | - */ |
|
53 | - protected static $_instance; |
|
54 | - |
|
55 | - |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * Adds a relationship to Term_Taxonomy for each CPT_Base |
|
60 | - * |
|
61 | - * @param string $timezone |
|
62 | - * @throws \EE_Error |
|
63 | - */ |
|
64 | - protected function __construct($timezone = null) |
|
65 | - { |
|
66 | - EE_Registry::instance()->load_model('Registration'); |
|
67 | - $this->singular_item = esc_html__('Event', 'event_espresso'); |
|
68 | - $this->plural_item = esc_html__('Events', 'event_espresso'); |
|
69 | - // to remove Cancelled events from the frontend, copy the following filter to your functions.php file |
|
70 | - // add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' ); |
|
71 | - // to remove Postponed events from the frontend, copy the following filter to your functions.php file |
|
72 | - // add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' ); |
|
73 | - // to remove Sold Out events from the frontend, copy the following filter to your functions.php file |
|
74 | - // add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' ); |
|
75 | - $this->_custom_stati = apply_filters( |
|
76 | - 'AFEE__EEM_Event__construct___custom_stati', |
|
77 | - array( |
|
78 | - EEM_Event::cancelled => array( |
|
79 | - 'label' => esc_html__('Cancelled', 'event_espresso'), |
|
80 | - 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true), |
|
81 | - ), |
|
82 | - EEM_Event::postponed => array( |
|
83 | - 'label' => esc_html__('Postponed', 'event_espresso'), |
|
84 | - 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true), |
|
85 | - ), |
|
86 | - EEM_Event::sold_out => array( |
|
87 | - 'label' => esc_html__('Sold Out', 'event_espresso'), |
|
88 | - 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true), |
|
89 | - ), |
|
90 | - ) |
|
91 | - ); |
|
92 | - self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment |
|
93 | - : self::$_default_reg_status; |
|
94 | - $this->_tables = array( |
|
95 | - 'Event_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
96 | - 'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'), |
|
97 | - ); |
|
98 | - $this->_fields = array( |
|
99 | - 'Event_CPT' => array( |
|
100 | - 'EVT_ID' => new EE_Primary_Key_Int_Field( |
|
101 | - 'ID', |
|
102 | - esc_html__('Post ID for Event', 'event_espresso') |
|
103 | - ), |
|
104 | - 'EVT_name' => new EE_Plain_Text_Field( |
|
105 | - 'post_title', |
|
106 | - esc_html__('Event Name', 'event_espresso'), |
|
107 | - false, |
|
108 | - '' |
|
109 | - ), |
|
110 | - 'EVT_desc' => new EE_Post_Content_Field( |
|
111 | - 'post_content', |
|
112 | - esc_html__('Event Description', 'event_espresso'), |
|
113 | - false, |
|
114 | - '' |
|
115 | - ), |
|
116 | - 'EVT_slug' => new EE_Slug_Field( |
|
117 | - 'post_name', |
|
118 | - esc_html__('Event Slug', 'event_espresso'), |
|
119 | - false, |
|
120 | - '' |
|
121 | - ), |
|
122 | - 'EVT_created' => new EE_Datetime_Field( |
|
123 | - 'post_date', |
|
124 | - esc_html__('Date/Time Event Created', 'event_espresso'), |
|
125 | - false, |
|
126 | - EE_Datetime_Field::now |
|
127 | - ), |
|
128 | - 'EVT_short_desc' => new EE_Simple_HTML_Field( |
|
129 | - 'post_excerpt', |
|
130 | - esc_html__('Event Short Description', 'event_espresso'), |
|
131 | - false, |
|
132 | - '' |
|
133 | - ), |
|
134 | - 'EVT_modified' => new EE_Datetime_Field( |
|
135 | - 'post_modified', |
|
136 | - esc_html__('Date/Time Event Modified', 'event_espresso'), |
|
137 | - false, |
|
138 | - EE_Datetime_Field::now |
|
139 | - ), |
|
140 | - 'EVT_wp_user' => new EE_WP_User_Field( |
|
141 | - 'post_author', |
|
142 | - esc_html__('Event Creator ID', 'event_espresso'), |
|
143 | - false |
|
144 | - ), |
|
145 | - 'parent' => new EE_Integer_Field( |
|
146 | - 'post_parent', |
|
147 | - esc_html__('Event Parent ID', 'event_espresso'), |
|
148 | - false, |
|
149 | - 0 |
|
150 | - ), |
|
151 | - 'EVT_order' => new EE_Integer_Field( |
|
152 | - 'menu_order', |
|
153 | - esc_html__('Event Menu Order', 'event_espresso'), |
|
154 | - false, |
|
155 | - 1 |
|
156 | - ), |
|
157 | - 'post_type' => new EE_WP_Post_Type_Field('espresso_events'), |
|
158 | - // EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ), |
|
159 | - 'status' => new EE_WP_Post_Status_Field( |
|
160 | - 'post_status', |
|
161 | - esc_html__('Event Status', 'event_espresso'), |
|
162 | - false, |
|
163 | - 'draft', |
|
164 | - $this->_custom_stati |
|
165 | - ), |
|
166 | - 'password' => new EE_Password_Field( |
|
167 | - 'post_password', |
|
168 | - esc_html__('Password', 'event_espresso'), |
|
169 | - false, |
|
170 | - '', |
|
171 | - array( |
|
172 | - 'EVT_desc', |
|
173 | - 'EVT_short_desc', |
|
174 | - 'EVT_display_desc', |
|
175 | - 'EVT_display_ticket_selector', |
|
176 | - 'EVT_visible_on', |
|
177 | - 'EVT_additional_limit', |
|
178 | - 'EVT_default_registration_status', |
|
179 | - 'EVT_member_only', |
|
180 | - 'EVT_phone', |
|
181 | - 'EVT_allow_overflow', |
|
182 | - 'EVT_timezone_string', |
|
183 | - 'EVT_external_URL', |
|
184 | - 'EVT_donations' |
|
185 | - ) |
|
186 | - ) |
|
187 | - ), |
|
188 | - 'Event_Meta' => array( |
|
189 | - 'EVTM_ID' => new EE_DB_Only_Float_Field( |
|
190 | - 'EVTM_ID', |
|
191 | - esc_html__('Event Meta Row ID', 'event_espresso'), |
|
192 | - false |
|
193 | - ), |
|
194 | - 'EVT_ID_fk' => new EE_DB_Only_Int_Field( |
|
195 | - 'EVT_ID', |
|
196 | - esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'), |
|
197 | - false |
|
198 | - ), |
|
199 | - 'EVT_display_desc' => new EE_Boolean_Field( |
|
200 | - 'EVT_display_desc', |
|
201 | - esc_html__('Display Description Flag', 'event_espresso'), |
|
202 | - false, |
|
203 | - true |
|
204 | - ), |
|
205 | - 'EVT_display_ticket_selector' => new EE_Boolean_Field( |
|
206 | - 'EVT_display_ticket_selector', |
|
207 | - esc_html__('Display Ticket Selector Flag', 'event_espresso'), |
|
208 | - false, |
|
209 | - true |
|
210 | - ), |
|
211 | - 'EVT_visible_on' => new EE_Datetime_Field( |
|
212 | - 'EVT_visible_on', |
|
213 | - esc_html__('Event Visible Date', 'event_espresso'), |
|
214 | - true, |
|
215 | - EE_Datetime_Field::now |
|
216 | - ), |
|
217 | - 'EVT_additional_limit' => new EE_Integer_Field( |
|
218 | - 'EVT_additional_limit', |
|
219 | - esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
220 | - true, |
|
221 | - self::$_default_additional_limit |
|
222 | - ), |
|
223 | - 'EVT_default_registration_status' => new EE_Enum_Text_Field( |
|
224 | - 'EVT_default_registration_status', |
|
225 | - esc_html__('Default Registration Status on this Event', 'event_espresso'), |
|
226 | - false, |
|
227 | - EEM_Event::$_default_reg_status, |
|
228 | - EEM_Registration::reg_status_array() |
|
229 | - ), |
|
230 | - 'EVT_member_only' => new EE_Boolean_Field( |
|
231 | - 'EVT_member_only', |
|
232 | - esc_html__('Member-Only Event Flag', 'event_espresso'), |
|
233 | - false, |
|
234 | - false |
|
235 | - ), |
|
236 | - 'EVT_phone' => new EE_Plain_Text_Field( |
|
237 | - 'EVT_phone', |
|
238 | - esc_html__('Event Phone Number', 'event_espresso'), |
|
239 | - false, |
|
240 | - '' |
|
241 | - ), |
|
242 | - 'EVT_allow_overflow' => new EE_Boolean_Field( |
|
243 | - 'EVT_allow_overflow', |
|
244 | - esc_html__('Allow Overflow on Event', 'event_espresso'), |
|
245 | - false, |
|
246 | - false |
|
247 | - ), |
|
248 | - 'EVT_timezone_string' => new EE_Plain_Text_Field( |
|
249 | - 'EVT_timezone_string', |
|
250 | - esc_html__('Timezone (name) for Event times', 'event_espresso'), |
|
251 | - false, |
|
252 | - '' |
|
253 | - ), |
|
254 | - 'EVT_external_URL' => new EE_Plain_Text_Field( |
|
255 | - 'EVT_external_URL', |
|
256 | - esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'), |
|
257 | - true |
|
258 | - ), |
|
259 | - 'EVT_donations' => new EE_Boolean_Field( |
|
260 | - 'EVT_donations', |
|
261 | - esc_html__('Accept Donations?', 'event_espresso'), |
|
262 | - false, |
|
263 | - false |
|
264 | - ), |
|
265 | - ), |
|
266 | - ); |
|
267 | - $this->_model_relations = array( |
|
268 | - 'Registration' => new EE_Has_Many_Relation(), |
|
269 | - 'Datetime' => new EE_Has_Many_Relation(), |
|
270 | - 'Question_Group' => new EE_HABTM_Relation('Event_Question_Group'), |
|
271 | - 'Event_Question_Group' => new EE_Has_Many_Relation(), |
|
272 | - 'Venue' => new EE_HABTM_Relation('Event_Venue'), |
|
273 | - 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
274 | - 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
275 | - 'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'), |
|
276 | - 'Attendee' => new EE_HABTM_Relation('Registration'), |
|
277 | - 'WP_User' => new EE_Belongs_To_Relation(), |
|
278 | - ); |
|
279 | - // this model is generally available for reading |
|
280 | - $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
281 | - $this->model_chain_to_password = ''; |
|
282 | - parent::__construct($timezone); |
|
283 | - } |
|
284 | - |
|
285 | - |
|
286 | - |
|
287 | - /** |
|
288 | - * @param string $default_reg_status |
|
289 | - */ |
|
290 | - public static function set_default_reg_status($default_reg_status) |
|
291 | - { |
|
292 | - self::$_default_reg_status = $default_reg_status; |
|
293 | - // if EEM_Event has already been instantiated, |
|
294 | - // then we need to reset the `EVT_default_reg_status` field to use the new default. |
|
295 | - if (self::$_instance instanceof EEM_Event) { |
|
296 | - $default_reg_status = new EE_Enum_Text_Field( |
|
297 | - 'EVT_default_registration_status', |
|
298 | - esc_html__('Default Registration Status on this Event', 'event_espresso'), |
|
299 | - false, |
|
300 | - $default_reg_status, |
|
301 | - EEM_Registration::reg_status_array() |
|
302 | - ); |
|
303 | - $default_reg_status->_construct_finalize( |
|
304 | - 'Event_Meta', |
|
305 | - 'EVT_default_registration_status', |
|
306 | - 'EEM_Event' |
|
307 | - ); |
|
308 | - self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status; |
|
309 | - } |
|
310 | - } |
|
311 | - |
|
312 | - |
|
313 | - /** |
|
314 | - * Used to override the default for the additional limit field. |
|
315 | - * @param $additional_limit |
|
316 | - */ |
|
317 | - public static function set_default_additional_limit($additional_limit) |
|
318 | - { |
|
319 | - self::$_default_additional_limit = (int) $additional_limit; |
|
320 | - if (self::$_instance instanceof EEM_Event) { |
|
321 | - self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field( |
|
322 | - 'EVT_additional_limit', |
|
323 | - esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
324 | - true, |
|
325 | - self::$_default_additional_limit |
|
326 | - ); |
|
327 | - self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize( |
|
328 | - 'Event_Meta', |
|
329 | - 'EVT_additional_limit', |
|
330 | - 'EEM_Event' |
|
331 | - ); |
|
332 | - } |
|
333 | - } |
|
334 | - |
|
335 | - |
|
336 | - /** |
|
337 | - * Return what is currently set as the default additional limit for the event. |
|
338 | - * @return int |
|
339 | - */ |
|
340 | - public static function get_default_additional_limit() |
|
341 | - { |
|
342 | - return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit); |
|
343 | - } |
|
344 | - |
|
345 | - |
|
346 | - /** |
|
347 | - * get_question_groups |
|
348 | - * |
|
349 | - * @return array |
|
350 | - * @throws \EE_Error |
|
351 | - */ |
|
352 | - public function get_all_question_groups() |
|
353 | - { |
|
354 | - return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
355 | - array( |
|
356 | - array('QSG_deleted' => false), |
|
357 | - 'order_by' => array('QSG_order' => 'ASC'), |
|
358 | - ) |
|
359 | - ); |
|
360 | - } |
|
361 | - |
|
362 | - |
|
363 | - |
|
364 | - /** |
|
365 | - * get_question_groups |
|
366 | - * |
|
367 | - * @param int $EVT_ID |
|
368 | - * @return array|bool |
|
369 | - * @throws \EE_Error |
|
370 | - */ |
|
371 | - public function get_all_event_question_groups($EVT_ID = 0) |
|
372 | - { |
|
373 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
374 | - EE_Error::add_error( |
|
375 | - esc_html__( |
|
376 | - 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
377 | - 'event_espresso' |
|
378 | - ), |
|
379 | - __FILE__, |
|
380 | - __FUNCTION__, |
|
381 | - __LINE__ |
|
382 | - ); |
|
383 | - return false; |
|
384 | - } |
|
385 | - return EE_Registry::instance()->load_model('Event_Question_Group')->get_all( |
|
386 | - array( |
|
387 | - array('EVT_ID' => $EVT_ID), |
|
388 | - ) |
|
389 | - ); |
|
390 | - } |
|
391 | - |
|
392 | - |
|
393 | - /** |
|
394 | - * get_question_groups |
|
395 | - * |
|
396 | - * @param int $EVT_ID |
|
397 | - * @param boolean $for_primary_attendee |
|
398 | - * @return array|bool |
|
399 | - * @throws EE_Error |
|
400 | - * @throws InvalidArgumentException |
|
401 | - * @throws ReflectionException |
|
402 | - * @throws InvalidDataTypeException |
|
403 | - * @throws InvalidInterfaceException |
|
404 | - */ |
|
405 | - public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true) |
|
406 | - { |
|
407 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
408 | - EE_Error::add_error( |
|
409 | - esc_html__( |
|
410 | - // @codingStandardsIgnoreStart |
|
411 | - 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
412 | - // @codingStandardsIgnoreEnd |
|
413 | - 'event_espresso' |
|
414 | - ), |
|
415 | - __FILE__, |
|
416 | - __FUNCTION__, |
|
417 | - __LINE__ |
|
418 | - ); |
|
419 | - return false; |
|
420 | - } |
|
421 | - $query_params = [ |
|
422 | - [ |
|
423 | - 'EVT_ID' => $EVT_ID, |
|
424 | - EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary_attendee) => true |
|
425 | - ] |
|
426 | - ]; |
|
427 | - if ($for_primary_attendee) { |
|
428 | - $query_params[0]['EQG_primary'] = true; |
|
429 | - } else { |
|
430 | - $query_params[0]['EQG_additional'] = true; |
|
431 | - } |
|
432 | - return EE_Registry::instance()->load_model('Event_Question_Group')->get_all($query_params); |
|
433 | - } |
|
434 | - |
|
435 | - |
|
436 | - /** |
|
437 | - * get_question_groups |
|
438 | - * |
|
439 | - * @param int $EVT_ID |
|
440 | - * @param EE_Registration $registration |
|
441 | - * @return array|bool |
|
442 | - * @throws EE_Error |
|
443 | - * @throws InvalidArgumentException |
|
444 | - * @throws InvalidDataTypeException |
|
445 | - * @throws InvalidInterfaceException |
|
446 | - * @throws ReflectionException |
|
447 | - */ |
|
448 | - public function get_question_groups_for_event($EVT_ID, EE_Registration $registration) |
|
449 | - { |
|
450 | - if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
451 | - EE_Error::add_error( |
|
452 | - esc_html__( |
|
453 | - 'An error occurred. No Question Groups could be retrieved because an Event ID was not received.', |
|
454 | - 'event_espresso' |
|
455 | - ), |
|
456 | - __FILE__, |
|
457 | - __FUNCTION__, |
|
458 | - __LINE__ |
|
459 | - ); |
|
460 | - return false; |
|
461 | - } |
|
462 | - return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
463 | - [ |
|
464 | - [ |
|
465 | - 'Event_Question_Group.EVT_ID' => $EVT_ID, |
|
466 | - 'Event_Question_Group.' |
|
467 | - . EEM_Event_Question_Group::instance()->fieldNameForContext( |
|
468 | - $registration->is_primary_registrant() |
|
469 | - ) => true |
|
470 | - ], |
|
471 | - 'order_by' => ['QSG_order' => 'ASC'], |
|
472 | - ] |
|
473 | - ); |
|
474 | - } |
|
475 | - |
|
476 | - |
|
477 | - |
|
478 | - /** |
|
479 | - * get_question_target_db_column |
|
480 | - * |
|
481 | - * @param string $QSG_IDs csv list of $QSG IDs |
|
482 | - * @return array|bool |
|
483 | - * @throws \EE_Error |
|
484 | - */ |
|
485 | - public function get_questions_in_groups($QSG_IDs = '') |
|
486 | - { |
|
487 | - if (empty($QSG_IDs)) { |
|
488 | - EE_Error::add_error( |
|
489 | - esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'), |
|
490 | - __FILE__, |
|
491 | - __FUNCTION__, |
|
492 | - __LINE__ |
|
493 | - ); |
|
494 | - return false; |
|
495 | - } |
|
496 | - return EE_Registry::instance()->load_model('Question')->get_all( |
|
497 | - array( |
|
498 | - array( |
|
499 | - 'Question_Group.QSG_ID' => array('IN', $QSG_IDs), |
|
500 | - 'QST_deleted' => false, |
|
501 | - 'QST_admin_only' => is_admin(), |
|
502 | - ), |
|
503 | - 'order_by' => 'QST_order', |
|
504 | - ) |
|
505 | - ); |
|
506 | - } |
|
507 | - |
|
508 | - |
|
509 | - |
|
510 | - /** |
|
511 | - * get_options_for_question |
|
512 | - * |
|
513 | - * @param string $QST_IDs csv list of $QST IDs |
|
514 | - * @return array|bool |
|
515 | - * @throws \EE_Error |
|
516 | - */ |
|
517 | - public function get_options_for_question($QST_IDs) |
|
518 | - { |
|
519 | - if (empty($QST_IDs)) { |
|
520 | - EE_Error::add_error( |
|
521 | - esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'), |
|
522 | - __FILE__, |
|
523 | - __FUNCTION__, |
|
524 | - __LINE__ |
|
525 | - ); |
|
526 | - return false; |
|
527 | - } |
|
528 | - return EE_Registry::instance()->load_model('Question_Option')->get_all( |
|
529 | - array( |
|
530 | - array( |
|
531 | - 'Question.QST_ID' => array('IN', $QST_IDs), |
|
532 | - 'QSO_deleted' => false, |
|
533 | - ), |
|
534 | - 'order_by' => 'QSO_ID', |
|
535 | - ) |
|
536 | - ); |
|
537 | - } |
|
538 | - |
|
539 | - |
|
540 | - |
|
541 | - |
|
542 | - |
|
543 | - |
|
544 | - |
|
545 | - /** |
|
546 | - * Gets all events that are published |
|
547 | - * and have event start time earlier than now and an event end time later than now |
|
548 | - * |
|
549 | - * @param array $query_params An array of query params to further filter on |
|
550 | - * (note that status and DTT_EVT_start and DTT_EVT_end will be overridden) |
|
551 | - * @param bool $count whether to return the count or not (default FALSE) |
|
552 | - * @return EE_Event[]|int |
|
553 | - * @throws \EE_Error |
|
554 | - */ |
|
555 | - public function get_active_events($query_params, $count = false) |
|
556 | - { |
|
557 | - if (array_key_exists(0, $query_params)) { |
|
558 | - $where_params = $query_params[0]; |
|
559 | - unset($query_params[0]); |
|
560 | - } else { |
|
561 | - $where_params = array(); |
|
562 | - } |
|
563 | - // if we have count make sure we don't include group by |
|
564 | - if ($count && isset($query_params['group_by'])) { |
|
565 | - unset($query_params['group_by']); |
|
566 | - } |
|
567 | - // let's add specific query_params for active_events |
|
568 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
569 | - $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
570 | - // if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions |
|
571 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
572 | - $where_params['Datetime.DTT_EVT_start******'] = array( |
|
573 | - '<', |
|
574 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
575 | - ); |
|
576 | - } else { |
|
577 | - $where_params['Datetime.DTT_EVT_start'] = array( |
|
578 | - '<', |
|
579 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
580 | - ); |
|
581 | - } |
|
582 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
583 | - $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
584 | - '>', |
|
585 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
586 | - ); |
|
587 | - } else { |
|
588 | - $where_params['Datetime.DTT_EVT_end'] = array( |
|
589 | - '>', |
|
590 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
591 | - ); |
|
592 | - } |
|
593 | - $query_params[0] = $where_params; |
|
594 | - // don't use $query_params with count() |
|
595 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
596 | - return $count |
|
597 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
598 | - : $this->get_all($query_params); |
|
599 | - } |
|
600 | - |
|
601 | - |
|
602 | - |
|
603 | - /** |
|
604 | - * get all events that are published and have an event start time later than now |
|
605 | - * |
|
606 | - * @param array $query_params An array of query params to further filter on |
|
607 | - * (Note that status and DTT_EVT_start will be overridden) |
|
608 | - * @param bool $count whether to return the count or not (default FALSE) |
|
609 | - * @return EE_Event[]|int |
|
610 | - * @throws \EE_Error |
|
611 | - */ |
|
612 | - public function get_upcoming_events($query_params, $count = false) |
|
613 | - { |
|
614 | - if (array_key_exists(0, $query_params)) { |
|
615 | - $where_params = $query_params[0]; |
|
616 | - unset($query_params[0]); |
|
617 | - } else { |
|
618 | - $where_params = array(); |
|
619 | - } |
|
620 | - // if we have count make sure we don't include group by |
|
621 | - if ($count && isset($query_params['group_by'])) { |
|
622 | - unset($query_params['group_by']); |
|
623 | - } |
|
624 | - // let's add specific query_params for active_events |
|
625 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
626 | - // we need to pull events with a status of publish and sold_out |
|
627 | - $event_status = array('publish', EEM_Event::sold_out); |
|
628 | - // check if the user can read private events and if so add the 'private status to the were params' |
|
629 | - if (EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_upcoming_events')) { |
|
630 | - $event_status[] = 'private'; |
|
631 | - } |
|
632 | - $where_params['status'] = array('IN', $event_status); |
|
633 | - // if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
|
634 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
635 | - $where_params['Datetime.DTT_EVT_start*****'] = array( |
|
636 | - '>', |
|
637 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
638 | - ); |
|
639 | - } else { |
|
640 | - $where_params['Datetime.DTT_EVT_start'] = array( |
|
641 | - '>', |
|
642 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
643 | - ); |
|
644 | - } |
|
645 | - $query_params[0] = $where_params; |
|
646 | - // don't use $query_params with count() |
|
647 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
648 | - return $count |
|
649 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
650 | - : $this->get_all($query_params); |
|
651 | - } |
|
652 | - |
|
653 | - |
|
654 | - |
|
655 | - /** |
|
656 | - * Gets all events that are published |
|
657 | - * and have an event end time later than now |
|
658 | - * |
|
659 | - * @param array $query_params An array of query params to further filter on |
|
660 | - * (note that status and DTT_EVT_end will be overridden) |
|
661 | - * @param bool $count whether to return the count or not (default FALSE) |
|
662 | - * @return EE_Event[]|int |
|
663 | - * @throws \EE_Error |
|
664 | - */ |
|
665 | - public function get_active_and_upcoming_events($query_params, $count = false) |
|
666 | - { |
|
667 | - if (array_key_exists(0, $query_params)) { |
|
668 | - $where_params = $query_params[0]; |
|
669 | - unset($query_params[0]); |
|
670 | - } else { |
|
671 | - $where_params = array(); |
|
672 | - } |
|
673 | - // if we have count make sure we don't include group by |
|
674 | - if ($count && isset($query_params['group_by'])) { |
|
675 | - unset($query_params['group_by']); |
|
676 | - } |
|
677 | - // let's add specific query_params for active_events |
|
678 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
679 | - $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
680 | - // add where params for DTT_EVT_end |
|
681 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
682 | - $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
683 | - '>', |
|
684 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
685 | - ); |
|
686 | - } else { |
|
687 | - $where_params['Datetime.DTT_EVT_end'] = array( |
|
688 | - '>', |
|
689 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
690 | - ); |
|
691 | - } |
|
692 | - $query_params[0] = $where_params; |
|
693 | - // don't use $query_params with count() |
|
694 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
695 | - return $count |
|
696 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
697 | - : $this->get_all($query_params); |
|
698 | - } |
|
699 | - |
|
700 | - |
|
701 | - |
|
702 | - /** |
|
703 | - * This only returns events that are expired. |
|
704 | - * They may still be published but all their datetimes have expired. |
|
705 | - * |
|
706 | - * @param array $query_params An array of query params to further filter on |
|
707 | - * (note that status and DTT_EVT_end will be overridden) |
|
708 | - * @param bool $count whether to return the count or not (default FALSE) |
|
709 | - * @return EE_Event[]|int |
|
710 | - * @throws \EE_Error |
|
711 | - */ |
|
712 | - public function get_expired_events($query_params, $count = false) |
|
713 | - { |
|
714 | - $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
715 | - // if we have count make sure we don't include group by |
|
716 | - if ($count && isset($query_params['group_by'])) { |
|
717 | - unset($query_params['group_by']); |
|
718 | - } |
|
719 | - // let's add specific query_params for active_events |
|
720 | - // keep in mind this will override any sent status in the query AND any date queries. |
|
721 | - if (isset($where_params['status'])) { |
|
722 | - unset($where_params['status']); |
|
723 | - } |
|
724 | - $exclude_query = $query_params; |
|
725 | - if (isset($exclude_query[0])) { |
|
726 | - unset($exclude_query[0]); |
|
727 | - } |
|
728 | - $exclude_query[0] = array( |
|
729 | - 'Datetime.DTT_EVT_end' => array( |
|
730 | - '>', |
|
731 | - EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
732 | - ), |
|
733 | - ); |
|
734 | - // first get all events that have datetimes where its not expired. |
|
735 | - $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID'); |
|
736 | - $event_ids = array_keys($event_ids); |
|
737 | - // if we have any additional query_params, let's add them to the 'AND' condition |
|
738 | - $and_condition = array( |
|
739 | - 'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')), |
|
740 | - 'EVT_ID' => array('NOT IN', $event_ids), |
|
741 | - ); |
|
742 | - if (isset($where_params['OR'])) { |
|
743 | - $and_condition['OR'] = $where_params['OR']; |
|
744 | - unset($where_params['OR']); |
|
745 | - } |
|
746 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
747 | - $and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
748 | - unset($where_params['Datetime.DTT_EVT_end']); |
|
749 | - } |
|
750 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
751 | - $and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
752 | - unset($where_params['Datetime.DTT_EVT_start']); |
|
753 | - } |
|
754 | - // merge remaining $where params with the and conditions. |
|
755 | - $where_params['AND'] = array_merge($and_condition, $where_params); |
|
756 | - $query_params[0] = $where_params; |
|
757 | - // don't use $query_params with count() |
|
758 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
759 | - return $count |
|
760 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
761 | - : $this->get_all($query_params); |
|
762 | - } |
|
763 | - |
|
764 | - |
|
765 | - |
|
766 | - /** |
|
767 | - * This basically just returns the events that do not have the publish status. |
|
768 | - * |
|
769 | - * @param array $query_params An array of query params to further filter on |
|
770 | - * (note that status will be overwritten) |
|
771 | - * @param boolean $count whether to return the count or not (default FALSE) |
|
772 | - * @return EE_Event[]|int |
|
773 | - * @throws \EE_Error |
|
774 | - */ |
|
775 | - public function get_inactive_events($query_params, $count = false) |
|
776 | - { |
|
777 | - $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
778 | - // let's add in specific query_params for inactive events. |
|
779 | - if (isset($where_params['status'])) { |
|
780 | - unset($where_params['status']); |
|
781 | - } |
|
782 | - // if we have count make sure we don't include group by |
|
783 | - if ($count && isset($query_params['group_by'])) { |
|
784 | - unset($query_params['group_by']); |
|
785 | - } |
|
786 | - // if we have any additional query_params, let's add them to the 'AND' condition |
|
787 | - $where_params['AND']['status'] = array('!=', 'publish'); |
|
788 | - if (isset($where_params['OR'])) { |
|
789 | - $where_params['AND']['OR'] = $where_params['OR']; |
|
790 | - unset($where_params['OR']); |
|
791 | - } |
|
792 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
793 | - $where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
794 | - unset($where_params['Datetime.DTT_EVT_end']); |
|
795 | - } |
|
796 | - if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
797 | - $where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
798 | - unset($where_params['Datetime.DTT_EVT_start']); |
|
799 | - } |
|
800 | - $query_params[0] = $where_params; |
|
801 | - // don't use $query_params with count() |
|
802 | - // because we don't want to include additional query clauses like "GROUP BY" |
|
803 | - return $count |
|
804 | - ? $this->count(array($where_params), 'EVT_ID', true) |
|
805 | - : $this->get_all($query_params); |
|
806 | - } |
|
807 | - |
|
808 | - |
|
809 | - |
|
810 | - /** |
|
811 | - * This is just injecting into the parent add_relationship_to so we do special handling on price relationships |
|
812 | - * because we don't want to override any existing global default prices but instead insert NEW prices that get |
|
813 | - * attached to the event. See parent for param descriptions |
|
814 | - * |
|
815 | - * @param $id_or_obj |
|
816 | - * @param $other_model_id_or_obj |
|
817 | - * @param string $relationName |
|
818 | - * @param array $where_query |
|
819 | - * @return EE_Base_Class |
|
820 | - * @throws EE_Error |
|
821 | - */ |
|
822 | - public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) |
|
823 | - { |
|
824 | - if ($relationName === 'Price') { |
|
825 | - // let's get the PRC object for the given ID to make sure that we aren't dealing with a default |
|
826 | - $prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj); |
|
827 | - // if EVT_ID = 0, then this is a default |
|
828 | - if ((int) $prc_chk->get('EVT_ID') === 0) { |
|
829 | - // let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation |
|
830 | - $prc_chk->set('PRC_ID', 0); |
|
831 | - } |
|
832 | - // run parent |
|
833 | - return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query); |
|
834 | - } |
|
835 | - // otherwise carry on as normal |
|
836 | - return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query); |
|
837 | - } |
|
838 | - |
|
839 | - |
|
840 | - |
|
841 | - /******************** DEPRECATED METHODS ********************/ |
|
842 | - |
|
843 | - |
|
844 | - |
|
845 | - /** |
|
846 | - * _get_question_target_db_column |
|
847 | - * |
|
848 | - * @deprecated as of 4.8.32.rc.001. Instead consider using |
|
849 | - * EE_Registration_Custom_Questions_Form located in |
|
850 | - * admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php |
|
851 | - * @access public |
|
852 | - * @param EE_Registration $registration (so existing answers for registration are included) |
|
853 | - * @param int $EVT_ID so all question groups are included for event (not just answers from |
|
854 | - * registration). |
|
855 | - * @throws EE_Error |
|
856 | - * @return array |
|
857 | - */ |
|
858 | - public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0) |
|
859 | - { |
|
860 | - if (empty($EVT_ID)) { |
|
861 | - throw new EE_Error(esc_html__( |
|
862 | - 'An error occurred. No EVT_ID is included. Needed to know which question groups to retrieve.', |
|
863 | - 'event_espresso' |
|
864 | - )); |
|
865 | - } |
|
866 | - $questions = array(); |
|
867 | - // get all question groups for event |
|
868 | - $qgs = $this->get_question_groups_for_event($EVT_ID, $registration); |
|
869 | - if (! empty($qgs)) { |
|
870 | - foreach ($qgs as $qg) { |
|
871 | - $qsts = $qg->questions(); |
|
872 | - $questions[ $qg->ID() ] = $qg->model_field_array(); |
|
873 | - $questions[ $qg->ID() ]['QSG_questions'] = array(); |
|
874 | - foreach ($qsts as $qst) { |
|
875 | - if ($qst->is_system_question()) { |
|
876 | - continue; |
|
877 | - } |
|
878 | - $answer = EEM_Answer::instance()->get_one(array( |
|
879 | - array( |
|
880 | - 'QST_ID' => $qst->ID(), |
|
881 | - 'REG_ID' => $registration->ID(), |
|
882 | - ), |
|
883 | - )); |
|
884 | - $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object(); |
|
885 | - $qst_name = $qstn_id = $qst->ID(); |
|
886 | - $ans_id = $answer->ID(); |
|
887 | - $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']'; |
|
888 | - $input_name = ''; |
|
889 | - $input_id = sanitize_key($qst->display_text()); |
|
890 | - $input_class = ''; |
|
891 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ] = $qst->model_field_array(); |
|
892 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name'] = 'qstn' |
|
893 | - . $input_name |
|
894 | - . $qst_name; |
|
895 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id'] = $input_id . '-' . $qstn_id; |
|
896 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class; |
|
897 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'] = array(); |
|
898 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj'] = $qst; |
|
899 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj'] = $answer; |
|
900 | - // leave responses as-is, don't convert stuff into html entities please! |
|
901 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['htmlentities'] = false; |
|
902 | - if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') { |
|
903 | - $QSOs = $qst->options(true, $answer->value()); |
|
904 | - if (is_array($QSOs)) { |
|
905 | - foreach ($QSOs as $QSO_ID => $QSO) { |
|
906 | - $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] = $QSO->model_field_array(); |
|
907 | - } |
|
908 | - } |
|
909 | - } |
|
910 | - } |
|
911 | - } |
|
912 | - } |
|
913 | - return $questions; |
|
914 | - } |
|
915 | - |
|
916 | - |
|
917 | - /** |
|
918 | - * @param mixed $cols_n_values either an array of where each key is the name of a field, and the value is its value |
|
919 | - * or an stdClass where each property is the name of a column, |
|
920 | - * @return EE_Base_Class |
|
921 | - * @throws \EE_Error |
|
922 | - */ |
|
923 | - public function instantiate_class_from_array_or_object($cols_n_values) |
|
924 | - { |
|
925 | - $classInstance = parent::instantiate_class_from_array_or_object($cols_n_values); |
|
926 | - if ($classInstance instanceof EE_Event) { |
|
927 | - // events have their timezone defined in the DB, so use it immediately |
|
928 | - $this->set_timezone($classInstance->get_timezone()); |
|
929 | - } |
|
930 | - return $classInstance; |
|
931 | - } |
|
17 | + /** |
|
18 | + * constant used by status(), indicating that no more tickets can be purchased for any of the datetimes for the |
|
19 | + * event |
|
20 | + */ |
|
21 | + const sold_out = 'sold_out'; |
|
22 | + |
|
23 | + /** |
|
24 | + * constant used by status(), indicating that upcoming event dates have been postponed (may be pushed to a later |
|
25 | + * date) |
|
26 | + */ |
|
27 | + const postponed = 'postponed'; |
|
28 | + |
|
29 | + /** |
|
30 | + * constant used by status(), indicating that the event will no longer occur |
|
31 | + */ |
|
32 | + const cancelled = 'cancelled'; |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * @var string |
|
37 | + */ |
|
38 | + protected static $_default_reg_status; |
|
39 | + |
|
40 | + |
|
41 | + /** |
|
42 | + * This is the default for the additional limit field. |
|
43 | + * @var int |
|
44 | + */ |
|
45 | + protected static $_default_additional_limit = 10; |
|
46 | + |
|
47 | + |
|
48 | + /** |
|
49 | + * private instance of the Event object |
|
50 | + * |
|
51 | + * @var EEM_Event |
|
52 | + */ |
|
53 | + protected static $_instance; |
|
54 | + |
|
55 | + |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * Adds a relationship to Term_Taxonomy for each CPT_Base |
|
60 | + * |
|
61 | + * @param string $timezone |
|
62 | + * @throws \EE_Error |
|
63 | + */ |
|
64 | + protected function __construct($timezone = null) |
|
65 | + { |
|
66 | + EE_Registry::instance()->load_model('Registration'); |
|
67 | + $this->singular_item = esc_html__('Event', 'event_espresso'); |
|
68 | + $this->plural_item = esc_html__('Events', 'event_espresso'); |
|
69 | + // to remove Cancelled events from the frontend, copy the following filter to your functions.php file |
|
70 | + // add_filter( 'AFEE__EEM_Event__construct___custom_stati__cancelled__Public', '__return_false' ); |
|
71 | + // to remove Postponed events from the frontend, copy the following filter to your functions.php file |
|
72 | + // add_filter( 'AFEE__EEM_Event__construct___custom_stati__postponed__Public', '__return_false' ); |
|
73 | + // to remove Sold Out events from the frontend, copy the following filter to your functions.php file |
|
74 | + // add_filter( 'AFEE__EEM_Event__construct___custom_stati__sold_out__Public', '__return_false' ); |
|
75 | + $this->_custom_stati = apply_filters( |
|
76 | + 'AFEE__EEM_Event__construct___custom_stati', |
|
77 | + array( |
|
78 | + EEM_Event::cancelled => array( |
|
79 | + 'label' => esc_html__('Cancelled', 'event_espresso'), |
|
80 | + 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__cancelled__Public', true), |
|
81 | + ), |
|
82 | + EEM_Event::postponed => array( |
|
83 | + 'label' => esc_html__('Postponed', 'event_espresso'), |
|
84 | + 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__postponed__Public', true), |
|
85 | + ), |
|
86 | + EEM_Event::sold_out => array( |
|
87 | + 'label' => esc_html__('Sold Out', 'event_espresso'), |
|
88 | + 'public' => apply_filters('AFEE__EEM_Event__construct___custom_stati__sold_out__Public', true), |
|
89 | + ), |
|
90 | + ) |
|
91 | + ); |
|
92 | + self::$_default_reg_status = empty(self::$_default_reg_status) ? EEM_Registration::status_id_pending_payment |
|
93 | + : self::$_default_reg_status; |
|
94 | + $this->_tables = array( |
|
95 | + 'Event_CPT' => new EE_Primary_Table('posts', 'ID'), |
|
96 | + 'Event_Meta' => new EE_Secondary_Table('esp_event_meta', 'EVTM_ID', 'EVT_ID'), |
|
97 | + ); |
|
98 | + $this->_fields = array( |
|
99 | + 'Event_CPT' => array( |
|
100 | + 'EVT_ID' => new EE_Primary_Key_Int_Field( |
|
101 | + 'ID', |
|
102 | + esc_html__('Post ID for Event', 'event_espresso') |
|
103 | + ), |
|
104 | + 'EVT_name' => new EE_Plain_Text_Field( |
|
105 | + 'post_title', |
|
106 | + esc_html__('Event Name', 'event_espresso'), |
|
107 | + false, |
|
108 | + '' |
|
109 | + ), |
|
110 | + 'EVT_desc' => new EE_Post_Content_Field( |
|
111 | + 'post_content', |
|
112 | + esc_html__('Event Description', 'event_espresso'), |
|
113 | + false, |
|
114 | + '' |
|
115 | + ), |
|
116 | + 'EVT_slug' => new EE_Slug_Field( |
|
117 | + 'post_name', |
|
118 | + esc_html__('Event Slug', 'event_espresso'), |
|
119 | + false, |
|
120 | + '' |
|
121 | + ), |
|
122 | + 'EVT_created' => new EE_Datetime_Field( |
|
123 | + 'post_date', |
|
124 | + esc_html__('Date/Time Event Created', 'event_espresso'), |
|
125 | + false, |
|
126 | + EE_Datetime_Field::now |
|
127 | + ), |
|
128 | + 'EVT_short_desc' => new EE_Simple_HTML_Field( |
|
129 | + 'post_excerpt', |
|
130 | + esc_html__('Event Short Description', 'event_espresso'), |
|
131 | + false, |
|
132 | + '' |
|
133 | + ), |
|
134 | + 'EVT_modified' => new EE_Datetime_Field( |
|
135 | + 'post_modified', |
|
136 | + esc_html__('Date/Time Event Modified', 'event_espresso'), |
|
137 | + false, |
|
138 | + EE_Datetime_Field::now |
|
139 | + ), |
|
140 | + 'EVT_wp_user' => new EE_WP_User_Field( |
|
141 | + 'post_author', |
|
142 | + esc_html__('Event Creator ID', 'event_espresso'), |
|
143 | + false |
|
144 | + ), |
|
145 | + 'parent' => new EE_Integer_Field( |
|
146 | + 'post_parent', |
|
147 | + esc_html__('Event Parent ID', 'event_espresso'), |
|
148 | + false, |
|
149 | + 0 |
|
150 | + ), |
|
151 | + 'EVT_order' => new EE_Integer_Field( |
|
152 | + 'menu_order', |
|
153 | + esc_html__('Event Menu Order', 'event_espresso'), |
|
154 | + false, |
|
155 | + 1 |
|
156 | + ), |
|
157 | + 'post_type' => new EE_WP_Post_Type_Field('espresso_events'), |
|
158 | + // EE_Plain_Text_Field( 'post_type', esc_html__( 'Event Post Type', 'event_espresso' ), FALSE, 'espresso_events' ), |
|
159 | + 'status' => new EE_WP_Post_Status_Field( |
|
160 | + 'post_status', |
|
161 | + esc_html__('Event Status', 'event_espresso'), |
|
162 | + false, |
|
163 | + 'draft', |
|
164 | + $this->_custom_stati |
|
165 | + ), |
|
166 | + 'password' => new EE_Password_Field( |
|
167 | + 'post_password', |
|
168 | + esc_html__('Password', 'event_espresso'), |
|
169 | + false, |
|
170 | + '', |
|
171 | + array( |
|
172 | + 'EVT_desc', |
|
173 | + 'EVT_short_desc', |
|
174 | + 'EVT_display_desc', |
|
175 | + 'EVT_display_ticket_selector', |
|
176 | + 'EVT_visible_on', |
|
177 | + 'EVT_additional_limit', |
|
178 | + 'EVT_default_registration_status', |
|
179 | + 'EVT_member_only', |
|
180 | + 'EVT_phone', |
|
181 | + 'EVT_allow_overflow', |
|
182 | + 'EVT_timezone_string', |
|
183 | + 'EVT_external_URL', |
|
184 | + 'EVT_donations' |
|
185 | + ) |
|
186 | + ) |
|
187 | + ), |
|
188 | + 'Event_Meta' => array( |
|
189 | + 'EVTM_ID' => new EE_DB_Only_Float_Field( |
|
190 | + 'EVTM_ID', |
|
191 | + esc_html__('Event Meta Row ID', 'event_espresso'), |
|
192 | + false |
|
193 | + ), |
|
194 | + 'EVT_ID_fk' => new EE_DB_Only_Int_Field( |
|
195 | + 'EVT_ID', |
|
196 | + esc_html__('Foreign key to Event ID from Event Meta table', 'event_espresso'), |
|
197 | + false |
|
198 | + ), |
|
199 | + 'EVT_display_desc' => new EE_Boolean_Field( |
|
200 | + 'EVT_display_desc', |
|
201 | + esc_html__('Display Description Flag', 'event_espresso'), |
|
202 | + false, |
|
203 | + true |
|
204 | + ), |
|
205 | + 'EVT_display_ticket_selector' => new EE_Boolean_Field( |
|
206 | + 'EVT_display_ticket_selector', |
|
207 | + esc_html__('Display Ticket Selector Flag', 'event_espresso'), |
|
208 | + false, |
|
209 | + true |
|
210 | + ), |
|
211 | + 'EVT_visible_on' => new EE_Datetime_Field( |
|
212 | + 'EVT_visible_on', |
|
213 | + esc_html__('Event Visible Date', 'event_espresso'), |
|
214 | + true, |
|
215 | + EE_Datetime_Field::now |
|
216 | + ), |
|
217 | + 'EVT_additional_limit' => new EE_Integer_Field( |
|
218 | + 'EVT_additional_limit', |
|
219 | + esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
220 | + true, |
|
221 | + self::$_default_additional_limit |
|
222 | + ), |
|
223 | + 'EVT_default_registration_status' => new EE_Enum_Text_Field( |
|
224 | + 'EVT_default_registration_status', |
|
225 | + esc_html__('Default Registration Status on this Event', 'event_espresso'), |
|
226 | + false, |
|
227 | + EEM_Event::$_default_reg_status, |
|
228 | + EEM_Registration::reg_status_array() |
|
229 | + ), |
|
230 | + 'EVT_member_only' => new EE_Boolean_Field( |
|
231 | + 'EVT_member_only', |
|
232 | + esc_html__('Member-Only Event Flag', 'event_espresso'), |
|
233 | + false, |
|
234 | + false |
|
235 | + ), |
|
236 | + 'EVT_phone' => new EE_Plain_Text_Field( |
|
237 | + 'EVT_phone', |
|
238 | + esc_html__('Event Phone Number', 'event_espresso'), |
|
239 | + false, |
|
240 | + '' |
|
241 | + ), |
|
242 | + 'EVT_allow_overflow' => new EE_Boolean_Field( |
|
243 | + 'EVT_allow_overflow', |
|
244 | + esc_html__('Allow Overflow on Event', 'event_espresso'), |
|
245 | + false, |
|
246 | + false |
|
247 | + ), |
|
248 | + 'EVT_timezone_string' => new EE_Plain_Text_Field( |
|
249 | + 'EVT_timezone_string', |
|
250 | + esc_html__('Timezone (name) for Event times', 'event_espresso'), |
|
251 | + false, |
|
252 | + '' |
|
253 | + ), |
|
254 | + 'EVT_external_URL' => new EE_Plain_Text_Field( |
|
255 | + 'EVT_external_URL', |
|
256 | + esc_html__('URL of Event Page if hosted elsewhere', 'event_espresso'), |
|
257 | + true |
|
258 | + ), |
|
259 | + 'EVT_donations' => new EE_Boolean_Field( |
|
260 | + 'EVT_donations', |
|
261 | + esc_html__('Accept Donations?', 'event_espresso'), |
|
262 | + false, |
|
263 | + false |
|
264 | + ), |
|
265 | + ), |
|
266 | + ); |
|
267 | + $this->_model_relations = array( |
|
268 | + 'Registration' => new EE_Has_Many_Relation(), |
|
269 | + 'Datetime' => new EE_Has_Many_Relation(), |
|
270 | + 'Question_Group' => new EE_HABTM_Relation('Event_Question_Group'), |
|
271 | + 'Event_Question_Group' => new EE_Has_Many_Relation(), |
|
272 | + 'Venue' => new EE_HABTM_Relation('Event_Venue'), |
|
273 | + 'Term_Relationship' => new EE_Has_Many_Relation(), |
|
274 | + 'Term_Taxonomy' => new EE_HABTM_Relation('Term_Relationship'), |
|
275 | + 'Message_Template_Group' => new EE_HABTM_Relation('Event_Message_Template'), |
|
276 | + 'Attendee' => new EE_HABTM_Relation('Registration'), |
|
277 | + 'WP_User' => new EE_Belongs_To_Relation(), |
|
278 | + ); |
|
279 | + // this model is generally available for reading |
|
280 | + $this->_cap_restriction_generators[ EEM_Base::caps_read ] = new EE_Restriction_Generator_Public(); |
|
281 | + $this->model_chain_to_password = ''; |
|
282 | + parent::__construct($timezone); |
|
283 | + } |
|
284 | + |
|
285 | + |
|
286 | + |
|
287 | + /** |
|
288 | + * @param string $default_reg_status |
|
289 | + */ |
|
290 | + public static function set_default_reg_status($default_reg_status) |
|
291 | + { |
|
292 | + self::$_default_reg_status = $default_reg_status; |
|
293 | + // if EEM_Event has already been instantiated, |
|
294 | + // then we need to reset the `EVT_default_reg_status` field to use the new default. |
|
295 | + if (self::$_instance instanceof EEM_Event) { |
|
296 | + $default_reg_status = new EE_Enum_Text_Field( |
|
297 | + 'EVT_default_registration_status', |
|
298 | + esc_html__('Default Registration Status on this Event', 'event_espresso'), |
|
299 | + false, |
|
300 | + $default_reg_status, |
|
301 | + EEM_Registration::reg_status_array() |
|
302 | + ); |
|
303 | + $default_reg_status->_construct_finalize( |
|
304 | + 'Event_Meta', |
|
305 | + 'EVT_default_registration_status', |
|
306 | + 'EEM_Event' |
|
307 | + ); |
|
308 | + self::$_instance->_fields['Event_Meta']['EVT_default_registration_status'] = $default_reg_status; |
|
309 | + } |
|
310 | + } |
|
311 | + |
|
312 | + |
|
313 | + /** |
|
314 | + * Used to override the default for the additional limit field. |
|
315 | + * @param $additional_limit |
|
316 | + */ |
|
317 | + public static function set_default_additional_limit($additional_limit) |
|
318 | + { |
|
319 | + self::$_default_additional_limit = (int) $additional_limit; |
|
320 | + if (self::$_instance instanceof EEM_Event) { |
|
321 | + self::$_instance->_fields['Event_Meta']['EVT_additional_limit'] = new EE_Integer_Field( |
|
322 | + 'EVT_additional_limit', |
|
323 | + esc_html__('Limit of Additional Registrations on Same Transaction', 'event_espresso'), |
|
324 | + true, |
|
325 | + self::$_default_additional_limit |
|
326 | + ); |
|
327 | + self::$_instance->_fields['Event_Meta']['EVT_additional_limit']->_construct_finalize( |
|
328 | + 'Event_Meta', |
|
329 | + 'EVT_additional_limit', |
|
330 | + 'EEM_Event' |
|
331 | + ); |
|
332 | + } |
|
333 | + } |
|
334 | + |
|
335 | + |
|
336 | + /** |
|
337 | + * Return what is currently set as the default additional limit for the event. |
|
338 | + * @return int |
|
339 | + */ |
|
340 | + public static function get_default_additional_limit() |
|
341 | + { |
|
342 | + return apply_filters('FHEE__EEM_Event__get_default_additional_limit', self::$_default_additional_limit); |
|
343 | + } |
|
344 | + |
|
345 | + |
|
346 | + /** |
|
347 | + * get_question_groups |
|
348 | + * |
|
349 | + * @return array |
|
350 | + * @throws \EE_Error |
|
351 | + */ |
|
352 | + public function get_all_question_groups() |
|
353 | + { |
|
354 | + return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
355 | + array( |
|
356 | + array('QSG_deleted' => false), |
|
357 | + 'order_by' => array('QSG_order' => 'ASC'), |
|
358 | + ) |
|
359 | + ); |
|
360 | + } |
|
361 | + |
|
362 | + |
|
363 | + |
|
364 | + /** |
|
365 | + * get_question_groups |
|
366 | + * |
|
367 | + * @param int $EVT_ID |
|
368 | + * @return array|bool |
|
369 | + * @throws \EE_Error |
|
370 | + */ |
|
371 | + public function get_all_event_question_groups($EVT_ID = 0) |
|
372 | + { |
|
373 | + if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
374 | + EE_Error::add_error( |
|
375 | + esc_html__( |
|
376 | + 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
377 | + 'event_espresso' |
|
378 | + ), |
|
379 | + __FILE__, |
|
380 | + __FUNCTION__, |
|
381 | + __LINE__ |
|
382 | + ); |
|
383 | + return false; |
|
384 | + } |
|
385 | + return EE_Registry::instance()->load_model('Event_Question_Group')->get_all( |
|
386 | + array( |
|
387 | + array('EVT_ID' => $EVT_ID), |
|
388 | + ) |
|
389 | + ); |
|
390 | + } |
|
391 | + |
|
392 | + |
|
393 | + /** |
|
394 | + * get_question_groups |
|
395 | + * |
|
396 | + * @param int $EVT_ID |
|
397 | + * @param boolean $for_primary_attendee |
|
398 | + * @return array|bool |
|
399 | + * @throws EE_Error |
|
400 | + * @throws InvalidArgumentException |
|
401 | + * @throws ReflectionException |
|
402 | + * @throws InvalidDataTypeException |
|
403 | + * @throws InvalidInterfaceException |
|
404 | + */ |
|
405 | + public function get_event_question_groups($EVT_ID = 0, $for_primary_attendee = true) |
|
406 | + { |
|
407 | + if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
408 | + EE_Error::add_error( |
|
409 | + esc_html__( |
|
410 | + // @codingStandardsIgnoreStart |
|
411 | + 'An error occurred. No Event Question Groups could be retrieved because an Event ID was not received.', |
|
412 | + // @codingStandardsIgnoreEnd |
|
413 | + 'event_espresso' |
|
414 | + ), |
|
415 | + __FILE__, |
|
416 | + __FUNCTION__, |
|
417 | + __LINE__ |
|
418 | + ); |
|
419 | + return false; |
|
420 | + } |
|
421 | + $query_params = [ |
|
422 | + [ |
|
423 | + 'EVT_ID' => $EVT_ID, |
|
424 | + EEM_Event_Question_Group::instance()->fieldNameForContext($for_primary_attendee) => true |
|
425 | + ] |
|
426 | + ]; |
|
427 | + if ($for_primary_attendee) { |
|
428 | + $query_params[0]['EQG_primary'] = true; |
|
429 | + } else { |
|
430 | + $query_params[0]['EQG_additional'] = true; |
|
431 | + } |
|
432 | + return EE_Registry::instance()->load_model('Event_Question_Group')->get_all($query_params); |
|
433 | + } |
|
434 | + |
|
435 | + |
|
436 | + /** |
|
437 | + * get_question_groups |
|
438 | + * |
|
439 | + * @param int $EVT_ID |
|
440 | + * @param EE_Registration $registration |
|
441 | + * @return array|bool |
|
442 | + * @throws EE_Error |
|
443 | + * @throws InvalidArgumentException |
|
444 | + * @throws InvalidDataTypeException |
|
445 | + * @throws InvalidInterfaceException |
|
446 | + * @throws ReflectionException |
|
447 | + */ |
|
448 | + public function get_question_groups_for_event($EVT_ID, EE_Registration $registration) |
|
449 | + { |
|
450 | + if (! isset($EVT_ID) || ! absint($EVT_ID)) { |
|
451 | + EE_Error::add_error( |
|
452 | + esc_html__( |
|
453 | + 'An error occurred. No Question Groups could be retrieved because an Event ID was not received.', |
|
454 | + 'event_espresso' |
|
455 | + ), |
|
456 | + __FILE__, |
|
457 | + __FUNCTION__, |
|
458 | + __LINE__ |
|
459 | + ); |
|
460 | + return false; |
|
461 | + } |
|
462 | + return EE_Registry::instance()->load_model('Question_Group')->get_all( |
|
463 | + [ |
|
464 | + [ |
|
465 | + 'Event_Question_Group.EVT_ID' => $EVT_ID, |
|
466 | + 'Event_Question_Group.' |
|
467 | + . EEM_Event_Question_Group::instance()->fieldNameForContext( |
|
468 | + $registration->is_primary_registrant() |
|
469 | + ) => true |
|
470 | + ], |
|
471 | + 'order_by' => ['QSG_order' => 'ASC'], |
|
472 | + ] |
|
473 | + ); |
|
474 | + } |
|
475 | + |
|
476 | + |
|
477 | + |
|
478 | + /** |
|
479 | + * get_question_target_db_column |
|
480 | + * |
|
481 | + * @param string $QSG_IDs csv list of $QSG IDs |
|
482 | + * @return array|bool |
|
483 | + * @throws \EE_Error |
|
484 | + */ |
|
485 | + public function get_questions_in_groups($QSG_IDs = '') |
|
486 | + { |
|
487 | + if (empty($QSG_IDs)) { |
|
488 | + EE_Error::add_error( |
|
489 | + esc_html__('An error occurred. No Question Group IDs were received.', 'event_espresso'), |
|
490 | + __FILE__, |
|
491 | + __FUNCTION__, |
|
492 | + __LINE__ |
|
493 | + ); |
|
494 | + return false; |
|
495 | + } |
|
496 | + return EE_Registry::instance()->load_model('Question')->get_all( |
|
497 | + array( |
|
498 | + array( |
|
499 | + 'Question_Group.QSG_ID' => array('IN', $QSG_IDs), |
|
500 | + 'QST_deleted' => false, |
|
501 | + 'QST_admin_only' => is_admin(), |
|
502 | + ), |
|
503 | + 'order_by' => 'QST_order', |
|
504 | + ) |
|
505 | + ); |
|
506 | + } |
|
507 | + |
|
508 | + |
|
509 | + |
|
510 | + /** |
|
511 | + * get_options_for_question |
|
512 | + * |
|
513 | + * @param string $QST_IDs csv list of $QST IDs |
|
514 | + * @return array|bool |
|
515 | + * @throws \EE_Error |
|
516 | + */ |
|
517 | + public function get_options_for_question($QST_IDs) |
|
518 | + { |
|
519 | + if (empty($QST_IDs)) { |
|
520 | + EE_Error::add_error( |
|
521 | + esc_html__('An error occurred. No Question IDs were received.', 'event_espresso'), |
|
522 | + __FILE__, |
|
523 | + __FUNCTION__, |
|
524 | + __LINE__ |
|
525 | + ); |
|
526 | + return false; |
|
527 | + } |
|
528 | + return EE_Registry::instance()->load_model('Question_Option')->get_all( |
|
529 | + array( |
|
530 | + array( |
|
531 | + 'Question.QST_ID' => array('IN', $QST_IDs), |
|
532 | + 'QSO_deleted' => false, |
|
533 | + ), |
|
534 | + 'order_by' => 'QSO_ID', |
|
535 | + ) |
|
536 | + ); |
|
537 | + } |
|
538 | + |
|
539 | + |
|
540 | + |
|
541 | + |
|
542 | + |
|
543 | + |
|
544 | + |
|
545 | + /** |
|
546 | + * Gets all events that are published |
|
547 | + * and have event start time earlier than now and an event end time later than now |
|
548 | + * |
|
549 | + * @param array $query_params An array of query params to further filter on |
|
550 | + * (note that status and DTT_EVT_start and DTT_EVT_end will be overridden) |
|
551 | + * @param bool $count whether to return the count or not (default FALSE) |
|
552 | + * @return EE_Event[]|int |
|
553 | + * @throws \EE_Error |
|
554 | + */ |
|
555 | + public function get_active_events($query_params, $count = false) |
|
556 | + { |
|
557 | + if (array_key_exists(0, $query_params)) { |
|
558 | + $where_params = $query_params[0]; |
|
559 | + unset($query_params[0]); |
|
560 | + } else { |
|
561 | + $where_params = array(); |
|
562 | + } |
|
563 | + // if we have count make sure we don't include group by |
|
564 | + if ($count && isset($query_params['group_by'])) { |
|
565 | + unset($query_params['group_by']); |
|
566 | + } |
|
567 | + // let's add specific query_params for active_events |
|
568 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
569 | + $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
570 | + // if already have where params for DTT_EVT_start or DTT_EVT_end then append these conditions |
|
571 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
572 | + $where_params['Datetime.DTT_EVT_start******'] = array( |
|
573 | + '<', |
|
574 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
575 | + ); |
|
576 | + } else { |
|
577 | + $where_params['Datetime.DTT_EVT_start'] = array( |
|
578 | + '<', |
|
579 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
580 | + ); |
|
581 | + } |
|
582 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
583 | + $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
584 | + '>', |
|
585 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
586 | + ); |
|
587 | + } else { |
|
588 | + $where_params['Datetime.DTT_EVT_end'] = array( |
|
589 | + '>', |
|
590 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
591 | + ); |
|
592 | + } |
|
593 | + $query_params[0] = $where_params; |
|
594 | + // don't use $query_params with count() |
|
595 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
596 | + return $count |
|
597 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
598 | + : $this->get_all($query_params); |
|
599 | + } |
|
600 | + |
|
601 | + |
|
602 | + |
|
603 | + /** |
|
604 | + * get all events that are published and have an event start time later than now |
|
605 | + * |
|
606 | + * @param array $query_params An array of query params to further filter on |
|
607 | + * (Note that status and DTT_EVT_start will be overridden) |
|
608 | + * @param bool $count whether to return the count or not (default FALSE) |
|
609 | + * @return EE_Event[]|int |
|
610 | + * @throws \EE_Error |
|
611 | + */ |
|
612 | + public function get_upcoming_events($query_params, $count = false) |
|
613 | + { |
|
614 | + if (array_key_exists(0, $query_params)) { |
|
615 | + $where_params = $query_params[0]; |
|
616 | + unset($query_params[0]); |
|
617 | + } else { |
|
618 | + $where_params = array(); |
|
619 | + } |
|
620 | + // if we have count make sure we don't include group by |
|
621 | + if ($count && isset($query_params['group_by'])) { |
|
622 | + unset($query_params['group_by']); |
|
623 | + } |
|
624 | + // let's add specific query_params for active_events |
|
625 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
626 | + // we need to pull events with a status of publish and sold_out |
|
627 | + $event_status = array('publish', EEM_Event::sold_out); |
|
628 | + // check if the user can read private events and if so add the 'private status to the were params' |
|
629 | + if (EE_Registry::instance()->CAP->current_user_can('ee_read_private_events', 'get_upcoming_events')) { |
|
630 | + $event_status[] = 'private'; |
|
631 | + } |
|
632 | + $where_params['status'] = array('IN', $event_status); |
|
633 | + // if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
|
634 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
635 | + $where_params['Datetime.DTT_EVT_start*****'] = array( |
|
636 | + '>', |
|
637 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
638 | + ); |
|
639 | + } else { |
|
640 | + $where_params['Datetime.DTT_EVT_start'] = array( |
|
641 | + '>', |
|
642 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_start'), |
|
643 | + ); |
|
644 | + } |
|
645 | + $query_params[0] = $where_params; |
|
646 | + // don't use $query_params with count() |
|
647 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
648 | + return $count |
|
649 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
650 | + : $this->get_all($query_params); |
|
651 | + } |
|
652 | + |
|
653 | + |
|
654 | + |
|
655 | + /** |
|
656 | + * Gets all events that are published |
|
657 | + * and have an event end time later than now |
|
658 | + * |
|
659 | + * @param array $query_params An array of query params to further filter on |
|
660 | + * (note that status and DTT_EVT_end will be overridden) |
|
661 | + * @param bool $count whether to return the count or not (default FALSE) |
|
662 | + * @return EE_Event[]|int |
|
663 | + * @throws \EE_Error |
|
664 | + */ |
|
665 | + public function get_active_and_upcoming_events($query_params, $count = false) |
|
666 | + { |
|
667 | + if (array_key_exists(0, $query_params)) { |
|
668 | + $where_params = $query_params[0]; |
|
669 | + unset($query_params[0]); |
|
670 | + } else { |
|
671 | + $where_params = array(); |
|
672 | + } |
|
673 | + // if we have count make sure we don't include group by |
|
674 | + if ($count && isset($query_params['group_by'])) { |
|
675 | + unset($query_params['group_by']); |
|
676 | + } |
|
677 | + // let's add specific query_params for active_events |
|
678 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
679 | + $where_params['status'] = array('IN', array('publish', EEM_Event::sold_out)); |
|
680 | + // add where params for DTT_EVT_end |
|
681 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
682 | + $where_params['Datetime.DTT_EVT_end*****'] = array( |
|
683 | + '>', |
|
684 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
685 | + ); |
|
686 | + } else { |
|
687 | + $where_params['Datetime.DTT_EVT_end'] = array( |
|
688 | + '>', |
|
689 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
690 | + ); |
|
691 | + } |
|
692 | + $query_params[0] = $where_params; |
|
693 | + // don't use $query_params with count() |
|
694 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
695 | + return $count |
|
696 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
697 | + : $this->get_all($query_params); |
|
698 | + } |
|
699 | + |
|
700 | + |
|
701 | + |
|
702 | + /** |
|
703 | + * This only returns events that are expired. |
|
704 | + * They may still be published but all their datetimes have expired. |
|
705 | + * |
|
706 | + * @param array $query_params An array of query params to further filter on |
|
707 | + * (note that status and DTT_EVT_end will be overridden) |
|
708 | + * @param bool $count whether to return the count or not (default FALSE) |
|
709 | + * @return EE_Event[]|int |
|
710 | + * @throws \EE_Error |
|
711 | + */ |
|
712 | + public function get_expired_events($query_params, $count = false) |
|
713 | + { |
|
714 | + $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
715 | + // if we have count make sure we don't include group by |
|
716 | + if ($count && isset($query_params['group_by'])) { |
|
717 | + unset($query_params['group_by']); |
|
718 | + } |
|
719 | + // let's add specific query_params for active_events |
|
720 | + // keep in mind this will override any sent status in the query AND any date queries. |
|
721 | + if (isset($where_params['status'])) { |
|
722 | + unset($where_params['status']); |
|
723 | + } |
|
724 | + $exclude_query = $query_params; |
|
725 | + if (isset($exclude_query[0])) { |
|
726 | + unset($exclude_query[0]); |
|
727 | + } |
|
728 | + $exclude_query[0] = array( |
|
729 | + 'Datetime.DTT_EVT_end' => array( |
|
730 | + '>', |
|
731 | + EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end'), |
|
732 | + ), |
|
733 | + ); |
|
734 | + // first get all events that have datetimes where its not expired. |
|
735 | + $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Event_CPT.ID'); |
|
736 | + $event_ids = array_keys($event_ids); |
|
737 | + // if we have any additional query_params, let's add them to the 'AND' condition |
|
738 | + $and_condition = array( |
|
739 | + 'Datetime.DTT_EVT_end' => array('<', EEM_Datetime::instance()->current_time_for_query('DTT_EVT_end')), |
|
740 | + 'EVT_ID' => array('NOT IN', $event_ids), |
|
741 | + ); |
|
742 | + if (isset($where_params['OR'])) { |
|
743 | + $and_condition['OR'] = $where_params['OR']; |
|
744 | + unset($where_params['OR']); |
|
745 | + } |
|
746 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
747 | + $and_condition['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
748 | + unset($where_params['Datetime.DTT_EVT_end']); |
|
749 | + } |
|
750 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
751 | + $and_condition['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
752 | + unset($where_params['Datetime.DTT_EVT_start']); |
|
753 | + } |
|
754 | + // merge remaining $where params with the and conditions. |
|
755 | + $where_params['AND'] = array_merge($and_condition, $where_params); |
|
756 | + $query_params[0] = $where_params; |
|
757 | + // don't use $query_params with count() |
|
758 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
759 | + return $count |
|
760 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
761 | + : $this->get_all($query_params); |
|
762 | + } |
|
763 | + |
|
764 | + |
|
765 | + |
|
766 | + /** |
|
767 | + * This basically just returns the events that do not have the publish status. |
|
768 | + * |
|
769 | + * @param array $query_params An array of query params to further filter on |
|
770 | + * (note that status will be overwritten) |
|
771 | + * @param boolean $count whether to return the count or not (default FALSE) |
|
772 | + * @return EE_Event[]|int |
|
773 | + * @throws \EE_Error |
|
774 | + */ |
|
775 | + public function get_inactive_events($query_params, $count = false) |
|
776 | + { |
|
777 | + $where_params = isset($query_params[0]) ? $query_params[0] : array(); |
|
778 | + // let's add in specific query_params for inactive events. |
|
779 | + if (isset($where_params['status'])) { |
|
780 | + unset($where_params['status']); |
|
781 | + } |
|
782 | + // if we have count make sure we don't include group by |
|
783 | + if ($count && isset($query_params['group_by'])) { |
|
784 | + unset($query_params['group_by']); |
|
785 | + } |
|
786 | + // if we have any additional query_params, let's add them to the 'AND' condition |
|
787 | + $where_params['AND']['status'] = array('!=', 'publish'); |
|
788 | + if (isset($where_params['OR'])) { |
|
789 | + $where_params['AND']['OR'] = $where_params['OR']; |
|
790 | + unset($where_params['OR']); |
|
791 | + } |
|
792 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
793 | + $where_params['AND']['Datetime.DTT_EVT_end****'] = $where_params['Datetime.DTT_EVT_end']; |
|
794 | + unset($where_params['Datetime.DTT_EVT_end']); |
|
795 | + } |
|
796 | + if (isset($where_params['Datetime.DTT_EVT_start'])) { |
|
797 | + $where_params['AND']['Datetime.DTT_EVT_start'] = $where_params['Datetime.DTT_EVT_start']; |
|
798 | + unset($where_params['Datetime.DTT_EVT_start']); |
|
799 | + } |
|
800 | + $query_params[0] = $where_params; |
|
801 | + // don't use $query_params with count() |
|
802 | + // because we don't want to include additional query clauses like "GROUP BY" |
|
803 | + return $count |
|
804 | + ? $this->count(array($where_params), 'EVT_ID', true) |
|
805 | + : $this->get_all($query_params); |
|
806 | + } |
|
807 | + |
|
808 | + |
|
809 | + |
|
810 | + /** |
|
811 | + * This is just injecting into the parent add_relationship_to so we do special handling on price relationships |
|
812 | + * because we don't want to override any existing global default prices but instead insert NEW prices that get |
|
813 | + * attached to the event. See parent for param descriptions |
|
814 | + * |
|
815 | + * @param $id_or_obj |
|
816 | + * @param $other_model_id_or_obj |
|
817 | + * @param string $relationName |
|
818 | + * @param array $where_query |
|
819 | + * @return EE_Base_Class |
|
820 | + * @throws EE_Error |
|
821 | + */ |
|
822 | + public function add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query = array()) |
|
823 | + { |
|
824 | + if ($relationName === 'Price') { |
|
825 | + // let's get the PRC object for the given ID to make sure that we aren't dealing with a default |
|
826 | + $prc_chk = $this->get_related_model_obj($relationName)->ensure_is_obj($other_model_id_or_obj); |
|
827 | + // if EVT_ID = 0, then this is a default |
|
828 | + if ((int) $prc_chk->get('EVT_ID') === 0) { |
|
829 | + // let's set the prc_id as 0 so we force an insert on the add_relation_to carried out by relation |
|
830 | + $prc_chk->set('PRC_ID', 0); |
|
831 | + } |
|
832 | + // run parent |
|
833 | + return parent::add_relationship_to($id_or_obj, $prc_chk, $relationName, $where_query); |
|
834 | + } |
|
835 | + // otherwise carry on as normal |
|
836 | + return parent::add_relationship_to($id_or_obj, $other_model_id_or_obj, $relationName, $where_query); |
|
837 | + } |
|
838 | + |
|
839 | + |
|
840 | + |
|
841 | + /******************** DEPRECATED METHODS ********************/ |
|
842 | + |
|
843 | + |
|
844 | + |
|
845 | + /** |
|
846 | + * _get_question_target_db_column |
|
847 | + * |
|
848 | + * @deprecated as of 4.8.32.rc.001. Instead consider using |
|
849 | + * EE_Registration_Custom_Questions_Form located in |
|
850 | + * admin_pages/registrations/form_sections/EE_Registration_Custom_Questions_Form.form.php |
|
851 | + * @access public |
|
852 | + * @param EE_Registration $registration (so existing answers for registration are included) |
|
853 | + * @param int $EVT_ID so all question groups are included for event (not just answers from |
|
854 | + * registration). |
|
855 | + * @throws EE_Error |
|
856 | + * @return array |
|
857 | + */ |
|
858 | + public function assemble_array_of_groups_questions_and_options(EE_Registration $registration, $EVT_ID = 0) |
|
859 | + { |
|
860 | + if (empty($EVT_ID)) { |
|
861 | + throw new EE_Error(esc_html__( |
|
862 | + 'An error occurred. No EVT_ID is included. Needed to know which question groups to retrieve.', |
|
863 | + 'event_espresso' |
|
864 | + )); |
|
865 | + } |
|
866 | + $questions = array(); |
|
867 | + // get all question groups for event |
|
868 | + $qgs = $this->get_question_groups_for_event($EVT_ID, $registration); |
|
869 | + if (! empty($qgs)) { |
|
870 | + foreach ($qgs as $qg) { |
|
871 | + $qsts = $qg->questions(); |
|
872 | + $questions[ $qg->ID() ] = $qg->model_field_array(); |
|
873 | + $questions[ $qg->ID() ]['QSG_questions'] = array(); |
|
874 | + foreach ($qsts as $qst) { |
|
875 | + if ($qst->is_system_question()) { |
|
876 | + continue; |
|
877 | + } |
|
878 | + $answer = EEM_Answer::instance()->get_one(array( |
|
879 | + array( |
|
880 | + 'QST_ID' => $qst->ID(), |
|
881 | + 'REG_ID' => $registration->ID(), |
|
882 | + ), |
|
883 | + )); |
|
884 | + $answer = $answer instanceof EE_Answer ? $answer : EEM_Answer::instance()->create_default_object(); |
|
885 | + $qst_name = $qstn_id = $qst->ID(); |
|
886 | + $ans_id = $answer->ID(); |
|
887 | + $qst_name = ! empty($ans_id) ? '[' . $qst_name . '][' . $ans_id . ']' : '[' . $qst_name . ']'; |
|
888 | + $input_name = ''; |
|
889 | + $input_id = sanitize_key($qst->display_text()); |
|
890 | + $input_class = ''; |
|
891 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ] = $qst->model_field_array(); |
|
892 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_name'] = 'qstn' |
|
893 | + . $input_name |
|
894 | + . $qst_name; |
|
895 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_id'] = $input_id . '-' . $qstn_id; |
|
896 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_input_class'] = $input_class; |
|
897 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'] = array(); |
|
898 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['qst_obj'] = $qst; |
|
899 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['ans_obj'] = $answer; |
|
900 | + // leave responses as-is, don't convert stuff into html entities please! |
|
901 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['htmlentities'] = false; |
|
902 | + if ($qst->type() == 'RADIO_BTN' || $qst->type() == 'CHECKBOX' || $qst->type() == 'DROPDOWN') { |
|
903 | + $QSOs = $qst->options(true, $answer->value()); |
|
904 | + if (is_array($QSOs)) { |
|
905 | + foreach ($QSOs as $QSO_ID => $QSO) { |
|
906 | + $questions[ $qg->ID() ]['QSG_questions'][ $qst->ID() ]['QST_options'][ $QSO_ID ] = $QSO->model_field_array(); |
|
907 | + } |
|
908 | + } |
|
909 | + } |
|
910 | + } |
|
911 | + } |
|
912 | + } |
|
913 | + return $questions; |
|
914 | + } |
|
915 | + |
|
916 | + |
|
917 | + /** |
|
918 | + * @param mixed $cols_n_values either an array of where each key is the name of a field, and the value is its value |
|
919 | + * or an stdClass where each property is the name of a column, |
|
920 | + * @return EE_Base_Class |
|
921 | + * @throws \EE_Error |
|
922 | + */ |
|
923 | + public function instantiate_class_from_array_or_object($cols_n_values) |
|
924 | + { |
|
925 | + $classInstance = parent::instantiate_class_from_array_or_object($cols_n_values); |
|
926 | + if ($classInstance instanceof EE_Event) { |
|
927 | + // events have their timezone defined in the DB, so use it immediately |
|
928 | + $this->set_timezone($classInstance->get_timezone()); |
|
929 | + } |
|
930 | + return $classInstance; |
|
931 | + } |
|
932 | 932 | } |