@@ -17,216 +17,214 @@ |
||
17 | 17 | class TableManager extends \EE_Base |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var TableAnalysis $table_analysis |
|
22 | - */ |
|
23 | - private $table_analysis; |
|
24 | - |
|
25 | - |
|
26 | - |
|
27 | - /** |
|
28 | - * TableManager constructor. |
|
29 | - * |
|
30 | - * @param TableAnalysis $TableAnalysis |
|
31 | - */ |
|
32 | - public function __construct(TableAnalysis $TableAnalysis) |
|
33 | - { |
|
34 | - $this->table_analysis = $TableAnalysis; |
|
35 | - } |
|
36 | - |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * Gets the injected table analyzer, or throws an exception |
|
41 | - * |
|
42 | - * @return TableAnalysis |
|
43 | - * @throws \EE_Error |
|
44 | - */ |
|
45 | - protected function getTableAnalysis() |
|
46 | - { |
|
47 | - if ($this->table_analysis instanceof TableAnalysis) { |
|
48 | - return $this->table_analysis; |
|
49 | - } else { |
|
50 | - throw new \EE_Error( |
|
51 | - sprintf( |
|
52 | - __('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
53 | - get_class($this) |
|
54 | - ) |
|
55 | - ); |
|
56 | - } |
|
57 | - } |
|
58 | - |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * @param string $table_name which can optionally start with $wpdb->prefix or not |
|
63 | - * @param string $column_name |
|
64 | - * @param string $column_info |
|
65 | - * @return bool|false|int |
|
66 | - */ |
|
67 | - public function addColumn($table_name, $column_name, $column_info = 'INT UNSIGNED NOT NULL') |
|
68 | - { |
|
69 | - if (apply_filters('FHEE__EEH_Activation__add_column_if_it_doesnt_exist__short_circuit', false)) { |
|
70 | - return false; |
|
71 | - } |
|
72 | - global $wpdb; |
|
73 | - $full_table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
74 | - $columns = $this->getTableColumns($table_name); |
|
75 | - if ( ! in_array($column_name, $columns)) { |
|
76 | - $alter_query = "ALTER TABLE {$full_table_name} ADD {$column_name} {$column_info}"; |
|
77 | - return $wpdb->query($alter_query); |
|
78 | - } |
|
79 | - return true; |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - |
|
84 | - /** |
|
85 | - * Gets the name of all columns on the table. $table_name can |
|
86 | - * optionally start with $wpdb->prefix or not |
|
87 | - * |
|
88 | - * @global \wpdb $wpdb |
|
89 | - * @param string $table_name |
|
90 | - * @return array |
|
91 | - */ |
|
92 | - public function getTableColumns($table_name) |
|
93 | - { |
|
94 | - global $wpdb; |
|
95 | - $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
96 | - $field_array = array(); |
|
97 | - if ( ! empty($table_name)) { |
|
98 | - $columns = $wpdb->get_results("SHOW COLUMNS FROM {$table_name} "); |
|
99 | - if ($columns !== false) { |
|
100 | - foreach ($columns as $column) { |
|
101 | - $field_array[] = $column->Field; |
|
102 | - } |
|
103 | - } |
|
104 | - } |
|
105 | - return $field_array; |
|
106 | - } |
|
107 | - |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * Drops the specified table from the database. $table_name can |
|
112 | - * optionally start with $wpdb->prefix or not |
|
113 | - * |
|
114 | - * @global \wpdb $wpdb |
|
115 | - * @param string $table_name |
|
116 | - * @return int |
|
117 | - */ |
|
118 | - public function dropTable($table_name) |
|
119 | - { |
|
120 | - global $wpdb; |
|
121 | - if ($this->getTableAnalysis()->tableExists($table_name)) { |
|
122 | - $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
123 | - return $wpdb->query("DROP TABLE IF EXISTS {$table_name}"); |
|
124 | - } |
|
125 | - return 0; |
|
126 | - } |
|
127 | - |
|
128 | - |
|
129 | - |
|
130 | - /** |
|
131 | - * Drops all the tables mentioned in a single MYSQL query. Double-checks |
|
132 | - * each table name provided has a wpdb prefix attached, and that it exists. |
|
133 | - * Returns the list actually deleted |
|
134 | - * |
|
135 | - * @global WPDB $wpdb |
|
136 | - * @param array $table_names |
|
137 | - * @return array of table names which we deleted |
|
138 | - */ |
|
139 | - public function dropTables($table_names) |
|
140 | - { |
|
141 | - $tables_to_delete = array(); |
|
142 | - foreach ($table_names as $table_name) { |
|
143 | - $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
144 | - if ($this->getTableAnalysis()->tableExists($table_name)) { |
|
145 | - $tables_to_delete[] = $table_name; |
|
146 | - } |
|
147 | - } |
|
148 | - if( ! empty( $tables_to_delete ) ) { |
|
149 | - global $wpdb; |
|
150 | - $wpdb->query('DROP TABLE ' . implode(', ', $tables_to_delete)); |
|
151 | - } |
|
152 | - return $tables_to_delete; |
|
153 | - } |
|
154 | - |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * Drops the specified index from the specified table. $table_name can |
|
159 | - * optionally start with $wpdb->prefix or not |
|
160 | - |
|
161 | - * |
|
20 | + /** |
|
21 | + * @var TableAnalysis $table_analysis |
|
22 | + */ |
|
23 | + private $table_analysis; |
|
24 | + |
|
25 | + |
|
26 | + |
|
27 | + /** |
|
28 | + * TableManager constructor. |
|
29 | + * |
|
30 | + * @param TableAnalysis $TableAnalysis |
|
31 | + */ |
|
32 | + public function __construct(TableAnalysis $TableAnalysis) |
|
33 | + { |
|
34 | + $this->table_analysis = $TableAnalysis; |
|
35 | + } |
|
36 | + |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * Gets the injected table analyzer, or throws an exception |
|
41 | + * |
|
42 | + * @return TableAnalysis |
|
43 | + * @throws \EE_Error |
|
44 | + */ |
|
45 | + protected function getTableAnalysis() |
|
46 | + { |
|
47 | + if ($this->table_analysis instanceof TableAnalysis) { |
|
48 | + return $this->table_analysis; |
|
49 | + } else { |
|
50 | + throw new \EE_Error( |
|
51 | + sprintf( |
|
52 | + __('Table analysis class on class %1$s is not set properly.', 'event_espresso'), |
|
53 | + get_class($this) |
|
54 | + ) |
|
55 | + ); |
|
56 | + } |
|
57 | + } |
|
58 | + |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * @param string $table_name which can optionally start with $wpdb->prefix or not |
|
63 | + * @param string $column_name |
|
64 | + * @param string $column_info |
|
65 | + * @return bool|false|int |
|
66 | + */ |
|
67 | + public function addColumn($table_name, $column_name, $column_info = 'INT UNSIGNED NOT NULL') |
|
68 | + { |
|
69 | + if (apply_filters('FHEE__EEH_Activation__add_column_if_it_doesnt_exist__short_circuit', false)) { |
|
70 | + return false; |
|
71 | + } |
|
72 | + global $wpdb; |
|
73 | + $full_table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
74 | + $columns = $this->getTableColumns($table_name); |
|
75 | + if ( ! in_array($column_name, $columns)) { |
|
76 | + $alter_query = "ALTER TABLE {$full_table_name} ADD {$column_name} {$column_info}"; |
|
77 | + return $wpdb->query($alter_query); |
|
78 | + } |
|
79 | + return true; |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + |
|
84 | + /** |
|
85 | + * Gets the name of all columns on the table. $table_name can |
|
86 | + * optionally start with $wpdb->prefix or not |
|
87 | + * |
|
88 | + * @global \wpdb $wpdb |
|
89 | + * @param string $table_name |
|
90 | + * @return array |
|
91 | + */ |
|
92 | + public function getTableColumns($table_name) |
|
93 | + { |
|
94 | + global $wpdb; |
|
95 | + $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
96 | + $field_array = array(); |
|
97 | + if ( ! empty($table_name)) { |
|
98 | + $columns = $wpdb->get_results("SHOW COLUMNS FROM {$table_name} "); |
|
99 | + if ($columns !== false) { |
|
100 | + foreach ($columns as $column) { |
|
101 | + $field_array[] = $column->Field; |
|
102 | + } |
|
103 | + } |
|
104 | + } |
|
105 | + return $field_array; |
|
106 | + } |
|
107 | + |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * Drops the specified table from the database. $table_name can |
|
112 | + * optionally start with $wpdb->prefix or not |
|
113 | + * |
|
114 | + * @global \wpdb $wpdb |
|
115 | + * @param string $table_name |
|
116 | + * @return int |
|
117 | + */ |
|
118 | + public function dropTable($table_name) |
|
119 | + { |
|
120 | + global $wpdb; |
|
121 | + if ($this->getTableAnalysis()->tableExists($table_name)) { |
|
122 | + $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
123 | + return $wpdb->query("DROP TABLE IF EXISTS {$table_name}"); |
|
124 | + } |
|
125 | + return 0; |
|
126 | + } |
|
127 | + |
|
128 | + |
|
129 | + |
|
130 | + /** |
|
131 | + * Drops all the tables mentioned in a single MYSQL query. Double-checks |
|
132 | + * each table name provided has a wpdb prefix attached, and that it exists. |
|
133 | + * Returns the list actually deleted |
|
134 | + * |
|
135 | + * @global WPDB $wpdb |
|
136 | + * @param array $table_names |
|
137 | + * @return array of table names which we deleted |
|
138 | + */ |
|
139 | + public function dropTables($table_names) |
|
140 | + { |
|
141 | + $tables_to_delete = array(); |
|
142 | + foreach ($table_names as $table_name) { |
|
143 | + $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
144 | + if ($this->getTableAnalysis()->tableExists($table_name)) { |
|
145 | + $tables_to_delete[] = $table_name; |
|
146 | + } |
|
147 | + } |
|
148 | + if( ! empty( $tables_to_delete ) ) { |
|
149 | + global $wpdb; |
|
150 | + $wpdb->query('DROP TABLE ' . implode(', ', $tables_to_delete)); |
|
151 | + } |
|
152 | + return $tables_to_delete; |
|
153 | + } |
|
154 | + |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * Drops the specified index from the specified table. $table_name can |
|
159 | + * optionally start with $wpdb->prefix or not |
|
160 | + * |
|
162 | 161 | *@global \wpdb $wpdb |
163 | - * @param string $table_name |
|
164 | - * @param string $index_name |
|
165 | - * @return int |
|
166 | - */ |
|
167 | - public function dropIndex($table_name, $index_name) |
|
168 | - { |
|
169 | - if (apply_filters('FHEE__EEH_Activation__drop_index__short_circuit', false)) { |
|
170 | - return false; |
|
171 | - } |
|
172 | - global $wpdb; |
|
173 | - $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
174 | - $index_exists_query = "SHOW INDEX FROM {$table_name} WHERE Key_name = '{$index_name}'"; |
|
175 | - if ( |
|
176 | - $this->getTableAnalysis()->tableExists($table_name) |
|
177 | - && $wpdb->get_var($index_exists_query) |
|
178 | - === $table_name //using get_var with the $index_exists_query returns the table's name |
|
179 | - ) { |
|
180 | - return $wpdb->query("ALTER TABLE {$table_name} DROP INDEX {$index_name}"); |
|
181 | - } |
|
182 | - return 0; |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - |
|
187 | - /** |
|
188 | - * Just creates the requested table. $table_name can |
|
189 | - * optionally start with $wpdb->prefix or not |
|
190 | - |
|
191 | - * |
|
162 | + * @param string $table_name |
|
163 | + * @param string $index_name |
|
164 | + * @return int |
|
165 | + */ |
|
166 | + public function dropIndex($table_name, $index_name) |
|
167 | + { |
|
168 | + if (apply_filters('FHEE__EEH_Activation__drop_index__short_circuit', false)) { |
|
169 | + return false; |
|
170 | + } |
|
171 | + global $wpdb; |
|
172 | + $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
173 | + $index_exists_query = "SHOW INDEX FROM {$table_name} WHERE Key_name = '{$index_name}'"; |
|
174 | + if ( |
|
175 | + $this->getTableAnalysis()->tableExists($table_name) |
|
176 | + && $wpdb->get_var($index_exists_query) |
|
177 | + === $table_name //using get_var with the $index_exists_query returns the table's name |
|
178 | + ) { |
|
179 | + return $wpdb->query("ALTER TABLE {$table_name} DROP INDEX {$index_name}"); |
|
180 | + } |
|
181 | + return 0; |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * Just creates the requested table. $table_name can |
|
188 | + * optionally start with $wpdb->prefix or not |
|
189 | + * |
|
192 | 190 | *@param string $table_name |
193 | - * @param string $create_sql defining the table's columns and indexes |
|
194 | - * @param string $engine (no need to specify "ENGINE=", that's implied) |
|
195 | - * @return void |
|
196 | - * @throws \EE_Error |
|
197 | - */ |
|
198 | - public function createTable($table_name, $create_sql, $engine = 'MyISAM') |
|
199 | - { |
|
200 | - // does $sql contain valid column information? ( LPT: https://regex101.com/ is great for working out regex patterns ) |
|
201 | - if (preg_match('((((.*?))(,\s))+)', $create_sql, $valid_column_data)) { |
|
202 | - $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
203 | - /** @var \wpdb $wpdb */ |
|
204 | - global $wpdb; |
|
205 | - $SQL = "CREATE TABLE {$table_name} ( {$create_sql} ) ENGINE={$engine} " . $wpdb->get_charset_collate(); |
|
206 | - |
|
207 | - //get $wpdb to echo errors, but buffer them. This way at least WE know an error |
|
208 | - //happened. And then we can choose to tell the end user |
|
209 | - $old_show_errors_policy = $wpdb->show_errors(true); |
|
210 | - $old_error_suppression_policy = $wpdb->suppress_errors(false); |
|
211 | - ob_start(); |
|
212 | - dbDelta($SQL); |
|
213 | - $output = ob_get_contents(); |
|
214 | - ob_end_clean(); |
|
215 | - $wpdb->show_errors($old_show_errors_policy); |
|
216 | - $wpdb->suppress_errors($old_error_suppression_policy); |
|
217 | - if ( ! empty($output)) { |
|
218 | - throw new \EE_Error($output); |
|
219 | - } |
|
220 | - } else { |
|
221 | - throw new \EE_Error( |
|
222 | - sprintf( |
|
223 | - __('The following table creation SQL does not contain valid information about the table columns: %1$s %2$s', |
|
224 | - 'event_espresso'), |
|
225 | - '<br />', |
|
226 | - $create_sql |
|
227 | - ) |
|
228 | - ); |
|
229 | - } |
|
230 | - } |
|
191 | + * @param string $create_sql defining the table's columns and indexes |
|
192 | + * @param string $engine (no need to specify "ENGINE=", that's implied) |
|
193 | + * @return void |
|
194 | + * @throws \EE_Error |
|
195 | + */ |
|
196 | + public function createTable($table_name, $create_sql, $engine = 'MyISAM') |
|
197 | + { |
|
198 | + // does $sql contain valid column information? ( LPT: https://regex101.com/ is great for working out regex patterns ) |
|
199 | + if (preg_match('((((.*?))(,\s))+)', $create_sql, $valid_column_data)) { |
|
200 | + $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
|
201 | + /** @var \wpdb $wpdb */ |
|
202 | + global $wpdb; |
|
203 | + $SQL = "CREATE TABLE {$table_name} ( {$create_sql} ) ENGINE={$engine} " . $wpdb->get_charset_collate(); |
|
204 | + |
|
205 | + //get $wpdb to echo errors, but buffer them. This way at least WE know an error |
|
206 | + //happened. And then we can choose to tell the end user |
|
207 | + $old_show_errors_policy = $wpdb->show_errors(true); |
|
208 | + $old_error_suppression_policy = $wpdb->suppress_errors(false); |
|
209 | + ob_start(); |
|
210 | + dbDelta($SQL); |
|
211 | + $output = ob_get_contents(); |
|
212 | + ob_end_clean(); |
|
213 | + $wpdb->show_errors($old_show_errors_policy); |
|
214 | + $wpdb->suppress_errors($old_error_suppression_policy); |
|
215 | + if ( ! empty($output)) { |
|
216 | + throw new \EE_Error($output); |
|
217 | + } |
|
218 | + } else { |
|
219 | + throw new \EE_Error( |
|
220 | + sprintf( |
|
221 | + __('The following table creation SQL does not contain valid information about the table columns: %1$s %2$s', |
|
222 | + 'event_espresso'), |
|
223 | + '<br />', |
|
224 | + $create_sql |
|
225 | + ) |
|
226 | + ); |
|
227 | + } |
|
228 | + } |
|
231 | 229 | |
232 | 230 | } |
@@ -145,9 +145,9 @@ discard block |
||
145 | 145 | $tables_to_delete[] = $table_name; |
146 | 146 | } |
147 | 147 | } |
148 | - if( ! empty( $tables_to_delete ) ) { |
|
148 | + if ( ! empty($tables_to_delete)) { |
|
149 | 149 | global $wpdb; |
150 | - $wpdb->query('DROP TABLE ' . implode(', ', $tables_to_delete)); |
|
150 | + $wpdb->query('DROP TABLE '.implode(', ', $tables_to_delete)); |
|
151 | 151 | } |
152 | 152 | return $tables_to_delete; |
153 | 153 | } |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | $table_name = $this->getTableAnalysis()->ensureTableNameHasPrefix($table_name); |
203 | 203 | /** @var \wpdb $wpdb */ |
204 | 204 | global $wpdb; |
205 | - $SQL = "CREATE TABLE {$table_name} ( {$create_sql} ) ENGINE={$engine} " . $wpdb->get_charset_collate(); |
|
205 | + $SQL = "CREATE TABLE {$table_name} ( {$create_sql} ) ENGINE={$engine} ".$wpdb->get_charset_collate(); |
|
206 | 206 | |
207 | 207 | //get $wpdb to echo errors, but buffer them. This way at least WE know an error |
208 | 208 | //happened. And then we can choose to tell the end user |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /** |
5 | 5 | * Datetime Model |
@@ -11,546 +11,546 @@ discard block |
||
11 | 11 | class EEM_Datetime extends EEM_Soft_Delete_Base |
12 | 12 | { |
13 | 13 | |
14 | - // private instance of the EEM_Datetime object |
|
15 | - protected static $_instance = null; |
|
16 | - |
|
17 | - |
|
18 | - |
|
19 | - /** |
|
20 | - * private constructor to prevent direct creation |
|
21 | - * |
|
22 | - * @Constructor |
|
23 | - * @access private |
|
24 | - * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any |
|
25 | - * incoming timezone data that gets saved). Note this just sends the timezone info to the |
|
26 | - * date time model field objects. Default is NULL (and will be assumed using the set |
|
27 | - * timezone in the 'timezone_string' wp option) |
|
28 | - */ |
|
29 | - protected function __construct($timezone) |
|
30 | - { |
|
31 | - $this->singular_item = __('Datetime', 'event_espresso'); |
|
32 | - $this->plural_item = __('Datetimes', 'event_espresso'); |
|
33 | - $this->_tables = array( |
|
34 | - 'Datetime' => new EE_Primary_Table('esp_datetime', 'DTT_ID'), |
|
35 | - ); |
|
36 | - $this->_fields = array( |
|
37 | - 'Datetime' => array( |
|
38 | - 'DTT_ID' => new EE_Primary_Key_Int_Field('DTT_ID', __('Datetime ID', 'event_espresso')), |
|
39 | - 'EVT_ID' => new EE_Foreign_Key_Int_Field('EVT_ID', __('Event ID', 'event_espresso'), false, 0, |
|
40 | - 'Event'), |
|
41 | - 'DTT_name' => new EE_Plain_Text_Field('DTT_name', __('Datetime Name', 'event_espresso'), false, |
|
42 | - ''), |
|
43 | - 'DTT_description' => new EE_Post_Content_Field('DTT_description', |
|
44 | - __('Description for Datetime', 'event_espresso'), false, ''), |
|
45 | - 'DTT_EVT_start' => new EE_Datetime_Field('DTT_EVT_start', |
|
46 | - __('Start time/date of Event', 'event_espresso'), false, EE_Datetime_Field::now, $timezone), |
|
47 | - 'DTT_EVT_end' => new EE_Datetime_Field('DTT_EVT_end', |
|
48 | - __('End time/date of Event', 'event_espresso'), false, EE_Datetime_Field::now, $timezone), |
|
49 | - 'DTT_reg_limit' => new EE_Infinite_Integer_Field('DTT_reg_limit', |
|
50 | - __('Registration Limit for this time', 'event_espresso'), true, EE_INF), |
|
51 | - 'DTT_sold' => new EE_Integer_Field('DTT_sold', |
|
52 | - __('How many sales for this Datetime that have occurred', 'event_espresso'), true, 0), |
|
53 | - 'DTT_reserved' => new EE_Integer_Field('DTT_reserved', |
|
54 | - __('Quantity of tickets that are reserved, but not yet fully purchased', 'event_espresso'), false, |
|
55 | - 0), |
|
56 | - 'DTT_is_primary' => new EE_Boolean_Field('DTT_is_primary', |
|
57 | - __("Flag indicating datetime is primary one for event", "event_espresso"), false, false), |
|
58 | - 'DTT_order' => new EE_Integer_Field('DTT_order', |
|
59 | - __('The order in which the Datetime is displayed', 'event_espresso'), false, 0), |
|
60 | - 'DTT_parent' => new EE_Integer_Field('DTT_parent', |
|
61 | - __('Indicates what DTT_ID is the parent of this DTT_ID'), true, 0), |
|
62 | - 'DTT_deleted' => new EE_Trashed_Flag_Field('DTT_deleted', |
|
63 | - __('Flag indicating datetime is archived', 'event_espresso'), false, false), |
|
64 | - ), |
|
65 | - ); |
|
66 | - $this->_model_relations = array( |
|
67 | - 'Ticket' => new EE_HABTM_Relation('Datetime_Ticket'), |
|
68 | - 'Event' => new EE_Belongs_To_Relation(), |
|
69 | - 'Checkin' => new EE_Has_Many_Relation(), |
|
70 | - ); |
|
71 | - $this->_model_chain_to_wp_user = 'Event'; |
|
72 | - //this model is generally available for reading |
|
73 | - $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public('Event'); |
|
74 | - $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected('Event'); |
|
75 | - $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected('Event'); |
|
76 | - $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected('Event', |
|
77 | - EEM_Base::caps_edit); |
|
78 | - parent::__construct($timezone); |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * create new blank datetime |
|
85 | - * |
|
86 | - * @access public |
|
87 | - * @return EE_Datetime[] array on success, FALSE on fail |
|
88 | - */ |
|
89 | - public function create_new_blank_datetime() |
|
90 | - { |
|
91 | - //makes sure timezone is always set. |
|
92 | - $timezone_string = $this->get_timezone(); |
|
93 | - $blank_datetime = EE_Datetime::new_instance( |
|
94 | - array( |
|
95 | - 'DTT_EVT_start' => $this->current_time_for_query('DTT_EVT_start', true) + (60 * 60 * 24 * 30), |
|
96 | - 'DTT_EVT_end' => $this->current_time_for_query('DTT_EVT_end', true) + (60 * 60 * 24 * 30), |
|
97 | - 'DTT_order' => 1, |
|
98 | - 'DTT_reg_limit' => EE_INF, |
|
99 | - ), |
|
100 | - $timezone_string |
|
101 | - ); |
|
102 | - $blank_datetime->set_start_time($this->convert_datetime_for_query('DTT_EVT_start', '8am', 'ga', |
|
103 | - $timezone_string)); |
|
104 | - $blank_datetime->set_end_time($this->convert_datetime_for_query('DTT_EVT_end', '5pm', 'ga', $timezone_string)); |
|
105 | - return array($blank_datetime); |
|
106 | - } |
|
107 | - |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * get event start date from db |
|
112 | - * |
|
113 | - * @access public |
|
114 | - * @param int $EVT_ID |
|
115 | - * @return EE_Datetime[] array on success, FALSE on fail |
|
116 | - */ |
|
117 | - public function get_all_event_dates($EVT_ID = 0) |
|
118 | - { |
|
119 | - if ( ! $EVT_ID) { // on add_new_event event_id gets set to 0 |
|
120 | - return $this->create_new_blank_datetime(); |
|
121 | - } |
|
122 | - $results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID); |
|
123 | - if (empty($results)) { |
|
124 | - return $this->create_new_blank_datetime(); |
|
125 | - } |
|
126 | - return $results; |
|
127 | - } |
|
128 | - |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * get all datetimes attached to an event ordered by the DTT_order field |
|
133 | - * |
|
134 | - * @public |
|
135 | - * @param int $EVT_ID event id |
|
136 | - * @param boolean $include_expired |
|
137 | - * @param boolean $include_deleted |
|
138 | - * @param int $limit If included then limit the count of results by |
|
139 | - * the given number |
|
140 | - * @return EE_Datetime[] |
|
141 | - */ |
|
142 | - public function get_datetimes_for_event_ordered_by_DTT_order( |
|
143 | - $EVT_ID, |
|
144 | - $include_expired = true, |
|
145 | - $include_deleted = true, |
|
146 | - $limit = null |
|
147 | - ) { |
|
148 | - //sanitize EVT_ID |
|
149 | - $EVT_ID = intval($EVT_ID); |
|
150 | - $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
151 | - $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
152 | - $where_params = array('Event.EVT_ID' => $EVT_ID); |
|
153 | - $query_params = ! empty($limit) ? array( |
|
154 | - $where_params, |
|
155 | - 'limit' => $limit, |
|
156 | - 'order_by' => array('DTT_order' => 'ASC'), |
|
157 | - 'default_where_conditions' => 'none', |
|
158 | - ) : array($where_params, 'order_by' => array('DTT_order' => 'ASC'), 'default_where_conditions' => 'none'); |
|
159 | - if ( ! $include_expired) { |
|
160 | - $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
161 | - } |
|
162 | - if ($include_deleted) { |
|
163 | - $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
164 | - } |
|
165 | - $result = $this->get_all($query_params); |
|
166 | - $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
167 | - return $result; |
|
168 | - } |
|
169 | - |
|
170 | - |
|
171 | - |
|
172 | - /** |
|
173 | - * Gets the datetimes for the event (with the given limit), and orders them by "importance". By importance, we mean |
|
174 | - * that the primary datetimes are most important (DEPRECATED FOR NOW), and then the earlier datetimes are the most |
|
175 | - * important. Maybe we'll want this to take into account datetimes that haven't already passed, but we don't yet. |
|
176 | - * |
|
177 | - * @param int $EVT_ID |
|
178 | - * @param int $limit |
|
179 | - * @return EE_Datetime[] |
|
180 | - */ |
|
181 | - public function get_datetimes_for_event_ordered_by_importance($EVT_ID = 0, $limit = null) |
|
182 | - { |
|
183 | - return $this->get_all(array( |
|
184 | - array('Event.EVT_ID' => $EVT_ID), |
|
185 | - 'limit' => $limit, |
|
186 | - 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
187 | - 'default_where_conditions' => 'none', |
|
188 | - )); |
|
189 | - } |
|
190 | - |
|
191 | - |
|
192 | - |
|
193 | - /** |
|
194 | - * @param int $EVT_ID |
|
195 | - * @param boolean $include_expired |
|
196 | - * @param boolean $include_deleted |
|
197 | - * @return EE_Datetime |
|
198 | - */ |
|
199 | - public function get_oldest_datetime_for_event($EVT_ID, $include_expired = false, $include_deleted = false) |
|
200 | - { |
|
201 | - $results = $this->get_datetimes_for_event_ordered_by_start_time($EVT_ID, $include_expired, $include_deleted, 1); |
|
202 | - if ($results) { |
|
203 | - return array_shift($results); |
|
204 | - } else { |
|
205 | - return null; |
|
206 | - } |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - |
|
211 | - /** |
|
212 | - * Gets the 'primary' datetime for an event. |
|
213 | - * |
|
214 | - * @param int $EVT_ID |
|
215 | - * @param bool $try_to_exclude_expired |
|
216 | - * @param bool $try_to_exclude_deleted |
|
217 | - * @return \EE_Datetime |
|
218 | - */ |
|
219 | - public function get_primary_datetime_for_event( |
|
220 | - $EVT_ID, |
|
221 | - $try_to_exclude_expired = true, |
|
222 | - $try_to_exclude_deleted = true |
|
223 | - ) { |
|
224 | - if ($try_to_exclude_expired) { |
|
225 | - $non_expired = $this->get_oldest_datetime_for_event($EVT_ID, false, false); |
|
226 | - if ($non_expired) { |
|
227 | - return $non_expired; |
|
228 | - } |
|
229 | - } |
|
230 | - if ($try_to_exclude_deleted) { |
|
231 | - $expired_even = $this->get_oldest_datetime_for_event($EVT_ID, true); |
|
232 | - if ($expired_even) { |
|
233 | - return $expired_even; |
|
234 | - } |
|
235 | - } |
|
236 | - $deleted_even = $this->get_oldest_datetime_for_event($EVT_ID, true, true); |
|
237 | - return $deleted_even; |
|
238 | - } |
|
239 | - |
|
240 | - |
|
241 | - |
|
242 | - /** |
|
243 | - * Gets ALL the datetimes for an event (including trashed ones, for now), ordered |
|
244 | - * only by start date |
|
245 | - * |
|
246 | - * @param int $EVT_ID |
|
247 | - * @param boolean $include_expired |
|
248 | - * @param boolean $include_deleted |
|
249 | - * @param int $limit |
|
250 | - * @return EE_Datetime[] |
|
251 | - */ |
|
252 | - public function get_datetimes_for_event_ordered_by_start_time( |
|
253 | - $EVT_ID, |
|
254 | - $include_expired = true, |
|
255 | - $include_deleted = true, |
|
256 | - $limit = null |
|
257 | - ) { |
|
258 | - //sanitize EVT_ID |
|
259 | - $EVT_ID = intval($EVT_ID); |
|
260 | - $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
261 | - $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
262 | - $query_params = array(array('Event.EVT_ID' => $EVT_ID), 'order_by' => array('DTT_EVT_start' => 'asc')); |
|
263 | - if ( ! $include_expired) { |
|
264 | - $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
265 | - } |
|
266 | - if ($include_deleted) { |
|
267 | - $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
268 | - } |
|
269 | - if ($limit) { |
|
270 | - $query_params['limit'] = $limit; |
|
271 | - } |
|
272 | - $result = $this->get_all($query_params); |
|
273 | - $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
274 | - return $result; |
|
275 | - } |
|
276 | - |
|
277 | - |
|
278 | - |
|
279 | - /** |
|
280 | - * Gets ALL the datetimes for an ticket (including trashed ones, for now), ordered |
|
281 | - * only by start date |
|
282 | - * |
|
283 | - * @param int $TKT_ID |
|
284 | - * @param boolean $include_expired |
|
285 | - * @param boolean $include_deleted |
|
286 | - * @param int $limit |
|
287 | - * @return EE_Datetime[] |
|
288 | - */ |
|
289 | - public function get_datetimes_for_ticket_ordered_by_start_time( |
|
290 | - $TKT_ID, |
|
291 | - $include_expired = true, |
|
292 | - $include_deleted = true, |
|
293 | - $limit = null |
|
294 | - ) { |
|
295 | - //sanitize TKT_ID |
|
296 | - $TKT_ID = intval($TKT_ID); |
|
297 | - $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
298 | - $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
299 | - $query_params = array(array('Ticket.TKT_ID' => $TKT_ID), 'order_by' => array('DTT_EVT_start' => 'asc')); |
|
300 | - if ( ! $include_expired) { |
|
301 | - $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
302 | - } |
|
303 | - if ($include_deleted) { |
|
304 | - $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
305 | - } |
|
306 | - if ($limit) { |
|
307 | - $query_params['limit'] = $limit; |
|
308 | - } |
|
309 | - $result = $this->get_all($query_params); |
|
310 | - $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
311 | - return $result; |
|
312 | - } |
|
313 | - |
|
314 | - |
|
315 | - |
|
316 | - /** |
|
317 | - * Gets all the datetimes for a ticket (including trashed ones, for now), ordered by the DTT_order for the |
|
318 | - * datetimes. |
|
319 | - * |
|
320 | - * @param int $TKT_ID ID of ticket to retrieve the datetimes for |
|
321 | - * @param boolean $include_expired whether to include expired datetimes or not |
|
322 | - * @param boolean $include_deleted whether to include trashed datetimes or not. |
|
323 | - * @param int|null $limit if null, no limit, if int then limit results by |
|
324 | - * that number |
|
325 | - * @return EE_Datetime[] |
|
326 | - */ |
|
327 | - public function get_datetimes_for_ticket_ordered_by_DTT_order( |
|
328 | - $TKT_ID, |
|
329 | - $include_expired = true, |
|
330 | - $include_deleted = true, |
|
331 | - $limit = null |
|
332 | - ) { |
|
333 | - //sanitize id. |
|
334 | - $TKT_ID = intval($TKT_ID); |
|
335 | - $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
336 | - $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
337 | - $where_params = array('Ticket.TKT_ID' => $TKT_ID); |
|
338 | - $query_params = array($where_params, 'order_by' => array('DTT_order' => 'ASC')); |
|
339 | - if ( ! $include_expired) { |
|
340 | - $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
341 | - } |
|
342 | - if ($include_deleted) { |
|
343 | - $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
344 | - } |
|
345 | - if ($limit) { |
|
346 | - $query_params['limit'] = $limit; |
|
347 | - } |
|
348 | - $result = $this->get_all($query_params); |
|
349 | - $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
350 | - return $result; |
|
351 | - } |
|
352 | - |
|
353 | - |
|
354 | - |
|
355 | - /** |
|
356 | - * Gets the most important datetime for a particular event (ie, the primary event usually. But if for some WACK |
|
357 | - * reason it doesn't exist, we consider the earliest event the most important) |
|
358 | - * |
|
359 | - * @param int $EVT_ID |
|
360 | - * @return EE_Datetime |
|
361 | - */ |
|
362 | - public function get_most_important_datetime_for_event($EVT_ID) |
|
363 | - { |
|
364 | - $results = $this->get_datetimes_for_event_ordered_by_importance($EVT_ID, 1); |
|
365 | - if ($results) { |
|
366 | - return array_shift($results); |
|
367 | - } else { |
|
368 | - return null; |
|
369 | - } |
|
370 | - } |
|
371 | - |
|
372 | - |
|
373 | - |
|
374 | - /** |
|
375 | - * This returns a wpdb->results Array of all DTT month and years matching the incoming query params and |
|
376 | - * grouped by month and year. |
|
377 | - * |
|
378 | - * @param array $where_params Array of query_params as described in the comments for EEM_Base::get_all() |
|
379 | - * @param string $evt_active_status A string representing the evt active status to filter the months by. |
|
380 | - * Can be: |
|
381 | - * - '' = no filter |
|
382 | - * - upcoming = Published events with at least one upcoming datetime. |
|
383 | - * - expired = Events with all datetimes expired. |
|
384 | - * - active = Events that are published and have at least one datetime that |
|
385 | - * starts before now and ends after now. |
|
386 | - * - inactive = Events that are either not published. |
|
387 | - * @return wpdb results array |
|
388 | - */ |
|
389 | - public function get_dtt_months_and_years($where_params, $evt_active_status = '') |
|
390 | - { |
|
391 | - $current_time_for_DTT_EVT_start = $this->current_time_for_query('DTT_EVT_start'); |
|
392 | - $current_time_for_DTT_EVT_end = $this->current_time_for_query('DTT_EVT_end'); |
|
393 | - switch ($evt_active_status) { |
|
394 | - case 'upcoming' : |
|
395 | - $where_params['Event.status'] = 'publish'; |
|
396 | - //if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
|
397 | - if (isset($where_params['DTT_EVT_start'])) { |
|
398 | - $where_params['DTT_EVT_start*****'] = $where_params['DTT_EVT_start']; |
|
399 | - } |
|
400 | - $where_params['DTT_EVT_start'] = array('>', $current_time_for_DTT_EVT_start); |
|
401 | - break; |
|
402 | - case 'expired' : |
|
403 | - if (isset($where_params['Event.status'])) { |
|
404 | - unset($where_params['Event.status']); |
|
405 | - } |
|
406 | - //get events to exclude |
|
407 | - $exclude_query[0] = array_merge($where_params, |
|
408 | - array('DTT_EVT_end' => array('>', $current_time_for_DTT_EVT_end))); |
|
409 | - //first get all events that have datetimes where its not expired. |
|
410 | - $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Datetime.EVT_ID'); |
|
411 | - $event_ids = array_keys($event_ids); |
|
412 | - if (isset($where_params['DTT_EVT_end'])) { |
|
413 | - $where_params['DTT_EVT_end****'] = $where_params['DTT_EVT_end']; |
|
414 | - } |
|
415 | - $where_params['DTT_EVT_end'] = array('<', $current_time_for_DTT_EVT_end); |
|
416 | - $where_params['Event.EVT_ID'] = array('NOT IN', $event_ids); |
|
417 | - break; |
|
418 | - case 'active' : |
|
419 | - $where_params['Event.status'] = 'publish'; |
|
420 | - if (isset($where_params['DTT_EVT_start'])) { |
|
421 | - $where_params['Datetime.DTT_EVT_start******'] = $where_params['DTT_EVT_start']; |
|
422 | - } |
|
423 | - if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
424 | - $where_params['Datetime.DTT_EVT_end*****'] = $where_params['DTT_EVT_end']; |
|
425 | - } |
|
426 | - $where_params['DTT_EVT_start'] = array('<', $current_time_for_DTT_EVT_start); |
|
427 | - $where_params['DTT_EVT_end'] = array('>', $current_time_for_DTT_EVT_end); |
|
428 | - break; |
|
429 | - case 'inactive' : |
|
430 | - if (isset($where_params['Event.status'])) { |
|
431 | - unset($where_params['Event.status']); |
|
432 | - } |
|
433 | - if (isset($where_params['OR'])) { |
|
434 | - $where_params['AND']['OR'] = $where_params['OR']; |
|
435 | - } |
|
436 | - if (isset($where_params['DTT_EVT_end'])) { |
|
437 | - $where_params['AND']['DTT_EVT_end****'] = $where_params['DTT_EVT_end']; |
|
438 | - unset($where_params['DTT_EVT_end']); |
|
439 | - } |
|
440 | - if (isset($where_params['DTT_EVT_start'])) { |
|
441 | - $where_params['AND']['DTT_EVT_start'] = $where_params['DTT_EVT_start']; |
|
442 | - unset($where_params['DTT_EVT_start']); |
|
443 | - } |
|
444 | - $where_params['AND']['Event.status'] = array('!=', 'publish'); |
|
445 | - break; |
|
446 | - } |
|
447 | - $query_params[0] = $where_params; |
|
448 | - $query_params['group_by'] = array('dtt_year', 'dtt_month'); |
|
449 | - $query_params['order_by'] = array('DTT_EVT_start' => 'DESC'); |
|
450 | - $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'DTT_EVT_start'); |
|
451 | - $columns_to_select = array( |
|
452 | - 'dtt_year' => array('YEAR(' . $query_interval . ')', '%s'), |
|
453 | - 'dtt_month' => array('MONTHNAME(' . $query_interval . ')', '%s'), |
|
454 | - 'dtt_month_num' => array('MONTH(' . $query_interval . ')', '%s'), |
|
455 | - ); |
|
456 | - return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select); |
|
457 | - } |
|
458 | - |
|
459 | - |
|
460 | - |
|
461 | - /** |
|
462 | - * Updates the DTT_sold attribute on each datetime (based on the registrations |
|
463 | - * for the tickets for each datetime) |
|
464 | - * |
|
465 | - * @param EE_Datetime[] $datetimes |
|
466 | - */ |
|
467 | - public function update_sold($datetimes) |
|
468 | - { |
|
469 | - foreach ($datetimes as $datetime) { |
|
470 | - $datetime->update_sold(); |
|
471 | - } |
|
472 | - } |
|
473 | - |
|
474 | - |
|
475 | - |
|
476 | - /** |
|
477 | - * Gets the total number of tickets available at a particular datetime |
|
478 | - * (does NOT take into account the datetime's spaces available) |
|
479 | - * |
|
480 | - * @param int $DTT_ID |
|
481 | - * @param array $query_params |
|
482 | - * @return int of tickets available. If sold out, return less than 1. If infinite, returns EE_INF, IF there are NO |
|
483 | - * tickets attached to datetime then FALSE is returned. |
|
484 | - */ |
|
485 | - public function sum_tickets_currently_available_at_datetime($DTT_ID, $query_params = array()) |
|
486 | - { |
|
487 | - $datetime = $this->get_one_by_ID($DTT_ID); |
|
488 | - if ($datetime instanceof EE_Datetime) { |
|
489 | - return $datetime->tickets_remaining($query_params); |
|
490 | - } |
|
491 | - return 0; |
|
492 | - } |
|
493 | - |
|
494 | - |
|
495 | - |
|
496 | - /** |
|
497 | - * This returns an array of counts of datetimes in the database for each Datetime status that can be queried. |
|
498 | - * |
|
499 | - * @param array $stati_to_include If included you can restrict the statuses we return counts for by including the |
|
500 | - * stati you want counts for as values in the array. An empty array returns counts |
|
501 | - * for all valid stati. |
|
502 | - * @param array $query_params If included can be used to refine the conditions for returning the count (i.e. |
|
503 | - * only for Datetimes connected to a specific event, or specific ticket. |
|
504 | - * @return array The value returned is an array indexed by Datetime Status and the values are the counts. The |
|
505 | - * stati used as index keys are: EE_Datetime::active EE_Datetime::upcoming EE_Datetime::expired |
|
506 | - */ |
|
507 | - public function get_datetime_counts_by_status($stati_to_include = array(), $query_params = array()) |
|
508 | - { |
|
509 | - //only accept where conditions for this query. |
|
510 | - $_where = isset($query_params[0]) ? $query_params[0] : array(); |
|
511 | - $status_query_args = array( |
|
512 | - EE_Datetime::active => array_merge( |
|
513 | - $_where, |
|
514 | - array('DTT_EVT_start' => array('<', time()), 'DTT_EVT_end' => array('>', time())) |
|
515 | - ), |
|
516 | - EE_Datetime::upcoming => array_merge( |
|
517 | - $_where, |
|
518 | - array('DTT_EVT_start' => array('>', time())) |
|
519 | - ), |
|
520 | - EE_Datetime::expired => array_merge( |
|
521 | - $_where, |
|
522 | - array('DTT_EVT_end' => array('<', time())) |
|
523 | - ), |
|
524 | - ); |
|
525 | - if ( ! empty($stati_to_include)) { |
|
526 | - foreach (array_keys($status_query_args) as $status) { |
|
527 | - if ( ! in_array($status, $stati_to_include)) { |
|
528 | - unset($status_query_args[$status]); |
|
529 | - } |
|
530 | - } |
|
531 | - } |
|
532 | - //loop through and query counts for each stati. |
|
533 | - $status_query_results = array(); |
|
534 | - foreach ($status_query_args as $status => $status_where_conditions) { |
|
535 | - $status_query_results[$status] = EEM_Datetime::count(array($status_where_conditions), 'DTT_ID', true); |
|
536 | - } |
|
537 | - return $status_query_results; |
|
538 | - } |
|
539 | - |
|
540 | - |
|
541 | - |
|
542 | - /** |
|
543 | - * Returns the specific count for a given Datetime status matching any given query_params. |
|
544 | - * |
|
545 | - * @param string $status Valid string representation for Datetime status requested. (Defaults to Active). |
|
546 | - * @param array $query_params |
|
547 | - * @return int |
|
548 | - */ |
|
549 | - public function get_datetime_count_for_status($status = EE_Datetime::active, $query_params = array()) |
|
550 | - { |
|
551 | - $count = $this->get_datetime_counts_by_status(array($status), $query_params); |
|
552 | - return ! empty($count[$status]) ? $count[$status] : 0; |
|
553 | - } |
|
14 | + // private instance of the EEM_Datetime object |
|
15 | + protected static $_instance = null; |
|
16 | + |
|
17 | + |
|
18 | + |
|
19 | + /** |
|
20 | + * private constructor to prevent direct creation |
|
21 | + * |
|
22 | + * @Constructor |
|
23 | + * @access private |
|
24 | + * @param string $timezone string representing the timezone we want to set for returned Date Time Strings (and any |
|
25 | + * incoming timezone data that gets saved). Note this just sends the timezone info to the |
|
26 | + * date time model field objects. Default is NULL (and will be assumed using the set |
|
27 | + * timezone in the 'timezone_string' wp option) |
|
28 | + */ |
|
29 | + protected function __construct($timezone) |
|
30 | + { |
|
31 | + $this->singular_item = __('Datetime', 'event_espresso'); |
|
32 | + $this->plural_item = __('Datetimes', 'event_espresso'); |
|
33 | + $this->_tables = array( |
|
34 | + 'Datetime' => new EE_Primary_Table('esp_datetime', 'DTT_ID'), |
|
35 | + ); |
|
36 | + $this->_fields = array( |
|
37 | + 'Datetime' => array( |
|
38 | + 'DTT_ID' => new EE_Primary_Key_Int_Field('DTT_ID', __('Datetime ID', 'event_espresso')), |
|
39 | + 'EVT_ID' => new EE_Foreign_Key_Int_Field('EVT_ID', __('Event ID', 'event_espresso'), false, 0, |
|
40 | + 'Event'), |
|
41 | + 'DTT_name' => new EE_Plain_Text_Field('DTT_name', __('Datetime Name', 'event_espresso'), false, |
|
42 | + ''), |
|
43 | + 'DTT_description' => new EE_Post_Content_Field('DTT_description', |
|
44 | + __('Description for Datetime', 'event_espresso'), false, ''), |
|
45 | + 'DTT_EVT_start' => new EE_Datetime_Field('DTT_EVT_start', |
|
46 | + __('Start time/date of Event', 'event_espresso'), false, EE_Datetime_Field::now, $timezone), |
|
47 | + 'DTT_EVT_end' => new EE_Datetime_Field('DTT_EVT_end', |
|
48 | + __('End time/date of Event', 'event_espresso'), false, EE_Datetime_Field::now, $timezone), |
|
49 | + 'DTT_reg_limit' => new EE_Infinite_Integer_Field('DTT_reg_limit', |
|
50 | + __('Registration Limit for this time', 'event_espresso'), true, EE_INF), |
|
51 | + 'DTT_sold' => new EE_Integer_Field('DTT_sold', |
|
52 | + __('How many sales for this Datetime that have occurred', 'event_espresso'), true, 0), |
|
53 | + 'DTT_reserved' => new EE_Integer_Field('DTT_reserved', |
|
54 | + __('Quantity of tickets that are reserved, but not yet fully purchased', 'event_espresso'), false, |
|
55 | + 0), |
|
56 | + 'DTT_is_primary' => new EE_Boolean_Field('DTT_is_primary', |
|
57 | + __("Flag indicating datetime is primary one for event", "event_espresso"), false, false), |
|
58 | + 'DTT_order' => new EE_Integer_Field('DTT_order', |
|
59 | + __('The order in which the Datetime is displayed', 'event_espresso'), false, 0), |
|
60 | + 'DTT_parent' => new EE_Integer_Field('DTT_parent', |
|
61 | + __('Indicates what DTT_ID is the parent of this DTT_ID'), true, 0), |
|
62 | + 'DTT_deleted' => new EE_Trashed_Flag_Field('DTT_deleted', |
|
63 | + __('Flag indicating datetime is archived', 'event_espresso'), false, false), |
|
64 | + ), |
|
65 | + ); |
|
66 | + $this->_model_relations = array( |
|
67 | + 'Ticket' => new EE_HABTM_Relation('Datetime_Ticket'), |
|
68 | + 'Event' => new EE_Belongs_To_Relation(), |
|
69 | + 'Checkin' => new EE_Has_Many_Relation(), |
|
70 | + ); |
|
71 | + $this->_model_chain_to_wp_user = 'Event'; |
|
72 | + //this model is generally available for reading |
|
73 | + $this->_cap_restriction_generators[EEM_Base::caps_read] = new EE_Restriction_Generator_Event_Related_Public('Event'); |
|
74 | + $this->_cap_restriction_generators[EEM_Base::caps_read_admin] = new EE_Restriction_Generator_Event_Related_Protected('Event'); |
|
75 | + $this->_cap_restriction_generators[EEM_Base::caps_edit] = new EE_Restriction_Generator_Event_Related_Protected('Event'); |
|
76 | + $this->_cap_restriction_generators[EEM_Base::caps_delete] = new EE_Restriction_Generator_Event_Related_Protected('Event', |
|
77 | + EEM_Base::caps_edit); |
|
78 | + parent::__construct($timezone); |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * create new blank datetime |
|
85 | + * |
|
86 | + * @access public |
|
87 | + * @return EE_Datetime[] array on success, FALSE on fail |
|
88 | + */ |
|
89 | + public function create_new_blank_datetime() |
|
90 | + { |
|
91 | + //makes sure timezone is always set. |
|
92 | + $timezone_string = $this->get_timezone(); |
|
93 | + $blank_datetime = EE_Datetime::new_instance( |
|
94 | + array( |
|
95 | + 'DTT_EVT_start' => $this->current_time_for_query('DTT_EVT_start', true) + (60 * 60 * 24 * 30), |
|
96 | + 'DTT_EVT_end' => $this->current_time_for_query('DTT_EVT_end', true) + (60 * 60 * 24 * 30), |
|
97 | + 'DTT_order' => 1, |
|
98 | + 'DTT_reg_limit' => EE_INF, |
|
99 | + ), |
|
100 | + $timezone_string |
|
101 | + ); |
|
102 | + $blank_datetime->set_start_time($this->convert_datetime_for_query('DTT_EVT_start', '8am', 'ga', |
|
103 | + $timezone_string)); |
|
104 | + $blank_datetime->set_end_time($this->convert_datetime_for_query('DTT_EVT_end', '5pm', 'ga', $timezone_string)); |
|
105 | + return array($blank_datetime); |
|
106 | + } |
|
107 | + |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * get event start date from db |
|
112 | + * |
|
113 | + * @access public |
|
114 | + * @param int $EVT_ID |
|
115 | + * @return EE_Datetime[] array on success, FALSE on fail |
|
116 | + */ |
|
117 | + public function get_all_event_dates($EVT_ID = 0) |
|
118 | + { |
|
119 | + if ( ! $EVT_ID) { // on add_new_event event_id gets set to 0 |
|
120 | + return $this->create_new_blank_datetime(); |
|
121 | + } |
|
122 | + $results = $this->get_datetimes_for_event_ordered_by_DTT_order($EVT_ID); |
|
123 | + if (empty($results)) { |
|
124 | + return $this->create_new_blank_datetime(); |
|
125 | + } |
|
126 | + return $results; |
|
127 | + } |
|
128 | + |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * get all datetimes attached to an event ordered by the DTT_order field |
|
133 | + * |
|
134 | + * @public |
|
135 | + * @param int $EVT_ID event id |
|
136 | + * @param boolean $include_expired |
|
137 | + * @param boolean $include_deleted |
|
138 | + * @param int $limit If included then limit the count of results by |
|
139 | + * the given number |
|
140 | + * @return EE_Datetime[] |
|
141 | + */ |
|
142 | + public function get_datetimes_for_event_ordered_by_DTT_order( |
|
143 | + $EVT_ID, |
|
144 | + $include_expired = true, |
|
145 | + $include_deleted = true, |
|
146 | + $limit = null |
|
147 | + ) { |
|
148 | + //sanitize EVT_ID |
|
149 | + $EVT_ID = intval($EVT_ID); |
|
150 | + $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
151 | + $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
152 | + $where_params = array('Event.EVT_ID' => $EVT_ID); |
|
153 | + $query_params = ! empty($limit) ? array( |
|
154 | + $where_params, |
|
155 | + 'limit' => $limit, |
|
156 | + 'order_by' => array('DTT_order' => 'ASC'), |
|
157 | + 'default_where_conditions' => 'none', |
|
158 | + ) : array($where_params, 'order_by' => array('DTT_order' => 'ASC'), 'default_where_conditions' => 'none'); |
|
159 | + if ( ! $include_expired) { |
|
160 | + $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
161 | + } |
|
162 | + if ($include_deleted) { |
|
163 | + $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
164 | + } |
|
165 | + $result = $this->get_all($query_params); |
|
166 | + $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
167 | + return $result; |
|
168 | + } |
|
169 | + |
|
170 | + |
|
171 | + |
|
172 | + /** |
|
173 | + * Gets the datetimes for the event (with the given limit), and orders them by "importance". By importance, we mean |
|
174 | + * that the primary datetimes are most important (DEPRECATED FOR NOW), and then the earlier datetimes are the most |
|
175 | + * important. Maybe we'll want this to take into account datetimes that haven't already passed, but we don't yet. |
|
176 | + * |
|
177 | + * @param int $EVT_ID |
|
178 | + * @param int $limit |
|
179 | + * @return EE_Datetime[] |
|
180 | + */ |
|
181 | + public function get_datetimes_for_event_ordered_by_importance($EVT_ID = 0, $limit = null) |
|
182 | + { |
|
183 | + return $this->get_all(array( |
|
184 | + array('Event.EVT_ID' => $EVT_ID), |
|
185 | + 'limit' => $limit, |
|
186 | + 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
187 | + 'default_where_conditions' => 'none', |
|
188 | + )); |
|
189 | + } |
|
190 | + |
|
191 | + |
|
192 | + |
|
193 | + /** |
|
194 | + * @param int $EVT_ID |
|
195 | + * @param boolean $include_expired |
|
196 | + * @param boolean $include_deleted |
|
197 | + * @return EE_Datetime |
|
198 | + */ |
|
199 | + public function get_oldest_datetime_for_event($EVT_ID, $include_expired = false, $include_deleted = false) |
|
200 | + { |
|
201 | + $results = $this->get_datetimes_for_event_ordered_by_start_time($EVT_ID, $include_expired, $include_deleted, 1); |
|
202 | + if ($results) { |
|
203 | + return array_shift($results); |
|
204 | + } else { |
|
205 | + return null; |
|
206 | + } |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + |
|
211 | + /** |
|
212 | + * Gets the 'primary' datetime for an event. |
|
213 | + * |
|
214 | + * @param int $EVT_ID |
|
215 | + * @param bool $try_to_exclude_expired |
|
216 | + * @param bool $try_to_exclude_deleted |
|
217 | + * @return \EE_Datetime |
|
218 | + */ |
|
219 | + public function get_primary_datetime_for_event( |
|
220 | + $EVT_ID, |
|
221 | + $try_to_exclude_expired = true, |
|
222 | + $try_to_exclude_deleted = true |
|
223 | + ) { |
|
224 | + if ($try_to_exclude_expired) { |
|
225 | + $non_expired = $this->get_oldest_datetime_for_event($EVT_ID, false, false); |
|
226 | + if ($non_expired) { |
|
227 | + return $non_expired; |
|
228 | + } |
|
229 | + } |
|
230 | + if ($try_to_exclude_deleted) { |
|
231 | + $expired_even = $this->get_oldest_datetime_for_event($EVT_ID, true); |
|
232 | + if ($expired_even) { |
|
233 | + return $expired_even; |
|
234 | + } |
|
235 | + } |
|
236 | + $deleted_even = $this->get_oldest_datetime_for_event($EVT_ID, true, true); |
|
237 | + return $deleted_even; |
|
238 | + } |
|
239 | + |
|
240 | + |
|
241 | + |
|
242 | + /** |
|
243 | + * Gets ALL the datetimes for an event (including trashed ones, for now), ordered |
|
244 | + * only by start date |
|
245 | + * |
|
246 | + * @param int $EVT_ID |
|
247 | + * @param boolean $include_expired |
|
248 | + * @param boolean $include_deleted |
|
249 | + * @param int $limit |
|
250 | + * @return EE_Datetime[] |
|
251 | + */ |
|
252 | + public function get_datetimes_for_event_ordered_by_start_time( |
|
253 | + $EVT_ID, |
|
254 | + $include_expired = true, |
|
255 | + $include_deleted = true, |
|
256 | + $limit = null |
|
257 | + ) { |
|
258 | + //sanitize EVT_ID |
|
259 | + $EVT_ID = intval($EVT_ID); |
|
260 | + $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
261 | + $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
262 | + $query_params = array(array('Event.EVT_ID' => $EVT_ID), 'order_by' => array('DTT_EVT_start' => 'asc')); |
|
263 | + if ( ! $include_expired) { |
|
264 | + $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
265 | + } |
|
266 | + if ($include_deleted) { |
|
267 | + $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
268 | + } |
|
269 | + if ($limit) { |
|
270 | + $query_params['limit'] = $limit; |
|
271 | + } |
|
272 | + $result = $this->get_all($query_params); |
|
273 | + $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
274 | + return $result; |
|
275 | + } |
|
276 | + |
|
277 | + |
|
278 | + |
|
279 | + /** |
|
280 | + * Gets ALL the datetimes for an ticket (including trashed ones, for now), ordered |
|
281 | + * only by start date |
|
282 | + * |
|
283 | + * @param int $TKT_ID |
|
284 | + * @param boolean $include_expired |
|
285 | + * @param boolean $include_deleted |
|
286 | + * @param int $limit |
|
287 | + * @return EE_Datetime[] |
|
288 | + */ |
|
289 | + public function get_datetimes_for_ticket_ordered_by_start_time( |
|
290 | + $TKT_ID, |
|
291 | + $include_expired = true, |
|
292 | + $include_deleted = true, |
|
293 | + $limit = null |
|
294 | + ) { |
|
295 | + //sanitize TKT_ID |
|
296 | + $TKT_ID = intval($TKT_ID); |
|
297 | + $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
298 | + $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
299 | + $query_params = array(array('Ticket.TKT_ID' => $TKT_ID), 'order_by' => array('DTT_EVT_start' => 'asc')); |
|
300 | + if ( ! $include_expired) { |
|
301 | + $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
302 | + } |
|
303 | + if ($include_deleted) { |
|
304 | + $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
305 | + } |
|
306 | + if ($limit) { |
|
307 | + $query_params['limit'] = $limit; |
|
308 | + } |
|
309 | + $result = $this->get_all($query_params); |
|
310 | + $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
311 | + return $result; |
|
312 | + } |
|
313 | + |
|
314 | + |
|
315 | + |
|
316 | + /** |
|
317 | + * Gets all the datetimes for a ticket (including trashed ones, for now), ordered by the DTT_order for the |
|
318 | + * datetimes. |
|
319 | + * |
|
320 | + * @param int $TKT_ID ID of ticket to retrieve the datetimes for |
|
321 | + * @param boolean $include_expired whether to include expired datetimes or not |
|
322 | + * @param boolean $include_deleted whether to include trashed datetimes or not. |
|
323 | + * @param int|null $limit if null, no limit, if int then limit results by |
|
324 | + * that number |
|
325 | + * @return EE_Datetime[] |
|
326 | + */ |
|
327 | + public function get_datetimes_for_ticket_ordered_by_DTT_order( |
|
328 | + $TKT_ID, |
|
329 | + $include_expired = true, |
|
330 | + $include_deleted = true, |
|
331 | + $limit = null |
|
332 | + ) { |
|
333 | + //sanitize id. |
|
334 | + $TKT_ID = intval($TKT_ID); |
|
335 | + $old_assumption = $this->get_assumption_concerning_values_already_prepared_by_model_object(); |
|
336 | + $this->assume_values_already_prepared_by_model_object(EEM_Base::prepared_for_use_in_db); |
|
337 | + $where_params = array('Ticket.TKT_ID' => $TKT_ID); |
|
338 | + $query_params = array($where_params, 'order_by' => array('DTT_order' => 'ASC')); |
|
339 | + if ( ! $include_expired) { |
|
340 | + $query_params[0]['DTT_EVT_end'] = array('>=', current_time('mysql', true)); |
|
341 | + } |
|
342 | + if ($include_deleted) { |
|
343 | + $query_params[0]['DTT_deleted'] = array('IN', array(true, false)); |
|
344 | + } |
|
345 | + if ($limit) { |
|
346 | + $query_params['limit'] = $limit; |
|
347 | + } |
|
348 | + $result = $this->get_all($query_params); |
|
349 | + $this->assume_values_already_prepared_by_model_object($old_assumption); |
|
350 | + return $result; |
|
351 | + } |
|
352 | + |
|
353 | + |
|
354 | + |
|
355 | + /** |
|
356 | + * Gets the most important datetime for a particular event (ie, the primary event usually. But if for some WACK |
|
357 | + * reason it doesn't exist, we consider the earliest event the most important) |
|
358 | + * |
|
359 | + * @param int $EVT_ID |
|
360 | + * @return EE_Datetime |
|
361 | + */ |
|
362 | + public function get_most_important_datetime_for_event($EVT_ID) |
|
363 | + { |
|
364 | + $results = $this->get_datetimes_for_event_ordered_by_importance($EVT_ID, 1); |
|
365 | + if ($results) { |
|
366 | + return array_shift($results); |
|
367 | + } else { |
|
368 | + return null; |
|
369 | + } |
|
370 | + } |
|
371 | + |
|
372 | + |
|
373 | + |
|
374 | + /** |
|
375 | + * This returns a wpdb->results Array of all DTT month and years matching the incoming query params and |
|
376 | + * grouped by month and year. |
|
377 | + * |
|
378 | + * @param array $where_params Array of query_params as described in the comments for EEM_Base::get_all() |
|
379 | + * @param string $evt_active_status A string representing the evt active status to filter the months by. |
|
380 | + * Can be: |
|
381 | + * - '' = no filter |
|
382 | + * - upcoming = Published events with at least one upcoming datetime. |
|
383 | + * - expired = Events with all datetimes expired. |
|
384 | + * - active = Events that are published and have at least one datetime that |
|
385 | + * starts before now and ends after now. |
|
386 | + * - inactive = Events that are either not published. |
|
387 | + * @return wpdb results array |
|
388 | + */ |
|
389 | + public function get_dtt_months_and_years($where_params, $evt_active_status = '') |
|
390 | + { |
|
391 | + $current_time_for_DTT_EVT_start = $this->current_time_for_query('DTT_EVT_start'); |
|
392 | + $current_time_for_DTT_EVT_end = $this->current_time_for_query('DTT_EVT_end'); |
|
393 | + switch ($evt_active_status) { |
|
394 | + case 'upcoming' : |
|
395 | + $where_params['Event.status'] = 'publish'; |
|
396 | + //if there are already query_params matching DTT_EVT_start then we need to modify that to add them. |
|
397 | + if (isset($where_params['DTT_EVT_start'])) { |
|
398 | + $where_params['DTT_EVT_start*****'] = $where_params['DTT_EVT_start']; |
|
399 | + } |
|
400 | + $where_params['DTT_EVT_start'] = array('>', $current_time_for_DTT_EVT_start); |
|
401 | + break; |
|
402 | + case 'expired' : |
|
403 | + if (isset($where_params['Event.status'])) { |
|
404 | + unset($where_params['Event.status']); |
|
405 | + } |
|
406 | + //get events to exclude |
|
407 | + $exclude_query[0] = array_merge($where_params, |
|
408 | + array('DTT_EVT_end' => array('>', $current_time_for_DTT_EVT_end))); |
|
409 | + //first get all events that have datetimes where its not expired. |
|
410 | + $event_ids = $this->_get_all_wpdb_results($exclude_query, OBJECT_K, 'Datetime.EVT_ID'); |
|
411 | + $event_ids = array_keys($event_ids); |
|
412 | + if (isset($where_params['DTT_EVT_end'])) { |
|
413 | + $where_params['DTT_EVT_end****'] = $where_params['DTT_EVT_end']; |
|
414 | + } |
|
415 | + $where_params['DTT_EVT_end'] = array('<', $current_time_for_DTT_EVT_end); |
|
416 | + $where_params['Event.EVT_ID'] = array('NOT IN', $event_ids); |
|
417 | + break; |
|
418 | + case 'active' : |
|
419 | + $where_params['Event.status'] = 'publish'; |
|
420 | + if (isset($where_params['DTT_EVT_start'])) { |
|
421 | + $where_params['Datetime.DTT_EVT_start******'] = $where_params['DTT_EVT_start']; |
|
422 | + } |
|
423 | + if (isset($where_params['Datetime.DTT_EVT_end'])) { |
|
424 | + $where_params['Datetime.DTT_EVT_end*****'] = $where_params['DTT_EVT_end']; |
|
425 | + } |
|
426 | + $where_params['DTT_EVT_start'] = array('<', $current_time_for_DTT_EVT_start); |
|
427 | + $where_params['DTT_EVT_end'] = array('>', $current_time_for_DTT_EVT_end); |
|
428 | + break; |
|
429 | + case 'inactive' : |
|
430 | + if (isset($where_params['Event.status'])) { |
|
431 | + unset($where_params['Event.status']); |
|
432 | + } |
|
433 | + if (isset($where_params['OR'])) { |
|
434 | + $where_params['AND']['OR'] = $where_params['OR']; |
|
435 | + } |
|
436 | + if (isset($where_params['DTT_EVT_end'])) { |
|
437 | + $where_params['AND']['DTT_EVT_end****'] = $where_params['DTT_EVT_end']; |
|
438 | + unset($where_params['DTT_EVT_end']); |
|
439 | + } |
|
440 | + if (isset($where_params['DTT_EVT_start'])) { |
|
441 | + $where_params['AND']['DTT_EVT_start'] = $where_params['DTT_EVT_start']; |
|
442 | + unset($where_params['DTT_EVT_start']); |
|
443 | + } |
|
444 | + $where_params['AND']['Event.status'] = array('!=', 'publish'); |
|
445 | + break; |
|
446 | + } |
|
447 | + $query_params[0] = $where_params; |
|
448 | + $query_params['group_by'] = array('dtt_year', 'dtt_month'); |
|
449 | + $query_params['order_by'] = array('DTT_EVT_start' => 'DESC'); |
|
450 | + $query_interval = EEH_DTT_Helper::get_sql_query_interval_for_offset($this->get_timezone(), 'DTT_EVT_start'); |
|
451 | + $columns_to_select = array( |
|
452 | + 'dtt_year' => array('YEAR(' . $query_interval . ')', '%s'), |
|
453 | + 'dtt_month' => array('MONTHNAME(' . $query_interval . ')', '%s'), |
|
454 | + 'dtt_month_num' => array('MONTH(' . $query_interval . ')', '%s'), |
|
455 | + ); |
|
456 | + return $this->_get_all_wpdb_results($query_params, OBJECT, $columns_to_select); |
|
457 | + } |
|
458 | + |
|
459 | + |
|
460 | + |
|
461 | + /** |
|
462 | + * Updates the DTT_sold attribute on each datetime (based on the registrations |
|
463 | + * for the tickets for each datetime) |
|
464 | + * |
|
465 | + * @param EE_Datetime[] $datetimes |
|
466 | + */ |
|
467 | + public function update_sold($datetimes) |
|
468 | + { |
|
469 | + foreach ($datetimes as $datetime) { |
|
470 | + $datetime->update_sold(); |
|
471 | + } |
|
472 | + } |
|
473 | + |
|
474 | + |
|
475 | + |
|
476 | + /** |
|
477 | + * Gets the total number of tickets available at a particular datetime |
|
478 | + * (does NOT take into account the datetime's spaces available) |
|
479 | + * |
|
480 | + * @param int $DTT_ID |
|
481 | + * @param array $query_params |
|
482 | + * @return int of tickets available. If sold out, return less than 1. If infinite, returns EE_INF, IF there are NO |
|
483 | + * tickets attached to datetime then FALSE is returned. |
|
484 | + */ |
|
485 | + public function sum_tickets_currently_available_at_datetime($DTT_ID, $query_params = array()) |
|
486 | + { |
|
487 | + $datetime = $this->get_one_by_ID($DTT_ID); |
|
488 | + if ($datetime instanceof EE_Datetime) { |
|
489 | + return $datetime->tickets_remaining($query_params); |
|
490 | + } |
|
491 | + return 0; |
|
492 | + } |
|
493 | + |
|
494 | + |
|
495 | + |
|
496 | + /** |
|
497 | + * This returns an array of counts of datetimes in the database for each Datetime status that can be queried. |
|
498 | + * |
|
499 | + * @param array $stati_to_include If included you can restrict the statuses we return counts for by including the |
|
500 | + * stati you want counts for as values in the array. An empty array returns counts |
|
501 | + * for all valid stati. |
|
502 | + * @param array $query_params If included can be used to refine the conditions for returning the count (i.e. |
|
503 | + * only for Datetimes connected to a specific event, or specific ticket. |
|
504 | + * @return array The value returned is an array indexed by Datetime Status and the values are the counts. The |
|
505 | + * stati used as index keys are: EE_Datetime::active EE_Datetime::upcoming EE_Datetime::expired |
|
506 | + */ |
|
507 | + public function get_datetime_counts_by_status($stati_to_include = array(), $query_params = array()) |
|
508 | + { |
|
509 | + //only accept where conditions for this query. |
|
510 | + $_where = isset($query_params[0]) ? $query_params[0] : array(); |
|
511 | + $status_query_args = array( |
|
512 | + EE_Datetime::active => array_merge( |
|
513 | + $_where, |
|
514 | + array('DTT_EVT_start' => array('<', time()), 'DTT_EVT_end' => array('>', time())) |
|
515 | + ), |
|
516 | + EE_Datetime::upcoming => array_merge( |
|
517 | + $_where, |
|
518 | + array('DTT_EVT_start' => array('>', time())) |
|
519 | + ), |
|
520 | + EE_Datetime::expired => array_merge( |
|
521 | + $_where, |
|
522 | + array('DTT_EVT_end' => array('<', time())) |
|
523 | + ), |
|
524 | + ); |
|
525 | + if ( ! empty($stati_to_include)) { |
|
526 | + foreach (array_keys($status_query_args) as $status) { |
|
527 | + if ( ! in_array($status, $stati_to_include)) { |
|
528 | + unset($status_query_args[$status]); |
|
529 | + } |
|
530 | + } |
|
531 | + } |
|
532 | + //loop through and query counts for each stati. |
|
533 | + $status_query_results = array(); |
|
534 | + foreach ($status_query_args as $status => $status_where_conditions) { |
|
535 | + $status_query_results[$status] = EEM_Datetime::count(array($status_where_conditions), 'DTT_ID', true); |
|
536 | + } |
|
537 | + return $status_query_results; |
|
538 | + } |
|
539 | + |
|
540 | + |
|
541 | + |
|
542 | + /** |
|
543 | + * Returns the specific count for a given Datetime status matching any given query_params. |
|
544 | + * |
|
545 | + * @param string $status Valid string representation for Datetime status requested. (Defaults to Active). |
|
546 | + * @param array $query_params |
|
547 | + * @return int |
|
548 | + */ |
|
549 | + public function get_datetime_count_for_status($status = EE_Datetime::active, $query_params = array()) |
|
550 | + { |
|
551 | + $count = $this->get_datetime_counts_by_status(array($status), $query_params); |
|
552 | + return ! empty($count[$status]) ? $count[$status] : 0; |
|
553 | + } |
|
554 | 554 | |
555 | 555 | |
556 | 556 |
@@ -1,16 +1,16 @@ discard block |
||
1 | 1 | <?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('No direct script access allowed'); } |
2 | 2 | /** |
3 | - * |
|
4 | - * Class EE_SPCO_Reg_Step_Attendee_Information |
|
5 | - * |
|
6 | - * Description |
|
7 | - * |
|
8 | - * @package Event Espresso |
|
9 | - * @subpackage core |
|
10 | - * @author Brent Christensen |
|
11 | - * @since 4.5.0 |
|
12 | - * |
|
13 | - */ |
|
3 | + * |
|
4 | + * Class EE_SPCO_Reg_Step_Attendee_Information |
|
5 | + * |
|
6 | + * Description |
|
7 | + * |
|
8 | + * @package Event Espresso |
|
9 | + * @subpackage core |
|
10 | + * @author Brent Christensen |
|
11 | + * @since 4.5.0 |
|
12 | + * |
|
13 | + */ |
|
14 | 14 | class EE_SPCO_Reg_Step_Attendee_Information extends EE_SPCO_Reg_Step { |
15 | 15 | |
16 | 16 | /** |
@@ -135,33 +135,33 @@ discard block |
||
135 | 135 | $registration instanceof EE_Registration |
136 | 136 | && $this->checkout->visit_allows_processing_of_this_registration( $registration ) |
137 | 137 | ) { |
138 | - $attendee_reg_form = $this->_registrations_reg_form($registration); |
|
139 | - if ($attendee_reg_form instanceof EE_Form_Section_Proper) { |
|
140 | - $subsections[$registration->reg_url_link()] = $attendee_reg_form; |
|
141 | - if ( ! $this->checkout->admin_request) { |
|
142 | - $template_args['registrations'][$registration->reg_url_link()] = $registration; |
|
143 | - $template_args['ticket_count'][$registration->ticket()->ID()] = isset( |
|
144 | - $template_args['ticket_count'][$registration->ticket()->ID()] |
|
145 | - ) |
|
146 | - ? $template_args['ticket_count'][$registration->ticket()->ID()] + 1 |
|
147 | - : 1; |
|
148 | - $ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
149 | - $this->checkout->cart->get_grand_total(), |
|
150 | - 'Ticket', |
|
151 | - array($registration->ticket()->ID()) |
|
152 | - ); |
|
153 | - $ticket_line_item = is_array($ticket_line_item) |
|
154 | - ? reset($ticket_line_item) |
|
155 | - : $ticket_line_item; |
|
156 | - $template_args['ticket_line_item'][$registration->ticket() |
|
157 | - ->ID()] = $Line_Item_Display->display_line_item( |
|
158 | - $ticket_line_item |
|
159 | - ); |
|
160 | - } |
|
161 | - } |
|
162 | - if ($registration->is_primary_registrant()) { |
|
163 | - $primary_registrant = $registration->reg_url_link(); |
|
164 | - } |
|
138 | + $attendee_reg_form = $this->_registrations_reg_form($registration); |
|
139 | + if ($attendee_reg_form instanceof EE_Form_Section_Proper) { |
|
140 | + $subsections[$registration->reg_url_link()] = $attendee_reg_form; |
|
141 | + if ( ! $this->checkout->admin_request) { |
|
142 | + $template_args['registrations'][$registration->reg_url_link()] = $registration; |
|
143 | + $template_args['ticket_count'][$registration->ticket()->ID()] = isset( |
|
144 | + $template_args['ticket_count'][$registration->ticket()->ID()] |
|
145 | + ) |
|
146 | + ? $template_args['ticket_count'][$registration->ticket()->ID()] + 1 |
|
147 | + : 1; |
|
148 | + $ticket_line_item = EEH_Line_Item::get_line_items_by_object_type_and_IDs( |
|
149 | + $this->checkout->cart->get_grand_total(), |
|
150 | + 'Ticket', |
|
151 | + array($registration->ticket()->ID()) |
|
152 | + ); |
|
153 | + $ticket_line_item = is_array($ticket_line_item) |
|
154 | + ? reset($ticket_line_item) |
|
155 | + : $ticket_line_item; |
|
156 | + $template_args['ticket_line_item'][$registration->ticket() |
|
157 | + ->ID()] = $Line_Item_Display->display_line_item( |
|
158 | + $ticket_line_item |
|
159 | + ); |
|
160 | + } |
|
161 | + } |
|
162 | + if ($registration->is_primary_registrant()) { |
|
163 | + $primary_registrant = $registration->reg_url_link(); |
|
164 | + } |
|
165 | 165 | } |
166 | 166 | } |
167 | 167 | // print_copy_info ? |
@@ -173,7 +173,7 @@ discard block |
||
173 | 173 | // generate hidden input |
174 | 174 | if ( |
175 | 175 | isset( $subsections[ $primary_registrant ] ) |
176 | - && $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper |
|
176 | + && $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper |
|
177 | 177 | ) { |
178 | 178 | $subsections[ $primary_registrant ]->add_subsections( $copy_options, 'primary_registrant', false ); |
179 | 179 | } |
@@ -208,35 +208,35 @@ discard block |
||
208 | 208 | */ |
209 | 209 | private function _registrations_reg_form( EE_Registration $registration ) { |
210 | 210 | static $attendee_nmbr = 1; |
211 | - $form_args = array(); |
|
211 | + $form_args = array(); |
|
212 | 212 | // verify that registration has valid event |
213 | 213 | if ( $registration->event() instanceof EE_Event ) { |
214 | 214 | $question_groups = $registration->event()->question_groups( |
215 | - array( |
|
216 | - array( |
|
217 | - 'Event.EVT_ID' => $registration->event()->ID(), |
|
218 | - 'Event_Question_Group.EQG_primary' => $registration->count() === 1 ? true : false |
|
219 | - ), |
|
220 | - 'order_by' => array('QSG_order' => 'ASC') |
|
221 | - ) |
|
222 | - ); |
|
215 | + array( |
|
216 | + array( |
|
217 | + 'Event.EVT_ID' => $registration->event()->ID(), |
|
218 | + 'Event_Question_Group.EQG_primary' => $registration->count() === 1 ? true : false |
|
219 | + ), |
|
220 | + 'order_by' => array('QSG_order' => 'ASC') |
|
221 | + ) |
|
222 | + ); |
|
223 | 223 | if ( $question_groups ) { |
224 | - // array of params to pass to parent constructor |
|
225 | - $form_args = array( |
|
226 | - 'html_id' => 'ee-registration-' . $registration->reg_url_link(), |
|
227 | - 'html_class' => 'ee-reg-form-attendee-dv', |
|
228 | - 'html_style' => $this->checkout->admin_request |
|
229 | - ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;' |
|
230 | - : '', |
|
231 | - 'subsections' => array(), |
|
232 | - 'layout_strategy' => new EE_Fieldset_Section_Layout( |
|
233 | - array( |
|
234 | - 'legend_class' => 'spco-attendee-lgnd smaller-text lt-grey-text', |
|
235 | - 'legend_text' => sprintf(__('Attendee %d', 'event_espresso'), $attendee_nmbr) |
|
236 | - ) |
|
237 | - ) |
|
238 | - ); |
|
239 | - foreach ( $question_groups as $question_group ) { |
|
224 | + // array of params to pass to parent constructor |
|
225 | + $form_args = array( |
|
226 | + 'html_id' => 'ee-registration-' . $registration->reg_url_link(), |
|
227 | + 'html_class' => 'ee-reg-form-attendee-dv', |
|
228 | + 'html_style' => $this->checkout->admin_request |
|
229 | + ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;' |
|
230 | + : '', |
|
231 | + 'subsections' => array(), |
|
232 | + 'layout_strategy' => new EE_Fieldset_Section_Layout( |
|
233 | + array( |
|
234 | + 'legend_class' => 'spco-attendee-lgnd smaller-text lt-grey-text', |
|
235 | + 'legend_text' => sprintf(__('Attendee %d', 'event_espresso'), $attendee_nmbr) |
|
236 | + ) |
|
237 | + ) |
|
238 | + ); |
|
239 | + foreach ( $question_groups as $question_group ) { |
|
240 | 240 | if ( $question_group instanceof EE_Question_Group ) { |
241 | 241 | $form_args['subsections'][ $question_group->identifier() ] = $this->_question_group_reg_form( |
242 | 242 | $registration, |
@@ -244,19 +244,19 @@ discard block |
||
244 | 244 | ); |
245 | 245 | } |
246 | 246 | } |
247 | - // add hidden input |
|
248 | - $form_args['subsections']['additional_attendee_reg_info'] = $this->_additional_attendee_reg_info_input( |
|
249 | - $registration |
|
250 | - ); |
|
251 | - // if we have question groups for additional attendees, then display the copy options |
|
247 | + // add hidden input |
|
248 | + $form_args['subsections']['additional_attendee_reg_info'] = $this->_additional_attendee_reg_info_input( |
|
249 | + $registration |
|
250 | + ); |
|
251 | + // if we have question groups for additional attendees, then display the copy options |
|
252 | 252 | $this->_print_copy_info = $attendee_nmbr > 1 ? true : $this->_print_copy_info; |
253 | - if ($registration->is_primary_registrant()) { |
|
254 | - // generate hidden input |
|
255 | - $form_args['subsections']['primary_registrant'] = $this->_additional_primary_registrant_inputs($registration); |
|
256 | - } |
|
257 | - } |
|
253 | + if ($registration->is_primary_registrant()) { |
|
254 | + // generate hidden input |
|
255 | + $form_args['subsections']['primary_registrant'] = $this->_additional_primary_registrant_inputs($registration); |
|
256 | + } |
|
257 | + } |
|
258 | 258 | } |
259 | - $attendee_nmbr++; |
|
259 | + $attendee_nmbr++; |
|
260 | 260 | return ! empty($form_args) ? new EE_Form_Section_Proper( $form_args ) : null; |
261 | 261 | } |
262 | 262 | |
@@ -889,7 +889,7 @@ discard block |
||
889 | 889 | if ( isset( $valid_data[ $reg_url_link ] ) ) { |
890 | 890 | // do we need to copy basic info from primary attendee ? |
891 | 891 | $copy_primary = isset( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] ) |
892 | - && absint( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] ) === 0 |
|
892 | + && absint( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] ) === 0 |
|
893 | 893 | ? true |
894 | 894 | : false; |
895 | 895 | // filter form input data for this registration |
@@ -1064,7 +1064,7 @@ discard block |
||
1064 | 1064 | ? $form_input |
1065 | 1065 | : $form_input . '-' . $registration->reg_url_link(); |
1066 | 1066 | $answer_is_obj = isset( $this->_registration_answers[ $answer_cache_id ] ) |
1067 | - && $this->_registration_answers[ $answer_cache_id ] instanceof EE_Answer |
|
1067 | + && $this->_registration_answers[ $answer_cache_id ] instanceof EE_Answer |
|
1068 | 1068 | ? true |
1069 | 1069 | : false; |
1070 | 1070 | //rename form_inputs if they are EE_Attendee properties |
@@ -1184,7 +1184,7 @@ discard block |
||
1184 | 1184 | // then attempt to copy them from the primary attendee |
1185 | 1185 | if ( |
1186 | 1186 | $this->checkout->primary_attendee_obj instanceof EE_Attendee |
1187 | - && ! isset( $attendee_data['ATT_fname'], $attendee_data['ATT_email'] ) |
|
1187 | + && ! isset( $attendee_data['ATT_fname'], $attendee_data['ATT_email'] ) |
|
1188 | 1188 | ) { |
1189 | 1189 | return $this->checkout->primary_attendee_obj; |
1190 | 1190 | } |
@@ -1302,7 +1302,7 @@ discard block |
||
1302 | 1302 | } |
1303 | 1303 | foreach ( $critical_attendee_details as $critical_attendee_detail ) { |
1304 | 1304 | if ( ! isset( $attendee_data[ $critical_attendee_detail ] ) |
1305 | - || empty( $attendee_data[ $critical_attendee_detail ] ) |
|
1305 | + || empty( $attendee_data[ $critical_attendee_detail ] ) |
|
1306 | 1306 | ) { |
1307 | 1307 | $attendee_data[ $critical_attendee_detail ] = $this->checkout->primary_attendee_obj->get( |
1308 | 1308 | $critical_attendee_detail |
@@ -41,21 +41,21 @@ discard block |
||
41 | 41 | * @access public |
42 | 42 | * @param EE_Checkout $checkout |
43 | 43 | */ |
44 | - public function __construct( EE_Checkout $checkout ) { |
|
44 | + public function __construct(EE_Checkout $checkout) { |
|
45 | 45 | $this->_slug = 'attendee_information'; |
46 | 46 | $this->_name = __('Attendee Information', 'event_espresso'); |
47 | - $this->_template = SPCO_REG_STEPS_PATH . $this->_slug . DS . 'attendee_info_main.template.php'; |
|
47 | + $this->_template = SPCO_REG_STEPS_PATH.$this->_slug.DS.'attendee_info_main.template.php'; |
|
48 | 48 | $this->checkout = $checkout; |
49 | 49 | $this->_reset_success_message(); |
50 | 50 | $this->set_instructions( |
51 | - __( 'Please answer the following registration questions before proceeding.', 'event_espresso' ) |
|
51 | + __('Please answer the following registration questions before proceeding.', 'event_espresso') |
|
52 | 52 | ); |
53 | 53 | } |
54 | 54 | |
55 | 55 | |
56 | 56 | |
57 | 57 | public function translate_js_strings() { |
58 | - EE_Registry::$i18n_js_strings['required_field'] = __( ' is a required question.', 'event_espresso' ); |
|
58 | + EE_Registry::$i18n_js_strings['required_field'] = __(' is a required question.', 'event_espresso'); |
|
59 | 59 | EE_Registry::$i18n_js_strings['required_multi_field'] = __( |
60 | 60 | ' is a required question. Please enter a value for at least one of the options.', |
61 | 61 | 'event_espresso' |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | // calculate taxes |
116 | 116 | $Line_Item_Display->display_line_item( |
117 | 117 | $this->checkout->cart->get_grand_total(), |
118 | - array( 'set_tax_rate' => true ) |
|
118 | + array('set_tax_rate' => true) |
|
119 | 119 | ); |
120 | 120 | /** @var $subsections EE_Form_Section_Proper[] */ |
121 | 121 | $subsections = array( |
@@ -127,13 +127,13 @@ discard block |
||
127 | 127 | 'ticket_count' => array() |
128 | 128 | ); |
129 | 129 | // grab the saved registrations from the transaction |
130 | - $registrations = $this->checkout->transaction->registrations( $this->checkout->reg_cache_where_params ); |
|
131 | - if ( $registrations ) { |
|
132 | - foreach ( $registrations as $registration ) { |
|
130 | + $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
131 | + if ($registrations) { |
|
132 | + foreach ($registrations as $registration) { |
|
133 | 133 | // can this registration be processed during this visit ? |
134 | 134 | if ( |
135 | 135 | $registration instanceof EE_Registration |
136 | - && $this->checkout->visit_allows_processing_of_this_registration( $registration ) |
|
136 | + && $this->checkout->visit_allows_processing_of_this_registration($registration) |
|
137 | 137 | ) { |
138 | 138 | $attendee_reg_form = $this->_registrations_reg_form($registration); |
139 | 139 | if ($attendee_reg_form instanceof EE_Form_Section_Proper) { |
@@ -165,17 +165,17 @@ discard block |
||
165 | 165 | } |
166 | 166 | } |
167 | 167 | // print_copy_info ? |
168 | - if ( $primary_registrant && ! $this->checkout->admin_request && count( $registrations ) > 1 ) { |
|
168 | + if ($primary_registrant && ! $this->checkout->admin_request && count($registrations) > 1) { |
|
169 | 169 | // TODO: add admin option for toggling copy attendee info, then use that value to change $this->_print_copy_info |
170 | 170 | $copy_options['spco_copy_attendee_chk'] = $this->_print_copy_info |
171 | 171 | ? $this->_copy_attendee_info_form() |
172 | 172 | : $this->_auto_copy_attendee_info(); |
173 | 173 | // generate hidden input |
174 | 174 | if ( |
175 | - isset( $subsections[ $primary_registrant ] ) |
|
176 | - && $subsections[ $primary_registrant ] instanceof EE_Form_Section_Proper |
|
175 | + isset($subsections[$primary_registrant]) |
|
176 | + && $subsections[$primary_registrant] instanceof EE_Form_Section_Proper |
|
177 | 177 | ) { |
178 | - $subsections[ $primary_registrant ]->add_subsections( $copy_options, 'primary_registrant', false ); |
|
178 | + $subsections[$primary_registrant]->add_subsections($copy_options, 'primary_registrant', false); |
|
179 | 179 | } |
180 | 180 | } |
181 | 181 | |
@@ -187,8 +187,7 @@ discard block |
||
187 | 187 | 'html_id' => $this->reg_form_name(), |
188 | 188 | 'subsections' => $subsections, |
189 | 189 | 'layout_strategy' => $this->checkout->admin_request ? |
190 | - new EE_Div_Per_Section_Layout() : |
|
191 | - new EE_Template_Layout( |
|
190 | + new EE_Div_Per_Section_Layout() : new EE_Template_Layout( |
|
192 | 191 | array( |
193 | 192 | 'layout_template_file' => $this->_template, // layout_template |
194 | 193 | 'template_args' => $template_args |
@@ -206,11 +205,11 @@ discard block |
||
206 | 205 | * @return EE_Form_Section_Proper |
207 | 206 | * @throws \EE_Error |
208 | 207 | */ |
209 | - private function _registrations_reg_form( EE_Registration $registration ) { |
|
208 | + private function _registrations_reg_form(EE_Registration $registration) { |
|
210 | 209 | static $attendee_nmbr = 1; |
211 | 210 | $form_args = array(); |
212 | 211 | // verify that registration has valid event |
213 | - if ( $registration->event() instanceof EE_Event ) { |
|
212 | + if ($registration->event() instanceof EE_Event) { |
|
214 | 213 | $question_groups = $registration->event()->question_groups( |
215 | 214 | array( |
216 | 215 | array( |
@@ -220,10 +219,10 @@ discard block |
||
220 | 219 | 'order_by' => array('QSG_order' => 'ASC') |
221 | 220 | ) |
222 | 221 | ); |
223 | - if ( $question_groups ) { |
|
222 | + if ($question_groups) { |
|
224 | 223 | // array of params to pass to parent constructor |
225 | 224 | $form_args = array( |
226 | - 'html_id' => 'ee-registration-' . $registration->reg_url_link(), |
|
225 | + 'html_id' => 'ee-registration-'.$registration->reg_url_link(), |
|
227 | 226 | 'html_class' => 'ee-reg-form-attendee-dv', |
228 | 227 | 'html_style' => $this->checkout->admin_request |
229 | 228 | ? 'padding:0em 2em 1em; margin:3em 0 0; border:1px solid #ddd;' |
@@ -236,9 +235,9 @@ discard block |
||
236 | 235 | ) |
237 | 236 | ) |
238 | 237 | ); |
239 | - foreach ( $question_groups as $question_group ) { |
|
240 | - if ( $question_group instanceof EE_Question_Group ) { |
|
241 | - $form_args['subsections'][ $question_group->identifier() ] = $this->_question_group_reg_form( |
|
238 | + foreach ($question_groups as $question_group) { |
|
239 | + if ($question_group instanceof EE_Question_Group) { |
|
240 | + $form_args['subsections'][$question_group->identifier()] = $this->_question_group_reg_form( |
|
242 | 241 | $registration, |
243 | 242 | $question_group |
244 | 243 | ); |
@@ -257,7 +256,7 @@ discard block |
||
257 | 256 | } |
258 | 257 | } |
259 | 258 | $attendee_nmbr++; |
260 | - return ! empty($form_args) ? new EE_Form_Section_Proper( $form_args ) : null; |
|
259 | + return ! empty($form_args) ? new EE_Form_Section_Proper($form_args) : null; |
|
261 | 260 | } |
262 | 261 | |
263 | 262 | |
@@ -278,7 +277,7 @@ discard block |
||
278 | 277 | // generate hidden input |
279 | 278 | return new EE_Hidden_Input( |
280 | 279 | array( |
281 | - 'html_id' => 'additional-attendee-reg-info-' . $registration->reg_url_link(), |
|
280 | + 'html_id' => 'additional-attendee-reg-info-'.$registration->reg_url_link(), |
|
282 | 281 | 'default' => $additional_attendee_reg_info |
283 | 282 | ) |
284 | 283 | ); |
@@ -292,26 +291,26 @@ discard block |
||
292 | 291 | * @return EE_Form_Section_Proper |
293 | 292 | * @throws \EE_Error |
294 | 293 | */ |
295 | - private function _question_group_reg_form( EE_Registration $registration, EE_Question_Group $question_group ){ |
|
294 | + private function _question_group_reg_form(EE_Registration $registration, EE_Question_Group $question_group) { |
|
296 | 295 | // array of params to pass to parent constructor |
297 | 296 | $form_args = array( |
298 | - 'html_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier(), |
|
297 | + 'html_id' => 'ee-reg-form-qstn-grp-'.$question_group->identifier(), |
|
299 | 298 | 'html_class' => $this->checkout->admin_request |
300 | 299 | ? 'form-table ee-reg-form-qstn-grp-dv' |
301 | 300 | : 'ee-reg-form-qstn-grp-dv', |
302 | - 'html_label_id' => 'ee-reg-form-qstn-grp-' . $question_group->identifier() . '-lbl', |
|
301 | + 'html_label_id' => 'ee-reg-form-qstn-grp-'.$question_group->identifier().'-lbl', |
|
303 | 302 | 'subsections' => array( |
304 | - 'reg_form_qstn_grp_hdr' => $this->_question_group_header( $question_group ) |
|
303 | + 'reg_form_qstn_grp_hdr' => $this->_question_group_header($question_group) |
|
305 | 304 | ), |
306 | 305 | 'layout_strategy' => $this->checkout->admin_request |
307 | 306 | ? new EE_Admin_Two_Column_Layout() |
308 | 307 | : new EE_Div_Per_Section_Layout() |
309 | 308 | ); |
310 | 309 | // where params |
311 | - $query_params = array( 'QST_deleted' => 0 ); |
|
310 | + $query_params = array('QST_deleted' => 0); |
|
312 | 311 | // don't load admin only questions on the frontend |
313 | - if ( ! $this->checkout->admin_request ) { |
|
314 | - $query_params['QST_admin_only'] = array( '!=', true ); |
|
312 | + if ( ! $this->checkout->admin_request) { |
|
313 | + $query_params['QST_admin_only'] = array('!=', true); |
|
315 | 314 | } |
316 | 315 | $questions = $question_group->get_many_related( |
317 | 316 | 'Question', |
@@ -333,10 +332,10 @@ discard block |
||
333 | 332 | ) |
334 | 333 | ); |
335 | 334 | // loop thru questions |
336 | - foreach ( $questions as $question ) { |
|
337 | - if( $question instanceof EE_Question ){ |
|
335 | + foreach ($questions as $question) { |
|
336 | + if ($question instanceof EE_Question) { |
|
338 | 337 | $identifier = $question->is_system_question() ? $question->system_ID() : $question->ID(); |
339 | - $form_args['subsections'][ $identifier ] = $this->reg_form_question( $registration, $question ); |
|
338 | + $form_args['subsections'][$identifier] = $this->reg_form_question($registration, $question); |
|
340 | 339 | } |
341 | 340 | } |
342 | 341 | $form_args['subsections'] = apply_filters( |
@@ -357,7 +356,7 @@ discard block |
||
357 | 356 | ) |
358 | 357 | ); |
359 | 358 | // d( $form_args ); |
360 | - $question_group_reg_form = new EE_Form_Section_Proper( $form_args ); |
|
359 | + $question_group_reg_form = new EE_Form_Section_Proper($form_args); |
|
361 | 360 | return apply_filters( |
362 | 361 | 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___question_group_reg_form__question_group_reg_form', |
363 | 362 | $question_group_reg_form, |
@@ -374,11 +373,11 @@ discard block |
||
374 | 373 | * @param EE_Question_Group $question_group |
375 | 374 | * @return EE_Form_Section_HTML |
376 | 375 | */ |
377 | - private function _question_group_header( EE_Question_Group $question_group ){ |
|
376 | + private function _question_group_header(EE_Question_Group $question_group) { |
|
378 | 377 | $html = ''; |
379 | 378 | // group_name |
380 | - if ( $question_group->show_group_name() && $question_group->name() !== '' ) { |
|
381 | - if ( $this->checkout->admin_request ) { |
|
379 | + if ($question_group->show_group_name() && $question_group->name() !== '') { |
|
380 | + if ($this->checkout->admin_request) { |
|
382 | 381 | $html .= EEH_HTML::br(); |
383 | 382 | $html .= EEH_HTML::h3( |
384 | 383 | $question_group->name(), |
@@ -392,7 +391,7 @@ discard block |
||
392 | 391 | } |
393 | 392 | } |
394 | 393 | // group_desc |
395 | - if ( $question_group->show_group_desc() && $question_group->desc() !== '' ) { |
|
394 | + if ($question_group->show_group_desc() && $question_group->desc() !== '') { |
|
396 | 395 | $html .= EEH_HTML::p( |
397 | 396 | $question_group->desc(), |
398 | 397 | '', |
@@ -402,7 +401,7 @@ discard block |
||
402 | 401 | ); |
403 | 402 | |
404 | 403 | } |
405 | - return new EE_Form_Section_HTML( $html ); |
|
404 | + return new EE_Form_Section_HTML($html); |
|
406 | 405 | } |
407 | 406 | |
408 | 407 | |
@@ -412,7 +411,7 @@ discard block |
||
412 | 411 | * @return EE_Form_Section_Proper |
413 | 412 | * @throws \EE_Error |
414 | 413 | */ |
415 | - private function _copy_attendee_info_form(){ |
|
414 | + private function _copy_attendee_info_form() { |
|
416 | 415 | // array of params to pass to parent constructor |
417 | 416 | return new EE_Form_Section_Proper( |
418 | 417 | array( |
@@ -441,7 +440,7 @@ discard block |
||
441 | 440 | private function _auto_copy_attendee_info() { |
442 | 441 | return new EE_Form_Section_HTML( |
443 | 442 | EEH_Template::locate_template( |
444 | - SPCO_REG_STEPS_PATH . $this->_slug . DS . '_auto_copy_attendee_info.template.php', |
|
443 | + SPCO_REG_STEPS_PATH.$this->_slug.DS.'_auto_copy_attendee_info.template.php', |
|
445 | 444 | apply_filters( |
446 | 445 | 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__auto_copy_attendee_info__template_args', |
447 | 446 | array() |
@@ -465,32 +464,32 @@ discard block |
||
465 | 464 | $copy_attendee_info_inputs = array(); |
466 | 465 | $prev_ticket = NULL; |
467 | 466 | // grab the saved registrations from the transaction |
468 | - $registrations = $this->checkout->transaction->registrations( $this->checkout->reg_cache_where_params ); |
|
469 | - foreach ( $registrations as $registration ) { |
|
467 | + $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
468 | + foreach ($registrations as $registration) { |
|
470 | 469 | // for all attendees other than the primary attendee |
471 | - if ( $registration instanceof EE_Registration && ! $registration->is_primary_registrant() ) { |
|
470 | + if ($registration instanceof EE_Registration && ! $registration->is_primary_registrant()) { |
|
472 | 471 | // if this is a new ticket OR if this is the very first additional attendee after the primary attendee |
473 | - if ( $registration->ticket()->ID() !== $prev_ticket ) { |
|
472 | + if ($registration->ticket()->ID() !== $prev_ticket) { |
|
474 | 473 | $item_name = $registration->ticket()->name(); |
475 | 474 | $item_name .= $registration->ticket()->description() !== '' |
476 | - ? ' - ' . $registration->ticket()->description() |
|
475 | + ? ' - '.$registration->ticket()->description() |
|
477 | 476 | : ''; |
478 | - $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[ticket-' . $registration->ticket()->ID() . ']' ] = new EE_Form_Section_HTML( |
|
479 | - '<h6 class="spco-copy-attendee-event-hdr">' . $item_name . '</h6>' |
|
477 | + $copy_attendee_info_inputs['spco_copy_attendee_chk[ticket-'.$registration->ticket()->ID().']'] = new EE_Form_Section_HTML( |
|
478 | + '<h6 class="spco-copy-attendee-event-hdr">'.$item_name.'</h6>' |
|
480 | 479 | ); |
481 | 480 | $prev_ticket = $registration->ticket()->ID(); |
482 | 481 | } |
483 | 482 | |
484 | - $copy_attendee_info_inputs[ 'spco_copy_attendee_chk[' . $registration->ID() . ']' ] = new |
|
483 | + $copy_attendee_info_inputs['spco_copy_attendee_chk['.$registration->ID().']'] = new |
|
485 | 484 | EE_Checkbox_Multi_Input( |
486 | 485 | array( |
487 | 486 | $registration->ID() => sprintf( |
488 | - __( 'Attendee #%s', 'event_espresso' ), |
|
487 | + __('Attendee #%s', 'event_espresso'), |
|
489 | 488 | $registration->count() |
490 | 489 | ) |
491 | 490 | ), |
492 | 491 | array( |
493 | - 'html_id' => 'spco-copy-attendee-chk-' . $registration->reg_url_link(), |
|
492 | + 'html_id' => 'spco-copy-attendee-chk-'.$registration->reg_url_link(), |
|
494 | 493 | 'html_class' => 'spco-copy-attendee-chk ee-do-not-validate', |
495 | 494 | 'display_html_label_text' => false |
496 | 495 | ) |
@@ -510,7 +509,7 @@ discard block |
||
510 | 509 | * @return EE_Form_Input_Base |
511 | 510 | * @throws \EE_Error |
512 | 511 | */ |
513 | - private function _additional_primary_registrant_inputs( EE_Registration $registration ){ |
|
512 | + private function _additional_primary_registrant_inputs(EE_Registration $registration) { |
|
514 | 513 | // generate hidden input |
515 | 514 | return new EE_Hidden_Input( |
516 | 515 | array( |
@@ -529,7 +528,7 @@ discard block |
||
529 | 528 | * @return EE_Form_Input_Base |
530 | 529 | * @throws \EE_Error |
531 | 530 | */ |
532 | - public function reg_form_question( EE_Registration $registration, EE_Question $question ){ |
|
531 | + public function reg_form_question(EE_Registration $registration, EE_Question $question) { |
|
533 | 532 | |
534 | 533 | // if this question was for an attendee detail, then check for that answer |
535 | 534 | $answer_value = EEM_Answer::instance()->get_attendee_property_answer_value( |
@@ -538,32 +537,32 @@ discard block |
||
538 | 537 | ); |
539 | 538 | $answer = $answer_value === null |
540 | 539 | ? EEM_Answer::instance()->get_one( |
541 | - array( array( 'QST_ID' => $question->ID(), 'REG_ID' => $registration->ID() ) ) |
|
540 | + array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID())) |
|
542 | 541 | ) |
543 | 542 | : null; |
544 | 543 | // if NOT returning to edit an existing registration |
545 | 544 | // OR if this question is for an attendee property |
546 | 545 | // OR we still don't have an EE_Answer object |
547 | - if( $answer_value || ! $answer instanceof EE_Answer || ! $registration->reg_url_link() ) { |
|
546 | + if ($answer_value || ! $answer instanceof EE_Answer || ! $registration->reg_url_link()) { |
|
548 | 547 | // create an EE_Answer object for storing everything in |
549 | - $answer = EE_Answer::new_instance ( array( |
|
548 | + $answer = EE_Answer::new_instance(array( |
|
550 | 549 | 'QST_ID'=> $question->ID(), |
551 | 550 | 'REG_ID'=> $registration->ID() |
552 | 551 | )); |
553 | 552 | } |
554 | 553 | // verify instance |
555 | - if( $answer instanceof EE_Answer ){ |
|
556 | - if ( ! empty( $answer_value )) { |
|
557 | - $answer->set( 'ANS_value', $answer_value ); |
|
554 | + if ($answer instanceof EE_Answer) { |
|
555 | + if ( ! empty($answer_value)) { |
|
556 | + $answer->set('ANS_value', $answer_value); |
|
558 | 557 | } |
559 | - $answer->cache( 'Question', $question ); |
|
558 | + $answer->cache('Question', $question); |
|
560 | 559 | //remember system ID had a bug where sometimes it could be null |
561 | - $answer_cache_id =$question->is_system_question() |
|
562 | - ? $question->system_ID() . '-' . $registration->reg_url_link() |
|
563 | - : $question->ID() . '-' . $registration->reg_url_link(); |
|
564 | - $registration->cache( 'Answer', $answer, $answer_cache_id ); |
|
560 | + $answer_cache_id = $question->is_system_question() |
|
561 | + ? $question->system_ID().'-'.$registration->reg_url_link() |
|
562 | + : $question->ID().'-'.$registration->reg_url_link(); |
|
563 | + $registration->cache('Answer', $answer, $answer_cache_id); |
|
565 | 564 | } |
566 | - return $this->_generate_question_input( $registration, $question, $answer ); |
|
565 | + return $this->_generate_question_input($registration, $question, $answer); |
|
567 | 566 | |
568 | 567 | } |
569 | 568 | |
@@ -576,46 +575,46 @@ discard block |
||
576 | 575 | * @return EE_Form_Input_Base |
577 | 576 | * @throws \EE_Error |
578 | 577 | */ |
579 | - private function _generate_question_input( EE_Registration $registration, EE_Question $question, $answer ){ |
|
578 | + private function _generate_question_input(EE_Registration $registration, EE_Question $question, $answer) { |
|
580 | 579 | $identifier = $question->is_system_question() ? $question->system_ID() : $question->ID(); |
581 | - $this->_required_questions[ $identifier ] = $question->required() ? true : false; |
|
580 | + $this->_required_questions[$identifier] = $question->required() ? true : false; |
|
582 | 581 | add_filter( |
583 | 582 | 'FHEE__EE_Question__generate_form_input__country_options', |
584 | - array( $this, 'use_cached_countries_for_form_input' ), |
|
583 | + array($this, 'use_cached_countries_for_form_input'), |
|
585 | 584 | 10, |
586 | 585 | 4 |
587 | 586 | ); |
588 | 587 | add_filter( |
589 | 588 | 'FHEE__EE_Question__generate_form_input__state_options', |
590 | - array( $this, 'use_cached_states_for_form_input' ), |
|
589 | + array($this, 'use_cached_states_for_form_input'), |
|
591 | 590 | 10, |
592 | 591 | 4 |
593 | 592 | ); |
594 | 593 | $input_constructor_args = array( |
595 | - 'html_name' => 'ee_reg_qstn[' . $registration->ID() . '][' . $identifier . ']', |
|
596 | - 'html_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
597 | - 'html_class' => 'ee-reg-qstn ee-reg-qstn-' . $identifier, |
|
598 | - 'html_label_id' => 'ee_reg_qstn-' . $registration->ID() . '-' . $identifier, |
|
594 | + 'html_name' => 'ee_reg_qstn['.$registration->ID().']['.$identifier.']', |
|
595 | + 'html_id' => 'ee_reg_qstn-'.$registration->ID().'-'.$identifier, |
|
596 | + 'html_class' => 'ee-reg-qstn ee-reg-qstn-'.$identifier, |
|
597 | + 'html_label_id' => 'ee_reg_qstn-'.$registration->ID().'-'.$identifier, |
|
599 | 598 | 'html_label_class' => 'ee-reg-qstn', |
600 | 599 | ); |
601 | - $input_constructor_args['html_label_id'] .= '-lbl'; |
|
602 | - if ( $answer instanceof EE_Answer && $answer->ID() ) { |
|
603 | - $input_constructor_args[ 'html_name' ] .= '[' . $answer->ID() . ']'; |
|
604 | - $input_constructor_args[ 'html_id' ] .= '-' . $answer->ID(); |
|
605 | - $input_constructor_args[ 'html_label_id' ] .= '-' . $answer->ID(); |
|
600 | + $input_constructor_args['html_label_id'] .= '-lbl'; |
|
601 | + if ($answer instanceof EE_Answer && $answer->ID()) { |
|
602 | + $input_constructor_args['html_name'] .= '['.$answer->ID().']'; |
|
603 | + $input_constructor_args['html_id'] .= '-'.$answer->ID(); |
|
604 | + $input_constructor_args['html_label_id'] .= '-'.$answer->ID(); |
|
606 | 605 | } |
607 | - $form_input = $question->generate_form_input( |
|
606 | + $form_input = $question->generate_form_input( |
|
608 | 607 | $registration, |
609 | 608 | $answer, |
610 | 609 | $input_constructor_args |
611 | 610 | ); |
612 | 611 | remove_filter( |
613 | 612 | 'FHEE__EE_Question__generate_form_input__country_options', |
614 | - array( $this, 'use_cached_countries_for_form_input' ) |
|
613 | + array($this, 'use_cached_countries_for_form_input') |
|
615 | 614 | ); |
616 | 615 | remove_filter( |
617 | 616 | 'FHEE__EE_Question__generate_form_input__state_options', |
618 | - array( $this, 'use_cached_states_for_form_input' ) |
|
617 | + array($this, 'use_cached_states_for_form_input') |
|
619 | 618 | ); |
620 | 619 | return $form_input; |
621 | 620 | } |
@@ -637,22 +636,22 @@ discard block |
||
637 | 636 | \EE_Registration $registration = null, |
638 | 637 | \EE_Answer $answer = null |
639 | 638 | ) { |
640 | - $country_options = array( '' => '' ); |
|
639 | + $country_options = array('' => ''); |
|
641 | 640 | // get possibly cached list of countries |
642 | 641 | $countries = $this->checkout->action === 'process_reg_step' |
643 | 642 | ? EEM_Country::instance()->get_all_countries() |
644 | 643 | : EEM_Country::instance()->get_all_active_countries(); |
645 | - if ( ! empty( $countries )) { |
|
646 | - foreach( $countries as $country ){ |
|
647 | - if ( $country instanceof EE_Country ) { |
|
648 | - $country_options[ $country->ID() ] = $country->name(); |
|
644 | + if ( ! empty($countries)) { |
|
645 | + foreach ($countries as $country) { |
|
646 | + if ($country instanceof EE_Country) { |
|
647 | + $country_options[$country->ID()] = $country->name(); |
|
649 | 648 | } |
650 | 649 | } |
651 | 650 | } |
652 | - if( $question instanceof EE_Question |
|
653 | - && $registration instanceof EE_Registration ) { |
|
651 | + if ($question instanceof EE_Question |
|
652 | + && $registration instanceof EE_Registration) { |
|
654 | 653 | $answer = EEM_Answer::instance()->get_one( |
655 | - array( array( 'QST_ID' => $question->ID(), 'REG_ID' => $registration->ID() ) ) |
|
654 | + array(array('QST_ID' => $question->ID(), 'REG_ID' => $registration->ID())) |
|
656 | 655 | ); |
657 | 656 | } else { |
658 | 657 | $answer = EE_Answer::new_instance(); |
@@ -685,14 +684,14 @@ discard block |
||
685 | 684 | \EE_Registration $registration = null, |
686 | 685 | \EE_Answer $answer = null |
687 | 686 | ) { |
688 | - $state_options = array( '' => array( '' => '')); |
|
687 | + $state_options = array('' => array('' => '')); |
|
689 | 688 | $states = $this->checkout->action === 'process_reg_step' |
690 | 689 | ? EEM_State::instance()->get_all_states() |
691 | 690 | : EEM_State::instance()->get_all_active_states(); |
692 | - if ( ! empty( $states )) { |
|
693 | - foreach( $states as $state ){ |
|
694 | - if ( $state instanceof EE_State ) { |
|
695 | - $state_options[ $state->country()->name() ][ $state->ID() ] = $state->name(); |
|
691 | + if ( ! empty($states)) { |
|
692 | + foreach ($states as $state) { |
|
693 | + if ($state instanceof EE_State) { |
|
694 | + $state_options[$state->country()->name()][$state->ID()] = $state->name(); |
|
696 | 695 | } |
697 | 696 | } |
698 | 697 | } |
@@ -720,24 +719,24 @@ discard block |
||
720 | 719 | * @throws \EE_Error |
721 | 720 | */ |
722 | 721 | public function process_reg_step() { |
723 | - do_action( 'AHEE_log', __FILE__, __FUNCTION__, '' ); |
|
722 | + do_action('AHEE_log', __FILE__, __FUNCTION__, ''); |
|
724 | 723 | // grab validated data from form |
725 | 724 | $valid_data = $this->checkout->current_step->valid_data(); |
726 | 725 | // EEH_Debug_Tools::printr( $_REQUEST, '$_REQUEST', __FILE__, __LINE__ ); |
727 | 726 | // EEH_Debug_Tools::printr( $valid_data, '$valid_data', __FILE__, __LINE__ ); |
728 | 727 | // if we don't have any $valid_data then something went TERRIBLY WRONG !!! |
729 | - if ( empty( $valid_data )) { |
|
728 | + if (empty($valid_data)) { |
|
730 | 729 | EE_Error::add_error( |
731 | - __( 'No valid question responses were received.', 'event_espresso' ), |
|
730 | + __('No valid question responses were received.', 'event_espresso'), |
|
732 | 731 | __FILE__, |
733 | 732 | __FUNCTION__, |
734 | 733 | __LINE__ |
735 | 734 | ); |
736 | 735 | return false; |
737 | 736 | } |
738 | - if ( ! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg ) { |
|
737 | + if ( ! $this->checkout->transaction instanceof EE_Transaction || ! $this->checkout->continue_reg) { |
|
739 | 738 | EE_Error::add_error( |
740 | - __( 'A valid transaction could not be initiated for processing your registrations.', 'event_espresso' ), |
|
739 | + __('A valid transaction could not be initiated for processing your registrations.', 'event_espresso'), |
|
741 | 740 | __FILE__, |
742 | 741 | __FUNCTION__, |
743 | 742 | __LINE__ |
@@ -745,11 +744,11 @@ discard block |
||
745 | 744 | return false; |
746 | 745 | } |
747 | 746 | // get cached registrations |
748 | - $registrations = $this->checkout->transaction->registrations( $this->checkout->reg_cache_where_params ); |
|
747 | + $registrations = $this->checkout->transaction->registrations($this->checkout->reg_cache_where_params); |
|
749 | 748 | // verify we got the goods |
750 | - if ( empty( $registrations )) { |
|
749 | + if (empty($registrations)) { |
|
751 | 750 | EE_Error::add_error( |
752 | - __( 'Your form data could not be applied to any valid registrations.', 'event_espresso' ), |
|
751 | + __('Your form data could not be applied to any valid registrations.', 'event_espresso'), |
|
753 | 752 | __FILE__, |
754 | 753 | __FUNCTION__, |
755 | 754 | __LINE__ |
@@ -757,15 +756,15 @@ discard block |
||
757 | 756 | return false; |
758 | 757 | } |
759 | 758 | // extract attendee info from form data and save to model objects |
760 | - $registrations_processed = $this->_process_registrations( $registrations, $valid_data ); |
|
759 | + $registrations_processed = $this->_process_registrations($registrations, $valid_data); |
|
761 | 760 | // if first pass thru SPCO, |
762 | 761 | // then let's check processed registrations against the total number of tickets in the cart |
763 | - if ( $registrations_processed === false ) { |
|
762 | + if ($registrations_processed === false) { |
|
764 | 763 | // but return immediately if the previous step exited early due to errors |
765 | 764 | return false; |
766 | - } else if ( ! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count ) { |
|
765 | + } else if ( ! $this->checkout->revisit && $registrations_processed !== $this->checkout->total_ticket_count) { |
|
767 | 766 | // generate a correctly translated string for all possible singular/plural combinations |
768 | - if ( $this->checkout->total_ticket_count === 1 && $registrations_processed !== 1 ) { |
|
767 | + if ($this->checkout->total_ticket_count === 1 && $registrations_processed !== 1) { |
|
769 | 768 | $error_msg = sprintf( |
770 | 769 | __( |
771 | 770 | 'There was %1$d ticket in the Event Queue, but %2$ds registrations were processed', |
@@ -774,7 +773,7 @@ discard block |
||
774 | 773 | $this->checkout->total_ticket_count, |
775 | 774 | $registrations_processed |
776 | 775 | ); |
777 | - } else if ( $this->checkout->total_ticket_count !== 1 && $registrations_processed === 1 ) { |
|
776 | + } else if ($this->checkout->total_ticket_count !== 1 && $registrations_processed === 1) { |
|
778 | 777 | $error_msg = sprintf( |
779 | 778 | __( |
780 | 779 | 'There was a total of %1$d tickets in the Event Queue, but only %2$ds registration was processed', |
@@ -793,17 +792,17 @@ discard block |
||
793 | 792 | $registrations_processed |
794 | 793 | ); |
795 | 794 | } |
796 | - EE_Error::add_error( $error_msg, __FILE__, __FUNCTION__, __LINE__ ); |
|
795 | + EE_Error::add_error($error_msg, __FILE__, __FUNCTION__, __LINE__); |
|
797 | 796 | return false; |
798 | 797 | } |
799 | 798 | // mark this reg step as completed |
800 | 799 | $this->set_completed(); |
801 | 800 | $this->_set_success_message( |
802 | - __( 'The Attendee Information Step has been successfully completed.', 'event_espresso' ) |
|
801 | + __('The Attendee Information Step has been successfully completed.', 'event_espresso') |
|
803 | 802 | ); |
804 | 803 | //do action in case a plugin wants to do something with the data submitted in step 1. |
805 | 804 | //passes EE_Single_Page_Checkout, and it's posted data |
806 | - do_action( 'AHEE__EE_Single_Page_Checkout__process_attendee_information__end', $this, $valid_data ); |
|
805 | + do_action('AHEE__EE_Single_Page_Checkout__process_attendee_information__end', $this, $valid_data); |
|
807 | 806 | return true; |
808 | 807 | } |
809 | 808 | |
@@ -817,9 +816,9 @@ discard block |
||
817 | 816 | * @return boolean | int |
818 | 817 | * @throws \EE_Error |
819 | 818 | */ |
820 | - private function _process_registrations( $registrations = array(), $valid_data = array() ) { |
|
819 | + private function _process_registrations($registrations = array(), $valid_data = array()) { |
|
821 | 820 | // load resources and set some defaults |
822 | - EE_Registry::instance()->load_model( 'Attendee' ); |
|
821 | + EE_Registry::instance()->load_model('Attendee'); |
|
823 | 822 | // holder for primary registrant attendee object |
824 | 823 | $this->checkout->primary_attendee_obj = NULL; |
825 | 824 | // array for tracking reg form data for the primary registrant |
@@ -836,9 +835,9 @@ discard block |
||
836 | 835 | // attendee counter |
837 | 836 | $att_nmbr = 0; |
838 | 837 | // grab the saved registrations from the transaction |
839 | - foreach ( $registrations as $registration ) { |
|
838 | + foreach ($registrations as $registration) { |
|
840 | 839 | // verify EE_Registration object |
841 | - if ( ! $registration instanceof EE_Registration ) { |
|
840 | + if ( ! $registration instanceof EE_Registration) { |
|
842 | 841 | EE_Error::add_error( |
843 | 842 | __( |
844 | 843 | 'An invalid Registration object was discovered when attempting to process your registration information.', |
@@ -853,12 +852,12 @@ discard block |
||
853 | 852 | /** @var string $reg_url_link */ |
854 | 853 | $reg_url_link = $registration->reg_url_link(); |
855 | 854 | // reg_url_link exists ? |
856 | - if ( ! empty( $reg_url_link ) ) { |
|
855 | + if ( ! empty($reg_url_link)) { |
|
857 | 856 | // should this registration be processed during this visit ? |
858 | - if ( $this->checkout->visit_allows_processing_of_this_registration( $registration ) ) { |
|
857 | + if ($this->checkout->visit_allows_processing_of_this_registration($registration)) { |
|
859 | 858 | // if NOT revisiting, then let's save the registration now, |
860 | 859 | // so that we have a REG_ID to use when generating other objects |
861 | - if ( ! $this->checkout->revisit ) { |
|
860 | + if ( ! $this->checkout->revisit) { |
|
862 | 861 | $registration->save(); |
863 | 862 | } |
864 | 863 | /** |
@@ -868,7 +867,7 @@ discard block |
||
868 | 867 | * @var bool if true is returned by the plugin then the |
869 | 868 | * registration processing is halted. |
870 | 869 | */ |
871 | - if ( apply_filters( |
|
870 | + if (apply_filters( |
|
872 | 871 | 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___process_registrations__pre_registration_process', |
873 | 872 | false, |
874 | 873 | $att_nmbr, |
@@ -876,38 +875,38 @@ discard block |
||
876 | 875 | $registrations, |
877 | 876 | $valid_data, |
878 | 877 | $this |
879 | - ) ) { |
|
878 | + )) { |
|
880 | 879 | return false; |
881 | 880 | } |
882 | 881 | |
883 | 882 | // Houston, we have a registration! |
884 | 883 | $att_nmbr++; |
885 | - $this->_attendee_data[ $reg_url_link ] = array(); |
|
884 | + $this->_attendee_data[$reg_url_link] = array(); |
|
886 | 885 | // grab any existing related answer objects |
887 | 886 | $this->_registration_answers = $registration->answers(); |
888 | 887 | // unset( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] ); |
889 | - if ( isset( $valid_data[ $reg_url_link ] ) ) { |
|
888 | + if (isset($valid_data[$reg_url_link])) { |
|
890 | 889 | // do we need to copy basic info from primary attendee ? |
891 | - $copy_primary = isset( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] ) |
|
892 | - && absint( $valid_data[ $reg_url_link ]['additional_attendee_reg_info'] ) === 0 |
|
890 | + $copy_primary = isset($valid_data[$reg_url_link]['additional_attendee_reg_info']) |
|
891 | + && absint($valid_data[$reg_url_link]['additional_attendee_reg_info']) === 0 |
|
893 | 892 | ? true |
894 | 893 | : false; |
895 | 894 | // filter form input data for this registration |
896 | - $valid_data[ $reg_url_link ] = (array)apply_filters( |
|
895 | + $valid_data[$reg_url_link] = (array) apply_filters( |
|
897 | 896 | 'FHEE__EE_Single_Page_Checkout__process_attendee_information__valid_data_line_item', |
898 | - $valid_data[ $reg_url_link ] |
|
897 | + $valid_data[$reg_url_link] |
|
899 | 898 | ); |
900 | 899 | // EEH_Debug_Tools::printr( $valid_data[ $reg_url_link ], '$valid_data[ $reg_url_link ]', __FILE__, __LINE__ ); |
901 | - if ( isset( $valid_data['primary_attendee'] )) { |
|
902 | - $primary_registrant['line_item_id'] = ! empty( $valid_data['primary_attendee'] ) |
|
900 | + if (isset($valid_data['primary_attendee'])) { |
|
901 | + $primary_registrant['line_item_id'] = ! empty($valid_data['primary_attendee']) |
|
903 | 902 | ? $valid_data['primary_attendee'] |
904 | 903 | : false; |
905 | - unset( $valid_data['primary_attendee'] ); |
|
904 | + unset($valid_data['primary_attendee']); |
|
906 | 905 | } |
907 | 906 | // now loop through our array of valid post data && process attendee reg forms |
908 | - foreach ( $valid_data[ $reg_url_link ] as $form_section => $form_inputs ) { |
|
909 | - if ( ! in_array( $form_section, $non_input_form_sections )) { |
|
910 | - foreach ( $form_inputs as $form_input => $input_value ) { |
|
907 | + foreach ($valid_data[$reg_url_link] as $form_section => $form_inputs) { |
|
908 | + if ( ! in_array($form_section, $non_input_form_sections)) { |
|
909 | + foreach ($form_inputs as $form_input => $input_value) { |
|
911 | 910 | // \EEH_Debug_Tools::printr( $input_value, $form_input, __FILE__, __LINE__ ); |
912 | 911 | // check for critical inputs |
913 | 912 | if ( |
@@ -921,16 +920,16 @@ discard block |
||
921 | 920 | // store a bit of data about the primary attendee |
922 | 921 | if ( |
923 | 922 | $att_nmbr === 1 |
924 | - && ! empty( $input_value ) |
|
923 | + && ! empty($input_value) |
|
925 | 924 | && $reg_url_link === $primary_registrant['line_item_id'] |
926 | 925 | ) { |
927 | - $primary_registrant[ $form_input ] = $input_value; |
|
926 | + $primary_registrant[$form_input] = $input_value; |
|
928 | 927 | } else if ( |
929 | 928 | $copy_primary |
930 | 929 | && $input_value === null |
931 | - && isset( $primary_registrant[ $form_input ] ) |
|
930 | + && isset($primary_registrant[$form_input]) |
|
932 | 931 | ) { |
933 | - $input_value = $primary_registrant[ $form_input ]; |
|
932 | + $input_value = $primary_registrant[$form_input]; |
|
934 | 933 | } |
935 | 934 | // now attempt to save the input data |
936 | 935 | if ( |
@@ -972,55 +971,55 @@ discard block |
||
972 | 971 | // have we met before? |
973 | 972 | $attendee = $this->_find_existing_attendee( |
974 | 973 | $registration, |
975 | - $this->_attendee_data[ $reg_url_link ] |
|
974 | + $this->_attendee_data[$reg_url_link] |
|
976 | 975 | ); |
977 | 976 | // did we find an already existing record for this attendee ? |
978 | - if ( $attendee instanceof EE_Attendee ) { |
|
977 | + if ($attendee instanceof EE_Attendee) { |
|
979 | 978 | $attendee = $this->_update_existing_attendee_data( |
980 | 979 | $attendee, |
981 | - $this->_attendee_data[ $reg_url_link ] |
|
980 | + $this->_attendee_data[$reg_url_link] |
|
982 | 981 | ); |
983 | 982 | } else { |
984 | 983 | // ensure critical details are set for additional attendees |
985 | - $this->_attendee_data[ $reg_url_link ] = $att_nmbr > 1 |
|
984 | + $this->_attendee_data[$reg_url_link] = $att_nmbr > 1 |
|
986 | 985 | ? $this->_copy_critical_attendee_details_from_primary_registrant( |
987 | - $this->_attendee_data[ $reg_url_link ] |
|
986 | + $this->_attendee_data[$reg_url_link] |
|
988 | 987 | ) |
989 | - : $this->_attendee_data[ $reg_url_link ]; |
|
988 | + : $this->_attendee_data[$reg_url_link]; |
|
990 | 989 | $attendee = $this->_create_new_attendee( |
991 | 990 | $registration, |
992 | - $this->_attendee_data[ $reg_url_link ] |
|
991 | + $this->_attendee_data[$reg_url_link] |
|
993 | 992 | ); |
994 | 993 | } |
995 | 994 | // who's #1 ? |
996 | - if ( $att_nmbr === 1 ) { |
|
995 | + if ($att_nmbr === 1) { |
|
997 | 996 | $this->checkout->primary_attendee_obj = $attendee; |
998 | 997 | } |
999 | 998 | } |
1000 | 999 | // EEH_Debug_Tools::printr( $attendee, '$attendee', __FILE__, __LINE__ ); |
1001 | 1000 | // add relation to registration, set attendee ID, and cache attendee |
1002 | - $this->_associate_attendee_with_registration( $registration, $attendee ); |
|
1001 | + $this->_associate_attendee_with_registration($registration, $attendee); |
|
1003 | 1002 | // \EEH_Debug_Tools::printr( $registration, '$registration', __FILE__, __LINE__ ); |
1004 | - if ( ! $registration->attendee() instanceof EE_Attendee ) { |
|
1005 | - EE_Error::add_error( sprintf( __( 'Registration %s has an invalid or missing Attendee object.', 'event_espresso' ), $reg_url_link ), __FILE__, __FUNCTION__, __LINE__ ); |
|
1003 | + if ( ! $registration->attendee() instanceof EE_Attendee) { |
|
1004 | + EE_Error::add_error(sprintf(__('Registration %s has an invalid or missing Attendee object.', 'event_espresso'), $reg_url_link), __FILE__, __FUNCTION__, __LINE__); |
|
1006 | 1005 | return false; |
1007 | 1006 | } |
1008 | 1007 | /** @type EE_Registration_Processor $registration_processor */ |
1009 | - $registration_processor = EE_Registry::instance()->load_class( 'Registration_Processor' ); |
|
1008 | + $registration_processor = EE_Registry::instance()->load_class('Registration_Processor'); |
|
1010 | 1009 | // at this point, we should have enough details about the registrant to consider the registration NOT incomplete |
1011 | - $registration_processor->toggle_incomplete_registration_status_to_default( $registration, false ); |
|
1010 | + $registration_processor->toggle_incomplete_registration_status_to_default($registration, false); |
|
1012 | 1011 | // we can also consider the TXN to not have been failed, so temporarily upgrade it's status to abandoned |
1013 | 1012 | $this->checkout->transaction->toggle_failed_transaction_status(); |
1014 | 1013 | // if we've gotten this far, then let's save what we have |
1015 | 1014 | $registration->save(); |
1016 | 1015 | // add relation between TXN and registration |
1017 | - $this->_associate_registration_with_transaction( $registration ); |
|
1016 | + $this->_associate_registration_with_transaction($registration); |
|
1018 | 1017 | } // end of if ( ! $this->checkout->revisit || $this->checkout->primary_revisit || ( $this->checkout->revisit && $this->checkout->reg_url_link == $reg_url_link )) { |
1019 | 1018 | |
1020 | - } else { |
|
1021 | - EE_Error::add_error( __( 'An invalid or missing line item ID was encountered while attempting to process the registration form.', 'event_espresso' ), __FILE__, __FUNCTION__, __LINE__ ); |
|
1019 | + } else { |
|
1020 | + EE_Error::add_error(__('An invalid or missing line item ID was encountered while attempting to process the registration form.', 'event_espresso'), __FILE__, __FUNCTION__, __LINE__); |
|
1022 | 1021 | // remove malformed data |
1023 | - unset( $valid_data[ $reg_url_link ] ); |
|
1022 | + unset($valid_data[$reg_url_link]); |
|
1024 | 1023 | return false; |
1025 | 1024 | } |
1026 | 1025 | |
@@ -1049,26 +1048,26 @@ discard block |
||
1049 | 1048 | // \EEH_Debug_Tools::printr( $input_value, '$input_value', __FILE__, __LINE__ ); |
1050 | 1049 | // allow for plugins to hook in and do their own processing of the form input. |
1051 | 1050 | // For plugins to bypass normal processing here, they just need to return a boolean value. |
1052 | - if ( apply_filters( |
|
1051 | + if (apply_filters( |
|
1053 | 1052 | 'FHEE__EE_SPCO_Reg_Step_Attendee_Information___save_registration_form_input', |
1054 | 1053 | false, |
1055 | 1054 | $registration, |
1056 | 1055 | $form_input, |
1057 | 1056 | $input_value, |
1058 | 1057 | $this |
1059 | - ) ) { |
|
1058 | + )) { |
|
1060 | 1059 | return true; |
1061 | 1060 | } |
1062 | 1061 | // $answer_cache_id is the key used to find the EE_Answer we want |
1063 | 1062 | $answer_cache_id = $this->checkout->reg_url_link |
1064 | 1063 | ? $form_input |
1065 | - : $form_input . '-' . $registration->reg_url_link(); |
|
1066 | - $answer_is_obj = isset( $this->_registration_answers[ $answer_cache_id ] ) |
|
1067 | - && $this->_registration_answers[ $answer_cache_id ] instanceof EE_Answer |
|
1064 | + : $form_input.'-'.$registration->reg_url_link(); |
|
1065 | + $answer_is_obj = isset($this->_registration_answers[$answer_cache_id]) |
|
1066 | + && $this->_registration_answers[$answer_cache_id] instanceof EE_Answer |
|
1068 | 1067 | ? true |
1069 | 1068 | : false; |
1070 | 1069 | //rename form_inputs if they are EE_Attendee properties |
1071 | - switch( (string)$form_input ) { |
|
1070 | + switch ((string) $form_input) { |
|
1072 | 1071 | |
1073 | 1072 | case 'state' : |
1074 | 1073 | case 'STA_ID' : |
@@ -1083,32 +1082,32 @@ discard block |
||
1083 | 1082 | break; |
1084 | 1083 | |
1085 | 1084 | default : |
1086 | - $ATT_input = 'ATT_' . $form_input; |
|
1085 | + $ATT_input = 'ATT_'.$form_input; |
|
1087 | 1086 | //EEH_Debug_Tools::printr( $ATT_input, '$ATT_input', __FILE__, __LINE__ ); |
1088 | - $attendee_property = EEM_Attendee::instance()->has_field( $ATT_input ) ? true : false; |
|
1089 | - $form_input = $attendee_property ? 'ATT_' . $form_input : $form_input; |
|
1087 | + $attendee_property = EEM_Attendee::instance()->has_field($ATT_input) ? true : false; |
|
1088 | + $form_input = $attendee_property ? 'ATT_'.$form_input : $form_input; |
|
1090 | 1089 | } |
1091 | 1090 | // EEH_Debug_Tools::printr( $answer_cache_id, '$answer_cache_id', __FILE__, __LINE__ ); |
1092 | 1091 | // EEH_Debug_Tools::printr( $attendee_property, '$attendee_property', __FILE__, __LINE__ ); |
1093 | 1092 | // EEH_Debug_Tools::printr( $answer_is_obj, '$answer_is_obj', __FILE__, __LINE__ ); |
1094 | 1093 | // if this form input has a corresponding attendee property |
1095 | - if ( $attendee_property ) { |
|
1096 | - $this->_attendee_data[ $registration->reg_url_link() ][ $form_input ] = $input_value; |
|
1097 | - if ( $answer_is_obj ) { |
|
1094 | + if ($attendee_property) { |
|
1095 | + $this->_attendee_data[$registration->reg_url_link()][$form_input] = $input_value; |
|
1096 | + if ($answer_is_obj) { |
|
1098 | 1097 | // and delete the corresponding answer since we won't be storing this data in that object |
1099 | - $registration->_remove_relation_to( $this->_registration_answers[ $answer_cache_id ], 'Answer' ); |
|
1100 | - $this->_registration_answers[ $answer_cache_id ]->delete_permanently(); |
|
1098 | + $registration->_remove_relation_to($this->_registration_answers[$answer_cache_id], 'Answer'); |
|
1099 | + $this->_registration_answers[$answer_cache_id]->delete_permanently(); |
|
1101 | 1100 | } |
1102 | 1101 | return true; |
1103 | - } elseif ( $answer_is_obj ) { |
|
1102 | + } elseif ($answer_is_obj) { |
|
1104 | 1103 | // save this data to the answer object |
1105 | - $this->_registration_answers[ $answer_cache_id ]->set_value( $input_value ); |
|
1106 | - $result = $this->_registration_answers[ $answer_cache_id ]->save(); |
|
1104 | + $this->_registration_answers[$answer_cache_id]->set_value($input_value); |
|
1105 | + $result = $this->_registration_answers[$answer_cache_id]->save(); |
|
1107 | 1106 | return $result !== false ? true : false; |
1108 | 1107 | } else { |
1109 | - foreach ( $this->_registration_answers as $answer ) { |
|
1110 | - if ( $answer instanceof EE_Answer && $answer->question_ID() === $answer_cache_id ) { |
|
1111 | - $answer->set_value( $input_value ); |
|
1108 | + foreach ($this->_registration_answers as $answer) { |
|
1109 | + if ($answer instanceof EE_Answer && $answer->question_ID() === $answer_cache_id) { |
|
1110 | + $answer->set_value($input_value); |
|
1112 | 1111 | $result = $answer->save(); |
1113 | 1112 | return $result !== false ? true : false; |
1114 | 1113 | } |
@@ -1130,15 +1129,15 @@ discard block |
||
1130 | 1129 | $form_input = '', |
1131 | 1130 | $input_value = '' |
1132 | 1131 | ) { |
1133 | - if ( empty( $input_value ) ) { |
|
1132 | + if (empty($input_value)) { |
|
1134 | 1133 | // if the form input isn't marked as being required, then just return |
1135 | - if ( ! isset( $this->_required_questions[ $form_input ] ) || ! $this->_required_questions[ $form_input ] ) { |
|
1134 | + if ( ! isset($this->_required_questions[$form_input]) || ! $this->_required_questions[$form_input]) { |
|
1136 | 1135 | return true; |
1137 | 1136 | } |
1138 | - switch ( $form_input ) { |
|
1137 | + switch ($form_input) { |
|
1139 | 1138 | case 'fname' : |
1140 | 1139 | EE_Error::add_error( |
1141 | - __( 'First Name is a required value.', 'event_espresso' ), |
|
1140 | + __('First Name is a required value.', 'event_espresso'), |
|
1142 | 1141 | __FILE__, |
1143 | 1142 | __FUNCTION__, |
1144 | 1143 | __LINE__ |
@@ -1147,7 +1146,7 @@ discard block |
||
1147 | 1146 | break; |
1148 | 1147 | case 'lname' : |
1149 | 1148 | EE_Error::add_error( |
1150 | - __( 'Last Name is a required value.', 'event_espresso' ), |
|
1149 | + __('Last Name is a required value.', 'event_espresso'), |
|
1151 | 1150 | __FILE__, |
1152 | 1151 | __FUNCTION__, |
1153 | 1152 | __LINE__ |
@@ -1156,7 +1155,7 @@ discard block |
||
1156 | 1155 | break; |
1157 | 1156 | case 'email' : |
1158 | 1157 | EE_Error::add_error( |
1159 | - __( 'Please enter a valid email address.', 'event_espresso' ), |
|
1158 | + __('Please enter a valid email address.', 'event_espresso'), |
|
1160 | 1159 | __FILE__, |
1161 | 1160 | __FUNCTION__, |
1162 | 1161 | __LINE__ |
@@ -1178,30 +1177,30 @@ discard block |
||
1178 | 1177 | * @return boolean|EE_Attendee |
1179 | 1178 | * @throws \EE_Error |
1180 | 1179 | */ |
1181 | - private function _find_existing_attendee( EE_Registration $registration, $attendee_data = array() ) { |
|
1180 | + private function _find_existing_attendee(EE_Registration $registration, $attendee_data = array()) { |
|
1182 | 1181 | $existing_attendee = null; |
1183 | 1182 | // if none of the critical properties are set in the incoming attendee data... |
1184 | 1183 | // then attempt to copy them from the primary attendee |
1185 | 1184 | if ( |
1186 | 1185 | $this->checkout->primary_attendee_obj instanceof EE_Attendee |
1187 | - && ! isset( $attendee_data['ATT_fname'], $attendee_data['ATT_email'] ) |
|
1186 | + && ! isset($attendee_data['ATT_fname'], $attendee_data['ATT_email']) |
|
1188 | 1187 | ) { |
1189 | 1188 | return $this->checkout->primary_attendee_obj; |
1190 | 1189 | } |
1191 | 1190 | // does this attendee already exist in the db ? |
1192 | 1191 | // we're searching using a combination of first name, last name, AND email address |
1193 | - $ATT_fname = isset( $attendee_data['ATT_fname'] ) && ! empty( $attendee_data['ATT_fname'] ) |
|
1192 | + $ATT_fname = isset($attendee_data['ATT_fname']) && ! empty($attendee_data['ATT_fname']) |
|
1194 | 1193 | ? $attendee_data['ATT_fname'] |
1195 | 1194 | : ''; |
1196 | - $ATT_lname = isset( $attendee_data['ATT_lname'] ) && ! empty( $attendee_data['ATT_lname'] ) |
|
1195 | + $ATT_lname = isset($attendee_data['ATT_lname']) && ! empty($attendee_data['ATT_lname']) |
|
1197 | 1196 | ? $attendee_data['ATT_lname'] |
1198 | 1197 | : ''; |
1199 | - $ATT_email = isset( $attendee_data['ATT_email'] ) && ! empty( $attendee_data['ATT_email'] ) |
|
1198 | + $ATT_email = isset($attendee_data['ATT_email']) && ! empty($attendee_data['ATT_email']) |
|
1200 | 1199 | ? $attendee_data['ATT_email'] |
1201 | 1200 | : ''; |
1202 | 1201 | // but only if those have values |
1203 | - if ( $ATT_fname && $ATT_lname && $ATT_email ) { |
|
1204 | - $existing_attendee = EEM_Attendee::instance()->find_existing_attendee( array( |
|
1202 | + if ($ATT_fname && $ATT_lname && $ATT_email) { |
|
1203 | + $existing_attendee = EEM_Attendee::instance()->find_existing_attendee(array( |
|
1205 | 1204 | 'ATT_fname' => $ATT_fname, |
1206 | 1205 | 'ATT_lname' => $ATT_lname, |
1207 | 1206 | 'ATT_email' => $ATT_email |
@@ -1225,13 +1224,13 @@ discard block |
||
1225 | 1224 | * @return \EE_Attendee |
1226 | 1225 | * @throws \EE_Error |
1227 | 1226 | */ |
1228 | - private function _update_existing_attendee_data( EE_Attendee $existing_attendee, $attendee_data = array() ) { |
|
1227 | + private function _update_existing_attendee_data(EE_Attendee $existing_attendee, $attendee_data = array()) { |
|
1229 | 1228 | // first remove fname, lname, and email from attendee data |
1230 | - $dont_set = array( 'ATT_fname', 'ATT_lname', 'ATT_email' ); |
|
1229 | + $dont_set = array('ATT_fname', 'ATT_lname', 'ATT_email'); |
|
1231 | 1230 | // now loop thru what's left and add to attendee CPT |
1232 | - foreach ( $attendee_data as $property_name => $property_value ) { |
|
1233 | - if ( ! in_array( $property_name, $dont_set ) && EEM_Attendee::instance()->has_field( $property_name )) { |
|
1234 | - $existing_attendee->set( $property_name, $property_value ); |
|
1231 | + foreach ($attendee_data as $property_name => $property_value) { |
|
1232 | + if ( ! in_array($property_name, $dont_set) && EEM_Attendee::instance()->has_field($property_name)) { |
|
1233 | + $existing_attendee->set($property_name, $property_value); |
|
1235 | 1234 | } |
1236 | 1235 | } |
1237 | 1236 | // better save that now |
@@ -1249,11 +1248,11 @@ discard block |
||
1249 | 1248 | * @return void |
1250 | 1249 | * @throws \EE_Error |
1251 | 1250 | */ |
1252 | - private function _associate_attendee_with_registration( EE_Registration $registration, EE_Attendee $attendee ) { |
|
1251 | + private function _associate_attendee_with_registration(EE_Registration $registration, EE_Attendee $attendee) { |
|
1253 | 1252 | // add relation to attendee |
1254 | - $registration->_add_relation_to( $attendee, 'Attendee' ); |
|
1255 | - $registration->set_attendee_id( $attendee->ID() ); |
|
1256 | - $registration->update_cache_after_object_save( 'Attendee', $attendee ); |
|
1253 | + $registration->_add_relation_to($attendee, 'Attendee'); |
|
1254 | + $registration->set_attendee_id($attendee->ID()); |
|
1255 | + $registration->update_cache_after_object_save('Attendee', $attendee); |
|
1257 | 1256 | } |
1258 | 1257 | |
1259 | 1258 | |
@@ -1265,10 +1264,10 @@ discard block |
||
1265 | 1264 | * @return void |
1266 | 1265 | * @throws \EE_Error |
1267 | 1266 | */ |
1268 | - private function _associate_registration_with_transaction( EE_Registration $registration ) { |
|
1267 | + private function _associate_registration_with_transaction(EE_Registration $registration) { |
|
1269 | 1268 | // add relation to attendee |
1270 | - $this->checkout->transaction->_add_relation_to( $registration, 'Registration' ); |
|
1271 | - $this->checkout->transaction->update_cache_after_object_save( 'Registration', $registration ); |
|
1269 | + $this->checkout->transaction->_add_relation_to($registration, 'Registration'); |
|
1270 | + $this->checkout->transaction->update_cache_after_object_save('Registration', $registration); |
|
1272 | 1271 | } |
1273 | 1272 | |
1274 | 1273 | |
@@ -1281,14 +1280,14 @@ discard block |
||
1281 | 1280 | * @return array |
1282 | 1281 | * @throws \EE_Error |
1283 | 1282 | */ |
1284 | - private function _copy_critical_attendee_details_from_primary_registrant( $attendee_data = array() ) { |
|
1283 | + private function _copy_critical_attendee_details_from_primary_registrant($attendee_data = array()) { |
|
1285 | 1284 | // bare minimum critical details include first name, last name, email address |
1286 | - $critical_attendee_details = array( 'ATT_fname', 'ATT_lname', 'ATT_email' ); |
|
1285 | + $critical_attendee_details = array('ATT_fname', 'ATT_lname', 'ATT_email'); |
|
1287 | 1286 | // add address info to critical details? |
1288 | - if ( apply_filters( |
|
1287 | + if (apply_filters( |
|
1289 | 1288 | 'FHEE__EE_SPCO_Reg_Step_Attendee_Information__merge_address_details_with_critical_attendee_details', |
1290 | 1289 | false |
1291 | - ) ) { |
|
1290 | + )) { |
|
1292 | 1291 | $address_details = array( |
1293 | 1292 | 'ATT_address', |
1294 | 1293 | 'ATT_address2', |
@@ -1298,13 +1297,13 @@ discard block |
||
1298 | 1297 | 'ATT_zip', |
1299 | 1298 | 'ATT_phone' |
1300 | 1299 | ); |
1301 | - $critical_attendee_details = array_merge( $critical_attendee_details, $address_details ); |
|
1300 | + $critical_attendee_details = array_merge($critical_attendee_details, $address_details); |
|
1302 | 1301 | } |
1303 | - foreach ( $critical_attendee_details as $critical_attendee_detail ) { |
|
1304 | - if ( ! isset( $attendee_data[ $critical_attendee_detail ] ) |
|
1305 | - || empty( $attendee_data[ $critical_attendee_detail ] ) |
|
1302 | + foreach ($critical_attendee_details as $critical_attendee_detail) { |
|
1303 | + if ( ! isset($attendee_data[$critical_attendee_detail]) |
|
1304 | + || empty($attendee_data[$critical_attendee_detail]) |
|
1306 | 1305 | ) { |
1307 | - $attendee_data[ $critical_attendee_detail ] = $this->checkout->primary_attendee_obj->get( |
|
1306 | + $attendee_data[$critical_attendee_detail] = $this->checkout->primary_attendee_obj->get( |
|
1308 | 1307 | $critical_attendee_detail |
1309 | 1308 | ); |
1310 | 1309 | } |
@@ -1322,11 +1321,11 @@ discard block |
||
1322 | 1321 | * @return \EE_Attendee |
1323 | 1322 | * @throws \EE_Error |
1324 | 1323 | */ |
1325 | - private function _create_new_attendee( EE_Registration $registration, $attendee_data = array() ) { |
|
1324 | + private function _create_new_attendee(EE_Registration $registration, $attendee_data = array()) { |
|
1326 | 1325 | // create new attendee object |
1327 | - $new_attendee = EE_Attendee::new_instance( $attendee_data ); |
|
1326 | + $new_attendee = EE_Attendee::new_instance($attendee_data); |
|
1328 | 1327 | // set author to event creator |
1329 | - $new_attendee->set( 'ATT_author', $registration->event()->wp_user() ); |
|
1328 | + $new_attendee->set('ATT_author', $registration->event()->wp_user()); |
|
1330 | 1329 | $new_attendee->save(); |
1331 | 1330 | return $new_attendee; |
1332 | 1331 | } |
@@ -1343,7 +1342,7 @@ discard block |
||
1343 | 1342 | */ |
1344 | 1343 | public function update_reg_step() { |
1345 | 1344 | // save everything |
1346 | - if ( $this->process_reg_step() ) { |
|
1345 | + if ($this->process_reg_step()) { |
|
1347 | 1346 | $this->checkout->redirect = true; |
1348 | 1347 | $this->checkout->redirect_url = add_query_arg( |
1349 | 1348 | array( |
@@ -1352,7 +1351,7 @@ discard block |
||
1352 | 1351 | ), |
1353 | 1352 | $this->checkout->thank_you_page_url |
1354 | 1353 | ); |
1355 | - $this->checkout->json_response->set_redirect_url( $this->checkout->redirect_url ); |
|
1354 | + $this->checkout->json_response->set_redirect_url($this->checkout->redirect_url); |
|
1356 | 1355 | return true; |
1357 | 1356 | } |
1358 | 1357 | return false; |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if ( ! defined('ABSPATH')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | /* |
5 | 5 | Plugin Name: Event Espresso |
@@ -40,239 +40,239 @@ discard block |
||
40 | 40 | * @since 4.0 |
41 | 41 | */ |
42 | 42 | if (function_exists('espresso_version')) { |
43 | - /** |
|
44 | - * espresso_duplicate_plugin_error |
|
45 | - * displays if more than one version of EE is activated at the same time |
|
46 | - */ |
|
47 | - function espresso_duplicate_plugin_error() |
|
48 | - { |
|
49 | - ?> |
|
43 | + /** |
|
44 | + * espresso_duplicate_plugin_error |
|
45 | + * displays if more than one version of EE is activated at the same time |
|
46 | + */ |
|
47 | + function espresso_duplicate_plugin_error() |
|
48 | + { |
|
49 | + ?> |
|
50 | 50 | <div class="error"> |
51 | 51 | <p> |
52 | 52 | <?php echo esc_html__( |
53 | - 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | - 'event_espresso' |
|
55 | - ); ?> |
|
53 | + 'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.', |
|
54 | + 'event_espresso' |
|
55 | + ); ?> |
|
56 | 56 | </p> |
57 | 57 | </div> |
58 | 58 | <?php |
59 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | - } |
|
59 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
60 | + } |
|
61 | 61 | |
62 | - add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
62 | + add_action('admin_notices', 'espresso_duplicate_plugin_error', 1); |
|
63 | 63 | } else { |
64 | - define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
65 | - if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | - /** |
|
67 | - * espresso_minimum_php_version_error |
|
68 | - * |
|
69 | - * @return void |
|
70 | - */ |
|
71 | - function espresso_minimum_php_version_error() |
|
72 | - { |
|
73 | - ?> |
|
64 | + define('EE_MIN_PHP_VER_REQUIRED', '5.3.9'); |
|
65 | + if ( ! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) { |
|
66 | + /** |
|
67 | + * espresso_minimum_php_version_error |
|
68 | + * |
|
69 | + * @return void |
|
70 | + */ |
|
71 | + function espresso_minimum_php_version_error() |
|
72 | + { |
|
73 | + ?> |
|
74 | 74 | <div class="error"> |
75 | 75 | <p> |
76 | 76 | <?php |
77 | - printf( |
|
78 | - esc_html__( |
|
79 | - 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | - 'event_espresso' |
|
81 | - ), |
|
82 | - EE_MIN_PHP_VER_REQUIRED, |
|
83 | - PHP_VERSION, |
|
84 | - '<br/>', |
|
85 | - '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | - ); |
|
87 | - ?> |
|
77 | + printf( |
|
78 | + esc_html__( |
|
79 | + 'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.', |
|
80 | + 'event_espresso' |
|
81 | + ), |
|
82 | + EE_MIN_PHP_VER_REQUIRED, |
|
83 | + PHP_VERSION, |
|
84 | + '<br/>', |
|
85 | + '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>' |
|
86 | + ); |
|
87 | + ?> |
|
88 | 88 | </p> |
89 | 89 | </div> |
90 | 90 | <?php |
91 | - espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | - } |
|
91 | + espresso_deactivate_plugin(plugin_basename(__FILE__)); |
|
92 | + } |
|
93 | 93 | |
94 | - add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | - } else { |
|
96 | - /** |
|
97 | - * espresso_version |
|
98 | - * Returns the plugin version |
|
99 | - * |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - function espresso_version() |
|
103 | - { |
|
104 | - return apply_filters('FHEE__espresso__espresso_version', '4.9.24.rc.030'); |
|
105 | - } |
|
94 | + add_action('admin_notices', 'espresso_minimum_php_version_error', 1); |
|
95 | + } else { |
|
96 | + /** |
|
97 | + * espresso_version |
|
98 | + * Returns the plugin version |
|
99 | + * |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + function espresso_version() |
|
103 | + { |
|
104 | + return apply_filters('FHEE__espresso__espresso_version', '4.9.24.rc.030'); |
|
105 | + } |
|
106 | 106 | |
107 | - // define versions |
|
108 | - define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | - define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | - define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | - define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | - define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | - //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | - if ( ! defined('DS')) { |
|
115 | - define('DS', '/'); |
|
116 | - } |
|
117 | - if ( ! defined('PS')) { |
|
118 | - define('PS', PATH_SEPARATOR); |
|
119 | - } |
|
120 | - if ( ! defined('SP')) { |
|
121 | - define('SP', ' '); |
|
122 | - } |
|
123 | - if ( ! defined('EENL')) { |
|
124 | - define('EENL', "\n"); |
|
125 | - } |
|
126 | - define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | - // define the plugin directory and URL |
|
128 | - define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | - define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | - define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | - // main root folder paths |
|
132 | - define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | - define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | - define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | - define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | - define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | - define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | - define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | - define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | - // core system paths |
|
141 | - define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | - define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | - define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | - define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | - define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | - define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | - define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | - define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | - define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | - define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | - define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | - define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | - // gateways |
|
154 | - define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | - define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | - // asset URL paths |
|
157 | - define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | - define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | - define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | - define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | - define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | - define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | - // define upload paths |
|
164 | - $uploads = wp_upload_dir(); |
|
165 | - // define the uploads directory and URL |
|
166 | - define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | - define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | - // define the templates directory and URL |
|
169 | - define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | - define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | - // define the gateway directory and URL |
|
172 | - define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | - define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | - // languages folder/path |
|
175 | - define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | - define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | - //check for dompdf fonts in uploads |
|
178 | - if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | - define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | - } |
|
181 | - //ajax constants |
|
182 | - define( |
|
183 | - 'EE_FRONT_AJAX', |
|
184 | - isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | - ); |
|
186 | - define( |
|
187 | - 'EE_ADMIN_AJAX', |
|
188 | - isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | - ); |
|
190 | - //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | - //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | - //want to change its default value! or find when -1 means infinity |
|
193 | - define('EE_INF_IN_DB', -1); |
|
194 | - define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | - define('EE_DEBUG', false); |
|
196 | - /** |
|
197 | - * espresso_plugin_activation |
|
198 | - * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
199 | - */ |
|
200 | - function espresso_plugin_activation() |
|
201 | - { |
|
202 | - update_option('ee_espresso_activation', true); |
|
203 | - } |
|
107 | + // define versions |
|
108 | + define('EVENT_ESPRESSO_VERSION', espresso_version()); |
|
109 | + define('EE_MIN_WP_VER_REQUIRED', '4.1'); |
|
110 | + define('EE_MIN_WP_VER_RECOMMENDED', '4.4.2'); |
|
111 | + define('EE_MIN_PHP_VER_RECOMMENDED', '5.4.44'); |
|
112 | + define('EVENT_ESPRESSO_MAIN_FILE', __FILE__); |
|
113 | + //used to be DIRECTORY_SEPARATOR, but that caused issues on windows |
|
114 | + if ( ! defined('DS')) { |
|
115 | + define('DS', '/'); |
|
116 | + } |
|
117 | + if ( ! defined('PS')) { |
|
118 | + define('PS', PATH_SEPARATOR); |
|
119 | + } |
|
120 | + if ( ! defined('SP')) { |
|
121 | + define('SP', ' '); |
|
122 | + } |
|
123 | + if ( ! defined('EENL')) { |
|
124 | + define('EENL', "\n"); |
|
125 | + } |
|
126 | + define('EE_SUPPORT_EMAIL', '[email protected]'); |
|
127 | + // define the plugin directory and URL |
|
128 | + define('EE_PLUGIN_BASENAME', plugin_basename(EVENT_ESPRESSO_MAIN_FILE)); |
|
129 | + define('EE_PLUGIN_DIR_PATH', plugin_dir_path(EVENT_ESPRESSO_MAIN_FILE)); |
|
130 | + define('EE_PLUGIN_DIR_URL', plugin_dir_url(EVENT_ESPRESSO_MAIN_FILE)); |
|
131 | + // main root folder paths |
|
132 | + define('EE_ADMIN_PAGES', EE_PLUGIN_DIR_PATH . 'admin_pages' . DS); |
|
133 | + define('EE_CORE', EE_PLUGIN_DIR_PATH . 'core' . DS); |
|
134 | + define('EE_MODULES', EE_PLUGIN_DIR_PATH . 'modules' . DS); |
|
135 | + define('EE_PUBLIC', EE_PLUGIN_DIR_PATH . 'public' . DS); |
|
136 | + define('EE_SHORTCODES', EE_PLUGIN_DIR_PATH . 'shortcodes' . DS); |
|
137 | + define('EE_WIDGETS', EE_PLUGIN_DIR_PATH . 'widgets' . DS); |
|
138 | + define('EE_PAYMENT_METHODS', EE_PLUGIN_DIR_PATH . 'payment_methods' . DS); |
|
139 | + define('EE_CAFF_PATH', EE_PLUGIN_DIR_PATH . 'caffeinated' . DS); |
|
140 | + // core system paths |
|
141 | + define('EE_ADMIN', EE_CORE . 'admin' . DS); |
|
142 | + define('EE_CPTS', EE_CORE . 'CPTs' . DS); |
|
143 | + define('EE_CLASSES', EE_CORE . 'db_classes' . DS); |
|
144 | + define('EE_INTERFACES', EE_CORE . 'interfaces' . DS); |
|
145 | + define('EE_BUSINESS', EE_CORE . 'business' . DS); |
|
146 | + define('EE_MODELS', EE_CORE . 'db_models' . DS); |
|
147 | + define('EE_HELPERS', EE_CORE . 'helpers' . DS); |
|
148 | + define('EE_LIBRARIES', EE_CORE . 'libraries' . DS); |
|
149 | + define('EE_TEMPLATES', EE_CORE . 'templates' . DS); |
|
150 | + define('EE_THIRD_PARTY', EE_CORE . 'third_party_libs' . DS); |
|
151 | + define('EE_GLOBAL_ASSETS', EE_TEMPLATES . 'global_assets' . DS); |
|
152 | + define('EE_FORM_SECTIONS', EE_LIBRARIES . 'form_sections' . DS); |
|
153 | + // gateways |
|
154 | + define('EE_GATEWAYS', EE_MODULES . 'gateways' . DS); |
|
155 | + define('EE_GATEWAYS_URL', EE_PLUGIN_DIR_URL . 'modules' . DS . 'gateways' . DS); |
|
156 | + // asset URL paths |
|
157 | + define('EE_TEMPLATES_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'templates' . DS); |
|
158 | + define('EE_GLOBAL_ASSETS_URL', EE_TEMPLATES_URL . 'global_assets' . DS); |
|
159 | + define('EE_IMAGES_URL', EE_GLOBAL_ASSETS_URL . 'images' . DS); |
|
160 | + define('EE_THIRD_PARTY_URL', EE_PLUGIN_DIR_URL . 'core' . DS . 'third_party_libs' . DS); |
|
161 | + define('EE_HELPERS_ASSETS', EE_PLUGIN_DIR_URL . 'core/helpers/assets/'); |
|
162 | + define('EE_LIBRARIES_URL', EE_PLUGIN_DIR_URL . 'core/libraries/'); |
|
163 | + // define upload paths |
|
164 | + $uploads = wp_upload_dir(); |
|
165 | + // define the uploads directory and URL |
|
166 | + define('EVENT_ESPRESSO_UPLOAD_DIR', $uploads['basedir'] . DS . 'espresso' . DS); |
|
167 | + define('EVENT_ESPRESSO_UPLOAD_URL', $uploads['baseurl'] . DS . 'espresso' . DS); |
|
168 | + // define the templates directory and URL |
|
169 | + define('EVENT_ESPRESSO_TEMPLATE_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'templates' . DS); |
|
170 | + define('EVENT_ESPRESSO_TEMPLATE_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'templates' . DS); |
|
171 | + // define the gateway directory and URL |
|
172 | + define('EVENT_ESPRESSO_GATEWAY_DIR', $uploads['basedir'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
173 | + define('EVENT_ESPRESSO_GATEWAY_URL', $uploads['baseurl'] . DS . 'espresso' . DS . 'gateways' . DS); |
|
174 | + // languages folder/path |
|
175 | + define('EE_LANGUAGES_SAFE_LOC', '..' . DS . 'uploads' . DS . 'espresso' . DS . 'languages' . DS); |
|
176 | + define('EE_LANGUAGES_SAFE_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'languages' . DS); |
|
177 | + //check for dompdf fonts in uploads |
|
178 | + if (file_exists(EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS)) { |
|
179 | + define('DOMPDF_FONT_DIR', EVENT_ESPRESSO_UPLOAD_DIR . 'fonts' . DS); |
|
180 | + } |
|
181 | + //ajax constants |
|
182 | + define( |
|
183 | + 'EE_FRONT_AJAX', |
|
184 | + isset($_REQUEST['ee_front_ajax']) || isset($_REQUEST['data']['ee_front_ajax']) ? true : false |
|
185 | + ); |
|
186 | + define( |
|
187 | + 'EE_ADMIN_AJAX', |
|
188 | + isset($_REQUEST['ee_admin_ajax']) || isset($_REQUEST['data']['ee_admin_ajax']) ? true : false |
|
189 | + ); |
|
190 | + //just a handy constant occasionally needed for finding values representing infinity in the DB |
|
191 | + //you're better to use this than its straight value (currently -1) in case you ever |
|
192 | + //want to change its default value! or find when -1 means infinity |
|
193 | + define('EE_INF_IN_DB', -1); |
|
194 | + define('EE_INF', INF > (float)PHP_INT_MAX ? INF : PHP_INT_MAX); |
|
195 | + define('EE_DEBUG', false); |
|
196 | + /** |
|
197 | + * espresso_plugin_activation |
|
198 | + * adds a wp-option to indicate that EE has been activated via the WP admin plugins page |
|
199 | + */ |
|
200 | + function espresso_plugin_activation() |
|
201 | + { |
|
202 | + update_option('ee_espresso_activation', true); |
|
203 | + } |
|
204 | 204 | |
205 | - register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
206 | - /** |
|
207 | - * espresso_load_error_handling |
|
208 | - * this function loads EE's class for handling exceptions and errors |
|
209 | - */ |
|
210 | - function espresso_load_error_handling() |
|
211 | - { |
|
212 | - // load debugging tools |
|
213 | - if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
214 | - require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
215 | - EEH_Debug_Tools::instance(); |
|
216 | - } |
|
217 | - // load error handling |
|
218 | - if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
219 | - require_once(EE_CORE . 'EE_Error.core.php'); |
|
220 | - } else { |
|
221 | - wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
222 | - } |
|
223 | - } |
|
205 | + register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation'); |
|
206 | + /** |
|
207 | + * espresso_load_error_handling |
|
208 | + * this function loads EE's class for handling exceptions and errors |
|
209 | + */ |
|
210 | + function espresso_load_error_handling() |
|
211 | + { |
|
212 | + // load debugging tools |
|
213 | + if (WP_DEBUG === true && is_readable(EE_HELPERS . 'EEH_Debug_Tools.helper.php')) { |
|
214 | + require_once(EE_HELPERS . 'EEH_Debug_Tools.helper.php'); |
|
215 | + EEH_Debug_Tools::instance(); |
|
216 | + } |
|
217 | + // load error handling |
|
218 | + if (is_readable(EE_CORE . 'EE_Error.core.php')) { |
|
219 | + require_once(EE_CORE . 'EE_Error.core.php'); |
|
220 | + } else { |
|
221 | + wp_die(esc_html__('The EE_Error core class could not be loaded.', 'event_espresso')); |
|
222 | + } |
|
223 | + } |
|
224 | 224 | |
225 | - /** |
|
226 | - * espresso_load_required |
|
227 | - * given a class name and path, this function will load that file or throw an exception |
|
228 | - * |
|
229 | - * @param string $classname |
|
230 | - * @param string $full_path_to_file |
|
231 | - * @throws EE_Error |
|
232 | - */ |
|
233 | - function espresso_load_required($classname, $full_path_to_file) |
|
234 | - { |
|
235 | - static $error_handling_loaded = false; |
|
236 | - if ( ! $error_handling_loaded) { |
|
237 | - espresso_load_error_handling(); |
|
238 | - $error_handling_loaded = true; |
|
239 | - } |
|
240 | - if (is_readable($full_path_to_file)) { |
|
241 | - require_once($full_path_to_file); |
|
242 | - } else { |
|
243 | - throw new EE_Error ( |
|
244 | - sprintf( |
|
245 | - esc_html__( |
|
246 | - 'The %s class file could not be located or is not readable due to file permissions.', |
|
247 | - 'event_espresso' |
|
248 | - ), |
|
249 | - $classname |
|
250 | - ) |
|
251 | - ); |
|
252 | - } |
|
253 | - } |
|
225 | + /** |
|
226 | + * espresso_load_required |
|
227 | + * given a class name and path, this function will load that file or throw an exception |
|
228 | + * |
|
229 | + * @param string $classname |
|
230 | + * @param string $full_path_to_file |
|
231 | + * @throws EE_Error |
|
232 | + */ |
|
233 | + function espresso_load_required($classname, $full_path_to_file) |
|
234 | + { |
|
235 | + static $error_handling_loaded = false; |
|
236 | + if ( ! $error_handling_loaded) { |
|
237 | + espresso_load_error_handling(); |
|
238 | + $error_handling_loaded = true; |
|
239 | + } |
|
240 | + if (is_readable($full_path_to_file)) { |
|
241 | + require_once($full_path_to_file); |
|
242 | + } else { |
|
243 | + throw new EE_Error ( |
|
244 | + sprintf( |
|
245 | + esc_html__( |
|
246 | + 'The %s class file could not be located or is not readable due to file permissions.', |
|
247 | + 'event_espresso' |
|
248 | + ), |
|
249 | + $classname |
|
250 | + ) |
|
251 | + ); |
|
252 | + } |
|
253 | + } |
|
254 | 254 | |
255 | - espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
256 | - espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
257 | - espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
258 | - new EE_Bootstrap(); |
|
259 | - } |
|
255 | + espresso_load_required('EEH_Base', EE_CORE . 'helpers' . DS . 'EEH_Base.helper.php'); |
|
256 | + espresso_load_required('EEH_File', EE_CORE . 'helpers' . DS . 'EEH_File.helper.php'); |
|
257 | + espresso_load_required('EE_Bootstrap', EE_CORE . 'EE_Bootstrap.core.php'); |
|
258 | + new EE_Bootstrap(); |
|
259 | + } |
|
260 | 260 | } |
261 | 261 | if ( ! function_exists('espresso_deactivate_plugin')) { |
262 | - /** |
|
263 | - * deactivate_plugin |
|
264 | - * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
265 | - * |
|
266 | - * @access public |
|
267 | - * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
268 | - * @return void |
|
269 | - */ |
|
270 | - function espresso_deactivate_plugin($plugin_basename = '') |
|
271 | - { |
|
272 | - if ( ! function_exists('deactivate_plugins')) { |
|
273 | - require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
274 | - } |
|
275 | - unset($_GET['activate'], $_REQUEST['activate']); |
|
276 | - deactivate_plugins($plugin_basename); |
|
277 | - } |
|
262 | + /** |
|
263 | + * deactivate_plugin |
|
264 | + * usage: espresso_deactivate_plugin( plugin_basename( __FILE__ )); |
|
265 | + * |
|
266 | + * @access public |
|
267 | + * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file |
|
268 | + * @return void |
|
269 | + */ |
|
270 | + function espresso_deactivate_plugin($plugin_basename = '') |
|
271 | + { |
|
272 | + if ( ! function_exists('deactivate_plugins')) { |
|
273 | + require_once(ABSPATH . 'wp-admin/includes/plugin.php'); |
|
274 | + } |
|
275 | + unset($_GET['activate'], $_REQUEST['activate']); |
|
276 | + deactivate_plugins($plugin_basename); |
|
277 | + } |
|
278 | 278 | } |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if ( ! defined( 'EVENT_ESPRESSO_VERSION' )) { exit('NO direct script access allowed'); } |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { exit('NO direct script access allowed'); } |
|
2 | 2 | |
3 | 3 | /** |
4 | 4 | * ---------------------------------------------- |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | * |
97 | 97 | *@param array $settings_array |
98 | 98 | */ |
99 | - public function set_settings( $settings_array ) { |
|
99 | + public function set_settings($settings_array) { |
|
100 | 100 | parent::set_settings($settings_array); |
101 | 101 | // Redirect URL. |
102 | 102 | $this->_base_gateway_url = $this->_debug_mode |
@@ -115,19 +115,19 @@ discard block |
||
115 | 115 | * @return \EE_Payment|\EEI_Payment |
116 | 116 | * @throws \EE_Error |
117 | 117 | */ |
118 | - public function set_redirection_info( $payment, $billing_info = array(), $return_url = NULL, $notify_url = NULL, $cancel_url = NULL ) { |
|
119 | - if ( ! $payment instanceof EEI_Payment ) { |
|
120 | - $payment->set_gateway_response( __( 'Error. No associated payment was found.', 'event_espresso' ) ); |
|
121 | - $payment->set_status( $this->_pay_model->failed_status() ); |
|
118 | + public function set_redirection_info($payment, $billing_info = array(), $return_url = NULL, $notify_url = NULL, $cancel_url = NULL) { |
|
119 | + if ( ! $payment instanceof EEI_Payment) { |
|
120 | + $payment->set_gateway_response(__('Error. No associated payment was found.', 'event_espresso')); |
|
121 | + $payment->set_status($this->_pay_model->failed_status()); |
|
122 | 122 | return $payment; |
123 | 123 | } |
124 | 124 | $transaction = $payment->transaction(); |
125 | - if ( ! $transaction instanceof EEI_Transaction ) { |
|
126 | - $payment->set_gateway_response( __( 'Could not process this payment because it has no associated transaction.', 'event_espresso' ) ); |
|
127 | - $payment->set_status( $this->_pay_model->failed_status() ); |
|
125 | + if ( ! $transaction instanceof EEI_Transaction) { |
|
126 | + $payment->set_gateway_response(__('Could not process this payment because it has no associated transaction.', 'event_espresso')); |
|
127 | + $payment->set_status($this->_pay_model->failed_status()); |
|
128 | 128 | return $payment; |
129 | 129 | } |
130 | - $order_description = substr( $this->_format_order_description($payment), 0, 127 ); |
|
130 | + $order_description = substr($this->_format_order_description($payment), 0, 127); |
|
131 | 131 | $primary_registration = $transaction->primary_registration(); |
132 | 132 | $primary_attendee = $primary_registration instanceof EE_Registration ? $primary_registration->attendee() : false; |
133 | 133 | $locale = explode('-', get_bloginfo('language')); |
@@ -141,37 +141,37 @@ discard block |
||
141 | 141 | 'RETURNURL' => $return_url, |
142 | 142 | 'CANCELURL' => $cancel_url, |
143 | 143 | 'PAYMENTREQUEST_0_PAYMENTACTION' => 'Sale', |
144 | - 'SOLUTIONTYPE' => 'Sole', // Buyer does not need to create a PayPal account to check out. This is referred to as PayPal Account Optional. |
|
145 | - 'BUTTONSOURCE' => 'EventEspresso_SP',//EE will blow up if you change this |
|
144 | + 'SOLUTIONTYPE' => 'Sole', // Buyer does not need to create a PayPal account to check out. This is referred to as PayPal Account Optional. |
|
145 | + 'BUTTONSOURCE' => 'EventEspresso_SP', //EE will blow up if you change this |
|
146 | 146 | 'LOCALECODE' => $locale[1] // Locale of the pages displayed by PayPal during Express Checkout. |
147 | 147 | ); |
148 | 148 | |
149 | 149 | // Show itemized list. |
150 | - if ( $this->_money->compare_floats( $payment->amount(), $transaction->total(), '==' ) ) { |
|
150 | + if ($this->_money->compare_floats($payment->amount(), $transaction->total(), '==')) { |
|
151 | 151 | $item_num = 0; |
152 | 152 | $itemized_sum = 0; |
153 | 153 | $total_line_items = $transaction->total_line_item(); |
154 | 154 | // Go through each item in the list. |
155 | - foreach ( $total_line_items->get_items() as $line_item ) { |
|
156 | - if ( $line_item instanceof EE_Line_Item ) { |
|
155 | + foreach ($total_line_items->get_items() as $line_item) { |
|
156 | + if ($line_item instanceof EE_Line_Item) { |
|
157 | 157 | // PayPal doesn't like line items with 0.00 amount, so we may skip those. |
158 | - if ( EEH_Money::compare_floats( $line_item->total(), '0.00', '==' ) ) { |
|
158 | + if (EEH_Money::compare_floats($line_item->total(), '0.00', '==')) { |
|
159 | 159 | continue; |
160 | 160 | } |
161 | 161 | |
162 | 162 | $unit_price = $line_item->unit_price(); |
163 | 163 | $line_item_quantity = $line_item->quantity(); |
164 | 164 | // This is a discount. |
165 | - if ( $line_item->is_percent() ) { |
|
165 | + if ($line_item->is_percent()) { |
|
166 | 166 | $unit_price = $line_item->total(); |
167 | 167 | $line_item_quantity = 1; |
168 | 168 | } |
169 | 169 | // Item Name. |
170 | - $token_request_dtls['L_PAYMENTREQUEST_0_NAME'.$item_num] = substr($this->_format_line_item_name( $line_item, $payment), 0, 127); |
|
170 | + $token_request_dtls['L_PAYMENTREQUEST_0_NAME'.$item_num] = substr($this->_format_line_item_name($line_item, $payment), 0, 127); |
|
171 | 171 | // Item description. |
172 | - $token_request_dtls['L_PAYMENTREQUEST_0_DESC'.$item_num] = substr($this->_format_line_item_desc( $line_item, $payment), 0, 127); |
|
172 | + $token_request_dtls['L_PAYMENTREQUEST_0_DESC'.$item_num] = substr($this->_format_line_item_desc($line_item, $payment), 0, 127); |
|
173 | 173 | // Cost of individual item. |
174 | - $token_request_dtls['L_PAYMENTREQUEST_0_AMT'.$item_num] = $this->format_currency( $unit_price ); |
|
174 | + $token_request_dtls['L_PAYMENTREQUEST_0_AMT'.$item_num] = $this->format_currency($unit_price); |
|
175 | 175 | // Item Number. |
176 | 176 | $token_request_dtls['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1; |
177 | 177 | // Item quantity. |
@@ -188,16 +188,16 @@ discard block |
||
188 | 188 | $token_request_dtls['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
189 | 189 | $token_request_dtls['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
190 | 190 | |
191 | - $itemized_sum_diff_from_txn_total = round( $transaction->total() - $itemized_sum - $total_line_items->get_total_tax(), 2 ); |
|
191 | + $itemized_sum_diff_from_txn_total = round($transaction->total() - $itemized_sum - $total_line_items->get_total_tax(), 2); |
|
192 | 192 | // If we were not able to recognize some item like promotion, surcharge or cancellation, |
193 | 193 | // add the difference as an extra line item. |
194 | - if ( $this->_money->compare_floats( $itemized_sum_diff_from_txn_total, 0, '!=' ) ) { |
|
194 | + if ($this->_money->compare_floats($itemized_sum_diff_from_txn_total, 0, '!=')) { |
|
195 | 195 | // Item Name. |
196 | - $token_request_dtls['L_PAYMENTREQUEST_0_NAME'.$item_num] = substr( __( 'Other (promotion/surcharge/cancellation)', 'event_espresso' ), 0, 127 ); |
|
196 | + $token_request_dtls['L_PAYMENTREQUEST_0_NAME'.$item_num] = substr(__('Other (promotion/surcharge/cancellation)', 'event_espresso'), 0, 127); |
|
197 | 197 | // Item description. |
198 | 198 | $token_request_dtls['L_PAYMENTREQUEST_0_DESC'.$item_num] = ''; |
199 | 199 | // Cost of individual item. |
200 | - $token_request_dtls['L_PAYMENTREQUEST_0_AMT'.$item_num] = $this->format_currency( $itemized_sum_diff_from_txn_total ); |
|
200 | + $token_request_dtls['L_PAYMENTREQUEST_0_AMT'.$item_num] = $this->format_currency($itemized_sum_diff_from_txn_total); |
|
201 | 201 | // Item Number. |
202 | 202 | $token_request_dtls['L_PAYMENTREQUEST_0_NUMBER'.$item_num] = $item_num + 1; |
203 | 203 | // Item quantity. |
@@ -209,11 +209,11 @@ discard block |
||
209 | 209 | } else { |
210 | 210 | // Just one Item. |
211 | 211 | // Item Name. |
212 | - $token_request_dtls['L_PAYMENTREQUEST_0_NAME0'] = substr( $this->_format_partial_payment_line_item_name($payment), 0, 127 ); |
|
212 | + $token_request_dtls['L_PAYMENTREQUEST_0_NAME0'] = substr($this->_format_partial_payment_line_item_name($payment), 0, 127); |
|
213 | 213 | // Item description. |
214 | - $token_request_dtls['L_PAYMENTREQUEST_0_DESC0'] = substr( $this->_format_partial_payment_line_item_desc($payment), 0, 127 ); |
|
214 | + $token_request_dtls['L_PAYMENTREQUEST_0_DESC0'] = substr($this->_format_partial_payment_line_item_desc($payment), 0, 127); |
|
215 | 215 | // Cost of individual item. |
216 | - $token_request_dtls['L_PAYMENTREQUEST_0_AMT0'] = $this->format_currency( $payment->amount() ); |
|
216 | + $token_request_dtls['L_PAYMENTREQUEST_0_AMT0'] = $this->format_currency($payment->amount()); |
|
217 | 217 | // Item Number. |
218 | 218 | $token_request_dtls['L_PAYMENTREQUEST_0_NUMBER0'] = 1; |
219 | 219 | // Item quantity. |
@@ -221,14 +221,14 @@ discard block |
||
221 | 221 | // Digital item is sold. |
222 | 222 | $token_request_dtls['L_PAYMENTREQUEST_0_ITEMCATEGORY0'] = 'Physical'; |
223 | 223 | // Item's sales S/H and tax amount. |
224 | - $token_request_dtls['PAYMENTREQUEST_0_ITEMAMT'] = $this->format_currency( $payment->amount() ); |
|
224 | + $token_request_dtls['PAYMENTREQUEST_0_ITEMAMT'] = $this->format_currency($payment->amount()); |
|
225 | 225 | $token_request_dtls['PAYMENTREQUEST_0_TAXAMT'] = '0'; |
226 | 226 | $token_request_dtls['PAYMENTREQUEST_0_SHIPPINGAMT'] = '0'; |
227 | 227 | $token_request_dtls['PAYMENTREQUEST_0_HANDLINGAMT'] = '0'; |
228 | 228 | } |
229 | 229 | // Automatically filling out shipping and contact information. |
230 | - if ( $this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee ) { |
|
231 | - $token_request_dtls['NOSHIPPING'] = '2'; // If you do not pass the shipping address, PayPal obtains it from the buyer's account profile. |
|
230 | + if ($this->_request_shipping_addr && $primary_attendee instanceof EEI_Attendee) { |
|
231 | + $token_request_dtls['NOSHIPPING'] = '2'; // If you do not pass the shipping address, PayPal obtains it from the buyer's account profile. |
|
232 | 232 | $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET'] = $primary_attendee->address(); |
233 | 233 | $token_request_dtls['PAYMENTREQUEST_0_SHIPTOSTREET2'] = $primary_attendee->address2(); |
234 | 234 | $token_request_dtls['PAYMENTREQUEST_0_SHIPTOCITY'] = $primary_attendee->city(); |
@@ -237,34 +237,34 @@ discard block |
||
237 | 237 | $token_request_dtls['PAYMENTREQUEST_0_SHIPTOZIP'] = $primary_attendee->zip(); |
238 | 238 | $token_request_dtls['PAYMENTREQUEST_0_EMAIL'] = $primary_attendee->email(); |
239 | 239 | $token_request_dtls['PAYMENTREQUEST_0_SHIPTOPHONENUM'] = $primary_attendee->phone(); |
240 | - } elseif ( ! $this->_request_shipping_addr ) { |
|
240 | + } elseif ( ! $this->_request_shipping_addr) { |
|
241 | 241 | // Do not request shipping details on the PP Checkout page. |
242 | 242 | $token_request_dtls['NOSHIPPING'] = '1'; |
243 | 243 | $token_request_dtls['REQCONFIRMSHIPPING'] = '0'; |
244 | 244 | |
245 | 245 | } |
246 | 246 | // Used a business/personal logo on the PayPal page. |
247 | - if ( ! empty($this->_image_url) ) { |
|
247 | + if ( ! empty($this->_image_url)) { |
|
248 | 248 | $token_request_dtls['LOGOIMG'] = $this->_image_url; |
249 | 249 | } |
250 | 250 | // Request PayPal token. |
251 | - $token_request_response = $this->_ppExpress_request( $token_request_dtls, 'Payment Token', $payment ); |
|
252 | - $token_rstatus = $this->_ppExpress_check_response( $token_request_response ); |
|
253 | - $response_args = ( isset($token_rstatus['args']) && is_array($token_rstatus['args']) ) ? $token_rstatus['args'] : array(); |
|
254 | - if ( $token_rstatus['status'] ) { |
|
251 | + $token_request_response = $this->_ppExpress_request($token_request_dtls, 'Payment Token', $payment); |
|
252 | + $token_rstatus = $this->_ppExpress_check_response($token_request_response); |
|
253 | + $response_args = (isset($token_rstatus['args']) && is_array($token_rstatus['args'])) ? $token_rstatus['args'] : array(); |
|
254 | + if ($token_rstatus['status']) { |
|
255 | 255 | // We got the Token so we may continue with the payment and redirect the client. |
256 | - $payment->set_details( $response_args ); |
|
256 | + $payment->set_details($response_args); |
|
257 | 257 | |
258 | 258 | $gateway_url = $this->_debug_mode ? 'https://www.sandbox.paypal.com' : 'https://www.paypal.com'; |
259 | - $payment->set_redirect_url( $gateway_url . '/checkoutnow?useraction=commit&cmd=_express-checkout&token=' . $response_args['TOKEN'] ); |
|
259 | + $payment->set_redirect_url($gateway_url.'/checkoutnow?useraction=commit&cmd=_express-checkout&token='.$response_args['TOKEN']); |
|
260 | 260 | } else { |
261 | - if ( isset($response_args['L_ERRORCODE']) ) { |
|
262 | - $payment->set_gateway_response( $response_args['L_ERRORCODE'] . '; ' . $response_args['L_SHORTMESSAGE'] ); |
|
261 | + if (isset($response_args['L_ERRORCODE'])) { |
|
262 | + $payment->set_gateway_response($response_args['L_ERRORCODE'].'; '.$response_args['L_SHORTMESSAGE']); |
|
263 | 263 | } else { |
264 | - $payment->set_gateway_response( __( 'Error occurred while trying to setup the Express Checkout.', 'event_espresso' ) ); |
|
264 | + $payment->set_gateway_response(__('Error occurred while trying to setup the Express Checkout.', 'event_espresso')); |
|
265 | 265 | } |
266 | - $payment->set_details( $response_args ); |
|
267 | - $payment->set_status( $this->_pay_model->failed_status() ); |
|
266 | + $payment->set_details($response_args); |
|
267 | + $payment->set_status($this->_pay_model->failed_status()); |
|
268 | 268 | } |
269 | 269 | |
270 | 270 | return $payment; |
@@ -280,22 +280,22 @@ discard block |
||
280 | 280 | * @param EEI_Transaction $transaction |
281 | 281 | * @return EEI_Payment |
282 | 282 | */ |
283 | - public function handle_payment_update( $update_info, $transaction ) { |
|
283 | + public function handle_payment_update($update_info, $transaction) { |
|
284 | 284 | $payment = $transaction instanceof EEI_Transaction ? $transaction->last_payment() : null; |
285 | 285 | |
286 | - if ( $payment instanceof EEI_Payment ) { |
|
287 | - $this->log( array( 'Return from Authorization' => $update_info ), $payment ); |
|
286 | + if ($payment instanceof EEI_Payment) { |
|
287 | + $this->log(array('Return from Authorization' => $update_info), $payment); |
|
288 | 288 | $transaction = $payment->transaction(); |
289 | - if ( ! $transaction instanceof EEI_Transaction ) { |
|
290 | - $payment->set_gateway_response( __( 'Could not process this payment because it has no associated transaction.', 'event_espresso' ) ); |
|
291 | - $payment->set_status( $this->_pay_model->failed_status() ); |
|
289 | + if ( ! $transaction instanceof EEI_Transaction) { |
|
290 | + $payment->set_gateway_response(__('Could not process this payment because it has no associated transaction.', 'event_espresso')); |
|
291 | + $payment->set_status($this->_pay_model->failed_status()); |
|
292 | 292 | return $payment; |
293 | 293 | } |
294 | 294 | $primary_registrant = $transaction->primary_registration(); |
295 | 295 | $payment_details = $payment->details(); |
296 | 296 | // Check if we still have the token. |
297 | - if ( ! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN']) ) { |
|
298 | - $payment->set_status( $this->_pay_model->failed_status() ); |
|
297 | + if ( ! isset($payment_details['TOKEN']) || empty($payment_details['TOKEN'])) { |
|
298 | + $payment->set_status($this->_pay_model->failed_status()); |
|
299 | 299 | return $payment; |
300 | 300 | } |
301 | 301 | |
@@ -304,10 +304,10 @@ discard block |
||
304 | 304 | 'TOKEN' => $payment_details['TOKEN'] |
305 | 305 | ); |
306 | 306 | // Request Customer Details. |
307 | - $cdetails_request_response = $this->_ppExpress_request( $cdetails_request_dtls, 'Customer Details', $payment ); |
|
308 | - $cdetails_rstatus = $this->_ppExpress_check_response( $cdetails_request_response ); |
|
309 | - $cdata_response_args = ( isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args']) ) ? $cdetails_rstatus['args'] : array(); |
|
310 | - if ( $cdetails_rstatus['status'] ) { |
|
307 | + $cdetails_request_response = $this->_ppExpress_request($cdetails_request_dtls, 'Customer Details', $payment); |
|
308 | + $cdetails_rstatus = $this->_ppExpress_check_response($cdetails_request_response); |
|
309 | + $cdata_response_args = (isset($cdetails_rstatus['args']) && is_array($cdetails_rstatus['args'])) ? $cdetails_rstatus['args'] : array(); |
|
310 | + if ($cdetails_rstatus['status']) { |
|
311 | 311 | // We got the PayerID so now we can Complete the transaction. |
312 | 312 | $docheckout_request_dtls = array( |
313 | 313 | 'METHOD' => 'DoExpressCheckoutPayment', |
@@ -318,39 +318,39 @@ discard block |
||
318 | 318 | 'PAYMENTREQUEST_0_CURRENCYCODE' => $payment->currency_code() |
319 | 319 | ); |
320 | 320 | // Payment Checkout/Capture. |
321 | - $docheckout_request_response = $this->_ppExpress_request( $docheckout_request_dtls, 'Do Payment', $payment ); |
|
322 | - $docheckout_rstatus = $this->_ppExpress_check_response( $docheckout_request_response ); |
|
323 | - $docheckout_response_args = ( isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args']) ) ? $docheckout_rstatus['args'] : array(); |
|
324 | - if ( $docheckout_rstatus['status'] ) { |
|
321 | + $docheckout_request_response = $this->_ppExpress_request($docheckout_request_dtls, 'Do Payment', $payment); |
|
322 | + $docheckout_rstatus = $this->_ppExpress_check_response($docheckout_request_response); |
|
323 | + $docheckout_response_args = (isset($docheckout_rstatus['args']) && is_array($docheckout_rstatus['args'])) ? $docheckout_rstatus['args'] : array(); |
|
324 | + if ($docheckout_rstatus['status']) { |
|
325 | 325 | // All is well, payment approved. |
326 | 326 | $primary_registration_code = $primary_registrant instanceof EE_Registration ? $primary_registrant->reg_code() : ''; |
327 | - $payment->set_extra_accntng( $primary_registration_code ); |
|
328 | - $payment->set_amount( isset($docheckout_response_args['PAYMENTINFO_0_AMT']) ? (float) $docheckout_response_args['PAYMENTINFO_0_AMT'] : 0 ); |
|
329 | - $payment->set_txn_id_chq_nmbr( isset( $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] ) ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] : null ); |
|
330 | - $payment->set_details( $cdata_response_args ); |
|
331 | - $payment->set_gateway_response( isset( $docheckout_response_args['PAYMENTINFO_0_ACK'] ) ? $docheckout_response_args['PAYMENTINFO_0_ACK'] : '' ); |
|
332 | - $payment->set_status( $this->_pay_model->approved_status() ); |
|
327 | + $payment->set_extra_accntng($primary_registration_code); |
|
328 | + $payment->set_amount(isset($docheckout_response_args['PAYMENTINFO_0_AMT']) ? (float) $docheckout_response_args['PAYMENTINFO_0_AMT'] : 0); |
|
329 | + $payment->set_txn_id_chq_nmbr(isset($docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID']) ? $docheckout_response_args['PAYMENTINFO_0_TRANSACTIONID'] : null); |
|
330 | + $payment->set_details($cdata_response_args); |
|
331 | + $payment->set_gateway_response(isset($docheckout_response_args['PAYMENTINFO_0_ACK']) ? $docheckout_response_args['PAYMENTINFO_0_ACK'] : ''); |
|
332 | + $payment->set_status($this->_pay_model->approved_status()); |
|
333 | 333 | } else { |
334 | - if ( isset($docheckout_response_args['L_ERRORCODE']) ) { |
|
335 | - $payment->set_gateway_response( $docheckout_response_args['L_ERRORCODE'] . '; ' . $docheckout_response_args['L_SHORTMESSAGE'] ); |
|
334 | + if (isset($docheckout_response_args['L_ERRORCODE'])) { |
|
335 | + $payment->set_gateway_response($docheckout_response_args['L_ERRORCODE'].'; '.$docheckout_response_args['L_SHORTMESSAGE']); |
|
336 | 336 | } else { |
337 | - $payment->set_gateway_response( __( 'Error occurred while trying to Capture the funds.', 'event_espresso' ) ); |
|
337 | + $payment->set_gateway_response(__('Error occurred while trying to Capture the funds.', 'event_espresso')); |
|
338 | 338 | } |
339 | - $payment->set_details( $docheckout_response_args ); |
|
340 | - $payment->set_status( $this->_pay_model->declined_status() ); |
|
339 | + $payment->set_details($docheckout_response_args); |
|
340 | + $payment->set_status($this->_pay_model->declined_status()); |
|
341 | 341 | } |
342 | 342 | } else { |
343 | - if ( isset($cdata_response_args['L_ERRORCODE']) ) { |
|
344 | - $payment->set_gateway_response( $cdata_response_args['L_ERRORCODE'] . '; ' . $cdata_response_args['L_SHORTMESSAGE'] ); |
|
343 | + if (isset($cdata_response_args['L_ERRORCODE'])) { |
|
344 | + $payment->set_gateway_response($cdata_response_args['L_ERRORCODE'].'; '.$cdata_response_args['L_SHORTMESSAGE']); |
|
345 | 345 | } else { |
346 | - $payment->set_gateway_response( __( 'Error occurred while trying to get payment Details from PayPal.', 'event_espresso' ) ); |
|
346 | + $payment->set_gateway_response(__('Error occurred while trying to get payment Details from PayPal.', 'event_espresso')); |
|
347 | 347 | } |
348 | - $payment->set_details( $cdata_response_args ); |
|
349 | - $payment->set_status( $this->_pay_model->failed_status() ); |
|
348 | + $payment->set_details($cdata_response_args); |
|
349 | + $payment->set_status($this->_pay_model->failed_status()); |
|
350 | 350 | } |
351 | 351 | } else { |
352 | - $payment->set_gateway_response( __( 'Error occurred while trying to process the payment.', 'event_espresso' ) ); |
|
353 | - $payment->set_status( $this->_pay_model->failed_status() ); |
|
352 | + $payment->set_gateway_response(__('Error occurred while trying to process the payment.', 'event_espresso')); |
|
353 | + $payment->set_status($this->_pay_model->failed_status()); |
|
354 | 354 | } |
355 | 355 | |
356 | 356 | return $payment; |
@@ -365,16 +365,16 @@ discard block |
||
365 | 365 | * @param EEI_Payment $payment |
366 | 366 | * @return mixed |
367 | 367 | */ |
368 | - public function _ppExpress_request( $request_params, $request_text, $payment ) { |
|
368 | + public function _ppExpress_request($request_params, $request_text, $payment) { |
|
369 | 369 | $request_dtls = array( |
370 | 370 | 'VERSION' => '204.0', |
371 | - 'USER' => urlencode( $this->_api_username ), |
|
372 | - 'PWD' => urlencode( $this->_api_password ), |
|
373 | - 'SIGNATURE' => urlencode( $this->_api_signature ) |
|
371 | + 'USER' => urlencode($this->_api_username), |
|
372 | + 'PWD' => urlencode($this->_api_password), |
|
373 | + 'SIGNATURE' => urlencode($this->_api_signature) |
|
374 | 374 | ); |
375 | - $dtls = array_merge( $request_dtls, $request_params ); |
|
375 | + $dtls = array_merge($request_dtls, $request_params); |
|
376 | 376 | |
377 | - $this->_log_clean_request( $dtls, $payment, $request_text . ' Request' ); |
|
377 | + $this->_log_clean_request($dtls, $payment, $request_text.' Request'); |
|
378 | 378 | // Request Customer Details. |
379 | 379 | $request_response = wp_remote_post( |
380 | 380 | $this->_base_gateway_url, |
@@ -384,11 +384,11 @@ discard block |
||
384 | 384 | 'httpversion' => '1.1', |
385 | 385 | 'cookies' => array(), |
386 | 386 | 'headers' => array(), |
387 | - 'body' => http_build_query( $dtls ) |
|
387 | + 'body' => http_build_query($dtls) |
|
388 | 388 | ) |
389 | 389 | ); |
390 | 390 | // Log the response. |
391 | - $this->log( array( $request_text . ' Response' => $request_response), $payment ); |
|
391 | + $this->log(array($request_text.' Response' => $request_response), $payment); |
|
392 | 392 | |
393 | 393 | return $request_response; |
394 | 394 | } |
@@ -400,13 +400,13 @@ discard block |
||
400 | 400 | * @param mixed $request_response |
401 | 401 | * @return array |
402 | 402 | */ |
403 | - public function _ppExpress_check_response( $request_response ) { |
|
404 | - if (empty($request_response['body']) || is_wp_error( $request_response ) ) { |
|
403 | + public function _ppExpress_check_response($request_response) { |
|
404 | + if (empty($request_response['body']) || is_wp_error($request_response)) { |
|
405 | 405 | // If we got here then there was an error in this request. |
406 | 406 | return array('status' => false, 'args' => $request_response); |
407 | 407 | } |
408 | 408 | $response_args = array(); |
409 | - parse_str( urldecode($request_response['body']), $response_args ); |
|
409 | + parse_str(urldecode($request_response['body']), $response_args); |
|
410 | 410 | if ( ! isset($response_args['ACK'])) { |
411 | 411 | return array('status' => false, 'args' => $request_response); |
412 | 412 | } |
@@ -436,10 +436,10 @@ discard block |
||
436 | 436 | * @param string $info |
437 | 437 | * @return void |
438 | 438 | */ |
439 | - private function _log_clean_request($request, $payment, $info ) { |
|
439 | + private function _log_clean_request($request, $payment, $info) { |
|
440 | 440 | $cleaned_request_data = $request; |
441 | 441 | unset($cleaned_request_data['PWD'], $cleaned_request_data['USER'], $cleaned_request_data['SIGNATURE']); |
442 | - $this->log( array($info => $cleaned_request_data), $payment ); |
|
442 | + $this->log(array($info => $cleaned_request_data), $payment); |
|
443 | 443 | } |
444 | 444 | |
445 | 445 | |
@@ -449,10 +449,10 @@ discard block |
||
449 | 449 | * @param array $data_array |
450 | 450 | * @return array |
451 | 451 | */ |
452 | - private function _get_errors( $data_array ) { |
|
452 | + private function _get_errors($data_array) { |
|
453 | 453 | $errors = array(); |
454 | 454 | $n = 0; |
455 | - while ( isset($data_array["L_ERRORCODE{$n}"]) ) { |
|
455 | + while (isset($data_array["L_ERRORCODE{$n}"])) { |
|
456 | 456 | $l_error_code = isset($data_array["L_ERRORCODE{$n}"]) |
457 | 457 | ? $data_array["L_ERRORCODE{$n}"] |
458 | 458 | : ''; |
@@ -466,7 +466,7 @@ discard block |
||
466 | 466 | ? $data_array["L_LONGMESSAGE{$n}"] |
467 | 467 | : ''; |
468 | 468 | |
469 | - if ( $n === 0 ) { |
|
469 | + if ($n === 0) { |
|
470 | 470 | $errors = array( |
471 | 471 | 'L_ERRORCODE' => $l_error_code, |
472 | 472 | 'L_SHORTMESSAGE' => $l_short_message, |
@@ -474,10 +474,10 @@ discard block |
||
474 | 474 | 'L_SEVERITYCODE' => $l_severity_code |
475 | 475 | ); |
476 | 476 | } else { |
477 | - $errors['L_ERRORCODE'] .= ', ' . $l_error_code; |
|
478 | - $errors['L_SHORTMESSAGE'] .= ', ' . $l_short_message; |
|
479 | - $errors['L_LONGMESSAGE'] .= ', ' . $l_long_message; |
|
480 | - $errors['L_SEVERITYCODE'] .= ', ' . $l_severity_code; |
|
477 | + $errors['L_ERRORCODE'] .= ', '.$l_error_code; |
|
478 | + $errors['L_SHORTMESSAGE'] .= ', '.$l_short_message; |
|
479 | + $errors['L_LONGMESSAGE'] .= ', '.$l_long_message; |
|
480 | + $errors['L_SEVERITYCODE'] .= ', '.$l_severity_code; |
|
481 | 481 | } |
482 | 482 | |
483 | 483 | $n++; |