@@ -16,220 +16,220 @@ |
||
16 | 16 | class Prices_List_Table extends EE_Admin_List_Table |
17 | 17 | { |
18 | 18 | |
19 | - private $_PRT; |
|
20 | - |
|
21 | - /** |
|
22 | - * Array of price types. |
|
23 | - * |
|
24 | - * @var EE_Price_Type[] |
|
25 | - */ |
|
26 | - protected $_price_types = array(); |
|
27 | - |
|
28 | - public function __construct($admin_page) |
|
29 | - { |
|
30 | - parent::__construct($admin_page); |
|
31 | - require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
32 | - $this->_PRT = EEM_Price_Type::instance(); |
|
33 | - $this->_price_types = $this->_PRT->get_all_deleted_and_undeleted(); |
|
34 | - } |
|
35 | - |
|
36 | - |
|
37 | - protected function _setup_data() |
|
38 | - { |
|
39 | - $trashed = $this->_admin_page->get_view() == 'trashed' ? true : false; |
|
40 | - $this->_data = $this->_admin_page->get_prices_overview_data($this->_per_page, false, $trashed); |
|
41 | - $this->_all_data_count = $this->_admin_page->get_prices_overview_data($this->_per_page, true, false); |
|
42 | - $this->_trashed_count = $this->_admin_page->get_prices_overview_data($this->_per_page, true, true); |
|
43 | - } |
|
44 | - |
|
45 | - |
|
46 | - protected function _set_properties() |
|
47 | - { |
|
48 | - $this->_wp_list_args = array( |
|
49 | - 'singular' => __('price', 'event_espresso'), |
|
50 | - 'plural' => __('prices', 'event_espresso'), |
|
51 | - 'ajax' => true, |
|
52 | - 'screen' => $this->_admin_page->get_current_screen()->id, |
|
53 | - ); |
|
54 | - |
|
55 | - $this->_columns = array( |
|
56 | - 'cb' => '<input type="checkbox" />', // Render a checkbox instead of text |
|
57 | - 'name' => __('Name', 'event_espresso'), |
|
58 | - 'type' => __('Price Type', 'event_espresso'), |
|
59 | - 'description' => __('Description', 'event_espresso'), |
|
60 | - 'amount' => __('Amount', 'event_espresso'), |
|
61 | - ); |
|
62 | - |
|
63 | - $this->_sortable_columns = array( |
|
64 | - // true means its already sorted |
|
65 | - 'name' => array('name' => false), |
|
66 | - 'type' => array('type' => false), |
|
67 | - 'amount' => array('amount' => false), |
|
68 | - ); |
|
69 | - |
|
70 | - $this->_hidden_columns = array(); |
|
71 | - |
|
72 | - $this->_ajax_sorting_callback = 'update_prices_order'; |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - protected function _get_table_filters() |
|
77 | - { |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - protected function _add_view_counts() |
|
82 | - { |
|
83 | - $this->_views['all']['count'] = $this->_all_data_count; |
|
84 | - if (EE_Registry::instance()->CAP->current_user_can('ee_delete_default_prices', 'pricing_trash_price')) { |
|
85 | - $this->_views['trashed']['count'] = $this->_trashed_count; |
|
86 | - } |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * overriding parent method so that we can make sure the row isn't sortable for certain items |
|
92 | - * |
|
93 | - * @param object $item the current item |
|
94 | - * @return string |
|
95 | - */ |
|
96 | - protected function _get_row_class($item) |
|
97 | - { |
|
98 | - static $row_class = ''; |
|
99 | - $row_class = ($row_class == '' ? 'alternate' : ''); |
|
100 | - |
|
101 | - $new_row = $row_class; |
|
102 | - |
|
103 | - if ($item->type_obj()->base_type() !== 1 && $item->type_obj()->base_type() !== 4) { |
|
104 | - $new_row .= ' rowsortable'; |
|
105 | - } |
|
106 | - |
|
107 | - return ' class="' . $new_row . '"'; |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - public function column_cb($item) |
|
112 | - { |
|
113 | - if ($item->type_obj()->base_type() !== 1) { |
|
114 | - return sprintf( |
|
115 | - '<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', |
|
116 | - $item->ID() |
|
117 | - ); |
|
118 | - } |
|
119 | - return ''; |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - public function column_name($item) |
|
124 | - { |
|
125 | - |
|
126 | - // Build row actions |
|
127 | - $actions = array(); |
|
128 | - // edit price link |
|
129 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
130 | - 'ee_edit_default_price', |
|
131 | - 'pricing_edit_price', |
|
132 | - $item->ID() |
|
133 | - )) { |
|
134 | - $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
135 | - 'action' => 'edit_price', |
|
136 | - 'id' => $item->ID(), |
|
137 | - ), PRICING_ADMIN_URL); |
|
138 | - $actions['edit'] = '<a href="' . $edit_lnk_url . '" title="' |
|
139 | - . esc_attr__('Edit Price', 'event_espresso') . '">' |
|
140 | - . __('Edit', 'event_espresso') . '</a>'; |
|
141 | - } |
|
142 | - |
|
143 | - $name_link = EE_Registry::instance()->CAP->current_user_can( |
|
144 | - 'ee_edit_default_price', |
|
145 | - 'edit_price', |
|
146 | - $item->ID() |
|
147 | - ) |
|
148 | - ? '<a href="' . $edit_lnk_url . '" title="' |
|
149 | - . esc_attr__('Edit Price', 'event_espresso') . '">' |
|
150 | - . stripslashes($item->name()) . '</a>' |
|
151 | - : $item->name(); |
|
152 | - |
|
153 | - if ($item->type_obj()->base_type() !== 1) { |
|
154 | - if ($this->_view == 'all') { |
|
155 | - // trash price link |
|
156 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
157 | - 'ee_delete_default_price', |
|
158 | - 'pricing_trash_price', |
|
159 | - $item->ID() |
|
160 | - )) { |
|
161 | - $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
162 | - 'action' => 'trash_price', |
|
163 | - 'id' => $item->ID(), |
|
164 | - 'noheader' => true, |
|
165 | - ), PRICING_ADMIN_URL); |
|
166 | - $actions['trash'] = '<a href="' . $trash_lnk_url . '" title="' |
|
167 | - . esc_attr__('Move Price to Trash', 'event_espresso') . '">' |
|
168 | - . __('Move to Trash', 'event_espresso') . '</a>'; |
|
169 | - } |
|
170 | - } else { |
|
171 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
172 | - 'ee_delete_default_price', |
|
173 | - 'pricing_restore_price', |
|
174 | - $item->ID() |
|
175 | - )) { |
|
176 | - // restore price link |
|
177 | - $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
178 | - 'action' => 'restore_price', |
|
179 | - 'id' => $item->ID(), |
|
180 | - 'noheader' => true, |
|
181 | - ), PRICING_ADMIN_URL); |
|
182 | - $actions['restore'] = '<a href="' . $restore_lnk_url . '" title="' |
|
183 | - . esc_attr__('Restore Price', 'event_espresso') . '">' |
|
184 | - . __('Restore', 'event_espresso') . '</a>'; |
|
185 | - } |
|
186 | - |
|
187 | - // delete price link |
|
188 | - if (EE_Registry::instance()->CAP->current_user_can( |
|
189 | - 'ee_delete_default_price', |
|
190 | - 'pricing_delete_price', |
|
191 | - $item->ID() |
|
192 | - )) { |
|
193 | - $delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
194 | - 'action' => 'delete_price', |
|
195 | - 'id' => $item->ID(), |
|
196 | - 'noheader' => true, |
|
197 | - ), PRICING_ADMIN_URL); |
|
198 | - $actions['delete'] = '<a href="' . $delete_lnk_url . '" title="' |
|
199 | - . esc_attr__('Delete Price Permanently', 'event_espresso') . '">' |
|
200 | - . __('Delete Permanently', 'event_espresso') . '</a>'; |
|
201 | - } |
|
202 | - } |
|
203 | - } |
|
204 | - |
|
205 | - // Return the name contents |
|
206 | - return sprintf( |
|
207 | - '%1$s <span style="color:silver">(id:%2$s)</span>%3$s', |
|
208 | - $name_link, |
|
209 | - $item->ID(), |
|
210 | - $this->row_actions($actions) |
|
211 | - ); |
|
212 | - } |
|
213 | - |
|
214 | - |
|
215 | - public function column_type($item) |
|
216 | - { |
|
217 | - return $this->_price_types[ $item->type() ]->name(); |
|
218 | - } |
|
219 | - |
|
220 | - |
|
221 | - public function column_description($item) |
|
222 | - { |
|
223 | - return stripslashes($item->desc()); |
|
224 | - } |
|
225 | - |
|
226 | - |
|
227 | - public function column_amount($item) |
|
228 | - { |
|
229 | - if ($this->_price_types[ $item->type() ]->is_percent()) { |
|
230 | - return '<div class="pad-amnt-rght">' . number_format($item->amount(), 1) . '%</div>'; |
|
231 | - } else { |
|
232 | - return '<div class="pad-amnt-rght">' . EEH_Template::format_currency($item->amount()) . '</div>'; |
|
233 | - } |
|
234 | - } |
|
19 | + private $_PRT; |
|
20 | + |
|
21 | + /** |
|
22 | + * Array of price types. |
|
23 | + * |
|
24 | + * @var EE_Price_Type[] |
|
25 | + */ |
|
26 | + protected $_price_types = array(); |
|
27 | + |
|
28 | + public function __construct($admin_page) |
|
29 | + { |
|
30 | + parent::__construct($admin_page); |
|
31 | + require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
32 | + $this->_PRT = EEM_Price_Type::instance(); |
|
33 | + $this->_price_types = $this->_PRT->get_all_deleted_and_undeleted(); |
|
34 | + } |
|
35 | + |
|
36 | + |
|
37 | + protected function _setup_data() |
|
38 | + { |
|
39 | + $trashed = $this->_admin_page->get_view() == 'trashed' ? true : false; |
|
40 | + $this->_data = $this->_admin_page->get_prices_overview_data($this->_per_page, false, $trashed); |
|
41 | + $this->_all_data_count = $this->_admin_page->get_prices_overview_data($this->_per_page, true, false); |
|
42 | + $this->_trashed_count = $this->_admin_page->get_prices_overview_data($this->_per_page, true, true); |
|
43 | + } |
|
44 | + |
|
45 | + |
|
46 | + protected function _set_properties() |
|
47 | + { |
|
48 | + $this->_wp_list_args = array( |
|
49 | + 'singular' => __('price', 'event_espresso'), |
|
50 | + 'plural' => __('prices', 'event_espresso'), |
|
51 | + 'ajax' => true, |
|
52 | + 'screen' => $this->_admin_page->get_current_screen()->id, |
|
53 | + ); |
|
54 | + |
|
55 | + $this->_columns = array( |
|
56 | + 'cb' => '<input type="checkbox" />', // Render a checkbox instead of text |
|
57 | + 'name' => __('Name', 'event_espresso'), |
|
58 | + 'type' => __('Price Type', 'event_espresso'), |
|
59 | + 'description' => __('Description', 'event_espresso'), |
|
60 | + 'amount' => __('Amount', 'event_espresso'), |
|
61 | + ); |
|
62 | + |
|
63 | + $this->_sortable_columns = array( |
|
64 | + // true means its already sorted |
|
65 | + 'name' => array('name' => false), |
|
66 | + 'type' => array('type' => false), |
|
67 | + 'amount' => array('amount' => false), |
|
68 | + ); |
|
69 | + |
|
70 | + $this->_hidden_columns = array(); |
|
71 | + |
|
72 | + $this->_ajax_sorting_callback = 'update_prices_order'; |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + protected function _get_table_filters() |
|
77 | + { |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + protected function _add_view_counts() |
|
82 | + { |
|
83 | + $this->_views['all']['count'] = $this->_all_data_count; |
|
84 | + if (EE_Registry::instance()->CAP->current_user_can('ee_delete_default_prices', 'pricing_trash_price')) { |
|
85 | + $this->_views['trashed']['count'] = $this->_trashed_count; |
|
86 | + } |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * overriding parent method so that we can make sure the row isn't sortable for certain items |
|
92 | + * |
|
93 | + * @param object $item the current item |
|
94 | + * @return string |
|
95 | + */ |
|
96 | + protected function _get_row_class($item) |
|
97 | + { |
|
98 | + static $row_class = ''; |
|
99 | + $row_class = ($row_class == '' ? 'alternate' : ''); |
|
100 | + |
|
101 | + $new_row = $row_class; |
|
102 | + |
|
103 | + if ($item->type_obj()->base_type() !== 1 && $item->type_obj()->base_type() !== 4) { |
|
104 | + $new_row .= ' rowsortable'; |
|
105 | + } |
|
106 | + |
|
107 | + return ' class="' . $new_row . '"'; |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + public function column_cb($item) |
|
112 | + { |
|
113 | + if ($item->type_obj()->base_type() !== 1) { |
|
114 | + return sprintf( |
|
115 | + '<input type="checkbox" name="checkbox[%1$s]" value="%1$s" />', |
|
116 | + $item->ID() |
|
117 | + ); |
|
118 | + } |
|
119 | + return ''; |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + public function column_name($item) |
|
124 | + { |
|
125 | + |
|
126 | + // Build row actions |
|
127 | + $actions = array(); |
|
128 | + // edit price link |
|
129 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
130 | + 'ee_edit_default_price', |
|
131 | + 'pricing_edit_price', |
|
132 | + $item->ID() |
|
133 | + )) { |
|
134 | + $edit_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
135 | + 'action' => 'edit_price', |
|
136 | + 'id' => $item->ID(), |
|
137 | + ), PRICING_ADMIN_URL); |
|
138 | + $actions['edit'] = '<a href="' . $edit_lnk_url . '" title="' |
|
139 | + . esc_attr__('Edit Price', 'event_espresso') . '">' |
|
140 | + . __('Edit', 'event_espresso') . '</a>'; |
|
141 | + } |
|
142 | + |
|
143 | + $name_link = EE_Registry::instance()->CAP->current_user_can( |
|
144 | + 'ee_edit_default_price', |
|
145 | + 'edit_price', |
|
146 | + $item->ID() |
|
147 | + ) |
|
148 | + ? '<a href="' . $edit_lnk_url . '" title="' |
|
149 | + . esc_attr__('Edit Price', 'event_espresso') . '">' |
|
150 | + . stripslashes($item->name()) . '</a>' |
|
151 | + : $item->name(); |
|
152 | + |
|
153 | + if ($item->type_obj()->base_type() !== 1) { |
|
154 | + if ($this->_view == 'all') { |
|
155 | + // trash price link |
|
156 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
157 | + 'ee_delete_default_price', |
|
158 | + 'pricing_trash_price', |
|
159 | + $item->ID() |
|
160 | + )) { |
|
161 | + $trash_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
162 | + 'action' => 'trash_price', |
|
163 | + 'id' => $item->ID(), |
|
164 | + 'noheader' => true, |
|
165 | + ), PRICING_ADMIN_URL); |
|
166 | + $actions['trash'] = '<a href="' . $trash_lnk_url . '" title="' |
|
167 | + . esc_attr__('Move Price to Trash', 'event_espresso') . '">' |
|
168 | + . __('Move to Trash', 'event_espresso') . '</a>'; |
|
169 | + } |
|
170 | + } else { |
|
171 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
172 | + 'ee_delete_default_price', |
|
173 | + 'pricing_restore_price', |
|
174 | + $item->ID() |
|
175 | + )) { |
|
176 | + // restore price link |
|
177 | + $restore_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
178 | + 'action' => 'restore_price', |
|
179 | + 'id' => $item->ID(), |
|
180 | + 'noheader' => true, |
|
181 | + ), PRICING_ADMIN_URL); |
|
182 | + $actions['restore'] = '<a href="' . $restore_lnk_url . '" title="' |
|
183 | + . esc_attr__('Restore Price', 'event_espresso') . '">' |
|
184 | + . __('Restore', 'event_espresso') . '</a>'; |
|
185 | + } |
|
186 | + |
|
187 | + // delete price link |
|
188 | + if (EE_Registry::instance()->CAP->current_user_can( |
|
189 | + 'ee_delete_default_price', |
|
190 | + 'pricing_delete_price', |
|
191 | + $item->ID() |
|
192 | + )) { |
|
193 | + $delete_lnk_url = EE_Admin_Page::add_query_args_and_nonce(array( |
|
194 | + 'action' => 'delete_price', |
|
195 | + 'id' => $item->ID(), |
|
196 | + 'noheader' => true, |
|
197 | + ), PRICING_ADMIN_URL); |
|
198 | + $actions['delete'] = '<a href="' . $delete_lnk_url . '" title="' |
|
199 | + . esc_attr__('Delete Price Permanently', 'event_espresso') . '">' |
|
200 | + . __('Delete Permanently', 'event_espresso') . '</a>'; |
|
201 | + } |
|
202 | + } |
|
203 | + } |
|
204 | + |
|
205 | + // Return the name contents |
|
206 | + return sprintf( |
|
207 | + '%1$s <span style="color:silver">(id:%2$s)</span>%3$s', |
|
208 | + $name_link, |
|
209 | + $item->ID(), |
|
210 | + $this->row_actions($actions) |
|
211 | + ); |
|
212 | + } |
|
213 | + |
|
214 | + |
|
215 | + public function column_type($item) |
|
216 | + { |
|
217 | + return $this->_price_types[ $item->type() ]->name(); |
|
218 | + } |
|
219 | + |
|
220 | + |
|
221 | + public function column_description($item) |
|
222 | + { |
|
223 | + return stripslashes($item->desc()); |
|
224 | + } |
|
225 | + |
|
226 | + |
|
227 | + public function column_amount($item) |
|
228 | + { |
|
229 | + if ($this->_price_types[ $item->type() ]->is_percent()) { |
|
230 | + return '<div class="pad-amnt-rght">' . number_format($item->amount(), 1) . '%</div>'; |
|
231 | + } else { |
|
232 | + return '<div class="pad-amnt-rght">' . EEH_Template::format_currency($item->amount()) . '</div>'; |
|
233 | + } |
|
234 | + } |
|
235 | 235 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | public function __construct($admin_page) |
29 | 29 | { |
30 | 30 | parent::__construct($admin_page); |
31 | - require_once(EE_MODELS . 'EEM_Price_Type.model.php'); |
|
31 | + require_once(EE_MODELS.'EEM_Price_Type.model.php'); |
|
32 | 32 | $this->_PRT = EEM_Price_Type::instance(); |
33 | 33 | $this->_price_types = $this->_PRT->get_all_deleted_and_undeleted(); |
34 | 34 | } |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | $new_row .= ' rowsortable'; |
105 | 105 | } |
106 | 106 | |
107 | - return ' class="' . $new_row . '"'; |
|
107 | + return ' class="'.$new_row.'"'; |
|
108 | 108 | } |
109 | 109 | |
110 | 110 | |
@@ -135,9 +135,9 @@ discard block |
||
135 | 135 | 'action' => 'edit_price', |
136 | 136 | 'id' => $item->ID(), |
137 | 137 | ), PRICING_ADMIN_URL); |
138 | - $actions['edit'] = '<a href="' . $edit_lnk_url . '" title="' |
|
139 | - . esc_attr__('Edit Price', 'event_espresso') . '">' |
|
140 | - . __('Edit', 'event_espresso') . '</a>'; |
|
138 | + $actions['edit'] = '<a href="'.$edit_lnk_url.'" title="' |
|
139 | + . esc_attr__('Edit Price', 'event_espresso').'">' |
|
140 | + . __('Edit', 'event_espresso').'</a>'; |
|
141 | 141 | } |
142 | 142 | |
143 | 143 | $name_link = EE_Registry::instance()->CAP->current_user_can( |
@@ -145,9 +145,9 @@ discard block |
||
145 | 145 | 'edit_price', |
146 | 146 | $item->ID() |
147 | 147 | ) |
148 | - ? '<a href="' . $edit_lnk_url . '" title="' |
|
149 | - . esc_attr__('Edit Price', 'event_espresso') . '">' |
|
150 | - . stripslashes($item->name()) . '</a>' |
|
148 | + ? '<a href="'.$edit_lnk_url.'" title="' |
|
149 | + . esc_attr__('Edit Price', 'event_espresso').'">' |
|
150 | + . stripslashes($item->name()).'</a>' |
|
151 | 151 | : $item->name(); |
152 | 152 | |
153 | 153 | if ($item->type_obj()->base_type() !== 1) { |
@@ -163,9 +163,9 @@ discard block |
||
163 | 163 | 'id' => $item->ID(), |
164 | 164 | 'noheader' => true, |
165 | 165 | ), PRICING_ADMIN_URL); |
166 | - $actions['trash'] = '<a href="' . $trash_lnk_url . '" title="' |
|
167 | - . esc_attr__('Move Price to Trash', 'event_espresso') . '">' |
|
168 | - . __('Move to Trash', 'event_espresso') . '</a>'; |
|
166 | + $actions['trash'] = '<a href="'.$trash_lnk_url.'" title="' |
|
167 | + . esc_attr__('Move Price to Trash', 'event_espresso').'">' |
|
168 | + . __('Move to Trash', 'event_espresso').'</a>'; |
|
169 | 169 | } |
170 | 170 | } else { |
171 | 171 | if (EE_Registry::instance()->CAP->current_user_can( |
@@ -179,9 +179,9 @@ discard block |
||
179 | 179 | 'id' => $item->ID(), |
180 | 180 | 'noheader' => true, |
181 | 181 | ), PRICING_ADMIN_URL); |
182 | - $actions['restore'] = '<a href="' . $restore_lnk_url . '" title="' |
|
183 | - . esc_attr__('Restore Price', 'event_espresso') . '">' |
|
184 | - . __('Restore', 'event_espresso') . '</a>'; |
|
182 | + $actions['restore'] = '<a href="'.$restore_lnk_url.'" title="' |
|
183 | + . esc_attr__('Restore Price', 'event_espresso').'">' |
|
184 | + . __('Restore', 'event_espresso').'</a>'; |
|
185 | 185 | } |
186 | 186 | |
187 | 187 | // delete price link |
@@ -195,9 +195,9 @@ discard block |
||
195 | 195 | 'id' => $item->ID(), |
196 | 196 | 'noheader' => true, |
197 | 197 | ), PRICING_ADMIN_URL); |
198 | - $actions['delete'] = '<a href="' . $delete_lnk_url . '" title="' |
|
199 | - . esc_attr__('Delete Price Permanently', 'event_espresso') . '">' |
|
200 | - . __('Delete Permanently', 'event_espresso') . '</a>'; |
|
198 | + $actions['delete'] = '<a href="'.$delete_lnk_url.'" title="' |
|
199 | + . esc_attr__('Delete Price Permanently', 'event_espresso').'">' |
|
200 | + . __('Delete Permanently', 'event_espresso').'</a>'; |
|
201 | 201 | } |
202 | 202 | } |
203 | 203 | } |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | |
215 | 215 | public function column_type($item) |
216 | 216 | { |
217 | - return $this->_price_types[ $item->type() ]->name(); |
|
217 | + return $this->_price_types[$item->type()]->name(); |
|
218 | 218 | } |
219 | 219 | |
220 | 220 | |
@@ -226,10 +226,10 @@ discard block |
||
226 | 226 | |
227 | 227 | public function column_amount($item) |
228 | 228 | { |
229 | - if ($this->_price_types[ $item->type() ]->is_percent()) { |
|
230 | - return '<div class="pad-amnt-rght">' . number_format($item->amount(), 1) . '%</div>'; |
|
229 | + if ($this->_price_types[$item->type()]->is_percent()) { |
|
230 | + return '<div class="pad-amnt-rght">'.number_format($item->amount(), 1).'%</div>'; |
|
231 | 231 | } else { |
232 | - return '<div class="pad-amnt-rght">' . EEH_Template::format_currency($item->amount()) . '</div>'; |
|
232 | + return '<div class="pad-amnt-rght">'.EEH_Template::format_currency($item->amount()).'</div>'; |
|
233 | 233 | } |
234 | 234 | } |
235 | 235 | } |
@@ -10,138 +10,138 @@ |
||
10 | 10 | class EE_Taxes extends EE_Base |
11 | 11 | { |
12 | 12 | |
13 | - /** |
|
14 | - * This is used for when EE_Taxes is used statically by the admin |
|
15 | - * |
|
16 | - * @var array |
|
17 | - */ |
|
18 | - private static $_subtotal = array(); |
|
13 | + /** |
|
14 | + * This is used for when EE_Taxes is used statically by the admin |
|
15 | + * |
|
16 | + * @var array |
|
17 | + */ |
|
18 | + private static $_subtotal = array(); |
|
19 | 19 | |
20 | - /** |
|
21 | - * This holds an array of EE_Price objects that are of PRT_ID == 4 (tax price types) |
|
22 | - * |
|
23 | - * @var EE_Price[] |
|
24 | - */ |
|
25 | - private static $_default_taxes = array(); |
|
20 | + /** |
|
21 | + * This holds an array of EE_Price objects that are of PRT_ID == 4 (tax price types) |
|
22 | + * |
|
23 | + * @var EE_Price[] |
|
24 | + */ |
|
25 | + private static $_default_taxes = array(); |
|
26 | 26 | |
27 | 27 | |
28 | - /** |
|
29 | - * This method simply calculates the total taxes for a given ticket (by pulling the prices attached to the ticket |
|
30 | - * and applying default taxes to it). Note: this is just an intermediary helper method added to facilitate quick |
|
31 | - * calc of taxes for tickets listed in the event editor. |
|
32 | - * |
|
33 | - * @param EE_Ticket $ticket incoming EE_Ticket |
|
34 | - * @return float total taxes to apply to ticket. |
|
35 | - * @throws \EE_Error |
|
36 | - */ |
|
37 | - public static function get_total_taxes_for_admin(EE_Ticket $ticket) |
|
38 | - { |
|
39 | - $tax = 0; |
|
40 | - $total_tax = 0; |
|
41 | - // This first checks to see if the given ticket is taxable. |
|
42 | - if (! $ticket->get('TKT_taxable')) { |
|
43 | - return $tax; |
|
44 | - } |
|
45 | - // get subtotal (notice we're only retrieving a subtotal if there isn't one given) |
|
46 | - $subtotal = self::get_subtotal_for_admin($ticket); |
|
47 | - // get taxes |
|
48 | - $taxes = self::get_taxes_for_admin(); |
|
49 | - // apply taxes to subtotal |
|
50 | - foreach ($taxes as $tax) { |
|
51 | - // assuming taxes are not cumulative |
|
52 | - $total_tax += $subtotal * $tax->get('PRC_amount') / 100; |
|
53 | - } |
|
54 | - return $total_tax; |
|
55 | - } |
|
28 | + /** |
|
29 | + * This method simply calculates the total taxes for a given ticket (by pulling the prices attached to the ticket |
|
30 | + * and applying default taxes to it). Note: this is just an intermediary helper method added to facilitate quick |
|
31 | + * calc of taxes for tickets listed in the event editor. |
|
32 | + * |
|
33 | + * @param EE_Ticket $ticket incoming EE_Ticket |
|
34 | + * @return float total taxes to apply to ticket. |
|
35 | + * @throws \EE_Error |
|
36 | + */ |
|
37 | + public static function get_total_taxes_for_admin(EE_Ticket $ticket) |
|
38 | + { |
|
39 | + $tax = 0; |
|
40 | + $total_tax = 0; |
|
41 | + // This first checks to see if the given ticket is taxable. |
|
42 | + if (! $ticket->get('TKT_taxable')) { |
|
43 | + return $tax; |
|
44 | + } |
|
45 | + // get subtotal (notice we're only retrieving a subtotal if there isn't one given) |
|
46 | + $subtotal = self::get_subtotal_for_admin($ticket); |
|
47 | + // get taxes |
|
48 | + $taxes = self::get_taxes_for_admin(); |
|
49 | + // apply taxes to subtotal |
|
50 | + foreach ($taxes as $tax) { |
|
51 | + // assuming taxes are not cumulative |
|
52 | + $total_tax += $subtotal * $tax->get('PRC_amount') / 100; |
|
53 | + } |
|
54 | + return $total_tax; |
|
55 | + } |
|
56 | 56 | |
57 | 57 | |
58 | - /** |
|
59 | - * Gets the total percentage of tax that should be applied to taxable line items |
|
60 | - * |
|
61 | - * @return float the percentage of tax that should be added to taxable items |
|
62 | - * @throws \EE_Error |
|
63 | - * eg 20 for %20 tax (NOT 0.20, which |
|
64 | - */ |
|
65 | - public static function get_total_taxes_percentage() |
|
66 | - { |
|
67 | - $total_tax_percent = 0; |
|
68 | - foreach (self::get_taxes_for_admin() as $tax_price) { |
|
69 | - $total_tax_percent += $tax_price->get('PRC_amount'); |
|
70 | - } |
|
71 | - return $total_tax_percent; |
|
72 | - } |
|
58 | + /** |
|
59 | + * Gets the total percentage of tax that should be applied to taxable line items |
|
60 | + * |
|
61 | + * @return float the percentage of tax that should be added to taxable items |
|
62 | + * @throws \EE_Error |
|
63 | + * eg 20 for %20 tax (NOT 0.20, which |
|
64 | + */ |
|
65 | + public static function get_total_taxes_percentage() |
|
66 | + { |
|
67 | + $total_tax_percent = 0; |
|
68 | + foreach (self::get_taxes_for_admin() as $tax_price) { |
|
69 | + $total_tax_percent += $tax_price->get('PRC_amount'); |
|
70 | + } |
|
71 | + return $total_tax_percent; |
|
72 | + } |
|
73 | 73 | |
74 | 74 | |
75 | - /** |
|
76 | - * @param EE_Ticket $ticket |
|
77 | - * @return float |
|
78 | - * @throws \EE_Error |
|
79 | - */ |
|
80 | - public static function get_subtotal_for_admin(EE_Ticket $ticket) |
|
81 | - { |
|
82 | - $TKT_ID = $ticket->ID(); |
|
83 | - return isset(self::$_subtotal[ $TKT_ID ]) |
|
84 | - ? self::$_subtotal[ $TKT_ID ] |
|
85 | - : self::_get_subtotal_for_admin($ticket); |
|
86 | - } |
|
75 | + /** |
|
76 | + * @param EE_Ticket $ticket |
|
77 | + * @return float |
|
78 | + * @throws \EE_Error |
|
79 | + */ |
|
80 | + public static function get_subtotal_for_admin(EE_Ticket $ticket) |
|
81 | + { |
|
82 | + $TKT_ID = $ticket->ID(); |
|
83 | + return isset(self::$_subtotal[ $TKT_ID ]) |
|
84 | + ? self::$_subtotal[ $TKT_ID ] |
|
85 | + : self::_get_subtotal_for_admin($ticket); |
|
86 | + } |
|
87 | 87 | |
88 | 88 | |
89 | - /** |
|
90 | - * simply take an incoming ticket and calculate the subtotal for the ticket |
|
91 | - * |
|
92 | - * @param EE_Ticket $ticket |
|
93 | - * @return float subtotal calculated from all EE_Price[] on Ticket. |
|
94 | - * @throws \EE_Error |
|
95 | - */ |
|
96 | - private static function _get_subtotal_for_admin(EE_Ticket $ticket) |
|
97 | - { |
|
98 | - $subtotal = 0; |
|
99 | - // get all prices |
|
100 | - $prices = $ticket->get_many_related( |
|
101 | - 'Price', |
|
102 | - array( |
|
103 | - 'default_where_conditions' => 'none', |
|
104 | - 'order_by' => array('PRC_order' => 'ASC'), |
|
105 | - ) |
|
106 | - ); |
|
107 | - // let's loop through them (base price is always the first item) |
|
108 | - foreach ($prices as $price) { |
|
109 | - if ($price instanceof EE_Price) { |
|
110 | - $price_type = $price->type_obj(); |
|
111 | - if ($price_type instanceof EE_Price_Type) { |
|
112 | - switch ($price->type_obj()->base_type()) { |
|
113 | - case 1: // base price |
|
114 | - case 3: // surcharges |
|
115 | - $subtotal += $price->is_percent() ? $subtotal * $price->get('PRC_amount') / 100 |
|
116 | - : $price->get('PRC_amount'); |
|
117 | - break; |
|
118 | - case 2: // discounts |
|
119 | - $subtotal -= $price->is_percent() ? $subtotal * $price->get('PRC_amount') / 100 |
|
120 | - : $price->get('PRC_amount'); |
|
121 | - break; |
|
122 | - } |
|
123 | - } |
|
124 | - } |
|
125 | - } |
|
126 | - $TKT_ID = $ticket->ID(); |
|
127 | - self::$_subtotal = array($TKT_ID => $subtotal); |
|
128 | - return $subtotal; |
|
129 | - } |
|
89 | + /** |
|
90 | + * simply take an incoming ticket and calculate the subtotal for the ticket |
|
91 | + * |
|
92 | + * @param EE_Ticket $ticket |
|
93 | + * @return float subtotal calculated from all EE_Price[] on Ticket. |
|
94 | + * @throws \EE_Error |
|
95 | + */ |
|
96 | + private static function _get_subtotal_for_admin(EE_Ticket $ticket) |
|
97 | + { |
|
98 | + $subtotal = 0; |
|
99 | + // get all prices |
|
100 | + $prices = $ticket->get_many_related( |
|
101 | + 'Price', |
|
102 | + array( |
|
103 | + 'default_where_conditions' => 'none', |
|
104 | + 'order_by' => array('PRC_order' => 'ASC'), |
|
105 | + ) |
|
106 | + ); |
|
107 | + // let's loop through them (base price is always the first item) |
|
108 | + foreach ($prices as $price) { |
|
109 | + if ($price instanceof EE_Price) { |
|
110 | + $price_type = $price->type_obj(); |
|
111 | + if ($price_type instanceof EE_Price_Type) { |
|
112 | + switch ($price->type_obj()->base_type()) { |
|
113 | + case 1: // base price |
|
114 | + case 3: // surcharges |
|
115 | + $subtotal += $price->is_percent() ? $subtotal * $price->get('PRC_amount') / 100 |
|
116 | + : $price->get('PRC_amount'); |
|
117 | + break; |
|
118 | + case 2: // discounts |
|
119 | + $subtotal -= $price->is_percent() ? $subtotal * $price->get('PRC_amount') / 100 |
|
120 | + : $price->get('PRC_amount'); |
|
121 | + break; |
|
122 | + } |
|
123 | + } |
|
124 | + } |
|
125 | + } |
|
126 | + $TKT_ID = $ticket->ID(); |
|
127 | + self::$_subtotal = array($TKT_ID => $subtotal); |
|
128 | + return $subtotal; |
|
129 | + } |
|
130 | 130 | |
131 | 131 | |
132 | - /** |
|
133 | - * get all default prices that are a Tax price type (PRT_ID = 4) and return |
|
134 | - * |
|
135 | - * @return EE_Price[] EE_Price objects that have PRT_ID == 4 |
|
136 | - * @throws \EE_Error |
|
137 | - */ |
|
138 | - public static function get_taxes_for_admin() |
|
139 | - { |
|
140 | - if (empty(self::$_default_taxes)) { |
|
141 | - self::$_default_taxes = EE_Registry::instance()->load_model('Price')->get_all( |
|
142 | - array(array('Price_Type.PBT_ID' => 4)) |
|
143 | - ); |
|
144 | - } |
|
145 | - return self::$_default_taxes; |
|
146 | - } |
|
132 | + /** |
|
133 | + * get all default prices that are a Tax price type (PRT_ID = 4) and return |
|
134 | + * |
|
135 | + * @return EE_Price[] EE_Price objects that have PRT_ID == 4 |
|
136 | + * @throws \EE_Error |
|
137 | + */ |
|
138 | + public static function get_taxes_for_admin() |
|
139 | + { |
|
140 | + if (empty(self::$_default_taxes)) { |
|
141 | + self::$_default_taxes = EE_Registry::instance()->load_model('Price')->get_all( |
|
142 | + array(array('Price_Type.PBT_ID' => 4)) |
|
143 | + ); |
|
144 | + } |
|
145 | + return self::$_default_taxes; |
|
146 | + } |
|
147 | 147 | } |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | $tax = 0; |
40 | 40 | $total_tax = 0; |
41 | 41 | // This first checks to see if the given ticket is taxable. |
42 | - if (! $ticket->get('TKT_taxable')) { |
|
42 | + if ( ! $ticket->get('TKT_taxable')) { |
|
43 | 43 | return $tax; |
44 | 44 | } |
45 | 45 | // get subtotal (notice we're only retrieving a subtotal if there isn't one given) |
@@ -80,8 +80,8 @@ discard block |
||
80 | 80 | public static function get_subtotal_for_admin(EE_Ticket $ticket) |
81 | 81 | { |
82 | 82 | $TKT_ID = $ticket->ID(); |
83 | - return isset(self::$_subtotal[ $TKT_ID ]) |
|
84 | - ? self::$_subtotal[ $TKT_ID ] |
|
83 | + return isset(self::$_subtotal[$TKT_ID]) |
|
84 | + ? self::$_subtotal[$TKT_ID] |
|
85 | 85 | : self::_get_subtotal_for_admin($ticket); |
86 | 86 | } |
87 | 87 |
@@ -13,173 +13,173 @@ |
||
13 | 13 | class EE_Message_Template extends EE_Base_Class |
14 | 14 | { |
15 | 15 | |
16 | - /** |
|
17 | - * @param array $props_n_values |
|
18 | - * @param string $timezone |
|
19 | - * @return EE_Message_Template|mixed |
|
20 | - */ |
|
21 | - public static function new_instance($props_n_values = array(), $timezone = '') |
|
22 | - { |
|
23 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone); |
|
24 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone); |
|
25 | - } |
|
26 | - |
|
27 | - |
|
28 | - /** |
|
29 | - * @param array $props_n_values |
|
30 | - * @param string $timezone |
|
31 | - * @return EE_Message_Template |
|
32 | - */ |
|
33 | - public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
34 | - { |
|
35 | - return new self($props_n_values, true, $timezone); |
|
36 | - } |
|
37 | - |
|
38 | - |
|
39 | - /** |
|
40 | - * @param bool $GRP_ID |
|
41 | - * @throws EE_Error |
|
42 | - */ |
|
43 | - public function set_group_template_id($GRP_ID = false) |
|
44 | - { |
|
45 | - if (! $GRP_ID) { |
|
46 | - throw new EE_Error(__('Missing required value for the message template group id', 'event_espresso')); |
|
47 | - } |
|
48 | - $this->set('GRP_ID', $GRP_ID); |
|
49 | - } |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * get Group ID |
|
54 | - * |
|
55 | - * @access public |
|
56 | - * @return int |
|
57 | - */ |
|
58 | - public function GRP_ID() |
|
59 | - { |
|
60 | - return $this->get('GRP_ID'); |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * get User ID |
|
66 | - * |
|
67 | - * @access public |
|
68 | - * @return int |
|
69 | - */ |
|
70 | - public function user() |
|
71 | - { |
|
72 | - return $this->get_first_related('Message_Template_Group')->get('MTP_user_id'); |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * get Message Messenger |
|
78 | - * |
|
79 | - * @access public |
|
80 | - * @return string |
|
81 | - */ |
|
82 | - public function messenger() |
|
83 | - { |
|
84 | - return $this->get_first_related('Message_Template_Group')->messenger(); |
|
85 | - } |
|
86 | - |
|
87 | - |
|
88 | - /** |
|
89 | - * get Message Messenger OBJECT |
|
90 | - * |
|
91 | - * @access public |
|
92 | - * @return object Messenger Object for the given messenger |
|
93 | - */ |
|
94 | - public function messenger_obj() |
|
95 | - { |
|
96 | - return $this->get_first_related('Message_Template_Group')->messenger_obj(); |
|
97 | - } |
|
98 | - |
|
99 | - |
|
100 | - /** |
|
101 | - * get Message Type |
|
102 | - * |
|
103 | - * @access public |
|
104 | - * @return string |
|
105 | - */ |
|
106 | - public function message_type() |
|
107 | - { |
|
108 | - return $this->get_first_related('Message_Template_Group')->message_type(); |
|
109 | - } |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * get Message type OBJECT |
|
114 | - * |
|
115 | - * @access public |
|
116 | - * @return object Message Type object for the given message type |
|
117 | - */ |
|
118 | - public function message_type_obj() |
|
119 | - { |
|
120 | - return $this->get_first_related('Message_Template_Group')->message_type_obj(); |
|
121 | - } |
|
122 | - |
|
123 | - |
|
124 | - /** |
|
125 | - * This returns the set context array configured in the message type object |
|
126 | - * |
|
127 | - * @access public |
|
128 | - * @return array array of contexts and their configuration. |
|
129 | - */ |
|
130 | - public function contexts_config() |
|
131 | - { |
|
132 | - return $this->get_first_related('Message_Template_Group')->contexts_config(); |
|
133 | - } |
|
134 | - |
|
135 | - |
|
136 | - /** |
|
137 | - * This returns the context_label for contexts as set in the message type object |
|
138 | - * |
|
139 | - * @access public |
|
140 | - * @return string label for "context" |
|
141 | - */ |
|
142 | - public function context_label() |
|
143 | - { |
|
144 | - return $this->get_first_related('Message_Template_Group')->context_label(); |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * this returns if the template group this template belongs to is global |
|
150 | - * |
|
151 | - * @return boolean true if it is, false if it isn't |
|
152 | - */ |
|
153 | - public function is_global() |
|
154 | - { |
|
155 | - return $this->get_first_related('Message_Template_Group')->is_global(); |
|
156 | - } |
|
157 | - |
|
158 | - |
|
159 | - /** |
|
160 | - * this returns if the template group this template belongs to is active (i.e. turned "on" or not) |
|
161 | - * |
|
162 | - * @return boolean true if it is, false if it isn't |
|
163 | - */ |
|
164 | - public function is_active() |
|
165 | - { |
|
166 | - return $this->get_first_related('Message_Template_Group')->is_active(); |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * This will return an array of shortcodes => labels from the messenger and message_type objects associated with |
|
172 | - * this template. |
|
173 | - * |
|
174 | - * @access public |
|
175 | - * @param string $context what context we're going to return shortcodes for |
|
176 | - * @param array $fields what fields we're returning valid shortcodes for. If empty then we assume all fields are |
|
177 | - * to be merged and returned. |
|
178 | - * @return mixed (array|bool) an array of shortcodes in the format array( '[shortcode] => 'label') OR FALSE if no |
|
179 | - * shortcodes found. |
|
180 | - */ |
|
181 | - public function get_shortcodes($context, $fields = array()) |
|
182 | - { |
|
183 | - return $this->get_first_related('Message_Template_Group')->get_shortcodes($context, $fields); |
|
184 | - } |
|
16 | + /** |
|
17 | + * @param array $props_n_values |
|
18 | + * @param string $timezone |
|
19 | + * @return EE_Message_Template|mixed |
|
20 | + */ |
|
21 | + public static function new_instance($props_n_values = array(), $timezone = '') |
|
22 | + { |
|
23 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone); |
|
24 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone); |
|
25 | + } |
|
26 | + |
|
27 | + |
|
28 | + /** |
|
29 | + * @param array $props_n_values |
|
30 | + * @param string $timezone |
|
31 | + * @return EE_Message_Template |
|
32 | + */ |
|
33 | + public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
34 | + { |
|
35 | + return new self($props_n_values, true, $timezone); |
|
36 | + } |
|
37 | + |
|
38 | + |
|
39 | + /** |
|
40 | + * @param bool $GRP_ID |
|
41 | + * @throws EE_Error |
|
42 | + */ |
|
43 | + public function set_group_template_id($GRP_ID = false) |
|
44 | + { |
|
45 | + if (! $GRP_ID) { |
|
46 | + throw new EE_Error(__('Missing required value for the message template group id', 'event_espresso')); |
|
47 | + } |
|
48 | + $this->set('GRP_ID', $GRP_ID); |
|
49 | + } |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * get Group ID |
|
54 | + * |
|
55 | + * @access public |
|
56 | + * @return int |
|
57 | + */ |
|
58 | + public function GRP_ID() |
|
59 | + { |
|
60 | + return $this->get('GRP_ID'); |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * get User ID |
|
66 | + * |
|
67 | + * @access public |
|
68 | + * @return int |
|
69 | + */ |
|
70 | + public function user() |
|
71 | + { |
|
72 | + return $this->get_first_related('Message_Template_Group')->get('MTP_user_id'); |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * get Message Messenger |
|
78 | + * |
|
79 | + * @access public |
|
80 | + * @return string |
|
81 | + */ |
|
82 | + public function messenger() |
|
83 | + { |
|
84 | + return $this->get_first_related('Message_Template_Group')->messenger(); |
|
85 | + } |
|
86 | + |
|
87 | + |
|
88 | + /** |
|
89 | + * get Message Messenger OBJECT |
|
90 | + * |
|
91 | + * @access public |
|
92 | + * @return object Messenger Object for the given messenger |
|
93 | + */ |
|
94 | + public function messenger_obj() |
|
95 | + { |
|
96 | + return $this->get_first_related('Message_Template_Group')->messenger_obj(); |
|
97 | + } |
|
98 | + |
|
99 | + |
|
100 | + /** |
|
101 | + * get Message Type |
|
102 | + * |
|
103 | + * @access public |
|
104 | + * @return string |
|
105 | + */ |
|
106 | + public function message_type() |
|
107 | + { |
|
108 | + return $this->get_first_related('Message_Template_Group')->message_type(); |
|
109 | + } |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * get Message type OBJECT |
|
114 | + * |
|
115 | + * @access public |
|
116 | + * @return object Message Type object for the given message type |
|
117 | + */ |
|
118 | + public function message_type_obj() |
|
119 | + { |
|
120 | + return $this->get_first_related('Message_Template_Group')->message_type_obj(); |
|
121 | + } |
|
122 | + |
|
123 | + |
|
124 | + /** |
|
125 | + * This returns the set context array configured in the message type object |
|
126 | + * |
|
127 | + * @access public |
|
128 | + * @return array array of contexts and their configuration. |
|
129 | + */ |
|
130 | + public function contexts_config() |
|
131 | + { |
|
132 | + return $this->get_first_related('Message_Template_Group')->contexts_config(); |
|
133 | + } |
|
134 | + |
|
135 | + |
|
136 | + /** |
|
137 | + * This returns the context_label for contexts as set in the message type object |
|
138 | + * |
|
139 | + * @access public |
|
140 | + * @return string label for "context" |
|
141 | + */ |
|
142 | + public function context_label() |
|
143 | + { |
|
144 | + return $this->get_first_related('Message_Template_Group')->context_label(); |
|
145 | + } |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * this returns if the template group this template belongs to is global |
|
150 | + * |
|
151 | + * @return boolean true if it is, false if it isn't |
|
152 | + */ |
|
153 | + public function is_global() |
|
154 | + { |
|
155 | + return $this->get_first_related('Message_Template_Group')->is_global(); |
|
156 | + } |
|
157 | + |
|
158 | + |
|
159 | + /** |
|
160 | + * this returns if the template group this template belongs to is active (i.e. turned "on" or not) |
|
161 | + * |
|
162 | + * @return boolean true if it is, false if it isn't |
|
163 | + */ |
|
164 | + public function is_active() |
|
165 | + { |
|
166 | + return $this->get_first_related('Message_Template_Group')->is_active(); |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * This will return an array of shortcodes => labels from the messenger and message_type objects associated with |
|
172 | + * this template. |
|
173 | + * |
|
174 | + * @access public |
|
175 | + * @param string $context what context we're going to return shortcodes for |
|
176 | + * @param array $fields what fields we're returning valid shortcodes for. If empty then we assume all fields are |
|
177 | + * to be merged and returned. |
|
178 | + * @return mixed (array|bool) an array of shortcodes in the format array( '[shortcode] => 'label') OR FALSE if no |
|
179 | + * shortcodes found. |
|
180 | + */ |
|
181 | + public function get_shortcodes($context, $fields = array()) |
|
182 | + { |
|
183 | + return $this->get_first_related('Message_Template_Group')->get_shortcodes($context, $fields); |
|
184 | + } |
|
185 | 185 | } |
@@ -42,7 +42,7 @@ |
||
42 | 42 | */ |
43 | 43 | public function set_group_template_id($GRP_ID = false) |
44 | 44 | { |
45 | - if (! $GRP_ID) { |
|
45 | + if ( ! $GRP_ID) { |
|
46 | 46 | throw new EE_Error(__('Missing required value for the message template group id', 'event_espresso')); |
47 | 47 | } |
48 | 48 | $this->set('GRP_ID', $GRP_ID); |
@@ -11,25 +11,25 @@ |
||
11 | 11 | class EE_Ticket_Price extends EE_Base_Class |
12 | 12 | { |
13 | 13 | |
14 | - /** |
|
15 | - * @param array $props_n_values |
|
16 | - * @param string $timezone |
|
17 | - * @return EE_Ticket_Price|mixed |
|
18 | - */ |
|
19 | - public static function new_instance($props_n_values = array(), $timezone = '', $date_formats = array()) |
|
20 | - { |
|
21 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
22 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
23 | - } |
|
14 | + /** |
|
15 | + * @param array $props_n_values |
|
16 | + * @param string $timezone |
|
17 | + * @return EE_Ticket_Price|mixed |
|
18 | + */ |
|
19 | + public static function new_instance($props_n_values = array(), $timezone = '', $date_formats = array()) |
|
20 | + { |
|
21 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone, $date_formats); |
|
22 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone, $date_formats); |
|
23 | + } |
|
24 | 24 | |
25 | 25 | |
26 | - /** |
|
27 | - * @param array $props_n_values |
|
28 | - * @param string $timezone |
|
29 | - * @return EE_Ticket_Price |
|
30 | - */ |
|
31 | - public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
32 | - { |
|
33 | - return new self($props_n_values, true, $timezone); |
|
34 | - } |
|
26 | + /** |
|
27 | + * @param array $props_n_values |
|
28 | + * @param string $timezone |
|
29 | + * @return EE_Ticket_Price |
|
30 | + */ |
|
31 | + public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
32 | + { |
|
33 | + return new self($props_n_values, true, $timezone); |
|
34 | + } |
|
35 | 35 | } |
@@ -12,25 +12,25 @@ |
||
12 | 12 | class EE_Ticket_Template extends EE_Base_Class |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * @param array $props_n_values |
|
17 | - * @param string $timezone |
|
18 | - * @return EE_Ticket_Template|mixed |
|
19 | - */ |
|
20 | - public static function new_instance($props_n_values = array(), $timezone = '') |
|
21 | - { |
|
22 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone); |
|
23 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone); |
|
24 | - } |
|
15 | + /** |
|
16 | + * @param array $props_n_values |
|
17 | + * @param string $timezone |
|
18 | + * @return EE_Ticket_Template|mixed |
|
19 | + */ |
|
20 | + public static function new_instance($props_n_values = array(), $timezone = '') |
|
21 | + { |
|
22 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone); |
|
23 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone); |
|
24 | + } |
|
25 | 25 | |
26 | 26 | |
27 | - /** |
|
28 | - * @param array $props_n_values |
|
29 | - * @param string $timezone |
|
30 | - * @return EE_Ticket_Template |
|
31 | - */ |
|
32 | - public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
33 | - { |
|
34 | - return new self($props_n_values, true, $timezone); |
|
35 | - } |
|
27 | + /** |
|
28 | + * @param array $props_n_values |
|
29 | + * @param string $timezone |
|
30 | + * @return EE_Ticket_Template |
|
31 | + */ |
|
32 | + public static function new_instance_from_db($props_n_values = array(), $timezone = '') |
|
33 | + { |
|
34 | + return new self($props_n_values, true, $timezone); |
|
35 | + } |
|
36 | 36 | } |
@@ -10,23 +10,23 @@ |
||
10 | 10 | class EE_Term_Relationship extends EE_Base_Class |
11 | 11 | { |
12 | 12 | |
13 | - /** |
|
14 | - * @param array $props_n_values |
|
15 | - * @return EE_Term_Relationship |
|
16 | - */ |
|
17 | - public static function new_instance($props_n_values = array()) |
|
18 | - { |
|
19 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
20 | - return $has_object ? $has_object : new self($props_n_values); |
|
21 | - } |
|
13 | + /** |
|
14 | + * @param array $props_n_values |
|
15 | + * @return EE_Term_Relationship |
|
16 | + */ |
|
17 | + public static function new_instance($props_n_values = array()) |
|
18 | + { |
|
19 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
20 | + return $has_object ? $has_object : new self($props_n_values); |
|
21 | + } |
|
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * @param array $props_n_values |
|
26 | - * @return EE_Term_Relationship |
|
27 | - */ |
|
28 | - public static function new_instance_from_db($props_n_values = array()) |
|
29 | - { |
|
30 | - return new self($props_n_values, true); |
|
31 | - } |
|
24 | + /** |
|
25 | + * @param array $props_n_values |
|
26 | + * @return EE_Term_Relationship |
|
27 | + */ |
|
28 | + public static function new_instance_from_db($props_n_values = array()) |
|
29 | + { |
|
30 | + return new self($props_n_values, true); |
|
31 | + } |
|
32 | 32 | } |
@@ -44,7 +44,7 @@ discard block |
||
44 | 44 | { |
45 | 45 | $this->_req_data = $request_data; |
46 | 46 | $this->today = date("Y-m-d", time()); |
47 | - require_once(EE_CLASSES . 'EE_CSV.class.php'); |
|
47 | + require_once(EE_CLASSES.'EE_CSV.class.php'); |
|
48 | 48 | $this->EE_CSV = EE_CSV::instance(); |
49 | 49 | } |
50 | 50 | |
@@ -167,7 +167,7 @@ discard block |
||
167 | 167 | $value_to_equal = $EVT_ID; |
168 | 168 | $event = EE_Registry::instance()->load_model('Event')->get_one_by_ID($EVT_ID); |
169 | 169 | |
170 | - $filename = 'event-' . ($event instanceof EE_Event ? $event->slug() : __('unknown', 'event_espresso')); |
|
170 | + $filename = 'event-'.($event instanceof EE_Event ? $event->slug() : __('unknown', 'event_espresso')); |
|
171 | 171 | } |
172 | 172 | $event_query_params[0]['EVT_ID'] = $value_to_equal; |
173 | 173 | $related_models_query_params[0]['Event.EVT_ID'] = $value_to_equal; |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | |
217 | 217 | $filename = $this->generate_filename($filename); |
218 | 218 | |
219 | - if (! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $model_data)) { |
|
219 | + if ( ! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $model_data)) { |
|
220 | 220 | EE_Error::add_error( |
221 | 221 | __( |
222 | 222 | "'An error occurred and the Event details could not be exported from the database.'", |
@@ -243,16 +243,16 @@ discard block |
||
243 | 243 | foreach (EEM_Attendee::instance()->field_settings() as $field_name => $field_obj) { |
244 | 244 | if ($field_name == 'STA_ID') { |
245 | 245 | $state_name_field = EEM_State::instance()->field_settings_for('STA_name'); |
246 | - $csv_row[ __('State', 'event_espresso') ] = $attendee_row[ $state_name_field->get_qualified_column( |
|
247 | - ) ]; |
|
246 | + $csv_row[__('State', 'event_espresso')] = $attendee_row[$state_name_field->get_qualified_column( |
|
247 | + )]; |
|
248 | 248 | } elseif ($field_name == 'CNT_ISO') { |
249 | 249 | $country_name_field = EEM_Country::instance()->field_settings_for('CNT_name'); |
250 | - $csv_row[ __( |
|
250 | + $csv_row[__( |
|
251 | 251 | 'Country', |
252 | 252 | 'event_espresso' |
253 | - ) ] = $attendee_row[ $country_name_field->get_qualified_column() ]; |
|
253 | + )] = $attendee_row[$country_name_field->get_qualified_column()]; |
|
254 | 254 | } else { |
255 | - $csv_row[ $field_obj->get_nicename() ] = $attendee_row[ $field_obj->get_qualified_column() ]; |
|
255 | + $csv_row[$field_obj->get_nicename()] = $attendee_row[$field_obj->get_qualified_column()]; |
|
256 | 256 | } |
257 | 257 | } |
258 | 258 | $csv_data[] = $csv_row; |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | $model_data = $this->_get_export_data_for_models($models_to_export); |
292 | 292 | $filename = $this->generate_filename('all-attendees'); |
293 | 293 | |
294 | - if (! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $model_data)) { |
|
294 | + if ( ! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $model_data)) { |
|
295 | 295 | EE_Error::add_error( |
296 | 296 | __( |
297 | 297 | 'An error occurred and the Attendee data could not be exported from the database.', |
@@ -409,9 +409,9 @@ discard block |
||
409 | 409 | foreach ($registration_rows as $reg_row) { |
410 | 410 | if (is_array($reg_row)) { |
411 | 411 | $reg_csv_array = array(); |
412 | - if (! $event_id) { |
|
412 | + if ( ! $event_id) { |
|
413 | 413 | // get the event's name and Id |
414 | - $reg_csv_array[ __('Event', 'event_espresso') ] = sprintf( |
|
414 | + $reg_csv_array[__('Event', 'event_espresso')] = sprintf( |
|
415 | 415 | __('%1$s (%2$s)', 'event_espresso'), |
416 | 416 | $this->_prepare_value_from_db_for_display( |
417 | 417 | EEM_Event::instance(), |
@@ -457,13 +457,13 @@ discard block |
||
457 | 457 | $value = $this->_prepare_value_from_db_for_display( |
458 | 458 | $reg_model, |
459 | 459 | $field_name, |
460 | - $reg_row[ $field->get_qualified_column() ] |
|
460 | + $reg_row[$field->get_qualified_column()] |
|
461 | 461 | ); |
462 | 462 | } |
463 | - $reg_csv_array[ $this->_get_column_name_for_field($field) ] = $value; |
|
463 | + $reg_csv_array[$this->_get_column_name_for_field($field)] = $value; |
|
464 | 464 | if ($field_name == 'REG_final_price') { |
465 | 465 | // add a column named Currency after the final price |
466 | - $reg_csv_array[ __("Currency", "event_espresso") ] = EE_Config::instance()->currency->code; |
|
466 | + $reg_csv_array[__("Currency", "event_espresso")] = EE_Config::instance()->currency->code; |
|
467 | 467 | } |
468 | 468 | } |
469 | 469 | // get pretty status |
@@ -475,23 +475,23 @@ discard block |
||
475 | 475 | false, |
476 | 476 | 'sentence' |
477 | 477 | ); |
478 | - $reg_csv_array[ __( |
|
478 | + $reg_csv_array[__( |
|
479 | 479 | "Registration Status", |
480 | 480 | 'event_espresso' |
481 | - ) ] = $stati[ $reg_row['Registration.STS_ID'] ]; |
|
481 | + )] = $stati[$reg_row['Registration.STS_ID']]; |
|
482 | 482 | // get pretty trnasaction status |
483 | - $reg_csv_array[ __( |
|
483 | + $reg_csv_array[__( |
|
484 | 484 | "Transaction Status", |
485 | 485 | 'event_espresso' |
486 | - ) ] = $stati[ $reg_row['TransactionTable.STS_ID'] ]; |
|
487 | - $reg_csv_array[ __('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg |
|
486 | + )] = $stati[$reg_row['TransactionTable.STS_ID']]; |
|
487 | + $reg_csv_array[__('Transaction Amount Due', 'event_espresso')] = $is_primary_reg |
|
488 | 488 | ? $this->_prepare_value_from_db_for_display( |
489 | 489 | EEM_Transaction::instance(), |
490 | 490 | 'TXN_total', |
491 | 491 | $reg_row['TransactionTable.TXN_total'], |
492 | 492 | 'localized_float' |
493 | 493 | ) : '0.00'; |
494 | - $reg_csv_array[ __('Amount Paid', 'event_espresso') ] = $is_primary_reg |
|
494 | + $reg_csv_array[__('Amount Paid', 'event_espresso')] = $is_primary_reg |
|
495 | 495 | ? $this->_prepare_value_from_db_for_display( |
496 | 496 | EEM_Transaction::instance(), |
497 | 497 | 'TXN_paid', |
@@ -523,15 +523,15 @@ discard block |
||
523 | 523 | ? $payment_method_and_gateway_txn_id['payment_time'] : ''; |
524 | 524 | } |
525 | 525 | } |
526 | - $reg_csv_array[ __('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times); |
|
527 | - $reg_csv_array[ __('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods); |
|
528 | - $reg_csv_array[ __('Gateway Transaction ID(s)', 'event_espresso') ] = implode( |
|
526 | + $reg_csv_array[__('Payment Date(s)', 'event_espresso')] = implode(',', $payment_times); |
|
527 | + $reg_csv_array[__('Payment Method(s)', 'event_espresso')] = implode(",", $payment_methods); |
|
528 | + $reg_csv_array[__('Gateway Transaction ID(s)', 'event_espresso')] = implode( |
|
529 | 529 | ',', |
530 | 530 | $gateway_txn_ids_etc |
531 | 531 | ); |
532 | 532 | |
533 | 533 | // get whether or not the user has checked in |
534 | - $reg_csv_array[ __("Check-Ins", "event_espresso") ] = $reg_model->count_related( |
|
534 | + $reg_csv_array[__("Check-Ins", "event_espresso")] = $reg_model->count_related( |
|
535 | 535 | $reg_row['Registration.REG_ID'], |
536 | 536 | 'Checkin' |
537 | 537 | ); |
@@ -561,8 +561,8 @@ discard block |
||
561 | 561 | $ticket_name = __('Unknown', 'event_espresso'); |
562 | 562 | $datetimes_strings = array(__('Unknown', 'event_espresso')); |
563 | 563 | } |
564 | - $reg_csv_array[ $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name; |
|
565 | - $reg_csv_array[ __("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings); |
|
564 | + $reg_csv_array[$ticket_model->field_settings_for('TKT_name')->get_nicename()] = $ticket_name; |
|
565 | + $reg_csv_array[__("Datetimes of Ticket", "event_espresso")] = implode(", ", $datetimes_strings); |
|
566 | 566 | // get datetime(s) of registration |
567 | 567 | |
568 | 568 | // add attendee columns |
@@ -583,20 +583,20 @@ discard block |
||
583 | 583 | $value = $this->_prepare_value_from_db_for_display( |
584 | 584 | EEM_Attendee::instance(), |
585 | 585 | $att_field_name, |
586 | - $reg_row[ $field_obj->get_qualified_column() ] |
|
586 | + $reg_row[$field_obj->get_qualified_column()] |
|
587 | 587 | ); |
588 | 588 | } |
589 | 589 | } else { |
590 | 590 | $value = ''; |
591 | 591 | } |
592 | 592 | |
593 | - $reg_csv_array[ $this->_get_column_name_for_field($field_obj) ] = $value; |
|
593 | + $reg_csv_array[$this->_get_column_name_for_field($field_obj)] = $value; |
|
594 | 594 | } |
595 | 595 | |
596 | 596 | // make sure each registration has the same questions in the same order |
597 | 597 | foreach ($questions_for_these_regs_rows as $question_row) { |
598 | - if (! isset($reg_csv_array[ $question_row['Question.QST_admin_label'] ])) { |
|
599 | - $reg_csv_array[ $question_row['Question.QST_admin_label'] ] = null; |
|
598 | + if ( ! isset($reg_csv_array[$question_row['Question.QST_admin_label']])) { |
|
599 | + $reg_csv_array[$question_row['Question.QST_admin_label']] = null; |
|
600 | 600 | } |
601 | 601 | } |
602 | 602 | // now fill out the questions THEY answered |
@@ -614,11 +614,11 @@ discard block |
||
614 | 614 | $question_label = sprintf(__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']); |
615 | 615 | } |
616 | 616 | if (isset($answer_row['Question.QST_type']) && $answer_row['Question.QST_type'] == EEM_Question::QST_type_state) { |
617 | - $reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID( |
|
617 | + $reg_csv_array[$question_label] = EEM_State::instance()->get_state_name_by_ID( |
|
618 | 618 | $answer_row['Answer.ANS_value'] |
619 | 619 | ); |
620 | 620 | } else { |
621 | - $reg_csv_array[ $question_label ] = $this->_prepare_value_from_db_for_display( |
|
621 | + $reg_csv_array[$question_label] = $this->_prepare_value_from_db_for_display( |
|
622 | 622 | EEM_Answer::instance(), |
623 | 623 | 'ANS_value', |
624 | 624 | $answer_row['Answer.ANS_value'] |
@@ -644,16 +644,16 @@ discard block |
||
644 | 644 | $model = EE_Registry::instance()->load_model($model_name); |
645 | 645 | foreach ($field_list as $field_name) { |
646 | 646 | $field = $model->field_settings_for($field_name); |
647 | - $reg_csv_array[ $this->_get_column_name_for_field( |
|
647 | + $reg_csv_array[$this->_get_column_name_for_field( |
|
648 | 648 | $field |
649 | - ) ] = null;// $registration->get($field->get_name()); |
|
649 | + )] = null; // $registration->get($field->get_name()); |
|
650 | 650 | } |
651 | 651 | } |
652 | 652 | $registrations_csv_ready_array [] = $reg_csv_array; |
653 | 653 | } |
654 | 654 | if ($event_id) { |
655 | 655 | $event_slug = EEM_Event::instance()->get_var(array(array('EVT_ID' => $event_id)), 'EVT_slug'); |
656 | - if (! $event_slug) { |
|
656 | + if ( ! $event_slug) { |
|
657 | 657 | $event_slug = __('unknown', 'event_espresso'); |
658 | 658 | } |
659 | 659 | } else { |
@@ -674,7 +674,7 @@ discard block |
||
674 | 674 | */ |
675 | 675 | protected function _get_column_name_for_field(EE_Model_Field_Base $field) |
676 | 676 | { |
677 | - return $field->get_nicename() . "[" . $field->get_name() . "]"; |
|
677 | + return $field->get_nicename()."[".$field->get_name()."]"; |
|
678 | 678 | } |
679 | 679 | |
680 | 680 | |
@@ -697,7 +697,7 @@ discard block |
||
697 | 697 | } else { |
698 | 698 | // generate regular where = clause |
699 | 699 | $EVT_CAT_ID = absint($this->_req_data['EVT_CAT_ID']); |
700 | - $filename = 'event-category#' . $EVT_CAT_ID; |
|
700 | + $filename = 'event-category#'.$EVT_CAT_ID; |
|
701 | 701 | $query_params[0]['term_taxonomy_id'] = $EVT_CAT_ID; |
702 | 702 | } |
703 | 703 | } else { |
@@ -712,7 +712,7 @@ discard block |
||
712 | 712 | $table_data = $this->_get_export_data_for_models($tables_to_export); |
713 | 713 | $filename = $this->generate_filename($filename); |
714 | 714 | |
715 | - if (! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $table_data)) { |
|
715 | + if ( ! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $table_data)) { |
|
716 | 716 | EE_Error::add_error( |
717 | 717 | __( |
718 | 718 | 'An error occurred and the Category details could not be exported from the database.', |
@@ -735,8 +735,8 @@ discard block |
||
735 | 735 | private function generate_filename($export_name = '') |
736 | 736 | { |
737 | 737 | if ($export_name != '') { |
738 | - $filename = get_bloginfo('name') . '-' . $export_name; |
|
739 | - $filename = sanitize_key($filename) . '-' . $this->today; |
|
738 | + $filename = get_bloginfo('name').'-'.$export_name; |
|
739 | + $filename = sanitize_key($filename).'-'.$this->today; |
|
740 | 740 | return $filename; |
741 | 741 | } else { |
742 | 742 | EE_Error::add_error(__("No filename was provided", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
@@ -765,25 +765,25 @@ discard block |
||
765 | 765 | $model = EE_Registry::instance()->load_model($model_name); |
766 | 766 | $model_objects = $model->get_all($query_params); |
767 | 767 | |
768 | - $table_data[ $model_name ] = array(); |
|
768 | + $table_data[$model_name] = array(); |
|
769 | 769 | foreach ($model_objects as $model_object) { |
770 | 770 | $model_data_array = array(); |
771 | 771 | $fields = $model->field_settings(); |
772 | 772 | foreach ($fields as $field) { |
773 | - $column_name = $field->get_nicename() . "[" . $field->get_name() . "]"; |
|
773 | + $column_name = $field->get_nicename()."[".$field->get_name()."]"; |
|
774 | 774 | if ($field instanceof EE_Datetime_Field) { |
775 | 775 | // $field->set_date_format('Y-m-d'); |
776 | 776 | // $field->set_time_format('H:i:s'); |
777 | - $model_data_array[ $column_name ] = $model_object->get_datetime( |
|
777 | + $model_data_array[$column_name] = $model_object->get_datetime( |
|
778 | 778 | $field->get_name(), |
779 | 779 | 'Y-m-d', |
780 | 780 | 'H:i:s' |
781 | 781 | ); |
782 | 782 | } else { |
783 | - $model_data_array[ $column_name ] = $model_object->get($field->get_name()); |
|
783 | + $model_data_array[$column_name] = $model_object->get($field->get_name()); |
|
784 | 784 | } |
785 | 785 | } |
786 | - $table_data[ $model_name ][] = $model_data_array; |
|
786 | + $table_data[$model_name][] = $model_data_array; |
|
787 | 787 | } |
788 | 788 | } |
789 | 789 | } |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | /** |
70 | 70 | * @Export Event Espresso data - routes export requests |
71 | 71 | * @access public |
72 | - * @return void | bool |
|
72 | + * @return false|null | bool |
|
73 | 73 | */ |
74 | 74 | public function export() |
75 | 75 | { |
@@ -750,7 +750,7 @@ discard block |
||
750 | 750 | * @access private |
751 | 751 | * @param array $models_to_export keys are model names (eg 'Event', 'Attendee', etc.) and values are arrays of |
752 | 752 | * query params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
753 | - * @return array on success, FALSE on fail |
|
753 | + * @return boolean on success, FALSE on fail |
|
754 | 754 | */ |
755 | 755 | private function _get_export_data_for_models($models_to_export = array()) |
756 | 756 | { |
@@ -16,777 +16,777 @@ |
||
16 | 16 | class EE_Export |
17 | 17 | { |
18 | 18 | |
19 | - const option_prefix = 'ee_report_job_'; |
|
20 | - |
|
21 | - |
|
22 | - // instance of the EE_Export object |
|
23 | - private static $_instance = null; |
|
24 | - |
|
25 | - // instance of the EE_CSV object |
|
26 | - /** |
|
27 | - * |
|
28 | - * @var EE_CSV |
|
29 | - */ |
|
30 | - public $EE_CSV = null; |
|
31 | - |
|
32 | - |
|
33 | - private $_req_data = array(); |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * private constructor to prevent direct creation |
|
38 | - * |
|
39 | - * @Constructor |
|
40 | - * @access private |
|
41 | - * @param array $request_data |
|
42 | - */ |
|
43 | - private function __construct($request_data = array()) |
|
44 | - { |
|
45 | - $this->_req_data = $request_data; |
|
46 | - $this->today = date("Y-m-d", time()); |
|
47 | - require_once(EE_CLASSES . 'EE_CSV.class.php'); |
|
48 | - $this->EE_CSV = EE_CSV::instance(); |
|
49 | - } |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * @ singleton method used to instantiate class object |
|
54 | - * @ access public |
|
55 | - * |
|
56 | - * @param array $request_data |
|
57 | - * @return \EE_Export |
|
58 | - */ |
|
59 | - public static function instance($request_data = array()) |
|
60 | - { |
|
61 | - // check if class object is instantiated |
|
62 | - if (self::$_instance === null or ! is_object(self::$_instance) or ! (self::$_instance instanceof EE_Export)) { |
|
63 | - self::$_instance = new self($request_data); |
|
64 | - } |
|
65 | - return self::$_instance; |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * @Export Event Espresso data - routes export requests |
|
71 | - * @access public |
|
72 | - * @return void | bool |
|
73 | - */ |
|
74 | - public function export() |
|
75 | - { |
|
76 | - // in case of bulk exports, the "actual" action will be in action2, but first check regular action for "export" keyword |
|
77 | - if (isset($this->_req_data['action']) && strpos($this->_req_data['action'], 'export') === false) { |
|
78 | - // check if action2 has export action |
|
79 | - if (isset($this->_req_data['action2']) && strpos($this->_req_data['action2'], 'export') !== false) { |
|
80 | - // whoop! there it is! |
|
81 | - $this->_req_data['action'] = $this->_req_data['action2']; |
|
82 | - } |
|
83 | - } |
|
84 | - |
|
85 | - $this->_req_data['export'] = isset($this->_req_data['export']) ? $this->_req_data['export'] : ''; |
|
86 | - |
|
87 | - switch ($this->_req_data['export']) { |
|
88 | - case 'report': |
|
89 | - switch ($this->_req_data['action']) { |
|
90 | - case "event": |
|
91 | - case "export_events": |
|
92 | - case 'all_event_data': |
|
93 | - $this->export_all_event_data(); |
|
94 | - break; |
|
95 | - |
|
96 | - case 'registrations_report_for_event': |
|
97 | - $this->report_registrations_for_event($this->_req_data['EVT_ID']); |
|
98 | - break; |
|
99 | - |
|
100 | - case 'attendees': |
|
101 | - $this->export_attendees(); |
|
102 | - break; |
|
103 | - |
|
104 | - case 'categories': |
|
105 | - $this->export_categories(); |
|
106 | - break; |
|
107 | - |
|
108 | - default: |
|
109 | - EE_Error::add_error( |
|
110 | - __('An error occurred! The requested export report could not be found.', 'event_espresso'), |
|
111 | - __FILE__, |
|
112 | - __FUNCTION__, |
|
113 | - __LINE__ |
|
114 | - ); |
|
115 | - return false; |
|
116 | - break; |
|
117 | - } |
|
118 | - break; // end of switch export : report |
|
119 | - default: |
|
120 | - break; |
|
121 | - } // end of switch export |
|
122 | - |
|
123 | - exit; |
|
124 | - } |
|
125 | - |
|
126 | - /** |
|
127 | - * Downloads a CSV file with all the columns, but no data. This should be used for importing |
|
128 | - * |
|
129 | - * @return null kills execution |
|
130 | - */ |
|
131 | - public function export_sample() |
|
132 | - { |
|
133 | - $event = EEM_Event::instance()->get_one(); |
|
134 | - $this->_req_data['EVT_ID'] = $event->ID(); |
|
135 | - $this->export_all_event_data(); |
|
136 | - } |
|
137 | - |
|
138 | - |
|
139 | - /** |
|
140 | - * @Export data for ALL events |
|
141 | - * @access public |
|
142 | - * @return void |
|
143 | - */ |
|
144 | - public function export_all_event_data() |
|
145 | - { |
|
146 | - // are any Event IDs set? |
|
147 | - $event_query_params = array(); |
|
148 | - $related_models_query_params = array(); |
|
149 | - $related_through_reg_query_params = array(); |
|
150 | - $datetime_ticket_query_params = array(); |
|
151 | - $price_query_params = array(); |
|
152 | - $price_type_query_params = array(); |
|
153 | - $term_query_params = array(); |
|
154 | - $state_country_query_params = array(); |
|
155 | - $question_group_query_params = array(); |
|
156 | - $question_query_params = array(); |
|
157 | - if (isset($this->_req_data['EVT_ID'])) { |
|
158 | - // do we have an array of IDs ? |
|
159 | - |
|
160 | - if (is_array($this->_req_data['EVT_ID'])) { |
|
161 | - $EVT_IDs = array_map('sanitize_text_field', $this->_req_data['EVT_ID']); |
|
162 | - $value_to_equal = array('IN', $EVT_IDs); |
|
163 | - $filename = 'events'; |
|
164 | - } else { |
|
165 | - // generate regular where = clause |
|
166 | - $EVT_ID = absint($this->_req_data['EVT_ID']); |
|
167 | - $value_to_equal = $EVT_ID; |
|
168 | - $event = EE_Registry::instance()->load_model('Event')->get_one_by_ID($EVT_ID); |
|
169 | - |
|
170 | - $filename = 'event-' . ($event instanceof EE_Event ? $event->slug() : __('unknown', 'event_espresso')); |
|
171 | - } |
|
172 | - $event_query_params[0]['EVT_ID'] = $value_to_equal; |
|
173 | - $related_models_query_params[0]['Event.EVT_ID'] = $value_to_equal; |
|
174 | - $related_through_reg_query_params[0]['Registration.EVT_ID'] = $value_to_equal; |
|
175 | - $datetime_ticket_query_params[0]['Datetime.EVT_ID'] = $value_to_equal; |
|
176 | - $price_query_params[0]['Ticket.Datetime.EVT_ID'] = $value_to_equal; |
|
177 | - $price_type_query_params[0]['Price.Ticket.Datetime.EVT_ID'] = $value_to_equal; |
|
178 | - $term_query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $value_to_equal; |
|
179 | - $state_country_query_params[0]['Venue.Event.EVT_ID'] = $value_to_equal; |
|
180 | - $question_group_query_params[0]['Event.EVT_ID'] = $value_to_equal; |
|
181 | - $question_query_params[0]['Question_Group.Event.EVT_ID'] = $value_to_equal; |
|
182 | - } else { |
|
183 | - $filename = 'all-events'; |
|
184 | - } |
|
185 | - |
|
186 | - |
|
187 | - // array in the format: table name => query where clause |
|
188 | - $models_to_export = array( |
|
189 | - 'Event' => $event_query_params, |
|
190 | - 'Datetime' => $related_models_query_params, |
|
191 | - 'Ticket_Template' => $price_query_params, |
|
192 | - 'Ticket' => $datetime_ticket_query_params, |
|
193 | - 'Datetime_Ticket' => $datetime_ticket_query_params, |
|
194 | - 'Price_Type' => $price_type_query_params, |
|
195 | - 'Price' => $price_query_params, |
|
196 | - 'Ticket_Price' => $price_query_params, |
|
197 | - 'Term' => $term_query_params, |
|
198 | - 'Term_Taxonomy' => $related_models_query_params, |
|
199 | - 'Term_Relationship' => $related_models_query_params, // model has NO primary key... |
|
200 | - 'Country' => $state_country_query_params, |
|
201 | - 'State' => $state_country_query_params, |
|
202 | - 'Venue' => $related_models_query_params, |
|
203 | - 'Event_Venue' => $related_models_query_params, |
|
204 | - 'Question_Group' => $question_group_query_params, |
|
205 | - 'Event_Question_Group' => $question_group_query_params, |
|
206 | - 'Question' => $question_query_params, |
|
207 | - 'Question_Group_Question' => $question_query_params, |
|
208 | - // 'Transaction'=>$related_through_reg_query_params, |
|
209 | - // 'Registration'=>$related_models_query_params, |
|
210 | - // 'Attendee'=>$related_through_reg_query_params, |
|
211 | - // 'Line_Item'=> |
|
212 | - |
|
213 | - ); |
|
214 | - |
|
215 | - $model_data = $this->_get_export_data_for_models($models_to_export); |
|
216 | - |
|
217 | - $filename = $this->generate_filename($filename); |
|
218 | - |
|
219 | - if (! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $model_data)) { |
|
220 | - EE_Error::add_error( |
|
221 | - __( |
|
222 | - "'An error occurred and the Event details could not be exported from the database.'", |
|
223 | - "event_espresso" |
|
224 | - ), |
|
225 | - __FILE__, |
|
226 | - __FUNCTION__, |
|
227 | - __LINE__ |
|
228 | - ); |
|
229 | - } |
|
230 | - } |
|
231 | - |
|
232 | - public function report_attendees() |
|
233 | - { |
|
234 | - $attendee_rows = EEM_Attendee::instance()->get_all_wpdb_results( |
|
235 | - array( |
|
236 | - 'force_join' => array('State', 'Country'), |
|
237 | - 'caps' => EEM_Base::caps_read_admin, |
|
238 | - ) |
|
239 | - ); |
|
240 | - $csv_data = array(); |
|
241 | - foreach ($attendee_rows as $attendee_row) { |
|
242 | - $csv_row = array(); |
|
243 | - foreach (EEM_Attendee::instance()->field_settings() as $field_name => $field_obj) { |
|
244 | - if ($field_name == 'STA_ID') { |
|
245 | - $state_name_field = EEM_State::instance()->field_settings_for('STA_name'); |
|
246 | - $csv_row[ __('State', 'event_espresso') ] = $attendee_row[ $state_name_field->get_qualified_column( |
|
247 | - ) ]; |
|
248 | - } elseif ($field_name == 'CNT_ISO') { |
|
249 | - $country_name_field = EEM_Country::instance()->field_settings_for('CNT_name'); |
|
250 | - $csv_row[ __( |
|
251 | - 'Country', |
|
252 | - 'event_espresso' |
|
253 | - ) ] = $attendee_row[ $country_name_field->get_qualified_column() ]; |
|
254 | - } else { |
|
255 | - $csv_row[ $field_obj->get_nicename() ] = $attendee_row[ $field_obj->get_qualified_column() ]; |
|
256 | - } |
|
257 | - } |
|
258 | - $csv_data[] = $csv_row; |
|
259 | - } |
|
260 | - |
|
261 | - $filename = $this->generate_filename('contact-list-report'); |
|
262 | - |
|
263 | - $handle = $this->EE_CSV->begin_sending_csv($filename); |
|
264 | - $this->EE_CSV->write_data_array_to_csv($handle, $csv_data); |
|
265 | - $this->EE_CSV->end_sending_csv($handle); |
|
266 | - } |
|
267 | - |
|
268 | - |
|
269 | - /** |
|
270 | - * @Export data for ALL attendees |
|
271 | - * @access public |
|
272 | - * @return void |
|
273 | - */ |
|
274 | - public function export_attendees() |
|
275 | - { |
|
276 | - |
|
277 | - $states_that_have_an_attendee = EEM_State::instance()->get_all( |
|
278 | - array(0 => array('Attendee.ATT_ID' => array('IS NOT NULL'))) |
|
279 | - ); |
|
280 | - $countries_that_have_an_attendee = EEM_Country::instance()->get_all( |
|
281 | - array(0 => array('Attendee.ATT_ID' => array('IS NOT NULL'))) |
|
282 | - ); |
|
283 | - // $states_to_export_query_params |
|
284 | - $models_to_export = array( |
|
285 | - 'Country' => array(array('CNT_ISO' => array('IN', array_keys($countries_that_have_an_attendee)))), |
|
286 | - 'State' => array(array('STA_ID' => array('IN', array_keys($states_that_have_an_attendee)))), |
|
287 | - 'Attendee' => array(), |
|
288 | - ); |
|
289 | - |
|
290 | - |
|
291 | - $model_data = $this->_get_export_data_for_models($models_to_export); |
|
292 | - $filename = $this->generate_filename('all-attendees'); |
|
293 | - |
|
294 | - if (! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $model_data)) { |
|
295 | - EE_Error::add_error( |
|
296 | - __( |
|
297 | - 'An error occurred and the Attendee data could not be exported from the database.', |
|
298 | - 'event_espresso' |
|
299 | - ), |
|
300 | - __FILE__, |
|
301 | - __FUNCTION__, |
|
302 | - __LINE__ |
|
303 | - ); |
|
304 | - } |
|
305 | - } |
|
306 | - |
|
307 | - /** |
|
308 | - * Shortcut for preparing a database result for display |
|
309 | - * |
|
310 | - * @param EEM_Base $model |
|
311 | - * @param string $field_name |
|
312 | - * @param string $raw_db_value |
|
313 | - * @param boolean|string $pretty_schema true to display pretty, a string to use a specific "Schema", or false to |
|
314 | - * NOT display pretty |
|
315 | - * @return string |
|
316 | - */ |
|
317 | - protected function _prepare_value_from_db_for_display($model, $field_name, $raw_db_value, $pretty_schema = true) |
|
318 | - { |
|
319 | - $field_obj = $model->field_settings_for($field_name); |
|
320 | - $value_on_model_obj = $field_obj->prepare_for_set_from_db($raw_db_value); |
|
321 | - if ($field_obj instanceof EE_Datetime_Field) { |
|
322 | - $field_obj->set_date_format( |
|
323 | - EE_CSV::instance()->get_date_format_for_csv($field_obj->get_date_format($pretty_schema)), |
|
324 | - $pretty_schema |
|
325 | - ); |
|
326 | - $field_obj->set_time_format( |
|
327 | - EE_CSV::instance()->get_time_format_for_csv($field_obj->get_time_format($pretty_schema)), |
|
328 | - $pretty_schema |
|
329 | - ); |
|
330 | - } |
|
331 | - if ($pretty_schema === true) { |
|
332 | - return $field_obj->prepare_for_pretty_echoing($value_on_model_obj); |
|
333 | - } elseif (is_string($pretty_schema)) { |
|
334 | - return $field_obj->prepare_for_pretty_echoing($value_on_model_obj, $pretty_schema); |
|
335 | - } else { |
|
336 | - return $field_obj->prepare_for_get($value_on_model_obj); |
|
337 | - } |
|
338 | - } |
|
339 | - |
|
340 | - /** |
|
341 | - * Export a custom CSV of registration info including: A bunch of the reg fields, the time of the event, the price |
|
342 | - * name, and the questions associated with the registrations |
|
343 | - * |
|
344 | - * @param int $event_id |
|
345 | - */ |
|
346 | - public function report_registrations_for_event($event_id = null) |
|
347 | - { |
|
348 | - $reg_fields_to_include = array( |
|
349 | - 'TXN_ID', |
|
350 | - 'ATT_ID', |
|
351 | - 'REG_ID', |
|
352 | - 'REG_date', |
|
353 | - 'REG_code', |
|
354 | - 'REG_count', |
|
355 | - 'REG_final_price', |
|
356 | - |
|
357 | - ); |
|
358 | - $att_fields_to_include = array( |
|
359 | - 'ATT_fname', |
|
360 | - 'ATT_lname', |
|
361 | - 'ATT_email', |
|
362 | - 'ATT_address', |
|
363 | - 'ATT_address2', |
|
364 | - 'ATT_city', |
|
365 | - 'STA_ID', |
|
366 | - 'CNT_ISO', |
|
367 | - 'ATT_zip', |
|
368 | - 'ATT_phone', |
|
369 | - ); |
|
370 | - |
|
371 | - $registrations_csv_ready_array = array(); |
|
372 | - $reg_model = EE_Registry::instance()->load_model('Registration'); |
|
373 | - $query_params = apply_filters( |
|
374 | - 'FHEE__EE_Export__report_registration_for_event', |
|
375 | - array( |
|
376 | - array( |
|
377 | - 'OR' => array( |
|
378 | - // don't include registrations from failed or abandoned transactions... |
|
379 | - 'Transaction.STS_ID' => array( |
|
380 | - 'NOT IN', |
|
381 | - array(EEM_Transaction::failed_status_code, EEM_Transaction::abandoned_status_code), |
|
382 | - ), |
|
383 | - // unless the registration is approved, in which case include it regardless of transaction status |
|
384 | - 'STS_ID' => EEM_Registration::status_id_approved, |
|
385 | - ), |
|
386 | - 'Ticket.TKT_deleted' => array('IN', array(true, false)), |
|
387 | - ), |
|
388 | - 'order_by' => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'), |
|
389 | - 'force_join' => array('Transaction', 'Ticket', 'Attendee'), |
|
390 | - 'caps' => EEM_Base::caps_read_admin, |
|
391 | - ), |
|
392 | - $event_id |
|
393 | - ); |
|
394 | - if ($event_id) { |
|
395 | - $query_params[0]['EVT_ID'] = $event_id; |
|
396 | - } else { |
|
397 | - $query_params['force_join'][] = 'Event'; |
|
398 | - } |
|
399 | - $registration_rows = $reg_model->get_all_wpdb_results($query_params); |
|
400 | - // get all questions which relate to someone in this group |
|
401 | - $registration_ids = array(); |
|
402 | - foreach ($registration_rows as $reg_row) { |
|
403 | - $registration_ids[] = intval($reg_row['Registration.REG_ID']); |
|
404 | - } |
|
405 | - // EEM_Question::instance()->show_next_x_db_queries(); |
|
406 | - $questions_for_these_regs_rows = EEM_Question::instance()->get_all_wpdb_results( |
|
407 | - array(array('Answer.REG_ID' => array('IN', $registration_ids))) |
|
408 | - ); |
|
409 | - foreach ($registration_rows as $reg_row) { |
|
410 | - if (is_array($reg_row)) { |
|
411 | - $reg_csv_array = array(); |
|
412 | - if (! $event_id) { |
|
413 | - // get the event's name and Id |
|
414 | - $reg_csv_array[ __('Event', 'event_espresso') ] = sprintf( |
|
415 | - __('%1$s (%2$s)', 'event_espresso'), |
|
416 | - $this->_prepare_value_from_db_for_display( |
|
417 | - EEM_Event::instance(), |
|
418 | - 'EVT_name', |
|
419 | - $reg_row['Event_CPT.post_title'] |
|
420 | - ), |
|
421 | - $reg_row['Event_CPT.ID'] |
|
422 | - ); |
|
423 | - } |
|
424 | - $is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false; |
|
425 | - /*@var $reg_row EE_Registration */ |
|
426 | - foreach ($reg_fields_to_include as $field_name) { |
|
427 | - $field = $reg_model->field_settings_for($field_name); |
|
428 | - if ($field_name == 'REG_final_price') { |
|
429 | - $value = $this->_prepare_value_from_db_for_display( |
|
430 | - $reg_model, |
|
431 | - $field_name, |
|
432 | - $reg_row['Registration.REG_final_price'], |
|
433 | - 'localized_float' |
|
434 | - ); |
|
435 | - } elseif ($field_name == 'REG_count') { |
|
436 | - $value = sprintf( |
|
437 | - __('%s of %s', 'event_espresso'), |
|
438 | - $this->_prepare_value_from_db_for_display( |
|
439 | - $reg_model, |
|
440 | - 'REG_count', |
|
441 | - $reg_row['Registration.REG_count'] |
|
442 | - ), |
|
443 | - $this->_prepare_value_from_db_for_display( |
|
444 | - $reg_model, |
|
445 | - 'REG_group_size', |
|
446 | - $reg_row['Registration.REG_group_size'] |
|
447 | - ) |
|
448 | - ); |
|
449 | - } elseif ($field_name == 'REG_date') { |
|
450 | - $value = $this->_prepare_value_from_db_for_display( |
|
451 | - $reg_model, |
|
452 | - $field_name, |
|
453 | - $reg_row['Registration.REG_date'], |
|
454 | - 'no_html' |
|
455 | - ); |
|
456 | - } else { |
|
457 | - $value = $this->_prepare_value_from_db_for_display( |
|
458 | - $reg_model, |
|
459 | - $field_name, |
|
460 | - $reg_row[ $field->get_qualified_column() ] |
|
461 | - ); |
|
462 | - } |
|
463 | - $reg_csv_array[ $this->_get_column_name_for_field($field) ] = $value; |
|
464 | - if ($field_name == 'REG_final_price') { |
|
465 | - // add a column named Currency after the final price |
|
466 | - $reg_csv_array[ __("Currency", "event_espresso") ] = EE_Config::instance()->currency->code; |
|
467 | - } |
|
468 | - } |
|
469 | - // get pretty status |
|
470 | - $stati = EEM_Status::instance()->localized_status( |
|
471 | - array( |
|
472 | - $reg_row['Registration.STS_ID'] => __('unknown', 'event_espresso'), |
|
473 | - $reg_row['TransactionTable.STS_ID'] => __('unknown', 'event_espresso'), |
|
474 | - ), |
|
475 | - false, |
|
476 | - 'sentence' |
|
477 | - ); |
|
478 | - $reg_csv_array[ __( |
|
479 | - "Registration Status", |
|
480 | - 'event_espresso' |
|
481 | - ) ] = $stati[ $reg_row['Registration.STS_ID'] ]; |
|
482 | - // get pretty trnasaction status |
|
483 | - $reg_csv_array[ __( |
|
484 | - "Transaction Status", |
|
485 | - 'event_espresso' |
|
486 | - ) ] = $stati[ $reg_row['TransactionTable.STS_ID'] ]; |
|
487 | - $reg_csv_array[ __('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg |
|
488 | - ? $this->_prepare_value_from_db_for_display( |
|
489 | - EEM_Transaction::instance(), |
|
490 | - 'TXN_total', |
|
491 | - $reg_row['TransactionTable.TXN_total'], |
|
492 | - 'localized_float' |
|
493 | - ) : '0.00'; |
|
494 | - $reg_csv_array[ __('Amount Paid', 'event_espresso') ] = $is_primary_reg |
|
495 | - ? $this->_prepare_value_from_db_for_display( |
|
496 | - EEM_Transaction::instance(), |
|
497 | - 'TXN_paid', |
|
498 | - $reg_row['TransactionTable.TXN_paid'], |
|
499 | - 'localized_float' |
|
500 | - ) : '0.00'; |
|
501 | - $payment_methods = array(); |
|
502 | - $gateway_txn_ids_etc = array(); |
|
503 | - $payment_times = array(); |
|
504 | - if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) { |
|
505 | - $payments_info = EEM_Payment::instance()->get_all_wpdb_results( |
|
506 | - array( |
|
507 | - array( |
|
508 | - 'TXN_ID' => $reg_row['TransactionTable.TXN_ID'], |
|
509 | - 'STS_ID' => EEM_Payment::status_id_approved, |
|
510 | - ), |
|
511 | - 'force_join' => array('Payment_Method'), |
|
512 | - ), |
|
513 | - ARRAY_A, |
|
514 | - 'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time' |
|
515 | - ); |
|
516 | - |
|
517 | - foreach ($payments_info as $payment_method_and_gateway_txn_id) { |
|
518 | - $payment_methods[] = isset($payment_method_and_gateway_txn_id['name']) |
|
519 | - ? $payment_method_and_gateway_txn_id['name'] : __('Unknown', 'event_espresso'); |
|
520 | - $gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id']) |
|
521 | - ? $payment_method_and_gateway_txn_id['gateway_txn_id'] : ''; |
|
522 | - $payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time']) |
|
523 | - ? $payment_method_and_gateway_txn_id['payment_time'] : ''; |
|
524 | - } |
|
525 | - } |
|
526 | - $reg_csv_array[ __('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times); |
|
527 | - $reg_csv_array[ __('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods); |
|
528 | - $reg_csv_array[ __('Gateway Transaction ID(s)', 'event_espresso') ] = implode( |
|
529 | - ',', |
|
530 | - $gateway_txn_ids_etc |
|
531 | - ); |
|
532 | - |
|
533 | - // get whether or not the user has checked in |
|
534 | - $reg_csv_array[ __("Check-Ins", "event_espresso") ] = $reg_model->count_related( |
|
535 | - $reg_row['Registration.REG_ID'], |
|
536 | - 'Checkin' |
|
537 | - ); |
|
538 | - // get ticket of registration and its price |
|
539 | - $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
540 | - if ($reg_row['Ticket.TKT_ID']) { |
|
541 | - $ticket_name = $this->_prepare_value_from_db_for_display( |
|
542 | - $ticket_model, |
|
543 | - 'TKT_name', |
|
544 | - $reg_row['Ticket.TKT_name'] |
|
545 | - ); |
|
546 | - $datetimes_strings = array(); |
|
547 | - foreach (EEM_Datetime::instance()->get_all_wpdb_results( |
|
548 | - array( |
|
549 | - array('Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']), |
|
550 | - 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
551 | - 'default_where_conditions' => 'none', |
|
552 | - ) |
|
553 | - ) as $datetime) { |
|
554 | - $datetimes_strings[] = $this->_prepare_value_from_db_for_display( |
|
555 | - EEM_Datetime::instance(), |
|
556 | - 'DTT_EVT_start', |
|
557 | - $datetime['Datetime.DTT_EVT_start'] |
|
558 | - ); |
|
559 | - } |
|
560 | - } else { |
|
561 | - $ticket_name = __('Unknown', 'event_espresso'); |
|
562 | - $datetimes_strings = array(__('Unknown', 'event_espresso')); |
|
563 | - } |
|
564 | - $reg_csv_array[ $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name; |
|
565 | - $reg_csv_array[ __("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings); |
|
566 | - // get datetime(s) of registration |
|
567 | - |
|
568 | - // add attendee columns |
|
569 | - foreach ($att_fields_to_include as $att_field_name) { |
|
570 | - $field_obj = EEM_Attendee::instance()->field_settings_for($att_field_name); |
|
571 | - if ($reg_row['Attendee_CPT.ID']) { |
|
572 | - if ($att_field_name == 'STA_ID') { |
|
573 | - $value = EEM_State::instance()->get_var( |
|
574 | - array(array('STA_ID' => $reg_row['Attendee_Meta.STA_ID'])), |
|
575 | - 'STA_name' |
|
576 | - ); |
|
577 | - } elseif ($att_field_name == 'CNT_ISO') { |
|
578 | - $value = EEM_Country::instance()->get_var( |
|
579 | - array(array('CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO'])), |
|
580 | - 'CNT_name' |
|
581 | - ); |
|
582 | - } else { |
|
583 | - $value = $this->_prepare_value_from_db_for_display( |
|
584 | - EEM_Attendee::instance(), |
|
585 | - $att_field_name, |
|
586 | - $reg_row[ $field_obj->get_qualified_column() ] |
|
587 | - ); |
|
588 | - } |
|
589 | - } else { |
|
590 | - $value = ''; |
|
591 | - } |
|
592 | - |
|
593 | - $reg_csv_array[ $this->_get_column_name_for_field($field_obj) ] = $value; |
|
594 | - } |
|
595 | - |
|
596 | - // make sure each registration has the same questions in the same order |
|
597 | - foreach ($questions_for_these_regs_rows as $question_row) { |
|
598 | - if (! isset($reg_csv_array[ $question_row['Question.QST_admin_label'] ])) { |
|
599 | - $reg_csv_array[ $question_row['Question.QST_admin_label'] ] = null; |
|
600 | - } |
|
601 | - } |
|
602 | - // now fill out the questions THEY answered |
|
603 | - foreach (EEM_Answer::instance()->get_all_wpdb_results( |
|
604 | - array(array('REG_ID' => $reg_row['Registration.REG_ID']), 'force_join' => array('Question')) |
|
605 | - ) as $answer_row) { |
|
606 | - /* @var $answer EE_Answer */ |
|
607 | - if ($answer_row['Question.QST_ID']) { |
|
608 | - $question_label = $this->_prepare_value_from_db_for_display( |
|
609 | - EEM_Question::instance(), |
|
610 | - 'QST_admin_label', |
|
611 | - $answer_row['Question.QST_admin_label'] |
|
612 | - ); |
|
613 | - } else { |
|
614 | - $question_label = sprintf(__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']); |
|
615 | - } |
|
616 | - if (isset($answer_row['Question.QST_type']) && $answer_row['Question.QST_type'] == EEM_Question::QST_type_state) { |
|
617 | - $reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID( |
|
618 | - $answer_row['Answer.ANS_value'] |
|
619 | - ); |
|
620 | - } else { |
|
621 | - $reg_csv_array[ $question_label ] = $this->_prepare_value_from_db_for_display( |
|
622 | - EEM_Answer::instance(), |
|
623 | - 'ANS_value', |
|
624 | - $answer_row['Answer.ANS_value'] |
|
625 | - ); |
|
626 | - } |
|
627 | - } |
|
628 | - $registrations_csv_ready_array[] = apply_filters( |
|
629 | - 'FHEE__EE_Export__report_registrations__reg_csv_array', |
|
630 | - $reg_csv_array, |
|
631 | - $reg_row |
|
632 | - ); |
|
633 | - } |
|
634 | - } |
|
635 | - |
|
636 | - // if we couldn't export anything, we want to at least show the column headers |
|
637 | - if (empty($registrations_csv_ready_array)) { |
|
638 | - $reg_csv_array = array(); |
|
639 | - $model_and_fields_to_include = array( |
|
640 | - 'Registration' => $reg_fields_to_include, |
|
641 | - 'Attendee' => $att_fields_to_include, |
|
642 | - ); |
|
643 | - foreach ($model_and_fields_to_include as $model_name => $field_list) { |
|
644 | - $model = EE_Registry::instance()->load_model($model_name); |
|
645 | - foreach ($field_list as $field_name) { |
|
646 | - $field = $model->field_settings_for($field_name); |
|
647 | - $reg_csv_array[ $this->_get_column_name_for_field( |
|
648 | - $field |
|
649 | - ) ] = null;// $registration->get($field->get_name()); |
|
650 | - } |
|
651 | - } |
|
652 | - $registrations_csv_ready_array [] = $reg_csv_array; |
|
653 | - } |
|
654 | - if ($event_id) { |
|
655 | - $event_slug = EEM_Event::instance()->get_var(array(array('EVT_ID' => $event_id)), 'EVT_slug'); |
|
656 | - if (! $event_slug) { |
|
657 | - $event_slug = __('unknown', 'event_espresso'); |
|
658 | - } |
|
659 | - } else { |
|
660 | - $event_slug = __('all', 'event_espresso'); |
|
661 | - } |
|
662 | - $filename = sprintf("registrations-for-%s", $event_slug); |
|
663 | - |
|
664 | - $handle = $this->EE_CSV->begin_sending_csv($filename); |
|
665 | - $this->EE_CSV->write_data_array_to_csv($handle, $registrations_csv_ready_array); |
|
666 | - $this->EE_CSV->end_sending_csv($handle); |
|
667 | - } |
|
668 | - |
|
669 | - /** |
|
670 | - * Gets the 'normal' column named for fields |
|
671 | - * |
|
672 | - * @param EE_Model_Field_Base $field |
|
673 | - * @return string |
|
674 | - */ |
|
675 | - protected function _get_column_name_for_field(EE_Model_Field_Base $field) |
|
676 | - { |
|
677 | - return $field->get_nicename() . "[" . $field->get_name() . "]"; |
|
678 | - } |
|
679 | - |
|
680 | - |
|
681 | - /** |
|
682 | - * @Export data for ALL events |
|
683 | - * @access public |
|
684 | - * @return void |
|
685 | - */ |
|
686 | - public function export_categories() |
|
687 | - { |
|
688 | - // are any Event IDs set? |
|
689 | - $query_params = array(); |
|
690 | - if (isset($this->_req_data['EVT_CAT_ID'])) { |
|
691 | - // do we have an array of IDs ? |
|
692 | - if (is_array($this->_req_data['EVT_CAT_ID'])) { |
|
693 | - // generate an "IN (CSV)" where clause |
|
694 | - $EVT_CAT_IDs = array_map('sanitize_text_field', $this->_req_data['EVT_CAT_ID']); |
|
695 | - $filename = 'event-categories'; |
|
696 | - $query_params[0]['term_taxonomy_id'] = array('IN', $EVT_CAT_IDs); |
|
697 | - } else { |
|
698 | - // generate regular where = clause |
|
699 | - $EVT_CAT_ID = absint($this->_req_data['EVT_CAT_ID']); |
|
700 | - $filename = 'event-category#' . $EVT_CAT_ID; |
|
701 | - $query_params[0]['term_taxonomy_id'] = $EVT_CAT_ID; |
|
702 | - } |
|
703 | - } else { |
|
704 | - // no IDs means we will d/l the entire table |
|
705 | - $filename = 'all-categories'; |
|
706 | - } |
|
707 | - |
|
708 | - $tables_to_export = array( |
|
709 | - 'Term_Taxonomy' => $query_params, |
|
710 | - ); |
|
711 | - |
|
712 | - $table_data = $this->_get_export_data_for_models($tables_to_export); |
|
713 | - $filename = $this->generate_filename($filename); |
|
714 | - |
|
715 | - if (! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $table_data)) { |
|
716 | - EE_Error::add_error( |
|
717 | - __( |
|
718 | - 'An error occurred and the Category details could not be exported from the database.', |
|
719 | - 'event_espresso' |
|
720 | - ), |
|
721 | - __FILE__, |
|
722 | - __FUNCTION__, |
|
723 | - __LINE__ |
|
724 | - ); |
|
725 | - } |
|
726 | - } |
|
727 | - |
|
728 | - |
|
729 | - /** |
|
730 | - * @process export name to create a suitable filename |
|
731 | - * @access private |
|
732 | - * @param string - export_name |
|
733 | - * @return string on success, FALSE on fail |
|
734 | - */ |
|
735 | - private function generate_filename($export_name = '') |
|
736 | - { |
|
737 | - if ($export_name != '') { |
|
738 | - $filename = get_bloginfo('name') . '-' . $export_name; |
|
739 | - $filename = sanitize_key($filename) . '-' . $this->today; |
|
740 | - return $filename; |
|
741 | - } else { |
|
742 | - EE_Error::add_error(__("No filename was provided", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
|
743 | - } |
|
744 | - return false; |
|
745 | - } |
|
746 | - |
|
747 | - |
|
748 | - /** |
|
749 | - * @recursive function for exporting table data and merging the results with the next results |
|
750 | - * @access private |
|
751 | - * @param array $models_to_export keys are model names (eg 'Event', 'Attendee', etc.) and values are arrays of |
|
752 | - * query params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
753 | - * @return array on success, FALSE on fail |
|
754 | - */ |
|
755 | - private function _get_export_data_for_models($models_to_export = array()) |
|
756 | - { |
|
757 | - $table_data = false; |
|
758 | - if (is_array($models_to_export)) { |
|
759 | - foreach ($models_to_export as $model_name => $query_params) { |
|
760 | - // check for a numerically-indexed array. in that case, $model_name is the value!! |
|
761 | - if (is_int($model_name)) { |
|
762 | - $model_name = $query_params; |
|
763 | - $query_params = array(); |
|
764 | - } |
|
765 | - $model = EE_Registry::instance()->load_model($model_name); |
|
766 | - $model_objects = $model->get_all($query_params); |
|
767 | - |
|
768 | - $table_data[ $model_name ] = array(); |
|
769 | - foreach ($model_objects as $model_object) { |
|
770 | - $model_data_array = array(); |
|
771 | - $fields = $model->field_settings(); |
|
772 | - foreach ($fields as $field) { |
|
773 | - $column_name = $field->get_nicename() . "[" . $field->get_name() . "]"; |
|
774 | - if ($field instanceof EE_Datetime_Field) { |
|
775 | - // $field->set_date_format('Y-m-d'); |
|
776 | - // $field->set_time_format('H:i:s'); |
|
777 | - $model_data_array[ $column_name ] = $model_object->get_datetime( |
|
778 | - $field->get_name(), |
|
779 | - 'Y-m-d', |
|
780 | - 'H:i:s' |
|
781 | - ); |
|
782 | - } else { |
|
783 | - $model_data_array[ $column_name ] = $model_object->get($field->get_name()); |
|
784 | - } |
|
785 | - } |
|
786 | - $table_data[ $model_name ][] = $model_data_array; |
|
787 | - } |
|
788 | - } |
|
789 | - } |
|
790 | - return $table_data; |
|
791 | - } |
|
19 | + const option_prefix = 'ee_report_job_'; |
|
20 | + |
|
21 | + |
|
22 | + // instance of the EE_Export object |
|
23 | + private static $_instance = null; |
|
24 | + |
|
25 | + // instance of the EE_CSV object |
|
26 | + /** |
|
27 | + * |
|
28 | + * @var EE_CSV |
|
29 | + */ |
|
30 | + public $EE_CSV = null; |
|
31 | + |
|
32 | + |
|
33 | + private $_req_data = array(); |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * private constructor to prevent direct creation |
|
38 | + * |
|
39 | + * @Constructor |
|
40 | + * @access private |
|
41 | + * @param array $request_data |
|
42 | + */ |
|
43 | + private function __construct($request_data = array()) |
|
44 | + { |
|
45 | + $this->_req_data = $request_data; |
|
46 | + $this->today = date("Y-m-d", time()); |
|
47 | + require_once(EE_CLASSES . 'EE_CSV.class.php'); |
|
48 | + $this->EE_CSV = EE_CSV::instance(); |
|
49 | + } |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * @ singleton method used to instantiate class object |
|
54 | + * @ access public |
|
55 | + * |
|
56 | + * @param array $request_data |
|
57 | + * @return \EE_Export |
|
58 | + */ |
|
59 | + public static function instance($request_data = array()) |
|
60 | + { |
|
61 | + // check if class object is instantiated |
|
62 | + if (self::$_instance === null or ! is_object(self::$_instance) or ! (self::$_instance instanceof EE_Export)) { |
|
63 | + self::$_instance = new self($request_data); |
|
64 | + } |
|
65 | + return self::$_instance; |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * @Export Event Espresso data - routes export requests |
|
71 | + * @access public |
|
72 | + * @return void | bool |
|
73 | + */ |
|
74 | + public function export() |
|
75 | + { |
|
76 | + // in case of bulk exports, the "actual" action will be in action2, but first check regular action for "export" keyword |
|
77 | + if (isset($this->_req_data['action']) && strpos($this->_req_data['action'], 'export') === false) { |
|
78 | + // check if action2 has export action |
|
79 | + if (isset($this->_req_data['action2']) && strpos($this->_req_data['action2'], 'export') !== false) { |
|
80 | + // whoop! there it is! |
|
81 | + $this->_req_data['action'] = $this->_req_data['action2']; |
|
82 | + } |
|
83 | + } |
|
84 | + |
|
85 | + $this->_req_data['export'] = isset($this->_req_data['export']) ? $this->_req_data['export'] : ''; |
|
86 | + |
|
87 | + switch ($this->_req_data['export']) { |
|
88 | + case 'report': |
|
89 | + switch ($this->_req_data['action']) { |
|
90 | + case "event": |
|
91 | + case "export_events": |
|
92 | + case 'all_event_data': |
|
93 | + $this->export_all_event_data(); |
|
94 | + break; |
|
95 | + |
|
96 | + case 'registrations_report_for_event': |
|
97 | + $this->report_registrations_for_event($this->_req_data['EVT_ID']); |
|
98 | + break; |
|
99 | + |
|
100 | + case 'attendees': |
|
101 | + $this->export_attendees(); |
|
102 | + break; |
|
103 | + |
|
104 | + case 'categories': |
|
105 | + $this->export_categories(); |
|
106 | + break; |
|
107 | + |
|
108 | + default: |
|
109 | + EE_Error::add_error( |
|
110 | + __('An error occurred! The requested export report could not be found.', 'event_espresso'), |
|
111 | + __FILE__, |
|
112 | + __FUNCTION__, |
|
113 | + __LINE__ |
|
114 | + ); |
|
115 | + return false; |
|
116 | + break; |
|
117 | + } |
|
118 | + break; // end of switch export : report |
|
119 | + default: |
|
120 | + break; |
|
121 | + } // end of switch export |
|
122 | + |
|
123 | + exit; |
|
124 | + } |
|
125 | + |
|
126 | + /** |
|
127 | + * Downloads a CSV file with all the columns, but no data. This should be used for importing |
|
128 | + * |
|
129 | + * @return null kills execution |
|
130 | + */ |
|
131 | + public function export_sample() |
|
132 | + { |
|
133 | + $event = EEM_Event::instance()->get_one(); |
|
134 | + $this->_req_data['EVT_ID'] = $event->ID(); |
|
135 | + $this->export_all_event_data(); |
|
136 | + } |
|
137 | + |
|
138 | + |
|
139 | + /** |
|
140 | + * @Export data for ALL events |
|
141 | + * @access public |
|
142 | + * @return void |
|
143 | + */ |
|
144 | + public function export_all_event_data() |
|
145 | + { |
|
146 | + // are any Event IDs set? |
|
147 | + $event_query_params = array(); |
|
148 | + $related_models_query_params = array(); |
|
149 | + $related_through_reg_query_params = array(); |
|
150 | + $datetime_ticket_query_params = array(); |
|
151 | + $price_query_params = array(); |
|
152 | + $price_type_query_params = array(); |
|
153 | + $term_query_params = array(); |
|
154 | + $state_country_query_params = array(); |
|
155 | + $question_group_query_params = array(); |
|
156 | + $question_query_params = array(); |
|
157 | + if (isset($this->_req_data['EVT_ID'])) { |
|
158 | + // do we have an array of IDs ? |
|
159 | + |
|
160 | + if (is_array($this->_req_data['EVT_ID'])) { |
|
161 | + $EVT_IDs = array_map('sanitize_text_field', $this->_req_data['EVT_ID']); |
|
162 | + $value_to_equal = array('IN', $EVT_IDs); |
|
163 | + $filename = 'events'; |
|
164 | + } else { |
|
165 | + // generate regular where = clause |
|
166 | + $EVT_ID = absint($this->_req_data['EVT_ID']); |
|
167 | + $value_to_equal = $EVT_ID; |
|
168 | + $event = EE_Registry::instance()->load_model('Event')->get_one_by_ID($EVT_ID); |
|
169 | + |
|
170 | + $filename = 'event-' . ($event instanceof EE_Event ? $event->slug() : __('unknown', 'event_espresso')); |
|
171 | + } |
|
172 | + $event_query_params[0]['EVT_ID'] = $value_to_equal; |
|
173 | + $related_models_query_params[0]['Event.EVT_ID'] = $value_to_equal; |
|
174 | + $related_through_reg_query_params[0]['Registration.EVT_ID'] = $value_to_equal; |
|
175 | + $datetime_ticket_query_params[0]['Datetime.EVT_ID'] = $value_to_equal; |
|
176 | + $price_query_params[0]['Ticket.Datetime.EVT_ID'] = $value_to_equal; |
|
177 | + $price_type_query_params[0]['Price.Ticket.Datetime.EVT_ID'] = $value_to_equal; |
|
178 | + $term_query_params[0]['Term_Taxonomy.Event.EVT_ID'] = $value_to_equal; |
|
179 | + $state_country_query_params[0]['Venue.Event.EVT_ID'] = $value_to_equal; |
|
180 | + $question_group_query_params[0]['Event.EVT_ID'] = $value_to_equal; |
|
181 | + $question_query_params[0]['Question_Group.Event.EVT_ID'] = $value_to_equal; |
|
182 | + } else { |
|
183 | + $filename = 'all-events'; |
|
184 | + } |
|
185 | + |
|
186 | + |
|
187 | + // array in the format: table name => query where clause |
|
188 | + $models_to_export = array( |
|
189 | + 'Event' => $event_query_params, |
|
190 | + 'Datetime' => $related_models_query_params, |
|
191 | + 'Ticket_Template' => $price_query_params, |
|
192 | + 'Ticket' => $datetime_ticket_query_params, |
|
193 | + 'Datetime_Ticket' => $datetime_ticket_query_params, |
|
194 | + 'Price_Type' => $price_type_query_params, |
|
195 | + 'Price' => $price_query_params, |
|
196 | + 'Ticket_Price' => $price_query_params, |
|
197 | + 'Term' => $term_query_params, |
|
198 | + 'Term_Taxonomy' => $related_models_query_params, |
|
199 | + 'Term_Relationship' => $related_models_query_params, // model has NO primary key... |
|
200 | + 'Country' => $state_country_query_params, |
|
201 | + 'State' => $state_country_query_params, |
|
202 | + 'Venue' => $related_models_query_params, |
|
203 | + 'Event_Venue' => $related_models_query_params, |
|
204 | + 'Question_Group' => $question_group_query_params, |
|
205 | + 'Event_Question_Group' => $question_group_query_params, |
|
206 | + 'Question' => $question_query_params, |
|
207 | + 'Question_Group_Question' => $question_query_params, |
|
208 | + // 'Transaction'=>$related_through_reg_query_params, |
|
209 | + // 'Registration'=>$related_models_query_params, |
|
210 | + // 'Attendee'=>$related_through_reg_query_params, |
|
211 | + // 'Line_Item'=> |
|
212 | + |
|
213 | + ); |
|
214 | + |
|
215 | + $model_data = $this->_get_export_data_for_models($models_to_export); |
|
216 | + |
|
217 | + $filename = $this->generate_filename($filename); |
|
218 | + |
|
219 | + if (! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $model_data)) { |
|
220 | + EE_Error::add_error( |
|
221 | + __( |
|
222 | + "'An error occurred and the Event details could not be exported from the database.'", |
|
223 | + "event_espresso" |
|
224 | + ), |
|
225 | + __FILE__, |
|
226 | + __FUNCTION__, |
|
227 | + __LINE__ |
|
228 | + ); |
|
229 | + } |
|
230 | + } |
|
231 | + |
|
232 | + public function report_attendees() |
|
233 | + { |
|
234 | + $attendee_rows = EEM_Attendee::instance()->get_all_wpdb_results( |
|
235 | + array( |
|
236 | + 'force_join' => array('State', 'Country'), |
|
237 | + 'caps' => EEM_Base::caps_read_admin, |
|
238 | + ) |
|
239 | + ); |
|
240 | + $csv_data = array(); |
|
241 | + foreach ($attendee_rows as $attendee_row) { |
|
242 | + $csv_row = array(); |
|
243 | + foreach (EEM_Attendee::instance()->field_settings() as $field_name => $field_obj) { |
|
244 | + if ($field_name == 'STA_ID') { |
|
245 | + $state_name_field = EEM_State::instance()->field_settings_for('STA_name'); |
|
246 | + $csv_row[ __('State', 'event_espresso') ] = $attendee_row[ $state_name_field->get_qualified_column( |
|
247 | + ) ]; |
|
248 | + } elseif ($field_name == 'CNT_ISO') { |
|
249 | + $country_name_field = EEM_Country::instance()->field_settings_for('CNT_name'); |
|
250 | + $csv_row[ __( |
|
251 | + 'Country', |
|
252 | + 'event_espresso' |
|
253 | + ) ] = $attendee_row[ $country_name_field->get_qualified_column() ]; |
|
254 | + } else { |
|
255 | + $csv_row[ $field_obj->get_nicename() ] = $attendee_row[ $field_obj->get_qualified_column() ]; |
|
256 | + } |
|
257 | + } |
|
258 | + $csv_data[] = $csv_row; |
|
259 | + } |
|
260 | + |
|
261 | + $filename = $this->generate_filename('contact-list-report'); |
|
262 | + |
|
263 | + $handle = $this->EE_CSV->begin_sending_csv($filename); |
|
264 | + $this->EE_CSV->write_data_array_to_csv($handle, $csv_data); |
|
265 | + $this->EE_CSV->end_sending_csv($handle); |
|
266 | + } |
|
267 | + |
|
268 | + |
|
269 | + /** |
|
270 | + * @Export data for ALL attendees |
|
271 | + * @access public |
|
272 | + * @return void |
|
273 | + */ |
|
274 | + public function export_attendees() |
|
275 | + { |
|
276 | + |
|
277 | + $states_that_have_an_attendee = EEM_State::instance()->get_all( |
|
278 | + array(0 => array('Attendee.ATT_ID' => array('IS NOT NULL'))) |
|
279 | + ); |
|
280 | + $countries_that_have_an_attendee = EEM_Country::instance()->get_all( |
|
281 | + array(0 => array('Attendee.ATT_ID' => array('IS NOT NULL'))) |
|
282 | + ); |
|
283 | + // $states_to_export_query_params |
|
284 | + $models_to_export = array( |
|
285 | + 'Country' => array(array('CNT_ISO' => array('IN', array_keys($countries_that_have_an_attendee)))), |
|
286 | + 'State' => array(array('STA_ID' => array('IN', array_keys($states_that_have_an_attendee)))), |
|
287 | + 'Attendee' => array(), |
|
288 | + ); |
|
289 | + |
|
290 | + |
|
291 | + $model_data = $this->_get_export_data_for_models($models_to_export); |
|
292 | + $filename = $this->generate_filename('all-attendees'); |
|
293 | + |
|
294 | + if (! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $model_data)) { |
|
295 | + EE_Error::add_error( |
|
296 | + __( |
|
297 | + 'An error occurred and the Attendee data could not be exported from the database.', |
|
298 | + 'event_espresso' |
|
299 | + ), |
|
300 | + __FILE__, |
|
301 | + __FUNCTION__, |
|
302 | + __LINE__ |
|
303 | + ); |
|
304 | + } |
|
305 | + } |
|
306 | + |
|
307 | + /** |
|
308 | + * Shortcut for preparing a database result for display |
|
309 | + * |
|
310 | + * @param EEM_Base $model |
|
311 | + * @param string $field_name |
|
312 | + * @param string $raw_db_value |
|
313 | + * @param boolean|string $pretty_schema true to display pretty, a string to use a specific "Schema", or false to |
|
314 | + * NOT display pretty |
|
315 | + * @return string |
|
316 | + */ |
|
317 | + protected function _prepare_value_from_db_for_display($model, $field_name, $raw_db_value, $pretty_schema = true) |
|
318 | + { |
|
319 | + $field_obj = $model->field_settings_for($field_name); |
|
320 | + $value_on_model_obj = $field_obj->prepare_for_set_from_db($raw_db_value); |
|
321 | + if ($field_obj instanceof EE_Datetime_Field) { |
|
322 | + $field_obj->set_date_format( |
|
323 | + EE_CSV::instance()->get_date_format_for_csv($field_obj->get_date_format($pretty_schema)), |
|
324 | + $pretty_schema |
|
325 | + ); |
|
326 | + $field_obj->set_time_format( |
|
327 | + EE_CSV::instance()->get_time_format_for_csv($field_obj->get_time_format($pretty_schema)), |
|
328 | + $pretty_schema |
|
329 | + ); |
|
330 | + } |
|
331 | + if ($pretty_schema === true) { |
|
332 | + return $field_obj->prepare_for_pretty_echoing($value_on_model_obj); |
|
333 | + } elseif (is_string($pretty_schema)) { |
|
334 | + return $field_obj->prepare_for_pretty_echoing($value_on_model_obj, $pretty_schema); |
|
335 | + } else { |
|
336 | + return $field_obj->prepare_for_get($value_on_model_obj); |
|
337 | + } |
|
338 | + } |
|
339 | + |
|
340 | + /** |
|
341 | + * Export a custom CSV of registration info including: A bunch of the reg fields, the time of the event, the price |
|
342 | + * name, and the questions associated with the registrations |
|
343 | + * |
|
344 | + * @param int $event_id |
|
345 | + */ |
|
346 | + public function report_registrations_for_event($event_id = null) |
|
347 | + { |
|
348 | + $reg_fields_to_include = array( |
|
349 | + 'TXN_ID', |
|
350 | + 'ATT_ID', |
|
351 | + 'REG_ID', |
|
352 | + 'REG_date', |
|
353 | + 'REG_code', |
|
354 | + 'REG_count', |
|
355 | + 'REG_final_price', |
|
356 | + |
|
357 | + ); |
|
358 | + $att_fields_to_include = array( |
|
359 | + 'ATT_fname', |
|
360 | + 'ATT_lname', |
|
361 | + 'ATT_email', |
|
362 | + 'ATT_address', |
|
363 | + 'ATT_address2', |
|
364 | + 'ATT_city', |
|
365 | + 'STA_ID', |
|
366 | + 'CNT_ISO', |
|
367 | + 'ATT_zip', |
|
368 | + 'ATT_phone', |
|
369 | + ); |
|
370 | + |
|
371 | + $registrations_csv_ready_array = array(); |
|
372 | + $reg_model = EE_Registry::instance()->load_model('Registration'); |
|
373 | + $query_params = apply_filters( |
|
374 | + 'FHEE__EE_Export__report_registration_for_event', |
|
375 | + array( |
|
376 | + array( |
|
377 | + 'OR' => array( |
|
378 | + // don't include registrations from failed or abandoned transactions... |
|
379 | + 'Transaction.STS_ID' => array( |
|
380 | + 'NOT IN', |
|
381 | + array(EEM_Transaction::failed_status_code, EEM_Transaction::abandoned_status_code), |
|
382 | + ), |
|
383 | + // unless the registration is approved, in which case include it regardless of transaction status |
|
384 | + 'STS_ID' => EEM_Registration::status_id_approved, |
|
385 | + ), |
|
386 | + 'Ticket.TKT_deleted' => array('IN', array(true, false)), |
|
387 | + ), |
|
388 | + 'order_by' => array('Transaction.TXN_ID' => 'asc', 'REG_count' => 'asc'), |
|
389 | + 'force_join' => array('Transaction', 'Ticket', 'Attendee'), |
|
390 | + 'caps' => EEM_Base::caps_read_admin, |
|
391 | + ), |
|
392 | + $event_id |
|
393 | + ); |
|
394 | + if ($event_id) { |
|
395 | + $query_params[0]['EVT_ID'] = $event_id; |
|
396 | + } else { |
|
397 | + $query_params['force_join'][] = 'Event'; |
|
398 | + } |
|
399 | + $registration_rows = $reg_model->get_all_wpdb_results($query_params); |
|
400 | + // get all questions which relate to someone in this group |
|
401 | + $registration_ids = array(); |
|
402 | + foreach ($registration_rows as $reg_row) { |
|
403 | + $registration_ids[] = intval($reg_row['Registration.REG_ID']); |
|
404 | + } |
|
405 | + // EEM_Question::instance()->show_next_x_db_queries(); |
|
406 | + $questions_for_these_regs_rows = EEM_Question::instance()->get_all_wpdb_results( |
|
407 | + array(array('Answer.REG_ID' => array('IN', $registration_ids))) |
|
408 | + ); |
|
409 | + foreach ($registration_rows as $reg_row) { |
|
410 | + if (is_array($reg_row)) { |
|
411 | + $reg_csv_array = array(); |
|
412 | + if (! $event_id) { |
|
413 | + // get the event's name and Id |
|
414 | + $reg_csv_array[ __('Event', 'event_espresso') ] = sprintf( |
|
415 | + __('%1$s (%2$s)', 'event_espresso'), |
|
416 | + $this->_prepare_value_from_db_for_display( |
|
417 | + EEM_Event::instance(), |
|
418 | + 'EVT_name', |
|
419 | + $reg_row['Event_CPT.post_title'] |
|
420 | + ), |
|
421 | + $reg_row['Event_CPT.ID'] |
|
422 | + ); |
|
423 | + } |
|
424 | + $is_primary_reg = $reg_row['Registration.REG_count'] == '1' ? true : false; |
|
425 | + /*@var $reg_row EE_Registration */ |
|
426 | + foreach ($reg_fields_to_include as $field_name) { |
|
427 | + $field = $reg_model->field_settings_for($field_name); |
|
428 | + if ($field_name == 'REG_final_price') { |
|
429 | + $value = $this->_prepare_value_from_db_for_display( |
|
430 | + $reg_model, |
|
431 | + $field_name, |
|
432 | + $reg_row['Registration.REG_final_price'], |
|
433 | + 'localized_float' |
|
434 | + ); |
|
435 | + } elseif ($field_name == 'REG_count') { |
|
436 | + $value = sprintf( |
|
437 | + __('%s of %s', 'event_espresso'), |
|
438 | + $this->_prepare_value_from_db_for_display( |
|
439 | + $reg_model, |
|
440 | + 'REG_count', |
|
441 | + $reg_row['Registration.REG_count'] |
|
442 | + ), |
|
443 | + $this->_prepare_value_from_db_for_display( |
|
444 | + $reg_model, |
|
445 | + 'REG_group_size', |
|
446 | + $reg_row['Registration.REG_group_size'] |
|
447 | + ) |
|
448 | + ); |
|
449 | + } elseif ($field_name == 'REG_date') { |
|
450 | + $value = $this->_prepare_value_from_db_for_display( |
|
451 | + $reg_model, |
|
452 | + $field_name, |
|
453 | + $reg_row['Registration.REG_date'], |
|
454 | + 'no_html' |
|
455 | + ); |
|
456 | + } else { |
|
457 | + $value = $this->_prepare_value_from_db_for_display( |
|
458 | + $reg_model, |
|
459 | + $field_name, |
|
460 | + $reg_row[ $field->get_qualified_column() ] |
|
461 | + ); |
|
462 | + } |
|
463 | + $reg_csv_array[ $this->_get_column_name_for_field($field) ] = $value; |
|
464 | + if ($field_name == 'REG_final_price') { |
|
465 | + // add a column named Currency after the final price |
|
466 | + $reg_csv_array[ __("Currency", "event_espresso") ] = EE_Config::instance()->currency->code; |
|
467 | + } |
|
468 | + } |
|
469 | + // get pretty status |
|
470 | + $stati = EEM_Status::instance()->localized_status( |
|
471 | + array( |
|
472 | + $reg_row['Registration.STS_ID'] => __('unknown', 'event_espresso'), |
|
473 | + $reg_row['TransactionTable.STS_ID'] => __('unknown', 'event_espresso'), |
|
474 | + ), |
|
475 | + false, |
|
476 | + 'sentence' |
|
477 | + ); |
|
478 | + $reg_csv_array[ __( |
|
479 | + "Registration Status", |
|
480 | + 'event_espresso' |
|
481 | + ) ] = $stati[ $reg_row['Registration.STS_ID'] ]; |
|
482 | + // get pretty trnasaction status |
|
483 | + $reg_csv_array[ __( |
|
484 | + "Transaction Status", |
|
485 | + 'event_espresso' |
|
486 | + ) ] = $stati[ $reg_row['TransactionTable.STS_ID'] ]; |
|
487 | + $reg_csv_array[ __('Transaction Amount Due', 'event_espresso') ] = $is_primary_reg |
|
488 | + ? $this->_prepare_value_from_db_for_display( |
|
489 | + EEM_Transaction::instance(), |
|
490 | + 'TXN_total', |
|
491 | + $reg_row['TransactionTable.TXN_total'], |
|
492 | + 'localized_float' |
|
493 | + ) : '0.00'; |
|
494 | + $reg_csv_array[ __('Amount Paid', 'event_espresso') ] = $is_primary_reg |
|
495 | + ? $this->_prepare_value_from_db_for_display( |
|
496 | + EEM_Transaction::instance(), |
|
497 | + 'TXN_paid', |
|
498 | + $reg_row['TransactionTable.TXN_paid'], |
|
499 | + 'localized_float' |
|
500 | + ) : '0.00'; |
|
501 | + $payment_methods = array(); |
|
502 | + $gateway_txn_ids_etc = array(); |
|
503 | + $payment_times = array(); |
|
504 | + if ($is_primary_reg && $reg_row['TransactionTable.TXN_ID']) { |
|
505 | + $payments_info = EEM_Payment::instance()->get_all_wpdb_results( |
|
506 | + array( |
|
507 | + array( |
|
508 | + 'TXN_ID' => $reg_row['TransactionTable.TXN_ID'], |
|
509 | + 'STS_ID' => EEM_Payment::status_id_approved, |
|
510 | + ), |
|
511 | + 'force_join' => array('Payment_Method'), |
|
512 | + ), |
|
513 | + ARRAY_A, |
|
514 | + 'Payment_Method.PMD_admin_name as name, Payment.PAY_txn_id_chq_nmbr as gateway_txn_id, Payment.PAY_timestamp as payment_time' |
|
515 | + ); |
|
516 | + |
|
517 | + foreach ($payments_info as $payment_method_and_gateway_txn_id) { |
|
518 | + $payment_methods[] = isset($payment_method_and_gateway_txn_id['name']) |
|
519 | + ? $payment_method_and_gateway_txn_id['name'] : __('Unknown', 'event_espresso'); |
|
520 | + $gateway_txn_ids_etc[] = isset($payment_method_and_gateway_txn_id['gateway_txn_id']) |
|
521 | + ? $payment_method_and_gateway_txn_id['gateway_txn_id'] : ''; |
|
522 | + $payment_times[] = isset($payment_method_and_gateway_txn_id['payment_time']) |
|
523 | + ? $payment_method_and_gateway_txn_id['payment_time'] : ''; |
|
524 | + } |
|
525 | + } |
|
526 | + $reg_csv_array[ __('Payment Date(s)', 'event_espresso') ] = implode(',', $payment_times); |
|
527 | + $reg_csv_array[ __('Payment Method(s)', 'event_espresso') ] = implode(",", $payment_methods); |
|
528 | + $reg_csv_array[ __('Gateway Transaction ID(s)', 'event_espresso') ] = implode( |
|
529 | + ',', |
|
530 | + $gateway_txn_ids_etc |
|
531 | + ); |
|
532 | + |
|
533 | + // get whether or not the user has checked in |
|
534 | + $reg_csv_array[ __("Check-Ins", "event_espresso") ] = $reg_model->count_related( |
|
535 | + $reg_row['Registration.REG_ID'], |
|
536 | + 'Checkin' |
|
537 | + ); |
|
538 | + // get ticket of registration and its price |
|
539 | + $ticket_model = EE_Registry::instance()->load_model('Ticket'); |
|
540 | + if ($reg_row['Ticket.TKT_ID']) { |
|
541 | + $ticket_name = $this->_prepare_value_from_db_for_display( |
|
542 | + $ticket_model, |
|
543 | + 'TKT_name', |
|
544 | + $reg_row['Ticket.TKT_name'] |
|
545 | + ); |
|
546 | + $datetimes_strings = array(); |
|
547 | + foreach (EEM_Datetime::instance()->get_all_wpdb_results( |
|
548 | + array( |
|
549 | + array('Ticket.TKT_ID' => $reg_row['Ticket.TKT_ID']), |
|
550 | + 'order_by' => array('DTT_EVT_start' => 'ASC'), |
|
551 | + 'default_where_conditions' => 'none', |
|
552 | + ) |
|
553 | + ) as $datetime) { |
|
554 | + $datetimes_strings[] = $this->_prepare_value_from_db_for_display( |
|
555 | + EEM_Datetime::instance(), |
|
556 | + 'DTT_EVT_start', |
|
557 | + $datetime['Datetime.DTT_EVT_start'] |
|
558 | + ); |
|
559 | + } |
|
560 | + } else { |
|
561 | + $ticket_name = __('Unknown', 'event_espresso'); |
|
562 | + $datetimes_strings = array(__('Unknown', 'event_espresso')); |
|
563 | + } |
|
564 | + $reg_csv_array[ $ticket_model->field_settings_for('TKT_name')->get_nicename() ] = $ticket_name; |
|
565 | + $reg_csv_array[ __("Datetimes of Ticket", "event_espresso") ] = implode(", ", $datetimes_strings); |
|
566 | + // get datetime(s) of registration |
|
567 | + |
|
568 | + // add attendee columns |
|
569 | + foreach ($att_fields_to_include as $att_field_name) { |
|
570 | + $field_obj = EEM_Attendee::instance()->field_settings_for($att_field_name); |
|
571 | + if ($reg_row['Attendee_CPT.ID']) { |
|
572 | + if ($att_field_name == 'STA_ID') { |
|
573 | + $value = EEM_State::instance()->get_var( |
|
574 | + array(array('STA_ID' => $reg_row['Attendee_Meta.STA_ID'])), |
|
575 | + 'STA_name' |
|
576 | + ); |
|
577 | + } elseif ($att_field_name == 'CNT_ISO') { |
|
578 | + $value = EEM_Country::instance()->get_var( |
|
579 | + array(array('CNT_ISO' => $reg_row['Attendee_Meta.CNT_ISO'])), |
|
580 | + 'CNT_name' |
|
581 | + ); |
|
582 | + } else { |
|
583 | + $value = $this->_prepare_value_from_db_for_display( |
|
584 | + EEM_Attendee::instance(), |
|
585 | + $att_field_name, |
|
586 | + $reg_row[ $field_obj->get_qualified_column() ] |
|
587 | + ); |
|
588 | + } |
|
589 | + } else { |
|
590 | + $value = ''; |
|
591 | + } |
|
592 | + |
|
593 | + $reg_csv_array[ $this->_get_column_name_for_field($field_obj) ] = $value; |
|
594 | + } |
|
595 | + |
|
596 | + // make sure each registration has the same questions in the same order |
|
597 | + foreach ($questions_for_these_regs_rows as $question_row) { |
|
598 | + if (! isset($reg_csv_array[ $question_row['Question.QST_admin_label'] ])) { |
|
599 | + $reg_csv_array[ $question_row['Question.QST_admin_label'] ] = null; |
|
600 | + } |
|
601 | + } |
|
602 | + // now fill out the questions THEY answered |
|
603 | + foreach (EEM_Answer::instance()->get_all_wpdb_results( |
|
604 | + array(array('REG_ID' => $reg_row['Registration.REG_ID']), 'force_join' => array('Question')) |
|
605 | + ) as $answer_row) { |
|
606 | + /* @var $answer EE_Answer */ |
|
607 | + if ($answer_row['Question.QST_ID']) { |
|
608 | + $question_label = $this->_prepare_value_from_db_for_display( |
|
609 | + EEM_Question::instance(), |
|
610 | + 'QST_admin_label', |
|
611 | + $answer_row['Question.QST_admin_label'] |
|
612 | + ); |
|
613 | + } else { |
|
614 | + $question_label = sprintf(__('Question $s', 'event_espresso'), $answer_row['Answer.QST_ID']); |
|
615 | + } |
|
616 | + if (isset($answer_row['Question.QST_type']) && $answer_row['Question.QST_type'] == EEM_Question::QST_type_state) { |
|
617 | + $reg_csv_array[ $question_label ] = EEM_State::instance()->get_state_name_by_ID( |
|
618 | + $answer_row['Answer.ANS_value'] |
|
619 | + ); |
|
620 | + } else { |
|
621 | + $reg_csv_array[ $question_label ] = $this->_prepare_value_from_db_for_display( |
|
622 | + EEM_Answer::instance(), |
|
623 | + 'ANS_value', |
|
624 | + $answer_row['Answer.ANS_value'] |
|
625 | + ); |
|
626 | + } |
|
627 | + } |
|
628 | + $registrations_csv_ready_array[] = apply_filters( |
|
629 | + 'FHEE__EE_Export__report_registrations__reg_csv_array', |
|
630 | + $reg_csv_array, |
|
631 | + $reg_row |
|
632 | + ); |
|
633 | + } |
|
634 | + } |
|
635 | + |
|
636 | + // if we couldn't export anything, we want to at least show the column headers |
|
637 | + if (empty($registrations_csv_ready_array)) { |
|
638 | + $reg_csv_array = array(); |
|
639 | + $model_and_fields_to_include = array( |
|
640 | + 'Registration' => $reg_fields_to_include, |
|
641 | + 'Attendee' => $att_fields_to_include, |
|
642 | + ); |
|
643 | + foreach ($model_and_fields_to_include as $model_name => $field_list) { |
|
644 | + $model = EE_Registry::instance()->load_model($model_name); |
|
645 | + foreach ($field_list as $field_name) { |
|
646 | + $field = $model->field_settings_for($field_name); |
|
647 | + $reg_csv_array[ $this->_get_column_name_for_field( |
|
648 | + $field |
|
649 | + ) ] = null;// $registration->get($field->get_name()); |
|
650 | + } |
|
651 | + } |
|
652 | + $registrations_csv_ready_array [] = $reg_csv_array; |
|
653 | + } |
|
654 | + if ($event_id) { |
|
655 | + $event_slug = EEM_Event::instance()->get_var(array(array('EVT_ID' => $event_id)), 'EVT_slug'); |
|
656 | + if (! $event_slug) { |
|
657 | + $event_slug = __('unknown', 'event_espresso'); |
|
658 | + } |
|
659 | + } else { |
|
660 | + $event_slug = __('all', 'event_espresso'); |
|
661 | + } |
|
662 | + $filename = sprintf("registrations-for-%s", $event_slug); |
|
663 | + |
|
664 | + $handle = $this->EE_CSV->begin_sending_csv($filename); |
|
665 | + $this->EE_CSV->write_data_array_to_csv($handle, $registrations_csv_ready_array); |
|
666 | + $this->EE_CSV->end_sending_csv($handle); |
|
667 | + } |
|
668 | + |
|
669 | + /** |
|
670 | + * Gets the 'normal' column named for fields |
|
671 | + * |
|
672 | + * @param EE_Model_Field_Base $field |
|
673 | + * @return string |
|
674 | + */ |
|
675 | + protected function _get_column_name_for_field(EE_Model_Field_Base $field) |
|
676 | + { |
|
677 | + return $field->get_nicename() . "[" . $field->get_name() . "]"; |
|
678 | + } |
|
679 | + |
|
680 | + |
|
681 | + /** |
|
682 | + * @Export data for ALL events |
|
683 | + * @access public |
|
684 | + * @return void |
|
685 | + */ |
|
686 | + public function export_categories() |
|
687 | + { |
|
688 | + // are any Event IDs set? |
|
689 | + $query_params = array(); |
|
690 | + if (isset($this->_req_data['EVT_CAT_ID'])) { |
|
691 | + // do we have an array of IDs ? |
|
692 | + if (is_array($this->_req_data['EVT_CAT_ID'])) { |
|
693 | + // generate an "IN (CSV)" where clause |
|
694 | + $EVT_CAT_IDs = array_map('sanitize_text_field', $this->_req_data['EVT_CAT_ID']); |
|
695 | + $filename = 'event-categories'; |
|
696 | + $query_params[0]['term_taxonomy_id'] = array('IN', $EVT_CAT_IDs); |
|
697 | + } else { |
|
698 | + // generate regular where = clause |
|
699 | + $EVT_CAT_ID = absint($this->_req_data['EVT_CAT_ID']); |
|
700 | + $filename = 'event-category#' . $EVT_CAT_ID; |
|
701 | + $query_params[0]['term_taxonomy_id'] = $EVT_CAT_ID; |
|
702 | + } |
|
703 | + } else { |
|
704 | + // no IDs means we will d/l the entire table |
|
705 | + $filename = 'all-categories'; |
|
706 | + } |
|
707 | + |
|
708 | + $tables_to_export = array( |
|
709 | + 'Term_Taxonomy' => $query_params, |
|
710 | + ); |
|
711 | + |
|
712 | + $table_data = $this->_get_export_data_for_models($tables_to_export); |
|
713 | + $filename = $this->generate_filename($filename); |
|
714 | + |
|
715 | + if (! $this->EE_CSV->export_multiple_model_data_to_csv($filename, $table_data)) { |
|
716 | + EE_Error::add_error( |
|
717 | + __( |
|
718 | + 'An error occurred and the Category details could not be exported from the database.', |
|
719 | + 'event_espresso' |
|
720 | + ), |
|
721 | + __FILE__, |
|
722 | + __FUNCTION__, |
|
723 | + __LINE__ |
|
724 | + ); |
|
725 | + } |
|
726 | + } |
|
727 | + |
|
728 | + |
|
729 | + /** |
|
730 | + * @process export name to create a suitable filename |
|
731 | + * @access private |
|
732 | + * @param string - export_name |
|
733 | + * @return string on success, FALSE on fail |
|
734 | + */ |
|
735 | + private function generate_filename($export_name = '') |
|
736 | + { |
|
737 | + if ($export_name != '') { |
|
738 | + $filename = get_bloginfo('name') . '-' . $export_name; |
|
739 | + $filename = sanitize_key($filename) . '-' . $this->today; |
|
740 | + return $filename; |
|
741 | + } else { |
|
742 | + EE_Error::add_error(__("No filename was provided", "event_espresso"), __FILE__, __FUNCTION__, __LINE__); |
|
743 | + } |
|
744 | + return false; |
|
745 | + } |
|
746 | + |
|
747 | + |
|
748 | + /** |
|
749 | + * @recursive function for exporting table data and merging the results with the next results |
|
750 | + * @access private |
|
751 | + * @param array $models_to_export keys are model names (eg 'Event', 'Attendee', etc.) and values are arrays of |
|
752 | + * query params @see https://github.com/eventespresso/event-espresso-core/tree/master/docs/G--Model-System/model-query-params.md |
|
753 | + * @return array on success, FALSE on fail |
|
754 | + */ |
|
755 | + private function _get_export_data_for_models($models_to_export = array()) |
|
756 | + { |
|
757 | + $table_data = false; |
|
758 | + if (is_array($models_to_export)) { |
|
759 | + foreach ($models_to_export as $model_name => $query_params) { |
|
760 | + // check for a numerically-indexed array. in that case, $model_name is the value!! |
|
761 | + if (is_int($model_name)) { |
|
762 | + $model_name = $query_params; |
|
763 | + $query_params = array(); |
|
764 | + } |
|
765 | + $model = EE_Registry::instance()->load_model($model_name); |
|
766 | + $model_objects = $model->get_all($query_params); |
|
767 | + |
|
768 | + $table_data[ $model_name ] = array(); |
|
769 | + foreach ($model_objects as $model_object) { |
|
770 | + $model_data_array = array(); |
|
771 | + $fields = $model->field_settings(); |
|
772 | + foreach ($fields as $field) { |
|
773 | + $column_name = $field->get_nicename() . "[" . $field->get_name() . "]"; |
|
774 | + if ($field instanceof EE_Datetime_Field) { |
|
775 | + // $field->set_date_format('Y-m-d'); |
|
776 | + // $field->set_time_format('H:i:s'); |
|
777 | + $model_data_array[ $column_name ] = $model_object->get_datetime( |
|
778 | + $field->get_name(), |
|
779 | + 'Y-m-d', |
|
780 | + 'H:i:s' |
|
781 | + ); |
|
782 | + } else { |
|
783 | + $model_data_array[ $column_name ] = $model_object->get($field->get_name()); |
|
784 | + } |
|
785 | + } |
|
786 | + $table_data[ $model_name ][] = $model_data_array; |
|
787 | + } |
|
788 | + } |
|
789 | + } |
|
790 | + return $table_data; |
|
791 | + } |
|
792 | 792 | } |
@@ -10,123 +10,123 @@ |
||
10 | 10 | class EE_Country extends EE_Base_Class |
11 | 11 | { |
12 | 12 | |
13 | - /** |
|
14 | - * @param array $props_n_values |
|
15 | - * @return EE_Country|mixed |
|
16 | - */ |
|
17 | - public static function new_instance($props_n_values = array()) |
|
18 | - { |
|
19 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
20 | - return $has_object ? $has_object : new self($props_n_values); |
|
21 | - } |
|
22 | - |
|
23 | - |
|
24 | - /** |
|
25 | - * @param array $props_n_values |
|
26 | - * @return EE_Country |
|
27 | - */ |
|
28 | - public static function new_instance_from_db($props_n_values = array()) |
|
29 | - { |
|
30 | - return new self($props_n_values, true); |
|
31 | - } |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * Gets the country name |
|
36 | - * |
|
37 | - * @return string |
|
38 | - */ |
|
39 | - public function name() |
|
40 | - { |
|
41 | - return $this->get('CNT_name'); |
|
42 | - } |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * gets the country's currency code |
|
47 | - * |
|
48 | - * @return string |
|
49 | - */ |
|
50 | - public function currency_code() |
|
51 | - { |
|
52 | - return $this->get('CNT_cur_code'); |
|
53 | - } |
|
54 | - |
|
55 | - |
|
56 | - /** |
|
57 | - * gets the country's currency sign/symbol |
|
58 | - * |
|
59 | - * @return string |
|
60 | - */ |
|
61 | - public function currency_sign() |
|
62 | - { |
|
63 | - $CNT_cur_sign = $this->get('CNT_cur_sign'); |
|
64 | - return $CNT_cur_sign ? $CNT_cur_sign : ''; |
|
65 | - } |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * Currency name singular |
|
70 | - * |
|
71 | - * @return string |
|
72 | - */ |
|
73 | - public function currency_name_single() |
|
74 | - { |
|
75 | - return $this->get('CNT_cur_single'); |
|
76 | - } |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * Currency name plural |
|
81 | - * |
|
82 | - * @return string |
|
83 | - */ |
|
84 | - public function currency_name_plural() |
|
85 | - { |
|
86 | - return $this->get('CNT_cur_plural'); |
|
87 | - } |
|
88 | - |
|
89 | - |
|
90 | - /** |
|
91 | - * currency_sign_before - ie: $TRUE or FALSE$ |
|
92 | - * |
|
93 | - * @return boolean |
|
94 | - */ |
|
95 | - public function currency_sign_before() |
|
96 | - { |
|
97 | - return $this->get('CNT_cur_sign_b4'); |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * currency_decimal_places : 2 = 0.00 3 = 0.000 |
|
103 | - * |
|
104 | - * @return integer |
|
105 | - */ |
|
106 | - public function currency_decimal_places() |
|
107 | - { |
|
108 | - return $this->get('CNT_cur_dec_plc'); |
|
109 | - } |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * currency_decimal_mark : (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
114 | - * |
|
115 | - * @return string |
|
116 | - */ |
|
117 | - public function currency_decimal_mark() |
|
118 | - { |
|
119 | - return $this->get('CNT_cur_dec_mrk'); |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * currency thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
125 | - * |
|
126 | - * @return string |
|
127 | - */ |
|
128 | - public function currency_thousands_separator() |
|
129 | - { |
|
130 | - return $this->get('CNT_cur_thsnds'); |
|
131 | - } |
|
13 | + /** |
|
14 | + * @param array $props_n_values |
|
15 | + * @return EE_Country|mixed |
|
16 | + */ |
|
17 | + public static function new_instance($props_n_values = array()) |
|
18 | + { |
|
19 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__); |
|
20 | + return $has_object ? $has_object : new self($props_n_values); |
|
21 | + } |
|
22 | + |
|
23 | + |
|
24 | + /** |
|
25 | + * @param array $props_n_values |
|
26 | + * @return EE_Country |
|
27 | + */ |
|
28 | + public static function new_instance_from_db($props_n_values = array()) |
|
29 | + { |
|
30 | + return new self($props_n_values, true); |
|
31 | + } |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * Gets the country name |
|
36 | + * |
|
37 | + * @return string |
|
38 | + */ |
|
39 | + public function name() |
|
40 | + { |
|
41 | + return $this->get('CNT_name'); |
|
42 | + } |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * gets the country's currency code |
|
47 | + * |
|
48 | + * @return string |
|
49 | + */ |
|
50 | + public function currency_code() |
|
51 | + { |
|
52 | + return $this->get('CNT_cur_code'); |
|
53 | + } |
|
54 | + |
|
55 | + |
|
56 | + /** |
|
57 | + * gets the country's currency sign/symbol |
|
58 | + * |
|
59 | + * @return string |
|
60 | + */ |
|
61 | + public function currency_sign() |
|
62 | + { |
|
63 | + $CNT_cur_sign = $this->get('CNT_cur_sign'); |
|
64 | + return $CNT_cur_sign ? $CNT_cur_sign : ''; |
|
65 | + } |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * Currency name singular |
|
70 | + * |
|
71 | + * @return string |
|
72 | + */ |
|
73 | + public function currency_name_single() |
|
74 | + { |
|
75 | + return $this->get('CNT_cur_single'); |
|
76 | + } |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * Currency name plural |
|
81 | + * |
|
82 | + * @return string |
|
83 | + */ |
|
84 | + public function currency_name_plural() |
|
85 | + { |
|
86 | + return $this->get('CNT_cur_plural'); |
|
87 | + } |
|
88 | + |
|
89 | + |
|
90 | + /** |
|
91 | + * currency_sign_before - ie: $TRUE or FALSE$ |
|
92 | + * |
|
93 | + * @return boolean |
|
94 | + */ |
|
95 | + public function currency_sign_before() |
|
96 | + { |
|
97 | + return $this->get('CNT_cur_sign_b4'); |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * currency_decimal_places : 2 = 0.00 3 = 0.000 |
|
103 | + * |
|
104 | + * @return integer |
|
105 | + */ |
|
106 | + public function currency_decimal_places() |
|
107 | + { |
|
108 | + return $this->get('CNT_cur_dec_plc'); |
|
109 | + } |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * currency_decimal_mark : (comma) ',' = 0,01 or (decimal) '.' = 0.01 |
|
114 | + * |
|
115 | + * @return string |
|
116 | + */ |
|
117 | + public function currency_decimal_mark() |
|
118 | + { |
|
119 | + return $this->get('CNT_cur_dec_mrk'); |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * currency thousands separator: (comma) ',' = 1,000 or (decimal) '.' = 1.000 |
|
125 | + * |
|
126 | + * @return string |
|
127 | + */ |
|
128 | + public function currency_thousands_separator() |
|
129 | + { |
|
130 | + return $this->get('CNT_cur_thsnds'); |
|
131 | + } |
|
132 | 132 | } |
@@ -12,25 +12,25 @@ |
||
12 | 12 | class EE_Extra_Join extends EE_Base_Class |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * @param array $props_n_values |
|
17 | - * @param null $timezone |
|
18 | - * @return EE_Extra_Join|mixed |
|
19 | - */ |
|
20 | - public static function new_instance($props_n_values = array(), $timezone = null) |
|
21 | - { |
|
22 | - $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone); |
|
23 | - return $has_object ? $has_object : new self($props_n_values, false, $timezone); |
|
24 | - } |
|
15 | + /** |
|
16 | + * @param array $props_n_values |
|
17 | + * @param null $timezone |
|
18 | + * @return EE_Extra_Join|mixed |
|
19 | + */ |
|
20 | + public static function new_instance($props_n_values = array(), $timezone = null) |
|
21 | + { |
|
22 | + $has_object = parent::_check_for_object($props_n_values, __CLASS__, $timezone); |
|
23 | + return $has_object ? $has_object : new self($props_n_values, false, $timezone); |
|
24 | + } |
|
25 | 25 | |
26 | 26 | |
27 | - /** |
|
28 | - * @param array $props_n_values |
|
29 | - * @param null $timezone |
|
30 | - * @return EE_Extra_Join |
|
31 | - */ |
|
32 | - public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
33 | - { |
|
34 | - return new self($props_n_values, true, $timezone); |
|
35 | - } |
|
27 | + /** |
|
28 | + * @param array $props_n_values |
|
29 | + * @param null $timezone |
|
30 | + * @return EE_Extra_Join |
|
31 | + */ |
|
32 | + public static function new_instance_from_db($props_n_values = array(), $timezone = null) |
|
33 | + { |
|
34 | + return new self($props_n_values, true, $timezone); |
|
35 | + } |
|
36 | 36 | } |